Source file src/vendor/golang.org/x/net/route/sys_dragonfly.go

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package route
     6  
     7  import (
     8  	"syscall"
     9  	"unsafe"
    10  )
    11  
    12  func (typ RIBType) parseable() bool { return true }
    13  
    14  // RouteMetrics represents route metrics.
    15  type RouteMetrics struct {
    16  	PathMTU int // path maximum transmission unit
    17  }
    18  
    19  // SysType implements the SysType method of Sys interface.
    20  func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
    21  
    22  // Sys implements the Sys method of Message interface.
    23  func (m *RouteMessage) Sys() []Sys {
    24  	return []Sys{
    25  		&RouteMetrics{
    26  			PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
    27  		},
    28  	}
    29  }
    30  
    31  // InterfaceMetrics represents interface metrics.
    32  type InterfaceMetrics struct {
    33  	Type int // interface type
    34  	MTU  int // maximum transmission unit
    35  }
    36  
    37  // SysType implements the SysType method of Sys interface.
    38  func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
    39  
    40  // Sys implements the Sys method of Message interface.
    41  func (m *InterfaceMessage) Sys() []Sys {
    42  	return []Sys{
    43  		&InterfaceMetrics{
    44  			Type: int(m.raw[m.extOff]),
    45  			MTU:  int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
    46  		},
    47  	}
    48  }
    49  
    50  func probeRoutingStack() (int, map[int]*wireFormat) {
    51  	var p uintptr
    52  	rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrDragonFlyBSD4}
    53  	rtm.parse = rtm.parseRouteMessage
    54  	ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDragonFlyBSD4}
    55  	ifm.parse = ifm.parseInterfaceMessage
    56  	ifam := &wireFormat{extOff: sizeofIfaMsghdrDragonFlyBSD4, bodyOff: sizeofIfaMsghdrDragonFlyBSD4}
    57  	ifam.parse = ifam.parseInterfaceAddrMessage
    58  	ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDragonFlyBSD4, bodyOff: sizeofIfmaMsghdrDragonFlyBSD4}
    59  	ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
    60  	ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
    61  	ifanm.parse = ifanm.parseInterfaceAnnounceMessage
    62  
    63  	rel, _ := syscall.SysctlUint32("kern.osreldate")
    64  	if rel >= 500705 {
    65  		// https://github.com/DragonFlyBSD/DragonFlyBSD/commit/43a373152df2d405c9940983e584e6a25e76632d
    66  		// but only the size of struct ifa_msghdr actually changed
    67  		rtmVersion = 7
    68  		ifam.bodyOff = sizeofIfaMsghdrDragonFlyBSD58
    69  	}
    70  
    71  	return int(unsafe.Sizeof(p)), map[int]*wireFormat{
    72  		syscall.RTM_ADD:        rtm,
    73  		syscall.RTM_DELETE:     rtm,
    74  		syscall.RTM_CHANGE:     rtm,
    75  		syscall.RTM_GET:        rtm,
    76  		syscall.RTM_LOSING:     rtm,
    77  		syscall.RTM_REDIRECT:   rtm,
    78  		syscall.RTM_MISS:       rtm,
    79  		syscall.RTM_LOCK:       rtm,
    80  		syscall.RTM_RESOLVE:    rtm,
    81  		syscall.RTM_NEWADDR:    ifam,
    82  		syscall.RTM_DELADDR:    ifam,
    83  		syscall.RTM_IFINFO:     ifm,
    84  		syscall.RTM_NEWMADDR:   ifmam,
    85  		syscall.RTM_DELMADDR:   ifmam,
    86  		syscall.RTM_IFANNOUNCE: ifanm,
    87  	}
    88  }
    89  

View as plain text