ipvlan.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <linux/netfilter.h>
  26. #include <net/ip.h>
  27. #include <net/ip6_route.h>
  28. #include <net/rtnetlink.h>
  29. #include <net/route.h>
  30. #include <net/addrconf.h>
  31. #include <net/l3mdev.h>
  32. #define IPVLAN_DRV "ipvlan"
  33. #define IPV_DRV_VER "0.1"
  34. #define IPVLAN_HASH_SIZE (1 << BITS_PER_BYTE)
  35. #define IPVLAN_HASH_MASK (IPVLAN_HASH_SIZE - 1)
  36. #define IPVLAN_MAC_FILTER_BITS 8
  37. #define IPVLAN_MAC_FILTER_SIZE (1 << IPVLAN_MAC_FILTER_BITS)
  38. #define IPVLAN_MAC_FILTER_MASK (IPVLAN_MAC_FILTER_SIZE - 1)
  39. #define IPVLAN_QBACKLOG_LIMIT 1000
  40. typedef enum {
  41. IPVL_IPV6 = 0,
  42. IPVL_ICMPV6,
  43. IPVL_IPV4,
  44. IPVL_ARP,
  45. } ipvl_hdr_type;
  46. struct ipvl_pcpu_stats {
  47. u64 rx_pkts;
  48. u64 rx_bytes;
  49. u64 rx_mcast;
  50. u64 tx_pkts;
  51. u64 tx_bytes;
  52. struct u64_stats_sync syncp;
  53. u32 rx_errs;
  54. u32 tx_drps;
  55. };
  56. struct ipvl_port;
  57. struct ipvl_dev {
  58. struct net_device *dev;
  59. struct list_head pnode;
  60. struct ipvl_port *port;
  61. struct net_device *phy_dev;
  62. struct list_head addrs;
  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. ipvl_hdr_type atype;
  80. struct rcu_head rcu;
  81. };
  82. struct ipvl_port {
  83. struct net_device *dev;
  84. struct hlist_head hlhead[IPVLAN_HASH_SIZE];
  85. struct list_head ipvlans;
  86. u16 mode;
  87. struct work_struct wq;
  88. struct sk_buff_head backlog;
  89. int count;
  90. struct rcu_head rcu;
  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_rcu_bh(const struct net_device *d)
  97. {
  98. return rcu_dereference_bh(d->rx_handler_data);
  99. }
  100. static inline struct ipvl_port *ipvlan_port_get_rtnl(const struct net_device *d)
  101. {
  102. return rtnl_dereference(d->rx_handler_data);
  103. }
  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. void ipvlan_ht_addr_del(struct ipvl_addr *addr);
  114. struct sk_buff *ipvlan_l3_rcv(struct net_device *dev, struct sk_buff *skb,
  115. u16 proto);
  116. unsigned int ipvlan_nf_input(void *priv, struct sk_buff *skb,
  117. const struct nf_hook_state *state);
  118. #endif /* __IPVLAN_H */