From a89445ca5982b501d79394ac0cc22c88c61edcd0 Mon Sep 17 00:00:00 2001 From: George Rubin Date: Sun, 29 Nov 2026 11:31:11 +0200 Subject: [PATCH] xfrm: parse state direction and IP-TFS counters from xfrm_stat Linux 6.10 added XfrmInStateDirError and XfrmOutStateDirError, and Linux 6.14 added XfrmInIptfsError and XfrmOutNoQueueSpace to /proc/net/xfrm_stat. NewXfrmStat silently dropped them. Add them so XfrmStat covers every counter in the kernel's xfrm_mib_list. Co-Authored-By: Claude Opus 5.5 Signed-off-by: George Rubin --- net_xfrm.go | 18 ++++++++++++++++++ net_xfrm_test.go | 4 ++++ testdata/fixtures.ttar | 6 +++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/net_xfrm.go b/net_xfrm.go index 5a9f497d..204ff193 100644 --- a/net_xfrm.go +++ b/net_xfrm.go @@ -86,6 +86,16 @@ type XfrmStat struct { XfrmOutStateInvalid int // State hasn’t been fully acquired before use XfrmAcquireError int + // State direction mismatch + // i.e. lookup found an input state on the output path + XfrmOutStateDirError int + // State direction mismatch + // i.e. lookup found an output state on the input path + XfrmInStateDirError int + // IP-TFS inbound packet processing error + XfrmInIptfsError int + // IP-TFS outbound queue is full + XfrmOutNoQueueSpace int } // NewXfrmStat reads the xfrm_stat statistics. @@ -181,6 +191,14 @@ func (fs FS) NewXfrmStat() (XfrmStat, error) { x.XfrmOutStateInvalid = value case "XfrmAcquireError": x.XfrmAcquireError = value + case "XfrmOutStateDirError": + x.XfrmOutStateDirError = value + case "XfrmInStateDirError": + x.XfrmInStateDirError = value + case "XfrmInIptfsError": + x.XfrmInIptfsError = value + case "XfrmOutNoQueueSpace": + x.XfrmOutNoQueueSpace = value } } diff --git a/net_xfrm_test.go b/net_xfrm_test.go index d3bbbfe0..ddf73fbb 100644 --- a/net_xfrm_test.go +++ b/net_xfrm_test.go @@ -56,6 +56,10 @@ func TestXfrmStats(t *testing.T) { {name: "XfrmFwdHdrError", want: 6654, got: xfrmStats.XfrmFwdHdrError}, {name: "XfrmOutStateInvaliad", want: 28765, got: xfrmStats.XfrmOutStateInvalid}, {name: "XfrmAcquireError", want: 24532, got: xfrmStats.XfrmAcquireError}, + {name: "XfrmOutStateDirError", want: 11, got: xfrmStats.XfrmOutStateDirError}, + {name: "XfrmInStateDirError", want: 12, got: xfrmStats.XfrmInStateDirError}, + {name: "XfrmInIptfsError", want: 13, got: xfrmStats.XfrmInIptfsError}, + {name: "XfrmOutNoQueueSpace", want: 14, got: xfrmStats.XfrmOutNoQueueSpace}, {name: "XfrmInStateInvalid", want: 55555, got: xfrmStats.XfrmInStateInvalid}, {name: "XfrmOutError", want: 1000000, got: xfrmStats.XfrmOutError}, } { diff --git a/testdata/fixtures.ttar b/testdata/fixtures.ttar index 8be35d96..e879f873 100644 --- a/testdata/fixtures.ttar +++ b/testdata/fixtures.ttar @@ -2983,7 +2983,7 @@ Inter-| sta-| Quality | Discarded packets | Missed Mode: 644 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Path: fixtures/proc/net/xfrm_stat -Lines: 28 +Lines: 32 XfrmInError 1 XfrmInBufferError 2 XfrmInHdrError 4 @@ -3012,6 +3012,10 @@ XfrmOutPolError 1454 XfrmFwdHdrError 6654 XfrmOutStateInvalid 28765 XfrmAcquireError 24532 +XfrmOutStateDirError 11 +XfrmInStateDirError 12 +XfrmInIptfsError 13 +XfrmOutNoQueueSpace 14 Mode: 644 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: fixtures/proc/pressure