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
48 changes: 46 additions & 2 deletions cmd/galactic-gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import (
"slices"
"sync"

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

"go.datum.net/galactic/internal/config"
"go.datum.net/galactic/internal/gateway"
"go.datum.net/galactic/internal/plumbing/ebpf/edgeattach"
"go.datum.net/galactic/internal/plumbing/ebpf/edgemetrics"
"go.datum.net/galactic/internal/plumbing/ebpf/edgeprog"
"go.datum.net/galactic/internal/plumbing/ebpf/vlanegress"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpattach"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpdispatch"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpmode"
Expand Down Expand Up @@ -294,11 +297,51 @@ func installGateway(
missing = append(missing, returnSet.reconcile(ctx, returnTargets)...)
}
coverage.set(missing)
go watchTargets(ctx, publicInterface, internalInterfaces, publicSet, returnSet, coverage, ipv4)
syncVLANEgress(objs.VlanEgress, publicInterface, internalInterfaces, true)
go watchTargets(ctx, publicInterface, internalInterfaces, publicSet, returnSet, coverage, ipv4, objs.VlanEgress)

return nil
}

// syncVLANEgress fills edgedsr.c's vlan_egress from the gateway's configured
// sides: the public interface and every internal interface that is a VLAN
// netdevice. A route the datapath resolves through one of them leaves through
// 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)
if err != nil {
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 {
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)
}
}
}

// 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 @@ -566,9 +609,10 @@ func (c *datapathCoverage) configure(targets []string) []string {
// resolution failure, such as a bond in the moment between losing a member and
// enslaving its replacement, keeps every attachment and skips that pass.
func watchTargets(ctx context.Context, publicInterface string, internalInterfaces []string,
publicSet, returnSet targetSet, coverage *datapathCoverage, ipv4 *ipv4Forwarding,
publicSet, returnSet targetSet, coverage *datapathCoverage, ipv4 *ipv4Forwarding, vlanEgress *ebpf.Map,
) {
xdpattach.OnNetlinkChange(ctx, func() {
syncVLANEgress(vlanEgress, publicInterface, internalInterfaces, false)
var (
targets []string
err error
Expand Down
37 changes: 37 additions & 0 deletions cmd/galactic-nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.datum.net/galactic/internal/plumbing/ebpf/natattach"
"go.datum.net/galactic/internal/plumbing/ebpf/natmap"
"go.datum.net/galactic/internal/plumbing/ebpf/natprog"
"go.datum.net/galactic/internal/plumbing/ebpf/vlanegress"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpattach"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpdispatch"
"go.datum.net/galactic/internal/plumbing/ebpf/xdpmode"
Expand Down Expand Up @@ -85,6 +86,10 @@ type natDatapath struct {
// resolveErrors counts watchUplinks' failed re-resolutions, which keep
// the previous coverage. Nil counts nothing.
resolveErrors prometheus.Counter

// vlanEgress is nat.c's vlan_egress, which syncVLANEgress keeps in step
// with the resolved uplinks. Nil skips it.
vlanEgress *ebpf.Map
}

// Attached reports whether startup completed its load and attach pass. It is
Expand Down Expand Up @@ -344,6 +349,8 @@ func setupNatDatapath(ctx context.Context, cfg *config.NATConfig,
// translating established flows until the first reconcile re-derives it
// 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)

var (
set *xdpattach.Set
Expand Down Expand Up @@ -398,6 +405,35 @@ func setupNatDatapath(ctx context.Context, cfg *config.NATConfig,
return d, nil
}

// syncVLANEgress fills nat.c's vlan_egress from the resolved uplinks: every
// 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) {
if d.vlanEgress == nil {
return
}
lowers, ifindexes, err := vlanegress.FromNetlink(uplinks)
if err != nil {
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 {
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)
}
}
}

// 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 @@ -531,6 +567,7 @@ func (d *natDatapath) watchUplinks(ctx context.Context, override []string, cover
}
return
}
d.syncVLANEgress(uplinks, false)
ready := d.adoptUplinks(uplinks)

missing := uncovered(uplinks, cover(ready))
Expand Down
Loading
Loading