Commit 80d326fa authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso Committed by David S. Miller

netlink: add netlink_dump_control structure for netlink_dump_start()

Davem considers that the argument list of this interface is getting
out of control. This patch tries to address this issue following
his proposal:

struct netlink_dump_control c = { .dump = dump, .done = done, ... };

netlink_dump_start(..., &c);

Suggested by David S. Miller.
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 48e316bc
...@@ -389,9 +389,13 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -389,9 +389,13 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
(nlh->nlmsg_flags & NLM_F_DUMP))) { (nlh->nlmsg_flags & NLM_F_DUMP))) {
if (link->dump == NULL) if (link->dump == NULL)
return -EINVAL; return -EINVAL;
{
return netlink_dump_start(crypto_nlsk, skb, nlh, struct netlink_dump_control c = {
link->dump, link->done, 0); .dump = link->dump,
.done = link->done,
};
return netlink_dump_start(crypto_nlsk, skb, nlh, &c);
}
} }
err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX, err = nlmsg_parse(nlh, crypto_msg_min[type], attrs, CRYPTOCFGA_MAX,
......
...@@ -147,9 +147,13 @@ static int ibnl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -147,9 +147,13 @@ static int ibnl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
if (op < 0 || op >= client->nops || if (op < 0 || op >= client->nops ||
!client->cb_table[RDMA_NL_GET_OP(op)].dump) !client->cb_table[RDMA_NL_GET_OP(op)].dump)
return -EINVAL; return -EINVAL;
return netlink_dump_start(nls, skb, nlh,
client->cb_table[op].dump, {
NULL, 0); struct netlink_dump_control c = {
.dump = client->cb_table[op].dump,
};
return netlink_dump_start(nls, skb, nlh, &c);
}
} }
} }
......
...@@ -248,11 +248,15 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags) ...@@ -248,11 +248,15 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)
#define NLMSG_PUT(skb, pid, seq, type, len) \ #define NLMSG_PUT(skb, pid, seq, type, len) \
NLMSG_NEW(skb, pid, seq, type, len, 0) NLMSG_NEW(skb, pid, seq, type, len, 0)
struct netlink_dump_control {
int (*dump)(struct sk_buff *skb, struct netlink_callback *);
int (*done)(struct netlink_callback*);
u16 min_dump_alloc;
};
extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
const struct nlmsghdr *nlh, const struct nlmsghdr *nlh,
int (*dump)(struct sk_buff *skb, struct netlink_callback*), struct netlink_dump_control *control);
int (*done)(struct netlink_callback*),
u16 min_dump_alloc);
#define NL_NONROOT_RECV 0x1 #define NL_NONROOT_RECV 0x1
......
...@@ -1981,8 +1981,13 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1981,8 +1981,13 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
__rtnl_unlock(); __rtnl_unlock();
rtnl = net->rtnl; rtnl = net->rtnl;
err = netlink_dump_start(rtnl, skb, nlh, dumpit, {
NULL, min_dump_alloc); struct netlink_dump_control c = {
.dump = dumpit,
.min_dump_alloc = min_dump_alloc,
};
err = netlink_dump_start(rtnl, skb, nlh, &c);
}
rtnl_lock(); rtnl_lock();
return err; return err;
} }
......
...@@ -960,9 +960,12 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -960,9 +960,12 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
inet_diag_bc_audit(nla_data(attr), nla_len(attr))) inet_diag_bc_audit(nla_data(attr), nla_len(attr)))
return -EINVAL; return -EINVAL;
} }
{
return netlink_dump_start(sock_diag_nlsk, skb, nlh, struct netlink_dump_control c = {
inet_diag_dump_compat, NULL, 0); .dump = inet_diag_dump_compat,
};
return netlink_dump_start(sock_diag_nlsk, skb, nlh, &c);
}
} }
return inet_diag_get_exact_compat(skb, nlh); return inet_diag_get_exact_compat(skb, nlh);
...@@ -985,9 +988,12 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -985,9 +988,12 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
inet_diag_bc_audit(nla_data(attr), nla_len(attr))) inet_diag_bc_audit(nla_data(attr), nla_len(attr)))
return -EINVAL; return -EINVAL;
} }
{
return netlink_dump_start(sock_diag_nlsk, skb, h, struct netlink_dump_control c = {
inet_diag_dump, NULL, 0); .dump = inet_diag_dump,
};
return netlink_dump_start(sock_diag_nlsk, skb, h, &c);
}
} }
return inet_diag_get_exact(skb, h, (struct inet_diag_req_v2 *)NLMSG_DATA(h)); return inet_diag_get_exact(skb, h, (struct inet_diag_req_v2 *)NLMSG_DATA(h));
......
...@@ -1162,9 +1162,13 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb, ...@@ -1162,9 +1162,13 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb,
if (unlikely(protocol_failed(attr))) if (unlikely(protocol_failed(attr)))
return -IPSET_ERR_PROTOCOL; return -IPSET_ERR_PROTOCOL;
return netlink_dump_start(ctnl, skb, nlh, {
ip_set_dump_start, struct netlink_dump_control c = {
ip_set_dump_done, 0); .dump = ip_set_dump_start,
.done = ip_set_dump_done,
};
return netlink_dump_start(ctnl, skb, nlh, &c);
}
} }
/* Add, del and test */ /* Add, del and test */
......
...@@ -977,9 +977,13 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, ...@@ -977,9 +977,13 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
u16 zone; u16 zone;
int err; int err;
if (nlh->nlmsg_flags & NLM_F_DUMP) if (nlh->nlmsg_flags & NLM_F_DUMP) {
return netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table, struct netlink_dump_control c = {
ctnetlink_done, 0); .dump = ctnetlink_dump_table,
.done = ctnetlink_done,
};
return netlink_dump_start(ctnl, skb, nlh, &c);
}
err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone); err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
if (err < 0) if (err < 0)
...@@ -1850,9 +1854,11 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, ...@@ -1850,9 +1854,11 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
int err; int err;
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
return netlink_dump_start(ctnl, skb, nlh, struct netlink_dump_control c = {
ctnetlink_exp_dump_table, .dump = ctnetlink_exp_dump_table,
ctnetlink_exp_done, 0); .done = ctnetlink_exp_done,
};
return netlink_dump_start(ctnl, skb, nlh, &c);
} }
err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone); err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
......
...@@ -171,8 +171,10 @@ nfnl_acct_get(struct sock *nfnl, struct sk_buff *skb, ...@@ -171,8 +171,10 @@ nfnl_acct_get(struct sock *nfnl, struct sk_buff *skb,
char *acct_name; char *acct_name;
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
return netlink_dump_start(nfnl, skb, nlh, nfnl_acct_dump, struct netlink_dump_control c = {
NULL, 0); .dump = nfnl_acct_dump,
};
return netlink_dump_start(nfnl, skb, nlh, &c);
} }
if (!tb[NFACCT_NAME]) if (!tb[NFACCT_NAME])
......
...@@ -1736,10 +1736,7 @@ static int netlink_dump(struct sock *sk) ...@@ -1736,10 +1736,7 @@ static int netlink_dump(struct sock *sk)
int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
const struct nlmsghdr *nlh, const struct nlmsghdr *nlh,
int (*dump)(struct sk_buff *skb, struct netlink_dump_control *control)
struct netlink_callback *),
int (*done)(struct netlink_callback *),
u16 min_dump_alloc)
{ {
struct netlink_callback *cb; struct netlink_callback *cb;
struct sock *sk; struct sock *sk;
...@@ -1750,10 +1747,10 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, ...@@ -1750,10 +1747,10 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
if (cb == NULL) if (cb == NULL)
return -ENOBUFS; return -ENOBUFS;
cb->dump = dump; cb->dump = control->dump;
cb->done = done; cb->done = control->done;
cb->nlh = nlh; cb->nlh = nlh;
cb->min_dump_alloc = min_dump_alloc; cb->min_dump_alloc = control->min_dump_alloc;
atomic_inc(&skb->users); atomic_inc(&skb->users);
cb->skb = skb; cb->skb = skb;
......
...@@ -563,8 +563,13 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -563,8 +563,13 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
return -EOPNOTSUPP; return -EOPNOTSUPP;
genl_unlock(); genl_unlock();
err = netlink_dump_start(net->genl_sock, skb, nlh, {
ops->dumpit, ops->done, 0); struct netlink_dump_control c = {
.dump = ops->dumpit,
.done = ops->done,
};
err = netlink_dump_start(net->genl_sock, skb, nlh, &c);
}
genl_lock(); genl_lock();
return err; return err;
} }
......
...@@ -301,10 +301,12 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -301,10 +301,12 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
if (nlmsg_len(h) < hdrlen) if (nlmsg_len(h) < hdrlen)
return -EINVAL; return -EINVAL;
if (h->nlmsg_flags & NLM_F_DUMP) if (h->nlmsg_flags & NLM_F_DUMP) {
return netlink_dump_start(sock_diag_nlsk, skb, h, struct netlink_dump_control c = {
unix_diag_dump, NULL, 0); .dump = unix_diag_dump,
else };
return netlink_dump_start(sock_diag_nlsk, skb, h, &c);
} else
return unix_diag_get_exact(skb, h, (struct unix_diag_req *)NLMSG_DATA(h)); return unix_diag_get_exact(skb, h, (struct unix_diag_req *)NLMSG_DATA(h));
} }
......
...@@ -2299,8 +2299,13 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2299,8 +2299,13 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
if (link->dump == NULL) if (link->dump == NULL)
return -EINVAL; return -EINVAL;
return netlink_dump_start(net->xfrm.nlsk, skb, nlh, {
link->dump, link->done, 0); struct netlink_dump_control c = {
.dump = link->dump,
.done = link->done,
};
return netlink_dump_start(net->xfrm.nlsk, skb, nlh, &c);
}
} }
err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, XFRMA_MAX, err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, XFRMA_MAX,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment