mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
Detect the ABI version based on kern.osreldate. Only use 32-bit cmsg alignment for versions before the September 2019 ABI changes: http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html Use RTM_VERSION 7 on Dragonfly master (5.8 release). Determine sizeof struct ifa_msghdr at runtime based on the ABI version. Temporarily skip some test relying on the net package which will only be fixed once this CL is re-vendored into std. Updates golang/go#34368 Change-Id: I732fab21d569b303f45dfb6a0bbbb11469511a07 Reviewed-on: https://go-review.googlesource.com/c/net/+/202317 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build darwin dragonfly freebsd netbsd openbsd
|
|
|
|
package route
|
|
|
|
// A Message represents a routing message.
|
|
type Message interface {
|
|
// Sys returns operating system-specific information.
|
|
Sys() []Sys
|
|
}
|
|
|
|
// A Sys reprensents operating system-specific information.
|
|
type Sys interface {
|
|
// SysType returns a type of operating system-specific
|
|
// information.
|
|
SysType() SysType
|
|
}
|
|
|
|
// A SysType represents a type of operating system-specific
|
|
// information.
|
|
type SysType int
|
|
|
|
const (
|
|
SysMetrics SysType = iota
|
|
SysStats
|
|
)
|
|
|
|
// ParseRIB parses b as a routing information base and returns a list
|
|
// of routing messages.
|
|
func ParseRIB(typ RIBType, b []byte) ([]Message, error) {
|
|
if !typ.parseable() {
|
|
return nil, errUnsupportedMessage
|
|
}
|
|
var msgs []Message
|
|
nmsgs, nskips := 0, 0
|
|
for len(b) > 4 {
|
|
nmsgs++
|
|
l := int(nativeEndian.Uint16(b[:2]))
|
|
if l == 0 {
|
|
return nil, errInvalidMessage
|
|
}
|
|
if len(b) < l {
|
|
return nil, errMessageTooShort
|
|
}
|
|
if b[2] != rtmVersion {
|
|
b = b[l:]
|
|
continue
|
|
}
|
|
if w, ok := wireFormats[int(b[3])]; !ok {
|
|
nskips++
|
|
} else {
|
|
m, err := w.parse(typ, b)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if m == nil {
|
|
nskips++
|
|
} else {
|
|
msgs = append(msgs, m)
|
|
}
|
|
}
|
|
b = b[l:]
|
|
}
|
|
// We failed to parse any of the messages - version mismatch?
|
|
if nmsgs != len(msgs)+nskips {
|
|
return nil, errMessageMismatch
|
|
}
|
|
return msgs, nil
|
|
}
|