]> git.ipfire.org Git - people/stevee/network.git/blob - src/hooks/configs/ipv6-static
Replace routing_db_* by db_*
[people/stevee/network.git] / src / hooks / 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 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 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 zone_config_settings_write "${zone}" "${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX}" ${HOOK_SETTINGS}
63
64 exit ${EXIT_OK}
65 }
66
67 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 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
78
79 ip_address_add ${zone} ${ADDRESS}/${PREFIX}
80
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
85 routing_default_update
86
87 exit ${EXIT_OK}
88 }
89
90 hook_down() {
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
99
100 # Remove routing information from database.
101 db_delete "${zone}/ipv6"
102
103 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
104
105 ip_address_del ${zone} ${ADDRESS}/${PREFIX}
106
107 # Update routing tables.
108 routing_default_update
109
110 exit ${EXIT_OK}
111 }
112
113 hook_status() {
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
123 zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
124
125 # Make sure ADDRESS is as short as possible.
126 ADDRESS=$(ipv6_implode ${ADDRESS})
127
128 local status
129 if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then
130 status=${MSG_HOOK_UP}
131 else
132 status=${MSG_HOOK_DOWN}
133 fi
134 cli_statusline 3 "${HOOK}" "${status}"
135
136 cli_print_fmt1 3 "IPv6 address" "${ADDRESS}/${PREFIX}"
137 if [ -n "${GATEWAY}" ]; then
138 cli_print_fmt1 3 "Gateway" "${GATEWAY}"
139 fi
140 cli_space
141
142 exit ${EXIT_OK}
143 }