Closed rankaiyx closed 1 year ago
Is possible to do this in hook script? add port mapping rule by call upnp client util (e.g. miniupnpc).
Both methods can do this by plug-in or by integrating a upnp server. We can try both methods and see which is easier to implement.
I found a upnp project that may be of reference value. https://github.com/ofekp/TinyUPnP
https://www.rfc-editor.org/rfc/rfc6886.html
"Correspondingly, NAT-PMP allows a client to request a desired external port, and if that external port is already in use by some other client, the NAT-PMP server will instead assign some other available external port. UPnP IGD does not do this. "
This gives us the opportunity to return the actual external port to the client.
I've made a simple implementation with nodejs.
I've made a simple implementation with nodejs.
https://github.com/OpportunityLiu/nat-mapmp Great! We need a usage document.
Great! We need a usage document.
I've added readme and releases. You can also use ./nat-mapmp.mjs --help
to see all options.
https://www.rfc-editor.org/rfc/rfc6886.html
"Correspondingly, NAT-PMP allows a client to request a desired external port, and if that external port is already in use by some other client, the NAT-PMP server will instead assign some other available external port. UPnP IGD does not do this. "
This gives us the opportunity to return the actual external port to the client.
https://datatracker.ietf.org/doc/html/rfc6886#section-9
Basically, run UPnP IGD server behind NAT is impossible, as well as PCP with PREFER_FAILURE support (which is designed for working with IGD, see https://datatracker.ietf.org/doc/html/rfc6887#section-13.2)
As rfc6970 Universal Plug and Play (UPnP) Internet Gateway Device - Port Control Protocol Interworking Function suggests, an IGD-PCP server will respond ConflictInMappingEntry
for AddPortMapping()
request, which will cause an IGD client trying all 65536 ports, and results in nothing.
Add upnp function to the router so that port mapping can be completed automatically. This should be an exciting feature.