2 * IS-IS Rout(e)ing protocol - isis_pdu.c
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
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)
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
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
38 #include "isisd/dict.h"
39 #include "isisd/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_network.h"
45 #include "isisd/isis_misc.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_dynhn.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/iso_checksum.h"
52 #include "isisd/isis_csm.h"
53 #include "isisd/isis_events.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
58 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
65 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
67 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
69 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
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 */
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
);
83 length
= (u_int16_t
)stream_get_endp(circuit
->snd_stream
);
84 /* Update PDU length */
85 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
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
);
101 struct isis_circuit
*circuit
;
106 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
113 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
118 struct isis_tlvs
*tlvs
;
121 static int process_p2p_hello(struct iih_info
*iih
)
124 * My interpertation of the ISO, if no adj exists we will create one for
127 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
128 /* If an adjacency exists, check it is with the source of the hello
131 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
133 "hello source and adjacency do not match, set adj down\n");
134 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
139 if (!adj
|| adj
->level
!= iih
->circ_type
) {
141 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
144 adj
->level
= iih
->circ_type
;
146 iih
->circuit
->u
.p2p
.neighbor
= adj
;
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.
153 adj
->circuit_t
= iih
->circ_type
;
154 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
155 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
158 /* 8.2.6 Monitoring point-to-point adjacencies */
159 adj
->hold_time
= iih
->holdtime
;
160 adj
->last_upd
= time(NULL
);
163 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
164 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
167 /* Update MPLS TE Remote IP address parameter if possible */
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]);
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
,
178 /* 8.2.5.2 a) a match was detected */
179 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
180 iih
->circuit
->area
->area_addrs
)) {
181 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
182 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
183 switch (iih
->circ_type
) {
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
,
190 /* (5) adj usage level 1 */
191 adj
->adj_usage
= ISIS_ADJ_LEVEL1
;
192 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
197 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
198 /* (7) reject - wrong system type event
200 zlog_warn("wrongSystemType");
202 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
203 /* (6) down - wrong system */
204 isis_adj_state_change(adj
,
212 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
213 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
214 switch (iih
->circ_type
) {
216 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
217 /* (6) adj state up */
218 isis_adj_state_change(adj
, ISIS_ADJ_UP
,
220 /* (7) adj usage level 1 */
221 adj
->adj_usage
= ISIS_ADJ_LEVEL1
;
222 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
224 } else if ((adj
->adj_usage
225 == ISIS_ADJ_LEVEL1AND2
)
227 == ISIS_ADJ_LEVEL2
)) {
228 /* (8) down - wrong system */
229 isis_adj_state_change(adj
,
235 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
236 /* (6) adj state up */
237 isis_adj_state_change(adj
, ISIS_ADJ_UP
,
239 /* (9) adj usage level 2 */
240 adj
->adj_usage
= ISIS_ADJ_LEVEL2
;
241 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
243 == ISIS_ADJ_LEVEL1AND2
)) {
244 /* (8) down - wrong system */
245 isis_adj_state_change(adj
,
248 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
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
,
257 /* (10) adj usage level 1 */
258 adj
->adj_usage
= ISIS_ADJ_LEVEL1AND2
;
259 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
261 == ISIS_ADJ_LEVEL2
)) {
262 /* (8) down - wrong system */
263 isis_adj_state_change(adj
,
266 } else if (adj
->adj_usage
267 == ISIS_ADJ_LEVEL1AND2
) {
274 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
275 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
276 switch (iih
->circ_type
) {
278 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
279 /* (5) reject - wrong system type event
281 zlog_warn("wrongSystemType");
283 } else if ((adj
->adj_usage
284 == ISIS_ADJ_LEVEL1AND2
)
286 == ISIS_ADJ_LEVEL2
)) {
287 /* (6) down - wrong system */
288 isis_adj_state_change(adj
,
293 case IS_LEVEL_1_AND_2
:
295 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
296 /* (7) adj state up */
297 isis_adj_state_change(adj
, ISIS_ADJ_UP
,
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
,
307 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
314 /* 8.2.5.2 b) if no match was detected */
315 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
316 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
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
,
321 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
323 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
324 "Down - Area Mismatch");
327 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
329 switch (iih
->circ_type
) {
331 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
332 /* (6) reject - Area Mismatch event */
333 zlog_warn("AreaMismatch");
335 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
336 /* (7) down - area mismatch */
337 isis_adj_state_change(adj
,
341 } else if ((adj
->adj_usage
342 == ISIS_ADJ_LEVEL1AND2
)
344 == ISIS_ADJ_LEVEL2
)) {
345 /* (7) down - wrong system */
346 isis_adj_state_change(adj
,
351 case IS_LEVEL_1_AND_2
:
353 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
354 /* (8) adj state up */
355 isis_adj_state_change(adj
, ISIS_ADJ_UP
,
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
,
364 } else if (adj
->adj_usage
365 == ISIS_ADJ_LEVEL1AND2
) {
366 if (iih
->circ_type
== IS_LEVEL_2
) {
367 /* (7) down - wrong system */
368 isis_adj_state_change(
372 /* (7) down - area mismatch */
373 isis_adj_state_change(
377 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
384 /* down - area mismatch */
385 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
388 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
389 lsp_regenerate_schedule(adj
->circuit
->area
,
390 isis_adj_usage2levels(adj
->adj_usage
),
394 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
395 /* FIXME - Missing parts */
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...
400 switch (adj
->adj_usage
) {
401 case ISIS_ADJ_LEVEL1
:
402 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
404 case ISIS_ADJ_LEVEL2
:
405 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
407 case ISIS_ADJ_LEVEL1AND2
:
408 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
411 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
415 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
417 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
418 " cir id %02d, length %d",
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
);
428 static int process_lan_hello(struct iih_info
*iih
)
430 struct isis_adjacency
*adj
;
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
)) {
436 /* Do as in 8.4.2.5 */
437 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
441 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
443 memset(adj
->snpa
, ' ', 6);
445 adj
->level
= iih
->level
;
447 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
449 if (iih
->level
== IS_LEVEL_1
)
450 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
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]);
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
;
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);
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);
479 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
480 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
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
,
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"
492 bool own_snpa_found
=
493 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
495 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
496 if (own_snpa_found
) {
497 isis_adj_state_change(
499 "own SNPA found in LAN Neighbours TLV");
502 if (!own_snpa_found
) {
503 isis_adj_state_change(
504 adj
, ISIS_ADJ_INITIALIZING
,
505 "own SNPA not found in LAN Neighbours TLV");
509 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
510 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
512 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
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
));
524 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
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
))
531 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
532 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
536 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
539 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
540 int level
= p2p_hello
? 0
541 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
543 const char *pdu_name
=
546 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
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
));
560 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
561 zlog_warn("p2p hello on non p2p circuit");
565 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
566 zlog_warn("lan hello on non broadcast circuit");
570 if (circuit
->ext_domain
) {
572 "level %d LAN Hello received over circuit with externalDomain = true",
577 if (!(circuit
->is_type
& level
)) {
578 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
580 "ISIS-Adj (%s): Interface level mismatch, %s",
581 circuit
->area
->area_tag
,
582 circuit
->interface
->name
);
588 struct iih_info iih
= {
589 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
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
);
598 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
600 iih
.priority
= stream_getc(circuit
->rcv_stream
);
601 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
604 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
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
);
612 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
613 zlog_err("Level %d LAN Hello with Circuit Type %d", level
,
618 const char *error_log
;
619 int retval
= ISIS_WARNING
;
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
);
627 if (!iih
.tlvs
->area_addresses
.count
) {
628 zlog_warn("No Area addresses TLV in %s", pdu_name
);
632 if (!iih
.tlvs
->protocols_supported
.count
) {
633 zlog_warn("No supported protocols TLV in %s", pdu_name
);
637 if (!isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
638 circuit
->rcv_stream
, false)) {
639 isis_event_auth_failure(circuit
->area
->area_tag
,
640 "IIH authentication failure",
645 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
647 "ISIS-Adj (%s): Received IIH with own sysid - discard",
648 circuit
->area
->area_tag
);
653 && (listcount(circuit
->area
->area_addrs
) == 0
654 || (level
== ISIS_LEVEL1
655 && !isis_tlvs_area_addresses_match(
656 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
657 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
659 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
660 circuit
->area
->area_tag
, level
,
661 circuit
->interface
->name
);
666 iih
.v4_usable
= (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
)
667 && iih
.tlvs
->ipv4_address
.count
);
669 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
670 && iih
.tlvs
->ipv6_address
.count
);
672 if (!iih
.v4_usable
&& !iih
.v6_usable
)
675 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
677 isis_free_tlvs(iih
.tlvs
);
683 * Process Level 1/2 Link State
685 * Section 7.3.15.1 - Action on receipt of a link state PDU
687 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
690 int level
= (pdu_type
== L1_LINK_STATE
) ? ISIS_LEVEL1
: ISIS_LEVEL2
;
692 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
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
));
704 struct isis_lsp_hdr hdr
= {};
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
);
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
),
720 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
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
);
730 /* lsp is_type check */
731 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
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
);
736 /* continue as per RFC1122 Be liberal in what you accept, and
737 * conservative in what you send */
740 /* Checksum sanity check - FIXME: move to correct place */
741 /* 12 = sysid+pdu+remtime */
742 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
743 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
745 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
746 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
751 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
752 if (circuit
->ext_domain
) {
754 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
755 "externalDomain = true",
756 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
761 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
762 if (!(circuit
->is_type
& level
)) {
764 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
766 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
767 level
, circuit_t2string(circuit
->is_type
));
771 struct isis_tlvs
*tlvs
= NULL
;
772 int retval
= ISIS_WARNING
;
773 const char *error_log
;
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",
782 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
784 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
787 /* 7.3.15.1 a) 7 - password check */
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",
798 /* Find the LSP in our database and compare it to this Link State header
800 struct isis_lsp
*lsp
=
801 lsp_search(hdr
.lsp_id
, circuit
->area
->lspdb
[level
- 1]);
804 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
805 hdr
.checksum
, hdr
.rem_lifetime
);
806 if (lsp
&& (lsp
->own_lsp
))
809 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
811 /* for broadcast circuits, snpa should be compared */
813 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
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
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 */
826 /* for non broadcast, we just need to find same level adj */
828 /* If no adj, or no sharing of level */
829 if (!circuit
->u
.p2p
.neighbor
) {
833 if (((level
== IS_LEVEL_1
)
834 && (circuit
->u
.p2p
.neighbor
->adj_usage
836 || ((level
== IS_LEVEL_2
)
837 && (circuit
->u
.p2p
.neighbor
->adj_usage
838 == ISIS_ADJ_LEVEL1
)))
846 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
848 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
850 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
853 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
855 * wrong checksum, initiate a purge. */
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
),
862 hdr
.rem_lifetime
= 0;
863 lsp_confusion
= true;
865 lsp_confusion
= false;
867 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
868 if (hdr
.rem_lifetime
== 0) {
870 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
872 /* only needed on explicit update, eg - p2p */
873 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
874 ack_lsp(&hdr
, circuit
, level
);
875 goto out
; /* FIXME: do we need a purge? */
877 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
878 /* LSP by some other system -> do 7.3.16.4 b) */
880 if (comp
== LSP_NEWER
) {
881 lsp_update(lsp
, &hdr
, tlvs
,
883 circuit
->area
, level
,
887 lsp_set_all_srmflags(lsp
);
889 ISIS_FLAGS_CLEAR_ALL(
890 lsp
->SSNflags
); /* FIXME:
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
) {
902 ISIS_CLEAR_FLAG(lsp
->SRMflags
,
905 if (circuit
->circ_type
906 != CIRCUIT_T_BROADCAST
)
911 } /* 7.3.16.4 b) 2) */
912 else if (comp
== LSP_EQUAL
) {
914 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
916 if (circuit
->circ_type
917 != CIRCUIT_T_BROADCAST
)
918 ISIS_SET_FLAG(lsp
->SSNflags
,
920 } /* 7.3.16.4 b) 3) */
922 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
923 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
925 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
926 /* our own LSP -> 7.3.16.4 c) */
927 if (comp
== LSP_NEWER
) {
928 lsp_inc_seqno(lsp
, hdr
.seqno
);
929 lsp_set_all_srmflags(lsp
);
931 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
932 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
934 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
936 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08" PRIx32
,
937 circuit
->area
->area_tag
,
938 rawlspid_print(hdr
.lsp_id
),
944 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
946 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
948 /* 7.3.16.4: initiate a purge */
949 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
953 /* 7.3.15.1 d) - If this is our own lsp and we have it */
955 /* In 7.3.16.1, If an Intermediate system R somewhere in the
957 * has information that the current sequence number for source S
959 * "greater" than that held by S, ... */
961 if (hdr
.seqno
> lsp
->hdr
.seqno
) {
963 lsp_inc_seqno(lsp
, hdr
.seqno
);
964 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
966 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
967 circuit
->area
->area_tag
,
968 rawlspid_print(hdr
.lsp_id
),
971 /* If the received LSP is older or equal,
972 * resend the LSP which will act as ACK */
973 lsp_set_all_srmflags(lsp
);
975 /* 7.3.15.1 e) - This lsp originated on another system */
977 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
979 if ((!lsp
|| comp
== LSP_NEWER
)) {
981 * If this lsp is a frag, need to see if we have zero
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);
988 LSP_FRAGMENT(lspid
) = 0;
990 lspid
, circuit
->area
->lspdb
[level
- 1]);
993 "Got lsp frag, while zero lsp not in database");
999 lsp
= lsp_new_from_recv(
1000 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1001 circuit
->area
, level
);
1004 circuit
->area
->lspdb
[level
- 1]);
1005 } else /* exists, so we overwrite */
1007 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1008 circuit
->area
, level
, false);
1012 lsp_set_all_srmflags(lsp
);
1014 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1017 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1018 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
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
);
1024 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1025 circuit
->area
, level
, false);
1027 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1028 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1030 /* 7.3.15.1 e) 3) LSP older than the one in db */
1032 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1033 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1040 isis_free_tlvs(tlvs
);
1045 * Process Sequence Numbers
1047 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1050 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1051 const u_char
*ssnpa
)
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
)
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 */
1066 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1067 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
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);
1076 if (pdu_len_validate(pdu_len
, circuit
)) {
1077 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1078 return ISIS_WARNING
;
1081 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
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
));
1093 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1094 if (circuit
->ext_domain
) {
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
);
1105 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1106 if (!(circuit
->is_type
& level
)) {
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
);
1117 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1118 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1119 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
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
);
1129 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1132 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1134 * - already checked */
1136 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1138 /* for broadcast circuits, snpa should be compared */
1139 /* FIXME : Do we need to check SNPA? */
1140 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1141 if (!isis_adj_lookup(rem_sys_id
,
1142 circuit
->u
.bc
.adjdb
[level
- 1]))
1143 return ISIS_OK
; /* Silently discard */
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 */
1152 struct isis_tlvs
*tlvs
;
1153 int retval
= ISIS_WARNING
;
1154 const char *error_log
;
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",
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
)
1167 && !isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
,
1169 isis_event_auth_failure(circuit
->area
->area_tag
,
1170 "SNP authentication failure",
1175 struct isis_lsp_entry
*entry_head
=
1176 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
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
);
1183 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1184 entry
= entry
->next
) {
1186 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1187 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
1189 circuit
->area
->area_tag
, typechar
,
1190 rawlspid_print(entry
->id
), entry
->seqno
,
1191 entry
->checksum
, entry
->rem_lifetime
);
1195 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1196 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1197 entry
= entry
->next
) {
1198 struct isis_lsp
*lsp
=
1199 lsp_search(entry
->id
, circuit
->area
->lspdb
[level
- 1]);
1200 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1202 /* 7.3.15.2 b) 1) is this LSP newer */
1203 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1204 entry
->seqno
, entry
->checksum
,
1205 entry
->rem_lifetime
);
1206 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1207 if (cmp
== LSP_EQUAL
) {
1208 /* if (circuit->circ_type !=
1209 * CIRCUIT_T_BROADCAST) */
1210 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1212 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1214 else if (cmp
== LSP_OLDER
) {
1215 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1216 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1218 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1222 lsp_inc_seqno(lsp
, entry
->seqno
);
1223 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1225 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1226 /* if (circuit->circ_type !=
1227 * CIRCUIT_T_BROADCAST) */
1228 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1232 /* 7.3.15.2 b) 5) if it was not found, and all of those
1234 * insert it and set SSN on it */
1235 if (entry
->rem_lifetime
&& entry
->checksum
1236 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1238 struct isis_lsp
*lsp0
= NULL
;
1240 if (LSP_FRAGMENT(entry
->id
)) {
1241 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1243 memcpy(lspid
, entry
->id
,
1244 ISIS_SYS_ID_LEN
+ 1);
1245 LSP_FRAGMENT(lspid
) = 0;
1249 ->lspdb
[level
- 1]);
1252 "Got lsp frag in snp, while zero not in database");
1256 struct isis_lsp
*lsp
=
1257 lsp_new(circuit
->area
, entry
->id
,
1258 entry
->rem_lifetime
, 0, 0,
1259 entry
->checksum
, lsp0
, level
);
1261 circuit
->area
->lspdb
[level
- 1]);
1262 ISIS_FLAGS_CLEAR_ALL(lsp
->SRMflags
);
1263 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1268 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1272 * Build a list from our own LSP db bounded with
1273 * start_lsp_id and stop_lsp_id
1275 struct list
*lsp_list
= list_new();
1276 lsp_build_list_nonzero_ht(start_lsp_id
, stop_lsp_id
, lsp_list
,
1277 circuit
->area
->lspdb
[level
- 1]);
1279 /* Fixme: Find a better solution */
1280 struct listnode
*node
, *nnode
;
1281 struct isis_lsp
*lsp
;
1282 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1283 entry
= entry
->next
) {
1284 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1285 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1287 list_delete_node(lsp_list
, node
);
1293 /* on remaining LSPs we set SRM (neighbor knew not of) */
1294 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
))
1295 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1297 list_delete_and_null(&lsp_list
);
1302 isis_free_tlvs(tlvs
);
1306 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1311 *size
= ISIS_LANHELLO_HDRLEN
;
1314 *size
= ISIS_P2PHELLO_HDRLEN
;
1318 *size
= ISIS_LSP_HDR_LEN
;
1320 case L1_COMPLETE_SEQ_NUM
:
1321 case L2_COMPLETE_SEQ_NUM
:
1322 *size
= ISIS_CSNP_HDRLEN
;
1324 case L1_PARTIAL_SEQ_NUM
:
1325 case L2_PARTIAL_SEQ_NUM
:
1326 *size
= ISIS_PSNP_HDRLEN
;
1331 *size
+= ISIS_FIXED_HDR_LEN
;
1339 static int isis_handle_pdu(struct isis_circuit
*circuit
, u_char
*ssnpa
)
1341 int retval
= ISIS_OK
;
1343 /* Verify that at least the 8 bytes fixed header have been received */
1344 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1345 zlog_err("PDU is too short to be IS-IS.");
1349 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1350 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1351 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1352 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1353 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1354 & 0x1f; /* bits 6-8 are reserved */
1355 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1356 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1357 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1359 if (idrp
== ISO9542_ESIS
) {
1360 zlog_err("No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1364 if (idrp
!= ISO10589_ISIS
) {
1365 zlog_err("Not an IS-IS packet IDRP=%" PRIx8
, idrp
);
1369 if (version1
!= 1) {
1370 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1371 return ISIS_WARNING
;
1374 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1376 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1377 ", while the parameter for this IS is %u",
1378 id_len
, ISIS_SYS_ID_LEN
);
1382 uint8_t expected_length
;
1383 if (pdu_size(pdu_type
, &expected_length
)) {
1384 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1385 return ISIS_WARNING
;
1388 if (length
!= expected_length
) {
1389 zlog_err("Exepected fixed header length = %" PRIu8
1391 expected_length
, length
);
1395 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1397 "PDU is too short to contain fixed header of given PDU type.");
1401 if (version2
!= 1) {
1402 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1403 return ISIS_WARNING
;
1406 if (circuit
->is_passive
) {
1407 zlog_warn("Received ISIS PDU on passive circuit %s",
1408 circuit
->interface
->name
);
1409 return ISIS_WARNING
;
1413 if (max_area_addrs
!= 0 && max_area_addrs
!= isis
->max_area_addrs
) {
1415 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1416 " while the parameter for this IS is %u",
1417 max_area_addrs
, isis
->max_area_addrs
);
1425 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1429 retval
= process_lsp(pdu_type
, circuit
, ssnpa
);
1431 case L1_COMPLETE_SEQ_NUM
:
1432 case L2_COMPLETE_SEQ_NUM
:
1433 case L1_PARTIAL_SEQ_NUM
:
1434 case L2_PARTIAL_SEQ_NUM
:
1435 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1444 int isis_receive(struct thread
*thread
)
1446 struct isis_circuit
*circuit
;
1447 u_char ssnpa
[ETH_ALEN
];
1453 circuit
= THREAD_ARG(thread
);
1456 circuit
->t_read
= NULL
;
1458 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1460 retval
= circuit
->rx(circuit
, ssnpa
);
1462 if (retval
== ISIS_OK
)
1463 retval
= isis_handle_pdu(circuit
, ssnpa
);
1466 * prepare for next packet.
1468 if (!circuit
->is_passive
)
1469 isis_circuit_prepare(circuit
);
1477 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1481 if (pdu_size(pdu_type
, &length
))
1482 assert(!"Unknown PDU Type");
1484 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1485 stream_putc(stream
, length
); /* Length of fixed header */
1486 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1487 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1488 stream_putc(stream
, pdu_type
);
1489 stream_putc(stream
, 1); /* Subversion */
1490 stream_putc(stream
, 0); /* Reserved */
1491 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1494 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1495 size_t *len_pointer
)
1499 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1500 pdu_type
= (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1502 pdu_type
= P2P_HELLO
;
1504 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1505 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1507 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1508 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1511 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1512 * circuit
->hello_interval
[level
- 1];
1514 if (holdtime
> 0xffff)
1517 stream_putw(circuit
->snd_stream
, holdtime
);
1518 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1519 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1521 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1522 u_char
*desig_is
= (level
== IS_LEVEL_1
)
1523 ? circuit
->u
.bc
.l1_desig_is
1524 : circuit
->u
.bc
.l2_desig_is
;
1525 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1526 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1528 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1532 int send_hello(struct isis_circuit
*circuit
, int level
)
1537 if (circuit
->is_passive
)
1540 if (circuit
->interface
->mtu
== 0) {
1541 zlog_warn("circuit has zero MTU");
1542 return ISIS_WARNING
;
1545 put_hello_hdr(circuit
, level
, &len_pointer
);
1547 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1549 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1551 if (!listcount(circuit
->area
->area_addrs
)) {
1552 isis_free_tlvs(tlvs
);
1553 return ISIS_WARNING
;
1556 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1558 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1559 isis_tlvs_add_lan_neighbors(
1560 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1562 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1567 * TLV gets included if no topology is enabled on the interface,
1568 * if one topology other than #0 is enabled, or if multiple topologies
1571 struct isis_circuit_mt_setting
**mt_settings
;
1572 unsigned int mt_count
;
1574 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1575 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1576 tlvs
->mt_router_info_empty
= true;
1577 } else if ((mt_count
== 1
1578 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1579 || (mt_count
> 1)) {
1580 for (unsigned int i
= 0; i
< mt_count
; i
++)
1581 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1585 if (circuit
->ip_router
&& circuit
->ip_addrs
)
1586 isis_tlvs_add_ipv4_addresses(tlvs
, circuit
->ip_addrs
);
1588 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1589 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1591 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1592 circuit
->pad_hellos
, false)) {
1593 isis_free_tlvs(tlvs
);
1594 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1597 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1598 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1600 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1601 circuit
->area
->area_tag
, level
,
1602 circuit
->interface
->name
,
1603 stream_get_endp(circuit
->snd_stream
));
1606 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1607 circuit
->area
->area_tag
,
1608 circuit
->interface
->name
,
1609 stream_get_endp(circuit
->snd_stream
));
1611 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1612 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1613 stream_get_endp(circuit
->snd_stream
));
1616 isis_free_tlvs(tlvs
);
1618 retval
= circuit
->tx(circuit
, level
);
1619 if (retval
!= ISIS_OK
)
1620 zlog_err("ISIS-Adj (%s): Send L%d IIH on %s failed",
1621 circuit
->area
->area_tag
, level
,
1622 circuit
->interface
->name
);
1627 int send_lan_l1_hello(struct thread
*thread
)
1629 struct isis_circuit
*circuit
;
1632 circuit
= THREAD_ARG(thread
);
1634 circuit
->u
.bc
.t_send_lan_hello
[0] = NULL
;
1636 if (!(circuit
->area
->is_type
& IS_LEVEL_1
)) {
1638 "ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
1639 circuit
->area
->area_tag
);
1643 if (circuit
->u
.bc
.run_dr_elect
[0])
1644 isis_dr_elect(circuit
, 1);
1646 retval
= send_hello(circuit
, 1);
1648 /* set next timer thread */
1649 thread_add_timer(master
, send_lan_l1_hello
, circuit
,
1650 isis_jitter(circuit
->hello_interval
[0], IIH_JITTER
),
1651 &circuit
->u
.bc
.t_send_lan_hello
[0]);
1656 int send_lan_l2_hello(struct thread
*thread
)
1658 struct isis_circuit
*circuit
;
1661 circuit
= THREAD_ARG(thread
);
1663 circuit
->u
.bc
.t_send_lan_hello
[1] = NULL
;
1665 if (!(circuit
->area
->is_type
& IS_LEVEL_2
)) {
1666 zlog_warn("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
1667 circuit
->area
->area_tag
);
1671 if (circuit
->u
.bc
.run_dr_elect
[1])
1672 isis_dr_elect(circuit
, 2);
1674 retval
= send_hello(circuit
, 2);
1676 /* set next timer thread */
1677 thread_add_timer(master
, send_lan_l2_hello
, circuit
,
1678 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1679 &circuit
->u
.bc
.t_send_lan_hello
[1]);
1684 int send_p2p_hello(struct thread
*thread
)
1686 struct isis_circuit
*circuit
;
1688 circuit
= THREAD_ARG(thread
);
1690 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1692 send_hello(circuit
, 1);
1694 /* set next timer thread */
1695 thread_add_timer(master
, send_p2p_hello
, circuit
,
1696 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1697 &circuit
->u
.p2p
.t_send_p2p_hello
);
1703 * Count the maximum number of lsps that can be accomodated by a given size.
1705 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
1706 static uint16_t get_max_lsp_count(uint16_t size
)
1710 uint16_t remaining_size
;
1712 /* First count the full size TLVs */
1713 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
1714 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
1716 /* The last TLV, if any */
1717 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
1718 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
1719 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
1724 int send_csnp(struct isis_circuit
*circuit
, int level
)
1726 if (circuit
->area
->lspdb
[level
- 1] == NULL
1727 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1730 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1731 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
1732 : L2_COMPLETE_SEQ_NUM
,
1733 circuit
->snd_stream
);
1735 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1736 stream_putw(circuit
->snd_stream
, 0);
1737 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1738 /* with zero circuit id - ref 9.10, 9.11 */
1739 stream_putc(circuit
->snd_stream
, 0);
1741 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
1742 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1743 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
1744 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1746 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1747 ? &circuit
->area
->area_passwd
1748 : &circuit
->area
->domain_passwd
;
1750 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1752 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1753 isis_tlvs_add_auth(tlvs
, passwd
);
1755 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1756 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1758 isis_free_tlvs(tlvs
);
1759 return ISIS_WARNING
;
1761 isis_free_tlvs(tlvs
);
1764 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1766 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
1767 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
1768 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
1769 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1773 tlvs
= isis_alloc_tlvs();
1774 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1775 isis_tlvs_add_auth(tlvs
, passwd
);
1777 struct isis_lsp
*last_lsp
;
1778 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
1779 circuit
->area
->lspdb
[level
- 1],
1782 * Update the stop lsp_id before encoding this CSNP.
1784 if (tlvs
->lsp_entries
.count
< num_lsps
) {
1785 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1787 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
1790 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
1791 ISIS_SYS_ID_LEN
+ 2);
1792 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
1793 ISIS_SYS_ID_LEN
+ 2);
1794 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1795 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1797 isis_free_tlvs(tlvs
);
1798 return ISIS_WARNING
;
1801 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1803 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
1804 circuit
->area
->area_tag
, level
,
1805 circuit
->interface
->name
,
1806 stream_get_endp(circuit
->snd_stream
));
1807 log_multiline(LOG_DEBUG
, " ", "%s",
1808 isis_format_tlvs(tlvs
));
1809 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1811 STREAM_DATA(circuit
->snd_stream
),
1812 stream_get_endp(circuit
->snd_stream
));
1815 int retval
= circuit
->tx(circuit
, level
);
1816 if (retval
!= ISIS_OK
) {
1817 zlog_err("ISIS-Snp (%s): Send L%d CSNP on %s failed",
1818 circuit
->area
->area_tag
, level
,
1819 circuit
->interface
->name
);
1820 isis_free_tlvs(tlvs
);
1825 * Start lsp_id of the next CSNP should be one plus the
1826 * stop lsp_id in this current CSNP.
1828 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
1830 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
1831 if (start
[i
] < (u_char
)0xff) {
1837 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1838 isis_free_tlvs(tlvs
);
1844 int send_l1_csnp(struct thread
*thread
)
1846 struct isis_circuit
*circuit
;
1847 int retval
= ISIS_OK
;
1849 circuit
= THREAD_ARG(thread
);
1852 circuit
->t_send_csnp
[0] = NULL
;
1854 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1855 && circuit
->u
.bc
.is_dr
[0]) {
1856 send_csnp(circuit
, 1);
1858 /* set next timer thread */
1859 thread_add_timer(master
, send_l1_csnp
, circuit
,
1860 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
1861 &circuit
->t_send_csnp
[0]);
1866 int send_l2_csnp(struct thread
*thread
)
1868 struct isis_circuit
*circuit
;
1869 int retval
= ISIS_OK
;
1871 circuit
= THREAD_ARG(thread
);
1874 circuit
->t_send_csnp
[1] = NULL
;
1876 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1877 && circuit
->u
.bc
.is_dr
[1]) {
1878 send_csnp(circuit
, 2);
1880 /* set next timer thread */
1881 thread_add_timer(master
, send_l2_csnp
, circuit
,
1882 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
1883 &circuit
->t_send_csnp
[1]);
1889 * 7.3.15.4 action on expiration of partial SNP interval
1892 static int send_psnp(int level
, struct isis_circuit
*circuit
)
1894 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1895 && circuit
->u
.bc
.is_dr
[level
- 1])
1898 if (circuit
->area
->lspdb
[level
- 1] == NULL
1899 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1902 if (!circuit
->snd_stream
)
1905 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1906 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
1907 : L2_PARTIAL_SEQ_NUM
,
1908 circuit
->snd_stream
);
1910 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1911 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1912 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1913 stream_putc(circuit
->snd_stream
, circuit
->idx
);
1915 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1916 ? &circuit
->area
->area_passwd
1917 : &circuit
->area
->domain_passwd
;
1919 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1921 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1922 isis_tlvs_add_auth(tlvs
, passwd
);
1924 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1925 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1927 isis_free_tlvs(tlvs
);
1928 return ISIS_WARNING
;
1930 isis_free_tlvs(tlvs
);
1933 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1936 tlvs
= isis_alloc_tlvs();
1937 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1938 isis_tlvs_add_auth(tlvs
, passwd
);
1940 for (dnode_t
*dnode
=
1941 dict_first(circuit
->area
->lspdb
[level
- 1]);
1942 dnode
; dnode
= dict_next(circuit
->area
->lspdb
[level
- 1],
1944 struct isis_lsp
*lsp
= dnode_get(dnode
);
1946 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
1947 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
1949 if (tlvs
->lsp_entries
.count
== num_lsps
)
1953 if (!tlvs
->lsp_entries
.count
) {
1954 isis_free_tlvs(tlvs
);
1958 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1959 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1961 isis_free_tlvs(tlvs
);
1962 return ISIS_WARNING
;
1965 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1967 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
1968 circuit
->area
->area_tag
, level
,
1969 circuit
->interface
->name
,
1970 stream_get_endp(circuit
->snd_stream
));
1971 log_multiline(LOG_DEBUG
, " ", "%s",
1972 isis_format_tlvs(tlvs
));
1973 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1975 STREAM_DATA(circuit
->snd_stream
),
1976 stream_get_endp(circuit
->snd_stream
));
1979 int retval
= circuit
->tx(circuit
, level
);
1980 if (retval
!= ISIS_OK
) {
1981 zlog_err("ISIS-Snp (%s): Send L%d PSNP on %s failed",
1982 circuit
->area
->area_tag
, level
,
1983 circuit
->interface
->name
);
1984 isis_free_tlvs(tlvs
);
1989 * sending succeeded, we can clear SSN flags of this circuit
1990 * for the LSPs in list
1992 struct isis_lsp_entry
*entry_head
;
1993 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1994 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1995 entry
= entry
->next
)
1996 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
1997 isis_free_tlvs(tlvs
);
2003 int send_l1_psnp(struct thread
*thread
)
2006 struct isis_circuit
*circuit
;
2007 int retval
= ISIS_OK
;
2009 circuit
= THREAD_ARG(thread
);
2012 circuit
->t_send_psnp
[0] = NULL
;
2014 send_psnp(1, circuit
);
2015 /* set next timer thread */
2016 thread_add_timer(master
, send_l1_psnp
, circuit
,
2017 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2018 &circuit
->t_send_psnp
[0]);
2024 * 7.3.15.4 action on expiration of partial SNP interval
2027 int send_l2_psnp(struct thread
*thread
)
2029 struct isis_circuit
*circuit
;
2030 int retval
= ISIS_OK
;
2032 circuit
= THREAD_ARG(thread
);
2035 circuit
->t_send_psnp
[1] = NULL
;
2037 send_psnp(2, circuit
);
2039 /* set next timer thread */
2040 thread_add_timer(master
, send_l2_psnp
, circuit
,
2041 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2042 &circuit
->t_send_psnp
[1]);
2048 * ISO 10589 - 7.3.14.3
2050 int send_lsp(struct thread
*thread
)
2052 struct isis_circuit
*circuit
;
2053 struct isis_lsp
*lsp
;
2055 int retval
= ISIS_OK
;
2057 circuit
= THREAD_ARG(thread
);
2059 circuit
->t_send_lsp
= NULL
;
2061 lsp
= isis_circuit_lsp_queue_pop(circuit
);
2065 if (!list_isempty(circuit
->lsp_queue
)) {
2066 isis_circuit_schedule_lsp_send(circuit
);
2069 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2073 * Do not send if levels do not match
2075 if (!(lsp
->level
& circuit
->is_type
))
2079 * Do not send if we do not have adjacencies in state up on the circuit
2081 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2084 /* stream_copy will assert and stop program execution if LSP is larger
2086 * the circuit's MTU. So handle and log this case here. */
2087 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2089 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2090 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2091 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2092 circuit
->area
->area_tag
, lsp
->level
,
2093 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2094 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2095 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2096 stream_get_size(circuit
->snd_stream
));
2097 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2098 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2099 stream_get_endp(lsp
->pdu
));
2100 retval
= ISIS_ERROR
;
2104 /* copy our lsp to the send buffer */
2105 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2107 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2108 zlog_debug("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08" PRIx32
2109 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2111 circuit
->area
->area_tag
, lsp
->level
,
2112 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2113 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2114 circuit
->interface
->name
);
2115 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2116 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2117 stream_get_endp(circuit
->snd_stream
));
2121 retval
= circuit
->tx(circuit
, lsp
->level
);
2122 if (retval
!= ISIS_OK
) {
2123 zlog_err("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2124 circuit
->area
->area_tag
, lsp
->level
,
2125 circuit
->interface
->name
,
2126 (retval
== ISIS_WARNING
) ? "temporarily"
2132 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2133 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2134 /* SRM flag will trigger retransmission. We will not retransmit
2136 * encountered a fatal error.
2137 * On success, they should only be cleared if it's a broadcast
2139 * On a P2P circuit, we will wait for the ack from the neighbor
2143 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);