distributed-arp-table.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2011-2020 B.A.T.M.A.N. contributors:
  3. *
  4. * Antonio Quartulli
  5. */
  6. #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
  7. #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
  8. #include "main.h"
  9. #include <linux/compiler.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/netlink.h>
  12. #include <linux/seq_file.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/types.h>
  15. #include <uapi/linux/batadv_packet.h>
  16. #include "originator.h"
  17. #ifdef CONFIG_BATMAN_ADV_DAT
  18. /* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */
  19. #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0)
  20. void batadv_dat_status_update(struct net_device *net_dev);
  21. bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
  22. struct sk_buff *skb);
  23. bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
  24. struct sk_buff *skb, int hdr_size);
  25. void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
  26. struct sk_buff *skb);
  27. bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
  28. struct sk_buff *skb, int hdr_size);
  29. void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
  30. struct sk_buff *skb,
  31. __be16 proto,
  32. unsigned short vid);
  33. void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
  34. struct sk_buff *skb, int hdr_size);
  35. bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
  36. struct batadv_forw_packet *forw_packet);
  37. /**
  38. * batadv_dat_init_orig_node_addr() - assign a DAT address to the orig_node
  39. * @orig_node: the node to assign the DAT address to
  40. */
  41. static inline void
  42. batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
  43. {
  44. u32 addr;
  45. addr = batadv_choose_orig(orig_node->orig, BATADV_DAT_ADDR_MAX);
  46. orig_node->dat_addr = (batadv_dat_addr_t)addr;
  47. }
  48. /**
  49. * batadv_dat_init_own_addr() - assign a DAT address to the node itself
  50. * @bat_priv: the bat priv with all the soft interface information
  51. * @primary_if: a pointer to the primary interface
  52. */
  53. static inline void
  54. batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
  55. struct batadv_hard_iface *primary_if)
  56. {
  57. u32 addr;
  58. addr = batadv_choose_orig(primary_if->net_dev->dev_addr,
  59. BATADV_DAT_ADDR_MAX);
  60. bat_priv->dat.addr = (batadv_dat_addr_t)addr;
  61. }
  62. int batadv_dat_init(struct batadv_priv *bat_priv);
  63. void batadv_dat_free(struct batadv_priv *bat_priv);
  64. int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset);
  65. int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb);
  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. u8 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 void
  116. batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
  117. struct sk_buff *skb, __be16 proto,
  118. unsigned short vid)
  119. {
  120. }
  121. static inline void
  122. batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
  123. struct sk_buff *skb, int hdr_size)
  124. {
  125. }
  126. static inline bool
  127. batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
  128. struct batadv_forw_packet *forw_packet)
  129. {
  130. return false;
  131. }
  132. static inline void
  133. batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
  134. {
  135. }
  136. static inline void batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
  137. struct batadv_hard_iface *iface)
  138. {
  139. }
  140. static inline int batadv_dat_init(struct batadv_priv *bat_priv)
  141. {
  142. return 0;
  143. }
  144. static inline void batadv_dat_free(struct batadv_priv *bat_priv)
  145. {
  146. }
  147. static inline int
  148. batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
  149. {
  150. return -EOPNOTSUPP;
  151. }
  152. static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
  153. u8 subtype)
  154. {
  155. }
  156. #endif /* CONFIG_BATMAN_ADV_DAT */
  157. #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */