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