Skip to content

Commit 9d88d83

Browse files
gongguanaboch
authored andcommitted
feat: add support for RtoMin lock
1 parent 6b5dd30 commit 9d88d83

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

route.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type Route struct {
8282
InitCwnd int
8383
Features int
8484
RtoMin int
85+
RtoMinLock bool
8586
InitRwnd int
8687
QuickACK int
8788
Congctl string

route_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,10 @@ func (h *Handle) prepareRouteReq(route *Route, req *nl.NetlinkRequest, msg *nl.R
11381138
if route.RtoMin > 0 {
11391139
b := nl.Uint32Attr(uint32(route.RtoMin))
11401140
metrics = append(metrics, nl.NewRtAttr(unix.RTAX_RTO_MIN, b))
1141+
if route.RtoMinLock {
1142+
b := nl.Uint32Attr(uint32(1 << unix.RTAX_RTO_MIN))
1143+
metrics = append(metrics, nl.NewRtAttr(unix.RTAX_LOCK, b))
1144+
}
11411145
}
11421146
if route.InitRwnd > 0 {
11431147
b := nl.Uint32Attr(uint32(route.InitRwnd))
@@ -1464,6 +1468,7 @@ func deserializeRoute(m []byte) (Route, error) {
14641468
route.MTU = int(native.Uint32(metric.Value[0:4]))
14651469
case unix.RTAX_LOCK:
14661470
route.MTULock = native.Uint32(metric.Value[0:4]) == uint32(1<<unix.RTAX_MTU)
1471+
route.RtoMinLock = native.Uint32(metric.Value[0:4]) == uint32(1<<unix.RTAX_RTO_MIN)
14671472
case unix.RTAX_WINDOW:
14681473
route.Window = int(native.Uint32(metric.Value[0:4]))
14691474
case unix.RTAX_RTT:

route_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,6 +2336,64 @@ func TestMTULockRouteAddDel(t *testing.T) {
23362336
}
23372337
}
23382338

2339+
func TestRtoMinLockRouteAddDel(t *testing.T) {
2340+
_, err := RouteList(nil, FAMILY_V4)
2341+
if err != nil {
2342+
t.Fatal(err)
2343+
}
2344+
2345+
tearDown := setUpNetlinkTest(t)
2346+
defer tearDown()
2347+
2348+
// get loopback interface
2349+
link, err := LinkByName("lo")
2350+
if err != nil {
2351+
t.Fatal(err)
2352+
}
2353+
2354+
// bring the interface up
2355+
if err := LinkSetUp(link); err != nil {
2356+
t.Fatal(err)
2357+
}
2358+
2359+
// add a gateway route
2360+
dst := &net.IPNet{
2361+
IP: net.IPv4(192, 168, 0, 0),
2362+
Mask: net.CIDRMask(24, 32),
2363+
}
2364+
2365+
route := Route{LinkIndex: link.Attrs().Index, Dst: dst, RtoMin: 40, RtoMinLock: true}
2366+
if err := RouteAdd(&route); err != nil {
2367+
t.Fatal(err)
2368+
}
2369+
routes, err := RouteList(link, FAMILY_V4)
2370+
if err != nil {
2371+
t.Fatal(err)
2372+
}
2373+
if len(routes) != 1 {
2374+
t.Fatal("Route not added properly")
2375+
}
2376+
2377+
if route.RtoMin != routes[0].RtoMin {
2378+
t.Fatal("Route RtoMin not set properly")
2379+
}
2380+
2381+
if route.RtoMinLock != routes[0].RtoMinLock {
2382+
t.Fatal("Route RtoMin lock not set properly")
2383+
}
2384+
2385+
if err := RouteDel(&route); err != nil {
2386+
t.Fatal(err)
2387+
}
2388+
routes, err = RouteList(link, FAMILY_V4)
2389+
if err != nil {
2390+
t.Fatal(err)
2391+
}
2392+
if len(routes) != 0 {
2393+
t.Fatal("Route not removed properly")
2394+
}
2395+
}
2396+
23392397
func TestRouteViaAddDel(t *testing.T) {
23402398
minKernelRequired(t, 5, 4)
23412399
tearDown := setUpNetlinkTest(t)

0 commit comments

Comments
 (0)