2 * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
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.2 2005/01/30 16:20:36 kattemat Exp $ */
36 * Dynamic linked library example for UniK OLSRd
42 #include "olsrd_plugin.h"
43 #include "nameservice.h"
49 /* strndup() is a GNU extention */
51 strndup(const char *ptr, size_t size)
53 int len = strlen(ptr);
62 ret = malloc(len + 1);
67 strncpy(ret, ptr, len);
75 /* Data to sent to the plugin with the register_olsr_function call
76 * THIS STRUCT MUST MATCH ITS SIBLING IN plugin_loader.h IN OLSRD
78 struct olsr_plugin_data
81 union olsr_ip_addr *main_addr;
82 int (*olsr_plugin_io)(int, void *, size_t);
87 * "Private" declarations
90 void __attribute__ ((constructor))
93 void __attribute__ ((destructor))
97 register_olsr_data(struct olsr_plugin_data *);
100 fetch_olsrd_data(void);
103 * Returns the version of the plugin interface that is used
104 * THIS IS NOT THE VERSION OF YOUR PLUGIN!
107 get_plugin_interface_version()
109 return PLUGIN_INTERFACE_VERSION;
118 /* Print plugin info to stdout */
119 printf("%s\n", MOD_DESC);
133 /* Calls the destruction function
135 * This function should be present in your
136 * sourcefile and all data destruction
137 * should happen there - NOT HERE!
144 /* Mulitpurpose funtion */
146 plugin_io(int cmd, void *data, size_t size)
159 register_olsr_param(char *key, char *value)
161 if(!strcmp(key, "name")) {
162 my_name = strndup( value, MAX_NAME );
163 my_name_len = strlen( my_name );
164 printf("(NAME) name: %s\n", my_name);
167 if(!strcmp(key, "filename")) {
168 my_filename = strndup( value, MAX_FILE );
169 printf("(NAME) filename: %s\n", my_filename);
177 *Register needed functions and pointers
179 *This function should not be changed!
183 register_olsr_data(struct olsr_plugin_data *data)
186 ipversion = data->ipversion;
188 main_addr = data->main_addr;
190 /* Multi-purpose function */
191 olsr_plugin_io = data->olsr_plugin_io;
193 /* Set size of IP address */
194 if(ipversion == AF_INET)
196 ipsize = sizeof(olsr_u32_t);
200 ipsize = sizeof(struct in6_addr);
203 if(!fetch_olsrd_data())
205 fprintf(stderr, "Could not fetch the neccessary functions from olsrd!\n");
209 /* Calls the initialization function
211 * This function should be present in your
212 * sourcefile and all data initialization
213 * should happen there - NOT HERE!
215 if(!olsr_plugin_init())
217 fprintf(stderr, "Could not initialize plugin!\n");
233 if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH, &net_outbuffer_push, sizeof(net_outbuffer_push)))
235 net_outbuffer_push = NULL;
239 /* Olsr debug output function */
240 if(!olsr_plugin_io(GETF__OLSR_PRINTF,
242 sizeof(olsr_printf)))
249 /* Olsr malloc wrapper */
250 if(!olsr_plugin_io(GETF__OLSR_MALLOC,
252 sizeof(olsr_malloc)))
258 /* Parser registration */
259 if(!olsr_plugin_io(GETF__OLSR_PARSER_ADD_FUNCTION,
260 &olsr_parser_add_function,
261 sizeof(olsr_parser_add_function)))
263 olsr_parser_add_function = NULL;
267 /* Scheduler timeout registration */
268 if(!olsr_plugin_io(GETF__OLSR_REGISTER_TIMEOUT_FUNCTION,
269 &olsr_register_timeout_function,
270 sizeof(olsr_register_timeout_function)))
272 olsr_register_timeout_function = NULL;
276 /* Scheduler event registration */
277 if(!olsr_plugin_io(GETF__OLSR_REGISTER_SCHEDULER_EVENT,
278 &olsr_register_scheduler_event,
279 sizeof(olsr_register_scheduler_event)))
281 olsr_register_scheduler_event = NULL;
285 /* Double to mantissa/exponent */
286 if(!olsr_plugin_io(GETF__DOUBLE_TO_ME,
288 sizeof(double_to_me)))
296 /* Mantissa/exponent to double conversion */
297 if(!olsr_plugin_io(GETF__ME_TO_DOUBLE,
299 sizeof(me_to_double)))
307 if(!olsr_plugin_io(GETD__IFNET, &ifs, sizeof(ifs)))
313 /* Messageseqno fetch function */
314 if(!olsr_plugin_io(GETF__GET_MSG_SEQNO, &get_msg_seqno, sizeof(get_msg_seqno)))
316 get_msg_seqno = NULL;
320 /* Scheduler maintained timestamp */
321 if(!olsr_plugin_io(GETD__NOW, &now, sizeof(now)))
327 /* Output function */
328 if(!olsr_plugin_io(GETF__NET_OUTPUT, &net_output, sizeof(net_output)))
334 /* Duplicate check (for processing) */
335 if(!olsr_plugin_io(GETF__OLSR_CHECK_DUP_TABLE_PROC, &check_dup_proc, sizeof(check_dup_proc)))
337 check_dup_proc = NULL;
341 /* Default forward function */
342 if(!olsr_plugin_io(GETF__OLSR_FORWARD_MESSAGE, &default_fwd, sizeof(default_fwd)))
349 /* Add socket to OLSR select function */
350 if(!olsr_plugin_io(GETF__ADD_OLSR_SOCKET, &add_olsr_socket, sizeof(add_olsr_socket)))
352 add_olsr_socket = NULL;
356 /* Neighbor link status lookup */
357 if(!olsr_plugin_io(GETF__CHECK_NEIGHBOR_LINK, &check_neighbor_link, sizeof(check_neighbor_link)))
359 check_neighbor_link = NULL;