Skip to content

Commit d146572

Browse files
kcudniklguohan
authored andcommitted
Fix interface name used on link message using lane map (sonic-net#386)
1 parent efdd86f commit d146572

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

vslib/src/sai_vs_hostintf.cpp

+38-29
Original file line numberDiff line numberDiff line change
@@ -827,54 +827,63 @@ void tap2veth_fun(std::shared_ptr<hostif_info_t> info)
827827
SWSS_LOG_NOTICE("ending thread proc for %s", info->name.c_str());
828828
}
829829

830-
bool hostif_create_tap_veth_forwarding(
831-
_In_ const std::string &tapname,
832-
_In_ int tapfd,
830+
std::string vs_get_veth_name(
831+
_In_ const std::string& tapname,
833832
_In_ sai_object_id_t port_id)
834833
{
835834
SWSS_LOG_ENTER();
836835

837-
// we assume here that veth devices were added by user before creating this
838-
// host interface, vEthernetX will be used for packet transfer between ip
839-
// namespaces
840-
841836
std::string vethname = SAI_VS_VETH_PREFIX + tapname;
842837

843838
// check if user override interface names
844839

845-
{
846-
sai_attribute_t attr;
840+
sai_attribute_t attr;
841+
842+
uint32_t lanes[4];
847843

848-
uint32_t lanes[4];
844+
attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
849845

850-
attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
846+
attr.value.u32list.count = 4;
847+
attr.value.u32list.list = lanes;
851848

852-
attr.value.u32list.count = 4;
853-
attr.value.u32list.list = lanes;
849+
if (vs_generic_get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr) != SAI_STATUS_SUCCESS)
850+
{
851+
SWSS_LOG_WARN("failed to get port %s lanes, using veth: %s",
852+
sai_serialize_object_id(port_id).c_str(),
853+
vethname.c_str());
854+
}
855+
else
856+
{
857+
auto it = g_lane_to_ifname.find(lanes[0]);
854858

855-
if (vs_generic_get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr) != SAI_STATUS_SUCCESS)
859+
if (it == g_lane_to_ifname.end())
856860
{
857-
SWSS_LOG_WARN("failed to get port %s lanes, using veth: %s",
858-
sai_serialize_object_id(port_id).c_str(),
859-
vethname.c_str());
861+
SWSS_LOG_WARN("failed to get ifname from lane number %u", lanes[0]);
860862
}
861863
else
862864
{
863-
auto it = g_lane_to_ifname.find(lanes[0]);
865+
SWSS_LOG_NOTICE("using %s instead of %s", it->second.c_str(), vethname.c_str());
864866

865-
if (it == g_lane_to_ifname.end())
866-
{
867-
SWSS_LOG_WARN("failed to get ifname from lane number %u", lanes[0]);
868-
}
869-
else
870-
{
871-
SWSS_LOG_NOTICE("using %s instead of %s", it->second.c_str(), vethname.c_str());
872-
873-
vethname = it->second;
874-
}
867+
vethname = it->second;
875868
}
876869
}
877870

871+
return vethname;
872+
}
873+
874+
bool hostif_create_tap_veth_forwarding(
875+
_In_ const std::string &tapname,
876+
_In_ int tapfd,
877+
_In_ sai_object_id_t port_id)
878+
{
879+
SWSS_LOG_ENTER();
880+
881+
// we assume here that veth devices were added by user before creating this
882+
// host interface, vEthernetX will be used for packet transfer between ip
883+
// namespaces or ethernet device name used in lane map if provided
884+
885+
std::string vethname = vs_get_veth_name(tapname, port_id);
886+
878887
int packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
879888

880889
if (packet_socket < 0)
@@ -1081,7 +1090,7 @@ sai_status_t vs_create_hostif_int(
10811090
SWSS_LOG_ERROR("forwarding rule on %s was not added", name.c_str());
10821091
}
10831092

1084-
std::string vname = SAI_VS_VETH_PREFIX + name;
1093+
std::string vname = vs_get_veth_name(name, obj_id);
10851094

10861095
SWSS_LOG_INFO("mapping interface %s to port id %s",
10871096
vname.c_str(),

vslib/src/sai_vs_switch.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class LinkMsg : public swss::NetMsg
9292
unsigned int if_flags = rtnl_link_get_flags(link); // IFF_LOWER_UP and IFF_RUNNING
9393
const char* if_name = rtnl_link_get_name(link);
9494

95-
if (strncmp(if_name, SAI_VS_VETH_PREFIX, sizeof(SAI_VS_VETH_PREFIX) - 1) != 0)
95+
if (strncmp(if_name, SAI_VS_VETH_PREFIX, sizeof(SAI_VS_VETH_PREFIX) - 1) != 0 &&
96+
g_ifname_to_lanes.find(if_name) == g_ifname_to_lanes.end())
9697
{
9798
SWSS_LOG_INFO("skipping newlink for %s", if_name);
9899
return;

0 commit comments

Comments
 (0)