diff options
author | Ben Pfaff <blp@ovn.org> | 2017-06-14 09:07:45 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-06-14 12:34:36 -0700 |
commit | ab79d262e17442926f1e480984ad663b978d46d7 (patch) | |
tree | 65aec4aaceb80207b1d0e42d70fec270381663e7 /lib/netlink.c | |
parent | 62a78fe5d996cf01355bc090383ba7850609c864 (diff) | |
download | openvswitch-ab79d262e17442926f1e480984ad663b978d46d7.tar.gz |
netlink: Introduce helpers for 128-bit integer attributes.
Use the helpers in appropriate places. In most cases, this fixes a
misaligned reference, since ovs_be128 and ovs_u128 require 8-byte alignment
but Netlink only guarantees 4-byte.
Found by GCC -fsanitize=undefined.
Reported-by: Lance Richardson <lrichard@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Lance Richardson <lrichard@redhat.com>
Diffstat (limited to 'lib/netlink.c')
-rw-r--r-- | lib/netlink.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/netlink.c b/lib/netlink.c index 0246131a4..4cf1aaca6 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -288,6 +288,14 @@ nl_msg_put_u64(struct ofpbuf *msg, uint16_t type, uint64_t value) nl_msg_put_unspec(msg, type, &value, sizeof value); } +/* Appends a Netlink attribute of the given 'type' and the given 128-bit host + * byte order 'value' to 'msg'. */ +void +nl_msg_put_u128(struct ofpbuf *msg, uint16_t type, ovs_u128 value) +{ + nl_msg_put_unspec(msg, type, &value, sizeof value); +} + /* Appends a Netlink attribute of the given 'type' and the given 16-bit network * byte order 'value' to 'msg'. */ void @@ -312,6 +320,14 @@ 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 128-bit + * network byte order 'value' to 'msg'. */ +void +nl_msg_put_be128(struct ofpbuf *msg, uint16_t type, ovs_be128 value) +{ + nl_msg_put_unspec(msg, type, &value, sizeof value); +} + /* Appends a Netlink attribute of the given 'type' and the given IPv6 * address order 'value' to 'msg'. */ void @@ -416,6 +432,14 @@ nl_msg_push_u64(struct ofpbuf *msg, uint16_t type, uint64_t value) nl_msg_push_unspec(msg, type, &value, sizeof value); } +/* Prepends a Netlink attribute of the given 'type' and the given 128-bit host + * byte order 'value' to 'msg'. */ +void +nl_msg_push_u128(struct ofpbuf *msg, uint16_t type, ovs_u128 value) +{ + nl_msg_push_unspec(msg, type, &value, sizeof value); +} + /* Prepends a Netlink attribute of the given 'type' and the given 16-bit * network byte order 'value' to 'msg'. */ void @@ -440,6 +464,14 @@ nl_msg_push_be64(struct ofpbuf *msg, uint16_t type, ovs_be64 value) nl_msg_push_unspec(msg, type, &value, sizeof value); } +/* Prepends a Netlink attribute of the given 'type' and the given 128-bit + * network byte order 'value' to 'msg'. */ +void +nl_msg_push_be128(struct ofpbuf *msg, uint16_t type, ovs_be128 value) +{ + nl_msg_push_unspec(msg, type, &value, sizeof value); +} + /* Prepends a Netlink attribute of the given 'type' and the given * null-terminated string 'value' to 'msg'. */ void @@ -625,6 +657,16 @@ nl_attr_get_u64(const struct nlattr *nla) return get_32aligned_u64(x); } +/* Returns the 128-bit host byte order value in 'nla''s payload. + * + * Asserts that 'nla''s payload is at least 16 bytes long. */ +ovs_u128 +nl_attr_get_u128(const struct nlattr *nla) +{ + const ovs_32aligned_u128 *x = nl_attr_get_unspec(nla, sizeof *x); + return get_32aligned_u128(x); +} + /* Returns the 16-bit network byte order value in 'nla''s payload. * * Asserts that 'nla''s payload is at least 2 bytes long. */ @@ -653,6 +695,16 @@ nl_attr_get_be64(const struct nlattr *nla) return get_32aligned_be64(x); } +/* Returns the 128-bit network byte order value in 'nla''s payload. + * + * Asserts that 'nla''s payload is at least 16 bytes long. */ +ovs_be128 +nl_attr_get_be128(const struct nlattr *nla) +{ + const ovs_32aligned_be128 *x = nl_attr_get_unspec(nla, sizeof *x); + return get_32aligned_be128(x); +} + /* Returns the IPv6 address value in 'nla''s payload. * * Asserts that 'nla''s payload is at least 16 bytes long. */ @@ -700,6 +752,7 @@ min_attr_len(enum nl_attr_type type) case NL_A_U16: return 2; case NL_A_U32: return 4; case NL_A_U64: return 8; + case NL_A_U128: return 16; case NL_A_STRING: return 1; case NL_A_FLAG: return 0; case NL_A_IPV6: return 16; @@ -719,6 +772,7 @@ max_attr_len(enum nl_attr_type type) case NL_A_U16: return 2; case NL_A_U32: return 4; case NL_A_U64: return 8; + case NL_A_U128: return 16; case NL_A_STRING: return SIZE_MAX; case NL_A_FLAG: return SIZE_MAX; case NL_A_IPV6: return 16; |