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
4 changes: 3 additions & 1 deletion docs/cni/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ field; as of this writing it is still env-only.
- **`GALACTIC_CNI_EBPF_INTERFACES`** — comma-separated list of interface
names (whitespace trimmed, duplicates/empties removed) to attach the
ingress hook to. When set, `attach.ResolveInterfaces` uses this list
directly and skips auto-detection entirely. When unset, the
directly and skips auto-detection entirely. A value that yields no
names, such as one made only of commas or only of whitespace, is an
error rather than a request to auto-detect. When unset or empty, the
interface(s) carrying the default IPv6 route or a BGP-learned route are
auto-detected, counting every nexthop of a multipath (ECMP) route. Either
way, any resolved interface that is itself a Linux bonding master is
Expand Down
16 changes: 10 additions & 6 deletions internal/plumbing/ebpf/attach/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ var (
// ResolveInterfaces returns the interface names the uSID datapath should attach
// its TC-BPF ingress hook to.
//
// When config.EnvCNIEBPFInterfaces is set it is parsed as a comma-separated
// list, with whitespace trimmed and duplicates and empty entries removed, and
// used as-is. That is the explicit override for multi-homed nodes where
// auto-detection is ambiguous.
// When config.EnvCNIEBPFInterfaces is non-empty it is parsed as a
// comma-separated list, with whitespace trimmed and duplicates and empty
// entries removed, and used as-is. That is the explicit override for
// multi-homed nodes where auto-detection is ambiguous. A non-empty value that
// yields no names, such as only commas or only whitespace, is an error.
//
// Otherwise interfaces are auto-detected: those carrying the default IPv6
// When it is unset or empty, interfaces are auto-detected: those carrying the default IPv6
// route first, then those carrying a BGP-learned route (every nexthop of a
// multipath route counts), which is where a fabric
// peer's SRv6 traffic arrives when locators travel over a segment the default
Expand All @@ -67,7 +68,10 @@ func ResolveInterfaces() ([]string, error) {
names []string
err error
)
if override := strings.TrimSpace(os.Getenv(config.EnvCNIEBPFInterfaces)); override != "" {
// Whether the override is set is decided on the raw value, not the trimmed
// one: a value made only of whitespace is a malformed override, rejected
// like one made only of commas, rather than a request to auto-detect.
if override := os.Getenv(config.EnvCNIEBPFInterfaces); override != "" {
names = parseInterfaceList(override)
if len(names) == 0 {
return nil, fmt.Errorf("attach: %s is set to %q but contains no usable interface names",
Expand Down
23 changes: 23 additions & 0 deletions internal/plumbing/ebpf/attach/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package attach

import (
"errors"
"fmt"
"net"
"slices"
Expand Down Expand Up @@ -63,6 +64,23 @@ func stubNonBondLinks(t *testing.T) {
func TestResolveInterfaces_EnvOverride(t *testing.T) {
stubNonBondLinks(t)

// No override case may fall through to auto-detection, which would
// otherwise read the host's routing table and make the result depend on
// the machine running the test. The stubs record the call and fail.
origRouteListFn, origLinkByIndexFn := routeListFn, linkByIndexFn
t.Cleanup(func() {
routeListFn, linkByIndexFn = origRouteListFn, origLinkByIndexFn
})
var autoDetected bool
routeListFn = func() ([]netlink.Route, error) {
autoDetected = true
return nil, errors.New("auto-detection reached from an override case")
}
linkByIndexFn = func(int) (netlink.Link, error) {
autoDetected = true
return nil, errFixtureNotFound
}

tests := []struct {
name string
envValue string
Expand Down Expand Up @@ -96,12 +114,17 @@ func TestResolveInterfaces_EnvOverride(t *testing.T) {
},
{"OnlyCommasIsError", ",,,", nil, true},
{"OnlyWhitespaceIsError", " ", nil, true},
{"WhitespaceAndCommasIsError", " , \t, ", nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv(config.EnvCNIEBPFInterfaces, tt.envValue)
autoDetected = false

got, err := ResolveInterfaces()
if autoDetected {
t.Fatalf("ResolveInterfaces() fell through to auto-detection for override %q", tt.envValue)
}
if (err != nil) != tt.wantError {
t.Fatalf("ResolveInterfaces() error = %v, wantError = %v", err, tt.wantError)
}
Expand Down
Loading