Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inet:setopts/2 return 'ok' for add_membership and multicast_if even if IfAddress is not avail #7916

Closed
miaxon opened this issue Nov 30, 2023 · 7 comments
Assignees
Labels
bug Issue is reported as a bug team:PS Assigned to OTP team PS

Comments

@miaxon
Copy link
Contributor

miaxon commented Nov 30, 2023

Describe the bug
inet:setpopts/2 return ok when {error, Error} expected.

To Reproduce
In erlang shell try set multicat_if option with unavail address:

1> {ok, S} = gen_udp:open(0).
{ok,#Port<0.4>}
2> inet:setopts(S, [{multicast_if, {1,2,3,4}}]).
ok

Expected behavior
Expected return {error, eaddrnotavail}

Affected versions
26.1.2

Additional context
Debug output:

1> {ok, S} = gen_udp:open(0).
INET-DRV-DBG[10723][-1,<0.86.0>] inet_ctl -> SETOPTS
INET-DRV-DBG[13970][<0.86.0>] packet_inet_ctl -> OPEN
INET-DRV-DBG[10723][19,<0.86.0>] inet_ctl -> SETOPTS
INET-DRV-DBG[6795][19,<0.86.0>] inet_set_opts -> opt: 7
INET-DRV-DBG[7177][19,<0.86.0>] inet_set_opts(rcvbuf) -> 8192
INET-DRV-DBG[7673][19,<0.86.0>] inet_set_opts -> try set opt (1) 8
inet_setopt -> try trick setopt with
   fd:        19
   proto:     1
   type:      8
   sz:        4
   propagate: 0
INET-DRV-DBG[7680][19,<0.86.0>] inet_set_opts -> set opt result: 0
INET-DRV-DBG[6795][19,<0.86.0>] inet_set_opts -> opt: 22
INET-DRV-DBG[6839][19,<0.86.0>] inet_set_opts(active) -> active (ival): active (1)
(drivers/common/inet_drv.c / 7718) sock_select(0x000055f2fe967f60): flags=01, onoff=1, event_mask=01
INET-DRV-DBG[11023][19,<0.86.0>] inet_ctl -> BIND
{ok,#Port<0.4>}

2> inet:setopts(S, [{multicast_if, {1,2,3,4}}]).
INET-DRV-DBG[10723][19,<0.86.0>] inet_ctl -> SETOPTS
INET-DRV-DBG[6795][19,<0.86.0>] inet_set_opts -> opt: 11
INET-DRV-DBG[7376][19,<0.86.0>] inet_set_opts(multicast-if) -> 16909060 (67305985)
inet_set_opts(0x000055f2fe967f60): s=19, IP_MULTICAST_IF = 1020304
INET-DRV-DBG[7673][19,<0.86.0>] inet_set_opts -> try set opt (0) 32
inet_setopt -> try trick setopt with
   fd:        19
   proto:     0
   type:      32
   sz:        4
   propagate: 0
INET-DRV-DBG[7680][19,<0.86.0>] inet_set_opts -> set opt result: -1
ok

inet_set_opts return -1, but inet:setopts/2 return ok.

strace :

[pid 58502] getsockopt(19, SOL_SOCKET, SO_PRIORITY, [0], [4]) = 0
[pid 58502] getsockopt(19, SOL_IP, IP_TOS, [0], [4]) = 0
[pid 58502] setsockopt(19, SOL_SOCKET, SO_RCVBUF, [8192], 4) = 0
[pid 58502] setsockopt(19, SOL_IP, IP_TOS, [0], 4) = 0
[pid 58502] setsockopt(19, SOL_SOCKET, SO_PRIORITY, [0], 4) = 0
[pid 58502] bind(19, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
[pid 58502] getsockname(19, {sa_family=AF_INET, sin_port=htons(42147), sin_addr=inet_addr("0.0.0.0")}, [112 => 16]) = 0
[pid 58502] getsockopt(19, SOL_SOCKET, SO_PRIORITY, [0], [4]) = 0
[pid 58502] getsockopt(19, SOL_IP, IP_TOS, [0], [4]) = 0
[pid 58502] setsockopt(19, SOL_IP, IP_MULTICAST_IF, [67305985], 4) = -1 EADDRNOTAVAIL (Cannot assign requested address)
@miaxon miaxon added the bug Issue is reported as a bug label Nov 30, 2023
@miaxon
Copy link
Contributor Author

miaxon commented Nov 30, 2023

Looks like propagate variable must be set to 1 (true) for multicat_if. Or not?

https://github.com/erlang/otp/blob/master/erts/emulator/drivers/common/inet_drv.c#L6764

I'm not sure I understand this comment correctly:

/* Set to 1 if failure to set this option
should be propagated to erlang (not all
errors can be propagated for BC reasons) */

What is BC in this context?

@miaxon
Copy link
Contributor Author

miaxon commented Nov 30, 2023

Similar behavior is also implemented for the option add_membership

2> gen_udp:open(0, [{add_membership,{{232,252,0,100},{1,2,3,4}}}]).
{ok,#Port<0.5>}

[pid 14876] socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) = 20
[pid 14876] getsockopt(20, SOL_SOCKET, SO_PRIORITY, [0], [4]) = 0
[pid 14876] getsockopt(20, SOL_IP, IP_TOS, [0], [4]) = 0
[pid 14876] setsockopt(20, SOL_IP, IP_ADD_MEMBERSHIP, {imr_multiaddr=inet_addr("232.252.0.100"), imr_interface=inet_addr("1.2.3.4")}, 12) = -1 ENODEV (No such device)
[pid 14876] getsockopt(20, SOL_SOCKET, SO_PRIORITY, [0], [4]) = 0
[pid 14876] getsockopt(20, SOL_IP, IP_TOS, [0], [4]) = 0
[pid 14876] setsockopt(20, SOL_SOCKET, SO_RCVBUF, [8192], 4) = 0
[pid 14876] setsockopt(20, SOL_IP, IP_TOS, [0], 4) = 0
[pid 14876] setsockopt(20, SOL_SOCKET, SO_PRIORITY, [0], 4) = 0
[pid 14876] bind(20, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
[pid 14876] getsockname(20, {sa_family=AF_INET, sin_port=htons(36052), sin_addr=inet_addr("0.0.0.0")}, [112 => 16]) = 0

Still looks like a bug.

propagate must be 1 for add_membersip and multicast_if

@miaxon miaxon changed the title inet:setopts(Socket, [{multicats_if, Addr}]) return 'ok' even if Addr is not avail inet:setopts(Socket, [{multicats_if, Addr}]) (and for add_membership) return 'ok' even if Addr is not avail Nov 30, 2023
@miaxon miaxon changed the title inet:setopts(Socket, [{multicats_if, Addr}]) (and for add_membership) return 'ok' even if Addr is not avail inet:setopts/2 return 'ok' for add_membership and multicast_if even if IfAddress is not avail Nov 30, 2023
@IngelaAndin IngelaAndin added the team:PS Assigned to OTP team PS label Nov 30, 2023
@bmk
Copy link
Contributor

bmk commented Dec 6, 2023

If you do the same with 'socket' it works as expected.
I will look into it.

@bmk
Copy link
Contributor

bmk commented Dec 6, 2023

Also do not know what BC stands for. Unless it was supposed to be PC (Politically Correct).

@bmk
Copy link
Contributor

bmk commented Dec 6, 2023

Raimo knew: BC = Backwards Compatibility

@bmk
Copy link
Contributor

bmk commented Dec 6, 2023

Also:
`8> {ok, S2} = gen_udp:open(0, [{inet_backend, socket}]).
{ok,{'$inet',gen_udp_socket,
{<0.95.0>,
{'$socket',#Ref<0.2221571745.2128216065.255332>}}}}

9> inet:setopts(S2, [{multicast_if, {1,2,3,4}}]).
{error,eaddrnotavail}
`

@miaxon
Copy link
Contributor Author

miaxon commented Dec 8, 2023

Thank you for answer. I see this is not a bug.

@miaxon miaxon closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:PS Assigned to OTP team PS
Projects
None yet
Development

No branches or pull requests

4 participants