nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

[HELP] Why isn't multicast loopback switched on by default?

Open sastel opened this issue 6 months ago • 10 comments

Description

@acassis I noticed recently that multicast loopback is disabled by default in NuttX. I have a pair of applications which when I run them on the same device using Linux, discover each other via multicast loopback. However when I run these applications on the same device using NuttX (kernel mode), they do not discover each other, even though applications on other devices can see their multicast traffic.

In nuttx/net/udp/udp_send.c, you can see that there is support for IP_MULTICAST_LOOP in the code. I have the relevant options set in my defconfig, so if that bit is set then it should be looping back.

It seems that IP_MULTICAST_LOOP is set by default in Linux, but in NuttX the bit is not set by default in conn->sconn.s_options.

I have two questions based on this, and I'm hoping someone more knowledgeable than I about this stuff can help.

  1. Why doesn't NuttX set this bit by default?
  2. Should NuttX set this bit by default?

I can use the sockets API to set this in my communications stack, but it isn't clear to me what is the right place to do it.

Verification

  • [x] I have verified before submitting the report.

sastel avatar Jun 10 '25 13:06 sastel

This Linux programming document from 1998 Multicast Programming says in section 6.1 IP_MULTICAST_LOOP "Loopback is by default enabled.", so I find it strange that NuttX doesn't have at least a config by which it may be default enabled.

sastel avatar Jun 10 '25 15:06 sastel

@sastel I think it is because NuttX try to only enable the minimal thinks possible. But things are changing, in the past we could enable or disable signals, until someone realized signal was a required by POSIX. Now we don't have option to disable signals. Although we got better compatibility we lose the ability to not use it in small microcontrollers.

Maybe a better compromise is just enabling by default what is required by the POSIX standard but keep the option to disable it. I think multicast loopback could follow this approach.

@wengzhe @xiaoxiang781216 @raiden00pl please comment

acassis avatar Jun 10 '25 17:06 acassis

it's fine to enable multicast loop by default like Linux

xiaoxiang781216 avatar Jun 10 '25 17:06 xiaoxiang781216

Would it be an idea to add a "POSIX-compliance" Kconfig option, default yes. If disabled, a list of all the individual features that can be disabled is shown. As items are added to that list over time, we could try and encourage proper help explanations of the advantage gained if each that item is disabled?

TimJTi avatar Jun 10 '25 17:06 TimJTi

POSIX-compliance isn't an option. It's also bad to add an option to control the minor default behavior, since only few people can remember them.

xiaoxiang781216 avatar Jun 10 '25 18:06 xiaoxiang781216

Ok, but I see people lamenting the loss of options that allow NuttX to better suit small processors. Shouldn't we accommodate that somehow as NON default options?

TimJTi avatar Jun 10 '25 19:06 TimJTi

This suggestion is only changing the default value, no size impact on the final image. ICMP already has an option and disabled by default.

xiaoxiang781216 avatar Jun 11 '25 06:06 xiaoxiang781216

I got sidetracked by Alan's comment about signals.

Loopback default state is a Linux vs NuttX argument that I have no opinion on if it doesn't break existing code/apps for NuttX users.

TimJTi avatar Jun 11 '25 07:06 TimJTi

@xiaoxiang781216 where would you enable it?

I was thinking in udp_alloc.

sastel avatar Jun 11 '25 10:06 sastel

@xiaoxiang781216 where would you enable it?

I was thinking in udp_alloc.

yes, it's good place to set the initial value.

xiaoxiang781216 avatar Jun 11 '25 15:06 xiaoxiang781216