pnet

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: ISC Imports: 16 Imported by: 0

Documentation

Overview

Package parlnet provides IP-related functions with few dependencies beyond the net package

Index

Constants

View Source
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"
)
View Source
const (
	TCPNetwork = "tcp"
)

Variables

This section is empty.

Functions

func CheckRedirect

func CheckRedirect(req *http.Request, via []*http.Request) (err error)

func Get

func Get(requestURL string, tlsConfig *tls.Config, ctx context.Context) (resp *http.Response, err error)

func IPAddr

func IPAddr(IP net.IP, index IfIndex, zone string) (ipa *net.IPAddr, err error)

IPAddr returns IPAddr from IP and IfIndex to IPAddr

func IPNetString

func IPNetString(ipNet net.IPNet) (s string)

IPNetString is abbreviated form 0/0

func InvertMask

func InvertMask(IPMask net.IPMask) (out net.IPMask)

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

func IsBroadcast(IP net.IP, IPMask net.IPMask) (isBroadcast bool)

IsBroadcast determines IP is the last address for Mask for 1.2.3.4/24 the network address 1.2.3.255 returns true

func IsDirect

func IsDirect(IP net.IP, mask *net.IPMask) bool

IsDirect determines if the route is direct

func IsDirectIPNet

func IsDirectIPNet(IPNet *net.IPNet) bool

IsDirectIPNet determines if the IPNET represents a direct route

func IsIPv4

func IsIPv4(ip net.IP) (isIPv4 bool)

IsIPv4 determines if net.IP value is IPv4

func IsIPv6

func IsIPv6(ip net.IP) (isIPv6 bool)

IsIPv6 determines if net.IP value is IPv6

func IsNetwork

func IsNetwork(IP net.IP, IPMask net.IPMask) (isNetwork bool)

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 IsNzIP

func IsNzIP(ip net.IP) bool

IsNzIP is ip set and not zero

func IsZeros

func IsZeros(p net.IP) bool

IsZeros determines if every byte of the IP address is zero

func NewTLSConfig

func NewTLSConfig(cert *x509.Certificate) (tlsConfig *tls.Config)

func NewTransport

func NewTransport(tlsConfig *tls.Config) (httpTransport *http.Transport)

Types

type Callback

type Callback func(msg Message)

Callback allows for processing of routing message,eg. populating a map

type Destination

type Destination struct {
	net.IPAddr
	net.IPMask
}

Destination contains IP, Zone and Mask

func NewDestination

func NewDestination(IPAddr *net.IPAddr, IPMask *net.IPMask) (d *Destination)

NewDestination instantiates Destination

func (Destination) Key

func (d Destination) Key() string

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 NewHttp

func NewHttp(host, network string) (hp *Http)

NewHttp creates http server host is host:port, default ":http"

func (*Http) CloseErr

func (hp *Http) CloseErr()

func (*Http) HandleFunc

func (hp *Http) HandleFunc(pattern string, handler HandlerFunc)

func (*Http) Listen

func (hp *Http) Listen() (errCh <-chan error)

func (*Http) Listener

func (hp *Http) Listener() (listener net.Listener, err error)

func (*Http) SendErr

func (hp *Http) SendErr(err error)

func (*Http) Shutdown

func (hp *Http) Shutdown()

func (*Http) SubListen

func (hp *Http) SubListen() (errCh <-chan error)

func (*Http) WaitForUp

func (hp *Http) WaitForUp() (isUp bool, addr net.Addr)

type HttpClient

type HttpClient struct {
	http.Client
}

func NewHttpClient

func NewHttpClient(tlsConfig *tls.Config) (httpClient *HttpClient)

func (*HttpClient) Get

func (ct *HttpClient) Get(requestURL string, ctx context.Context) (resp *http.Response, err error)

type Https

type Https struct {
	Http
	Cert    parlca.CertificateDER
	Private crypto.Signer
}

func NewHttps

func NewHttps(host, network string, certDER parlca.CertificateDER, signer crypto.Signer) (hp *Https)

func (*Https) Listen

func (hp *Https) Listen() (errCh <-chan error)

func (*Https) TLS

func (hp *Https) TLS() (tlsListener net.Listener, err error)

type IfIndex

type IfIndex int

IfIndex is a dynamic reference to a network interface on Linux systems

