aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/netlink
diff options
context:
space:
mode:
Diffstat (limited to 'internal/netlink')
-rw-r--r--internal/netlink/netlink.go23
-rw-r--r--internal/netlink/rtnl.go4
2 files changed, 24 insertions, 3 deletions
diff --git a/internal/netlink/netlink.go b/internal/netlink/netlink.go
index 7324f1a7..6cd15610 100644
--- a/internal/netlink/netlink.go
+++ b/internal/netlink/netlink.go
@@ -46,7 +46,11 @@ type Conn struct {
// Dial returns the address of a newly connected generic netlink connection of
// specified family and groups.
-func Dial(family int, groups uint32) (*Conn, error) {
+//
+// For a nonzero rcvbuf, the socket receive buffer size is set to its absolute
+// value via SO_RCVBUF for a positive value, or SO_RCVBUFFORCE for a negative
+// value.
+func Dial(family int, groups uint32, rcvbuf int64) (*Conn, error) {
var c Conn
if fd, err := syscall.Socket(
syscall.AF_NETLINK,
@@ -75,6 +79,23 @@ func Dial(family int, groups uint32) (*Conn, error) {
return nil, syscall.ENOTRECOVERABLE
}
+ if rcvbuf != 0 {
+ opt := syscall.SO_RCVBUF
+ if rcvbuf < 0 {
+ opt = syscall.SO_RCVBUFFORCE
+ rcvbuf = -rcvbuf
+ }
+ if err = syscall.SetsockoptInt(
+ fd,
+ syscall.SOL_SOCKET,
+ opt,
+ int(rcvbuf),
+ ); err != nil {
+ _ = syscall.Close(fd)
+ return nil, os.NewSyscallError("setsockopt", err)
+ }
+ }
+
c.family = family
c.f = os.NewFile(uintptr(fd), "netlink")
if c.raw, err = c.f.SyscallConn(); err != nil {
diff --git a/internal/netlink/rtnl.go b/internal/netlink/rtnl.go
index e370bae7..521e8569 100644
--- a/internal/netlink/rtnl.go
+++ b/internal/netlink/rtnl.go
@@ -13,8 +13,8 @@ type RouteConn struct{ conn *Conn }
func (c *RouteConn) Close() error { return c.conn.Close() }
// DialRoute returns the address of a newly connected [RouteConn].
-func DialRoute() (*RouteConn, error) {
- c, err := Dial(syscall.NETLINK_ROUTE, 0)
+func DialRoute(rcvbuf int64) (*RouteConn, error) {
+ c, err := Dial(syscall.NETLINK_ROUTE, 0, rcvbuf)
if err != nil {
return nil, err
}