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
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,10 @@ flows_through() {
}

# mapping GATEWAY prints "port backend" for each fixed UDP source port
# through GATEWAY. One TCP request goes first: edge_lb drops a packet whose
# next hop has no neighbor entry yet (fib_no_neigh), and only TCP's
# retransmits ride that out, so on a path idle long enough for the entry to
# expire the first UDP probes would be lost for a reason this check does not
# test.
# through GATEWAY.
mapping() {
local p
pin "$1"
pick_port
request tcp "${PORT_PICKED}" >/dev/null
for p in "${PORTS[@]}"; do
echo "${p} $(request udp "${p}")"
done
Expand Down
10 changes: 9 additions & 1 deletion docs/agents/ARCHITECTURE-GATEWAY.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,15 @@ forward half, so it has exactly one branch, not two. Replies are
differ on every gateway that reaches its clients and its compute nodes over
separate links, which is this role's normal shape — see [Known
Constraints](#known-constraints) for the bug that came from returning
`XDP_TX` unconditionally. The inner packet travels completely unmodified —
`XDP_TX` unconditionally. A next hop with no neighbor entry, as after a
link flap or a node rejoining the fabric, sends the encapsulated packet to
the kernel with `XDP_PASS` instead, since XDP cannot start neighbor
resolution: the kernel solicits the neighbor and forwards the packet, and
later packets stay in XDP. Those packets are counted in `neigh_fallbacks`
(`galactic_edge_neigh_fallbacks_total`), not as drops. Unlike the XDP
path, they cross the node's netfilter FORWARD hook, as new flows from the
node's own encapsulation source, so a host firewall that drops forwarded
traffic drops them too. The inner packet travels completely unmodified —
this is DSR's entire premise: no address or port rewriting and no checksum
touch anywhere.

Expand Down
6 changes: 5 additions & 1 deletion docs/gateway/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,11 @@ Relevant series: `galactic_edge_rule_packets_total`,
by `reason`; `ipv4_fragment` counts IPv4 fragments addressed to a VIP, which
are dropped because a later fragment has no ports to pick a backend by;
the drop applies to any TCP or UDP port on a VIP address, and it is not
counted in a VIP's own dropped packets because the port is unknown), and `galactic_edge_control_plane_drops_total` (rule
counted in a VIP's own dropped packets because the port is unknown),
`galactic_edge_neigh_fallbacks_total` (load-balanced packets handed to the
kernel because the next hop toward the backend had no neighbor entry, for it
to resolve the neighbor and forward them; not counted as drops), and
`galactic_edge_control_plane_drops_total` (rule
applications rejected before ever reaching the datapath, e.g. quota
denials). In dispatch mode, `galactic_edge_dispatch_lease_renewals_total`
(labeled by `slot` and `result`) and
Expand Down
10 changes: 10 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ so there is no connection table to report. See
| `galactic_edge_return_bytes_total` | counter | same | Bytes of those replies |
| `galactic_edge_return_dropped_packets_total` | counter | same | Replies sourced from the VIP that the datapath dropped. A subset of `return_packets_total` |
| `galactic_edge_drops_total` | counter | `reason` | Packets `edge_lb` and `edge_return` dropped, by reason |
| `galactic_edge_neigh_fallbacks_total` | counter | none | Packets `edge_lb` handed to the kernel to resolve the next hop. Not counted as drops |
| `galactic_edge_control_plane_drops_total` | counter | `rule`, `reason` (`quota_exceeded`) | Rule applications refused before they reached the datapath |
| `galactic_edge_dispatch_lease_renewals_total` | counter | `slot`, `result` | Renewals of the gateway's XDP dispatcher slot leases. Dispatch mode only |
| `galactic_edge_dispatch_lease_expiry_timestamp_seconds` | gauge | `slot` | Unix time each lease, as last renewed, expires. Dispatch mode only |
Expand All @@ -650,6 +651,15 @@ so there is no connection table to report. See
`fib_lookup_failed`, `adjust_head_failed`, `no_egress_ifindex`,
`redirect_failed`, `return_hop_limit`, `icmp_rate_limited`, plus
`unknown_<n>` for an index the binary has no name for.
- `fib_no_neigh` counts only replies `edge_return` forwards and ICMP errors
the gateway sends. A load-balanced packet whose next hop has no neighbor
entry goes to the kernel, which resolves the neighbor and forwards it, and
is counted in `galactic_edge_neigh_fallbacks_total` instead. That counter
rises briefly after a link or node rejoins the fabric. Steady growth means
neighbor entries keep expiring or a next hop does not answer, and the
kernel drops what it cannot resolve. The counter records the handoff, not
delivery: these packets cross the node's netfilter FORWARD hook, unlike the
XDP path, so a host firewall that drops forwarded traffic drops them too.

The port also serves controller-runtime's metrics for the
`NetworkGateway`/`NetworkService` reconcilers.
Expand Down
43 changes: 39 additions & 4 deletions internal/plumbing/ebpf/edgemetrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type VPCAttribution interface {
// counters and drops by reason. There is no connection table here at all, direct
// server return keeping no per-flow state to report.
type Collector struct {
vipTable *edgemap.VIPTable
dropReasons DropReasonsReader
attribution VPCAttribution
vipTable *edgemap.VIPTable
dropReasons DropReasonsReader
neighFallbacks DropReasonsReader
attribution VPCAttribution
}

// NewCollector builds a Collector from already-constructed values, so tests can
Expand All @@ -56,6 +57,13 @@ func NewCollector(vipTable *edgemap.VIPTable, dropReasons DropReasonsReader, att
return &Collector{vipTable: vipTable, dropReasons: dropReasons, attribution: attribution}
}

// WithNeighFallbacks adds the neigh_fallbacks map, a single-entry per-CPU
// array, as galactic_edge_neigh_fallbacks_total.
func (c *Collector) WithNeighFallbacks(m DropReasonsReader) *Collector {
c.neighFallbacks = m
return c
}

// NewCollectorFromObjects builds a Collector reading directly from a loaded
// object set's maps.
func NewCollectorFromObjects(objs *edgeprog.EdgedsrObjects, attribution VPCAttribution) *Collector {
Expand All @@ -65,7 +73,7 @@ func NewCollectorFromObjects(objs *edgeprog.EdgedsrObjects, attribution VPCAttri
edgemap.KernelTable{Map: objs.VipAddrTable}, edgemap.KernelTable{Map: objs.VipReturnStatsTable}),
objs.DropReasons,
attribution,
)
).WithNeighFallbacks(objs.NeighFallbacks)
}

