FD.io VPP  v18.01.2-1-g9b554f3
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/vnet_msg_enum.h>
28 
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32 
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36 
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42 
44 
45 #define foreach_vpe_api_msg \
46 _(AF_PACKET_CREATE, af_packet_create) \
47 _(AF_PACKET_DELETE, af_packet_delete) \
48 _(AF_PACKET_SET_L4_CKSUM_OFFLOAD, af_packet_set_l4_cksum_offload)
49 
50 static void
52 {
55  int rv = 0;
56  u8 *host_if_name = NULL;
57  u32 sw_if_index;
58 
59  host_if_name = format (0, "%s", mp->host_if_name);
60  vec_add1 (host_if_name, 0);
61 
62  rv = af_packet_create_if (vm, host_if_name,
63  mp->use_random_hw_addr ? 0 : mp->hw_addr,
64  &sw_if_index);
65 
66  vec_free (host_if_name);
67 
68  /* *INDENT-OFF* */
69  REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
70  ({
71  rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
72  }));
73  /* *INDENT-ON* */
74 }
75 
76 static void
78 {
80  vl_api_af_packet_delete_reply_t *rmp;
81  int rv = 0;
82  u8 *host_if_name = NULL;
83 
84  host_if_name = format (0, "%s", mp->host_if_name);
85  vec_add1 (host_if_name, 0);
86 
87  rv = af_packet_delete_if (vm, host_if_name);
88 
89  vec_free (host_if_name);
90 
91  REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
92 }
93 
94 static void
97 {
99  vl_api_af_packet_delete_reply_t *rmp;
100  int rv = 0;
101 
102  rv = af_packet_set_l4_cksum_offload (vm, mp->sw_if_index, mp->set);
103  REPLY_MACRO (VL_API_AF_PACKET_SET_L4_CKSUM_OFFLOAD_REPLY);
104 }
105 
106 /*
107  * af_packet_api_hookup
108  * Add vpe's API message handlers to the table.
109  * vlib has alread mapped shared memory and
110  * added the client registration handlers.
111  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
112  */
113 #define vl_msg_name_crc_list
114 #include <vnet/vnet_all_api_h.h>
115 #undef vl_msg_name_crc_list
116 
117 static void
119 {
120 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
121  foreach_vl_msg_name_crc_af_packet;
122 #undef _
123 }
124 
125 static clib_error_t *
127 {
128  api_main_t *am = &api_main;
129 
130 #define _(N,n) \
131  vl_msg_api_set_handlers(VL_API_##N, #n, \
132  vl_api_##n##_t_handler, \
133  vl_noop_handler, \
134  vl_api_##n##_t_endian, \
135  vl_api_##n##_t_print, \
136  sizeof(vl_api_##n##_t), 1);
138 #undef _
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  */
static void vl_api_af_packet_create_t_handler(vl_api_af_packet_create_t *mp)
Definition: af_packet_api.c:51
Set l4 offload ckecksum calculation.
Definition: af_packet.api:63
int af_packet_set_l4_cksum_offload(vlib_main_t *vm, u32 sw_if_index, u8 set)
Definition: af_packet.c:412
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:55
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define foreach_vpe_api_msg
Definition: af_packet_api.c:45
Create host-interface response.
Definition: af_packet.api:39
Delete host-interface.
Definition: af_packet.api:51
#define REPLY_MACRO(t)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:198
api_main_t api_main
Definition: api_shared.c:35
Create host-interface.
Definition: af_packet.api:25
vlib_main_t * vm
Definition: buffer.c:283
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
VLIB_API_INIT_FUNCTION(af_packet_api_hookup)
unsigned int u32
Definition: types.h:88
static void setup_message_id_table(api_main_t *am)
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
unsigned char u8
Definition: types.h:56
static void vl_api_af_packet_delete_t_handler(vl_api_af_packet_delete_t *mp)
Definition: af_packet_api.c:77
static clib_error_t * af_packet_api_hookup(vlib_main_t *vm)
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:211
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:96
int af_packet_delete_if(vlib_main_t *vm, u8 *host_if_name)
Definition: af_packet.c:353