devices: tap API cleanup
[vpp.git] / src / vat / api_format.c
index 3ad4ec6..6e1ebf9 100644 (file)
@@ -1100,7 +1100,7 @@ vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
 {
   vat_main_t *vam = &vat_main;
   vat_json_node_t node;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   void *oldheap;
   u8 *reply;
 
@@ -2710,7 +2710,7 @@ static void vl_api_get_node_graph_reply_t_handler
   (vl_api_get_node_graph_reply_t * mp)
 {
   vat_main_t *vam = &vat_main;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   i32 retval = ntohl (mp->retval);
   u8 *pvt_copy, *reply;
   void *oldheap;
@@ -2773,7 +2773,7 @@ static void vl_api_get_node_graph_reply_t_handler_json
   (vl_api_get_node_graph_reply_t * mp)
 {
   vat_main_t *vam = &vat_main;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   void *oldheap;
   vat_json_node_t node;
   u8 *reply;
@@ -5071,6 +5071,9 @@ _(l2fib_flush_int_reply)                                \
 _(l2fib_flush_bd_reply)                                 \
 _(ip_route_add_del_reply)                               \
 _(ip_table_add_del_reply)                               \
+_(ip_table_replace_begin_reply)                         \
+_(ip_table_flush_reply)                                 \
+_(ip_table_replace_end_reply)                           \
 _(ip_mroute_add_del_reply)                              \
 _(mpls_route_add_del_reply)                             \
 _(mpls_table_add_del_reply)                             \
@@ -5081,7 +5084,6 @@ _(proxy_arp_add_del_reply)                              \
 _(proxy_arp_intfc_enable_disable_reply)                 \
 _(sw_interface_set_unnumbered_reply)                    \
 _(ip_neighbor_add_del_reply)                            \
-_(reset_fib_reply)                                      \
 _(set_ip_flow_hash_reply)                               \
 _(sw_interface_ip6_enable_disable_reply)                \
 _(ip6nd_proxy_add_del_reply)                            \
@@ -5270,6 +5272,9 @@ _(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details)                 \
 _(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details)               \
 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply)                      \
 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply)                      \
+_(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply)           \
+_(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply)                           \
+_(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply)               \
 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply)                    \
 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply)                  \
 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply)                  \
@@ -5285,7 +5290,6 @@ _(SW_INTERFACE_SET_UNNUMBERED_REPLY,                                    \
 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply)                 \
 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply)                     \
 _(CREATE_SUBIF_REPLY, create_subif_reply)                              \
-_(RESET_FIB_REPLY, reset_fib_reply)                                     \
 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply)                       \
 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY,                                \
   sw_interface_ip6_enable_disable_reply)                                \
@@ -7470,8 +7474,8 @@ api_tap_create_v2 (vat_main_t * vam)
   mp->id = ntohl (id);
   mp->host_namespace_set = host_ns != 0;
   mp->host_bridge_set = host_bridge != 0;
-  mp->host_ip4_addr_set = host_ip4_prefix_len != 0;
-  mp->host_ip6_addr_set = host_ip6_prefix_len != 0;
+  mp->host_ip4_prefix_set = host_ip4_prefix_len != 0;
+  mp->host_ip6_prefix_set = host_ip6_prefix_len != 0;
   mp->rx_ring_sz = ntohs (rx_ring_sz);
   mp->tx_ring_sz = ntohs (tx_ring_sz);
   mp->host_mtu_set = host_mtu_set;
@@ -7489,9 +7493,9 @@ api_tap_create_v2 (vat_main_t * vam)
   if (host_bridge)
     clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
   if (host_ip4_prefix_len)
-    clib_memcpy (mp->host_ip4_addr, &host_ip4_addr, 4);
+    clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
   if (host_ip6_prefix_len)
-    clib_memcpy (mp->host_ip6_addr, &host_ip6_addr, 16);
+    clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
   if (host_ip4_gw_set)
     clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
   if (host_ip6_gw_set)
@@ -9210,19 +9214,18 @@ api_create_subif (vat_main_t * vam)
 }
 
 static int
-api_reset_fib (vat_main_t * vam)
+api_ip_table_replace_begin (vat_main_t * vam)
 {
   unformat_input_t *i = vam->input;
-  vl_api_reset_fib_t *mp;
-  u32 vrf_id = 0;
+  vl_api_ip_table_replace_begin_t *mp;
+  u32 table_id = 0;
   u8 is_ipv6 = 0;
-  u8 vrf_id_set = 0;
 
   int ret;
   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (i, "vrf %d", &vrf_id))
-       vrf_id_set = 1;
+      if (unformat (i, "table %d", &table_id))
+       ;
       else if (unformat (i, "ipv6"))
        is_ipv6 = 1;
       else
