4 * Copyright (c) 2004, Andreas Tønnesen(andreto-at-olsr.org)
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 notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * * Neither the name of the UniK olsr daemon nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Dynamic linked library example for UniK OLSRd
37 #ifndef _OLSRD_PLUGIN_DEFS
38 #define _OLSRD_PLUGIN_DEFS
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
48 #include "olsr_plugin_io.h"
50 /* Use this as PARSER_TYPE to receive ALL messages! */
51 #define PROMISCUOUS 0xffffffff
54 /*****************************************************************************
56 * ALTER THIS TO YOUR OWN NEED *
57 *****************************************************************************/
59 #define PLUGIN_NAME "OLSRD dynamic gateway plugin"
60 #define PLUGIN_VERSION "0.1"
61 #define PLUGIN_AUTHOR "Andreas Tønnesen"
62 #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
63 #define PLUGIN_INTERFACE_VERSION 1
65 /* The type of message you will use */
66 #define MESSAGE_TYPE 128
68 /* The type of messages we will receive - can be set to promiscuous */
69 #define PARSER_TYPE MESSAGE_TYPE
73 /****************************************************************************
74 * Various datastructures and definitions from olsrd *
75 ****************************************************************************/
82 #include <sys/types.h>
84 typedef u_int8_t olsr_u8_t;
85 typedef u_int16_t olsr_u16_t;
86 typedef u_int32_t olsr_u32_t;
87 typedef int8_t olsr_8_t;
88 typedef int16_t olsr_16_t;
89 typedef int32_t olsr_32_t;
116 #define UNSPEC_LINK 0
125 * Mantissa scaling factor
128 #define VTIME_SCALE_FACTOR 0.0625
136 #define HASHMASK (HASHSIZE - 1)
138 #define MAXIFS 8 /* Maximum number of interfaces (from defs.h) in uOLSRd */
141 /****************************************************************************
142 * INTERFACE SECTION *
143 ****************************************************************************/
146 *A struct containing all necessary information about each
147 *interface participating in the OLSD routing
152 struct sockaddr int_addr; /* address */
153 struct sockaddr int_netmask; /* netmask */
154 struct sockaddr int_broadaddr; /* broadcast address */
156 struct sockaddr_in6 int6_addr; /* Address */
157 struct sockaddr_in6 int6_multaddr; /* Multicast */
159 union olsr_ip_addr ip_addr;
160 int olsr_socket; /* The broadcast socket for this interface */
161 int int_metric; /* metric of interface */
162 int int_flags; /* see below */
163 char *int_name; /* from kernel if structure */
164 int if_index; /* Kernels index of this interface */
165 int if_nr; /* This interfaces index internally*/
166 int is_wireless; /* wireless interface or not*/
167 olsr_u16_t olsr_seqnum; /* Olsr message seqno */
168 struct interface *int_next;
171 /****************************************************************************
173 ****************************************************************************/
176 /**********************************
177 * DEFINE YOUR CUSTOM PACKET HERE *
178 **********************************/
182 * OLSR message (several can exist in one OLSR packet)
187 olsr_u8_t olsr_msgtype;
188 olsr_u8_t olsr_vtime;
189 olsr_u16_t olsr_msgsize;
190 olsr_u32_t originator;
195 /* YOUR PACKET GOES HERE */
205 olsr_u8_t olsr_msgtype;
206 olsr_u8_t olsr_vtime;
207 olsr_u16_t olsr_msgsize;
208 struct in6_addr originator;
213 /* YOUR PACKET GOES HERE */
218 * Generic OLSR packet - DO NOT ALTER
223 olsr_u16_t olsr_packlen; /* packet length */
224 olsr_u16_t olsr_seqno;
225 struct olsrmsg olsr_msg[1]; /* variable messages */
231 olsr_u16_t olsr_packlen; /* packet length */
232 olsr_u16_t olsr_seqno;
233 struct olsrmsg6 olsr_msg[1]; /* variable messages */
238 * ALWAYS USE THESE WRAPPERS TO
239 * ENSURE IPv4 <-> IPv6 compability
255 /***************************************************************************
256 * Functions provided by uolsrd_plugin.c *
257 * Similar to their siblings in olsrd *
258 ***************************************************************************/
260 char ipv6_buf[100]; /* buffer for IPv6 inet_htop */
262 /* All these could optionally be fetched from olsrd */
265 olsr_hashing(union olsr_ip_addr *);
268 olsr_get_timestamp(olsr_u32_t, struct timeval *);
271 olsr_init_timer(olsr_u32_t, struct timeval *);
274 olsr_timed_out(struct timeval *);
277 olsr_ip_to_string(union olsr_ip_addr *);
281 /****************************************************************************
282 * Function pointers to functions in olsrd *
283 * These allow direct access to olsrd functions *
284 ****************************************************************************/
286 /* The multi-purpose funtion. All other functions are fetched trough this */
287 int (*olsr_plugin_io)(int, void *, size_t);
289 /* add a prser function */
290 void (*olsr_parser_add_function)(void (*)(union olsr_message *, struct interface *, union olsr_ip_addr *),
293 /* Register a timeout function */
294 int (*olsr_register_timeout_function)(void (*)());
296 /* Register a scheduled event */
297 int (*olsr_register_scheduler_event)(void (*)(), float, float, olsr_u8_t *);
299 /* Get the next message seqno in line */
300 olsr_u16_t (*get_msg_seqno)();
302 /* Transmit package */
303 int (*net_output)(struct interface*);
305 /* Check the duplicate table for prior processing */
306 int (*check_dup_proc)(union olsr_ip_addr *, olsr_u16_t);
308 /* Default forward algorithm */
309 int (*default_fwd)(union olsr_message *,
310 union olsr_ip_addr *,
313 union olsr_ip_addr *);
315 /* Add a socket to the main olsrd select loop */
316 void (*add_olsr_socket)(int, void(*)(int));
318 /* Remove a socket from the main olsrd select loop */
319 int (*remove_olsr_socket)(int, void(*)(int));
321 /* get the link status to a neighbor */
322 int (*check_neighbor_link)(union olsr_ip_addr *);
324 /* Mantissa/exponen conversions */
325 olsr_u8_t (*double_to_me)(double);
327 double (*me_to_double)(olsr_u8_t);
329 /* olsrd printf wrapper */
330 int (*olsr_printf)(int, char *, ...);
332 /* olsrd malloc wrapper */
333 void *(*olsr_malloc)(size_t, const char *);
335 /* Add hna net IPv4 */
336 void (*add_local_hna4_entry)(union olsr_ip_addr *, union hna_netmask *);
338 /* Remove hna net IPv4 */
339 int (*remove_local_hna4_entry)(union olsr_ip_addr *, union hna_netmask *);
341 /* Add hna net IPv6 */
342 void (*add_local_hna6_entry)(union olsr_ip_addr *, union hna_netmask *);
344 /* Remove hna net IPv6 */
345 int (*remove_local_hna6_entry)(union olsr_ip_addr *, union hna_netmask *);
348 /****************************************************************************
350 * NOTE THAT POINTERS POINT TO THE DATA USED BY OLSRD! *
351 * NEVER ALTER DATA POINTED TO BY THESE POINTERS *
352 * UNLESS YOU KNOW WHAT YOU ARE DOING!!! *
353 ****************************************************************************/
355 * The interface list from olsrd
358 struct interface *ifs;
360 /* These two are set automatically by olsrd at load time */
361 int ipversion; /* IPversion in use */
362 union olsr_ip_addr *main_addr; /* Main address */
365 size_t ipsize; /* Size of the ipadresses used */
366 struct timeval *now; /* the olsrds schedulers idea of current time */
368 /* Data that can be altered by your plugin */
369 char *buffer; /* The packet buffer - put your packet here */
370 int *outputsize;/* Pointer to the outputsize - set the size of your packet here */
373 /****************************************************************************
374 * Functions that the plugin MUST provide *
375 ****************************************************************************/
378 /* Initialization function */
382 /* IPC initialization function */
386 /* Destructor function */
390 /* Mulitpurpose funtion */
392 plugin_io(int, void *, size_t);