netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: jamal <hadi@cyberus.ca>
Cc: "David S. Miller" <davem@davemloft.net>, netdev@oss.sgi.com
Subject: [PATCH 1/2] [NETLINK] Introduce NLMSG_NEW macro to better handle netlink flags
Date: Fri, 27 May 2005 19:00:41 +0200	[thread overview]
Message-ID: <20050527170041.GD15391@postel.suug.ch> (raw)
In-Reply-To: <20050527165935.GC15391@postel.suug.ch>

Introduces a new macro NLMSG_NEW which extends NLMSG_PUT but takes
a flags argument. NLMSG_PUT stays there for compatibility but now
calls NLMSG_NEW with flags == 0. NLMSG_PUT_ANSWER is renamed to
NLMSG_NEW_ANSWER which now also takes a flags argument.

Also converts the users of NLMSG_PUT_ANSWER to use NLMSG_NEW_ANSWER
and fixes the two direct users of __nlmsg_put to either provide
the flags or use NLMSG_NEW(_ANSWER).

Signed-off-by: Thomas Graf <tgraf@suug.ch>

---
commit 1eb85f52f4e0d23996f6aa49009ce02fc0579658
tree debb58e5f900a6551f751b457226250cfccc3c75
parent fde09d4989b6c7b5183ffb3ec2076ff53dd6fa78
author Thomas Graf <tgraf@suug.ch> Fri, 27 May 2005 17:43:09 +0200
committer Thomas Graf <tgraf@suug.ch> Fri, 27 May 2005 17:43:09 +0200

 include/linux/netlink.h  |   17 ++++++++++-------
 net/core/neighbour.c     |    8 ++++----
 net/netlink/af_netlink.c |    8 +++++---
 3 files changed, 19 insertions(+), 14 deletions(-)

Index: include/linux/netlink.h
===================================================================
--- b032d0d440d93aac252e656bd41df32ff5461e3a/include/linux/netlink.h  (mode:100644)
+++ debb58e5f900a6551f751b457226250cfccc3c75/include/linux/netlink.h  (mode:100644)
@@ -156,7 +156,7 @@
 };
 
 static __inline__ struct nlmsghdr *
-__nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len)
+__nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)
 {
 	struct nlmsghdr *nlh;
 	int size = NLMSG_LENGTH(len);
@@ -164,20 +164,23 @@
 	nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size));
 	nlh->nlmsg_type = type;
 	nlh->nlmsg_len = size;
-	nlh->nlmsg_flags = 0;
+	nlh->nlmsg_flags = flags;
 	nlh->nlmsg_pid = pid;
 	nlh->nlmsg_seq = seq;
 	return nlh;
 }
 
-#define NLMSG_PUT(skb, pid, seq, type, len) \
+#define NLMSG_NEW(skb, pid, seq, type, len, flags) \
 ({	if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) \
 		goto nlmsg_failure; \
-	__nlmsg_put(skb, pid, seq, type, len); })
+	__nlmsg_put(skb, pid, seq, type, len, flags); })
+
+#define NLMSG_PUT(skb, pid, seq, type, len) \
+	NLMSG_NEW(skb, pid, seq, type, len, 0)
 
