MTU: set interface mtu tap 90/890/2
authorMohsin Kazmi <sykazmi@cisco.com>
Sun, 24 Apr 2016 16:53:42 +0000 (18:53 +0200)
committerDamjan Marion <damarion@cisco.com>
Tue, 26 Apr 2016 16:43:30 +0000 (16:43 +0000)
This patch introduces standard command line 'set interface mtu' for setting the MTU
for tap devices. It allows user to set the mtu in between 68 to 65535 bytes
aligned to what linux kernel supports for tun/tap devices.

Right now tapcli set the same MTU size for each tap interface. But it should be set
and configure to per interface rather than per tap instance.

Change-Id: I81b7f3ad95ca56d585907ff8f51d9935a428e01b
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
vnet/vnet/ethernet/interface.c
vnet/vnet/interface.h
vnet/vnet/interface_cli.c
vnet/vnet/unix/tapcli.c
vnet/vnet/unix/tapcli.h

index 6bc9f28..833ee30 100644 (file)
@@ -181,8 +181,8 @@ ethernet_register_interface (vnet_main_t * vnm,
 
   ethernet_setup_node (vnm->vlib_main, hi->output_node_index);
 
-  hi->min_packet_bytes = ETHERNET_MIN_PACKET_BYTES;
-  hi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
+  hi->min_packet_bytes = hi->min_supported_packet_bytes = ETHERNET_MIN_PACKET_BYTES;
+  hi->max_packet_bytes = hi->max_supported_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
   hi->per_packet_overhead_bytes =
     /* preamble */ 8 + /* inter frame gap */ 12;
 
index fdf23a6..2829a0c 100644 (file)
@@ -292,6 +292,12 @@ typedef struct vnet_hw_interface_t {
   /* Maximum transmit rate for this interface in bits/sec. */
   f64 max_rate_bits_per_sec;
 
+  /* Smallest packet size supported by this interface. */
+  u32 min_supported_packet_bytes;
+
+  /* Largest packet size supported by this interface. */
+  u32 max_supported_packet_bytes;
+
   /* Smallest packet size for this interface. */
   u32 min_packet_bytes;
 
index 31fc9c3..13a7d8c 100644 (file)
@@ -851,13 +851,14 @@ mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
       if (!eif)
         return clib_error_return (0, "not supported");
 
-      if (mtu < ETHERNET_MIN_PACKET_BYTES)
+      if (mtu < hi->min_supported_packet_bytes)
        return clib_error_return (0, "Invalid mtu (%d): "
                                  "must be >= min pkt bytes (%d)", mtu,
-                                 hi->min_packet_bytes);
+                                 hi->min_supported_packet_bytes);
 
-      if (mtu > ETHERNET_MAX_PACKET_BYTES)
-       return clib_error_return (0, "Invalid mtu (%d): must be <= 9216", mtu);
+      if (mtu > hi->max_supported_packet_bytes)
+       return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
+                                  hi->max_supported_packet_bytes);
 
       if (hi->max_packet_bytes != mtu)
        {
@@ -873,7 +874,7 @@ mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
 
 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
   .path = "set interface mtu",
-  .short_help = "set interface mtu <64-9216> <intfc>",
+  .short_help = "set interface mtu <value> <intfc>",
   .function = mtu_cmd,
 };
 
index d17d09d..596f8d1 100644 (file)
@@ -515,39 +515,48 @@ static u32 tapcli_flag_change (vnet_main_t * vnm,
 {
   tapcli_main_t *tm = &tapcli_main;
   tapcli_interface_t *ti;
-  struct ifreq ifr;
-  u32 want_promisc;
-
-  ti = vec_elt_at_index (tm->tapcli_interfaces, hw->dev_instance);
 
-  clib_memcpy (&ifr, &ti->ifr, sizeof (ifr));
+   ti = vec_elt_at_index (tm->tapcli_interfaces, hw->dev_instance);
 
-  /* get flags, modify to bring up interface... */
-  if (ioctl (ti->provision_fd, SIOCGIFFLAGS, &ifr) < 0)
+  if (flags & ETHERNET_INTERFACE_FLAG_MTU)
     {
-      clib_unix_warning ("Couldn't get interface flags for %s", hw->name);
-      return 0;
+      const uword buffer_size = VLIB_BUFFER_DATA_SIZE;
+      tm->mtu_bytes = hw->max_packet_bytes;
+      tm->mtu_buffers = (tm->mtu_bytes + (buffer_size - 1)) / buffer_size;
     }
+   else
+    {
+      struct ifreq ifr;
+      u32 want_promisc;
 
-  want_promisc = (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) != 0;
+      memcpy (&ifr, &ti->ifr, sizeof (ifr));
 
-  if (want_promisc == ti->is_promisc)
-    return 0;
+      /* get flags, modify to bring up interface... */
+      if (ioctl (ti->provision_fd, SIOCGIFFLAGS, &ifr) < 0)
+        {
+          clib_unix_warning ("Couldn't get interface flags for %s", hw->name);
+          return 0;
+        }
 
+      want_promisc = (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) != 0;
 
-  if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL)
-    ifr.ifr_flags |= IFF_PROMISC;
-  else
-    ifr.ifr_flags &= ~(IFF_PROMISC);
+      if (want_promisc == ti->is_promisc)
+        return 0;
 
-  /* get flags, modify to bring up interface... */
-  if (ioctl (ti->provision_fd, SIOCSIFFLAGS, &ifr) < 0)
-    {
-      clib_unix_warning ("Couldn't set interface flags for %s", hw->name);
-      return 0;
-    }
+      if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL)
+        ifr.ifr_flags |= IFF_PROMISC;
+      else
+        ifr.ifr_flags &= ~(IFF_PROMISC);
 
-  ti->is_promisc = want_promisc;
+      /* get flags, modify to bring up interface... */
+      if (ioctl (ti->provision_fd, SIOCSIFFLAGS, &ifr) < 0)
+        {
+          clib_unix_warning ("Couldn't set interface flags for %s", hw->name);
+          return 0;
+        }
+
+      ti->is_promisc = want_promisc;
+    }
 
   return 0;
 }
@@ -788,7 +797,9 @@ int vnet_tap_connect (vlib_main_t * vm, u8 * intfc_name, u8 *hwaddr_arg,
   {
     vnet_hw_interface_t * hw;
     hw = vnet_get_hw_interface (tm->vnet_main, ti->hw_if_index);
-    hw->max_l3_packet_bytes[VLIB_RX] = hw->max_l3_packet_bytes[VLIB_TX] = tm->mtu_bytes - sizeof(ethernet_header_t);
+    hw->min_supported_packet_bytes = TAP_MTU_MIN;
+    hw->max_supported_packet_bytes = TAP_MTU_MAX;
+    hw->max_l3_packet_bytes[VLIB_RX] = hw->max_l3_packet_bytes[VLIB_TX] = hw->max_supported_packet_bytes - sizeof(ethernet_header_t);
     ti->sw_if_index = hw->sw_if_index;
     if (sw_if_indexp)
       *sw_if_indexp = hw->sw_if_index;
@@ -1149,7 +1160,9 @@ tap_connect_command_fn (vlib_main_t * vm,
     vnet_hw_interface_t * hw;
     hw = vnet_get_hw_interface (tm->vnet_main, ti->hw_if_index);
     ti->sw_if_index = hw->sw_if_index;
-    hw->max_l3_packet_bytes[VLIB_RX] = hw->max_l3_packet_bytes[VLIB_TX] = tm->mtu_bytes - sizeof(ethernet_header_t);
+    hw->min_supported_packet_bytes = TAP_MTU_MIN;
+    hw->max_supported_packet_bytes = TAP_MTU_MAX;
+    hw->max_l3_packet_bytes[VLIB_RX] = hw->max_l3_packet_bytes[VLIB_TX] = hw->max_supported_packet_bytes - sizeof(ethernet_header_t);
   }
 
   ti->active = 1;
@@ -1187,7 +1200,7 @@ tapcli_init (vlib_main_t * vm)
   tm->vlib_main = vm;
   tm->vnet_main = vnet_get_main();
   tm->unix_main = &unix_main;
-  tm->mtu_bytes = 4096 + 256;
+  tm->mtu_bytes = TAP_MTU_DEFAULT;
   tm->tapcli_interface_index_by_sw_if_index = hash_create (0, sizeof(uword));
   tm->tapcli_interface_index_by_unix_fd = hash_create (0, sizeof (uword));
   tm->rx_buffers = 0;
index 00a96c6..76580bf 100644 (file)
@@ -38,4 +38,8 @@ typedef struct {
 
 int vnet_tap_dump_ifs (tapcli_interface_details_t **out_tapids);
 
+#define TAP_MTU_MIN 68
+#define TAP_MTU_MAX 65535
+#define TAP_MTU_DEFAULT 1500
+
 #endif /* __included_tapcli_h__ */