]>
Commit | Line | Data |
---|---|---|
cccb3a4b MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
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 | . /usr/lib/network/header-zone | |
23 | ||
24 | HOOK_SETTINGS="HOOK SERVER_ADDRESS LOCAL_ADDRESS LOCAL_ADDRESS6" | |
25 | ||
26 | # The IPv4 address of the tunnel endpoint where to connect to. | |
27 | SERVER_ADDRESS= | |
28 | ||
29 | # The local IPv4 address of the tunnel endpoint. | |
30 | LOCAL_ADDRESS= | |
31 | ||
32 | # The address that is assigned to the tunnel device (with prefix). | |
33 | LOCAL_ADDRESS6= | |
34 | ||
35 | function _check() { | |
36 | assert isset SERVER_ADDRESS | |
37 | assert isset LOCAL_ADDRESS | |
38 | assert isset LOCAL_ADDRESS6 | |
39 | } | |
40 | ||
41 | function _parse_cmdline() { | |
42 | local value | |
43 | ||
44 | while [ $# -gt 0 ]; do | |
45 | case "${1}" in | |
46 | --server-address=*) | |
47 | SERVER_ADDRESS=$(cli_get_val ${1}) | |
48 | ;; | |
49 | --local-ipv4-address=*) | |
50 | LOCAL_ADDRESS=$(cli_get_val ${1}) | |
51 | ;; | |
52 | --local-ipv6-address=*) | |
53 | LOCAL_ADDRESS6=$(cli_get_val ${1}) | |
54 | ;; | |
55 | *) | |
56 | echo "Unknown option: ${1}" >&2 | |
57 | exit ${EXIT_ERROR} | |
58 | ;; | |
59 | esac | |
60 | shift | |
61 | done | |
62 | } | |
63 | ||
64 | function _up() { | |
65 | local zone=${1} | |
66 | assert isset zone | |
67 | ||
68 | # Read configuration options. | |
69 | zone_config_read ${zone} | |
70 | ||
71 | ip_tunnel_add ${zone} --ttl=255 \ | |
72 | --remote-address="${SERVER_ADDRESS}" \ | |
73 | --local-address="${LOCAL_ADDRESS}" | |
74 | ||
75 | # Bring up the device. | |
76 | device_set_up ${zone} | |
77 | ||
78 | # Assign IPv6 address. | |
79 | ip_address_add ${zone} ${LOCAL_ADDRESS6} | |
80 | ||
81 | # Update routing information. | |
82 | routing_db_set ${zone} ipv6 type "${HOOK}" | |
83 | routing_db_set ${zone} ipv6 local-ip-address "${LOCAL_ADDRESS6}" | |
84 | routing_db_set ${zone} ipv6 active 1 | |
85 | ||
86 | # Update the routing database. | |
87 | routing_update ${zone} ipv6 | |
88 | routing_default_update | |
89 | ||
90 | exit ${EXIT_OK} | |
91 | } | |
92 | ||
93 | function _down() { | |
94 | local zone=${1} | |
95 | assert isset zone | |
96 | ||
97 | # Remove everything from the routing db. | |
98 | routing_db_remove ${zone} ipv6 | |
99 | routing_update ${zone} ipv6 | |
100 | routing_default_update | |
101 | ||
102 | # Remove the tunnel device. | |
103 | ip_tunnel_del ${zone} | |
104 | ||
105 | exit ${EXIT_OK} | |
106 | } | |
107 | ||
108 | function _status() { | |
109 | local zone=${1} | |
110 | assert isset zone | |
111 | ||
3cb2fc42 | 112 | cli_device_headline ${zone} |
cccb3a4b MT |
113 | |
114 | zone_config_read ${zone} | |
115 | ||
116 | local server_line="${SERVER_ADDRESS}" | |
117 | local server_hostname=$(dns_get_hostname ${SERVER_ADDRESS}) | |
118 | if [ -n "${server_hostname}" ]; then | |
119 | server_line="${server_line} (Hostname: ${server_hostname})" | |
120 | fi | |
121 | ||
3cb2fc42 MT |
122 | cli_headline 2 "Configuration" |
123 | cli_print_fmt1 2 "Server" "${server_line}" | |
124 | cli_print_fmt1 2 "Endpoint IPv4 address" "${LOCAL_ADDRESS}" | |
125 | cli_print_fmt1 2 "Endpoint IPv6 address" "${LOCAL_ADDRESS6}" | |
126 | cli_space | |
cccb3a4b MT |
127 | |
128 | exit ${EXIT_OK} | |
129 | } |