summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-04-20 12:18:22 +0000
committerglebius <glebius@FreeBSD.org>2005-04-20 12:18:22 +0000
commit49b129d962b99a6180eba9f6155e297bb869c1c4 (patch)
tree8235d75b1ac951b9301c1751d72fa1c7c73c5c06 /sys
parenteeee734451e20221ffd70b4c0417be68889aff0f (diff)
downloadFreeBSD-src-49b129d962b99a6180eba9f6155e297bb869c1c4.zip
FreeBSD-src-49b129d962b99a6180eba9f6155e297bb869c1c4.tar.gz
Add macro NG_COPYMESSAGE(), which allocates memory and creates a
copy of given control message.
Diffstat (limited to 'sys')
-rw-r--r--sys/netgraph/ng_message.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/sys/netgraph/ng_message.h b/sys/netgraph/ng_message.h
index 749756d..c132b03 100644
--- a/sys/netgraph/ng_message.h
+++ b/sys/netgraph/ng_message.h
@@ -405,7 +405,28 @@ struct flow_manager {
sizeof((rsp)->header.cmdstr)); \
(rsp)->header.flags |= NGF_RESP; \
} while (0)
+
+/*
+ * Make a copy of message. Sets "copy" to NULL if fails.
+ */
+#define NG_COPYMESSAGE(copy, msg, how) \
+ do { \
+ MALLOC((copy), struct ng_mesg *, sizeof(struct ng_mesg) + \
+ (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO); \
+ if ((copy) == NULL) \
+ break; \
+ (copy)->header.version = NG_VERSION; \
+ (copy)->header.arglen = (msg)->header.arglen; \
+ (copy)->header.token = (msg)->header.token; \
+ (copy)->header.typecookie = (msg)->header.typecookie; \
+ (copy)->header.cmd = (msg)->header.cmd; \
+ (copy)->header.flags = (msg)->header.flags; \
+ bcopy((msg)->header.cmdstr, (copy)->header.cmdstr, \
+ sizeof((copy)->header.cmdstr)); \
+ if ((msg)->header.arglen > 0) \
+ bcopy((msg)->data, (copy)->data, (msg)->header.arglen); \
+ } while (0)
+
#endif /* _KERNEL */
#endif /* _NETGRAPH_NG_MESSAGE_H_ */
-
OpenPOWER on IntegriCloud