Netfilter/IPVS updates for net-next
Subsystems (5)
Pablo Neira Ayuso
maintainerPATCH 4/10 netfilter: nfnl_acct: remove data from struct net
In reply to Pablo Neira AyusoFrom: Wang Shanker <[email protected]>
This patch removes nfnl_acct_list from struct net to reduce the default memory footprint for the netns structure.
--- include/net/net_namespace.h | 3 --- net/netfilter/nfnetlink_acct.c | 38 ++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-)
include/net/net_namespace.h +0 -3
@@ -151,9 +151,6 @@ struct net {#endif struct sock *nfnl;struct sock *nfnl_stash; -#if IS_ENABLED (CONFIG_NETFILTER_NETLINK_ACCT ) -struct list_head nfnl_acct_list; -#endif #if IS_ENABLED (CONFIG_NF_CT_NETLINK_TIMEOUT )struct list_head nfct_timeout_list;#endif
net/netfilter/nfnetlink_acct.c +29 -9
@@ -16,6 +16,7 @@#include <linux/errno.h> #include <net/netlink.h> #include <net/sock.h> +#include <net/netns/generic.h> #include <linux/netfilter.h> #include <linux/netfilter/nfnetlink.h>
@@ -41,6 +42,17 @@ struct nfacct_filter {u32 mask; }; +struct nfnl_acct_net { +struct list_head nfnl_acct_list; +}; + +static unsigned int nfnl_acct_net_id__read_mostly ; + +static inline struct nfnl_acct_net *nfnl_acct_pernet (struct net *net) +{ +return net_generic (net, nfnl_acct_net_id); +} +#define NFACCT_F_QUOTA (NFACCT_F_QUOTA_PKTS | NFACCT_F_QUOTA_BYTES)#define NFACCT_OVERQUOTA_BIT 2/* NFACCT_F_OVERQUOTA */
@@ -49,6 +61,7 @@ static int nfnl_acct_new(struct net *net, struct sock *nfnl,const struct nlattr *const tb[], struct netlink_ext_ack *extack) { + struct nfnl_acct_net *nfnl_acct_net = nfnl_acct_pernet(net);struct nf_acct *nfacct, *matching =NULL ;char *acct_name;unsigned int size =0 ;
@@ -61,7 +74,7 @@ static int nfnl_acct_new(struct net *net, struct sock *nfnl,if (strlen (acct_name) ==0 )return -EINVAL ; -list_for_each_entry (nfacct, &net->nfnl_acct_list, head) { +list_for_each_entry (nfacct, &nfnl_acct_net->nfnl_acct_list, head) {if (strncmp (nfacct->name, acct_name,NFACCT_NAME_MAX ) !=0 )continue ;
@@ -123,7 +136,7 @@ static int nfnl_acct_new(struct net *net, struct sock *nfnl, be64_to_cpu(nla_get_be64(tb[NFACCT_PKTS]))); }refcount_set (&nfacct->refcnt,1 ); -list_add_tail_rcu (&nfacct->head, &net->nfnl_acct_list); +list_add_tail_rcu (&nfacct->head, &nfnl_acct_net->nfnl_acct_list);return 0 ; }
@@ -188,6 +201,7 @@ static int nfnl_acct_dump(struct sk_buff *skb, struct netlink_callback *cb) { struct net *net = sock_net(skb->sk); +struct nfnl_acct_net *nfnl_acct_net =nfnl_acct_pernet (net);struct nf_acct *cur, *last;const struct nfacct_filter *filter = cb->data;
@@ -199,7 +213,7 @@ nfnl_acct_dump(struct sk_buff *skb, struct netlink_callback *cb) cb->args[1 ] =0 ;rcu_read_lock (); -list_for_each_entry_rcu (cur, &net->nfnl_acct_list, head) { +list_for_each_entry_rcu (cur, &nfnl_acct_net->nfnl_acct_list, head) {if (last) {if (cur != last)continue ;
@@ -269,6 +283,7 @@ static int nfnl_acct_get(struct net *net, struct sock *nfnl,const struct nlattr *const tb[], struct netlink_ext_ack *extack) { + struct nfnl_acct_net *nfnl_acct_net = nfnl_acct_pernet(net);int ret = -ENOENT ;struct nf_acct *cur;char *acct_name;
@@ -288,7 +303,7 @@ static int nfnl_acct_get(struct net *net, struct sock *nfnl,return -EINVAL ; acct_name =nla_data (tb[NFACCT_NAME ]); -list_for_each_entry (cur, &net->nfnl_acct_list, head) { +list_for_each_entry (cur, &nfnl_acct_net->nfnl_acct_list, head) {struct sk_buff *skb2;if (strncmp (cur->name, acct_name,NFACCT_NAME_MAX )!=0 )
@@ -342,19 +357,20 @@ static int nfnl_acct_del(struct net *net, struct sock *nfnl,const struct nlattr *const tb[], struct netlink_ext_ack *extack) { + struct nfnl_acct_net *nfnl_acct_net = nfnl_acct_pernet(net);struct nf_acct *cur, *tmp;int ret = -ENOENT ;char *acct_name;if (!tb[NFACCT_NAME ]) { -list_for_each_entry_safe (cur, tmp, &net->nfnl_acct_list, head) +list_for_each_entry_safe (cur, tmp, &nfnl_acct_net->nfnl_acct_list, head)nfnl_acct_try_del (cur);return 0 ; } acct_name =nla_data (tb[NFACCT_NAME ]); -list_for_each_entry (cur, &net->nfnl_acct_list, head) { +list_for_each_entry (cur, &nfnl_acct_net->nfnl_acct_list, head) {if (strncmp (cur->name, acct_name,NFACCT_NAME_MAX ) !=0 )continue ;
@@ -402,10 +418,11 @@ MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_ACCT);struct nf_acct *nfnl_acct_find_get (struct net *net,const char *acct_name) { +struct nfnl_acct_net *nfnl_acct_net =nfnl_acct_pernet (net);struct nf_acct *cur, *acct =NULL ;rcu_read_lock (); -list_for_each_entry_rcu (cur, &net->nfnl_acct_list, head) { +list_for_each_entry_rcu (cur, &nfnl_acct_net->nfnl_acct_list, head) {if (strncmp (cur->name, acct_name,NFACCT_NAME_MAX )!=0 )continue ;
@@ -488,16 +505,17 @@ EXPORT_SYMBOL_GPL(nfnl_acct_overquota);static int __net_init nfnl_acct_net_init (struct net *net) { -INIT_LIST_HEAD (&net->nfnl_acct_list); +INIT_LIST_HEAD (&nfnl_acct_pernet (net)->nfnl_acct_list);return 0 ; } static void __net_exit nfnl_acct_net_exit(struct net *net) { +struct nfnl_acct_net *nfnl_acct_net =nfnl_acct_pernet (net);struct nf_acct *cur, *tmp; -list_for_each_entry_safe (cur, tmp, &net->nfnl_acct_list, head) { +list_for_each_entry_safe (cur, tmp, &nfnl_acct_net->nfnl_acct_list, head) {list_del_rcu (&cur->head);if (refcount_dec_and_test (&cur->refcnt))
@@ -508,6 +526,8 @@ static void __net_exit nfnl_acct_net_exit(struct net *net)static struct pernet_operations nfnl_acct_ops = { .init = nfnl_acct_net_init, .exit = nfnl_acct_net_exit, + .id = &nfnl_acct_net_id, + .size =sizeof (struct nfnl_acct_net ), };static int __init nfnl_acct_init (void )
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 9/10 netfilter: nftables: generalize set extension to support for several expressions
In reply to Pablo Neira AyusoThis patch replaces NFT_SET_EXPR by NFT_SET_EXT_EXPRESSIONS. This new extension allows to attach several expressions to one set element (not only one single expression as NFT_SET_EXPR provides). This patch prepares for support for several expressions per set element in the netlink userspace API.
--- include/net/netfilter/nf_tables.h | 36 ++++++++--- net/netfilter/nf_tables_api.c | 85 ++++++++++++++++++------ net/netfilter/nft_dynset.c | 103 ++++++++++++++++++++++++------ net/netfilter/nft_set_hash.c | 27 ++++++-- 4 files changed, 196 insertions(+), 55 deletions(-)
include/net/netfilter/nf_tables.h +28 -8
@@ -421,6 +421,20 @@ struct nft_set_type { };#define to_set_type (o) container_of(o, struct nft_set_type, ops) +struct nft_set_elem_expr { +u8 size; +unsigned char data[] + __attribute__((aligned (__alignof__(struct nft_expr )))); +}; + +#define nft_setelem_expr_at (__elem_expr, __offset) \ + ((struct nft_expr *)&__elem_expr->data[__offset]) + +#define nft_setelem_expr_foreach (__expr, __elem_expr, __size) \ + for (__expr = nft_setelem_expr_at(__elem_expr, 0), __size = 0; \ + __size < (__elem_expr)->size; \ + __size += (__expr)->ops->size, __expr = ((void *)(__expr)) + (__expr)->ops->size) +#define NFT_SET_EXPR_MAX 2/**
@@ -547,7 +561,7 @@ void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);* @NFT_SET_EXT_TIMEOUT: element timeout * @NFT_SET_EXT_EXPIRATION: element expiration time * @NFT_SET_EXT_USERDATA: user data associated with the element -* @NFT_SET_EXT_EXPR: expression assiociated with the element +* @NFT_SET_EXT_EXPRESSIONS: expressions assiciated with the element * @NFT_SET_EXT_OBJREF: stateful object reference associated with element * @NFT_SET_EXT_NUM: number of extension types */
@@ -559,7 +573,7 @@ enum nft_set_extensions {NFT_SET_EXT_TIMEOUT ,NFT_SET_EXT_EXPIRATION ,NFT_SET_EXT_USERDATA , -NFT_SET_EXT_EXPR , +NFT_SET_EXT_EXPRESSIONS ,NFT_SET_EXT_OBJREF , NFT_SET_EXT_NUM };
@@ -677,9 +691,9 @@ static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_extreturn nft_set_ext (ext,NFT_SET_EXT_USERDATA ); } -static inline struct nft_expr *nft_set_ext_expr (const struct nft_set_ext *ext) +static inline struct nft_set_elem_expr *nft_set_ext_expr (const struct nft_set_ext *ext) { -return nft_set_ext (ext,NFT_SET_EXT_EXPR ); +return nft_set_ext (ext,NFT_SET_EXT_EXPRESSIONS ); }static inline bool nft_set_elem_expired (const struct nft_set_ext *ext)
@@ -909,11 +923,17 @@ static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,struct nft_regs *regs, const struct nft_pktinfo *pkt) { + struct nft_set_elem_expr *elem_expr;struct nft_expr *expr; - -if (__nft_set_ext_exists (ext,NFT_SET_EXT_EXPR )) { - expr =nft_set_ext_expr (ext); - expr->ops->eval (expr, regs, pkt); +u32 size; + +if (__nft_set_ext_exists (ext,NFT_SET_EXT_EXPRESSIONS )) { + elem_expr =nft_set_ext_expr (ext); + nft_setelem_expr_foreach(expr, elem_expr, size) { + expr->ops->eval (expr, regs, pkt); +if (regs->verdict.code ==NFT_BREAK ) +return ; + } } }
net/netfilter/nf_tables_api.c +65 -20
154 lines not on this page · raw message
net/netfilter/nft_dynset.c +83 -20
166 lines not on this page · raw message
net/netfilter/nft_set_hash.c +20 -7
@@ -293,6 +293,22 @@ static void nft_rhash_walk(const struct nft_ctx *ctx, struct nft_set *set,rhashtable_walk_exit (&hti); } +static bool nft_rhash_expr_needs_gc_run (const struct nft_set *set, +struct nft_set_ext *ext) +{ +struct nft_set_elem_expr *elem_expr =nft_set_ext_expr (ext); +struct nft_expr *expr; +u32 size; + + nft_setelem_expr_foreach(expr, elem_expr, size) { +if (expr->ops->gc && + expr->ops->gc (read_pnet (&set->net), expr)) +return true; + } + +return false; +} +static void nft_rhash_gc (struct work_struct *work) {struct nft_set *set;
@@ -314,16 +330,13 @@ static void nft_rhash_gc(struct work_struct *work)continue ; } -if (nft_set_ext_exists (&he->ext,NFT_SET_EXT_EXPR )) { -struct nft_expr *expr =nft_set_ext_expr (&he->ext); +if (nft_set_ext_exists (&he->ext,NFT_SET_EXT_EXPRESSIONS ) && +nft_rhash_expr_needs_gc_run (set, &he->ext)) + goto needs_gc_run; -if (expr->ops->gc && - expr->ops->gc (read_pnet (&set->net), expr)) - goto gc; - }if (!nft_set_elem_expired (&he->ext))continue ; -gc: +needs_gc_run:if (nft_set_elem_mark_busy (&he->ext))continue ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 7/10 netfilter: nftables: generalize set expressions support
In reply to Pablo Neira AyusoCurrently, the set infrastucture allows for one single expressions per element. This patch extends the existing infrastructure to allow for up to two expressions. This is not updating the netlink API yet, this is coming as an initial preparation patch.
--- include/net/netfilter/nf_tables.h | 5 +- net/netfilter/nf_tables_api.c | 90 ++++++++++++++++++++++--------- net/netfilter/nft_dynset.c | 3 +- 3 files changed, 70 insertions(+), 28 deletions(-)
include/net/netfilter/nf_tables.h +4 -1
@@ -396,6 +396,8 @@ struct nft_set_type { };#define to_set_type (o) container_of(o, struct nft_set_type, ops) +#define NFT_SET_EXPR_MAX 2 +/** * struct nft_set - nf_tables set instance *
@@ -448,13 +450,14 @@ struct nft_set {u16 policy;u16 udlen;unsigned char *udata; -struct nft_expr *expr;/* runtime data below here */ const struct nft_set_ops *ops____cacheline_aligned ; u16 flags:14, genmask:2;u8 klen;u8 dlen; +u8 num_exprs; +struct nft_expr *exprs[NFT_SET_EXPR_MAX ]; unsigned char data[] __attribute__((aligned(__alignof__(u64)))); };
net/netfilter/nf_tables_api.c +64 -26
179 lines not on this page · raw message
net/netfilter/nft_dynset.c +2 -1
@@ -188,7 +188,8 @@ static int nft_dynset_init(const struct nft_ctx *ctx,if (IS_ERR (priv->expr))return PTR_ERR (priv->expr); -if (set->expr && set->expr->ops != priv->expr->ops) { +if (set->num_exprs ==1 && + set->exprs[0 ]->ops != priv->expr->ops) { err = -EOPNOTSUPP ; goto err_expr_free; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 6/10 netfilter: ctnetlink: add timeout and protoinfo to destroy events
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
DESTROY events do not include the remaining timeout.
Add the timeout if the entry was removed explicitly. This can happen when a conntrack gets deleted prematurely, e.g. due to a tcp reset, module removal, netdev notifier (nat/masquerade device went down), ctnetlink and so on.
Add the protocol state too for the destroy message to check for abnormal state on connection termination.
Joint work with Pablo.
--- include/net/netfilter/nf_conntrack_l4proto.h | 2 +- net/netfilter/nf_conntrack_netlink.c | 31 +++++++++++++------- net/netfilter/nf_conntrack_proto_dccp.c | 13 ++++++-- net/netfilter/nf_conntrack_proto_sctp.c | 13 +++++--- net/netfilter/nf_conntrack_proto_tcp.c | 13 +++++--- 5 files changed, 49 insertions(+), 23 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +1 -1
@@ -32,7 +32,7 @@ struct nf_conntrack_l4proto {/* convert protoinfo to nfnetink attributes */ int (*to_nlattr)(struct sk_buff *skb,struct nlattr *nla, -struct nf_conn *ct); +struct nf_conn *ct,bool destroy);/* convert nfnetlink attributes to protoinfo */ int (*from_nlattr)(struct nlattr *tb[],struct nf_conn *ct);
net/netfilter/nf_conntrack_netlink.c +20 -11
@@ -167,10 +167,14 @@ static int ctnetlink_dump_status(struct sk_buff *skb, const struct nf_conn *ct)return -1 ; } -static int ctnetlink_dump_timeout (struct sk_buff *skb,const struct nf_conn *ct) +static int ctnetlink_dump_timeout (struct sk_buff *skb,const struct nf_conn *ct, +bool skip_zero) {long timeout =nf_ct_expires (ct) /HZ ; +if (skip_zero && timeout ==0 ) +return 0 ; +if (nla_put_be32 (skb,CTA_TIMEOUT ,htonl (timeout))) goto nla_put_failure;return 0 ;
@@ -179,7 +183,8 @@ static int ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)return -1 ; } -static int ctnetlink_dump_protoinfo (struct sk_buff *skb,struct nf_conn *ct) +static int ctnetlink_dump_protoinfo (struct sk_buff *skb,struct nf_conn *ct, +bool destroy) {const struct nf_conntrack_l4proto *l4proto;struct nlattr *nest_proto;
@@ -193,7 +198,7 @@ static int ctnetlink_dump_protoinfo(struct sk_buff *skb, struct nf_conn *ct)if (!nest_proto) goto nla_put_failure; - ret = l4proto->to_nlattr (skb, nest_proto, ct); + ret = l4proto->to_nlattr (skb, nest_proto, ct, destroy);nla_nest_end (skb, nest_proto);
@@ -537,8 +542,8 @@ static int ctnetlink_dump_info(struct sk_buff *skb, struct nf_conn *ct)return -1 ;if (!test_bit (IPS_OFFLOAD_BIT , &ct->status) && - (ctnetlink_dump_timeout (skb, ct) <0 || -ctnetlink_dump_protoinfo (skb, ct) <0 )) + (ctnetlink_dump_timeout (skb, ct, false) <0 || +ctnetlink_dump_protoinfo (skb, ct, false) <0 ))return -1 ;return 0 ;
@@ -780,15 +785,19 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) goto nla_put_failure;if (events & (1 <<IPCT_DESTROY )) { +if (ctnetlink_dump_timeout (skb, ct, true) <0 ) + goto nla_put_failure; +if (ctnetlink_dump_acct (skb, ct, type) <0 || -ctnetlink_dump_timestamp (skb, ct) <0 ) +ctnetlink_dump_timestamp (skb, ct) <0 || +ctnetlink_dump_protoinfo (skb, ct, true) <0 ) goto nla_put_failure; }else { -if (ctnetlink_dump_timeout (skb, ct) <0 ) +if (ctnetlink_dump_timeout (skb, ct, false) <0 ) goto nla_put_failure; -if (events & (1 <<IPCT_PROTOINFO ) - &&ctnetlink_dump_protoinfo (skb, ct) <0 ) +if (events & (1 <<IPCT_PROTOINFO ) && +ctnetlink_dump_protoinfo (skb, ct, false) <0 ) goto nla_put_failure; if ((events & (1 << IPCT_HELPER) || nfct_help(ct))
@@ -2720,10 +2729,10 @@ static int __ctnetlink_glue_build(struct sk_buff *skb, struct nf_conn *ct)if (ctnetlink_dump_status (skb, ct) <0 ) goto nla_put_failure; -if (ctnetlink_dump_timeout (skb, ct) <0 ) +if (ctnetlink_dump_timeout (skb, ct, false) <0 ) goto nla_put_failure; -if (ctnetlink_dump_protoinfo (skb, ct) <0 ) +if (ctnetlink_dump_protoinfo (skb, ct, false) <0 ) goto nla_put_failure;if (ctnetlink_dump_helpinfo (skb, ct) <0 )
net/netfilter/nf_conntrack_proto_dccp.c +10 -3
@@ -589,7 +589,7 @@ static void dccp_print_conntrack(struct seq_file *s, struct nf_conn *ct)#if IS_ENABLED (CONFIG_NF_CT_NETLINK )static int dccp_to_nlattr (struct sk_buff *skb,struct nlattr *nla, -struct nf_conn *ct) +struct nf_conn *ct,bool destroy) {struct nlattr *nest_parms;
@@ -597,15 +597,22 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla, nest_parms =nla_nest_start (skb,CTA_PROTOINFO_DCCP );if (!nest_parms) goto nla_put_failure; -if (nla_put_u8 (skb,CTA_PROTOINFO_DCCP_STATE , ct->proto.dccp.state) || -nla_put_u8 (skb,CTA_PROTOINFO_DCCP_ROLE , +if (nla_put_u8 (skb,CTA_PROTOINFO_DCCP_STATE , ct->proto.dccp.state)) + goto nla_put_failure; + +if (destroy) + goto skip_state; + +if (nla_put_u8 (skb,CTA_PROTOINFO_DCCP_ROLE , ct->proto.dccp.role[IP_CT_DIR_ORIGINAL ]) ||nla_put_be64 (skb,CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ ,cpu_to_be64 (ct->proto.dccp.handshake_seq),CTA_PROTOINFO_DCCP_PAD )) goto nla_put_failure; +skip_state:nla_nest_end (skb, nest_parms);spin_unlock_bh (&ct->lock); +return 0 ; nla_put_failure:
net/netfilter/nf_conntrack_proto_sctp.c +9 -4
@@ -543,7 +543,7 @@ static bool sctp_can_early_drop(const struct nf_conn *ct)#include <linux/netfilter/nfnetlink_conntrack.h> static int sctp_to_nlattr (struct sk_buff *skb,struct nlattr *nla, -struct nf_conn *ct) +struct nf_conn *ct,bool destroy) {struct nlattr *nest_parms;
@@ -552,15 +552,20 @@ static int sctp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,if (!nest_parms) goto nla_put_failure; -if (nla_put_u8 (skb,CTA_PROTOINFO_SCTP_STATE , ct->proto.sctp.state) || -nla_put_be32 (skb,CTA_PROTOINFO_SCTP_VTAG_ORIGINAL , +if (nla_put_u8 (skb,CTA_PROTOINFO_SCTP_STATE , ct->proto.sctp.state)) + goto nla_put_failure; + +if (destroy) + goto skip_state; + +if (nla_put_be32 (skb,CTA_PROTOINFO_SCTP_VTAG_ORIGINAL , ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL ]) ||nla_put_be32 (skb,CTA_PROTOINFO_SCTP_VTAG_REPLY , ct->proto.sctp.vtag[IP_CT_DIR_REPLY ])) goto nla_put_failure; +skip_state:spin_unlock_bh (&ct->lock); -nla_nest_end (skb, nest_parms);return 0 ;
net/netfilter/nf_conntrack_proto_tcp.c +9 -4
@@ -1186,7 +1186,7 @@ static bool tcp_can_early_drop(const struct nf_conn *ct)#include <linux/netfilter/nfnetlink_conntrack.h> static int tcp_to_nlattr (struct sk_buff *skb,struct nlattr *nla, -struct nf_conn *ct) +struct nf_conn *ct,bool destroy) {struct nlattr *nest_parms;struct nf_ct_tcp_flags tmp = {};
@@ -1196,8 +1196,13 @@ static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,if (!nest_parms) goto nla_put_failure; -if (nla_put_u8 (skb,CTA_PROTOINFO_TCP_STATE , ct->proto.tcp.state) || -nla_put_u8 (skb,CTA_PROTOINFO_TCP_WSCALE_ORIGINAL , +if (nla_put_u8 (skb,CTA_PROTOINFO_TCP_STATE , ct->proto.tcp.state)) + goto nla_put_failure; + +if (destroy) + goto skip_state; + +if (nla_put_u8 (skb,CTA_PROTOINFO_TCP_WSCALE_ORIGINAL , ct->proto.tcp.seen[0 ].td_scale) ||nla_put_u8 (skb,CTA_PROTOINFO_TCP_WSCALE_REPLY , ct->proto.tcp.seen[1 ].td_scale))
@@ -1212,8 +1217,8 @@ static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,if (nla_put (skb,CTA_PROTOINFO_TCP_FLAGS_REPLY ,sizeof (struct nf_ct_tcp_flags ), &tmp)) goto nla_put_failure; +skip_state:spin_unlock_bh (&ct->lock); -nla_nest_end (skb, nest_parms);return 0 ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 8/10 netfilter: nftables: move nft_expr before nft_set
In reply to Pablo Neira AyusoMove the nft_expr structure definition before nft_set. Expressions are used by rules and sets, remove unnecessary forward declarations. This comes as preparation to support for multiple expressions per set element.
--- include/net/netfilter/nf_tables.h | 54 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 28 deletions(-)
include/net/netfilter/nf_tables.h +26 -28
@@ -305,8 +305,33 @@ struct nft_set_estimate {enum nft_set_class space; }; +#define NFT_EXPR_MAXATTR 16 +#define NFT_EXPR_SIZE (size) (sizeof(struct nft_expr) + \ + ALIGN(size, __alignof__(struct nft_expr))) + +/** +* struct nft_expr - nf_tables expression +* +* @ops: expression ops +* @data: expression private data +*/ +struct nft_expr { +const struct nft_expr_ops *ops; +unsigned char data[] + __attribute__((aligned (__alignof__(u64 )))); +}; + +static inline void *nft_expr_priv (const struct nft_expr *expr) +{ +return (void *)expr->data; +} + +int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src); +void nft_expr_destroy (const struct nft_ctx *ctx,struct nft_expr *expr); +int nft_expr_dump (struct sk_buff *skb,unsigned int attr, +const struct nft_expr *expr); +struct nft_set_ext ; -struct nft_expr ;/** * struct nft_set_ops - nf_tables set operations
@@ -797,7 +822,6 @@ struct nft_offload_ctx;* @validate: validate expression, called during loop detection * @data: extra data to attach to this expression operation */ -struct nft_expr ;struct nft_expr_ops { void (*eval)(const struct nft_expr *expr, struct nft_regs *regs,
@@ -833,32 +857,6 @@ struct nft_expr_ops {void *data; }; -#define NFT_EXPR_MAXATTR 16 -#define NFT_EXPR_SIZE (size) (sizeof(struct nft_expr) + \ - ALIGN(size, __alignof__(struct nft_expr))) - -/** -* struct nft_expr - nf_tables expression -* -* @ops: expression ops -* @data: expression private data -*/ -struct nft_expr { -const struct nft_expr_ops *ops; -unsigned char data[] - __attribute__((aligned (__alignof__(u64 )))); -}; - -static inline void *nft_expr_priv (const struct nft_expr *expr) -{ -return (void *)expr->data; -} - -int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src); -void nft_expr_destroy (const struct nft_ctx *ctx,struct nft_expr *expr); -int nft_expr_dump (struct sk_buff *skb,unsigned int attr, -const struct nft_expr *expr); -/** * struct nft_rule - nf_tables rule *
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 10/10 netfilter: nftables: netlink support for several set element expressions
In reply to Pablo Neira AyusoThis patch adds three new netlink attributes to encapsulate a list of expressions per set elements:
- NFTA_SET_EXPRESSIONS: this attribute provides the set definition in terms of expressions. New set elements get attached the list of expressions that is specified by this new netlink attribute.
- NFTA_SET_ELEM_EXPRESSIONS: this attribute allows users to restore (or initialize) the stateful information of set elements when adding an element to the set.
- NFTA_DYNSET_EXPRESSIONS: this attribute specifies the list of expressions that the set element gets when it is inserted from the packet path.
--- include/uapi/linux/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_tables_api.c | 93 +++++++++++++++++++++++- net/netfilter/nft_dynset.c | 56 +++++++++++++- 3 files changed, 149 insertions(+), 6 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +6 -0
@@ -361,6 +361,7 @@ enum nft_set_field_attributes {* @NFTA_SET_OBJ_TYPE: stateful object type (NLA_U32: NFT_OBJECT_*) * @NFTA_SET_HANDLE: set handle (NLA_U64) * @NFTA_SET_EXPR: set expression (NLA_NESTED: nft_expr_attributes) +* @NFTA_SET_EXPRESSIONS: list of expressions (NLA_NESTED: nft_list_attributes) */ enum nft_set_attributes {NFTA_SET_UNSPEC ,
@@ -381,6 +382,7 @@ enum nft_set_attributes {NFTA_SET_OBJ_TYPE ,NFTA_SET_HANDLE ,NFTA_SET_EXPR , +NFTA_SET_EXPRESSIONS , __NFTA_SET_MAX };#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
@@ -406,6 +408,7 @@ enum nft_set_elem_flags {* @NFTA_SET_ELEM_EXPR: expression (NLA_NESTED: nft_expr_attributes) * @NFTA_SET_ELEM_OBJREF: stateful object reference (NLA_STRING) * @NFTA_SET_ELEM_KEY_END: closing key value (NLA_NESTED: nft_data) +* @NFTA_SET_ELEM_EXPRESSIONS: list of expressions (NLA_NESTED: nft_list_attributes) */ enum nft_set_elem_attributes {NFTA_SET_ELEM_UNSPEC ,
@@ -419,6 +422,7 @@ enum nft_set_elem_attributes {NFTA_SET_ELEM_PAD ,NFTA_SET_ELEM_OBJREF ,NFTA_SET_ELEM_KEY_END , +NFTA_SET_ELEM_EXPRESSIONS , __NFTA_SET_ELEM_MAX };#define NFTA_SET_ELEM_MAX (__NFTA_SET_ELEM_MAX - 1)
@@ -715,6 +719,7 @@ enum nft_dynset_flags {* @NFTA_DYNSET_TIMEOUT: timeout value for the new element (NLA_U64) * @NFTA_DYNSET_EXPR: expression (NLA_NESTED: nft_expr_attributes) * @NFTA_DYNSET_FLAGS: flags (NLA_U32) +* @NFTA_DYNSET_EXPRESSIONS: list of expressions (NLA_NESTED: nft_list_attributes) */ enum nft_dynset_attributes {NFTA_DYNSET_UNSPEC ,
@@ -727,6 +732,7 @@ enum nft_dynset_attributes {NFTA_DYNSET_EXPR ,NFTA_DYNSET_PAD ,NFTA_DYNSET_FLAGS , +NFTA_DYNSET_EXPRESSIONS , __NFTA_DYNSET_MAX, };#define NFTA_DYNSET_MAX (__NFTA_DYNSET_MAX - 1)
net/netfilter/nf_tables_api.c +90 -3
155 lines not on this page · raw message
net/netfilter/nft_dynset.c +53 -3
89 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi Jakub, David,
The following patchset contains Netfilter updates for net-next:
1) Missing dependencies in NFT_BRIDGE_REJECT, from Randy Dunlap.
2) Use atomic_inc_return() instead of atomic_add_return() in IPVS, from Yejune Deng.
3) Simplify check for overquota in xt_nfacct, from Kaixu Xia.
4) Move nfnl_acct_list away from struct net, from Miao Wang.
5) Pass actual sk in reject actions, from Jan Engelhardt.
6) Add timeout and protoinfo to ctnetlink destroy events, from Florian Westphal.
7) Four patches to generalize set infrastructure to support for multiple expressions per set element.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit f9e425e99b0756c1479042afe761073779df2a30:
octeontx2-af: Add support for RSS hashing based on Transport protocol field (2020-11-21 16:05:22 -0800)
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 48b0ae046ee96eac999839f6d26c624b8c93ed66:
netfilter: nftables: netlink support for several set element expressions (2020-12-12 19:20:52 +0100)
----------------------------------------------------------------
Florian Westphal (1):
netfilter: ctnetlink: add timeout and protoinfo to destroy events
Jan Engelhardt (1):
netfilter: use actual socket sk for REJECT action
Kaixu Xia (1):
netfilter: Remove unnecessary conversion to bool
Pablo Neira Ayuso (4):
netfilter: nftables: generalize set expressions support
netfilter: nftables: move nft_expr before nft_set
netfilter: nftables: generalize set extension to support for several expressions
netfilter: nftables: netlink support for several set element expressions
Randy Dunlap (1):
netfilter: nft_reject_bridge: fix build errors due to code movement
Wang Shanker (1):
netfilter: nfnl_acct: remove data from struct net
Yejune Deng (1):
ipvs: replace atomic_add_return()
include/net/net_namespace.h | 3 - include/net/netfilter/ipv4/nf_reject.h | 4 +- include/net/netfilter/ipv6/nf_reject.h | 5 +- include/net/netfilter/nf_conntrack_l4proto.h | 2 +- include/net/netfilter/nf_tables.h | 95 ++++++---- include/uapi/linux/netfilter/nf_tables.h | 6 + net/bridge/netfilter/Kconfig | 2 + net/ipv4/netfilter/ipt_REJECT.c | 3 +- net/ipv4/netfilter/nf_reject_ipv4.c | 6 +- net/ipv4/netfilter/nft_reject_ipv4.c | 3 +- net/ipv6/netfilter/ip6t_REJECT.c | 2 +- net/ipv6/netfilter/nf_reject_ipv6.c | 5 +- net/ipv6/netfilter/nft_reject_ipv6.c | 3 +- net/netfilter/ipvs/ip_vs_core.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 4 +- net/netfilter/nf_conntrack_netlink.c | 31 ++-- net/netfilter/nf_conntrack_proto_dccp.c | 13 +- net/netfilter/nf_conntrack_proto_sctp.c | 13 +- net/netfilter/nf_conntrack_proto_tcp.c | 13 +- net/netfilter/nf_tables_api.c | 250 ++++++++++++++++++++++----- net/netfilter/nfnetlink_acct.c | 38 +++- net/netfilter/nft_dynset.c | 156 ++++++++++++++--- net/netfilter/nft_reject_inet.c | 6 +- net/netfilter/nft_set_hash.c | 27 ++- net/netfilter/xt_nfacct.c | 2 +- 25 files changed, 534 insertions(+), 160 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 5/10 netfilter: use actual socket sk for REJECT action
From: Jan Engelhardt <[email protected]>
True to the message of commit v5.10-rc1-105-g46d6c5ae953c, _do_ actually make use of state->sk when possible, such as in the REJECT modules.
--- include/net/netfilter/ipv4/nf_reject.h | 4 ++-- include/net/netfilter/ipv6/nf_reject.h | 5 ++--- net/ipv4/netfilter/ipt_REJECT.c | 3 ++- net/ipv4/netfilter/nf_reject_ipv4.c | 6 +++--- net/ipv4/netfilter/nft_reject_ipv4.c | 3 ++- net/ipv6/netfilter/ip6t_REJECT.c | 2 +- net/ipv6/netfilter/nf_reject_ipv6.c | 5 +++-- net/ipv6/netfilter/nft_reject_ipv6.c | 3 ++- net/netfilter/nft_reject_inet.c | 6 ++++-- 9 files changed, 21 insertions(+), 16 deletions(-)
include/net/netfilter/ipv4/nf_reject.h +2 -2
@@ -8,8 +8,8 @@#include <net/netfilter/nf_reject.h> void nf_send_unreach (struct sk_buff *skb_in,int code,int hook); -void nf_send_reset (struct net *net,struct sk_buff *oldskb,int hook); - +void nf_send_reset (struct net *net,struct sock *,struct sk_buff *oldskb, +int hook);const struct tcphdr *nf_reject_ip_tcphdr_get (struct sk_buff *oldskb,struct tcphdr *_oth,int hook); struct iphdr *nf_reject_iphdr_put(struct sk_buff *nskb,
include/net/netfilter/ipv6/nf_reject.h +2 -3
@@ -7,9 +7,8 @@void nf_send_unreach6 (struct net *net,struct sk_buff *skb_in,unsigned char code,unsigned int hooknum); - -void nf_send_reset6 (struct net *net,struct sk_buff *oldskb,int hook); - +void nf_send_reset6 (struct net *net,struct sock *sk,struct sk_buff *oldskb, +int hook);const struct tcphdr *nf_reject_ip6_tcphdr_get (struct sk_buff *oldskb,struct tcphdr *otcph,unsigned int *otcplen,int hook);
net/ipv4/netfilter/ipt_REJECT.c +2 -1
@@ -56,7 +56,8 @@ reject_tg(struct sk_buff *skb, const struct xt_action_param *par)nf_send_unreach (skb,ICMP_PKT_FILTERED , hook);break ;case IPT_TCP_RESET : -nf_send_reset (xt_net (par), skb, hook); +nf_send_reset (xt_net (par), par->state->sk, skb, hook); +break ;case IPT_ICMP_ECHOREPLY :/* Doesn't happen. */ break ;
net/ipv4/netfilter/nf_reject_ipv4.c +3 -3
@@ -234,7 +234,8 @@ static int nf_reject_fill_skb_dst(struct sk_buff *skb_in) }/* Send RST reply */ -void nf_send_reset (struct net *net,struct sk_buff *oldskb,int hook) +void nf_send_reset (struct net *net,struct sock *sk,struct sk_buff *oldskb, +int hook) {struct net_device *br_indev__maybe_unused ;struct sk_buff *nskb;
@@ -267,8 +268,7 @@ void nf_send_reset(struct net *net, struct sk_buff *oldskb, int hook) niph =nf_reject_iphdr_put (nskb, oldskb,IPPROTO_TCP ,ip4_dst_hoplimit (skb_dst (nskb)));nf_reject_ip_tcphdr_put (nskb, oldskb, oth); - -if (ip_route_me_harder (net, nskb->sk, nskb,RTN_UNSPEC )) +if (ip_route_me_harder (net, sk, nskb,RTN_UNSPEC )) goto free_nskb; niph =ip_hdr (nskb);
net/ipv4/netfilter/nft_reject_ipv4.c +2 -1
@@ -27,7 +27,8 @@ static void nft_reject_ipv4_eval(const struct nft_expr *expr,nf_send_unreach (pkt->skb, priv->icmp_code,nft_hook (pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset (nft_net (pkt), pkt->skb,nft_hook (pkt)); +nf_send_reset (nft_net (pkt), pkt->xt.state->sk, pkt->skb, +nft_hook (pkt));break ;default :break ;
net/ipv6/netfilter/ip6t_REJECT.c +1 -1
@@ -61,7 +61,7 @@ reject_tg6(struct sk_buff *skb, const struct xt_action_param *par)/* Do nothing */ break ;case IP6T_TCP_RESET : -nf_send_reset6 (net, skb,xt_hooknum (par)); +nf_send_reset6 (net, par->state->sk, skb,xt_hooknum (par));break ;case IP6T_ICMP6_POLICY_FAIL :nf_send_unreach6 (net, skb,ICMPV6_POLICY_FAIL ,xt_hooknum (par));
net/ipv6/netfilter/nf_reject_ipv6.c +3 -2
@@ -275,7 +275,8 @@ static int nf_reject6_fill_skb_dst(struct sk_buff *skb_in)return 0 ; } -void nf_send_reset6 (struct net *net,struct sk_buff *oldskb,int hook) +void nf_send_reset6 (struct net *net,struct sock *sk,struct sk_buff *oldskb, +int hook) {struct net_device *br_indev__maybe_unused ;struct sk_buff *nskb;
@@ -367,7 +368,7 @@ void nf_send_reset6(struct net *net, struct sk_buff *oldskb, int hook) dev_queue_xmit(nskb); } else#endif -ip6_local_out (net, nskb->sk, nskb); +ip6_local_out (net, sk, nskb); }EXPORT_SYMBOL_GPL (nf_send_reset6);
net/ipv6/netfilter/nft_reject_ipv6.c +2 -1
@@ -28,7 +28,8 @@ static void nft_reject_ipv6_eval(const struct nft_expr *expr, nft_hook(pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset6 (nft_net (pkt), pkt->skb,nft_hook (pkt)); +nf_send_reset6 (nft_net (pkt), pkt->xt.state->sk, pkt->skb, +nft_hook (pkt));break ;default :break ;
net/netfilter/nft_reject_inet.c +4 -2
@@ -28,7 +28,8 @@ static void nft_reject_inet_eval(const struct nft_expr *expr, nft_hook(pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset (nft_net (pkt), pkt->skb,nft_hook (pkt)); +nf_send_reset (nft_net (pkt), pkt->xt.state->sk, + pkt->skb,nft_hook (pkt));break ;case NFT_REJECT_ICMPX_UNREACH : nf_send_unreach(pkt->skb,
@@ -44,7 +45,8 @@ static void nft_reject_inet_eval(const struct nft_expr *expr, priv->icmp_code, nft_hook(pkt));break ;case NFT_REJECT_TCP_RST : -nf_send_reset6 (nft_net (pkt), pkt->skb,nft_hook (pkt)); +nf_send_reset6 (nft_net (pkt), pkt->xt.state->sk, + pkt->skb,nft_hook (pkt));break ;case NFT_REJECT_ICMPX_UNREACH : nf_send_unreach6(nft_net(pkt), pkt->skb,
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 1/10 netfilter: nft_reject_bridge: fix build errors due to code movement
In reply to Pablo Neira AyusoFrom: Randy Dunlap <[email protected]>
Fix build errors in net/bridge/netfilter/nft_reject_bridge.ko by selecting NF_REJECT_IPV4, which provides the missing symbols.
ERROR: modpost: "nf_reject_skb_v4_tcp_reset" [net/bridge/netfilter/nft_reject_bridge.ko] undefined!
ERROR: modpost: "nf_reject_skb_v4_unreach" [net/bridge/netfilter/nft_reject_bridge.ko] undefined!
--- net/bridge/netfilter/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
net/bridge/netfilter/Kconfig +2 -0
@@ -18,6 +18,8 @@ config NFT_BRIDGE_META config NFT_BRIDGE_REJECT tristate "Netfilter nf_tables bridge reject support" depends on NFT_REJECT + depends on NF_REJECT_IPV4 + depends on NF_REJECT_IPV6 help Add support to reject packets.
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/10 netfilter: Remove unnecessary conversion to bool
In reply to Pablo Neira AyusoFrom: Kaixu Xia <[email protected]>
Here we could use the '!=' expression to fix the following coccicheck warning:
./net/netfilter/xt_nfacct.c:30:41-46: WARNING: conversion to bool not needed here
--- net/netfilter/xt_nfacct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_nfacct.c +1 -1
@@ -27,7 +27,7 @@ static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par) overquota =nfnl_acct_overquota (xt_net (par), info->nfacct); -return overquota ==NFACCT_UNDERQUOTA ? false : true; +return overquota !=NFACCT_UNDERQUOTA ; } static int
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/10 ipvs: replace atomic_add_return()
In reply to Pablo Neira AyusoFrom: Yejune Deng <[email protected]>
atomic_inc_return() looks better
--- net/netfilter/ipvs/ip_vs_core.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +1 -1
@@ -2137,7 +2137,7 @@ ip_vs_in(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, intif (cp->flags &IP_VS_CONN_F_ONE_PACKET ) pkts =sysctl_sync_threshold (ipvs);else - pkts =atomic_add_return (1 , &cp->in_pkts); + pkts =atomic_inc_return (&cp->in_pkts);if (ipvs->sync_state &IP_VS_STATE_MASTER )ip_vs_sync_conn (ipvs, cp, pkts);
net/netfilter/ipvs/ip_vs_sync.c +2 -2
@@ -615,7 +615,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, cp = cp->control;if (cp) {if (cp->flags &IP_VS_CONN_F_TEMPLATE ) - pkts =atomic_add_return (1 , &cp->in_pkts); + pkts =atomic_inc_return (&cp->in_pkts);else pkts =sysctl_sync_threshold (ipvs);ip_vs_sync_conn (ipvs, cp, pkts);
@@ -776,7 +776,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)if (!cp)return ;if (cp->flags &IP_VS_CONN_F_TEMPLATE ) - pkts =atomic_add_return (1 , &cp->in_pkts); + pkts =atomic_inc_return (&cp->in_pkts);else pkts =sysctl_sync_threshold (ipvs); goto sloop;
Signature · 1 line
2.20.1
Jakub Kicinski
maintainerQuoted 9 lines · On Sun, 13 Dec 2020 00:05:03 +0100 Pablo Neira Ayuso wrote:
1) Missing dependencies in
NFT_BRIDGE_REJECT, from Randy Dunlap.2) Use
atomic_inc_return()instead ofatomic_add_return()in IPVS, from Yejune Deng.3) Simplify check for overquota in
xt_nfacct, from Kaixu Xia.4) Move
nfnl_acct_listaway from struct net, from Miao Wang.
Quoted 7 lines
5) Pass actual sk in reject actions, from Jan Engelhardt.
6) Add timeout and protoinfo to ctnetlink destroy events, from Florian Westphal.
7) Four patches to generalize set infrastructure to support for multiple expressions per set element.
Pulled, thanks!