summaryrefslogtreecommitdiffstats
path: root/net/batman-adv/types.h
blob: 03197f5ebf6ce05d35195dcbf5c3333a77f27855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
 *
 * Marek Lindner, Simon Wunderlich
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA
 */

#ifndef _NET_BATMAN_ADV_TYPES_H_
#define _NET_BATMAN_ADV_TYPES_H_

#include "packet.h"
#include "bitarray.h"
#include <linux/kernel.h>

/**
 * Maximum overhead for the encapsulation for a payload packet
 */
#define BATADV_HEADER_LEN \
	(ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
			sizeof(struct batadv_bcast_packet)))

#ifdef CONFIG_BATMAN_ADV_DAT

/* batadv_dat_addr_t is the type used for all DHT addresses. If it is changed,
 * BATADV_DAT_ADDR_MAX is changed as well.
 *
 * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
 */
#define batadv_dat_addr_t uint16_t

#endif /* CONFIG_BATMAN_ADV_DAT */

/**
 * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
 * @ogm_buff: buffer holding the OGM packet
 * @ogm_buff_len: length of the OGM packet buffer
 * @ogm_seqno: OGM sequence number - used to identify each OGM
 */
struct batadv_hard_iface_bat_iv {
	unsigned char *ogm_buff;
	int ogm_buff_len;
	atomic_t ogm_seqno;
};

/**
 * struct batadv_hard_iface - network device known to batman-adv
 * @list: list node for batadv_hardif_list
 * @if_num: identificator of the interface
 * @if_status: status of the interface for batman-adv
 * @net_dev: pointer to the net_device
 * @frag_seqno: last fragment sequence number sent by this interface
 * @hardif_obj: kobject of the per interface sysfs "mesh" directory
 * @refcount: number of contexts the object is used
 * @batman_adv_ptype: packet type describing packets that should be processed by
 *  batman-adv for this interface
 * @soft_iface: the batman-adv interface which uses this network interface
 * @rcu: struct used for freeing in an RCU-safe manner
 * @bat_iv: BATMAN IV specific per hard interface data
 */
struct batadv_hard_iface {
	struct list_head list;
	int16_t if_num;
	char if_status;
	struct net_device *net_dev;
	atomic_t frag_seqno;
	struct kobject *hardif_obj;
	atomic_t refcount;
	struct packet_type batman_adv_ptype;
	struct net_device *soft_iface;
	struct rcu_head rcu;
	struct batadv_hard_iface_bat_iv bat_iv;
};

