From: Pablo Neira Ayuso Date: Tue, 4 Oct 2016 06:48:37 +0000 (+0200) Subject: set_elem: don't add NFTA_SET_ELEM_LIST_ELEMENTS attribute if set is empty X-Git-Tag: libnftnl-1.0.7~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a24e4b21ee33d8307e25ce609c7333ef0ca5811c;p=thirdparty%2Flibnftnl.git set_elem: don't add NFTA_SET_ELEM_LIST_ELEMENTS attribute if set is empty If the set is empty, don't send an empty NFTA_SET_ELEM_LIST_ELEMENTS netlink attributes with no elements. Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/set_elem.c b/src/set_elem.c index 46fb7c6e..4d2b4f60 100644 --- a/src/set_elem.c +++ b/src/set_elem.c @@ -304,6 +304,9 @@ void nftnl_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set nftnl_set_elem_nlmsg_build_def(nlh, s); + if (list_empty(&s->element_list)) + return; + nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_LIST_ELEMENTS); list_for_each_entry(elem, &s->element_list, head) nftnl_set_elem_build(nlh, elem, ++i);