diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-03-25 15:34:20 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-03-25 15:39:29 +0900 |
| commit | 50403e9d60a69640107d20525379d4714da2f739 (patch) | |
| tree | eb9a72082f5aaf04c886db68b07ad8ccb9c88e72 /internal/netlink/rtnl.go | |
| parent | b98c5f2e219c142ab89c09445b6c014120f0760f (diff) | |
internal/netlink: wrap netpoll via context
This removes netpoll boilerplate for the most common use case.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/netlink/rtnl.go')
| -rw-r--r-- | internal/netlink/rtnl.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/internal/netlink/rtnl.go b/internal/netlink/rtnl.go index e6585bf8..e824f091 100644 --- a/internal/netlink/rtnl.go +++ b/internal/netlink/rtnl.go @@ -1,6 +1,7 @@ package netlink import ( + "context" "syscall" "unsafe" ) @@ -72,6 +73,7 @@ func (c *RouteConn) writeIfAddrmsg( // SendIfAddrmsg sends an ifaddrmsg structure to rtnetlink. func (c *RouteConn) SendIfAddrmsg( + ctx context.Context, typ, flags uint16, msg *syscall.IfAddrmsg, attrs ...RtAttrMsg[InAddr], @@ -79,7 +81,7 @@ func (c *RouteConn) SendIfAddrmsg( if !c.writeIfAddrmsg(typ, flags, msg, attrs...) { return syscall.ENOMEM } - return c.Roundtrip(rtnlConsume) + return c.Roundtrip(ctx, rtnlConsume) } // writeNewaddrLo writes a RTM_NEWADDR message for the loopback address. @@ -104,11 +106,11 @@ func (c *RouteConn) writeNewaddrLo(lo uint32) bool { } // SendNewaddrLo sends a RTM_NEWADDR message for the loopback address to the kernel. -func (c *RouteConn) SendNewaddrLo(lo uint32) error { +func (c *RouteConn) SendNewaddrLo(ctx context.Context, lo uint32) error { if !c.writeNewaddrLo(lo) { return syscall.ENOMEM } - return c.Roundtrip(rtnlConsume) + return c.Roundtrip(ctx, rtnlConsume) } // writeIfInfomsg writes an ifinfomsg structure to conn. @@ -122,11 +124,12 @@ func (c *RouteConn) writeIfInfomsg( // SendIfInfomsg sends an ifinfomsg structure to rtnetlink. func (c *RouteConn) SendIfInfomsg( + ctx context.Context, typ, flags uint16, msg *syscall.IfInfomsg, ) error { if !c.writeIfInfomsg(typ, flags, msg) { return syscall.ENOMEM } - return c.Roundtrip(rtnlConsume) + return c.Roundtrip(ctx, rtnlConsume) } |
