Skip to contentSkip to conversation

ipv4: Store rtable entries directly in FIB

PATCH David Miller 2 participants 3 messages May 5, 2011 – May 6, 2011

Subsystems (4)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

Ok, here is the fun patch showing the scheme I'm working on. Two things going on here.

First, we store pre-constructed rtable entries, on demand, inside of the routing table objects themselves.

Second, we get rid of RT_TABLE_LOCAL and load all routes equally into RT_TABLE_MAIN.

include/net/ip_fib.h +2 -4
index 10422ef..f3c9598 100644
@@ -44,6 +44,7 @@ struct fib_config {
  };
 
 struct fib_info;
+struct rtable;
 
 struct fib_nh {
 	struct net_device	*nh_dev;
@@ -62,6 +63,7 @@ struct fib_nh {
 	__be32			nh_gw;
 	__be32			nh_saddr;
 	int			nh_saddr_genid;
+	struct rtable		*nh_rtable;
 };
 
 /*
@@ -200,10 +202,6 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
 {
 	struct fib_table *table;
 
-	table = fib_get_table(net, RT_TABLE_LOCAL);
-	if (!fib_table_lookup(table, flp, res, FIB_LOOKUP_NOREF))
-		return 0;
-
 	table = fib_get_table(net, RT_TABLE_MAIN);
 	if (!fib_table_lookup(table, flp, res, FIB_LOOKUP_NOREF))
 		return 0;
include/net/route.h +1 -0
index 70155fb..04e7197 100644
@@ -109,6 +109,7 @@ extern int		ip_rt_init(void);
 extern void		ip_rt_redirect(__be32 old_gw, __be32 dst, __be32 new_gw,
 				       __be32 src, struct net_device *dev);
 extern void		rt_cache_flush(struct net *net, int how);
+extern struct rtable *ip_route_output_new(struct net *, struct flowi4 *flp);
 extern struct rtable *__ip_route_output_key(struct net *, struct flowi4 *flp);
 extern struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
 					   struct sock *sk);
net/ipv4/fib_frontend.c +2 -6
index 33bbbda..24e67d8 100644
@@ -155,7 +155,7 @@ static inline unsigned __inet_dev_addr_type(struct net *net,
 	res.r = NULL;
 #endif
 
-	local_table = fib_get_table(net, RT_TABLE_LOCAL);
+	local_table = fib_get_table(net, RT_TABLE_MAIN);
 	if (local_table) {
 		ret = RTN_UNICAST;
 		rcu_read_lock();
@@ -662,11 +662,7 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad
 		},
 	};
 
-	if (type == RTN_UNICAST)
-		tb = fib_new_table(net, RT_TABLE_MAIN);
-	else
-		tb = fib_new_table(net, RT_TABLE_LOCAL);
-
+	tb = fib_new_table(net, RT_TABLE_MAIN);
 	if (tb == NULL)
 		return;
 
net/ipv4/fib_semantics.c +4 -0
index 641a5a2..c37ebd3 100644
@@ -148,6 +148,10 @@ static void free_fib_info_rcu(struct rcu_head *head)
 {
 	struct fib_info *fi = container_of(head, struct fib_info, rcu);
 
+	change_nexthops(fi) {
+		ip_rt_put(nexthop_nh->nh_rtable);
+		nexthop_nh->nh_rtable = NULL;
+	} endfor_nexthops(fi);
 	if (fi->fib_metrics != (u32 *) dst_default_metrics)
 		kfree(fi->fib_metrics);
 	kfree(fi);
net/ipv4/route.c +62 -0

68 lines not on this page · raw message

net/ipv4/udp.c +1 -1
index 544f435..9bb827e 100644
@@ -929,7 +929,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 				   faddr, saddr, dport, inet->inet_sport);
 
 		security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
-		rt = ip_route_output_flow(net, &fl4, sk);
+		rt = ip_route_output_new(net, &fl4);
 		if (IS_ERR(rt)) {
 			err = PTR_ERR(rt);
 			rt = NULL;
#1 lore raw

Hello,

Quoted 24 lines · David Miller

Ok, here is the fun patch showing the scheme I'm working on. Two things going on here.

First, we store pre-constructed rtable entries, on demand, inside of the routing table objects themselves.

Second, we get rid of RT_TABLE_LOCAL and load all routes equally into RT_TABLE_MAIN.

include/net/ip_fib.h +1 -0
index 10422ef..f3c9598 100644
@@ -44,6 +44,7 @@ struct fib_config {
  };
 
 struct fib_info;
+struct rtable;
 
 struct fib_nh {
 	struct net_device	*nh_dev;

include/net/ip_fib.h struct fib_nh { · line 66

Quoted 4 lines
include/net/ip_fib.h +1 -0
@@ -62,6 +63,7 @@ struct fib_nh {
 	__be32			nh_gw;
 	__be32			nh_saddr;
 	int			nh_saddr_genid;
+	struct rtable		*nh_rtable;

Caching results of __mkroute_output in NH does
not work well for RTN_MULTICAST because ip_check_mc_rcu wants to further restrict local delivery depending on the source address and protocol. Even the routing cache does not cache the protocol as key. May be received IGMP report can create input cache entry with RTCF_LOCAL flag and later the UDP stack can see unwatned incoming traffic that should be dropped by MCAST_INCLUDE/MCAST_EXCLUDE settings for the same group. I.e. the routing code calls ip_check_mc_rcu for IGMP but the cache prevents the next calls for UDP to drop these sources.

Before now ip_rt_multicast_event was used to
notify about changes in subscriptions for groups and the routing cache can update its information (RTCF_LOCAL) per indev+saddr+daddr (but no protocol). Without routing cache we can not solve the ip_check_mc_rcu problem with nh_mc_genid fields because NH can be used for many different saddr addresses.

Same problem is in ip_route_input_common,
we have to call ip_check_mc_rcu for every packet and this can be a problem with long lists. But I'm not sure if the stack can see many filters. If yes, may be only using hash table for in_dev->mc_list and its "sources" can help here because we have to call ip_check_mc_rcu for every input and output packet if dev+saddr+daddr+proto results are not cached for mcast.

Regards

--
Julian Anastasov <[email protected]>

author maintainer
#2 lore raw

From: Julian Anastasov <[email protected]>
Date: Fri, 6 May 2011 12:12:26 +0300 (EEST)

Quoted 4 lines

Caching results of __mkroute_output in NH does
not work well for RTN_MULTICAST because ip_check_mc_rcu wants to further restrict local delivery depending on the source address and protocol.

I understand that multicast needs special handling.

I'm concentrating on unicast/broadcast at the moment because there is a predominantly clear path for making that work.