+ if (ipconfig->address == NULL)
+ return;
+
+ g_free(ipconfig->address->broadcast);
+ ipconfig->address->broadcast = g_strdup(broadcast);
+}
+
+const char *__connman_ipconfig_get_gateway(struct connman_ipconfig *ipconfig)
+{
+ if (ipconfig->address == NULL)
+ return NULL;
+
+ return ipconfig->address->gateway;
+}
+
+void __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig, const char *gateway)
+{
+ struct connman_service *service;
+
+ if (ipconfig->address == NULL)
+ return;
+
+ service = __connman_service_lookup_from_index(ipconfig->index);
+ if (service != NULL)
+ __connman_connection_gateway_remove(service);
+
+ g_free(ipconfig->address->gateway);
+ ipconfig->address->gateway = g_strdup(gateway);
+
+ if (service != NULL && ipconfig->address->gateway != NULL) {
+ if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+ __connman_connection_gateway_add(service,
+ NULL,
+ ipconfig->address->gateway,
+ ipconfig->address->peer);
+ } else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+ __connman_connection_gateway_add(service,
+ ipconfig->address->gateway,
+ NULL,
+ ipconfig->address->peer);
+ }
+ }
+}
+
+unsigned char __connman_ipconfig_get_prefixlen(struct connman_ipconfig *ipconfig)
+{
+ if (ipconfig->address == NULL)
+ return 0;
+
+ return ipconfig->address->prefixlen;
+}
+
+void __connman_ipconfig_set_prefixlen(struct connman_ipconfig *ipconfig, unsigned char prefixlen)
+{
+ if (ipconfig->address == NULL)
+ return;
+
+ ipconfig->address->prefixlen = prefixlen;
+}
+
+static struct connman_ipconfig *create_ipv6config(int index)
+{
+ struct connman_ipconfig *ipv6config;
+
+ DBG("index %d", index);
+
+ ipv6config = g_try_new0(struct connman_ipconfig, 1);
+ if (ipv6config == NULL)
+ return NULL;
+
+ ipv6config->refcount = 1;
+
+ ipv6config->index = index;
+ ipv6config->type = CONNMAN_IPCONFIG_TYPE_IPV6;
+ ipv6config->method = CONNMAN_IPCONFIG_METHOD_AUTO;
+ ipv6config->ipv6_privacy_config = 0;
+
+ ipv6config->address = connman_ipaddress_alloc(AF_INET6);
+ if (ipv6config->address == NULL) {
+ g_free(ipv6config);
+ return NULL;
+ }
+
+ ipv6config->system = connman_ipaddress_alloc(AF_INET6);
+
+ DBG("ipconfig %p", ipv6config);
+
+ return ipv6config;
+}
+
+/**
+ * connman_ipconfig_create:
+ *
+ * Allocate a new ipconfig structure.
+ *
+ * Returns: a newly-allocated #connman_ipconfig structure
+ */
+struct connman_ipconfig *connman_ipconfig_create(int index,
+ enum connman_ipconfig_type type)
+{
+ struct connman_ipconfig *ipconfig;
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ return create_ipv6config(index);
+
+ DBG("index %d", index);
+
+ ipconfig = g_try_new0(struct connman_ipconfig, 1);
+ if (ipconfig == NULL)
+ return NULL;
+
+ ipconfig->refcount = 1;
+
+ ipconfig->index = index;
+ ipconfig->type = CONNMAN_IPCONFIG_TYPE_IPV4;
+
+ ipconfig->address = connman_ipaddress_alloc(AF_INET);
+ if (ipconfig->address == NULL) {
+ g_free(ipconfig);
+ return NULL;
+ }
+
+ ipconfig->system = connman_ipaddress_alloc(AF_INET);
+
+ DBG("ipconfig %p", ipconfig);
+
+ return ipconfig;
+}
+
+
+/**
+ * connman_ipconfig_ref:
+ * @ipconfig: ipconfig structure
+ *
+ * Increase reference counter of ipconfig
+ */
+struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
+{
+ DBG("ipconfig %p refcount %d", ipconfig,
+ g_atomic_int_get(&ipconfig->refcount) + 1);
+
+ g_atomic_int_inc(&ipconfig->refcount);
+
+ return ipconfig;
+}
+
+/**
+ * connman_ipconfig_unref:
+ * @ipconfig: ipconfig structure
+ *
+ * Decrease reference counter of ipconfig
+ */
+void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
+{
+ if (ipconfig == NULL)
+ return;
+
+ DBG("ipconfig %p refcount %d", ipconfig,
+ g_atomic_int_get(&ipconfig->refcount) - 1);
+