blob: f9e0e174b3f6efc9ebadb631968f85971226d1ad [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
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 Eckelmannc6c8fea2010-12-13 11:19:28 +000025#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 Eckelmannc6c8fea2010-12-13 11:19:28 +000037
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020038 /* 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 Quartulli2dafb492011-05-05 08:42:45 +020044#define TT_LOCAL_TIMEOUT 3600 /* in seconds */
Antonio Quartullicc47f662011-04-27 14:27:57 +020045#define TT_CLIENT_ROAM_TIMEOUT 600
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020046/* 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
Antonio Quartullia73105b2011-04-27 14:27:44 +020049#define TT_REQUEST_TIMEOUT 3 /* seconds we have to keep pending tt_req */
50
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000051#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
Antonio Quartullia73105b2011-04-27 14:27:44 +020056#define TT_OGM_APPEND_MAX 3 /* number of OGMs sent with the last tt diff */
57
Antonio Quartullicc47f662011-04-27 14:27:57 +020058#define ROAMING_MAX_TIME 20 /* Time in which a client can roam at most
59 * ROAMING_MAX_COUNT times */
60#define ROAMING_MAX_COUNT 5
61
Marek Lindnerecbd5322011-06-09 17:13:09 +020062#define NO_FLAGS 0
63
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000064#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
65
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000066#define LOG_BUF_LEN 8192 /* has to be a power of 2 */
67
68#define VIS_INTERVAL 5000 /* 5 seconds */
69
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020070/* how much worse secondary interfaces may be to be considered as bonding
71 * candidates */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000072#define BONDING_TQ_THRESHOLD 50
73
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020074/* should not be bigger than 512 bytes or change the size of
75 * forw_packet->direct_link_flags */
76#define MAX_AGGREGATION_BYTES 512
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000077#define MAX_AGGREGATION_MS 100
78
79#define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */
80
Sven Eckelmann6e215fd2011-05-08 12:45:45 +020081/* don't reset again within 30 seconds */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000082#define RESET_PROTECTION_MS 30000
83#define EXPECTED_SEQNO_RANGE 65536
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000084
Sven Eckelmanne8958db2011-06-04 11:26:00 +020085enum mesh_state {
86 MESH_INACTIVE,
87 MESH_ACTIVE,
88 MESH_DEACTIVATING
89};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090
91#define BCAST_QUEUE_LEN 256
92#define BATMAN_QUEUE_LEN 256
93
Antonio Quartullic6bda682011-04-26 18:26:01 +020094
95enum uev_action {
96 UEV_ADD = 0,
97 UEV_DEL,
98 UEV_CHANGE
99};
100
101enum uev_type {
102 UEV_GW = 0
103};
104
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000105/*
106 * Debug Messages
107 */
108#ifdef pr_fmt
109#undef pr_fmt
110#endif
Sven Eckelmann6e215fd2011-05-08 12:45:45 +0200111/* Append 'batman-adv: ' before kernel messages */
112#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113
Sven Eckelmann6e215fd2011-05-08 12:45:45 +0200114/* all messages related to routing / flooding / broadcasting / etc */
Sven Eckelmanne8958db2011-06-04 11:26:00 +0200115enum dbg_level {
116 DBG_BATMAN = 1 << 0,
117 DBG_ROUTES = 1 << 1, /* route added / changed / deleted */
Antonio Quartullia73105b2011-04-27 14:27:44 +0200118 DBG_TT = 1 << 2, /* translation table operations */
119 DBG_ALL = 7
Sven Eckelmanne8958db2011-06-04 11:26:00 +0200120};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000121
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000122
123/*
124 * Vis
125 */
126
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000127/*
128 * Kernel headers
129 */
130
131#include <linux/mutex.h> /* mutex */
132#include <linux/module.h> /* needed by all modules */
133#include <linux/netdevice.h> /* netdevice */
134#include <linux/etherdevice.h> /* ethernet address classifaction */
135#include <linux/if_ether.h> /* ethernet header */
136#include <linux/poll.h> /* poll_table */
137#include <linux/kthread.h> /* kernel threads */
138#include <linux/pkt_sched.h> /* schedule types */
139#include <linux/workqueue.h> /* workqueue */
140#include <linux/slab.h>
141#include <net/sock.h> /* struct sock */
142#include <linux/jiffies.h>
143#include <linux/seq_file.h>
144#include "types.h"
145
146#ifndef REVISION_VERSION
147#define REVISION_VERSION_STR ""
148#else
149#define REVISION_VERSION_STR " "REVISION_VERSION
150#endif
151
Marek Lindner4389e472011-02-18 12:33:19 +0000152extern struct list_head hardif_list;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000153
154extern unsigned char broadcast_addr[];
155extern struct workqueue_struct *bat_event_workqueue;
156
157int mesh_init(struct net_device *soft_iface);
158void mesh_free(struct net_device *soft_iface);
159void inc_module_count(void);
160void dec_module_count(void);
Sven Eckelmann747e4222011-05-14 23:14:50 +0200161int is_my_mac(const uint8_t *addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000162
163#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmann747e4222011-05-14 23:14:50 +0200164int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000165
166#define bat_dbg(type, bat_priv, fmt, arg...) \
167 do { \
168 if (atomic_read(&bat_priv->log_level) & type) \
169 debug_log(bat_priv, fmt, ## arg); \
170 } \
171 while (0)
172#else /* !CONFIG_BATMAN_ADV_DEBUG */
Sven Eckelmannd3a547b2011-05-14 23:14:46 +0200173__printf(3, 4)
Sven Eckelmannb4e17052011-06-15 09:41:37 +0200174static inline void bat_dbg(int type __always_unused,
Sven Eckelmannaa0adb12011-01-15 14:39:43 +0000175 struct bat_priv *bat_priv __always_unused,
Sven Eckelmann747e4222011-05-14 23:14:50 +0200176 const char *fmt __always_unused, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000177{
178}
179#endif
180
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000181#define bat_info(net_dev, fmt, arg...) \
182 do { \
183 struct net_device *_netdev = (net_dev); \
184 struct bat_priv *_batpriv = netdev_priv(_netdev); \
185 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
186 pr_info("%s: " fmt, _netdev->name, ## arg); \
187 } while (0)
188#define bat_err(net_dev, fmt, arg...) \
189 do { \
190 struct net_device *_netdev = (net_dev); \
191 struct bat_priv *_batpriv = netdev_priv(_netdev); \
192 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
193 pr_err("%s: " fmt, _netdev->name, ## arg); \
194 } while (0)
195
Marek Lindner39901e72011-02-18 12:28:08 +0000196/**
197 * returns 1 if they are the same ethernet addr
198 *
199 * note: can't use compare_ether_addr() as it requires aligned memory
200 */
Sven Eckelmann747e4222011-05-14 23:14:50 +0200201
202static inline int compare_eth(const void *data1, const void *data2)
Marek Lindner39901e72011-02-18 12:28:08 +0000203{
204 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
205}
206
Sven Eckelmann747e4222011-05-14 23:14:50 +0200207
Antonio Quartulli5f657ec2011-04-20 09:52:56 +0200208#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
209
Antonio Quartullif5d33d32011-05-18 09:20:50 +0200210/* Returns the smallest signed integer in two's complement with the sizeof x */
211#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
212
213/* Checks if a sequence number x is a predecessor/successor of y.
214 * they handle overflows/underflows and can correctly check for a
215 * predecessor/successor unless the variable sequence number has grown by
216 * more then 2**(bitwidth(x)-1)-1.
217 * This means that for a uint8_t with the maximum value 255, it would think:
218 * - when adding nothing - it is neither a predecessor nor a successor
219 * - before adding more than 127 to the starting value - it is a predecessor,
220 * - when adding 128 - it is neither a predecessor nor a successor,
221 * - after adding more than 127 to the starting value - it is a successor */
Sven Eckelmann0bb85752011-05-19 21:43:08 +0200222#define seq_before(x, y) ({typeof(x) _d1 = (x); \
223 typeof(y) _d2 = (y); \
224 typeof(x) _dummy = (_d1 - _d2); \
225 (void) (&_d1 == &_d2); \
226 _dummy > smallest_signed_int(_dummy); })
Antonio Quartullif5d33d32011-05-18 09:20:50 +0200227#define seq_after(x, y) seq_before(y, x)
228
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000229#endif /* _NET_BATMAN_ADV_MAIN_H_ */