chiark / gitweb /
server/tests.at: Fix TRIPECTL_INTERACT argument order.
[tripe] / svc / tripe-ifup.in
CommitLineData
a62f8e8a
MW
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
16set -e
17
18: ${bindir=@bindir@}
19: ${tripectl=$bindir/tripectl}
20PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
21export PATH TRIPEDIR
22
23###--------------------------------------------------------------------------
24### Collect arguments.
25
26## Collect the simple arguments.
27if [ $# -lt 3 ]; then
28 echo >&2 "usage: $0 PEER IFNAME ADDR..."; exit 1
29fi
30peer=$1 ifname=$2 family=$3; shift 3
31
32## Parse the address family.
33case "$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 ;;
38esac
39
40###--------------------------------------------------------------------------
41### Set the interface name.
42
43case "${P_IFNAME+set}" in
44 set)
45 ip link set "$ifname" name "$P_IFNAME"
46 ifname=$P_IFNAME
47 $tripectl setifname "$peer" "$ifname"
48 ;;
49esac
50
51###--------------------------------------------------------------------------
52### Configure the point-to-point link.
53
54ifup=no
55case "${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 ;;
67esac
68
69###--------------------------------------------------------------------------
70### Set up routing.
71
72case "$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 ;;
78esac
79
80###--------------------------------------------------------------------------
81### Maybe invoke a follow-on script.
82
83case "${P_IFUPEXTRA+set}" in
84 set)
85 eval "$P_IFUPEXTRA"
86 ;;
87esac
88
89###--------------------------------------------------------------------------
90### Issue a notification that we've won.
91
92$tripectl notify tripe-ifup configured "$peer"
93
94###----- That's all, folks --------------------------------------------------