4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
# Copyright (C) 1996-2009 Red Hat, Inc. all rights reserved.
|
|
|
3 |
#
|
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
|
5 |
# it under the terms of the GNU General Public License, version 2,
|
|
|
6 |
# as published by the Free Software Foundation.
|
|
|
7 |
#
|
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
# GNU General Public License for more details.
|
|
|
12 |
#
|
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
15 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
16 |
|
|
|
17 |
# Thanks to:
|
|
|
18 |
# - Razvan Corneliu C.R. Vilt <razvan.vilt@linux360.ro>
|
|
|
19 |
# - Aaron Hope <aaron.hope@unh.edu>
|
|
|
20 |
# - Sean Millichamp <sean@enertronllc.com>
|
|
|
21 |
# for providing the scripts this one is based on
|
|
|
22 |
|
|
|
23 |
. /etc/init.d/functions
|
|
|
24 |
|
|
|
25 |
cd /etc/sysconfig/network-scripts
|
|
|
26 |
. ./network-functions
|
|
|
27 |
|
|
|
28 |
CONFIG=$1
|
|
|
29 |
need_config "$CONFIG"
|
|
|
30 |
source_config
|
|
|
31 |
|
|
|
32 |
if [ "$PEER_OUTER_IPADDR" = "$PEER_INNER_IPADDR" ]; then
|
|
|
33 |
# Specifying PEER_INNER_IPADDR would automatically add a route to the peer
|
|
|
34 |
# through the tunnel, redirecting tunnel packets back to the tunnel and
|
|
|
35 |
# creating a dead loop.
|
|
|
36 |
unset PEER_INNER_IPADDR
|
|
|
37 |
fi
|
|
|
38 |
|
|
|
39 |
case "$TYPE" in
|
|
|
40 |
GRE)
|
|
|
41 |
MODE=gre
|
|
|
42 |
/sbin/modprobe ip_gre
|
|
|
43 |
;;
|
|
|
44 |
IPIP)
|
|
|
45 |
MODE=ipip
|
|
|
46 |
/sbin/modprobe ipip
|
|
|
47 |
;;
|
|
|
48 |
*)
|
|
|
49 |
net_log $"Invalid tunnel type $TYPE"
|
|
|
50 |
exit 1
|
|
|
51 |
;;
|
|
|
52 |
esac
|
|
|
53 |
|
|
|
54 |
# Generic tunnel devices are not supported here
|
|
|
55 |
if [ "$DEVICE" = gre0 -o "$DEVICE" = tunl0 ]; then
|
|
|
56 |
net_log $"Device '$DEVICE' isn't supported as a valid GRE device name."
|
|
|
57 |
exit 1
|
|
|
58 |
fi
|
|
|
59 |
|
|
|
60 |
# Create the tunnel
|
|
|
61 |
# The outer addresses are those of the underlying (public) network.
|
|
|
62 |
/sbin/ip tunnel add "$DEVICE" mode "$MODE" \
|
|
|
63 |
${MY_OUTER_IPADDR:+local "$MY_OUTER_IPADDR"} \
|
|
|
64 |
${PEER_OUTER_IPADDR:+remote "$PEER_OUTER_IPADDR"} \
|
|
|
65 |
${KEY:+key "$KEY"} ${TTL:+ttl "$TTL"}
|
|
|
66 |
|
|
|
67 |
if [ -n "$MTU" ]; then
|
|
|
68 |
/sbin/ip link set "$DEVICE" mtu "$MTU"
|
|
|
69 |
fi
|
|
|
70 |
|
|
|
71 |
# The inner address are used mainly for communication between a gateway
|
|
|
72 |
# and a private network. When the peer is configured with an inner address
|
|
|
73 |
# contained in the peer's private network or identical to it's public address,
|
|
|
74 |
# it need not be specified.
|
|
|
75 |
/sbin/ip addr add "$MY_INNER_IPADDR" dev "$DEVICE" \
|
|
|
76 |
${PEER_INNER_IPADDR:+peer "$PEER_INNER_IPADDR"}
|
|
|
77 |
|
|
|
78 |
/sbin/ip link set dev "$DEVICE" up
|
|
|
79 |
|
|
|
80 |
exec /etc/sysconfig/network-scripts/ifup-post "$CONFIG" "$2"
|