Unverified Commit 29d70d1a authored by Will's avatar Will Committed by GitHub

Merge pull request #9 from libp2p/bug/ifaceperm

remove full iface access assumption [linux/bsd]
parents bca610e7 d8d75cf2
Pipeline #486 failed with stages
in 0 seconds
version: 2.1
orbs:
ci-go: ipfs/ci-go@0.2
ci-go: ipfs/ci-go@0.2.8
workflows:
version: 2
......
......@@ -57,8 +57,8 @@ func (r routeSlice) Swap(i, j int) {
}
type router struct {
ifaces []net.Interface
addrs []ipAddrs
ifaces map[int]net.Interface
addrs map[int]ipAddrs
v4, v6 routeSlice
}
......@@ -98,9 +98,12 @@ func (r *router) RouteWithSrc(input net.HardwareAddr, src, dst net.IP) (iface *n
}
// Interfaces are 1-indexed, but we store them in a 0-indexed array.
ifaceIndex--
correspondingIface, ok := r.ifaces[ifaceIndex]
if !ok {
err = errors.New("Route refereced unknown interface")
}
iface = &correspondingIface
iface = &r.ifaces[ifaceIndex]
if preferredSrc == nil {
switch {
case dst.To4() != nil:
......
......@@ -53,6 +53,8 @@ const (
func New() (routing.Router, error) {
rtr := &router{}
rtr.ifaces = make(map[int]net.Interface)
rtr.addrs = make(map[int]ipAddrs)
tab, err := route.FetchRIB(syscall.AF_UNSPEC, route.RIBTypeRoute, 0)
if err != nil {
return nil, err
......@@ -124,11 +126,8 @@ func New() (routing.Router, error) {
if err != nil {
return nil, err
}
for i, iface := range ifaces {
if i != iface.Index-1 {
return nil, fmt.Errorf("out of order iface %d = %v", i, iface)
}
rtr.ifaces = append(rtr.ifaces, iface)
for _, iface := range ifaces {
rtr.ifaces[iface.Index] = iface
var addrs ipAddrs
ifaceAddrs, err := iface.Addrs()
if err != nil {
......@@ -148,7 +147,7 @@ func New() (routing.Router, error) {
}
}
}
rtr.addrs = append(rtr.addrs, addrs)
rtr.addrs[iface.Index] = addrs
}
return rtr, nil
}
......@@ -12,7 +12,6 @@
package netroute
import (
"fmt"
"net"
"sort"
"syscall"
......@@ -23,6 +22,8 @@ import (
func New() (routing.Router, error) {
rtr := &router{}
rtr.ifaces = make(map[int]net.Interface)
rtr.addrs = make(map[int]ipAddrs)
tab, err := syscall.NetlinkRIB(syscall.RTM_GETROUTE, syscall.AF_UNSPEC)
if err != nil {
return nil, err
......@@ -83,11 +84,8 @@ loop:
if err != nil {
return nil, err
}
for i, iface := range ifaces {
if i != iface.Index-1 {
return nil, fmt.Errorf("out of order iface %d = %v", i, iface)
}
rtr.ifaces = append(rtr.ifaces, iface)
for _, iface := range ifaces {
rtr.ifaces[iface.Index] = iface
var addrs ipAddrs
ifaceAddrs, err := iface.Addrs()
if err != nil {
......@@ -107,7 +105,7 @@ loop:
}
}
}
rtr.addrs = append(rtr.addrs, addrs)
rtr.addrs[iface.Index] = addrs
}
return rtr, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment