link.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. }
  161. // Device links cannot be created via netlink. These links
  162. // are links created by udev like 'lo' and 'etho0'
  163. type Device struct {
  164. LinkAttrs
  165. }
  166. func (device *Device) Attrs() *LinkAttrs {
  167. return &device.LinkAttrs
  168. }
  169. func (device *Device) Type() string {
  170. return "device"
  171. }
  172. // Dummy links are dummy ethernet devices
  173. type Dummy struct {
  174. LinkAttrs
  175. }
  176. func (dummy *Dummy) Attrs() *LinkAttrs {
  177. return &dummy.LinkAttrs
  178. }
  179. func (dummy *Dummy) Type() string {
  180. return "dummy"
  181. }
  182. // Ifb links are advanced dummy devices for packet filtering
  183. type Ifb struct {
  184. LinkAttrs
  185. }
  186. func (ifb *Ifb) Attrs() *LinkAttrs {
  187. return &ifb.LinkAttrs
  188. }
  189. func (ifb *Ifb) Type() string {
  190. return "ifb"
  191. }
  192. // Bridge links are simple linux bridges
  193. type Bridge struct {
  194. LinkAttrs
  195. }
  196. func (bridge *Bridge) Attrs() *LinkAttrs {
  197. return &bridge.LinkAttrs
  198. }
  199. func (bridge *Bridge) Type() string {
  200. return "bridge"
  201. }
  202. // Vlan links have ParentIndex set in their Attrs()
  203. type Vlan struct {
  204. LinkAttrs
  205. VlanId int
  206. }
  207. func (vlan *Vlan) Attrs() *LinkAttrs {
  208. return &vlan.LinkAttrs
  209. }
  210. func (vlan *Vlan) Type() string {
  211. return "vlan"
  212. }
  213. type MacvlanMode uint16
  214. const (
  215. MACVLAN_MODE_DEFAULT MacvlanMode = iota
  216. MACVLAN_MODE_PRIVATE
  217. MACVLAN_MODE_VEPA
  218. MACVLAN_MODE_BRIDGE
  219. MACVLAN_MODE_PASSTHRU
  220. MACVLAN_MODE_SOURCE
  221. )
  222. // Macvlan links have ParentIndex set in their Attrs()
  223. type Macvlan struct {
  224. LinkAttrs
  225. Mode MacvlanMode
  226. }
  227. func (macvlan *Macvlan) Attrs() *LinkAttrs {
  228. return &macvlan.LinkAttrs
  229. }
  230. func (macvlan *Macvlan) Type() string {
  231. return "macvlan"
  232. }
  233. // Macvtap - macvtap is a virtual interfaces based on macvlan
  234. type Macvtap struct {
  235. Macvlan
  236. }
  237. func (macvtap Macvtap) Type() string {
  238. return "macvtap"
  239. }
  240. type TuntapMode uint16
  241. type TuntapFlag uint16
  242. // Tuntap links created via /dev/tun/tap, but can be destroyed via netlink
  243. type Tuntap struct {
  244. LinkAttrs
  245. Mode TuntapMode
  246. Flags TuntapFlag
  247. }
  248. func (tuntap *Tuntap) Attrs() *LinkAttrs {
  249. return &tuntap.LinkAttrs
  250. }
  251. func (tuntap *Tuntap) Type() string {
  252. return "tuntap"
  253. }
  254. // Veth devices must specify PeerName on create
  255. type Veth struct {
  256. LinkAttrs
  257. PeerName string // veth on create only
  258. }
  259. func (veth *Veth) Attrs() *LinkAttrs {
  260. return &veth.LinkAttrs
  261. }
  262. func (veth *Veth) Type() string {
  263. return "veth"
  264. }
  265. // GenericLink links represent types that are not currently understood
  266. // by this netlink library.
  267. type GenericLink struct {
  268. LinkAttrs
  269. LinkType string
  270. }
  271. func (generic *GenericLink) Attrs() *LinkAttrs {
  272. return &generic.LinkAttrs
  273. }
  274. func (generic *GenericLink) Type() string {
  275. return generic.LinkType
  276. }
  277. type Vxlan struct {
  278. LinkAttrs
  279. VxlanId int
  280. VtepDevIndex int
  281. SrcAddr net.IP
  282. Group net.IP
  283. TTL int
  284. TOS int
  285. Learning bool
  286. Proxy bool
  287. RSC bool
  288. L2miss bool
  289. L3miss bool
  290. UDPCSum bool
  291. NoAge bool
  292. GBP bool
  293. Age int
  294. Limit int
  295. Port int
  296. PortLow int
  297. PortHigh int
  298. }
  299. func (vxlan *Vxlan) Attrs() *LinkAttrs {
  300. return &vxlan.LinkAttrs
  301. }
  302. func (vxlan *Vxlan) Type() string {
  303. return "vxlan"
  304. }
  305. type IPVlanMode uint16
  306. const (
  307. IPVLAN_MODE_L2 IPVlanMode = iota
  308. IPVLAN_MODE_L3
  309. IPVLAN_MODE_L3S
  310. IPVLAN_MODE_MAX
  311. )
  312. type IPVlan struct {
  313. LinkAttrs
  314. Mode IPVlanMode
  315. }
  316. func (ipvlan *IPVlan) Attrs() *LinkAttrs {
  317. return &ipvlan.LinkAttrs
  318. }
  319. func (ipvlan *IPVlan) Type() string {
  320. return "ipvlan"
  321. }
  322. // BondMode type
  323. type BondMode int
  324. func (b BondMode) String() string {
  325. s, ok := bondModeToString[b]
  326. if !ok {
  327. return fmt.Sprintf("BondMode(%d)", b)
  328. }
  329. return s
  330. }
  331. // StringToBondMode returns bond mode, or uknonw is the s is invalid.
  332. func StringToBondMode(s string) BondMode {
  333. mode, ok := StringToBondModeMap[s]
  334. if !ok {
  335. return BOND_MODE_UNKNOWN
  336. }
  337. return mode
  338. }
  339. // Possible BondMode
  340. const (
  341. BOND_MODE_BALANCE_RR BondMode = iota
  342. BOND_MODE_ACTIVE_BACKUP
  343. BOND_MODE_BALANCE_XOR
  344. BOND_MODE_BROADCAST
  345. BOND_MODE_802_3AD
  346. BOND_MODE_BALANCE_TLB
  347. BOND_MODE_BALANCE_ALB
  348. BOND_MODE_UNKNOWN
  349. )
  350. var bondModeToString = map[BondMode]string{
  351. BOND_MODE_BALANCE_RR: "balance-rr",
  352. BOND_MODE_ACTIVE_BACKUP: "active-backup",
  353. BOND_MODE_BALANCE_XOR: "balance-xor",
  354. BOND_MODE_BROADCAST: "broadcast",
  355. BOND_MODE_802_3AD: "802.3ad",
  356. BOND_MODE_BALANCE_TLB: "balance-tlb",
  357. BOND_MODE_BALANCE_ALB: "balance-alb",
  358. }
  359. var StringToBondModeMap = map[string]BondMode{
  360. "balance-rr": BOND_MODE_BALANCE_RR,
  361. "active-backup": BOND_MODE_ACTIVE_BACKUP,
  362. "balance-xor": BOND_MODE_BALANCE_XOR,
  363. "broadcast": BOND_MODE_BROADCAST,
  364. "802.3ad": BOND_MODE_802_3AD,
  365. "balance-tlb": BOND_MODE_BALANCE_TLB,
  366. "balance-alb": BOND_MODE_BALANCE_ALB,
  367. }
  368. // BondArpValidate type
  369. type BondArpValidate int
  370. // Possible BondArpValidate value
  371. const (
  372. BOND_ARP_VALIDATE_NONE BondArpValidate = iota
  373. BOND_ARP_VALIDATE_ACTIVE
  374. BOND_ARP_VALIDATE_BACKUP
  375. BOND_ARP_VALIDATE_ALL
  376. )
  377. // BondPrimaryReselect type
  378. type BondPrimaryReselect int
  379. // Possible BondPrimaryReselect value
  380. const (
  381. BOND_PRIMARY_RESELECT_ALWAYS BondPrimaryReselect = iota
  382. BOND_PRIMARY_RESELECT_BETTER
  383. BOND_PRIMARY_RESELECT_FAILURE
  384. )
  385. // BondArpAllTargets type
  386. type BondArpAllTargets int
  387. // Possible BondArpAllTargets value
  388. const (
  389. BOND_ARP_ALL_TARGETS_ANY BondArpAllTargets = iota
  390. BOND_ARP_ALL_TARGETS_ALL
  391. )
  392. // BondFailOverMac type
  393. type BondFailOverMac int
  394. // Possible BondFailOverMac value
  395. const (
  396. BOND_FAIL_OVER_MAC_NONE BondFailOverMac = iota
  397. BOND_FAIL_OVER_MAC_ACTIVE
  398. BOND_FAIL_OVER_MAC_FOLLOW
  399. )
  400. // BondXmitHashPolicy type
  401. type BondXmitHashPolicy int
  402. func (b BondXmitHashPolicy) String() string {
  403. s, ok := bondXmitHashPolicyToString[b]
  404. if !ok {
  405. return fmt.Sprintf("XmitHashPolicy(%d)", b)
  406. }
  407. return s
  408. }
  409. // StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid.
  410. func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
  411. lacp, ok := StringToBondXmitHashPolicyMap[s]
  412. if !ok {
  413. return BOND_XMIT_HASH_POLICY_UNKNOWN
  414. }
  415. return lacp
  416. }
  417. // Possible BondXmitHashPolicy value
  418. const (
  419. BOND_XMIT_HASH_POLICY_LAYER2 BondXmitHashPolicy = iota
  420. BOND_XMIT_HASH_POLICY_LAYER3_4
  421. BOND_XMIT_HASH_POLICY_LAYER2_3
  422. BOND_XMIT_HASH_POLICY_ENCAP2_3
  423. BOND_XMIT_HASH_POLICY_ENCAP3_4
  424. BOND_XMIT_HASH_POLICY_UNKNOWN
  425. )
  426. var bondXmitHashPolicyToString = map[BondXmitHashPolicy]string{
  427. BOND_XMIT_HASH_POLICY_LAYER2: "layer2",
  428. BOND_XMIT_HASH_POLICY_LAYER3_4: "layer3+4",
  429. BOND_XMIT_HASH_POLICY_LAYER2_3: "layer2+3",
  430. BOND_XMIT_HASH_POLICY_ENCAP2_3: "encap2+3",
  431. BOND_XMIT_HASH_POLICY_ENCAP3_4: "encap3+4",
  432. }
  433. var StringToBondXmitHashPolicyMap = map[string]BondXmitHashPolicy{
  434. "layer2": BOND_XMIT_HASH_POLICY_LAYER2,
  435. "layer3+4": BOND_XMIT_HASH_POLICY_LAYER3_4,
  436. "layer2+3": BOND_XMIT_HASH_POLICY_LAYER2_3,
  437. "encap2+3": BOND_XMIT_HASH_POLICY_ENCAP2_3,
  438. "encap3+4": BOND_XMIT_HASH_POLICY_ENCAP3_4,
  439. }
  440. // BondLacpRate type
  441. type BondLacpRate int
  442. func (b BondLacpRate) String() string {
  443. s, ok := bondLacpRateToString[b]
  444. if !ok {
  445. return fmt.Sprintf("LacpRate(%d)", b)
  446. }
  447. return s
  448. }
  449. // StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid.
  450. func StringToBondLacpRate(s string) BondLacpRate {
  451. lacp, ok := StringToBondLacpRateMap[s]
  452. if !ok {
  453. return BOND_LACP_RATE_UNKNOWN
  454. }
  455. return lacp
  456. }
  457. // Possible BondLacpRate value
  458. const (
  459. BOND_LACP_RATE_SLOW BondLacpRate = iota
  460. BOND_LACP_RATE_FAST
  461. BOND_LACP_RATE_UNKNOWN
  462. )
  463. var bondLacpRateToString = map[BondLacpRate]string{
  464. BOND_LACP_RATE_SLOW: "slow",
  465. BOND_LACP_RATE_FAST: "fast",
  466. }
  467. var StringToBondLacpRateMap = map[string]BondLacpRate{
  468. "slow": BOND_LACP_RATE_SLOW,
  469. "fast": BOND_LACP_RATE_FAST,
  470. }
  471. // BondAdSelect type
  472. type BondAdSelect int
  473. // Possible BondAdSelect value
  474. const (
  475. BOND_AD_SELECT_STABLE BondAdSelect = iota
  476. BOND_AD_SELECT_BANDWIDTH
  477. BOND_AD_SELECT_COUNT
  478. )
  479. // BondAdInfo represents ad info for bond
  480. type BondAdInfo struct {
  481. AggregatorId int
  482. NumPorts int
  483. ActorKey int
  484. PartnerKey int
  485. PartnerMac net.HardwareAddr
  486. }
  487. // Bond representation
  488. type Bond struct {
  489. LinkAttrs
  490. Mode BondMode
  491. ActiveSlave int
  492. Miimon int
  493. UpDelay int
  494. DownDelay int
  495. UseCarrier int
  496. ArpInterval int
  497. ArpIpTargets []net.IP
  498. ArpValidate BondArpValidate
  499. ArpAllTargets BondArpAllTargets
  500. Primary int
  501. PrimaryReselect BondPrimaryReselect
  502. FailOverMac BondFailOverMac
  503. XmitHashPolicy BondXmitHashPolicy
  504. ResendIgmp int
  505. NumPeerNotif int
  506. AllSlavesActive int
  507. MinLinks int
  508. LpInterval int
  509. PackersPerSlave int
  510. LacpRate BondLacpRate
  511. AdSelect BondAdSelect
  512. // looking at iproute tool AdInfo can only be retrived. It can't be set.
  513. AdInfo *BondAdInfo
  514. }
  515. func NewLinkBond(atr LinkAttrs) *Bond {
  516. return &Bond{
  517. LinkAttrs: atr,
  518. Mode: -1,
  519. ActiveSlave: -1,
  520. Miimon: -1,
  521. UpDelay: -1,
  522. DownDelay: -1,
  523. UseCarrier: -1,
  524. ArpInterval: -1,
  525. ArpIpTargets: nil,
  526. ArpValidate: -1,
  527. ArpAllTargets: -1,
  528. Primary: -1,
  529. PrimaryReselect: -1,
  530. FailOverMac: -1,
  531. XmitHashPolicy: -1,
  532. ResendIgmp: -1,
  533. NumPeerNotif: -1,
  534. AllSlavesActive: -1,
  535. MinLinks: -1,
  536. LpInterval: -1,
  537. PackersPerSlave: -1,
  538. LacpRate: -1,
  539. AdSelect: -1,
  540. }
  541. }
  542. // Flag mask for bond options. Bond.Flagmask must be set to on for option to work.
  543. const (
  544. BOND_MODE_MASK uint64 = 1 << (1 + iota)
  545. BOND_ACTIVE_SLAVE_MASK
  546. BOND_MIIMON_MASK
  547. BOND_UPDELAY_MASK
  548. BOND_DOWNDELAY_MASK
  549. BOND_USE_CARRIER_MASK
  550. BOND_ARP_INTERVAL_MASK
  551. BOND_ARP_VALIDATE_MASK
  552. BOND_ARP_ALL_TARGETS_MASK
  553. BOND_PRIMARY_MASK
  554. BOND_PRIMARY_RESELECT_MASK
  555. BOND_FAIL_OVER_MAC_MASK
  556. BOND_XMIT_HASH_POLICY_MASK
  557. BOND_RESEND_IGMP_MASK
  558. BOND_NUM_PEER_NOTIF_MASK
  559. BOND_ALL_SLAVES_ACTIVE_MASK
  560. BOND_MIN_LINKS_MASK
  561. BOND_LP_INTERVAL_MASK
  562. BOND_PACKETS_PER_SLAVE_MASK
  563. BOND_LACP_RATE_MASK
  564. BOND_AD_SELECT_MASK
  565. )
  566. // Attrs implementation.
  567. func (bond *Bond) Attrs() *LinkAttrs {
  568. return &bond.LinkAttrs
  569. }
  570. // Type implementation fro Vxlan.
  571. func (bond *Bond) Type() string {
  572. return "bond"
  573. }
  574. // Gretap devices must specify LocalIP and RemoteIP on create
  575. type Gretap struct {
  576. LinkAttrs
  577. IKey uint32
  578. OKey uint32
  579. EncapSport uint16
  580. EncapDport uint16
  581. Local net.IP
  582. Remote net.IP
  583. IFlags uint16
  584. OFlags uint16
  585. PMtuDisc uint8
  586. Ttl uint8
  587. Tos uint8
  588. EncapType uint16
  589. EncapFlags uint16
  590. Link uint32
  591. }
  592. func (gretap *Gretap) Attrs() *LinkAttrs {
  593. return &gretap.LinkAttrs
  594. }
  595. func (gretap *Gretap) Type() string {
  596. return "gretap"
  597. }
  598. type Iptun struct {
  599. LinkAttrs
  600. Ttl uint8
  601. Tos uint8
  602. PMtuDisc uint8
  603. Link uint32
  604. Local net.IP
  605. Remote net.IP
  606. }
  607. func (iptun *Iptun) Attrs() *LinkAttrs {
  608. return &iptun.LinkAttrs
  609. }
  610. func (iptun *Iptun) Type() string {
  611. return "ipip"
  612. }
  613. type Vti struct {
  614. LinkAttrs
  615. IKey uint32
  616. OKey uint32
  617. Link uint32
  618. Local net.IP
  619. Remote net.IP
  620. }
  621. func (vti *Vti) Attrs() *LinkAttrs {
  622. return &vti.LinkAttrs
  623. }
  624. func (iptun *Vti) Type() string {
  625. return "vti"
  626. }
  627. type Vrf struct {
  628. LinkAttrs
  629. Table uint32
  630. }
  631. func (vrf *Vrf) Attrs() *LinkAttrs {
  632. return &vrf.LinkAttrs
  633. }
  634. func (vrf *Vrf) Type() string {
  635. return "vrf"
  636. }
  637. // iproute2 supported devices;
  638. // vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
  639. // bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
  640. // gre | gretap | ip6gre | ip6gretap | vti | nlmon |
  641. // bond_slave | ipvlan