]>
Commit | Line | Data |
---|---|---|
c6c8fea2 | 1 | /* |
64afe353 | 2 | * Copyright (C) 2007-2011 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 | ||
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 | |
c6c8fea2 | 37 | |
6e215fd8 SE |
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 | |
2dafb49d | 44 | #define TT_LOCAL_TIMEOUT 3600 /* in seconds */ |
c6c8fea2 | 45 | |
6e215fd8 SE |
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 | |
c6c8fea2 SE |
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 | ||
ecbd5321 ML |
54 | #define NO_FLAGS 0 |
55 | ||
c6c8fea2 SE |
56 | #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE) |
57 | ||
c6c8fea2 SE |
58 | #define LOG_BUF_LEN 8192 /* has to be a power of 2 */ |
59 | ||
60 | #define VIS_INTERVAL 5000 /* 5 seconds */ | |
61 | ||
6e215fd8 SE |
62 | /* how much worse secondary interfaces may be to be considered as bonding |
63 | * candidates */ | |
c6c8fea2 SE |
64 | #define BONDING_TQ_THRESHOLD 50 |
65 | ||
6e215fd8 SE |
66 | /* should not be bigger than 512 bytes or change the size of |
67 | * forw_packet->direct_link_flags */ | |
68 | #define MAX_AGGREGATION_BYTES 512 | |
c6c8fea2 SE |
69 | #define MAX_AGGREGATION_MS 100 |
70 | ||
71 | #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */ | |
72 | ||
6e215fd8 | 73 | /* don't reset again within 30 seconds */ |
c6c8fea2 SE |
74 | #define RESET_PROTECTION_MS 30000 |
75 | #define EXPECTED_SEQNO_RANGE 65536 | |
c6c8fea2 | 76 | |
e8958dbf SE |
77 | enum mesh_state { |
78 | MESH_INACTIVE, | |
79 | MESH_ACTIVE, | |
80 | MESH_DEACTIVATING | |
81 | }; | |
c6c8fea2 SE |
82 | |
83 | #define BCAST_QUEUE_LEN 256 | |
84 | #define BATMAN_QUEUE_LEN 256 | |
85 | ||
86 | /* | |
87 | * Debug Messages | |
88 | */ | |
89 | #ifdef pr_fmt | |
90 | #undef pr_fmt | |
91 | #endif | |
6e215fd8 SE |
92 | /* Append 'batman-adv: ' before kernel messages */ |
93 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
c6c8fea2 | 94 | |
6e215fd8 | 95 | /* all messages related to routing / flooding / broadcasting / etc */ |
e8958dbf SE |
96 | enum dbg_level { |
97 | DBG_BATMAN = 1 << 0, | |
98 | DBG_ROUTES = 1 << 1, /* route added / changed / deleted */ | |
99 | DBG_ALL = 3 | |
100 | }; | |
c6c8fea2 | 101 | |
c6c8fea2 SE |
102 | |
103 | /* | |
104 | * Vis | |
105 | */ | |
106 | ||
c6c8fea2 SE |
107 | /* |
108 | * Kernel headers | |
109 | */ | |
110 | ||
111 | #include <linux/mutex.h> /* mutex */ | |
112 | #include <linux/module.h> /* needed by all modules */ | |
113 | #include <linux/netdevice.h> /* netdevice */ | |
114 | #include <linux/etherdevice.h> /* ethernet address classifaction */ | |
115 | #include <linux/if_ether.h> /* ethernet header */ | |
116 | #include <linux/poll.h> /* poll_table */ | |
117 | #include <linux/kthread.h> /* kernel threads */ | |
118 | #include <linux/pkt_sched.h> /* schedule types */ | |
119 | #include <linux/workqueue.h> /* workqueue */ | |
120 | #include <linux/slab.h> | |
121 | #include <net/sock.h> /* struct sock */ | |
122 | #include <linux/jiffies.h> | |
123 | #include <linux/seq_file.h> | |
124 | #include "types.h" | |
125 | ||
126 | #ifndef REVISION_VERSION | |
127 | #define REVISION_VERSION_STR "" | |
128 | #else | |
129 | #define REVISION_VERSION_STR " "REVISION_VERSION | |
130 | #endif | |
131 | ||
4389e47a | 132 | extern struct list_head hardif_list; |
c6c8fea2 SE |
133 | |
134 | extern unsigned char broadcast_addr[]; | |
135 | extern struct workqueue_struct *bat_event_workqueue; | |
136 | ||
137 | int mesh_init(struct net_device *soft_iface); | |
138 | void mesh_free(struct net_device *soft_iface); | |
139 | void inc_module_count(void); | |
140 | void dec_module_count(void); | |
747e4221 | 141 | int is_my_mac(const uint8_t *addr); |
c6c8fea2 SE |
142 | |
143 | #ifdef CONFIG_BATMAN_ADV_DEBUG | |
747e4221 | 144 | int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); |
c6c8fea2 SE |
145 | |
146 | #define bat_dbg(type, bat_priv, fmt, arg...) \ | |
147 | do { \ | |
148 | if (atomic_read(&bat_priv->log_level) & type) \ | |
149 | debug_log(bat_priv, fmt, ## arg); \ | |
150 | } \ | |
151 | while (0) | |
152 | #else /* !CONFIG_BATMAN_ADV_DEBUG */ | |
d3a547be | 153 | __printf(3, 4) |
aa0adb1a SE |
154 | static inline void bat_dbg(char type __always_unused, |
155 | struct bat_priv *bat_priv __always_unused, | |
747e4221 | 156 | const char *fmt __always_unused, ...) |
c6c8fea2 SE |
157 | { |
158 | } | |
159 | #endif | |
160 | ||
c6c8fea2 SE |
161 | #define bat_info(net_dev, fmt, arg...) \ |
162 | do { \ | |
163 | struct net_device *_netdev = (net_dev); \ | |
164 | struct bat_priv *_batpriv = netdev_priv(_netdev); \ | |
165 | bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ | |
166 | pr_info("%s: " fmt, _netdev->name, ## arg); \ | |
167 | } while (0) | |
168 | #define bat_err(net_dev, fmt, arg...) \ | |
169 | do { \ | |
170 | struct net_device *_netdev = (net_dev); \ | |
171 | struct bat_priv *_batpriv = netdev_priv(_netdev); \ | |
172 | bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \ | |
173 | pr_err("%s: " fmt, _netdev->name, ## arg); \ | |
174 | } while (0) | |
175 | ||
39901e71 ML |
176 | /** |
177 | * returns 1 if they are the same ethernet addr | |
178 | * | |
179 | * note: can't use compare_ether_addr() as it requires aligned memory | |
180 | */ | |
747e4221 SE |
181 | |
182 | static inline int compare_eth(const void *data1, const void *data2) | |
39901e71 ML |
183 | { |
184 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); | |
185 | } | |
186 | ||
747e4221 | 187 | |
5f657ec0 AQ |
188 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) |
189 | ||
f5d33d37 AQ |
190 | /* Returns the smallest signed integer in two's complement with the sizeof x */ |
191 | #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) | |
192 | ||
193 | /* Checks if a sequence number x is a predecessor/successor of y. | |
194 | * they handle overflows/underflows and can correctly check for a | |
195 | * predecessor/successor unless the variable sequence number has grown by | |
196 | * more then 2**(bitwidth(x)-1)-1. | |
197 | * This means that for a uint8_t with the maximum value 255, it would think: | |
198 | * - when adding nothing - it is neither a predecessor nor a successor | |
199 | * - before adding more than 127 to the starting value - it is a predecessor, | |
200 | * - when adding 128 - it is neither a predecessor nor a successor, | |
201 | * - after adding more than 127 to the starting value - it is a successor */ | |
0bb85751 SE |
202 | #define seq_before(x, y) ({typeof(x) _d1 = (x); \ |
203 | typeof(y) _d2 = (y); \ | |
204 | typeof(x) _dummy = (_d1 - _d2); \ | |
205 | (void) (&_d1 == &_d2); \ | |
206 | _dummy > smallest_signed_int(_dummy); }) | |
f5d33d37 AQ |
207 | #define seq_after(x, y) seq_before(y, x) |
208 | ||
c6c8fea2 | 209 | #endif /* _NET_BATMAN_ADV_MAIN_H_ */ |