Blame view

include/net/inet_frag.h 4.01 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
5ab11c98d   Pavel Emelyanov   [INET]: Move comm...
2
3
  #ifndef __NET_FRAG_H__
  #define __NET_FRAG_H__
9aee41eff   Eric Dumazet   inet: frags: use ...
4
  #include <linux/rhashtable.h>
ac18e7509   Pavel Emelyanov   [NETNS][FRAGS]: M...
5
  struct netns_frags {
b2fd5321d   Pavel Emelyanov   [NETNS][FRAGS]: M...
6
  	/* sysctls */
990204ddc   Eric Dumazet   inet: frags: brea...
7
8
  	long			high_thresh;
  	long			low_thresh;
b2fd5321d   Pavel Emelyanov   [NETNS][FRAGS]: M...
9
  	int			timeout;
0fbf4cb27   Nikolay Borisov   ipv4: namespacify...
10
  	int			max_dist;
673220d64   Eric Dumazet   inet: frags: add ...
11
  	struct inet_frags	*f;
8291cd943   Eric Dumazet   inet: frags: reor...
12
13
14
15
16
  
  	struct rhashtable       rhashtable ____cacheline_aligned_in_smp;
  
  	/* Keep atomic mem on separate cachelines in structs that include it */
  	atomic_long_t		mem ____cacheline_aligned_in_smp;
ac18e7509   Pavel Emelyanov   [NETNS][FRAGS]: M...
17
  };
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
18
19
20
21
22
23
  /**
   * fragment queue flags
   *
   * @INET_FRAG_FIRST_IN: first fragment has arrived
   * @INET_FRAG_LAST_IN: final fragment has arrived
   * @INET_FRAG_COMPLETE: frag queue has been processed and is due for destruction
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
24
25
26
27
28
   */
  enum {
  	INET_FRAG_FIRST_IN	= BIT(0),
  	INET_FRAG_LAST_IN	= BIT(1),
  	INET_FRAG_COMPLETE	= BIT(2),
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
29
  };
9aee41eff   Eric Dumazet   inet: frags: use ...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  struct frag_v4_compare_key {
  	__be32		saddr;
  	__be32		daddr;
  	u32		user;
  	u32		vif;
  	__be16		id;
  	u16		protocol;
  };
  
  struct frag_v6_compare_key {
  	struct in6_addr	saddr;
  	struct in6_addr	daddr;
  	u32		user;
  	__be32		id;
  	u32		iif;
  };
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
46
47
48
  /**
   * struct inet_frag_queue - fragment queue
   *
9aee41eff   Eric Dumazet   inet: frags: use ...
49
50
   * @node: rhash node
   * @key: keys identifying this frag.
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
51
   * @timer: queue expiration timer
9aee41eff   Eric Dumazet   inet: frags: use ...
52
   * @lock: spinlock protecting this frag
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
53
54
   * @refcnt: reference count of the queue
   * @fragments: received fragments head
c91f27fb5   Peter Oskolkov   ip: add helpers t...
55
   * @rb_fragments: received fragments rb-tree root
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
56
   * @fragments_tail: received fragments tail
c91f27fb5   Peter Oskolkov   ip: add helpers t...
57
   * @last_run_head: the head of the last "run". see ip_fragment.c
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
58
59
60
61
   * @stamp: timestamp of the last received fragment
   * @len: total length of the original datagram
   * @meat: length of received fragments so far
   * @flags: fragment queue flags
d6b915e29   Florian Westphal   ip_fragment: don'...
62
   * @max_size: maximum received fragment size
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
63
   * @net: namespace that this frag belongs to
9aee41eff   Eric Dumazet   inet: frags: use ...
64
   * @rcu: rcu head for freeing deferall
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
65
   */
5ab11c98d   Pavel Emelyanov   [INET]: Move comm...
66
  struct inet_frag_queue {
9aee41eff   Eric Dumazet   inet: frags: use ...
67
68
69
70
71
  	struct rhash_head	node;
  	union {
  		struct frag_v4_compare_key v4;
  		struct frag_v6_compare_key v6;
  	} key;
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
72
  	struct timer_list	timer;
9aee41eff   Eric Dumazet   inet: frags: use ...
73
  	spinlock_t		lock;
edcb69187   Reshetova, Elena   net: convert inet...
74
  	refcount_t		refcnt;
6b921536f   Eric Dumazet   net: sk_buff rbno...
75
76
  	struct sk_buff		*fragments;  /* Used in IPv6. */
  	struct rb_root		rb_fragments; /* Used in IPv4. */
d6bebca92   Changli Gao   fragment: add fas...
77
  	struct sk_buff		*fragments_tail;
c91f27fb5   Peter Oskolkov   ip: add helpers t...
78
  	struct sk_buff		*last_run_head;
5ab11c98d   Pavel Emelyanov   [INET]: Move comm...
79
  	ktime_t			stamp;
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
80
  	int			len;
5ab11c98d   Pavel Emelyanov   [INET]: Move comm...
81
  	int			meat;
1ab1934ed   Nikolay Aleksandrov   inet: frags: enum...
82
  	__u8			flags;
5f2d04f1f   Patrick McHardy   ipv4: fix path MT...
83
  	u16			max_size;
9aee41eff   Eric Dumazet   inet: frags: use ...
84
85
  	struct netns_frags      *net;
  	struct rcu_head		rcu;
19952cc4f   Jesper Dangaard Brouer   net: frag queue p...
86
  };
