]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
libnftnl: Fix res_id byte order
authorIan Pilcher <arequipeno@gmail.com>
Tue, 18 Oct 2022 16:45:28 +0000 (11:45 -0500)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 25 Oct 2022 10:48:08 +0000 (12:48 +0200)
The res_id member of struct nfgenmsg is supposed to be in network
byte order (big endian).  Call htons() in __nftnl_nlmsg_build_hdr()
to ensure that this is true on little endian systems.

There is a kernel workaround that was introduced in 4.3 to address
this issue:

 commit a9de9777d613500b089a7416f936bf3ae5f070d2
 Author: Pablo Neira Ayuso <pablo@netfilter.org>
 Date:   Fri Aug 28 21:01:43 2015 +0200

    netfilter: nfnetlink: work around wrong endianess in res_id field

And current oldest stable kernel branch in 4.9, merge this to fix
the incorrect endianness from userspace.

Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/common.c

index 2d83c12ef99e541144b3caa06a4e738793337461..08572c3fc917fd8546635dad03cdb51a4412e168 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <sys/socket.h>
 #include <time.h>
+#include <arpa/inet.h>
 #include <linux/netlink.h>
 #include <linux/netfilter/nfnetlink.h>
 #include <linux/netfilter/nf_tables.h>
@@ -37,7 +38,7 @@ static struct nlmsghdr *__nftnl_nlmsg_build_hdr(char *buf, uint16_t type,
        nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
        nfh->nfgen_family = family;
        nfh->version = NFNETLINK_V0;
-       nfh->res_id = res_id;
+       nfh->res_id = htons(res_id);
 
        return nlh;
 }