Skip to content

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

Merged
merged 3 commits into from
Dec 28, 2017
Merged

lwip: fix socket behaviour #5684

merged 3 commits into from
Dec 28, 2017

Conversation

juhaylinen
Copy link
Contributor

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

Copy link
Contributor

@kjbracey kjbracey left a 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);
Copy link
Contributor

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.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 15, 2017

@kjbracey-arm happy with the updated commits?

/morph build

@mbed-ci
Copy link

mbed-ci commented Dec 15, 2017

Build : FAILURE

Build number : 708
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5684/

@@ -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;
Copy link
Contributor

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.

Copy link
Contributor

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.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 18, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Dec 18, 2017

Build : FAILURE

Build number : 710
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5684/

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 18, 2017

Please review the jenkins CI error Error: ip6_addr.h@140,65: ‘ip_addr_t {aka const struct ip_addr}’ has no member named ‘addr’; did you mean ‘u_addr’? Is it related?

@kjbracey
Copy link
Contributor

You need ip_2_ip4(ip_addr) and ip_2_ip6(ip_addr) in the comparison - when doing this sort of code, make sure you check with IPv4-only, IPv6-only and IPv4+IPv6, otherwise it's easy to miss the necessary adaptation bits like that.

@SeppoTakalo
Copy link
Contributor

@0xc0170 Please rerun the tests

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 19, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Dec 19, 2017

Build : SUCCESS

Build number : 720
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5684/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Dec 19, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 19, 2017

Waiting for travis fix to land, then will restart it here (plus morph tests )

@mbed-ci
Copy link

mbed-ci commented Dec 19, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 22, 2017

@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()
@juhaylinen
Copy link
Contributor Author

@0xc0170 Rebase done

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 22, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Dec 22, 2017

Build : SUCCESS

Build number : 762
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5684/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Dec 22, 2017

@mbed-ci
Copy link

mbed-ci commented Dec 28, 2017

@cmonr cmonr removed the needs: CI label Dec 28, 2017
@cmonr cmonr merged commit 5a19f6d into ARMmbed:master Dec 28, 2017
@juhaylinen juhaylinen deleted the lwip-socket-fix branch January 2, 2018 07:13
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

Successfully merging this pull request may close these issues.

7 participants