summaryrefslogtreecommitdiff
path: root/vendor/github.com/vishvananda/netlink/handle_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/vishvananda/netlink/handle_linux.go')
-rw-r--r--vendor/github.com/vishvananda/netlink/handle_linux.go51
1 files changed, 42 insertions, 9 deletions
diff --git a/vendor/github.com/vishvananda/netlink/handle_linux.go b/vendor/github.com/vishvananda/netlink/handle_linux.go
index a04ceae6b..9f6d7fe0f 100644
--- a/vendor/github.com/vishvananda/netlink/handle_linux.go
+++ b/vendor/github.com/vishvananda/netlink/handle_linux.go
@@ -2,11 +2,11 @@ package netlink
import (
"fmt"
- "syscall"
"time"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
+ "golang.org/x/sys/unix"
)
// Empty handle used by the netlink package methods
@@ -43,14 +43,29 @@ func (h *Handle) SetSocketTimeout(to time.Duration) error {
if to < time.Microsecond {
return fmt.Errorf("invalid timeout, minimul value is %s", time.Microsecond)
}
- tv := syscall.NsecToTimeval(to.Nanoseconds())
+ tv := unix.NsecToTimeval(to.Nanoseconds())
for _, sh := range h.sockets {
- fd := sh.Socket.GetFd()
- err := syscall.SetsockoptTimeval(fd, syscall.SOL_SOCKET, syscall.SO_RCVTIMEO, &tv)
- if err != nil {
+ if err := sh.Socket.SetSendTimeout(&tv); err != nil {
return err
}
- err = syscall.SetsockoptTimeval(fd, syscall.SOL_SOCKET, syscall.SO_SNDTIMEO, &tv)
+ if err := sh.Socket.SetReceiveTimeout(&tv); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// SetSocketReceiveBufferSize sets the receive buffer size for each
+// socket in the netlink handle. The maximum value is capped by
+// /proc/sys/net/core/rmem_max.
+func (h *Handle) SetSocketReceiveBufferSize(size int, force bool) error {
+ opt := unix.SO_RCVBUF
+ if force {
+ opt = unix.SO_RCVBUFFORCE
+ }
+ for _, sh := range h.sockets {
+ fd := sh.Socket.GetFd()
+ err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, opt, size)
if err != nil {
return err
}
@@ -58,6 +73,24 @@ func (h *Handle) SetSocketTimeout(to time.Duration) error {
return nil
}
+// GetSocketReceiveBufferSize gets the receiver buffer size for each
+// socket in the netlink handle. The retrieved value should be the
+// double to the one set for SetSocketReceiveBufferSize.
+func (h *Handle) GetSocketReceiveBufferSize() ([]int, error) {
+ results := make([]int, len(h.sockets))
+ i := 0
+ for _, sh := range h.sockets {
+ fd := sh.Socket.GetFd()
+ size, err := unix.GetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_RCVBUF)
+ if err != nil {
+ return nil, err
+ }
+ results[i] = size
+ i++
+ }
+ return results, nil
+}
+
// NewHandle returns a netlink handle on the network namespace
// specified by ns. If ns=netns.None(), current network namespace
// will be assumed
@@ -101,10 +134,10 @@ func (h *Handle) newNetlinkRequest(proto, flags int) *nl.NetlinkRequest {
return nl.NewNetlinkRequest(proto, flags)
}
return &nl.NetlinkRequest{
- NlMsghdr: syscall.NlMsghdr{
- Len: uint32(syscall.SizeofNlMsghdr),
+ NlMsghdr: unix.NlMsghdr{
+ Len: uint32(unix.SizeofNlMsghdr),
Type: uint16(proto),
- Flags: syscall.NLM_F_REQUEST | uint16(flags),
+ Flags: unix.NLM_F_REQUEST | uint16(flags),
},
Sockets: h.sockets,
}