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