portfinder

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2022 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Overview

Package portfinder helps with reasoning about rule expressions about port forwarding in combination with destination NAT (“DNAT”).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForwardedPortLess

func ForwardedPortLess(a, b *ForwardedPortRange) bool

ForwardedPortLess returns true if the forwarded port range a comes before b. The sorting order of two forwarded port ranges a and b is defined as follows:

  • IPv4 addresses come before IPv6 addresse (or, in other words: IPv4 addresses are less than IPv6 addresses *snicker*).
  • by the original (host) IP address,
  • by the original beginning of the port range,
  • finally by the IP address forwarding to.

Types

type ForwardedPortRange

type ForwardedPortRange struct {
	Protocol       string // such as "tcp" and "udp".
	IP             net.IP // the original destination IP address to forward from, if any.
	PortMin        uint16 // original destination port...
	PortMax        uint16 // ...or port range.
	ForwardIP      net.IP // new destionation IP address to forward to.
	ForwardPortMin uint16 // the new (min) destination port to forward to.
}

ForwardedPortRange describes a port or port range in a network namespace (such as the "host") to be forwarded to a potentially shifted range of ports on one or more new destination IP(s). Multiple forwarded destination IPs can used in case of load-balancing between multiple instances of the same service.

func ForwardedPort

func ForwardedPort(rule nufftables.Rule) *ForwardedPortRange

ForwardedPort returns the port range forwarding if contained in the passed nufftables.Rule, otherwise nil.

ForwardedPort ensures that the returned IP addresses are always in their canonical IPv4 format, and never in form of IPv4-mapped addresses.

func (ForwardedPortRange) String

func (f ForwardedPortRange) String() string

String returns the port forwarding information in plain textual format, such as for simple logging, et cetera. In case of a single forwarded port only, the port range automatically will be collapsed into a single port only.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL