Subject: Re: [PATCH net-next] tcp_metrics: add netlink protocol spec in YAML

From: Donald Hunter <[email-masked]>
Date: Thu, 27 Jun 2024 10:20:15 +0100

Jakub Kicinski <[email-masked]> writes:

> Add a protocol spec for tcp_metrics, so that it's accessible via YNL.
> Useful at the very least for testing fixes.
>
> In this episode of "10,000 ways to complicate netlink" the metric
> nest has defines which are off by 1. iproute2 does:
>
>         struct rtattr *m[TCP_METRIC_MAX + 1 + 1];
>
>         parse_rtattr_nested(m, TCP_METRIC_MAX + 1, a);
>
>         for (i = 0; i < TCP_METRIC_MAX + 1; i++) {
>                 // ...
>                 attr = m[i + 1];
>
> This is too weird to support in YNL, add a new set of defines
> with _correct_ values to the official kernel header.

I had to add tcp_metrics.h to Makefile.deps to get the generated code to
complile.

diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps
index f4e8eb79c1b8..2f05f8ec2324 100644
--- a/tools/net/ynl/Makefile.deps
+++ b/tools/net/ynl/Makefile.deps
@@ -25,3 +25,4 @@ CFLAGS_nfsd:=$(call get_hdr_inc,_LINUX_NFSD_NETLINK_H,nfsd_netlink.h)
 CFLAGS_ovs_datapath:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
 CFLAGS_ovs_flow:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
 CFLAGS_ovs_vport:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
+CFLAGS_tcp_metrics:=$(call get_hdr_inc,__LINUX_TCP_METRICS_H,tcp_metrics.h)

> +
> +  -
> +    name: metrics
> +    # Intentially don't define the name-prefix to match the kernel, see below.

Typo: Intentionally

> +    doc: |
> +      Attributes with metrics. Note that the values here do not match
> +      the TCP_METRIC_* defines in the kernel, because kernel defines
> +      are off-by one (e.g. rtt is defined as enum 0, while netlink carries
> +      attribute type 1).
> +    attributes:
> +      -
> +        name: rtt
> +        type: u32
> +        doc: |
> +          Round Trip Time (RTT), in msecs with 3 bits fractional
> +          (left-shift by 3 to get the msec value).
> +      -
> +        name: rttvar
> +        type: u32
> +        doc: |
> +          Round Trip Time VARiance (RTT), in msecs with 2 bits fractional
> +          (left-shift by 2 to get the msec value).
> +      -
> +        name: ssthresh
> +        type: u32
> +        doc: Slow Start THRESHold.
> +      -
> +        name: cwnd
> +        type: u32
> +        doc: Congestion Window.
> +      -
> +        name: reodering
> +        type: u32
> +        doc: Reodering metric.
> +      -
> +        name: rtt_us

Should this be a dash, 'rtt-us' ?

> +        type: u32
> +        doc: |
> +          Round Trip Time (RTT), in usecs, with 3 bits fractional
> +          (left-shift by 3 to get the msec value).
> +      -
> +        name: rttvar_us

Same here?

> +        type: u32
> +        doc: |
> +          Round Trip Time (RTT), in usecs, with 3 bits fractional
> +          (left-shift by 3 to get the msec value).
> +