-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoriginator.c
2127 lines (1383 loc) · 68.1 KB
/
originator.c
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2006 B.A.T.M.A.N. contributors:
* Simon Wunderlich, Marek Lindner, Axel Neumann
*
* 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
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <linux/if.h> /* ifr_if, ifr_tun */
#include <linux/rtnetlink.h>
#include "batman.h"
#include "os.h"
#include "metrics.h"
#include "originator.h"
#include "plugin.h"
#include "schedule.h"
//#include "avl.h"
static int32_t my_seqno;
int32_t my_pws = DEF_PWS;
int32_t local_lws = DEF_LWS;
int32_t local_rtq_lounge = DEF_RTQ_LOUNGE;
int32_t my_path_lounge = DEF_PATH_LOUNGE;
static int32_t my_path_hystere = DEF_PATH_HYST;
static int32_t my_rcnt_hystere = DEF_RCNT_HYST;
static int32_t my_rcnt_pws = DEF_RCNT_PWS;
/*
static int32_t my_rcnt_lounge = DEF_RCNT_LOUNGE;
*/
static int32_t my_rcnt_fk = DEF_RCNT_FK;
static int32_t my_late_penalty = DEF_LATE_PENAL;
static int32_t drop_2hop_loop = DEF_DROP_2HLOOP;
static int32_t purge_to = DEF_PURGE_TO;
int32_t dad_to = DEF_DAD_TO;
static int32_t Asocial_device = DEF_ASOCIAL;
int32_t Ttl = DEF_TTL;
int32_t wl_clones = DEF_WL_CLONES;
static int32_t my_asym_weight = DEF_ASYM_WEIGHT;
static int32_t my_hop_penalty = DEF_HOP_PENALTY;
static int32_t my_asym_exp = DEF_ASYM_EXP;
static SIMPEL_LIST( pifnb_list );
SIMPEL_LIST( link_list );
//struct avl_tree link_avl = {sizeof( uint32_t), NULL};
AVL_TREE( link_avl, sizeof( uint32_t) );
struct batman_if *primary_if = NULL;
uint32_t primary_addr = 0;
//struct avl_tree orig_avl = {sizeof( uint32_t), NULL};
AVL_TREE( orig_avl, sizeof( uint32_t) );
SIMPEL_LIST( if_list );
static void update_routes( struct orig_node *orig_node, struct neigh_node *new_router ) {
prof_start( PROF_update_routes );
static char old_nh_str[ADDR_STR_LEN], new_nh_str[ADDR_STR_LEN];
dbgf_all( DBGT_INFO, " " );
addr_to_str( (new_router ? new_router->nnkey_addr : 0 ), new_nh_str );
addr_to_str( (orig_node->router ? orig_node->router->nnkey_addr : 0 ), old_nh_str );
/* update routing table and check for changed hna announcements */
if ( orig_node->router != new_router )
dbg( DBGL_CHANGES, DBGT_INFO, "change route to %-15s via %-15s %s %3d / %3d (prev. via %-15s %s %3d)",
orig_node->orig_str,
new_nh_str,
(new_router ? new_router->nnkey_iif->dev : "--"),
(new_router ? new_router->longtm_sqr.wa_val : 0),
orig_node->pws,
old_nh_str,
(orig_node->router ? orig_node->router->nnkey_iif->dev : "--"),
(orig_node->router ? orig_node->router->longtm_sqr.wa_val : 0) );
if ( orig_node->router != new_router ) {
if ( new_router ) {
dbgf_all( DBGT_INFO, "Route to %s via %s", orig_node->orig_str, new_nh_str );
}
/* route altered or deleted */
if ( orig_node->router ) {
add_del_route( orig_node->orig, 32, orig_node->router->nnkey_addr, 0,
orig_node->router->nnkey_iif->if_index,
orig_node->router->nnkey_iif->dev,
RT_TABLE_HOSTS, RTN_UNICAST, DEL, TRACK_OTHER_HOST );
}
/* route altered or new route added */
if ( new_router ) {
orig_node->rt_changes++;
add_del_route( orig_node->orig, 32, new_router->nnkey_addr, primary_addr,
new_router->nnkey_iif->if_index,
new_router->nnkey_iif->dev,
RT_TABLE_HOSTS, RTN_UNICAST, ADD, TRACK_OTHER_HOST );
}
orig_node->router = new_router;
}
prof_stop( PROF_update_routes );
}
static void flush_orig( struct orig_node *orig_node, struct batman_if *bif ) {
struct list_head *neigh_pos /*, *neigh_temp, *neigh_prev */;
struct neigh_node *neigh_node = NULL;
dbgf_all( DBGT_INFO, "%s", ipStr( orig_node->orig ) );
list_for_each( neigh_pos, &orig_node->neigh_list ) {
neigh_node = list_entry( neigh_pos, struct neigh_node, list );
if ( !bif || bif == neigh_node->nnkey_iif ) {
flush_sq_record( &neigh_node->longtm_sqr );
flush_sq_record( &neigh_node->recent_sqr );
}
}
if ( !bif || ( orig_node->router && orig_node->router->nnkey_iif == bif ) ) {
update_routes( orig_node, NULL );
cb_plugin_hooks( orig_node, PLUGIN_CB_ORIG_FLUSH );
}
/*
* plugins must be called with PLUGIN_CB_ORIG_FLUSH and PLUGIN_CB_ORIG_DESRTROY
* before orig_node->router can be destroyed:
*
neigh_prev = (struct list_head *) & orig_node->neigh_list;
// for all neighbours towards this originator ...
list_for_each_safe(neigh_pos, neigh_temp, &orig_node->neigh_list) {
neigh_node = list_entry(neigh_pos, struct neigh_node, list);
if (!bif || (neigh_node->iif == bif)) {
list_del(neigh_prev, neigh_pos, &orig_node->neigh_list);
debugFree(neigh_node, 1403);
} else {
neigh_prev = &neigh_node->list;
}
}
*/
}
static
struct neigh_node *init_neigh_node( struct orig_node *orig_node, uint32_t neigh, struct batman_if *iif, uint16_t seqno, uint32_t last_aware )
{
dbgf_all( DBGT_INFO, " " );
struct neigh_node *neigh_node = debugMalloc( sizeof (struct neigh_node), 403 );
memset( neigh_node, 0, sizeof(struct neigh_node) );
INIT_LIST_HEAD( &neigh_node->list );
neigh_node->nnkey_addr = neigh;
neigh_node->nnkey_iif = iif;
neigh_node->last_aware = last_aware;
list_add_tail( &neigh_node->list, &orig_node->neigh_list );
avl_insert(&orig_node->neigh_avl, neigh_node );
return neigh_node;
}
static
struct neigh_node *update_orig(struct orig_node *on, uint16_t *oCtx, struct msg_buff *mb)
{
prof_start( PROF_update_originator );
struct list_head *neigh_pos;
struct neigh_node *incm_rt = NULL, *tmp_neigh = NULL;
struct neigh_node *curr_rt = on->router;
struct neigh_node *old_rt;
struct bat_packet_ogm *ogm = mb->bp.ogm;
old_rt = curr_rt;
uint32_t max_othr_longtm_val = 0;
uint32_t max_othr_recent_val = 0;
dbgf_all( DBGT_INFO, "%s", on->orig_str );
/* only used for debugging purposes */
if (!on->first_valid_sec)
on->first_valid_sec = batman_time_sec;
// find incoming_neighbor and purge outdated SQNs of alternative next hops
list_for_each( neigh_pos, &on->neigh_list ) {
uint8_t probe = 0;
tmp_neigh = list_entry( neigh_pos, struct neigh_node, list );
if ( ( tmp_neigh->nnkey_addr == mb->neigh ) && ( tmp_neigh->nnkey_iif == mb->iif ) ) {
incm_rt = tmp_neigh;
if (*oCtx & IS_ACCEPTED) {
if (*oCtx & IS_NEW)
probe = PROBE_RANGE;
else
probe = PROBE_RANGE - (my_late_penalty * PROBE_TO100);
}
}
update_lounged_metric(probe, my_path_lounge, ogm->ogm_seqno, on->last_valid_sqn, &tmp_neigh->longtm_sqr,
on->pws);
if ( incm_rt != tmp_neigh)
max_othr_longtm_val = MAX(max_othr_longtm_val, tmp_neigh->longtm_sqr.wa_val);
if ( my_rcnt_fk == MAX_RCNT_FK )
continue;
//if (*oCtx & IS_NEW || (((SQ_TYPE) (on->last_valid_sqn - ogm->ogm_seqno)) <= my_rcnt_lounge))
update_lounged_metric(probe, my_path_lounge, ogm->ogm_seqno, on->last_valid_sqn, &tmp_neigh->recent_sqr,
my_rcnt_pws);
if ( incm_rt != tmp_neigh )
max_othr_recent_val = MAX(max_othr_recent_val, tmp_neigh->recent_sqr.wa_val);
}
paranoia( -500001, !incm_rt );
/*
* The following if-else-else branch implements my currently best known heuristic
* Its tuned for fast path convergence as well as long-term path-quality awareness.
* In the future this should be configurable by each node participating in the mesh.
* Its Fuzzy! The following path-quality characteristics are judged:
* - Recent vers. Longterm path quality
* - eXtreme vers. Conservative distinction to alternative paths
* - Best vers. Worst path quality
* allowing combinations like:
* Recent_Conservative_Best (RCB) -- Recent_eXtreme_Best (RXB) -- Longterm_Conservative_Best (LCB)
* The general idea is to keep/change the path (best neighbor) if:
* - change: (RXB (implying RCB)) || (RCB && LCB)
* - keep: RXB || RCB || LCB
* - not-yet-rebroadcasted (not-yet-finally-decided based on) this or newer seqno
* - incoming packet has been received via incoming_neighbor which is better than all other router
* - curr_router == incoming_neighbor is really the best neighbor towards our destination
* */
int8_t RXB = 0, RCB = 0, LCB = 0, changed = 0;
if ( ( curr_rt != incm_rt ) &&
( ((SQ_TYPE)( on->last_decided_sqn - ogm->ogm_seqno ) >= on->pws ) ) &&
( ( ( my_rcnt_fk == MAX_RCNT_FK ) &&
( ( LCB = ((int)incm_rt->longtm_sqr.wa_val > (int)(max_othr_longtm_val) + (my_path_hystere * PROBE_TO100)) ) )
) || (
( my_rcnt_fk != MAX_RCNT_FK ) &&
( ( ( LCB = ((int)incm_rt->longtm_sqr.wa_val > (int)(max_othr_longtm_val) + (my_path_hystere * PROBE_TO100)) ) &&
( RCB = ((int)incm_rt->recent_sqr.wa_val > (int)(max_othr_recent_val) ) ) )
||
( RXB = ((int)incm_rt->recent_sqr.wa_val > (int)((max_othr_recent_val * my_rcnt_fk)/100) + (my_rcnt_hystere * PROBE_TO100)) )
)
)
)
) {
curr_rt = incm_rt;
on->last_decided_sqn = ogm->ogm_seqno;
*oCtx |= IS_BEST_NEIGH_AND_NOT_BROADCASTED;
changed = YES;
} else if
( ( curr_rt == incm_rt ) &&
( ((SQ_TYPE)( on->last_decided_sqn - ogm->ogm_seqno ) >= on->pws ) ) &&
( ( ( my_rcnt_fk == MAX_RCNT_FK ) &&
( ( LCB = ((int)incm_rt->longtm_sqr.wa_val >= (int)(max_othr_longtm_val) - (my_path_hystere * PROBE_TO100)) ) )
) || (
( my_rcnt_fk != MAX_RCNT_FK ) &&
( ( ( LCB = ((int)incm_rt->longtm_sqr.wa_val >= (int)(max_othr_longtm_val) - (my_path_hystere * PROBE_TO100)) ) ||
( RCB = ((int)incm_rt->recent_sqr.wa_val >= (int)(max_othr_recent_val) ) ) )
)
)
)
) {
on->last_decided_sqn = ogm->ogm_seqno;
*oCtx |= IS_BEST_NEIGH_AND_NOT_BROADCASTED;
}
if ( changed && !LCB ) {
dbgf(DBGL_CHANGES, DBGT_INFO,
"%s path to %-15s via %-15s (old %-15s incm %-15s) due to %s %s %s PH: "
"recent incm %3d othr %3d fk %-4d "
"longtm incm %3d othr %3d",
changed ? "NEW" : "OLD",
on->orig_str,
curr_rt ? ipStr(curr_rt->nnkey_addr) : "----",
old_rt ? ipStr(old_rt->nnkey_addr) : "----",
ipStr(incm_rt->nnkey_addr),
LCB ? " LCB" : "!LCB",
RCB ? " RCB" : "!RCB",
RXB ? " RXB" : "!RXB",
incm_rt->recent_sqr.wa_val / PROBE_TO100,
max_othr_recent_val, my_rcnt_fk,
incm_rt->longtm_sqr.wa_val / PROBE_TO100,
max_othr_longtm_val
);
}
if ( curr_rt != incm_rt ) {
// only evaluate and change recorded attributes and route if arrived via best neighbor
prof_stop( PROF_update_originator );
return curr_rt;
}
on->last_path_ttl = ogm->ogm_ttl;
on->ogx_flag = ogm->ogx_flag;
on->ogm_misc = ogm->ogm_misc;
if ( on->pws != ogm->ogm_pws ) {
dbg( DBGL_SYS, DBGT_INFO,
"window size of OG %s changed from %d to %d, flushing packets and route!",
on->orig_str, on->pws, ogm->ogm_pws );
on->pws = ogm->ogm_pws;
flush_orig( on, NULL );
prof_stop( PROF_update_originator );
return NULL;
}
prof_stop( PROF_update_originator );
return curr_rt;
}
static
void free_pifnb_node( struct orig_node *orig_node ) {
struct pifnb_node *pn;
struct list_head *pifnb_pos, *pifnb_pos_tmp, *prev_list_head;
paranoia( -500013, ( !orig_node->id4him ) ); //free_pifnb_node(): requested to free pifnb_node with id4him of zero
prev_list_head = (struct list_head *)&pifnb_list;
list_for_each_safe( pifnb_pos, pifnb_pos_tmp, &pifnb_list ) {
pn = list_entry(pifnb_pos, struct pifnb_node, list);
if ( pn->pog == orig_node ) {
list_del( prev_list_head, pifnb_pos, &pifnb_list );
orig_node->id4him = 0;
debugFree( pn, 1429 );
break;
} else {
prev_list_head = &pn->list;
}
}
paranoia( -500012, ( orig_node->id4him != 0 )); //free_pifnb_node(): requested to free non-existent pifnb_node
}
static
int8_t init_pifnb_node( struct orig_node *orig_node ) {
struct pifnb_node *pn_tmp = NULL;
struct list_head *list_pos, *prev_list_head;
uint16_t id4him = 1;
paranoia( -500011, ( orig_node->id4him != 0 ) );//init_pifnb_node(): requested to init already existing pifnb_node
prev_list_head = (struct list_head *)&pifnb_list;
list_for_each( list_pos, &pifnb_list ) {
pn_tmp = list_entry( list_pos, struct pifnb_node, list );
if ( pn_tmp->pog->id4him > id4him )
break;
id4him++;
if ( id4him >= MAX_ID4HIM ) {
dbgf( DBGL_SYS, DBGT_ERR, "Max numbers of pifnb_nodes reached!");
return FAILURE;
}
prev_list_head = &pn_tmp->list;
pn_tmp = NULL;
}
struct pifnb_node *pn = debugMalloc( sizeof(struct pifnb_node), 429 );
memset( pn, 0, sizeof(struct pifnb_node) );
INIT_LIST_HEAD( &pn->list );
pn->pog = orig_node;
orig_node->id4him = id4him;
if ( pn_tmp )
list_add_before( prev_list_head, list_pos, &pn->list );
else if ( ( pn_tmp == NULL ) || ( pn_tmp->pog->id4him <= orig_node->id4him ) )
list_add_tail( &pn->list, &pifnb_list );
return SUCCESS;
}
static
void free_link_node( struct orig_node *orig_node, struct batman_if *bif ) {
struct link_node *ln;
struct list_head *list_pos, *list_tmp, *list_prev;
dbgf_all( DBGT_INFO, "of orig %s", orig_node->orig_str);
paranoia( -500010, ( orig_node->link_node == NULL ) ); //free_link_node(): requested to free non-existing link_node
ln = orig_node->link_node;
list_prev = (struct list_head *)&ln->lndev_list;
list_for_each_safe( list_pos, list_tmp, &ln->lndev_list ) {
struct link_node_dev *lndev = list_entry( list_pos, struct link_node_dev, list );
if ( !bif || lndev->bif == bif ) {
dbgf_all( DBGT_INFO, "purging lndev %16s %10s %s",
orig_node->orig_str, lndev->bif->dev, lndev->bif->if_ip_str );
list_del( list_prev, list_pos, &ln->lndev_list );
debugFree( list_pos, 1429 );
} else {
list_prev = list_pos;
}
}
list_prev = (struct list_head *)&link_list;
list_for_each_safe( list_pos, list_tmp, &link_list ) {
ln = list_entry( list_pos, struct link_node, list);
if ( ln->orig_node == orig_node && list_empty( &ln->lndev_list ) ) {
dbgf_all( DBGT_INFO, "purging link_node %16s ", orig_node->orig_str);
list_del( list_prev, list_pos, &link_list );
avl_remove(&link_avl, /*(uint32_t*)*/orig_node->link_node);
debugFree( orig_node->link_node, 1428 );
orig_node->link_node = NULL;
break;
} else {
list_prev = list_pos;
}
}
}
static
void flush_link_node_seqnos( void ) {
struct list_head *ln_pos, *lndev_pos, *lndev_tmp;
struct link_node *ln = NULL;
list_for_each( ln_pos, &link_list ) {
ln = list_entry( ln_pos, struct link_node, list );
list_for_each_safe( lndev_pos, lndev_tmp, &ln->lndev_list ) {
struct link_node_dev *lndev = list_entry( lndev_pos, struct link_node_dev, list );
dbgf( DBGL_CHANGES, DBGT_INFO, "purging lndev %16s %10s %s",
ln->orig_node->orig_str, lndev->bif->dev, lndev->bif->if_ip_str );
list_del( (struct list_head *)&ln->lndev_list, lndev_pos, &ln->lndev_list );
debugFree( lndev_pos, 1429 );
}
}
}
static
void init_link_node( struct orig_node *orig_node ) {
struct link_node *ln;
dbgf_all( DBGT_INFO, "%s", orig_node->orig_str );
ln = orig_node->link_node = debugMalloc( sizeof(struct link_node), 428 );
memset( ln, 0, sizeof(struct link_node) );
INIT_LIST_HEAD( &ln->list );
ln->orig_node = orig_node;
ln->orig_addr = orig_node->orig;
INIT_LIST_HEAD_FIRST( ln->lndev_list );
list_add_tail ( &ln->list, &link_list );
avl_insert(&link_avl, ln);
}
static
int8_t validate_orig_seqno( struct orig_node *orig_node, uint32_t neigh, SQ_TYPE ogm_seqno ) {
// this originator IP is somehow known..(has ever been valid)
if ( orig_node->last_valid_time || orig_node->last_valid_sqn ) {
if ( (uint16_t)( ogm_seqno + my_path_lounge - orig_node->last_valid_sqn ) >
MAX_SEQNO - orig_node->pws ) {
dbg_mute( 25, DBGL_CHANGES, DBGT_WARN,
"drop OGM %-15s via %4s NB %-15s with old SQN %5i "
"(prev %5i lounge-margin %2i pws %3d lvld %d) !",
orig_node->orig_str,
(orig_node->router && orig_node->router->nnkey_addr == neigh) ? "best" : "altn",
ipStr(neigh),
ogm_seqno,
orig_node->last_valid_sqn,
my_path_lounge, orig_node->pws, orig_node->last_valid_time );
return FAILURE;
}
if (// if seqno is more than 10 times out of dad timeout
((uint16_t) (ogm_seqno + my_path_lounge - orig_node->last_valid_sqn)) >
(my_path_lounge +
((1000 * dad_to) / MIN(WAVG(orig_node->ogi_wavg, OGI_WAVG_EXP), MIN_OGI))) &&
// but we have received an ogm in less than timeout sec
LESS_U32(batman_time, (orig_node->last_valid_time + (1000 * dad_to))))
{
dbg_mute( 26, DBGL_SYS, DBGT_WARN,
"DAD-alert! %s via NB %s with out-of-range SQN %i lounge-margin %i "
"lvld %i at %d dad_to %d wavg %d Reinit in %d s",
orig_node->orig_str, ipStr(neigh), ogm_seqno, my_path_lounge,
orig_node->last_valid_sqn, orig_node->last_valid_time,
dad_to, WAVG(orig_node->ogi_wavg, OGI_WAVG_EXP),
((orig_node->last_valid_time + (1000 * dad_to)) - batman_time)/1000 );
return FAILURE;
}
} else {
// init orig sqns to reasonable values
/*
orig_node->last_valid_sqn = ogm_seqno;
orig_node->last_valid_time = batman_time;
*/
}
return SUCCESS;
}
static void set_primary_orig( struct orig_node *orig_node, uint32_t new_primary_addr ) {
if ( orig_node->primary_orig_node && ( !new_primary_addr || orig_node->primary_orig_node->orig != new_primary_addr ) ) {
// remove old:
if ( orig_node->primary_orig_node != orig_node ) {
orig_node->primary_orig_node->pog_refcnt--;
paranoia( -500152, orig_node->pog_refcnt < 0 );
}
orig_node->primary_orig_node = NULL;
}
if ( new_primary_addr && ( !orig_node->primary_orig_node || orig_node->primary_orig_node->orig != new_primary_addr ) ) {
// add new:
if ( orig_node->orig != new_primary_addr ) {
orig_node->primary_orig_node = get_orig_node( new_primary_addr, YES/*create*/ );
orig_node->primary_orig_node->pog_refcnt++;
} else {
orig_node->primary_orig_node = orig_node;
}
}
}
static
int8_t validate_primary_orig( struct orig_node *orig_node, struct msg_buff *mb, uint16_t oCtx ) {
if ( mb->rcv_ext_len[EXT_TYPE_64B_PIP] ) {
struct ext_packet *pip = mb->rcv_ext_array[EXT_TYPE_64B_PIP];
dbgf_all( DBGT_INFO, "orig %s neigh %s", mb->orig_str, mb->neigh_str );
if ( orig_node->primary_orig_node ) {
if ( orig_node->primary_orig_node->orig != pip->EXT_PIP_FIELD_ADDR ) {
dbg_mute( 45, DBGL_SYS, DBGT_WARN,
"neighbor %s changed his primary interface from %s to %s !",
orig_node->orig_str,
orig_node->primary_orig_node->orig_str,
ipStr( pip->EXT_PIP_FIELD_ADDR ) );
if ( orig_node->primary_orig_node->id4him )
free_pifnb_node( orig_node->primary_orig_node );
set_primary_orig( orig_node, pip->EXT_PIP_FIELD_ADDR );
//orig_node->primary_orig_node = get_orig_node( pip->EXT_PIP_FIELD_ADDR, YES/*create*/ );
}
} else {
set_primary_orig( orig_node, pip->EXT_PIP_FIELD_ADDR );
//orig_node->primary_orig_node = get_orig_node( pip->EXT_PIP_FIELD_ADDR, YES/*create*/ );
}
if ( pip->EXT_PIP_FIELD_PIPSEQNO && //remain compatible to COMPAT_VERSION 10
validate_orig_seqno( orig_node->primary_orig_node, 0, ntohs( pip->EXT_PIP_FIELD_PIPSEQNO ) ) == FAILURE )
{
//orig_node->primary_orig_node = NULL;
set_primary_orig( orig_node, 0 );
return FAILURE;
}
} else {
if ( orig_node->primary_orig_node ) {
if ( orig_node->primary_orig_node != orig_node ) {
dbg_mute( 30, DBGL_SYS, DBGT_WARN,
"neighbor %s changed primary interface from %s to %s !",
orig_node->orig_str,
orig_node->primary_orig_node->orig_str,
orig_node->orig_str );
if ( orig_node->primary_orig_node->id4him )
free_pifnb_node( orig_node->primary_orig_node );
//orig_node->primary_orig_node = orig_node;
set_primary_orig( orig_node, orig_node->orig );
}
} else {
//orig_node->primary_orig_node = orig_node;
set_primary_orig( orig_node, orig_node->orig );
}
}
orig_node->primary_orig_node->last_aware = batman_time;
if ( (oCtx & IS_DIRECT_NEIGH) && !(orig_node->primary_orig_node->id4him) )
return init_pifnb_node( orig_node->primary_orig_node );
return SUCCESS;
}
static
void update_rtq_link(struct orig_node *orig_node_neigh, uint16_t oCtx, struct msg_buff *mb,
struct batman_if *iif, struct bat_packet_ogm *ogm, struct link_node_dev *lndev)
{
dbgf_all(DBGT_INFO,
"received own OGM via NB, lastTxIfSeqno: %d, currRxSeqno: %d oCtx: 0x%X "
"link_node %s primary_orig %s",
(iif->if_seqno - OUT_SEQNO_OFFSET), ogm->ogm_seqno, oCtx,
(orig_node_neigh->link_node ? "exist" : "NOT exists"),
(orig_node_neigh->primary_orig_node ? "exist" : "NOT exists"));
if (!(oCtx & HAS_DIRECTLINK_FLAG) || (oCtx & HAS_CLONED_FLAG) || iif->if_addr != ogm->orig)
return;
if (((SQ_TYPE) ((iif->if_seqno - OUT_SEQNO_OFFSET) - ogm->ogm_seqno)) > local_rtq_lounge ) {
dbg_mute(51, DBGL_CHANGES, DBGT_WARN,
"late reception of own OGM via NB %s lastTxIfSqn %d rcvdSqn %d margin %d ! "
"Try configureing a greater --%s value .",
mb->neigh_str, (iif->if_seqno - OUT_SEQNO_OFFSET),
ogm->ogm_seqno, local_rtq_lounge, ARG_RTQ_LOUNGE);
return;
}
/* neighbour has to indicate direct link and it has to come via the corresponding interface */
/* if received seqno equals last send seqno save new seqno for bidirectional check */
if (orig_node_neigh->link_node && orig_node_neigh->primary_orig_node && lndev) {
update_lounged_metric(PROBE_RANGE, local_rtq_lounge, ogm->ogm_seqno, (iif->if_seqno - OUT_SEQNO_OFFSET),
&lndev->rtq_sqr, local_lws);
if (orig_node_neigh->primary_orig_node->id4me != ogm->prev_hop_id) {
if (orig_node_neigh->primary_orig_node->id4me != 0)
dbg_mute(53, DBGL_CHANGES, DBGT_WARN,
"received changed prev_hop_id from neighbor %s !!!",
mb->neigh_str);
orig_node_neigh->primary_orig_node->id4me = ogm->prev_hop_id;
}
dbgf_all(DBGT_INFO, "indicating bidirectional link");
}
}
static
void update_rq_link( struct orig_node *orig_node, SQ_TYPE sqn, struct batman_if *iif, uint16_t oCtx ) {
if ( !( (oCtx & IS_DIRECT_NEIGH) || orig_node->link_node ) )
return;
if ( oCtx & IS_DIRECT_NEIGH ) {
orig_node->primary_orig_node->last_pog_link = batman_time;
if ( !orig_node->link_node )
init_link_node( orig_node );
}
dbgf_all( DBGT_INFO, "OG %s SQN %d IF %s ctx %x ln %s cloned %s direct %s",
orig_node->orig_str, sqn, iif->dev, oCtx,
orig_node->link_node ? "YES":"NO",
(oCtx & HAS_CLONED_FLAG) ? "YES":"NO",
(oCtx & IS_DIRECT_NEIGH) ? "YES":"NO" );
// skip updateing link_node if this SQN is known but not new
if ( ( orig_node->last_valid_time || orig_node->last_valid_sqn ) &&
( (uint16_t)( sqn + RQ_LINK_LOUNGE - orig_node->last_valid_sqn ) > MAX_SEQNO - local_lws - MAX_PATH_LOUNGE) )
return;
paranoia( -500156, !orig_node->link_node );
struct list_head *lndev_pos;
struct link_node_dev *lndev, *this_lndev = NULL;
dbgf_all( DBGT_INFO, "[%10s %3s %3s %3s]", "dev","RTQ","RQ","TQ" );
list_for_each( lndev_pos, &orig_node->link_node->lndev_list ) {
lndev = list_entry( lndev_pos, struct link_node_dev, list );
dbgf_all( DBGT_INFO, "[%10s %3i %3i %3i] before", lndev->bif->dev,
(((lndev->rtq_sqr.wa_val))/PROBE_TO100),
(((lndev->rq_sqr.wa_val))/PROBE_TO100),
(((tq_rate( orig_node, lndev->bif, PROBE_RANGE )))/PROBE_TO100) );
if ( lndev->bif == iif ) {
this_lndev = lndev;
} else {
update_lounged_metric( 0, RQ_LINK_LOUNGE, sqn, orig_node->last_valid_sqn, &lndev->rq_sqr, local_lws );
}
}
if ( !this_lndev && (oCtx & IS_DIRECT_NEIGH) )
this_lndev = get_lndev( orig_node->link_node, iif, YES/*create*/ );
if ( this_lndev ) {
uint8_t probe = ( (oCtx & IS_DIRECT_NEIGH) && !(oCtx & HAS_CLONED_FLAG) ) ? PROBE_RANGE : 0;
update_lounged_metric(probe, RQ_LINK_LOUNGE, sqn, orig_node->last_valid_sqn, &this_lndev->rq_sqr, local_lws);
if ( probe)
this_lndev->last_lndev = batman_time;
}
//orig_node->link_node->last_rq_sqn = in_seqno;
/*
list_for_each( lndev_pos, &orig_node->link_node->lndev_list ) {
lndev = list_entry( lndev_pos, struct link_node_dev, list );
dbgf_all( DBGT_INFO, "[%10s %3i %3i %3i] afterwards", lndev->bif->dev,
(((lndev->rtq_sqr.wa_val))/PROBE_TO100),
(((lndev->rq_sqr.wa_val))/PROBE_TO100),
(((tq_rate( orig_node, lndev->bif, PROBE_RANGE )))/PROBE_TO100) );
}
*/
return;
}
static
int tq_power( int tq_rate_value, int range ) {
int tq_power_value = range;
int exp_counter;
for ( exp_counter = 0; exp_counter < my_asym_exp; exp_counter++ )
tq_power_value = ((tq_power_value * tq_rate_value) / range);
return tq_power_value;
}
static
int8_t validate_considered_order( struct orig_node *orig_node, SQ_TYPE seqno, uint32_t neigh, struct batman_if *iif ) {
struct neigh_node_key key = {neigh, iif};
struct avl_node *an = avl_find( &orig_node->neigh_avl, &key );
struct neigh_node *nn = an ? (struct neigh_node*) an->key : NULL;
if (nn) {
paranoia( -500198, (nn->nnkey_addr != neigh || nn->nnkey_iif != iif ) );
nn->last_aware = batman_time;
if (seqno == nn->last_considered_seqno) {
return FAILURE;
} else if (((SQ_TYPE) (seqno - nn->last_considered_seqno)) > MAX_SEQNO - my_pws) {
dbgf_ext(DBGT_WARN,
"rcvd illegal SQN %d order from %s via %s %s (last considered sqn %d",
seqno, orig_node->orig_str, ipStr(neigh), iif->dev,
nn->last_considered_seqno);
return FAILURE;
}
nn->last_considered_seqno = seqno;
return SUCCESS;
}
nn = init_neigh_node( orig_node, neigh, iif, seqno, batman_time );
nn->last_considered_seqno = seqno;
return SUCCESS;
}
/* this function finds and may create an originator entry for the given address */
struct orig_node *get_orig_node( uint32_t addr, uint8_t create ) {
prof_start( PROF_get_orig_node );
struct avl_node *an = avl_find( &orig_avl, &addr);
struct orig_node *orig_node = an ? (struct orig_node *) an->key : NULL;
if ( !create ) {
prof_stop( PROF_get_orig_node );
return orig_node;
}
if ( orig_node ) {
orig_node->last_aware = batman_time;
prof_stop( PROF_get_orig_node );
return orig_node;
}
orig_node = debugMalloc( (sizeof(struct orig_node) + (plugin_data_registries[PLUGIN_DATA_ORIG] * sizeof(void*)) ), 402 );
memset( orig_node, 0, (sizeof(struct orig_node) + (plugin_data_registries[PLUGIN_DATA_ORIG] * sizeof(void*) ) ) );
INIT_LIST_HEAD_FIRST( orig_node->neigh_list );
AVL_INIT_TREE( orig_node->neigh_avl, sizeof( struct neigh_node_key ) );
addr_to_str( addr, orig_node->orig_str );
dbgf_all( DBGT_INFO, "creating new originator: %s with %d plugin_data_registries",
orig_node->orig_str, plugin_data_registries[PLUGIN_DATA_ORIG] );
orig_node->orig = addr;
orig_node->last_aware = batman_time;
orig_node->router = NULL;
orig_node->link_node = NULL;
// orig_node->path_lounge = my_path_lounge;
orig_node->pws = my_pws;
// orig_node->path_hystere = my_path_hystere;
// orig_node->late_penalty = my_late_penalty;
// orig_node->hop_penalty = my_hop_penalty;
// orig_node->asym_weight = my_asym_weight;
// orig_node->asym_exp = my_asym_exp;
// orig_node->rcnt_pws = my_rcnt_pws;