ip: Fix crash in ip address add on sub-int without exact-match
[vpp.git] / src / vnet / ip / ip4_forward.c
index 0fa9da2..57ad658 100644 (file)
@@ -55,6 +55,7 @@
 #include <vnet/dpo/classify_dpo.h>
 #include <vnet/mfib/mfib_table.h>      /* for mFIB table and entry creation */
 #include <vnet/adj/adj_dp.h>
+#include <vnet/pg/pg.h>
 
 #include <vnet/ip/ip4_forward.h>
 #include <vnet/interface_output.h>
@@ -380,28 +381,28 @@ ip4_add_interface_prefix_routes (ip4_main_t *im,
   mhash_set (&lm->prefix_to_if_prefix_index, &key,
             if_prefix - lm->if_prefix_pool, 0 /* old value */);
 
+  pfx_special.fp_len = a->address_length;
+  pfx_special.fp_addr.ip4.as_u32 = address->as_u32;
+
+  /* set the glean route for the prefix */
+  fib_table_entry_update_one_path (fib_index, &pfx_special,
+                                   FIB_SOURCE_INTERFACE,
+                                   (FIB_ENTRY_FLAG_CONNECTED |
+                                    FIB_ENTRY_FLAG_ATTACHED),
+                                   DPO_PROTO_IP4,
+                                   /* No next-hop address */
+                                   NULL,
+                                   sw_if_index,
+                                   /* invalid FIB index */
+                                   ~0,
+                                   1,
+                                   /* no out-label stack */
+                                   NULL,
+                                   FIB_ROUTE_PATH_FLAG_NONE);
+
   /* length <= 30 - add glean, drop first address, maybe drop bcast address */
   if (a->address_length <= 30)
     {
-      pfx_special.fp_len = a->address_length;
-      pfx_special.fp_addr.ip4.as_u32 = address->as_u32;
-
-      /* set the glean route for the prefix */
-      fib_table_entry_update_one_path (fib_index, &pfx_special,
-                                      FIB_SOURCE_INTERFACE,
-                                      (FIB_ENTRY_FLAG_CONNECTED |
-                                       FIB_ENTRY_FLAG_ATTACHED),
-                                      DPO_PROTO_IP4,
-                                      /* No next-hop address */
-                                      NULL,
-                                      sw_if_index,
-                                       /* invalid FIB index */
-                                       ~0,
-                                       1,
-                                       /* no out-label stack */
-                                       NULL,
-                                       FIB_ROUTE_PATH_FLAG_NONE);
-
       /* set a drop route for the base address of the prefix */
       pfx_special.fp_len = 32;
       pfx_special.fp_addr.ip4.as_u32 =
@@ -528,90 +529,52 @@ ip4_del_interface_prefix_routes (ip4_main_t * im,
   if_prefix->ref_count -= 1;
 
   /*
-   * Routes need to be adjusted if:
-   * - deleting last intf addr in prefix
-   * - deleting intf addr used as default source address in glean adjacency
+   * Routes need to be adjusted if deleting last intf addr in prefix
    *
    * We're done now otherwise
    */
-  if ((if_prefix->ref_count > 0) &&
-      !pool_is_free_index (lm->if_address_pool, if_prefix->src_ia_index))
+  if (if_prefix->ref_count > 0)
     return;
 
   /* length <= 30, delete glean route, first address, last address */
   if (address_length <= 30)
     {
+      /* Less work to do in FIB if we remove the covered /32s first */
 
-      /* remove glean route for prefix */
-      pfx_special.fp_addr.ip4 = *address;
-      pfx_special.fp_len = address_length;
-      fib_table_entry_delete (fib_index, &pfx_special, FIB_SOURCE_INTERFACE);
-
-      /* if no more intf addresses in prefix, remove other special routes */
-      if (!if_prefix->ref_count)
-       {
-         /* first address in prefix */
-         pfx_special.fp_addr.ip4.as_u32 =
-           address->as_u32 & im->fib_masks[address_length];
-         pfx_special.fp_len = 32;
+      /* first address in prefix */
+      pfx_special.fp_addr.ip4.as_u32 =
+        address->as_u32 & im->fib_masks[address_length];
+      pfx_special.fp_len = 32;
 
-         if (pfx_special.fp_addr.ip4.as_u32 != address->as_u32)
-         fib_table_entry_special_remove (fib_index,
-                                         &pfx_special,
-                                         FIB_SOURCE_INTERFACE);
+      if (pfx_special.fp_addr.ip4.as_u32 != address->as_u32)
+        fib_table_entry_special_remove (fib_index,
+                                        &pfx_special,
+                                        FIB_SOURCE_INTERFACE);
 
-         /* prefix broadcast address */
-         pfx_special.fp_addr.ip4.as_u32 =
-           address->as_u32 | ~im->fib_masks[address_length];
-         pfx_special.fp_len = 32;
+      /* prefix broadcast address */
+      pfx_special.fp_addr.ip4.as_u32 =
+        address->as_u32 | ~im->fib_masks[address_length];
+      pfx_special.fp_len = 32;
 
-         if (pfx_special.fp_addr.ip4.as_u32 != address->as_u32)
-         fib_table_entry_special_remove (fib_index,
-                                         &pfx_special,
-                                         FIB_SOURCE_INTERFACE);
-       }
-      else
-       /* default source addr just got deleted, find another */
-       {
-         ip_interface_address_t *new_src_ia = NULL;
-         ip4_address_t *new_src_addr = NULL;
-
-         new_src_addr =
-           ip4_interface_address_matching_destination
-             (im, address, sw_if_index, &new_src_ia);
-
-         if_prefix->src_ia_index = new_src_ia - lm->if_address_pool;
-
-         pfx_special.fp_len = address_length;
-         pfx_special.fp_addr.ip4 = *new_src_addr;
-
-         /* set new glean route for the prefix */
-         fib_table_entry_update_one_path (fib_index, &pfx_special,
-                                          FIB_SOURCE_INTERFACE,
-                                          (FIB_ENTRY_FLAG_CONNECTED |
-                                           FIB_ENTRY_FLAG_ATTACHED),
-                                          DPO_PROTO_IP4,
-                                          /* No next-hop address */
-                                          NULL,
-                                          sw_if_index,
-                                          /* invalid FIB index */
-                                          ~0,
-                                          1,
-                                          /* no out-label stack */
-                                          NULL,
-                                          FIB_ROUTE_PATH_FLAG_NONE);
-         return;
-       }
+      if (pfx_special.fp_addr.ip4.as_u32 != address->as_u32)
+        fib_table_entry_special_remove (fib_index,
+                                        &pfx_special,
+                                        FIB_SOURCE_INTERFACE);
     }
-  /* length == 31, delete attached route for the other address */
   else if (address_length == 31)
     {
+      /* length == 31, delete attached route for the other address */
       pfx_special.fp_addr.ip4.as_u32 =
        address->as_u32 ^ clib_host_to_net_u32(1);
 
       fib_table_entry_delete (fib_index, &pfx_special, FIB_SOURCE_INTERFACE);
     }
 
+  /* remove glean route for prefix */
+  pfx_special.fp_addr.ip4 = *address;
+  pfx_special.fp_len = address_length;
+  fib_table_entry_delete (fib_index, &pfx_special, FIB_SOURCE_INTERFACE);
+
   mhash_unset (&lm->prefix_to_if_prefix_index, &key, 0 /* old_value */);
   pool_put (lm->if_prefix_pool, if_prefix);
 }
@@ -623,16 +586,15 @@ ip4_del_interface_routes (u32 sw_if_index,
                          ip4_address_t * address, u32 address_length)
 {
   fib_prefix_t pfx = {
-    .fp_len = address_length,
+    .fp_len = 32,
     .fp_proto = FIB_PROTOCOL_IP4,
     .fp_addr.ip4 = *address,
   };
 
+  fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
+
   ip4_del_interface_prefix_routes (im, sw_if_index, fib_index,
                                   address, address_length);
-
-  pfx.fp_len = 32;
-  fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE);
 }
 
 #ifndef CLIB_MARCH_VARIANT
@@ -691,12 +653,9 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm,
   u32 if_address_index;
   ip4_address_fib_t ip4_af, *addr_fib = 0;
 
-  /* local0 interface doesn't support IP addressing  */
-  if (sw_if_index == 0)
-    {
-      return
-       clib_error_create ("local0 interface doesn't support IP addressing");
-    }
+  error = vnet_sw_interface_supports_addressing (vnm, sw_if_index);
+  if (error)
+    return error;
 
   vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
   ip4_addr_fib_init (&ip4_af, address,
@@ -716,8 +675,8 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm,
       ip_interface_address_t *ia;
       vnet_sw_interface_t *sif;
 
-      pool_foreach(sif, vnm->interface_main.sw_interfaces,
-      ({
+      pool_foreach (sif, vnm->interface_main.sw_interfaces)
+       {
           if (im->fib_index_by_sw_if_index[sw_if_index] ==
               im->fib_index_by_sw_if_index[sif->sw_if_index])
             {
@@ -767,7 +726,7 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm,
                      }
                  }));
             }
-      }));
+      }
     }
   /* *INDENT-ON* */
 
@@ -1456,9 +1415,10 @@ ip4_local_l4_csum_validate (vlib_main_t * vm, vlib_buffer_t * p,
     }
 }
 
-#define ip4_local_csum_is_offloaded(_b)                                        \
-    _b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM                                \
-       || _b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM
+#define ip4_local_csum_is_offloaded(_b)                                       \
+  ((_b->flags & VNET_BUFFER_F_OFFLOAD) &&                                     \
+   (vnet_buffer (_b)->oflags &                                                \
+    (VNET_BUFFER_OFFLOAD_F_TCP_CKSUM | VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)))
 
 #define ip4_local_need_csum_check(is_tcp_udp, _b)                      \
     (is_tcp_udp && !(_b->flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED    \
@@ -1554,8 +1514,6 @@ static inline void
 ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0,
                     ip4_local_last_check_t * last_check, u8 * error0)
 {
-  ip4_fib_mtrie_leaf_t leaf0;
-  ip4_fib_mtrie_t *mtrie0;
   const dpo_id_t *dpo0;
   load_balance_t *lb0;
   u32 lbi0;
@@ -1573,11 +1531,8 @@ ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0,
   if (PREDICT_TRUE (last_check->src.as_u32 != ip0->src_address.as_u32) ||
       last_check->first)
     {
-      mtrie0 = &ip4_fib_get (vnet_buffer (b)->ip.fib_index)->mtrie;
-      leaf0 = ip4_fib_mtrie_lookup_step_one (mtrie0, &ip0->src_address);
-      leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2);
-      leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3);
-      lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
+      lbi0 = ip4_fib_forwarding_lookup (vnet_buffer (b)->ip.fib_index,
+                                       &ip0->src_address);
 
       vnet_buffer (b)->ip.adj_index[VLIB_RX] =
        vnet_buffer (b)->ip.adj_index[VLIB_TX];
@@ -1623,8 +1578,6 @@ static inline void
 ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip,
                        ip4_local_last_check_t * last_check, u8 * error)
 {
-  ip4_fib_mtrie_leaf_t leaf[2];
-  ip4_fib_mtrie_t *mtrie[2];
   const dpo_id_t *dpo[2];
   load_balance_t *lb[2];
   u32 not_last_hit;
@@ -1652,24 +1605,9 @@ ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip,
    */
   if (PREDICT_TRUE (not_last_hit))
     {
-      mtrie[0] = &ip4_fib_get (vnet_buffer (b[0])->ip.fib_index)->mtrie;
-      mtrie[1] = &ip4_fib_get (vnet_buffer (b[1])->ip.fib_index)->mtrie;
-
-      leaf[0] = ip4_fib_mtrie_lookup_step_one (mtrie[0], &ip[0]->src_address);
-      leaf[1] = ip4_fib_mtrie_lookup_step_one (mtrie[1], &ip[1]->src_address);
-
-      leaf[0] = ip4_fib_mtrie_lookup_step (mtrie[0], leaf[0],
-                                          &ip[0]->src_address, 2);
-      leaf[1] = ip4_fib_mtrie_lookup_step (mtrie[1], leaf[1],
-                                          &ip[1]->src_address, 2);
-
-      leaf[0] = ip4_fib_mtrie_lookup_step (mtrie[0], leaf[0],
-                                          &ip[0]->src_address, 3);
-      leaf[1] = ip4_fib_mtrie_lookup_step (mtrie[1], leaf[1],
-                                          &ip[1]->src_address, 3);
-
-      lbi[0] = ip4_fib_mtrie_leaf_get_adj_index (leaf[0]);
-      lbi[1] = ip4_fib_mtrie_leaf_get_adj_index (leaf[1]);
+      ip4_fib_forwarding_lookup_x2 (
+       vnet_buffer (b[0])->ip.fib_index, vnet_buffer (b[1])->ip.fib_index,
+       &ip[0]->src_address, &ip[1]->src_address, &lbi[0], &lbi[1]);
 
       vnet_buffer (b[0])->ip.adj_index[VLIB_RX] =
        vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
@@ -1799,8 +1737,8 @@ ip4_local_inline (vlib_main_t * vm,
        vlib_prefetch_buffer_header (b[4], LOAD);
        vlib_prefetch_buffer_header (b[5], LOAD);
 
-       CLIB_PREFETCH (b[4]->data, CLIB_CACHE_LINE_BYTES, LOAD);
-       CLIB_PREFETCH (b[5]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+       clib_prefetch_load (b[4]->data);
+       clib_prefetch_load (b[5]->data);
       }
 
       error[0] = error[1] = IP4_ERROR_UNKNOWN_PROTOCOL;
@@ -2063,7 +2001,7 @@ ip4_ttl_inc (vlib_buffer_t * b, ip4_header_t * ip)
   ttl += 1;
   ip->ttl = ttl;
 
-  ASSERT (ip->checksum == ip4_header_checksum (ip));
+  ASSERT (ip4_header_checksum_is_valid (ip));
 }
 
 /* Decrement TTL & update checksum.
@@ -2104,16 +2042,14 @@ ip4_ttl_and_checksum_check (vlib_buffer_t * b, ip4_header_t * ip, u16 * next,
     }
 
   /* Verify checksum. */
-  ASSERT ((ip->checksum == ip4_header_checksum (ip)) ||
-         (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM));
+  ASSERT (ip4_header_checksum_is_valid (ip) ||
+         (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM));
 }
 
-
 always_inline uword
-ip4_rewrite_inline_with_gso (vlib_main_t * vm,
-                            vlib_node_runtime_t * node,
-                            vlib_frame_t * frame,
-                            int do_counters, int is_midchain, int is_mcast)
+ip4_rewrite_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
+                   vlib_frame_t *frame, int do_counters, int is_midchain,
+                   int is_mcast)
 {
   ip_lookup_main_t *lm = &ip4_main.lookup_main;
   u32 *from = vlib_frame_vector_args (frame);
@@ -2148,8 +2084,11 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
       u32 tx_sw_if_index0, tx_sw_if_index1;
       u8 *p;
 
-      vlib_prefetch_buffer_header (b[6], LOAD);
-      vlib_prefetch_buffer_header (b[7], LOAD);
+      if (is_midchain)
+       {
+         vlib_prefetch_buffer_header (b[6], LOAD);
+         vlib_prefetch_buffer_header (b[7], LOAD);
+       }
 
       adj_index0 = vnet_buffer (b[0])->ip.adj_index[VLIB_TX];
       adj_index1 = vnet_buffer (b[1])->ip.adj_index[VLIB_TX];
@@ -2184,12 +2123,12 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
       vnet_buffer (b[1])->ip.save_rewrite_length = rw_len1;
 
       p = vlib_buffer_get_current (b[2]);
-      CLIB_PREFETCH (p - CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES, STORE);
-      CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
+      clib_prefetch_store (p - CLIB_CACHE_LINE_BYTES);
+      clib_prefetch_load (p);
 
       p = vlib_buffer_get_current (b[3]);
-      CLIB_PREFETCH (p - CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES, STORE);
-      CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
+      clib_prefetch_store (p - CLIB_CACHE_LINE_BYTES);
+      clib_prefetch_load (p);
 
       /* Check MTU of outgoing interface. */
       u16 ip0_len = clib_net_to_host_u16 (ip0->length);
@@ -2304,9 +2243,9 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
       if (is_midchain)
        {
          if (error0 == IP4_ERROR_NONE)
-           adj_midchain_fixup (vm, adj0, b[0]);
+           adj_midchain_fixup (vm, adj0, b[0], VNET_LINK_IP4);
          if (error1 == IP4_ERROR_NONE)
-           adj_midchain_fixup (vm, adj1, b[1]);
+           adj_midchain_fixup (vm, adj1, b[1], VNET_LINK_IP4);
        }
 
       if (is_mcast)
@@ -2438,7 +2377,7 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
                                                           b[0]) + rw_len0);
 
          if (is_midchain)
-           adj_midchain_fixup (vm, adj0, b[0]);
+           adj_midchain_fixup (vm, adj0, b[0], VNET_LINK_IP4);
 
          if (is_mcast)
            /* copy bytes from the IP address into the MAC rewrite */
@@ -2540,9 +2479,8 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
               thread_index, adj_index0, 1,
               vlib_buffer_length_in_chain (vm, b[0]) + rw_len0);
 
-         if (is_midchain && adj0->sub_type.midchain.fixup_func)
-           adj0->sub_type.midchain.fixup_func
-             (vm, adj0, b[0], adj0->sub_type.midchain.fixup_data);
+         if (is_midchain)
+           adj_midchain_fixup (vm, adj0, b[0], VNET_LINK_IP4);
 
          if (is_mcast)
            /* copy bytes from the IP address into the MAC rewrite */
@@ -2572,17 +2510,6 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
   return frame->n_vectors;
 }
 
-always_inline uword
-ip4_rewrite_inline (vlib_main_t * vm,
-                   vlib_node_runtime_t * node,
-                   vlib_frame_t * frame,
-                   int do_counters, int is_midchain, int is_mcast)
-{
-  return ip4_rewrite_inline_with_gso (vm, node, frame, do_counters,
-                                     is_midchain, is_mcast);
-}
-
-
 /** @brief IPv4 rewrite node.
     @node ip4-rewrite
 
@@ -2711,121 +2638,6 @@ VLIB_REGISTER_NODE (ip4_midchain_node) = {
 };
 /* *INDENT-ON */
 
-static int
-ip4_lookup_validate (ip4_address_t * a, u32 fib_index0)
-{
-  ip4_fib_mtrie_t *mtrie0;
-  ip4_fib_mtrie_leaf_t leaf0;
-  u32 lbi0;
-
-  mtrie0 = &ip4_fib_get (fib_index0)->mtrie;
-
-  leaf0 = ip4_fib_mtrie_lookup_step_one (mtrie0, a);
-  leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, a, 2);
-  leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, a, 3);
-
-  lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0);
-
-  return lbi0 == ip4_fib_table_lookup_lb (ip4_fib_get (fib_index0), a);
-}
-
-static clib_error_t *
-test_lookup_command_fn (vlib_main_t * vm,
-                       unformat_input_t * input, vlib_cli_command_t * cmd)
-{
-  ip4_fib_t *fib;
-  u32 table_id = 0;
-  f64 count = 1;
-  u32 n;
-  int i;
-  ip4_address_t ip4_base_address;
-  u64 errors = 0;
-
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "table %d", &table_id))
-       {
-         /* Make sure the entry exists. */
-         fib = ip4_fib_get (table_id);
-         if ((fib) && (fib->index != table_id))
-           return clib_error_return (0, "<fib-index> %d does not exist",
-                                     table_id);
-       }
-      else if (unformat (input, "count %f", &count))
-       ;
-
-      else if (unformat (input, "%U",
-                        unformat_ip4_address, &ip4_base_address))
-       ;
-      else
-       return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
-    }
-
-  n = count;
-
-  for (i = 0; i < n; i++)
-    {
-      if (!ip4_lookup_validate (&ip4_base_address, table_id))
-       errors++;
-
-      ip4_base_address.as_u32 =
-       clib_host_to_net_u32 (1 +
-                             clib_net_to_host_u32 (ip4_base_address.as_u32));
-    }
-
-  if (errors)
-    vlib_cli_output (vm, "%llu errors out of %d lookups\n", errors, n);
-  else
-    vlib_cli_output (vm, "No errors in %d lookups\n", n);
-
-  return 0;
-}
-
-/*?
- * Perform a lookup of an IPv4 Address (or range of addresses) in the
- * given FIB table to determine if there is a conflict with the
- * adjacency table. The fib-id can be determined by using the
- * '<em>show ip fib</em>' command. If fib-id is not entered, default value
- * of 0 is used.
- *
- * @todo This command uses fib-id, other commands use table-id (not
- * just a name, they are different indexes). Would like to change this
- * to table-id for consistency.
- *
- * @cliexpar
- * Example of how to run the test lookup command:
- * @cliexstart{test lookup 172.16.1.1 table 1 count 2}
- * No errors in 2 lookups
- * @cliexend
-?*/
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lookup_test_command, static) =
-{
-  .path = "test lookup",
-  .short_help = "test lookup <ipv4-addr> [table <fib-id>] [count <nn>]",
-  .function = test_lookup_command_fn,
-};
-/* *INDENT-ON* */
-
-#ifndef CLIB_MARCH_VARIANT
-int
-vnet_set_ip4_flow_hash (u32 table_id, u32 flow_hash_config)
-{
-  u32 fib_index;
-
-  fib_index = fib_table_find (FIB_PROTOCOL_IP4, table_id);
-
-  if (~0 == fib_index)
-    return VNET_API_ERROR_NO_SUCH_FIB;
-
-  fib_table_set_flow_hash_config (fib_index, FIB_PROTOCOL_IP4,
-                                 flow_hash_config);
-
-  return 0;
-}
-#endif
-
 static clib_error_t *
 set_ip_flow_hash_command_fn (vlib_main_t * vm,
                             unformat_input_t * input,
@@ -2840,8 +2652,12 @@ set_ip_flow_hash_command_fn (vlib_main_t * vm,
     {
       if (unformat (input, "table %d", &table_id))
        matched = 1;
-#define _(a,v) \
-    else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
+#define _(a, b, v)                                                            \
+  else if (unformat (input, #a))                                              \
+  {                                                                           \
+    flow_hash_config |= v;                                                    \
+    matched = 1;                                                              \
+  }
       foreach_flow_hash_bit
 #undef _
        else
@@ -2852,7 +2668,7 @@ set_ip_flow_hash_command_fn (vlib_main_t * vm,
     return clib_error_return (0, "unknown input `%U'",
                              format_unformat_error, input);
 
-  rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
+  rv = ip_flow_hash_set (AF_IP4, table_id, flow_hash_config);
   switch (rv)
     {
     case 0:
@@ -3087,29 +2903,6 @@ VLIB_CLI_COMMAND (set_ip_classify_command, static) =
 };
 /* *INDENT-ON* */
 
-static clib_error_t *
-ip4_config (vlib_main_t * vm, unformat_input_t * input)
-{
-  ip4_main_t *im = &ip4_main;
-  uword heapsize = 0;
-
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (input, "heap-size %U", unformat_memory_size, &heapsize))
-       ;
-      else
-       return clib_error_return (0,
-                                 "invalid heap-size parameter `%U'",
-                                 format_unformat_error, input);
-    }
-
-  im->mtrie_heap_size = heapsize;
-
-  return 0;
-}
-
-VLIB_EARLY_CONFIG_FUNCTION (ip4_config, "ip");
-
 /*
  * fd.io coding-style-patch-verification: ON
  *