summaryrefslogtreecommitdiffstats
path: root/ospf6d/ospf6_flood.c
blob: 98d3bbc5197bb0e78d6ba2b67df3ac5231f6c74a (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2003 Yasuhiro Ohara
 */

#include <zebra.h>

#include "log.h"
#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "command.h"

#include "ospf6d.h"
#include "ospf6_proto.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"
#include "ospf6_message.h"
#include "ospf6_route.h"
#include "ospf6_spf.h"

#include "ospf6_top.h"
#include "ospf6_area.h"
#include "ospf6_interface.h"
#include "ospf6_neighbor.h"

#include "ospf6_flood.h"
#include "ospf6_nssa.h"
#include "ospf6_gr.h"

unsigned char conf_debug_ospf6_flooding;

struct ospf6_lsdb *ospf6_get_scoped_lsdb(struct ospf6_lsa *lsa)
{
	struct ospf6_lsdb *lsdb = NULL;
	switch (OSPF6_LSA_SCOPE(lsa->header->type)) {
	case OSPF6_SCOPE_LINKLOCAL:
		lsdb = OSPF6_INTERFACE(lsa->lsdb->data)->lsdb;
		break;
	case OSPF6_SCOPE_AREA:
		lsdb = OSPF6_AREA(lsa->lsdb->data)->lsdb;
		break;
	case OSPF6_SCOPE_AS:
		lsdb = OSPF6_PROCESS(lsa->lsdb->data)->lsdb;
		break;
	default:
		assert(0);
		break;
	}
	return lsdb;
}

struct ospf6_lsdb *ospf6_get_scoped_lsdb_self(struct ospf6_lsa *lsa)
{
	struct ospf6_lsdb *lsdb_self = NULL;
	switch (OSPF6_LSA_SCOPE(lsa->header->type)) {
	case OSPF6_SCOPE_LINKLOCAL:
		lsdb_self = OSPF6_INTERFACE(lsa->lsdb->data)->lsdb_self;
		break;
	case OSPF6_SCOPE_AREA:
		lsdb_self = OSPF6_AREA(lsa->lsdb->data)->lsdb_self;
		break;
	case OSPF6_SCOPE_AS:
		lsdb_self = OSPF6_PROCESS(lsa->lsdb->data)->lsdb_self;
		break;
	default:
		assert(0);
		break;
	}
	return lsdb_self;
}

void ospf6_lsa_originate(struct ospf6 *ospf6, struct ospf6_lsa *lsa)
{
	struct ospf6_lsa *old;
	struct ospf6_lsdb *lsdb_self;

	if (lsa->header->adv_router == INADDR_ANY) {
		if (IS_OSPF6_DEBUG_ORIGINATE_TYPE(lsa->header->type))
			zlog_debug(
				"Refusing to originate LSA (zero router ID): %s",
				lsa->name);

		ospf6_lsa_delete(lsa);
		return;
	}

	/* find previous LSA */
	old = ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
				lsa->header->adv_router, lsa->lsdb);

	/* if the new LSA does not differ from previous,
	   suppress this update of the LSA */
	if (old && !OSPF6_LSA_IS_DIFFER(lsa, old)
	    && !ospf6->gr_info.finishing_restart) {
		if (IS_OSPF6_DEBUG_ORIGINATE_TYPE(lsa->header->type))
			zlog_debug("Suppress updating LSA: %s", lsa->name);
		ospf6_lsa_delete(lsa);
		return;
	}

	/* store it in the LSDB for self-originated LSAs */
	lsdb_self = ospf6_get_scoped_lsdb_self(lsa);
	ospf6_lsdb_add(ospf6_lsa_copy(lsa), lsdb_self);

	EVENT_OFF(lsa->refresh);
	event_add_timer(master, ospf6_lsa_refresh, lsa, OSPF_LS_REFRESH_TIME,
			&lsa->refresh);

	if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type)
	    || IS_OSPF6_DEBUG_ORIGINATE_TYPE(lsa->header->type)) {
		zlog_debug("LSA Originate:");
		ospf6_lsa_header_print(lsa);
	}

	ospf6_install_lsa(lsa);
	ospf6_flood(NULL, lsa);
}

void ospf6_lsa_originate_process(struct ospf6_lsa *lsa, struct ospf6 *process)
{
	lsa->lsdb = process->lsdb;
	ospf6_lsa_originate(process, lsa);
}

void ospf6_lsa_originate_area(struct ospf6_lsa *lsa, struct ospf6_area *oa)
{
	lsa->lsdb = oa->lsdb;
	ospf6_lsa_originate(oa->ospf6, lsa);
}

void ospf6_lsa_originate_interface(struct ospf6_lsa *lsa,
				   struct ospf6_interface *oi)
{
	lsa->lsdb = oi->lsdb;
	ospf6_lsa_originate(oi->area->ospf6, lsa);
}

void ospf6_external_lsa_purge(struct ospf6 *ospf6, struct ospf6_lsa *lsa)
{
	uint32_t id = lsa->header->id;
	struct ospf6_area *oa;
	struct listnode *lnode;

	ospf6_lsa_purge(lsa);

	/* Delete the corresponding NSSA LSA */
	for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, lnode, oa)) {
		lsa = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_TYPE_7), id,
					ospf6->router_id, oa->lsdb);
		if (lsa) {
			if (IS_OSPF6_DEBUG_NSSA)
				zlog_debug("withdraw type 7 lsa, LS ID: %u",
					   htonl(id));

			ospf6_lsa_purge(lsa);
		}
	}
}

