Add OVS packet family YNL spec and unicast notification support
Subsystems (3)
v4 cover Add OVS packet family YNL spec and unicast notification support
This series adds a YAML netlink spec for the OVS_PACKET_FAMILY genetlink family and a bind-only ntf_bind() helper for receiving unicast notifications.
Changes in v4:
- patch 2: rename ntf_listen() to ntf_bind(addr=(0, 0)); the name listen() was misleading since the operation is a bind(), and the address is now an explicit argument defaulting to (0, 0) (suggested by Jakub Kicinski)
Changes in v3:
- patch 1: add missing document start "---" after SPDX comment (yamllint warning in v2)
Changes in v2:
- patch 1: use YAML anchor (&event-attrs / *event-attrs) to avoid repeating the same attribute list for miss and action events (suggested by Donald Hunter)
- patch 1: fix enum-name from ovs-packet-attrs to ovs-packet-attr to match the kernel enum name ovs_packet_attr
- patch 2: add ntf_bind() to the YnlFamily docstring under the "Notification API" heading (suggested by Donald Hunter)
Minxi Hou (2):
netlink: specs: add OVS packet family specification
tools: ynl: add unicast notification receive support
Documentation/netlink/specs/ovs_packet.yaml | 130 ++++++++++++++++++++ tools/net/ynl/pyynl/lib/ynl.py | 5 + 2 files changed, 135 insertions(+) create mode 100644 Documentation/netlink/specs/ovs_packet.yaml
Signature · 1 line
2.54.0
PATCH v4 1/2 netlink: specs: add OVS packet family specification
Add YAML netlink spec for the OVS_PACKET_FAMILY (ovs_packet). This completes the set of OVS genetlink family specs (ovs_datapath, ovs_flow, ovs_vport already exist).
The spec defines three operations: MISS (event), ACTION (event), and EXECUTE (do). MISS and ACTION are kernel-to-userspace upcalls sent via genlmsg_unicast(); EXECUTE is the only registered genl operation.
Key, actions, and egress-tun-key attributes are typed as binary rather than nest because the nested attribute definitions belong to the ovs_flow spec and cross-spec references are not supported by the YNL framework.
--- Documentation/netlink/specs/ovs_packet.yaml | 130 ++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Documentation/netlink/specs/ovs_packet.yaml
Documentation/netlink/specs/ovs_packet.yaml new file +130 -0
@@ -0,0 +1,130 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +--- +name: ovs_packet +version: 1 +protocol: genetlink-legacy +uapi-header: linux/openvswitch.h + +doc: | + OVS packet execution over generic netlink. + + Only OVS_PACKET_CMD_EXECUTE is exposed as a genl operation. + OVS_PACKET_CMD_MISS and OVS_PACKET_CMD_ACTION are kernel-to-userspace + upcalls sent via genlmsg_unicast() to the vport's upcall_pid and have + no associated genl_ops or multicast group. + + Several attributes in the attribute set (userdata, egress-tun-key, len) + exist for the upcall path and are not used by the EXECUTE operation. + For EXECUTE, packet, key, and actions are mandatory (kernel returns + -EINVAL without them). + +definitions: + - + name: ovs-header + type: struct + members: + - + name: dp-ifindex + type: u32 + +attribute-sets: + - + name: packet + name-prefix: ovs-packet-attr- + enum-name: ovs-packet-attr + attributes: + - + name: packet + type: binary + doc: Packet data, from the start of the Ethernet header. + checks: + min-len: 14 + - + name: key + type: binary + doc: | + Nested OVS_KEY_ATTR_* attributes, extracted flow key. + Defined as binary because the key attribute-set belongs to the + ovs_flow family spec; cross-spec references are not supported. + - + name: actions + type: binary + doc: | + Nested OVS_ACTION_ATTR_* attributes. + Defined as binary for the same reason as key. + - + name: userdata + type: binary + doc: Opaque userspace cookie from OVS_USERSPACE_ATTR_USERDATA. + - + name: egress-tun-key + type: binary + doc: Nested OVS_TUNNEL_KEY_ATTR_* for output tunnel metadata. + - + name: unused1 + type: unused + - + name: unused2 + type: unused + - + name: probe + type: flag + doc: Packet operation is a feature probe, error logging suppressed. + - + name: mru + type: u16 + doc: Maximum received IP fragment size. + - + name: len + type: u32 + doc: Packet size before truncation. + - + name: hash + type: u64 + doc: Packet hash, low 32 bits are skb hash, upper bits are flags. + - + name: upcall-pid + type: u32 + doc: Netlink PID to use for upcalls during EXECUTE processing. + +operations: + fixed-header: ovs-header + name-prefix: ovs-packet-cmd- + list: + - + name: miss + doc: Notify userspace of a flow table miss for a received packet. + value: 1 + attribute-set: packet + event: + attributes: &event-attrs + - packet + - key + - userdata + - actions + - egress-tun-key + - mru + - len + - hash + - + name: action + doc: Notify userspace as requested by an OVS_ACTION_ATTR_USERSPACE action. + value: 2 + attribute-set: packet + event: + attributes: *event-attrs + - + name: execute + doc: Apply actions to a packet. + value: 3 + attribute-set: packet + do: + request: + attributes: + - packet + - key + - actions + - probe + - mru + - hash + - upcall-pid
Signature · 1 line
2.54.0
PATCH v4 2/2 tools: ynl: add unicast notification receive support
In reply to Minxi HouAdd ntf_bind() method to YnlFamily for binding the netlink socket without joining a multicast group. This enables receiving unicast notifications through the existing poll_ntf/check_ntf path.
The OVS packet family sends MISS and ACTION upcalls via genlmsg_unicast() to a per-vport PID rather than through a multicast group. The existing ntf_subscribe() couples bind() with setsockopt(ADD_MEMBERSHIP), which does not fit the unicast case. ntf_bind() provides the bind-only alternative, with the address defaulting to (0, 0) but exposed as an explicit argument.
--- tools/net/ynl/pyynl/lib/ynl.py | 5 +++++ 1 file changed, 5 insertions(+)
tools/net/ynl/pyynl/lib/ynl.py +5 -0
@@ -680,6 +680,7 @@ class YnlFamily(SpecFamily): Notification API: ynl.ntf_subscribe(mcast_name) -- join a multicast group + ynl.ntf_bind(addr=(0, 0)) -- bind socket for unicast notifications ynl.check_ntf() -- drain pending notifications ynl.poll_ntf(duration=None) -- yield notifications
@@ -748,6 +749,10 @@ class YnlFamily(SpecFamily): self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_ADD_MEMBERSHIP, mcast_id) + def ntf_bind(self, addr=(0, 0)): + """Bind socket for receiving unicast notifications.""" + self.sock.bind(addr) + def set_recv_dbg(self, enabled): self._recv_dbg = enabled
Signature · 1 line
2.54.0
Sashiko flagged a few things on this series, noting my analysis here for the record.
The dp-ifindex field is typed as u32 in the spec while the kernel struct uses "int". All three existing OVS specs (ovs_datapath, ovs_flow, ovs_vport) also use u32 for this field, so I kept it consistent.
key/actions/egress-tun-key are typed as binary rather than nest. This is documented in the commit message and inline comments -- the nested attribute-sets belong to ovs_flow's spec, and YNL does not support cross-spec references.
The execute operation does not carry uns-admin-perm in the spec. The kernel sets GENL_UNS_ADMIN_PERM on it, but none of the existing OVS specs declare admin-perm flags on any of their operations either (ovs_datapath new/del/set, ovs_flow new/del/set, ovs_vport new/del/set all have GENL_UNS_ADMIN_PERM in the kernel but omit it in the YAML).
ntf_bind() will raise OSError if the socket was already bound. ntf_subscribe() has the same constraint -- both expect to be called before any operation that triggers autobind.
Jakub Kicinski
maintainerQuoted 19 lines · On Fri, 22 May 2026 11:24:47 +0800 Minxi Hou wrote:
Sashiko flagged a few things on this series, noting my analysis here for the record.
The dp-ifindex field is typed as u32 in the spec while the kernel struct uses "int". All three existing OVS specs (
ovs_datapath,ovs_flow,ovs_vport) also use u32 for this field, so I kept it consistent.key/actions/egress-tun-key are typed as binary rather than nest. This is documented in the commit message and inline comments -- the nested attribute-sets belong to ovs_flow's spec, and YNL does not support cross-spec references.
The execute operation does not carry uns-admin-perm in the spec. The kernel sets
GENL_UNS_ADMIN_PERMon it, but none of the existing OVS specs declare admin-perm flags on any of their operations either (ovs_datapathnew/del/set,ovs_flownew/del/set,ovs_vportnew/del/set all haveGENL_UNS_ADMIN_PERMin the kernel but omit it in the YAML).
Quoted 3 lines
ntf_bind()will raise OSError if the socket was already bound.ntf_subscribe()has the same constraint -- both expect to be called before any operation that triggers autobind.
Your explanations sound reasonable.
But please rebase and repost, I think some patches merged yesterday will conflict with the new ynl helper.
Signature · 1 line
pw-bot: cr