]>
Commit | Line | Data |
---|---|---|
e9ea243e 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 | ||
f41fa3d7 | 22 | . /usr/lib/network/header-config |
e9ea243e | 23 | |
b98a1b86 | 24 | HOOK_CONFIG_SETTINGS="HOOK ENABLE_IPV6 ENABLE_IPV4" |
e9ea243e MT |
25 | |
26 | # Default settings. | |
9353a4e4 JS |
27 | ENABLE_IPV6="on" |
28 | ENABLE_IPV4="on" | |
e9ea243e | 29 | |
b6d9bf2b | 30 | hook_check_config_settings() { |
9353a4e4 JS |
31 | assert isset ENABLE_IPV6 |
32 | assert isbool ENABLE_IPV6 | |
33 | assert isset ENABLE_IPV4 | |
34 | assert isbool ENABLE_IPV4 | |
e9ea243e MT |
35 | } |
36 | ||
9353a4e4 | 37 | hook_parse_cmdline() { |
320f1fda JS |
38 | local id="${1}" |
39 | shift | |
40 | ||
e9ea243e MT |
41 | while [ $# -gt 0 ]; do |
42 | case "${1}" in | |
9353a4e4 JS |
43 | --enable-ipv6) |
44 | ENABLE_IPV6="on" | |
45 | ;; | |
46 | --disable-ipv6) | |
47 | ENABLE_IPV6="off" | |
48 | ;; | |
49 | --enable-ipv4) | |
50 | ENABLE_IPV4="on" | |
51 | ;; | |
52 | --disable-ipv4) | |
53 | ENABLE_IPV4="off" | |
54 | ;; | |
55 | *) | |
56 | warning "Ignoring unknown option '${1}'" | |
57 | ;; | |
e9ea243e MT |
58 | esac |
59 | shift | |
60 | done | |
e36f775d JS |
61 | |
62 | # Check if the user disabled ipv6 and ipv4 | |
63 | if ! enabled ENABLE_IPV6 && ! enabled ENABLE_IPV4; then | |
64 | log ERROR "You disabled IPv6 and IPv4. At least one must be enabled" | |
65 | return ${EXIT_ERROR} | |
66 | fi | |
9353a4e4 JS |
67 | } |
68 | ||
69 | hook_new() { | |
70 | local zone="${1}" | |
71 | shift | |
72 | ||
73 | if zone_config_hook_is_configured ${zone} "dhcp"; then | |
74 | log ERROR "You can configure the dhcp hook only once for a zone" | |
75 | return ${EXIT_ERROR} | |
76 | fi | |
77 | ||
320f1fda JS |
78 | local id=$(zone_config_get_new_id ${zone}) |
79 | log DEBUG "ID for the config is: ${id}" | |
80 | ||
81 | if ! hook_parse_cmdline "${id}" "$@"; then | |
9353a4e4 JS |
82 | # Return an error if the parsing of the cmd line fails |
83 | return ${EXIT_ERROR} | |
84 | fi | |
85 | ||
320f1fda | 86 | zone_config_settings_write "${zone}" "${HOOK}" "${id}" |
e9ea243e MT |
87 | |
88 | exit ${EXIT_OK} | |
89 | } | |
90 | ||
1c6a4e30 | 91 | hook_up() { |
e9ea243e MT |
92 | local zone=${1} |
93 | local config=${2} | |
94 | shift 2 | |
95 | ||
96 | if ! device_exists ${zone}; then | |
97 | error "Zone '${zone}' doesn't exist." | |
98 | exit ${EXIT_ERROR} | |
99 | fi | |
100 | ||
9353a4e4 JS |
101 | zone_config_settings_read "${zone}" "${config}" |
102 | ||
103 | # Start dhclient for IPv6 on this zone if enabled. | |
104 | if enabled ENABLE_IPV6; then | |
105 | dhclient_start ${zone} ipv6 | |
106 | fi | |
107 | ||
108 | # Start dhclient for IPv4 on this zone if enabled. | |
109 | if enabled ENABLE_IPV4; then | |
110 | dhclient_start ${zone} ipv4 | |
111 | fi | |
e9ea243e MT |
112 | |
113 | exit ${EXIT_OK} | |
114 | } | |
115 | ||
1c6a4e30 | 116 | hook_down() { |
e9ea243e MT |
117 | local zone=${1} |
118 | local config=${2} | |
119 | shift 2 | |
120 | ||
121 | if ! device_exists ${zone}; then | |
122 | error "Zone '${zone}' doesn't exist." | |
123 | exit ${EXIT_ERROR} | |
124 | fi | |
125 | ||
9353a4e4 JS |
126 | # Stop dhclient for IPv6 on this zone. |
127 | dhclient_stop ${zone} ipv6 | |
128 | ||
e9ea243e MT |
129 | # Stop dhclient for IPv4 on this zone. |
130 | dhclient_stop ${zone} ipv4 | |
131 | ||
132 | exit ${EXIT_OK} | |
133 | } | |
134 | ||
1c6a4e30 | 135 | hook_status() { |
e9ea243e MT |
136 | local zone=${1} |
137 | local config=${2} | |
138 | shift 2 | |
139 | ||
140 | if ! device_exists ${zone}; then | |
141 | error "Zone '${zone}' doesn't exist." | |
142 | exit ${EXIT_ERROR} | |
143 | fi | |
e9df08ad | 144 | |
b6d9bf2b | 145 | zone_config_settings_read "${zone}" "${config}" |
e9ea243e | 146 | |
8e3508ac | 147 | local status |
9353a4e4 | 148 | if dhclient_status ${zone} ipv4 || dhclient_status ${zone} ipv6; then |
8e3508ac | 149 | status="${MSG_HOOK_UP}" |
e9ea243e | 150 | else |
8e3508ac | 151 | status="${MSG_HOOK_DOWN}" |
e9ea243e | 152 | fi |
8e3508ac | 153 | cli_statusline 3 "${HOOK}" "${status}" |
e9ea243e | 154 | |
9353a4e4 JS |
155 | cli_space |
156 | ||
157 | local proto | |
158 | for proto in "IPv6" "IPv4"; do | |
159 | local _proto=${proto,,} | |
160 | ||
161 | cli_print_fmt1 3 "${proto}" | |
162 | ||
163 | if enabled ENABLE_${proto^^}; then | |
164 | cli_print_fmt1 4 "Status" "enabled" | |
165 | ||
166 | local address="$(db_get "${zone}/${_proto}/local-ip-address")" | |
167 | if isset address; then | |
168 | cli_print_fmt1 4 "Address" "${address}" | |
169 | fi | |
170 | ||
171 | local gateway="$(db_get "${zone}/${_proto}/remote-ip-address")" | |
172 | if isset gateway; then | |
173 | cli_print_fmt1 4 "Gateway" "${gateway}" | |
174 | fi | |
175 | ||
176 | local dns_servers="$(db_get "${zone}/${_proto}/domain-name-servers")" | |
177 | if isset dns_servers; then | |
178 | cli_print_fmt1 4 "DNS Servers" "${dns_servers}" | |
179 | fi | |
180 | else | |
181 | cli_print_fmt1 4 "Status" "disabled" | |
182 | fi | |
183 | ||
ffea9f57 | 184 | cli_space |
9353a4e4 JS |
185 | |
186 | done | |
e9ea243e MT |
187 | |
188 | exit ${EXIT_OK} | |
189 | } |