ipvlan.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. typedef enum {
  38. IPVL_IPV6 = 0,
  39. IPVL_ICMPV6,
  40. IPVL_IPV4,
  41. IPVL_ARP,
  42. } ipvl_hdr_type;
  43. struct ipvl_pcpu_stats {
  44. u64 rx_pkts;
  45. u64 rx_bytes;
  46. u64 rx_mcast;
  47. u64 tx_pkts;
  48. u64 tx_bytes;
  49. struct u64_stats_sync syncp;
  50. u32 rx_errs;
  51. u32 tx_drps;
  52. };
  53. struct ipvl_port;
  54. struct ipvl_dev {
  55. struct net_device *dev;
  56. struct list_head pnode;
  57. struct ipvl_port *port;
  58. struct net_device *phy_dev;
  59. struct list_head addrs;
  60. int ipv4cnt;
  61. int ipv6cnt;
  62. struct ipvl_pcpu_stats __percpu *pcpu_stats;
  63. DECLARE_BITMAP(mac_filters, IPVLAN_MAC_FILTER_SIZE);
  64. netdev_features_t sfeatures;
  65. u32 msg_enable;
  66. u16 mtu_adj;
  67. };
  68. struct ipvl_addr {
  69. struct ipvl_dev *master; /* Back pointer to master */
  70. union {
  71. struct in6_addr ip6; /* IPv6 address on logical interface */
  72. struct in_addr ip4; /* IPv4 address on logical interface */
  73. } ipu;
  74. #define ip6addr ipu.ip6
  75. #define ip4addr ipu.ip4
  76. struct hlist_node hlnode; /* Hash-table linkage */
  77. struct list_head anode; /* logical-interface linkage */
  78. struct rcu_head rcu;
  79. ipvl_hdr_type atype;
  80. };
  81. struct ipvl_port {
  82. struct net_device *dev;
  83. struct hlist_head hlhead[IPVLAN_HASH_SIZE];
  84. struct list_head ipvlans;
  85. struct rcu_head rcu;
  86. int count;
  87. u16 mode;
  88. };
  89. static inline struct ipvl_port *ipvlan_port_get_rcu(const struct net_device *d)
  90. {
  91. return rcu_dereference(d->rx_handler_data);
  92. }
  93. static inline struct ipvl_port *ipvlan_port_get_rtnl(const struct net_device *d)
  94. {
  95. return rtnl_dereference(d->rx_handler_data);
  96. }
  97. void ipvlan_adjust_mtu(struct ipvl_dev *ipvlan, struct net_device *dev);
  98. void ipvlan_set_port_mode(struct ipvl_port *port, u32 nval);
  99. void ipvlan_init_secret(void);
  100. unsigned int ipvlan_mac_hash(const unsigned char *addr);
  101. rx_handler_result_t ipvlan_handle_frame(struct sk_buff **pskb);
  102. int ipvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev);
  103. void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr);
  104. bool ipvlan_addr_busy(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6);
  105. struct ipvl_addr *ipvlan_ht_addr_lookup(const struct ipvl_port *port,
  106. const void *iaddr, bool is_v6);
  107. void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync);
  108. #endif /* __IPVLAN_H */