Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * flow_api.c - flow api |
| 4 | * |
| 5 | * Copyright (c) 2020 Intel 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 <stddef.h> |
| 21 | |
| 22 | #include <vnet/vnet.h> |
| 23 | #include <vlibmemory/api.h> |
| 24 | #include <vnet/interface.h> |
| 25 | #include <vnet/api_errno.h> |
| 26 | #include <vnet/flow/flow.h> |
| 27 | #include <vnet/fib/fib_table.h> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 28 | #include <vnet/udp/udp_local.h> |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 29 | #include <vnet/tunnel/tunnel_types_api.h> |
| 30 | #include <vnet/ip/ip_types_api.h> |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 31 | |
Filip Tehlar | 9597f08 | 2021-06-21 09:49:31 +0000 | [diff] [blame] | 32 | #include <vnet/format_fns.h> |
| 33 | #include <vnet/flow/flow.api_enum.h> |
| 34 | #include <vnet/flow/flow.api_types.h> |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 35 | |
Filip Tehlar | 9597f08 | 2021-06-21 09:49:31 +0000 | [diff] [blame] | 36 | #define REPLY_MSG_ID_BASE flow_main.msg_id_base |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 37 | #include <vlibapi/api_helper_macros.h> |
| 38 | |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 39 | static inline void |
| 40 | ipv4_addr_and_mask_convert (vl_api_ip4_address_and_mask_t * vl_api_addr, |
| 41 | ip4_address_and_mask_t * vnet_addr) |
| 42 | { |
| 43 | clib_memcpy (vnet_addr, vl_api_addr, sizeof (*vnet_addr)); |
| 44 | } |
| 45 | |
| 46 | static inline void |
| 47 | ipv6_addr_and_mask_convert (vl_api_ip6_address_and_mask_t * vl_api_addr, |
| 48 | ip6_address_and_mask_t * vnet_addr) |
| 49 | { |
| 50 | clib_memcpy (vnet_addr, vl_api_addr, sizeof (*vnet_addr)); |
| 51 | } |
| 52 | |
| 53 | static inline void |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 54 | protocol_and_mask_convert (vl_api_ip_prot_and_mask_t * vl_api_protocol, |
| 55 | ip_prot_and_mask_t * vnet_protocol) |
| 56 | { |
| 57 | vnet_protocol->prot = (ip_protocol_t) vl_api_protocol->prot; |
| 58 | vnet_protocol->mask = vl_api_protocol->mask; |
| 59 | } |
| 60 | |
| 61 | static inline void |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 62 | port_and_mask_convert (vl_api_ip_port_and_mask_t * vl_api_port, |
| 63 | ip_port_and_mask_t * vnet_port) |
| 64 | { |
| 65 | vnet_port->port = ntohs (vl_api_port->port); |
| 66 | vnet_port->mask = ntohs (vl_api_port->mask); |
| 67 | } |
| 68 | |
| 69 | static inline void |
Chenmin Sun | c7e7819 | 2020-09-04 06:50:22 +0800 | [diff] [blame] | 70 | ipv4_flow_convert (vl_api_flow_ip4_t *vl_api_flow, vnet_flow_ip4_t *f) |
| 71 | { |
| 72 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 73 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 74 | |
| 75 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
| 76 | } |
| 77 | |
| 78 | static void |
| 79 | ipv6_flow_convert (vl_api_flow_ip6_t *vl_api_flow, vnet_flow_ip6_t *f) |
| 80 | { |
| 81 | ipv6_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 82 | ipv6_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 83 | |
| 84 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
| 85 | } |
| 86 | |
| 87 | static inline void |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 88 | ipv4_n_tuple_flow_convert (vl_api_flow_ip4_n_tuple_t * vl_api_flow, |
| 89 | vnet_flow_ip4_n_tuple_t * f) |
| 90 | { |
| 91 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 92 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 93 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 94 | |
| 95 | port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); |
| 96 | port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void |
| 100 | ipv6_n_tuple_flow_convert (vl_api_flow_ip6_n_tuple_t * vl_api_flow, |
| 101 | vnet_flow_ip6_n_tuple_t * f) |
| 102 | { |
| 103 | ipv6_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 104 | ipv6_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 105 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 106 | |
| 107 | port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); |
| 108 | port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static inline void |
| 112 | ipv4_n_tuple_tagged_flow_convert (vl_api_flow_ip4_n_tuple_tagged_t * |
| 113 | vl_api_flow, |
| 114 | vnet_flow_ip4_n_tuple_tagged_t * f) |
| 115 | { |
| 116 | return ipv4_n_tuple_flow_convert ((vl_api_flow_ip4_n_tuple_t *) vl_api_flow, |
| 117 | (vnet_flow_ip4_n_tuple_t *) f); |
| 118 | } |
| 119 | |
| 120 | static inline void |
| 121 | ipv6_n_tuple_tagged_flow_convert (vl_api_flow_ip6_n_tuple_tagged_t * |
| 122 | vl_api_flow, |
| 123 | vnet_flow_ip6_n_tuple_tagged_t * f) |
| 124 | { |
| 125 | return ipv6_n_tuple_flow_convert ((vl_api_flow_ip6_n_tuple_t *) vl_api_flow, |
| 126 | (vnet_flow_ip6_n_tuple_t *) f); |
| 127 | } |
| 128 | |
| 129 | static inline void |
| 130 | ipv4_l2tpv3oip_flow_convert (vl_api_flow_ip4_l2tpv3oip_t * vl_api_flow, |
| 131 | vnet_flow_ip4_l2tpv3oip_t * f) |
| 132 | { |
| 133 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 134 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 135 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 136 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 137 | f->session_id = ntohl (vl_api_flow->session_id); |
| 138 | } |
| 139 | |
| 140 | static inline void |
| 141 | ipv4_ipsec_esp_flow_convert (vl_api_flow_ip4_ipsec_esp_t * vl_api_flow, |
| 142 | vnet_flow_ip4_ipsec_esp_t * f) |
| 143 | { |
| 144 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 145 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 146 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 147 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 148 | f->spi = ntohl (vl_api_flow->spi); |
| 149 | } |
| 150 | |
| 151 | static inline void |
| 152 | ipv4_ipsec_ah_flow_convert (vl_api_flow_ip4_ipsec_ah_t * vl_api_flow, |
| 153 | vnet_flow_ip4_ipsec_ah_t * f) |
| 154 | { |
| 155 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 156 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 157 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 158 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 159 | f->spi = ntohl (vl_api_flow->spi); |
| 160 | } |
| 161 | |
| 162 | static inline void |
Chenmin Sun | c7e7819 | 2020-09-04 06:50:22 +0800 | [diff] [blame] | 163 | ipv4_vxlan_flow_convert (vl_api_flow_ip4_vxlan_t *vl_api_flow, |
| 164 | vnet_flow_ip4_vxlan_t *f) |
| 165 | { |
| 166 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 167 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 168 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
| 169 | |
| 170 | port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); |
| 171 | port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); |
| 172 | |
Chenmin Sun | ee32d66 | 2021-05-10 20:11:49 +0800 | [diff] [blame] | 173 | f->vni = ntohl (vl_api_flow->vni); |
Chenmin Sun | c7e7819 | 2020-09-04 06:50:22 +0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static inline void |
| 177 | ipv6_vxlan_flow_convert (vl_api_flow_ip6_vxlan_t *vl_api_flow, |
| 178 | vnet_flow_ip6_vxlan_t *f) |
| 179 | { |
| 180 | ipv6_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 181 | ipv6_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 182 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
| 183 | |
| 184 | port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); |
| 185 | port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); |
| 186 | |
Chenmin Sun | ee32d66 | 2021-05-10 20:11:49 +0800 | [diff] [blame] | 187 | f->vni = ntohl (vl_api_flow->vni); |
Chenmin Sun | c7e7819 | 2020-09-04 06:50:22 +0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static inline void |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 191 | ipv4_gtpu_flow_convert (vl_api_flow_ip4_gtpu_t * vl_api_flow, |
| 192 | vnet_flow_ip4_gtpu_t * f) |
| 193 | { |
| 194 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 195 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 196 | |
| 197 | port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); |
| 198 | port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); |
| 199 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 200 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 201 | f->teid = ntohl (vl_api_flow->teid); |
| 202 | } |
| 203 | |
| 204 | static inline void |
| 205 | ipv4_gtpc_flow_convert (vl_api_flow_ip4_gtpc_t * vl_api_flow, |
| 206 | vnet_flow_ip4_gtpc_t * f) |
| 207 | { |
| 208 | ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); |
| 209 | ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); |
| 210 | |
| 211 | port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); |
| 212 | port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); |
| 213 | |
Chenmin Sun | 34bfa50 | 2020-07-27 17:40:17 +0800 | [diff] [blame] | 214 | protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 215 | f->teid = ntohl (vl_api_flow->teid); |
| 216 | } |
| 217 | |
Ting Xu | 337960b | 2022-03-08 07:22:56 +0000 | [diff] [blame] | 218 | static inline void |
| 219 | generic_flow_convert (vl_api_flow_generic_t *vl_api_flow, |
| 220 | vnet_flow_generic_t *f) |
| 221 | { |
| 222 | clib_memcpy (f->pattern.spec, vl_api_flow->pattern.spec, |
| 223 | sizeof (vl_api_flow->pattern.spec)); |
| 224 | clib_memcpy (f->pattern.mask, vl_api_flow->pattern.mask, |
| 225 | sizeof (vl_api_flow->pattern.mask)); |
| 226 | } |
| 227 | |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 228 | static void |
| 229 | vl_api_flow_add_t_handler (vl_api_flow_add_t * mp) |
| 230 | { |
| 231 | vl_api_flow_add_reply_t *rmp; |
| 232 | int rv = 0; |
| 233 | vnet_flow_t flow; |
| 234 | u32 flow_index = ~0; |
| 235 | vl_api_flow_rule_t *f = &mp->flow; |
| 236 | |
| 237 | vnet_main_t *vnm = vnet_get_main (); |
| 238 | |
| 239 | flow.type = ntohl (f->type); |
| 240 | flow.actions = ntohl (f->actions); |
| 241 | flow.mark_flow_id = ntohl (f->mark_flow_id); |
| 242 | flow.redirect_node_index = ntohl (f->redirect_node_index); |
| 243 | flow.redirect_device_input_next_index = |
| 244 | ntohl (f->redirect_device_input_next_index); |
| 245 | flow.redirect_queue = ntohl (f->redirect_queue); |
| 246 | flow.buffer_advance = ntohl (f->buffer_advance); |
| 247 | |
| 248 | switch (flow.type) |
| 249 | { |
Chenmin Sun | c7e7819 | 2020-09-04 06:50:22 +0800 | [diff] [blame] | 250 | case VNET_FLOW_TYPE_IP4: |
| 251 | ipv4_flow_convert (&f->flow.ip4, &flow.ip4); |
| 252 | break; |
| 253 | case VNET_FLOW_TYPE_IP6: |
| 254 | ipv6_flow_convert (&f->flow.ip6, &flow.ip6); |
| 255 | break; |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 256 | case VNET_FLOW_TYPE_IP4_N_TUPLE: |
| 257 | ipv4_n_tuple_flow_convert (&f->flow.ip4_n_tuple, &flow.ip4_n_tuple); |
| 258 | break; |
| 259 | case VNET_FLOW_TYPE_IP6_N_TUPLE: |
| 260 | ipv6_n_tuple_flow_convert (&f->flow.ip6_n_tuple, &flow.ip6_n_tuple); |
| 261 | break; |
| 262 | case VNET_FLOW_TYPE_IP4_N_TUPLE_TAGGED: |
| 263 | ipv4_n_tuple_tagged_flow_convert (&f->flow.ip4_n_tuple_tagged, |
| 264 | &flow.ip4_n_tuple_tagged); |
| 265 | break; |
| 266 | case VNET_FLOW_TYPE_IP6_N_TUPLE_TAGGED: |
| 267 | ipv6_n_tuple_tagged_flow_convert (&f->flow.ip6_n_tuple_tagged, |
| 268 | &flow.ip6_n_tuple_tagged); |
| 269 | break; |
| 270 | case VNET_FLOW_TYPE_IP4_L2TPV3OIP: |
| 271 | ipv4_l2tpv3oip_flow_convert (&f->flow.ip4_l2tpv3oip, |
| 272 | &flow.ip4_l2tpv3oip); |
| 273 | break; |
| 274 | case VNET_FLOW_TYPE_IP4_IPSEC_ESP: |
| 275 | ipv4_ipsec_esp_flow_convert (&f->flow.ip4_ipsec_esp, |
| 276 | &flow.ip4_ipsec_esp); |
| 277 | break; |
| 278 | case VNET_FLOW_TYPE_IP4_IPSEC_AH: |
| 279 | ipv4_ipsec_ah_flow_convert (&f->flow.ip4_ipsec_ah, &flow.ip4_ipsec_ah); |
| 280 | break; |
Chenmin Sun | c7e7819 | 2020-09-04 06:50:22 +0800 | [diff] [blame] | 281 | case VNET_FLOW_TYPE_IP4_VXLAN: |
| 282 | ipv4_vxlan_flow_convert (&f->flow.ip4_vxlan, &flow.ip4_vxlan); |
| 283 | break; |
| 284 | case VNET_FLOW_TYPE_IP6_VXLAN: |
| 285 | ipv6_vxlan_flow_convert (&f->flow.ip6_vxlan, &flow.ip6_vxlan); |
| 286 | break; |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 287 | case VNET_FLOW_TYPE_IP4_GTPU: |
| 288 | ipv4_gtpu_flow_convert (&f->flow.ip4_gtpu, &flow.ip4_gtpu); |
| 289 | break; |
| 290 | case VNET_FLOW_TYPE_IP4_GTPC: |
| 291 | ipv4_gtpc_flow_convert (&f->flow.ip4_gtpc, &flow.ip4_gtpc); |
| 292 | break; |
| 293 | default: |
| 294 | rv = VNET_FLOW_ERROR_NOT_SUPPORTED; |
| 295 | goto out; |
| 296 | break; |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | rv = vnet_flow_add (vnm, &flow, &flow_index); |
| 300 | |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 301 | out: |
| 302 | /* *INDENT-OFF* */ |
| 303 | REPLY_MACRO2(VL_API_FLOW_ADD_REPLY, |
| 304 | ({ |
| 305 | rmp->flow_index = ntohl (flow_index); |
| 306 | })); |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 307 | /* *INDENT-ON* */ |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void |
Ting Xu | 337960b | 2022-03-08 07:22:56 +0000 | [diff] [blame] | 311 | vl_api_flow_add_v2_t_handler (vl_api_flow_add_v2_t *mp) |
| 312 | { |
| 313 | vl_api_flow_add_v2_reply_t *rmp; |
| 314 | int rv = 0; |
| 315 | vnet_flow_t flow; |
| 316 | u32 flow_index = ~0; |
| 317 | vl_api_flow_rule_v2_t *f = &mp->flow; |
| 318 | |
| 319 | vnet_main_t *vnm = vnet_get_main (); |
| 320 | |
| 321 | flow.type = ntohl (f->type); |
| 322 | flow.actions = ntohl (f->actions); |
| 323 | flow.mark_flow_id = ntohl (f->mark_flow_id); |
| 324 | flow.redirect_node_index = ntohl (f->redirect_node_index); |
| 325 | flow.redirect_device_input_next_index = |
| 326 | ntohl (f->redirect_device_input_next_index); |
| 327 | flow.redirect_queue = ntohl (f->redirect_queue); |
| 328 | flow.buffer_advance = ntohl (f->buffer_advance); |
| 329 | flow.queue_index = ntohl (f->queue_index); |
| 330 | flow.queue_num = ntohl (f->queue_num); |
| 331 | flow.rss_types = ntohl (f->rss_types); |
| 332 | flow.rss_fun = ntohl (f->rss_fun); |
| 333 | |
| 334 | switch (flow.type) |
| 335 | { |
| 336 | case VNET_FLOW_TYPE_IP4: |
| 337 | ipv4_flow_convert (&f->flow.ip4, &flow.ip4); |
| 338 | break; |
| 339 | case VNET_FLOW_TYPE_IP6: |
| 340 | ipv6_flow_convert (&f->flow.ip6, &flow.ip6); |
| 341 | break; |
| 342 | case VNET_FLOW_TYPE_IP4_N_TUPLE: |
| 343 | ipv4_n_tuple_flow_convert (&f->flow.ip4_n_tuple, &flow.ip4_n_tuple); |
| 344 | break; |
| 345 | case VNET_FLOW_TYPE_IP6_N_TUPLE: |
| 346 | ipv6_n_tuple_flow_convert (&f->flow.ip6_n_tuple, &flow.ip6_n_tuple); |
| 347 | break; |
| 348 | case VNET_FLOW_TYPE_IP4_N_TUPLE_TAGGED: |
| 349 | ipv4_n_tuple_tagged_flow_convert (&f->flow.ip4_n_tuple_tagged, |
| 350 | &flow.ip4_n_tuple_tagged); |
| 351 | break; |
| 352 | case VNET_FLOW_TYPE_IP6_N_TUPLE_TAGGED: |
| 353 | ipv6_n_tuple_tagged_flow_convert (&f->flow.ip6_n_tuple_tagged, |
| 354 | &flow.ip6_n_tuple_tagged); |
| 355 | break; |
| 356 | case VNET_FLOW_TYPE_IP4_L2TPV3OIP: |
| 357 | ipv4_l2tpv3oip_flow_convert (&f->flow.ip4_l2tpv3oip, |
| 358 | &flow.ip4_l2tpv3oip); |
| 359 | break; |
| 360 | case VNET_FLOW_TYPE_IP4_IPSEC_ESP: |
| 361 | ipv4_ipsec_esp_flow_convert (&f->flow.ip4_ipsec_esp, |
| 362 | &flow.ip4_ipsec_esp); |
| 363 | break; |
| 364 | case VNET_FLOW_TYPE_IP4_IPSEC_AH: |
| 365 | ipv4_ipsec_ah_flow_convert (&f->flow.ip4_ipsec_ah, &flow.ip4_ipsec_ah); |
| 366 | break; |
| 367 | case VNET_FLOW_TYPE_IP4_VXLAN: |
| 368 | ipv4_vxlan_flow_convert (&f->flow.ip4_vxlan, &flow.ip4_vxlan); |
| 369 | break; |
| 370 | case VNET_FLOW_TYPE_IP6_VXLAN: |
| 371 | ipv6_vxlan_flow_convert (&f->flow.ip6_vxlan, &flow.ip6_vxlan); |
| 372 | break; |
| 373 | case VNET_FLOW_TYPE_IP4_GTPU: |
| 374 | ipv4_gtpu_flow_convert (&f->flow.ip4_gtpu, &flow.ip4_gtpu); |
| 375 | break; |
| 376 | case VNET_FLOW_TYPE_IP4_GTPC: |
| 377 | ipv4_gtpc_flow_convert (&f->flow.ip4_gtpc, &flow.ip4_gtpc); |
| 378 | break; |
| 379 | case VNET_FLOW_TYPE_GENERIC: |
| 380 | generic_flow_convert (&f->flow.generic, &flow.generic); |
| 381 | break; |
| 382 | default: |
| 383 | rv = VNET_FLOW_ERROR_NOT_SUPPORTED; |
| 384 | goto out; |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | rv = vnet_flow_add (vnm, &flow, &flow_index); |
| 389 | |
| 390 | out: |
| 391 | REPLY_MACRO2 (VL_API_FLOW_ADD_V2_REPLY, |
| 392 | ({ rmp->flow_index = ntohl (flow_index); })); |
| 393 | } |
| 394 | |
| 395 | static void |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 396 | vl_api_flow_del_t_handler (vl_api_flow_del_t * mp) |
| 397 | { |
| 398 | vl_api_flow_add_reply_t *rmp; |
| 399 | int rv = 0; |
| 400 | |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 401 | vnet_main_t *vnm = vnet_get_main (); |
| 402 | rv = vnet_flow_del (vnm, ntohl (mp->flow_index)); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 403 | |
| 404 | REPLY_MACRO (VL_API_FLOW_DEL_REPLY); |
| 405 | } |
| 406 | |
| 407 | static void |
| 408 | vl_api_flow_enable_t_handler (vl_api_flow_enable_t * mp) |
| 409 | { |
| 410 | vl_api_flow_add_reply_t *rmp; |
| 411 | int rv = 0; |
| 412 | |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 413 | vnet_main_t *vnm = vnet_get_main (); |
| 414 | rv = |
| 415 | vnet_flow_enable (vnm, ntohl (mp->flow_index), ntohl (mp->hw_if_index)); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 416 | |
| 417 | REPLY_MACRO (VL_API_FLOW_ENABLE_REPLY); |
| 418 | } |
| 419 | |
| 420 | static void |
| 421 | vl_api_flow_disable_t_handler (vl_api_flow_disable_t * mp) |
| 422 | { |
| 423 | vl_api_flow_add_reply_t *rmp; |
| 424 | int rv = 0; |
| 425 | |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 426 | vnet_main_t *vnm = vnet_get_main (); |
| 427 | rv = |
| 428 | vnet_flow_disable (vnm, ntohl (mp->flow_index), ntohl (mp->hw_if_index)); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 429 | |
| 430 | REPLY_MACRO (VL_API_FLOW_DISABLE_REPLY); |
| 431 | } |
| 432 | |
Filip Tehlar | 9597f08 | 2021-06-21 09:49:31 +0000 | [diff] [blame] | 433 | #include <vnet/flow/flow.api.c> |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 434 | static clib_error_t * |
| 435 | hw_flow_api_hookup (vlib_main_t * vm) |
| 436 | { |
Filip Tehlar | 9597f08 | 2021-06-21 09:49:31 +0000 | [diff] [blame] | 437 | flow_main.msg_id_base = setup_message_id_table (); |
Chenmin Sun | d0236f7 | 2020-07-27 17:54:40 +0800 | [diff] [blame] | 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | VLIB_API_INIT_FUNCTION (hw_flow_api_hookup); |
| 443 | |
| 444 | /* |
| 445 | * fd.io coding-style-patch-verification: ON |
| 446 | * |
| 447 | * Local Variables: |
| 448 | * eval: (c-set-style "gnu") |
| 449 | * End: |
| 450 | */ |