Fix a minor bug
[snf-network] / clear-tap
1 #!/bin/bash
2
3 # This is an example of a Ganeti kvm ifup script that configures network
4 # interfaces based on the initial deployment of the Okeanos project
5
6 DEFAULT=/etc/default/snf-network
7 NFDHCPD_STATE_DIR=/var/lib/nfdhcpd
8 source $DEFAULT
9 source $CONF
10 source $STATE_DIR/infra
11
12 function clear_routed_setup_ipv4 {
13
14  arptables -D OUTPUT -o $INTERFACE --opcode request -j mangle
15  while ip rule del dev $INTERFACE; do :; done
16  iptables -D FORWARD -i $INTERFACE -p udp --dport 67 -j DROP
17
18 }
19
20 function clear_routed_setup_ipv6 {
21
22  while ip -6 rule del dev $INTERFACE; do :; done
23
24 }
25
26
27 function clear_routed_setup_firewall {
28
29   for oldchain in protected unprotected limited; do
30     iptables  -D FORWARD -o $INTERFACE -j $oldchain
31     ip6tables -D FORWARD -o $INTERFACE -j $oldchain
32   done
33
34 }
35
36 function clear_ebtables {
37   TAP=$INTERFACE
38   FROM=FROM${TAP^^}
39   TO=TO${TAP^^}
40
41   ebtables -D INPUT -i $TAP -j $FROM
42   ebtables -D FORWARD -i $TAP -j $FROM
43   ebtables -D FORWARD -o $TAP -j $TO
44   ebtables -D OUTPUT -o $TAP -j $TO
45
46   ebtables -X $FROM
47   ebtables -X $TO
48 }
49
50
51 if [ $# -ne 1 ]; then
52   echo "Usage: $0 <tap>"
53   exit 1
54 fi
55
56 INTERFACE=$1
57
58 clear_routed_setup_ipv4 
59 clear_routed_setup_ipv6 
60 clear_routed_setup_firewall 
61 clear_ebtables 
62
63 rm $NFDHCPD_STATE_DIR/$INTERFACE