Documentation
¶
Index ¶
- func DetachSocketFilter(f *os.File) error
- func GetPortRange() (start, end uint16)
- type OSAllocator
- type PortAllocator
- func (p *PortAllocator) ReleaseAll()
- func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int)
- func (p *PortAllocator) RequestPort(ip net.IP, proto string, port int) (int, error)
- func (p *PortAllocator) RequestPortInRange(ip net.IP, proto string, portStart, portEnd int) (int, error)
- func (p *PortAllocator) RequestPortsInRange(ips []net.IP, proto string, portStart, portEnd int) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetachSocketFilter ¶
DetachSocketFilter removes the BPF filter set during port allocation to prevent the kernel from accepting connections before DNAT rules are inserted.
func GetPortRange ¶
func GetPortRange() (start, end uint16)
GetPortRange returns the PortAllocator's default port range.
This function is for internal use in tests, and must not be used for other purposes.
Types ¶
type OSAllocator ¶
type OSAllocator struct {
// contains filtered or unexported fields
}
func NewOSAllocator ¶
func NewOSAllocator() OSAllocator
func (OSAllocator) ReleasePorts ¶
ReleasePorts releases a common port reserved for a list of addrs. It doesn't close the sockets bound by [RequestPortsInRange]. This must be taken care of independently by the caller.
func (OSAllocator) RequestPortsInRange ¶
func (pa OSAllocator) RequestPortsInRange(addrs []net.IP, proto types.Protocol, portStart, portEnd int) (_ int, _ []*os.File, retErr error)
RequestPortsInRange reserves a port available in the range [portStart, portEnd] for all the specified addrs, and then try to bind/listen those addresses to allocate the port from the OS.
It returns the allocated port, and all the sockets bound, or an error if the reserved port isn't available. These sockets have a filter set to ensure that the kernel doesn't accept connections on these. Callers must take care of calling DetachSocketFilter once they're ready to accept connections (e.g. after setting up DNAT rules, and before starting the userland proxy), and they must take care of closing the returned sockets.
It's safe for concurrent use.
type PortAllocator ¶
type PortAllocator struct {
// contains filtered or unexported fields
}
PortAllocator manages the transport ports database
func (*PortAllocator) ReleaseAll ¶
func (p *PortAllocator) ReleaseAll()
ReleaseAll releases all ports for all ips.
func (*PortAllocator) ReleasePort ¶
func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int)
ReleasePort releases port from global ports pool for specified ip and proto.
func (*PortAllocator) RequestPort ¶
RequestPort requests new port from global ports pool for specified ip and proto. If port is 0 it returns first free port. Otherwise it checks port availability in proto's pool and returns that port or error if port is already busy.
func (*PortAllocator) RequestPortInRange ¶
func (p *PortAllocator) RequestPortInRange(ip net.IP, proto string, portStart, portEnd int) (int, error)
RequestPortInRange is equivalent to PortAllocator.RequestPortsInRange with a single IP address. If ip is nil, a port is instead requested for the default IP (0.0.0.0).
func (*PortAllocator) RequestPortsInRange ¶
func (p *PortAllocator) RequestPortsInRange(ips []net.IP, proto string, portStart, portEnd int) (int, error)
RequestPortsInRange requests new ports from the global ports pool, for proto and each of ips. If portStart and portEnd are 0 it returns the first free port in the default ephemeral range. If portStart != portEnd it returns the first free port in the requested range. Otherwise, (portStart == portEnd) it checks port availability in the requested proto's port-pool and returns that port or error if port is already busy.