grml-sniff: disable IPv6 to avoid neighbor solicitation/multicast traffic
[grml-network.git] / sbin / grml-sniff
1 #!/bin/sh
2 # Filename:      grml-sniff
3 # Purpose:       script for configuring a network sniffing setup
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 CONFIG_FILE=/etc/grml/routersetup
10 . /etc/grml/lsb-functions
11 . /etc/grml/script-functions
12
13 usage_info()
14 {
15    einfo "$0 - script for configuring a network sniffing setup"
16    einfo "Configure via $CONFIG_FILE - see man 8 grml-sniff" ; eend 0
17 }
18
19 if [ -r "$CONFIG_FILE" ] ; then
20   . "$CONFIG_FILE"
21 else
22   ewarn "Could not read $CONFIG_FILE"
23 fi
24
25 # defaults if unconfigured
26 [ -n "$BRCTL" ]          || BRCTL='brctl'
27 [ -n "$BRIDGE_NAME" ]    || BRIDGE_NAME='br0'
28 [ -n "$BRIDGE_DEVICES" ] || BRIDGE_DEVICES='eth0 eth1'
29
30 check_devs() {
31   for dev in $BRIDGE_DEVICES ; do
32     ip link show dev "$dev" >/dev/null 2>&1 || return 1
33  done
34 }
35
36 if ! check_devs ; then
37   eerror "BRIDGE_DEVICES $BRIDGE_DEVICES do not seem to exist." >&2
38   exit 1
39 fi
40
41 check4progs $BRCTL || exit 1
42
43 case "$1" in
44     start)
45         check4root || exit 1
46         einfo "Starting sniffing setup"
47         eindent
48
49             einfo "Disabling IPv6 to avoid neighbor solicitation/multicast traffic"
50             echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
51
52             einfo "Creating bridge device"
53             brctl addbr "$BRIDGE_NAME"
54             eend $?
55
56             einfo "Bringing network device in promiscuous mode up:"
57             eindent
58                for i in $BRIDGE_DEVICES ; do
59                    einfo "$i"
60                    ifconfig "$i" -arp promisc 0.0.0.0 up ; eend $?
61                done
62             eoutdent
63
64             einfo "Adding network devices to $BRIDGE_NAME:"
65             eindent
66             for i in $BRIDGE_DEVICES ; do
67                 einfo "$i"
68                 brctl addif "$BRIDGE_NAME" $i  ; eend $?
69             done
70             eoutdent
71
72             einfo "Bringing bridge $BRIDGE_NAME in promiscuous up"
73             ip link set "$BRIDGE_NAME" promisc on up ; eend $?
74         eoutdent
75    ;;
76
77    stop)
78         check4root || exit 1
79         einfo "Stopping sniffing setup"
80         eindent
81             einfo "Removing network devices from $BRIDGE_NAME: "
82
83             eindent
84                for i in $BRIDGE_DEVICES ; do
85                    einfo "$i "
86                    brctl delif "$BRIDGE_NAME" $i  ; eend $?
87                done
88             eoutdent
89
90             einfo "Disabling promiscuous mode on: "
91             eindent
92                for i in $BRIDGE_DEVICES ; do
93                    einfo "$i "
94                    ip link set "$i" promisc off ; eend $?
95                done
96             eoutdent
97
98             einfo "Bringing bridge $BRIDGE_NAME down"
99             ip link set "$BRIDGE_NAME" down; eend $?
100
101             einfo "Removing bridge device $BRIDGE_NAME"
102             ifconfig "$BRIDGE_NAME" down || /bin/true
103             brctl delbr "$BRIDGE_NAME"
104             eend $?
105
106             einfo "Re-enabling IPv6"
107             echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6
108         eoutdent
109    ;;
110
111    restart)
112         check4root || exit 1
113         $0 stop
114         sleep 1
115         $0 start
116    ;;
117
118    info|-h|--help)
119         usage_info
120    ;;
121
122    status)
123         check4root || exit 1
124         einfo "$0 - status:"
125         $BRCTL show ; eend $?
126    ;;
127
128    *)
129         echo "Usage: $0 {start|stop|restart|status|info}"
130         exit 1
131    ;;
132 esac
133
134 ## END OF FILE #################################################################
135 # vim: ft=sh expandtab ai