Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 2 | #ifndef _NET_DST_OPS_H |
| 3 | #define _NET_DST_OPS_H |
| 4 | #include <linux/types.h> |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 5 | #include <linux/percpu_counter.h> |
Paul Mundt | 43b81f8 | 2010-11-07 19:58:05 -0800 | [diff] [blame] | 6 | #include <linux/cache.h> |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 7 | |
| 8 | struct dst_entry; |
| 9 | struct kmem_cachep; |
| 10 | struct net_device; |
| 11 | struct sk_buff; |
David S. Miller | d8f1641 | 2012-07-19 10:43:03 -0700 | [diff] [blame] | 12 | struct sock; |
Eric W. Biederman | cf91a99 | 2015-10-07 16:48:45 -0500 | [diff] [blame] | 13 | struct net; |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 14 | |
| 15 | struct dst_ops { |
| 16 | unsigned short family; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 17 | unsigned int gc_thresh; |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 18 | |
| 19 | int (*gc)(struct dst_ops *ops); |
| 20 | struct dst_entry * (*check)(struct dst_entry *, __u32 cookie); |
David S. Miller | 0dbaee3 | 2010-12-13 12:52:14 -0800 | [diff] [blame] | 21 | unsigned int (*default_advmss)(const struct dst_entry *); |
Steffen Klassert | ebb762f | 2011-11-23 02:12:51 +0000 | [diff] [blame] | 22 | unsigned int (*mtu)(const struct dst_entry *); |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 23 | u32 * (*cow_metrics)(struct dst_entry *, unsigned long); |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 24 | void (*destroy)(struct dst_entry *); |
| 25 | void (*ifdown)(struct dst_entry *, |
| 26 | struct net_device *dev, int how); |
| 27 | struct dst_entry * (*negative_advice)(struct dst_entry *); |
| 28 | void (*link_failure)(struct sk_buff *); |
David S. Miller | 6700c27 | 2012-07-17 03:29:28 -0700 | [diff] [blame] | 29 | void (*update_pmtu)(struct dst_entry *dst, struct sock *sk, |
Hangbin Liu | bd085ef | 2019-12-22 10:51:09 +0800 | [diff] [blame] | 30 | struct sk_buff *skb, u32 mtu, |
| 31 | bool confirm_neigh); |
David S. Miller | 6700c27 | 2012-07-17 03:29:28 -0700 | [diff] [blame] | 32 | void (*redirect)(struct dst_entry *dst, struct sock *sk, |
| 33 | struct sk_buff *skb); |
Eric W. Biederman | cf91a99 | 2015-10-07 16:48:45 -0500 | [diff] [blame] | 34 | int (*local_out)(struct net *net, struct sock *sk, struct sk_buff *skb); |
David S. Miller | f894cbf | 2012-07-02 21:52:24 -0700 | [diff] [blame] | 35 | struct neighbour * (*neigh_lookup)(const struct dst_entry *dst, |
| 36 | struct sk_buff *skb, |
| 37 | const void *daddr); |
Julian Anastasov | 63fca65 | 2017-02-06 23:14:15 +0200 | [diff] [blame] | 38 | void (*confirm_neigh)(const struct dst_entry *dst, |
| 39 | const void *daddr); |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 40 | |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 41 | struct kmem_cache *kmem_cachep; |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 42 | |
| 43 | struct percpu_counter pcpuc_entries ____cacheline_aligned_in_smp; |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 44 | }; |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 45 | |
| 46 | static inline int dst_entries_get_fast(struct dst_ops *dst) |
| 47 | { |
| 48 | return percpu_counter_read_positive(&dst->pcpuc_entries); |
| 49 | } |
| 50 | |
| 51 | static inline int dst_entries_get_slow(struct dst_ops *dst) |
| 52 | { |
Eric Dumazet | c2a2efb | 2017-01-20 05:06:08 -0800 | [diff] [blame] | 53 | return percpu_counter_sum_positive(&dst->pcpuc_entries); |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Eric Dumazet | cf86a08 | 2020-05-07 18:58:10 -0700 | [diff] [blame] | 56 | #define DST_PERCPU_COUNTER_BATCH 32 |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 57 | static inline void dst_entries_add(struct dst_ops *dst, int val) |
| 58 | { |
Eric Dumazet | cf86a08 | 2020-05-07 18:58:10 -0700 | [diff] [blame] | 59 | percpu_counter_add_batch(&dst->pcpuc_entries, val, |
| 60 | DST_PERCPU_COUNTER_BATCH); |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static inline int dst_entries_init(struct dst_ops *dst) |
| 64 | { |
Tejun Heo | 908c7f1 | 2014-09-08 09:51:29 +0900 | [diff] [blame] | 65 | return percpu_counter_init(&dst->pcpuc_entries, 0, GFP_KERNEL); |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static inline void dst_entries_destroy(struct dst_ops *dst) |
| 69 | { |
| 70 | percpu_counter_destroy(&dst->pcpuc_entries); |
| 71 | } |
| 72 | |
Alexey Dobriyan | 86393e5 | 2009-08-29 01:34:49 +0000 | [diff] [blame] | 73 | #endif |