Skip to content

Commit bab3551

Browse files
committed
net: ipv4_autoconf: Fix requested IPv4 address in ARP packet
Unspecified address 0.0.0.0 was used as a requested IPv4 address because the ARP message was generated second time. So for IPv4 autoconf ARP message, generate the message only once. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent dd88711 commit bab3551

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

subsys/net/l2/ethernet/arp.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ static inline struct net_pkt *arp_prepare(struct net_if *iface,
234234
struct in_addr *next_addr,
235235
struct arp_entry *entry,
236236
struct net_pkt *pending,
237-
struct in_addr *request_ip,
238237
struct in_addr *current_ip)
239238
{
240239
#if defined(CONFIG_NET_VLAN)
@@ -259,6 +258,8 @@ static inline struct net_pkt *arp_prepare(struct net_if *iface,
259258
* things setup so no need to allocate new net_pkt
260259
*/
261260
pkt = pending;
261+
262+
net_buf_add(pkt->frags, sizeof(struct net_arp_hdr));
262263
} else {
263264
pkt = net_pkt_get_reserve_tx(eth_hdr_len, NET_BUF_TIMEOUT);
264265
if (!pkt) {
@@ -378,7 +379,8 @@ struct net_pkt *net_arp_prepare(struct net_pkt *pkt,
378379
/* Is the destination in the local network, if not route via
379380
* the gateway address.
380381
*/
381-
if (!net_if_ipv4_addr_mask_cmp(net_pkt_iface(pkt), request_ip)) {
382+
if (!current_ip &&
383+
!net_if_ipv4_addr_mask_cmp(net_pkt_iface(pkt), request_ip)) {
382384
struct net_if_ipv4 *ipv4 = net_pkt_iface(pkt)->config.ip.ipv4;
383385

384386
if (ipv4) {
@@ -417,7 +419,7 @@ struct net_pkt *net_arp_prepare(struct net_pkt *pkt,
417419
}
418420

419421
req = arp_prepare(net_pkt_iface(pkt), addr, entry, pkt,
420-
request_ip, current_ip);
422+
current_ip);
421423

422424
if (!entry) {
423425
/* We cannot send the packet, the ARP cache is full
@@ -437,7 +439,8 @@ struct net_pkt *net_arp_prepare(struct net_pkt *pkt,
437439
net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->src));
438440

439441
net_eth_fill_header(ctx, pkt,
440-
htons(NET_ETH_PTYPE_IP),
442+
current_ip == NULL ? htons(NET_ETH_PTYPE_IP) :
443+
htons(NET_ETH_PTYPE_ARP),
441444
ll->addr, entry->eth.addr);
442445

443446
return pkt;

subsys/net/l2/ethernet/ethernet.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -419,24 +419,30 @@ static enum net_verdict ethernet_send(struct net_if *iface,
419419
goto setup_hdr;
420420
}
421421

422-
arp_pkt = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst, NULL);
423-
if (!arp_pkt) {
424-
return NET_DROP;
425-
}
422+
/* Trying to send ARP message so no need to setup it twice */
423+
if (ntohs(NET_ETH_HDR(pkt)->type) != NET_ETH_PTYPE_ARP) {
424+
arp_pkt = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst,
425+
NULL);
426+
if (!arp_pkt) {
427+
return NET_DROP;
428+
}
426429

427-
if (pkt != arp_pkt) {
428-
NET_DBG("Sending arp pkt %p (orig %p) to iface %p",
429-
arp_pkt, pkt, iface);
430+
if (pkt != arp_pkt) {
431+
NET_DBG("Sending arp pkt %p (orig %p) to "
432+
"iface %p",
433+
arp_pkt, pkt, iface);
430434

431-
/* Either pkt went to ARP pending queue or
432-
* there was no space in the queue anymore.
433-
*/
434-
net_pkt_unref(pkt);
435+
/* Either pkt went to ARP pending queue or
436+
* there was no space in the queue anymore.
437+
*/
438+
net_pkt_unref(pkt);
435439

436-
pkt = arp_pkt;
437-
} else {
438-
NET_DBG("Found ARP entry, sending pkt %p to iface %p",
439-
pkt, iface);
440+
pkt = arp_pkt;
441+
} else {
442+
NET_DBG("Found ARP entry, sending pkt %p to "
443+
"iface %p",
444+
pkt, iface);
445+
}
440446
}
441447

442448
net_pkt_ll_src(pkt)->addr = (u8_t *)&NET_ETH_HDR(pkt)->src;

0 commit comments

Comments
 (0)