]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
38f61548 | 62 | config_write $(zone_dir ${zone})/configs/${HOOK}.$(ipv6_hash ${ADDRESS}).${PREFIX} ${HOOK_SETTINGS} |
4231f419 MT |
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 | ||
38f61548 | 77 | config_read $(zone_dir ${zone})/configs/${config} |
4231f419 | 78 | |
38f61548 | 79 | ip_address_add ${zone} ${ADDRESS}/${PREFIX} |
4231f419 MT |
80 | |
81 | if zone_is_nonlocal ${zone} && [ -n "${GATEWAY}" ]; then | |
82 | : # XXX to be done | |
83 | fi | |
84 | ||
85 | exit ${EXIT_OK} | |
86 | } | |
87 | ||
88 | function _down() { | |
89 | local zone=${1} | |
90 | local config=${2} | |
91 | shift 2 | |
92 | ||
93 | if ! device_exists ${zone}; then | |
94 | error "Zone '${zone}' doesn't exist." | |
95 | exit ${EXIT_ERROR} | |
96 | fi | |
97 | ||
38f61548 | 98 | config_read $(zone_dir ${zone})/configs/${config} |
4231f419 | 99 | |
38f61548 | 100 | ip_address_del ${zone} ${ADDRESS}/${PREFIX} |
4231f419 MT |
101 | |
102 | exit ${EXIT_OK} | |
103 | } | |
104 | ||
105 | function _status() { | |
106 | local zone=${1} | |
107 | local config=${2} | |
108 | shift 2 | |
109 | ||
110 | if ! device_exists ${zone}; then | |
111 | error "Zone '${zone}' doesn't exist." | |
112 | exit ${EXIT_ERROR} | |
113 | fi | |
114 | ||
38f61548 | 115 | config_read $(zone_dir ${zone})/configs/${config} |
4231f419 MT |
116 | |
117 | printf " %10s - " "${HOOK}" | |
38f61548 MT |
118 | if zone_has_ip ${zone} ${ADDRESS}/${PREFIX}; then |
119 | echo -ne "${COLOUR_UP} UP ${COLOUR_NORMAL}" | |
4231f419 | 120 | else |
38f61548 | 121 | echo -ne "${COLOUR_DOWN}DOWN${COLOUR_NORMAL}" |
4231f419 MT |
122 | fi |
123 | echo " - $(ipv6_implode ${ADDRESS})/${PREFIX}" | |
124 | ||
125 | if [ -n "${GATEWAY}" ]; then | |
126 | echo " Gateway: ${GATEWAY}" | |
127 | fi | |
128 | ||
129 | exit ${EXIT_OK} | |
130 | } | |
131 | ||
132 | run $@ |