/**
 * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
 * @orig: originator ethernet address
 * @primary_addr: hosts primary interface address
 * @router: router that should be used to reach this originator
 * @batadv_dat_addr_t:  address of the orig node in the distributed hash
 * @bcast_own: bitfield containing the number of our OGMs this orig_node
 *  rebroadcasted "back" to us (relative to last_real_seqno)
 * @bcast_own_sum: counted result of bcast_own
 * @last_seen: time when last packet from this node was received
 * @bcast_seqno_reset: time when the broadcast seqno window was reset
 * @batman_seqno_reset: time when the batman seqno window was reset
 * @gw_flags: flags related to gateway class
 * @flags: for now only VIS_SERVER flag
 * @last_ttvn: last seen translation table version number
 * @tt_crc: CRC of the translation table
 * @tt_buff: last tt changeset this node received from the orig node
 * @tt_buff_len: length of the last tt changeset this node received from the
 *  orig node
 * @tt_buff_lock: lock that protects tt_buff and tt_buff_len
 * @tt_size: number of global TT entries announced by the orig node
 * @tt_initialised: bool keeping track of whether or not this node have received
 *  any translation table information from the orig node yet
 * @last_real_seqno: last and best known sequence number
 * @last_ttl: ttl of last received packet
 * @bcast_bits: bitfield containing the info which payload broadcast originated
 *  from this orig node this host already has seen (relative to
 *  last_bcast_seqno)
 * @last_bcast_seqno: last broadcast sequence number received by this host
 * @neigh_list: list of potential next hop neighbor towards this orig node
 * @frag_list: fragmentation buffer list for fragment re-assembly
 * @last_frag_packet: time when last fragmented packet from this node was
 *  received
 * @neigh_list_lock: lock protecting neigh_list, router and bonding_list
 * @hash_entry: hlist node for batadv_priv::orig_hash
 * @bat_priv: pointer to soft_iface this orig node belongs to
 * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
 *  neigh_node->real_bits & neigh_node->real_packet_count
 * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno
 * @bond_candidates: how many candidates are available
 * @bond_list: list of bonding candidates
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
struct batadv_orig_node {
	uint8_t orig[ETH_ALEN];
	uint8_t primary_addr[ETH_ALEN];
	struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
#ifdef CONFIG_BATMAN_ADV_DAT
	batadv_dat_addr_t dat_addr;
#endif
	unsigned long *bcast_own;
	uint8_t *bcast_own_sum;
	unsigned long last_seen;
	unsigned long bcast_seqno_reset;
	unsigned long batman_seqno_reset;
	uint8_t gw_flags;
	uint8_t flags;
	atomic_t last_ttvn;
	uint16_t tt_crc;
	unsigned char *tt_buff;
	int16_t tt_buff_len;
	spinlock_t tt_buff_lock; /* protects tt_buff & tt_buff_len */
	atomic_t tt_size;
	bool tt_initialised;
	uint32_t last_real_seqno;
	uint8_t last_ttl;
	DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
	uint32_t last_bcast_seqno;
	struct hlist_head neigh_list;
	struct list_head frag_list;
	unsigned long last_frag_packet;
	/* neigh_list_lock protects: neigh_list, router & bonding_list */
	spinlock_t neigh_list_lock;
	struct hlist_node hash_entry;
	struct batadv_priv *bat_priv;
	/* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
	 * neigh_node->real_bits & neigh_node->real_packet_count
	 */
	spinlock_t ogm_cnt_lock;
	/* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
	spinlock_t bcast_seqno_lock;
	atomic_t bond_candidates;
	struct list_head bond_list;
	atomic_t refcount;
	struct rcu_head rcu;
};

/**
 * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
 * @list: list node for batadv_priv_gw::list
 * @orig_node: pointer to corresponding orig node
 * @deleted: this struct is scheduled for deletion
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
struct batadv_gw_node {
	struct hlist_node list;
	struct batadv_orig_node *orig_node;
	unsigned long deleted;
	atomic_t refcount;
	struct rcu_head rcu;
};

/**
 * struct batadv_neigh_node - structure for single hop neighbors
 * @list: list node for batadv_orig_node::neigh_list
 * @addr: mac address of neigh node
 * @tq_recv: ring buffer of received TQ values from this neigh node
 * @tq_index: ring buffer index
 * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
 * @last_ttl: last received ttl from this neigh node
 * @bonding_list: list node for batadv_orig_node::bond_list
 * @last_seen: when last packet via this neighbor was received
 * @real_bits: bitfield containing the number of OGMs received from this neigh
 *  node (relative to orig_node->last_real_seqno)
 * @real_packet_count: counted result of real_bits
 * @orig_node: pointer to corresponding orig_node
 * @if_incoming: pointer to incoming hard interface
 * @lq_update_lock: lock protecting tq_recv & tq_index
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
struct batadv_neigh_node {
	struct hlist_node list;
	uint8_t addr[ETH_ALEN];
	uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
	uint8_t tq_index;
	uint8_t tq_avg;
	uint8_t last_ttl;
	struct list_head bonding_list;
	unsigned long last_seen;
	DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
	uint8_t real_packet_count;
	struct batadv_orig_node *orig_node;
	struct batadv_hard_iface *if_incoming;
	spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
	atomic_t refcount;
	struct rcu_head rcu;
};

/**
 * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
 * @orig[ETH_ALEN]: mac address of orig node orginating the broadcast
 * @crc: crc32 checksum of broadcast payload
 * @entrytime: time when the broadcast packet was received
 */
#ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_bcast_duplist_entry {
	uint8_t orig[ETH_ALEN];
	__be32 crc;
	unsigned long entrytime;
};
#endif

/**
 * enum batadv_counters - indices for traffic counters
 * @BATADV_CNT_TX: transmitted payload traffic packet counter
 * @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter
 * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet counter
 * @BATADV_CNT_RX: received payload traffic packet counter
 * @BATADV_CNT_RX_BYTES: received payload traffic bytes counter
 * @BATADV_CNT_FORWARD: forwarded payload traffic packet counter
 * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
 * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet counter
 * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes counter
 * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
 * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes counter
 * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
 * @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter
 * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet counter
 * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
 * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet counter
 * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
 * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
 * @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter
 * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
 * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter
 * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet
 *  counter
 * @BATADV_CNT_NUM: number of traffic counters
 */
enum batadv_counters {
	BATADV_CNT_TX,
	BATADV_CNT_TX_BYTES,
	BATADV_CNT_TX_DROPPED,
	BATADV_CNT_RX,
	BATADV_CNT_RX_BYTES,
	BATADV_CNT_FORWARD,
	BATADV_CNT_FORWARD_BYTES,
	BATADV_CNT_MGMT_TX,
	BATADV_CNT_MGMT_TX_BYTES,
	BATADV_CNT_MGMT_RX,
	BATADV_CNT_MGMT_RX_BYTES,
	BATADV_CNT_TT_REQUEST_TX,
	BATADV_CNT_TT_REQUEST_RX,
	BATADV_CNT_TT_RESPONSE_TX,
	BATADV_CNT_TT_RESPONSE_RX,
	BATADV_CNT_TT_ROAM_ADV_TX,
	BATADV_CNT_TT_ROAM_ADV_RX,
#ifdef CONFIG_BATMAN_