Skip to contentSkip to conversation

nft typeof keywork patch

DISCUSSION Florian Westphal 2 participants 4 messages Sep 13, 2017 – Sep 15, 2017 2 messages not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 20170913115823.GA2297@salvia

Florian Westphal

author maintainer
#2 lore raw
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Florian Westphal

I am looking into adding 'string' type for sets.
To do this I'd need to add the typeof command that you mentioned last year:
https://marc.info/?l=netfilter-devel&m=145683813130409&w=2

[..]

Quoted 2 lines

Missing part is to add a UDATA_SET_TYPEOF to store the original datatype. So, we dumping back the ruleset, we get same listing.

Wait, so

    nft add set ip filter set1 { typeof ip saddr;}

then it should not list

    nft add set ip filter set1 { type ipv4_addr;}

but the exact input using the typeof()?

I wonder how to encode this, especially given we also need to support concatenation, e.g.

nft add set ip f s { type ipv4_addr . typeof meta iifname . typeof tcp dport ;}

Quoted 1 line

See UDATA_SET_KEYBYTEORDER and UDATA_SET_DATABYTEORDER for instance.

They don't need to store a vector.

For the above we'd need to store the exact text input string to rebuild cmdline.

I think this needs to store something like this in the kernel:
":4-meta iifname:16-tcp dport:2'.

and nft needs to chew through this to learn the typeof and the size of the datatype.

Alternatively we need infra in nft to obtain the template that was used to derive the size from the input string ("meta iifname").

I guess the latter should also be doable. If we do this then we'd only need to store something like "-meta iifname-tcp dport" to help with splitting the key into its components.

Quoted 6 lines
Quoted 1 line

meta mark set typeof(meta mark) ip saddr

Casting is something we should definitely explore, yes. Question here is that we would need to annotate somewhere that the user has specified typeof(), or any cast, so we dump back exactly what the user is asking for. Probably this needs userdata area for expressions.

Yes, seems like above needs to annotate payload expression (ip saddr) with the typecast info. Alternatively however this MIGHT be able to be detectable on userspace side, e.g.

meta mark set ip saddr

We know that meta mark wants the packet mark, so we could infer that user forced an override of the type mismatch, and that can be determined by looking at the expressions' data type.

#3 lore raw
Quoted 20 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Florian Westphal

I am looking into adding 'string' type for sets.
To do this I'd need to add the typeof command that you mentioned last year:
https://marc.info/?l=netfilter-devel&m=145683813130409&w=2

[..]

Quoted 2 lines

Missing part is to add a UDATA_SET_TYPEOF to store the original datatype. So, we dumping back the ruleset, we get same listing.

Wait, so

    nft add set ip filter set1 { typeof ip saddr;}

then it should not list

    nft add set ip filter set1 { type ipv4_addr;}

but the exact input using the typeof()?

Quoted 8 lines

I wonder how to encode this, especially given we also need to support concatenation, e.g.

nft add set ip f s { type ipv4_addr . typeof meta iifname . typeof tcp dport ;}

Quoted 1 line

See UDATA_SET_KEYBYTEORDER and UDATA_SET_DATABYTEORDER for instance.

They don't need to store a vector.

These UDATA_SET_KEYBYTEORDER and UDATA_SET_DATABYTEORDER should be split not to store a vector anymore. We should have one UDATA_SET_KEYBYTEORDERX for each component of the tuple.

Quoted 27 lines

For the above we'd need to store the exact text input string to rebuild cmdline.

I think this needs to store something like this in the kernel:
":4-meta iifname:16-tcp dport:2'.

and nft needs to chew through this to learn the typeof and the size of the datatype.

Alternatively we need infra in nft to obtain the template that was used to derive the size from the input string ("meta iifname").

I guess the latter should also be doable. If we do this then we'd only need to store something like "-meta iifname-tcp dport" to help with splitting the key into its components.

Quoted 6 lines
Quoted 1 line

meta mark set typeof(meta mark) ip saddr

Casting is something we should definitely explore, yes. Question here is that we would need to annotate somewhere that the user has specified typeof(), or any cast, so we dump back exactly what the user is asking for. Probably this needs userdata area for expressions.

Yes, seems like above needs to annotate payload expression (ip saddr) with the typecast info. Alternatively however this MIGHT be able to be detectable on userspace side, e.g.

Quoted 5 lines

meta mark set ip saddr

We know that meta mark wants the packet mark, so we could infer that user forced an override of the type mismatch, and that can be determined by looking at the expressions' data type.

That's another possibility, yes.

I would start with typeof() support for set, then we look at casting.

author maintainer
#4 lore raw
Quoted 10 lines
Quoted 10 lines

Wait, so

    nft add set ip filter set1 { typeof ip saddr;}

then it should not list

    nft add set ip filter set1 { type ipv4_addr;}

but the exact input using the typeof()?

I wonder how to encode this, especially given we also need to support concatenation, e.g.

I've started with this, first item i am working on is to change struct set to pass in struct expr *key instead of datatype+len to make the original expression (meta iifname for example) available to the linerize parts so we can stash this info in the udata.

For "typeof(meta iifname) . mark" case the parser will generate a concat expression, and, since these keep the original expr around we can iterate over that list to get back the original expressions.

For the normal 'type' case, i think we can simply use a dummy constant expression to serve as a container for the data type.

What do you think?

#5 lore raw
Quoted 11 lines · Florian Westphal
Quoted 10 lines
Quoted 10 lines

Wait, so

    nft add set ip filter set1 { typeof ip saddr;}

then it should not list

    nft add set ip filter set1 { type ipv4_addr;}

but the exact input using the typeof()?

I wonder how to encode this, especially given we also need to support concatenation, e.g.

Quoted 8 lines

I've started with this, first item i am working on is to change struct set to pass in struct expr *key instead of datatype+len to make the original expression (meta iifname for example) available to the linerize parts so we can stash this info in the udata.

For "typeof(meta iifname) . mark" case the parser will generate a concat expression, and, since these keep the original expr around we can iterate over that list to get back the original expressions.

Yes, a list is going to be much cleaner and I would expect it simplies the code. I remember Carlos Falgueras sent me a patch for this in a batch he made, however, for whatever reason it never reached upstream.

Quoted 4 lines

For the normal 'type' case, i think we can simply use a dummy constant expression to serve as a container for the data type.

What do you think?

Sounds reasonable, give a shot.