Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/inventory/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (db *DB) Run(ctx context.Context) error {
// Obtain data that will not change after the startup
db.instance = getInstanceProperties(ctx)
db.gwInterfaces = getDefaultGwInterfaces()
klog.V(2).Infof("Default gateway interfaces: %v", db.gwInterfaces.UnsortedList())

for {
err := db.rateLimiter.Wait(ctx)
Expand Down
10 changes: 8 additions & 2 deletions pkg/inventory/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ import (
"github.com/cilium/ebpf/link"
"github.com/google/dranet/internal/nlwrap"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"

"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
)

// getDefaultGwInterfaces returns a set of interface names that are configured
// as default gateways in the main routing table. It identifies these by querying
// the main routing table for routes with an unspecified destination (0.0.0.0/0
// for IPv4 or ::/0 for IPv6).
func getDefaultGwInterfaces() sets.Set[string] {
interfaces := sets.Set[string]{}
filter := &netlink.Route{}
filter := &netlink.Route{
Table: unix.RT_TABLE_MAIN,
}
routes, err := nlwrap.RouteListFiltered(netlink.FAMILY_ALL, filter, netlink.RT_FILTER_TABLE)
if err != nil {
return interfaces
Expand Down Expand Up @@ -68,7 +75,6 @@ func getDefaultGwInterfaces() sets.Set[string] {
interfaces.Insert(intfLink.Attrs().Name)
}
}
klog.V(4).Infof("Found following interfaces for the default gateway: %v", interfaces.UnsortedList())
return interfaces
}

Expand Down
Loading