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