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
6 TAP_CONSTANT_MAC=cc:47:52:4e:45:54 # GRNET in hex :-)
7 MAC2EUI64=/usr/bin/mac2eui64
8 NFDHCPD_STATE_DIR=/var/lib/nfdhcpd
10 function clear_routed_setup_ipv4 {
12 arptables -D OUTPUT -o $INTERFACE --opcode request -j mangle
13 while ip rule del dev $INTERFACE; do :; done
14 iptables -D FORWARD -i $INTERFACE -p udp --dport 67 -j DROP
18 function clear_routed_setup_ipv6 {
20 while ip -6 rule del dev $INTERFACE; do :; done
25 function clear_routed_setup_firewall {
27 for oldchain in protected unprotected limited; do
28 iptables -D FORWARD -o $INTERFACE -j $oldchain
29 ip6tables -D FORWARD -o $INTERFACE -j $oldchain
34 function clear_ebtables {
39 ebtables -D INPUT -i $TAP -j $FROM
40 ebtables -D FORWARD -i $TAP -j $FROM
41 ebtables -D FORWARD -o $TAP -j $TO
42 ebtables -D OUTPUT -o $TAP -j $TO
50 function routed_setup_ipv4 {
52 # mangle ARPs to come from the gw's IP
53 arptables -A OUTPUT -o $INTERFACE --opcode request -j mangle --mangle-ip-s "$GATEWAY"
55 # route interface to the proper routing table
56 ip rule add dev $INTERFACE table $TABLE
58 # static route mapping IP -> INTERFACE
59 ip route replace $IP proto static dev $INTERFACE table $TABLE
62 echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
65 function routed_setup_ipv6 {
66 # Add a routing entry for the eui-64
69 eui64=$($MAC2EUI64 $MAC $prefix)
72 ip -6 rule add dev $INTERFACE table $TABLE
73 ip -6 ro replace $eui64/128 dev $INTERFACE table $TABLE
74 ip -6 neigh add proxy $eui64 dev $uplink
76 # disable proxy NDP since we're handling this on userspace
77 # this should be the default, but better safe than sorry
78 echo 0 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
81 # pick a firewall profile per NIC, based on tags (and apply it)
82 function routed_setup_firewall {
83 ifprefix="synnefo:network:$INTERFACE_INDEX:"
85 case ${tag#$ifprefix} in
98 if [ "x$chain" != "x" ]; then
99 iptables -A FORWARD -o $INTERFACE -j $chain
100 ip6tables -A FORWARD -o $INTERFACE -j $chain
104 function setup_ebtables {
110 # do not allow changes in ip-mac pair
112 ebtables -A $FROM --ip-source \! $IP -p ipv4 -j DROP
114 ebtables -A $FROM -s \! $MAC -j DROP
115 ebtables -A FORWARD -i $TAP -j $FROM
117 ebtables -A FORWARD -o $TAP -j $TO
118 #accept dhcp responses from host (nfdhcpd)
119 ebtables -A $TO -p ipv4 --ip-protocol=udp --ip-destination-port=68 -j ACCEPT
120 # allow only packets from the same mac prefix
121 ebtables -A $TO -s \! $MAC/$MAC_MASK -j DROP
122 if [ $ENABLE_MASQ -a -n "$GATEWAY" ]; then
123 # allow packets from/to router (for masquerading)
124 ebtables -A $TO -s $PUBLIC_MAC -j ACCEPT
125 ebtables -A INPUT -i $TAP -j $FROM
126 ebtables -A OUTPUT -o $TAP -j $TO
131 function setup_nfdhcpd {
133 FILE=$NFDHCPD_STATE_DIR/$INTERFACE
134 #IFACE is the interface from which the packet seems to arrive
135 #needed in bridged mode where the packets seems to arrive from the
136 #bridge and not from the tap
147 EUI64=$($MAC2EUI64 $MAC $SUBNET6 2>/dev/null)
153 DEFAULT=/etc/default/snf-network
157 INFRA=$STATE_DIR/infra
162 clear_routed_setup_ipv4 > /dev/null 2>&1
163 clear_routed_setup_ipv6 > /dev/null 2>&1
164 clear_routed_setup_firewall > /dev/null 2>&1
165 clear_ebtables > /dev/null 2>&1
167 if [ "$MODE" = "routed" ]; then
169 # use a constant predefined MAC address for the tap
170 ip link set $INTERFACE addr $TAP_CONSTANT_MAC
172 ifconfig $INTERFACE 0.0.0.0 up
174 # Drop unicast BOOTP/DHCP packets
175 iptables -A FORWARD -i $INTERFACE -p udp --dport 67 -j DROP
177 routed_setup_ipv4 > /dev/null 2>&1
178 routed_setup_ipv6 > /dev/null 2>&1
179 routed_setup_firewall > /dev/null 2>&1
180 setup_nfdhcpd $INTERFACE
181 elif [ "$MODE" = "bridged" ]; then
182 ifconfig $INTERFACE 0.0.0.0 up
183 brctl addif $BRIDGE $INTERFACE
184 setup_nfdhcpd $BRIDGE
185 if [ $ENABLE_EBTABLES -a "$TYPE" = "private-filtered" ]; then
186 setup_ebtables > /dev/null 2>&1