From patchwork Thu Mar 27 15:38:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 27209 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3D7FA202FA for ; Thu, 27 Mar 2014 15:39:00 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id ec20sf6620237lab.10 for ; Thu, 27 Mar 2014 08:38:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=QzRccVcf7Irdpy2YUye1tHY4KstHX0zx6iNplAJpGdQ=; b=G2UpaDG6RsYi39t+de7qmYX8RWH2WC6Fp5ImEDRn1gv1c/pqJJTufuJGDF6Pw00CPD FfM6RtupkRyMB3ZOdE4cItVVfjMaseOaomsTjyq8iLrP097/QGVqRabrpVf03Vo0xD4B wdqcMX0knuwDLTTUWDOCrW2F2UepIR/290vp8syJZpFCtpJtJLX5GevMq5vcNMk7Y1cp oTCCFK7W2HjNtrjTqLEqr5vzDetjJggIKg2rMKIogR0UHZqQmy/gwBhBzgXKOxE4UMq6 dXjtrMLn3/kr0CmphmKele/mhNMXa7YykldwNTihL5SGCVYiCIDXG7utKWa7RZka/XKe 00jQ== X-Gm-Message-State: ALoCoQmiF8QptuqQQqyCTURt97LnsMQdJP8hjVZtTpwvT33ZOHszAfoXUypo5S8Ke1VSZH771RHv X-Received: by 10.153.6.43 with SMTP id cr11mr1252095lad.2.1395934738529; Thu, 27 Mar 2014 08:38:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.152.2.8 with SMTP id 8ls174437laq.30.gmail; Thu, 27 Mar 2014 08:38:58 -0700 (PDT) X-Received: by 10.112.236.69 with SMTP id us5mr29994lbc.88.1395934738305; Thu, 27 Mar 2014 08:38:58 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com [209.85.215.52]) by mx.google.com with ESMTPS id h8si1569439lam.74.2014.03.27.08.38.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Mar 2014 08:38:58 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.52 is neither permitted nor denied by best guess record for domain of ciprian.barbu@linaro.org) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id ec20so2729814lab.39 for ; Thu, 27 Mar 2014 08:38:58 -0700 (PDT) X-Received: by 10.112.39.97 with SMTP id o1mr1321212lbk.38.1395934738180; Thu, 27 Mar 2014 08:38:58 -0700 (PDT) Received: from sestofb10.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id f9sm2280177laa.8.2014.03.27.08.38.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Mar 2014 08:38:57 -0700 (PDT) From: Ciprian Barbu To: lng-odp@linaro.org Cc: Ciprian Barbu Subject: [lng-odp][PATCH] packet parsing modifications Date: Thu, 27 Mar 2014 16:38:49 +0100 Message-Id: <1395934729-9029-2-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395934729-9029-1-git-send-email-ciprian.barbu@linaro.org> References: <1395934729-9029-1-git-send-email-ciprian.barbu@linaro.org> X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.215.52 is neither permitted nor denied by best guess record for domain of ciprian.barbu@linaro.org) smtp.mail=ciprian.barbu@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Ciprian Barbu --- platform/linux-generic/include/odp_packet_internal.h | 2 +- platform/linux-generic/source/odp_packet.c | 8 +++++--- platform/linux-generic/source/odp_packet_netmap.c | 6 +++++- platform/linux-generic/source/odp_packet_socket.c | 20 ++++++++++++++++---- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 792fc7c..b316b20 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -135,7 +135,7 @@ static inline odp_packet_hdr_t *odp_packet_hdr(odp_packet_t pkt) /** * Parse packet and set internal metadata */ -void odp_packet_parse(odp_packet_t pkt, size_t len, size_t l2_offset); +int odp_packet_parse(odp_packet_t pkt, size_t len, size_t l2_offset); #ifdef __cplusplus } diff --git a/platform/linux-generic/source/odp_packet.c b/platform/linux-generic/source/odp_packet.c index 5f07374..700ac39 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -138,8 +138,9 @@ void odp_packet_set_l4_offset(odp_packet_t pkt, size_t offset) * @param pkt Packet handle * @param len Packet length in bytes * @param frame_offset Byte offset to L2 header + * @return 1 if the packet is valid, 0 otherwise */ -void odp_packet_parse(odp_packet_t pkt, size_t len, size_t frame_offset) +int odp_packet_parse(odp_packet_t pkt, size_t len, size_t frame_offset) { odp_packet_hdr_t *const pkt_hdr = odp_packet_hdr(pkt); odp_ethhdr_t *eth; @@ -154,9 +155,9 @@ void odp_packet_parse(odp_packet_t pkt, size_t len, size_t frame_offset) pkt_hdr->frame_offset = frame_offset; pkt_hdr->frame_len = len; - if (odp_unlikely(len < ODP_ETH_LEN_MIN)) { + if (odp_unlikely(len < ODP_ETHHDR_LEN)) { pkt_hdr->error_flags.frame_len = 1; - return; + return 0; } else if (len > ODP_ETH_LEN_MAX) { pkt_hdr->input_flags.jumbo = 1; } @@ -235,6 +236,7 @@ void odp_packet_parse(odp_packet_t pkt, size_t len, size_t frame_offset) } break; } + return 1; } static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, odp_ipv4hdr_t *ipv4, diff --git a/platform/linux-generic/source/odp_packet_netmap.c b/platform/linux-generic/source/odp_packet_netmap.c index 1cbd84c..0dc109c 100644 --- a/platform/linux-generic/source/odp_packet_netmap.c +++ b/platform/linux-generic/source/odp_packet_netmap.c @@ -308,7 +308,11 @@ int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], /* Initialize, parse and set packet header data */ odp_packet_init(pkt); - odp_packet_parse(pkt, payload_len, pkt_nm->l2_offset); + if (!odp_packet_parse(pkt, payload_len, pkt_nm->l2_offset)) { + ODP_DBG("Packet parsing failed\n"); + odp_packet_init(pkt); + continue; + } pkt_table[nb_rx] = pkt; pkt = ODP_PACKET_INVALID; diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c index aaf2605..65796de 100644 --- a/platform/linux-generic/source/odp_packet_socket.c +++ b/platform/linux-generic/source/odp_packet_socket.c @@ -224,7 +224,11 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock, continue; /* Parse and set packet header data */ - odp_packet_parse(pkt, recv_bytes, pkt_sock->frame_offset); + if (!odp_packet_parse(pkt, recv_bytes, pkt_sock->frame_offset)) { + ODP_DBG("Packet parsing failed\n"); + odp_packet_init(pkt); + continue; + } pkt_table[nb_rx] = pkt; pkt = ODP_PACKET_INVALID; @@ -331,8 +335,12 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock, } /* Parse and set packet header data */ - odp_packet_parse(pkt_table[i], msgvec[i].msg_len, - pkt_sock->frame_offset); + if (!odp_packet_parse(pkt_table[i], msgvec[i].msg_len, + pkt_sock->frame_offset)) { + ODP_DBG("Packet parsing failed\n"); + odp_packet_init(pkt); + continue; + } pkt_table[nb_rx] = pkt_table[i]; nb_rx++; @@ -489,7 +497,11 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring, rx_user_ready(ppd.raw); /* Parse and set packet header data */ - odp_packet_parse(pkt_table[i], pkt_len, frame_offset); + if (!odp_packet_parse(pkt_table[i], pkt_len, frame_offset)) { + ODP_DBG("Packet parsing failed\n"); + odp_packet_init(pkt_table[i]); + continue; + } frame_num = next_frame_num; i++;