Skip to content

Commit

Permalink
add DeleteExternalPortMapping to the NAT interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Inuart committed Mar 11, 2019
1 parent 5172223 commit 5a9c2ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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

0 comments on commit 5a9c2ce

Please sign in to comment.