From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id E7B7C2A07 for ; Fri, 15 May 2015 18:08:58 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 15 May 2015 09:08:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,434,1427785200"; d="scan'208";a="695436261" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 15 May 2015 09:08:56 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t4FG8tt5005567; Fri, 15 May 2015 17:08:55 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t4FG8tMF013260; Fri, 15 May 2015 17:08:55 +0100 Received: (from achiliki@localhost) by sivswdev02.ir.intel.com with id t4FG8taQ013256; Fri, 15 May 2015 17:08:55 +0100 From: Andrey Chilikin To: dev@dpdk.org Date: Fri, 15 May 2015 17:08:52 +0100 Message-Id: <1431706132-13223-1-git-send-email-andrey.chilikin@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 May 2015 16:08:59 -0000 Added optional ip version check to l3fwd app to allow to detect the ip version if mbuf ol_flags are not set in case of running in a VM with emulated network controllers Signed-off-by: Andrey Chilikin --- examples/l3fwd/main.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index e32512e..4d4e5bc 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -76,6 +76,8 @@ #define APP_LOOKUP_LPM 1 #define DO_RFC_1812_CHECKS +#define DO_IP_VERSION_CHECK 0 + #ifndef APP_LOOKUP_METHOD #define APP_LOOKUP_METHOD APP_LOOKUP_LPM #endif @@ -953,6 +955,15 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, struct lcore_conf *qcon void *d_addr_bytes; uint8_t dst_port; +#if DO_IP_VERSION_CHECK + if (!(m->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) { + uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) + + sizeof(struct ether_hdr)) >> 4; + if (ip_ver == 4) + m->ol_flags |= PKT_RX_IPV4_HDR; + } +#endif + eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *); if (m->ol_flags & PKT_RX_IPV4_HDR) { @@ -1071,6 +1082,17 @@ get_dst_port(const struct lcore_conf *qconf, struct rte_mbuf *pkt, struct ipv6_hdr *ipv6_hdr; struct ether_hdr *eth_hdr; +#if DO_IP_VERSION_CHECK + if (!(pkt->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) { + uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(pkt, unsigned char *) + + sizeof(struct ether_hdr)) >> 4; + if (ip_ver == 4) + pkt->ol_flags |= PKT_RX_IPV4_HDR; + else if (ip_ver == 6) + pkt->ol_flags |= PKT_RX_IPV6_HDR; + } +#endif + if (pkt->ol_flags & PKT_RX_IPV4_HDR) { if (rte_lpm_lookup(qconf->ipv4_lookup_struct, dst_ipv4, &next_hop) != 0) -- 1.7.4.1