Netfilter updates for net-next
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi,
The following patchset contains Netfilter updates for net-next to extend ctnetlink and the flowtable infrastructure:
1) Extend ctnetlink kernel side netlink dump filtering capabilities, from Romain Bellan.
2) Generalise the flowtable hook parser to take a hook list.
3) Pass a hook list to the flowtable hook registration/unregistration.
4) Add a helper function to release the flowtable hook list.
5) Update the flowtable event notifier to pass a flowtable hook list.
6) Allow users to add new devices to an existing flowtables.
7) Allow users to remove devices to an existing flowtables.
8) Allow for registering a flowtable with no initial devices.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thank you!
----------------------------------------------------------------
The following changes since commit 626a83238e6a63d88a5b5291febe797b244b5f18:
net: dsa: felix: accept VLAN config regardless of bridge VLAN awareness state (2020-05-27 11:39:58 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to 5b6743fb2c2a1fcb31c8b227558f537095dbece4:
netfilter: nf_tables: skip flowtable hooknum and priority on device updates (2020-05-27 22:20:35 +0200)
----------------------------------------------------------------
Pablo Neira Ayuso (8):
netfilter: nf_tables: generalise flowtable hook parsing
netfilter: nf_tables: pass hook list to nft_{un,}register_flowtable_net_hooks()
netfilter: nf_tables: add nft_flowtable_hooks_destroy()
netfilter: nf_tables: pass hook list to flowtable event notifier
netfilter: nf_tables: add devices to existing flowtable
netfilter: nf_tables: delete devices from flowtable
netfilter: nf_tables: allow to register flowtable with no devices
netfilter: nf_tables: skip flowtable hooknum and priority on device updates
Romain Bellan (1):
netfilter: ctnetlink: add kernel side filtering for dump
include/net/netfilter/nf_conntrack_l4proto.h | 6 +- include/net/netfilter/nf_tables.h | 7 + include/uapi/linux/netfilter/nfnetlink_conntrack.h | 9 + net/netfilter/nf_conntrack_core.c | 19 +- net/netfilter/nf_conntrack_netlink.c | 334 ++++++++++++++++++--- net/netfilter/nf_conntrack_proto_icmp.c | 40 ++- net/netfilter/nf_conntrack_proto_icmpv6.c | 42 ++- net/netfilter/nf_internals.h | 17 ++ net/netfilter/nf_tables_api.c | 333 ++++++++++++++++---- 9 files changed, 670 insertions(+), 137 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/9 netfilter: ctnetlink: add kernel side filtering for dump
From: Romain Bellan <[email protected]>
Conntrack dump does not support kernel side filtering (only get exists, but it returns only one entry. And user has to give a full valid tuple)
It means that userspace has to implement filtering after receiving many irrelevant entries, consuming resources (conntrack table is sometimes very huge, much more than a routing table for example).
This patch adds filtering in kernel side. To achieve this goal, we:
* Add a new CTA_FILTER netlink attributes, actually a flag list to parametize filtering
* Convert some *nlattr_to_tuple() functions, to allow a partial parsing of CTA_TUPLE_ORIG and CTA_TUPLE_REPLY (so nf_conntrack_tuple it not fully set)
Filtering is now possible on:
* IP SRC/DST values
* Ports for TCP and UDP flows
* IMCP(v6) codes types and IDs
Filtering is done as an "AND" operator. For example, when flags PROTO_SRC_PORT, PROTO_NUM and IP_SRC are sets, only entries matching all values are dumped.
Changes since v1:
Set NLM_F_DUMP_FILTERED in nlm flags if entries are filtered
Changes since v2:
Move several constants to nf_internals.h
Move a fix on netlink values check in a separate patch Add a check on not-supported flags
Return EOPNOTSUPP if CDA_FILTER is set in ctnetlink_flush_conntrack (not yet implemented)
Code style issues
Changes since v3:
Fix compilation warning reported by kbuild test robot
Changes since v4:
Fix a regression introduced in v3 (returned EINVAL for valid netlink messages without CTA_MARK)
Changes since v5:
Change definition of CTA_FILTER_F_ALL
Fix a regression when CTA_TUPLE_ZONE is not set
--- include/net/netfilter/nf_conntrack_l4proto.h | 6 +- .../linux/netfilter/nfnetlink_conntrack.h | 9 + net/netfilter/nf_conntrack_core.c | 19 +- net/netfilter/nf_conntrack_netlink.c | 334 ++++++++++++++++-- net/netfilter/nf_conntrack_proto_icmp.c | 40 ++- net/netfilter/nf_conntrack_proto_icmpv6.c | 42 ++- net/netfilter/nf_internals.h | 17 + 7 files changed, 394 insertions(+), 73 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +4 -2
@@ -42,7 +42,8 @@ struct nf_conntrack_l4proto {/* Calculate tuple nlattr size */ unsigned int (*nlattr_tuple_size)(void );int (*nlattr_to_tuple)(struct nlattr *tb[], -struct nf_conntrack_tuple *t); +struct nf_conntrack_tuple *t, +u_int32_t flags);const struct nla_policy *nla_policy;struct {
@@ -152,7 +153,8 @@ const struct nf_conntrack_l4proto *nf_ct_l4proto_find(u8 l4proto);int nf_ct_port_tuple_to_nlattr (struct sk_buff *skb,const struct nf_conntrack_tuple *tuple);int nf_ct_port_nlattr_to_tuple (struct nlattr *tb[], -struct nf_conntrack_tuple *t); +struct nf_conntrack_tuple *t, +u_int32_t flags);unsigned int nf_ct_port_nlattr_tuple_size (void );extern const struct nla_policy nf_ct_port_nla_policy[];
include/uapi/linux/netfilter/nfnetlink_conntrack.h +9 -0
@@ -55,6 +55,7 @@ enum ctattr_type {CTA_LABELS ,CTA_LABELS_MASK ,CTA_SYNPROXY , +CTA_FILTER , __CTA_MAX };#define CTA_MAX (__CTA_MAX - 1)
@@ -276,4 +277,12 @@ enum ctattr_expect_stats { };#define CTA_STATS_EXP_MAX (__CTA_STATS_EXP_MAX - 1) +enum ctattr_filter { +CTA_FILTER_UNSPEC , +CTA_FILTER_ORIG_FLAGS , +CTA_FILTER_REPLY_FLAGS , + __CTA_FILTER_MAX +}; +#define CTA_FILTER_MAX (__CTA_FILTER_MAX - 1) +#endif /* _IPCONNTRACK_NETLINK_H */
net/netfilter/nf_conntrack_core.c +14 -5
@@ -1974,13 +1974,22 @@ const struct nla_policy nf_ct_port_nla_policy[CTA_PROTO_MAX+1] = {EXPORT_SYMBOL_GPL (nf_ct_port_nla_policy);int nf_ct_port_nlattr_to_tuple (struct nlattr *tb[], -struct nf_conntrack_tuple *t) +struct nf_conntrack_tuple *t, +u_int32_t flags) { -if (!tb[CTA_PROTO_SRC_PORT ] || !tb[CTA_PROTO_DST_PORT ]) -return -EINVAL ; +if (flags &CTA_FILTER_FLAG (CTA_PROTO_SRC_PORT )) { +if (!tb[CTA_PROTO_SRC_PORT ]) +return -EINVAL ; + + t->src.u.tcp.port =nla_get_be16 (tb[CTA_PROTO_SRC_PORT ]); + } - t->src.u.tcp.port =nla_get_be16 (tb[CTA_PROTO_SRC_PORT ]); - t->dst.u.tcp.port =nla_get_be16 (tb[CTA_PROTO_DST_PORT ]); +if (flags &CTA_FILTER_FLAG (CTA_PROTO_DST_PORT )) { +if (!tb[CTA_PROTO_DST_PORT ]) +return -EINVAL ; + + t->dst.u.tcp.port =nla_get_be16 (tb[CTA_PROTO_DST_PORT ]); + }return 0 ; }
net/netfilter/nf_conntrack_netlink.c +295 -39
512 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_icmp.c +27 -13
@@ -20,6 +20,8 @@#include <net/netfilter/nf_conntrack_zones.h> #include <net/netfilter/nf_log.h> +#include "nf_internals.h" +static const unsigned int nf_ct_icmp_timeout =30 *HZ ; bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
@@ -271,20 +273,32 @@ static const struct nla_policy icmp_nla_policy[CTA_PROTO_MAX+1] = { };static int icmp_nlattr_to_tuple (struct nlattr *tb[], -struct nf_conntrack_tuple *tuple) +struct nf_conntrack_tuple *tuple, +u_int32_t flags) { -if (!tb[CTA_PROTO_ICMP_TYPE ] || - !tb[CTA_PROTO_ICMP_CODE ] || - !tb[CTA_PROTO_ICMP_ID ]) -return -EINVAL ; - - tuple->dst.u.icmp.type =nla_get_u8 (tb[CTA_PROTO_ICMP_TYPE ]); - tuple->dst.u.icmp.code =nla_get_u8 (tb[CTA_PROTO_ICMP_CODE ]); - tuple->src.u.icmp.id =nla_get_be16 (tb[CTA_PROTO_ICMP_ID ]); - -if (tuple->dst.u.icmp.type >=sizeof (invmap) || - !invmap[tuple->dst.u.icmp.type]) -return -EINVAL ; +if (flags &CTA_FILTER_FLAG (CTA_PROTO_ICMP_TYPE )) { +if (!tb[CTA_PROTO_ICMP_TYPE ]) +return -EINVAL ; + + tuple->dst.u.icmp.type =nla_get_u8 (tb[CTA_PROTO_ICMP_TYPE ]); +if (tuple->dst.u.icmp.type >=sizeof (invmap) || + !invmap[tuple->dst.u.icmp.type]) +return -EINVAL ; + } + +if (flags &CTA_FILTER_FLAG (CTA_PROTO_ICMP_CODE )) { +if (!tb[CTA_PROTO_ICMP_CODE ]) +return -EINVAL ; + + tuple->dst.u.icmp.code =nla_get_u8 (tb[CTA_PROTO_ICMP_CODE ]); + } + +if (flags &CTA_FILTER_FLAG (CTA_PROTO_ICMP_ID )) { +if (!tb[CTA_PROTO_ICMP_ID ]) +return -EINVAL ; + + tuple->src.u.icmp.id =nla_get_be16 (tb[CTA_PROTO_ICMP_ID ]); + }return 0 ; }
net/netfilter/nf_conntrack_proto_icmpv6.c +28 -14
55 lines not on this page · raw message
net/netfilter/nf_internals.h +17 -0
@@ -6,6 +6,23 @@#include <linux/skbuff.h> #include <linux/netdevice.h> +/* nf_conntrack_netlink.c: applied on tuple filters */ +#define CTA_FILTER_F_CTA_IP_SRC (1 << 0) +#define CTA_FILTER_F_CTA_IP_DST (1 << 1) +#define CTA_FILTER_F_CTA_TUPLE_ZONE (1 << 2) +#define CTA_FILTER_F_CTA_PROTO_NUM (1 << 3) +#define CTA_FILTER_F_CTA_PROTO_SRC_PORT (1 << 4) +#define CTA_FILTER_F_CTA_PROTO_DST_PORT (1 << 5) +#define CTA_FILTER_F_CTA_PROTO_ICMP_TYPE (1 << 6) +#define CTA_FILTER_F_CTA_PROTO_ICMP_CODE (1 << 7) +#define CTA_FILTER_F_CTA_PROTO_ICMP_ID (1 << 8) +#define CTA_FILTER_F_CTA_PROTO_ICMPV6_TYPE (1 << 9) +#define CTA_FILTER_F_CTA_PROTO_ICMPV6_CODE (1 << 10) +#define CTA_FILTER_F_CTA_PROTO_ICMPV6_ID (1 << 11) +#define CTA_FILTER_F_MAX (1 << 12) +#define CTA_FILTER_F_ALL (CTA_FILTER_F_MAX-1) +#define CTA_FILTER_FLAG (ctattr) CTA_FILTER_F_ ## ctattr +/* nf_queue.c */ void nf_queue_nf_hook_drop (struct net *net);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/9 netfilter: nf_tables: generalise flowtable hook parsing
In reply to Pablo Neira AyusoUpdate nft_flowtable_parse_hook() to take the flowtable hook list as parameter. This allows to reuse this function to update the hooks.
--- net/netfilter/nf_tables_api.c | 36 ++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
net/netfilter/nf_tables_api.c +25 -11
@@ -6178,21 +6178,30 @@ nft_flowtable_lookup_byhandle(const struct nft_table *table,return ERR_PTR (-ENOENT ); } +struct nft_flowtable_hook { +u32 num; +int priority; +struct list_head list; +}; +static const struct nla_policy nft_flowtable_hook_policy[NFTA_FLOWTABLE_HOOK_MAX +1 ] = { [NFTA_FLOWTABLE_HOOK_NUM ] = { .type =NLA_U32 }, [NFTA_FLOWTABLE_HOOK_PRIORITY ] = { .type =NLA_U32 }, [NFTA_FLOWTABLE_HOOK_DEVS ] = { .type =NLA_NESTED }, }; -static int nf_tables_flowtable_parse_hook (const struct nft_ctx *ctx, -const struct nlattr *attr, -struct nft_flowtable *flowtable) +static int nft_flowtable_parse_hook (const struct nft_ctx *ctx, +const struct nlattr *attr, +struct nft_flowtable_hook *flowtable_hook, +struct nf_flowtable *ft) {struct nlattr *tb[NFTA_FLOWTABLE_HOOK_MAX +1 ];struct nft_hook *hook;int hooknum, priority;int err; +INIT_LIST_HEAD (&flowtable_hook->list); + err =nla_parse_nested_deprecated (tb,NFTA_FLOWTABLE_HOOK_MAX , attr, nft_flowtable_hook_policy,NULL );if (err <0 )
@@ -6211,19 +6220,19 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx, err =nf_tables_parse_netdev_hooks (ctx->net, tb[NFTA_FLOWTABLE_HOOK_DEVS ], - &flowtable->hook_list); + &flowtable_hook->list);if (err <0 )return err; - flowtable->hooknum = hooknum; - flowtable->data.priority = priority; + flowtable_hook->priority = priority; + flowtable_hook->num = hooknum; -list_for_each_entry (hook, &flowtable->hook_list, list) { +list_for_each_entry (hook, &flowtable_hook->list, list) { hook->ops.pf =NFPROTO_NETDEV ; hook->ops.hooknum = hooknum; hook->ops.priority = priority; - hook->ops.priv = &flowtable->data; - hook->ops.hook = flowtable->data.type->hook; + hook->ops.priv = ft; + hook->ops.hook = ft->type->hook; }return err;
@@ -6336,6 +6345,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, struct netlink_ext_ack *extack) {const struct nfgenmsg *nfmsg =nlmsg_data (nlh); +struct nft_flowtable_hook flowtable_hook;const struct nf_flowtable_type *type;u8 genmask =nft_genmask_next (net);int family = nfmsg->nfgen_family;
@@ -6409,11 +6419,15 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,if (err <0 ) goto err3; - err =nf_tables_flowtable_parse_hook (&ctx, nla[NFTA_FLOWTABLE_HOOK ], - flowtable); + err =nft_flowtable_parse_hook (&ctx, nla[NFTA_FLOWTABLE_HOOK ], + &flowtable_hook, &flowtable->data);if (err <0 ) goto err4; +list_splice (&flowtable_hook.list, &flowtable->hook_list); + flowtable->data.priority = flowtable_hook.priority; + flowtable->hooknum = flowtable_hook.num; + err =nft_register_flowtable_net_hooks (ctx.net, table, flowtable);if (err <0 ) {list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) {
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/9 netfilter: nf_tables: pass hook list to nft_{un,}register_flowtable_net_hooks()
In reply to Pablo Neira AyusoThis patch prepares for incremental flowtable hook updates.
--- net/netfilter/nf_tables_api.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
net/netfilter/nf_tables_api.c +10 -7
@@ -6279,23 +6279,24 @@ static void nft_unregister_flowtable_hook(struct net *net, }static void nft_unregister_flowtable_net_hooks (struct net *net, -struct nft_flowtable *flowtable) +struct list_head *hook_list) {struct nft_hook *hook; -list_for_each_entry (hook, &flowtable->hook_list, list) +list_for_each_entry (hook, hook_list, list)nf_unregister_net_hook (net, &hook->ops); }static int nft_register_flowtable_net_hooks (struct net *net,struct nft_table *table, +struct list_head *hook_list,struct nft_flowtable *flowtable) {struct nft_hook *hook, *hook2, *next;struct nft_flowtable *ft;int err, i =0 ; -list_for_each_entry (hook, &flowtable->hook_list, list) { +list_for_each_entry (hook, hook_list, list) {list_for_each_entry (ft, &table->flowtables, list) {list_for_each_entry (hook2, &ft->hook_list, list) { if (hook->ops.dev == hook2->ops.dev &&
@@ -6326,7 +6327,7 @@ static int nft_register_flowtable_net_hooks(struct net *net,return 0 ; err_unregister_net_hooks: -list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) { +list_for_each_entry_safe (hook, next, hook_list, list) {if (i-- <=0 )break ;
@@ -6428,7 +6429,9 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, flowtable->data.priority = flowtable_hook.priority; flowtable->hooknum = flowtable_hook.num; - err =nft_register_flowtable_net_hooks (ctx.net, table, flowtable); + err =nft_register_flowtable_net_hooks (ctx.net, table, + &flowtable->hook_list, + flowtable);if (err <0 ) {list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) {list_del_rcu (&hook->list);
@@ -7493,7 +7496,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_trans_flowtable (trans), NFT_MSG_DELFLOWTABLE);nft_unregister_flowtable_net_hooks (net, -nft_trans_flowtable (trans)); + &nft_trans_flowtable (trans)->hook_list);break ; } }
@@ -7652,7 +7655,7 @@ static int __nf_tables_abort(struct net *net, bool autoload) trans->ctx.table->use--;list_del_rcu (&nft_trans_flowtable (trans)->list);nft_unregister_flowtable_net_hooks (net, -nft_trans_flowtable (trans)); + &nft_trans_flowtable (trans)->hook_list);break ;case NFT_MSG_DELFLOWTABLE : trans->ctx.table->use++;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 4/9 netfilter: nf_tables: add nft_flowtable_hooks_destroy()
In reply to Pablo Neira AyusoThis patch adds a helper function destroy the flowtable hooks.
--- net/netfilter/nf_tables_api.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +11 -4
@@ -6339,6 +6339,16 @@ static int nft_register_flowtable_net_hooks(struct net *net,return err; } +static void nft_flowtable_hooks_destroy (struct list_head *hook_list) +{ +struct nft_hook *hook, *next; + +list_for_each_entry_safe (hook, next, hook_list, list) { +list_del_rcu (&hook->list); +kfree_rcu (hook, rcu); + } +} + static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, struct sk_buff *skb, const struct nlmsghdr *nlh,
@@ -6433,10 +6443,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, &flowtable->hook_list, flowtable);if (err <0 ) { -list_for_each_entry_safe (hook, next, &flowtable->hook_list, list) { -list_del_rcu (&hook->list); -kfree_rcu (hook, rcu); - } +nft_flowtable_hooks_destroy (&flowtable->hook_list); goto err4; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 5/9 netfilter: nf_tables: pass hook list to flowtable event notifier
In reply to Pablo Neira AyusoUpdate the flowtable netlink notifier to take the list of hooks as input. This allows to reuse this function in incremental flowtable hook updates.
--- net/netfilter/nf_tables_api.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +11 -5
@@ -6523,7 +6523,8 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,static int nf_tables_fill_flowtable_info (struct sk_buff *skb,struct net *net,u32 portid,u32 seq,int event,u32 flags,int family, -struct nft_flowtable *flowtable) +struct nft_flowtable *flowtable, +struct list_head *hook_list) {struct nlattr *nest, *nest_devs;struct nfgenmsg *nfmsg;
@@ -6559,7 +6560,7 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,if (!nest_devs) goto nla_put_failure; -list_for_each_entry_rcu (hook, &flowtable->hook_list, list) { +list_for_each_entry_rcu (hook, hook_list, list) {if (nla_put_string (skb,NFTA_DEVICE_NAME , hook->ops.dev->name)) goto nla_put_failure; }
@@ -6612,7 +6613,9 @@ static int nf_tables_dump_flowtable(struct sk_buff *skb, cb->nlh->nlmsg_seq,NFT_MSG_NEWFLOWTABLE ,NLM_F_MULTI |NLM_F_APPEND , - table->family, flowtable) < 0) + table->family, + flowtable, + &flowtable->hook_list) < 0) goto done;nl_dump_check_consistent (cb,nlmsg_hdr (skb));
@@ -6709,7 +6712,7 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk, err =nf_tables_fill_flowtable_info (skb2, net,NETLINK_CB (skb).portid, nlh->nlmsg_seq,NFT_MSG_NEWFLOWTABLE ,0 , family, - flowtable); + flowtable, &flowtable->hook_list);if (err <0 ) goto err;
@@ -6721,6 +6724,7 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,static void nf_tables_flowtable_notify (struct nft_ctx *ctx,struct nft_flowtable *flowtable, +struct list_head *hook_list,int event) {struct sk_buff *skb;
@@ -6736,7 +6740,7 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx, err =nf_tables_fill_flowtable_info (skb, ctx->net, ctx->portid, ctx->seq, event,0 , - ctx->family, flowtable); + ctx->family, flowtable, hook_list);if (err <0 ) {kfree_skb (skb); goto err;
@@ -7494,6 +7498,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_clear (net,nft_trans_flowtable (trans));nf_tables_flowtable_notify (&trans->ctx,nft_trans_flowtable (trans), + &nft_trans_flowtable (trans)->hook_list,NFT_MSG_NEWFLOWTABLE );nft_trans_destroy (trans);break ;
@@ -7501,6 +7506,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)list_del_rcu (&nft_trans_flowtable (trans)->list);nf_tables_flowtable_notify (&trans->ctx,nft_trans_flowtable (trans), + &nft_trans_flowtable (trans)->hook_list,NFT_MSG_DELFLOWTABLE );nft_unregister_flowtable_net_hooks (net, &nft_trans_flowtable (trans)->hook_list);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 6/9 netfilter: nf_tables: add devices to existing flowtable
In reply to Pablo Neira AyusoThis patch allows users to add devices to an existing flowtable.
--- include/net/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_tables_api.c | 97 +++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 11 deletions(-)
include/net/netfilter/nf_tables.h +6 -0
@@ -1481,10 +1481,16 @@ struct nft_trans_obj {struct nft_trans_flowtable {struct nft_flowtable *flowtable; +bool update; +struct list_head hook_list; };#define nft_trans_flowtable (trans) \ (((struct nft_trans_flowtable *)trans->data)->flowtable) +#define nft_trans_flowtable_update (trans) \ + (((struct nft_trans_flowtable *)trans->data)->update) +#define nft_trans_flowtable_hooks (trans) \ + (((struct nft_trans_flowtable *)trans->data)->hook_list)int __init nft_chain_filter_init (void );void nft_chain_filter_fini (void );
net/netfilter/nf_tables_api.c +86 -11
127 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 7/9 netfilter: nf_tables: delete devices from flowtable
In reply to Pablo Neira AyusoThis patch allows users to delete devices from existing flowtables.
--- include/net/netfilter/nf_tables.h | 1 + net/netfilter/nf_tables_api.c | 113 +++++++++++++++++++++++++----- 2 files changed, 98 insertions(+), 16 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
@@ -1002,6 +1002,7 @@ struct nft_stats {struct nft_hook {struct list_head list; +bool inactive;struct nf_hook_ops ops;struct rcu_head rcu; };
net/netfilter/nf_tables_api.c +97 -16
179 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 8/9 netfilter: nf_tables: allow to register flowtable with no devices
In reply to Pablo Neira AyusoA flowtable might be composed of dynamic interfaces only. Such dynamic interfaces might show up at a later stage. This patch allows users to register a flowtable with no devices. Once the dynamic interface becomes available, the user adds the dynamic devices to the flowtable.
--- net/netfilter/nf_tables_api.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
net/netfilter/nf_tables_api.c +11 -9
@@ -1724,8 +1724,6 @@ static int nf_tables_parse_netdev_hooks(struct net *net, goto err_hook; } } -if (!n) -return -EINVAL ;return 0 ;
@@ -1762,6 +1760,9 @@ static int nft_chain_parse_netdev(struct net *net, hook_list);if (err <0 )return err; + +if (list_empty (hook_list)) +return -EINVAL ; }else {return -EINVAL ; }
@@ -6209,8 +6210,7 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,return err;if (!tb[NFTA_FLOWTABLE_HOOK_NUM ] || - !tb[NFTA_FLOWTABLE_HOOK_PRIORITY ] || - !tb[NFTA_FLOWTABLE_HOOK_DEVS ]) + !tb[NFTA_FLOWTABLE_HOOK_PRIORITY ])return -EINVAL ; hooknum =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_NUM ]));
@@ -6219,11 +6219,13 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx, priority =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_PRIORITY ])); - err =nf_tables_parse_netdev_hooks (ctx->net, - tb[NFTA_FLOWTABLE_HOOK_DEVS ], - &flowtable_hook->list); -if (err <0 ) -return err; +if (tb[NFTA_FLOWTABLE_HOOK_DEVS ]) { + err =nf_tables_parse_netdev_hooks (ctx->net, + tb[NFTA_FLOWTABLE_HOOK_DEVS ], + &flowtable_hook->list); +if (err <0 ) +return err; + } flowtable_hook->priority = priority; flowtable_hook->num = hooknum;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 9/9 netfilter: nf_tables: skip flowtable hooknum and priority on device updates
In reply to Pablo Neira AyusoOn device updates, the hooknum and priority attributes are not required. This patch makes optional these two netlink attributes.
Moreover, bail out with EOPNOTSUPP if userspace tries to update the hooknum and priority for existing flowtables.
While at this, turn EINVAL into EOPNOTSUPP in case the hooknum is not ingress. EINVAL is reserved for missing netlink attribute / malformed netlink messages.
--- net/netfilter/nf_tables_api.c | 53 +++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 18 deletions(-)
net/netfilter/nf_tables_api.c +35 -18
@@ -6195,7 +6195,7 @@ static const struct nla_policy nft_flowtable_hook_policy[NFTA_FLOWTABLE_HOOK_MAXstatic int nft_flowtable_parse_hook (const struct nft_ctx *ctx,const struct nlattr *attr,struct nft_flowtable_hook *flowtable_hook, -struct nf_flowtable *ft) +struct nft_flowtable *flowtable,bool add) {struct nlattr *tb[NFTA_FLOWTABLE_HOOK_MAX +1 ];struct nft_hook *hook;
@@ -6209,15 +6209,35 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,if (err <0 )return err; -if (!tb[NFTA_FLOWTABLE_HOOK_NUM ] || - !tb[NFTA_FLOWTABLE_HOOK_PRIORITY ]) -return -EINVAL ; +if (add) { +if (!tb[NFTA_FLOWTABLE_HOOK_NUM ] || + !tb[NFTA_FLOWTABLE_HOOK_PRIORITY ]) +return -EINVAL ; - hooknum =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_NUM ])); -if (hooknum !=NF_NETDEV_INGRESS ) -return -EINVAL ; + hooknum =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_NUM ])); +if (hooknum !=NF_NETDEV_INGRESS ) +return -EOPNOTSUPP ; + + priority =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_PRIORITY ])); + + flowtable_hook->priority = priority; + flowtable_hook->num = hooknum; + }else { +if (tb[NFTA_FLOWTABLE_HOOK_NUM ]) { + hooknum =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_NUM ])); +if (hooknum != flowtable->hooknum) +return -EOPNOTSUPP ; + } + +if (tb[NFTA_FLOWTABLE_HOOK_PRIORITY ]) { + priority =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_PRIORITY ])); +if (priority != flowtable->data.priority) +return -EOPNOTSUPP ; + } - priority =ntohl (nla_get_be32 (tb[NFTA_FLOWTABLE_HOOK_PRIORITY ])); + flowtable_hook->priority = flowtable->data.priority; + flowtable_hook->num = flowtable->hooknum; + }if (tb[NFTA_FLOWTABLE_HOOK_DEVS ]) { err = nf_tables_parse_netdev_hooks(ctx->net,
@@ -6227,15 +6247,12 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,return err; } - flowtable_hook->priority = priority; - flowtable_hook->num = hooknum; -list_for_each_entry (hook, &flowtable_hook->list, list) { hook->ops.pf =NFPROTO_NETDEV ; - hook->ops.hooknum = hooknum; - hook->ops.priority = priority; - hook->ops.priv = ft; - hook->ops.hook = ft->type->hook; + hook->ops.hooknum = flowtable_hook->num; + hook->ops.priority = flowtable_hook->priority; + hook->ops.priv = &flowtable->data; + hook->ops.hook = flowtable->data.type->hook; }return err;
@@ -6363,7 +6380,7 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,int err; err =nft_flowtable_parse_hook (ctx, nla[NFTA_FLOWTABLE_HOOK ], - &flowtable_hook, &flowtable->data); + &flowtable_hook, flowtable, false);if (err <0 )return err;
@@ -6492,7 +6509,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, goto err3; err =nft_flowtable_parse_hook (&ctx, nla[NFTA_FLOWTABLE_HOOK ], - &flowtable_hook, &flowtable->data); + &flowtable_hook, flowtable, true);if (err <0 ) goto err4;
@@ -6543,7 +6560,7 @@ static int nft_delflowtable_hook(struct nft_ctx *ctx,int err; err =nft_flowtable_parse_hook (ctx, nla[NFTA_FLOWTABLE_HOOK ], - &flowtable_hook, &flowtable->data); + &flowtable_hook, flowtable, false);if (err <0 )return err;
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 29 May 2020 19:50:17 +0200
Quoted 16 lines
The following patchset contains Netfilter updates for net-next to extend ctnetlink and the flowtable infrastructure:
1) Extend ctnetlink kernel side netlink dump filtering capabilities, from Romain Bellan.
2) Generalise the flowtable hook parser to take a hook list.
3) Pass a hook list to the flowtable hook registration/unregistration.
4) Add a helper function to release the flowtable hook list.
5) Update the flowtable event notifier to pass a flowtable hook list.
6) Allow users to add new devices to an existing flowtables.
Quoted 7 lines
7) Allow users to remove devices to an existing flowtables.
8) Allow for registering a flowtable with no initial devices.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thank you.