Skip to content

Commit

Permalink
Merge pull request containers#1440 from Cydox/static-routes-pull
Browse files Browse the repository at this point in the history
Static Routes
  • Loading branch information
openshift-merge-robot authored May 24, 2023
2 parents 53220b2 + 9a5e17f commit 5e0be23
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 0 deletions.
37 changes: 37 additions & 0 deletions libnetwork/internal/util/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,43 @@ func ValidateSubnets(network *types.Network, addGateway bool, usedNetworks []*ne
return nil
}

func ValidateRoutes(routes []types.Route) error {
for _, route := range routes {
err := ValidateRoute(route)
if err != nil {
return err
}
}
return nil
}

func ValidateRoute(route types.Route) error {
if route.Destination.IP == nil {
return fmt.Errorf("route destination ip nil")
}

if route.Destination.Mask == nil {
return fmt.Errorf("route destination mask nil")
}

if route.Gateway == nil {
return fmt.Errorf("route gateway nil")
}

// Reparse to ensure destination is valid.
ip, ipNet, err := net.ParseCIDR(route.Destination.String())
if err != nil {
return fmt.Errorf("route destination invalid: %w", err)
}

// check that destination is a network and not an address
if !ip.Equal(ipNet.IP) {
return fmt.Errorf("route destination invalid")
}

return nil
}

func ValidateSetupOptions(n NetUtil, namespacePath string, options types.SetupOptions) error {
if namespacePath == "" {
return errors.New("namespacePath is empty")
Expand Down
20 changes: 20 additions & 0 deletions libnetwork/netavark/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
if err != nil {
return nil, err
}
case types.NoDefaultRoute:
val, err := strconv.ParseBool(value)
if err != nil {
return nil, err
}
// rust only support "true" or "false" while go can parse 1 and 0 as well so we need to change it
newNetwork.Options[types.NoDefaultRoute] = strconv.FormatBool(val)

default:
return nil, fmt.Errorf("unsupported bridge network option %s", key)
Expand Down Expand Up @@ -237,6 +244,12 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
return nil, err
}

//validate routes
err = internalutil.ValidateRoutes(newNetwork.Routes)
if err != nil {
return nil, err
}

newNetwork.Created = time.Now()

if !defaultNet {
Expand Down Expand Up @@ -317,6 +330,13 @@ func createIpvlanOrMacvlan(network *types.Network) error {
if err != nil {
return err
}
case types.NoDefaultRoute:
val, err := strconv.ParseBool(value)
if err != nil {
return err
}
// rust only support "true" or "false" while go can parse 1 and 0 as well so we need to change it
network.Options[types.NoDefaultRoute] = strconv.FormatBool(val)
default:
return fmt.Errorf("unsupported %s network option %s", driver, key)
}
Expand Down
Loading

0 comments on commit 5e0be23

Please sign in to comment.