]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_lsp.c
ospfd: Fix ospfd crash
[mirror_frr.git] / isisd / isis_lsp.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_lsp.c
3 * LSP processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; see the file COPYING; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include <zebra.h>
26
27 #include "linklist.h"
28 #include "thread.h"
29 #include "vty.h"
30 #include "stream.h"
31 #include "memory.h"
32 #include "log.h"
33 #include "prefix.h"
34 #include "command.h"
35 #include "hash.h"
36 #include "if.h"
37 #include "checksum.h"
38 #include "md5.h"
39 #include "table.h"
40
41 #include "isisd/dict.h"
42 #include "isisd/isis_constants.h"
43 #include "isisd/isis_common.h"
44 #include "isisd/isis_flags.h"
45 #include "isisd/isis_circuit.h"
46 #include "isisd/isisd.h"
47 #include "isisd/isis_lsp.h"
48 #include "isisd/isis_pdu.h"
49 #include "isisd/isis_dynhn.h"
50 #include "isisd/isis_misc.h"
51 #include "isisd/isis_csm.h"
52 #include "isisd/isis_adjacency.h"
53 #include "isisd/isis_spf.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
57
58 /* staticly assigned vars for printing purposes */
59 char lsp_bits_string[200]; /* FIXME: enough ? */
60
61 static int lsp_l1_refresh(struct thread *thread);
62 static int lsp_l2_refresh(struct thread *thread);
63 static int lsp_l1_refresh_pseudo(struct thread *thread);
64 static int lsp_l2_refresh_pseudo(struct thread *thread);
65
66 int lsp_id_cmp(u_char *id1, u_char *id2)
67 {
68 return memcmp(id1, id2, ISIS_SYS_ID_LEN + 2);
69 }
70
71 dict_t *lsp_db_init(void)
72 {
73 dict_t *dict;
74
75 dict = dict_create(DICTCOUNT_T_MAX, (dict_comp_t)lsp_id_cmp);
76
77 return dict;
78 }
79
80 struct isis_lsp *lsp_search(u_char *id, dict_t *lspdb)
81 {
82 dnode_t *node;
83
84 #ifdef EXTREME_DEBUG
85 dnode_t *dn;
86
87 zlog_debug("searching db");
88 for (dn = dict_first(lspdb); dn; dn = dict_next(lspdb, dn)) {
89 zlog_debug("%s\t%pX",
90 rawlspid_print((u_char *)dnode_getkey(dn)),
91 dnode_get(dn));
92 }
93 #endif /* EXTREME DEBUG */
94
95 node = dict_lookup(lspdb, id);
96
97 if (node)
98 return (struct isis_lsp *)dnode_get(node);
99
100 return NULL;
101 }
102
103 static void lsp_clear_data(struct isis_lsp *lsp)
104 {
105 if (!lsp)
106 return;
107
108 isis_free_tlvs(lsp->tlvs);
109 lsp->tlvs = NULL;
110 }
111
112 static void lsp_destroy(struct isis_lsp *lsp)
113 {
114 struct listnode *cnode;
115 struct isis_circuit *circuit;
116
117 if (!lsp)
118 return;
119
120 for (ALL_LIST_ELEMENTS_RO(lsp->area->circuit_list, cnode, circuit))
121 isis_circuit_cancel_queued_lsp(circuit, lsp);
122
123 ISIS_FLAGS_CLEAR_ALL(lsp->SSNflags);
124 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
125
126 lsp_clear_data(lsp);
127
128 if (LSP_FRAGMENT(lsp->hdr.lsp_id) == 0 && lsp->lspu.frags) {
129 list_delete_and_null(&lsp->lspu.frags);
130 lsp->lspu.frags = NULL;
131 }
132
133 isis_spf_schedule(lsp->area, lsp->level);
134
135 if (lsp->pdu)
136 stream_free(lsp->pdu);
137 XFREE(MTYPE_ISIS_LSP, lsp);
138 }
139
140 void lsp_db_destroy(dict_t *lspdb)
141 {
142 dnode_t *dnode, *next;
143 struct isis_lsp *lsp;
144
145 dnode = dict_first(lspdb);
146 while (dnode) {
147 next = dict_next(lspdb, dnode);
148 lsp = dnode_get(dnode);
149 lsp_destroy(lsp);
150 dict_delete_free(lspdb, dnode);
151 dnode = next;
152 }
153
154 dict_free(lspdb);
155
156 return;
157 }
158
159 /*
160 * Remove all the frags belonging to the given lsp
161 */
162 static void lsp_remove_frags(struct list *frags, dict_t *lspdb)
163 {
164 dnode_t *dnode;
165 struct listnode *lnode, *lnnode;
166 struct isis_lsp *lsp;
167
168 for (ALL_LIST_ELEMENTS(frags, lnode, lnnode, lsp)) {
169 dnode = dict_lookup(lspdb, lsp->hdr.lsp_id);
170 lsp_destroy(lsp);
171 dnode_destroy(dict_delete(lspdb, dnode));
172 }
173
174 list_delete_all_node(frags);
175
176 return;
177 }
178
179 void lsp_search_and_destroy(u_char *id, dict_t *lspdb)
180 {
181 dnode_t *node;
182 struct isis_lsp *lsp;
183
184 node = dict_lookup(lspdb, id);
185 if (node) {
186 node = dict_delete(lspdb, node);
187 lsp = dnode_get(node);
188 /*
189 * If this is a zero lsp, remove all the frags now
190 */
191 if (LSP_FRAGMENT(lsp->hdr.lsp_id) == 0) {
192 if (lsp->lspu.frags)
193 lsp_remove_frags(lsp->lspu.frags, lspdb);
194 } else {
195 /*
196 * else just remove this frag, from the zero lsps' frag
197 * list
198 */
199 if (lsp->lspu.zero_lsp
200 && lsp->lspu.zero_lsp->lspu.frags)
201 listnode_delete(lsp->lspu.zero_lsp->lspu.frags,
202 lsp);
203 }
204 lsp_destroy(lsp);
205 dnode_destroy(node);
206 }
207 }
208
209 /*
210 * Compares a LSP to given values
211 * Params are given in net order
212 */
213 int lsp_compare(char *areatag, struct isis_lsp *lsp, uint32_t seqno,
214 uint16_t checksum, uint16_t rem_lifetime)
215 {
216 if (lsp->hdr.seqno == seqno && lsp->hdr.checksum == checksum
217 && ((lsp->hdr.rem_lifetime == 0 && rem_lifetime == 0)
218 || (lsp->hdr.rem_lifetime != 0 && rem_lifetime != 0))) {
219 if (isis->debugs & DEBUG_SNP_PACKETS) {
220 zlog_debug(
221 "ISIS-Snp (%s): Compare LSP %s seq 0x%08" PRIx32
222 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
223 "s",
224 areatag, rawlspid_print(lsp->hdr.lsp_id),
225 lsp->hdr.seqno, lsp->hdr.checksum,
226 lsp->hdr.rem_lifetime);
227 zlog_debug(
228 "ISIS-Snp (%s): is equal to ours seq 0x%08" PRIx32
229 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
230 "s",
231 areatag, seqno, checksum, rem_lifetime);
232 }
233 return LSP_EQUAL;
234 }
235
236 /*
237 * LSPs with identical checksums should only be treated as newer if:
238 * a) The current LSP has a remaining lifetime != 0 and the other LSP
239 * has a
240 * remaining lifetime == 0. In this case, we should participate in
241 * the purge
242 * and should not treat the current LSP with remaining lifetime == 0
243 * as older.
244 * b) The LSP has an incorrect checksum. In this case, we need to react
245 * as given
246 * in 7.3.16.2.
247 */
248 if (seqno > lsp->hdr.seqno
249 || (seqno == lsp->hdr.seqno
250 && ((lsp->hdr.rem_lifetime != 0 && rem_lifetime == 0)
251 || lsp->hdr.checksum != checksum))) {
252 if (isis->debugs & DEBUG_SNP_PACKETS) {
253 zlog_debug(
254 "ISIS-Snp (%s): Compare LSP %s seq 0x%08" PRIx32
255 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
256 "s",
257 areatag, rawlspid_print(lsp->hdr.lsp_id), seqno,
258 checksum, rem_lifetime);
259 zlog_debug(
260 "ISIS-Snp (%s): is newer than ours seq 0x%08" PRIx32
261 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
262 "s",
263 areatag, lsp->hdr.seqno, lsp->hdr.checksum,
264 lsp->hdr.rem_lifetime);
265 }
266 return LSP_NEWER;
267 }
268 if (isis->debugs & DEBUG_SNP_PACKETS) {
269 zlog_debug("ISIS-Snp (%s): Compare LSP %s seq 0x%08" PRIx32
270 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16 "s",
271 areatag, rawlspid_print(lsp->hdr.lsp_id), seqno,
272 checksum, rem_lifetime);
273 zlog_debug(
274 "ISIS-Snp (%s): is older than ours seq 0x%08" PRIx32
275 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16 "s",
276 areatag, lsp->hdr.seqno, lsp->hdr.checksum,
277 lsp->hdr.rem_lifetime);
278 }
279
280 return LSP_OLDER;
281 }
282
283 static void put_lsp_hdr(struct isis_lsp *lsp, size_t *len_pointer, bool keep)
284 {
285 uint8_t pdu_type =
286 (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE : L2_LINK_STATE;
287 struct isis_lsp_hdr *hdr = &lsp->hdr;
288 struct stream *stream = lsp->pdu;
289 size_t orig_getp = 0, orig_endp = 0;
290
291 if (keep) {
292 orig_getp = stream_get_getp(lsp->pdu);
293 orig_endp = stream_get_endp(lsp->pdu);
294 }
295
296 stream_set_getp(lsp->pdu, 0);
297 stream_set_endp(lsp->pdu, 0);
298
299 fill_fixed_hdr(pdu_type, stream);
300
301 if (len_pointer)
302 *len_pointer = stream_get_endp(stream);
303 stream_putw(stream, hdr->pdu_len);
304 stream_putw(stream, hdr->rem_lifetime);
305 stream_put(stream, hdr->lsp_id, sizeof(hdr->lsp_id));
306 stream_putl(stream, hdr->seqno);
307 stream_putw(stream, hdr->checksum);
308 stream_putc(stream, hdr->lsp_bits);
309
310 if (keep) {
311 stream_set_endp(lsp->pdu, orig_endp);
312 stream_set_getp(lsp->pdu, orig_getp);
313 }
314 }
315
316 static void lsp_add_auth(struct isis_lsp *lsp)
317 {
318 struct isis_passwd *passwd;
319 passwd = (lsp->level == IS_LEVEL_1) ? &lsp->area->area_passwd
320 : &lsp->area->domain_passwd;
321 isis_tlvs_add_auth(lsp->tlvs, passwd);
322 }
323
324 static void lsp_pack_pdu(struct isis_lsp *lsp)
325 {
326 if (!lsp->tlvs)
327 lsp->tlvs = isis_alloc_tlvs();
328
329 lsp_add_auth(lsp);
330
331 size_t len_pointer;
332 put_lsp_hdr(lsp, &len_pointer, false);
333 isis_pack_tlvs(lsp->tlvs, lsp->pdu, len_pointer, false, true);
334
335 lsp->hdr.pdu_len = stream_get_endp(lsp->pdu);
336 lsp->hdr.checksum =
337 ntohs(fletcher_checksum(STREAM_DATA(lsp->pdu) + 12,
338 stream_get_endp(lsp->pdu) - 12, 12));
339 }
340
341 void lsp_inc_seqno(struct isis_lsp *lsp, uint32_t seqno)
342 {
343 uint32_t newseq;
344
345 if (seqno == 0 || lsp->hdr.seqno > seqno)
346 newseq = lsp->hdr.seqno + 1;
347 else
348 newseq = seqno + 1;
349
350 lsp->hdr.seqno = newseq;
351
352 lsp_pack_pdu(lsp);
353 isis_spf_schedule(lsp->area, lsp->level);
354 }
355
356 static void lsp_purge(struct isis_lsp *lsp, int level)
357 {
358 /* reset stream */
359 lsp_clear_data(lsp);
360 stream_reset(lsp->pdu);
361
362 /* update header */
363 lsp->hdr.checksum = 0;
364 lsp->hdr.rem_lifetime = 0;
365 lsp->level = level;
366 lsp->age_out = lsp->area->max_lsp_lifetime[level - 1];
367
368 lsp_pack_pdu(lsp);
369 lsp_set_all_srmflags(lsp);
370 }
371
372 /*
373 * Generates checksum for LSP and its frags
374 */
375 static void lsp_seqno_update(struct isis_lsp *lsp0)
376 {
377 struct isis_lsp *lsp;
378 struct listnode *node;
379
380 lsp_inc_seqno(lsp0, 0);
381
382 if (!lsp0->lspu.frags)
383 return;
384
385 for (ALL_LIST_ELEMENTS_RO(lsp0->lspu.frags, node, lsp)) {
386 if (lsp->tlvs)
387 lsp_inc_seqno(lsp, 0);
388 else
389 lsp_purge(lsp, lsp0->level);
390 }
391
392 return;
393 }
394
395 static u_int8_t lsp_bits_generate(int level, int overload_bit, int attached_bit)
396 {
397 u_int8_t lsp_bits = 0;
398 if (level == IS_LEVEL_1)
399 lsp_bits = IS_LEVEL_1;
400 else
401 lsp_bits = IS_LEVEL_1_AND_2;
402 if (overload_bit)
403 lsp_bits |= overload_bit;
404 if (attached_bit)
405 lsp_bits |= attached_bit;
406 return lsp_bits;
407 }
408
409 static void lsp_update_data(struct isis_lsp *lsp, struct isis_lsp_hdr *hdr,
410 struct isis_tlvs *tlvs, struct stream *stream,
411 struct isis_area *area, int level)
412 {
413 /* free the old lsp data */
414 lsp_clear_data(lsp);
415
416 /* copying only the relevant part of our stream */
417 if (lsp->pdu != NULL)
418 stream_free(lsp->pdu);
419 lsp->pdu = stream_dup(stream);
420
421 memcpy(&lsp->hdr, hdr, sizeof(lsp->hdr));
422 lsp->area = area;
423 lsp->level = level;
424 lsp->age_out = ZERO_AGE_LIFETIME;
425 lsp->installed = time(NULL);
426
427 lsp->tlvs = tlvs;
428
429 if (area->dynhostname && lsp->tlvs->hostname) {
430 isis_dynhn_insert(lsp->hdr.lsp_id, lsp->tlvs->hostname,
431 (lsp->hdr.lsp_bits & LSPBIT_IST)
432 == IS_LEVEL_1_AND_2
433 ? IS_LEVEL_2
434 : IS_LEVEL_1);
435 }
436
437 return;
438 }
439
440 static void lsp_link_fragment(struct isis_lsp *lsp, struct isis_lsp *lsp0)
441 {
442 if (!LSP_FRAGMENT(lsp->hdr.lsp_id)) {
443 /* zero lsp -> create list to store fragments */
444 lsp->lspu.frags = list_new();
445 } else {
446 /* fragment -> set backpointer and add to zero lsps list */
447 assert(lsp0);
448 lsp->lspu.zero_lsp = lsp0;
449 listnode_add(lsp0->lspu.frags, lsp);
450 }
451 }
452
453 void lsp_update(struct isis_lsp *lsp, struct isis_lsp_hdr *hdr,
454 struct isis_tlvs *tlvs, struct stream *stream,
455 struct isis_area *area, int level, bool confusion)
456 {
457 if (lsp->own_lsp) {
458 zlog_err(
459 "ISIS-Upd (%s): BUG updating LSP %s still marked as own LSP",
460 area->area_tag, rawlspid_print(lsp->hdr.lsp_id));
461 lsp_clear_data(lsp);
462 lsp->own_lsp = 0;
463 }
464
465 lsp_update_data(lsp, hdr, tlvs, stream, area, level);
466 if (confusion) {
467 lsp->hdr.rem_lifetime = hdr->rem_lifetime = 0;
468 put_lsp_hdr(lsp, NULL, true);
469 }
470
471 if (LSP_FRAGMENT(lsp->hdr.lsp_id) && !lsp->lspu.zero_lsp) {
472 uint8_t lspid[ISIS_SYS_ID_LEN + 2];
473 struct isis_lsp *lsp0;
474
475 memcpy(lspid, lsp->hdr.lsp_id, ISIS_SYS_ID_LEN + 1);
476 LSP_FRAGMENT(lspid) = 0;
477 lsp0 = lsp_search(lspid, area->lspdb[level - 1]);
478 if (lsp0)
479 lsp_link_fragment(lsp, lsp0);
480 }
481
482 if (lsp->hdr.seqno)
483 isis_spf_schedule(lsp->area, lsp->level);
484 }
485
486 /* creation of LSP directly from what we received */
487 struct isis_lsp *lsp_new_from_recv(struct isis_lsp_hdr *hdr,
488 struct isis_tlvs *tlvs,
489 struct stream *stream, struct isis_lsp *lsp0,
490 struct isis_area *area, int level)
491 {
492 struct isis_lsp *lsp;
493
494 lsp = XCALLOC(MTYPE_ISIS_LSP, sizeof(struct isis_lsp));
495 lsp_update_data(lsp, hdr, tlvs, stream, area, level);
496 lsp_link_fragment(lsp, lsp0);
497
498 return lsp;
499 }
500
501 struct isis_lsp *lsp_new(struct isis_area *area, u_char *lsp_id,
502 uint16_t rem_lifetime, uint32_t seqno,
503 uint8_t lsp_bits, uint16_t checksum,
504 struct isis_lsp *lsp0, int level)
505 {
506 struct isis_lsp *lsp;
507
508 lsp = XCALLOC(MTYPE_ISIS_LSP, sizeof(struct isis_lsp));
509 lsp->area = area;
510
511 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
512
513 /* Minimal LSP PDU size */
514 lsp->hdr.pdu_len = ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN;
515 memcpy(lsp->hdr.lsp_id, lsp_id, sizeof(lsp->hdr.lsp_id));
516 lsp->hdr.checksum = checksum;
517 lsp->hdr.seqno = seqno;
518 lsp->hdr.rem_lifetime = rem_lifetime;
519 lsp->hdr.lsp_bits = lsp_bits;
520 lsp->level = level;
521 lsp->age_out = ZERO_AGE_LIFETIME;
522 lsp_link_fragment(lsp, lsp0);
523 put_lsp_hdr(lsp, NULL, false);
524
525 if (isis->debugs & DEBUG_EVENTS)
526 zlog_debug("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
527 sysid_print(lsp_id), LSP_PSEUDO_ID(lsp->hdr.lsp_id),
528 LSP_FRAGMENT(lsp->hdr.lsp_id), lsp->hdr.pdu_len,
529 lsp->hdr.seqno);
530
531 return lsp;
532 }
533
534 void lsp_insert(struct isis_lsp *lsp, dict_t *lspdb)
535 {
536 dict_alloc_insert(lspdb, lsp->hdr.lsp_id, lsp);
537 if (lsp->hdr.seqno)
538 isis_spf_schedule(lsp->area, lsp->level);
539 }
540
541 /*
542 * Build a list of LSPs with non-zero ht bounded by start and stop ids
543 */
544 void lsp_build_list_nonzero_ht(u_char *start_id, u_char *stop_id,
545 struct list *list, dict_t *lspdb)
546 {
547 dnode_t *first, *last, *curr;
548
549 first = dict_lower_bound(lspdb, start_id);
550 if (!first)
551 return;
552
553 last = dict_upper_bound(lspdb, stop_id);
554
555 curr = first;
556
557 if (((struct isis_lsp *)(curr->dict_data))->hdr.rem_lifetime)
558 listnode_add(list, first->dict_data);
559
560 while (curr) {
561 curr = dict_next(lspdb, curr);
562 if (curr
563 && ((struct isis_lsp *)(curr->dict_data))->hdr.rem_lifetime)
564 listnode_add(list, curr->dict_data);
565 if (curr == last)
566 break;
567 }
568
569 return;
570 }
571
572 static void lsp_set_time(struct isis_lsp *lsp)
573 {
574 assert(lsp);
575
576 if (lsp->hdr.rem_lifetime == 0) {
577 if (lsp->age_out > 0)
578 lsp->age_out--;
579 return;
580 }
581
582 lsp->hdr.rem_lifetime--;
583 if (lsp->pdu && stream_get_endp(lsp->pdu) >= 12)
584 stream_putw_at(lsp->pdu, 10, lsp->hdr.rem_lifetime);
585 }
586
587 static void lspid_print(u_char *lsp_id, u_char *trg, char dynhost, char frag)
588 {
589 struct isis_dynhn *dyn = NULL;
590 u_char id[SYSID_STRLEN];
591
592 if (dynhost)
593 dyn = dynhn_find_by_id(lsp_id);
594 else
595 dyn = NULL;
596
597 if (dyn)
598 sprintf((char *)id, "%.14s", dyn->hostname);
599 else if (!memcmp(isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
600 sprintf((char *)id, "%.14s", cmd_hostname_get());
601 else
602 memcpy(id, sysid_print(lsp_id), 15);
603 if (frag)
604 sprintf((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID(lsp_id),
605 LSP_FRAGMENT(lsp_id));
606 else
607 sprintf((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID(lsp_id));
608 }
609
610 /* Convert the lsp attribute bits to attribute string */
611 static const char *lsp_bits2string(uint8_t lsp_bits)
612 {
613 char *pos = lsp_bits_string;
614
615 if (!lsp_bits)
616 return " none";
617
618 /* we only focus on the default metric */
619 pos += sprintf(pos, "%d/",
620 ISIS_MASK_LSP_ATT_DEFAULT_BIT(lsp_bits) ? 1 : 0);
621
622 pos += sprintf(pos, "%d/",
623 ISIS_MASK_LSP_PARTITION_BIT(lsp_bits) ? 1 : 0);
624
625 pos += sprintf(pos, "%d", ISIS_MASK_LSP_OL_BIT(lsp_bits) ? 1 : 0);
626
627 *(pos) = '\0';
628
629 return lsp_bits_string;
630 }
631
632 /* this function prints the lsp on show isis database */
633 void lsp_print(struct isis_lsp *lsp, struct vty *vty, char dynhost)
634 {
635 u_char LSPid[255];
636 char age_out[8];
637
638 lspid_print(lsp->hdr.lsp_id, LSPid, dynhost, 1);
639 vty_out(vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
640 vty_out(vty, "%5" PRIu16 " ", lsp->hdr.pdu_len);
641 vty_out(vty, "0x%08" PRIx32 " ", lsp->hdr.seqno);
642 vty_out(vty, "0x%04" PRIx16 " ", lsp->hdr.checksum);
643 if (lsp->hdr.rem_lifetime == 0) {
644 snprintf(age_out, 8, "(%d)", lsp->age_out);
645 age_out[7] = '\0';
646 vty_out(vty, "%7s ", age_out);
647 } else
648 vty_out(vty, " %5" PRIu16 " ", lsp->hdr.rem_lifetime);
649 vty_out(vty, "%s\n", lsp_bits2string(lsp->hdr.lsp_bits));
650 }
651
652 void lsp_print_detail(struct isis_lsp *lsp, struct vty *vty, char dynhost)
653 {
654 lsp_print(lsp, vty, dynhost);
655 if (lsp->tlvs)
656 vty_multiline(vty, " ", "%s", isis_format_tlvs(lsp->tlvs));
657 vty_out(vty, "\n");
658 }
659
660 /* print all the lsps info in the local lspdb */
661 int lsp_print_all(struct vty *vty, dict_t *lspdb, char detail, char dynhost)
662 {
663
664 dnode_t *node = dict_first(lspdb), *next;
665 int lsp_count = 0;
666
667 if (detail == ISIS_UI_LEVEL_BRIEF) {
668 while (node != NULL) {
669 /* I think it is unnecessary, so I comment it out */
670 /* dict_contains (lspdb, node); */
671 next = dict_next(lspdb, node);
672 lsp_print(dnode_get(node), vty, dynhost);
673 node = next;
674 lsp_count++;
675 }
676 } else if (detail == ISIS_UI_LEVEL_DETAIL) {
677 while (node != NULL) {
678 next = dict_next(lspdb, node);
679 lsp_print_detail(dnode_get(node), vty, dynhost);
680 node = next;
681 lsp_count++;
682 }
683 }
684
685 return lsp_count;
686 }
687
688 static u_int16_t lsp_rem_lifetime(struct isis_area *area, int level)
689 {
690 u_int16_t rem_lifetime;
691
692 /* Add jitter to configured LSP lifetime */
693 rem_lifetime =
694 isis_jitter(area->max_lsp_lifetime[level - 1], MAX_AGE_JITTER);
695
696 /* No jitter if the max refresh will be less than configure gen interval
697 */
698 /* N.B. this calucation is acceptable since rem_lifetime is in
699 * [332,65535] at
700 * this point */
701 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
702 rem_lifetime = area->max_lsp_lifetime[level - 1];
703
704 return rem_lifetime;
705 }
706
707 static u_int16_t lsp_refresh_time(struct isis_lsp *lsp, u_int16_t rem_lifetime)
708 {
709 struct isis_area *area = lsp->area;
710 int level = lsp->level;
711 u_int16_t refresh_time;
712
713 /* Add jitter to LSP refresh time */
714 refresh_time =
715 isis_jitter(area->lsp_refresh[level - 1], MAX_LSP_GEN_JITTER);
716
717 /* RFC 4444 : make sure the refresh time is at least less than 300
718 * of the remaining lifetime and more than gen interval */
719 if (refresh_time <= area->lsp_gen_interval[level - 1]
720 || refresh_time > (rem_lifetime - 300))
721 refresh_time = rem_lifetime - 300;
722
723 /* In cornercases, refresh_time might be <= lsp_gen_interval, however
724 * we accept this violation to satisfy refresh_time <= rem_lifetime -
725 * 300 */
726
727 return refresh_time;
728 }
729
730 static void lsp_build_ext_reach_ipv4(struct isis_lsp *lsp,
731 struct isis_area *area)
732 {
733 struct route_table *er_table = get_ext_reach(area, AF_INET, lsp->level);
734 if (!er_table)
735 return;
736
737 for (struct route_node *rn = route_top(er_table); rn;
738 rn = route_next(rn)) {
739 if (!rn->info)
740 continue;
741
742 struct prefix_ipv4 *ipv4 = (struct prefix_ipv4 *)&rn->p;
743 struct isis_ext_info *info = rn->info;
744
745 uint32_t metric = info->metric;
746 if (metric > MAX_WIDE_PATH_METRIC)
747 metric = MAX_WIDE_PATH_METRIC;
748 if (area->oldmetric && metric > 0x3f)
749 metric = 0x3f;
750
751 if (area->oldmetric)
752 isis_tlvs_add_oldstyle_ip_reach(lsp->tlvs, ipv4,
753 metric);
754 if (area->newmetric)
755 isis_tlvs_add_extended_ip_reach(lsp->tlvs, ipv4,
756 metric);
757 }
758 }
759
760 static void lsp_build_ext_reach_ipv6(struct isis_lsp *lsp,
761 struct isis_area *area)
762 {
763 struct route_table *er_table =
764 get_ext_reach(area, AF_INET6, lsp->level);
765 if (!er_table)
766 return;
767
768 for (struct route_node *rn = route_top(er_table); rn;
769 rn = route_next(rn)) {
770 if (!rn->info)
771 continue;
772
773 struct prefix_ipv6 *ipv6 = (struct prefix_ipv6 *)&rn->p;
774 struct isis_ext_info *info = rn->info;
775
776 uint32_t metric = info->metric;
777 if (info->metric > MAX_WIDE_PATH_METRIC)
778 metric = MAX_WIDE_PATH_METRIC;
779 isis_tlvs_add_ipv6_reach(
780 lsp->tlvs, isis_area_ipv6_topology(area), ipv6, metric);
781 }
782 }
783
784 static void lsp_build_ext_reach(struct isis_lsp *lsp, struct isis_area *area)
785 {
786 lsp_build_ext_reach_ipv4(lsp, area);
787 lsp_build_ext_reach_ipv6(lsp, area);
788 }
789
790 static struct isis_lsp *lsp_next_frag(uint8_t frag_num, struct isis_lsp *lsp0,
791 struct isis_area *area, int level)
792 {
793 struct isis_lsp *lsp;
794 uint8_t frag_id[ISIS_SYS_ID_LEN + 2];
795
796 memcpy(frag_id, lsp0->hdr.lsp_id, ISIS_SYS_ID_LEN + 1);
797 LSP_FRAGMENT(frag_id) = frag_num;
798
799 lsp = lsp_search(frag_id, area->lspdb[level - 1]);
800 if (lsp) {
801 lsp_clear_data(lsp);
802 if (!lsp->lspu.zero_lsp)
803 lsp_link_fragment(lsp, lsp0);
804 return lsp;
805 }
806
807 lsp = lsp_new(area, frag_id, lsp0->hdr.rem_lifetime, 0,
808 lsp_bits_generate(level, area->overload_bit,
809 area->attached_bit),
810 0, lsp0, level);
811 lsp->own_lsp = 1;
812 lsp_insert(lsp, area->lspdb[level - 1]);
813 return lsp;
814 }
815
816 /*
817 * Builds the LSP data part. This func creates a new frag whenever
818 * area->lsp_frag_threshold is exceeded.
819 */
820 static void lsp_build(struct isis_lsp *lsp, struct isis_area *area)
821 {
822 int level = lsp->level;
823 char buf[PREFIX2STR_BUFFER];
824 struct listnode *node;
825 struct isis_lsp *frag;
826
827 lsp_clear_data(lsp);
828 for (ALL_LIST_ELEMENTS_RO(lsp->lspu.frags, node, frag))
829 lsp_clear_data(frag);
830
831 lsp->tlvs = isis_alloc_tlvs();
832 lsp_debug("ISIS (%s): Constructing local system LSP for level %d",
833 area->area_tag, level);
834
835 lsp->hdr.lsp_bits = lsp_bits_generate(level, area->overload_bit,
836 area->attached_bit);
837
838 lsp_add_auth(lsp);
839
840 isis_tlvs_add_area_addresses(lsp->tlvs, area->area_addrs);
841
842 /* Protocols Supported */
843 if (area->ip_circuits > 0 || area->ipv6_circuits > 0) {
844 struct nlpids nlpids = {.count = 0};
845 if (area->ip_circuits > 0) {
846 lsp_debug(
847 "ISIS (%s): Found IPv4 circuit, adding IPv4 to NLPIDs",
848 area->area_tag);
849 nlpids.nlpids[nlpids.count] = NLPID_IP;
850 nlpids.count++;
851 }
852 if (area->ipv6_circuits > 0) {
853 lsp_debug(
854 "ISIS (%s): Found IPv6 circuit, adding IPv6 to NLPIDs",
855 area->area_tag);
856 nlpids.nlpids[nlpids.count] = NLPID_IPV6;
857 nlpids.count++;
858 }
859 isis_tlvs_set_protocols_supported(lsp->tlvs, &nlpids);
860 }
861
862 if (area_is_mt(area)) {
863 lsp_debug("ISIS (%s): Adding MT router tlv...", area->area_tag);
864
865 struct isis_area_mt_setting **mt_settings;
866 unsigned int mt_count;
867
868 mt_settings = area_mt_settings(area, &mt_count);
869 for (unsigned int i = 0; i < mt_count; i++) {
870 isis_tlvs_add_mt_router_info(
871 lsp->tlvs, mt_settings[i]->mtid,
872 mt_settings[i]->overload, false);
873 lsp_debug("ISIS (%s): MT %s", area->area_tag,
874 isis_mtid2str(mt_settings[i]->mtid));
875 }
876 } else {
877 lsp_debug("ISIS (%s): Not adding MT router tlv (disabled)",
878 area->area_tag);
879 }
880 /* Dynamic Hostname */
881 if (area->dynhostname) {
882 isis_tlvs_set_dynamic_hostname(lsp->tlvs, cmd_hostname_get());
883 lsp_debug("ISIS (%s): Adding dynamic hostname '%s'",
884 area->area_tag, cmd_hostname_get());
885 } else {
886 lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)",
887 area->area_tag);
888 }
889
890 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
891 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put
892 * into
893 * LSP and this address is same as router id. */
894 if (isis->router_id != 0) {
895 struct in_addr id = {.s_addr = isis->router_id};
896 inet_ntop(AF_INET, &id, buf, sizeof(buf));
897 lsp_debug("ISIS (%s): Adding router ID %s as IPv4 tlv.",
898 area->area_tag, buf);
899 isis_tlvs_add_ipv4_address(lsp->tlvs, &id);
900
901 /* Exactly same data is put into TE router ID TLV, but only if
902 * new style
903 * TLV's are in use. */
904 if (area->newmetric) {
905
906 lsp_debug(
907 "ISIS (%s): Adding router ID also as TE router ID tlv.",
908 area->area_tag);
909 isis_tlvs_set_te_router_id(lsp->tlvs, &id);
910 }
911 } else {
912 lsp_debug("ISIS (%s): Router ID is unset. Not adding tlv.",
913 area->area_tag);
914 }
915
916 lsp_debug("ISIS (%s): Adding circuit specific information.",
917 area->area_tag);
918
919 struct isis_circuit *circuit;
920 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
921 if (!circuit->interface)
922 lsp_debug(
923 "ISIS (%s): Processing %s circuit %p with unknown interface",
924 area->area_tag,
925 circuit_type2string(circuit->circ_type),
926 circuit);
927 else
928 lsp_debug("ISIS (%s): Processing %s circuit %s",
929 area->area_tag,
930 circuit_type2string(circuit->circ_type),
931 circuit->interface->name);
932
933 if (circuit->state != C_STATE_UP) {
934 lsp_debug("ISIS (%s): Circuit is not up, ignoring.",
935 area->area_tag);
936 continue;
937 }
938
939 uint32_t metric = area->oldmetric
940 ? circuit->metric[level - 1]
941 : circuit->te_metric[level - 1];
942
943 if (circuit->ip_router && circuit->ip_addrs
944 && circuit->ip_addrs->count > 0) {
945 lsp_debug(
946 "ISIS (%s): Circuit has IPv4 active, adding respective TLVs.",
947 area->area_tag);
948 struct listnode *ipnode;
949 struct prefix_ipv4 *ipv4;
950 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, ipnode,
951 ipv4)) {
952 if (area->oldmetric) {
953 lsp_debug(
954 "ISIS (%s): Adding old-style IP reachability for %s",
955 area->area_tag,
956 prefix2str(ipv4, buf,
957 sizeof(buf)));
958 isis_tlvs_add_oldstyle_ip_reach(
959 lsp->tlvs, ipv4, metric);
960 }
961
962 if (area->newmetric) {
963 lsp_debug(
964 "ISIS (%s): Adding te-style IP reachability for %s",
965 area->area_tag,
966 prefix2str(ipv4, buf,
967 sizeof(buf)));
968 isis_tlvs_add_extended_ip_reach(
969 lsp->tlvs, ipv4, metric);
970 }
971 }
972 }
973
974 if (circuit->ipv6_router && circuit->ipv6_non_link
975 && circuit->ipv6_non_link->count > 0) {
976 struct listnode *ipnode;
977 struct prefix_ipv6 *ipv6;
978 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link,
979 ipnode, ipv6)) {
980 lsp_debug(
981 "ISIS (%s): Adding IPv6 reachability for %s",
982 area->area_tag,
983 prefix2str(ipv6, buf, sizeof(buf)));
984 isis_tlvs_add_ipv6_reach(
985 lsp->tlvs,
986 isis_area_ipv6_topology(area), ipv6,
987 metric);
988 }
989 }
990
991 switch (circuit->circ_type) {
992 case CIRCUIT_T_BROADCAST:
993 if (level & circuit->is_type) {
994 uint8_t *ne_id =
995 (level == IS_LEVEL_1)
996 ? circuit->u.bc.l1_desig_is
997 : circuit->u.bc.l2_desig_is;
998
999 if (LSP_PSEUDO_ID(ne_id)) {
1000 if (area->oldmetric) {
1001 lsp_debug(
1002 "ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1003 area->area_tag,
1004 sysid_print(ne_id),
1005 LSP_PSEUDO_ID(ne_id));
1006 isis_tlvs_add_oldstyle_reach(
1007 lsp->tlvs, ne_id,
1008 metric);
1009 }
1010 if (area->newmetric) {
1011 uint8_t subtlvs[256];
1012 uint8_t subtlv_len;
1013
1014 if (IS_MPLS_TE(isisMplsTE)
1015 && HAS_LINK_PARAMS(
1016 circuit->interface))
1017 subtlv_len = add_te_subtlvs(
1018 subtlvs,
1019 circuit->mtc);
1020 else
1021 subtlv_len = 0;
1022
1023 tlvs_add_mt_bcast(
1024 lsp->tlvs, circuit,
1025 level, ne_id, metric,
1026 subtlvs, subtlv_len);
1027 }
1028 }
1029 } else {
1030 lsp_debug(
1031 "ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1032 area->area_tag);
1033 }
1034 break;
1035 case CIRCUIT_T_P2P: {
1036 struct isis_adjacency *nei = circuit->u.p2p.neighbor;
1037 if (nei && (level & nei->circuit_t)) {
1038 uint8_t ne_id[7];
1039 memcpy(ne_id, nei->sysid, ISIS_SYS_ID_LEN);
1040 LSP_PSEUDO_ID(ne_id) = 0;
1041
1042 if (area->oldmetric) {
1043 lsp_debug(
1044 "ISIS (%s): Adding old-style is reach for %s",
1045 area->area_tag,
1046 sysid_print(ne_id));
1047 isis_tlvs_add_oldstyle_reach(
1048 lsp->tlvs, ne_id, metric);
1049 }
1050 if (area->newmetric) {
1051 uint8_t subtlvs[256];
1052 uint8_t subtlv_len;
1053
1054 if (IS_MPLS_TE(isisMplsTE)
1055 && HAS_LINK_PARAMS(
1056 circuit->interface))
1057 /* Update Local and Remote IP
1058 * address for MPLS TE circuit
1059 * parameters */
1060 /* NOTE sure that it is the
1061 * pertinent place for that
1062 * updates */
1063 /* Local IP address could be
1064 * updated in isis_circuit.c -
1065 * isis_circuit_add_addr() */
1066 /* But, where update remote IP
1067 * address ? in isis_pdu.c -
1068 * process_p2p_hello() ? */
1069
1070 /* Add SubTLVs & Adjust real
1071 * size of SubTLVs */
1072 subtlv_len = add_te_subtlvs(
1073 subtlvs, circuit->mtc);
1074 else
1075 /* Or keep only TE metric with
1076 * no SubTLVs if MPLS_TE is off
1077 */
1078 subtlv_len = 0;
1079
1080 tlvs_add_mt_p2p(lsp->tlvs, circuit,
1081 ne_id, metric, subtlvs,
1082 subtlv_len);
1083 }
1084 } else {
1085 lsp_debug(
1086 "ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1087 area->area_tag);
1088 }
1089 } break;
1090 case CIRCUIT_T_LOOPBACK:
1091 break;
1092 default:
1093 zlog_warn("lsp_area_create: unknown circuit type");
1094 }
1095 }
1096
1097 lsp_build_ext_reach(lsp, area);
1098
1099 struct isis_tlvs *tlvs = lsp->tlvs;
1100 lsp->tlvs = NULL;
1101
1102 lsp_pack_pdu(lsp);
1103 size_t tlv_space = STREAM_WRITEABLE(lsp->pdu) - LLC_LEN;
1104 lsp_clear_data(lsp);
1105
1106 struct list *fragments = isis_fragment_tlvs(tlvs, tlv_space);
1107 if (!fragments) {
1108 zlog_warn("BUG: could not fragment own LSP:");
1109 log_multiline(LOG_WARNING, " ", "%s", isis_format_tlvs(tlvs));
1110 isis_free_tlvs(tlvs);
1111 return;
1112 }
1113 isis_free_tlvs(tlvs);
1114
1115 bool fragment_overflow = false;
1116 frag = lsp;
1117 for (ALL_LIST_ELEMENTS_RO(fragments, node, tlvs)) {
1118 if (node != listhead(fragments)) {
1119 if (LSP_FRAGMENT(frag->hdr.lsp_id) == 255) {
1120 if (!fragment_overflow) {
1121 fragment_overflow = true;
1122 zlog_warn("ISIS (%s): Too much information for 256 fragments",
1123 area->area_tag);
1124 }
1125 isis_free_tlvs(tlvs);
1126 continue;
1127 }
1128
1129 frag = lsp_next_frag(LSP_FRAGMENT(frag->hdr.lsp_id) + 1,
1130 lsp, area, level);
1131 }
1132 frag->tlvs = tlvs;
1133 }
1134
1135 list_delete_and_null(&fragments);
1136 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...",
1137 area->area_tag);
1138 return;
1139 }
1140
1141 /*
1142 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
1143 */
1144 int lsp_generate(struct isis_area *area, int level)
1145 {
1146 struct isis_lsp *oldlsp, *newlsp;
1147 u_int32_t seq_num = 0;
1148 u_char lspid[ISIS_SYS_ID_LEN + 2];
1149 u_int16_t rem_lifetime, refresh_time;
1150
1151 if ((area == NULL) || (area->is_type & level) != level)
1152 return ISIS_ERROR;
1153
1154 memset(&lspid, 0, ISIS_SYS_ID_LEN + 2);
1155 memcpy(&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1156
1157 /* only builds the lsp if the area shares the level */
1158 oldlsp = lsp_search(lspid, area->lspdb[level - 1]);
1159 if (oldlsp) {
1160 /* FIXME: we should actually initiate a purge */
1161 seq_num = oldlsp->hdr.seqno;
1162 lsp_search_and_destroy(oldlsp->hdr.lsp_id,
1163 area->lspdb[level - 1]);
1164 }
1165 rem_lifetime = lsp_rem_lifetime(area, level);
1166 newlsp =
1167 lsp_new(area, lspid, rem_lifetime, seq_num,
1168 area->is_type | area->overload_bit | area->attached_bit,
1169 0, NULL, level);
1170 newlsp->area = area;
1171 newlsp->own_lsp = 1;
1172
1173 lsp_insert(newlsp, area->lspdb[level - 1]);
1174 /* build_lsp_data (newlsp, area); */
1175 lsp_build(newlsp, area);
1176 /* time to calculate our checksum */
1177 lsp_seqno_update(newlsp);
1178 newlsp->last_generated = time(NULL);
1179 lsp_set_all_srmflags(newlsp);
1180
1181 refresh_time = lsp_refresh_time(newlsp, rem_lifetime);
1182
1183 THREAD_TIMER_OFF(area->t_lsp_refresh[level - 1]);
1184 area->lsp_regenerate_pending[level - 1] = 0;
1185 if (level == IS_LEVEL_1)
1186 thread_add_timer(master, lsp_l1_refresh, area, refresh_time,
1187 &area->t_lsp_refresh[level - 1]);
1188 else if (level == IS_LEVEL_2)
1189 thread_add_timer(master, lsp_l2_refresh, area, refresh_time,
1190 &area->t_lsp_refresh[level - 1]);
1191
1192 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1193 zlog_debug("ISIS-Upd (%s): Building L%d LSP %s, len %" PRIu16
1194 ", seq 0x%08" PRIx32 ", cksum 0x%04" PRIx16
1195 ", lifetime %" PRIu16 "s refresh %" PRIu16 "s",
1196 area->area_tag, level,
1197 rawlspid_print(newlsp->hdr.lsp_id),
1198 newlsp->hdr.pdu_len, newlsp->hdr.seqno,
1199 newlsp->hdr.checksum, newlsp->hdr.rem_lifetime,
1200 refresh_time);
1201 }
1202 sched_debug(
1203 "ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1204 area->area_tag, level);
1205
1206 return ISIS_OK;
1207 }
1208
1209 /*
1210 * Search own LSPs, update holding time and set SRM
1211 */
1212 static int lsp_regenerate(struct isis_area *area, int level)
1213 {
1214 dict_t *lspdb;
1215 struct isis_lsp *lsp, *frag;
1216 struct listnode *node;
1217 u_char lspid[ISIS_SYS_ID_LEN + 2];
1218 u_int16_t rem_lifetime, refresh_time;
1219
1220 if ((area == NULL) || (area->is_type & level) != level)
1221 return ISIS_ERROR;
1222
1223 lspdb = area->lspdb[level - 1];
1224
1225 memset(lspid, 0, ISIS_SYS_ID_LEN + 2);
1226 memcpy(lspid, isis->sysid, ISIS_SYS_ID_LEN);
1227
1228 lsp = lsp_search(lspid, lspdb);
1229
1230 if (!lsp) {
1231 zlog_err("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1232 area->area_tag, level);
1233 return ISIS_ERROR;
1234 }
1235
1236 lsp_clear_data(lsp);
1237 lsp_build(lsp, area);
1238 rem_lifetime = lsp_rem_lifetime(area, level);
1239 lsp->hdr.rem_lifetime = rem_lifetime;
1240 lsp->last_generated = time(NULL);
1241 lsp_set_all_srmflags(lsp);
1242 for (ALL_LIST_ELEMENTS_RO(lsp->lspu.frags, node, frag)) {
1243 frag->hdr.lsp_bits = lsp_bits_generate(
1244 level, area->overload_bit, area->attached_bit);
1245 /* Set the lifetime values of all the fragments to the same
1246 * value,
1247 * so that no fragment expires before the lsp is refreshed.
1248 */
1249 frag->hdr.rem_lifetime = rem_lifetime;
1250 frag->age_out = ZERO_AGE_LIFETIME;
1251 lsp_set_all_srmflags(frag);
1252 }
1253 lsp_seqno_update(lsp);
1254
1255 refresh_time = lsp_refresh_time(lsp, rem_lifetime);
1256 if (level == IS_LEVEL_1)
1257 thread_add_timer(master, lsp_l1_refresh, area, refresh_time,
1258 &area->t_lsp_refresh[level - 1]);
1259 else if (level == IS_LEVEL_2)
1260 thread_add_timer(master, lsp_l2_refresh, area, refresh_time,
1261 &area->t_lsp_refresh[level - 1]);
1262 area->lsp_regenerate_pending[level - 1] = 0;
1263
1264 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1265 zlog_debug(
1266 "ISIS-Upd (%s): Refreshed our L%d LSP %s, len %" PRIu16
1267 ", seq 0x%08" PRIx32 ", cksum 0x%04" PRIx16
1268 ", lifetime %" PRIu16 "s refresh %" PRIu16 "s",
1269 area->area_tag, level, rawlspid_print(lsp->hdr.lsp_id),
1270 lsp->hdr.pdu_len, lsp->hdr.seqno, lsp->hdr.checksum,
1271 lsp->hdr.rem_lifetime, refresh_time);
1272 }
1273 sched_debug(
1274 "ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
1275 area->area_tag, level);
1276
1277 return ISIS_OK;
1278 }
1279
1280 /*
1281 * Something has changed or periodic refresh -> regenerate LSP
1282 */
1283 static int lsp_l1_refresh(struct thread *thread)
1284 {
1285 struct isis_area *area;
1286
1287 area = THREAD_ARG(thread);
1288 assert(area);
1289
1290 area->t_lsp_refresh[0] = NULL;
1291 area->lsp_regenerate_pending[0] = 0;
1292
1293 if ((area->is_type & IS_LEVEL_1) == 0)
1294 return ISIS_ERROR;
1295
1296 sched_debug(
1297 "ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...",
1298 area->area_tag);
1299 return lsp_regenerate(area, IS_LEVEL_1);
1300 }
1301
1302 static int lsp_l2_refresh(struct thread *thread)
1303 {
1304 struct isis_area *area;
1305
1306 area = THREAD_ARG(thread);
1307 assert(area);
1308
1309 area->t_lsp_refresh[1] = NULL;
1310 area->lsp_regenerate_pending[1] = 0;
1311
1312 if ((area->is_type & IS_LEVEL_2) == 0)
1313 return ISIS_ERROR;
1314
1315 sched_debug(
1316 "ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...",
1317 area->area_tag);
1318 return lsp_regenerate(area, IS_LEVEL_2);
1319 }
1320
1321 int lsp_regenerate_schedule(struct isis_area *area, int level, int all_pseudo)
1322 {
1323 struct isis_lsp *lsp;
1324 u_char id[ISIS_SYS_ID_LEN + 2];
1325 time_t now, diff;
1326 long timeout;
1327 struct listnode *cnode;
1328 struct isis_circuit *circuit;
1329 int lvl;
1330
1331 if (area == NULL)
1332 return ISIS_ERROR;
1333
1334 sched_debug(
1335 "ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs",
1336 area->area_tag, circuit_t2string(level),
1337 all_pseudo ? "" : "not ");
1338
1339 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
1340 LSP_PSEUDO_ID(id) = LSP_FRAGMENT(id) = 0;
1341 now = time(NULL);
1342
1343 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++) {
1344 if (!((level & lvl) && (area->is_type & lvl)))
1345 continue;
1346
1347 sched_debug(
1348 "ISIS (%s): Checking whether L%d needs to be scheduled",
1349 area->area_tag, lvl);
1350
1351 if (area->lsp_regenerate_pending[lvl - 1]) {
1352 struct timeval remain = thread_timer_remain(
1353 area->t_lsp_refresh[lvl - 1]);
1354 sched_debug(
1355 "ISIS (%s): Regeneration is already pending, nothing todo."
1356 " (Due in %lld.%03lld seconds)",
1357 area->area_tag, (long long)remain.tv_sec,
1358 (long long)remain.tv_usec / 1000);
1359 continue;
1360 }
1361
1362 lsp = lsp_search(id, area->lspdb[lvl - 1]);
1363 if (!lsp) {
1364 sched_debug(
1365 "ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
1366 area->area_tag);
1367 continue;
1368 }
1369
1370 /*
1371 * Throttle avoidance
1372 */
1373 sched_debug(
1374 "ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
1375 area->area_tag, (long long)lsp->last_generated,
1376 (long long)now);
1377 THREAD_TIMER_OFF(area->t_lsp_refresh[lvl - 1]);
1378 diff = now - lsp->last_generated;
1379 if (diff < area->lsp_gen_interval[lvl - 1]) {
1380 timeout =
1381 1000 * (area->lsp_gen_interval[lvl - 1] - diff);
1382 sched_debug(
1383 "ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
1384 area->area_tag, timeout);
1385 } else {
1386 /*
1387 * lsps are not regenerated if lsp_regenerate function
1388 * is called
1389 * directly. However if the lsp_regenerate call is
1390 * queued for
1391 * later execution it works.
1392 */
1393 timeout = 100;
1394 sched_debug(
1395 "ISIS (%s): Last generation was more than lsp_gen_interval ago."
1396 " Scheduling for execution in %ld ms.",
1397 area->area_tag, timeout);
1398 }
1399
1400 area->lsp_regenerate_pending[lvl - 1] = 1;
1401 if (lvl == IS_LEVEL_1) {
1402 thread_add_timer_msec(master, lsp_l1_refresh, area,
1403 timeout,
1404 &area->t_lsp_refresh[lvl - 1]);
1405 } else if (lvl == IS_LEVEL_2) {
1406 thread_add_timer_msec(master, lsp_l2_refresh, area,
1407 timeout,
1408 &area->t_lsp_refresh[lvl - 1]);
1409 }
1410 }
1411
1412 if (all_pseudo) {
1413 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit))
1414 lsp_regenerate_schedule_pseudo(circuit, level);
1415 }
1416
1417 return ISIS_OK;
1418 }
1419
1420 /*
1421 * Funcs for pseudonode LSPs
1422 */
1423
1424 /*
1425 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1426 */
1427 static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
1428 int level)
1429 {
1430 struct isis_adjacency *adj;
1431 struct list *adj_list;
1432 struct listnode *node;
1433 struct isis_area *area = circuit->area;
1434
1435 lsp_clear_data(lsp);
1436 lsp->tlvs = isis_alloc_tlvs();
1437 lsp_debug(
1438 "ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
1439 area->area_tag, rawlspid_print(lsp->hdr.lsp_id),
1440 circuit->interface->name, level);
1441
1442 lsp->level = level;
1443 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
1444 lsp->hdr.lsp_bits =
1445 lsp_bits_generate(level, 0, circuit->area->attached_bit);
1446
1447 /*
1448 * add self to IS neighbours
1449 */
1450 uint8_t ne_id[ISIS_SYS_ID_LEN + 1];
1451
1452 memcpy(ne_id, isis->sysid, ISIS_SYS_ID_LEN);
1453 LSP_PSEUDO_ID(ne_id) = 0;
1454
1455 if (circuit->area->oldmetric) {
1456 isis_tlvs_add_oldstyle_reach(lsp->tlvs, ne_id, 0);
1457 lsp_debug(
1458 "ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
1459 area->area_tag, sysid_print(ne_id),
1460 LSP_PSEUDO_ID(ne_id));
1461 }
1462 if (circuit->area->newmetric) {
1463 isis_tlvs_add_extended_reach(lsp->tlvs, ISIS_MT_IPV4_UNICAST,
1464 ne_id, 0, NULL, 0);
1465 lsp_debug(
1466 "ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
1467 area->area_tag, sysid_print(ne_id),
1468 LSP_PSEUDO_ID(ne_id));
1469 }
1470
1471 adj_list = list_new();
1472 isis_adj_build_up_list(circuit->u.bc.adjdb[level - 1], adj_list);
1473
1474 for (ALL_LIST_ELEMENTS_RO(adj_list, node, adj)) {
1475 if (!(adj->level & level)) {
1476 lsp_debug(
1477 "ISIS (%s): Ignoring neighbor %s, level does not intersect",
1478 area->area_tag, sysid_print(adj->sysid));
1479 continue;
1480 }
1481
1482 if (!(level == IS_LEVEL_1
1483 && adj->sys_type == ISIS_SYSTYPE_L1_IS)
1484 && !(level == IS_LEVEL_1
1485 && adj->sys_type == ISIS_SYSTYPE_L2_IS
1486 && adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
1487 && !(level == IS_LEVEL_2
1488 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) {
1489 lsp_debug(
1490 "ISIS (%s): Ignoring neighbor %s, level does not match",
1491 area->area_tag, sysid_print(adj->sysid));
1492 continue;
1493 }
1494
1495 memcpy(ne_id, adj->sysid, ISIS_SYS_ID_LEN);
1496 if (circuit->area->oldmetric) {
1497 isis_tlvs_add_oldstyle_reach(lsp->tlvs, ne_id, 0);
1498 lsp_debug(
1499 "ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
1500 area->area_tag, sysid_print(ne_id),
1501 LSP_PSEUDO_ID(ne_id));
1502 }
1503 if (circuit->area->newmetric) {
1504 isis_tlvs_add_extended_reach(lsp->tlvs,
1505 ISIS_MT_IPV4_UNICAST,
1506 ne_id, 0, NULL, 0);
1507 lsp_debug(
1508 "ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
1509 area->area_tag, sysid_print(ne_id),
1510 LSP_PSEUDO_ID(ne_id));
1511 }
1512 }
1513 list_delete_and_null(&adj_list);
1514 return;
1515 }
1516
1517 int lsp_generate_pseudo(struct isis_circuit *circuit, int level)
1518 {
1519 dict_t *lspdb = circuit->area->lspdb[level - 1];
1520 struct isis_lsp *lsp;
1521 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
1522 u_int16_t rem_lifetime, refresh_time;
1523
1524 if ((circuit->is_type & level) != level
1525 || (circuit->state != C_STATE_UP)
1526 || (circuit->circ_type != CIRCUIT_T_BROADCAST)
1527 || (circuit->u.bc.is_dr[level - 1] == 0))
1528 return ISIS_ERROR;
1529
1530 memcpy(lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1531 LSP_FRAGMENT(lsp_id) = 0;
1532 LSP_PSEUDO_ID(lsp_id) = circuit->circuit_id;
1533
1534 /*
1535 * If for some reason have a pseudo LSP in the db already -> regenerate
1536 */
1537 if (lsp_search(lsp_id, lspdb))
1538 return lsp_regenerate_schedule_pseudo(circuit, level);
1539
1540 rem_lifetime = lsp_rem_lifetime(circuit->area, level);
1541 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
1542 lsp = lsp_new(circuit->area, lsp_id, rem_lifetime, 1,
1543 circuit->area->is_type | circuit->area->attached_bit, 0,
1544 NULL, level);
1545 lsp->area = circuit->area;
1546
1547 lsp_build_pseudo(lsp, circuit, level);
1548 lsp_pack_pdu(lsp);
1549 lsp->own_lsp = 1;
1550 lsp_insert(lsp, lspdb);
1551 lsp_set_all_srmflags(lsp);
1552
1553 refresh_time = lsp_refresh_time(lsp, rem_lifetime);
1554 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1555 circuit->lsp_regenerate_pending[level - 1] = 0;
1556 if (level == IS_LEVEL_1)
1557 thread_add_timer(
1558 master, lsp_l1_refresh_pseudo, circuit, refresh_time,
1559 &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1560 else if (level == IS_LEVEL_2)
1561 thread_add_timer(
1562 master, lsp_l2_refresh_pseudo, circuit, refresh_time,
1563 &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1564
1565 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1566 zlog_debug(
1567 "ISIS-Upd (%s): Built L%d Pseudo LSP %s, len %" PRIu16
1568 ", seq 0x%08" PRIx32 ", cksum 0x%04" PRIx16
1569 ", lifetime %" PRIu16 "s, refresh %" PRIu16 "s",
1570 circuit->area->area_tag, level,
1571 rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.pdu_len,
1572 lsp->hdr.seqno, lsp->hdr.checksum,
1573 lsp->hdr.rem_lifetime, refresh_time);
1574 }
1575
1576 return ISIS_OK;
1577 }
1578
1579 static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level)
1580 {
1581 dict_t *lspdb = circuit->area->lspdb[level - 1];
1582 struct isis_lsp *lsp;
1583 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
1584 u_int16_t rem_lifetime, refresh_time;
1585
1586 if ((circuit->is_type & level) != level
1587 || (circuit->state != C_STATE_UP)
1588 || (circuit->circ_type != CIRCUIT_T_BROADCAST)
1589 || (circuit->u.bc.is_dr[level - 1] == 0))
1590 return ISIS_ERROR;
1591
1592 memcpy(lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1593 LSP_PSEUDO_ID(lsp_id) = circuit->circuit_id;
1594 LSP_FRAGMENT(lsp_id) = 0;
1595
1596 lsp = lsp_search(lsp_id, lspdb);
1597
1598 if (!lsp) {
1599 zlog_err("lsp_regenerate_pseudo: no l%d LSP %s found!", level,
1600 rawlspid_print(lsp_id));
1601 return ISIS_ERROR;
1602 }
1603
1604 rem_lifetime = lsp_rem_lifetime(circuit->area, level);
1605 lsp->hdr.rem_lifetime = rem_lifetime;
1606 lsp_build_pseudo(lsp, circuit, level);
1607 lsp_inc_seqno(lsp, 0);
1608 lsp->last_generated = time(NULL);
1609 lsp_set_all_srmflags(lsp);
1610
1611 refresh_time = lsp_refresh_time(lsp, rem_lifetime);
1612 if (level == IS_LEVEL_1)
1613 thread_add_timer(
1614 master, lsp_l1_refresh_pseudo, circuit, refresh_time,
1615 &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1616 else if (level == IS_LEVEL_2)
1617 thread_add_timer(
1618 master, lsp_l2_refresh_pseudo, circuit, refresh_time,
1619 &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1620
1621 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1622 zlog_debug(
1623 "ISIS-Upd (%s): Refreshed L%d Pseudo LSP %s, len %" PRIu16
1624 ", seq 0x%08" PRIx32 ", cksum 0x%04" PRIx16
1625 ", lifetime %" PRIu16 "s, refresh %" PRIu16 "s",
1626 circuit->area->area_tag, level,
1627 rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.pdu_len,
1628 lsp->hdr.seqno, lsp->hdr.checksum,
1629 lsp->hdr.rem_lifetime, refresh_time);
1630 }
1631
1632 return ISIS_OK;
1633 }
1634
1635 /*
1636 * Something has changed or periodic refresh -> regenerate pseudo LSP
1637 */
1638 static int lsp_l1_refresh_pseudo(struct thread *thread)
1639 {
1640 struct isis_circuit *circuit;
1641 u_char id[ISIS_SYS_ID_LEN + 2];
1642
1643 circuit = THREAD_ARG(thread);
1644
1645 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
1646 circuit->lsp_regenerate_pending[0] = 0;
1647
1648 if ((circuit->u.bc.is_dr[0] == 0)
1649 || (circuit->is_type & IS_LEVEL_1) == 0) {
1650 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
1651 LSP_PSEUDO_ID(id) = circuit->circuit_id;
1652 LSP_FRAGMENT(id) = 0;
1653 lsp_purge_pseudo(id, circuit, IS_LEVEL_1);
1654 return ISIS_ERROR;
1655 }
1656
1657 return lsp_regenerate_pseudo(circuit, IS_LEVEL_1);
1658 }
1659
1660 static int lsp_l2_refresh_pseudo(struct thread *thread)
1661 {
1662 struct isis_circuit *circuit;
1663 u_char id[ISIS_SYS_ID_LEN + 2];
1664
1665 circuit = THREAD_ARG(thread);
1666
1667 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
1668 circuit->lsp_regenerate_pending[1] = 0;
1669
1670 if ((circuit->u.bc.is_dr[1] == 0)
1671 || (circuit->is_type & IS_LEVEL_2) == 0) {
1672 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
1673 LSP_PSEUDO_ID(id) = circuit->circuit_id;
1674 LSP_FRAGMENT(id) = 0;
1675 lsp_purge_pseudo(id, circuit, IS_LEVEL_2);
1676 return ISIS_ERROR;
1677 }
1678
1679 return lsp_regenerate_pseudo(circuit, IS_LEVEL_2);
1680 }
1681
1682 int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level)
1683 {
1684 struct isis_lsp *lsp;
1685 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
1686 time_t now, diff;
1687 long timeout;
1688 int lvl;
1689 struct isis_area *area = circuit->area;
1690
1691 if (circuit->circ_type != CIRCUIT_T_BROADCAST
1692 || circuit->state != C_STATE_UP)
1693 return ISIS_OK;
1694
1695 sched_debug(
1696 "ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
1697 area->area_tag, circuit_t2string(level),
1698 circuit->interface->name);
1699
1700 memcpy(lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1701 LSP_PSEUDO_ID(lsp_id) = circuit->circuit_id;
1702 LSP_FRAGMENT(lsp_id) = 0;
1703 now = time(NULL);
1704
1705 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++) {
1706 sched_debug(
1707 "ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
1708 area->area_tag, lvl);
1709
1710 if (!((level & lvl) && (circuit->is_type & lvl))) {
1711 sched_debug("ISIS (%s): Level is not active on circuit",
1712 area->area_tag);
1713 continue;
1714 }
1715
1716 if (circuit->u.bc.is_dr[lvl - 1] == 0) {
1717 sched_debug(
1718 "ISIS (%s): This IS is not DR, nothing to do.",
1719 area->area_tag);
1720 continue;
1721 }
1722
1723 if (circuit->lsp_regenerate_pending[lvl - 1]) {
1724 struct timeval remain = thread_timer_remain(
1725 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
1726 sched_debug(
1727 "ISIS (%s): Regenerate is already pending, nothing todo."
1728 " (Due in %lld.%03lld seconds)",
1729 area->area_tag, (long long)remain.tv_sec,
1730 (long long)remain.tv_usec / 1000);
1731 continue;
1732 }
1733
1734 lsp = lsp_search(lsp_id, circuit->area->lspdb[lvl - 1]);
1735 if (!lsp) {
1736 sched_debug(
1737 "ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
1738 area->area_tag);
1739 continue;
1740 }
1741
1742 /*
1743 * Throttle avoidance
1744 */
1745 sched_debug(
1746 "ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
1747 area->area_tag, (long long)lsp->last_generated,
1748 (long long)now);
1749 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
1750 diff = now - lsp->last_generated;
1751 if (diff < circuit->area->lsp_gen_interval[lvl - 1]) {
1752 timeout =
1753 1000 * (circuit->area->lsp_gen_interval[lvl - 1]
1754 - diff);
1755 sched_debug(
1756 "ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
1757 area->area_tag, timeout);
1758 } else {
1759 timeout = 100;
1760 sched_debug(
1761 "ISIS (%s): Last generation was more than lsp_gen_interval ago."
1762 " Scheduling for execution in %ld ms.",
1763 area->area_tag, timeout);
1764 }
1765
1766 circuit->lsp_regenerate_pending[lvl - 1] = 1;
1767
1768 if (lvl == IS_LEVEL_1) {
1769 thread_add_timer_msec(
1770 master, lsp_l1_refresh_pseudo, circuit, timeout,
1771 &circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
1772 } else if (lvl == IS_LEVEL_2) {
1773 thread_add_timer_msec(
1774 master, lsp_l2_refresh_pseudo, circuit, timeout,
1775 &circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
1776 }
1777 }
1778
1779 return ISIS_OK;
1780 }
1781
1782 /*
1783 * Walk through LSPs for an area
1784 * - set remaining lifetime
1785 * - set LSPs with SRMflag set for sending
1786 */
1787 int lsp_tick(struct thread *thread)
1788 {
1789 struct isis_area *area;
1790 struct isis_circuit *circuit;
1791 struct isis_lsp *lsp;
1792 struct list *lsp_list;
1793 struct listnode *lspnode, *cnode;
1794 dnode_t *dnode, *dnode_next;
1795 int level;
1796 u_int16_t rem_lifetime;
1797 time_t now = monotime(NULL);
1798
1799 lsp_list = list_new();
1800
1801 area = THREAD_ARG(thread);
1802 assert(area);
1803 area->t_tick = NULL;
1804 thread_add_timer(master, lsp_tick, area, 1, &area->t_tick);
1805
1806 /*
1807 * Build a list of LSPs with (any) SRMflag set
1808 * and removed the ones that have aged out
1809 */
1810 for (level = 0; level < ISIS_LEVELS; level++) {
1811 if (area->lspdb[level] && dict_count(area->lspdb[level]) > 0) {
1812 for (dnode = dict_first(area->lspdb[level]);
1813 dnode != NULL; dnode = dnode_next) {
1814 dnode_next =
1815 dict_next(area->lspdb[level], dnode);
1816 lsp = dnode_get(dnode);
1817
1818 /*
1819 * The lsp rem_lifetime is kept at 0 for MaxAge
1820 * or
1821 * ZeroAgeLifetime depending on explicit purge
1822 * or
1823 * natural age out. So schedule spf only once
1824 * when
1825 * the first time rem_lifetime becomes 0.
1826 */
1827 rem_lifetime = lsp->hdr.rem_lifetime;
1828 lsp_set_time(lsp);
1829
1830 /*
1831 * Schedule may run spf which should be done
1832 * only after
1833 * the lsp rem_lifetime becomes 0 for the first
1834 * time.
1835 * ISO 10589 - 7.3.16.4 first paragraph.
1836 */
1837 if (rem_lifetime == 1 && lsp->hdr.seqno != 0) {
1838 /* 7.3.16.4 a) set SRM flags on all */
1839 lsp_set_all_srmflags(lsp);
1840 /* 7.3.16.4 b) retain only the header
1841 * FIXME */
1842 /* 7.3.16.4 c) record the time to purge
1843 * FIXME */
1844 /* run/schedule spf */
1845 /* isis_spf_schedule is called inside
1846 * lsp_destroy() below;
1847 * so it is not needed here. */
1848 /* isis_spf_schedule (lsp->area,
1849 * lsp->level); */
1850 }
1851
1852 if (lsp->age_out == 0) {
1853 zlog_debug(
1854 "ISIS-Upd (%s): L%u LSP %s seq "
1855 "0x%08" PRIx32 " aged out",
1856 area->area_tag, lsp->level,
1857 rawlspid_print(lsp->hdr.lsp_id),
1858 lsp->hdr.seqno);
1859 lsp_destroy(lsp);
1860 lsp = NULL;
1861 dict_delete_free(area->lspdb[level],
1862 dnode);
1863 } else if (flags_any_set(lsp->SRMflags))
1864 listnode_add(lsp_list, lsp);
1865 }
1866
1867 /*
1868 * Send LSPs on circuits indicated by the SRMflags
1869 */
1870 if (listcount(lsp_list) > 0) {
1871 for (ALL_LIST_ELEMENTS_RO(area->circuit_list,
1872 cnode, circuit)) {
1873 if (!circuit->lsp_queue)
1874 continue;
1875
1876 if (now - circuit->lsp_queue_last_push[level]
1877 < MIN_LSP_RETRANS_INTERVAL) {
1878 continue;
1879 }
1880
1881 circuit->lsp_queue_last_push[level] = now;
1882
1883 for (ALL_LIST_ELEMENTS_RO(
1884 lsp_list, lspnode, lsp)) {
1885 if (circuit->upadjcount
1886 [lsp->level - 1]
1887 && ISIS_CHECK_FLAG(
1888 lsp->SRMflags,
1889 circuit)) {
1890 isis_circuit_queue_lsp(circuit, lsp);
1891 }
1892 }
1893 }
1894 list_delete_all_node(lsp_list);
1895 }
1896 }
1897 }
1898
1899 list_delete_and_null(&lsp_list);
1900
1901 return ISIS_OK;
1902 }
1903
1904 void lsp_purge_pseudo(u_char *id, struct isis_circuit *circuit, int level)
1905 {
1906 struct isis_lsp *lsp;
1907
1908 lsp = lsp_search(id, circuit->area->lspdb[level - 1]);
1909 if (!lsp)
1910 return;
1911
1912 lsp_purge(lsp, level);
1913 }
1914
1915 /*
1916 * Purge own LSP that is received and we don't have.
1917 * -> Do as in 7.3.16.4
1918 */
1919 void lsp_purge_non_exist(int level, struct isis_lsp_hdr *hdr,
1920 struct isis_area *area)
1921 {
1922 struct isis_lsp *lsp;
1923
1924 /*
1925 * We need to create the LSP to be purged
1926 */
1927 lsp = XCALLOC(MTYPE_ISIS_LSP, sizeof(struct isis_lsp));
1928 lsp->area = area;
1929 lsp->level = level;
1930 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
1931 lsp->age_out = ZERO_AGE_LIFETIME;
1932
1933 memcpy(&lsp->hdr, hdr, sizeof(lsp->hdr));
1934 lsp->hdr.rem_lifetime = 0;
1935
1936 lsp_pack_pdu(lsp);
1937
1938 lsp_insert(lsp, area->lspdb[lsp->level - 1]);
1939 lsp_set_all_srmflags(lsp);
1940
1941 return;
1942 }
1943
1944 void lsp_set_all_srmflags(struct isis_lsp *lsp)
1945 {
1946 struct listnode *node;
1947 struct isis_circuit *circuit;
1948
1949 assert(lsp);
1950
1951 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
1952
1953 if (lsp->area) {
1954 struct list *circuit_list = lsp->area->circuit_list;
1955 for (ALL_LIST_ELEMENTS_RO(circuit_list, node, circuit)) {
1956 ISIS_SET_FLAG(lsp->SRMflags, circuit);
1957 }
1958 }
1959 }