mirror of
https://github.com/vishvananda/netlink
synced 2025-04-11 03:51:42 +00:00
Change route to hold pointers to structs
This commit is contained in:
parent
ec452b3aa1
commit
9f98335fb3
4
route.go
4
route.go
@ -10,8 +10,8 @@ import (
|
|||||||
// gateway. Advanced route parameters and non-main routing tables are
|
// gateway. Advanced route parameters and non-main routing tables are
|
||||||
// currently not supported.
|
// currently not supported.
|
||||||
type Route struct {
|
type Route struct {
|
||||||
Link Link
|
Link *Link
|
||||||
Dst net.IPNet
|
Dst *net.IPNet
|
||||||
Src net.IP
|
Src net.IP
|
||||||
Gw net.IP
|
Gw net.IP
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func RouteList(link *Link, family int) ([]Route, error) {
|
|||||||
case syscall.RTA_PREFSRC:
|
case syscall.RTA_PREFSRC:
|
||||||
route.Src = net.IP(attr.Value)
|
route.Src = net.IP(attr.Value)
|
||||||
case syscall.RTA_DST:
|
case syscall.RTA_DST:
|
||||||
route.Dst = net.IPNet{
|
route.Dst = &net.IPNet{
|
||||||
IP: attr.Value,
|
IP: attr.Value,
|
||||||
Mask: net.CIDRMask(int(msg.Dst_len), 8*len(attr.Value)),
|
Mask: net.CIDRMask(int(msg.Dst_len), 8*len(attr.Value)),
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ func RouteList(link *Link, family int) ([]Route, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resLink, _ := LinkByIndex(index)
|
resLink, _ := LinkByIndex(index)
|
||||||
route.Link = *resLink
|
route.Link = resLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = append(res, route)
|
res = append(res, route)
|
||||||
|
@ -24,7 +24,7 @@ func TestRouteAddDel(t *testing.T) {
|
|||||||
_, dst, err := net.ParseCIDR("192.168.0.0/24")
|
_, dst, err := net.ParseCIDR("192.168.0.0/24")
|
||||||
|
|
||||||
ip := net.ParseIP("127.1.1.1")
|
ip := net.ParseIP("127.1.1.1")
|
||||||
route := Route{Link: *link, Dst: *dst, Src: ip}
|
route := Route{Link: link, Dst: dst, Src: ip}
|
||||||
err = RouteAdd(&route)
|
err = RouteAdd(&route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user