]> git.ipfire.org Git - people/stevee/network.git/blame - hooks/zones/bridge.configs/ipv6-static
Fix two missing CONFIG_DIR substitutions.
[people/stevee/network.git] / hooks / zones / bridge.configs / ipv6-static
CommitLineData
4231f419
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. /lib/network/header-port
23
24HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
25
26function _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
36function _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 full format
56 ADDRESS=$(ipv6_explode ${ADDRESS})
57
58 if [ -n "${GATEWAY}" ]; then
59 GATEWAY=$(ipv6_explode ${GATEWAY})
60 fi
61
38f61548 62 config_write $(zone_dir ${zone})/configs/${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX} ${HOOK_SETTINGS}
4231f419
MT
63
64 exit ${EXIT_OK}
65}
66
67function _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
38f61548 77 config_read $(zone_dir ${zone})/configs/${config}
4231f419 78
38f61548 79 ip_address_add ${zone} ${ADDRESS}/${PREFIX}
4231f419 80
b368da2f
MT
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
4231f419
MT
85
86 exit ${EXIT_OK}
87}
88
89function _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
b0c273ad
MT
98
99 # Remove routing information from database.
100 routing_db_remove ${zone} ipv6
4231f419 101
38f61548 102 config_read $(zone_dir ${zone})/configs/${config}
4231f419 103
38f61548 104 ip_address_del ${zone} ${ADDRESS}/${PREFIX}
4231f419 105
b0c273ad
MT
106 # Update routing tables.
107 routing_default_update
108
4231f419
MT
109 exit ${EXIT_OK}
110}
111
112function _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
38f61548 122 config_read $(zone_dir ${zone})/configs/${config}
4231f419
MT
123
124 printf " %10s - " "${HOOK}"
38f61548
MT
125 if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
126 echo -ne "${COLOUR_UP} UP ${COLOUR_NORMAL}"
4231f419 127 else
38f61548 128 echo -ne "${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
4231f419
MT
129 fi
130 echo " - $(ipv6_implode ${ADDRESS})/${PREFIX}"
131
132 if [ -n "${GATEWAY}" ]; then
133 echo " Gateway: ${GATEWAY}"
134 fi
135
136 exit ${EXIT_OK}
137}
138
139run $@