inet_frag.h 2.8 KB
Newer Older
1 2 3
#ifndef __NET_FRAG_H__
#define __NET_FRAG_H__

4
struct netns_frags {
5
	int			nqueues;
6
	struct list_head	lru_list;
7

8 9 10 11
	/* Its important for performance to keep lru_list and mem on
	 * separate cachelines
	 */
	atomic_t		mem ____cacheline_aligned_in_smp;
12 13
	/* sysctls */
	int			timeout;
14 15
	int			high_thresh;
	int			low_thresh;
16 17
};

18 19 20
struct inet_frag_queue {
	spinlock_t		lock;
	struct timer_list	timer;      /* when will this queue expire? */
21 22 23
	struct list_head	lru_list;   /* lru list member */
	struct hlist_node	list;
	atomic_t		refcnt;
24
	struct sk_buff		*fragments; /* list of received fragments */
25
	struct sk_buff		*fragments_tail;
26 27 28 29 30
	ktime_t			stamp;
	int			len;        /* total length of orig datagram */
	int			meat;
	__u8			last_in;    /* first/last segment arrived? */

31 32 33
#define INET_FRAG_COMPLETE	4
#define INET_FRAG_FIRST_IN	2
#define INET_FRAG_LAST_IN	1
34 35

	u16			max_size;
36 37

	struct netns_frags	*net;
38 39
};

40 41 42 43
#define INETFRAGS_HASHSZ		64

struct inet_frags {
	struct hlist_head	hash[INETFRAGS_HASHSZ];
44 45 46 47
	/* This rwlock is a global lock (seperate per IPv4, IPv6 and
	 * netfilter). Important to keep this on a seperate cacheline.
	 */
	rwlock_t		lock ____cacheline_aligned_in_smp;
48
	int			secret_interval;
49
	struct timer_list	secret_timer;
50 51
	u32			rnd;
	int			qsize;
52 53

	unsigned int		(*hashfn)(struct inet_frag_queue *);
54
	bool			(*match)(struct inet_frag_queue *q, void *arg);
55 56
	void			(*constructor)(struct inet_frag_queue *q,
						void *arg);
57 58
	void			(*destructor)(struct inet_frag_queue *);
	void			(*skb_free)(struct sk_buff *);
59
	void			(*frag_expire)(unsigned long data);
60 61 62 63 64
};

void inet_frags_init(struct inet_frags *);
void inet_frags_fini(struct inet_frags *);

65
void inet_frags_init_net(struct netns_frags *nf);
66
void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f);
67

68
void inet_frag_kill(struct inet_frag_queue *q, struct inet_frags *f);
69 70
void inet_frag_destroy(struct inet_frag_queue *q,
				struct inet_frags *f, int *work);
71
int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force);
72
struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
73 74
		struct inet_frags *f, void *key, unsigned int hash)
	__releases(&f->lock);
75

P
Pavel Emelyanov 已提交
76 77 78 79 80 81
static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f)
{
	if (atomic_dec_and_test(&q->refcnt))
		inet_frag_destroy(q, f, NULL);
}

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
/* Memory Tracking Functions. */

static inline int frag_mem_limit(struct netns_frags *nf)
{
	return atomic_read(&nf->mem);
}

static inline void sub_frag_mem_limit(struct inet_frag_queue *q, int i)
{
	atomic_sub(i, &q->net->mem);
}

static inline void add_frag_mem_limit(struct inet_frag_queue *q, int i)
{
	atomic_add(i, &q->net->mem);
}

static inline void init_frag_mem_limit(struct netns_frags *nf)
{
	atomic_set(&nf->mem, 0);
}

static inline int sum_frag_mem_limit(struct netns_frags *nf)
{
	return atomic_read(&nf->mem);
}

109
#endif