Merge pull request #2504 from weaveworks/check-tx-off
Check current tx value before trying to set it
This commit is contained in:
commit
6a528409ab
1 file changed
+20
-12
+20
-12
@@ -6,6 +6,7 @@ import "unsafe"
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
SIOCETHTOOL = 0x8946 // linux/sockios.h
|
SIOCETHTOOL = 0x8946 // linux/sockios.h
|
||||||
|
ETHTOOL_GTXCSUM = 0x00000016 // linux/ethtool.h
|
||||||
ETHTOOL_STXCSUM = 0x00000017 // linux/ethtool.h
|
ETHTOOL_STXCSUM = 0x00000017 // linux/ethtool.h
|
||||||
IFNAMSIZ = 16 // linux/if.h
|
IFNAMSIZ = 16 // linux/if.h
|
||||||
)
|
)
|
||||||
@@ -22,31 +23,38 @@ type EthtoolValue struct {
|
|||||||
Data uint32
|
Data uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ioctlEthtool(fd int, argp uintptr) error {
|
||||||
|
_, _, errno := syscall.RawSyscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(SIOCETHTOOL), argp)
|
||||||
|
if errno != 0 {
|
||||||
|
return errno
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Disable TX checksum offload on specified interface
|
// Disable TX checksum offload on specified interface
|
||||||
func EthtoolTXOff(name string) error {
|
func EthtoolTXOff(name string) error {
|
||||||
if len(name)+1 > IFNAMSIZ {
|
if len(name)+1 > IFNAMSIZ {
|
||||||
return fmt.Errorf("name too long")
|
return fmt.Errorf("name too long")
|
||||||
}
|
}
|
||||||
|
|
||||||
value := EthtoolValue{ETHTOOL_STXCSUM, 0}
|
|
||||||
request := IFReqData{Data: uintptr(unsafe.Pointer(&value))}
|
|
||||||
|
|
||||||
copy(request.Name[:], name)
|
|
||||||
|
|
||||||
socket, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0)
|
socket, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer syscall.Close(socket)
|
defer syscall.Close(socket)
|
||||||
|
|
||||||
_, _, errno := syscall.RawSyscall(syscall.SYS_IOCTL,
|
// Request current value
|
||||||
uintptr(socket),
|
value := EthtoolValue{Cmd: ETHTOOL_GTXCSUM}
|
||||||
uintptr(SIOCETHTOOL),
|
request := IFReqData{Data: uintptr(unsafe.Pointer(&value))}
|
||||||
uintptr(unsafe.Pointer(&request)))
|
copy(request.Name[:], name)
|
||||||
|
|
||||||
if errno != 0 {
|
if err := ioctlEthtool(socket, uintptr(unsafe.Pointer(&request))); err != nil {
|
||||||
return errno
|
return err
|
||||||
|
}
|
||||||
|
if value.Data == 0 { // if already off, don't try to change
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
value = EthtoolValue{ETHTOOL_STXCSUM, 0}
|
||||||
|
return ioctlEthtool(socket, uintptr(unsafe.Pointer(&request)))
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user