Statistics
| Branch: | Tag: | Revision:

root / vlans / if-up.d / vmrouter @ cf51ea5b

History | View | Annotate | Download (1.6 kB)

1
#!/bin/bash
2
#
3
# if-up.d hook to do some weird networking stuff on IP-less interfaces
4
#
5
# Example:
6
#
7
# auto bond0.90
8
# iface bond0.90 inet manual
9
#         ip-routing-table 90
10
#         ip-routes 62.217.124.0/26
11
#         ip-gateway 62.217.124.1
12
#         ip-forwarding 1
13
#         ip-proxy-arp 1
14
#         arp-ip 62.217.124.58
15
#
16
# iface bond0.90 inet6 manual
17
#         ip-routing-table 90
18
#         ip-routes 2001:648:2ffc:105::/64
19
#         ip-gateway 2001:648:2ffc:105::1
20
#         ip-forwarding 1
21
#         ip-proxy-ndp 1
22

    
23
PATH=/usr/sbin:/usr/bin:/sbin:/bin
24

    
25
ip link set $IFACE up
26

    
27
if [ "$ADDRFAM" = "inet" ]; then
28
	IP="ip"
29
elif [ "$ADDRFAM" = "inet6" ]; then
30
	IP="ip -6"
31
else
32
	exit 0
33
fi
34

    
35
if [ -n "$IF_IP_ROUTING_TABLE" ]; then
36
	TABLE="table $IF_IP_ROUTING_TABLE"
37
else
38
	# bail out early if there's no ip-routing-table defined
39
	exit 0
40
fi
41

    
42
while $IP rule del iif $IFACE;do :; done 2>/dev/null
43
$IP rule add iif $IFACE $TABLE
44

    
45
for route in $IF_IP_ROUTES; do
46
	$IP route add $route dev $IFACE table main
47
	$IP route add $route dev $IFACE $TABLE
48
done
49

    
50
if [ -n "$IF_IP_GATEWAY" ]; then
51
	$IP route add default via $IF_IP_GATEWAY dev $IFACE $TABLE
52
fi
53

    
54
if [ -n "$IF_IP_FORWARDING" ]; then
55
	[ "$ADDRFAM" = "inet" ] && echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
56
	[ "$ADDRFAM" = "inet6" ] && echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
57
fi
58

    
59
[ "$IF_IP_PROXY_NDP" = "1" ] && [ "$ADDRFAM" = "inet6" ] && echo 1 > /proc/sys/net/ipv6/conf/$IFACE/proxy_ndp
60

    
61
if [ "$ADDRFAM" = "inet" ]; then
62
	if [ -n "$IF_ARP_IP" ]; then
63
		arptables -D OUTPUT -o $IFACE --opcode request -j mangle 2>/dev/null || true
64
		arptables -A OUTPUT -o $IFACE --opcode request -j mangle --mangle-ip-s $IF_ARP_IP
65
	fi
66
fi