void ospf6_lsa_purge(struct ospf6_lsa *lsa)
{
	struct ospf6_lsa *self;
	struct ospf6_lsdb *lsdb_self;

	/* remove it from the LSDB for self-originated LSAs */
	lsdb_self = ospf6_get_scoped_lsdb_self(lsa);
	self = ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
				 lsa->header->adv_router, lsdb_self);
	if (self) {
		EVENT_OFF(self->expire);
		EVENT_OFF(self->refresh);
		ospf6_lsdb_remove(self, lsdb_self);
	}

	ospf6_lsa_premature_aging(lsa);
}

/* Puring Multi Link-State IDs LSAs:
 * Same Advertising Router with Multiple Link-State IDs
 * LSAs, purging require to traverse all Link-State IDs
 */
void ospf6_lsa_purge_multi_ls_id(struct ospf6_area *oa, struct ospf6_lsa *lsa)
{
	int ls_id = 0;
	struct ospf6_lsa *lsa_next;
	uint16_t type;

	type = lsa->header->type;

	ospf6_lsa_purge(lsa);

	lsa_next = ospf6_lsdb_lookup(type, htonl(++ls_id),
				     oa->ospf6->router_id, oa->lsdb);
	while (lsa_next) {
		ospf6_lsa_purge(lsa_next);
		lsa_next = ospf6_lsdb_lookup(type, htonl(++ls_id),
					     oa->ospf6->router_id, oa->lsdb);
	}
}

void ospf6_increment_retrans_count(struct ospf6_lsa *lsa)
{
	/* The LSA must be the original one (see the description
	   in ospf6_decrement_retrans_count () below) */
	lsa->retrans_count++;
}

void ospf6_decrement_retrans_count(struct ospf6_lsa *lsa)
{
	struct ospf6_lsdb *lsdb;
	struct ospf6_lsa *orig;

	/* The LSA must be on the retrans-list of a neighbor. It means
	   the "lsa" is a copied one, and we have to decrement the
	   retransmission count of the original one (instead of this "lsa"'s).
	   In order to find the original LSA, first we have to find
	   appropriate LSDB that have the original LSA. */
	lsdb = ospf6_get_scoped_lsdb(lsa);

	/* Find the original LSA of which the retrans_count should be
	 * decremented */
	orig = ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
				 lsa->header->adv_router, lsdb);
	if (orig) {
		orig->retrans_count--;
		assert(orig->retrans_count >= 0);
	}
}

/* RFC2328 section 13.2 Installing LSAs in the database */
void ospf6_install_lsa(struct ospf6_lsa *lsa)
{
	struct ospf6 *ospf6;
	struct timeval now;
	struct ospf6_lsa *old;
	struct ospf6_area *area = NULL;

	ospf6 = ospf6_get_by_lsdb(lsa);
	assert(ospf6);

	/* Remove the old instance from all neighbors' Link state
	   retransmission list (RFC2328 13.2 last paragraph) */
	old = ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
				lsa->header->adv_router, lsa->lsdb);
	if (old) {
		if (ntohs(lsa->header->type) == OSPF6_LSTYPE_TYPE_7) {
			if (IS_OSPF6_DEBUG_NSSA)
				zlog_debug("%s : old LSA %s", __func__,
					   lsa->name);
			lsa->external_lsa_id = old->external_lsa_id;
		}
		EVENT_OFF(old->expire);
		EVENT_OFF(old->refresh);
		ospf6_flood_clear(old);
	}

	monotime(&now);
	if (!OSPF6_LSA_IS_MAXAGE(lsa)) {
		event_add_timer(master, ospf6_lsa_expire, lsa,
				OSPF_LSA_MAXAGE + lsa->birth.tv_sec -
					now.tv_sec,
				&lsa->expire);
	} else
		lsa->expire = NULL;

	if (OSPF6_LSA_IS_SEQWRAP(lsa)
	    && !(CHECK_FLAG(lsa->flag, OSPF6_LSA_SEQWRAPPED)
		 && lsa->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER))) {
		if (IS_OSPF6_DEBUG_EXAMIN_TYPE(lsa->header->type))
			zlog_debug("lsa install wrapping: sequence 0x%x",
				   ntohl(lsa->header->seqnum));
		SET_FLAG(lsa->flag, OSPF6_LSA_SEQWRAPPED);
		/* in lieu of premature_aging, since we do not want to recreate
		 * this lsa
		 * and/or mess with timers etc, we just want to wrap the
		 * sequence number
		 * and reflood the lsa before continuing.
		 * NOTE: Flood needs to be called right after this function
		 * call, by the
		 * caller
		 */
		lsa->header->seqnum = htonl(OSPF_MAX_SEQUENCE_NUMBER);
		lsa->header->age = htons(OSPF_LSA_MAXAGE);
		ospf6_lsa_checksum(lsa->header);
	}

	if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type)
	    || IS_OSPF6_DEBUG_EXAMIN_TYPE(lsa->header->type))
		zlog_debug("%s Install LSA: %s age %d seqnum %x in LSDB.",
			   __func__, lsa->name, ntohs(lsa->header->age),
			   ntohl(lsa->header->seqnum));

	/* actually install */
	lsa->installed = now;

	/* Topo change handling */
	if (CHECK_LSA_TOPO_CHG_ELIGIBLE(ntohs(lsa->header->type))
	    && !CHECK_FLAG(lsa->flag, OSPF6_LSA_DUPLICATE)) {

		/* check if it is new lsa ? or existing lsa got modified ?*/
		if (!old || OSPF6_LSA_IS_CHANGED(old, lsa))
			ospf6_helper_handle_topo_chg(ospf6, lsa);
	}

	ospf6_lsdb_add(lsa, lsa->lsdb);

	if (ntohs(lsa->header->type) == OSPF6_LSTYPE_TYPE_7
	    && lsa->header->adv_router != ospf6->router_id) {
		area = OSPF6_AREA(lsa->lsdb->data);
		ospf6_translated_nssa_refresh(area, lsa, NULL);
		ospf6_schedule_abr_task(area->ospf6);
	}

	if (ntohs(lsa->header->type) == OSPF6_LSTYPE_ROUTER) {
		area = OSPF6_AREA(lsa->lsdb->data);
		if (old == NULL) {
			if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type)
			    || IS_OSPF6_DEBUG_EXAMIN_TYPE(lsa->header->type))
				zlog_debug("%s: New router LSA %s", __func__,
					   lsa->name);
			ospf6_abr_nssa_check_status(area->ospf6);
		}
	}
	return;
}

