Skip to content

Commit

Permalink
Fix VLAN error introduced with new 4.9 kernel behavior (sonic-net#1001)
Browse files Browse the repository at this point in the history
The change includes two parts:

<1> Bring member out of default VLAN 1 upon putting port/lag in a VLAN

<2> Second part was done by @tieguoevan ( https://github.com/tieguoevan) and incorporated here to avoid test error that would follow change <1>.

Summary:
The Bridge interface needs to be up all the time. Otherwise, the command bridge vlan will fail.
Not sure it is a kernel bug, but it cause error when clear all vlan members and reconfigure it.

create a dummy interface in the Bridge to keep it up all the time

Signed-off-by: Jipan Yang <[email protected]>
  • Loading branch information
jipanyang authored and Tony Titus committed Jul 31, 2019
1 parent 4160813 commit 81283fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cfgmgr/vlanmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
// The command should be generated as:
// /bin/bash -c "/sbin/ip link del Bridge 2>/dev/null ;
// /sbin/ip link add Bridge up type bridge &&
// /sbin/bridge vlan del vid 1 dev Bridge self"
// /sbin/bridge vlan del vid 1 dev Bridge self;
// /sbin/ip link del dummy 2>/dev/null;
// /sbin/ip link add dummy type dummy &&
// sbin/ip link set dummy master Bridge"

const std::string cmds = std::string("")
+ BASH_CMD + " -c \""
+ IP_CMD + " link del " + DOT1Q_BRIDGE_NAME + " 2>/dev/null; "
+ IP_CMD + " link add " + DOT1Q_BRIDGE_NAME + " up type bridge && "
+ BRIDGE_CMD + " vlan del vid " + DEFAULT_VLAN_ID + " dev " + DOT1Q_BRIDGE_NAME + " self\"";
+ BRIDGE_CMD + " vlan del vid " + DEFAULT_VLAN_ID + " dev " + DOT1Q_BRIDGE_NAME + " self; "
+ IP_CMD + " link del dev dummy 2>/dev/null; "
+ IP_CMD + " link add dummy type dummy && "
+ IP_CMD + " link set dummy master " + DOT1Q_BRIDGE_NAME + "\"";

std::string res;
EXEC_WITH_ERROR_THROW(cmds, res);
Expand Down Expand Up @@ -169,10 +175,12 @@ bool VlanMgr::addHostVlanMember(int vlan_id, const string &port_alias, const str

// The command should be generated as:
// /bin/bash -c "/sbin/ip link set {{port_alias}} master Bridge &&
// /sbin/bridge vlan del vid 1 dev {{ port_alias }} &&
// /sbin/bridge vlan add vid {{vlan_id}} dev {{port_alias}} {{tagging_mode}}"
const std::string cmds = std::string("")
+ BASH_CMD + " -c \""
+ IP_CMD + " link set " + port_alias + " master " + DOT1Q_BRIDGE_NAME + " && "
+ BRIDGE_CMD + " vlan del vid " + DEFAULT_VLAN_ID + " dev " + port_alias + " && "
+ BRIDGE_CMD + " vlan add vid " + std::to_string(vlan_id) + " dev " + port_alias + " " + tagging_cmd + "\"";

std::string res;
Expand Down
8 changes: 8 additions & 0 deletions tests/test_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_MultipleVlan(self, dvs, testlog):
vlan_member_entries = tbl.getKeys()
assert len(vlan_member_entries) == 0

# member ports should have been detached from bridge master properly
exitcode, output = dvs.runcmd(['sh', '-c', "ip link show Ethernet20 | grep -w master"])
assert exitcode != 0
exitcode, output = dvs.runcmd(['sh', '-c', "ip link show Ethernet24 | grep -w master"])
assert exitcode != 0
exitcode, output = dvs.runcmd(['sh', '-c', "ip link show Ethernet28 | grep -w master"])
assert exitcode != 0

# remove vlans
dvs.remove_vlan("18")
dvs.remove_vlan("188")
Expand Down

0 comments on commit 81283fb

Please sign in to comment.