link_linux.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. package nl
  2. import (
  3. "syscall"
  4. "unsafe"
  5. )
  6. const (
  7. DEFAULT_CHANGE = 0xFFFFFFFF
  8. // doesn't exist in syscall
  9. IFLA_VFINFO_LIST = syscall.IFLA_IFALIAS + 1 + iota
  10. IFLA_STATS64
  11. IFLA_VF_PORTS
  12. IFLA_PORT_SELF
  13. IFLA_AF_SPEC
  14. IFLA_GROUP
  15. IFLA_NET_NS_FD
  16. IFLA_EXT_MASK
  17. IFLA_PROMISCUITY
  18. IFLA_NUM_TX_QUEUES
  19. IFLA_NUM_RX_QUEUES
  20. IFLA_CARRIER
  21. IFLA_PHYS_PORT_ID
  22. IFLA_CARRIER_CHANGES
  23. IFLA_PHYS_SWITCH_ID
  24. IFLA_LINK_NETNSID
  25. IFLA_PHYS_PORT_NAME
  26. IFLA_PROTO_DOWN
  27. IFLA_GSO_MAX_SEGS
  28. IFLA_GSO_MAX_SIZE
  29. IFLA_PAD
  30. IFLA_XDP
  31. )
  32. const (
  33. IFLA_INFO_UNSPEC = iota
  34. IFLA_INFO_KIND
  35. IFLA_INFO_DATA
  36. IFLA_INFO_XSTATS
  37. IFLA_INFO_MAX = IFLA_INFO_XSTATS
  38. )
  39. const (
  40. IFLA_VLAN_UNSPEC = iota
  41. IFLA_VLAN_ID
  42. IFLA_VLAN_FLAGS
  43. IFLA_VLAN_EGRESS_QOS
  44. IFLA_VLAN_INGRESS_QOS
  45. IFLA_VLAN_PROTOCOL
  46. IFLA_VLAN_MAX = IFLA_VLAN_PROTOCOL
  47. )
  48. const (
  49. VETH_INFO_UNSPEC = iota
  50. VETH_INFO_PEER
  51. VETH_INFO_MAX = VETH_INFO_PEER
  52. )
  53. const (
  54. IFLA_VXLAN_UNSPEC = iota
  55. IFLA_VXLAN_ID
  56. IFLA_VXLAN_GROUP
  57. IFLA_VXLAN_LINK
  58. IFLA_VXLAN_LOCAL
  59. IFLA_VXLAN_TTL
  60. IFLA_VXLAN_TOS
  61. IFLA_VXLAN_LEARNING
  62. IFLA_VXLAN_AGEING
  63. IFLA_VXLAN_LIMIT
  64. IFLA_VXLAN_PORT_RANGE
  65. IFLA_VXLAN_PROXY
  66. IFLA_VXLAN_RSC
  67. IFLA_VXLAN_L2MISS
  68. IFLA_VXLAN_L3MISS
  69. IFLA_VXLAN_PORT
  70. IFLA_VXLAN_GROUP6
  71. IFLA_VXLAN_LOCAL6
  72. IFLA_VXLAN_UDP_CSUM
  73. IFLA_VXLAN_UDP_ZERO_CSUM6_TX
  74. IFLA_VXLAN_UDP_ZERO_CSUM6_RX
  75. IFLA_VXLAN_REMCSUM_TX
  76. IFLA_VXLAN_REMCSUM_RX
  77. IFLA_VXLAN_GBP
  78. IFLA_VXLAN_REMCSUM_NOPARTIAL
  79. IFLA_VXLAN_FLOWBASED
  80. IFLA_VXLAN_MAX = IFLA_VXLAN_FLOWBASED
  81. )
  82. const (
  83. BRIDGE_MODE_UNSPEC = iota
  84. BRIDGE_MODE_HAIRPIN
  85. )
  86. const (
  87. IFLA_BRPORT_UNSPEC = iota
  88. IFLA_BRPORT_STATE
  89. IFLA_BRPORT_PRIORITY
  90. IFLA_BRPORT_COST
  91. IFLA_BRPORT_MODE
  92. IFLA_BRPORT_GUARD
  93. IFLA_BRPORT_PROTECT
  94. IFLA_BRPORT_FAST_LEAVE
  95. IFLA_BRPORT_LEARNING
  96. IFLA_BRPORT_UNICAST_FLOOD
  97. IFLA_BRPORT_MAX = IFLA_BRPORT_UNICAST_FLOOD
  98. )
  99. const (
  100. IFLA_IPVLAN_UNSPEC = iota
  101. IFLA_IPVLAN_MODE
  102. IFLA_IPVLAN_MAX = IFLA_IPVLAN_MODE
  103. )
  104. const (
  105. IFLA_MACVLAN_UNSPEC = iota
  106. IFLA_MACVLAN_MODE
  107. IFLA_MACVLAN_FLAGS
  108. IFLA_MACVLAN_MAX = IFLA_MACVLAN_FLAGS
  109. )
  110. const (
  111. MACVLAN_MODE_PRIVATE = 1
  112. MACVLAN_MODE_VEPA = 2
  113. MACVLAN_MODE_BRIDGE = 4
  114. MACVLAN_MODE_PASSTHRU = 8
  115. MACVLAN_MODE_SOURCE = 16
  116. )
  117. const (
  118. IFLA_BOND_UNSPEC = iota
  119. IFLA_BOND_MODE
  120. IFLA_BOND_ACTIVE_SLAVE
  121. IFLA_BOND_MIIMON
  122. IFLA_BOND_UPDELAY
  123. IFLA_BOND_DOWNDELAY
  124. IFLA_BOND_USE_CARRIER
  125. IFLA_BOND_ARP_INTERVAL
  126. IFLA_BOND_ARP_IP_TARGET
  127. IFLA_BOND_ARP_VALIDATE
  128. IFLA_BOND_ARP_ALL_TARGETS
  129. IFLA_BOND_PRIMARY
  130. IFLA_BOND_PRIMARY_RESELECT
  131. IFLA_BOND_FAIL_OVER_MAC
  132. IFLA_BOND_XMIT_HASH_POLICY
  133. IFLA_BOND_RESEND_IGMP
  134. IFLA_BOND_NUM_PEER_NOTIF
  135. IFLA_BOND_ALL_SLAVES_ACTIVE
  136. IFLA_BOND_MIN_LINKS
  137. IFLA_BOND_LP_INTERVAL
  138. IFLA_BOND_PACKETS_PER_SLAVE
  139. IFLA_BOND_AD_LACP_RATE
  140. IFLA_BOND_AD_SELECT
  141. IFLA_BOND_AD_INFO
  142. )
  143. const (
  144. IFLA_BOND_AD_INFO_UNSPEC = iota
  145. IFLA_BOND_AD_INFO_AGGREGATOR
  146. IFLA_BOND_AD_INFO_NUM_PORTS
  147. IFLA_BOND_AD_INFO_ACTOR_KEY
  148. IFLA_BOND_AD_INFO_PARTNER_KEY
  149. IFLA_BOND_AD_INFO_PARTNER_MAC
  150. )
  151. const (
  152. IFLA_BOND_SLAVE_UNSPEC = iota
  153. IFLA_BOND_SLAVE_STATE
  154. IFLA_BOND_SLAVE_MII_STATUS
  155. IFLA_BOND_SLAVE_LINK_FAILURE_COUNT
  156. IFLA_BOND_SLAVE_PERM_HWADDR
  157. IFLA_BOND_SLAVE_QUEUE_ID
  158. IFLA_BOND_SLAVE_AD_AGGREGATOR_ID
  159. )
  160. const (
  161. IFLA_GRE_UNSPEC = iota
  162. IFLA_GRE_LINK
  163. IFLA_GRE_IFLAGS
  164. IFLA_GRE_OFLAGS
  165. IFLA_GRE_IKEY
  166. IFLA_GRE_OKEY
  167. IFLA_GRE_LOCAL
  168. IFLA_GRE_REMOTE
  169. IFLA_GRE_TTL
  170. IFLA_GRE_TOS
  171. IFLA_GRE_PMTUDISC
  172. IFLA_GRE_ENCAP_LIMIT
  173. IFLA_GRE_FLOWINFO
  174. IFLA_GRE_FLAGS
  175. IFLA_GRE_ENCAP_TYPE
  176. IFLA_GRE_ENCAP_FLAGS
  177. IFLA_GRE_ENCAP_SPORT
  178. IFLA_GRE_ENCAP_DPORT
  179. IFLA_GRE_COLLECT_METADATA
  180. IFLA_GRE_MAX = IFLA_GRE_COLLECT_METADATA
  181. )
  182. const (
  183. GRE_CSUM = 0x8000
  184. GRE_ROUTING = 0x4000
  185. GRE_KEY = 0x2000
  186. GRE_SEQ = 0x1000
  187. GRE_STRICT = 0x0800
  188. GRE_REC = 0x0700
  189. GRE_FLAGS = 0x00F8
  190. GRE_VERSION = 0x0007
  191. )
  192. const (
  193. IFLA_VF_INFO_UNSPEC = iota
  194. IFLA_VF_INFO
  195. IFLA_VF_INFO_MAX = IFLA_VF_INFO
  196. )
  197. const (
  198. IFLA_VF_UNSPEC = iota
  199. IFLA_VF_MAC /* Hardware queue specific attributes */
  200. IFLA_VF_VLAN
  201. IFLA_VF_TX_RATE /* Max TX Bandwidth Allocation */
  202. IFLA_VF_SPOOFCHK /* Spoof Checking on/off switch */
  203. IFLA_VF_LINK_STATE /* link state enable/disable/auto switch */
  204. IFLA_VF_RATE /* Min and Max TX Bandwidth Allocation */
  205. IFLA_VF_RSS_QUERY_EN /* RSS Redirection Table and Hash Key query
  206. * on/off switch
  207. */
  208. IFLA_VF_STATS /* network device statistics */
  209. IFLA_VF_MAX = IFLA_VF_STATS
  210. )
  211. const (
  212. IFLA_VF_LINK_STATE_AUTO = iota /* link state of the uplink */
  213. IFLA_VF_LINK_STATE_ENABLE /* link always up */
  214. IFLA_VF_LINK_STATE_DISABLE /* link always down */
  215. IFLA_VF_LINK_STATE_MAX = IFLA_VF_LINK_STATE_DISABLE
  216. )
  217. const (
  218. IFLA_VF_STATS_RX_PACKETS = iota
  219. IFLA_VF_STATS_TX_PACKETS
  220. IFLA_VF_STATS_RX_BYTES
  221. IFLA_VF_STATS_TX_BYTES
  222. IFLA_VF_STATS_BROADCAST
  223. IFLA_VF_STATS_MULTICAST
  224. IFLA_VF_STATS_MAX = IFLA_VF_STATS_MULTICAST
  225. )
  226. const (
  227. SizeofVfMac = 0x24
  228. SizeofVfVlan = 0x0c
  229. SizeofVfTxRate = 0x08
  230. SizeofVfRate = 0x0c
  231. SizeofVfSpoofchk = 0x08
  232. SizeofVfLinkState = 0x08
  233. SizeofVfRssQueryEn = 0x08
  234. )
  235. // struct ifla_vf_mac {
  236. // __u32 vf;
  237. // __u8 mac[32]; /* MAX_ADDR_LEN */
  238. // };
  239. type VfMac struct {
  240. Vf uint32
  241. Mac [32]byte
  242. }
  243. func (msg *VfMac) Len() int {
  244. return SizeofVfMac
  245. }
  246. func DeserializeVfMac(b []byte) *VfMac {
  247. return (*VfMac)(unsafe.Pointer(&b[0:SizeofVfMac][0]))
  248. }
  249. func (msg *VfMac) Serialize() []byte {
  250. return (*(*[SizeofVfMac]byte)(unsafe.Pointer(msg)))[:]
  251. }
  252. // struct ifla_vf_vlan {
  253. // __u32 vf;
  254. // __u32 vlan; /* 0 - 4095, 0 disables VLAN filter */
  255. // __u32 qos;
  256. // };
  257. type VfVlan struct {
  258. Vf uint32
  259. Vlan uint32
  260. Qos uint32
  261. }
  262. func (msg *VfVlan) Len() int {
  263. return SizeofVfVlan
  264. }
  265. func DeserializeVfVlan(b []byte) *VfVlan {
  266. return (*VfVlan)(unsafe.Pointer(&b[0:SizeofVfVlan][0]))
  267. }
  268. func (msg *VfVlan) Serialize() []byte {
  269. return (*(*[SizeofVfVlan]byte)(unsafe.Pointer(msg)))[:]
  270. }
  271. // struct ifla_vf_tx_rate {
  272. // __u32 vf;
  273. // __u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */
  274. // };
  275. type VfTxRate struct {
  276. Vf uint32
  277. Rate uint32
  278. }
  279. func (msg *VfTxRate) Len() int {
  280. return SizeofVfTxRate
  281. }
  282. func DeserializeVfTxRate(b []byte) *VfTxRate {
  283. return (*VfTxRate)(unsafe.Pointer(&b[0:SizeofVfTxRate][0]))
  284. }
  285. func (msg *VfTxRate) Serialize() []byte {
  286. return (*(*[SizeofVfTxRate]byte)(unsafe.Pointer(msg)))[:]
  287. }
  288. // struct ifla_vf_rate {
  289. // __u32 vf;
  290. // __u32 min_tx_rate; /* Min Bandwidth in Mbps */
  291. // __u32 max_tx_rate; /* Max Bandwidth in Mbps */
  292. // };
  293. type VfRate struct {
  294. Vf uint32
  295. MinTxRate uint32
  296. MaxTxRate uint32
  297. }
  298. func (msg *VfRate) Len() int {
  299. return SizeofVfRate
  300. }
  301. func DeserializeVfRate(b []byte) *VfRate {
  302. return (*VfRate)(unsafe.Pointer(&b[0:SizeofVfRate][0]))
  303. }
  304. func (msg *VfRate) Serialize() []byte {
  305. return (*(*[SizeofVfRate]byte)(unsafe.Pointer(msg)))[:]
  306. }
  307. // struct ifla_vf_spoofchk {
  308. // __u32 vf;
  309. // __u32 setting;
  310. // };
  311. type VfSpoofchk struct {
  312. Vf uint32
  313. Setting uint32
  314. }
  315. func (msg *VfSpoofchk) Len() int {
  316. return SizeofVfSpoofchk
  317. }
  318. func DeserializeVfSpoofchk(b []byte) *VfSpoofchk {
  319. return (*VfSpoofchk)(unsafe.Pointer(&b[0:SizeofVfSpoofchk][0]))
  320. }
  321. func (msg *VfSpoofchk) Serialize() []byte {
  322. return (*(*[SizeofVfSpoofchk]byte)(unsafe.Pointer(msg)))[:]
  323. }
  324. // struct ifla_vf_link_state {
  325. // __u32 vf;
  326. // __u32 link_state;
  327. // };
  328. type VfLinkState struct {
  329. Vf uint32
  330. LinkState uint32
  331. }
  332. func (msg *VfLinkState) Len() int {
  333. return SizeofVfLinkState
  334. }
  335. func DeserializeVfLinkState(b []byte) *VfLinkState {
  336. return (*VfLinkState)(unsafe.Pointer(&b[0:SizeofVfLinkState][0]))
  337. }
  338. func (msg *VfLinkState) Serialize() []byte {
  339. return (*(*[SizeofVfLinkState]byte)(unsafe.Pointer(msg)))[:]
  340. }
  341. // struct ifla_vf_rss_query_en {
  342. // __u32 vf;
  343. // __u32 setting;
  344. // };
  345. type VfRssQueryEn struct {
  346. Vf uint32
  347. Setting uint32
  348. }
  349. func (msg *VfRssQueryEn) Len() int {
  350. return SizeofVfRssQueryEn
  351. }
  352. func DeserializeVfRssQueryEn(b []byte) *VfRssQueryEn {
  353. return (*VfRssQueryEn)(unsafe.Pointer(&b[0:SizeofVfRssQueryEn][0]))
  354. }
  355. func (msg *VfRssQueryEn) Serialize() []byte {
  356. return (*(*[SizeofVfRssQueryEn]byte)(unsafe.Pointer(msg)))[:]
  357. }
  358. const (
  359. IFLA_XDP_UNSPEC = iota
  360. IFLA_XDP_FD /* fd of xdp program to attach, or -1 to remove */
  361. IFLA_XDP_ATTACHED /* read-only bool indicating if prog is attached */
  362. IFLA_XDP_MAX = IFLA_XDP_ATTACHED
  363. )
  364. const (
  365. IFLA_IPTUN_UNSPEC = iota
  366. IFLA_IPTUN_LINK
  367. IFLA_IPTUN_LOCAL
  368. IFLA_IPTUN_REMOTE
  369. IFLA_IPTUN_TTL
  370. IFLA_IPTUN_TOS
  371. IFLA_IPTUN_ENCAP_LIMIT
  372. IFLA_IPTUN_FLOWINFO
  373. IFLA_IPTUN_FLAGS
  374. IFLA_IPTUN_PROTO
  375. IFLA_IPTUN_PMTUDISC
  376. IFLA_IPTUN_6RD_PREFIX
  377. IFLA_IPTUN_6RD_RELAY_PREFIX
  378. IFLA_IPTUN_6RD_PREFIXLEN
  379. IFLA_IPTUN_6RD_RELAY_PREFIXLEN
  380. IFLA_IPTUN_MAX = IFLA_IPTUN_6RD_RELAY_PREFIXLEN
  381. )
  382. const (
  383. IFLA_VTI_UNSPEC = iota
  384. IFLA_VTI_LINK
  385. IFLA_VTI_IKEY
  386. IFLA_VTI_OKEY
  387. IFLA_VTI_LOCAL
  388. IFLA_VTI_REMOTE
  389. IFLA_VTI_MAX = IFLA_VTI_REMOTE
  390. )
  391. const (
  392. IFLA_VRF_UNSPEC = iota
  393. IFLA_VRF_TABLE
  394. )