ip: mark IP_ADDRESS_DUMP as mp-safe
[vpp.git] / src / vnet / ethernet / ethernet.h
index 2e5209c..858400d 100644 (file)
@@ -43,7 +43,6 @@
 #include <vnet/vnet.h>
 #include <vnet/ethernet/packet.h>
 #include <vnet/ethernet/mac_address.h>
-#include <vnet/pg/pg.h>
 #include <vnet/feature/feature.h>
 
 /* ethernet-input frame flags and scalar data */
@@ -129,34 +128,58 @@ struct vnet_hw_interface_t;
 typedef u32 (ethernet_flag_change_function_t)
   (vnet_main_t * vnm, struct vnet_hw_interface_t * hi, u32 flags);
 
+typedef struct
+{
+  /* ethernet interface flags change */
+  ethernet_flag_change_function_t *flag_change;
+
+  /* set Max Frame Size callback */
+  vnet_interface_set_max_frame_size_function_t *set_max_frame_size;
+} vnet_eth_if_callbacks_t;
+
 #define ETHERNET_MIN_PACKET_BYTES  64
 #define ETHERNET_MAX_PACKET_BYTES  9216
 
+/* ethernet dataplane loads mac address as u64 for efficiency */
+typedef union ethernet_interface_address
+{
+  struct
+  {
+    mac_address_t mac;
+    u16 zero;
+  };
+  u64 as_u64;
+} ethernet_interface_address_t;
+
 /* Ethernet interface instance. */
 typedef struct ethernet_interface
 {
   u32 flags;
 
-  /* Accept all packets (promiscuous mode). */
-#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL (1 << 0)
-#define ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC(flags) \
-  (((flags) & ~ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) == 0)
+  /* Top 16 bits for status and bottom 16 bits for set operation */
+#define ETHERNET_INTERFACE_FLAGS_STATUS_MASK  (0xffff0000)
+#define ETHERNET_INTERFACE_FLAGS_SET_OPN_MASK (0x0000ffff)
+
+  /* Interface driver/hw is in L3/non-promiscuous mode so packet DMAC
+     would already be filtered */
+#define ETHERNET_INTERFACE_FLAG_STATUS_L3 (1 << 16)
+
+  /* Set interface to default L3 mode */
+#define ETHERNET_INTERFACE_FLAG_DEFAULT_L3 0
 
-  /* Change MTU on interface from hw interface structure */
-#define ETHERNET_INTERFACE_FLAG_MTU (1 << 1)
-#define ETHERNET_INTERFACE_FLAG_CONFIG_MTU(flags) \
-  ((flags) & ETHERNET_INTERFACE_FLAG_MTU)
+  /* Set interface to accept all packets (promiscuous mode). */
+#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL 1
 
   /* Callback, e.g. to turn on/off promiscuous mode */
-  ethernet_flag_change_function_t *flag_change;
+  vnet_eth_if_callbacks_t cb;
 
   u32 driver_instance;
 
   /* Ethernet (MAC) address for this interface. */
-  u8 address[6];
+  ethernet_interface_address_t address;
 
   /* Secondary MAC addresses for this interface */
-  mac_address_t *secondary_addrs;
+  ethernet_interface_address_t *secondary_addrs;
 } ethernet_interface_t;
 
 extern vnet_hw_interface_class_t ethernet_hw_interface_class;
@@ -315,6 +338,9 @@ typedef struct ethernet_main_t_
   /** 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;
@@ -333,14 +359,6 @@ mac_address_t *ethernet_interface_add_del_address (ethernet_main_t * em,
                                                   const u8 * address,
                                                   u8 is_add);
 
-clib_error_t *ethernet_register_interface (vnet_main_t * vnm,
-                                          u32 dev_class_index,
-                                          u32 dev_instance,
-                                          const u8 * address,
-                                          u32 * hw_if_index_return,
-                                          ethernet_flag_change_function_t
-                                          flag_change);
-
 void ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index);
 
 /* Register given node index to take input for given ethernet type. */
@@ -383,16 +401,7 @@ uword unformat_ethernet_interface (unformat_input_t * input, va_list * args);
 
 uword unformat_pg_ethernet_header (unformat_input_t * input, va_list * args);
 
-always_inline void
-ethernet_setup_node (vlib_main_t * vm, u32 node_index)
-{
-  vlib_node_t *n = vlib_get_node (vm, node_index);
-  pg_node_t *pn = pg_get_node (node_index);
-
-  n->format_buffer = format_ethernet_header_with_length;
-  n->unformat_buffer = unformat_ethernet_header;
-  pn->unformat_edit = unformat_pg_ethernet_header;
-}
+void ethernet_setup_node (vlib_main_t *vm, u32 node_index);
 
 always_inline ethernet_header_t *
 ethernet_buffer_get_header (vlib_buffer_t * b)
@@ -563,6 +572,18 @@ vnet_get_ethernet_main (void)
   return &ethernet_main;
 }
 
+typedef struct
+{
+  u32 dev_class_index;
+  u32 dev_instance;
+  u16 max_frame_size;
+  u16 frame_overhead;
+  vnet_eth_if_callbacks_t cb;
+  const u8 *address;
+} vnet_eth_interface_registration_t;
+
+u32 vnet_eth_register_interface (vnet_main_t *vnm,
+                                vnet_eth_interface_registration_t *r);
 void ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai);
 u8 *ethernet_build_rewrite (vnet_main_t * vnm,
                            u32 sw_if_index,