blob: 32786a0447187f44e1264f4dc4c0b4721ebc3e08 [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
Patrick McHardy5f2d04f2012-08-26 19:13:55 +020032
33 u16 max_size;
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070034};
35
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070036#define INETFRAGS_HASHSZ 64
37
38struct inet_frags {
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070039 struct hlist_head hash[INETFRAGS_HASHSZ];
40 rwlock_t lock;
41 u32 rnd;
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070042 int qsize;
Pavel Emelyanov3b4bc4a2008-01-22 06:11:04 -080043 int secret_interval;
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070044 struct timer_list secret_timer;
Pavel Emelyanov321a3a92007-10-15 02:38:08 -070045
46 unsigned int (*hashfn)(struct inet_frag_queue *);
Pavel Emelyanovc6fda282007-10-17 19:46:47 -070047 void (*constructor)(struct inet_frag_queue *q,
48 void *arg);
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070049 void (*destructor)(struct inet_frag_queue *);
50 void (*skb_free)(struct sk_buff *);
Eric Dumazetcbc264c2012-05-18 05:57:13 +020051 bool (*match)(struct inet_frag_queue *q, void *arg);
Pavel Emelyanove521db92007-10-17 19:45:23 -070052 void (*frag_expire)(unsigned long data);
Pavel Emelyanov7eb95152007-10-15 02:31:52 -070053};
54
55void inet_frags_init(struct inet_frags *);
56void inet_frags_fini(struct inet_frags *);
57
Pavel Emelyanove5a2bb82008-01-22 06:06:23 -080058void inet_frags_init_net(struct netns_frags *nf);
Pavel Emelyanov81566e82008-01-22 06:12:39 -080059void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f);
Pavel Emelyanove5a2bb82008-01-22 06:06:23 -080060
Pavel Emelyanov277e6502007-10-15 02:37:18 -070061void inet_frag_kill(struct inet_frag_queue *q, struct inet_frags *f);
Pavel Emelyanov1e4b8282007-10-15 02:39:14 -070062void inet_frag_destroy(struct inet_frag_queue *q,
63 struct inet_frags *f, int *work);
Amerigo Wang6b102862012-09-18 16:50:11 +000064int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force);
Pavel Emelyanovac18e752008-01-22 06:02:14 -080065struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
Hannes Eder56bca312009-02-25 10:32:52 +000066 struct inet_frags *f, void *key, unsigned int hash)
67 __releases(&f->lock);
Pavel Emelyanov277e6502007-10-15 02:37:18 -070068
Pavel Emelyanov762cc402007-10-15 02:41:56 -070069static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f)
70{
71 if (atomic_dec_and_test(&q->refcnt))
72 inet_frag_destroy(q, f, NULL);
73}
74
Pavel Emelyanov5ab11c92007-10-15 02:24:19 -070075#endif