casaroli opened a new pull request, #21565: URL: https://github.com/apache/nuttx/pull/21565
## Summary `SIOCGIFBRDADDR` returned 0.0.0.0 as the broadcast address of an interface. `ioctl_get_ipv4broadcast()` stored the result of `net_ipv4addr_broadcast()`, which is a test macro: it gives 0 or 1 (true if the address is a broadcast address). The fix returns the device address with all host bits set (`address | ~netmask`) if the device has `IFF_BROADCAST`, else 0.0.0.0. Linux does the same: `net/ipv4/devinet.c` sets the broadcast address (`ifa_address | ~ifa_mask`) only if `dev->flags` has `IFF_BROADCAST`, and `SIOCGIFBRDADDR` returns it; the loopback device has only `IFF_LOOPBACK` (`drivers/net/loopback.c`), so Linux gives 0.0.0.0 for lo. ## Impact `SIOCGIFBRDADDR` now gives the broadcast address of the sub-net for a device with `IFF_BROADCAST`: `netdev_register()` sets it for Ethernet, IEEE 802.11, Bluetooth and MBIM devices. For example 10.1.2.255 for 10.1.2.3/255.255.255.0 on eth0. A device without `IFF_BROADCAST` (lo, CAN, SLIP, TUN, IEEE 802.15.4, packet radio, cellular) still gives 0.0.0.0, as on Linux. No other ioctl changes. In-tree, only `getifaddrs()` sends `SIOCGIFBRDADDR`, and only when `SIOCGIFDSTADDR` fails. No Documentation change: Documentation/ does not describe this ioctl. All build modes and arches use the same code. ## Testing Test program `ifbrdaddr.c`: reads `SIOCGIFADDR`, `SIOCGIFNETMASK`, `SIOCGIFBRDADDR` and `SIOCGIFFLAGS` of eth0, sets 10.1.2.3/255.255.255.0 on eth0 and reads them again, then reads lo. qemu-armv8a:knsh (kernel build, arm64, QEMU with HVF) with `CONFIG_NET_IPv4`, `CONFIG_NET_LOOPBACK`, `CONFIG_NET_UDP` and `CONFIG_DRIVERS_VIRTIO_NET` (`-device virtio-net-device`): | | master 6d1fa235d69 | this PR | |---|---|---| | eth0 10.0.0.2/255.255.255.0 | 0.0.0.0 | 10.0.0.255 | | eth0 10.1.2.3/255.255.255.0 | 0.0.0.0 | 10.1.2.255 | | lo 127.0.0.1/255.0.0.0 (no `IFF_BROADCAST`) | 0.0.0.0 | 0.0.0.0 | | result | FAIL | PASS | ostest exits 0 on qemu-armv8a:knsh and on qemu-armv8a:nsh (flat build) with the same options. `tools/checkpatch.sh -c -u -m -g` passes. -- 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]
