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
46 changes: 19 additions & 27 deletions cmd/galactic-gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
"github.com/vishvananda/netlink"
"go.miloapis.com/instrumentation/metrics"

"go.datum.net/galactic/internal/config"
Expand All @@ -29,6 +28,7 @@ import (
"go.datum.net/galactic/internal/plumbing/ebpf/xdpmode"
"go.datum.net/galactic/internal/plumbing/ebpf/xmitdrops"
"go.datum.net/galactic/internal/plumbing/sysctl"
"go.datum.net/galactic/internal/plumbing/transport"
)

// gatewayDatapathKeepAlive holds the loaded objects and every attached link for
Expand Down Expand Up @@ -297,7 +297,7 @@ func installGateway(
missing = append(missing, returnSet.reconcile(ctx, returnTargets)...)
}
coverage.set(missing)
syncVLANEgress(objs.VlanEgress, publicInterface, internalInterfaces, true)
syncVLANEgress(objs.VlanEgress, publicInterface, internalInterfaces)
go watchTargets(ctx, publicInterface, internalInterfaces, publicSet, returnSet, coverage, ipv4, objs.VlanEgress)

return nil
Expand All @@ -309,39 +309,31 @@ func installGateway(
// its lower device with that side's tag pushed in XDP, since a native redirect
// to a VLAN netdevice transmits nothing. A side that cannot be resolved keeps
// no row and is reported; the attachment itself reports a missing interface.
// logSides logs each tagged side, which startup does once.
func syncVLANEgress(m *ebpf.Map, publicInterface string, internalInterfaces []string, logSides bool) {
names := append([]string{publicInterface}, internalInterfaces...)
lowers, ifindexes, err := vlanegress.FromNetlink(names)
//
// Every call publishes the derived sides through gatewayTransport: the first
// logs each side's mode, VLAN ID, parent and members, later ones log and count
// what changed, such as a VLAN recreated with a new ifindex.
func syncVLANEgress(m *ebpf.Map, publicInterface string, internalInterfaces []string) {
set, ifindexes, err := vlanegress.Resolve(
vlanegress.Side{Side: transport.SidePublic, Names: []string{publicInterface}},
vlanegress.Side{Side: transport.SideFabric, Names: internalInterfaces},
)
if err != nil {
gatewayTransport.Fail(err)
slog.Warn("Cannot resolve every edge gateway interface for VLAN egress; routes through the ones "+
"left out are redirected to the VLAN device as the FIB names it", "err", err)
}
if err := vlanegress.Sync(m, lowers, ifindexes); err != nil {
if err := vlanegress.Sync(m, set, ifindexes); err != nil {
slog.Warn("Cannot update the edge gateway's VLAN egress map", "err", err)
}
if !logSides {
return
}
for i, name := range names {
if name == "" {
continue
}
side := "internal"
if i == 0 {
side = "public"
}
l, err := netlink.LinkByName(name)
if err != nil {
continue
}
if lower, vid, ok := lowers.VLANLower(l.Attrs().Index); ok {
slog.Info("Edge gateway side is tagged; its XDP hook runs in generic mode on the VLAN device",
"side", side, "interface", name, "vlanID", vid, "lowerIfindex", lower)
}
if set != nil {
gatewayTransport.Observe(set)
}
}

// gatewayTransport publishes the gateway's derived transport sides.
var gatewayTransport = transport.NewTracker("galactic-gateway")

// targetSet keeps one of the gateway's programs on a set of interfaces and
// reports the ones it does not cover: xdpattach.Set in direct mode,
// xdpattach.DispatchSet in dispatch mode.
Expand Down Expand Up @@ -612,7 +604,7 @@ func watchTargets(ctx context.Context, publicInterface string, internalInterface
publicSet, returnSet targetSet, coverage *datapathCoverage, ipv4 *ipv4Forwarding, vlanEgress *ebpf.Map,
) {
xdpattach.OnNetlinkChange(ctx, func() {
syncVLANEgress(vlanEgress, publicInterface, internalInterfaces, false)
syncVLANEgress(vlanEgress, publicInterface, internalInterfaces)
var (
targets []string
err error
Expand Down
33 changes: 18 additions & 15 deletions cmd/galactic-nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"go.datum.net/galactic/internal/plumbing/ebpf/xdpmode"
"go.datum.net/galactic/internal/plumbing/nicstats"
"go.datum.net/galactic/internal/plumbing/sysctl"
"go.datum.net/galactic/internal/plumbing/transport"
)

// natDatapathKeepAlive holds the loaded objects and the attached link for the
Expand Down Expand Up @@ -350,7 +351,7 @@ func setupNatDatapath(ctx context.Context, cfg *config.NATConfig,
// from the EgressShard spec -- or clears it, if that shard is gone.
d.shardConfig = natmap.NewShardConfigTable(natmap.KernelTable{Map: objs.ShardConfigTable})
d.vlanEgress = objs.VlanEgress
d.syncVLANEgress(uplinks, true)
d.syncVLANEgress(uplinks)

var (
set *xdpattach.Set
Expand Down Expand Up @@ -409,31 +410,33 @@ func setupNatDatapath(ctx context.Context, cfg *config.NATConfig,
// one that is a VLAN netdevice, a tagged uplink, gets a row naming its lower
// device and VLAN ID. A translated packet whose route leaves through it is
// then sent through the lower device with that tag pushed in XDP, since a
// native redirect to a VLAN netdevice transmits nothing. logSides logs each
// tagged uplink, which startup does once.
func (d *natDatapath) syncVLANEgress(uplinks []string, logSides bool) {
// native redirect to a VLAN netdevice transmits nothing.
//
// The uplink list can hold both sides, so each uplink is reported as
// unassigned. Every call publishes them through natTransport: the first logs
// each uplink's mode, VLAN ID, parent and members, later ones log and count
// what changed.
func (d *natDatapath) syncVLANEgress(uplinks []string) {
if d.vlanEgress == nil {
return
}
lowers, ifindexes, err := vlanegress.FromNetlink(uplinks)
set, ifindexes, err := vlanegress.Resolve(vlanegress.Side{Side: transport.SideUnassigned, Names: uplinks})
if err != nil {
natTransport.Fail(err)
slog.Warn("Cannot resolve every uplink for VLAN egress; routes through the ones left out are "+
"redirected to the VLAN device as the FIB names it", "err", err)
}
if err := vlanegress.Sync(d.vlanEgress, lowers, ifindexes); err != nil {
if err := vlanegress.Sync(d.vlanEgress, set, ifindexes); err != nil {
slog.Warn("Cannot update the egress translation VLAN egress map", "err", err)
}
if !logSides {
return
}
for _, ifindex := range ifindexes {
if lower, vid, ok := lowers.VLANLower(ifindex); ok {
slog.Info("Uplink is tagged; its XDP hook runs in generic mode on the VLAN device",
"ifindex", ifindex, "vlanID", vid, "lowerIfindex", lower)
}
if set != nil {
natTransport.Observe(set)
}
}

// natTransport publishes the shard's derived uplink transport state.
var natTransport = transport.NewTracker("galactic-nat")

// registerUplinkQueueStats exports the per-queue receive counters of every
// uplink d currently resolves. A single stalled NIC receive queue drops packets
// before the datapath sees them, so drops_total stays flat through it (#673);
Expand Down Expand Up @@ -567,7 +570,7 @@ func (d *natDatapath) watchUplinks(ctx context.Context, override []string, cover
}
return
}
d.syncVLANEgress(uplinks, false)
d.syncVLANEgress(uplinks)
ready := d.adoptUplinks(uplinks)

missing := uncovered(uplinks, cover(ready))
Expand Down
7 changes: 7 additions & 0 deletions config/galactic-cni/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ spec:
# docs/nat/configuration.md#active-active-egress.
- name: GALACTIC_CNI_EGRESS_MODE
value: ordered
# Matches this node's entry in
# GALACTIC_CNI_EBPF_INTERFACES_BY_NODE, which both containers
# read.
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
# Documentation only: hostNetwork: true means these are the
# process's actual listen ports on the node, not something
# Kubernetes publishes -- containerPort here doesn't change
Expand Down
45 changes: 45 additions & 0 deletions docs/cni/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ field; as of this writing it is still env-only.

**Type:** comma-separated string · **Default:** _(auto-detected)_

- **`GALACTIC_CNI_EBPF_INTERFACES_BY_NODE`** gives individual nodes their
own `GALACTIC_CNI_EBPF_INTERFACES` list, so one cluster-wide DaemonSet can
name a tagged transport side on a node where the same interface plays a
different side elsewhere. Entries are separated by semicolons or newlines,
each `node=iface[,iface...]`:

```yaml
- name: GALACTIC_CNI_EBPF_INTERFACES_BY_NODE
value: |
edge-a=bond0.101
compute-b=bond0
```

`galactic-cni init` and `run` match the entry against `NODE_NAME` (or
`GALACTIC_CNI_NODE_NAME`), so set the variable on both the `install-cni`
and `credential-refresh` containers; the shipped DaemonSet gives both
`NODE_NAME`. A listed node's entry replaces `GALACTIC_CNI_EBPF_INTERFACES`
before anything resolves it, so the conflist carries the node's own list.
Other nodes keep the cluster-wide value or auto-detection. A malformed
value, a node listed twice, or a value set where the node name is unknown
fails startup.

**Type:** string · **Default:** _(unset)_

- **`GALACTIC_CNI_EBPF_FILTER_PRIORITY`** — overrides the `tc` priority the
ingress filter attaches at. Cilium also runs its own tc/bpf programs on
the same native-device ingress hook, and the default has not been
Expand All @@ -141,6 +165,27 @@ field; as of this writing it is still env-only.
**Type:** `uint16` · **Default:** `1` (highest/lowest-numbered priority
`tc` allows)

### Transport checks on the selected interfaces

`galactic-cni run` checks every selected interface, however it was chosen,
against the [transport contract](../designs/vlan-transport/contract.md#validation)
before it attaches. It refuses to start on a named interface that does not
exist, a VLAN with ID 0, an 802.1ad VLAN, a VLAN stacked on another VLAN, or
a VLAN whose parent is missing, is a bond member, or is not a NIC or bond.

While running, it re-checks on every health check (every 10 seconds) and on
every change to the attached set. A failure then is reported once until it
changes or clears, and does not detach anything.

| Signal | What it shows |
| ---------------------------------------------- | ----------------------------------------------------------------------------------- |
| `galactic_transport_side_info` | Each selected interface's derived mode, VLAN ID and parent, always 1 |
| `galactic_transport_side_changes_total` | Changes since the last check, such as `recreated` or `members_changed`, by `reason` |
| `galactic_transport_validation_failures_total` | Distinct refusals, by the contract rule in `reason` |

The log lines `transport: resolved side` and `transport: side changed` carry
the same state, with each interface's members.

## `GALACTIC_CNI_TCP_MSS_CLAMP`

Sets the fabric MTU the uSID datapath sizes tenant traffic to. A tenant
Expand Down
4 changes: 3 additions & 1 deletion docs/designs/vlan-transport/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ Seamless live migration is not assumed. Each change below affects only the side
| VLAN netdevice recreated with the same ID and parent | Restart the same components | As above |
| Bond member replaced or failed | No action; hooks follow bond membership | Bounded by bond failover, measured against the untagged baseline |

A restart must leave no stale hooks, routes or map rows that name the old netdevice. `galactic-gateway` already re-resolves its targets on netlink changes (`watchTargets`, `cmd/galactic-gateway/gateway.go:550`); [#1404](https://github.com/datum-cloud/galactic/issues/1404) may replace restarts with reconciliation, and then updates this table. Rollback is the same procedure with the old values.
A restart must leave no stale hooks, routes or map rows that name the old netdevice. Rollback is the same procedure with the old values.

Each component also reconciles a change that keeps the selected names. On a netlink link event, `galactic-cni`'s watch loop re-attaches `usid_ingress` by name and rewrites `transport_vlan_table`, and `galactic-gateway` and `galactic-nat` re-resolve their XDP targets and rewrite `vlan_egress`. All three derive the side through `internal/plumbing/transport` and rewrite each ifindex-keyed map in full, so a deleted VLAN's row goes away and a reused ifindex never keeps another device's tag context. Each reports the derived side and every change (`recreated`, `vlan_id_changed`, `parent_changed`, `members_changed`, `mode_changed`) in its log and in `galactic_transport_side_changes_total`, and each refusal in `galactic_transport_validation_failures_total`. Root tests cover the map rewrite after recreation; recovery time without a restart is unmeasured until [#1405](https://github.com/datum-cloud/galactic/issues/1405)'s lab pass, so the restart above stays the documented procedure.

## 6. Supported topologies

Expand Down
1 change: 1 addition & 0 deletions docs/observability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ the fabric-api gateway are Deployments, scraped per pod.
| VPC ingress return path | `galactic-cni` (`credential-refresh`) | `galactic_sidecar_return_*` | 9180 | `galactic-cni` |
| VPC ingress backends | `galactic-cni` (`credential-refresh`) | `galactic_endpointslice_repair_*` | 9180 | `galactic-cni` |
| VPC host link repair | `galactic-cni` (`credential-refresh`) | `galactic_cni_host_link*` | 9180 | `galactic-cni` |
| Transport sides (VLAN) | `galactic-cni` (`credential-refresh`) | `galactic_transport_*` | 9180 | `galactic-cni` |
| Edge load balancer | `galactic-gateway` | `galactic_edge_*`, controller-runtime | 8081 | none shipped |
| Tenant routing (GoBGP) | `galactic-router`, `galactic-router-rr` | `galactic_router_*`, controller-runtime | 9179 | `galactic-router` / `galactic-router-rr` |
| Private service routes | `galactic-router` (plain mode only) | `galactic_service_route_*` | 9179 | `galactic-router` |
Expand Down
8 changes: 8 additions & 0 deletions internal/config/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const (
// ambiguous.
EnvCNIEBPFInterfaces = "GALACTIC_CNI_EBPF_INTERFACES"

// EnvCNIEBPFInterfacesByNode gives individual nodes their own
// EnvCNIEBPFInterfaces list: entries separated by semicolons or newlines,
// each "node=iface[,iface...]". A listed node's entry replaces the
// cluster-wide list; other nodes keep it. It lets one DaemonSet name a
// tagged transport side where the same interface plays a different side on
// another node. Read only by galactic-cni init and run.
EnvCNIEBPFInterfacesByNode = "GALACTIC_CNI_EBPF_INTERFACES_BY_NODE"

// EnvCNIEBPFFilterPriority overrides the tc priority the uSID datapath's
// ingress filter attaches at, the default being the highest tc allows. A
// cluster CNI may run its own programs on the same hook, and that default
Expand Down
15 changes: 14 additions & 1 deletion internal/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ func Bootstrap(ctx context.Context, nodeName string) error {
logLevel := resolveLogLevel()
egressShardSIDs := resolveEgressShardSIDs()
nat64Prefix := resolveNAT64Prefix()
if err := applyNodeInterfaces(nodeName); err != nil {
return err
}
ebpfInterfaces := resolveEBPFInterfaces()
danDir := os.Getenv(config.EnvCNIDANDir)
conflistContent := renderConflist(&hostconf.HostConf{
Expand Down Expand Up @@ -554,6 +557,13 @@ func startEBPFDatapath(ctx context.Context, m *metrics.Metrics) (ebpfDatapathSta

attach.SetHooks(m.Events.Hooks())

if err := applyNodeInterfaces(""); err != nil {
return ebpfDatapathState{}, nil, err
}
if err := checkTransport(); err != nil {
return ebpfDatapathState{}, nil, fmt.Errorf("eBPF datapath interface selection: %w", err)
}

datapath, ifaces, watcher, err := ebpfStartFn(ctx, attach.PinDir)
if err != nil {
return ebpfDatapathState{}, nil, fmt.Errorf("start eBPF uSID datapath: %w", err)
Expand All @@ -568,7 +578,7 @@ func startEBPFDatapath(ctx context.Context, m *metrics.Metrics) (ebpfDatapathSta
state.sidecarReturn = m.SidecarReturn
state.endpointSliceRepair = m.EndpointSliceRepair
m.Egress.SetMode(string(egressCfg.Mode), string(config.EgressModeOrdered), string(config.EgressModeHashed))
watcher.OnChange(rewriteEBPFInterfaces)
watcher.OnChange(onAttachedSetChange)

// The closer is the loaded objects in production. A test fake stands in a
// plain mock closer, which correctly leaves the metrics, health, and GC
Expand Down Expand Up @@ -1431,6 +1441,9 @@ func reportEBPFHealth(st ebpfDatapathState, healthSrv *health.Server, lastHealth
if st.objs == nil {
return
}
// The watcher reports only a changed set of names; a VLAN recreated under
// the same name, a new VLAN ID or a replaced bond member shows up here.
recheckTransport()
h := attach.Handle{Objs: st.objs, Watcher: st.watcher}
healthErr := h.Healthy()
healthy := healthErr == nil
Expand Down
Loading
Loading