diff --git a/libnetwork/netavark/config.go b/libnetwork/netavark/config.go index c71cc2eb5..dcac9ef1e 100644 --- a/libnetwork/netavark/config.go +++ b/libnetwork/netavark/config.go @@ -203,6 +203,11 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo return nil, fmt.Errorf("unsupported bridge network option %s", key) } } + case types.IPVLANNetworkDriver: + err = createIpvlan(newNetwork) + if err != nil { + return nil, err + } case types.MacVLANNetworkDriver: err = createMacvlan(newNetwork) if err != nil { @@ -245,6 +250,54 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo return newNetwork, nil } +func createIpvlan(network *types.Network) error { + if network.NetworkInterface != "" { + interfaceNames, err := internalutil.GetLiveNetworkNames() + if err != nil { + return err + } + if !util.StringInSlice(network.NetworkInterface, interfaceNames) { + return fmt.Errorf("parent interface %s does not exist", network.NetworkInterface) + } + } + + // always turn dns off with macvlan, it is not implemented in netavark + // and makes little sense to support with macvlan + // see https://github.com/containers/netavark/pull/467 + network.DNSEnabled = false + + // we already validated the drivers before so we just have to set the default here + switch network.IPAMOptions[types.Driver] { + case "": + if len(network.Subnets) == 0 { + return fmt.Errorf("ipvlan driver needs at least one subnet specified, DHCP is not yet supported with netavark") + } + network.IPAMOptions[types.Driver] = types.HostLocalIPAMDriver + case types.HostLocalIPAMDriver: + if len(network.Subnets) == 0 { + return fmt.Errorf("ipvlan driver needs at least one subnet specified, when the host-local ipam driver is set") + } + } + + // validate the given options, we do not need them but just check to make sure they are valid + for key, value := range network.Options { + switch key { + case types.ModeOption: + if !util.StringInSlice(value, types.ValidIPVLANModes) { + return fmt.Errorf("unknown ipvlan mode %q", value) + } + case types.MTUOption: + _, err := internalutil.ParseMTU(value) + if err != nil { + return err + } + default: + return fmt.Errorf("unsupported ipvlan network option %s", key) + } + } + return nil +} + func createMacvlan(network *types.Network) error { if network.NetworkInterface != "" { interfaceNames, err := internalutil.GetLiveNetworkNames()