Skip to content

Fixing Static EthernetInterface IP #1645

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

Closed
wants to merge 3 commits into from
Closed

Conversation

Eosis
Copy link
Contributor

@Eosis Eosis commented Apr 1, 2016

When trying to add a static IP to the EthernetInterface I found that it wasn't possible, due to a lengthy timeout in the K64F phy drivers and a race condition exhibited by the EthernetInterface class itself.

I changed the timeout in the driver and proposed a fix for the EthernetInterface lock up.

Rupert Rutledge added 2 commits April 1, 2016 16:24
Prior to this, the ethernet init method always returned 0, which meant
we didn't know if the interface had initialised correctly or if it had
failed.
Prior to this change, trying to use a static IP address caused the
call to EthernetInterface::connect() to fail (timeout).  This was due
to a race condition between the thread that added the interface with
lwip's netif_add and the ethernet driver (in my case the k64f).  The
ethernet driver eventually tries to call the callback set for the netif
by netif_set_link_callback, but this is only set after the netif_add call.
If the netif_add_call thread hasn't been scheduled yet, the callback
does nothing, meaning we wait for the netif_linked semaphore until it
times out.

In the case of a static IP, the race condition ensured that the interface
didn't work.
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 1, 2016

@sg- @bogdanm

@Eosis
Copy link
Contributor Author

Eosis commented Apr 1, 2016

Just realised I didn't commit the driver change. Will do so now.

The previous value of 0x10000 led to a timeout that was over a minute long
on the K64F platform, which is too long for many use cases. This has been
changed to 0x800, which represents around 2 seconds on the K64F.
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 11, 2016

cc @geky

@Eosis We shall review this soon. How did you test your code please?

@geky
Copy link
Contributor

geky commented Apr 11, 2016

+1 This looks fine to me and should be backwards compatible

netif_add(&netif, ipaddr, netmask, gw, NULL, eth_arch_enetif_init, tcpip_input);
struct netif * ret;
ret = netif_add(&netif, ipaddr, netmask, gw, NULL, eth_arch_enetif_init, tcpip_input);
if( ret == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please fix a space -> if(ret == NULL), use rebase or I'll do it when merging

@@ -92,12 +94,15 @@ int EthernetInterface::init() {
return init_netif(NULL, NULL, NULL);
}

int EthernetInterface::init(const char* ip, const char* mask, const char* gateway) {
int EthernetInterface::init(const char* ip, const char* mask, const char* gateway, const char * dns) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This API change appears unrelated to the issue being discussed. IMHO it would be better as a separate PR.

@ciarmcom
Copy link
Member

Can one of the admins verify this patch?

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 12, 2016

@geky Can you help out with this PR ?

@sg-
Copy link
Contributor

sg- commented Aug 23, 2016

@geky any help here?

@geky
Copy link
Contributor

geky commented Aug 26, 2016

I'm not really sure what the state of this pr is.

@0xc0170 and @infinnovation have good comments that should be taken care of. Outside of those are there other concerns with this patch?

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 26, 2016

@geky Looks like we have to take this patch, rebase and update it.

@sg-
Copy link
Contributor

sg- commented Oct 3, 2016

@Eosis Lots has happened around networking since this patch. Please clean up and re-open if still valid

@sg- sg- closed this Oct 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants