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:
Shaun Crampton 2016-12-09 22:08:27 +00:00 committed by Vish Ishaya
parent 266f02d3a8
commit 7a823e360e
2 changed files with 36 additions and 0 deletions

34
link.go
View File

@ -36,6 +36,40 @@ type LinkAttrs struct {
Xdp *LinkXdp
EncapType string
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

View File

@ -1083,6 +1083,8 @@ func LinkDeserialize(hdr *syscall.NlMsghdr, m []byte) (Link, error) {
}
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