main.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
  45. #define LOG_BUF_LEN 8192 /* has to be a power of 2 */
  46. #define VIS_INTERVAL 5000 /* 5 seconds */
  47. /* how much worse secondary interfaces may be to be considered as bonding
  48. * candidates */
  49. #define BONDING_TQ_THRESHOLD 50
  50. /* should not be bigger than 512 bytes or change the size of
  51. * forw_packet->direct_link_flags */
  52. #define MAX_AGGREGATION_BYTES 512
  53. #define MAX_AGGREGATION_MS 100
  54. #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */
  55. /* don't reset again within 30 seconds */
  56. #define RESET_PROTECTION_MS 30000
  57. #define EXPECTED_SEQNO_RANGE 65536
  58. #define MESH_INACTIVE 0
  59. #define MESH_ACTIVE 1
  60. #define MESH_DEACTIVATING 2
  61. #define BCAST_QUEUE_LEN 256
  62. #define BATMAN_QUEUE_LEN 256
  63. /*
  64. * Debug Messages
  65. */
  66. #ifdef pr_fmt
  67. #undef pr_fmt
  68. #endif
  69. /* Append 'batman-adv: ' before kernel messages */
  70. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  71. /* all messages related to routing / flooding / broadcasting / etc */
  72. #define DBG_BATMAN 1
  73. /* route or tt entry added / changed / deleted */
  74. #define DBG_ROUTES 2
  75. #define DBG_ALL 3
  76. /*
  77. * Vis
  78. */
  79. /*
  80. * Kernel headers
  81. */
  82. #include <linux/mutex.h> /* mutex */
  83. #include <linux/module.h> /* needed by all modules */
  84. #include <linux/netdevice.h> /* netdevice */
  85. #include <linux/etherdevice.h> /* ethernet address classifaction */
  86. #include <linux/if_ether.h> /* ethernet header */
  87. #include <linux/poll.h> /* poll_table */
  88. #include <linux/kthread.h> /* kernel threads */
  89. #include <linux/pkt_sched.h> /* schedule types */
  90. #include <linux/workqueue.h> /* workqueue */
  91. #include <linux/slab.h>
  92. #include <net/sock.h> /* struct sock */
  93. #include <linux/jiffies.h>
  94. #include <linux/seq_file.h>
  95. #include "types.h"
  96. #ifndef REVISION_VERSION
  97. #define REVISION_VERSION_STR ""
  98. #else
  99. #define REVISION_VERSION_STR " "REVISION_VERSION
  100. #endif
  101. extern struct list_head hardif_list;
  102. extern unsigned char broadcast_addr[];
  103. extern struct workqueue_struct *bat_event_workqueue;
  104. int mesh_init(struct net_device *soft_iface);
  105. void mesh_free(struct net_device *soft_iface);
  106. void inc_module_count(void);
  107. void dec_module_count(void);
  108. int is_my_mac(uint8_t *addr);
  109. #ifdef CONFIG_BATMAN_ADV_DEBUG
  110. int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
  111. #define bat_dbg(type, bat_priv, fmt, arg...) \
  112. do { \
  113. if (atomic_read(&bat_priv->log_level) & type) \
  114. debug_log(bat_priv, fmt, ## arg); \
  115. } \
  116. while (0)
  117. #else /* !CONFIG_BATMAN_ADV_DEBUG */
  118. static inline void bat_dbg(char type __always_unused,
  119. struct bat_priv *bat_priv __always_unused,
  120. char *fmt __always_unused, ...)
  121. {
  122. }
  123. #endif
  124. #define bat_info(net_dev, fmt, arg...) \
  125. do { \
  126. struct net_device *_netdev = (net_dev); \
  127. struct bat_priv *_batpriv = netdev_priv(_netdev); \
  128. bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
  129. pr_info("%s: " fmt, _netdev->name, ## arg); \
  130. } while (0)
  131. #define bat_err(net_dev, fmt, arg...) \
  132. do { \
  133. struct net_device *_netdev = (net_dev); \
  134. struct bat_priv *_batpriv = netdev_priv(_netdev); \
  135. bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
  136. pr_err("%s: " fmt, _netdev->name, ## arg); \
  137. } while (0)
  138. /**
  139. * returns 1 if they are the same ethernet addr
  140. *
  141. * note: can't use compare_ether_addr() as it requires aligned memory
  142. */
  143. static inline int compare_eth(void *data1, void *data2)
  144. {
  145. return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
  146. }
  147. #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
  148. #endif /* _NET_BATMAN_ADV_MAIN_H_ */