Documentation ¶
Overview ¶
Package pnet provides IP-related functions with few dependencies beyond the net package
Index ¶
- Constants
- Variables
- func CheckRedirect(req *http.Request, via []*http.Request) (err error)
- func Get(requestURL string, tlsConfig *tls.Config, ctx context.Context) (resp *http.Response, err error)
- func IPAddr(IP net.IP, index IfIndex, zone string) (ipa *net.IPAddr, err error)
- func IPNetString(ipNet net.IPNet) (s string)
- func InvertMask(IPMask net.IPMask) (out net.IPMask)
- func IsBroadcast(addr netip.Addr, IPMask net.IPMask) (isBroadcast bool)
- func IsDirect(route netip.Prefix) bool
- func IsErrClosed(err error) (isErrNetClosing bool)
- func IsHardwareAddrLength(byts []byte) (isHardwareAddrLength bool)
- func IsIPv4(ip net.IP) (isIPv4 bool)
- func IsIPv6(ip net.IP) (isIPv6 bool)
- func IsNetwork(IP net.IP, IPMask net.IPMask) (isNetwork bool)
- func IsNzIP(ip net.IP) bool
- func IsZeros(p net.IP) bool
- func NetworkPrefixBitCount(byts []byte) (bits int)
- func NewTLSConfig(cert *x509.Certificate) (tlsConfig *tls.Config)
- func NewTransport(tlsConfig *tls.Config) (httpTransport *http.Transport)
- type Callback
- type Destination
- type HandlerFunc
- type Http
- func (hp *Http) CloseErr()
- func (hp *Http) HandleFunc(pattern string, handler HandlerFunc)
- func (hp *Http) Listen() (errCh <-chan error)
- func (hp *Http) Listener() (listener net.Listener, err error)
- func (hp *Http) SendErr(err error)
- func (hp *Http) Shutdown()
- func (hp *Http) SubListen() (errCh <-chan error)
- func (hp *Http) WaitForUp() (isUp bool, addr net.Addr)
- type HttpClient
- type Https
- type IfIndex
- type LinkAddr
- type Message
- type NextHop
- func EmptyNextHop() *NextHop
- func NewNextHop(gateway netip.Addr, linkAddr *LinkAddr, src netip.Addr) (nextHop *NextHop)
- func NewNextHop2(index IfIndex, gateway netip.Addr, src netip.Addr) (next *NextHop, err error)
- func NewNextHopCounts(gateway netip.Addr, linkAddr *LinkAddr, src netip.Addr) (nextHop *NextHop, err error)
- type Route
- type TCPListener
- type Tcp
- type UDP
- type UDPFunc
Constants ¶
const ( HardwareAddrMac48 = 6 HardwareAddrEui64 = 8 HardwareAddrInfini = 20 )
const ( // DefaultRouteIPv4 is the default route 0/0 for IPv4 DefaultRouteIPv4 = "0.0.0.0/0" // VPNRoute0IPv4 is overriding VPN route 0/1 for IPv4 VPNRoute0IPv4 = "0.0.0.0/1" // VPNRoute128IPv4 is overriding VPN route 128/1 for IPv4 VPNRoute128IPv4 = "128.0.0.0/1" // DefaultRouteIPv6 is the default route ::/0 for IPv6 DefaultRouteIPv6 = "::/0" // VPNRouteIPv6 is overriding VPN route ::/3 for IPv6 VPNRouteIPv6 = "::/3" )
const (
TCPNetwork = "tcp"
)
Variables ¶
var HardwareAddrLengths = []int{HardwareAddrMac48, HardwareAddrEui64, HardwareAddrInfini}
var HardwareAddrLengthsWithZero = append([]int{0}, HardwareAddrLengths...)
Functions ¶
func InvertMask ¶
InvertMask inverts the bits of a mask the mask for 1.2.3.4/24 is normally ffffff00 or []byte{255, 255, 255, 0}
func IsBroadcast ¶
IsBroadcast determines whether addr is the last address for Mask
- the last address is typically broadcast
- for 1.2.3.4/24 the network address 1.2.3.255 returns true
func IsDirect ¶
IsDirect determines if the route is direct
- a direct route has mask 32 or 128 bit length /32 /128
func IsErrClosed ¶ added in v0.4.26
func IsHardwareAddrLength ¶ added in v0.4.28
func IsNetwork ¶
IsNetwork determines if IP is the network address (all zeros) for this Mask for 1.2.3.4/24 the network address 1.2.3.0 returns true
func NetworkPrefixBitCount ¶ added in v0.4.29
func NewTLSConfig ¶
func NewTLSConfig(cert *x509.Certificate) (tlsConfig *tls.Config)
Types ¶
type Callback ¶
type Callback func(msg Message)
Callback allows for processing of routing message,eg. populating a map
type Destination ¶
Destination represents a selector for routing, ie. an IPv4 or IPv6 address with zone and prefix. go1.18 introduced netip.Prefix for this purpose see Linux: ip route add. [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ] contains IP, Zone and Mask
func NewDestination ¶
func NewDestination(prefix netip.Prefix) (d *Destination, err error)
NewDestination instantiates Destination. addr is IPv4 address or IPv6 address with Zone. prefix is number of bits actually used 0…32 for IPv4, 0…128 for IPv6
func (Destination) Key ¶
func (d Destination) Key() (key netip.Prefix)
Key is a string suitable as a key in a map
func (Destination) String ¶
func (d Destination) String() (s string)
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request)
type Http ¶
type Http struct { Network string // "tcp", "tcp4", "tcp6", "unix" or "unixpacket" http.Server ListenInvoked parl.AtomicBool ReadyWg sync.WaitGroup ErrCh chan<- error ErrChMutex sync.Mutex ErrChClosed parl.AtomicBool net.Addr // interface IsListening parl.AtomicBool IsShutdown parl.AtomicBool }
func (*Http) HandleFunc ¶
func (hp *Http) HandleFunc(pattern string, handler HandlerFunc)
type HttpClient ¶
func NewHttpClient ¶
func NewHttpClient(tlsConfig *tls.Config) (httpClient *HttpClient)
type Https ¶
type Https struct { Http Cert parl.CertificateDer Private crypto.Signer }
type IfIndex ¶
type IfIndex uint32
IfIndex is a dynamic reference to a network interface on Linux systems
func NewIfIndex ¶ added in v0.4.28
func (IfIndex) InterfaceIndex ¶ added in v0.4.28
Interface gets net.Interface for ifIndex
type LinkAddr ¶
type LinkAddr struct { IfIndex // 0 is none Name string // "" none net.HardwareAddr // []byte }
LinkAddr contains an Ethernet mac address, its interface name and interface index
func NewLinkAddr ¶
NewLinkAddr instantiates LinkAddr
func (*LinkAddr) UpdateName ¶
UpdateName attempts to populate interface name if not already present
type NextHop ¶
type NextHop struct { /* if NextHop is an address on the local host or on a local subnet, Gateway is nil LinkAddr describes the local interface Src is the address on that local interface If Nexthop is remote, beyond any local subnet, Gateway is an IP on a local subnet LinkAddr describes the local interface for that subnet Src is the address on that local interface */ Gateway netip.Addr LinkAddr // LinkAddr is the hosts’s network interface where to send packets Src netip.Addr // the source ip to use for originating packets on LinkAddr // contains filtered or unexported fields }
NextHop describes a route target
func NewNextHop ¶
NewNextHop assembles a route destination
func NewNextHop2 ¶
NewNextHop2 assembles a route destination based on IfIndex
func NewNextHopCounts ¶ added in v0.4.28
func (*NextHop) HasGateway ¶
HasGateway determines if next hop uses a remote gateway
type Route ¶
type Route struct { Destination NextHop }
Route describes a routing table route with destination and next hop
type TCPListener ¶ added in v0.4.62
type TCPListener struct { net.TCPListener // contains filtered or unexported fields }
TCPListener embeds net.TCPListener
- NewListenTCP4 initializes
- go AcceptThread handles inbound connections
- Ch provides the error channel
- Close closes TCPListener
- Wait awaits last handler exit
func NewListenTCP4 ¶ added in v0.4.62
func NewListenTCP4(socketString string, handler func(net.Conn)) (socket *TCPListener, err error)
NewListenTCP4 returns a tcp listener on a local IPv4 network interface
- socketString is host:port "1.2.3.4:80"
- — host must be literal IPv4 address 1.2.3.4
- — port must be literal port number 0…65534 where 0 means a temporary port
- network is always "tcp4"
- handler must invoke net.Conn.Close
func (*TCPListener) AcceptThread ¶ added in v0.4.62
func (s *TCPListener) AcceptThread()
AcceptThread is a goroutine handling inbound connections
func (*TCPListener) Ch ¶ added in v0.4.62
func (s *TCPListener) Ch() (ch <-chan error)
func (*TCPListener) Err ¶ added in v0.4.62
func (s *TCPListener) Err(errp *error)
func (*TCPListener) IsAcceptThread ¶ added in v0.4.62
func (s *TCPListener) IsAcceptThread() (isAcceptThread bool)
IsAcceptThread indicates whether the listener is functional and accepting incoming connections
func (*TCPListener) Wait ¶ added in v0.4.62
func (s *TCPListener) Wait()
Wait waits for all connections and the handler thread to exit. ListenTCP4.Close needs to be invoked
type UDP ¶
type UDP struct { Network string F UDPFunc MaxSize int net.UDPAddr // struct IP Port Zone ListenInvoked parl.AtomicBool StartingListen sync.WaitGroup ErrCh chan<- error IsListening parl.AtomicBool NetUDPConn *net.UDPConn Addr net.Addr IsShutdown parl.AtomicBool // contains filtered or unexported fields }