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

IPv6 Multicast unable to set send adapter/scope #1567

Open
BitFis opened this issue Jan 7, 2025 · 2 comments
Open

IPv6 Multicast unable to set send adapter/scope #1567

BitFis opened this issue Jan 7, 2025 · 2 comments

Comments

@BitFis
Copy link

BitFis commented Jan 7, 2025

Is your feature request related to a problem? Please describe.

Unable to send on a specific adapter in case of multiple adapters available. (tested on linux)

Describe the solution you would like

Provide an option to configure the ipv6 adapter/scope either via source address (in coap_new_client_session call).
Or on send.

Describe alternatives you have considered

using coap_new_client_session, I tryed to configure the scope for the local_if / coapLocalAddress and server / mcastAddress argument.
For both the scope is ignored and the request is sent on the default adapter.
(If required can provide test code)

Only workaround I found by accessing the socket directly and configure:

// hidden setup code ...
auto session = coap_new_client_session(ctx, coapLocalAddress,
                                          mcastAddress,
                                          COAP_PROTO_UDP);
setsockopt(session->sock.fd, SOL_SOCKET, SO_BINDTODEVICE,
                   interface, strlen(interface))
Adapter test setup on linux for reference
# create links
sudo ip link add name veth0 type veth peer name veth1
sudo ip link add name veth2 type veth peer name veth3

# add some ipv6 addresses
sudo ip -6 addr add 2001:db8::1/64 dev veth0
sudo ip -6 addr add 2001:db9::2/64 dev veth2

# bring all up
sudo ip link set veth0 up
sudo ip link set veth1 up
sudo ip link set veth2 up
sudo ip link set veth3 up

# adapter available on veth0 and veth2 for testing

# cleanup
sudo ip link delete veth0
sudo ip link delete veth2

Additional context

Non.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jan 8, 2025

I need to do further testing here to get to the bottom of what is not working as expected.

IP6 addresses specified with a scope_id/interface suffix (e.g. ip6-address%scope_id) get the correct scope_id filled in to sin6.sin6_scope_id by coap_resolve_address_info() which calls getaddrinfo().

The sendmsg() to the multicast address does have the scope_id set. If the local address to bind to is defined using %scope_id, the bind() takes place, but the socket information (using getsockname()) no longer contains the scope_id.

The sendmsg() however fails unless the multicast's scope_id is for the default interface.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jan 10, 2025

Please see #1571 which works for me on Ubuntu 24. Does this work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants