Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module github.com/fd/go-nat
module github.com/Inuart/go-nat

require (
github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324
github.com/jackpal/gateway v1.0.5
github.com/jackpal/go-nat-pmp v1.0.1
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79
golang.org/x/text v0.3.0
github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 // indirect
golang.org/x/text v0.3.0 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324 h1:PV190X5/DzQ/tbFFG5YpT5mH6q+cHlfgqI5JuRnH9oE=
github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag=
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA=
github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ=
github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk=
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 h1:1FDlG4HI84rVePw1/0E/crL5tt2N+1blLJpY6UZ6krs=
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3 changes: 3 additions & 0 deletions nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type NAT interface {

// DeletePortMapping removes a port mapping.
DeletePortMapping(protocol string, internalPort int) (err error)

// DeleteExternalPortMapping removes an external port mapping.
DeleteExternalPortMapping(protocol string, externalPort int) (err error)
}

// DiscoverGateway attempts to find a gateway device.
Expand Down
6 changes: 5 additions & 1 deletion natpmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/jackpal/gateway"
"github.com/jackpal/go-nat-pmp"
natpmp "github.com/jackpal/go-nat-pmp"
)

var (
Expand Down Expand Up @@ -110,6 +110,10 @@ func (n *natpmpNAT) DeletePortMapping(protocol string, internalPort int) (err er
return nil
}

func (u *natpmpNAT) DeleteExternalPortMapping(protocol string, externalPort int) error {
return nil
}

func (n *natpmpNAT) Type() string {
return "NAT-PMP"
}
12 changes: 12 additions & 0 deletions upnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ func (u *upnp_NAT) DeletePortMapping(protocol string, internalPort int) error {
return nil
}

func (u *upnp_NAT) DeleteExternalPortMapping(protocol string, externalPort int) error {
if externalPort <= 0 {
return nil
}
for i, e := range u.ports {
if e == externalPort {
delete(u.ports, i)
}
}
return u.c.DeletePortMapping("", uint16(externalPort), mapProtocol(protocol))
}

func (u *upnp_NAT) GetDeviceAddress() (net.IP, error) {
addr, err := net.ResolveUDPAddr("udp4", u.rootDevice.URLBase.Host)
if err != nil {
Expand Down