From 57a98acb893c73063792bf6d7adf8bca71f8b9d6 Mon Sep 17 00:00:00 2001 From: lguohan Date: Thu, 30 Nov 2017 08:47:49 -0800 Subject: [PATCH] [vlanmgr]: use IP cmd to setup vlan_filter as a backup method (#401) echo will fail in virtual switch since /sys directory is read-only. need to use ip command to setup the vlan_filtering which is not available in debian 8. Once we move sonic to debian 9, we can use IP command by default. --- cfgmgr/vlanmgr.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index 43a7e0303034..e9f4eb650ee3 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -44,7 +44,16 @@ VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c cmd.str(""); cmd << ECHO_CMD << " 1 > /sys/class/net/" << DOT1Q_BRIDGE_NAME << "/bridge/vlan_filtering"; - EXEC_WITH_ERROR_THROW(cmd.str(), res); + int ret = swss::exec(cmd.str(), res); + /* echo will fail in virtual switch since /sys directory is read-only. + * need to use ip command to setup the vlan_filtering which is not available in debian 8. + * Once we move sonic to debian 9, we can use IP command by default */ + if (ret != 0) + { + cmd.str(""); + cmd << IP_CMD << " link set " << DOT1Q_BRIDGE_NAME << " type bridge vlan_filtering 1"; + EXEC_WITH_ERROR_THROW(cmd.str(), res); + } cmd.str(""); cmd << BRIDGE_CMD << " vlan del vid " << DEFAULT_VLAN_ID << " dev " << DOT1Q_BRIDGE_NAME << " self";