Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 1 | /* |
| 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 Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 22 | #include <sys/ioctl.h> |
| 23 | #include <net/if.h> |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 24 | #include <dirent.h> |
Ray Kinsella | 7bfa119 | 2017-05-15 11:52:43 +0100 | [diff] [blame] | 25 | #include <sys/stat.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <fcntl.h> |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 28 | |
Damjan Marion | 01914ce | 2017-09-14 19:04:50 +0200 | [diff] [blame] | 29 | #include <vppinfra/linux/sysfs.h> |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 30 | #include <vlib/vlib.h> |
| 31 | #include <vlib/unix/unix.h> |
| 32 | #include <vnet/ip/ip.h> |
Aloys Augustin | e39376e | 2021-03-29 22:08:09 +0200 | [diff] [blame] | 33 | #include <vnet/devices/netlink.h> |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 34 | #include <vnet/ethernet/ethernet.h> |
Mohammed Hawari | 85c1943 | 2020-12-18 16:29:45 +0100 | [diff] [blame] | 35 | #include <vnet/interface/rx_queue_funcs.h> |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 36 | #include <vnet/interface/tx_queue_funcs.h> |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 37 | |
| 38 | #include <vnet/devices/af_packet/af_packet.h> |
| 39 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 40 | af_packet_main_t af_packet_main; |
| 41 | |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 42 | VNET_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 Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 47 | #define AF_PACKET_DEFAULT_TX_FRAMES_PER_BLOCK 1024 |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 48 | #define AF_PACKET_DEFAULT_TX_FRAME_SIZE (2048 * 33) // GSO packet of 64KB |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 49 | #define AF_PACKET_TX_BLOCK_NR 1 |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 50 | |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 51 | #define AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK_V2 1024 |
| 52 | #define AF_PACKET_DEFAULT_RX_FRAME_SIZE_V2 (2048 * 33) // GSO packet of 64KB |
| 53 | #define AF_PACKET_RX_BLOCK_NR_V2 1 |
| 54 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 55 | #define AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK 32 |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 56 | #define AF_PACKET_DEFAULT_RX_FRAME_SIZE 2048 |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 57 | #define AF_PACKET_RX_BLOCK_NR 160 |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 58 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 59 | /*defined in net/if.h but clashes with dpdk headers */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 60 | unsigned int if_nametoindex (const char *ifname); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 61 | |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 62 | static clib_error_t * |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame] | 63 | af_packet_eth_set_max_frame_size (vnet_main_t *vnm, vnet_hw_interface_t *hi, |
| 64 | u32 frame_size) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 65 | { |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 66 | clib_error_t *error, *rv; |
Ray Kinsella | 7bfa119 | 2017-05-15 11:52:43 +0100 | [diff] [blame] | 67 | af_packet_main_t *apm = &af_packet_main; |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 68 | af_packet_if_t *apif = pool_elt_at_index (apm->interfaces, hi->dev_instance); |
Ray Kinsella | 7bfa119 | 2017-05-15 11:52:43 +0100 | [diff] [blame] | 69 | |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame] | 70 | error = vnet_netlink_set_link_mtu (apif->host_if_index, |
| 71 | frame_size + hi->frame_overhead); |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 72 | |
| 73 | if (error) |
Ray Kinsella | 7bfa119 | 2017-05-15 11:52:43 +0100 | [diff] [blame] | 74 | { |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 75 | vlib_log_err (apm->log_class, "netlink failed to change MTU: %U", |
| 76 | format_clib_error, error); |
| 77 | rv = vnet_error (VNET_ERR_SYSCALL_ERROR_1, "netlink error: %U", |
| 78 | format_clib_error, error); |
| 79 | clib_error_free (error); |
| 80 | return rv; |
Ray Kinsella | 7bfa119 | 2017-05-15 11:52:43 +0100 | [diff] [blame] | 81 | } |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 82 | else |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame] | 83 | apif->host_mtu = frame_size + hi->frame_overhead; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Nathan Skrzypczak | ffc6bdc | 2021-02-01 17:13:59 +0100 | [diff] [blame] | 87 | static int |
| 88 | af_packet_read_mtu (af_packet_if_t *apif) |
| 89 | { |
| 90 | af_packet_main_t *apm = &af_packet_main; |
| 91 | clib_error_t *error; |
Aloys Augustin | e39376e | 2021-03-29 22:08:09 +0200 | [diff] [blame] | 92 | error = vnet_netlink_get_link_mtu (apif->host_if_index, &apif->host_mtu); |
Nathan Skrzypczak | ffc6bdc | 2021-02-01 17:13:59 +0100 | [diff] [blame] | 93 | if (error) |
| 94 | { |
Aloys Augustin | e39376e | 2021-03-29 22:08:09 +0200 | [diff] [blame] | 95 | vlib_log_err (apm->log_class, "netlink failed to get MTU: %U", |
Nathan Skrzypczak | ffc6bdc | 2021-02-01 17:13:59 +0100 | [diff] [blame] | 96 | format_clib_error, error); |
| 97 | clib_error_free (error); |
| 98 | return VNET_API_ERROR_SYSCALL_ERROR_1; |
| 99 | } |
| 100 | return 0; |
| 101 | } |
| 102 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 103 | static clib_error_t * |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 104 | af_packet_fd_read_ready (clib_file_t * uf) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 105 | { |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 106 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 107 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 108 | /* Schedule the rx node */ |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 109 | vnet_hw_if_rx_queue_set_int_pending (vnm, uf->private_data); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 114 | is_bridge (const u8 * host_if_name) |
| 115 | { |
| 116 | u8 *s; |
| 117 | DIR *dir = NULL; |
| 118 | |
| 119 | s = format (0, "/sys/class/net/%s/bridge%c", host_if_name, 0); |
| 120 | dir = opendir ((char *) s); |
| 121 | vec_free (s); |
| 122 | |
| 123 | if (dir) |
| 124 | { |
| 125 | closedir (dir); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | return -1; |
| 130 | } |
| 131 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 132 | static void |
| 133 | af_packet_set_rx_queues (vlib_main_t *vm, af_packet_if_t *apif) |
| 134 | { |
| 135 | vnet_main_t *vnm = vnet_get_main (); |
| 136 | af_packet_queue_t *rx_queue; |
| 137 | |
| 138 | vnet_hw_if_set_input_node (vnm, apif->hw_if_index, |
| 139 | af_packet_input_node.index); |
| 140 | |
| 141 | vec_foreach (rx_queue, apif->rx_queues) |
| 142 | { |
| 143 | rx_queue->queue_index = vnet_hw_if_register_rx_queue ( |
| 144 | vnm, apif->hw_if_index, rx_queue->queue_id, VNET_HW_IF_RXQ_THREAD_ANY); |
| 145 | |
| 146 | { |
| 147 | clib_file_t template = { 0 }; |
| 148 | template.read_function = af_packet_fd_read_ready; |
| 149 | template.file_descriptor = rx_queue->fd; |
| 150 | template.private_data = rx_queue->queue_index; |
| 151 | template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED; |
| 152 | template.description = |
| 153 | format (0, "%U queue %u", format_af_packet_device_name, |
| 154 | apif->dev_instance, rx_queue->queue_id); |
| 155 | rx_queue->clib_file_index = clib_file_add (&file_main, &template); |
| 156 | } |
| 157 | vnet_hw_if_set_rx_queue_file_index (vnm, rx_queue->queue_index, |
| 158 | rx_queue->clib_file_index); |
| 159 | vnet_hw_if_set_rx_queue_mode (vnm, rx_queue->queue_index, |
| 160 | VNET_HW_IF_RX_MODE_INTERRUPT); |
| 161 | rx_queue->mode = VNET_HW_IF_RX_MODE_INTERRUPT; |
| 162 | } |
| 163 | vnet_hw_if_update_runtime_data (vnm, apif->hw_if_index); |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | af_packet_set_tx_queues (vlib_main_t *vm, af_packet_if_t *apif) |
| 168 | { |
| 169 | vnet_main_t *vnm = vnet_get_main (); |
| 170 | af_packet_main_t *apm = &af_packet_main; |
| 171 | af_packet_queue_t *tx_queue; |
| 172 | |
| 173 | vec_foreach (tx_queue, apif->tx_queues) |
| 174 | { |
| 175 | tx_queue->queue_index = vnet_hw_if_register_tx_queue ( |
| 176 | vnm, apif->hw_if_index, tx_queue->queue_id); |
| 177 | } |
| 178 | |
| 179 | if (apif->num_txqs == 0) |
| 180 | { |
| 181 | vlib_log_err (apm->log_class, "Interface %U has 0 txq", |
| 182 | format_vnet_hw_if_index_name, vnm, apif->hw_if_index); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | for (u32 j = 0; j < vlib_get_n_threads (); j++) |
| 187 | { |
| 188 | u32 qi = apif->tx_queues[j % apif->num_txqs].queue_index; |
| 189 | vnet_hw_if_tx_queue_assign_thread (vnm, qi, j); |
| 190 | } |
| 191 | |
| 192 | vnet_hw_if_update_runtime_data (vnm, apif->hw_if_index); |
| 193 | } |
| 194 | |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 195 | static int |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 196 | create_packet_sock (int host_if_index, tpacket_req_u_t *rx_req, |
| 197 | tpacket_req_u_t *tx_req, int *fd, af_packet_ring_t *ring, |
| 198 | u32 fanout_id, af_packet_if_flags_t *flags, int ver) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 199 | { |
Mohsin Kazmi | acba9f7 | 2018-05-17 15:42:27 +0200 | [diff] [blame] | 200 | af_packet_main_t *apm = &af_packet_main; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 201 | struct sockaddr_ll sll; |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 202 | socklen_t req_sz = sizeof (tpacket_req3_t); |
| 203 | int ret; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 204 | u32 ring_sz = 0; |
| 205 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 206 | if ((*fd = socket (AF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 207 | { |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 208 | vlib_log_err (apm->log_class, |
| 209 | "Failed to create AF_PACKET socket: %s (errno %d)", |
| 210 | strerror (errno), errno); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 211 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 212 | goto error; |
| 213 | } |
Damjan Marion | c517020 | 2017-10-11 14:15:47 +0200 | [diff] [blame] | 214 | |
Chaoyu Jin | afb1930 | 2018-03-13 07:37:41 -0700 | [diff] [blame] | 215 | /* bind before rx ring is cfged so we don't receive packets from other interfaces */ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 216 | clib_memset (&sll, 0, sizeof (sll)); |
Chaoyu Jin | afb1930 | 2018-03-13 07:37:41 -0700 | [diff] [blame] | 217 | sll.sll_family = PF_PACKET; |
| 218 | sll.sll_protocol = htons (ETH_P_ALL); |
| 219 | sll.sll_ifindex = host_if_index; |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 220 | if (bind (*fd, (struct sockaddr *) &sll, sizeof (sll)) < 0) |
Chaoyu Jin | afb1930 | 2018-03-13 07:37:41 -0700 | [diff] [blame] | 221 | { |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 222 | vlib_log_err (apm->log_class, |
| 223 | "Failed to bind rx packet socket: %s (errno %d)", |
| 224 | strerror (errno), errno); |
Chaoyu Jin | afb1930 | 2018-03-13 07:37:41 -0700 | [diff] [blame] | 225 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 226 | goto error; |
| 227 | } |
| 228 | |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 229 | if (setsockopt (*fd, SOL_PACKET, PACKET_VERSION, &ver, sizeof (ver)) < 0) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 230 | { |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 231 | vlib_log_err (apm->log_class, |
| 232 | "Failed to set rx packet interface version: %s (errno %d)", |
| 233 | strerror (errno), errno); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 234 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 235 | goto error; |
| 236 | } |
| 237 | |
Damjan Marion | c517020 | 2017-10-11 14:15:47 +0200 | [diff] [blame] | 238 | int opt = 1; |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 239 | if (setsockopt (*fd, SOL_PACKET, PACKET_LOSS, &opt, sizeof (opt)) < 0) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 240 | { |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 241 | vlib_log_err ( |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 242 | apm->log_class, |
| 243 | "Failed to set packet tx ring error handling option: %s (errno %d)", |
| 244 | strerror (errno), errno); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 245 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 246 | goto error; |
| 247 | } |
| 248 | |
Mohsin Kazmi | 788676b | 2022-04-05 12:43:13 +0000 | [diff] [blame] | 249 | if (*flags & AF_PACKET_IF_FLAGS_CKSUM_GSO) |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 250 | { |
Mohsin Kazmi | 788676b | 2022-04-05 12:43:13 +0000 | [diff] [blame] | 251 | |
| 252 | int opt2 = 1; |
| 253 | if (setsockopt (*fd, SOL_PACKET, PACKET_VNET_HDR, &opt2, sizeof (opt2)) < |
| 254 | 0) |
| 255 | { |
| 256 | // remove the flag |
| 257 | *flags &= ~AF_PACKET_IF_FLAGS_CKSUM_GSO; |
| 258 | vlib_log_debug (apm->log_class, |
| 259 | "Failed to set packet vnet hdr error handling " |
| 260 | "option: %s (errno %d)", |
| 261 | strerror (errno), errno); |
| 262 | } |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 263 | } |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 264 | |
Florin Coras | 2dc942e | 2021-11-22 21:34:56 -0800 | [diff] [blame] | 265 | #if defined(PACKET_QDISC_BYPASS) |
Mohsin Kazmi | 2b6479c | 2022-04-05 12:03:47 +0000 | [diff] [blame] | 266 | if (*flags & AF_PACKET_IF_FLAGS_QDISC_BYPASS) |
| 267 | /* Introduced with Linux 3.14 so the ifdef should eventually be removed */ |
| 268 | if (setsockopt (*fd, SOL_PACKET, PACKET_QDISC_BYPASS, &opt, sizeof (opt)) < |
| 269 | 0) |
| 270 | { |
| 271 | // remove the flag |
| 272 | *flags &= ~AF_PACKET_IF_FLAGS_QDISC_BYPASS; |
| 273 | vlib_log_debug (apm->log_class, |
| 274 | "Failed to set qdisc bypass error " |
| 275 | "handling option: %s (errno %d)", |
| 276 | strerror (errno), errno); |
| 277 | } |
Florin Coras | 2dc942e | 2021-11-22 21:34:56 -0800 | [diff] [blame] | 278 | #endif |
Mohammed Hawari | eed6fc9 | 2021-09-06 11:48:17 +0200 | [diff] [blame] | 279 | |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 280 | if (rx_req) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 281 | { |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 282 | if (*flags & AF_PACKET_IF_FLAGS_FANOUT) |
| 283 | { |
| 284 | int fanout = ((fanout_id & 0xffff) | ((PACKET_FANOUT_HASH) << 16)); |
| 285 | if (setsockopt (*fd, SOL_PACKET, PACKET_FANOUT, &fanout, |
| 286 | sizeof (fanout)) < 0) |
| 287 | { |
| 288 | // remove the flag |
| 289 | *flags &= ~AF_PACKET_IF_FLAGS_FANOUT; |
| 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 | } |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 297 | if (ver == TPACKET_V2) |
| 298 | { |
| 299 | req_sz = sizeof (tpacket_req_t); |
| 300 | ring_sz += rx_req->req.tp_block_size * rx_req->req.tp_block_nr; |
| 301 | } |
| 302 | else |
| 303 | ring_sz += rx_req->req3.tp_block_size * rx_req->req3.tp_block_nr; |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 304 | if (setsockopt (*fd, SOL_PACKET, PACKET_RX_RING, rx_req, req_sz) < 0) |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 305 | { |
| 306 | vlib_log_err (apm->log_class, |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 307 | "Failed to set packet rx ring options: %s (errno %d)", |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 308 | strerror (errno), errno); |
| 309 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 310 | goto error; |
| 311 | } |
| 312 | } |
| 313 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 314 | if (tx_req) |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 315 | { |
| 316 | if (ver == TPACKET_V2) |
| 317 | { |
| 318 | req_sz = sizeof (tpacket_req_t); |
| 319 | ring_sz += tx_req->req.tp_block_size * tx_req->req.tp_block_nr; |
| 320 | } |
| 321 | else |
| 322 | ring_sz += tx_req->req3.tp_block_size * tx_req->req3.tp_block_nr; |
| 323 | if (setsockopt (*fd, SOL_PACKET, PACKET_TX_RING, tx_req, req_sz) < 0) |
| 324 | { |
| 325 | vlib_log_err (apm->log_class, |
| 326 | "Failed to set packet tx ring options: %s (errno %d)", |
| 327 | strerror (errno), errno); |
| 328 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 329 | goto error; |
| 330 | } |
| 331 | } |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 332 | ring->ring_start_addr = mmap (NULL, ring_sz, PROT_READ | PROT_WRITE, |
| 333 | MAP_SHARED | MAP_LOCKED, *fd, 0); |
| 334 | if (ring->ring_start_addr == MAP_FAILED) |
| 335 | { |
| 336 | vlib_log_err (apm->log_class, "mmap failure: %s (errno %d)", |
| 337 | strerror (errno), errno); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 338 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 339 | goto error; |
| 340 | } |
| 341 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 342 | ring->ring_size = ring_sz; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 343 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 344 | return 0; |
| 345 | error: |
Dave Barach | 16ad6ae | 2016-07-28 17:55:30 -0400 | [diff] [blame] | 346 | if (*fd >= 0) |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 347 | { |
| 348 | close (*fd); |
| 349 | *fd = -1; |
| 350 | } |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | int |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 355 | af_packet_queue_init (vlib_main_t *vm, af_packet_if_t *apif, |
| 356 | af_packet_create_if_arg_t *arg, |
| 357 | af_packet_queue_t *rx_queue, af_packet_queue_t *tx_queue, |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 358 | u8 queue_id) |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 359 | { |
| 360 | af_packet_main_t *apm = &af_packet_main; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 361 | tpacket_req_u_t *rx_req = 0; |
| 362 | tpacket_req_u_t *tx_req = 0; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 363 | int ret, fd = -1; |
| 364 | af_packet_ring_t ring = { 0 }; |
| 365 | u8 *ring_addr = 0; |
| 366 | u32 rx_frames_per_block, tx_frames_per_block; |
| 367 | u32 rx_frame_size, tx_frame_size; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 368 | u32 i = 0; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 369 | |
| 370 | if (rx_queue) |
| 371 | { |
| 372 | rx_frames_per_block = arg->rx_frames_per_block ? |
| 373 | arg->rx_frames_per_block : |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 374 | ((apif->version == TPACKET_V3) ? |
| 375 | AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK : |
| 376 | AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK_V2); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 377 | |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 378 | rx_frame_size = |
| 379 | arg->rx_frame_size ? |
| 380 | arg->rx_frame_size : |
| 381 | ((apif->version == TPACKET_V3) ? AF_PACKET_DEFAULT_RX_FRAME_SIZE : |
| 382 | AF_PACKET_DEFAULT_RX_FRAME_SIZE_V2); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 383 | vec_validate (rx_queue->rx_req, 0); |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 384 | rx_queue->rx_req->req.tp_block_size = |
| 385 | rx_frame_size * rx_frames_per_block; |
| 386 | rx_queue->rx_req->req.tp_frame_size = rx_frame_size; |
| 387 | rx_queue->rx_req->req.tp_block_nr = (apif->version == TPACKET_V3) ? |
| 388 | AF_PACKET_RX_BLOCK_NR : |
| 389 | AF_PACKET_RX_BLOCK_NR_V2; |
| 390 | rx_queue->rx_req->req.tp_frame_nr = |
| 391 | rx_queue->rx_req->req.tp_block_nr * rx_frames_per_block; |
| 392 | if (apif->version == TPACKET_V3) |
| 393 | { |
| 394 | rx_queue->rx_req->req3.tp_retire_blk_tov = 1; // 1 ms block timout |
| 395 | rx_queue->rx_req->req3.tp_feature_req_word = 0; |
| 396 | rx_queue->rx_req->req3.tp_sizeof_priv = 0; |
| 397 | } |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 398 | rx_req = rx_queue->rx_req; |
| 399 | } |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 400 | if (tx_queue) |
| 401 | { |
| 402 | tx_frames_per_block = arg->tx_frames_per_block ? |
| 403 | arg->tx_frames_per_block : |
| 404 | AF_PACKET_DEFAULT_TX_FRAMES_PER_BLOCK; |
| 405 | tx_frame_size = arg->tx_frame_size ? arg->tx_frame_size : |
| 406 | AF_PACKET_DEFAULT_TX_FRAME_SIZE; |
| 407 | |
| 408 | vec_validate (tx_queue->tx_req, 0); |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 409 | tx_queue->tx_req->req.tp_block_size = |
| 410 | tx_frame_size * tx_frames_per_block; |
| 411 | tx_queue->tx_req->req.tp_frame_size = tx_frame_size; |
| 412 | tx_queue->tx_req->req.tp_block_nr = AF_PACKET_TX_BLOCK_NR; |
| 413 | tx_queue->tx_req->req.tp_frame_nr = |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 414 | AF_PACKET_TX_BLOCK_NR * tx_frames_per_block; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 415 | if (apif->version == TPACKET_V3) |
| 416 | { |
| 417 | tx_queue->tx_req->req3.tp_retire_blk_tov = 0; |
| 418 | tx_queue->tx_req->req3.tp_sizeof_priv = 0; |
| 419 | tx_queue->tx_req->req3.tp_feature_req_word = 0; |
| 420 | } |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 421 | tx_req = tx_queue->tx_req; |
| 422 | } |
| 423 | |
Mohsin Kazmi | 3ce1d14 | 2022-04-05 10:46:39 +0000 | [diff] [blame] | 424 | if (rx_queue || tx_queue) |
| 425 | { |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 426 | ret = |
| 427 | create_packet_sock (apif->host_if_index, rx_req, tx_req, &fd, &ring, |
| 428 | apif->dev_instance, &arg->flags, apif->version); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 429 | |
Mohsin Kazmi | 3ce1d14 | 2022-04-05 10:46:39 +0000 | [diff] [blame] | 430 | if (ret != 0) |
| 431 | goto error; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 432 | |
Mohsin Kazmi | 3ce1d14 | 2022-04-05 10:46:39 +0000 | [diff] [blame] | 433 | vec_add1 (apif->rings, ring); |
| 434 | ring_addr = ring.ring_start_addr; |
| 435 | } |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 436 | |
| 437 | if (rx_queue) |
| 438 | { |
| 439 | rx_queue->fd = fd; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 440 | vec_validate (rx_queue->rx_ring, rx_queue->rx_req->req.tp_block_nr - 1); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 441 | vec_foreach_index (i, rx_queue->rx_ring) |
| 442 | { |
| 443 | rx_queue->rx_ring[i] = |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 444 | ring_addr + i * rx_queue->rx_req->req.tp_block_size; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | rx_queue->next_rx_block = 0; |
| 448 | rx_queue->queue_id = queue_id; |
| 449 | rx_queue->is_rx_pending = 0; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 450 | ring_addr = ring_addr + rx_queue->rx_req->req.tp_block_size * |
| 451 | rx_queue->rx_req->req.tp_block_nr; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | if (tx_queue) |
| 455 | { |
| 456 | tx_queue->fd = fd; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 457 | vec_validate (tx_queue->tx_ring, tx_queue->tx_req->req.tp_block_nr - 1); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 458 | vec_foreach_index (i, tx_queue->tx_ring) |
| 459 | { |
| 460 | tx_queue->tx_ring[i] = |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 461 | ring_addr + i * tx_queue->tx_req->req.tp_block_size; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | tx_queue->next_tx_frame = 0; |
| 465 | tx_queue->queue_id = queue_id; |
Mohammed Hawari | 8a419d5 | 2022-02-24 15:19:01 +0100 | [diff] [blame] | 466 | tx_queue->is_tx_pending = 0; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 467 | clib_spinlock_init (&tx_queue->lockp); |
| 468 | } |
| 469 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 470 | return 0; |
| 471 | error: |
| 472 | vlib_log_err (apm->log_class, "Failed to set queue %u error", queue_id); |
Mohsin Kazmi | 3ce1d14 | 2022-04-05 10:46:39 +0000 | [diff] [blame] | 473 | if (rx_queue) |
| 474 | vec_free (rx_queue->rx_req); |
| 475 | if (tx_queue) |
| 476 | vec_free (tx_queue->tx_req); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | int |
| 481 | af_packet_device_init (vlib_main_t *vm, af_packet_if_t *apif, |
| 482 | af_packet_create_if_arg_t *args) |
| 483 | { |
| 484 | af_packet_main_t *apm = &af_packet_main; |
| 485 | af_packet_queue_t *rx_queue = 0; |
| 486 | af_packet_queue_t *tx_queue = 0; |
| 487 | u16 nq = clib_min (args->num_rxqs, args->num_txqs); |
| 488 | u16 i = 0; |
| 489 | int ret = 0; |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 490 | |
| 491 | // enable fanout feature for multi-rxqs |
| 492 | if (args->num_rxqs > 1) |
| 493 | args->flags |= AF_PACKET_IF_FLAGS_FANOUT; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 494 | |
| 495 | vec_validate (apif->rx_queues, args->num_rxqs - 1); |
| 496 | vec_validate (apif->tx_queues, args->num_txqs - 1); |
| 497 | |
| 498 | for (; i < nq; i++) |
| 499 | { |
| 500 | rx_queue = vec_elt_at_index (apif->rx_queues, i); |
| 501 | tx_queue = vec_elt_at_index (apif->tx_queues, i); |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 502 | ret = af_packet_queue_init (vm, apif, args, rx_queue, tx_queue, i); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 503 | if (ret != 0) |
| 504 | goto error; |
| 505 | } |
| 506 | |
| 507 | if (args->num_rxqs > args->num_txqs) |
| 508 | { |
| 509 | for (; i < args->num_rxqs; i++) |
| 510 | { |
| 511 | rx_queue = vec_elt_at_index (apif->rx_queues, i); |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 512 | ret = af_packet_queue_init (vm, apif, args, rx_queue, 0, i); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 513 | if (ret != 0) |
| 514 | goto error; |
| 515 | } |
| 516 | } |
| 517 | else if (args->num_txqs > args->num_rxqs) |
| 518 | { |
| 519 | for (; i < args->num_txqs; i++) |
| 520 | { |
| 521 | tx_queue = vec_elt_at_index (apif->tx_queues, i); |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 522 | ret = af_packet_queue_init (vm, apif, args, 0, tx_queue, i); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 523 | if (ret != 0) |
| 524 | goto error; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | apif->num_rxqs = args->num_rxqs; |
| 529 | apif->num_txqs = args->num_txqs; |
| 530 | |
| 531 | return 0; |
| 532 | error: |
| 533 | vlib_log_err (apm->log_class, "Failed to init device error"); |
| 534 | return ret; |
| 535 | } |
| 536 | |
| 537 | int |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 538 | af_packet_create_if (af_packet_create_if_arg_t *arg) |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 539 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 540 | af_packet_main_t *apm = &af_packet_main; |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 541 | vlib_main_t *vm = vlib_get_main (); |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 542 | int fd2 = -1; |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 543 | struct ifreq ifr; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 544 | af_packet_if_t *apif = 0; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 545 | u8 hw_addr[6]; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 546 | vnet_sw_interface_t *sw; |
| 547 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 548 | vnet_hw_if_caps_t caps = VNET_HW_IF_CAP_INT_MODE; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 549 | uword *p; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 550 | uword if_index; |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 551 | u8 *host_if_name_dup = 0; |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 552 | int host_if_index = -1; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 553 | int ret = 0; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 554 | |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 555 | p = mhash_get (&apm->if_index_by_host_if_name, arg->host_if_name); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 556 | if (p) |
| 557 | { |
Mohsin Kazmi | 43fc688 | 2018-03-22 23:45:23 +0100 | [diff] [blame] | 558 | apif = vec_elt_at_index (apm->interfaces, p[0]); |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 559 | arg->sw_if_index = apif->sw_if_index; |
Mohsin Kazmi | 43fc688 | 2018-03-22 23:45:23 +0100 | [diff] [blame] | 560 | return VNET_API_ERROR_IF_ALREADY_EXISTS; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 561 | } |
| 562 | |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 563 | host_if_name_dup = vec_dup (arg->host_if_name); |
| 564 | |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 565 | /* |
| 566 | * make sure host side of interface is 'UP' before binding AF_PACKET |
| 567 | * socket on it. |
| 568 | */ |
| 569 | if ((fd2 = socket (AF_UNIX, SOCK_DGRAM, 0)) < 0) |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 570 | { |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 571 | vlib_log_debug (apm->log_class, |
| 572 | "Failed to create AF_UNIX socket: %s (errno %d)", |
| 573 | strerror (errno), errno); |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 574 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 575 | goto error; |
| 576 | } |
| 577 | |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 578 | clib_memcpy (ifr.ifr_name, (const char *) arg->host_if_name, |
| 579 | vec_len (arg->host_if_name)); |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 580 | if (ioctl (fd2, SIOCGIFINDEX, &ifr) < 0) |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 581 | { |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 582 | vlib_log_debug ( |
| 583 | apm->log_class, |
| 584 | "Failed to retrieve the interface (%s) index: %s (errno %d)", |
| 585 | arg->host_if_name, strerror (errno), errno); |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 586 | ret = VNET_API_ERROR_INVALID_INTERFACE; |
| 587 | goto error; |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 588 | } |
| 589 | |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 590 | host_if_index = ifr.ifr_ifindex; |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 591 | if (ioctl (fd2, SIOCGIFFLAGS, &ifr) < 0) |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 592 | { |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 593 | vlib_log_debug (apm->log_class, |
| 594 | "Failed to get the active flag: %s (errno %d)", |
| 595 | strerror (errno), errno); |
| 596 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 597 | goto error; |
| 598 | } |
| 599 | |
| 600 | if (!(ifr.ifr_flags & IFF_UP)) |
| 601 | { |
| 602 | ifr.ifr_flags |= IFF_UP; |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 603 | if (ioctl (fd2, SIOCSIFFLAGS, &ifr) < 0) |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 604 | { |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 605 | vlib_log_debug (apm->log_class, |
| 606 | "Failed to set the active flag: %s (errno %d)", |
| 607 | strerror (errno), errno); |
| 608 | ret = VNET_API_ERROR_SYSCALL_ERROR_1; |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 609 | goto error; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | if (fd2 > -1) |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 614 | { |
| 615 | close (fd2); |
| 616 | fd2 = -1; |
| 617 | } |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 618 | |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 619 | ret = is_bridge (arg->host_if_name); |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 620 | if (ret == 0) /* is a bridge, ignore state */ |
| 621 | host_if_index = -1; |
| 622 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 623 | /* So far everything looks good, let's create interface */ |
Damjan Marion | 048ee2e | 2016-03-16 22:59:21 +0100 | [diff] [blame] | 624 | pool_get (apm->interfaces, apif); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 625 | if_index = apif - apm->interfaces; |
| 626 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 627 | apif->dev_instance = if_index; |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 628 | apif->host_if_index = host_if_index; |
Ivan Kelly | bfe737a | 2016-10-07 18:02:43 +0200 | [diff] [blame] | 629 | apif->host_if_name = host_if_name_dup; |
Dave Barach | 13f3c45 | 2016-03-29 11:56:41 -0400 | [diff] [blame] | 630 | apif->per_interface_next_index = ~0; |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 631 | apif->mode = arg->mode; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 632 | |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 633 | if (arg->is_v2) |
| 634 | apif->version = TPACKET_V2; |
| 635 | else |
| 636 | apif->version = TPACKET_V3; |
| 637 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 638 | ret = af_packet_device_init (vm, apif, arg); |
| 639 | if (ret != 0) |
| 640 | goto error; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 641 | |
Nathan Skrzypczak | ffc6bdc | 2021-02-01 17:13:59 +0100 | [diff] [blame] | 642 | ret = af_packet_read_mtu (apif); |
| 643 | if (ret != 0) |
| 644 | goto error; |
| 645 | |
Mohsin KAZMI | cf751ec | 2017-01-18 11:59:45 +0100 | [diff] [blame] | 646 | |
Nathan Skrzypczak | b225b0a | 2021-10-26 16:11:38 +0200 | [diff] [blame] | 647 | if (apif->mode != AF_PACKET_IF_MODE_IP) |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 648 | { |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 649 | vnet_eth_interface_registration_t eir = {}; |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 650 | /*use configured or generate random MAC address */ |
| 651 | if (arg->hw_addr) |
| 652 | clib_memcpy (hw_addr, arg->hw_addr, 6); |
| 653 | else |
| 654 | { |
| 655 | f64 now = vlib_time_now (vm); |
| 656 | u32 rnd; |
| 657 | rnd = (u32) (now * 1e6); |
| 658 | rnd = random_u32 (&rnd); |
| 659 | |
| 660 | clib_memcpy (hw_addr + 2, &rnd, sizeof (rnd)); |
| 661 | hw_addr[0] = 2; |
| 662 | hw_addr[1] = 0xfe; |
| 663 | } |
| 664 | |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 665 | eir.dev_class_index = af_packet_device_class.index; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 666 | eir.dev_instance = apif->dev_instance; |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 667 | eir.address = hw_addr; |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame] | 668 | eir.cb.set_max_frame_size = af_packet_eth_set_max_frame_size; |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 669 | apif->hw_if_index = vnet_eth_register_interface (vnm, &eir); |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 670 | } |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 671 | else |
| 672 | { |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 673 | apif->hw_if_index = vnet_register_interface ( |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 674 | vnm, af_packet_device_class.index, apif->dev_instance, |
| 675 | af_packet_ip_device_hw_interface_class.index, apif->dev_instance); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 676 | } |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 677 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 678 | sw = vnet_get_hw_sw_interface (vnm, apif->hw_if_index); |
| 679 | apif->sw_if_index = sw->sw_if_index; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 680 | |
| 681 | af_packet_set_rx_queues (vm, apif); |
| 682 | af_packet_set_tx_queues (vm, apif); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 683 | |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 684 | if (arg->flags & AF_PACKET_IF_FLAGS_FANOUT) |
| 685 | apif->is_fanout_enabled = 1; |
| 686 | |
Mohsin Kazmi | 2b6479c | 2022-04-05 12:03:47 +0000 | [diff] [blame] | 687 | apif->is_qdisc_bypass_enabled = |
| 688 | (arg->flags & AF_PACKET_IF_FLAGS_QDISC_BYPASS); |
| 689 | |
Mohsin Kazmi | 788676b | 2022-04-05 12:43:13 +0000 | [diff] [blame] | 690 | if (arg->flags & AF_PACKET_IF_FLAGS_CKSUM_GSO) |
| 691 | apif->is_cksum_gso_enabled = 1; |
| 692 | |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 693 | if (apif->is_cksum_gso_enabled) |
| 694 | caps |= VNET_HW_IF_CAP_TCP_GSO | VNET_HW_IF_CAP_TX_IP4_CKSUM | |
| 695 | VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM; |
| 696 | |
| 697 | vnet_hw_if_set_caps (vnm, apif->hw_if_index, caps); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 698 | vnet_hw_interface_set_flags (vnm, apif->hw_if_index, |
| 699 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 700 | |
Ivan Kelly | bfe737a | 2016-10-07 18:02:43 +0200 | [diff] [blame] | 701 | mhash_set_mem (&apm->if_index_by_host_if_name, host_if_name_dup, &if_index, |
| 702 | 0); |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 703 | arg->sw_if_index = apif->sw_if_index; |
Mohsin KAZMI | cf751ec | 2017-01-18 11:59:45 +0100 | [diff] [blame] | 704 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 705 | return 0; |
| 706 | |
| 707 | error: |
Mohsin Kazmi | a50a14c | 2018-04-25 15:58:05 +0200 | [diff] [blame] | 708 | if (fd2 > -1) |
jackiechen1985 | 7fa4160 | 2019-05-07 18:59:13 +0800 | [diff] [blame] | 709 | { |
| 710 | close (fd2); |
| 711 | fd2 = -1; |
| 712 | } |
Ivan Kelly | bfe737a | 2016-10-07 18:02:43 +0200 | [diff] [blame] | 713 | vec_free (host_if_name_dup); |
Gabriel Ganne | 01f6c73 | 2022-05-05 10:16:56 +0200 | [diff] [blame] | 714 | if (apif) |
| 715 | { |
| 716 | memset (apif, 0, sizeof (*apif)); |
| 717 | pool_put (apm->interfaces, apif); |
| 718 | } |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 719 | return ret; |
| 720 | } |
| 721 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 722 | static int |
| 723 | af_packet_rx_queue_free (af_packet_if_t *apif, af_packet_queue_t *rx_queue) |
| 724 | { |
| 725 | clib_file_del_by_index (&file_main, rx_queue->clib_file_index); |
| 726 | close (rx_queue->fd); |
| 727 | rx_queue->fd = -1; |
| 728 | rx_queue->rx_ring = NULL; |
| 729 | vec_free (rx_queue->rx_req); |
| 730 | rx_queue->rx_req = NULL; |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | static int |
| 735 | af_packet_tx_queue_free (af_packet_if_t *apif, af_packet_queue_t *tx_queue) |
| 736 | { |
| 737 | close (tx_queue->fd); |
| 738 | tx_queue->fd = -1; |
| 739 | clib_spinlock_free (&tx_queue->lockp); |
| 740 | tx_queue->tx_ring = NULL; |
| 741 | vec_free (tx_queue->tx_req); |
| 742 | tx_queue->tx_req = NULL; |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | static int |
| 747 | af_packet_ring_free (af_packet_if_t *apif, af_packet_ring_t *ring) |
| 748 | { |
| 749 | af_packet_main_t *apm = &af_packet_main; |
| 750 | |
| 751 | if (ring) |
| 752 | { |
| 753 | // FIXME: unmap the memory |
| 754 | if (munmap (ring->ring_start_addr, ring->ring_size)) |
| 755 | vlib_log_warn (apm->log_class, |
| 756 | "Host interface %s could not free ring %p of size %u", |
| 757 | apif->host_if_name, ring->ring_start_addr, |
| 758 | ring->ring_size); |
| 759 | else |
| 760 | ring->ring_start_addr = 0; |
| 761 | } |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 766 | int |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 767 | af_packet_delete_if (u8 *host_if_name) |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 768 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 769 | vnet_main_t *vnm = vnet_get_main (); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 770 | af_packet_main_t *apm = &af_packet_main; |
| 771 | af_packet_if_t *apif; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 772 | af_packet_queue_t *rx_queue; |
| 773 | af_packet_queue_t *tx_queue; |
| 774 | af_packet_ring_t *ring; |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 775 | uword *p; |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 776 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 777 | p = mhash_get (&apm->if_index_by_host_if_name, host_if_name); |
| 778 | if (p == NULL) |
| 779 | { |
Mohsin Kazmi | acba9f7 | 2018-05-17 15:42:27 +0200 | [diff] [blame] | 780 | vlib_log_warn (apm->log_class, "Host interface %s does not exist", |
| 781 | host_if_name); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 782 | return VNET_API_ERROR_SYSCALL_ERROR_1; |
| 783 | } |
| 784 | apif = pool_elt_at_index (apm->interfaces, p[0]); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 785 | |
| 786 | /* bring down the interface */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 787 | vnet_hw_interface_set_flags (vnm, apif->hw_if_index, 0); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 788 | |
| 789 | /* clean up */ |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 790 | vec_foreach (rx_queue, apif->rx_queues) |
| 791 | af_packet_rx_queue_free (apif, rx_queue); |
| 792 | vec_foreach (tx_queue, apif->tx_queues) |
| 793 | af_packet_tx_queue_free (apif, tx_queue); |
| 794 | vec_foreach (ring, apif->rings) |
| 795 | af_packet_ring_free (apif, ring); |
Eyal Bari | f298ecf | 2016-09-19 18:47:39 +0300 | [diff] [blame] | 796 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 797 | vec_free (apif->rx_queues); |
| 798 | apif->rx_queues = NULL; |
| 799 | vec_free (apif->tx_queues); |
| 800 | apif->tx_queues = NULL; |
| 801 | vec_free (apif->rings); |
| 802 | apif->rings = NULL; |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 803 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 804 | vec_free (apif->host_if_name); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 805 | apif->host_if_name = NULL; |
Ray Kinsella | c855b73 | 2017-04-21 12:24:43 +0100 | [diff] [blame] | 806 | apif->host_if_index = -1; |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 807 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 808 | mhash_unset (&apm->if_index_by_host_if_name, host_if_name, p); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 809 | |
Nathan Skrzypczak | b225b0a | 2021-10-26 16:11:38 +0200 | [diff] [blame] | 810 | if (apif->mode != AF_PACKET_IF_MODE_IP) |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 811 | ethernet_delete_interface (vnm, apif->hw_if_index); |
| 812 | else |
| 813 | vnet_delete_hw_interface (vnm, apif->hw_if_index); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 814 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 815 | memset (apif, 0, sizeof (*apif)); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 816 | pool_put (apm->interfaces, apif); |
Peter Lei | dba76f2 | 2016-04-08 08:16:31 -0700 | [diff] [blame] | 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
Jakub Grajciar | 92b0275 | 2017-10-20 13:37:28 +0200 | [diff] [blame] | 821 | int |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 822 | af_packet_set_l4_cksum_offload (u32 sw_if_index, u8 set) |
Jakub Grajciar | 92b0275 | 2017-10-20 13:37:28 +0200 | [diff] [blame] | 823 | { |
Mohsin Kazmi | c1fd17b | 2022-03-22 21:40:04 +0000 | [diff] [blame] | 824 | // deprecated ... |
Jakub Grajciar | 92b0275 | 2017-10-20 13:37:28 +0200 | [diff] [blame] | 825 | return 0; |
| 826 | } |
| 827 | |
Mohsin Kazmi | 04e0bb2 | 2018-05-28 18:55:37 +0200 | [diff] [blame] | 828 | int |
| 829 | af_packet_dump_ifs (af_packet_if_detail_t ** out_af_packet_ifs) |
| 830 | { |
| 831 | af_packet_main_t *apm = &af_packet_main; |
| 832 | af_packet_if_t *apif; |
| 833 | af_packet_if_detail_t *r_af_packet_ifs = NULL; |
| 834 | af_packet_if_detail_t *af_packet_if = NULL; |
| 835 | |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 836 | pool_foreach (apif, apm->interfaces) |
| 837 | { |
Jakub Grajciar | 3b2db90 | 2019-08-26 11:25:52 +0200 | [diff] [blame] | 838 | vec_add2 (r_af_packet_ifs, af_packet_if, 1); |
| 839 | af_packet_if->sw_if_index = apif->sw_if_index; |
| 840 | if (apif->host_if_name) |
| 841 | { |
| 842 | clib_memcpy (af_packet_if->host_if_name, apif->host_if_name, |
| 843 | MIN (ARRAY_LEN (af_packet_if->host_if_name) - 1, |
| 844 | strlen ((const char *) apif->host_if_name))); |
| 845 | } |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 846 | } |
Mohsin Kazmi | 04e0bb2 | 2018-05-28 18:55:37 +0200 | [diff] [blame] | 847 | |
| 848 | *out_af_packet_ifs = r_af_packet_ifs; |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 853 | static clib_error_t * |
| 854 | af_packet_init (vlib_main_t * vm) |
| 855 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 856 | af_packet_main_t *apm = &af_packet_main; |
Damjan Marion | 553f6bd | 2016-09-07 11:54:22 +0200 | [diff] [blame] | 857 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 858 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 859 | clib_memset (apm, 0, sizeof (af_packet_main_t)); |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 860 | |
| 861 | mhash_init_vec_string (&apm->if_index_by_host_if_name, sizeof (uword)); |
| 862 | |
Damjan Marion | 553f6bd | 2016-09-07 11:54:22 +0200 | [diff] [blame] | 863 | vec_validate_aligned (apm->rx_buffers, tm->n_vlib_mains - 1, |
| 864 | CLIB_CACHE_LINE_BYTES); |
| 865 | |
Mohsin Kazmi | acba9f7 | 2018-05-17 15:42:27 +0200 | [diff] [blame] | 866 | apm->log_class = vlib_log_register_class ("af_packet", 0); |
| 867 | vlib_log_debug (apm->log_class, "initialized"); |
| 868 | |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | VLIB_INIT_FUNCTION (af_packet_init); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 873 | |
| 874 | /* |
| 875 | * fd.io coding-style-patch-verification: ON |
| 876 | * |
| 877 | * Local Variables: |
| 878 | * eval: (c-set-style "gnu") |
| 879 | * End: |
| 880 | */ |