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 {
36 ebtables -D FORWARD -i $TAP -j $FROM
37 ebtables -D FORWARD -o $TAP -j $TO
38 #ebtables -D OUTPUT -o $TAP -j $TO
46 function routed_setup_ipv4 {
48 # mangle ARPs to come from the gw's IP
49 arptables -A OUTPUT -o $INTERFACE --opcode request -j mangle --mangle-ip-s "$NETWORK_GATEWAY"
51 # route interface to the proper routing table
52 ip rule add dev $INTERFACE table $TABLE
54 # static route mapping IP -> INTERFACE
55 ip route replace $IP proto static dev $INTERFACE table $TABLE
58 echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
61 function routed_setup_ipv6 {
62 # Add a routing entry for the eui-64
63 prefix=$NETWORK_SUBNET6
65 eui64=$($MAC2EUI64 $MAC $prefix)
68 ip -6 rule add dev $INTERFACE table $TABLE
69 ip -6 ro replace $eui64/128 dev $INTERFACE table $TABLE
70 ip -6 neigh add proxy $eui64 dev $uplink
72 # disable proxy NDP since we're handling this on userspace
73 # this should be the default, but better safe than sorry
74 echo 0 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
77 # pick a firewall profile per NIC, based on tags (and apply it)
78 function routed_setup_firewall {
79 ifprefix="synnefo:network:$INTERFACE_INDEX:"
81 case ${tag#$ifprefix} in
94 if [ "x$chain" != "x" ]; then
95 iptables -A FORWARD -o $INTERFACE -j $chain
96 ip6tables -A FORWARD -o $INTERFACE -j $chain
100 function init_ebtables {
103 ebtables -A FORWARD -i $TAP -j $FROM
105 ebtables -A FORWARD -o $TAP -j $TO
110 function setup_ebtables {
112 # do not allow changes in ip-mac pair
114 ebtables -A $FROM --ip-source \! $IP -p ipv4 -j DROP
116 ebtables -A $FROM -s \! $MAC -j DROP
117 #accept dhcp responses from host (nfdhcpd)
118 ebtables -A $TO -p ipv4 --ip-protocol=udp --ip-destination-port=68 -j ACCEPT
119 # allow only packets from the same mac prefix
120 ebtables -A $TO -s \! $MAC/$MAC_MASK -j DROP
123 function setup_masq {
125 # allow packets from/to router (for masquerading)
126 # ebtables -A $TO -s $PUBLIC_MAC -j ACCEPT
127 # ebtables -A INPUT -i $TAP -j $FROM
128 # ebtables -A OUTPUT -o $TAP -j $TO
133 function setup_nfdhcpd {
135 FILE=$NFDHCPD_STATE_DIR/$INTERFACE
136 #IFACE is the interface from which the packet seems to arrive
137 #needed in bridged mode where the packets seems to arrive from the
138 #bridge and not from the tap
145 GATEWAY=$NETWORK_GATEWAY
146 SUBNET=$NETWORK_SUBNET
147 GATEWAY6=$NETWORK_GATEWAY6
148 SUBNET6=$NETWORK_SUBNET6
149 EUI64=$($MAC2EUI64 $MAC $NETWORK_SUBNET6 2>/dev/null)
155 DEFAULT=/etc/default/snf-network
159 INFRA=$STATE_DIR/infra
169 clear_routed_setup_ipv4 > /dev/null 2>&1
170 clear_routed_setup_ipv6 > /dev/null 2>&1
171 clear_routed_setup_firewall > /dev/null 2>&1
172 clear_ebtables > /dev/null 2>&1
174 if [ "$MODE" = "routed" ]; then
176 ip link set $INTERFACE addr $TAP_CONSTANT_MAC up
178 DROPDHCPREQCMD="iptables -A FORWARD -i $INTERFACE -p udp --dport 67 -j DROP"
179 elif [ "$MODE" = "bridged" ]; then
180 ip link set $INTERFACE up
181 brctl addif $BRIDGE $INTERFACE
183 init_ebtables > /dev/null 2>&1
184 DROPDHCPREQCMD="ebtables -A $FROM -p ipv4 --ip-protocol udp --ip-destination-port 67 -j DROP"
188 for tag in $NETWORK_TAGS; do
191 routed_setup_ipv4 > /dev/null 2>&1
192 routed_setup_ipv6 > /dev/null 2>&1
193 routed_setup_firewall > /dev/null 2>&1
196 # Drop unicast BOOTP/DHCP packets
197 $DROPDHCPREQCMD > /dev/null 2>&1
198 setup_nfdhcpd > /dev/null 2>&1
201 setup_ebtables > /dev/null 2>&1
204 setup_masq > /dev/null 2>&1