6 * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
19 * * Neither the name of olsrd, olsr.org nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
36 * $Id: olsrd_plugin.c,v 1.8 2004/11/30 17:04:45 kattemat Exp $
41 #include "olsrd_plugin.h"
45 /* Data to sent to the plugin with the register_olsr_function call
46 * THIS STRUCT MUST MATCH ITS SIBLING IN plugin_loader.h IN OLSRD
48 struct olsr_plugin_data
51 union olsr_ip_addr *main_addr;
52 int (*olsr_plugin_io)(int, void *, size_t);
58 void __attribute__ ((constructor))
61 void __attribute__ ((destructor))
65 register_olsr_data(struct olsr_plugin_data *);
68 fetch_olsrd_data(void);
71 * Defines the version of the plugin interface that is used
72 * THIS IS NOT THE VERSION OF YOUR PLUGIN!
73 * Do not alter unless you know what you are doing!
76 get_plugin_interface_version()
78 return PLUGIN_INTERFACE_VERSION;
89 /* Print plugin info to stdout */
90 /* We cannot use olsr_printf yet! */
91 printf("%s\n", MOD_DESC);
92 printf("[ENC]Accepted parameter pairs: (\"Keyfile\" <FILENAME>)\n");
105 /* Calls the destruction function
107 * This function should be present in your
108 * sourcefile and all data destruction
109 * should happen there - NOT HERE!
118 register_olsr_param(char *key, char *value)
120 if(!strcmp(key, "Keyfile"))
122 strncpy(keyfile, value, FILENAME_MAX);
130 *Register needed functions and pointers
132 *This function should not be changed!
136 register_olsr_data(struct olsr_plugin_data *data)
139 ipversion = data->ipversion;
141 main_addr = data->main_addr;
143 /* Multi-purpose function */
144 olsr_plugin_io = data->olsr_plugin_io;
146 /* Set size of IP address */
147 if(ipversion == AF_INET)
149 ipsize = sizeof(olsr_u32_t);
153 ipsize = sizeof(struct in6_addr);
156 if(!fetch_olsrd_data())
158 fprintf(stderr, "Could not fetch the neccessary functions from olsrd!\n");
162 /* Calls the initialization function
164 * This function should be present in your
165 * sourcefile and all data initialization
166 * should happen there - NOT HERE!
168 if(!olsr_plugin_init())
170 fprintf(stderr, "Could not initialize plugin!\n");
174 if(!plugin_ipc_init())
176 fprintf(stderr, "Could not initialize plugin IPC!\n");
191 if(!olsr_plugin_io(GETF__NET_RESERVE_BUFSPACE,
192 &net_reserve_bufspace,
193 sizeof(net_reserve_bufspace)))
195 net_reserve_bufspace = NULL;
199 if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH_RESERVED,
200 &net_outbuffer_push_reserved,
201 sizeof(net_outbuffer_push_reserved)))
203 net_outbuffer_push_reserved = NULL;
207 if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH,
209 sizeof(net_outbuffer_push)))
211 net_outbuffer_push = NULL;
216 if(!olsr_plugin_io(GETF__OLSR_PRINTF,
218 sizeof(olsr_printf)))
224 if(!olsr_plugin_io(GETD__NOW,
232 if(!olsr_plugin_io(GETF__NET_OUTPUT,
240 /* Olsr malloc wrapper */
241 if(!olsr_plugin_io(GETF__OLSR_MALLOC,
243 sizeof(olsr_malloc)))
249 /* Scheduler event registration */
250 if(!olsr_plugin_io(GETF__OLSR_REGISTER_SCHEDULER_EVENT,
251 &olsr_register_scheduler_event,
252 sizeof(olsr_register_scheduler_event)))
254 olsr_register_scheduler_event = NULL;
260 if(!olsr_plugin_io(GETD__IFNET, &ifs, sizeof(ifs)))
268 /* Add socket to OLSR select function */
269 if(!olsr_plugin_io(GETF__ADD_OLSR_SOCKET, &add_olsr_socket, sizeof(add_olsr_socket)))
271 add_olsr_socket = NULL;
275 /* Remove socket from OLSR select function */
276 if(!olsr_plugin_io(GETF__REMOVE_OLSR_SOCKET, &remove_olsr_socket, sizeof(remove_olsr_socket)))
278 remove_olsr_socket = NULL;
282 /* Add packet transform function */
283 if(!olsr_plugin_io(GETF__ADD_PTF, &add_ptf, sizeof(add_ptf)))
289 /* Remove packet transform function */
290 if(!olsr_plugin_io(GETF__DEL_PTF, &del_ptf, sizeof(del_ptf)))
296 /* Get message seqno function */
297 if(!olsr_plugin_io(GETF__GET_MSG_SEQNO, &get_msg_seqno, sizeof(get_msg_seqno)))
299 get_msg_seqno = NULL;
303 /* Socket read function */
304 if(!olsr_plugin_io(GETF__OLSR_INPUT, &olsr_input, sizeof(olsr_input)))
310 /* Default packet parser */
311 if(!olsr_plugin_io(GETF__PARSE_PACKET, &parse_packet, sizeof(parse_packet)))
317 /* Find interface by socket */
318 if(!olsr_plugin_io(GETF__IF_IFWITHSOCK, &if_ifwithsock, sizeof(if_ifwithsock)))
320 if_ifwithsock = NULL;
324 /* Find interface by address */
325 if(!olsr_plugin_io(GETF__IF_IFWITHADDR, &if_ifwithaddr, sizeof(if_ifwithaddr)))
327 if_ifwithaddr = NULL;
332 /* Add ifchange function */
333 if(!olsr_plugin_io(GETF__ADD_IFCHGF, &add_ifchgf, sizeof(add_ifchgf)))
339 /* Remove ifchange function */
340 if(!olsr_plugin_io(GETF__DEL_IFCHGF, &del_ifchgf, sizeof(del_ifchgf)))