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_CONFIG_SETTINGS
="HOOK ADDRESS PREFIX GATEWAY"
26 hook_check_config_settings
() {
28 assert isinteger PREFIX
30 if [ ${PREFIX} -gt 64 ]; then
31 error
"PREFIX is greater than 64."
36 hook_parse_cmdline
() {
37 while [ $# -gt 0 ]; do
40 ADDRESS
=${1#--address=}
46 GATEWAY
=${1#--gateway=}
52 if zone_config_check_same_setting
"${zone}" "ipv6-static" "ADDRESS" "${ADDRESS}"; then
53 error
"An ipv6-static config with the same IPv6 address is already configured"
54 exit ${EXIT_CONF_ERROR}
57 # Store IPv6 address in small format.
58 ADDRESS
=$
(ipv6_format
"${ADDRESS}")
60 if [ -n "${GATEWAY}" ]; then
61 GATEWAY
=$
(ipv6_format
"${GATEWAY}")
69 if ! hook_parse_cmdline
"$@"; then
70 # Return an error if the parsing of the cmd line fails
74 zone_config_settings_write
"${zone}" "${HOOK}"
84 if ! device_exists
${zone}; then
85 error
"Zone '${zone}' doesn't exist."
89 zone_config_settings_read
"${zone}" "${config}"
91 ip_address_add
${zone} ${ADDRESS}/${PREFIX}
93 db_set
"${zone}/ipv6/local-ip-address" "${ADDRESS}/${PREFIX}"
94 db_set
"${zone}/ipv6/remote-ip-address" "${GATEWAY}"
95 db_set
"${zone}/ipv6/active" 1
97 routing_default_update
107 if ! device_exists
${zone}; then
108 error
"Zone '${zone}' doesn't exist."
112 # Remove routing information from database.
113 db_delete
"${zone}/ipv6"
115 zone_config_settings_read
"${zone}" "${config}"
117 ip_address_del
${zone} ${ADDRESS}/${PREFIX}
119 # Update routing tables.
120 routing_default_update
130 if ! device_exists
${zone}; then
131 error
"Zone '${zone}' doesn't exist."
135 zone_config_settings_read
"${zone}" "${config}"
137 # Make sure ADDRESS is as short as possible.
138 ADDRESS
=$
(ipv6_format
"${ADDRESS}")
141 if zone_has_ip
${zone} ${ADDRESS}/${PREFIX}; then
142 status
=${MSG_HOOK_UP}
144 status
=${MSG_HOOK_DOWN}
146 cli_statusline
3 "${HOOK}" "${status}"
148 cli_print_fmt1
3 "IPv6 address" "${ADDRESS}/${PREFIX}"
149 if [ -n "${GATEWAY}" ]; then
150 cli_print_fmt1
3 "Gateway" "${GATEWAY}"