]> git.ipfire.org Git - people/ms/network.git/blob - src/hooks/configs/ipv6-auto
Fix zone_config_check_same_setting
[people/ms/network.git] / src / hooks / configs / ipv6-auto
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
24 HOOK_CONFIG_SETTINGS="HOOK PRIVACY_EXTENSIONS"
25
26 # Privacy Extensions are disabled by default
27 PRIVACY_EXTENSIONS="off"
28
29 hook_check_config_settings() {
30 assert isbool PRIVACY_EXTENSIONS
31 }
32
33 hook_parse_cmdline() {
34 local id="${1}"
35 shift
36
37 local arg
38
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
51 done <<< "$(args "$@")"
52 }
53
54 hook_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
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
67 # Return an error if the parsing of the cmd line fails
68 return ${EXIT_ERROR}
69 fi
70
71 zone_config_settings_write "${zone}" "${HOOK}" "${id}"
72
73 exit ${EXIT_OK}
74 }
75
76 hook_up() {
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
100 hook_down() {
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
116 hook_status() {
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 }