span: fix wrong next1 feature index in dual loop
[vpp.git] / vnet / vnet / interface.h
index 7738bb6..5ac7fbd 100644 (file)
 #define included_vnet_interface_h
 
 #include <vnet/unix/pcap.h>
+#include <vnet/l3_types.h>
 
 struct vnet_main_t;
 struct vnet_hw_interface_t;
 struct vnet_sw_interface_t;
+struct ip46_address_t;
 
 /* Interface up/down callback. */
 typedef clib_error_t *(vnet_interface_function_t)
@@ -55,6 +57,17 @@ typedef clib_error_t *(vnet_subif_add_del_function_t)
   (struct vnet_main_t * vnm, u32 if_index,
    struct vnet_sw_interface_t * template, int is_add);
 
+/* Interface set mac address callback. */
+typedef clib_error_t *(vnet_interface_set_mac_address_function_t)
+  (struct vnet_hw_interface_t * hi, char *address);
+
+typedef enum vnet_interface_function_priority_t_
+{
+  VNET_ITF_FUNC_PRIORITY_LOW,
+  VNET_ITF_FUNC_PRIORITY_HIGH,
+} vnet_interface_function_priority_t;
+#define VNET_ITF_FUNC_N_PRIO ((vnet_interface_function_priority_t)VNET_ITF_FUNC_PRIORITY_HIGH+1)
+
 typedef struct _vnet_interface_function_list_elt
 {
   struct _vnet_interface_function_list_elt *next_interface_function;
@@ -70,8 +83,23 @@ static void __vnet_interface_function_init_##tag##_##f (void)           \
 {                                                                       \
  vnet_main_t * vnm = vnet_get_main();                                   \
  static _vnet_interface_function_list_elt_t init_function;              \
- init_function.next_interface_function = vnm->tag##_functions;          \
- vnm->tag##_functions = &init_function;                                 \
+ init_function.next_interface_function =                                \
+   vnm->tag##_functions[VNET_ITF_FUNC_PRIORITY_LOW];                    \
+ vnm->tag##_functions[VNET_ITF_FUNC_PRIORITY_LOW] = &init_function;     \
+ init_function.fp = (void *) &f;                                        \
+}
+
+#define _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,tag,p)                    \
+                                                                        \
+static void __vnet_interface_function_init_##tag##_##f (void)           \
+    __attribute__((__constructor__)) ;                                  \
+                                                                        \
+static void __vnet_interface_function_init_##tag##_##f (void)           \
+{                                                                       \
+ vnet_main_t * vnm = vnet_get_main();                                   \
+ static _vnet_interface_function_list_elt_t init_function;              \
+ init_function.next_interface_function = vnm->tag##_functions[p];       \
+ vnm->tag##_functions[p] = &init_function;                              \
  init_function.fp = (void *) &f;                                        \
 }
 
@@ -79,10 +107,14 @@ static void __vnet_interface_function_init_##tag##_##f (void)           \
   _VNET_INTERFACE_FUNCTION_DECL(f,hw_interface_add_del)
 #define VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION(f)             \
   _VNET_INTERFACE_FUNCTION_DECL(f,hw_interface_link_up_down)
+#define VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION_PRIO(f,p)        \
+  _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,hw_interface_link_up_down,p)
 #define VNET_SW_INTERFACE_ADD_DEL_FUNCTION(f)                  \
   _VNET_INTERFACE_FUNCTION_DECL(f,sw_interface_add_del)
 #define VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(f)            \
   _VNET_INTERFACE_FUNCTION_DECL(f,sw_interface_admin_up_down)
+#define VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION_PRIO(f,p)             \
+  _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,sw_interface_admin_up_down, p)
 
 /* A class of hardware interface devices. */
 typedef struct _vnet_device_class
@@ -151,6 +183,8 @@ typedef struct _vnet_device_class
   /* Do not splice vnet_interface_output_node into TX path */
   u8 no_flatten_output_chains;
 
+  /* Function to set mac address. */
+  vnet_interface_set_mac_address_function_t *mac_addr_change_function;
 } vnet_device_class_t;
 
 #define VNET_DEVICE_CLASS(x,...)                                        \
@@ -190,6 +224,53 @@ __VA_ARGS__ vnet_device_class_t x
   { dev.tx_function = fn ## _multiarch_select(); }
 #endif
 
+/**
+ * Link Type: A description of the protocol of packets on the link.
+ * On an ethernet link this maps directly into the ethertype. On a GRE tunnel
+ * it maps to the GRE-proto, etc for other lnk types.
+ */
+typedef enum vnet_link_t_
+{
+#if CLIB_DEBUG > 0
+  VNET_LINK_IP4 = 1,
+#else
+  VNET_LINK_IP4 = 0,
+#endif
+  VNET_LINK_IP6,
+  VNET_LINK_MPLS,
+  VNET_LINK_ETHERNET,
+  VNET_LINK_ARP,
+} __attribute__ ((packed)) vnet_link_t;
+
+#define VNET_LINKS {                   \
+    [VNET_LINK_ETHERNET] = "ethernet", \
+    [VNET_LINK_IP4] = "ipv4",          \
+    [VNET_LINK_IP6] = "ipv6",          \
+    [VNET_LINK_MPLS] = "mpls",         \
+    [VNET_LINK_ARP] = "arp",          \
+}
+
+/**
+ * @brief Number of link types. Not part of the enum so it does not have to be included in
+ * switch statements
+ */
+#define VNET_LINK_NUM (VNET_LINK_ARP+1)
+
+/**
+ * @brief Convert a link to to an Ethertype
+ */
+extern vnet_l3_packet_type_t vnet_link_to_l3_proto (vnet_link_t link);
+
+/**
+ * @brief Attributes assignable to a HW interface Class.
+ */
+typedef enum vnet_hw_interface_class_flags_t_
+{
+  /**
+   * @brief a point 2 point interface
+   */
+  VNET_HW_INTERFACE_CLASS_FLAG_P2P = (1 << 0),
+} vnet_hw_interface_class_flags_t;
 
 /* Layer-2 (e.g. Ethernet) interface class. */
 typedef struct _vnet_hw_interface_class
