diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/Makefile olsrd-0.4.10/lib/dyn_gw_plain/Makefile --- olsrd-0.4.10.orig/lib/dyn_gw_plain/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ olsrd-0.4.10/lib/dyn_gw_plain/Makefile 2006-12-01 08:26:58.000000000 +0100 @@ -0,0 +1,57 @@ +# The olsr.org Optimized Link-State Routing daemon(olsrd) +# Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org) +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of olsr.org, olsrd nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# Visit http://www.olsr.org for more information. +# +# If you find this software useful feel free to make a donation +# to the project. For more information see the website or contact +# the copyright holders. +# +# $Id: olsrd-dyngwplain.patch,v 1.5 2006/12/04 08:33:46 sven-ola Exp $ + +OLSRD_PLUGIN = true +PLUGIN_NAME = olsrd_dyn_gw_plain +PLUGIN_VER = 0.4 + +TOPDIR = ../.. +include $(TOPDIR)/Makefile.inc + +default_target: $(PLUGIN_FULLNAME) + +$(PLUGIN_FULLNAME): $(OBJS) + $(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS) + +install: $(PLUGIN_FULLNAME) + $(STRIP) $(PLUGIN_FULLNAME) + $(INSTALL_LIB) + +clean: + rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME) diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/README_DYN_GW_PLAIN olsrd-0.4.10/lib/dyn_gw_plain/README_DYN_GW_PLAIN --- olsrd-0.4.10.orig/lib/dyn_gw_plain/README_DYN_GW_PLAIN 1970-01-01 01:00:00.000000000 +0100 +++ olsrd-0.4.10/lib/dyn_gw_plain/README_DYN_GW_PLAIN 2006-12-01 08:26:58.000000000 +0100 @@ -0,0 +1,17 @@ +DYNAMIC INTERNET GATEWAY PLAIN PLUGIN FOR olsr.org olsrd +by Andreas Tønnesen(andreto@olsr.org) +additions by Sven-Ola Tuecke + +This plugin is without Ping/libthread. It is the plain dyn_gw! + +HOW TO USE + +Add an entry like this to your olsrd configuration file: + +LoadPlugin "olsrd_dyn_gw_plain.so.0.4" +{ +} + +ABOUT + +Plugin is IPv4 only. diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c --- olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c 1970-01-01 01:00:00.000000000 +0100 +++ olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c 2006-12-01 08:26:58.000000000 +0100 @@ -0,0 +1,186 @@ +/* + * The olsr.org Optimized Link-State Routing daemon(olsrd) + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of olsr.org, olsrd nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Visit http://www.olsr.org for more information. + * + * If you find this software useful feel free to make a donation + * to the project. For more information see the website or contact + * the copyright holders. + */ + +#include "olsr_types.h" +#include "olsrd_dyn_gw_plain.h" +#include "scheduler.h" +#include "olsr.h" +#include "local_hna_set.h" +#include +#include +#include +#include +#include +#include +#include + +#define DEBUGLEV 1 + +static int has_inet_gateway; + +/** + * Plugin interface version + * Used by main olsrd to check plugin interface version + */ +int +olsrd_plugin_interface_version() +{ + return OLSRD_PLUGIN_INTERFACE_VERSION; +} + +/** + * Register parameters from config file + * Called for all plugin parameters + */ +int +olsrd_plugin_register_param(char *key, char *value) +{ + return 1; +} + +/** + * Initialize plugin + * Called after all parameters are passed + */ +int +olsrd_plugin_init() +{ + gw_net.v4 = INET_NET; + gw_netmask.v4 = INET_PREFIX; + + has_inet_gateway = 0; + + /* Remove all local Inet HNA entries */ + while(remove_local_hna4_entry(&gw_net, &gw_netmask)) { + olsr_printf(DEBUGLEV, "HNA Internet gateway deleted\n"); + } + + /* Register the GW check */ + olsr_register_scheduler_event(&olsr_event, NULL, 3, 4, NULL); + + return 1; +} + +int +check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask) +{ + char buff[1024], iface[16]; + olsr_u32_t gate_addr, dest_addr, netmask; + unsigned int iflags; + int num, metric, refcnt, use; + int retval = 0; + + FILE *fp = fopen(PROCENTRY_ROUTE, "r"); + + if (!fp) + { + perror(PROCENTRY_ROUTE); + olsr_printf(DEBUGLEV, "INET (IPv4) not configured in this system.\n"); + return -1; + } + + rewind(fp); + + /* + olsr_printf(DEBUGLEV, "Genmask Destination Gateway " + "Flags Metric Ref Use Iface\n"); + /**/ + while (fgets(buff, 1023, fp)) + { + num = sscanf(buff, "%16s %128X %128X %X %d %d %d %128X \n", + iface, &dest_addr, &gate_addr, + &iflags, &refcnt, &use, &metric, &netmask); + + if (num < 8) + { + continue; + } + + /* + olsr_printf(DEBUGLEV, "%-15s ", olsr_ip_to_string((union olsr_ip_addr *)&netmask)); + + olsr_printf(DEBUGLEV, "%-15s ", olsr_ip_to_string((union olsr_ip_addr *)&dest_addr)); + + olsr_printf(DEBUGLEV, "%-15s %-6d %-2d %7d %s\n", + olsr_ip_to_string((union olsr_ip_addr *)&gate_addr), + metric, refcnt, use, iface); + /**/ + + if(//(iflags & RTF_GATEWAY) && + (iflags & RTF_UP) && + (metric == 0) && + (netmask == mask->v4) && + (dest_addr == net->v4)) + { + olsr_printf(DEBUGLEV, "INTERNET GATEWAY VIA %s detected in routing table.\n", iface); + retval=1; + } + + } + + fclose(fp); + + if(retval == 0) + { + olsr_printf(DEBUGLEV, "No Internet GWs detected...\n"); + } + + return retval; +} + +/** + * Scheduled event to update the hna table, + * called from olsrd main thread to keep the hna table thread-safe + */ +void olsr_event(void* foo) +{ + int res = check_gw(&gw_net, &gw_netmask); + if (1 == res && 0 == has_inet_gateway) { + olsr_printf(DEBUGLEV, "Adding OLSR local HNA entry for Internet\n"); + add_local_hna4_entry(&gw_net, &gw_netmask); + has_inet_gateway = 1; + } + else if (0 == res && 1 == has_inet_gateway) { + /* Remove all local Inet HNA entries */ + while(remove_local_hna4_entry(&gw_net, &gw_netmask)) { + olsr_printf(DEBUGLEV, "Removing OLSR local HNA entry for Internet\n"); + } + has_inet_gateway = 0; + } +} diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h --- olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h 1970-01-01 01:00:00.000000000 +0100 +++ olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h 2006-12-01 08:26:58.000000000 +0100 @@ -0,0 +1,59 @@ +/* + * The olsr.org Optimized Link-State Routing daemon(olsrd) + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of olsr.org, olsrd nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Visit http://www.olsr.org for more information. + * + * If you find this software useful feel free to make a donation + * to the project. For more information see the website or contact + * the copyright holders. + */ + +#ifndef _OLSRD_PLUGIN_TEST +#define _OLSRD_PLUGIN_TEST + +#include "olsrd_plugin.h" +#include "olsr.h" + +#define INET_NET 0 +#define INET_PREFIX 0 + +#define PROCENTRY_ROUTE "/proc/net/route" + +union olsr_ip_addr gw_net; +union olsr_ip_addr gw_netmask; + +int check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask); + +/* Event function to register with the scheduler */ +void olsr_event(void* foo); + +#endif diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/version-script.txt olsrd-0.4.10/lib/dyn_gw_plain/version-script.txt --- olsrd-0.4.10.orig/lib/dyn_gw_plain/version-script.txt 1970-01-01 01:00:00.000000000 +0100 +++ olsrd-0.4.10/lib/dyn_gw_plain/version-script.txt 2006-12-01 08:26:58.000000000 +0100 @@ -0,0 +1,10 @@ +VERS_1.0 +{ + global: + olsrd_plugin_interface_version; + olsrd_plugin_register_param; + olsrd_plugin_init; + + local: + *; +}; diff -Nur olsrd-0.4.10.orig/Makefile olsrd-0.4.10/Makefile --- olsrd-0.4.10.orig/Makefile 2006-01-04 09:45:38.000000000 +0100 +++ olsrd-0.4.10/Makefile 2006-12-01 08:26:58.000000000 +0100 @@ -144,6 +144,11 @@ $(MAKE) -C lib/dyn_gw $(MAKE) -C lib/dyn_gw install +dyn_gw_plain: + $(MAKE) -C lib/dyn_gw_plain clean + $(MAKE) -C lib/dyn_gw_plain + $(MAKE) -C lib/dyn_gw_plain install + powerinfo: $(MAKE) -C lib/powerinfo clean $(MAKE) -C lib/powerinfo