Bump all vendoring (#1612)
Update all vendoring to current releases. Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
14df2a1a1a
commit
1567cefdae
511 changed files with 98653 additions and 38115 deletions
219
vendor/github.com/mdlayher/netlink/attribute.go
generated
vendored
219
vendor/github.com/mdlayher/netlink/attribute.go
generated
vendored
|
|
@ -17,7 +17,9 @@ type Attribute struct {
|
|||
// Length of an Attribute, including this field and Type.
|
||||
Length uint16
|
||||
|
||||
// The type of this Attribute, typically matched to a constant.
|
||||
// The type of this Attribute, typically matched to a constant. Note that
|
||||
// flags such as Nested and NetByteOrder must be handled manually when
|
||||
// working with Attribute structures directly.
|
||||
Type uint16
|
||||
|
||||
// An arbitrary payload which is specified by Type.
|
||||
|
|
@ -70,6 +72,9 @@ func (a *Attribute) unmarshal(b []byte) error {
|
|||
// MarshalAttributes packs a slice of Attributes into a single byte slice.
|
||||
// In most cases, the Length field of each Attribute should be set to 0, so it
|
||||
// can be calculated and populated automatically for each Attribute.
|
||||
//
|
||||
// It is recommend to use the AttributeEncoder type where possible instead of
|
||||
// calling MarshalAttributes and using package nlenc functions directly.
|
||||
func MarshalAttributes(attrs []Attribute) ([]byte, error) {
|
||||
// Count how many bytes we should allocate to store each attribute's contents.
|
||||
var c int
|
||||
|
|
@ -102,26 +107,26 @@ func MarshalAttributes(attrs []Attribute) ([]byte, error) {
|
|||
// It is recommend to use the AttributeDecoder type where possible instead of calling
|
||||
// UnmarshalAttributes and using package nlenc functions directly.
|
||||
func UnmarshalAttributes(b []byte) ([]Attribute, error) {
|
||||
var attrs []Attribute
|
||||
var i int
|
||||
for {
|
||||
if i > len(b) || len(b[i:]) == 0 {
|
||||
break
|
||||
ad, err := NewAttributeDecoder(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Return a nil slice when there are no attributes to decode.
|
||||
if ad.Len() == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
attrs := make([]Attribute, 0, ad.Len())
|
||||
|
||||
for ad.Next() {
|
||||
if ad.attr().Length != 0 {
|
||||
attrs = append(attrs, ad.attr())
|
||||
}
|
||||
}
|
||||
|
||||
var a Attribute
|
||||
if err := (&a).unmarshal(b[i:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if a.Length == 0 {
|
||||
i += nlaHeaderLen
|
||||
continue
|
||||
}
|
||||
|
||||
i += nlaAlign(int(a.Length))
|
||||
|
||||
attrs = append(attrs, a)
|
||||
if err := ad.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return attrs, nil
|
||||
|
|
@ -143,10 +148,14 @@ type AttributeDecoder struct {
|
|||
// If not set, the native byte order will be used.
|
||||
ByteOrder binary.ByteOrder
|
||||
|
||||
// The attributes being worked on, and the iterator index into the slice of
|
||||
// attributes.
|
||||
attrs []Attribute
|
||||
i int
|
||||
// The current attribute being worked on.
|
||||
a Attribute
|
||||
|
||||
// The slice of input bytes and its iterator index.
|
||||
b []byte
|
||||
i int
|
||||
|
||||
length int
|
||||
|
||||
// Any error encountered while decoding attributes.
|
||||
err error
|
||||
|
|
@ -155,17 +164,20 @@ type AttributeDecoder struct {
|
|||
// NewAttributeDecoder creates an AttributeDecoder that unpacks Attributes
|
||||
// from b and prepares the decoder for iteration.
|
||||
func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
|
||||
attrs, err := UnmarshalAttributes(b)
|
||||
ad := &AttributeDecoder{
|
||||
// By default, use native byte order.
|
||||
ByteOrder: nlenc.NativeEndian(),
|
||||
|
||||
b: b,
|
||||
}
|
||||
|
||||
var err error
|
||||
ad.length, err = ad.available()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &AttributeDecoder{
|
||||
// By default, use native byte order.
|
||||
ByteOrder: nlenc.NativeEndian(),
|
||||
|
||||
attrs: attrs,
|
||||
}, nil
|
||||
return ad, nil
|
||||
}
|
||||
|
||||
// Next advances the decoder to the next netlink attribute. It returns false
|
||||
|
|
@ -176,26 +188,92 @@ func (ad *AttributeDecoder) Next() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
ad.i++
|
||||
// Exit if array pointer is at or beyond the end of the slice.
|
||||
if ad.i >= len(ad.b) {
|
||||
return false
|
||||
}
|
||||
|
||||
// More attributes?
|
||||
return len(ad.attrs) >= ad.i
|
||||
if err := ad.a.unmarshal(ad.b[ad.i:]); err != nil {
|
||||
ad.err = err
|
||||
return false
|
||||
}
|
||||
|
||||
// Advance the pointer by at least one header's length.
|
||||
if int(ad.a.Length) < nlaHeaderLen {
|
||||
ad.i += nlaHeaderLen
|
||||
} else {
|
||||
ad.i += nlaAlign(int(ad.a.Length))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Type returns the Attribute.Type field of the current netlink attribute
|
||||
// pointed to by the decoder.
|
||||
//
|
||||
// Type masks off the high bits of the netlink attribute type which may contain
|
||||
// the Nested and NetByteOrder flags. These can be obtained by calling TypeFlags.
|
||||
func (ad *AttributeDecoder) Type() uint16 {
|
||||
return ad.attr().Type
|
||||
// Mask off any flags stored in the high bits.
|
||||
return ad.a.Type & attrTypeMask
|
||||
}
|
||||
|
||||
// TypeFlags returns the two high bits of the Attribute.Type field of the current
|
||||
// netlink attribute pointed to by the decoder.
|
||||
//
|
||||
// These bits of the netlink attribute type are used for the Nested and NetByteOrder
|
||||
// flags, available as the Nested and NetByteOrder constants in this package.
|
||||
func (ad *AttributeDecoder) TypeFlags() uint16 {
|
||||
return ad.a.Type & ^attrTypeMask
|
||||
}
|
||||
|
||||
// Len returns the number of netlink attributes pointed to by the decoder.
|
||||
func (ad *AttributeDecoder) Len() int { return ad.length }
|
||||
|
||||
// count scans the input slice to count the number of netlink attributes
|
||||
// that could be decoded by Next().
|
||||
func (ad *AttributeDecoder) available() (int, error) {
|
||||
var i, count int
|
||||
for {
|
||||
|
||||
// No more data to read.
|
||||
if i >= len(ad.b) {
|
||||
break
|
||||
}
|
||||
|
||||
// Make sure there's at least a header's worth
|
||||
// of data to read on each iteration.
|
||||
if len(ad.b[i:]) < nlaHeaderLen {
|
||||
return 0, errInvalidAttribute
|
||||
}
|
||||
|
||||
// Extract the length of the attribute.
|
||||
l := int(nlenc.Uint16(ad.b[i : i+2]))
|
||||
|
||||
// Ignore zero-length attributes.
|
||||
if l != 0 {
|
||||
count++
|
||||
}
|
||||
|
||||
// Advance by at least a header's worth of bytes.
|
||||
if l < nlaHeaderLen {
|
||||
l = nlaHeaderLen
|
||||
}
|
||||
|
||||
i += nlaAlign(l)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// attr returns the current Attribute pointed to by the decoder.
|
||||
func (ad *AttributeDecoder) attr() Attribute {
|
||||
return ad.attrs[ad.i-1]
|
||||
return ad.a
|
||||
}
|
||||
|
||||
// data returns the Data field of the current Attribute pointed to by the decoder.
|
||||
func (ad *AttributeDecoder) data() []byte {
|
||||
return ad.attr().Data
|
||||
return ad.a.Data
|
||||
}
|
||||
|
||||
// Err returns the first error encountered by the decoder.
|
||||
|
|
@ -280,6 +358,21 @@ func (ad *AttributeDecoder) Uint64() uint64 {
|
|||
return ad.ByteOrder.Uint64(b)
|
||||
}
|
||||
|
||||
// Flag returns a boolean representing the Attribute.
|
||||
func (ad *AttributeDecoder) Flag() bool {
|
||||
if ad.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
b := ad.data()
|
||||
if len(b) != 0 {
|
||||
ad.err = fmt.Errorf("netlink: attribute %d is not a flag; length: %d", ad.Type(), len(b))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Do is a general purpose function which allows access to the current data
|
||||
// pointed to by the AttributeDecoder.
|
||||
//
|
||||
|
|
@ -301,6 +394,29 @@ func (ad *AttributeDecoder) Do(fn func(b []byte) error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Nested decodes data into a nested AttributeDecoder to handle nested netlink
|
||||
// attributes. When calling Nested, the Err method does not need to be called on
|
||||
// the nested AttributeDecoder.
|
||||
//
|
||||
// The nested AttributeDecoder nad inherits the same ByteOrder setting as the
|
||||
// top-level AttributeDecoder ad.
|
||||
func (ad *AttributeDecoder) Nested(fn func(nad *AttributeDecoder) error) {
|
||||
// Because we are wrapping Do, there is no need to check ad.err immediately.
|
||||
ad.Do(func(b []byte) error {
|
||||
nad, err := NewAttributeDecoder(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nad.ByteOrder = ad.ByteOrder
|
||||
|
||||
if err := fn(nad); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nad.Err()
|
||||
})
|
||||
}
|
||||
|
||||
// An AttributeEncoder provides a safe way to encode attributes.
|
||||
//
|
||||
// It is recommended to use an AttributeEncoder where possible instead of
|
||||
|
|
@ -384,6 +500,17 @@ func (ae *AttributeEncoder) Uint64(typ uint16, v uint64) {
|
|||
})
|
||||
}
|
||||
|
||||
// Flag encodes a flag into an Attribute specidied by typ.
|
||||
func (ae *AttributeEncoder) Flag(typ uint16, v bool) {
|
||||
// Only set flag on no previous error or v == true.
|
||||
if ae.err != nil || !v {
|
||||
return
|
||||
}
|
||||
|
||||
// Flags have no length or data fields.
|
||||
ae.attrs = append(ae.attrs, Attribute{Type: typ})
|
||||
}
|
||||
|
||||
// String encodes string s as a null-terminated string into an Attribute
|
||||
// specified by typ.
|
||||
func (ae *AttributeEncoder) String(typ uint16, s string) {
|
||||
|
|
@ -432,6 +559,26 @@ func (ae *AttributeEncoder) Do(typ uint16, fn func() ([]byte, error)) {
|
|||
})
|
||||
}
|
||||
|
||||
// Nested embeds data produced by a nested AttributeEncoder and flags that data
|
||||
// with the Nested flag. When calling Nested, the Encode method should not be
|
||||
// called on the nested AttributeEncoder.
|
||||
//
|
||||
// The nested AttributeEncoder nae inherits the same ByteOrder setting as the
|
||||
// top-level AttributeEncoder ae.
|
||||
func (ae *AttributeEncoder) Nested(typ uint16, fn func(nae *AttributeEncoder) error) {
|
||||
// Because we are wrapping Do, there is no need to check ae.err immediately.
|
||||
ae.Do(Nested|typ, func() ([]byte, error) {
|
||||
nae := NewAttributeEncoder()
|
||||
nae.ByteOrder = ae.ByteOrder
|
||||
|
||||
if err := fn(nae); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nae.Encode()
|
||||
})
|
||||
}
|
||||
|
||||
// Encode returns the encoded bytes representing the attributes.
|
||||
func (ae *AttributeEncoder) Encode() ([]byte, error) {
|
||||
if ae.err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue