hs-test: cache docker build in local filesystem
[vpp.git] / src / vnet / ethernet / ethernet.h
index fb7e2c5..858400d 100644 (file)
 
 #include <vnet/vnet.h>
 #include <vnet/ethernet/packet.h>
-#include <vnet/pg/pg.h>
+#include <vnet/ethernet/mac_address.h>
 #include <vnet/feature/feature.h>
 
-always_inline u64
-ethernet_mac_address_u64 (u8 * a)
-{
-  return (((u64) a[0] << (u64) (5 * 8))
-         | ((u64) a[1] << (u64) (4 * 8))
-         | ((u64) a[2] << (u64) (3 * 8))
-         | ((u64) a[3] << (u64) (2 * 8))
-         | ((u64) a[4] << (u64) (1 * 8)) | ((u64) a[5] << (u64) (0 * 8)));
-}
+/* ethernet-input frame flags and scalar data */
 
-static inline int
-ethernet_mac_address_is_multicast_u64 (u64 a)
-{
-  return (a & (1ULL << (5 * 8))) != 0;
-}
+/* all packets in frame share same sw_if_index */
+#define ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX (1 << 0)
 
-static inline int
-ethernet_mac_address_is_zero (u8 * mac)
+/* all ip4 packets in frame have correct ip4 checksum */
+#define ETH_INPUT_FRAME_F_IP4_CKSUM_OK (1 << 1)
+
+typedef struct
 {
-  return ((*((u32 *) mac) == 0) && (*((u16 *) (mac + 4)) == 0));
-}
+  u32 sw_if_index;
+  u32 hw_if_index;
+} ethernet_input_frame_t;
 
 #ifdef CLIB_HAVE_VEC128
 static const u16x8 tagged_ethertypes = {
@@ -136,30 +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;
+
+  /* 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)
 
-  /* 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)
+  /* Interface driver/hw is in L3/non-promiscuous mode so packet DMAC
+     would already be filtered */
+#define ETHERNET_INTERFACE_FLAG_STATUS_L3 (1 << 16)
 
-  /* 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 default L3 mode */
+#define ETHERNET_INTERFACE_FLAG_DEFAULT_L3 0
+
+  /* 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 */
+  ethernet_interface_address_t *secondary_addrs;
 } ethernet_interface_t;
 
 extern vnet_hw_interface_class_t ethernet_hw_interface_class;
@@ -260,7 +280,18 @@ typedef struct
   u32 input_next_mpls;
 } next_by_ethertype_t;
 
+struct ethernet_main_t_;
+
+typedef void (ethernet_address_change_function_t)
+  (struct ethernet_main_t_ * im, u32 sw_if_index, uword opaque);
+
 typedef struct
+{
+  ethernet_address_change_function_t *function;
+  uword function_opaque;
+} ethernet_address_change_ctx_t;
+
+typedef struct ethernet_main_t_
 {
   vlib_main_t *vlib_main;
 
@@ -303,6 +334,13 @@ typedef struct
 
   /* Allocated loopback instances */
   uword *bm_loopback_instances;
+
+  /** 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;
@@ -316,14 +354,10 @@ ethernet_get_type_info (ethernet_main_t * em, ethernet_type_t type)
 
 ethernet_interface_t *ethernet_get_interface (ethernet_main_t * em,
                                              u32 hw_if_index);
-
-clib_error_t *ethernet_register_interface (vnet_main_t * vnm,
-                                          u32 dev_class_index,
-                                          u32 dev_instance,
-                                          u8 * address,
-                                          u32 * hw_if_index_return,
-                                          ethernet_flag_change_function_t
-                                          flag_change);
+mac_address_t *ethernet_interface_add_del_address (ethernet_main_t * em,
+                                                  u32 hw_if_index,
+                                                  const u8 * address,
+                                                  u8 is_add);
 
 void ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index);
 
@@ -339,6 +373,7 @@ void ethernet_register_l2_input (vlib_main_t * vm, u32 node_index);
 void ethernet_register_l3_redirect (vlib_main_t * vm, u32 node_index);
 
 /* Formats ethernet address X:X:X:X:X:X */
+u8 *format_mac_address (u8 * s, va_list * args);
 u8 *format_ethernet_address (u8 * s, va_list * args);
 u8 *format_ethernet_type (u8 * s, va_list * args);
 u8 *format_ethernet_vlan_tci (u8 * s, va_list * va);
@@ -347,6 +382,7 @@ u8 *format_ethernet_header_with_length (u8 * s, va_list * args);
 
 /* Parse ethernet address in either X:X:X:X:X:X unix or X.X.X cisco format. */
 uword unformat_ethernet_address (unformat_input_t * input, va_list * args);
+uword unformat_mac_address (unformat_input_t * input, va_list * args);
 
 /* Parse ethernet type as 0xXXXX or type name from ethernet/types.def.
    In either host or network byte order. */
@@ -365,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)
@@ -435,17 +462,6 @@ void ethernet_sw_interface_set_l2_mode_noport (vnet_main_t * vnm,
 void ethernet_set_rx_redirect (vnet_main_t * vnm, vnet_hw_interface_t * hi,
                               u32 enable);
 
-int
-vnet_arp_set_ip4_over_ethernet (vnet_main_t * vnm,
-                               u32 sw_if_index, void *a_arg,
-                               int is_static, int is_no_fib_entry);
-
-int
-vnet_arp_unset_ip4_over_ethernet (vnet_main_t * vnm,
-                                 u32 sw_if_index, void *a_arg);
-
-int vnet_proxy_arp_fib_reset (u32 fib_id);
-
 clib_error_t *next_by_ethertype_init (next_by_ethertype_t * l3_next);
 clib_error_t *next_by_ethertype_register (next_by_ethertype_t * l3_next,
                                          u32 ethertype, u32 next_index);
@@ -453,6 +469,9 @@ clib_error_t *next_by_ethertype_register (next_by_ethertype_t * l3_next,
 int vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address,
                                    u8 is_specified, u32 user_instance);
 int vnet_delete_loopback_interface (u32 sw_if_index);
+int vnet_create_sub_interface (u32 sw_if_index, u32 id,
+                              u32 flags, u16 inner_vlan_id,
+                              u16 outer_vlan_id, u32 * sub_sw_if_index);
 int vnet_delete_sub_interface (u32 sw_if_index);
 
 // Perform ethernet subinterface classification table lookups given
@@ -499,7 +518,6 @@ eth_vlan_table_lookups (ethernet_main_t * em,
 // Returns 1 if a matching subinterface was found, otherwise returns 0.
 always_inline u32
 eth_identify_subint (vnet_hw_interface_t * hi,
-                    vlib_buffer_t * b0,
                     u32 match_flags,
                     main_intf_t * main_intf,
                     vlan_intf_t * vlan_intf,
@@ -526,13 +544,13 @@ eth_identify_subint (vnet_hw_interface_t * hi,
   if ((subint->flags & match_flags) == match_flags)
     goto matched;
 
-  // check for untagged interface
-  subint = &main_intf->untagged_subint;
+  // check for default interface
+  subint = &main_intf->default_subint;
   if ((subint->flags & match_flags) == match_flags)
     goto matched;
 
-  // check for default interface
-  subint = &main_intf->default_subint;
+  // check for untagged interface
+  subint = &main_intf->untagged_subint;
   if ((subint->flags & match_flags) == match_flags)
     goto matched;
 
@@ -548,58 +566,32 @@ matched:
   return 1;
 }
 
-// Compare two ethernet macs. Return 1 if they are the same, 0 if different
-always_inline u32
-eth_mac_equal (u8 * mac1, u8 * mac2)
-{
-  return (*((u32 *) (mac1 + 0)) == *((u32 *) (mac2 + 0)) &&
-         *((u32 *) (mac1 + 2)) == *((u32 *) (mac2 + 2)));
-}
-
-
 always_inline ethernet_main_t *
 vnet_get_ethernet_main (void)
 {
   return &ethernet_main;
 }
 
-void vnet_register_ip4_arp_resolution_event (vnet_main_t * vnm,
-                                            void *address_arg,
-                                            uword node_index,
-                                            uword type_opaque, uword data);
-
-
-int vnet_add_del_ip4_arp_change_event (vnet_main_t * vnm,
-                                      void *data_callback,
-                                      u32 pid,
-                                      void *address_arg,
-                                      uword node_index,
-                                      uword type_opaque,
-                                      uword data, int is_add);
-
-void wc_arp_set_publisher_node (uword inode_index, uword event_type);
-
-void ethernet_arp_change_mac (u32 sw_if_index);
-void ethernet_ndp_change_mac (u32 sw_if_index);
-
-void arp_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai);
-
+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,
                            vnet_link_t link_type, const void *dst_address);
-const u8 *ethernet_ip4_mcast_dst_addr (void);
-const u8 *ethernet_ip6_mcast_dst_addr (void);
+void ethernet_input_init (vlib_main_t * vm, ethernet_main_t * em);
 
 extern vlib_node_registration_t ethernet_input_node;
 
-typedef struct
-{
-  u32 sw_if_index;
-  u32 ip4;
-  u8 mac[6];
-} wc_arp_report_t;
-
 #endif /* included_ethernet_h */
 
 /*