network

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package network defines Gostwire's virtual network configuration and topology model and implements the discovery.

Network configuration covers (not only) IP address and route configuration, but also “netstat on drugs”: discovery of open ports and then relating them not only to processes (as “netstat” and “showsocket” do; the latter has a condemnable short name without any understanding of history, really) but also to containers.

The topology model bases on conveniently post-processed RT netlink data, taking care of netlink glitches especially with interface indices in other network namespaces. The in-memory model allows for quick topology traversal using simple pointer dereferencing.

And finally, Gostwire is fully dual-stack IPv4/IPv6 aware.

Basics

In any case, any Gostwire discovery turns up a set of network namespaces, represented by type NetworkNamespace. Please note that network namespaces are flat and thus do not form any kind of hierarchy.

Each NetworkNamespace lists the network interfaces assigned to it, where the interfaces are represented by the aptly-named type Interface. NetworkNamespace also holds the IP routes (sic!) as well as open transport ports. Finally, a NetworkNamespace lists the “tenants” attached to this network stack. Here, a “tenant” is either a process at the top of a process sub-tree, still attached to this network stack, or the initial process of a container.

Depending on system configuration and process state, multiple tenants might be present. A most prominent example are the containers of a single Kubernetes pod sharing the same single network stack between themselves.

Only Interface provides information about the configured (or “assigned”) IP addresses. In contrast, routes, belong to a network stack and thus a NetworkNamespace, but not to any Interface.

Index

Constants

View Source
const (
	UDP_ESTABLISHED = TCP_ESTABLISHED // UDP socket is connected
	UDP_LISTEN      = TCP_CLOSE       // sic! arguably semantically not 100% correct...
)

UDP socket states are not defined explicitly, but instead the udp.c Linux kernel module reuses a few TCP socket states; for instance, see: https://elixir.bootlin.com/linux/v5.13.13/source/net/ipv4/udp.c#L786

View Source
const (
	Unconnected = SocketSimplifiedState(0)               // undefined state
	Connected   = SocketSimplifiedState(TCP_ESTABLISHED) // both TCP and UDP sockets
	Listening   = SocketSimplifiedState(TCP_LISTEN)      // both TCP and UDP sockets
)

Gostwire's simplified socket states; please note that the concept of "connected" versus "listen" really doesn't map well onto UDP socket. What Gostwire considers to be a "listening" UDP socket is any open UDP socket that isn't connected to a specific remote socket. Connecting a UDP socket here means that the remote peer address has been set and the network stack filters out (throws away) any UDP packets reaching the socket but originating from sources other than the set remote peer address.

View Source
const GostwireInternalBridgeKey = "gostwire/bridge/internal"

GostwireInternalBridgeKey specifies the label key indicating if a bridge belongs to a Docker network that has been configured as "internal". If present, it has an empty value.

View Source
const NSID_NONE = ^NSID(0)

NSID_NONE is the Linux' kernel telling us that there ain't no such peer network namespace.

Variables

This section is empty.

Functions

func Exploded

func Exploded(ip net.IP) string

Exploded returns the textural IP address representation with 0 padding and without any compression. For instance, "000.000.000.000" and "0000:0000:0000:0000:0000:0000:0000:0000". The exploded form is mainly of use when sorting IP addresses, as this avoids the need for (hex) number-aware sorting functions.

func ResolveForwardedPort

func ResolveForwardedPort(forwardedPort *ForwardedPort, netns *NetworkNamespace)

ResolveForwardedPort attempts to fill in the missing pieces of information for forwarded ports:

  • network namespace of (rewritten) destination IP,
  • network interface related to the (rewritten) destination IP,
  • the processes (and PIDs) with socket(s) willing to serve the forwarded port.

Types

type Address

type Address struct {
	Family            int    `json:"family"`
	Address           net.IP `json:"address"`
	PrefixLength      uint   `json:"prefixlen"`
	PreferredLifetime uint32 `json:"preferred-lifetime"`
	ValidLifetime     uint32 `json:"valid-lifetime"`
	Scope             int    `json:"scope"`
	Index             int    `json:"index"` // index of network interface the address is assigned to.
}

