blob: 2431cf83aecafb74ca1e9464bec6f6a669046d75 [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 Emelyanove5a2bb82008-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 */
Changli Gaod6bebca2010-06-29 04:39:37 +000023 struct sk_buff *fragments_tail;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070024 ktime_t stamp;
25 int len; /* total length of orig datagram */
26 int meat;
27 __u8 last_in; /* first/last segment arrived? */
28
Joe Perchesbc578a52008-03-28 16:35:27 -070029#define INET_FRAG_COMPLETE 4
30#define INET_FRAG_FIRST_IN 2
31#define INET_FRAG_LAST_IN 1
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070032};
33
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070034#define INETFRAGS_HASHSZ 64
35
36struct inet_frags {
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070037 struct hlist_head hash[INETFRAGS_HASHSZ];
38 rwlock_t lock;
39 u32 rnd;
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070040 int qsize;
Pavel Emelyanov3b4bc4a2008-01-22 06:11:04 -080041 int secret_interval;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070042 struct timer_list secret_timer;
Pavel Emelyanov321a3a92007-10-15 02:38:08 -070043
44 unsigned int (*hashfn)(struct inet_frag_queue *);
Pavel Emelyanovc6fda282007-10-17 19:46:47 -070045 void (*constructor)(struct inet_frag_queue *q,
46 void *arg);
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070047 void (*destructor)(struct inet_frag_queue *);
48 void (*skb_free)(struct sk_buff *);
Eric Dumazetcbc264c2012-05-18 05:57:13 +020049 bool (*match)(struct inet_frag_queue *q, 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 Emelyanove5a2bb82008-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 Emelyanove5a2bb82008-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