]> git.ipfire.org Git - people/stevee/network.git/blob - src/hooks/zones/bridge.configs/ipv6-static
hostapd: Enable WMM by default.
[people/stevee/network.git] / src / hooks / zones / bridge.configs / ipv6-static
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-port
23
24 HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
25
26 function hook_check() {
27 assert isset ADDRESS
28 assert isinteger PREFIX
29
30 if [ ${PREFIX} -gt 64 ]; then
31 error "PREFIX is greater than 64."
32 exit ${EXIT_ERROR}
33 fi
34 }
35
36 function hook_create() {
37 local zone=${1}
38 shift
39
40 while [ $# -gt 0 ]; do
41 case "${1}" in
42 --address=*)
43 ADDRESS=${1#--address=}
44 ;;
45 --prefix=*)
46 PREFIX=${1#--prefix=}
47 ;;
48 --gateway=*)
49 GATEWAY=${1#--gateway=}
50 ;;
51 esac
52 shift
53 done
54
55 # Store IPv6 address in small format.
56 ADDRESS=$(ipv6_implode ${ADDRESS})
57
58 if [ -n "${GATEWAY}" ]; then
59 GATEWAY=$(ipv6_implode ${GATEWAY})
60 fi
61
62 config_write $(zone_dir ${zone})/configs/${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX} ${HOOK_SETTINGS}
63
64 exit ${EXIT_OK}
65 }
66
67 function hook_up() {
68 local zone=${1}
69 local config=${2}
70 shift 2
71
72 if ! device_exists ${zone}; then
73 error "Zone '${zone}' doesn't exist."
74 exit ${EXIT_ERROR}
75 fi
76
77 config_read $(zone_dir ${zone})/configs/${config}
78
79 ip_address_add ${zone} ${ADDRESS}/${PREFIX}
80
81 routing_db_set ${zone} ipv6 local-ip-address ${ADDRESS}/${PREFIX}
82 routing_db_set ${zone} ipv6 remote-ip-address ${GATEWAY}
83 routing_db_set ${zone} ipv6 active 1
84 routing_default_update
85
86 exit ${EXIT_OK}
87 }
88
89 function hook_down() {
90 local zone=${1}
91 local config=${2}
92 shift 2
93
94 if ! device_exists ${zone}; then
95 error "Zone '${zone}' doesn't exist."
96 exit ${EXIT_ERROR}
97 fi
98
99 # Remove routing information from database.
100 routing_db_remove ${zone} ipv6
101
102 config_read $(zone_dir ${zone})/configs/${config}
103
104 ip_address_del ${zone} ${ADDRESS}/${PREFIX}
105
106 # Update routing tables.
107 routing_default_update
108
109 exit ${EXIT_OK}
110 }
111
112 function hook_status() {
113 local zone=${1}
114 local config=${2}
115 shift 2
116
117 if ! device_exists ${zone}; then
118 error "Zone '${zone}' doesn't exist."
119 exit ${EXIT_ERROR}
120 fi
121
122 config_read $(zone_dir ${zone})/configs/${config}
123
124 # Make sure ADDRESS is as short as possible.
125 ADDRESS=$(ipv6_implode ${ADDRESS})
126
127 local status
128 if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
129 status=${MSG_HOOK_UP}
130 else
131 status=${MSG_HOOK_DOWN}
132 fi
133 cli_statusline 3 "${HOOK}" "${status}"
134
135 cli_print_fmt1 3 "IPv6 address" "${ADDRESS}/${PREFIX}"
136 if [ -n "${GATEWAY}" ]; then
137 cli_print_fmt1 3 "Gateway" "${GATEWAY}"
138 fi
139 cli_space
140
141 exit ${EXIT_OK}
142 }