@@ -681,6 +681,13 @@ int ifup(const char *dev)
681
681
return err;
682
682
}
683
683
684
+ if (ifr.ifr_flags & IFF_UP)
685
+ {
686
+ close (s);
687
+
688
+ return 0 ;
689
+ }
690
+
684
691
ifr.ifr_flags |= IFF_UP;
685
692
686
693
err = ioctl (s, SIOCSIFFLAGS, &ifr);
@@ -695,6 +702,57 @@ int ifup(const char *dev)
695
702
return err;
696
703
}
697
704
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
+
698
756
void veth2tap_fun (std::shared_ptr<hostif_info_t > info)
699
757
{
700
758
SWSS_LOG_ENTER ();
@@ -812,6 +870,24 @@ bool hostif_create_tap_veth_forwarding(
812
870
813
871
SWSS_LOG_INFO (" interface index = %d %s\n " , sock_address.sll_ifindex , vethname.c_str ());
814
872
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
+
815
891
if (bind (packet_socket, (struct sockaddr *) &sock_address, sizeof (sock_address)) < 0 )
816
892
{
817
893
SWSS_LOG_ERROR (" bind failed on %s" , vethname.c_str ());
0 commit comments