ip: add container proxy api
[vpp.git] / src / vnet / ip / ip_api.c
index 8a3ceb2..fad518f 100644 (file)
@@ -79,7 +79,8 @@ _(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del)                             \
 _(IP6ND_PROXY_DUMP, ip6nd_proxy_dump)                                   \
 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable )    \
 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS,                             \
-  sw_interface_ip6_set_link_local_address)
+  sw_interface_ip6_set_link_local_address)                             \
+_(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del )
 
 extern void stats_dslock_with_hint (int hint, int tag);
 extern void stats_dsunlock (void);
@@ -364,7 +365,7 @@ send_ip6_fib_details (vpe_api_main_t * am,
       }
     fp->weight = api_rpath->rpath.frp_weight;
     fp->preference = api_rpath->rpath.frp_preference;
-    fp->sw_if_index = api_rpath->rpath.frp_sw_if_index;
+    fp->sw_if_index = htonl (api_rpath->rpath.frp_sw_if_index);
     copy_fib_next_hop (api_rpath, fp);
     fp++;
   }
@@ -989,11 +990,23 @@ add_del_route_check (fib_protocol_t table_proto,
 {
   vnet_main_t *vnm = vnet_get_main ();
 
+  /* Temporaray whilst I do the CSIT dance */
+  u8 create_missing_tables = 1;
+
   *fib_index = fib_table_find (table_proto, ntohl (table_id));
   if (~0 == *fib_index)
     {
-      /* No such VRF */
-      return VNET_API_ERROR_NO_SUCH_FIB;
+      if (create_missing_tables)
+       {
+         *fib_index = fib_table_find_or_create_and_lock (table_proto,
+                                                         ntohl (table_id),
+                                                         FIB_SOURCE_API);
+       }
+      else
+       {
+         /* No such VRF, and we weren't asked to create one */
+         return VNET_API_ERROR_NO_SUCH_FIB;
+       }
     }
 
   if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index))
@@ -1022,7 +1035,26 @@ add_del_route_check (fib_protocol_t table_proto,
 
       if (~0 == *next_hop_fib_index)
        {
-         return VNET_API_ERROR_NO_SUCH_FIB;
+         if (create_missing_tables)
+           {
+             if (is_rpf_id)
+               *next_hop_fib_index =
+                 mfib_table_find_or_create_and_lock (fib_nh_proto,
+                                                     ntohl
+                                                     (next_hop_table_id),
+                                                     MFIB_SOURCE_API);
+             else
+               *next_hop_fib_index =
+                 fib_table_find_or_create_and_lock (fib_nh_proto,
+                                                    ntohl
+                                                    (next_hop_table_id),
+                                                    FIB_SOURCE_API);
+           }
+         else
+           {
+             /* No such VRF, and we weren't asked to create one */
+             return VNET_API_ERROR_NO_SUCH_FIB;
+           }
        }
     }
 
@@ -1818,6 +1850,29 @@ vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
     ;
 }
 
+static void
+  vl_api_ip_container_proxy_add_del_t_handler
+  (vl_api_ip_container_proxy_add_del_t * mp)
+{
+  vl_api_ip_container_proxy_add_del_reply_t *rmp;
+  vnet_ip_container_proxy_args_t args;
+  int rv = 0;
+  clib_error_t *error;
+
+  memset (&args, 0, sizeof (args));
+  ip_set (&args.prefix.fp_addr, mp->ip, mp->is_ip4);
+  args.prefix.fp_len = mp->plen ? mp->plen : (mp->is_ip4 ? 32 : 128);
+  args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
+  args.is_add = mp->is_add;
+  if ((error = vnet_ip_container_proxy_add_del (&args)))
+    {
+      rv = clib_error_get_code (error);
+      clib_error_report (error);
+    }
+
+  REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY);
+}
+
 #define vl_msg_name_crc_list
 #include <vnet/ip/ip.api.h>
 #undef vl_msg_name_crc_list