casaroli opened a new pull request, #21127: URL: https://github.com/apache/nuttx/pull/21127
## Summary This PR adds `struct group_req`, `struct group_source_req` and the protocol-independent multicast socket options of RFC 3678 to `<netinet/in.h>`, and makes `MCAST_JOIN_GROUP` and `MCAST_LEAVE_GROUP` work. Linux and the BSDs have them, and programs use them without a check (libuv, for example). The options have the values of Linux (`__SO_PROTOCOL + 31` to `+ 36`, that is 42 to 47). They work at the level `IPPROTO_IP` and `IPPROTO_IPV6`, so no option of either level may have their values. The `IP_*` and `IPV6_*` options use `__SO_PROTOCOL + 0` to `+ 14`, and the `SO_*` options use 0 to 11 and 64 and up, so there is no clash. `MCAST_JOIN_GROUP` and `MCAST_LEAVE_GROUP` at `IPPROTO_IP` take an `AF_INET` group and use the code of `IP_ADD_MEMBERSHIP` and `IP_DROP_MEMBERSHIP` (IGMP). At `IPPROTO_IPV6` they take an `AF_INET6` group and use the code of `IPV6_JOIN_GROUP` and `IPV6_LEAVE_GROUP` (MLD). `gr_interface` is an interface index; 0 selects the default device. As on Linux, a short option length gives `EINVAL`, and a group of the other family gives `EINVAL` at `IPPROTO_IP` and `EADDRNOTAVAIL` at `IPPROTO_IPV6`. The Kconfig conditions are those of the existing options (`CONFIG_NET_IGMP` and the UDP stack for IPv4, `CONFIG_NET_MLD` for IPv6); without them the options give `ENOPROTOOPT`. `getsockopt()` does not read them, as for `IP_ADD_MEMBERSHIP`. The source options `MCAST_BLOCK_SOURCE`, `MCAST_UNBLOCK_SOURCE`, `MCAST_JOIN_SOURCE_GROUP` and `MCAST_LEAVE_SOURCE_GROUP` give `ENOSYS`, as `IP_BLOCK_SOURCE` and the other IPv4 source options do: IGMP is version 2 and MLD keeps no source lists. The first commit adds the header names. The second commit changes only white space: the `IPV6_MULTICAST_IF` block in `ipv6_setsockopt.c` had a "Bad left brace alignment" error, and checkpatch checks the whole file. The third commit adds the implementation. ## Impact New names and new behavior only: no existing option changes. Programs that use `MCAST_JOIN_GROUP` and `MCAST_LEAVE_GROUP` now compile and work. The libuv patch in nuttx-apps (`#ifndef __NuttX__` around `struct group_source_req`) still builds. All build modes and architectures. Documentation: no change (`Documentation/` does not list the IP socket options). ## Testing No test in nuttx-apps covers the multicast socket options, so the test is a stand-alone program, `mcastrfc.c`, with `CONFIG_NET`, `NET_IPv4`, `NET_IPv6`, `NET_UDP`, `NET_LOOPBACK`, `NETDEV_LATEINIT`, `NET_SOCKOPTS`, `NET_IGMP`, `NET_ICMPv6` and `NET_MLD`. It checks the two structures and the six values. Then it does these steps at `IPPROTO_IP` with 239.1.2.3 and at `IPPROTO_IPV6` with ff02::123, on the interface `lo`. Join gives 0. A datagram that a second socket sends to the group (from 127.0.0.1 or ::1, with `IP_MULTICAST_LOOP` or `IPV6_MULTICAST_LOOP`) arrives. Leave gives 0. For IPv4, the next datagram does not arrive (IPv6 input accepts every ff00::/8 address, so this step is IPv4 only). A second leave fails with the same errno as a second `IP_DROP_MEMBERSHIP` or `IPV6_LEAVE_GROUP` (`ENOENT`). A short length and the other family give the errors above. `MCAST_JOIN_SOURCE_GROUP` gives `ENOSYS`. | | master | this PR | |---|---|---| | `mcastrfc.c` on `qemu-armv8a:knsh` (kernel, arm64, QEMU with HVF) | does not compile: `struct group_req` incomplete, `MCAST_*` undeclared | all 17 checks PASS | | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` (with the network options) | status 0 | status 0 | Build, each OK: `rv-virt:netnsh64` (flat, rv64) as it is (IPv4, no IGMP), with `NET_IGMP`, with IPv6 + `NET_IGMP` + `NET_MLD` + `NET_BINDTODEVICE`, IPv6 only with `NET_MLD`, and with `NET_IGMP` + `NET_MLD` but no `NET_UDP`; `rv-virt:knetnsh64` (kernel, rv64) with IPv6, with and without `NET_IGMP` + `NET_MLD`. These cover every `#if` path of the two files. The change is in the kernel network stack only, so a protected build compiles the same code. `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]