@@ -9232,16 +9235,74 @@ api_reset_fib (vat_main_t * vam)
        }
     }
 
-  if (vrf_id_set == 0)
+  M (IP_TABLE_REPLACE_BEGIN, mp);
+
+  mp->table.table_id = ntohl (table_id);
+  mp->table.is_ip6 = is_ipv6;
+
+  S (mp);
+  W (ret);
+  return ret;
+}
+
+static int
+api_ip_table_flush (vat_main_t * vam)
+{
+  unformat_input_t *i = vam->input;
+  vl_api_ip_table_flush_t *mp;
+  u32 table_id = 0;
+  u8 is_ipv6 = 0;
+
+  int ret;
+  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     {
-      errmsg ("missing vrf id");
-      return -99;
+      if (unformat (i, "table %d", &table_id))
+       ;
+      else if (unformat (i, "ipv6"))
+       is_ipv6 = 1;
+      else
+       {
+         clib_warning ("parse error '%U'", format_unformat_error, i);
+         return -99;
+       }
     }
 
-  M (RESET_FIB, mp);
+  M (IP_TABLE_FLUSH, mp);
 
-  mp->vrf_id = ntohl (vrf_id);
-  mp->is_ipv6 = is_ipv6;
+  mp->table.table_id = ntohl (table_id);
+  mp->table.is_ip6 = is_ipv6;
+
+  S (mp);
+  W (ret);
+  return ret;
+}
+
+static int
+api_ip_table_replace_end (vat_main_t * vam)
+{
+  unformat_input_t *i = vam->input;
+  vl_api_ip_table_replace_end_t *mp;
+  u32 table_id = 0;
+  u8 is_ipv6 = 0;
+
+  int ret;
+  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (i, "table %d", &table_id))
+       ;
+      else if (unformat (i, "ipv6"))
+       is_ipv6 = 1;
+      else
+       {
+         clib_warning ("parse error '%U'", format_unformat_error, i);
+         return -99;
+       }
+    }
+
+  M (IP_TABLE_REPLACE_END, mp);
+
+  mp->table.table_id = ntohl (table_id);
+  mp->table.is_ip6 = is_ipv6;
 
   S (mp);
   W (ret);
@@ -9796,6 +9857,7 @@ api_sr_localsid_add_del (vat_main_t * vam)
   M (SR_LOCALSID_ADD_DEL, mp);
 
   clib_memcpy (mp->localsid.addr, &localsid, sizeof (mp->localsid));
+
   if (nexthop_set)
     {
       clib_memcpy (mp->nh_addr6, &nh_addr6, sizeof (mp->nh_addr6));
@@ -11575,17 +11637,17 @@ api_l2tpv3_create_tunnel (vat_main_t * vam)
 
   M (L2TPV3_CREATE_TUNNEL, mp);
 
-  clib_memcpy (mp->client_address, client_address.as_u8,
-              sizeof (mp->client_address));
+  clib_memcpy (mp->client_address.un.ip6, client_address.as_u8,
+              sizeof (ip6_address_t));
 
-  clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
+  clib_memcpy (mp->our_address.un.ip6, our_address.as_u8,
+              sizeof (ip6_address_t));
 
   mp->local_session_id = ntohl (local_session_id);
   mp->remote_session_id = ntohl (remote_session_id);
   mp->local_cookie = clib_host_to_net_u64 (local_cookie);
   mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
   mp->l2_sublayer_present = l2_sublayer_present;
-  mp->is_ipv6 = 1;
 
   S (mp);
   W (ret);
@@ -11750,9 +11812,9 @@ static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
 
   vat_json_init_object (node);
 
-  clib_memcpy (&addr, mp->our_address, sizeof (addr));
+  clib_memcpy (&addr, mp->our_address.un.ip6, sizeof (addr));
   vat_json_object_add_ip6 (node, "our_address", addr);
-  clib_memcpy (&addr, mp->client_address, sizeof (addr));
+  clib_memcpy (&addr, mp->client_address.un.ip6, sizeof (addr));
   vat_json_object_add_ip6 (node, "client_address", addr);
 
   vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
@@ -11797,10 +11859,12 @@ static void vl_api_sw_interface_tap_v2_details_t_handler
 {
   vat_main_t *vam = &vat_main;
 
-  u8 *ip4 = format (0, "%U/%d", format_ip4_address, mp->host_ip4_addr,
-                   mp->host_ip4_prefix_len);
-  u8 *ip6 = format (0, "%U/%d", format_ip6_address, mp->host_ip6_addr,
-                   mp->host_ip6_prefix_len);
+  u8 *ip4 =
+    format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
+           mp->host_ip4_prefix.len);
+  u8 *ip6 =
+    format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
+           mp->host_ip6_prefix.len);
 
   print (vam->ofp,
         "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
@@ -11841,12 +11905,12 @@ static void vl_api_sw_interface_tap_v2_details_t_handler_json
   vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
   vat_json_object_add_string_copy (node, "host_ip4_addr",
                                   format (0, "%U/%d", format_ip4_address,
-                                          mp->host_ip4_addr,
-                                          mp->host_ip4_prefix_len));
-  vat_json_object_add_string_copy (node, "host_ip6_addr",
+                                          mp->host_ip4_prefix.address,
+                                          mp->host_ip4_prefix.len));
+  vat_json_object_add_string_copy (node, "host_ip6_prefix",
                                   format (0, "%U/%d", format_ip6_address,
-                                          mp->host_ip6_addr,
-                                          mp->host_ip6_prefix_len));
+                                          mp->host_ip6_prefix.address,
+                                          mp->host_ip6_prefix.len));
 
 }
 
@@ -12589,7 +12653,7 @@ api_gre_tunnel_add_del (vat_main_t * vam)
   u8 is_add = 1;
   u8 src_set = 0;
   u8 dst_set = 0;
-  u32 outer_fib_id = 0;
+  u32 outer_table_id = 0;
   u32 session_id = 0;
   u32 instance = ~0;
   int ret;
@@ -12610,7 +12674,7 @@ api_gre_tunnel_add_del (vat_main_t * vam)
        {
          dst_set = 1;
        }
-      else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
+      else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
        ;
       else if (unformat (line_input, "teb"))
        t_type = GRE_API_TUNNEL_TYPE_TEB;
@@ -12640,7 +12704,7 @@ api_gre_tunnel_add_del (vat_main_t * vam)
   clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
 
   mp->tunnel.instance = htonl (instance);
-  mp->tunnel.outer_fib_id = htonl (outer_fib_id);
+  mp->tunnel.outer_table_id = htonl (outer_table_id);
   mp->is_add = is_add;
   mp->tunnel.session_id = htons ((u16) session_id);
   mp->tunnel.type = htonl (t_type);
@@ -12660,7 +12724,7 @@ static void vl_api_gre_tunnel_details_t_handler
         ntohl (mp->tunnel.instance),
         format_vl_api_address, &mp->tunnel.src,
         format_vl_api_address, &mp->tunnel.dst,
-        mp->tunnel.type, ntohl (mp->tunnel.outer_fib_id),
+        mp->tunnel.type, ntohl (mp->tunnel.outer_table_id),
         ntohl (mp->tunnel.session_id));
 }
 
@@ -12685,8 +12749,8 @@ static void vl_api_gre_tunnel_details_t_handler_json
   vat_json_object_add_address (node, "src", &mp->tunnel.src);
   vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
   vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
-  vat_json_object_add_uint (node, "outer_fib_id",
-                           ntohl (mp->tunnel.outer_fib_id));
+  vat_json_object_add_uint (node, "outer_table_id",
+                           ntohl (mp->tunnel.outer_table_id));
   vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
 }
 
@@ -16278,13 +16342,13 @@ api_one_use_petr (vat_main_t * vam)
        if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
        {
          is_add = 1;
-         ip_addr_version (&ip) = IP4;
+         ip_addr_version (&ip) = AF_IP4;
        }
       else
        if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
        {
          is_add = 1;
-         ip_addr_version (&ip) = IP6;
+         ip_addr_version (&ip) = AF_IP6;
        }
       else
        {
@@ -16298,7 +16362,7 @@ api_one_use_petr (vat_main_t * vam)
   mp->is_add = is_add;
   if (is_add)
     {
-      mp->is_ip4 = ip_addr_version (&ip) == IP4 ? 1 : 0;
+      mp->is_ip4 = ip_addr_version (&ip) == AF_IP4 ? 1 : 0;
       if (mp->is_ip4)
        clib_memcpy (mp->address, &ip, 4);
       else
@@ -21271,7 +21335,7 @@ value_sort_cmp (void *a1, void *a2)
 static int
 dump_msg_api_table (vat_main_t * vam)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   name_sort_t *nses = 0, *ns;
   hash_pair_t *hp;
   int i;
@@ -21545,7 +21609,9 @@ _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n"               \
   "[outer_vlan_id <n>][inner_vlan_id <n>]\n"                            \
   "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n"    \
   "[outer_vlan_id_any][inner_vlan_id_any]")                             \
-_(reset_fib, "vrf <n> [ipv6]")                                          \
+_(ip_table_replace_begin, "table <n> [ipv6]")                           \
+_(ip_table_flush, "table <n> [ipv6]")                                   \
+_(ip_table_replace_end, "table <n> [ipv6]")                             \
 _(set_ip_flow_hash,                                                     \
   "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]")       \
 _(sw_interface_ip6_enable_disable,                                      \