#include <rte_memcpy.h>
#include <rte_memzone.h>
#include <rte_launch.h>
-#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#define IP_HDRLEN 0x05 /* default IP header length == five 32-bits words. */
#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
+#define GRE_KEY_PRESENT 0x2000
+#define GRE_KEY_LEN 4
+#define GRE_SUPPORTED_FIELDS GRE_KEY_PRESENT
+
/* We cannot use rte_cpu_to_be_16() on a constant in a switch/case */
#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
#define _htons(x) ((uint16_t)((((x) & 0x00ffU) << 8) | (((x) & 0xff00U) >> 8)))
uint16_t tso_segsz;
};
-/* simplified GRE header (flags must be 0) */
+/* simplified GRE header */
struct simple_gre_hdr {
uint16_t flags;
uint16_t proto;
-};
+} __attribute__((__packed__));
static uint16_t
get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags)
/* Parse a vxlan header */
static void
-parse_vxlan(struct udp_hdr *udp_hdr, struct testpmd_offload_info *info,
- uint64_t mbuf_olflags)
+parse_vxlan(struct udp_hdr *udp_hdr,
+ struct testpmd_offload_info *info,
+ uint32_t pkt_type)
{
struct ether_hdr *eth_hdr;
* (rfc7348) or that the rx offload flag is set (i40e only
* currently) */
if (udp_hdr->dst_port != _htons(4789) &&
- (mbuf_olflags & (PKT_RX_TUNNEL_IPV4_HDR |
- PKT_RX_TUNNEL_IPV6_HDR)) == 0)
+ RTE_ETH_IS_TUNNEL_PKT(pkt_type) == 0)
return;
info->is_tunnel = 1;
struct ether_hdr *eth_hdr;
struct ipv4_hdr *ipv4_hdr;
struct ipv6_hdr *ipv6_hdr;
+ uint8_t gre_len = 0;
- /* if flags != 0; it's not supported */
- if (gre_hdr->flags != 0)
+ /* check which fields are supported */
+ if ((gre_hdr->flags & _htons(~GRE_SUPPORTED_FIELDS)) != 0)
return;
+ gre_len += sizeof(struct simple_gre_hdr);
+
+ if (gre_hdr->flags & _htons(GRE_KEY_PRESENT))
+ gre_len += GRE_KEY_LEN;
+
if (gre_hdr->proto == _htons(ETHER_TYPE_IPv4)) {
info->is_tunnel = 1;
info->outer_ethertype = info->ethertype;
info->outer_l3_len = info->l3_len;
info->outer_l4_proto = info->l4_proto;
- ipv4_hdr = (struct ipv4_hdr *)((char *)gre_hdr +
- sizeof(struct simple_gre_hdr));
+ ipv4_hdr = (struct ipv4_hdr *)((char *)gre_hdr + gre_len);
parse_ipv4(ipv4_hdr, info);
info->ethertype = _htons(ETHER_TYPE_IPv4);
info->outer_l3_len = info->l3_len;
info->outer_l4_proto = info->l4_proto;
- ipv6_hdr = (struct ipv6_hdr *)((char *)gre_hdr +
- sizeof(struct simple_gre_hdr));
+ ipv6_hdr = (struct ipv6_hdr *)((char *)gre_hdr + gre_len);
info->ethertype = _htons(ETHER_TYPE_IPv6);
parse_ipv6(ipv6_hdr, info);
info->l2_len = 0;
- } else if (gre_hdr->proto == _htons(0x6558)) { /* ETH_P_TEB in linux */
+ } else if (gre_hdr->proto == _htons(ETHER_TYPE_TEB)) {
info->is_tunnel = 1;
info->outer_ethertype = info->ethertype;
info->outer_l2_len = info->l2_len;
info->outer_l3_len = info->l3_len;
info->outer_l4_proto = info->l4_proto;
- eth_hdr = (struct ether_hdr *)((char *)gre_hdr +
- sizeof(struct simple_gre_hdr));
+ eth_hdr = (struct ether_hdr *)((char *)gre_hdr + gre_len);
parse_ethernet(eth_hdr, info);
} else
return;
- info->l2_len += sizeof(struct simple_gre_hdr);
+ info->l2_len += gre_len;
+}
+
+
+/* Parse an encapsulated ip or ipv6 header */
+static void
+parse_encap_ip(void *encap_ip, struct testpmd_offload_info *info)
+{
+ struct ipv4_hdr *ipv4_hdr = encap_ip;
+ struct ipv6_hdr *ipv6_hdr = encap_ip;
+ uint8_t ip_version;
+
+ ip_version = (ipv4_hdr->version_ihl & 0xf0) >> 4;
+
+ if (ip_version != 4 && ip_version != 6)
+ return;
+
+ info->is_tunnel = 1;
+ info->outer_ethertype = info->ethertype;
+ info->outer_l2_len = info->l2_len;
+ info->outer_l3_len = info->l3_len;
+
+ if (ip_version == 4) {
+ parse_ipv4(ipv4_hdr, info);
+ info->ethertype = _htons(ETHER_TYPE_IPv4);
+ } else {
+ parse_ipv6(ipv6_hdr, info);
+ info->ethertype = _htons(ETHER_TYPE_IPv6);
+ }
+ info->l2_len = 0;
}
/* modify the IPv4 or IPv4 source address of a packet */
* UDP|TCP|SCTP
* Ether / (vlan) / outer IP|IP6 / GRE / Ether / IP|IP6 / UDP|TCP|SCTP
* Ether / (vlan) / outer IP|IP6 / GRE / IP|IP6 / UDP|TCP|SCTP
+ * Ether / (vlan) / outer IP|IP6 / IP|IP6 / UDP|TCP|SCTP
*
* The testpmd command line for this forward engine sets the flags
* TESTPMD_TX_OFFLOAD_* in ports[tx_port].tx_ol_flags. They control
* and inner headers */
eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+ ether_addr_copy(&peer_eth_addrs[fs->peer_addr],
+ ð_hdr->d_addr);
+ ether_addr_copy(&ports[fs->tx_port].eth_addr,
+ ð_hdr->s_addr);
parse_ethernet(eth_hdr, &info);
l3_hdr = (char *)eth_hdr + info.l2_len;
struct udp_hdr *udp_hdr;
udp_hdr = (struct udp_hdr *)((char *)l3_hdr +
info.l3_len);
- parse_vxlan(udp_hdr, &info, m->ol_flags);
+ parse_vxlan(udp_hdr, &info, m->packet_type);
} else if (info.l4_proto == IPPROTO_GRE) {
struct simple_gre_hdr *gre_hdr;
gre_hdr = (struct simple_gre_hdr *)
((char *)l3_hdr + info.l3_len);
parse_gre(gre_hdr, &info);
+ } else if (info.l4_proto == IPPROTO_IPIP) {
+ void *encap_ip_hdr;
+ encap_ip_hdr = (char *)l3_hdr + info.l3_len;
+ parse_encap_ip(encap_ip_hdr, &info);
}
}
m->outer_l3_len = info.outer_l3_len;
m->l2_len = info.l2_len;
m->l3_len = info.l3_len;
+ m->l4_len = info.l4_len;
}
else {
/* if there is a outer UDP cksum
.port_fwd_end = NULL,
.packet_fwd = pkt_burst_checksum_forward,
};
-