From d146572eab9b45110c39bae017759c766aa3d75f Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Thu, 22 Nov 2018 02:58:08 +0100 Subject: [PATCH] Fix interface name used on link message using lane map (#386) --- vslib/src/sai_vs_hostintf.cpp | 67 ++++++++++++++++++++--------------- vslib/src/sai_vs_switch.cpp | 3 +- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/vslib/src/sai_vs_hostintf.cpp b/vslib/src/sai_vs_hostintf.cpp index 06ee08eee198..5346aadac188 100644 --- a/vslib/src/sai_vs_hostintf.cpp +++ b/vslib/src/sai_vs_hostintf.cpp @@ -827,54 +827,63 @@ void tap2veth_fun(std::shared_ptr info) SWSS_LOG_NOTICE("ending thread proc for %s", info->name.c_str()); } -bool hostif_create_tap_veth_forwarding( - _In_ const std::string &tapname, - _In_ int tapfd, +std::string vs_get_veth_name( + _In_ const std::string& tapname, _In_ sai_object_id_t port_id) { SWSS_LOG_ENTER(); - // we assume here that veth devices were added by user before creating this - // host interface, vEthernetX will be used for packet transfer between ip - // namespaces - std::string vethname = SAI_VS_VETH_PREFIX + tapname; // check if user override interface names - { - sai_attribute_t attr; + sai_attribute_t attr; + + uint32_t lanes[4]; - uint32_t lanes[4]; + attr.id = SAI_PORT_ATTR_HW_LANE_LIST; - attr.id = SAI_PORT_ATTR_HW_LANE_LIST; + attr.value.u32list.count = 4; + attr.value.u32list.list = lanes; - attr.value.u32list.count = 4; - attr.value.u32list.list = lanes; + if (vs_generic_get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr) != SAI_STATUS_SUCCESS) + { + SWSS_LOG_WARN("failed to get port %s lanes, using veth: %s", + sai_serialize_object_id(port_id).c_str(), + vethname.c_str()); + } + else + { + auto it = g_lane_to_ifname.find(lanes[0]); - if (vs_generic_get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr) != SAI_STATUS_SUCCESS) + if (it == g_lane_to_ifname.end()) { - SWSS_LOG_WARN("failed to get port %s lanes, using veth: %s", - sai_serialize_object_id(port_id).c_str(), - vethname.c_str()); + SWSS_LOG_WARN("failed to get ifname from lane number %u", lanes[0]); } else { - auto it = g_lane_to_ifname.find(lanes[0]); + SWSS_LOG_NOTICE("using %s instead of %s", it->second.c_str(), vethname.c_str()); - if (it == g_lane_to_ifname.end()) - { - SWSS_LOG_WARN("failed to get ifname from lane number %u", lanes[0]); - } - else - { - SWSS_LOG_NOTICE("using %s instead of %s", it->second.c_str(), vethname.c_str()); - - vethname = it->second; - } + vethname = it->second; } } + return vethname; +} + +bool hostif_create_tap_veth_forwarding( + _In_ const std::string &tapname, + _In_ int tapfd, + _In_ sai_object_id_t port_id) +{ + SWSS_LOG_ENTER(); + + // we assume here that veth devices were added by user before creating this + // host interface, vEthernetX will be used for packet transfer between ip + // namespaces or ethernet device name used in lane map if provided + + std::string vethname = vs_get_veth_name(tapname, port_id); + int packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (packet_socket < 0) @@ -1081,7 +1090,7 @@ sai_status_t vs_create_hostif_int( SWSS_LOG_ERROR("forwarding rule on %s was not added", name.c_str()); } - std::string vname = SAI_VS_VETH_PREFIX + name; + std::string vname = vs_get_veth_name(name, obj_id); SWSS_LOG_INFO("mapping interface %s to port id %s", vname.c_str(), diff --git a/vslib/src/sai_vs_switch.cpp b/vslib/src/sai_vs_switch.cpp index 977927430b5a..326d73be413c 100644 --- a/vslib/src/sai_vs_switch.cpp +++ b/vslib/src/sai_vs_switch.cpp @@ -92,7 +92,8 @@ class LinkMsg : public swss::NetMsg unsigned int if_flags = rtnl_link_get_flags(link); // IFF_LOWER_UP and IFF_RUNNING const char* if_name = rtnl_link_get_name(link); - if (strncmp(if_name, SAI_VS_VETH_PREFIX, sizeof(SAI_VS_VETH_PREFIX) - 1) != 0) + if (strncmp(if_name, SAI_VS_VETH_PREFIX, sizeof(SAI_VS_VETH_PREFIX) - 1) != 0 && + g_ifname_to_lanes.find(if_name) == g_ifname_to_lanes.end()) { SWSS_LOG_INFO("skipping newlink for %s", if_name); return;