4 * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
5 * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation or - at your option - under
10 * the terms of the GNU General Public Licence version 2 but can be
11 * linked to any BSD-Licenced Software with public available sourcecode
15 /* -------------------------------------------------------------------------
16 * File : olsrd_plugin.c
17 * Description : functions to setup plugin
18 * ------------------------------------------------------------------------- */
24 #include "olsrd_plugin.h"
25 #include "plugin_util.h"
27 #include "scheduler.h"
32 #define PLUGIN_NAME "OLSRD quagga plugin"
33 #define PLUGIN_VERSION "0.2.2"
34 #define PLUGIN_AUTHOR "Immo 'FaUl' Wehrenberg"
35 #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
36 #define PLUGIN_INTERFACE_VERSION 5
38 static void __attribute__ ((constructor)) my_init(void);
39 static void __attribute__ ((destructor)) my_fini(void);
41 static set_plugin_parameter set_redistribute;
42 static set_plugin_parameter set_exportroutes;
43 static set_plugin_parameter set_distance;
44 static set_plugin_parameter set_localpref;
45 static set_plugin_parameter set_sockpath;
46 static set_plugin_parameter set_port;
47 static set_plugin_parameter set_version;
51 olsrd_plugin_interface_version(void)
53 return PLUGIN_INTERFACE_VERSION;
56 static const struct olsrd_plugin_parameters plugin_parameters[] = {
57 {.name = "redistribute",.set_plugin_parameter = &set_redistribute,},
58 {.name = "ExportRoutes",.set_plugin_parameter = &set_exportroutes,},
59 {.name = "Distance",.set_plugin_parameter = &set_distance,},
60 {.name = "LocalPref",.set_plugin_parameter = &set_localpref,},
61 {.name = "SockPath",.set_plugin_parameter = &set_sockpath,.addon = {PATH_MAX},},
62 {.name = "Port",.set_plugin_parameter = &set_port,},
63 {.name = "Version",.set_plugin_parameter = &set_version,},
67 olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
69 *params = plugin_parameters;
70 *size = ARRAYSIZE(plugin_parameters);
74 set_redistribute(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
76 const char *zebra_route_types[] = { "system", "kernel", "connect",
77 "static", "rip", "ripng", "ospf",
78 "ospf6", "isis", "bgp", "hsls"
82 for (i = 0; i < ARRAYSIZE(zebra_route_types); i++) {
83 if (!strcmp(value, zebra_route_types[i]))
84 if (zebra_redistribute (i)) return 1;
91 set_exportroutes(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
93 if (!strcmp(value, "only")) {
94 olsr_addroute_function = zebra_add_route;
95 olsr_delroute_function = zebra_del_route;
96 zebra_export_routes(1);
97 } else if (!strcmp(value, "additional")) {
98 olsr_addroute_function = zebra_add_route;
99 olsr_delroute_function = zebra_del_route;
100 zebra_export_routes(1);
102 zebra_export_routes(0);
107 set_distance(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
111 if (set_plugin_int(value, &distance, addon))
113 if (distance < 0 || distance > 255)
115 zebra_olsr_distance(distance);
120 set_localpref(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
124 if (set_plugin_boolean(value, &b, addon))
127 zebra_olsr_localpref();
132 set_sockpath(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon)
134 char sockpath[PATH_MAX];
136 if (set_plugin_string(value, &sockpath, addon))
138 zebra_sockpath(sockpath);
143 set_port(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
147 if (set_plugin_port(value, &port, addon))
155 set_version(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
159 if (set_plugin_int(value, &version, addon))
161 if (version < 0 || version > 1)
163 zebra_version(version);
169 olsrd_plugin_init(void)
171 if (olsr_cnf->ip_version != AF_INET) {
172 fputs("see the source - ipv6 so far not supported\n", stderr);
176 olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_parse, NULL, 0);
196 * indent-tabs-mode: nil