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