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