ixgbe/base: add flow control ethertype for filtering
[dpdk.git] / examples / l3fwd-acl / main.c
index fce55f3..f676d14 100644 (file)
@@ -80,8 +80,6 @@
 
 #define MEMPOOL_CACHE_SIZE 256
 
-#define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
-
 /*
  * This expression is used to calculate the number of mbufs needed
  * depending on user input, taking into account memory for rx and tx hardware
@@ -218,9 +216,9 @@ send_single_packet(struct rte_mbuf *m, uint8_t port);
 #define OFF_IPV42PROTO (offsetof(struct ipv4_hdr, next_proto_id))
 #define OFF_IPV62PROTO (offsetof(struct ipv6_hdr, proto))
 #define MBUF_IPV4_2PROTO(m)    \
-       (rte_pktmbuf_mtod((m), uint8_t *) + OFF_ETHHEAD + OFF_IPV42PROTO)
+       rte_pktmbuf_mtod_offset((m), uint8_t *, OFF_ETHHEAD + OFF_IPV42PROTO)
 #define MBUF_IPV6_2PROTO(m)    \
-       (rte_pktmbuf_mtod((m), uint8_t *) + OFF_ETHHEAD + OFF_IPV62PROTO)
+       rte_pktmbuf_mtod_offset((m), uint8_t *, OFF_ETHHEAD + OFF_IPV62PROTO)
 
 #define GET_CB_FIELD(in, fd, base, lim, dlm)   do {            \
        unsigned long val;                                      \
@@ -263,6 +261,23 @@ enum {
        NUM_FIELDS_IPV4
 };
 
+/*
+ * That effectively defines order of IPV4VLAN classifications:
+ *  - PROTO
+ *  - VLAN (TAG and DOMAIN)
+ *  - SRC IP ADDRESS
+ *  - DST IP ADDRESS
+ *  - PORTS (SRC and DST)
+ */
+enum {
+       RTE_ACL_IPV4VLAN_PROTO,
+       RTE_ACL_IPV4VLAN_VLAN,
+       RTE_ACL_IPV4VLAN_SRC,
+       RTE_ACL_IPV4VLAN_DST,
+       RTE_ACL_IPV4VLAN_PORTS,
+       RTE_ACL_IPV4VLAN_NUM
+};
+
 struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {
        {
                .type = RTE_ACL_FIELD_TYPE_BITMASK,
@@ -566,9 +581,9 @@ dump_acl4_rule(struct rte_mbuf *m, uint32_t sig)
 {
        uint32_t offset = sig & ~ACL_DENY_SIGNATURE;
        unsigned char a, b, c, d;
-       struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)
-                                       (rte_pktmbuf_mtod(m, unsigned char *) +
-                                       sizeof(struct ether_hdr));
+       struct ipv4_hdr *ipv4_hdr = rte_pktmbuf_mtod_offset(m,
+                                                           struct ipv4_hdr *,
+                                                           sizeof(struct ether_hdr));
 
        uint32_t_to_char(rte_bswap32(ipv4_hdr->src_addr), &a, &b, &c, &d);
        printf("Packet Src:%hhu.%hhu.%hhu.%hhu ", a, b, c, d);
@@ -590,9 +605,9 @@ dump_acl6_rule(struct rte_mbuf *m, uint32_t sig)
 {
        unsigned i;
        uint32_t offset = sig & ~ACL_DENY_SIGNATURE;
-       struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)
-                                       (rte_pktmbuf_mtod(m, unsigned char *) +
-                                       sizeof(struct ether_hdr));
+       struct ipv6_hdr *ipv6_hdr = rte_pktmbuf_mtod_offset(m,
+                                                           struct ipv6_hdr *,
+                                                           sizeof(struct ether_hdr));
 
        printf("Packet Src");
        for (i = 0; i < RTE_DIM(ipv6_hdr->src_addr); i += sizeof(uint16_t))
@@ -647,12 +662,9 @@ prepare_one_packet(struct rte_mbuf **pkts_in, struct acl_search_t *acl,
        struct ipv4_hdr *ipv4_hdr;
        struct rte_mbuf *pkt = pkts_in[index];
 
-       int type = pkt->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR);
-
-       if (type == PKT_RX_IPV4_HDR) {
-
-               ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt,
-                       unsigned char *) + sizeof(struct ether_hdr));
+       if (RTE_ETH_IS_IPV4_HDR(pkt->packet_type)) {
+               ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct ipv4_hdr *,
+                                                  sizeof(struct ether_hdr));
 
                /* Check to make sure the packet is valid (RFC1812) */
                if (is_valid_ipv4_pkt(ipv4_hdr, pkt->pkt_len) >= 0) {
@@ -669,9 +681,7 @@ prepare_one_packet(struct rte_mbuf **pkts_in, struct acl_search_t *acl,
                        /* Not a valid IPv4 packet */
                        rte_pktmbuf_free(pkt);
                }
-
-       } else if (type == PKT_RX_IPV6_HDR) {
-
+       } else if (RTE_ETH_IS_IPV6_HDR(pkt->packet_type)) {
                /* Fill acl structure */
                acl->data_ipv6[acl->num_ipv6] = MBUF_IPV6_2PROTO(pkt);
                acl->m_ipv6[(acl->num_ipv6)++] = pkt;
@@ -689,17 +699,12 @@ prepare_one_packet(struct rte_mbuf **pkts_in, struct acl_search_t *acl,
 {
        struct rte_mbuf *pkt = pkts_in[index];
 
-       int type = pkt->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR);
-
-       if (type == PKT_RX_IPV4_HDR) {
-
+       if (RTE_ETH_IS_IPV4_HDR(pkt->packet_type)) {
                /* Fill acl structure */
                acl->data_ipv4[acl->num_ipv4] = MBUF_IPV4_2PROTO(pkt);
                acl->m_ipv4[(acl->num_ipv4)++] = pkt;
 
-
-       } else if (type == PKT_RX_IPV6_HDR) {
-
+       } else if (RTE_ETH_IS_IPV6_HDR(pkt->packet_type)) {
                /* Fill acl structure */
                acl->data_ipv6[acl->num_ipv6] = MBUF_IPV6_2PROTO(pkt);
                acl->m_ipv6[(acl->num_ipv6)++] = pkt;
@@ -747,9 +752,9 @@ send_one_packet(struct rte_mbuf *m, uint32_t res)
                /* in the ACL list, drop it */
 #ifdef L3FWDACL_DEBUG
                if ((res & ACL_DENY_SIGNATURE) != 0) {
-                       if (m->ol_flags & PKT_RX_IPV4_HDR)
+                       if (RTE_ETH_IS_IPV4_HDR(m->packet_type))
                                dump_acl4_rule(m, res);
-                       else
+                       else if (RTE_ETH_IS_IPV6_HDR(m->packet_type))
                                dump_acl6_rule(m, res);
                }
 #endif
@@ -1848,12 +1853,10 @@ init_mem(unsigned nb_mbuf)
                if (pktmbuf_pool[socketid] == NULL) {
                        snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
                        pktmbuf_pool[socketid] =
-                               rte_mempool_create(s, nb_mbuf, MBUF_SIZE,
-                                       MEMPOOL_CACHE_SIZE,
-                                       sizeof(struct rte_pktmbuf_pool_private),
-                                       rte_pktmbuf_pool_init, NULL,
-                                       rte_pktmbuf_init, NULL,
-                                       socketid, 0);
+                               rte_pktmbuf_pool_create(s, nb_mbuf,
+                                       MEMPOOL_CACHE_SIZE, 0,
+                                       RTE_MBUF_DEFAULT_BUF_SIZE,
+                                       socketid);
                        if (pktmbuf_pool[socketid] == NULL)
                                rte_exit(EXIT_FAILURE,
                                        "Cannot init mbuf pool on socket %d\n",