1 #ifndef __LINUX_NETDEVICE_WRAPPER_H
2 #define __LINUX_NETDEVICE_WRAPPER_H 1
4 #include_next <linux/netdevice.h>
8 #include <linux/version.h>
9 /* Before 2.6.21, struct net_device has a "struct class_device" member named
10 * class_dev. Beginning with 2.6.21, struct net_device instead has a "struct
11 * device" member named dev. Otherwise the usage of these members is pretty
13 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
14 #define NETDEV_DEV_MEMBER class_dev
16 #define NETDEV_DEV_MEMBER dev
20 #define to_net_dev(class) container_of(class, struct net_device, NETDEV_DEV_MEMBER)
23 #ifdef HAVE_RHEL_OVS_HOOK
24 extern struct sk_buff *(*openvswitch_handle_frame_hook)(struct sk_buff *skb);
25 extern int nr_bridges;
28 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
30 struct net *dev_net(const struct net_device *dev)
34 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
42 void dev_net_set(struct net_device *dev, const struct net *net)
48 #endif /* linux kernel < 2.6.26 */
50 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
51 #define NETIF_F_NETNS_LOCAL 0
54 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
55 #define proc_net init_net.proc_net
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
59 typedef int netdev_tx_t;
62 #ifndef for_each_netdev
63 /* Linux before 2.6.22 didn't have for_each_netdev at all. */
64 #define for_each_netdev(net, d) for (d = dev_base; d; d = d->next)
65 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
66 /* Linux 2.6.24 added a network namespace pointer to the macro. */
67 #undef for_each_netdev
68 #define for_each_netdev(net, d) list_for_each_entry(d, &dev_base_head, dev_list)
71 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
72 #define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
75 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
76 extern void unregister_netdevice_queue(struct net_device *dev,
77 struct list_head *head);
78 extern void unregister_netdevice_many(struct list_head *head);
81 #ifndef HAVE_DEV_DISABLE_LRO
82 extern void dev_disable_lro(struct net_device *dev);
85 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) || \
86 defined HAVE_RHEL_OVS_HOOK
87 static inline int netdev_rx_handler_register(struct net_device *dev,
89 void *rx_handler_data)
91 #ifdef HAVE_RHEL_OVS_HOOK
92 rcu_assign_pointer(dev->ax25_ptr, rx_handler_data);
94 rcu_assign_pointer(openvswitch_handle_frame_hook, rx_handler);
98 rcu_assign_pointer(dev->br_port, rx_handler_data);
102 static inline void netdev_rx_handler_unregister(struct net_device *dev)
104 #ifdef HAVE_RHEL_OVS_HOOK
105 rcu_assign_pointer(dev->ax25_ptr, NULL);
107 if (--nr_bridges <= 0)
108 rcu_assign_pointer(openvswitch_handle_frame_hook, NULL);
110 rcu_assign_pointer(dev->br_port, NULL);
115 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
116 #undef SET_ETHTOOL_OPS
117 #define SET_ETHTOOL_OPS(netdev, ops) \
118 ((netdev)->ethtool_ops = (struct ethtool_ops *)(ops))
121 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
122 #define dev_get_by_name(net, name) dev_get_by_name(name)
123 #define dev_get_by_index(net, ifindex) dev_get_by_index(ifindex)
124 #define __dev_get_by_name(net, name) __dev_get_by_name(name)
125 #define __dev_get_by_index(net, ifindex) __dev_get_by_index(ifindex)
126 #define dev_get_by_index_rcu(net, ifindex) dev_get_by_index_rcu(ifindex)
129 #ifndef HAVE_DEV_GET_BY_INDEX_RCU
130 static inline struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
132 struct net_device *dev;
134 read_lock(&dev_base_lock);
135 dev = __dev_get_by_index(net, ifindex);
136 read_unlock(&dev_base_lock);
143 #define NETIF_F_FSO 0
146 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
147 #define NETIF_F_FCOE_CRC (1 << 24) /* FCoE CRC32 */
150 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
151 #define NETIF_F_IPV6_CSUM 16 /* Can checksum TCP/UDP over IPV6 */
153 #define NETIF_F_V4_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)
154 #define NETIF_F_V6_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)
157 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
158 #define skb_gso_segment rpl_skb_gso_segment
159 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb, u32 features);
161 #define netif_skb_features rpl_netif_skb_features
162 u32 rpl_netif_skb_features(struct sk_buff *skb);
164 #define netif_needs_gso rpl_netif_needs_gso
165 static inline int rpl_netif_needs_gso(struct sk_buff *skb, int features)
167 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
168 unlikely(skb->ip_summed != CHECKSUM_PARTIAL));
172 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
173 typedef u32 netdev_features_t;
176 #ifndef HAVE___SKB_GSO_SEGMENT
177 static inline struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
178 netdev_features_t features,
181 return skb_gso_segment(skb, features);
185 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
187 /* XEN dom0 networking assumes dev->master is bond device
188 * and it tries to access bond private structure from dev->master
189 * ptr on receive path. This causes panic. Therefore it is better
190 * not to backport this API.
192 static inline int netdev_master_upper_dev_link(struct net_device *dev,
193 struct net_device *upper_dev)
198 static inline void netdev_upper_dev_unlink(struct net_device *dev,
199 struct net_device *upper_dev)