Commit e9321713 authored by Francesco Giudici's avatar Francesco Giudici

ifcfg: make_ip6_setting cleanup & optimization 2/2

get rid of svGetValueStr_cp() in favor of svGetValueStr() in the
make_ip6_setting() function
parent fa478d8f
......@@ -1685,11 +1685,13 @@ make_ip6_setting (shvarFile *ifcfg,
{
NMSettingIPConfig *s_ip6 = NULL;
const char *v;
char *value = NULL;
gs_free char *value = NULL;
char *route6_path = NULL;
gboolean ipv6init, ipv6forwarding, dhcp6 = FALSE;
char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
char *ipv6addr, *ipv6addr_secondaries;
const char *ipv6addr, *ipv6addr_secondaries;
gs_free char *ipv6addr_to_free = NULL;
gs_free char *ipv6addr_secondaries_to_free = NULL;
gs_free const char **list = NULL;
const char *const *iter;
guint32 i;
......@@ -1715,13 +1717,16 @@ make_ip6_setting (shvarFile *ifcfg,
* When both are set, the device specified in IPV6_DEFAULTGW takes preference.
*/
if (network_ifcfg) {
char *ipv6_defaultgw, *ipv6_defaultdev;
char *default_dev = NULL;
const char *ipv6_defaultgw, *ipv6_defaultdev;
gs_free char *ipv6_defaultgw_to_free = NULL;
gs_free char *ipv6_defaultdev_to_free = NULL;
const char *default_dev = NULL;
/* Get the connection ifcfg device name and the global default route device */
value = svGetValueStr_cp (ifcfg, "DEVICE");
ipv6_defaultgw = svGetValueStr_cp (network_ifcfg, "IPV6_DEFAULTGW");
ipv6_defaultdev = svGetValueStr_cp (network_ifcfg, "IPV6_DEFAULTDEV");
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "DEVICE", &value);
ipv6_defaultgw = svGetValueStr (network_ifcfg, "IPV6_DEFAULTGW", &ipv6_defaultgw_to_free);
ipv6_defaultdev = svGetValueStr (network_ifcfg, "IPV6_DEFAULTDEV", &ipv6_defaultdev_to_free);
if (ipv6_defaultgw) {
default_dev = strchr (ipv6_defaultgw, '%');
......@@ -1734,66 +1739,64 @@ make_ip6_setting (shvarFile *ifcfg,
/* If there was a global default route device specified, then only connections
* for that device can be the default connection.
*/
if (default_dev && value)
never_default = !!strcmp (value, default_dev);
g_free (ipv6_defaultgw);
g_free (ipv6_defaultdev);
g_free (value);
if (default_dev && v)
never_default = !!strcmp (v, default_dev);
}
/* Find out method property */
/* Is IPV6 enabled? Set method to "ignored", when not enabled */
value = svGetValueStr_cp (ifcfg, "IPV6INIT");
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6INIT", &value);
ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE);
if (!value) {
if (!v) {
if (network_ifcfg)
ipv6init = svGetValueBoolean (network_ifcfg, "IPV6INIT", FALSE);
}
g_free (value);
if (!ipv6init)
method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE; /* IPv6 is disabled */
else {
ipv6forwarding = svGetValueBoolean (ifcfg, "IPV6FORWARDING", FALSE);
value = svGetValueStr_cp (ifcfg, "IPV6_AUTOCONF");
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6_AUTOCONF", &value);
dhcp6 = svGetValueBoolean (ifcfg, "DHCPV6C", FALSE);
if (!g_strcmp0 (value, "shared"))
if (!g_strcmp0 (v, "shared"))
method = NM_SETTING_IP6_CONFIG_METHOD_SHARED;
else if (svParseBoolean (value, !ipv6forwarding))
else if (svParseBoolean (v, !ipv6forwarding))
method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
else if (dhcp6)
method = NM_SETTING_IP6_CONFIG_METHOD_DHCP;
else {
/* IPV6_AUTOCONF=no and no IPv6 address -> method 'link-local' */
g_free (value);
value = svGetValueStr_cp (ifcfg, "IPV6ADDR");
if (!value)
value = svGetValueStr_cp (ifcfg, "IPV6ADDR_SECONDARIES");
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6ADDR", &value);
if (!v) {
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6ADDR_SECONDARIES", &value);
}
if (!value)
if (!v)
method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL;
}
g_free (value);
}
/* TODO - handle other methods */
/* Read IPv6 Privacy Extensions configuration */
value = svGetValueStr_cp (ifcfg, "IPV6_PRIVACY");
if (value) {
ip6_privacy = svParseBoolean (value, FALSE);
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6_PRIVACY", &value);
if (v) {
ip6_privacy = svParseBoolean (v, FALSE);
if (!ip6_privacy)
ip6_privacy = (g_strcmp0 (value, "rfc4941") == 0) ||
(g_strcmp0 (value, "rfc3041") == 0);
ip6_privacy = (g_strcmp0 (v, "rfc4941") == 0) ||
(g_strcmp0 (v, "rfc3041") == 0);
}
ip6_privacy_prefer_public_ip = svGetValueBoolean (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", FALSE);
ip6_privacy_val = value ?
ip6_privacy_val = v ?
(ip6_privacy ?
(ip6_privacy_prefer_public_ip ? NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR : NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR) :
NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED) :
NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;
g_free (value);
/* the route table (policy routing) is ignored if we don't handle routes. */
route_table = svGetValueInt64 (ifcfg, "IPV6_ROUTE_TABLE", 10,
......@@ -1820,19 +1823,20 @@ make_ip6_setting (shvarFile *ifcfg,
if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0)
return NM_SETTING (s_ip6);
value = svGetValueStr_cp (ifcfg, "DHCPV6_HOSTNAME");
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "DHCPV6_HOSTNAME", &value);
/* Use DHCP_HOSTNAME as fallback if it is in FQDN format and ipv6.method is
* auto or dhcp: this is required to support old ifcfg files
*/
if (!value && ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)
if (!v && ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)
|| !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP))) {
value = svGetValueStr_cp (ifcfg, "DHCP_HOSTNAME");
if (value && !strchr (value, '.'))
g_clear_pointer (&value, g_free);
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "DHCP_HOSTNAME", &value);
if (v && !strchr (v, '.'))
v = NULL;
}
if (value)
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL);
g_free (value);
if (v)
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, v, NULL);
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME,
svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL);
......@@ -1842,18 +1846,16 @@ make_ip6_setting (shvarFile *ifcfg,
* added to the automatic ones. Note that this is not currently supported by
* the legacy 'network' service (ifup-eth).
*/
ipv6addr = svGetValueStr_cp (ifcfg, "IPV6ADDR");
ipv6addr_secondaries = svGetValueStr_cp (ifcfg, "IPV6ADDR_SECONDARIES");
ipv6addr = svGetValueStr (ifcfg, "IPV6ADDR", &ipv6addr_to_free);
ipv6addr_secondaries = svGetValueStr (ifcfg, "IPV6ADDR_SECONDARIES", &ipv6addr_secondaries_to_free);
nm_clear_g_free (&value);
value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL,
ipv6addr ?: "",
ipv6addr_secondaries ?: "",
NULL);
g_free (ipv6addr);
g_free (ipv6addr_secondaries);
list = nm_utils_strsplit_set (value, " ");
g_free (value);
for (iter = list, i = 0; iter && *iter; iter++, i++) {
NMIPAddress *addr = NULL;
......@@ -1867,25 +1869,26 @@ make_ip6_setting (shvarFile *ifcfg,
/* Gateway */
if (nm_setting_ip_config_get_num_addresses (s_ip6)) {
value = svGetValueStr_cp (ifcfg, "IPV6_DEFAULTGW");
if (!value) {
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6_DEFAULTGW", &value);
if (!v) {
/* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */
if (network_ifcfg)
value = svGetValueStr_cp (network_ifcfg, "IPV6_DEFAULTGW");
if (network_ifcfg) {
nm_clear_g_free (&value);
v = svGetValueStr (network_ifcfg, "IPV6_DEFAULTGW", &value);
}
}
if (value) {
if (v) {
char *ptr;
if ((ptr = strchr (value, '%')) != NULL)
if ((ptr = strchr (v, '%')) != NULL)
*ptr = '\0'; /* remove %interface prefix if present */
if (!nm_utils_ipaddr_valid (AF_INET6, value)) {
if (!nm_utils_ipaddr_valid (AF_INET6, v)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 address '%s'", value);
g_free (value);
"Invalid IP6 address '%s'", v);
goto error;
}
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, value, NULL);
g_free (value);
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, v, NULL);
}
}
......@@ -1899,11 +1902,10 @@ make_ip6_setting (shvarFile *ifcfg,
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, i_val, NULL);
/* IPv6 tokenized interface identifier */
value = svGetValueStr_cp (ifcfg, "IPV6_TOKEN");
if (value) {
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, value, NULL);
g_free (value);
}
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6_TOKEN", &value);
if (v)
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, v, NULL);
/* DNS servers
* Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting())
......@@ -1912,24 +1914,22 @@ make_ip6_setting (shvarFile *ifcfg,
char tag[256];
numbered_tag (tag, "DNS", i);
value = svGetValueStr_cp (ifcfg, tag);
if (!value) {
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, tag, &value);
if (!v) {
/* all done */
break;
}
if (nm_utils_ipaddr_valid (AF_INET6, value)) {
if (!nm_setting_ip_config_add_dns (s_ip6, value))
if (nm_utils_ipaddr_valid (AF_INET6, v)) {
if (!nm_setting_ip_config_add_dns (s_ip6, v))
PARSE_WARNING ("duplicate DNS server %s", tag);
} else if (nm_utils_ipaddr_valid (AF_INET, value)) {
} else if (nm_utils_ipaddr_valid (AF_INET, v)) {
/* Ignore IPv4 addresses */
} else {
PARSE_WARNING ("invalid DNS server address %s", value);
g_free (value);
PARSE_WARNING ("invalid DNS server address %s", v);
goto error;
}
g_free (value);
}
if (!routes_read) {
......@@ -1960,7 +1960,6 @@ make_ip6_setting (shvarFile *ifcfg,
/* DNS options */
nm_clear_g_free (&value);
parse_dns_options (s_ip6, svGetValue (ifcfg, "IPV6_RES_OPTIONS", &value));
g_free (value);
/* DNS priority */
priority = svGetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment