Checksum the header and refuse sequence numbers the sender never sent

This commit is contained in:
flamingcow
2026-08-04 20:41:16 -07:00
parent 703039587b
commit 1d54a1a1f6
9 changed files with 241 additions and 35 deletions
+15 -6
View File
@@ -169,6 +169,7 @@ type sample struct {
rxFrames, rxBytes uint64
lost, late uint64
crcErr, badMagic uint64
badHdr uint64
badLen uint64
txErrs uint64
rxErrs uint64
@@ -204,6 +205,7 @@ func (d *direction) snapshot() sample {
s.rxBytes += r.bytes.Load()
s.crcErr += r.crcErr.Load()
s.badMagic += r.badMagic.Load()
s.badHdr += r.badHdr.Load()
s.badLen += r.badLen.Load()
s.rxErrs += r.rxErrs.Load()
}
@@ -279,10 +281,11 @@ type view struct {
func errsBetween(b, n counterSet) errs {
return errs{
lost: n.s.lost - b.s.lost,
// Three ways of noticing one thing: a payload that does not match its
// checksum, a header that is not ours, and a length that cannot be.
corrupt: (n.s.crcErr - b.s.crcErr) + (n.s.badMagic - b.s.badMagic) +
(n.s.badLen - b.s.badLen),
// Four ways of noticing one thing: a payload that does not match its
// checksum, a header that does not match its own, a header that is not
// ours, and a length that cannot be.
corrupt: (n.s.crcErr - b.s.crcErr) + (n.s.badHdr - b.s.badHdr) +
(n.s.badMagic - b.s.badMagic) + (n.s.badLen - b.s.badLen),
// What the hardware reported. Nothing the host declined to send is here,
// so this one going red means the cable.
link: (n.nic - b.nic) + (n.s.rxErrs - b.s.rxErrs),
@@ -372,8 +375,15 @@ func (d *direction) primeCounters() {
}
func buildDirection(label string, tx, rx endpoint) (*direction, error) {
// Built before the windows, since each window judges sequence numbers against
// the frontier its own sender publishes.
txs := make([]*txStats, numStreams)
for i := range txs {
txs[i] = &txStats{}
}
d := &direction{
streams: newLossWindows(numStreams),
txStats: txs,
streams: newLossWindows(txs),
cable: newCableStats(),
}
// Held open for the life of the run: the stats ioctl is issued five times a
@@ -399,7 +409,6 @@ func buildDirection(label string, tx, rx endpoint) (*direction, error) {
return nil, fmt.Errorf("%s tx socket: %w", label, err)
}
d.txFDs = append(d.txFDs, fd)
d.txStats = append(d.txStats, &txStats{})
fd, err = openRxSocket(rx.idx, et)
if err != nil {