]> git.ipfire.org Git - people/arne_f/network.git/blob - hooks/bridge.configs/ipv6-static
network: New hook ipv6-static.
[people/arne_f/network.git] / hooks / 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 . /lib/network/header-port
23
24 HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
25
26 function _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 _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
62 config_write $(zone_dir ${zone})/config.${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX} ${HOOK_SETTINGS}
63
64 exit ${EXIT_OK}
65 }
66
67 function _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})/${config}
78
79 if ! zone_has_ipv6 ${zone} ${ADDRESS}/${PREFIX}; then
80 ip addr add ${ADDRESS}/${PREFIX} dev ${zone}
81 else
82 warning "Do not set IPv6 address '${ADDRESS}/${PREFIX}' because it was already configured on zone '${zone}'."
83 fi
84
85 if zone_is_nonlocal ${zone} && [ -n "${GATEWAY}" ]; then
86 : # XXX to be done
87 fi
88
89 exit ${EXIT_OK}
90 }
91
92 function _down() {
93 local zone=${1}
94 local config=${2}
95 shift 2
96
97 if ! device_exists ${zone}; then
98 error "Zone '${zone}' doesn't exist."
99 exit ${EXIT_ERROR}
100 fi
101
102 config_read $(zone_dir ${zone})/${config}
103
104 if zone_has_ipv6 ${zone} ${ADDRESS}/${PREFIX}; then
105 ip addr del ${ADDRESS}/${PREFIX} dev ${zone}
106 fi
107
108 exit ${EXIT_OK}
109 }
110
111 function _status() {
112 local zone=${1}
113 local config=${2}
114 shift 2
115
116 if ! device_exists ${zone}; then
117 error "Zone '${zone}' doesn't exist."
118 exit ${EXIT_ERROR}
119 fi
120
121 config_read $(zone_dir ${zone})/${config}
122
123 printf " %10s - " "${HOOK}"
124 if zone_has_ipv6 ${zone} ${ADDRESS}/${PREFIX}; then
125 echo -ne "${COLOUR_OK} OK ${COLOUR_NORMAL}"
126 else
127 echo -ne "${COLOUR_ERROR}ERROR${COLOUR_NORMAL}"
128 fi
129 echo " - $(ipv6_implode ${ADDRESS})/${PREFIX}"
130
131 if [ -n "${GATEWAY}" ]; then
132 echo " Gateway: ${GATEWAY}"
133 fi
134
135 exit ${EXIT_OK}
136 }
137
138 run $@