/* RFC2740 section 3.5.2. Sending Link State Update packets */
/* RFC2328 section 13.3 Next step in the flooding procedure */
void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa,
			   struct ospf6_interface *oi)
{
	struct listnode *node, *nnode;
	struct ospf6_neighbor *on;
	struct ospf6_lsa *req, *old;
	int retrans_added = 0;
	int is_debug = 0;

	if (IS_OSPF6_DEBUG_FLOODING
	    || IS_OSPF6_DEBUG_FLOOD_TYPE(lsa->header->type)) {
		is_debug++;
		zlog_debug("Flooding on %s: %s", oi->interface->name,
			   lsa->name);
	}

	/* (1) For each neighbor */
	for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
		if (is_debug)
			zlog_debug("To neighbor %s", on->name);

		/* (a) if neighbor state < Exchange, examin next */
		if (on->state < OSPF6_NEIGHBOR_EXCHANGE) {
			if (is_debug)
				zlog_debug(
					"Neighbor state less than ExChange, next neighbor");
			continue;
		}

		/* (b) if neighbor not yet Full, check request-list */
		if (on->state != OSPF6_NEIGHBOR_FULL) {
			if (is_debug)
				zlog_debug("Neighbor not yet Full");

			req = ospf6_lsdb_lookup(
				lsa->header->type, lsa->header->id,
				lsa->header->adv_router, on->request_list);
			if (req == NULL) {
				if (is_debug)
					zlog_debug(
						"Not on request-list for this neighbor");
				/* fall through */
			} else {
				/* If new LSA less recent, examin next neighbor
				 */
				if (ospf6_lsa_compare(lsa, req) > 0) {
					if (is_debug)
						zlog_debug(
							"Requesting is older, next neighbor");
					continue;
				}

				/* If the same instance, delete from
				   request-list and
				   examin next neighbor */
				if (ospf6_lsa_compare(lsa, req) == 0) {
					if (is_debug)
						zlog_debug(
							"Requesting the same, remove it, next neighbor");
					if (req == on->last_ls_req) {
						/* sanity check refcount */
						assert(req->lock >= 2);
						ospf6_lsa_unlock(&req);
						on->last_ls_req = NULL;
					}
					if (req)
						ospf6_lsdb_remove(
							req, on->request_list);
					ospf6_check_nbr_loading(on);
					continue;
				}

				/* If the new LSA is more recent, delete from
				 * request-list */
				if (ospf6_lsa_compare(lsa, req) < 0) {
					if (is_debug)
						zlog_debug(
							"Received is newer, remove requesting");
					if (req == on->last_ls_req) {
						ospf6_lsa_unlock(&req);
						on->last_ls_req = NULL;
					}
					if (req)
						ospf6_lsdb_remove(req,
							on->request_list);
					ospf6_check_nbr_loading(on);
					/* fall through */
				}
			}
		}

		/* (c) If the new LSA was received from this neighbor,
		   examin next neighbor */
		if (from == on) {
			if (is_debug)
				zlog_debug(
					"Received is from the neighbor, next neighbor");
			continue;
		}

		if ((oi->area->ospf6->inst_shutdown)
		    || CHECK_FLAG(lsa->flag, OSPF6_LSA_FLUSH)) {
			if (is_debug)
				zlog_debug(
					"%s: Send LSA %s (age %d) update now",
					__func__, lsa->name,
					ntohs(lsa->header->age));
			ospf6_lsupdate_send_neighbor_now(on, lsa);
			continue;
		} else {
			/* (d) add retrans-list, schedule retransmission */
			if (is_debug)
				zlog_debug("Add retrans-list of neighbor %s ",
					   on->name);

			/* Do not increment the retrans count if the lsa is
			 * already present in the retrans list.
			 */
			old = ospf6_lsdb_lookup(
				lsa->header->type, lsa->header->id,
				lsa->header->adv_router, on->retrans_list);
			if (!old) {
				struct ospf6_lsa *orig;
				struct ospf6_lsdb *lsdb;

				if (is_debug)
					zlog_debug(
						"Increment %s from retrans_list of %s",
						lsa->name, on->name);

				/* Increment the retrans count on the original
				 * copy of LSA if present, to maintain the
				 * counter consistency.
				 */

				lsdb = ospf6_get_scoped_lsdb(lsa);
				orig = ospf6_lsdb_lookup(
					lsa->header->type, lsa->header->id,
					lsa->header->adv_router, lsdb);
				if (orig)
					ospf6_increment_retrans_count(orig);
				else
					ospf6_increment_retrans_count(lsa);

				ospf6_lsdb_add(ospf6_lsa_copy(lsa),
					       on->retrans_list);
				event_add_timer(master,
						ospf6_lsupdate_send_neighbor,
						on, on->ospf6_if->rxmt_interval,
						&on->thread_send_lsupdate);
				retrans_added++;
			}
		}
	}

	/* (2) examin next interface if not added to retrans-list */
	if (retrans_added == 0) {
		if (is_debug)
			zlog_debug(
				"No retransmission scheduled, next interface %s",
				oi->interface->name);
		return;
	}

	/* (3) If the new LSA was received on this interface,
	   and it was from DR or BDR, examin next interface */
	if (from && from->ospf6_if == oi
	    && (from->router_id == oi->drouter
		|| from->router_id == oi->bdrouter)) {
		if (is_debug)
			zlog_debug(
				"Received is from the I/F's DR or BDR, next interface");
		return;
	}

	/* (4) If the new LSA was received on this interface,
	   and the interface state is BDR, examin next interface */
	if (from && from->ospf6_if == oi) {
		if (oi->state == OSPF6_INTERFACE_BDR) {
			if (is_debug)
				zlog_debug(
					"Received is from the I/F, itself BDR, next interface");
			return;
		}
		SET_FLAG(lsa->flag, OSPF6_LSA_FLOODBACK);
	}

	/* (5) flood the LSA out the interface. */
	if (is_debug)
		zlog_debug("Schedule flooding for the interface");
	if ((oi->type == OSPF_IFTYPE_BROADCAST)
	    || (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
		ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsupdate_list);
		event_add_event(master, ospf6_lsupdate_send_interface, oi, 0,
				&oi->thread_send_lsupdate);
	} else {
		/* reschedule retransmissions to all neighbors */
		for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
			EVENT_OFF(on->thread_send_lsupdate);
			event_add_event(master, ospf6_lsupdate_send_neighbor,
					on, 0, &on->thread_send_lsupdate);
		}
	}
}

void ospf6_flood_area(struct ospf6_neighbor *from, struct ospf6_lsa *lsa,
		      struct ospf6_area *oa)
{
	struct listnode *node, *nnode;
	struct ospf6_interface *oi;

	for (ALL_LIST_ELEMENTS(oa->if_list, node, nnode, oi)) {
		if (OSPF6_LSA_SCOPE(lsa->header->type) == OSPF6_SCOPE_LINKLOCAL
		    && oi != OSPF6_INTERFACE(lsa->lsdb->data))
			continue;

		ospf6_flood_interface(from, lsa, oi);
	}
}

static void ospf6_flood_process(struct ospf6_neighbor *from,
				struct ospf6_lsa *lsa, struct ospf6 *process)
{
	struct listnode *node, *nnode;
	struct ospf6_area *oa;

	for (ALL_LIST_ELEMENTS(process->area_list, node, nnode, oa)) {

		/* If unknown LSA and U-bit clear, treat as link local
		 * flooding scope
		 */
		if (!OSPF6_LSA_IS_KNOWN(lsa->header->type)
		    && !(ntohs(lsa->header->type) & OSPF6_LSTYPE_UBIT_MASK)
		    && (oa != OSPF6_INTERFACE(lsa->lsdb->data)->area)) {

			if (IS_OSPF6_DEBUG_FLOODING)
				zlog_debug("Unknown LSA, do not flood");
			continue;
		}

		if (OSPF6_LSA_SCOPE(lsa->header->type) == OSPF6_SCOPE_AREA
		    && oa != OSPF6_AREA(lsa->lsdb->data))
			continue;
		if (OSPF6_LSA_SCOPE(lsa->header->type) == OSPF6_SCOPE_LINKLOCAL
		    && oa != OSPF6_INTERFACE(lsa->lsdb->data)->area)
			continue;

		if (ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL
		    && (IS_AREA_STUB(oa) || IS_AREA_NSSA(oa)))
			continue;

		/* Check for NSSA LSA */
		if (ntohs(lsa->header->type) == OSPF6_LSTYPE_TYPE_7
		    && !IS_AREA_NSSA(oa) && !OSPF6_LSA_IS_MAXAGE(lsa))
			continue;

		ospf6_flood_area(from, lsa, oa);
	}
}

void ospf6_flood(struct ospf6_neighbor *from, struct ospf6_lsa *lsa)
{
	struct ospf6 *ospf6;

	ospf6 = ospf6_get_by_lsdb(lsa);
	if (ospf6 == NULL)
		return;

	ospf6_flood_process(from, lsa, ospf6);
}

static void ospf6_flood_clear_interface(struct ospf6_lsa *lsa,
					struct ospf6_interface *oi)
{
	struct listnode *node, *nnode;
	struct ospf6_neighbor *on;
	struct ospf6_lsa *rem;

	for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
		rem = ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
					lsa->header->adv_router,
					on->retrans_list);
		if (rem && !ospf6_lsa_compare(rem, lsa)) {
			if (IS_OSPF6_DEBUG_FLOODING
			    || IS_OSPF6_DEBUG_FLOOD_TYPE(lsa->header->type))
				zlog_debug("Remove %s from retrans_list of %s",
					   rem->name, on->name);
			ospf6_decrement_retrans_count(rem);
			ospf6_lsdb_remove(rem, on->retrans_list);
		}
	}
}

void ospf6_flood_clear_area(struct ospf6_lsa *lsa, struct ospf6_area *oa)
{
	struct listnode *node, *nnode;
	struct ospf6_interface *oi;

	for (ALL_LIST_ELEMENTS(oa->if_list, node, nnode, oi)) {
		if (OSPF6_LSA_SCOPE(lsa->header->type) == OSPF6_SCOPE_LINKLOCAL
		    && oi != OSPF6_INTERFACE(lsa->lsdb->data))
			continue;

		ospf6_flood_clear_interface(lsa, oi);
	}
}

static void ospf6_flood_clear_process(struct ospf6_lsa *lsa,
				      struct ospf6 *process)
{
	struct listnode *node, *nnode;
	struct ospf6_area *oa;

