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

Ferry Huberts (spam-protected)
Wed Jul 25 09:08:33 CEST 2012



On 25-07-12 09:04, Henning Rogge wrote:
> 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).
>

this allows you to create multiple tunnels. the functions can now only 
be used to create a single tunnel since the same name is always used


> 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)),
>>
>
>
>
>

-- 
Ferry Huberts




More information about the Olsr-dev mailing list