forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathisis_spf.c
2737 lines (2376 loc) · 71.6 KB
/
isis_spf.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_spf.c
* The SPT algorithm
*
* Copyright (C) 2001,2002 Sampo Saaristo
* Tampere University of Technology
* Institute of Communications Engineering
* Copyright (C) 2017 Christian Franke <chris@opensourcerouting.org>
*
* 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 "thread.h"
#include "linklist.h"
#include "vty.h"
#include "log.h"
#include "command.h"
#include "termtable.h"
#include "memory.h"
#include "prefix.h"
#include "filter.h"
#include "if.h"
#include "hash.h"
#include "table.h"
#include "spf_backoff.h"
#include "srcdest_table.h"
#include "vrf.h"
#include "isis_errors.h"
#include "isis_constants.h"
#include "isis_common.h"
#include "isis_flags.h"
#include "isisd.h"
#include "isis_misc.h"
#include "isis_adjacency.h"
#include "isis_circuit.h"
#include "isis_pdu.h"
#include "isis_lsp.h"
#include "isis_dynhn.h"
#include "isis_spf.h"
#include "isis_route.h"
#include "isis_csm.h"
#include "isis_mt.h"
#include "isis_tlvs.h"
#include "isis_zebra.h"
#include "fabricd.h"
#include "isis_spf_private.h"
DEFINE_MTYPE_STATIC(ISISD, ISIS_SPFTREE, "ISIS SPFtree");
DEFINE_MTYPE_STATIC(ISISD, ISIS_SPF_RUN, "ISIS SPF Run Info");
DEFINE_MTYPE_STATIC(ISISD, ISIS_SPF_ADJ, "ISIS SPF Adjacency");
DEFINE_MTYPE_STATIC(ISISD, ISIS_VERTEX, "ISIS vertex");
DEFINE_MTYPE_STATIC(ISISD, ISIS_VERTEX_ADJ, "ISIS SPF Vertex Adjacency");
static void spf_adj_list_parse_lsp(struct isis_spftree *spftree,
struct list *adj_list, struct isis_lsp *lsp,
const uint8_t *pseudo_nodeid,
uint32_t pseudo_metric);
/*
* supports the given af ?
*/
static bool speaks(uint8_t *protocols, uint8_t count, int family)
{
for (uint8_t i = 0; i < count; i++) {
if (family == AF_INET && protocols[i] == NLPID_IP)
return true;
if (family == AF_INET6 && protocols[i] == NLPID_IPV6)
return true;
}
return false;
}
struct isis_spf_run {
struct isis_area *area;
int level;
};
/* 7.2.7 */
static void remove_excess_adjs(struct list *adjs)
{
struct listnode *node, *excess = NULL;
struct isis_vertex_adj *vadj, *candidate = NULL;
int comp;
for (ALL_LIST_ELEMENTS_RO(adjs, node, vadj)) {
struct isis_adjacency *adj, *candidate_adj;
adj = vadj->sadj->adj;
assert(adj);
if (excess == NULL)
excess = node;
candidate = listgetdata(excess);
candidate_adj = candidate->sadj->adj;
if (candidate_adj->sys_type < adj->sys_type) {
excess = node;
continue;
}
if (candidate_adj->sys_type > adj->sys_type)
continue;
comp = memcmp(candidate_adj->sysid, adj->sysid,
ISIS_SYS_ID_LEN);
if (comp > 0) {
excess = node;
continue;
}
if (comp < 0)
continue;
if (candidate_adj->circuit->idx > adj->circuit->idx) {
excess = node;
continue;
}
if (candidate_adj->circuit->idx < adj->circuit->idx)
continue;
comp = memcmp(candidate_adj->snpa, adj->snpa, ETH_ALEN);
if (comp > 0) {
excess = node;
continue;
}
}
list_delete_node(adjs, excess);
return;
}
const char *vtype2string(enum vertextype vtype)
{
switch (vtype) {
case VTYPE_PSEUDO_IS:
return "pseudo_IS";
case VTYPE_PSEUDO_TE_IS:
return "pseudo_TE-IS";
case VTYPE_NONPSEUDO_IS:
return "IS";
case VTYPE_NONPSEUDO_TE_IS:
return "TE-IS";
case VTYPE_ES:
return "ES";
case VTYPE_IPREACH_INTERNAL:
return "IP internal";
case VTYPE_IPREACH_EXTERNAL:
return "IP external";
case VTYPE_IPREACH_TE:
return "IP TE";
case VTYPE_IP6REACH_INTERNAL:
return "IP6 internal";
case VTYPE_IP6REACH_EXTERNAL:
return "IP6 external";
default:
return "UNKNOWN";
}
return NULL; /* Not reached */
}
const char *vid2string(const struct isis_vertex *vertex, char *buff, int size)
{
if (VTYPE_IS(vertex->type) || VTYPE_ES(vertex->type)) {
const char *hostname = print_sys_hostname(vertex->N.id);
strlcpy(buff, hostname, size);
return buff;
}
if (VTYPE_IP(vertex->type)) {
srcdest2str(&vertex->N.ip.p.dest, &vertex->N.ip.p.src, buff,
size);
return buff;
}
return "UNKNOWN";
}
static bool prefix_sid_cmp(const void *value1, const void *value2)
{
const struct isis_vertex *c1 = value1;
const struct isis_vertex *c2 = value2;
if (CHECK_FLAG(c1->N.ip.sr.sid.flags,
ISIS_PREFIX_SID_VALUE | ISIS_PREFIX_SID_LOCAL)
!= CHECK_FLAG(c2->N.ip.sr.sid.flags,
ISIS_PREFIX_SID_VALUE | ISIS_PREFIX_SID_LOCAL))
return false;
return c1->N.ip.sr.sid.value == c2->N.ip.sr.sid.value;
}
static unsigned int prefix_sid_key_make(const void *value)
{
const struct isis_vertex *vertex = value;
return jhash_1word(vertex->N.ip.sr.sid.value, 0);
}
struct isis_vertex *isis_spf_prefix_sid_lookup(struct isis_spftree *spftree,
struct isis_prefix_sid *psid)
{
struct isis_vertex lookup = {};
lookup.N.ip.sr.sid = *psid;
return hash_lookup(spftree->prefix_sids, &lookup);
}
void isis_vertex_adj_free(void *arg)
{
struct isis_vertex_adj *vadj = arg;
XFREE(MTYPE_ISIS_VERTEX_ADJ, vadj);
}
static struct isis_vertex *isis_vertex_new(struct isis_spftree *spftree,
void *id,
enum vertextype vtype)
{
struct isis_vertex *vertex;
vertex = XCALLOC(MTYPE_ISIS_VERTEX, sizeof(struct isis_vertex));
isis_vertex_id_init(vertex, id, vtype);
vertex->Adj_N = list_new();
vertex->Adj_N->del = isis_vertex_adj_free;
vertex->parents = list_new();
if (CHECK_FLAG(spftree->flags, F_SPFTREE_HOPCOUNT_METRIC)) {
vertex->firsthops = hash_create(isis_vertex_queue_hash_key,
isis_vertex_queue_hash_cmp,
NULL);
}
return vertex;
}
void isis_vertex_del(struct isis_vertex *vertex)
{
list_delete(&vertex->Adj_N);
list_delete(&vertex->parents);
if (vertex->firsthops) {
hash_clean(vertex->firsthops, NULL);
hash_free(vertex->firsthops);
vertex->firsthops = NULL;
}
memset(vertex, 0, sizeof(struct isis_vertex));
XFREE(MTYPE_ISIS_VERTEX, vertex);
}
struct isis_vertex_adj *
isis_vertex_adj_add(struct isis_spftree *spftree, struct isis_vertex *vertex,
struct list *vadj_list, struct isis_spf_adj *sadj,
struct isis_prefix_sid *psid, bool last_hop)
{
struct isis_vertex_adj *vadj;
vadj = XCALLOC(MTYPE_ISIS_VERTEX_ADJ, sizeof(*vadj));
vadj->sadj = sadj;
if (spftree->area->srdb.enabled && psid) {
if (vertex->N.ip.sr.present
&& vertex->N.ip.sr.sid.value != psid->value)
zlog_warn(
"ISIS-SPF: ignoring different Prefix-SID for route %pFX",
&vertex->N.ip.p.dest);
else {
vadj->sr.sid = *psid;
vadj->sr.label = sr_prefix_out_label(
spftree->lspdb, vertex->N.ip.p.dest.family,
psid, sadj->id, last_hop);
if (vadj->sr.label != MPLS_INVALID_LABEL)
vadj->sr.present = true;
}
}
listnode_add(vadj_list, vadj);
return vadj;
}
static void isis_vertex_adj_del(struct isis_vertex *vertex,
struct isis_adjacency *adj)
{
struct isis_vertex_adj *vadj;
struct listnode *node, *nextnode;
if (!vertex)
return;
for (ALL_LIST_ELEMENTS(vertex->Adj_N, node, nextnode, vadj)) {
if (vadj->sadj->adj == adj) {
listnode_delete(vertex->Adj_N, vadj);
isis_vertex_adj_free(vadj);
}
}
return;
}
bool isis_vertex_adj_exists(const struct isis_spftree *spftree,
const struct isis_vertex *vertex,
const struct isis_spf_adj *sadj)
{
struct isis_vertex_adj *tmp;
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO(vertex->Adj_N, node, tmp)) {
if (CHECK_FLAG(spftree->flags, F_SPFTREE_NO_ADJACENCIES)) {
if (memcmp(sadj->id, tmp->sadj->id, sizeof(sadj->id))
== 0)
return true;
} else {
if (sadj->adj == tmp->sadj->adj)
return true;
}
}
return false;
}
static void isis_spf_adj_free(void *arg)
{
struct isis_spf_adj *sadj = arg;
XFREE(MTYPE_ISIS_SPF_ADJ, sadj);
}
struct isis_spftree *isis_spftree_new(struct isis_area *area,
struct lspdb_head *lspdb,
const uint8_t *sysid, int level,
enum spf_tree_id tree_id,
enum spf_type type, uint8_t flags)
{
struct isis_spftree *tree;
tree = XCALLOC(MTYPE_ISIS_SPFTREE, sizeof(struct isis_spftree));
isis_vertex_queue_init(&tree->tents, "IS-IS SPF tents", true);
isis_vertex_queue_init(&tree->paths, "IS-IS SPF paths", false);
tree->route_table = srcdest_table_init();
tree->route_table->cleanup = isis_route_node_cleanup;
tree->route_table_backup = srcdest_table_init();
tree->route_table_backup->cleanup = isis_route_node_cleanup;
tree->area = area;
tree->lspdb = lspdb;
tree->prefix_sids = hash_create(prefix_sid_key_make, prefix_sid_cmp,
"SR Prefix-SID Entries");
tree->sadj_list = list_new();
tree->sadj_list->del = isis_spf_adj_free;
tree->last_run_timestamp = 0;
tree->last_run_monotime = 0;
tree->last_run_duration = 0;
tree->runcount = 0;
tree->type = type;
memcpy(tree->sysid, sysid, ISIS_SYS_ID_LEN);
tree->level = level;
tree->tree_id = tree_id;
tree->family = (tree->tree_id == SPFTREE_IPV4) ? AF_INET : AF_INET6;
tree->flags = flags;
isis_rlfa_list_init(tree);
tree->lfa.remote.pc_spftrees = list_new();
tree->lfa.remote.pc_spftrees->del = (void (*)(void *))isis_spftree_del;
if (tree->type == SPF_TYPE_RLFA || tree->type == SPF_TYPE_TI_LFA) {
isis_spf_node_list_init(&tree->lfa.p_space);
isis_spf_node_list_init(&tree->lfa.q_space);
}
return tree;
}
void isis_spftree_del(struct isis_spftree *spftree)
{
hash_clean(spftree->prefix_sids, NULL);
hash_free(spftree->prefix_sids);
isis_zebra_rlfa_unregister_all(spftree);
isis_rlfa_list_clear(spftree);
list_delete(&spftree->lfa.remote.pc_spftrees);
if (spftree->type == SPF_TYPE_RLFA
|| spftree->type == SPF_TYPE_TI_LFA) {
isis_spf_node_list_clear(&spftree->lfa.q_space);
isis_spf_node_list_clear(&spftree->lfa.p_space);
}
isis_spf_node_list_clear(&spftree->adj_nodes);
list_delete(&spftree->sadj_list);
isis_vertex_queue_free(&spftree->tents);
isis_vertex_queue_free(&spftree->paths);
route_table_finish(spftree->route_table);
route_table_finish(spftree->route_table_backup);
spftree->route_table = NULL;
XFREE(MTYPE_ISIS_SPFTREE, spftree);
return;
}
static void isis_spftree_adj_del(struct isis_spftree *spftree,
struct isis_adjacency *adj)
{
struct listnode *node;
struct isis_vertex *v;
if (!adj)
return;
assert(!isis_vertex_queue_count(&spftree->tents));
for (ALL_QUEUE_ELEMENTS_RO(&spftree->paths, node, v))
isis_vertex_adj_del(v, adj);
return;
}
void spftree_area_init(struct isis_area *area)
{
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
if (!(area->is_type & level))
continue;
if (area->spftree[tree][level - 1])
continue;
area->spftree[tree][level - 1] =
isis_spftree_new(area, &area->lspdb[level - 1],
area->isis->sysid, level, tree,
SPF_TYPE_FORWARD, 0);
}
}
}
void spftree_area_del(struct isis_area *area)
{
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
if (!(area->is_type & level))
continue;
if (!area->spftree[tree][level - 1])
continue;
isis_spftree_del(area->spftree[tree][level - 1]);
}
}
}
static int spf_adj_state_change(struct isis_adjacency *adj)
{
struct isis_area *area = adj->circuit->area;
if (adj->adj_state == ISIS_ADJ_UP)
return 0;
/* Remove adjacency from all SPF trees. */
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
if (!(area->is_type & level))
continue;
if (!area->spftree[tree][level - 1])
continue;
isis_spftree_adj_del(area->spftree[tree][level - 1],
adj);
}
}
if (fabricd_spftree(area) != NULL)
isis_spftree_adj_del(fabricd_spftree(area), adj);
return 0;
}
/*
* Find the system LSP: returns the LSP in our LSP database
* associated with the given system ID.
*/
struct isis_lsp *isis_root_system_lsp(struct lspdb_head *lspdb,
const uint8_t *sysid)
{
struct isis_lsp *lsp;
uint8_t lspid[ISIS_SYS_ID_LEN + 2];
memcpy(lspid, sysid, ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(lspid) = 0;
LSP_FRAGMENT(lspid) = 0;
lsp = lsp_search(lspdb, lspid);
if (lsp && lsp->hdr.rem_lifetime != 0)
return lsp;
return NULL;
}
/*
* Add this IS to the root of SPT
*/
static struct isis_vertex *isis_spf_add_root(struct isis_spftree *spftree)
{
struct isis_vertex *vertex;
#ifdef EXTREME_DEBUG
char buff[VID2STR_BUFFER];
#endif /* EXTREME_DEBUG */
vertex = isis_vertex_new(spftree, spftree->sysid,
spftree->area->oldmetric
? VTYPE_NONPSEUDO_IS
: VTYPE_NONPSEUDO_TE_IS);
isis_vertex_queue_append(&spftree->paths, vertex);
#ifdef EXTREME_DEBUG
if (IS_DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-SPF: added this IS %s %s depth %d dist %d to PATHS",
vtype2string(vertex->type),
vid2string(vertex, buff, sizeof(buff)), vertex->depth,
vertex->d_N);
#endif /* EXTREME_DEBUG */
return vertex;
}
static void vertex_add_parent_firsthop(struct hash_bucket *bucket, void *arg)
{
struct isis_vertex *vertex = arg;
struct isis_vertex *hop = bucket->data;
(void)hash_get(vertex->firsthops, hop, hash_alloc_intern);
}
static void vertex_update_firsthops(struct isis_vertex *vertex,
struct isis_vertex *parent)
{
if (vertex->d_N <= 2)
(void)hash_get(vertex->firsthops, vertex, hash_alloc_intern);
if (vertex->d_N < 2 || !parent)
return;
hash_iterate(parent->firsthops, vertex_add_parent_firsthop, vertex);
}
/*
* Add a vertex to TENT sorted by cost and by vertextype on tie break situation
*/
static struct isis_vertex *
isis_spf_add2tent(struct isis_spftree *spftree, enum vertextype vtype, void *id,
uint32_t cost, int depth, struct isis_spf_adj *sadj,
struct isis_prefix_sid *psid, struct isis_vertex *parent)
{
struct isis_vertex *vertex;
struct listnode *node;
bool last_hop;
char buff[VID2STR_BUFFER];
vertex = isis_find_vertex(&spftree->paths, id, vtype);
if (vertex != NULL) {
zlog_err(
"%s: vertex %s of type %s already in PATH; check for sysId collisions with established neighbors",
__func__, vid2string(vertex, buff, sizeof(buff)),
vtype2string(vertex->type));
return NULL;
}
vertex = isis_find_vertex(&spftree->tents, id, vtype);
if (vertex != NULL) {
zlog_err(
"%s: vertex %s of type %s already in TENT; check for sysId collisions with established neighbors",
__func__, vid2string(vertex, buff, sizeof(buff)),
vtype2string(vertex->type));
return NULL;
}
vertex = isis_vertex_new(spftree, id, vtype);
vertex->d_N = cost;
vertex->depth = depth;
if (VTYPE_IP(vtype) && spftree->area->srdb.enabled && psid) {
struct isis_area *area = spftree->area;
struct isis_vertex *vertex_psid;
/*
* Check if the Prefix-SID is already in use by another prefix.
*/
vertex_psid = isis_spf_prefix_sid_lookup(spftree, psid);
if (vertex_psid
&& !prefix_same(&vertex_psid->N.ip.p.dest,
&vertex->N.ip.p.dest)) {
flog_warn(
EC_ISIS_SID_COLLISION,
"ISIS-Sr (%s): collision detected, prefixes %pFX and %pFX share the same SID %s (%u)",
area->area_tag, &vertex->N.ip.p.dest,
&vertex_psid->N.ip.p.dest,
CHECK_FLAG(psid->flags, ISIS_PREFIX_SID_VALUE)
? "label"
: "index",
psid->value);
psid = NULL;
} else {
bool local;
local = (vertex->depth == 1);
vertex->N.ip.sr.sid = *psid;
vertex->N.ip.sr.label =
sr_prefix_in_label(area, psid, local);
if (vertex->N.ip.sr.label != MPLS_INVALID_LABEL)
vertex->N.ip.sr.present = true;
(void)hash_get(spftree->prefix_sids, vertex,
hash_alloc_intern);
}
}
if (parent) {
listnode_add(vertex->parents, parent);
}
if (CHECK_FLAG(spftree->flags, F_SPFTREE_HOPCOUNT_METRIC))
vertex_update_firsthops(vertex, parent);
last_hop = (vertex->depth == 2);
if (parent && parent->Adj_N && listcount(parent->Adj_N) > 0) {
struct isis_vertex_adj *parent_vadj;
for (ALL_LIST_ELEMENTS_RO(parent->Adj_N, node, parent_vadj))
isis_vertex_adj_add(spftree, vertex, vertex->Adj_N,
parent_vadj->sadj, psid, last_hop);
} else if (sadj) {
isis_vertex_adj_add(spftree, vertex, vertex->Adj_N, sadj, psid,
last_hop);
}
#ifdef EXTREME_DEBUG
if (IS_DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-SPF: add to TENT %s %s %s depth %d dist %d adjcount %d",
print_sys_hostname(vertex->N.id),
vtype2string(vertex->type),
vid2string(vertex, buff, sizeof(buff)), vertex->depth,
vertex->d_N, listcount(vertex->Adj_N));
#endif /* EXTREME_DEBUG */
isis_vertex_queue_insert(&spftree->tents, vertex);
return vertex;
}
static void isis_spf_add_local(struct isis_spftree *spftree,
enum vertextype vtype, void *id,
struct isis_spf_adj *sadj, uint32_t cost,
struct isis_prefix_sid *psid,
struct isis_vertex *parent)
{
struct isis_vertex *vertex;
vertex = isis_find_vertex(&spftree->tents, id, vtype);
if (vertex) {
/* C.2.5 c) */
if (vertex->d_N == cost) {
if (sadj) {
bool last_hop = (vertex->depth == 2);
isis_vertex_adj_add(spftree, vertex,
vertex->Adj_N, sadj, psid,
last_hop);
}
/* d) */
if (!CHECK_FLAG(spftree->flags,
F_SPFTREE_NO_ADJACENCIES)
&& listcount(vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
remove_excess_adjs(vertex->Adj_N);
if (parent && (listnode_lookup(vertex->parents, parent)
== NULL))
listnode_add(vertex->parents, parent);
return;
} else if (vertex->d_N < cost) {
/* e) do nothing */
return;
} else { /* vertex->d_N > cost */
/* f) */
isis_vertex_queue_delete(&spftree->tents, vertex);
isis_vertex_del(vertex);
}
}
isis_spf_add2tent(spftree, vtype, id, cost, 1, sadj, psid, parent);
return;
}
static void process_N(struct isis_spftree *spftree, enum vertextype vtype,
void *id, uint32_t dist, uint16_t depth,
struct isis_prefix_sid *psid, struct isis_vertex *parent)
{
struct isis_vertex *vertex;
#ifdef EXTREME_DEBUG
char buff[VID2STR_BUFFER];
#endif
assert(spftree && parent);
if (CHECK_FLAG(spftree->flags, F_SPFTREE_HOPCOUNT_METRIC)
&& !VTYPE_IS(vtype))
return;
struct prefix_pair p;
if (vtype >= VTYPE_IPREACH_INTERNAL) {
memcpy(&p, id, sizeof(p));
apply_mask(&p.dest);
apply_mask(&p.src);
id = &p;
}
/* RFC3787 section 5.1 */
if (spftree->area->newmetric == 1) {
if (dist > MAX_WIDE_PATH_METRIC)
return;
}
/* C.2.6 b) */
else if (spftree->area->oldmetric == 1) {
if (dist > MAX_NARROW_PATH_METRIC)
return;
}
/* c) */
vertex = isis_find_vertex(&spftree->paths, id, vtype);
if (vertex) {
#ifdef EXTREME_DEBUG
if (IS_DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-SPF: process_N %s %s %s dist %d already found from PATH",
print_sys_hostname(vertex->N.id),
vtype2string(vtype),
vid2string(vertex, buff, sizeof(buff)), dist);
#endif /* EXTREME_DEBUG */
assert(dist >= vertex->d_N);
return;
}
vertex = isis_find_vertex(&spftree->tents, id, vtype);
/* d) */
if (vertex) {
/* 1) */
#ifdef EXTREME_DEBUG
if (IS_DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-SPF: process_N %s %s %s dist %d parent %s adjcount %d",
print_sys_hostname(vertex->N.id),
vtype2string(vtype),
vid2string(vertex, buff, sizeof(buff)), dist,
(parent ? print_sys_hostname(parent->N.id)
: "null"),
(parent ? listcount(parent->Adj_N) : 0));
#endif /* EXTREME_DEBUG */
if (vertex->d_N == dist) {
struct listnode *node;
struct isis_vertex_adj *parent_vadj;
for (ALL_LIST_ELEMENTS_RO(parent->Adj_N, node,
parent_vadj))
if (!isis_vertex_adj_exists(
spftree, vertex,
parent_vadj->sadj)) {
bool last_hop = (vertex->depth == 2);
isis_vertex_adj_add(spftree, vertex,
vertex->Adj_N,
parent_vadj->sadj,
psid, last_hop);
}
if (CHECK_FLAG(spftree->flags,
F_SPFTREE_HOPCOUNT_METRIC))
vertex_update_firsthops(vertex, parent);
/* 2) */
if (!CHECK_FLAG(spftree->flags,
F_SPFTREE_NO_ADJACENCIES)
&& listcount(vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
remove_excess_adjs(vertex->Adj_N);
if (listnode_lookup(vertex->parents, parent) == NULL)
listnode_add(vertex->parents, parent);
return;
} else if (vertex->d_N < dist) {
return;
/* 4) */
} else {
isis_vertex_queue_delete(&spftree->tents, vertex);
isis_vertex_del(vertex);
}
}
#ifdef EXTREME_DEBUG
if (IS_DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-SPF: process_N add2tent %s %s dist %d parent %s",
print_sys_hostname(id), vtype2string(vtype), dist,
(parent ? print_sys_hostname(parent->N.id) : "null"));
#endif /* EXTREME_DEBUG */
isis_spf_add2tent(spftree, vtype, id, dist, depth, NULL, psid, parent);
return;
}
/*
* C.2.6 Step 1
*/
static int isis_spf_process_lsp(struct isis_spftree *spftree,
struct isis_lsp *lsp, uint32_t cost,
uint16_t depth, uint8_t *root_sysid,
struct isis_vertex *parent)
{
bool pseudo_lsp = LSP_PSEUDO_ID(lsp->hdr.lsp_id);
struct listnode *fragnode = NULL;
uint32_t dist;
enum vertextype vtype;
static const uint8_t null_sysid[ISIS_SYS_ID_LEN];
struct isis_mt_router_info *mt_router_info = NULL;
struct prefix_pair ip_info;
bool has_valid_psid;
if (isis_lfa_excise_node_check(spftree, lsp->hdr.lsp_id)) {
if (IS_DEBUG_LFA)
zlog_debug("ISIS-LFA: excising node %s",
print_sys_hostname(lsp->hdr.lsp_id));
return ISIS_OK;
}
if (!lsp->tlvs)
return ISIS_OK;
if (spftree->mtid != ISIS_MT_IPV4_UNICAST)
mt_router_info = isis_tlvs_lookup_mt_router_info(lsp->tlvs,
spftree->mtid);
if (!pseudo_lsp && (spftree->mtid == ISIS_MT_IPV4_UNICAST
&& !speaks(lsp->tlvs->protocols_supported.protocols,
lsp->tlvs->protocols_supported.count,
spftree->family))
&& !mt_router_info)
return ISIS_OK;
/* RFC3787 section 4 SHOULD ignore overload bit in pseudo LSPs */
bool no_overload = (pseudo_lsp
|| (spftree->mtid == ISIS_MT_IPV4_UNICAST
&& !ISIS_MASK_LSP_OL_BIT(lsp->hdr.lsp_bits))
|| (mt_router_info && !mt_router_info->overload));
lspfragloop:
if (lsp->hdr.seqno == 0) {
zlog_warn("%s: lsp with 0 seq_num - ignore", __func__);
return ISIS_WARNING;
}
#ifdef EXTREME_DEBUG
if (IS_DEBUG_SPF_EVENTS)
zlog_debug("ISIS-SPF: process_lsp %s",
print_sys_hostname(lsp->hdr.lsp_id));
#endif /* EXTREME_DEBUG */
if (no_overload) {
if ((pseudo_lsp || spftree->mtid == ISIS_MT_IPV4_UNICAST)
&& spftree->area->oldmetric) {
struct isis_oldstyle_reach *r;
for (r = (struct isis_oldstyle_reach *)
lsp->tlvs->oldstyle_reach.head;
r; r = r->next) {
if (fabricd)
continue;
/* C.2.6 a) */
/* Two way connectivity */
if (!LSP_PSEUDO_ID(r->id)
&& !memcmp(r->id, root_sysid,
ISIS_SYS_ID_LEN))
continue;
if (!pseudo_lsp
&& !memcmp(r->id, null_sysid,
ISIS_SYS_ID_LEN))
continue;
dist = cost + r->metric;
process_N(spftree,
LSP_PSEUDO_ID(r->id)
? VTYPE_PSEUDO_IS
: VTYPE_NONPSEUDO_IS,
(void *)r->id, dist, depth + 1, NULL,
parent);
}
}
if (spftree->area->newmetric) {
struct isis_item_list *te_neighs = NULL;
if (pseudo_lsp || spftree->mtid == ISIS_MT_IPV4_UNICAST)
te_neighs = &lsp->tlvs->extended_reach;
else
te_neighs = isis_lookup_mt_items(
&lsp->tlvs->mt_reach, spftree->mtid);
struct isis_extended_reach *er;
for (er = te_neighs ? (struct isis_extended_reach *)
te_neighs->head
: NULL;
er; er = er->next) {
/* C.2.6 a) */
/* Two way connectivity */
if (!LSP_PSEUDO_ID(er->id)
&& !memcmp(er->id, root_sysid,
ISIS_SYS_ID_LEN))
continue;
if (!pseudo_lsp
&& !memcmp(er->id, null_sysid,
ISIS_SYS_ID_LEN))
continue;
dist = cost
+ (CHECK_FLAG(spftree->flags,
F_SPFTREE_HOPCOUNT_METRIC)
? 1
: er->metric);
process_N(spftree,
LSP_PSEUDO_ID(er->id)
? VTYPE_PSEUDO_TE_IS
: VTYPE_NONPSEUDO_TE_IS,
(void *)er->id, dist, depth + 1, NULL,
parent);
}
}
}
if (!fabricd && !pseudo_lsp && spftree->family == AF_INET
&& spftree->mtid == ISIS_MT_IPV4_UNICAST
&& spftree->area->oldmetric) {
struct isis_item_list *reachs[] = {
&lsp->tlvs->oldstyle_ip_reach,
&lsp->tlvs->oldstyle_ip_reach_ext};
for (unsigned int i = 0; i < array_size(reachs); i++) {
vtype = i ? VTYPE_IPREACH_EXTERNAL
: VTYPE_IPREACH_INTERNAL;
memset(&ip_info, 0, sizeof(ip_info));
ip_info.dest.family = AF_INET;
struct isis_oldstyle_ip_reach *r;
for (r = (struct isis_oldstyle_ip_reach *)reachs[i]
->head;
r; r = r->next) {
dist = cost + r->metric;
ip_info.dest.u.prefix4 = r->prefix.prefix;
ip_info.dest.prefixlen = r->prefix.prefixlen;
process_N(spftree, vtype, &ip_info,
dist, depth + 1, NULL, parent);
}
}
}
/* we can skip all the rest if we're using metric style narrow */
if (!spftree->area->newmetric)
goto end;
if (!pseudo_lsp && spftree->family == AF_INET) {
struct isis_item_list *ipv4_reachs;
if (spftree->mtid == ISIS_MT_IPV4_UNICAST)
ipv4_reachs = &lsp->tlvs->extended_ip_reach;
else
ipv4_reachs = isis_lookup_mt_items(
&lsp->tlvs->mt_ip_reach, spftree->mtid);
memset(&ip_info, 0, sizeof(ip_info));
ip_info.dest.family = AF_INET;
struct isis_extended_ip_reach *r;
for (r = ipv4_reachs
? (struct isis_extended_ip_reach *)
ipv4_reachs->head
: NULL;
r; r = r->next) {
dist = cost + r->metric;
ip_info.dest.u.prefix4 = r->prefix.prefix;
ip_info.dest.prefixlen = r->prefix.prefixlen;
/* Parse list of Prefix-SID subTLVs if SR is enabled */
has_valid_psid = false;
if (spftree->area->srdb.enabled && r->subtlvs) {
for (struct isis_item *i =
r->subtlvs->prefix_sids.head;
i; i = i->next) {
struct isis_prefix_sid *psid =
(struct isis_prefix_sid *)i;
if (psid->algorithm != SR_ALGORITHM_SPF)
continue;
has_valid_psid = true;
process_N(spftree, VTYPE_IPREACH_TE,
&ip_info, dist, depth + 1,
psid, parent);
/*
* Stop the Prefix-SID iteration since
* we only support the SPF algorithm for
* now.
*/
break;
}
}