Add extern to *_main global variable declarations in header files.
[vpp.git] / src / vnet / devices / af_packet / af_packet.c
index cb52e6d..d0a241e 100644 (file)
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
 #include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
 
+#include <vppinfra/linux/sysfs.h>
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
 #include <vnet/ip/ip.h>
@@ -28,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
@@ -61,12 +67,31 @@ static u32
 af_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
                           u32 flags)
 {
-  /* nothing for now */
+  clib_error_t *error;
+  u8 *s;
+  af_packet_main_t *apm = &af_packet_main;
+  af_packet_if_t *apif =
+    pool_elt_at_index (apm->interfaces, hi->dev_instance);
+
+  if (ETHERNET_INTERFACE_FLAG_MTU == (flags & ETHERNET_INTERFACE_FLAG_MTU))
+    {
+      s = format (0, "/sys/class/net/%s/mtu%c", apif->host_if_name, 0);
+
+      error = clib_sysfs_write ((char *) s, "%d", hi->max_packet_bytes);
+      vec_free (s);
+
+      if (error)
+       {
+         clib_error_report (error);
+         return VNET_API_ERROR_SYSCALL_ERROR_1;
+       }
+    }
+
   return 0;
 }
 
 static clib_error_t *
-af_packet_fd_read_ready (unix_file_t * uf)
+af_packet_fd_read_ready (clib_file_t * uf)
 {
   af_packet_main_t *apm = &af_packet_main;
   vnet_main_t *vnm = vnet_get_main ();
@@ -258,12 +283,12 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
     clib_spinlock_init (&apif->lockp);
 
   {
-    unix_file_t template = { 0 };
+    clib_file_t template = { 0 };
     template.read_function = af_packet_fd_read_ready;
     template.file_descriptor = fd;
     template.private_data = if_index;
     template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED;
-    apif->unix_file_index = unix_file_add (&unix_main, &template);
+    apif->clib_file_index = clib_file_add (&file_main, &template);
   }
 
   /*use configured or generate random MAC address */
@@ -348,10 +373,10 @@ af_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
   vnet_hw_interface_unassign_rx_thread (vnm, apif->hw_if_index, 0);
 
   /* clean up */
-  if (apif->unix_file_index != ~0)
+  if (apif->clib_file_index != ~0)
     {
-      unix_file_del (&unix_main, unix_main.file_pool + apif->unix_file_index);
-      apif->unix_file_index = ~0;
+      clib_file_del (&file_main, file_main.file_pool + apif->clib_file_index);
+      apif->clib_file_index = ~0;
     }
   else
     close (apif->fd);
@@ -383,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)
 {