-#define NLMSG_PUT_ANSWER(skb, cb, type, len) \
-	NLMSG_PUT(skb, NETLINK_CB((cb)->skb).pid, \
-		  (cb)->nlh->nlmsg_seq, type, len)
+#define NLMSG_NEW_ANSWER(skb, cb, type, len, flags) \
+	NLMSG_NEW(skb, NETLINK_CB((cb)->skb).pid, \
+		  (cb)->nlh->nlmsg_seq, type, len, flags)
 
 #define NLMSG_END(skb, nlh) \
 ({	(nlh)->nlmsg_len = (skb)->tail - (unsigned char *) (nlh); \
Index: net/core/neighbour.c
===================================================================
--- b032d0d440d93aac252e656bd41df32ff5461e3a/net/core/neighbour.c  (mode:100644)
+++ debb58e5f900a6551f751b457226250cfccc3c75/net/core/neighbour.c  (mode:100644)
@@ -1588,8 +1588,8 @@
 	struct nlmsghdr *nlh;
 	struct ndtmsg *ndtmsg;
 
-	nlh = NLMSG_PUT_ANSWER(skb, cb, RTM_NEWNEIGHTBL, sizeof(struct ndtmsg));
-	nlh->nlmsg_flags |= NLM_F_MULTI;
+	nlh = NLMSG_NEW_ANSWER(skb, cb, RTM_NEWNEIGHTBL, sizeof(struct ndtmsg),
+			       NLM_F_MULTI);
 
 	ndtmsg = NLMSG_DATA(nlh);
 
@@ -1673,8 +1673,8 @@
 	struct ndtmsg *ndtmsg;
 	struct nlmsghdr *nlh;
 
-	nlh = NLMSG_PUT_ANSWER(skb, cb, RTM_NEWNEIGHTBL, sizeof(struct ndtmsg));
-	nlh->nlmsg_flags |= NLM_F_MULTI;
+	nlh = NLMSG_NEW_ANSWER(skb, cb, RTM_NEWNEIGHTBL, sizeof(struct ndtmsg),
+			       NLM_F_MULTI);
 
 	ndtmsg = NLMSG_DATA(nlh);
 
Index: net/netlink/af_netlink.c
===================================================================
--- b032d0d440d93aac252e656bd41df32ff5461e3a/net/netlink/af_netlink.c  (mode:100644)
+++ debb58e5f900a6551f751b457226250cfccc3c75/net/netlink/af_netlink.c  (mode:100644)
@@ -1095,8 +1095,7 @@
 		return 0;
 	}
 
-	nlh = __nlmsg_put(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, NLMSG_DONE, sizeof(int));
-	nlh->nlmsg_flags |= NLM_F_MULTI;
+	nlh = NLMSG_NEW_ANSWER(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
 	memcpy(NLMSG_DATA(nlh), &len, sizeof(len));
 	skb_queue_tail(&sk->sk_receive_queue, skb);
 	sk->sk_data_ready(sk, skb->len);
@@ -1107,6 +1106,9 @@
 
 	netlink_destroy_callback(cb);
 	return 0;
+
+nlmsg_failure:
+	return -ENOBUFS;
 }
 
 int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
@@ -1178,7 +1180,7 @@
 	}
 
 	rep = __nlmsg_put(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq,
-			  NLMSG_ERROR, sizeof(struct nlmsgerr));
+			  NLMSG_ERROR, sizeof(struct nlmsgerr), 0);
 	errmsg = NLMSG_DATA(rep);
 	errmsg->error = err;
 	memcpy(&errmsg->msg, nlh, err ? nlh->nlmsg_len : sizeof(struct nlmsghdr));

  reply	other threads:[~2005-05-27 17:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-27 12:32 PATCH: rtnetlink explicit flags setting jamal
2005-05-27 12:50 ` Thomas Graf
2005-05-27 13:58   ` jamal
2005-05-27 14:13     ` Thomas Graf
2005-05-27 15:01       ` jamal
2005-05-27 15:19         ` Thomas Graf
2005-05-27 15:57           ` jamal
2005-05-27 16:59             ` Thomas Graf
2005-05-27 17:00               ` Thomas Graf [this message]
2005-05-27 17:01               ` [PATCH 2/2] [NETLINK] Correctly set NLM_F_MULTI without checking the pid Thomas Graf
2005-05-28  1:06                 ` jamal
2005-05-31 22:37                 ` David S. Miller
2005-05-28  1:12               ` PATCH: rtnetlink explicit flags setting jamal
2005-05-28  1:28                 ` Thomas Graf
2005-05-28  1:48                   ` jamal
2005-05-28 12:18                     ` Thomas Graf
2005-05-28 16:00                       ` jamal
2005-05-28 16:16                         ` Thomas Graf
2005-05-31  9:39                           ` jamal
2005-05-31  9:41                             ` who 王海
2005-05-31 21:43 ` PATCH: rtnetlink explicit flags setting David S. Miller
2005-05-31 22:26   ` Thomas Graf
2005-05-31 22:31     ` David S. Miller
2005-06-02 13:04       ` PATCH: explicit typing WAS(Re: " jamal
2005-06-02 13:30         ` jamal
2005-06-03  5:08         ` David S. 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=20050527170041.GD15391@postel.suug.ch \
    --to=tgraf@suug.ch \
    --cc=davem@davemloft.net \
    --cc=hadi@cyberus.ca \
    --cc=netdev@oss.sgi.com \
    /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).