net: add rte prefix to ether functions
[dpdk.git] / lib / librte_pipeline / rte_table_action.c
index 8a2bb13..a474148 100644 (file)
@@ -109,29 +109,29 @@ mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
 
 struct mtr_trtcm_data {
        struct rte_meter_trtcm trtcm;
-       uint64_t stats[e_RTE_METER_COLORS];
+       uint64_t stats[RTE_COLORS];
 } __attribute__((__packed__));
 
 #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data)          \
-       (((data)->stats[e_RTE_METER_GREEN] & 0xF8LLU) >> 3)
+       (((data)->stats[RTE_COLOR_GREEN] & 0xF8LLU) >> 3)
 
 static void
 mtr_trtcm_data_meter_profile_id_set(struct mtr_trtcm_data *data,
        uint32_t profile_id)
 {
-       data->stats[e_RTE_METER_GREEN] &= ~0xF8LLU;
-       data->stats[e_RTE_METER_GREEN] |= (profile_id % 32) << 3;
+       data->stats[RTE_COLOR_GREEN] &= ~0xF8LLU;
+       data->stats[RTE_COLOR_GREEN] |= (profile_id % 32) << 3;
 }
 
 #define MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color)\
        (((data)->stats[(color)] & 4LLU) >> 2)
 
 #define MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color)\
-       ((enum rte_meter_color)((data)->stats[(color)] & 3LLU))
+       ((enum rte_color)((data)->stats[(color)] & 3LLU))
 
 static void
 mtr_trtcm_data_policer_action_set(struct mtr_trtcm_data *data,
-       enum rte_meter_color color,
+       enum rte_color color,
        enum rte_table_action_policer action)
 {
        if (action == RTE_TABLE_ACTION_POLICER_DROP) {
@@ -144,14 +144,14 @@ mtr_trtcm_data_policer_action_set(struct mtr_trtcm_data *data,
 
 static uint64_t
 mtr_trtcm_data_stats_get(struct mtr_trtcm_data *data,
-       enum rte_meter_color color)
+       enum rte_color color)
 {
        return data->stats[color] >> 8;
 }
 
 static void
 mtr_trtcm_data_stats_reset(struct mtr_trtcm_data *data,
-       enum rte_meter_color color)
+       enum rte_color color)
 {
        data->stats[color] &= 0xFFLU;
 }
@@ -166,7 +166,7 @@ mtr_data_size(struct rte_table_action_mtr_config *mtr)
 }
 
 struct dscp_table_entry_data {
-       enum rte_meter_color color;
+       enum rte_color color;
        uint16_t tc;
        uint16_t tc_queue;
 };
@@ -287,16 +287,16 @@ mtr_apply(struct mtr_trtcm_data *data,
 
                /* Policer actions */
                mtr_trtcm_data_policer_action_set(data_tc,
-                       e_RTE_METER_GREEN,
-                       p_tc->policer[e_RTE_METER_GREEN]);
+                       RTE_COLOR_GREEN,
+                       p_tc->policer[RTE_COLOR_GREEN]);
 
                mtr_trtcm_data_policer_action_set(data_tc,
-                       e_RTE_METER_YELLOW,
-                       p_tc->policer[e_RTE_METER_YELLOW]);
+                       RTE_COLOR_YELLOW,
+                       p_tc->policer[RTE_COLOR_YELLOW]);
 
                mtr_trtcm_data_policer_action_set(data_tc,
-                       e_RTE_METER_RED,
-                       p_tc->policer[e_RTE_METER_RED]);
+                       RTE_COLOR_RED,
+                       p_tc->policer[RTE_COLOR_RED]);
        }
 
        return 0;
