]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/configs/ipv6-static
Rename all "config" to "settings"
[people/stevee/network.git] / src / hooks / 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
f41fa3d7 22. /usr/lib/network/header-port
4231f419
MT
23
24HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
25
2181765d 26function hook_check() {
4231f419
MT
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
2181765d 36function hook_create() {
4231f419
MT
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
b61ca684
MT
55 # Store IPv6 address in small format.
56 ADDRESS=$(ipv6_implode ${ADDRESS})
4231f419
MT
57
58 if [ -n "${GATEWAY}" ]; then
b61ca684 59 GATEWAY=$(ipv6_implode ${GATEWAY})
4231f419
MT
60 fi
61
e9df08ad 62 zone_config_settings_write "${zone}" "${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX}" ${HOOK_SETTINGS}
4231f419
MT
63
64 exit ${EXIT_OK}
65}
66
2181765d 67function hook_up() {
4231f419
MT
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
e9df08ad 77 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
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
2181765d 89function hook_down() {
4231f419
MT
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
e9df08ad 102 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
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
2181765d 112function hook_status() {
4231f419
MT
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
e9df08ad 122 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
4231f419 123
c447aaa8
MT
124 # Make sure ADDRESS is as short as possible.
125 ADDRESS=$(ipv6_implode ${ADDRESS})
126
127 local status
38f61548 128 if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
c447aaa8 129 status=${MSG_HOOK_UP}
4231f419 130 else
c447aaa8 131 status=${MSG_HOOK_DOWN}
4231f419 132 fi
c447aaa8 133 cli_statusline 3 "${HOOK}" "${status}"
4231f419 134
c447aaa8 135 cli_print_fmt1 3 "IPv6 address" "${ADDRESS}/${PREFIX}"
4231f419 136 if [ -n "${GATEWAY}" ]; then
c447aaa8 137 cli_print_fmt1 3 "Gateway" "${GATEWAY}"
4231f419 138 fi
50250b79 139 cli_space
4231f419
MT
140
141 exit ${EXIT_OK}
142}