aboutsummaryrefslogtreecommitdiff
path: root/utilities/nlmon.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-04-09 15:35:29 -0700
committerBen Pfaff <blp@nicira.com>2012-04-18 20:28:48 -0700
commit72d32ac0b3a1358cb36cf43f15ee7c026be36d2c (patch)
treea031af06500b11fb4bddfa81f17af9916f632ba9 /utilities/nlmon.c
parent8843668ae593f51b3bf4ab189fa218c40f0f0e33 (diff)
netlink-socket: Make caller provide message receive buffers.
Typically an nl_sock client can stack-allocate the buffer for receiving a Netlink message, which provides a performance boost. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'utilities/nlmon.c')
-rw-r--r--utilities/nlmon.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/utilities/nlmon.c b/utilities/nlmon.c
index 1b2f1e21..e6cf0235 100644
--- a/utilities/nlmon.c
+++ b/utilities/nlmon.c
@@ -39,7 +39,9 @@ static const struct nl_policy rtnlgrp_link_policy[] = {
int
main(int argc OVS_UNUSED, char *argv[])
{
+ uint64_t buf_stub[4096 / 64];
struct nl_sock *sock;
+ struct ofpbuf buf;
int error;
set_program_name(argv[0]);
@@ -55,9 +57,8 @@ main(int argc OVS_UNUSED, char *argv[])
ovs_fatal(error, "could not join RTNLGRP_LINK multicast group");
}
+ ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub);
for (;;) {
- struct ofpbuf *buf;
-
error = nl_sock_recv(sock, &buf, false);
if (error == EAGAIN) {
/* Nothing to do. */
@@ -95,19 +96,17 @@ main(int argc OVS_UNUSED, char *argv[])
struct ifinfomsg *iim;
int i;
- nlh = ofpbuf_at(buf, 0, NLMSG_HDRLEN);
- iim = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *iim);
+ nlh = ofpbuf_at(&buf, 0, NLMSG_HDRLEN);
+ iim = ofpbuf_at(&buf, NLMSG_HDRLEN, sizeof *iim);
if (!iim) {
ovs_error(0, "received bad rtnl message (no ifinfomsg)");
- ofpbuf_delete(buf);
continue;
}
- if (!nl_policy_parse(buf, NLMSG_HDRLEN + sizeof(struct ifinfomsg),
+ if (!nl_policy_parse(&buf, NLMSG_HDRLEN + sizeof(struct ifinfomsg),
rtnlgrp_link_policy,
attrs, ARRAY_SIZE(rtnlgrp_link_policy))) {
ovs_error(0, "received bad rtnl message (policy)");
- ofpbuf_delete(buf);
continue;
}
printf("netdev %s changed (%s):\n",
@@ -132,7 +131,6 @@ main(int argc OVS_UNUSED, char *argv[])
}
printf("\tmaster=%"PRIu32" (%s)\n", idx, ifname);
}
- ofpbuf_delete(buf);
}
nl_sock_wait(sock, POLLIN);