X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fnetlink.c;h=40477eaec14c50b9266f676bd5f3ed5324b6b104;hb=542024c4c3d36b2d303efbe6c0da469c8e446476;hp=50444abd973c9352239ecb98cbacc59fae31ac22;hpb=98b07853dfd6046938c41937d60ce693437c1f25;p=sliver-openvswitch.git diff --git a/lib/netlink.c b/lib/netlink.c index 50444abd9..40477eaec 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -322,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); - ovs_assert(NLA_ALIGN(total_size) <= UINT16_MAX); + ovs_assert(!nl_attr_oversized(size)); nla->nla_len = total_size; nla->nla_type = type; return nla + 1; @@ -468,6 +468,16 @@ nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg) msg->size = 0; return NULL; } + +/* Returns true if a Netlink attribute with a payload that is 'payload_size' + * bytes long would be oversized, that is, if it's not possible to create an + * nlattr of that size because its size wouldn't fit in the 16-bit nla_len + * field. */ +bool +nl_attr_oversized(size_t payload_size) +{ + return NL_ATTR_SIZE(payload_size) > UINT16_MAX; +} /* Attributes. */