Skip to content

Commit

Permalink
probes: migrate leftover API from pkg/probe
Browse files Browse the repository at this point in the history
This also refactors HaveIPv6Support into returning an error instead of a
bool to keep feature probing APIs consistent across the package and adds
a small test for the probe.

Fixes: #25621.

Signed-off-by: Robin Gögge <r.goegge@isovalent.com>
  • Loading branch information
rgo3 authored and ti-mo committed May 26, 2023
1 parent 3f13ceb commit 1e41a91
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
3 changes: 1 addition & 2 deletions daemon/cmd/kube_proxy_replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cilium/cilium/pkg/mountinfo"
"github.com/cilium/cilium/pkg/node"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/probe"
"github.com/cilium/cilium/pkg/safeio"
"github.com/cilium/cilium/pkg/sysctl"
wgTypes "github.com/cilium/cilium/pkg/wireguard/types"
Expand Down Expand Up @@ -275,7 +274,7 @@ func probeKubeProxyReplacementOptions() error {
if option.Config.EnableSocketLB {
// Try to auto-load IPv6 module if it hasn't been done yet as there can
// be v4-in-v6 connections even if the agent has v6 support disabled.
probe.HaveIPv6Support()
probes.HaveIPv6Support()

if option.Config.EnableMKE {
if probes.HaveProgramHelper(ebpf.CGroupSockAddr, asm.FnGetCgroupClassid) != nil ||
Expand Down
12 changes: 12 additions & 0 deletions pkg/datapath/linux/probes/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,18 @@ func HaveOuterSourceIPSupport() (err error) {
return nil
}

// HaveIPv6Support tests whether kernel can open an IPv6 socket. This will
// also implicitly auto-load IPv6 kernel module if available and not yet
// loaded.
func HaveIPv6Support() error {
fd, err := unix.Socket(unix.AF_INET6, unix.SOCK_STREAM, 0)
if errors.Is(err, unix.EAFNOSUPPORT) || errors.Is(err, unix.EPROTONOSUPPORT) {
return ErrNotSupported
}
unix.Close(fd)
return nil
}

// CreateHeaderFiles creates C header files with macros indicating which BPF
// features are available in the kernel.
func CreateHeaderFiles(headerDir string, probes *FeatureProbes) error {
Expand Down
6 changes: 6 additions & 0 deletions pkg/datapath/linux/probes/probes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,9 @@ func TestOuterSourceIPProbe(t *testing.T) {
t.Fatal(err)
}
}

func TestIPv6Support(t *testing.T) {
if err := HaveIPv6Support(); err != nil {
t.Fatal(err)
}
}
5 changes: 0 additions & 5 deletions pkg/probe/doc.go

This file was deleted.

22 changes: 0 additions & 22 deletions pkg/probe/probe.go

This file was deleted.

0 comments on commit 1e41a91

Please sign in to comment.