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