-
Notifications
You must be signed in to change notification settings - Fork 3k
lwip: fix socket behaviour #5684
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept seems fine, but the address match needs to be a bit more general.
@@ -992,6 +992,32 @@ static nsapi_error_t mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t | |||
return NSAPI_ERROR_PARAMETER; | |||
} | |||
|
|||
#if LWIP_IPV6 | |||
if (IP_IS_V6(ip_addr) && !ip6_addr_isany(&ip_addr)) { | |||
const ip_addr_t *local_addr = mbed_lwip_get_ipv6_addr(&lwip_netif); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really sufficient - you need to check all addresses for all interfaces. At present this code isn't multiple-interface, but #5558 will make it so. Basically accessing the global lwip_netif
from this socket call is a cheat - that won't be possible from #5558. Socket calls are not interface-specific.
And even before #5558, an interface may have multiple IPv6 addresses - there currently isn't a public API to enumerate them, so it's not obvious how an application would have found any other address than mbed_lwip_get_ipv6_addr
returns - but there may be in future.
So loop over the netif_list
, then over each netif's addresses, looking for a match.
You may be able collapse the code a bit with some use of generic lwIP functions - the outer if could be if !(ip_addr_isany())
, then inside that loop over interfaces, then inside that loop the V4 and V6 checks.
25ce09e
to
0b778b2
Compare
@kjbracey-arm happy with the updated commits? /morph build |
Build : FAILUREBuild number : 708 |
@@ -992,6 +1023,10 @@ static nsapi_error_t mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t | |||
return NSAPI_ERROR_PARAMETER; | |||
} | |||
|
|||
if (!ip_addr_isany(&ip_addr) && !mbed_lwip_is_local_addr(&ip_addr)) { | |||
return NSAPI_ERROR_PARAMETER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the return error here should be "NO_ADDRESS"? Guess this is fine though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see Nanostack has "PARAMETER" already, so this matches.
/morph build |
Build : FAILUREBuild number : 710 |
Please review the jenkins CI error |
You need |
@0xc0170 Please rerun the tests |
/morph build |
Build : SUCCESSBuild number : 720 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 372 |
Waiting for travis fix to land, then will restart it here (plus morph tests ) |
Test : FAILUREBuild number : 550 |
@juhaylinen Can you please rebase to fix travis in this PR? we will trigger CI once done |
Return NSAPI_ERROR_PARAMETER when: Binding to a non-local address Socket listen() is called without calling bind() first Socket accept() is called without calling listen() first
Update the code to check all addresses for all interfaces. Move the code from mbed_lwip_socket_bind() to a new function called mbed_lwip_is_local_addr()
cc53590
to
32e64e7
Compare
@0xc0170 Rebase done |
/morph build |
Build : SUCCESSBuild number : 762 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 415 |
Test : SUCCESSBuild number : 593 |
Return NSAPI_ERROR_PARAMETER when:
Binding to a non-local address
Socket listen() is called without calling bind() first
Socket accept() is called without calling listen() first