Skip to content

testing/nettest: Test short IPv6 multicast options. - #4150

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:sockopt-ipv6-len-up
Nov 27, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:sockopt-ipv6-len-up

Conversation

@casaroli

@casaroli casaroli commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

test_mcast_optlen_ipv6 of cmocka_net_mcast now also checks IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP with an option one byte shorter than struct ipv6_mreq, and IPV6_MULTICAST_IF with an option one byte shorter than an int. Each call must fail with EINVAL, as MCAST_JOIN_GROUP does.

Impact

Test only. Without apache/nuttx#22376 the case fails: the kernel accepts the short options.

Testing

cmocka_net_mcast on sim:nsh with IPv6, UDP, loopback, ICMPv6 and MLD (CI image, apps with the new checks):

master 28db4789c34 this PR
test_mcast_optlen_ipv6 FAIL: 0 != -1 at test_mcast_ipv6.c:211 (the short IPV6_JOIN_GROUP succeeds) pass
other 5 cases pass pass

@casaroli
casaroli marked this pull request as ready for review November 26, 2026 14:38
@anjiahao1

Copy link
Copy Markdown
Contributor

This CI failure is not caused by the nettest change. The sim-03 job builds the apps tree from this PR's test-merge commit (bace6f5), which was created before testing/fs/wzipfs landed in master. The job does fetch current nuttx master, where the zipfs defconfig now enables CONFIG_TESTING_WZIPFS, so the defconfig normalization reports:

  81d80
  < CONFIG_TESTING_WZIPFS=y

A rebase, or any new push, regenerates the merge commit against current master and clears it. No code change is needed in this PR.

test_mcast_optlen_ipv6 now also gives IPV6_JOIN_GROUP and
IPV6_LEAVE_GROUP an option one byte shorter than struct ipv6_mreq, and
IPV6_MULTICAST_IF an option one byte shorter than an int.  Each call
must fail with EINVAL, as MCAST_JOIN_GROUP does.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli force-pushed the sockopt-ipv6-len-up branch from 6c13c1c to 7634bca Compare November 27, 2026 05:39
@xiaoxiang781216
xiaoxiang781216 merged commit 5c21bfd into apache:master Nov 27, 2026
41 checks passed
@cederom

cederom commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

LGTM. Checked against net/inet/ipv6_setsockopt.c on master after apache/nuttx#22376:

  • IPV6_JOIN_GROUP / IPV6_LEAVE_GROUP with sizeof(struct ipv6_mreq) - 1 hit the new value_len < sizeof(struct ipv6_mreq) check → -EINVAL. The LEAVE case is meaningful on its own: the group isn't joined at that point, so without the length check it would fail with a different errno from mld_leavegroup(), not EINVAL.
  • IPV6_MULTICAST_IF with sizeof(int) - 1 hits the length check before any ifindex validation, so ifindex = 0 can't produce EINVAL (or ENODEV) by another path. sfd isn't bound to a device, so the CONFIG_NET_BINDTODEVICE branch doesn't interfere either.
  • Expected errno matches Linux (EINVAL for a short ipv6_mreq and for IPV6_MULTICAST_IF with optlen != sizeof(int)), so the test isn't asserting NuttX-only behaviour.
  • memset(&mreq, 0, ...) before filling: good (the existing test_mcast_leave_ipv6 skips it).

Optional nits, none blocking:

  1. The new description says "shorter than its structure", but IPV6_MULTICAST_IF takes an int. Maybe "shorter than its option type" / "than the option it expects".
  2. On a kernel without #22376 the short IPV6_JOIN_GROUP succeeds and the assert at L211 aborts the test before the LEAVE. Since MLD membership is per device, not per socket, ff02::123 stays joined on lo after teardown. That only matters when the test is already failing, but you could do the LEAVE-style cleanup (or put the JOIN case last) if you care about later cases staying independent on old kernels.
  3. IPV6_MULTICAST_IF has no positive case with a full-length option anywhere in the suite. A setsockopt(..., &ifindex, sizeof(ifindex)) → 0 right after would show the EINVAL comes from the length alone. Same idea as test_mcast_leave_ipv6 covering full-length JOIN/LEAVE.

The sim-03 CI failure is the unrelated CONFIG_TESTING_WZIPFS defconfig drift anjiahao1 described; a rebase/push should clear it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants