summaryrefslogtreecommitdiff
path: root/src/settings/plugins/ifcfg-rh
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-05-31 14:31:29 +0200
committerThomas Haller <thaller@redhat.com>2016-06-01 13:30:00 +0200
commit19ea8f44b7a3931ccd038cb0afd48a09fd403413 (patch)
treeb0cf018ca749ffef9b0e6ec0ae4c2c2be8311dfd /src/settings/plugins/ifcfg-rh
parent70d194c159c80266140157db535700f8e44dbe0b (diff)
parentec53ed2cbaab754ddf1283658b5adfba8134e757 (diff)
downloadNetworkManager-th/nm-1-2-merge.tar.gz
all: merge branch 'master' into nm-1-2th/nm-1-2-merge
Since releasing 1.2.0, we maintain a stable branch 'nm-1-2' and implement new features on 'master'. Occasionally, we backport patches by cherry-picking from 'master'. While developing RHEL-7.3, we want essentially all those features and fixes from 'master' also show up in final RHEL-7.3, because that largely determines our priorities. One way to get 'master' stuff into RHEL-7.3, would be to release 1.4.0, and bring that to RHEL-7.3. The downside is, that we already have downstreams as a user of 'nm-1-2' branch (Ubuntu 16.04 LTS). Obviously, there are many useful and important fixes on 'master' that also should reach downstream. Would downstream also rebase with us to 1.4.0? Do we want to invest the effort to heavily maintain both a 'nm-1-4' and 'nm-1-2' branch upstream? After releasing 1.4.0, upstream has less motivation for the additional work to maintain an old-stable 'nm-1-2' branch. So I think this either means more work for upstream, or less upstream help with old-stable branch. The latter possibly also means a worse expirience for 'nm-1-2' users. The alternative is to bring 'nm-1-2' to RHEL-7.3, but that means we backport essentially everything from 'master'. Of course, that temporarily destabilizes our 'nm-1-2' somewhat (our 'master' is in a decent shape, so it shouldn't be that bad). It also means, that 'nm-1-2' will see large development/backporting efforts and thus our upstream stable branch isn't what one would traditionally consider a bugfix-only, stable branch. This is also exactly what we did for 'nm-1-0' branch at the RHEL-7.2 time and although it has downsides, I think it is preferable to above option. Upstream is not going to maintain a bugfix-only 'nm-1-2' branch. If somebody wants that, he must be prepared to do the work and maintain such a "stable" branch based on 1.2.2 himself. Do note, that 'master' is supposed to be backward compatible, and all the gazillion of changes that happend there are considered to be an improvement. Thus, we bring all those improvements to 'nm-1-2', not only bugfixes. Also note, that after this large merge we are going to take the time to test and fix possible regressions before releasing 1.2.4. You can also think of 1.2.4 as a new backward compatible version of NetworkManager and 'master' was the development branch towards that. Now, instead of cherry-picking basically everything, re-merge 'master' into 'nm-1-2'. The outcome is pretty similar, the difference is: + doing it in one rush is considerabily less work, and you can easily verify that the backports are correct via `git diff master`. + we anyway backport everything. Thus a real merge in our git history better represents what is happening. + with a real merge, git has a new merge-parent and future backports will less conflict. - we don't have a fine-grained history of cherry-picked patches on 'nm-1-2'. Instead, there is only this one merge-commit. Of course, the real history is all here and comes from 'master', on HEAD^2. - it also means, if downstream wants to patch 1.2.2 release, it must find the appropriate patch on HEAD^2. - the large merge plays less nice with git-annotate and git-bisect, but still acceptable. I think the time to do this is good, because - 'master' is in a relatively good shape - there are many useful fixes to backport - 1.2.4 is still a bit out, and we can find regressions that this merge may cause. - RHEL-7.3 is even farther away and thus all the testing effort immediately benefits 'nm-1-2'. Yet another alternative to a real merge or extensive cherry-picking would be to do a `git merge --squash master`. However, I think that a real merge better expresses what actually happened. Conflicts: clients/cli/settings.c clients/common/nm-vpn-helpers.c configure.ac libnm-core/Makefile.am libnm-core/nm-vpn-editor-plugin.c man/common.ent.in po/pt_BR.po po/sv.po shared/nm-macros-internal.h shared/nm-test-utils.h shared/nm-version-macros.h.in src/devices/bluetooth/nm-bluez-device.c src/devices/nm-device-ethernet.c src/devices/nm-device.c src/devices/nm-device.h src/devices/wwan/nm-modem-broadband.c src/dhcp-manager/nm-dhcp-systemd.c src/dns-manager/nm-dns-dnsmasq.c src/dns-manager/nm-dns-manager.c src/dnsmasq-manager/tests/test-dnsmasq-utils.c src/nm-auth-subject.c src/nm-connection-provider.c src/nm-connection-provider.h src/nm-core-utils.c src/nm-ip4-config.c src/nm-ip6-config.c src/nm-manager.c src/platform/nm-fake-platform.c src/platform/nm-linux-platform.c src/platform/nm-platform-utils.c src/platform/nm-platform-utils.h src/platform/nm-platform.c src/platform/nm-platform.h src/ppp-manager/nm-ppp-manager.c src/settings/nm-settings.c src/tests/test-ip4-config.c src/vpn-manager/nm-vpn-connection.c
Diffstat (limited to 'src/settings/plugins/ifcfg-rh')
-rw-r--r--src/settings/plugins/ifcfg-rh/common.h4
-rw-r--r--src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c3
-rw-r--r--src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h8
-rw-r--r--src/settings/plugins/ifcfg-rh/plugin.c9
-rw-r--r--src/settings/plugins/ifcfg-rh/plugin.h4
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c200
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.h5
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c20
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.h8
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c2
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c2
-rw-r--r--src/settings/plugins/ifcfg-rh/utils.c3
-rw-r--r--src/settings/plugins/ifcfg-rh/utils.h5
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c45
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.h6
15 files changed, 170 insertions, 154 deletions
diff --git a/src/settings/plugins/ifcfg-rh/common.h b/src/settings/plugins/ifcfg-rh/common.h
index 5d6ebe6d65..d850ac4e75 100644
--- a/src/settings/plugins/ifcfg-rh/common.h
+++ b/src/settings/plugins/ifcfg-rh/common.h
@@ -21,8 +21,6 @@
#ifndef __COMMON_H__
#define __COMMON_H__
-#include "nm-default.h"
-
#define IFCFG_TAG "ifcfg-"
#define KEYS_TAG "keys-"
#define ROUTE_TAG "route-"
@@ -38,7 +36,7 @@
#define AUGNEW_TAG ".augnew"
#define AUGTMP_TAG ".augtmp"
-#define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts"
+#define IFCFG_DIR SYSCONFDIR "/sysconfig/network-scripts"
#define IFCFG_PLUGIN_NAME "ifcfg-rh"
#define IFCFG_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c
index b9bbf6d5b0..3efd99a4c5 100644
--- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c
+++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c
@@ -20,6 +20,8 @@
#include "nm-default.h"
+#include "nm-ifcfg-connection.h"
+
#include <string.h>
#include <glib/gstdio.h>
@@ -37,7 +39,6 @@
#include "common.h"
#include "nm-config.h"
-#include "nm-ifcfg-connection.h"
#include "reader.h"
#include "writer.h"
#include "nm-inotify-helper.h"
diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h
index 44e0298772..57db059b00 100644
--- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h
+++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h
@@ -21,10 +21,8 @@
#ifndef __NETWORKMANAGER_IFCFG_CONNECTION_H__
#define __NETWORKMANAGER_IFCFG_CONNECTION_H__
-G_BEGIN_DECLS
-
-#include <nm-dbus-interface.h>
-#include <nm-settings-connection.h>
+#include "nm-dbus-interface.h"
+#include "nm-settings-connection.h"
#define NM_TYPE_IFCFG_CONNECTION (nm_ifcfg_connection_get_type ())
#define NM_IFCFG_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnection))
@@ -58,6 +56,4 @@ gboolean nm_ifcfg_connection_update (NMIfcfgConnection *self,
GHashTable *new_settings,
GError **error);
-G_END_DECLS
-
#endif /* __NETWORKMANAGER_IFCFG_CONNECTION_H__ */
diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c
index 1fb6b78947..1c0ce918b1 100644
--- a/src/settings/plugins/ifcfg-rh/plugin.c
+++ b/src/settings/plugins/ifcfg-rh/plugin.c
@@ -23,6 +23,8 @@
#include "nm-default.h"
+#include "plugin.h"
+
#include <string.h>
#include <unistd.h>
#include <errno.h>
@@ -31,20 +33,19 @@
#include <gmodule.h>
+#include "nm-dbus-compat.h"
#include "nm-setting-connection.h"
-#include "common.h"
-#include "plugin.h"
#include "nm-settings-plugin.h"
#include "nm-config.h"
#include "NetworkManagerUtils.h"
#include "nm-ifcfg-connection.h"
#include "shvar.h"
+#include "common.h"
#include "reader.h"
#include "writer.h"
#include "utils.h"
-#include "nm-dbus-compat.h"
#include "nm-exported-object.h"
#include "nmdbus-ifcfg-rh.h"
@@ -61,8 +62,6 @@
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
} G_STMT_END
-#define ERR_GET_MSG(err) (((err) && (err)->message) ? (err)->message : "(unknown)")
-
static NMIfcfgConnection *update_connection (SettingsPluginIfcfg *plugin,
NMConnection *source,
diff --git a/src/settings/plugins/ifcfg-rh/plugin.h b/src/settings/plugins/ifcfg-rh/plugin.h
index eba734cff8..74c4b00a04 100644
--- a/src/settings/plugins/ifcfg-rh/plugin.h
+++ b/src/settings/plugins/ifcfg-rh/plugin.h
@@ -24,8 +24,6 @@
#ifndef _PLUGIN_H_
#define _PLUGIN_H_
-#include "nm-exported-object.h"
-
#define SETTINGS_TYPE_PLUGIN_IFCFG (settings_plugin_ifcfg_get_type ())
#define SETTINGS_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfg))
#define SETTINGS_PLUGIN_IFCFG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgClass))
@@ -46,5 +44,5 @@ struct _SettingsPluginIfcfgClass {
GType settings_plugin_ifcfg_get_type (void);
-#endif /* _PLUGIN_H_ */
+#endif /* _PLUGIN_H_ */
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index 39e981f959..b933e1a5fa 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -20,6 +20,8 @@
#include "nm-default.h"
+#include "reader.h"
+
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -57,35 +59,31 @@
#include "shvar.h"
#include "utils.h"
-#include "reader.h"
+/*****************************************************************************/
-#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg)
+#define _NMLOG_DOMAIN LOGD_SETTINGS
+#define _NMLOG_PREFIX_NAME "ifcfg-rh"
+#define _NMLOG(level, ...) \
+ G_STMT_START { \
+ nm_log ((level), (_NMLOG_DOMAIN), \
+ "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
+ _NMLOG_PREFIX_NAME": " \
+ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
+ } G_STMT_END
-static gboolean
-get_int (const char *str, int *value)
-{
- char *e;
- long int tmp;
+#define PARSE_WARNING(...) _LOGW ("%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), " " _NM_UTILS_MACRO_REST(__VA_ARGS__))
- errno = 0;
- tmp = strtol (str, &e, 0);
- if (errno || *e != '\0' || tmp > G_MAXINT || tmp < G_MININT)
- return FALSE;
- *value = (int) tmp;
- return TRUE;
-}
+/*****************************************************************************/
static gboolean
get_uint (const char *str, guint32 *value)
{
- char *e;
- long unsigned int tmp;
+ gint64 tmp;
- errno = 0;
- tmp = strtoul (str, &e, 0);
- if (errno || *e != '\0')
+ tmp = _nm_utils_ascii_str_to_int64 (str, 0, 0, G_MAXUINT32, -1);
+ if (tmp == -1)
return FALSE;
- *value = (guint32) tmp;
+ *value = tmp;
return TRUE;
}
@@ -242,15 +240,12 @@ make_connection_setting (const char *file,
value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT", FALSE);
if (value) {
- long int tmp;
- guint32 timeout;
+ gint64 tmp;
- errno = 0;
- tmp = strtol (value, NULL, 10);
- if (errno == 0 && tmp >= 0 && tmp < G_MAXINT32) {
- timeout = (guint32) tmp;
- g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, timeout, NULL);
- } else
+ tmp = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT32 - 1, -1);
+ if (tmp >= 0)
+ g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, (guint) tmp, NULL);
+ else
PARSE_WARNING ("invalid GATEWAY_PING_TIMEOUT time");
g_free (value);
}
@@ -541,7 +536,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info;
- gint64 prefix_int, metric_int;
+ int prefix_int;
+ gint64 metric_int;
gboolean success = FALSE;
const char *pattern_empty = "^\\s*(\\#.*)?$";
@@ -609,9 +605,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
g_match_info_free (match_info);
prefix_int = 32;
if (prefix) {
- errno = 0;
- prefix_int = strtol (prefix, NULL, 10);
- if (errno || prefix_int <= 0 || prefix_int > 32) {
+ prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 32, -1);
+ if (prefix_int == -1) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination prefix '%s'", prefix);
g_free (prefix);
@@ -641,9 +636,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
metric_int = -1;
if (g_match_info_matches (match_info)) {
metric = g_match_info_fetch (match_info, 1);
- errno = 0;
- metric_int = strtol (metric, NULL, 10);
- if (errno || metric_int < 0) {
+ metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1);
+ if (metric_int == -1) {
g_match_info_free (match_info);
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route metric '%s'", metric);
@@ -766,7 +760,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info;
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
- gint64 prefix_int, metric_int;
+ int prefix_int;
+ gint64 metric_int;
gboolean success = FALSE;
const char *pattern_empty = "^\\s*(\\#.*)?$";
@@ -828,9 +823,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
g_match_info_free (match_info);
prefix_int = 128;
if (prefix) {
- errno = 0;
- prefix_int = strtol (prefix, NULL, 10);
- if (errno || prefix_int <= 0 || prefix_int > 128) {
+ prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 128, -1);
+ if (prefix_int == -1) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 route destination prefix '%s'", prefix);
g_free (dest);
@@ -864,9 +858,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
metric_int = -1;
if (g_match_info_matches (match_info)) {
metric = g_match_info_fetch (match_info, 1);
- errno = 0;
- metric_int = strtol (metric, NULL, 10);
- if (errno || metric_int < 0 || metric_int > G_MAXUINT32) {
+ metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1);
+ if (metric_int == -1) {
g_match_info_free (match_info);
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 route metric '%s'", metric);
@@ -919,6 +912,7 @@ make_ip4_setting (shvarFile *ifcfg,
shvarFile *route_ifcfg;
gboolean never_default = FALSE;
gint64 timeout;
+ gint priority;
s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
@@ -984,6 +978,8 @@ make_ip4_setting (shvarFile *ifcfg,
goto done;
(void) nm_setting_ip_config_add_address (s_ip4, addr);
nm_ip_address_unref (addr);
+ if (never_default)
+ PARSE_WARNING ("GATEWAY will be ignored when DEFROUTE is disabled");
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL);
}
return NM_SETTING (s_ip4);
@@ -1082,6 +1078,9 @@ make_ip4_setting (shvarFile *ifcfg,
}
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL);
+ if (gateway && never_default)
+ PARSE_WARNING ("GATEWAY will be ignored when DEFROUTE is disabled");
+
/* DNS servers
* Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting())
*/
@@ -1136,6 +1135,13 @@ make_ip4_setting (shvarFile *ifcfg,
g_free (dns_options);
dns_options = NULL;
+ /* DNS priority */
+ priority = svGetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0);
+ g_object_set (s_ip4,
+ NM_SETTING_IP_CONFIG_DNS_PRIORITY,
+ priority,
+ NULL);
+
/* Static routes - route-<name> file */
route_path = utils_get_route_path (ifcfg->fileName);
@@ -1318,6 +1324,7 @@ make_ip6_setting (shvarFile *ifcfg,
char *ipv6addr, *ipv6addr_secondaries;
char **list = NULL, **iter;
guint32 i;
+ gint priority;
shvarFile *network_ifcfg;
gboolean never_default = FALSE;
gboolean ip6_privacy = FALSE, ip6_privacy_prefer_public_ip;
@@ -1520,6 +1527,13 @@ make_ip6_setting (shvarFile *ifcfg,
NULL);
}
+ /* IPv6 tokenized interface identifier */
+ tmp = svGetValue (ifcfg, "IPV6_TOKEN", FALSE);
+ if (tmp) {
+ g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, tmp, NULL);
+ g_free (tmp);
+ }
+
/* DNS servers
* Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting())
*/
@@ -1567,6 +1581,13 @@ make_ip6_setting (shvarFile *ifcfg,
g_free (value);
g_free (dns_options);
+ /* DNS priority */
+ priority = svGetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0);
+ g_object_set (s_ip6,
+ NM_SETTING_IP_CONFIG_DNS_PRIORITY,
+ priority,
+ NULL);
+
return NM_SETTING (s_ip6);
error:
@@ -1676,10 +1697,9 @@ read_dcb_app (shvarFile *ifcfg,
tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app);
val = svGetValue (ifcfg, tmp, FALSE);
if (val) {
- success = get_int (val, &priority);
- if (success)
- success = (priority >= 0 && priority <= 7);
- if (!success) {
+ priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1);
+ if (priority < 0) {
+ success = FALSE;
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid %s value '%s' (expected 0 - 7)",
tmp, val);
@@ -1819,7 +1839,6 @@ read_dcb_percent_array (shvarFile *ifcfg,
char *val;
gboolean success = FALSE;
char **split = NULL, **iter;
- int tmp;
guint i, sum = 0;
val = svGetValue (ifcfg, prop, FALSE);
@@ -1842,7 +1861,10 @@ read_dcb_percent_array (shvarFile *ifcfg,
}
for (iter = split, i = 0; iter && *iter; iter++, i++) {
- if (!get_int (*iter, &tmp) || tmp < 0 || tmp > 100) {
+ int tmp;
+
+ tmp = _nm_utils_ascii_str_to_int64 (*iter, 0, 0, 100, -1);
+ if (tmp < 0) {
PARSE_WARNING ("invalid %s percentage value '%s'", prop, *iter);
g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"invalid percent element");
@@ -2164,7 +2186,7 @@ make_wep_setting (shvarFile *ifcfg,
char *value;
shvarFile *keys_ifcfg = NULL;
int default_key_idx = 0;
- gboolean has_default_key = FALSE, success;
+ gboolean has_default_key = FALSE;
NMSettingSecretFlags key_flags;
s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
@@ -2172,18 +2194,17 @@ make_wep_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "DEFAULTKEY", FALSE);
if (value) {
- success = get_int (value, &default_key_idx);
- if (success && (default_key_idx >= 1) && (default_key_idx <= 4)) {
- has_default_key = TRUE;
- default_key_idx--; /* convert to [0...3] */
- g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, default_key_idx, NULL);
- } else {
+ default_key_idx = _nm_utils_ascii_str_to_int64 (value, 0, 1, 4, 0);
+ if (default_key_idx == 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid default WEP key '%s'", value);
- g_free (value);
+ g_free (value);
goto error;
}
- g_free (value);
+ has_default_key = TRUE;
+ default_key_idx--; /* convert to [0...3] */
+ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, (guint) default_key_idx, NULL);
+ g_free (value);
}
/* Read WEP key flags */
@@ -3484,17 +3505,16 @@ make_wireless_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "MTU", FALSE);
if (value) {
- long int mtu;
+ int mtu;
- errno = 0;
- mtu = strtol (value, NULL, 10);
- if (errno || mtu < 0 || mtu > 50000) {
+ mtu = _nm_utils_ascii_str_to_int64 (value, 10, 0, 50000, -1);
+ if (mtu == -1) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid wireless MTU '%s'", value);
g_free (value);
goto error;
}
- g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint32) mtu, NULL);
+ g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint) mtu, NULL);
g_free (value);
}
@@ -3756,20 +3776,19 @@ make_wired_setting (shvarFile *ifcfg,
{
NMSettingWired *s_wired;
char *value = NULL;
- int mtu;
char *nettype;
s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
value = svGetValue (ifcfg, "MTU", FALSE);
if (value) {
- if (get_int (value, &mtu)) {
- if (mtu >= 0 && mtu < 65536)
- g_object_set (s_wired, NM_SETTING_WIRED_MTU, mtu, NULL);
- } else {
- /* Shouldn't be fatal... */
+ int mtu;
+
+ mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1);
+ if (mtu >= 0)
+ g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL);
+ else
PARSE_WARNING ("invalid MTU '%s'", value);
- }
g_free (value);
}
@@ -3940,9 +3959,9 @@ parse_infiniband_p_key (shvarFile *ifcfg,
char **out_parent,
GError **error)
{
- char *device = NULL, *physdev = NULL, *pkey_id = NULL, *end;
+ char *device = NULL, *physdev = NULL, *pkey_id = NULL;
char *ifname = NULL;
- guint32 id = G_MAXUINT32;
+ int id;
gboolean ret = FALSE;
device = svGetValue (ifcfg, "DEVICE", FALSE);
@@ -3963,19 +3982,14 @@ parse_infiniband_p_key (shvarFile *ifcfg,
goto done;
}
- if (g_str_has_prefix (pkey_id, "0x"))
- id = strtoul (pkey_id, &end, 16);
- else if (!g_str_has_prefix (pkey_id, "0"))
- id = strtoul (pkey_id, &end, 10);
- else
- end = pkey_id;
- if (end == pkey_id || *end || id > 0xFFFF) {
+ id = _nm_utils_ascii_str_to_int64 (pkey_id, 0, 0, 0xFFFF, -1);
+ if (id == -1) {
PARSE_WARNING ("invalid InfiniBand PKEY_ID '%s'", pkey_id);
goto done;
}
id = (id | 0x8000);
- ifname = g_strdup_printf ("%s.%04x", physdev, id);
+ ifname = g_strdup_printf ("%s.%04x", physdev, (unsigned) id);
if (strcmp (device, ifname) != 0) {
PARSE_WARNING ("InfiniBand DEVICE (%s) does not match PHYSDEV+PKEY_ID (%s)",
device, ifname);
@@ -4007,19 +4021,18 @@ make_infiniband_setting (shvarFile *ifcfg,
{
NMSettingInfiniband *s_infiniband;
char *value = NULL;
- int mtu;
s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ());
value = svGetValue (ifcfg, "MTU", FALSE);
if (value) {
- if (get_int (value, &mtu)) {
- if (mtu >= 0 && mtu < 65536)
- g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, mtu, NULL);
- } else {
- /* Shouldn't be fatal... */
+ int mtu;
+
+ mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1);
+ if (mtu >= 0)
+ g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, (guint) mtu, NULL);
+ else
PARSE_WARNING ("invalid MTU '%s'", value);
- }
g_free (value);
}
@@ -4643,16 +4656,14 @@ make_vlan_setting (shvarFile *ifcfg,
char *iface_name = NULL;
char *parent = NULL;
const char *p = NULL;
- char *end = NULL;
- gint vlan_id = -1;
+ int vlan_id = -1;
guint32 vlan_flags = 0;
gint gvrp, reorder_hdr;
value = svGetValue (ifcfg, "VLAN_ID", FALSE);
if (value) {
- errno = 0;
- vlan_id = (gint) g_ascii_strtoll (value, NULL, 10);
- if (vlan_id < 0 || vlan_id > 4096 || errno) {
+ vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1);
+ if (vlan_id == -1) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid VLAN_ID '%s'", value);
g_free (value);
@@ -4696,12 +4707,13 @@ make_vlan_setting (shvarFile *ifcfg,
}
if (p) {
+ int device_vlan_id;
+
/* Grab VLAN ID from interface name; this takes precedence over the
* separate VLAN_ID property for backwards compat.
*/
-
- gint device_vlan_id = (gint) g_ascii_strtoll (p, &end, 10);
- if (device_vlan_id >= 0 && device_vlan_id <= 4095 && end != p && !*end)
+ device_vlan_id = _nm_utils_ascii_str_to_int64 (p, 10, 0, 4095, -1);
+ if (device_vlan_id != -1)
vlan_id = device_vlan_id;
}
}
diff --git a/src/settings/plugins/ifcfg-rh/reader.h b/src/settings/plugins/ifcfg-rh/reader.h
index 88f9a72007..35464474f2 100644
--- a/src/settings/plugins/ifcfg-rh/reader.h
+++ b/src/settings/plugins/ifcfg-rh/reader.h
@@ -21,10 +21,7 @@
#ifndef __READER_H__
#define __READER_H__
-#include <nm-connection.h>
-
-#include "nm-default.h"
-#include "shvar.h"
+#include "nm-connection.h"
NMConnection *connection_from_file (const char *filename,
char **out_unhandled,
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index 4e756349ca..75b19d5383 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -25,6 +25,8 @@
#include "nm-default.h"
+#include "shvar.h"
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -34,12 +36,8 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "shvar.h"
-
#include "nm-core-internal.h"
-#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg)
-
/* Open the file <name>, returning a shvarFile on success and NULL on failure.
* Add a wrinkle to let the caller specify whether or not to create the file
* (actually, return a structure anyway) if it doesn't exist.
@@ -273,26 +271,23 @@ svGetValueFull (shvarFile *s, const char *key, gboolean verbatim)
{
char *value = NULL;
char *line;
- char *keyString;
- int len;
+ guint len;
g_return_val_if_fail (s != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
- keyString = g_strdup_printf ("%s=", key);
- len = strlen (keyString);
+ len = strlen (key);
for (s->current = s->lineList; s->current; s->current = s->current->next) {
line = s->current->data;
- if (!strncmp (keyString, line, len)) {
+ if (!strncmp (key, line, len) && line[len] == '=') {
/* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */
- value = g_strchomp (g_strdup (line + len));
+ value = g_strchomp (g_strdup (line + len + 1));
if (!verbatim)
svUnescape (value);
break;
}
}
- g_free (keyString);
return value;
}
@@ -373,11 +368,10 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
result = _nm_utils_ascii_str_to_int64 (tmp, base, min, max, fallback);
errsv = errno;
- if (errsv != 0)
- PARSE_WARNING ("Error reading '%s' value '%s' as integer (%d)", key, tmp, errsv);
g_free (tmp);
+ errno = errsv;
return result;
}
diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h
index 227a44db17..97df81284a 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.h
+++ b/src/settings/plugins/ifcfg-rh/shvar.h
@@ -31,10 +31,6 @@
#ifndef _SHVAR_H
#define _SHVAR_H
-#include "nm-default.h"
-
-G_BEGIN_DECLS
-
typedef struct _shvarFile shvarFile;
struct _shvarFile {
char *fileName; /* read-only */
@@ -95,6 +91,4 @@ const char *svEscape (const char *s, char **to_free);
/* Unescape a string in-place */
void svUnescape (char *s);
-G_END_DECLS
-
-#endif /* ! _SHVAR_H */
+#endif /* _SHVAR_H */
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c
index 5a0f6451a4..d2a348bb8b 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c
@@ -28,7 +28,7 @@
#include "common.h"
#include "utils.h"
-#include "nm-test-utils.h"
+#include "nm-test-utils-core.h"
static void
test_get_ifcfg_name (const char *desc,
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 5ed25fda10..c7e741f996 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -55,7 +55,7 @@
#include "writer.h"
#include "utils.h"
-#include "nm-test-utils.h"
+#include "nm-test-utils-core.h"
/*****************************************************************************/
diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/utils.c
index fda900b20e..b602a7d7c3 100644
--- a/src/settings/plugins/ifcfg-rh/utils.c
+++ b/src/settings/plugins/ifcfg-rh/utils.c
@@ -27,7 +27,8 @@
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
-#include "shvar.h"
+
+#include "common.h"
/*
* utils_single_quote_string
diff --git a/src/settings/plugins/ifcfg-rh/utils.h b/src/settings/plugins/ifcfg-rh/utils.h
index 752d08a60b..b8b172e7ce 100644
--- a/src/settings/plugins/ifcfg-rh/utils.h
+++ b/src/settings/plugins/ifcfg-rh/utils.h
@@ -21,10 +21,9 @@
#ifndef _UTILS_H_
#define _UTILS_H_
-#include <nm-connection.h>
-#include "nm-default.h"
+#include "nm-connection.h"
+
#include "shvar.h"
-#include "common.h"
#define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index c17824d6fc..2864078a48 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -42,7 +42,6 @@
#include "nm-setting-vlan.h"
#include "nm-setting-team.h"
#include "nm-setting-team-port.h"
-#include "nm-core-internal.h"
#include "nm-utils.h"
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
@@ -51,8 +50,20 @@
#include "shvar.h"
#include "reader.h"
#include "utils.h"
-#include "crypto.h"
+/*****************************************************************************/
+
+#define _NMLOG_DOMAIN LOGD_SETTINGS
+#define _NMLOG_PREFIX_NAME "ifcfg-rh"
+#define _NMLOG(level, ...) \
+ G_STMT_START { \
+ nm_log ((level), (_NMLOG_DOMAIN), \
+ "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
+ _NMLOG_PREFIX_NAME": " \
+ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
+ } G_STMT_END
+
+/*****************************************************************************/
static void
save_secret_flags (shvarFile *ifcfg,
@@ -100,7 +111,7 @@ set_secret (shvarFile *ifcfg,
{
shvarFile *keyfile;
GError *error = NULL;
-
+
/* Clear the secret from the ifcfg and the associated "keys" file */
svSetValue (ifcfg, key, NULL, FALSE);
@@ -109,7 +120,7 @@ set_secret (shvarFile *ifcfg,
keyfile = utils_get_keys_ifcfg (ifcfg->fileName, TRUE);
if (!keyfile) {
- nm_log_warn (LOGD_SETTINGS, " could not create ifcfg file for '%s'", ifcfg->fileName);
+ _LOGW ("could not create ifcfg file for '%s'", ifcfg->fileName);
goto error;
}
@@ -121,8 +132,8 @@ set_secret (shvarFile *ifcfg,
svSetValue (keyfile, key, value, verbatim);
if (!svWriteFile (keyfile, 0600, &error)) {
- nm_log_warn (LOGD_SETTINGS, " could not update ifcfg file '%s': %s",
- keyfile->fileName, error->message);
+ _LOGW ("could not update ifcfg file '%s': %s",
+ keyfile->fileName, error->message);
g_clear_error (&error);
svCloseFile (keyfile);
goto error;
@@ -715,7 +726,7 @@ write_wireless_security_setting (NMConnection *connection,
key = ascii_key;
}
} else {
- nm_log_warn (LOGD_SETTINGS, " invalid WEP key '%s'", key);
+ _LOGW ("invalid WEP key '%s'", key);
tmp = NULL;
}
@@ -1970,6 +1981,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
gint32 j;
guint32 i, n, num;
gint64 route_metric;
+ gint priority;
int timeout;
GString *searches;
gboolean success = FALSE;
@@ -2281,6 +2293,12 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1);
}
+ priority = nm_setting_ip_config_get_dns_priority (s_ip4);
+ if (priority)
+ svSetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", priority);
+ else
+ svSetValue (ifcfg, "IPV4_DNS_PRIORITY", NULL, FALSE);
+
success = TRUE;
out:
@@ -2440,6 +2458,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
char *addr_key;
char *tmp;
guint32 i, num, num4;
+ gint priority;
GString *searches;
NMIPAddress *addr;
const char *dns;
@@ -2604,8 +2623,20 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
addr_gen_mode);
svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", tmp, FALSE);
g_free (tmp);
+ } else {
+ svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", NULL, FALSE);
}
+ /* IPv6 tokenized interface identifier */
+ value = nm_setting_ip6_config_get_token (NM_SETTING_IP6_CONFIG (s_ip6));
+ svSetValue (ifcfg, "IPV6_TOKEN", value, FALSE);
+
+ priority = nm_setting_ip_config_get_dns_priority (s_ip6);
+ if (priority)
+ svSetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", priority);
+ else
+ svSetValue (ifcfg, "IPV6_DNS_PRIORITY", NULL, FALSE);
+
/* Static routes go to route6-<dev> file */
route6_path = utils_get_route6_path (ifcfg->fileName);
if (!route6_path) {
diff --git a/src/settings/plugins/ifcfg-rh/writer.h b/src/settings/plugins/ifcfg-rh/writer.h
index 69389361c9..97a9f25252 100644
--- a/src/settings/plugins/ifcfg-rh/writer.h
+++ b/src/settings/plugins/ifcfg-rh/writer.h
@@ -21,11 +21,7 @@
#ifndef _WRITER_H_
#define _WRITER_H_
-#include <sys/types.h>
-
-#include <nm-connection.h>
-
-#include "nm-default.h"
+#include "nm-connection.h"
gboolean writer_can_write_connection (NMConnection *connection,
GError **error);