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