...

Source file src/internal/x/net/route/sys_darwin.go

Documentation: internal/x/net/route

     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  func (typ RIBType) parseable() bool {
     8  	switch typ {
     9  	case sysNET_RT_STAT, sysNET_RT_TRASH:
    10  		return false
    11  	default:
    12  		return true
    13  	}
    14  }
    15  
    16  // RouteMetrics represents route metrics.
    17  type RouteMetrics struct {
    18  	PathMTU int // path maximum transmission unit
    19  }
    20  
    21  // SysType implements the SysType method of Sys interface.
    22  func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
    23  
    24  // Sys implements the Sys method of Message interface.
    25  func (m *RouteMessage) Sys() []Sys {
    26  	return []Sys{
    27  		&RouteMetrics{
    28  			PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
    29  		},
    30  	}
    31  }
    32  
    33  // InterfaceMetrics represents interface metrics.
    34  type InterfaceMetrics struct {
    35  	Type int // interface type
    36  	MTU  int // maximum transmission unit
    37  }
    38  
    39  // SysType implements the SysType method of Sys interface.
    40  func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
    41  
    42  // Sys implements the Sys method of Message interface.
    43  func (m *InterfaceMessage) Sys() []Sys {
    44  	return []Sys{
    45  		&InterfaceMetrics{
    46  			Type: int(m.raw[m.extOff]),
    47  			MTU:  int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
    48  		},
    49  	}
    50  }
    51  
    52  func probeRoutingStack() (int, map[int]*wireFormat) {
    53  	rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
    54  	rtm.parse = rtm.parseRouteMessage
    55  	rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
    56  	rtm2.parse = rtm2.parseRouteMessage
    57  	ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
    58  	ifm.parse = ifm.parseInterfaceMessage
    59  	ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
    60  	ifm2.parse = ifm2.parseInterfaceMessage
    61  	ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
    62  	ifam.parse = ifam.parseInterfaceAddrMessage
    63  	ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
    64  	ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
    65  	ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
    66  	ifmam2.parse = ifmam2.parseInterfaceMulticastAddrMessage
    67  	// Darwin kernels require 32-bit aligned access to routing facilities.
    68  	return 4, map[int]*wireFormat{
    69  		sysRTM_ADD:       rtm,
    70  		sysRTM_DELETE:    rtm,
    71  		sysRTM_CHANGE:    rtm,
    72  		sysRTM_GET:       rtm,
    73  		sysRTM_LOSING:    rtm,
    74  		sysRTM_REDIRECT:  rtm,
    75  		sysRTM_MISS:      rtm,
    76  		sysRTM_LOCK:      rtm,
    77  		sysRTM_RESOLVE:   rtm,
    78  		sysRTM_NEWADDR:   ifam,
    79  		sysRTM_DELADDR:   ifam,
    80  		sysRTM_IFINFO:    ifm,
    81  		sysRTM_NEWMADDR:  ifmam,
    82  		sysRTM_DELMADDR:  ifmam,
    83  		sysRTM_IFINFO2:   ifm2,
    84  		sysRTM_NEWMADDR2: ifmam2,
    85  		sysRTM_GET2:      rtm2,
    86  	}
    87  }
    88  

View as plain text