[Olsr-dev] [olsrd] [PATCH v1 12/29] gateway: let init and cleanup functions take the name as parameter

Henning Rogge (spam-protected)
Wed Jul 25 09:04:23 CEST 2012


On 07/24/2012 06:09 PM, Ferry Huberts wrote:
> From: Ferry Huberts <(spam-protected)>

Why do you move this from the OS-specific code to the generic one? The 
way how tunnels (and their endpoints) are generated is OS-specific, 
right? I am not sure all operation systems do this the linux way (with a 
special device name for the endpoint).

Henning

> Signed-off-by: Ferry Huberts <(spam-protected)>
> ---
>   src/bsd/dummy.c           |    4 ++--
>   src/gateway.c             |    4 ++--
>   src/kernel_tunnel.h       |    4 ++--
>   src/linux/kernel_tunnel.c |   15 +++++----------
>   src/win32/dummy.c         |    4 ++--
>   5 files changed, 13 insertions(+), 18 deletions(-)
>
> diff --git a/src/bsd/dummy.c b/src/bsd/dummy.c
> index 1d8f1ae..114d19b 100644
> --- a/src/bsd/dummy.c
> +++ b/src/bsd/dummy.c
> @@ -15,11 +15,11 @@ int olsr_if_setip(const char *dev __attribute__ ((unused)), union olsr_ip_addr *
>
>
>
> -int olsr_os_init_iptunnel(void) {
> +int olsr_os_init_iptunnel(const char * name __attribute__((unused))) {
>     return -1;
>   }
>
> -void olsr_os_cleanup_iptunnel(void) {
> +void olsr_os_cleanup_iptunnel(const char * name __attribute__((unused))) {
>   }
>
>   struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target __attribute__ ((unused)),
> diff --git a/src/gateway.c b/src/gateway.c
> index f74e04a..3fc5bca 100644
> --- a/src/gateway.c
> +++ b/src/gateway.c
> @@ -108,7 +108,7 @@ olsr_init_gateways(void) {
>
>     refresh_smartgw_netmask();
>
> -  if (olsr_os_init_iptunnel()) {
> +  if (olsr_os_init_iptunnel(olsr_cnf->ip_version == AF_INET ? TUNNEL_ENDPOINT_IF : TUNNEL_ENDPOINT_IF6)) {
>       return 1;
>     }
>
> @@ -158,7 +158,7 @@ void olsr_cleanup_gateways(void) {
>     }
>
>     olsr_remove_ifchange_handler(smartgw_tunnel_monitor);
> -  olsr_os_cleanup_iptunnel();
> +  olsr_os_cleanup_iptunnel(olsr_cnf->ip_version == AF_INET ? TUNNEL_ENDPOINT_IF : TUNNEL_ENDPOINT_IF6);
>   }
>
>   /**
> diff --git a/src/kernel_tunnel.h b/src/kernel_tunnel.h
> index 15d1525..a948ebf 100644
> --- a/src/kernel_tunnel.h
> +++ b/src/kernel_tunnel.h
> @@ -32,8 +32,8 @@ struct olsr_iptunnel_entry {
>     int usage;
>   };
>
> -int olsr_os_init_iptunnel(void);
> -void olsr_os_cleanup_iptunnel(void);
> +int olsr_os_init_iptunnel(const char * name);
> +void olsr_os_cleanup_iptunnel(const char * name);
>
>   struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target, bool transportV4);
>   void olsr_os_del_ipip_tunnel(struct olsr_iptunnel_entry *);
> diff --git a/src/linux/kernel_tunnel.c b/src/linux/kernel_tunnel.c
> index 3289d5b..63cec71 100644
> --- a/src/linux/kernel_tunnel.c
> +++ b/src/linux/kernel_tunnel.c
> @@ -73,16 +73,11 @@
>   #include <sys/types.h>
>   #include <net/if.h>
>
> -static const char DEV_IPV4_TUNNEL[IFNAMSIZ] = TUNNEL_ENDPOINT_IF;
> -static const char DEV_IPV6_TUNNEL[IFNAMSIZ] = TUNNEL_ENDPOINT_IF6;
> -
>   static bool store_iptunnel_state;
>   static struct olsr_cookie_info *tunnel_cookie;
>   static struct avl_tree tunnel_tree;
>
> -int olsr_os_init_iptunnel(void) {
> -  const char *dev = olsr_cnf->ip_version == AF_INET ? DEV_IPV4_TUNNEL : DEV_IPV6_TUNNEL;
> -
> +int olsr_os_init_iptunnel(const char * dev) {
>     tunnel_cookie = olsr_alloc_cookie("iptunnel", OLSR_COOKIE_TYPE_MEMORY);
>     olsr_cookie_set_memory_size(tunnel_cookie, sizeof(struct olsr_iptunnel_entry));
>     avl_init(&tunnel_tree, avl_comp_default);
> @@ -98,7 +93,7 @@ int olsr_os_init_iptunnel(void) {
>     return olsr_os_ifip(if_nametoindex(dev), &olsr_cnf->main_addr, true);
>   }
>
> -void olsr_os_cleanup_iptunnel(void) {
> +void olsr_os_cleanup_iptunnel(const char * dev) {
>     while (tunnel_tree.count > 0) {
>       struct olsr_iptunnel_entry *t;
>
> @@ -109,7 +104,7 @@ void olsr_os_cleanup_iptunnel(void) {
>       olsr_os_del_ipip_tunnel(t);
>     }
>     if (!store_iptunnel_state) {
> -    olsr_if_set_state(olsr_cnf->ip_version == AF_INET ? DEV_IPV4_TUNNEL : DEV_IPV6_TUNNEL, false);
> +    olsr_if_set_state(dev, false);
>     }
>
>     olsr_free_cookie(tunnel_cookie);
> @@ -142,7 +137,7 @@ static int os_ip4_tunnel(const char *name, in_addr_t *target)
>     strncpy(p.name, name, IFNAMSIZ);
>
>     memset(&ifr, 0, sizeof(ifr));
> -  strncpy(ifr.ifr_name, target != NULL ? DEV_IPV4_TUNNEL : name, IFNAMSIZ);
> +  strncpy(ifr.ifr_name, target != NULL ? TUNNEL_ENDPOINT_IF : name, IFNAMSIZ);
>     ifr.ifr_ifru.ifru_data = (void *) &p;
>
>     if ((err = ioctl(olsr_cnf->ioctl_s, target != NULL ? SIOCADDTUNNEL : SIOCDELTUNNEL, &ifr))) {
> @@ -183,7 +178,7 @@ static int os_ip6_tunnel(const char *name, struct in6_addr *target)
>     strncpy(p.name, name, IFNAMSIZ);
>
>     memset(&ifr, 0, sizeof(ifr));
> -  strncpy(ifr.ifr_name, target != NULL ? DEV_IPV6_TUNNEL : name, IFNAMSIZ);
> +  strncpy(ifr.ifr_name, target != NULL ? TUNNEL_ENDPOINT_IF6 : name, IFNAMSIZ);
>     ifr.ifr_ifru.ifru_data = (void *) &p;
>
>     if ((err = ioctl(olsr_cnf->ioctl_s, target != NULL ? SIOCADDTUNNEL : SIOCDELTUNNEL, &ifr))) {
> diff --git a/src/win32/dummy.c b/src/win32/dummy.c
> index d305565..7d011b4 100644
> --- a/src/win32/dummy.c
> +++ b/src/win32/dummy.c
> @@ -10,11 +10,11 @@
>   #include "../kernel_tunnel.h"
>   #include "../net_os.h"
>
> -int olsr_os_init_iptunnel(void) {
> +int olsr_os_init_iptunnel(const char * name __attribute__((unused))) {
>     return -1;
>   }
>
> -void olsr_os_cleanup_iptunnel(void) {
> +void olsr_os_cleanup_iptunnel(const char * name __attribute__((unused))) {
>   }
>
>   struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target __attribute__ ((unused)),
>


-- 
Diplom-Informatiker Henning Rogge , Fraunhofer-Institut für
Kommunikation, Informationsverarbeitung und Ergonomie FKIE
Kommunikationssysteme (KOM)
Neuenahrer Straße 20, 53343 Wachtberg, Germany
Telefon +49 228 9435-961,   Fax +49 228 9435 685
mailto:(spam-protected) http://www.fkie.fraunhofer.de
GPG: E1C6 0914 490B 3909 D944 F80D 4487 C67C 55EC CFE0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6169 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.olsr.org/pipermail/olsr-dev/attachments/20120725/5ef5bab9/attachment.bin>


More information about the Olsr-dev mailing list