batman-adv: upgrade package to latest release 2017.0
[feed/routing.git] / batman-adv / files / compat-hacks.h
1 /* Please avoid adding hacks here - instead add it to mac80211/backports.git */
2
3 #undef CONFIG_MODULE_STRIPPED
4
5 #include <linux/version.h> /* LINUX_VERSION_CODE */
6 #include <linux/types.h>
7
8 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
9
10 #define dev_get_iflink(_net_dev) ((_net_dev)->iflink)
11
12 #endif /* < KERNEL_VERSION(4, 1, 0) */
13
14 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
15
16 #include <linux/netdevice.h>
17
18 #define netdev_master_upper_dev_link(dev, upper_dev, upper_priv, upper_info) ({\
19 BUILD_BUG_ON(upper_priv != NULL); \
20 BUILD_BUG_ON(upper_info != NULL); \
21 netdev_set_master(dev, upper_dev); \
22 })
23
24 #elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
25
26 #include <linux/netdevice.h>
27
28 #define netdev_master_upper_dev_link(dev, upper_dev, upper_priv, upper_info) ({\
29 BUILD_BUG_ON(upper_priv != NULL); \
30 BUILD_BUG_ON(upper_info != NULL); \
31 netdev_master_upper_dev_link(dev, upper_dev); \
32 })
33
34 #endif /* < KERNEL_VERSION(4, 5, 0) */
35
36
37 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
38
39 /* wild hack for batadv_getlink_net only */
40 #define get_link_net get_xstats_size || 1 ? fallback_net : (struct net*)netdev->rtnl_link_ops->get_xstats_size
41
42 #endif /* < KERNEL_VERSION(4, 0, 0) */
43
44
45 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
46
47 struct sk_buff *skb_checksum_trimmed(struct sk_buff *skb,
48 unsigned int transport_len,
49 __sum16(*skb_chkf)(struct sk_buff *skb));
50
51 int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed);
52
53 int ipv6_mc_check_mld(struct sk_buff *skb, struct sk_buff **skb_trimmed);
54
55 #endif /* < KERNEL_VERSION(4, 2, 0) */
56
57 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
58
59 #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0
60
61 static inline bool hlist_fake(struct hlist_node *h)
62 {
63 return h->pprev == &h->next;
64 }
65
66 #endif /* < KERNEL_VERSION(4, 3, 0) */
67
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
69
70 #include <linux/ethtool.h>
71
72 #define ethtool_link_ksettings batadv_ethtool_link_ksettings
73
74 struct batadv_ethtool_link_ksettings {
75 struct {
76 __u32 speed;
77 __u8 duplex;
78 } base;
79 };
80
81 #define __ethtool_get_link_ksettings(__dev, __link_settings) \
82 batadv_ethtool_get_link_ksettings(__dev, __link_settings)
83
84 static inline int
85 batadv_ethtool_get_link_ksettings(struct net_device *dev,
86 struct ethtool_link_ksettings *link_ksettings)
87 {
88 struct ethtool_cmd cmd;
89 int ret;
90
91 memset(&cmd, 0, sizeof(cmd));
92 ret = __ethtool_get_settings(dev, &cmd);
93
94 if (ret != 0)
95 return ret;
96
97 link_ksettings->base.duplex = cmd.duplex;
98 link_ksettings->base.speed = ethtool_cmd_speed(&cmd);
99
100 return 0;
101 }
102
103 #endif /* < KERNEL_VERSION(4, 6, 0) */
104
105 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
106
107 #define netif_trans_update batadv_netif_trans_update
108 static inline void batadv_netif_trans_update(struct net_device *dev)
109 {
110 dev->trans_start = jiffies;
111 }
112
113 #endif /* < KERNEL_VERSION(4, 7, 0) */
114
115
116 #include_next <linux/netlink.h>
117
118 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
119
120 #include_next <net/netlink.h>
121
122 static inline bool batadv_nla_need_padding_for_64bit(struct sk_buff *skb);
123
124 static inline int batadv_nla_align_64bit(struct sk_buff *skb, int padattr)
125 {
126 if (batadv_nla_need_padding_for_64bit(skb) &&
127 !nla_reserve(skb, padattr, 0))
128 return -EMSGSIZE;
129
130 return 0;
131 }
132
133 static inline struct nlattr *batadv__nla_reserve_64bit(struct sk_buff *skb,
134 int attrtype,
135 int attrlen, int padattr)
136 {
137 if (batadv_nla_need_padding_for_64bit(skb))
138 batadv_nla_align_64bit(skb, padattr);
139
140 return __nla_reserve(skb, attrtype, attrlen);
141 }
142
143 static inline void batadv__nla_put_64bit(struct sk_buff *skb, int attrtype,
144 int attrlen, const void *data,
145 int padattr)
146 {
147 struct nlattr *nla;
148
149 nla = batadv__nla_reserve_64bit(skb, attrtype, attrlen, padattr);
150 memcpy(nla_data(nla), data, attrlen);
151 }
152
153 static inline bool batadv_nla_need_padding_for_64bit(struct sk_buff *skb)
154 {
155 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
156 /* The nlattr header is 4 bytes in size, that's why we test
157 * if the skb->data _is_ aligned. A NOP attribute, plus
158 * nlattr header for next attribute, will make nla_data()
159 * 8-byte aligned.
160 */
161 if (IS_ALIGNED((unsigned long)skb_tail_pointer(skb), 8))
162 return true;
163 #endif
164 return false;
165 }
166
167 static inline int batadv_nla_total_size_64bit(int payload)
168 {
169 return NLA_ALIGN(nla_attr_size(payload))
170 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
171 + NLA_ALIGN(nla_attr_size(0))
172 #endif
173 ;
174 }
175
176 static inline int batadv_nla_put_64bit(struct sk_buff *skb, int attrtype,
177 int attrlen, const void *data,
178 int padattr)
179 {
180 size_t len;
181
182 if (batadv_nla_need_padding_for_64bit(skb))
183 len = batadv_nla_total_size_64bit(attrlen);
184 else
185 len = nla_total_size(attrlen);
186 if (unlikely(skb_tailroom(skb) < len))
187 return -EMSGSIZE;
188
189 batadv__nla_put_64bit(skb, attrtype, attrlen, data, padattr);
190 return 0;
191 }
192
193 #define nla_put_u64_64bit(_skb, _attrtype, _value, _padattr) \
194 batadv_nla_put_u64_64bit(_skb, _attrtype, _value, _padattr)
195 static inline int batadv_nla_put_u64_64bit(struct sk_buff *skb, int attrtype,
196 u64 value, int padattr)
197 {
198 return batadv_nla_put_64bit(skb, attrtype, sizeof(u64), &value,
199 padattr);
200 }
201
202 #endif /* < KERNEL_VERSION(4, 7, 0) */
203
204
205 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
206
207 #include_next <linux/cache.h>
208
209 /* hack for netlink.c which marked the family ops as ro */
210 #ifdef __ro_after_init
211 #undef __ro_after_init
212 #endif
213 #define __ro_after_init
214
215 #endif /* < KERNEL_VERSION(4, 10, 0) */