func ParseInterfaceType(sysPath, interfaceName string) LinkLayerDeviceType {
	const deviceType = "DEVTYPE="
	location := filepath.Join(sysPath, interfaceName, "uevent")

	data, err := ioutil.ReadFile(location)
	if err != nil {
		logger.Debugf("ignoring error reading %q: %v", location, err)
		return UnknownDevice
	}

	var devType string
	lines := strings.Fields(string(data))
	for _, line := range lines {
		if !strings.HasPrefix(line, deviceType) {
			continue
		}

		devType = strings.TrimPrefix(line, deviceType)
		switch devType {
		case "bridge":
			return BridgeDevice
		case "vlan":
			return VLAN8021QDevice
		case "bond":
			return BondDevice
		case "":
			// DEVTYPE is not present for some types, like Ethernet and loopback
			// interfaces, so if missing do not try to guess.
			break
		}
	}

	return UnknownDevice
}
// ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel
// userspace SYSFS location "<sysPath/<interfaceName>/uevent" and returns it as
// InterfaceType. SysClassNetPath should be passed as sysPath. Returns
// UnknownInterface if the type cannot be reliably determined for any reason.
// Example call: network.ParseInterfaceType(network.SysClassNetPath, "br-eth1")
// TODO (manadart 2021-02-12): As with SysClassNetPath above, specific
// implementations should be sought for this that are OS-dependent.
ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel
userspace SYSFS location "/uevent" and returns it as
InterfaceType. SysClassNetPath should be passed as sysPath. Returns
UnknownInterface if the type cannot be reliably determined for any reason.
Example call: network.ParseInterfaceType(network.SysClassNetPath, "br-eth1")
TODO (manadart 2021-02-12): As with SysClassNetPath above, specific
implementations should be sought for this that are OS-dependent.
// ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel // userspace SYSFS location " <sysPath / <interfaceName > / uevent " and returns it as // InterfaceType . SysClassNetPath should be passed as sysPath . Returns // UnknownInterface if the type cannot be reliably determined for any reason . // Example call : network . ParseInterfaceType ( network . SysClassNetPath " br - eth1 " ) // TODO ( manadart 2021 - 02 - 12 ) : As with SysClassNetPath above specific // implementations should be sought for this that are OS - dependent .
func ParseInterfaceType(sysPath, interfaceName string) LinkLayerDeviceType {
	const deviceType = "DEVTYPE="
	location := filepath.Join(sysPath, interfaceName, "uevent")
	data, err := ioutil.ReadFile(location)
	if err != nil {
		logger.Debugf("ignoring error reading %q: %v", location, err)
		return UnknownDevice
	}
	var devType string
	lines := strings.Fields(string(data))
	for _, line := range lines {
		if !strings.HasPrefix(line, deviceType) {
			continue
		}
		devType = strings.TrimPrefix(line, deviceType)
		switch devType {
		case "bridge":
			return BridgeDevice
		case "vlan":
			return VLAN8021QDevice
		case "bond":
			return BondDevice
		case "":
			break
		}
	}
	return UnknownDevice
}
func ParseInterfaceType ( sysPath , interfaceName string ) LinkLayerDeviceType { const deviceType = " " location := filepath . Join ( sysPath , interfaceName , " " ) data , err := ioutil . ReadFile ( location ) if err != nil { logger . Debugf ( " " , location , err ) return UnknownDevice } var devType string lines := strings . Fields ( string ( data ) ) for _ , line := range lines { if ! strings . HasPrefix ( line , deviceType ) { continue } devType = strings . TrimPrefix ( line , deviceType ) switch devType { case " " : return BridgeDevice case " " : return VLAN8021QDevice case " " : return BondDevice case " " : break } } return UnknownDevice }
ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel
userspace SYSFS location "/uevent" and returns it as
InterfaceType.
ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel userspace SYSFS location " / uevent " and returns it as InterfaceType .
// DEVTYPE is not present for some types, like Ethernet and loopback // interfaces, so if missing do not try to guess.