diff -Nur olsrd-0.4.10.orig/src/main.c olsrd-0.4.10/src/main.c --- olsrd-0.4.10.orig/src/main.c 2005-09-29 07:53:34.000000000 +0200 +++ olsrd-0.4.10/src/main.c 2006-12-01 09:10:15.000000000 +0100 @@ -280,6 +280,9 @@ /* Initialize parser */ olsr_init_parser(); + /* Initialize route-exporter */ + olsr_init_export_route(); + /* Initialize message sequencnumber */ init_msg_seqno(); diff -Nur olsrd-0.4.10.orig/src/process_routes.c olsrd-0.4.10/src/process_routes.c --- olsrd-0.4.10.orig/src/process_routes.c 2005-05-30 15:13:38.000000000 +0200 +++ olsrd-0.4.10/src/process_routes.c 2006-12-01 09:10:15.000000000 +0100 @@ -3,6 +3,9 @@ * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org) * All rights reserved. * + * export_route_entry interface added by Immo 'FaUl Wehrenberg + * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -39,7 +42,6 @@ * $Id: process_routes.c,v 1.27 2005/05/30 13:13:38 kattemat Exp $ */ - #include "defs.h" #include "olsr.h" #include "log.h" @@ -51,10 +53,162 @@ #define strerror(x) StrError(x) #endif +struct export_route_entry +{ + olsr_u8_t type; /* AF_INET/AF_INET6 */ + int (*function)(struct rt_entry*); + struct export_route_entry *next; +}; + + +static struct export_route_entry *add_routes; +static struct export_route_entry *del_routes; + struct rt_entry old_routes[HASHSIZE]; struct rt_entry old_hna[HASHSIZE]; +void +olsr_addroute_add_function(int (*function)(struct rt_entry*), olsr_u8_t type) +{ + struct export_route_entry *tmp; + tmp = olsr_malloc(sizeof *tmp, "olsr_addroute_add_function"); + tmp->type = type; + tmp->function = function; + tmp->next = add_routes; + add_routes = tmp; +} + +void +olsr_delroute_add_function(int (*function) (struct rt_entry*), olsr_u8_t type) +{ + struct export_route_entry *tmp; + tmp = olsr_malloc(sizeof *tmp, "olsr_delroute_add_function"); + tmp->type = type; + tmp->function = function; + tmp->next = del_routes; + del_routes = tmp; +} + + +int +olsr_addroute_remove_function(int (*function) (struct rt_entry*), olsr_u8_t type) +{ + struct export_route_entry *tmp, *prev = NULL /* Make compiler happy */; + tmp = add_routes; + while (tmp) + { + if (function == tmp->function && type == tmp->type) + { + if (tmp == add_routes) + { + add_routes = add_routes->next; + free (tmp); + return 1; + } + else + { + prev->next = tmp->next; + free (tmp); + return 1; + } + } + prev = tmp; + tmp = tmp->next; + } + return 0; +} + +int +olsr_delroute_remove_function(int (*function) (struct rt_entry*), olsr_u8_t type) +{ + struct export_route_entry *tmp, *prev = NULL /* Make compiler happy */; + tmp = del_routes; + while (tmp) + { + if (function == tmp->function && type == tmp->type) + { + if (tmp == del_routes) + { + del_routes = del_routes->next; + free (tmp); + return 1; + } + else + { + prev->next = tmp->next; + free (tmp); + return 1; + } + } + prev = tmp; + tmp = tmp->next; + } + return 0; +} + +void +olsr_init_export_route() +{ + olsr_addroute_add_function(&olsr_ioctl_add_route, AF_INET); + olsr_addroute_add_function(&olsr_ioctl_add_route6, AF_INET6); + olsr_delroute_add_function(&olsr_ioctl_del_route, AF_INET); + olsr_delroute_add_function(&olsr_ioctl_del_route6, AF_INET6); +} + +int +olsr_export_add_route (struct rt_entry *e) +{ + int retval = 0; + struct export_route_entry *tmp; + for (tmp = add_routes; tmp; tmp = tmp->next) + { + if (tmp->type == AF_INET) + retval = tmp->function(e); + } + return retval; +} + +int +olsr_export_add_route6 (struct rt_entry *e) +{ + int retval = 0; + struct export_route_entry *tmp; + for (tmp = add_routes; tmp; tmp = tmp->next) + { + if (tmp->type == AF_INET6) + retval = tmp->function(e); + } + return retval; +} + +int +olsr_export_del_route (struct rt_entry *e) +{ + int retval = 0; + struct export_route_entry *tmp; + for (tmp = del_routes; tmp; tmp = tmp->next) + { + if (tmp->type == AF_INET) + retval = tmp->function(e); + } + return retval; +} + +int +olsr_export_del_route6 (struct rt_entry *e) +{ + int retval = 0; + struct export_route_entry *tmp; + for (tmp = del_routes; tmp; tmp = tmp->next) + { + if (tmp->type == AF_INET6) + retval = tmp->function(e); + } + return retval; +} + + int olsr_init_old_table() @@ -348,9 +502,9 @@ if(!olsr_cnf->host_emul) { if(olsr_cnf->ip_version == AF_INET) - error = olsr_ioctl_del_route(destination_ptr->destination); + error = olsr_export_del_route(destination_ptr->destination); else - error = olsr_ioctl_del_route6(destination_ptr->destination); + error = olsr_export_del_route6(destination_ptr->destination); if(error < 0) { @@ -436,9 +590,9 @@ if(!olsr_cnf->host_emul) { if(olsr_cnf->ip_version == AF_INET) - error=olsr_ioctl_add_route(destination_kernel->destination); + error=olsr_export_add_route(destination_kernel->destination); else - error=olsr_ioctl_add_route6(destination_kernel->destination); + error=olsr_export_add_route6(destination_kernel->destination); if(error < 0) { diff -Nur olsrd-0.4.10.orig/src/process_routes.h olsrd-0.4.10/src/process_routes.h --- olsrd-0.4.10.orig/src/process_routes.h 2005-05-29 14:47:45.000000000 +0200 +++ olsrd-0.4.10/src/process_routes.h 2006-12-01 09:10:15.000000000 +0100 @@ -50,6 +50,34 @@ extern struct rt_entry old_routes[HASHSIZE]; extern struct rt_entry old_hna[HASHSIZE]; +void +olsr_init_export_route(void); + +void +olsr_addroute_add_function(int (*)(struct rt_entry*), olsr_u8_t); + +int +olsr_addroute_remove_function(int (*)(struct rt_entry*), olsr_u8_t); + +void +olsr_delroute_add_function(int (*)(struct rt_entry*), olsr_u8_t); + +int +olsr_delroute_remove_function(int (*)(struct rt_entry*), olsr_u8_t); + +int +olsr_export_add_route (struct rt_entry*); + +int +olsr_export_del_route (struct rt_entry*); + +int +olsr_export_add_route6 (struct rt_entry*); + +int +olsr_export_del_route6 (struct rt_entry*); + + int olsr_init_old_table(void);