distributed-arp-table.h 4.9 KB

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