forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisis_te.c
2147 lines (1890 loc) · 58.2 KB
/
isis_te.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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* IS-IS Rout(e)ing protocol - isis_te.c
*
* This is an implementation of RFC5305 & RFC 7810
*
* Author: Olivier Dugeon <olivier.dugeon@orange.com>
*
* Copyright (C) 2014 - 2019 Orange Labs http://www.orange.com
*/
#include <zebra.h>
#include <math.h>
#include "linklist.h"
#include "frrevent.h"
#include "vty.h"
#include "stream.h"
#include "memory.h"
#include "log.h"
#include "prefix.h"
#include "command.h"
#include "hash.h"
#include "if.h"
#include "vrf.h"
#include "checksum.h"
#include "md5.h"
#include "sockunion.h"
#include "network.h"
#include "sbuf.h"
#include "link_state.h"
#include "lib/json.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_flags.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isisd.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/isis_dynhn.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_spf.h"
#include "isisd/isis_tlvs.h"
#include "isisd/isis_mt.h"
#include "isisd/isis_te.h"
#include "isisd/isis_zebra.h"
DEFINE_MTYPE_STATIC(ISISD, ISIS_MPLS_TE, "ISIS MPLS_TE parameters");
static void isis_mpls_te_circuit_ip_update(struct isis_circuit *circuit);
/*------------------------------------------------------------------------*
* Following are control functions for MPLS-TE parameters management.
*------------------------------------------------------------------------*/
/**
* Create MPLS Traffic Engineering structure which belongs to given area.
*
* @param area IS-IS Area
*/
void isis_mpls_te_create(struct isis_area *area)
{
struct listnode *node;
struct isis_circuit *circuit;
if (!area)
return;
if (area->mta == NULL) {
struct mpls_te_area *new;
zlog_debug("ISIS-TE(%s): Initialize MPLS Traffic Engineering",
area->area_tag);
new = XCALLOC(MTYPE_ISIS_MPLS_TE, sizeof(struct mpls_te_area));
/* Initialize MPLS_TE structure */
new->status = enable;
new->level = 0;
new->inter_as = off;
new->interas_areaid.s_addr = 0;
new->router_id.s_addr = 0;
new->ted = ls_ted_new(1, "ISIS", 0);
if (!new->ted)
zlog_warn("Unable to create Link State Data Base");
area->mta = new;
} else {
area->mta->status = enable;
}
/* Initialize Link State Database */
if (area->mta->ted)
isis_te_init_ted(area);
/* Update Extended TLVs according to Interface link parameters
* and neighbor IP addresses
*/
for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
isis_link_params_update(circuit, circuit->interface);
isis_mpls_te_circuit_ip_update(circuit);
}
}
/**
* Disable MPLS Traffic Engineering structure which belongs to given area.
*
* @param area IS-IS Area
*/
void isis_mpls_te_disable(struct isis_area *area)
{
struct listnode *node;
struct isis_circuit *circuit;
if (!area->mta)
return;
area->mta->status = disable;
/* Remove Link State Database */
ls_ted_clean(area->mta->ted);
/* Disable Extended SubTLVs on all circuit */
for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
if (!IS_EXT_TE(circuit->ext))
continue;
/* disable MPLS_TE Circuit keeping SR one's */
if (IS_SUBTLV(circuit->ext, EXT_ADJ_SID))
circuit->ext->status = EXT_ADJ_SID;
else if (IS_SUBTLV(circuit->ext, EXT_LAN_ADJ_SID))
circuit->ext->status = EXT_LAN_ADJ_SID;
else
circuit->ext->status = 0;
}
}
void isis_mpls_te_term(struct isis_area *area)
{
struct listnode *node;
struct isis_circuit *circuit;
if (!area->mta)
return;
zlog_info("TE(%s): Terminate MPLS TE", __func__);
/* Remove Link State Database */
ls_ted_del_all(&area->mta->ted);
/* Remove Extended SubTLVs */
zlog_info(" |- Remove Extended SubTLVS for all circuit");
for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
zlog_info(" |- Call isis_del_ext_subtlvs()");
isis_del_ext_subtlvs(circuit->ext);
circuit->ext = NULL;
}
zlog_info(" |- Free MTA structure at %p", area->mta);
XFREE(MTYPE_ISIS_MPLS_TE, area->mta);
}
static void isis_link_params_update_asla(struct isis_circuit *circuit,
struct interface *ifp)
{
struct isis_asla_subtlvs *asla;
struct listnode *node, *nnode;
struct isis_ext_subtlvs *ext = circuit->ext;
int i;
if (!HAS_LINK_PARAMS(ifp)) {
list_delete_all_node(ext->aslas);
return;
}
#ifndef FABRICD
/* RFC 8919 Application Specific Link-Attributes
* is required by flex-algo application ISIS_SABM_FLAG_X
*/
if (list_isempty(circuit->area->flex_algos->flex_algos))
isis_tlvs_free_asla(ext, ISIS_SABM_FLAG_X);
else
isis_tlvs_find_alloc_asla(ext, ISIS_SABM_FLAG_X);
#endif /* ifndef FABRICD */
if (list_isempty(ext->aslas))
return;
for (ALL_LIST_ELEMENTS(ext->aslas, node, nnode, asla)) {
asla->legacy = circuit->area->asla_legacy_flag;
RESET_SUBTLV(asla);
if (asla->legacy)
continue;
/* Fulfill ASLA subTLVs from interface link parameters */
if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP)) {
asla->admin_group = ifp->link_params->admin_grp;
SET_SUBTLV(asla, EXT_ADM_GRP);
} else
UNSET_SUBTLV(asla, EXT_ADM_GRP);
if (IS_PARAM_SET(ifp->link_params, LP_EXTEND_ADM_GRP)) {
admin_group_copy(&asla->ext_admin_group,
&ifp->link_params->ext_admin_grp);
SET_SUBTLV(asla, EXT_EXTEND_ADM_GRP);
} else
UNSET_SUBTLV(asla, EXT_EXTEND_ADM_GRP);
/* Send admin-group zero for better compatibility
* https://www.rfc-editor.org/rfc/rfc7308#section-2.3.2
*/
if (circuit->area->admin_group_send_zero &&
!IS_SUBTLV(asla, EXT_ADM_GRP) &&
!IS_SUBTLV(asla, EXT_EXTEND_ADM_GRP)) {
asla->admin_group = 0;
SET_SUBTLV(asla, EXT_ADM_GRP);
admin_group_clear(&asla->ext_admin_group);
admin_group_allow_explicit_zero(&asla->ext_admin_group);
SET_SUBTLV(asla, EXT_EXTEND_ADM_GRP);
}
if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC)) {
asla->te_metric = ifp->link_params->te_metric;
SET_SUBTLV(asla, EXT_TE_METRIC);
} else
UNSET_SUBTLV(asla, EXT_TE_METRIC);
if (IS_PARAM_SET(ifp->link_params, LP_DELAY)) {
asla->delay = ifp->link_params->av_delay;
SET_SUBTLV(asla, EXT_DELAY);
} else
UNSET_SUBTLV(asla, EXT_DELAY);
if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY)) {
asla->min_delay = ifp->link_params->min_delay;
asla->max_delay = ifp->link_params->max_delay;
SET_SUBTLV(asla, EXT_MM_DELAY);
} else {
UNSET_SUBTLV(asla, EXT_MM_DELAY);
}
if (asla->standard_apps == ISIS_SABM_FLAG_X)
/* Flex-Algo ASLA does not need the following TE
* sub-TLVs
*/
continue;
if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW)) {
asla->max_bw = ifp->link_params->max_bw;
SET_SUBTLV(asla, EXT_MAX_BW);
} else
UNSET_SUBTLV(asla, EXT_MAX_BW);
if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW)) {
asla->max_rsv_bw = ifp->link_params->max_rsv_bw;
SET_SUBTLV(asla, EXT_MAX_RSV_BW);
} else
UNSET_SUBTLV(asla, EXT_MAX_RSV_BW);
if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW)) {
for (i = 0; i < MAX_CLASS_TYPE; i++)
asla->unrsv_bw[i] =
ifp->link_params->unrsv_bw[i];
SET_SUBTLV(asla, EXT_UNRSV_BW);
} else
UNSET_SUBTLV(asla, EXT_UNRSV_BW);
if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR)) {
asla->delay_var = ifp->link_params->delay_var;
SET_SUBTLV(asla, EXT_DELAY_VAR);
} else
UNSET_SUBTLV(asla, EXT_DELAY_VAR);
if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS)) {
asla->pkt_loss = ifp->link_params->pkt_loss;
SET_SUBTLV(asla, EXT_PKT_LOSS);
} else
UNSET_SUBTLV(asla, EXT_PKT_LOSS);
if (IS_PARAM_SET(ifp->link_params, LP_RES_BW)) {
asla->res_bw = ifp->link_params->res_bw;
SET_SUBTLV(asla, EXT_RES_BW);
} else
UNSET_SUBTLV(asla, EXT_RES_BW);
if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW)) {
asla->ava_bw = ifp->link_params->ava_bw;
SET_SUBTLV(asla, EXT_AVA_BW);
} else
UNSET_SUBTLV(asla, EXT_AVA_BW);
if (IS_PARAM_SET(ifp->link_params, LP_USE_BW)) {
asla->use_bw = ifp->link_params->use_bw;
SET_SUBTLV(asla, EXT_USE_BW);
} else
UNSET_SUBTLV(asla, EXT_USE_BW);
}
for (ALL_LIST_ELEMENTS(ext->aslas, node, nnode, asla)) {
if (!asla->legacy && NO_SUBTLV(asla) &&
admin_group_nb_words(&asla->ext_admin_group) == 0)
/* remove ASLA without info from the list of ASLAs to
* not send void ASLA
*/
isis_tlvs_del_asla_flex_algo(ext, asla);
}
}
/* Main initialization / update function of the MPLS TE Circuit context */
/* Call when interface TE Link parameters are modified */
void isis_link_params_update(struct isis_circuit *circuit,
struct interface *ifp)
{
int i;
struct prefix_ipv4 *addr;
struct prefix_ipv6 *addr6;
struct isis_ext_subtlvs *ext;
/* Check if TE is enable or not */
if (!circuit->area || !IS_MPLS_TE(circuit->area->mta))
return;
/* Sanity Check */
if ((ifp == NULL) || (circuit->state != C_STATE_UP))
return;
te_debug("ISIS-TE(%s): Update circuit parameters for interface %s",
circuit->area->area_tag, ifp->name);
/* Check if MPLS TE Circuit context has not been already created */
if (circuit->ext == NULL) {
circuit->ext = isis_alloc_ext_subtlvs();
te_debug(" |- Allocated new Ext-subTLVs for interface %s",
ifp->name);
}
ext = circuit->ext;
/* Fulfill Extended subTLVs from interface link parameters */
if (HAS_LINK_PARAMS(ifp)) {
/* STD_TE metrics */
if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP)) {
ext->adm_group = ifp->link_params->admin_grp;
SET_SUBTLV(ext, EXT_ADM_GRP);
} else
UNSET_SUBTLV(ext, EXT_ADM_GRP);
if (IS_PARAM_SET(ifp->link_params, LP_EXTEND_ADM_GRP)) {
admin_group_copy(&ext->ext_admin_group,
&ifp->link_params->ext_admin_grp);
SET_SUBTLV(ext, EXT_EXTEND_ADM_GRP);
} else
UNSET_SUBTLV(ext, EXT_EXTEND_ADM_GRP);
/* Send admin-group zero for better compatibility
* https://www.rfc-editor.org/rfc/rfc7308#section-2.3.2
*/
if (circuit->area->admin_group_send_zero &&
!IS_SUBTLV(ext, EXT_ADM_GRP) &&
!IS_SUBTLV(ext, EXT_EXTEND_ADM_GRP)) {
ext->adm_group = 0;
SET_SUBTLV(ext, EXT_ADM_GRP);
admin_group_clear(&ext->ext_admin_group);
admin_group_allow_explicit_zero(&ext->ext_admin_group);
SET_SUBTLV(ext, EXT_EXTEND_ADM_GRP);
}
/* If known, register local IPv4 addr from ip_addr list */
if (listcount(circuit->ip_addrs) != 0) {
addr = (struct prefix_ipv4 *)listgetdata(
(struct listnode *)listhead(circuit->ip_addrs));
IPV4_ADDR_COPY(&ext->local_addr, &addr->prefix);
SET_SUBTLV(ext, EXT_LOCAL_ADDR);
} else
UNSET_SUBTLV(ext, EXT_LOCAL_ADDR);
/* If known, register local IPv6 addr from ip_addr list */
if (listcount(circuit->ipv6_non_link) != 0) {
addr6 = (struct prefix_ipv6 *)listgetdata(
(struct listnode *)listhead(
circuit->ipv6_non_link));
IPV6_ADDR_COPY(&ext->local_addr6, &addr6->prefix);
SET_SUBTLV(ext, EXT_LOCAL_ADDR6);
} else
UNSET_SUBTLV(ext, EXT_LOCAL_ADDR6);
/*
* Remote IPv4 and IPv6 addresses are now added in
* isis_mpls_te_adj_ip_enabled() to get the right IP address
* in particular for IPv6 to get the global IPv6 address and
* not the link-local IPv6 address.
*/
if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW)) {
ext->max_bw = ifp->link_params->max_bw;
SET_SUBTLV(ext, EXT_MAX_BW);
} else
UNSET_SUBTLV(ext, EXT_MAX_BW);
if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW)) {
ext->max_rsv_bw = ifp->link_params->max_rsv_bw;
SET_SUBTLV(ext, EXT_MAX_RSV_BW);
} else
UNSET_SUBTLV(ext, EXT_MAX_RSV_BW);
if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW)) {
for (i = 0; i < MAX_CLASS_TYPE; i++)
ext->unrsv_bw[i] =
ifp->link_params->unrsv_bw[i];
SET_SUBTLV(ext, EXT_UNRSV_BW);
} else
UNSET_SUBTLV(ext, EXT_UNRSV_BW);
if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC)) {
ext->te_metric = ifp->link_params->te_metric;
SET_SUBTLV(ext, EXT_TE_METRIC);
} else
UNSET_SUBTLV(ext, EXT_TE_METRIC);
/* TE metric extensions */
if (IS_PARAM_SET(ifp->link_params, LP_DELAY)) {
ext->delay = ifp->link_params->av_delay;
SET_SUBTLV(ext, EXT_DELAY);
} else
UNSET_SUBTLV(ext, EXT_DELAY);
if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY)) {
ext->min_delay = ifp->link_params->min_delay;
ext->max_delay = ifp->link_params->max_delay;
SET_SUBTLV(ext, EXT_MM_DELAY);
} else
UNSET_SUBTLV(ext, EXT_MM_DELAY);
if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR)) {
ext->delay_var = ifp->link_params->delay_var;
SET_SUBTLV(ext, EXT_DELAY_VAR);
} else
UNSET_SUBTLV(ext, EXT_DELAY_VAR);
if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS)) {
ext->pkt_loss = ifp->link_params->pkt_loss;
SET_SUBTLV(ext, EXT_PKT_LOSS);
} else
UNSET_SUBTLV(ext, EXT_PKT_LOSS);
if (IS_PARAM_SET(ifp->link_params, LP_RES_BW)) {
ext->res_bw = ifp->link_params->res_bw;
SET_SUBTLV(ext, EXT_RES_BW);
} else
UNSET_SUBTLV(ext, EXT_RES_BW);
if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW)) {
ext->ava_bw = ifp->link_params->ava_bw;
SET_SUBTLV(ext, EXT_AVA_BW);
} else
UNSET_SUBTLV(ext, EXT_AVA_BW);
if (IS_PARAM_SET(ifp->link_params, LP_USE_BW)) {
ext->use_bw = ifp->link_params->use_bw;
SET_SUBTLV(ext, EXT_USE_BW);
} else
UNSET_SUBTLV(ext, EXT_USE_BW);
/* INTER_AS */
if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) {
ext->remote_as = ifp->link_params->rmt_as;
ext->remote_ip = ifp->link_params->rmt_ip;
SET_SUBTLV(ext, EXT_RMT_AS);
SET_SUBTLV(ext, EXT_RMT_IP);
} else {
/* reset inter-as TE params */
UNSET_SUBTLV(ext, EXT_RMT_AS);
UNSET_SUBTLV(ext, EXT_RMT_IP);
}
te_debug(" |- New MPLS-TE link parameters status 0x%x",
ext->status);
} else {
te_debug(" |- Reset Extended subTLVs status 0x%x",
ext->status);
/* Reset TE subTLVs keeping SR one's */
if (IS_SUBTLV(ext, EXT_ADJ_SID))
ext->status = EXT_ADJ_SID;
else if (IS_SUBTLV(ext, EXT_LAN_ADJ_SID))
ext->status = EXT_LAN_ADJ_SID;
else
ext->status = 0;
}
isis_link_params_update_asla(circuit, ifp);
return;
}
static int _isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
bool global)
{
struct isis_circuit *circuit;
struct isis_ext_subtlvs *ext;
circuit = adj->circuit;
/* Check that MPLS TE is enabled */
if (!IS_MPLS_TE(circuit->area->mta) || !circuit->ext)
return 0;
ext = circuit->ext;
/* Determine nexthop IP address */
switch (family) {
case AF_INET:
if (!circuit->ip_router || !adj->ipv4_address_count)
UNSET_SUBTLV(ext, EXT_NEIGH_ADDR);
else {
IPV4_ADDR_COPY(&ext->neigh_addr,
&adj->ipv4_addresses[0]);
SET_SUBTLV(ext, EXT_NEIGH_ADDR);
}
break;
case AF_INET6:
/* Nothing to do for link-local addresses - ie. not global.
* https://datatracker.ietf.org/doc/html/rfc6119#section-3.1.1
* Because the IPv6 traffic engineering TLVs present in LSPs are
* propagated across networks, they MUST NOT use link-local
* addresses.
*/
if (!global)
return 0;
if (!circuit->ipv6_router || !adj->global_ipv6_count)
UNSET_SUBTLV(ext, EXT_NEIGH_ADDR6);
else {
IPV6_ADDR_COPY(&ext->neigh_addr6,
&adj->global_ipv6_addrs[0]);
SET_SUBTLV(ext, EXT_NEIGH_ADDR6);
}
break;
default:
return 0;
}
return 0;
}
static int isis_mpls_te_adj_ip_enabled(struct isis_adjacency *adj, int family,
bool global)
{
int ret;
/* Sanity Check */
if (!adj || !adj->circuit)
return 0;
ret = _isis_mpls_te_adj_ip_enabled(adj, family, global);
/* Update LSP */
lsp_regenerate_schedule(adj->circuit->area, adj->circuit->is_type, 0);
return ret;
}
static int _isis_mpls_te_adj_ip_disabled(struct isis_adjacency *adj, int family,
bool global)
{
struct isis_circuit *circuit;
struct isis_ext_subtlvs *ext;
circuit = adj->circuit;
/* Check that MPLS TE is enabled */
if (!IS_MPLS_TE(circuit->area->mta) || !circuit->ext)
return 0;
ext = circuit->ext;
/* Update MPLS TE IP address parameters if possible */
if (!IS_MPLS_TE(circuit->area->mta) || !IS_EXT_TE(ext))
return 0;
/* Determine nexthop IP address */
switch (family) {
case AF_INET:
UNSET_SUBTLV(ext, EXT_NEIGH_ADDR);
break;
case AF_INET6:
if (global)
UNSET_SUBTLV(ext, EXT_NEIGH_ADDR6);
break;
default:
return 0;
}
return 0;
}
static int isis_mpls_te_adj_ip_disabled(struct isis_adjacency *adj, int family,
bool global)
{
int ret;
/* Sanity Check */
if (!adj || !adj->circuit || !adj->circuit->ext)
return 0;
ret = _isis_mpls_te_adj_ip_disabled(adj, family, global);
/* Update LSP */
lsp_regenerate_schedule(adj->circuit->area, adj->circuit->is_type, 0);
return ret;
}
static void isis_mpls_te_circuit_ip_update(struct isis_circuit *circuit)
{
struct isis_adjacency *adj;
/* https://datatracker.ietf.org/doc/html/rfc6119#section-3.2.3
* This sub-TLV of the Extended IS Reachability TLV is used for point-
* to-point links
*/
if (circuit->circ_type != CIRCUIT_T_P2P)
return;
adj = circuit->u.p2p.neighbor;
if (!adj)
return;
/* Nothing to do for link-local addresses.
* https://datatracker.ietf.org/doc/html/rfc6119#section-3.1.1
* Because the IPv6 traffic engineering TLVs present in LSPs are
* propagated across networks, they MUST NOT use link-local addresses.
*/
if (adj->ipv4_address_count > 0)
_isis_mpls_te_adj_ip_enabled(adj, AF_INET, false);
else
_isis_mpls_te_adj_ip_disabled(adj, AF_INET, false);
if (adj->global_ipv6_count > 0)
_isis_mpls_te_adj_ip_enabled(adj, AF_INET6, true);
else
_isis_mpls_te_adj_ip_disabled(adj, AF_INET6, true);
}
int isis_mpls_te_update(struct interface *ifp)
{
struct isis_circuit *circuit;
uint8_t rc = 1;
/* Sanity Check */
if (ifp == NULL)
return rc;
/* Get circuit context from interface */
circuit = circuit_scan_by_ifp(ifp);
if (circuit == NULL)
return rc;
/* Update TE TLVs ... */
isis_link_params_update(circuit, ifp);
/* ... and LSP */
if (circuit->area &&
(IS_MPLS_TE(circuit->area->mta)
#ifndef FABRICD
|| !list_isempty(circuit->area->flex_algos->flex_algos)
#endif /* ifndef FABRICD */
))
lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
rc = 0;
return rc;
}
/**
* Export Link State information to consumer daemon through ZAPI Link State
* Opaque Message.
*
* @param type Type of Link State Element i.e. Vertex, Edge or Subnet
* @param link_state Pointer to Link State Vertex, Edge or Subnet
*
* @return 0 if success, -1 otherwise
*/
static int isis_te_export(uint8_t type, void *link_state)
{
struct ls_message msg = {};
int rc = 0;
switch (type) {
case LS_MSG_TYPE_NODE:
ls_vertex2msg(&msg, (struct ls_vertex *)link_state);
rc = ls_send_msg(zclient, &msg, NULL);
break;
case LS_MSG_TYPE_ATTRIBUTES:
ls_edge2msg(&msg, (struct ls_edge *)link_state);
rc = ls_send_msg(zclient, &msg, NULL);
break;
case LS_MSG_TYPE_PREFIX:
ls_subnet2msg(&msg, (struct ls_subnet *)link_state);
rc = ls_send_msg(zclient, &msg, NULL);
break;
default:
rc = -1;
break;
}
return rc;
}
/**
* Parse LSP and build corresponding vertex. If vertex doesn't exist in the
* Link State Database it is created otherwise updated.
*
* @param ted Traffic Engineering Link State Database
* @param lsp IS-IS Link State PDU
*
* @return Link State Vertex or NULL in case of error
*/
static struct ls_vertex *lsp_to_vertex(struct ls_ted *ted, struct isis_lsp *lsp)
{
struct ls_vertex *vertex = NULL;
struct ls_node *old, lnode = {};
struct isis_tlvs *tlvs;
const struct in_addr inaddr_any = {.s_addr = INADDR_ANY};
/* Sanity check */
if (!ted || !lsp)
return NULL;
/* Compute Link State Node ID from IS-IS sysID ... */
if (lsp->level == ISIS_LEVEL1)
lnode.adv.origin = ISIS_L1;
else
lnode.adv.origin = ISIS_L2;
memcpy(&lnode.adv.id.iso.sys_id, &lsp->hdr.lsp_id, ISIS_SYS_ID_LEN);
lnode.adv.id.iso.level = lsp->level;
/* ... and search the corresponding vertex */
vertex = ls_find_vertex_by_id(ted, lnode.adv);
/* Create a new one if not found */
if (!vertex) {
old = ls_node_new(lnode.adv, inaddr_any, in6addr_any);
old->type = STANDARD;
vertex = ls_vertex_add(ted, old);
}
old = vertex->node;
te_debug(" |- %s Vertex (%" PRIu64 ") for node %s",
vertex->status == NEW ? "Create" : "Found", vertex->key,
print_sys_hostname(old->adv.id.iso.sys_id));
/* Fulfill Link State Node information */
tlvs = lsp->tlvs;
if (tlvs) {
if (tlvs->te_router_id) {
IPV4_ADDR_COPY(&lnode.router_id, tlvs->te_router_id);
SET_FLAG(lnode.flags, LS_NODE_ROUTER_ID);
}
if (tlvs->te_router_id_ipv6) {
IPV6_ADDR_COPY(&lnode.router_id6,
tlvs->te_router_id_ipv6);
SET_FLAG(lnode.flags, LS_NODE_ROUTER_ID6);
}
if (tlvs->hostname) {
strlcpy(lnode.name, tlvs->hostname, MAX_NAME_LENGTH);
SET_FLAG(lnode.flags, LS_NODE_NAME);
}
if (tlvs->router_cap) {
struct isis_router_cap *cap = tlvs->router_cap;
if (cap->srgb.lower_bound != 0
&& cap->srgb.range_size != 0) {
SET_FLAG(lnode.flags, LS_NODE_SR);
lnode.srgb.flag = cap->srgb.flags;
lnode.srgb.lower_bound = cap->srgb.lower_bound;
lnode.srgb.range_size = cap->srgb.range_size;
for (int i = 0; i < LIB_LS_SR_ALGO_COUNT; i++)
lnode.algo[i] = cap->algo[i];
}
if (cap->srlb.lower_bound != 0
&& cap->srlb.range_size != 0) {
lnode.srlb.lower_bound = cap->srlb.lower_bound;
lnode.srlb.range_size = cap->srlb.range_size;
SET_FLAG(lnode.flags, LS_NODE_SRLB);
}
if (cap->msd != 0) {
lnode.msd = cap->msd;
SET_FLAG(lnode.flags, LS_NODE_MSD);
}
}
}
/* Update Link State Node information */
if (!ls_node_same(old, &lnode)) {
te_debug(" |- Update Link State Node information");
memcpy(old, &lnode, sizeof(struct ls_node));
if (vertex->status != NEW)
vertex->status = UPDATE;
}
/* Set self TED vertex if LSP corresponds to the own router */
if (lsp->own_lsp)
ted->self = vertex;
return vertex;
}
/**
* Get Link State Edge from Link State Attributes in TE Database.
* Edge structure is dynamically allocated and fulfill with Link State
* Attributes if not found.
*
* @param ted Link State Database
* @param attr Link State Attributes
*
* @return New Link State Edge if success, NULL otherwise
*/
static struct ls_edge *get_edge(struct ls_ted *ted, struct ls_attributes *attr)
{
struct ls_edge *edge;
struct ls_standard *std;
struct ls_edge_key key;
/* Check parameters */
if (!ted || !attr)
return NULL;
std = &attr->standard;
/* Compute keys in function of local address (IPv4/v6) or identifier */
if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR)) {
key.family = AF_INET;
IPV4_ADDR_COPY(&key.k.addr, &std->local);
} else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR6)) {
key.family = AF_INET6;
IPV6_ADDR_COPY(&key.k.addr6, &std->local6);
} else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ID)) {
key.family = AF_LOCAL;
key.k.link_id = (((uint64_t)std->local_id) & 0xffffffff) |
((uint64_t)std->remote_id << 32);
} else {
key.family = AF_UNSPEC;
}
/* Stop here if we don't got a valid key */
if (key.family == AF_UNSPEC)
return NULL;
/* Get corresponding Edge by key from Link State Data Base */
edge = ls_find_edge_by_key(ted, key);
/* and create new one if not exist */
if (!edge) {
edge = ls_edge_add(ted, attr);
/*
* Edge could be Null if no local ID is found in Attributes.
* Stop the processing as without any local ID it is not
* possible to store Edge in the TED.
*/
if (!edge)
return NULL;
}
if (CHECK_FLAG(edge->attributes->flags, LS_ATTR_LOCAL_ADDR))
te_debug(" |- %s Edge (%pI4) from Extended Reach. %pI4",
edge->status == NEW ? "Create" : "Found",
&edge->key.k.addr, &attr->standard.local);
else if (CHECK_FLAG(edge->attributes->flags, LS_ATTR_LOCAL_ADDR6))
te_debug(" |- %s Edge (%pI6) from Extended Reach. %pI6",
edge->status == NEW ? "Create" : "Found",
&edge->key.k.addr6, &attr->standard.local6);
else
te_debug(" |- %s Edge (%" PRIu64 ")",
edge->status == NEW ? "Create" : "Found",
edge->key.k.link_id);
return edge;
}
/**
* Get Link State Attributes from IS-IS Sub-TLVs. Structure is dynamically
* allocated and should be free once not use anymore.
*
* @param adv Link State Node ID
* @param tlvs IS-IS Sub TLVs
*
* @return New Link State attributes if success, NULL otherwise
*/
static struct ls_attributes *get_attributes(struct ls_node_id adv,
struct isis_ext_subtlvs *tlvs)
{
struct ls_attributes *attr;
struct in_addr local = {.s_addr = INADDR_ANY};
struct in6_addr local6 = in6addr_any;
uint32_t local_id = 0;
/* Got Local identifier */
if (CHECK_FLAG(tlvs->status, EXT_LOCAL_ADDR))
local.s_addr = tlvs->local_addr.s_addr;
if (CHECK_FLAG(tlvs->status, EXT_LOCAL_ADDR6))
memcpy(&local6, &tlvs->local_addr6, IPV6_MAX_BYTELEN);
if (CHECK_FLAG(tlvs->status, EXT_LLRI))
local_id = tlvs->local_llri;
/* Create LS Attributes */
attr = ls_attributes_new(adv, local, local6, local_id);
if (!attr)
return NULL;
/* Browse sub-TLV and fulfill Link State Attributes */
if (CHECK_FLAG(tlvs->status, EXT_ADM_GRP)) {
attr->standard.admin_group = tlvs->adm_group;
SET_FLAG(attr->flags, LS_ATTR_ADM_GRP);
}
if (CHECK_FLAG(tlvs->status, EXT_EXTEND_ADM_GRP)) {
admin_group_copy(&attr->ext_admin_group,
&tlvs->ext_admin_group);
SET_FLAG(attr->flags, LS_ATTR_EXT_ADM_GRP);
}
if (CHECK_FLAG(tlvs->status, EXT_LLRI)) {
attr->standard.local_id = tlvs->local_llri;
attr->standard.remote_id = tlvs->remote_llri;
SET_FLAG(attr->flags, LS_ATTR_LOCAL_ID);
SET_FLAG(attr->flags, LS_ATTR_NEIGH_ID);
}
if (CHECK_FLAG(tlvs->status, EXT_NEIGH_ADDR)) {
attr->standard.remote.s_addr = tlvs->neigh_addr.s_addr;
SET_FLAG(attr->flags, LS_ATTR_NEIGH_ADDR);
}
if (CHECK_FLAG(tlvs->status, EXT_NEIGH_ADDR6)) {
memcpy(&attr->standard.remote6, &tlvs->neigh_addr6,
IPV6_MAX_BYTELEN);
SET_FLAG(attr->flags, LS_ATTR_NEIGH_ADDR6);
}
if (CHECK_FLAG(tlvs->status, EXT_MAX_BW)) {
attr->standard.max_bw = tlvs->max_bw;
SET_FLAG(attr->flags, LS_ATTR_MAX_BW);
}
if (CHECK_FLAG(tlvs->status, EXT_MAX_RSV_BW)) {
attr->standard.max_rsv_bw = tlvs->max_rsv_bw;
SET_FLAG(attr->flags, LS_ATTR_MAX_RSV_BW);
}
if (CHECK_FLAG(tlvs->status, EXT_UNRSV_BW)) {
memcpy(&attr->standard.unrsv_bw, tlvs->unrsv_bw,
ISIS_SUBTLV_UNRSV_BW_SIZE);
SET_FLAG(attr->flags, LS_ATTR_UNRSV_BW);
}
if (CHECK_FLAG(tlvs->status, EXT_TE_METRIC)) {
attr->standard.te_metric = tlvs->te_metric;
SET_FLAG(attr->flags, LS_ATTR_TE_METRIC);
}
if (CHECK_FLAG(tlvs->status, EXT_RMT_AS)) {
attr->standard.remote_as = tlvs->remote_as;
SET_FLAG(attr->flags, LS_ATTR_REMOTE_AS);
}
if (CHECK_FLAG(tlvs->status, EXT_RMT_IP)) {
attr->standard.remote_addr = tlvs->remote_ip;
SET_FLAG(attr->flags, LS_ATTR_REMOTE_ADDR);
}
if (CHECK_FLAG(tlvs->status, EXT_DELAY)) {
attr->extended.delay = tlvs->delay;
SET_FLAG(attr->flags, LS_ATTR_DELAY);
}
if (CHECK_FLAG(tlvs->status, EXT_MM_DELAY)) {
attr->extended.min_delay = tlvs->min_delay;
attr->extended.max_delay = tlvs->max_delay;
SET_FLAG(attr->flags, LS_ATTR_MIN_MAX_DELAY);
}
if (CHECK_FLAG(tlvs->status, EXT_DELAY_VAR)) {
attr->extended.jitter = tlvs->delay_var;
SET_FLAG(attr->flags, LS_ATTR_JITTER);
}
if (CHECK_FLAG(tlvs->status, EXT_PKT_LOSS)) {
attr->extended.pkt_loss = tlvs->pkt_loss;
SET_FLAG(attr->flags, LS_ATTR_PACKET_LOSS);
}
if (CHECK_FLAG(tlvs->status, EXT_AVA_BW)) {
attr->extended.ava_bw = tlvs->ava_bw;
SET_FLAG(attr->flags, LS_ATTR_AVA_BW);
}
if (CHECK_FLAG(tlvs->status, EXT_RES_BW)) {
attr->extended.rsv_bw = tlvs->res_bw;
SET_FLAG(attr->flags, LS_ATTR_RSV_BW);
}
if (CHECK_FLAG(tlvs->status, EXT_USE_BW)) {
attr->extended.used_bw = tlvs->use_bw;
SET_FLAG(attr->flags, LS_ATTR_USE_BW);
}
if (CHECK_FLAG(tlvs->status, EXT_ADJ_SID)) {
struct isis_adj_sid *adj =
(struct isis_adj_sid *)tlvs->adj_sid.head;
int i;