]> git.ipfire.org Git - people/ms/network.git/blob - src/hooks/configs/ipv6-auto
ipv6-auto: prevent multiple configs for the same zone
[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_new() {
34 local zone="${1}"
35 shift
36
37 if zone_config_hook_is_configured ${zone} "ipv6-auto"; then
38 log ERROR "You can configure the ipv6-auto hook only once for a zone"
39 return ${EXIT_ERROR}
40 fi
41
42 while read arg; do
43 case "${arg}" in
44 --privacy-extensions=*)
45 local val="$(cli_get_val "${arg}")"
46
47 if enabled val; then
48 PRIVACY_EXTENSIONS="on"
49 else
50 PRIVACY_EXTENSIONS="off"
51 fi
52 ;;
53 esac
54 done <<< "$(args $@)"
55
56 zone_config_settings_write "${zone}" "${HOOK}"
57
58 exit ${EXIT_OK}
59 }
60
61 hook_up() {
62 local zone=${1}
63 shift
64
65 if ! device_exists ${zone}; then
66 error "Zone '${zone}' doesn't exist."
67 exit ${EXIT_ERROR}
68 fi
69
70 zone_config_settings_read "${zone}" "${HOOK}"
71
72 # Enable IPv6 auto-configuration
73 ipv6_device_autoconf_enable "${zone}"
74
75 # Set up privacy extensions (RFC3041)
76 if enabled PRIVACY_EXTENSIONS; then
77 ipv6_device_privacy_extensions_enable "${zone}"
78 else
79 ipv6_device_privacy_extensions_disable "${zone}"
80 fi
81
82 exit ${EXIT_OK}
83 }
84
85 hook_down() {
86 local zone=${1}
87 local config=${2}
88 shift 2
89
90 if ! device_exists ${zone}; then
91 error "Zone '${zone}' doesn't exist."
92 exit ${EXIT_ERROR}
93 fi
94
95 # Disable IPv6 auto-configuration
96 ipv6_device_autoconf_disable "${zone}"
97
98 exit ${EXIT_OK}
99 }
100
101 hook_status() {
102 local zone=${1}
103 local config=${2}
104 shift 2
105
106 if ! device_exists ${zone}; then
107 error "Zone '${zone}' doesn't exist."
108 exit ${EXIT_ERROR}
109 fi
110
111 zone_config_settings_read "${zone}" "${config}"
112
113 local addresses=$(ipv6_device_get_addresses "${zone}" --scope="global")
114 local status
115 if isset addresses; then
116 status="${MSG_HOOK_UP}"
117 else
118 status="${MSG_HOOK_DOWN}"
119 fi
120 cli_statusline 3 "${HOOK}" "${status}"
121
122 if enabled PRIVACY_EXTENSIONS; then
123 cli_print_fmt1 3 "Privacy Extensions enabled"
124 cli_space
125 fi
126
127 local addr
128 for addr in ${addresses}; do
129 cli_print_fmt1 3 "IPv6 address" "${addr}"
130 done
131 cli_space
132
133 exit ${EXIT_OK}
134 }