3 ### TrIPE interface initialization script
4 ### suitable for Linux; other operating systems probably want something
7 ###----- Licensing notica ---------------------------------------------------
9 ### Redistribution, modification and use of this file is permitted without
12 ### This file is distributed in the hope that it will be useful,
13 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ## Import compile-time configuration.
20 : ${tripectl=$bindir/tripectl}
21 PATH
=/usr
/bin
:/usr
/sbin
:/bin
:/sbin
:$bindir
24 ## Determine whether we have IPv6 support.
25 if [ -d
/proc
/sys
/net
/ipv6
]; then have6
=t
; else have6
=nil
; fi
27 ###--------------------------------------------------------------------------
28 ### Collect arguments.
30 ## Collect the simple arguments.
32 echo >&2 "usage: $0 PEER IFNAME ADDR..."; exit 1
34 peer
=$1 ifname
=$2 family
=$3; shift 3
36 ## Parse the address family.
38 INET
,1) addr
=$1 port
=4070 ;;
39 INET
,2) addr
=$1 port
=$2 ;;
40 INET
,*) echo >&2 "$0: bad INET address"; exit 1 ;;
41 *) echo >&2 "$0: unknown address family $family"; exit 1 ;;
44 ###--------------------------------------------------------------------------
45 ### Set the interface name.
47 case "${P_IFNAME+set}" in
49 ip link
set "$ifname" name
"$P_IFNAME"
51 $tripectl setifname
"$peer" "$ifname"
55 ###--------------------------------------------------------------------------
56 ### Configure the point-to-point link.
58 ## Split local addresses into v4 and v6 lists.
62 *:*) l6addr
=${l6addr+$l6addr }$a ;;
63 *) l4addr
=${l4addr+$l4addr }$a ;;
67 ## Determine the remote v4 and v6 addresses. We only allow one remote
68 ## address for each: others can be added as routes.
77 ## Configure the first v4 address as point-to-point; add the others as plain
81 case $#,${r4addr+set} in
83 ip addr add
"$1" peer
"$r4addr" dev
"$ifname"
89 ip addr add
"$a/32" dev
"$ifname"
93 ## IPv6 point-to-point links seem broken in Linux. Attach the local and
94 ## remote addresses by hand.
100 ip addr add
"$a/128" dev
"$ifname"
103 case ${r6addr+set} in
104 set) ip route add
$r6addr/128 dev
"$ifname" ;;
109 ###--------------------------------------------------------------------------
110 ### Bring the interface up.
112 case $haveaddr4,$haveaddr6 in
116 case "${P_MTU+set}" in
120 pathmtu
=$
(pathmtu
"$addr")
121 mtu
=$
(expr "$pathmtu" - 33 - $A_CIPHER_BLKSZ - $A_MAC_TAGSZ)
124 ip link
set dev
"$ifname" up mtu
"$mtu"
128 ###--------------------------------------------------------------------------
131 ## Split the routes into v4 and v6 lists.
135 *:*) route6
=${route6+$route6 }$p ;;
136 *) route4
=${route4+$route4 }$p ;;
140 ## Add the v4 routes.
142 case $haveaddr4,$# in
145 ip route add
$p via
"$r4addr"
150 ## Add the v6 routes.
152 case $haveaddr6,$# in
155 ip route add
$p via
"$r6addr"
160 ###--------------------------------------------------------------------------
161 ### Maybe invoke a follow-on script.
163 case "${P_IFUPEXTRA+set}" in
169 ###--------------------------------------------------------------------------
170 ### Issue a notification that we've won.
172 $tripectl notify tripe-ifup configured
"$peer"
174 ###----- That's all, folks --------------------------------------------------