Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 28 additions & 0 deletions docs/netlink/gotc-status.md

Large diffs are not rendered by default.

884 changes: 880 additions & 4 deletions docs/netlink/upstream/iproute2-tc-action-write.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion docs/netlink/upstream/iproute2-tc-action.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# iproute2 `tc actions` and action printers: totals that aren't totals, JSON that drops or doubles keys, spacing by kind, and reads tc never checked

**Status (2026-11-24, increment 12; extended 2026-11-25, increment 13; extended 2026-11-30, increment 22):**
**Status (2026-11-24, increment 12; extended 2026-11-25, increment 13; extended 2026-11-30, increments 22 and 23):**

- **The write side** of these twelve kinds and m_action.c is
[iproute2-tc-action-write.md](iproute2-tc-action-write.md) (W156–W215, K63–K76). Increment 22 extends AC6, AC7,
AC33, AC34 (a correction) and AC70 and K8 below, each marked "Extended in increment 22".
Increment 23 (W216–W320, the same file's "Increment 23" part) extends AC38 and AC70, each marked "Extended in
increment 23".
- **Not submitted to netdev.** These are drafts for the user's review, recorded here only, like the other write-ups in
this directory. No patch, no PR, no sign-off.
- **Source:**
Expand Down Expand Up @@ -212,6 +214,7 @@
actions (K8) and exits 0.
- **gotc:** it refuses a get whose request would pass `MAX_MSG`, naming its length, rather than send a truncated
request.
- **Extended in increment 23:** the write side ignores addattr's result the same way: pedit's 16 KiB echo (W248, tcact2write ng-157), gate's 1024 entry nest (W293) and bpf past 16384 (W307). See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).

## AC4, AC5, AC11. The writes' messages

Expand Down Expand Up @@ -353,6 +356,7 @@ no NUL, a skbmod MAC of length 0 or over 21, and a tab of more than 1024 orders.
[iproute2-tc-action-write.md](iproute2-tc-action-write.md)): every `set` writes `dst MAC address <…>`, `src MAC
address <…>` or `skbmod etype 0x…` to stderr (tcactwrite/ec-202–ec-204, ng-062). gotc copies skbmod's lines (22W);
ife stays refused until increment 23.
- **Extended in increment 23:** ife's decode prints the same stderr lines for dst, type and allow, though it drops them (W273, tcact2write ec-146). See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).

## AC54–AC58. ct

Expand Down
9 changes: 8 additions & 1 deletion docs/netlink/upstream/iproute2-tc-filter-write.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# iproute2 tc filter writes: narrowed selectors, a renamed check, sticky cookies and a realm cache that answers with the wrong number

**Status (2026-11-29, increment 20; extended 2026-11-30, increment 22):**
**Status (2026-11-29, increment 20; extended 2026-11-30, increments 22 and 23):**

- **Increment 22** extends W65, W68, W74, W75, W85, W113, W114, W117 and W121 below, each marked "Extended in
increment 22", from the action write-up [iproute2-tc-action-write.md](iproute2-tc-action-write.md).
- **Increment 23** extends W70, W95, W97, W114 and W117, each marked "Extended in increment 23", from the same file's
"Increment 23" part (W216–W320).
- **Not submitted to netdev.** These are drafts for the user's review, recorded here only, like the other write-ups in
this directory. No patch, no PR, no sign-off.
- **Scope:** the write path of `tc filter` and `tc chain` (`tc/tc_filter.c` tc_filter_modify, which `chain add` and
Expand Down Expand Up @@ -140,6 +142,7 @@
reports only `Cannot find device "nosuch"`, rc 1 (ng-005), and the parser's error is never seen. Exit codes by
path: a missing device and every parse_fopt failure (its `help` too) 1; modify's own checks, invarg, duparg and
NEXT_ARG 255; a kernel error 2; top-level `help` 0.
- **Extended in increment 23:** the bpf filter's parse failures (`What is "X"?`, `Illegal "classid"`, `Unable to parse bpf command line`) take rc 1 by the same path (W319; tcact2write ng-147–ng-149, ng-152). See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).
- **W72.** m_estimator.c calls `invarg("invalid estimator interval", *argv)` with the arguments in the wrong order
for `invarg(msg, arg)`, so `estimator zz 1s` prints `Error: argument "invalid estimator interval" is wrong:
estimator`, rc 255 (ng-007). The same line serves qdisc and class writes; W7 looked only at the argv step.
Expand Down Expand Up @@ -209,6 +212,7 @@
1:2` installs 1:2 (ec-097). u32's `ht`, `order` and flags take the last value locally.
- **Increment 21:** basic and cgroup don't check either. A second classid or `match` wins (tcematch ec-136), and
with both police and action the kernel keeps the police alone (K59, ec-139) ([iproute2-tc-ematch-write.md](iproute2-tc-ematch-write.md)).
- **Extended in increment 23:** cls_bpf has no repeat check either: a second classid is sent as a second TCA_BPF_CLASSID (W317, tcact2write ec-245). See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).

## W96–W109. fw, route, matchall and flow

Expand All @@ -220,6 +224,7 @@
the -1 and the request goes out without that attribute. gotc refuses a request tc would truncate (W6's rule).
- **Increment 21:** a large flow `match` hits the same bound: tcematch ec-137's two 300-rule canids send a 4900-byte
request without MODE, DIVISOR and BASECLASS, and its readback ends in EMSGSIZE (K62, [iproute2-tc-ematch-write.md](iproute2-tc-ematch-write.md)).
- **Extended in increment 23:** increment 23 meets the same ignored bound in actions: gate's per-entry nest is held to 1024 of the whole message (W293, tcact2write ec-196–ec-199), and a bpf program past 16384 drops PARMS or OPS (W307, tcact2write ng-120–ng-122). Since 23W gotc copies each addattr_l error and drop and sends what fits, here too. See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).
- **W98.** route's `order` is shifted and masked into the handle's 0x7F00 without a check: `order 200` is 72 in the
handle, 0xffff4804 (ec-098).
- **W99, W100.** route's explain says `fromif TAG` (a device name) and omits order, police and flowid (ng-023).
Expand Down Expand Up @@ -269,6 +274,7 @@
- **Extended in increment 22:** the kinds' own parsers hand words on as kinds too: mirred's `dev d1 blockid 5` reads
blockid as a kind (W161, ng-028), and ctinfo's unconsumed statemask `0x1junk` is `Bad action type 0x1junk` (W208,
ng-056), both in [iproute2-tc-action-write.md](iproute2-tc-action-write.md).
- **Extended in increment 23:** bpf takes `drop` as a mode word, not a gact control (W312, tcact2write ng-134). See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).
- **W115.** parse_action_control checks a jump count only against TC_ACT_EXT_VAL_MASK: `jump 0` and `jump 512` are
sent (ec-104, ec-105) and fail only at run time. A gact `random … goto chain 5` is built and sent; the workbench
kernel has no CONFIG_GACT_PROB (ng-038, EOPNOTSUPP).
Expand All @@ -283,6 +289,7 @@
order is another action: mirred redirect takes no control (W158), `skbedit mark 1 index 5 pipe` is skbedit then a
gact pipe (W175), and `simple sdata x index 5 drop` is two actions (W190), all in
[iproute2-tc-action-write.md](iproute2-tc-action-write.md).
- **Extended in increment 23:** gate's maxoctets keeps get_size's partial value past 32 bits and leaves the word, which starts the next action: `5G` becomes `Bad action type 5G` (W295). See [increment 23](iproute2-tc-action-write.md#increment-23-pedit-tunnel_key-ife-ct-gate-bpf-and-the-bpf-filter-w216w320-k77k89).
- **W118.** gact takes control, then random, then index: `action drop index 5 random determ pass 10` makes `random`
a new action (ng-041). After the control word, `h` is gact's help, rc 255 (ng-042), where parse_action would read
`h` as `hw_stats`.
Expand Down
11 changes: 11 additions & 0 deletions internal/gotc/act2_corpus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build gotc_write

package gotc

// tcact2writeDir is increment 23's capture space (23C). TestGotcCorpus
// replays it since 23W, with the rows refused by name in corpusRefused.
const tcact2writeDir = "../../pkg/xtcpnl/testdata/7_3_1/ws/tcact2write"

// act2Row is a tcact2write row id as awCase.row names it: a space/row id
// awReplayRow resolves.
func act2Row(id string) string { return "tcact2write/" + id }
57 changes: 37 additions & 20 deletions internal/gotc/act_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
// m_action.c parse_action (each action's prio nest, kind, options, cookie,
// hw_stats and flags), tc_util.c action_a2n and parse_action_control, and
// each kind's parse_aopt by name (actParsers: m_gact.c here, the 12 kinds
// of increment 22 in aw_*.go). pedit, tunnel_key, ife, ct, gate and bpf
// are refused by name until increment 23; an unknown name is
// get_action_kind's fallback to gact's parser, with the name kept as
// TCA_ACT_KIND (W114).
// of increment 22 and increment 23's six in aw_*.go). linkedActKinds'
// refusal by name stays for a kind tc links that gotc does not parse; an
// unknown name is get_action_kind's fallback to gact's parser, with the
// name kept as TCA_ACT_KIND (W114).

// actParser is an action_util's parse_aopt(a, &argc, &argv, tca_id, n):
// args starts at the kind word (for gact, possibly a control word); it
Expand All @@ -27,22 +27,39 @@ import (
// action parsing"; a non-nil error is an exit, or a refusal.
type actParser func(r *runner, ops *fops, args []string, tcaID uint16) (rest []string, ok bool, err error)

// actParsers are the parse_aopts gotc clones, by action_util id.
var actParsers = map[string]actParser{
xtcpnl.TcActKindGact: (*runner).parseGact,
xtcpnl.TcActKindPolice: (*runner).parsePoliceAct,
xtcpnl.TcActKindMirred: (*runner).parseMirred,
xtcpnl.TcActKindSkbedit: (*runner).parseSkbedit,
xtcpnl.TcActKindVlan: (*runner).parseVlan,
xtcpnl.TcActKindCsum: (*runner).parseCsum,
xtcpnl.TcActKindNat: (*runner).parseNat,
xtcpnl.TcActKindConnmark: (*runner).parseConnmark,
xtcpnl.TcActKindCtinfo: (*runner).parseCtinfo,
xtcpnl.TcActKindSample: (*runner).parseSample,
xtcpnl.TcActKindSkbmod: (*runner).parseSkbmod,
xtcpnl.TcActKindMpls: (*runner).parseMpls,
xtcpnl.TcActKindSimple: (*runner).parseSimple,
}
// actParsers are the parse_aopts gotc clones, by action_util id, built
// from a kind and parser list as action_util is.
var actParsers = func() map[string]actParser {
kinds := []struct {
kind string
parse actParser
}{
{xtcpnl.TcActKindGact, (*runner).parseGact},
{xtcpnl.TcActKindPolice, (*runner).parsePoliceAct},
{xtcpnl.TcActKindMirred, (*runner).parseMirred},
{xtcpnl.TcActKindSkbedit, (*runner).parseSkbedit},
{xtcpnl.TcActKindVlan, (*runner).parseVlan},
{xtcpnl.TcActKindCsum, (*runner).parseCsum},
{xtcpnl.TcActKindNat, (*runner).parseNat},
{xtcpnl.TcActKindConnmark, (*runner).parseConnmark},
{xtcpnl.TcActKindCtinfo, (*runner).parseCtinfo},
{xtcpnl.TcActKindSample, (*runner).parseSample},
{xtcpnl.TcActKindSkbmod, (*runner).parseSkbmod},
{xtcpnl.TcActKindMpls, (*runner).parseMpls},
{xtcpnl.TcActKindSimple, (*runner).parseSimple},
{xtcpnl.TcActKindTunnelKey, (*runner).parseTunnelKey},
{xtcpnl.TcActKindIfe, (*runner).parseIfe},
{xtcpnl.TcActKindBpf, (*runner).parseBpf},
{xtcpnl.TcActKindPedit, (*runner).parsePedit},
{xtcpnl.TcActKindCt, (*runner).parseCt},
{xtcpnl.TcActKindGate, (*runner).parseGate},
}
m := make(map[string]actParser, len(kinds))
for _, k := range kinds {
m[k.kind] = k.parse
}
return m
}()

// tcCookieMax is TC_COOKIE_MAX_SIZE.
const tcCookieMax = 16
Expand Down
2 changes: 1 addition & 1 deletion internal/gotc/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (r *runner) printActionControl(prefix string, a int32, suffix string) {
o.fp(prefix)
o.openObject("control_action")
t := actionN2A(a)
o.str(printAny, colorNone, "type", t, t)
o.str(printAny, colorNone, wordType, t, t)
v := cint.Bits(a) & tcActExtValMask
if a&^tcActExtValMask == tcActGotoChain {
o.uint(printAny, "chain", " chain "+u32s(v), v)
Expand Down
105 changes: 105 additions & 0 deletions internal/gotc/aw_bpf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//go:build gotc_write

package gotc

import (
"github.com/randomizedcoder/xtcp2/pkg/xtcpnl"
)

// tc/m_bpf.c bpf_parse_opt at iproute2 v7.2.0.

// bpfActExplain is m_bpf.c explain, with bpf_prog_to_default_section of
// BPF_PROG_TYPE_SCHED_ACT.
func (r *runner) bpfActExplain() {
r.errf("%s", "Usage: ... bpf ... [ index INDEX ]\n"+
"\n"+
"BPF use case:\n"+
" bytecode BPF_BYTECODE\n"+
" bytecode-file FILE\n"+
"\n"+
"eBPF use case:\n"+
" object-file FILE [ section ACT_NAME ] [ export UDS_FILE ] [ verbose ]\n"+
" object-pinned FILE\n"+
"\n"+
"Where BPF_BYTECODE := 's,c t f k,c t f k,c t f k,...'\n"+
"c,t,f,k and s are decimals; s denotes number of 4-tuples\n"+
"\n"+
"Where FILE points to a file containing the BPF_BYTECODE string,\n"+
"an ELF file containing eBPF map definitions and bytecode, or a\n"+
"pinned eBPF program.\n"+
"\n"+
"Where ACT_NAME refers to the section name containing the\n"+
"action (default 'action').\n"+
"\n"+
"Where UDS_FILE points to a unix domain socket file in order\n"+
"to hand off control of all created eBPF maps to an agent.\n"+
"\n"+
"Where optionally INDEX points to an existing action, or\n"+
"explicitly specifies an action index upon creation.\n")
}

// parseBpf is bpf_parse_opt: the nest opens before the loop, which a
// bare kind never reaches (W313); `index` ends the loop, so `bpf index 5`
// sends PARMS alone (W312), and the first word that is no run, help or
// index is the program's mode word (`bpf drop` is "What mode is", W312).
// After the program, any word ends the loop: a second program word is
// left for parse_action (a control, or the next kind). Each program is
// loaded as parsed, its OPS_LEN and OPS written at once.
func (r *runner) parseBpf(ops *fops, args []string, tcaID uint16) ([]string, bool, error) {
args, err := r.nextArg(args)
if err != nil {
return nil, false, err
}
nest := ops.begin(maxMsg, tcaID)
seenRun := false
loop:
for len(args) > 0 {
switch {
case matches(args[0], "run"):
if args, err = r.nextArg(args); err != nil {
return nil, false, err
}
if seenRun {
return nil, false, r.duparg("run", args[0])
}
case matches(args[0], helpWord):
r.bpfActExplain()
return nil, false, nil
case matches(args[0], "index"):
break loop
case seenRun:
break loop
}
seenRun = true // opt_bpf
var cfg bpfCfg
rest, ok, err := r.bpfDoParse(args, &cfg)
if err != nil || !ok {
return nil, false, err
}
if err := cfg.load(); err != nil {
return nil, false, err
}
ops.put(maxMsg, xtcpnl.TcaActBpfOpsLen, cfg.opsLen())
ops.put(maxMsg, xtcpnl.TcaActBpfOps, cfg.opsBytes())
args = rest[1:] // NEXT_ARG_FWD
}
var parm xtcpnl.TcGen
if args, parm.Action, err = r.parseActionControlDflt(args, tcActPipe); err != nil {
return nil, false, err
}
if len(args) > 0 && matches(args[0], "index") {
if args, err = r.nextArg(args); err != nil {
return nil, false, err
}
i, good := getU32(args[0], 10)
if !good {
r.errf("bpf: Illegal \"index\"\n")
return nil, false, nil
}
parm.Index = i
args = args[1:]
}
ops.put(maxMsg, xtcpnl.TcaActBpfParms, parm.Append(nil))
ops.end(nest)
return args, true, nil
}
Loading