3 * Copyright (c) 2004, Andreas Tønnesen(andreto-at-olsr.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither the name of the UniK olsr daemon nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 /* $Id: olsrd_plugin.c,v 1.3 2004/11/30 17:04:45 kattemat Exp $ */
36 * Dynamic linked library example for UniK OLSRd
40 #include "olsrd_plugin.h"
44 /* Data to sent to the plugin with the register_olsr_function call
45 * THIS STRUCT MUST MATCH ITS SIBLING IN plugin_loader.h IN OLSRD
47 struct olsr_plugin_data
50 union olsr_ip_addr *main_addr;
51 int (*olsr_plugin_io)(int, void *, size_t);
56 * "Private" declarations
59 void __attribute__ ((constructor))
62 void __attribute__ ((destructor))
66 register_olsr_data(struct olsr_plugin_data *);
69 fetch_olsrd_data(void);
72 * Returns the version of the plugin interface that is used
73 * THIS IS NOT THE VERSION OF YOUR PLUGIN!
76 get_plugin_interface_version()
78 return PLUGIN_INTERFACE_VERSION;
87 /* Print plugin info to stdout */
88 printf("%s\n", MOD_DESC);
102 /* Calls the destruction function
104 * This function should be present in your
105 * sourcefile and all data destruction
106 * should happen there - NOT HERE!
115 *Register needed functions and pointers
117 *This function should not be changed!
121 register_olsr_data(struct olsr_plugin_data *data)
124 ipversion = data->ipversion;
126 main_addr = data->main_addr;
128 /* Multi-purpose function */
129 olsr_plugin_io = data->olsr_plugin_io;
131 /* Set size of IP address */
132 if(ipversion == AF_INET)
134 ipsize = sizeof(olsr_u32_t);
138 ipsize = sizeof(struct in6_addr);
141 if(!fetch_olsrd_data())
143 fprintf(stderr, "Could not fetch the neccessary functions from olsrd!\n");
147 /* Calls the initialization function
149 * This function should be present in your
150 * sourcefile and all data initialization
151 * should happen there - NOT HERE!
153 if(!olsr_plugin_init())
155 fprintf(stderr, "Could not initialize plugin!\n");
159 if(!plugin_ipc_init())
161 fprintf(stderr, "Could not initialize plugin IPC!\n");
177 if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH, &net_outbuffer_push, sizeof(net_outbuffer_push)))
179 net_outbuffer_push = NULL;
183 /* Olsr debug output function */
184 if(!olsr_plugin_io(GETF__OLSR_PRINTF,
186 sizeof(olsr_printf)))
193 /* Olsr malloc wrapper */
194 if(!olsr_plugin_io(GETF__OLSR_MALLOC,
196 sizeof(olsr_malloc)))
202 /* Parser registration */
203 if(!olsr_plugin_io(GETF__OLSR_PARSER_ADD_FUNCTION,
204 &olsr_parser_add_function,
205 sizeof(olsr_parser_add_function)))
207 olsr_parser_add_function = NULL;
211 /* Scheduler timeout registration */
212 if(!olsr_plugin_io(GETF__OLSR_REGISTER_TIMEOUT_FUNCTION,
213 &olsr_register_timeout_function,
214 sizeof(olsr_register_timeout_function)))
216 olsr_register_timeout_function = NULL;
220 /* Scheduler event registration */
221 if(!olsr_plugin_io(GETF__OLSR_REGISTER_SCHEDULER_EVENT,
222 &olsr_register_scheduler_event,
223 sizeof(olsr_register_scheduler_event)))
225 olsr_register_scheduler_event = NULL;
229 /* Double to mantissa/exponent */
230 if(!olsr_plugin_io(GETF__DOUBLE_TO_ME,
232 sizeof(double_to_me)))
240 /* Mantissa/exponent to double conversion */
241 if(!olsr_plugin_io(GETF__ME_TO_DOUBLE,
243 sizeof(me_to_double)))
251 if(!olsr_plugin_io(GETD__IFNET, &ifs, sizeof(ifs)))
257 /* Messageseqno fetch function */
258 if(!olsr_plugin_io(GETF__GET_MSG_SEQNO, &get_msg_seqno, sizeof(get_msg_seqno)))
260 get_msg_seqno = NULL;
264 /* Scheduler maintained timestamp */
265 if(!olsr_plugin_io(GETD__NOW, &now, sizeof(now)))
271 /* Output function */
272 if(!olsr_plugin_io(GETF__NET_OUTPUT, &net_output, sizeof(net_output)))
278 /* Duplicate check (for processing) */
279 if(!olsr_plugin_io(GETF__OLSR_CHECK_DUP_TABLE_PROC, &check_dup_proc, sizeof(check_dup_proc)))
281 check_dup_proc = NULL;
285 /* Default forward function */
286 if(!olsr_plugin_io(GETF__OLSR_FORWARD_MESSAGE, &default_fwd, sizeof(default_fwd)))
293 /* Add socket to OLSR select function */
294 if(!olsr_plugin_io(GETF__ADD_OLSR_SOCKET, &add_olsr_socket, sizeof(add_olsr_socket)))
296 add_olsr_socket = NULL;
300 /* Neighbor link status lookup */
301 if(!olsr_plugin_io(GETF__CHECK_NEIGHBOR_LINK, &check_neighbor_link, sizeof(check_neighbor_link)))
303 check_neighbor_link = NULL;
309 if(!olsr_plugin_io(GETF__APM_READ, &apm_read, sizeof(apm_read)))