@@ -313,7 +313,7 @@ pkt_work_mtr(struct rte_mbuf *mbuf,
 {
        uint64_t drop_mask;
        struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
-       enum rte_meter_color color_in, color_meter, color_policer;
+       enum rte_color color_in, color_meter, color_policer;
        uint32_t tc, mp_id;
 
        tc = dscp_entry->tc;
@@ -420,6 +420,7 @@ encap_valid(enum rte_table_action_encap_type encap)
        case RTE_TABLE_ACTION_ENCAP_MPLS:
        case RTE_TABLE_ACTION_ENCAP_PPPOE:
        case RTE_TABLE_ACTION_ENCAP_VXLAN:
+       case RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
                return 1;
        default:
                return 0;
@@ -437,7 +438,7 @@ encap_cfg_check(struct rte_table_action_encap_config *encap)
 }
 
 struct encap_ether_data {
-       struct ether_hdr ether;
+       struct rte_ether_hdr ether;
 } __attribute__((__packed__));
 
 #define VLAN(pcp, dei, vid)                                \
@@ -446,14 +447,14 @@ struct encap_ether_data {
        (((uint64_t)(vid)) & 0xFFFLLU))                    \
 
 struct encap_vlan_data {
-       struct ether_hdr ether;
-       struct vlan_hdr vlan;
+       struct rte_ether_hdr ether;
+       struct rte_vlan_hdr vlan;
 } __attribute__((__packed__));
 
 struct encap_qinq_data {
-       struct ether_hdr ether;
-       struct vlan_hdr svlan;
-       struct vlan_hdr cvlan;
+       struct rte_ether_hdr ether;
+       struct rte_vlan_hdr svlan;
+       struct rte_vlan_hdr cvlan;
 } __attribute__((__packed__));
 
 #define ETHER_TYPE_MPLS_UNICAST                            0x8847
@@ -467,13 +468,11 @@ struct encap_qinq_data {
        (((uint64_t)(ttl)) & 0xFFLLU)))
 
 struct encap_mpls_data {
-       struct ether_hdr ether;
+       struct rte_ether_hdr ether;
        uint32_t mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
        uint32_t mpls_count;
 } __attribute__((__packed__));
 
-#define ETHER_TYPE_PPPOE_SESSION                           0x8864
-
 #define PPP_PROTOCOL_IP                                    0x0021
 
 struct pppoe_ppp_hdr {
@@ -484,40 +483,47 @@ struct pppoe_ppp_hdr {
 } __attribute__((__packed__));
 
 struct encap_pppoe_data {
-       struct ether_hdr ether;
+       struct rte_ether_hdr ether;
        struct pppoe_ppp_hdr pppoe_ppp;
 } __attribute__((__packed__));
 
 #define IP_PROTO_UDP                                       17
 
 struct encap_vxlan_ipv4_data {
-       struct ether_hdr ether;
+       struct rte_ether_hdr ether;
        struct ipv4_hdr ipv4;
        struct udp_hdr udp;
-       struct vxlan_hdr vxlan;
+       struct rte_vxlan_hdr vxlan;
 } __attribute__((__packed__));
 
 struct encap_vxlan_ipv4_vlan_data {
-       struct ether_hdr ether;
-       struct vlan_hdr vlan;
+       struct rte_ether_hdr ether;
+       struct rte_vlan_hdr vlan;
        struct ipv4_hdr ipv4;
        struct udp_hdr udp;
-       struct vxlan_hdr vxlan;
+       struct rte_vxlan_hdr vxlan;
 } __attribute__((__packed__));
 
 struct encap_vxlan_ipv6_data {
-       struct ether_hdr ether;
+       struct rte_ether_hdr ether;
        struct ipv6_hdr ipv6;
        struct udp_hdr udp;
-       struct vxlan_hdr vxlan;
+       struct rte_vxlan_hdr vxlan;
 } __attribute__((__packed__));
 
 struct encap_vxlan_ipv6_vlan_data {
-       struct ether_hdr ether;
-       struct vlan_hdr vlan;
+       struct rte_ether_hdr ether;
+       struct rte_vlan_hdr vlan;
        struct ipv6_hdr ipv6;
        struct udp_hdr udp;
-       struct vxlan_hdr vxlan;
+       struct rte_vxlan_hdr vxlan;
+} __attribute__((__packed__));
+
+struct encap_qinq_pppoe_data {
+       struct rte_ether_hdr ether;
+       struct rte_vlan_hdr svlan;
+       struct rte_vlan_hdr cvlan;
+       struct pppoe_ppp_hdr pppoe_ppp;
 } __attribute__((__packed__));
 
 static size_t
@@ -551,6 +557,9 @@ encap_data_size(struct rte_table_action_encap_config *encap)
                        else
                                return sizeof(struct encap_vxlan_ipv6_data);
 
+       case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
+                       return sizeof(struct encap_qinq_pppoe_data);
+
        default:
                return 0;
        }
