Documentation
¶
Index ¶
Constants ¶
const EthHdrLen = 14
Untagged ethernet (IEEE 802.3) frame header len
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MAC ¶
type MAC [6]byte
MAC is an IEEE 802 MAC-48 address.
It is a comparable value type: two MACs may be compared with == and a MAC may be used as a map key. Its zero value means "unset", which is how a device carrying no layer 2 address, such as an L3/NOARP device, is represented.
MAC can also be used in CRD-embedded structs. It is serialized as a string and validated by the API server on admission.
+kubebuilder:validation:Type=string +kubebuilder:validation:Format=mac
func FromHardwareAddr ¶
func FromHardwareAddr(ha net.HardwareAddr) (MAC, error)
FromHardwareAddr converts ha to a MAC. Like ParseMAC it only accepts an IEEE 802 MAC-48 address, so a device carrying no layer 2 address, such as an L3/NOARP device, yields an error rather than an unset MAC.
Prefer this over a plain MAC(ha) conversion, which panics at run time on a net.HardwareAddr shorter than 6 bytes.
func GenerateRandMAC ¶ added in v0.15.7
GenerateRandMAC generates a random unicast and locally administered MAC address.
func MustParseMAC ¶ added in v1.19.0
MustParseMAC calls ParseMAC and panics on error. It is intended for use in tests with hard-coded strings.
func ParseMACOrUnset ¶
ParseMACOrUnset is ParseMAC with the empty string parsed as an unset MAC rather than as an error, matching MAC.UnmarshalText.
It is meant for the sources which report a MAC address optionally, such as the cloud provider interface and statuses in a CiliumNode: an absent value is legitimate there, and only a malformed one is rejected. Consumers which do require a MAC must reject the unset one themselves.
func (MAC) HardwareAddr ¶
func (m MAC) HardwareAddr() net.HardwareAddr
HardwareAddr returns m as a net.HardwareAddr, or nil if m is unset. The result is a copy and does not alias m.
Unset must map to nil rather than to six zero bytes: consumers such as netlink treat a nil net.HardwareAddr as "no address requested" and a non-nil one as an explicit address to set, which the kernel rejects for devices that carry no layer 2 address.
func (MAC) IsValid ¶
IsValid reports whether m is set. Devices without a layer 2 address, such as L3/NOARP devices, carry an invalid MAC.
func (MAC) MarshalText ¶ added in v1.20.0
MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as the one returned by MAC.String.
func (MAC) String ¶
String returns the string representation of m, or the empty string if m is unset.
func (*MAC) UnmarshalText ¶ added in v1.20.0
UnmarshalText implements the encoding.TextUnmarshaler interface.