.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * net/core/dst.c Protocol independent destination cache. |
---|
3 | 4 | * |
---|
.. | .. |
---|
26 | 27 | #include <net/dst.h> |
---|
27 | 28 | #include <net/dst_metadata.h> |
---|
28 | 29 | |
---|
29 | | -/* |
---|
30 | | - * Theory of operations: |
---|
31 | | - * 1) We use a list, protected by a spinlock, to add |
---|
32 | | - * new entries from both BH and non-BH context. |
---|
33 | | - * 2) In order to keep spinlock held for a small delay, |
---|
34 | | - * we use a second list where are stored long lived |
---|
35 | | - * entries, that are handled by the garbage collect thread |
---|
36 | | - * fired by a workqueue. |
---|
37 | | - * 3) This list is guarded by a mutex, |
---|
38 | | - * so that the gc_task and dst_dev_event() can be synchronized. |
---|
39 | | - */ |
---|
40 | | - |
---|
41 | | -/* |
---|
42 | | - * We want to keep lock & list close together |
---|
43 | | - * to dirty as few cache lines as possible in __dst_free(). |
---|
44 | | - * As this is not a very strong hint, we dont force an alignment on SMP. |
---|
45 | | - */ |
---|
46 | 30 | int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb) |
---|
47 | 31 | { |
---|
48 | 32 | kfree_skb(skb); |
---|
.. | .. |
---|
97 | 81 | { |
---|
98 | 82 | struct dst_entry *dst; |
---|
99 | 83 | |
---|
100 | | - if (ops->gc && dst_entries_get_fast(ops) > ops->gc_thresh) { |
---|
101 | | - if (ops->gc(ops)) |
---|
| 84 | + if (ops->gc && |
---|
| 85 | + !(flags & DST_NOCOUNT) && |
---|
| 86 | + dst_entries_get_fast(ops) > ops->gc_thresh) { |
---|
| 87 | + if (ops->gc(ops)) { |
---|
| 88 | + pr_notice_ratelimited("Route cache is full: consider increasing sysctl net.ipv6.route.max_size.\n"); |
---|
102 | 89 | return NULL; |
---|
| 90 | + } |
---|
103 | 91 | } |
---|
104 | 92 | |
---|
105 | 93 | dst = kmem_cache_alloc(ops->kmem_cachep, GFP_ATOMIC); |
---|
.. | .. |
---|
156 | 144 | |
---|
157 | 145 | /* Operations to mark dst as DEAD and clean up the net device referenced |
---|
158 | 146 | * by dst: |
---|
159 | | - * 1. put the dst under loopback interface and discard all tx/rx packets |
---|
| 147 | + * 1. put the dst under blackhole interface and discard all tx/rx packets |
---|
160 | 148 | * on this route. |
---|
161 | 149 | * 2. release the net_device |
---|
162 | 150 | * This function should be called when removing routes from the fib tree |
---|
.. | .. |
---|
172 | 160 | dst->ops->ifdown(dst, dev, true); |
---|
173 | 161 | dst->input = dst_discard; |
---|
174 | 162 | dst->output = dst_discard_out; |
---|
175 | | - dst->dev = dev_net(dst->dev)->loopback_dev; |
---|
| 163 | + dst->dev = blackhole_netdev; |
---|
176 | 164 | dev_hold(dst->dev); |
---|
177 | 165 | dev_put(dev); |
---|
178 | 166 | } |
---|
.. | .. |
---|
184 | 172 | int newrefcnt; |
---|
185 | 173 | |
---|
186 | 174 | newrefcnt = atomic_dec_return(&dst->__refcnt); |
---|
187 | | - if (unlikely(newrefcnt < 0)) |
---|
| 175 | + if (WARN_ONCE(newrefcnt < 0, "dst_release underflow")) |
---|
188 | 176 | net_warn_ratelimited("%s: dst:%p refcnt:%d\n", |
---|
189 | 177 | __func__, dst, newrefcnt); |
---|
190 | 178 | if (!newrefcnt) |
---|
.. | .. |
---|
199 | 187 | int newrefcnt; |
---|
200 | 188 | |
---|
201 | 189 | newrefcnt = atomic_dec_return(&dst->__refcnt); |
---|
202 | | - if (unlikely(newrefcnt < 0)) |
---|
| 190 | + if (WARN_ONCE(newrefcnt < 0, "dst_release_immediate underflow")) |
---|
203 | 191 | net_warn_ratelimited("%s: dst:%p refcnt:%d\n", |
---|
204 | 192 | __func__, dst, newrefcnt); |
---|
205 | 193 | if (!newrefcnt) |
---|
.. | .. |
---|
249 | 237 | } |
---|
250 | 238 | EXPORT_SYMBOL(__dst_destroy_metrics_generic); |
---|
251 | 239 | |
---|
252 | | -static struct dst_ops md_dst_ops = { |
---|
253 | | - .family = AF_UNSPEC, |
---|
| 240 | +struct dst_entry *dst_blackhole_check(struct dst_entry *dst, u32 cookie) |
---|
| 241 | +{ |
---|
| 242 | + return NULL; |
---|
| 243 | +} |
---|
| 244 | + |
---|
| 245 | +u32 *dst_blackhole_cow_metrics(struct dst_entry *dst, unsigned long old) |
---|
| 246 | +{ |
---|
| 247 | + return NULL; |
---|
| 248 | +} |
---|
| 249 | + |
---|
| 250 | +struct neighbour *dst_blackhole_neigh_lookup(const struct dst_entry *dst, |
---|
| 251 | + struct sk_buff *skb, |
---|
| 252 | + const void *daddr) |
---|
| 253 | +{ |
---|
| 254 | + return NULL; |
---|
| 255 | +} |
---|
| 256 | + |
---|
| 257 | +void dst_blackhole_update_pmtu(struct dst_entry *dst, struct sock *sk, |
---|
| 258 | + struct sk_buff *skb, u32 mtu, |
---|
| 259 | + bool confirm_neigh) |
---|
| 260 | +{ |
---|
| 261 | +} |
---|
| 262 | +EXPORT_SYMBOL_GPL(dst_blackhole_update_pmtu); |
---|
| 263 | + |
---|
| 264 | +void dst_blackhole_redirect(struct dst_entry *dst, struct sock *sk, |
---|
| 265 | + struct sk_buff *skb) |
---|
| 266 | +{ |
---|
| 267 | +} |
---|
| 268 | +EXPORT_SYMBOL_GPL(dst_blackhole_redirect); |
---|
| 269 | + |
---|
| 270 | +unsigned int dst_blackhole_mtu(const struct dst_entry *dst) |
---|
| 271 | +{ |
---|
| 272 | + unsigned int mtu = dst_metric_raw(dst, RTAX_MTU); |
---|
| 273 | + |
---|
| 274 | + return mtu ? : dst->dev->mtu; |
---|
| 275 | +} |
---|
| 276 | +EXPORT_SYMBOL_GPL(dst_blackhole_mtu); |
---|
| 277 | + |
---|
| 278 | +static struct dst_ops dst_blackhole_ops = { |
---|
| 279 | + .family = AF_UNSPEC, |
---|
| 280 | + .neigh_lookup = dst_blackhole_neigh_lookup, |
---|
| 281 | + .check = dst_blackhole_check, |
---|
| 282 | + .cow_metrics = dst_blackhole_cow_metrics, |
---|
| 283 | + .update_pmtu = dst_blackhole_update_pmtu, |
---|
| 284 | + .redirect = dst_blackhole_redirect, |
---|
| 285 | + .mtu = dst_blackhole_mtu, |
---|
254 | 286 | }; |
---|
255 | | - |
---|
256 | | -static int dst_md_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb) |
---|
257 | | -{ |
---|
258 | | - WARN_ONCE(1, "Attempting to call output on metadata dst\n"); |
---|
259 | | - kfree_skb(skb); |
---|
260 | | - return 0; |
---|
261 | | -} |
---|
262 | | - |
---|
263 | | -static int dst_md_discard(struct sk_buff *skb) |
---|
264 | | -{ |
---|
265 | | - WARN_ONCE(1, "Attempting to call input on metadata dst\n"); |
---|
266 | | - kfree_skb(skb); |
---|
267 | | - return 0; |
---|
268 | | -} |
---|
269 | 287 | |
---|
270 | 288 | static void __metadata_dst_init(struct metadata_dst *md_dst, |
---|
271 | 289 | enum metadata_type type, u8 optslen) |
---|
272 | | - |
---|
273 | 290 | { |
---|
274 | 291 | struct dst_entry *dst; |
---|
275 | 292 | |
---|
276 | 293 | dst = &md_dst->dst; |
---|
277 | | - dst_init(dst, &md_dst_ops, NULL, 1, DST_OBSOLETE_NONE, |
---|
| 294 | + dst_init(dst, &dst_blackhole_ops, NULL, 1, DST_OBSOLETE_NONE, |
---|
278 | 295 | DST_METADATA | DST_NOCOUNT); |
---|
279 | | - |
---|
280 | | - dst->input = dst_md_discard; |
---|
281 | | - dst->output = dst_md_discard_out; |
---|
282 | | - |
---|
283 | 296 | memset(dst + 1, 0, sizeof(*md_dst) + optslen - sizeof(*dst)); |
---|
284 | 297 | md_dst->type = type; |
---|
285 | 298 | } |
---|