dpif: Log flow masks for "put" and "dump_next".
[sliver-openvswitch.git] / lib / netlink.c
index 5414239..7e7884e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #include <config.h>
 #include "netlink.h"
-#include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include "coverage.h"
+#include "flow.h"
 #include "netlink-protocol.h"
 #include "ofpbuf.h"
 #include "timeval.h"
@@ -113,7 +113,7 @@ nl_msg_put_nlmsghdr(struct ofpbuf *msg,
 {
     struct nlmsghdr *nlmsghdr;
 
-    assert(msg->size == 0);
+    ovs_assert(msg->size == 0);
 
     nl_msg_reserve(msg, NLMSG_HDRLEN + expected_payload);
     nlmsghdr = nl_msg_put_uninit(msg, NLMSG_HDRLEN);
@@ -152,7 +152,7 @@ nl_msg_put_genlmsghdr(struct ofpbuf *msg, size_t expected_payload,
     struct genlmsghdr *genlmsghdr;
 
     nl_msg_put_nlmsghdr(msg, GENL_HDRLEN + expected_payload, family, flags);
-    assert(msg->size == NLMSG_HDRLEN);
+    ovs_assert(msg->size == NLMSG_HDRLEN);
     genlmsghdr = nl_msg_put_uninit(msg, GENL_HDRLEN);
     genlmsghdr->cmd = cmd;
     genlmsghdr->version = version;
@@ -214,7 +214,7 @@ nl_msg_put_unspec_uninit(struct ofpbuf *msg, uint16_t type, size_t size)
 {
     size_t total_size = NLA_HDRLEN + size;
     struct nlattr* nla = nl_msg_put_uninit(msg, total_size);
-    assert(NLA_ALIGN(total_size) <= UINT16_MAX);
+    ovs_assert(NLA_ALIGN(total_size) <= UINT16_MAX);
     nla->nla_len = total_size;
     nla->nla_type = type;
     return nla + 1;
@@ -296,6 +296,15 @@ nl_msg_put_be64(struct ofpbuf *msg, uint16_t type, ovs_be64 value)
     nl_msg_put_unspec(msg, type, &value, sizeof value);
 }
 
+/* Appends a Netlink attribute of the given 'type' and the given odp_port_t
+ * 'value' to 'msg'. */
+void
+nl_msg_put_odp_port(struct ofpbuf *msg, uint16_t type, odp_port_t value)
+{
+    nl_msg_put_u32(msg, type, odp_to_u32(value));
+}
+
+
 /* Appends a Netlink attribute of the given 'type' and the given
  * null-terminated string 'value' to 'msg'. */
 void
@@ -313,7 +322,7 @@ nl_msg_push_unspec_uninit(struct ofpbuf *msg, uint16_t type, size_t size)
 {
     size_t total_size = NLA_HDRLEN + size;
     struct nlattr* nla = nl_msg_push_uninit(msg, total_size);
-    assert(NLA_ALIGN(total_size) <= UINT16_MAX);
+    ovs_assert(NLA_ALIGN(total_size) <= UINT16_MAX);
     nla->nla_len = total_size;
     nla->nla_type = type;
     return nla + 1;
@@ -474,7 +483,7 @@ nl_attr_type(const struct nlattr *nla)
 const void *
 nl_attr_get(const struct nlattr *nla)
 {
-    assert(nla->nla_len >= NLA_HDRLEN);
+    ovs_assert(nla->nla_len >= NLA_HDRLEN);
     return nla + 1;
 }
 
@@ -482,7 +491,7 @@ nl_attr_get(const struct nlattr *nla)
 size_t
 nl_attr_get_size(const struct nlattr *nla)
 {
-    assert(nla->nla_len >= NLA_HDRLEN);
+    ovs_assert(nla->nla_len >= NLA_HDRLEN);
     return nla->nla_len - NLA_HDRLEN;
 }
 
@@ -491,7 +500,7 @@ nl_attr_get_size(const struct nlattr *nla)
 const void *
 nl_attr_get_unspec(const struct nlattr *nla, size_t size)
 {
-    assert(nla->nla_len >= NLA_HDRLEN + size);
+    ovs_assert(nla->nla_len >= NLA_HDRLEN + size);
     return nla + 1;
 }
 
@@ -571,14 +580,23 @@ nl_attr_get_be64(const struct nlattr *nla)
     return get_32aligned_be64(x);
 }
 
+/* Returns the 32-bit odp_port_t value in 'nla''s payload.
+ *
+ * Asserts that 'nla''s payload is at least 4 bytes long. */
+odp_port_t
+nl_attr_get_odp_port(const struct nlattr *nla)
+{
+    return u32_to_odp(nl_attr_get_u32(nla));
+}
+
 /* Returns the null-terminated string value in 'nla''s payload.
  *
  * Asserts that 'nla''s payload contains a null-terminated string. */
 const char *
 nl_attr_get_string(const struct nlattr *nla)
 {
-    assert(nla->nla_len > NLA_HDRLEN);
-    assert(memchr(nl_attr_get(nla), '\0', nla->nla_len - NLA_HDRLEN) != NULL);
+    ovs_assert(nla->nla_len > NLA_HDRLEN);
+    ovs_assert(memchr(nl_attr_get(nla), '\0', nla->nla_len - NLA_HDRLEN));
     return nl_attr_get(nla);
 }