p2p/nat: handle responses with alternative port in NAT-PMP (#26321)
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
f20eba426a
commit
42212808f0
@ -50,10 +50,24 @@ func (n *pmp) AddMapping(protocol string, extport, intport int, name string, lif
|
|||||||
}
|
}
|
||||||
// Note order of port arguments is switched between our
|
// Note order of port arguments is switched between our
|
||||||
// AddMapping and the client's AddPortMapping.
|
// AddMapping and the client's AddPortMapping.
|
||||||
_, err := n.c.AddPortMapping(strings.ToLower(protocol), intport, extport, int(lifetime/time.Second))
|
res, err := n.c.AddPortMapping(strings.ToLower(protocol), intport, extport, int(lifetime/time.Second))
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NAT-PMP maps an alternative available port number if the requested
|
||||||
|
// port is already mapped to another address and returns success. In this
|
||||||
|
// case, we return an error because there is no way to return the new port
|
||||||
|
// to the caller.
|
||||||
|
if uint16(extport) != res.MappedExternalPort {
|
||||||
|
// Destroy the mapping in NAT device.
|
||||||
|
n.c.AddPortMapping(strings.ToLower(protocol), intport, 0, 0)
|
||||||
|
return fmt.Errorf("port %d already mapped to another address (%s)", extport, protocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (n *pmp) DeleteMapping(protocol string, extport, intport int) (err error) {
|
func (n *pmp) DeleteMapping(protocol string, extport, intport int) (err error) {
|
||||||
// To destroy a mapping, send an add-port with an internalPort of
|
// To destroy a mapping, send an add-port with an internalPort of
|
||||||
// the internal port to destroy, an external port of zero and a
|
// the internal port to destroy, an external port of zero and a
|
||||||
|
Loading…
Reference in New Issue
Block a user