Source file src/vendor/golang.org/x/net/route/sys_darwin.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 "syscall"
     8  
     9  func (typ RIBType) parseable() bool {
    10  	switch typ {
    11  	case syscall.NET_RT_STAT, syscall.NET_RT_TRASH:
    12  		return false
    13  	default:
    14  		return true
    15  	}
    16  }
    17  
    18  // RouteMetrics represents route metrics.
    19  type RouteMetrics struct {
    20  	PathMTU int // path maximum transmission unit
    21  }
    22  
    23  // SysType implements the SysType method of Sys interface.
    24  func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
    25  
    26  // Sys implements the Sys method of Message interface.
    27  func (m *RouteMessage) Sys() []Sys {
    28  	return []Sys{
    29  		&RouteMetrics{
    30  			PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
    31  		},
    32  	}
    33  }
    34  
    35  // InterfaceMetrics represents interface metrics.
    36  type InterfaceMetrics struct {
    37  	Type int // interface type
    38  	MTU  int // maximum transmission unit
    39  }
    40  
    41  // SysType implements the SysType method of Sys interface.
    42  func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
    43  
    44  // Sys implements the Sys method of Message interface.
    45  func (m *InterfaceMessage) Sys() []Sys {
    46  	return []Sys{
    47  		&InterfaceMetrics{
    48  			Type: int(m.raw[m.extOff]),
    49  			MTU:  int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
    50  		},
    51  	}
    52  }
    53  
    54  func probeRoutingStack() (int, map[int]*wireFormat) {
    55  	rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
    56  	rtm.parse = rtm.parseRouteMessage
    57  	rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
    58  	rtm2.parse = rtm2.parseRouteMessage
    59  	ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
    60  	ifm.parse = ifm.parseInterfaceMessage
    61  	ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
    62  	ifm2.parse = ifm2.parseInterfaceMessage
    63  	ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
    64  	ifam.parse = ifam.parseInterfaceAddrMessage
    65  	ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
    66  	ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
    67  	ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
    68  	ifmam2.parse = ifmam2.parseInterfaceMulticastAddrMessage
    69  	// Darwin kernels require 32-bit aligned access to routing facilities.
    70  	return 4, map[int]*wireFormat{
    71  		syscall.RTM_ADD:       rtm,
    72  		syscall.RTM_DELETE:    rtm,
    73  		syscall.RTM_CHANGE:    rtm,
    74  		syscall.RTM_GET:       rtm,
    75  		syscall.RTM_LOSING:    rtm,
    76  		syscall.RTM_REDIRECT:  rtm,
    77  		syscall.RTM_MISS:      rtm,
    78  		syscall.RTM_LOCK:      rtm,
    79  		syscall.RTM_RESOLVE:   rtm,
    80  		syscall.RTM_NEWADDR:   ifam,
    81  		syscall.RTM_DELADDR:   ifam,
    82  		syscall.RTM_IFINFO:    ifm,
    83  		syscall.RTM_NEWMADDR:  ifmam,
    84  		syscall.RTM_DELMADDR:  ifmam,
    85  		syscall.RTM_IFINFO2:   ifm2,
    86  		syscall.RTM_NEWMADDR2: ifmam2,
    87  		syscall.RTM_GET2:      rtm2,
    88  	}
    89  }
    90  

View as plain text