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.
33 * Dynamic linked library example for UniK OLSRd
36 #ifndef _OLSRD_PLUGIN_DEFS
37 #define _OLSRD_PLUGIN_DEFS
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
47 #include "olsr_plugin_io.h"
49 /* Use this as PARSER_TYPE to receive ALL messages! */
50 #define PROMISCUOUS 0xffffffff
53 /*****************************************************************************
55 * ALTER THIS TO YOUR OWN NEED *
56 *****************************************************************************/
58 #define PLUGIN_NAME "OLSRD Powerstatus plugin"
59 #define PLUGIN_VERSION "0.1"
60 #define PLUGIN_AUTHOR "Andreas Tønnesen"
61 #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
62 #define PLUGIN_INTERFACE_VERSION 1
64 /* The type of message you will use */
65 #define MESSAGE_TYPE 128
67 /* The type of messages we will receive - can be set to promiscuous */
68 #define PARSER_TYPE MESSAGE_TYPE
72 /****************************************************************************
73 * Various datastructures and definitions from olsrd *
74 ****************************************************************************/
81 #include <sys/types.h>
83 typedef u_int8_t olsr_u8_t;
84 typedef u_int16_t olsr_u16_t;
85 typedef u_int32_t olsr_u32_t;
86 typedef int8_t olsr_8_t;
87 typedef int16_t olsr_16_t;
88 typedef int32_t olsr_32_t;
115 #define UNSPEC_LINK 0
124 * Mantissa scaling factor
127 #define VTIME_SCALE_FACTOR 0.0625
135 #define HASHMASK (HASHSIZE - 1)
137 #define MAXIFS 8 /* Maximum number of interfaces (from defs.h) in uOLSRd */
140 /****************************************************************************
141 * INTERFACE SECTION *
142 ****************************************************************************/
145 *A struct containing all necessary information about each
146 *interface participating in the OLSD routing
151 struct sockaddr int_addr; /* address */
152 struct sockaddr int_netmask; /* netmask */
153 struct sockaddr int_broadaddr; /* broadcast address */
155 struct sockaddr_in6 int6_addr; /* Address */
156 struct sockaddr_in6 int6_multaddr; /* Multicast */
158 union olsr_ip_addr ip_addr;
159 int olsr_socket; /* The broadcast socket for this interface */
160 int int_metric; /* init's routing entry */
161 int int_mtu; /* MTU 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 number internally*/
166 int is_wireless; /* wireless interface or not*/
167 olsr_u16_t olsr_seqnum; /* Sequence numbers*/
168 struct interface *int_next;
172 /****************************************************************************
174 ****************************************************************************/
177 /**********************************
178 * DEFINE YOUR CUSTOM PACKET HERE *
179 **********************************/
183 olsr_u8_t source_type;
184 olsr_u8_t percentage;
185 olsr_u16_t time_left;
189 * OLSR message (several can exist in one OLSR packet)
194 olsr_u8_t olsr_msgtype;
195 olsr_u8_t olsr_vtime;
196 olsr_u16_t olsr_msgsize;
197 olsr_u32_t originator;
202 /* YOUR PACKET GOES HERE */
213 olsr_u8_t olsr_msgtype;
214 olsr_u8_t olsr_vtime;
215 olsr_u16_t olsr_msgsize;
216 struct in6_addr originator;
221 /* YOUR PACKET GOES HERE */
227 * Generic OLSR packet - DO NOT ALTER
232 olsr_u16_t olsr_packlen; /* packet length */
233 olsr_u16_t olsr_seqno;
234 struct olsrmsg olsr_msg[1]; /* variable messages */
240 olsr_u16_t olsr_packlen; /* packet length */
241 olsr_u16_t olsr_seqno;
242 struct olsrmsg6 olsr_msg[1]; /* variable messages */
247 * ALWAYS USE THESE WRAPPERS TO
248 * ENSURE IPv4 <-> IPv6 compability
264 /***************************************************************************
265 * Functions provided by uolsrd_plugin.c *
266 * Similar to their siblings in olsrd *
267 ***************************************************************************/
269 char ipv6_buf[100]; /* buffer for IPv6 inet_htop */
271 /* All these could optionally be fetched from olsrd */
274 olsr_hashing(union olsr_ip_addr *);
277 olsr_get_timestamp(olsr_u32_t, struct timeval *);
280 olsr_init_timer(olsr_u32_t, struct timeval *);
283 olsr_timed_out(struct timeval *);
286 olsr_ip_to_string(union olsr_ip_addr *);
290 /****************************************************************************
291 * Function pointers to functions in olsrd *
292 * These allow direct access to olsrd functions *
293 ****************************************************************************/
295 /* The multi-purpose funtion. All other functions are fetched trough this */
296 int (*olsr_plugin_io)(int, void *, size_t);
298 /* add a prser function */
299 void (*olsr_parser_add_function)(void (*)(union olsr_message *, struct interface *, union olsr_ip_addr *),
302 /* Register a timeout function */
303 int (*olsr_register_timeout_function)(void (*)());
305 /* Register a scheduled event */
306 int (*olsr_register_scheduler_event)(void (*)(), float, float, olsr_u8_t *);
308 /* Get the next message seqno in line */
309 olsr_u16_t (*get_msg_seqno)();
311 /* Transmit package */
312 int (*net_output)(struct interface*);
314 /* Check the duplicate table for prior processing */
315 int (*check_dup_proc)(union olsr_ip_addr *, olsr_u16_t);
317 /* Default forward algorithm */
318 int (*default_fwd)(union olsr_message *,
319 union olsr_ip_addr *,
322 union olsr_ip_addr *);
324 /* Add a socket to the main olsrd select loop */
325 void (*add_olsr_socket)(int, void(*)(int));
327 /* Remove a socket from the main olsrd select loop */
328 int (*remove_olsr_socket)(int, void(*)(int));
330 /* get the link status to a neighbor */
331 int (*check_neighbor_link)(union olsr_ip_addr *);
333 /* Mantissa/exponen conversions */
334 olsr_u8_t (*double_to_me)(double);
336 double (*me_to_double)(olsr_u8_t);
338 /* olsrd printf wrapper */
339 int (*olsr_printf)(int, char *, ...);
341 /* olsrd malloc wrapper */
342 void *(*olsr_malloc)(size_t, const char *);
344 /* Add hna net IPv4 */
345 void (*add_local_hna4_entry)(union olsr_ip_addr *, union hna_netmask *);
347 /* Remove hna net IPv4 */
348 int (*remove_local_hna4_entry)(union olsr_ip_addr *, union hna_netmask *);
350 /* Add hna net IPv6 */
351 void (*add_local_hna6_entry)(union olsr_ip_addr *, union hna_netmask *);
353 /* Remove hna net IPv6 */
354 int (*remove_local_hna6_entry)(union olsr_ip_addr *, union hna_netmask *);
357 /****************************************************************************
359 * NOTE THAT POINTERS POINT TO THE DATA USED BY OLSRD! *
360 * NEVER ALTER DATA POINTED TO BY THESE POINTERS *
361 * UNLESS YOU KNOW WHAT YOU ARE DOING!!! *
362 ****************************************************************************/
364 * The interface list from olsrd
367 struct interface *ifs;
369 /* These two are set automatically by olsrd at load time */
370 int ipversion; /* IPversion in use */
371 union olsr_ip_addr *main_addr; /* Main address */
374 size_t ipsize; /* Size of the ipadresses used */
375 struct timeval *now; /* the olsrds schedulers idea of current time */
377 /* Data that can be altered by your plugin */
378 char *buffer; /* The packet buffer - put your packet here */
379 int *outputsize;/* Pointer to the outputsize - set the size of your packet here */
382 /****************************************************************************
383 * Functions that the plugin MUST provide *
384 ****************************************************************************/
387 /* Initialization function */
391 /* IPC initialization function */
395 /* Destructor function */
399 /* Mulitpurpose funtion */
401 plugin_io(int, void *, size_t);