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

gnrc_sock: implicitly set netif if there is only a single one #18065

Merged
merged 1 commit into from
May 9, 2022

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented May 5, 2022

Contribution description

The interface is already set implicitly for the gnrc_netif_highlander() case - also set it implicitly if there is only a single interface.

Testing procedure

Issues/PRs references

alternative to #17927

@benpicco benpicco requested a review from kfessel May 5, 2022 21:57
@github-actions github-actions bot added Area: network Area: Networking Area: sys Area: System labels May 5, 2022
@kfessel
Copy link
Contributor

kfessel commented May 6, 2022

this one seems to meet expetations better than #17927

@benpicco benpicco force-pushed the gnrc_sock-implicit_netif branch from cb7aae7 to cbd48c2 Compare May 6, 2022 10:11
@kfessel kfessel added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels May 6, 2022
@kfessel
Copy link
Contributor

kfessel commented May 6, 2022

this PR in itself seems good to go but i am not sure how to trigger the changes

all users of gnrc_ep_set() seem to check netif for not being SOCK_ADDR_ANY_NETIF (0) prior to calling gnrc_ep_set()

I would like to see example commands or code snippet or script that does not work prior to this PR but works with this PR

eg:

examples/gnrc_networking$ USE_ZEP=1 make all term
..RIOT boot..
> ifconfig
Iface  7  HWaddr: 27:AD  Channel: 26  NID: 0x23  PHY: O-QPSK 
          Long HWaddr: A6:19:9A:54:06:CB:27:AD 
...
> ping fe80::a419:9a54:6cb:1
...
3 packets transmitted, 0 packets received, 100% packet loss << 100% loss is expected 

this one works before this PR -> can't evaluate it
also udp send does not complain about a missing netif

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 7, 2022
@benpicco
Copy link
Contributor Author

benpicco commented May 8, 2022

Huh I can't reproduce the ping issue - ping doesn't even make use of gnrc_sock.

For a test you can use e.g. tests/nanocoap_cli and start aiocoap-fileserver:

With this you can now do

url get coap://[fe80::ac59:5aff:fe33:896e]/

whereas on master you have to specify the interface

url get coap://[fe80::ac59:5aff:fe33:896e%5]/

@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

url get coap://[fe80::ac59:5aff:fe33:896e]/

should this one error out ? (in master)

@benpicco
Copy link
Contributor Author

benpicco commented May 9, 2022

It will just run into a timeout, but the test does not print error return codes (I thought I could just do #17922 instead)

@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

i added me a


void shell_post_command_hook(int ret, int argc, char **argv)
{
    (void)argv;
    (void)argc;

    if(ret) printf ("ERROR HAPPEND: %d\n", ret);

}

I prints -110 but i seemd to have send something (which is kindof strange)

@benpicco
Copy link
Contributor Author

benpicco commented May 9, 2022

I prints -110

Which is -ETIMEDOUT

but i seemd to have send something

What makes you think so?

@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

but i seemd to have send something

What makes you think so?

With #define ENABLE_DEBUG 1 in nanocoap/sock.c

> url get coap://[fe80::58ca:8ff:fe05:6dfa]/
url get coap://[fe80::58ca:8ff:fe05:6dfa]/
fetching block 0
nanocoap: send 7 bytes (5 tries left)
nanocoap: waiting for response (timeout: 2341766 µs)
nanocoap: timeout
nanocoap: send 7 bytes (4 tries left)
nanocoap: waiting for response (timeout: 4685532 µs)
nanocoap: timeout
nanocoap: send 7 bytes (3 tries left)
nanocoap: waiting for response (timeout: 9371064 µs)
nanocoap: timeout
nanocoap: send 7 bytes (2 tries left)
nanocoap: waiting for response (timeout: 18741128 µs)
nanocoap: timeout
nanocoap: send 7 bytes (1 tries left)
nanocoap: maximum retries reached
error fetching block 0: -110
ERROR HAPPEND: -110

for some reason i think every send should have errored and i should get -22 (EINVAL)

but it sends and waits (which seems wrong)

@benpicco
Copy link
Contributor Author

benpicco commented May 9, 2022

i think every send should have errored and i should get -22 (EINVAL)

For this you would need

diff --git a/sys/net/gnrc/sock/udp/gnrc_sock_udp.c b/sys/net/gnrc/sock/udp/gnrc_sock_udp.c
index bc02fd979f..9169130f81 100644
--- a/sys/net/gnrc/sock/udp/gnrc_sock_udp.c
+++ b/sys/net/gnrc/sock/udp/gnrc_sock_udp.c
@@ -133,6 +133,9 @@ int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local,
         }
         gnrc_ep_set((sock_ip_ep_t *)&sock->remote,
                     (sock_ip_ep_t *)remote, sizeof(sock_udp_ep_t));
+        if (sock->remote.netif == SOCK_ADDR_ANY_NETIF) {
+            return -EINVAL;
+        }
     }
     if (local != NULL) {
         /* listen only with local given */

@miri64
Copy link
Member

miri64 commented May 9, 2022

+        if (sock->remote.netif == SOCK_ADDR_ANY_NETIF) {
+            return -EINVAL;
+        }

Shouldn't this only happen if the address is a link-local address?

@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

some how gnrc purports it send bytes even though it did not. (i think this happen in https://github.com/RIOT-OS/RIOT/blob/master/sys/net/gnrc/sock/gnrc_sock.c#L290 )
where a else clause is missing (at this point it did not copy the pkt into any buffer since it know that will never move anywhere)

I was wrong here thpkt is send without netif information
the netif might thean be added in

sys/net/gnrc/netif/gnrc_netif.c : gnrc_netif_get_by_ipv6_addr or

sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c : _send () (there is already a loopback check in line 699)

@benpicco
Copy link
Contributor Author

benpicco commented May 9, 2022

some how gnrc purports it send bytes even though it did not.

This is a long standing (and quite annoying) issue, see #11551
It looks like that with #15821 there is now a solution on the horizon.

@kfessel kfessel added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label May 9, 2022
@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

why not do this in ?:
sys/net/gnrc/netif/gnrc_netif.c : gnrc_netif_get_by_ipv6_addr or

sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c : _send () (there is already a loopback check in line 699)

@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

BTW.: This is working like intended, (it reads well and documentation is good ( the function is still doing the same thing just in another way)
I am just not sure if a better position would be lower (avoid sending more bytes send into the void) or higher in stack or if this is just the right place.

@benpicco
Copy link
Contributor Author

benpicco commented May 9, 2022

Since this has already a check for gnrc_netif_highlander() I'd say it fits right in.

Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more sane default, eases development

@kfessel
Copy link
Contributor

kfessel commented May 9, 2022

I think its much better to have the package go somewhere especially if it is just one direction then them to be send but not send

@benpicco
Copy link
Contributor Author

benpicco commented May 9, 2022

Thank you for the review!

@benpicco benpicco merged commit cb1aea0 into RIOT-OS:master May 9, 2022
@benpicco benpicco deleted the gnrc_sock-implicit_netif branch May 9, 2022 22:16
@chrysn chrysn added this to the Release 2022.07 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants