Skip to contentSkip to conversation

YAML template for MPTCP netlink API

RFC PATCH In review Davide Caratti 2 participants 12 messages Apr 6, 2023 – Jul 18, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover YAML template for MPTCP netlink API

Related: #377

Notes:
- the attributes in the operation list is not really good, we probably need to specify better what parameters are used in the .doit() function (though the generated code is the same). Specifying 'remote_addr' either in 'request' or in 'reply' would probably make patch 2/5 useless.
- I didn't add the multicast groups on purpose. ynl-c.py is not able to generate the operation list for genetlink-legacy, so all this part (including multicast groups) needs to be left unspecified in the template.

Davide Caratti (5):
tools: ynl: add uns-admin-perm to genetlink legacy
tools: ynl: fix bug in case of multiple nested attributes of the same
type
Documentation: netlink: add a YAML spec for mptcp
mptcp: uapi: add header files generated from YAML spec net/mptcp: use netlink policy generated from YAML spec

 Documentation/netlink/genetlink-legacy.yaml |   2 +-
 Documentation/netlink/specs/mptcp.yaml      | 361 ++++++++++++++++++++
 include/uapi/linux/mptcp.h                  | 167 +--------
 include/uapi/linux/mptcp_pm.h               | 145 ++++++++
 net/mptcp/Makefile                          |   3 +-
 net/mptcp/pm_netlink.c                      | 107 +-----
 net/mptcp/pm_nl.c                           |  91 +++++
 net/mptcp/pm_nl.h                           |  39 +++
 net/mptcp/pm_userspace.c                    |   9 +-
 net/mptcp/protocol.h                        |   6 +-
 tools/net/ynl/ynl-gen-c.py                  |   3 +-
 11 files changed, 665 insertions(+), 268 deletions(-)
 create mode 100644 Documentation/netlink/specs/mptcp.yaml
 create mode 100644 include/uapi/linux/mptcp_pm.h
 create mode 100644 net/mptcp/pm_nl.c
 create mode 100644 net/mptcp/pm_nl.h
Signature · 1 line
2.39.2
#1 lore raw

RFC PATCH 1/5 tools: ynl: add uns-admin-perm to genetlink legacy

this flag maps to GENL_UNS_ADMIN_PERM and will be used by future specs.

---
 Documentation/netlink/genetlink-legacy.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/netlink/genetlink-legacy.yaml +1 -1
index b33541a51d6b..6d075bfb712e 100644
@@ -295,7 +295,7 @@ properties:
               description: Command flags.
               type: array
               items:
-                enum: [ admin-perm ]
+                enum: [ admin-perm, uns-admin-perm ]
             dont-validate:
               description: Kernel attribute validation flags.
               type: array
Signature · 1 line
2.39.2
#2 lore raw

RFC PATCH 2/5 tools: ynl: fix bug in case of multiple nested attributes of the same type

In reply to Davide Caratti

when a policy contains multiple nested attributes of the same type, avoid re-initializing .request and .reply members.

---
 tools/net/ynl/ynl-gen-c.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +2 -1
index cc2f8c945340..ba55f217a006 100755
@@ -812,7 +812,8 @@ class Family(SpecFamily):
                     inherit = set()
                     nested = spec['nested-attributes']
                     if nested not in self.root_sets:
-                        self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
+                        if nested not in self.pure_nested_structs:
+                            self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
                     if attr in rs_members['request']:
                         self.pure_nested_structs[nested].request = True
                     if attr in rs_members['reply']:
Signature · 1 line
2.39.2
maintainer
#3 lore raw

Re: [PATCH RFC mptcp-net-next 2/5] tools: ynl: fix bug in case of multiple nested attributes of the same type

Quoted 2 lines · Davide Caratti

when a policy contains multiple nested attributes of the same type, avoid re-initializing .request and .reply members.

It's unclear to me why we need to avoid such re-init...

Quoted 11 lines
---
 tools/net/ynl/ynl-gen-c.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/net/ynl/ynl-gen-c.py +0 -0
index cc2f8c945340..ba55f217a006 100755

tools/net/ynl/ynl-gen-c.py class Family(SpecFamily): · line 816

Quoted 6 lines
tools/net/ynl/ynl-gen-c.py +2 -1
@@ -812,7 +812,8 @@ class Family(SpecFamily):
                     inherit = set()
                     nested = spec['nested-attributes']
                     if nested not in self.root_sets:
-                        self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
+                        if nested not in self.pure_nested_structs:
+                            self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)

... and is unclear to me how the above produces the effect described in the commit message :)

Thanks!

Paolo

#4 lore raw

Re: [PATCH RFC mptcp-net-next 2/5] tools: ynl: fix bug in case of multiple nested attributes of the same type

hi Paolo,

thanks a lot for looking at this!

Quoted 5 lines · Paolo Abeni
Quoted 2 lines · Davide Caratti

when a policy contains multiple nested attributes of the same type, avoid re-initializing .request and .reply members.

It's unclear to me why we need to avoid such re-init...

*disclaimer*: this will sound as a giant word pun, since "pm", "addr" and "attr" are used in any combination in the current netlink API :)

That said:

"attr" has two nested attributes, "addr" and "remote_addr", of the same type "addr". When ynl-gen-c.py parses "addr" (e.g. in the block describing the "add_addr" operation), it sets

self.pure_nested_structs['addr'].Request

equal to True, because at least on operation needs it. Then, when it parses "remote_addr", the call to

Struct(self, nested, inherited=inherit)

will reset the above variable to 'False'. As a consequence, when it comes to print the nla_policy struct, the following code will run:

2127 if args.mode == "kernel":
2128 if args.header:
2129 for _, struct in sorted(parsed.pure_nested_structs.items()):
2130 if struct.request:
2131 cw.p('/* Common nested types */')
2132 break
2133 for attr_set, struct in sorted(parsed.pure_nested_structs.items()):
2134 if struct.request:
2135 print_req_policy_fwd(cw, struct)
2136 cw.nl()

since struct.request has become True and then resetted to False, ynl-gen-c.py refuses to print the nla_policy of the nested attribute. Like I mentioned in the cover letter, changing the yaml spec in a way that at least one operation requires 'remote_addr' in the attribute-set will make this issue disappear; anyway, I think that the current behavior of ynl-gen-c.py is not intentional, that's why I did this fix attempt.

[...]

Quoted 6 lines
Quoted 6 lines
tools/net/ynl/ynl-gen-c.py +0 -0
index cc2f8c945340..ba55f217a006 100755
@@ -812,7 +812,8 @@ class Family(SpecFamily):
                     inherit = set()
Quoted 8 lines

tools/net/ynl/ynl-gen-c.py class Family(SpecFamily): · line 816

Quoted 5 lines
tools/net/ynl/ynl-gen-c.py +2 -1
                     nested = spec['nested-attributes']
                     if nested not in self.root_sets:
-                        self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
+                        if nested not in self.pure_nested_structs:
+                            self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)

... and is unclear to me how the above produces the effect described in the commit message :)

this hunk avoids re-initializing

self.pure_nested_structs['addr'].{request,reply}

when it has already been parsed once. If at least a nested attribute sets 'request' to True, then 'request' remains True also when other nested attributes of the same type are found.

Signature · 1 line
davide
#5 lore raw

Re: [PATCH RFC mptcp-net-next 2/5] tools: ynl: fix bug in case of multiple nested attributes of the same type

In reply to Paolo Abeni
Quoted 13 lines · Paolo Abeni
Quoted 2 lines · Davide Caratti

when a policy contains multiple nested attributes of the same type, avoid re-initializing .request and .reply members.

It's unclear to me why we need to avoid such re-init...

Quoted 6 lines
---
 tools/net/ynl/ynl-gen-c.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

tools/net/ynl/ynl-gen-c.py class Family(SpecFamily): · line 816

Quoted 11 lines
tools/net/ynl/ynl-gen-c.py +2 -1
index cc2f8c945340..ba55f217a006 100755
@@ -812,7 +812,8 @@ class Family(SpecFamily):
                     inherit = set()
                     nested = spec['nested-attributes']
                     if nested not in self.root_sets:
-                        self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
+                        if nested not in self.pure_nested_structs:
+                            self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)

... and is unclear to me how the above produces the effect described in the commit message :)

FTR: I'm removing this patch from the series as it's already in the net-next tree [1]. Thanks!

[1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=67c65ce762adaf3515fe0585

Signature · 1 line
davide
#6 lore raw

RFC PATCH 3/5 Documentation: netlink: add a YAML spec for mptcp

In reply to Davide Caratti
---
 Documentation/netlink/specs/mptcp.yaml | 361 +++++++++++++++++++++++++
 1 file changed, 361 insertions(+)
 create mode 100644 Documentation/netlink/specs/mptcp.yaml
Documentation/netlink/specs/mptcp.yaml new file +361 -0
new file mode 100644
index 000000000000..910307b021ba
@@ -0,0 +1,361 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+
+name: mptcp_pm
+protocol: genetlink-legacy
+doc: Multipath TCP.
+
+c-family-name: mptcp_pm_name
+c-version-name: mptcp_pm_ver
+max-by-define: true
+kernel-policy: global
+
+definitions:
+  -
+    type: enum
+    name: event-type
+    enum-name: mptcp_event_type
+    name-prefix: mptcp_event_
+    entries:
+     -
+      name: unspec
+     -
+      name: created
+      value: 1
+      doc:
+        token, family, saddr4 | saddr6, daddr4 | daddr6, sport, dport
+        A new MPTCP connection has been created. It is the good time to
+        allocate memory and send ADD_ADDR if needed. Depending on the
+        traffic-patterns it can take a long time until the
+        MPTCP_EVENT_ESTABLISHED is sent.
+     -
+      name: established
+      value: 2
+      doc:
+        token, family, saddr4 | saddr6, daddr4 | daddr6, sport, dport
+        A MPTCP connection is established (can start new subflows).
+     -
+      name: closed
+      value: 3
+      doc:
+        token
+        A MPTCP connection has stopped.
+     -
+      name: announced
+      value: 6
+      doc:
+        token, rem_id, family, daddr4 | daddr6 [, dport]
+        A new address has been announced by the peer.
+     -
+      name: removed
+      value: 7
+      doc:
+        token, rem_id
+        An address has been lost by the peer.
+     -
+      name: sub_established
+      value: 10
+      doc:
+        token, family, loc_id, rem_id, saddr4 | saddr6, daddr4 | daddr6, sport,
+        dport, backup, if_idx [, error]
+        A new subflow has been established. 'error' should not be set.
+     -
+      name: sub_closed
+      value: 11
+      doc:
+        token, family, loc_id, rem_id, saddr4 | saddr6, daddr4 | daddr6, sport,
+        dport, backup, if_idx [, error]
+        A subflow has been closed. An error (copy of sk_err) could be set if an
+        error has been detected for this subflow.
+     -
+      name: sub_priority
+      value: 13
+      doc:
+        token, family, loc_id, rem_id, saddr4 | saddr6, daddr4 | daddr6, sport,
+        dport, backup, if_idx [, error]
+        The priority of a subflow has changed. 'error' should not be set.
+     -
+      name: listener_created
+      value: 15
+      doc:
+        family, sport, saddr4 | saddr6
+        A new PM listener is created.
+     -
+      name: listener_closed
+      value: 16
+      doc:
+        family, sport, saddr4 | saddr6
+        A PM listener is closed.
+
+attribute-sets:
+  -
+    name: addr
+    name-prefix: mptcp_pm_addr_attr_
+    attributes:
+      -
+        name: unspec
+        type: unused
+        value: 0
+      -
+        name: family
+        type: u16
+      -
+        name: id
+        type: u8
+      -
+        name: addr4
+        type: u32
+        byte-order: big-endian
+      -
+        name: addr6
+        type: binary
+        checks:
+          min-len: 16
+      -
+        name: port
+        type: u16
+        byte-order: big-endian
+      -
+        name: flags
+        type: u32
+      -
+        name: if_idx
+        type: s32
+  -
+    name: subflow-attribute
+    name-prefix: mptcp_subflow_attr_
+    attributes:
+      -
+        name: unspec
+        type: unused
+        value: 0
+      -
+        name: token_rem
+        type: u32
+      -
+        name: token_loc
+        type: u32
+      -
+        name: relwrite_seq
+        type: u32
+      -
+        name: map_seq
+        type: u64
+      -
+        name: map_sfseq
+        type: u32
+      -
+        name: ssn_offset
+        type: u32
+      -
+        name: map_datalen
+        type: u16
+      -
+        name: flags
+        type: u32
+      -
+        name: id_rem
+        type: u8
+      -
+        name: id_loc
+        type: u8
+      -
+        name: pad
+        type: pad
+  -
+    name: attr
+    name-prefix: mptcp_pm_attr_
+    attributes:
+      -
+        name: unspec
+        type: unused
+        value: 0
+      -
+        name: addr
+        type: nest
+        nested-attributes: addr
+      -
+        name: rcv_add_addrs
+        type: u32
+      -
+        name: subflows
+        type: u32
+      -
+        name: token
+        type: u32
+      -
+        name: loc_id
+        type: u8
+      -
+        name: addr_remote
+        type: nest
+        nested-attributes: addr
+  -
+    name: event_attr
+    enum-name: mptcp_event_attr
+    name-prefix: mptcp_attr_
+    attributes:
+      -
+        name: UNSPEC
+        type: unused
+        value: 0
+      -
+        name: token
+        type: u32
+      -
+        name: family
+        type: u16
+      -
+        name: loc_id
+        type: u8
+      -
+        name: rem_id
+        type: u8
+      -
+        name: saddr4
+        type: u32
+        byte-order: big-endian
+      -
+        name: saddr6
+        type: binary
+        checks:
+          min-len: 16
+      -
+        name: daddr4
+        type: u32
+        byte-order: big-endian
+      -
+        name: daddr6
+        type: binary
+        checks:
+          min-len: 16
+      -
+        name: sport
+        type: u16
+        byte-order: big-endian
+      -
+        name: dport
+        type: u16
+        byte-order: big-endian
+      -
+        name: backup
+        type: u8
+      -
+        name: error
+        type: u8
+      -
+        name: flags
+        type: u16
+      -
+        name: timeout
+        type: u32
+      -
+        name: if_idx
+        type: u32
+      -
+        name: reset_reason
+        type: u32
+      -
+        name: reset_flags
+        type: u32
+      -
+        name: server_side
+        type: u8
+
+operations:
+  list:
+    -
+      name: unspec
+      doc: unused
+      value: 0
+    -
+      name: add_addr
+      doc: Add endpoint
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+
+      do:
+        request: &add_addr_attrs
+          attributes:
+            - addr
+    -
+      name: del_addr
+      doc: Delete endpoint
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+    -
+      name: get_addr
+      doc: Get endpoint information
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+        reply: *add_addr_attrs
+
+      dump:
+        reply: *add_addr_attrs
+    -
+      name:  flush_addrs
+      doc: flush addresses
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+    -
+      name: set_limits
+      doc: Set protocol limits
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: &mptcp_limits
+          attributes:
+            - rcv_add_addrs
+            - subflows
+    -
+      name: get_limits
+      doc: Get protocol limits
+      attribute-set: attr
+      do:
+        request: *mptcp_limits
+        reply: *mptcp_limits
+    -
+      name: set_flags
+      doc: Change endpoint flags
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+    -
+      name: announce
+      doc: announce new sf
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+        reply: *add_addr_attrs
+    -
+      name: remove
+      doc: announce removal
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+        reply: *add_addr_attrs
+    -
+      name: subflow_create
+      doc: todo
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+        reply: *add_addr_attrs
+    -
+      name: subflow_destroy
+      doc: todo
+      attribute-set: attr
+      flags: [ uns-admin-perm ]
+      do:
+        request: *add_addr_attrs
+        reply: *add_addr_attrs
+
Signature · 1 line
2.39.2
maintainer
#7 lore raw

Re: [PATCH RFC mptcp-net-next 3/5] Documentation: netlink: add a YAML spec for mptcp

On Thu, 2023-04-06 at 19:31 +0200, Davide Caratti wrote:
[...]

Documentation/netlink/specs/mptcp.yaml line 97

Quoted 9 lines
Documentation/netlink/specs/mptcp.yaml new file +9 -0
+attribute-sets:
+  -
+    name: addr
+    name-prefix: mptcp_pm_addr_attr_
+    attributes:
+      -
+        name: unspec
+        type: unused
+        value: 0

This entry should not be needed, the tool should add it by default and keep the first item with value == 1.

Quoted 18 lines
Documentation/netlink/specs/mptcp.yaml new file +18 -0
+  -
+    name: attr
+    name-prefix: mptcp_pm_attr_
+    attributes:
+      -
+        name: unspec
+        type: unused
+        value: 0
+      -
+        name: addr
+        type: nest
+        nested-attributes: addr
+      -
+        name: rcv_add_addrs
+        type: u32
+      -
+        name: subflows
+        type: u32

Documentation/netlink/specs/mptcp.yaml line 191

Quoted 10 lines
Documentation/netlink/specs/mptcp.yaml new file +10 -0
+      -
+        name: token
+        type: u32
+      -
+        name: loc_id
+        type: u8
+      -
+        name: addr_remote
+        type: nest
+        nested-attributes: addr

Is this the definition requiring patch 2/5 ?

Are there other attribute set requiring such change?

Thanks!

Paolo

#8 lore raw

Re: [PATCH RFC mptcp-net-next 3/5] Documentation: netlink: add a YAML spec for mptcp

hello Paolo, thanks for looking at this!

Quoted 12 lines · Paolo Abeni

On Thu, 2023-04-06 at 19:31 +0200, Davide Caratti wrote:
[...]

Review

Quoted 9 lines
(quoted diff) +9 -0
+attribute-sets:
+  -
+    name: addr
+    name-prefix: mptcp_pm_addr_attr_
+    attributes:
+      -
+        name: unspec
+        type: unused
+        value: 0
Quoted 2 lines

This entry should not be needed, the tool should add it by default and keep the first item with value == 1.

wouldn't this would break the uAPI? I mean, in the current one we have MPTCP_PM_ADDR_ATTR_UNSPEC equal to zero. Removing the whole element would make MPTCP_PM_ADDR_ATTR_UNSPEC disappear and potentially break the build of userspace programs that use it. See below:

 $ git diff 
Documentation/netlink/specs/mptcp.yaml +0 -4
index 910307b021ba..12974bf0cf10 100644
@@ -91,10 +91,6 @@ attribute-sets:
     name: addr
     name-prefix: mptcp_pm_addr_attr_
     attributes:
-      -
-        name: unspec
-        type: unused
-        value: 0
       -
         name: family
         type: u16
 $ ./tools/net/ynl/ynl-gen-c.py --mode uapi  \
Quoted 2 lines

--spec Documentation/netlink/specs/mptcp.yaml --header \
| grep -B1 -A1 -i addr_attr_family

enum {
MPTCP_PM_ADDR_ATTR_FAMILY = 1,
MPTCP_PM_ADDR_ATTR_ID,

[...]

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+      -
+        name: addr_remote
+        type: nest
+        nested-attributes: addr

Is this the definition requiring patch 2/5 ?

yes! I replied to your comment to patch 2/5 (and hopefully didn't mess with the names ;) )

Quoted 1 line

Are there other attribute set requiring such change?

currently ynl-gen-c.py supports only a single attribute-set for each list of operations - but the effect on the generated code is not relevant AFAIU.

Signature · 1 line
davide
#9 lore raw

RFC PATCH 4/5 mptcp: uapi: add header files generated from YAML spec

In reply to Davide Caratti
 $ ./tools/net/ynl/ynl-gen-c.py --mode uapi \
Quoted 2 lines

--spec Documentation/netlink/specs/mptcp.yaml --header \
-o include/uapi/linux/mptcp_pm.h

and remove these definitions from mptcp.h

---
 include/uapi/linux/mptcp.h    | 167 +---------------------------------
 include/uapi/linux/mptcp_pm.h | 145 +++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+), 163 deletions(-)
 create mode 100644 include/uapi/linux/mptcp_pm.h
include/uapi/linux/mptcp.h +4 -163
index 32af2d278cb4..f919f43a178a 100644
@@ -12,6 +12,10 @@
 #include <linux/in.h>		/* for sockaddr_in			*/
 #include <linux/in6.h>		/* for sockaddr_in6			*/
 #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
+#include <linux/mptcp_pm.h>	/* for netlink interface		*/
+
+#define __MPTCP_PM_CMD_AFTER_LAST  __MPTCP_PM_CMD_MAX
+#define __MPTCP_ATTR_AFTER_LAST	__MPTCP_ATTR_MAX
 
 #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
 #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
@@ -23,88 +27,12 @@
 #define MPTCP_SUBFLOW_FLAG_CONNECTED		_BITUL(7)
 #define MPTCP_SUBFLOW_FLAG_MAPVALID		_BITUL(8)
 
-enum {
-	MPTCP_SUBFLOW_ATTR_UNSPEC,
-	MPTCP_SUBFLOW_ATTR_TOKEN_REM,
-	MPTCP_SUBFLOW_ATTR_TOKEN_LOC,
-	MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ,
-	MPTCP_SUBFLOW_ATTR_MAP_SEQ,
-	MPTCP_SUBFLOW_ATTR_MAP_SFSEQ,
-	MPTCP_SUBFLOW_ATTR_SSN_OFFSET,
-	MPTCP_SUBFLOW_ATTR_MAP_DATALEN,
-	MPTCP_SUBFLOW_ATTR_FLAGS,
-	MPTCP_SUBFLOW_ATTR_ID_REM,
-	MPTCP_SUBFLOW_ATTR_ID_LOC,
-	MPTCP_SUBFLOW_ATTR_PAD,
-	__MPTCP_SUBFLOW_ATTR_MAX
-};
-
-#define MPTCP_SUBFLOW_ATTR_MAX (__MPTCP_SUBFLOW_ATTR_MAX - 1)
-
-/* netlink interface */
-#define MPTCP_PM_NAME		"mptcp_pm"
-#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
-#define MPTCP_PM_EV_GRP_NAME	"mptcp_pm_events"
-#define MPTCP_PM_VER		0x1
-
-/*
- * ATTR types defined for MPTCP
- */
-enum {
-	MPTCP_PM_ATTR_UNSPEC,
-
-	MPTCP_PM_ATTR_ADDR,				/* nested address */
-	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
-	MPTCP_PM_ATTR_SUBFLOWS,				/* u32 */
-	MPTCP_PM_ATTR_TOKEN,				/* u32 */
-	MPTCP_PM_ATTR_LOC_ID,				/* u8 */
-	MPTCP_PM_ATTR_ADDR_REMOTE,			/* nested address */
-
-	__MPTCP_PM_ATTR_MAX
-};
-
-#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
-
-enum {
-	MPTCP_PM_ADDR_ATTR_UNSPEC,
-
-	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
-	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
-	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
-	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
-	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */
-	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
-	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
-
-	__MPTCP_PM_ADDR_ATTR_MAX
-};
-
-#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
-
 #define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
 #define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
 #define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)
 #define MPTCP_PM_ADDR_FLAG_FULLMESH			(1 << 3)
 #define MPTCP_PM_ADDR_FLAG_IMPLICIT			(1 << 4)
 
-enum {
-	MPTCP_PM_CMD_UNSPEC,
-
-	MPTCP_PM_CMD_ADD_ADDR,
-	MPTCP_PM_CMD_DEL_ADDR,
-	MPTCP_PM_CMD_GET_ADDR,
-	MPTCP_PM_CMD_FLUSH_ADDRS,
-	MPTCP_PM_CMD_SET_LIMITS,
-	MPTCP_PM_CMD_GET_LIMITS,
-	MPTCP_PM_CMD_SET_FLAGS,
-	MPTCP_PM_CMD_ANNOUNCE,
-	MPTCP_PM_CMD_REMOVE,
-	MPTCP_PM_CMD_SUBFLOW_CREATE,
-	MPTCP_PM_CMD_SUBFLOW_DESTROY,
-
-	__MPTCP_PM_CMD_AFTER_LAST
-};
-
 #define MPTCP_INFO_FLAG_FALLBACK		_BITUL(0)
 #define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED	_BITUL(1)
 
@@ -125,93 +53,6 @@ struct mptcp_info {
 	__u8	mptcpi_csum_enabled;
 };
 
-/*
- * MPTCP_EVENT_CREATED: token, family, saddr4 | saddr6, daddr4 | daddr6,
- *                      sport, dport
- * A new MPTCP connection has been created. It is the good time to allocate
- * memory and send ADD_ADDR if needed. Depending on the traffic-patterns
- * it can take a long time until the MPTCP_EVENT_ESTABLISHED is sent.
- *
- * MPTCP_EVENT_ESTABLISHED: token, family, saddr4 | saddr6, daddr4 | daddr6,
- *			    sport, dport
- * A MPTCP connection is established (can start new subflows).
- *
- * MPTCP_EVENT_CLOSED: token
- * A MPTCP connection has stopped.
- *
- * MPTCP_EVENT_ANNOUNCED: token, rem_id, family, daddr4 | daddr6 [, dport]
- * A new address has been announced by the peer.
- *
- * MPTCP_EVENT_REMOVED: token, rem_id
- * An address has been lost by the peer.
- *
- * MPTCP_EVENT_SUB_ESTABLISHED: token, family, loc_id, rem_id,
- *                              saddr4 | saddr6, daddr4 | daddr6, sport,
- *                              dport, backup, if_idx [, error]
- * A new subflow has been established. 'error' should not be set.
- *
- * MPTCP_EVENT_SUB_CLOSED: token, family, loc_id, rem_id, saddr4 | saddr6,
- *                         daddr4 | daddr6, sport, dport, backup, if_idx
- *                         [, error]
- * A subflow has been closed. An error (copy of sk_err) could be set if an
- * error has been detected for this subflow.
- *
- * MPTCP_EVENT_SUB_PRIORITY: token, family, loc_id, rem_id, saddr4 | saddr6,
- *                           daddr4 | daddr6, sport, dport, backup, if_idx
- *                           [, error]
- * The priority of a subflow has changed. 'error' should not be set.
- *
- * MPTCP_EVENT_LISTENER_CREATED: family, sport, saddr4 | saddr6
- * A new PM listener is created.
- *
- * MPTCP_EVENT_LISTENER_CLOSED: family, sport, saddr4 | saddr6
- * A PM listener is closed.
- */
-enum mptcp_event_type {
-	MPTCP_EVENT_UNSPEC = 0,
-	MPTCP_EVENT_CREATED = 1,
-	MPTCP_EVENT_ESTABLISHED = 2,
-	MPTCP_EVENT_CLOSED = 3,
-
-	MPTCP_EVENT_ANNOUNCED = 6,
-	MPTCP_EVENT_REMOVED = 7,
-
-	MPTCP_EVENT_SUB_ESTABLISHED = 10,
-	MPTCP_EVENT_SUB_CLOSED = 11,
-
-	MPTCP_EVENT_SUB_PRIORITY = 13,
-
-	MPTCP_EVENT_LISTENER_CREATED = 15,
-	MPTCP_EVENT_LISTENER_CLOSED = 16,
-};
-
-enum mptcp_event_attr {
-	MPTCP_ATTR_UNSPEC = 0,
-
-	MPTCP_ATTR_TOKEN,	/* u32 */
-	MPTCP_ATTR_FAMILY,	/* u16 */
-	MPTCP_ATTR_LOC_ID,	/* u8 */
-	MPTCP_ATTR_REM_ID,	/* u8 */
-	MPTCP_ATTR_SADDR4,	/* be32 */
-	MPTCP_ATTR_SADDR6,	/* struct in6_addr */
-	MPTCP_ATTR_DADDR4,	/* be32 */
-	MPTCP_ATTR_DADDR6,	/* struct in6_addr */
-	MPTCP_ATTR_SPORT,	/* be16 */
-	MPTCP_ATTR_DPORT,	/* be16 */
-	MPTCP_ATTR_BACKUP,	/* u8 */
-	MPTCP_ATTR_ERROR,	/* u8 */
-	MPTCP_ATTR_FLAGS,	/* u16 */
-	MPTCP_ATTR_TIMEOUT,	/* u32 */
-	MPTCP_ATTR_IF_IDX,	/* s32 */
-	MPTCP_ATTR_RESET_REASON,/* u32 */
-	MPTCP_ATTR_RESET_FLAGS, /* u32 */
-	MPTCP_ATTR_SERVER_SIDE,	/* u8 */
-
-	__MPTCP_ATTR_AFTER_LAST
-};
-
-#define MPTCP_ATTR_MAX (__MPTCP_ATTR_AFTER_LAST - 1)
-
 /* MPTCP Reset reason codes, rfc8684 */
 #define MPTCP_RST_EUNSPEC	0
 #define MPTCP_RST_EMPTCP	1
include/uapi/linux/mptcp_pm.h new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.39.2
#10 lore raw

RFC PATCH 5/5 net/mptcp: use netlink policy generated from YAML spec

In reply to Davide Caratti
 $ ./tools/net/ynl/ynl-gen-c.py --mode kernel  \
Quoted 2 lines

--spec Documentation/netlink/specs/mptcp.yaml --header \
-o net/mptcp/pm_nl.h

 $ ./tools/net/ynl/ynl-gen-c.py --mode kernel  \
Quoted 2 lines

--spec Documentation/netlink/specs/mptcp.yaml --source \
-o net/mptcp/pm_nl.c

and remove the old ones we had in pm_netlink.c/pm_userspace.c

---
 net/mptcp/Makefile       |   3 +-
 net/mptcp/pm_netlink.c   | 107 +++++----------------------------------
 net/mptcp/pm_nl.c        |  91 +++++++++++++++++++++++++++++++++
 net/mptcp/pm_nl.h        |  39 ++++++++++++++
 net/mptcp/pm_userspace.c |   9 ++--
 net/mptcp/protocol.h     |   6 +--
 6 files changed, 152 insertions(+), 103 deletions(-)
 create mode 100644 net/mptcp/pm_nl.c
 create mode 100644 net/mptcp/pm_nl.h
net/mptcp/Makefile +2 -1
index 84e531f86b82..dedd1bf8d052 100644
@@ -2,7 +2,8 @@
 obj-$(CONFIG_MPTCP) += mptcp.o
 
 mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
-	   mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o
+	   mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o \
+	   pm_nl.o
 
 obj-$(CONFIG_SYN_COOKIES) += syncookies.o
 obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o
net/mptcp/pm_netlink.c +13 -94

179 lines not on this page · raw message

net/mptcp/pm_nl.c new file +91 -0

91 lines not on this page · raw message

net/mptcp/pm_nl.h new file +39 -0
new file mode 100644
index 000000000000..26dd13f3244d
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
+/* Do not edit directly, auto-generated from: */
+/*	Documentation/netlink/specs/mptcp.yaml */
+/* YNL-GEN kernel header */
+
+#ifndef _LINUX_MPTCP_PM_GEN_H
+#define _LINUX_MPTCP_PM_GEN_H
+
+#include <net/netlink.h>
+#include <net/genetlink.h>
+
+#include <linux/mptcp_pm.h>
+
+/* Common nested types */
+extern const struct nla_policy mptcp_pm_addr_nl_policy[MPTCP_PM_ADDR_ATTR_IF_IDX + 1];
+
+/* Global operation policy for mptcp_pm */
+extern const struct nla_policy mptcp_pm_attr_nl_policy[MPTCP_PM_ATTR_ADDR_REMOTE + 1];
+
+/* Ops table for mptcp_pm */
+extern const struct genl_small_ops mptcp_pm_nl_ops[11];
+
+int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *skb,
+				struct netlink_callback *cb);
+int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_set_limits_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_get_limits_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb,
+				    struct genl_info *info);
+int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb,
+				     struct genl_info *info);
+
+#endif /* _LINUX_MPTCP_PM_GEN_H */
net/mptcp/pm_userspace.c +5 -4
index 27a275805c06..8936d0f80884 100644
@@ -122,7 +122,7 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,
 	return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry);
 }
 
