link_linux.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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_PROXYARP
  98. IFLA_BRPORT_LEARNING_SYNC
  99. IFLA_BRPORT_PROXYARP_WIFI
  100. IFLA_BRPORT_MAX = IFLA_BRPORT_PROXYARP_WIFI
  101. )
  102. const (
  103. IFLA_IPVLAN_UNSPEC = iota
  104. IFLA_IPVLAN_MODE
  105. IFLA_IPVLAN_MAX = IFLA_IPVLAN_MODE
  106. )
  107. const (
  108. IFLA_MACVLAN_UNSPEC = iota
  109. IFLA_MACVLAN_MODE
  110. IFLA_MACVLAN_FLAGS
  111. IFLA_MACVLAN_MAX = IFLA_MACVLAN_FLAGS
  112. )
  113. const (
  114. MACVLAN_MODE_PRIVATE = 1
  115. MACVLAN_MODE_VEPA = 2
  116. MACVLAN_MODE_BRIDGE = 4
  117. MACVLAN_MODE_PASSTHRU = 8
  118. MACVLAN_MODE_SOURCE = 16
  119. )
  120. const (
  121. IFLA_BOND_UNSPEC = iota
  122. IFLA_BOND_MODE
  123. IFLA_BOND_ACTIVE_SLAVE
  124. IFLA_BOND_MIIMON
  125. IFLA_BOND_UPDELAY
  126. IFLA_BOND_DOWNDELAY
  127. IFLA_BOND_USE_CARRIER
  128. IFLA_BOND_ARP_INTERVAL
  129. IFLA_BOND_ARP_IP_TARGET
  130. IFLA_BOND_ARP_VALIDATE
  131. IFLA_BOND_ARP_ALL_TARGETS
  132. IFLA_BOND_PRIMARY
  133. IFLA_BOND_PRIMARY_RESELECT
  134. IFLA_BOND_FAIL_OVER_MAC
  135. IFLA_BOND_XMIT_HASH_POLICY
  136. IFLA_BOND_RESEND_IGMP
  137. IFLA_BOND_NUM_PEER_NOTIF
  138. IFLA_BOND_ALL_SLAVES_ACTIVE
  139. IFLA_BOND_MIN_LINKS
  140. IFLA_BOND_LP_INTERVAL
  141. IFLA_BOND_PACKETS_PER_SLAVE
  142. IFLA_BOND_AD_LACP_RATE
  143. IFLA_BOND_AD_SELECT
  144. IFLA_BOND_AD_INFO
  145. IFLA_BOND_AD_ACTOR_SYS_PRIO
  146. IFLA_BOND_AD_USER_PORT_KEY
  147. IFLA_BOND_AD_ACTOR_SYSTEM
  148. IFLA_BOND_TLB_DYNAMIC_LB
  149. )
  150. const (
  151. IFLA_BOND_AD_INFO_UNSPEC = iota
  152. IFLA_BOND_AD_INFO_AGGREGATOR
  153. IFLA_BOND_AD_INFO_NUM_PORTS
  154. IFLA_BOND_AD_INFO_ACTOR_KEY
  155. IFLA_BOND_AD_INFO_PARTNER_KEY
  156. IFLA_BOND_AD_INFO_PARTNER_MAC
  157. )
  158. const (
  159. IFLA_BOND_SLAVE_UNSPEC = iota
  160. IFLA_BOND_SLAVE_STATE
  161. IFLA_BOND_SLAVE_MII_STATUS
  162. IFLA_BOND_SLAVE_LINK_FAILURE_COUNT
  163. IFLA_BOND_SLAVE_PERM_HWADDR
  164. IFLA_BOND_SLAVE_QUEUE_ID
  165. IFLA_BOND_SLAVE_AD_AGGREGATOR_ID
  166. )
  167. const (
  168. IFLA_GRE_UNSPEC = iota
  169. IFLA_GRE_LINK
  170. IFLA_GRE_IFLAGS
  171. IFLA_GRE_OFLAGS
  172. IFLA_GRE_IKEY
  173. IFLA_GRE_OKEY
  174. IFLA_GRE_LOCAL
  175. IFLA_GRE_REMOTE
  176. IFLA_GRE_TTL
  177. IFLA_GRE_TOS
  178. IFLA_GRE_PMTUDISC
  179. IFLA_GRE_ENCAP_LIMIT
  180. IFLA_GRE_FLOWINFO
  181. IFLA_GRE_FLAGS
  182. IFLA_GRE_ENCAP_TYPE
  183. IFLA_GRE_ENCAP_FLAGS
  184. IFLA_GRE_ENCAP_SPORT
  185. IFLA_GRE_ENCAP_DPORT
  186. IFLA_GRE_COLLECT_METADATA
  187. IFLA_GRE_MAX = IFLA_GRE_COLLECT_METADATA
  188. )
  189. const (
  190. GRE_CSUM = 0x8000
  191. GRE_ROUTING = 0x4000
  192. GRE_KEY = 0x2000
  193. GRE_SEQ = 0x1000
  194. GRE_STRICT = 0x0800
  195. GRE_REC = 0x0700
  196. GRE_FLAGS = 0x00F8
  197. GRE_VERSION = 0x0007
  198. )
  199. const (
  200. IFLA_VF_INFO_UNSPEC = iota
  201. IFLA_VF_INFO
  202. IFLA_VF_INFO_MAX = IFLA_VF_INFO
  203. )
  204. const (
  205. IFLA_VF_UNSPEC = iota
  206. IFLA_VF_MAC /* Hardware queue specific attributes */
  207. IFLA_VF_VLAN
  208. IFLA_VF_TX_RATE /* Max TX Bandwidth Allocation */
  209. IFLA_VF_SPOOFCHK /* Spoof Checking on/off switch */
  210. IFLA_VF_LINK_STATE /* link state enable/disable/auto switch */
  211. IFLA_VF_RATE /* Min and Max TX Bandwidth Allocation */
  212. IFLA_VF_RSS_QUERY_EN /* RSS Redirection Table and Hash Key query
  213. * on/off switch
  214. */
  215. IFLA_VF_STATS /* network device statistics */
  216. IFLA_VF_TRUST /* Trust state of VF */
  217. IFLA_VF_MAX = IFLA_VF_TRUST
  218. )
  219. const (
  220. IFLA_VF_LINK_STATE_AUTO = iota /* link state of the uplink */
  221. IFLA_VF_LINK_STATE_ENABLE /* link always up */
  222. IFLA_VF_LINK_STATE_DISABLE /* link always down */
  223. IFLA_VF_LINK_STATE_MAX = IFLA_VF_LINK_STATE_DISABLE
  224. )
  225. const (
  226. IFLA_VF_STATS_RX_PACKETS = iota
  227. IFLA_VF_STATS_TX_PACKETS
  228. IFLA_VF_STATS_RX_BYTES
  229. IFLA_VF_STATS_TX_BYTES
  230. IFLA_VF_STATS_BROADCAST
  231. IFLA_VF_STATS_MULTICAST
  232. IFLA_VF_STATS_MAX = IFLA_VF_STATS_MULTICAST
  233. )
  234. const (
  235. SizeofVfMac = 0x24
  236. SizeofVfVlan = 0x0c
  237. SizeofVfTxRate = 0x08
  238. SizeofVfRate = 0x0c
  239. SizeofVfSpoofchk = 0x08
  240. SizeofVfLinkState = 0x08
  241. SizeofVfRssQueryEn = 0x08
  242. SizeofVfTrust = 0x08
  243. )
  244. // struct ifla_vf_mac {
  245. // __u32 vf;
  246. // __u8 mac[32]; /* MAX_ADDR_LEN */
  247. // };
  248. type VfMac struct {
  249. Vf uint32
  250. Mac [32]byte
  251. }
  252. func (msg *VfMac) Len() int {
  253. return SizeofVfMac
  254. }
  255. func DeserializeVfMac(b []byte) *VfMac {
  256. return (*VfMac)(unsafe.Pointer(&b[0:SizeofVfMac][0]))
  257. }
  258. func (msg *VfMac) Serialize() []byte {
  259. return (*(*[SizeofVfMac]byte)(unsafe.Pointer(msg)))[:]
  260. }
  261. // struct ifla_vf_vlan {
  262. // __u32 vf;
  263. // __u32 vlan; /* 0 - 4095, 0 disables VLAN filter */
  264. // __u32 qos;
  265. // };
  266. type VfVlan struct {
  267. Vf uint32
  268. Vlan uint32
  269. Qos uint32
  270. }
  271. func (msg *VfVlan) Len() int {
  272. return SizeofVfVlan
  273. }
  274. func DeserializeVfVlan(b []byte) *VfVlan {
  275. return (*VfVlan)(unsafe.Pointer(&b[0:SizeofVfVlan][0]))
  276. }
  277. func (msg *VfVlan) Serialize() []byte {
  278. return (*(*[SizeofVfVlan]byte)(unsafe.Pointer(msg)))[:]
  279. }
  280. // struct ifla_vf_tx_rate {
  281. // __u32 vf;
  282. // __u32 rate; /* Max TX bandwidth in Mbps, 0 disables throttling */
  283. // };
  284. type VfTxRate struct {
  285. Vf uint32
  286. Rate uint32
  287. }
  288. func (msg *VfTxRate) Len() int {
  289. return SizeofVfTxRate
  290. }
  291. func DeserializeVfTxRate(b []byte) *VfTxRate {
  292. return (*VfTxRate)(unsafe.Pointer(&b[0:SizeofVfTxRate][0]))
  293. }
  294. func (msg *VfTxRate) Serialize() []byte {
  295. return (*(*[SizeofVfTxRate]byte)(unsafe.Pointer(msg)))[:]
  296. }
  297. // struct ifla_vf_rate {
  298. // __u32 vf;
  299. // __u32 min_tx_rate; /* Min Bandwidth in Mbps */
  300. // __u32 max_tx_rate; /* Max Bandwidth in Mbps */
  301. // };
  302. type VfRate struct {
  303. Vf uint32
  304. MinTxRate uint32
  305. MaxTxRate uint32
  306. }
  307. func (msg *VfRate) Len() int {
  308. return SizeofVfRate
  309. }
  310. func DeserializeVfRate(b []byte) *VfRate {
  311. return (*VfRate)(unsafe.Pointer(&b[0:SizeofVfRate][0]))
  312. }
  313. func (msg *VfRate) Serialize() []byte {
  314. return (*(*[SizeofVfRate]byte)(unsafe.Pointer(msg)))[:]
  315. }
  316. // struct ifla_vf_spoofchk {
  317. // __u32 vf;
  318. // __u32 setting;
  319. // };
  320. type VfSpoofchk struct {
  321. Vf uint32
  322. Setting uint32
  323. }
  324. func (msg *VfSpoofchk) Len() int {
  325. return SizeofVfSpoofchk
  326. }
  327. func DeserializeVfSpoofchk(b []byte) *VfSpoofchk {
  328. return (*VfSpoofchk)(unsafe.Pointer(&b[0:SizeofVfSpoofchk][0]))
  329. }
  330. func (msg *VfSpoofchk) Serialize() []byte {
  331. return (*(*[SizeofVfSpoofchk]byte)(unsafe.Pointer(msg)))[:]
  332. }
  333. // struct ifla_vf_link_state {
  334. // __u32 vf;
  335. // __u32 link_state;
  336. // };
  337. type VfLinkState struct {
  338. Vf uint32
  339. LinkState uint32
  340. }
  341. func (msg *VfLinkState) Len() int {
  342. return SizeofVfLinkState
  343. }
  344. func DeserializeVfLinkState(b []byte) *VfLinkState {
  345. return (*VfLinkState)(unsafe.Pointer(&b[0:SizeofVfLinkState][0]))
  346. }
  347. func (msg *VfLinkState) Serialize() []byte {
  348. return (*(*[SizeofVfLinkState]byte)(unsafe.Pointer(msg)))[:]
  349. }
  350. // struct ifla_vf_rss_query_en {
  351. // __u32 vf;
  352. // __u32 setting;
  353. // };
  354. type VfRssQueryEn struct {
  355. Vf uint32
  356. Setting uint32
  357. }
  358. func (msg *VfRssQueryEn) Len() int {
  359. return SizeofVfRssQueryEn
  360. }
  361. func DeserializeVfRssQueryEn(b []byte) *VfRssQueryEn {
  362. return (*VfRssQueryEn)(unsafe.Pointer(&b[0:SizeofVfRssQueryEn][0]))
  363. }
  364. func (msg *VfRssQueryEn) Serialize() []byte {
  365. return (*(*[SizeofVfRssQueryEn]byte)(unsafe.Pointer(msg)))[:]
  366. }
  367. // struct ifla_vf_trust {
  368. // __u32 vf;
  369. // __u32 setting;
  370. // };
  371. type VfTrust struct {
  372. Vf uint32
  373. Setting uint32
  374. }
  375. func (msg *VfTrust) Len() int {
  376. return SizeofVfTrust
  377. }
  378. func DeserializeVfTrust(b []byte) *VfTrust {
  379. return (*VfTrust)(unsafe.Pointer(&b[0:SizeofVfTrust][0]))
  380. }
  381. func (msg *VfTrust) Serialize() []byte {
  382. return (*(*[SizeofVfTrust]byte)(unsafe.Pointer(msg)))[:]
  383. }
  384. const (
  385. IFLA_XDP_UNSPEC = iota
  386. IFLA_XDP_FD /* fd of xdp program to attach, or -1 to remove */
  387. IFLA_XDP_ATTACHED /* read-only bool indicating if prog is attached */
  388. IFLA_XDP_FLAGS /* xdp prog related flags */
  389. IFLA_XDP_PROG_ID /* xdp prog id */
  390. IFLA_XDP_MAX = IFLA_XDP_PROG_ID
  391. )
  392. const (
  393. IFLA_IPTUN_UNSPEC = iota
  394. IFLA_IPTUN_LINK
  395. IFLA_IPTUN_LOCAL
  396. IFLA_IPTUN_REMOTE
  397. IFLA_IPTUN_TTL
  398. IFLA_IPTUN_TOS
  399. IFLA_IPTUN_ENCAP_LIMIT
  400. IFLA_IPTUN_FLOWINFO
  401. IFLA_IPTUN_FLAGS
  402. IFLA_IPTUN_PROTO
  403. IFLA_IPTUN_PMTUDISC
  404. IFLA_IPTUN_6RD_PREFIX
  405. IFLA_IPTUN_6RD_RELAY_PREFIX
  406. IFLA_IPTUN_6RD_PREFIXLEN
  407. IFLA_IPTUN_6RD_RELAY_PREFIXLEN
  408. IFLA_IPTUN_MAX = IFLA_IPTUN_6RD_RELAY_PREFIXLEN
  409. )
  410. const (
  411. IFLA_VTI_UNSPEC = iota
  412. IFLA_VTI_LINK
  413. IFLA_VTI_IKEY
  414. IFLA_VTI_OKEY
  415. IFLA_VTI_LOCAL
  416. IFLA_VTI_REMOTE
  417. IFLA_VTI_MAX = IFLA_VTI_REMOTE
  418. )
  419. const (
  420. IFLA_VRF_UNSPEC = iota
  421. IFLA_VRF_TABLE
  422. )
  423. const (
  424. IFLA_BR_UNSPEC = iota
  425. IFLA_BR_FORWARD_DELAY
  426. IFLA_BR_HELLO_TIME
  427. IFLA_BR_MAX_AGE
  428. IFLA_BR_AGEING_TIME
  429. IFLA_BR_STP_STATE
  430. IFLA_BR_PRIORITY
  431. IFLA_BR_VLAN_FILTERING
  432. IFLA_BR_VLAN_PROTOCOL
  433. IFLA_BR_GROUP_FWD_MASK
  434. IFLA_BR_ROOT_ID
  435. IFLA_BR_BRIDGE_ID
  436. IFLA_BR_ROOT_PORT
  437. IFLA_BR_ROOT_PATH_COST
  438. IFLA_BR_TOPOLOGY_CHANGE
  439. IFLA_BR_TOPOLOGY_CHANGE_DETECTED
  440. IFLA_BR_HELLO_TIMER
  441. IFLA_BR_TCN_TIMER
  442. IFLA_BR_TOPOLOGY_CHANGE_TIMER
  443. IFLA_BR_GC_TIMER
  444. IFLA_BR_GROUP_ADDR
  445. IFLA_BR_FDB_FLUSH
  446. IFLA_BR_MCAST_ROUTER
  447. IFLA_BR_MCAST_SNOOPING
  448. IFLA_BR_MCAST_QUERY_USE_IFADDR
  449. IFLA_BR_MCAST_QUERIER
  450. IFLA_BR_MCAST_HASH_ELASTICITY
  451. IFLA_BR_MCAST_HASH_MAX
  452. IFLA_BR_MCAST_LAST_MEMBER_CNT
  453. IFLA_BR_MCAST_STARTUP_QUERY_CNT
  454. IFLA_BR_MCAST_LAST_MEMBER_INTVL
  455. IFLA_BR_MCAST_MEMBERSHIP_INTVL
  456. IFLA_BR_MCAST_QUERIER_INTVL
  457. IFLA_BR_MCAST_QUERY_INTVL
  458. IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
  459. IFLA_BR_MCAST_STARTUP_QUERY_INTVL
  460. IFLA_BR_NF_CALL_IPTABLES
  461. IFLA_BR_NF_CALL_IP6TABLES
  462. IFLA_BR_NF_CALL_ARPTABLES
  463. IFLA_BR_VLAN_DEFAULT_PVID
  464. IFLA_BR_PAD
  465. IFLA_BR_VLAN_STATS_ENABLED
  466. IFLA_BR_MCAST_STATS_ENABLED
  467. IFLA_BR_MCAST_IGMP_VERSION
  468. IFLA_BR_MCAST_MLD_VERSION
  469. IFLA_BR_MAX = IFLA_BR_MCAST_MLD_VERSION
  470. )
  471. const (
  472. IFLA_GTP_UNSPEC = iota
  473. IFLA_GTP_FD0
  474. IFLA_GTP_FD1
  475. IFLA_GTP_PDP_HASHSIZE
  476. IFLA_GTP_ROLE
  477. )
  478. const (
  479. GTP_ROLE_GGSN = iota
  480. GTP_ROLE_SGSN
  481. )