Debian Codegraph @

heartbeat/iface-bridge

raw
1 #!/bin/sh
2 #
3 # OCF Resource Agent compliant iface-bridge script.
4 #
5 # Implements network Bridge interface management
6 #
7 # Copyright (C) 2013 Red Hat, Inc. All rights reserved.
8 # Author: Fabio M. Di Nitto <[email protected]>
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of version 2 of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 #
18 # Further, this software is distributed without any warranty that it is
19 # free of the rightful claim of any third person regarding infringement
20 # or the like. Any license provided herein, whether implied or
21 # otherwise, applies only to this software file. Patent licenses, if
22 # any, provided herein do not apply to combinations of this program with
23 # other software, or any other product whatsoever.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
28 #
29 #
30
31 # TODO:
32 # * Eventually improve bridge_check to verify all runtime
33 # parameters. Is it really necessary?
34 # * consider add support for advanced multicast timers tuning
35 # sethashel <bridge> <int> set hash elasticity default 4
36 # sethashmax <bridge> <int> set hash max default 512
37 # setmclmc <bridge> <int> set multicast last member count default 2, ?
38 # setmcsqc <bridge> <int> set multicast startup query count default 2, ?
39 # setmclmi <bridge> <time> set multicast last member interval default HZ
40 # setmcmi <bridge> <time> set multicast membership interval default 260 * HZ
41 # setmcqpi <bridge> <time> set multicast querier interval default 255 * HZ
42 # setmcqi <bridge> <time> set multicast query interval detault 125 * HZ
43 # setmcqri <bridge> <time> set multicast query response interval default 10 * HZ
44 # setmcqri <bridge> <time> set multicast startup query interval default 125 * hZ / 4
45 #
46 #
47 # OCF parameters are as below
48 # OCF_RESKEY_bridge_name
49 # OCF_RESKEY_bridge_slaves
50 # OCF_RESKEY_bridge_ageing
51 # OCF_RESKEY_port_hairpin
52 # OCF_RESKEY_stp
53 # OCF_RESKEY_stp_bridgeprio
54 # OCF_RESKEY_stp_fd
55 # OCF_RESKEY_stp_maxage
56 # OCF_RESKEY_stp_hello
57 # OCF_RESKEY_stp_pathcost
58 # OCF_RESKEY_stp_portprio
59 # OCF_RESKEY_multicast_router
60 # OCF_RESKEY_multicast_snooping
61 # OCF_RESKEY_multicast_querier
62 # OCF_RESKEY_multicast_port_router
63 #
64
65 #######################################################################
66 # Initialization:
67
68 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
69 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
70
71 # Defaults
72 OCF_RESKEY_stp_default=false
73 OCF_RESKEY_stp_fd_default=0
74 OCF_RESKEY_multicast_router_default=1
75 OCF_RESKEY_multicast_snooping_default=1
76 OCF_RESKEY_multicast_querier_default=0
77
78 : ${OCF_RESKEY_stp=${OCF_RESKEY_stp_default}}
79 : ${OCF_RESKEY_stp_fd=${OCF_RESKEY_stp_fd_default}}
80 : ${OCF_RESKEY_multicast_router=${OCF_RESKEY_multicast_router_default}}
81 : ${OCF_RESKEY_multicast_snooping=${OCF_RESKEY_multicast_snooping_default}}
82 : ${OCF_RESKEY_multicast_querier=${OCF_RESKEY_multicast_querier_default}}
83
84 # binaries
85 : ${BRCTL:=brctl}
86
87 #######################################################################
88
89 bridge_usage() {
90 cat <<END
91 usage: $0 {start|stop|status|monitor|validate-all|meta-data}
92
93 Expects to have a fully populated OCF RA-compliant environment set.
94 END
95 }
96
97 bridge_meta_data() {
98 cat <<END
99 <?xml version="1.0"?>
100 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
101 <resource-agent name="iface-bridge" version="1.0">
102 <version>1.0</version>
103
104 <longdesc lang="en">
105 This resource manages Bridge network interfaces.
106 It can add, remove, configure bridges and spanning-tree.
107 </longdesc>
108
109 <shortdesc lang="en">
110 Manages Bridge network interfaces.
111 </shortdesc>
112
113 <parameters>
114 <parameter name="bridge_name" unique="1" required="1">
115 <longdesc lang="en">
116 Define the name of the bridge (max 15 charaters).
117 </longdesc>
118 <shortdesc lang="en">
119 Name of the bridge
120 </shortdesc>
121 <content type="string"/>
122 </parameter>
123
124 <parameter name="bridge_slaves" unique="1">
125 <longdesc lang="en">
126 Define the list of interfaces, space separated, to add to the bridge.
127 The list can be empty.
128 </longdesc>
129 <shortdesc lang="en">
130 Network interface
131 </shortdesc>
132 <content type="string"/>
133 </parameter>
134
135 <parameter name="bridge_ageing" unique="0">
136 <longdesc lang="en">
137 Set the ethernet (MAC) address ageing time in seconds.
138 </longdesc>
139 <shortdesc lang="en">
140 MAC ageing in seconds.
141 </shortdesc>
142 <content type="integer"/>
143 </parameter>
144
145 <parameter name="port_hairpin" unique="0">
146 <longdesc lang="en">
147 Set hairpin forwarding mode.
148 A list of ports that should have hairpin enabled
149 can be specified using the following
150 Example: eth0 eth1
151 </longdesc>
152 <shortdesc lang="en">
153 Set hairpin forwarding mode.
154 </shortdesc>
155 <content type="string"/>
156 </parameter>
157
158 <parameter name="stp" unique="0">
159 <longdesc lang="en">
160 Enable or disable Spanning Tree Protocol on the bridge.
161 </longdesc>
162 <shortdesc lang="en">
163 Spanning Tree Protocol
164 </shortdesc>
165 <content type="boolean" default="${OCF_RESKEY_stp_default}"/>
166 </parameter>
167
168 <parameter name="stp_bridgeprio" unique="0">
169 <longdesc lang="en">
170 Set the bridge's priority to defined value. The priority value is a
171 number between 0 and 65535), and has no dimension. Lower priority values are
172 preferred. The bridge with the lowest priority will be elected as root bridge.
173 </longdesc>
174 <shortdesc lang="en">
175 Set the bridge's priority.
176 </shortdesc>
177 <content type="integer"/>
178 </parameter>
179
180 <parameter name="stp_fd" unique="0">
181 <longdesc lang="en">
182 Set the bridge forward delay (in seconds).
183 </longdesc>
184 <shortdesc lang="en">
185 Set the bridge forward delay.
186 </shortdesc>
187 <content type="integer" default="${OCF_RESKEY_stp_fd_default}"/>
188 </parameter>
189
190 <parameter name="stp_maxage" unique="0">
191 <longdesc lang="en">
192 Set the bridge maximum message age (in seconds).
193 </longdesc>
194 <shortdesc lang="en">
195 Set the bridge maximum message age.
196 </shortdesc>
197 <content type="integer"/>
198 </parameter>
199
200 <parameter name="stp_hello" unique="0">
201 <longdesc lang="en">
202 Set the bridge hello time (in seconds).
203 </longdesc>
204 <shortdesc lang="en">
205 Set the bridge hello time.
206 </shortdesc>
207 <content type="integer"/>
208 </parameter>
209
210 <parameter name="stp_pathcost" unique="0">
211 <longdesc lang="en">
212 Set the port cost. This is a dimensionless metric.
213 A list of port/cost can be specified using the following
214 format: unpromoted cost unpromoted cost.
215 Example: eth0 100 eth1 1000
216 </longdesc>
217 <shortdesc lang="en">
218 Set the port cost.
219 </shortdesc>
220 <content type="string"/>
221 </parameter>
222
223 <parameter name="stp_portprio" unique="0">
224 <longdesc lang="en">
225 Set the port priority. This is a number between 0 and 63.
226 $BRCTL man page reports a value between 0 and 255, but
227 tests show a limit of 63 on a live system.
228 This metric is used in the designated port and root port
229 selection algorithms.
230 A list of port/priority can be specified using the following
231 format: unpromoted cost unpromoted cost.
232 Example: eth0 10 eth1 60
233 </longdesc>
234 <shortdesc lang="en">
235 Set the port priority.
236 </shortdesc>
237 <content type="string"/>
238 </parameter>
239
240 <parameter name="multicast_router" unique="0">
241 <longdesc lang="en">
242 Enable or disable multicast routing on the bridge.
243 </longdesc>
244 <shortdesc lang="en">
245 Enable or disable multicast routing.
246 </shortdesc>
247 <content type="boolean" default="${OCF_RESKEY_multicast_router_default}"/>
248 </parameter>
249
250 <parameter name="multicast_snooping" unique="0">
251 <longdesc lang="en">
252 Enable or disable multicast snooping on the bridge.
253 </longdesc>
254 <shortdesc lang="en">
255 Enable or disable multicast snooping.
256 </shortdesc>
257 <content type="boolean" default="${OCF_RESKEY_multicast_snooping_default}"/>
258 </parameter>
259
260 <parameter name="multicast_port_router" unique="0">
261 <longdesc lang="en">
262 Enable or disable a port from the multicast router.
263 Kernel enables all port by default.
264 A list of port can be specified using the following
265 format: unpromoted 0|1 unpromoted 0|1.
266 Example: eth0 1 eth1 0
267 </longdesc>
268 <shortdesc lang="en">
269 Enable or disable a port from the multicast router.
270 </shortdesc>
271 <content type="string"/>
272 </parameter>
273 </parameters>
274
275 <actions>
276 <action name="start" timeout="30s" />
277 <action name="stop" timeout="20s" />
278 <action name="status" timeout="20s" depth="0" interval="10s" />
279 <action name="monitor" timeout="20s" depth="0" interval="10s" />
280 <action name="meta-data" timeout="5s" />
281 <action name="validate-all" timeout="20s" />
282 </actions>
283 </resource-agent>
284 END
285 }
286
287 # commodity function
288 # split_string eth0 100 eth1 1000 eth2 100
289 # eth0 100
290 # eth1 1000
291 # eth2 100
292
293 split_string() {
294 while [ -n "$1" ]; do
295 echo $1 $2
296 shift && shift
297 done
298 }
299
300 # check if the interface is admin up/down
301
302 iface_is_up() {
303 if ! $IP2UTIL -o link show $1 | \
304 sed -e 's#.*<##g' -e 's#>.*##' -e 's#LOWER_UP##g' | \
305 grep -q UP; then
306 return 1
307 fi
308 return 0
309 }
310
311 # check if the slaves have link layer up/down
312 # see kernel network documentation on meaning of LOWER_UP flag
313 # for more in depth explanation on how it works
314 # NOTE: this check is not reliable in virt environment
315 # since interfaces are always LOWER_UP. There is no way
316 # from the guest to know if the host has disconnected somehow
317
318 iface_lower_is_up() {
319 if ! $IP2UTIL -o link show $1 | \
320 grep -q LOWER_UP; then
321 return 1
322 fi
323 return 0
324 }
325
326 # wrapup function to check if any interface defined in
327 # option lists is a slave
328
329 iface_is_slave() {
330 for slave in $OCF_RESKEY_bridge_slaves; do
331 if [ "$1" = "$slave" ]; then
332 return 0
333 fi
334 done
335 return 1
336 }
337
338 bridge_validate() {
339 check_binary $BRCTL
340 check_binary $IP2UTIL
341
342 if [ -z "$OCF_RESKEY_bridge_name" ]; then
343 ocf_log err "Invalid OCF_RESKEY_bridge_name: value cannot be empty"
344 return 1
345 fi
346
347 # the echo .. is the equivalent of strlen in bash
348 #
349 # /usr/include/linux/if.h:#define IFNAMSIZ 16
350 # needs to include 0 byte end string
351
352 if [ "${#OCF_RESKEY_bridge_name}" -gt 15 ]; then
353 ocf_log err "Invalid OCF_RESKEY_bridge_name: name is too long"
354 return 1
355 fi
356
357 if [ ! -d "/sys/class/net" ]; then
358 ocf_log err "Unable to find sysfs network class in /sys"
359 return 1
360 fi
361
362 for slave in $OCF_RESKEY_bridge_slaves; do
363 if [ ! -e "/sys/class/net/$slave" ]; then
364 ocf_log err "Invalid OCF_RESKEY_bridge_slaves: $slave does not exists"
365 return 1
366 fi
367 done
368
369 # check if declared harpin ports are slaves
370 for hairpin in $OCF_RESKEY_port_hairpin; do
371 if ! iface_is_slave $hairpin; then
372 ocf_log err "Invalid OCF_RESKEY_port_hairpin: $hairpin is not listed in OCF_RESKEY_bridge_slaves"
373 return 1
374 fi
375 done
376
377 if [ -n "$OCF_RESKEY_bridge_ageing" ]; then
378 if ! ocf_is_decimal "$OCF_RESKEY_bridge_ageing"; then
379 ocf_log err "Invalid OCF_RESKEY_bridge_ageing: must be a decimal value (0 or greater)"
380 return 1
381 fi
382 fi
383
384 # OCF_RESKEY_stp_fd needs special handling as it can be 0 or greater
385 # but only when configured before OCF_RESKEY_stp.
386 # if enabled after OCF_RESKEY_stp with stp=true the value range is
387 # different. It is not clear from the man page or brctl documentation
388 # what the range is ahead of time.
389 if [ -n "$OCF_RESKEY_stp_fd" ]; then
390 if ! ocf_is_decimal "$OCF_RESKEY_stp_fd" || \
391 [ "$OCF_RESKEY_stp_fd" -lt 0 ]; then
392 ocf_log err "Invalid OCF_RESKEY_stp_fd: must be a decimal value (0 or greater)"
393 return 1
394 fi
395 fi
396
397 if ocf_is_true "$OCF_RESKEY_stp"; then
398
399 if [ -n "$OCF_RESKEY_stp_bridgeprio" ]; then
400 if ! ocf_is_decimal "$OCF_RESKEY_stp_bridgeprio" || \
401 [ "$OCF_RESKEY_stp_bridgeprio" -gt 65535 ]; then
402 ocf_log err "Invalid OCF_RESKEY_stp_bridgeprio: must be a decimal value between 0 and 65535 included"
403 return 1
404 fi
405 fi
406
407 if [ -n "$OCF_RESKEY_stp_hello" ]; then
408 if ! ocf_is_decimal "$OCF_RESKEY_stp_hello"; then
409 ocf_log err "Invalid OCF_RESKEY_stp_hello: must be a decimal value (0 or greater)"
410 return 1
411 fi
412 fi
413
414 if [ -n "$OCF_RESKEY_stp_maxage" ]; then
415 if ! ocf_is_decimal "$OCF_RESKEY_stp_maxage"; then
416 ocf_log err "Invalid OCF_RESKEY_stp_maxage: must be a decimal value (0 or greater)"
417 return 1
418 fi
419 fi
420
421 if [ -n "$OCF_RESKEY_stp_pathcost" ]; then
422 split_string $OCF_RESKEY_stp_pathcost | { while read iface cost; do
423 if ! iface_is_slave $iface; then
424 ocf_log err "Invalid OCF_RESKEY_stp_pathcost: $iface is not listed in OCF_RESKEY_bridge_slaves"
425 return 1
426 fi
427
428 if ! ocf_is_decimal $cost; then
429 ocf_log err "Invalid OCF_RESKEY_stp_pathcost: cost must be a decimal value (0 or great)"
430 return 1
431 fi
432 done
433 }
434 fi
435
436 if [ -n "$OCF_RESKEY_stp_portprio" ]; then
437 split_string $OCF_RESKEY_stp_portprio | { while read iface prio; do
438 if ! iface_is_slave $iface; then
439 ocf_log err "Invalid OCF_RESKEY_stp_portprio: $iface is not listed in OCF_RESKEY_bridge_slaves"
440 return 1
441 fi
442
443 if ! ocf_is_decimal $prio || \
444 [ "$prio" -gt "63" ]; then
445 ocf_log err "Invalid OCF_RESKEY_stp_portprio: priority must be a decimal value between 0 and 63 included"
446 return 1
447 fi
448 done
449 }
450 fi
451
452 fi
453
454 if [ -n "$OCF_RESKEY_multicast_port_router" ]; then
455 split_string $OCF_RESKEY_multicast_port_router | { while read iface mcport; do
456 if ! iface_is_slave $iface; then
457 ocf_log err "Invalid OCF_RESKEY_multicast_port_router: $iface is not listed in OCF_RESKEY_bridge_slaves"
458 return 1
459 fi
460
461 if ! ocf_is_decimal $mcport || \
462 [ "$mcport" -gt "1" ]; then
463 ocf_log err "Invalid OCF_RESKEY_multicast_port_router: valuer must be 0 (disabled) or 1 (enabled)"
464 return 1
465 fi
466 done
467 }
468 fi
469
470 return 0
471 }
472
473 bridge_check() {
474 if [ -e "/sys/class/net/$OCF_RESKEY_bridge_name" ]; then
475 if [ ! -e "$HA_RSCTMP/iface-bridge.$OCF_RESKEY_bridge_name" ]; then
476 return $OCF_ERR_GENERIC
477 fi
478 else
479 if [ -e "$HA_RSCTMP/iface-bridge.$OCF_RESKEY_bridge_name" ]; then
480 error="$(rm -f "$HA_RSCTMP/iface-bridge.$OCF_RESKEY_bridge_name" 2>&1)"
481 if [ "$?" != "0" ]; then
482 ocf_log err "Unable to remove stale lock file for bridge $OCF_RESKEY_bridge_name: $error"
483 return $OCF_ERR_GENERIC
484 fi
485 fi
486 return $OCF_NOT_RUNNING
487 fi
488
489 # we check if all slaves are still part of the bridge
490 for slave in $OCF_RESKEY_bridge_slaves; do
491 if [ ! -e "/sys/class/net/$OCF_RESKEY_bridge_name/brif/$slave" ]; then
492 ocf_log err "Interface $slave is not part of the bridge $OCF_RESKEY_bridge_name"
493 return $OCF_ERR_GENERIC
494 fi
495 if ! iface_is_up $slave; then
496 ocf_log err "Interface $slave of the bridge $OCF_RESKEY_bridge_name is administratively down"
497 return $OCF_ERR_GENERIC
498 fi
499 done
500
501 # check if bridge is still "UP"
502 # is there a cleaner way?
503
504 if ! iface_is_up $OCF_RESKEY_bridge_name; then
505 ocf_log err "Bridge $OCF_RESKEY_bridge_name is administratively down"
506 return $OCF_ERR_GENERIC
507 fi
508
509 if ! iface_lower_is_up $OCF_RESKEY_bridge_name; then
510 ocf_log err "Bridge $OCF_RESKEY_bridge_name has no active link-layer slaves"
511 return $OCF_ERR_GENERIC
512 fi
513
514 return $OCF_SUCCESS
515 }
516
517 # we need a simpler stop version to clean after us if start fails
518 # without involving any error checking
519 # rolling back in case of failure is otherwise complex
520
521 bridge_force_stop() {
522 $IP2UTIL link set dev "$OCF_RESKEY_bridge_name" down 2>&1
523 for slave in $OCF_RESKEY_bridge_slaves; do
524 $IP2UTIL link set dev "$slave" down 2>&1
525 done
526 $BRCTL delbr "$OCF_RESKEY_bridge_name" 2>&1
527 rm -f "$HA_RSCTMP/iface-bridge.$OCF_RESKEY_bridge_name" 2>&1
528 }
529
530 bridge_start() {
531 # check if the bridge already exists
532 bridge_check
533 ret=$?
534 if [ "$ret" != "$OCF_NOT_RUNNING" ]; then
535 return $ret
536 fi
537
538 # create the bridge
539 error="$($BRCTL addbr "$OCF_RESKEY_bridge_name" 2>&1)"
540 if [ "$?" != "0" ]; then
541 ocf_log err "Unable to create bridge $OCF_RESKEY_bridge_name: $error"
542 return $OCF_ERR_GENERIC
543 fi
544
545 # add slaves if configured
546 for slave in $OCF_RESKEY_bridge_slaves; do
547 error="$($BRCTL addif "$OCF_RESKEY_bridge_name" "$slave" 2>&1)"
548 if [ "$?" != "0" ]; then
549 ocf_log err "Unable to add interface $slave to bridge $OCF_RESKEY_bridge_name: $error"
550 return $OCF_ERR_GENERIC
551 fi
552 done
553
554 # set haripin forward mode
555 for hairpin in $OCF_RESKEY_port_hairpin; do
556 error="$($BRCTL hairpin "$OCF_RESKEY_bridge_name" "$hairpin" on 2>&1)"
557 if [ "$?" != "0" ]; then
558 ocf_log err "Unable to set hairpin on for interface $hairpin to bridge $OCF_RESKEY_bridge_name: $error"
559 return $OCF_ERR_GENERIC
560 fi
561 done
562
563 # set bridge ageing
564 if [ -n "$OCF_RESKEY_bridge_ageing" ]; then
565 error="$($BRCTL setageing "$OCF_RESKEY_bridge_name" "$OCF_RESKEY_bridge_ageing" 2>&1)"
566 if [ "$?" != "0" ]; then
567 ocf_log err "Unable to set bridge $OCF_RESKEY_bridge_name ageing to $OCF_RESKEY_bridge_ageing: $error"
568 return $OCF_ERR_GENERIC
569 fi
570 fi
571
572 # OCF_RESKEY_stp_fd needs special handling as it can be 0 or greater
573 # but only when configured before OCF_RESKEY_stp.
574 # if enabled after OCF_RESKEY_stp with stp=true the value range is
575 # different. It is not clear from the man page or brctl documentation
576 # what the range is ahead of time.
577 if [ -n "$OCF_RESKEY_stp_fd" ]; then
578 error="$($BRCTL setfd "$OCF_RESKEY_bridge_name" "$OCF_RESKEY_stp_fd" 2>&1)"
579 if [ "$?" != "0" ]; then
580 ocf_log err "Unable to set bridge forward delay $OCF_RESKEY_stp_fd on bridge $OCF_RESKEY_bridge_name : $error"
581 return $OCF_ERR_GENERIC
582 fi
583 fi
584
585 # enable/disable spanning tree protocol
586 if ocf_is_true "$OCF_RESKEY_stp"; then
587 error="$($BRCTL stp "$OCF_RESKEY_bridge_name" on 2>&1)"
588 if [ "$?" != "0" ]; then
589 ocf_log err "Unable to enable STP on bridge $OCF_RESKEY_bridge_name : $error"
590 return $OCF_ERR_GENERIC
591 fi
592
593 # set bridge priority
594 if [ -n "$OCF_RESKEY_stp_bridgeprio" ]; then
595 error="$($BRCTL setbridgeprio "$OCF_RESKEY_bridge_name" "$OCF_RESKEY_stp_bridgeprio" 2>&1)"
596 if [ "$?" != "0" ]; then
597 ocf_log err "Unable to set bridge priority $OCF_RESKEY_stp_bridgeprio on bridge $OCF_RESKEY_bridge_name : $error"
598 return $OCF_ERR_GENERIC
599 fi
600 fi
601
602 # set hello timer
603 if [ -n "$OCF_RESKEY_stp_hello" ]; then
604 error="$($BRCTL sethello "$OCF_RESKEY_bridge_name" "$OCF_RESKEY_stp_hello" 2>&1)"
605 if [ "$?" != "0" ]; then
606 ocf_log err "Unable to set bridge hello timer $OCF_RESKEY_stp_hello on bridge $OCF_RESKEY_bridge_name : $error"
607 return $OCF_ERR_GENERIC
608 fi
609 fi
610
611
612 # set max age
613 if [ -n "$OCF_RESKEY_stp_maxage" ]; then
614 error="$($BRCTL setmaxage "$OCF_RESKEY_bridge_name" "$OCF_RESKEY_stp_maxage" 2>&1)"
615 if [ "$?" != "0" ]; then
616 ocf_log err "Unable to set bridge max age $OCF_RESKEY_stp_maxage on bridge $OCF_RESKEY_bridge_name : $error"
617 return $OCF_ERR_GENERIC
618 fi
619 fi
620
621 # set path cost per port
622 if [ -n "$OCF_RESKEY_stp_pathcost" ]; then
623 split_string $OCF_RESKEY_stp_pathcost | { while read iface cost; do
624 error="$($BRCTL setpathcost "$OCF_RESKEY_bridge_name" "$iface" "$cost" 2>&1)"
625 if [ "$?" != "0" ]; then
626 ocf_log err "Unable to set pathcost $cost for interface $iface on bridge $OCF_RESKEY_bridge_name : $error"
627 return $OCF_ERR_GENERIC
628 fi
629 done
630 }
631 fi
632
633 # set port priority per port
634 if [ -n "$OCF_RESKEY_stp_portprio" ]; then
635 split_string $OCF_RESKEY_stp_portprio | { while read iface prio; do
636 error="$($BRCTL setportprio "$OCF_RESKEY_bridge_name" "$iface" "$prio" 2>&1)"
637 if [ "$?" != "0" ]; then
638 ocf_log err "Unable to set portprio $prio for interface $iface on bridge $OCF_RESKEY_bridge_name : $error"
639 return $OCF_ERR_GENERIC
640 fi
641 done
642 }
643 fi
644 else
645 # stp off is default via brctl/kernel interface but it
646 # is best to force it since we don't know if default
647 # has changed across kernel releases
648 error="$($BRCTL stp "$OCF_RESKEY_bridge_name" off 2>&1)"
649 if [ "$?" != "0" ]; then
650 ocf_log err "Unable to disable STP on bridge $OCF_RESKEY_bridge_name : $error"
651 return $OCF_ERR_GENERIC
652 fi
653 fi
654
655 # set slaves up
656 for slave in $OCF_RESKEY_bridge_slaves; do
657 error="$($IP2UTIL link set dev "$slave" up 2>&1)"
658 if [ "$?" != "0" ]; then
659 ocf_log err "Unable to set slave $slave for bridge $OCF_RESKEY_bridge_name up: $error"
660 return $OCF_ERR_GENERIC
661 fi
662 done
663
664 # set the bridge up
665 error="$($IP2UTIL link set dev "$OCF_RESKEY_bridge_name" up 2>&1)"
666 if [ "$?" != "0" ]; then
667 ocf_log err "Unable to set bridge $OCF_RESKEY_bridge_name up: $error"
668 return $OCF_ERR_GENERIC
669 fi
670
671 # multicast operations can only be executed after the bridge is up
672 # and configured.
673
674 # enable/disable multicast router
675 if ocf_is_true "$OCF_RESKEY_multicast_router"; then
676 mcrouter=1
677 else
678 mcrouter=0
679 fi
680 if [ -e "/sys/class/net/$OCF_RESKEY_bridge_name/bridge/multicast_router" ]; then
681 error="$(echo $mcrouter 2>&1 >/sys/class/net/$OCF_RESKEY_bridge_name/bridge/multicast_router)"
682 if [ "$?" != "0" ]; then
683 ocf_log err "Unable to set OCF_RESKEY_multicast_router for bridge $OCF_RESKEY_bridge_name: $error"
684 return $OCF_ERR_GENERIC
685 fi
686 else
687 ocf_log warn "Unable to set multicast router on bridge $OCF_RESKEY_bridge_name because kernel does not support it"
688 fi
689
690 # enable/disable multicast snoopint
691 if ocf_is_true "$OCF_RESKEY_multicast_snooping"; then
692 mcsnooping=1
693 else
694 mcsnooping=0
695 fi
696 if [ -e "/sys/class/net/$OCF_RESKEY_bridge_name/bridge/multicast_snooping" ]; then
697 error="$(echo $mcsnooping 2>&1 >/sys/class/net/$OCF_RESKEY_bridge_name/bridge/multicast_snooping)"
698 if [ "$?" != "0" ]; then
699 ocf_log err "Unable to set OCF_RESKEY_multicast_snooping for bridge $OCF_RESKEY_bridge_name: $error"
700 return $OCF_ERR_GENERIC
701 fi
702 else
703 ocf_log warn "Unable to set multicast snooping on bridge $OCF_RESKEY_bridge_name because kernel does not support it"
704 fi
705
706 # enable/disable multicast querier
707 if ocf_is_true "$OCF_RESKEY_multicast_querier"; then
708 mcquerier=1
709 else
710 mcquerier=0
711 fi
712 if [ -e "/sys/class/net/$OCF_RESKEY_bridge_name/bridge/multicast_querier" ]; then
713 error="$(echo $mcquerier 2>&1 >/sys/class/net/$OCF_RESKEY_bridge_name/bridge/multicast_querier)"
714 if [ "$?" != "0" ]; then
715 ocf_log err "Unable to set OCF_RESKEY_multicast_querier for bridge $OCF_RESKEY_bridge_name: $error"
716 return $OCF_ERR_GENERIC
717 fi
718 else
719 ocf_log warn "Unable to set multicast querier on bridge $OCF_RESKEY_bridge_name because kernel does not support it"
720 fi
721
722 # set multicast router per port
723 if [ -n "$OCF_RESKEY_multicast_port_router" ]; then
724 split_string $OCF_RESKEY_multicast_port_router | { while read iface mcport; do
725 if [ -e "/sys/class/net/$iface/brport/multicast_router" ]; then
726 error="$(echo $mcport 2>&1 >/sys/class/net/$iface/brport/multicast_router)"
727 if [ "$?" != "0" ]; then
728 ocf_log err "Unable to set OCF_RESKEY_multicast_port_router $mcport for interface $iface on bridge $OCF_RESKEY_bridge_name : $error"
729 return $OCF_ERR_GENERIC
730 fi
731 else
732 ocf_log warn "Unable to set multicast port router on bridge $OCF_RESKEY_bridge_name because kernel does not support it"
733 fi
734 done
735 }
736 fi
737
738 error="$(touch "$HA_RSCTMP/iface-bridge.$OCF_RESKEY_bridge_name")"
739 if [ "$?" != "0" ]; then
740 ocf_log err "Unable to write lock file for bridge $OCF_RESKEY_bridge_name: $error"
741 return $OCF_ERR_GENERIC
742 fi
743
744 return $OCF_SUCCESS
745 }
746
747 bridge_stop() {
748 bridge_check
749 ret=$?
750 if [ "$ret" = "$OCF_NOT_RUNNING" ]; then
751 return $OCF_SUCCESS
752 fi
753 if [ "$ret" != "$OCF_SUCCESS" ]; then
754 return $ret
755 fi
756
757 # set bridge down
758 error="$($IP2UTIL link set dev "$OCF_RESKEY_bridge_name" down 2>&1)"
759 if [ "$?" != "0" ]; then
760 ocf_log err "Unable to set bridge $OCF_RESKEY_bridge_name down: $error"
761 return $OCF_ERR_GENERIC
762 fi
763
764 # set slaves down
765 for slave in $OCF_RESKEY_bridge_slaves; do
766 error="$($IP2UTIL link set dev "$slave" down 2>&1)"
767 if [ "$?" != "0" ]; then
768 ocf_log err "Unable to set slave $slave for bridge $OCF_RESKEY_bridge_name down: $error"
769 return $OCF_ERR_GENERIC
770 fi
771 done
772
773 # delete bridge
774 error="$($BRCTL delbr "$OCF_RESKEY_bridge_name" 2>&1)"
775 if [ "$?" != "0" ]; then
776 ocf_log err "Unable to delete bridge $OCF_RESKEY_bridge_name: $error"
777 return $OCF_ERR_GENERIC
778 fi
779
780 error="$(rm -f "$HA_RSCTMP/iface-bridge.$OCF_RESKEY_bridge_name" 2>&1)"
781 if [ "$?" != "0" ]; then
782 ocf_log err "Unable to remove lock file for bridge $OCF_RESKEY_bridge_name: $error"
783 return $OCF_ERR_GENERIC
784 fi
785
786 return $OCF_SUCCESS
787 }
788
789 case $__OCF_ACTION in
790 meta-data)
791 bridge_meta_data
792 exit $OCF_SUCCESS
793 ;;
794 usage|help)
795 bridge_usage
796 exit $OCF_SUCCESS
797 ;;
798 esac
799
800 if [ ! -d "$HA_RSCTMP" ]; then
801 ocf_log debug "$HA_RSCTMP not found, we are probably being executed manually"
802 mkdir -p "$HA_RSCTMP"
803 fi
804
805 if [ -n "$__OCF_ACTION" ] && ! bridge_validate; then
806 exit $OCF_ERR_CONFIGURED
807 fi
808
809 case $__OCF_ACTION in
810 start|stop)
811 if ! ocf_is_root; then
812 ocf_log err "You must be root for $__OCF_ACTION operation."
813 exit $OCF_ERR_PERM
814 fi
815 ;;
816 esac
817
818 case $__OCF_ACTION in
819 start)
820 bridge_start
821 ret=$?
822 if [ "$ret" != "$OCF_SUCCESS" ]; then
823 bridge_force_stop
824 fi
825 exit $ret
826 ;;
827 stop)
828 bridge_stop
829 exit $?
830 ;;
831 status|monitor)
832 bridge_check
833 exit $?
834 ;;
835 validate-all)
836 # bridge_validate above does the trick
837 ;;
838 *)
839 bridge_usage
840 exit $OCF_ERR_UNIMPLEMENTED
841 ;;
842 esac
843 # vi:sw=4:ts=8: