0c0c0761912602a58d544d252e9f8bfaddbe356d
[cascardo/ovs.git] / datapath / linux / compat / include / net / inet_frag.h
1 #ifndef __NET_INET_FRAG_WRAPPER_H
2 #define __NET_INET_FRAG_WRAPPER_H 1
3
4 #include <linux/version.h>
5 #include_next <net/inet_frag.h>
6
7 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)
8 #define inet_frag_evictor(nf, f, force)                                 \
9         do {                                                            \
10                 if (force || atomic_read(&nf->mem) > nf->high_thresh) { \
11                         inet_frag_evictor(nf, f);                       \
12                 }                                                       \
13         } while (0)
14 #endif
15
16 #ifdef OVS_FRAGMENT_BACKPORT
17 #ifdef HAVE_INET_FRAGS_LAST_IN
18 #define q_flags(q) (q->last_in)
19 #define qp_flags(qp) (qp->q.last_in)
20 #else
21 #define q_flags(q) (q->flags)
22 #define qp_flags(qp) (qp->q.flags)
23 #endif
24
25 /**
26  * struct ovs_inet_frag_queue - fragment queue
27  *
28  * Wrap the system inet_frag_queue to provide a list evictor.
29  *
30  * @list_evictor: list of queues to forcefully evict (e.g. due to low memory)
31  */
32 struct ovs_inet_frag_queue {
33         struct inet_frag_queue  fq;
34         struct hlist_node       list_evictor;
35 };
36
37 static inline bool rpl_inet_frag_evicting(struct inet_frag_queue *q)
38 {
39 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0)
40         return (q_flags(q) & INET_FRAG_FIRST_IN) && q->fragments != NULL;
41 #else
42         struct ovs_inet_frag_queue *ofq = (struct ovs_inet_frag_queue *)q;
43         return !hlist_unhashed(&ofq->list_evictor);
44 #endif
45 }
46 #define inet_frag_evicting rpl_inet_frag_evicting
47
48 static unsigned int rpl_frag_percpu_counter_batch = 130000;
49 #define frag_percpu_counter_batch rpl_frag_percpu_counter_batch
50
51 static inline void rpl_sub_frag_mem_limit(struct netns_frags *nf, int i)
52 {
53         __percpu_counter_add(&nf->mem, -i, frag_percpu_counter_batch);
54 }
55 #define sub_frag_mem_limit rpl_sub_frag_mem_limit
56
57 static inline void rpl_add_frag_mem_limit(struct netns_frags *nf, int i)
58 {
59         __percpu_counter_add(&nf->mem, i, frag_percpu_counter_batch);
60 }
61 #define add_frag_mem_limit rpl_add_frag_mem_limit
62
63 int rpl_inet_frags_init(struct inet_frags *f);
64 #define inet_frags_init rpl_inet_frags_init
65
66 void rpl_inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f);
67 #define inet_frags_exit_net rpl_inet_frags_exit_net
68
69 void rpl_inet_frag_destroy(struct inet_frag_queue *q, struct inet_frags *f);
70 #define inet_frag_destroy(q, f, work) rpl_inet_frag_destroy(q, f)
71 #endif /* OVS_FRAGMENT_BACKPORT */
72
73 #endif /* inet_frag.h */