2 * OLSR Basic Multicast Forwarding (BMF) plugin.
3 * Copyright (c) 2005 - 2007, Thales Communications, Huizen, The Netherlands.
4 * Written by Erik Tromp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Thales, BMF nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* -------------------------------------------------------------------------
34 * File : olsrd_plugin.c
35 * Description: Interface to the OLSRD plugin system
36 * Created : 29 Jun 2006
38 * ------------------------------------------------------------------------- */
41 #include <assert.h> /* assert() */
42 #include <stddef.h> /* NULL */
45 #include "olsrd_plugin.h"
46 #include "defs.h" /* olsr_u8_t, olsr_cnf */
47 #include "scheduler.h" /* olsr_register_scheduler_event */
50 #include "Bmf.h" /* InitBmf(), CloseBmf(), RegisterBmfParameter() */
51 #include "PacketHistory.h" /* InitPacketHistory() */
53 #define PLUGIN_INTERFACE_VERSION 4
55 static void __attribute__ ((constructor)) my_init(void);
56 static void __attribute__ ((destructor)) my_fini(void);
58 void olsr_plugin_exit(void);
60 /* -------------------------------------------------------------------------
61 * Function : olsrd_plugin_interface_version
62 * Description: Plugin interface version
65 * Return : BMF plugin interface version number
67 * Notes : Called by main OLSRD (olsr_load_dl) to check plugin interface
69 * ------------------------------------------------------------------------- */
70 int olsrd_plugin_interface_version(void)
72 return PLUGIN_INTERFACE_VERSION;
75 /* -------------------------------------------------------------------------
76 * Function : olsrd_plugin_init
77 * Description: Plugin initialisation
80 * Return : fail (0) or success (1)
81 * Data Used : olsr_cnf
82 * Notes : Called by main OLSRD (init_olsr_plugin) to initialize plugin
83 * ------------------------------------------------------------------------- */
84 int olsrd_plugin_init(void)
87 if (olsr_cnf->ip_version != AF_INET)
89 fprintf(stderr, PLUGIN_NAME ": This plugin only supports IPv4!\n");
93 /* Clear the packet history */
96 /* Register ifchange function */
97 add_ifchgf(&InterfaceChange);
99 /* Register the duplicate registration pruning process */
100 olsr_register_scheduler_event(&PrunePacketHistory, NULL, 3.0, 2.0, NULL);
102 return InitBmf(NULL);
105 /* -------------------------------------------------------------------------
106 * Function : olsr_plugin_exit
107 * Description: Plugin cleanup
112 * Notes : Called by my_fini() at unload of shared object
113 * ------------------------------------------------------------------------- */
114 void olsr_plugin_exit(void)
119 /* -------------------------------------------------------------------------
120 * Function : olsrd_plugin_register_param
121 * Description: Register parameters from config file
122 * Input : key - the parameter name
123 * value - the parameter value
125 * Return : fatal error (<0), minor error (0) or success (>0)
127 * Notes : Called by main OLSR (init_olsr_plugin) for all plugin parameters
128 * ------------------------------------------------------------------------- */
129 int olsrd_plugin_register_param(char* key, char* value)
131 assert(key != NULL && value != NULL);
133 return RegisterBmfParameter(key, value);
136 /* -------------------------------------------------------------------------
138 * Description: Plugin constructor
143 * Notes : Called at load of shared object
144 * ------------------------------------------------------------------------- */
145 static void my_init(void)
147 /* Print plugin info to stdout */
148 printf("%s\n", MOD_DESC);
153 /* -------------------------------------------------------------------------
155 * Description: Plugin destructor
160 * Notes : Called at unload of shared object
161 * ------------------------------------------------------------------------- */
162 static void my_fini(void)