Skip to content

Commit 9844cf0

Browse files
committed
vxlan: Improve Bash if-statement logic
Bash suggest using double brackets instead of single brackets in if-statement test logic Signed-off-by: Wido den Hollander <wido@widodh.nl>
1 parent 2a52e06 commit 9844cf0

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

scripts/vm/network/vnet/modifyvxlan.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ addVxlan() {
3737
local sysfs_dir=/sys/devices/virtual/net/
3838
local brif=`find ${sysfs_dir}*/brif/ -name $pif | sed -e "s,$sysfs_dir,," | sed -e 's,/brif/.*$,,'`
3939

40-
if [ "$brif " == " " ]
40+
if [[ "$brif " == " " ]]
4141
then
42-
if [ -d "/sys/class/net/${pif}" ]
42+
if [[ -d "/sys/class/net/${pif}" ]]
4343
then
4444
# if bridge is not found, but matches a pif, use it
4545
brif=$pif
@@ -50,7 +50,7 @@ addVxlan() {
5050
else
5151
# confirm ip address of $brif
5252
ip addr show $brif | grep -w inet
53-
if [ $? -gt 0 ]
53+
if [[ $? -gt 0 ]]
5454
then
5555
printf "Failed to find vxlan multicast source ip address on brif: $brif."
5656
return 1
@@ -60,23 +60,23 @@ addVxlan() {
6060
# mcast route
6161
## TODO(VXLAN): Can we assume there're only one IP address which can be multicast src IP on the IF?
6262
ip route get $mcastGrp | grep -w "dev $brif"
63-
if [ $? -gt 0 ]
63+
if [[ $? -gt 0 ]]
6464
then
6565
ip route add $mcastGrp/32 dev $brif
66-
if [ $? -gt 0 ]
66+
if [[ $? -gt 0 ]]
6767
then
6868
printf "Failed to add vxlan multicast route on brif: $brif."
6969
return 1
7070
fi
7171
fi
7272

73-
if [ ! -d /sys/class/net/$vxlanDev ]
73+
if [[ ! -d /sys/class/net/$vxlanDev ]]
7474
then
7575
ip link add $vxlanDev type vxlan id $vxlanId group $mcastGrp ttl 10 dev $brif
76-
if [ $? -gt 0 ]
76+
if [[ $? -gt 0 ]]
7777
then
7878
# race condition that someone already creates the vxlan
79-
if [ ! -d /sys/class/net/$vxlanDev ]
79+
if [[ ! -d /sys/class/net/$vxlanDev ]]
8080
then
8181
printf "Failed to create vxlan $vxlanId on brif: $brif."
8282
return 1
@@ -86,17 +86,17 @@ addVxlan() {
8686

8787
# is up?
8888
ip link show $vxlanDev | grep -w UP > /dev/null
89-
if [ $? -gt 0 ]
89+
if [[ $? -gt 0 ]]
9090
then
9191
ip link set $vxlanDev up > /dev/null
9292
fi
9393

94-
if [ ! -d /sys/class/net/$vxlanBr ]
94+
if [[ ! -d /sys/class/net/$vxlanBr ]]
9595
then
9696
brctl addbr $vxlanBr > /dev/null
97-
if [ $? -gt 0 ]
97+
if [[ $? -gt 0 ]]
9898
then
99-
if [ ! -d /sys/class/net/$vxlanBr ]
99+
if [[ ! -d /sys/class/net/$vxlanBr ]]
100100
then
101101
printf "Failed to create br: $vxlanBr"
102102
return 2
@@ -107,13 +107,13 @@ addVxlan() {
107107

108108
#pif is eslaved into vxlanBr?
109109
ls /sys/class/net/$vxlanBr/brif/ | grep -w "$vxlanDev" > /dev/null
110-
if [ $? -gt 0 ]
110+
if [[ $? -gt 0 ]]
111111
then
112112
brctl addif $vxlanBr $vxlanDev > /dev/null
113-
if [ $? -gt 0 ]
113+
if [[ $? -gt 0 ]]
114114
then
115115
ls /sys/class/net/$vxlanBr/brif/ | grep -w "$vxlanDev" > /dev/null
116-
if [ $? -gt 0 ]
116+
if [[ $? -gt 0 ]]
117117
then
118118
printf "Failed to add vxlan: $vxlanDev to $vxlanBr"
119119
return 3
@@ -123,7 +123,7 @@ addVxlan() {
123123

124124
# is vxlanBr up?
125125
ip link show $vxlanBr | grep -w UP > /dev/null
126-
if [ $? -gt 0 ]
126+
if [[ $? -gt 0 ]]
127127
then
128128
ip link set $vxlanBr up
129129
fi
@@ -145,22 +145,22 @@ deleteVxlan() {
145145

146146
ip link delete $vxlanDev
147147

148-
if [ $? -gt 0 ]
148+
if [[ $? -gt 0 ]]
149149
then
150150
printf "Failed to del vxlan: $vxlanId"
151151
printf "Continue..."
152152
fi
153153

154154
ip link set $vxlanBr down
155155

156-
if [ $? -gt 0 ]
156+
if [[ $? -gt 0 ]]
157157
then
158158
return 1
159159
fi
160160

161161
brctl delbr $vxlanBr
162162

163-
if [ $? -gt 0 ]
163+
if [[ $? -gt 0 ]]
164164
then
165165
printf "Failed to del bridge $vxlanBr"
166166
return 1
@@ -195,25 +195,25 @@ do
195195
done
196196

197197
# Check that all arguments were passed in
198-
if [ "$oflag$vflag$pflag$bflag" != "1111" ]
198+
if [[ "$oflag$vflag$pflag$bflag" != "1111" ]]
199199
then
200200
usage
201201
exit 2
202202
fi
203203

204204
# Do we support Vxlan?
205205
lsmod|grep ^vxlan >& /dev/null
206-
if [ $? -gt 0 ]
206+
if [[ $? -gt 0 ]]
207207
then
208208
modprobe=`modprobe vxlan 2>&1`
209-
if [ $? -gt 0 ]
209+
if [[ $? -gt 0 ]]
210210
then
211211
printf "Failed to load vxlan kernel module: $modprobe"
212212
exit 1
213213
fi
214214
fi
215215

216-
if [ "$op" == "add" ]
216+
if [[ "$op" == "add" ]]
217217
then
218218
# Add the vxlan
219219
addVxlan $vxlanId $pif $brName
@@ -224,7 +224,7 @@ then
224224
exit 1
225225
fi
226226
else
227-
if [ "$op" == "delete" ]
227+
if [[ "$op" == "delete" ]]
228228
then
229229
# Delete the vxlan
230230
deleteVxlan $vxlanId $pif $brName

0 commit comments

Comments
 (0)