]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/configs/ipv6-static
Replace ipcalc by inetcalc
[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
b6d9bf2b 22. /usr/lib/network/header-config
4231f419 23
b6d9bf2b 24HOOK_CONFIG_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
4231f419 25
b6d9bf2b 26hook_check_config_settings() {
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
b6d9bf2b 36hook_new() {
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 55 # Store IPv6 address in small format.
13a6e69f 56 ADDRESS=$(ipv6_format "${ADDRESS}")
4231f419
MT
57
58 if [ -n "${GATEWAY}" ]; then
13a6e69f 59 GATEWAY=$(ipv6_format "${GATEWAY}")
4231f419
MT
60 fi
61
b6d9bf2b 62 zone_config_settings_write "${zone}" "${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX}"
4231f419
MT
63
64 exit ${EXIT_OK}
65}
66
1c6a4e30 67hook_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
b6d9bf2b 77 zone_config_settings_read "${zone}" "${config}"
4231f419 78
38f61548 79 ip_address_add ${zone} ${ADDRESS}/${PREFIX}
4231f419 80
c041b631
MT
81 db_set "${zone}/ipv6/local-ip-address" "${ADDRESS}/${PREFIX}"
82 db_set "${zone}/ipv6/remote-ip-address" "${GATEWAY}"
83 db_set "${zone}/ipv6/active" 1
84
b368da2f 85 routing_default_update
4231f419
MT
86
87 exit ${EXIT_OK}
88}
89
1c6a4e30 90hook_down() {
4231f419
MT
91 local zone=${1}
92 local config=${2}
93 shift 2
94
95 if ! device_exists ${zone}; then
96 error "Zone '${zone}' doesn't exist."
97 exit ${EXIT_ERROR}
98 fi
b0c273ad
MT
99
100 # Remove routing information from database.
c041b631 101 db_delete "${zone}/ipv6"
4231f419 102
b6d9bf2b 103 zone_config_settings_read "${zone}" "${config}"
4231f419 104
38f61548 105 ip_address_del ${zone} ${ADDRESS}/${PREFIX}
4231f419 106
b0c273ad
MT
107 # Update routing tables.
108 routing_default_update
109
4231f419
MT
110 exit ${EXIT_OK}
111}
112
1c6a4e30 113hook_status() {
4231f419
MT
114 local zone=${1}
115 local config=${2}
116 shift 2
117
118 if ! device_exists ${zone}; then
119 error "Zone '${zone}' doesn't exist."
120 exit ${EXIT_ERROR}
121 fi
122
b6d9bf2b 123 zone_config_settings_read "${zone}" "${config}"
4231f419 124
c447aaa8 125 # Make sure ADDRESS is as short as possible.
13a6e69f 126 ADDRESS=$(ipv6_format "${ADDRESS}")
c447aaa8
MT
127
128 local status
38f61548 129 if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
c447aaa8 130 status=${MSG_HOOK_UP}
4231f419 131 else
c447aaa8 132 status=${MSG_HOOK_DOWN}
4231f419 133 fi
c447aaa8 134 cli_statusline 3 "${HOOK}" "${status}"
4231f419 135
c447aaa8 136 cli_print_fmt1 3 "IPv6 address" "${ADDRESS}/${PREFIX}"
4231f419 137 if [ -n "${GATEWAY}" ]; then
c447aaa8 138 cli_print_fmt1 3 "Gateway" "${GATEWAY}"
4231f419 139 fi
50250b79 140 cli_space
4231f419
MT
141
142 exit ${EXIT_OK}
143}