2 *------------------------------------------------------------------
3 * Copyright (c) 2020 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
21 #include <af_xdp/af_xdp.h>
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
26 /* define message IDs */
27 #include <af_xdp/af_xdp.api_enum.h>
28 #include <af_xdp/af_xdp.api_types.h>
30 #include <vlibapi/api_helper_macros.h>
33 af_xdp_api_mode (vl_api_af_xdp_mode_t mode)
37 case AF_XDP_API_MODE_AUTO:
38 return AF_XDP_MODE_AUTO;
39 case AF_XDP_API_MODE_COPY:
40 return AF_XDP_MODE_COPY;
41 case AF_XDP_API_MODE_ZERO_COPY:
42 return AF_XDP_MODE_ZERO_COPY;
44 return AF_XDP_MODE_AUTO;
48 vl_api_af_xdp_create_t_handler (vl_api_af_xdp_create_t * mp)
50 vlib_main_t *vm = vlib_get_main ();
51 af_xdp_main_t *rm = &af_xdp_main;
52 vl_api_af_xdp_create_reply_t *rmp;
53 af_xdp_create_if_args_t args;
56 clib_memset (&args, 0, sizeof (af_xdp_create_if_args_t));
58 args.linux_ifname = mp->host_if[0] ? (char *) mp->host_if : 0;
59 args.name = mp->name[0] ? (char *) mp->name : 0;
60 args.prog = mp->prog[0] ? (char *) mp->prog : 0;
61 args.mode = af_xdp_api_mode (mp->mode);
62 args.rxq_size = ntohs (mp->rxq_size);
63 args.txq_size = ntohs (mp->txq_size);
64 args.rxq_num = ntohs (mp->rxq_num);
66 af_xdp_create_if (vm, &args);
70 REPLY_MACRO2 (VL_API_AF_XDP_CREATE_REPLY + rm->msg_id_base,
72 rmp->sw_if_index = ntohl (args.sw_if_index);
78 vl_api_af_xdp_delete_t_handler (vl_api_af_xdp_delete_t * mp)
80 vlib_main_t *vm = vlib_get_main ();
81 vnet_main_t *vnm = vnet_get_main ();
82 af_xdp_main_t *rm = &af_xdp_main;
83 vl_api_af_xdp_delete_reply_t *rmp;
85 vnet_hw_interface_t *hw;
89 vnet_get_sup_hw_interface_api_visible_or_null (vnm,
90 htonl (mp->sw_if_index));
91 if (hw == NULL || af_xdp_device_class.index != hw->dev_class_index)
93 rv = VNET_API_ERROR_INVALID_INTERFACE;
97 rd = pool_elt_at_index (rm->devices, hw->dev_instance);
99 af_xdp_delete_if (vm, rd);
102 REPLY_MACRO (VL_API_AF_XDP_DELETE_REPLY + rm->msg_id_base);
105 /* set tup the API message handling tables */
106 #include <af_xdp/af_xdp.api.c>
107 static clib_error_t *
108 af_xdp_plugin_api_hookup (vlib_main_t * vm)
110 af_xdp_main_t *rm = &af_xdp_main;
112 /* ask for a correctly-sized block of API message decode slots */
113 rm->msg_id_base = setup_message_id_table ();
117 VLIB_API_INIT_FUNCTION (af_xdp_plugin_api_hookup);
120 * fd.io coding-style-patch-verification: ON
123 * eval: (c-set-style "gnu")