2 * OLSR Basic Multicast Forwarding (BMF) plugin.
3 * Copyright (c) 2005 - 2007, Thales Communications, Huizen, The Netherlands.
4 * Written by Erik Tromp.
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
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Thales, BMF nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* -------------------------------------------------------------------------
35 * Description: IP packet characterization functions
36 * Created : 29 Jun 2006
38 * ------------------------------------------------------------------------- */
43 #include <stddef.h> /* NULL */
44 #include <assert.h> /* assert() */
45 #include <netinet/ip.h> /* struct ip */
46 #include <netinet/udp.h> /* struct udphdr */
49 #include "defs.h" /* ipequal */
52 #include "Bmf.h" /* BMF_ENCAP_PORT */
53 #include "NetworkInterfaces.h" /* TBmfInterface */
55 /* Whether or not to flood local broadcast packets (e.g. packets with IP
56 * destination 192.168.1.255). May be overruled by setting the plugin
57 * parameter "DoLocalBroadcast" to "no" */
58 int EnableLocalBroadcast = 1;
60 /* -------------------------------------------------------------------------
61 * Function : DoLocalBroadcast
62 * Description: Overrule the default setting, enabling or disabling the
63 * flooding of local broadcast packets
64 * Input : enable - either "yes" or "no"
68 * Return : success (0) or fail (1)
70 * ------------------------------------------------------------------------- */
73 void* data __attribute__((unused)),
74 set_plugin_parameter_addon addon __attribute__((unused)))
76 if (strcmp(enable, "yes") == 0)
78 EnableLocalBroadcast = 1;
81 else if (strcmp(enable, "no") == 0)
83 EnableLocalBroadcast = 0;
87 /* Value not recognized */
91 /* -------------------------------------------------------------------------
92 * Function : IsMulticast
93 * Description: Check if an IP address is a multicast address
96 * Return : true (1) or false (0)
98 * ------------------------------------------------------------------------- */
99 int IsMulticast(union olsr_ip_addr* ipAddress)
101 assert(ipAddress != NULL);
103 return IN_MULTICAST(ntohl(ipAddress->v4.s_addr));
106 /* -------------------------------------------------------------------------
107 * Function : IsOlsrOrBmfPacket
108 * Description: Check if an IP packet is either an OLSR packet or a BMF packet
111 * Return : true (1) or false (0)
113 * ------------------------------------------------------------------------- */
114 int IsOlsrOrBmfPacket(unsigned char* ipPacket)
117 unsigned int ipHeaderLen;
118 struct udphdr* udpHeader;
121 assert(ipPacket != NULL);
123 /* OLSR packets are UDP - port 698
124 * OLSR-BMF packets are UDP - port 50698
125 * OLSR-Autodetect probe packets are UDP - port 51698 */
128 ipHeader = (struct ip*) ARM_NOWARN_ALIGN(ipPacket);
129 if (ipHeader->ip_p != SOL_UDP)
135 /* The total length must be at least large enough to store the UDP header */
136 ipHeaderLen = GetIpHeaderLength(ipPacket);
137 if (GetIpTotalLength(ipPacket) < ipHeaderLen + sizeof(struct udphdr))
139 /* Not long enough */
143 /* Go into the UDP header and check port number */
144 udpHeader = (struct udphdr*) ARM_NOWARN_ALIGN((ipPacket + ipHeaderLen));
145 #if defined(__GLIBC__) || defined(__BIONIC__)
146 destPort = ntohs(udpHeader->dest);
148 destPort = ntohs(udpHeader->uh_dport);
151 if (destPort == olsr_cnf->olsrport || destPort == BMF_ENCAP_PORT || destPort == 51698)
152 /* TODO: #define for 51698 */