gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/route/interface_openbsd.go (about)

     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 (*wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
     8  	if len(b) < 32 {
     9  		return nil, errMessageTooShort
    10  	}
    11  	l := int(nativeEndian.Uint16(b[:2]))
    12  	if len(b) < l {
    13  		return nil, errInvalidMessage
    14  	}
    15  	attrs := uint(nativeEndian.Uint32(b[12:16]))
    16  	if attrs&sysRTA_IFP == 0 {
    17  		return nil, nil
    18  	}
    19  	m := &InterfaceMessage{
    20  		Version: int(b[2]),
    21  		Type:    int(b[3]),
    22  		Flags:   int(nativeEndian.Uint32(b[16:20])),
    23  		Index:   int(nativeEndian.Uint16(b[6:8])),
    24  		Addrs:   make([]Addr, sysRTAX_MAX),
    25  		raw:     b[:l],
    26  	}
    27  	ll := int(nativeEndian.Uint16(b[4:6]))
    28  	if len(b) < ll {
    29  		return nil, errInvalidMessage
    30  	}
    31  	a, err := parseLinkAddr(b[ll:])
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  	m.Addrs[sysRTAX_IFP] = a
    36  	m.Name = a.(*LinkAddr).Name
    37  	return m, nil
    38  }
    39  
    40  func (*wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
    41  	if len(b) < 24 {
    42  		return nil, errMessageTooShort
    43  	}
    44  	l := int(nativeEndian.Uint16(b[:2]))
    45  	if len(b) < l {
    46  		return nil, errInvalidMessage
    47  	}
    48  	bodyOff := int(nativeEndian.Uint16(b[4:6]))
    49  	if len(b) < bodyOff {
    50  		return nil, errInvalidMessage
    51  	}
    52  	m := &InterfaceAddrMessage{
    53  		Version: int(b[2]),
    54  		Type:    int(b[3]),
    55  		Flags:   int(nativeEndian.Uint32(b[12:16])),
    56  		Index:   int(nativeEndian.Uint16(b[6:8])),
    57  		raw:     b[:l],
    58  	}
    59  	var err error
    60  	m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[bodyOff:])
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  	return m, nil
    65  }
    66  
    67  func (*wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
    68  	if len(b) < 26 {
    69  		return nil, errMessageTooShort
    70  	}
    71  	l := int(nativeEndian.Uint16(b[:2]))
    72  	if len(b) < l {
    73  		return nil, errInvalidMessage
    74  	}
    75  	m := &InterfaceAnnounceMessage{
    76  		Version: int(b[2]),
    77  		Type:    int(b[3]),
    78  		Index:   int(nativeEndian.Uint16(b[6:8])),
    79  		What:    int(nativeEndian.Uint16(b[8:10])),
    80  		raw:     b[:l],
    81  	}
    82  	for i := 0; i < 16; i++ {
    83  		if b[10+i] != 0 {
    84  			continue
    85  		}
    86  		m.Name = string(b[10 : 10+i])
    87  		break
    88  	}
    89  	return m, nil
    90  }