Skip to content

Commit de68dca

Browse files
Eric Dumazetdavem330
authored andcommitted
inet: add a redirect generation id in inetpeer
Now inetpeer is the place where we cache redirect information for ipv4 destinations, we must be able to invalidate informations when a route is added/removed on host. As inetpeer is not yet namespace aware, this patch adds a shared redirect_genid, and a per inetpeer redirect_genid. This might be changed later if inetpeer becomes ns aware. Cache information for one inerpeer is valid as long as its redirect_genid has the same value than global redirect_genid. Reported-by: Arkadiusz Miśkiewicz <a.miskiewicz@gmail.com> Tested-by: Arkadiusz Miśkiewicz <a.miskiewicz@gmail.com> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0884d7a commit de68dca

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎include/net/inetpeer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct inet_peer {
3535

3636
u32 metrics[RTAX_MAX];
3737
u32 rate_tokens; /* rate limiting for ICMP */
38+
int redirect_genid;
3839
unsigned long rate_last;
3940
unsigned long pmtu_expires;
4041
u32 pmtu_orig;

‎net/ipv4/route.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static int ip_rt_mtu_expires __read_mostly = 10 * 60 * HZ;
131131
static int ip_rt_min_pmtu __read_mostly = 512 + 20 + 20;
132132
static int ip_rt_min_advmss __read_mostly = 256;
133133
static int rt_chain_length_max __read_mostly = 20;
134+
static int redirect_genid;
134135

135136
/*
136137
* Interface to generic destination cache.
@@ -837,6 +838,7 @@ static void rt_cache_invalidate(struct net *net)
837838

838839
get_random_bytes(&shuffle, sizeof(shuffle));
839840
atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
841+
redirect_genid++;
840842
}
841843

842844
/*
@@ -1391,8 +1393,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
13911393

13921394
peer = rt->peer;
13931395
if (peer) {
1394-
if (peer->redirect_learned.a4 != new_gw) {
1396+
if (peer->redirect_learned.a4 != new_gw ||
1397+
peer->redirect_genid != redirect_genid) {
13951398
peer->redirect_learned.a4 = new_gw;
1399+
peer->redirect_genid = redirect_genid;
13961400
atomic_inc(&__rt_peer_genid);
13971401
}
13981402
check_peer_redir(&rt->dst, peer);
@@ -1701,6 +1705,8 @@ static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
17011705
if (peer) {
17021706
check_peer_pmtu(dst, peer);
17031707

1708+
if (peer->redirect_genid != redirect_genid)
1709+
peer->redirect_learned.a4 = 0;
17041710
if (peer->redirect_learned.a4 &&
17051711
peer->redirect_learned.a4 != rt->rt_gateway) {
17061712
if (check_peer_redir(dst, peer))
@@ -1857,6 +1863,8 @@ static void rt_init_metrics(struct rtable *rt, const struct flowi4 *fl4,
18571863
dst_init_metrics(&rt->dst, peer->metrics, false);
18581864

18591865
check_peer_pmtu(&rt->dst, peer);
1866+
if (peer->redirect_genid != redirect_genid)
1867+
peer->redirect_learned.a4 = 0;
18601868
if (peer->redirect_learned.a4 &&
18611869
peer->redirect_learned.a4 != rt->rt_gateway) {
18621870
rt->rt_gateway = peer->redirect_learned.a4;

0 commit comments

Comments
 (0)