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 INPUT -i $TAP -j $FROM
37 ebtables -D FORWARD -i $TAP -j $FROM
38 ebtables -D FORWARD -o $TAP -j $TO
39 ebtables -D OUTPUT -o $TAP -j $TO
47 function routed_setup_ipv4 {
49 # mangle ARPs to come from the gw's IP
50 arptables -A OUTPUT -o $INTERFACE --opcode request -j mangle --mangle-ip-s "$NETWORK_GATEWAY"
52 # route interface to the proper routing table
53 ip rule add dev $INTERFACE table $TABLE
55 # static route mapping IP -> INTERFACE
56 ip route replace $IP proto static dev $INTERFACE table $TABLE
59 echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
62 function routed_setup_ipv6 {
63 # Add a routing entry for the eui-64
64 prefix=$NETWORK_SUBNET6
66 eui64=$($MAC2EUI64 $MAC $prefix)
69 ip -6 rule add dev $INTERFACE table $TABLE
70 ip -6 ro replace $eui64/128 dev $INTERFACE table $TABLE
71 ip -6 neigh add proxy $eui64 dev $uplink
73 # disable proxy NDP since we're handling this on userspace
74 # this should be the default, but better safe than sorry
75 echo 0 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
78 # pick a firewall profile per NIC, based on tags (and apply it)
79 function routed_setup_firewall {
80 ifprefix="synnefo:network:$INTERFACE_INDEX:"
82 case ${tag#$ifprefix} in
95 if [ "x$chain" != "x" ]; then
96 iptables -A FORWARD -o $INTERFACE -j $chain
97 ip6tables -A FORWARD -o $INTERFACE -j $chain
101 function create_ebtables {
104 ebtables -A FORWARD -i $TAP -j $FROM
106 ebtables -A FORWARD -o $TAP -j $TO
111 function setup_ebtables {
113 # do not allow changes in ip-mac pair
115 ebtables -A $FROM --ip-source \! $IP -p ipv4 -j DROP
117 ebtables -A $FROM -s \! $MAC -j DROP
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
124 function setup_masq {
126 # allow packets from/to router (for masquerading)
127 # ebtables -A $TO -s $PUBLIC_MAC -j ACCEPT
128 # ebtables -A INPUT -i $TAP -j $FROM
129 # ebtables -A OUTPUT -o $TAP -j $TO
134 function setup_nfdhcpd {
136 FILE=$NFDHCPD_STATE_DIR/$INTERFACE
137 #IFACE is the interface from which the packet seems to arrive
138 #needed in bridged mode where the packets seems to arrive from the
139 #bridge and not from the tap
146 GATEWAY=$NETWORK_GATEWAY
147 SUBNET=$NETWORK_SUBNET
148 GATEWAY6=$NETWORK_GATEWAY6
149 SUBNET6=$NETWORK_SUBNET6
150 EUI64=$($MAC2EUI64 $MAC $NETWORK_SUBNET6 2>/dev/null)
156 DEFAULT=/etc/default/snf-network
160 INFRA=$STATE_DIR/infra
166 clear_routed_setup_ipv4 > /dev/null 2>&1
167 clear_routed_setup_ipv6 > /dev/null 2>&1
168 clear_routed_setup_firewall > /dev/null 2>&1
169 clear_ebtables > /dev/null 2>&1
175 if [ "$MODE" = "routed" ]; then
177 ip link set $INTERFACE addr $TAP_CONSTANT_MAC up
179 DROPDHCPREQCMD="iptables -A FORWARD -i $INTERFACE -p udp --dport 67 -j DROP"
180 elif [ "$MODE" = "bridged" ]; then
181 ip link set $INTERFACE up
182 brctl addif $BRIDGE $INTERFACE
184 init_ebtables > /dev/null 2>&1
185 DROPDHCPREQCMD="ebtables -A $FROM -p ipv4 --ip-protocol udp --ip-destination-port 67 -j DROP"
189 for tag in $NETWORK_TAGS; do
192 routed_setup_ipv4 > /dev/null 2>&1
193 routed_setup_ipv6 > /dev/null 2>&1
194 routed_setup_firewall > /dev/null 2>&1
197 # Drop unicast BOOTP/DHCP packets
198 setup_nfdhcpd > /dev/null 2>&1
202 setup_ebtables > /dev/null 2>&1
205 setup_masq > /dev/null 2>&1