datapath: Add support for lwtunnel
[cascardo/ovs.git] / datapath / linux / compat / include / linux / etherdevice.h
1 #ifndef __LINUX_ETHERDEVICE_WRAPPER_H
2 #define __LINUX_ETHERDEVICE_WRAPPER_H 1
3
4 #include <linux/version.h>
5 #include_next <linux/etherdevice.h>
6
7 #ifndef HAVE_ETH_HW_ADDR_RANDOM
8 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
9 static inline void eth_hw_addr_random(struct net_device *dev)
10 {
11         random_ether_addr(dev->dev_addr);
12 }
13 #elif LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)
14 static inline void eth_hw_addr_random(struct net_device *dev)
15 {
16         dev_hw_addr_random(dev, dev->dev_addr);
17 }
18 #endif
19 #endif
20
21 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0)
22 #define eth_mac_addr rpl_eth_mac_addr
23 static inline int eth_mac_addr(struct net_device *dev, void *p)
24 {
25         struct sockaddr *addr = p;
26
27         if (!is_valid_ether_addr(addr->sa_data))
28                 return -EADDRNOTAVAIL;
29 #ifdef NET_ADDR_RANDOM
30         dev->addr_assign_type &= ~NET_ADDR_RANDOM;
31 #endif
32         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
33         return 0;
34 }
35 #endif
36
37 #ifndef HAVE_ETHER_ADDR_COPY
38 static inline void ether_addr_copy(u8 *dst, const u8 *src)
39 {
40 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
41         *(u32 *)dst = *(const u32 *)src;
42         *(u16 *)(dst + 4) = *(const u16 *)(src + 4);
43 #else
44         u16 *a = (u16 *)dst;
45         const u16 *b = (const u16 *)src;
46
47         a[0] = b[0];
48         a[1] = b[1];
49         a[2] = b[2];
50 #endif
51 }
52 #endif
53
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
55 #define eth_proto_is_802_3 rpl_eth_proto_is_802_3
56 static inline bool eth_proto_is_802_3(__be16 proto)
57 {
58 #ifndef __BIG_ENDIAN
59         /* if CPU is little endian mask off bits representing LSB */
60         proto &= htons(0xFF00);
61 #endif
62         /* cast both to u16 and compare since LSB can be ignored */
63         return (__force u16)proto >= (__force u16)htons(ETH_P_802_3_MIN);
64 }
65 #endif
66
67 #define ether_addr_equal rpl_ether_addr_equal
68 static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2)
69 {
70 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
71         u32 fold = ((*(const u32 *)addr1) ^ (*(const u32 *)addr2)) |
72                    ((*(const u16 *)(addr1 + 4)) ^ (*(const u16 *)(addr2 + 4)));
73
74         return fold == 0;
75 #else
76         const u16 *a = (const u16 *)addr1;
77         const u16 *b = (const u16 *)addr2;
78
79         return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) == 0;
80 #endif
81 }
82
83 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
84 #define eth_gro_receive rpl_eth_gro_receive
85 struct sk_buff **rpl_eth_gro_receive(struct sk_buff **head,
86                                      struct sk_buff *skb);
87
88 #define eth_gro_complete rpl_eth_gro_complete
89 int rpl_eth_gro_complete(struct sk_buff *skb, int nhoff);
90 #endif
91
92 #endif