From patchwork Tue May 29 19:08:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thibaut Robert X-Patchwork-Id: 10436787 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4BB0D60327 for ; Tue, 29 May 2018 19:09:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AE9828856 for ; Tue, 29 May 2018 19:09:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F89828874; Tue, 29 May 2018 19:09:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2D5928856 for ; Tue, 29 May 2018 19:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966320AbeE2TJN (ORCPT ); Tue, 29 May 2018 15:09:13 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:55750 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965614AbeE2TJL (ORCPT ); Tue, 29 May 2018 15:09:11 -0400 Received: by mail-wm0-f68.google.com with SMTP id a8-v6so43340817wmg.5; Tue, 29 May 2018 12:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Q1eImjtVhibNmSuDPYrloLIzaj2zJaF6GXsFu7YwW6E=; b=RpxRBZOMPRVRgrTroJZuIZ8BY5zAyafEvChlcHuBmx3JAROpBMUp708N8SZxO/gX0P Q3g20Ee9aNmM8bf9OmrReWnX0OTCvj20+3+dXwgZMxC6LkYapUNMCrQACG5YsFwb3sSx l30WFIFWJrWVqzAinhJFoRIOZ2CquhejlOxcirmzDikW5kCFMZKgM0Yo6khyuHsriBPW Bb1MlQjBG8nDxDCJ15jj5CHV64Km6CeXWUrm7ugaVrKeo4fpNbZBA70PqxP30ZWUpyB9 Q6nLDM+OCMZc/QAaqYq+ADBewIbTD3HW0crY7HRsVdc3FCNqme3oZzc+Z1WuQGbuvJzA rJ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Q1eImjtVhibNmSuDPYrloLIzaj2zJaF6GXsFu7YwW6E=; b=qoTIpWY3/1X/CBVGwihvs9iFnF5F63sD0SVOVC+nMiyjNtbIegO/y2y/xa7nI6OX8y tFgPtCsIa4L+IEW26p0XwhwwiSfxoViNlxR/DJuVCq+REXhOnUp8rBhKCKHjUB5XOC2e bRRnnaJF47ohjIy6uaE8XmGbdM8aVRdITyAg7aH0P2SpkdVP6lsXkaDiXmhU1M7TTmjs vmwTzBqsJwtXkS1SDnr30RaGddQWNXhd4a0KVe9qpwd9V7t42TNjjM57rLek9EJlx3mt Mt08qLx7H4gnZ1IPnNfOCGJwET+3flQy7ndhb5G5Tv/2CNjiqIJCAisBPYVF3FWBHD5U 9ewg== X-Gm-Message-State: ALKqPwf7Ih6bKwKyC3br8NU+oo1F/Skgr9cDm2+EpJH7fdgbGzsspJf1 jVjsrNUnbZI5YGUxuN2CkFQ= X-Google-Smtp-Source: ADUXVKJUifOCwKVaTiAHxhfcz1I+jBpKa/7spLO7qqb0IaYS/WSpbqDg5RDAUocDydBGUKi37O/bJA== X-Received: by 2002:a1c:9d49:: with SMTP id g70-v6mr100370wme.134.1527620949480; Tue, 29 May 2018 12:09:09 -0700 (PDT) Received: from L80496.priv.atos.fr (abo-39-222-68.trs.modulonet.fr. [85.68.222.39]) by smtp.gmail.com with ESMTPSA id 90-v6sm33015851wrl.79.2018.05.29.12.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 12:09:07 -0700 (PDT) From: Thibaut Robert To: Aditya Shankar , Ganesh Krishna , Greg Kroah-Hartman Cc: linux-wireless@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Thibaut Robert Subject: [PATCH 1/1] staging: wilc1000: Use common structs to parse ip packets Date: Tue, 29 May 2018 21:08:39 +0200 Message-Id: <20180529190839.12818-1-thibaut.robert@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use structs ethhdr, iphdr and tcphdr instead of manual parsing in tcp_process. This commit fix handling of ip packets containing options. It also fixes the following sparse warning: drivers/staging/wilc1000//wilc_wlan.c:201:19: warning: cast to restricted __be16 Signed-off-by: Thibaut Robert --- drivers/staging/wilc1000/wilc_wlan.c | 44 +++++++++++----------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c index d4ebbf67e50b..28c93f3f846e 100644 --- a/drivers/staging/wilc1000/wilc_wlan.c +++ b/drivers/staging/wilc1000/wilc_wlan.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include #include "wilc_wfi_netdevice.h" #include "wilc_wlan_cfg.h" @@ -184,9 +186,9 @@ static inline int add_tcp_pending_ack(u32 ack, u32 session_index, static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) { - u8 *eth_hdr_ptr; + const struct ethhdr *eth_hdr_ptr = (const struct ethhdr *)tqe->buffer; + u8 *buffer = tqe->buffer; - unsigned short h_proto; int i; unsigned long flags; struct wilc_vif *vif; @@ -197,37 +199,25 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) spin_lock_irqsave(&wilc->txq_spinlock, flags); - eth_hdr_ptr = &buffer[0]; - h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12])); - if (h_proto == ETH_P_IP) { - u8 *ip_hdr_ptr; - u8 protocol; - - ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; - protocol = ip_hdr_ptr[9]; + if (eth_hdr_ptr->h_proto == htons(ETH_P_IP)) { + const struct iphdr *ip_hdr_ptr = (const struct iphdr *) + (buffer + ETH_HLEN); - if (protocol == 0x06) { - u8 *tcp_hdr_ptr; + if (ip_hdr_ptr->protocol == IPPROTO_TCP) { + const struct tcphdr *tcp_hdr_ptr; u32 IHL, total_length, data_offset; - tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN]; - IHL = (ip_hdr_ptr[0] & 0xf) << 2; - total_length = ((u32)ip_hdr_ptr[2] << 8) + - (u32)ip_hdr_ptr[3]; - data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2; + IHL = ip_hdr_ptr->ihl << 2; + tcp_hdr_ptr = (const struct tcphdr *) + ((u8 *)ip_hdr_ptr + IHL); + total_length = ntohs(ip_hdr_ptr->tot_len); + + data_offset = tcp_hdr_ptr->doff << 2; if (total_length == (IHL + data_offset)) { u32 seq_no, ack_no; - seq_no = ((u32)tcp_hdr_ptr[4] << 24) + - ((u32)tcp_hdr_ptr[5] << 16) + - ((u32)tcp_hdr_ptr[6] << 8) + - (u32)tcp_hdr_ptr[7]; - - ack_no = ((u32)tcp_hdr_ptr[8] << 24) + - ((u32)tcp_hdr_ptr[9] << 16) + - ((u32)tcp_hdr_ptr[10] << 8) + - (u32)tcp_hdr_ptr[11]; - + seq_no = ntohl(tcp_hdr_ptr->seq); + ack_no = ntohl(tcp_hdr_ptr->ack_seq); for (i = 0; i < tcp_session; i++) { u32 j = ack_session_info[i].seq_num;