]>
Commit | Line | Data |
---|---|---|
711ffac1 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 | ||
987dfeb4 | 22 | . /usr/lib/network/header-port |
711ffac1 | 23 | |
d1e71061 | 24 | HOOK_SETTINGS="HOOK ADDRESS MIIMON MODE SLAVES" |
711ffac1 | 25 | |
d1e71061 MT |
26 | ADDRESS=$(mac_generate) |
27 | SLAVES="" | |
711ffac1 | 28 | MIIMON=100 |
4c4dd614 | 29 | MODE="balance-rr" |
711ffac1 | 30 | |
1e6f187e | 31 | function hook_check_settings() { |
d1e71061 MT |
32 | assert isset ADDRESS |
33 | assert ismac ADDRESS | |
711ffac1 MT |
34 | |
35 | #assert isset SLAVES | |
36 | assert isinteger MIIMON | |
37 | } | |
38 | ||
1ba6a2bb | 39 | function hook_new() { |
4c4dd614 | 40 | hook_edit $@ |
711ffac1 MT |
41 | } |
42 | ||
2181765d | 43 | function hook_edit() { |
711ffac1 | 44 | local port=${1} |
d1e71061 | 45 | assert isset port |
711ffac1 MT |
46 | shift |
47 | ||
48 | while [ $# -gt 0 ]; do | |
49 | case "${1}" in | |
d1e71061 MT |
50 | --address=*) |
51 | ADDRESS=$(cli_get_val ${1}) | |
711ffac1 MT |
52 | ;; |
53 | --miimon=*) | |
d1e71061 | 54 | MIIMON=$(cli_get_val ${1}) |
711ffac1 MT |
55 | ;; |
56 | --mode=*) | |
d1e71061 | 57 | MODE=$(cli_get_val ${1}) |
711ffac1 MT |
58 | ;; |
59 | --slave=*) | |
d1e71061 MT |
60 | slave=$(cli_get_val ${1}) |
61 | SLAVES="${SLAVES} ${slave}" | |
711ffac1 MT |
62 | ;; |
63 | *) | |
64 | warning "Unknown argument '${1}'" | |
65 | ;; | |
66 | esac | |
67 | shift | |
68 | done | |
69 | ||
70 | DEVICE=${port} | |
71 | ||
72 | # XXX think this must move to _check() | |
73 | if ! isset DEVICE; then | |
74 | error "You must set a device name." | |
75 | exit ${EXIT_ERROR} | |
76 | fi | |
77 | ||
78 | if ! isset SLAVES; then | |
79 | error "You need to specify at least one slave port (e.g. --slave=port0)." | |
80 | exit ${EXIT_ERROR} | |
81 | fi | |
82 | ||
83 | local slave | |
d1e71061 | 84 | for slave in $(unquote ${SLAVES}); do |
57c577a4 MT |
85 | if ! device_is_ethernet_compatible ${slave}; then |
86 | error "The slave device '${slave}' is not able to transport ethernet frames" | |
711ffac1 MT |
87 | exit ${EXIT_ERROR} |
88 | fi | |
89 | done | |
90 | ||
91 | # Remove any whitespace | |
92 | SLAVES=$(echo ${SLAVES}) | |
93 | ||
e9df08ad | 94 | port_settings_write "${port}" ${HOOK_SETTINGS} |
711ffac1 MT |
95 | |
96 | exit ${EXIT_OK} | |
97 | } | |
98 | ||
1ba6a2bb MT |
99 | function hook_create() { |
100 | local port="${1}" | |
101 | assert isset port | |
711ffac1 | 102 | |
1ba6a2bb MT |
103 | # Exit silently if the device already exists |
104 | device_exists "${port}" && exit ${EXIT_OK} | |
711ffac1 | 105 | |
1ba6a2bb MT |
106 | port_settings_read "${port}" ${HOOK_SETTINGS} |
107 | ||
108 | # Create the bonding devices | |
109 | bonding_create "${port}" \ | |
110 | --address="${ADDRESS}" \ | |
111 | --mode="${MODE}" || exit ${EXIT_ERROR} | |
112 | ||
113 | bonding_set_miimon "${port}" "${MIIMON}" | |
114 | ||
115 | exit ${EXIT_OK} | |
116 | } | |
117 | ||
118 | function hook_remove() { | |
119 | local port="${1}" | |
120 | assert isset port | |
121 | ||
122 | port_settings_read "${port}" ${HOOK_SETTINGS} | |
123 | ||
124 | # Remove the bonding device | |
125 | if device_exists "${port}"; then | |
126 | bonding_remove "${port}" | |
711ffac1 | 127 | fi |
1ba6a2bb MT |
128 | } |
129 | ||
130 | function hook_up() { | |
131 | local port="${1}" | |
132 | assert isset port | |
711ffac1 | 133 | |
1ba6a2bb | 134 | port_settings_read "${port}" ${HOOK_SETTINGS} |
711ffac1 | 135 | |
1ba6a2bb MT |
136 | # Execute the default action |
137 | hook_default_up "${port}" | |
138 | ||
139 | # Bring up all slaves | |
711ffac1 | 140 | local slave |
d1e71061 | 141 | for slave in $(unquote ${SLAVES}); do |
1ba6a2bb | 142 | port_up "${slave}" |
711ffac1 | 143 | done |
711ffac1 MT |
144 | } |
145 | ||
2181765d | 146 | function hook_down() { |
1ba6a2bb MT |
147 | local port="${1}" |
148 | assert isset port | |
711ffac1 | 149 | |
1ba6a2bb | 150 | port_settings_read "${port}" ${HOOK_SETTINGS} |
711ffac1 | 151 | |
1ba6a2bb | 152 | # Bring down all slaves |
711ffac1 | 153 | local slave |
1ba6a2bb MT |
154 | for slave in $(unquote ${SLAVES}); do |
155 | port_down "${slave}" | |
711ffac1 MT |
156 | done |
157 | ||
1ba6a2bb MT |
158 | # Execute the default action |
159 | hook_default_down "${port}" | |
160 | } | |
161 | ||
162 | function hook_hotplug() { | |
163 | local port="${1}" | |
164 | assert isset port | |
165 | ||
166 | case "$(hotplug_action)" in | |
167 | add) | |
168 | # Handle events of the same interface | |
169 | if hotplug_event_port_is_interface "${port}"; then | |
170 | # Read configuration | |
171 | port_settings_read "${port}" ${HOOK_SETTINGS} | |
172 | ||
173 | # Bring up all slaves | |
174 | # Attach those which already exist and try to create | |
175 | # those which don't exist yet. They will be attached | |
176 | # in their own hotplug event. | |
177 | local slave | |
178 | for slave in $(unquote ${SLAVES}); do | |
179 | if device_exists "${slave}"; then | |
180 | bonding_enslave_device "${port}" "${slave}" | |
181 | else | |
182 | port_create "${slave}" | |
183 | fi | |
184 | done | |
185 | ||
186 | exit ${EXIT_OK} | |
187 | ||
188 | # Handle slave devices that have just been created and | |
189 | # attach them. | |
190 | elif hotplug_event_interface_is_slave_of_port "${port}"; then | |
191 | bonding_enslave_device "${port}" "${INTERFACE}" | |
192 | ||
193 | # If the parent device has been set up, we will | |
194 | # bring up the slave device as well. | |
195 | if device_is_up "${port}"; then | |
196 | port_up "${INTERFACE}" | |
197 | fi | |
198 | fi | |
199 | ||
200 | exit ${EXIT_OK} | |
201 | ;; | |
202 | ||
203 | remove) | |
204 | if hotplug_event_port_is_interface "${port}"; then | |
205 | # Bring down all slaves after the parent device went away | |
206 | local slave | |
207 | for slave in $(port_get_slaves "${port}"); do | |
208 | port_remove "${slave}" | |
209 | done | |
210 | ||
211 | exit ${EXIT_OK} | |
212 | fi | |
213 | ;; | |
214 | esac | |
215 | ||
216 | exit ${EXIT_NOT_HANDLED} | |
711ffac1 | 217 | } |