package route
-import (
- "testing"
- "unsafe"
-)
+import "testing"
func TestFetchAndParseRIBOnFreeBSD(t *testing.T) {
for _, typ := range []RIBType{sysNET_RT_IFMALIST} {
if _, err := FetchRIB(sysAF_UNSPEC, sysNET_RT_IFLISTL, 0); err != nil {
t.Skip("NET_RT_IFLISTL not supported")
}
- var p uintptr
- if kernelAlign != int(unsafe.Sizeof(p)) {
+ if compatFreeBSD32 {
t.Skip("NET_RT_IFLIST vs. NET_RT_IFLISTL doesn't work for 386 emulation on amd64")
}
}
}
+var compatFreeBSD32 bool // 386 emulation on amd64
+
func probeRoutingStack() (int, map[int]*wireFormat) {
var p uintptr
wordSize := int(unsafe.Sizeof(p))
break
}
}
+ if align != wordSize {
+ compatFreeBSD32 = true // 386 emulation on amd64
+ }
var rtm, ifm, ifam, ifmam, ifanm *wireFormat
- if align != wordSize { // 386 emulation on amd64
+ if compatFreeBSD32 {
rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10Emu - sizeofRtMetricsFreeBSD10Emu, bodyOff: sizeofRtMsghdrFreeBSD10Emu}
ifm = &wireFormat{extOff: 16}
ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10Emu, bodyOff: sizeofIfaMsghdrFreeBSD10Emu}
rel, _ := syscall.SysctlUint32("kern.osreldate")
switch {
case rel < 800000:
- if align != wordSize { // 386 emulation on amd64
+ if compatFreeBSD32 {
ifm.bodyOff = sizeofIfMsghdrFreeBSD7Emu
} else {
ifm.bodyOff = sizeofIfMsghdrFreeBSD7
}
case 800000 <= rel && rel < 900000:
- if align != wordSize { // 386 emulation on amd64
+ if compatFreeBSD32 {
ifm.bodyOff = sizeofIfMsghdrFreeBSD8Emu
} else {
ifm.bodyOff = sizeofIfMsghdrFreeBSD8
}
case 900000 <= rel && rel < 1000000:
- if align != wordSize { // 386 emulation on amd64
+ if compatFreeBSD32 {
ifm.bodyOff = sizeofIfMsghdrFreeBSD9Emu
} else {
ifm.bodyOff = sizeofIfMsghdrFreeBSD9
}
case 1000000 <= rel && rel < 1100000:
- if align != wordSize { // 386 emulation on amd64
+ if compatFreeBSD32 {
ifm.bodyOff = sizeofIfMsghdrFreeBSD10Emu
} else {
ifm.bodyOff = sizeofIfMsghdrFreeBSD10
}
default:
- if align != wordSize { // 386 emulation on amd64
+ if compatFreeBSD32 {
ifm.bodyOff = sizeofIfMsghdrFreeBSD11Emu
} else {
ifm.bodyOff = sizeofIfMsghdrFreeBSD11