blob: fd2f6fc9a57be4ecf7006fc6e1547680a88efe12 [file] [log] [blame]
Damjan Marion83243a02016-02-29 13:09:30 +01001/*
2 *------------------------------------------------------------------
3 * af_packet.c - linux kernel packet interface
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 <linux/if_ether.h>
21#include <linux/if_packet.h>
Mohsin Kazmia50a14c2018-04-25 15:58:05 +020022#include <sys/ioctl.h>
23#include <net/if.h>
Ray Kinsellac855b732017-04-21 12:24:43 +010024#include <dirent.h>
Ray Kinsella7bfa1192017-05-15 11:52:43 +010025#include <sys/stat.h>
26#include <sys/types.h>
27#include <fcntl.h>
Damjan Marion83243a02016-02-29 13:09:30 +010028
Damjan Marion01914ce2017-09-14 19:04:50 +020029#include <vppinfra/linux/sysfs.h>
Damjan Marion83243a02016-02-29 13:09:30 +010030#include <vlib/vlib.h>
31#include <vlib/unix/unix.h>
32#include <vnet/ip/ip.h>
Aloys Augustine39376e2021-03-29 22:08:09 +020033#include <vnet/devices/netlink.h>
Damjan Marion83243a02016-02-29 13:09:30 +010034#include <vnet/ethernet/ethernet.h>
Mohammed Hawari85c19432020-12-18 16:29:45 +010035#include <vnet/interface/rx_queue_funcs.h>
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +000036#include <vnet/interface/tx_queue_funcs.h>
Damjan Marion83243a02016-02-29 13:09:30 +010037
38#include <vnet/devices/af_packet/af_packet.h>
39
Dave Wallace71612d62017-10-24 01:32:41 -040040af_packet_main_t af_packet_main;
41
Mohsin Kazmicae84fa2021-10-08 15:10:49 +000042VNET_HW_INTERFACE_CLASS (af_packet_ip_device_hw_interface_class, static) = {
43 .name = "af-packet-ip-device",
44 .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
45};
46
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +020047#define AF_PACKET_DEFAULT_TX_FRAMES_PER_BLOCK 1024
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +000048#define AF_PACKET_DEFAULT_TX_FRAME_SIZE (2048 * 33) // GSO packet of 64KB
Damjan Marion83243a02016-02-29 13:09:30 +010049#define AF_PACKET_TX_BLOCK_NR 1
Damjan Marion83243a02016-02-29 13:09:30 +010050
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +000051#define AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK 32
Mohsin Kazmi219cbcb2022-03-18 16:58:31 +000052#define AF_PACKET_DEFAULT_RX_FRAME_SIZE 2048
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +000053#define AF_PACKET_RX_BLOCK_NR 160
Damjan Marion83243a02016-02-29 13:09:30 +010054
Damjan Marion83243a02016-02-29 13:09:30 +010055/*defined in net/if.h but clashes with dpdk headers */
Damjan Marion00a9dca2016-08-17 17:05:46 +020056unsigned int if_nametoindex (const char *ifname);
Damjan Marion83243a02016-02-29 13:09:30 +010057
Damjan Marion88a9c0e2022-01-06 21:14:08 +010058static clib_error_t *
Damjan Marion1cd0e5d2022-01-17 14:49:17 +010059af_packet_eth_set_max_frame_size (vnet_main_t *vnm, vnet_hw_interface_t *hi,
60 u32 frame_size)
Damjan Marion83243a02016-02-29 13:09:30 +010061{
Damjan Marion88a9c0e2022-01-06 21:14:08 +010062 clib_error_t *error, *rv;
Ray Kinsella7bfa1192017-05-15 11:52:43 +010063 af_packet_main_t *apm = &af_packet_main;
Damjan Marion88a9c0e2022-01-06 21:14:08 +010064 af_packet_if_t *apif = pool_elt_at_index (apm->interfaces, hi->dev_instance);
Ray Kinsella7bfa1192017-05-15 11:52:43 +010065
Damjan Marion1cd0e5d2022-01-17 14:49:17 +010066 error = vnet_netlink_set_link_mtu (apif->host_if_index,
67 frame_size + hi->frame_overhead);
Damjan Marion88a9c0e2022-01-06 21:14:08 +010068
69 if (error)
Ray Kinsella7bfa1192017-05-15 11:52:43 +010070 {
Damjan Marion88a9c0e2022-01-06 21:14:08 +010071 vlib_log_err (apm->log_class, "netlink failed to change MTU: %U",
72 format_clib_error, error);
73 rv = vnet_error (VNET_ERR_SYSCALL_ERROR_1, "netlink error: %U",
74 format_clib_error, error);
75 clib_error_free (error);
76 return rv;
Ray Kinsella7bfa1192017-05-15 11:52:43 +010077 }
Damjan Marion88a9c0e2022-01-06 21:14:08 +010078 else
Damjan Marion1cd0e5d2022-01-17 14:49:17 +010079 apif->host_mtu = frame_size + hi->frame_overhead;
Damjan Marion83243a02016-02-29 13:09:30 +010080 return 0;
81}
82
Nathan Skrzypczakffc6bdc2021-02-01 17:13:59 +010083static int
84af_packet_read_mtu (af_packet_if_t *apif)
85{
86 af_packet_main_t *apm = &af_packet_main;
87 clib_error_t *error;
Aloys Augustine39376e2021-03-29 22:08:09 +020088 error = vnet_netlink_get_link_mtu (apif->host_if_index, &apif->host_mtu);
Nathan Skrzypczakffc6bdc2021-02-01 17:13:59 +010089 if (error)
90 {
Aloys Augustine39376e2021-03-29 22:08:09 +020091 vlib_log_err (apm->log_class, "netlink failed to get MTU: %U",
Nathan Skrzypczakffc6bdc2021-02-01 17:13:59 +010092 format_clib_error, error);
93 clib_error_free (error);
94 return VNET_API_ERROR_SYSCALL_ERROR_1;
95 }
96 return 0;
97}
98
Damjan Marion00a9dca2016-08-17 17:05:46 +020099static clib_error_t *
Damjan Marion56dd5432017-09-08 19:52:02 +0200100af_packet_fd_read_ready (clib_file_t * uf)
Damjan Marion83243a02016-02-29 13:09:30 +0100101{
Damjan Marioneb743fa2017-03-20 16:34:15 +0100102 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion83243a02016-02-29 13:09:30 +0100103
Damjan Marion83243a02016-02-29 13:09:30 +0100104 /* Schedule the rx node */
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000105 vnet_hw_if_rx_queue_set_int_pending (vnm, uf->private_data);
Damjan Marion83243a02016-02-29 13:09:30 +0100106 return 0;
107}
108
109static int
Ray Kinsellac855b732017-04-21 12:24:43 +0100110is_bridge (const u8 * host_if_name)
111{
112 u8 *s;
113 DIR *dir = NULL;
114
115 s = format (0, "/sys/class/net/%s/bridge%c", host_if_name, 0);
116 dir = opendir ((char *) s);
117 vec_free (s);
118
119 if (dir)
120 {
121 closedir (dir);
122 return 0;
123 }
124
125 return -1;
126}
127
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000128static void
129af_packet_set_rx_queues (vlib_main_t *vm, af_packet_if_t *apif)
130{
131 vnet_main_t *vnm = vnet_get_main ();
132 af_packet_queue_t *rx_queue;
133
134 vnet_hw_if_set_input_node (vnm, apif->hw_if_index,
135 af_packet_input_node.index);
136
137 vec_foreach (rx_queue, apif->rx_queues)
138 {
139 rx_queue->queue_index = vnet_hw_if_register_rx_queue (
140 vnm, apif->hw_if_index, rx_queue->queue_id, VNET_HW_IF_RXQ_THREAD_ANY);
141
142 {
143 clib_file_t template = { 0 };
144 template.read_function = af_packet_fd_read_ready;
145 template.file_descriptor = rx_queue->fd;
146 template.private_data = rx_queue->queue_index;
147 template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED;
148 template.description =
149 format (0, "%U queue %u", format_af_packet_device_name,
150 apif->dev_instance, rx_queue->queue_id);
151 rx_queue->clib_file_index = clib_file_add (&file_main, &template);
152 }
153 vnet_hw_if_set_rx_queue_file_index (vnm, rx_queue->queue_index,
154 rx_queue->clib_file_index);
155 vnet_hw_if_set_rx_queue_mode (vnm, rx_queue->queue_index,
156 VNET_HW_IF_RX_MODE_INTERRUPT);
157 rx_queue->mode = VNET_HW_IF_RX_MODE_INTERRUPT;
158 }
159 vnet_hw_if_update_runtime_data (vnm, apif->hw_if_index);
160}
161
162static void
163af_packet_set_tx_queues (vlib_main_t *vm, af_packet_if_t *apif)
164{
165 vnet_main_t *vnm = vnet_get_main ();
166 af_packet_main_t *apm = &af_packet_main;
167 af_packet_queue_t *tx_queue;
168
169 vec_foreach (tx_queue, apif->tx_queues)
170 {
171 tx_queue->queue_index = vnet_hw_if_register_tx_queue (
172 vnm, apif->hw_if_index, tx_queue->queue_id);
173 }
174
175 if (apif->num_txqs == 0)
176 {
177 vlib_log_err (apm->log_class, "Interface %U has 0 txq",
178 format_vnet_hw_if_index_name, vnm, apif->hw_if_index);
179 return;
180 }
181
182 for (u32 j = 0; j < vlib_get_n_threads (); j++)
183 {
184 u32 qi = apif->tx_queues[j % apif->num_txqs].queue_index;
185 vnet_hw_if_tx_queue_assign_thread (vnm, qi, j);
186 }
187
188 vnet_hw_if_update_runtime_data (vnm, apif->hw_if_index);
189}
190
Ray Kinsellac855b732017-04-21 12:24:43 +0100191static int
Mohsin Kazmi219cbcb2022-03-18 16:58:31 +0000192create_packet_v3_sock (int host_if_index, tpacket_req3_t *rx_req,
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000193 tpacket_req3_t *tx_req, int *fd, af_packet_ring_t *ring,
Mohsin Kazmi788676b2022-04-05 12:43:13 +0000194 u32 fanout_id, u8 is_fanout,
Mohsin Kazmi2b6479c2022-04-05 12:03:47 +0000195 af_packet_if_flags_t *flags)
Damjan Marion83243a02016-02-29 13:09:30 +0100196{
Mohsin Kazmiacba9f72018-05-17 15:42:27 +0200197 af_packet_main_t *apm = &af_packet_main;
Damjan Marion83243a02016-02-29 13:09:30 +0100198 struct sockaddr_ll sll;
Mohsin Kazmi219cbcb2022-03-18 16:58:31 +0000199 socklen_t req_sz = sizeof (tpacket_req3_t);
200 int ret;
201 int ver = TPACKET_V3;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000202 u32 ring_sz = 0;
203
204 if (rx_req)
205 ring_sz += rx_req->tp_block_size * rx_req->tp_block_nr;
206
207 if (tx_req)
208 ring_sz += tx_req->tp_block_size * tx_req->tp_block_nr;
Damjan Marion83243a02016-02-29 13:09:30 +0100209
Damjan Marion00a9dca2016-08-17 17:05:46 +0200210 if ((*fd = socket (AF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
Damjan Marion83243a02016-02-29 13:09:30 +0100211 {
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000212 vlib_log_err (apm->log_class,
213 "Failed to create AF_PACKET socket: %s (errno %d)",
214 strerror (errno), errno);
Damjan Marion83243a02016-02-29 13:09:30 +0100215 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
216 goto error;
217 }
Damjan Marionc5170202017-10-11 14:15:47 +0200218
Chaoyu Jinafb19302018-03-13 07:37:41 -0700219 /* bind before rx ring is cfged so we don't receive packets from other interfaces */
Dave Barachb7b92992018-10-17 10:38:51 -0400220 clib_memset (&sll, 0, sizeof (sll));
Chaoyu Jinafb19302018-03-13 07:37:41 -0700221 sll.sll_family = PF_PACKET;
222 sll.sll_protocol = htons (ETH_P_ALL);
223 sll.sll_ifindex = host_if_index;
jackiechen19857fa41602019-05-07 18:59:13 +0800224 if (bind (*fd, (struct sockaddr *) &sll, sizeof (sll)) < 0)
Chaoyu Jinafb19302018-03-13 07:37:41 -0700225 {
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000226 vlib_log_err (apm->log_class,
227 "Failed to bind rx packet socket: %s (errno %d)",
228 strerror (errno), errno);
Chaoyu Jinafb19302018-03-13 07:37:41 -0700229 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
230 goto error;
231 }
232
jackiechen19857fa41602019-05-07 18:59:13 +0800233 if (setsockopt (*fd, SOL_PACKET, PACKET_VERSION, &ver, sizeof (ver)) < 0)
Damjan Marion83243a02016-02-29 13:09:30 +0100234 {
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000235 vlib_log_err (apm->log_class,
236 "Failed to set rx packet interface version: %s (errno %d)",
237 strerror (errno), errno);
Damjan Marion83243a02016-02-29 13:09:30 +0100238 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
239 goto error;
240 }
241
Damjan Marionc5170202017-10-11 14:15:47 +0200242 int opt = 1;
jackiechen19857fa41602019-05-07 18:59:13 +0800243 if (setsockopt (*fd, SOL_PACKET, PACKET_LOSS, &opt, sizeof (opt)) < 0)
Damjan Marion83243a02016-02-29 13:09:30 +0100244 {
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000245 vlib_log_err (
Mohsin Kazmi219cbcb2022-03-18 16:58:31 +0000246 apm->log_class,
247 "Failed to set packet tx ring error handling option: %s (errno %d)",
248 strerror (errno), errno);
Damjan Marion83243a02016-02-29 13:09:30 +0100249 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
250 goto error;
251 }
252
Mohsin Kazmi788676b2022-04-05 12:43:13 +0000253 if (*flags & AF_PACKET_IF_FLAGS_CKSUM_GSO)
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +0000254 {
Mohsin Kazmi788676b2022-04-05 12:43:13 +0000255
256 int opt2 = 1;
257 if (setsockopt (*fd, SOL_PACKET, PACKET_VNET_HDR, &opt2, sizeof (opt2)) <
258 0)
259 {
260 // remove the flag
261 *flags &= ~AF_PACKET_IF_FLAGS_CKSUM_GSO;
262 vlib_log_debug (apm->log_class,
263 "Failed to set packet vnet hdr error handling "
264 "option: %s (errno %d)",
265 strerror (errno), errno);
266 }
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +0000267 }
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +0000268
Florin Coras2dc942e2021-11-22 21:34:56 -0800269#if defined(PACKET_QDISC_BYPASS)
Mohsin Kazmi2b6479c2022-04-05 12:03:47 +0000270 if (*flags & AF_PACKET_IF_FLAGS_QDISC_BYPASS)
271 /* Introduced with Linux 3.14 so the ifdef should eventually be removed */
272 if (setsockopt (*fd, SOL_PACKET, PACKET_QDISC_BYPASS, &opt, sizeof (opt)) <
273 0)
274 {
275 // remove the flag
276 *flags &= ~AF_PACKET_IF_FLAGS_QDISC_BYPASS;
277 vlib_log_debug (apm->log_class,
278 "Failed to set qdisc bypass error "
279 "handling option: %s (errno %d)",
280 strerror (errno), errno);
281 }
Florin Coras2dc942e2021-11-22 21:34:56 -0800282#endif
Mohammed Hawarieed6fc92021-09-06 11:48:17 +0200283
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000284 if (is_fanout)
Damjan Marion83243a02016-02-29 13:09:30 +0100285 {
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000286 int fanout = ((fanout_id & 0xffff) | ((PACKET_FANOUT_HASH) << 16));
287 if (setsockopt (*fd, SOL_PACKET, PACKET_FANOUT, &fanout,
288 sizeof (fanout)) < 0)
289 {
290 vlib_log_err (apm->log_class,
291 "Failed to set fanout options: %s (errno %d)",
292 strerror (errno), errno);
293 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
294 goto error;
295 }
296 }
297
298 if (rx_req)
299 if (setsockopt (*fd, SOL_PACKET, PACKET_RX_RING, rx_req, req_sz) < 0)
300 {
301 vlib_log_err (apm->log_class,
jackiechen19857fa41602019-05-07 18:59:13 +0800302 "Failed to set packet rx ring options: %s (errno %d)",
303 strerror (errno), errno);
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000304 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
305 goto error;
306 }
Damjan Marion83243a02016-02-29 13:09:30 +0100307
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000308 if (tx_req)
309 if (setsockopt (*fd, SOL_PACKET, PACKET_TX_RING, tx_req, req_sz) < 0)
310 {
311 vlib_log_err (apm->log_class,
jackiechen19857fa41602019-05-07 18:59:13 +0800312 "Failed to set packet tx ring options: %s (errno %d)",
313 strerror (errno), errno);
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000314 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
315 goto error;
316 }
317
318 ring->ring_start_addr = mmap (NULL, ring_sz, PROT_READ | PROT_WRITE,
319 MAP_SHARED | MAP_LOCKED, *fd, 0);
320 if (ring->ring_start_addr == MAP_FAILED)
321 {
322 vlib_log_err (apm->log_class, "mmap failure: %s (errno %d)",
323 strerror (errno), errno);
Damjan Marion83243a02016-02-29 13:09:30 +0100324 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
325 goto error;
326 }
327
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000328 ring->ring_size = ring_sz;
Damjan Marion83243a02016-02-29 13:09:30 +0100329
Damjan Marion83243a02016-02-29 13:09:30 +0100330 return 0;
331error:
Dave Barach16ad6ae2016-07-28 17:55:30 -0400332 if (*fd >= 0)
jackiechen19857fa41602019-05-07 18:59:13 +0800333 {
334 close (*fd);
335 *fd = -1;
336 }
Damjan Marion83243a02016-02-29 13:09:30 +0100337 return ret;
338}
339
340int
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000341af_packet_queue_init (vlib_main_t *vm, af_packet_if_t *apif,
342 af_packet_create_if_arg_t *arg,
343 af_packet_queue_t *rx_queue, af_packet_queue_t *tx_queue,
344 u8 queue_id, u8 is_fanout)
345{
346 af_packet_main_t *apm = &af_packet_main;
347 tpacket_req3_t *rx_req = 0;
348 tpacket_req3_t *tx_req = 0;
349 int ret, fd = -1;
350 af_packet_ring_t ring = { 0 };
351 u8 *ring_addr = 0;
352 u32 rx_frames_per_block, tx_frames_per_block;
353 u32 rx_frame_size, tx_frame_size;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000354 u32 i = 0;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000355
356 if (rx_queue)
357 {
358 rx_frames_per_block = arg->rx_frames_per_block ?
359 arg->rx_frames_per_block :
360 AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK;
361
362 rx_frame_size = arg->rx_frame_size ? arg->rx_frame_size :
363 AF_PACKET_DEFAULT_RX_FRAME_SIZE;
364 vec_validate (rx_queue->rx_req, 0);
365 rx_queue->rx_req->tp_block_size = rx_frame_size * rx_frames_per_block;
366 rx_queue->rx_req->tp_frame_size = rx_frame_size;
367 rx_queue->rx_req->tp_block_nr = AF_PACKET_RX_BLOCK_NR;
368 rx_queue->rx_req->tp_frame_nr =
369 AF_PACKET_RX_BLOCK_NR * rx_frames_per_block;
370 rx_queue->rx_req->tp_retire_blk_tov = 1; // 1 ms block timout
371 rx_queue->rx_req->tp_feature_req_word = 0;
372 rx_queue->rx_req->tp_sizeof_priv = 0;
373 rx_req = rx_queue->rx_req;
374 }
375
376 if (tx_queue)
377 {
378 tx_frames_per_block = arg->tx_frames_per_block ?
379 arg->tx_frames_per_block :
380 AF_PACKET_DEFAULT_TX_FRAMES_PER_BLOCK;
381 tx_frame_size = arg->tx_frame_size ? arg->tx_frame_size :
382 AF_PACKET_DEFAULT_TX_FRAME_SIZE;
383
384 vec_validate (tx_queue->tx_req, 0);
385 tx_queue->tx_req->tp_block_size = tx_frame_size * tx_frames_per_block;
386 tx_queue->tx_req->tp_frame_size = tx_frame_size;
387 tx_queue->tx_req->tp_block_nr = AF_PACKET_TX_BLOCK_NR;
388 tx_queue->tx_req->tp_frame_nr =
389 AF_PACKET_TX_BLOCK_NR * tx_frames_per_block;
390 tx_queue->tx_req->tp_retire_blk_tov = 0;
391 tx_queue->tx_req->tp_sizeof_priv = 0;
392 tx_queue->tx_req->tp_feature_req_word = 0;
393 tx_req = tx_queue->tx_req;
394 }
395
Mohsin Kazmi3ce1d142022-04-05 10:46:39 +0000396 if (rx_queue || tx_queue)
397 {
Mohsin Kazmi788676b2022-04-05 12:43:13 +0000398 ret =
399 create_packet_v3_sock (apif->host_if_index, rx_req, tx_req, &fd, &ring,
400 apif->dev_instance, is_fanout, &arg->flags);
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000401
Mohsin Kazmi3ce1d142022-04-05 10:46:39 +0000402 if (ret != 0)
403 goto error;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000404
Mohsin Kazmi3ce1d142022-04-05 10:46:39 +0000405 vec_add1 (apif->rings, ring);
406 ring_addr = ring.ring_start_addr;
407 }
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000408
409 if (rx_queue)
410 {
411 rx_queue->fd = fd;
412 vec_validate (rx_queue->rx_ring, rx_queue->rx_req->tp_block_nr - 1);
413 vec_foreach_index (i, rx_queue->rx_ring)
414 {
415 rx_queue->rx_ring[i] =
416 ring_addr + i * rx_queue->rx_req->tp_block_size;
417 }
418
419 rx_queue->next_rx_block = 0;
420 rx_queue->queue_id = queue_id;
421 rx_queue->is_rx_pending = 0;
422 ring_addr = ring_addr + rx_queue->rx_req->tp_block_size *
423 rx_queue->rx_req->tp_block_nr;
424 }
425
426 if (tx_queue)
427 {
428 tx_queue->fd = fd;
429 vec_validate (tx_queue->tx_ring, tx_queue->tx_req->tp_block_nr - 1);
430 vec_foreach_index (i, tx_queue->tx_ring)
431 {
432 tx_queue->tx_ring[i] =
433 ring_addr + i * tx_queue->tx_req->tp_block_size;
434 }
435
436 tx_queue->next_tx_frame = 0;
437 tx_queue->queue_id = queue_id;
438 clib_spinlock_init (&tx_queue->lockp);
439 }
440
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000441 return 0;
442error:
443 vlib_log_err (apm->log_class, "Failed to set queue %u error", queue_id);
Mohsin Kazmi3ce1d142022-04-05 10:46:39 +0000444 if (rx_queue)
445 vec_free (rx_queue->rx_req);
446 if (tx_queue)
447 vec_free (tx_queue->tx_req);
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000448 return ret;
449}
450
451int
452af_packet_device_init (vlib_main_t *vm, af_packet_if_t *apif,
453 af_packet_create_if_arg_t *args)
454{
455 af_packet_main_t *apm = &af_packet_main;
456 af_packet_queue_t *rx_queue = 0;
457 af_packet_queue_t *tx_queue = 0;
458 u16 nq = clib_min (args->num_rxqs, args->num_txqs);
459 u16 i = 0;
460 int ret = 0;
461 u8 is_fanout = (args->num_rxqs > 1) ? 1 : 0;
462
463 vec_validate (apif->rx_queues, args->num_rxqs - 1);
464 vec_validate (apif->tx_queues, args->num_txqs - 1);
465
466 for (; i < nq; i++)
467 {
468 rx_queue = vec_elt_at_index (apif->rx_queues, i);
469 tx_queue = vec_elt_at_index (apif->tx_queues, i);
470 ret = af_packet_queue_init (vm, apif, args, rx_queue, tx_queue, i,
471 is_fanout);
472 if (ret != 0)
473 goto error;
474 }
475
476 if (args->num_rxqs > args->num_txqs)
477 {
478 for (; i < args->num_rxqs; i++)
479 {
480 rx_queue = vec_elt_at_index (apif->rx_queues, i);
481 ret =
482 af_packet_queue_init (vm, apif, args, rx_queue, 0, i, is_fanout);
483 if (ret != 0)
484 goto error;
485 }
486 }
487 else if (args->num_txqs > args->num_rxqs)
488 {
489 for (; i < args->num_txqs; i++)
490 {
491 tx_queue = vec_elt_at_index (apif->tx_queues, i);
492 ret = af_packet_queue_init (vm, apif, args, 0, tx_queue, i, 0);
493 if (ret != 0)
494 goto error;
495 }
496 }
497
498 apif->num_rxqs = args->num_rxqs;
499 apif->num_txqs = args->num_txqs;
500
501 return 0;
502error:
503 vlib_log_err (apm->log_class, "Failed to init device error");
504 return ret;
505}
506
507int
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200508af_packet_create_if (af_packet_create_if_arg_t *arg)
Damjan Marion83243a02016-02-29 13:09:30 +0100509{
Damjan Marion00a9dca2016-08-17 17:05:46 +0200510 af_packet_main_t *apm = &af_packet_main;
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200511 vlib_main_t *vm = vlib_get_main ();
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000512 int fd2 = -1;
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200513 struct ifreq ifr;
Damjan Marion00a9dca2016-08-17 17:05:46 +0200514 af_packet_if_t *apif = 0;
Damjan Marion83243a02016-02-29 13:09:30 +0100515 u8 hw_addr[6];
Damjan Marion00a9dca2016-08-17 17:05:46 +0200516 vnet_sw_interface_t *sw;
517 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +0000518 vnet_hw_if_caps_t caps = VNET_HW_IF_CAP_INT_MODE;
Damjan Marion00a9dca2016-08-17 17:05:46 +0200519 uword *p;
Damjan Marion83243a02016-02-29 13:09:30 +0100520 uword if_index;
jackiechen19857fa41602019-05-07 18:59:13 +0800521 u8 *host_if_name_dup = 0;
Ray Kinsellac855b732017-04-21 12:24:43 +0100522 int host_if_index = -1;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000523 int ret = 0;
Damjan Marion83243a02016-02-29 13:09:30 +0100524
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200525 p = mhash_get (&apm->if_index_by_host_if_name, arg->host_if_name);
Damjan Marion83243a02016-02-29 13:09:30 +0100526 if (p)
527 {
Mohsin Kazmi43fc6882018-03-22 23:45:23 +0100528 apif = vec_elt_at_index (apm->interfaces, p[0]);
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200529 arg->sw_if_index = apif->sw_if_index;
Mohsin Kazmi43fc6882018-03-22 23:45:23 +0100530 return VNET_API_ERROR_IF_ALREADY_EXISTS;
Damjan Marion83243a02016-02-29 13:09:30 +0100531 }
532
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200533 host_if_name_dup = vec_dup (arg->host_if_name);
534
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200535 /*
536 * make sure host side of interface is 'UP' before binding AF_PACKET
537 * socket on it.
538 */
539 if ((fd2 = socket (AF_UNIX, SOCK_DGRAM, 0)) < 0)
Ray Kinsellac855b732017-04-21 12:24:43 +0100540 {
jackiechen19857fa41602019-05-07 18:59:13 +0800541 vlib_log_debug (apm->log_class,
542 "Failed to create AF_UNIX socket: %s (errno %d)",
543 strerror (errno), errno);
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200544 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
545 goto error;
546 }
547
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200548 clib_memcpy (ifr.ifr_name, (const char *) arg->host_if_name,
549 vec_len (arg->host_if_name));
jackiechen19857fa41602019-05-07 18:59:13 +0800550 if (ioctl (fd2, SIOCGIFINDEX, &ifr) < 0)
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200551 {
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200552 vlib_log_debug (
553 apm->log_class,
554 "Failed to retrieve the interface (%s) index: %s (errno %d)",
555 arg->host_if_name, strerror (errno), errno);
jackiechen19857fa41602019-05-07 18:59:13 +0800556 ret = VNET_API_ERROR_INVALID_INTERFACE;
557 goto error;
Ray Kinsellac855b732017-04-21 12:24:43 +0100558 }
559
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200560 host_if_index = ifr.ifr_ifindex;
jackiechen19857fa41602019-05-07 18:59:13 +0800561 if (ioctl (fd2, SIOCGIFFLAGS, &ifr) < 0)
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200562 {
jackiechen19857fa41602019-05-07 18:59:13 +0800563 vlib_log_debug (apm->log_class,
564 "Failed to get the active flag: %s (errno %d)",
565 strerror (errno), errno);
566 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200567 goto error;
568 }
569
570 if (!(ifr.ifr_flags & IFF_UP))
571 {
572 ifr.ifr_flags |= IFF_UP;
jackiechen19857fa41602019-05-07 18:59:13 +0800573 if (ioctl (fd2, SIOCSIFFLAGS, &ifr) < 0)
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200574 {
jackiechen19857fa41602019-05-07 18:59:13 +0800575 vlib_log_debug (apm->log_class,
576 "Failed to set the active flag: %s (errno %d)",
577 strerror (errno), errno);
578 ret = VNET_API_ERROR_SYSCALL_ERROR_1;
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200579 goto error;
580 }
581 }
582
583 if (fd2 > -1)
jackiechen19857fa41602019-05-07 18:59:13 +0800584 {
585 close (fd2);
586 fd2 = -1;
587 }
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200588
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200589 ret = is_bridge (arg->host_if_name);
Ray Kinsellac855b732017-04-21 12:24:43 +0100590 if (ret == 0) /* is a bridge, ignore state */
591 host_if_index = -1;
592
Damjan Marion83243a02016-02-29 13:09:30 +0100593 /* So far everything looks good, let's create interface */
Damjan Marion048ee2e2016-03-16 22:59:21 +0100594 pool_get (apm->interfaces, apif);
Damjan Marion83243a02016-02-29 13:09:30 +0100595 if_index = apif - apm->interfaces;
596
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000597 apif->dev_instance = if_index;
Ray Kinsellac855b732017-04-21 12:24:43 +0100598 apif->host_if_index = host_if_index;
Ivan Kellybfe737a2016-10-07 18:02:43 +0200599 apif->host_if_name = host_if_name_dup;
Dave Barach13f3c452016-03-29 11:56:41 -0400600 apif->per_interface_next_index = ~0;
Mohsin Kazmicae84fa2021-10-08 15:10:49 +0000601 apif->mode = arg->mode;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000602
603 ret = af_packet_device_init (vm, apif, arg);
604 if (ret != 0)
605 goto error;
Damjan Marion83243a02016-02-29 13:09:30 +0100606
Nathan Skrzypczakffc6bdc2021-02-01 17:13:59 +0100607 ret = af_packet_read_mtu (apif);
608 if (ret != 0)
609 goto error;
610
Mohsin KAZMIcf751ec2017-01-18 11:59:45 +0100611
Nathan Skrzypczakb225b0a2021-10-26 16:11:38 +0200612 if (apif->mode != AF_PACKET_IF_MODE_IP)
Mohsin Kazmicae84fa2021-10-08 15:10:49 +0000613 {
Damjan Marion5c954c42022-01-06 20:36:14 +0100614 vnet_eth_interface_registration_t eir = {};
Mohsin Kazmicae84fa2021-10-08 15:10:49 +0000615 /*use configured or generate random MAC address */
616 if (arg->hw_addr)
617 clib_memcpy (hw_addr, arg->hw_addr, 6);
618 else
619 {
620 f64 now = vlib_time_now (vm);
621 u32 rnd;
622 rnd = (u32) (now * 1e6);
623 rnd = random_u32 (&rnd);
624
625 clib_memcpy (hw_addr + 2, &rnd, sizeof (rnd));
626 hw_addr[0] = 2;
627 hw_addr[1] = 0xfe;
628 }
629
Damjan Marion5c954c42022-01-06 20:36:14 +0100630 eir.dev_class_index = af_packet_device_class.index;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000631 eir.dev_instance = apif->dev_instance;
Damjan Marion5c954c42022-01-06 20:36:14 +0100632 eir.address = hw_addr;
Damjan Marion1cd0e5d2022-01-17 14:49:17 +0100633 eir.cb.set_max_frame_size = af_packet_eth_set_max_frame_size;
Damjan Marion5c954c42022-01-06 20:36:14 +0100634 apif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
Mohsin Kazmicae84fa2021-10-08 15:10:49 +0000635 }
Damjan Marion83243a02016-02-29 13:09:30 +0100636 else
637 {
Mohsin Kazmicae84fa2021-10-08 15:10:49 +0000638 apif->hw_if_index = vnet_register_interface (
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000639 vnm, af_packet_device_class.index, apif->dev_instance,
640 af_packet_ip_device_hw_interface_class.index, apif->dev_instance);
Damjan Marion83243a02016-02-29 13:09:30 +0100641 }
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000642
Damjan Marion83243a02016-02-29 13:09:30 +0100643 sw = vnet_get_hw_sw_interface (vnm, apif->hw_if_index);
644 apif->sw_if_index = sw->sw_if_index;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000645
646 af_packet_set_rx_queues (vm, apif);
647 af_packet_set_tx_queues (vm, apif);
Damjan Marion44036902017-04-28 12:29:15 +0200648
Mohsin Kazmi2b6479c2022-04-05 12:03:47 +0000649 apif->is_qdisc_bypass_enabled =
650 (arg->flags & AF_PACKET_IF_FLAGS_QDISC_BYPASS);
651
Mohsin Kazmi788676b2022-04-05 12:43:13 +0000652 if (arg->flags & AF_PACKET_IF_FLAGS_CKSUM_GSO)
653 apif->is_cksum_gso_enabled = 1;
654
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +0000655 if (apif->is_cksum_gso_enabled)
656 caps |= VNET_HW_IF_CAP_TCP_GSO | VNET_HW_IF_CAP_TX_IP4_CKSUM |
657 VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM;
658
659 vnet_hw_if_set_caps (vnm, apif->hw_if_index, caps);
Damjan Marion83243a02016-02-29 13:09:30 +0100660 vnet_hw_interface_set_flags (vnm, apif->hw_if_index,
661 VNET_HW_INTERFACE_FLAG_LINK_UP);
662
Ivan Kellybfe737a2016-10-07 18:02:43 +0200663 mhash_set_mem (&apm->if_index_by_host_if_name, host_if_name_dup, &if_index,
664 0);
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200665 arg->sw_if_index = apif->sw_if_index;
Mohsin KAZMIcf751ec2017-01-18 11:59:45 +0100666
Damjan Marion83243a02016-02-29 13:09:30 +0100667 return 0;
668
669error:
Mohsin Kazmia50a14c2018-04-25 15:58:05 +0200670 if (fd2 > -1)
jackiechen19857fa41602019-05-07 18:59:13 +0800671 {
672 close (fd2);
673 fd2 = -1;
674 }
Ivan Kellybfe737a2016-10-07 18:02:43 +0200675 vec_free (host_if_name_dup);
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000676 memset (apif, 0, sizeof (*apif));
677 pool_put (apm->interfaces, apif);
Damjan Marion83243a02016-02-29 13:09:30 +0100678 return ret;
679}
680
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000681static int
682af_packet_rx_queue_free (af_packet_if_t *apif, af_packet_queue_t *rx_queue)
683{
684 clib_file_del_by_index (&file_main, rx_queue->clib_file_index);
685 close (rx_queue->fd);
686 rx_queue->fd = -1;
687 rx_queue->rx_ring = NULL;
688 vec_free (rx_queue->rx_req);
689 rx_queue->rx_req = NULL;
690 return 0;
691}
692
693static int
694af_packet_tx_queue_free (af_packet_if_t *apif, af_packet_queue_t *tx_queue)
695{
696 close (tx_queue->fd);
697 tx_queue->fd = -1;
698 clib_spinlock_free (&tx_queue->lockp);
699 tx_queue->tx_ring = NULL;
700 vec_free (tx_queue->tx_req);
701 tx_queue->tx_req = NULL;
702 return 0;
703}
704
705static int
706af_packet_ring_free (af_packet_if_t *apif, af_packet_ring_t *ring)
707{
708 af_packet_main_t *apm = &af_packet_main;
709
710 if (ring)
711 {
712 // FIXME: unmap the memory
713 if (munmap (ring->ring_start_addr, ring->ring_size))
714 vlib_log_warn (apm->log_class,
715 "Host interface %s could not free ring %p of size %u",
716 apif->host_if_name, ring->ring_start_addr,
717 ring->ring_size);
718 else
719 ring->ring_start_addr = 0;
720 }
721
722 return 0;
723}
724
Peter Leidba76f22016-04-08 08:16:31 -0700725int
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200726af_packet_delete_if (u8 *host_if_name)
Peter Leidba76f22016-04-08 08:16:31 -0700727{
Damjan Marion00a9dca2016-08-17 17:05:46 +0200728 vnet_main_t *vnm = vnet_get_main ();
Peter Leidba76f22016-04-08 08:16:31 -0700729 af_packet_main_t *apm = &af_packet_main;
730 af_packet_if_t *apif;
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000731 af_packet_queue_t *rx_queue;
732 af_packet_queue_t *tx_queue;
733 af_packet_ring_t *ring;
Peter Leidba76f22016-04-08 08:16:31 -0700734 uword *p;
Peter Leidba76f22016-04-08 08:16:31 -0700735
Damjan Marion00a9dca2016-08-17 17:05:46 +0200736 p = mhash_get (&apm->if_index_by_host_if_name, host_if_name);
737 if (p == NULL)
738 {
Mohsin Kazmiacba9f72018-05-17 15:42:27 +0200739 vlib_log_warn (apm->log_class, "Host interface %s does not exist",
740 host_if_name);
Damjan Marion00a9dca2016-08-17 17:05:46 +0200741 return VNET_API_ERROR_SYSCALL_ERROR_1;
742 }
743 apif = pool_elt_at_index (apm->interfaces, p[0]);
Peter Leidba76f22016-04-08 08:16:31 -0700744
745 /* bring down the interface */
Damjan Marion00a9dca2016-08-17 17:05:46 +0200746 vnet_hw_interface_set_flags (vnm, apif->hw_if_index, 0);
Peter Leidba76f22016-04-08 08:16:31 -0700747
748 /* clean up */
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000749 vec_foreach (rx_queue, apif->rx_queues)
750 af_packet_rx_queue_free (apif, rx_queue);
751 vec_foreach (tx_queue, apif->tx_queues)
752 af_packet_tx_queue_free (apif, tx_queue);
753 vec_foreach (ring, apif->rings)
754 af_packet_ring_free (apif, ring);
Eyal Barif298ecf2016-09-19 18:47:39 +0300755
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000756 vec_free (apif->rx_queues);
757 apif->rx_queues = NULL;
758 vec_free (apif->tx_queues);
759 apif->tx_queues = NULL;
760 vec_free (apif->rings);
761 apif->rings = NULL;
Peter Leidba76f22016-04-08 08:16:31 -0700762
Damjan Marion00a9dca2016-08-17 17:05:46 +0200763 vec_free (apif->host_if_name);
Peter Leidba76f22016-04-08 08:16:31 -0700764 apif->host_if_name = NULL;
Ray Kinsellac855b732017-04-21 12:24:43 +0100765 apif->host_if_index = -1;
Peter Leidba76f22016-04-08 08:16:31 -0700766
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000767 mhash_unset (&apm->if_index_by_host_if_name, host_if_name, p);
Peter Leidba76f22016-04-08 08:16:31 -0700768
Nathan Skrzypczakb225b0a2021-10-26 16:11:38 +0200769 if (apif->mode != AF_PACKET_IF_MODE_IP)
Mohsin Kazmicae84fa2021-10-08 15:10:49 +0000770 ethernet_delete_interface (vnm, apif->hw_if_index);
771 else
772 vnet_delete_hw_interface (vnm, apif->hw_if_index);
Peter Leidba76f22016-04-08 08:16:31 -0700773
Mohsin Kazmi5a7aa512022-03-25 14:27:45 +0000774 memset (apif, 0, sizeof (*apif));
Damjan Marion00a9dca2016-08-17 17:05:46 +0200775 pool_put (apm->interfaces, apif);
Peter Leidba76f22016-04-08 08:16:31 -0700776
777 return 0;
778}
779
Jakub Grajciar92b02752017-10-20 13:37:28 +0200780int
Nathan Skrzypczak7d0e30b2021-06-23 11:28:39 +0200781af_packet_set_l4_cksum_offload (u32 sw_if_index, u8 set)
Jakub Grajciar92b02752017-10-20 13:37:28 +0200782{
Mohsin Kazmic1fd17b2022-03-22 21:40:04 +0000783 // deprecated ...
Jakub Grajciar92b02752017-10-20 13:37:28 +0200784 return 0;
785}
786
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +0200787int
788af_packet_dump_ifs (af_packet_if_detail_t ** out_af_packet_ifs)
789{
790 af_packet_main_t *apm = &af_packet_main;
791 af_packet_if_t *apif;
792 af_packet_if_detail_t *r_af_packet_ifs = NULL;
793 af_packet_if_detail_t *af_packet_if = NULL;
794
Damjan Marionb2c31b62020-12-13 21:47:40 +0100795 pool_foreach (apif, apm->interfaces)
796 {
Jakub Grajciar3b2db902019-08-26 11:25:52 +0200797 vec_add2 (r_af_packet_ifs, af_packet_if, 1);
798 af_packet_if->sw_if_index = apif->sw_if_index;
799 if (apif->host_if_name)
800 {
801 clib_memcpy (af_packet_if->host_if_name, apif->host_if_name,
802 MIN (ARRAY_LEN (af_packet_if->host_if_name) - 1,
803 strlen ((const char *) apif->host_if_name)));
804 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100805 }
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +0200806
807 *out_af_packet_ifs = r_af_packet_ifs;
808
809 return 0;
810}
811
Damjan Marion83243a02016-02-29 13:09:30 +0100812static clib_error_t *
813af_packet_init (vlib_main_t * vm)
814{
Damjan Marion00a9dca2016-08-17 17:05:46 +0200815 af_packet_main_t *apm = &af_packet_main;
Damjan Marion553f6bd2016-09-07 11:54:22 +0200816 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marion83243a02016-02-29 13:09:30 +0100817
Dave Barachb7b92992018-10-17 10:38:51 -0400818 clib_memset (apm, 0, sizeof (af_packet_main_t));
Damjan Marion83243a02016-02-29 13:09:30 +0100819
820 mhash_init_vec_string (&apm->if_index_by_host_if_name, sizeof (uword));
821
Damjan Marion553f6bd2016-09-07 11:54:22 +0200822 vec_validate_aligned (apm->rx_buffers, tm->n_vlib_mains - 1,
823 CLIB_CACHE_LINE_BYTES);
824
Mohsin Kazmiacba9f72018-05-17 15:42:27 +0200825 apm->log_class = vlib_log_register_class ("af_packet", 0);
826 vlib_log_debug (apm->log_class, "initialized");
827
Damjan Marion83243a02016-02-29 13:09:30 +0100828 return 0;
829}
830
831VLIB_INIT_FUNCTION (af_packet_init);
Damjan Marion00a9dca2016-08-17 17:05:46 +0200832
833/*
834 * fd.io coding-style-patch-verification: ON
835 *
836 * Local Variables:
837 * eval: (c-set-style "gnu")
838 * End:
839 */