1# Configuration file for setting IP addresses for tunneling network interfaces
2
3INTERFACE="$1"
4
5HWADDR="00:00:5e:00:53:ff"
6
7# Read the "TUNNEL_VxVy" as "Vx over Vy"
8TUNNEL_V4V4=${INTERFACE}-ipip
9TUNNEL_V4V6=${INTERFACE}-ipip6
10TUNNEL_V6V4=${INTERFACE}-ip6ip
11TUNNEL_V6V6=${INTERFACE}-ip6ip6
12
13PREFIX_1_IPV6="2001:db8:100"
14PREFIXLEN_1_IPV6="64"
15PREFIX_2_IPV6="2001:db8:200"
16PREFIXLEN_2_IPV6="64"
17
18# From RFC 5737
19PREFIX_1_IPV4="198.51.100"
20PREFIXLEN_1_IPV4="24"
21PREFIX_2_IPV4="203.0.113"
22PREFIXLEN_2_IPV4="24"
23
24# Remote and local addresses for the tunnel.
25IPV6_ADDR_REMOTE="2001:db8::1"
26IPV6_ADDR_LOCAL="2001:db8::2"
27IPV6_ROUTE_LOCAL="2001:db8::/64"
28IPV4_ADDR_REMOTE="192.0.2.1"
29IPV4_ADDR_LOCAL="192.0.2.2"
30IPV4_ROUTE_LOCAL="192.0.2.0/24"
31
32ip link set dev ${INTERFACE} up
33ip link set dev ${INTERFACE} address ${HWADDR}
34
35ip -6 address add ${IPV6_ADDR_LOCAL} dev ${INTERFACE}
36ip -6 route add ${IPV6_ROUTE_LOCAL} dev ${INTERFACE}
37ip address add ${IPV4_ADDR_LOCAL} dev ${INTERFACE}
38ip route add ${IPV4_ROUTE_LOCAL} dev ${INTERFACE}
39
40ip tunnel add name ${TUNNEL_V4V4} mode ipip local ${IPV4_ADDR_LOCAL} \
41	remote ${IPV4_ADDR_REMOTE} dev ${INTERFACE}
42
43ip tunnel add name ${TUNNEL_V6V4} mode sit local ${IPV4_ADDR_LOCAL} \
44	remote ${IPV4_ADDR_REMOTE} dev ${INTERFACE}
45
46ip tunnel add name ${TUNNEL_V4V6} mode ipip6 local ${IPV6_ADDR_LOCAL} \
47	remote ${IPV6_ADDR_REMOTE} dev ${INTERFACE}
48
49# Create separate ip6ip6 link, otherwise the tunnel creation can fail
50# (because default interface ip6tnl0 might already exist)
51ip link add name ${TUNNEL_V6V6} type ip6tnl local ${IPV6_ADDR_LOCAL} \
52	remote ${IPV6_ADDR_REMOTE} mode ip6ip6
53ip tunnel add name ${TUNNEL_V6V6} mode ip6ip6 local ${IPV6_ADDR_LOCAL} \
54	remote ${IPV6_ADDR_REMOTE} dev ${INTERFACE}
55
56ip link set ${TUNNEL_V4V4} up
57ip link set ${TUNNEL_V6V4} up
58ip link set ${TUNNEL_V4V6} up
59ip link set ${TUNNEL_V6V6} up
60
61ip addr add ${PREFIX_1_IPV4}.2/${PREFIXLEN_1_IPV4} dev ${TUNNEL_V4V4}
62ip addr add ${PREFIX_2_IPV4}.2/${PREFIXLEN_2_IPV4} dev ${TUNNEL_V4V6}
63ip route add ${PREFIX_1_IPV4}/${PREFIXLEN_1_IPV4} dev ${TUNNEL_V4V4}
64ip route add ${PREFIX_2_IPV4}/${PREFIXLEN_2_IPV4} dev ${TUNNEL_V4V6}
65
66ip -6 addr add ${PREFIX_1_IPV6}::2/${PREFIXLEN_1_IPV6} dev ${TUNNEL_V6V6}
67ip -6 addr add ${PREFIX_2_IPV6}::2/${PREFIXLEN_2_IPV6} dev ${TUNNEL_V6V4}
68ip -6 route add ${PREFIX_1_IPV6}::/${PREFIXLEN_1_IPV6} dev ${TUNNEL_V6V6}
69ip -6 route add ${PREFIX_2_IPV6}::/${PREFIXLEN_2_IPV6} dev ${TUNNEL_V6V4}
70