c11 safe string handling support
[vpp.git] / src / vnet / ipip / sixrd.c
index 08fd604..cc5bfa3 100644 (file)
@@ -177,17 +177,9 @@ sixrd_tunnel_stack (adj_index_t ai, u32 fib_index)
                                      LOOKUP_UNICAST, LOOKUP_INPUT_DST_ADDR,
                                      LOOKUP_TABLE_FROM_CONFIG, &dpo);
   adj_nbr_midchain_stack (ai, &dpo);
+  dpo_reset (&dpo);
 }
 
-const static ip46_address_t sixrd_special_nh = {
-  .ip6 = {
-         .as_u64 = {
-                    [0] = 0xffffffffffffffff,
-                    [1] = 0xffffffffffffffff,
-                    },
-         },
-};
-
 static void
 sixrd_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
 {
@@ -197,8 +189,7 @@ sixrd_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
   /* Not our tunnel */
   if (!t)
     return;
-  if (!memcmp (&sixrd_special_nh, &adj->sub_type.nbr.next_hop,
-              sizeof (sixrd_special_nh)))
+  if (IP_LOOKUP_NEXT_BCAST == adj->lookup_next_index)
     {
       adj_nbr_midchain_update_rewrite (ai, sixrd_fixup, t, ADJ_FLAG_NONE,
                                       sixrd_build_rewrite (vnm, sw_if_index,
@@ -281,14 +272,11 @@ int
 sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
                  ip4_address_t * ip4_prefix, u8 ip4_prefix_len,
                  ip4_address_t * ip4_src, bool security_check,
-                 u32 fib_index, u32 * sw_if_index)
+                 u32 ip4_fib_index, u32 ip6_fib_index, u32 * sw_if_index)
 {
   ipip_main_t *gm = &ipip_main;
   ipip_tunnel_t *t;
 
-  if (fib_index == ~0)
-    return VNET_API_ERROR_NO_SUCH_FIB;
-
   if ((ip6_prefix_len + 32 - ip4_prefix_len) > 64)
     return VNET_API_ERROR_INVALID_VALUE;
 
@@ -296,8 +284,9 @@ sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
   ip46_address_t src = ip46_address_initializer, dst =
     ip46_address_initializer;
   ip_set (&src, ip4_src, true);
-  ipip_tunnel_key_t key = {.transport = IPIP_TRANSPORT_IP4,
-    .fib_index = fib_index,
+  ipip_tunnel_key_t key = {
+    .transport = IPIP_TRANSPORT_IP4,
+    .fib_index = ip4_fib_index,
     .src = src,
     .dst = dst
   };
@@ -308,7 +297,7 @@ sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
 
   /* Get tunnel index */
   pool_get_aligned (gm->tunnels, t, CLIB_CACHE_LINE_BYTES);
-  memset (t, 0, sizeof (*t));
+  clib_memset (t, 0, sizeof (*t));
   u32 t_idx = t - gm->tunnels; /* tunnel index (or instance) */
 
   /* Init tunnel struct */
@@ -317,6 +306,7 @@ sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
   t->sixrd.ip4_prefix_len = ip4_prefix_len;
   t->sixrd.ip6_prefix = *ip6_prefix;
   t->sixrd.ip6_prefix_len = ip6_prefix_len;
+  t->sixrd.ip6_fib_index = ip6_fib_index;
   t->tunnel_src = src;
   t->sixrd.security_check = security_check;
   t->sixrd.shift =
@@ -332,12 +322,12 @@ sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
   vnet_hw_interface_t *hi =
     vnet_get_hw_interface (vnet_get_main (), hw_if_index);
   t->hw_if_index = hw_if_index;
-  t->fib_index = fib_index;
+  t->fib_index = ip4_fib_index;
   t->sw_if_index = hi->sw_if_index;
   t->dev_instance = t_idx;
   t->user_instance = t_idx;
 
-  hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] = 1480;
+  vnet_sw_interface_set_mtu (vnet_get_main (), t->sw_if_index, 1480);
 
   ipip_tunnel_db_add (t, &key);
 
@@ -349,24 +339,26 @@ sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
                               VNET_HW_INTERFACE_FLAG_LINK_UP);
   vnet_sw_interface_set_flags (vnet_get_main (), hi->sw_if_index,
                               VNET_SW_INTERFACE_FLAG_ADMIN_UP);
-  ip6_sw_interface_enable_disable (hi->sw_if_index, true);
+  ip6_sw_interface_enable_disable (t->sw_if_index, true);
 
   /* Create IPv6 route/adjacency */
+  /* *INDENT-OFF* */
   fib_prefix_t pfx6 = {
     .fp_proto = FIB_PROTOCOL_IP6,
     .fp_len = t->sixrd.ip6_prefix_len,
     .fp_addr = {
-               .ip6 = t->sixrd.ip6_prefix,
-               }
-    ,
+      .ip6 = t->sixrd.ip6_prefix,
+    },
   };
+  /* *INDENT-ON* */
 
-  fib_table_entry_update_one_path (fib_index, &pfx6, FIB_SOURCE_CLI,
+  fib_table_lock (ip6_fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_6RD);
+  fib_table_entry_update_one_path (ip6_fib_index, &pfx6, FIB_SOURCE_6RD,
                                   FIB_ENTRY_FLAG_ATTACHED, DPO_PROTO_IP6,
-                                  &sixrd_special_nh, hi->sw_if_index, ~0, 1,
+                                  &ADJ_BCAST_ADDR, t->sw_if_index, ~0, 1,
                                   NULL, FIB_ROUTE_PATH_FLAG_NONE);
 
-  *sw_if_index = hi->sw_if_index;
+  *sw_if_index = t->sw_if_index;
 
   if (!gm->ip4_protocol_registered)
     {
@@ -394,15 +386,23 @@ sixrd_del_tunnel (u32 sw_if_index)
       return -1;
     }
 
+  /* *INDENT-OFF* */
   fib_prefix_t pfx6 = {
     .fp_proto = FIB_PROTOCOL_IP6,
     .fp_len = t->sixrd.ip6_prefix_len,
     .fp_addr = {
-               .ip6 = t->sixrd.ip6_prefix,
-               }
-    ,
+      .ip6 = t->sixrd.ip6_prefix,
+    },
   };
-  fib_table_entry_special_remove (0, &pfx6, FIB_SOURCE_CLI);
+  /* *INDENT-ON* */
+
+  fib_table_entry_path_remove (t->sixrd.ip6_fib_index, &pfx6,
+                              FIB_SOURCE_6RD,
+                              DPO_PROTO_IP6,
+                              &ADJ_BCAST_ADDR, t->sw_if_index, ~0, 1,
+                              FIB_ROUTE_PATH_FLAG_NONE);
+  fib_table_unlock (t->sixrd.ip6_fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_6RD);
+
   vnet_sw_interface_set_flags (vnet_get_main (), t->sw_if_index,
                               0 /* down */ );
   ip6_sw_interface_enable_disable (t->sw_if_index, false);
@@ -501,7 +501,7 @@ sixrd_init (vlib_main_t * vm)
   clib_error_t *error = 0;
 
   /* Make sure the IPIP tunnel subsystem is initialised */
-  vlib_call_init_function (vm, ipip_init);
+  error = vlib_call_init_function (vm, ipip_init);
 
   sixrd_adj_delegate_type =
     adj_delegate_register_new_type (&sixrd_adj_delegate_vft);