Byteorder may be different in each field of reg->val array. Pass a 16bit value where each bit indicates the field value at same offset is in network byte order. Signed-off-by: Phil Sutter <phil@xxxxxx> --- src/expr/data_reg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c index 789958ea66c0d..289443b47f9d6 100644 --- a/src/expr/data_reg.c +++ b/src/expr/data_reg.c @@ -27,8 +27,7 @@ static int nftnl_data_reg_value_snprintf_default(char *buf, size_t remain, const union nftnl_data_reg *reg, - uint32_t flags, - enum nftnl_byteorder byteorder) + uint32_t flags, uint16_t byteorder_bits) { const char *pfx = flags & DATA_F_NOPFX ? "" : "0x"; int offset = 0, ret, i; @@ -37,7 +36,7 @@ nftnl_data_reg_value_snprintf_default(char *buf, size_t remain, for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { - if (byteorder == NFTNL_BYTEORDER_NETWORK) + if (byteorder_bits & (1 << i)) value = ntohl(reg->val[i]); else value = reg->val[i]; @@ -72,11 +71,13 @@ int nftnl_data_reg_snprintf(char *buf, size_t size, uint32_t flags, int reg_type, enum nftnl_byteorder byteorder) { + uint16_t byteorder_bits = byteorder == NFTNL_BYTEORDER_NETWORK ? -1 : 0; + switch(reg_type) { case DATA_VALUE: return nftnl_data_reg_value_snprintf_default(buf, size, reg, flags, - byteorder); + byteorder_bits); case DATA_VERDICT: case DATA_CHAIN: return nftnl_data_reg_verdict_snprintf_def(buf, size, -- 2.33.0