forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathospf_ri.c
2139 lines (1774 loc) · 55.4 KB
/
ospf_ri.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
/*
* This is an implementation of RFC4970 Router Information
* with support of RFC5088 PCE Capabilites announcement
*
* Module name: Router Information
* Author: Olivier Dugeon <olivier.dugeon@orange.com>
* Copyright (C) 2012 - 2017 Orange Labs http://www.orange.com/
*
* This file is part of GNU Quagga.
*
* GNU Zebra is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* GNU Quagga 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 <math.h>
#include "linklist.h"
#include "prefix.h"
#include "if.h"
#include "table.h"
#include "memory.h"
#include "command.h"
#include "vty.h"
#include "stream.h"
#include "log.h"
#include "thread.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "mpls.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_asbr.h"
#include "ospfd/ospf_lsa.h"
#include "ospfd/ospf_lsdb.h"
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_nsm.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_packet.h"
#include "ospfd/ospf_spf.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_route.h"
#include "ospfd/ospf_ase.h"
#include "ospfd/ospf_zebra.h"
#include "ospfd/ospf_sr.h"
#include "ospfd/ospf_ri.h"
#include "ospfd/ospf_errors.h"
/*
* Global variable to manage Opaque-LSA/Router Information on this node.
* Note that all parameter values are stored in network byte order.
*/
static struct ospf_router_info OspfRI;
/*------------------------------------------------------------------------------*
* Following are initialize/terminate functions for Router Information
*handling.
*------------------------------------------------------------------------------*/
static void ospf_router_info_ism_change(struct ospf_interface *oi,
int old_status);
static void ospf_router_info_config_write_router(struct vty *vty);
static void ospf_router_info_show_info(struct vty *vty,
struct json_object *json,
struct ospf_lsa *lsa);
static int ospf_router_info_lsa_originate(void *arg);
static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa);
static void ospf_router_info_lsa_schedule(struct ospf_ri_area_info *ai,
enum lsa_opcode opcode);
static void ospf_router_info_register_vty(void);
static int ospf_router_info_lsa_update(struct ospf_lsa *lsa);
static void del_area_info(void *val);
static void del_pce_info(void *val);
int ospf_router_info_init(void)
{
zlog_info("RI (%s): Initialize Router Information", __func__);
memset(&OspfRI, 0, sizeof(OspfRI));
OspfRI.enabled = false;
OspfRI.registered = 0;
OspfRI.scope = OSPF_OPAQUE_AS_LSA;
OspfRI.as_flags = RIFLG_LSA_INACTIVE;
OspfRI.area_info = list_new();
OspfRI.area_info->del = del_area_info;
/* Initialize pce domain and neighbor list */
OspfRI.pce_info.enabled = false;
OspfRI.pce_info.pce_domain = list_new();
OspfRI.pce_info.pce_domain->del = del_pce_info;
OspfRI.pce_info.pce_neighbor = list_new();
OspfRI.pce_info.pce_neighbor->del = del_pce_info;
/* Initialize Segment Routing information structure */
OspfRI.sr_info.enabled = false;
ospf_router_info_register_vty();
return 0;
}
static int ospf_router_info_register(uint8_t scope)
{
int rc = 0;
if (OspfRI.registered)
return rc;
zlog_info("RI (%s): Register Router Information with scope %s(%d)",
__func__,
scope == OSPF_OPAQUE_AREA_LSA ? "Area" : "AS", scope);
rc = ospf_register_opaque_functab(
scope, OPAQUE_TYPE_ROUTER_INFORMATION_LSA,
NULL, /* new interface */
NULL, /* del interface */
ospf_router_info_ism_change,
NULL, /* NSM change */
ospf_router_info_config_write_router,
NULL, /* Config. write interface */
NULL, /* Config. write debug */
ospf_router_info_show_info, ospf_router_info_lsa_originate,
ospf_router_info_lsa_refresh, ospf_router_info_lsa_update,
NULL); /* del_lsa_hook */
if (rc != 0) {
flog_warn(
EC_OSPF_OPAQUE_REGISTRATION,
"RI (%s): Failed to register functions", __func__);
return rc;
}
OspfRI.registered = 1;
OspfRI.scope = scope;
return rc;
}
static int ospf_router_info_unregister(void)
{
if ((OspfRI.scope != OSPF_OPAQUE_AS_LSA)
&& (OspfRI.scope != OSPF_OPAQUE_AREA_LSA)) {
assert("Unable to unregister Router Info functions: Wrong scope!"
== NULL);
return -1;
}
ospf_delete_opaque_functab(OspfRI.scope,
OPAQUE_TYPE_ROUTER_INFORMATION_LSA);
OspfRI.registered = 0;
return 0;
}
void ospf_router_info_term(void)
{
list_delete(&OspfRI.pce_info.pce_domain);
list_delete(&OspfRI.pce_info.pce_neighbor);
OspfRI.enabled = false;
ospf_router_info_unregister();
return;
}
void ospf_router_info_finish(void)
{
struct listnode *node, *nnode;
struct ospf_ri_area_info *ai;
/* Flush Router Info LSA */
for (ALL_LIST_ELEMENTS(OspfRI.area_info, node, nnode, ai))
if (CHECK_FLAG(ai->flags, RIFLG_LSA_ENGAGED))
ospf_router_info_lsa_schedule(ai, FLUSH_THIS_LSA);
list_delete_all_node(OspfRI.pce_info.pce_domain);
list_delete_all_node(OspfRI.pce_info.pce_neighbor);
OspfRI.enabled = false;
}
static void del_area_info(void *val)
{
XFREE(MTYPE_OSPF_ROUTER_INFO, val);
}
static void del_pce_info(void *val)
{
XFREE(MTYPE_OSPF_PCE_PARAMS, val);
}
/* Catch RI LSA flooding Scope for ospf_ext.[h,c] code */
struct scope_info ospf_router_info_get_flooding_scope(void)
{
struct scope_info flooding_scope;
if (OspfRI.scope == OSPF_OPAQUE_AS_LSA) {
flooding_scope.scope = OSPF_OPAQUE_AS_LSA;
flooding_scope.areas = NULL;
return flooding_scope;
}
flooding_scope.scope = OSPF_OPAQUE_AREA_LSA;
flooding_scope.areas = OspfRI.area_info;
return flooding_scope;
}
static struct ospf_ri_area_info *lookup_by_area(struct ospf_area *area)
{
struct listnode *node, *nnode;
struct ospf_ri_area_info *ai;
for (ALL_LIST_ELEMENTS(OspfRI.area_info, node, nnode, ai))
if (ai->area == area)
return ai;
return NULL;
}
/*------------------------------------------------------------------------*
* Following are control functions for ROUTER INFORMATION parameters
*management.
*------------------------------------------------------------------------*/
static void set_router_info_capabilities(struct ri_tlv_router_cap *ric,
uint32_t cap)
{
ric->header.type = htons(RI_TLV_CAPABILITIES);
ric->header.length = htons(RI_TLV_LENGTH);
ric->value = htonl(cap);
return;
}
static int set_pce_header(struct ospf_pce_info *pce)
{
uint16_t length = 0;
struct listnode *node;
struct ri_pce_subtlv_domain *domain;
struct ri_pce_subtlv_neighbor *neighbor;
/* PCE Address */
if (ntohs(pce->pce_address.header.type) != 0)
length += TLV_SIZE(&pce->pce_address.header);
/* PCE Path Scope */
if (ntohs(pce->pce_scope.header.type) != 0)
length += TLV_SIZE(&pce->pce_scope.header);
/* PCE Domain */
for (ALL_LIST_ELEMENTS_RO(pce->pce_domain, node, domain)) {
if (ntohs(domain->header.type) != 0)
length += TLV_SIZE(&domain->header);
}
/* PCE Neighbor */
for (ALL_LIST_ELEMENTS_RO(pce->pce_neighbor, node, neighbor)) {
if (ntohs(neighbor->header.type) != 0)
length += TLV_SIZE(&neighbor->header);
}
/* PCE Capabilities */
if (ntohs(pce->pce_cap_flag.header.type) != 0)
length += TLV_SIZE(&pce->pce_cap_flag.header);
if (length != 0) {
pce->pce_header.header.type = htons(RI_TLV_PCE);
pce->pce_header.header.length = htons(length);
pce->enabled = true;
} else {
pce->pce_header.header.type = 0;
pce->pce_header.header.length = 0;
pce->enabled = false;
}
return length;
}
static void set_pce_address(struct in_addr ipv4, struct ospf_pce_info *pce)
{
/* Enable PCE Info */
pce->pce_header.header.type = htons(RI_TLV_PCE);
/* Set PCE Address */
pce->pce_address.header.type = htons(RI_PCE_SUBTLV_ADDRESS);
pce->pce_address.header.length = htons(PCE_ADDRESS_IPV4_SIZE);
pce->pce_address.address.type = htons(PCE_ADDRESS_IPV4);
pce->pce_address.address.value = ipv4;
return;
}
static void set_pce_path_scope(uint32_t scope, struct ospf_pce_info *pce)
{
/* Set PCE Scope */
pce->pce_scope.header.type = htons(RI_PCE_SUBTLV_PATH_SCOPE);
pce->pce_scope.header.length = htons(RI_TLV_LENGTH);
pce->pce_scope.value = htonl(scope);
return;
}
static void set_pce_domain(uint16_t type, uint32_t domain,
struct ospf_pce_info *pce)
{
struct ri_pce_subtlv_domain *new;
/* Create new domain info */
new = XCALLOC(MTYPE_OSPF_PCE_PARAMS,
sizeof(struct ri_pce_subtlv_domain));
new->header.type = htons(RI_PCE_SUBTLV_DOMAIN);
new->header.length = htons(PCE_ADDRESS_IPV4_SIZE);
new->type = htons(type);
new->value = htonl(domain);
/* Add new domain to the list */
listnode_add(pce->pce_domain, new);
return;
}
static void unset_pce_domain(uint16_t type, uint32_t domain,
struct ospf_pce_info *pce)
{
struct listnode *node;
struct ri_pce_subtlv_domain *old = NULL;
int found = 0;
/* Search the corresponding node */
for (ALL_LIST_ELEMENTS_RO(pce->pce_domain, node, old)) {
if ((old->type == htons(type))
&& (old->value == htonl(domain))) {
found = 1;
break;
}
}
/* if found remove it */
if (found) {
listnode_delete(pce->pce_domain, old);
/* Finally free the old domain */
XFREE(MTYPE_OSPF_PCE_PARAMS, old);
}
}
static void set_pce_neighbor(uint16_t type, uint32_t domain,
struct ospf_pce_info *pce)
{
struct ri_pce_subtlv_neighbor *new;
/* Create new neighbor info */
new = XCALLOC(MTYPE_OSPF_PCE_PARAMS,
sizeof(struct ri_pce_subtlv_neighbor));
new->header.type = htons(RI_PCE_SUBTLV_NEIGHBOR);
new->header.length = htons(PCE_ADDRESS_IPV4_SIZE);
new->type = htons(type);
new->value = htonl(domain);
/* Add new domain to the list */
listnode_add(pce->pce_neighbor, new);
return;
}
static void unset_pce_neighbor(uint16_t type, uint32_t domain,
struct ospf_pce_info *pce)
{
struct listnode *node;
struct ri_pce_subtlv_neighbor *old = NULL;
int found = 0;
/* Search the corresponding node */
for (ALL_LIST_ELEMENTS_RO(pce->pce_neighbor, node, old)) {
if ((old->type == htons(type))
&& (old->value == htonl(domain))) {
found = 1;
break;
}
}
/* if found remove it */
if (found) {
listnode_delete(pce->pce_neighbor, old);
/* Finally free the old domain */
XFREE(MTYPE_OSPF_PCE_PARAMS, old);
}
}
static void set_pce_cap_flag(uint32_t cap, struct ospf_pce_info *pce)
{
/* Set PCE Capabilities flag */
pce->pce_cap_flag.header.type = htons(RI_PCE_SUBTLV_CAP_FLAG);
pce->pce_cap_flag.header.length = htons(RI_TLV_LENGTH);
pce->pce_cap_flag.value = htonl(cap);
return;
}
/* Segment Routing TLV setter */
/* Algorithm SubTLV - section 3.1 */
static void set_sr_algorithm(uint8_t algo)
{
OspfRI.sr_info.algo.value[0] = algo;
for (int i = 1; i < ALGORITHM_COUNT; i++)
OspfRI.sr_info.algo.value[i] = SR_ALGORITHM_UNSET;
/* Set TLV type and length == only 1 Algorithm */
TLV_TYPE(OspfRI.sr_info.algo) = htons(RI_SR_TLV_SR_ALGORITHM);
TLV_LEN(OspfRI.sr_info.algo) = htons(sizeof(uint8_t));
}
/* unset Aglogithm SubTLV */
static void unset_sr_algorithm(uint8_t algo)
{
for (int i = 0; i < ALGORITHM_COUNT; i++)
OspfRI.sr_info.algo.value[i] = SR_ALGORITHM_UNSET;
/* Unset TLV type and length */
TLV_TYPE(OspfRI.sr_info.algo) = htons(0);
TLV_LEN(OspfRI.sr_info.algo) = htons(0);
}
/* Set Segment Routing Global Block SubTLV - section 3.2 */
static void set_sr_global_label_range(struct sr_block srgb)
{
/* Set Header */
TLV_TYPE(OspfRI.sr_info.srgb) = htons(RI_SR_TLV_SRGB_LABEL_RANGE);
TLV_LEN(OspfRI.sr_info.srgb) = htons(RI_SR_TLV_LABEL_RANGE_SIZE);
/* Set Range Size */
OspfRI.sr_info.srgb.size = htonl(SET_RANGE_SIZE(srgb.range_size));
/* Set Lower bound label SubTLV */
TLV_TYPE(OspfRI.sr_info.srgb.lower) = htons(SUBTLV_SID_LABEL);
TLV_LEN(OspfRI.sr_info.srgb.lower) = htons(SID_RANGE_LABEL_LENGTH);
OspfRI.sr_info.srgb.lower.value = htonl(SET_LABEL(srgb.lower_bound));
}
/* Unset Segment Routing Global Block SubTLV */
static void unset_sr_global_label_range(void)
{
TLV_TYPE(OspfRI.sr_info.srgb) = htons(0);
TLV_LEN(OspfRI.sr_info.srgb) = htons(0);
TLV_TYPE(OspfRI.sr_info.srgb.lower) = htons(0);
TLV_LEN(OspfRI.sr_info.srgb.lower) = htons(0);
}
/* Set Segment Routing Local Block SubTLV - section 3.2 */
static void set_sr_local_label_range(struct sr_block srlb)
{
/* Set Header */
TLV_TYPE(OspfRI.sr_info.srlb) = htons(RI_SR_TLV_SRLB_LABEL_RANGE);
TLV_LEN(OspfRI.sr_info.srlb) = htons(RI_SR_TLV_LABEL_RANGE_SIZE);
/* Set Range Size */
OspfRI.sr_info.srlb.size = htonl(SET_RANGE_SIZE(srlb.range_size));
/* Set Lower bound label SubTLV */
TLV_TYPE(OspfRI.sr_info.srlb.lower) = htons(SUBTLV_SID_LABEL);
TLV_LEN(OspfRI.sr_info.srlb.lower) = htons(SID_RANGE_LABEL_LENGTH);
OspfRI.sr_info.srlb.lower.value = htonl(SET_LABEL(srlb.lower_bound));
}
/* Unset Segment Routing Local Block SubTLV */
static void unset_sr_local_label_range(void)
{
TLV_TYPE(OspfRI.sr_info.srlb) = htons(0);
TLV_LEN(OspfRI.sr_info.srlb) = htons(0);
TLV_TYPE(OspfRI.sr_info.srlb.lower) = htons(0);
TLV_LEN(OspfRI.sr_info.srlb.lower) = htons(0);
}
/* Set Maximum Stack Depth for this router */
static void set_sr_node_msd(uint8_t msd)
{
TLV_TYPE(OspfRI.sr_info.msd) = htons(RI_SR_TLV_NODE_MSD);
TLV_LEN(OspfRI.sr_info.msd) = htons(sizeof(uint32_t));
OspfRI.sr_info.msd.value = msd;
}
/* Unset this router MSD */
static void unset_sr_node_msd(void)
{
TLV_TYPE(OspfRI.sr_info.msd) = htons(0);
TLV_LEN(OspfRI.sr_info.msd) = htons(0);
}
static void unset_param(void *tlv_buffer)
{
struct tlv_header *tlv = (struct tlv_header *)tlv_buffer;
tlv->type = 0;
/* Fill the Value to 0 */
memset(TLV_DATA(tlv_buffer), 0, TLV_BODY_SIZE(tlv));
tlv->length = 0;
return;
}
static void initialize_params(struct ospf_router_info *ori)
{
uint32_t cap = 0;
struct ospf *top;
struct listnode *node, *nnode;
struct ospf_area *area;
struct ospf_ri_area_info *new;
/*
* Initialize default Router Information Capabilities.
*/
cap = RI_TE_SUPPORT;
set_router_info_capabilities(&ori->router_cap, cap);
/* If Area address is not null and exist, retrieve corresponding
* structure */
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
zlog_info("RI (%s): Initialize Router Info for %s scope", __func__,
OspfRI.scope == OSPF_OPAQUE_AREA_LSA ? "Area" : "AS");
/* Try to get available Area's context from ospf at this step.
* Do it latter if not available */
if (OspfRI.scope == OSPF_OPAQUE_AREA_LSA) {
if (!list_isempty(OspfRI.area_info))
list_delete_all_node(OspfRI.area_info);
for (ALL_LIST_ELEMENTS(top->areas, node, nnode, area)) {
zlog_debug("RI (%s): Add area %pI4 to Router Information",
__func__, &area->area_id);
new = XCALLOC(MTYPE_OSPF_ROUTER_INFO,
sizeof(struct ospf_ri_area_info));
new->area = area;
new->flags = RIFLG_LSA_INACTIVE;
listnode_add(OspfRI.area_info, new);
}
}
/*
* Initialize default PCE Information values
*/
/* PCE address == OSPF Router ID */
set_pce_address(top->router_id, &ori->pce_info);
/* PCE scope */
cap = 7; /* Set L, R and Rd bits to one = intra & inter-area path
computation */
set_pce_path_scope(cap, &ori->pce_info);
/* PCE Capabilities */
cap = PCE_CAP_BIDIRECTIONAL | PCE_CAP_DIVERSE_PATH | PCE_CAP_OBJECTIVES
| PCE_CAP_ADDITIVE | PCE_CAP_MULTIPLE_REQ;
set_pce_cap_flag(cap, &ori->pce_info);
return;
}
static int is_mandated_params_set(struct ospf_router_info *ori)
{
int rc = 0;
if (ori == NULL)
return rc;
if (ntohs(ori->router_cap.header.type) == 0)
return rc;
if ((ntohs(ori->pce_info.pce_header.header.type) == RI_TLV_PCE)
&& (ntohs(ori->pce_info.pce_address.header.type) == 0)
&& (ntohs(ori->pce_info.pce_cap_flag.header.type) == 0))
return rc;
if ((ori->sr_info.enabled) && (ntohs(TLV_TYPE(ori->sr_info.algo)) == 0)
&& (ntohs(TLV_TYPE(ori->sr_info.srgb)) == 0))
return rc;
rc = 1;
return rc;
}
/*
* Used by Segment Routing to set new TLVs and Sub-TLVs values
*
* @param enable To activate or not Segment Routing router Information flooding
* @param srn Self Segment Routing node
*
* @return none
*/
void ospf_router_info_update_sr(bool enable, struct sr_node *srn)
{
struct listnode *node, *nnode;
struct ospf_ri_area_info *ai;
/* First, check if Router Information is registered or not */
if (!OspfRI.registered)
ospf_router_info_register(OSPF_OPAQUE_AREA_LSA);
/* Verify that scope is AREA */
if (OspfRI.scope != OSPF_OPAQUE_AREA_LSA) {
zlog_err(
"RI (%s): Router Info is %s flooding: Change scope to Area flooding for Segment Routing",
__func__,
OspfRI.scope == OSPF_OPAQUE_AREA_LSA ? "Area" : "AS");
return;
}
/* Then, activate and initialize Router Information if necessary */
if (!OspfRI.enabled) {
OspfRI.enabled = true;
initialize_params(&OspfRI);
}
/* Check that SR node is valid */
if (srn == NULL)
return;
if (IS_DEBUG_OSPF_SR)
zlog_debug("RI (%s): %s Routing Information for Segment Routing",
__func__, enable ? "Enable" : "Disable");
/* Unset or Set SR parameters */
if (!enable) {
unset_sr_algorithm(SR_ALGORITHM_SPF);
unset_sr_global_label_range();
unset_sr_local_label_range();
unset_sr_node_msd();
OspfRI.sr_info.enabled = false;
} else {
// Only SR_ALGORITHM_SPF is supported
set_sr_algorithm(SR_ALGORITHM_SPF);
set_sr_global_label_range(srn->srgb);
set_sr_local_label_range(srn->srlb);
if (srn->msd != 0)
set_sr_node_msd(srn->msd);
else
unset_sr_node_msd();
OspfRI.sr_info.enabled = true;
}
/* Refresh if already engaged or originate RI LSA */
for (ALL_LIST_ELEMENTS(OspfRI.area_info, node, nnode, ai)) {
if (CHECK_FLAG(ai->flags, RIFLG_LSA_ENGAGED))
ospf_router_info_lsa_schedule(ai, REFRESH_THIS_LSA);
else
ospf_router_info_lsa_schedule(ai,
REORIGINATE_THIS_LSA);
}
}
/*------------------------------------------------------------------------*
* Following are callback functions against generic Opaque-LSAs handling.
*------------------------------------------------------------------------*/
static void ospf_router_info_ism_change(struct ospf_interface *oi,
int old_state)
{
struct ospf_ri_area_info *ai;
/* Collect area information */
ai = lookup_by_area(oi->area);
/* Check if area is not yet registered */
if (ai != NULL)
return;
/* Add this new area to the list */
ai = XCALLOC(MTYPE_OSPF_ROUTER_INFO, sizeof(struct ospf_ri_area_info));
ai->area = oi->area;
ai->flags = RIFLG_LSA_INACTIVE;
listnode_add(OspfRI.area_info, ai);
return;
}
/*------------------------------------------------------------------------*
* Following are OSPF protocol processing functions for ROUTER INFORMATION
*------------------------------------------------------------------------*/
static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
{
stream_put(s, tlvh, sizeof(struct tlv_header));
return;
}
static void build_tlv(struct stream *s, struct tlv_header *tlvh)
{
if (ntohs(tlvh->type) != 0) {
build_tlv_header(s, tlvh);
stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
}
return;
}
static void ospf_router_info_lsa_body_set(struct stream *s)
{
struct listnode *node;
struct ri_pce_subtlv_domain *domain;
struct ri_pce_subtlv_neighbor *neighbor;
/* Build Router Information TLV */
build_tlv(s, &OspfRI.router_cap.header);
/* Build Segment Routing TLVs if enabled */
if (OspfRI.sr_info.enabled) {
/* Build Algorithm TLV */
build_tlv(s, &TLV_HDR(OspfRI.sr_info.algo));
/* Build SRGB TLV */
build_tlv(s, &TLV_HDR(OspfRI.sr_info.srgb));
/* Build SRLB TLV */
build_tlv(s, &TLV_HDR(OspfRI.sr_info.srlb));
/* Build MSD TLV */
build_tlv(s, &TLV_HDR(OspfRI.sr_info.msd));
}
/* Add RI PCE TLV if it is set */
if (OspfRI.pce_info.enabled) {
/* Compute PCE Info header first */
set_pce_header(&OspfRI.pce_info);
/* Build PCE TLV */
build_tlv_header(s, &OspfRI.pce_info.pce_header.header);
/* Build PCE address sub-tlv */
build_tlv(s, &OspfRI.pce_info.pce_address.header);
/* Build PCE path scope sub-tlv */
build_tlv(s, &OspfRI.pce_info.pce_scope.header);
/* Build PCE domain sub-tlv */
for (ALL_LIST_ELEMENTS_RO(OspfRI.pce_info.pce_domain, node,
domain))
build_tlv(s, &domain->header);
/* Build PCE neighbor sub-tlv */
for (ALL_LIST_ELEMENTS_RO(OspfRI.pce_info.pce_neighbor, node,
neighbor))
build_tlv(s, &neighbor->header);
/* Build PCE cap flag sub-tlv */
build_tlv(s, &OspfRI.pce_info.pce_cap_flag.header);
}
return;
}
/* Create new opaque-LSA. */
static struct ospf_lsa *ospf_router_info_lsa_new(struct ospf_area *area)
{
struct ospf *top;
struct stream *s;
struct lsa_header *lsah;
struct ospf_lsa *new = NULL;
uint8_t options, lsa_type;
struct in_addr lsa_id;
uint32_t tmp;
uint16_t length;
/* Create a stream for LSA. */
s = stream_new(OSPF_MAX_LSA_SIZE);
lsah = (struct lsa_header *)STREAM_DATA(s);
options = OSPF_OPTION_E; /* Enable AS external as we flood RI with
Opaque Type 11 */
options |= OSPF_OPTION_O; /* Don't forget this :-) */
lsa_type = OspfRI.scope;
/* LSA ID == 0 for Router Information see RFC 4970 */
tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_ROUTER_INFORMATION_LSA, 0);
lsa_id.s_addr = htonl(tmp);
if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
zlog_debug(
"LSA[Type%d:%pI4]: Create an Opaque-LSA/ROUTER INFORMATION instance",
lsa_type, &lsa_id);
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Set opaque-LSA header fields. */
lsa_header_set(s, options, lsa_type, lsa_id, top->router_id);
/* Set opaque-LSA body fields. */
ospf_router_info_lsa_body_set(s);
/* Set length. */
length = stream_get_endp(s);
lsah->length = htons(length);
/* Now, create an OSPF LSA instance. */
new = ospf_lsa_new_and_data(length);
new->area = area;
if (new->area && new->area->ospf)
new->vrf_id = new->area->ospf->vrf_id;
else
new->vrf_id = VRF_DEFAULT;
SET_FLAG(new->flags, OSPF_LSA_SELF);
memcpy(new->data, lsah, length);
stream_free(s);
return new;
}
static int ospf_router_info_lsa_originate_as(void *arg)
{
struct ospf_lsa *new;
struct ospf *top;
int rc = -1;
vrf_id_t vrf_id = VRF_DEFAULT;
/* Sanity Check */
if (OspfRI.scope == OSPF_OPAQUE_AREA_LSA) {
flog_warn(
EC_OSPF_LSA_INSTALL_FAILURE,
"RI (%s): wrong flooding scope AREA instead of AS ?",
__func__);
return rc;
}
/* Create new Opaque-LSA/ROUTER INFORMATION instance. */
new = ospf_router_info_lsa_new(NULL);
new->vrf_id = VRF_DEFAULT;
top = (struct ospf *)arg;
/* Check ospf info */
if (top == NULL) {
zlog_debug("RI (%s): ospf instance not found for vrf id %u",
__func__, vrf_id);
ospf_lsa_unlock(&new);
return rc;
}
/* Install this LSA into LSDB. */
if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
flog_warn(
EC_OSPF_LSA_INSTALL_FAILURE,
"RI (%s): ospf_lsa_install() ?", __func__);
ospf_lsa_unlock(&new);
return rc;
}
/* Update new LSA origination count. */
top->lsa_originate_count++;
/* Flood new LSA through AREA or AS. */
SET_FLAG(OspfRI.as_flags, RIFLG_LSA_ENGAGED);
ospf_flood_through_as(top, NULL /*nbr */, new);
if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
zlog_debug(
"LSA[Type%d:%pI4]: Originate Opaque-LSA/ROUTER INFORMATION",
new->data->type, &new->data->id);
ospf_lsa_header_dump(new->data);
}
rc = 0;
return rc;
}
static int ospf_router_info_lsa_originate_area(void *arg)
{
struct ospf_lsa *new;
struct ospf *top;
struct ospf_ri_area_info *ai = NULL;
int rc = -1;
vrf_id_t vrf_id = VRF_DEFAULT;
/* Sanity Check */
if (OspfRI.scope == OSPF_OPAQUE_AS_LSA) {
flog_warn(
EC_OSPF_LSA_INSTALL_FAILURE,
"RI (%s): wrong flooding scope AS instead of AREA ?",
__func__);
return rc;
}
/* Create new Opaque-LSA/ROUTER INFORMATION instance. */
ai = lookup_by_area((struct ospf_area *)arg);
if (ai == NULL) {
zlog_debug(
"RI (%s): There is no context for this Router Information. Stop processing",
__func__);
return rc;
}
if (ai->area->ospf) {
vrf_id = ai->area->ospf->vrf_id;
top = ai->area->ospf;
} else {
top = ospf_lookup_by_vrf_id(vrf_id);
}
new = ospf_router_info_lsa_new(ai->area);
new->vrf_id = vrf_id;
/* Check ospf info */
if (top == NULL) {
zlog_debug("RI (%s): ospf instance not found for vrf id %u",
__func__, vrf_id);
ospf_lsa_unlock(&new);
return rc;
}
/* Install this LSA into LSDB. */
if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
flog_warn(
EC_OSPF_LSA_INSTALL_FAILURE,
"RI (%s): ospf_lsa_install() ?", __func__);
ospf_lsa_unlock(&new);
return rc;
}
/* Update new LSA origination count. */
top->lsa_originate_count++;
/* Flood new LSA through AREA or AS. */
SET_FLAG(ai->flags, RIFLG_LSA_ENGAGED);
ospf_flood_through_area(ai->area, NULL /*nbr */, new);
if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
zlog_debug(
"LSA[Type%d:%pI4]: Originate Opaque-LSA/ROUTER INFORMATION",
new->data->type, &new->data->id);
ospf_lsa_header_dump(new->data);
}
rc = 0;
return rc;
}
static int ospf_router_info_lsa_originate(void *arg)
{
struct ospf_ri_area_info *ai;
int rc = -1;
if (!OspfRI.enabled) {
zlog_info("RI (%s): ROUTER INFORMATION is disabled now.",
__func__);
rc = 0; /* This is not an error case. */
return rc;
}
/* Check if Router Information LSA is already engaged */
if (OspfRI.scope == OSPF_OPAQUE_AS_LSA) {
if ((CHECK_FLAG(OspfRI.as_flags, RIFLG_LSA_ENGAGED))
&& (CHECK_FLAG(OspfRI.as_flags,
RIFLG_LSA_FORCED_REFRESH))) {
UNSET_FLAG(OspfRI.as_flags, RIFLG_LSA_FORCED_REFRESH);
ospf_router_info_lsa_schedule(NULL, REFRESH_THIS_LSA);
rc = 0;
return rc;
}
} else {
ai = lookup_by_area((struct ospf_area *)arg);
if (ai == NULL) {
flog_warn(
EC_OSPF_LSA,
"RI (%s): Missing area information", __func__);
return rc;
}
if ((CHECK_FLAG(ai->flags, RIFLG_LSA_ENGAGED))
&& (CHECK_FLAG(ai->flags, RIFLG_LSA_FORCED_REFRESH))) {
UNSET_FLAG(ai->flags, RIFLG_LSA_FORCED_REFRESH);
ospf_router_info_lsa_schedule(ai, REFRESH_THIS_LSA);
rc = 0;
return rc;
}
}
/* Router Information is not yet Engaged, check parameters */
if (!is_mandated_params_set(&OspfRI))
flog_warn(
EC_OSPF_LSA,
"RI (%s): lacks mandated ROUTER INFORMATION parameters",
__func__);