2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2004, Andreas Tonnesen(andreto@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
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of olsr.org, olsrd nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * Visit http://www.olsr.org for more information.
35 * If you find this software useful feel free to make a donation
36 * to the project. For more information see the website or contact
37 * the copyright holders.
42 * Dynamic linked library for the olsr.org olsr daemon
46 #include "olsrd_plugin.h"
51 #include <netinet/in.h>
53 #include <arpa/nameser.h>
55 /* The -mno-cygwin prevent these defs. Otherwise we pull in cygwin1.dll */
56 typedef uint32_t in_addr_t;
57 typedef uint16_t sa_family_t;
60 #include "olsrd_httpinfo.h"
64 int resolve_ip_addresses = 0;
65 struct ip_prefix_list *allowed_nets = NULL;
67 static void my_init(void) __attribute__ ((constructor));
68 static void my_fini(void) __attribute__ ((destructor));
70 static int add_plugin_ipnet4(const char *value, void *data, set_plugin_parameter_addon);
71 static int add_plugin_ipnet6(const char *value, void *data, set_plugin_parameter_addon);
72 static int add_plugin_ipaddr4(const char *value, void *data, set_plugin_parameter_addon);
73 static int add_plugin_ipaddr6(const char *value, void *data, set_plugin_parameter_addon);
75 static int insert_plugin_ipnet(sa_family_t ip_version, const char *sz_net, const char *sz_mask, struct ip_prefix_list **all_nets);
76 static int add_plugin_ipnet(sa_family_t ip_version, const char *value, struct ip_prefix_list **all_nets);
79 * Defines the version of the plugin interface that is used
80 * THIS IS NOT THE VERSION OF YOUR PLUGIN!
81 * Do not alter unless you know what you are doing!
83 int olsrd_plugin_interface_version(void)
85 return PLUGIN_INTERFACE_VERSION;
91 static void my_init(void)
93 /* Print plugin info to stdout */
94 printf("%s\n", MOD_DESC);
100 static void my_fini(void)
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!
111 static const struct olsrd_plugin_parameters plugin_parameters[] = {
112 { .name = "port", .set_plugin_parameter = &set_plugin_port, .data = &http_port },
113 { .name = "host4", .set_plugin_parameter = &add_plugin_ipaddr4, .data = &allowed_nets },
114 { .name = "net4", .set_plugin_parameter = &add_plugin_ipnet4, .data = &allowed_nets },
115 { .name = "host", .set_plugin_parameter = &add_plugin_ipaddr4, .data = &allowed_nets },
116 { .name = "net", .set_plugin_parameter = &add_plugin_ipnet4, .data = &allowed_nets },
117 { .name = "host6", .set_plugin_parameter = &add_plugin_ipaddr6, .data = &allowed_nets },
118 { .name = "net6", .set_plugin_parameter = &add_plugin_ipnet6, .data = &allowed_nets },
119 { .name = "resolve", .set_plugin_parameter = &set_plugin_boolean, .data = &resolve_ip_addresses },
122 void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
124 *params = plugin_parameters;
125 *size = ARRAYSIZE(plugin_parameters);
128 static int insert_plugin_ipnet(sa_family_t ip_version, const char *sz_net, const char *sz_mask, struct ip_prefix_list **all_nets)
130 union olsr_ip_addr net;
133 if (inet_pton(ip_version, sz_net, &net) <= 0) {
136 if (ip_version == AF_INET) {
137 union olsr_ip_addr netmask;
138 if(inet_pton(AF_INET, sz_mask, &netmask) <= 0) {
141 prefix_len = olsr_netmask_to_prefix(&netmask);
144 prefix_len = strtoul(sz_mask, &endptr, 10);
145 if(*endptr != '\0' || prefix_len > 128) {
150 if (ip_version != olsr_cnf->ip_version) {
151 if (ip_version == AF_INET) {
152 memmove(&net.v6.s6_addr[12], &net.v4.s_addr, sizeof(in_addr_t));
153 memset(&net.v6.s6_addr[0], 0x00, 10 * sizeof(uint8_t));
154 memset(&net.v6.s6_addr[10], 0xff, 2 * sizeof(uint8_t));
162 ip_prefix_list_add(all_nets, &net, prefix_len);
167 static int add_plugin_ipnet(sa_family_t ip_version, const char *value, struct ip_prefix_list **all_nets)
169 char sz_net[100], sz_mask[100]; /* IPv6 in the future */
171 if(sscanf(value, "%99s %99s", sz_net, sz_mask) != 2) {
174 return insert_plugin_ipnet(ip_version, sz_net, sz_mask, all_nets);
177 static int add_plugin_ipnet4(const char *value, void *data, set_plugin_parameter_addon addon __attribute__((unused)))
179 return add_plugin_ipnet(AF_INET, value, data);
182 static int add_plugin_ipnet6(const char *value, void *data, set_plugin_parameter_addon addon __attribute__((unused)))
184 return add_plugin_ipnet(AF_INET6, value, data);
187 static int add_plugin_ipaddr4(const char *value, void *data, set_plugin_parameter_addon addon __attribute__((unused)))
189 return insert_plugin_ipnet(AF_INET, value, "255.255.255.255", data);
192 static int add_plugin_ipaddr6(const char *value, void *data, set_plugin_parameter_addon addon __attribute__((unused)))
194 return insert_plugin_ipnet(AF_INET6, value, "128", data);
202 * indent-tabs-mode: nil