]>
Commit | Line | Data |
---|---|---|
c6c8fea2 | 1 | /* |
567db7b0 | 2 | * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: |
c6c8fea2 SE |
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 | ||
c6c8fea2 SE |
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 | ||
44c4349a | 30 | #ifndef SOURCE_VERSION |
fdc8ff10 | 31 | #define SOURCE_VERSION "2012.1.0" |
44c4349a | 32 | #endif |
c6c8fea2 SE |
33 | |
34 | /* B.A.T.M.A.N. parameters */ | |
35 | ||
36 | #define TQ_MAX_VALUE 255 | |
37 | #define JITTER 20 | |
c6c8fea2 | 38 | |
6e215fd8 SE |
39 | /* Time To Live of broadcast messages */ |
40 | #define TTL 50 | |
41 | ||
42 | /* purge originators after time in seconds if no valid packet comes in | |
43 | * -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */ | |
032b7969 ML |
44 | #define PURGE_TIMEOUT 200000 /* 200 seconds */ |
45 | #define TT_LOCAL_TIMEOUT 3600000 /* in miliseconds */ | |
46 | #define TT_CLIENT_ROAM_TIMEOUT 600000 /* in miliseconds */ | |
015758d0 | 47 | /* sliding packet range of received originator messages in sequence numbers |
6e215fd8 SE |
48 | * (should be a multiple of our word size) */ |
49 | #define TQ_LOCAL_WINDOW_SIZE 64 | |
032b7969 ML |
50 | #define TT_REQUEST_TIMEOUT 3000 /* miliseconds we have to keep |
51 | * pending tt_req */ | |
a73105b8 | 52 | |
c6c8fea2 SE |
53 | #define TQ_GLOBAL_WINDOW_SIZE 5 |
54 | #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 | |
55 | #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 | |
56 | #define TQ_TOTAL_BIDRECT_LIMIT 1 | |
57 | ||
a73105b8 AQ |
58 | #define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */ |
59 | ||
032b7969 ML |
60 | #define ROAMING_MAX_TIME 20000 /* Time in which a client can roam at most |
61 | * ROAMING_MAX_COUNT times in miliseconds*/ | |
cc47f66e AQ |
62 | #define ROAMING_MAX_COUNT 5 |
63 | ||
ecbd5321 ML |
64 | #define NO_FLAGS 0 |
65 | ||
bc279080 AQ |
66 | #define NULL_IFINDEX 0 /* dummy ifindex used to avoid iface checks */ |
67 | ||
0079d2ce | 68 | #define NUM_WORDS BITS_TO_LONGS(TQ_LOCAL_WINDOW_SIZE) |
c6c8fea2 | 69 | |
c6c8fea2 SE |
70 | #define LOG_BUF_LEN 8192 /* has to be a power of 2 */ |
71 | ||
72 | #define VIS_INTERVAL 5000 /* 5 seconds */ | |
73 | ||
6e215fd8 SE |
74 | /* how much worse secondary interfaces may be to be considered as bonding |
75 | * candidates */ | |
c6c8fea2 SE |
76 | #define BONDING_TQ_THRESHOLD 50 |
77 | ||
6e215fd8 SE |
78 | /* should not be bigger than 512 bytes or change the size of |
79 | * forw_packet->direct_link_flags */ | |
80 | #define MAX_AGGREGATION_BYTES 512 | |
c6c8fea2 SE |
81 | #define MAX_AGGREGATION_MS 100 |
82 | ||
6e215fd8 | 83 | /* don't reset again within 30 seconds */ |
c6c8fea2 SE |
84 | #define RESET_PROTECTION_MS 30000 |
85 | #define EXPECTED_SEQNO_RANGE 65536 | |
c6c8fea2 | 86 | |
e8958dbf SE |
87 | enum mesh_state { |
88 | MESH_INACTIVE, | |
89 | MESH_ACTIVE, | |
90 | MESH_DEACTIVATING | |
91 | }; | |
c6c8fea2 SE |
92 | |
93 | #define BCAST_QUEUE_LEN 256 | |
94 | #define BATMAN_QUEUE_LEN 256 | |
95 | ||
c6bda689 AQ |
96 | enum uev_action { |
97 | UEV_ADD = 0, | |
98 | UEV_DEL, | |
99 | UEV_CHANGE | |
100 | }; | |
101 | ||
102 | enum uev_type { | |
103 | UEV_GW = 0 | |
104 | }; | |
105 | ||
43676ab5 AQ |
106 | #define GW_THRESHOLD 50 |
107 | ||
21a1236b | 108 | /* Debug Messages */ |
c6c8fea2 SE |
109 | #ifdef pr_fmt |
110 | #undef pr_fmt | |
111 | #endif | |
6e215fd8 SE |
112 | /* Append 'batman-adv: ' before kernel messages */ |
113 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
c6c8fea2 | 114 | |
6e215fd8 | 115 | /* all messages related to routing / flooding / broadcasting / etc */ |
e8958dbf SE |
116 | enum dbg_level { |
117 | DBG_BATMAN = 1 << 0, | |
118 | DBG_ROUTES = 1 << 1, /* route added / changed / deleted */ | |
a73105b8 AQ |
119 | DBG_TT = 1 << 2, /* translation table operations */ |
120 | DBG_ALL = 7 | |
e8958dbf | 121 | }; |
c6c8fea2 | 122 | |
21a1236b | 123 | /* Kernel headers */ |
c6c8fea2 SE |
124 | |
125 | #include <linux/mutex.h> /* mutex */ | |
126 | #include <linux/module.h> /* needed by all modules */ | |
127 | #include <linux/netdevice.h> /* netdevice */ | |
015758d0 | 128 | #include <linux/etherdevice.h> /* ethernet address classification */ |
c6c8fea2 SE |
129 | #include <linux/if_ether.h> /* ethernet header */ |
130 | #include <linux/poll.h> /* poll_table */ | |
131 | #include <linux/kthread.h> /* kernel threads */ | |
132 | #include <linux/pkt_sched.h> /* schedule types */ | |
133 | #include <linux/workqueue.h> /* workqueue */ | |
134 | #include <linux/slab.h> | |
135 | #include <net/sock.h> /* struct sock */ | |
136 | #include <linux/jiffies.h> | |
137 | #include <linux/seq_file.h> | |
138 | #include "types.h" | |
139 | ||
1c280471 | 140 | extern char bat_routing_algo[]; |
4389e47a | 141 | extern struct list_head hardif_list; |
c6c8fea2 SE |
142 | |
143 | extern unsigned char broadcast_addr[]; | |
144 | extern struct workqueue_struct *bat_event_workqueue; | |
145 | ||
146 | int mesh_init(struct net_device *soft_iface); | |
147 | void mesh_free(struct net_device *soft_iface); | |
148 | void inc_module_count(void); | |
149 | void dec_module_count(void); | |
747e4221 | 150 | int is_my_mac(const uint8_t *addr); |
1c280471 ML |
151 | int bat_algo_register(struct bat_algo_ops *bat_algo_ops); |
152 | int bat_algo_select(struct bat_priv *bat_priv, char *name); | |
153 | int bat_algo_seq_print_text(struct seq_file *seq, void *offset); | |
c6c8fea2 SE |
154 | |
155 | #ifdef CONFIG_BATMAN_ADV_DEBUG | |
747e4221 | 156 | int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); |
c6c8fea2 SE |
157 | |
158 | #define bat_dbg(type, bat_priv, fmt, arg...) \ | |
159 | do { \ | |
160 | if (atomic_read(&bat_priv->log_level) & type) \ | |
161 | debug_log(bat_priv, fmt, ## arg); \ | |
162 | } \ | |
163 | while (0) | |
164 | #else /* !CONFIG_BATMAN_ADV_DEBUG */ | |
d3a547be | 165 | __printf(3, 4) |
b4e17054 | 166 | static inline void bat_dbg(int type __always_unused, |
aa0adb1a | 167 | struct bat_priv *bat_priv __always_unused, |
747e4221 | 168 | const char *fmt __always_unused, ...) |
c6c8fea2 SE |
169 | { |
170 | } | |
171 | #endif | |
172 | ||
c6c8fea2 SE |
173 | #define bat_info(net_dev, fmt, arg...) \ |
174 | do { \ | |
175 | struct net_device *_netdev = (net_dev); \ | |
176 | struct bat_priv *_batpriv = netdev_priv(_netdev); \ | |
177 | bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ | |
178 | pr_info("%s: " fmt, _netdev->name, ## arg); \ | |
179 | } while (0) | |
180 | #define bat_err(net_dev, fmt, arg...) \ | |
181 | do { \ | |
182 | struct net_device *_netdev = (net_dev); \ | |
183 | struct bat_priv *_batpriv = netdev_priv(_netdev); \ | |
184 | bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ | |
185 | pr_err("%s: " fmt, _netdev->name, ## arg); \ | |
186 | } while (0) | |
187 | ||
39901e71 ML |
188 | /** |
189 | * returns 1 if they are the same ethernet addr | |
190 | * | |
191 | * note: can't use compare_ether_addr() as it requires aligned memory | |
192 | */ | |
747e4221 SE |
193 | |
194 | static inline int compare_eth(const void *data1, const void *data2) | |
39901e71 ML |
195 | { |
196 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); | |
197 | } | |
198 | ||
a04ccd59 MH |
199 | /** |
200 | * has_timed_out - compares current time (jiffies) and timestamp + timeout | |
201 | * @timestamp: base value to compare with (in jiffies) | |
202 | * @timeout: added to base value before comparing (in milliseconds) | |
203 | * | |
204 | * Returns true if current time is after timestamp + timeout | |
205 | */ | |
206 | static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout) | |
207 | { | |
208 | return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); | |
209 | } | |
747e4221 | 210 | |
5f657ec0 AQ |
211 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) |
212 | ||
f5d33d37 AQ |
213 | /* Returns the smallest signed integer in two's complement with the sizeof x */ |
214 | #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) | |
215 | ||
216 | /* Checks if a sequence number x is a predecessor/successor of y. | |
217 | * they handle overflows/underflows and can correctly check for a | |
218 | * predecessor/successor unless the variable sequence number has grown by | |
219 | * more then 2**(bitwidth(x)-1)-1. | |
220 | * This means that for a uint8_t with the maximum value 255, it would think: | |
221 | * - when adding nothing - it is neither a predecessor nor a successor | |
222 | * - before adding more than 127 to the starting value - it is a predecessor, | |
223 | * - when adding 128 - it is neither a predecessor nor a successor, | |
224 | * - after adding more than 127 to the starting value - it is a successor */ | |
0bb85751 SE |
225 | #define seq_before(x, y) ({typeof(x) _d1 = (x); \ |
226 | typeof(y) _d2 = (y); \ | |
227 | typeof(x) _dummy = (_d1 - _d2); \ | |
228 | (void) (&_d1 == &_d2); \ | |
229 | _dummy > smallest_signed_int(_dummy); }) | |
f5d33d37 AQ |
230 | #define seq_after(x, y) seq_before(y, x) |
231 | ||
c6c8fea2 | 232 | #endif /* _NET_BATMAN_ADV_MAIN_H_ */ |