Skip to content

Commit a37e70f

Browse files
Pull up following revision(s) (requested by ozaki-r in ticket #1154):
sys/net/nd.c: revision 1.8 tests/net/arp/t_arp.sh: revision 1.49 nd: fix the number of requests for address resolution ARP is expected to send requests for address resolution net.inet.arp.nd_bmaxtries times at most. However, it sends one more. IPv6 ND also behaves the same way. The fix requires nd_set_timer reorganization to handle scheduling timer without sending an NS message. PR kern/59596 tests: add tests for ARP address resolution
1 parent 8081bb2 commit a37e70f

2 files changed

Lines changed: 54 additions & 15 deletions

File tree

sys/net/nd.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: nd.c,v 1.5.2.1 2024/09/11 16:18:36 martin Exp $ */
1+
/* $NetBSD: nd.c,v 1.5.2.2 2025/08/29 15:21:16 martin Exp $ */
22

33
/*
44
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
2828
*/
2929

3030
#include <sys/cdefs.h>
31-
__KERNEL_RCSID(0, "$NetBSD: nd.c,v 1.5.2.1 2024/09/11 16:18:36 martin Exp $");
31+
__KERNEL_RCSID(0, "$NetBSD: nd.c,v 1.5.2.2 2025/08/29 15:21:16 martin Exp $");
3232

3333
#include <sys/callout.h>
3434
#include <sys/mbuf.h>
@@ -85,9 +85,11 @@ nd_timer(void *arg)
8585
break;
8686

8787
case ND_LLINFO_INCOMPLETE:
88-
send_ns = true;
89-
if (ln->ln_asked++ < nd->nd_mmaxtries)
88+
if (ln->ln_asked < nd->nd_mmaxtries) {
89+
ln->ln_asked++;
90+
send_ns = true;
9091
break;
92+
}
9193

9294
if (ln->ln_hold) {
9395
struct mbuf *m0, *mnxt;
@@ -116,10 +118,8 @@ nd_timer(void *arg)
116118
break;
117119

118120
case ND_LLINFO_REACHABLE:
119-
if (!ND_IS_LLINFO_PERMANENT(ln)) {
121+
if (!ND_IS_LLINFO_PERMANENT(ln))
120122
ln->ln_state = ND_LLINFO_STALE;
121-
nd_set_timer(ln, ND_TIMER_GC);
122-
}
123123
break;
124124

125125
case ND_LLINFO_PURGE: /* FALLTHROUGH */
@@ -137,10 +137,8 @@ nd_timer(void *arg)
137137
ln->ln_state = ND_LLINFO_PROBE;
138138
send_ns = true;
139139
daddrp = &taddr;
140-
} else {
140+
} else
141141
ln->ln_state = ND_LLINFO_STALE;
142-
nd_set_timer(ln, ND_TIMER_GC);
143-
}
144142
break;
145143

146144
case ND_LLINFO_PROBE:
@@ -180,14 +178,18 @@ nd_timer(void *arg)
180178
break;
181179
}
182180

181+
if (ln != NULL) {
182+
int type = ND_TIMER_RETRANS;
183+
if (ln->ln_state == ND_LLINFO_WAITDELETE)
184+
type = ND_TIMER_RETRANS_BACKOFF;
185+
else if (ln->ln_state == ND_LLINFO_STALE)
186+
type = ND_TIMER_GC;
187+
nd_set_timer(ln, type);
188+
}
183189
if (send_ns) {
184190
uint8_t lladdr[255], *lladdrp;
185191
union l3addr src, *psrc;
186192

187-
if (ln->ln_state == ND_LLINFO_WAITDELETE)
188-
nd_set_timer(ln, ND_TIMER_RETRANS_BACKOFF);
189-
else
190-
nd_set_timer(ln, ND_TIMER_RETRANS);
191193
if (ln->ln_state > ND_LLINFO_INCOMPLETE &&
192194
ln->la_flags & LLE_VALID)
193195
{

tests/net/arp/t_arp.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $NetBSD: t_arp.sh,v 1.45.6.2 2024/09/13 14:17:26 martin Exp $
1+
# $NetBSD: t_arp.sh,v 1.45.6.3 2025/08/29 15:21:16 martin Exp $
22
#
33
# Copyright (c) 2015 The NetBSD Foundation, Inc.
44
# All rights reserved.
@@ -871,6 +871,42 @@ test_cache_creation_nodad()
871871
test_cache_creation_common true
872872
}
873873

874+
test_arp_request_count()
875+
{
876+
877+
export RUMP_SERVER=$SOCKSRC
878+
pkt=$(make_pkt_str_arpreq 10.0.1.2 10.0.1.1)
879+
880+
extract_new_packets bus1 > ./out
881+
atf_check -s not-exit:0 -o ignore -e ignore rump.ping -n -c 1 $IP4DST
882+
extract_new_packets bus1 > ./out
883+
884+
# ARP sends request packets net.inet.arp.nd_bmaxtries times at most.
885+
times=$(rump.sysctl -n net.inet.arp.nd_bmaxtries)
886+
$DEBUG && echo times=$times
887+
$DEBUG && cat ./out
888+
atf_check -s exit:0 -o match:"$pkt" cat ./out
889+
atf_check -s exit:0 -o match:"$times" sh -c "grep -E '$pkt' ./out |wc -l"
890+
}
891+
892+
test_resolution()
893+
{
894+
895+
rump_server_start $SOCKSRC
896+
setup_src_server
897+
898+
export RUMP_SERVER=$SOCKSRC
899+
900+
# Test default value of net.inet.arp.nd_bmaxtries
901+
test_arp_request_count
902+
903+
# Test net.inet.arp.nd_bmaxtries=1
904+
atf_check -s exit:0 rump.sysctl -wq net.inet.arp.nd_bmaxtries=1
905+
test_arp_request_count
906+
907+
rump_server_destroy_ifaces
908+
}
909+
874910
add_test()
875911
{
876912
local name=$1
@@ -910,4 +946,5 @@ atf_init_test_cases()
910946
add_test stray_entries "Tests if ARP entries are removed on route change"
911947
add_test cache_creation "Tests for ARP cache creation"
912948
add_test cache_creation_nodad "Tests for ARP cache creation without DAD"
949+
add_test resolution "Tests for ARP resolution"
913950
}

0 commit comments

Comments
 (0)