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
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions docs/netlink/gotc-status.md

Large diffs are not rendered by default.

61 changes: 60 additions & 1 deletion docs/netlink/upstream/iproute2-tc-write.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# iproute2 tc qdisc and class writes: help that carries on, ingress that eats words, silent failures and copy-paste messages

**Status (2026-11-27, increment 17):**
**Status (2026-11-27, increments 17 and 18):**

- **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.
Expand Down Expand Up @@ -41,6 +41,8 @@
- [W15–W25. Kind parsers](#w15w25-kind-parsers)
- [W7. Dropped](#w7-dropped)
- [K44, K45. Kernel notes](#k44-k45-kernel-notes)
- [Increment 18: W26–W41, the increment-15 kinds](#increment-18-w26w41-the-increment-15-kinds)
- [K46. Kernel note](#k46-kernel-note)

## Summary

Expand Down Expand Up @@ -157,3 +159,60 @@ it; `est_help` prints and does not exit, after which invarg fails the word. Corr
flag must be on.` (ng-014).
- **K45.** Extack comes back in the ack and tc prints it as `Error: ...` in place of `RTNETLINK answers`; a warning
on success is printed too (ec-092: `Warning: sch_htb: quantum of class 10010 is big.`), rc 0.

## Increment 18: W26–W41, the increment-15 kinds

**Scope:** parse_qopt of drr, qfq, hfsc, ets, mqprio, taprio, multiq, cbs and etf, and parse_copt of drr, qfq, hfsc
and ets (tc/q_*.c at v7.2.0, with tc_util.c get_clockid). **At HEAD:** the GitHub mirror's `main` is still
`35033e4713fe` (2026-11-27), and none of these files has a commit since v7.2.0. The latest are q_hfsc.c
`3ebe6ec196b6` (JSON output), q_qfq.c `935b2aea0641` and q_multiq.c `4ac8d234f736` (all 2026-03-07), and
tc_core.c `6c1113633fde` (2025-12-07). **Every finding is present at HEAD.** **Corpus:**
`pkg/xtcpnl/testdata/7_3_1/ws/tcswrite/` (114 rows, V042). "ec-N" and "ng-N" in this section are its rows.
**Reproduced** by gotc's port (V044), which replays all 114 rows byte for byte. **Checked** on the host's tc 7.2.0
(kernel 7.3.3, unprivileged netns) for the crash leads: W38 dies with SIGFPE, rc 136, in both its forms; W26, W28
and W29 get past tc's parse and are refused by the kernel.

| lead | where (v7.2.0) | what | pinned by | gotc |
|---|---|---|---|---|
| W26 | q_ets.c:121 | `quanta[nquanta++]` has no bound: a 17th quantum is written past `quanta[16]`, and tc sends what the stack then holds (the kernel says `Invalid number of bands`) | tdc 65b6, unit | refused |
| W27 | q_ets.c:126,156 | a priomap band is a u32 stored in a `__u8` before the bound check: `priomap 256` is sent as band 0 | ec-066 | same |
| W28 | q_mqprio.c:118-127,226 | a repeated `fp` restarts idx but keeps summing `num_fp_entries`; past 16, add_tc_entries reads `fp[16..]` off the stack | unit | refused |
| W29 | q_taprio.c:212-235,93 | the same for taprio's `fp` and `max-sdu` | unit | refused |
| W30 | q_mqprio.c:99,209 | a repeated `queues` sums `cnt_off_pairs`: `queues 4@0 4@4 queues 4@0 4@4` with num_tc 2 fails `pair count 4 can not be higher than given num_tc 2` | ng-020 | same |
| W31 | q_mqprio.c:138,152 | `mode` and `shaper` are taken only after a nonzero `hw` (default 1), so `hw 0 mode channel` is invarg's `unknown argument` (rc 255) and `mode channel hw 0` is sent | ng-018, ng-019 | same |
| W32 | q_mqprio.c:171,186 | too few `min_rate`/`max_rate` values are an error only when no word follows | ng-022, ng-023 | same |
| W33 | q_mqprio.c:204 | an unknown word exits 255 through invarg, where every other error returns 1 | ng-016 (vs ng-017) | same |
| W34 | q_taprio.c:271-296 | a bad `base-time`, `cycle-time` or `cycle-time-extension` is `PREV_ARG; break`: no message, the rest of argv unread, the request sent (the kernel says `There should be at least one entry`) | ng-025, ng-026 | same |
| W35 | q_taprio.c:314-337 | a bad `flags` or `txtime-delay` returns -1 with no message; an unknown word prints a bare `Unknown argument` | ng-027, ng-028 | same |
| W36 | q_taprio.c:349 | with num_tc unset, `map` and `queues` are parsed and then dropped (the priomap goes only when num_tc > 0); the kernel says `'mqprio' configuration is necessary` | ng-029 | same |
| W37 | q_taprio.c:245-267 | sched entries are calloc'd and never freed, a leak per command under `-batch` | — | n/a |
| W38 | q_hfsc.c:396 | a convex curve at rate 0 (`rt rate 0`, `rt umax 0 dmax 10ms rate 0`) divides by zero: SIGFPE | unit, host | refused |
| W39 | q_hfsc.c:396 | `umax * TIME_UNITS_PER_SEC` is unsigned 32-bit: `umax 5000` wraps, giving the wrong convex d | ec-072 | same |
| W40 | q_hfsc.c:387 | the concave m1 is a double put into a u32 with no range check: `umax 100000 dmax 1us` is 10^11, sent as 1215752192 | ec-073 | same |
| W41 | q_hfsc.c:150-179, 299 | rt/ls/sc/ul have no duplicate check (the last wins; `rt ... sc ...` is accepted); a bad `m1` prints `Illegal "m1"`, then sc2 retries the same words, then `Illegal "rt"` | ec-074, ng-007 | same |

Earlier leads that recur here: W3's nonzero duplicate check in ets `bands` (ec-067), hfsc `default` (ec-068), cbs
(ec-069), etf `delta` (ec-070) and taprio `cycle-time` (ec-071); W16's 32-bit rates in hfsc (`m2 40gbit`, ng-008);
W9's percent rate on a dummy (`ls m2 10%`, ng-009).

**Notes:**

- **W26.** tc survives the write on the host because `quanta[16]` lands in other locals. What is sent depends on
the compiler's stack layout. gotc refuses the 17th quantum by name, and the tdc row stays in `tdcWriteKnown`.
- **W28, W29.** add_tc_entries runs `tc < num_fp_entries` (or the max of both counts) with the arrays sized 16. Up
to 16 in total, a repeat overwrites from index 0 and the count is the sum: `fp E fp P` sends two entries, P then
0.
- **W31.** The word order matters because `hw` is parsed in place. The check is on the value parsed so far, not on
the final one.
- **W34.** Unlike `flags` and `txtime-delay` (W35), which return -1, the three time words fall out of the loop, so
`base-time zz sched-entry ...` sends a schedule with no entries.
- **W39.** The correct d for ec-072 is 100000 - 5000*10^6/12500000 = 99600 us. tc computes (5000*10^6 mod 2^32)
/ 12500000 = 56, and sends 99944.

## K46. Kernel note

- **K46.** A qdisc kind with no `change` op fails `qdisc change`/`replace` only when the request carries
TCA_OPTIONS (sch_api.c qdisc_change). drr and qfq have no qdisc change op and send no options, so their change
and replace succeed (ec-002/003, ec-006/007). mqprio and etf have none either but always send options, and get
EINVAL `Change operation not supported by specified qdisc.` (ng-036..039, as K31). multiq's succeed for another
reason: it has a change op, `multiq_tune` (sch_multiq.c:394 at v7.4-rc4) (ec-010/011).
9 changes: 7 additions & 2 deletions internal/gotc/corpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ var corpusRefused = map[string]string{
}

// qwriteSent are the corpusWrites rows the gotc_write build sends and
// matches (17W).
var qwriteSent = map[string]bool{"tcqdisc/ng-018": true, "tcclass/ng-011": true}
// matches (17W, 18W).
var qwriteSent = map[string]bool{
"tcqdisc/ng-018": true, "tcclass/ng-011": true,
"tcsched/ng-001": true, "tcsched/ng-002": true, "tcsched/ng-003": true, "tcsched/ng-004": true,
}

var corpusWrites = map[string]bool{
"tcqdisc/ng-018": true, "tcclass/ng-011": true, "tcfilter/ng-024": true, "tcflower/ng-009": true,
Expand Down Expand Up @@ -234,6 +237,8 @@ func TestGotcCorpus(t *testing.T) {
if writesBuilt {
spaces = append(spaces, "tcqwrite")
corpusRows["tcqwrite"] = 125
spaces = append(spaces, "tcswrite")
corpusRows["tcswrite"] = 114
}
for _, sp := range spaces {
more, err := filepath.Glob("../../pkg/xtcpnl/testdata/*/ws/" + sp)
Expand Down
244 changes: 244 additions & 0 deletions internal/gotc/qw_ets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
//go:build gotc_write

package gotc

import (
"fmt"

"github.com/randomizedcoder/xtcp2/pkg/xtcpnl"
"golang.org/x/sys/unix"
)

// tc/q_ets.c ets_parse_opt and ets_parse_copt at iproute2 v7.2.0.

func (r *runner) etsExplain() {
r.errf("Usage: ... ets [bands NUMBER] [strict NUMBER] [quanta Q1 Q2...] [priomap P1 P2...]\n")
}

// etsQuantum is parse_quantum: 0 is its failure, after the message.
func (r *runner) etsQuantum(a string) uint32 {
q, ok := getUnsigned(a, 10)
if !ok {
r.errf("Illegal \"quanta\" element\n")
return 0
}
if q == 0 {
r.errf("\"quanta\" must be > 0\n")
}
return q
}

// etsNbands is parse_nbands.
func (r *runner) etsNbands(a, what string) (uint8, bool) {
v, ok := getUnsigned(a, 10)
if !ok {
r.errf("Illegal \"%s\"\n", what)
return 0, false
}
if v > xtcpnl.TcqEtsMaxBandsCst {
r.errf("The number of \"%s\" must be <= %d\n", what, xtcpnl.TcqEtsMaxBandsCst)
return 0, false
}
return uint8(v), true
}

// etsArgs is ets_parse_opt's locals.
type etsArgs struct {
nbands, nstrict uint8
quantaMode, prioMode bool
quanta []uint32
priomap []uint8
}

// etsWord is one turn of ets_parse_opt's loop on a word that is not a
// keyword (or follows quanta/priomap): a quantum or a priomap band. A
// band is a u32 stored in a __u8, so 256 passes the bound check as 0
// (W27); a 17th quantum overruns tc's quanta[16] (W26): gotc refuses it.
func (r *runner) etsWord(e *etsArgs, a string) error {
switch {
case e.quantaMode:
q := r.etsQuantum(a)
if q == 0 {
return errKindParse
}
if len(e.quanta) == xtcpnl.TcqEtsMaxBandsCst {
return fmt.Errorf("%w: ets with more than %d quanta (tc writes past quanta[%d])",
errNotImplemented, xtcpnl.TcqEtsMaxBandsCst, xtcpnl.TcqEtsMaxBandsCst)
}
e.quanta = append(e.quanta, q)
case e.prioMode:
band, ok := getUnsigned(a, 10)
if !ok {
r.errf("Illegal \"priomap\" element\n")
return errKindParse
}
if len(e.priomap) > tcPrioMax {
r.errf("\"priomap\" index cannot be higher than %d\n", tcPrioMax)
return errKindParse
}
e.priomap = append(e.priomap, uint8(band&0xff))
default:
r.errf("What is \"%s\"?\n", a)
r.etsExplain()
return errKindParse
}
return nil
}

// parseEtsQopt is ets_parse_opt. The duplicate checks are on a nonzero
// count (W3).
func parseEtsQopt(r *runner, args []string, _ string) (func(*xtcpnl.AttrBuilder) error, error) {
var e etsArgs
for ; len(args) > 0; args = args[1:] {
a := args[0]
var err error
switch a {
case wordBands, "strict":
if (a == wordBands && e.nbands != 0) || (a == "strict" && e.nstrict != 0) {
r.errf("Duplicate \"%s\"\n", a)
return nil, errKindParse
}
if len(args) < 2 {
return nil, r.incomplete()
}
args = args[1:]
v, ok := r.etsNbands(args[0], a)
if !ok {
return nil, errKindParse
}
if a == wordBands {
e.nbands = v
} else {
e.nstrict = v
}
e.prioMode, e.quantaMode = false, false
case wordQuanta, wordPriomap:
if (a == wordQuanta && len(e.quanta) != 0) || (a == wordPriomap && len(e.priomap) != 0) {
r.errf("Duplicate \"%s\"\n", a)
return nil, errKindParse
}
if len(args) < 2 {
return nil, r.incomplete()
}
args = args[1:]
e.quantaMode, e.prioMode = a == wordQuanta, a == wordPriomap
err = r.etsWord(&e, args[0])
case helpWord:
r.etsExplain()
return nil, errKindParse
default:
err = r.etsWord(&e, a)
}
if err != nil {
return nil, err
}
}
if e.nbands == 0 {
e.nbands = uint8(len(e.quanta)) + e.nstrict
}
if e.nbands == 0 {
r.errf("One of \"bands\", \"quanta\" or \"strict\" needs to be specified\n")
r.etsExplain()
return nil, errKindParse
}
if int(e.nstrict)+len(e.quanta) > int(e.nbands) {
r.errf("Not enough total bands to cover all the strict bands and quanta\n")
r.etsExplain()
return nil, errKindParse
}
for _, p := range e.priomap {
if p >= e.nbands {
r.errf("\"priomap\" element is out of bounds\n")
return nil, errKindParse
}
}
return e.attrs, nil
}

// attrs is ets_parse_opt's TCA_OPTIONS: flagged nests (K30), NBANDS as a
// u8, NSTRICT only when nonzero.
func (e *etsArgs) attrs(ab *xtcpnl.AttrBuilder) error {
tail, err := ab.BeginNest(xtcpnl.TcaOptions | unix.NLA_F_NESTED)
if err != nil {
return err
}
if err := ab.PutU8(xtcpnl.TcaEtsNbands, e.nbands); err != nil {
return err
}
if e.nstrict != 0 {
if err := ab.PutU8(xtcpnl.TcaEtsNstrict, e.nstrict); err != nil {
return err
}
}
if len(e.quanta) != 0 {
nest, err := ab.BeginNest(xtcpnl.TcaEtsQuanta | unix.NLA_F_NESTED)
if err != nil {
return err
}
for _, q := range e.quanta {
if err := ab.PutU32(xtcpnl.TcaEtsQuantaBand, q); err != nil {
return err
}
}
if err := ab.EndNest(nest); err != nil {
return err
}
}
if len(e.priomap) != 0 {
nest, err := ab.BeginNest(xtcpnl.TcaEtsPriomap | unix.NLA_F_NESTED)
if err != nil {
return err
}
for _, p := range e.priomap {
if err := ab.PutU8(xtcpnl.TcaEtsPriomapBand, p); err != nil {
return err
}
}
if err := ab.EndNest(nest); err != nil {
return err
}
}
return ab.EndNest(tail)
}

// parseEtsCopt is ets_parse_copt: a flagged TCA_OPTIONS, with
// TCA_ETS_QUANTA_BAND when a quantum is given.
func parseEtsCopt(r *runner, args []string, _ string) (func(*xtcpnl.AttrBuilder) error, error) {
cexplain := func() { r.errf("Usage: ... ets [quantum Q1]\n") }
var quantum uint32
for ; len(args) > 0; args = args[1:] {
switch a := args[0]; a {
case wordQuantum:
if quantum != 0 {
r.errf("Duplicate \"quantum\"\n")
return nil, errKindParse
}
if len(args) < 2 {
return nil, r.incomplete()
}
args = args[1:]
if quantum = r.etsQuantum(args[0]); quantum == 0 {
return nil, errKindParse
}
case helpWord:
cexplain()
return nil, errKindParse
default:
r.errf("What is \"%s\"?\n", a)
cexplain()
return nil, errKindParse
}
}
return func(ab *xtcpnl.AttrBuilder) error {
tail, err := ab.BeginNest(xtcpnl.TcaOptions | unix.NLA_F_NESTED)
if err != nil {
return err
}
if quantum != 0 {
if err := ab.PutU32(xtcpnl.TcaEtsQuantaBand, quantum); err != nil {
return err
}
}
return ab.EndNest(tail)
}, nil
}
2 changes: 1 addition & 1 deletion internal/gotc/qw_fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func parsePrioQopt(r *runner, args []string, _ string) (func(*xtcpnl.AttrBuilder
return nil, errKindParse
}
opt.Bands = v
case "priomap":
case wordPriomap:
if pmap {
r.errf("Error: duplicate priomap\n")
return nil, errKindParse
Expand Down
2 changes: 1 addition & 1 deletion internal/gotc/qw_fq.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func fqPriomap(r *runner, args []string, prio *xtcpnl.TcPrioQopt, dup bool) ([]s
return nil, r.incomplete()
}
args = args[1:]
if args[0] != "priomap" {
if args[0] != wordPriomap {
r.errf("\"priomap\" expected\n")
return nil, errKindParse
}
Expand Down
Loading