ipvlan.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. */
  10. #ifndef __IPVLAN_H
  11. #define __IPVLAN_H
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/rculist.h>
  17. #include <linux/notifier.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/if_arp.h>
  21. #include <linux/if_link.h>
  22. #include <linux/if_vlan.h>
  23. #include <linux/ip.h>
  24. #include <linux/inetdevice.h>
  25. #include <net/ip.h>
  26. #include <net/ip6_route.h>
  27. #include <net/rtnetlink.h>
  28. #include <net/route.h>
  29. #include <net/addrconf.h>
  30. #define IPVLAN_DRV "ipvlan"
  31. #define IPV_DRV_VER "0.1"
  32. #define IPVLAN_HASH_SIZE (1 << BITS_PER_BYTE)
  33. #define IPVLAN_HASH_MASK (IPVLAN_HASH_SIZE - 1)
  34. #define IPVLAN_MAC_FILTER_BITS 8
  35. #define IPVLAN_MAC_FILTER_SIZE (1 << IPVLAN_MAC_FILTER_BITS)
  36. #define IPVLAN_MAC_FILTER_MASK (IPVLAN_MAC_FILTER_SIZE - 1)
  37. #define IPVLAN_QBACKLOG_LIMIT 1000
  38. typedef enum {
  39. IPVL_IPV6 = 0,
  40. IPVL_ICMPV6,
  41. IPVL_IPV4,
  42. IPVL_ARP,
  43. } ipvl_hdr_type;
  44. struct ipvl_pcpu_stats {
  45. u64 rx_pkts;
  46. u64 rx_bytes;
  47. u64 rx_mcast;
  48. u64 tx_pkts;
  49. u64 tx_bytes;
  50. struct u64_stats_sync syncp;
  51. u32 rx_errs;
  52. u32 tx_drps;
  53. };
  54. struct ipvl_port;
  55. struct ipvl_dev {
  56. struct net_device *dev;
  57. struct list_head pnode;
  58. struct ipvl_port *port;
  59. struct net_device *phy_dev;
  60. struct list_head addrs;
  61. struct ipvl_pcpu_stats __percpu *pcpu_stats;
  62. DECLARE_BITMAP(mac_filters, IPVLAN_MAC_FILTER_SIZE);
  63. netdev_features_t sfeatures;
  64. u32 msg_enable;
  65. u16 mtu_adj;
  66. };
  67. struct ipvl_addr {
  68. struct ipvl_dev *master; /* Back pointer to master */
  69. union {
  70. struct in6_addr ip6; /* IPv6 address on logical interface */
  71. struct in_addr ip4; /* IPv4 address on logical interface */
  72. } ipu;
  73. #define ip6addr ipu.ip6
  74. #define ip4addr ipu.ip4
  75. struct hlist_node hlnode; /* Hash-table linkage */
  76. struct list_head anode; /* logical-interface linkage */
  77. struct rcu_head rcu;
  78. ipvl_hdr_type atype;
  79. };
  80. struct ipvl_port {
  81. struct net_device *dev;
  82. struct hlist_head hlhead[IPVLAN_HASH_SIZE];
  83. struct list_head ipvlans;
  84. struct rcu_head rcu;
  85. struct work_struct wq;
  86. struct sk_buff_head backlog;
  87. int count;
  88. u16 mode;
  89. };
  90. static inline struct ipvl_port *ipvlan_port_get_rcu(const struct net_device *d)
  91. {
  92. return rcu_dereference(d->rx_handler_data);
  93. }
  94. static inline struct ipvl_port *ipvlan_port_get_rcu_bh(const struct net_device *d)
  95. {
  96. return rcu_dereference_bh(d->rx_handler_data);
  97. }
  98. static inline struct ipvl_port *ipvlan_port_get_rtnl(const struct net_device *d)
  99. {
  100. return rtnl_dereference(d->rx_handler_data);
  101. }
  102. void ipvlan_adjust_mtu(struct ipvl_dev *ipvlan, struct net_device *dev);
  103. void ipvlan_set_port_mode(struct ipvl_port *port, u32 nval);
  104. void ipvlan_init_secret(void);
  105. unsigned int ipvlan_mac_hash(const unsigned char *addr);
  106. rx_handler_result_t ipvlan_handle_frame(struct sk_buff **pskb);
  107. void ipvlan_process_multicast(struct work_struct *work);
  108. int ipvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev);
  109. void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr);
  110. struct ipvl_addr *ipvlan_find_addr(const struct ipvl_dev *ipvlan,
  111. const void *iaddr, bool is_v6);
  112. bool ipvlan_addr_busy(struct ipvl_port *port, void *iaddr, bool is_v6);
  113. struct ipvl_addr *ipvlan_ht_addr_lookup(const struct ipvl_port *port,
  114. const void *iaddr, bool is_v6);
  115. void ipvlan_ht_addr_del(struct ipvl_addr *addr);
  116. #endif /* __IPVLAN_H */