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

Use UPnP to punch holes in NATs #142

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

Conversation

quentinmit
Copy link
Contributor

This patch series uses UPnP to make Zephyr work transparently behind a consumer-grade NAT that supports UPnP-IGD.

lib/ZInit.c Outdated
#if defined(__APPLE__) && defined(__MACH__)
if (__My_addr.s_addr == INADDR_NONE) {
nwi_state_t state;
state = nwi_state_copy();
Copy link
Member

Choose a reason for hiding this comment

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

Why not merge these two lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No good reason other than trying to copy local style.

@@ -0,0 +1,286 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Why is there an Apple header included? Is this not part of the macOS SDK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not; the header is distributed in a separate tarball. The symbols are, however, part of the SDK libraries.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not enthusiastic about having to ship an Apple header for macOS support, but the licence is permissive, so I guess it's fine.

@@ -183,6 +183,7 @@ main(int argc,
if (code)
fprintf (stderr, "%s: %s: %s\n",
argv[0], error_message (code), ssline);
ZClosePort();
Copy link
Member

Choose a reason for hiding this comment

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

Why? Is this just to close the UPnP session before we exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, otherwise the UPnP port mapping will persist on the router until you reboot the router.

Copy link
Member

Choose a reason for hiding this comment

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

This is really making me want to have a proper zephyr_ctx that we can manage the lifecycle with. It's a bit annoying we can't easily test for these sorts of port leaks. Not something to address now, of course.

lib/ZInit.c Outdated Show resolved Hide resolved
lib/ZInit.c Outdated Show resolved Hide resolved
lib/ZSubs.c Outdated
@@ -93,6 +93,12 @@ ZSubscriptions(register ZSubscription_t *sublist,
int size, start, numok;
Z_AuthProc cert_routine;

if (ZGetFD() < 0)
Copy link
Member

Choose a reason for hiding this comment

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

Please add {} to all new ifs. braceless if statements should be discouraged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was copied and pasted verbatim from a different file that didn't have curly braces. I added them.

__UPnP_active = UPNP_GetIGDFromUrl(__UPnP_rooturl, &__UPnP_urls, &__UPnP_data, NULL, 0);
}
if (__UPnP_active) {
char port_str[16];
Copy link
Member

Choose a reason for hiding this comment

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

Why 16? Port are only 0..65535, so shouldn't [8] be sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copied verbatim from the library.

}
if (__UPnP_active) {
char port_str[16];
snprintf(port_str, 16, "%d", ntohs(__Zephyr_port));
Copy link
Member

Choose a reason for hiding this comment

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

Error checking to make sure snprintf didn't overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As is this.

lib/ZUPnP.c Outdated Show resolved Hide resolved
lib/ZUPnP.c Show resolved Hide resolved
@achernya
Copy link
Member

I'd like at least one other person (@kaduk, perhaps?) to review before we merge this one.

Copy link
Member

@achernya achernya left a comment

Choose a reason for hiding this comment

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

Thanks for the changes.

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.

2 participants