xref: /linux/net/batman-adv/main.h (revision 015758d00251a4dd9287806cdab4b9c1298f97ed)
1c6c8fea2SSven Eckelmann /*
264afe353SSven Eckelmann  * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
3c6c8fea2SSven Eckelmann  *
4c6c8fea2SSven Eckelmann  * Marek Lindner, Simon Wunderlich
5c6c8fea2SSven Eckelmann  *
6c6c8fea2SSven Eckelmann  * This program is free software; you can redistribute it and/or
7c6c8fea2SSven Eckelmann  * modify it under the terms of version 2 of the GNU General Public
8c6c8fea2SSven Eckelmann  * License as published by the Free Software Foundation.
9c6c8fea2SSven Eckelmann  *
10c6c8fea2SSven Eckelmann  * This program is distributed in the hope that it will be useful, but
11c6c8fea2SSven Eckelmann  * WITHOUT ANY WARRANTY; without even the implied warranty of
12c6c8fea2SSven Eckelmann  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13c6c8fea2SSven Eckelmann  * General Public License for more details.
14c6c8fea2SSven Eckelmann  *
15c6c8fea2SSven Eckelmann  * You should have received a copy of the GNU General Public License
16c6c8fea2SSven Eckelmann  * along with this program; if not, write to the Free Software
17c6c8fea2SSven Eckelmann  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18c6c8fea2SSven Eckelmann  * 02110-1301, USA
19c6c8fea2SSven Eckelmann  *
20c6c8fea2SSven Eckelmann  */
21c6c8fea2SSven Eckelmann 
22c6c8fea2SSven Eckelmann #ifndef _NET_BATMAN_ADV_MAIN_H_
23c6c8fea2SSven Eckelmann #define _NET_BATMAN_ADV_MAIN_H_
24c6c8fea2SSven Eckelmann 
25c6c8fea2SSven Eckelmann #define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \
26c6c8fea2SSven Eckelmann 		      "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>"
27c6c8fea2SSven Eckelmann #define DRIVER_DESC   "B.A.T.M.A.N. advanced"
28c6c8fea2SSven Eckelmann #define DRIVER_DEVICE "batman-adv"
29c6c8fea2SSven Eckelmann 
3044c4349aSSven Eckelmann #ifndef SOURCE_VERSION
3144c4349aSSven Eckelmann #define SOURCE_VERSION "2011.3.0"
3244c4349aSSven Eckelmann #endif
33c6c8fea2SSven Eckelmann 
34c6c8fea2SSven Eckelmann /* B.A.T.M.A.N. parameters */
35c6c8fea2SSven Eckelmann 
36c6c8fea2SSven Eckelmann #define TQ_MAX_VALUE 255
37c6c8fea2SSven Eckelmann #define JITTER 20
38c6c8fea2SSven Eckelmann 
396e215fd8SSven Eckelmann  /* Time To Live of broadcast messages */
406e215fd8SSven Eckelmann #define TTL 50
416e215fd8SSven Eckelmann 
426e215fd8SSven Eckelmann /* purge originators after time in seconds if no valid packet comes in
436e215fd8SSven Eckelmann  * -> TODO: check influence on TQ_LOCAL_WINDOW_SIZE */
446e215fd8SSven Eckelmann #define PURGE_TIMEOUT 200
452dafb49dSAntonio Quartulli #define TT_LOCAL_TIMEOUT 3600 /* in seconds */
46cc47f66eSAntonio Quartulli #define TT_CLIENT_ROAM_TIMEOUT 600
47*015758d0SAntonio Quartulli /* sliding packet range of received originator messages in sequence numbers
486e215fd8SSven Eckelmann  * (should be a multiple of our word size) */
496e215fd8SSven Eckelmann #define TQ_LOCAL_WINDOW_SIZE 64
50a73105b8SAntonio Quartulli #define TT_REQUEST_TIMEOUT 3 /* seconds we have to keep pending tt_req */
51a73105b8SAntonio Quartulli 
52c6c8fea2SSven Eckelmann #define TQ_GLOBAL_WINDOW_SIZE 5
53c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
54c6c8fea2SSven Eckelmann #define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
55c6c8fea2SSven Eckelmann #define TQ_TOTAL_BIDRECT_LIMIT 1
56c6c8fea2SSven Eckelmann 
57a73105b8SAntonio Quartulli #define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
58a73105b8SAntonio Quartulli 
59cc47f66eSAntonio Quartulli #define ROAMING_MAX_TIME 20 /* Time in which a client can roam at most
60cc47f66eSAntonio Quartulli 			     * ROAMING_MAX_COUNT times */
61cc47f66eSAntonio Quartulli #define ROAMING_MAX_COUNT 5
62cc47f66eSAntonio Quartulli 
63ecbd5321SMarek Lindner #define NO_FLAGS 0
64ecbd5321SMarek Lindner 
65c6c8fea2SSven Eckelmann #define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
66c6c8fea2SSven Eckelmann 
67c6c8fea2SSven Eckelmann #define LOG_BUF_LEN 8192	  /* has to be a power of 2 */
68c6c8fea2SSven Eckelmann 
69c6c8fea2SSven Eckelmann #define VIS_INTERVAL 5000	/* 5 seconds */
70c6c8fea2SSven Eckelmann 
716e215fd8SSven Eckelmann /* how much worse secondary interfaces may be to be considered as bonding
726e215fd8SSven Eckelmann  * candidates */
73c6c8fea2SSven Eckelmann #define BONDING_TQ_THRESHOLD	50
74c6c8fea2SSven Eckelmann 
756e215fd8SSven Eckelmann /* should not be bigger than 512 bytes or change the size of
76c6c8fea2SSven Eckelmann  * forw_packet->direct_link_flags */
776e215fd8SSven Eckelmann #define MAX_AGGREGATION_BYTES 512
78c6c8fea2SSven Eckelmann #define MAX_AGGREGATION_MS 100
79c6c8fea2SSven Eckelmann 
80c6c8fea2SSven Eckelmann #define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */
81c6c8fea2SSven Eckelmann 
826e215fd8SSven Eckelmann /* don't reset again within 30 seconds */
83c6c8fea2SSven Eckelmann #define RESET_PROTECTION_MS 30000
84c6c8fea2SSven Eckelmann #define EXPECTED_SEQNO_RANGE	65536
85c6c8fea2SSven Eckelmann 
86e8958dbfSSven Eckelmann enum mesh_state {
87e8958dbfSSven Eckelmann 	MESH_INACTIVE,
88e8958dbfSSven Eckelmann 	MESH_ACTIVE,
89e8958dbfSSven Eckelmann 	MESH_DEACTIVATING
90e8958dbfSSven Eckelmann };
91c6c8fea2SSven Eckelmann 
92c6c8fea2SSven Eckelmann #define BCAST_QUEUE_LEN		256
93c6c8fea2SSven Eckelmann #define BATMAN_QUEUE_LEN	256
94c6c8fea2SSven Eckelmann 
95c6bda689SAntonio Quartulli enum uev_action {
96c6bda689SAntonio Quartulli 	UEV_ADD = 0,
97c6bda689SAntonio Quartulli 	UEV_DEL,
98c6bda689SAntonio Quartulli 	UEV_CHANGE
99c6bda689SAntonio Quartulli };
100c6bda689SAntonio Quartulli 
101c6bda689SAntonio Quartulli enum uev_type {
102c6bda689SAntonio Quartulli 	UEV_GW = 0
103c6bda689SAntonio Quartulli };
104c6bda689SAntonio Quartulli 
10543676ab5SAntonio Quartulli #define GW_THRESHOLD	50
10643676ab5SAntonio Quartulli 
107c6c8fea2SSven Eckelmann /*
108c6c8fea2SSven Eckelmann  * Debug Messages
109c6c8fea2SSven Eckelmann  */
110c6c8fea2SSven Eckelmann #ifdef pr_fmt
111c6c8fea2SSven Eckelmann #undef pr_fmt
112c6c8fea2SSven Eckelmann #endif
1136e215fd8SSven Eckelmann /* Append 'batman-adv: ' before kernel messages */
1146e215fd8SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
115c6c8fea2SSven Eckelmann 
1166e215fd8SSven Eckelmann /* all messages related to routing / flooding / broadcasting / etc */
117e8958dbfSSven Eckelmann enum dbg_level {
118e8958dbfSSven Eckelmann 	DBG_BATMAN = 1 << 0,
119e8958dbfSSven Eckelmann 	DBG_ROUTES = 1 << 1, /* route added / changed / deleted */
120a73105b8SAntonio Quartulli 	DBG_TT	   = 1 << 2, /* translation table operations */
121a73105b8SAntonio Quartulli 	DBG_ALL    = 7
122e8958dbfSSven Eckelmann };
123c6c8fea2SSven Eckelmann 
124c6c8fea2SSven Eckelmann 
125c6c8fea2SSven Eckelmann /*
126c6c8fea2SSven Eckelmann  *  Vis
127c6c8fea2SSven Eckelmann  */
128c6c8fea2SSven Eckelmann 
129c6c8fea2SSven Eckelmann /*
130c6c8fea2SSven Eckelmann  * Kernel headers
131c6c8fea2SSven Eckelmann  */
132c6c8fea2SSven Eckelmann 
133c6c8fea2SSven Eckelmann #include <linux/mutex.h>	/* mutex */
134c6c8fea2SSven Eckelmann #include <linux/module.h>	/* needed by all modules */
135c6c8fea2SSven Eckelmann #include <linux/netdevice.h>	/* netdevice */
136*015758d0SAntonio Quartulli #include <linux/etherdevice.h>  /* ethernet address classification */
137c6c8fea2SSven Eckelmann #include <linux/if_ether.h>	/* ethernet header */
138c6c8fea2SSven Eckelmann #include <linux/poll.h>		/* poll_table */
139c6c8fea2SSven Eckelmann #include <linux/kthread.h>	/* kernel threads */
140c6c8fea2SSven Eckelmann #include <linux/pkt_sched.h>	/* schedule types */
141c6c8fea2SSven Eckelmann #include <linux/workqueue.h>	/* workqueue */
142c6c8fea2SSven Eckelmann #include <linux/slab.h>
143c6c8fea2SSven Eckelmann #include <net/sock.h>		/* struct sock */
144c6c8fea2SSven Eckelmann #include <linux/jiffies.h>
145c6c8fea2SSven Eckelmann #include <linux/seq_file.h>
146c6c8fea2SSven Eckelmann #include "types.h"
147c6c8fea2SSven Eckelmann 
1484389e47aSMarek Lindner extern struct list_head hardif_list;
149c6c8fea2SSven Eckelmann 
150c6c8fea2SSven Eckelmann extern unsigned char broadcast_addr[];
151c6c8fea2SSven Eckelmann extern struct workqueue_struct *bat_event_workqueue;
152c6c8fea2SSven Eckelmann 
153c6c8fea2SSven Eckelmann int mesh_init(struct net_device *soft_iface);
154c6c8fea2SSven Eckelmann void mesh_free(struct net_device *soft_iface);
155c6c8fea2SSven Eckelmann void inc_module_count(void);
156c6c8fea2SSven Eckelmann void dec_module_count(void);
157747e4221SSven Eckelmann int is_my_mac(const uint8_t *addr);
158c6c8fea2SSven Eckelmann 
159c6c8fea2SSven Eckelmann #ifdef CONFIG_BATMAN_ADV_DEBUG
160747e4221SSven Eckelmann int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3);
161c6c8fea2SSven Eckelmann 
162c6c8fea2SSven Eckelmann #define bat_dbg(type, bat_priv, fmt, arg...)			\
163c6c8fea2SSven Eckelmann 	do {							\
164c6c8fea2SSven Eckelmann 		if (atomic_read(&bat_priv->log_level) & type)	\
165c6c8fea2SSven Eckelmann 			debug_log(bat_priv, fmt, ## arg);	\
166c6c8fea2SSven Eckelmann 	}							\
167c6c8fea2SSven Eckelmann 	while (0)
168c6c8fea2SSven Eckelmann #else /* !CONFIG_BATMAN_ADV_DEBUG */
169d3a547beSSven Eckelmann __printf(3, 4)
170b4e17054SSven Eckelmann static inline void bat_dbg(int type __always_unused,
171aa0adb1aSSven Eckelmann 			   struct bat_priv *bat_priv __always_unused,
172747e4221SSven Eckelmann 			   const char *fmt __always_unused, ...)
173c6c8fea2SSven Eckelmann {
174c6c8fea2SSven Eckelmann }
175c6c8fea2SSven Eckelmann #endif
176c6c8fea2SSven Eckelmann 
177c6c8fea2SSven Eckelmann #define bat_info(net_dev, fmt, arg...)					\
178c6c8fea2SSven Eckelmann 	do {								\
179c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
180c6c8fea2SSven Eckelmann 		struct bat_priv *_batpriv = netdev_priv(_netdev);       \
181c6c8fea2SSven Eckelmann 		bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);		\
182c6c8fea2SSven Eckelmann 		pr_info("%s: " fmt, _netdev->name, ## arg);		\
183c6c8fea2SSven Eckelmann 	} while (0)
184c6c8fea2SSven Eckelmann #define bat_err(net_dev, fmt, arg...)					\
185c6c8fea2SSven Eckelmann 	do {								\
186c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
187c6c8fea2SSven Eckelmann 		struct bat_priv *_batpriv = netdev_priv(_netdev);       \
188c6c8fea2SSven Eckelmann 		bat_dbg(DBG_ALL, _batpriv, fmt, ## arg);		\
189c6c8fea2SSven Eckelmann 		pr_err("%s: " fmt, _netdev->name, ## arg);		\
190c6c8fea2SSven Eckelmann 	} while (0)
191c6c8fea2SSven Eckelmann 
19239901e71SMarek Lindner /**
19339901e71SMarek Lindner  * returns 1 if they are the same ethernet addr
19439901e71SMarek Lindner  *
19539901e71SMarek Lindner  * note: can't use compare_ether_addr() as it requires aligned memory
19639901e71SMarek Lindner  */
197747e4221SSven Eckelmann 
198747e4221SSven Eckelmann static inline int compare_eth(const void *data1, const void *data2)
19939901e71SMarek Lindner {
20039901e71SMarek Lindner 	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
20139901e71SMarek Lindner }
20239901e71SMarek Lindner 
203747e4221SSven Eckelmann 
2045f657ec0SAntonio Quartulli #define atomic_dec_not_zero(v)	atomic_add_unless((v), -1, 0)
2055f657ec0SAntonio Quartulli 
206f5d33d37SAntonio Quartulli /* Returns the smallest signed integer in two's complement with the sizeof x */
207f5d33d37SAntonio Quartulli #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
208f5d33d37SAntonio Quartulli 
209f5d33d37SAntonio Quartulli /* Checks if a sequence number x is a predecessor/successor of y.
210f5d33d37SAntonio Quartulli  * they handle overflows/underflows and can correctly check for a
211f5d33d37SAntonio Quartulli  * predecessor/successor unless the variable sequence number has grown by
212f5d33d37SAntonio Quartulli  * more then 2**(bitwidth(x)-1)-1.
213f5d33d37SAntonio Quartulli  * This means that for a uint8_t with the maximum value 255, it would think:
214f5d33d37SAntonio Quartulli  *  - when adding nothing - it is neither a predecessor nor a successor
215f5d33d37SAntonio Quartulli  *  - before adding more than 127 to the starting value - it is a predecessor,
216f5d33d37SAntonio Quartulli  *  - when adding 128 - it is neither a predecessor nor a successor,
217f5d33d37SAntonio Quartulli  *  - after adding more than 127 to the starting value - it is a successor */
2180bb85751SSven Eckelmann #define seq_before(x, y) ({typeof(x) _d1 = (x); \
2190bb85751SSven Eckelmann 			  typeof(y) _d2 = (y); \
2200bb85751SSven Eckelmann 			  typeof(x) _dummy = (_d1 - _d2); \
2210bb85751SSven Eckelmann 			  (void) (&_d1 == &_d2); \
222f5d33d37SAntonio Quartulli 			  _dummy > smallest_signed_int(_dummy); })
223f5d33d37SAntonio Quartulli #define seq_after(x, y) seq_before(y, x)
224f5d33d37SAntonio Quartulli 
225c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */
226