@@ -587,6 +596,9 @@ encap_apply_check(struct rte_table_action_encap_params *p,
        case RTE_TABLE_ACTION_ENCAP_VXLAN:
                return 0;
 
+       case RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
+               return 0;
+
        default:
                return -EINVAL;
        }
@@ -603,8 +615,8 @@ encap_ether_apply(void *data,
                ETHER_TYPE_IPv6;
 
        /* Ethernet */
-       ether_addr_copy(&p->ether.ether.da, &d->ether.d_addr);
-       ether_addr_copy(&p->ether.ether.sa, &d->ether.s_addr);
+       rte_ether_addr_copy(&p->ether.ether.da, &d->ether.d_addr);
+       rte_ether_addr_copy(&p->ether.ether.sa, &d->ether.s_addr);
        d->ether.ether_type = rte_htons(ethertype);
 
        return 0;
@@ -621,8 +633,8 @@ encap_vlan_apply(void *data,
                ETHER_TYPE_IPv6;
 
        /* Ethernet */
-       ether_addr_copy(&p->vlan.ether.da, &d->ether.d_addr);
-       ether_addr_copy(&p->vlan.ether.sa, &d->ether.s_addr);
+       rte_ether_addr_copy(&p->vlan.ether.da, &d->ether.d_addr);
+       rte_ether_addr_copy(&p->vlan.ether.sa, &d->ether.s_addr);
        d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
 
        /* VLAN */
@@ -645,8 +657,8 @@ encap_qinq_apply(void *data,
                ETHER_TYPE_IPv6;
 
        /* Ethernet */
-       ether_addr_copy(&p->qinq.ether.da, &d->ether.d_addr);
-       ether_addr_copy(&p->qinq.ether.sa, &d->ether.s_addr);
+       rte_ether_addr_copy(&p->qinq.ether.da, &d->ether.d_addr);
+       rte_ether_addr_copy(&p->qinq.ether.sa, &d->ether.s_addr);
        d->ether.ether_type = rte_htons(ETHER_TYPE_QINQ);
 
        /* SVLAN */
@@ -664,6 +676,38 @@ encap_qinq_apply(void *data,
        return 0;
 }
 
+static int
+encap_qinq_pppoe_apply(void *data,
+       struct rte_table_action_encap_params *p)
+{
+       struct encap_qinq_pppoe_data *d = data;
+
+       /* Ethernet */
+       rte_ether_addr_copy(&p->qinq.ether.da, &d->ether.d_addr);
+       rte_ether_addr_copy(&p->qinq.ether.sa, &d->ether.s_addr);
+       d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
+
+       /* SVLAN */
+       d->svlan.vlan_tci = rte_htons(VLAN(p->qinq.svlan.pcp,
+               p->qinq.svlan.dei,
+               p->qinq.svlan.vid));
+       d->svlan.eth_proto = rte_htons(ETHER_TYPE_VLAN);
+
+       /* CVLAN */
+       d->cvlan.vlan_tci = rte_htons(VLAN(p->qinq.cvlan.pcp,
+               p->qinq.cvlan.dei,
+               p->qinq.cvlan.vid));
+       d->cvlan.eth_proto = rte_htons(ETHER_TYPE_PPPOE_SESSION);
+
+       /* PPPoE and PPP*/
+       d->pppoe_ppp.ver_type_code = rte_htons(0x1100);
+       d->pppoe_ppp.session_id = rte_htons(p->qinq_pppoe.pppoe.session_id);
+       d->pppoe_ppp.length = 0; /* not pre-computed */
+       d->pppoe_ppp.protocol = rte_htons(PPP_PROTOCOL_IP);
+
+       return 0;
+}
+
 static int
 encap_mpls_apply(void *data,
        struct rte_table_action_encap_params *p)
@@ -675,8 +719,8 @@ encap_mpls_apply(void *data,
        uint32_t i;
 
        /* Ethernet */
-       ether_addr_copy(&p->mpls.ether.da, &d->ether.d_addr);
-       ether_addr_copy(&p->mpls.ether.sa, &d->ether.s_addr);
+       rte_ether_addr_copy(&p->mpls.ether.da, &d->ether.d_addr);
+       rte_ether_addr_copy(&p->mpls.ether.sa, &d->ether.s_addr);
        d->ether.ether_type = rte_htons(ethertype);
 
        /* MPLS */
@@ -702,8 +746,8 @@ encap_pppoe_apply(void *data,
        struct encap_pppoe_data *d = data;
 
        /* Ethernet */
-       ether_addr_copy(&p->pppoe.ether.da, &d->ether.d_addr);
-       ether_addr_copy(&p->pppoe.ether.sa, &d->ether.s_addr);
+       rte_ether_addr_copy(&p->pppoe.ether.da, &d->ether.d_addr);
+       rte_ether_addr_copy(&p->pppoe.ether.sa, &d->ether.s_addr);
        d->ether.ether_type = rte_htons(ETHER_TYPE_PPPOE_SESSION);
 
        /* PPPoE and PPP*/
@@ -732,8 +776,10 @@ encap_vxlan_apply(void *data,
                        struct encap_vxlan_ipv4_vlan_data *d = data;
 
                        /* Ethernet */
-                       ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
-                       ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.da,
+                                       &d->ether.d_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.sa,
+                                       &d->ether.s_addr);
                        d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
 
                        /* VLAN */
@@ -771,8 +817,10 @@ encap_vxlan_apply(void *data,
                        struct encap_vxlan_ipv4_data *d = data;
 
                        /* Ethernet */
-                       ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
-                       ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.da,
+                                       &d->ether.d_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.sa,
+                                       &d->ether.s_addr);
                        d->ether.ether_type = rte_htons(ETHER_TYPE_IPv4);
 
                        /* IPv4*/
@@ -806,8 +854,10 @@ encap_vxlan_apply(void *data,
                        struct encap_vxlan_ipv6_vlan_data *d = data;
 
                        /* Ethernet */
-                       ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
-                       ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.da,
+                                       &d->ether.d_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.sa,
+                                       &d->ether.s_addr);
                        d->ether.ether_type = rte_htons(ETHER_TYPE_VLAN);
 
                        /* VLAN */
@@ -845,8 +895,10 @@ encap_vxlan_apply(void *data,
                        struct encap_vxlan_ipv6_data *d = data;
 
                        /* Ethernet */
-                       ether_addr_copy(&p->vxlan.ether.da, &d->ether.d_addr);
-                       ether_addr_copy(&p->vxlan.ether.sa, &d->ether.s_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.da,
+                                       &d->ether.d_addr);
+                       rte_ether_addr_copy(&p->vxlan.ether.sa,
+                                       &d->ether.s_addr);
                        d->ether.ether_type = rte_htons(ETHER_TYPE_IPv6);
 
                        /* IPv6*/
@@ -909,6 +961,9 @@ encap_apply(void *data,
        case RTE_TABLE_ACTION_ENCAP_VXLAN:
                return encap_vxlan_apply(data, p, cfg);
 
+       case RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
+               return encap_qinq_pppoe_apply(data, p);
+
        default:
                return -EINVAL;
        }
@@ -950,13 +1005,13 @@ pkt_work_encap_vxlan_ipv4(struct rte_mbuf *mbuf,
 
        ether_length = (uint16_t)mbuf->pkt_len;
        ipv4_total_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr) +
                sizeof(struct ipv4_hdr));
        ipv4_hdr_cksum = encap_vxlan_ipv4_checksum_update(vxlan_tbl->ipv4.hdr_checksum,
                rte_htons(ipv4_total_length));
        udp_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr));
 
        vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
@@ -980,13 +1035,13 @@ pkt_work_encap_vxlan_ipv4_vlan(struct rte_mbuf *mbuf,
 
        ether_length = (uint16_t)mbuf->pkt_len;
        ipv4_total_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr) +
                sizeof(struct ipv4_hdr));
        ipv4_hdr_cksum = encap_vxlan_ipv4_checksum_update(vxlan_tbl->ipv4.hdr_checksum,
                rte_htons(ipv4_total_length));
        udp_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr));
 
        vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