-int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
+int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
 	struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR];
@@ -184,7 +184,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
 	return err;
 }
 
-int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info)
+int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
 	struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID];
@@ -246,7 +246,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info)
 	return err;
 }
 
-int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct genl_info *info)
+int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
 	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
@@ -361,7 +361,8 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk,
 	return NULL;
 }
 
-int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info)
+int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb,
+				     struct genl_info *info)
 {
 	struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
 	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
net/mptcp/protocol.h +2 -4
index 5a35c77723e3..ca33d2808b61 100644
@@ -13,6 +13,8 @@
 #include <uapi/linux/mptcp.h>
 #include <net/genetlink.h>
 
+#include "pm_nl.h" /* for netlink interface */
+
 #define MPTCP_SUPPORTED_VERSION	1
 
 /* MPTCP option bits */
@@ -849,10 +851,6 @@ void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
 					struct list_head *rm_list);
 
 void mptcp_free_local_addr_list(struct mptcp_sock *msk);
-int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info);
-int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info);
-int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct genl_info *info);
-int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info);
 
 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
 		 const struct sock *ssk, gfp_t gfp);
Signature · 1 line
2.39.2
maintainer
#11 lore raw

Re: [PATCH RFC mptcp-net-next 5/5] net/mptcp: use netlink policy generated from YAML spec

Quoted 6 lines · Davide Caratti
 $ ./tools/net/ynl/ynl-gen-c.py --mode kernel  \
Quoted 2 lines

--spec Documentation/netlink/specs/mptcp.yaml --header \
-o net/mptcp/pm_nl.h

 $ ./tools/net/ynl/ynl-gen-c.py --mode kernel  \
Quoted 2 lines

--spec Documentation/netlink/specs/mptcp.yaml --source \
-o net/mptcp/pm_nl.c

perhaps:

pm_nl_autogen.{c,h}

or

pm_nl_spec.{c,h}

to avoid confusion vs pm_netlink ?

Thanks!

Paolo