const (
Expand Down Expand Up @@ -120,6 +128,15 @@ var (
"direction.",
[]string{"reason"}, nil,
)
neighFallbacksDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "neigh_fallbacks_total"),
"Encapsulated packets edge_lb handed to the kernel because the next hop toward the "+
"backend had no neighbor entry, for the kernel to resolve the neighbor and forward them. "+
"Counts the handoff, not delivery: the kernel drops what it cannot resolve, and these "+
"packets cross the node's netfilter FORWARD hook, where a host firewall can drop them. "+
"Not counted in drops_total.",
nil, nil,
)
returnPacketsDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "return", "packets_total"),
"Reply packets this node forwarded for traffic sourced from this VIP, bypassing the kernel "+
Expand Down Expand Up @@ -149,6 +166,7 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- ruleBackendsDesc
ch <- ruleSecondsSinceLastPacketDesc
ch <- dropsDesc
ch <- neighFallbacksDesc
ch <- returnPacketsDesc
ch <- returnBytesDesc
ch <- returnDroppedDesc
Expand All @@ -159,6 +177,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.collectRules(ch)
c.collectReturn(ch)
c.collectDrops(ch)
c.collectNeighFallbacks(ch)
}

// vpcs snapshots the attribution. Callers take it after listing a map: the
Expand Down Expand Up @@ -257,3 +276,19 @@ func (c *Collector) collectDrops(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(dropsDesc, prometheus.CounterValue, float64(total), name)
}
}

func (c *Collector) collectNeighFallbacks(ch chan<- prometheus.Metric) {
if c.neighFallbacks == nil {
return
}
var perCPU []uint64
if err := c.neighFallbacks.Lookup(uint32(0), &perCPU); err != nil {
ch <- prometheus.NewInvalidMetric(neighFallbacksDesc, fmt.Errorf("lookup neigh_fallbacks: %w", err))
return
}
var total uint64
for _, v := range perCPU {
total += v
}
ch <- prometheus.MustNewConstMetric(neighFallbacksDesc, prometheus.CounterValue, float64(total))
}
16 changes: 16 additions & 0 deletions internal/plumbing/ebpf/edgemetrics/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,22 @@ func TestCollector_CollectsDropsByReason(t *testing.T) {
}
}

// TestCollector_CollectsNeighFallbacks covers the packets edge_lb handed to the
// kernel for neighbor resolution, which are counted apart from every drop.
func TestCollector_CollectsNeighFallbacks(t *testing.T) {
vt := edgemap.NewVIPTable(
newFakeVIPTable(), newFakeStatsTable(), newFakeAddrTable(), newFakeReturnStatsTable())
c := NewCollector(vt, fakeDropReasons{}, nil).WithNeighFallbacks(fakeDropReasons{0: 5})
metrics := collect(t, c)

if got := metricValue(findMetric(t, metrics, neighFallbacksDesc, "", "")); got != 5 {
t.Errorf("neigh_fallbacks_total = %v, want 5", got)
}
if got := metricValue(findMetric(t, metrics, dropsDesc, "reason", "fib_no_neigh")); got != 0 {
t.Errorf("drops_total{reason=fib_no_neigh} = %v, want 0", got)
}
}

