ipvlan.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. int ipv4cnt;
  62. int ipv6cnt;
  63. struct ipvl_pcpu_stats __percpu *pcpu_stats;
  64. DECLARE_BITMAP(mac_filters, IPVLAN_MAC_FILTER_SIZE);
  65. netdev_features_t sfeatures;
  66. u32 msg_enable;
  67. u16 mtu_adj;
  68. };
  69. struct ipvl_addr {
  70. struct ipvl_dev *master; /* Back pointer to master */
  71. union {
  72. struct in6_addr ip6; /* IPv6 address on logical interface */
  73. struct in_addr ip4; /* IPv4 address on logical interface */
  74. } ipu;
  75. #define ip6addr ipu.ip6
  76. #define ip4addr ipu.ip4
  77. struct hlist_node hlnode; /* Hash-table linkage */
  78. struct list_head anode; /* logical-interface linkage */
  79. struct rcu_head rcu;
  80. ipvl_hdr_type atype;
  81. };
  82. struct ipvl_port {
  83. struct net_device *dev;
  84. struct hlist_head hlhead[IPVLAN_HASH_SIZE];
  85. struct list_head ipvlans;
  86. struct rcu_head rcu;
  87. struct work_struct wq;
  88. struct sk_buff_head backlog;
  89. int count;
  90. u16 mode;
  91. };
  92. static inline struct ipvl_port *ipvlan_port_get_rcu(const struct net_device *d)
  93. {
  94. return rcu_dereference(d->rx_handler_data);
  95. }
  96. static inline struct ipvl_port *ipvlan_port_get_rtnl(const struct net_device *d)
  97. {
  98. return rtnl_dereference(d->rx_handler_data);
  99. }
  100. void ipvlan_adjust_mtu(struct ipvl_dev *ipvlan, struct net_device *dev);
  101. void ipvlan_set_port_mode(struct ipvl_port *port, u32 nval);
  102. void ipvlan_init_secret(void);
  103. unsigned int ipvlan_mac_hash(const unsigned char *addr);
  104. rx_handler_result_t ipvlan_handle_frame(struct sk_buff **pskb);
  105. void ipvlan_process_multicast(struct work_struct *work);
  106. int ipvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev);
  107. void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr);
  108. struct ipvl_addr *ipvlan_find_addr(const struct ipvl_dev *ipvlan,
  109. const void *iaddr, bool is_v6);
  110. bool ipvlan_addr_busy(struct ipvl_port *port, void *iaddr, bool is_v6);
  111. struct ipvl_addr *ipvlan_ht_addr_lookup(const struct ipvl_port *port,
  112. const void *iaddr, bool is_v6);
  113. void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync);
  114. #endif /* __IPVLAN_H */