From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by dpdk.org (Postfix) with ESMTP id 66A06B3F7 for ; Fri, 13 Feb 2015 10:23:09 +0100 (CET) Received: by mail-wi0-f171.google.com with SMTP id hi2so10434310wib.4 for ; Fri, 13 Feb 2015 01:23:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UhVjWBMWKEe0EhDYeQadY4K0sJsShMtxTbTC6R+hb9Y=; b=hIz6ihhMOahq80Bcgl6BX1Q0XcnQnQrGc+qht6SmswYjhF9rSkUECLk2HAW+dDtSmm TfcoP5QyRGH9DSrg08ghdDtZ8SN5tXvJgPVL4gExtTsMsf/lkYXtkPu7P3e7yHXnnB+H KJ4Ks+3YMO0b22ozkeIujjCrGh5mlNh3b8G0TinRWeAYPyyeVvqsH13BkQ5DgNaGyuM2 eVvXn29LW0EncowD4sGUdv0ZL2Y8Ui4VZHYxpKmOyAsIy2KiqmPNs2C7y8O30YVPAahH fbKVvZfzBg2OZUqp411p7FCnkdDssIjn+dZhqFJSAWYewo4e4BByGzZsZ2tx74pLk6Vp QQLA== X-Gm-Message-State: ALoCoQlklxUEvLOX8ZTiJosQFdu7TzJ0AKyPGwT1Tg9HKm8g9A6wW7p5KrZ6cD4iMrDDTbaNHjak X-Received: by 10.180.38.76 with SMTP id e12mr14031592wik.76.1423819389328; Fri, 13 Feb 2015 01:23:09 -0800 (PST) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id a5sm2100153wib.20.2015.02.13.01.23.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Feb 2015 01:23:08 -0800 (PST) From: Olivier Matz To: dev@dpdk.org Date: Fri, 13 Feb 2015 10:22:41 +0100 Message-Id: <1423819371-24222-11-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1423819371-24222-1-git-send-email-olivier.matz@6wind.com> References: <1423041925-26956-1-git-send-email-olivier.matz@6wind.com> <1423819371-24222-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v3 10/20] testpmd: introduce parse_ipv* in csum fwd engine 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, 13 Feb 2015 09:23:09 -0000 These functions may be used to parse encapsulated layers when we will support IP over GRE tunnels. No functional change. Signed-off-by: Olivier Matz --- app/test-pmd/csumonly.c | 51 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 3921643..b023f12 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -104,6 +104,42 @@ get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uint16_t ethertype) return rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr); } +/* Parse an IPv4 header to fill l3_len, l4_len, and l4_proto */ +static void +parse_ipv4(struct ipv4_hdr *ipv4_hdr, uint16_t *l3_len, uint8_t *l4_proto, + uint16_t *l4_len) +{ + struct tcp_hdr *tcp_hdr; + + *l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4; + *l4_proto = ipv4_hdr->next_proto_id; + + /* only fill l4_len for TCP, it's useful for TSO */ + if (*l4_proto == IPPROTO_TCP) { + tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + *l3_len); + *l4_len = (tcp_hdr->data_off & 0xf0) >> 2; + } else + *l4_len = 0; +} + +/* Parse an IPv6 header to fill l3_len, l4_len, and l4_proto */ +static void +parse_ipv6(struct ipv6_hdr *ipv6_hdr, uint16_t *l3_len, uint8_t *l4_proto, + uint16_t *l4_len) +{ + struct tcp_hdr *tcp_hdr; + + *l3_len = sizeof(struct ipv6_hdr); + *l4_proto = ipv6_hdr->proto; + + /* only fill l4_len for TCP, it's useful for TSO */ + if (*l4_proto == IPPROTO_TCP) { + tcp_hdr = (struct tcp_hdr *)((char *)ipv6_hdr + *l3_len); + *l4_len = (tcp_hdr->data_off & 0xf0) >> 2; + } else + *l4_len = 0; +} + /* * Parse an ethernet header to fill the ethertype, l2_len, l3_len and * ipproto. This function is able to recognize IPv4/IPv6 with one optional vlan @@ -115,7 +151,6 @@ parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *ethertype, uint16_t *l2_len, { struct ipv4_hdr *ipv4_hdr; struct ipv6_hdr *ipv6_hdr; - struct tcp_hdr *tcp_hdr; *l2_len = sizeof(struct ether_hdr); *ethertype = eth_hdr->ether_type; @@ -130,26 +165,18 @@ parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *ethertype, uint16_t *l2_len, switch (*ethertype) { case _htons(ETHER_TYPE_IPv4): ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr + *l2_len); - *l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4; - *l4_proto = ipv4_hdr->next_proto_id; + parse_ipv4(ipv4_hdr, l3_len, l4_proto, l4_len); break; case _htons(ETHER_TYPE_IPv6): ipv6_hdr = (struct ipv6_hdr *) ((char *)eth_hdr + *l2_len); - *l3_len = sizeof(struct ipv6_hdr); - *l4_proto = ipv6_hdr->proto; + parse_ipv6(ipv6_hdr, l3_len, l4_proto, l4_len); break; default: + *l4_len = 0; *l3_len = 0; *l4_proto = 0; break; } - - if (*l4_proto == IPPROTO_TCP) { - tcp_hdr = (struct tcp_hdr *)((char *)eth_hdr + - *l2_len + *l3_len); - *l4_len = (tcp_hdr->data_off & 0xf0) >> 2; - } else - *l4_len = 0; } /* modify the IPv4 or IPv4 source address of a packet */ -- 2.1.4