#! /bin/bash

# TunnelDigger "up" command
#
#    Copyright (C) 2000-2002 Tommi Virtanen <tv@debian.org>
#    Copyright (C) 2003 Kai Henningsen <kai@debian.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Parameters:
# 1 peer name
# 2 local interface addresses
# 3 remote networks to route
# 4 dev
# 5 tunmtu
# 6 udpmtu
# 7 localip
# 8 remoteip

DEV="$(echo "td-$1"|cut -c -15)"
ip li set dev "$4" down
ip li set dev "$4" name "$DEV" || DEV="$4"
ip li set dev "$DEV" up mtu "$5"

ifconfig $DEV $7 pointopoint $8 mtu $5
for i in $2
do
	ip a add "$i"/32 scope host dev "$DEV"
done

for i in $3
do
	ip ro add "$i" dev "$DEV"
done

