Skip to content

feat: add support for RtoMin lock #1076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
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 route.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Route struct {
InitCwnd int
Features int
RtoMin int
RtoMinLock bool
InitRwnd int
QuickACK int
Congctl string
Expand Down
5 changes: 5 additions & 0 deletions route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,10 @@ func (h *Handle) prepareRouteReq(route *Route, req *nl.NetlinkRequest, msg *nl.R
if route.RtoMin > 0 {
b := nl.Uint32Attr(uint32(route.RtoMin))
metrics = append(metrics, nl.NewRtAttr(unix.RTAX_RTO_MIN, b))
if route.RtoMinLock {
b := nl.Uint32Attr(uint32(1 << unix.RTAX_RTO_MIN))
metrics = append(metrics, nl.NewRtAttr(unix.RTAX_LOCK, b))
}
}
if route.InitRwnd > 0 {
b := nl.Uint32Attr(uint32(route.InitRwnd))
Expand Down Expand Up @@ -1464,6 +1468,7 @@ func deserializeRoute(m []byte) (Route, error) {
route.MTU = int(native.Uint32(metric.Value[0:4]))
case unix.RTAX_LOCK:
route.MTULock = native.Uint32(metric.Value[0:4]) == uint32(1<<unix.RTAX_MTU)
route.RtoMinLock = native.Uint32(metric.Value[0:4]) == uint32(1<<unix.RTAX_RTO_MIN)
case unix.RTAX_WINDOW:
route.Window = int(native.Uint32(metric.Value[0:4]))
case unix.RTAX_RTT:
Expand Down
58 changes: 58 additions & 0 deletions route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,64 @@ func TestMTULockRouteAddDel(t *testing.T) {
}
}

func TestRtoMinLockRouteAddDel(t *testing.T) {
_, err := RouteList(nil, FAMILY_V4)
if err != nil {
t.Fatal(err)
}

tearDown := setUpNetlinkTest(t)
defer tearDown()

// get loopback interface
link, err := LinkByName("lo")
if err != nil {
t.Fatal(err)
}

// bring the interface up
if err := LinkSetUp(link); err != nil {
t.Fatal(err)
}

// add a gateway route
dst := &net.IPNet{
IP: net.IPv4(192, 168, 0, 0),
Mask: net.CIDRMask(24, 32),
}

route := Route{LinkIndex: link.Attrs().Index, Dst: dst, RtoMin: 40, RtoMinLock: true}
if err := RouteAdd(&route); err != nil {
t.Fatal(err)
}
routes, err := RouteList(link, FAMILY_V4)
if err != nil {
t.Fatal(err)
}
if len(routes) != 1 {
t.Fatal("Route not added properly")
}

if route.RtoMin != routes[0].RtoMin {
t.Fatal("Route RtoMin not set properly")
}

if route.RtoMinLock != routes[0].RtoMinLock {
t.Fatal("Route RtoMin lock not set properly")
}

if err := RouteDel(&route); err != nil {
t.Fatal(err)
}
routes, err = RouteList(link, FAMILY_V4)
if err != nil {
t.Fatal(err)
}
if len(routes) != 0 {
t.Fatal("Route not removed properly")
}
}

func TestRouteViaAddDel(t *testing.T) {
minKernelRequired(t, 5, 4)
tearDown := setUpNetlinkTest(t)
Expand Down