zhhyu7 opened a new pull request, #22012:
URL: https://github.com/apache/nuttx/pull/22012

   ## Summary
   
   This PR brings seven ARP changes from the downstream tree.                   
                                                                                
                                               
                                                                                
                         
   net/arp: Add checks on hardware/protocol type.                               
                                                                                
                                               
   arp_input() drops ARP packets whose hardware type is not Ethernet or whose 
protocol type is not IPv4, as RFC 826 requires.                                 
                                                 
                                                                                
                                                                                
                                               
   net/arp: Output ACD state to procfs for userspace query.                     
                                                                                
                                               
   Shows the ACD announcing state in /proc/net/<ifname> as "(acd:ann)". Only 
the in-progress state is shown, because the finished state does not guarantee 
that no future conflict will happen. Also fixes a 
   reentrancy problem in arp_acd_try_announce(): sendnum and the state are now 
updated before arp_send_async() is called, because the async callback may run 
synchronously and re-enter arp_acd_arrange_
   announce().                                                                  
                                                                                
                                               
                                                                                
                                                                                
                                               
   net/arp: Avoid sizeof on an array element in arp_update.                     
                                                                                
                                               
   The Tasking compiler reports "W515: side effects of 'sizeof' operand are 
ignored" for sizeof(g_arptable[i]). arp_update() now uses sizeof(struct 
arp_entry_s), and ipt_sockopt.c computes the table count 
   once in an enum instead of calling nitems() in the loop condition.
                                                      
   net/arp: Preserve static ARP entries on carrier loss.
   arp_cleanup() flushed every ARP entry of a device, including the permanent 
ones. Since netdev_carrier_off() calls it directly, a PHY link-down event also 
dropped the manually configured static entries. 
   arp_cleanup() now takes a skip_perm parameter: netdev_carrier_off() passes 
true so that static entries survive a carrier loss, and netdev_ifdown() passes 
false so that an administrative down flushes 
   everything. This matches Linux, where carrier loss goes through 
neigh_carrier_down() with skip_perm set.                                        
                                                            
                                                                                
                                                                                
                                               
   net/arp: add debug logging for error and skip paths.
   Adds nwarn() and ninfo() messages to the error handling and skip paths in 
arp_acd, arp_format, arp_out and arp_table.
                                                                                
                         
   net/arp: Assert that arp_update receives a device.
   arp_update() dereferences dev unconditionally and every caller passes a 
resolved device, so the precondition is now stated with DEBUGASSERT().
   
   net/arp: Allocate send state from a mempool and lock across retries.
   arp_send() kept its send and notify state on the caller's stack, and 
arp_send_async() allocated its state with kmm_zalloc(). Both now allocate a 
struct arp_send_info_s from a MEMPOOL_DEFINE pool, sized by
   the new options NET_ARP_PREALLOC_STATES, NET_ARP_ALLOC_STATES and 
NET_ARP_MAX_STATES. arp_send() takes netdev_lock() once before the retry loop 
and releases it once after, instead of on every pass. arp_
   wait() now takes the device and waits with conn_dev_sem_timedwait(), which 
releases the device lock while blocked so that the receive path can deliver the 
reply. The returned error codes do not change.
   
   ## Impact
   
   Kconfig: three new options under ARP Configuration, with defaults 2, 1 and 
0. No defconfig change is needed.
   
   Internal API: arp_wait() changes from (notify, timeout) to (dev, notify, 
timeout), and arp_cleanup() changes from (dev) to (dev, skip_perm). Both are 
private to the network stack. arp_send() is the only 
   caller of arp_wait(), and arp_cleanup() is called only from 
netdev_carrier_off() and netdev_ifdown(). No network driver has to change.
   
   Behavior: the errno values returned by arp_send() do not change. ARP packets 
with a wrong hardware type or protocol type are now dropped. A carrier loss no 
longer removes static ARP entries, while an 
   administrative ifdown still removes them.
   
   Memory: NET_ARP_PREALLOC_STATES send states are allocated in BSS. On the 
test configuration below, the series adds 1288 bytes of text, 224 bytes of data 
and 224 bytes of bss.
   
   ## Testing
   
   Host: x86_64 Linux. Configuration: sim:dynconns, flat build. The TAP device 
is attached to the host bridge nuttx0, which has the address 10.0.1.1/24. The 
device uses 10.0.1.2/24 with gateway 10.0.1.1. For
   the runtime test I enabled SIM_NET_BRIDGE, SYSTEM_PING, FS_PROCFS and 
NETINIT_THREAD, and disabled NETDEV_LATEINIT. I also disabled NET_PKT, because 
with NET_PKT enabled the sim crashes in eth_input() on
   the first received frame. That crash also happens on master and is not 
related to this PR.
   
   Resolution and ping, device console:
   
   nsh> ping -c 4 10.0.1.1
   PING 10.0.1.1 56 bytes of data
   56 bytes from 10.0.1.1: icmp_seq=0 time=0.1 ms
   56 bytes from 10.0.1.1: icmp_seq=1 time=0.0 ms
   56 bytes from 10.0.1.1: icmp_seq=2 time=0.0 ms
   56 bytes from 10.0.1.1: icmp_seq=3 time=0.0 ms
   4 packets transmitted, 4 received, 0% packet loss, time 4039 ms
   nsh> arp
   10.0.1.1     a2:96:06:65:38:2a eth0
   
   Host capture on nuttx0, showing one ARP request, the reply, and the ICMP 
exchange:
   
   42:3e:48:c5:96:9e > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: 
Request who-has 10.0.1.1 tell 10.0.1.2, length 28
   a2:96:06:65:38:2a > 42:3e:48:c5:96:9e, ethertype ARP (0x0806), length 42: 
Reply 10.0.1.1 is-at a2:96:06:65:38:2a, length 28
   42:3e:48:c5:96:9e > a2:96:06:65:38:2a, ethertype IPv4 (0x0800), length 98: 
10.0.1.2 > 10.0.1.1: ICMP echo request, id 1, seq 0, length 64
   a2:96:06:65:38:2a > 42:3e:48:c5:96:9e, ethertype IPv4 (0x0800), length 98: 
10.0.1.1 > 10.0.1.2: ICMP echo reply, id 1, seq 0, length 64
   
   I ran the following cases on master and on this PR, and both gave the same 
results:
   
   Ping 10.0.1.99, where no host exists: sendto fails with 113 (EHOSTUNREACH) 
after 4 ARP requests.
   Two concurrent pings to 10.0.1.98, where no host exists: both fail with 113, 
and only 4 ARP requests are sent in total.
   Static entry added with arp -s 10.0.1.50 02:11:22:33:44:55, then a ping: no 
ARP request is sent.
   
   Concurrent resolutions: five background pings to unreachable hosts 10.0.1.61 
to 10.0.1.65, run together with ping -c 3 10.0.1.1.
   With the default pool (2, 1, 0), all five fail with 113 after 4 ARP requests 
each, and 10.0.1.1 answers 3 of 3.
   With a static-only pool (NET_ARP_PREALLOC_STATES=2, NET_ARP_ALLOC_STATES=0), 
the pool runs out. All five still fail with 113, and 10.0.1.1 answers 3 of 3. 
The first reply takes 239 ms because that ping 
   waits for a free send state. There is no crash or hang.
   Static entry handling across an interface down and up, with a dynamic entry 
for 10.0.1.1 and a static entry for 10.0.1.77:
   
   nsh> ifdown eth0
   nsh> arp
   IP Address   Ethernet Address  Interface
   nsh> ifup eth0
   nsh> arp
   10.0.1.1     a2:96:06:65:38:2a eth0
   
   An administrative ifdown removes both entries, which is the intended 
behaviour of arp_cleanup(dev, false). The sim TAP driver has no PHY, so a real 
carrier loss cannot be produced. To exercise the skip_
   perm path I temporarily changed the ioctl call to arp_cleanup(dev, true) and 
repeated the test. The static entry survived and only the dynamic one was 
flushed:
   
   nsh> ifdown eth0
   nsh> arp
   10.0.1.77    02:aa:bb:cc:dd:ee eth0
   
   That temporary change was reverted and the tree rebuilt.
   
   Build checks on sim:dynconns: the pool settings 2/1/0, 4/0/0, 0/1/0 and 
2/2/8 all build. ./tools/refresh.sh --silent sim:dynconns makes no change. 
./tools/checkpatch.sh -c -u -m -g passes on every commit 
   and on all 13 changed files.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to