ethernet: configure system default ethernet MTU

Type: feature
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I9c2081c56cfbf61df7e5170002f5f65902f49942
diff --git a/src/vnet/ethernet/ethernet.h b/src/vnet/ethernet/ethernet.h
index 2e5209c..2f544bb 100644
--- a/src/vnet/ethernet/ethernet.h
+++ b/src/vnet/ethernet/ethernet.h
@@ -315,6 +315,9 @@
   /** Functions to call when interface hw address changes. */
   ethernet_address_change_ctx_t *address_change_callbacks;
 
+  /** Default interface MTU */
+  u32 default_mtu;
+
 } ethernet_main_t;
 
 extern ethernet_main_t ethernet_main;
diff --git a/src/vnet/ethernet/init.c b/src/vnet/ethernet/init.c
index 9fd95f1..f78b65c 100644
--- a/src/vnet/ethernet/init.c
+++ b/src/vnet/ethernet/init.c
@@ -88,6 +88,11 @@
 
   em->type_info_by_name = hash_create_string (0, sizeof (uword));
   em->type_info_by_type = hash_create (0, sizeof (uword));
+  /*
+   * System default ethernet interface MTU, configure via ethernet_config in
+   * interface.c if desired.
+   */
+  em->default_mtu = 9000;
 
 #define ethernet_type(n,s) add_type (em, ETHERNET_TYPE_##s, #s);
 #include "types.def"
diff --git a/src/vnet/ethernet/interface.c b/src/vnet/ethernet/interface.c
index 39e5cfb..3b9093c 100644
--- a/src/vnet/ethernet/interface.c
+++ b/src/vnet/ethernet/interface.c
@@ -359,8 +359,8 @@
   hi->max_packet_bytes = hi->max_supported_packet_bytes =
     ETHERNET_MAX_PACKET_BYTES;
 
-  /* Standard default ethernet MTU. */
-  vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, 9000);
+  /* Default ethernet MTU, 9000 unless set by ethernet_config see below */
+  vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, em->default_mtu);
 
   clib_memcpy (ei->address, address, sizeof (ei->address));
   vec_add (hi->hw_address, address, sizeof (ei->address));
@@ -1192,6 +1192,29 @@
 };
 /* *INDENT-ON* */
 
+static clib_error_t *
+ethernet_config (vlib_main_t * vm, unformat_input_t * input)
+{
+  ethernet_main_t *em = &ethernet_main;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "default-mtu %u", &em->default_mtu))
+	{
+	  if (em->default_mtu < 64 || em->default_mtu > 9000)
+	    return clib_error_return (0, "default MTU must be >=64, <=9000");
+	}
+      else
+	{
+	  return clib_error_return (0, "unknown input '%U'",
+				    format_unformat_error, input);
+	}
+    }
+  return 0;
+}
+
+VLIB_CONFIG_FUNCTION (ethernet_config, "ethernet");
+
 /*
  * fd.io coding-style-patch-verification: ON
  *