link.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. package netlink
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. // Link represents a link device from netlink. Shared link attributes
  7. // like name may be retrieved using the Attrs() method. Unique data
  8. // can be retrieved by casting the object to the proper type.
  9. type Link interface {
  10. Attrs() *LinkAttrs
  11. Type() string
  12. }
  13. type (
  14. NsPid int
  15. NsFd int
  16. )
  17. // LinkAttrs represents data shared by most link types
  18. type LinkAttrs struct {
  19. Index int
  20. MTU int
  21. TxQLen int // Transmit Queue Length
  22. Name string
  23. HardwareAddr net.HardwareAddr
  24. Flags net.Flags
  25. RawFlags uint32
  26. ParentIndex int // index of the parent link device
  27. MasterIndex int // must be the index of a bridge
  28. Namespace interface{} // nil | NsPid | NsFd
  29. Alias string
  30. Statistics *LinkStatistics
  31. Promisc int
  32. Xdp *LinkXdp
  33. EncapType string
  34. Protinfo *Protinfo
  35. OperState LinkOperState
  36. }
  37. // LinkOperState represents the values of the IFLA_OPERSTATE link
  38. // attribute, which contains the RFC2863 state of the interface.
  39. type LinkOperState uint8
  40. const (
  41. OperUnknown = iota // Status can't be determined.
  42. OperNotPresent // Some component is missing.
  43. OperDown // Down.
  44. OperLowerLayerDown // Down due to state of lower layer.
  45. OperTesting // In some test mode.
  46. OperDormant // Not up but pending an external event.
  47. OperUp // Up, ready to send packets.
  48. )
  49. func (s LinkOperState) String() string {
  50. switch s {
  51. case OperNotPresent:
  52. return "not-present"
  53. case OperDown:
  54. return "down"
  55. case OperLowerLayerDown:
  56. return "lower-layer-down"
  57. case OperTesting:
  58. return "testing"
  59. case OperDormant:
  60. return "dormant"
  61. case OperUp:
  62. return "up"
  63. default:
  64. return "unknown"
  65. }
  66. }
  67. // NewLinkAttrs returns LinkAttrs structure filled with default values
  68. func NewLinkAttrs() LinkAttrs {
  69. return LinkAttrs{
  70. TxQLen: -1,
  71. }
  72. }
  73. type LinkStatistics LinkStatistics64
  74. /*
  75. Ref: struct rtnl_link_stats {...}
  76. */
  77. type LinkStatistics32 struct {
  78. RxPackets uint32
  79. TxPackets uint32
  80. RxBytes uint32
  81. TxBytes uint32
  82. RxErrors uint32
  83. TxErrors uint32
  84. RxDropped uint32
  85. TxDropped uint32
  86. Multicast uint32
  87. Collisions uint32
  88. RxLengthErrors uint32
  89. RxOverErrors uint32
  90. RxCrcErrors uint32
  91. RxFrameErrors uint32
  92. RxFifoErrors uint32
  93. RxMissedErrors uint32
  94. TxAbortedErrors uint32
  95. TxCarrierErrors uint32
  96. TxFifoErrors uint32
  97. TxHeartbeatErrors uint32
  98. TxWindowErrors uint32
  99. RxCompressed uint32
  100. TxCompressed uint32
  101. }
  102. func (s32 LinkStatistics32) to64() *LinkStatistics64 {
  103. return &LinkStatistics64{
  104. RxPackets: uint64(s32.RxPackets),
  105. TxPackets: uint64(s32.TxPackets),
  106. RxBytes: uint64(s32.RxBytes),
  107. TxBytes: uint64(s32.TxBytes),
  108. RxErrors: uint64(s32.RxErrors),
  109. TxErrors: uint64(s32.TxErrors),
  110. RxDropped: uint64(s32.RxDropped),
  111. TxDropped: uint64(s32.TxDropped),
  112. Multicast: uint64(s32.Multicast),
  113. Collisions: uint64(s32.Collisions),
  114. RxLengthErrors: uint64(s32.RxLengthErrors),
  115. RxOverErrors: uint64(s32.RxOverErrors),
  116. RxCrcErrors: uint64(s32.RxCrcErrors),
  117. RxFrameErrors: uint64(s32.RxFrameErrors),
  118. RxFifoErrors: uint64(s32.RxFifoErrors),
  119. RxMissedErrors: uint64(s32.RxMissedErrors),
  120. TxAbortedErrors: uint64(s32.TxAbortedErrors),
  121. TxCarrierErrors: uint64(s32.TxCarrierErrors),
  122. TxFifoErrors: uint64(s32.TxFifoErrors),
  123. TxHeartbeatErrors: uint64(s32.TxHeartbeatErrors),
  124. TxWindowErrors: uint64(s32.TxWindowErrors),
  125. RxCompressed: uint64(s32.RxCompressed),
  126. TxCompressed: uint64(s32.TxCompressed),
  127. }
  128. }
  129. /*
  130. Ref: struct rtnl_link_stats64 {...}
  131. */
  132. type LinkStatistics64 struct {
  133. RxPackets uint64
  134. TxPackets uint64
  135. RxBytes uint64
  136. TxBytes uint64
  137. RxErrors uint64
  138. TxErrors uint64
  139. RxDropped uint64
  140. TxDropped uint64
  141. Multicast uint64
  142. Collisions uint64
  143. RxLengthErrors uint64
  144. RxOverErrors uint64
  145. RxCrcErrors uint64
  146. RxFrameErrors uint64
  147. RxFifoErrors uint64
  148. RxMissedErrors uint64
  149. TxAbortedErrors uint64
  150. TxCarrierErrors uint64
  151. TxFifoErrors uint64
  152. TxHeartbeatErrors uint64
  153. TxWindowErrors uint64
  154. RxCompressed uint64
  155. TxCompressed uint64
  156. }
  157. type LinkXdp struct {
  158. Fd int
  159. Attached bool
  160. Flags uint32
  161. ProgId uint32
  162. }
  163. // Device links cannot be created via netlink. These links
  164. // are links created by udev like 'lo' and 'etho0'
  165. type Device struct {
  166. LinkAttrs
  167. }
  168. func (device *Device) Attrs() *LinkAttrs {
  169. return &device.LinkAttrs
  170. }
  171. func (device *Device) Type() string {
  172. return "device"
  173. }
  174. // Dummy links are dummy ethernet devices
  175. type Dummy struct {
  176. LinkAttrs
  177. }
  178. func (dummy *Dummy) Attrs() *LinkAttrs {
  179. return &dummy.LinkAttrs
  180. }
  181. func (dummy *Dummy) Type() string {
  182. return "dummy"
  183. }
  184. // Ifb links are advanced dummy devices for packet filtering
  185. type Ifb struct {
  186. LinkAttrs
  187. }
  188. func (ifb *Ifb) Attrs() *LinkAttrs {
  189. return &ifb.LinkAttrs
  190. }
  191. func (ifb *Ifb) Type() string {
  192. return "ifb"
  193. }
  194. // Bridge links are simple linux bridges
  195. type Bridge struct {
  196. LinkAttrs
  197. MulticastSnooping *bool
  198. HelloTime *uint32
  199. }
  200. func (bridge *Bridge) Attrs() *LinkAttrs {
  201. return &bridge.LinkAttrs
  202. }
  203. func (bridge *Bridge) Type() string {
  204. return "bridge"
  205. }
  206. // Vlan links have ParentIndex set in their Attrs()
  207. type Vlan struct {
  208. LinkAttrs
  209. VlanId int
  210. }
  211. func (vlan *Vlan) Attrs() *LinkAttrs {
  212. return &vlan.LinkAttrs
  213. }
  214. func (vlan *Vlan) Type() string {
  215. return "vlan"
  216. }
  217. type MacvlanMode uint16
  218. const (
  219. MACVLAN_MODE_DEFAULT MacvlanMode = iota
  220. MACVLAN_MODE_PRIVATE
  221. MACVLAN_MODE_VEPA
  222. MACVLAN_MODE_BRIDGE
  223. MACVLAN_MODE_PASSTHRU
  224. MACVLAN_MODE_SOURCE
  225. )
  226. // Macvlan links have ParentIndex set in their Attrs()
  227. type Macvlan struct {
  228. LinkAttrs
  229. Mode MacvlanMode
  230. }
  231. func (macvlan *Macvlan) Attrs() *LinkAttrs {
  232. return &macvlan.LinkAttrs
  233. }
  234. func (macvlan *Macvlan) Type() string {
  235. return "macvlan"
  236. }
  237. // Macvtap - macvtap is a virtual interfaces based on macvlan
  238. type Macvtap struct {
  239. Macvlan
  240. }
  241. func (macvtap Macvtap) Type() string {
  242. return "macvtap"
  243. }
  244. type TuntapMode uint16
  245. type TuntapFlag uint16
  246. // Tuntap links created via /dev/tun/tap, but can be destroyed via netlink
  247. type Tuntap struct {
  248. LinkAttrs
  249. Mode TuntapMode
  250. Flags TuntapFlag
  251. }
  252. func (tuntap *Tuntap) Attrs() *LinkAttrs {
  253. return &tuntap.LinkAttrs
  254. }
  255. func (tuntap *Tuntap) Type() string {
  256. return "tuntap"
  257. }
  258. // Veth devices must specify PeerName on create
  259. type Veth struct {
  260. LinkAttrs
  261. PeerName string // veth on create only
  262. }
  263. func (veth *Veth) Attrs() *LinkAttrs {
  264. return &veth.LinkAttrs
  265. }
  266. func (veth *Veth) Type() string {
  267. return "veth"
  268. }
  269. // GenericLink links represent types that are not currently understood
  270. // by this netlink library.
  271. type GenericLink struct {
  272. LinkAttrs
  273. LinkType string
  274. }
  275. func (generic *GenericLink) Attrs() *LinkAttrs {
  276. return &generic.LinkAttrs
  277. }
  278. func (generic *GenericLink) Type() string {
  279. return generic.LinkType
  280. }
  281. type Vxlan struct {
  282. LinkAttrs
  283. VxlanId int
  284. VtepDevIndex int
  285. SrcAddr net.IP
  286. Group net.IP
  287. TTL int
  288. TOS int
  289. Learning bool
  290. Proxy bool
  291. RSC bool
  292. L2miss bool
  293. L3miss bool
  294. UDPCSum bool
  295. NoAge bool
  296. GBP bool
  297. FlowBased bool
  298. Age int
  299. Limit int
  300. Port int
  301. PortLow int
  302. PortHigh int
  303. }
  304. func (vxlan *Vxlan) Attrs() *LinkAttrs {
  305. return &vxlan.LinkAttrs
  306. }
  307. func (vxlan *Vxlan) Type() string {
  308. return "vxlan"
  309. }
  310. type IPVlanMode uint16
  311. const (
  312. IPVLAN_MODE_L2 IPVlanMode = iota
  313. IPVLAN_MODE_L3
  314. IPVLAN_MODE_L3S
  315. IPVLAN_MODE_MAX
  316. )
  317. type IPVlan struct {
  318. LinkAttrs
  319. Mode IPVlanMode
  320. }
  321. func (ipvlan *IPVlan) Attrs() *LinkAttrs {
  322. return &ipvlan.LinkAttrs
  323. }
  324. func (ipvlan *IPVlan) Type() string {
  325. return "ipvlan"
  326. }
  327. // BondMode type
  328. type BondMode int
  329. func (b BondMode) String() string {
  330. s, ok := bondModeToString[b]
  331. if !ok {
  332. return fmt.Sprintf("BondMode(%d)", b)
  333. }
  334. return s
  335. }
  336. // StringToBondMode returns bond mode, or uknonw is the s is invalid.
  337. func StringToBondMode(s string) BondMode {
  338. mode, ok := StringToBondModeMap[s]
  339. if !ok {
  340. return BOND_MODE_UNKNOWN
  341. }
  342. return mode
  343. }
  344. // Possible BondMode
  345. const (
  346. BOND_MODE_BALANCE_RR BondMode = iota
  347. BOND_MODE_ACTIVE_BACKUP
  348. BOND_MODE_BALANCE_XOR
  349. BOND_MODE_BROADCAST
  350. BOND_MODE_802_3AD
  351. BOND_MODE_BALANCE_TLB
  352. BOND_MODE_BALANCE_ALB
  353. BOND_MODE_UNKNOWN
  354. )
  355. var bondModeToString = map[BondMode]string{
  356. BOND_MODE_BALANCE_RR: "balance-rr",
  357. BOND_MODE_ACTIVE_BACKUP: "active-backup",
  358. BOND_MODE_BALANCE_XOR: "balance-xor",
  359. BOND_MODE_BROADCAST: "broadcast",
  360. BOND_MODE_802_3AD: "802.3ad",
  361. BOND_MODE_BALANCE_TLB: "balance-tlb",
  362. BOND_MODE_BALANCE_ALB: "balance-alb",
  363. }
  364. var StringToBondModeMap = map[string]BondMode{
  365. "balance-rr": BOND_MODE_BALANCE_RR,
  366. "active-backup": BOND_MODE_ACTIVE_BACKUP,
  367. "balance-xor": BOND_MODE_BALANCE_XOR,
  368. "broadcast": BOND_MODE_BROADCAST,
  369. "802.3ad": BOND_MODE_802_3AD,
  370. "balance-tlb": BOND_MODE_BALANCE_TLB,
  371. "balance-alb": BOND_MODE_BALANCE_ALB,
  372. }
  373. // BondArpValidate type
  374. type BondArpValidate int
  375. // Possible BondArpValidate value
  376. const (
  377. BOND_ARP_VALIDATE_NONE BondArpValidate = iota
  378. BOND_ARP_VALIDATE_ACTIVE
  379. BOND_ARP_VALIDATE_BACKUP
  380. BOND_ARP_VALIDATE_ALL
  381. )
  382. // BondPrimaryReselect type
  383. type BondPrimaryReselect int
  384. // Possible BondPrimaryReselect value
  385. const (
  386. BOND_PRIMARY_RESELECT_ALWAYS BondPrimaryReselect = iota
  387. BOND_PRIMARY_RESELECT_BETTER
  388. BOND_PRIMARY_RESELECT_FAILURE
  389. )
  390. // BondArpAllTargets type
  391. type BondArpAllTargets int
  392. // Possible BondArpAllTargets value
  393. const (
  394. BOND_ARP_ALL_TARGETS_ANY BondArpAllTargets = iota
  395. BOND_ARP_ALL_TARGETS_ALL
  396. )
  397. // BondFailOverMac type
  398. type BondFailOverMac int
  399. // Possible BondFailOverMac value
  400. const (
  401. BOND_FAIL_OVER_MAC_NONE BondFailOverMac = iota
  402. BOND_FAIL_OVER_MAC_ACTIVE
  403. BOND_FAIL_OVER_MAC_FOLLOW
  404. )
  405. // BondXmitHashPolicy type
  406. type BondXmitHashPolicy int
  407. func (b BondXmitHashPolicy) String() string {
  408. s, ok := bondXmitHashPolicyToString[b]
  409. if !ok {
  410. return fmt.Sprintf("XmitHashPolicy(%d)", b)
  411. }
  412. return s
  413. }
  414. // StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid.
  415. func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
  416. lacp, ok := StringToBondXmitHashPolicyMap[s]
  417. if !ok {
  418. return BOND_XMIT_HASH_POLICY_UNKNOWN
  419. }
  420. return lacp
  421. }
  422. // Possible BondXmitHashPolicy value
  423. const (
  424. BOND_XMIT_HASH_POLICY_LAYER2 BondXmitHashPolicy = iota
  425. BOND_XMIT_HASH_POLICY_LAYER3_4
  426. BOND_XMIT_HASH_POLICY_LAYER2_3
  427. BOND_XMIT_HASH_POLICY_ENCAP2_3
  428. BOND_XMIT_HASH_POLICY_ENCAP3_4
  429. BOND_XMIT_HASH_POLICY_UNKNOWN
  430. )
  431. var bondXmitHashPolicyToString = map[BondXmitHashPolicy]string{
  432. BOND_XMIT_HASH_POLICY_LAYER2: "layer2",
  433. BOND_XMIT_HASH_POLICY_LAYER3_4: "layer3+4",
  434. BOND_XMIT_HASH_POLICY_LAYER2_3: "layer2+3",
  435. BOND_XMIT_HASH_POLICY_ENCAP2_3: "encap2+3",
  436. BOND_XMIT_HASH_POLICY_ENCAP3_4: "encap3+4",
  437. }
  438. var StringToBondXmitHashPolicyMap = map[string]BondXmitHashPolicy{
  439. "layer2": BOND_XMIT_HASH_POLICY_LAYER2,
  440. "layer3+4": BOND_XMIT_HASH_POLICY_LAYER3_4,
  441. "layer2+3": BOND_XMIT_HASH_POLICY_LAYER2_3,
  442. "encap2+3": BOND_XMIT_HASH_POLICY_ENCAP2_3,
  443. "encap3+4": BOND_XMIT_HASH_POLICY_ENCAP3_4,
  444. }
  445. // BondLacpRate type
  446. type BondLacpRate int
  447. func (b BondLacpRate) String() string {
  448. s, ok := bondLacpRateToString[b]
  449. if !ok {
  450. return fmt.Sprintf("LacpRate(%d)", b)
  451. }
  452. return s
  453. }
  454. // StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid.
  455. func StringToBondLacpRate(s string) BondLacpRate {
  456. lacp, ok := StringToBondLacpRateMap[s]
  457. if !ok {
  458. return BOND_LACP_RATE_UNKNOWN
  459. }
  460. return lacp
  461. }
  462. // Possible BondLacpRate value
  463. const (
  464. BOND_LACP_RATE_SLOW BondLacpRate = iota
  465. BOND_LACP_RATE_FAST
  466. BOND_LACP_RATE_UNKNOWN
  467. )
  468. var bondLacpRateToString = map[BondLacpRate]string{
  469. BOND_LACP_RATE_SLOW: "slow",
  470. BOND_LACP_RATE_FAST: "fast",
  471. }
  472. var StringToBondLacpRateMap = map[string]BondLacpRate{
  473. "slow": BOND_LACP_RATE_SLOW,
  474. "fast": BOND_LACP_RATE_FAST,
  475. }
  476. // BondAdSelect type
  477. type BondAdSelect int
  478. // Possible BondAdSelect value
  479. const (
  480. BOND_AD_SELECT_STABLE BondAdSelect = iota
  481. BOND_AD_SELECT_BANDWIDTH
  482. BOND_AD_SELECT_COUNT
  483. )
  484. // BondAdInfo represents ad info for bond
  485. type BondAdInfo struct {
  486. AggregatorId int
  487. NumPorts int
  488. ActorKey int
  489. PartnerKey int
  490. PartnerMac net.HardwareAddr
  491. }
  492. // Bond representation
  493. type Bond struct {
  494. LinkAttrs
  495. Mode BondMode
  496. ActiveSlave int
  497. Miimon int
  498. UpDelay int
  499. DownDelay int
  500. UseCarrier int
  501. ArpInterval int
  502. ArpIpTargets []net.IP
  503. ArpValidate BondArpValidate
  504. ArpAllTargets BondArpAllTargets
  505. Primary int
  506. PrimaryReselect BondPrimaryReselect
  507. FailOverMac BondFailOverMac
  508. XmitHashPolicy BondXmitHashPolicy
  509. ResendIgmp int
  510. NumPeerNotif int
  511. AllSlavesActive int
  512. MinLinks int
  513. LpInterval int
  514. PackersPerSlave int
  515. LacpRate BondLacpRate
  516. AdSelect BondAdSelect
  517. // looking at iproute tool AdInfo can only be retrived. It can't be set.
  518. AdInfo *BondAdInfo
  519. AdActorSysPrio int
  520. AdUserPortKey int
  521. AdActorSystem net.HardwareAddr
  522. TlbDynamicLb int
  523. }
  524. func NewLinkBond(atr LinkAttrs) *Bond {
  525. return &Bond{
  526. LinkAttrs: atr,
  527. Mode: -1,
  528. ActiveSlave: -1,
  529. Miimon: -1,
  530. UpDelay: -1,
  531. DownDelay: -1,
  532. UseCarrier: -1,
  533. ArpInterval: -1,
  534. ArpIpTargets: nil,
  535. ArpValidate: -1,
  536. ArpAllTargets: -1,
  537. Primary: -1,
  538. PrimaryReselect: -1,
  539. FailOverMac: -1,
  540. XmitHashPolicy: -1,
  541. ResendIgmp: -1,
  542. NumPeerNotif: -1,
  543. AllSlavesActive: -1,
  544. MinLinks: -1,
  545. LpInterval: -1,
  546. PackersPerSlave: -1,
  547. LacpRate: -1,
  548. AdSelect: -1,
  549. AdActorSysPrio: -1,
  550. AdUserPortKey: -1,
  551. AdActorSystem: nil,
  552. TlbDynamicLb: -1,
  553. }
  554. }
  555. // Flag mask for bond options. Bond.Flagmask must be set to on for option to work.
  556. const (
  557. BOND_MODE_MASK uint64 = 1 << (1 + iota)
  558. BOND_ACTIVE_SLAVE_MASK
  559. BOND_MIIMON_MASK
  560. BOND_UPDELAY_MASK
  561. BOND_DOWNDELAY_MASK
  562. BOND_USE_CARRIER_MASK
  563. BOND_ARP_INTERVAL_MASK
  564. BOND_ARP_VALIDATE_MASK
  565. BOND_ARP_ALL_TARGETS_MASK
  566. BOND_PRIMARY_MASK
  567. BOND_PRIMARY_RESELECT_MASK
  568. BOND_FAIL_OVER_MAC_MASK
  569. BOND_XMIT_HASH_POLICY_MASK
  570. BOND_RESEND_IGMP_MASK
  571. BOND_NUM_PEER_NOTIF_MASK
  572. BOND_ALL_SLAVES_ACTIVE_MASK
  573. BOND_MIN_LINKS_MASK
  574. BOND_LP_INTERVAL_MASK
  575. BOND_PACKETS_PER_SLAVE_MASK
  576. BOND_LACP_RATE_MASK
  577. BOND_AD_SELECT_MASK
  578. )
  579. // Attrs implementation.
  580. func (bond *Bond) Attrs() *LinkAttrs {
  581. return &bond.LinkAttrs
  582. }
  583. // Type implementation fro Vxlan.
  584. func (bond *Bond) Type() string {
  585. return "bond"
  586. }
  587. // Gretap devices must specify LocalIP and RemoteIP on create
  588. type Gretap struct {
  589. LinkAttrs
  590. IKey uint32
  591. OKey uint32
  592. EncapSport uint16
  593. EncapDport uint16
  594. Local net.IP
  595. Remote net.IP
  596. IFlags uint16
  597. OFlags uint16
  598. PMtuDisc uint8
  599. Ttl uint8
  600. Tos uint8
  601. EncapType uint16
  602. EncapFlags uint16
  603. Link uint32
  604. FlowBased bool
  605. }
  606. func (gretap *Gretap) Attrs() *LinkAttrs {
  607. return &gretap.LinkAttrs
  608. }
  609. func (gretap *Gretap) Type() string {
  610. return "gretap"
  611. }
  612. type Iptun struct {
  613. LinkAttrs
  614. Ttl uint8
  615. Tos uint8
  616. PMtuDisc uint8
  617. Link uint32
  618. Local net.IP
  619. Remote net.IP
  620. }
  621. func (iptun *Iptun) Attrs() *LinkAttrs {
  622. return &iptun.LinkAttrs
  623. }
  624. func (iptun *Iptun) Type() string {
  625. return "ipip"
  626. }
  627. type Vti struct {
  628. LinkAttrs
  629. IKey uint32
  630. OKey uint32
  631. Link uint32
  632. Local net.IP
  633. Remote net.IP
  634. }
  635. func (vti *Vti) Attrs() *LinkAttrs {
  636. return &vti.LinkAttrs
  637. }
  638. func (iptun *Vti) Type() string {
  639. return "vti"
  640. }
  641. type Vrf struct {
  642. LinkAttrs
  643. Table uint32
  644. }
  645. func (vrf *Vrf) Attrs() *LinkAttrs {
  646. return &vrf.LinkAttrs
  647. }
  648. func (vrf *Vrf) Type() string {
  649. return "vrf"
  650. }
  651. type GTP struct {
  652. LinkAttrs
  653. FD0 int
  654. FD1 int
  655. Role int
  656. PDPHashsize int
  657. }
  658. func (gtp *GTP) Attrs() *LinkAttrs {
  659. return &gtp.LinkAttrs
  660. }
  661. func (gtp *GTP) Type() string {
  662. return "gtp"
  663. }
  664. // iproute2 supported devices;
  665. // vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
  666. // bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
  667. // gre | gretap | ip6gre | ip6gretap | vti | nlmon |
  668. // bond_slave | ipvlan
  669. // LinkNotFoundError wraps the various not found errors when
  670. // getting/reading links. This is intended for better error
  671. // handling by dependent code so that "not found error" can
  672. // be distinguished from other errors
  673. type LinkNotFoundError struct {
  674. error
  675. }