Skip to content

Commit 85b018a

Browse files
committed
feat(gateway): add fib_multipath_hash_policy support for L4-aware ECMP flow distribution
1 parent defd807 commit 85b018a

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

cmd/gateway/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ func run(cmd *cobra.Command, _ []string) error {
118118
return err
119119
}
120120

121+
// Enable Multipath Hash Policy if required.
122+
if connoptions.GwOptions.EnableMultipathHashPolicy {
123+
if err = kernel.EnableMultipathHashPolicy(); err != nil {
124+
return fmt.Errorf("failed to enable multipath hash policy: %w", err)
125+
}
126+
}
121127
// Set controller-runtime logger.
122128
log.SetLogger(klog.NewKlogr())
123129

pkg/gateway/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const (
7777
FlagNameDisableKernelVersionCheck FlagName = "disable-kernel-version-check"
7878
// FlagNameMinimumKernelVersion is the minimum kernel version required by Liqo.
7979
FlagNameMinimumKernelVersion FlagName = "minimum-kernel-version"
80+
// FlagNameEnableMultipathHashPolicy sets fib_multipath_hash_policy=1 to enable 5-tuple hashing for multipath routing.
81+
FlagNameEnableMultipathHashPolicy FlagName = "enable-multipath-hash-policy"
8082
)
8183

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

126128
flagset.BoolVar(&opts.DisableKernelVersionCheck, FlagNameDisableKernelVersionCheck.String(), false, "Disable the kernel version check")
127129
flagset.Var(&opts.MinimumKernelVersion, FlagNameMinimumKernelVersion.String(), "Minimum kernel version required by Liqo")
130+
flagset.BoolVar(&opts.EnableMultipathHashPolicy, FlagNameEnableMultipathHashPolicy.String(), false,
131+
"Set fib_multipath_hash_policy=1 to use 5-tuple hashing for multipath routing")
128132
}
129133

130134
// MarkFlagsRequired marks the flags as required.

pkg/gateway/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type Options struct {
5151

5252
DisableKernelVersionCheck bool
5353
MinimumKernelVersion kernelversion.KernelVersion
54+
EnableMultipathHashPolicy bool
5455
}
5556

5657
// NewOptions returns a new Options struct.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2019-2026 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package kernel
16+
17+
import (
18+
"fmt"
19+
"os"
20+
)
21+
22+
const multipathpolicyFile = "/proc/sys/net/ipv4/fib_multipath_hash_policy"
23+
24+
// EnableMultipathHashPolicy enables 5-tuple hashing for multipath routing by writing 1 to /proc/sys/net/ipv4/fib_multipath_hash_policy.
25+
func EnableMultipathHashPolicy() error {
26+
file, err := os.OpenFile(multipathpolicyFile, os.O_WRONLY, 0o600)
27+
if err != nil {
28+
return fmt.Errorf("failed to open multipath policy file %s: %w", multipathpolicyFile, err)
29+
}
30+
defer file.Close()
31+
32+
if _, err := file.WriteString("1\n"); err != nil {
33+
return fmt.Errorf("failed to write to multipath policy file %s: %w", multipathpolicyFile, err)
34+
}
35+
return nil
36+
}

0 commit comments

Comments
 (0)