Seán C McCord f7ad24ec4f feat: allow network interface to be ignored
Added a property to userdata to allow a network interface to be ignored,
such that Talos will perform no operations on it (including DHCP).

Also added kernel commandline parameter (talos.network.interface.ignore)
to specify a network interface should be ignored.

Also allows chaining of kernel cmdline parameter Contains() where the
parameter in question does not exist.

Fixes #1124

Signed-off-by: Seán C McCord <ulexus@gmail.com>
2019-09-07 16:33:52 -07:00

90 lines
2.2 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 main
import (
"log"
"github.com/talos-systems/talos/internal/app/networkd/pkg/networkd"
"github.com/talos-systems/talos/internal/app/networkd/pkg/nic"
"github.com/talos-systems/talos/internal/app/networkd/pkg/reg"
"github.com/talos-systems/talos/pkg/constants"
"github.com/talos-systems/talos/pkg/grpc/factory"
"github.com/talos-systems/talos/pkg/userdata"
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime)
}
func main() {
var (
netconf networkd.NetConf
ud *userdata.UserData
)
nwd, err := networkd.New()
if err != nil {
log.Fatal(err)
}
// Convert links to nic
log.Println("discovering local network interfaces")
netconf, err = nwd.Discover()
if err != nil {
log.Fatal(err)
}
// Load up userdata
ud, err = userdata.Open(constants.UserDataPath)
if err != nil {
log.Printf("failed to read userdata %s, using defaults: %+v", constants.UserDataPath, err)
}
log.Println("overlaying userdata network configuration")
// Update nic with userdata specified options
if err = netconf.OverlayUserData(ud); err != nil {
log.Fatal(err)
}
// Configure specified interface
netIfaces := make([]*nic.NetworkInterface, 0, len(netconf))
for link, opts := range netconf {
var iface *nic.NetworkInterface
log.Printf("creating interface %s", link.Name)
iface, err = nic.Create(link, opts...)
if err != nil {
log.Fatal(err)
}
if iface.IsIgnored() {
continue
}
netIfaces = append(netIfaces, iface)
}
// kick off the addressing mechanism
// Add any necessary routes
log.Println("configuring interface addressing")
if err = nwd.Configure(netIfaces...); err != nil {
log.Fatal(err)
}
log.Println("interface configuration")
nwd.PrintState()
log.Println("starting renewal watcher")
// handle dhcp renewal
go nwd.Renew(netIfaces...)
log.Fatalf("%+v", factory.ListenAndServe(
reg.NewRegistrator(nwd),
factory.Network("unix"),
factory.SocketPath(constants.NetworkdSocketPath),
),
)
}