safer checks in network-bridge script
PATCH 1/1 safer checks in network-bridge script
The network-bridge script is fragile because of how grep is used. As one example, if I already have "xenbridge", I can't create "xenbr". (It's actually worse than that, because it's even grepping the header output by brctl show.)
Assuming dom0 is on Linux with /sys mounted (is that a safe assumption?) we can check for the existence of a bridge, and check if a device is on the bridge, by looking in /sys. The attached patch does that.
If that's not a safe assumption, at least add "-w" to the two instances of grep. Not perfect, but better.
tools/examples/network-bridge +2 -2
@@ -157,7 +157,7 @@ create_bridge () { local bridge=$1 # Don't create the bridge if it already exists. - if ! brctl show | grep -q ${bridge} ; then + if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then brctl addbr ${bridge} brctl stp ${bridge} off brctl setfd ${bridge} 0
@@ -170,7 +170,7 @@ add_to_bridge () { local bridge=$1 local dev=$2 # Don't add $dev to $bridge if it's already on a bridge. - if ! brctl show | grep -q ${dev} ; then + if [ ! -e "/sys/class/net/*/brif/${dev}" ]; then brctl addif ${bridge} ${dev} fi }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 5 lines · Charles Coffing
The network-bridge script is fragile because of how grep is used. As one example, if I already have "xenbridge", I can't create "xenbr". (It's actually worse than that, because it's even grepping the header output by brctl show.)
Quoted 7 lines
Assuming dom0 is on Linux with /sys mounted (is that a safe assumption?) we can check for the existence of a bridge, and check if a device is on the bridge, by looking in /sys. The attached patch does that.
If that's not a safe assumption, at least add "-w" to the two instances of grep. Not perfect, but better.
Thanks for this, Charles. I'm not sure that it's safe to rely upon /sys though. Could you rework this patch to use /sys/class if it exists, but falls back to using grep / brctl otherwise (and fix the grep)?
Thanks,
Ewan.