main.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  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, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #ifndef _NET_BATMAN_ADV_MAIN_H_
  22. #define _NET_BATMAN_ADV_MAIN_H_
  23. #define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \
  24. "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>"
  25. #define DRIVER_DESC "B.A.T.M.A.N. advanced"
  26. #define DRIVER_DEVICE "batman-adv"
  27. #define SOURCE_VERSION "next"
  28. /* B.A.T.M.A.N. parameters */
  29. #define TQ_MAX_VALUE 255
  30. #define JITTER 20
  31. /* Time To Live of broadcast messages */
  32. #define TTL 50
  33. /* purge originators after time in seconds if no valid packet comes in
  34. * -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */
  35. #define PURGE_TIMEOUT 200
  36. #define TT_LOCAL_TIMEOUT 3600 /* in seconds */
  37. /* sliding packet range of received originator messages in squence numbers
  38. * (should be a multiple of our word size) */
  39. #define TQ_LOCAL_WINDOW_SIZE 64
  40. #define TQ_GLOBAL_WINDOW_SIZE 5
  41. #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
  42. #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
  43. #define TQ_TOTAL_BIDRECT_LIMIT 1
  44. #define NO_FLAGS 0
  45. #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
  46. #define LOG_BUF_LEN 8192 /* has to be a power of 2 */
  47. #define VIS_INTERVAL 5000 /* 5 seconds */
  48. /* how much worse secondary interfaces may be to be considered as bonding
  49. * candidates */
  50. #define BONDING_TQ_THRESHOLD 50
  51. /* should not be bigger than 512 bytes or change the size of
  52. * forw_packet->direct_link_flags */
  53. #define MAX_AGGREGATION_BYTES 512
  54. #define MAX_AGGREGATION_MS 100
  55. #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */
  56. /* don't reset again within 30 seconds */
  57. #define RESET_PROTECTION_MS 30000
  58. #define EXPECTED_SEQNO_RANGE 65536
  59. enum mesh_state {
  60. MESH_INACTIVE,
  61. MESH_ACTIVE,
  62. MESH_DEACTIVATING
  63. };
  64. #define BCAST_QUEUE_LEN 256
  65. #define BATMAN_QUEUE_LEN 256
  66. /*
  67. * Debug Messages
  68. */
  69. #ifdef pr_fmt
  70. #undef pr_fmt
  71. #endif
  72. /* Append 'batman-adv: ' before kernel messages */
  73. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  74. /* all messages related to routing / flooding / broadcasting / etc */
  75. enum dbg_level {
  76. DBG_BATMAN = 1 << 0,
  77. DBG_ROUTES = 1 << 1, /* route added / changed / deleted */
  78. DBG_ALL = 3
  79. };
  80. /*
  81. * Vis
  82. */
  83. /*
  84. * Kernel headers
  85. */
  86. #include <linux/mutex.h> /* mutex */
  87. #include <linux/module.h> /* needed by all modules */
  88. #include <linux/netdevice.h> /* netdevice */
  89. #include <linux/etherdevice.h> /* ethernet address classifaction */
  90. #include <linux/if_ether.h> /* ethernet header */
  91. #include <linux/poll.h> /* poll_table */
  92. #include <linux/kthread.h> /* kernel threads */
  93. #include <linux/pkt_sched.h> /* schedule types */
  94. #include <linux/workqueue.h> /* workqueue */
  95. #include <linux/slab.h>
  96. #include <net/sock.h> /* struct sock */
  97. #include <linux/jiffies.h>
  98. #include <linux/seq_file.h>
  99. #include "types.h"
  100. #ifndef REVISION_VERSION
  101. #define REVISION_VERSION_STR ""
  102. #else
  103. #define REVISION_VERSION_STR " "REVISION_VERSION
  104. #endif
  105. extern struct list_head hardif_list;
  106. extern unsigned char broadcast_addr[];
  107. extern struct workqueue_struct *bat_event_workqueue;
  108. int mesh_init(struct net_device *soft_iface);
  109. void mesh_free(struct net_device *soft_iface);
  110. void inc_module_count(void);
  111. void dec_module_count(void);
  112. int is_my_mac(const uint8_t *addr);
  113. #ifdef CONFIG_BATMAN_ADV_DEBUG
  114. int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3);
  115. #define bat_dbg(type, bat_priv, fmt, arg...) \
  116. do { \
  117. if (atomic_read(&bat_priv->log_level) & type) \
  118. debug_log(bat_priv, fmt, ## arg); \
  119. } \
  120. while (0)
  121. #else /* !CONFIG_BATMAN_ADV_DEBUG */
  122. __printf(3, 4)
  123. static inline void bat_dbg(char type __always_unused,
  124. struct bat_priv *bat_priv __always_unused,
  125. const char *fmt __always_unused, ...)
  126. {
  127. }
  128. #endif
  129. #define bat_info(net_dev, fmt, arg...) \
  130. do { \
  131. struct net_device *_netdev = (net_dev); \
  132. struct bat_priv *_batpriv = netdev_priv(_netdev); \
  133. bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
  134. pr_info("%s: " fmt, _netdev->name, ## arg); \
  135. } while (0)
  136. #define bat_err(net_dev, fmt, arg...) \
  137. do { \
  138. struct net_device *_netdev = (net_dev); \
  139. struct bat_priv *_batpriv = netdev_priv(_netdev); \
  140. bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
  141. pr_err("%s: " fmt, _netdev->name, ## arg); \
  142. } while (0)
  143. /**
  144. * returns 1 if they are the same ethernet addr
  145. *
  146. * note: can't use compare_ether_addr() as it requires aligned memory
  147. */
  148. static inline int compare_eth(const void *data1, const void *data2)
  149. {
  150. return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
  151. }
  152. #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
  153. /* Returns the smallest signed integer in two's complement with the sizeof x */
  154. #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
  155. /* Checks if a sequence number x is a predecessor/successor of y.
  156. * they handle overflows/underflows and can correctly check for a
  157. * predecessor/successor unless the variable sequence number has grown by
  158. * more then 2**(bitwidth(x)-1)-1.
  159. * This means that for a uint8_t with the maximum value 255, it would think:
  160. * - when adding nothing - it is neither a predecessor nor a successor
  161. * - before adding more than 127 to the starting value - it is a predecessor,
  162. * - when adding 128 - it is neither a predecessor nor a successor,
  163. * - after adding more than 127 to the starting value - it is a successor */
  164. #define seq_before(x, y) ({typeof(x) _d1 = (x); \
  165. typeof(y) _d2 = (y); \
  166. typeof(x) _dummy = (_d1 - _d2); \
  167. (void) (&_d1 == &_d2); \
  168. _dummy > smallest_signed_int(_dummy); })
  169. #define seq_after(x, y) seq_before(y, x)
  170. #endif /* _NET_BATMAN_ADV_MAIN_H_ */