Open tomkcook opened 6 years ago
Is it possible that the nftables are not supported by the kernel you run the code on? I couldn't reproduce.
What version of Linux are you using? Linux 5.4 got a lot stricter about nested attributes. Specifically, it looks like pyroute2 is not setting NLA_F_NESTED on some/all NLAs and nla_parse_nested
will reject these attrs.
So I'm definitely seeing this in other code. An NLA with nla_flags = NLA_F_NESTED
is setting the right type in encode, but in the kernel attr->nla_type & NLA_F_NESTED
is false.
But I can't figure out why, since the pyroute2 code seems to be doing the right thing.
Actually, I figured out the issue. If you append an NLA directly, it does not set the NESTED bit. If you extract the attrs from the NLA and append that, it does. Sorry for hijacking this thread.
@pallas np, you're probably right. I just can not reproduce the issue. Do you know the conditions? It works starting at least from kernel version 4.19.x and up to net-next. I'll try older versions later, if I will have time.
Yeah, I do. Sorry if this is a bit abstract, but if you have a top_level_thing
of type genlmsg
class with *nested_thing
in the nla_map
, and you try to do
tlt = top_level_thing()
nt = nested_thing()
tlt['attrs'].append(('NESTED_THINGS', [nl]))
it does not set the NESTED bit. If instead you do
tlt = top_level_thing()
nt = nested_thing()
tlt['attrs'].append(('NESTED_THINGS', [{'attrs': nt['attrs']}]))
then the NESTED bit is set.
I ended up making the above transformation in https://github.com/pallas/wgnlpy/commit/cb37bf269cbec72439f59183762046c653c39f1a to get that project working on Linux 5.4, but I think the check might have come in with Linux 5.2.
And specifically, I have not tried this with NFTables. (Hence the apology for hijacking the thread.)
I'll have a look into debugging this, but I'm not exactly sure where to start.