	for (ALL_LIST_ELEMENTS(process->area_list, node, nnode, oa)) {
		if (OSPF6_LSA_SCOPE(lsa->header->type) == OSPF6_SCOPE_AREA
		    && oa != OSPF6_AREA(lsa->lsdb->data))
			continue;
		if (OSPF6_LSA_SCOPE(lsa->header->type) == OSPF6_SCOPE_LINKLOCAL
		    && oa != OSPF6_INTERFACE(lsa->lsdb->data)->area)
			continue;

		if (ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL
		    && (IS_AREA_STUB(oa) || (IS_AREA_NSSA(oa))))
			continue;
		/* Check for NSSA LSA */
		if (ntohs(lsa->header->type) == OSPF6_LSTYPE_TYPE_7
		    && !IS_AREA_NSSA(oa))
			continue;

		ospf6_flood_clear_area(lsa, oa);
	}
}

void ospf6_flood_clear(struct ospf6_lsa *lsa)
{
	struct ospf6 *ospf6;

	ospf6 = ospf6_get_by_lsdb(lsa);
	if (ospf6 == NULL)
		return;
	ospf6_flood_clear_process(lsa, ospf6);
}


/* RFC2328 13.5 (Table 19): Sending link state acknowledgements. */
static void ospf6_acknowledge_lsa_bdrouter(struct ospf6_lsa *lsa,
					   int ismore_recent,
					   struct ospf6_neighbor *from)
{
	struct ospf6_interface *oi;
	int is_debug = 0;

	if (IS_OSPF6_DEBUG_FLOODING
	    || IS_OSPF6_DEBUG_FLOOD_TYPE(lsa->header->type))
		is_debug++;

	assert(from && from->ospf6_if);
	oi = from->ospf6_if;

	/* LSA is more recent than database copy, but was not flooded
	   back out receiving interface. Delayed acknowledgement sent
	   if advertisement received from Designated Router,
	   otherwide do nothing. */
	if (ismore_recent < 0) {
		if (oi->drouter == from->router_id) {
			if (is_debug)
				zlog_debug(
					"Delayed acknowledgement (BDR & MoreRecent & from DR)");
			/* Delayed acknowledgement */
			ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsack_list);
			event_add_timer(master, ospf6_lsack_send_interface, oi,
					3, &oi->thread_send_lsack);
		} else {
			if (is_debug)
				zlog_debug(
					"No acknowledgement (BDR & MoreRecent & ! from DR)");
		}
		return;
	}

	/* LSA is a duplicate, and was treated as an implied acknowledgement.
	   Delayed acknowledgement sent if advertisement received from
	   Designated Router, otherwise do nothing */
	if (CHECK_FLAG(lsa->flag, OSPF6_LSA_DUPLICATE)
	    && CHECK_FLAG(lsa->flag, OSPF6_LSA_IMPLIEDACK)) {
		if (oi->drouter == from->router_id) {
			if (is_debug)
				zlog_debug(
					"Delayed acknowledgement (BDR & Duplicate & ImpliedAck & from DR)");
			/* Delayed acknowledgement */
			ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsack_list);
			event_add_timer(master, ospf6_lsack_send_interface, oi,
					3, &oi->thread_send_lsack);
		} else {
			if (is_debug)
				zlog_debug(
					"No acknowledgement (BDR & Duplicate & ImpliedAck & ! from DR)");
		}
		return;
	}

	/* LSA is a duplicate, and was not treated as an implied
	   acknowledgement.
	   Direct acknowledgement sent */
	if (CHECK_FLAG(lsa->flag, OSPF6_LSA_DUPLICATE)
	    && !CHECK_FLAG(lsa->flag, OSPF6_LSA_IMPLIEDACK)) {
		if (is_debug)
			zlog_debug("Direct acknowledgement (BDR & Duplicate)");
		ospf6_lsdb_add(ospf6_lsa_copy(lsa), from->lsack_list);
		event_add_event(master, ospf6_lsack_send_neighbor, from, 0,
				&from->thread_send_lsack);
		return;
	}

	/* LSA's LS age is equal to Maxage, and there is no current instance
	   of the LSA in the link state database, and none of router's
	   neighbors are in states Exchange or Loading */
	/* Direct acknowledgement sent, but this case is handled in
	   early of ospf6_receive_lsa () */
}

static void ospf6_acknowledge_lsa_allother(struct ospf6_lsa *lsa,
					   int ismore_recent,
					   struct ospf6_neighbor *from)
{
	struct ospf6_interface *oi;
	int is_debug = 0;

	if (IS_OSPF6_DEBUG_FLOODING
	    || IS_OSPF6_DEBUG_FLOOD_TYPE(lsa->header->type))
		is_debug++;

	assert(from && from->ospf6_if);
	oi = from->ospf6_if;

	/* LSA has been flood back out receiving interface.
	   No acknowledgement sent. */
	if (CHECK_FLAG(lsa->flag, OSPF6_LSA_FLOODBACK)) {
		if (is_debug)
			zlog_debug("No acknowledgement (AllOther & FloodBack)");
		return;
	}

