forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisis_pdu.c
2474 lines (2174 loc) · 69.4 KB
/
isis_pdu.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
/*
* IS-IS Rout(e)ing protocol - isis_pdu.c
* PDU processing
*
* Copyright (C) 2001,2002 Sampo Saaristo
* Tampere University of Technology
* Institute of Communications Engineering
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public Licenseas published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* 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; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "memory.h"
#include "thread.h"
#include "linklist.h"
#include "log.h"
#include "stream.h"
#include "vty.h"
#include "hash.h"
#include "prefix.h"
#include "if.h"
#include "checksum.h"
#include "md5.h"
#include "lib_errors.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_flags.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_network.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_dr.h"
#include "isisd/isisd.h"
#include "isisd/isis_dynhn.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/iso_checksum.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
#include "isisd/isis_tlvs.h"
#include "isisd/isis_errors.h"
#include "isisd/fabricd.h"
#include "isisd/isis_tx_queue.h"
#include "isisd/isis_pdu_counter.h"
static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit,
int level)
{
unsigned long lenp;
int retval;
uint16_t length;
uint8_t pdu_type =
(level == IS_LEVEL_1) ? L1_PARTIAL_SEQ_NUM : L2_PARTIAL_SEQ_NUM;
isis_circuit_stream(circuit, &circuit->snd_stream);
fill_fixed_hdr(pdu_type, circuit->snd_stream);
lenp = stream_get_endp(circuit->snd_stream);
stream_putw(circuit->snd_stream, 0); /* PDU length */
stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
stream_putc(circuit->snd_stream, circuit->idx);
stream_putc(circuit->snd_stream, 9); /* code */
stream_putc(circuit->snd_stream, 16); /* len */
stream_putw(circuit->snd_stream, hdr->rem_lifetime);
stream_put(circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
stream_putl(circuit->snd_stream, hdr->seqno);
stream_putw(circuit->snd_stream, hdr->checksum);
length = (uint16_t)stream_get_endp(circuit->snd_stream);
/* Update PDU length */
stream_putw_at(circuit->snd_stream, lenp, length);
pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
retval = circuit->tx(circuit, level);
if (retval != ISIS_OK)
flog_err(EC_ISIS_PACKET,
"ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
return retval;
}
/*
* RECEIVE SIDE
*/
struct iih_info {
struct isis_circuit *circuit;
uint8_t *ssnpa;
int level;
uint8_t circ_type;
uint8_t sys_id[ISIS_SYS_ID_LEN];
uint16_t holdtime;
uint16_t pdu_len;
uint8_t circuit_id;
uint8_t priority;
uint8_t dis[ISIS_SYS_ID_LEN + 1];
bool v4_usable;
bool v6_usable;
struct isis_tlvs *tlvs;
};
static int process_p2p_hello(struct iih_info *iih)
{
struct isis_threeway_adj *tw_adj = iih->tlvs->threeway_adj;
if (tw_adj) {
if (tw_adj->state > ISIS_THREEWAY_DOWN) {
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
iih->circuit->area->area_tag,
iih->circuit->interface->name,
tw_adj->state);
}
return ISIS_WARNING;
}
if (tw_adj->neighbor_set
&& (memcmp(tw_adj->neighbor_id, isis->sysid, ISIS_SYS_ID_LEN)
|| tw_adj->neighbor_circuit_id != (uint32_t) iih->circuit->idx)) {
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
iih->circuit->area->area_tag,
iih->circuit->interface->name);
}
return ISIS_WARNING;
}
}
/*
* My interpertation of the ISO, if no adj exists we will create one for
* the circuit
*/
struct isis_adjacency *adj = iih->circuit->u.p2p.neighbor;
/* If an adjacency exists, check it is with the source of the hello
* packets */
if (adj) {
if (memcmp(iih->sys_id, adj->sysid, ISIS_SYS_ID_LEN)) {
zlog_debug(
"hello source and adjacency do not match, set adj down\n");
isis_adj_state_change(adj, ISIS_ADJ_DOWN,
"adj do not exist");
return ISIS_OK;
}
}
if (!adj || adj->level != iih->circ_type) {
if (!adj) {
adj = isis_new_adj(iih->sys_id, NULL, iih->circ_type,
iih->circuit);
} else {
adj->level = iih->circ_type;
}
iih->circuit->u.p2p.neighbor = adj;
/* Build lsp with the new neighbor entry when a new
* adjacency is formed. Set adjacency circuit type to
* IIH PDU header circuit type before lsp is regenerated
* when an adjacency is up. This will result in the new
* adjacency entry getting added to the lsp tlv neighbor list.
*/
adj->circuit_t = iih->circ_type;
isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL);
adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
}
if (tw_adj && adj->threeway_state == ISIS_THREEWAY_DOWN)
adj->ext_circuit_id = tw_adj->local_circuit_id;
/* 8.2.6 Monitoring point-to-point adjacencies */
adj->hold_time = iih->holdtime;
adj->last_upd = time(NULL);
bool changed;
isis_tlvs_to_adj(iih->tlvs, adj, &changed);
changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable,
adj);
/* Update MPLS TE Remote IP address parameter if possible */
if (IS_MPLS_TE(isisMplsTE) && iih->circuit->mtc
&& IS_CIRCUIT_TE(iih->circuit->mtc) && adj->ipv4_address_count)
set_circuitparams_rmt_ipaddr(iih->circuit->mtc,
adj->ipv4_addresses[0]);
/* lets take care of the expiry */
THREAD_TIMER_OFF(adj->t_expire);
thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
&adj->t_expire);
/* While fabricds initial sync is in progress, ignore hellos from other
* interfaces than the one we are performing the initial sync on. */
if (fabricd_initial_sync_is_in_progress(iih->circuit->area)
&& fabricd_initial_sync_circuit(iih->circuit->area) != iih->circuit)
return ISIS_OK;
/* 8.2.5.2 a) a match was detected */
if (isis_tlvs_area_addresses_match(iih->tlvs,
iih->circuit->area->area_addrs)) {
/* 8.2.5.2 a) 2) If the system is L1 - table 5 */
if (iih->circuit->area->is_type == IS_LEVEL_1) {
switch (iih->circ_type) {
case IS_LEVEL_1:
case IS_LEVEL_1_AND_2:
if (adj->adj_state != ISIS_ADJ_UP
|| adj->adj_usage == ISIS_ADJ_LEVEL1) {
isis_adj_process_threeway(adj, tw_adj,
ISIS_ADJ_LEVEL1);
}
break;
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP) {
/* (7) reject - wrong system type event
*/
zlog_warn("wrongSystemType");
return ISIS_WARNING;
} else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
/* (6) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
}
}
/* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
if (iih->circuit->area->is_type == IS_LEVEL_1_AND_2) {
switch (iih->circ_type) {
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP
|| adj->adj_usage == ISIS_ADJ_LEVEL1) {
isis_adj_process_threeway(adj, tw_adj,
ISIS_ADJ_LEVEL1);
} else if ((adj->adj_usage
== ISIS_ADJ_LEVEL1AND2)
|| (adj->adj_usage
== ISIS_ADJ_LEVEL2)) {
/* (8) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP
|| adj->adj_usage == ISIS_ADJ_LEVEL2) {
isis_adj_process_threeway(adj, tw_adj,
ISIS_ADJ_LEVEL2);
} else if ((adj->adj_usage == ISIS_ADJ_LEVEL1)
|| (adj->adj_usage
== ISIS_ADJ_LEVEL1AND2)) {
/* (8) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
if (adj->adj_state != ISIS_ADJ_UP
|| adj->adj_usage == ISIS_ADJ_LEVEL1AND2) {
isis_adj_process_threeway(adj, tw_adj,
ISIS_ADJ_LEVEL1AND2);
} else if ((adj->adj_usage == ISIS_ADJ_LEVEL1)
|| (adj->adj_usage
== ISIS_ADJ_LEVEL2)) {
/* (8) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
}
}
/* 8.2.5.2 a) 4) If the system is L2 - table 7 */
if (iih->circuit->area->is_type == IS_LEVEL_2) {
switch (iih->circ_type) {
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP) {
/* (5) reject - wrong system type event
*/
zlog_warn("wrongSystemType");
return ISIS_WARNING;
} else if ((adj->adj_usage
== ISIS_ADJ_LEVEL1AND2)
|| (adj->adj_usage
== ISIS_ADJ_LEVEL2)) {
/* (6) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP
|| adj->adj_usage == ISIS_ADJ_LEVEL2) {
isis_adj_process_threeway(adj, tw_adj,
ISIS_ADJ_LEVEL2);
} else if (adj->adj_usage
== ISIS_ADJ_LEVEL1AND2) {
/* (6) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
}
}
}
/* 8.2.5.2 b) if no match was detected */
else if (listcount(iih->circuit->area->area_addrs) > 0) {
if (iih->circuit->area->is_type == IS_LEVEL_1) {
/* 8.2.5.2 b) 1) is_type L1 and adj is not up */
if (adj->adj_state != ISIS_ADJ_UP) {
isis_adj_state_change(adj, ISIS_ADJ_DOWN,
"Area Mismatch");
/* 8.2.5.2 b) 2)is_type L1 and adj is up */
} else {
isis_adj_state_change(adj, ISIS_ADJ_DOWN,
"Down - Area Mismatch");
}
}
/* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
else {
switch (iih->circ_type) {
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP) {
/* (6) reject - Area Mismatch event */
zlog_warn("AreaMismatch");
return ISIS_WARNING;
} else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
/* (7) down - area mismatch */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Area Mismatch");
} else if ((adj->adj_usage
== ISIS_ADJ_LEVEL1AND2)
|| (adj->adj_usage
== ISIS_ADJ_LEVEL2)) {
/* (7) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP
|| adj->adj_usage == ISIS_ADJ_LEVEL2) {
isis_adj_process_threeway(adj, tw_adj,
ISIS_ADJ_LEVEL2);
} else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
/* (7) down - wrong system */
isis_adj_state_change(adj,
ISIS_ADJ_DOWN,
"Wrong System");
} else if (adj->adj_usage
== ISIS_ADJ_LEVEL1AND2) {
if (iih->circ_type == IS_LEVEL_2) {
/* (7) down - wrong system */
isis_adj_state_change(
adj, ISIS_ADJ_DOWN,
"Wrong System");
} else {
/* (7) down - area mismatch */
isis_adj_state_change(
adj, ISIS_ADJ_DOWN,
"Area Mismatch");
}
}
break;
}
}
} else {
/* down - area mismatch */
isis_adj_state_change(adj, ISIS_ADJ_DOWN, "Area Mismatch");
}
if (adj->adj_state == ISIS_ADJ_UP && changed) {
lsp_regenerate_schedule(adj->circuit->area,
isis_adj_usage2levels(adj->adj_usage),
0);
}
/* 8.2.5.2 c) if the action was up - comparing circuit IDs */
/* FIXME - Missing parts */
/* some of my own understanding of the ISO, why the heck does
* it not say what should I change the system_type to...
*/
switch (adj->adj_usage) {
case ISIS_ADJ_LEVEL1:
adj->sys_type = ISIS_SYSTYPE_L1_IS;
break;
case ISIS_ADJ_LEVEL2:
adj->sys_type = ISIS_SYSTYPE_L2_IS;
break;
case ISIS_ADJ_LEVEL1AND2:
adj->sys_type = ISIS_SYSTYPE_L2_IS;
break;
case ISIS_ADJ_NONE:
adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
break;
}
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug(
"ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
" cir id %hhu, length %" PRIu16,
iih->circuit->area->area_tag,
iih->circuit->interface->name,
circuit_t2string(iih->circuit->is_type),
iih->circuit->circuit_id, iih->pdu_len);
}
return ISIS_OK;
}
static int process_lan_hello(struct iih_info *iih)
{
struct isis_adjacency *adj;
adj = isis_adj_lookup(iih->sys_id,
iih->circuit->u.bc.adjdb[iih->level - 1]);
if ((adj == NULL) || (memcmp(adj->snpa, iih->ssnpa, ETH_ALEN))
|| (adj->level != iih->level)) {
if (!adj) {
/* Do as in 8.4.2.5 */
adj = isis_new_adj(iih->sys_id, iih->ssnpa, iih->level,
iih->circuit);
} else {
if (iih->ssnpa) {
memcpy(adj->snpa, iih->ssnpa, 6);
} else {
memset(adj->snpa, ' ', 6);
}
adj->level = iih->level;
}
isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL);
if (iih->level == IS_LEVEL_1)
adj->sys_type = ISIS_SYSTYPE_L1_IS;
else
adj->sys_type = ISIS_SYSTYPE_L2_IS;
list_delete_all_node(
iih->circuit->u.bc.lan_neighs[iih->level - 1]);
isis_adj_build_neigh_list(
iih->circuit->u.bc.adjdb[iih->level - 1],
iih->circuit->u.bc.lan_neighs[iih->level - 1]);
}
if (adj->dis_record[iih->level - 1].dis == ISIS_IS_DIS) {
uint8_t *dis = (iih->level == 1)
? iih->circuit->u.bc.l1_desig_is
: iih->circuit->u.bc.l2_desig_is;
if (memcmp(dis, iih->dis, ISIS_SYS_ID_LEN + 1)) {
thread_add_event(master, isis_event_dis_status_change,
iih->circuit, 0, NULL);
memcpy(dis, iih->dis, ISIS_SYS_ID_LEN + 1);
}
}
adj->circuit_t = iih->circ_type;
adj->hold_time = iih->holdtime;
adj->last_upd = time(NULL);
adj->prio[iih->level - 1] = iih->priority;
memcpy(adj->lanid, iih->dis, ISIS_SYS_ID_LEN + 1);
bool changed;
isis_tlvs_to_adj(iih->tlvs, adj, &changed);
changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable,
adj);
/* lets take care of the expiry */
THREAD_TIMER_OFF(adj->t_expire);
thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
&adj->t_expire);
/*
* If the snpa for this circuit is found from LAN Neighbours TLV
* we have two-way communication -> adjacency can be put to state "up"
*/
bool own_snpa_found =
isis_tlvs_own_snpa_found(iih->tlvs, iih->circuit->u.bc.snpa);
if (adj->adj_state != ISIS_ADJ_UP) {
if (own_snpa_found) {
isis_adj_state_change(
adj, ISIS_ADJ_UP,
"own SNPA found in LAN Neighbours TLV");
}
} else {
if (!own_snpa_found) {
isis_adj_state_change(
adj, ISIS_ADJ_INITIALIZING,
"own SNPA not found in LAN Neighbours TLV");
}
}
if (adj->adj_state == ISIS_ADJ_UP && changed)
lsp_regenerate_schedule(adj->circuit->area, iih->level, 0);
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug(
"ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
iih->circuit->area->area_tag, iih->level,
snpa_print(iih->ssnpa), iih->circuit->interface->name,
circuit_t2string(iih->circuit->is_type),
iih->circuit->circuit_id,
stream_get_endp(iih->circuit->rcv_stream));
}
return ISIS_OK;
}
static int pdu_len_validate(uint16_t pdu_len, struct isis_circuit *circuit)
{
if (pdu_len < stream_get_getp(circuit->rcv_stream)
|| pdu_len > ISO_MTU(circuit)
|| pdu_len > stream_get_endp(circuit->rcv_stream))
return 1;
if (pdu_len < stream_get_endp(circuit->rcv_stream))
stream_set_endp(circuit->rcv_stream, pdu_len);
return 0;
}
static int process_hello(uint8_t pdu_type, struct isis_circuit *circuit,
uint8_t *ssnpa)
{
/* keep a copy of the raw pdu for NB notifications */
size_t pdu_start = stream_get_getp(circuit->rcv_stream);
size_t pdu_end = stream_get_endp(circuit->rcv_stream);
char raw_pdu[pdu_end - pdu_start];
bool p2p_hello = (pdu_type == P2P_HELLO);
int level = p2p_hello ? 0
: (pdu_type == L1_LAN_HELLO) ? ISIS_LEVEL1
: ISIS_LEVEL2;
const char *pdu_name =
p2p_hello
? "P2P IIH"
: (level == ISIS_LEVEL1) ? "L1 LAN IIH" : "L2 LAN IIH";
stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
pdu_end - pdu_start);
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
circuit->area->area_tag, pdu_name,
circuit->interface->name,
circuit_t2string(circuit->is_type),
circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
stream_get_endp(circuit->rcv_stream));
}
if (p2p_hello) {
if (circuit->circ_type != CIRCUIT_T_P2P) {
zlog_warn("p2p hello on non p2p circuit");
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "p2p hello on non p2p circuit",
raw_pdu);
#endif /* ifndef FABRICD */
return ISIS_WARNING;
}
} else {
if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
zlog_warn("lan hello on non broadcast circuit");
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "lan hello on non broadcast circuit",
raw_pdu);
#endif /* ifndef FABRICD */
return ISIS_WARNING;
}
if (circuit->ext_domain) {
zlog_debug(
"level %d LAN Hello received over circuit with externalDomain = true",
level);
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit,
"LAN Hello received over circuit with externalDomain = true",
raw_pdu);
#endif /* ifndef FABRICD */
return ISIS_WARNING;
}
if (!(circuit->is_type & level)) {
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug(
"ISIS-Adj (%s): Interface level mismatch, %s",
circuit->area->area_tag,
circuit->interface->name);
}
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "Interface level mismatch", raw_pdu);
#endif /* ifndef FABRICD */
return ISIS_WARNING;
}
}
struct iih_info iih = {
.circuit = circuit, .ssnpa = ssnpa, .level = level};
/* Generic IIH Header */
iih.circ_type = stream_getc(circuit->rcv_stream) & 0x03;
stream_get(iih.sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
iih.holdtime = stream_getw(circuit->rcv_stream);
iih.pdu_len = stream_getw(circuit->rcv_stream);
if (p2p_hello) {
iih.circuit_id = stream_getc(circuit->rcv_stream);
} else {
iih.priority = stream_getc(circuit->rcv_stream);
stream_get(iih.dis, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
}
if (pdu_len_validate(iih.pdu_len, circuit)) {
zlog_warn(
"ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16,
circuit->area->area_tag, pdu_name,
circuit->interface->name, iih.pdu_len);
#ifndef FABRICD
isis_notif_reject_adjacency(circuit, "Invalid PDU length",
raw_pdu);
#endif /* ifndef FABRICD */
return ISIS_WARNING;
}
if (!p2p_hello && !(level & iih.circ_type)) {
flog_err(EC_ISIS_PACKET,
"Level %d LAN Hello with Circuit Type %d", level,
iih.circ_type);
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "LAN Hello with wrong IS-level", raw_pdu);
#endif /* ifndef FABRICD */
return ISIS_ERROR;
}
const char *error_log;
int retval = ISIS_WARNING;
if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
circuit->rcv_stream, &iih.tlvs, &error_log)) {
zlog_warn("isis_unpack_tlvs() failed: %s", error_log);
#ifndef FABRICD
isis_notif_reject_adjacency(circuit, "Failed to unpack TLVs",
raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
if (!iih.tlvs->area_addresses.count) {
zlog_warn("No Area addresses TLV in %s", pdu_name);
#ifndef FABRICD
/* send northbound notification */
isis_notif_area_mismatch(circuit, raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
if (!iih.tlvs->protocols_supported.count) {
zlog_warn("No supported protocols TLV in %s", pdu_name);
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "No supported protocols TLV", raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
int auth_code = isis_tlvs_auth_is_valid(iih.tlvs, &circuit->passwd,
circuit->rcv_stream, false);
if (auth_code != ISIS_AUTH_OK) {
isis_event_auth_failure(circuit->area->area_tag,
"IIH authentication failure",
iih.sys_id);
#ifndef FABRICD
/* send northbound notification */
stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
pdu_end - pdu_start);
if (auth_code == ISIS_AUTH_FAILURE)
isis_notif_authentication_failure(circuit, raw_pdu);
else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
isis_notif_authentication_type_failure(circuit,
raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
if (!memcmp(iih.sys_id, isis->sysid, ISIS_SYS_ID_LEN)) {
zlog_warn(
"ISIS-Adj (%s): Received IIH with own sysid - discard",
circuit->area->area_tag);
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "Received IIH with our own sysid", raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
if (!p2p_hello
&& (listcount(circuit->area->area_addrs) == 0
|| (level == ISIS_LEVEL1
&& !isis_tlvs_area_addresses_match(
iih.tlvs, circuit->area->area_addrs)))) {
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_debug(
"ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
circuit->area->area_tag, level,
circuit->interface->name);
}
#ifndef FABRICD
/* send northbound notification */
isis_notif_area_mismatch(circuit, raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
iih.v4_usable = (fabricd_ip_addrs(circuit)
&& iih.tlvs->ipv4_address.count);
iih.v6_usable = (circuit->ipv6_link && listcount(circuit->ipv6_link)
&& iih.tlvs->ipv6_address.count);
if (!iih.v4_usable && !iih.v6_usable) {
if (isis->debugs & DEBUG_ADJ_PACKETS) {
zlog_warn(
"ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
circuit->area->area_tag);
}
#ifndef FABRICD
isis_notif_reject_adjacency(
circuit, "Neither IPv4 not IPv6 considered usable",
raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
retval = p2p_hello ? process_p2p_hello(&iih) : process_lan_hello(&iih);
out:
isis_free_tlvs(iih.tlvs);
return retval;
}
static void lsp_flood_or_update(struct isis_lsp *lsp,
struct isis_circuit *circuit,
bool circuit_scoped)
{
if (!circuit_scoped)
lsp_flood(lsp, circuit);
else
fabricd_update_lsp_no_flood(lsp, circuit);
}
/*
* Process Level 1/2 Link State
* ISO - 10589
* Section 7.3.15.1 - Action on receipt of a link state PDU
*/
static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit,
const uint8_t *ssnpa, uint8_t max_area_addrs)
{
int level;
bool circuit_scoped;
size_t pdu_start = stream_get_getp(circuit->rcv_stream);
size_t pdu_end = stream_get_endp(circuit->rcv_stream);
char raw_pdu[pdu_end - pdu_start];
stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
pdu_end - pdu_start);
if (pdu_type == FS_LINK_STATE) {
if (!fabricd)
return ISIS_ERROR;
if (max_area_addrs != L2_CIRCUIT_FLOODING_SCOPE)
return ISIS_ERROR;
level = ISIS_LEVEL2;
circuit_scoped = true;
/* The stream is used verbatim for sending out new LSPDUs.
* So make sure we store it as an L2 LSPDU internally.
* (compare for the reverse in `send_lsp`) */
stream_putc_at(circuit->rcv_stream, 4, L2_LINK_STATE);
stream_putc_at(circuit->rcv_stream, 7, 0);
} else {
if (pdu_type == L1_LINK_STATE)
level = ISIS_LEVEL1;
else
level = ISIS_LEVEL2;
circuit_scoped = false;
}
if (isis->debugs & DEBUG_UPDATE_PACKETS) {
zlog_debug(
"ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
circuit->area->area_tag,
circuit_scoped ? "Circuit scoped " : "", level,
circuit->interface->name,
circuit_t2string(circuit->is_type),
circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
stream_get_endp(circuit->rcv_stream));
}
struct isis_lsp_hdr hdr = {};
hdr.pdu_len = stream_getw(circuit->rcv_stream);
hdr.rem_lifetime = stream_getw(circuit->rcv_stream);
stream_get(hdr.lsp_id, circuit->rcv_stream, sizeof(hdr.lsp_id));
hdr.seqno = stream_getl(circuit->rcv_stream);
hdr.checksum = stream_getw(circuit->rcv_stream);
hdr.lsp_bits = stream_getc(circuit->rcv_stream);
#ifndef FABRICD
/* send northbound notification */
isis_notif_lsp_received(circuit, rawlspid_print(hdr.lsp_id), hdr.seqno,
time(NULL), sysid_print(hdr.lsp_id));
#endif /* ifndef FABRICD */
if (pdu_len_validate(hdr.pdu_len, circuit)) {
zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16,
circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
hdr.pdu_len);
return ISIS_WARNING;
}
if (isis->debugs & DEBUG_UPDATE_PACKETS) {
zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
"s, len %" PRIu16 ", on %s",
circuit->area->area_tag, level,
rawlspid_print(hdr.lsp_id), hdr.seqno, hdr.checksum,
hdr.rem_lifetime, hdr.pdu_len,
circuit->interface->name);
}
/* lsp is_type check */
if ((hdr.lsp_bits & IS_LEVEL_1) != IS_LEVEL_1) {
zlog_debug(
"ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8,
circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
hdr.lsp_bits & IS_LEVEL_1_AND_2);
/* continue as per RFC1122 Be liberal in what you accept, and
* conservative in what you send */
}
/* Checksum sanity check - FIXME: move to correct place */
/* 12 = sysid+pdu+remtime */
if (iso_csum_verify(STREAM_DATA(circuit->rcv_stream) + 12,
hdr.pdu_len - 12, hdr.checksum, 12)) {
zlog_debug(
"ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16,
circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
hdr.checksum);
return ISIS_WARNING;
}
/* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
if (circuit->ext_domain) {
zlog_debug(
"ISIS-Upd (%s): LSP %s received at level %d over circuit with "
"externalDomain = true",
circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
level);
return ISIS_WARNING;
}
/* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
if (!(circuit->is_type & level)) {
zlog_debug(
"ISIS-Upd (%s): LSP %s received at level %d over circuit of"
" type %s",
circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
level, circuit_t2string(circuit->is_type));
return ISIS_WARNING;
}
struct isis_tlvs *tlvs = NULL;
int retval = ISIS_WARNING;
const char *error_log;
if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
circuit->rcv_stream, &tlvs, &error_log)) {
zlog_warn("Something went wrong unpacking the LSP: %s",
error_log);
#ifndef FABRICD
/* send northbound notification. Note that the tlv-type and
* offset cannot correctly be set here as they are not returned
* by isis_unpack_tlvs, but in there I cannot fire a
* notification because I have no circuit information. So until
* we change the code above to return those extra fields, we
* will send dummy values which are ignored in the callback
*/
isis_notif_lsp_error(circuit, rawlspid_print(hdr.lsp_id),
raw_pdu, 0, 0);
#endif /* ifndef FABRICD */
goto out;
}
/* 7.3.15.1 a) 4 - need to make sure IDLength matches */
/* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
* 3 */
/* 7.3.15.1 a) 7 - password check */
struct isis_passwd *passwd = (level == ISIS_LEVEL1)
? &circuit->area->area_passwd
: &circuit->area->domain_passwd;
int auth_code = isis_tlvs_auth_is_valid(tlvs, passwd,
circuit->rcv_stream, true);
if (auth_code != ISIS_AUTH_OK) {
isis_event_auth_failure(circuit->area->area_tag,
"LSP authentication failure",
hdr.lsp_id);
#ifndef FABRICD
/* send northbound notification */
if (auth_code == ISIS_AUTH_FAILURE)
isis_notif_authentication_failure(circuit, raw_pdu);
else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
isis_notif_authentication_type_failure(circuit,
raw_pdu);
#endif /* ifndef FABRICD */
goto out;
}
/* Find the LSP in our database and compare it to this Link State header
*/
struct isis_lsp *lsp =
lsp_search(hdr.lsp_id, circuit->area->lspdb[level - 1]);
int comp = 0;
if (lsp)
comp = lsp_compare(circuit->area->area_tag, lsp, hdr.seqno,
hdr.checksum, hdr.rem_lifetime);
if (lsp && (lsp->own_lsp))
goto dontcheckadj;
/* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
* level */
/* for broadcast circuits, snpa should be compared */
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
if (!isis_adj_lookup_snpa(ssnpa,
circuit->u.bc.adjdb[level - 1])) {
zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
"s on %s",
circuit->area->area_tag,
rawlspid_print(hdr.lsp_id), hdr.seqno,
hdr.checksum, hdr.rem_lifetime,
circuit->interface->name);
goto out; /* Silently discard */
}
}
/* for non broadcast, we just need to find same level adj */
else {
/* If no adj, or no sharing of level */
if (!circuit->u.p2p.neighbor) {
retval = ISIS_OK;
goto out;
} else {
if (((level == IS_LEVEL_1)
&& (circuit->u.p2p.neighbor->adj_usage
== ISIS_ADJ_LEVEL2))
|| ((level == IS_LEVEL_2)
&& (circuit->u.p2p.neighbor->adj_usage
== ISIS_ADJ_LEVEL1)))
goto out;