From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, dmitry.tarnyaginuug.ch@6wind.com,
Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [RFC PATCH net 4/4] netlink: add a flags field in the cb structure
Date: Tue, 28 Apr 2015 18:33:51 +0200 [thread overview]
Message-ID: <1430238831-29966-5-git-send-email-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <1430238831-29966-1-git-send-email-nicolas.dichtel@6wind.com>
The goal of this patch is to minimize copy and paste error. The flag
NLM_F_MULTI is often set in wrong cases because people copy and paste code
that uses this flag. When this flag is set, it means that it is a
multi-part netlink message which ends with a NLMSG_DONE.
In most of the cases, only a dump sends this NLMSG_DONE message. Let's set
this flag directly into the dump, hence people won't copy and paste
NLM_F_MULTI.
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
include/linux/netlink.h | 1 +
net/core/rtnetlink.c | 9 ++++-----
net/netlink/af_netlink.c | 1 +
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 6835c1279df7..0a29bd255639 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -129,6 +129,7 @@ struct netlink_callback {
u16 family;
u16 min_dump_alloc;
unsigned int prev_seq, seq;
+ int flags;
long args[6];
};
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 666e0928ba40..837d30b5ffed 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1357,8 +1357,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, 0,
- NLM_F_MULTI,
- ext_filter_mask);
+ cb->flags, ext_filter_mask);
/* If we ran out of room on the first message,
* we're in trouble
*/
@@ -2738,7 +2737,7 @@ static int nlmsg_populate_fdb(struct sk_buff *skb,
err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0,
portid, seq,
RTM_NEWNEIGH, NTF_SELF,
- NLM_F_MULTI);
+ cb->flags);
if (err < 0)
return err;
skip:
@@ -2970,7 +2969,7 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
if (idx >= cb->args[0] &&
br_dev->netdev_ops->ndo_bridge_getlink(
skb, portid, seq, dev, filter_mask,
- NLM_F_MULTI) < 0)
+ cb->flags) < 0)
break;
idx++;
}
@@ -2979,7 +2978,7 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
if (idx >= cb->args[0] &&
ops->ndo_bridge_getlink(skb, portid, seq, dev,
filter_mask,
- NLM_F_MULTI) < 0)
+ cb->flags) < 0)
break;
idx++;
}
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index ec4adbdcb9b4..3e2d29703499 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2755,6 +2755,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
cb->module = control->module;
cb->min_dump_alloc = control->min_dump_alloc;
cb->skb = skb;
+ cb->flags = NLM_F_MULTI;
nlk->cb_running = true;
--
2.2.2
next prev parent reply other threads:[~2015-04-28 16:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-28 16:33 [PATCH net 0/3] netlink: fix wrong use of the flag NLM_F_MULTI Nicolas Dichtel
2015-04-28 16:33 ` [PATCH net 1/3] bridge/mdb: remove wrong use of NLM_F_MULTI Nicolas Dichtel
2015-04-28 16:33 ` [PATCH net 2/3] bridge/nl: " Nicolas Dichtel
2015-04-30 13:01 ` Jeff Kirsher
2015-04-28 16:33 ` [PATCH net 3/3] tipc: " Nicolas Dichtel
2015-04-28 16:33 ` Nicolas Dichtel [this message]
2015-04-29 19:00 ` [PATCH net 0/3] netlink: fix wrong use of the flag NLM_F_MULTI David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430238831-29966-5-git-send-email-nicolas.dichtel@6wind.com \
--to=nicolas.dichtel@6wind.com \
--cc=davem@davemloft.net \
--cc=dmitry.tarnyaginuug.ch@6wind.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).