if_macvlan.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _LINUX_IF_MACVLAN_H
  2. #define _LINUX_IF_MACVLAN_H
  3. #include <linux/if_link.h>
  4. #include <linux/list.h>
  5. #include <linux/netdevice.h>
  6. #include <linux/netlink.h>
  7. #include <net/netlink.h>
  8. #if defined(CONFIG_MACVTAP) || defined(CONFIG_MACVTAP_MODULE)
  9. struct socket *macvtap_get_socket(struct file *);
  10. #else
  11. #include <linux/err.h>
  12. #include <linux/errno.h>
  13. struct file;
  14. struct socket;
  15. static inline struct socket *macvtap_get_socket(struct file *f)
  16. {
  17. return ERR_PTR(-EINVAL);
  18. }
  19. #endif /* CONFIG_MACVTAP */
  20. struct macvlan_port;
  21. struct macvtap_queue;
  22. /**
  23. * struct macvlan_rx_stats - MACVLAN percpu rx stats
  24. * @rx_packets: number of received packets
  25. * @rx_bytes: number of received bytes
  26. * @multicast: number of received multicast packets
  27. * @rx_errors: number of errors
  28. */
  29. struct macvlan_rx_stats {
  30. unsigned long rx_packets;
  31. unsigned long rx_bytes;
  32. unsigned long multicast;
  33. unsigned long rx_errors;
  34. };
  35. struct macvlan_dev {
  36. struct net_device *dev;
  37. struct list_head list;
  38. struct hlist_node hlist;
  39. struct macvlan_port *port;
  40. struct net_device *lowerdev;
  41. struct macvlan_rx_stats __percpu *rx_stats;
  42. enum macvlan_mode mode;
  43. int (*receive)(struct sk_buff *skb);
  44. int (*forward)(struct net_device *dev, struct sk_buff *skb);
  45. struct macvtap_queue *tap;
  46. };
  47. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  48. unsigned int len, bool success,
  49. bool multicast)
  50. {
  51. struct macvlan_rx_stats *rx_stats;
  52. rx_stats = per_cpu_ptr(vlan->rx_stats, smp_processor_id());
  53. if (likely(success)) {
  54. rx_stats->rx_packets++;;
  55. rx_stats->rx_bytes += len;
  56. if (multicast)
  57. rx_stats->multicast++;
  58. } else {
  59. rx_stats->rx_errors++;
  60. }
  61. }
  62. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  63. struct nlattr *tb[], struct nlattr *data[],
  64. int (*receive)(struct sk_buff *skb),
  65. int (*forward)(struct net_device *dev,
  66. struct sk_buff *skb));
  67. extern void macvlan_count_rx(const struct macvlan_dev *vlan,
  68. unsigned int len, bool success,
  69. bool multicast);
  70. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  71. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  72. extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
  73. struct net_device *dev);
  74. extern struct sk_buff *(*macvlan_handle_frame_hook)(struct macvlan_port *,
  75. struct sk_buff *);
  76. #endif /* _LINUX_IF_MACVLAN_H */