Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Compatibility with lwIP and ESP-IDF #13

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

snej
Copy link
Contributor

@snej snej commented Jul 2, 2018

lwIP = Lightweight IP library
http://savannah.nongnu.org/projects/lwip/

ESP-IDF = iOT Development Framework for Espressif's ESP32 chip
https://github.com/espressif/esp-idf

New preprocessor flags for configuration:

  • NYOCI_LWIP -- define if compiling for lwIP. Will be automatically
    defined if ESP_PLATFORM is defined (i.e. building for ESP-IDF.)
  • NYOCI_CAN_POLL -- Indicates the poll system call is available and
    should be used instead of select. Defaults to 1 unless building
    for lwIP; explicitly define it as 0 to force use of select.
  • NYOCI_CAN_SENDMSG -- Indicates the sendmsg system call is
    available and should be used instead of send. Defaults to 1 unless
    building for lwIP; explicitly define it as 0 to force use of send.
    Note: send does not support setting the “from” address of the
    packet.

Fixes #8

(I also added a one-line commit that fixes a recent regression on the master branch
that I discovered when rebasing just now.)

snej added 2 commits July 2, 2018 10:45
lwIP = Lightweight IP library
<http://savannah.nongnu.org/projects/lwip/>

ESP-IDF = iOT Development Framework for Espressif's ESP32 chip
<https://github.com/espressif/esp-idf>

New preprocessor flags for configuration:
* NYOCI_LWIP -- define if compiling for lwIP. Will be automatically
  defined if ESP_PLATFORM is defined (i.e. building for ESP-IDF.)
* NYOCI_CAN_POLL -- Indicates the `poll` system call is available and
  should be used instead of `select`. Defaults to 1 unless building
  for lwIP; explicitly define it as 0 to force use of `select`.
* NYOCI_CAN_SENDMSG -- Indicates the `sendmsg` system call is
  available and should be used instead of `send`. Defaults to 1 unless
  building for lwIP; explicitly define it as 0 to force use of `send`.
  Note: `send` does not support setting the “from” address of the
  packet.
`==` has higher precedence than `&`, so the expression wasn’t doing
what was intended.
@darconeous
Copy link
Owner

I think a better approach would be to create a net platform rather than modifying the posix platform in-place, even if the new platform is based on posix.

Maybe call it plat-net/lwip-sockets?

@@ -320,7 +320,7 @@ nyoci_outbound_add_options_up_to_key_(

#if NYOCI_CONF_TRANS_ENABLE_OBSERVING
if ( (self->current_transaction != NULL)
&& (self->current_transaction->flags & NYOCI_TRANSACTION_OBSERVE == NYOCI_TRANSACTION_OBSERVE)
&& ((self->current_transaction->flags & NYOCI_TRANSACTION_OBSERVE) == NYOCI_TRANSACTION_OBSERVE)
Copy link
Owner

Choose a reason for hiding this comment

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

Good catch! Mind pulling this commit out into it's own pull request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't claim credit -- GCC found it and warned me (but I can't remember which warning flag it was.)
I'll submit a separate PR when I have a chance.

@snej
Copy link
Contributor Author

snej commented Jul 6, 2018

I think a better approach would be to create a net platform rather than modifying the posix platform in-place, even if the new platform is based on posix.

But that would mean duplicating ~1200 lines of code, which I couldn't bring myself to do (I'm pretty strict about DRY.)

Consider also that most of the changes aren't specific to lwIP; they'll add support for any other POSIX-like platform that's missing poll and/or sendmsg.

But it is of course your call. I may just keep my fork, err, forked. In that case, mind if I submit a smaller PR for just the ESP32-specific changes (e.g. to logging?)

@darconeous
Copy link
Owner

darconeous commented Jul 7, 2018

I'll take another look over the changes. If there are other POSIX platforms that your changes help make LibNyoci build on (Solaris? QNX? Minix?), then I'd be inclined to accept it. QNX in particular might benefit from it.

But I may end up just going ahead and implementing support for native LWIP.

Travis is failing here with these changes:

../../../../src/plat-net/posix/nyoci-plat-net.c:922:4: error: field designator 'sin6_len' does not refer to any field in type 'struct sockaddr_in6'
                .sin6_len = sizeof(struct sockaddr_in6),
                 ^

But let me review this stuff before you spend any significant amount of time trying to address that.

@@ -79,6 +80,12 @@
PSTR(__FILE__ ":%d: "fmt"\n"), \
__LINE__, \
__VA_ARGS__)
#elif ESP_PLATFORM
Copy link
Owner

Choose a reason for hiding this comment

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

I like all of the changes in this file, including the errno stuff. May be worth spinning out.

Copy link
Owner

@darconeous darconeous left a comment

Choose a reason for hiding this comment

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

I'm still reviewing, but I like several of your changes so far. There are a few minor style issues (some spaces snuck in where tabs should be, etc), but I won't nit-pick those until I'm sure I grok the whole picture—which I will try to do in the morning.

@@ -34,40 +34,46 @@

#if !VERBOSE_DEBUG

#define CSTR(x) (x)
#define CSTR(x) (x)
Copy link
Owner

Choose a reason for hiding this comment

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

I'd rather significant changes in the whitespace not be combined with material additions or changes to a file, unless it is unavoidable. It makes the diffs harder to read.

That aside, I'm having trouble getting my brain to not be weirded out by the use of full indents, though. That's largely why I used single-space indents in assert-macros.h: indented preprocessor macros look weird to me after 20+ years of not indenting them at all. I found the single-space indentation improved readability for assert-macros.h without looking too weird to my eyes, but maybe I'm just being stubborn and tabs are really the way to go.

@@ -230,7 +287,7 @@ nyoci_plat_init(nyoci_t self) {
#if NYOCI_PLAT_NET_POSIX_FAMILY == AF_INET6
if (self->plat.mcfd_v6 == -1) {
self->plat.mcfd_v6 = socket(AF_INET6, SOCK_DGRAM, 0);
check(self->plat.mcfd_v6 >= 0);
check_errno(self->plat.mcfd_v6 >= 0);
Copy link
Owner

Choose a reason for hiding this comment

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

+1 for all of these sorts of changes.

ret = sendmsg(fd, &msg, flags);

check(ret > 0);
check_string(ret >= 0, strerror(errno));
#else // !NYOCI_CAN_SENDMSG
abort(); //TODO
Copy link
Owner

Choose a reason for hiding this comment

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

It's a little hard to tell what is going on here from looking at the diff on GitHub. Why is this abort() here? Would an #error be more suitable?

}
ret = nyoci_plat_update_fdsets(self, &reads, &writes, &errors, &fdCount, &cms);
if (ret != NYOCI_STATUS_OK)
goto bail;
Copy link
Owner

Choose a reason for hiding this comment

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

I know there is a lot of old code in LibNyoci that doesn't use braces for single-line if() statements, but ever since the goto fail bug I require the use of curly braces for all if() statements in all new code, even if copy-pasted.

@darconeous
Copy link
Owner

Good news: It looks like I'll be adding real native support for LWIP at some point between now and the end of November. I'll also be adding support for bare-bones OpenThread.

@darconeous
Copy link
Owner

You've got some good changes in this PR, so I'm going to keep this open for now.

snej added 7 commits August 20, 2018 17:32
Mostly so that an outgoing packet can be logged by coap_dump_header.
strtol returns an long, not a pointer.
It wasn’t at all obvious how to specify the CoAP URL, without
browsing the source code...
Added FETCH/PATCH and status codes from RFC 8132.
Changed Internet-Draft references to the RFCs they became.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for lwIP
2 participants