[Olsr-dev] [PATCH v1 10/23] gateway: let the gateway code determine the tunnel name
Ferry Huberts
(spam-protected)
Tue Dec 4 16:17:17 CET 2012
From: Ferry Huberts <(spam-protected)>
Signed-off-by: Ferry Huberts <(spam-protected)>
---
src/bsd/dummy.c | 2 +-
src/gateway.c | 24 ++++++++++++++++++++++--
src/kernel_tunnel.h | 2 +-
src/linux/kernel_tunnel.c | 20 ++------------------
src/win32/dummy.c | 2 +-
5 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/bsd/dummy.c b/src/bsd/dummy.c
index e619362..3ce9e80 100644
--- a/src/bsd/dummy.c
+++ b/src/bsd/dummy.c
@@ -23,7 +23,7 @@ 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)),
- bool transportV4 __attribute__ ((unused))) {
+ bool transportV4 __attribute__ ((unused)), char *name) {
return NULL;
}
diff --git a/src/gateway.c b/src/gateway.c
index e58e66a..02b6b9c 100644
--- a/src/gateway.c
+++ b/src/gateway.c
@@ -118,6 +118,18 @@ static uint8_t serialize_gw_speed(uint32_t speed) {
return ((speed - 1) << 3) | exp;
}
+/**
+ * Dummy for generating an interface name for an olsr ipip tunnel
+ * @param target IP destination of the tunnel
+ * @param name pointer to output buffer (length IFNAMSIZ)
+ */
+static void generate_iptunnel_name(union olsr_ip_addr *target, char * name) {
+ static uint32_t counter = 0;
+
+ memset(name, 0, IFNAMSIZ);
+ snprintf(name, IFNAMSIZ, "tnl_%08x", olsr_cnf->ip_version == AF_INET ? target->v4.s_addr : ++counter);
+}
+
/*
* Callback Functions
*/
@@ -612,7 +624,11 @@ bool olsr_set_inet_gateway(union olsr_ip_addr *originator, uint64_t path_cost, b
current_ipv4_gw = olsr_gw_list_update(&gw_list_ipv4, new_gw_in_list, path_cost);
} else {
/* new gw is not yet in the gw list */
- struct olsr_iptunnel_entry *new_v4gw_tunnel = olsr_os_add_ipip_tunnel(&new_gw->originator, true);
+ char name[IFNAMSIZ];
+ struct olsr_iptunnel_entry *new_v4gw_tunnel;
+
+ generate_iptunnel_name(&new_gw->originator, name);
+ new_v4gw_tunnel = olsr_os_add_ipip_tunnel(&new_gw->originator, true, name);
if (new_v4gw_tunnel) {
olsr_os_inetgw_tunnel_route(new_v4gw_tunnel->if_index, true, true, NULL);
@@ -653,7 +669,11 @@ bool olsr_set_inet_gateway(union olsr_ip_addr *originator, uint64_t path_cost, b
current_ipv6_gw = olsr_gw_list_update(&gw_list_ipv6, new_gw_in_list, path_cost);
} else {
/* new gw is not yet in the gw list */
- struct olsr_iptunnel_entry *new_v6gw_tunnel = olsr_os_add_ipip_tunnel(&new_gw->originator, false);
+ char name[IFNAMSIZ];
+ struct olsr_iptunnel_entry *new_v6gw_tunnel;
+
+ generate_iptunnel_name(&new_gw->originator, name);
+ new_v6gw_tunnel = olsr_os_add_ipip_tunnel(&new_gw->originator, false, name);
if (new_v6gw_tunnel) {
olsr_os_inetgw_tunnel_route(new_v6gw_tunnel->if_index, false, true, NULL);
diff --git a/src/kernel_tunnel.h b/src/kernel_tunnel.h
index 691191f..5603a76 100644
--- a/src/kernel_tunnel.h
+++ b/src/kernel_tunnel.h
@@ -35,7 +35,7 @@ struct olsr_iptunnel_entry {
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);
+struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target, bool transportV4, char *name);
void olsr_os_del_ipip_tunnel(struct olsr_iptunnel_entry *);
#endif /* KERNEL_TUNNEL_H_ */
diff --git a/src/linux/kernel_tunnel.c b/src/linux/kernel_tunnel.c
index 0522ae0..26d9d8b 100644
--- a/src/linux/kernel_tunnel.c
+++ b/src/linux/kernel_tunnel.c
@@ -183,38 +183,22 @@ static int os_ip_tunnel(const char *name, void *target) {
}
/**
- * Dummy for generating an interface name for an olsr ipip tunnel
- * @param target IP destination of the tunnel
- * @param name pointer to output buffer (length IFNAMSIZ)
- */
-static void generate_iptunnel_name(union olsr_ip_addr *target, char *name) {
- static char PREFIX[] = "tnl_";
- static uint32_t counter = 0;
-
- snprintf(name, IFNAMSIZ, "%s%08x", PREFIX,
- olsr_cnf->ip_version == AF_INET ? target->v4.s_addr : ++counter);
-}
-
-/**
* demands an ipip tunnel to a certain target. If no tunnel exists it will be created
* @param target ip address of the target
* @param transportV4 true if IPv4 traffic is used, false for IPv6 traffic
+ * @param name pointer to name string buffer (length IFNAMSIZ)
* @return NULL if an error happened, pointer to olsr_iptunnel_entry otherwise
*/
-struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target, bool transportV4 __attribute__ ((unused))) {
+struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target, bool transportV4 __attribute__ ((unused)), char *name) {
struct olsr_iptunnel_entry *t;
assert(olsr_cnf->ip_version == AF_INET6 || transportV4);
t = (struct olsr_iptunnel_entry *)avl_find(&tunnel_tree, target);
if (t == NULL) {
- char name[IFNAMSIZ];
int if_idx;
struct ipaddr_str buf;
- memset(name, 0, sizeof(name));
- generate_iptunnel_name(target, name);
-
if_idx = os_ip_tunnel(name, (olsr_cnf->ip_version == AF_INET) ? (void *) &target->v4.s_addr : (void *) &target->v6);
if (if_idx == 0) {
// cannot create tunnel
diff --git a/src/win32/dummy.c b/src/win32/dummy.c
index 3b655a6..bbf3ed9 100644
--- a/src/win32/dummy.c
+++ b/src/win32/dummy.c
@@ -20,7 +20,7 @@ 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)),
- bool transportV4 __attribute__ ((unused))) {
+ bool transportV4 __attribute__ ((unused)), char *name __attribute__ ((unused))) {
return NULL;
}
--
1.7.11.7
More information about the Olsr-dev
mailing list