Skip to content

Commit 85c7afb

Browse files
authored
Merge pull request #64 from libp2p/use-rtnetlink
linux: use rtnetlink directly
2 parents 7c836b7 + 0d22acb commit 85c7afb

File tree

4 files changed

+281
-100
lines changed

4 files changed

+281
-100
lines changed

common.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"strings"
1919
)
2020

21+
//lint:file-ignore U1000 structs here used by different build tags
22+
2123
// rtInfo contains information on a single route.
2224
type rtInfo struct {
2325
Src, Dst *net.IPNet
@@ -60,23 +62,10 @@ func (rt rtInfo) IsMoreSpecThan(mostSpecificRt *rtInfo) bool {
6062
return mostSpecificRt.Priority >= rt.Priority
6163
}
6264

63-
// routeSlice implements sort.Interface to sort routes by Priority.
64-
type routeSlice []*rtInfo
65-
66-
func (r routeSlice) Len() int {
67-
return len(r)
68-
}
69-
func (r routeSlice) Less(i, j int) bool {
70-
return r[i].Priority < r[j].Priority
71-
}
72-
func (r routeSlice) Swap(i, j int) {
73-
r[i], r[j] = r[j], r[i]
74-
}
75-
7665
type router struct {
7766
ifaces map[int]net.Interface
7867
addrs map[int]ipAddrs
79-
v4, v6 routeSlice
68+
v4, v6 []*rtInfo
8069
}
8170

8271
func (r *router) String() string {
@@ -132,7 +121,7 @@ func (r *router) RouteWithSrc(input net.HardwareAddr, src, dst net.IP) (iface *n
132121
return
133122
}
134123

135-
func (r *router) route(routes routeSlice, input net.HardwareAddr, src, dst net.IP) (iface int, gateway, preferredSrc net.IP, err error) {
124+
func (r *router) route(routes []*rtInfo, input net.HardwareAddr, src, dst net.IP) (iface int, gateway, preferredSrc net.IP, err error) {
136125
var inputIndex uint32
137126
if input != nil {
138127
for i, iface := range r.ifaces {

0 commit comments

Comments
 (0)