mirror of
https://github.com/jsimonetti/rtnetlink.git
synced 2026-03-28 15:31:09 +01:00
A new "ListMatch" function has been added to the RouteService to allow for kernel-based filtering of the routing tables. The netlink flags required for getting a route for an IP (eg, rtnl.RouteGetAll) is different than those required while filtering the table. This changeset removes the superfluous "netlink.DumpFiltered" flag from the Get function of RouteService, as this flag is for kernel responses. Signed-off-by: Terin Stock <terinjokes@gmail.com>
40 lines
720 B
Go
40 lines
720 B
Go
//go:build integration
|
|
// +build integration
|
|
|
|
package rtnetlink
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jsimonetti/rtnetlink/v2/internal/unix"
|
|
"github.com/mdlayher/netlink"
|
|
)
|
|
|
|
func TestListMatch(t *testing.T) {
|
|
c, err := Dial(&netlink.Config{Strict: true})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
|
|
routes, err := c.Route.ListMatch(&RouteMessage{
|
|
Family: unix.AF_INET,
|
|
Attributes: RouteAttributes{
|
|
Table: unix.RT_TABLE_MAIN,
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if len(routes) <= 1 {
|
|
t.Fatal("expected multiple routes to be returned")
|
|
}
|
|
|
|
for _, rx := range routes {
|
|
if rx.Attributes.Table != unix.RT_TABLE_MAIN {
|
|
t.Fatalf("unepxected route from table %d", rx.Attributes.Table)
|
|
}
|
|
}
|
|
}
|