From patchwork Thu Jul 5 02:13:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tran Tien Dat X-Patchwork-Id: 939617 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g94WXA+U"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41LhJL1k7Xz9s3C for ; Thu, 5 Jul 2018 12:14:42 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D54D0C21FB2; Thu, 5 Jul 2018 02:14:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 47B91C21FEC; Thu, 5 Jul 2018 02:14:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C5B66C21FD8; Thu, 5 Jul 2018 02:14:12 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) by lists.denx.de (Postfix) with ESMTPS id 0F7C6C21FE5 for ; Thu, 5 Jul 2018 02:14:08 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id a7-v6so495922plp.3 for ; Wed, 04 Jul 2018 19:14:07 -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:in-reply-to:references; bh=A7LNhyScn5vWsS48aLGeja3YMQrTnfgOoNTfRpc3eJ4=; b=g94WXA+UV88TG3i48q0kyrsYnLttkVyD4s6FsaAlLFDuTG1LmQ7vzfY0+0TUobfFqJ grOG4a9vXYPKHF0vJ0/m2IXlqB42zX2Zw6PSOe6Qe6hZd1rEu+n6DBvGht7qF6F/wUhA P1QNwHxxqRUDn7tVHc5fVpV0EOoXetBvpbyWOxj41TAM1ew9jRvqTfuq9jdPAsVcR0mw TvGZF5uUXbyVGW9sva3mbAwqi5ymgoSo1vPRpVUY1BWOrCXpfJXfY9mKtKXh/KEaJOfg qVAcoTR7mSptnZAkpTtlFn5zxpQu2py8aVx2/viCFvLDRxT+V6+8iPo+r1H9UgwBBuqv ZKbQ== 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:in-reply-to :references; bh=A7LNhyScn5vWsS48aLGeja3YMQrTnfgOoNTfRpc3eJ4=; b=fU0A8P89PDJRApIIhgRoMFme0ofFXr/IhWldRVMGPipkwRBI6HSI/l/i0hcs6vxBAP KBDjk4RYaZv+hwv7mNu6j81SC7EmyHqr6oC0Qzm6gZrly9oRaligtxLyTJwKUn24LIz9 vKNSCm+2VDKqp0KFNidxxv0031uyHhYr5tyQEeZXjELE2fEQ8VevK2RC5VVojZcRe98F W/nwdCj3yuytrMHiEbKgPAMj1WHIhzlJnw06LOvKT1Xi2BL12hA/MFyIvpcm3nQRKuRK q70CVaDBKt4q/AcA6lXVf7GI5ZoTuDRqN8ILKaEIsoglbKmd47C6g/1GGJiR9TDv7e66 hFyQ== X-Gm-Message-State: APt69E0a3qjLvzlLrLW0gzbo45BmiHp/d7P4Txe/mN4SnwkEcodsTEoE 07pWWBi3oKnY2AdxREgGrVcTyg== X-Google-Smtp-Source: AAOMgpfuTKC/A2PH0mFRz3L4/Y/PsJI5U+mCKEg9HuMCvxQrf+lMWQB90sAsLrWLaSJlIyJzezKp2Q== X-Received: by 2002:a17:902:112b:: with SMTP id d40-v6mr4243460pla.123.1530756846519; Wed, 04 Jul 2018 19:14:06 -0700 (PDT) Received: from localhost.localdomain ([42.61.113.194]) by smtp.gmail.com with ESMTPSA id 65-v6sm4497222pfq.81.2018.07.04.19.14.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 19:14:06 -0700 (PDT) From: Tran Tien Dat To: u-boot@lists.denx.de Date: Thu, 5 Jul 2018 10:13:41 +0800 Message-Id: <20180705021341.8881-2-peter.trantiendat@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180705021341.8881-1-peter.trantiendat@gmail.com> References: <20180705021341.8881-1-peter.trantiendat@gmail.com> Cc: Joe Hershberger , Tran Tien Dat Subject: [U-Boot] [PATCH v2 1/1] net: Store waiting packet in a different buffer when making ARP requests X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" U-Boot has 1 common buffer to send Ethernet frames, pointed to by net_tx_packet. When sending to an IP address without knowing the MAC address, U-Boot makes an ARP request (using the arp_tx_packet buffer) to find out the MAC address of the IP addressr. When a matching ARP reply is received, U-Boot continues sending the frame stored in the net_tx_packet buffer. However, in the mean time, if U-Boot needs to send out any network packets (e.g. replying ping packets or ARP requests for its own IP address etc.), it will use the net_tx_packet buffer to prepare the new packet. Thus this buffer is no longer the original packet meant to be transmitted after the ARP reply. The original packet will be lost. U-Boot has another buffer, pointed to by arp_tx_packet which is used to prepare ARP requests. ARP requests use this buffer instead of the normal net_tx_packet in order to avoid modifying the waiting packet to be sent. However, this approach does not prevent other parts of the codes from modifying the waiting packet to be sent, as explained above. This patch repurposes the arp_tx_packet buffer to be used to store the waiting packet to be sent, and use the normal net_tx_packet buffer to send ARP request instead. Signed-off-by: Tran Tien Dat Acked-by: Joe Hershberger Nacked-by: Joe Hershberger --- Changes in v2: - Provide more detailed description net/arp.c | 18 ++++++++++-------- net/arp.h | 1 + net/net.c | 3 +++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/net/arp.c b/net/arp.c index b8a71684cd..f5e2c0b0cf 100644 --- a/net/arp.c +++ b/net/arp.c @@ -35,8 +35,8 @@ int arp_wait_tx_packet_size; ulong arp_wait_timer_start; int arp_wait_try; -static uchar *arp_tx_packet; /* THE ARP transmit packet */ -static uchar arp_tx_packet_buf[PKTSIZE_ALIGN + PKTALIGN]; +uchar *arp_wait_tx_packet; /* THE waiting transmit packet after ARP */ +static uchar arp_wait_tx_packet_buf[PKTSIZE_ALIGN + PKTALIGN]; void arp_init(void) { @@ -45,8 +45,8 @@ void arp_init(void) net_arp_wait_packet_ip.s_addr = 0; net_arp_wait_reply_ip.s_addr = 0; arp_wait_tx_packet_size = 0; - arp_tx_packet = &arp_tx_packet_buf[0] + (PKTALIGN - 1); - arp_tx_packet -= (ulong)arp_tx_packet % PKTALIGN; + arp_wait_tx_packet = &arp_wait_tx_packet_buf[0] + (PKTALIGN - 1); + arp_wait_tx_packet -= (ulong)arp_wait_tx_packet % PKTALIGN; } void arp_raw_request(struct in_addr source_ip, const uchar *target_ethaddr, @@ -58,7 +58,7 @@ void arp_raw_request(struct in_addr source_ip, const uchar *target_ethaddr, debug_cond(DEBUG_DEV_PKT, "ARP broadcast %d\n", arp_wait_try); - pkt = arp_tx_packet; + pkt = net_tx_packet; eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_ARP); pkt += eth_hdr_size; @@ -76,7 +76,7 @@ void arp_raw_request(struct in_addr source_ip, const uchar *target_ethaddr, memcpy(&arp->ar_tha, target_ethaddr, ARP_HLEN); /* target ET addr */ net_write_ip(&arp->ar_tpa, target_ip); /* target IP addr */ - net_send_packet(arp_tx_packet, eth_hdr_size + ARP_HDR_SIZE); + net_send_packet(net_tx_packet, eth_hdr_size + ARP_HDR_SIZE); } void arp_request(void) @@ -217,9 +217,11 @@ void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len) /* set the mac address in the waiting packet's header and transmit it */ - memcpy(((struct ethernet_hdr *)net_tx_packet)->et_dest, + memcpy(((struct ethernet_hdr *)arp_wait_tx_packet) + ->et_dest, &arp->ar_sha, ARP_HLEN); - net_send_packet(net_tx_packet, arp_wait_tx_packet_size); + net_send_packet(arp_wait_tx_packet, + arp_wait_tx_packet_size); /* no arp request pending now */ net_arp_wait_packet_ip.s_addr = 0; diff --git a/net/arp.h b/net/arp.h index afb86958f3..65d73927a7 100644 --- a/net/arp.h +++ b/net/arp.h @@ -20,6 +20,7 @@ extern uchar *arp_wait_packet_ethaddr; extern int arp_wait_tx_packet_size; extern ulong arp_wait_timer_start; extern int arp_wait_try; +extern uchar *arp_wait_tx_packet; void arp_init(void); void arp_request(void); diff --git a/net/net.c b/net/net.c index f35695b4fc..6325ad3e1a 100644 --- a/net/net.c +++ b/net/net.c @@ -836,6 +836,9 @@ int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport, /* size of the waiting packet */ arp_wait_tx_packet_size = pkt_hdr_size + payload_len; + /* copy current packet to ARP waiting packet buffer */ + memcpy(arp_wait_tx_packet, net_tx_packet, + arp_wait_tx_packet_size); /* and do the ARP request */ arp_wait_try = 1;