nftnlrdr_misc.c: fix parse_rule_immediate()

so it works correctly on both little endian and big endian CPUs
should fix #628
This commit is contained in:
Thomas Bernard 2022-10-10 02:05:47 +02:00
parent 8bbe1c1339
commit 890e4ec218
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
2 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,8 @@
$Id: Changelog.txt,v 1.489 2022/06/01 23:21:11 nanard Exp $
2022/10/10:
NFTables : fix for Big Endian. iport was always read as 0
2022/08/06:
Fixes DeletePCPMap() for "IPv6 pinholes" with netfilter_nftables backend

View File

@ -217,9 +217,21 @@ parse_rule_immediate(struct nftnl_expr *e, rule_t *r)
if (dreg == NFT_REG_VERDICT) {
reg_val = nftnl_expr_get_u32(e, NFTNL_EXPR_IMM_VERDICT);
} else {
reg_val = *(uint32_t *)nftnl_expr_get(e,
NFTNL_EXPR_IMM_DATA,
&reg_len);
const void * p = nftnl_expr_get(e, NFTNL_EXPR_IMM_DATA, &reg_len);
if (p == NULL) {
log_error("nftnl_expr_get() failed for reg:%u", dreg);
return;
} else switch(reg_len) {
case sizeof(uint32_t):
reg_val = *(const uint32_t *)p;
break;
case sizeof(uint16_t):
reg_val = *(const uint16_t *)p;
break;
default:
log_error("nftnl_expr_get() reg_len=%u", reg_len);
return;
}
}
set_reg(r, dreg, RULE_REG_IMM_VAL, reg_val);