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

Large diffs are not rendered by default.

406 changes: 406 additions & 0 deletions docs/netlink/upstream/iproute2-tc-action-write.md

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion docs/netlink/upstream/iproute2-tc-action.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# 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):**
**Status (2026-11-24, increment 12; extended 2026-11-25, increment 13; extended 2026-11-30, increment 22):**

- **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".
- **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 @@ -171,8 +174,14 @@

- **AC6:** `tc_act_list_or_flush` prints `bad action %s` for a kind it can't find and returns 0 (`goto bad_val` with
`ret = 0`). `actions ls action nosuch` exits 0 (ec-004).
- **Extended in increment 22:** the flush takes the same path (W182 in
[iproute2-tc-action-write.md](iproute2-tc-action-write.md)): `actions flush action nosuch` prints `bad action
nosuch` and exits 0 (tcactwrite/ec-239). gotc copies it (22W).
- **AC7:** `do_action` passes `argv + 2` to the list: the word after `list` is skipped whatever it is. After the
kind, only `since` is read. `actions list foo gact bar` lists every gact (ec-056).
- **Extended in increment 22:** flush is passed `argv + 2` too (W181 in
[iproute2-tc-action-write.md](iproute2-tc-action-write.md)): `actions flush foo gact` flushes every gact
(tcactwrite/ec-238). gotc copies it (22W).
- **AC8:** when `rtnl_talk` fails, `tc_action_gd` prints "We have an error talking to the kernel" and returns 1
without updating `*argc_p`/`*argv_p`. 1 is not < 0, so `do_action` loops on the words it already passed, from
`action`: `Command "action" is unknown, try "tc actions help".`, rc 255 (ng-004 for a missing index, ng-005 for a
Expand All @@ -189,6 +198,10 @@
- **AC34:** `tc_action_gd` requires `index` after each kind, though it puts `TCA_ACT_INDEX` only when the index is
non-zero and the kernel accepts a get without it. `get action gact` is `Error: no index specified action: gact`,
rc 255 (ng-002).
- **Extended in increment 22:** **correction** (W178 in [iproute2-tc-action-write.md](iproute2-tc-action-write.md)).
The kernel doesn't answer a get or delete without TCA_ACT_INDEX: tcf_action_get_1 refuses it with `Invalid TC
action index value` (act_api.c:1770-1774, K70). tc reaches that with `delete action gact index 0`, which sends no
INDEX (tcactwrite/ng-085); its `index` check only stops a get or delete with no index word at all.
- **AC38:** `tc_action_gd` builds into `MAX_MSG` (16384, tc_util.h:5) and never checks the return values of
`addattr_nest`, `addattr_l` or `addattr32` (m_action.c:627, 676-679). Past the bound, `addattr_l` prints
`addattr_l ERROR: message exceeded bound of 16384` and appends nothing (libnetlink.c:1380-1384). The loop goes
Expand Down Expand Up @@ -224,6 +237,11 @@ gotc refuses the writes, so these are from the source only.
0bit burst 0b mtu 4Gb pkts_rate 1000 pkts_burst 10` (ec-015).
- **AC33:** `act_parse_police` returns -1 with no message when both `rate` and `avrate` are given, so tc says only
"bad action parsing" (V014, live).
- **Extended in increment 22:** confirmed on the write side by tcactwrite/ng-004 (`police rate 1mbit burst 10k avrate
1mbit index 1`): stderr is only `bad action parsing`, `parse_action: bad value (9:police)!` and `Illegal
"action"`, rc 255. The sweep listed it again as W188, which
[iproute2-tc-action-write.md](iproute2-tc-action-write.md) drops as a duplicate. The slash form's `foo/pass`
(W169) is the same silent -1. gotc now sends police (22W) and copies both.
- **AC37:** `print_police` prints `"kind"` with `PRINT_JSON`; the text kind is the `" police 0x%x "` inside the
options. A terse dump sends no options, so `-br` text has no kind at all: `action order 0: \t index 1` (ec-010),
where the other kinds print theirs first (`mirred \t index 1`, ec-021). JSON has `"kind":"police"` (pw-010).
Expand Down Expand Up @@ -331,6 +349,10 @@ no NUL, a skbmod MAC of length 0 or over 21, and a tab of more than 1024 orders.
the length; an empty one prints `allow`. JSON's `"mark"` is then a number or the string `"allow"` (pw-018).
- **AC70:** on the write side, `parse_ife` reports what it parsed on stderr: `IFE type 0x%04X` for a given type and,
at m_ife.c:179, `IFE type 0xED3E` when none was given, plus the MAC addresses. Seen in every ife pre step of 13C.
- **Extended in increment 22:** skbmod does the same (W199 in
[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.

## AC54–AC58. ct

Expand Down Expand Up @@ -410,6 +432,10 @@ no NUL, a skbmod MAC of length 0 or over 21, and a tab of more than 1024 orders.
So a get of 33 actions is answered with the first 32, with no error or extack. tc prints them, `action order 1:`
to `32:`, and exits 0 (ec-066, pw-066). A gap stops the loop early too: orders 1, 2 and 4 are answered with 1
and 2. That is from the code: tc numbers its orders without gaps.
- **Extended in increment 22:** a delete is parsed the same way (W179 in
[iproute2-tc-action-write.md](iproute2-tc-action-write.md)): 33 `action gact index N` pairs in one `tc actions
delete` delete the first 32, and the 33rd is kept with no error or extack, rc 0. tcactwrite/ec-231's readback
still lists index 33.
- **K9:** `tunnel_key_dump` puts TOS and TTL only when non-zero (act_tunnel_key.c:762-766), so tc's `!= 0` tests
never fail on a dump.
- **K10:** `tcf_pedit_dump` puts PARMS_EX and KEYS_EX when any key is extended, otherwise PARMS
Expand Down
28 changes: 27 additions & 1 deletion docs/netlink/upstream/iproute2-tc-filter-write.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 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):**
**Status (2026-11-29, increment 20; extended 2026-11-30, increment 22):**

- **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).
- **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 @@ -120,6 +122,8 @@
- **W65.** `strncpy(d, *argv, sizeof(d)-1)` into `d[IFNAMSIZ]`: a 17-byte altname is looked up as its first 15
bytes, `Cannot find device "abcdefghijklmno"`, rc 1 (ng-002), naming text the user never typed. tc_class.c:74,408
does the same; W1–W63 don't list it.
- **Extended in increment 22:** mirred's `dev` is copied the same way, `strncpy(d, *argv, sizeof(d) - 1)` at
m_mirred.c:197 (W162 in [iproute2-tc-action-write.md](iproute2-tc-action-write.md)).
- **W66.** With no `dev` and no `block`, modify calls ll_init_map (a link dump) and sends tcm_ifindex 0, which the
kernel refuses with ENODEV (K49): `RTNETLINK answers: No such device`, `We have an error talking to the kernel`,
rc 2 (ng-003). tc_filter_get refuses the case itself (`Must specify netdevice`).
Expand All @@ -128,6 +132,8 @@
- **W68.** `if (prio) duparg(...)`, `if (req.t.tcm_parent) duparg(...)`, `if (d[0]) duparg(...)`: a first value of 0
is not a value. `pref 0 pref 5` installs pref 5 (ec-079); `parent none ingress` installs on ingress (ec-080). W3's
class for the qdisc `handle`.
- **Extended in increment 22:** police's duparg tests rate64 != 0, so `police rate 0 rate 1mbit burst 10k` is accepted
(W166 in [iproute2-tc-action-write.md](iproute2-tc-action-write.md)).
- **W69, W70.** get_filter_kind never returns NULL and the loop leaves only at the kind or the last word, so the
no-kind `Garbage instead of arguments` and its `help` can't be reached; no kind at all is the kernel's refusal
(ng-004). The device is looked up after the loop and before parse_fopt, so `dev nosuch ingress pref 1 u32 bogus`
Expand All @@ -143,8 +149,12 @@
`classid 100000001` is 0:1 (ec-081), `classid -1` is ffff:ffff (ec-082), and `parent 1ffffffff` is root, where
htb has no class ffff (ng-009). With a colon both halves are range-checked as unsigned longs, so `100000001:1` is
refused. This hits every `classid`, `flowid`, `baseclass` and `parent`.
- **Extended in increment 22:** skbedit's `priority` is get_tc_classid too: `priority 10` is :10 (hex) and `100000001`
wraps to :1 (W174 in [iproute2-tc-action-write.md](iproute2-tc-action-write.md), tcactwrite/ec-132–ec-135).
- **W75.** ll_name_to_index's last fallback is `sscanf(name, "if%u")`, which takes trailing text: `dev if1junk` is
ifindex 1 (lo, ec-083) when no device has that name. The bridge write-up's ng-022 note is the same line.
- **Extended in increment 22:** mirred's `dev if3junk` redirects to ifindex 3 the same way (W162 in
[iproute2-tc-action-write.md](iproute2-tc-action-write.md), tcactwrite/ec-119).

## W76–W95. u32

Expand Down Expand Up @@ -173,6 +183,9 @@
"mark" mask`.
- **W85.** parse_ether_addr is `sscanf("%hhx:%hhx:%hhx:%hhx:%hhx:%hhx")`: anything after the sixth byte is ignored
(`aa:bb:cc:dd:ee:ffzz`, ec-089), and each part is strtoul cut to a byte (`1ff` is ff, `-1` is ff, ec-090).
- **Extended in increment 22:** skbmod's dmac and smac are `sscanf %hhx` per byte as well: `…:01:junk` and
`0x02:1aa:-1:…` are accepted (W196 in [iproute2-tc-action-write.md](iproute2-tc-action-write.md),
tcactwrite/ec-202, ec-203).
- **W86–W89.** parse_offset and parse_hashkey read ints with get_integer and store them in narrower fields:
`plus` into the `__u16` off (`70000` is 4464, ec-091); `at` into the `short` offoff, after an even test on the int
(`65538` is 2, ec-092); `shift` into the `__u8` offshift (`258` is 2 and accepted, ec-093; `300` is 44, which the
Expand Down Expand Up @@ -245,11 +258,17 @@
length to 0 and turns it off again.
- **W113.** parse_action numbers actions 1, 2, … with no TCA_ACT_MAX_PRIO (32) check; 33 actions are sent and the
kernel refuses the whole filter, `Only 32 actions supported per filter` (K51, ng-035).
- **Extended in increment 22:** a delete has no bound either: 33 actions in `tc actions delete` are all sent, and the
kernel deletes 32 and silently keeps the 33rd (W179 and K8's extension, tcactwrite/ec-231). A standalone add of 33
is refused as K51 is, `Only 32 actions supported per filter` (K71, ng-083).
- **W114.** A word that is not a control word is the kind, and get_action_kind falls back to gact's util when no
`m_<kind>.so` or `<kind>_action_util` exists, but TCA_ACT_KIND keeps the typed word. After `action drop cookie
aa`, `index 5` is a second action of kind "index" with gact's PARMS {index 5} and the sticky cookie; the kernel
can't load act_index (`Failed to load TC action module`, ng-036). `action foo` is `Bad action type foo` and gact's
usage, rc 255 (ng-037). The `noact` stub is dead code: CONFIG_GACT is always set.
- **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).
- **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 @@ -260,6 +279,10 @@
`action drop act pass` is `Bad action type act` and gact's usage, rc 255 (ng-040). After each action the modifiers
are taken in a fixed order, cookie, hw_stats, no_percpu, skip flags, and a modifier out of that order is a new
action.
- **Extended in increment 22:** each kind takes its control word and then `index`, in that order, and a word out of
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).
- **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 All @@ -271,6 +294,9 @@
- **W121.** gact's usage() and parse_action's invarg and NEXT_ARG call exit(-1) on the parse path, so in `tc -force
-batch` one bad action ends the batch before its next line (ng-064); an ordinary parse failure returns 1 and
`-force` goes on. W4's and the bridge write-up's B30 class.
- **Extended in increment 22:** police and four other invarg/duparg paths (W185, tcactwrite/ng-092), and skbmod's,
sample's and mpls' usage and missarg paths (W201, ng-093), exit(-1) the same way and end a `-force` batch; see
[iproute2-tc-action-write.md](iproute2-tc-action-write.md).

## W122. The rt_names caches

Expand Down
100 changes: 81 additions & 19 deletions internal/gotc/act_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,38 @@ import (
"golang.org/x/sys/unix"
)

// The filter side of tc's actions at iproute2 v7.2.0: 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 m_gact.c
// parse_gact. Every other action kind is refused by name until the
// actions increment; an unknown name is get_action_kind's fallback to
// gact's parser, with the name kept as TCA_ACT_KIND (W114).
// tc's action parsing at iproute2 v7.2.0, for filters and `tc actions`:
// 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).

// 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
// records its options nest, of type tcaID, in ops and returns the words
// after it. ok false is its -1, after which parse_action prints "bad
// 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,
}

// tcCookieMax is TC_COOKIE_MAX_SIZE.
const tcCookieMax = 16
Expand All @@ -41,9 +67,9 @@ func actionA2N(arg string) (int32, bool) {
a string
n int32
}{
{"continue", tcActUnspec}, {wordDrop, tcActShot}, {"shot", tcActShot}, {"pass", tcActOK},
{"ok", tcActOK}, {"reclassify", tcActReclassify}, {"pipe", tcActPipe},
{"goto", tcActGotoChain}, {"jump", tcActJump}, {"trap", tcActTrap},
{wordContinue, tcActUnspec}, {wordDrop, tcActShot}, {"shot", tcActShot}, {wordPass, tcActOK},
{"ok", tcActOK}, {wordReclassify, tcActReclassify}, {wordPipe, tcActPipe},
{wordGoto, tcActGotoChain}, {"jump", tcActJump}, {"trap", tcActTrap},
} {
if matches(arg, c.a) {
return c.n, true
Expand All @@ -56,12 +82,40 @@ func actionA2N(arg string) (int32, bool) {
// control word, with goto's "chain N" and jump's count, and the step past
// it. ok false is its -1, after its message.
func (r *runner) parseActionControl(args []string) (rest []string, result int32, ok bool, err error) {
return r.parseActionControlNum(args, false)
}

// parseActionControlNum is parse_action_control with allow_num: with it, a
// whole decimal is a control too (police's conform-exceed).
func (r *runner) parseActionControlNum(args []string, allowNum bool) (rest []string, result int32, ok bool, err error) {
return r.parseActionControlMiss(args, allowNum, false)
}

// parseActionControlDflt is parse_action_control_dflt(…, allow_num false,
// dflt): a word that is no control is silently dflt with args unmoved, as
// is a bad goto chain or jump count, after its message.
func (r *runner) parseActionControlDflt(args []string, dflt int32) (rest []string, result int32, err error) {
rest, result, ok, err := r.parseActionControlMiss(args, false, true)
if err != nil {
return nil, 0, err
}
if !ok {
return args, dflt, nil
}
return rest, result, nil
}

// parseActionControlMiss is __parse_action_control: ignoreMiss leaves a
// word that is no control unremarked.
func (r *runner) parseActionControlMiss(args []string, allowNum, ignoreMiss bool) (rest []string, result int32, ok bool, err error) {
if len(args) == 0 {
return nil, 0, false, nil
}
result, found := actionA2N(args[0])
result, found := actionA2NNum(args[0], allowNum)
if !found {
r.errf("Bad action type %s\n", args[0])
if !ignoreMiss {
r.errf("Bad action type %s\n", args[0])
}
return nil, 0, false, nil
}
switch result {
Expand Down Expand Up @@ -178,16 +232,24 @@ func (r *runner) parseOneAction(m *fmod, args []string, prio int, ck *actionCook
if _, isCtl := actionA2N(args[0]); !isCtl {
k = truncKind(args[0])
}
if k != xtcpnl.TcActKindGact && linkedActKinds[k] {
return nil, false, fmt.Errorf("%w: tc filter action kind %s", errNotImplemented, k)
parse, ok := actParsers[k]
if !ok {
if linkedActKinds[k] {
where := "filter"
if m.standalone {
where = "actions"
}
return nil, false, fmt.Errorf("%w: tc %s action kind %s", errNotImplemented, where, k)
}
parse = (*runner).parseGact // get_action_kind's fallback (W114)
}
if prio > math.MaxUint16 {
return nil, false, fmt.Errorf("%w: action prio %d past a u16 attribute type", errNotImplemented, prio)
}
nest := m.ops.begin(maxMsg, uint16(prio))
m.ops.str(maxMsg, xtcpnl.TcaActKind, k)
kindAt := args
args, ok, err = r.parseGact(m, args, xtcpnl.TcaActOptions|unix.NLA_F_NESTED)
args, ok, err = parse(r, &m.ops, args, xtcpnl.TcaActOptions|unix.NLA_F_NESTED)
if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -296,7 +358,7 @@ func (r *runner) gactUsage() error {
// parseGact is m_gact.c parse_gact: args starts at the kind word (a
// control word, "gact", or the unknown name gact stands in for). ok false
// is its -1.
func (r *runner) parseGact(m *fmod, args []string, tcaID uint16) (rest []string, ok bool, err error) {
func (r *runner) parseGact(ops *fops, args []string, tcaID uint16) (rest []string, ok bool, err error) {
var p xtcpnl.TcGact
var pp xtcpnl.TcGactP
rd := false
Expand Down Expand Up @@ -346,12 +408,12 @@ func (r *runner) parseGact(m *fmod, args []string, tcaID uint16) (rest []string,
return nil, false, r.gactUsage()
}
}
nest := m.ops.begin(maxMsg, tcaID)
m.ops.put(maxMsg, xtcpnl.TcaGactParms, p.Append(nil))
nest := ops.begin(maxMsg, tcaID)
ops.put(maxMsg, xtcpnl.TcaGactParms, p.Append(nil))
if rd {
m.ops.put(maxMsg, xtcpnl.TcaGactProb, pp.Append(nil))
ops.put(maxMsg, xtcpnl.TcaGactProb, pp.Append(nil))
}
m.ops.end(nest)
ops.end(nest)
return args, true, nil
}

Expand Down
Loading