Address represents a network-layer address with associated information.

func (Address) Exploded

func (a Address) Exploded() string

Exploded returns the textural IP address representation with 0 padding and without any compression. For instance, "000.000.000.000" and "0000:0000:0000:0000:0000:0000:0000:0000". The exploded form is mainly of use when sorting IP addresses, as this avoids the need for (hex) number-aware sorting functions.

type AddressFamily

type AddressFamily int

AddressFamily represents an AF_ address family. Additionally, AdressFamily can be String-ified into the text strings "IPv4" or "IPv6".

func (AddressFamily) String

func (af AddressFamily) String() string

String returns either "IPv4" or "IPv6" for an AF_INET(6) address family.

type Addresses

type Addresses []Address

Addresses is an unordered list of Address elements.

func (Addresses) Sort

func (as Addresses) Sort()

Sort sorts a list of Addresses in-place. IPv4 addresses are always sorted before IPv6 addresses. IP addresses within the same family (v4 or v6) are sorted based on their Exploded form. An address with a shorter prefix length sort before the same address with a longer prefix length.

type Bridge

type Bridge interface {
	Interface
	Bridge() *BridgeAttrs // returns the bridge attributes.
}

Bridge represents a bridge network interface, and especially the bridge-port relationships.

type BridgeAttrs

type BridgeAttrs struct {
	NifAttrs
	Ports []Interface // "enslaved" network interfaces acting as bridge ports
}

BridgeAttrs represents the attributes of a bridge network interface.

func (*BridgeAttrs) Bridge

func (n *BridgeAttrs) Bridge() *BridgeAttrs

Bridge returns the bridge attributes.

func (*BridgeAttrs) Init

func (n *BridgeAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this Bridge Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*BridgeAttrs) Nif

func (n *BridgeAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*BridgeAttrs) ResolveRelations

func (n *BridgeAttrs) ResolveRelations(allns NetworkNamespaces)

ResolveRelations resolves relations to the enslaved "port" network interfaces. Please note that as only the ports of a bridge indicate their bridge, resolving these relations can only and mut be done in the generic resolution of the Nif base type.

type DnsConfiguration

type DnsConfiguration struct {
	Hostname      string            `json:"uts-hostname"` // nodename returned by uname(2) and usually used instead of the gethostname() syscall.
	EtcHostname   string            `json:"etc-hostname"` // host name read from /etc/hostname, if present.
	EtcDomainname string            `json:"domainname"`   // domain name read from /etc/domainname, if present.
	Hosts         map[string]net.IP `json:"etc-hosts"`    // (host)name to IP address mapping, as read from /etc/hosts.
	Nameservers   []net.IP          `json:"nameservers"`  // list of name server IP addresses.
	Searchlist    []string          `json:"searchlist"`   // list of domain names to use in resolving names to IP addresses.
}

DnsConfiguration contains DNS/name resolution-related configuration information.

type ForwardedPort

type ForwardedPort struct {
	portfinder.ForwardedPortRange                   // "general" port forwarding information incl. protocol, et cetera.
	Protocol                      Protocol          // transport-layer protocol, such as syscall.IPPROTO_TCP, etc.
	DestinationNetns              *NetworkNamespace // network namespace where the IP forwarded to is.
	PIDs                          []model.PIDType   // processes having a listening/open socket for the port forwarded to.
	Processes                     []*model.Process  // processes having a listening/open socket for the port forwarded to.
	Nifs                          Interfaces        // network interfaces the traffic is forwarded to.
}

ForwardedPort is Gostwire's view on forwarded ports (actually port ranges) inside a particular network namespace. The rewritten destinations the traffic should be forwarded to can be in other network namespaces, as long as packets can be properly forwarded to these new destinations.

Please note that under less-than-ideal circumstances we might end up with traffic to a host port getting forwarded into a particular network namespace (which we identify based on the network interfaces' configured IP addresses), yet there isn't any open socket handling the forwarded traffic. In this situation, only DestinationNetns will be set and PIDs/Processes are empty.

type IP

type IP net.IP

IP is a net.IP that returns its IPv6 address textual representation in square bracket notation "[textual-ipv6-address]". This is useful in "ip:port" output contexts, as it is common practise to then render IPv6 addresses as "[ipv6]:port" in order to be able to clearly see the port number, which otherwise could be mistaken for the final address group.

func (IP) String

func (a IP) String() string

String returns for IPv4 the IPv4 textual representation (for instance, "127.0.0.1") and for IPv6 the textual representation enclosed in square brackets, for instance: "[fe80::1]".

type Interface

type Interface interface {
	Nif() *NifAttrs       // returns the common network interface attributes.
	Interface() Interface // returns the NetworkInterface interface for this, erm, network interface.
}

Interface represents Gostwire's perspective on the common properties of a network interface inside a network namespace. For some (virtual) type of network interfaces, additional nif type-specific interfaces give more details, such as the Peer interface about the peer relations between the two VETH ends of an VETH "wire".

Due to the design of Go interfaces versus (pointer) receivers we have to deal with the ugly situation were in a (pointer) receiver method with a *NifAttrs receiver and we need the Interface instead to whatever "derived" type like VethAttrs is implementing it. The Interface() method is a convience to encapsulate our work-around that looks up the original Interface from the nif list of the owning NetworkNamespace.

func NewInterface

func NewInterface(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link) Interface

NewInterface returns a new network.Interface that is Gostwire's view take on network interfaces in network namespaces. The network interface returned has the correct underlying Go type (such as BridgeAttrs, VethAttrs, ...) based on the specific kind of link. If there is no dedicated Gostwire type, then the generic NifAttr type is created and returned instead.

type Interfaces

type Interfaces []Interface

Interfaces is a list of network Interface elements, and can optionally be sorted in-place.

func (Interfaces) OfKind

func (i Interfaces) OfKind(kind string) Interfaces

OfKind returns only the Interfaces of the specified kind.

func (Interfaces) Sort

func (i Interfaces) Sort()

Sort sorts the list of Interface elements in-place.

type Macvlan

type Macvlan interface {
	Interface
	Macvlan() *MacvlanAttrs // returns the macvlan attributes.
}

Macvlan represents a MACVLAN network interface with quite some gory configuration details and the relation to it "master" network interface (a "hardware") interface.

type MacvlanAttrs

type MacvlanAttrs struct {
	NifAttrs
	Master Interface // master (hardware) network interface
	Mode   MacvlanMode
}

MacvlanAttrs represents the attributes of a MACVLAN network interface.

func (*MacvlanAttrs) Init

func (n *MacvlanAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this MACVLAN Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*MacvlanAttrs) Macvlan

func (n *MacvlanAttrs) Macvlan() *MacvlanAttrs

Macvlan returns the macvlan attributes.

func (*MacvlanAttrs) Nif

func (n *MacvlanAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*MacvlanAttrs) ResolveRelations

func (n *MacvlanAttrs) ResolveRelations(allns NetworkNamespaces)

ResolveRelations resolves relations to the master network interface.

type MacvlanMode

type MacvlanMode netlink.MacvlanMode

MacvlanMode specifies the switching mode with respect to other MACVLANs and the rest of the world, excluding the master network interface though.

func (MacvlanMode) String

func (m MacvlanMode) String() string

String returns a short text for this MACVLAN (switching) mode.

type NSID

type NSID uint32

NSID is the Linux-kernel type for network "namespace IDs", which must not be confused with the general network identifiers (consisting of device ID and inode number). NSIDs are 32bit unsigned int identifiers associated with a peer network namespace and can be either set explicitly or implicitly by the kernel when needed. NSIDs are scoped to the network namespace they are defined in. NSIDs cannot be changed anymore after they have been assigned for the first time.

type NetworkNamespace

type NetworkNamespace struct {
	model.Namespace                       // discovered namespace details courtesy of lxkns.
	Nifs             map[int]Interface    // map of network interfaces by index number.
	NamedNifs        map[string]Interface // map of network interfaces indexed by name.
	Tenants          Tenants              // tenants of this network namespace (=processes/containers with additional information).
	Routesv4         []Route              // IPv4 routes
	Routesv6         []Route              // IPv6 routes
	Portsv4          []ProcessSocket      // sockets/open ports for IPv4 (including IPv6 sockets!)
	Portsv6          []ProcessSocket      // sockets/open ports for IPv6
	ForwardedPortsv4 []ForwardedPort      // IPv4 ports forwarded into other network namespaces
	ForwardedPortsv6 []ForwardedPort      // IPv6 ports forwarded into other network namespaces
	// contains filtered or unexported fields
}

NetworkNamespace represents a particular Linux network namespace together with its network interfaces, routes, open ports, et cetera. It additionally references the containers and non-container processes attached to this NetworkNamespace. Sets of containers (=initial process of container) as well as stand-alone (=non-container) processes are referred to as "tenants".

func NewNetworkNamespace

func NewNetworkNamespace(netns model.Namespace, tenantProcs []*model.Process) *NetworkNamespace

NewNetworkNamespace returns a new NetworkNamespace, based on the lxkns namespace discover information. The new NetworkNamespace will have its network interfaces and routes discovered. However, the relations between network interfaces remain unresolved at this time.

func (*NetworkNamespace) DisplayName

func (n *NetworkNamespace) DisplayName() string

DisplayName returns a "simplified" name for "simple" display use cases, where it is desirable to identify network namespaces by the names of their tenants (containers and stand-alone processes). In case of multiple tenants, the display name will be the lexicographically first tenant name, or the name of the process with PID 1, if present.

func (*NetworkNamespace) NifInBridgedNetwork

func (n *NetworkNamespace) NifInBridgedNetwork(bridge Interface, addr net.IP) Interface

NifInBridgeNetwork returns the network Interface with the specified IP address connected somehow to the specified bridge; otherwise, nil.

func (*NetworkNamespace) NifList

func (n *NetworkNamespace) NifList() Interfaces

NifList returns the (unordered) list of NetworkInterfaces in this network namespace.

func (*NetworkNamespace) NifWithAddress

func (n *NetworkNamespace) NifWithAddress(addr net.IP) Interface

NifWithAddress returns the network Interface in this network namespace that has the specified IP address assigned to it, or nil if none could be found.

func (*NetworkNamespace) NifsString

func (n *NetworkNamespace) NifsString() string

NifsString returns the display name of this network namespace together with the names of its network interface (and interface indices).

func (*NetworkNamespace) OpenEthtool

func (n *NetworkNamespace) OpenEthtool() (fd int, err error)

OpenEthtool open a socket in this network namespace that is suitable for ethtool-related ioctl's. Somewhat deviating from the standard Go error return pattern, it doesn't return a zero fd on error, but a -1 fd ... which is guaranteed to be an invalid fd, whereas 0 most probably is valid.

func (*NetworkNamespace) OpenInNetworkNamespace

func (n *NetworkNamespace) OpenInNetworkNamespace(opener func() error) error

OpenInNetworkNamespace calls the supplied opener function in the context of this network namespace.

func (n *NetworkNamespace) OpenNetlink() (*netlink.Handle, error)

OpenNetlink returns a netlink (route) handle for netlink queries and operations on this network namespace. The caller is responsible for releasing the resources associated with the returned netlink handle by calling Delete(!) on it when not needed anymore.

func (*NetworkNamespace) WhereIs

func (n *NetworkNamespace) WhereIs(destIP net.IP) (*NetworkNamespace, Interface)

WhereIs determines the network namespace the specified IP address is located in and at the same time reachable from the current network namespace. It returns the matching network namespace and network interface, or nil if nothing suitable was found.

type NetworkNamespaceList

type NetworkNamespaceList []*NetworkNamespace

NetworkNamespaceList contains NetworkNamespace elements, and optionally can be sorted in-place using its Sort method.

func (NetworkNamespaceList) Sort

func (n NetworkNamespaceList) Sort()

Sort (stably) sorts the list of NetworkNamespace elements in-place. Please note that the network namespace with the initial process PID 1 will always come first.

type NetworkNamespaces

type NetworkNamespaces map[species.NamespaceID]*NetworkNamespace

NetworkNamespaces maps all NetworkNamespace objects known to us.

func NewNetworkNamespaces

func NewNetworkNamespaces(
	allnetns model.NamespaceMap,
	allprocs model.ProcessTable,
	containers model.Containers,
) NetworkNamespaces

NewNetworkNamespaces takes a set of discovered network namespaces and creates the Gostwire-specific NetworkNamespace objects wrapping them and supplying network layer-related information not discovered by lxkns.

func (NetworkNamespaces) ByContainer

func (m NetworkNamespaces) ByContainer(cntr *model.Container) *NetworkNamespace

ByContainer looks up the NetworkNamespace for the given model.Container. If not found, returns nil.

func (NetworkNamespaces) ByProcess

func (m NetworkNamespaces) ByProcess(proc *model.Process) *NetworkNamespace

ByProcess looks up the NetworkNamespace for the given model.Process. If not found, returns nil.

func (NetworkNamespaces) Sorted

Sorted returns the (stable) sorted list of NetworkNamespace elements.

func (NetworkNamespaces) String

func (m NetworkNamespaces) String() string

String returns a textual representation of the network namespaces map consisting of the (sorted) network namespaces' display names.

type NifAttrs

type NifAttrs struct {
	Netns       *NetworkNamespace // network namespace this interface belongs to.
	Kind        string            // kind of interface.
	Name        string            // interface name.
	Alias       string            // alias name.
	Index       int               // interface index.
	State       OperState         // operational state.
	Physical    bool              // or more metaphorical: it has an associated driver.
	DriverInfo  NifDriverInfo     // ethtool-derived nif driver information.
	Promiscuous bool              // does snoop all traffic?
	Labels      model.Labels      // optional labels attached by Gostwire decorators.
	L2Addr      net.HardwareAddr  // data-link layer (aka "hardware") address.
	Addrsv4     Addresses         // assigned IPv4 network addresses.
	Addrsv6     Addresses         // assigned IPv6 network addresses.
	SRIOVRole   SRIOVRole         // ...when network interface is an SR-IOV PF or VF.

	// Relations with other network interfaces
	Bridge Interface  // when interface is a "port" of a bridge interface.
	Slaves Interfaces // MACVLANs, VXLANs, VFs, others (but not VETH peers).
	PF     Interface  // when interface is an SR-IOV VF.

	// Low-level, not available after unmarshalling.
	Link netlink.Link // low-level netlink information about this interface.
}

NifAttrs defines Gostwire's view on the common attributes of any network interface. This also includes some relations between network interfaces.

func (*NifAttrs) AddLabels

func (n *NifAttrs) AddLabels(labels model.Labels)

AddLabels adds in (merges) the passed labels with the existing labels assigned to this network interface. Added labels take precedence over existing labels, replacing them in case of conflict.

func (*NifAttrs) HasAddress

func (n *NifAttrs) HasAddress(ip net.IP) bool

HasAddress returns true if the specified IP address is one of the addresses assigned to this interface, else false. The specified address is expected to be in canonical format, that is of length 4 for an IPv4 address (and being an IPv4-mapped IPv6 address).

func (*NifAttrs) Init

func (n *NifAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*NifAttrs) Interface

func (n *NifAttrs) Interface() Interface

Interface returns the network.Interface for this network.Interface (sic!). This is specific to Go, due to the Go design with its interfaces versus (pointer) receivers.

func (*NifAttrs) Nif

func (n *NifAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*NifAttrs) ResolveRelations

func (n *NifAttrs) ResolveRelations(allns NetworkNamespaces)

ResolveRelations resolves relations to other network interfaces. Please note that this doesn't include the PF-VF topology, as we're to resolve that topology separately.

func (*NifAttrs) SysfsBusPath

func (n *NifAttrs) SysfsBusPath() string

SysfsBusPath returns a device directory path for the physical device of this network interface somewhere deeper inside /sys/bus/.

Note: this is currently needed only for PCI(e) devices and thus does not work correctly for other busses, such as USB.

type NifDriverInfo added in v2.2.0

type NifDriverInfo struct {
	Driver      string `json:"driver"`                // Driver short name, cannot be empty, except that it can.
	Version     string `json:"version,omitempty"`     // Driver version string, but can be empty.
	FwVersion   string `json:"fwversion,omitempty"`   // Driver-specific firmware version string, can be empty, except that it might show "N/A" instead.
	BusInfo     string `json:"businfo,omitempty"`     // Device bus address, but may be empty.
	EromVersion string `json:"eromversion,omitempty"` // Driver-specific expansion ROM version string, can be empty.
}

NifDriverInfo contains some of the general driver and device information returned by the ethtool API.

The Driver name is empty in case of severl kinds of virtual devices. However, we've seen “taptun” kinds in the wild that are actually (pseudo) “HW” virtual devices that otherwise act like the Linux kernel's “taptun”'s, such as in WSL2 configurations, where they wire up the Linux VM with its Windows host.

The fields mirror some, but not all, of the ethtoo_drvinfo fields, see also: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/ethtool.h#L185

type NifMaker

type NifMaker func() Interface

NifMaker returns an instance of something implementing network.Interface.

type OperState

type OperState uint8

OperState indicates the operational state of a network interface.

const (
	Unknown        OperState = iota // operational state hasn't been specified by driver or userspace.
	NotPresent                      // unused in Linux kernel.
	Down                            // interface is unable to transfer data on "physical" level.
	LowerLayerDown                  // an interface onto which this interface is stacked is in Down state.
	Testing                         // unused in Linux kernel.
	Dormant                         // physical layer is up, but waiting for external event (Godot?).
	Up                              // interface is operational up and can be used.
)

Operational states of network interfaces. See also: https://www.kernel.org/doc/Documentation/networking/operstates.txt

func (OperState) Name

func (s OperState) Name() string

Name returns the name of the operational state (in CAPITALS).

func (OperState) TerminalIcon

func (s OperState) TerminalIcon() string

TerminalIcon returns a Unicode "icon" for the given operational state.

type ProcessSocket

type ProcessSocket struct {
	Family          AddressFamily         // address family, such as unix.AD_INET6, ...
	Protocol        Protocol              // transport protocol, such as syscall.IPPROTO_TCP, ...
	LocalIP         net.IP                // local IP address; IPv4 addresses are in .To4() format.
	LocalPort       uint16                // local TCP/UDP port
	RemoteIP        net.IP                // remote IP address; IPv4 addresses are in .To4() format.
	RemotePort      uint16                // remote TCP/UDP port
	State           SocketState           // (detailed) socket state
	SimplifiedState SocketSimplifiedState // simplified state: either listening or connected (both TCP and UDP)
	PIDs            []model.PIDType       // processes using this socket
	Processes       []*model.Process      // processes using this socket
	IPv4Mapped      bool                  // IPv6 socket handling IPv4 traffic?
	Nifs            Interfaces            // network interfaces handling this traffic, based on address/routing data.
}

ProcessSocket describes the communication parameters of a network socket and which process is using it. Please note that the same socket can be used by multiple processes by sharing its file descriptor.

type ProcessSockets

type ProcessSockets []ProcessSocket

ProcessSockets is a list of ProcessSocket elements, that optionally can be sorted in-place.

func (ProcessSockets) Sort

func (p ProcessSockets) Sort()

Sort sorts a list of ProcessSocket elements: - local port, - transport protocol, - (reverse) connection state -- to show listening ports before connected ports, - IPv4 before IPv6, - local address, - remote address, - remote port.

type Protocol

type Protocol int

Protocol represents a (transport) protocol number for TCP or UDP. Additionally, Protocol can be String-ified into the text strings "TCP" and "UDP".

func (Protocol) String

func (p Protocol) String() string

String returns either "TCP" or "UDP" for the given protocol number.

type Route

type Route struct {
	Family               AddressFamily
	Type                 RouteType
	Destination          net.IPNet
	DestinationPrefixLen int
	NextHop              net.IP
	Index                int
	Nif                  Interface
	Table                int
	Priority             int
	Preference           uint8 // TODO: support from vishvananda/netlink missing
}

Route is Gostwire's view on network stack routes.

type RouteType

type RouteType uint8

RouteType represents the type of route and allows converting it to a string, such as "unicast", "local", et cetera; this mimics pyroute2's behavior.

func (RouteType) String

func (r RouteType) String() string

String returns the string representation of a route type value in form of a lower-case identifier derived from the RTN_* constant identifiers, with the RTN_ prefix removed. For instance, "unicast", "local", et cetera.

type SRIOVRole

type SRIOVRole uint8

SRIOVRole identifies network interfaces that are SR-IOV PFs or VFs.

const (
	PCI_NIC      SRIOVRole = iota // Not a PCI NIC or SR-IOV isn't enabled.
	PCI_SRIOV_PF                  // network interface is a PCI PF.
	PCI_SRIOV_VF                  // network interface is a PCI VF.
)

type SocketSimplifiedState

type SocketSimplifiedState uint8

SocketSimplifiedState indicates whether a TCP or UDP socket is listening or connected, and nothing else; this hides all the gory details of SocketState.

func (SocketSimplifiedState) String

func (s SocketSimplifiedState) String() string

String returns a clear-text socket simplified status message.

type SocketState

type SocketState uint8

SocketState is a TCP's or UDP's socket state, such as listening, connected ("established"), et cetera.

const (
	TCP_ESTABLISHED SocketState = iota + 1
	TCP_SYN_SENT
	TCP_SYN_RECV
	TCP_FIN_WAIT1
	TCP_FIN_WAIT2
	TCP_TIME_WAIT
	TCP_CLOSE
	TCP_CLOSE_WAIT
	TCP_LAST_ACK
	TCP_LISTEN
	TCP_CLOSING
	TCP_NEW_SYN_RECV
)

TCP socket state codes are defined in https://elixir.bootlin.com/linux/v5.13.13/source/include/net/tcp_states.h

func (SocketState) String

func (s SocketState) String() string

String returns a clear-text socket status message.

type Tenant

type Tenant struct {
	Process      *model.Process   // associated ealdorman process
	BoundingCaps []byte           // bounding capabilities in form of a byte string with lsb being bit 0 of the last byte.
	DNS          DnsConfiguration // DNS and name resolution configuration
}

Tenant represents a process or even a container together with its application-layer specific communication configuration, namely configuration of the name resolution/DNS.

func NewTenant

func NewTenant(proc *model.Process) *Tenant

NewTenant returns a new Tenant corresponding with the specified process (and its optional container) and with its DNS configuration discovered.

func (*Tenant) Name

func (t *Tenant) Name() string

Name returns the tenant's name, which can be either its container name, falling back to its process name (with PID), if there's no associated container.

type Tenants

type Tenants []*Tenant

Tenants is a list of Tenant elements; it allows for in-place sorting using its Sort method.

func (Tenants) Sort

func (t Tenants) Sort()

Sort the list of tenants by their names and in place. However, the init(1) process with PID 1 always comes first.

type TunTap added in v2.1.9

type TunTap interface {
	Interface
	TunTap() *TunTapAttrs // returns the TUN/TAP attributes
}

type TunTapAttrs added in v2.1.9

type TunTapAttrs struct {
	NifAttrs
	Mode       TunTapMode
	Processors []*model.Process
}

TunTapAttrs represents the attributes of a TUN/TAP network interface.

func (*TunTapAttrs) Init added in v2.1.9

func (n *TunTapAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this TUN/TAP Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*TunTapAttrs) Nif added in v2.1.9

func (n *TunTapAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*TunTapAttrs) TunTap added in v2.1.9

func (n *TunTapAttrs) TunTap() *TunTapAttrs

TunTap returns the TAP/TUN attributes.

type TunTapMode added in v2.1.9

type TunTapMode int

type Veth

type Veth interface {
	Interface
	Veth() *VethAttrs // returns the veth attributes.
}

Veth represents an VETH network interface, and especially the peer-to-peer relationships between exactly two Veths. However, beware that since network discovery will never be an atomic operation, be prepared to trip upon an Veth without a peer (nil peer).

type VethAttrs

type VethAttrs struct {
	NifAttrs
	Peer Interface // other end of the VETH "wire"
}

VethAttrs represents the attributes of an VETH peer-to-peer network interface (one end of the pair).

func (*VethAttrs) Init

func (n *VethAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this VETH Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*VethAttrs) Nif

func (n *VethAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*VethAttrs) ResolveRelations

func (n *VethAttrs) ResolveRelations(allns NetworkNamespaces)

ResolveRelations resolves relations to the other peer network interface.

func (*VethAttrs) Veth

func (n *VethAttrs) Veth() *VethAttrs

Veth returns the veth attributes.

type Vlan

type Vlan interface {
	Interface
	Vlan() *VlanAttrs // returns the VLAN attributes.
}

Vlan represents a VLAN network interface that in turn represents a specific IEEE 802.1Q VLAN ID.

type VlanAttrs

type VlanAttrs struct {
	NifAttrs
	Master       Interface // master network interface
	VID          uint16    // VLAN ID 1..4094
	VlanProtocol netlink.VlanProtocol
}

VlanAttrs represents the attributes of a VLAN network interface.

func (*VlanAttrs) Init

func (n *VlanAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this VLAN Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*VlanAttrs) Nif

func (n *VlanAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*VlanAttrs) ResolveRelations

func (n *VlanAttrs) ResolveRelations(allns NetworkNamespaces)

ResolveRelations resolves relations to the master (underlay) network interface.

func (*VlanAttrs) Vlan

func (n *VlanAttrs) Vlan() *VlanAttrs

Vlan returns the VLAN attributes.

type Vxlan

type Vxlan interface {
	Interface
	Vxlan() *VxlanAttrs // returns the vxlan attributes.
}

Vxlan represents a VXLAN overlay network interface with quite some gory configuration details and the relation to it "master" network interface.

type VxlanAttrs

type VxlanAttrs struct {
	NifAttrs
	Master          Interface // master network interface
	VID             uint32    // VXLAN ID
	Groupv4         net.IP
	Groupv6         net.IP
	Sourcev4        net.IP
	Sourcev6        net.IP
	DestinationPort uint16
	SourcePortLow   uint16
	SourcePortHigh  uint16
	TTL             uint8
	TOS             uint8
	ArpProxy        bool
}

VxlanAttrs represents the attributes of a VXLAN network interface.

func (*VxlanAttrs) Init

func (n *VxlanAttrs) Init(nlh *netlink.Handle, netns *NetworkNamespace, link netlink.Link)

Init initializes this VXLAN Nif from information specified in the NetworkNamespace and lots of netlink.Link information.

func (*VxlanAttrs) Nif

func (n *VxlanAttrs) Nif() *NifAttrs

Nif returns the common network interface attributes.

func (*VxlanAttrs) ResolveRelations

func (n *VxlanAttrs) ResolveRelations(allns NetworkNamespaces)

ResolveRelations resolves relations to the master (underlay) network interface.

func (*VxlanAttrs) Vxlan

func (n *VxlanAttrs) Vxlan() *VxlanAttrs

Vxlan returns the macvlan attributes.

Directories

Path Synopsis
Package portfwd defines a plugin interface for detecting forwarded ports from nftables.
Package portfwd defines a plugin interface for detecting forwarded ports from nftables.
all
Package all pulls in all Gostwire port forwarding detectors (plugins).
Package all pulls in all Gostwire port forwarding detectors (plugins).
docker
Package docker implements port forwarding detection for iptables (nft) rules managed by the Docker daemon.
Package docker implements port forwarding detection for iptables (nft) rules managed by the Docker daemon.
kubeproxy
Package kubeproxy implements port forwarding detection for iptables (nft) rules managed by Kubernete's kube-proxy.
Package kubeproxy implements port forwarding detection for iptables (nft) rules managed by Kubernete's kube-proxy.
nftget
Package nftget help with conveniently retrieving information from nftable expressions.
Package nftget help with conveniently retrieving information from nftable expressions.

Jump to

Keyboard shortcuts

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