Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func run(cmd *cobra.Command, _ []string) error {
return err
}

// Enable Multipath Hash Policy if required.
if connoptions.GwOptions.EnableMultipathHashPolicy {
if err = kernel.EnableMultipathHashPolicy(); err != nil {
return fmt.Errorf("failed to enable multipath hash policy: %w", err)
}
}
Comment thread
fra98 marked this conversation as resolved.
// Set controller-runtime logger.
log.SetLogger(klog.NewKlogr())

Expand Down
4 changes: 4 additions & 0 deletions pkg/gateway/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
FlagNameDisableKernelVersionCheck FlagName = "disable-kernel-version-check"
// FlagNameMinimumKernelVersion is the minimum kernel version required by Liqo.
FlagNameMinimumKernelVersion FlagName = "minimum-kernel-version"
// FlagNameEnableMultipathHashPolicy sets fib_multipath_hash_policy=1 to enable 5-tuple hashing for multipath routing.
FlagNameEnableMultipathHashPolicy FlagName = "enable-multipath-hash-policy"
)

// RequiredFlags contains the list of the mandatory flags.
Expand Down Expand Up @@ -125,6 +127,8 @@ func InitFlags(flagset *pflag.FlagSet, opts *Options) {

flagset.BoolVar(&opts.DisableKernelVersionCheck, FlagNameDisableKernelVersionCheck.String(), false, "Disable the kernel version check")
flagset.Var(&opts.MinimumKernelVersion, FlagNameMinimumKernelVersion.String(), "Minimum kernel version required by Liqo")
flagset.BoolVar(&opts.EnableMultipathHashPolicy, FlagNameEnableMultipathHashPolicy.String(), false,
"Set fib_multipath_hash_policy=1 to use 5-tuple hashing for multipath routing")
Comment thread
fra98 marked this conversation as resolved.
}

// MarkFlagsRequired marks the flags as required.
Expand Down
1 change: 1 addition & 0 deletions pkg/gateway/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Options struct {

DisableKernelVersionCheck bool
MinimumKernelVersion kernelversion.KernelVersion
EnableMultipathHashPolicy bool
}

// NewOptions returns a new Options struct.
Expand Down
36 changes: 36 additions & 0 deletions pkg/utils/kernel/multipathpolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2019-2026 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package kernel

import (
"fmt"
"os"
)

const multipathpolicyFile = "/proc/sys/net/ipv4/fib_multipath_hash_policy"

// EnableMultipathHashPolicy enables 5-tuple hashing for multipath routing by writing 1 to /proc/sys/net/ipv4/fib_multipath_hash_policy.
func EnableMultipathHashPolicy() error {
file, err := os.OpenFile(multipathpolicyFile, os.O_WRONLY, 0o600)
if err != nil {
return fmt.Errorf("failed to open multipath policy file %s: %w", multipathpolicyFile, err)
}
defer file.Close()

if _, err := file.WriteString("1\n"); err != nil {
return fmt.Errorf("failed to write to multipath policy file %s: %w", multipathpolicyFile, err)
}
return nil
}
Loading