Skip to content

Commit cf9a293

Browse files
Wataru IshidaShuotian Cheng
Wataru Ishida
authored and
Shuotian Cheng
committed
[vlanmgrd]: Fix bug of removing VLAN members (sonic-net#387)
When an interface belongs to multiple VLANs, 'grep -q None' won't return 0 and we should not set this interface to 'nomaster'. Signed-off-by: Wataru Ishida <[email protected]>
1 parent ebb5324 commit cf9a293

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cfgmgr/vlanmgr.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,22 @@ bool VlanMgr::removeHostVlanMember(int vlan_id, const string &port_alias)
172172
SWSS_LOG_ENTER();
173173

174174
// The command should be generated as:
175-
// /bin/bash -c "/sbin/bridge vlan del vid {{vlan_id}} dev {{port_alias}} &&
176-
// /sbin/bridge vlan show dev {{port_alias}} | /bin/grep -q None &&
177-
// /sbin/ip link set {{port_alias}} nomaster"
175+
// /bin/bash -c '/sbin/bridge vlan del vid {{vlan_id}} dev {{port_alias}} &&
176+
// ( /sbin/bridge vlan show dev {{port_alias}} | /bin/grep -q None;
177+
// ret=$?; if [ $ret -eq 0 ]; then
178+
// /sbin/ip link set {{port_alias}} nomaster;
179+
// elif [ $ret -eq 1 ]; then exit 0;
180+
// else exit $ret; fi )'
178181

179182
// When port is not member of any VLAN, it shall be detached from Dot1Q bridge!
180183
const std::string cmds = std::string("")
181-
+ BASH_CMD + " -c \""
182-
+ BRIDGE_CMD + " vlan del vid " + std::to_string(vlan_id) + " dev " + port_alias + " && "
184+
+ BASH_CMD + " -c \'"
185+
+ BRIDGE_CMD + " vlan del vid " + std::to_string(vlan_id) + " dev " + port_alias + " && ( "
183186
+ BRIDGE_CMD + " vlan show dev " + port_alias + " | "
184-
+ GREP_CMD + " -q None && "
185-
+ IP_CMD + " link set " + port_alias + " nomaster\"";
187+
+ GREP_CMD + " -q None; ret=$?; if [ $ret -eq 0 ]; then "
188+
+ IP_CMD + " link set " + port_alias + " nomaster; "
189+
+ "elif [ $ret -eq 1 ]; then exit 0; "
190+
+ "else exit $ret; fi )\'";
186191

187192
std::string res;
188193
EXEC_WITH_ERROR_THROW(cmds, res);

0 commit comments

Comments
 (0)