distributed-arp-table.h 4.7 KB

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