IPSEC-GRE: fixes and API update to common types.
[vpp.git] / src / vat / api_format.c
index 9986268..bdfa8c1 100644 (file)
@@ -934,11 +934,14 @@ static void vl_api_sw_interface_details_t_handler
       sub->sw_if_index = ntohl (mp->sw_if_index);
       sub->sub_id = ntohl (mp->sub_id);
 
-      sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
-
+      sub->sub_dot1ad = mp->sub_dot1ad;
       sub->sub_number_of_tags = mp->sub_number_of_tags;
       sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
       sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
+      sub->sub_exact_match = mp->sub_exact_match;
+      sub->sub_default = mp->sub_default;
+      sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
+      sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
 
       /* vlan tag rewrite */
       sub->vtr_op = ntohl (mp->vtr_op);
@@ -965,28 +968,37 @@ static void vl_api_sw_interface_details_t_handler_json
   vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
   vat_json_object_add_uint (node, "sup_sw_if_index",
                            ntohl (mp->sup_sw_if_index));
+  vat_json_object_add_uint (node, "l2_address_length",
+                           ntohl (mp->l2_address_length));
   vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
                             sizeof (mp->l2_address));
   vat_json_object_add_string_copy (node, "interface_name",
-                                  mp->interface_name.buf);
-  vat_json_object_add_uint (node, "flags", mp->flags);
+                                  mp->interface_name);
+  vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
+  vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
   vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
   vat_json_object_add_uint (node, "link_speed", mp->link_speed);
   vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
   vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
+  vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
   vat_json_object_add_uint (node, "sub_number_of_tags",
                            mp->sub_number_of_tags);
   vat_json_object_add_uint (node, "sub_outer_vlan_id",
                            ntohs (mp->sub_outer_vlan_id));
   vat_json_object_add_uint (node, "sub_inner_vlan_id",
                            ntohs (mp->sub_inner_vlan_id));
-  vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
+  vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
+  vat_json_object_add_uint (node, "sub_default", mp->sub_default);
+  vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
+                           mp->sub_outer_vlan_id_any);
+  vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
+                           mp->sub_inner_vlan_id_any);
   vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
   vat_json_object_add_uint (node, "vtr_push_dot1q",
                            ntohl (mp->vtr_push_dot1q));
   vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
   vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
-  if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
+  if (mp->sub_dot1ah)
     {
       vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
                                       format (0, "%U",
@@ -1009,10 +1021,8 @@ static void vl_api_sw_interface_event_t_handler
   if (vam->interface_event_display)
     errmsg ("interface flags: sw_if_index %d %s %s",
            ntohl (mp->sw_if_index),
-           ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
-           "admin-up" : "admin-down",
-           ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
-           "link-up" : "link-down");
+           mp->admin_up_down ? "admin-up" : "admin-down",
+           mp->link_up_down ? "link-up" : "link-down");
 }
 #endif
 
@@ -5020,8 +5030,8 @@ static void vl_api_policer_classify_details_t_handler_json
   vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
 }
 
-static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
-  (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
+static void vl_api_ipsec_gre_tunnel_add_del_reply_t_handler
+  (vl_api_ipsec_gre_tunnel_add_del_reply_t * mp)
 {
   vat_main_t *vam = &vat_main;
   i32 retval = ntohl (mp->retval);
@@ -5038,8 +5048,8 @@ static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
   vam->regenerate_interface_table = 1;
 }
 
-static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
-  (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
+static void vl_api_ipsec_gre_tunnel_add_del_reply_t_handler_json
+  (vl_api_ipsec_gre_tunnel_add_del_reply_t * mp)
 {
   vat_main_t *vam = &vat_main;
   vat_json_node_t node;
@@ -5540,7 +5550,7 @@ _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY,                         \
  ip_source_and_port_range_check_add_del_reply)                          \
 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY,               \
  ip_source_and_port_range_check_interface_add_del_reply)                \
-_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply)       \
+_(IPSEC_GRE_TUNNEL_ADD_DEL_REPLY, ipsec_gre_tunnel_add_del_reply)       \
 _(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details)                   \
 _(DELETE_SUBIF_REPLY, delete_subif_reply)                               \
 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
@@ -5992,7 +6002,7 @@ api_sw_interface_set_flags (vat_main_t * vam)
   /* Construct the API message */
   M (SW_INTERFACE_SET_FLAGS, mp);
   mp->sw_if_index = ntohl (sw_if_index);
-  mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
+  mp->admin_up_down = admin_up;
 
   /* send it... */
   S (mp);
@@ -6284,15 +6294,14 @@ api_sw_interface_add_del_address (vat_main_t * vam)
   mp->del_all = del_all;
   if (v6_address_set)
     {
-      mp->prefix.address.af = ADDRESS_IP6;
-      clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
+      mp->is_ipv6 = 1;
+      clib_memcpy (mp->address, &v6address, sizeof (v6address));
     }
   else
     {
-      mp->prefix.address.af = ADDRESS_IP4;
-      clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
+      clib_memcpy (mp->address, &v4address, sizeof (v4address));
     }
-  mp->prefix.address_length = address_length;
+  mp->address_length = address_length;
 
   /* send it... */
   S (mp);
@@ -9427,16 +9436,6 @@ _(default_sub)                                  \
 _(outer_vlan_id_any)                            \
 _(inner_vlan_id_any)
 
-#define foreach_create_subif_flag              \
-_(0, "no_tags")                                        \
-_(1, "one_tag")                                        \
-_(2, "two_tags")                               \
-_(3, "dot1ad")                                 \
-_(4, "exact_match")                            \
-_(5, "default_sub")                            \
-_(6, "outer_vlan_id_any")                      \
-_(7, "inner_vlan_id_any")
-
 static int
 api_create_subif (vat_main_t * vam)
 {
@@ -9499,8 +9498,8 @@ api_create_subif (vat_main_t * vam)
   mp->sw_if_index = ntohl (sw_if_index);
   mp->sub_id = ntohl (sub_id);
 
-#define _(a,b) mp->sub_if_flags |= (1 << a);
-  foreach_create_subif_flag;
+#define _(a) mp->a = a;
+  foreach_create_subif_bit;
 #undef _
 
   mp->outer_vlan_id = ntohs (outer_vlan_id);
@@ -15029,8 +15028,8 @@ api_ipsec_tunnel_if_add_del (vat_main_t * vam)
   u32 crypto_alg = 0, integ_alg = 0;
   u8 *lck = NULL, *rck = NULL;
   u8 *lik = NULL, *rik = NULL;
-  ip4_address_t local_ip = { {0} };
-  ip4_address_t remote_ip = { {0} };
+  vl_api_address_t local_ip = { 0 };
+  vl_api_address_t remote_ip = { 0 };
   u8 is_add = 1;
   u8 esn = 0;
   u8 anti_replay = 0;
@@ -15050,9 +15049,11 @@ api_ipsec_tunnel_if_add_del (vat_main_t * vam)
        ;
       else if (unformat (i, "remote_spi %d", &remote_spi))
        ;
-      else if (unformat (i, "local_ip %U", unformat_ip4_address, &local_ip))
+      else
+       if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
        ;
-      else if (unformat (i, "remote_ip %U", unformat_ip4_address, &remote_ip))
+      else
+       if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
        ;
       else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
        ;
@@ -15100,8 +15101,8 @@ api_ipsec_tunnel_if_add_del (vat_main_t * vam)
   mp->esn = esn;
   mp->anti_replay = anti_replay;
 
-  clib_memcpy (mp->local_ip, &local_ip, sizeof (ip4_address_t));
-  clib_memcpy (mp->remote_ip, &remote_ip, sizeof (ip4_address_t));
+  clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
+  clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
 
   mp->local_spi = htonl (local_spi);
   mp->remote_spi = htonl (remote_spi);
@@ -15230,8 +15231,7 @@ static void vl_api_ipsec_sa_details_t_handler_json
                            ntohl (mp->entry.integrity_algorithm));
   flags = ntohl (mp->entry.flags);
   vat_json_object_add_uint (node, "use_esn",
-                           ! !(flags &
-                               IPSEC_API_SAD_FLAG_USE_EXTENDED_SEQ_NUM));
+                           ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
   vat_json_object_add_uint (node, "use_anti_replay",
                            ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
   vat_json_object_add_uint (node, "is_tunnel",
@@ -20346,14 +20346,14 @@ api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
 }
 
 static int
-api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
+api_ipsec_gre_tunnel_add_del (vat_main_t * vam)
 {
   unformat_input_t *i = vam->input;
-  vl_api_ipsec_gre_add_del_tunnel_t *mp;
+  vl_api_ipsec_gre_tunnel_add_del_t *mp;
   u32 local_sa_id = 0;
   u32 remote_sa_id = 0;
-  ip4_address_t src_address;
-  ip4_address_t dst_address;
+  vl_api_ip4_address_t src_address;
+  vl_api_ip4_address_t dst_address;
   u8 is_add = 1;
   int ret;
 
@@ -20363,9 +20363,11 @@ api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
        ;
       else if (unformat (i, "remote_sa %d", &remote_sa_id))
        ;
-      else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
+      else
+       if (unformat (i, "src %U", unformat_vl_api_ip4_address, &src_address))
        ;
-      else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
+      else
+       if (unformat (i, "dst %U", unformat_vl_api_ip4_address, &dst_address))
        ;
       else if (unformat (i, "del"))
        is_add = 0;
@@ -20376,12 +20378,12 @@ api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
        }
     }
 
-  M (IPSEC_GRE_ADD_DEL_TUNNEL, mp);
+  M (IPSEC_GRE_TUNNEL_ADD_DEL, mp);
 
-  mp->local_sa_id = ntohl (local_sa_id);
-  mp->remote_sa_id = ntohl (remote_sa_id);
-  clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
-  clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
+  mp->tunnel.local_sa_id = ntohl (local_sa_id);
+  mp->tunnel.remote_sa_id = ntohl (remote_sa_id);
+  clib_memcpy (mp->tunnel.src, &src_address, sizeof (src_address));
+  clib_memcpy (mp->tunnel.dst, &dst_address, sizeof (dst_address));
   mp->is_add = is_add;
 
   S (mp);
@@ -20435,10 +20437,21 @@ static void vl_api_ipsec_gre_tunnel_details_t_handler
   vat_main_t *vam = &vat_main;
 
   print (vam->ofp, "%11d%15U%15U%14d%14d",
-        ntohl (mp->sw_if_index),
-        format_ip4_address, &mp->src_address,
-        format_ip4_address, &mp->dst_address,
-        ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
+        ntohl (mp->tunnel.sw_if_index),
+        format_vl_api_ip4_address, mp->tunnel.src,
+        format_vl_api_ip4_address, mp->tunnel.dst,
+        ntohl (mp->tunnel.local_sa_id), ntohl (mp->tunnel.remote_sa_id));
+}
+
+static void
+vat_json_object_add_vl_api_ip4 (vat_json_node_t * node,
+                               const char *name,
+                               const vl_api_ip4_address_t addr)
+{
+  struct in_addr ip4;
+
+  clib_memcpy (&ip4, addr, sizeof (ip4));
+  vat_json_object_add_ip4 (node, name, ip4);
 }
 
 static void vl_api_ipsec_gre_tunnel_details_t_handler_json
@@ -20456,13 +20469,14 @@ static void vl_api_ipsec_gre_tunnel_details_t_handler_json
   node = vat_json_array_add (&vam->json_tree);
 
   vat_json_init_object (node);
-  vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
-  clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
-  vat_json_object_add_ip4 (node, "src_address", ip4);
-  clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
-  vat_json_object_add_ip4 (node, "dst_address", ip4);
-  vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
-  vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
+  vat_json_object_add_uint (node, "sw_if_index",
+                           ntohl (mp->tunnel.sw_if_index));
+  vat_json_object_add_vl_api_ip4 (node, "src", mp->tunnel.src);
+  vat_json_object_add_vl_api_ip4 (node, "src", mp->tunnel.dst);
+  vat_json_object_add_uint (node, "local_sa_id",
+                           ntohl (mp->tunnel.local_sa_id));
+  vat_json_object_add_uint (node, "remote_sa_id",
+                           ntohl (mp->tunnel.remote_sa_id));
 }
 
 static int
@@ -20828,7 +20842,7 @@ api_sw_interface_tag_add_del (vat_main_t * vam)
   mp->sw_if_index = ntohl (sw_if_index);
   mp->is_add = enable;
   if (enable)
-    vl_api_to_api_string (strlen ((char *) tag), tag, &mp->tag);
+    strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
   vec_free (tag);
 
   S (mp);
@@ -22657,7 +22671,7 @@ _(ip_source_and_port_range_check_add_del,                               \
 _(ip_source_and_port_range_check_interface_add_del,                     \
   "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]"      \
   "[udp-in-vrf <id>] [udp-out-vrf <id>]")                               \
-_(ipsec_gre_add_del_tunnel,                                             \
+_(ipsec_gre_tunnel_add_del,                                             \
   "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]")     \
 _(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]")                          \
 _(delete_subif,"<intfc> | sw_if_index <nn>")                            \