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
42 changes: 30 additions & 12 deletions cmd/galactic-gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ var gatewayDatapathKeepAlive struct {
returnSet targetSet
dispatcher *xdpdispatch.Dispatcher
xmitDrops *xmitdrops.Counter
// modeClaim holds this host's XDP attach mode for the gateway until the
// process exits.
modeClaim *xdpmode.HostClaim
}

// xdpModeComponent names the gateway in this host's XDP attach mode claims
// (xdpmode.Claim).
const xdpModeComponent = "galactic-gateway"

// xdpConfig is how the gateway attaches its XDP programs: attach is one of
// the config.GatewayXDPAttach values, and mode is config.EnvXDPMode's
// setting.
type xdpConfig struct {
attach string
mode xdpmode.Setting
}

// setupGatewayDatapath loads and attaches the edge Maglev datapath to
Expand All @@ -64,15 +79,15 @@ var gatewayDatapathKeepAlive struct {
//
// See installGateway for the attachment itself.
func setupGatewayDatapath(
ctx context.Context, publicInterface string, internalInterfaces []string, srv6Address, attachMode string,
ctx context.Context, publicInterface string, internalInterfaces []string, srv6Address string, xdp xdpConfig,
ipv4 *ipv4Forwarding, coverage *datapathCoverage,
) (gateway.Datapath, error) {
encapSrc, err := netip.ParseAddr(srv6Address)
if err != nil {
return nil, fmt.Errorf("parse gateway SRv6 address %q: %w", srv6Address, err)
}
var datapath *gateway.KernelDatapath
err = installGateway(ctx, publicInterface, internalInterfaces, attachMode, ipv4, coverage,
err = installGateway(ctx, publicInterface, internalInterfaces, xdp, ipv4, coverage,
func(objs *edgeprog.EdgedsrObjects) (edgemetrics.VPCAttribution, error) {
dp, err := gateway.NewKernelDatapath(objs, encapSrc)
if err != nil {
Expand All @@ -95,11 +110,11 @@ func setupGatewayDatapath(
// load-balancing slot is emptied and only the return slot is filled and
// leased. See installGateway for the attachment itself.
func setupReturnPath(
ctx context.Context, internalInterfaces []string, attachMode string, ipv4 *ipv4Forwarding,
ctx context.Context, internalInterfaces []string, xdp xdpConfig, ipv4 *ipv4Forwarding,
coverage *datapathCoverage,
) (*gateway.KernelReturnPath, error) {
var returnPath *gateway.KernelReturnPath
err := installGateway(ctx, "", internalInterfaces, attachMode, ipv4, coverage,
err := installGateway(ctx, "", internalInterfaces, xdp, ipv4, coverage,
func(objs *edgeprog.EdgedsrObjects) (edgemetrics.VPCAttribution, error) {
returnPath = gateway.NewKernelReturnPath(objs)
return nil, nil
Expand Down Expand Up @@ -138,7 +153,7 @@ func setupReturnPath(
// (see edgedsr.c's edge_return comment). An empty list attaches nothing and
// leaves the packet path unchanged.
func installGateway(
ctx context.Context, publicInterface string, internalInterfaces []string, attachMode string,
ctx context.Context, publicInterface string, internalInterfaces []string, xdp xdpConfig,
ipv4 *ipv4Forwarding, coverage *datapathCoverage,
build func(*edgeprog.EdgedsrObjects) (edgemetrics.VPCAttribution, error),
) error {
Expand Down Expand Up @@ -167,16 +182,19 @@ func installGateway(
// One attach mode for every XDP attachment on the host, the public and
// internal targets alike (xdpmode). A target that does not exist, or a
// NIC whose driver cannot be read, fails startup rather than settling the
// mode without it.
modeDecision, err := xdpmode.Select(append(slices.Clone(targets), returnTargets...)...)
// mode without it, and so does the egress shard on this host attaching in
// the other mode.
modeDecision, err := xdpmode.Select(xdp.mode, append(slices.Clone(targets), returnTargets...)...)
if err != nil {
return fmt.Errorf("select the XDP attach mode for this host: %w", err)
}
mode := modeDecision.Mode
slog.Info("Selected the XDP attach mode for this host", "mode", mode.String(), "reason", modeDecision.Reason)
for _, skipped := range modeDecision.Skipped {
slog.Warn("Left a NIC with no driver out of the XDP attach mode decision", "reason", skipped)
modeDecision.Log()
claim, err := xdpmode.Claim(ctx, xdpmode.ClaimDir, xdpModeComponent, modeDecision)
if err != nil {
return fmt.Errorf("claim the XDP attach mode for this host: %w", err)
}
gatewayDatapathKeepAlive.modeClaim = claim
mode := modeDecision.Mode

// Required for the FIB lookup in the datapath's header push to succeed
// on the interface the program actually runs on. The lookup uses the
Expand Down Expand Up @@ -215,7 +233,7 @@ func installGateway(
// leases stop and the slots are emptied, so a half-set-up gateway never
// claims packets while the process exits.
abandon := func() {}
if attachMode == config.GatewayXDPAttachDispatch {
if xdp.attach == config.GatewayXDPAttachDispatch {
leaseCtx, stopLeases := context.WithCancel(ctx)
var leaseDone <-chan struct{}
lease := xdpdispatch.NewLeaseMetrics(edgemetrics.Namespace)
Expand Down
3 changes: 2 additions & 1 deletion cmd/galactic-gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
// binary's config.GatewayConfig.Validate rejects an empty
// PublicInterface/SRv6Address before setupGatewayDatapath is ever called.
func TestSetupGatewayDatapath_InvalidAddressIsError(t *testing.T) {
_, err := setupGatewayDatapath(context.Background(), "eth0", nil, "not-an-ip-address", "dispatch", nil,
_, err := setupGatewayDatapath(context.Background(), "eth0", nil, "not-an-ip-address",
xdpConfig{attach: "dispatch"}, nil,
newDatapathCoverage(nil))
if err == nil {
t.Error("setupGatewayDatapath with an invalid SRv6 address: want an error, got nil")
Expand Down
9 changes: 7 additions & 2 deletions cmd/galactic-gateway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.datum.net/galactic/internal/logging"
"go.datum.net/galactic/internal/metadata"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpdispatch"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpmode"
"go.datum.net/galactic/internal/plumbing/sysctl"
)

Expand Down Expand Up @@ -187,7 +188,7 @@ func runCmd(cfg *config.GatewayConfig) error {
},
}
gwDatapath, err = setupGatewayDatapath(ctx, cfg.PublicInterface, cfg.InternalInterfaces, encapSrc,
cfg.XDPAttach, ipv4, coverage)
xdpConfig{attach: cfg.XDPAttach, mode: cfg.XDPModeSetting}, ipv4, coverage)
if err != nil {
return fmt.Errorf("setup edge gateway eBPF datapath: %w", err)
}
Expand All @@ -196,7 +197,8 @@ func runCmd(cfg *config.GatewayConfig) error {
// is load-balanced here, but backend nodes can still send replies
// through it, which only edge_return lets past connection tracking.
turnOffDatapath(ctx, xdpdispatch.PinDir, xdpdispatch.SlotGatewayLB)
rp, err := setupReturnPath(ctx, cfg.InternalInterfaces, cfg.XDPAttach, ipv4, coverage)
rp, err := setupReturnPath(ctx, cfg.InternalInterfaces,
xdpConfig{attach: cfg.XDPAttach, mode: cfg.XDPModeSetting}, ipv4, coverage)
if err != nil {
return fmt.Errorf("setup edge gateway return path: %w", err)
}
Expand Down Expand Up @@ -328,6 +330,9 @@ func newRootCommand() *cobra.Command {
cmd.Flags().StringP("gateway-xdp-attach", "", config.GatewayXDPAttachDispatch,
"How the datapath reaches its interfaces' XDP hook: \"dispatch\" runs it from the node's shared, "+
"pinned XDP dispatcher, \"direct\" attaches it")
cmd.Flags().String(config.FlagXDPMode, xdpmode.SettingAutoValue,
"XDP attach mode for every Galactic XDP attachment on this host: \"auto\" decides from the NIC "+
"drivers, \"native\" or \"generic\" forces that mode; galactic-nat on the host must resolve the same")
cmd.Flags().Bool("gateway-datapath-enabled", true,
"Run the edge gateway datapath; false keeps the process up but attaches nothing and withdraws "+
"this node's VIP advertisements")
Expand Down
22 changes: 16 additions & 6 deletions cmd/galactic-nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ var natDatapathKeepAlive struct {
objs *natprog.NatObjects
set *xdpattach.Set
dispatch *xdpdispatch.Dispatcher
// modeClaim holds this host's XDP attach mode for the shard until the
// process exits.
modeClaim *xdpmode.HostClaim
}

// xdpModeComponent names the shard in this host's XDP attach mode claims
// (xdpmode.Claim).
const xdpModeComponent = "galactic-nat"

// natDatapath is this node's attached egress translation datapath, as
// controller.EgressShardReconciler drives it (controller.EgressDatapath).
//
Expand Down Expand Up @@ -290,16 +297,19 @@ func setupNatDatapath(ctx context.Context, cfg *config.NATConfig,
// One attach mode for every XDP attachment on the host, shared with the
// edge gateway's (xdpmode). An uplink that does not exist, or a NIC whose
// driver cannot be read, fails startup rather than settling the mode
// without it.
modeDecision, err := xdpmode.Select(uplinks...)
// without it, and so does the edge gateway on this host attaching in the
// other mode.
modeDecision, err := xdpmode.Select(cfg.XDPModeSetting, uplinks...)
if err != nil {
return nil, fmt.Errorf("select the XDP attach mode for this host: %w", err)
}
mode := modeDecision.Mode
slog.Info("Selected the XDP attach mode for this host", "mode", mode.String(), "reason", modeDecision.Reason)
for _, skipped := range modeDecision.Skipped {
slog.Warn("Left a NIC with no driver out of the XDP attach mode decision", "reason", skipped)
modeDecision.Log()
claim, err := xdpmode.Claim(ctx, xdpmode.ClaimDir, xdpModeComponent, modeDecision)
if err != nil {
return nil, fmt.Errorf("claim the XDP attach mode for this host: %w", err)
}
natDatapathKeepAlive.modeClaim = claim
mode := modeDecision.Mode

// Required for the FIB lookup in both the forward and return paths to
// succeed on the interface the program actually runs on. The lookup uses
Expand Down
4 changes: 4 additions & 0 deletions cmd/galactic-nat/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"go.datum.net/galactic/internal/logging"
"go.datum.net/galactic/internal/metadata"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpdispatch"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpmode"
"go.datum.net/galactic/internal/plumbing/sysctl"
)

Expand Down Expand Up @@ -253,6 +254,9 @@ func newRootCommand() *cobra.Command {
cmd.Flags().StringP("nat-xdp-attach", "", config.NATXDPAttachDirect,
"How the datapath reaches its uplinks' XDP hook: \"direct\" attaches it, \"dispatch\" runs it "+
"from the node's shared, pinned XDP dispatcher (\"chain\" is read as dispatch)")
cmd.Flags().String(config.FlagXDPMode, xdpmode.SettingAutoValue,
"XDP attach mode for every Galactic XDP attachment on this host: \"auto\" decides from the NIC "+
"drivers, \"native\" or \"generic\" forces that mode; galactic-gateway on the host must resolve the same")
cmd.Flags().Bool("nat-datapath-enabled", true,
"Run the egress translation datapath; false keeps the process up but attaches nothing, "+
"clears the shard's identity and withdraws its advertisement")
Expand Down
23 changes: 23 additions & 0 deletions deploy/containerlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,27 @@ cd deploy/containerlab
task deploy # build all images, apply host sysctls, deploy lab end-to-end
```

### Generic XDP mode

The lab's veths select native XDP, so by default Galactic's programs never run
in generic mode here. `XDP_MODE` forces a mode on every edge node by setting
`GALACTIC_XDP_MODE` on every `galactic-nat` and `galactic-gateway` DaemonSet
(see [XDP attach mode](../../docs/operations/xdp-attach-mode.md#forcing-a-mode)):

```bash
task deploy XDP_MODE=generic # deploy the lab in generic mode
task lab:xdp-mode XDP_MODE=generic # switch a running lab
task verify:xdp-mode EXPECT=generic # every Galactic attachment shows xdpgeneric
task lab:xdp-mode # back to the drivers' choice, native here
task verify:xdp-mode EXPECT=native
```

`lab:xdp-mode` sets the gateways and the shard in each site together, since
the two refuse to start beside each other in different modes, and dispatch
links migrate in place, bouncing each uplink once. `deploy:galactic-nat` and
`deploy:galactic-gateway` apply `XDP_MODE` too, and remove the variable when
it is unset, so pass the same value on a redeploy to stay in generic mode.

To tear down and start fresh:

```bash
Expand Down Expand Up @@ -530,6 +551,7 @@ task deploy
| `deploy:bmp-collector` | Install the BMP collector on iad-worker3, where the route reflector streams to it |
| `deploy:galactic-router` | Apply galactic-router DaemonSets and BGP CRs |
| `deploy:galactic-gateway` | Install galactic-gateway on every edge node, with each site's VIP rules (after `deploy:scenarios`) |
| `lab:xdp-mode` | Set every edge node's Galactic XDP attach mode to `XDP_MODE` (`generic`, `native`, or empty for the drivers' choice) |
| `deploy:scenarios` | Deploy all VPC test scenarios |
| `deploy:ns10` | Deploy ns10 test VPC (IPv6-only, fd20 ULA) |
| `deploy:ns20` | Deploy ns20 test VPC (dual-stack, fd20 ULA + IPv4) |
Expand All @@ -545,6 +567,7 @@ task deploy
| `verify:gateway-ingress-ipv4` | IPv4 TCP and UDP to each site's IPv4 VIP through every gateway node, translated to the IPv6-only backends |
| `verify:gateway-backend-health` | Stops a dfw backend's listener; both gateways must drop it, keep it out across restarts, and take it back once it listens |
| `verify:gateway-node-loss` | Take dfw-worker2's fabric links down: ingress through dfw-worker3 must pass, then through dfw-worker2 once restored (not in `verify`) |
| `verify:xdp-mode` | Check every Galactic XDP attachment on every edge node, and every pod's logged decision, is in `EXPECT` mode (not in `verify`) |
| `verify:gateway-restart` | Restart dfw-worker2's gateway and shard in turn while the other carries traffic (#710) |
| `verify:gateway-detach` | Turn dfw-worker2's gateway datapath off: ingress through it must fail and through dfw-worker3 pass, then through it pass (not in `verify`) |
| `verify:nat-datapath` | Full egress round trip to the off-fabric host, IPv6 (NAT66) and IPv4 (NAT64) |
Expand Down
24 changes: 22 additions & 2 deletions deploy/containerlab/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ vars:
TOPO:
sh: echo *.clab.yaml
FABRIC_ROUTER_IMAGE: fabric-router:latest
# XDP_MODE sets GALACTIC_XDP_MODE on every galactic-nat and galactic-gateway
# DaemonSet: "generic" or "native" forces that XDP attach mode on every edge
# node, and empty (the default) or "auto" leaves it to the NIC drivers,
# native on the lab's veths. deploy, deploy:galactic-nat,
# deploy:galactic-gateway and lab:xdp-mode read it, as in
# `task deploy XDP_MODE=generic`.
XDP_MODE: ''

tasks:
default:
Expand Down Expand Up @@ -413,12 +420,17 @@ tasks:
"deploy:galactic-nat":
desc: Install the NAT egress DaemonSet and shards
cmds:
- ./scripts/deploy-galactic-nat.sh
- LAB_XDP_MODE={{.XDP_MODE}} ./scripts/deploy-galactic-nat.sh

"deploy:galactic-gateway":
desc: Install galactic-gateway on every edge node, with each site's VIP rules
cmds:
- ./scripts/deploy-galactic-gateway.sh
- LAB_XDP_MODE={{.XDP_MODE}} ./scripts/deploy-galactic-gateway.sh

"lab:xdp-mode":
desc: Switch every edge node's Galactic XDP attach mode to XDP_MODE (generic, native, or empty for auto)
cmds:
- LAB_XDP_MODE={{.XDP_MODE}} ./scripts/xdp-mode.sh

"deploy:galactic-edge":
desc: Run Galactic Edge on dfw's edge nodes (node agent, galactic-controller --edge, VPC objects)
Expand Down Expand Up @@ -737,6 +749,14 @@ tasks:
# #710: the gateway and the egress shard share each edge node's uplinks
# through its XDP dispatcher, so restarting either must leave the other's
# traffic flowing.
# Not part of `verify`: it needs the mode the lab was deployed in.
"verify:xdp-mode":
desc: Check every Galactic XDP attachment on every edge node runs in EXPECT mode (native or generic)
requires:
vars: [EXPECT]
cmds:
- ./scripts/verify-xdp-mode.sh {{.EXPECT}}

"verify:gateway-restart":
desc: Restart dfw-worker2's gateway and shard in turn while the other carries traffic
cmds:
Expand Down
3 changes: 3 additions & 0 deletions deploy/containerlab/scripts/deploy-galactic-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ for site in dfw sjc iad; do
# rules.
docker exec "${node}" kubectl -n galactic-system delete servicevipbindings \
-l "app.kubernetes.io/managed-by!=galactic-router" --ignore-not-found
# GALACTIC_XDP_MODE from XDP_MODE, on the shard too, so the two keep
# resolving one mode (lib.sh apply_xdp_mode).
apply_xdp_mode "${node}"
for gw in ${GATEWAY_NODES[${site}]}; do
docker exec "${node}" kubectl -n galactic-system rollout status daemonset "galactic-gateway-${gw}" --timeout=180s
done
Expand Down
3 changes: 3 additions & 0 deletions deploy/containerlab/scripts/deploy-galactic-nat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ for site in dfw sjc iad; do
copy_to "${node}" galactic-nat
copy_nat_config "${node}"
apply_k "${node}" "/galactic/resources/galactic-nat/${site}/"
# GALACTIC_XDP_MODE from XDP_MODE, on the gateways too, so the two keep
# resolving one mode (lib.sh apply_xdp_mode).
apply_xdp_mode "${node}"
docker exec "${node}" kubectl -n galactic-system rollout status daemonset galactic-nat
# Rollout means attached, not translating: a shard turns ready before its
# identity is programmed. Programmed is what a tenant's egress route needs.
Expand Down
37 changes: 37 additions & 0 deletions deploy/containerlab/scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,43 @@ apply_f() {
docker exec -i "${node}" kubectl apply -f "${path}"
}

# apply_xdp_mode NODE sets GALACTIC_XDP_MODE, from LAB_XDP_MODE (the
# Taskfile's XDP_MODE), on every DaemonSet in NODE's cluster that attaches
# Galactic XDP programs: galactic-nat and each edge node's
# galactic-gateway-<node>. Empty or "auto" removes the variable, so the
# processes decide from the NIC drivers and the lab's veths run native, as
# before the option existed; "native" or "generic" forces that mode. Every
# such DaemonSet is set together, since a gateway and a shard on one node
# refuse to start beside each other in different modes (xdpmode.Claim), and
# the call waits for each to roll out.
#
# kubectl apply -k leaves an env var set this way in place, so every deploy
# calls this, removing the variable again when XDP_MODE is unset.
apply_xdp_mode() {
local node="$1" mode="${LAB_XDP_MODE:-}" ds
local -a daemonsets
case "${mode}" in
"" | auto | native | generic) ;;
*)
echo "error: XDP_MODE must be empty, auto, native or generic, got \"${mode}\"" >&2
return 1
;;
esac
mapfile -t daemonsets < <(docker exec "${node}" kubectl -n galactic-system get daemonsets \
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep -E '^galactic-(nat|gateway-.+)$')
for ds in "${daemonsets[@]}"; do
if [ -z "${mode}" ] || [ "${mode}" = auto ]; then
docker exec "${node}" kubectl -n galactic-system set env "daemonset/${ds}" -c 'galactic-*' GALACTIC_XDP_MODE-
else
docker exec "${node}" kubectl -n galactic-system set env "daemonset/${ds}" -c 'galactic-*' \
"GALACTIC_XDP_MODE=${mode}"
fi
done
for ds in "${daemonsets[@]}"; do
docker exec "${node}" kubectl -n galactic-system rollout status "daemonset/${ds}" --timeout=300s
done
}

ensure_namespace() {
local node="$1" ns="$2"
docker exec "${node}" sh -c "kubectl create namespace ${ns} --dry-run=client -o yaml | kubectl apply -f -"
Expand Down
Loading
Loading