diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-08-08 19:16:59 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-08-08 19:16:59 -0700 |
commit | 10b6ada1337f719b1a0a4232c63f098da218bc2b (patch) | |
tree | 86952458fa5edb99ca690ed8f53dbe1b46712038 | |
parent | 5640935cc685a7aa2bc8b6230d48f71d9ca0fdcc (diff) | |
download | connman-10b6ada1337f719b1a0a4232c63f098da218bc2b.tar.gz connman-10b6ada1337f719b1a0a4232c63f098da218bc2b.tar.bz2 connman-10b6ada1337f719b1a0a4232c63f098da218bc2b.zip |
Attach IP addresses to configuration
-rw-r--r-- | src/ipconfig.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c index 70131ad5..2d5c5eed 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -33,6 +33,11 @@ #include "connman.h" +struct connman_ipaddress { + unsigned char prefixlen; + char *address; +}; + struct connman_ipconfig { gint refcount; int index; @@ -40,8 +45,40 @@ struct connman_ipconfig { unsigned short type; unsigned int flags; enum connman_ipconfig_method method; + GSList *address_list; }; +static void free_address_list(struct connman_ipconfig *ipconfig) +{ + GSList *list; + + for (list = ipconfig->address_list; list; list = list->next) { + struct connman_ipaddress *ipaddress = list->data; + + g_free(ipaddress->address); + g_free(ipaddress); + } + + g_slist_free(ipconfig->address_list); + ipconfig->address_list = NULL; +} + +static struct connman_ipaddress *find_ipaddress(struct connman_ipconfig *ipconfig, + unsigned char prefixlen, const char *address) +{ + GSList *list; + + for (list = ipconfig->address_list; list; list = list->next) { + struct connman_ipaddress *ipaddress = list->data; + + if (g_strcmp0(ipaddress->address, address) == 0 && + ipaddress->prefixlen == prefixlen) + return ipaddress; + } + + return NULL; +} + /** * connman_ipconfig_create: * @@ -97,6 +134,8 @@ void connman_ipconfig_unref(struct connman_ipconfig *ipconfig) connman_info("%s {remove} index %d", ipconfig->interface, ipconfig->index); + free_address_list(ipconfig); + g_free(ipconfig->interface); g_free(ipconfig); } @@ -167,6 +206,18 @@ void __connman_ipconfig_add_address(struct connman_ipconfig *ipconfig, const char *label, unsigned char prefixlen, const char *address, const char *broadcast) { + struct connman_ipaddress *ipaddress; + + ipaddress = g_try_new0(struct connman_ipaddress, 1); + if (ipaddress == NULL) + return; + + ipaddress->prefixlen = prefixlen; + ipaddress->address = g_strdup(address); + + ipconfig->address_list = g_slist_append(ipconfig->address_list, + ipaddress); + connman_info("%s {add} address %s/%u label %s", ipconfig->interface, address, prefixlen, label); } @@ -175,6 +226,18 @@ void __connman_ipconfig_del_address(struct connman_ipconfig *ipconfig, const char *label, unsigned char prefixlen, const char *address, const char *broadcast) { + struct connman_ipaddress *ipaddress; + + ipaddress = find_ipaddress(ipconfig, prefixlen, address); + if (ipaddress == NULL) + return; + + ipconfig->address_list = g_slist_remove(ipconfig->address_list, + ipaddress); + + g_free(ipaddress->address); + g_free(ipaddress); + connman_info("%s {del} address %s/%u label %s", ipconfig->interface, address, prefixlen, label); } |