Skip to contentSkip to conversation

netfilter: nft_fib: allow from forward/input without iif selector

PATCH Superseded Eric Garver 2 participants 5 messages May 17, 2024 – May 20, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nft_fib: allow from forward/input without iif selector

This removes the restriction of needing iif selector in the forward/input hooks for fib lookups when requested result is oif/oifname.

Removing this restriction allows "loose" lookups from the forward hooks.

---
 net/ipv4/netfilter/nft_fib_ipv4.c | 3 +--
 net/ipv6/netfilter/nft_fib_ipv6.c | 3 +--
 net/netfilter/nft_fib.c           | 8 +++-----
 3 files changed, 5 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +1 -2
index 9eee535c64dd..975a4a809058 100644
@@ -116,8 +116,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		fl4.daddr = iph->daddr;
 		fl4.saddr = get_saddr(iph->saddr);
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl4.flowi4_iif = nft_out(pkt)->ifindex;
 
 		fl4.daddr = iph->saddr;
net/ipv6/netfilter/nft_fib_ipv6.c +1 -2
index 36dc14b34388..f95e39e235d3 100644
@@ -30,8 +30,7 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
 		fl6->daddr = iph->daddr;
 		fl6->saddr = iph->saddr;
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl6->flowi6_iif = nft_out(pkt)->ifindex;
 
 		fl6->daddr = iph->saddr;
