]>
Commit | Line | Data |
---|---|---|
cccb3a4b MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
9390b61b | 5 | # Copyright (C) 2012-2013 IPFire Network Development Team # |
cccb3a4b MT |
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 | ||
1c6a4e30 | 24 | ip_tunnel_add() { |
cccb3a4b MT |
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=*) | |
9390b61b | 37 | mode="$(cli_get_val ${1})" |
cccb3a4b MT |
38 | ;; |
39 | --ttl=*) | |
9390b61b | 40 | ttl="$(cli_get_val ${1})" |
cccb3a4b MT |
41 | ;; |
42 | ||
43 | --remote-address=*) | |
9390b61b | 44 | remote_address="$(cli_get_val ${1})" |
cccb3a4b MT |
45 | ;; |
46 | --local-address=*) | |
9390b61b | 47 | local_address="$(cli_get_val ${1})" |
cccb3a4b MT |
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 | ||
cccb3a4b MT |
59 | assert isset local_address |
60 | ||
61 | local cmd_args | |
62 | ||
63 | # Apply TTL if a value has been set. | |
64 | if isset ttl; then | |
65 | cmd_args="${cmd_args} ttl ${ttl}" | |
66 | fi | |
67 | ||
9390b61b SS |
68 | # Apply remote address if a value has been set. |
69 | if isset remote_address; then | |
70 | cmd_args="${cmd_args} remote ${remote_address}" | |
71 | fi | |
72 | ||
cccb3a4b MT |
73 | log DEBUG "Creating tunnel device '${device}' (mode=${mode})..." |
74 | ||
75 | # Create the device. | |
76 | cmd ip tunnel add ${device} mode ${mode} \ | |
9390b61b | 77 | local ${local_address} ${cmd_args} |
cccb3a4b MT |
78 | assert [ $? -eq 0 ] |
79 | } | |
80 | ||
1c6a4e30 | 81 | ip_tunnel_del() { |
cccb3a4b MT |
82 | local device=${1} |
83 | assert device_exists ${device} | |
84 | ||
85 | # Make sure the device has been shut down. | |
86 | device_set_down ${device} | |
87 | ||
88 | log DEBUG "Removing tunnel device '${device}'..." | |
89 | ||
90 | ip tunnel del ${device} | |
91 | assert [ $? -eq 0 ] | |
92 | } | |
9390b61b | 93 | |
1c6a4e30 | 94 | ip_tunnel_6rd_set_prefix() { |
9390b61b SS |
95 | local device="${1}" |
96 | assert isset device | |
97 | ||
98 | local prefix="${2}" | |
99 | assert isset prefix | |
100 | ||
101 | # Validate the prefix. | |
102 | assert ipv6_is_valid "${prefix}" | |
103 | ||
104 | log INFO "Setting 6rd-prefix ${prefix} on ${device}" | |
105 | ||
106 | # Set the prefix. | |
107 | cmd ip tunnel 6rd dev "${device}" 6rd-prefix "${prefix}" | |
108 | assert [ $? -eq 0 ] | |
109 | } |