ip: Router ID included in flow hash
[vpp.git] / src / plugins / gbp / gbp_endpoint.c
index 1286546..b0cf64c 100644 (file)
 #include <plugins/gbp/gbp_policy_dpo.h>
 #include <plugins/gbp/gbp_vxlan.h>
 
-#include <vnet/ethernet/arp.h>
 #include <vnet/l2/l2_input.h>
 #include <vnet/l2/l2_output.h>
 #include <vnet/l2/feat_bitmap.h>
 #include <vnet/l2/l2_fib.h>
 #include <vnet/fib/fib_table.h>
-#include <vnet/ip/ip_neighbor.h>
+#include <vnet/ip-neighbor/ip_neighbor.h>
+#include <vnet/ip-neighbor/ip4_neighbor.h>
+#include <vnet/ip-neighbor/ip6_neighbor.h>
 #include <vnet/fib/fib_walk.h>
 #include <vnet/vxlan-gbp/vxlan_gbp.h>
 
@@ -41,9 +42,10 @@ static const char *gbp_endpoint_attr_names[] = GBP_ENDPOINT_ATTR_NAMES;
  */
 gbp_ep_db_t gbp_ep_db;
 
-fib_node_type_t gbp_endpoint_fib_type;
-
-vlib_log_class_t gbp_ep_logger;
+static fib_source_t gbp_fib_source_hi;
+static fib_source_t gbp_fib_source_low;
+static fib_node_type_t gbp_endpoint_fib_type;
+static vlib_log_class_t gbp_ep_logger;
 
 #define GBP_ENDPOINT_DBG(...)                           \
     vlib_log_debug (gbp_ep_logger, __VA_ARGS__);
@@ -207,12 +209,6 @@ gbp_endpoint_index (const gbp_endpoint_t * ge)
   return (ge - gbp_endpoint_pool);
 }
 
-static ip46_type_t
-ip46_address_get_type (const ip46_address_t * a)
-{
-  return (ip46_address_is_ip4 (a) ? IP46_TYPE_IP4 : IP46_TYPE_IP6);
-}
-
 static int
 gbp_endpoint_ip_is_equal (const fib_prefix_t * fp, const ip46_address_t * ip)
 {
@@ -588,10 +584,10 @@ gbb_endpoint_fwd_reset (gbp_endpoint_t * ge)
      */
     if (gbp_endpoint_is_remote (ge))
       {
-       fib_table_entry_special_remove (fib_index, pfx, FIB_SOURCE_PLUGIN_HI);
+       fib_table_entry_special_remove (fib_index, pfx, gbp_fib_source_hi);
       }
 
-    fib_table_entry_delete (fib_index, pfx, FIB_SOURCE_PLUGIN_LOW);
+    fib_table_entry_delete (fib_index, pfx, gbp_fib_source_low);
   }
   vec_foreach (ai, gef->gef_adjs)
   {
@@ -726,7 +722,7 @@ gbb_endpoint_fwd_recalc (gbp_endpoint_t * ge)
       }
 
     fib_table_entry_path_add (fib_index, pfx,
-                             FIB_SOURCE_PLUGIN_LOW,
+                             gbp_fib_source_low,
                              FIB_ENTRY_FLAG_NONE,
                              fib_proto_to_dpo (pfx->fp_proto),
                              &pfx->fp_addr, ip_sw_if_index,
@@ -759,7 +755,7 @@ gbb_endpoint_fwd_recalc (gbp_endpoint_t * ge)
                                        gg->gg_sclass, ~0, &policy_dpo);
 
            fib_table_entry_special_dpo_add (fib_index, pfx,
-                                            FIB_SOURCE_PLUGIN_HI,
+                                            gbp_fib_source_hi,
                                             FIB_ENTRY_FLAG_INTERPOSE,
                                             &policy_dpo);
            dpo_reset (&policy_dpo);
@@ -775,13 +771,15 @@ gbb_endpoint_fwd_recalc (gbp_endpoint_t * ge)
            gbp_endpoint_add_itf (gbp_itf_get_sw_if_index (gef->gef_itf),
                                  gei);
            if (FIB_PROTOCOL_IP4 == pfx->fp_proto)
-             send_ip4_garp_w_addr (vlib_get_main (),
-                                   &pfx->fp_addr.ip4,
-                                   gg->gg_uplink_sw_if_index);
+             ip4_neighbor_advertise (vlib_get_main (),
+                                     vnet_get_main (),
+                                     gg->gg_uplink_sw_if_index,
+                                     &pfx->fp_addr.ip4);
            else
-             send_ip6_na_w_addr (vlib_get_main (),
-                                 &pfx->fp_addr.ip6,
-                                 gg->gg_uplink_sw_if_index);
+             ip6_neighbor_advertise (vlib_get_main (),
+                                     vnet_get_main (),
+                                     gg->gg_uplink_sw_if_index,
+                                     &pfx->fp_addr.ip6);
          }
       }
   }
@@ -1065,11 +1063,11 @@ gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx)
   u32 index;
 
   /* *INDENT-OFF* */
-  pool_foreach_index(index, gbp_endpoint_pool,
+  pool_foreach_index (index, gbp_endpoint_pool)
   {
     if (!cb(index, ctx))
       break;
-  });
+  }
   /* *INDENT-ON* */
 }
 
@@ -1267,8 +1265,8 @@ gbp_endpoint_show_one (index_t gei, void *ctx)
   return (WALK_CONTINUE);
 }
 
-static void
-gbp_endpoint_walk_ip_itf (const clib_bihash_kv_24_8_t * kvp, void *arg)
+static int
+gbp_endpoint_walk_ip_itf (clib_bihash_kv_24_8_t * kvp, void *arg)
 {
   ip46_address_t ip;
   vlib_main_t *vm;
@@ -1282,10 +1280,11 @@ gbp_endpoint_walk_ip_itf (const clib_bihash_kv_24_8_t * kvp, void *arg)
                   format_ip46_address, &ip, IP46_TYPE_ANY,
                   format_vnet_sw_if_index_name, vnet_get_main (),
                   sw_if_index, kvp->value);
+  return (BIHASH_WALK_CONTINUE);
 }
 
-static void
-gbp_endpoint_walk_mac_itf (const clib_bihash_kv_16_8_t * kvp, void *arg)
+static int
+gbp_endpoint_walk_mac_itf (clib_bihash_kv_16_8_t * kvp, void *arg)
 {
   mac_address_t mac;
   vlib_main_t *vm;
@@ -1299,6 +1298,7 @@ gbp_endpoint_walk_mac_itf (const clib_bihash_kv_16_8_t * kvp, void *arg)
                   format_mac_address_t, &mac,
                   format_vnet_sw_if_index_name, vnet_get_main (),
                   sw_if_index, kvp->value);
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static clib_error_t *
@@ -1405,8 +1405,8 @@ gbp_endpoint_scan_l2 (vlib_main_t * vm)
          last_start = vlib_time_now (vm);
        }
 
-      b = &gte_table->buckets[i];
-      if (b->offset == 0)
+      b = clib_bihash_get_bucket_16_8 (gte_table, i);
+      if (clib_bihash_bucket_is_empty_16_8 (b))
        continue;
       v = clib_bihash_get_value_16_8 (gte_table, b->offset);
 
@@ -1423,7 +1423,7 @@ gbp_endpoint_scan_l2 (vlib_main_t * vm)
               * Note: we may have just freed the bucket's backing
               * storage, so check right here...
               */
-             if (b->offset == 0)
+             if (clib_bihash_bucket_is_empty_16_8 (b))
                goto doublebreak;
            }
          v++;
@@ -1460,8 +1460,8 @@ gbp_endpoint_scan_l3 (vlib_main_t * vm)
          last_start = vlib_time_now (vm);
        }
 
-      b = &gte_table->buckets[i];
-      if (b->offset == 0)
+      b = clib_bihash_get_bucket_24_8 (gte_table, i);
+      if (clib_bihash_bucket_is_empty_24_8 (b))
        continue;
       v = clib_bihash_get_value_24_8 (gte_table, b->offset);
 
@@ -1478,7 +1478,7 @@ gbp_endpoint_scan_l3 (vlib_main_t * vm)
               * Note: we may have just freed the bucket's backing
               * storage, so check right here...
               */
-             if (b->offset == 0)
+             if (clib_bihash_bucket_is_empty_24_8 (b))
                goto doublebreak;
            }
          v++;
@@ -1576,6 +1576,12 @@ gbp_endpoint_init (vlib_main_t * vm)
 
   gbp_ep_logger = vlib_log_register_class ("gbp", "ep");
   gbp_endpoint_fib_type = fib_node_register_new_type (&gbp_endpoint_vft);
+  gbp_fib_source_hi = fib_source_allocate ("gbp-endpoint-hi",
+                                          FIB_SOURCE_PRIORITY_HI,
+                                          FIB_SOURCE_BH_SIMPLE);
+  gbp_fib_source_low = fib_source_allocate ("gbp-endpoint-low",
+                                           FIB_SOURCE_PRIORITY_LOW,
+                                           FIB_SOURCE_BH_SIMPLE);
 
   return (NULL);
 }