	/* LSA is more recent than database copy, but was not flooded
	   back out receiving interface. Delayed acknowledgement sent. */
	if (ismore_recent < 0) {
		if (is_debug)
			zlog_debug(
				"Delayed acknowledgement (AllOther & MoreRecent)");
		/* Delayed acknowledgement */
		ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsack_list);
		event_add_timer(master, ospf6_lsack_send_interface, oi, 3,
				&oi->thread_send_lsack);
		return;
	}

	/* LSA is a duplicate, and was treated as an implied acknowledgement.
	   No acknowledgement sent. */
	if (CHECK_FLAG(lsa->flag, OSPF6_LSA_DUPLICATE)
	    && CHECK_FLAG(lsa->flag, OSPF6_LSA_IMPLIEDACK)) {
		if (is_debug)
			zlog_debug(
				"No acknowledgement (AllOther & Duplicate & ImpliedAck)");
		return;
	}

	/* LSA is a duplicate, and was not treated as an implied
	   acknowledgement.
	   Direct acknowledgement sent */
	if (CHECK_FLAG(lsa->flag, OSPF6_LSA_DUPLICATE)
	    && !CHECK_FLAG(lsa->flag, OSPF6_LSA_IMPLIEDACK)) {
		if (is_debug)
			zlog_debug(
				"Direct acknowledgement (AllOther & Duplicate)");
		ospf6_lsdb_add(ospf6_lsa_copy(lsa), from->lsack_list);
		event_add_event(master, ospf6_lsack_send_neighbor, from, 0,
				&from->thread_send_lsack);
		return;
	}

	/* LSA's LS age is equal to Maxage, and there is no current instance
	   of the LSA in the link state database, and none of router's
	   neighbors are in states Exchange or Loading */
	/* Direct acknowledgement sent, but this case is handled in
	   early of ospf6_receive_lsa () */
}

static void ospf6_acknowledge_lsa(struct ospf6_lsa *lsa, int ismore_recent,
				  struct ospf6_neighbor *from)
{
	struct ospf6_interface *oi;

	assert(from && from->ospf6_if);
	oi = from->ospf6_if;

	if (oi->state == OSPF6_INTERFACE_BDR)
		ospf6_acknowledge_lsa_bdrouter(lsa, ismore_recent, from);
	else
		ospf6_acknowledge_lsa_allother(lsa, ismore_recent, from);
}

/* RFC2328 section 13 (4):
   if MaxAge LSA and if we have no instance, and no neighbor
   is in states Exchange or Loading
   returns 1 if match this case, else returns 0 */
static int ospf6_is_maxage_lsa_drop(struct ospf6_lsa *lsa,
				    struct ospf6_neighbor *from)
{
	struct ospf6_neighbor *on;
	struct ospf6_interface *oi;
	struct ospf6_area *oa;
	struct ospf6 *process = NULL;
	struct listnode *i, *j, *k;
	int count = 0;

	if (!OSPF6_LSA_IS_MAXAGE(lsa))
		return 0;

	if (ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
			      lsa->header->adv_router, lsa->lsdb))
		return 0;

	process = from->ospf6_if->area->ospf6;

	for (ALL_LIST_ELEMENTS_RO(process->area_list, i, oa))
		for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
			for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on))
				if (on->state == OSPF6_NEIGHBOR_EXCHANGE
				    || on->state == OSPF6_NEIGHBOR_LOADING)
					count++;

	if (count == 0)
		return 1;
	return 0;
}

static bool ospf6_lsa_check_min_arrival(struct ospf6_lsa *lsa,
					struct ospf6_neighbor *from)
{
	struct timeval now, res;
	unsigned int time_delta_ms;

	monotime(&now);
	timersub(&now, &lsa->installed, &res);
	time_delta_ms = (res.tv_sec * 1000) + (int)(res.tv_usec / 1000);

	if (time_delta_ms < from->ospf6_if->area->ospf6->lsa_minarrival) {
		if (IS_OSPF6_DEBUG_FLOODING ||
		    IS_OSPF6_DEBUG_FLOOD_TYPE(lsa->header->type))
			zlog_debug(
				"LSA can't be updated within MinLSArrival, %dms < %dms, discard",
				time_delta_ms,
				from->ospf6_if->area->ospf6->lsa_minarrival);
		return true;
	}
	return false;
}

/* RFC2328 section 13 The Flooding Procedure */
void ospf6_receive_lsa(struct ospf6_neighbor *from,
		       struct ospf6_lsa_header *lsa_header)
{
	struct ospf6_lsa *new = NULL, *old = NULL, *rem = NULL;
	int ismore_recent;
	int is_debug = 0;

	ismore_recent = 1;
	assert(from);

	/* if we receive a LSA with invalid seqnum drop it */
	if (ntohl(lsa_header->seqnum) - 1 == OSPF_MAX_SEQUENCE_NUMBER) {
		if (IS_OSPF6_DEBUG_EXAMIN_TYPE(lsa_header->type)) {
			zlog_debug(
				"received lsa [%s Id:%pI4 Adv:%pI4] with invalid seqnum 0x%x, ignore",
				ospf6_lstype_name(lsa_header->type),
				&lsa_header->id, &lsa_header->adv_router,
				ntohl(lsa_header->seqnum));
		}
		return;
	}

	/* make lsa structure for received lsa */
	new = ospf6_lsa_create(lsa_header);

	if (IS_OSPF6_DEBUG_FLOODING
	    || IS_OSPF6_DEBUG_FLOOD_TYPE(new->header->type)) {
		is_debug++;
		zlog_debug("LSA Receive from %s", from->name);
		ospf6_lsa_header_print(new);
	}

	/* (1) LSA Checksum */
	if (!ospf6_lsa_checksum_valid(new->header)) {
		if (is_debug)
			zlog_debug(
				"Wrong LSA Checksum %s (Router-ID: %pI4) [Type:%s Checksum:%#06hx), discard",
				from->name, &from->router_id,
				ospf6_lstype_name(new->header->type),
				ntohs(new->header->checksum));
		ospf6_lsa_delete(new);
		return;
	}

	/* (2) Examine the LSA's LS type.
	   RFC2470 3.5.1. Receiving Link State Update packets  */
	if (IS_AREA_STUB(from->ospf6_if->area)
	    && OSPF6_LSA_SCOPE(new->header->type) == OSPF6_SCOPE_AS) {
		if (is_debug)
			zlog_debug(
				"AS-External-LSA (or AS-scope LSA) in stub area, discard");
		ospf6_lsa_delete(new);
		return;
	}