func (IfIndex) Interface

func (ifIndex IfIndex) Interface() (*net.Interface, error)

Interface gets net.Interface for ifIndex

func (IfIndex) Present

func (ifIndex IfIndex) Present() bool

Present determines if intreface index is set

func (IfIndex) Zone

func (ifIndex IfIndex) Zone() (zone string, err error)

Zone gets net.IPAddr.Zone string for ifIndex

type LinkAddr

type LinkAddr struct {
	Index IfIndex          // 0 is none
	Name  string           // "" none
	Hw    net.HardwareAddr // []byte
}

LinkAddr contains an Ethernet mac address, its interface name and interface index

func NewLinkAddr

func NewLinkAddr(index IfIndex) *LinkAddr

NewLinkAddr instantiates LinkAddr

func NewLinkAddr2

func NewLinkAddr2(index IfIndex, name string, hw net.HardwareAddr) *LinkAddr

NewLinkAddr2 instantiates LinkAddr

func (*LinkAddr) OneString

func (a *LinkAddr) OneString() string

OneString picks the most meaningful value

func (LinkAddr) String

func (a LinkAddr) String() string

func (*LinkAddr) UpdateName

func (a *LinkAddr) UpdateName() (err error)

UpdateName attempts to populate interface name if not already present

func (*LinkAddr) ZoneID

func (a *LinkAddr) ZoneID() string

ZoneID is the IPv6 ZoneID for this interface

type Message

type Message interface {
	fmt.Stringer
}

Message is a portable routing message emitted by netlink socket

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 net.IPAddr
	LinkAddr
	Src net.IPAddr // the source ip to use on LinkAddr
}

NextHop describes a route target

func EmptyNextHop

func EmptyNextHop() *NextHop

EmptyNextHop provides empty NextHop

func NewNextHop

func NewNextHop(gateway *net.IPAddr, linkAddr *LinkAddr, src *net.IPAddr) *NextHop

NewNextHop assembles a route destination

func NewNextHop2

func NewNextHop2(index IfIndex, gateway *net.IPAddr, src *net.IPAddr) (next *NextHop, err error)

NewNextHop2 assembles a route destination based on IfIndex

func (*NextHop) HasGateway

func (nh *NextHop) HasGateway() bool

HasGateway determines if next hop uses a remote gateway

func (*NextHop) HasSrc

func (nh *NextHop) HasSrc() bool

HasSrc determines if next hop has src specified

func (NextHop) String

func (nh NextHop) String() (s string)

func (*NextHop) Target

func (nh *NextHop) Target() (gateway *net.IPAddr, s string)

Target describes the detination for this next hop

type Route

type Route struct {
	Destination
	NextHop
}

Route describes a routing table route with destination and next hop

func NewRoute

func NewRoute(d *Destination, nextHop *NextHop) *Route

NewRoute instantiates Route

type Socket

type Socket struct {
	*net.TCPListener
	// contains filtered or unexported fields
}

Socket embeds net.TCPListener

func ListenTCP4

func ListenTCP4(socketString string) (socket *Socket, err error)

ListenTCP4 listens on local network interfaces with ipv4 tcp socket: ":8080" or "1.2.3.4:80"

func (*Socket) RunHandler

func (s *Socket) RunHandler(handler func(net.Conn)) (errCh <-chan error)

RunHandler handles inbound connections

func (*Socket) Wait

func (s *Socket) Wait()

Wait waits for all connections and the handler thread to exit. ListenTCP4.Close needs to be invoked

type Tcp

type Tcp struct {
	net.Addr // interface
	http.ServeMux
	http.Server
	// contains filtered or unexported fields
}

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
}

func NewUDP

func NewUDP(network, address string, udpFunc UDPFunc, maxSize int) (udp *UDP)

NewUDP network: "udp" "udp4" "udp6" address: "host:port"

func (*UDP) Listen

func (udp *UDP) Listen() (errCh <-chan error)

func (*UDP) Shutdown

func (udp *UDP) Shutdown()

func (*UDP) WaitForUp

func (udp *UDP) WaitForUp() (isUp bool, addr net.Addr)

type UDPFunc

type UDPFunc func(b []byte, oob []byte, flags int, addr *net.UDPAddr)

Jump to

Keyboard shortcuts

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