...
1
2
3
4
5
6
7 package route
8
9 import (
10 "runtime"
11 "syscall"
12 )
13
14 func (w *wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
15 if len(b) < w.bodyOff {
16 return nil, errMessageTooShort
17 }
18 l := int(nativeEndian.Uint16(b[:2]))
19 if len(b) < l {
20 return nil, errInvalidMessage
21 }
22 attrs := uint(nativeEndian.Uint32(b[4:8]))
23 if attrs&syscall.RTA_IFP == 0 {
24 return nil, nil
25 }
26 m := &InterfaceMessage{
27 Version: int(b[2]),
28 Type: int(b[3]),
29 Addrs: make([]Addr, syscall.RTAX_MAX),
30 Flags: int(nativeEndian.Uint32(b[8:12])),
31 Index: int(nativeEndian.Uint16(b[12:14])),
32 extOff: w.extOff,
33 raw: b[:l],
34 }
35 a, err := parseLinkAddr(b[w.bodyOff:])
36 if err != nil {
37 return nil, err
38 }
39 m.Addrs[syscall.RTAX_IFP] = a
40 m.Name = a.(*LinkAddr).Name
41 return m, nil
42 }
43
44 func (w *wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
45 if len(b) < w.bodyOff {
46 return nil, errMessageTooShort
47 }
48 l := int(nativeEndian.Uint16(b[:2]))
49 if len(b) < l {
50 return nil, errInvalidMessage
51 }
52 m := &InterfaceAddrMessage{
53 Version: int(b[2]),
54 Type: int(b[3]),
55 Flags: int(nativeEndian.Uint32(b[8:12])),
56 raw: b[:l],
57 }
58 if runtime.GOOS == "netbsd" {
59 m.Index = int(nativeEndian.Uint16(b[16:18]))
60 } else {
61 m.Index = int(nativeEndian.Uint16(b[12:14]))
62 }
63 var err error
64 m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[w.bodyOff:])
65 if err != nil {
66 return nil, err
67 }
68 return m, nil
69 }
70
View as plain text