@@ -1010,10 +1065,10 @@ pkt_work_encap_vxlan_ipv6(struct rte_mbuf *mbuf,
 
        ether_length = (uint16_t)mbuf->pkt_len;
        ipv6_payload_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr));
        udp_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr));
 
        vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
@@ -1036,10 +1091,10 @@ pkt_work_encap_vxlan_ipv6_vlan(struct rte_mbuf *mbuf,
 
        ether_length = (uint16_t)mbuf->pkt_len;
        ipv6_payload_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr));
        udp_length = ether_length +
-               (sizeof(struct vxlan_hdr) +
+               (sizeof(struct rte_vxlan_hdr) +
                sizeof(struct udp_hdr));
 
        vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
@@ -1086,7 +1141,7 @@ pkt_work_encap(struct rte_mbuf *mbuf,
        case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
        {
                struct encap_mpls_data *mpls = data;
-               size_t size = sizeof(struct ether_hdr) +
+               size_t size = sizeof(struct rte_ether_hdr) +
                        mpls->mpls_count * 4;
 
                encap(ip, data, size);
@@ -1107,6 +1162,18 @@ pkt_work_encap(struct rte_mbuf *mbuf,
                break;
        }
 
+       case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
+       {
+               struct encap_qinq_pppoe_data *qinq_pppoe =
+                       encap(ip, data, sizeof(struct encap_qinq_pppoe_data));
+               qinq_pppoe->pppoe_ppp.length = rte_htons(total_length + 2);
+               mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
+                       sizeof(struct encap_qinq_pppoe_data));
+               mbuf->pkt_len = mbuf->data_len = total_length +
+                       sizeof(struct encap_qinq_pppoe_data);
+               break;
+       }
+
        case 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN:
        {
                if (cfg->vxlan.ip_version)
@@ -2672,14 +2739,14 @@ rte_table_action_meter_read(struct rte_table_action *action,
                        if ((tc_mask & (1 << i)) == 0)
                                continue;
 
-                       dst->n_packets[e_RTE_METER_GREEN] =
-                               mtr_trtcm_data_stats_get(src, e_RTE_METER_GREEN);
+                       dst->n_packets[RTE_COLOR_GREEN] =
+                               mtr_trtcm_data_stats_get(src, RTE_COLOR_GREEN);
 
-                       dst->n_packets[e_RTE_METER_YELLOW] =
-                               mtr_trtcm_data_stats_get(src, e_RTE_METER_YELLOW);
+                       dst->n_packets[RTE_COLOR_YELLOW] =
+                               mtr_trtcm_data_stats_get(src, RTE_COLOR_YELLOW);
 
-                       dst->n_packets[e_RTE_METER_RED] =
-                               mtr_trtcm_data_stats_get(src, e_RTE_METER_RED);
+                       dst->n_packets[RTE_COLOR_RED] =
+                               mtr_trtcm_data_stats_get(src, RTE_COLOR_RED);
 
                        dst->n_packets_valid = 1;
                        dst->n_bytes_valid = 0;
@@ -2696,9 +2763,9 @@ rte_table_action_meter_read(struct rte_table_action *action,
                        if ((tc_mask & (1 << i)) == 0)
                                continue;
 
-                       mtr_trtcm_data_stats_reset(src, e_RTE_METER_GREEN);
-                       mtr_trtcm_data_stats_reset(src, e_RTE_METER_YELLOW);
-                       mtr_trtcm_data_stats_reset(src, e_RTE_METER_RED);
+                       mtr_trtcm_data_stats_reset(src, RTE_COLOR_GREEN);
+                       mtr_trtcm_data_stats_reset(src, RTE_COLOR_YELLOW);
+                       mtr_trtcm_data_stats_reset(src, RTE_COLOR_RED);
                }