typeof incremental enhancements
Pablo Neira Ayuso
maintainercover typeof incremental enhancements
Hi Florian,
This patchset removes the need to self invoke the parser and the evaluation to fetch the datatype. Instead, the expression type and the expression description are stored into the userdata area.
This patch only supports for the payload expression, but it should be relatively easy to extend it to support for other existing expressions types.
This patch could be squashed into 06/11 src: add "typeof" print support of your patch series, which is actually not just adding support for printing but also for building the userdata.
Thanks.
Pablo Neira Ayuso (3):
proto: add proto_desc_id enumeration
expr: add expr_ops_by_type()
expr: add parse and build userdata interface
include/expression.h | 5 +++ include/proto.h | 27 +++++++++++++ src/expression.c | 12 ++++++ src/mnl.c | 28 +++++--------- src/netlink.c | 105 +++++++++++++++++---------------------------------- src/payload.c | 80 +++++++++++++++++++++++++++++++++++++++ src/proto.c | 46 ++++++++++++++++++++++ 7 files changed, 214 insertions(+), 89 deletions(-)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 1/3 proto: add proto_desc_id enumeration
This allows to uniquely identify the protocol description.
--- include/proto.h | 27 +++++++++++++++++++++++++++ src/proto.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
include/proto.h +27 -0
@@ -63,10 +63,34 @@ struct proto_hdr_template {#define PROTO_UPPER_MAX 16#define PROTO_HDRS_MAX 20 +enum proto_desc_id { +PROTO_DESC_UNKNOWN =0 , +PROTO_DESC_AH , +PROTO_DESC_ESP , +PROTO_DESC_COMP , +PROTO_DESC_ICMP , +PROTO_DESC_IGMP , +PROTO_DESC_UDP , +PROTO_DESC_UDPLITE , +PROTO_DESC_TCP , +PROTO_DESC_DCCP , +PROTO_DESC_SCTP , +PROTO_DESC_TH , +PROTO_DESC_IP , +PROTO_DESC_IP6 , +PROTO_DESC_ICMPV6 , +PROTO_DESC_ARP , +PROTO_DESC_VLAN , +PROTO_DESC_ETHER , + __PROTO_DESC_MAX +}; +#define PROTO_DESC_MAX (__PROTO_DESC_MAX - 1) +/** * struct proto_desc - protocol header description * * @name: protocol name +* @id: protocol identifier * @base: header base * @checksum_key: key of template containing checksum * @protocol_key: key of template containing upper layer protocol description
@@ -77,6 +101,7 @@ struct proto_hdr_template {*/ struct proto_desc {const char *name; +enum proto_desc_id id;enum proto_bases base;unsigned int checksum_key;unsigned int protocol_key;
@@ -160,6 +185,8 @@ extern const struct proto_desc *proto_find_upper(const struct proto_desc *base,extern int proto_find_num (const struct proto_desc *base,const struct proto_desc *desc); +extern const struct proto_desc *proto_find_desc (enum proto_desc_id desc_id); +enum eth_hdr_fields {ETHHDR_INVALID ,ETHHDR_DADDR ,
src/proto.c +46 -0
151 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/3 expr: add expr_ops_by_type()
In reply to Pablo Neira AyusoFetch expression operation from the expression type.
--- include/expression.h | 1 + src/expression.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
include/expression.h +1 -0
@@ -169,6 +169,7 @@ struct expr_ops { };const struct expr_ops *expr_ops (const struct expr *e); +const struct expr_ops *expr_ops_by_type (enum expr_types etype);/** * enum expr_flags
src/expression.c +12 -0
@@ -1222,3 +1222,15 @@ const struct expr_ops *expr_ops(const struct expr *e)BUG ("Unknown expression type %d\n" , e->etype); } + +const struct expr_ops *expr_ops_by_type (enum expr_types etype) +{ +switch (etype) { +case EXPR_PAYLOAD : +return &payload_expr_ops; +default : +break ; + } + +BUG ("Unknown expression type %d\n" , etype); +}
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/3 expr: add parse and build userdata interface
In reply to Pablo Neira AyusoThis patch adds two new expression operations to build and to parse the userdata area that describe the set key and data typeof definitions.
--- include/expression.h | 4 ++ src/mnl.c | 28 +++++--------- src/netlink.c | 105 +++++++++++++++++---------------------------------- src/payload.c | 80 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 89 deletions(-)
include/expression.h +4 -0
@@ -10,6 +10,7 @@#include <utils.h> #include <list.h> #include <json.h> +#include <libnftnl/udata.h> /** * enum expr_types
@@ -166,6 +167,9 @@ struct expr_ops { const struct expr *e2);void (*pctx_update)(struct proto_ctx *ctx,const struct expr *expr); +int (*build_udata)(struct nftnl_udata_buf *udbuf, +const struct expr *expr); +struct expr * (*parse_udata)(const struct nftnl_udata *ud); };const struct expr_ops *expr_ops (const struct expr *e);
src/mnl.c +9 -19
@@ -816,28 +816,18 @@ static void set_key_expression(struct netlink_ctx *ctx, struct nftnl_udata_buf *udbuf, unsigned int type) { -struct output_ctx octx = {}; -char buf[64 ]; +struct nftnl_udata *nest1, *nest2;if (expr->flags &EXPR_F_CONSTANT || set_flags &NFT_SET_ANONYMOUS )return ; - buf[0 ] =0 ; -/* Set definition uses typeof to define datatype. */ - octx.output_fp =fmemopen (buf,sizeof (buf),"w" ); -if (octx.output_fp) { -char *end; - -expr_print (expr, &octx); -fclose (octx.output_fp); - end =strchr (buf,'&' ); -if (end) - * end =0 ; - -if (!nftnl_udata_put (udbuf, type,strlen (buf) +1 , buf)) -memory_allocation_error (); - } + nest1 =nftnl_udata_nest_start (udbuf, type); +nftnl_udata_put_u32 (udbuf,NFTNL_UDATA_SET_TYPEOF_EXPR , expr->etype); + nest2 =nftnl_udata_nest_start (udbuf,NFTNL_UDATA_SET_TYPEOF_DATA ); +expr_ops (expr)->build_udata (udbuf, expr); +nftnl_udata_nest_end (udbuf, nest2); +nftnl_udata_nest_end (udbuf, nest1); }/*
@@ -910,9 +900,9 @@ int mnl_nft_set_add(struct netlink_ctx *ctx, const struct cmd *cmd, set->automerge))memory_allocation_error (); -set_key_expression (ctx, set->key, set->flags, udbuf,NFTNL_UDATA_SET_TYPEOF_KEY ); +set_key_expression (ctx, set->key, set->flags, udbuf,NFTNL_UDATA_SET_KEY_TYPEOF );if (set->data) -set_key_expression (ctx, set->data, set->flags, udbuf,NFTNL_UDATA_SET_TYPEOF_DATA ); +set_key_expression (ctx, set->data, set->flags, udbuf,NFTNL_UDATA_SET_DATA_TYPEOF );nftnl_set_set_data (nls,NFTNL_SET_USERDATA ,nftnl_udata_buf_data (udbuf),nftnl_udata_buf_len (udbuf));
src/netlink.c +35 -70
144 lines not on this page · raw message
src/payload.c +80 -0
92 lines not on this page · raw message
Signature · 1 line
2.11.0
Florian Westphal
maintainerQuoted 6 lines · Pablo Neira Ayuso
Hi Florian,
This patchset removes the need to self invoke the parser and the evaluation to fetch the datatype. Instead, the expression type and the expression description are stored into the userdata area.
Quoted 7 lines
This patch only supports for the payload expression, but it should be relatively easy to extend it to support for other existing expressions types.
This patch could be squashed into 06/11 src: add "typeof" print support of your patch series, which is actually not just adding support for printing but also for building the userdata.
I had considered that but found that storing netlink data
needs more space in the udata area compared to text and it needs more/extra parsing for serialize/deserialize, so I abandoned this idea.
If you think its the way to go, then ok, I can rework it but I will be unable to add the extra steps for other expression types for some time I fear.
Pablo Neira Ayuso
maintainerQuoted 11 lines · Florian Westphal
Quoted 10 lines · Pablo Neira Ayuso
Hi Florian,
This patchset removes the need to self invoke the parser and the evaluation to fetch the datatype. Instead, the expression type and the expression description are stored into the userdata area.
This patch only supports for the payload expression, but it should be relatively easy to extend it to support for other existing expressions types.
Quoted 7 lines
Quoted 3 lines
This patch could be squashed into 06/11 src: add "typeof" print support of your patch series, which is actually not just adding support for printing but also for building the userdata.
I had considered that but found that storing netlink data
needs more space in the udata area compared to text and it needs more/extra parsing for serialize/deserialize, so I abandoned this idea.
Yes, it's scratching a bit extra of the userdata area.
The listing path should be easier, since it's just parsing the TLVs instead of invoking the nft parsing and evaluation phases.
Quoted 3 lines
If you think its the way to go, then ok, I can rework it but I will be unable to add the extra steps for other expression types for some time I fear.
If you send a v3 including this work, I'll finishing the remaining expressions.
One more thing regarding your patchset is:
integer,128
If the typeof works for all of the existing selectors, then I think there is not need to expose this raw type, right?
Thanks.
Florian Westphal
maintainerQuoted 9 lines · Pablo Neira Ayuso
The listing path should be easier, since it's just parsing the TLVs instead of invoking the nft parsing and evaluation phases.
Quoted 3 lines
If you think its the way to go, then ok, I can rework it but I will be unable to add the extra steps for other expression types for some time I fear.
If you send a v3 including this work, I'll finishing the remaining expressions.
Ok, will respin.
Quoted 6 lines
One more thing regarding your patchset is:
integer,128If the typeof works for all of the existing selectors, then I think there is not need to expose this raw type, right?
How would you handle the 'udate missing' case?
If its not a problem to display a non-restoreable ruleset (e.g. unspecific 'type integer' shown as set keys) in that case then the interger,width part can be omitted indeed.
Let me know. For concatenations, we will be unable to show a proper ruleset without the udata info anyway (concatentations do not work at the moment for non-specific types anyway though).
Pablo Neira Ayuso
maintainerQuoted 4 lines · Florian Westphal
Quoted 3 lines · Pablo Neira Ayuso
The listing path should be easier, since it's just parsing the TLVs instead of invoking the nft parsing and evaluation phases.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
If you think its the way to go, then ok, I can rework it but I will be unable to add the extra steps for other expression types for some time I fear.
If you send a v3 including this work, I'll finishing the remaining expressions.
Ok, will respin.
Thanks!
Quoted 9 lines
Quoted 6 lines
One more thing regarding your patchset is:
integer,128If the typeof works for all of the existing selectors, then I think there is not need to expose this raw type, right?
How would you handle the 'udate missing' case?
Quoted 7 lines
If its not a problem to display a non-restoreable ruleset (e.g. unspecific 'type integer' shown as set keys) in that case then the interger,width part can be omitted indeed.
Let me know. For concatenations, we will be unable to show a proper ruleset without the udata info anyway (concatentations do not work at the moment for non-specific types anyway though).
Indeed, what scenario are you considering that set udata might be missing?
We could still print it in such a case, even if we cannot parse it if you are willing to deal with. Just to provide some information to the user.
Florian Westphal
maintainerQuoted 10 lines · Pablo Neira Ayuso
Quoted 7 lines
If its not a problem to display a non-restoreable ruleset (e.g. unspecific 'type integer' shown as set keys) in that case then the interger,width part can be omitted indeed.
Let me know. For concatenations, we will be unable to show a proper ruleset without the udata info anyway (concatentations do not work at the moment for non-specific types anyway though).
Indeed, what scenario are you considering that set udata might be missing?
Any non-nft client/direct netlink user.
Quoted 3 lines
We could still print it in such a case, even if we cannot parse it if you are willing to deal with. Just to provide some information to the user.
If udata is missing, we only have the type available.
If its a type with unspecific length (string, integer) we can use the key length to get the bit size.
But for concatenation case, it might be ambigiuos.
So, I would remove the "type integer, length" format again so in such case we would print
type string
or
type integer.
Users won't see this non-restoreable ruleset listed as long as the udata is there.
Pablo Neira Ayuso
maintainerQuoted 5 lines · Florian Westphal
Quoted 4 lines · Pablo Neira Ayuso
Quoted 4 lines
If its not a problem to display a non-restoreable ruleset (e.g. unspecific 'type integer' shown as set keys) in that case then the interger,width part can be omitted indeed.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Let me know. For concatenations, we will be unable to show a proper ruleset without the udata info anyway (concatentations do not work at the moment for non-specific types anyway though).
Indeed, what scenario are you considering that set udata might be missing?
Any non-nft client/direct netlink user.
Ah I see, as direct uapi users.
Quoted 14 lines
Quoted 3 lines
We could still print it in such a case, even if we cannot parse it if you are willing to deal with. Just to provide some information to the user.
If udata is missing, we only have the type available.
If its a type with unspecific length (string, integer) we can use the key length to get the bit size.
But for concatenation case, it might be ambigiuos.
So, I would remove the "type integer, length" format again so in such case we would print
Quoted 6 lines
type string
or
type integer.Users won't see this non-restoreable ruleset listed as long as the udata is there.
That's good enough by now, I think, thanks.
Once we get more of those users, if they want some sort of interaction with nft, then we probably revisit this. Those clients might not even use nft for listing the ruleset at all.
Pablo Neira Ayuso
maintainerHi Florian,
One more thought regarding userdata, in case this is provided by the user, eg.
table x {
set y {
typeof ip saddr
}
}I think 'nft list ruleset' should also print the same input, instead of falling back to 'type ipv4_addr'.
Thanks.