00001 00002 /* 00003 * OLSR Basic Multicast Forwarding (BMF) plugin. 00004 * Copyright (c) 2005 - 2007, Thales Communications, Huizen, The Netherlands. 00005 * Written by Erik Tromp. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * * Neither the name of Thales, BMF nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00024 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00025 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00026 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00029 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00030 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00031 * OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 /* ------------------------------------------------------------------------- 00035 * File : olsrd_plugin.c 00036 * Description: Interface to the OLSRD plugin system 00037 * Created : 29 Jun 2006 00038 * 00039 * ------------------------------------------------------------------------- */ 00040 00041 /* System includes */ 00042 #include <assert.h> /* assert() */ 00043 #include <stddef.h> /* NULL */ 00044 00045 /* OLSRD includes */ 00046 #include "plugin.h" 00047 #include "plugin_util.h" 00048 #include "defs.h" /* uint8_t, olsr_cnf */ 00049 #include "olsr_timer.h" 00050 #include "olsr_socket.h" /* olsr_timer_start() */ 00051 #include "olsr_cfg.h" /* olsr_cnf() */ 00052 #include "olsr_memcookie.h" /* olsr_memcookie_add() */ 00053 #include "olsr_logging.h" 00054 00055 /* BMF includes */ 00056 #include "Bmf.h" /* InitBmf(), CloseBmf() */ 00057 #include "PacketHistory.h" /* InitPacketHistory() */ 00058 #include "NetworkInterfaces.h" /* AddNonOlsrBmfIf(), SetBmfInterfaceIp(), ... */ 00059 #include "Address.h" /* DoLocalBroadcast() */ 00060 00061 static void __attribute__ ((constructor)) my_init(void); 00062 static void __attribute__ ((destructor)) my_fini(void); 00063 00064 static struct olsr_timer_info *prune_packet_history_timer_info; 00065 00066 void olsr_plugin_exit(void); 00067 00068 /* ------------------------------------------------------------------------- 00069 * Function : olsrd_plugin_interface_version 00070 * Description: Plugin interface version 00071 * Input : none 00072 * Output : none 00073 * Return : BMF plugin interface version number 00074 * Data Used : none 00075 * Notes : Called by main OLSRD (olsr_load_dl) to check plugin interface 00076 * version 00077 * ------------------------------------------------------------------------- */ 00078 int 00079 olsrd_plugin_interface_version(void) 00080 { 00081 return PLUGIN_INTERFACE_VERSION; 00082 } 00083 00084 /* ------------------------------------------------------------------------- 00085 * Function : olsrd_plugin_init 00086 * Description: Plugin initialisation 00087 * Input : none 00088 * Output : none 00089 * Return : fail (0) or success (1) 00090 * Data Used : olsr_cnf 00091 * Notes : Called by main OLSRD (init_olsr_plugin) to initialize plugin 00092 * ------------------------------------------------------------------------- */ 00093 int 00094 olsrd_plugin_init(void) 00095 { 00096 /* Check validity */ 00097 if (olsr_cnf->ip_version != AF_INET) { 00098 OLSR_WARN(LOG_PLUGINS, PLUGIN_NAME ": This plugin only supports IPv4!\n"); 00099 return 0; 00100 } 00101 00102 /* Clear the packet history */ 00103 InitPacketHistory(); 00104 00105 /* Register ifchange function */ 00106 add_ifchgf(&InterfaceChange); 00107 00108 /* create the cookie */ 00109 prune_packet_history_timer_info = 00110 olsr_timer_add("BMF: Prune Packet History", &PrunePacketHistory, true); 00111 00112 /* Register the duplicate registration pruning process */ 00113 olsr_timer_start(3 * MSEC_PER_SEC, 0, NULL, prune_packet_history_timer_info); 00114 00115 00116 return InitBmf(NULL); 00117 } 00118 00119 /* ------------------------------------------------------------------------- 00120 * Function : olsr_plugin_exit 00121 * Description: Plugin cleanup 00122 * Input : none 00123 * Output : none 00124 * Return : none 00125 * Data Used : none 00126 * Notes : Called by my_fini() at unload of shared object 00127 * ------------------------------------------------------------------------- */ 00128 void 00129 olsr_plugin_exit(void) 00130 { 00131 CloseBmf(); 00132 } 00133 00134 static const struct olsrd_plugin_parameters plugin_parameters[] = { 00135 {.name = "NonOlsrIf",.set_plugin_parameter = &AddNonOlsrBmfIf,.data = NULL}, 00136 {.name = "DoLocalBroadcast",.set_plugin_parameter = &DoLocalBroadcast,.data = NULL}, 00137 {.name = "BmfInterface",.set_plugin_parameter = &SetBmfInterfaceName,.data = NULL}, 00138 {.name = "BmfInterfaceIp",.set_plugin_parameter = &SetBmfInterfaceIp,.data = NULL}, 00139 {.name = "CapturePacketsOnOlsrInterfaces",.set_plugin_parameter = &SetCapturePacketsOnOlsrInterfaces,.data = NULL}, 00140 {.name = "BmfMechanism",.set_plugin_parameter = &SetBmfMechanism,.data = NULL}, 00141 {.name = "FanOutLimit",.set_plugin_parameter = &SetFanOutLimit,.data = NULL}, 00142 {.name = "BroadcastRetransmitCount",.set_plugin_parameter = &set_plugin_int,.data = &BroadcastRetransmitCount}, 00143 }; 00144 00145 /* ------------------------------------------------------------------------- 00146 * Function : olsrd_get_plugin_parameters 00147 * Description: Return the parameter table and its size 00148 * Input : none 00149 * Output : params - the parameter table 00150 * size - its size in no. of entries 00151 * Return : none 00152 * Data Used : plugin_parameters 00153 * Notes : Called by main OLSR (init_olsr_plugin) for all plugins 00154 * ------------------------------------------------------------------------- */ 00155 void 00156 olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size) 00157 { 00158 *params = plugin_parameters; 00159 *size = ARRAYSIZE(plugin_parameters); 00160 } 00161 00162 /* ------------------------------------------------------------------------- 00163 * Function : my_init 00164 * Description: Plugin constructor 00165 * Input : none 00166 * Output : none 00167 * Return : none 00168 * Data Used : none 00169 * Notes : Called at load of shared object 00170 * ------------------------------------------------------------------------- */ 00171 static void 00172 my_init(void) 00173 { 00174 /* Print plugin info to stdout */ 00175 OLSR_INFO(LOG_PLUGINS, "%s\n", MOD_DESC); 00176 00177 return; 00178 } 00179 00180 /* ------------------------------------------------------------------------- 00181 * Function : my_fini 00182 * Description: Plugin destructor 00183 * Input : none 00184 * Output : none 00185 * Return : none 00186 * Data Used : none 00187 * Notes : Called at unload of shared object 00188 * ------------------------------------------------------------------------- */ 00189 static void 00190 my_fini(void) 00191 { 00192 olsr_plugin_exit(); 00193 } 00194 00195 /* 00196 * Local Variables: 00197 * c-basic-offset: 2 00198 * indent-tabs-mode: nil 00199 * End: 00200 */
1.6.3