If IPv4 address is missing then DHCPv4 is used. If IPv6 address is missing,
then SLAAC or DHCPv6 is used. This was specified in doc/config-format.txt
but implementation was missing.
We also allow the IP address to contain "off", "dhcp" or "auto" string,
so user can specify how the IP address can be set for the interface.
Fixes BMC#25985
---
doc/config-format.txt | 8 ++++++--
src/config.c | 40 ++++++++++++++++++++++++++++++++++++----
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/doc/config-format.txt b/doc/config-format.txt
index 7be6d05..c255177 100644
--- a/doc/config-format.txt
+++ b/doc/config-format.txt
@@ -37,12 +37,16 @@ Allowed fields:
- Type: Service type. We currently only support wifi and ethernet.
- IPv4: The IPv4 address, netmask and gateway. Format of the entry
is network/netmask/gateway. The mask length can be used instead
- of netmask.
+ of netmask. The field can also contain the string "off" or "dhcp".
+ If the setting is "off", then no IPv4 address is set to the interface.
+ If the setting is "dhcp", then DHCPv4 address resolution is activated.
Example: 192.168.1.2/24/192.168.1.1
192.168.200.100/255.255.255.0/192.168.200.1
- IPv6: The IPv6 address, prefix length and gateway. Format of the entry
is network/prefixlen/gateway. For IPv6 addresses only prefix length is
- accepted.
+ accepted. The field can also contain the string "off" or "auto".
+ If the setting is "off", then no IPv6 address is set to the interface.
+ If the setting is "auto", then SLAAC or DHCPv6 is used.
Example: 2001:db8::2/64/2001:db8::1
- IPv6.Privacy: IPv6 privacy option. Value can be either "disabled",
"enabled" or "prefered". See use_tempaddr variable description in Linux
diff --git a/src/config.c b/src/config.c
index 63c15ea..05c654b 100644
--- a/src/config.c
+++ b/src/config.c
@@ -392,6 +392,18 @@ out:
return err;
}
+static connman_bool_t check_address(char *address_str, char **address)
+{
+ if (g_ascii_strcasecmp(address_str, "auto") == 0 ||
+ g_ascii_strcasecmp(address_str, "dhcp") == 0 ||
+ g_ascii_strcasecmp(address_str, "off") == 0) {
+ *address = address_str;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static connman_bool_t load_service_generic(GKeyFile *keyfile,
const char *group, struct connman_config *config,
struct connman_config_service *service)
@@ -401,7 +413,7 @@ static connman_bool_t load_service_generic(GKeyFile
*keyfile,
gsize length;
str = g_key_file_get_string(keyfile, group, SERVICE_KEY_IPv4, NULL);
- if (str != NULL) {
+ if (str != NULL && check_address(str, &service->ipv4_address) == TRUE) {
mask = NULL;
if (parse_address(str, AF_INET, &service->ipv4_address,
@@ -436,7 +448,7 @@ static connman_bool_t load_service_generic(GKeyFile
*keyfile,
}
str = g_key_file_get_string(keyfile, group, SERVICE_KEY_IPv6, NULL);
- if (str != NULL) {
+ if (str != NULL && check_address(str, &service->ipv6_address) == TRUE) {
long int value;
char *ptr;
@@ -1110,7 +1122,17 @@ static void provision_service(gpointer key, gpointer
value,
return;
}
- if (config->ipv6_address != NULL) {
+ if (config->ipv6_address == NULL) {
+ connman_network_set_ipv6_method(network,
+ CONNMAN_IPCONFIG_METHOD_AUTO);
+ } else if (g_ascii_strcasecmp(config->ipv6_address, "off") == 0) {
+ connman_network_set_ipv6_method(network,
+ CONNMAN_IPCONFIG_METHOD_OFF);
+ } else if (g_ascii_strcasecmp(config->ipv6_address, "auto") == 0 ||
+ g_ascii_strcasecmp(config->ipv6_address, "dhcp") == 0) {
+ connman_network_set_ipv6_method(network,
+ CONNMAN_IPCONFIG_METHOD_AUTO);
+ } else {
struct connman_ipaddress *address;
if (config->ipv6_prefix_length == 0 ||
@@ -1146,7 +1168,17 @@ static void provision_service(gpointer key, gpointer
value,
config->ipv6_privacy);
}
- if (config->ipv4_address != NULL) {
+ if (config->ipv4_address == NULL) {
+ connman_network_set_ipv4_method(network,
+ CONNMAN_IPCONFIG_METHOD_DHCP);
+ } else if (g_ascii_strcasecmp(config->ipv4_address, "off") == 0) {
+ connman_network_set_ipv4_method(network,
+ CONNMAN_IPCONFIG_METHOD_OFF);
+ } else if (g_ascii_strcasecmp(config->ipv4_address, "auto") == 0 ||
+ g_ascii_strcasecmp(config->ipv4_address, "dhcp") == 0) {
+ connman_network_set_ipv4_method(network,
+ CONNMAN_IPCONFIG_METHOD_DHCP);
+ } else {
struct connman_ipaddress *address;
if (config->ipv4_netmask == 0 ||
--
1.7.11.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman