fib: fix crash while adding intf-rx routes
[vpp.git] / src / vnet / ip / lookup.c
index 26bdaa6..f86c8b6 100644 (file)
@@ -145,13 +145,13 @@ unformat_ip_flow_hash_config (unformat_input_t *input, va_list *args)
     {
       if (unformat (input, "%_,"))
        ;
-#define _(a, b)                                                               \
+#define _(a, b, c)                                                            \
   else if (unformat (input, "%_" #a))                                         \
   {                                                                           \
-    *flow_hash_config |= b;                                                   \
+    *flow_hash_config |= c;                                                   \
     matched_once = 1;                                                         \
   }
-      foreach_flow_hash_bit_v1
+      foreach_flow_hash_bit
 #undef _
        else
       {
@@ -220,6 +220,27 @@ const ip46_address_t zero_addr = {
             0, 0},
 };
 
+bool
+fib_prefix_validate (const fib_prefix_t *prefix)
+{
+  if (FIB_PROTOCOL_IP4 == prefix->fp_proto)
+    {
+      if (prefix->fp_len > 32)
+       {
+         return false;
+       }
+    }
+
+  if (FIB_PROTOCOL_IP6 == prefix->fp_proto)
+    {
+      if (prefix->fp_len > 128)
+       {
+         return false;
+       }
+    }
+  return true;
+}
+
 static clib_error_t *
 vnet_ip_route_cmd (vlib_main_t * vm,
                   unformat_input_t * main_input, vlib_cli_command_t * cmd)
@@ -353,6 +374,12 @@ vnet_ip_route_cmd (vlib_main_t * vm,
                .fp_addr = prefixs[i].fp_addr,
              };
 
+             if (!fib_prefix_validate (&rpfx))
+               {
+                 vlib_cli_output (vm, "Invalid prefix len: %d", rpfx.fp_len);
+                 continue;
+               }
+
              if (is_del)
                fib_table_entry_path_remove2 (fib_index,
                                              &rpfx, FIB_SOURCE_CLI, rpaths);
@@ -593,7 +620,7 @@ VLIB_CLI_COMMAND (ip_route_command, static) = {
                "[next-hop-table <value>] [weight <value>] [preference "
                "<value>] [udp-encap <value>] [ip4-lookup-in-table <value>] "
                "[ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] "
-               "[resolve-via-host] [resolve-via-connected] [rx-ip4 "
+               "[resolve-via-host] [resolve-via-connected] [rx-ip4|rx-ip6 "
                "<interface>] [out-labels <value value value>]",
   .function = vnet_ip_route_cmd,
   .is_mp_safe = 1,