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