1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
7 #include <rte_common.h>
8 #include <rte_byteorder.h>
9 #include <rte_cycles.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_ether.h>
17 #include <rte_cryptodev.h>
18 #include <rte_cryptodev_pmd.h>
20 #include "rte_table_action.h"
22 #define rte_htons rte_cpu_to_be_16
23 #define rte_htonl rte_cpu_to_be_32
25 #define rte_ntohs rte_be_to_cpu_16
26 #define rte_ntohl rte_be_to_cpu_32
29 * RTE_TABLE_ACTION_FWD
31 #define fwd_data rte_pipeline_table_entry
34 fwd_apply(struct fwd_data *data,
35 struct rte_table_action_fwd_params *p)
37 data->action = p->action;
39 if (p->action == RTE_PIPELINE_ACTION_PORT)
40 data->port_id = p->id;
42 if (p->action == RTE_PIPELINE_ACTION_TABLE)
43 data->table_id = p->id;
52 lb_cfg_check(struct rte_table_action_lb_config *cfg)
55 (cfg->key_size < RTE_TABLE_ACTION_LB_KEY_SIZE_MIN) ||
56 (cfg->key_size > RTE_TABLE_ACTION_LB_KEY_SIZE_MAX) ||
57 (!rte_is_power_of_2(cfg->key_size)) ||
58 (cfg->f_hash == NULL))
65 uint32_t out[RTE_TABLE_ACTION_LB_TABLE_SIZE];
66 } __attribute__((__packed__));
69 lb_apply(struct lb_data *data,
70 struct rte_table_action_lb_params *p)
72 memcpy(data->out, p->out, sizeof(data->out));
77 static __rte_always_inline void
78 pkt_work_lb(struct rte_mbuf *mbuf,
80 struct rte_table_action_lb_config *cfg)
82 uint8_t *pkt_key = RTE_MBUF_METADATA_UINT8_PTR(mbuf, cfg->key_offset);
83 uint32_t *out = RTE_MBUF_METADATA_UINT32_PTR(mbuf, cfg->out_offset);
87 digest = cfg->f_hash(pkt_key,
91 pos = digest & (RTE_TABLE_ACTION_LB_TABLE_SIZE - 1);
92 out_val = data->out[pos];
98 * RTE_TABLE_ACTION_MTR
101 mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
103 if ((mtr->alg == RTE_TABLE_ACTION_METER_SRTCM) ||
104 ((mtr->n_tc != 1) && (mtr->n_tc != 4)) ||
105 (mtr->n_bytes_enabled != 0))
110 #define MBUF_SCHED_QUEUE_TC_COLOR(queue, tc, color) \
111 ((uint16_t)((((uint64_t)(queue)) & 0x3) | \
112 ((((uint64_t)(tc)) & 0x3) << 2) | \
113 ((((uint64_t)(color)) & 0x3) << 4)))
115 #define MBUF_SCHED_COLOR(sched, color) \
116 (((sched) & (~0x30LLU)) | ((color) << 4))
118 struct mtr_trtcm_data {
119 struct rte_meter_trtcm trtcm;
120 uint64_t stats[e_RTE_METER_COLORS];
121 } __attribute__((__packed__));
123 #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data) \
124 (((data)->stats[e_RTE_METER_GREEN] & 0xF8LLU) >> 3)
127 mtr_trtcm_data_meter_profile_id_set(struct mtr_trtcm_data *data,
130 data->stats[e_RTE_METER_GREEN] &= ~0xF8LLU;
131 data->stats[e_RTE_METER_GREEN] |= (profile_id % 32) << 3;
134 #define MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color)\
135 (((data)->stats[(color)] & 4LLU) >> 2)
137 #define MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color)\
138 ((enum rte_meter_color)((data)->stats[(color)] & 3LLU))
141 mtr_trtcm_data_policer_action_set(struct mtr_trtcm_data *data,
142 enum rte_meter_color color,
143 enum rte_table_action_policer action)
145 if (action == RTE_TABLE_ACTION_POLICER_DROP) {
146 data->stats[color] |= 4LLU;
148 data->stats[color] &= ~7LLU;
149 data->stats[color] |= color & 3LLU;
154 mtr_trtcm_data_stats_get(struct mtr_trtcm_data *data,
155 enum rte_meter_color color)
157 return data->stats[color] >> 8;
161 mtr_trtcm_data_stats_reset(struct mtr_trtcm_data *data,
162 enum rte_meter_color color)
164 data->stats[color] &= 0xFFLU;
167 #define MTR_TRTCM_DATA_STATS_INC(data, color) \
168 ((data)->stats[(color)] += (1LLU << 8))
171 mtr_data_size(struct rte_table_action_mtr_config *mtr)
173 return mtr->n_tc * sizeof(struct mtr_trtcm_data);
176 struct dscp_table_entry_data {
177 enum rte_meter_color color;
179 uint16_t queue_tc_color;
182 struct dscp_table_data {
183 struct dscp_table_entry_data entry[64];
186 struct meter_profile_data {
187 struct rte_meter_trtcm_profile profile;
192 static struct meter_profile_data *
193 meter_profile_data_find(struct meter_profile_data *mp,
199 for (i = 0; i < mp_size; i++) {
200 struct meter_profile_data *mp_data = &mp[i];
202 if (mp_data->valid && (mp_data->profile_id == profile_id))
209 static struct meter_profile_data *
210 meter_profile_data_find_unused(struct meter_profile_data *mp,
215 for (i = 0; i < mp_size; i++) {
216 struct meter_profile_data *mp_data = &mp[i];
226 mtr_apply_check(struct rte_table_action_mtr_params *p,
227 struct rte_table_action_mtr_config *cfg,
228 struct meter_profile_data *mp,
233 if (p->tc_mask > RTE_LEN2MASK(cfg->n_tc, uint32_t))
236 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
237 struct rte_table_action_mtr_tc_params *p_tc = &p->mtr[i];
238 struct meter_profile_data *mp_data;
240 if ((p->tc_mask & (1LLU << i)) == 0)
243 mp_data = meter_profile_data_find(mp,
245 p_tc->meter_profile_id);
254 mtr_apply(struct mtr_trtcm_data *data,
255 struct rte_table_action_mtr_params *p,
256 struct rte_table_action_mtr_config *cfg,
257 struct meter_profile_data *mp,
263 /* Check input arguments */
264 status = mtr_apply_check(p, cfg, mp, mp_size);
269 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
270 struct rte_table_action_mtr_tc_params *p_tc = &p->mtr[i];
271 struct mtr_trtcm_data *data_tc = &data[i];
272 struct meter_profile_data *mp_data;
274 if ((p->tc_mask & (1LLU << i)) == 0)
278 mp_data = meter_profile_data_find(mp,
280 p_tc->meter_profile_id);
284 memset(data_tc, 0, sizeof(*data_tc));
287 status = rte_meter_trtcm_config(&data_tc->trtcm,
293 mtr_trtcm_data_meter_profile_id_set(data_tc,
296 /* Policer actions */
297 mtr_trtcm_data_policer_action_set(data_tc,
299 p_tc->policer[e_RTE_METER_GREEN]);
301 mtr_trtcm_data_policer_action_set(data_tc,
303 p_tc->policer[e_RTE_METER_YELLOW]);
305 mtr_trtcm_data_policer_action_set(data_tc,
307 p_tc->policer[e_RTE_METER_RED]);
313 static __rte_always_inline uint64_t
314 pkt_work_mtr(struct rte_mbuf *mbuf,
315 struct mtr_trtcm_data *data,
316 struct dscp_table_data *dscp_table,
317 struct meter_profile_data *mp,
320 uint16_t total_length)
322 uint64_t drop_mask, sched;
323 uint64_t *sched_ptr = (uint64_t *) &mbuf->hash.sched;
324 struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
325 enum rte_meter_color color_in, color_meter, color_policer;
329 color_in = dscp_entry->color;
331 mp_id = MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data);
335 color_meter = rte_meter_trtcm_color_aware_check(
343 MTR_TRTCM_DATA_STATS_INC(data, color_meter);
346 drop_mask = MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color_meter);
348 MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color_meter);
349 *sched_ptr = MBUF_SCHED_COLOR(sched, color_policer);
355 * RTE_TABLE_ACTION_TM
358 tm_cfg_check(struct rte_table_action_tm_config *tm)
360 if ((tm->n_subports_per_port == 0) ||
361 (rte_is_power_of_2(tm->n_subports_per_port) == 0) ||
362 (tm->n_subports_per_port > UINT16_MAX) ||
363 (tm->n_pipes_per_subport == 0) ||
364 (rte_is_power_of_2(tm->n_pipes_per_subport) == 0))
371 uint16_t queue_tc_color;
374 } __attribute__((__packed__));
377 tm_apply_check(struct rte_table_action_tm_params *p,
378 struct rte_table_action_tm_config *cfg)
380 if ((p->subport_id >= cfg->n_subports_per_port) ||
381 (p->pipe_id >= cfg->n_pipes_per_subport))
388 tm_apply(struct tm_data *data,
389 struct rte_table_action_tm_params *p,
390 struct rte_table_action_tm_config *cfg)
394 /* Check input arguments */
395 status = tm_apply_check(p, cfg);
400 data->queue_tc_color = 0;
401 data->subport = (uint16_t) p->subport_id;
402 data->pipe = p->pipe_id;
407 static __rte_always_inline void
408 pkt_work_tm(struct rte_mbuf *mbuf,
409 struct tm_data *data,
410 struct dscp_table_data *dscp_table,
413 struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
414 struct tm_data *sched_ptr = (struct tm_data *) &mbuf->hash.sched;
415 struct tm_data sched;
418 sched.queue_tc_color = dscp_entry->queue_tc_color;
423 * RTE_TABLE_ACTION_ENCAP
426 encap_valid(enum rte_table_action_encap_type encap)
429 case RTE_TABLE_ACTION_ENCAP_ETHER:
430 case RTE_TABLE_ACTION_ENCAP_VLAN:
431 case RTE_TABLE_ACTION_ENCAP_QINQ:
432 case RTE_TABLE_ACTION_ENCAP_MPLS:
433 case RTE_TABLE_ACTION_ENCAP_PPPOE:
434 case RTE_TABLE_ACTION_ENCAP_VXLAN:
442 encap_cfg_check(struct rte_table_action_encap_config *encap)
444 if ((encap->encap_mask == 0) ||
445 (__builtin_popcountll(encap->encap_mask) != 1))
451 struct encap_ether_data {
452 struct ether_hdr ether;
453 } __attribute__((__packed__));
455 #define VLAN(pcp, dei, vid) \
456 ((uint16_t)((((uint64_t)(pcp)) & 0x7LLU) << 13) | \
457 ((((uint64_t)(dei)) & 0x1LLU) << 12) | \
458 (((uint64_t)(vid)) & 0xFFFLLU)) \
460 struct encap_vlan_data {
461 struct ether_hdr ether;
462 struct vlan_hdr vlan;
463 } __attribute__((__packed__));
465 struct encap_qinq_data {
466 struct ether_hdr ether;
467 struct vlan_hdr svlan;
468 struct vlan_hdr cvlan;
469 } __attribute__((__packed__));
471 #define ETHER_TYPE_MPLS_UNICAST 0x8847
473 #define ETHER_TYPE_MPLS_MULTICAST 0x8848
475 #define MPLS(label, tc, s, ttl) \
476 ((uint32_t)(((((uint64_t)(label)) & 0xFFFFFLLU) << 12) |\
477 ((((uint64_t)(tc)) & 0x7LLU) << 9) | \
478 ((((uint64_t)(s)) & 0x1LLU) << 8) | \
479 (((uint64_t)(ttl)) & 0xFFLLU)))
481 struct encap_mpls_data {
482 struct ether_hdr ether;
483 uint32_t mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
485 } __attribute__((__packed__));
487 #define ETHER_TYPE_PPPOE_SESSION 0x8864
489 #define PPP_PROTOCOL_IP 0x0021
491 struct pppoe_ppp_hdr {
492 uint16_t ver_type_code;
496 } __attribute__((__packed__));
498 struct encap_pppoe_data {
499 struct ether_hdr ether;
500 struct pppoe_ppp_hdr pppoe_ppp;
501 } __attribute__((__packed__));
503 #define IP_PROTO_UDP 17
505 struct encap_vxlan_ipv4_data {
506 struct ether_hdr ether;
507 struct ipv4_hdr ipv4;
509 struct vxlan_hdr vxlan;
510 } __attribute__((__packed__));
512 struct encap_vxlan_ipv4_vlan_data {
513 struct ether_hdr ether;
514 struct vlan_hdr vlan;
515 struct ipv4_hdr ipv4;
517 struct vxlan_hdr vxlan;
518 } __attribute__((__packed__));
520 struct encap_vxlan_ipv6_data {
521 struct ether_hdr ether;
522 struct ipv6_hdr ipv6;
524 struct vxlan_hdr vxlan;
525 } __attribute__((__packed__));
527 struct encap_vxlan_ipv6_vlan_data {
528 struct ether_hdr ether;
529 struct vlan_hdr vlan;
530 struct ipv6_hdr ipv6;
532 struct vxlan_hdr vxlan;
533 } __attribute__((__packed__));
536 encap_data_size(struct rte_table_action_encap_config *encap)
538 switch (encap->encap_mask) {
539 case 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER:
540 return sizeof(struct encap_ether_data);
542 case 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN:
543 return sizeof(struct encap_vlan_data);
545 case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ:
546 return sizeof(struct encap_qinq_data);
548 case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
549 return sizeof(struct encap_mpls_data);
551 case 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE:
552 return sizeof(struct encap_pppoe_data);
554 case 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN:
555 if (encap->vxlan.ip_version)
556 if (encap->vxlan.vlan)
557 return sizeof(struct encap_vxlan_ipv4_vlan_data);
559 return sizeof(struct encap_vxlan_ipv4_data);
561 if (encap->vxlan.vlan)
562 return sizeof(struct encap_vxlan_ipv6_vlan_data);
564 return sizeof(struct encap_vxlan_ipv6_data);
572 encap_apply_check(struct rte_table_action_encap_params *p,
573 struct rte_table_action_encap_config *cfg)
575 if ((encap_valid(p->type) == 0) ||
576 ((cfg->encap_mask & (1LLU << p->type)) == 0))
580 case RTE_TABLE_ACTION_ENCAP_ETHER:
583 case RTE_TABLE_ACTION_ENCAP_VLAN:
586 case RTE_TABLE_ACTION_ENCAP_QINQ:
589 case RTE_TABLE_ACTION_ENCAP_MPLS:
590 if ((p->mpls.mpls_count == 0) ||
591 (p->mpls.mpls_count > RTE_TABLE_ACTION_MPLS_LABELS_MAX))
596 case RTE_TABLE_ACTION_ENCAP_PPPOE:
599 case RTE_TABLE_ACTION_ENCAP_VXLAN:
608 encap_ether_apply(void *data,
609 struct rte_table_action_encap_params *p,
610 struct rte_table_action_common_config *common_cfg)
612 struct encap_ether_data *d = data;
613 uint16_t ethertype = (common_cfg->ip_version) ?
618 ether_addr_copy(&p->ether.ether.da, &d->ether.d_addr);
619 ether_addr_copy(&p->ether.ether.sa, &d->ether.s_addr);
620 d->ether.ether_type = rte_htons(ethertype);
626 encap_vlan_apply(void *data,
627 struct rte_table_action_encap_params *p,
628 struct rte_table_action_common_config *common_cfg)
630 struct encap_vlan_data *d = data;
631 uint16_t ethertype = (common_cfg->ip_version) ?
636 ether_addr_copy(&p->vlan.ether.da, &d->ether.d_addr);
637 ether_addr_copy(&p->vlan.ether.sa, &d->ether.s_addr);
638 d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
641 d->vlan.vlan_tci = rte_htons(VLAN(p->vlan.vlan.pcp,
644 d->vlan.eth_proto = rte_htons(ethertype);
650 encap_qinq_apply(void *data,
651 struct rte_table_action_encap_params *p,
652 struct rte_table_action_common_config *common_cfg)
654 struct encap_qinq_data *d = data;
655 uint16_t ethertype = (common_cfg->ip_version) ?
660 ether_addr_copy(&p->qinq.ether.da, &d->ether.d_addr);
661 ether_addr_copy(&p->qinq.ether.sa, &d->ether.s_addr);
662 d->ether.ether_type = rte_htons(ETHER_TYPE_QINQ);
665 d->svlan.vlan_tci = rte_htons(VLAN(p->qinq.svlan.pcp,
668 d->svlan.eth_proto = rte_htons(ETHER_TYPE_VLAN);
671 d->cvlan.vlan_tci = rte_htons(VLAN(p->qinq.cvlan.pcp,
674 d->cvlan.eth_proto = rte_htons(ethertype);
680 encap_mpls_apply(void *data,
681 struct rte_table_action_encap_params *p)
683 struct encap_mpls_data *d = data;
684 uint16_t ethertype = (p->mpls.unicast) ?
685 ETHER_TYPE_MPLS_UNICAST :
686 ETHER_TYPE_MPLS_MULTICAST;
690 ether_addr_copy(&p->mpls.ether.da, &d->ether.d_addr);
691 ether_addr_copy(&p->mpls.ether.sa, &d->ether.s_addr);
692 d->ether.ether_type = rte_htons(ethertype);
695 for (i = 0; i < p->mpls.mpls_count - 1; i++)
696 d->mpls[i] = rte_htonl(MPLS(p->mpls.mpls[i].label,
699 p->mpls.mpls[i].ttl));
701 d->mpls[i] = rte_htonl(MPLS(p->mpls.mpls[i].label,
704 p->mpls.mpls[i].ttl));
706 d->mpls_count = p->mpls.mpls_count;
711 encap_pppoe_apply(void *data,
712 struct rte_table_action_encap_params *p)
714 struct encap_pppoe_data *d = data;
717 ether_addr_copy(&p->pppoe.ether.da, &d->ether.d_addr);
718 ether_addr_copy(&p->pppoe.ether.sa, &d->ether.s_addr);
719 d->ether.ether_type = rte_htons(ETHER_TYPE_PPPOE_SESSION);
722 d->pppoe_ppp.ver_type_code = rte_htons(0x1100);
723 d->pppoe_ppp.session_id = rte_htons(p->pppoe.pppoe.session_id);
724 d->pppoe_ppp.length = 0; /* not pre-computed */
725 d->pppoe_ppp.protocol = rte_htons(PPP_PROTOCOL_IP);
731 encap_vxlan_apply(void *data,
732 struct rte_table_action_encap_params *p,
733 struct rte_table_action_encap_config *cfg)
735 if ((p->vxlan.vxlan.vni > 0xFFFFFF) ||
736 (cfg->vxlan.ip_version && (p->vxlan.ipv4.dscp > 0x3F)) ||
737 (!cfg->vxlan.ip_version && (p->vxlan.ipv6.flow_label > 0xFFFFF)) ||
738 (!cfg->vxlan.ip_version && (p->vxlan.ipv6.dscp > 0x3F)) ||
739 (cfg->vxlan.vlan && (p->vxlan.vlan.vid > 0xFFF)))
742 if (cfg->vxlan.ip_version)
743 if (cfg->vxlan.vlan) {
744 struct encap_vxlan_ipv4_vlan_data *d = data;
747 ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
748 ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
749 d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
752 d->vlan.vlan_tci = rte_htons(VLAN(p->vxlan.vlan.pcp,
755 d->vlan.eth_proto = rte_htons(ETHER_TYPE_IPv4);
758 d->ipv4.version_ihl = 0x45;
759 d->ipv4.type_of_service = p->vxlan.ipv4.dscp << 2;
760 d->ipv4.total_length = 0; /* not pre-computed */
761 d->ipv4.packet_id = 0;
762 d->ipv4.fragment_offset = 0;
763 d->ipv4.time_to_live = p->vxlan.ipv4.ttl;
764 d->ipv4.next_proto_id = IP_PROTO_UDP;
765 d->ipv4.hdr_checksum = 0;
766 d->ipv4.src_addr = rte_htonl(p->vxlan.ipv4.sa);
767 d->ipv4.dst_addr = rte_htonl(p->vxlan.ipv4.da);
769 d->ipv4.hdr_checksum = rte_ipv4_cksum(&d->ipv4);
772 d->udp.src_port = rte_htons(p->vxlan.udp.sp);
773 d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
774 d->udp.dgram_len = 0; /* not pre-computed */
775 d->udp.dgram_cksum = 0;
778 d->vxlan.vx_flags = rte_htonl(0x08000000);
779 d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
783 struct encap_vxlan_ipv4_data *d = data;
786 ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
787 ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
788 d->ether.ether_type = rte_htons(ETHER_TYPE_IPv4);
791 d->ipv4.version_ihl = 0x45;
792 d->ipv4.type_of_service = p->vxlan.ipv4.dscp << 2;
793 d->ipv4.total_length = 0; /* not pre-computed */
794 d->ipv4.packet_id = 0;
795 d->ipv4.fragment_offset = 0;
796 d->ipv4.time_to_live = p->vxlan.ipv4.ttl;
797 d->ipv4.next_proto_id = IP_PROTO_UDP;
798 d->ipv4.hdr_checksum = 0;
799 d->ipv4.src_addr = rte_htonl(p->vxlan.ipv4.sa);
800 d->ipv4.dst_addr = rte_htonl(p->vxlan.ipv4.da);
802 d->ipv4.hdr_checksum = rte_ipv4_cksum(&d->ipv4);
805 d->udp.src_port = rte_htons(p->vxlan.udp.sp);
806 d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
807 d->udp.dgram_len = 0; /* not pre-computed */
808 d->udp.dgram_cksum = 0;
811 d->vxlan.vx_flags = rte_htonl(0x08000000);
812 d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
817 if (cfg->vxlan.vlan) {
818 struct encap_vxlan_ipv6_vlan_data *d = data;
821 ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
822 ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
823 d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
826 d->vlan.vlan_tci = rte_htons(VLAN(p->vxlan.vlan.pcp,
829 d->vlan.eth_proto = rte_htons(ETHER_TYPE_IPv6);
832 d->ipv6.vtc_flow = rte_htonl((6 << 28) |
833 (p->vxlan.ipv6.dscp << 22) |
834 p->vxlan.ipv6.flow_label);
835 d->ipv6.payload_len = 0; /* not pre-computed */
836 d->ipv6.proto = IP_PROTO_UDP;
837 d->ipv6.hop_limits = p->vxlan.ipv6.hop_limit;
838 memcpy(d->ipv6.src_addr,
840 sizeof(p->vxlan.ipv6.sa));
841 memcpy(d->ipv6.dst_addr,
843 sizeof(p->vxlan.ipv6.da));
846 d->udp.src_port = rte_htons(p->vxlan.udp.sp);
847 d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
848 d->udp.dgram_len = 0; /* not pre-computed */
849 d->udp.dgram_cksum = 0;
852 d->vxlan.vx_flags = rte_htonl(0x08000000);
853 d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
857 struct encap_vxlan_ipv6_data *d = data;
860 ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
861 ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
862 d->ether.ether_type = rte_htons(ETHER_TYPE_IPv6);
865 d->ipv6.vtc_flow = rte_htonl((6 << 28) |
866 (p->vxlan.ipv6.dscp << 22) |
867 p->vxlan.ipv6.flow_label);
868 d->ipv6.payload_len = 0; /* not pre-computed */
869 d->ipv6.proto = IP_PROTO_UDP;
870 d->ipv6.hop_limits = p->vxlan.ipv6.hop_limit;
871 memcpy(d->ipv6.src_addr,
873 sizeof(p->vxlan.ipv6.sa));
874 memcpy(d->ipv6.dst_addr,
876 sizeof(p->vxlan.ipv6.da));
879 d->udp.src_port = rte_htons(p->vxlan.udp.sp);
880 d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
881 d->udp.dgram_len = 0; /* not pre-computed */
882 d->udp.dgram_cksum = 0;
885 d->vxlan.vx_flags = rte_htonl(0x08000000);
886 d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
893 encap_apply(void *data,
894 struct rte_table_action_encap_params *p,
895 struct rte_table_action_encap_config *cfg,
896 struct rte_table_action_common_config *common_cfg)
900 /* Check input arguments */
901 status = encap_apply_check(p, cfg);
906 case RTE_TABLE_ACTION_ENCAP_ETHER:
907 return encap_ether_apply(data, p, common_cfg);
909 case RTE_TABLE_ACTION_ENCAP_VLAN:
910 return encap_vlan_apply(data, p, common_cfg);
912 case RTE_TABLE_ACTION_ENCAP_QINQ:
913 return encap_qinq_apply(data, p, common_cfg);
915 case RTE_TABLE_ACTION_ENCAP_MPLS:
916 return encap_mpls_apply(data, p);
918 case RTE_TABLE_ACTION_ENCAP_PPPOE:
919 return encap_pppoe_apply(data, p);
921 case RTE_TABLE_ACTION_ENCAP_VXLAN:
922 return encap_vxlan_apply(data, p, cfg);
929 static __rte_always_inline uint16_t
930 encap_vxlan_ipv4_checksum_update(uint16_t cksum0,
931 uint16_t total_length)
936 cksum1 = ~cksum1 & 0xFFFF;
938 /* Add total length (one's complement logic) */
939 cksum1 += total_length;
940 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
941 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
943 return (uint16_t)(~cksum1);
946 static __rte_always_inline void *
947 encap(void *dst, const void *src, size_t n)
949 dst = ((uint8_t *) dst) - n;
950 return rte_memcpy(dst, src, n);
953 static __rte_always_inline void
954 pkt_work_encap_vxlan_ipv4(struct rte_mbuf *mbuf,
955 struct encap_vxlan_ipv4_data *vxlan_tbl,
956 struct rte_table_action_encap_config *cfg)
958 uint32_t ether_offset = cfg->vxlan.data_offset;
959 void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
960 struct encap_vxlan_ipv4_data *vxlan_pkt;
961 uint16_t ether_length, ipv4_total_length, ipv4_hdr_cksum, udp_length;
963 ether_length = (uint16_t)mbuf->pkt_len;
964 ipv4_total_length = ether_length +
965 (sizeof(struct vxlan_hdr) +
966 sizeof(struct udp_hdr) +
967 sizeof(struct ipv4_hdr));
968 ipv4_hdr_cksum = encap_vxlan_ipv4_checksum_update(vxlan_tbl->ipv4.hdr_checksum,
969 rte_htons(ipv4_total_length));
970 udp_length = ether_length +
971 (sizeof(struct vxlan_hdr) +
972 sizeof(struct udp_hdr));
974 vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
975 vxlan_pkt->ipv4.total_length = rte_htons(ipv4_total_length);
976 vxlan_pkt->ipv4.hdr_checksum = ipv4_hdr_cksum;
977 vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
979 mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
980 mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
983 static __rte_always_inline void
984 pkt_work_encap_vxlan_ipv4_vlan(struct rte_mbuf *mbuf,
985 struct encap_vxlan_ipv4_vlan_data *vxlan_tbl,
986 struct rte_table_action_encap_config *cfg)
988 uint32_t ether_offset = cfg->vxlan.data_offset;
989 void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
990 struct encap_vxlan_ipv4_vlan_data *vxlan_pkt;
991 uint16_t ether_length, ipv4_total_length, ipv4_hdr_cksum, udp_length;
993 ether_length = (uint16_t)mbuf->pkt_len;
994 ipv4_total_length = ether_length +
995 (sizeof(struct vxlan_hdr) +
996 sizeof(struct udp_hdr) +
997 sizeof(struct ipv4_hdr));
998 ipv4_hdr_cksum = encap_vxlan_ipv4_checksum_update(vxlan_tbl->ipv4.hdr_checksum,
999 rte_htons(ipv4_total_length));
1000 udp_length = ether_length +
1001 (sizeof(struct vxlan_hdr) +
1002 sizeof(struct udp_hdr));
1004 vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1005 vxlan_pkt->ipv4.total_length = rte_htons(ipv4_total_length);
1006 vxlan_pkt->ipv4.hdr_checksum = ipv4_hdr_cksum;
1007 vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
1009 mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1010 mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1013 static __rte_always_inline void
1014 pkt_work_encap_vxlan_ipv6(struct rte_mbuf *mbuf,
1015 struct encap_vxlan_ipv6_data *vxlan_tbl,
1016 struct rte_table_action_encap_config *cfg)
1018 uint32_t ether_offset = cfg->vxlan.data_offset;
1019 void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
1020 struct encap_vxlan_ipv6_data *vxlan_pkt;
1021 uint16_t ether_length, ipv6_payload_length, udp_length;
1023 ether_length = (uint16_t)mbuf->pkt_len;
1024 ipv6_payload_length = ether_length +
1025 (sizeof(struct vxlan_hdr) +
1026 sizeof(struct udp_hdr));
1027 udp_length = ether_length +
1028 (sizeof(struct vxlan_hdr) +
1029 sizeof(struct udp_hdr));
1031 vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1032 vxlan_pkt->ipv6.payload_len = rte_htons(ipv6_payload_length);
1033 vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
1035 mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1036 mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1039 static __rte_always_inline void
1040 pkt_work_encap_vxlan_ipv6_vlan(struct rte_mbuf *mbuf,
1041 struct encap_vxlan_ipv6_vlan_data *vxlan_tbl,
1042 struct rte_table_action_encap_config *cfg)
1044 uint32_t ether_offset = cfg->vxlan.data_offset;
1045 void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
1046 struct encap_vxlan_ipv6_vlan_data *vxlan_pkt;
1047 uint16_t ether_length, ipv6_payload_length, udp_length;
1049 ether_length = (uint16_t)mbuf->pkt_len;
1050 ipv6_payload_length = ether_length +
1051 (sizeof(struct vxlan_hdr) +
1052 sizeof(struct udp_hdr));
1053 udp_length = ether_length +
1054 (sizeof(struct vxlan_hdr) +
1055 sizeof(struct udp_hdr));
1057 vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1058 vxlan_pkt->ipv6.payload_len = rte_htons(ipv6_payload_length);
1059 vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
1061 mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1062 mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1065 static __rte_always_inline void
1066 pkt_work_encap(struct rte_mbuf *mbuf,
1068 struct rte_table_action_encap_config *cfg,
1070 uint16_t total_length,
1073 switch (cfg->encap_mask) {
1074 case 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER:
1075 encap(ip, data, sizeof(struct encap_ether_data));
1076 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1077 sizeof(struct encap_ether_data));
1078 mbuf->pkt_len = mbuf->data_len = total_length +
1079 sizeof(struct encap_ether_data);
1082 case 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN:
1083 encap(ip, data, sizeof(struct encap_vlan_data));
1084 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1085 sizeof(struct encap_vlan_data));
1086 mbuf->pkt_len = mbuf->data_len = total_length +
1087 sizeof(struct encap_vlan_data);
1090 case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ:
1091 encap(ip, data, sizeof(struct encap_qinq_data));
1092 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1093 sizeof(struct encap_qinq_data));
1094 mbuf->pkt_len = mbuf->data_len = total_length +
1095 sizeof(struct encap_qinq_data);
1098 case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
1100 struct encap_mpls_data *mpls = data;
1101 size_t size = sizeof(struct ether_hdr) +
1102 mpls->mpls_count * 4;
1104 encap(ip, data, size);
1105 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) + size);
1106 mbuf->pkt_len = mbuf->data_len = total_length + size;
1110 case 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE:
1112 struct encap_pppoe_data *pppoe =
1113 encap(ip, data, sizeof(struct encap_pppoe_data));
1114 pppoe->pppoe_ppp.length = rte_htons(total_length + 2);
1115 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1116 sizeof(struct encap_pppoe_data));
1117 mbuf->pkt_len = mbuf->data_len = total_length +
1118 sizeof(struct encap_pppoe_data);
1122 case 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN:
1124 if (cfg->vxlan.ip_version)
1125 if (cfg->vxlan.vlan)
1126 pkt_work_encap_vxlan_ipv4_vlan(mbuf, data, cfg);
1128 pkt_work_encap_vxlan_ipv4(mbuf, data, cfg);
1130 if (cfg->vxlan.vlan)
1131 pkt_work_encap_vxlan_ipv6_vlan(mbuf, data, cfg);
1133 pkt_work_encap_vxlan_ipv6(mbuf, data, cfg);
1142 * RTE_TABLE_ACTION_NAT
1145 nat_cfg_check(struct rte_table_action_nat_config *nat)
1147 if ((nat->proto != 0x06) &&
1148 (nat->proto != 0x11))
1154 struct nat_ipv4_data {
1157 } __attribute__((__packed__));
1159 struct nat_ipv6_data {
1162 } __attribute__((__packed__));
1165 nat_data_size(struct rte_table_action_nat_config *nat __rte_unused,
1166 struct rte_table_action_common_config *common)
1168 int ip_version = common->ip_version;
1170 return (ip_version) ?
1171 sizeof(struct nat_ipv4_data) :
1172 sizeof(struct nat_ipv6_data);
1176 nat_apply_check(struct rte_table_action_nat_params *p,
1177 struct rte_table_action_common_config *cfg)
1179 if ((p->ip_version && (cfg->ip_version == 0)) ||
1180 ((p->ip_version == 0) && cfg->ip_version))
1187 nat_apply(void *data,
1188 struct rte_table_action_nat_params *p,
1189 struct rte_table_action_common_config *cfg)
1193 /* Check input arguments */
1194 status = nat_apply_check(p, cfg);
1199 if (p->ip_version) {
1200 struct nat_ipv4_data *d = data;
1202 d->addr = rte_htonl(p->addr.ipv4);
1203 d->port = rte_htons(p->port);
1205 struct nat_ipv6_data *d = data;
1207 memcpy(d->addr, p->addr.ipv6, sizeof(d->addr));
1208 d->port = rte_htons(p->port);
1214 static __rte_always_inline uint16_t
1215 nat_ipv4_checksum_update(uint16_t cksum0,
1222 cksum1 = ~cksum1 & 0xFFFF;
1224 /* Subtract ip0 (one's complement logic) */
1225 cksum1 -= (ip0 >> 16) + (ip0 & 0xFFFF);
1226 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1227 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1229 /* Add ip1 (one's complement logic) */
1230 cksum1 += (ip1 >> 16) + (ip1 & 0xFFFF);
1231 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1232 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1234 return (uint16_t)(~cksum1);
1237 static __rte_always_inline uint16_t
1238 nat_ipv4_tcp_udp_checksum_update(uint16_t cksum0,
1247 cksum1 = ~cksum1 & 0xFFFF;
1249 /* Subtract ip0 and port 0 (one's complement logic) */
1250 cksum1 -= (ip0 >> 16) + (ip0 & 0xFFFF) + port0;
1251 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1252 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1254 /* Add ip1 and port1 (one's complement logic) */
1255 cksum1 += (ip1 >> 16) + (ip1 & 0xFFFF) + port1;
1256 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1257 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1259 return (uint16_t)(~cksum1);
1262 static __rte_always_inline uint16_t
1263 nat_ipv6_tcp_udp_checksum_update(uint16_t cksum0,
1272 cksum1 = ~cksum1 & 0xFFFF;
1274 /* Subtract ip0 and port 0 (one's complement logic) */
1275 cksum1 -= ip0[0] + ip0[1] + ip0[2] + ip0[3] +
1276 ip0[4] + ip0[5] + ip0[6] + ip0[7] + port0;
1277 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1278 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1280 /* Add ip1 and port1 (one's complement logic) */
1281 cksum1 += ip1[0] + ip1[1] + ip1[2] + ip1[3] +
1282 ip1[4] + ip1[5] + ip1[6] + ip1[7] + port1;
1283 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1284 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1286 return (uint16_t)(~cksum1);
1289 static __rte_always_inline void
1290 pkt_ipv4_work_nat(struct ipv4_hdr *ip,
1291 struct nat_ipv4_data *data,
1292 struct rte_table_action_nat_config *cfg)
1294 if (cfg->source_nat) {
1295 if (cfg->proto == 0x6) {
1296 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
1297 uint16_t ip_cksum, tcp_cksum;
1299 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1303 tcp_cksum = nat_ipv4_tcp_udp_checksum_update(tcp->cksum,
1309 ip->src_addr = data->addr;
1310 ip->hdr_checksum = ip_cksum;
1311 tcp->src_port = data->port;
1312 tcp->cksum = tcp_cksum;
1314 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
1315 uint16_t ip_cksum, udp_cksum;
1317 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1321 udp_cksum = nat_ipv4_tcp_udp_checksum_update(udp->dgram_cksum,
1327 ip->src_addr = data->addr;
1328 ip->hdr_checksum = ip_cksum;
1329 udp->src_port = data->port;
1330 if (udp->dgram_cksum)
1331 udp->dgram_cksum = udp_cksum;
1334 if (cfg->proto == 0x6) {
1335 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
1336 uint16_t ip_cksum, tcp_cksum;
1338 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1342 tcp_cksum = nat_ipv4_tcp_udp_checksum_update(tcp->cksum,
1348 ip->dst_addr = data->addr;
1349 ip->hdr_checksum = ip_cksum;
1350 tcp->dst_port = data->port;
1351 tcp->cksum = tcp_cksum;
1353 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
1354 uint16_t ip_cksum, udp_cksum;
1356 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1360 udp_cksum = nat_ipv4_tcp_udp_checksum_update(udp->dgram_cksum,
1366 ip->dst_addr = data->addr;
1367 ip->hdr_checksum = ip_cksum;
1368 udp->dst_port = data->port;
1369 if (udp->dgram_cksum)
1370 udp->dgram_cksum = udp_cksum;
1375 static __rte_always_inline void
1376 pkt_ipv6_work_nat(struct ipv6_hdr *ip,
1377 struct nat_ipv6_data *data,
1378 struct rte_table_action_nat_config *cfg)
1380 if (cfg->source_nat) {
1381 if (cfg->proto == 0x6) {
1382 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
1385 tcp_cksum = nat_ipv6_tcp_udp_checksum_update(tcp->cksum,
1386 (uint16_t *)ip->src_addr,
1387 (uint16_t *)data->addr,
1391 rte_memcpy(ip->src_addr, data->addr, 16);
1392 tcp->src_port = data->port;
1393 tcp->cksum = tcp_cksum;
1395 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
1398 udp_cksum = nat_ipv6_tcp_udp_checksum_update(udp->dgram_cksum,
1399 (uint16_t *)ip->src_addr,
1400 (uint16_t *)data->addr,
1404 rte_memcpy(ip->src_addr, data->addr, 16);
1405 udp->src_port = data->port;
1406 udp->dgram_cksum = udp_cksum;
1409 if (cfg->proto == 0x6) {
1410 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
1413 tcp_cksum = nat_ipv6_tcp_udp_checksum_update(tcp->cksum,
1414 (uint16_t *)ip->dst_addr,
1415 (uint16_t *)data->addr,
1419 rte_memcpy(ip->dst_addr, data->addr, 16);
1420 tcp->dst_port = data->port;
1421 tcp->cksum = tcp_cksum;
1423 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
1426 udp_cksum = nat_ipv6_tcp_udp_checksum_update(udp->dgram_cksum,
1427 (uint16_t *)ip->dst_addr,
1428 (uint16_t *)data->addr,
1432 rte_memcpy(ip->dst_addr, data->addr, 16);
1433 udp->dst_port = data->port;
1434 udp->dgram_cksum = udp_cksum;
1440 * RTE_TABLE_ACTION_TTL
1443 ttl_cfg_check(struct rte_table_action_ttl_config *ttl)
1453 } __attribute__((__packed__));
1455 #define TTL_INIT(data, decrement) \
1456 ((data)->n_packets = (decrement) ? 1 : 0)
1458 #define TTL_DEC_GET(data) \
1459 ((uint8_t)((data)->n_packets & 1))
1461 #define TTL_STATS_RESET(data) \
1462 ((data)->n_packets = ((data)->n_packets & 1))
1464 #define TTL_STATS_READ(data) \
1465 ((data)->n_packets >> 1)
1467 #define TTL_STATS_ADD(data, value) \
1468 ((data)->n_packets = \
1469 (((((data)->n_packets >> 1) + (value)) << 1) | \
1470 ((data)->n_packets & 1)))
1473 ttl_apply(void *data,
1474 struct rte_table_action_ttl_params *p)
1476 struct ttl_data *d = data;
1478 TTL_INIT(d, p->decrement);
1483 static __rte_always_inline uint64_t
1484 pkt_ipv4_work_ttl(struct ipv4_hdr *ip,
1485 struct ttl_data *data)
1488 uint16_t cksum = ip->hdr_checksum;
1489 uint8_t ttl = ip->time_to_live;
1490 uint8_t ttl_diff = TTL_DEC_GET(data);
1495 ip->hdr_checksum = cksum;
1496 ip->time_to_live = ttl;
1498 drop = (ttl == 0) ? 1 : 0;
1499 TTL_STATS_ADD(data, drop);
1504 static __rte_always_inline uint64_t
1505 pkt_ipv6_work_ttl(struct ipv6_hdr *ip,
1506 struct ttl_data *data)
1509 uint8_t ttl = ip->hop_limits;
1510 uint8_t ttl_diff = TTL_DEC_GET(data);
1514 ip->hop_limits = ttl;
1516 drop = (ttl == 0) ? 1 : 0;
1517 TTL_STATS_ADD(data, drop);
1523 * RTE_TABLE_ACTION_STATS
1526 stats_cfg_check(struct rte_table_action_stats_config *stats)
1528 if ((stats->n_packets_enabled == 0) && (stats->n_bytes_enabled == 0))
1537 } __attribute__((__packed__));
1540 stats_apply(struct stats_data *data,
1541 struct rte_table_action_stats_params *p)
1543 data->n_packets = p->n_packets;
1544 data->n_bytes = p->n_bytes;
1549 static __rte_always_inline void
1550 pkt_work_stats(struct stats_data *data,
1551 uint16_t total_length)
1554 data->n_bytes += total_length;
1558 * RTE_TABLE_ACTION_TIME
1562 } __attribute__((__packed__));
1565 time_apply(struct time_data *data,
1566 struct rte_table_action_time_params *p)
1568 data->time = p->time;
1572 static __rte_always_inline void
1573 pkt_work_time(struct time_data *data,
1581 * RTE_TABLE_ACTION_CRYPTO
1584 #define CRYPTO_OP_MASK_CIPHER 0x1
1585 #define CRYPTO_OP_MASK_AUTH 0x2
1586 #define CRYPTO_OP_MASK_AEAD 0x4
1588 struct crypto_op_sym_iv_aad {
1589 struct rte_crypto_op op;
1590 struct rte_crypto_sym_op sym_op;
1594 RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX];
1596 RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX];
1600 uint8_t iv[RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX];
1601 uint8_t aad[RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX];
1607 struct sym_crypto_data {
1612 /** Length of cipher iv. */
1613 uint16_t cipher_iv_len;
1615 /** Offset from start of IP header to the cipher iv. */
1616 uint16_t cipher_iv_data_offset;
1618 /** Length of cipher iv to be updated in the mbuf. */
1619 uint16_t cipher_iv_update_len;
1621 /** Offset from start of IP header to the auth iv. */
1622 uint16_t auth_iv_data_offset;
1624 /** Length of auth iv in the mbuf. */
1625 uint16_t auth_iv_len;
1627 /** Length of auth iv to be updated in the mbuf. */
1628 uint16_t auth_iv_update_len;
1633 /** Length of iv. */
1636 /** Offset from start of IP header to the aead iv. */
1637 uint16_t iv_data_offset;
1639 /** Length of iv to be updated in the mbuf. */
1640 uint16_t iv_update_len;
1642 /** Length of aad */
1645 /** Offset from start of IP header to the aad. */
1646 uint16_t aad_data_offset;
1648 /** Length of aad to updated in the mbuf. */
1649 uint16_t aad_update_len;
1654 /** Offset from start of IP header to the data. */
1655 uint16_t data_offset;
1657 /** Digest length. */
1658 uint16_t digest_len;
1661 uint16_t block_size;
1663 /** Mask of crypto operation */
1666 /** Session pointer. */
1667 struct rte_cryptodev_sym_session *session;
1669 /** Direction of crypto, encrypt or decrypt */
1672 /** Private data size to store cipher iv / aad. */
1673 uint8_t iv_aad_data[32];
1675 } __attribute__((__packed__));
1678 sym_crypto_cfg_check(struct rte_table_action_sym_crypto_config *cfg)
1680 if (!rte_cryptodev_pmd_is_valid_dev(cfg->cryptodev_id))
1682 if (cfg->mp_create == NULL || cfg->mp_init == NULL)
1689 get_block_size(const struct rte_crypto_sym_xform *xform, uint8_t cdev_id)
1691 struct rte_cryptodev_info dev_info;
1692 const struct rte_cryptodev_capabilities *cap;
1695 rte_cryptodev_info_get(cdev_id, &dev_info);
1698 cap = &dev_info.capabilities[i];
1702 if (cap->sym.xform_type != xform->type)
1705 if ((xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) &&
1706 (cap->sym.cipher.algo == xform->cipher.algo))
1707 return cap->sym.cipher.block_size;
1709 if ((xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) &&
1710 (cap->sym.aead.algo == xform->aead.algo))
1711 return cap->sym.aead.block_size;
1713 if (xform->type == RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED)
1721 sym_crypto_apply(struct sym_crypto_data *data,
1722 struct rte_table_action_sym_crypto_config *cfg,
1723 struct rte_table_action_sym_crypto_params *p)
1725 const struct rte_crypto_cipher_xform *cipher_xform = NULL;
1726 const struct rte_crypto_auth_xform *auth_xform = NULL;
1727 const struct rte_crypto_aead_xform *aead_xform = NULL;
1728 struct rte_crypto_sym_xform *xform = p->xform;
1729 struct rte_cryptodev_sym_session *session;
1732 memset(data, 0, sizeof(*data));
1735 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
1736 cipher_xform = &xform->cipher;
1738 if (cipher_xform->iv.length >
1739 RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX)
1741 if (cipher_xform->iv.offset !=
1742 RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET)
1745 ret = get_block_size(xform, cfg->cryptodev_id);
1748 data->block_size = (uint16_t)ret;
1749 data->op_mask |= CRYPTO_OP_MASK_CIPHER;
1751 data->cipher_auth.cipher_iv_len =
1752 cipher_xform->iv.length;
1753 data->cipher_auth.cipher_iv_data_offset = (uint16_t)
1754 p->cipher_auth.cipher_iv_update.offset;
1755 data->cipher_auth.cipher_iv_update_len = (uint16_t)
1756 p->cipher_auth.cipher_iv_update.length;
1758 rte_memcpy(data->iv_aad_data,
1759 p->cipher_auth.cipher_iv.val,
1760 p->cipher_auth.cipher_iv.length);
1762 data->direction = cipher_xform->op;
1764 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
1765 auth_xform = &xform->auth;
1766 if (auth_xform->iv.length >
1767 RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX)
1769 data->op_mask |= CRYPTO_OP_MASK_AUTH;
1771 data->cipher_auth.auth_iv_len = auth_xform->iv.length;
1772 data->cipher_auth.auth_iv_data_offset = (uint16_t)
1773 p->cipher_auth.auth_iv_update.offset;
1774 data->cipher_auth.auth_iv_update_len = (uint16_t)
1775 p->cipher_auth.auth_iv_update.length;
1776 data->digest_len = auth_xform->digest_length;
1778 data->direction = (auth_xform->op ==
1779 RTE_CRYPTO_AUTH_OP_GENERATE) ?
1780 RTE_CRYPTO_CIPHER_OP_ENCRYPT :
1781 RTE_CRYPTO_CIPHER_OP_DECRYPT;
1783 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
1784 aead_xform = &xform->aead;
1786 if ((aead_xform->iv.length >
1787 RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX) || (
1788 aead_xform->aad_length >
1789 RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX))
1791 if (aead_xform->iv.offset !=
1792 RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET)
1795 ret = get_block_size(xform, cfg->cryptodev_id);
1798 data->block_size = (uint16_t)ret;
1799 data->op_mask |= CRYPTO_OP_MASK_AEAD;
1801 data->digest_len = aead_xform->digest_length;
1802 data->aead.iv_len = aead_xform->iv.length;
1803 data->aead.aad_len = aead_xform->aad_length;
1805 data->aead.iv_data_offset = (uint16_t)
1806 p->aead.iv_update.offset;
1807 data->aead.iv_update_len = (uint16_t)
1808 p->aead.iv_update.length;
1809 data->aead.aad_data_offset = (uint16_t)
1810 p->aead.aad_update.offset;
1811 data->aead.aad_update_len = (uint16_t)
1812 p->aead.aad_update.length;
1814 rte_memcpy(data->iv_aad_data,
1818 rte_memcpy(data->iv_aad_data + p->aead.iv.length,
1820 p->aead.aad.length);
1822 data->direction = (aead_xform->op ==
1823 RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
1824 RTE_CRYPTO_CIPHER_OP_ENCRYPT :
1825 RTE_CRYPTO_CIPHER_OP_DECRYPT;
1829 xform = xform->next;
1832 if (auth_xform && auth_xform->iv.length) {
1834 if (auth_xform->iv.offset !=
1835 RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET +
1836 cipher_xform->iv.length)
1839 rte_memcpy(data->iv_aad_data + cipher_xform->iv.length,
1840 p->cipher_auth.auth_iv.val,
1841 p->cipher_auth.auth_iv.length);
1843 rte_memcpy(data->iv_aad_data,
1844 p->cipher_auth.auth_iv.val,
1845 p->cipher_auth.auth_iv.length);
1849 session = rte_cryptodev_sym_session_create(cfg->mp_create);
1853 ret = rte_cryptodev_sym_session_init(cfg->cryptodev_id, session,
1854 p->xform, cfg->mp_init);
1856 rte_cryptodev_sym_session_free(session);
1860 data->data_offset = (uint16_t)p->data_offset;
1861 data->session = session;
1866 static __rte_always_inline uint64_t
1867 pkt_work_sym_crypto(struct rte_mbuf *mbuf, struct sym_crypto_data *data,
1868 struct rte_table_action_sym_crypto_config *cfg,
1871 struct crypto_op_sym_iv_aad *crypto_op = (struct crypto_op_sym_iv_aad *)
1872 RTE_MBUF_METADATA_UINT8_PTR(mbuf, cfg->op_offset);
1873 struct rte_crypto_op *op = &crypto_op->op;
1874 struct rte_crypto_sym_op *sym = op->sym;
1875 uint32_t pkt_offset = sizeof(*mbuf) + mbuf->data_off;
1876 uint32_t payload_len = pkt_offset + mbuf->data_len - data->data_offset;
1878 op->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
1879 op->sess_type = RTE_CRYPTO_OP_WITH_SESSION;
1880 op->phys_addr = mbuf->buf_iova + cfg->op_offset - sizeof(*mbuf);
1881 op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
1884 sym->session = data->session;
1886 /** pad the packet */
1887 if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1888 uint32_t append_len = RTE_ALIGN_CEIL(payload_len,
1889 data->block_size) - payload_len;
1891 if (unlikely(rte_pktmbuf_append(mbuf, append_len +
1892 data->digest_len) == NULL))
1895 payload_len += append_len;
1897 payload_len -= data->digest_len;
1899 if (data->op_mask & CRYPTO_OP_MASK_CIPHER) {
1900 /** prepare cipher op */
1901 uint8_t *iv = crypto_op->iv_aad.cipher_auth.cipher_iv;
1903 sym->cipher.data.length = payload_len;
1904 sym->cipher.data.offset = data->data_offset - pkt_offset;
1906 if (data->cipher_auth.cipher_iv_update_len) {
1907 uint8_t *pkt_iv = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
1908 data->cipher_auth.cipher_iv_data_offset
1911 /** For encryption, update the pkt iv field, otherwise
1912 * update the iv_aad_field
1914 if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
1915 rte_memcpy(pkt_iv, data->iv_aad_data,
1916 data->cipher_auth.cipher_iv_update_len);
1918 rte_memcpy(data->iv_aad_data, pkt_iv,
1919 data->cipher_auth.cipher_iv_update_len);
1923 rte_memcpy(iv, data->iv_aad_data,
1924 data->cipher_auth.cipher_iv_len);
1927 if (data->op_mask & CRYPTO_OP_MASK_AUTH) {
1928 /** authentication always start from IP header. */
1929 sym->auth.data.offset = ip_offset - pkt_offset;
1930 sym->auth.data.length = mbuf->data_len - sym->auth.data.offset -
1932 sym->auth.digest.data = rte_pktmbuf_mtod_offset(mbuf,
1933 uint8_t *, rte_pktmbuf_pkt_len(mbuf) -
1935 sym->auth.digest.phys_addr = rte_pktmbuf_iova_offset(mbuf,
1936 rte_pktmbuf_pkt_len(mbuf) - data->digest_len);
1938 if (data->cipher_auth.auth_iv_update_len) {
1939 uint8_t *pkt_iv = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
1940 data->cipher_auth.auth_iv_data_offset
1942 uint8_t *data_iv = data->iv_aad_data +
1943 data->cipher_auth.cipher_iv_len;
1945 if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
1946 rte_memcpy(pkt_iv, data_iv,
1947 data->cipher_auth.auth_iv_update_len);
1949 rte_memcpy(data_iv, pkt_iv,
1950 data->cipher_auth.auth_iv_update_len);
1953 if (data->cipher_auth.auth_iv_len) {
1954 /** prepare cipher op */
1955 uint8_t *iv = crypto_op->iv_aad.cipher_auth.auth_iv;
1957 rte_memcpy(iv, data->iv_aad_data +
1958 data->cipher_auth.cipher_iv_len,
1959 data->cipher_auth.auth_iv_len);
1963 if (data->op_mask & CRYPTO_OP_MASK_AEAD) {
1964 uint8_t *iv = crypto_op->iv_aad.aead_iv_aad.iv;
1965 uint8_t *aad = crypto_op->iv_aad.aead_iv_aad.aad;
1967 sym->aead.aad.data = aad;
1968 sym->aead.aad.phys_addr = rte_pktmbuf_iova_offset(mbuf,
1969 aad - rte_pktmbuf_mtod(mbuf, uint8_t *));
1970 sym->aead.digest.data = rte_pktmbuf_mtod_offset(mbuf,
1971 uint8_t *, rte_pktmbuf_pkt_len(mbuf) -
1973 sym->aead.digest.phys_addr = rte_pktmbuf_iova_offset(mbuf,
1974 rte_pktmbuf_pkt_len(mbuf) - data->digest_len);
1975 sym->aead.data.offset = data->data_offset - pkt_offset;
1976 sym->aead.data.length = payload_len;
1978 if (data->aead.iv_update_len) {
1979 uint8_t *pkt_iv = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
1980 data->aead.iv_data_offset + ip_offset);
1981 uint8_t *data_iv = data->iv_aad_data;
1983 if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
1984 rte_memcpy(pkt_iv, data_iv,
1985 data->aead.iv_update_len);
1987 rte_memcpy(data_iv, pkt_iv,
1988 data->aead.iv_update_len);
1991 rte_memcpy(iv, data->iv_aad_data, data->aead.iv_len);
1993 if (data->aead.aad_update_len) {
1994 uint8_t *pkt_aad = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
1995 data->aead.aad_data_offset + ip_offset);
1996 uint8_t *data_aad = data->iv_aad_data +
1999 if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
2000 rte_memcpy(pkt_aad, data_aad,
2001 data->aead.iv_update_len);
2003 rte_memcpy(data_aad, pkt_aad,
2004 data->aead.iv_update_len);
2007 rte_memcpy(aad, data->iv_aad_data + data->aead.iv_len,
2008 data->aead.aad_len);
2015 * RTE_TABLE_ACTION_TAG
2019 } __attribute__((__packed__));
2022 tag_apply(struct tag_data *data,
2023 struct rte_table_action_tag_params *p)
2029 static __rte_always_inline void
2030 pkt_work_tag(struct rte_mbuf *mbuf,
2031 struct tag_data *data)
2033 mbuf->hash.fdir.hi = data->tag;
2034 mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
2037 static __rte_always_inline void
2038 pkt4_work_tag(struct rte_mbuf *mbuf0,
2039 struct rte_mbuf *mbuf1,
2040 struct rte_mbuf *mbuf2,
2041 struct rte_mbuf *mbuf3,
2042 struct tag_data *data0,
2043 struct tag_data *data1,
2044 struct tag_data *data2,
2045 struct tag_data *data3)
2047 mbuf0->hash.fdir.hi = data0->tag;
2048 mbuf1->hash.fdir.hi = data1->tag;
2049 mbuf2->hash.fdir.hi = data2->tag;
2050 mbuf3->hash.fdir.hi = data3->tag;
2052 mbuf0->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
2053 mbuf1->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
2054 mbuf2->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
2055 mbuf3->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
2059 * RTE_TABLE_ACTION_DECAP
2063 } __attribute__((__packed__));
2066 decap_apply(struct decap_data *data,
2067 struct rte_table_action_decap_params *p)
2073 static __rte_always_inline void
2074 pkt_work_decap(struct rte_mbuf *mbuf,
2075 struct decap_data *data)
2077 uint16_t data_off = mbuf->data_off;
2078 uint16_t data_len = mbuf->data_len;
2079 uint32_t pkt_len = mbuf->pkt_len;
2080 uint16_t n = data->n;
2082 mbuf->data_off = data_off + n;
2083 mbuf->data_len = data_len - n;
2084 mbuf->pkt_len = pkt_len - n;
2087 static __rte_always_inline void
2088 pkt4_work_decap(struct rte_mbuf *mbuf0,
2089 struct rte_mbuf *mbuf1,
2090 struct rte_mbuf *mbuf2,
2091 struct rte_mbuf *mbuf3,
2092 struct decap_data *data0,
2093 struct decap_data *data1,
2094 struct decap_data *data2,
2095 struct decap_data *data3)
2097 uint16_t data_off0 = mbuf0->data_off;
2098 uint16_t data_len0 = mbuf0->data_len;
2099 uint32_t pkt_len0 = mbuf0->pkt_len;
2101 uint16_t data_off1 = mbuf1->data_off;
2102 uint16_t data_len1 = mbuf1->data_len;
2103 uint32_t pkt_len1 = mbuf1->pkt_len;
2105 uint16_t data_off2 = mbuf2->data_off;
2106 uint16_t data_len2 = mbuf2->data_len;
2107 uint32_t pkt_len2 = mbuf2->pkt_len;
2109 uint16_t data_off3 = mbuf3->data_off;
2110 uint16_t data_len3 = mbuf3->data_len;
2111 uint32_t pkt_len3 = mbuf3->pkt_len;
2113 uint16_t n0 = data0->n;
2114 uint16_t n1 = data1->n;
2115 uint16_t n2 = data2->n;
2116 uint16_t n3 = data3->n;
2118 mbuf0->data_off = data_off0 + n0;
2119 mbuf0->data_len = data_len0 - n0;
2120 mbuf0->pkt_len = pkt_len0 - n0;
2122 mbuf1->data_off = data_off1 + n1;
2123 mbuf1->data_len = data_len1 - n1;
2124 mbuf1->pkt_len = pkt_len1 - n1;
2126 mbuf2->data_off = data_off2 + n2;
2127 mbuf2->data_len = data_len2 - n2;
2128 mbuf2->pkt_len = pkt_len2 - n2;
2130 mbuf3->data_off = data_off3 + n3;
2131 mbuf3->data_len = data_len3 - n3;
2132 mbuf3->pkt_len = pkt_len3 - n3;
2139 action_valid(enum rte_table_action_type action)
2142 case RTE_TABLE_ACTION_FWD:
2143 case RTE_TABLE_ACTION_LB:
2144 case RTE_TABLE_ACTION_MTR:
2145 case RTE_TABLE_ACTION_TM:
2146 case RTE_TABLE_ACTION_ENCAP:
2147 case RTE_TABLE_ACTION_NAT:
2148 case RTE_TABLE_ACTION_TTL:
2149 case RTE_TABLE_ACTION_STATS:
2150 case RTE_TABLE_ACTION_TIME:
2151 case RTE_TABLE_ACTION_SYM_CRYPTO:
2152 case RTE_TABLE_ACTION_TAG:
2153 case RTE_TABLE_ACTION_DECAP:
2161 #define RTE_TABLE_ACTION_MAX 64
2164 uint64_t action_mask;
2165 struct rte_table_action_common_config common;
2166 struct rte_table_action_lb_config lb;
2167 struct rte_table_action_mtr_config mtr;
2168 struct rte_table_action_tm_config tm;
2169 struct rte_table_action_encap_config encap;
2170 struct rte_table_action_nat_config nat;
2171 struct rte_table_action_ttl_config ttl;
2172 struct rte_table_action_stats_config stats;
2173 struct rte_table_action_sym_crypto_config sym_crypto;
2177 action_cfg_size(enum rte_table_action_type action)
2180 case RTE_TABLE_ACTION_LB:
2181 return sizeof(struct rte_table_action_lb_config);
2182 case RTE_TABLE_ACTION_MTR:
2183 return sizeof(struct rte_table_action_mtr_config);
2184 case RTE_TABLE_ACTION_TM:
2185 return sizeof(struct rte_table_action_tm_config);
2186 case RTE_TABLE_ACTION_ENCAP:
2187 return sizeof(struct rte_table_action_encap_config);
2188 case RTE_TABLE_ACTION_NAT:
2189 return sizeof(struct rte_table_action_nat_config);
2190 case RTE_TABLE_ACTION_TTL:
2191 return sizeof(struct rte_table_action_ttl_config);
2192 case RTE_TABLE_ACTION_STATS:
2193 return sizeof(struct rte_table_action_stats_config);
2194 case RTE_TABLE_ACTION_SYM_CRYPTO:
2195 return sizeof(struct rte_table_action_sym_crypto_config);
2202 action_cfg_get(struct ap_config *ap_config,
2203 enum rte_table_action_type type)
2206 case RTE_TABLE_ACTION_LB:
2207 return &ap_config->lb;
2209 case RTE_TABLE_ACTION_MTR:
2210 return &ap_config->mtr;
2212 case RTE_TABLE_ACTION_TM:
2213 return &ap_config->tm;
2215 case RTE_TABLE_ACTION_ENCAP:
2216 return &ap_config->encap;
2218 case RTE_TABLE_ACTION_NAT:
2219 return &ap_config->nat;
2221 case RTE_TABLE_ACTION_TTL:
2222 return &ap_config->ttl;
2224 case RTE_TABLE_ACTION_STATS:
2225 return &ap_config->stats;
2227 case RTE_TABLE_ACTION_SYM_CRYPTO:
2228 return &ap_config->sym_crypto;
2235 action_cfg_set(struct ap_config *ap_config,
2236 enum rte_table_action_type type,
2239 void *dst = action_cfg_get(ap_config, type);
2242 memcpy(dst, action_cfg, action_cfg_size(type));
2244 ap_config->action_mask |= 1LLU << type;
2248 size_t offset[RTE_TABLE_ACTION_MAX];
2253 action_data_size(enum rte_table_action_type action,
2254 struct ap_config *ap_config)
2257 case RTE_TABLE_ACTION_FWD:
2258 return sizeof(struct fwd_data);
2260 case RTE_TABLE_ACTION_LB:
2261 return sizeof(struct lb_data);
2263 case RTE_TABLE_ACTION_MTR:
2264 return mtr_data_size(&ap_config->mtr);
2266 case RTE_TABLE_ACTION_TM:
2267 return sizeof(struct tm_data);
2269 case RTE_TABLE_ACTION_ENCAP:
2270 return encap_data_size(&ap_config->encap);
2272 case RTE_TABLE_ACTION_NAT:
2273 return nat_data_size(&ap_config->nat,
2274 &ap_config->common);
2276 case RTE_TABLE_ACTION_TTL:
2277 return sizeof(struct ttl_data);
2279 case RTE_TABLE_ACTION_STATS:
2280 return sizeof(struct stats_data);
2282 case RTE_TABLE_ACTION_TIME:
2283 return sizeof(struct time_data);
2285 case RTE_TABLE_ACTION_SYM_CRYPTO:
2286 return (sizeof(struct sym_crypto_data));
2288 case RTE_TABLE_ACTION_TAG:
2289 return sizeof(struct tag_data);
2291 case RTE_TABLE_ACTION_DECAP:
2292 return sizeof(struct decap_data);
2301 action_data_offset_set(struct ap_data *ap_data,
2302 struct ap_config *ap_config)
2304 uint64_t action_mask = ap_config->action_mask;
2308 memset(ap_data->offset, 0, sizeof(ap_data->offset));
2311 for (action = 0; action < RTE_TABLE_ACTION_MAX; action++)
2312 if (action_mask & (1LLU << action)) {
2313 ap_data->offset[action] = offset;
2314 offset += action_data_size((enum rte_table_action_type)action,
2318 ap_data->total_size = offset;
2321 struct rte_table_action_profile {
2322 struct ap_config cfg;
2323 struct ap_data data;
2327 struct rte_table_action_profile *
2328 rte_table_action_profile_create(struct rte_table_action_common_config *common)
2330 struct rte_table_action_profile *ap;
2332 /* Check input arguments */
2336 /* Memory allocation */
2337 ap = calloc(1, sizeof(struct rte_table_action_profile));
2341 /* Initialization */
2342 memcpy(&ap->cfg.common, common, sizeof(*common));
2349 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
2350 enum rte_table_action_type type,
2351 void *action_config)
2355 /* Check input arguments */
2356 if ((profile == NULL) ||
2358 (action_valid(type) == 0) ||
2359 (profile->cfg.action_mask & (1LLU << type)) ||
2360 ((action_cfg_size(type) == 0) && action_config) ||
2361 (action_cfg_size(type) && (action_config == NULL)))
2365 case RTE_TABLE_ACTION_LB:
2366 status = lb_cfg_check(action_config);
2369 case RTE_TABLE_ACTION_MTR:
2370 status = mtr_cfg_check(action_config);
2373 case RTE_TABLE_ACTION_TM:
2374 status = tm_cfg_check(action_config);
2377 case RTE_TABLE_ACTION_ENCAP:
2378 status = encap_cfg_check(action_config);
2381 case RTE_TABLE_ACTION_NAT:
2382 status = nat_cfg_check(action_config);
2385 case RTE_TABLE_ACTION_TTL:
2386 status = ttl_cfg_check(action_config);
2389 case RTE_TABLE_ACTION_STATS:
2390 status = stats_cfg_check(action_config);
2393 case RTE_TABLE_ACTION_SYM_CRYPTO:
2394 status = sym_crypto_cfg_check(action_config);
2406 action_cfg_set(&profile->cfg, type, action_config);
2412 rte_table_action_profile_freeze(struct rte_table_action_profile *profile)
2414 if (profile->frozen)
2417 profile->cfg.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
2418 action_data_offset_set(&profile->data, &profile->cfg);
2419 profile->frozen = 1;
2425 rte_table_action_profile_free(struct rte_table_action_profile *profile)
2427 if (profile == NULL)
2437 #define METER_PROFILES_MAX 32
2439 struct rte_table_action {
2440 struct ap_config cfg;
2441 struct ap_data data;
2442 struct dscp_table_data dscp_table;
2443 struct meter_profile_data mp[METER_PROFILES_MAX];
2446 struct rte_table_action *
2447 rte_table_action_create(struct rte_table_action_profile *profile,
2450 struct rte_table_action *action;
2452 /* Check input arguments */
2453 if ((profile == NULL) ||
2454 (profile->frozen == 0))
2457 /* Memory allocation */
2458 action = rte_zmalloc_socket(NULL,
2459 sizeof(struct rte_table_action),
2460 RTE_CACHE_LINE_SIZE,
2465 /* Initialization */
2466 memcpy(&action->cfg, &profile->cfg, sizeof(profile->cfg));
2467 memcpy(&action->data, &profile->data, sizeof(profile->data));
2472 static __rte_always_inline void *
2473 action_data_get(void *data,
2474 struct rte_table_action *action,
2475 enum rte_table_action_type type)
2477 size_t offset = action->data.offset[type];
2478 uint8_t *data_bytes = data;
2480 return &data_bytes[offset];
2484 rte_table_action_apply(struct rte_table_action *action,
2486 enum rte_table_action_type type,
2487 void *action_params)
2491 /* Check input arguments */
2492 if ((action == NULL) ||
2494 (action_valid(type) == 0) ||
2495 ((action->cfg.action_mask & (1LLU << type)) == 0) ||
2496 (action_params == NULL))
2500 action_data = action_data_get(data, action, type);
2503 case RTE_TABLE_ACTION_FWD:
2504 return fwd_apply(action_data,
2507 case RTE_TABLE_ACTION_LB:
2508 return lb_apply(action_data,
2511 case RTE_TABLE_ACTION_MTR:
2512 return mtr_apply(action_data,
2516 RTE_DIM(action->mp));
2518 case RTE_TABLE_ACTION_TM:
2519 return tm_apply(action_data,
2523 case RTE_TABLE_ACTION_ENCAP:
2524 return encap_apply(action_data,
2527 &action->cfg.common);
2529 case RTE_TABLE_ACTION_NAT:
2530 return nat_apply(action_data,
2532 &action->cfg.common);
2534 case RTE_TABLE_ACTION_TTL:
2535 return ttl_apply(action_data,
2538 case RTE_TABLE_ACTION_STATS:
2539 return stats_apply(action_data,
2542 case RTE_TABLE_ACTION_TIME:
2543 return time_apply(action_data,
2546 case RTE_TABLE_ACTION_SYM_CRYPTO:
2547 return sym_crypto_apply(action_data,
2548 &action->cfg.sym_crypto,
2551 case RTE_TABLE_ACTION_TAG:
2552 return tag_apply(action_data,
2555 case RTE_TABLE_ACTION_DECAP:
2556 return decap_apply(action_data,
2565 rte_table_action_dscp_table_update(struct rte_table_action *action,
2567 struct rte_table_action_dscp_table *table)
2571 /* Check input arguments */
2572 if ((action == NULL) ||
2573 ((action->cfg.action_mask & ((1LLU << RTE_TABLE_ACTION_MTR) |
2574 (1LLU << RTE_TABLE_ACTION_TM))) == 0) ||
2579 for (i = 0; i < RTE_DIM(table->entry); i++) {
2580 struct dscp_table_entry_data *data =
2581 &action->dscp_table.entry[i];
2582 struct rte_table_action_dscp_table_entry *entry =
2584 uint16_t queue_tc_color =
2585 MBUF_SCHED_QUEUE_TC_COLOR(entry->tc_queue_id,
2589 if ((dscp_mask & (1LLU << i)) == 0)
2592 data->color = entry->color;
2593 data->tc = entry->tc_id;
2594 data->queue_tc_color = queue_tc_color;
2601 rte_table_action_meter_profile_add(struct rte_table_action *action,
2602 uint32_t meter_profile_id,
2603 struct rte_table_action_meter_profile *profile)
2605 struct meter_profile_data *mp_data;
2608 /* Check input arguments */
2609 if ((action == NULL) ||
2610 ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
2614 if (profile->alg != RTE_TABLE_ACTION_METER_TRTCM)
2617 mp_data = meter_profile_data_find(action->mp,
2618 RTE_DIM(action->mp),
2623 mp_data = meter_profile_data_find_unused(action->mp,
2624 RTE_DIM(action->mp));
2628 /* Install new profile */
2629 status = rte_meter_trtcm_profile_config(&mp_data->profile,
2634 mp_data->profile_id = meter_profile_id;
2641 rte_table_action_meter_profile_delete(struct rte_table_action *action,
2642 uint32_t meter_profile_id)
2644 struct meter_profile_data *mp_data;
2646 /* Check input arguments */
2647 if ((action == NULL) ||
2648 ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0))
2651 mp_data = meter_profile_data_find(action->mp,
2652 RTE_DIM(action->mp),
2657 /* Uninstall profile */
2664 rte_table_action_meter_read(struct rte_table_action *action,
2667 struct rte_table_action_mtr_counters *stats,
2670 struct mtr_trtcm_data *mtr_data;
2673 /* Check input arguments */
2674 if ((action == NULL) ||
2675 ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
2677 (tc_mask > RTE_LEN2MASK(action->cfg.mtr.n_tc, uint32_t)))
2680 mtr_data = action_data_get(data, action, RTE_TABLE_ACTION_MTR);
2684 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
2685 struct rte_table_action_mtr_counters_tc *dst =
2687 struct mtr_trtcm_data *src = &mtr_data[i];
2689 if ((tc_mask & (1 << i)) == 0)
2692 dst->n_packets[e_RTE_METER_GREEN] =
2693 mtr_trtcm_data_stats_get(src, e_RTE_METER_GREEN);
2695 dst->n_packets[e_RTE_METER_YELLOW] =
2696 mtr_trtcm_data_stats_get(src, e_RTE_METER_YELLOW);
2698 dst->n_packets[e_RTE_METER_RED] =
2699 mtr_trtcm_data_stats_get(src, e_RTE_METER_RED);
2701 dst->n_packets_valid = 1;
2702 dst->n_bytes_valid = 0;
2705 stats->tc_mask = tc_mask;
2710 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
2711 struct mtr_trtcm_data *src = &mtr_data[i];
2713 if ((tc_mask & (1 << i)) == 0)
2716 mtr_trtcm_data_stats_reset(src, e_RTE_METER_GREEN);
2717 mtr_trtcm_data_stats_reset(src, e_RTE_METER_YELLOW);
2718 mtr_trtcm_data_stats_reset(src, e_RTE_METER_RED);
2726 rte_table_action_ttl_read(struct rte_table_action *action,
2728 struct rte_table_action_ttl_counters *stats,
2731 struct ttl_data *ttl_data;
2733 /* Check input arguments */
2734 if ((action == NULL) ||
2735 ((action->cfg.action_mask &
2736 (1LLU << RTE_TABLE_ACTION_TTL)) == 0) ||
2740 ttl_data = action_data_get(data, action, RTE_TABLE_ACTION_TTL);
2744 stats->n_packets = TTL_STATS_READ(ttl_data);
2748 TTL_STATS_RESET(ttl_data);
2754 rte_table_action_stats_read(struct rte_table_action *action,
2756 struct rte_table_action_stats_counters *stats,
2759 struct stats_data *stats_data;
2761 /* Check input arguments */
2762 if ((action == NULL) ||
2763 ((action->cfg.action_mask &
2764 (1LLU << RTE_TABLE_ACTION_STATS)) == 0) ||
2768 stats_data = action_data_get(data, action,
2769 RTE_TABLE_ACTION_STATS);
2773 stats->n_packets = stats_data->n_packets;
2774 stats->n_bytes = stats_data->n_bytes;
2775 stats->n_packets_valid = 1;
2776 stats->n_bytes_valid = 1;
2781 stats_data->n_packets = 0;
2782 stats_data->n_bytes = 0;
2789 rte_table_action_time_read(struct rte_table_action *action,
2791 uint64_t *timestamp)
2793 struct time_data *time_data;
2795 /* Check input arguments */
2796 if ((action == NULL) ||
2797 ((action->cfg.action_mask &
2798 (1LLU << RTE_TABLE_ACTION_TIME)) == 0) ||
2800 (timestamp == NULL))
2803 time_data = action_data_get(data, action, RTE_TABLE_ACTION_TIME);
2806 *timestamp = time_data->time;
2811 struct rte_cryptodev_sym_session *
2812 rte_table_action_crypto_sym_session_get(struct rte_table_action *action,
2815 struct sym_crypto_data *sym_crypto_data;
2817 /* Check input arguments */
2818 if ((action == NULL) ||
2819 ((action->cfg.action_mask &
2820 (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) == 0) ||
2824 sym_crypto_data = action_data_get(data, action,
2825 RTE_TABLE_ACTION_SYM_CRYPTO);
2827 return sym_crypto_data->session;
2830 static __rte_always_inline uint64_t
2831 pkt_work(struct rte_mbuf *mbuf,
2832 struct rte_pipeline_table_entry *table_entry,
2834 struct rte_table_action *action,
2835 struct ap_config *cfg)
2837 uint64_t drop_mask = 0;
2839 uint32_t ip_offset = action->cfg.common.ip_offset;
2840 void *ip = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ip_offset);
2843 uint16_t total_length;
2845 if (cfg->common.ip_version) {
2846 struct ipv4_hdr *hdr = ip;
2848 dscp = hdr->type_of_service >> 2;
2849 total_length = rte_ntohs(hdr->total_length);
2851 struct ipv6_hdr *hdr = ip;
2853 dscp = (rte_ntohl(hdr->vtc_flow) & 0x0F600000) >> 18;
2855 rte_ntohs(hdr->payload_len) + sizeof(struct ipv6_hdr);
2858 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
2860 action_data_get(table_entry, action, RTE_TABLE_ACTION_LB);
2866 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
2868 action_data_get(table_entry, action, RTE_TABLE_ACTION_MTR);
2870 drop_mask |= pkt_work_mtr(mbuf,
2872 &action->dscp_table,
2879 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
2881 action_data_get(table_entry, action, RTE_TABLE_ACTION_TM);
2885 &action->dscp_table,
2889 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
2890 void *data = action_data_get(table_entry,
2892 RTE_TABLE_ACTION_DECAP);
2894 pkt_work_decap(mbuf, data);
2897 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
2899 action_data_get(table_entry, action, RTE_TABLE_ACTION_ENCAP);
2901 pkt_work_encap(mbuf,
2909 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
2911 action_data_get(table_entry, action, RTE_TABLE_ACTION_NAT);
2913 if (cfg->common.ip_version)
2914 pkt_ipv4_work_nat(ip, data, &cfg->nat);
2916 pkt_ipv6_work_nat(ip, data, &cfg->nat);
2919 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
2921 action_data_get(table_entry, action, RTE_TABLE_ACTION_TTL);
2923 if (cfg->common.ip_version)
2924 drop_mask |= pkt_ipv4_work_ttl(ip, data);
2926 drop_mask |= pkt_ipv6_work_ttl(ip, data);
2929 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
2931 action_data_get(table_entry, action, RTE_TABLE_ACTION_STATS);
2933 pkt_work_stats(data, total_length);
2936 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
2938 action_data_get(table_entry, action, RTE_TABLE_ACTION_TIME);
2940 pkt_work_time(data, time);
2943 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) {
2944 void *data = action_data_get(table_entry, action,
2945 RTE_TABLE_ACTION_SYM_CRYPTO);
2947 drop_mask |= pkt_work_sym_crypto(mbuf, data, &cfg->sym_crypto,
2951 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TAG)) {
2952 void *data = action_data_get(table_entry,
2954 RTE_TABLE_ACTION_TAG);
2956 pkt_work_tag(mbuf, data);
2962 static __rte_always_inline uint64_t
2963 pkt4_work(struct rte_mbuf **mbufs,
2964 struct rte_pipeline_table_entry **table_entries,
2966 struct rte_table_action *action,
2967 struct ap_config *cfg)
2969 uint64_t drop_mask0 = 0;
2970 uint64_t drop_mask1 = 0;
2971 uint64_t drop_mask2 = 0;
2972 uint64_t drop_mask3 = 0;
2974 struct rte_mbuf *mbuf0 = mbufs[0];
2975 struct rte_mbuf *mbuf1 = mbufs[1];
2976 struct rte_mbuf *mbuf2 = mbufs[2];
2977 struct rte_mbuf *mbuf3 = mbufs[3];
2979 struct rte_pipeline_table_entry *table_entry0 = table_entries[0];
2980 struct rte_pipeline_table_entry *table_entry1 = table_entries[1];
2981 struct rte_pipeline_table_entry *table_entry2 = table_entries[2];
2982 struct rte_pipeline_table_entry *table_entry3 = table_entries[3];
2984 uint32_t ip_offset = action->cfg.common.ip_offset;
2985 void *ip0 = RTE_MBUF_METADATA_UINT32_PTR(mbuf0, ip_offset);
2986 void *ip1 = RTE_MBUF_METADATA_UINT32_PTR(mbuf1, ip_offset);
2987 void *ip2 = RTE_MBUF_METADATA_UINT32_PTR(mbuf2, ip_offset);
2988 void *ip3 = RTE_MBUF_METADATA_UINT32_PTR(mbuf3, ip_offset);
2990 uint32_t dscp0, dscp1, dscp2, dscp3;
2991 uint16_t total_length0, total_length1, total_length2, total_length3;
2993 if (cfg->common.ip_version) {
2994 struct ipv4_hdr *hdr0 = ip0;
2995 struct ipv4_hdr *hdr1 = ip1;
2996 struct ipv4_hdr *hdr2 = ip2;
2997 struct ipv4_hdr *hdr3 = ip3;
2999 dscp0 = hdr0->type_of_service >> 2;
3000 dscp1 = hdr1->type_of_service >> 2;
3001 dscp2 = hdr2->type_of_service >> 2;
3002 dscp3 = hdr3->type_of_service >> 2;
3004 total_length0 = rte_ntohs(hdr0->total_length);
3005 total_length1 = rte_ntohs(hdr1->total_length);
3006 total_length2 = rte_ntohs(hdr2->total_length);
3007 total_length3 = rte_ntohs(hdr3->total_length);
3009 struct ipv6_hdr *hdr0 = ip0;
3010 struct ipv6_hdr *hdr1 = ip1;
3011 struct ipv6_hdr *hdr2 = ip2;
3012 struct ipv6_hdr *hdr3 = ip3;
3014 dscp0 = (rte_ntohl(hdr0->vtc_flow) & 0x0F600000) >> 18;
3015 dscp1 = (rte_ntohl(hdr1->vtc_flow) & 0x0F600000) >> 18;
3016 dscp2 = (rte_ntohl(hdr2->vtc_flow) & 0x0F600000) >> 18;
3017 dscp3 = (rte_ntohl(hdr3->vtc_flow) & 0x0F600000) >> 18;
3020 rte_ntohs(hdr0->payload_len) + sizeof(struct ipv6_hdr);
3022 rte_ntohs(hdr1->payload_len) + sizeof(struct ipv6_hdr);
3024 rte_ntohs(hdr2->payload_len) + sizeof(struct ipv6_hdr);
3026 rte_ntohs(hdr3->payload_len) + sizeof(struct ipv6_hdr);
3029 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
3031 action_data_get(table_entry0, action, RTE_TABLE_ACTION_LB);
3033 action_data_get(table_entry1, action, RTE_TABLE_ACTION_LB);
3035 action_data_get(table_entry2, action, RTE_TABLE_ACTION_LB);
3037 action_data_get(table_entry3, action, RTE_TABLE_ACTION_LB);
3056 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
3058 action_data_get(table_entry0, action, RTE_TABLE_ACTION_MTR);
3060 action_data_get(table_entry1, action, RTE_TABLE_ACTION_MTR);
3062 action_data_get(table_entry2, action, RTE_TABLE_ACTION_MTR);
3064 action_data_get(table_entry3, action, RTE_TABLE_ACTION_MTR);
3066 drop_mask0 |= pkt_work_mtr(mbuf0,
3068 &action->dscp_table,
3074 drop_mask1 |= pkt_work_mtr(mbuf1,
3076 &action->dscp_table,
3082 drop_mask2 |= pkt_work_mtr(mbuf2,
3084 &action->dscp_table,
3090 drop_mask3 |= pkt_work_mtr(mbuf3,
3092 &action->dscp_table,
3099 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
3101 action_data_get(table_entry0, action, RTE_TABLE_ACTION_TM);
3103 action_data_get(table_entry1, action, RTE_TABLE_ACTION_TM);
3105 action_data_get(table_entry2, action, RTE_TABLE_ACTION_TM);
3107 action_data_get(table_entry3, action, RTE_TABLE_ACTION_TM);
3111 &action->dscp_table,
3116 &action->dscp_table,
3121 &action->dscp_table,
3126 &action->dscp_table,
3130 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
3131 void *data0 = action_data_get(table_entry0,
3133 RTE_TABLE_ACTION_DECAP);
3134 void *data1 = action_data_get(table_entry1,
3136 RTE_TABLE_ACTION_DECAP);
3137 void *data2 = action_data_get(table_entry2,
3139 RTE_TABLE_ACTION_DECAP);
3140 void *data3 = action_data_get(table_entry3,
3142 RTE_TABLE_ACTION_DECAP);
3144 pkt4_work_decap(mbuf0, mbuf1, mbuf2, mbuf3,
3145 data0, data1, data2, data3);
3148 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
3150 action_data_get(table_entry0, action, RTE_TABLE_ACTION_ENCAP);
3152 action_data_get(table_entry1, action, RTE_TABLE_ACTION_ENCAP);
3154 action_data_get(table_entry2, action, RTE_TABLE_ACTION_ENCAP);
3156 action_data_get(table_entry3, action, RTE_TABLE_ACTION_ENCAP);
3158 pkt_work_encap(mbuf0,
3165 pkt_work_encap(mbuf1,
3172 pkt_work_encap(mbuf2,
3179 pkt_work_encap(mbuf3,
3187 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
3189 action_data_get(table_entry0, action, RTE_TABLE_ACTION_NAT);
3191 action_data_get(table_entry1, action, RTE_TABLE_ACTION_NAT);
3193 action_data_get(table_entry2, action, RTE_TABLE_ACTION_NAT);
3195 action_data_get(table_entry3, action, RTE_TABLE_ACTION_NAT);
3197 if (cfg->common.ip_version) {
3198 pkt_ipv4_work_nat(ip0, data0, &cfg->nat);
3199 pkt_ipv4_work_nat(ip1, data1, &cfg->nat);
3200 pkt_ipv4_work_nat(ip2, data2, &cfg->nat);
3201 pkt_ipv4_work_nat(ip3, data3, &cfg->nat);
3203 pkt_ipv6_work_nat(ip0, data0, &cfg->nat);
3204 pkt_ipv6_work_nat(ip1, data1, &cfg->nat);
3205 pkt_ipv6_work_nat(ip2, data2, &cfg->nat);
3206 pkt_ipv6_work_nat(ip3, data3, &cfg->nat);
3210 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
3212 action_data_get(table_entry0, action, RTE_TABLE_ACTION_TTL);
3214 action_data_get(table_entry1, action, RTE_TABLE_ACTION_TTL);
3216 action_data_get(table_entry2, action, RTE_TABLE_ACTION_TTL);
3218 action_data_get(table_entry3, action, RTE_TABLE_ACTION_TTL);
3220 if (cfg->common.ip_version) {
3221 drop_mask0 |= pkt_ipv4_work_ttl(ip0, data0);
3222 drop_mask1 |= pkt_ipv4_work_ttl(ip1, data1);
3223 drop_mask2 |= pkt_ipv4_work_ttl(ip2, data2);
3224 drop_mask3 |= pkt_ipv4_work_ttl(ip3, data3);
3226 drop_mask0 |= pkt_ipv6_work_ttl(ip0, data0);
3227 drop_mask1 |= pkt_ipv6_work_ttl(ip1, data1);
3228 drop_mask2 |= pkt_ipv6_work_ttl(ip2, data2);
3229 drop_mask3 |= pkt_ipv6_work_ttl(ip3, data3);
3233 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
3235 action_data_get(table_entry0, action, RTE_TABLE_ACTION_STATS);
3237 action_data_get(table_entry1, action, RTE_TABLE_ACTION_STATS);
3239 action_data_get(table_entry2, action, RTE_TABLE_ACTION_STATS);
3241 action_data_get(table_entry3, action, RTE_TABLE_ACTION_STATS);
3243 pkt_work_stats(data0, total_length0);
3244 pkt_work_stats(data1, total_length1);
3245 pkt_work_stats(data2, total_length2);
3246 pkt_work_stats(data3, total_length3);
3249 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
3251 action_data_get(table_entry0, action, RTE_TABLE_ACTION_TIME);
3253 action_data_get(table_entry1, action, RTE_TABLE_ACTION_TIME);
3255 action_data_get(table_entry2, action, RTE_TABLE_ACTION_TIME);
3257 action_data_get(table_entry3, action, RTE_TABLE_ACTION_TIME);
3259 pkt_work_time(data0, time);
3260 pkt_work_time(data1, time);
3261 pkt_work_time(data2, time);
3262 pkt_work_time(data3, time);
3265 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) {
3266 void *data0 = action_data_get(table_entry0, action,
3267 RTE_TABLE_ACTION_SYM_CRYPTO);
3268 void *data1 = action_data_get(table_entry1, action,
3269 RTE_TABLE_ACTION_SYM_CRYPTO);
3270 void *data2 = action_data_get(table_entry2, action,
3271 RTE_TABLE_ACTION_SYM_CRYPTO);
3272 void *data3 = action_data_get(table_entry3, action,
3273 RTE_TABLE_ACTION_SYM_CRYPTO);
3275 drop_mask0 |= pkt_work_sym_crypto(mbuf0, data0, &cfg->sym_crypto,
3277 drop_mask1 |= pkt_work_sym_crypto(mbuf1, data1, &cfg->sym_crypto,
3279 drop_mask2 |= pkt_work_sym_crypto(mbuf2, data2, &cfg->sym_crypto,
3281 drop_mask3 |= pkt_work_sym_crypto(mbuf3, data3, &cfg->sym_crypto,
3285 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TAG)) {
3286 void *data0 = action_data_get(table_entry0,
3288 RTE_TABLE_ACTION_TAG);
3289 void *data1 = action_data_get(table_entry1,
3291 RTE_TABLE_ACTION_TAG);
3292 void *data2 = action_data_get(table_entry2,
3294 RTE_TABLE_ACTION_TAG);
3295 void *data3 = action_data_get(table_entry3,
3297 RTE_TABLE_ACTION_TAG);
3299 pkt4_work_tag(mbuf0, mbuf1, mbuf2, mbuf3,
3300 data0, data1, data2, data3);
3309 static __rte_always_inline int
3310 ah(struct rte_pipeline *p,
3311 struct rte_mbuf **pkts,
3313 struct rte_pipeline_table_entry **entries,
3314 struct rte_table_action *action,
3315 struct ap_config *cfg)
3317 uint64_t pkts_drop_mask = 0;
3320 if (cfg->action_mask & ((1LLU << RTE_TABLE_ACTION_MTR) |
3321 (1LLU << RTE_TABLE_ACTION_TIME)))
3324 if ((pkts_mask & (pkts_mask + 1)) == 0) {
3325 uint64_t n_pkts = __builtin_popcountll(pkts_mask);
3328 for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4) {
3331 drop_mask = pkt4_work(&pkts[i],
3337 pkts_drop_mask |= drop_mask << i;
3340 for ( ; i < n_pkts; i++) {
3343 drop_mask = pkt_work(pkts[i],
3349 pkts_drop_mask |= drop_mask << i;
3352 for ( ; pkts_mask; ) {
3353 uint32_t pos = __builtin_ctzll(pkts_mask);
3354 uint64_t pkt_mask = 1LLU << pos;
3357 drop_mask = pkt_work(pkts[pos],
3363 pkts_mask &= ~pkt_mask;
3364 pkts_drop_mask |= drop_mask << pos;
3367 rte_pipeline_ah_packet_drop(p, pkts_drop_mask);
3373 ah_default(struct rte_pipeline *p,
3374 struct rte_mbuf **pkts,
3376 struct rte_pipeline_table_entry **entries,
3379 struct rte_table_action *action = arg;
3389 static rte_pipeline_table_action_handler_hit
3390 ah_selector(struct rte_table_action *action)
3392 if (action->cfg.action_mask == (1LLU << RTE_TABLE_ACTION_FWD))
3399 rte_table_action_table_params_get(struct rte_table_action *action,
3400 struct rte_pipeline_table_params *params)
3402 rte_pipeline_table_action_handler_hit f_action_hit;
3403 uint32_t total_size;
3405 /* Check input arguments */
3406 if ((action == NULL) ||
3410 f_action_hit = ah_selector(action);
3411 total_size = rte_align32pow2(action->data.total_size);
3413 /* Fill in params */
3414 params->f_action_hit = f_action_hit;
3415 params->f_action_miss = NULL;
3416 params->arg_ah = (f_action_hit) ? action : NULL;
3417 params->action_data_size = total_size -
3418 sizeof(struct rte_pipeline_table_entry);
3424 rte_table_action_free(struct rte_table_action *action)