1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2016 6WIND S.A. 3 * Copyright 2016 Mellanox Technologies, Ltd 4 */ 5 6 #include <errno.h> 7 #include <stddef.h> 8 #include <stdint.h> 9 #include <string.h> 10 11 #include <rte_common.h> 12 #include <rte_errno.h> 13 #include <rte_branch_prediction.h> 14 #include <rte_string_fns.h> 15 #include <rte_mbuf.h> 16 #include <rte_mbuf_dyn.h> 17 #include "rte_ethdev.h" 18 #include "rte_flow_driver.h" 19 #include "rte_flow.h" 20 21 /* Mbuf dynamic field name for metadata. */ 22 int32_t rte_flow_dynf_metadata_offs = -1; 23 24 /* Mbuf dynamic field flag bit number for metadata. */ 25 uint64_t rte_flow_dynf_metadata_mask; 26 27 /** 28 * Flow elements description tables. 29 */ 30 struct rte_flow_desc_data { 31 const char *name; 32 size_t size; 33 size_t (*desc_fn)(void *dst, const void *src); 34 }; 35 36 /** 37 * 38 * @param buf 39 * Destination memory. 40 * @param data 41 * Source memory 42 * @param size 43 * Requested copy size 44 * @param desc 45 * rte_flow_desc_item - for flow item conversion. 46 * rte_flow_desc_action - for flow action conversion. 47 * @param type 48 * Offset into the desc param or negative value for private flow elements. 49 */ 50 static inline size_t 51 rte_flow_conv_copy(void *buf, const void *data, const size_t size, 52 const struct rte_flow_desc_data *desc, int type) 53 { 54 /** 55 * Allow PMD private flow item 56 */ 57 size_t sz = type >= 0 ? desc[type].size : sizeof(void *); 58 if (buf == NULL || data == NULL) 59 return 0; 60 rte_memcpy(buf, data, (size > sz ? sz : size)); 61 if (desc[type].desc_fn) 62 sz += desc[type].desc_fn(size > 0 ? buf : NULL, data); 63 return sz; 64 } 65 66 static size_t 67 rte_flow_item_flex_conv(void *buf, const void *data) 68 { 69 struct rte_flow_item_flex *dst = buf; 70 const struct rte_flow_item_flex *src = data; 71 if (buf) { 72 dst->pattern = rte_memcpy 73 ((void *)((uintptr_t)(dst + 1)), src->pattern, 74 src->length); 75 } 76 return src->length; 77 } 78 79 /** Generate flow_item[] entry. */ 80 #define MK_FLOW_ITEM(t, s) \ 81 [RTE_FLOW_ITEM_TYPE_ ## t] = { \ 82 .name = # t, \ 83 .size = s, \ 84 .desc_fn = NULL,\ 85 } 86 87 #define MK_FLOW_ITEM_FN(t, s, fn) \ 88 [RTE_FLOW_ITEM_TYPE_ ## t] = {\ 89 .name = # t, \ 90 .size = s, \ 91 .desc_fn = fn, \ 92 } 93 94 /** Information about known flow pattern items. */ 95 static const struct rte_flow_desc_data rte_flow_desc_item[] = { 96 MK_FLOW_ITEM(END, 0), 97 MK_FLOW_ITEM(VOID, 0), 98 MK_FLOW_ITEM(INVERT, 0), 99 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)), 100 MK_FLOW_ITEM(PF, 0), 101 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)), 102 MK_FLOW_ITEM(PHY_PORT, sizeof(struct rte_flow_item_phy_port)), 103 MK_FLOW_ITEM(PORT_ID, sizeof(struct rte_flow_item_port_id)), 104 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), 105 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)), 106 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)), 107 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)), 108 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)), 109 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)), 110 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)), 111 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)), 112 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)), 113 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)), 114 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)), 115 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)), 116 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)), 117 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)), 118 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)), 119 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)), 120 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)), 121 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)), 122 MK_FLOW_ITEM(ESP, sizeof(struct rte_flow_item_esp)), 123 MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)), 124 MK_FLOW_ITEM(VXLAN_GPE, sizeof(struct rte_flow_item_vxlan_gpe)), 125 MK_FLOW_ITEM(ARP_ETH_IPV4, sizeof(struct rte_flow_item_arp_eth_ipv4)), 126 MK_FLOW_ITEM(IPV6_EXT, sizeof(struct rte_flow_item_ipv6_ext)), 127 MK_FLOW_ITEM(IPV6_FRAG_EXT, sizeof(struct rte_flow_item_ipv6_frag_ext)), 128 MK_FLOW_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)), 129 MK_FLOW_ITEM(ICMP6_ND_NS, sizeof(struct rte_flow_item_icmp6_nd_ns)), 130 MK_FLOW_ITEM(ICMP6_ND_NA, sizeof(struct rte_flow_item_icmp6_nd_na)), 131 MK_FLOW_ITEM(ICMP6_ND_OPT, sizeof(struct rte_flow_item_icmp6_nd_opt)), 132 MK_FLOW_ITEM(ICMP6_ND_OPT_SLA_ETH, 133 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)), 134 MK_FLOW_ITEM(ICMP6_ND_OPT_TLA_ETH, 135 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)), 136 MK_FLOW_ITEM(MARK, sizeof(struct rte_flow_item_mark)), 137 MK_FLOW_ITEM(META, sizeof(struct rte_flow_item_meta)), 138 MK_FLOW_ITEM(TAG, sizeof(struct rte_flow_item_tag)), 139 MK_FLOW_ITEM(GRE_KEY, sizeof(rte_be32_t)), 140 MK_FLOW_ITEM(GTP_PSC, sizeof(struct rte_flow_item_gtp_psc)), 141 MK_FLOW_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)), 142 MK_FLOW_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)), 143 MK_FLOW_ITEM(PPPOE_PROTO_ID, 144 sizeof(struct rte_flow_item_pppoe_proto_id)), 145 MK_FLOW_ITEM(NSH, sizeof(struct rte_flow_item_nsh)), 146 MK_FLOW_ITEM(IGMP, sizeof(struct rte_flow_item_igmp)), 147 MK_FLOW_ITEM(AH, sizeof(struct rte_flow_item_ah)), 148 MK_FLOW_ITEM(HIGIG2, sizeof(struct rte_flow_item_higig2_hdr)), 149 MK_FLOW_ITEM(L2TPV3OIP, sizeof(struct rte_flow_item_l2tpv3oip)), 150 MK_FLOW_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)), 151 MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)), 152 MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)), 153 MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)), 154 MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)), 155 MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)), 156 MK_FLOW_ITEM(REPRESENTED_PORT, sizeof(struct rte_flow_item_ethdev)), 157 MK_FLOW_ITEM_FN(FLEX, sizeof(struct rte_flow_item_flex), 158 rte_flow_item_flex_conv), 159 MK_FLOW_ITEM(L2TPV2, sizeof(struct rte_flow_item_l2tpv2)), 160 MK_FLOW_ITEM(PPP, sizeof(struct rte_flow_item_ppp)), 161 }; 162 163 /** Generate flow_action[] entry. */ 164 #define MK_FLOW_ACTION(t, s) \ 165 [RTE_FLOW_ACTION_TYPE_ ## t] = { \ 166 .name = # t, \ 167 .size = s, \ 168 .desc_fn = NULL,\ 169 } 170 171 #define MK_FLOW_ACTION_FN(t, fn) \ 172 [RTE_FLOW_ACTION_TYPE_ ## t] = { \ 173 .name = # t, \ 174 .size = 0, \ 175 .desc_fn = fn,\ 176 } 177 178 179 /** Information about known flow actions. */ 180 static const struct rte_flow_desc_data rte_flow_desc_action[] = { 181 MK_FLOW_ACTION(END, 0), 182 MK_FLOW_ACTION(VOID, 0), 183 MK_FLOW_ACTION(PASSTHRU, 0), 184 MK_FLOW_ACTION(JUMP, sizeof(struct rte_flow_action_jump)), 185 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)), 186 MK_FLOW_ACTION(FLAG, 0), 187 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)), 188 MK_FLOW_ACTION(DROP, 0), 189 MK_FLOW_ACTION(COUNT, sizeof(struct rte_flow_action_count)), 190 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), 191 MK_FLOW_ACTION(PF, 0), 192 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)), 193 MK_FLOW_ACTION(PHY_PORT, sizeof(struct rte_flow_action_phy_port)), 194 MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)), 195 MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)), 196 MK_FLOW_ACTION(SECURITY, sizeof(struct rte_flow_action_security)), 197 MK_FLOW_ACTION(OF_SET_MPLS_TTL, 198 sizeof(struct rte_flow_action_of_set_mpls_ttl)), 199 MK_FLOW_ACTION(OF_DEC_MPLS_TTL, 0), 200 MK_FLOW_ACTION(OF_SET_NW_TTL, 201 sizeof(struct rte_flow_action_of_set_nw_ttl)), 202 MK_FLOW_ACTION(OF_DEC_NW_TTL, 0), 203 MK_FLOW_ACTION(OF_COPY_TTL_OUT, 0), 204 MK_FLOW_ACTION(OF_COPY_TTL_IN, 0), 205 MK_FLOW_ACTION(OF_POP_VLAN, 0), 206 MK_FLOW_ACTION(OF_PUSH_VLAN, 207 sizeof(struct rte_flow_action_of_push_vlan)), 208 MK_FLOW_ACTION(OF_SET_VLAN_VID, 209 sizeof(struct rte_flow_action_of_set_vlan_vid)), 210 MK_FLOW_ACTION(OF_SET_VLAN_PCP, 211 sizeof(struct rte_flow_action_of_set_vlan_pcp)), 212 MK_FLOW_ACTION(OF_POP_MPLS, 213 sizeof(struct rte_flow_action_of_pop_mpls)), 214 MK_FLOW_ACTION(OF_PUSH_MPLS, 215 sizeof(struct rte_flow_action_of_push_mpls)), 216 MK_FLOW_ACTION(VXLAN_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)), 217 MK_FLOW_ACTION(VXLAN_DECAP, 0), 218 MK_FLOW_ACTION(NVGRE_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)), 219 MK_FLOW_ACTION(NVGRE_DECAP, 0), 220 MK_FLOW_ACTION(RAW_ENCAP, sizeof(struct rte_flow_action_raw_encap)), 221 MK_FLOW_ACTION(RAW_DECAP, sizeof(struct rte_flow_action_raw_decap)), 222 MK_FLOW_ACTION(SET_IPV4_SRC, 223 sizeof(struct rte_flow_action_set_ipv4)), 224 MK_FLOW_ACTION(SET_IPV4_DST, 225 sizeof(struct rte_flow_action_set_ipv4)), 226 MK_FLOW_ACTION(SET_IPV6_SRC, 227 sizeof(struct rte_flow_action_set_ipv6)), 228 MK_FLOW_ACTION(SET_IPV6_DST, 229 sizeof(struct rte_flow_action_set_ipv6)), 230 MK_FLOW_ACTION(SET_TP_SRC, 231 sizeof(struct rte_flow_action_set_tp)), 232 MK_FLOW_ACTION(SET_TP_DST, 233 sizeof(struct rte_flow_action_set_tp)), 234 MK_FLOW_ACTION(MAC_SWAP, 0), 235 MK_FLOW_ACTION(DEC_TTL, 0), 236 MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)), 237 MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)), 238 MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)), 239 MK_FLOW_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)), 240 MK_FLOW_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)), 241 MK_FLOW_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)), 242 MK_FLOW_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)), 243 MK_FLOW_ACTION(SET_TAG, sizeof(struct rte_flow_action_set_tag)), 244 MK_FLOW_ACTION(SET_META, sizeof(struct rte_flow_action_set_meta)), 245 MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)), 246 MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)), 247 MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)), 248 MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), 249 MK_FLOW_ACTION(MODIFY_FIELD, 250 sizeof(struct rte_flow_action_modify_field)), 251 /** 252 * Indirect action represented as handle of type 253 * (struct rte_flow_action_handle *) stored in conf field (see 254 * struct rte_flow_action); no need for additional structure to * store 255 * indirect action handle. 256 */ 257 MK_FLOW_ACTION(INDIRECT, 0), 258 MK_FLOW_ACTION(CONNTRACK, sizeof(struct rte_flow_action_conntrack)), 259 MK_FLOW_ACTION(PORT_REPRESENTOR, sizeof(struct rte_flow_action_ethdev)), 260 MK_FLOW_ACTION(REPRESENTED_PORT, sizeof(struct rte_flow_action_ethdev)), 261 }; 262 263 int 264 rte_flow_dynf_metadata_register(void) 265 { 266 int offset; 267 int flag; 268 269 static const struct rte_mbuf_dynfield desc_offs = { 270 .name = RTE_MBUF_DYNFIELD_METADATA_NAME, 271 .size = sizeof(uint32_t), 272 .align = __alignof__(uint32_t), 273 }; 274 static const struct rte_mbuf_dynflag desc_flag = { 275 .name = RTE_MBUF_DYNFLAG_METADATA_NAME, 276 }; 277 278 offset = rte_mbuf_dynfield_register(&desc_offs); 279 if (offset < 0) 280 goto error; 281 flag = rte_mbuf_dynflag_register(&desc_flag); 282 if (flag < 0) 283 goto error; 284 rte_flow_dynf_metadata_offs = offset; 285 rte_flow_dynf_metadata_mask = RTE_BIT64(flag); 286 return 0; 287 288 error: 289 rte_flow_dynf_metadata_offs = -1; 290 rte_flow_dynf_metadata_mask = UINT64_C(0); 291 return -rte_errno; 292 } 293 294 static inline void 295 fts_enter(struct rte_eth_dev *dev) 296 { 297 if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE)) 298 pthread_mutex_lock(&dev->data->flow_ops_mutex); 299 } 300 301 static inline void 302 fts_exit(struct rte_eth_dev *dev) 303 { 304 if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE)) 305 pthread_mutex_unlock(&dev->data->flow_ops_mutex); 306 } 307 308 static int 309 flow_err(uint16_t port_id, int ret, struct rte_flow_error *error) 310 { 311 if (ret == 0) 312 return 0; 313 if (rte_eth_dev_is_removed(port_id)) 314 return rte_flow_error_set(error, EIO, 315 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 316 NULL, rte_strerror(EIO)); 317 return ret; 318 } 319 320 /* Get generic flow operations structure from a port. */ 321 const struct rte_flow_ops * 322 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error) 323 { 324 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 325 const struct rte_flow_ops *ops; 326 int code; 327 328 if (unlikely(!rte_eth_dev_is_valid_port(port_id))) 329 code = ENODEV; 330 else if (unlikely(dev->dev_ops->flow_ops_get == NULL)) 331 /* flow API not supported with this driver dev_ops */ 332 code = ENOSYS; 333 else 334 code = dev->dev_ops->flow_ops_get(dev, &ops); 335 if (code == 0 && ops == NULL) 336 /* flow API not supported with this device */ 337 code = ENOSYS; 338 339 if (code != 0) { 340 rte_flow_error_set(error, code, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 341 NULL, rte_strerror(code)); 342 return NULL; 343 } 344 return ops; 345 } 346 347 /* Check whether a flow rule can be created on a given port. */ 348 int 349 rte_flow_validate(uint16_t port_id, 350 const struct rte_flow_attr *attr, 351 const struct rte_flow_item pattern[], 352 const struct rte_flow_action actions[], 353 struct rte_flow_error *error) 354 { 355 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 356 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 357 int ret; 358 359 if (unlikely(!ops)) 360 return -rte_errno; 361 if (likely(!!ops->validate)) { 362 fts_enter(dev); 363 ret = ops->validate(dev, attr, pattern, actions, error); 364 fts_exit(dev); 365 return flow_err(port_id, ret, error); 366 } 367 return rte_flow_error_set(error, ENOSYS, 368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 369 NULL, rte_strerror(ENOSYS)); 370 } 371 372 /* Create a flow rule on a given port. */ 373 struct rte_flow * 374 rte_flow_create(uint16_t port_id, 375 const struct rte_flow_attr *attr, 376 const struct rte_flow_item pattern[], 377 const struct rte_flow_action actions[], 378 struct rte_flow_error *error) 379 { 380 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 381 struct rte_flow *flow; 382 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 383 384 if (unlikely(!ops)) 385 return NULL; 386 if (likely(!!ops->create)) { 387 fts_enter(dev); 388 flow = ops->create(dev, attr, pattern, actions, error); 389 fts_exit(dev); 390 if (flow == NULL) 391 flow_err(port_id, -rte_errno, error); 392 return flow; 393 } 394 rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 395 NULL, rte_strerror(ENOSYS)); 396 return NULL; 397 } 398 399 /* Destroy a flow rule on a given port. */ 400 int 401 rte_flow_destroy(uint16_t port_id, 402 struct rte_flow *flow, 403 struct rte_flow_error *error) 404 { 405 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 406 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 407 int ret; 408 409 if (unlikely(!ops)) 410 return -rte_errno; 411 if (likely(!!ops->destroy)) { 412 fts_enter(dev); 413 ret = ops->destroy(dev, flow, error); 414 fts_exit(dev); 415 return flow_err(port_id, ret, error); 416 } 417 return rte_flow_error_set(error, ENOSYS, 418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 419 NULL, rte_strerror(ENOSYS)); 420 } 421 422 /* Destroy all flow rules associated with a port. */ 423 int 424 rte_flow_flush(uint16_t port_id, 425 struct rte_flow_error *error) 426 { 427 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 428 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 429 int ret; 430 431 if (unlikely(!ops)) 432 return -rte_errno; 433 if (likely(!!ops->flush)) { 434 fts_enter(dev); 435 ret = ops->flush(dev, error); 436 fts_exit(dev); 437 return flow_err(port_id, ret, error); 438 } 439 return rte_flow_error_set(error, ENOSYS, 440 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 441 NULL, rte_strerror(ENOSYS)); 442 } 443 444 /* Query an existing flow rule. */ 445 int 446 rte_flow_query(uint16_t port_id, 447 struct rte_flow *flow, 448 const struct rte_flow_action *action, 449 void *data, 450 struct rte_flow_error *error) 451 { 452 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 453 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 454 int ret; 455 456 if (!ops) 457 return -rte_errno; 458 if (likely(!!ops->query)) { 459 fts_enter(dev); 460 ret = ops->query(dev, flow, action, data, error); 461 fts_exit(dev); 462 return flow_err(port_id, ret, error); 463 } 464 return rte_flow_error_set(error, ENOSYS, 465 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 466 NULL, rte_strerror(ENOSYS)); 467 } 468 469 /* Restrict ingress traffic to the defined flow rules. */ 470 int 471 rte_flow_isolate(uint16_t port_id, 472 int set, 473 struct rte_flow_error *error) 474 { 475 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 476 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 477 int ret; 478 479 if (!ops) 480 return -rte_errno; 481 if (likely(!!ops->isolate)) { 482 fts_enter(dev); 483 ret = ops->isolate(dev, set, error); 484 fts_exit(dev); 485 return flow_err(port_id, ret, error); 486 } 487 return rte_flow_error_set(error, ENOSYS, 488 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 489 NULL, rte_strerror(ENOSYS)); 490 } 491 492 /* Initialize flow error structure. */ 493 int 494 rte_flow_error_set(struct rte_flow_error *error, 495 int code, 496 enum rte_flow_error_type type, 497 const void *cause, 498 const char *message) 499 { 500 if (error) { 501 *error = (struct rte_flow_error){ 502 .type = type, 503 .cause = cause, 504 .message = message, 505 }; 506 } 507 rte_errno = code; 508 return -code; 509 } 510 511 /** Pattern item specification types. */ 512 enum rte_flow_conv_item_spec_type { 513 RTE_FLOW_CONV_ITEM_SPEC, 514 RTE_FLOW_CONV_ITEM_LAST, 515 RTE_FLOW_CONV_ITEM_MASK, 516 }; 517 518 /** 519 * Copy pattern item specification. 520 * 521 * @param[out] buf 522 * Output buffer. Can be NULL if @p size is zero. 523 * @param size 524 * Size of @p buf in bytes. 525 * @param[in] item 526 * Pattern item to copy specification from. 527 * @param type 528 * Specification selector for either @p spec, @p last or @p mask. 529 * 530 * @return 531 * Number of bytes needed to store pattern item specification regardless 532 * of @p size. @p buf contents are truncated to @p size if not large 533 * enough. 534 */ 535 static size_t 536 rte_flow_conv_item_spec(void *buf, const size_t size, 537 const struct rte_flow_item *item, 538 enum rte_flow_conv_item_spec_type type) 539 { 540 size_t off; 541 const void *data = 542 type == RTE_FLOW_CONV_ITEM_SPEC ? item->spec : 543 type == RTE_FLOW_CONV_ITEM_LAST ? item->last : 544 type == RTE_FLOW_CONV_ITEM_MASK ? item->mask : 545 NULL; 546 547 switch (item->type) { 548 union { 549 const struct rte_flow_item_raw *raw; 550 } spec; 551 union { 552 const struct rte_flow_item_raw *raw; 553 } last; 554 union { 555 const struct rte_flow_item_raw *raw; 556 } mask; 557 union { 558 const struct rte_flow_item_raw *raw; 559 } src; 560 union { 561 struct rte_flow_item_raw *raw; 562 } dst; 563 size_t tmp; 564 565 case RTE_FLOW_ITEM_TYPE_RAW: 566 spec.raw = item->spec; 567 last.raw = item->last ? item->last : item->spec; 568 mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask; 569 src.raw = data; 570 dst.raw = buf; 571 rte_memcpy(dst.raw, 572 (&(struct rte_flow_item_raw){ 573 .relative = src.raw->relative, 574 .search = src.raw->search, 575 .reserved = src.raw->reserved, 576 .offset = src.raw->offset, 577 .limit = src.raw->limit, 578 .length = src.raw->length, 579 }), 580 size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size); 581 off = sizeof(*dst.raw); 582 if (type == RTE_FLOW_CONV_ITEM_SPEC || 583 (type == RTE_FLOW_CONV_ITEM_MASK && 584 ((spec.raw->length & mask.raw->length) >= 585 (last.raw->length & mask.raw->length)))) 586 tmp = spec.raw->length & mask.raw->length; 587 else 588 tmp = last.raw->length & mask.raw->length; 589 if (tmp) { 590 off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern)); 591 if (size >= off + tmp) 592 dst.raw->pattern = rte_memcpy 593 ((void *)((uintptr_t)dst.raw + off), 594 src.raw->pattern, tmp); 595 off += tmp; 596 } 597 break; 598 default: 599 off = rte_flow_conv_copy(buf, data, size, 600 rte_flow_desc_item, item->type); 601 break; 602 } 603 return off; 604 } 605 606 /** 607 * Copy action configuration. 608 * 609 * @param[out] buf 610 * Output buffer. Can be NULL if @p size is zero. 611 * @param size 612 * Size of @p buf in bytes. 613 * @param[in] action 614 * Action to copy configuration from. 615 * 616 * @return 617 * Number of bytes needed to store pattern item specification regardless 618 * of @p size. @p buf contents are truncated to @p size if not large 619 * enough. 620 */ 621 static size_t 622 rte_flow_conv_action_conf(void *buf, const size_t size, 623 const struct rte_flow_action *action) 624 { 625 size_t off; 626 627 switch (action->type) { 628 union { 629 const struct rte_flow_action_rss *rss; 630 const struct rte_flow_action_vxlan_encap *vxlan_encap; 631 const struct rte_flow_action_nvgre_encap *nvgre_encap; 632 } src; 633 union { 634 struct rte_flow_action_rss *rss; 635 struct rte_flow_action_vxlan_encap *vxlan_encap; 636 struct rte_flow_action_nvgre_encap *nvgre_encap; 637 } dst; 638 size_t tmp; 639 int ret; 640 641 case RTE_FLOW_ACTION_TYPE_RSS: 642 src.rss = action->conf; 643 dst.rss = buf; 644 rte_memcpy(dst.rss, 645 (&(struct rte_flow_action_rss){ 646 .func = src.rss->func, 647 .level = src.rss->level, 648 .types = src.rss->types, 649 .key_len = src.rss->key_len, 650 .queue_num = src.rss->queue_num, 651 }), 652 size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size); 653 off = sizeof(*dst.rss); 654 if (src.rss->key_len && src.rss->key) { 655 off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key)); 656 tmp = sizeof(*src.rss->key) * src.rss->key_len; 657 if (size >= off + tmp) 658 dst.rss->key = rte_memcpy 659 ((void *)((uintptr_t)dst.rss + off), 660 src.rss->key, tmp); 661 off += tmp; 662 } 663 if (src.rss->queue_num) { 664 off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue)); 665 tmp = sizeof(*src.rss->queue) * src.rss->queue_num; 666 if (size >= off + tmp) 667 dst.rss->queue = rte_memcpy 668 ((void *)((uintptr_t)dst.rss + off), 669 src.rss->queue, tmp); 670 off += tmp; 671 } 672 break; 673 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP: 674 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP: 675 src.vxlan_encap = action->conf; 676 dst.vxlan_encap = buf; 677 RTE_BUILD_BUG_ON(sizeof(*src.vxlan_encap) != 678 sizeof(*src.nvgre_encap) || 679 offsetof(struct rte_flow_action_vxlan_encap, 680 definition) != 681 offsetof(struct rte_flow_action_nvgre_encap, 682 definition)); 683 off = sizeof(*dst.vxlan_encap); 684 if (src.vxlan_encap->definition) { 685 off = RTE_ALIGN_CEIL 686 (off, sizeof(*dst.vxlan_encap->definition)); 687 ret = rte_flow_conv 688 (RTE_FLOW_CONV_OP_PATTERN, 689 (void *)((uintptr_t)dst.vxlan_encap + off), 690 size > off ? size - off : 0, 691 src.vxlan_encap->definition, NULL); 692 if (ret < 0) 693 return 0; 694 if (size >= off + ret) 695 dst.vxlan_encap->definition = 696 (void *)((uintptr_t)dst.vxlan_encap + 697 off); 698 off += ret; 699 } 700 break; 701 default: 702 off = rte_flow_conv_copy(buf, action->conf, size, 703 rte_flow_desc_action, action->type); 704 break; 705 } 706 return off; 707 } 708 709 /** 710 * Copy a list of pattern items. 711 * 712 * @param[out] dst 713 * Destination buffer. Can be NULL if @p size is zero. 714 * @param size 715 * Size of @p dst in bytes. 716 * @param[in] src 717 * Source pattern items. 718 * @param num 719 * Maximum number of pattern items to process from @p src or 0 to process 720 * the entire list. In both cases, processing stops after 721 * RTE_FLOW_ITEM_TYPE_END is encountered. 722 * @param[out] error 723 * Perform verbose error reporting if not NULL. 724 * 725 * @return 726 * A positive value representing the number of bytes needed to store 727 * pattern items regardless of @p size on success (@p buf contents are 728 * truncated to @p size if not large enough), a negative errno value 729 * otherwise and rte_errno is set. 730 */ 731 static int 732 rte_flow_conv_pattern(struct rte_flow_item *dst, 733 const size_t size, 734 const struct rte_flow_item *src, 735 unsigned int num, 736 struct rte_flow_error *error) 737 { 738 uintptr_t data = (uintptr_t)dst; 739 size_t off; 740 size_t ret; 741 unsigned int i; 742 743 for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) { 744 /** 745 * allow PMD private flow item 746 */ 747 if (((int)src->type >= 0) && 748 ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) || 749 !rte_flow_desc_item[src->type].name)) 750 return rte_flow_error_set 751 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src, 752 "cannot convert unknown item type"); 753 if (size >= off + sizeof(*dst)) 754 *dst = (struct rte_flow_item){ 755 .type = src->type, 756 }; 757 off += sizeof(*dst); 758 if (!src->type) 759 num = i + 1; 760 } 761 num = i; 762 src -= num; 763 dst -= num; 764 do { 765 if (src->spec) { 766 off = RTE_ALIGN_CEIL(off, sizeof(double)); 767 ret = rte_flow_conv_item_spec 768 ((void *)(data + off), 769 size > off ? size - off : 0, src, 770 RTE_FLOW_CONV_ITEM_SPEC); 771 if (size && size >= off + ret) 772 dst->spec = (void *)(data + off); 773 off += ret; 774 775 } 776 if (src->last) { 777 off = RTE_ALIGN_CEIL(off, sizeof(double)); 778 ret = rte_flow_conv_item_spec 779 ((void *)(data + off), 780 size > off ? size - off : 0, src, 781 RTE_FLOW_CONV_ITEM_LAST); 782 if (size && size >= off + ret) 783 dst->last = (void *)(data + off); 784 off += ret; 785 } 786 if (src->mask) { 787 off = RTE_ALIGN_CEIL(off, sizeof(double)); 788 ret = rte_flow_conv_item_spec 789 ((void *)(data + off), 790 size > off ? size - off : 0, src, 791 RTE_FLOW_CONV_ITEM_MASK); 792 if (size && size >= off + ret) 793 dst->mask = (void *)(data + off); 794 off += ret; 795 } 796 ++src; 797 ++dst; 798 } while (--num); 799 return off; 800 } 801 802 /** 803 * Copy a list of actions. 804 * 805 * @param[out] dst 806 * Destination buffer. Can be NULL if @p size is zero. 807 * @param size 808 * Size of @p dst in bytes. 809 * @param[in] src 810 * Source actions. 811 * @param num 812 * Maximum number of actions to process from @p src or 0 to process the 813 * entire list. In both cases, processing stops after 814 * RTE_FLOW_ACTION_TYPE_END is encountered. 815 * @param[out] error 816 * Perform verbose error reporting if not NULL. 817 * 818 * @return 819 * A positive value representing the number of bytes needed to store 820 * actions regardless of @p size on success (@p buf contents are truncated 821 * to @p size if not large enough), a negative errno value otherwise and 822 * rte_errno is set. 823 */ 824 static int 825 rte_flow_conv_actions(struct rte_flow_action *dst, 826 const size_t size, 827 const struct rte_flow_action *src, 828 unsigned int num, 829 struct rte_flow_error *error) 830 { 831 uintptr_t data = (uintptr_t)dst; 832 size_t off; 833 size_t ret; 834 unsigned int i; 835 836 for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) { 837 /** 838 * allow PMD private flow action 839 */ 840 if (((int)src->type >= 0) && 841 ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) || 842 !rte_flow_desc_action[src->type].name)) 843 return rte_flow_error_set 844 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, 845 src, "cannot convert unknown action type"); 846 if (size >= off + sizeof(*dst)) 847 *dst = (struct rte_flow_action){ 848 .type = src->type, 849 }; 850 off += sizeof(*dst); 851 if (!src->type) 852 num = i + 1; 853 } 854 num = i; 855 src -= num; 856 dst -= num; 857 do { 858 if (src->conf) { 859 off = RTE_ALIGN_CEIL(off, sizeof(double)); 860 ret = rte_flow_conv_action_conf 861 ((void *)(data + off), 862 size > off ? size - off : 0, src); 863 if (size && size >= off + ret) 864 dst->conf = (void *)(data + off); 865 off += ret; 866 } 867 ++src; 868 ++dst; 869 } while (--num); 870 return off; 871 } 872 873 /** 874 * Copy flow rule components. 875 * 876 * This comprises the flow rule descriptor itself, attributes, pattern and 877 * actions list. NULL components in @p src are skipped. 878 * 879 * @param[out] dst 880 * Destination buffer. Can be NULL if @p size is zero. 881 * @param size 882 * Size of @p dst in bytes. 883 * @param[in] src 884 * Source flow rule descriptor. 885 * @param[out] error 886 * Perform verbose error reporting if not NULL. 887 * 888 * @return 889 * A positive value representing the number of bytes needed to store all 890 * components including the descriptor regardless of @p size on success 891 * (@p buf contents are truncated to @p size if not large enough), a 892 * negative errno value otherwise and rte_errno is set. 893 */ 894 static int 895 rte_flow_conv_rule(struct rte_flow_conv_rule *dst, 896 const size_t size, 897 const struct rte_flow_conv_rule *src, 898 struct rte_flow_error *error) 899 { 900 size_t off; 901 int ret; 902 903 rte_memcpy(dst, 904 (&(struct rte_flow_conv_rule){ 905 .attr = NULL, 906 .pattern = NULL, 907 .actions = NULL, 908 }), 909 size > sizeof(*dst) ? sizeof(*dst) : size); 910 off = sizeof(*dst); 911 if (src->attr_ro) { 912 off = RTE_ALIGN_CEIL(off, sizeof(double)); 913 if (size && size >= off + sizeof(*dst->attr)) 914 dst->attr = rte_memcpy 915 ((void *)((uintptr_t)dst + off), 916 src->attr_ro, sizeof(*dst->attr)); 917 off += sizeof(*dst->attr); 918 } 919 if (src->pattern_ro) { 920 off = RTE_ALIGN_CEIL(off, sizeof(double)); 921 ret = rte_flow_conv_pattern((void *)((uintptr_t)dst + off), 922 size > off ? size - off : 0, 923 src->pattern_ro, 0, error); 924 if (ret < 0) 925 return ret; 926 if (size && size >= off + (size_t)ret) 927 dst->pattern = (void *)((uintptr_t)dst + off); 928 off += ret; 929 } 930 if (src->actions_ro) { 931 off = RTE_ALIGN_CEIL(off, sizeof(double)); 932 ret = rte_flow_conv_actions((void *)((uintptr_t)dst + off), 933 size > off ? size - off : 0, 934 src->actions_ro, 0, error); 935 if (ret < 0) 936 return ret; 937 if (size >= off + (size_t)ret) 938 dst->actions = (void *)((uintptr_t)dst + off); 939 off += ret; 940 } 941 return off; 942 } 943 944 /** 945 * Retrieve the name of a pattern item/action type. 946 * 947 * @param is_action 948 * Nonzero when @p src represents an action type instead of a pattern item 949 * type. 950 * @param is_ptr 951 * Nonzero to write string address instead of contents into @p dst. 952 * @param[out] dst 953 * Destination buffer. Can be NULL if @p size is zero. 954 * @param size 955 * Size of @p dst in bytes. 956 * @param[in] src 957 * Depending on @p is_action, source pattern item or action type cast as a 958 * pointer. 959 * @param[out] error 960 * Perform verbose error reporting if not NULL. 961 * 962 * @return 963 * A positive value representing the number of bytes needed to store the 964 * name or its address regardless of @p size on success (@p buf contents 965 * are truncated to @p size if not large enough), a negative errno value 966 * otherwise and rte_errno is set. 967 */ 968 static int 969 rte_flow_conv_name(int is_action, 970 int is_ptr, 971 char *dst, 972 const size_t size, 973 const void *src, 974 struct rte_flow_error *error) 975 { 976 struct desc_info { 977 const struct rte_flow_desc_data *data; 978 size_t num; 979 }; 980 static const struct desc_info info_rep[2] = { 981 { rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), }, 982 { rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), }, 983 }; 984 const struct desc_info *const info = &info_rep[!!is_action]; 985 unsigned int type = (uintptr_t)src; 986 987 if (type >= info->num) 988 return rte_flow_error_set 989 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 990 "unknown object type to retrieve the name of"); 991 if (!is_ptr) 992 return strlcpy(dst, info->data[type].name, size); 993 if (size >= sizeof(const char **)) 994 *((const char **)dst) = info->data[type].name; 995 return sizeof(const char **); 996 } 997 998 /** Helper function to convert flow API objects. */ 999 int 1000 rte_flow_conv(enum rte_flow_conv_op op, 1001 void *dst, 1002 size_t size, 1003 const void *src, 1004 struct rte_flow_error *error) 1005 { 1006 switch (op) { 1007 const struct rte_flow_attr *attr; 1008 1009 case RTE_FLOW_CONV_OP_NONE: 1010 return 0; 1011 case RTE_FLOW_CONV_OP_ATTR: 1012 attr = src; 1013 if (size > sizeof(*attr)) 1014 size = sizeof(*attr); 1015 rte_memcpy(dst, attr, size); 1016 return sizeof(*attr); 1017 case RTE_FLOW_CONV_OP_ITEM: 1018 return rte_flow_conv_pattern(dst, size, src, 1, error); 1019 case RTE_FLOW_CONV_OP_ACTION: 1020 return rte_flow_conv_actions(dst, size, src, 1, error); 1021 case RTE_FLOW_CONV_OP_PATTERN: 1022 return rte_flow_conv_pattern(dst, size, src, 0, error); 1023 case RTE_FLOW_CONV_OP_ACTIONS: 1024 return rte_flow_conv_actions(dst, size, src, 0, error); 1025 case RTE_FLOW_CONV_OP_RULE: 1026 return rte_flow_conv_rule(dst, size, src, error); 1027 case RTE_FLOW_CONV_OP_ITEM_NAME: 1028 return rte_flow_conv_name(0, 0, dst, size, src, error); 1029 case RTE_FLOW_CONV_OP_ACTION_NAME: 1030 return rte_flow_conv_name(1, 0, dst, size, src, error); 1031 case RTE_FLOW_CONV_OP_ITEM_NAME_PTR: 1032 return rte_flow_conv_name(0, 1, dst, size, src, error); 1033 case RTE_FLOW_CONV_OP_ACTION_NAME_PTR: 1034 return rte_flow_conv_name(1, 1, dst, size, src, error); 1035 } 1036 return rte_flow_error_set 1037 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 1038 "unknown object conversion operation"); 1039 } 1040 1041 /** Store a full rte_flow description. */ 1042 size_t 1043 rte_flow_copy(struct rte_flow_desc *desc, size_t len, 1044 const struct rte_flow_attr *attr, 1045 const struct rte_flow_item *items, 1046 const struct rte_flow_action *actions) 1047 { 1048 /* 1049 * Overlap struct rte_flow_conv with struct rte_flow_desc in order 1050 * to convert the former to the latter without wasting space. 1051 */ 1052 struct rte_flow_conv_rule *dst = 1053 len ? 1054 (void *)((uintptr_t)desc + 1055 (offsetof(struct rte_flow_desc, actions) - 1056 offsetof(struct rte_flow_conv_rule, actions))) : 1057 NULL; 1058 size_t dst_size = 1059 len > sizeof(*desc) - sizeof(*dst) ? 1060 len - (sizeof(*desc) - sizeof(*dst)) : 1061 0; 1062 struct rte_flow_conv_rule src = { 1063 .attr_ro = NULL, 1064 .pattern_ro = items, 1065 .actions_ro = actions, 1066 }; 1067 int ret; 1068 1069 RTE_BUILD_BUG_ON(sizeof(struct rte_flow_desc) < 1070 sizeof(struct rte_flow_conv_rule)); 1071 if (dst_size && 1072 (&dst->pattern != &desc->items || 1073 &dst->actions != &desc->actions || 1074 (uintptr_t)(dst + 1) != (uintptr_t)(desc + 1))) { 1075 rte_errno = EINVAL; 1076 return 0; 1077 } 1078 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, dst, dst_size, &src, NULL); 1079 if (ret < 0) 1080 return 0; 1081 ret += sizeof(*desc) - sizeof(*dst); 1082 rte_memcpy(desc, 1083 (&(struct rte_flow_desc){ 1084 .size = ret, 1085 .attr = *attr, 1086 .items = dst_size ? dst->pattern : NULL, 1087 .actions = dst_size ? dst->actions : NULL, 1088 }), 1089 len > sizeof(*desc) ? sizeof(*desc) : len); 1090 return ret; 1091 } 1092 1093 int 1094 rte_flow_dev_dump(uint16_t port_id, struct rte_flow *flow, 1095 FILE *file, struct rte_flow_error *error) 1096 { 1097 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1098 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1099 int ret; 1100 1101 if (unlikely(!ops)) 1102 return -rte_errno; 1103 if (likely(!!ops->dev_dump)) { 1104 fts_enter(dev); 1105 ret = ops->dev_dump(dev, flow, file, error); 1106 fts_exit(dev); 1107 return flow_err(port_id, ret, error); 1108 } 1109 return rte_flow_error_set(error, ENOSYS, 1110 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1111 NULL, rte_strerror(ENOSYS)); 1112 } 1113 1114 int 1115 rte_flow_get_aged_flows(uint16_t port_id, void **contexts, 1116 uint32_t nb_contexts, struct rte_flow_error *error) 1117 { 1118 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1119 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1120 int ret; 1121 1122 if (unlikely(!ops)) 1123 return -rte_errno; 1124 if (likely(!!ops->get_aged_flows)) { 1125 fts_enter(dev); 1126 ret = ops->get_aged_flows(dev, contexts, nb_contexts, error); 1127 fts_exit(dev); 1128 return flow_err(port_id, ret, error); 1129 } 1130 return rte_flow_error_set(error, ENOTSUP, 1131 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1132 NULL, rte_strerror(ENOTSUP)); 1133 } 1134 1135 struct rte_flow_action_handle * 1136 rte_flow_action_handle_create(uint16_t port_id, 1137 const struct rte_flow_indir_action_conf *conf, 1138 const struct rte_flow_action *action, 1139 struct rte_flow_error *error) 1140 { 1141 struct rte_flow_action_handle *handle; 1142 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1143 1144 if (unlikely(!ops)) 1145 return NULL; 1146 if (unlikely(!ops->action_handle_create)) { 1147 rte_flow_error_set(error, ENOSYS, 1148 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 1149 rte_strerror(ENOSYS)); 1150 return NULL; 1151 } 1152 handle = ops->action_handle_create(&rte_eth_devices[port_id], 1153 conf, action, error); 1154 if (handle == NULL) 1155 flow_err(port_id, -rte_errno, error); 1156 return handle; 1157 } 1158 1159 int 1160 rte_flow_action_handle_destroy(uint16_t port_id, 1161 struct rte_flow_action_handle *handle, 1162 struct rte_flow_error *error) 1163 { 1164 int ret; 1165 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1166 1167 if (unlikely(!ops)) 1168 return -rte_errno; 1169 if (unlikely(!ops->action_handle_destroy)) 1170 return rte_flow_error_set(error, ENOSYS, 1171 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1172 NULL, rte_strerror(ENOSYS)); 1173 ret = ops->action_handle_destroy(&rte_eth_devices[port_id], 1174 handle, error); 1175 return flow_err(port_id, ret, error); 1176 } 1177 1178 int 1179 rte_flow_action_handle_update(uint16_t port_id, 1180 struct rte_flow_action_handle *handle, 1181 const void *update, 1182 struct rte_flow_error *error) 1183 { 1184 int ret; 1185 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1186 1187 if (unlikely(!ops)) 1188 return -rte_errno; 1189 if (unlikely(!ops->action_handle_update)) 1190 return rte_flow_error_set(error, ENOSYS, 1191 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1192 NULL, rte_strerror(ENOSYS)); 1193 ret = ops->action_handle_update(&rte_eth_devices[port_id], handle, 1194 update, error); 1195 return flow_err(port_id, ret, error); 1196 } 1197 1198 int 1199 rte_flow_action_handle_query(uint16_t port_id, 1200 const struct rte_flow_action_handle *handle, 1201 void *data, 1202 struct rte_flow_error *error) 1203 { 1204 int ret; 1205 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1206 1207 if (unlikely(!ops)) 1208 return -rte_errno; 1209 if (unlikely(!ops->action_handle_query)) 1210 return rte_flow_error_set(error, ENOSYS, 1211 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1212 NULL, rte_strerror(ENOSYS)); 1213 ret = ops->action_handle_query(&rte_eth_devices[port_id], handle, 1214 data, error); 1215 return flow_err(port_id, ret, error); 1216 } 1217 1218 int 1219 rte_flow_tunnel_decap_set(uint16_t port_id, 1220 struct rte_flow_tunnel *tunnel, 1221 struct rte_flow_action **actions, 1222 uint32_t *num_of_actions, 1223 struct rte_flow_error *error) 1224 { 1225 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1226 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1227 1228 if (unlikely(!ops)) 1229 return -rte_errno; 1230 if (likely(!!ops->tunnel_decap_set)) { 1231 return flow_err(port_id, 1232 ops->tunnel_decap_set(dev, tunnel, actions, 1233 num_of_actions, error), 1234 error); 1235 } 1236 return rte_flow_error_set(error, ENOTSUP, 1237 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1238 NULL, rte_strerror(ENOTSUP)); 1239 } 1240 1241 int 1242 rte_flow_tunnel_match(uint16_t port_id, 1243 struct rte_flow_tunnel *tunnel, 1244 struct rte_flow_item **items, 1245 uint32_t *num_of_items, 1246 struct rte_flow_error *error) 1247 { 1248 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1249 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1250 1251 if (unlikely(!ops)) 1252 return -rte_errno; 1253 if (likely(!!ops->tunnel_match)) { 1254 return flow_err(port_id, 1255 ops->tunnel_match(dev, tunnel, items, 1256 num_of_items, error), 1257 error); 1258 } 1259 return rte_flow_error_set(error, ENOTSUP, 1260 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1261 NULL, rte_strerror(ENOTSUP)); 1262 } 1263 1264 int 1265 rte_flow_get_restore_info(uint16_t port_id, 1266 struct rte_mbuf *m, 1267 struct rte_flow_restore_info *restore_info, 1268 struct rte_flow_error *error) 1269 { 1270 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1271 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1272 1273 if (unlikely(!ops)) 1274 return -rte_errno; 1275 if (likely(!!ops->get_restore_info)) { 1276 return flow_err(port_id, 1277 ops->get_restore_info(dev, m, restore_info, 1278 error), 1279 error); 1280 } 1281 return rte_flow_error_set(error, ENOTSUP, 1282 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1283 NULL, rte_strerror(ENOTSUP)); 1284 } 1285 1286 int 1287 rte_flow_tunnel_action_decap_release(uint16_t port_id, 1288 struct rte_flow_action *actions, 1289 uint32_t num_of_actions, 1290 struct rte_flow_error *error) 1291 { 1292 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1293 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1294 1295 if (unlikely(!ops)) 1296 return -rte_errno; 1297 if (likely(!!ops->tunnel_action_decap_release)) { 1298 return flow_err(port_id, 1299 ops->tunnel_action_decap_release(dev, actions, 1300 num_of_actions, 1301 error), 1302 error); 1303 } 1304 return rte_flow_error_set(error, ENOTSUP, 1305 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1306 NULL, rte_strerror(ENOTSUP)); 1307 } 1308 1309 int 1310 rte_flow_tunnel_item_release(uint16_t port_id, 1311 struct rte_flow_item *items, 1312 uint32_t num_of_items, 1313 struct rte_flow_error *error) 1314 { 1315 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1316 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1317 1318 if (unlikely(!ops)) 1319 return -rte_errno; 1320 if (likely(!!ops->tunnel_item_release)) { 1321 return flow_err(port_id, 1322 ops->tunnel_item_release(dev, items, 1323 num_of_items, error), 1324 error); 1325 } 1326 return rte_flow_error_set(error, ENOTSUP, 1327 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1328 NULL, rte_strerror(ENOTSUP)); 1329 } 1330 1331 int 1332 rte_flow_pick_transfer_proxy(uint16_t port_id, uint16_t *proxy_port_id, 1333 struct rte_flow_error *error) 1334 { 1335 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1336 struct rte_eth_dev *dev; 1337 1338 if (unlikely(ops == NULL)) 1339 return -rte_errno; 1340 1341 if (ops->pick_transfer_proxy == NULL) { 1342 *proxy_port_id = port_id; 1343 return 0; 1344 } 1345 1346 dev = &rte_eth_devices[port_id]; 1347 1348 return flow_err(port_id, 1349 ops->pick_transfer_proxy(dev, proxy_port_id, error), 1350 error); 1351 } 1352 1353 struct rte_flow_item_flex_handle * 1354 rte_flow_flex_item_create(uint16_t port_id, 1355 const struct rte_flow_item_flex_conf *conf, 1356 struct rte_flow_error *error) 1357 { 1358 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1359 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1360 struct rte_flow_item_flex_handle *handle; 1361 1362 if (unlikely(!ops)) 1363 return NULL; 1364 if (unlikely(!ops->flex_item_create)) { 1365 rte_flow_error_set(error, ENOTSUP, 1366 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1367 NULL, rte_strerror(ENOTSUP)); 1368 return NULL; 1369 } 1370 handle = ops->flex_item_create(dev, conf, error); 1371 if (handle == NULL) 1372 flow_err(port_id, -rte_errno, error); 1373 return handle; 1374 } 1375 1376 int 1377 rte_flow_flex_item_release(uint16_t port_id, 1378 const struct rte_flow_item_flex_handle *handle, 1379 struct rte_flow_error *error) 1380 { 1381 int ret; 1382 struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 1383 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); 1384 1385 if (unlikely(!ops || !ops->flex_item_release)) 1386 return rte_flow_error_set(error, ENOTSUP, 1387 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, 1388 NULL, rte_strerror(ENOTSUP)); 1389 ret = ops->flex_item_release(dev, handle, error); 1390 return flow_err(port_id, ret, error); 1391 } 1392