[ovs-dev] [ipfix-bug 1/3] netlink: New function nl_msg_put_unspec_zero().
Ben Pfaff
blp at nicira.com
Mon Oct 7 21:33:29 UTC 2013
This function already had a few potential users, which this commit
converts. An upcoming commit adds more users.
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
lib/netlink.c | 12 ++++++++++++
lib/netlink.h | 1 +
lib/odp-util.c | 12 +++++-------
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/lib/netlink.c b/lib/netlink.c
index 40477ea..680c676 100644
--- a/lib/netlink.c
+++ b/lib/netlink.c
@@ -220,6 +220,18 @@ nl_msg_put_unspec_uninit(struct ofpbuf *msg, uint16_t type, size_t size)
return nla + 1;
}
+/* Appends a Netlink attribute of the given 'type' and room for 'size' bytes of
+ * data as its payload, plus Netlink padding if needed, to the tail end of
+ * 'msg', reallocating and copying its data if necessary. Returns a pointer to
+ * the first byte of data in the attribute, which is zeroed. */
+void *
+nl_msg_put_unspec_zero(struct ofpbuf *msg, uint16_t type, size_t size)
+{
+ void *data = nl_msg_put_unspec_uninit(msg, type, size);
+ memset(data, 0, size);
+ return data;
+}
+
/* Appends a Netlink attribute of the given 'type' and the 'size' bytes of
* 'data' as its payload, to the tail end of 'msg', reallocating and copying
* its data if necessary. Returns a pointer to the first byte of data in the
diff --git a/lib/netlink.h b/lib/netlink.h
index 21d49d3..1a1c0de 100644
--- a/lib/netlink.h
+++ b/lib/netlink.h
@@ -59,6 +59,7 @@ void *nl_msg_push_uninit(struct ofpbuf *, size_t);
/* Appending attributes. */
void *nl_msg_put_unspec_uninit(struct ofpbuf *, uint16_t type, size_t);
+void *nl_msg_put_unspec_zero(struct ofpbuf *, uint16_t type, size_t);
void nl_msg_put_unspec(struct ofpbuf *, uint16_t type, const void *, size_t);
void nl_msg_put_flag(struct ofpbuf *, uint16_t type);
void nl_msg_put_u8(struct ofpbuf *, uint16_t type, uint8_t value);
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 5c7ccfb..d2aa748 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -1395,7 +1395,7 @@ generate_all_wildcard_mask(struct ofpbuf *ofp, const struct nlattr *key)
int size = nl_attr_get_size(key);
if (odp_flow_key_attr_len(type) >=0) {
- memset(nl_msg_put_unspec_uninit(ofp, type, size), 0, size);
+ nl_msg_put_unspec_zero(ofp, type, size);
} else {
size_t nested_mask;
@@ -2546,9 +2546,8 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *data,
flow->dl_type == htons(ETH_TYPE_RARP)) {
struct ovs_key_arp *arp_key;
- arp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ARP,
- sizeof *arp_key);
- memset(arp_key, 0, sizeof *arp_key);
+ arp_key = nl_msg_put_unspec_zero(buf, OVS_KEY_ATTR_ARP,
+ sizeof *arp_key);
arp_key->arp_sip = data->nw_src;
arp_key->arp_tip = data->nw_dst;
arp_key->arp_op = htons(data->nw_proto);
@@ -3411,9 +3410,8 @@ commit_mpls_action(const struct flow *flow, struct flow *base,
case 1: {
struct ovs_action_push_mpls *mpls;
- mpls = nl_msg_put_unspec_uninit(odp_actions, OVS_ACTION_ATTR_PUSH_MPLS,
- sizeof *mpls);
- memset(mpls, 0, sizeof *mpls);
+ mpls = nl_msg_put_unspec_zero(odp_actions, OVS_ACTION_ATTR_PUSH_MPLS,
+ sizeof *mpls);
mpls->mpls_ethertype = flow->dl_type;
mpls->mpls_lse = flow->mpls_lse;
break;
--
1.7.10.4
More information about the dev
mailing list