Renaming the netmask length calc function so that it can be used
by both connmand and vpnd.
---
include/ipaddress.h | 1 +
src/connman.h | 1 -
src/dhcp.c | 4 ++--
src/ipaddress.c | 48 ++++++++++++++++++++++++------------------------
src/tethering.c | 7 +++----
5 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/include/ipaddress.h b/include/ipaddress.h
index 4ced318..ff775c9 100644
--- a/include/ipaddress.h
+++ b/include/ipaddress.h
@@ -34,6 +34,7 @@ extern "C" {
struct connman_ipaddress;
+unsigned char connman_ipaddress_calc_netmask_len(const char *netmask);
struct connman_ipaddress *connman_ipaddress_alloc(int family);
void connman_ipaddress_free(struct connman_ipaddress *ipaddress);
int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
diff --git a/src/connman.h b/src/connman.h
index 24db5f8..6bd7e3b 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -383,7 +383,6 @@ 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_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 631d15c..00df486 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -346,7 +346,7 @@ static void lease_available_cb(GDHCPClient *dhcp_client,
gpointer user_data)
if (option)
gateway = g_strdup(option->data);
- prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
+ prefixlen = connman_ipaddress_calc_netmask_len(netmask);
if (prefixlen == 255)
connman_warn("netmask: %s is invalid", netmask);
@@ -479,7 +479,7 @@ static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client,
gpointer user_data)
address = g_dhcp_client_get_address(ipv4ll_client);
netmask = g_dhcp_client_get_netmask(ipv4ll_client);
- prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
+ prefixlen = connman_ipaddress_calc_netmask_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
index 57f9435..9788294 100644
--- a/src/ipaddress.c
+++ b/src/ipaddress.c
@@ -33,6 +33,29 @@
#include "connman.h"
+unsigned char connman_ipaddress_calc_netmask_len(const char *netmask)
+{
+ unsigned char bits;
+ in_addr_t mask;
+ in_addr_t host;
+
+ if (!netmask)
+ 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;
+}
+
struct connman_ipaddress *connman_ipaddress_alloc(int family)
{
struct connman_ipaddress *ipaddress;
@@ -63,29 +86,6 @@ void connman_ipaddress_free(struct connman_ipaddress
*ipaddress)
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)
- 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 bool check_ipv6_address(const char *address)
{
unsigned char buf[sizeof(struct in6_addr)];
@@ -136,7 +136,7 @@ int connman_ipaddress_set_ipv4(struct connman_ipaddress
*ipaddress,
ipaddress->family = AF_INET;
- ipaddress->prefixlen = __connman_ipaddress_netmask_prefix_len(netmask);
+ ipaddress->prefixlen = connman_ipaddress_calc_netmask_len(netmask);
g_free(ipaddress->local);
ipaddress->local = g_strdup(address);
diff --git a/src/tethering.c b/src/tethering.c
index c7e17f5..ceeec74 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -222,7 +222,7 @@ void __connman_tethering_set_enabled(void)
end_ip = __connman_ippool_get_end_ip(dhcp_ippool);
err = __connman_bridge_enable(BRIDGE_NAME, gateway,
- __connman_ipaddress_netmask_prefix_len(subnet_mask),
+ connman_ipaddress_calc_netmask_len(subnet_mask),
broadcast);
if (err < 0 && err != -EALREADY) {
__connman_ippool_unref(dhcp_ippool);
@@ -267,7 +267,7 @@ void __connman_tethering_set_enabled(void)
return;
}
- prefixlen = __connman_ipaddress_netmask_prefix_len(subnet_mask);
+ prefixlen = connman_ipaddress_calc_netmask_len(subnet_mask);
err = __connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen);
if (err < 0) {
connman_error("Cannot enable NAT %d/%s", err, strerror(-err));
@@ -340,8 +340,7 @@ static void setup_tun_interface(unsigned int flags,
unsigned change,
subnet_mask = __connman_ippool_get_subnet_mask(pn->pool);
server_ip = __connman_ippool_get_start_ip(pn->pool);
peer_ip = __connman_ippool_get_end_ip(pn->pool);
- prefixlen =
- __connman_ipaddress_netmask_prefix_len(subnet_mask);
+ prefixlen = connman_ipaddress_calc_netmask_len(subnet_mask);
if ((__connman_inet_modify_address(RTM_NEWADDR,
NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET,
--
1.8.3.1
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman