Add af_packet API 17/1017/3
authorMatus Fabian <[email protected]>
Fri, 6 May 2016 13:14:13 +0000 (15:14 +0200)
committerDave Barach <[email protected]>
Tue, 10 May 2016 11:10:37 +0000 (11:10 +0000)
Change-Id: I39409ae9e75fdb59d8cbbd940fa192b24eb79b6a
Signed-off-by: Matus Fabian <[email protected]>
vpp-api-test/vat/api_format.c
vpp/api/api.c
vpp/api/vpe.api

index 6f1db38..1c8a14d 100644 (file)
@@ -2201,7 +2201,9 @@ _(lisp_add_del_local_eid_reply)                         \
 _(lisp_gpe_add_del_fwd_entry_reply)                     \
 _(lisp_add_del_map_resolver_reply)                      \
 _(lisp_gpe_enable_disable_reply)                        \
-_(lisp_gpe_add_del_iface_reply)
+_(lisp_gpe_add_del_iface_reply)                         \
+_(af_packet_create_reply)                               \
+_(af_packet_delete_reply)
 
 #define _(n)                                    \
     static void vl_api_##n##_t_handler          \
@@ -2379,7 +2381,9 @@ _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details)           \
 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details)                     \
 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details)                 \
 _(LISP_GPE_ENABLE_DISABLE_STATUS_DETAILS,                               \
-  lisp_gpe_enable_disable_status_details)
+  lisp_gpe_enable_disable_status_details)                               \
+_(AF_PACKET_CREATE_REPLY, af_packet_create_reply)                       \
+_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply)
 
 /* M: construct, but don't yet send a message */
 
@@ -10201,6 +10205,84 @@ api_lisp_gpe_enable_disable_status_dump(vat_main_t *vam)
     return 0;
 }
 
+static int
+api_af_packet_create (vat_main_t * vam)
+{
+    unformat_input_t * i = vam->input;
+    vl_api_af_packet_create_t * mp;
+    f64 timeout;
+    u8 * host_if_name = 0;
+    u8 hw_addr[6];
+    u8 random_hw_addr = 1;
+
+    memset (hw_addr, 0, sizeof (hw_addr));
+
+    while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+        if (unformat (i, "name %s", &host_if_name))
+            vec_add1 (host_if_name, 0);
+        else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
+            random_hw_addr = 0;
+        else
+          break;
+    }
+
+    if (!vec_len (host_if_name)) {
+        errmsg ("host-interface name must be specified");
+        return -99;
+    }
+
+    if (vec_len (host_if_name) > 64) {
+        errmsg ("host-interface name too long");
+        return -99;
+    }
+
+    M(AF_PACKET_CREATE, af_packet_create);
+
+    clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
+    clib_memcpy (mp->hw_addr, hw_addr, 6);
+    mp->use_random_hw_addr = random_hw_addr;
+    vec_free (host_if_name);
+
+    S; W;
+    /* NOTREACHED */
+    return 0;
+}
+
+static int
+api_af_packet_delete (vat_main_t * vam)
+{
+    unformat_input_t * i = vam->input;
+    vl_api_af_packet_delete_t * mp;
+    f64 timeout;
+    u8 * host_if_name = 0;
+
+    while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+        if (unformat (i, "name %s", &host_if_name))
+            vec_add1 (host_if_name, 0);
+        else
+          break;
+    }
+
+    if (!vec_len (host_if_name)) {
+        errmsg ("host-interface name must be specified");
+        return -99;
+    }
+
+    if (vec_len (host_if_name) > 64) {
+        errmsg ("host-interface name too long");
+        return -99;
+    }
+
+    M(AF_PACKET_DELETE, af_packet_delete);
+
+    clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
+    vec_free (host_if_name);
+
+    S; W;
+    /* NOTREACHED */
+    return 0;
+}
+
 static int q_or_quit (vat_main_t * vam)
 {
     longjmp (vam->jump_buf, 1);
@@ -10688,7 +10770,9 @@ _(lisp_locator_set_dump, "")                                            \
 _(lisp_local_eid_table_dump, "")                                        \
 _(lisp_gpe_tunnel_dump, "")                                             \
 _(lisp_map_resolver_dump, "")                                           \
-_(lisp_gpe_enable_disable_status_dump, "")
+_(lisp_gpe_enable_disable_status_dump, "")                              \
+_(af_packet_create, "name <host interface name> [hw_addr <mac>]")       \
+_(af_packet_delete, "name <host interface name>")
 
 /* List of command functions, CLI names map directly to functions */
 #define foreach_cli_function                                    \
index 5e80879..4d7a919 100644 (file)
@@ -74,6 +74,7 @@
 #include <vnet/map/map.h>
 #include <vnet/cop/cop.h>
 #include <vnet/ip/ip6_hop_by_hop.h>
+#include <vnet/devices/af_packet/af_packet.h>
 
 #undef BIHASH_TYPE
 #undef __included_bihash_template_h__
@@ -332,7 +333,10 @@ _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump)                           \
 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)                       \
 _(LISP_GPE_ENABLE_DISABLE_STATUS_DUMP,                                  \
   lisp_gpe_enable_disable_status_dump)                                  \
-_(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del)
+_(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del)                   \
+_(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del)                   \
+_(AF_PACKET_CREATE, af_packet_create)                                   \
+_(AF_PACKET_DELETE, af_packet_delete)
 
 #define QUOTE_(x) #x
 #define QUOTE(x) QUOTE_(x)
@@ -5861,6 +5865,44 @@ static void vl_api_trace_profile_del_t_handler
     REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
 }
 
+static void
+vl_api_af_packet_create_t_handler
+(vl_api_af_packet_create_t *mp)
+{
+    vlib_main_t *vm = vlib_get_main();
+    vl_api_af_packet_create_reply_t *rmp;
+    int rv = 0;
+    u8 *host_if_name = NULL;
+
+    host_if_name = format(0, "%s", mp->host_if_name);
+    vec_add1 (host_if_name, 0);
+
+    rv = af_packet_create_if(vm, host_if_name,
+                             mp->use_random_hw_addr ? 0 : mp->hw_addr);
+
+    vec_free(host_if_name);
+
+    REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
+}
+
+static void
+vl_api_af_packet_delete_t_handler
+(vl_api_af_packet_delete_t *mp)
+{
+    vlib_main_t * vm = vlib_get_main();
+    vl_api_af_packet_delete_reply_t *rmp;
+    int rv = 0;
+    u8 *host_if_name = NULL;
+
+    host_if_name = format(0, "%s", mp->host_if_name);
+    vec_add1 (host_if_name, 0);
+
+    rv = af_packet_delete_if(vm, host_if_name);
+
+    vec_free(host_if_name);
+
+    REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
+}
 
 #define BOUNCE_HANDLER(nn)                                              \
 static void vl_api_##nn##_t_handler (                                   \
index 10c62bb..c92715f 100644 (file)
@@ -3355,3 +3355,49 @@ define trace_profile_del_reply {
     u32 context;
     i32 retval;
 };
+
+/** \brief Create host-interface
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param host_if_name - interface name
+    @param hw_addr - interface MAC
+    @param use_random_hw_addr - use random generated MAC
+*/
+define af_packet_create {
+    u32 client_index;
+    u32 context;
+
+    u8 host_if_name[64];
+    u8 hw_addr[6];
+    u8 use_random_hw_addr;
+};
+
+/** \brief Create host-interface response
+    @param context - sender context, to match reply w/ request
+    @param retval - return value for request
+*/
+define af_packet_create_reply {
+    u32 context;
+    i32 retval;
+};
+
+/** \brief Delete host-interface
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param host_if_name - interface name
+*/
+define af_packet_delete {
+    u32 client_index;
+    u32 context;
+
+    u8 host_if_name[64];
+};
+
+/** \brief Delete host-interface response
+    @param context - sender context, to match reply w/ request
+    @param retval - return value for request
+*/
+define af_packet_delete_reply {
+    u32 context;
+    i32 retval;
+};