Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
5ab11c98 PE |
2 | #ifndef __NET_FRAG_H__ |
3 | #define __NET_FRAG_H__ | |
4 | ||
0eb71a9d | 5 | #include <linux/rhashtable-types.h> |
648700f7 | 6 | |
6ce3b4dc ED |
7 | /* Per netns frag queues directory */ |
8 | struct fqdir { | |
b2fd5321 | 9 | /* sysctls */ |
3e67f106 ED |
10 | long high_thresh; |
11 | long low_thresh; | |
b2fd5321 | 12 | int timeout; |
0fbf4cb2 | 13 | int max_dist; |
093ba729 | 14 | struct inet_frags *f; |
c2615cf5 ED |
15 | |
16 | struct rhashtable rhashtable ____cacheline_aligned_in_smp; | |
17 | ||
18 | /* Keep atomic mem on separate cachelines in structs that include it */ | |
19 | atomic_long_t mem ____cacheline_aligned_in_smp; | |
ac18e750 PE |
20 | }; |
21 | ||
1ab1934e NA |
22 | /** |
23 | * fragment queue flags | |
24 | * | |
25 | * @INET_FRAG_FIRST_IN: first fragment has arrived | |
26 | * @INET_FRAG_LAST_IN: final fragment has arrived | |
27 | * @INET_FRAG_COMPLETE: frag queue has been processed and is due for destruction | |
1ab1934e NA |
28 | */ |
29 | enum { | |
30 | INET_FRAG_FIRST_IN = BIT(0), | |
31 | INET_FRAG_LAST_IN = BIT(1), | |
32 | INET_FRAG_COMPLETE = BIT(2), | |
1ab1934e NA |
33 | }; |
34 | ||
648700f7 ED |
35 | struct frag_v4_compare_key { |
36 | __be32 saddr; | |
37 | __be32 daddr; | |
38 | u32 user; | |
39 | u32 vif; | |
40 | __be16 id; | |
41 | u16 protocol; | |
42 | }; | |
43 | ||
44 | struct frag_v6_compare_key { | |
45 | struct in6_addr saddr; | |
46 | struct in6_addr daddr; | |
47 | u32 user; | |
48 | __be32 id; | |
49 | u32 iif; | |
50 | }; | |
51 | ||
1ab1934e NA |
52 | /** |
53 | * struct inet_frag_queue - fragment queue | |
54 | * | |
648700f7 ED |
55 | * @node: rhash node |
56 | * @key: keys identifying this frag. | |
1ab1934e | 57 | * @timer: queue expiration timer |
648700f7 | 58 | * @lock: spinlock protecting this frag |
1ab1934e | 59 | * @refcnt: reference count of the queue |
353c9cb3 | 60 | * @rb_fragments: received fragments rb-tree root |
1ab1934e | 61 | * @fragments_tail: received fragments tail |
353c9cb3 | 62 | * @last_run_head: the head of the last "run". see ip_fragment.c |
1ab1934e NA |
63 | * @stamp: timestamp of the last received fragment |
64 | * @len: total length of the original datagram | |
65 | * @meat: length of received fragments so far | |
66 | * @flags: fragment queue flags | |
d6b915e2 | 67 | * @max_size: maximum received fragment size |
6ce3b4dc | 68 | * @fqdir: pointer to struct fqdir |
648700f7 | 69 | * @rcu: rcu head for freeing deferall |
1ab1934e | 70 | */ |
5ab11c98 | 71 | struct inet_frag_queue { |
648700f7 ED |
72 | struct rhash_head node; |
73 | union { | |
74 | struct frag_v4_compare_key v4; | |
75 | struct frag_v6_compare_key v6; | |
76 | } key; | |
1ab1934e | 77 | struct timer_list timer; |
648700f7 | 78 | spinlock_t lock; |
edcb6918 | 79 | refcount_t refcnt; |
d8cf757f | 80 | struct rb_root rb_fragments; |
d6bebca9 | 81 | struct sk_buff *fragments_tail; |
353c9cb3 | 82 | struct sk_buff *last_run_head; |
5ab11c98 | 83 | ktime_t stamp; |
1ab1934e | 84 | int len; |
5ab11c98 | 85 | int meat; |
1ab1934e | 86 | __u8 flags; |
5f2d04f1 | 87 | u16 max_size; |
6ce3b4dc | 88 | struct fqdir *fqdir; |
648700f7 | 89 | struct rcu_head rcu; |
19952cc4 JDB |
90 | }; |
91 | ||
7eb95156 | 92 | struct inet_frags { |
4c0ebd6f | 93 | unsigned int qsize; |
321a3a99 | 94 | |
c6fda282 | 95 | void (*constructor)(struct inet_frag_queue *q, |
36c77782 | 96 | const void *arg); |
1e4b8287 | 97 | void (*destructor)(struct inet_frag_queue *); |
78802011 | 98 | void (*frag_expire)(struct timer_list *t); |
d4ad4d22 NA |
99 | struct kmem_cache *frags_cachep; |
100 | const char *frags_cache_name; | |
648700f7 | 101 | struct rhashtable_params rhash_params; |
7eb95156 PE |
102 | }; |
103 | ||
d4ad4d22 | 104 | int inet_frags_init(struct inet_frags *); |
7eb95156 PE |
105 | void inet_frags_fini(struct inet_frags *); |
106 | ||
6ce3b4dc | 107 | static inline int inet_frags_init_net(struct fqdir *fqdir) |
1d6119ba | 108 | { |
6ce3b4dc ED |
109 | atomic_long_set(&fqdir->mem, 0); |
110 | return rhashtable_init(&fqdir->rhashtable, &fqdir->f->rhash_params); | |
1d6119ba | 111 | } |
6ce3b4dc | 112 | void inet_frags_exit_net(struct fqdir *fqdir); |
e5a2bb84 | 113 | |
093ba729 ED |
114 | void inet_frag_kill(struct inet_frag_queue *q); |
115 | void inet_frag_destroy(struct inet_frag_queue *q); | |
6ce3b4dc | 116 | struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key); |
277e650d | 117 | |
353c9cb3 PO |
118 | /* Free all skbs in the queue; return the sum of their truesizes. */ |
119 | unsigned int inet_frag_rbtree_purge(struct rb_root *root); | |
120 | ||
093ba729 | 121 | static inline void inet_frag_put(struct inet_frag_queue *q) |
762cc408 | 122 | { |
edcb6918 | 123 | if (refcount_dec_and_test(&q->refcnt)) |
093ba729 | 124 | inet_frag_destroy(q); |
762cc408 PE |
125 | } |
126 | ||
d433673e JDB |
127 | /* Memory Tracking Functions. */ |
128 | ||
6ce3b4dc | 129 | static inline long frag_mem_limit(const struct fqdir *fqdir) |
d433673e | 130 | { |
6ce3b4dc | 131 | return atomic_long_read(&fqdir->mem); |
d433673e JDB |
132 | } |
133 | ||
6ce3b4dc | 134 | static inline void sub_frag_mem_limit(struct fqdir *fqdir, long val) |
d433673e | 135 | { |
6ce3b4dc | 136 | atomic_long_sub(val, &fqdir->mem); |
d433673e JDB |
137 | } |
138 | ||
6ce3b4dc | 139 | static inline void add_frag_mem_limit(struct fqdir *fqdir, long val) |
d433673e | 140 | { |
6ce3b4dc | 141 | atomic_long_add(val, &fqdir->mem); |
d433673e JDB |
142 | } |
143 | ||
be991971 HFS |
144 | /* RFC 3168 support : |
145 | * We want to check ECN values of all fragments, do detect invalid combinations. | |
146 | * In ipq->ecn, we store the OR value of each ip4_frag_ecn() fragment value. | |
147 | */ | |
148 | #define IPFRAG_ECN_NOT_ECT 0x01 /* one frag had ECN_NOT_ECT */ | |
149 | #define IPFRAG_ECN_ECT_1 0x02 /* one frag had ECN_ECT_1 */ | |
150 | #define IPFRAG_ECN_ECT_0 0x04 /* one frag had ECN_ECT_0 */ | |
151 | #define IPFRAG_ECN_CE 0x08 /* one frag had ECN_CE */ | |
152 | ||
153 | extern const u8 ip_frag_ecn_table[16]; | |
154 | ||
c23f35d1 PO |
155 | /* Return values of inet_frag_queue_insert() */ |
156 | #define IPFRAG_OK 0 | |
157 | #define IPFRAG_DUP 1 | |
158 | #define IPFRAG_OVERLAP 2 | |
159 | int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, | |
160 | int offset, int end); | |
161 | void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, | |
162 | struct sk_buff *parent); | |
163 | void inet_frag_reasm_finish(struct inet_frag_queue *q, struct sk_buff *head, | |
164 | void *reasm_data); | |
165 | struct sk_buff *inet_frag_pull_head(struct inet_frag_queue *q); | |
166 | ||
5ab11c98 | 167 | #endif |