xfrm: Use xfrm_ip2inner_mode() unconditionally
Subsystems (4)
PATCH v3 1/1 xfrm: Use xfrm_ip2inner_mode() unconditionally
Commit c9500d7b7de8 ("xfrm: store xfrm_mode directly, not its address") changed how the xfrm_mode is stored in the xfrm state. The inner_mode NULL check is redundant as xfrm_ip2inner_mode() now returns the address of an embedded structure, which cannot be NULL.
Additionally, commit 61fafbee6cfe ("xfrm: Determine inner GSO type from packet inner protocol") updated xfrm_ip2inner_mode() to explicitly check x->sel.family. If the selector family is specified (i.e., not AF_UNSPEC), the helper now correctly returns &x->inner_mode directly.
This means the manual branching which checked for AF_UNSPEC before deciding whether to call the helper or use the state's inner mode directly is no longer necessary.
This patch simplifies the code by calling xfrm_ip2inner_mode() unconditionally and removing the NULL checking.
---
V3:
- Change the commit subject (was "xfrm: Remove redundant state inner mode check").
- Call xfrm_ip2inner_mode() unconditionally and update the commit message accordingly.
V2:
- Change subject prefix, and send separately to "ipsec-next".
net/ipv4/ip_vti.c | 11 +---------- net/ipv6/ip6_vti.c | 11 +---------- net/xfrm/xfrm_interface_core.c | 11 +---------- net/xfrm/xfrm_policy.c | 11 +---------- 4 files changed, 4 insertions(+), 40 deletions(-)
net/ipv4/ip_vti.c +1 -10
@@ -118,16 +118,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err) x =xfrm_input_state (skb); - inner_mode = &x->inner_mode; - -if (x->sel.family ==AF_UNSPEC ) { - inner_mode =xfrm_ip2inner_mode (x,XFRM_MODE_SKB_CB (skb)->protocol); -if (inner_mode ==NULL ) { -XFRM_INC_STATS (dev_net (skb->dev), -LINUX_MIB_XFRMINSTATEMODEERROR ); -return -EINVAL ; - } - } + inner_mode =xfrm_ip2inner_mode (x,XFRM_MODE_SKB_CB (skb)->protocol); family = inner_mode->family;
net/ipv6/ip6_vti.c +1 -10
@@ -362,16 +362,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err) x =xfrm_input_state (skb); - inner_mode = &x->inner_mode; - -if (x->sel.family ==AF_UNSPEC ) { - inner_mode =xfrm_ip2inner_mode (x,XFRM_MODE_SKB_CB (skb)->protocol); -if (inner_mode ==NULL ) { -XFRM_INC_STATS (dev_net (skb->dev), -LINUX_MIB_XFRMINSTATEMODEERROR ); -return -EINVAL ; - } - } + inner_mode =xfrm_ip2inner_mode (x,XFRM_MODE_SKB_CB (skb)->protocol); family = inner_mode->family;
net/xfrm/xfrm_interface_core.c +1 -10
@@ -387,16 +387,7 @@ static int xfrmi_rcv_cb(struct sk_buff *skb, int err) xnet = !net_eq (xi->net,dev_net (skb->dev));if (xnet) { - inner_mode = &x->inner_mode; - -if (x->sel.family ==AF_UNSPEC ) { - inner_mode =xfrm_ip2inner_mode (x,XFRM_MODE_SKB_CB (skb)->protocol); -if (inner_mode ==NULL ) { -XFRM_INC_STATS (dev_net (skb->dev), -LINUX_MIB_XFRMINSTATEMODEERROR ); -return -EINVAL ; - } - } + inner_mode =xfrm_ip2inner_mode (x,XFRM_MODE_SKB_CB (skb)->protocol);if (!xfrm_policy_check (NULL ,XFRM_POLICY_IN , skb, inner_mode->family))
net/xfrm/xfrm_policy.c +1 -10
@@ -2711,16 +2711,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,*/ xfrm_dst_set_child (xdst_prev, &xdst->u.dst); -if (xfrm[i]->sel.family ==AF_UNSPEC ) { - inner_mode =xfrm_ip2inner_mode (xfrm[i], -xfrm_af2proto (family)); -if (!inner_mode) { - err = -EAFNOSUPPORT ; -dst_release (dst); - goto put_states; - } - }else - inner_mode = &xfrm[i]->inner_mode; + inner_mode =xfrm_ip2inner_mode (xfrm[i],xfrm_af2proto (family)); xdst->route = dst;dst_copy_metrics (dst1, dst);
Signature · 1 line
2.49.0
Quoted 10 lines · Jianbo Liu
Commit
c9500d7b7de8("xfrm: storexfrm_modedirectly, not its address") changed how thexfrm_modeis stored in the xfrm state. Theinner_modeNULL check is redundant asxfrm_ip2inner_mode()now returns the address of an embedded structure, which cannot be NULL.Additionally, commit
61fafbee6cfe("xfrm: Determine inner GSO type from packet inner protocol") updatedxfrm_ip2inner_mode()to explicitly checkx->sel.family. If the selector family is specified (i.e., notAF_UNSPEC), the helper now correctly returns&x->inner_modedirectly.
Note: that commit is not in ipsec-next yet, only in ipsec. This patch should only be applied to ipsec-next once the trees have been merged together.
Quoted 7 lines
This means the manual branching which checked for
AF_UNSPECbefore deciding whether to call the helper or use the state's inner mode directly is no longer necessary.This patch simplifies the code by calling
xfrm_ip2inner_mode()unconditionally and removing the NULL checking.
Quoted 6 lines
Signed-off-by Jianbo Liu <[email protected]>Reviewed-by Cosmin Ratiu <[email protected]>---
V3:
- Change the commit subject (was "xfrm: Remove redundant state inner mode check").
- Callxfrm_ip2inner_mode()unconditionally and update the commit message accordingly.
Other than the tree scheduling comment above, the patch looks ok, thanks.
Signature · 1 line
Sabrina