7eb95156d   Pavel Emelyanov   [INET]: Collect f...
87
  struct inet_frags {
4c0ebd6fe   Alexey Dobriyan   net: make struct ...
88
  	unsigned int		qsize;
321a3a99e   Pavel Emelyanov   [INET]: Consolida...
89

c6fda2822   Pavel Emelyanov   [INET]: Consolida...
90
  	void			(*constructor)(struct inet_frag_queue *q,
36c777821   Florian Westphal   inet: frag: const...
91
  					       const void *arg);
1e4b82873   Pavel Emelyanov   [INET]: Consolida...
92
  	void			(*destructor)(struct inet_frag_queue *);
0512f7e93   Kees Cook   inet: frags: Conv...
93
  	void			(*frag_expire)(struct timer_list *t);
d4ad4d22e   Nikolay Aleksandrov   inet: frags: use ...
94
95
  	struct kmem_cache	*frags_cachep;
  	const char		*frags_cache_name;
9aee41eff   Eric Dumazet   inet: frags: use ...
96
  	struct rhashtable_params rhash_params;
7eb95156d   Pavel Emelyanov   [INET]: Collect f...
97
  };
d4ad4d22e   Nikolay Aleksandrov   inet: frags: use ...
98
  int inet_frags_init(struct inet_frags *);
7eb95156d   Pavel Emelyanov   [INET]: Collect f...
99
  void inet_frags_fini(struct inet_frags *);
6093d5abc   Eric Dumazet   inet: frags: chan...
100
  static inline int inet_frags_init_net(struct netns_frags *nf)
1d6119baf   Eric Dumazet   net: fix percpu m...
101
  {
990204ddc   Eric Dumazet   inet: frags: brea...
102
  	atomic_long_set(&nf->mem, 0);
9aee41eff   Eric Dumazet   inet: frags: use ...
103
  	return rhashtable_init(&nf->rhashtable, &nf->f->rhash_params);
1d6119baf   Eric Dumazet   net: fix percpu m...
104
  }
673220d64   Eric Dumazet   inet: frags: add ...
105
  void inet_frags_exit_net(struct netns_frags *nf);
e5a2bb842   Pavel Emelyanov   [NETNS][FRAGS]: M...
106

673220d64   Eric Dumazet   inet: frags: add ...
107
108
  void inet_frag_kill(struct inet_frag_queue *q);
  void inet_frag_destroy(struct inet_frag_queue *q);
9aee41eff   Eric Dumazet   inet: frags: use ...
109
  struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, void *key);
277e650dd   Pavel Emelyanov   [INET]: Consolida...
110

c91f27fb5   Peter Oskolkov   ip: add helpers t...
111
112
  /* Free all skbs in the queue; return the sum of their truesizes. */
  unsigned int inet_frag_rbtree_purge(struct rb_root *root);
673220d64   Eric Dumazet   inet: frags: add ...
113
  static inline void inet_frag_put(struct inet_frag_queue *q)
762cc4080   Pavel Emelyanov   [INET]: Consolida...
114
  {
edcb69187   Reshetova, Elena   net: convert inet...
115
  	if (refcount_dec_and_test(&q->refcnt))
673220d64   Eric Dumazet   inet: frags: add ...
116
  		inet_frag_destroy(q);
762cc4080   Pavel Emelyanov   [INET]: Consolida...
117
  }
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
118
  /* Memory Tracking Functions. */
990204ddc   Eric Dumazet   inet: frags: brea...
119
  static inline long frag_mem_limit(const struct netns_frags *nf)
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
120
  {
990204ddc   Eric Dumazet   inet: frags: brea...
121
  	return atomic_long_read(&nf->mem);
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
122
  }
990204ddc   Eric Dumazet   inet: frags: brea...
123
  static inline void sub_frag_mem_limit(struct netns_frags *nf, long val)
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
124
  {
990204ddc   Eric Dumazet   inet: frags: brea...
125
  	atomic_long_sub(val, &nf->mem);
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
126
  }
990204ddc   Eric Dumazet   inet: frags: brea...
127
  static inline void add_frag_mem_limit(struct netns_frags *nf, long val)
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
128
  {
990204ddc   Eric Dumazet   inet: frags: brea...
129
  	atomic_long_add(val, &nf->mem);
d433673e5   Jesper Dangaard Brouer   net: frag helper ...
130
  }
be991971d   Hannes Frederic Sowa   inet: generalize ...
131
132
133
134
135
136
137
138
139
140
  /* RFC 3168 support :
   * We want to check ECN values of all fragments, do detect invalid combinations.
   * In ipq->ecn, we store the OR value of each ip4_frag_ecn() fragment value.
   */
  #define	IPFRAG_ECN_NOT_ECT	0x01 /* one frag had ECN_NOT_ECT */
  #define	IPFRAG_ECN_ECT_1	0x02 /* one frag had ECN_ECT_1 */
  #define	IPFRAG_ECN_ECT_0	0x04 /* one frag had ECN_ECT_0 */
  #define	IPFRAG_ECN_CE		0x08 /* one frag had ECN_CE */
  
  extern const u8 ip_frag_ecn_table[16];
5ab11c98d   Pavel Emelyanov   [INET]: Move comm...
141
  #endif