package netutils

import "github.com/docker/docker/libnetwork/netutils"

Package netutils provides network utility functions.

Index

Functions

func GenerateIfaceName

func GenerateIfaceName(nlh nlwrap.Handle, prefix string, len int) (string, error)

GenerateIfaceName returns an interface name using the passed in prefix and the length of random bytes. The api ensures that the there is no interface which exists with that name.

func GenerateMACFromIP

func GenerateMACFromIP(ip net.IP) net.HardwareAddr

GenerateMACFromIP returns a locally administered MAC address where the 4 least significant bytes are derived from the IPv4 address.

func GenerateRandomMAC

func GenerateRandomMAC() net.HardwareAddr

GenerateRandomMAC returns a new 6-byte(48-bit) hardware address (MAC) that is not multicast and has the local assignment bit set.

func GenerateRandomName

func GenerateRandomName(prefix string, length int) (string, error)

GenerateRandomName returns a string of the specified length, created by joining the prefix to random hex characters. The length must be strictly larger than len(prefix), or an error will be returned.

func InferReservedNetworks

func InferReservedNetworks(v6 bool) []netip.Prefix

InferReservedNetworks returns a list of network prefixes that seem to be used by the system and that would likely break it if they were assigned to some Docker networks. It uses two heuristics to build that list:

1. Nameservers configured in /etc/resolv.conf ; 2. On-link routes ;

That 2nd heuristic was originally not limited to on-links -- all non-default routes were checked (see 1). This proved to be not ideal at best and highly problematic at worst:

The 2nd heuristic was modified to be limited to on-link routes in PR #42598 (first released in v23.0, see 3).

If these heuristics don't detect an overlap, users should change their daemon config to remove that overlapping prefix from `default-address-pools`. If a prefix is found to overlap but users care enough about it being associated to a Docker network they can still rely on static allocation.

For IPv6, the 2nd heuristic isn't applied as there's no such thing as on-link routes for IPv6.

func IsV6Listenable

func IsV6Listenable() bool

IsV6Listenable returns true when `[::1]:0` is listenable. IsV6Listenable returns false mostly when the kernel was booted with `ipv6.disable=1` option.

func MustParseMAC

func MustParseMAC(s string) net.HardwareAddr

MustParseMAC returns a net.HardwareAddr or panic.

func ReverseIP

func ReverseIP(IP string) string

ReverseIP accepts a V4 or V6 IP string in the canonical form and returns a reversed IP in the dotted decimal form . This is used to setup the IP to service name mapping in the optimal way for the DNS PTR queries.

Source Files

utils.go utils_linux.go

Version
v28.0.1+incompatible
Published
Feb 26, 2025
Platform
linux/amd64
Imports
19 packages
Last checked
34 minutes ago

Tools for package owners.