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 ###--------------------------------------------------------------------------
34 tripectl warn tripe-ifup command-failed rc
=$rc "$*"
39 ###--------------------------------------------------------------------------
40 ### Collect arguments.
42 ## Collect the simple arguments.
44 echo >&2 "usage: $0 PEER IFNAME ADDR..."; exit 1
46 peer
=$1 ifname
=$2 family
=$3; shift 3
48 ## Parse the address family.
52 *) echo >&2 "$0: unknown address family $family"; exit 1 ;;
55 INET
,1 | INET6
,1) addr
=$1 port
=4070 ;;
56 INET
,2 | INET6
,2) addr
=$1 port
=$2 ;;
57 INET
,* | INET6
,*) echo >&2 "$0: bad $family address"; exit 1 ;;
58 *) echo >&2 "$0: unknown address family $family"; exit 1 ;;
61 ###--------------------------------------------------------------------------
62 ### Set the interface name.
64 case "${P_IFNAME+set}" in
66 try ip link
set "$ifname" name
"$P_IFNAME"
68 $tripectl setifname
"$peer" "$ifname"
72 ###--------------------------------------------------------------------------
73 ### Configure the link.
75 ## Split local addresses into v4 and v6 lists.
79 *:*) l6addr
=${l6addr+$l6addr }$a ;;
80 *) l4addr
=${l4addr+$l4addr }$a ;;
84 ## Determine the remote v4 and v6 addresses. We only allow one remote
85 ## address for each: others can be added as routes.
94 ## Configure the first v4 address as point-to-point; add the others as plain
98 case $#,${r4addr+set} in
100 try ip addr add
"$1" peer
"$r4addr" dev
"$ifname"
106 try ip addr add
"$a" dev
"$ifname"
110 ## IPv6 point-to-point links seem broken in Linux. Attach the local and
111 ## remote addresses by hand.
117 ## If we're configured to set IPv6 addresses then we should ensure that
118 ## they're going to work, even if the default setting for new interfaces
119 ## is to disable IPv6.
120 try sysctl
-q net.ipv6.conf.
"$ifname".disable_ipv6
=0
122 ## Now add the source and destination addresses.
124 try ip addr add
"$a" dev
"$ifname"
130 ###--------------------------------------------------------------------------
131 ### Bring the interface up.
133 case $haveaddr4,$haveaddr6 in
137 case "${P_MTU+set}" in
141 pathmtu
=$
(pathmtu
"$addr")
142 mtu
=$
(( $pathmtu - $ipsz - 9 - $A_BULK_OVERHEAD ))
145 try ip link
set dev
"$ifname" up mtu
"$mtu"
149 ###--------------------------------------------------------------------------
150 ### Set the peer IPv6 address if any.
152 ## IPv6 point-to-point links seem broken in Linux. Attach the local and
153 ## remote addresses by hand.
155 case $have6,$#,${r6addr+set} in
157 try ip route add
$r6addr proto static dev
"$ifname"
161 ###--------------------------------------------------------------------------
164 ## Split the routes into v4 and v6 lists.
168 *:*) route6
=${route6+$route6 }$p ;;
169 *) route4
=${route4+$route4 }$p ;;
173 ## Add the v4 routes.
175 case $haveaddr4,$# in
178 try ip route add
$p proto static via
"$r4addr"
183 ## Add the v6 routes.
185 case $haveaddr6,$# in
188 try ip route add
$p proto static via
"${r6addr%/*}"
193 ###--------------------------------------------------------------------------
194 ### Maybe invoke a follow-on script.
196 case "${P_IFUPEXTRA+set}" in
202 ###--------------------------------------------------------------------------
203 ### Issue a notification that we've won.
206 t
) $tripectl notify tripe-ifup configured
"$peer" ;;
207 nil
) $tripectl notify tripe-ifup configured
"$peer" failed
;;
210 ###----- That's all, folks --------------------------------------------------