2 * OLSR Basic Multicast Forwarding (BMF) plugin.
3 * Copyright (c) 2005, 2006, 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 /* $Id: DropList.c,v 1.1 2006/05/03 08:59:04 kattemat Exp $ */
39 #include <assert.h> /* assert() */
40 #include <stdio.h> /* NULL */
41 #include <stdlib.h> /* malloc */
42 #include <string.h> /* memcmp */
45 #include "olsr.h" /* olsr_printf */
48 #include "Bmf.h" /* PLUGIN_NAME */
49 #include "Packet.h" /* IFHWADDRLEN */
51 static struct TMacAddress* DroppedMacAddresses = NULL;
53 /* Register a MAC address in the drop list. The registered MAC address will be matched
54 * to the source MAC address of incoming multicast packets. If matched, the multicast
55 * packet will be silently dropped.
56 * The drop list is needed only in lab environments, where hidden nodes are simulated
57 * by using iptables with the -m mac --mac-source option (as in:
58 * "iptables -A INPUT -m mac --mac-source 00:0C:29:EE:C9:D0 -j DROP")
59 * The drop list is needed because network interfaces in promiscuous mode will still
60 * capture packets even if they are specified to be dropped by iptables.
62 int DropMac(const char* macStr)
66 struct TMacAddress* newMacAddress;
69 assert(macStr != NULL);
71 n = sscanf(macStr, "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
74 olsr_printf(1, "%s: Invalid Ethernet address '%s'\n", PLUGIN_NAME, macStr);
78 newMacAddress = malloc(sizeof(struct TMacAddress));
79 for (i = 0; i < 6; i++)
81 newMacAddress->addr[i] = (unsigned char) mac[i];
83 newMacAddress->next = DroppedMacAddresses;
84 DroppedMacAddresses = newMacAddress;
89 /* Return 1 if macAddress is in the drop list, else 0 */
90 int IsInDropList(const unsigned char* macAddress)
92 struct TMacAddress* ma = DroppedMacAddresses;
94 assert(macAddress != NULL);
98 if (memcmp(ma->addr, macAddress, IFHWADDRLEN) == 0) return 1;