Skip to content

Commit

Permalink
libnetwork: enable ipvlan support for netavark
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Zimmermann <[email protected]>
  • Loading branch information
M1cha authored and Luap99 committed Mar 31, 2023
1 parent e27c30e commit e118ea2
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions libnetwork/netavark/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e118ea2

Please sign in to comment.