Skip to content

Commit 5ddafbc

Browse files
authored
support virtual switch (sonic-net#384)
* support virtual switch Signed-off-by: Guohan Lu <gulv@microsoft.com> * bring physical interface up and turn on promisc Signed-off-by: Guohan Lu <gulv@microsoft.com>
1 parent 398d24a commit 5ddafbc

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

syncd/scripts/syncd_init_common.sh

+7
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ config_syncd_nephos()
136136
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
137137
}
138138

139+
config_syncd_vs()
140+
{
141+
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
142+
}
143+
139144
config_syncd()
140145
{
141146
check_warm_boot
@@ -154,6 +159,8 @@ config_syncd()
154159
config_syncd_barefoot
155160
elif [ "$SONIC_ASIC_TYPE" == "nephos" ]; then
156161
config_syncd_nephos
162+
elif [ "$SONIC_ASIC_TYPE" == "vs" ]; then
163+
config_syncd_vs
157164
else
158165
echo "Unknown ASIC type $SONIC_ASIC_TYPE"
159166
exit 1

vslib/src/sai_vs_hostintf.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,13 @@ int ifup(const char *dev)
681681
return err;
682682
}
683683

684+
if (ifr.ifr_flags & IFF_UP)
685+
{
686+
close(s);
687+
688+
return 0;
689+
}
690+
684691
ifr.ifr_flags |= IFF_UP;
685692

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

705+
int promisc(const char *dev)
706+
{
707+
SWSS_LOG_ENTER();
708+
709+
int s = socket(AF_INET, SOCK_DGRAM, 0);
710+
711+
if (s < 0)
712+
{
713+
SWSS_LOG_ERROR("failed to open socket: %d", s);
714+
715+
return -1;
716+
}
717+
718+
struct ifreq ifr;
719+
720+
memset(&ifr, 0, sizeof ifr);
721+
722+
strncpy(ifr.ifr_name, dev , IFNAMSIZ);
723+
724+
int err = ioctl(s, SIOCGIFFLAGS, &ifr);
725+
726+
if (err < 0)
727+
{
728+
SWSS_LOG_ERROR("ioctl SIOCGIFFLAGS on socket %d %s failed, err %d", s, dev, err);
729+
730+
close(s);
731+
732+
return err;
733+
}
734+
735+
if (ifr.ifr_flags & IFF_PROMISC)
736+
{
737+
close(s);
738+
739+
return 0;
740+
}
741+
742+
ifr.ifr_flags |= IFF_PROMISC;
743+
744+
err = ioctl(s, SIOCSIFFLAGS, &ifr);
745+
746+
if (err < 0)
747+
{
748+
SWSS_LOG_ERROR("ioctl SIOCSIFFLAGS on socket %d %s failed, err %d", s, dev, err);
749+
}
750+
751+
close(s);
752+
753+
return err;
754+
}
755+
698756
void veth2tap_fun(std::shared_ptr<hostif_info_t> info)
699757
{
700758
SWSS_LOG_ENTER();
@@ -812,6 +870,24 @@ bool hostif_create_tap_veth_forwarding(
812870

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

873+
if (ifup(vethname.c_str()))
874+
{
875+
SWSS_LOG_ERROR("ifup failed on %s", vethname.c_str());
876+
877+
close(packet_socket);
878+
879+
return false;
880+
}
881+
882+
if (promisc(vethname.c_str()))
883+
{
884+
SWSS_LOG_ERROR("promisc failed on %s", vethname.c_str());
885+
886+
close(packet_socket);
887+
888+
return false;
889+
}
890+
815891
if (bind(packet_socket, (struct sockaddr*) &sock_address, sizeof(sock_address)) < 0)
816892
{
817893
SWSS_LOG_ERROR("bind failed on %s", vethname.c_str());

0 commit comments

Comments
 (0)