Skip to content

Commit

Permalink
support virtual switch (sonic-net#384)
Browse files Browse the repository at this point in the history
* support virtual switch

Signed-off-by: Guohan Lu <[email protected]>

* bring physical interface up and turn on promisc

Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan authored Nov 18, 2018
1 parent 398d24a commit 5ddafbc
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
7 changes: 7 additions & 0 deletions syncd/scripts/syncd_init_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ config_syncd_nephos()
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
}

config_syncd_vs()
{
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
}

config_syncd()
{
check_warm_boot
Expand All @@ -154,6 +159,8 @@ config_syncd()
config_syncd_barefoot
elif [ "$SONIC_ASIC_TYPE" == "nephos" ]; then
config_syncd_nephos
elif [ "$SONIC_ASIC_TYPE" == "vs" ]; then
config_syncd_vs
else
echo "Unknown ASIC type $SONIC_ASIC_TYPE"
exit 1
Expand Down
76 changes: 76 additions & 0 deletions vslib/src/sai_vs_hostintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,13 @@ int ifup(const char *dev)
return err;
}

if (ifr.ifr_flags & IFF_UP)
{
close(s);

return 0;
}

ifr.ifr_flags |= IFF_UP;

err = ioctl(s, SIOCSIFFLAGS, &ifr);
Expand All @@ -695,6 +702,57 @@ int ifup(const char *dev)
return err;
}

int promisc(const char *dev)
{
SWSS_LOG_ENTER();

int s = socket(AF_INET, SOCK_DGRAM, 0);

if (s < 0)
{
SWSS_LOG_ERROR("failed to open socket: %d", s);

return -1;
}

struct ifreq ifr;

memset(&ifr, 0, sizeof ifr);

strncpy(ifr.ifr_name, dev , IFNAMSIZ);

int err = ioctl(s, SIOCGIFFLAGS, &ifr);

if (err < 0)
{
SWSS_LOG_ERROR("ioctl SIOCGIFFLAGS on socket %d %s failed, err %d", s, dev, err);

close(s);

return err;
}

if (ifr.ifr_flags & IFF_PROMISC)
{
close(s);

return 0;
}

ifr.ifr_flags |= IFF_PROMISC;

err = ioctl(s, SIOCSIFFLAGS, &ifr);

if (err < 0)
{
SWSS_LOG_ERROR("ioctl SIOCSIFFLAGS on socket %d %s failed, err %d", s, dev, err);
}

close(s);

return err;
}

void veth2tap_fun(std::shared_ptr<hostif_info_t> info)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -812,6 +870,24 @@ bool hostif_create_tap_veth_forwarding(

SWSS_LOG_INFO("interface index = %d %s\n", sock_address.sll_ifindex, vethname.c_str());

if (ifup(vethname.c_str()))
{
SWSS_LOG_ERROR("ifup failed on %s", vethname.c_str());

close(packet_socket);

return false;
}

if (promisc(vethname.c_str()))
{
SWSS_LOG_ERROR("promisc failed on %s", vethname.c_str());

close(packet_socket);

return false;
}

if (bind(packet_socket, (struct sockaddr*) &sock_address, sizeof(sock_address)) < 0)
{
SWSS_LOG_ERROR("bind failed on %s", vethname.c_str());
Expand Down

0 comments on commit 5ddafbc

Please sign in to comment.