mirror of
https://github.com/vishvananda/netlink
synced 2025-01-25 08:54:08 +00:00
Parse the IFLA_OPERSTATE flag and recort in the link attributes. (#180)
The operstate gives the best picture of whether the interface is really up.
This commit is contained in:
parent
266f02d3a8
commit
7a823e360e
34
link.go
34
link.go
@ -36,6 +36,40 @@ type LinkAttrs struct {
|
|||||||
Xdp *LinkXdp
|
Xdp *LinkXdp
|
||||||
EncapType string
|
EncapType string
|
||||||
Protinfo *Protinfo
|
Protinfo *Protinfo
|
||||||
|
OperState LinkOperState
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkOperState represents the values of the IFLA_OPERSTATE link
|
||||||
|
// attribute, which contains the RFC2863 state of the interface.
|
||||||
|
type LinkOperState uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
OperUnknown = iota // Status can't be determined.
|
||||||
|
OperNotPresent // Some component is missing.
|
||||||
|
OperDown // Down.
|
||||||
|
OperLowerLayerDown // Down due to state of lower layer.
|
||||||
|
OperTesting // In some test mode.
|
||||||
|
OperDormant // Not up but pending an external event.
|
||||||
|
OperUp // Up, ready to send packets.
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s LinkOperState) String() string {
|
||||||
|
switch s {
|
||||||
|
case OperNotPresent:
|
||||||
|
return "not-present"
|
||||||
|
case OperDown:
|
||||||
|
return "down"
|
||||||
|
case OperLowerLayerDown:
|
||||||
|
return "lower-layer-down"
|
||||||
|
case OperTesting:
|
||||||
|
return "testing"
|
||||||
|
case OperDormant:
|
||||||
|
return "dormant"
|
||||||
|
case OperUp:
|
||||||
|
return "up"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLinkAttrs returns LinkAttrs structure filled with default values
|
// NewLinkAttrs returns LinkAttrs structure filled with default values
|
||||||
|
@ -1083,6 +1083,8 @@ func LinkDeserialize(hdr *syscall.NlMsghdr, m []byte) (Link, error) {
|
|||||||
}
|
}
|
||||||
base.Protinfo = parseProtinfo(attrs)
|
base.Protinfo = parseProtinfo(attrs)
|
||||||
}
|
}
|
||||||
|
case syscall.IFLA_OPERSTATE:
|
||||||
|
base.OperState = LinkOperState(uint8(attr.Value[0]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Links that don't have IFLA_INFO_KIND are hardware devices
|
// Links that don't have IFLA_INFO_KIND are hardware devices
|
||||||
|
Loading…
Reference in New Issue
Block a user