distributed-arp-table.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Copyright (C) 2011-2014 B.A.T.M.A.N. contributors:
  2. *
  3. * Antonio Quartulli
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
  18. #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
  19. #ifdef CONFIG_BATMAN_ADV_DAT
  20. #include "types.h"
  21. #include "originator.h"
  22. #include <linux/if_arp.h>
  23. /**
  24. * BATADV_DAT_ADDR_MAX - maximum address value in the DHT space
  25. */
  26. #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0)
  27. void batadv_dat_status_update(struct net_device *net_dev);
  28. bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
  29. struct sk_buff *skb);
  30. bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
  31. struct sk_buff *skb, int hdr_size);
  32. void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
  33. struct sk_buff *skb);
  34. bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
  35. struct sk_buff *skb, int hdr_size);
  36. bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
  37. struct batadv_forw_packet *forw_packet);
  38. /**
  39. * batadv_dat_init_orig_node_addr - assign a DAT address to the orig_node
  40. * @orig_node: the node to assign the DAT address to
  41. */
  42. static inline void
  43. batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
  44. {
  45. uint32_t addr;
  46. addr = batadv_choose_orig(orig_node->orig, BATADV_DAT_ADDR_MAX);
  47. orig_node->dat_addr = (batadv_dat_addr_t)addr;
  48. }
  49. /**
  50. * batadv_dat_init_own_addr - assign a DAT address to the node itself
  51. * @bat_priv: the bat priv with all the soft interface information
  52. * @primary_if: a pointer to the primary interface
  53. */
  54. static inline void
  55. batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
  56. struct batadv_hard_iface *primary_if)
  57. {
  58. uint32_t addr;
  59. addr = batadv_choose_orig(primary_if->net_dev->dev_addr,
  60. BATADV_DAT_ADDR_MAX);
  61. bat_priv->dat.addr = (batadv_dat_addr_t)addr;
  62. }
  63. int batadv_dat_init(struct batadv_priv *bat_priv);
  64. void batadv_dat_free(struct batadv_priv *bat_priv);
  65. int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset);
  66. /**
  67. * batadv_dat_inc_counter - increment the correct DAT packet counter
  68. * @bat_priv: the bat priv with all the soft interface information
  69. * @subtype: the 4addr subtype of the packet to be counted
  70. *
  71. * Updates the ethtool statistics for the received packet if it is a DAT subtype
  72. */
  73. static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
  74. uint8_t subtype)
  75. {
  76. switch (subtype) {
  77. case BATADV_P_DAT_DHT_GET:
  78. batadv_inc_counter(bat_priv,
  79. BATADV_CNT_DAT_GET_RX);
  80. break;
  81. case BATADV_P_DAT_DHT_PUT:
  82. batadv_inc_counter(bat_priv,
  83. BATADV_CNT_DAT_PUT_RX);
  84. break;
  85. }
  86. }
  87. #else
  88. static inline void batadv_dat_status_update(struct net_device *net_dev)
  89. {
  90. }
  91. static inline bool
  92. batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
  93. struct sk_buff *skb)
  94. {
  95. return false;
  96. }
  97. static inline bool
  98. batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
  99. struct sk_buff *skb, int hdr_size)
  100. {
  101. return false;
  102. }
  103. static inline bool
  104. batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
  105. struct sk_buff *skb)
  106. {
  107. return false;
  108. }
  109. static inline bool
  110. batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
  111. struct sk_buff *skb, int hdr_size)
  112. {
  113. return false;
  114. }
  115. static inline bool
  116. batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
  117. struct batadv_forw_packet *forw_packet)
  118. {
  119. return false;
  120. }
  121. static inline void
  122. batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
  123. {
  124. }
  125. static inline void batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
  126. struct batadv_hard_iface *iface)
  127. {
  128. }
  129. static inline void batadv_arp_change_timeout(struct net_device *soft_iface,
  130. const char *name)
  131. {
  132. }
  133. static inline int batadv_dat_init(struct batadv_priv *bat_priv)
  134. {
  135. return 0;
  136. }
  137. static inline void batadv_dat_free(struct batadv_priv *bat_priv)
  138. {
  139. }
  140. static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
  141. uint8_t subtype)
  142. {
  143. }
  144. #endif /* CONFIG_BATMAN_ADV_DAT */
  145. #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */