if_macvlan.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. struct macvlan_port;
  9. struct macvtap_queue;
  10. /**
  11. * struct macvlan_rx_stats - MACVLAN percpu rx stats
  12. * @rx_packets: number of received packets
  13. * @rx_bytes: number of received bytes
  14. * @multicast: number of received multicast packets
  15. * @rx_errors: number of errors
  16. */
  17. struct macvlan_rx_stats {
  18. unsigned long rx_packets;
  19. unsigned long rx_bytes;
  20. unsigned long multicast;
  21. unsigned long rx_errors;
  22. };
  23. struct macvlan_dev {
  24. struct net_device *dev;
  25. struct list_head list;
  26. struct hlist_node hlist;
  27. struct macvlan_port *port;
  28. struct net_device *lowerdev;
  29. struct macvlan_rx_stats __percpu *rx_stats;
  30. enum macvlan_mode mode;
  31. int (*receive)(struct sk_buff *skb);
  32. int (*forward)(struct net_device *dev, struct sk_buff *skb);
  33. struct macvtap_queue *tap;
  34. };
  35. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  36. unsigned int len, bool success,
  37. bool multicast)
  38. {
  39. struct macvlan_rx_stats *rx_stats;
  40. rx_stats = per_cpu_ptr(vlan->rx_stats, smp_processor_id());
  41. if (likely(success)) {
  42. rx_stats->rx_packets++;;
  43. rx_stats->rx_bytes += len;
  44. if (multicast)
  45. rx_stats->multicast++;
  46. } else {
  47. rx_stats->rx_errors++;
  48. }
  49. }
  50. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  51. struct nlattr *tb[], struct nlattr *data[],
  52. int (*receive)(struct sk_buff *skb),
  53. int (*forward)(struct net_device *dev,
  54. struct sk_buff *skb));
  55. extern void macvlan_count_rx(const struct macvlan_dev *vlan,
  56. unsigned int len, bool success,
  57. bool multicast);
  58. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  59. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  60. extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
  61. struct net_device *dev);
  62. extern struct sk_buff *(*macvlan_handle_frame_hook)(struct sk_buff *);
  63. #endif /* _LINUX_IF_MACVLAN_H */