From 76b454562798599cfc81ada45e3d634117c89aed Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Fri, 25 Feb 2011 19:31:04 +0100 Subject: [PATCH] service: Add a generic ipconfig selection routine --- src/connman.h | 2 ++ src/ipconfig.c | 4 ++-- src/network.c | 6 +----- src/provider.c | 10 ++-------- src/service.c | 12 ++++++++++++ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/connman.h b/src/connman.h index a390516..437eaed 100644 --- a/src/connman.h +++ b/src/connman.h @@ -481,6 +481,8 @@ struct connman_ipconfig *__connman_service_get_ip4config( struct connman_service *service); struct connman_ipconfig *__connman_service_get_ip6config( struct connman_service *service); +struct connman_ipconfig *__connman_service_get_ipconfig( + struct connman_service *service, int family); const char *__connman_service_get_ident(struct connman_service *service); const char *__connman_service_get_path(struct connman_service *service); unsigned int __connman_service_get_order(struct connman_service *service); diff --git a/src/ipconfig.c b/src/ipconfig.c index d620383..7eea909 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -168,7 +168,7 @@ int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress, DBG("prefix_len %d address %s gateway %s", prefix_length, address, gateway); - ipaddress->family = CONNMAN_IPCONFIG_TYPE_IPV6; + ipaddress->family = AF_INET6; ipaddress->prefixlen = prefix_length; @@ -187,7 +187,7 @@ int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress, if (ipaddress == NULL) return -EINVAL; - ipaddress->family = CONNMAN_IPCONFIG_TYPE_IPV4; + ipaddress->family = AF_INET; ipaddress->prefixlen = __connman_ipconfig_netmask_prefix_len(netmask); diff --git a/src/network.c b/src/network.c index 2ad073b..babb28b 100644 --- a/src/network.c +++ b/src/network.c @@ -1207,11 +1207,7 @@ int connman_network_set_ipaddress(struct connman_network *network, if (service == NULL) return -EINVAL; - if (ipaddress->family == CONNMAN_IPCONFIG_TYPE_IPV4) - ipconfig = __connman_service_get_ip4config(service); - else if (ipaddress->family == CONNMAN_IPCONFIG_TYPE_IPV6) - ipconfig = __connman_service_get_ip6config(service); - + ipconfig = __connman_service_get_ipconfig(service, ipaddress->family); if (ipconfig == NULL) return -EINVAL; diff --git a/src/provider.c b/src/provider.c index 816ad3d..c930d37 100644 --- a/src/provider.c +++ b/src/provider.c @@ -683,14 +683,8 @@ int connman_provider_set_ipaddress(struct connman_provider *provider, { struct connman_ipconfig *ipconfig = NULL; - if (ipaddress->family == CONNMAN_IPCONFIG_TYPE_IPV4) { - ipconfig = __connman_service_get_ip4config( - provider->vpn_service); - } else if (ipaddress->family == CONNMAN_IPCONFIG_TYPE_IPV6) { - ipconfig = __connman_service_get_ip6config( - provider->vpn_service); - } - + ipconfig = __connman_service_get_ipconfig(provider->vpn_service, + ipaddress->family); if (ipconfig == NULL) return -EINVAL; diff --git a/src/service.c b/src/service.c index a103549..c95c96b 100644 --- a/src/service.c +++ b/src/service.c @@ -3247,6 +3247,18 @@ __connman_service_get_ip6config(struct connman_service *service) return service->ipconfig_ipv6; } +struct connman_ipconfig * +__connman_service_get_ipconfig(struct connman_service *service, int family) +{ + if (family == AF_INET) + return __connman_service_get_ip4config(service); + else if (family == AF_INET6) + return __connman_service_get_ip6config(service); + else + return NULL; + +} + enum connman_service_security __connman_service_get_security(struct connman_service *service) { if (service == NULL) -- 2.7.4