net/netfilter/nft_fib.c +3 -5
index 37cfe6dd712d..b58f62195ff3 100644
@@ -35,11 +35,9 @@ int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	switch (priv->result) {
 	case NFT_FIB_RESULT_OIF:
 	case NFT_FIB_RESULT_OIFNAME:
-		hooks = (1 << NF_INET_PRE_ROUTING);
-		if (priv->flags & NFTA_FIB_F_IIF) {
-			hooks |= (1 << NF_INET_LOCAL_IN) |
-				 (1 << NF_INET_FORWARD);
-		}
+		hooks = (1 << NF_INET_PRE_ROUTING) |
+			(1 << NF_INET_LOCAL_IN) |
+			(1 << NF_INET_FORWARD);
 		break;
 	case NFT_FIB_RESULT_ADDRTYPE:
 		if (priv->flags & NFTA_FIB_F_IIF)
Signature · 1 line
2.43.0
#1 lore raw

This is of course for nf-next, not net-next. I failed to update the subject after sending it to the wrong list.

Quoted 64 lines · Eric Garver

This removes the restriction of needing iif selector in the forward/input hooks for fib lookups when requested result is oif/oifname.

Removing this restriction allows "loose" lookups from the forward hooks.

---
 net/ipv4/netfilter/nft_fib_ipv4.c | 3 +--
 net/ipv6/netfilter/nft_fib_ipv6.c | 3 +--
 net/netfilter/nft_fib.c           | 8 +++-----
 3 files changed, 5 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +1 -2
index 9eee535c64dd..975a4a809058 100644
@@ -116,8 +116,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		fl4.daddr = iph->daddr;
 		fl4.saddr = get_saddr(iph->saddr);
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl4.flowi4_iif = nft_out(pkt)->ifindex;
 
 		fl4.daddr = iph->saddr;
net/ipv6/netfilter/nft_fib_ipv6.c +1 -2
index 36dc14b34388..f95e39e235d3 100644
@@ -30,8 +30,7 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
 		fl6->daddr = iph->daddr;
 		fl6->saddr = iph->saddr;
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl6->flowi6_iif = nft_out(pkt)->ifindex;
 
 		fl6->daddr = iph->saddr;
net/netfilter/nft_fib.c +3 -5
index 37cfe6dd712d..b58f62195ff3 100644
@@ -35,11 +35,9 @@ int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	switch (priv->result) {
 	case NFT_FIB_RESULT_OIF:
 	case NFT_FIB_RESULT_OIFNAME:
-		hooks = (1 << NF_INET_PRE_ROUTING);
-		if (priv->flags & NFTA_FIB_F_IIF) {
-			hooks |= (1 << NF_INET_LOCAL_IN) |
-				 (1 << NF_INET_FORWARD);
-		}
+		hooks = (1 << NF_INET_PRE_ROUTING) |
+			(1 << NF_INET_LOCAL_IN) |
+			(1 << NF_INET_FORWARD);
 		break;
 	case NFT_FIB_RESULT_ADDRTYPE:
 		if (priv->flags & NFTA_FIB_F_IIF)
Signature · 1 line
2.43.0
#2 lore raw

Hi Eric,

Quoted 2 lines · Eric Garver

This is of course for nf-next, not net-next. I failed to update the subject after sending it to the wrong list.

Thanks for your patch. Alternatively, I can place this in nf.git instead:

Fixes be8be04e5ddb ("netfilter: nft_fib: reverse path filter for policy-based routing on iif")
Quoted 66 lines · Eric Garver
Quoted 64 lines

This removes the restriction of needing iif selector in the forward/input hooks for fib lookups when requested result is oif/oifname.

Removing this restriction allows "loose" lookups from the forward hooks.

---
 net/ipv4/netfilter/nft_fib_ipv4.c | 3 +--
 net/ipv6/netfilter/nft_fib_ipv6.c | 3 +--
 net/netfilter/nft_fib.c           | 8 +++-----
 3 files changed, 5 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +1 -2
index 9eee535c64dd..975a4a809058 100644
@@ -116,8 +116,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		fl4.daddr = iph->daddr;
 		fl4.saddr = get_saddr(iph->saddr);
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl4.flowi4_iif = nft_out(pkt)->ifindex;
 
 		fl4.daddr = iph->saddr;
net/ipv6/netfilter/nft_fib_ipv6.c +1 -2
index 36dc14b34388..f95e39e235d3 100644
@@ -30,8 +30,7 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
 		fl6->daddr = iph->daddr;
 		fl6->saddr = iph->saddr;
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl6->flowi6_iif = nft_out(pkt)->ifindex;
 
 		fl6->daddr = iph->saddr;
net/netfilter/nft_fib.c +3 -5
index 37cfe6dd712d..b58f62195ff3 100644
@@ -35,11 +35,9 @@ int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	switch (priv->result) {
 	case NFT_FIB_RESULT_OIF:
 	case NFT_FIB_RESULT_OIFNAME:
-		hooks = (1 << NF_INET_PRE_ROUTING);
-		if (priv->flags & NFTA_FIB_F_IIF) {
-			hooks |= (1 << NF_INET_LOCAL_IN) |
-				 (1 << NF_INET_FORWARD);
-		}
+		hooks = (1 << NF_INET_PRE_ROUTING) |
+			(1 << NF_INET_LOCAL_IN) |
+			(1 << NF_INET_FORWARD);
 		break;
 	case NFT_FIB_RESULT_ADDRTYPE:
 		if (priv->flags & NFTA_FIB_F_IIF)
Signature · 1 line
2.43.0
#3 lore raw
In reply to Eric Garver

BTW, one more comment below.

Quoted 18 lines · Eric Garver

This removes the restriction of needing iif selector in the forward/input hooks for fib lookups when requested result is oif/oifname.

Removing this restriction allows "loose" lookups from the forward hooks.

---
 net/ipv4/netfilter/nft_fib_ipv4.c | 3 +--
 net/ipv6/netfilter/nft_fib_ipv6.c | 3 +--
 net/netfilter/nft_fib.c           | 8 +++-----
 3 files changed, 5 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +0 -0
index 9eee535c64dd..975a4a809058 100644

net/ipv4/netfilter/nft_fib_ipv4.c void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, · line 120

Quoted 7 lines
net/ipv4/netfilter/nft_fib_ipv4.c +1 -2
@@ -116,8 +116,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		fl4.daddr = iph->daddr;
 		fl4.saddr = get_saddr(iph->saddr);
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl4.flowi4_iif = nft_out(pkt)->ifindex;

is it intentional to remove for the priv->flags & NFTA_FIB_F_IIF here?

Maybe only the last chunk below is required?

Quoted 21 lines
net/ipv4/netfilter/nft_fib_ipv4.c +0 -0
 		fl4.daddr = iph->saddr;
net/ipv6/netfilter/nft_fib_ipv6.c +1 -2
index 36dc14b34388..f95e39e235d3 100644
@@ -30,8 +30,7 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
 		fl6->daddr = iph->daddr;
 		fl6->saddr = iph->saddr;
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl6->flowi6_iif = nft_out(pkt)->ifindex;
 
 		fl6->daddr = iph->saddr;
net/netfilter/nft_fib.c +0 -0
index 37cfe6dd712d..b58f62195ff3 100644
@@ -35,11 +35,9 @@ int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	switch (priv->result) {

net/netfilter/nft_fib.c int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr, · line 40

Quoted 10 lines
net/netfilter/nft_fib.c +3 -5
 	case NFT_FIB_RESULT_OIF:
 	case NFT_FIB_RESULT_OIFNAME:
-		hooks = (1 << NF_INET_PRE_ROUTING);
-		if (priv->flags & NFTA_FIB_F_IIF) {
-			hooks |= (1 << NF_INET_LOCAL_IN) |
-				 (1 << NF_INET_FORWARD);
-		}
+		hooks = (1 << NF_INET_PRE_ROUTING) |
+			(1 << NF_INET_LOCAL_IN) |
+			(1 << NF_INET_FORWARD);

I mean: This chunk alone to remove the hook restriction should be good?

Thanks.

Quoted 6 lines
net/netfilter/nft_fib.c +0 -0
 		break;
 	case NFT_FIB_RESULT_ADDRTYPE:
 		if (priv->flags & NFTA_FIB_F_IIF)
Signature · 1 line
2.43.0
#4 lore raw
Quoted 58 lines · Pablo Neira Ayuso

BTW, one more comment below.

Quoted 18 lines · Eric Garver

This removes the restriction of needing iif selector in the forward/input hooks for fib lookups when requested result is oif/oifname.

Removing this restriction allows "loose" lookups from the forward hooks.

---
 net/ipv4/netfilter/nft_fib_ipv4.c | 3 +--
 net/ipv6/netfilter/nft_fib_ipv6.c | 3 +--
 net/netfilter/nft_fib.c           | 8 +++-----
 3 files changed, 5 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +0 -0
index 9eee535c64dd..975a4a809058 100644

net/ipv4/netfilter/nft_fib_ipv4.c void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, · line 120

Quoted 7 lines
net/ipv4/netfilter/nft_fib_ipv4.c +1 -2
@@ -116,8 +116,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		fl4.daddr = iph->daddr;
 		fl4.saddr = get_saddr(iph->saddr);
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl4.flowi4_iif = nft_out(pkt)->ifindex;

is it intentional to remove for the priv->flags & NFTA_FIB_F_IIF here?

Maybe only the last chunk below is required?

Quoted 25 lines
net/ipv4/netfilter/nft_fib_ipv4.c +0 -0
 		fl4.daddr = iph->saddr;
net/ipv6/netfilter/nft_fib_ipv6.c +1 -2
index 36dc14b34388..f95e39e235d3 100644
@@ -30,8 +30,7 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
 		fl6->daddr = iph->daddr;
 		fl6->saddr = iph->saddr;
 	} else {
-		if (nft_hook(pkt) == NF_INET_FORWARD &&
-		    priv->flags & NFTA_FIB_F_IIF)
+		if (nft_hook(pkt) == NF_INET_FORWARD)
 			fl6->flowi6_iif = nft_out(pkt)->ifindex;
 
 		fl6->daddr = iph->saddr;
net/netfilter/nft_fib.c +0 -2
index 37cfe6dd712d..b58f62195ff3 100644
@@ -35,11 +35,9 @@ int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	switch (priv->result) {
 	case NFT_FIB_RESULT_OIF:
 	case NFT_FIB_RESULT_OIFNAME:
-		hooks = (1 << NF_INET_PRE_ROUTING);
-		if (priv->flags & NFTA_FIB_F_IIF) {
Quoted 8 lines

net/netfilter/nft_fib.c int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr, · line 40

Quoted 6 lines
net/netfilter/nft_fib.c +3 -3
-			hooks |= (1 << NF_INET_LOCAL_IN) |
-				 (1 << NF_INET_FORWARD);
-		}
+		hooks = (1 << NF_INET_PRE_ROUTING) |
+			(1 << NF_INET_LOCAL_IN) |
+			(1 << NF_INET_FORWARD);

I mean: This chunk alone to remove the hook restriction should be good?

ACK. I'll retest and post a v2.