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> |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 21 | #include <vnet/l3_types.h> |
| 22 | #include <vnet/ip/ip4_packet.h> |
| 23 | #include <vnet/ip/ip6_packet.h> |
Chenmin Sun | 4ff8d61 | 2019-12-15 01:16:45 +0800 | [diff] [blame] | 24 | #include <vnet/ethernet/packet.h> |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 25 | |
| 26 | #define foreach_flow_type \ |
Chenmin Sun | 4ff8d61 | 2019-12-15 01:16:45 +0800 | [diff] [blame] | 27 | /* l2 flow*/ \ |
| 28 | _(ETHERNET, ethernet, "ethernet") \ |
| 29 | /* l4 flow*/ \ |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 30 | _(IP4_N_TUPLE, ip4_n_tuple, "ipv4-n-tuple") \ |
Hongjun Ni | 95eec06 | 2018-12-28 18:27:04 +0800 | [diff] [blame] | 31 | _(IP6_N_TUPLE, ip6_n_tuple, "ipv6-n-tuple") \ |
Chenmin Sun | f13830c | 2020-02-26 19:22:35 +0800 | [diff] [blame] | 32 | _(IP4_N_TUPLE_TAGGED, ip4_n_tuple_tagged, "ipv4-n-tuple-tagged") \ |
| 33 | _(IP6_N_TUPLE_TAGGED, ip6_n_tuple_tagged, "ipv6-n-tuple-tagged") \ |
Chenmin Sun | 8b43aaa | 2020-04-15 01:55:58 +0800 | [diff] [blame] | 34 | /* IP tunnel flow */ \ |
| 35 | _(IP4_L2TPV3OIP, ip4_l2tpv3oip, "ipv4-l2tpv3oip") \ |
Chenmin Sun | d4c3666 | 2020-06-22 18:21:31 +0800 | [diff] [blame] | 36 | _(IP4_IPSEC_ESP, ip4_ipsec_esp, "ipv4-ipsec-esp") \ |
| 37 | _(IP4_IPSEC_AH, ip4_ipsec_ah, "ipv4-ipsec-ah") \ |
Chenmin Sun | 4ff8d61 | 2019-12-15 01:16:45 +0800 | [diff] [blame] | 38 | /* L4 tunnel flow*/ \ |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 39 | _(IP4_VXLAN, ip4_vxlan, "ipv4-vxlan") \ |
Chenmin Sun | bf85a98 | 2019-10-18 07:35:16 +0800 | [diff] [blame] | 40 | _(IP6_VXLAN, ip6_vxlan, "ipv6-vxlan") \ |
| 41 | _(IP4_GTPC, ip4_gtpc, "ipv4-gtpc") \ |
| 42 | _(IP4_GTPU, ip4_gtpu, "ipv4-gtpu") \ |
| 43 | _(IP4_GTPU_IP4, ip4_gtpu_ip4, "ipv4-gtpu-ipv4") \ |
| 44 | _(IP4_GTPU_IP6, ip4_gtpu_ip6, "ipv4-gtpu-ipv6") \ |
| 45 | _(IP6_GTPC, ip6_gtpc, "ipv6-gtpc") \ |
| 46 | _(IP6_GTPU, ip6_gtpu, "ipv6-gtpu") \ |
| 47 | _(IP6_GTPU_IP4, ip6_gtpu_ip4, "ipv6-gtpu-ipv4") \ |
| 48 | _(IP6_GTPU_IP6, ip6_gtpu_ip6, "ipv6-gtpu-ipv6") |
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 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 53 | #define foreach_flow_entry_ip4_n_tuple \ |
| 54 | _fe(ip4_address_and_mask_t, src_addr) \ |
| 55 | _fe(ip4_address_and_mask_t, dst_addr) \ |
| 56 | _fe(ip_port_and_mask_t, src_port) \ |
| 57 | _fe(ip_port_and_mask_t, dst_port) \ |
| 58 | _fe(ip_protocol_t, protocol) |
| 59 | |
| 60 | #define foreach_flow_entry_ip6_n_tuple \ |
| 61 | _fe(ip6_address_and_mask_t, src_addr) \ |
| 62 | _fe(ip6_address_and_mask_t, dst_addr) \ |
| 63 | _fe(ip_port_and_mask_t, src_port) \ |
| 64 | _fe(ip_port_and_mask_t, dst_port) \ |
| 65 | _fe(ip_protocol_t, protocol) |
| 66 | |
Chenmin Sun | f13830c | 2020-02-26 19:22:35 +0800 | [diff] [blame] | 67 | #define foreach_flow_entry_ip4_n_tuple_tagged \ |
| 68 | _fe(ip4_address_and_mask_t, src_addr) \ |
| 69 | _fe(ip4_address_and_mask_t, dst_addr) \ |
| 70 | _fe(ip_port_and_mask_t, src_port) \ |
| 71 | _fe(ip_port_and_mask_t, dst_port) \ |
| 72 | _fe(ip_protocol_t, protocol) |
| 73 | |
| 74 | #define foreach_flow_entry_ip6_n_tuple_tagged \ |
| 75 | _fe(ip6_address_and_mask_t, src_addr) \ |
| 76 | _fe(ip6_address_and_mask_t, dst_addr) \ |
| 77 | _fe(ip_port_and_mask_t, src_port) \ |
| 78 | _fe(ip_port_and_mask_t, dst_port) \ |
| 79 | _fe(ip_protocol_t, protocol) |
| 80 | |
Chenmin Sun | 8b43aaa | 2020-04-15 01:55:58 +0800 | [diff] [blame] | 81 | #define foreach_flow_entry_ip4_l2tpv3oip \ |
| 82 | _fe(ip4_address_and_mask_t, src_addr) \ |
| 83 | _fe(ip4_address_and_mask_t, dst_addr) \ |
| 84 | _fe(ip_protocol_t, protocol) \ |
| 85 | _fe(u32, session_id) |
Chenmin Sun | f13830c | 2020-02-26 19:22:35 +0800 | [diff] [blame] | 86 | |
Chenmin Sun | d4c3666 | 2020-06-22 18:21:31 +0800 | [diff] [blame] | 87 | #define foreach_flow_entry_ip4_ipsec_esp \ |
| 88 | _fe(ip4_address_and_mask_t, src_addr) \ |
| 89 | _fe(ip4_address_and_mask_t, dst_addr) \ |
| 90 | _fe(ip_protocol_t, protocol) \ |
| 91 | _fe(u32, spi) |
| 92 | |
| 93 | #define foreach_flow_entry_ip4_ipsec_ah \ |
| 94 | _fe(ip4_address_and_mask_t, src_addr) \ |
| 95 | _fe(ip4_address_and_mask_t, dst_addr) \ |
| 96 | _fe(ip_protocol_t, protocol) \ |
| 97 | _fe(u32, spi) |
| 98 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 99 | #define foreach_flow_entry_ip4_vxlan \ |
| 100 | _fe(ip4_address_t, src_addr) \ |
| 101 | _fe(ip4_address_t, dst_addr) \ |
| 102 | _fe(u16, dst_port) \ |
| 103 | _fe(u16, vni) |
| 104 | |
| 105 | #define foreach_flow_entry_ip6_vxlan \ |
| 106 | _fe(ip6_address_t, src_addr) \ |
| 107 | _fe(ip6_address_t, dst_addr) \ |
| 108 | _fe(u16, dst_port) \ |
| 109 | _fe(u16, vni) |
| 110 | |
Chenmin Sun | bf85a98 | 2019-10-18 07:35:16 +0800 | [diff] [blame] | 111 | #define foreach_flow_entry_ip4_gtpc \ |
| 112 | foreach_flow_entry_ip4_n_tuple \ |
| 113 | _fe(u32, teid) |
| 114 | |
| 115 | #define foreach_flow_entry_ip4_gtpu \ |
| 116 | foreach_flow_entry_ip4_n_tuple \ |
| 117 | _fe(u32, teid) |
| 118 | |
| 119 | #define foreach_flow_entry_ip4_gtpu_ip4 \ |
| 120 | foreach_flow_entry_ip4_gtpu \ |
| 121 | _fe(ip4_address_and_mask_t, inner_src_addr) \ |
| 122 | _fe(ip4_address_and_mask_t, inner_dst_addr) |
| 123 | |
| 124 | #define foreach_flow_entry_ip4_gtpu_ip6 \ |
| 125 | foreach_flow_entry_ip4_gtpu \ |
| 126 | _fe(ip6_address_and_mask_t, inner_src_addr) \ |
| 127 | _fe(ip6_address_and_mask_t, inner_dst_addr) |
| 128 | |
| 129 | #define foreach_flow_entry_ip6_gtpc \ |
| 130 | foreach_flow_entry_ip6_n_tuple \ |
| 131 | _fe(u32, teid) |
| 132 | |
| 133 | #define foreach_flow_entry_ip6_gtpu \ |
| 134 | foreach_flow_entry_ip6_n_tuple \ |
| 135 | _fe(u32, teid) |
| 136 | |
| 137 | #define foreach_flow_entry_ip6_gtpu_ip4 \ |
| 138 | foreach_flow_entry_ip6_gtpu \ |
| 139 | _fe(ip4_address_and_mask_t, inner_src_addr) \ |
| 140 | _fe(ip4_address_and_mask_t, inner_dst_addr) |
| 141 | |
| 142 | #define foreach_flow_entry_ip6_gtpu_ip6 \ |
| 143 | foreach_flow_entry_ip6_gtpu \ |
| 144 | _fe(ip6_address_and_mask_t, inner_src_addr) \ |
| 145 | _fe(ip6_address_and_mask_t, inner_dst_addr) |
| 146 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 147 | #define foreach_flow_action \ |
| 148 | _(0, COUNT, "count") \ |
| 149 | _(1, MARK, "mark") \ |
| 150 | _(2, BUFFER_ADVANCE, "buffer-advance") \ |
| 151 | _(3, REDIRECT_TO_NODE, "redirect-to-node") \ |
| 152 | _(4, REDIRECT_TO_QUEUE, "redirect-to-queue") \ |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 153 | _(5, RSS, "rss") \ |
| 154 | _(6, DROP, "drop") |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 155 | |
| 156 | typedef enum |
| 157 | { |
| 158 | #define _(v,n,s) VNET_FLOW_ACTION_##n = (1 << v), |
| 159 | foreach_flow_action |
| 160 | #undef _ |
| 161 | } vnet_flow_action_t; |
| 162 | |
| 163 | |
| 164 | #define foreach_flow_error \ |
| 165 | _( -1, NOT_SUPPORTED, "not supported") \ |
| 166 | _( -2, ALREADY_DONE, "already done") \ |
| 167 | _( -3, ALREADY_EXISTS, "already exists") \ |
| 168 | _( -4, NO_SUCH_ENTRY, "no such entry") \ |
| 169 | _( -5, NO_SUCH_INTERFACE, "no such interface") \ |
| 170 | _( -6, INTERNAL, "internal error") |
| 171 | |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 172 | #define foreach_flow_rss_types \ |
| 173 | _(0, FRAG_IPV4, "ipv4-frag") \ |
| 174 | _(1, IPV4_TCP, "ipv4-tcp") \ |
| 175 | _(2, IPV4_UDP, "ipv4-udp") \ |
| 176 | _(3, IPV4_SCTP, "ipv4-sctp") \ |
| 177 | _(4, IPV4_OTHER, "ipv4-other") \ |
| 178 | _(5, IPV4, "ipv4") \ |
| 179 | _(6, IPV6_TCP_EX, "ipv6-tcp-ex") \ |
| 180 | _(7, IPV6_UDP_EX, "ipv6-udp-ex") \ |
| 181 | _(8, FRAG_IPV6, "ipv6-frag") \ |
| 182 | _(9, IPV6_TCP, "ipv6-tcp") \ |
| 183 | _(10, IPV6_UDP, "ipv6-udp") \ |
| 184 | _(11, IPV6_SCTP, "ipv6-sctp") \ |
| 185 | _(12, IPV6_OTHER, "ipv6-other") \ |
| 186 | _(13, IPV6_EX, "ipv6-ex") \ |
| 187 | _(14, IPV6, "ipv6") \ |
| 188 | _(15, L2_PAYLOAD, "l2-payload") \ |
| 189 | _(16, PORT, "port") \ |
| 190 | _(17, VXLAN, "vxlan") \ |
| 191 | _(18, GENEVE, "geneve") \ |
| 192 | _(19, NVGRE, "nvgre") \ |
| 193 | _(20, GTPU, "gtpu") \ |
| 194 | _(60, L4_DST_ONLY, "l4-dst-only") \ |
| 195 | _(61, L4_SRC_ONLY, "l4-src-only") \ |
| 196 | _(62, L3_DST_ONLY, "l3-dst-only") \ |
| 197 | _(63, L3_SRC_ONLY, "l3-src-only") |
| 198 | |
| 199 | #define foreach_rss_function \ |
| 200 | _(DEFAULT, "default") \ |
| 201 | _(TOEPLITZ, "toeplitz") \ |
| 202 | _(SIMPLE_XOR, "simple_xor") \ |
| 203 | _(SYMMETRIC_TOEPLITZ, "symmetric_toeplitz") |
| 204 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 205 | typedef enum |
| 206 | { |
| 207 | VNET_FLOW_NO_ERROR = 0, |
| 208 | #define _(v,n,s) VNET_FLOW_ERROR_##n = v, |
| 209 | foreach_flow_error |
| 210 | #undef _ |
| 211 | } vnet_flow_error_t; |
| 212 | |
| 213 | typedef struct |
| 214 | { |
| 215 | u16 port, mask; |
| 216 | } ip_port_and_mask_t; |
| 217 | |
| 218 | typedef enum |
| 219 | { |
| 220 | VNET_FLOW_TYPE_UNKNOWN, |
| 221 | #define _(a,b,c) VNET_FLOW_TYPE_##a, |
| 222 | foreach_flow_type |
| 223 | #undef _ |
| 224 | VNET_FLOW_N_TYPES, |
| 225 | } vnet_flow_type_t; |
| 226 | |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 227 | typedef enum |
| 228 | { |
| 229 | #define _(a,b) VNET_RSS_FUNC_##a, |
| 230 | foreach_rss_function |
| 231 | #undef _ |
| 232 | VNET_RSS_N_TYPES, |
| 233 | } vnet_rss_function_t; |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * Create typedef struct vnet_flow_XXX_t |
| 237 | */ |
| 238 | #define _fe(a, b) a b; |
| 239 | #define _(a,b,c) \ |
| 240 | typedef struct { \ |
| 241 | int foo; \ |
| 242 | foreach_flow_entry_##b \ |
| 243 | } vnet_flow_##b##_t; |
| 244 | foreach_flow_type; |
| 245 | #undef _ |
| 246 | #undef _fe |
| 247 | |
| 248 | /* main flow struct */ |
| 249 | typedef struct |
| 250 | { |
| 251 | /* flow type */ |
| 252 | vnet_flow_type_t type; |
| 253 | |
| 254 | /* flow index */ |
| 255 | u32 index; |
| 256 | |
| 257 | /* bitmap of flow actions (VNET_FLOW_ACTION_*) */ |
| 258 | u32 actions; |
| 259 | |
| 260 | /* flow id for VNET_FLOW_ACTION_MARK */ |
| 261 | u32 mark_flow_id; |
| 262 | |
| 263 | /* node index and next index for VNET_FLOW_ACTION_REDIRECT_TO_NODE */ |
| 264 | u32 redirect_node_index; |
| 265 | u32 redirect_device_input_next_index; |
| 266 | |
| 267 | /* queue for VNET_FLOW_ACTION_REDIRECT_TO_QUEUE */ |
| 268 | u32 redirect_queue; |
| 269 | |
| 270 | /* buffer offset for VNET_FLOW_ACTION_BUFFER_ADVANCE */ |
| 271 | i32 buffer_advance; |
| 272 | |
Chenmin Sun | 24e2c50 | 2020-02-28 22:49:37 +0800 | [diff] [blame] | 273 | /* RSS types, including IPv4/IPv6/TCP/UDP... */ |
| 274 | u64 rss_types; |
| 275 | |
| 276 | /* RSS functions, including IPv4/IPv6/TCP/UDP... */ |
| 277 | vnet_rss_function_t rss_fun; |
| 278 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 279 | union |
| 280 | { |
| 281 | #define _(a,b,c) vnet_flow_##b##_t b; |
| 282 | foreach_flow_type |
| 283 | #undef _ |
| 284 | }; |
| 285 | |
| 286 | /* per-interface private data */ |
| 287 | uword *private_data; |
| 288 | } vnet_flow_t; |
| 289 | |
| 290 | int vnet_flow_get_range (vnet_main_t * vnm, char *owner, u32 count, |
| 291 | u32 * start); |
| 292 | int vnet_flow_add (vnet_main_t * vnm, vnet_flow_t * flow, u32 * flow_index); |
| 293 | int vnet_flow_enable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index); |
| 294 | int vnet_flow_disable (vnet_main_t * vnm, u32 flow_index, u32 hw_if_index); |
| 295 | int vnet_flow_del (vnet_main_t * vnm, u32 flow_index); |
| 296 | vnet_flow_t *vnet_get_flow (u32 flow_index); |
| 297 | |
| 298 | typedef struct |
| 299 | { |
| 300 | u32 start; |
| 301 | u32 count; |
| 302 | u8 *owner; |
| 303 | } vnet_flow_range_t; |
| 304 | |
| 305 | typedef struct |
| 306 | { |
| 307 | /* pool of device flow entries */ |
| 308 | vnet_flow_t *global_flow_pool; |
| 309 | |
| 310 | /* flow ids allocated */ |
| 311 | u32 flows_used; |
| 312 | |
| 313 | /* vector of flow ranges */ |
| 314 | vnet_flow_range_t *ranges; |
| 315 | |
| 316 | } vnet_flow_main_t; |
| 317 | |
| 318 | extern vnet_flow_main_t flow_main; |
| 319 | |
| 320 | format_function_t format_flow_actions; |
Eyal Bari | d3de756 | 2018-05-31 11:30:16 +0300 | [diff] [blame] | 321 | format_function_t format_flow_enabled_hw; |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 322 | |
| 323 | #endif /* included_vnet_flow_flow_h */ |
| 324 | |
| 325 | /* |
| 326 | * fd.io coding-style-patch-verification: ON |
| 327 | * |
| 328 | * Local Variables: |
| 329 | * eval: (c-set-style "gnu") |
| 330 | * End: |
| 331 | */ |