Skip to content

Commit

Permalink
add netlink options
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitos committed Feb 7, 2025
1 parent 2b427a7 commit fb5e770
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions overlay/tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type tun struct {
routeTree atomic.Pointer[bart.Table[netip.Addr]]
routeChan chan struct{}
useSystemRoutes bool
useSystemRoutesBuffer int

l *logrus.Logger
}
Expand Down Expand Up @@ -129,6 +130,7 @@ func newTunGeneric(c *config.C, l *logrus.Logger, file *os.File, cidr netip.Pref
cidr: cidr,
TXQueueLen: c.GetInt("tun.tx_queue", 500),
useSystemRoutes: c.GetBool("tun.use_system_route_table", false),
useSystemRoutesBuffer: c.GetInt("tun.use_system_route_table_buffer", 0),
l: l,
}

Expand Down Expand Up @@ -488,7 +490,13 @@ func (t *tun) watchRoutes() {
rch := make(chan netlink.RouteUpdate)
doneChan := make(chan struct{})

if err := netlink.RouteSubscribe(rch, doneChan); err != nil {
netlinkOptions := netlink.RouteSubscribeOptions{
ReceiveBufferSize: t.useSystemRoutesBuffer,
ReceiveBufferForceSize: false,
ErrorCallback: func (e error) {t.l.WithError(e).Errorf("netlink error")},
}

if err := netlink.RouteSubscribeWithOptions(rch, doneChan, netlinkOptions); err != nil {
t.l.WithError(err).Errorf("failed to subscribe to system route changes")
return
}
Expand All @@ -498,8 +506,14 @@ func (t *tun) watchRoutes() {
go func() {
for {
select {
case r := <-rch:
t.updateRoutes(r)
case r, ok := <-rch:
if ok {
t.updateRoutes(r)
} else {
// may be should do something here as
// netlink stops sending updates
return
}
case <-doneChan:
// netlink.RouteSubscriber will close the rch for us
return
Expand Down

0 comments on commit fb5e770

Please sign in to comment.