chiark / gitweb /
Allow the caller to configure the administration socket permissions.
[tripe] / svc / tripe-ifup.in
1 #! /bin/sh
2 ###
3 ### TrIPE interface initialization script
4 ###   suitable for Linux; other operating systems probably want something
5 ###   similar
6
7 ###----- Licensing notica ---------------------------------------------------
8 ###
9 ### Redistribution, modification and use of this file is permitted without
10 ### limitation.
11 ###
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.
15
16 set -e
17
18 : ${bindir=@bindir@}
19 : ${tripectl=$bindir/tripectl}
20 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
21 export PATH TRIPEDIR
22
23 ###--------------------------------------------------------------------------
24 ### Collect arguments.
25
26 ## Collect the simple arguments.
27 if [ $# -lt 3 ]; then
28   echo >&2 "usage: $0 PEER IFNAME ADDR..."; exit 1
29 fi
30 peer=$1 ifname=$2 family=$3; shift 3
31
32 ## Parse the address family.
33 case "$family,$#" in
34   INET,1) addr=$1 port=4070 ;;
35   INET,2) addr=$1 port=$2 ;;
36   INET,*) echo >&2 "$0: bad INET address"; exit 1 ;;
37   *)      echo >&2 "$0: unknown address family $family"; exit 1 ;;
38 esac
39
40 ###--------------------------------------------------------------------------
41 ### Set the interface name.
42
43 case "${P_IFNAME+set}" in
44   set)
45     ip link set "$ifname" name "$P_IFNAME"
46     ifname=$P_IFNAME
47     $tripectl setifname "$peer" "$ifname"
48     ;;
49 esac
50
51 ###--------------------------------------------------------------------------
52 ### Configure the point-to-point link.
53
54 ifup=no
55 case "${P_LADDR+set},${P_RADDR+set}" in
56   set,set)
57     case "${P_MTU+set}" in
58       set) mtu=$P_MTU;;
59       *)
60         pathmtu=$(pathmtu "$addr")
61         mtu=$(expr "$pathmtu" - 33 - $A_CIPHER_BLKSZ - $A_MAC_TAGSZ)
62         ;;
63     esac
64     ifconfig "$ifname" "$P_LADDR" pointopoint "$P_RADDR" up mtu "$mtu"
65     ifup=yes
66     ;;
67 esac
68
69 ###--------------------------------------------------------------------------
70 ### Set up routing.
71
72 case "$ifup,${P_NETS+set}" in
73   yes,set)
74     for net in $P_NETS; do
75       route add -net $net gw "$P_RADDR" dev "$ifname" metric 2
76     done
77     ;;
78 esac
79
80 ###--------------------------------------------------------------------------
81 ### Maybe invoke a follow-on script.
82
83 case "${P_IFUPEXTRA+set}" in
84   set)
85     eval "$P_IFUPEXTRA"
86     ;;
87 esac
88
89 ###--------------------------------------------------------------------------
90 ### Issue a notification that we've won.
91
92 $tripectl notify tripe-ifup configured "$peer"
93
94 ###----- That's all, folks --------------------------------------------------