AdGuardHome/internal/aghnet/addr.go
Ainar Garipov bfc7e16d84 Pull request: dhcpd: do not assume mac addrs of 6 bytes
Closes #2828.

Squashed commit of the following:

commit 26c6cf81c32469e1c4955aafb40490c29b4d1a99
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Mar 30 17:43:53 2021 +0300

    dhcpd: do not assume mac addrs of 6 bytes
2021-03-31 12:36:57 +03:00

24 lines
523 B
Go

package aghnet
import (
"fmt"
"net"
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
)
// ValidateHardwareAddress returns an error if hwa is not a valid EUI-48,
// EUI-64, or 20-octet InfiniBand link-layer address.
func ValidateHardwareAddress(hwa net.HardwareAddr) (err error) {
defer agherr.Annotate("validating hardware address %q: %w", &err, hwa)
switch l := len(hwa); l {
case 0:
return agherr.Error("address is empty")
case 6, 8, 20:
return nil
default:
return fmt.Errorf("bad len: %d", l)
}
}