FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
api.c
Go to the documentation of this file.
1 /*
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:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 
21 #include <af_xdp/af_xdp.h>
22 
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
25 
26 /* define message IDs */
27 #include <af_xdp/af_xdp.api_enum.h>
28 #include <af_xdp/af_xdp.api_types.h>
29 
31 
32 static af_xdp_mode_t
33 af_xdp_api_mode (vl_api_af_xdp_mode_t mode)
34 {
35  switch (mode)
36  {
38  return AF_XDP_MODE_AUTO;
40  return AF_XDP_MODE_COPY;
42  return AF_XDP_MODE_ZERO_COPY;
43  }
44  return AF_XDP_MODE_AUTO;
45 }
46 
48 af_xdp_api_flags (vl_api_af_xdp_flag_t flags)
49 {
50  af_xdp_create_flag_t cflags = 0;
51 
52  if (flags & AF_XDP_API_FLAGS_NO_SYSCALL_LOCK)
54 
55  return cflags;
56 }
57 
58 static void
60 {
65  int rv;
66 
67  clib_memset (&args, 0, sizeof (af_xdp_create_if_args_t));
68 
69  args.linux_ifname = mp->host_if[0] ? (char *) mp->host_if : 0;
70  args.name = mp->name[0] ? (char *) mp->name : 0;
71  args.prog = mp->prog[0] ? (char *) mp->prog : 0;
72  args.mode = af_xdp_api_mode (mp->mode);
73  args.flags = af_xdp_api_flags (mp->flags);
74  args.rxq_size = ntohs (mp->rxq_size);
75  args.txq_size = ntohs (mp->txq_size);
76  args.rxq_num = ntohs (mp->rxq_num);
77 
78  af_xdp_create_if (vm, &args);
79  rv = args.rv;
80 
81  /* *INDENT-OFF* */
82  REPLY_MACRO2 (VL_API_AF_XDP_CREATE_REPLY + rm->msg_id_base,
83  ({
84  rmp->sw_if_index = ntohl (args.sw_if_index);
85  }));
86  /* *INDENT-ON* */
87 }
88 
89 static void
91 {
93  vnet_main_t *vnm = vnet_get_main ();
95  vl_api_af_xdp_delete_reply_t *rmp;
96  af_xdp_device_t *rd;
98  int rv = 0;
99 
100  hw =
102  htonl (mp->sw_if_index));
103  if (hw == NULL || af_xdp_device_class.index != hw->dev_class_index)
104  {
105  rv = VNET_API_ERROR_INVALID_INTERFACE;
106  goto reply;
107  }
108 
109  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
110 
111  af_xdp_delete_if (vm, rd);
112 
113 reply:
114  REPLY_MACRO (VL_API_AF_XDP_DELETE_REPLY + rm->msg_id_base);
115 }
116 
117 /* set tup the API message handling tables */
118 #include <af_xdp/af_xdp.api.c>
119 static clib_error_t *
121 {
122  af_xdp_main_t *rm = &af_xdp_main;
123 
124  /* ask for a correctly-sized block of API message decode slots */
126  return 0;
127 }
128 
130 
131 /*
132  * fd.io coding-style-patch-verification: ON
133  *
134  * Local Variables:
135  * eval: (c-set-style "gnu")
136  * End:
137  */
vlib.h
vl_api_af_xdp_create_t::flags
vl_api_af_xdp_flag_t flags[default=0]
Definition: af_xdp.api:57
api.h
af_xdp_create_if_args_t::flags
af_xdp_create_flag_t flags
Definition: af_xdp.h:153
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vl_api_af_xdp_create_t::name
string name[64]
Definition: af_xdp.api:52
af_xdp_create_if_args_t::prog
char * prog
Definition: af_xdp.h:151
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
af_xdp_main_t
Definition: af_xdp.h:126
af_xdp.h
af_xdp_create_if_args_t::mode
af_xdp_mode_t mode
Definition: af_xdp.h:152
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
af_xdp_create_flag_t
af_xdp_create_flag_t
Definition: af_xdp.h:142
af_xdp_create_if_args_t::rxq_size
u32 rxq_size
Definition: af_xdp.h:154
vl_api_af_xdp_create_t::txq_size
u16 txq_size[default=0]
Definition: af_xdp.api:55
AF_XDP_MODE_AUTO
@ AF_XDP_MODE_AUTO
Definition: af_xdp.h:137
af_xdp_main_t::devices
af_xdp_device_t * devices
Definition: af_xdp.h:128
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
af_xdp_device_class
vnet_device_class_t af_xdp_device_class
af_xdp_mode_t
af_xdp_mode_t
Definition: af_xdp.h:135
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
af_xdp_delete_if
void af_xdp_delete_if(vlib_main_t *vm, af_xdp_device_t *ad)
Definition: device.c:90
vl_api_af_xdp_create_reply_t
Definition: af_xdp.api:69
vl_api_af_xdp_create_t::prog
string prog[256]
Definition: af_xdp.api:58
af_xdp_main
af_xdp_main_t af_xdp_main
Definition: device.c:31
AF_XDP_MODE_COPY
@ AF_XDP_MODE_COPY
Definition: af_xdp.h:138
af_xdp_api_mode
static af_xdp_mode_t af_xdp_api_mode(vl_api_af_xdp_mode_t mode)
Definition: api.c:33
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vl_api_af_xdp_create_t
Definition: af_xdp.api:46
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
af_xdp_create_if_args_t::linux_ifname
char * linux_ifname
Definition: af_xdp.h:149
vl_api_af_xdp_create_t::mode
vl_api_af_xdp_mode_t mode[default=0]
Definition: af_xdp.api:56
af_xdp_device_t
Definition: af_xdp.h:91
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(af_xdp_plugin_api_hookup)
vl_api_af_xdp_create_t::rxq_size
u16 rxq_size[default=0]
Definition: af_xdp.api:54
vl_api_af_xdp_create_t::rxq_num
u16 rxq_num[default=1]
Definition: af_xdp.api:53
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: api.c:799
af_xdp_create_if_args_t::rxq_num
u32 rxq_num
Definition: af_xdp.h:156
af_xdp_create_if_args_t::name
char * name
Definition: af_xdp.h:150
af_xdp_create_if_args_t::rv
int rv
Definition: af_xdp.h:159
af_xdp_create_if_args_t::txq_size
u32 txq_size
Definition: af_xdp.h:155
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vl_api_af_xdp_create_t_handler
static void vl_api_af_xdp_create_t_handler(vl_api_af_xdp_create_t *mp)
Definition: api.c:59
af_xdp_create_if
void af_xdp_create_if(vlib_main_t *vm, af_xdp_create_if_args_t *args)
Definition: device.c:365
af_xdp_create_if_args_t
Definition: af_xdp.h:147
vl_api_af_xdp_delete_t
Definition: af_xdp.api:83
api_helper_macros.h
AF_XDP_MODE_ZERO_COPY
@ AF_XDP_MODE_ZERO_COPY
Definition: af_xdp.h:139
AF_XDP_API_MODE_ZERO_COPY
@ AF_XDP_API_MODE_ZERO_COPY
Definition: af_xdp.api:25
vl_api_af_xdp_delete_t_handler
static void vl_api_af_xdp_delete_t_handler(vl_api_af_xdp_delete_t *mp)
Definition: api.c:90
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
clib_error_t
Definition: clib_error.h:21
AF_XDP_API_MODE_COPY
@ AF_XDP_API_MODE_COPY
Definition: af_xdp.api:24
af_xdp_main_t::msg_id_base
u16 msg_id_base
Definition: af_xdp.h:130
rv
int __clib_unused rv
Definition: application.c:491
AF_XDP_API_MODE_AUTO
@ AF_XDP_API_MODE_AUTO
Definition: af_xdp.api:23
vnet.h
af_xdp_api_flags
static af_xdp_create_flag_t af_xdp_api_flags(vl_api_af_xdp_flag_t flags)
Definition: api.c:48
vl_api_af_xdp_create_t::host_if
string host_if[64]
Definition: af_xdp.api:51
AF_XDP_CREATE_FLAGS_NO_SYSCALL_LOCK
@ AF_XDP_CREATE_FLAGS_NO_SYSCALL_LOCK
Definition: af_xdp.h:144
af_xdp_plugin_api_hookup
static clib_error_t * af_xdp_plugin_api_hookup(vlib_main_t *vm)
Definition: api.c:120
vl_api_af_xdp_delete_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: af_xdp.api:88
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105