FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
af_packet_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * af_packet_api.c - af-packet api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
26 
27 #include <vnet/format_fns.h>
28 #include <vnet/devices/af_packet/af_packet.api_enum.h>
29 #include <vnet/devices/af_packet/af_packet.api_types.h>
30 
31 #define REPLY_MSG_ID_BASE msg_id_base
33 
35 
36 static void
38 {
41  int rv = 0;
42  u8 *host_if_name = NULL;
44 
45  host_if_name = format (0, "%s", mp->host_if_name);
46  vec_add1 (host_if_name, 0);
47 
48  rv = af_packet_create_if (vm, host_if_name,
49  mp->use_random_hw_addr ? 0 : mp->hw_addr,
50  &sw_if_index);
51 
52  vec_free (host_if_name);
53 
54  /* *INDENT-OFF* */
55  REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
56  ({
57  rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
58  }));
59  /* *INDENT-ON* */
60 }
61 
62 static void
64 {
66  vl_api_af_packet_delete_reply_t *rmp;
67  int rv = 0;
68  u8 *host_if_name = NULL;
69 
70  host_if_name = format (0, "%s", mp->host_if_name);
71  vec_add1 (host_if_name, 0);
72 
73  rv = af_packet_delete_if (vm, host_if_name);
74 
75  vec_free (host_if_name);
76 
77  REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
78 }
79 
80 static void
83 {
85  vl_api_af_packet_delete_reply_t *rmp;
86  int rv = 0;
87 
88  rv = af_packet_set_l4_cksum_offload (vm, ntohl (mp->sw_if_index), mp->set);
89  REPLY_MACRO (VL_API_AF_PACKET_SET_L4_CKSUM_OFFLOAD_REPLY);
90 }
91 
92 static void
95  af_packet_if_detail_t * af_packet_if, u32 context)
96 {
98  mp = vl_msg_api_alloc (sizeof (*mp));
99  clib_memset (mp, 0, sizeof (*mp));
100  mp->_vl_msg_id = htons (REPLY_MSG_ID_BASE + VL_API_AF_PACKET_DETAILS);
101  mp->sw_if_index = htonl (af_packet_if->sw_if_index);
102  clib_memcpy (mp->host_if_name, af_packet_if->host_if_name,
103  MIN (ARRAY_LEN (mp->host_if_name) - 1,
104  strlen ((const char *) af_packet_if->host_if_name)));
105 
106  mp->context = context;
107  vl_api_send_msg (reg, (u8 *) mp);
108 }
109 
110 
111 static void
113 {
114  int rv;
117  af_packet_if_detail_t *out_af_packet_ifs = NULL;
118  af_packet_if_detail_t *af_packet_if = NULL;
119 
121  if (!reg)
122  return;
123 
124  rv = af_packet_dump_ifs (&out_af_packet_ifs);
125  if (rv)
126  return;
127 
128  vec_foreach (af_packet_if, out_af_packet_ifs)
129  {
130  af_packet_send_details (am, reg, af_packet_if, mp->context);
131  }
132 
133  vec_free (out_af_packet_ifs);
134 }
135 
136 #include <vnet/devices/af_packet/af_packet.api.c>
137 static clib_error_t *
139 {
140  /*
141  * Set up the (msg_name, crc, message-id) table
142  */
144 
145  return 0;
146 }
147 
149 
150 /*
151  * fd.io coding-style-patch-verification: ON
152  *
153  * Local Variables:
154  * eval: (c-set-style "gnu")
155  * End:
156  */
vl_api_af_packet_delete_t::host_if_name
string host_if_name[64]
Definition: af_packet.api:59
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
vl_api_af_packet_set_l4_cksum_offload_t_handler
static void vl_api_af_packet_set_l4_cksum_offload_t_handler(vl_api_af_packet_set_l4_cksum_offload_t *mp)
Definition: af_packet_api.c:82
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: af_packet_api.c:31
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
af_packet_if_detail_t::host_if_name
u8 host_if_name[64]
Definition: af_packet.h:27
vpe_api_main_t
Definition: api_helper_macros.h:414
af_packet_api_hookup
static clib_error_t * af_packet_api_hookup(vlib_main_t *vm)
Definition: af_packet_api.c:138
u16
unsigned short u16
Definition: types.h:57
am
app_main_t * am
Definition: application.c:489
af_packet_create_if
int af_packet_create_if(vlib_main_t *vm, u8 *host_if_name, u8 *hw_addr_set, u32 *sw_if_index)
Definition: af_packet.c:244
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vl_api_af_packet_set_l4_cksum_offload_t
Set l4 offload checksum calculation.
Definition: af_packet.api:66
vl_api_af_packet_create_t::use_random_hw_addr
bool use_random_hw_addr
Definition: af_packet.api:34
vl_api_af_packet_dump_t::client_index
u32 client_index
Definition: af_packet.api:78
vl_api_af_packet_delete_t
Delete host-interface.
Definition: af_packet.api:54
vl_api_af_packet_delete_t_handler
static void vl_api_af_packet_delete_t_handler(vl_api_af_packet_delete_t *mp)
Definition: af_packet_api.c:63
vl_api_af_packet_details_t
Reply for af_packet dump request.
Definition: af_packet.api:86
vl_api_af_packet_create_t::hw_addr
vl_api_mac_address_t hw_addr
Definition: af_packet.api:33
vl_api_af_packet_create_reply_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: af_packet.api:46
af_packet_send_details
static void af_packet_send_details(vpe_api_main_t *am, vl_api_registration_t *reg, af_packet_if_detail_t *af_packet_if, u32 context)
Definition: af_packet_api.c:93
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
af_packet_delete_if
int af_packet_delete_if(vlib_main_t *vm, u8 *host_if_name)
Definition: af_packet.c:450
vl_api_af_packet_dump_t::context
u32 context
Definition: af_packet.api:79
vl_api_af_packet_details_t::host_if_name
string host_if_name[64]
Definition: af_packet.api:90
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
MIN
#define MIN(x, y)
Definition: node.h:31
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vl_api_af_packet_dump_t_handler
static void vl_api_af_packet_dump_t_handler(vl_api_af_packet_dump_t *mp)
Definition: af_packet_api.c:112
vl_api_af_packet_details_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: af_packet.api:89
interface.h
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(af_packet_api_hookup)
vl_api_af_packet_set_l4_cksum_offload_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: af_packet.api:71
af_packet_set_l4_cksum_offload
int af_packet_set_l4_cksum_offload(vlib_main_t *vm, u32 sw_if_index, u8 set)
Definition: af_packet.c:510
vl_api_af_packet_create_t::host_if_name
string host_if_name[64]
Definition: af_packet.api:35
vl_api_af_packet_set_l4_cksum_offload_t::set
bool set
Definition: af_packet.api:72
af_packet_dump_ifs
int af_packet_dump_ifs(af_packet_if_detail_t **out_af_packet_ifs)
Definition: af_packet.c:534
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vl_api_af_packet_details_t::context
u32 context
Definition: af_packet.api:88
vl_api_af_packet_create_t
Create host-interface.
Definition: af_packet.api:28
format_fns.h
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
af_packet_if_detail_t
Definition: af_packet.h:24
api_helper_macros.h
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
af_packet.h
vl_api_af_packet_create_t_handler
static void vl_api_af_packet_create_t_handler(vl_api_af_packet_create_t *mp)
Definition: af_packet_api.c:37
vl_api_af_packet_dump_t
Dump af_packet interfaces request.
Definition: af_packet.api:76
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
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_api_af_packet_create_reply_t
Create host-interface response.
Definition: af_packet.api:42
context
u32 context
Definition: ip.api:852
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
api_errno.h
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
msg_id_base
static u16 msg_id_base
Definition: af_packet_api.c:34
vpe_api_main
vpe_api_main_t vpe_api_main
Definition: interface_api.c:47
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
af_packet_if_detail_t::sw_if_index
u32 sw_if_index
Definition: af_packet.h:26