]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_pdu.c
Merge pull request #5625 from qlyoung/fix-zapi-ipset-name-nullterm
[mirror_frr.git] / isisd / isis_pdu.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_pdu.c
3 * PDU processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <zebra.h>
25
26 #include "memory.h"
27 #include "thread.h"
28 #include "linklist.h"
29 #include "log.h"
30 #include "stream.h"
31 #include "vty.h"
32 #include "hash.h"
33 #include "prefix.h"
34 #include "if.h"
35 #include "checksum.h"
36 #include "md5.h"
37 #include "lib_errors.h"
38
39 #include "isisd/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_network.h"
45 #include "isisd/isis_misc.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_dynhn.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/iso_checksum.h"
52 #include "isisd/isis_csm.h"
53 #include "isisd/isis_events.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
57 #include "isisd/isis_errors.h"
58 #include "isisd/fabricd.h"
59 #include "isisd/isis_tx_queue.h"
60 #include "isisd/isis_pdu_counter.h"
61 #include "isisd/isis_nb.h"
62
63 static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit,
64 int level)
65 {
66 unsigned long lenp;
67 int retval;
68 uint16_t length;
69 uint8_t pdu_type =
70 (level == IS_LEVEL_1) ? L1_PARTIAL_SEQ_NUM : L2_PARTIAL_SEQ_NUM;
71
72 isis_circuit_stream(circuit, &circuit->snd_stream);
73
74 fill_fixed_hdr(pdu_type, circuit->snd_stream);
75
76 lenp = stream_get_endp(circuit->snd_stream);
77 stream_putw(circuit->snd_stream, 0); /* PDU length */
78 stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
79 stream_putc(circuit->snd_stream, circuit->idx);
80 stream_putc(circuit->snd_stream, 9); /* code */
81 stream_putc(circuit->snd_stream, 16); /* len */
82
83 stream_putw(circuit->snd_stream, hdr->rem_lifetime);
84 stream_put(circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
85 stream_putl(circuit->snd_stream, hdr->seqno);
86 stream_putw(circuit->snd_stream, hdr->checksum);
87
88 length = (uint16_t)stream_get_endp(circuit->snd_stream);
89 /* Update PDU length */
90 stream_putw_at(circuit->snd_stream, lenp, length);
91
92 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
93 retval = circuit->tx(circuit, level);
94 if (retval != ISIS_OK)
95 flog_err(EC_ISIS_PACKET,
96 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
97 circuit->area->area_tag, level,
98 circuit->interface->name);
99
100 return retval;
101 }
102
103 /*
104 * RECEIVE SIDE
105 */
106
107 struct iih_info {
108 struct isis_circuit *circuit;
109 uint8_t *ssnpa;
110 int level;
111
112 uint8_t circ_type;
113 uint8_t sys_id[ISIS_SYS_ID_LEN];
114 uint16_t holdtime;
115 uint16_t pdu_len;
116
117 uint8_t circuit_id;
118
119 uint8_t priority;
120 uint8_t dis[ISIS_SYS_ID_LEN + 1];
121
122 bool v4_usable;
123 bool v6_usable;
124
125 struct isis_tlvs *tlvs;
126 };
127
128 static int process_p2p_hello(struct iih_info *iih)
129 {
130 struct isis_threeway_adj *tw_adj = iih->tlvs->threeway_adj;
131 if (tw_adj) {
132 if (tw_adj->state > ISIS_THREEWAY_DOWN) {
133 if (isis->debugs & DEBUG_ADJ_PACKETS) {
134 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
135 iih->circuit->area->area_tag,
136 iih->circuit->interface->name,
137 tw_adj->state);
138 }
139 return ISIS_WARNING;
140 }
141
142 if (tw_adj->neighbor_set
143 && (memcmp(tw_adj->neighbor_id, isis->sysid, ISIS_SYS_ID_LEN)
144 || tw_adj->neighbor_circuit_id != (uint32_t) iih->circuit->idx)) {
145
146 if (isis->debugs & DEBUG_ADJ_PACKETS) {
147 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
148 iih->circuit->area->area_tag,
149 iih->circuit->interface->name);
150 }
151
152 return ISIS_WARNING;
153 }
154 }
155
156 /*
157 * My interpertation of the ISO, if no adj exists we will create one for
158 * the circuit
159 */
160 struct isis_adjacency *adj = iih->circuit->u.p2p.neighbor;
161 /* If an adjacency exists, check it is with the source of the hello
162 * packets */
163 if (adj) {
164 if (memcmp(iih->sys_id, adj->sysid, ISIS_SYS_ID_LEN)) {
165 zlog_debug(
166 "hello source and adjacency do not match, set adj down\n");
167 isis_adj_state_change(adj, ISIS_ADJ_DOWN,
168 "adj do not exist");
169 return ISIS_OK;
170 }
171 }
172 if (!adj || adj->level != iih->circ_type) {
173 if (!adj) {
174 adj = isis_new_adj(iih->sys_id, NULL, iih->circ_type,
175 iih->circuit);
176 } else {
177 adj->level = iih->circ_type;
178 }
179 iih->circuit->u.p2p.neighbor = adj;
180 /* Build lsp with the new neighbor entry when a new
181 * adjacency is formed. Set adjacency circuit type to
182 * IIH PDU header circuit type before lsp is regenerated
183 * when an adjacency is up. This will result in the new
184 * adjacency entry getting added to the lsp tlv neighbor list.
185 */
186 adj->circuit_t = iih->circ_type;
187 isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL);
188 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
189 }
190
191 if (tw_adj)
192 adj->ext_circuit_id = tw_adj->local_circuit_id;
193
194 /* 8.2.6 Monitoring point-to-point adjacencies */
195 adj->hold_time = iih->holdtime;
196 adj->last_upd = time(NULL);
197
198 bool changed;
199 isis_tlvs_to_adj(iih->tlvs, adj, &changed);
200 changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable,
201 adj);
202
203 /* lets take care of the expiry */
204 THREAD_TIMER_OFF(adj->t_expire);
205 thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
206 &adj->t_expire);
207
208 /* While fabricds initial sync is in progress, ignore hellos from other
209 * interfaces than the one we are performing the initial sync on. */
210 if (fabricd_initial_sync_is_in_progress(iih->circuit->area)
211 && fabricd_initial_sync_circuit(iih->circuit->area) != iih->circuit)
212 return ISIS_OK;
213
214 /* 8.2.5.2 a) a match was detected */
215 if (isis_tlvs_area_addresses_match(iih->tlvs,
216 iih->circuit->area->area_addrs)) {
217 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
218 if (iih->circuit->area->is_type == IS_LEVEL_1) {
219 switch (iih->circ_type) {
220 case IS_LEVEL_1:
221 case IS_LEVEL_1_AND_2:
222 if (adj->adj_state != ISIS_ADJ_UP
223 || adj->adj_usage == ISIS_ADJ_LEVEL1) {
224 isis_adj_process_threeway(adj, tw_adj,
225 ISIS_ADJ_LEVEL1);
226 }
227 break;
228 case IS_LEVEL_2:
229 if (adj->adj_state != ISIS_ADJ_UP) {
230 /* (7) reject - wrong system type event
231 */
232 zlog_warn("wrongSystemType");
233 return ISIS_WARNING;
234 } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
235 /* (6) down - wrong system */
236 isis_adj_state_change(adj,
237 ISIS_ADJ_DOWN,
238 "Wrong System");
239 }
240 break;
241 }
242 }
243
244 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
245 if (iih->circuit->area->is_type == IS_LEVEL_1_AND_2) {
246 switch (iih->circ_type) {
247 case IS_LEVEL_1:
248 if (adj->adj_state != ISIS_ADJ_UP
249 || adj->adj_usage == ISIS_ADJ_LEVEL1) {
250 isis_adj_process_threeway(adj, tw_adj,
251 ISIS_ADJ_LEVEL1);
252 } else if ((adj->adj_usage
253 == ISIS_ADJ_LEVEL1AND2)
254 || (adj->adj_usage
255 == ISIS_ADJ_LEVEL2)) {
256 /* (8) down - wrong system */
257 isis_adj_state_change(adj,
258 ISIS_ADJ_DOWN,
259 "Wrong System");
260 }
261 break;
262 case IS_LEVEL_2:
263 if (adj->adj_state != ISIS_ADJ_UP
264 || adj->adj_usage == ISIS_ADJ_LEVEL2) {
265 isis_adj_process_threeway(adj, tw_adj,
266 ISIS_ADJ_LEVEL2);
267 } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1)
268 || (adj->adj_usage
269 == ISIS_ADJ_LEVEL1AND2)) {
270 /* (8) down - wrong system */
271 isis_adj_state_change(adj,
272 ISIS_ADJ_DOWN,
273 "Wrong System");
274 }
275 break;
276 case IS_LEVEL_1_AND_2:
277 if (adj->adj_state != ISIS_ADJ_UP
278 || adj->adj_usage == ISIS_ADJ_LEVEL1AND2) {
279 isis_adj_process_threeway(adj, tw_adj,
280 ISIS_ADJ_LEVEL1AND2);
281 } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1)
282 || (adj->adj_usage
283 == ISIS_ADJ_LEVEL2)) {
284 /* (8) down - wrong system */
285 isis_adj_state_change(adj,
286 ISIS_ADJ_DOWN,
287 "Wrong System");
288 }
289 break;
290 }
291 }
292
293 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
294 if (iih->circuit->area->is_type == IS_LEVEL_2) {
295 switch (iih->circ_type) {
296 case IS_LEVEL_1:
297 if (adj->adj_state != ISIS_ADJ_UP) {
298 /* (5) reject - wrong system type event
299 */
300 zlog_warn("wrongSystemType");
301 return ISIS_WARNING;
302 } else if ((adj->adj_usage
303 == ISIS_ADJ_LEVEL1AND2)
304 || (adj->adj_usage
305 == ISIS_ADJ_LEVEL2)) {
306 /* (6) down - wrong system */
307 isis_adj_state_change(adj,
308 ISIS_ADJ_DOWN,
309 "Wrong System");
310 }
311 break;
312 case IS_LEVEL_1_AND_2:
313 case IS_LEVEL_2:
314 if (adj->adj_state != ISIS_ADJ_UP
315 || adj->adj_usage == ISIS_ADJ_LEVEL2) {
316 isis_adj_process_threeway(adj, tw_adj,
317 ISIS_ADJ_LEVEL2);
318 } else if (adj->adj_usage
319 == ISIS_ADJ_LEVEL1AND2) {
320 /* (6) down - wrong system */
321 isis_adj_state_change(adj,
322 ISIS_ADJ_DOWN,
323 "Wrong System");
324 }
325 break;
326 }
327 }
328 }
329 /* 8.2.5.2 b) if no match was detected */
330 else if (listcount(iih->circuit->area->area_addrs) > 0) {
331 if (iih->circuit->area->is_type == IS_LEVEL_1) {
332 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
333 if (adj->adj_state != ISIS_ADJ_UP) {
334 isis_adj_state_change(adj, ISIS_ADJ_DOWN,
335 "Area Mismatch");
336 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
337 } else {
338 isis_adj_state_change(adj, ISIS_ADJ_DOWN,
339 "Down - Area Mismatch");
340 }
341 }
342 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
343 else {
344 switch (iih->circ_type) {
345 case IS_LEVEL_1:
346 if (adj->adj_state != ISIS_ADJ_UP) {
347 /* (6) reject - Area Mismatch event */
348 zlog_warn("AreaMismatch");
349 return ISIS_WARNING;
350 } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
351 /* (7) down - area mismatch */
352 isis_adj_state_change(adj,
353 ISIS_ADJ_DOWN,
354 "Area Mismatch");
355
356 } else if ((adj->adj_usage
357 == ISIS_ADJ_LEVEL1AND2)
358 || (adj->adj_usage
359 == ISIS_ADJ_LEVEL2)) {
360 /* (7) down - wrong system */
361 isis_adj_state_change(adj,
362 ISIS_ADJ_DOWN,
363 "Wrong System");
364 }
365 break;
366 case IS_LEVEL_1_AND_2:
367 case IS_LEVEL_2:
368 if (adj->adj_state != ISIS_ADJ_UP
369 || adj->adj_usage == ISIS_ADJ_LEVEL2) {
370 isis_adj_process_threeway(adj, tw_adj,
371 ISIS_ADJ_LEVEL2);
372 } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
373 /* (7) down - wrong system */
374 isis_adj_state_change(adj,
375 ISIS_ADJ_DOWN,
376 "Wrong System");
377 } else if (adj->adj_usage
378 == ISIS_ADJ_LEVEL1AND2) {
379 if (iih->circ_type == IS_LEVEL_2) {
380 /* (7) down - wrong system */
381 isis_adj_state_change(
382 adj, ISIS_ADJ_DOWN,
383 "Wrong System");
384 } else {
385 /* (7) down - area mismatch */
386 isis_adj_state_change(
387 adj, ISIS_ADJ_DOWN,
388 "Area Mismatch");
389 }
390 }
391 break;
392 }
393 }
394 } else {
395 /* down - area mismatch */
396 isis_adj_state_change(adj, ISIS_ADJ_DOWN, "Area Mismatch");
397 }
398
399 if (adj->adj_state == ISIS_ADJ_UP && changed) {
400 lsp_regenerate_schedule(adj->circuit->area,
401 isis_adj_usage2levels(adj->adj_usage),
402 0);
403 }
404
405 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
406 /* FIXME - Missing parts */
407
408 /* some of my own understanding of the ISO, why the heck does
409 * it not say what should I change the system_type to...
410 */
411 switch (adj->adj_usage) {
412 case ISIS_ADJ_LEVEL1:
413 adj->sys_type = ISIS_SYSTYPE_L1_IS;
414 break;
415 case ISIS_ADJ_LEVEL2:
416 adj->sys_type = ISIS_SYSTYPE_L2_IS;
417 break;
418 case ISIS_ADJ_LEVEL1AND2:
419 adj->sys_type = ISIS_SYSTYPE_L2_IS;
420 break;
421 case ISIS_ADJ_NONE:
422 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
423 break;
424 }
425
426 if (isis->debugs & DEBUG_ADJ_PACKETS) {
427 zlog_debug(
428 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
429 " cir id %hhu, length %" PRIu16,
430 iih->circuit->area->area_tag,
431 iih->circuit->interface->name,
432 circuit_t2string(iih->circuit->is_type),
433 iih->circuit->circuit_id, iih->pdu_len);
434 }
435
436 return ISIS_OK;
437 }
438
439 static int process_lan_hello(struct iih_info *iih)
440 {
441 struct isis_adjacency *adj;
442 adj = isis_adj_lookup(iih->sys_id,
443 iih->circuit->u.bc.adjdb[iih->level - 1]);
444 if ((adj == NULL) || (memcmp(adj->snpa, iih->ssnpa, ETH_ALEN))
445 || (adj->level != iih->level)) {
446 if (!adj) {
447 /* Do as in 8.4.2.5 */
448 adj = isis_new_adj(iih->sys_id, iih->ssnpa, iih->level,
449 iih->circuit);
450 } else {
451 if (iih->ssnpa) {
452 memcpy(adj->snpa, iih->ssnpa, 6);
453 } else {
454 memset(adj->snpa, ' ', 6);
455 }
456 adj->level = iih->level;
457 }
458 isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL);
459
460 if (iih->level == IS_LEVEL_1)
461 adj->sys_type = ISIS_SYSTYPE_L1_IS;
462 else
463 adj->sys_type = ISIS_SYSTYPE_L2_IS;
464 list_delete_all_node(
465 iih->circuit->u.bc.lan_neighs[iih->level - 1]);
466 isis_adj_build_neigh_list(
467 iih->circuit->u.bc.adjdb[iih->level - 1],
468 iih->circuit->u.bc.lan_neighs[iih->level - 1]);
469 }
470
471 if (adj->dis_record[iih->level - 1].dis == ISIS_IS_DIS) {
472 uint8_t *dis = (iih->level == 1)
473 ? iih->circuit->u.bc.l1_desig_is
474 : iih->circuit->u.bc.l2_desig_is;
475
476 if (memcmp(dis, iih->dis, ISIS_SYS_ID_LEN + 1)) {
477 thread_add_event(master, isis_event_dis_status_change,
478 iih->circuit, 0, NULL);
479 memcpy(dis, iih->dis, ISIS_SYS_ID_LEN + 1);
480 }
481 }
482
483 adj->circuit_t = iih->circ_type;
484 adj->hold_time = iih->holdtime;
485 adj->last_upd = time(NULL);
486 adj->prio[iih->level - 1] = iih->priority;
487 memcpy(adj->lanid, iih->dis, ISIS_SYS_ID_LEN + 1);
488
489 bool changed;
490 isis_tlvs_to_adj(iih->tlvs, adj, &changed);
491 changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable,
492 adj);
493
494 /* lets take care of the expiry */
495 THREAD_TIMER_OFF(adj->t_expire);
496 thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
497 &adj->t_expire);
498
499 /*
500 * If the snpa for this circuit is found from LAN Neighbours TLV
501 * we have two-way communication -> adjacency can be put to state "up"
502 */
503 bool own_snpa_found =
504 isis_tlvs_own_snpa_found(iih->tlvs, iih->circuit->u.bc.snpa);
505
506 if (adj->adj_state != ISIS_ADJ_UP) {
507 if (own_snpa_found) {
508 isis_adj_state_change(
509 adj, ISIS_ADJ_UP,
510 "own SNPA found in LAN Neighbours TLV");
511 }
512 } else {
513 if (!own_snpa_found) {
514 isis_adj_state_change(
515 adj, ISIS_ADJ_INITIALIZING,
516 "own SNPA not found in LAN Neighbours TLV");
517 }
518 }
519
520 if (adj->adj_state == ISIS_ADJ_UP && changed)
521 lsp_regenerate_schedule(adj->circuit->area, iih->level, 0);
522
523 if (isis->debugs & DEBUG_ADJ_PACKETS) {
524 zlog_debug(
525 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
526 iih->circuit->area->area_tag, iih->level,
527 snpa_print(iih->ssnpa), iih->circuit->interface->name,
528 circuit_t2string(iih->circuit->is_type),
529 iih->circuit->circuit_id,
530 stream_get_endp(iih->circuit->rcv_stream));
531 }
532 return ISIS_OK;
533 }
534
535 static int pdu_len_validate(uint16_t pdu_len, struct isis_circuit *circuit)
536 {
537 if (pdu_len < stream_get_getp(circuit->rcv_stream)
538 || pdu_len > ISO_MTU(circuit)
539 || pdu_len > stream_get_endp(circuit->rcv_stream))
540 return 1;
541
542 if (pdu_len < stream_get_endp(circuit->rcv_stream))
543 stream_set_endp(circuit->rcv_stream, pdu_len);
544 return 0;
545 }
546
547 static int process_hello(uint8_t pdu_type, struct isis_circuit *circuit,
548 uint8_t *ssnpa)
549 {
550 /* keep a copy of the raw pdu for NB notifications */
551 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
552 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
553 char raw_pdu[pdu_end - pdu_start];
554 bool p2p_hello = (pdu_type == P2P_HELLO);
555 int level = p2p_hello ? 0
556 : (pdu_type == L1_LAN_HELLO) ? ISIS_LEVEL1
557 : ISIS_LEVEL2;
558 const char *pdu_name =
559 p2p_hello
560 ? "P2P IIH"
561 : (level == ISIS_LEVEL1) ? "L1 LAN IIH" : "L2 LAN IIH";
562
563
564 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
565 pdu_end - pdu_start);
566 if (isis->debugs & DEBUG_ADJ_PACKETS) {
567 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
568 circuit->area->area_tag, pdu_name,
569 circuit->interface->name,
570 circuit_t2string(circuit->is_type),
571 circuit->circuit_id);
572 if (isis->debugs & DEBUG_PACKET_DUMP)
573 zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
574 stream_get_endp(circuit->rcv_stream));
575 }
576
577 if (p2p_hello) {
578 if (circuit->circ_type != CIRCUIT_T_P2P) {
579 zlog_warn("p2p hello on non p2p circuit");
580 circuit->rej_adjacencies++;
581 #ifndef FABRICD
582 isis_notif_reject_adjacency(
583 circuit, "p2p hello on non p2p circuit",
584 raw_pdu);
585 #endif /* ifndef FABRICD */
586 return ISIS_WARNING;
587 }
588 } else {
589 if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
590 zlog_warn("lan hello on non broadcast circuit");
591 circuit->rej_adjacencies++;
592 #ifndef FABRICD
593 isis_notif_reject_adjacency(
594 circuit, "lan hello on non broadcast circuit",
595 raw_pdu);
596 #endif /* ifndef FABRICD */
597 return ISIS_WARNING;
598 }
599
600 if (circuit->ext_domain) {
601 zlog_debug(
602 "level %d LAN Hello received over circuit with externalDomain = true",
603 level);
604 circuit->rej_adjacencies++;
605 #ifndef FABRICD
606 isis_notif_reject_adjacency(
607 circuit,
608 "LAN Hello received over circuit with externalDomain = true",
609 raw_pdu);
610 #endif /* ifndef FABRICD */
611 return ISIS_WARNING;
612 }
613
614 if (!(circuit->is_type & level)) {
615 if (isis->debugs & DEBUG_ADJ_PACKETS) {
616 zlog_debug(
617 "ISIS-Adj (%s): Interface level mismatch, %s",
618 circuit->area->area_tag,
619 circuit->interface->name);
620 }
621 circuit->rej_adjacencies++;
622 #ifndef FABRICD
623 isis_notif_reject_adjacency(
624 circuit, "Interface level mismatch", raw_pdu);
625 #endif /* ifndef FABRICD */
626 return ISIS_WARNING;
627 }
628 }
629
630 struct iih_info iih = {
631 .circuit = circuit, .ssnpa = ssnpa, .level = level};
632
633 /* Generic IIH Header */
634 iih.circ_type = stream_getc(circuit->rcv_stream) & 0x03;
635 stream_get(iih.sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
636 iih.holdtime = stream_getw(circuit->rcv_stream);
637 iih.pdu_len = stream_getw(circuit->rcv_stream);
638
639 if (p2p_hello) {
640 iih.circuit_id = stream_getc(circuit->rcv_stream);
641 } else {
642 iih.priority = stream_getc(circuit->rcv_stream);
643 stream_get(iih.dis, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
644 }
645
646 if (pdu_len_validate(iih.pdu_len, circuit)) {
647 zlog_warn(
648 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16,
649 circuit->area->area_tag, pdu_name,
650 circuit->interface->name, iih.pdu_len);
651 circuit->rej_adjacencies++;
652 #ifndef FABRICD
653 isis_notif_reject_adjacency(circuit, "Invalid PDU length",
654 raw_pdu);
655 #endif /* ifndef FABRICD */
656 return ISIS_WARNING;
657 }
658
659 if (!p2p_hello && !(level & iih.circ_type)) {
660 flog_err(EC_ISIS_PACKET,
661 "Level %d LAN Hello with Circuit Type %d", level,
662 iih.circ_type);
663 circuit->rej_adjacencies++;
664 #ifndef FABRICD
665 isis_notif_reject_adjacency(
666 circuit, "LAN Hello with wrong IS-level", raw_pdu);
667 #endif /* ifndef FABRICD */
668 return ISIS_ERROR;
669 }
670
671 const char *error_log;
672 int retval = ISIS_WARNING;
673
674 if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
675 circuit->rcv_stream, &iih.tlvs, &error_log)) {
676 zlog_warn("isis_unpack_tlvs() failed: %s", error_log);
677 circuit->rej_adjacencies++;
678 #ifndef FABRICD
679 isis_notif_reject_adjacency(circuit, "Failed to unpack TLVs",
680 raw_pdu);
681 #endif /* ifndef FABRICD */
682 goto out;
683 }
684
685 if (!iih.tlvs->area_addresses.count) {
686 zlog_warn("No Area addresses TLV in %s", pdu_name);
687 #ifndef FABRICD
688 /* send northbound notification */
689 isis_notif_area_mismatch(circuit, raw_pdu);
690 #endif /* ifndef FABRICD */
691 goto out;
692 }
693
694 if (!iih.tlvs->protocols_supported.count) {
695 zlog_warn("No supported protocols TLV in %s", pdu_name);
696 circuit->rej_adjacencies++;
697 #ifndef FABRICD
698 isis_notif_reject_adjacency(
699 circuit, "No supported protocols TLV", raw_pdu);
700 #endif /* ifndef FABRICD */
701 goto out;
702 }
703
704 int auth_code = isis_tlvs_auth_is_valid(iih.tlvs, &circuit->passwd,
705 circuit->rcv_stream, false);
706 if (auth_code != ISIS_AUTH_OK) {
707 isis_event_auth_failure(circuit->area->area_tag,
708 "IIH authentication failure",
709 iih.sys_id);
710 #ifndef FABRICD
711 /* send northbound notification */
712 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
713 pdu_end - pdu_start);
714 if (auth_code == ISIS_AUTH_FAILURE) {
715 circuit->auth_failures++;
716 isis_notif_authentication_failure(circuit, raw_pdu);
717 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
718 circuit->auth_type_failures++;
719 isis_notif_authentication_type_failure(circuit,
720 raw_pdu);
721 }
722 #endif /* ifndef FABRICD */
723 goto out;
724 }
725
726 if (!memcmp(iih.sys_id, isis->sysid, ISIS_SYS_ID_LEN)) {
727 zlog_warn(
728 "ISIS-Adj (%s): Received IIH with own sysid - discard",
729 circuit->area->area_tag);
730 circuit->rej_adjacencies++;
731 #ifndef FABRICD
732 isis_notif_reject_adjacency(
733 circuit, "Received IIH with our own sysid", raw_pdu);
734 #endif /* ifndef FABRICD */
735 goto out;
736 }
737
738 if (!p2p_hello
739 && (listcount(circuit->area->area_addrs) == 0
740 || (level == ISIS_LEVEL1
741 && !isis_tlvs_area_addresses_match(
742 iih.tlvs, circuit->area->area_addrs)))) {
743 if (isis->debugs & DEBUG_ADJ_PACKETS) {
744 zlog_debug(
745 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
746 circuit->area->area_tag, level,
747 circuit->interface->name);
748 }
749 #ifndef FABRICD
750 /* send northbound notification */
751 isis_notif_area_mismatch(circuit, raw_pdu);
752 #endif /* ifndef FABRICD */
753 goto out;
754 }
755
756 iih.v4_usable = (fabricd_ip_addrs(circuit)
757 && iih.tlvs->ipv4_address.count);
758
759 iih.v6_usable = (circuit->ipv6_link && listcount(circuit->ipv6_link)
760 && iih.tlvs->ipv6_address.count);
761
762 if (!iih.v4_usable && !iih.v6_usable) {
763 if (isis->debugs & DEBUG_ADJ_PACKETS) {
764 zlog_warn(
765 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
766 circuit->area->area_tag);
767 }
768 circuit->rej_adjacencies++;
769 #ifndef FABRICD
770 isis_notif_reject_adjacency(
771 circuit, "Neither IPv4 not IPv6 considered usable",
772 raw_pdu);
773 #endif /* ifndef FABRICD */
774 goto out;
775 }
776
777 retval = p2p_hello ? process_p2p_hello(&iih) : process_lan_hello(&iih);
778 out:
779 isis_free_tlvs(iih.tlvs);
780
781 return retval;
782 }
783
784 static void lsp_flood_or_update(struct isis_lsp *lsp,
785 struct isis_circuit *circuit,
786 bool circuit_scoped)
787 {
788 if (!circuit_scoped)
789 lsp_flood(lsp, circuit);
790 else
791 fabricd_update_lsp_no_flood(lsp, circuit);
792 }
793
794 /*
795 * Process Level 1/2 Link State
796 * ISO - 10589
797 * Section 7.3.15.1 - Action on receipt of a link state PDU
798 */
799 static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit,
800 const uint8_t *ssnpa, uint8_t max_area_addrs)
801 {
802 int level;
803 bool circuit_scoped;
804 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
805 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
806 char raw_pdu[pdu_end - pdu_start];
807
808 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
809 pdu_end - pdu_start);
810
811 if (pdu_type == FS_LINK_STATE) {
812 if (!fabricd)
813 return ISIS_ERROR;
814 if (max_area_addrs != L2_CIRCUIT_FLOODING_SCOPE)
815 return ISIS_ERROR;
816 level = ISIS_LEVEL2;
817 circuit_scoped = true;
818
819 /* The stream is used verbatim for sending out new LSPDUs.
820 * So make sure we store it as an L2 LSPDU internally.
821 * (compare for the reverse in `send_lsp`) */
822 stream_putc_at(circuit->rcv_stream, 4, L2_LINK_STATE);
823 stream_putc_at(circuit->rcv_stream, 7, 0);
824 } else {
825 if (pdu_type == L1_LINK_STATE)
826 level = ISIS_LEVEL1;
827 else
828 level = ISIS_LEVEL2;
829 circuit_scoped = false;
830 }
831
832 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
833 zlog_debug(
834 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
835 circuit->area->area_tag,
836 circuit_scoped ? "Circuit scoped " : "", level,
837 circuit->interface->name,
838 circuit_t2string(circuit->is_type),
839 circuit->circuit_id);
840 if (isis->debugs & DEBUG_PACKET_DUMP)
841 zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
842 stream_get_endp(circuit->rcv_stream));
843 }
844
845 struct isis_lsp_hdr hdr = {};
846
847 hdr.pdu_len = stream_getw(circuit->rcv_stream);
848 hdr.rem_lifetime = stream_getw(circuit->rcv_stream);
849 stream_get(hdr.lsp_id, circuit->rcv_stream, sizeof(hdr.lsp_id));
850 hdr.seqno = stream_getl(circuit->rcv_stream);
851 hdr.checksum = stream_getw(circuit->rcv_stream);
852 hdr.lsp_bits = stream_getc(circuit->rcv_stream);
853
854 #ifndef FABRICD
855 /* send northbound notification */
856 isis_notif_lsp_received(circuit, rawlspid_print(hdr.lsp_id), hdr.seqno,
857 time(NULL), sysid_print(hdr.lsp_id));
858 #endif /* ifndef FABRICD */
859
860 if (pdu_len_validate(hdr.pdu_len, circuit)) {
861 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16,
862 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
863 hdr.pdu_len);
864 return ISIS_WARNING;
865 }
866
867 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
868 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
869 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
870 "s, len %" PRIu16 ", on %s",
871 circuit->area->area_tag, level,
872 rawlspid_print(hdr.lsp_id), hdr.seqno, hdr.checksum,
873 hdr.rem_lifetime, hdr.pdu_len,
874 circuit->interface->name);
875 }
876
877 /* lsp is_type check */
878 if ((hdr.lsp_bits & IS_LEVEL_1) != IS_LEVEL_1) {
879 zlog_debug(
880 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8,
881 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
882 hdr.lsp_bits & IS_LEVEL_1_AND_2);
883 /* continue as per RFC1122 Be liberal in what you accept, and
884 * conservative in what you send */
885 }
886
887 /* Checksum sanity check - FIXME: move to correct place */
888 /* 12 = sysid+pdu+remtime */
889 if (iso_csum_verify(STREAM_DATA(circuit->rcv_stream) + 12,
890 hdr.pdu_len - 12, hdr.checksum, 12)) {
891 zlog_debug(
892 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16,
893 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
894 hdr.checksum);
895 return ISIS_WARNING;
896 }
897
898 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
899 if (circuit->ext_domain) {
900 zlog_debug(
901 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
902 "externalDomain = true",
903 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
904 level);
905 return ISIS_WARNING;
906 }
907
908 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
909 if (!(circuit->is_type & level)) {
910 zlog_debug(
911 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
912 " type %s",
913 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
914 level, circuit_t2string(circuit->is_type));
915 return ISIS_WARNING;
916 }
917
918 struct isis_tlvs *tlvs = NULL;
919 int retval = ISIS_WARNING;
920 const char *error_log;
921
922 if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
923 circuit->rcv_stream, &tlvs, &error_log)) {
924 zlog_warn("Something went wrong unpacking the LSP: %s",
925 error_log);
926 #ifndef FABRICD
927 /* send northbound notification. Note that the tlv-type and
928 * offset cannot correctly be set here as they are not returned
929 * by isis_unpack_tlvs, but in there I cannot fire a
930 * notification because I have no circuit information. So until
931 * we change the code above to return those extra fields, we
932 * will send dummy values which are ignored in the callback
933 */
934 isis_notif_lsp_error(circuit, rawlspid_print(hdr.lsp_id),
935 raw_pdu, 0, 0);
936 #endif /* ifndef FABRICD */
937 goto out;
938 }
939
940 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
941
942 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
943 * 3 */
944
945 /* 7.3.15.1 a) 7 - password check */
946 struct isis_passwd *passwd = (level == ISIS_LEVEL1)
947 ? &circuit->area->area_passwd
948 : &circuit->area->domain_passwd;
949 int auth_code = isis_tlvs_auth_is_valid(tlvs, passwd,
950 circuit->rcv_stream, true);
951 if (auth_code != ISIS_AUTH_OK) {
952 isis_event_auth_failure(circuit->area->area_tag,
953 "LSP authentication failure",
954 hdr.lsp_id);
955 #ifndef FABRICD
956 /* send northbound notification */
957 if (auth_code == ISIS_AUTH_FAILURE) {
958 circuit->auth_failures++;
959 isis_notif_authentication_failure(circuit, raw_pdu);
960 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
961 circuit->auth_type_failures++;
962 isis_notif_authentication_type_failure(circuit,
963 raw_pdu);
964 }
965 #endif /* ifndef FABRICD */
966 goto out;
967 }
968
969 /* Find the LSP in our database and compare it to this Link State header
970 */
971 struct isis_lsp *lsp =
972 lsp_search(&circuit->area->lspdb[level - 1], hdr.lsp_id);
973 int comp = 0;
974 if (lsp)
975 comp = lsp_compare(circuit->area->area_tag, lsp, hdr.seqno,
976 hdr.checksum, hdr.rem_lifetime);
977 if (lsp && (lsp->own_lsp))
978 goto dontcheckadj;
979
980 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
981 * level */
982 /* for broadcast circuits, snpa should be compared */
983
984 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
985 if (!isis_adj_lookup_snpa(ssnpa,
986 circuit->u.bc.adjdb[level - 1])) {
987 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
988 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
989 "s on %s",
990 circuit->area->area_tag,
991 rawlspid_print(hdr.lsp_id), hdr.seqno,
992 hdr.checksum, hdr.rem_lifetime,
993 circuit->interface->name);
994 goto out; /* Silently discard */
995 }
996 }
997 /* for non broadcast, we just need to find same level adj */
998 else {
999 /* If no adj, or no sharing of level */
1000 if (!circuit->u.p2p.neighbor) {
1001 retval = ISIS_OK;
1002 goto out;
1003 } else {
1004 if (((level == IS_LEVEL_1)
1005 && (circuit->u.p2p.neighbor->adj_usage
1006 == ISIS_ADJ_LEVEL2))
1007 || ((level == IS_LEVEL_2)
1008 && (circuit->u.p2p.neighbor->adj_usage
1009 == ISIS_ADJ_LEVEL1)))
1010 goto out;
1011 }
1012 }
1013
1014 bool lsp_confusion;
1015
1016 dontcheckadj:
1017 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1018
1019 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1020
1021 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1022 * it */
1023
1024 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1025 * but
1026 * wrong checksum, initiate a purge. */
1027 if (lsp && (lsp->hdr.seqno == hdr.seqno)
1028 && (lsp->hdr.checksum != hdr.checksum)
1029 && hdr.rem_lifetime) {
1030 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
1031 " with confused checksum received.",
1032 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
1033 hdr.seqno);
1034 hdr.rem_lifetime = 0;
1035 lsp_confusion = true;
1036 } else
1037 lsp_confusion = false;
1038
1039 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1040 if (hdr.rem_lifetime == 0) {
1041 if (!lsp) {
1042 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1043 * save */
1044 /* only needed on explicit update, eg - p2p */
1045 if (circuit->circ_type == CIRCUIT_T_P2P)
1046 ack_lsp(&hdr, circuit, level);
1047 goto out; /* FIXME: do we need a purge? */
1048 } else {
1049 if (memcmp(hdr.lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) {
1050 /* LSP by some other system -> do 7.3.16.4 b) */
1051 /* 7.3.16.4 b) 1) */
1052 if (comp == LSP_NEWER) {
1053 lsp_update(lsp, &hdr, tlvs,
1054 circuit->rcv_stream,
1055 circuit->area, level,
1056 lsp_confusion);
1057 if (lsp_confusion)
1058 isis_free_tlvs(tlvs);
1059 tlvs = NULL;
1060 /* ii */
1061 lsp_flood_or_update(lsp, NULL,
1062 circuit_scoped);
1063 /* v */
1064 ISIS_FLAGS_CLEAR_ALL(
1065 lsp->SSNflags); /* FIXME:
1066 OTHER
1067 than c
1068 */
1069
1070 /* For the case of lsp confusion, flood
1071 * the purge back to its
1072 * originator so that it can react.
1073 * Otherwise, don't reflood
1074 * through incoming circuit as usual */
1075 if (!lsp_confusion) {
1076 isis_tx_queue_del(
1077 circuit->tx_queue,
1078 lsp);
1079
1080 /* iv */
1081 if (circuit->circ_type
1082 != CIRCUIT_T_BROADCAST)
1083 ISIS_SET_FLAG(
1084 lsp->SSNflags,
1085 circuit);
1086 }
1087 } /* 7.3.16.4 b) 2) */
1088 else if (comp == LSP_EQUAL) {
1089 /* i */
1090 isis_tx_queue_del(circuit->tx_queue,
1091 lsp);
1092 /* ii */
1093 if (circuit->circ_type
1094 != CIRCUIT_T_BROADCAST)
1095 ISIS_SET_FLAG(lsp->SSNflags,
1096 circuit);
1097 } /* 7.3.16.4 b) 3) */
1098 else {
1099 isis_tx_queue_add(circuit->tx_queue,
1100 lsp, TX_LSP_NORMAL);
1101 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1102 }
1103 } else if (lsp->hdr.rem_lifetime != 0) {
1104 /* our own LSP -> 7.3.16.4 c) */
1105 if (comp == LSP_NEWER) {
1106 #ifndef FABRICD
1107 if (lsp->hdr.seqno < hdr.seqno) {
1108 /* send northbound
1109 * notification */
1110 isis_notif_seqno_skipped(
1111 circuit,
1112 rawlspid_print(
1113 hdr.lsp_id));
1114 }
1115 #endif /* ifndef FABRICD */
1116 lsp_inc_seqno(lsp, hdr.seqno);
1117 lsp_flood_or_update(lsp, NULL,
1118 circuit_scoped);
1119 } else {
1120 isis_tx_queue_add(circuit->tx_queue,
1121 lsp, TX_LSP_NORMAL);
1122 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1123 }
1124 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1125 zlog_debug(
1126 "ISIS-Upd (%s): (1) "
1127 "re-originating LSP %s new seq "
1128 "0x%08" PRIx32,
1129 circuit->area->area_tag,
1130 rawlspid_print(hdr.lsp_id),
1131 lsp->hdr.seqno);
1132 } else {
1133 /* our own LSP with 0 remaining life time */
1134 #ifndef FABRICD
1135 /* send northbound notification */
1136 isis_notif_own_lsp_purge(
1137 circuit, rawlspid_print(hdr.lsp_id));
1138 #endif /* ifndef FABRICD */
1139 }
1140 }
1141 goto out;
1142 }
1143 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1144 * purge */
1145 if (memcmp(hdr.lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0) {
1146 if (!lsp) {
1147 /* 7.3.16.4: initiate a purge */
1148 lsp_purge_non_exist(level, &hdr, circuit->area);
1149 retval = ISIS_OK;
1150 goto out;
1151 }
1152 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1153
1154 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1155 * domain
1156 * has information that the current sequence number for source S
1157 * is
1158 * "greater" than that held by S, ... */
1159
1160 if (comp == LSP_NEWER) {
1161 /* 7.3.16.1 */
1162 lsp_inc_seqno(lsp, hdr.seqno);
1163 #ifndef FABRICD
1164 /* send northbound notification */
1165 isis_notif_seqno_skipped(circuit,
1166 rawlspid_print(hdr.lsp_id));
1167 #endif /* ifndef FABRICD */
1168 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1169 zlog_debug(
1170 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32,
1171 circuit->area->area_tag,
1172 rawlspid_print(hdr.lsp_id),
1173 lsp->hdr.seqno);
1174 }
1175 lsp_flood(lsp, NULL);
1176 } else if (comp == LSP_EQUAL) {
1177 isis_tx_queue_del(circuit->tx_queue, lsp);
1178 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1179 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1180 } else {
1181 isis_tx_queue_add(circuit->tx_queue, lsp,
1182 TX_LSP_NORMAL);
1183 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1184 }
1185 } else {
1186 /* 7.3.15.1 e) - This lsp originated on another system */
1187
1188 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1189 */
1190 if ((!lsp || comp == LSP_NEWER)) {
1191 /*
1192 * If this lsp is a frag, need to see if we have zero
1193 * lsp present
1194 */
1195 struct isis_lsp *lsp0 = NULL;
1196 if (LSP_FRAGMENT(hdr.lsp_id) != 0) {
1197 uint8_t lspid[ISIS_SYS_ID_LEN + 2];
1198 memcpy(lspid, hdr.lsp_id, ISIS_SYS_ID_LEN + 1);
1199 LSP_FRAGMENT(lspid) = 0;
1200 lsp0 = lsp_search(
1201 &circuit->area->lspdb[level - 1], lspid);
1202 if (!lsp0) {
1203 zlog_debug(
1204 "Got lsp frag, while zero lsp not in database");
1205 goto out;
1206 }
1207 }
1208 /* i */
1209 if (!lsp) {
1210 lsp = lsp_new_from_recv(
1211 &hdr, tlvs, circuit->rcv_stream, lsp0,
1212 circuit->area, level);
1213 tlvs = NULL;
1214 lsp_insert(&circuit->area->lspdb[level - 1],
1215 lsp);
1216 } else /* exists, so we overwrite */
1217 {
1218 lsp_update(lsp, &hdr, tlvs, circuit->rcv_stream,
1219 circuit->area, level, false);
1220 tlvs = NULL;
1221 }
1222 lsp_flood_or_update(lsp, circuit, circuit_scoped);
1223
1224 /* iv */
1225 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1226 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1227 /* FIXME: v) */
1228 }
1229 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1230 else if (comp == LSP_EQUAL) {
1231 isis_tx_queue_del(circuit->tx_queue, lsp);
1232 lsp_update(lsp, &hdr, tlvs, circuit->rcv_stream,
1233 circuit->area, level, false);
1234 tlvs = NULL;
1235 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1236 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1237 }
1238 /* 7.3.15.1 e) 3) LSP older than the one in db */
1239 else {
1240 isis_tx_queue_add(circuit->tx_queue, lsp,
1241 TX_LSP_NORMAL);
1242 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1243 }
1244 }
1245
1246 retval = ISIS_OK;
1247
1248 out:
1249 fabricd_trigger_csnp(circuit->area, circuit_scoped);
1250
1251 isis_free_tlvs(tlvs);
1252 return retval;
1253 }
1254
1255 /*
1256 * Process Sequence Numbers
1257 * ISO - 10589
1258 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1259 */
1260
1261 static int process_snp(uint8_t pdu_type, struct isis_circuit *circuit,
1262 const uint8_t *ssnpa)
1263 {
1264 #ifndef FABRICD
1265 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
1266 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
1267 char raw_pdu[pdu_end - pdu_start];
1268 #endif /* ifndef FABRICD */
1269
1270 bool is_csnp = (pdu_type == L1_COMPLETE_SEQ_NUM
1271 || pdu_type == L2_COMPLETE_SEQ_NUM);
1272 char typechar = is_csnp ? 'C' : 'P';
1273 int level = (pdu_type == L1_COMPLETE_SEQ_NUM
1274 || pdu_type == L1_PARTIAL_SEQ_NUM)
1275 ? ISIS_LEVEL1
1276 : ISIS_LEVEL2;
1277
1278 uint16_t pdu_len = stream_getw(circuit->rcv_stream);
1279 uint8_t rem_sys_id[ISIS_SYS_ID_LEN];
1280
1281 stream_get(rem_sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
1282 stream_forward_getp(circuit->rcv_stream, 1); /* Circuit ID - unused */
1283
1284 uint8_t start_lsp_id[ISIS_SYS_ID_LEN + 2] = {};
1285 uint8_t stop_lsp_id[ISIS_SYS_ID_LEN + 2] = {};
1286
1287 if (is_csnp) {
1288 stream_get(start_lsp_id, circuit->rcv_stream,
1289 ISIS_SYS_ID_LEN + 2);
1290 stream_get(stop_lsp_id, circuit->rcv_stream,
1291 ISIS_SYS_ID_LEN + 2);
1292 }
1293
1294 if (pdu_len_validate(pdu_len, circuit)) {
1295 zlog_warn("Received a CSNP with bogus length %d", pdu_len);
1296 return ISIS_WARNING;
1297 }
1298
1299 if (isis->debugs & DEBUG_SNP_PACKETS) {
1300 zlog_debug(
1301 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1302 circuit->area->area_tag, level, typechar,
1303 circuit->interface->name,
1304 circuit_t2string(circuit->is_type),
1305 circuit->circuit_id);
1306 if (isis->debugs & DEBUG_PACKET_DUMP)
1307 zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
1308 stream_get_endp(circuit->rcv_stream));
1309 }
1310
1311 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1312 if (circuit->ext_domain) {
1313
1314 zlog_debug(
1315 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1316 "skipping: circuit externalDomain = true",
1317 circuit->area->area_tag, level, typechar,
1318 circuit->interface->name);
1319
1320 return ISIS_OK;
1321 }
1322
1323 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1324 if (!(circuit->is_type & level)) {
1325 zlog_debug(
1326 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1327 "skipping: circuit type %s does not match level %d",
1328 circuit->area->area_tag, level, typechar,
1329 circuit->interface->name,
1330 circuit_t2string(circuit->is_type), level);
1331
1332 return ISIS_OK;
1333 }
1334
1335 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1336 if (!is_csnp && (circuit->circ_type == CIRCUIT_T_BROADCAST)
1337 && !circuit->u.bc.is_dr[level - 1]) {
1338 zlog_debug(
1339 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1340 "skipping: we are not the DIS",
1341 circuit->area->area_tag, level, typechar,
1342 snpa_print(ssnpa), circuit->interface->name);
1343
1344 return ISIS_OK;
1345 }
1346
1347 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1348 */
1349
1350 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1351 * 3
1352 * - already checked */
1353
1354 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1355 * level */
1356 /* for broadcast circuits, snpa should be compared */
1357 /* FIXME : Do we need to check SNPA? */
1358 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1359 if (!isis_adj_lookup(rem_sys_id,
1360 circuit->u.bc.adjdb[level - 1]))
1361 return ISIS_OK; /* Silently discard */
1362 } else {
1363 if (!fabricd && !circuit->u.p2p.neighbor) {
1364 zlog_warn("no p2p neighbor on circuit %s",
1365 circuit->interface->name);
1366 return ISIS_OK; /* Silently discard */
1367 }
1368 }
1369
1370 struct isis_tlvs *tlvs;
1371 int retval = ISIS_WARNING;
1372 const char *error_log;
1373
1374 if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
1375 circuit->rcv_stream, &tlvs, &error_log)) {
1376 zlog_warn("Something went wrong unpacking the SNP: %s",
1377 error_log);
1378 goto out;
1379 }
1380
1381 struct isis_passwd *passwd = (level == IS_LEVEL_1)
1382 ? &circuit->area->area_passwd
1383 : &circuit->area->domain_passwd;
1384 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV)) {
1385 int auth_code = isis_tlvs_auth_is_valid(
1386 tlvs, passwd, circuit->rcv_stream, false);
1387 if (auth_code != ISIS_AUTH_OK) {
1388 isis_event_auth_failure(circuit->area->area_tag,
1389 "SNP authentication failure",
1390 rem_sys_id);
1391 #ifndef FABRICD
1392 /* send northbound notification */
1393 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
1394 pdu_end - pdu_start);
1395 if (auth_code == ISIS_AUTH_FAILURE) {
1396 circuit->auth_failures++;
1397 isis_notif_authentication_failure(circuit,
1398 raw_pdu);
1399 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1400 circuit->auth_type_failures++;
1401 isis_notif_authentication_type_failure(circuit,
1402 raw_pdu);
1403 }
1404 #endif /* ifndef FABRICD */
1405 goto out;
1406 }
1407 }
1408
1409 struct isis_lsp_entry *entry_head =
1410 (struct isis_lsp_entry *)tlvs->lsp_entries.head;
1411
1412 /* debug isis snp-packets */
1413 if (isis->debugs & DEBUG_SNP_PACKETS) {
1414 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1415 circuit->area->area_tag, level, typechar,
1416 snpa_print(ssnpa), circuit->interface->name);
1417 for (struct isis_lsp_entry *entry = entry_head; entry;
1418 entry = entry->next) {
1419 zlog_debug(
1420 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1421 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16 "s",
1422 circuit->area->area_tag, typechar,
1423 rawlspid_print(entry->id), entry->seqno,
1424 entry->checksum, entry->rem_lifetime);
1425 }
1426 }
1427
1428 bool resync_needed = false;
1429
1430 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1431 for (struct isis_lsp_entry *entry = entry_head; entry;
1432 entry = entry->next) {
1433 struct isis_lsp *lsp =
1434 lsp_search(&circuit->area->lspdb[level - 1], entry->id);
1435 bool own_lsp = !memcmp(entry->id, isis->sysid, ISIS_SYS_ID_LEN);
1436 if (lsp) {
1437 /* 7.3.15.2 b) 1) is this LSP newer */
1438 int cmp = lsp_compare(circuit->area->area_tag, lsp,
1439 entry->seqno, entry->checksum,
1440 entry->rem_lifetime);
1441 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1442 if (cmp == LSP_EQUAL) {
1443 /* if (circuit->circ_type !=
1444 * CIRCUIT_T_BROADCAST) */
1445 isis_tx_queue_del(circuit->tx_queue, lsp);
1446 }
1447 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1448 */
1449 else if (cmp == LSP_OLDER) {
1450 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1451 isis_tx_queue_add(circuit->tx_queue, lsp,
1452 TX_LSP_NORMAL);
1453 }
1454 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1455 on p2p */
1456 else {
1457 if (own_lsp) {
1458 lsp_inc_seqno(lsp, entry->seqno);
1459 isis_tx_queue_add(circuit->tx_queue, lsp,
1460 TX_LSP_NORMAL);
1461 } else {
1462 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1463 /* if (circuit->circ_type !=
1464 * CIRCUIT_T_BROADCAST) */
1465 isis_tx_queue_del(circuit->tx_queue, lsp);
1466 resync_needed = true;
1467 }
1468 }
1469 } else {
1470 /* 7.3.15.2 b) 5) if it was not found, and all of those
1471 * are not 0,
1472 * insert it and set SSN on it */
1473 if (entry->rem_lifetime && entry->checksum
1474 && entry->seqno && memcmp(entry->id, isis->sysid,
1475 ISIS_SYS_ID_LEN)) {
1476 struct isis_lsp *lsp0 = NULL;
1477
1478 if (LSP_FRAGMENT(entry->id)) {
1479 uint8_t lspid[ISIS_SYS_ID_LEN + 2];
1480
1481 memcpy(lspid, entry->id,
1482 ISIS_SYS_ID_LEN + 1);
1483 LSP_FRAGMENT(lspid) = 0;
1484 lsp0 = lsp_search(
1485 &circuit->area->lspdb[level - 1],
1486 lspid);
1487 if (!lsp0) {
1488 zlog_debug("Got lsp frag in snp, while zero not in database");
1489 continue;
1490 }
1491 }
1492 lsp = lsp_new(circuit->area, entry->id,
1493 entry->rem_lifetime, 0, 0,
1494 entry->checksum, lsp0, level);
1495 lsp_insert(&circuit->area->lspdb[level - 1],
1496 lsp);
1497
1498 lsp_set_all_srmflags(lsp, false);
1499 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1500 resync_needed = true;
1501 }
1502 }
1503 }
1504
1505 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1506 */
1507 if (is_csnp) {
1508 /*
1509 * Build a list from our own LSP db bounded with
1510 * start_lsp_id and stop_lsp_id
1511 */
1512 struct list *lsp_list = list_new();
1513 lsp_build_list_nonzero_ht(&circuit->area->lspdb[level - 1],
1514 start_lsp_id, stop_lsp_id, lsp_list);
1515
1516 /* Fixme: Find a better solution */
1517 struct listnode *node, *nnode;
1518 struct isis_lsp *lsp;
1519 for (struct isis_lsp_entry *entry = entry_head; entry;
1520 entry = entry->next) {
1521 for (ALL_LIST_ELEMENTS(lsp_list, node, nnode, lsp)) {
1522 if (lsp_id_cmp(lsp->hdr.lsp_id, entry->id)
1523 == 0) {
1524 list_delete_node(lsp_list, node);
1525 break;
1526 }
1527 }
1528 }
1529
1530 /* on remaining LSPs we set SRM (neighbor knew not of) */
1531 for (ALL_LIST_ELEMENTS_RO(lsp_list, node, lsp)) {
1532 isis_tx_queue_add(circuit->tx_queue, lsp, TX_LSP_NORMAL);
1533 resync_needed = true;
1534 }
1535
1536 /* lets free it */
1537 list_delete(&lsp_list);
1538 }
1539
1540 if (fabricd_initial_sync_is_complete(circuit->area) && resync_needed)
1541 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1542
1543 retval = ISIS_OK;
1544 out:
1545 isis_free_tlvs(tlvs);
1546 return retval;
1547 }
1548
1549 static int pdu_size(uint8_t pdu_type, uint8_t *size)
1550 {
1551 switch (pdu_type) {
1552 case L1_LAN_HELLO:
1553 case L2_LAN_HELLO:
1554 *size = ISIS_LANHELLO_HDRLEN;
1555 break;
1556 case P2P_HELLO:
1557 *size = ISIS_P2PHELLO_HDRLEN;
1558 break;
1559 case L1_LINK_STATE:
1560 case L2_LINK_STATE:
1561 case FS_LINK_STATE:
1562 *size = ISIS_LSP_HDR_LEN;
1563 break;
1564 case L1_COMPLETE_SEQ_NUM:
1565 case L2_COMPLETE_SEQ_NUM:
1566 *size = ISIS_CSNP_HDRLEN;
1567 break;
1568 case L1_PARTIAL_SEQ_NUM:
1569 case L2_PARTIAL_SEQ_NUM:
1570 *size = ISIS_PSNP_HDRLEN;
1571 break;
1572 default:
1573 return 1;
1574 }
1575 *size += ISIS_FIXED_HDR_LEN;
1576 return 0;
1577 }
1578
1579 /*
1580 * PDU Dispatcher
1581 */
1582
1583 int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
1584 {
1585 int retval = ISIS_OK;
1586 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
1587 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
1588 char raw_pdu[pdu_end - pdu_start];
1589
1590 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
1591 pdu_end - pdu_start);
1592
1593 /* Verify that at least the 8 bytes fixed header have been received */
1594 if (stream_get_endp(circuit->rcv_stream) < ISIS_FIXED_HDR_LEN) {
1595 flog_err(EC_ISIS_PACKET, "PDU is too short to be IS-IS.");
1596 return ISIS_ERROR;
1597 }
1598
1599 uint8_t idrp = stream_getc(circuit->rcv_stream);
1600 uint8_t length = stream_getc(circuit->rcv_stream);
1601 uint8_t version1 = stream_getc(circuit->rcv_stream);
1602 uint8_t id_len = stream_getc(circuit->rcv_stream);
1603 uint8_t pdu_type = stream_getc(circuit->rcv_stream)
1604 & 0x1f; /* bits 6-8 are reserved */
1605 uint8_t version2 = stream_getc(circuit->rcv_stream);
1606
1607 stream_forward_getp(circuit->rcv_stream, 1); /* reserved */
1608 uint8_t max_area_addrs = stream_getc(circuit->rcv_stream);
1609
1610 pdu_counter_count(circuit->area->pdu_rx_counters, pdu_type);
1611
1612 if (idrp == ISO9542_ESIS) {
1613 flog_err(EC_LIB_DEVELOPMENT,
1614 "No support for ES-IS packet IDRP=%" PRIx8, idrp);
1615 return ISIS_ERROR;
1616 }
1617
1618 if (idrp != ISO10589_ISIS) {
1619 flog_err(EC_ISIS_PACKET, "Not an IS-IS packet IDRP=%" PRIx8,
1620 idrp);
1621 return ISIS_ERROR;
1622 }
1623
1624 if (version1 != 1) {
1625 zlog_warn("Unsupported ISIS version %" PRIu8, version1);
1626 #ifndef FABRICD
1627 /* send northbound notification */
1628 isis_notif_version_skew(circuit, version1, raw_pdu);
1629 #endif /* ifndef FABRICD */
1630 return ISIS_WARNING;
1631 }
1632
1633 if (id_len != 0 && id_len != ISIS_SYS_ID_LEN) {
1634 flog_err(
1635 EC_ISIS_PACKET,
1636 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1637 ", while the parameter for this IS is %u",
1638 id_len, ISIS_SYS_ID_LEN);
1639 circuit->id_len_mismatches++;
1640 #ifndef FABRICD
1641 /* send northbound notification */
1642 isis_notif_id_len_mismatch(circuit, id_len, raw_pdu);
1643 #endif /* ifndef FABRICD */
1644 return ISIS_ERROR;
1645 }
1646
1647 uint8_t expected_length;
1648 if (pdu_size(pdu_type, &expected_length)) {
1649 zlog_warn("Unsupported ISIS PDU %" PRIu8, pdu_type);
1650 return ISIS_WARNING;
1651 }
1652
1653 if (length != expected_length) {
1654 flog_err(EC_ISIS_PACKET,
1655 "Exepected fixed header length = %" PRIu8
1656 " but got %" PRIu8,
1657 expected_length, length);
1658 return ISIS_ERROR;
1659 }
1660
1661 if (stream_get_endp(circuit->rcv_stream) < length) {
1662 flog_err(
1663 EC_ISIS_PACKET,
1664 "PDU is too short to contain fixed header of given PDU type.");
1665 return ISIS_ERROR;
1666 }
1667
1668 if (version2 != 1) {
1669 zlog_warn("Unsupported ISIS PDU version %" PRIu8, version2);
1670 #ifndef FABRICD
1671 /* send northbound notification */
1672 isis_notif_version_skew(circuit, version2, raw_pdu);
1673 #endif /* ifndef FABRICD */
1674 return ISIS_WARNING;
1675 }
1676
1677 if (circuit->is_passive) {
1678 zlog_warn("Received ISIS PDU on passive circuit %s",
1679 circuit->interface->name);
1680 return ISIS_WARNING;
1681 }
1682
1683 /* either 3 or 0 */
1684 if (pdu_type != FS_LINK_STATE /* FS PDU doesn't contain max area addr field */
1685 && max_area_addrs != 0
1686 && max_area_addrs != isis->max_area_addrs) {
1687 flog_err(
1688 EC_ISIS_PACKET,
1689 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1690 " while the parameter for this IS is %u",
1691 max_area_addrs, isis->max_area_addrs);
1692 circuit->max_area_addr_mismatches++;
1693 #ifndef FABRICD
1694 /* send northbound notification */
1695 isis_notif_max_area_addr_mismatch(circuit, max_area_addrs,
1696 raw_pdu);
1697 #endif /* ifndef FABRICD */
1698 return ISIS_ERROR;
1699 }
1700
1701 switch (pdu_type) {
1702 case L1_LAN_HELLO:
1703 case L2_LAN_HELLO:
1704 case P2P_HELLO:
1705 if (fabricd && pdu_type != P2P_HELLO)
1706 return ISIS_ERROR;
1707 retval = process_hello(pdu_type, circuit, ssnpa);
1708 break;
1709 case L1_LINK_STATE:
1710 case L2_LINK_STATE:
1711 case FS_LINK_STATE:
1712 if (fabricd
1713 && pdu_type != L2_LINK_STATE
1714 && pdu_type != FS_LINK_STATE)
1715 return ISIS_ERROR;
1716 retval = process_lsp(pdu_type, circuit, ssnpa, max_area_addrs);
1717 break;
1718 case L1_COMPLETE_SEQ_NUM:
1719 case L2_COMPLETE_SEQ_NUM:
1720 case L1_PARTIAL_SEQ_NUM:
1721 case L2_PARTIAL_SEQ_NUM:
1722 retval = process_snp(pdu_type, circuit, ssnpa);
1723 break;
1724 default:
1725 return ISIS_ERROR;
1726 }
1727
1728 return retval;
1729 }
1730
1731 int isis_receive(struct thread *thread)
1732 {
1733 struct isis_circuit *circuit;
1734 uint8_t ssnpa[ETH_ALEN];
1735 int retval;
1736
1737 /*
1738 * Get the circuit
1739 */
1740 circuit = THREAD_ARG(thread);
1741 assert(circuit);
1742
1743 circuit->t_read = NULL;
1744
1745 isis_circuit_stream(circuit, &circuit->rcv_stream);
1746
1747 retval = circuit->rx(circuit, ssnpa);
1748
1749 #if ISIS_METHOD != ISIS_METHOD_BPF
1750 if (retval == ISIS_OK)
1751 retval = isis_handle_pdu(circuit, ssnpa);
1752 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1753
1754 /*
1755 * prepare for next packet.
1756 */
1757 if (!circuit->is_passive)
1758 isis_circuit_prepare(circuit);
1759
1760 return retval;
1761 }
1762
1763 /*
1764 * SEND SIDE
1765 */
1766 void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream)
1767 {
1768 uint8_t length;
1769
1770 if (pdu_size(pdu_type, &length))
1771 assert(!"Unknown PDU Type");
1772
1773 stream_putc(stream, ISO10589_ISIS); /* IDRP */
1774 stream_putc(stream, length); /* Length of fixed header */
1775 stream_putc(stream, 1); /* Version/Protocol ID Extension 1 */
1776 stream_putc(stream, 0); /* ID Length, 0 => 6 */
1777 stream_putc(stream, pdu_type);
1778 stream_putc(stream, 1); /* Subversion */
1779 stream_putc(stream, 0); /* Reserved */
1780 stream_putc(stream, 0); /* Max Area Addresses 0 => 3 */
1781 }
1782
1783 static uint8_t hello_pdu_type(struct isis_circuit *circuit, int level)
1784 {
1785 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1786 return (level == IS_LEVEL_1) ? L1_LAN_HELLO : L2_LAN_HELLO;
1787 else
1788 return P2P_HELLO;
1789 }
1790
1791 static void put_hello_hdr(struct isis_circuit *circuit, int level,
1792 size_t *len_pointer)
1793 {
1794 uint8_t pdu_type = hello_pdu_type(circuit, level);
1795
1796 isis_circuit_stream(circuit, &circuit->snd_stream);
1797 fill_fixed_hdr(pdu_type, circuit->snd_stream);
1798
1799 stream_putc(circuit->snd_stream, circuit->is_type);
1800 stream_put(circuit->snd_stream, circuit->area->isis->sysid,
1801 ISIS_SYS_ID_LEN);
1802
1803 uint32_t holdtime = circuit->hello_multiplier[level - 1]
1804 * circuit->hello_interval[level - 1];
1805
1806 if (holdtime > 0xffff)
1807 holdtime = 0xffff;
1808
1809 stream_putw(circuit->snd_stream, holdtime);
1810 *len_pointer = stream_get_endp(circuit->snd_stream);
1811 stream_putw(circuit->snd_stream, 0); /* length is filled in later */
1812
1813 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1814 uint8_t *desig_is = (level == IS_LEVEL_1)
1815 ? circuit->u.bc.l1_desig_is
1816 : circuit->u.bc.l2_desig_is;
1817 stream_putc(circuit->snd_stream, circuit->priority[level - 1]);
1818 stream_put(circuit->snd_stream, desig_is, ISIS_SYS_ID_LEN + 1);
1819 } else {
1820 stream_putc(circuit->snd_stream, circuit->circuit_id);
1821 }
1822 }
1823
1824 int send_hello(struct isis_circuit *circuit, int level)
1825 {
1826 size_t len_pointer;
1827 int retval;
1828
1829 if (circuit->is_passive)
1830 return ISIS_OK;
1831
1832 if (circuit->interface->mtu == 0) {
1833 zlog_warn("circuit has zero MTU");
1834 return ISIS_WARNING;
1835 }
1836
1837 put_hello_hdr(circuit, level, &len_pointer);
1838
1839 struct isis_tlvs *tlvs = isis_alloc_tlvs();
1840
1841 isis_tlvs_add_auth(tlvs, &circuit->passwd);
1842
1843 if (!listcount(circuit->area->area_addrs)) {
1844 isis_free_tlvs(tlvs);
1845 return ISIS_WARNING;
1846 }
1847
1848 isis_tlvs_add_area_addresses(tlvs, circuit->area->area_addrs);
1849
1850 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1851 isis_tlvs_add_lan_neighbors(
1852 tlvs, circuit->u.bc.lan_neighs[level - 1]);
1853 } else if (circuit->circ_type == CIRCUIT_T_P2P
1854 && !circuit->disable_threeway_adj) {
1855 uint32_t ext_circuit_id = circuit->idx;
1856 if (circuit->u.p2p.neighbor) {
1857 uint8_t threeway_state;
1858
1859 if (fabricd_initial_sync_is_in_progress(circuit->area)
1860 && fabricd_initial_sync_circuit(circuit->area) != circuit)
1861 threeway_state = ISIS_THREEWAY_DOWN;
1862 else
1863 threeway_state = circuit->u.p2p.neighbor->threeway_state;
1864 isis_tlvs_add_threeway_adj(tlvs,
1865 threeway_state,
1866 ext_circuit_id,
1867 circuit->u.p2p.neighbor->sysid,
1868 circuit->u.p2p.neighbor->ext_circuit_id);
1869 } else {
1870 isis_tlvs_add_threeway_adj(tlvs,
1871 ISIS_THREEWAY_DOWN,
1872 ext_circuit_id,
1873 NULL, 0);
1874 }
1875 }
1876
1877 isis_tlvs_set_protocols_supported(tlvs, &circuit->nlpids);
1878
1879 /*
1880 * MT Supported TLV
1881 *
1882 * TLV gets included if no topology is enabled on the interface,
1883 * if one topology other than #0 is enabled, or if multiple topologies
1884 * are enabled.
1885 */
1886 struct isis_circuit_mt_setting **mt_settings;
1887 unsigned int mt_count;
1888
1889 mt_settings = circuit_mt_settings(circuit, &mt_count);
1890 if (mt_count == 0 && area_is_mt(circuit->area)) {
1891 tlvs->mt_router_info_empty = true;
1892 } else if ((mt_count == 1
1893 && mt_settings[0]->mtid != ISIS_MT_IPV4_UNICAST)
1894 || (mt_count > 1)) {
1895 for (unsigned int i = 0; i < mt_count; i++)
1896 isis_tlvs_add_mt_router_info(tlvs, mt_settings[i]->mtid,
1897 false, false);
1898 }
1899
1900 if (circuit->ip_router) {
1901 struct list *circuit_ip_addrs = fabricd_ip_addrs(circuit);
1902
1903 if (circuit_ip_addrs)
1904 isis_tlvs_add_ipv4_addresses(tlvs, circuit_ip_addrs);
1905 }
1906
1907 if (circuit->ipv6_router && circuit->ipv6_link)
1908 isis_tlvs_add_ipv6_addresses(tlvs, circuit->ipv6_link);
1909
1910 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
1911 circuit->pad_hellos, false)) {
1912 isis_free_tlvs(tlvs);
1913 return ISIS_WARNING; /* XXX: Maybe Log TLV structure? */
1914 }
1915
1916 if (isis->debugs & DEBUG_ADJ_PACKETS) {
1917 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1918 zlog_debug(
1919 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1920 circuit->area->area_tag, level,
1921 circuit->interface->name,
1922 stream_get_endp(circuit->snd_stream));
1923 } else {
1924 zlog_debug(
1925 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1926 circuit->area->area_tag,
1927 circuit->interface->name,
1928 stream_get_endp(circuit->snd_stream));
1929 }
1930 if (isis->debugs & DEBUG_PACKET_DUMP)
1931 zlog_dump_data(STREAM_DATA(circuit->snd_stream),
1932 stream_get_endp(circuit->snd_stream));
1933 }
1934
1935 isis_free_tlvs(tlvs);
1936
1937 pdu_counter_count(circuit->area->pdu_tx_counters,
1938 hello_pdu_type(circuit, level));
1939 retval = circuit->tx(circuit, level);
1940 if (retval != ISIS_OK)
1941 flog_err(EC_ISIS_PACKET,
1942 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1943 circuit->area->area_tag, level,
1944 circuit->interface->name);
1945
1946 return retval;
1947 }
1948
1949 static int send_hello_cb(struct thread *thread)
1950 {
1951 struct isis_circuit_arg *arg = THREAD_ARG(thread);
1952 assert(arg);
1953
1954 struct isis_circuit *circuit = arg->circuit;
1955 int level = arg->level;
1956
1957 assert(circuit);
1958
1959 if (circuit->circ_type == CIRCUIT_T_P2P) {
1960 circuit->u.p2p.t_send_p2p_hello = NULL;
1961 send_hello(circuit, 1);
1962 send_hello_sched(circuit, ISIS_LEVEL1,
1963 1000 * circuit->hello_interval[1]);
1964 return ISIS_OK;
1965 }
1966
1967 if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
1968 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1969 circuit->area->area_tag, circuit->circ_type);
1970 return ISIS_WARNING;
1971 }
1972
1973 circuit->u.bc.t_send_lan_hello[level - 1] = NULL;
1974 if (!(circuit->is_type & level)) {
1975 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1976 circuit->area->area_tag, level, 3 - level);
1977 return ISIS_WARNING;
1978 }
1979
1980 if (circuit->u.bc.run_dr_elect[level - 1])
1981 isis_dr_elect(circuit, level);
1982
1983 int rv = send_hello(circuit, level);
1984
1985 /* set next timer thread */
1986 send_hello_sched(circuit, level, 1000 * circuit->hello_interval[level - 1]);
1987 return rv;
1988 }
1989
1990 static void _send_hello_sched(struct isis_circuit *circuit,
1991 struct thread **threadp,
1992 int level, long delay)
1993 {
1994 if (*threadp) {
1995 if (thread_timer_remain_msec(*threadp) < (unsigned long)delay)
1996 return;
1997
1998 thread_cancel(*threadp);
1999 }
2000
2001 thread_add_timer_msec(master, send_hello_cb,
2002 &circuit->level_arg[level - 1],
2003 isis_jitter(delay, IIH_JITTER),
2004 threadp);
2005 }
2006
2007 void send_hello_sched(struct isis_circuit *circuit, int level, long delay)
2008 {
2009 if (circuit->circ_type == CIRCUIT_T_P2P) {
2010 _send_hello_sched(circuit, &circuit->u.p2p.t_send_p2p_hello,
2011 ISIS_LEVEL1, delay);
2012 return;
2013 }
2014
2015 if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
2016 zlog_warn("%s: encountered unknown circuit type %d on %s",
2017 __func__, circuit->circ_type,
2018 circuit->interface->name);
2019 return;
2020 }
2021
2022 for (int loop_level = ISIS_LEVEL1; loop_level <= ISIS_LEVEL2; loop_level++) {
2023 if (!(loop_level & level))
2024 continue;
2025
2026 _send_hello_sched(
2027 circuit,
2028 &circuit->u.bc.t_send_lan_hello[loop_level - 1],
2029 loop_level,
2030 delay
2031 );
2032 }
2033 }
2034
2035
2036 /*
2037 * Count the maximum number of lsps that can be accomodated by a given size.
2038 */
2039 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2040 static uint16_t get_max_lsp_count(uint16_t size)
2041 {
2042 uint16_t tlv_count;
2043 uint16_t lsp_count;
2044 uint16_t remaining_size;
2045
2046 /* First count the full size TLVs */
2047 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2048 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2049
2050 /* The last TLV, if any */
2051 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2052 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2053 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2054
2055 return lsp_count;
2056 }
2057
2058 int send_csnp(struct isis_circuit *circuit, int level)
2059 {
2060 if (lspdb_count(&circuit->area->lspdb[level - 1]) == 0)
2061 return ISIS_OK;
2062
2063 uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_COMPLETE_SEQ_NUM
2064 : L2_COMPLETE_SEQ_NUM;
2065
2066 isis_circuit_stream(circuit, &circuit->snd_stream);
2067 fill_fixed_hdr(pdu_type, circuit->snd_stream);
2068
2069 size_t len_pointer = stream_get_endp(circuit->snd_stream);
2070 stream_putw(circuit->snd_stream, 0);
2071 stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2072 /* with zero circuit id - ref 9.10, 9.11 */
2073 stream_putc(circuit->snd_stream, 0);
2074
2075 size_t start_pointer = stream_get_endp(circuit->snd_stream);
2076 stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2);
2077 size_t end_pointer = stream_get_endp(circuit->snd_stream);
2078 stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2);
2079
2080 struct isis_passwd *passwd = (level == ISIS_LEVEL1)
2081 ? &circuit->area->area_passwd
2082 : &circuit->area->domain_passwd;
2083
2084 struct isis_tlvs *tlvs = isis_alloc_tlvs();
2085
2086 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2087 isis_tlvs_add_auth(tlvs, passwd);
2088
2089 size_t tlv_start = stream_get_endp(circuit->snd_stream);
2090 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false,
2091 false)) {
2092 isis_free_tlvs(tlvs);
2093 return ISIS_WARNING;
2094 }
2095 isis_free_tlvs(tlvs);
2096
2097 uint16_t num_lsps =
2098 get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream));
2099
2100 uint8_t start[ISIS_SYS_ID_LEN + 2];
2101 memset(start, 0x00, ISIS_SYS_ID_LEN + 2);
2102 uint8_t stop[ISIS_SYS_ID_LEN + 2];
2103 memset(stop, 0xff, ISIS_SYS_ID_LEN + 2);
2104
2105 bool loop = true;
2106 while (loop) {
2107 tlvs = isis_alloc_tlvs();
2108 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2109 isis_tlvs_add_auth(tlvs, passwd);
2110
2111 struct isis_lsp *last_lsp;
2112 isis_tlvs_add_csnp_entries(tlvs, start, stop, num_lsps,
2113 &circuit->area->lspdb[level - 1],
2114 &last_lsp);
2115 /*
2116 * Update the stop lsp_id before encoding this CSNP.
2117 */
2118 if (tlvs->lsp_entries.count < num_lsps) {
2119 memset(stop, 0xff, ISIS_SYS_ID_LEN + 2);
2120 } else {
2121 memcpy(stop, last_lsp->hdr.lsp_id, sizeof(stop));
2122 }
2123
2124 memcpy(STREAM_DATA(circuit->snd_stream) + start_pointer, start,
2125 ISIS_SYS_ID_LEN + 2);
2126 memcpy(STREAM_DATA(circuit->snd_stream) + end_pointer, stop,
2127 ISIS_SYS_ID_LEN + 2);
2128 stream_set_endp(circuit->snd_stream, tlv_start);
2129 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
2130 false, false)) {
2131 isis_free_tlvs(tlvs);
2132 return ISIS_WARNING;
2133 }
2134
2135 if (isis->debugs & DEBUG_SNP_PACKETS) {
2136 zlog_debug(
2137 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2138 circuit->area->area_tag, level,
2139 circuit->interface->name,
2140 stream_get_endp(circuit->snd_stream));
2141 log_multiline(LOG_DEBUG, " ", "%s",
2142 isis_format_tlvs(tlvs));
2143 if (isis->debugs & DEBUG_PACKET_DUMP)
2144 zlog_dump_data(
2145 STREAM_DATA(circuit->snd_stream),
2146 stream_get_endp(circuit->snd_stream));
2147 }
2148
2149 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
2150 int retval = circuit->tx(circuit, level);
2151 if (retval != ISIS_OK) {
2152 flog_err(EC_ISIS_PACKET,
2153 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2154 circuit->area->area_tag, level,
2155 circuit->interface->name);
2156 isis_free_tlvs(tlvs);
2157 return retval;
2158 }
2159
2160 /*
2161 * Start lsp_id of the next CSNP should be one plus the
2162 * stop lsp_id in this current CSNP.
2163 */
2164 memcpy(start, stop, ISIS_SYS_ID_LEN + 2);
2165 loop = false;
2166 for (int i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) {
2167 if (start[i] < (uint8_t)0xff) {
2168 start[i] += 1;
2169 loop = true;
2170 break;
2171 }
2172 }
2173 memset(stop, 0xff, ISIS_SYS_ID_LEN + 2);
2174 isis_free_tlvs(tlvs);
2175 }
2176
2177 return ISIS_OK;
2178 }
2179
2180 int send_l1_csnp(struct thread *thread)
2181 {
2182 struct isis_circuit *circuit;
2183
2184 circuit = THREAD_ARG(thread);
2185 assert(circuit);
2186
2187 circuit->t_send_csnp[0] = NULL;
2188
2189 if ((circuit->circ_type == CIRCUIT_T_BROADCAST
2190 && circuit->u.bc.is_dr[0])
2191 || circuit->circ_type == CIRCUIT_T_P2P) {
2192 send_csnp(circuit, 1);
2193 }
2194 /* set next timer thread */
2195 thread_add_timer(master, send_l1_csnp, circuit,
2196 isis_jitter(circuit->csnp_interval[0], CSNP_JITTER),
2197 &circuit->t_send_csnp[0]);
2198
2199 return ISIS_OK;
2200 }
2201
2202 int send_l2_csnp(struct thread *thread)
2203 {
2204 struct isis_circuit *circuit;
2205
2206 circuit = THREAD_ARG(thread);
2207 assert(circuit);
2208
2209 circuit->t_send_csnp[1] = NULL;
2210
2211 if ((circuit->circ_type == CIRCUIT_T_BROADCAST
2212 && circuit->u.bc.is_dr[1])
2213 || circuit->circ_type == CIRCUIT_T_P2P) {
2214 send_csnp(circuit, 2);
2215 }
2216 /* set next timer thread */
2217 thread_add_timer(master, send_l2_csnp, circuit,
2218 isis_jitter(circuit->csnp_interval[1], CSNP_JITTER),
2219 &circuit->t_send_csnp[1]);
2220
2221 return ISIS_OK;
2222 }
2223
2224 /*
2225 * 7.3.15.4 action on expiration of partial SNP interval
2226 * level 1
2227 */
2228 static int send_psnp(int level, struct isis_circuit *circuit)
2229 {
2230 if (circuit->circ_type == CIRCUIT_T_BROADCAST
2231 && circuit->u.bc.is_dr[level - 1])
2232 return ISIS_OK;
2233
2234 if (lspdb_count(&circuit->area->lspdb[level - 1]) == 0)
2235 return ISIS_OK;
2236
2237 if (!circuit->snd_stream)
2238 return ISIS_ERROR;
2239
2240 uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_PARTIAL_SEQ_NUM
2241 : L2_PARTIAL_SEQ_NUM;
2242
2243 isis_circuit_stream(circuit, &circuit->snd_stream);
2244 fill_fixed_hdr(pdu_type, circuit->snd_stream);
2245
2246 size_t len_pointer = stream_get_endp(circuit->snd_stream);
2247 stream_putw(circuit->snd_stream, 0); /* length is filled in later */
2248 stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2249 stream_putc(circuit->snd_stream, circuit->idx);
2250
2251 struct isis_passwd *passwd = (level == ISIS_LEVEL1)
2252 ? &circuit->area->area_passwd
2253 : &circuit->area->domain_passwd;
2254
2255 struct isis_tlvs *tlvs = isis_alloc_tlvs();
2256
2257 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2258 isis_tlvs_add_auth(tlvs, passwd);
2259
2260 size_t tlv_start = stream_get_endp(circuit->snd_stream);
2261 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false,
2262 false)) {
2263 isis_free_tlvs(tlvs);
2264 return ISIS_WARNING;
2265 }
2266 isis_free_tlvs(tlvs);
2267
2268 uint16_t num_lsps =
2269 get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream));
2270
2271 while (1) {
2272 struct isis_lsp *lsp;
2273
2274 tlvs = isis_alloc_tlvs();
2275 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2276 isis_tlvs_add_auth(tlvs, passwd);
2277
2278 frr_each (lspdb, &circuit->area->lspdb[level - 1], lsp) {
2279 if (ISIS_CHECK_FLAG(lsp->SSNflags, circuit))
2280 isis_tlvs_add_lsp_entry(tlvs, lsp);
2281
2282 if (tlvs->lsp_entries.count == num_lsps)
2283 break;
2284 }
2285
2286 if (!tlvs->lsp_entries.count) {
2287 isis_free_tlvs(tlvs);
2288 return ISIS_OK;
2289 }
2290
2291 stream_set_endp(circuit->snd_stream, tlv_start);
2292 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
2293 false, false)) {
2294 isis_free_tlvs(tlvs);
2295 return ISIS_WARNING;
2296 }
2297
2298 if (isis->debugs & DEBUG_SNP_PACKETS) {
2299 zlog_debug(
2300 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2301 circuit->area->area_tag, level,
2302 circuit->interface->name,
2303 stream_get_endp(circuit->snd_stream));
2304 log_multiline(LOG_DEBUG, " ", "%s",
2305 isis_format_tlvs(tlvs));
2306 if (isis->debugs & DEBUG_PACKET_DUMP)
2307 zlog_dump_data(
2308 STREAM_DATA(circuit->snd_stream),
2309 stream_get_endp(circuit->snd_stream));
2310 }
2311
2312 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
2313 int retval = circuit->tx(circuit, level);
2314 if (retval != ISIS_OK) {
2315 flog_err(EC_ISIS_PACKET,
2316 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2317 circuit->area->area_tag, level,
2318 circuit->interface->name);
2319 isis_free_tlvs(tlvs);
2320 return retval;
2321 }
2322
2323 /*
2324 * sending succeeded, we can clear SSN flags of this circuit
2325 * for the LSPs in list
2326 */
2327 struct isis_lsp_entry *entry_head;
2328 entry_head = (struct isis_lsp_entry *)tlvs->lsp_entries.head;
2329 for (struct isis_lsp_entry *entry = entry_head; entry;
2330 entry = entry->next)
2331 ISIS_CLEAR_FLAG(entry->lsp->SSNflags, circuit);
2332 isis_free_tlvs(tlvs);
2333 }
2334
2335 return ISIS_OK;
2336 }
2337
2338 int send_l1_psnp(struct thread *thread)
2339 {
2340
2341 struct isis_circuit *circuit;
2342
2343 circuit = THREAD_ARG(thread);
2344 assert(circuit);
2345
2346 circuit->t_send_psnp[0] = NULL;
2347
2348 send_psnp(1, circuit);
2349 /* set next timer thread */
2350 thread_add_timer(master, send_l1_psnp, circuit,
2351 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
2352 &circuit->t_send_psnp[0]);
2353
2354 return ISIS_OK;
2355 }
2356
2357 /*
2358 * 7.3.15.4 action on expiration of partial SNP interval
2359 * level 2
2360 */
2361 int send_l2_psnp(struct thread *thread)
2362 {
2363 struct isis_circuit *circuit;
2364
2365 circuit = THREAD_ARG(thread);
2366 assert(circuit);
2367
2368 circuit->t_send_psnp[1] = NULL;
2369
2370 send_psnp(2, circuit);
2371
2372 /* set next timer thread */
2373 thread_add_timer(master, send_l2_psnp, circuit,
2374 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
2375 &circuit->t_send_psnp[1]);
2376
2377 return ISIS_OK;
2378 }
2379
2380 /*
2381 * ISO 10589 - 7.3.14.3
2382 */
2383 void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp,
2384 enum isis_tx_type tx_type)
2385 {
2386 int clear_srm = 1;
2387 int retval = ISIS_OK;
2388
2389 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
2390 goto out;
2391
2392 /*
2393 * Do not send if levels do not match
2394 */
2395 if (!(lsp->level & circuit->is_type))
2396 goto out;
2397
2398 /*
2399 * Do not send if we do not have adjacencies in state up on the circuit
2400 */
2401 if (circuit->upadjcount[lsp->level - 1] == 0)
2402 goto out;
2403
2404 /* stream_copy will assert and stop program execution if LSP is larger
2405 * than
2406 * the circuit's MTU. So handle and log this case here. */
2407 if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) {
2408 flog_err(
2409 EC_ISIS_PACKET,
2410 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2411 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
2412 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2413 circuit->area->area_tag, lsp->level,
2414 rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno,
2415 lsp->hdr.checksum, lsp->hdr.rem_lifetime,
2416 circuit->interface->name, stream_get_endp(lsp->pdu),
2417 stream_get_size(circuit->snd_stream));
2418 #ifndef FABRICD
2419 /* send a northbound notification */
2420 isis_notif_lsp_too_large(circuit, stream_get_endp(lsp->pdu),
2421 rawlspid_print(lsp->hdr.lsp_id));
2422 #endif /* ifndef FABRICD */
2423 if (isis->debugs & DEBUG_PACKET_DUMP)
2424 zlog_dump_data(STREAM_DATA(lsp->pdu),
2425 stream_get_endp(lsp->pdu));
2426 retval = ISIS_ERROR;
2427 goto out;
2428 }
2429
2430 /* copy our lsp to the send buffer */
2431 stream_copy(circuit->snd_stream, lsp->pdu);
2432
2433 if (tx_type == TX_LSP_CIRCUIT_SCOPED) {
2434 stream_putc_at(circuit->snd_stream, 4, FS_LINK_STATE);
2435 stream_putc_at(circuit->snd_stream, 7,
2436 L2_CIRCUIT_FLOODING_SCOPE);
2437 }
2438
2439 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
2440 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2441 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
2442 "s on %s",
2443 circuit->area->area_tag,
2444 (tx_type == TX_LSP_CIRCUIT_SCOPED)
2445 ? "Circuit scoped " : "",
2446 lsp->level,
2447 rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno,
2448 lsp->hdr.checksum, lsp->hdr.rem_lifetime,
2449 circuit->interface->name);
2450 if (isis->debugs & DEBUG_PACKET_DUMP)
2451 zlog_dump_data(STREAM_DATA(circuit->snd_stream),
2452 stream_get_endp(circuit->snd_stream));
2453 }
2454
2455 uint8_t pdu_type = (tx_type == TX_LSP_CIRCUIT_SCOPED) ? FS_LINK_STATE
2456 : (lsp->level == ISIS_LEVEL1) ? L1_LINK_STATE
2457 : L2_LINK_STATE;
2458
2459 clear_srm = 0;
2460 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
2461 retval = circuit->tx(circuit, lsp->level);
2462 if (retval != ISIS_OK) {
2463 flog_err(EC_ISIS_PACKET,
2464 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2465 circuit->area->area_tag, lsp->level,
2466 circuit->interface->name,
2467 (retval == ISIS_WARNING) ? "temporarily"
2468 : "permanently");
2469 }
2470
2471 out:
2472 if (clear_srm
2473 || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST)
2474 || (retval != ISIS_OK && retval != ISIS_WARNING)) {
2475 /* SRM flag will trigger retransmission. We will not retransmit
2476 * if we
2477 * encountered a fatal error.
2478 * On success, they should only be cleared if it's a broadcast
2479 * circuit.
2480 * On a P2P circuit, we will wait for the ack from the neighbor
2481 * to clear
2482 * the fag.
2483 */
2484 isis_tx_queue_del(circuit->tx_queue, lsp);
2485 }
2486 }