summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2012-11-12 14:07:18 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-11-23 12:58:50 +0200
commit68dde4bb2c3e90a6f48dc48609636228dd186c8c (patch)
tree319e4787674daa49b939916769611f0770a32e91 /src
parentd20247d3b3074b7c5937540ce5dbc8f020c79907 (diff)
downloadconnman-68dde4bb2c3e90a6f48dc48609636228dd186c8c.tar.gz
connman-68dde4bb2c3e90a6f48dc48609636228dd186c8c.tar.bz2
connman-68dde4bb2c3e90a6f48dc48609636228dd186c8c.zip
ipconfig: Move IP address API into separate ipaddress.c file
Done so that connman_ipaddress_* functions can be used from separate vpn daemon.
Diffstat (limited to 'src')
-rw-r--r--src/connman.h2
-rw-r--r--src/dhcp.c4
-rw-r--r--src/ipaddress.c200
-rw-r--r--src/ipconfig.c167
-rw-r--r--src/tethering.c4
5 files changed, 206 insertions, 171 deletions
diff --git a/src/connman.h b/src/connman.h
index 613d1dc9..014552a4 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -350,7 +350,7 @@ int __connman_ipconfig_address_remove(struct connman_ipconfig *ipconfig);
int __connman_ipconfig_address_unset(struct connman_ipconfig *ipconfig);
int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig);
void __connman_ipconfig_gateway_remove(struct connman_ipconfig *ipconfig);
-unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask);
+unsigned char __connman_ipaddress_netmask_prefix_len(const char *netmask);
int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
const char *url);
diff --git a/src/dhcp.c b/src/dhcp.c
index e64c975a..f32bfaef 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -227,7 +227,7 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
if (option != NULL)
gateway = g_strdup(option->data);
- prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
+ prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
if (prefixlen == 255)
connman_warn("netmask: %s is invalid", netmask);
@@ -375,7 +375,7 @@ static void ipv4ll_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
address = g_dhcp_client_get_address(dhcp_client);
netmask = g_dhcp_client_get_netmask(dhcp_client);
- prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
+ prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
__connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP);
__connman_ipconfig_set_local(ipconfig, address);
diff --git a/src/ipaddress.c b/src/ipaddress.c
new file mode 100644
index 00000000..e5af9a06
--- /dev/null
+++ b/src/ipaddress.c
@@ -0,0 +1,200 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include <connman/ipaddress.h>
+
+#include "connman.h"
+
+struct connman_ipaddress *connman_ipaddress_alloc(int family)
+{
+ struct connman_ipaddress *ipaddress;
+
+ ipaddress = g_try_new0(struct connman_ipaddress, 1);
+ if (ipaddress == NULL)
+ return NULL;
+
+ ipaddress->family = family;
+ ipaddress->prefixlen = 0;
+ ipaddress->local = NULL;
+ ipaddress->peer = NULL;
+ ipaddress->broadcast = NULL;
+ ipaddress->gateway = NULL;
+
+ return ipaddress;
+}
+
+void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
+{
+ if (ipaddress == NULL)
+ return;
+
+ g_free(ipaddress->broadcast);
+ g_free(ipaddress->peer);
+ g_free(ipaddress->local);
+ g_free(ipaddress->gateway);
+ g_free(ipaddress);
+}
+
+unsigned char __connman_ipaddress_netmask_prefix_len(const char *netmask)
+{
+ unsigned char bits;
+ in_addr_t mask;
+ in_addr_t host;
+
+ if (netmask == NULL)
+ return 32;
+
+ mask = inet_network(netmask);
+ host = ~mask;
+
+ /* a valid netmask must be 2^n - 1 */
+ if ((host & (host + 1)) != 0)
+ return -1;
+
+ bits = 0;
+ for (; mask; mask <<= 1)
+ ++bits;
+
+ return bits;
+}
+
+static gboolean check_ipv6_address(const char *address)
+{
+ unsigned char buf[sizeof(struct in6_addr)];
+ int err;
+
+ if (address == NULL)
+ return FALSE;
+
+ err = inet_pton(AF_INET6, address, buf);
+ if (err > 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
+ const char *address,
+ unsigned char prefix_length,
+ const char *gateway)
+{
+ if (ipaddress == NULL)
+ return -EINVAL;
+
+ if (check_ipv6_address(address) == FALSE)
+ return -EINVAL;
+
+ DBG("prefix_len %d address %s gateway %s",
+ prefix_length, address, gateway);
+
+ ipaddress->family = AF_INET6;
+
+ ipaddress->prefixlen = prefix_length;
+
+ g_free(ipaddress->local);
+ ipaddress->local = g_strdup(address);
+
+ g_free(ipaddress->gateway);
+ ipaddress->gateway = g_strdup(gateway);
+
+ return 0;
+}
+
+int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
+ const char *address, const char *netmask, const char *gateway)
+{
+ if (ipaddress == NULL)
+ return -EINVAL;
+
+ ipaddress->family = AF_INET;
+
+ ipaddress->prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
+
+ g_free(ipaddress->local);
+ ipaddress->local = g_strdup(address);
+
+ g_free(ipaddress->gateway);
+ ipaddress->gateway = g_strdup(gateway);
+
+ return 0;
+}
+
+void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress,
+ const char *peer)
+{
+ if (ipaddress == NULL)
+ return;
+
+ g_free(ipaddress->peer);
+ ipaddress->peer = g_strdup(peer);
+}
+
+void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
+{
+ if (ipaddress == NULL)
+ return;
+
+ ipaddress->prefixlen = 0;
+
+ g_free(ipaddress->local);
+ ipaddress->local = NULL;
+
+ g_free(ipaddress->peer);
+ ipaddress->peer = NULL;
+
+ g_free(ipaddress->broadcast);
+ ipaddress->broadcast = NULL;
+
+ g_free(ipaddress->gateway);
+ ipaddress->gateway = NULL;
+}
+
+void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
+ struct connman_ipaddress *source)
+{
+ if (ipaddress == NULL || source == NULL)
+ return;
+
+ ipaddress->family = source->family;
+ ipaddress->prefixlen = source->prefixlen;
+
+ g_free(ipaddress->local);
+ ipaddress->local = g_strdup(source->local);
+
+ g_free(ipaddress->peer);
+ ipaddress->peer = g_strdup(source->peer);
+
+ g_free(ipaddress->broadcast);
+ ipaddress->broadcast = g_strdup(source->broadcast);
+
+ g_free(ipaddress->gateway);
+ ipaddress->gateway = g_strdup(source->gateway);
+}
diff --git a/src/ipconfig.c b/src/ipconfig.c
index aa7a03db..3cb0d9bb 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -36,6 +36,7 @@
#endif
#include <gdbus.h>
+#include <connman/ipaddress.h>
#include "connman.h"
@@ -91,150 +92,6 @@ static GHashTable *ipdevice_hash = NULL;
static GList *ipconfig_list = NULL;
static connman_bool_t is_ipv6_supported = FALSE;
-struct connman_ipaddress *connman_ipaddress_alloc(int family)
-{
- struct connman_ipaddress *ipaddress;
-
- ipaddress = g_try_new0(struct connman_ipaddress, 1);
- if (ipaddress == NULL)
- return NULL;
-
- ipaddress->family = family;
- ipaddress->prefixlen = 0;
- ipaddress->local = NULL;
- ipaddress->peer = NULL;
- ipaddress->broadcast = NULL;
- ipaddress->gateway = NULL;
-
- return ipaddress;
-}
-
-void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
-{
- if (ipaddress == NULL)
- return;
-
- g_free(ipaddress->broadcast);
- g_free(ipaddress->peer);
- g_free(ipaddress->local);
- g_free(ipaddress->gateway);
- g_free(ipaddress);
-}
-
-unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask)
-{
- unsigned char bits;
- in_addr_t mask;
- in_addr_t host;
-
- if (netmask == NULL)
- return 32;
-
- mask = inet_network(netmask);
- host = ~mask;
-
- /* a valid netmask must be 2^n - 1 */
- if ((host & (host + 1)) != 0)
- return -1;
-
- bits = 0;
- for (; mask; mask <<= 1)
- ++bits;
-
- return bits;
-}
-
-static gboolean check_ipv6_address(const char *address)
-{
- unsigned char buf[sizeof(struct in6_addr)];
- int err;
-
- if (address == NULL)
- return FALSE;
-
- err = inet_pton(AF_INET6, address, buf);
- if (err > 0)
- return TRUE;
-
- return FALSE;
-}
-
-int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
- const char *address,
- unsigned char prefix_length,
- const char *gateway)
-{
- if (ipaddress == NULL)
- return -EINVAL;
-
- if (check_ipv6_address(address) == FALSE)
- return -EINVAL;
-
- DBG("prefix_len %d address %s gateway %s",
- prefix_length, address, gateway);
-
- ipaddress->family = AF_INET6;
-
- ipaddress->prefixlen = prefix_length;
-
- g_free(ipaddress->local);
- ipaddress->local = g_strdup(address);
-
- g_free(ipaddress->gateway);
- ipaddress->gateway = g_strdup(gateway);
-
- return 0;
-}
-
-int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
- const char *address, const char *netmask, const char *gateway)
-{
- if (ipaddress == NULL)
- return -EINVAL;
-
- ipaddress->family = AF_INET;
-
- ipaddress->prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
-
- g_free(ipaddress->local);
- ipaddress->local = g_strdup(address);
-
- g_free(ipaddress->gateway);
- ipaddress->gateway = g_strdup(gateway);
-
- return 0;
-}
-
-void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress,
- const char *peer)
-{
- if (ipaddress == NULL)
- return;
-
- g_free(ipaddress->peer);
- ipaddress->peer = g_strdup(peer);
-}
-
-void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
-{
- if (ipaddress == NULL)
- return;
-
- ipaddress->prefixlen = 0;
-
- g_free(ipaddress->local);
- ipaddress->local = NULL;
-
- g_free(ipaddress->peer);
- ipaddress->peer = NULL;
-
- g_free(ipaddress->broadcast);
- ipaddress->broadcast = NULL;
-
- g_free(ipaddress->gateway);
- ipaddress->gateway = NULL;
-}
-
void __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
{
if (ipconfig == NULL)
@@ -243,28 +100,6 @@ void __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
connman_ipaddress_clear(ipconfig->address);
}
-void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
- struct connman_ipaddress *source)
-{
- if (ipaddress == NULL || source == NULL)
- return;
-
- ipaddress->family = source->family;
- ipaddress->prefixlen = source->prefixlen;
-
- g_free(ipaddress->local);
- ipaddress->local = g_strdup(source->local);
-
- g_free(ipaddress->peer);
- ipaddress->peer = g_strdup(source->peer);
-
- g_free(ipaddress->broadcast);
- ipaddress->broadcast = g_strdup(source->broadcast);
-
- g_free(ipaddress->gateway);
- ipaddress->gateway = g_strdup(source->gateway);
-}
-
static void free_address_list(struct connman_ipdevice *ipdevice)
{
GSList *list;
diff --git a/src/tethering.c b/src/tethering.c
index b9df21b3..ab892d3a 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -247,7 +247,7 @@ void __connman_tethering_set_enabled(void)
}
prefixlen =
- __connman_ipconfig_netmask_prefix_len(subnet_mask);
+ __connman_ipaddress_netmask_prefix_len(subnet_mask);
__connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen);
DBG("tethering started");
@@ -300,7 +300,7 @@ static void setup_tun_interface(unsigned int flags, unsigned change,
server_ip = __connman_ippool_get_start_ip(pn->pool);
peer_ip = __connman_ippool_get_end_ip(pn->pool);
prefixlen =
- __connman_ipconfig_netmask_prefix_len(subnet_mask);
+ __connman_ipaddress_netmask_prefix_len(subnet_mask);
if ((__connman_inet_modify_address(RTM_NEWADDR,
NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET,