[NETLINK]: New message building macros
authorThomas Graf <tgraf@suug.ch>
Sun, 19 Jun 2005 05:50:12 +0000 (22:50 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 19 Jun 2005 05:50:12 +0000 (22:50 -0700)
 NLMSG_PUT_ANSWER(skb, nlcb, type, length)
   Start a new netlink message as answer to a request,
   returns the message header.

 NLMSG_END(skb, nlh)
   End a netlink message, fixes total message length,
   returns skb->len.

 NLMSG_CANCEL(skb, nlh)
   Cancel the building process and trim whole message
   from skb again, returns -1.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netlink.h

index b2738ac..8d1cb41 100644 (file)
@@ -171,8 +171,21 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len)
 }
 
 #define NLMSG_PUT(skb, pid, seq, type, len) \
-({ if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) goto nlmsg_failure; \
-   __nlmsg_put(skb, pid, seq, type, len); })
+({     if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) \
+               goto nlmsg_failure; \
+       __nlmsg_put(skb, pid, seq, type, len); })
+
+#define NLMSG_PUT_ANSWER(skb, cb, type, len) \
+       NLMSG_PUT(skb, NETLINK_CB((cb)->skb).pid, \
+                 (cb)->nlh->nlmsg_seq, type, len)
+
+#define NLMSG_END(skb, nlh) \
+({     (nlh)->nlmsg_len = (skb)->tail - (unsigned char *) (nlh); \
+       (skb)->len; })
+
+#define NLMSG_CANCEL(skb, nlh) \
+({     skb_trim(skb, (unsigned char *) (nlh) - (skb)->data); \
+       -1; })
 
 extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
                              struct nlmsghdr *nlh,