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

Add initial PCP support #17

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

Conversation

sashahilton00
Copy link

After checking activity, it looks like upstream is dead. Am thus creating a PR for this repo. Copy pasted from original PR, last part may not apply to the same extent:

This isn't ready to merge yet, as some of the logic for a correct implementation is missing upstream, but I would be grateful if someone with a router that supports PCP could test this and let me know if it is working as expected (ie. it creates a mapping).

There is also potential for a bigger rework of go-nat in general, as the architecture of PCP is quite different from previous NAT traversal implementations, as it takes into account multiple network interfaces, supports IPv4 and IPv6, and server sent events.

@sashahilton00
Copy link
Author

Not sure what is wrong with Travis, looks like it couldn't download a setup script.

@Stebalien Stebalien added the status/blocked Unable to be worked further until needs are met label Feb 14, 2020
@Stebalien
Copy link
Member

Awesome! I'll see if we can find someone to test this (I've asked on IRC, we'll see...).

Could you quickly run your code through the go race detector? It looks like there might be a few issues.

@sashahilton00
Copy link
Author

Yeah that'd be useful. I'm sure there are a few race conditions that I've missed, just trying to get the logic implemented atm, then will tidy it up and refactor where needed (hence WIP). If there are any that you see off the bat feel free to open an issue and I'll take a look.

Wasn't aware of the race detector bundled with go. What is the proper way to use it? It looks as though it'll have to wait until I create some tests, unless there's something I'm missing?

@Stebalien
Copy link
Member

If there are any that you see off the bat feel free to open an issue and I'll take a look.

You're canceling by setting a variable that's read by a different thread. Go reserves the right to never observe that update. Check out https://golang.org/ref/mem for more details.

(there may be others, that's why I suggested you try the race detector).

Wasn't aware of the race detector bundled with go. What is the proper way to use it? It looks as though it'll have to wait until I create some tests, unless there's something I'm missing?

You can use it with go test -race ... or go build -race.

@sashahilton00
Copy link
Author

sashahilton00 commented Feb 15, 2020

You're canceling by setting a variable that's read by a different thread. Go reserves the right to never observe that update. Check out https://golang.org/ref/mem for more details.

Good spot, have corrected it, now uses a channel. Have run the race detector, doesn't give any output, which I assume means no race conditions were found.

I've also got some code for implementing connection timeout/testing, but due to being unable to test on an actual server, I'm not committing it currently, as it could break the connection logic if the implementation is bad. I've stuck it in the udp-timeout branch, I'd appreciate any testing (running the example should be enough, it'll show some request and response bytes).

@bonedaddy
Copy link

Any updates or stuff that can be done to help push this along? Need functionality like this.

@Stebalien
Copy link
Member

This is blocked on testing the underlying library against a real device.

@sashahilton00
Copy link
Author

I should hopefully be able to test this soon, have ordered a router with PCP support. I also need to rewrite some parts of it as things like connection checking are not implemented yet.

@bonedaddy
Copy link

This is blocked on testing the underlying library against a real device.

Hmm is this not a feature widely supported? I did a google search and I couldn't find anything specific to PCP support with various routers. I have at my disposal:

  • 1x SG-2220
  • 2x XG-7100
  • A bunch of linksys, actiontec, and residential grade routers/modem combos

@sashahilton00
Copy link
Author

This is blocked on testing the underlying library against a real device.

Hmm is this not a feature widely supported? I did a google search and I couldn't find anything specific to PCP support with various routers. I have at my disposal:

* 1x SG-2220

* 2x XG-7100

* A bunch of linksys, actiontec, and residential grade routers/modem combos

feel free to test the underlying library if you have a router that supports it. Sadly I have to use a Vodafone supplied China Inc. router that has the bare minimum in terms of functionality. Am in the process of switching atm, then once that's done, will test with new router.

@bonedaddy
Copy link

This is blocked on testing the underlying library against a real device.

Hmm is this not a feature widely supported? I did a google search and I couldn't find anything specific to PCP support with various routers. I have at my disposal:

* 1x SG-2220

* 2x XG-7100

* A bunch of linksys, actiontec, and residential grade routers/modem combos

feel free to test the underlying library if you have a router that supports it. Sadly I have to use a Vodafone supplied China Inc. router that has the bare minimum in terms of functionality. Am in the process of switching atm, then once that's done, will test with new router.

So interestingly I tested the changes in this PR, and my router appears to support PCP and is recognized by the _examples in this repo. However in your underlying library in the examples I ran and got the following:

INFO[0000] Internal IP: 192.168.0.208 Gateway IP: 192.168.0.1 
DEBU[0000] Client addr: 192.168.0.208                   
DEBU[0000] Number of options in request: 0              
DEBU[0000] Request Bytes: 0201000000000e1000000000000000000000ffffc0a800d0126a9d6bf028a64fa1295907060000001f9000000000000000000000000000000000000000000000 
DEBU[0000] 1584319204 1584318754 450                    
DEBU[0000] max - current: 2250 min - current: 1800 random int: 2157, lifetime: 3600 
DEBU[0000] Refresh max: 1584319204 Refresh min: 1584318754 Time now: 1584316954 Interval: 1584319111 
DEBU[0000] successfully sent port map request           
DEBU[0000] Client addr: 192.168.0.208                   
DEBU[0000] Number of options in request: 0              
DEBU[0000] Request Bytes: 020100000000001e00000000000000000000ffffc0a800d0126a9d6bf028a64fa1295907110000000009000000000000000000000000ffffc0a800d000000000 
DEBU[0000] 1584316972 1584316969 3                      
DEBU[0000] max - current: 18 min - current: 15 random int: 16, lifetime: 30 
DEBU[0000] Refresh max: 1584316972 Refresh min: 1584316969 Time now: 1584316954 Interval: 1584316970 
DEBU[0000] Error occurred when receiving UDP packet: read udp 192.168.0.208:58757->192.168.0.1:5351: recvfrom: connection refused 

@sashahilton00
Copy link
Author

It’s possible that I missed something. I have just received the router, so I’ll be testing it over the coming days hopefully.

@sashahilton00
Copy link
Author

Just to provide an update, the router arrived, I have been testing it, there are a few bugs that I have found, and will fix when I have a moment, mostly surrounding the PCP options logic and refresh logic. I encountered the same error that you had @bonedaddy but it was due to not having upnp2 enabled on the router, after that it was fine.

@bt90
Copy link

bt90 commented Sep 12, 2023

miniupnpd should also implement PCP, so testing shouldn't require dedicated hardware.

https://github.com/miniupnp/miniupnp/blob/master/README#L11-L12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/blocked Unable to be worked further until needs are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants