Trivial: Clean up some typos.
[vpp.git] / src / plugins / gbp / gbp_api.c
index 1f24eed..0cbe991 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <vnet/interface.h>
 #include <vnet/api_errno.h>
+#include <vnet/ip/ip_types_api.h>
+#include <vnet/ethernet/ethernet_types_api.h>
 #include <vpp/app/version.h>
 
 #include <gbp/gbp.h>
@@ -52,7 +54,8 @@
 #include <vlibapi/api_helper_macros.h>
 
 #define foreach_gbp_api_msg                                 \
-  _(GBP_ENDPOINT_ADD_DEL, gbp_endpoint_add_del)             \
+  _(GBP_ENDPOINT_ADD, gbp_endpoint_add)                     \
+  _(GBP_ENDPOINT_DEL, gbp_endpoint_del)                     \
   _(GBP_ENDPOINT_DUMP, gbp_endpoint_dump)                   \
   _(GBP_SUBNET_ADD_DEL, gbp_subnet_add_del)                 \
   _(GBP_SUBNET_DUMP, gbp_subnet_dump)                       \
@@ -70,39 +73,55 @@ static u16 msg_id_base;
 #define GBP_MSG_BASE msg_id_base
 
 static void
-vl_api_gbp_endpoint_add_del_t_handler (vl_api_gbp_endpoint_add_del_t * mp)
+vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp)
 {
-  vl_api_gbp_endpoint_add_del_reply_t *rmp;
-  ip46_address_t ip = { };
-  u32 sw_if_index;
-  int rv = 0;
+  vl_api_gbp_endpoint_add_reply_t *rmp;
+  u32 sw_if_index, handle;
+  ip46_address_t *ips;
+  mac_address_t mac;
+  int rv = 0, ii;
+
+  VALIDATE_SW_IF_INDEX (&(mp->endpoint));
 
   sw_if_index = ntohl (mp->endpoint.sw_if_index);
-  if (!vnet_sw_if_index_is_api_valid (sw_if_index))
-    goto bad_sw_if_index;
 
-  if (mp->endpoint.is_ip6)
-    {
-      clib_memcpy (&ip.ip6, mp->endpoint.address, sizeof (ip.ip6));
-    }
-  else
-    {
-      clib_memcpy (&ip.ip4, mp->endpoint.address, sizeof (ip.ip4));
-    }
+  ips = NULL;
 
-  if (mp->is_add)
-    {
-      rv =
-       gbp_endpoint_update (sw_if_index, &ip, ntohl (mp->endpoint.epg_id));
-    }
-  else
+  if (mp->endpoint.n_ips)
     {
-      gbp_endpoint_delete (sw_if_index, &ip);
+      vec_validate (ips, mp->endpoint.n_ips - 1);
+
+      vec_foreach_index (ii, ips)
+      {
+       ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
+      }
     }
+  mac_address_decode (&mp->endpoint.mac, &mac);
+
+  rv = gbp_endpoint_update (sw_if_index, ips, &mac,
+                           ntohs (mp->endpoint.epg_id), &handle);
+
+  vec_free (ips);
 
   BAD_SW_IF_INDEX_LABEL;
 
-  REPLY_MACRO (VL_API_GBP_ENDPOINT_ADD_DEL_REPLY + GBP_MSG_BASE);
+  /* *INDENT-OFF* */
+  REPLY_MACRO2 (VL_API_GBP_ENDPOINT_ADD_REPLY + GBP_MSG_BASE,
+  ({
+    rmp->handle = htonl (handle);
+  }));
+  /* *INDENT-ON* */
+}
+
+static void
+vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp)
+{
+  vl_api_gbp_endpoint_del_reply_t *rmp;
+  int rv = 0;
+
+  gbp_endpoint_delete (ntohl (mp->handle));
+
+  REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE);
 }
 
 typedef struct gbp_walk_ctx_t_
@@ -111,14 +130,16 @@ typedef struct gbp_walk_ctx_t_
   u32 context;
 } gbp_walk_ctx_t;
 
