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