Skip to content

Commit 1dbe325

Browse files
tracywwnjdavem330
authored andcommitted
net: use loopback dev when generating blackhole route
Existing ipv4/6_blackhole_route() code generates a blackhole route with dst->dev pointing to the passed in dst->dev. It is not necessary to hold reference to the passed in dst->dev because the packets going through this route are dropped anyway. A loopback interface is good enough so that we don't need to worry about releasing this dst->dev when this dev is going down. 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 d24406c commit 1dbe325

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

net/ipv4/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,7 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
25042504
new->input = dst_discard;
25052505
new->output = dst_discard_out;
25062506

2507-
new->dev = ort->dst.dev;
2507+
new->dev = net->loopback_dev;
25082508
if (new->dev)
25092509
dev_hold(new->dev);
25102510

net/ipv6/route.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,9 +1245,12 @@ EXPORT_SYMBOL_GPL(ip6_route_output_flags);
12451245
struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_orig)
12461246
{
12471247
struct rt6_info *rt, *ort = (struct rt6_info *) dst_orig;
1248+
struct net_device *loopback_dev = net->loopback_dev;
12481249
struct dst_entry *new = NULL;
12491250

1250-
rt = dst_alloc(&ip6_dst_blackhole_ops, ort->dst.dev, 1, DST_OBSOLETE_NONE, 0);
1251+
1252+
rt = dst_alloc(&ip6_dst_blackhole_ops, loopback_dev, 1,
1253+
DST_OBSOLETE_NONE, 0);
12511254
if (rt) {
12521255
rt6_info_init(rt);
12531256

@@ -1257,10 +1260,8 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
12571260
new->output = dst_discard_out;
12581261

12591262
dst_copy_metrics(new, &ort->dst);
1260-
rt->rt6i_idev = ort->rt6i_idev;
1261-
if (rt->rt6i_idev)
1262-
in6_dev_hold(rt->rt6i_idev);
12631263

1264+
rt->rt6i_idev = in6_dev_get(loopback_dev);
12641265
rt->rt6i_gateway = ort->rt6i_gateway;
12651266
rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU;
12661267
rt->rt6i_metric = 0;

0 commit comments

Comments
 (0)