-static int
+static walk_rc_t
 gbp_endpoint_send_details (gbp_endpoint_t * gbpe, void *args)
 {
   vl_api_gbp_endpoint_details_t *mp;
   gbp_walk_ctx_t *ctx;
+  u8 n_ips, ii;
 
   ctx = args;
-  mp = vl_msg_api_alloc (sizeof (*mp));
+  n_ips = vec_len (gbpe->ge_ips);
+  mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
   if (!mp)
     return 1;
 
@@ -126,22 +147,20 @@ gbp_endpoint_send_details (gbp_endpoint_t * gbpe, void *args)
   mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
   mp->context = ctx->context;
 
-  mp->endpoint.sw_if_index = ntohl (gbpe->ge_key->gek_sw_if_index);
-  mp->endpoint.is_ip6 = !ip46_address_is_ip4 (&gbpe->ge_key->gek_ip);
-  if (mp->endpoint.is_ip6)
-    clib_memcpy (&mp->endpoint.address,
-                &gbpe->ge_key->gek_ip.ip6,
-                sizeof (gbpe->ge_key->gek_ip.ip6));
-  else
-    clib_memcpy (&mp->endpoint.address,
-                &gbpe->ge_key->gek_ip.ip4,
-                sizeof (gbpe->ge_key->gek_ip.ip4));
+  mp->endpoint.sw_if_index = ntohl (gbpe->ge_sw_if_index);
+  mp->endpoint.epg_id = ntohs (gbpe->ge_epg_id);
+  mp->endpoint.n_ips = n_ips;
+  mac_address_encode (&gbpe->ge_mac, &mp->endpoint.mac);
 
-  mp->endpoint.epg_id = ntohl (gbpe->ge_epg_id);
+  vec_foreach_index (ii, gbpe->ge_ips)
+  {
+    ip_address_encode (&gbpe->ge_ips[ii], IP46_TYPE_ANY,
+                      &mp->endpoint.ips[ii]);
+  }
 
   vl_api_send_msg (ctx->reg, (u8 *) mp);
 
-  return (1);
+  return (WALK_CONTINUE);
 }
 
 static void
@@ -175,7 +194,7 @@ static void
 
   if (mp->is_add)
     {
-      rv = gbp_endpoint_group_add (ntohl (mp->epg.epg_id),
+      rv = gbp_endpoint_group_add (ntohs (mp->epg.epg_id),
                                   ntohl (mp->epg.bd_id),
                                   ntohl (mp->epg.ip4_table_id),
                                   ntohl (mp->epg.ip6_table_id),
@@ -183,7 +202,7 @@ static void
     }
   else
     {
-      gbp_endpoint_group_delete (ntohl (mp->epg.epg_id));
+      gbp_endpoint_group_delete (ntohs (mp->epg.epg_id));
     }
 
   BAD_SW_IF_INDEX_LABEL;
@@ -195,23 +214,15 @@ static void
 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
 {
   vl_api_gbp_subnet_add_del_reply_t *rmp;
+  fib_prefix_t pfx;
   int rv = 0;
-  fib_prefix_t pfx = {
-    .fp_len = mp->subnet.address_length,
-    .fp_proto = (mp->subnet.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4),
-  };
 
-  if (mp->subnet.is_ip6)
-    clib_memcpy (&pfx.fp_addr.ip6, mp->subnet.address,
-                sizeof (pfx.fp_addr.ip6));
-  else
-    clib_memcpy (&pfx.fp_addr.ip4, mp->subnet.address,
-                sizeof (pfx.fp_addr.ip4));
+  ip_prefix_decode (&mp->subnet.prefix, &pfx);
 
   rv = gbp_subnet_add_del (ntohl (mp->subnet.table_id),
                           &pfx,
                           ntohl (mp->subnet.sw_if_index),
-                          ntohl (mp->subnet.epg_id),
+                          ntohs (mp->subnet.epg_id),
                           mp->is_add, mp->subnet.is_internal);
 
   REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
@@ -237,17 +248,9 @@ gbp_subnet_send_details (u32 table_id,
 
   mp->subnet.is_internal = is_internal;
   mp->subnet.sw_if_index = ntohl (sw_if_index);
-  mp->subnet.epg_id = ntohl (epg);
-  mp->subnet.is_ip6 = (pfx->fp_proto == FIB_PROTOCOL_IP6);
-  mp->subnet.address_length = pfx->fp_len;
+  mp->subnet.epg_id = ntohs (epg);
   mp->subnet.table_id = ntohl (table_id);
-  if (mp->subnet.is_ip6)
-    clib_memcpy (&mp->subnet.address,
-                &pfx->fp_addr.ip6, sizeof (pfx->fp_addr.ip6));
-  else
-    clib_memcpy (&mp->subnet.address,
-                &pfx->fp_addr.ip4, sizeof (pfx->fp_addr.ip4));
-
+  ip_prefix_encode (pfx, &mp->subnet.prefix);
 
   vl_api_send_msg (ctx->reg, (u8 *) mp);
 
@@ -287,7 +290,7 @@ gbp_endpoint_group_send_details (gbp_endpoint_group_t * gepg, void *args)
   mp->context = ctx->context;
 
   mp->epg.uplink_sw_if_index = ntohl (gepg->gepg_uplink_sw_if_index);
-  mp->epg.epg_id = ntohl (gepg->gepg_id);
+  mp->epg.epg_id = ntohs (gepg->gepg_id);
   mp->epg.bd_id = ntohl (gepg->gepg_bd);
   mp->epg.ip4_table_id = ntohl (gepg->gepg_rd[FIB_PROTOCOL_IP4]);
   mp->epg.ip6_table_id = ntohl (gepg->gepg_rd[FIB_PROTOCOL_IP6]);
@@ -328,7 +331,7 @@ vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
 
   if (mp->is_add)
     gbp_recirc_add (sw_if_index,
-                   ntohl (mp->recirc.epg_id), mp->recirc.is_ext);
+                   ntohs (mp->recirc.epg_id), mp->recirc.is_ext);
   else
     gbp_recirc_delete (sw_if_index);
 
@@ -352,7 +355,7 @@ gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
   mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
   mp->context = ctx->context;
 
-  mp->recirc.epg_id = ntohl (gr->gr_epg);
+  mp->recirc.epg_id = ntohs (gr->gr_epg);
   mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
   mp->recirc.is_ext = ntohl (gr->gr_is_ext);
 
@@ -385,12 +388,12 @@ vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
   int rv = 0;
 
   if (mp->is_add)
-    gbp_contract_update (ntohl (mp->contract.src_epg),
-                        ntohl (mp->contract.dst_epg),
+    gbp_contract_update (ntohs (mp->contract.src_epg),
+                        ntohs (mp->contract.dst_epg),
                         ntohl (mp->contract.acl_index));
   else
-    gbp_contract_delete (ntohl (mp->contract.src_epg),
-                        ntohl (mp->contract.dst_epg));
+    gbp_contract_delete (ntohs (mp->contract.src_epg),
+                        ntohs (mp->contract.dst_epg));
 
   REPLY_MACRO (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE);
 }
@@ -410,8 +413,8 @@ gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
   mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
   mp->context = ctx->context;
 
-  mp->contract.src_epg = ntohl (gbpc->gc_key.gck_src);
-  mp->contract.dst_epg = ntohl (gbpc->gc_key.gck_dst);
+  mp->contract.src_epg = ntohs (gbpc->gc_key.gck_src);
+  mp->contract.dst_epg = ntohs (gbpc->gc_key.gck_dst);
   mp->contract.acl_index = ntohl (gbpc->gc_value.gc_acl_index);
 
   vl_api_send_msg (ctx->reg, (u8 *) mp);
@@ -439,7 +442,7 @@ vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
 /*
  * gbp_api_hookup
  * Add vpe's API message handlers to the table.
- * vlib has alread mapped shared memory and
+ * vlib has already mapped shared memory and
  * added the client registration handlers.
  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
  */