Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * af_packet.h - linux kernel packet interface header file |
| 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 | |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 20 | #include <linux/if_packet.h> |
| 21 | |
Damjan Marion | 1927da2 | 2017-03-27 17:08:20 +0200 | [diff] [blame] | 22 | #include <vppinfra/lock.h> |
Mohsin Kazmi | acba9f7 | 2018-05-17 15:42:27 +0200 | [diff] [blame] | 23 | #include <vlib/log.h> |
| 24 | |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 25 | typedef struct tpacket_block_desc block_desc_t; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 26 | typedef struct tpacket_req tpacket_req_t; |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 27 | typedef struct tpacket_req3 tpacket_req3_t; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 28 | typedef struct tpacket2_hdr tpacket2_hdr_t; |
Mohsin Kazmi | 219cbcb | 2022-03-18 16:58:31 +0000 | [diff] [blame] | 29 | typedef struct tpacket3_hdr tpacket3_hdr_t; |
| 30 | |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 31 | typedef union _tpacket_req_u |
| 32 | { |
| 33 | tpacket_req_t req; |
| 34 | tpacket_req3_t req3; |
| 35 | } tpacket_req_u_t; |
| 36 | |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 37 | typedef enum |
| 38 | { |
| 39 | AF_PACKET_IF_MODE_ETHERNET = 1, |
| 40 | AF_PACKET_IF_MODE_IP = 2 |
| 41 | } af_packet_if_mode_t; |
| 42 | |
Mohsin Kazmi | 2b6479c | 2022-04-05 12:03:47 +0000 | [diff] [blame] | 43 | typedef enum |
| 44 | { |
| 45 | AF_PACKET_IF_FLAGS_QDISC_BYPASS = 1, |
Mohsin Kazmi | 788676b | 2022-04-05 12:43:13 +0000 | [diff] [blame] | 46 | AF_PACKET_IF_FLAGS_CKSUM_GSO = 2, |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 47 | AF_PACKET_IF_FLAGS_FANOUT = 4, |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 48 | AF_PACKET_IF_FLAGS_VERSION_2 = 8, |
Mohsin Kazmi | 2b6479c | 2022-04-05 12:03:47 +0000 | [diff] [blame] | 49 | } af_packet_if_flags_t; |
| 50 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 51 | typedef struct |
| 52 | { |
Mohsin Kazmi | 04e0bb2 | 2018-05-28 18:55:37 +0200 | [diff] [blame] | 53 | u32 sw_if_index; |
| 54 | u8 host_if_name[64]; |
| 55 | } af_packet_if_detail_t; |
| 56 | |
| 57 | typedef struct |
| 58 | { |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 59 | u8 *ring_start_addr; |
| 60 | u32 ring_size; |
| 61 | } af_packet_ring_t; |
Mohsin Kazmi | 89d74bd | 2022-03-25 00:33:27 +0000 | [diff] [blame] | 62 | |
| 63 | typedef struct |
| 64 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 65 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Damjan Marion | 1927da2 | 2017-03-27 17:08:20 +0200 | [diff] [blame] | 66 | clib_spinlock_t lockp; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 67 | int fd; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 68 | union |
| 69 | { |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 70 | tpacket_req_u_t *rx_req; |
| 71 | tpacket_req_u_t *tx_req; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | union |
| 75 | { |
| 76 | u8 **rx_ring; |
| 77 | u8 **tx_ring; |
| 78 | }; |
| 79 | |
| 80 | union |
| 81 | { |
| 82 | u32 next_rx_block; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 83 | u32 next_rx_frame; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 84 | u32 next_tx_frame; |
| 85 | }; |
| 86 | |
| 87 | u16 queue_id; |
| 88 | u32 queue_index; |
| 89 | |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 90 | u32 clib_file_index; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 91 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 92 | u32 rx_frame_offset; |
| 93 | u16 num_rx_pkts; |
| 94 | u8 is_rx_pending; |
Mohammed Hawari | 8a419d5 | 2022-02-24 15:19:01 +0100 | [diff] [blame] | 95 | u8 is_tx_pending; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 96 | vnet_hw_if_rx_mode mode; |
| 97 | } af_packet_queue_t; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 98 | |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 99 | typedef struct |
| 100 | { |
| 101 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 102 | u32 hw_if_index; |
| 103 | u32 sw_if_index; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 104 | u32 per_interface_next_index; |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 105 | af_packet_if_mode_t mode; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 106 | u8 is_admin_up; |
| 107 | u8 is_cksum_gso_enabled; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 108 | u8 version; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 109 | af_packet_queue_t *rx_queues; |
| 110 | af_packet_queue_t *tx_queues; |
| 111 | |
| 112 | u8 num_rxqs; |
| 113 | u8 num_txqs; |
| 114 | |
| 115 | u8 *host_if_name; |
| 116 | int host_if_index; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 117 | |
| 118 | u32 host_mtu; |
| 119 | u32 dev_instance; |
| 120 | |
| 121 | af_packet_ring_t *rings; |
Mohsin Kazmi | 2b6479c | 2022-04-05 12:03:47 +0000 | [diff] [blame] | 122 | u8 is_qdisc_bypass_enabled; |
Mohsin Kazmi | c73984a | 2022-04-05 13:08:53 +0000 | [diff] [blame] | 123 | u8 is_fanout_enabled; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 124 | } af_packet_if_t; |
| 125 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 126 | typedef struct |
| 127 | { |
| 128 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 129 | af_packet_if_t *interfaces; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 130 | |
Mohsin Kazmi | 89733a1 | 2022-08-30 13:29:06 +0000 | [diff] [blame] | 131 | u32 polling_count; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 132 | /* rx buffer cache */ |
Damjan Marion | 553f6bd | 2016-09-07 11:54:22 +0200 | [diff] [blame] | 133 | u32 **rx_buffers; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 134 | |
| 135 | /* hash of host interface names */ |
| 136 | mhash_t if_index_by_host_if_name; |
Mohsin Kazmi | acba9f7 | 2018-05-17 15:42:27 +0200 | [diff] [blame] | 137 | |
| 138 | /** log class */ |
| 139 | vlib_log_class_t log_class; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 140 | } af_packet_main_t; |
| 141 | |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 142 | typedef struct |
| 143 | { |
| 144 | u8 *host_if_name; |
| 145 | u8 *hw_addr; |
| 146 | u32 rx_frame_size; |
| 147 | u32 tx_frame_size; |
| 148 | u32 rx_frames_per_block; |
| 149 | u32 tx_frames_per_block; |
Mohsin Kazmi | 5a7aa51 | 2022-03-25 14:27:45 +0000 | [diff] [blame] | 150 | u8 num_rxqs; |
| 151 | u8 num_txqs; |
Mohsin Kazmi | 8b90d89 | 2022-09-08 17:21:20 +0000 | [diff] [blame] | 152 | u8 is_v2; |
Mohsin Kazmi | cae84fa | 2021-10-08 15:10:49 +0000 | [diff] [blame] | 153 | af_packet_if_mode_t mode; |
Mohsin Kazmi | 2b6479c | 2022-04-05 12:03:47 +0000 | [diff] [blame] | 154 | af_packet_if_flags_t flags; |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 155 | |
| 156 | /* return */ |
| 157 | u32 sw_if_index; |
| 158 | } af_packet_create_if_arg_t; |
| 159 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 160 | extern af_packet_main_t af_packet_main; |
Damjan Marion | 83243a0 | 2016-02-29 13:09:30 +0100 | [diff] [blame] | 161 | extern vnet_device_class_t af_packet_device_class; |
| 162 | extern vlib_node_registration_t af_packet_input_node; |
| 163 | |
Nathan Skrzypczak | 7d0e30b | 2021-06-23 11:28:39 +0200 | [diff] [blame] | 164 | int af_packet_create_if (af_packet_create_if_arg_t *arg); |
| 165 | int af_packet_delete_if (u8 *host_if_name); |
| 166 | int af_packet_set_l4_cksum_offload (u32 sw_if_index, u8 set); |
Mohsin Kazmi | 04e0bb2 | 2018-05-28 18:55:37 +0200 | [diff] [blame] | 167 | int af_packet_dump_ifs (af_packet_if_detail_t ** out_af_packet_ifs); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 168 | |
Damjan Marion | ceab788 | 2018-01-19 20:56:12 +0100 | [diff] [blame] | 169 | format_function_t format_af_packet_device_name; |
| 170 | |
Mohsin Kazmi | 04e0bb2 | 2018-05-28 18:55:37 +0200 | [diff] [blame] | 171 | #define MIN(x,y) (((x)<(y))?(x):(y)) |
| 172 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 173 | /* |
| 174 | * fd.io coding-style-patch-verification: ON |
| 175 | * |
| 176 | * Local Variables: |
| 177 | * eval: (c-set-style "gnu") |
| 178 | * End: |
| 179 | */ |