net: frag helper functions for mem limit tracking
[deliverable/linux.git] / include / net / inet_frag.h
CommitLineData
5ab11c98
PE
1#ifndef __NET_FRAG_H__
2#define __NET_FRAG_H__
3
ac18e750 4struct netns_frags {
e5a2bb84 5 int nqueues;
3140c25c 6 struct list_head lru_list;
b2fd5321 7
cd39a789
JDB
8 /* Its important for performance to keep lru_list and mem on
9 * separate cachelines
10 */
11 atomic_t mem ____cacheline_aligned_in_smp;
b2fd5321
PE
12 /* sysctls */
13 int timeout;
e31e0bdc
PE
14 int high_thresh;
15 int low_thresh;
ac18e750
PE
16};
17
5ab11c98 18struct inet_frag_queue {
5ab11c98 19 spinlock_t lock;
5ab11c98 20 struct timer_list timer; /* when will this queue expire? */
6e34a8b3
JDB
21 struct list_head lru_list; /* lru list member */
22 struct hlist_node list;
23 atomic_t refcnt;
5ab11c98 24 struct sk_buff *fragments; /* list of received fragments */
d6bebca9 25 struct sk_buff *fragments_tail;
5ab11c98
PE
26 ktime_t stamp;
27 int len; /* total length of orig datagram */
28 int meat;
29 __u8 last_in; /* first/last segment arrived? */
30
bc578a54
JP
31#define INET_FRAG_COMPLETE 4
32#define INET_FRAG_FIRST_IN 2
33#define INET_FRAG_LAST_IN 1
5f2d04f1
PM
34
35 u16 max_size;
6e34a8b3
JDB
36
37 struct netns_frags *net;
5ab11c98
PE
38};
39
7eb95156
PE
40#define INETFRAGS_HASHSZ 64
41
42struct inet_frags {
7eb95156 43 struct hlist_head hash[INETFRAGS_HASHSZ];
5f8e1e8b
JDB
44 /* This rwlock is a global lock (seperate per IPv4, IPv6 and
45 * netfilter). Important to keep this on a seperate cacheline.
46 */
47 rwlock_t lock ____cacheline_aligned_in_smp;
3b4bc4a2 48 int secret_interval;
7eb95156 49 struct timer_list secret_timer;
5f8e1e8b
JDB
50 u32 rnd;
51 int qsize;
321a3a99
PE
52
53 unsigned int (*hashfn)(struct inet_frag_queue *);
5f8e1e8b 54 bool (*match)(struct inet_frag_queue *q, void *arg);
c6fda282
PE
55 void (*constructor)(struct inet_frag_queue *q,
56 void *arg);
1e4b8287
PE
57 void (*destructor)(struct inet_frag_queue *);
58 void (*skb_free)(struct sk_buff *);
e521db9d 59 void (*frag_expire)(unsigned long data);
7eb95156
PE
60};
61
62void inet_frags_init(struct inet_frags *);
63void inet_frags_fini(struct inet_frags *);
64
e5a2bb84 65void inet_frags_init_net(struct netns_frags *nf);
81566e83 66void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f);
e5a2bb84 67
277e650d 68void inet_frag_kill(struct inet_frag_queue *q, struct inet_frags *f);
1e4b8287
PE
69void inet_frag_destroy(struct inet_frag_queue *q,
70 struct inet_frags *f, int *work);
6b102865 71int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force);
ac18e750 72struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
56bca31f
HE
73 struct inet_frags *f, void *key, unsigned int hash)
74 __releases(&f->lock);
277e650d 75
762cc408
PE
76static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f)
77{
78 if (atomic_dec_and_test(&q->refcnt))
79 inet_frag_destroy(q, f, NULL);
80}
81
d433673e
JDB
82/* Memory Tracking Functions. */
83
84static inline int frag_mem_limit(struct netns_frags *nf)
85{
86 return atomic_read(&nf->mem);
87}
88
89static inline void sub_frag_mem_limit(struct inet_frag_queue *q, int i)
90{
91 atomic_sub(i, &q->net->mem);
92}
93
94static inline void add_frag_mem_limit(struct inet_frag_queue *q, int i)
95{
96 atomic_add(i, &q->net->mem);
97}
98
99static inline void init_frag_mem_limit(struct netns_frags *nf)
100{
101 atomic_set(&nf->mem, 0);
102}
103
104static inline int sum_frag_mem_limit(struct netns_frags *nf)
105{
106 return atomic_read(&nf->mem);
107}
108
5ab11c98 109#endif
This page took 0.524254 seconds and 5 git commands to generate.