1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
|
package driver
import (
"fmt"
"net"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/jsimonetti/rtnetlink/v2/internal/unix"
"github.com/mdlayher/netlink"
)
// BondMode specifies one of the bonding policies.
type BondMode uint8
const (
// Round-robin policy: Transmit packets in sequential order from the first available slave through the last
// This is the default value
BondModeBalanceRR BondMode = iota
// Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if,
// the active slave fails. The bond’s MAC address is externally visible on only one port (network adapter) to
// avoid confusing the switch.
BondModeActiveBackup
// XOR policy: Transmit based on the selected transmit hash policy.
// The default policy is BOND_XMIT_HASH_POLICY_LAYER2
// Alternate transmit policies may be selected via the XmitHashPolicy option
BondModeBalanceXOR
// Broadcast policy: transmits everything on all slave interfaces
BondModeBroadcast
// IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings.
// Utilizes all slaves in the active aggregator according to the 802.3ad specification
BondMode802_3AD
// Adaptive transmit load balancing: channel bonding that does not require any special switch support
// Outgoing traffic is configured by TlbDynamicLb field
// Incoming traffic is received by the current slave. If the receiving slave fails,
// another slave takes over the MAC address of the failed receiving slave.
BondModeBalanceTLB
// Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic,
// and does not require any special switch support
BondModeBalanceALB
BondModeUnknown
)
func (b BondMode) String() string {
switch b {
case BondModeBalanceRR:
return "balance-rr"
case BondModeActiveBackup:
return "active-backup"
case BondModeBalanceXOR:
return "balance-xor"
case BondModeBroadcast:
return "broadcast"
case BondMode802_3AD:
return "802.3ad"
case BondModeBalanceTLB:
return "balance-tld"
case BondModeBalanceALB:
return "balance-alb"
default:
return fmt.Sprintf("unknown BondMode value (%d)", b)
}
}
// BondArpValidate specifies whether or not ARP probes and replies should be validated in any mode that
// supports arp monitoring, or whether non-ARP traffic should be filtered (disregarded) for link monitoring purposes.
type BondArpValidate uint32
const (
// No validation or filtering is performed
BondArpValidateNone BondArpValidate = iota
// Validation is performed only for the active slave
BondArpValidateActive
// Validation is performed only for backup slaves
BondArpValidateBackup
// Validation is performed for all slaves
BondArpValidateAll
// Filtering is applied to all slaves. No validation is performed
BondArpValidateFilter
// Filtering is applied to all slaves, validation is performed only for the active slave
BondArpValidateFilterActive
// Filtering is applied to all slaves, validation is performed only for backup slaves
BondArpValidateFilterBackup
)
func (b BondArpValidate) String() string {
switch b {
case BondArpValidateNone:
return "none"
case BondArpValidateActive:
return "active"
case BondArpValidateBackup:
return "backup"
case BondArpValidateAll:
return "all"
case BondArpValidateFilter:
return "filter"
case BondArpValidateFilterActive:
return "filter_active"
case BondArpValidateFilterBackup:
return "filter_backup"
default:
return fmt.Sprintf("unknown BondArpValidate value (%d)", b)
}
}
// BondArpAllTargets specifies the quantity of arp_ip_targets that must be reachable in order for the ARP monitor
// to consider a slave as being up. This option affects only active-backup mode for slaves with arp_validation enabled.
type BondArpAllTargets uint32
const (
// Consider the slave up only when any of the arp_ip_targets is reachable
BondArpAllTargetsAny BondArpAllTargets = iota
// Consider the slave up only when all of the arp_ip_targets are reachable
BondArpAllTargetsAll
)
func (b BondArpAllTargets) String() string {
switch b {
case BondArpAllTargetsAny:
return "any"
case BondArpAllTargetsAll:
return "all"
default:
return fmt.Sprintf("unknown BondArpAllTargets value (%d)", b)
}
}
// Specifies the reselection policy for the primary slave. This affects how the primary slave is
// chosen to become the active slave when failure of the active slave or recovery of the primary slave occurs.
// This option is designed to prevent flip-flopping between the primary slave and other slaves
type BondPrimaryReselect uint8
const (
// The primary slave becomes the active slave whenever it comes back up, this is the default value
BondPrimaryReselectAlways BondPrimaryReselect = iota
// The primary slave becomes the active slave when it comes back up,
// if the speed and duplex of the primary slave is better than the speed and duplex of the current active slave
BondPrimaryReselectBetter
// The primary slave becomes the active slave only if the current active slave fails and the primary slave is up
BondPrimaryReselectFailure
)
func (b BondPrimaryReselect) String() string {
switch b {
case BondPrimaryReselectAlways:
return "always"
case BondPrimaryReselectBetter:
return "better"
case BondPrimaryReselectFailure:
return "failure"
default:
return fmt.Sprintf("unknown BondPrimaryReselect value (%d)", b)
}
}
// BondFailOverMac specifies whether active-backup mode should set all slaves to the same MAC address at enslavement
// (the traditional behavior), or, when enabled, perform special handling of the bond’s MAC address
// in accordance with the selected policy.
type BondFailOverMac uint8
const (
// This setting disables fail_over_mac, and causes bonding to set all slaves of an active-backup bond
// to the same MAC address at enslavement time
BondFailOverMacNone BondFailOverMac = iota
// The “active” fail_over_mac policy indicates that the MAC address of the bond should always be
// the MAC address of the currently active slave. The MAC address of the slaves is not changed;
// instead, the MAC address of the bond changes during a failover
BondFailOverMacActive
// The “follow” fail_over_mac policy causes the MAC address of the bond to be selected normally
// (normally the MAC address of the first slave added to the bond)
// However, the second and subsequent slaves are not set to this MAC address while they are in a backup role;
// a slave is programmed with the bond’s MAC address at failover time
// (and the formerly active slave receives the newly active slave’s MAC address)
BondFailOverMacFollow
)
func (b BondFailOverMac) String() string {
switch b {
case BondFailOverMacNone:
return "none"
case BondFailOverMacActive:
return "active"
case BondFailOverMacFollow:
return "follow"
default:
return fmt.Sprintf("unknown BondPrimaryReselect value (%d)", b)
}
}
// BondXmitHashPolicy specifies the transmit hash policy to use for
// slave selection in balance-xor, 802.3ad, and tlb modes.
type BondXmitHashPolicy uint8
const (
// Uses XOR of hardware MAC addresses and packet type ID field to generate the hash
BondXmitHashPolicyLayer2 BondXmitHashPolicy = iota
// This policy uses upper layer protocol information, when available, to generate the hash
// This allows for traffic to a particular network peer to span multiple slaves,
// although a single connection will not span multiple slaves
BondXmitHashPolicyLayer3_4
// This policy uses a combination of layer2 and layer3 protocol information to generate the hash
// Uses XOR of hardware MAC addresses and IP addresses to generate the hash
BondXmitHashPolicyLayer2_3
// This policy uses the same formula as layer2+3 but it relies on skb_flow_dissect to obtain
// the header fields which might result in the use of inner headers if an encapsulation protocol is used
BondXmitHashPolicyEncap2_3
// This policy uses the same formula as layer3+4 but it relies on skb_flow_dissect to obtain
// the header fields which might result in the use of inner headers if an encapsulation protocol is used
BondXmitHashPolicyEncap3_4
// This policy uses a very rudimentary vlan ID and source mac hash to load-balance traffic per-vlan,
// with failover should one leg fail
BondXmitHashPolicyVlanSrcMAC
)
func (b BondXmitHashPolicy) String() string {
switch b {
case BondXmitHashPolicyLayer2:
return "layer2"
case BondXmitHashPolicyLayer3_4:
return "layer3+4"
case BondXmitHashPolicyLayer2_3:
return "layer2+3"
case BondXmitHashPolicyEncap2_3:
return "encap2+3"
case BondXmitHashPolicyEncap3_4:
return "encap3+4"
case BondXmitHashPolicyVlanSrcMAC:
return "vlan+srcmac"
default:
return fmt.Sprintf("unknown BondXmitHashPolicy value (%d)", b)
}
}
// BondAdLacpActive specifies whether to send LACPDU frames periodically.
type BondAdLacpActive uint8
const (
// LACPDU frames acts as “speak when spoken to”
BondAdLacpActiveOff BondAdLacpActive = iota
// LACPDU frames are sent along the configured links periodically with the rate configured with BondLacpRate
// This is the default value
BondAdLacpActiveOn
)
func (b BondAdLacpActive) String() string {
switch b {
case BondAdLacpActiveOff:
return "off"
case BondAdLacpActiveOn:
return "on"
default:
return fmt.Sprintf("unknown BondLacpActive value (%d)", b)
}
}
// Option specifying the rate in which we’ll ask our link partner to transmit LACPDU packets in 802.3ad mode.
type BondLacpRate uint8
const (
// Request partner to transmit LACPDUs every 30 seconds
// This is the default value
BondLacpRateSlow BondLacpRate = iota
// Request partner to transmit LACPDUs every 1 second
BondLacpRateFast
)
func (b BondLacpRate) String() string {
switch b {
case BondLacpRateSlow:
return "slow"
case BondLacpRateFast:
return "fast"
default:
return fmt.Sprintf("unknown BondLacpRate value (%d)", b)
}
}
// BondAdSelect specifies the 802.3ad aggregation selection logic to use.
type BondAdSelect uint8
const (
// The active aggregator is chosen by largest aggregate bandwidth
// Reselection of the active aggregator occurs only when all slaves of the active aggregator
// are down or the active aggregator has no slaves
// This is the default value.
BondAdSelectStable BondAdSelect = iota
// The active aggregator is chosen by largest aggregate bandwidth.
// Reselection occurs if:
// - A slave is added to or removed from the bond
// - Any slave’s link state changes
// - Any slave’s 802.3ad association state changes
// - The bond’s administrative state changes to up
BondAdSelectBandwidth
// The active aggregator is chosen by the largest number of ports (slaves)
// Reselection rules are the same with BOND_AD_SELECT_BANDWIDTH
BondAdSelectCount
)
func (b BondAdSelect) String() string {
switch b {
case BondAdSelectStable:
return "stable"
case BondAdSelectBandwidth:
return "bandwidth"
case BondAdSelectCount:
return "count"
default:
return fmt.Sprintf("unknown BondAdSelect value (%d)", b)
}
}
// BondAdInfo specifies the 802.3ad aggregation information
type BondAdInfo struct {
AggregatorId uint16
NumPorts uint16
ActorKey uint16
PartnerKey uint16
PartnerMac net.HardwareAddr
}
const bondMaxTargets = 16
// Bond implements LinkDriver for the bond driver
type Bond struct {
// For more detailed information see https://www.kernel.org/doc/html/latest/networking/bonding.html
// Specifies the bonding policy. The default is balance-rr (round robin)
Mode BondMode
// Specifies the new active slave for modes that support it (active-backup, balance-alb and balance-tlb)
ActiveSlave *uint32
// Specifies the MII link monitoring frequency in milliseconds
Miimon *uint32
// Specifies the time, in milliseconds, to wait before enabling a slave after a link recovery has been detected
UpDelay *uint32
// Specifies the time, in milliseconds, to wait before disabling a slave after a link failure has been detected
DownDelay *uint32
// Specify the delay, in milliseconds, between each peer notification
PeerNotifyDelay *uint32
// Specifies whether or not miimon should use MII or ETHTOOL
UseCarrier *uint8
// Specifies the ARP link monitoring frequency in milliseconds
ArpInterval *uint32
// Specifies the IP addresses to use as ARP monitoring peers when arp_interval is > 0
ArpIpTargets []net.IP
// Specifies the IPv6 addresses to use as IPv6 monitoring peers when arp_interval is > 0
NsIP6Targets []net.IP
// Specifies whether or not ARP probes and replies should be validated
ArpValidate *BondArpValidate
// Specifies the quantity of arp_ip_targets that must be reachable in order for the ARP monitor to consider a slave as being up
ArpAllTargets *BondArpAllTargets
// A device index specifying which slave is the primary device
Primary *uint32
// Specifies the reselection policy for the primary slave
PrimaryReselect *BondPrimaryReselect
// Specifies whether active-backup mode should set all slaves to the same MAC address at enslavement, when enabled, or perform special handling
FailOverMac *BondFailOverMac
// Selects the transmit hash policy to use for slave selection
XmitHashPolicy *BondXmitHashPolicy
// Specifies the number of IGMP membership reports to be issued after a failover event
ResendIgmp *uint32
// Specify the number of peer notifications (gratuitous ARPs and unsolicited IPv6 Neighbor Advertisements) to be issued after a failover event
NumPeerNotif *uint8
// Specifies that duplicate frames (received on inactive ports) should be dropped (0) or delivered (1)
AllSlavesActive *uint8
// Specifies the minimum number of links that must be active before asserting carrier
MinLinks *uint32
// Specifies the number of seconds between instances where the bonding driver sends learning packets to each slaves peer switch
LpInterval *uint32
// Specify the number of packets to transmit through a slave before moving to the next one
PacketsPerSlave *uint32
// Option specifying whether to send LACPDU frames periodically
AdLacpActive *BondAdLacpActive
// Option specifying the rate in which we’ll ask our link partner to transmit LACPDU packets
AdLacpRate *BondLacpRate
// Specifies the 802.3ad aggregation selection logic to use
AdSelect *BondAdSelect
// In an AD system, this specifies the system priority
AdActorSysPrio *uint16
// Defines the upper 10 bits of the port key
AdUserPortKey *uint16
// In an AD system, this specifies the mac-address for the actor in protocol packet exchanges
AdActorSystem net.HardwareAddr
// Specifies if dynamic shuffling of flows is enabled in tlb or alb mode
TlbDynamicLb *uint8
// Specifies the number of arp_interval monitor checks that must fail in order for an interface to be marked down by the ARP monitor
MissedMax *uint8
// Specifies the 802.3ad aggregation information, this is read only value
AdInfo *BondAdInfo
}
var _ rtnetlink.LinkDriver = &Bond{}
func (b *Bond) New() rtnetlink.LinkDriver {
return &Bond{}
}
func (b *Bond) Encode(ae *netlink.AttributeEncoder) error {
if b.Mode < BondModeUnknown {
ae.Uint8(unix.IFLA_BOND_MODE, uint8(b.Mode))
}
if b.ActiveSlave != nil {
ae.Uint32(unix.IFLA_BOND_ACTIVE_SLAVE, *b.ActiveSlave)
}
if b.Miimon != nil {
ae.Uint32(unix.IFLA_BOND_MIIMON, *b.Miimon)
}
if b.UpDelay != nil {
ae.Uint32(unix.IFLA_BOND_UPDELAY, *b.UpDelay)
}
if b.DownDelay != nil {
ae.Uint32(unix.IFLA_BOND_DOWNDELAY, *b.DownDelay)
}
if b.PeerNotifyDelay != nil {
ae.Uint32(unix.IFLA_BOND_PEER_NOTIF_DELAY, *b.PeerNotifyDelay)
}
if b.UseCarrier != nil {
ae.Uint8(unix.IFLA_BOND_USE_CARRIER, *b.UseCarrier)
}
if b.ArpInterval != nil {
ae.Uint32(unix.IFLA_BOND_ARP_INTERVAL, *b.ArpInterval)
}
if b.ArpIpTargets != nil {
if lb := len(b.ArpIpTargets); lb > bondMaxTargets {
return fmt.Errorf("exceeded max ArpIpTargets %d, %d", bondMaxTargets, lb)
}
ae.Nested(unix.IFLA_BOND_ARP_IP_TARGET, func(nae *netlink.AttributeEncoder) error {
for i := range b.ArpIpTargets {
ip := b.ArpIpTargets[i].To4()
if ip == nil {
return fmt.Errorf("%s is not an ip4 address", ip)
}
nae.Bytes(uint16(i), ip)
}
return nil
})
}
if b.NsIP6Targets != nil {
if lb := len(b.ArpIpTargets); lb > bondMaxTargets {
return fmt.Errorf("exceeded max NsIP6Targets %d, %d", bondMaxTargets, lb)
}
ae.Nested(unix.IFLA_BOND_NS_IP6_TARGET, func(nae *netlink.AttributeEncoder) error {
for i := range b.NsIP6Targets {
ip := b.NsIP6Targets[i].To16()
if ip == nil {
return fmt.Errorf("%s is not an ip6 address", ip)
}
nae.Bytes(uint16(i), ip)
}
return nil
})
}
if b.ArpValidate != nil {
ae.Uint32(unix.IFLA_BOND_ARP_VALIDATE, uint32(*b.ArpValidate))
}
if b.ArpAllTargets != nil {
ae.Uint32(unix.IFLA_BOND_ARP_ALL_TARGETS, uint32(*b.ArpAllTargets))
}
if b.Primary != nil {
ae.Uint32(unix.IFLA_BOND_PRIMARY, *b.Primary)
}
if b.PrimaryReselect != nil {
ae.Uint8(unix.IFLA_BOND_PRIMARY_RESELECT, uint8(*b.PrimaryReselect))
}
if b.FailOverMac != nil {
ae.Uint8(unix.IFLA_BOND_FAIL_OVER_MAC, uint8(*b.FailOverMac))
}
if b.XmitHashPolicy != nil {
ae.Uint8(unix.IFLA_BOND_XMIT_HASH_POLICY, uint8(*b.XmitHashPolicy))
}
if b.ResendIgmp != nil {
ae.Uint32(unix.IFLA_BOND_RESEND_IGMP, *b.ResendIgmp)
}
if b.NumPeerNotif != nil {
ae.Uint8(unix.IFLA_BOND_NUM_PEER_NOTIF, *b.NumPeerNotif)
}
if b.AllSlavesActive != nil {
ae.Uint8(unix.IFLA_BOND_ALL_SLAVES_ACTIVE, *b.AllSlavesActive)
}
if b.MinLinks != nil {
ae.Uint32(unix.IFLA_BOND_MIN_LINKS, *b.MinLinks)
}
if b.LpInterval != nil {
ae.Uint32(unix.IFLA_BOND_LP_INTERVAL, *b.LpInterval)
}
if b.PacketsPerSlave != nil {
ae.Uint32(unix.IFLA_BOND_PACKETS_PER_SLAVE, *b.PacketsPerSlave)
}
if b.AdLacpActive != nil {
ae.Uint8(unix.IFLA_BOND_AD_LACP_ACTIVE, uint8(*b.AdLacpActive))
}
if b.AdLacpRate != nil {
ae.Uint8(unix.IFLA_BOND_AD_LACP_RATE, uint8(*b.AdLacpRate))
}
if b.AdSelect != nil {
ae.Uint8(unix.IFLA_BOND_AD_SELECT, uint8(*b.AdSelect))
}
if b.AdActorSysPrio != nil {
ae.Uint16(unix.IFLA_BOND_AD_ACTOR_SYS_PRIO, *b.AdActorSysPrio)
}
if b.AdUserPortKey != nil {
ae.Uint16(unix.IFLA_BOND_AD_USER_PORT_KEY, *b.AdUserPortKey)
}
if b.AdActorSystem != nil {
ae.Bytes(unix.IFLA_BOND_AD_ACTOR_SYSTEM, []byte(b.AdActorSystem))
}
if b.TlbDynamicLb != nil {
ae.Uint8(unix.IFLA_BOND_TLB_DYNAMIC_LB, *b.TlbDynamicLb)
}
if b.MissedMax != nil {
ae.Uint8(unix.IFLA_BOND_MISSED_MAX, *b.MissedMax)
}
return nil
}
func (b *Bond) Decode(ad *netlink.AttributeDecoder) error {
for ad.Next() {
switch ad.Type() {
case unix.IFLA_BOND_MODE:
b.Mode = BondMode(ad.Uint8())
case unix.IFLA_BOND_ACTIVE_SLAVE:
v := ad.Uint32()
b.ActiveSlave = &v
case unix.IFLA_BOND_MIIMON:
v := ad.Uint32()
b.Miimon = &v
case unix.IFLA_BOND_UPDELAY:
v := ad.Uint32()
b.UpDelay = &v
case unix.IFLA_BOND_DOWNDELAY:
v := ad.Uint32()
b.DownDelay = &v
case unix.IFLA_BOND_PEER_NOTIF_DELAY:
v := ad.Uint32()
b.PeerNotifyDelay = &v
case unix.IFLA_BOND_USE_CARRIER:
v := ad.Uint8()
b.UseCarrier = &v
case unix.IFLA_BOND_ARP_INTERVAL:
v := ad.Uint32()
b.ArpInterval = &v
case unix.IFLA_BOND_ARP_IP_TARGET:
ad.Nested(func(nad *netlink.AttributeDecoder) error {
for nad.Next() {
b.ArpIpTargets = append(b.ArpIpTargets, nad.Bytes())
}
return nil
})
case unix.IFLA_BOND_NS_IP6_TARGET:
ad.Nested(func(nad *netlink.AttributeDecoder) error {
for nad.Next() {
b.NsIP6Targets = append(b.NsIP6Targets, nad.Bytes())
}
return nil
})
case unix.IFLA_BOND_ARP_VALIDATE:
v := BondArpValidate(ad.Uint32())
b.ArpValidate = &v
case unix.IFLA_BOND_ARP_ALL_TARGETS:
v := BondArpAllTargets(ad.Uint32())
b.ArpAllTargets = &v
case unix.IFLA_BOND_PRIMARY:
v := ad.Uint32()
b.Primary = &v
case unix.IFLA_BOND_PRIMARY_RESELECT:
v := BondPrimaryReselect(ad.Uint8())
b.PrimaryReselect = &v
case unix.IFLA_BOND_FAIL_OVER_MAC:
v := BondFailOverMac(ad.Uint8())
b.FailOverMac = &v
case unix.IFLA_BOND_XMIT_HASH_POLICY:
v := BondXmitHashPolicy(ad.Uint8())
b.XmitHashPolicy = &v
case unix.IFLA_BOND_RESEND_IGMP:
v := ad.Uint32()
b.ResendIgmp = &v
case unix.IFLA_BOND_NUM_PEER_NOTIF:
v := ad.Uint8()
b.NumPeerNotif = &v
case unix.IFLA_BOND_ALL_SLAVES_ACTIVE:
v := ad.Uint8()
b.AllSlavesActive = &v
case unix.IFLA_BOND_MIN_LINKS:
v := ad.Uint32()
b.MinLinks = &v
case unix.IFLA_BOND_LP_INTERVAL:
v := ad.Uint32()
b.LpInterval = &v
case unix.IFLA_BOND_PACKETS_PER_SLAVE:
v := ad.Uint32()
b.PacketsPerSlave = &v
case unix.IFLA_BOND_AD_LACP_ACTIVE:
v := BondAdLacpActive(ad.Uint8())
b.AdLacpActive = &v
case unix.IFLA_BOND_AD_LACP_RATE:
v := BondLacpRate(ad.Uint8())
b.AdLacpRate = &v
case unix.IFLA_BOND_AD_SELECT:
v := BondAdSelect(ad.Uint8())
b.AdSelect = &v
case unix.IFLA_BOND_AD_ACTOR_SYS_PRIO:
v := ad.Uint16()
b.AdActorSysPrio = &v
case unix.IFLA_BOND_AD_USER_PORT_KEY:
v := ad.Uint16()
b.AdUserPortKey = &v
case unix.IFLA_BOND_AD_ACTOR_SYSTEM:
b.AdActorSystem = ad.Bytes()
case unix.IFLA_BOND_TLB_DYNAMIC_LB:
v := ad.Uint8()
b.TlbDynamicLb = &v
case unix.IFLA_BOND_MISSED_MAX:
v := ad.Uint8()
b.MissedMax = &v
case unix.IFLA_BOND_AD_INFO:
ad.Nested(func(nad *netlink.AttributeDecoder) error {
b.AdInfo = &BondAdInfo{}
for nad.Next() {
switch nad.Type() {
case unix.IFLA_BOND_AD_INFO_AGGREGATOR:
b.AdInfo.AggregatorId = nad.Uint16()
case unix.IFLA_BOND_AD_INFO_NUM_PORTS:
b.AdInfo.NumPorts = nad.Uint16()
case unix.IFLA_BOND_AD_INFO_ACTOR_KEY:
b.AdInfo.ActorKey = nad.Uint16()
case unix.IFLA_BOND_AD_INFO_PARTNER_KEY:
b.AdInfo.PartnerKey = nad.Uint16()
case unix.IFLA_BOND_AD_INFO_PARTNER_MAC:
b.AdInfo.PartnerMac = nad.Bytes()
}
}
return nil
})
}
}
return nil
}
func (*Bond) Kind() string {
return "bond"
}
// BondSlaveState specifies bond slave state
type BondSlaveState uint8
const (
BondStateActive BondSlaveState = iota
BondStateBackup
)
func (b BondSlaveState) String() string {
switch b {
case BondStateActive:
return "ACTIVE"
case BondStateBackup:
return "BACKUP"
default:
return fmt.Sprintf("unknown BondSlaveState value %d", b)
}
}
// BondSlaveMiiStatus MII link monitoring frequency status
type BondSlaveMiiStatus uint8
const (
BondLinkUp BondSlaveMiiStatus = iota
BondLinkFail
BondLinkDown
BondLinkBack
)
func (b BondSlaveMiiStatus) String() string {
switch b {
case BondLinkUp:
return "UP"
case BondLinkFail:
return "GOING_DOWN"
case BondLinkDown:
return "DOWN"
case BondLinkBack:
return "GOING_BACK"
default:
return fmt.Sprintf("unknown BondSlaveMiiStatus value %d", b)
}
}
// BondSlave implements LinkSlaveDriver interface for bond driver
type BondSlave struct {
State *BondSlaveState
MiiStatus *BondSlaveMiiStatus
LinkFailureCount *uint32
PermHardwareAddr net.HardwareAddr
QueueId *uint16
Priority *int32
AggregatorId *uint16
AdActorOperPortState *uint8
AdPartnerOperPortState *uint16
}
var _ rtnetlink.LinkSlaveDriver = &BondSlave{}
func (b *BondSlave) New() rtnetlink.LinkDriver {
return &BondSlave{}
}
func (b *BondSlave) Slave() {}
func (b *BondSlave) Encode(ae *netlink.AttributeEncoder) error {
if b.QueueId != nil {
ae.Uint16(unix.IFLA_BOND_SLAVE_QUEUE_ID, *b.QueueId)
}
if b.Priority != nil {
ae.Int32(unix.IFLA_BOND_SLAVE_PRIO, *b.Priority)
}
return nil
}
func (b *BondSlave) Decode(ad *netlink.AttributeDecoder) error {
for ad.Next() {
switch ad.Type() {
case unix.IFLA_BOND_SLAVE_STATE:
v := BondSlaveState(ad.Uint8())
b.State = &v
case unix.IFLA_BOND_SLAVE_MII_STATUS:
v := BondSlaveMiiStatus(ad.Uint8())
b.MiiStatus = &v
case unix.IFLA_BOND_SLAVE_LINK_FAILURE_COUNT:
v := ad.Uint32()
b.LinkFailureCount = &v
case unix.IFLA_BOND_SLAVE_PERM_HWADDR:
b.PermHardwareAddr = net.HardwareAddr(ad.Bytes())
case unix.IFLA_BOND_SLAVE_QUEUE_ID:
v := ad.Uint16()
b.QueueId = &v
case unix.IFLA_BOND_SLAVE_PRIO:
v := ad.Int32()
b.Priority = &v
case unix.IFLA_BOND_SLAVE_AD_AGGREGATOR_ID:
v := ad.Uint16()
b.AggregatorId = &v
case unix.IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE:
v := ad.Uint8()
b.AdActorOperPortState = &v
case unix.IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE:
v := ad.Uint16()
b.AdPartnerOperPortState = &v
}
}
return nil
}
func (*BondSlave) Kind() string {
return "bond"
}
|