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