Skip to content

Commit 4a6ce2b

Browse files
tracywwnjdavem330
authored andcommitted
net: introduce a new function dst_dev_put()
This function should be called when removing routes from fib tree after the dst gc is no longer in use. We first mark DST_OBSOLETE_DEAD on this dst to make sure next dst_ops->check() fails and returns NULL. Secondly, as we no longer keep the gc_list, we need to properly release dst->dev right at the moment when the dst is removed from the fib/fib6 tree. It does the following: 1. change dst->input and output pointers to dst_discard/dst_dscard_out to discard all packets 2. replace dst->dev with loopback interface Signed-off-by: Wei Wang <weiwan@google.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5f56f40 commit 4a6ce2b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/net/dst.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ void dst_init(struct dst_entry *dst, struct dst_ops *ops,
428428
unsigned short flags);
429429
void __dst_free(struct dst_entry *dst);
430430
struct dst_entry *dst_destroy(struct dst_entry *dst);
431+
void dst_dev_put(struct dst_entry *dst);
431432

432433
static inline void dst_free(struct dst_entry *dst)
433434
{

net/core/dst.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,30 @@ static void dst_destroy_rcu(struct rcu_head *head)
296296
__dst_free(dst);
297297
}
298298

299+
/* Operations to mark dst as DEAD and clean up the net device referenced
300+
* by dst:
301+
* 1. put the dst under loopback interface and discard all tx/rx packets
302+
* on this route.
303+
* 2. release the net_device
304+
* This function should be called when removing routes from the fib tree
305+
* in preparation for a NETDEV_DOWN/NETDEV_UNREGISTER event and also to
306+
* make the next dst_ops->check() fail.
307+
*/
308+
void dst_dev_put(struct dst_entry *dst)
309+
{
310+
struct net_device *dev = dst->dev;
311+
312+
dst->obsolete = DST_OBSOLETE_DEAD;
313+
if (dst->ops->ifdown)
314+
dst->ops->ifdown(dst, dev, true);
315+
dst->input = dst_discard;
316+
dst->output = dst_discard_out;
317+
dst->dev = dev_net(dst->dev)->loopback_dev;
318+
dev_hold(dst->dev);
319+
dev_put(dev);
320+
}
321+
EXPORT_SYMBOL(dst_dev_put);
322+
299323
void dst_release(struct dst_entry *dst)
300324
{
301325
if (dst) {

0 commit comments

Comments
 (0)