Skip to content

Commit 4b4aaf9

Browse files
authored
[vlanmgr] use IP command for vlan_filtering and no_linklocal_learn, remove echo command (#3198)
Why I did Database privileges give RW permission to /sys. In container hardening, when remove database privileges, /sys is changed to RO permission for all Sonic containers What I did it Use IP command (fallback method previously) for vlan_filtering and no_linklocal_learn, remove echo command
1 parent 70eb766 commit 4b4aaf9

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

cfgmgr/vlanmgr.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,13 @@ VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
9595
std::string res;
9696
EXEC_WITH_ERROR_THROW(cmds, res);
9797

98-
// The generated command is:
99-
// /bin/echo 1 > /sys/class/net/Bridge/bridge/vlan_filtering
100-
const std::string echo_cmd = std::string("")
101-
+ ECHO_CMD + " 1 > /sys/class/net/" + DOT1Q_BRIDGE_NAME + "/bridge/vlan_filtering";
102-
103-
int ret = swss::exec(echo_cmd, res);
104-
/* echo will fail in virtual switch since /sys directory is read-only.
105-
* need to use ip command to setup the vlan_filtering which is not available in debian 8.
106-
* Once we move sonic to debian 9, we can use IP command by default
107-
* ip command available in Debian 9 to create a bridge with a vlan filtering:
108-
* /sbin/ip link add Bridge up type bridge vlan_filtering 1 */
109-
if (ret != 0)
110-
{
111-
const std::string echo_cmd_backup = std::string("")
112-
+ IP_CMD + " link set " + DOT1Q_BRIDGE_NAME + " type bridge vlan_filtering 1";
113-
114-
EXEC_WITH_ERROR_THROW(echo_cmd_backup, res);
115-
}
116-
117-
// not learn from link-local frames
118-
// /bin/echo 1 > /sys/class/net/Bridge/bridge/no_linklocal_learn
119-
const std::string no_ll_learn_cmd = std::string("")
120-
+ ECHO_CMD + " 1 > /sys/class/net/" + DOT1Q_BRIDGE_NAME + "/bridge/no_linklocal_learn";
121-
122-
ret = swss::exec(no_ll_learn_cmd, res);
123-
if (ret != 0) {
124-
EXEC_WITH_ERROR_THROW(no_ll_learn_cmd, res);
125-
}
98+
// /sbin/ip link set Bridge type bridge vlan_filtering 1
99+
const std::string vlan_filtering_cmd = std::string(IP_CMD) + " link set " + DOT1Q_BRIDGE_NAME + " type bridge vlan_filtering 1";
100+
EXEC_WITH_ERROR_THROW(vlan_filtering_cmd, res);
126101

102+
// /sbin/ip link set Bridge type bridge no_linklocal_learn 1
103+
const std::string no_ll_learn_cmd = std::string(IP_CMD) + " link set " + DOT1Q_BRIDGE_NAME + " type bridge no_linklocal_learn 1";
104+
EXEC_WITH_ERROR_THROW(no_ll_learn_cmd, res);
127105
}
128106

129107
bool VlanMgr::addHostVlan(int vlan_id)

0 commit comments

Comments
 (0)