distributed-arp-table.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright (C) 2011-2015 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. #include "main.h"
  20. #include <linux/compiler.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/types.h>
  23. #include "originator.h"
  24. #include "packet.h"
  25. struct seq_file;
  26. struct sk_buff;
  27. #ifdef CONFIG_BATMAN_ADV_DAT
  28. /* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */
  29. #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0)
  30. void batadv_dat_status_update(struct net_device *net_dev);
  31. bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
  32. struct sk_buff *skb);
  33. bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
  34. struct sk_buff *skb, int hdr_size);
  35. void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
  36. struct sk_buff *skb);
  37. bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
  38. struct sk_buff *skb, int hdr_size);
  39. bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
  40. struct batadv_forw_packet *forw_packet);
  41. /**
  42. * batadv_dat_init_orig_node_addr - assign a DAT address to the orig_node
  43. * @orig_node: the node to assign the DAT address to
  44. */
  45. static inline void
  46. batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
  47. {
  48. u32 addr;
  49. addr = batadv_choose_orig(orig_node->orig, BATADV_DAT_ADDR_MAX);
  50. orig_node->dat_addr = (batadv_dat_addr_t)addr;
  51. }
  52. /**
  53. * batadv_dat_init_own_addr - assign a DAT address to the node itself
  54. * @bat_priv: the bat priv with all the soft interface information
  55. * @primary_if: a pointer to the primary interface
  56. */
  57. static inline void
  58. batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
  59. struct batadv_hard_iface *primary_if)
  60. {
  61. u32 addr;
  62. addr = batadv_choose_orig(primary_if->net_dev->dev_addr,
  63. BATADV_DAT_ADDR_MAX);
  64. bat_priv->dat.addr = (batadv_dat_addr_t)addr;
  65. }
  66. int batadv_dat_init(struct batadv_priv *bat_priv);
  67. void batadv_dat_free(struct batadv_priv *bat_priv);
  68. int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset);
  69. /**
  70. * batadv_dat_inc_counter - increment the correct DAT packet counter
  71. * @bat_priv: the bat priv with all the soft interface information
  72. * @subtype: the 4addr subtype of the packet to be counted
  73. *
  74. * Updates the ethtool statistics for the received packet if it is a DAT subtype
  75. */
  76. static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
  77. u8 subtype)
  78. {
  79. switch (subtype) {
  80. case BATADV_P_DAT_DHT_GET:
  81. batadv_inc_counter(bat_priv,
  82. BATADV_CNT_DAT_GET_RX);
  83. break;
  84. case BATADV_P_DAT_DHT_PUT:
  85. batadv_inc_counter(bat_priv,
  86. BATADV_CNT_DAT_PUT_RX);
  87. break;
  88. }
  89. }
  90. #else
  91. static inline void batadv_dat_status_update(struct net_device *net_dev)
  92. {
  93. }
  94. static inline bool
  95. batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
  96. struct sk_buff *skb)
  97. {
  98. return false;
  99. }
  100. static inline bool
  101. batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
  102. struct sk_buff *skb, int hdr_size)
  103. {
  104. return false;
  105. }
  106. static inline bool
  107. batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
  108. struct sk_buff *skb)
  109. {
  110. return false;
  111. }
  112. static inline bool
  113. batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
  114. struct sk_buff *skb, int hdr_size)
  115. {
  116. return false;
  117. }
  118. static inline bool
  119. batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
  120. struct batadv_forw_packet *forw_packet)
  121. {
  122. return false;
  123. }
  124. static inline void
  125. batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
  126. {
  127. }
  128. static inline void batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
  129. struct batadv_hard_iface *iface)
  130. {
  131. }
  132. static inline void batadv_arp_change_timeout(struct net_device *soft_iface,
  133. const char *name)
  134. {
  135. }
  136. static inline int batadv_dat_init(struct batadv_priv *bat_priv)
  137. {
  138. return 0;
  139. }
  140. static inline void batadv_dat_free(struct batadv_priv *bat_priv)
  141. {
  142. }
  143. static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
  144. u8 subtype)
  145. {
  146. }
  147. #endif /* CONFIG_BATMAN_ADV_DAT */
  148. #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */