diff mbox series

[net-next,v3,3/4] tools/net/ynl: Handle acks that use req_value

Message ID 20240416193215.8259-4-donald.hunter@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series netlink: Add nftables spec w/ multi messages | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-17--09-00 (tests: 959)

Commit Message

Donald Hunter April 16, 2024, 7:32 p.m. UTC
The nfnetlink family uses the directional op model but errors get
reported using the request value instead of the reply value.

Add a method get_op_by_value that falls back to returning the request op
for directional ops.

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
 tools/net/ynl/lib/nlspec.py | 12 ++++++++++++
 tools/net/ynl/lib/ynl.py    |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski April 17, 2024, 2:10 a.m. UTC | #1
On Tue, 16 Apr 2024 20:32:14 +0100 Donald Hunter wrote:
> The nfnetlink family uses the directional op model but errors get
> reported using the request value instead of the reply value.

What's an error in this case ? "Normal" errors come via NLMSG_ERROR

> diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
> index 6d08ab9e213f..04085bc6365e 100644
> --- a/tools/net/ynl/lib/nlspec.py
> +++ b/tools/net/ynl/lib/nlspec.py
> @@ -567,6 +567,18 @@ class SpecFamily(SpecElement):
>            return op
>        return None
>  
> +    def get_op_by_value(self, value):
> +        """
> +        For a given operation value, look up operation spec. Search
> +        by response value first then fall back to request value. This
> +        is required for handling failure cases.

Looks like we're only going to need it in NetlinkProtocol, so that's
fine. But let's somehow call out that this is a bit of a hack, so that
people don't feel like this is the more correct way of finding the op
than direct access to rsp_by_value[].
Donald Hunter April 17, 2024, 12:51 p.m. UTC | #2
Jakub Kicinski <kuba@kernel.org> writes:

> On Tue, 16 Apr 2024 20:32:14 +0100 Donald Hunter wrote:
>> The nfnetlink family uses the directional op model but errors get
>> reported using the request value instead of the reply value.
>
> What's an error in this case ? "Normal" errors come via NLMSG_ERROR

Thanks for pointing out what should have been obvious. Looking at it
again today, I realise I missed the root cause which was a bug in the
extack decoding for directional ops. When I fix that issue, this patch
can be dropped.

>> diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
>> index 6d08ab9e213f..04085bc6365e 100644
>> --- a/tools/net/ynl/lib/nlspec.py
>> +++ b/tools/net/ynl/lib/nlspec.py
>> @@ -567,6 +567,18 @@ class SpecFamily(SpecElement):
>>            return op
>>        return None
>>  
>> +    def get_op_by_value(self, value):
>> +        """
>> +        For a given operation value, look up operation spec. Search
>> +        by response value first then fall back to request value. This
>> +        is required for handling failure cases.
>
> Looks like we're only going to need it in NetlinkProtocol, so that's
> fine. But let's somehow call out that this is a bit of a hack, so that
> people don't feel like this is the more correct way of finding the op
> than direct access to rsp_by_value[].
Jakub Kicinski April 17, 2024, 1:50 p.m. UTC | #3
On Wed, 17 Apr 2024 13:51:38 +0100 Donald Hunter wrote:
> > On Tue, 16 Apr 2024 20:32:14 +0100 Donald Hunter wrote:  
> >> The nfnetlink family uses the directional op model but errors get
> >> reported using the request value instead of the reply value.  
> >
> > What's an error in this case ? "Normal" errors come via NLMSG_ERROR  
> 
> Thanks for pointing out what should have been obvious. Looking at it
> again today, I realise I missed the root cause which was a bug in the
> extack decoding for directional ops. When I fix that issue, this patch
> can be dropped.

Ha :) Feel free to post v4 as soon as ready.
diff mbox series

Patch

diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index 6d08ab9e213f..04085bc6365e 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -567,6 +567,18 @@  class SpecFamily(SpecElement):
           return op
       return None
 
+    def get_op_by_value(self, value):
+        """
+        For a given operation value, look up operation spec. Search
+        by response value first then fall back to request value. This
+        is required for handling failure cases.
+        """
+        if value in self.rsp_by_value:
+            return self.rsp_by_value[value]
+        if self.msg_id_model == 'directional' and value in self.req_by_value:
+            return self.req_by_value[value]
+        return None
+
     def resolve(self):
         self.resolve_up(super())
 
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index a45e53ab0dd9..eb6c5475fb48 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -390,7 +390,7 @@  class NetlinkProtocol:
         msg = self._decode(nl_msg)
         fixed_header_size = 0
         if ynl:
-            op = ynl.rsp_by_value[msg.cmd()]
+            op = ynl.get_op_by_value(msg.cmd())
             fixed_header_size = ynl._struct_size(op.fixed_header)
         msg.raw_attrs = NlAttrs(msg.raw, fixed_header_size)
         return msg