	/* (3) LSA which have reserved scope is discarded
	   RFC2470 3.5.1. Receiving Link State Update packets  */
	/* Flooding scope check. LSAs with unknown scope are discarded here.
	   Set appropriate LSDB for the LSA */
	switch (OSPF6_LSA_SCOPE(new->header->type)) {
	case OSPF6_SCOPE_LINKLOCAL:
		new->lsdb = from->ospf6_if->lsdb;
		break;
	case OSPF6_SCOPE_AREA:
		new->lsdb = from->ospf6_if->area->lsdb;
		break;
	case OSPF6_SCOPE_AS:
		new->lsdb = from->ospf6_if->area->ospf6->lsdb;
		break;
	default:
		if (is_debug)
			zlog_debug("LSA has reserved scope, discard");
		ospf6_lsa_delete(new);
		return;
	}

	/* (4) if MaxAge LSA and if we have no instance, and no neighbor
	       is in states Exchange or Loading */
	if (ospf6_is_maxage_lsa_drop(new, from)) {
		/* log */
		if (is_debug)
			zlog_debug(
				"Drop MaxAge LSA with direct acknowledgement.");

		/* a) Acknowledge back to neighbor (Direct acknowledgement,
		 * 13.5) */
		ospf6_lsdb_add(ospf6_lsa_copy(new), from->lsack_list);
		event_add_event(master, ospf6_lsack_send_neighbor, from, 0,
				&from->thread_send_lsack);

		/* b) Discard */
		ospf6_lsa_delete(new);
		return;
	}

	/* (5) */
	/* lookup the same database copy in lsdb */
	old = ospf6_lsdb_lookup(new->header->type, new->header->id,
				new->header->adv_router, new->lsdb);
	if (old) {
		ismore_recent = ospf6_lsa_compare(new, old);
		if (ntohl(new->header->seqnum) == ntohl(old->header->seqnum)) {
			if (is_debug)
				zlog_debug("Received is duplicated LSA");
			SET_FLAG(new->flag, OSPF6_LSA_DUPLICATE);
		}
	}

	/* if no database copy or received is more recent */
	if (old == NULL || ismore_recent < 0) {
		bool self_originated;

		/* in case we have no database copy */
		ismore_recent = -1;

		/* (a) MinLSArrival check */
		if (old) {
			if (ospf6_lsa_check_min_arrival(old, from)) {
				ospf6_lsa_delete(new);
				return; /* examin next lsa */
			}
		}

		monotime(&new->received);

		if (is_debug)
			zlog_debug(
				"Install, Flood, Possibly acknowledge the received LSA");

		/* Remove older copies of this LSA from retx lists */
		if (old)
			ospf6_flood_clear(old);

		self_originated = (new->header->adv_router
				   == from->ospf6_if->area->ospf6->router_id);

		/* Received non-self-originated Grace LSA. */
		if (IS_GRACE_LSA(new) && !self_originated) {
			struct ospf6 *ospf6;

			ospf6 = ospf6_get_by_lsdb(new);

			assert(ospf6);

			if (OSPF6_LSA_IS_MAXAGE(new)) {

				if (IS_DEBUG_OSPF6_GR)
					zlog_debug(
						"%s, Received a maxage GraceLSA from router %pI4",
						__func__,
						&new->header->adv_router);
				if (old) {
					ospf6_process_maxage_grace_lsa(
						ospf6, new, from);
				} else {
					if (IS_DEBUG_OSPF6_GR)
						zlog_debug(
							"%s, GraceLSA doesn't exist in lsdb, so discarding GraceLSA",
							__func__);
					ospf6_lsa_delete(new);
					return;
				}
			} else {

				if (IS_DEBUG_OSPF6_GR)
					zlog_debug(
						"%s, Received a GraceLSA from router %pI4",
						__func__,
						&new->header->adv_router);

				if (ospf6_process_grace_lsa(ospf6, new, from)
				    == OSPF6_GR_NOT_HELPER) {
					if (IS_DEBUG_OSPF6_GR)
						zlog_debug(
							"%s, Not moving to HELPER role, So dicarding GraceLSA",
							__func__);
					return;
				}
			}
		}

		/* (b) immediately flood and (c) remove from all retrans-list */
		/* Prevent self-originated LSA to be flooded. this is to make
		 * reoriginated instance of the LSA not to be rejected by other
		 * routers due to MinLSArrival.
		 */
		if (!self_originated)
			ospf6_flood(from, new);

		/* (d), installing lsdb, which may cause routing
			table calculation (replacing database copy) */
		ospf6_install_lsa(new);

		if (OSPF6_LSA_IS_MAXAGE(new))
			ospf6_maxage_remove(from->ospf6_if->area->ospf6);

		/* (e) possibly acknowledge */
		ospf6_acknowledge_lsa(new, ismore_recent, from);

		/* (f) Self Originated LSA, section 13.4 */
		if (self_originated) {
			if (from->ospf6_if->area->ospf6->gr_info
				    .restart_in_progress) {
				if (IS_DEBUG_OSPF6_GR)
					zlog_debug(
						"Graceful Restart in progress -- not flushing self-originated LSA: %s",
						new->name);
				return;
			}

			/* Self-originated LSA (newer than ours) is received
			   from
			   another router. We have to make a new instance of the
			   LSA
			   or have to flush this LSA. */
			if (is_debug) {
				zlog_debug(
					"Newer instance of the self-originated LSA");
				zlog_debug("Schedule reorigination");
			}
			event_add_event(master, ospf6_lsa_refresh, new, 0,
					&new->refresh);
		}

		/* GR: check for network topology change. */
		struct ospf6 *ospf6 = from->ospf6_if->area->ospf6;
		struct ospf6_area *area = from->ospf6_if->area;
		if (ospf6->gr_info.restart_in_progress &&
		    (new->header->type == ntohs(OSPF6_LSTYPE_ROUTER) ||
		     new->header->type == ntohs(OSPF6_LSTYPE_NETWORK)))
			ospf6_gr_check_lsdb_consistency(ospf6, area);

		return;
	}

