Skip to contentSkip to conversation

xfrm: fix disable_xfrm sysctl when used on xfrm interfaces

PATCH Applied Eyal Birger 2 participants 2 messages Dec 23, 2020 – Jan 5, 2021

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

PATCH 1/1 xfrm: fix disable_xfrm sysctl when used on xfrm interfaces

The disable_xfrm flag signals that xfrm should not be performed during routing towards a device before reaching device xmit.

For xfrm interfaces this is usually desired as they perform the outbound policy lookup as part of their xmit using their if_id.

Before this change enabling this flag on xfrm interfaces prevented them from xmitting as xfrm_lookup_with_ifid() would not perform a policy lookup in case the original dst had the DST_NOXFRM flag.

This optimization is incorrect when the lookup is done by the xfrm interface xmit logic.

Fix by performing policy lookup when invoked by xfrmi as if_id != 0.

Similarly it's unlikely for the 'no policy exists on net' check to yield any performance benefits when invoked from xfrmi.

Fixes f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
---
 net/xfrm/xfrm_policy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_policy.c +2 -2
index d622c2548d22..2f84136af48a 100644
@@ -3078,8 +3078,8 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
 		xflo.flags = flags;
 
 		/* To accelerate a bit...  */
-		if ((dst_orig->flags & DST_NOXFRM) ||
-		    !net->xfrm.policy_count[XFRM_POLICY_OUT])
+		if (!if_id && ((dst_orig->flags & DST_NOXFRM) ||
+			       !net->xfrm.policy_count[XFRM_POLICY_OUT]))
 			goto nopol;
 
 		xdst = xfrm_bundle_lookup(net, fl, family, dir, &xflo, if_id);
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 13 lines · Eyal Birger

The disable_xfrm flag signals that xfrm should not be performed during routing towards a device before reaching device xmit.

For xfrm interfaces this is usually desired as they perform the outbound policy lookup as part of their xmit using their if_id.

Before this change enabling this flag on xfrm interfaces prevented them from xmitting as xfrm_lookup_with_ifid() would not perform a policy lookup in case the original dst had the DST_NOXFRM flag.

This optimization is incorrect when the lookup is done by the xfrm interface xmit logic.

Quoted 7 lines

Fix by performing policy lookup when invoked by xfrmi as if_id != 0.

Similarly it's unlikely for the 'no policy exists on net' check to yield any performance benefits when invoked from xfrmi.

Fixes f203b76d7809 ("xfrm: Add virtual xfrm interfaces")

Applied, thanks a lot Eyal!