forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathospf_abr.c
1855 lines (1542 loc) · 47.4 KB
/
ospf_abr.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
/*
* OSPF ABR functions.
* Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada
*
* This file is part of GNU Zebra.
*
* 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 Zebra 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 "memory.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
#include "table.h"
#include "vty.h"
#include "filter.h"
#include "plist.h"
#include "log.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_spf.h"
#include "ospfd/ospf_route.h"
#include "ospfd/ospf_ia.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_abr.h"
#include "ospfd/ospf_ase.h"
#include "ospfd/ospf_zebra.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_errors.h"
static struct ospf_area_range *ospf_area_range_new(struct prefix_ipv4 *p)
{
struct ospf_area_range *range;
range = XCALLOC(MTYPE_OSPF_AREA_RANGE, sizeof(struct ospf_area_range));
range->addr = p->prefix;
range->masklen = p->prefixlen;
range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
return range;
}
static void ospf_area_range_free(struct ospf_area_range *range)
{
XFREE(MTYPE_OSPF_AREA_RANGE, range);
}
static void ospf_area_range_add(struct ospf_area *area,
struct ospf_area_range *range)
{
struct route_node *rn;
struct prefix_ipv4 p;
p.family = AF_INET;
p.prefixlen = range->masklen;
p.prefix = range->addr;
apply_mask_ipv4(&p);
rn = route_node_get(area->ranges, (struct prefix *)&p);
if (rn->info)
route_unlock_node(rn);
else
rn->info = range;
}
static void ospf_area_range_delete(struct ospf_area *area,
struct route_node *rn)
{
struct ospf_area_range *range = rn->info;
if (range->specifics != 0)
ospf_delete_discard_route(area->ospf, area->ospf->new_table,
(struct prefix_ipv4 *)&rn->p);
ospf_area_range_free(range);
rn->info = NULL;
route_unlock_node(rn);
route_unlock_node(rn);
}
struct ospf_area_range *ospf_area_range_lookup(struct ospf_area *area,
struct prefix_ipv4 *p)
{
struct route_node *rn;
rn = route_node_lookup(area->ranges, (struct prefix *)p);
if (rn) {
route_unlock_node(rn);
return rn->info;
}
return NULL;
}
struct ospf_area_range *ospf_area_range_lookup_next(struct ospf_area *area,
struct in_addr *range_net,
int first)
{
struct route_node *rn;
struct prefix_ipv4 p;
struct ospf_area_range *find;
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = *range_net;
apply_mask_ipv4(&p);
if (first)
rn = route_top(area->ranges);
else {
rn = route_node_get(area->ranges, (struct prefix *)&p);
rn = route_next(rn);
}
for (; rn; rn = route_next(rn))
if (rn->info)
break;
if (rn && rn->info) {
find = rn->info;
*range_net = rn->p.u.prefix4;
route_unlock_node(rn);
return find;
}
return NULL;
}
static struct ospf_area_range *ospf_area_range_match(struct ospf_area *area,
struct prefix_ipv4 *p)
{
struct route_node *node;
node = route_node_match(area->ranges, (struct prefix *)p);
if (node) {
route_unlock_node(node);
return node->info;
}
return NULL;
}
struct ospf_area_range *ospf_area_range_match_any(struct ospf *ospf,
struct prefix_ipv4 *p)
{
struct ospf_area_range *range;
struct ospf_area *area;
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
if ((range = ospf_area_range_match(area, p)))
return range;
return NULL;
}
int ospf_area_range_active(struct ospf_area_range *range)
{
return range->specifics;
}
static int ospf_area_actively_attached(struct ospf_area *area)
{
return area->act_ints;
}
int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id,
struct prefix_ipv4 *p, int advertise)
{
struct ospf_area *area;
struct ospf_area_range *range;
area = ospf_area_get(ospf, area_id);
if (area == NULL)
return 0;
range = ospf_area_range_lookup(area, p);
if (range != NULL) {
if (!CHECK_FLAG(advertise, OSPF_AREA_RANGE_ADVERTISE))
range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
if ((CHECK_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE)
&& !CHECK_FLAG(advertise, OSPF_AREA_RANGE_ADVERTISE))
|| (!CHECK_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE)
&& CHECK_FLAG(advertise, OSPF_AREA_RANGE_ADVERTISE)))
ospf_schedule_abr_task(ospf);
} else {
range = ospf_area_range_new(p);
ospf_area_range_add(area, range);
ospf_schedule_abr_task(ospf);
}
if (CHECK_FLAG(advertise, OSPF_AREA_RANGE_ADVERTISE))
SET_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE);
else {
UNSET_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE);
range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
}
return 1;
}
int ospf_area_range_cost_set(struct ospf *ospf, struct in_addr area_id,
struct prefix_ipv4 *p, uint32_t cost)
{
struct ospf_area *area;
struct ospf_area_range *range;
area = ospf_area_get(ospf, area_id);
if (area == NULL)
return 0;
range = ospf_area_range_lookup(area, p);
if (range == NULL)
return 0;
if (range->cost_config != cost) {
range->cost_config = cost;
if (ospf_area_range_active(range))
ospf_schedule_abr_task(ospf);
}
return 1;
}
int ospf_area_range_unset(struct ospf *ospf, struct in_addr area_id,
struct prefix_ipv4 *p)
{
struct ospf_area *area;
struct route_node *rn;
area = ospf_area_lookup_by_area_id(ospf, area_id);
if (area == NULL)
return 0;
rn = route_node_lookup(area->ranges, (struct prefix *)p);
if (rn == NULL)
return 0;
if (ospf_area_range_active(rn->info))
ospf_schedule_abr_task(ospf);
ospf_area_range_delete(area, rn);
return 1;
}
int ospf_area_range_substitute_set(struct ospf *ospf, struct in_addr area_id,
struct prefix_ipv4 *p, struct prefix_ipv4 *s)
{
struct ospf_area *area;
struct ospf_area_range *range;
area = ospf_area_get(ospf, area_id);
range = ospf_area_range_lookup(area, p);
if (range != NULL) {
if (!CHECK_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE)
|| !CHECK_FLAG(range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
ospf_schedule_abr_task(ospf);
} else {
range = ospf_area_range_new(p);
ospf_area_range_add(area, range);
ospf_schedule_abr_task(ospf);
}
SET_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE);
SET_FLAG(range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
range->subst_addr = s->prefix;
range->subst_masklen = s->prefixlen;
return 1;
}
int ospf_area_range_substitute_unset(struct ospf *ospf, struct in_addr area_id,
struct prefix_ipv4 *p)
{
struct ospf_area *area;
struct ospf_area_range *range;
area = ospf_area_lookup_by_area_id(ospf, area_id);
if (area == NULL)
return 0;
range = ospf_area_range_lookup(area, p);
if (range == NULL)
return 0;
if (CHECK_FLAG(range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
if (ospf_area_range_active(range))
ospf_schedule_abr_task(ospf);
UNSET_FLAG(range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
range->subst_addr.s_addr = INADDR_ANY;
range->subst_masklen = 0;
return 1;
}
int ospf_act_bb_connection(struct ospf *ospf)
{
struct ospf_interface *oi;
struct listnode *node;
int full_nbrs = 0;
if (ospf->backbone == NULL)
return 0;
for (ALL_LIST_ELEMENTS_RO(ospf->backbone->oiflist, node, oi)) {
struct ospf_neighbor *nbr;
struct route_node *rn;
for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
nbr = rn->info;
if (!nbr)
continue;
if (nbr->state == NSM_Full
|| OSPF_GR_IS_ACTIVE_HELPER(nbr))
full_nbrs++;
}
}
return full_nbrs;
}
/* Determine whether this router is elected translator or not for area */
static int ospf_abr_nssa_am_elected(struct ospf_area *area)
{
struct route_node *rn;
struct ospf_lsa *lsa;
struct router_lsa *rlsa;
struct in_addr *best = NULL;
char buf[PREFIX_STRLEN];
LSDB_LOOP (ROUTER_LSDB(area), rn, lsa) {
/* sanity checks */
if (!lsa || (lsa->data->type != OSPF_ROUTER_LSA)
|| IS_LSA_SELF(lsa))
continue;
rlsa = (struct router_lsa *)lsa->data;
/* ignore non-ABR routers */
if (!IS_ROUTER_LSA_BORDER(rlsa))
continue;
/* Router has Nt flag - always translate */
if (IS_ROUTER_LSA_NT(rlsa)) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_nssa_am_elected: router %pI4 asserts Nt",
&lsa->data->id);
return 0;
}
if (best == NULL)
best = &lsa->data->id;
else if (IPV4_ADDR_CMP(&best->s_addr, &lsa->data->id.s_addr)
< 0)
best = &lsa->data->id;
}
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_nssa_am_elected: best electable ABR is: %s",
(best) ? inet_ntop(AF_INET, best, buf, sizeof(buf)) :
"<none>");
if (best == NULL)
return 1;
if (IPV4_ADDR_CMP(&best->s_addr, &area->ospf->router_id.s_addr) < 0)
return 1;
else
return 0;
}
/* Check NSSA ABR status
* assumes there are nssa areas
*/
void ospf_abr_nssa_check_status(struct ospf *ospf)
{
struct ospf_area *area;
struct listnode *lnode, *nnode;
for (ALL_LIST_ELEMENTS(ospf->areas, lnode, nnode, area)) {
uint8_t old_state = area->NSSATranslatorState;
if (area->external_routing != OSPF_AREA_NSSA)
continue;
if (IS_DEBUG_OSPF(nssa, NSSA))
zlog_debug(
"ospf_abr_nssa_check_status: checking area %pI4",
&area->area_id);
if (!IS_OSPF_ABR(area->ospf)) {
if (IS_DEBUG_OSPF(nssa, NSSA))
zlog_debug(
"ospf_abr_nssa_check_status: not ABR");
area->NSSATranslatorState =
OSPF_NSSA_TRANSLATE_DISABLED;
} else {
switch (area->NSSATranslatorRole) {
case OSPF_NSSA_ROLE_NEVER:
/* We never Translate Type-7 LSA. */
/* TODO: check previous state and flush? */
if (IS_DEBUG_OSPF(nssa, NSSA))
zlog_debug(
"ospf_abr_nssa_check_status: never translate");
area->NSSATranslatorState =
OSPF_NSSA_TRANSLATE_DISABLED;
break;
case OSPF_NSSA_ROLE_ALWAYS:
/* We always translate if we are an ABR
* TODO: originate new LSAs if state change?
* or let the nssa abr task take care of it?
*/
if (IS_DEBUG_OSPF(nssa, NSSA))
zlog_debug(
"ospf_abr_nssa_check_status: translate always");
area->NSSATranslatorState =
OSPF_NSSA_TRANSLATE_ENABLED;
break;
case OSPF_NSSA_ROLE_CANDIDATE:
/* We are a candidate for Translation */
if (ospf_abr_nssa_am_elected(area) > 0) {
area->NSSATranslatorState =
OSPF_NSSA_TRANSLATE_ENABLED;
if (IS_DEBUG_OSPF(nssa, NSSA))
zlog_debug(
"ospf_abr_nssa_check_status: elected translator");
} else {
area->NSSATranslatorState =
OSPF_NSSA_TRANSLATE_DISABLED;
if (IS_DEBUG_OSPF(nssa, NSSA))
zlog_debug(
"ospf_abr_nssa_check_status: not elected");
}
break;
}
}
/* RFC3101, 3.1:
* All NSSA border routers must set the E-bit in the Type-1
* router-LSAs
* of their directly attached non-stub areas, even when they are
* not
* translating.
*/
if (old_state != area->NSSATranslatorState) {
if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
ospf_asbr_status_update(ospf,
++ospf->redistribute);
else if (area->NSSATranslatorState
== OSPF_NSSA_TRANSLATE_DISABLED)
ospf_asbr_status_update(ospf,
--ospf->redistribute);
}
}
}
/* Check area border router status. */
void ospf_check_abr_status(struct ospf *ospf)
{
struct ospf_area *area;
struct listnode *node, *nnode;
int bb_configured = 0;
int bb_act_attached = 0;
int areas_configured = 0;
int areas_act_attached = 0;
uint8_t new_flags = ospf->flags;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("ospf_check_abr_status(): Start");
for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) {
if (listcount(area->oiflist)) {
areas_configured++;
if (OSPF_IS_AREA_BACKBONE(area))
bb_configured = 1;
}
if (ospf_area_actively_attached(area)) {
areas_act_attached++;
if (OSPF_IS_AREA_BACKBONE(area))
bb_act_attached = 1;
}
}
if (IS_DEBUG_OSPF_EVENT) {
zlog_debug("ospf_check_abr_status(): looked through areas");
zlog_debug("ospf_check_abr_status(): bb_configured: %d",
bb_configured);
zlog_debug("ospf_check_abr_status(): bb_act_attached: %d",
bb_act_attached);
zlog_debug("ospf_check_abr_status(): areas_configured: %d",
areas_configured);
zlog_debug("ospf_check_abr_status(): areas_act_attached: %d",
areas_act_attached);
}
switch (ospf->abr_type) {
case OSPF_ABR_SHORTCUT:
case OSPF_ABR_STAND:
if (areas_act_attached > 1)
SET_FLAG(new_flags, OSPF_FLAG_ABR);
else
UNSET_FLAG(new_flags, OSPF_FLAG_ABR);
break;
case OSPF_ABR_IBM:
if ((areas_act_attached > 1) && bb_configured)
SET_FLAG(new_flags, OSPF_FLAG_ABR);
else
UNSET_FLAG(new_flags, OSPF_FLAG_ABR);
break;
case OSPF_ABR_CISCO:
if ((areas_configured > 1) && bb_act_attached)
SET_FLAG(new_flags, OSPF_FLAG_ABR);
else
UNSET_FLAG(new_flags, OSPF_FLAG_ABR);
break;
default:
break;
}
if (new_flags != ospf->flags) {
ospf_spf_calculate_schedule(ospf, SPF_FLAG_ABR_STATUS_CHANGE);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_check_abr_status(): new router flags: %x",
new_flags);
ospf->flags = new_flags;
ospf_router_lsa_update(ospf);
}
}
static void ospf_abr_update_aggregate(struct ospf_area_range *range,
struct ospf_route * or,
struct ospf_area *area)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("ospf_abr_update_aggregate(): Start");
if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)
&& (range->cost != OSPF_STUB_MAX_METRIC_SUMMARY_COST)) {
range->cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
range->cost);
} else if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_update_aggregate(): use configured cost %d",
range->cost_config);
range->cost = range->cost_config;
} else {
if (range->specifics == 0) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_update_aggregate(): use or->cost %d",
or->cost);
range->cost = or->cost; /* 1st time get 1st cost */
}
if (or->cost > range->cost) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_update_aggregate(): update to %d",
or->cost);
range->cost = or->cost;
}
}
range->specifics++;
}
static void set_metric(struct ospf_lsa *lsa, uint32_t metric)
{
struct summary_lsa *header;
uint8_t *mp;
metric = htonl(metric);
mp = (uint8_t *)&metric;
mp++;
header = (struct summary_lsa *)lsa->data;
memcpy(header->metric, mp, 3);
}
/* ospf_abr_translate_nssa */
static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa)
{
/* Incoming Type-7 or later aggregated Type-7
*
* LSA is skipped if P-bit is off.
* LSA is aggregated if within range.
*
* The Type-7 is translated, Installed/Approved as a Type-5 into
* global LSDB, then Flooded through AS
*
* Later, any Unapproved Translated Type-5's are flushed/discarded
*/
struct ospf_lsa *old = NULL, *new = NULL;
struct as_external_lsa *ext7;
struct prefix_ipv4 p;
if (!CHECK_FLAG(lsa->data->options, OSPF_OPTION_NP)) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): LSA Id %pI4, P-bit off, NO Translation",
&lsa->data->id);
return 1;
}
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): LSA Id %pI4, TRANSLATING 7 to 5",
&lsa->data->id);
ext7 = (struct as_external_lsa *)(lsa->data);
p.prefix = lsa->data->id;
p.prefixlen = ip_masklen(ext7->mask);
if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): LSA Id %pI4, Forward address is 0, NO Translation",
&lsa->data->id);
return 1;
}
/* try find existing AS-External LSA for this prefix */
old = ospf_external_info_find_lsa(area->ospf, &p);
if (CHECK_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE)) {
/* if type-7 is removed, remove old translated type-5 lsa */
if (old) {
UNSET_FLAG(old->flags, OSPF_LSA_APPROVED);
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): remove old translated LSA id %pI4",
&old->data->id);
}
/* if type-7 is removed and type-5 does not exist, do not
* originate */
return 1;
}
if (old && CHECK_FLAG(old->flags, OSPF_LSA_APPROVED)) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): found old translated LSA Id %pI4, refreshing",
&old->data->id);
/* refresh */
new = ospf_translated_nssa_refresh(area->ospf, lsa, old);
if (!new) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): could not refresh translated LSA Id %pI4",
&old->data->id);
}
} else {
/* no existing external route for this LSA Id
* originate translated LSA
*/
if (ospf_translated_nssa_originate(area->ospf, lsa, old)
== NULL) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_translate_nssa(): Could not translate Type-7 for %pI4 to Type-5",
&lsa->data->id);
return 1;
}
}
/* Area where Aggregate testing will be inserted, just like summary
advertisements */
/* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
return 0;
}
static void ospf_abr_translate_nssa_range(struct prefix_ipv4 *p, uint32_t cost)
{
/* The Type-7 is created from the aggregated prefix and forwarded
for lsa installation and flooding... to be added... */
}
void ospf_abr_announce_network_to_area(struct prefix_ipv4 *p, uint32_t cost,
struct ospf_area *area)
{
struct ospf_lsa *lsa, *old = NULL;
struct summary_lsa *sl = NULL;
uint32_t full_cost;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("ospf_abr_announce_network_to_area(): Start");
if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
full_cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
else
full_cost = cost;
old = ospf_lsa_lookup_by_prefix(area->lsdb, OSPF_SUMMARY_LSA, p,
area->ospf->router_id);
if (old) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network_to_area(): old summary found");
sl = (struct summary_lsa *)old->data;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network_to_area(): old metric: %d, new metric: %d",
GET_METRIC(sl->metric), cost);
if ((GET_METRIC(sl->metric) == full_cost)
&& ((old->flags & OSPF_LSA_IN_MAXAGE) == 0)) {
/* unchanged. simply reapprove it */
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network_to_area(): old summary approved");
SET_FLAG(old->flags, OSPF_LSA_APPROVED);
} else {
/* LSA is changed, refresh it */
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network_to_area(): refreshing summary");
set_metric(old, full_cost);
lsa = ospf_lsa_refresh(area->ospf, old);
if (!lsa) {
flog_warn(EC_OSPF_LSA_MISSING,
"%s: Could not refresh %pFX to %pI4",
__func__, (struct prefix *)p,
&area->area_id);
return;
}
SET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
/* This will flood through area. */
}
} else {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network_to_area(): creating new summary");
lsa = ospf_summary_lsa_originate(p, full_cost, area);
/* This will flood through area. */
if (!lsa) {
flog_warn(EC_OSPF_LSA_MISSING,
"%s: Could not originate %pFX to %pi4",
__func__, (struct prefix *)p,
&area->area_id);
return;
}
SET_FLAG(lsa->flags, OSPF_LSA_APPROVED);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network_to_area(): flooding new version of summary");
}
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("ospf_abr_announce_network_to_area(): Stop");
}
static int ospf_abr_nexthops_belong_to_area(struct ospf_route * or,
struct ospf_area *area)
{
struct listnode *node, *nnode;
struct ospf_path *path;
struct ospf_interface *oi;
for (ALL_LIST_ELEMENTS_RO(or->paths, node, path))
for (ALL_LIST_ELEMENTS_RO(area->oiflist, nnode, oi))
if (oi->ifp && oi->ifp->ifindex == path->ifindex)
return 1;
return 0;
}
static int ospf_abr_should_accept(struct prefix_ipv4 *p, struct ospf_area *area)
{
if (IMPORT_NAME(area)) {
if (IMPORT_LIST(area) == NULL)
IMPORT_LIST(area) =
access_list_lookup(AFI_IP, IMPORT_NAME(area));
if (IMPORT_LIST(area))
if (access_list_apply(IMPORT_LIST(area), p)
== FILTER_DENY)
return 0;
}
return 1;
}
static int ospf_abr_plist_in_check(struct ospf_area *area,
struct ospf_route * or,
struct prefix_ipv4 *p)
{
if (PREFIX_NAME_IN(area)) {
if (PREFIX_LIST_IN(area) == NULL)
PREFIX_LIST_IN(area) = prefix_list_lookup(
AFI_IP, PREFIX_NAME_IN(area));
if (PREFIX_LIST_IN(area))
if (prefix_list_apply(PREFIX_LIST_IN(area), p)
!= PREFIX_PERMIT)
return 0;
}
return 1;
}
static int ospf_abr_plist_out_check(struct ospf_area *area,
struct ospf_route * or,
struct prefix_ipv4 *p)
{
if (PREFIX_NAME_OUT(area)) {
if (PREFIX_LIST_OUT(area) == NULL)
PREFIX_LIST_OUT(area) = prefix_list_lookup(
AFI_IP, PREFIX_NAME_OUT(area));
if (PREFIX_LIST_OUT(area))
if (prefix_list_apply(PREFIX_LIST_OUT(area), p)
!= PREFIX_PERMIT)
return 0;
}
return 1;
}
static void ospf_abr_announce_network(struct ospf *ospf, struct prefix_ipv4 *p,
struct ospf_route * or)
{
struct ospf_area_range *range;
struct ospf_area *area, *or_area;
struct listnode *node;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("ospf_abr_announce_network(): Start");
or_area = ospf_area_lookup_by_area_id(ospf, or->u.std.area_id);
assert(or_area);
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network(): looking at area %pI4",
&area->area_id);
if (IPV4_ADDR_SAME(& or->u.std.area_id, &area->area_id))
continue;
if (ospf_abr_nexthops_belong_to_area(or, area))
continue;
if (!ospf_abr_should_accept(p, area)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network(): prefix %pFX was denied by import-list",
p);
continue;
}
if (!ospf_abr_plist_in_check(area, or, p)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network(): prefix %pFX was denied by prefix-list",
p);
continue;
}
if (area->external_routing != OSPF_AREA_DEFAULT
&& area->no_summary) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network(): area %pI4 is stub and no_summary",
&area->area_id);
continue;
}
if (or->path_type == OSPF_PATH_INTER_AREA) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network(): this is inter-area route to %pFX",
p);
if (!OSPF_IS_AREA_BACKBONE(area))
ospf_abr_announce_network_to_area(p, or->cost,
area);
}
if (or->path_type == OSPF_PATH_INTRA_AREA) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"ospf_abr_announce_network(): this is intra-area route to %pFX",
p);
if ((range = ospf_area_range_match(or_area, p))
&& !ospf_area_is_transit(area))
ospf_abr_update_aggregate(range, or, area);
else
ospf_abr_announce_network_to_area(p, or->cost,
area);
}
}
}
static int ospf_abr_should_announce(struct ospf *ospf, struct prefix_ipv4 *p,
struct ospf_route * or)
{
struct ospf_area *area;
area = ospf_area_lookup_by_area_id(ospf, or->u.std.area_id);
assert(area);
if (EXPORT_NAME(area)) {
if (EXPORT_LIST(area) == NULL)
EXPORT_LIST(area) =
access_list_lookup(AFI_IP, EXPORT_NAME(area));
if (EXPORT_LIST(area))
if (access_list_apply(EXPORT_LIST(area), p)
== FILTER_DENY)
return 0;
}
return 1;
}
static void ospf_abr_process_nssa_translates(struct ospf *ospf)
{
/* Scan through all NSSA_LSDB records for all areas;
If P-bit is on, translate all Type-7's to 5's and aggregate or
flood install as approved in Type-5 LSDB with XLATE Flag on
later, do same for all aggregates... At end, DISCARD all
remaining UNAPPROVED Type-5's (Aggregate is for future ) */
struct listnode *node;
struct ospf_area *area;
struct route_node *rn;
struct ospf_lsa *lsa;
if (IS_DEBUG_OSPF_NSSA)
zlog_debug("ospf_abr_process_nssa_translates(): Start");
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
if (!area->NSSATranslatorState)
continue; /* skip if not translator */
if (area->external_routing != OSPF_AREA_NSSA)
continue; /* skip if not Nssa Area */
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
"ospf_abr_process_nssa_translates(): looking at area %pI4",
&area->area_id);
LSDB_LOOP (NSSA_LSDB(area), rn, lsa)
ospf_abr_translate_nssa(area, lsa);
}
if (IS_DEBUG_OSPF_NSSA)
zlog_debug("ospf_abr_process_nssa_translates(): Stop");
}
static void ospf_abr_process_network_rt(struct ospf *ospf,
struct route_table *rt)
{