1# Configuration file for setting IP addresses for multiple network interface. 2 3INTERFACE_PREFIX="$1" 4 5HWADDR_PREFIX="00:00:5e:00:53:" 6 7IPV6_ADDR_PREFIX0="2001:db8::" 8IPV6_ROUTE0="2001:db8::/64" 9 10IPV6_ADDR_PREFIX1="2001:db8:2::" 11IPV6_ROUTE1="2001:db8:2::/64" 12 13IPV4_ADDR_PREFIX0="192.0.2." 14IPV4_ADDR_PREFIX1="198.51.100." 15 16INTERFACE0=${INTERFACE_PREFIX} 17INTERFACE1=`echo ${INTERFACE_PREFIX} | sed "s/0/1/g"` 18 19IPV4_ROUTE0="${IPV4_ADDR_PREFIX0}0/24" 20IPV4_ROUTE1="${IPV4_ADDR_PREFIX1}0/24" 21 22# The zeth0 is already created by net-setup script so avoid 23# doing it twice. 24ip link set dev ${INTERFACE0} up 25ip link set dev ${INTERFACE0} address ${HWADDR_PREFIX}0 26ip -6 address add ${IPV6_ADDR_PREFIX0}2 dev $INTERFACE0 nodad 27ip -6 route add $IPV6_ROUTE0 dev $INTERFACE0 28ip address add ${IPV4_ADDR_PREFIX0}2 dev $INTERFACE0 29ip route add $IPV4_ROUTE0 dev $INTERFACE0 2>&1 30 31COUNT=${COUNTER:-2} 32 33INTERFACE_TMPL=`echo ${INTERFACE_PREFIX} | sed "s/0//g"` 34 35for ((i = 1; i < $COUNT; i++ )); { 36 iface_idx=$i 37 INTERFACE=${INTERFACE_TMPL}${iface_idx} 38 39 ip tuntap add ${INTERFACE} mode tap 40 ip link set dev ${INTERFACE} up 41 42 # If there are config options then try to apply them. 43 # TODO: this should be changed to use a yaml file or similar. 44 VAR_CHECK="INTERFACE${iface_idx}" 45 if [ -n "${!VAR_CHECK}" ]; then 46 ip link set dev ${INTERFACE} address ${HWADDR_PREFIX}${iface_idx} 47 VAR=IPV6_ADDR_PREFIX${iface_idx} 48 ip -6 address add ${!VAR}${iface_idx} dev ${INTERFACE} nodad 49 VAR=IPV6_ROUTE${iface_idx} 50 ip -6 route add ${!VAR} dev ${INTERFACE} 51 VAR=IPV4_ADDR_PREFIX${iface_idx} 52 ip address add ${!VAR}${iface_idx} dev ${INTERFACE} 53 VAR=IPV4_ROUTE${iface_idx} 54 ip route add ${!VAR} dev ${INTERFACE} 2>&1 55 fi 56} 57