Add extern to *_main global variable declarations in header files.
[vpp.git] / src / vnet / devices / af_packet / af_packet.c
index fbcd488..d0a241e 100644 (file)
@@ -23,7 +23,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
-#include <linux/virtio_net.h>
 
 #include <vppinfra/linux/sysfs.h>
 #include <vlib/vlib.h>
@@ -33,6 +32,8 @@
 
 #include <vnet/devices/af_packet/af_packet.h>
 
+af_packet_main_t af_packet_main;
+
 #define AF_PACKET_DEBUG_SOCKET         0
 
 #define AF_PACKET_TX_FRAMES_PER_BLOCK  1024
@@ -129,7 +130,6 @@ static int
 create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req,
                       tpacket_req_t * tx_req, int *fd, u8 ** ring)
 {
-  af_packet_main_t *apm = &af_packet_main;
   int ret, err;
   struct sockaddr_ll sll;
   int ver = TPACKET_V2;
@@ -143,31 +143,7 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req,
       ret = VNET_API_ERROR_SYSCALL_ERROR_1;
       goto error;
     }
-  int opt = 1;
-  if (setsockopt (*fd, SOL_PACKET, PACKET_VNET_HDR, &opt, sizeof (opt)) != 0)
-    {
-      DBG_SOCK ("Failed to enable vnet headers on the socket");
-      if ((apm->flags & AF_PACKET_USES_VNET_HEADERS) != 0)
-       {
-         /* Should never happen - vnet was already enabled once,
-          * but we fail to reenable it on a new interface
-          **/
-         ret = VNET_API_ERROR_SYSCALL_ERROR_1;
-         goto error;
-       }
-    }
-  else
-    {
-      apm->flags |= AF_PACKET_USES_VNET_HEADERS;
-    }
-#ifdef PACKET_QDISC_BYPASS
-  opt = 1;
-  if (setsockopt (*fd, SOL_PACKET, PACKET_QDISC_BYPASS, &opt, sizeof (opt)) !=
-      0)
-    {
-      DBG_SOCK ("Failed to bypass Linux QDISC");
-    }
-#endif
+
   if ((err =
        setsockopt (*fd, SOL_PACKET, PACKET_VERSION, &ver, sizeof (ver))) < 0)
     {
@@ -176,7 +152,7 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req,
       goto error;
     }
 
-  opt = 1;
+  int opt = 1;
   if ((err =
        setsockopt (*fd, SOL_PACKET, PACKET_LOSS, &opt, sizeof (opt))) < 0)
     {
@@ -432,6 +408,22 @@ af_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
   return 0;
 }
 
+int
+af_packet_set_l4_cksum_offload (vlib_main_t * vm, u32 sw_if_index, u8 set)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_hw_interface_t *hw;
+
+  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
+
+  if (set)
+    hw->flags &= ~VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
+  else
+    hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
+
+  return 0;
+}
+
 static clib_error_t *
 af_packet_init (vlib_main_t * vm)
 {