// TestCollector_CollectsReturnCounters covers the return path's own counters.
// They are keyed by VIP address alone, with no port or protocol, since
// edge_return matches a reply on its source address -- so one series covers
Expand Down
50 changes: 48 additions & 2 deletions internal/plumbing/ebpf/edgeprog/edgedsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
// ingress interface, bpf_redirect and XDP_REDIRECT where it is not. The
// two differ on every gateway that reaches its clients and its compute
// nodes over different links, which is this role's normal shape.
// Where the next hop has no neighbor entry, the encapsulated packet goes
// to the kernel instead, which resolves the neighbor and forwards it;
// see push_outer_header.
// 7. A packet the route refuses for size, too big once the outer header is
// on, is answered with an ICMPv6 Packet Too Big, or for an IPv4 packet
// with Don't Fragment set an ICMPv4 Fragmentation Needed, to the client
Expand Down Expand Up @@ -364,6 +367,16 @@ struct {
__type(value, __u64);
} drop_reasons SEC(".maps");

// neigh_fallbacks counts the encapsulated packets edge_lb passed to the kernel
// because their next hop had no neighbor entry; see push_outer_header. They
// are not drops, so they have their own map rather than a drop_reasons bucket.
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, __u64);
} neigh_fallbacks SEC(".maps");

// struct icmp_bucket is one CPU's token bucket, held as nanoseconds of credit
// rather than whole tokens so a refill is an addition, with no division on the
// packet path: each message costs EDGE_ICMP_COST_NS, and credit accrues one
Expand Down Expand Up @@ -648,11 +661,31 @@ static EDGE_ALWAYS_INLINE long resolve_fib4_and_write_eth(void *ctx, __u32 ifind
//
// outer_payload_len is the whole inner packet's length, header included, and
// nexthdr says what that packet is: EDGE_IPPROTO_IPV6 or EDGE_IPPROTO_IPIP.
//
// A next hop with no neighbor entry is not a failure. XDP has no way to start
// neighbor resolution, so a drop here repeats for every packet until something
// else resolves the neighbor, as after a link flap, a neighbor table purge or
// a gateway restart, for as long as the kernel takes to notice. The
// encapsulated packet goes to the kernel instead, framed as the original was
// so the stack takes it as addressed to this host: the kernel forwards it to
// the backend's uSID, queuing it while it solicits the neighbor, and every
// later packet finds the entry and stays in XDP. That case returns
// EDGE_PUSH_TO_KERNEL and is counted in neigh_fallbacks, not as a drop.
#define EDGE_PUSH_TO_KERNEL 1

static EDGE_ALWAYS_INLINE int push_outer_header(struct xdp_md *ctx, const __u8 src[16],
const __u8 dst[16], __be16 outer_payload_len, __u8 nexthdr,
struct vip_stats_value *stats, __u32 *egress_ifindex,
__u16 *frag_mtu)
{
struct edge_ethhdr orig_eth;
void *orig = (void *) (long) ctx->data;
if (orig + sizeof(orig_eth) > (void *) (long) ctx->data_end) {
count_claimed_drop(DROP_REASON_ADJUST_HEAD_FAILED, stats);
return -1;
}
__builtin_memcpy(&orig_eth, orig, sizeof(orig_eth));

if (bpf_xdp_adjust_head(ctx, -40) != 0) {
count_claimed_drop(DROP_REASON_ADJUST_HEAD_FAILED, stats);
return -1;
Expand Down Expand Up @@ -685,6 +718,16 @@ static EDGE_ALWAYS_INLINE int push_outer_header(struct xdp_md *ctx, const __u8 s
long fib_rc = resolve_fib_and_write_eth(ctx, ctx->ingress_ifindex, src, dst,
(__u16) (sizeof(*outer) + __builtin_bswap16(outer_payload_len)),
eth, egress_ifindex, frag_mtu);
if (fib_rc == BPF_FIB_LKUP_RET_NO_NEIGH) {
__builtin_memcpy(eth->h_dest, orig_eth.h_dest, sizeof(eth->h_dest));
__builtin_memcpy(eth->h_source, orig_eth.h_source, sizeof(eth->h_source));
eth->h_proto = __builtin_bswap16(EDGE_ETH_P_IPV6);
__u32 key = 0;
__u64 *counter = bpf_map_lookup_elem(&neigh_fallbacks, &key);
if (counter)
*counter += 1;
return EDGE_PUSH_TO_KERNEL;
}
if (fib_rc != BPF_FIB_LKUP_RET_SUCCESS) {
count_fib_drop(fib_rc, stats);
return -1;
Expand Down Expand Up @@ -944,8 +987,11 @@ static EDGE_ALWAYS_INLINE int lb_forward(struct xdp_md *ctx, struct vip_value *r
// checksum touch, the client's packet travelling inside untouched to the
// backend, which replies to the client directly.
__u32 egress_ifindex = 0;
if (push_outer_header(ctx, cfg->encap_src, b->usid, outer_payload_len, nexthdr, stats,
&egress_ifindex, frag_mtu) != 0)
int pushed = push_outer_header(ctx, cfg->encap_src, b->usid, outer_payload_len, nexthdr, stats,
&egress_ifindex, frag_mtu);
if (pushed == EDGE_PUSH_TO_KERNEL)
return XDP_PASS;
if (pushed != 0)
return -1;
return leave_via(ctx, egress_ifindex, stats);
}
Expand Down
Loading
Loading