	/* (6) if there is instance on sending neighbor's request list */
	if (ospf6_lsdb_lookup(new->header->type, new->header->id,
			      new->header->adv_router, from->request_list)) {
		/* if no database copy, should go above state (5) */
		assert(old);

		zlog_warn(
			"Received is not newer, on the neighbor %s request-list",
			from->name);
		zlog_warn(
			"BadLSReq, discard the received LSA lsa %s send badLSReq",
			new->name);

		/* BadLSReq */
		event_add_event(master, bad_lsreq, from, 0, NULL);

		ospf6_lsa_delete(new);
		return;
	}

	/* (7) if neither one is more recent */
	if (ismore_recent == 0) {
		if (is_debug)
			zlog_debug(
				"The same instance as database copy (neither recent)");

		/* (a) if on retrans-list, Treat this LSA as an Ack: Implied Ack
		 */
		rem = ospf6_lsdb_lookup(new->header->type, new->header->id,
					new->header->adv_router,
					from->retrans_list);
		if (rem) {
			if (is_debug) {
				zlog_debug(
					"It is on the neighbor's retrans-list.");
				zlog_debug(
					"Treat as an Implied acknowledgement");
			}
			SET_FLAG(new->flag, OSPF6_LSA_IMPLIEDACK);
			ospf6_decrement_retrans_count(rem);
			ospf6_lsdb_remove(rem, from->retrans_list);
		}

		if (is_debug)
			zlog_debug("Possibly acknowledge and then discard");

		/* (b) possibly acknowledge */
		ospf6_acknowledge_lsa(new, ismore_recent, from);

		ospf6_lsa_delete(new);
		return;
	}

	/* (8) previous database copy is more recent */
	{
		assert(old);

		/* If database copy is in 'Seqnumber Wrapping',
		   simply discard the received LSA */
		if (OSPF6_LSA_IS_MAXAGE(old)
		    && old->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER)) {
			if (is_debug) {
				zlog_debug("The LSA is in Seqnumber Wrapping");
				zlog_debug("MaxAge & MaxSeqNum, discard");
			}
			ospf6_lsa_delete(new);
			return;
		}

		/* Otherwise, Send database copy of this LSA to this neighbor */
		{
			if (is_debug) {
				zlog_debug("Database copy is more recent.");
				zlog_debug(
					"Send back directly and then discard");
			}

			/* Neighbor router sent recent age for LSA,
			 * Router could be restarted while current copy is
			 * MAXAGEd and not removed.*/
			if (OSPF6_LSA_IS_MAXAGE(old)
			    && !OSPF6_LSA_IS_MAXAGE(new)) {
				if (new->header->adv_router
				    != from->ospf6_if->area->ospf6->router_id) {
					if (is_debug)
						zlog_debug(
							"%s: Current copy of LSA %s is MAXAGE, but new has recent age, flooding/installing.",
							__PRETTY_FUNCTION__, old->name);
					ospf6_lsa_purge(old);
					ospf6_flood(from, new);
					ospf6_install_lsa(new);
					return;
				}
				/* For self-originated LSA, only trust
				 * ourselves. Fall through and send
				 * LS Update with our current copy.
				 */
				if (is_debug)
					zlog_debug(
						"%s: Current copy of self-originated LSA %s is MAXAGE, but new has recent age, re-sending current one.",
						__PRETTY_FUNCTION__, old->name);
			}

			/* MinLSArrival check as per RFC 2328 13 (8) */
			if (ospf6_lsa_check_min_arrival(old, from)) {
				ospf6_lsa_delete(new);
				return; /* examin next lsa */
			}

			ospf6_lsdb_add(ospf6_lsa_copy(old),
				       from->lsupdate_list);
			event_add_event(master, ospf6_lsupdate_send_neighbor,
					from, 0, &from->thread_send_lsupdate);

			ospf6_lsa_delete(new);
			return;
		}
	}
}

DEFUN (debug_ospf6_flooding,
       debug_ospf6_flooding_cmd,
       "debug ospf6 flooding",
       DEBUG_STR
       OSPF6_STR
       "Debug OSPFv3 flooding function\n"
      )
{
	OSPF6_DEBUG_FLOODING_ON();
	return CMD_SUCCESS;
}

DEFUN (no_debug_ospf6_flooding,
       no_debug_ospf6_flooding_cmd,
       "no debug ospf6 flooding",
       NO_STR
       DEBUG_STR
       OSPF6_STR
       "Debug OSPFv3 flooding function\n"
      )
{
	OSPF6_DEBUG_FLOODING_OFF();
	return CMD_SUCCESS;
}

int config_write_ospf6_debug_flood(struct vty *vty)
{
	if (IS_OSPF6_DEBUG_FLOODING)
		vty_out(vty, "debug ospf6 flooding\n");
	return 0;
}

void install_element_ospf6_debug_flood(void)
{
	install_element(ENABLE_NODE, &debug_ospf6_flooding_cmd);
	install_element(ENABLE_NODE, &no_debug_ospf6_flooding_cmd);
	install_element(CONFIG_NODE, &debug_ospf6_flooding_cmd);
	install_element(CONFIG_NODE, &no_debug_ospf6_flooding_cmd);
}