-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: master
Are you sure you want to change the base?
Conversation
lib/ZInit.c
Outdated
#if defined(__APPLE__) && defined(__MACH__) | ||
if (__My_addr.s_addr == INADDR_NONE) { | ||
nwi_state_t state; | ||
state = nwi_state_copy(); |
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.
Why not merge these two lines?
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.
No good reason other than trying to copy local style.
@@ -0,0 +1,286 @@ | |||
/* |
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.
Why is there an Apple header included? Is this not part of the macOS SDK?
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.
It's not; the header is distributed in a separate tarball. The symbols are, however, part of the SDK libraries.
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'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(); |
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.
Why? Is this just to close the UPnP session before we exit?
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.
Yes, otherwise the UPnP port mapping will persist on the router until you reboot the router.
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 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/ZSubs.c
Outdated
@@ -93,6 +93,12 @@ ZSubscriptions(register ZSubscription_t *sublist, | |||
int size, start, numok; | |||
Z_AuthProc cert_routine; | |||
|
|||
if (ZGetFD() < 0) |
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.
Please add {} to all new ifs. braceless if statements should be discouraged.
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 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]; |
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.
Why 16? Port are only 0..65535, so shouldn't [8] be sufficient?
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 is copied verbatim from the library.
} | ||
if (__UPnP_active) { | ||
char port_str[16]; | ||
snprintf(port_str, 16, "%d", ntohs(__Zephyr_port)); |
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.
Error checking to make sure snprintf didn't overflow?
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.
As is this.
I'd like at least one other person (@kaduk, perhaps?) to review before we merge this one. |
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.
Thanks for the changes.
This patch series uses UPnP to make Zephyr work transparently behind a consumer-grade NAT that supports UPnP-IGD.