blob: 39f2dc9439086b83e45b6495e712ebfe91daa2a4 [file] [log] [blame]
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -07001#ifndef __NET_FRAG_H__
2#define __NET_FRAG_H__
3
Pavel Emelyanovac18e752008-01-22 06:02:14 -08004struct netns_frags {
Pavel Emelyanove5a2bb8422008-01-22 06:06:23 -08005 int nqueues;
Pavel Emelyanov6ddc0822008-01-22 06:07:25 -08006 atomic_t mem;
Pavel Emelyanov3140c252008-01-22 06:11:48 -08007 struct list_head lru_list;
Pavel Emelyanovb2fd5322008-01-22 06:09:37 -08008
9 /* sysctls */
10 int timeout;
Pavel Emelyanove31e0bdc72008-01-22 06:10:13 -080011 int high_thresh;
12 int low_thresh;
Pavel Emelyanovac18e752008-01-22 06:02:14 -080013};
14
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070015struct inet_frag_queue {
16 struct hlist_node list;
Pavel Emelyanovac18e752008-01-22 06:02:14 -080017 struct netns_frags *net;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070018 struct list_head lru_list; /* lru list member */
19 spinlock_t lock;
20 atomic_t refcnt;
21 struct timer_list timer; /* when will this queue expire? */
22 struct sk_buff *fragments; /* list of received fragments */
23 ktime_t stamp;
24 int len; /* total length of orig datagram */
25 int meat;
26 __u8 last_in; /* first/last segment arrived? */
27
Joe Perchesbc578a52008-03-28 16:35:27 -070028#define INET_FRAG_COMPLETE 4
29#define INET_FRAG_FIRST_IN 2
30#define INET_FRAG_LAST_IN 1
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070031};
32
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070033#define INETFRAGS_HASHSZ 64
34
35struct inet_frags {
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070036 struct hlist_head hash[INETFRAGS_HASHSZ];
37 rwlock_t lock;
38 u32 rnd;
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070039 int qsize;
Pavel Emelyanov3b4bc4a2008-01-22 06:11:04 -080040 int secret_interval;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070041 struct timer_list secret_timer;
Pavel Emelyanov321a3a92007-10-15 02:38:08 -070042
43 unsigned int (*hashfn)(struct inet_frag_queue *);
Pavel Emelyanovc6fda282007-10-17 19:46:47 -070044 void (*constructor)(struct inet_frag_queue *q,
45 void *arg);
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070046 void (*destructor)(struct inet_frag_queue *);
47 void (*skb_free)(struct sk_buff *);
Pavel Emelyanovabd65232007-10-17 19:47:21 -070048 int (*match)(struct inet_frag_queue *q,
49 void *arg);
Pavel Emelyanove521db92007-10-17 19:45:23 -070050 void (*frag_expire)(unsigned long data);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070051};
52
53void inet_frags_init(struct inet_frags *);
54void inet_frags_fini(struct inet_frags *);
55
Pavel Emelyanove5a2bb8422008-01-22 06:06:23 -080056void inet_frags_init_net(struct netns_frags *nf);
Pavel Emelyanov81566e82008-01-22 06:12:39 -080057void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f);
Pavel Emelyanove5a2bb8422008-01-22 06:06:23 -080058
Pavel Emelyanov277e6502007-10-15 02:37:18 -070059void inet_frag_kill(struct inet_frag_queue *q, struct inet_frags *f);
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070060void inet_frag_destroy(struct inet_frag_queue *q,
61 struct inet_frags *f, int *work);
Pavel Emelyanov6ddc0822008-01-22 06:07:25 -080062int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f);
Pavel Emelyanovac18e752008-01-22 06:02:14 -080063struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
Hannes Eder56bca312009-02-25 10:32:52 +000064 struct inet_frags *f, void *key, unsigned int hash)
65 __releases(&f->lock);
Pavel Emelyanov277e6502007-10-15 02:37:18 -070066
Pavel Emelyanov762cc402007-10-15 02:41:56 -070067static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f)
68{
69 if (atomic_dec_and_test(&q->refcnt))
70 inet_frag_destroy(q, f, NULL);
71}
72
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070073#endif