Skip to content

Commit 9ef2ba4

Browse files
authored
[vlanmgr]: Update VLAN removal code to work with 5.10 kernel and newer iproute2 versions (sonic-net#1970)
* Update VLAN removal code to work with 5.10 kernel and newer iproute2 versions There is an issue discovered by Alexander Allen where VLAN member removal from a VLAN doesn't fully happen on a 5.10 kernel. The reason for this is that there is a change in the output of the `bridge vlan show` command between the 4.19 kernel and the 5.10 kernel. To add to this, the output is different depending on whether iproute2 4.20 or iproute2 5.10 is installed. These output changes cause only some of the VLAN member removal code to run; specifically, the interface will not be the member of a VLAN anymore, but it will still be part of the bridge. Therefore, update the code that parses the output of `bridge vlan show` to handle iproute2 4.20 with 4.19 kernel, iproute2 4.20 with 5.10 kernel, and iproute2 5.10 with 5.10 kernel. This should cover all possible combinations we'll have until all containers are on Bullseye. Signed-off-by: Saikrishna Arcot <[email protected]> * Store the exit code of the bridge vlan show command. Signed-off-by: Saikrishna Arcot <[email protected]> * Add missing space. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent 41fb26c commit 9ef2ba4

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

cfgmgr/vlanmgr.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,27 @@ bool VlanMgr::removeHostVlanMember(int vlan_id, const string &port_alias)
237237

238238
// The command should be generated as:
239239
// /bin/bash -c '/sbin/bridge vlan del vid {{vlan_id}} dev {{port_alias}} &&
240-
// ( /sbin/bridge vlan show dev {{port_alias}} | /bin/grep -q None;
241-
// ret=$?; if [ $ret -eq 0 ]; then
240+
// ( vlanShow=$(/sbin/bridge vlan show dev {{port_alias}});
241+
// ret=$?;
242+
// if [ $ret -eq 0 ]; then
243+
// if (! echo "$vlanShow" | grep -q {{port_alias}})
244+
// || (echo "$vlanShow" | grep -q None$)
245+
// || (echo "$vlanShow" | grep -q {{port_alias}}$); then
242246
// /sbin/ip link set {{port_alias}} nomaster;
243-
// elif [ $ret -eq 1 ]; then exit 0;
247+
// fi;
244248
// else exit $ret; fi )'
245249

246250
// When port is not member of any VLAN, it shall be detached from Dot1Q bridge!
247251
ostringstream cmds, inner;
248252
inner << BRIDGE_CMD " vlan del vid " + std::to_string(vlan_id) + " dev " << shellquote(port_alias) << " && ( "
249-
BRIDGE_CMD " vlan show dev " << shellquote(port_alias) << " | "
250-
GREP_CMD " -q None; ret=$?; if [ $ret -eq 0 ]; then "
253+
"vlanShow=$(" BRIDGE_CMD " vlan show dev " << shellquote(port_alias) << "); "
254+
"ret=$?; "
255+
"if [ $ret -eq 0 ]; then "
256+
"if (! echo \"$vlanShow\" | " GREP_CMD " -q " << shellquote(port_alias) << ") "
257+
" || (echo \"$vlanShow\" | " GREP_CMD " -q None$) "
258+
" || (echo \"$vlanShow\" | " GREP_CMD " -q " << shellquote(port_alias) << "$); then "
251259
IP_CMD " link set " << shellquote(port_alias) << " nomaster; "
252-
"elif [ $ret -eq 1 ]; then exit 0; "
260+
"fi; "
253261
"else exit $ret; fi )";
254262
cmds << BASH_CMD " -c " << shellquote(inner.str());
255263

0 commit comments

Comments
 (0)