Brad Beam 119bf3e7bb feat(networkd): Add support for bonding
This includes a healthy refactor of the networkd code as well.
- Move netlink functionality to nic package
- Networkd facilitates the orchestration of the underlying interface configuration
- Networkd now stores the state of each interface configuration. This
  should allow us to expose this information via api in the future.

Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
2019-11-26 20:08:31 -08:00

50 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package nic
import (
"github.com/mdlayher/netlink"
"github.com/talos-systems/talos/internal/app/networkd/pkg/address"
)
// Option is the functional option func.
type Option func(*NetworkInterface) error
// defaultOptions defines our default network interface configuration.
func defaultOptions() *NetworkInterface {
return &NetworkInterface{
Bonded: false,
MTU: 1500,
AddressMethod: []address.Addressing{},
BondSettings: netlink.NewAttributeEncoder(),
}
}
// WithIgnore indicates that the interface should not be processed by talos.
func WithIgnore() Option {
return func(n *NetworkInterface) (err error) {
n.Ignore = true
return
}
}
// WithName sets the name of the interface to the given name.
func WithName(o string) Option {
return func(n *NetworkInterface) (err error) {
n.Name = o
return err
}
}
// WithAddressing defines how the addressing for a given interface
// should be configured
func WithAddressing(a address.Addressing) Option {
return func(n *NetworkInterface) (err error) {
n.AddressMethod = append(n.AddressMethod, a)
return err
}
}