af91f418fdca5620b10344803ca1497d657efe84
[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 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
37
38 struct sk_buff *skb_checksum_trimmed(struct sk_buff *skb,
39 unsigned int transport_len,
40 __sum16(*skb_chkf)(struct sk_buff *skb));
41
42 int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed);
43
44 int ipv6_mc_check_mld(struct sk_buff *skb, struct sk_buff **skb_trimmed);
45
46 #endif /* < KERNEL_VERSION(4, 2, 0) */
47
48 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
49
50 #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0
51
52 static inline bool hlist_fake(struct hlist_node *h)
53 {
54 return h->pprev == &h->next;
55 }
56
57 #endif /* < KERNEL_VERSION(4, 3, 0) */
58
59 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
60
61 #include <linux/ethtool.h>
62
63 #define ethtool_link_ksettings batadv_ethtool_link_ksettings
64
65 struct batadv_ethtool_link_ksettings {
66 struct {
67 __u32 speed;
68 __u8 duplex;
69 } base;
70 };
71
72 #define __ethtool_get_link_ksettings(__dev, __link_settings) \
73 batadv_ethtool_get_link_ksettings(__dev, __link_settings)
74
75 static inline int
76 batadv_ethtool_get_link_ksettings(struct net_device *dev,
77 struct ethtool_link_ksettings *link_ksettings)
78 {
79 struct ethtool_cmd cmd;
80 int ret;
81
82 memset(&cmd, 0, sizeof(cmd));
83 ret = __ethtool_get_settings(dev, &cmd);
84
85 if (ret != 0)
86 return ret;
87
88 link_ksettings->base.duplex = cmd.duplex;
89 link_ksettings->base.speed = ethtool_cmd_speed(&cmd);
90
91 return 0;
92 }
93
94 #endif /* < KERNEL_VERSION(4, 6, 0) */
95
96 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
97
98 #define netif_trans_update batadv_netif_trans_update
99 static inline void batadv_netif_trans_update(struct net_device *dev)
100 {
101 dev->trans_start = jiffies;
102 }
103
104 #endif /* < KERNEL_VERSION(4, 7, 0) */
105
106
107 #include_next <linux/netlink.h>
108
109 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
110
111 #include_next <net/netlink.h>
112
113 static inline bool batadv_nla_need_padding_for_64bit(struct sk_buff *skb);
114
115 static inline int batadv_nla_align_64bit(struct sk_buff *skb, int padattr)
116 {
117 if (batadv_nla_need_padding_for_64bit(skb) &&
118 !nla_reserve(skb, padattr, 0))
119 return -EMSGSIZE;
120
121 return 0;
122 }
123
124 static inline struct nlattr *batadv__nla_reserve_64bit(struct sk_buff *skb,
125 int attrtype,
126 int attrlen, int padattr)
127 {
128 if (batadv_nla_need_padding_for_64bit(skb))
129 batadv_nla_align_64bit(skb, padattr);
130
131 return __nla_reserve(skb, attrtype, attrlen);
132 }
133
134 static inline void batadv__nla_put_64bit(struct sk_buff *skb, int attrtype,
135 int attrlen, const void *data,
136 int padattr)
137 {
138 struct nlattr *nla;
139
140 nla = batadv__nla_reserve_64bit(skb, attrtype, attrlen, padattr);
141 memcpy(nla_data(nla), data, attrlen);
142 }
143
144 static inline bool batadv_nla_need_padding_for_64bit(struct sk_buff *skb)
145 {
146 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
147 /* The nlattr header is 4 bytes in size, that's why we test
148 * if the skb->data _is_ aligned. A NOP attribute, plus
149 * nlattr header for next attribute, will make nla_data()
150 * 8-byte aligned.
151 */
152 if (IS_ALIGNED((unsigned long)skb_tail_pointer(skb), 8))
153 return true;
154 #endif
155 return false;
156 }
157
158 static inline int batadv_nla_total_size_64bit(int payload)
159 {
160 return NLA_ALIGN(nla_attr_size(payload))
161 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
162 + NLA_ALIGN(nla_attr_size(0))
163 #endif
164 ;
165 }
166
167 static inline int batadv_nla_put_64bit(struct sk_buff *skb, int attrtype,
168 int attrlen, const void *data,
169 int padattr)
170 {
171 size_t len;
172
173 if (batadv_nla_need_padding_for_64bit(skb))
174 len = batadv_nla_total_size_64bit(attrlen);
175 else
176 len = nla_total_size(attrlen);
177 if (unlikely(skb_tailroom(skb) < len))
178 return -EMSGSIZE;
179
180 batadv__nla_put_64bit(skb, attrtype, attrlen, data, padattr);
181 return 0;
182 }
183
184 #define nla_put_u64_64bit(_skb, _attrtype, _value, _padattr) \
185 batadv_nla_put_u64_64bit(_skb, _attrtype, _value, _padattr)
186 static inline int batadv_nla_put_u64_64bit(struct sk_buff *skb, int attrtype,
187 u64 value, int padattr)
188 {
189 return batadv_nla_put_64bit(skb, attrtype, sizeof(u64), &value,
190 padattr);
191 }
192
193 #endif /* < KERNEL_VERSION(4, 7, 0) */
194
195
196 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
197
198 #include_next <linux/cache.h>
199
200 /* hack for netlink.c which marked the family ops as ro */
201 #ifdef __ro_after_init
202 #undef __ro_after_init
203 #endif
204 #define __ro_after_init
205
206 #endif /* < KERNEL_VERSION(4, 10, 0) */