forked from dtaht/sch_cake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cobalt_compat.h
126 lines (101 loc) · 3.2 KB
/
cobalt_compat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef __NET_SCHED_COBALT_COMPAT_H
#define __NET_SCHED_COBALT_COMPAT_H
/* Backport some stuff if needed.
*/
#if KERNEL_VERSION(3, 11, 0) > LINUX_VERSION_CODE
#define ktime_add_ms(kt, msec) ktime_add_ns(kt, msec * NSEC_PER_MSEC)
#endif
#if KERNEL_VERSION(3, 14, 0) > LINUX_VERSION_CODE
static inline u32 reciprocal_scale(u32 val, u32 ep_ro)
{
return (u32)(((u64) val * ep_ro) >> 32);
}
#endif
#if KERNEL_VERSION(3, 15, 0) > LINUX_VERSION_CODE
static inline void kvfree(const void *addr)
{
if (is_vmalloc_addr(addr))
vfree(addr);
else
kfree(addr);
}
#endif
#if KERNEL_VERSION(3, 16, 0) > LINUX_VERSION_CODE
#define ktime_after(cmp1, cmp2) ktime_compare(cmp1, cmp2) > 0
#define ktime_before(cmp1, cmp2) ktime_compare(cmp1, cmp2) < 0
#endif
#if KERNEL_VERSION(3, 17, 0) > LINUX_VERSION_CODE
#define ktime_get_ns() ktime_to_ns(ktime_get())
#endif
/* 3.18 > 4.7 use 3 arg, everything else uses 2 arg versions
* of qdisc_watchdog_schedule_ns
*/
#if ((KERNEL_VERSION(3, 18, 0) <= LINUX_VERSION_CODE) && (KERNEL_VERSION(4, 8, 0) > LINUX_VERSION_CODE))
#define qdisc_watchdog_schedule_ns(_a, _b) qdisc_watchdog_schedule_ns(_a, _b, true);
#endif
#if KERNEL_VERSION(3, 18, 0) > LINUX_VERSION_CODE
static inline void qdisc_qstats_backlog_dec(struct Qdisc *sch,
const struct sk_buff *skb)
{
sch->qstats.backlog -= qdisc_pkt_len(skb);
}
static inline void qdisc_qstats_backlog_inc(struct Qdisc *sch,
const struct sk_buff *skb)
{
sch->qstats.backlog += qdisc_pkt_len(skb);
}
static inline void __qdisc_qstats_drop(struct Qdisc *sch, int count)
{
sch->qstats.drops += count;
}
static inline void qdisc_qstats_drop(struct Qdisc *sch)
{
sch->qstats.drops++;
}
#endif
#if KERNEL_VERSION(4, 1, 0) > LINUX_VERSION_CODE
#define TCPOPT_FASTOPEN 34
#endif
#if !defined(IS_REACHABLE)
#define IS_REACHABLE(option) (config_enabled(option) || \
(config_enabled(option##_MODULE) && config_enabled(MODULE)))
#endif
#if KERNEL_VERSION(4, 4, 114) > LINUX_VERSION_CODE
static inline unsigned int __tcp_hdrlen(const struct tcphdr *th)
{
return th->doff * 4;
}
#endif
#if KERNEL_VERSION(4, 7, 0) > LINUX_VERSION_CODE
#define nla_put_u64_64bit(skb, attrtype, value, padattr) nla_put_u64(skb, attrtype, value)
#endif
#if KERNEL_VERSION(4, 12, 0) > LINUX_VERSION_CODE
static void *kvzalloc(size_t sz, gfp_t flags)
{
void *ptr = kzalloc(sz, flags);
if (!ptr)
ptr = vzalloc(sz);
return ptr;
}
#endif
/* save the best till last
* qdisc_tree_reduce_backlog appears in kernel from:
3.16.37 onward
not in 3.17
3.18.37
not in 3.19
not in 4.0
4.1.27 onward
not in 4.2
not in 4.3
4.4.11 onward
4.5.5 onward
*/
#if ((KERNEL_VERSION(3, 0, 0) <= LINUX_VERSION_CODE) && (KERNEL_VERSION(3, 16, 37) > LINUX_VERSION_CODE)) || \
((KERNEL_VERSION(3, 18, 0) <= LINUX_VERSION_CODE) && (KERNEL_VERSION(3, 18, 37) > LINUX_VERSION_CODE)) || \
((KERNEL_VERSION(4, 1, 0) <= LINUX_VERSION_CODE) && (KERNEL_VERSION(4, 1, 27) > LINUX_VERSION_CODE)) || \
((KERNEL_VERSION(4, 4, 0) <= LINUX_VERSION_CODE) && (KERNEL_VERSION(4, 4, 11) > LINUX_VERSION_CODE)) || \
((KERNEL_VERSION(4, 5, 0) <= LINUX_VERSION_CODE) && (KERNEL_VERSION(4, 5, 5) > LINUX_VERSION_CODE))
#define qdisc_tree_reduce_backlog(_a, _b, _c) qdisc_tree_decrease_qlen(_a, _b)
#endif
#endif