FD.io VPP
v17.10-9-gd594711
Vector Packet Processing
Main Page
Related Pages
Modules
Data Structures
Source
Files
Symbols
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
>
25
#include <
vnet/devices/af_packet/af_packet.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
43
#include <
vlibapi/api_helper_macros.h
>
44
45
#define foreach_vpe_api_msg \
46
_(AF_PACKET_CREATE, af_packet_create) \
47
_(AF_PACKET_DELETE, af_packet_delete)
48
49
static
void
50
vl_api_af_packet_create_t_handler
(
vl_api_af_packet_create_t
* mp)
51
{
52
vlib_main_t
*
vm
=
vlib_get_main
();
53
vl_api_af_packet_create_reply_t
*rmp;
54
int
rv = 0;
55
u8
*host_if_name =
NULL
;
56
u32
sw_if_index;
57
58
host_if_name =
format
(0,
"%s"
, mp->
host_if_name
);
59
vec_add1
(host_if_name, 0);
60
61
rv =
af_packet_create_if
(vm, host_if_name,
62
mp->
use_random_hw_addr
? 0 : mp->
hw_addr
,
63
&sw_if_index);
64
65
vec_free
(host_if_name);
66
67
/* *INDENT-OFF* */
68
REPLY_MACRO2
(VL_API_AF_PACKET_CREATE_REPLY,
69
({
70
rmp->
sw_if_index
= clib_host_to_net_u32(sw_if_index);
71
}));
72
/* *INDENT-ON* */
73
}
74
75
static
void
76
vl_api_af_packet_delete_t_handler
(
vl_api_af_packet_delete_t
* mp)
77
{
78
vlib_main_t
*
vm
=
vlib_get_main
();
79
vl_api_af_packet_delete_reply_t *rmp;
80
int
rv = 0;
81
u8
*host_if_name =
NULL
;
82
83
host_if_name =
format
(0,
"%s"
, mp->
host_if_name
);
84
vec_add1
(host_if_name, 0);
85
86
rv =
af_packet_delete_if
(vm, host_if_name);
87
88
vec_free
(host_if_name);
89
90
REPLY_MACRO
(VL_API_AF_PACKET_DELETE_REPLY);
91
}
92
93
/*
94
* af_packet_api_hookup
95
* Add vpe's API message handlers to the table.
96
* vlib has alread mapped shared memory and
97
* added the client registration handlers.
98
* See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
99
*/
100
#define vl_msg_name_crc_list
101
#include <
vnet/vnet_all_api_h.h
>
102
#undef vl_msg_name_crc_list
103
104
static
void
105
setup_message_id_table
(
api_main_t
* am)
106
{
107
#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
108
foreach_vl_msg_name_crc_af_packet;
109
#undef _
110
}
111
112
static
clib_error_t
*
113
af_packet_api_hookup
(
vlib_main_t
*
vm
)
114
{
115
api_main_t
*am = &
api_main
;
116
117
#define _(N,n) \
118
vl_msg_api_set_handlers(VL_API_##N, #n, \
119
vl_api_##n##_t_handler, \
120
vl_noop_handler, \
121
vl_api_##n##_t_endian, \
122
vl_api_##n##_t_print, \
123
sizeof(vl_api_##n##_t), 1);
124
foreach_vpe_api_msg
;
125
#undef _
126
127
/*
128
* Set up the (msg_name, crc, message-id) table
129
*/
130
setup_message_id_table
(am);
131
132
return
0;
133
}
134
135
VLIB_API_INIT_FUNCTION
(
af_packet_api_hookup
);
136
137
/*
138
* fd.io coding-style-patch-verification: ON
139
*
140
* Local Variables:
141
* eval: (c-set-style "gnu")
142
* End:
143
*/
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:50
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition:
api_helper_macros.h:46
NULL
#define NULL
Definition:
clib.h:55
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition:
vec.h:518
format
u8 * format(u8 *s, const char *fmt,...)
Definition:
format.c:419
vnet_msg_enum.h
foreach_vpe_api_msg
#define foreach_vpe_api_msg
Definition:
af_packet_api.c:45
vl_api_af_packet_create_reply_t
Create host-interface response.
Definition:
af_packet.api:37
af_packet.h
api_errno.h
vl_api_af_packet_delete_t
Delete host-interface.
Definition:
af_packet.api:49
api_helper_macros.h
interface.h
vl_api_af_packet_create_t::use_random_hw_addr
u8 use_random_hw_addr
Definition:
af_packet.api:30
REPLY_MACRO
#define REPLY_MACRO(t)
Definition:
api_helper_macros.h:30
vl_api_af_packet_delete_t::host_if_name
u8 host_if_name[64]
Definition:
af_packet.api:54
vnet.h
api_main_t
API main structure, used by both vpp and binary API clients.
Definition:
api_common.h:182
api_main
api_main_t api_main
Definition:
api_shared.c:35
vl_api_af_packet_create_t
Create host-interface.
Definition:
af_packet.api:23
vm
vlib_main_t * vm
Definition:
buffer.c:283
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition:
vec.h:336
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(af_packet_api_hookup)
u32
unsigned int u32
Definition:
types.h:88
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition:
af_packet_api.c:105
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition:
global_funcs.h:23
clib_error_t
Definition:
clib_error.h:21
vnet_all_api_h.h
u8
unsigned char u8
Definition:
types.h:56
api.h
vlib_main_t
Definition:
main.h:59
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:76
vl_api_af_packet_create_reply_t::sw_if_index
u32 sw_if_index
Definition:
af_packet.api:41
af_packet_api_hookup
static clib_error_t * af_packet_api_hookup(vlib_main_t *vm)
Definition:
af_packet_api.c:113
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:209
vl_api_af_packet_create_t::host_if_name
u8 host_if_name[64]
Definition:
af_packet.api:28
vl_api_af_packet_create_t::hw_addr
u8 hw_addr[6]
Definition:
af_packet.api:29
af_packet_delete_if
int af_packet_delete_if(vlib_main_t *vm, u8 *host_if_name)
Definition:
af_packet.c:351
src
vnet
devices
af_packet
af_packet_api.c
Generated on Tue Nov 14 2017 00:29:59 for FD.io VPP by
1.8.11