@@ -200,6 +281,9 @@ typedef struct _vnet_hw_interface_class
   /* Class name (e.g. "Ethernet"). */
   char *name;
 
+  /* Flags */
+  vnet_hw_interface_class_flags_t flags;
+
   /* Function to call when hardware interface is added/deleted. */
   vnet_interface_function_t *interface_add_del_function;
 
@@ -227,13 +311,16 @@ typedef struct _vnet_hw_interface_class
   /* Parser for packet header for e.g. rewrite string. */
   unformat_function_t *unformat_header;
 
-  /* Forms adjacency for given l3 packet type and destination address.
-     Returns number of bytes in adjacency. */
-    uword (*set_rewrite) (struct vnet_main_t * vnm,
-                         u32 sw_if_index,
-                         u32 l3_packet_type,
-                         void *dst_address,
-                         void *rewrite, uword max_rewrite_bytes);
+  /* Builds a rewrite string for the interface to the destination
+   * for the payload/link type. */
+  u8 *(*build_rewrite) (struct vnet_main_t * vnm,
+                       u32 sw_if_index,
+                       vnet_link_t link_type, const void *dst_hw_address);
+
+  /* Update an adjacecny added by FIB (as opposed to via the
+   * neighbour resolution protocol). */
+  void (*update_adjacency) (struct vnet_main_t * vnm,
+                           u32 sw_if_index, u32 adj_index);
 
     uword (*is_valid_class_for_interface) (struct vnet_main_t * vnm,
                                           u32 hw_if_index,
@@ -249,6 +336,20 @@ typedef struct _vnet_hw_interface_class
 
 } vnet_hw_interface_class_t;
 
+/**
+ * @brief Return a complete, zero-length (aka dummy) rewrite
+ */
+extern u8 *default_build_rewrite (struct vnet_main_t *vnm,
+                                 u32 sw_if_index,
+                                 vnet_link_t link_type,
+                                 const void *dst_hw_address);
+
+/**
+ * @brief Default adjacency update function
+ */
+extern void default_update_adjacency (struct vnet_main_t *vnm,
+                                     u32 sw_if_index, u32 adj_index);
+
 #define VNET_HW_INTERFACE_CLASS(x,...)                                  \
   __VA_ARGS__ vnet_hw_interface_class_t x;                              \
 static void __vnet_add_hw_interface_class_registration_##x (void)       \
@@ -436,8 +537,6 @@ typedef struct
 
   u32 link_speed;
 
-  u32 output_feature_bitmap;
-
   union
   {
     /* VNET_SW_INTERFACE_TYPE_HARDWARE. */
@@ -459,7 +558,8 @@ typedef enum
   VNET_INTERFACE_COUNTER_RX_MISS = 5,
   VNET_INTERFACE_COUNTER_RX_ERROR = 6,
   VNET_INTERFACE_COUNTER_TX_ERROR = 7,
-  VNET_N_SIMPLE_INTERFACE_COUNTER = 8,
+  VNET_INTERFACE_COUNTER_MPLS = 8,
+  VNET_N_SIMPLE_INTERFACE_COUNTER = 9,
   /* Combined counters. */
   VNET_INTERFACE_COUNTER_RX = 0,
   VNET_INTERFACE_COUNTER_TX = 1,
@@ -531,30 +631,6 @@ void vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add);
 
 int vnet_interface_name_renumber (u32 sw_if_index, u32 new_show_dev_instance);
 
-
-/*
- *  Output features
- */
-
-#define foreach_intf_output_feat \
- _(IPSEC, "ipsec-output")
-
-/* Feature bitmap positions */
-typedef enum
-{
-#define _(sym,str) INTF_OUTPUT_FEAT_##sym,
-  foreach_intf_output_feat
-#undef _
-    INTF_OUTPUT_N_FEAT,
-} intf_output_feat_t;
-
-/* flag that we are done with feature path */
-#define INTF_OUTPUT_FEAT_DONE INTF_OUTPUT_N_FEAT
-
-int vnet_interface_add_del_feature (struct vnet_main_t *vnm, vlib_main_t * vm,
-                                   u32 sw_if_index,
-                                   intf_output_feat_t feature, int is_add);
-
 #endif /* included_vnet_interface_h */
 
 /*