ioctl_linux.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package netlink
  2. import (
  3. "syscall"
  4. "unsafe"
  5. "golang.org/x/sys/unix"
  6. )
  7. // ioctl for statistics.
  8. const (
  9. // ETHTOOL_GSSET_INFO gets string set info
  10. ETHTOOL_GSSET_INFO = 0x00000037
  11. // SIOCETHTOOL is Ethtool interface
  12. SIOCETHTOOL = 0x8946
  13. // ETHTOOL_GSTRINGS gets specified string set
  14. ETHTOOL_GSTRINGS = 0x0000001b
  15. // ETHTOOL_GSTATS gets NIC-specific statistics
  16. ETHTOOL_GSTATS = 0x0000001d
  17. )
  18. // string set id.
  19. const (
  20. // ETH_SS_TEST is self-test result names, for use with %ETHTOOL_TEST
  21. ETH_SS_TEST = iota
  22. // ETH_SS_STATS statistic names, for use with %ETHTOOL_GSTATS
  23. ETH_SS_STATS
  24. // ETH_SS_PRIV_FLAGS are driver private flag names
  25. ETH_SS_PRIV_FLAGS
  26. // _ETH_SS_NTUPLE_FILTERS is deprecated
  27. _ETH_SS_NTUPLE_FILTERS
  28. // ETH_SS_FEATURES are device feature names
  29. ETH_SS_FEATURES
  30. // ETH_SS_RSS_HASH_FUNCS is RSS hush function names
  31. ETH_SS_RSS_HASH_FUNCS
  32. )
  33. // IfreqSlave is a struct for ioctl bond manipulation syscalls.
  34. // It is used to assign slave to bond interface with Name.
  35. type IfreqSlave struct {
  36. Name [unix.IFNAMSIZ]byte
  37. Slave [unix.IFNAMSIZ]byte
  38. }
  39. // Ifreq is a struct for ioctl ethernet manipulation syscalls.
  40. type Ifreq struct {
  41. Name [unix.IFNAMSIZ]byte
  42. Data uintptr
  43. }
  44. // ethtoolSset is a string set information
  45. type ethtoolSset struct {
  46. cmd uint32
  47. reserved uint32
  48. mask uint64
  49. data [1]uint32
  50. }
  51. // ethtoolGstrings is string set for data tagging
  52. type ethtoolGstrings struct {
  53. cmd uint32
  54. stringSet uint32
  55. length uint32
  56. data [32]byte
  57. }
  58. type ethtoolStats struct {
  59. cmd uint32
  60. nStats uint32
  61. data [1]uint64
  62. }
  63. // newIocltSlaveReq returns filled IfreqSlave with proper interface names
  64. // It is used by ioctl to assign slave to bond master
  65. func newIocltSlaveReq(slave, master string) *IfreqSlave {
  66. ifreq := &IfreqSlave{}
  67. copy(ifreq.Name[:unix.IFNAMSIZ-1], master)
  68. copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave)
  69. return ifreq
  70. }
  71. // newIocltStringSetReq creates request to get interface string set
  72. func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) {
  73. e := &ethtoolSset{
  74. cmd: ETHTOOL_GSSET_INFO,
  75. mask: 1 << ETH_SS_STATS,
  76. }
  77. ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))}
  78. copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName)
  79. return ifreq, e
  80. }
  81. // getSocketUDP returns file descriptor to new UDP socket
  82. // It is used for communication with ioctl interface.
  83. func getSocketUDP() (int, error) {
  84. return syscall.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0)
  85. }