Skip to contentSkip to conversation

xfrm: remove three xfrm_afinfo_policy indirections

PATCH In review Florian Westphal 2 participants 5 messages Apr 16, 2019 – Apr 24, 2019

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

cover xfrm: remove three xfrm_afinfo_policy indirections

This series removes three indirections from xfrm_afinfo_policy by folding them into their callers.

1. Tos is a one-liner only needed by ipv4
2. init_path is also small and only needed by ipv6
3. decode_session has no dependencies on ipv6 or ipv4, fold it.

The remaining indirections are necessary in the CONFIG_IPV6=m case. Its possible to fold only the ipv4 part and handle ipv6 based on CONFIG_IPV6_{MODULE,BUILTIN} but that increases complexity, so my intent is to go after indirections similar to the ones folded here first.

Florian Westphal (3):
xfrm: remove tos indirection from afinfo_policy
xfrm: remove init_path indirection from afinfo_policy
xfrm: remove decode_session indirection from afinfo_policy

 include/net/xfrm.h      |    7 -
 net/ipv4/xfrm4_policy.c |  127 ----------------------
 net/ipv6/xfrm6_policy.c |  126 ----------------------
 net/xfrm/xfrm_policy.c  |  266 +++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 232 insertions(+), 294 deletions(-)
#1 lore raw

PATCH 1/3 xfrm: remove tos indirection from afinfo_policy

Only used by ipv4, we can read the fl4 tos value directly instead.

---
 include/net/xfrm.h      |  1 -
 net/ipv4/xfrm4_policy.c |  6 ------
 net/ipv6/xfrm6_policy.c |  6 ------
 net/xfrm/xfrm_policy.c  | 14 +++-----------
 4 files changed, 3 insertions(+), 24 deletions(-)
include/net/xfrm.h +0 -1
index 77eb578a0384..652da5861772 100644
@@ -329,7 +329,6 @@ struct xfrm_policy_afinfo {
 	void			(*decode_session)(struct sk_buff *skb,
 						  struct flowi *fl,
 						  int reverse);
-	int			(*get_tos)(const struct flowi *fl);
 	int			(*init_path)(struct xfrm_dst *path,
 					     struct dst_entry *dst,
 					     int nfheader_len);
net/ipv4/xfrm4_policy.c +0 -6
index d73a6d6652f6..244d26baa3af 100644
@@ -69,11 +69,6 @@ static int xfrm4_get_saddr(struct net *net, int oif,
 	return 0;
 }
 
-static int xfrm4_get_tos(const struct flowi *fl)
-{
-	return IPTOS_RT_MASK & fl->u.ip4.flowi4_tos; /* Strip ECN bits */
-}
-
 static int xfrm4_init_path(struct xfrm_dst *path, struct dst_entry *dst,
 			   int nfheader_len)
 {
@@ -272,7 +267,6 @@ static const struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
 	.dst_lookup =		xfrm4_dst_lookup,
 	.get_saddr =		xfrm4_get_saddr,
 	.decode_session =	_decode_session4,
-	.get_tos =		xfrm4_get_tos,
 	.init_path =		xfrm4_init_path,
 	.fill_dst =		xfrm4_fill_dst,
 	.blackhole_route =	ipv4_blackhole_route,
net/ipv6/xfrm6_policy.c +0 -6
index 769f8f78d3b8..0e92fa2f9678 100644
@@ -71,11 +71,6 @@ static int xfrm6_get_saddr(struct net *net, int oif,
 	return 0;
 }
 
-static int xfrm6_get_tos(const struct flowi *fl)
-{
-	return 0;
-}
-
 static int xfrm6_init_path(struct xfrm_dst *path, struct dst_entry *dst,
 			   int nfheader_len)
 {
@@ -292,7 +287,6 @@ static const struct xfrm_policy_afinfo xfrm6_policy_afinfo = {
 	.dst_lookup =		xfrm6_dst_lookup,
 	.get_saddr =		xfrm6_get_saddr,
 	.decode_session =	_decode_session6,
-	.get_tos =		xfrm6_get_tos,
 	.init_path =		xfrm6_init_path,
 	.fill_dst =		xfrm6_fill_dst,
 	.blackhole_route =	ip6_blackhole_route,
net/xfrm/xfrm_policy.c +3 -11
index 16e70fc547b1..1d1335eab76c 100644
@@ -2450,18 +2450,10 @@ xfrm_tmpl_resolve(struct xfrm_policy **pols, int npols, const struct flowi *fl,
 
 static int xfrm_get_tos(const struct flowi *fl, int family)
 {
-	const struct xfrm_policy_afinfo *afinfo;
-	int tos;
-
-	afinfo = xfrm_policy_get_afinfo(family);
-	if (!afinfo)
-		return 0;
-
-	tos = afinfo->get_tos(fl);
+	if (family == AF_INET)
+		return IPTOS_RT_MASK & fl->u.ip4.flowi4_tos;
 
-	rcu_read_unlock();
-
-	return tos;
+	return 0;
 }
 
 static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/3 xfrm: remove init_path indirection from afinfo_policy

In reply to Florian Westphal

handle this directly, its only used by ipv6.

---
 include/net/xfrm.h      |  3 ---
 net/ipv4/xfrm4_policy.c |  7 -------
 net/ipv6/xfrm6_policy.c | 14 --------------
 net/xfrm/xfrm_policy.c  | 21 +++++++--------------
 4 files changed, 7 insertions(+), 38 deletions(-)
include/net/xfrm.h +0 -3
index 652da5861772..b8de1622141a 100644
@@ -329,9 +329,6 @@ struct xfrm_policy_afinfo {
 	void			(*decode_session)(struct sk_buff *skb,
 						  struct flowi *fl,
 						  int reverse);
-	int			(*init_path)(struct xfrm_dst *path,
-					     struct dst_entry *dst,
-					     int nfheader_len);
 	int			(*fill_dst)(struct xfrm_dst *xdst,
 					    struct net_device *dev,
 					    const struct flowi *fl);
net/ipv4/xfrm4_policy.c +0 -7
index 244d26baa3af..6e89378668ae 100644
@@ -69,12 +69,6 @@ static int xfrm4_get_saddr(struct net *net, int oif,
 	return 0;
 }
 
-static int xfrm4_init_path(struct xfrm_dst *path, struct dst_entry *dst,
-			   int nfheader_len)
-{
-	return 0;
-}
-
 static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
 			  const struct flowi *fl)
 {
@@ -267,7 +261,6 @@ static const struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
 	.dst_lookup =		xfrm4_dst_lookup,
 	.get_saddr =		xfrm4_get_saddr,
 	.decode_session =	_decode_session4,
-	.init_path =		xfrm4_init_path,
 	.fill_dst =		xfrm4_fill_dst,
 	.blackhole_route =	ipv4_blackhole_route,
 };
net/ipv6/xfrm6_policy.c +0 -14
index 0e92fa2f9678..358e834fedce 100644
@@ -71,19 +71,6 @@ static int xfrm6_get_saddr(struct net *net, int oif,
 	return 0;
 }
 
-static int xfrm6_init_path(struct xfrm_dst *path, struct dst_entry *dst,
-			   int nfheader_len)
-{
-	if (dst->ops->family == AF_INET6) {
-		struct rt6_info *rt = (struct rt6_info *)dst;
-		path->path_cookie = rt6_get_cookie(rt);
-	}
-
-	path->u.rt6.rt6i_nfheader_len = nfheader_len;
-
-	return 0;
-}
-
 static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
 			  const struct flowi *fl)
 {
@@ -287,7 +274,6 @@ static const struct xfrm_policy_afinfo xfrm6_policy_afinfo = {
 	.dst_lookup =		xfrm6_dst_lookup,
 	.get_saddr =		xfrm6_get_saddr,
 	.decode_session =	_decode_session6,
-	.init_path =		xfrm6_init_path,
 	.fill_dst =		xfrm6_fill_dst,
 	.blackhole_route =	ip6_blackhole_route,
 };
net/xfrm/xfrm_policy.c +7 -14
index 1d1335eab76c..5359c312f016 100644
@@ -2491,21 +2491,14 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
 	return xdst;
 }
 
-static inline int xfrm_init_path(struct xfrm_dst *path, struct dst_entry *dst,
-				 int nfheader_len)
+static void xfrm_init_path(struct xfrm_dst *path, struct dst_entry *dst,
+			   int nfheader_len)
 {
-	const struct xfrm_policy_afinfo *afinfo =
-		xfrm_policy_get_afinfo(dst->ops->family);
-	int err;
-
-	if (!afinfo)
-		return -EINVAL;
-
-	err = afinfo->init_path(path, dst, nfheader_len);
-
-	rcu_read_unlock();
-
-	return err;
+	if (dst->ops->family == AF_INET6) {
+		struct rt6_info *rt = (struct rt6_info *)dst;
+		path->path_cookie = rt6_get_cookie(rt);
+		path->u.rt6.rt6i_nfheader_len = nfheader_len;
+	}
 }
 
 static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
Signature · 1 line
2.21.0
#3 lore raw

PATCH 3/3 xfrm: remove decode_session indirection from afinfo_policy

In reply to Florian Westphal

No external dependencies, might as well handle this directly. xfrm_afinfo_policy is now 40 bytes on x86_64.

---
 include/net/xfrm.h      |   3 -
 net/ipv4/xfrm4_policy.c | 114 --------------------
 net/ipv6/xfrm6_policy.c | 106 ------------------
 net/xfrm/xfrm_policy.c  | 231 ++++++++++++++++++++++++++++++++++++++--
 4 files changed, 222 insertions(+), 232 deletions(-)
include/net/xfrm.h +0 -3
index b8de1622141a..18d6b33501b9 100644
@@ -326,9 +326,6 @@ struct xfrm_policy_afinfo {
 					     xfrm_address_t *saddr,
 					     xfrm_address_t *daddr,
 					     u32 mark);
-	void			(*decode_session)(struct sk_buff *skb,
-						  struct flowi *fl,
-						  int reverse);
 	int			(*fill_dst)(struct xfrm_dst *xdst,
 					    struct net_device *dev,
 					    const struct flowi *fl);
net/ipv4/xfrm4_policy.c +0 -114

132 lines not on this page · raw message

net/ipv6/xfrm6_policy.c +0 -106

124 lines not on this page · raw message

net/xfrm/xfrm_policy.c +222 -9

252 lines not on this page · raw message

Signature · 1 line
2.21.0
maintainer
#4 lore raw
In reply to Florian Westphal
Quoted 14 lines · Florian Westphal

This series removes three indirections from xfrm_afinfo_policy by folding them into their callers.

1. Tos is a one-liner only needed by ipv4
2. init_path is also small and only needed by ipv6
3. decode_session has no dependencies on ipv6 or ipv4, fold it.

The remaining indirections are necessary in the CONFIG_IPV6=m case. Its possible to fold only the ipv4 part and handle ipv6 based on CONFIG_IPV6_{MODULE,BUILTIN} but that increases complexity, so my intent is to go after indirections similar to the ones folded here first.

Quoted 4 lines

Florian Westphal (3):
xfrm: remove tos indirection from afinfo_policy
xfrm: remove init_path indirection from afinfo_policy
xfrm: remove decode_session indirection from afinfo_policy

Series applied, thanks a lot Florian!