From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Sohaib Mohamed <sohaib.amhmd@gmail.com>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 1/2] net: arp: collect context into new struct pending_arp
Date: Fri, 28 Nov 2025 13:49:33 +0100 [thread overview]
Message-ID: <20251128124939.108159-1-a.fatoum@pengutronix.de> (raw)
The ARP code employs two global variables to communicate between the
code sending off the ARP request and the response that runs in the
poller:
- arp_wait_ip, which is the IP to be resolved
- arp_ether, which on success will point to the resulting MAC address
To make the relation between these two clearer and to prepare for the
follow-up fix, collect them into a common struct.
No functional change expected.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- use pending_arp.ip as correct loop condition
---
net/net.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/net/net.c b/net/net.c
index 4703842f4377..795afed159aa 100644
--- a/net/net.c
+++ b/net/net.c
@@ -110,26 +110,33 @@ int setenv_ip(const char *name, IPaddr_t ip)
return 0;
}
-static unsigned char *arp_ether;
-static IPaddr_t arp_wait_ip;
+/**
+ * struct pending_arp - Pending ARP state
+ * @ip: input IPv4 address whose resolution is being requested
+ * @ether: output MAC addess buffer after receing a response
+ */
+static struct pending_arp {
+ IPaddr_t ip;
+ unsigned char *ether;
+} pending_arp;
static void arp_handler(struct arprequest *arp)
{
IPaddr_t tmp;
/* are we waiting for a reply */
- if (!arp_wait_ip)
+ if (!pending_arp.ip)
return;
tmp = net_read_ip(&arp->ar_data[6]);
/* matched waiting packet's address */
- if (tmp == arp_wait_ip) {
+ if (tmp == pending_arp.ip) {
/* save address for later use */
- memcpy(arp_ether, &arp->ar_data[0], 6);
+ memcpy(pending_arp.ether, &arp->ar_data[0], 6);
/* no arp request pending now */
- arp_wait_ip = 0;
+ pending_arp.ip = 0;
}
}
@@ -162,6 +169,7 @@ static int arp_request(struct eth_device *edev, IPaddr_t dest, unsigned char *et
static char *arp_packet;
struct ethernet *et;
unsigned retries = 0;
+ IPaddr_t arp_wait_ip;
int ret;
if (!edev)
@@ -207,14 +215,15 @@ static int arp_request(struct eth_device *edev, IPaddr_t dest, unsigned char *et
net_write_ip(arp->ar_data + 16, arp_wait_ip);
- arp_ether = ether;
+ pending_arp.ether = ether;
+ pending_arp.ip = arp_wait_ip;
ret = eth_send(edev, arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
if (ret)
return ret;
arp_start = get_time_ns();
- while (arp_wait_ip) {
+ while (pending_arp.ip) {
if (ctrlc())
return -EINTR;
--
2.47.3
next reply other threads:[~2025-11-28 12:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 12:49 Ahmad Fatoum [this message]
2025-11-28 12:49 ` [PATCH v2 2/2] net: reset pending ARP state when request is done Ahmad Fatoum
2025-12-01 11:06 ` [PATCH v2 1/2] net: arp: collect context into new struct pending_arp Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251128124939.108159-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sohaib.amhmd@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox