Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef included_vnet_flow_flow_h |
| 17 | #define included_vnet_flow_flow_h |
| 18 | |
| 19 | #include <vppinfra/clib.h> |
Dave Barach | 3ae2873 | 2018-11-16 17:19:00 -0500 | [diff] [blame] | 20 | #include <vppinfra/pcap.h> |
Neale Ranns | f7040f0 | 2022-02-15 09:02:27 +0000 | [diff] [blame] | 21 | #include <vnet/vnet.h> |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 22 | #include <vnet/l3_types.h> |
| 23 | #include <vnet/ip/ip4_packet.h> |
| 24 | #include <vnet/ip/ip6_packet.h> |
Chenmin Sun | 4ff8d61 | 2019-12-15 01:16:45 +0800 | [diff] [blame] | 25 | #include <vnet/ethernet/packet.h> |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 26 | |
Ting Xu | 3a36682 | 2021-09-16 08:37:25 +0000 | [diff] [blame] | 27 | #define foreach_flow_type \ |
| 28 | /* l2 flow*/ \ |
| 29 | _ (ETHERNET, ethernet, "ethernet") \ |
| 30 | /* l3 IP flow */ \ |
| 31 | _ (IP4, ip4, "ipv4") \ |
| 32 | _ (IP6, ip6, "ipv6") \ |
| 33 | /* IP tunnel flow */ \ |
| 34 | _ (IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \ |
| 35 | _ (IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \ |
| 36 | _ (IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \ |
| 37 | /* l4 flow*/ \ |
| 38 | _ (IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \ |
| 39 | _ (IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \ |
| 40 | _ (IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \ |
| 41 | _ (IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \ |
| 42 | /* L4 tunnel flow*/ \ |
| 43 | _ (IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \ |
| 44 | _ (IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \ |
| 45 | _ (IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \ |
| 46 | _ (IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \ |
| 47 | /* generic flow */ \ |
| 48 | _ (GENERIC, generic, "generic") |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 49 | |
Chenmin Sun | 4ff8d61 | 2019-12-15 01:16:45 +0800 | [diff] [blame] | 50 | #define foreach_flow_entry_ethernet \ |
| 51 | _fe(ethernet_header_t, eth_hdr) |
| 52 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 53 | #define foreach_flow_entry_ip4 \ |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 54 | _fe(ip4_address_and_mask_t, src_addr) \ |
| 55 | _fe(ip4_address_and_mask_t, dst_addr) \ |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 56 | _fe(ip_prot_and_mask_t, protocol) |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 57 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 58 | #define foreach_flow_entry_ip6 \ |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 59 | _fe(ip6_address_and_mask_t, src_addr) \ |
| 60 | _fe(ip6_address_and_mask_t, dst_addr) \ |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 61 | _fe(ip_prot_and_mask_t, protocol) |
Chenmin Sun | f13830c | 2020-02-26 19:22:35 +0800 | [diff] [blame] | 62 | |
Chenmin Sun | 8b43aaa | 2020-04-15 01:55:58 +0800 | [diff] [blame] | 63 | #define foreach_flow_entry_ip4_l2tpv3oip \ |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 64 | foreach_flow_entry_ip4 \ |
Chenmin Sun | 8b43aaa | 2020-04-15 01:55:58 +0800 | [diff] [blame] | 65 | _fe(u32, session_id) |
Chenmin Sun | f13830c | 2020-02-26 19:22:35 +0800 | [diff] [blame] | 66 | |
Chenmin Sun | d4c3666 | 2020-06-22 18:21:31 +0800 | [diff] [blame] | 67 | #define foreach_flow_entry_ip4_ipsec_esp \ |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 68 | foreach_flow_entry_ip4 \ |
Chenmin Sun | d4c3666 | 2020-06-22 18:21:31 +0800 | [diff] [blame] | 69 | _fe(u32, spi) |
| 70 | |
| 71 | #define foreach_flow_entry_ip4_ipsec_ah \ |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 72 | foreach_flow_entry_ip4 \ |
Chenmin Sun | d4c3666 | 2020-06-22 18:21:31 +0800 | [diff] [blame] | 73 | _fe(u32, spi) |
| 74 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 75 | #define foreach_flow_entry_ip4_n_tuple \ |
| 76 | foreach_flow_entry_ip4 \ |
| 77 | _fe(ip_port_and_mask_t, src_port) \ |
| 78 | _fe(ip_port_and_mask_t, dst_port) |
| 79 | |
| 80 | #define foreach_flow_entry_ip6_n_tuple \ |
| 81 | foreach_flow_entry_ip6 \ |
| 82 | _fe(ip_port_and_mask_t, src_port) \ |
| 83 | _fe(ip_port_and_mask_t, dst_port) |
| 84 | |
| 85 | #define foreach_flow_entry_ip4_n_tuple_tagged \ |
| 86 | foreach_flow_entry_ip4 \ |
| 87 | _fe(ip_port_and_mask_t, src_port) \ |
| 88 | _fe(ip_port_and_mask_t, dst_port) |
| 89 | |
| 90 | #define foreach_flow_entry_ip6_n_tuple_tagged \ |
| 91 | foreach_flow_entry_ip6 \ |
| 92 | _fe(ip_port_and_mask_t, src_port) \ |
| 93 | _fe(ip_port_and_mask_t, dst_port) |
| 94 | |
Chenmin Sun | 91f102e | 2020-12-08 00:42:43 +0800 | [diff] [blame] | 95 | #define foreach_flow_entry_ip4_vxlan \ |
| 96 | foreach_flow_entry_ip4_n_tuple _fe (u32, vni) |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 97 | |
Chenmin Sun | 91f102e | 2020-12-08 00:42:43 +0800 | [diff] [blame] | 98 | #define foreach_flow_entry_ip6_vxlan \ |
| 99 | foreach_flow_entry_ip6_n_tuple _fe (u32, vni) |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 100 | |
Chenmin Sun | bf85a98 | 2019-10-18 07:35:16 +0800 | [diff] [blame] | 101 | #define foreach_flow_entry_ip4_gtpc \ |
| 102 | foreach_flow_entry_ip4_n_tuple \ |
| 103 | _fe(u32, teid) |
| 104 | |
| 105 | #define foreach_flow_entry_ip4_gtpu \ |
| 106 | foreach_flow_entry_ip4_n_tuple \ |
| 107 | _fe(u32, teid) |
| 108 | |
Ting Xu | 3a36682 | 2021-09-16 08:37:25 +0000 | [diff] [blame] | 109 | #define foreach_flow_entry_generic _fe (generic_pattern_t, pattern) |
| 110 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 111 | #define foreach_flow_action \ |
| 112 | _(0, COUNT, "count") \ |
| 113 | _(1, MARK, "mark") \ |
| 114 | _(2, BUFFER_ADVANCE, "buffer-advance") \ |
| 115 | _(3, REDIRECT_TO_NODE, "redirect-to-node") \ |
| 116 | _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \ |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 117 | _(5, RSS, "rss") \ |
| 118 | _(6, DROP, "drop") |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 119 | |
| 120 | typedef enum |
| 121 | { |
| 122 | #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v), |
| 123 | foreach_flow_action |
| 124 | #undef _ |
| 125 | } vnet_flow_action_t; |
| 126 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 127 | #define foreach_flow_error \ |
| 128 | _( -1, NOT_SUPPORTED, "not supported") \ |
| 129 | _( -2, ALREADY_DONE, "already done") \ |
| 130 | _( -3, ALREADY_EXISTS, "already exists") \ |
| 131 | _( -4, NO_SUCH_ENTRY, "no such entry") \ |
| 132 | _( -5, NO_SUCH_INTERFACE, "no such interface") \ |
| 133 | _( -6, INTERNAL, "internal error") |
| 134 | |
Piotr Bronowski | da6520b | 2021-07-02 09:20:03 +0000 | [diff] [blame] | 135 | #define foreach_flow_rss_types \ |
| 136 | _ (0, FRAG_IPV4, "ipv4-frag") \ |
| 137 | _ (1, IPV4_TCP, "ipv4-tcp") \ |
| 138 | _ (2, IPV4_UDP, "ipv4-udp") \ |
| 139 | _ (3, IPV4_SCTP, "ipv4-sctp") \ |
| 140 | _ (4, IPV4_OTHER, "ipv4-other") \ |
| 141 | _ (5, IPV4, "ipv4") \ |
| 142 | _ (6, IPV6_TCP_EX, "ipv6-tcp-ex") \ |
| 143 | _ (7, IPV6_UDP_EX, "ipv6-udp-ex") \ |
| 144 | _ (8, FRAG_IPV6, "ipv6-frag") \ |
| 145 | _ (9, IPV6_TCP, "ipv6-tcp") \ |
| 146 | _ (10, IPV6_UDP, "ipv6-udp") \ |
| 147 | _ (11, IPV6_SCTP, "ipv6-sctp") \ |
| 148 | _ (12, IPV6_OTHER, "ipv6-other") \ |
| 149 | _ (13, IPV6_EX, "ipv6-ex") \ |
| 150 | _ (14, IPV6, "ipv6") \ |
| 151 | _ (15, L2_PAYLOAD, "l2-payload") \ |
| 152 | _ (16, PORT, "port") \ |
| 153 | _ (17, VXLAN, "vxlan") \ |
| 154 | _ (18, GENEVE, "geneve") \ |
| 155 | _ (19, NVGRE, "nvgre") \ |
| 156 | _ (20, GTPU, "gtpu") \ |
| 157 | _ (21, ESP, "esp") \ |
| 158 | _ (60, L4_DST_ONLY, "l4-dst-only") \ |
| 159 | _ (61, L4_SRC_ONLY, "l4-src-only") \ |
| 160 | _ (62, L3_DST_ONLY, "l3-dst-only") \ |
| 161 | _ (63, L3_SRC_ONLY, "l3-src-only") |
| 162 | |
| 163 | typedef enum |
| 164 | { |
| 165 | #define _(v, n, s) VNET_FLOW_RSS_TYPES_##n = v, |
| 166 | foreach_flow_rss_types |
| 167 | #undef _ |
| 168 | } vnet_flow_rss_types_t; |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 169 | |
| 170 | #define foreach_rss_function \ |
| 171 | _(DEFAULT, "default") \ |
| 172 | _(TOEPLITZ, "toeplitz") \ |
| 173 | _(SIMPLE_XOR, "simple_xor") \ |
| 174 | _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz") |
| 175 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 176 | typedef enum |
| 177 | { |
| 178 | VNET_FLOW_NO_ERROR = 0, |
| 179 | #define _(v,n,s) VNET_FLOW_ERROR_##n = v, |
| 180 | foreach_flow_error |
| 181 | #undef _ |
| 182 | } vnet_flow_error_t; |
| 183 | |
| 184 | typedef struct |
| 185 | { |
| 186 | u16 port, mask; |
| 187 | } ip_port_and_mask_t; |
| 188 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 189 | typedef struct |
| 190 | { |
| 191 | ip_protocol_t prot; |
| 192 | /* ip protocol mask should be either 0 or 0xFF */ |
| 193 | /* other values are meanless */ |
| 194 | u8 mask; |
| 195 | } ip_prot_and_mask_t; |
| 196 | |
Ting Xu | 3a36682 | 2021-09-16 08:37:25 +0000 | [diff] [blame] | 197 | typedef struct |
| 198 | { |
| 199 | u8 spec[1024]; |
| 200 | u8 mask[1024]; |
| 201 | } generic_pattern_t; |
| 202 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 203 | typedef enum |
| 204 | { |
| 205 | VNET_FLOW_TYPE_UNKNOWN, |
| 206 | #define _(a,b,c) VNET_FLOW_TYPE_##a, |
| 207 | foreach_flow_type |
| 208 | #undef _ |
| 209 | VNET_FLOW_N_TYPES, |
| 210 | } vnet_flow_type_t; |
| 211 | |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 212 | typedef enum |
| 213 | { |
| 214 | #define _(a,b) VNET_RSS_FUNC_##a, |
| 215 | foreach_rss_function |
| 216 | #undef _ |
| 217 | VNET_RSS_N_TYPES, |
| 218 | } vnet_rss_function_t; |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * Create typedef struct vnet_flow_XXX_t |
| 222 | */ |
| 223 | #define _fe(a, b) a b; |
| 224 | #define _(a,b,c) \ |
| 225 | typedef struct { \ |
| 226 | int foo; \ |
| 227 | foreach_flow_entry_##b \ |
| 228 | } vnet_flow_##b##_t; |
| 229 | foreach_flow_type; |
| 230 | #undef _ |
| 231 | #undef _fe |
| 232 | |
| 233 | /* main flow struct */ |
| 234 | typedef struct |
| 235 | { |
| 236 | /* flow type */ |
| 237 | vnet_flow_type_t type; |
| 238 | |
| 239 | /* flow index */ |
| 240 | u32 index; |
| 241 | |
| 242 | /* bitmap of flow actions (VNET_FLOW_ACTION_*) */ |
| 243 | u32 actions; |
| 244 | |
| 245 | /* flow id for VNET_FLOW_ACTION_MARK */ |
| 246 | u32 mark_flow_id; |
| 247 | |
| 248 | /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */ |
| 249 | u32 redirect_node_index; |
| 250 | u32 redirect_device_input_next_index; |
| 251 | |
| 252 | /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */ |
| 253 | u32 redirect_queue; |
| 254 | |
Ting Xu | b95e6d4 | 2022-03-25 03:45:07 +0000 | [diff] [blame] | 255 | /* start queue index and queue numbers for RSS queue group */ |
| 256 | u32 queue_index; |
| 257 | u32 queue_num; |
| 258 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 259 | /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */ |
| 260 | i32 buffer_advance; |
| 261 | |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 262 | /* RSS types, including IPv4/IPv6/TCP/UDP... */ |
| 263 | u64 rss_types; |
| 264 | |
| 265 | /* RSS functions, including IPv4/IPv6/TCP/UDP... */ |
| 266 | vnet_rss_function_t rss_fun; |
| 267 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 268 | union |
| 269 | { |
| 270 | #define _(a,b,c) vnet_flow_##b##_t b; |
| 271 | foreach_flow_type |
| 272 | #undef _ |
| 273 | }; |
| 274 | |
| 275 | /* per-interface private data */ |
| 276 | uword *private_data; |
| 277 | } vnet_flow_t; |
| 278 | |
| 279 | int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count, |
| 280 | u32 * start); |
| 281 | int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index); |
| 282 | int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index); |
| 283 | int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index); |
| 284 | int vnet_flow_del (vnet_main_t * vnm, u32 flow_index); |
| 285 | vnet_flow_t *vnet_get_flow (u32 flow_index); |
| 286 | |
| 287 | typedef struct |
| 288 | { |
| 289 | u32 start; |
| 290 | u32 count; |
| 291 | u8 *owner; |
| 292 | } vnet_flow_range_t; |
| 293 | |
| 294 | typedef struct |
| 295 | { |
| 296 | /* pool of device flow entries */ |
| 297 | vnet_flow_t *global_flow_pool; |
| 298 | |
| 299 | /* flow ids allocated */ |
| 300 | u32 flows_used; |
| 301 | |
| 302 | /* vector of flow ranges */ |
| 303 | vnet_flow_range_t *ranges; |
| 304 | |
Filip Tehlar | 9597f08 | 2021-06-21 09:49:31 +0000 | [diff] [blame] | 305 | u16 msg_id_base; |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 306 | } vnet_flow_main_t; |
| 307 | |
| 308 | extern vnet_flow_main_t flow_main; |
| 309 | |
| 310 | format_function_t format_flow_actions; |
Eyal Bari | d3de756 | 2018-05-31 11:30:16 +0300 | [diff] [blame] | 311 | format_function_t format_flow_enabled_hw; |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 312 | |
| 313 | #endif /* included_vnet_flow_flow_h */ |
| 314 | |
| 315 | /* |
| 316 | * fd.io coding-style-patch-verification: ON |
| 317 | * |
| 318 | * Local Variables: |
| 319 | * eval: (c-set-style "gnu") |
| 320 | * End: |
| 321 | */ |