0001
0002
0003
0004
0005
0006
0007 #ifndef _NET_BATMAN_ADV_MAIN_H_
0008 #define _NET_BATMAN_ADV_MAIN_H_
0009
0010 #define BATADV_DRIVER_AUTHOR "Marek Lindner <mareklindner@neomailbox.ch>, " \
0011 "Simon Wunderlich <sw@simonwunderlich.de>"
0012 #define BATADV_DRIVER_DESC "B.A.T.M.A.N. advanced"
0013 #define BATADV_DRIVER_DEVICE "batman-adv"
0014
0015 #ifndef BATADV_SOURCE_VERSION
0016 #define BATADV_SOURCE_VERSION "2022.2"
0017 #endif
0018
0019
0020
0021 #define BATADV_TQ_MAX_VALUE 255
0022 #define BATADV_THROUGHPUT_MAX_VALUE 0xFFFFFFFF
0023 #define BATADV_JITTER 20
0024
0025
0026 #define BATADV_TTL 50
0027
0028
0029 #define BATADV_BCAST_MAX_AGE 64
0030
0031
0032
0033
0034 #define BATADV_PURGE_TIMEOUT 200000
0035 #define BATADV_TT_LOCAL_TIMEOUT 600000
0036 #define BATADV_TT_CLIENT_ROAM_TIMEOUT 600000
0037 #define BATADV_TT_CLIENT_TEMP_TIMEOUT 600000
0038 #define BATADV_TT_WORK_PERIOD 5000
0039 #define BATADV_ORIG_WORK_PERIOD 1000
0040 #define BATADV_MCAST_WORK_PERIOD 500
0041 #define BATADV_DAT_ENTRY_TIMEOUT (5 * 60000)
0042
0043
0044
0045 #define BATADV_TQ_LOCAL_WINDOW_SIZE 64
0046
0047 #define BATADV_TT_REQUEST_TIMEOUT 3000
0048
0049 #define BATADV_TQ_GLOBAL_WINDOW_SIZE 5
0050 #define BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
0051 #define BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
0052 #define BATADV_TQ_TOTAL_BIDRECT_LIMIT 1
0053
0054
0055 #define BATADV_THROUGHPUT_DEFAULT_VALUE 10
0056 #define BATADV_ELP_PROBES_PER_NODE 2
0057 #define BATADV_ELP_MIN_PROBE_SIZE 200
0058 #define BATADV_ELP_PROBE_MAX_TX_DIFF 100
0059 #define BATADV_ELP_MAX_AGE 64
0060 #define BATADV_OGM_MAX_ORIGDIFF 5
0061 #define BATADV_OGM_MAX_AGE 64
0062
0063
0064 #define BATADV_TT_OGM_APPEND_MAX 3
0065
0066
0067
0068
0069 #define BATADV_ROAMING_MAX_TIME 20000
0070 #define BATADV_ROAMING_MAX_COUNT 5
0071
0072 #define BATADV_NO_FLAGS 0
0073
0074 #define BATADV_NULL_IFINDEX 0
0075
0076 #define BATADV_NO_MARK 0
0077
0078
0079
0080
0081
0082 #define BATADV_IF_DEFAULT ((struct batadv_hard_iface *)NULL)
0083
0084 #define BATADV_NUM_WORDS BITS_TO_LONGS(BATADV_TQ_LOCAL_WINDOW_SIZE)
0085
0086 #define BATADV_LOG_BUF_LEN 8192
0087
0088
0089 #define BATADV_NUM_BCASTS_DEFAULT 1
0090 #define BATADV_NUM_BCASTS_WIRELESS 3
0091
0092
0093 #define BATADV_TP_PACKET_LEN ETH_DATA_LEN
0094
0095
0096 #define ARP_REQ_DELAY 250
0097
0098 #define BATADV_DAT_CANDIDATES_NUM 3
0099
0100
0101
0102
0103 #define BATADV_TQ_SIMILARITY_THRESHOLD 50
0104
0105
0106
0107
0108 #define BATADV_MAX_AGGREGATION_BYTES 512
0109 #define BATADV_MAX_AGGREGATION_MS 100
0110
0111 #define BATADV_BLA_PERIOD_LENGTH 10000
0112 #define BATADV_BLA_BACKBONE_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 6)
0113 #define BATADV_BLA_CLAIM_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 10)
0114 #define BATADV_BLA_WAIT_PERIODS 3
0115 #define BATADV_BLA_LOOPDETECT_PERIODS 6
0116 #define BATADV_BLA_LOOPDETECT_TIMEOUT 3000
0117
0118 #define BATADV_DUPLIST_SIZE 16
0119 #define BATADV_DUPLIST_TIMEOUT 500
0120
0121 #define BATADV_RESET_PROTECTION_MS 30000
0122 #define BATADV_EXPECTED_SEQNO_RANGE 65536
0123
0124 #define BATADV_NC_NODE_TIMEOUT 10000
0125
0126
0127
0128
0129 #define BATADV_TP_MAX_NUM 5
0130
0131
0132
0133
0134 enum batadv_mesh_state {
0135
0136 BATADV_MESH_INACTIVE,
0137
0138
0139 BATADV_MESH_ACTIVE,
0140
0141
0142 BATADV_MESH_DEACTIVATING,
0143 };
0144
0145 #define BATADV_BCAST_QUEUE_LEN 256
0146 #define BATADV_BATMAN_QUEUE_LEN 256
0147
0148
0149
0150
0151 enum batadv_uev_action {
0152
0153 BATADV_UEV_ADD = 0,
0154
0155
0156
0157
0158
0159 BATADV_UEV_DEL,
0160
0161
0162
0163
0164 BATADV_UEV_CHANGE,
0165
0166
0167
0168
0169
0170 BATADV_UEV_LOOPDETECT,
0171 };
0172
0173
0174
0175
0176 enum batadv_uev_type {
0177
0178 BATADV_UEV_GW = 0,
0179
0180
0181 BATADV_UEV_BLA,
0182 };
0183
0184 #define BATADV_GW_THRESHOLD 50
0185
0186
0187 #define BATADV_FRAG_BUFFER_COUNT 8
0188
0189 #define BATADV_FRAG_MAX_FRAGMENTS 16
0190
0191 #define BATADV_FRAG_MAX_FRAG_SIZE 1280
0192
0193 #define BATADV_FRAG_TIMEOUT 10000
0194
0195 #define BATADV_DAT_CANDIDATE_NOT_FOUND 0
0196 #define BATADV_DAT_CANDIDATE_ORIG 1
0197
0198
0199 #ifdef pr_fmt
0200 #undef pr_fmt
0201 #endif
0202
0203 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0204
0205
0206
0207 #include <linux/atomic.h>
0208 #include <linux/compiler.h>
0209 #include <linux/etherdevice.h>
0210 #include <linux/if_vlan.h>
0211 #include <linux/jiffies.h>
0212 #include <linux/netdevice.h>
0213 #include <linux/percpu.h>
0214 #include <linux/skbuff.h>
0215 #include <linux/types.h>
0216 #include <uapi/linux/batadv_packet.h>
0217
0218 #include "types.h"
0219 #include "main.h"
0220
0221
0222
0223
0224
0225
0226
0227 static inline int batadv_print_vid(unsigned short vid)
0228 {
0229 if (vid & BATADV_VLAN_HAS_TAG)
0230 return (int)(vid & VLAN_VID_MASK);
0231 else
0232 return -1;
0233 }
0234
0235 extern struct list_head batadv_hardif_list;
0236 extern unsigned int batadv_hardif_generation;
0237
0238 extern unsigned char batadv_broadcast_addr[];
0239 extern struct workqueue_struct *batadv_event_workqueue;
0240
0241 int batadv_mesh_init(struct net_device *soft_iface);
0242 void batadv_mesh_free(struct net_device *soft_iface);
0243 bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr);
0244 int batadv_max_header_len(void);
0245 void batadv_skb_set_priority(struct sk_buff *skb, int offset);
0246 int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
0247 struct packet_type *ptype,
0248 struct net_device *orig_dev);
0249 int
0250 batadv_recv_handler_register(u8 packet_type,
0251 int (*recv_handler)(struct sk_buff *,
0252 struct batadv_hard_iface *));
0253 void batadv_recv_handler_unregister(u8 packet_type);
0254 __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 static inline bool batadv_compare_eth(const void *data1, const void *data2)
0266 {
0267 return ether_addr_equal_unaligned(data1, data2);
0268 }
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278 static inline bool batadv_has_timed_out(unsigned long timestamp,
0279 unsigned int timeout)
0280 {
0281 return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout));
0282 }
0283
0284
0285
0286
0287
0288
0289
0290 #define batadv_atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
0291
0292
0293
0294
0295
0296
0297
0298
0299 #define batadv_smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319 #define batadv_seq_before(x, y) ({ \
0320 typeof(x)_d1 = (x); \
0321 typeof(y)_d2 = (y); \
0322 typeof(x)_dummy = (_d1 - _d2); \
0323 (void)(&_d1 == &_d2); \
0324 _dummy > batadv_smallest_signed_int(_dummy); \
0325 })
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345 #define batadv_seq_after(x, y) batadv_seq_before(y, x)
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355 static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx,
0356 size_t count)
0357 {
0358 this_cpu_add(bat_priv->bat_counters[idx], count);
0359 }
0360
0361
0362
0363
0364
0365
0366 #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1)
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377 #define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0]))
0378
0379 unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len);
0380 bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid);
0381 int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
0382 enum batadv_uev_action action, const char *data);
0383
0384 #endif