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