rtnetlink/route_live_test.go
Terin Stock 5d4f0c437b
feat(route): list with kernel filtering (#262)
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>
2025-05-11 12:06:36 +02:00

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)
}
}
}