Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-netroute
Commits
29d70d1a
Unverified
Commit
29d70d1a
authored
Mar 30, 2020
by
Will
Committed by
GitHub
Mar 30, 2020
Browse files
Options
Browse Files
Download
Plain Diff
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
18 deletions
+18
-18
.circleci/config.yml
.circleci/config.yml
+1
-1
common.go
common.go
+7
-4
netroute_bsd.go
netroute_bsd.go
+5
-6
netroute_linux.go
netroute_linux.go
+5
-7
No files found.
.circleci/config.yml
View file @
29d70d1a
version
:
2.1
orbs
:
ci-go
:
ipfs/ci-go@0.2
ci-go
:
ipfs/ci-go@0.2
.8
workflows
:
version
:
2
...
...
common.go
View file @
29d70d1a
...
...
@@ -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
:
...
...
netroute_bsd.go
View file @
29d70d1a
...
...
@@ -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
}
netroute_linux.go
View file @
29d70d1a
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment