]> git.ipfire.org Git - people/stevee/network.git/blob - functions.ip-tunnel
Don't use connection tracking for loopback traffic.
[people/stevee/network.git] / functions.ip-tunnel
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program 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. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 IP_TUNNEL_MODES="sit"
23
24 function ip_tunnel_add() {
25 local device=${1}
26 shift
27
28 local mode="sit"
29 local ttl
30
31 local remote_address
32 local local_address
33
34 while [ $# -gt 0 ]; do
35 case "${1}" in
36 --mode=*)
37 mode=$(cli_get_val ${1})
38 ;;
39 --ttl=*)
40 ttl=$(cli_get_val ${1})
41 ;;
42
43 --remote-address=*)
44 remote_address=$(cli_get_val ${1})
45 ;;
46 --local-address=*)
47 local_address=$(cli_get_val ${1})
48 ;;
49 esac
50 shift
51 done
52
53 assert isset mode
54 assert isoneof mode ${IP_TUNNEL_MODES}
55
56 # If TTL is set, make sure it is an integer.
57 isset ttl && assert isinteger ttl
58
59 assert isset remote_address
60 assert isset local_address
61
62 local cmd_args
63
64 # Apply TTL if a value has been set.
65 if isset ttl; then
66 cmd_args="${cmd_args} ttl ${ttl}"
67 fi
68
69 log DEBUG "Creating tunnel device '${device}' (mode=${mode})..."
70
71 # Create the device.
72 cmd ip tunnel add ${device} mode ${mode} \
73 remote ${remote_address} local ${local_address} ${cmd_args}
74 assert [ $? -eq 0 ]
75 }
76
77
78 function ip_tunnel_del() {
79 local device=${1}
80 assert device_exists ${device}
81
82 # Make sure the device has been shut down.
83 device_set_down ${device}
84
85 log DEBUG "Removing tunnel device '${device}'..."
86
87 ip tunnel del ${device}
88 assert [ $? -eq 0 ]
89 }