forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathospf6_asbr.c
3776 lines (3153 loc) · 98.5 KB
/
ospf6_asbr.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
/*
* Copyright (C) 2003 Yasuhiro Ohara
*/
#include <zebra.h>
#include "log.h"
#include "memory.h"
#include "prefix.h"
#include "command.h"
#include "vty.h"
#include "routemap.h"
#include "table.h"
#include "plist.h"
#include "frrevent.h"
#include "frrstr.h"
#include "linklist.h"
#include "lib/northbound_cli.h"
#include "ospf6_proto.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"
#include "ospf6_route.h"
#include "ospf6_zebra.h"
#include "ospf6_message.h"
#include "ospf6_spf.h"
#include "ospf6_top.h"
#include "ospf6d.h"
#include "ospf6_area.h"
#include "ospf6_interface.h"
#include "ospf6_neighbor.h"
#include "ospf6_asbr.h"
#include "ospf6_abr.h"
#include "ospf6_intra.h"
#include "ospf6_flood.h"
#include "ospf6_nssa.h"
#include "ospf6d.h"
#include "ospf6_spf.h"
#include "ospf6_nssa.h"
#include "ospf6_gr.h"
#include "lib/json.h"
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_EXTERNAL_INFO, "OSPF6 ext. info");
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_DIST_ARGS, "OSPF6 Distribute arguments");
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_REDISTRIBUTE, "OSPF6 Redistribute arguments");
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_EXTERNAL_RT_AGGR, "OSPF6 ASBR Summarisation");
static void ospf6_asbr_redistribute_set(struct ospf6 *ospf6, int type);
static void ospf6_asbr_redistribute_unset(struct ospf6 *ospf6,
struct ospf6_redist *red, int type);
#include "ospf6d/ospf6_asbr_clippy.c"
unsigned char conf_debug_ospf6_asbr = 0;
#define ZROUTE_NAME(x) zebra_route_string(x)
/* Originate Type-5 and Type-7 LSA */
static struct ospf6_lsa *ospf6_originate_type5_type7_lsas(
struct ospf6_route *route,
struct ospf6 *ospf6)
{
struct ospf6_lsa *lsa;
struct listnode *lnode;
struct ospf6_area *oa = NULL;
lsa = ospf6_as_external_lsa_originate(route, ospf6);
for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, lnode, oa)) {
if (IS_AREA_NSSA(oa))
ospf6_nssa_lsa_originate(route, oa, true);
}
return lsa;
}
/* AS External LSA origination */
struct ospf6_lsa *ospf6_as_external_lsa_originate(struct ospf6_route *route,
struct ospf6 *ospf6)
{
char buffer[OSPF6_MAX_LSASIZE];
struct ospf6_lsa_header *lsa_header;
struct ospf6_lsa *lsa;
struct ospf6_external_info *info = route->route_option;
struct ospf6_as_external_lsa *as_external_lsa;
caddr_t p;
if (ospf6->gr_info.restart_in_progress) {
if (IS_DEBUG_OSPF6_GR)
zlog_debug(
"Graceful Restart in progress, don't originate LSA");
return NULL;
}
if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE(AS_EXTERNAL))
zlog_debug("Originate AS-External-LSA for %pFX",
&route->prefix);
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
as_external_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa_header);
p = (caddr_t)((caddr_t)as_external_lsa
+ sizeof(struct ospf6_as_external_lsa));
/* Fill AS-External-LSA */
/* Metric type */
if (route->path.metric_type == 2)
SET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
else
UNSET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
/* forwarding address */
if (!IN6_IS_ADDR_UNSPECIFIED(&info->forwarding))
SET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
else
UNSET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
/* external route tag */
if (info->tag)
SET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
else
UNSET_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
/* Set metric */
OSPF6_ASBR_METRIC_SET(as_external_lsa, route->path.cost);
/* prefixlen */
as_external_lsa->prefix.prefix_length = route->prefix.prefixlen;
/* PrefixOptions */
as_external_lsa->prefix.prefix_options = route->prefix_options;
/* don't use refer LS-type */
as_external_lsa->prefix.prefix_refer_lstype = htons(0);
/* set Prefix */
memcpy(p, &route->prefix.u.prefix6,
OSPF6_PREFIX_SPACE(route->prefix.prefixlen));
ospf6_prefix_apply_mask(&as_external_lsa->prefix);
p += OSPF6_PREFIX_SPACE(route->prefix.prefixlen);
/* Forwarding address */
if (CHECK_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F)) {
memcpy(p, &info->forwarding, sizeof(struct in6_addr));
p += sizeof(struct in6_addr);
}
/* External Route Tag */
if (CHECK_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T)) {
route_tag_t network_order = htonl(info->tag);
memcpy(p, &network_order, sizeof(network_order));
p += sizeof(network_order);
}
/* Fill LSA Header */
lsa_header->age = 0;
lsa_header->type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
lsa_header->id = route->path.origin.id;
lsa_header->adv_router = ospf6->router_id;
lsa_header->seqnum =
ospf6_new_ls_seqnum(lsa_header->type, lsa_header->id,
lsa_header->adv_router, ospf6->lsdb);
lsa_header->length = htons((caddr_t)p - (caddr_t)lsa_header);
/* LSA checksum */
ospf6_lsa_checksum(lsa_header);
/* create LSA */
lsa = ospf6_lsa_create(lsa_header);
/* Originate */
ospf6_lsa_originate_process(lsa, ospf6);
return lsa;
}
void ospf6_orig_as_external_lsa(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_lsa *lsa;
uint32_t type, adv_router;
oi = (struct ospf6_interface *)EVENT_ARG(thread);
if (oi->state == OSPF6_INTERFACE_DOWN)
return;
if (IS_AREA_NSSA(oi->area) || IS_AREA_STUB(oi->area))
return;
type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
adv_router = oi->area->ospf6->router_id;
for (ALL_LSDB_TYPED_ADVRTR(oi->area->ospf6->lsdb, type, adv_router,
lsa)) {
if (IS_OSPF6_DEBUG_ASBR)
zlog_debug(
"%s: Send update of AS-External LSA %s seq 0x%x",
__func__, lsa->name,
ntohl(lsa->header->seqnum));
ospf6_flood_interface(NULL, lsa, oi);
}
}
static route_tag_t ospf6_as_external_lsa_get_tag(struct ospf6_lsa *lsa)
{
struct ospf6_as_external_lsa *external;
ptrdiff_t tag_offset;
route_tag_t network_order;
if (!lsa)
return 0;
external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (!CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T))
return 0;
tag_offset = sizeof(*external)
+ OSPF6_PREFIX_SPACE(external->prefix.prefix_length);
if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F))
tag_offset += sizeof(struct in6_addr);
memcpy(&network_order, (caddr_t)external + tag_offset,
sizeof(network_order));
return ntohl(network_order);
}
void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old,
struct ospf6_route *route,
struct ospf6 *ospf6)
{
struct ospf6_route *old_route, *next_route;
struct ospf6_path *ecmp_path, *o_path = NULL;
struct listnode *anode, *anext;
struct listnode *nnode, *rnode, *rnext;
struct ospf6_nexthop *nh, *rnh;
bool route_found = false;
/* check for old entry match with new route origin,
* delete old entry.
*/
for (old_route = old; old_route; old_route = next_route) {
bool route_updated = false;
next_route = old_route->next;
/* The route linked-list is grouped in batches of prefix.
* If the new prefix is not the same as the one of interest
* then we have walked over the end of the batch and so we
* should break rather than continuing unnecessarily.
*/
if (!ospf6_route_is_same(old_route, route))
break;
if (old_route->path.type != route->path.type)
continue;
/* Current and New route has same origin,
* delete old entry.
*/
for (ALL_LIST_ELEMENTS(old_route->paths, anode, anext,
o_path)) {
/* Check old route path and route has same
* origin.
*/
if (o_path->area_id != route->path.area_id
|| !ospf6_ls_origin_same(o_path, &route->path))
continue;
/* Cost is not same then delete current path */
if ((o_path->cost == route->path.cost)
&& (o_path->u.cost_e2 == route->path.u.cost_e2))
continue;
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
zlog_debug(
"%s: route %pFX cost old %u new %u is not same, replace route",
__func__, &old_route->prefix, o_path->cost,
route->path.cost);
}
/* Remove selected current rout path's nh from
* effective nh list.
*/
for (ALL_LIST_ELEMENTS_RO(o_path->nh_list, nnode, nh)) {
for (ALL_LIST_ELEMENTS(old_route->nh_list,
rnode, rnext, rnh)) {
if (!ospf6_nexthop_is_same(rnh, nh))
continue;
listnode_delete(old_route->nh_list,
rnh);
ospf6_nexthop_delete(rnh);
}
}
listnode_delete(old_route->paths, o_path);
ospf6_path_free(o_path);
route_updated = true;
/* Current route's path (adv_router info) is similar
* to route being added.
* Replace current route's path with paths list head.
* Update FIB with effective NHs.
*/
if (listcount(old_route->paths)) {
for (ALL_LIST_ELEMENTS(old_route->paths,
anode, anext, o_path)) {
ospf6_merge_nexthops(
old_route->nh_list,
o_path->nh_list);
}
/* Update RIB/FIB with effective
* nh_list
*/
if (ospf6->route_table->hook_add)
(*ospf6->route_table->hook_add)(
old_route);
if (old_route->path.origin.id
== route->path.origin.id
&& old_route->path.origin.adv_router
== route->path.origin
.adv_router) {
struct ospf6_path *h_path;
h_path = (struct ospf6_path *)
listgetdata(listhead(
old_route->paths));
old_route->path.origin.type =
h_path->origin.type;
old_route->path.origin.id =
h_path->origin.id;
old_route->path.origin.adv_router =
h_path->origin.adv_router;
}
} else {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
zlog_debug(
"%s: route %pFX old cost %u new cost %u, delete old entry.",
__func__, &old_route->prefix,
old_route->path.cost,
route->path.cost);
}
if (old == old_route)
old = next_route;
ospf6_route_remove(old_route,
ospf6->route_table);
}
}
if (route_updated)
break;
}
/* Add new route */
for (old_route = old; old_route; old_route = old_route->next) {
/* The route linked-list is grouped in batches of prefix.
* If the new prefix is not the same as the one of interest
* then we have walked over the end of the batch and so we
* should break rather than continuing unnecessarily.
*/
if (!ospf6_route_is_same(old_route, route))
break;
if (old_route->path.type != route->path.type)
continue;
/* Old Route and New Route have Equal Cost, Merge NHs */
if ((old_route->path.cost == route->path.cost)
&& (old_route->path.u.cost_e2 == route->path.u.cost_e2)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
zlog_debug(
"%s: old route %pFX path cost %u e2 %u",
__func__, &old_route->prefix,
old_route->path.cost,
old_route->path.u.cost_e2);
}
route_found = true;
/* check if this path exists already in
* route->paths list, if so, replace nh_list
* from asbr_entry.
*/
for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode,
o_path)) {
if (o_path->area_id == route->path.area_id
&& ospf6_ls_origin_same(o_path, &route->path))
break;
}
/* If path is not found in old_route paths's list,
* add a new path to route paths list and merge
* nexthops in route->path->nh_list.
* Otherwise replace existing path's nh_list.
*/
if (o_path == NULL) {
ecmp_path = ospf6_path_dup(&route->path);
/* Add a nh_list to new ecmp path */
ospf6_copy_nexthops(ecmp_path->nh_list,
route->nh_list);
/* Add the new path to route's path list */
listnode_add_sort(old_route->paths, ecmp_path);
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
zlog_debug(
"%s: route %pFX another path added with nh %u, effective paths %u nh %u",
__func__, &route->prefix,
listcount(ecmp_path->nh_list),
old_route->paths ? listcount(
old_route->paths)
: 0,
listcount(old_route->nh_list));
}
} else {
list_delete_all_node(o_path->nh_list);
ospf6_copy_nexthops(o_path->nh_list,
route->nh_list);
}
/* Reset nexthop lists, rebuild from brouter table
* for each adv. router.
*/
list_delete_all_node(old_route->nh_list);
for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode,
o_path)) {
struct ospf6_route *asbr_entry;
asbr_entry = ospf6_route_lookup(
&o_path->ls_prefix,
ospf6->brouter_table);
if (asbr_entry == NULL) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"%s: ls_prfix %pFX asbr_entry not found.",
__func__,
&old_route->prefix);
continue;
}
ospf6_route_merge_nexthops(old_route,
asbr_entry);
}
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"%s: route %pFX with effective paths %u nh %u",
__func__, &route->prefix,
old_route->paths
? listcount(old_route->paths)
: 0,
old_route->nh_list
? listcount(old_route->nh_list)
: 0);
/* Update RIB/FIB */
if (ospf6->route_table->hook_add)
(*ospf6->route_table->hook_add)(old_route);
/* Delete the new route its info added to existing
* route.
*/
ospf6_route_delete(route);
break;
}
}
if (!route_found) {
/* Add new route to existing node in ospf6 route table. */
ospf6_route_add(route, ospf6->route_table);
}
}
/* Check if the forwarding address is local address */
static int ospf6_ase_forward_address_check(struct ospf6 *ospf6,
struct in6_addr *fwd_addr)
{
struct listnode *anode, *node;
struct ospf6_interface *oi;
struct ospf6_area *oa;
struct interface *ifp;
struct connected *c;
for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, anode, oa)) {
for (ALL_LIST_ELEMENTS_RO(oa->if_list, node, oi)) {
if (!if_is_operative(oi->interface)
|| oi->type == OSPF_IFTYPE_VIRTUALLINK)
continue;
ifp = oi->interface;
frr_each (if_connected, ifp->connected, c) {
if (IPV6_ADDR_SAME(&c->address->u.prefix6,
fwd_addr))
return 0;
}
}
}
return 1;
}
void ospf6_asbr_lsa_add(struct ospf6_lsa *lsa)
{
struct ospf6_as_external_lsa *external;
struct prefix asbr_id;
struct ospf6_route *asbr_entry, *route, *old = NULL;
struct ospf6_path *path;
struct ospf6 *ospf6;
int type;
struct ospf6_area *oa = NULL;
struct prefix fwd_addr;
ptrdiff_t offset;
type = ntohs(lsa->header->type);
oa = lsa->lsdb->data;
external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("Calculate AS-External route for %s", lsa->name);
ospf6 = ospf6_get_by_lsdb(lsa);
if (lsa->header->adv_router == ospf6->router_id) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("Ignore self-originated AS-External-LSA");
return;
}
if (OSPF6_ASBR_METRIC(external) == OSPF_LS_INFINITY) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("Ignore LSA with LSInfinity Metric");
return;
}
if (CHECK_FLAG(external->prefix.prefix_options,
OSPF6_PREFIX_OPTION_NU)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("Ignore LSA with NU bit set Metric");
return;
}
ospf6_linkstate_prefix(lsa->header->adv_router, htonl(0), &asbr_id);
asbr_entry = ospf6_route_lookup(&asbr_id, ospf6->brouter_table);
if (asbr_entry == NULL) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("ASBR entry not found: %pFX", &asbr_id);
return;
} else {
/* The router advertising external LSA can be ASBR or ABR */
if (!CHECK_FLAG(asbr_entry->path.router_bits,
OSPF6_ROUTER_BIT_E)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"External bit reset ASBR route entry : %pFX",
&asbr_id);
return;
}
/*
* RFC 3101 - Section 2.5:
* "For a Type-7 LSA the matching routing table entry must
* specify an intra-area path through the LSA's originating
* NSSA".
*/
if (ntohs(lsa->header->type) == OSPF6_LSTYPE_TYPE_7
&& (asbr_entry->path.area_id != oa->area_id
|| asbr_entry->path.type != OSPF6_PATH_TYPE_INTRA)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"Intra-area route to NSSA ASBR not found: %pFX",
&asbr_id);
return;
}
}
/*
* RFC 3101 - Section 2.5:
* "If the destination is a Type-7 default route (destination ID =
* DefaultDestination) and one of the following is true, then do
* nothing with this LSA and consider the next in the list:
*
* o The calculating router is a border router and the LSA has
* its P-bit clear. Appendix E describes a technique
* whereby an NSSA border router installs a Type-7 default
* LSA without propagating it.
*
* o The calculating router is a border router and is
* suppressing the import of summary routes as Type-3
* summary-LSAs".
*/
if (ntohs(lsa->header->type) == OSPF6_LSTYPE_TYPE_7
&& external->prefix.prefix_length == 0
&& CHECK_FLAG(ospf6->flag, OSPF6_FLAG_ABR)
&& (CHECK_FLAG(external->prefix.prefix_options,
OSPF6_PREFIX_OPTION_P)
|| oa->no_summary)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("Skipping Type-7 default route");
return;
}
/* Check the forwarding address */
if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_F)) {
offset = sizeof(*external)
+ OSPF6_PREFIX_SPACE(external->prefix.prefix_length);
memset(&fwd_addr, 0, sizeof(fwd_addr));
fwd_addr.family = AF_INET6;
fwd_addr.prefixlen = IPV6_MAX_BITLEN;
memcpy(&fwd_addr.u.prefix6, (caddr_t)external + offset,
sizeof(struct in6_addr));
if (!IN6_IS_ADDR_UNSPECIFIED(&fwd_addr.u.prefix6)) {
if (!ospf6_ase_forward_address_check(
ospf6, &fwd_addr.u.prefix6)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"Fwd address %pFX is local address",
&fwd_addr);
return;
}
/* Find the forwarding entry */
asbr_entry = ospf6_route_lookup_bestmatch(
&fwd_addr, ospf6->route_table);
if (asbr_entry == NULL) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"Fwd address not found: %pFX",
&fwd_addr);
return;
}
}
}
route = ospf6_route_create(ospf6);
route->type = OSPF6_DEST_TYPE_NETWORK;
route->prefix.family = AF_INET6;
route->prefix.prefixlen = external->prefix.prefix_length;
ospf6_prefix_in6_addr(&route->prefix.u.prefix6, external,
&external->prefix);
route->prefix_options = external->prefix.prefix_options;
route->path.area_id = asbr_entry->path.area_id;
route->path.origin.type = lsa->header->type;
route->path.origin.id = lsa->header->id;
route->path.origin.adv_router = lsa->header->adv_router;
memcpy(&route->path.ls_prefix, &asbr_id, sizeof(struct prefix));
if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_E)) {
route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
route->path.metric_type = 2;
route->path.cost = asbr_entry->path.cost;
route->path.u.cost_e2 = OSPF6_ASBR_METRIC(external);
} else {
route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
route->path.metric_type = 1;
route->path.cost =
asbr_entry->path.cost + OSPF6_ASBR_METRIC(external);
route->path.u.cost_e2 = 0;
}
route->path.tag = ospf6_as_external_lsa_get_tag(lsa);
ospf6_route_copy_nexthops(route, asbr_entry);
path = ospf6_path_dup(&route->path);
ospf6_copy_nexthops(path->nh_list, asbr_entry->nh_list);
listnode_add_sort(route->paths, path);
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug(
"%s: %s %u route add %pFX cost %u(%u) nh %u", __func__,
(type == OSPF6_LSTYPE_AS_EXTERNAL) ? "AS-External"
: "NSSA",
(route->path.type == OSPF6_PATH_TYPE_EXTERNAL1) ? 1 : 2,
&route->prefix, route->path.cost, route->path.u.cost_e2,
listcount(route->nh_list));
if (type == OSPF6_LSTYPE_AS_EXTERNAL)
old = ospf6_route_lookup(&route->prefix, ospf6->route_table);
else if (type == OSPF6_LSTYPE_TYPE_7)
old = ospf6_route_lookup(&route->prefix, oa->route_table);
if (!old) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("%s: Adding new route", __func__);
/* Add the new route to ospf6 instance route table. */
if (type == OSPF6_LSTYPE_AS_EXTERNAL)
ospf6_route_add(route, ospf6->route_table);
/* Add the route to the area route table */
else if (type == OSPF6_LSTYPE_TYPE_7) {
ospf6_route_add(route, oa->route_table);
}
} else {
/* RFC 2328 16.4 (6)
* ECMP: Keep new equal preference path in current
* route's path list, update zebra with new effective
* list along with addition of ECMP path.
*/
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
zlog_debug("%s : old route %pFX cost %u(%u) nh %u",
__func__, &route->prefix, route->path.cost,
route->path.u.cost_e2,
listcount(route->nh_list));
ospf6_asbr_update_route_ecmp_path(old, route, ospf6);
}
}
void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
struct ospf6_route *asbr_entry)
{
struct ospf6_as_external_lsa *external;
struct prefix prefix;
struct ospf6_route *route, *nroute, *route_to_del;
struct ospf6_area *oa = NULL;
struct ospf6 *ospf6;
int type;
bool debug = false;
external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL) || (IS_OSPF6_DEBUG_NSSA))
debug = true;
ospf6 = ospf6_get_by_lsdb(lsa);
type = ntohs(lsa->header->type);
if (type == OSPF6_LSTYPE_TYPE_7) {
if (debug)
zlog_debug("%s: Withdraw Type 7 route for %s",
__func__, lsa->name);
oa = lsa->lsdb->data;
} else {
if (debug)
zlog_debug("%s: Withdraw AS-External route for %s",
__func__, lsa->name);
if (ospf6_check_and_set_router_abr(ospf6))
oa = ospf6->backbone;
else
oa = listnode_head(ospf6->area_list);
}
if (oa == NULL) {
if (debug)
zlog_debug("%s: Invalid area", __func__);
return;
}
if (lsa->header->adv_router == oa->ospf6->router_id) {
if (debug)
zlog_debug("Ignore self-originated AS-External-LSA");
return;
}
route_to_del = ospf6_route_create(ospf6);
route_to_del->type = OSPF6_DEST_TYPE_NETWORK;
route_to_del->prefix.family = AF_INET6;
route_to_del->prefix.prefixlen = external->prefix.prefix_length;
ospf6_prefix_in6_addr(&route_to_del->prefix.u.prefix6, external,
&external->prefix);
route_to_del->path.origin.type = lsa->header->type;
route_to_del->path.origin.id = lsa->header->id;
route_to_del->path.origin.adv_router = lsa->header->adv_router;
if (asbr_entry) {
route_to_del->path.area_id = asbr_entry->path.area_id;
if (CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_E)) {
route_to_del->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
route_to_del->path.metric_type = 2;
route_to_del->path.cost = asbr_entry->path.cost;
route_to_del->path.u.cost_e2 =
OSPF6_ASBR_METRIC(external);
} else {
route_to_del->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
route_to_del->path.metric_type = 1;
route_to_del->path.cost = asbr_entry->path.cost
+ OSPF6_ASBR_METRIC(external);
route_to_del->path.u.cost_e2 = 0;
}
}
memset(&prefix, 0, sizeof(struct prefix));
prefix.family = AF_INET6;
prefix.prefixlen = external->prefix.prefix_length;
ospf6_prefix_in6_addr(&prefix.u.prefix6, external, &external->prefix);
if (type == OSPF6_LSTYPE_TYPE_7)
route = ospf6_route_lookup(&prefix, oa->route_table);
else
route = ospf6_route_lookup(&prefix, oa->ospf6->route_table);
if (route == NULL) {
if (debug)
zlog_debug("AS-External route %pFX not found", &prefix);
ospf6_route_delete(route_to_del);
return;
}
if (debug)
zlog_debug(
"%s: Current route %pFX cost %u e2 %u, route to del cost %u e2 %u",
__func__, &prefix, route->path.cost, route->path.u.cost_e2,
route_to_del->path.cost, route_to_del->path.u.cost_e2);
for (ospf6_route_lock(route);
route && ospf6_route_is_prefix(&prefix, route); route = nroute) {
nroute = ospf6_route_next(route);
if (route->type != OSPF6_DEST_TYPE_NETWORK)
continue;
/* Route has multiple ECMP paths, remove matching
* path. Update current route's effective nh list
* after removal of one of the path.
*/
if (listcount(route->paths) > 1) {
struct listnode *anode, *anext;
struct listnode *nnode, *rnode, *rnext;
struct ospf6_nexthop *nh, *rnh;
struct ospf6_path *o_path;
bool nh_updated = false;
/* Iterate all paths of route to find maching with LSA
* remove from route path list. If route->path is same,
* replace from paths list.
*/
for (ALL_LIST_ELEMENTS(route->paths, anode, anext,
o_path)) {
if ((o_path->origin.type != lsa->header->type)
|| (o_path->origin.adv_router
!= lsa->header->adv_router)
|| (o_path->origin.id != lsa->header->id))
continue;
/* Compare LSA cost with current
* route info.
*/
if (asbr_entry
&& (o_path->cost != route_to_del->path.cost
|| o_path->u.cost_e2
!= route_to_del->path.u
.cost_e2)) {
if (IS_OSPF6_DEBUG_EXAMIN(
AS_EXTERNAL)) {
zlog_debug(
"%s: route %pFX to delete is not same, cost %u del cost %u. skip",
__func__, &prefix,
route->path.cost,
route_to_del->path
.cost);
}
continue;
}
if (debug) {
zlog_debug(
"%s: route %pFX path found with cost %u nh %u to remove.",
__func__, &prefix, route->path.cost,
listcount(o_path->nh_list));
}
/* Remove found path's nh_list from
* the route's nh_list.
*/
for (ALL_LIST_ELEMENTS_RO(o_path->nh_list,
nnode, nh)) {
for (ALL_LIST_ELEMENTS(route->nh_list,
rnode, rnext,
rnh)) {
if (!ospf6_nexthop_is_same(rnh,
nh))
continue;
listnode_delete(route->nh_list,
rnh);
ospf6_nexthop_delete(rnh);
}
}
/* Delete the path from route's path list */
listnode_delete(route->paths, o_path);
ospf6_path_free(o_path);
nh_updated = true;
}
if (nh_updated) {
/* Iterate all paths and merge nexthop,
* unlesss any of the nexthop similar to
* ones deleted as part of path deletion.
*/
for (ALL_LIST_ELEMENTS(route->paths, anode,
anext, o_path)) {
ospf6_merge_nexthops(route->nh_list,
o_path->nh_list);
}
if (debug) {
zlog_debug(
"%s: AS-External %u route %pFX update paths %u nh %u",
__func__,
(route->path.type
== OSPF6_PATH_TYPE_EXTERNAL1)
? 1
: 2,
&route->prefix, listcount(route->paths),
route->nh_list ? listcount(
route->nh_list)
: 0);
}
if (listcount(route->paths)) {
/* Update RIB/FIB with effective
* nh_list
*/
if (oa->ospf6->route_table->hook_add)
(*oa->ospf6->route_table
->hook_add)(route);
/* route's primary path is similar
* to LSA, replace route's primary
* path with route's paths list head.
*/
if ((route->path.origin.id ==
lsa->header->id) &&
(route->path.origin.adv_router
== lsa->header->adv_router)) {
struct ospf6_path *h_path;
h_path = (struct ospf6_path *)
listgetdata(
listhead(route->paths));
route->path.origin.type =
h_path->origin.type;
route->path.origin.id =
h_path->origin.id;
route->path.origin.adv_router =
h_path->origin.adv_router;
}
} else {
if (type == OSPF6_LSTYPE_TYPE_7)
ospf6_route_remove(
route, oa->route_table);
else
ospf6_route_remove(
route,
oa->ospf6->route_table);
}
}
continue;
} else {
/* Compare LSA origin and cost with current route info.
* if any check fails skip del this route node.
*/
if (asbr_entry
&& (!ospf6_route_is_same_origin(route, route_to_del)
|| (route->path.type != route_to_del->path.type)
|| (route->path.cost != route_to_del->path.cost)
|| (route->path.u.cost_e2
!= route_to_del->path.u.cost_e2))) {
if (debug) {
zlog_debug(
"%s: route %pFX to delete is not same, cost %u del cost %u. skip",
__func__, &prefix, route->path.cost,
route_to_del->path.cost);
}
continue;
}
if ((route->path.origin.type != lsa->header->type)
|| (route->path.origin.adv_router
!= lsa->header->adv_router)
|| (route->path.origin.id != lsa->header->id))
continue;
}
if (debug) {
zlog_debug(
"%s: AS-External %u route remove %pFX cost %u(%u) nh %u",
__func__,
route->path.type == OSPF6_PATH_TYPE_EXTERNAL1
? 1
: 2,
&route->prefix, route->path.cost, route->path.u.cost_e2,
listcount(route->nh_list));
}
if (type == OSPF6_LSTYPE_TYPE_7)
ospf6_route_remove(route, oa->route_table);
else
ospf6_route_remove(route, oa->ospf6->route_table);
}