Skip to content

Commit

Permalink
Fix interface name used on link message using lane map (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and lguohan committed Nov 22, 2018
1 parent efdd86f commit d146572
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
67 changes: 38 additions & 29 deletions vslib/src/sai_vs_hostintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,54 +827,63 @@ void tap2veth_fun(std::shared_ptr<hostif_info_t> 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)
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion vslib/src/sai_vs_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d146572

Please sign in to comment.