af_packet: support changing the mtu size 95/6695/5
authorRay Kinsella <ray.kinsella@intel.com>
Mon, 15 May 2017 10:52:43 +0000 (11:52 +0100)
committerNeale Ranns <nranns@cisco.com>
Mon, 15 May 2017 18:20:30 +0000 (18:20 +0000)
Added support to the af_packet device to change the MTU size.

Change-Id: I9c9e1e17323721f3efccf70a10b753e12eef94d5
Signed-off-by: Ray Kinsella <ray.kinsella@intel.com>
src/vnet/devices/af_packet/af_packet.c

index cb52e6d..ea52878 100644 (file)
@@ -20,6 +20,9 @@
 #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 <vlib/vlib.h>
 #include <vlib/unix/unix.h>
@@ -61,7 +64,26 @@ 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 = vlib_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;
 }