summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2013-03-25 11:58:32 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-03-25 14:08:36 +0200
commitbd320a31a4939c43976726fbb201b1ad6c752b13 (patch)
treed55c5c93c3a28003bf13311fc4c2f690791b8a5b /src
parent555f962dc5f75a9a54fa79257f348a6c46be0f5e (diff)
downloadconnman-bd320a31a4939c43976726fbb201b1ad6c752b13.tar.gz
connman-bd320a31a4939c43976726fbb201b1ad6c752b13.tar.bz2
connman-bd320a31a4939c43976726fbb201b1ad6c752b13.zip
config: Allow user to specify how IP address is used
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
Diffstat (limited to 'src')
-rw-r--r--src/config.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/config.c b/src/config.c
index 63c15ea7..05c654b6 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 ||