Source file
src/syscall/route_dragonfly.go
1
2
3
4
5 package syscall
6
7 import "unsafe"
8
9 func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage {
10 switch any.Type {
11 case RTM_ADD, RTM_DELETE, RTM_CHANGE, RTM_GET, RTM_LOSING, RTM_REDIRECT, RTM_MISS, RTM_LOCK, RTM_RESOLVE:
12 p := (*RouteMessage)(unsafe.Pointer(any))
13
14 p.Header.Addrs &= RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_GENMASK | RTA_IFA | RTA_IFP | RTA_BRD | RTA_AUTHOR
15 return &RouteMessage{Header: p.Header, Data: b[SizeofRtMsghdr:any.Msglen]}
16 case RTM_IFINFO:
17 p := (*InterfaceMessage)(unsafe.Pointer(any))
18 return &InterfaceMessage{Header: p.Header, Data: b[SizeofIfMsghdr:any.Msglen]}
19 case RTM_IFANNOUNCE:
20 p := (*InterfaceAnnounceMessage)(unsafe.Pointer(any))
21 return &InterfaceAnnounceMessage{Header: p.Header}
22 case RTM_NEWADDR, RTM_DELADDR:
23 p := (*InterfaceAddrMessage)(unsafe.Pointer(any))
24 return &InterfaceAddrMessage{Header: p.Header, Data: b[SizeofIfaMsghdr:any.Msglen]}
25 case RTM_NEWMADDR, RTM_DELMADDR:
26 p := (*InterfaceMulticastAddrMessage)(unsafe.Pointer(any))
27 return &InterfaceMulticastAddrMessage{Header: p.Header, Data: b[SizeofIfmaMsghdr:any.Msglen]}
28 }
29 return nil
30 }
31
32
33
34
35
36 type InterfaceAnnounceMessage struct {
37 Header IfAnnounceMsghdr
38 }
39
40 func (m *InterfaceAnnounceMessage) sockaddr() ([]Sockaddr, error) { return nil, nil }
41
42
43
44
45
46 type InterfaceMulticastAddrMessage struct {
47 Header IfmaMsghdr
48 Data []byte
49 }
50
51 func (m *InterfaceMulticastAddrMessage) sockaddr() ([]Sockaddr, error) {
52 var sas [RTAX_MAX]Sockaddr
53 b := m.Data[:]
54 for i := uint(0); i < RTAX_MAX && len(b) >= minRoutingSockaddrLen; i++ {
55 if m.Header.Addrs&(1<<i) == 0 {
56 continue
57 }
58 rsa := (*RawSockaddr)(unsafe.Pointer(&b[0]))
59 switch rsa.Family {
60 case AF_LINK:
61 sa, err := parseSockaddrLink(b)
62 if err != nil {
63 return nil, err
64 }
65 sas[i] = sa
66 b = b[rsaAlignOf(int(rsa.Len)):]
67 case AF_INET, AF_INET6:
68 sa, err := parseSockaddrInet(b, rsa.Family)
69 if err != nil {
70 return nil, err
71 }
72 sas[i] = sa
73 b = b[rsaAlignOf(int(rsa.Len)):]
74 default:
75 sa, l, err := parseLinkLayerAddr(b)
76 if err != nil {
77 return nil, err
78 }
79 sas[i] = sa
80 b = b[l:]
81 }
82 }
83 return sas[:], nil
84 }
85
View as plain text