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