Netlink protocol specs
Subsystems (4)
Jakub Kicinski
maintainercover Netlink protocol specs
Hi!
I think the Netlink proto specs are far along enough to merge. Filling in all attribute types and quirks will be an ongoing effort but we have enough to cover FOU so it's somewhat complete.
I fully intend to continue polishing the code but at the same time I'd like to start helping others base their work on the specs (e.g. DPLL) and need to start working on some new families myself.
That's the progress / motivation for merging. The RFC [1] has more of a high level blurb, plus I created a lot of documentation, I'm not going to repeat it here. There was also the talk at LPC [2].
[1] https://lore.kernel.org/all/[email protected]/
[2] https://youtu.be/9QkXIQXkaQk?t=2562
Jakub Kicinski (6):
docs: add more netlink docs (incl. spec docs)
netlink: add schemas for YAML specs
net: add basic C code generators for Netlink
netlink: add a proto specification for FOU
net: fou: regenerate the uAPI from the spec
net: fou: use policy and operation tables generated from the spec
Documentation/core-api/index.rst | 1 + Documentation/core-api/netlink.rst | 99 + Documentation/netlink/genetlink-c.yaml | 287 +++ Documentation/netlink/genetlink-legacy.yaml | 313 +++ Documentation/netlink/genetlink.yaml | 252 +++ Documentation/netlink/specs/fou.yaml | 128 ++ .../userspace-api/netlink/c-code-gen.rst | 104 + .../netlink/genetlink-legacy.rst | 96 + Documentation/userspace-api/netlink/index.rst | 5 + Documentation/userspace-api/netlink/specs.rst | 410 ++++ MAINTAINERS | 3 + include/uapi/linux/fou.h | 54 +- net/ipv4/Makefile | 2 +- net/ipv4/fou-nl.c | 48 + net/ipv4/fou-nl.h | 25 + net/ipv4/fou.c | 51 +- tools/net/ynl/ynl-gen-c.py | 1998 +++++++++++++++++ tools/net/ynl/ynl-regen.sh | 30 + 18 files changed, 3835 insertions(+), 71 deletions(-) create mode 100644 Documentation/core-api/netlink.rst create mode 100644 Documentation/netlink/genetlink-c.yaml create mode 100644 Documentation/netlink/genetlink-legacy.yaml create mode 100644 Documentation/netlink/genetlink.yaml create mode 100644 Documentation/netlink/specs/fou.yaml create mode 100644 Documentation/userspace-api/netlink/c-code-gen.rst create mode 100644 Documentation/userspace-api/netlink/genetlink-legacy.rst create mode 100644 Documentation/userspace-api/netlink/specs.rst create mode 100644 net/ipv4/fou-nl.c create mode 100644 net/ipv4/fou-nl.h create mode 100755 tools/net/ynl/ynl-gen-c.py create mode 100755 tools/net/ynl/ynl-regen.sh
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerPATCH 5/6 net: fou: regenerate the uAPI from the spec
Regenerate the FOU uAPI header from the YAML spec.
The flags now come before attributes which use them, and the comments for type disappear (coders should look at the spec instead).
--- include/uapi/linux/fou.h | 54 +++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 28 deletions(-)
include/uapi/linux/fou.h +26 -28
@@ -1,32 +1,37 @@/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -/* fou.h - FOU Interface */ +// Do not edit directly, auto-generated from: +// Documentation/netlink/specs/fou.yaml +// YNL-GEN uapi header #ifndef _UAPI_LINUX_FOU_H#define _UAPI_LINUX_FOU_H -/* NETLINK_GENERIC related info -*/ #define FOU_GENL_NAME "fou" -#define FOU_GENL_VERSION 0x1 +#define FOU_GENL_VERSION 1enum { -FOU_ATTR_UNSPEC , -FOU_ATTR_PORT ,/* u16 */ -FOU_ATTR_AF ,/* u8 */ -FOU_ATTR_IPPROTO ,/* u8 */ -FOU_ATTR_TYPE ,/* u8 */ -FOU_ATTR_REMCSUM_NOPARTIAL ,/* flag */ -FOU_ATTR_LOCAL_V4 ,/* u32 */ -FOU_ATTR_LOCAL_V6 ,/* in6_addr */ -FOU_ATTR_PEER_V4 ,/* u32 */ -FOU_ATTR_PEER_V6 ,/* in6_addr */ -FOU_ATTR_PEER_PORT ,/* u16 */ -FOU_ATTR_IFINDEX ,/* s32 */ - - __FOU_ATTR_MAX, +FOU_ENCAP_UNSPEC , +FOU_ENCAP_DIRECT , +FOU_ENCAP_GUE , }; -#define FOU_ATTR_MAX (__FOU_ATTR_MAX - 1) +enum { +FOU_ATTR_UNSPEC , +FOU_ATTR_PORT , +FOU_ATTR_AF , +FOU_ATTR_IPPROTO , +FOU_ATTR_TYPE , +FOU_ATTR_REMCSUM_NOPARTIAL , +FOU_ATTR_LOCAL_V4 , +FOU_ATTR_LOCAL_V6 , +FOU_ATTR_PEER_V4 , +FOU_ATTR_PEER_V6 , +FOU_ATTR_PEER_PORT , +FOU_ATTR_IFINDEX , + + __FOU_ATTR_MAX +}; +#define FOU_ATTR_MAX (__FOU_ATTR_MAX - 1)enum { FOU_CMD_UNSPEC,
@@ -34,15 +39,8 @@ enum {FOU_CMD_DEL ,FOU_CMD_GET , - __FOU_CMD_MAX, + __FOU_CMD_MAX }; - -enum { -FOU_ENCAP_UNSPEC , -FOU_ENCAP_DIRECT , -FOU_ENCAP_GUE , -}; - -#define FOU_CMD_MAX (__FOU_CMD_MAX - 1) +#define FOU_CMD_MAX (__FOU_CMD_MAX - 1)#endif /* _UAPI_LINUX_FOU_H */
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerPATCH 1/6 docs: add more netlink docs (incl. spec docs)
In reply to Jakub KicinskiAdd documentation about the upcoming Netlink protocol specs.
--- Documentation/core-api/index.rst | 1 + Documentation/core-api/netlink.rst | 99 +++++ .../userspace-api/netlink/c-code-gen.rst | 104 +++++ .../netlink/genetlink-legacy.rst | 96 ++++ Documentation/userspace-api/netlink/index.rst | 5 + Documentation/userspace-api/netlink/specs.rst | 410 ++++++++++++++++++ MAINTAINERS | 2 + 7 files changed, 717 insertions(+) create mode 100644 Documentation/core-api/netlink.rst create mode 100644 Documentation/userspace-api/netlink/c-code-gen.rst create mode 100644 Documentation/userspace-api/netlink/genetlink-legacy.rst create mode 100644 Documentation/userspace-api/netlink/specs.rst
Documentation/core-api/index.rst +1 -0
@@ -122,6 +122,7 @@ Documents that don't fit elsewhere or which have yet to be categorized. :maxdepth: 1 librs + netlink .. only:: subproject and html
Documentation/core-api/netlink.rst new file +99 -0
99 lines not on this page · raw message
Documentation/userspace-api/netlink/c-code-gen.rst new file +104 -0
104 lines not on this page · raw message
Documentation/userspace-api/netlink/genetlink-legacy.rst new file +96 -0
96 lines not on this page · raw message
Documentation/userspace-api/netlink/index.rst +5 -0
@@ -10,3 +10,8 @@ Netlink documentation for users. :maxdepth: 2 intro + specs + c-code-gen + genetlink-legacy + +See also :ref:`Documentation/core-api/netlink.rst <kernel_netlink>`.
Documentation/userspace-api/netlink/specs.rst new file +410 -0
410 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -14187,8 +14187,10 @@ Q: https://patchwork.kernel.org/project/netdevbpf/list/ B: mailto:[email protected] T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git +F: Documentation/core-api/netlink.rst F: Documentation/networking/ F: Documentation/process/maintainer-netdev.rst +F: Documentation/userspace-api/netlink/ F: include/linux/in.h F: include/linux/net.h F: include/linux/netdevice.h
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerPATCH 6/6 net: fou: use policy and operation tables generated from the spec
In reply to Jakub KicinskiGenerate and plug in the spec-based tables.
A little bit of renaming is needed in the FOU code.
--- net/ipv4/Makefile | 2 +- net/ipv4/fou-nl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ net/ipv4/fou-nl.h | 25 +++++++++++++++++++++++ net/ipv4/fou.c | 51 +++++++++-------------------------------------- 4 files changed, 83 insertions(+), 43 deletions(-) create mode 100644 net/ipv4/fou-nl.c create mode 100644 net/ipv4/fou-nl.h
net/ipv4/Makefile +1 -1
@@ -26,7 +26,7 @@ obj-$(CONFIG_IP_MROUTE) += ipmr.o obj-$(CONFIG_IP_MROUTE_COMMON) += ipmr_base.o obj-$(CONFIG_NET_IPIP) += ipip.o gre-y := gre_demux.o -obj-$(CONFIG_NET_FOU) += fou.o +obj-$(CONFIG_NET_FOU) += fou.o fou-nl.o obj-$(CONFIG_NET_IPGRE_DEMUX) += gre.o obj-$(CONFIG_NET_IPGRE) += ip_gre.o udp_tunnel-y := udp_tunnel_core.o udp_tunnel_nic.o
net/ipv4/fou-nl.c new file +48 -0
48 lines not on this page · raw message
net/ipv4/fou-nl.h new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Do not edit directly, auto-generated from: +// Documentation/netlink/specs/fou.yaml +// YNL-GEN kernel header + +#ifndef _LINUX_FOU_GEN_H +#define _LINUX_FOU_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <linux/fou.h> + +// Global operation policy for fou +extern const struct nla_policy fou_policy[FOU_ATTR_IFINDEX +1 ]; + +// Ops table for fou +extern const struct genl_small_ops fou_ops[3 ]; + +int fou_add_doit (struct sk_buff *skb,struct genl_info *info); +int fou_del_doit (struct sk_buff *skb,struct genl_info *info); +int fou_get_doit (struct sk_buff *skb,struct genl_info *info); +int fou_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); + +#endif /* _LINUX_FOU_GEN_H */
net/ipv4/fou.c +9 -42
100 lines not on this page · raw message
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerPATCH 4/6 netlink: add a proto specification for FOU
In reply to Jakub KicinskiFOU has a reasonably modern Genetlink family. Add a spec.
--- Documentation/netlink/specs/fou.yaml | 128 +++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Documentation/netlink/specs/fou.yaml
Documentation/netlink/specs/fou.yaml new file +128 -0
@@ -0,0 +1,128 @@ +name: fou + +protocol: genetlink-legacy + +doc: | + Foo-over-UDP. + +c-family-name: fou-genl-name +c-version-name: fou-genl-version +max-by-define: true +kernel-policy: global + +definitions: + - + type: enum + name: encap_type + name-prefix: fou-encap- + enum-name: + entries: [ unspec, direct, gue ] + +attribute-sets: + - + name: fou + name-prefix: fou-attr- + attributes: + - + name: unspec + type: unused + - + name: port + type: u16 + byte-order: big-endian + - + name: af + type: u8 + - + name: ipproto + type: u8 + - + name: type + type: u8 + - + name: remcsum_nopartial + type: flag + - + name: local_v4 + type: u32 + - + name: local_v6 + type: binary + checks: + min-len: 16 + - + name: peer_v4 + type: u32 + - + name: peer_v6 + type: binary + checks: + min-len: 16 + - + name: peer_port + type: u16 + byte-order: big-endian + - + name: ifindex + type: s32 + +operations: + list: + - + name: unspec + doc: unused + + - + name: add + doc: Add port. + attribute-set: fou + + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: &all_attrs + attributes: + - port + - ipproto + - type + - remcsum_nopartial + - local_v4 + - peer_v4 + - local_v6 + - peer_v6 + - peer_port + - ifindex + + - + name: del + doc: Delete port. + attribute-set: fou + + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: &select_attrs + attributes: + - af + - ifindex + - port + - peer_port + - local_v4 + - peer_v4 + - local_v6 + - peer_v6 + + - + name: get + doc: Get tunnel info. + attribute-set: fou + dont-validate: [ strict, dump ] + + do: + request: *select_attrs + reply: *all_attrs + + dump: + reply: *all_attrs
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerPATCH 2/6 netlink: add schemas for YAML specs
In reply to Jakub KicinskiAdd schemas for Netlink spec files. As described in the docs we have 4 "protocols" or compatibility levels, and each one comes with its own schema, but the more general / legacy schemas are superset of more modern ones: genetlink is the smallest followed by genetlink-c and genetlink-legacy. There is no schema for raw netlink, yet, I haven't found the time..
I don't know enough jsonschema to do inheritance or something but the repetition is not too bad. I hope.
--- Documentation/netlink/genetlink-c.yaml | 287 ++++++++++++++++++ Documentation/netlink/genetlink-legacy.yaml | 313 ++++++++++++++++++++ Documentation/netlink/genetlink.yaml | 252 ++++++++++++++++ 3 files changed, 852 insertions(+) create mode 100644 Documentation/netlink/genetlink-c.yaml create mode 100644 Documentation/netlink/genetlink-legacy.yaml create mode 100644 Documentation/netlink/genetlink.yaml
Documentation/netlink/genetlink-c.yaml new file +287 -0
@@ -0,0 +1,287 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: "http://kernel.org/schemas/netlink/genetlink-c.yaml#" +$schema: "http://kernel.org/meta-schemas/netlink/core.yaml#" + +title: Protocol +description: Specification of a genetlink protocol +type: object +required: [ name, doc, attribute-sets, operations ] +additionalProperties: False +properties: + name: + description: Name of the genetlink family. + type: string + doc: + type: string + version: + description: Generic Netlink family version. Default is 1. + type: integer + protocol: + description: Schema compatibility level. Default is "genetlink". + enum: [ genetlink, genetlink-c] + # Start genetlink-c + uapi-header: + description: Path to the uAPI header, default is linux/${family-name}.h + type: string + c-family-name: + description: Name of the define for the family name. + type: string + c-version-name: + description: Name of the define for the verion of the family. + type: string + max-by-define: + description: Makes the number of attributes and commands be specified by a define, not an enum value. + type: boolean + # End genetlink-c + + definitions: + description: Array of type and constant definitions. + type: array + items: + type: object + required: [ type, name ] + additionalProperties: False + properties: + name: + type: string + header: + description: For C-compatible languages, header which already defines this value. + type: string + type: + enum: [ const, enum, flags ] + # For const + value: + description: For const - the value. + type: [ string, integer ] + # For enum and flags + value-start: + description: For enum or flags the literal initializer for the first value. + type: [ string, integer ] + entries: + description: For enum or flags array of values + type: array + items: + type: string + # Start genetlink-c + enum-name: + description: Name for enum, if empty no name will be used. + type: [ string, "null" ] + name-prefix: + description: For enum the prefix of the values, optional. + type: string + # End genetlink-c + + attribute-sets: + description: Definition of attribute spaces for this family. + type: array + items: + description: Definition of a single attribute space. + type: object + required: [ name, attributes ] + additionalProperties: False + properties: + name: + description: | + Name used when referring to this space in other definitions, not used outside of YAML. + type: string + # Strictly speaking 'name-prefix' and 'subset-of' should be mutually exclusive. + name-prefix: + description: | + Prefix for the C enum name of the attributes. Default family[name]-set[name]-a- + type: string + enum-name: + description: Name for the enum type of the attribute. + type: string + doc: + description: Documentation of the space. + type: string + subset-of: + description: | + Name of another space which this is a logical part of. Sub-spaces can be used to define + a limited group of attributes which are used in a nest. + type: string + # Start genetlink-c + attr-cnt-name: + description: The explicit name for constant holding the count of attributes (last attr + 1). + type: string + attr-max-name: + description: The explicit name for last member of attribute enum. + type: string + # End genetlink-c + attributes: + description: List of attributes in the space. + type: array + items: + type: object + required: [ name, type ] + additionalProperties: False + properties: + name: + type: string + type: &attr-type + enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64, + string, nest, array-nest, nest-type-value ] + doc: + description: Documentation of the attribute. + type: string + value: + description: Value for the enum item representing this attribute in the uAPI. + type: integer + type-value: + description: Name of the value extracted from the type of a nest-type-value attribute. + type: array + items: + type: string + byte-order: + enum: [little-endian, big-endian] + multi-attr: + type: boolean + nested-attributes: + description: Name of the space (sub-space) used inside the attribute. + type: string + enum: + description: Name of the enum type used for the atttribute. + type: string + checks: + description: Kernel input validation. + type: object + additionalProperties: False + properties: + flags-mask: + description: Name of the flags constant on which to base mask (unsigned scalar types only). + type: string + min-len: + description: Min length for a binary attribute. + oneOf: + - type: string + pattern: ^[0-9A-Za-z_-]*( - 1)?$ + - type: integer + max-len: + description: Max length for a string or a binary attribute. + oneOf: + - type: string + pattern: ^[0-9A-Za-z_-]*( - 1)?$ + - type: integer + sub-type: *attr-type + operations: + description: Operations supported by the protocol. + type: object + required: [ list ] + additionalProperties: False + properties: + enum-model: + description: | + The model of assigning values to the operations. + "unified" is the recommended model where all message types belong + to a single enum. + "directional" has the messages sent to the kernel and from the kernel + enumerated separately. + "notify-split" has the notifications and request-response types in + different enums. + enum: [ unified, directional, notify-split ] + name-prefix: + description: | + Prefix for the C enum name of the command. The name is formed by concatenating + the prefix with the upper case name of the command, with dashes replaced by underscores. + type: string + enum-name: + description: Name for the enum type with commands. + type: string + async-prefix: + description: Same as name-prefix but used to render notifications and events to separate enum. + type: string + async-enum: + description: Name for the enum type with notifications/events. + type: string + list: + description: List of commands + type: array + items: + type: object + additionalProperties: False + required: [ name, doc ] + properties: + name: + description: Name of the operation, also defining its C enum value in uAPI. + type: string + doc: + description: Documentation for the command. + type: string + value: + description: Value for the enum in the uAPI. + type: integer + attribute-set: + description: | + Attribute space from which attributes directly in the requests and replies + to this command are defined. + type: string + flags: &cmd_flags + description: Command flags. + type: array + items: + enum: [ admin-perm ] + dont-validate: + description: Kernel attribute validation flags. + type: array + items: + enum: [ strict, dump ] + do: &subop-type + description: Main command handler. + type: object + additionalProperties: False + properties: + request: &subop-attr-list + description: Definition of the request message for a given command. + type: object + additionalProperties: False + properties: + attributes: + description: | + Names of attributes from the attribute-set (not full attribute + definitions, just names). + type: array + items: + type: string + reply: *subop-attr-list + dump: *subop-type + notify: + description: Name of the command sharing the reply type with this notification. + type: string + event: + type: object + additionalProperties: False + properties: + attributes: + description: Explicit list of the attributes for the notification. + type: array + items: + type: string + mcgrp: + description: Name of the multicast group generating given notification. + type: string + mcast-groups: + description: List of multicast groups. + type: object + required: [ list ] + additionalProperties: False + properties: + list: + description: List of groups. + type: array + items: + type: object + required: [ name ] + additionalProperties: False + properties: + name: + description: | + The name for the group, used to form the define and the value of the define. + type: string + # Start genetlink-c + c-define-name: + description: Override for the name of the define in C uAPI. + type: string + # End genetlink-c + flags: *cmd_flags
Documentation/netlink/genetlink-legacy.yaml new file +313 -0
313 lines not on this page · raw message
Documentation/netlink/genetlink.yaml new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerPATCH 3/6 net: add basic C code generators for Netlink
In reply to Jakub KicinskiCode generators to turn Netlink specs into C code. I'm definitely not proud of it.
The main generator is in Python, there's a bash script to regen all code-gen'ed files in tree after making spec changes.
--- MAINTAINERS | 1 + tools/net/ynl/ynl-gen-c.py | 1998 ++++++++++++++++++++++++++++++++++++ tools/net/ynl/ynl-regen.sh | 30 + 3 files changed, 2029 insertions(+) create mode 100755 tools/net/ynl/ynl-gen-c.py create mode 100755 tools/net/ynl/ynl-regen.sh
MAINTAINERS +1 -0
@@ -14202,6 +14202,7 @@ F: include/uapi/linux/netdevice.h F: lib/net_utils.c F: lib/random32.c F: net/ +F: tools/net/ F: tools/testing/selftests/net/ NETWORKING [IPSEC]
tools/net/ynl/ynl-gen-c.py new file +1998 -0
1,998 lines not on this page · raw message
tools/net/ynl/ynl-regen.sh new file +30 -0
@@ -0,0 +1,30 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause + +TOOL=$(dirname $(realpath $0))/ynl-gen-c.py + +force= + +while [ ! -z "$1" ]; do + case "$1" in + -f ) force=yes; shift ;; + * ) echo "Unrecognized option '$1'"; exit 1 ;; + esac +done + +KDIR=$(dirname $(dirname $(dirname $(dirname $(realpath $0))))) + +files=$(git grep --files-with-matches '^// YNL-GEN \(kernel\|uapi\)') +for f in $files; do + # params: 0 1 2 3 4 5 + # // $YAML // YNL-GEN kernel $mode + params=( $(git grep -B1 -h '// YNL-GEN' $f) ) + + if [ $f -nt ${params[1]} -a -z "$force" ]; then + echo -e "\tSKIP $f" + continue + fi + + echo -e "\tGEN ${params[4]}\t$f" + $TOOL --mode ${params[4]} --${params[5]} --spec $KDIR/${params[1]} > $f +done
Signature · 1 line
2.37.3
Re: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
In reply to Jakub KicinskiQuoted 21 lines · Jakub Kicinski
Documentation/core-api/netlink.rst new file +15
-0@@ -0,0 +1,99 @@ +.. SPDX-License-Identifier: BSD-3-Clause + +.. _kernel_netlink: + +=================================== +Netlink notes for kernel developers +=================================== + +General guidance +================ + +Attribute enums +--------------- + +Older families often define "null" attributes and commands with value
Documentation/core-api/netlink.rst line 25
Quoted 10 lines
Documentation/core-api/netlink.rst new file +10
-0+of ``0`` and named ``unspec``. This is supported (``type: unspec``) +but should be avoided in new families. The ``unspec`` enum values are +not used in practice, so just set the value of the first attribute to ``1``. + +Message enums +------------- + +Use the same command IDs for requests and replies. This makes it easier +to match them up, and we have plenty ID space. +
s/plenty/plenty of/
Quoted 64 lines
Documentation/core-api/netlink.rst new file +64
-0+Use separate command IDs for notifications. This makes it easier to +sort the notifications from replies (and present them to the user +application via a different API than replies). + +Answer requests +--------------- + +Older families do not reply to all of the commands, especially NEW / ADD +commands. User only gets information whether the operation succeeded or +not via the ACK. Try to find useful data to return. Once the command is +added whether it replies with a full message or only an ACK is uAPI and +cannot be changed. It's better to err on the side of replying. + +Specifically NEW and ADD commands should reply with information identifying +the created object such as the allocated object's ID. + +Having to rely on ``NLM_F_ECHO`` is a hack, not a valid design. + +NLM_F_ECHO +---------- + +Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO`` +to take effect. + +Support dump consistency +------------------------ + +If iterating over objects during dump may skip over objects or repeat +them - make sure to report dump inconsistency with ``NLM_F_DUMP_INTR``. + +Netlink specification +===================== + +Documentation of the Netlink specification parts which are only relevant +to the kernel space. + +Globals +------- + +kernel-policy +~~~~~~~~~~~~~ + +Defines if the kernel validation policy is per operation (``per-op``) +or for the entire family (``global``). New families should use ``per-op`` +(default) to be able to narrow down the attributes accepted by a specific +command. + +checks +------ + +Documentation for the ``checks`` sub-sections of attribute specs. + +unterminated-ok +~~~~~~~~~~~~~~~ + +Accept strings without the null-termination (for legacy families only). +Switches from the ``NLA_NUL_STRING`` to ``NLA_STRING`` policy type. + +max-len +~~~~~~~ + +Defines max length for a binary or string attribute (corresponding +to the ``len`` member of struct nla_policy). For string attributes terminating +null character is not counted towards ``max-len``.
Documentation/core-api/netlink.rst line 99
Quoted 10 lines
Documentation/core-api/netlink.rst new file +10
-0+ +The field may either be a literal integer value or a name of a defined +constant. String types may reduce the constant by one +(i.e. specify ``max-len: CONST - 1``) to reserve space for the terminating +character so implementations should recognize such pattern. + +min-len +~~~~~~~ + +Similar to ``max-len`` but defines minimum length.
Otherwise this doc is LGTM.
Quoted 100 lines
Documentation/userspace-api/netlink/c-code-gen.rst new file +94
-0@@ -0,0 +1,104 @@ +.. SPDX-License-Identifier: BSD-3-Clause + +============================== +Netlink spec C code generation +============================== + +This document describes how Netlink specifications are used to render +C code (uAPI, policies etc.). It also defines the additional properties +allowed in older families by the ``genetlink-c`` protocol level, +to control the naming. + +For brevity this document refers to ``name`` properties of various +objects by the object type. For example ``$attr`` is the value +of ``name`` in an attribute, and ``$family`` is the name of the +family (the global ``name`` property). + +The upper case is used to denote literal values, e.g. ``$family-CMD`` +means the concatenation of ``$family``, a dash character, and the literal +``CMD``. + +The names of ``#defines`` and enum values are always converted to upper case, +and with dashes (``-``) replaced by underscores (``_``). + +If the constructured name is a C keyword, an extra underscore is +appended (``do`` -> ``do_``). + +Globals +======= + +``c-family-name`` controls the name of the ``#define`` for the family +name, default is ``$family-FAMILY-NAME``. + +``c-version-name`` controls the name of the ``#define`` for the version +of the family, default is ``$family-FAMILY-VERSION``. + +``max-by-define`` selects if max values for enums are defined as a +``#define`` rather than inside the enum. + +Definitions +=========== + +Constants +--------- + +Every constant is rendered as a ``#define``. +The name of the constant is ``$family-$constant`` and the value +is rendered as a string or integer according to its type in the spec. + +Enums and flags +--------------- + +Enums are named ``$family-$enum``. The full name can be set directly +or suppressed by specifying the ``enum-name`` property. +Default entry name is ``$family-$enum-$entry``. +If ``name-prefix`` is specified it replaces the ``$family-$enum`` +portion of the entry name. + +Attributes +========== + +Each attribute set (excluding fractional sets) is rendered as an enum. + +Attribute enums are traditionally unnamed in netlink headers. +If naming is desired ``enum-name`` can be used to specify the name. + +The default attribute name prefix is ``$family-A`` if the name of the set +is the same as the name of the family and ``$family-A-$set`` if the names +differ. The prefix can be overridden by the ``name-prefix`` property of a set. +The rest of the section will refer to the prefix as ``$pfx``. + +Attributes are named ``$pfx-$attribute``. + +Attribute enums end with two special values ``__$pfx-MAX`` and ``$pfx-MAX`` +which are used for sizing attribute tables. +These two names can be specified directly with the ``attr-cnt-name`` +and ``attr-max-name`` properties respectively. + +If ``max-by-define`` is set to ``true`` at the global level ``attr-max-name`` +will be specified as a ``#define`` rather than an enum value. + +Operations +========== + +Operations are named ``$family-CMD-$operation``. +If ``name-prefix`` is specified it replaces the ``$family-CMD`` +portion of the name. + +Similarly to attribute enums operation enums end with special count and max +attributes. For operations those attributes can be renamed with +``cmd-cnt-name`` and ``cmd-max-name``. Max will be a define if ``max-by-define`` +is ``true``. + +Multicast groups +================
Documentation/userspace-api/netlink/c-code-gen.rst line 104
Quoted 10 lines
Documentation/userspace-api/netlink/c-code-gen.rst new file +10
-0+ +Each multicast group gets a define rendered into the kernel uAPI header. +The name of the define is ``$family-MCGRP-$group``, and can be overwritten +with the ``c-define-name`` property. + +Code generation +=============== + +uAPI header is assumed to come from ``<linux/$family.h>`` in the default header +search path. It can be changed using the ``uapi-header`` global property.
LGTM (grammar and formatting).
Quoted 92 lines
Documentation/userspace-api/netlink/genetlink-legacy.rst new file +86
-0@@ -0,0 +1,96 @@ +.. SPDX-License-Identifier: BSD-3-Clause + +================================================================= +Netlink specification support for legacy Generic Netlink families +================================================================= + +This document describes the many additional quirks and properties +required to describe older Generic Netlink families which form +the ``genetlink-legacy`` protocol level. + +The spec is a work in progress, some of the quirks are just documented +for future reference. + +Specification (defined) +======================= + +Attribute type nests +-------------------- + +New Netlink families should use ``multi-attr`` to define arrays. +Older families (e.g. ``genetlink`` control family) attempted to +define array types reusing attribute type to carry information. + +For reference the ``multi-attr`` array may look like this:: + + [ARRAY-ATTR] + [INDEX (optionally)] + [MEMBER1] + [MEMBER2] + [SOME-OTHER-ATTR] + [ARRAY-ATTR] + [INDEX (optionally)] + [MEMBER1] + [MEMBER2] + +where ``ARRAY-ATTR`` is the array entry type. + +array-nest +~~~~~~~~~~ + +``array-nest`` creates the following structure:: + + [SOME-OTHER-ATTR] + [ARRAY-ATTR] + [ENTRY] + [MEMBER1] + [MEMBER2] + [ENTRY] + [MEMBER1] + [MEMBER2] + +It wraps the entire array in an extra attribute (hence limiting its size +to 64kB). The ``ENTRY`` nests are special and have the index of the entry +as their type instead of normal attribute type. + +type-value +~~~~~~~~~~ + +``type-value`` is a construct which uses attribute types to carry +information about a single object (often used when array is dumped +entry-by-entry). + +``type-value`` can have multiple levels of nesting, for example +genetlink's policy dumps create the following structures:: + + [POLICY-IDX] + [ATTR-IDX] + [POLICY-INFO-ATTR1] + [POLICY-INFO-ATTR2] + +Where the first level of nest has the policy index as it's attribute +type, it contains a single nest which has the attribute index as its +type. Inside the attr-index nest are the policy attributes. Modern +Netlink families should have instead defined this as a flat structure, +the nesting serves no good purpose here. + +Other quirks (todo) +=================== + +Structures +---------- + +Legacy families can define C structures both to be used as the contents +of an attribute and as a fixed message header. The plan is to define +the structs in ``definitions`` and link the appropriate attrs. +
Documentation/userspace-api/netlink/genetlink-legacy.rst line 96
Quoted 10 lines
Documentation/userspace-api/netlink/genetlink-legacy.rst new file +10
-0+Multi-message DO +---------------- + +New Netlink families should never respond to a DO operation with multiple +replies, with ``NLM_F_MULTI`` set. Use a filtered dump instead. + +At the spec level we can define a ``dumps`` property for the ``do``, +perhaps with values of ``combine`` and ``multi-object`` depending +on how the parsing should be implemented (parse into a single reply +vs list of objects i.e. pretty much a dump).
LGTM (grammar and formatting).
Quoted 419 lines
Documentation/userspace-api/netlink/index.rst +5
-0@@ -10,3 +10,8 @@ Netlink documentation for users. :maxdepth: 2 intro + specs + c-code-gen + genetlink-legacy + +See also :ref:`Documentation/core-api/netlink.rst <kernel_netlink>`.Documentation/userspace-api/netlink/specs.rst new file +400
-0@@ -0,0 +1,410 @@ +.. SPDX-License-Identifier: BSD-3-Clause + +========================================= +Netlink protocol specifications (in YAML) +========================================= + +Netlink protocol specifications are complete, machine readable descriptions of +Netlink protocols written in YAML. The goal of the specifications is to allow +separating Netlink parsing from user space logic and minimize the amount of +hand written Netlink code for each new family, command, attribute. +Netlink specs should be complete and not depend on any other spec +or C header file, making it easy to use in languages which can't include +kernel headers directly. + +Internally kernel uses the YAML specs to generate: + + - the C uAPI header + - documentation of the protocol as a ReST file + - policy tables for input attribute validation + - operation tables + +YAML specifications can be found under ``Documentation/netlink/specs/`` + +Compatibility levels +==================== + +There are four schema levels for Netlink specs, from the simplest used +by new families to the most complex covering all the quirks of the old ones. +Each next level inherits the attributes of the previous level, meaning that +user capable of parsing more complex ``genetlink`` schemas is also compatible +with simpler ones. The levels are: + + - ``genetlink`` - most streamlined, should be used by all new families + - ``genetlink-c`` - superset of ``genetlink`` with extra attributes allowing + customization of define and enum type and value names; this schema should + be equivalent to ``genetlink`` for all implementations which don't interact + directly with C uAPI headers + - ``genetlink-legacy`` - Generic Netlink catch all schema supporting quirks of + all old genetlink families, strange attribute formats, binary structures etc. + - ``netlink-raw`` - catch all schema supporting pre-Generic Netlink protocols + such as ``NETLINK_ROUTE`` + +The definition of the schemas (in ``jsonschema``) can be found +under ``Documentation/netlink/``. + +Schema structure +================ + +YAML schema has the following conceptual sections: + + - globals + - definitions + - attributes + - operations + - multicast groups + +Most properties in the schema accept (or in fact require) a ``doc`` +sub-property documenting the defined object. + +The following sections describe the properties of the most modern ``genetlink`` +schema. See the documentation of :doc:`genetlink-c <c-code-gen>` +for information on how C names are derived from name properties. + +genetlink +========= + +Globals +------- + +Attributes listed directly at the root level of the spec file. + +name +~~~~ + +Name of the family. Name identifies the family in a unique way, since +the Family IDs are allocated dynamically. + +version +~~~~~~~ + +Generic Netlink family version, default is 1. + +protocol +~~~~~~~~ + +The schema level, default is ``genetlink``, which is the only value +allowed for new ``genetlink`` families. + +definitions +----------- + +Array of type and constant definitions. + +name +~~~~ + +Name of the type / constant. + +type +~~~~ + +One of the following types: + + - const - a single, standalone constant + - enum - defines an integer enumeration, with values for each entry + incrementing by 1, (e.g. 0, 1, 2, 3) + - flags - defines an integer enumeration, with values for each entry + occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8) + +value +~~~~~ + +The value for the ``const``. + +value-start +~~~~~~~~~~~ + +The first value for ``enum`` and ``flags``, allows overriding the default +start value of ``0`` (for ``enum``) and starting bit (for ``flags``). +For ``flags`` ``value-start`` selects the starting bit, not the shifted value. + +Sparse enumerations are not supported. + +entries +~~~~~~~ + +Array of names of the entries for ``enum`` and ``flags``. + +header +~~~~~~ + +For C-compatible languages, header which already defines this value. +In case the definition is shared by multiple families (e.g. ``IFNAMSIZ``) +code generators for C-compabile languages may prefer to add an appropriate +include instead of rendering a new definition. + +attribute-sets +-------------- + +This property contains information about netlink attributes of the family. +All families have at least one attribute set, most have multiple. +``attribute-sets`` is an array, with each entry describing a single set. + +Note that the spec is "flattened" and is not meant to visually resemble +the format of the netlink messages (unlike certain ad-hoc documentation +formats seen in kernel comments). In the spec subordinate attribute sets +are not defined inline as a nest, but defined in a separate attribute set +referred to with a ``nested-attributes`` property of the container. + +Spec may also contain fractional sets - sets which contain a ``subset-of`` +property. Such sets describe a section of a full set, allowing narrowing down +which attributes are allowed in a nest or refining the validation criteria. +Fractional sets can only be used in nests. They are not rendered to the uAPI +in any fashion. + +name +~~~~ + +Uniquely identifies the attribute set, operations and nested attributes +refer to the sets by the ``name``. + +subset-of +~~~~~~~~~ + +Re-defines a portion of another set (a fractional set). +Allows narrowing down fields and changing validation criteria +or even types of attributes depending on the nest in which they +are contained. The ``value`` of each attribute in the fractional +set is implicitly the same as in the main set. + +attributes +~~~~~~~~~~ + +List of attributes in the set. + +Attribute properties +-------------------- + +name +~~~~ + +Identifies the attribute, unique within the set. + +type +~~~~ + +Netlink attribute type, see :ref:`attr_types`. + +.. _assign_val: + +value +~~~~~ + +Numerical attribute ID, used in serialized Netlink messages. +The ``value`` property can be skipped, in which case the attribute ID +will be the value of the previous attribute plus one (recursively) +and ``0`` for the first attribute in the attribute set. + +Note that the ``value`` of an attribute is defined only in its main set. + +enum +~~~~ + +For integer types specifies that values in the attribute belong to a defined +``enum``. Note that in case of ``flags`` the values may be combined. + +nested-attributes +~~~~~~~~~~~~~~~~~ + +Identifies the attribute space for attributes nested within given attribute. +Only valid for complex attributes which may have sub-attributes. + +multi-attr (arrays) +~~~~~~~~~~~~~~~~~~~ + +Boolean property signifying that the attribute may be present multiple times. +Allowing an attribute to repeat is the recommended way of implementing arrays +(no extra nesting). + +byte-order +~~~~~~~~~~ + +For integer types specifies attribute byte order - ``little-endian`` +or ``big-endian``. + +checks +~~~~~~ + +Input validation constraints used by the kernel. User space should query +the policy of the running kernel using Generic Netlink introspection, +rather than depend on what is specified in the spec file. + +The validation policy in the kernel is formed by combining the type +definition (``type`` and ``nested-attributes``) and the ``checks``. + +operations +---------- + +This section describes messages passed between the kernel and the user space. +There are three types of entries in this section - operations, notifications +and events. + +Operations describe the most common request - response communication. User +sends a request and kernel replies. Each operation may contain any combination +of the two modes familiar to netlink users - ``do`` and ``dump``. +``do`` and ``dump`` in turn contain a combination of ``request`` and +``response`` properties. If no explicit message with attributes is passed +in a given direction (e.g. a ``dump`` which does not accept filter, or a ``do`` +of a SET operation to which the kernel responds with just the netlink error +code) ``request`` or ``response`` section can be skipped. +``request`` and ``response`` sections list the attributes allowed in a message. +The list contains only the names of attributes from a set referred +to by the ``attribute-set`` property. + +Notifications and events both refer to the asynchronous messages sent by +the kernel to members of a multicast group. The difference between the +two is that a notification shares its contents with a GET operation +(the name of the GET operation is specified in the ``notify`` property). +This arrangement is commonly used for notifications about +objects where the notification carries the full object definition. + +Events are more focused and carry only a subset of information rather than full +object state (a made up example would be a link state change event with just +the interface name and the new link state). Events contain the ``event`` +property. Events are considered less idiomatic for netlink and notifications +should be preferred. + +list +~~~~ + +The only property of ``operations`` for ``genetlink``, holds the list of +operations, notifications etc. + +Operation properties +-------------------- + +name +~~~~ + +Identifies the operation. + +value +~~~~~ + +Numerical message ID, used in serialized Netlink messages. +The same enumeration rules are applied as to +:ref:`attribute values<assign_val>`. + +attribute-set +~~~~~~~~~~~~~ + +Specifies the attribute set contained within the message. + +do +~~~ + +Specification for the ``doit`` request. Should contain ``request``, ``reply`` +or both of these properties, each holding a :ref:`attr_list`. + +dump +~~~~ + +Specification for the ``dumpit`` request. Should contain ``request``, ``reply`` +or both of these properties, each holding a :ref:`attr_list`. + +notify +~~~~~~ + +Designates the message as a notification. Contains the name of the operation +(possibly the same as the operation holding this property) which shares +the contents with the notification (``do``). + +event +~~~~~ + +Specification of attributes in the event, holds a :ref:`attr_list`. +``event`` property is mutually exclusive with ``notify``. + +mcgrp +~~~~~ + +Used with ``event`` and ``notify``, specifies which multicast group +message belongs to. + +.. _attr_list: + +Message attribute list +---------------------- + +``request``, ``reply`` and ``event`` properties have a single ``attributes`` +property which holds the list of attribute names. + +mcast-groups +------------ + +This section lists the multicast groups of the family. + +list +~~~~ + +The only property of ``mcast-groups`` for ``genetlink``, holds the list +of groups. + +Multicast group properties +-------------------------- + +name +~~~~ + +Uniquely identifies the multicast group in the family. Similarly to +Family ID, Multicast Group ID needs to be resolved at runtime, based +on the name. + +.. _attr_types: + +Attribute types +=============== + +This section describes the attribute types supported by the ``genetlink`` +compatibility level. Refer to documentation of different levels for additional +attribute types. + +Scalar integer types +-------------------- + +Fixed-width integer types: +``u8``, ``u16``, ``u32``, ``u64``, ``s8``, ``s16``, ``s32``, ``s64``. + +Note that types smaller than 32 bit should be avoided as using them +does not save any memory in Netlink messages (due to alignment). +See :ref:`pad_type` for padding of 64 bit attributes. + +The payload of the attribute is the integer in host order unless ``byte-order`` +specifies otherwise. + +.. _pad_type: + +pad +--- + +Special attribute type used for padding attributes which require alignment +bigger than standard 4B alignment required by netlink (e.g. 64 bit integers). +There can only be a single attribute of the ``pad`` type in any attribute set +and it should be automatically used for padding when needed. + +flag +---- + +Attribute with no payload, its presence is the entire information. + +binary +------ + +Raw binary data attribute, the contents are opaque to generic code. + +string +------ + +Character string. Unless ``checks`` has ``unterminated-ok`` set to ``true`` +the string is required to be null terminated.
Documentation/userspace-api/netlink/specs.rst line 410
Quoted 10 lines
Documentation/userspace-api/netlink/specs.rst new file +10
-0+``max-len`` in ``checks`` indicates the longest possible string, +if not present the length of the string is unbounded. + +Note that ``max-len`` does not count the terminating character. + +nest +---- + +Attribute containing other (nested) attributes. +``nested-attributes`` specifies which attribute set is used inside.
LGTM (grammar and formatting).
All docs have been reviewed, thanks.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Re: [PATCH net-next 4/6] netlink: add a proto specification for FOU
In reply to Jakub KicinskiLe 29/09/2022 à 03:11, Jakub Kicinski a écrit :
Quoted 32 lines
FOU has a reasonably modern Genetlink family. Add a spec.
Signed-off-by Jakub Kicinski <[email protected]>--- Documentation/netlink/specs/fou.yaml | 128 +++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Documentation/netlink/specs/fou.yamlDocumentation/netlink/specs/fou.yaml new file +18
-0@@ -0,0 +1,128 @@ +name: fou + +protocol: genetlink-legacy + +doc: | + Foo-over-UDP. + +c-family-name: fou-genl-name +c-version-name: fou-genl-version +max-by-define: true +kernel-policy: global + +definitions: + - + type: enum + name: encap_type + name-prefix: fou-encap- + enum-name:
Documentation/netlink/specs/fou.yaml line 28
Quoted 10 lines
Documentation/netlink/specs/fou.yaml new file +10
-0+ entries: [ unspec, direct, gue ] + +attribute-sets: + - + name: fou + name-prefix: fou-attr- + attributes: + - + name: unspec + type: unused
The first attribute should always be unspec/unused. Maybe it could be automatically generated?
Quoted 35 lines
Documentation/netlink/specs/fou.yaml new file +35
-0+ - + name: port + type: u16 + byte-order: big-endian + - + name: af + type: u8 + - + name: ipproto + type: u8 + - + name: type + type: u8 + - + name: remcsum_nopartial + type: flag + - + name: local_v4 + type: u32 + - + name: local_v6 + type: binary + checks: + min-len: 16 + - + name: peer_v4 + type: u32 + - + name: peer_v6 + type: binary + checks: + min-len: 16 + - + name: peer_port + type: u16
Documentation/netlink/specs/fou.yaml line 73
Quoted 10 lines
Documentation/netlink/specs/fou.yaml new file +10
-0+ byte-order: big-endian + - + name: ifindex + type: s32 + +operations: + list: + - + name: unspec + doc: unused
To what correspond this name?
It helps to name the generated operations array? Something else than 'const struct genl_small_ops fou_ops[3]'?
Re: [PATCH net-next 4/6] netlink: add a proto specification for FOU
Le 29/09/2022 à 11:02, Nicolas Dichtel a écrit :
Quoted 38 lines
Le 29/09/2022 à 03:11, Jakub Kicinski a écrit :
Quoted 36 lines
FOU has a reasonably modern Genetlink family. Add a spec.
Signed-off-by Jakub Kicinski <[email protected]>--- Documentation/netlink/specs/fou.yaml | 128 +++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Documentation/netlink/specs/fou.yamlDocumentation/netlink/specs/fou.yaml new file +22
-0@@ -0,0 +1,128 @@ +name: fou + +protocol: genetlink-legacy + +doc: | + Foo-over-UDP. + +c-family-name: fou-genl-name +c-version-name: fou-genl-version +max-by-define: true +kernel-policy: global + +definitions: + - + type: enum + name: encap_type + name-prefix: fou-encap- + enum-name: + entries: [ unspec, direct, gue ] + +attribute-sets: + -
Quoted 8 lines
Documentation/netlink/specs/fou.yaml line 28
Quoted 6 lines
Documentation/netlink/specs/fou.yaml new file +6
-0+ name: fou + name-prefix: fou-attr- + attributes: + - + name: unspec + type: unusedThe first attribute should always be unspec/unused. Maybe it could be automatically generated?
I read the doc after the code :)
Re: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
In reply to Jakub KicinskiLe 29/09/2022 à 03:11, Jakub Kicinski a écrit :
Quoted 3 lines
Add documentation about the upcoming Netlink protocol specs.
Signed-off-by Jakub Kicinski <[email protected]>
[snip]
Quoted 7 lines
Documentation/core-api/netlink.rst new file +7
-0+Attribute enums +--------------- + +Older families often define "null" attributes and commands with value +of ``0`` and named ``unspec``. This is supported (``type: unspec``) +but should be avoided in new families. The ``unspec`` enum values are +not used in practice, so just set the value of the first attribute to ``1``.
[snip]
Documentation/userspace-api/netlink/specs.rst line 384
Quoted 12 lines
Documentation/userspace-api/netlink/specs.rst new file +12
-0+The payload of the attribute is the integer in host order unless ``byte-order`` +specifies otherwise. + +.. _pad_type: + +pad +--- + +Special attribute type used for padding attributes which require alignment +bigger than standard 4B alignment required by netlink (e.g. 64 bit integers). +There can only be a single attribute of the ``pad`` type in any attribute set +and it should be automatically used for padding when needed.
This answers my question.
Nice job!
Re: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
In reply to Jakub KicinskiQuoted 9 lines · Jakub Kicinski
Documentation/core-api/netlink.rst new file +9
-0+Answer requests +--------------- + +Older families do not reply to all of the commands, especially NEW / ADD +commands. User only gets information whether the operation succeeded or +not via the ACK. Try to find useful data to return. Once the command is +added whether it replies with a full message or only an ACK is uAPI and +cannot be changed. It's better to err on the side of replying. +
Documentation/core-api/netlink.rst line 48
Quoted 10 lines
Documentation/core-api/netlink.rst new file +10
-0+Specifically NEW and ADD commands should reply with information identifying +the created object such as the allocated object's ID. + +Having to rely on ``NLM_F_ECHO`` is a hack, not a valid design. + +NLM_F_ECHO +---------- + +Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO`` +to take effect.
Do you mean that netlink commands should properly handle NLM_F_ECHO, although they should also design their API so that users don't need it?
Jakub Kicinski
maintainerRe: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
Quoted 5 lines · On Thu, 29 Sep 2022 15:34:13 +0200 Guillaume Nault wrote:
Documentation/core-api/netlink.rst line 48
Quoted 2 lines
Documentation/core-api/netlink.rst new file +2
-0+Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO`` +to take effect.Do you mean that netlink commands should properly handle
NLM_F_ECHO, although they should also design their API so that users don't need it?
Yes, ECHO should be supported but as an extra, not something that is crucial to write a basic script without assuming full ownership of the system...
IOW support the logging use case you mentioned but don't do the NEWLINK thing.
Should I clarify or rephrase? The ECHO section needs to be read with the one above it to get the full answer.
Jakub Kicinski
maintainerRe: [PATCH net-next 4/6] netlink: add a proto specification for FOU
In reply to Nicolas DichtelQuoted 9 lines · On Thu, 29 Sep 2022 11:02:51 +0200 Nicolas Dichtel wrote:
Documentation/netlink/specs/fou.yaml line 73
Quoted 5 lines
Documentation/netlink/specs/fou.yaml new file +5
-0+operations: + list: + - + name: unspec + doc: unusedTo what correspond this name?
It helps to name the generated operations array? Something else than 'const structgenl_small_opsfou_ops[3]'?
Same as the attr, it just reserves zero FWIW, never actually used in the code I've grepped:
linux$ git grep FOU_CMD_UNSPECinclude/uapi/linux/fou.h: FOU_CMD_UNSPEC,
iproute2$ git grep FOU_CMD_UNSPECinclude/uapi/linux/fou.h: FOU_CMD_UNSPEC,
BTW thanks for asking, I noticed I mistyped the documentation, type is 'unused', in the docs I said 'unspec'.
Re: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
In reply to Jakub KicinskiQuoted 11 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 29 Sep 2022 15:34:13 +0200 Guillaume Nault wrote:
Documentation/core-api/netlink.rst line 48
Quoted 2 lines
Documentation/core-api/netlink.rst new file +2
-0+Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO`` +to take effect.Do you mean that netlink commands should properly handle
NLM_F_ECHO, although they should also design their API so that users don't need it?Yes, ECHO should be supported but as an extra, not something that is crucial to write a basic script without assuming full ownership of the system...
Quoted 5 lines
IOW support the logging use case you mentioned but don't do the NEWLINK thing.
Should I clarify or rephrase? The ECHO section needs to be read with the one above it to get the full answer.
Maybe we can make this more explicit.
Something like:
-Having to rely on ``NLM_F_ECHO`` is a hack, not a valid design. +Users shouldn't have to use ``NLM_F_ECHO`` to get a handle on the created +object.
(or keep both sentences, I feel they fit well together).
Then maybe explain in the next section why support for NLM_F_ECHO is desirable anyway:
Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO``
-to take effect.
+to take effect. This is usefull for programs that need precise feedback from
+ the kernel (for example for logging purpose).
Jakub Kicinski
maintainerRe: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
Quoted 13 lines · On Thu, 29 Sep 2022 17:11:45 +0200 Guillaume Nault wrote:
Maybe we can make this more explicit.
Something like:(quoted diff) +2
-1-Having to rely on ``NLM_F_ECHO`` is a hack, not a valid design. +Users shouldn't have to use ``NLM_F_ECHO`` to get a handle on the created +object.(or keep both sentences, I feel they fit well together).
Then maybe explain in the next section why support for
NLM_F_ECHOis desirable anyway:Make sure to pass the request info to
genl_notify()to allow ``NLM_F_ECHO``
Review
Quoted 3 lines
(quoted diff) +2
-1-to take effect. +to take effect. This is usefull for programs that need precise feedback from + the kernel (for example for logging purpose).
Folded it a little bit:
Documentation/core-api/netlink.rst +4 -4
@@ -37,15 +37,15 @@ added whether it replies with a full message or only an ACK is uAPI and cannot be changed. It's better to err on the side of replying. Specifically NEW and ADD commands should reply with information identifying -the created object such as the allocated object's ID. - -Having to rely on ``NLM_F_ECHO`` is a hack, not a valid design. +the created object such as the allocated object's ID (without having to +resort to using ``NLM_F_ECHO``). NLM_F_ECHO ---------- Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO`` -to take effect. +to take effect. This is useful for programs that need precise feedback +from the kernel (for example for logging purposes). Support dump consistency ------------------------
Re: [PATCH net-next 1/6] docs: add more netlink docs (incl. spec docs)
Quoted 13 lines · Jakub Kicinski
Folded it a little bit:
Documentation/core-api/netlink.rst +0
-3@@ -37,15 +37,15 @@ added whether it replies with a full message or only an ACK is uAPI and cannot be changed. It's better to err on the side of replying. Specifically NEW and ADD commands should reply with information identifying -the created object such as the allocated object's ID. - -Having to rely on ``NLM_F_ECHO`` is a hack, not a valid design.
Documentation/core-api/netlink.rst added whether it replies with a full message or only an ACK is uAPI and · line 48
Quoted 10 lines
Documentation/core-api/netlink.rst +4
-1+the created object such as the allocated object's ID (without having to +resort to using ``NLM_F_ECHO``). NLM_F_ECHO ---------- Make sure to pass the request info to genl_notify() to allow ``NLM_F_ECHO`` -to take effect. +to take effect. This is useful for programs that need precise feedback +from the kernel (for example for logging purposes).
That's very clear, thanks!