2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/usr
/lib
/network
/header-config
24 HOOK_MANPAGE
="network-config-ipv4-static"
26 HOOK_SETTINGS
="HOOK ADDRESS PREFIX GATEWAY"
28 function hook_check
() {
30 assert isinteger PREFIX
32 if [ ${PREFIX} -gt 30 ]; then
33 error
"PREFIX is greater than 30."
38 function hook_create
() {
40 assert zone_exists
"${zone}"
45 local key
="$(cli_get_key "${arg}")"
46 local val
="$(cli_get_val "${arg}")"
50 if ! ipv4_is_valid
"${val}"; then
51 error
"Invalid IPv4 address: ${val}"
52 exit ${EXIT_CONF_ERROR}
59 if ! ipv4_prefix_is_valid
"${val}"; then
60 error
"Invalid IPv4 prefix: ${val}"
61 exit ${EXIT_CONF_ERROR}
68 if ! ipv4_is_valid
"${val}"; then
69 error
"Invalid IPv4 address for gateway: ${val}"
70 exit ${EXIT_CONF_ERROR}
76 # Compatibility switches
78 if ! ipv4_netmask_is_valid
"${val}"; then
79 error
"Invalid netmask: ${val}"
80 exit ${EXIT_CONF_ERROR}
83 # The netmask will be converted into a prefix
84 PREFIX
="$(ipv4_netmask2prefix ${val})"
89 error
"Unhandled argument: ${arg}"
90 exit ${EXIT_CONF_ERROR}
95 if ! isset ADDRESS
; then
96 error
"You need to provide an IPv4 address"
97 exit ${EXIT_CONF_ERROR}
100 if ! isset PREFIX
; then
101 error
"You need to provide an IPv4 prefix"
102 exit ${EXIT_CONF_ERROR}
105 if ! isset GATEWAY
&& zone_is_nonlocal
"${zone}"; then
106 warning
"You did not configure a gateway for a non-local zone"
109 # XXX maybe we can add some hashing to identify a configuration again
110 zone_config_settings_write
"${zone}" "${HOOK}.$(uuid)" ${HOOK_SETTINGS}
120 if ! device_exists ${zone}; then
121 error "Zone
'${zone}' doesn
't exist."
125 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
127 ip_address_add ${zone} ${ADDRESS}/${PREFIX}
130 routing_db_set ${zone} ipv4 type "${HOOK}"
131 routing_db_set ${zone} ipv4 local-ip-address "${ADDRESS}/${PREFIX}"
132 routing_db_set ${zone} ipv4 remote-ip-address "${GATEWAY}"
133 routing_db_set ${zone} ipv4 active 1
135 routing_update ${zone} ipv4
136 routing_default_update
141 function hook_down() {
146 if ! device_exists ${zone}; then
147 error "Zone '${zone}' doesn't exist.
"
151 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
153 ip_address_del
${zone} ${ADDRESS}/${PREFIX}
155 # Update routing tables.
156 routing_default_update
161 function hook_status
() {
166 if ! device_exists
${zone}; then
167 error
"Zone '${zone}' doesn't exist."
171 zone_config_settings_read
"${zone}" "${config}" ${HOOK_SETTINGS}
174 if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
175 status=${MSG_HOOK_UP}
177 status=${MSG_HOOK_DOWN}
179 cli_statusline 3 "${HOOK}" "${status}"
181 cli_print_fmt1 3 "IPv4 address
" "${ADDRESS}/${PREFIX}"
182 if [ -n "${GATEWAY}" ]; then
183 cli_print_fmt1 3 "Gateway
" "${GATEWAY}"