Skip to content

Commit 6431cbc

Browse files
committed
inet: Create a mechanism for upward inetpeer propagation into routes.
If we didn't have a routing cache, we would not be able to properly propagate certain kinds of dynamic path attributes, for example PMTU information and redirects. The reason is that if we didn't have a routing cache, then there would be no way to lookup all of the active cached routes hanging off of sockets, tunnels, IPSEC bundles, etc. Consider the case where we created a cached route, but no inetpeer entry existed and also we were not asked to pre-COW the route metrics and therefore did not force the creation a new inetpeer entry. If we later get a PMTU message, or a redirect, and store this information in a new inetpeer entry, there is no way to teach that cached route about the newly existing inetpeer entry. The facilities implemented here handle this problem. First we create a generation ID. When we create a cached route of any kind, we remember the generation ID at the time of attachment. Any time we force-create an inetpeer entry in response to new path information, we bump that generation ID. The dst_ops->check() callback is where the knowledge of this event is propagated. If the global generation ID does not equal the one stored in the cached route, and the cached route has not attached to an inetpeer yet, we look it up and attach if one is found. Now that we've updated the cached route's information, we update the route's generation ID too. This clears the way for implementing PMTU and redirects directly in the inetpeer cache. There is absolutely no need to consult cached route information in order to maintain this information. At this point nothing bumps the inetpeer genids, that comes in the later changes which handle PMTUs and redirects using inetpeers. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ddd4aa4 commit 6431cbc

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎include/net/ip6_fib.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct rt6_info {
108108
u32 rt6i_flags;
109109
struct rt6key rt6i_src;
110110
u32 rt6i_metric;
111+
u32 rt6i_peer_genid;
111112

112113
struct inet6_dev *rt6i_idev;
113114
struct inet_peer *rt6i_peer;

‎include/net/route.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct rtable {
6969

7070
/* Miscellaneous cached information */
7171
__be32 rt_spec_dst; /* RFC1122 specific destination */
72+
u32 rt_peer_genid;
7273
struct inet_peer *peer; /* long-living peer info */
7374
struct fib_info *fi; /* for client ref to shared metrics */
7475
};

‎net/ipv4/route.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,13 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt,
13081308
return 0;
13091309
}
13101310

1311+
static atomic_t __rt_peer_genid = ATOMIC_INIT(0);
1312+
1313+
static u32 rt_peer_genid(void)
1314+
{
1315+
return atomic_read(&__rt_peer_genid);
1316+
}
1317+
13111318
void rt_bind_peer(struct rtable *rt, int create)
13121319
{
13131320
struct inet_peer *peer;
@@ -1316,6 +1323,8 @@ void rt_bind_peer(struct rtable *rt, int create)
13161323

13171324
if (peer && cmpxchg(&rt->peer, NULL, peer) != NULL)
13181325
inet_putpeer(peer);
1326+
else
1327+
rt->rt_peer_genid = rt_peer_genid();
13191328
}
13201329

13211330
/*
@@ -1767,8 +1776,16 @@ static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu)
17671776

17681777
static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
17691778
{
1770-
if (rt_is_expired((struct rtable *)dst))
1779+
struct rtable *rt = (struct rtable *) dst;
1780+
1781+
if (rt_is_expired(rt))
17711782
return NULL;
1783+
if (rt->rt_peer_genid != rt_peer_genid()) {
1784+
if (!rt->peer)
1785+
rt_bind_peer(rt, 0);
1786+
1787+
rt->rt_peer_genid = rt_peer_genid();
1788+
}
17721789
return dst;
17731790
}
17741791

‎net/ipv6/route.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,22 @@ static void ip6_dst_destroy(struct dst_entry *dst)
240240
}
241241
}
242242

243+
static atomic_t __rt6_peer_genid = ATOMIC_INIT(0);
244+
245+
static u32 rt6_peer_genid(void)
246+
{
247+
return atomic_read(&__rt6_peer_genid);
248+
}
249+
243250
void rt6_bind_peer(struct rt6_info *rt, int create)
244251
{
245252
struct inet_peer *peer;
246253

247254
peer = inet_getpeer_v6(&rt->rt6i_dst.addr, create);
248255
if (peer && cmpxchg(&rt->rt6i_peer, NULL, peer) != NULL)
249256
inet_putpeer(peer);
257+
else
258+
rt->rt6i_peer_genid = rt6_peer_genid();
250259
}
251260

252261
static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
@@ -912,9 +921,14 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
912921

913922
rt = (struct rt6_info *) dst;
914923

915-
if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie))
924+
if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) {
925+
if (rt->rt6i_peer_genid != rt6_peer_genid()) {
926+
if (!rt->rt6i_peer)
927+
rt6_bind_peer(rt, 0);
928+
rt->rt6i_peer_genid = rt6_peer_genid();
929+
}
916930
return dst;
917-
931+
}
918932
return NULL;
919933
}
920934

0 commit comments

Comments
 (0)