Skip to contentSkip to conversation

ipv4: Remove flowi from struct rtable.

PATCH In review David Miller 2 participants 4 messages Mar 5, 2011 – Mar 9, 2011

Subsystems (5)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 1/1 ipv4: Remove flowi from struct rtable.

The only necessary parts are the src/dst addresses, the interface indexes, the TOS, and the mark.

The rest is unnecessary bloat, which amounts to nearly 50 bytes on 64-bit.

---
 include/net/route.h     |   22 ++++---
 net/ipv4/icmp.c         |    2 +-
 net/ipv4/ipmr.c         |   52 +++++++++++++----
 net/ipv4/route.c        |  153 +++++++++++++++++++++++++---------------------
 net/ipv4/xfrm4_policy.c |    7 ++-
 net/sched/cls_route.c   |    2 +-
 net/sched/em_meta.c     |    2 +-
 7 files changed, 146 insertions(+), 94 deletions(-)
include/net/route.h +13 -9
index 8905d90..9257f5f 100644
@@ -53,16 +53,20 @@ struct fib_info;
 struct rtable {
 	struct dst_entry	dst;
 
-	/* Cache lookup keys */
-	struct flowi		fl;
+	/* Lookup key. */
+	__be32			rt_key_dst;
+	__be32			rt_key_src;
 
 	int			rt_genid;
 	unsigned		rt_flags;
 	__u16			rt_type;
+	__u8			rt_tos;
 
 	__be32			rt_dst;	/* Path destination	*/
 	__be32			rt_src;	/* Path source		*/
 	int			rt_iif;
+	int			rt_oif;
+	__u32			rt_mark;
 
 	/* Info on neighbour */
 	__be32			rt_gateway;
@@ -76,12 +80,12 @@ struct rtable {
 
 static inline bool rt_is_input_route(struct rtable *rt)
 {
-	return rt->fl.iif != 0;
+	return rt->rt_iif != 0;
 }
 
 static inline bool rt_is_output_route(struct rtable *rt)
 {
-	return rt->fl.iif == 0;
+	return rt->rt_iif == 0;
 }
 
 struct ip_rt_acct {
@@ -212,11 +216,11 @@ static inline struct rtable *ip_route_newports(struct rtable *rt,
 					       __be16 dport, struct sock *sk)
 {
 	if (sport != orig_sport || dport != orig_dport) {
-		struct flowi fl = { .oif = rt->fl.oif,
-				    .mark = rt->fl.mark,
-				    .fl4_dst = rt->fl.fl4_dst,
-				    .fl4_src = rt->fl.fl4_src,
-				    .fl4_tos = rt->fl.fl4_tos,
+		struct flowi fl = { .oif = rt->rt_oif,
+				    .mark = rt->rt_mark,
+				    .fl4_dst = rt->rt_key_dst,
+				    .fl4_src = rt->rt_key_src,
+				    .fl4_tos = rt->rt_tos,
 				    .proto = protocol,
 				    .fl_ip_sport = sport,
 				    .fl_ip_dport = dport };
net/ipv4/icmp.c +1 -1
index 994a785..1771ce6 100644
@@ -563,7 +563,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
 		rcu_read_lock();
 		if (rt_is_input_route(rt) &&
 		    net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr)
-			dev = dev_get_by_index_rcu(net, rt->fl.iif);
+			dev = dev_get_by_index_rcu(net, rt->rt_iif);
 
 		if (dev)
 			saddr = inet_select_addr(dev, 0, RT_SCOPE_LINK);
net/ipv4/ipmr.c +41 -11

71 lines not on this page · raw message

net/ipv4/route.c +83 -70

330 lines not on this page · raw message

net/ipv4/xfrm4_policy.c +6 -1
index 45b8214..c70c42e 100644
@@ -70,7 +70,12 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
 {
 	struct rtable *rt = (struct rtable *)xdst->route;
 
-	xdst->u.rt.fl = *fl;
+	rt->rt_key_dst = fl->fl4_dst;
+	rt->rt_key_src = fl->fl4_src;
+	rt->rt_tos = fl->fl4_tos;
+	rt->rt_iif = fl->iif;
+	rt->rt_oif = fl->oif;
+	rt->rt_mark = fl->mark;
 
 	xdst->u.dst.dev = dev;
 	dev_hold(dev);
net/sched/cls_route.c +1 -1
index d580cdf..a9079053 100644
@@ -143,7 +143,7 @@ static int route4_classify(struct sk_buff *skb, struct tcf_proto *tp,
 	if (head == NULL)
 		goto old_method;
 
-	iif = ((struct rtable *)dst)->fl.iif;
+	iif = ((struct rtable *)dst)->rt_iif;
 
 	h = route4_fastmap_hash(id, iif);
 	if (id == head->fastmap[h].id &&
net/sched/em_meta.c +1 -1
index e5e1747..a4de67e 100644
@@ -264,7 +264,7 @@ META_COLLECTOR(int_rtiif)
 	if (unlikely(skb_rtable(skb) == NULL))
 		*err = -1;
 	else
-		dst->value = skb_rtable(skb)->fl.iif;
+		dst->value = skb_rtable(skb)->rt_iif;
 }
 
 /**************************************************************************
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 11 lines · David Miller

The only necessary parts are the src/dst addresses, the interface indexes, the TOS, and the mark.

The rest is unnecessary bloat, which amounts to nearly 50 bytes on 64-bit.

---

net/ipv4/ipmr.c int ip_mr_input(struct sk_buff *skb) · line 1825

Quoted 9 lines
net/ipv4/ipmr.c +9 -0
+		struct rtable *rt = skb_rtable(skb);
+		struct flowi fl = {
+			.fl4_dst = rt->rt_key_dst,
+			.fl4_src = rt->rt_key_src,
+			.fl4_tos = rt->rt_tos,
+			.oif = rt->rt_oif,
+			.iif = rt->rt_iif,
+			.mark = rt->rt_mark,
+		};

Eventually we could have a helper for this, as this is done three times in this file. Or maybe you have further plans for ipmr ?

author maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Sat, 05 Mar 2011 07:59:48 +0100

Quoted 2 lines

Eventually we could have a helper for this, as this is done three times in this file. Or maybe you have further plans for ipmr ?

No immediate plans, so yes I'll make a helper, good idea.

author maintainer
#3 lore raw

From: David Miller <[email protected]>
Date: Fri, 04 Mar 2011 23:09:14 -0800 (PST)

Quoted 7 lines

From: Eric Dumazet <[email protected]>
Date: Sat, 05 Mar 2011 07:59:48 +0100

Quoted 2 lines

Eventually we could have a helper for this, as this is done three times in this file. Or maybe you have further plans for ipmr ?

No immediate plans, so yes I'll make a helper, good idea.

Sorry for taking so long on this, I just added the following to net-next-2.6:

--------------------
ipv4: Lookup multicast routes by rtable using helper.

Create a common helper for this operation, since we do it identically in three spots.

Suggested by Eric Dumazet.

---
 net/ipv4/ipmr.c |   70 ++++++++++++++++++++++---------------------------------
 1 files changed, 28 insertions(+), 42 deletions(-)
net/ipv4/ipmr.c +28 -42
index 9d5f634..74909ba 100644
@@ -1793,6 +1793,24 @@ dont_forward:
 	return 0;
 }
 
+static struct mr_table *ipmr_rt_fib_lookup(struct net *net, struct rtable *rt)
+{
+	struct flowi fl = {
+		.fl4_dst = rt->rt_key_dst,
+		.fl4_src = rt->rt_key_src,
+		.fl4_tos = rt->rt_tos,
+		.oif = rt->rt_oif,
+		.iif = rt->rt_iif,
+		.mark = rt->rt_mark,
+	};
+	struct mr_table *mrt;
+	int err;
+
+	err = ipmr_fib_lookup(net, &fl, &mrt);
+	if (err)
+		return ERR_PTR(err);
+	return mrt;
+}
 
 /*
  *	Multicast packets for forwarding arrive here
@@ -1805,7 +1823,6 @@ int ip_mr_input(struct sk_buff *skb)
 	struct net *net = dev_net(skb->dev);
 	int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL;
 	struct mr_table *mrt;
-	int err;
 
 	/* Packet is looped back after forward, it should not be
 	 * forwarded second time, but still can be delivered locally.
@@ -1813,21 +1830,10 @@ int ip_mr_input(struct sk_buff *skb)
 	if (IPCB(skb)->flags & IPSKB_FORWARDED)
 		goto dont_forward;
 
-	{
-		struct rtable *rt = skb_rtable(skb);
-		struct flowi fl = {
-			.fl4_dst = rt->rt_key_dst,
-			.fl4_src = rt->rt_key_src,
-			.fl4_tos = rt->rt_tos,
-			.oif = rt->rt_oif,
-			.iif = rt->rt_iif,
-			.mark = rt->rt_mark,
-		};
-		err = ipmr_fib_lookup(net, &fl, &mrt);
-		if (err < 0) {
-			kfree_skb(skb);
-			return err;
-		}
+	mrt = ipmr_rt_fib_lookup(net, skb_rtable(skb));
+	if (IS_ERR(mrt)) {
+		kfree_skb(skb);
+		return PTR_ERR(mrt);
 	}
 	if (!local) {
 		if (IPCB(skb)->opt.router_alert) {
@@ -1956,19 +1962,9 @@ int pim_rcv_v1(struct sk_buff *skb)
 
 	pim = igmp_hdr(skb);
 
-	{
-		struct rtable *rt = skb_rtable(skb);
-		struct flowi fl = {
-			.fl4_dst = rt->rt_key_dst,
-			.fl4_src = rt->rt_key_src,
-			.fl4_tos = rt->rt_tos,
-			.oif = rt->rt_oif,
-			.iif = rt->rt_iif,
-			.mark = rt->rt_mark,
-		};
-		if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
-			goto drop;
-	}
+	mrt = ipmr_rt_fib_lookup(net, skb_rtable(skb));
+	if (IS_ERR(mrt))
+		goto drop;
 	if (!mrt->mroute_do_pim ||
 	    pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
 		goto drop;
@@ -1998,19 +1994,9 @@ static int pim_rcv(struct sk_buff *skb)
 	     csum_fold(skb_checksum(skb, 0, skb->len, 0))))
 		goto drop;
 
-	{
-		struct rtable *rt = skb_rtable(skb);
-		struct flowi fl = {
-			.fl4_dst = rt->rt_key_dst,
-			.fl4_src = rt->rt_key_src,
-			.fl4_tos = rt->rt_tos,
-			.oif = rt->rt_oif,
-			.iif = rt->rt_iif,
-			.mark = rt->rt_mark,
-		};
-		if (ipmr_fib_lookup(net, &fl, &mrt) < 0)
-			goto drop;
-	}
+	mrt = ipmr_rt_fib_lookup(net, skb_rtable(skb));
+	if (IS_ERR(mrt))
+		goto drop;
 	if (__pim_rcv(mrt, skb, sizeof(*pim))) {
 drop:
 		kfree_skb(skb);
Signature · 1 line
1.7.4.1