1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
8 #include <rte_common.h>
9 #include <rte_byteorder.h>
10 #include <rte_cycles.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_ether.h>
19 #include "rte_table_action.h"
21 #define rte_htons rte_cpu_to_be_16
22 #define rte_htonl rte_cpu_to_be_32
24 #define rte_ntohs rte_be_to_cpu_16
25 #define rte_ntohl rte_be_to_cpu_32
28 * RTE_TABLE_ACTION_FWD
30 #define fwd_data rte_pipeline_table_entry
33 fwd_apply(struct fwd_data *data,
34 struct rte_table_action_fwd_params *p)
36 data->action = p->action;
38 if (p->action == RTE_PIPELINE_ACTION_PORT)
39 data->port_id = p->id;
41 if (p->action == RTE_PIPELINE_ACTION_TABLE)
42 data->table_id = p->id;
48 * RTE_TABLE_ACTION_MTR
51 mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
53 if ((mtr->alg == RTE_TABLE_ACTION_METER_SRTCM) ||
54 ((mtr->n_tc != 1) && (mtr->n_tc != 4)) ||
55 (mtr->n_bytes_enabled != 0))
60 #define MBUF_SCHED_QUEUE_TC_COLOR(queue, tc, color) \
61 ((uint16_t)((((uint64_t)(queue)) & 0x3) | \
62 ((((uint64_t)(tc)) & 0x3) << 2) | \
63 ((((uint64_t)(color)) & 0x3) << 4)))
65 #define MBUF_SCHED_COLOR(sched, color) \
66 (((sched) & (~0x30LLU)) | ((color) << 4))
68 struct mtr_trtcm_data {
69 struct rte_meter_trtcm trtcm;
70 uint64_t stats[e_RTE_METER_COLORS];
71 } __attribute__((__packed__));
73 #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data) \
74 (((data)->stats[e_RTE_METER_GREEN] & 0xF8LLU) >> 3)
77 mtr_trtcm_data_meter_profile_id_set(struct mtr_trtcm_data *data,
80 data->stats[e_RTE_METER_GREEN] &= ~0xF8LLU;
81 data->stats[e_RTE_METER_GREEN] |= (profile_id % 32) << 3;
84 #define MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color)\
85 (((data)->stats[(color)] & 4LLU) >> 2)
87 #define MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color)\
88 ((enum rte_meter_color)((data)->stats[(color)] & 3LLU))
91 mtr_trtcm_data_policer_action_set(struct mtr_trtcm_data *data,
92 enum rte_meter_color color,
93 enum rte_table_action_policer action)
95 if (action == RTE_TABLE_ACTION_POLICER_DROP) {
96 data->stats[color] |= 4LLU;
98 data->stats[color] &= ~7LLU;
99 data->stats[color] |= color & 3LLU;
104 mtr_trtcm_data_stats_get(struct mtr_trtcm_data *data,
105 enum rte_meter_color color)
107 return data->stats[color] >> 8;
111 mtr_trtcm_data_stats_reset(struct mtr_trtcm_data *data,
112 enum rte_meter_color color)
114 data->stats[color] &= 0xFFLU;
117 #define MTR_TRTCM_DATA_STATS_INC(data, color) \
118 ((data)->stats[(color)] += (1LLU << 8))
121 mtr_data_size(struct rte_table_action_mtr_config *mtr)
123 return mtr->n_tc * sizeof(struct mtr_trtcm_data);
126 struct dscp_table_entry_data {
127 enum rte_meter_color color;
129 uint16_t queue_tc_color;
132 struct dscp_table_data {
133 struct dscp_table_entry_data entry[64];
136 struct meter_profile_data {
137 struct rte_meter_trtcm_profile profile;
142 static struct meter_profile_data *
143 meter_profile_data_find(struct meter_profile_data *mp,
149 for (i = 0; i < mp_size; i++) {
150 struct meter_profile_data *mp_data = &mp[i];
152 if (mp_data->valid && (mp_data->profile_id == profile_id))
159 static struct meter_profile_data *
160 meter_profile_data_find_unused(struct meter_profile_data *mp,
165 for (i = 0; i < mp_size; i++) {
166 struct meter_profile_data *mp_data = &mp[i];
176 mtr_apply_check(struct rte_table_action_mtr_params *p,
177 struct rte_table_action_mtr_config *cfg,
178 struct meter_profile_data *mp,
183 if (p->tc_mask > RTE_LEN2MASK(cfg->n_tc, uint32_t))
186 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
187 struct rte_table_action_mtr_tc_params *p_tc = &p->mtr[i];
188 struct meter_profile_data *mp_data;
190 if ((p->tc_mask & (1LLU << i)) == 0)
193 mp_data = meter_profile_data_find(mp,
195 p_tc->meter_profile_id);
204 mtr_apply(struct mtr_trtcm_data *data,
205 struct rte_table_action_mtr_params *p,
206 struct rte_table_action_mtr_config *cfg,
207 struct meter_profile_data *mp,
213 /* Check input arguments */
214 status = mtr_apply_check(p, cfg, mp, mp_size);
219 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
220 struct rte_table_action_mtr_tc_params *p_tc = &p->mtr[i];
221 struct mtr_trtcm_data *data_tc = &data[i];
222 struct meter_profile_data *mp_data;
224 if ((p->tc_mask & (1LLU << i)) == 0)
228 mp_data = meter_profile_data_find(mp,
230 p_tc->meter_profile_id);
234 memset(data_tc, 0, sizeof(*data_tc));
237 status = rte_meter_trtcm_config(&data_tc->trtcm,
243 mtr_trtcm_data_meter_profile_id_set(data_tc,
246 /* Policer actions */
247 mtr_trtcm_data_policer_action_set(data_tc,
249 p_tc->policer[e_RTE_METER_GREEN]);
251 mtr_trtcm_data_policer_action_set(data_tc,
253 p_tc->policer[e_RTE_METER_YELLOW]);
255 mtr_trtcm_data_policer_action_set(data_tc,
257 p_tc->policer[e_RTE_METER_RED]);
263 static __rte_always_inline uint64_t
264 pkt_work_mtr(struct rte_mbuf *mbuf,
265 struct mtr_trtcm_data *data,
266 struct dscp_table_data *dscp_table,
267 struct meter_profile_data *mp,
270 uint16_t total_length)
272 uint64_t drop_mask, sched;
273 uint64_t *sched_ptr = (uint64_t *) &mbuf->hash.sched;
274 struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
275 enum rte_meter_color color_in, color_meter, color_policer;
279 color_in = dscp_entry->color;
281 mp_id = MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data);
285 color_meter = rte_meter_trtcm_color_aware_check(
293 MTR_TRTCM_DATA_STATS_INC(data, color_meter);
296 drop_mask = MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color_meter);
298 MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color_meter);
299 *sched_ptr = MBUF_SCHED_COLOR(sched, color_policer);
305 * RTE_TABLE_ACTION_TM
308 tm_cfg_check(struct rte_table_action_tm_config *tm)
310 if ((tm->n_subports_per_port == 0) ||
311 (rte_is_power_of_2(tm->n_subports_per_port) == 0) ||
312 (tm->n_subports_per_port > UINT16_MAX) ||
313 (tm->n_pipes_per_subport == 0) ||
314 (rte_is_power_of_2(tm->n_pipes_per_subport) == 0))
321 uint16_t queue_tc_color;
324 } __attribute__((__packed__));
327 tm_apply_check(struct rte_table_action_tm_params *p,
328 struct rte_table_action_tm_config *cfg)
330 if ((p->subport_id >= cfg->n_subports_per_port) ||
331 (p->pipe_id >= cfg->n_pipes_per_subport))
338 tm_apply(struct tm_data *data,
339 struct rte_table_action_tm_params *p,
340 struct rte_table_action_tm_config *cfg)
344 /* Check input arguments */
345 status = tm_apply_check(p, cfg);
350 data->queue_tc_color = 0;
351 data->subport = (uint16_t) p->subport_id;
352 data->pipe = p->pipe_id;
357 static __rte_always_inline void
358 pkt_work_tm(struct rte_mbuf *mbuf,
359 struct tm_data *data,
360 struct dscp_table_data *dscp_table,
363 struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
364 struct tm_data *sched_ptr = (struct tm_data *) &mbuf->hash.sched;
365 struct tm_data sched;
368 sched.queue_tc_color = dscp_entry->queue_tc_color;
373 * RTE_TABLE_ACTION_ENCAP
376 encap_valid(enum rte_table_action_encap_type encap)
379 case RTE_TABLE_ACTION_ENCAP_ETHER:
380 case RTE_TABLE_ACTION_ENCAP_VLAN:
381 case RTE_TABLE_ACTION_ENCAP_QINQ:
382 case RTE_TABLE_ACTION_ENCAP_MPLS:
383 case RTE_TABLE_ACTION_ENCAP_PPPOE:
391 encap_cfg_check(struct rte_table_action_encap_config *encap)
393 if ((encap->encap_mask == 0) ||
394 (__builtin_popcountll(encap->encap_mask) != 1))
400 struct encap_ether_data {
401 struct ether_hdr ether;
402 } __attribute__((__packed__));
404 #define VLAN(pcp, dei, vid) \
405 ((uint16_t)((((uint64_t)(pcp)) & 0x7LLU) << 13) | \
406 ((((uint64_t)(dei)) & 0x1LLU) << 12) | \
407 (((uint64_t)(vid)) & 0xFFFLLU)) \
409 struct encap_vlan_data {
410 struct ether_hdr ether;
411 struct vlan_hdr vlan;
412 } __attribute__((__packed__));
414 struct encap_qinq_data {
415 struct ether_hdr ether;
416 struct vlan_hdr svlan;
417 struct vlan_hdr cvlan;
418 } __attribute__((__packed__));
420 #define ETHER_TYPE_MPLS_UNICAST 0x8847
422 #define ETHER_TYPE_MPLS_MULTICAST 0x8848
424 #define MPLS(label, tc, s, ttl) \
425 ((uint32_t)(((((uint64_t)(label)) & 0xFFFFFLLU) << 12) |\
426 ((((uint64_t)(tc)) & 0x7LLU) << 9) | \
427 ((((uint64_t)(s)) & 0x1LLU) << 8) | \
428 (((uint64_t)(ttl)) & 0xFFLLU)))
430 struct encap_mpls_data {
431 struct ether_hdr ether;
432 uint32_t mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
434 } __attribute__((__packed__));
436 #define ETHER_TYPE_PPPOE_SESSION 0x8864
438 #define PPP_PROTOCOL_IP 0x0021
440 struct pppoe_ppp_hdr {
441 uint16_t ver_type_code;
445 } __attribute__((__packed__));
447 struct encap_pppoe_data {
448 struct ether_hdr ether;
449 struct pppoe_ppp_hdr pppoe_ppp;
450 } __attribute__((__packed__));
453 encap_data_size(struct rte_table_action_encap_config *encap)
455 switch (encap->encap_mask) {
456 case 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER:
457 return sizeof(struct encap_ether_data);
459 case 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN:
460 return sizeof(struct encap_vlan_data);
462 case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ:
463 return sizeof(struct encap_qinq_data);
465 case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
466 return sizeof(struct encap_mpls_data);
468 case 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE:
469 return sizeof(struct encap_pppoe_data);
477 encap_apply_check(struct rte_table_action_encap_params *p,
478 struct rte_table_action_encap_config *cfg)
480 if ((encap_valid(p->type) == 0) ||
481 ((cfg->encap_mask & (1LLU << p->type)) == 0))
485 case RTE_TABLE_ACTION_ENCAP_ETHER:
488 case RTE_TABLE_ACTION_ENCAP_VLAN:
491 case RTE_TABLE_ACTION_ENCAP_QINQ:
494 case RTE_TABLE_ACTION_ENCAP_MPLS:
495 if ((p->mpls.mpls_count == 0) ||
496 (p->mpls.mpls_count > RTE_TABLE_ACTION_MPLS_LABELS_MAX))
501 case RTE_TABLE_ACTION_ENCAP_PPPOE:
510 encap_ether_apply(void *data,
511 struct rte_table_action_encap_params *p,
512 struct rte_table_action_common_config *common_cfg)
514 struct encap_ether_data *d = data;
515 uint16_t ethertype = (common_cfg->ip_version) ?
520 ether_addr_copy(&p->ether.ether.da, &d->ether.d_addr);
521 ether_addr_copy(&p->ether.ether.sa, &d->ether.s_addr);
522 d->ether.ether_type = rte_htons(ethertype);
528 encap_vlan_apply(void *data,
529 struct rte_table_action_encap_params *p,
530 struct rte_table_action_common_config *common_cfg)
532 struct encap_vlan_data *d = data;
533 uint16_t ethertype = (common_cfg->ip_version) ?
538 ether_addr_copy(&p->vlan.ether.da, &d->ether.d_addr);
539 ether_addr_copy(&p->vlan.ether.sa, &d->ether.s_addr);
540 d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
543 d->vlan.vlan_tci = rte_htons(VLAN(p->vlan.vlan.pcp,
546 d->vlan.eth_proto = rte_htons(ethertype);
552 encap_qinq_apply(void *data,
553 struct rte_table_action_encap_params *p,
554 struct rte_table_action_common_config *common_cfg)
556 struct encap_qinq_data *d = data;
557 uint16_t ethertype = (common_cfg->ip_version) ?
562 ether_addr_copy(&p->qinq.ether.da, &d->ether.d_addr);
563 ether_addr_copy(&p->qinq.ether.sa, &d->ether.s_addr);
564 d->ether.ether_type = rte_htons(ETHER_TYPE_QINQ);
567 d->svlan.vlan_tci = rte_htons(VLAN(p->qinq.svlan.pcp,
570 d->svlan.eth_proto = rte_htons(ETHER_TYPE_VLAN);
573 d->cvlan.vlan_tci = rte_htons(VLAN(p->qinq.cvlan.pcp,
576 d->cvlan.eth_proto = rte_htons(ethertype);
582 encap_mpls_apply(void *data,
583 struct rte_table_action_encap_params *p)
585 struct encap_mpls_data *d = data;
586 uint16_t ethertype = (p->mpls.unicast) ?
587 ETHER_TYPE_MPLS_UNICAST :
588 ETHER_TYPE_MPLS_MULTICAST;
592 ether_addr_copy(&p->mpls.ether.da, &d->ether.d_addr);
593 ether_addr_copy(&p->mpls.ether.sa, &d->ether.s_addr);
594 d->ether.ether_type = rte_htons(ethertype);
597 for (i = 0; i < p->mpls.mpls_count - 1; i++)
598 d->mpls[i] = rte_htonl(MPLS(p->mpls.mpls[i].label,
601 p->mpls.mpls[i].ttl));
603 d->mpls[i] = rte_htonl(MPLS(p->mpls.mpls[i].label,
606 p->mpls.mpls[i].ttl));
608 d->mpls_count = p->mpls.mpls_count;
613 encap_pppoe_apply(void *data,
614 struct rte_table_action_encap_params *p)
616 struct encap_pppoe_data *d = data;
619 ether_addr_copy(&p->pppoe.ether.da, &d->ether.d_addr);
620 ether_addr_copy(&p->pppoe.ether.sa, &d->ether.s_addr);
621 d->ether.ether_type = rte_htons(ETHER_TYPE_PPPOE_SESSION);
624 d->pppoe_ppp.ver_type_code = rte_htons(0x1100);
625 d->pppoe_ppp.session_id = rte_htons(p->pppoe.pppoe.session_id);
626 d->pppoe_ppp.length = 0; /* not pre-computed */
627 d->pppoe_ppp.protocol = rte_htons(PPP_PROTOCOL_IP);
633 encap_apply(void *data,
634 struct rte_table_action_encap_params *p,
635 struct rte_table_action_encap_config *cfg,
636 struct rte_table_action_common_config *common_cfg)
640 /* Check input arguments */
641 status = encap_apply_check(p, cfg);
646 case RTE_TABLE_ACTION_ENCAP_ETHER:
647 return encap_ether_apply(data, p, common_cfg);
649 case RTE_TABLE_ACTION_ENCAP_VLAN:
650 return encap_vlan_apply(data, p, common_cfg);
652 case RTE_TABLE_ACTION_ENCAP_QINQ:
653 return encap_qinq_apply(data, p, common_cfg);
655 case RTE_TABLE_ACTION_ENCAP_MPLS:
656 return encap_mpls_apply(data, p);
658 case RTE_TABLE_ACTION_ENCAP_PPPOE:
659 return encap_pppoe_apply(data, p);
666 static __rte_always_inline void *
667 encap(void *dst, const void *src, size_t n)
669 dst = ((uint8_t *) dst) - n;
670 return rte_memcpy(dst, src, n);
673 static __rte_always_inline void
674 pkt_work_encap(struct rte_mbuf *mbuf,
676 struct rte_table_action_encap_config *cfg,
678 uint16_t total_length,
681 switch (cfg->encap_mask) {
682 case 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER:
683 encap(ip, data, sizeof(struct encap_ether_data));
684 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
685 sizeof(struct encap_ether_data));
686 mbuf->pkt_len = mbuf->data_len = total_length +
687 sizeof(struct encap_ether_data);
690 case 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN:
691 encap(ip, data, sizeof(struct encap_vlan_data));
692 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
693 sizeof(struct encap_vlan_data));
694 mbuf->pkt_len = mbuf->data_len = total_length +
695 sizeof(struct encap_vlan_data);
698 case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ:
699 encap(ip, data, sizeof(struct encap_qinq_data));
700 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
701 sizeof(struct encap_qinq_data));
702 mbuf->pkt_len = mbuf->data_len = total_length +
703 sizeof(struct encap_qinq_data);
706 case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
708 struct encap_mpls_data *mpls = data;
709 size_t size = sizeof(struct ether_hdr) +
710 mpls->mpls_count * 4;
712 encap(ip, data, size);
713 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) + size);
714 mbuf->pkt_len = mbuf->data_len = total_length + size;
718 case 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE:
720 struct encap_pppoe_data *pppoe =
721 encap(ip, data, sizeof(struct encap_pppoe_data));
722 pppoe->pppoe_ppp.length = rte_htons(total_length + 2);
723 mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
724 sizeof(struct encap_pppoe_data));
725 mbuf->pkt_len = mbuf->data_len = total_length +
726 sizeof(struct encap_pppoe_data);
736 * RTE_TABLE_ACTION_NAT
739 nat_cfg_check(struct rte_table_action_nat_config *nat)
741 if ((nat->proto != 0x06) &&
742 (nat->proto != 0x11))
748 struct nat_ipv4_data {
751 } __attribute__((__packed__));
753 struct nat_ipv6_data {
756 } __attribute__((__packed__));
759 nat_data_size(struct rte_table_action_nat_config *nat __rte_unused,
760 struct rte_table_action_common_config *common)
762 int ip_version = common->ip_version;
764 return (ip_version) ?
765 sizeof(struct nat_ipv4_data) :
766 sizeof(struct nat_ipv6_data);
770 nat_apply_check(struct rte_table_action_nat_params *p,
771 struct rte_table_action_common_config *cfg)
773 if ((p->ip_version && (cfg->ip_version == 0)) ||
774 ((p->ip_version == 0) && cfg->ip_version))
781 nat_apply(void *data,
782 struct rte_table_action_nat_params *p,
783 struct rte_table_action_common_config *cfg)
787 /* Check input arguments */
788 status = nat_apply_check(p, cfg);
794 struct nat_ipv4_data *d = data;
796 d->addr = rte_htonl(p->addr.ipv4);
797 d->port = rte_htons(p->port);
799 struct nat_ipv6_data *d = data;
801 memcpy(d->addr, p->addr.ipv6, sizeof(d->addr));
802 d->port = rte_htons(p->port);
808 static __rte_always_inline uint16_t
809 nat_ipv4_checksum_update(uint16_t cksum0,
816 cksum1 = ~cksum1 & 0xFFFF;
818 /* Subtract ip0 (one's complement logic) */
819 cksum1 -= (ip0 >> 16) + (ip0 & 0xFFFF);
820 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
821 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
823 /* Add ip1 (one's complement logic) */
824 cksum1 += (ip1 >> 16) + (ip1 & 0xFFFF);
825 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
826 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
828 return (uint16_t)(~cksum1);
831 static __rte_always_inline uint16_t
832 nat_ipv4_tcp_udp_checksum_update(uint16_t cksum0,
841 cksum1 = ~cksum1 & 0xFFFF;
843 /* Subtract ip0 and port 0 (one's complement logic) */
844 cksum1 -= (ip0 >> 16) + (ip0 & 0xFFFF) + port0;
845 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
846 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
848 /* Add ip1 and port1 (one's complement logic) */
849 cksum1 += (ip1 >> 16) + (ip1 & 0xFFFF) + port1;
850 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
851 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
853 return (uint16_t)(~cksum1);
856 static __rte_always_inline uint16_t
857 nat_ipv6_tcp_udp_checksum_update(uint16_t cksum0,
866 cksum1 = ~cksum1 & 0xFFFF;
868 /* Subtract ip0 and port 0 (one's complement logic) */
869 cksum1 -= ip0[0] + ip0[1] + ip0[2] + ip0[3] +
870 ip0[4] + ip0[5] + ip0[6] + ip0[7] + port0;
871 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
872 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
874 /* Add ip1 and port1 (one's complement logic) */
875 cksum1 += ip1[0] + ip1[1] + ip1[2] + ip1[3] +
876 ip1[4] + ip1[5] + ip1[6] + ip1[7] + port1;
877 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
878 cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
880 return (uint16_t)(~cksum1);
883 static __rte_always_inline void
884 pkt_ipv4_work_nat(struct ipv4_hdr *ip,
885 struct nat_ipv4_data *data,
886 struct rte_table_action_nat_config *cfg)
888 if (cfg->source_nat) {
889 if (cfg->proto == 0x6) {
890 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
891 uint16_t ip_cksum, tcp_cksum;
893 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
897 tcp_cksum = nat_ipv4_tcp_udp_checksum_update(tcp->cksum,
903 ip->src_addr = data->addr;
904 ip->hdr_checksum = ip_cksum;
905 tcp->src_port = data->port;
906 tcp->cksum = tcp_cksum;
908 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
909 uint16_t ip_cksum, udp_cksum;
911 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
915 udp_cksum = nat_ipv4_tcp_udp_checksum_update(udp->dgram_cksum,
921 ip->src_addr = data->addr;
922 ip->hdr_checksum = ip_cksum;
923 udp->src_port = data->port;
924 if (udp->dgram_cksum)
925 udp->dgram_cksum = udp_cksum;
928 if (cfg->proto == 0x6) {
929 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
930 uint16_t ip_cksum, tcp_cksum;
932 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
936 tcp_cksum = nat_ipv4_tcp_udp_checksum_update(tcp->cksum,
942 ip->dst_addr = data->addr;
943 ip->hdr_checksum = ip_cksum;
944 tcp->dst_port = data->port;
945 tcp->cksum = tcp_cksum;
947 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
948 uint16_t ip_cksum, udp_cksum;
950 ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
954 udp_cksum = nat_ipv4_tcp_udp_checksum_update(udp->dgram_cksum,
960 ip->dst_addr = data->addr;
961 ip->hdr_checksum = ip_cksum;
962 udp->dst_port = data->port;
963 if (udp->dgram_cksum)
964 udp->dgram_cksum = udp_cksum;
969 static __rte_always_inline void
970 pkt_ipv6_work_nat(struct ipv6_hdr *ip,
971 struct nat_ipv6_data *data,
972 struct rte_table_action_nat_config *cfg)
974 if (cfg->source_nat) {
975 if (cfg->proto == 0x6) {
976 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
979 tcp_cksum = nat_ipv6_tcp_udp_checksum_update(tcp->cksum,
980 (uint16_t *)ip->src_addr,
981 (uint16_t *)data->addr,
985 rte_memcpy(ip->src_addr, data->addr, 16);
986 tcp->src_port = data->port;
987 tcp->cksum = tcp_cksum;
989 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
992 udp_cksum = nat_ipv6_tcp_udp_checksum_update(udp->dgram_cksum,
993 (uint16_t *)ip->src_addr,
994 (uint16_t *)data->addr,
998 rte_memcpy(ip->src_addr, data->addr, 16);
999 udp->src_port = data->port;
1000 udp->dgram_cksum = udp_cksum;
1003 if (cfg->proto == 0x6) {
1004 struct tcp_hdr *tcp = (struct tcp_hdr *) &ip[1];
1007 tcp_cksum = nat_ipv6_tcp_udp_checksum_update(tcp->cksum,
1008 (uint16_t *)ip->dst_addr,
1009 (uint16_t *)data->addr,
1013 rte_memcpy(ip->dst_addr, data->addr, 16);
1014 tcp->dst_port = data->port;
1015 tcp->cksum = tcp_cksum;
1017 struct udp_hdr *udp = (struct udp_hdr *) &ip[1];
1020 udp_cksum = nat_ipv6_tcp_udp_checksum_update(udp->dgram_cksum,
1021 (uint16_t *)ip->dst_addr,
1022 (uint16_t *)data->addr,
1026 rte_memcpy(ip->dst_addr, data->addr, 16);
1027 udp->dst_port = data->port;
1028 udp->dgram_cksum = udp_cksum;
1034 * RTE_TABLE_ACTION_TTL
1037 ttl_cfg_check(struct rte_table_action_ttl_config *ttl)
1047 } __attribute__((__packed__));
1049 #define TTL_INIT(data, decrement) \
1050 ((data)->n_packets = (decrement) ? 1 : 0)
1052 #define TTL_DEC_GET(data) \
1053 ((uint8_t)((data)->n_packets & 1))
1055 #define TTL_STATS_RESET(data) \
1056 ((data)->n_packets = ((data)->n_packets & 1))
1058 #define TTL_STATS_READ(data) \
1059 ((data)->n_packets >> 1)
1061 #define TTL_STATS_ADD(data, value) \
1062 ((data)->n_packets = \
1063 (((((data)->n_packets >> 1) + (value)) << 1) | \
1064 ((data)->n_packets & 1)))
1067 ttl_apply(void *data,
1068 struct rte_table_action_ttl_params *p)
1070 struct ttl_data *d = data;
1072 TTL_INIT(d, p->decrement);
1077 static __rte_always_inline uint64_t
1078 pkt_ipv4_work_ttl(struct ipv4_hdr *ip,
1079 struct ttl_data *data)
1082 uint16_t cksum = ip->hdr_checksum;
1083 uint8_t ttl = ip->time_to_live;
1084 uint8_t ttl_diff = TTL_DEC_GET(data);
1089 ip->hdr_checksum = cksum;
1090 ip->time_to_live = ttl;
1092 drop = (ttl == 0) ? 1 : 0;
1093 TTL_STATS_ADD(data, drop);
1098 static __rte_always_inline uint64_t
1099 pkt_ipv6_work_ttl(struct ipv6_hdr *ip,
1100 struct ttl_data *data)
1103 uint8_t ttl = ip->hop_limits;
1104 uint8_t ttl_diff = TTL_DEC_GET(data);
1108 ip->hop_limits = ttl;
1110 drop = (ttl == 0) ? 1 : 0;
1111 TTL_STATS_ADD(data, drop);
1117 * RTE_TABLE_ACTION_STATS
1120 stats_cfg_check(struct rte_table_action_stats_config *stats)
1122 if ((stats->n_packets_enabled == 0) && (stats->n_bytes_enabled == 0))
1131 } __attribute__((__packed__));
1134 stats_apply(struct stats_data *data,
1135 struct rte_table_action_stats_params *p)
1137 data->n_packets = p->n_packets;
1138 data->n_bytes = p->n_bytes;
1143 static __rte_always_inline void
1144 pkt_work_stats(struct stats_data *data,
1145 uint16_t total_length)
1148 data->n_bytes += total_length;
1155 action_valid(enum rte_table_action_type action)
1158 case RTE_TABLE_ACTION_FWD:
1159 case RTE_TABLE_ACTION_MTR:
1160 case RTE_TABLE_ACTION_TM:
1161 case RTE_TABLE_ACTION_ENCAP:
1162 case RTE_TABLE_ACTION_NAT:
1163 case RTE_TABLE_ACTION_TTL:
1164 case RTE_TABLE_ACTION_STATS:
1172 #define RTE_TABLE_ACTION_MAX 64
1175 uint64_t action_mask;
1176 struct rte_table_action_common_config common;
1177 struct rte_table_action_mtr_config mtr;
1178 struct rte_table_action_tm_config tm;
1179 struct rte_table_action_encap_config encap;
1180 struct rte_table_action_nat_config nat;
1181 struct rte_table_action_ttl_config ttl;
1182 struct rte_table_action_stats_config stats;
1186 action_cfg_size(enum rte_table_action_type action)
1189 case RTE_TABLE_ACTION_MTR:
1190 return sizeof(struct rte_table_action_mtr_config);
1191 case RTE_TABLE_ACTION_TM:
1192 return sizeof(struct rte_table_action_tm_config);
1193 case RTE_TABLE_ACTION_ENCAP:
1194 return sizeof(struct rte_table_action_encap_config);
1195 case RTE_TABLE_ACTION_NAT:
1196 return sizeof(struct rte_table_action_nat_config);
1197 case RTE_TABLE_ACTION_TTL:
1198 return sizeof(struct rte_table_action_ttl_config);
1199 case RTE_TABLE_ACTION_STATS:
1200 return sizeof(struct rte_table_action_stats_config);
1207 action_cfg_get(struct ap_config *ap_config,
1208 enum rte_table_action_type type)
1211 case RTE_TABLE_ACTION_MTR:
1212 return &ap_config->mtr;
1214 case RTE_TABLE_ACTION_TM:
1215 return &ap_config->tm;
1217 case RTE_TABLE_ACTION_ENCAP:
1218 return &ap_config->encap;
1220 case RTE_TABLE_ACTION_NAT:
1221 return &ap_config->nat;
1223 case RTE_TABLE_ACTION_TTL:
1224 return &ap_config->ttl;
1226 case RTE_TABLE_ACTION_STATS:
1227 return &ap_config->stats;
1235 action_cfg_set(struct ap_config *ap_config,
1236 enum rte_table_action_type type,
1239 void *dst = action_cfg_get(ap_config, type);
1242 memcpy(dst, action_cfg, action_cfg_size(type));
1244 ap_config->action_mask |= 1LLU << type;
1248 size_t offset[RTE_TABLE_ACTION_MAX];
1253 action_data_size(enum rte_table_action_type action,
1254 struct ap_config *ap_config)
1257 case RTE_TABLE_ACTION_FWD:
1258 return sizeof(struct fwd_data);
1260 case RTE_TABLE_ACTION_MTR:
1261 return mtr_data_size(&ap_config->mtr);
1263 case RTE_TABLE_ACTION_TM:
1264 return sizeof(struct tm_data);
1266 case RTE_TABLE_ACTION_ENCAP:
1267 return encap_data_size(&ap_config->encap);
1269 case RTE_TABLE_ACTION_NAT:
1270 return nat_data_size(&ap_config->nat,
1271 &ap_config->common);
1273 case RTE_TABLE_ACTION_TTL:
1274 return sizeof(struct ttl_data);
1276 case RTE_TABLE_ACTION_STATS:
1277 return sizeof(struct stats_data);
1286 action_data_offset_set(struct ap_data *ap_data,
1287 struct ap_config *ap_config)
1289 uint64_t action_mask = ap_config->action_mask;
1293 memset(ap_data->offset, 0, sizeof(ap_data->offset));
1296 for (action = 0; action < RTE_TABLE_ACTION_MAX; action++)
1297 if (action_mask & (1LLU << action)) {
1298 ap_data->offset[action] = offset;
1299 offset += action_data_size((enum rte_table_action_type)action,
1303 ap_data->total_size = offset;
1306 struct rte_table_action_profile {
1307 struct ap_config cfg;
1308 struct ap_data data;
1312 struct rte_table_action_profile *
1313 rte_table_action_profile_create(struct rte_table_action_common_config *common)
1315 struct rte_table_action_profile *ap;
1317 /* Check input arguments */
1321 /* Memory allocation */
1322 ap = calloc(1, sizeof(struct rte_table_action_profile));
1326 /* Initialization */
1327 memcpy(&ap->cfg.common, common, sizeof(*common));
1334 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
1335 enum rte_table_action_type type,
1336 void *action_config)
1340 /* Check input arguments */
1341 if ((profile == NULL) ||
1343 (action_valid(type) == 0) ||
1344 (profile->cfg.action_mask & (1LLU << type)) ||
1345 ((action_cfg_size(type) == 0) && action_config) ||
1346 (action_cfg_size(type) && (action_config == NULL)))
1350 case RTE_TABLE_ACTION_MTR:
1351 status = mtr_cfg_check(action_config);
1354 case RTE_TABLE_ACTION_TM:
1355 status = tm_cfg_check(action_config);
1358 case RTE_TABLE_ACTION_ENCAP:
1359 status = encap_cfg_check(action_config);
1362 case RTE_TABLE_ACTION_NAT:
1363 status = nat_cfg_check(action_config);
1366 case RTE_TABLE_ACTION_TTL:
1367 status = ttl_cfg_check(action_config);
1370 case RTE_TABLE_ACTION_STATS:
1371 status = stats_cfg_check(action_config);
1383 action_cfg_set(&profile->cfg, type, action_config);
1389 rte_table_action_profile_freeze(struct rte_table_action_profile *profile)
1391 if (profile->frozen)
1394 profile->cfg.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1395 action_data_offset_set(&profile->data, &profile->cfg);
1396 profile->frozen = 1;
1402 rte_table_action_profile_free(struct rte_table_action_profile *profile)
1404 if (profile == NULL)
1414 #define METER_PROFILES_MAX 32
1416 struct rte_table_action {
1417 struct ap_config cfg;
1418 struct ap_data data;
1419 struct dscp_table_data dscp_table;
1420 struct meter_profile_data mp[METER_PROFILES_MAX];
1423 struct rte_table_action *
1424 rte_table_action_create(struct rte_table_action_profile *profile,
1427 struct rte_table_action *action;
1429 /* Check input arguments */
1430 if ((profile == NULL) ||
1431 (profile->frozen == 0))
1434 /* Memory allocation */
1435 action = rte_zmalloc_socket(NULL,
1436 sizeof(struct rte_table_action),
1437 RTE_CACHE_LINE_SIZE,
1442 /* Initialization */
1443 memcpy(&action->cfg, &profile->cfg, sizeof(profile->cfg));
1444 memcpy(&action->data, &profile->data, sizeof(profile->data));
1449 static __rte_always_inline void *
1450 action_data_get(void *data,
1451 struct rte_table_action *action,
1452 enum rte_table_action_type type)
1454 size_t offset = action->data.offset[type];
1455 uint8_t *data_bytes = data;
1457 return &data_bytes[offset];
1461 rte_table_action_apply(struct rte_table_action *action,
1463 enum rte_table_action_type type,
1464 void *action_params)
1468 /* Check input arguments */
1469 if ((action == NULL) ||
1471 (action_valid(type) == 0) ||
1472 ((action->cfg.action_mask & (1LLU << type)) == 0) ||
1473 (action_params == NULL))
1477 action_data = action_data_get(data, action, type);
1480 case RTE_TABLE_ACTION_FWD:
1481 return fwd_apply(action_data,
1484 case RTE_TABLE_ACTION_MTR:
1485 return mtr_apply(action_data,
1489 RTE_DIM(action->mp));
1491 case RTE_TABLE_ACTION_TM:
1492 return tm_apply(action_data,
1496 case RTE_TABLE_ACTION_ENCAP:
1497 return encap_apply(action_data,
1500 &action->cfg.common);
1502 case RTE_TABLE_ACTION_NAT:
1503 return nat_apply(action_data,
1505 &action->cfg.common);
1507 case RTE_TABLE_ACTION_TTL:
1508 return ttl_apply(action_data,
1511 case RTE_TABLE_ACTION_STATS:
1512 return stats_apply(action_data,
1521 rte_table_action_dscp_table_update(struct rte_table_action *action,
1523 struct rte_table_action_dscp_table *table)
1527 /* Check input arguments */
1528 if ((action == NULL) ||
1529 ((action->cfg.action_mask & ((1LLU << RTE_TABLE_ACTION_MTR) |
1530 (1LLU << RTE_TABLE_ACTION_TM))) == 0) ||
1535 for (i = 0; i < RTE_DIM(table->entry); i++) {
1536 struct dscp_table_entry_data *data =
1537 &action->dscp_table.entry[i];
1538 struct rte_table_action_dscp_table_entry *entry =
1540 uint16_t queue_tc_color =
1541 MBUF_SCHED_QUEUE_TC_COLOR(entry->tc_queue_id,
1545 if ((dscp_mask & (1LLU << i)) == 0)
1548 data->color = entry->color;
1549 data->tc = entry->tc_id;
1550 data->queue_tc_color = queue_tc_color;
1557 rte_table_action_meter_profile_add(struct rte_table_action *action,
1558 uint32_t meter_profile_id,
1559 struct rte_table_action_meter_profile *profile)
1561 struct meter_profile_data *mp_data;
1564 /* Check input arguments */
1565 if ((action == NULL) ||
1566 ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
1570 if (profile->alg != RTE_TABLE_ACTION_METER_TRTCM)
1573 mp_data = meter_profile_data_find(action->mp,
1574 RTE_DIM(action->mp),
1579 mp_data = meter_profile_data_find_unused(action->mp,
1580 RTE_DIM(action->mp));
1584 /* Install new profile */
1585 status = rte_meter_trtcm_profile_config(&mp_data->profile,
1590 mp_data->profile_id = meter_profile_id;
1597 rte_table_action_meter_profile_delete(struct rte_table_action *action,
1598 uint32_t meter_profile_id)
1600 struct meter_profile_data *mp_data;
1602 /* Check input arguments */
1603 if ((action == NULL) ||
1604 ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0))
1607 mp_data = meter_profile_data_find(action->mp,
1608 RTE_DIM(action->mp),
1613 /* Uninstall profile */
1620 rte_table_action_meter_read(struct rte_table_action *action,
1623 struct rte_table_action_mtr_counters *stats,
1626 struct mtr_trtcm_data *mtr_data;
1629 /* Check input arguments */
1630 if ((action == NULL) ||
1631 ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
1633 (tc_mask > RTE_LEN2MASK(action->cfg.mtr.n_tc, uint32_t)))
1636 mtr_data = action_data_get(data, action, RTE_TABLE_ACTION_MTR);
1640 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
1641 struct rte_table_action_mtr_counters_tc *dst =
1643 struct mtr_trtcm_data *src = &mtr_data[i];
1645 if ((tc_mask & (1 << i)) == 0)
1648 dst->n_packets[e_RTE_METER_GREEN] =
1649 mtr_trtcm_data_stats_get(src, e_RTE_METER_GREEN);
1651 dst->n_packets[e_RTE_METER_YELLOW] =
1652 mtr_trtcm_data_stats_get(src, e_RTE_METER_YELLOW);
1654 dst->n_packets[e_RTE_METER_RED] =
1655 mtr_trtcm_data_stats_get(src, e_RTE_METER_RED);
1657 dst->n_packets_valid = 1;
1658 dst->n_bytes_valid = 0;
1661 stats->tc_mask = tc_mask;
1666 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
1667 struct mtr_trtcm_data *src = &mtr_data[i];
1669 if ((tc_mask & (1 << i)) == 0)
1672 mtr_trtcm_data_stats_reset(src, e_RTE_METER_GREEN);
1673 mtr_trtcm_data_stats_reset(src, e_RTE_METER_YELLOW);
1674 mtr_trtcm_data_stats_reset(src, e_RTE_METER_RED);
1682 rte_table_action_ttl_read(struct rte_table_action *action,
1684 struct rte_table_action_ttl_counters *stats,
1687 struct ttl_data *ttl_data;
1689 /* Check input arguments */
1690 if ((action == NULL) ||
1691 ((action->cfg.action_mask &
1692 (1LLU << RTE_TABLE_ACTION_TTL)) == 0) ||
1696 ttl_data = action_data_get(data, action, RTE_TABLE_ACTION_TTL);
1700 stats->n_packets = TTL_STATS_READ(ttl_data);
1704 TTL_STATS_RESET(ttl_data);
1710 rte_table_action_stats_read(struct rte_table_action *action,
1712 struct rte_table_action_stats_counters *stats,
1715 struct stats_data *stats_data;
1717 /* Check input arguments */
1718 if ((action == NULL) ||
1719 ((action->cfg.action_mask &
1720 (1LLU << RTE_TABLE_ACTION_STATS)) == 0) ||
1724 stats_data = action_data_get(data, action,
1725 RTE_TABLE_ACTION_STATS);
1729 stats->n_packets = stats_data->n_packets;
1730 stats->n_bytes = stats_data->n_bytes;
1731 stats->n_packets_valid = 1;
1732 stats->n_bytes_valid = 1;
1737 stats_data->n_packets = 0;
1738 stats_data->n_bytes = 0;
1744 static __rte_always_inline uint64_t
1745 pkt_work(struct rte_mbuf *mbuf,
1746 struct rte_pipeline_table_entry *table_entry,
1748 struct rte_table_action *action,
1749 struct ap_config *cfg)
1751 uint64_t drop_mask = 0;
1753 uint32_t ip_offset = action->cfg.common.ip_offset;
1754 void *ip = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ip_offset);
1757 uint16_t total_length;
1759 if (cfg->common.ip_version) {
1760 struct ipv4_hdr *hdr = ip;
1762 dscp = hdr->type_of_service >> 2;
1763 total_length = rte_ntohs(hdr->total_length);
1765 struct ipv6_hdr *hdr = ip;
1767 dscp = (rte_ntohl(hdr->vtc_flow) & 0x0F600000) >> 18;
1769 rte_ntohs(hdr->payload_len) + sizeof(struct ipv6_hdr);
1772 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
1774 action_data_get(table_entry, action, RTE_TABLE_ACTION_MTR);
1776 drop_mask |= pkt_work_mtr(mbuf,
1778 &action->dscp_table,
1785 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
1787 action_data_get(table_entry, action, RTE_TABLE_ACTION_TM);
1791 &action->dscp_table,
1795 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
1797 action_data_get(table_entry, action, RTE_TABLE_ACTION_ENCAP);
1799 pkt_work_encap(mbuf,
1807 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
1809 action_data_get(table_entry, action, RTE_TABLE_ACTION_NAT);
1811 if (cfg->common.ip_version)
1812 pkt_ipv4_work_nat(ip, data, &cfg->nat);
1814 pkt_ipv6_work_nat(ip, data, &cfg->nat);
1817 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
1819 action_data_get(table_entry, action, RTE_TABLE_ACTION_TTL);
1821 if (cfg->common.ip_version)
1822 drop_mask |= pkt_ipv4_work_ttl(ip, data);
1824 drop_mask |= pkt_ipv6_work_ttl(ip, data);
1827 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
1829 action_data_get(table_entry, action, RTE_TABLE_ACTION_STATS);
1831 pkt_work_stats(data, total_length);
1837 static __rte_always_inline uint64_t
1838 pkt4_work(struct rte_mbuf **mbufs,
1839 struct rte_pipeline_table_entry **table_entries,
1841 struct rte_table_action *action,
1842 struct ap_config *cfg)
1844 uint64_t drop_mask0 = 0;
1845 uint64_t drop_mask1 = 0;
1846 uint64_t drop_mask2 = 0;
1847 uint64_t drop_mask3 = 0;
1849 struct rte_mbuf *mbuf0 = mbufs[0];
1850 struct rte_mbuf *mbuf1 = mbufs[1];
1851 struct rte_mbuf *mbuf2 = mbufs[2];
1852 struct rte_mbuf *mbuf3 = mbufs[3];
1854 struct rte_pipeline_table_entry *table_entry0 = table_entries[0];
1855 struct rte_pipeline_table_entry *table_entry1 = table_entries[1];
1856 struct rte_pipeline_table_entry *table_entry2 = table_entries[2];
1857 struct rte_pipeline_table_entry *table_entry3 = table_entries[3];
1859 uint32_t ip_offset = action->cfg.common.ip_offset;
1860 void *ip0 = RTE_MBUF_METADATA_UINT32_PTR(mbuf0, ip_offset);
1861 void *ip1 = RTE_MBUF_METADATA_UINT32_PTR(mbuf1, ip_offset);
1862 void *ip2 = RTE_MBUF_METADATA_UINT32_PTR(mbuf2, ip_offset);
1863 void *ip3 = RTE_MBUF_METADATA_UINT32_PTR(mbuf3, ip_offset);
1865 uint32_t dscp0, dscp1, dscp2, dscp3;
1866 uint16_t total_length0, total_length1, total_length2, total_length3;
1868 if (cfg->common.ip_version) {
1869 struct ipv4_hdr *hdr0 = ip0;
1870 struct ipv4_hdr *hdr1 = ip1;
1871 struct ipv4_hdr *hdr2 = ip2;
1872 struct ipv4_hdr *hdr3 = ip3;
1874 dscp0 = hdr0->type_of_service >> 2;
1875 dscp1 = hdr1->type_of_service >> 2;
1876 dscp2 = hdr2->type_of_service >> 2;
1877 dscp3 = hdr3->type_of_service >> 2;
1879 total_length0 = rte_ntohs(hdr0->total_length);
1880 total_length1 = rte_ntohs(hdr1->total_length);
1881 total_length2 = rte_ntohs(hdr2->total_length);
1882 total_length3 = rte_ntohs(hdr3->total_length);
1884 struct ipv6_hdr *hdr0 = ip0;
1885 struct ipv6_hdr *hdr1 = ip1;
1886 struct ipv6_hdr *hdr2 = ip2;
1887 struct ipv6_hdr *hdr3 = ip3;
1889 dscp0 = (rte_ntohl(hdr0->vtc_flow) & 0x0F600000) >> 18;
1890 dscp1 = (rte_ntohl(hdr1->vtc_flow) & 0x0F600000) >> 18;
1891 dscp2 = (rte_ntohl(hdr2->vtc_flow) & 0x0F600000) >> 18;
1892 dscp3 = (rte_ntohl(hdr3->vtc_flow) & 0x0F600000) >> 18;
1895 rte_ntohs(hdr0->payload_len) + sizeof(struct ipv6_hdr);
1897 rte_ntohs(hdr1->payload_len) + sizeof(struct ipv6_hdr);
1899 rte_ntohs(hdr2->payload_len) + sizeof(struct ipv6_hdr);
1901 rte_ntohs(hdr3->payload_len) + sizeof(struct ipv6_hdr);
1904 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
1906 action_data_get(table_entry0, action, RTE_TABLE_ACTION_MTR);
1908 action_data_get(table_entry1, action, RTE_TABLE_ACTION_MTR);
1910 action_data_get(table_entry2, action, RTE_TABLE_ACTION_MTR);
1912 action_data_get(table_entry3, action, RTE_TABLE_ACTION_MTR);
1914 drop_mask0 |= pkt_work_mtr(mbuf0,
1916 &action->dscp_table,
1922 drop_mask1 |= pkt_work_mtr(mbuf1,
1924 &action->dscp_table,
1930 drop_mask2 |= pkt_work_mtr(mbuf2,
1932 &action->dscp_table,
1938 drop_mask3 |= pkt_work_mtr(mbuf3,
1940 &action->dscp_table,
1947 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
1949 action_data_get(table_entry0, action, RTE_TABLE_ACTION_TM);
1951 action_data_get(table_entry1, action, RTE_TABLE_ACTION_TM);
1953 action_data_get(table_entry2, action, RTE_TABLE_ACTION_TM);
1955 action_data_get(table_entry3, action, RTE_TABLE_ACTION_TM);
1959 &action->dscp_table,
1964 &action->dscp_table,
1969 &action->dscp_table,
1974 &action->dscp_table,
1978 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
1980 action_data_get(table_entry0, action, RTE_TABLE_ACTION_ENCAP);
1982 action_data_get(table_entry1, action, RTE_TABLE_ACTION_ENCAP);
1984 action_data_get(table_entry2, action, RTE_TABLE_ACTION_ENCAP);
1986 action_data_get(table_entry3, action, RTE_TABLE_ACTION_ENCAP);
1988 pkt_work_encap(mbuf0,
1995 pkt_work_encap(mbuf1,
2002 pkt_work_encap(mbuf2,
2009 pkt_work_encap(mbuf3,
2017 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
2019 action_data_get(table_entry0, action, RTE_TABLE_ACTION_NAT);
2021 action_data_get(table_entry1, action, RTE_TABLE_ACTION_NAT);
2023 action_data_get(table_entry2, action, RTE_TABLE_ACTION_NAT);
2025 action_data_get(table_entry3, action, RTE_TABLE_ACTION_NAT);
2027 if (cfg->common.ip_version) {
2028 pkt_ipv4_work_nat(ip0, data0, &cfg->nat);
2029 pkt_ipv4_work_nat(ip1, data1, &cfg->nat);
2030 pkt_ipv4_work_nat(ip2, data2, &cfg->nat);
2031 pkt_ipv4_work_nat(ip3, data3, &cfg->nat);
2033 pkt_ipv6_work_nat(ip0, data0, &cfg->nat);
2034 pkt_ipv6_work_nat(ip1, data1, &cfg->nat);
2035 pkt_ipv6_work_nat(ip2, data2, &cfg->nat);
2036 pkt_ipv6_work_nat(ip3, data3, &cfg->nat);
2040 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
2042 action_data_get(table_entry0, action, RTE_TABLE_ACTION_TTL);
2044 action_data_get(table_entry1, action, RTE_TABLE_ACTION_TTL);
2046 action_data_get(table_entry2, action, RTE_TABLE_ACTION_TTL);
2048 action_data_get(table_entry3, action, RTE_TABLE_ACTION_TTL);
2050 if (cfg->common.ip_version) {
2051 drop_mask0 |= pkt_ipv4_work_ttl(ip0, data0);
2052 drop_mask1 |= pkt_ipv4_work_ttl(ip1, data1);
2053 drop_mask2 |= pkt_ipv4_work_ttl(ip2, data2);
2054 drop_mask3 |= pkt_ipv4_work_ttl(ip3, data3);
2056 drop_mask0 |= pkt_ipv6_work_ttl(ip0, data0);
2057 drop_mask1 |= pkt_ipv6_work_ttl(ip1, data1);
2058 drop_mask2 |= pkt_ipv6_work_ttl(ip2, data2);
2059 drop_mask3 |= pkt_ipv6_work_ttl(ip3, data3);
2063 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
2065 action_data_get(table_entry0, action, RTE_TABLE_ACTION_STATS);
2067 action_data_get(table_entry1, action, RTE_TABLE_ACTION_STATS);
2069 action_data_get(table_entry2, action, RTE_TABLE_ACTION_STATS);
2071 action_data_get(table_entry3, action, RTE_TABLE_ACTION_STATS);
2073 pkt_work_stats(data0, total_length0);
2074 pkt_work_stats(data1, total_length1);
2075 pkt_work_stats(data2, total_length2);
2076 pkt_work_stats(data3, total_length3);
2085 static __rte_always_inline int
2086 ah(struct rte_pipeline *p,
2087 struct rte_mbuf **pkts,
2089 struct rte_pipeline_table_entry **entries,
2090 struct rte_table_action *action,
2091 struct ap_config *cfg)
2093 uint64_t pkts_drop_mask = 0;
2096 if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR))
2099 if ((pkts_mask & (pkts_mask + 1)) == 0) {
2100 uint64_t n_pkts = __builtin_popcountll(pkts_mask);
2103 for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4) {
2106 drop_mask = pkt4_work(&pkts[i],
2112 pkts_drop_mask |= drop_mask << i;
2115 for ( ; i < n_pkts; i++) {
2118 drop_mask = pkt_work(pkts[i],
2124 pkts_drop_mask |= drop_mask << i;
2127 for ( ; pkts_mask; ) {
2128 uint32_t pos = __builtin_ctzll(pkts_mask);
2129 uint64_t pkt_mask = 1LLU << pos;
2132 drop_mask = pkt_work(pkts[pos],
2138 pkts_mask &= ~pkt_mask;
2139 pkts_drop_mask |= drop_mask << pos;
2142 rte_pipeline_ah_packet_drop(p, pkts_drop_mask);
2148 ah_default(struct rte_pipeline *p,
2149 struct rte_mbuf **pkts,
2151 struct rte_pipeline_table_entry **entries,
2154 struct rte_table_action *action = arg;
2164 static rte_pipeline_table_action_handler_hit
2165 ah_selector(struct rte_table_action *action)
2167 if (action->cfg.action_mask == (1LLU << RTE_TABLE_ACTION_FWD))
2174 rte_table_action_table_params_get(struct rte_table_action *action,
2175 struct rte_pipeline_table_params *params)
2177 rte_pipeline_table_action_handler_hit f_action_hit;
2178 uint32_t total_size;
2180 /* Check input arguments */
2181 if ((action == NULL) ||
2185 f_action_hit = ah_selector(action);
2186 total_size = rte_align32pow2(action->data.total_size);
2188 /* Fill in params */
2189 params->f_action_hit = f_action_hit;
2190 params->f_action_miss = NULL;
2191 params->arg_ah = (f_action_hit) ? action : NULL;
2192 params->action_data_size = total_size -
2193 sizeof(struct rte_pipeline_table_entry);
2199 rte_table_action_free(struct rte_table_action *action)