]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
udata: Store u32 udata values in Big Endian master
authorPhil Sutter <phil@nwl.cc>
Fri, 17 Oct 2025 16:08:11 +0000 (18:08 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 27 Jan 2026 21:59:15 +0000 (22:59 +0100)
Avoid deviation of this data in between different byte orders. Assume
that direct callers of nftnl_udata_put() know what they do.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/udata.c

index a1956571ef5fd6046995c25859eb28e2ac6ab9d5..8cf4e7ca61e2fef76eec4f54b227169856b05b7f 100644 (file)
@@ -8,6 +8,7 @@
 #include <udata.h>
 #include <utils.h>
 
+#include <arpa/inet.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
@@ -100,7 +101,9 @@ EXPORT_SYMBOL(nftnl_udata_put_u32);
 bool nftnl_udata_put_u32(struct nftnl_udata_buf *buf, uint8_t type,
                         uint32_t data)
 {
-       return nftnl_udata_put(buf, type, sizeof(data), &data);
+       uint32_t data_be = htonl(data);
+
+       return nftnl_udata_put(buf, type, sizeof(data_be), &data_be);
 }
 
 EXPORT_SYMBOL(nftnl_udata_type);
@@ -128,7 +131,7 @@ uint32_t nftnl_udata_get_u32(const struct nftnl_udata *attr)
 
        memcpy(&data, attr->value, sizeof(data));
 
-       return data;
+       return ntohl(data);
 }
 
 EXPORT_SYMBOL(nftnl_udata_next);