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 |
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[].
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[].
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 --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
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(-)