Skip to contentSkip to conversation

netfilter: nft_fib: convert htonl to ntohl properly

PATCH Applied Liping Zhang 3 participants 6 messages Nov 23, 2016 – Dec 4, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nft_fib: convert htonl to ntohl properly

From: Liping Zhang <[email protected]>

Acctually ntohl and htonl are identical, so this doesn't affect anything, but it is conceptually wrong.

---
 net/ipv4/netfilter/nft_fib_ipv4.c | 2 +-
 net/ipv6/netfilter/nft_fib_ipv6.c | 2 +-
 net/netfilter/nft_fib.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +1 -1
index 1b49966..bfffa74 100644
@@ -198,7 +198,7 @@ nft_fib4_select_ops(const struct nft_ctx *ctx,
 	if (!tb[NFTA_FIB_RESULT])
 		return ERR_PTR(-EINVAL);
 
-	result = htonl(nla_get_be32(tb[NFTA_FIB_RESULT]));
+	result = ntohl(nla_get_be32(tb[NFTA_FIB_RESULT]));
 
 	switch (result) {
 	case NFT_FIB_RESULT_OIF:
net/ipv6/netfilter/nft_fib_ipv6.c +1 -1
index d526bb5..c947aad 100644
@@ -235,7 +235,7 @@ nft_fib6_select_ops(const struct nft_ctx *ctx,
 	if (!tb[NFTA_FIB_RESULT])
 		return ERR_PTR(-EINVAL);
 
-	result = htonl(nla_get_be32(tb[NFTA_FIB_RESULT]));
+	result = ntohl(nla_get_be32(tb[NFTA_FIB_RESULT]));
 
 	switch (result) {
 	case NFT_FIB_RESULT_OIF:
net/netfilter/nft_fib.c +1 -1
index 249c9b8..29a4906 100644
@@ -86,7 +86,7 @@ int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	if ((priv->flags & (NFTA_FIB_F_SADDR | NFTA_FIB_F_DADDR)) == 0)
 		return -EINVAL;
 
-	priv->result = htonl(nla_get_be32(tb[NFTA_FIB_RESULT]));
+	priv->result = ntohl(nla_get_be32(tb[NFTA_FIB_RESULT]));
 	priv->dreg = nft_parse_register(tb[NFTA_FIB_DREG]);
 
 	switch (priv->result) {
Signature · 1 line
2.5.5
#1 lore raw

PATCH 1/1 netfilter: nft_fib_ipv4: initialize *dest to zero

From: Liping Zhang <[email protected]>

Otherwise, if fib lookup fail, *dest will be filled with garbage value, so reverse path filtering will not work properly:

 # nft add rule x prerouting fib saddr oif eq 0 drop
Fixes f6d0cbcf09c5 ("netfilter: nf_tables: add fib expression")
---
 net/ipv4/netfilter/nft_fib_ipv4.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/netfilter/nft_fib_ipv4.c +2 -0
index bfffa74..2581363 100644
@@ -122,6 +122,8 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		fl4.saddr = get_saddr(iph->daddr);
 	}
 
+	*dest = 0;
+
 	if (fib_lookup(nft_net(pkt), &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE))
 		return;
 
Signature · 1 line
2.5.5
maintainer Acked-by on v1 1/1
#2 lore raw

Re: [PATCH nf-next] netfilter: nft_fib_ipv4: initialize *dest to zero

Quoted 8 lines · Liping Zhang

From: Liping Zhang <[email protected]>

Otherwise, if fib lookup fail, *dest will be filled with garbage value, so reverse path filtering will not work properly:

 # nft add rule x prerouting fib saddr oif eq 0 drop
Fixes f6d0cbcf09c5 ("netfilter: nf_tables: add fib expression")
#3 lore raw

Re: [PATCH nf-next] netfilter: nft_fib_ipv4: initialize *dest to zero

In reply to Liping Zhang
Quoted 5 lines · Liping Zhang

From: Liping Zhang <[email protected]>

Otherwise, if fib lookup fail, *dest will be filled with garbage value, so reverse path filtering will not work properly:

 # nft add rule x prerouting fib saddr oif eq 0 drop

Also applied, thanks.