netfilter: nfnetlink: pass down netns pointer to call() and call_rcu()
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 4/5 netfilter: nfnetlink: pass down netns pointer to call() and call_rcu()
Adapt callsites to avoid recurrent lookup of the netns pointer.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
@Jozsef: This modifies ipset bits.
include/linux/netfilter/nfnetlink.h | 8 +-- net/netfilter/ipset/ip_set_core.c | 108 +++++++++++++++-------------------- net/netfilter/nf_conntrack_netlink.c | 96 ++++++++++++++----------------- net/netfilter/nf_tables_api.c | 30 ++++------ net/netfilter/nfnetlink.c | 6 +- net/netfilter/nfnetlink_acct.c | 21 +++---- net/netfilter/nfnetlink_cthelper.c | 18 +++--- net/netfilter/nfnetlink_cttimeout.c | 38 ++++++------ net/netfilter/nfnetlink_log.c | 15 ++--- net/netfilter/nfnetlink_queue.c | 36 +++++------- net/netfilter/nft_compat.c | 6 +- net/netfilter/xt_osf.c | 7 ++- 12 files changed, 172 insertions(+), 217 deletions(-)
include/linux/netfilter/nfnetlink.h +4 -4
@@ -8,12 +8,12 @@#include <uapi/linux/netfilter/nfnetlink.h> struct nfnl_callback { -int (*call)(struct sock *nl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const cda[]); -int (*call_rcu)(struct sock *nl,struct sk_buff *skb, +int (*call)(struct net *net,struct sock *nl,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const cda[]); +int (*call_rcu)(struct net *net,struct sock *nl,struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const cda[]);int (*call_batch)(struct net *net,struct sock *nl,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const cda[]);
net/netfilter/ipset/ip_set_core.c +47 -61
193 lines not on this page · raw message
net/netfilter/nf_conntrack_netlink.c +43 -53
184 lines not on this page · raw message
net/netfilter/nf_tables_api.c +12 -18
@@ -543,15 +543,14 @@ done:return skb->len; } -static int nf_tables_gettable (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int nf_tables_gettable (struct net *net,struct sock *nlsk, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[]) {const struct nfgenmsg *nfmsg =nlmsg_data (nlh);const struct nft_af_info *afi;const struct nft_table *table;struct sk_buff *skb2; -struct net *net =sock_net (skb->sk);int family = nfmsg->nfgen_family;int err;
@@ -1097,8 +1096,8 @@ done:return skb->len; } -static int nf_tables_getchain (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int nf_tables_getchain (struct net *net,struct sock *nlsk, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[]) {const struct nfgenmsg *nfmsg =nlmsg_data (nlh);
@@ -1106,7 +1105,6 @@ static int nf_tables_getchain(struct sock *nlsk, struct sk_buff *skb,const struct nft_table *table;const struct nft_chain *chain;struct sk_buff *skb2; -struct net *net =sock_net (skb->sk);int family = nfmsg->nfgen_family;int err;
@@ -1923,8 +1921,8 @@ done:return skb->len; } -static int nf_tables_getrule (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int nf_tables_getrule (struct net *net,struct sock *nlsk, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[]) {const struct nfgenmsg *nfmsg =nlmsg_data (nlh);
@@ -1933,7 +1931,6 @@ static int nf_tables_getrule(struct sock *nlsk, struct sk_buff *skb,const struct nft_chain *chain;const struct nft_rule *rule;struct sk_buff *skb2; -struct net *net =sock_net (skb->sk);int family = nfmsg->nfgen_family;int err;
@@ -2604,11 +2601,10 @@ static int nf_tables_dump_sets_done(struct netlink_callback *cb)return 0 ; } -static int nf_tables_getset (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int nf_tables_getset (struct net *net,struct sock *nlsk, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[]) { -struct net *net =sock_net (skb->sk);const struct nft_set *set;struct nft_ctx ctx;struct sk_buff *skb2;
@@ -3190,11 +3186,10 @@ nla_put_failure:return -ENOSPC ; } -static int nf_tables_getsetelem (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int nf_tables_getsetelem (struct net *net,struct sock *nlsk, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[]) { -struct net *net =sock_net (skb->sk);const struct nft_set *set;struct nft_ctx ctx;int err;
@@ -3723,11 +3718,10 @@ err:return err; } -static int nf_tables_getgen (struct sock *nlsk,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int nf_tables_getgen (struct net *net,struct sock *nlsk, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const nla[]) { -struct net *net =sock_net (skb->sk);struct sk_buff *skb2;int err;
net/netfilter/nfnetlink.c +3 -3
@@ -201,7 +201,7 @@ replay: }if (nc->call_rcu) { - err = nc->call_rcu (net->nfnl, skb, nlh, + err = nc->call_rcu (net, net->nfnl, skb, nlh, (const struct nlattr **)cda);rcu_read_unlock (); }else {
@@ -212,8 +212,8 @@ replay: nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; else if (nc->call) - err = nc->call (net->nfnl, skb, nlh, - (const struct nlattr **)cda); + err = nc->call (net, net->nfnl, skb, nlh, + (const struct nlattr **)cda); else err = -EINVAL ;nfnl_unlock (subsys_id);
net/netfilter/nfnetlink_acct.c +9 -12
@@ -46,12 +46,11 @@ struct nfacct_filter {#define NFACCT_F_QUOTA (NFACCT_F_QUOTA_PKTS | NFACCT_F_QUOTA_BYTES)#define NFACCT_OVERQUOTA_BIT 2/* NFACCT_F_OVERQUOTA */ -static int -nfnl_acct_new (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_acct_new (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) {struct nf_acct *nfacct, *matching =NULL ; -struct net *net =sock_net (nfnl);char *acct_name;unsigned int size =0 ;u32 flags =0 ;
@@ -253,11 +252,10 @@ nfacct_filter_alloc(const struct nlattr * const attr)return filter; } -static int -nfnl_acct_get (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_acct_get (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) { -struct net *net =sock_net (nfnl);int ret = -ENOENT ;struct nf_acct *cur;char *acct_name;
@@ -333,11 +331,10 @@ static int nfnl_acct_try_del(struct nf_acct *cur)return ret; } -static int -nfnl_acct_del (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_acct_del (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) { -struct net *net =sock_net (nfnl);char *acct_name;struct nf_acct *cur;int ret = -ENOENT ;
net/netfilter/nfnetlink_cthelper.c +9 -9
@@ -286,9 +286,9 @@ nfnl_cthelper_update(const struct nlattr * const tb[],return 0 ; } -static int -nfnl_cthelper_new (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_cthelper_new (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) {const char *helper_name;struct nf_conntrack_helper *cur, *helper =NULL ;
@@ -498,9 +498,9 @@ out:return skb->len; } -static int -nfnl_cthelper_get (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_cthelper_get (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) {int ret = -ENOENT , i;struct nf_conntrack_helper *cur;
@@ -570,9 +570,9 @@ nfnl_cthelper_get(struct sock *nfnl, struct sk_buff *skb,return ret; } -static int -nfnl_cthelper_del (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_cthelper_del (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) {char *helper_name =NULL ;struct nf_conntrack_helper *cur;
net/netfilter/nfnetlink_cttimeout.c +18 -20
@@ -67,16 +67,15 @@ ctnl_timeout_parse_policy(void *timeouts, struct nf_conntrack_l4proto *l4proto,return ret; } -static int -cttimeout_new_timeout (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const cda[]) +static int cttimeout_new_timeout (struct net *net,struct sock *ctnl, +struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const cda[]) {__u16 l3num;__u8 l4num;struct nf_conntrack_l4proto *l4proto;struct ctnl_timeout *timeout, *matching =NULL ; -struct net *net =sock_net (skb->sk);char *name;int ret;
@@ -240,10 +239,10 @@ ctnl_timeout_dump(struct sk_buff *skb, struct netlink_callback *cb)return skb->len; } -static int -cttimeout_get_timeout (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const cda[]) +static int cttimeout_get_timeout (struct net *net,struct sock *ctnl, +struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const cda[]) {int ret = -ENOENT ;char *name;
@@ -339,10 +338,10 @@ static int ctnl_timeout_try_del(struct ctnl_timeout *timeout)return ret; } -static int -cttimeout_del_timeout (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const cda[]) +static int cttimeout_del_timeout (struct net *net,struct sock *ctnl, +struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const cda[]) {char *name;struct ctnl_timeout *cur;
@@ -369,15 +368,14 @@ cttimeout_del_timeout(struct sock *ctnl, struct sk_buff *skb,return ret; } -static int -cttimeout_default_set (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const cda[]) +static int cttimeout_default_set (struct net *net,struct sock *ctnl, +struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const cda[]) {__u16 l3num;__u8 l4num;struct nf_conntrack_l4proto *l4proto; -struct net *net =sock_net (skb->sk);unsigned int *timeouts;int ret;
@@ -459,14 +457,14 @@ nla_put_failure:return -1 ; } -static int cttimeout_default_get (struct sock *ctnl,struct sk_buff *skb, +static int cttimeout_default_get (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const cda[]) {__u16 l3num;__u8 l4num;struct nf_conntrack_l4proto *l4proto; -struct net *net =sock_net (skb->sk);struct sk_buff *skb2;int ret, err;
net/netfilter/nfnetlink_log.c +6 -9
@@ -789,10 +789,9 @@ static struct notifier_block nfulnl_rtnl_notifier = { .notifier_call = nfulnl_rcv_nl_event, }; -static int -nfulnl_recv_unsupp (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nfqa[]) +static int nfulnl_recv_unsupp (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const nfqa[]) {return -ENOTSUPP ; }
@@ -813,16 +812,14 @@ static const struct nla_policy nfula_cfg_policy[NFULA_CFG_MAX+1] = { [NFULA_CFG_FLAGS] = { .type = NLA_U16 }, }; -static int -nfulnl_recv_config (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nfula[]) +static int nfulnl_recv_config (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const nfula[]) {struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int16_t group_num =ntohs (nfmsg->res_id);struct nfulnl_instance *inst;struct nfulnl_msg_config_cmd *cmd =NULL ; -struct net *net =sock_net (ctnl);struct nfnl_log_net *log =nfnl_log_pernet (net);int ret =0 ;u16 flags =0 ;
net/netfilter/nfnetlink_queue.c +14 -22
@@ -957,10 +957,10 @@ static int nfq_id_after(unsigned int id, unsigned int max)return (int )(id - max) >0 ; } -static int -nfqnl_recv_verdict_batch (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nfqa[]) +static int nfqnl_recv_verdict_batch (struct net *net,struct sock *ctnl, +struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const nfqa[]) {struct nfgenmsg *nfmsg =nlmsg_data (nlh);struct nf_queue_entry *entry, *tmp;
@@ -969,8 +969,6 @@ nfqnl_recv_verdict_batch(struct sock *ctnl, struct sk_buff *skb,struct nfqnl_instance *queue;LIST_HEAD (batch_list);u16 queue_num =ntohs (nfmsg->res_id); - -struct net *net =sock_net (ctnl);struct nfnl_queue_net *q =nfnl_queue_pernet (net); queue = verdict_instance_lookup(q, queue_num,
@@ -1029,14 +1027,13 @@ static struct nf_conn *nfqnl_ct_parse(struct nfnl_ct_hook *nfnl_ct,return ct; } -static int -nfqnl_recv_verdict (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nfqa[]) +static int nfqnl_recv_verdict (struct net *net,struct sock *ctnl, +struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const nfqa[]) {struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int16_t queue_num =ntohs (nfmsg->res_id); -struct nfqnl_msg_verdict_hdr *vhdr;struct nfqnl_instance *queue;unsigned int verdict;
@@ -1044,8 +1041,6 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,enum ip_conntrack_info uninitialized_var (ctinfo );struct nfnl_ct_hook *nfnl_ct;struct nf_conn *ct =NULL ; - -struct net *net =sock_net (ctnl);struct nfnl_queue_net *q =nfnl_queue_pernet (net); queue =instance_lookup (q, queue_num);
@@ -1092,10 +1087,9 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,return 0 ; } -static int -nfqnl_recv_unsupp (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nfqa[]) +static int nfqnl_recv_unsupp (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const nfqa[]) {return -ENOTSUPP ; }
@@ -1110,16 +1104,14 @@ static const struct nf_queue_handler nfqh = { .nf_hook_drop = &nfqnl_nf_hook_drop, }; -static int -nfqnl_recv_config (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, -const struct nlattr *const nfqa[]) +static int nfqnl_recv_config (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const nfqa[]) {struct nfgenmsg *nfmsg =nlmsg_data (nlh);u_int16_t queue_num =ntohs (nfmsg->res_id);struct nfqnl_instance *queue;struct nfqnl_msg_config_cmd *cmd =NULL ; -struct net *net =sock_net (ctnl);struct nfnl_queue_net *q =nfnl_queue_pernet (net);int ret =0 ;
net/netfilter/nft_compat.c +3 -3
@@ -519,9 +519,9 @@ nla_put_failure:return -1 ; } -static int -nfnl_compat_get (struct sock *nfnl,struct sk_buff *skb, -const struct nlmsghdr *nlh,const struct nlattr *const tb[]) +static int nfnl_compat_get (struct net *net,struct sock *nfnl, +struct sk_buff *skb,const struct nlmsghdr *nlh, +const struct nlattr *const tb[]) {int ret =0 , target;struct nfgenmsg *nfmsg;
net/netfilter/xt_osf.c +4 -3
@@ -61,8 +61,8 @@ static const struct nla_policy xt_osf_policy[OSF_ATTR_MAX + 1] = { [OSF_ATTR_FINGER] = { .len = sizeof(struct xt_osf_user_finger) }, }; -static int xt_osf_add_callback (struct sock *ctnl,struct sk_buff *skb, -const struct nlmsghdr *nlh, +static int xt_osf_add_callback (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const osf_attrs[]) {struct xt_osf_user_finger *f;
@@ -104,7 +104,8 @@ static int xt_osf_add_callback(struct sock *ctnl, struct sk_buff *skb,return err; } -static int xt_osf_remove_callback (struct sock *ctnl,struct sk_buff *skb, +static int xt_osf_remove_callback (struct net *net,struct sock *ctnl, +struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const osf_attrs[]) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/5 netfilter: nfnetlink: pass down netns pointer to commit() and abort() callbacks
Adapt callsites to avoid recurrent lookup of the netns pointer.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/linux/netfilter/nfnetlink.h | 4 ++-- net/netfilter/nf_tables_api.c | 6 ++---- net/netfilter/nfnetlink.c | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-)
include/linux/netfilter/nfnetlink.h +2 -2
@@ -26,8 +26,8 @@ struct nfnetlink_subsystem {__u8 subsys_id;/* nfnetlink subsystem ID */ __u8 cb_count;/* number of callbacks */ const struct nfnl_callback *cb;/* callback for individual types */ -int (*commit)(struct sk_buff *skb); -int (*abort)(struct sk_buff *skb); +int (*commit)(struct net *net,struct sk_buff *skb); +int (*abort)(struct net *net,struct sk_buff *skb); };int nfnetlink_subsys_register (const struct nfnetlink_subsystem *n);
net/netfilter/nf_tables_api.c +2 -4
@@ -3865,9 +3865,8 @@ static void nf_tables_commit_release(struct nft_trans *trans)kfree (trans); } -static int nf_tables_commit (struct sk_buff *skb) +static int nf_tables_commit (struct net *net,struct sk_buff *skb) { -struct net *net =sock_net (skb->sk);struct nft_trans *trans, *next;struct nft_trans_elem *te;
@@ -4002,9 +4001,8 @@ static void nf_tables_abort_release(struct nft_trans *trans)kfree (trans); } -static int nf_tables_abort (struct sk_buff *skb) +static int nf_tables_abort (struct net *net,struct sk_buff *skb) { -struct net *net =sock_net (skb->sk);struct nft_trans *trans, *next;struct nft_trans_elem *te;
net/netfilter/nfnetlink.c +3 -3
@@ -423,15 +423,15 @@ next: } done:if (status &NFNL_BATCH_REPLAY ) { - ss->abort (oskb); + ss->abort (net, oskb);nfnl_err_reset (&err_list);nfnl_unlock (subsys_id);kfree_skb (skb); goto replay; }else if (status ==NFNL_BATCH_DONE ) { - ss->commit (oskb); + ss->commit (net, oskb); }else { - ss->abort (oskb); + ss->abort (net, oskb); }nfnl_err_deliver (&err_list, oskb);
Signature · 1 line
2.1.4