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