]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/configs/ipv6-auto
Fix zone_config_check_same_setting
[people/ms/network.git] / src / hooks / configs / ipv6-auto
CommitLineData
b73e9d43
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
22. /usr/lib/network/header-config
23
24HOOK_CONFIG_SETTINGS="HOOK PRIVACY_EXTENSIONS"
25
26# Privacy Extensions are disabled by default
27PRIVACY_EXTENSIONS="off"
28
1c6a4e30 29hook_check_config_settings() {
b73e9d43
MT
30 assert isbool PRIVACY_EXTENSIONS
31}
32
6ca65afb 33hook_parse_cmdline() {
320f1fda
JS
34 local id="${1}"
35 shift
36
6ca65afb 37 local arg
75e02e58 38
b73e9d43
MT
39 while read arg; do
40 case "${arg}" in
41 --privacy-extensions=*)
42 local val="$(cli_get_val "${arg}")"
43
44 if enabled val; then
45 PRIVACY_EXTENSIONS="on"
46 else
47 PRIVACY_EXTENSIONS="off"
48 fi
49 ;;
50 esac
2212045f 51 done <<< "$(args "$@")"
6ca65afb
JS
52}
53
54hook_new() {
55 local zone="${1}"
56 shift
57
58 if zone_config_hook_is_configured ${zone} "ipv6-auto"; then
59 log ERROR "You can configure the ipv6-auto hook only once for a zone"
60 return ${EXIT_ERROR}
61 fi
62
320f1fda
JS
63 local id=$(zone_config_get_new_id ${zone})
64 log DEBUG "ID for the config is: ${id}"
65
66 if ! hook_parse_cmdline "${id}" "$@"; then
6ca65afb
JS
67 # Return an error if the parsing of the cmd line fails
68 return ${EXIT_ERROR}
69 fi
b73e9d43 70
320f1fda 71 zone_config_settings_write "${zone}" "${HOOK}" "${id}"
b73e9d43
MT
72
73 exit ${EXIT_OK}
74}
75
1c6a4e30 76hook_up() {
b73e9d43
MT
77 local zone=${1}
78 shift
79
80 if ! device_exists ${zone}; then
81 error "Zone '${zone}' doesn't exist."
82 exit ${EXIT_ERROR}
83 fi
84
85 zone_config_settings_read "${zone}" "${HOOK}"
86
87 # Enable IPv6 auto-configuration
88 ipv6_device_autoconf_enable "${zone}"
89
90 # Set up privacy extensions (RFC3041)
91 if enabled PRIVACY_EXTENSIONS; then
92 ipv6_device_privacy_extensions_enable "${zone}"
93 else
94 ipv6_device_privacy_extensions_disable "${zone}"
95 fi
96
97 exit ${EXIT_OK}
98}
99
1c6a4e30 100hook_down() {
b73e9d43
MT
101 local zone=${1}
102 local config=${2}
103 shift 2
104
105 if ! device_exists ${zone}; then
106 error "Zone '${zone}' doesn't exist."
107 exit ${EXIT_ERROR}
108 fi
109
110 # Disable IPv6 auto-configuration
111 ipv6_device_autoconf_disable "${zone}"
112
113 exit ${EXIT_OK}
114}
115
1c6a4e30 116hook_status() {
b73e9d43
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
126 zone_config_settings_read "${zone}" "${config}"
127
128 local addresses=$(ipv6_device_get_addresses "${zone}" --scope="global")
129 local status
130 if isset addresses; then
131 status="${MSG_HOOK_UP}"
132 else
133 status="${MSG_HOOK_DOWN}"
134 fi
135 cli_statusline 3 "${HOOK}" "${status}"
136
137 if enabled PRIVACY_EXTENSIONS; then
138 cli_print_fmt1 3 "Privacy Extensions enabled"
139 cli_space
140 fi
141
142 local addr
143 for addr in ${addresses}; do
144 cli_print_fmt1 3 "IPv6 address" "${addr}"
145 done
146 cli_space
147
148 exit ${EXIT_OK}
149}