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