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
= (uint16_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
)
123 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
125 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
126 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
127 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d\n",
128 iih
->circuit
->area
->area_tag
,
129 iih
->circuit
->interface
->name
,
135 if (tw_adj
->neighbor_set
136 && (memcmp(tw_adj
->neighbor_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)
137 || tw_adj
->neighbor_circuit_id
!= (uint32_t) iih
->circuit
->idx
)) {
139 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
140 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.\n",
141 iih
->circuit
->area
->area_tag
,
142 iih
->circuit
->interface
->name
);
150 * My interpertation of the ISO, if no adj exists we will create one for
153 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
154 /* If an adjacency exists, check it is with the source of the hello
157 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
159 "hello source and adjacency do not match, set adj down\n");
160 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
165 if (!adj
|| adj
->level
!= iih
->circ_type
) {
167 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
170 adj
->level
= iih
->circ_type
;
172 iih
->circuit
->u
.p2p
.neighbor
= adj
;
173 /* Build lsp with the new neighbor entry when a new
174 * adjacency is formed. Set adjacency circuit type to
175 * IIH PDU header circuit type before lsp is regenerated
176 * when an adjacency is up. This will result in the new
177 * adjacency entry getting added to the lsp tlv neighbor list.
179 adj
->circuit_t
= iih
->circ_type
;
180 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
181 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
184 if (tw_adj
&& adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
185 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
187 /* 8.2.6 Monitoring point-to-point adjacencies */
188 adj
->hold_time
= iih
->holdtime
;
189 adj
->last_upd
= time(NULL
);
192 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
193 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
196 /* Update MPLS TE Remote IP address parameter if possible */
197 if (IS_MPLS_TE(isisMplsTE
) && iih
->circuit
->mtc
198 && IS_CIRCUIT_TE(iih
->circuit
->mtc
) && adj
->ipv4_address_count
)
199 set_circuitparams_rmt_ipaddr(iih
->circuit
->mtc
,
200 adj
->ipv4_addresses
[0]);
202 /* lets take care of the expiry */
203 THREAD_TIMER_OFF(adj
->t_expire
);
204 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
207 /* 8.2.5.2 a) a match was detected */
208 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
209 iih
->circuit
->area
->area_addrs
)) {
210 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
211 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
212 switch (iih
->circ_type
) {
214 case IS_LEVEL_1_AND_2
:
215 if (adj
->adj_state
!= ISIS_ADJ_UP
216 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
217 isis_adj_process_threeway(adj
, tw_adj
,
222 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
223 /* (7) reject - wrong system type event
225 zlog_warn("wrongSystemType");
227 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
228 /* (6) down - wrong system */
229 isis_adj_state_change(adj
,
237 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
238 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
239 switch (iih
->circ_type
) {
241 if (adj
->adj_state
!= ISIS_ADJ_UP
242 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
243 isis_adj_process_threeway(adj
, tw_adj
,
245 } else if ((adj
->adj_usage
246 == ISIS_ADJ_LEVEL1AND2
)
248 == ISIS_ADJ_LEVEL2
)) {
249 /* (8) down - wrong system */
250 isis_adj_state_change(adj
,
256 if (adj
->adj_state
!= ISIS_ADJ_UP
257 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
258 isis_adj_process_threeway(adj
, tw_adj
,
260 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
262 == ISIS_ADJ_LEVEL1AND2
)) {
263 /* (8) down - wrong system */
264 isis_adj_state_change(adj
,
269 case IS_LEVEL_1_AND_2
:
270 if (adj
->adj_state
!= ISIS_ADJ_UP
271 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
272 isis_adj_process_threeway(adj
, tw_adj
,
273 ISIS_ADJ_LEVEL1AND2
);
274 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
276 == ISIS_ADJ_LEVEL2
)) {
277 /* (8) down - wrong system */
278 isis_adj_state_change(adj
,
286 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
287 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
288 switch (iih
->circ_type
) {
290 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
291 /* (5) reject - wrong system type event
293 zlog_warn("wrongSystemType");
295 } else if ((adj
->adj_usage
296 == ISIS_ADJ_LEVEL1AND2
)
298 == ISIS_ADJ_LEVEL2
)) {
299 /* (6) down - wrong system */
300 isis_adj_state_change(adj
,
305 case IS_LEVEL_1_AND_2
:
307 if (adj
->adj_state
!= ISIS_ADJ_UP
308 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
309 isis_adj_process_threeway(adj
, tw_adj
,
311 } else if (adj
->adj_usage
312 == ISIS_ADJ_LEVEL1AND2
) {
313 /* (6) down - wrong system */
314 isis_adj_state_change(adj
,
322 /* 8.2.5.2 b) if no match was detected */
323 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
324 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
325 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
326 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
327 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
329 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
331 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
332 "Down - Area Mismatch");
335 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
337 switch (iih
->circ_type
) {
339 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
340 /* (6) reject - Area Mismatch event */
341 zlog_warn("AreaMismatch");
343 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
344 /* (7) down - area mismatch */
345 isis_adj_state_change(adj
,
349 } else if ((adj
->adj_usage
350 == ISIS_ADJ_LEVEL1AND2
)
352 == ISIS_ADJ_LEVEL2
)) {
353 /* (7) down - wrong system */
354 isis_adj_state_change(adj
,
359 case IS_LEVEL_1_AND_2
:
361 if (adj
->adj_state
!= ISIS_ADJ_UP
362 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
363 isis_adj_process_threeway(adj
, tw_adj
,
365 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
366 /* (7) down - wrong system */
367 isis_adj_state_change(adj
,
370 } else if (adj
->adj_usage
371 == ISIS_ADJ_LEVEL1AND2
) {
372 if (iih
->circ_type
== IS_LEVEL_2
) {
373 /* (7) down - wrong system */
374 isis_adj_state_change(
378 /* (7) down - area mismatch */
379 isis_adj_state_change(
388 /* down - area mismatch */
389 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
392 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
393 lsp_regenerate_schedule(adj
->circuit
->area
,
394 isis_adj_usage2levels(adj
->adj_usage
),
398 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
399 /* FIXME - Missing parts */
401 /* some of my own understanding of the ISO, why the heck does
402 * it not say what should I change the system_type to...
404 switch (adj
->adj_usage
) {
405 case ISIS_ADJ_LEVEL1
:
406 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
408 case ISIS_ADJ_LEVEL2
:
409 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
411 case ISIS_ADJ_LEVEL1AND2
:
412 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
415 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
419 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
421 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
422 " cir id %hhu, length %" PRIu16
,
423 iih
->circuit
->area
->area_tag
,
424 iih
->circuit
->interface
->name
,
425 circuit_t2string(iih
->circuit
->is_type
),
426 iih
->circuit
->circuit_id
, iih
->pdu_len
);
432 static int process_lan_hello(struct iih_info
*iih
)
434 struct isis_adjacency
*adj
;
435 adj
= isis_adj_lookup(iih
->sys_id
,
436 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
437 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
438 || (adj
->level
!= iih
->level
)) {
440 /* Do as in 8.4.2.5 */
441 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
445 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
447 memset(adj
->snpa
, ' ', 6);
449 adj
->level
= iih
->level
;
451 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
453 if (iih
->level
== IS_LEVEL_1
)
454 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
456 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
457 list_delete_all_node(
458 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
459 isis_adj_build_neigh_list(
460 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
461 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
464 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
465 uint8_t *dis
= (iih
->level
== 1)
466 ? iih
->circuit
->u
.bc
.l1_desig_is
467 : iih
->circuit
->u
.bc
.l2_desig_is
;
469 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
470 thread_add_event(master
, isis_event_dis_status_change
,
471 iih
->circuit
, 0, NULL
);
472 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
476 adj
->circuit_t
= iih
->circ_type
;
477 adj
->hold_time
= iih
->holdtime
;
478 adj
->last_upd
= time(NULL
);
479 adj
->prio
[iih
->level
- 1] = iih
->priority
;
480 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
483 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
484 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
487 /* lets take care of the expiry */
488 THREAD_TIMER_OFF(adj
->t_expire
);
489 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
493 * If the snpa for this circuit is found from LAN Neighbours TLV
494 * we have two-way communication -> adjacency can be put to state "up"
496 bool own_snpa_found
=
497 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
499 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
500 if (own_snpa_found
) {
501 isis_adj_state_change(
503 "own SNPA found in LAN Neighbours TLV");
506 if (!own_snpa_found
) {
507 isis_adj_state_change(
508 adj
, ISIS_ADJ_INITIALIZING
,
509 "own SNPA not found in LAN Neighbours TLV");
513 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
514 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
516 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
518 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
519 iih
->circuit
->area
->area_tag
, iih
->level
,
520 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
521 circuit_t2string(iih
->circuit
->is_type
),
522 iih
->circuit
->circuit_id
,
523 stream_get_endp(iih
->circuit
->rcv_stream
));
528 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
530 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
531 || pdu_len
> ISO_MTU(circuit
)
532 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
535 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
536 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
540 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
543 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
544 int level
= p2p_hello
? 0
545 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
547 const char *pdu_name
=
550 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
552 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
553 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
554 circuit
->area
->area_tag
, pdu_name
,
555 circuit
->interface
->name
,
556 circuit_t2string(circuit
->is_type
),
557 circuit
->circuit_id
);
558 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
559 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
560 stream_get_endp(circuit
->rcv_stream
));
564 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
565 zlog_warn("p2p hello on non p2p circuit");
569 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
570 zlog_warn("lan hello on non broadcast circuit");
574 if (circuit
->ext_domain
) {
576 "level %d LAN Hello received over circuit with externalDomain = true",
581 if (!(circuit
->is_type
& level
)) {
582 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
584 "ISIS-Adj (%s): Interface level mismatch, %s",
585 circuit
->area
->area_tag
,
586 circuit
->interface
->name
);
592 struct iih_info iih
= {
593 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
595 /* Generic IIH Header */
596 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
597 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
598 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
599 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
602 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
604 iih
.priority
= stream_getc(circuit
->rcv_stream
);
605 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
608 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
610 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
611 circuit
->area
->area_tag
, pdu_name
,
612 circuit
->interface
->name
, iih
.pdu_len
);
616 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
617 zlog_err("Level %d LAN Hello with Circuit Type %d", level
,
622 const char *error_log
;
623 int retval
= ISIS_WARNING
;
625 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
626 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
627 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
631 if (!iih
.tlvs
->area_addresses
.count
) {
632 zlog_warn("No Area addresses TLV in %s", pdu_name
);
636 if (!iih
.tlvs
->protocols_supported
.count
) {
637 zlog_warn("No supported protocols TLV in %s", pdu_name
);
641 if (!isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
642 circuit
->rcv_stream
, false)) {
643 isis_event_auth_failure(circuit
->area
->area_tag
,
644 "IIH authentication failure",
649 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
651 "ISIS-Adj (%s): Received IIH with own sysid - discard",
652 circuit
->area
->area_tag
);
657 && (listcount(circuit
->area
->area_addrs
) == 0
658 || (level
== ISIS_LEVEL1
659 && !isis_tlvs_area_addresses_match(
660 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
661 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
663 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
664 circuit
->area
->area_tag
, level
,
665 circuit
->interface
->name
);
670 iih
.v4_usable
= (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
)
671 && iih
.tlvs
->ipv4_address
.count
);
673 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
674 && iih
.tlvs
->ipv6_address
.count
);
676 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
677 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
679 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
680 circuit
->area
->area_tag
);
686 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
688 isis_free_tlvs(iih
.tlvs
);
694 * Process Level 1/2 Link State
696 * Section 7.3.15.1 - Action on receipt of a link state PDU
698 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
699 const uint8_t *ssnpa
)
701 int level
= (pdu_type
== L1_LINK_STATE
) ? ISIS_LEVEL1
: ISIS_LEVEL2
;
703 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
705 "ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
706 circuit
->area
->area_tag
, level
,
707 circuit
->interface
->name
,
708 circuit_t2string(circuit
->is_type
),
709 circuit
->circuit_id
);
710 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
711 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
712 stream_get_endp(circuit
->rcv_stream
));
715 struct isis_lsp_hdr hdr
= {};
717 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
718 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
719 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
720 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
721 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
722 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
724 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
725 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
726 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
731 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
732 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
733 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
734 "s, len %" PRIu16
", on %s",
735 circuit
->area
->area_tag
, level
,
736 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
737 hdr
.rem_lifetime
, hdr
.pdu_len
,
738 circuit
->interface
->name
);
741 /* lsp is_type check */
742 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
744 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
745 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
746 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
747 /* continue as per RFC1122 Be liberal in what you accept, and
748 * conservative in what you send */
751 /* Checksum sanity check - FIXME: move to correct place */
752 /* 12 = sysid+pdu+remtime */
753 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
754 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
756 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
757 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
762 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
763 if (circuit
->ext_domain
) {
765 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
766 "externalDomain = true",
767 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
772 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
773 if (!(circuit
->is_type
& level
)) {
775 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
777 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
778 level
, circuit_t2string(circuit
->is_type
));
782 struct isis_tlvs
*tlvs
= NULL
;
783 int retval
= ISIS_WARNING
;
784 const char *error_log
;
786 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
787 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
788 zlog_warn("Something went wrong unpacking the LSP: %s",
793 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
795 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
798 /* 7.3.15.1 a) 7 - password check */
799 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
800 ? &circuit
->area
->area_passwd
801 : &circuit
->area
->domain_passwd
;
802 if (!isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
, true)) {
803 isis_event_auth_failure(circuit
->area
->area_tag
,
804 "LSP authentication failure",
809 /* Find the LSP in our database and compare it to this Link State header
811 struct isis_lsp
*lsp
=
812 lsp_search(hdr
.lsp_id
, circuit
->area
->lspdb
[level
- 1]);
815 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
816 hdr
.checksum
, hdr
.rem_lifetime
);
817 if (lsp
&& (lsp
->own_lsp
))
820 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
822 /* for broadcast circuits, snpa should be compared */
824 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
825 if (!isis_adj_lookup_snpa(ssnpa
,
826 circuit
->u
.bc
.adjdb
[level
- 1])) {
827 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
828 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
830 circuit
->area
->area_tag
,
831 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
832 hdr
.checksum
, hdr
.rem_lifetime
,
833 circuit
->interface
->name
);
834 goto out
; /* Silently discard */
837 /* for non broadcast, we just need to find same level adj */
839 /* If no adj, or no sharing of level */
840 if (!circuit
->u
.p2p
.neighbor
) {
844 if (((level
== IS_LEVEL_1
)
845 && (circuit
->u
.p2p
.neighbor
->adj_usage
847 || ((level
== IS_LEVEL_2
)
848 && (circuit
->u
.p2p
.neighbor
->adj_usage
849 == ISIS_ADJ_LEVEL1
)))
857 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
859 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
861 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
864 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
866 * wrong checksum, initiate a purge. */
867 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
868 && (lsp
->hdr
.checksum
!= hdr
.checksum
)) {
869 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
870 " with confused checksum received.",
871 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
873 hdr
.rem_lifetime
= 0;
874 lsp_confusion
= true;
876 lsp_confusion
= false;
878 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
879 if (hdr
.rem_lifetime
== 0) {
881 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
883 /* only needed on explicit update, eg - p2p */
884 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
885 ack_lsp(&hdr
, circuit
, level
);
886 goto out
; /* FIXME: do we need a purge? */
888 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
889 /* LSP by some other system -> do 7.3.16.4 b) */
891 if (comp
== LSP_NEWER
) {
892 lsp_update(lsp
, &hdr
, tlvs
,
894 circuit
->area
, level
,
898 lsp_set_all_srmflags(lsp
);
900 ISIS_FLAGS_CLEAR_ALL(
901 lsp
->SSNflags
); /* FIXME:
906 /* For the case of lsp confusion, flood
907 * the purge back to its
908 * originator so that it can react.
909 * Otherwise, don't reflood
910 * through incoming circuit as usual */
911 if (!lsp_confusion
) {
913 ISIS_CLEAR_FLAG(lsp
->SRMflags
,
916 if (circuit
->circ_type
917 != CIRCUIT_T_BROADCAST
)
922 } /* 7.3.16.4 b) 2) */
923 else if (comp
== LSP_EQUAL
) {
925 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
927 if (circuit
->circ_type
928 != CIRCUIT_T_BROADCAST
)
929 ISIS_SET_FLAG(lsp
->SSNflags
,
931 } /* 7.3.16.4 b) 3) */
933 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
934 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
936 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
937 /* our own LSP -> 7.3.16.4 c) */
938 if (comp
== LSP_NEWER
) {
939 lsp_inc_seqno(lsp
, hdr
.seqno
);
940 lsp_set_all_srmflags(lsp
);
942 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
943 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
945 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
947 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08" PRIx32
,
948 circuit
->area
->area_tag
,
949 rawlspid_print(hdr
.lsp_id
),
955 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
957 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
959 /* 7.3.16.4: initiate a purge */
960 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
964 /* 7.3.15.1 d) - If this is our own lsp and we have it */
966 /* In 7.3.16.1, If an Intermediate system R somewhere in the
968 * has information that the current sequence number for source S
970 * "greater" than that held by S, ... */
972 if (hdr
.seqno
> lsp
->hdr
.seqno
) {
974 lsp_inc_seqno(lsp
, hdr
.seqno
);
975 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
977 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
978 circuit
->area
->area_tag
,
979 rawlspid_print(hdr
.lsp_id
),
982 /* If the received LSP is older or equal,
983 * resend the LSP which will act as ACK */
984 lsp_set_all_srmflags(lsp
);
986 /* 7.3.15.1 e) - This lsp originated on another system */
988 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
990 if ((!lsp
|| comp
== LSP_NEWER
)) {
992 * If this lsp is a frag, need to see if we have zero
995 struct isis_lsp
*lsp0
= NULL
;
996 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
997 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
998 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
999 LSP_FRAGMENT(lspid
) = 0;
1001 lspid
, circuit
->area
->lspdb
[level
- 1]);
1004 "Got lsp frag, while zero lsp not in database");
1010 lsp
= lsp_new_from_recv(
1011 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1012 circuit
->area
, level
);
1015 circuit
->area
->lspdb
[level
- 1]);
1016 } else /* exists, so we overwrite */
1018 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1019 circuit
->area
, level
, false);
1023 lsp_set_all_srmflags(lsp
);
1025 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1028 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1029 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1032 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1033 else if (comp
== LSP_EQUAL
) {
1034 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1035 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1036 circuit
->area
, level
, false);
1038 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1039 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1041 /* 7.3.15.1 e) 3) LSP older than the one in db */
1043 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1044 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1051 isis_free_tlvs(tlvs
);
1056 * Process Sequence Numbers
1058 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1061 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1062 const uint8_t *ssnpa
)
1064 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1065 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1066 char typechar
= is_csnp
? 'C' : 'P';
1067 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1068 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1072 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1073 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1074 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1075 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1077 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1078 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1081 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1082 ISIS_SYS_ID_LEN
+ 2);
1083 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1084 ISIS_SYS_ID_LEN
+ 2);
1087 if (pdu_len_validate(pdu_len
, circuit
)) {
1088 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1089 return ISIS_WARNING
;
1092 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1094 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1095 circuit
->area
->area_tag
, level
, typechar
,
1096 circuit
->interface
->name
,
1097 circuit_t2string(circuit
->is_type
),
1098 circuit
->circuit_id
);
1099 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1100 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1101 stream_get_endp(circuit
->rcv_stream
));
1104 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1105 if (circuit
->ext_domain
) {
1108 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1109 "skipping: circuit externalDomain = true",
1110 circuit
->area
->area_tag
, level
, typechar
,
1111 circuit
->interface
->name
);
1116 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1117 if (!(circuit
->is_type
& level
)) {
1119 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1120 "skipping: circuit type %s does not match level %d",
1121 circuit
->area
->area_tag
, level
, typechar
,
1122 circuit
->interface
->name
,
1123 circuit_t2string(circuit
->is_type
), level
);
1128 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1129 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1130 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1132 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1133 "skipping: we are not the DIS",
1134 circuit
->area
->area_tag
, level
, typechar
,
1135 snpa_print(ssnpa
), circuit
->interface
->name
);
1140 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1143 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1145 * - already checked */
1147 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1149 /* for broadcast circuits, snpa should be compared */
1150 /* FIXME : Do we need to check SNPA? */
1151 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1152 if (!isis_adj_lookup(rem_sys_id
,
1153 circuit
->u
.bc
.adjdb
[level
- 1]))
1154 return ISIS_OK
; /* Silently discard */
1156 if (!circuit
->u
.p2p
.neighbor
) {
1157 zlog_warn("no p2p neighbor on circuit %s",
1158 circuit
->interface
->name
);
1159 return ISIS_OK
; /* Silently discard */
1163 struct isis_tlvs
*tlvs
;
1164 int retval
= ISIS_WARNING
;
1165 const char *error_log
;
1167 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1168 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1169 zlog_warn("Something went wrong unpacking the SNP: %s",
1174 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1175 ? &circuit
->area
->area_passwd
1176 : &circuit
->area
->domain_passwd
;
1177 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)
1178 && !isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
,
1180 isis_event_auth_failure(circuit
->area
->area_tag
,
1181 "SNP authentication failure",
1186 struct isis_lsp_entry
*entry_head
=
1187 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1189 /* debug isis snp-packets */
1190 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1191 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1192 circuit
->area
->area_tag
, level
, typechar
,
1193 snpa_print(ssnpa
), circuit
->interface
->name
);
1194 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1195 entry
= entry
->next
) {
1197 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1198 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1199 circuit
->area
->area_tag
, typechar
,
1200 rawlspid_print(entry
->id
), entry
->seqno
,
1201 entry
->checksum
, entry
->rem_lifetime
);
1205 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1206 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1207 entry
= entry
->next
) {
1208 struct isis_lsp
*lsp
=
1209 lsp_search(entry
->id
, circuit
->area
->lspdb
[level
- 1]);
1210 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1212 /* 7.3.15.2 b) 1) is this LSP newer */
1213 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1214 entry
->seqno
, entry
->checksum
,
1215 entry
->rem_lifetime
);
1216 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1217 if (cmp
== LSP_EQUAL
) {
1218 /* if (circuit->circ_type !=
1219 * CIRCUIT_T_BROADCAST) */
1220 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1222 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1224 else if (cmp
== LSP_OLDER
) {
1225 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1226 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1228 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1232 lsp_inc_seqno(lsp
, entry
->seqno
);
1233 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1235 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1236 /* if (circuit->circ_type !=
1237 * CIRCUIT_T_BROADCAST) */
1238 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1242 /* 7.3.15.2 b) 5) if it was not found, and all of those
1244 * insert it and set SSN on it */
1245 if (entry
->rem_lifetime
&& entry
->checksum
1246 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1248 struct isis_lsp
*lsp0
= NULL
;
1250 if (LSP_FRAGMENT(entry
->id
)) {
1251 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1253 memcpy(lspid
, entry
->id
,
1254 ISIS_SYS_ID_LEN
+ 1);
1255 LSP_FRAGMENT(lspid
) = 0;
1258 circuit
->area
->lspdb
[level
- 1]);
1260 zlog_debug("Got lsp frag in snp, while zero not in database");
1264 struct isis_lsp
*lsp
=
1265 lsp_new(circuit
->area
, entry
->id
,
1266 entry
->rem_lifetime
, 0, 0,
1267 entry
->checksum
, lsp0
, level
);
1269 circuit
->area
->lspdb
[level
- 1]);
1270 ISIS_FLAGS_CLEAR_ALL(lsp
->SRMflags
);
1271 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1276 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1280 * Build a list from our own LSP db bounded with
1281 * start_lsp_id and stop_lsp_id
1283 struct list
*lsp_list
= list_new();
1284 lsp_build_list_nonzero_ht(start_lsp_id
, stop_lsp_id
, lsp_list
,
1285 circuit
->area
->lspdb
[level
- 1]);
1287 /* Fixme: Find a better solution */
1288 struct listnode
*node
, *nnode
;
1289 struct isis_lsp
*lsp
;
1290 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1291 entry
= entry
->next
) {
1292 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1293 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1295 list_delete_node(lsp_list
, node
);
1301 /* on remaining LSPs we set SRM (neighbor knew not of) */
1302 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
))
1303 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1305 list_delete_and_null(&lsp_list
);
1310 isis_free_tlvs(tlvs
);
1314 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1319 *size
= ISIS_LANHELLO_HDRLEN
;
1322 *size
= ISIS_P2PHELLO_HDRLEN
;
1326 *size
= ISIS_LSP_HDR_LEN
;
1328 case L1_COMPLETE_SEQ_NUM
:
1329 case L2_COMPLETE_SEQ_NUM
:
1330 *size
= ISIS_CSNP_HDRLEN
;
1332 case L1_PARTIAL_SEQ_NUM
:
1333 case L2_PARTIAL_SEQ_NUM
:
1334 *size
= ISIS_PSNP_HDRLEN
;
1339 *size
+= ISIS_FIXED_HDR_LEN
;
1347 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1349 int retval
= ISIS_OK
;
1351 /* Verify that at least the 8 bytes fixed header have been received */
1352 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1353 zlog_err("PDU is too short to be IS-IS.");
1357 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1358 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1359 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1360 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1361 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1362 & 0x1f; /* bits 6-8 are reserved */
1363 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1364 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1365 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1367 if (idrp
== ISO9542_ESIS
) {
1368 zlog_err("No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1372 if (idrp
!= ISO10589_ISIS
) {
1373 zlog_err("Not an IS-IS packet IDRP=%" PRIx8
, idrp
);
1377 if (version1
!= 1) {
1378 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1379 return ISIS_WARNING
;
1382 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1384 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1385 ", while the parameter for this IS is %u",
1386 id_len
, ISIS_SYS_ID_LEN
);
1390 uint8_t expected_length
;
1391 if (pdu_size(pdu_type
, &expected_length
)) {
1392 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1393 return ISIS_WARNING
;
1396 if (length
!= expected_length
) {
1397 zlog_err("Exepected fixed header length = %" PRIu8
1399 expected_length
, length
);
1403 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1405 "PDU is too short to contain fixed header of given PDU type.");
1409 if (version2
!= 1) {
1410 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1411 return ISIS_WARNING
;
1414 if (circuit
->is_passive
) {
1415 zlog_warn("Received ISIS PDU on passive circuit %s",
1416 circuit
->interface
->name
);
1417 return ISIS_WARNING
;
1421 if (max_area_addrs
!= 0 && max_area_addrs
!= isis
->max_area_addrs
) {
1423 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1424 " while the parameter for this IS is %u",
1425 max_area_addrs
, isis
->max_area_addrs
);
1433 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1437 retval
= process_lsp(pdu_type
, circuit
, ssnpa
);
1439 case L1_COMPLETE_SEQ_NUM
:
1440 case L2_COMPLETE_SEQ_NUM
:
1441 case L1_PARTIAL_SEQ_NUM
:
1442 case L2_PARTIAL_SEQ_NUM
:
1443 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1452 int isis_receive(struct thread
*thread
)
1454 struct isis_circuit
*circuit
;
1455 uint8_t ssnpa
[ETH_ALEN
];
1461 circuit
= THREAD_ARG(thread
);
1464 circuit
->t_read
= NULL
;
1466 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1468 retval
= circuit
->rx(circuit
, ssnpa
);
1470 #if ISIS_METHOD != ISIS_METHOD_BPF
1471 if (retval
== ISIS_OK
)
1472 retval
= isis_handle_pdu(circuit
, ssnpa
);
1473 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1476 * prepare for next packet.
1478 if (!circuit
->is_passive
)
1479 isis_circuit_prepare(circuit
);
1487 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1491 if (pdu_size(pdu_type
, &length
))
1492 assert(!"Unknown PDU Type");
1494 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1495 stream_putc(stream
, length
); /* Length of fixed header */
1496 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1497 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1498 stream_putc(stream
, pdu_type
);
1499 stream_putc(stream
, 1); /* Subversion */
1500 stream_putc(stream
, 0); /* Reserved */
1501 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1504 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1505 size_t *len_pointer
)
1509 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1510 pdu_type
= (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1512 pdu_type
= P2P_HELLO
;
1514 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1515 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1517 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1518 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1521 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1522 * circuit
->hello_interval
[level
- 1];
1524 if (holdtime
> 0xffff)
1527 stream_putw(circuit
->snd_stream
, holdtime
);
1528 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1529 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1531 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1532 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1533 ? circuit
->u
.bc
.l1_desig_is
1534 : circuit
->u
.bc
.l2_desig_is
;
1535 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1536 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1538 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1542 int send_hello(struct isis_circuit
*circuit
, int level
)
1547 if (circuit
->is_passive
)
1550 if (circuit
->interface
->mtu
== 0) {
1551 zlog_warn("circuit has zero MTU");
1552 return ISIS_WARNING
;
1555 put_hello_hdr(circuit
, level
, &len_pointer
);
1557 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1559 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1561 if (!listcount(circuit
->area
->area_addrs
)) {
1562 isis_free_tlvs(tlvs
);
1563 return ISIS_WARNING
;
1566 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1568 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1569 isis_tlvs_add_lan_neighbors(
1570 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1571 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1572 && !circuit
->disable_threeway_adj
) {
1573 uint32_t ext_circuit_id
= circuit
->idx
;
1574 if (circuit
->u
.p2p
.neighbor
) {
1575 isis_tlvs_add_threeway_adj(tlvs
,
1576 circuit
->u
.p2p
.neighbor
->threeway_state
,
1578 circuit
->u
.p2p
.neighbor
->sysid
,
1579 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1581 isis_tlvs_add_threeway_adj(tlvs
,
1588 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1593 * TLV gets included if no topology is enabled on the interface,
1594 * if one topology other than #0 is enabled, or if multiple topologies
1597 struct isis_circuit_mt_setting
**mt_settings
;
1598 unsigned int mt_count
;
1600 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1601 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1602 tlvs
->mt_router_info_empty
= true;
1603 } else if ((mt_count
== 1
1604 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1605 || (mt_count
> 1)) {
1606 for (unsigned int i
= 0; i
< mt_count
; i
++)
1607 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1611 if (circuit
->ip_router
&& circuit
->ip_addrs
)
1612 isis_tlvs_add_ipv4_addresses(tlvs
, circuit
->ip_addrs
);
1614 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1615 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1617 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1618 circuit
->pad_hellos
, false)) {
1619 isis_free_tlvs(tlvs
);
1620 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1623 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1624 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1626 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1627 circuit
->area
->area_tag
, level
,
1628 circuit
->interface
->name
,
1629 stream_get_endp(circuit
->snd_stream
));
1632 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1633 circuit
->area
->area_tag
,
1634 circuit
->interface
->name
,
1635 stream_get_endp(circuit
->snd_stream
));
1637 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1638 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1639 stream_get_endp(circuit
->snd_stream
));
1642 isis_free_tlvs(tlvs
);
1644 retval
= circuit
->tx(circuit
, level
);
1645 if (retval
!= ISIS_OK
)
1646 zlog_err("ISIS-Adj (%s): Send L%d IIH on %s failed",
1647 circuit
->area
->area_tag
, level
,
1648 circuit
->interface
->name
);
1653 int send_lan_l1_hello(struct thread
*thread
)
1655 struct isis_circuit
*circuit
;
1658 circuit
= THREAD_ARG(thread
);
1660 circuit
->u
.bc
.t_send_lan_hello
[0] = NULL
;
1662 if (!(circuit
->area
->is_type
& IS_LEVEL_1
)) {
1664 "ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
1665 circuit
->area
->area_tag
);
1669 if (circuit
->u
.bc
.run_dr_elect
[0])
1670 isis_dr_elect(circuit
, 1);
1672 retval
= send_hello(circuit
, 1);
1674 /* set next timer thread */
1675 thread_add_timer(master
, send_lan_l1_hello
, circuit
,
1676 isis_jitter(circuit
->hello_interval
[0], IIH_JITTER
),
1677 &circuit
->u
.bc
.t_send_lan_hello
[0]);
1682 int send_lan_l2_hello(struct thread
*thread
)
1684 struct isis_circuit
*circuit
;
1687 circuit
= THREAD_ARG(thread
);
1689 circuit
->u
.bc
.t_send_lan_hello
[1] = NULL
;
1691 if (!(circuit
->area
->is_type
& IS_LEVEL_2
)) {
1692 zlog_warn("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
1693 circuit
->area
->area_tag
);
1697 if (circuit
->u
.bc
.run_dr_elect
[1])
1698 isis_dr_elect(circuit
, 2);
1700 retval
= send_hello(circuit
, 2);
1702 /* set next timer thread */
1703 thread_add_timer(master
, send_lan_l2_hello
, circuit
,
1704 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1705 &circuit
->u
.bc
.t_send_lan_hello
[1]);
1710 int send_p2p_hello(struct thread
*thread
)
1712 struct isis_circuit
*circuit
;
1714 circuit
= THREAD_ARG(thread
);
1716 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1718 send_hello(circuit
, 1);
1720 /* set next timer thread */
1721 thread_add_timer(master
, send_p2p_hello
, circuit
,
1722 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1723 &circuit
->u
.p2p
.t_send_p2p_hello
);
1729 * Count the maximum number of lsps that can be accomodated by a given size.
1731 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
1732 static uint16_t get_max_lsp_count(uint16_t size
)
1736 uint16_t remaining_size
;
1738 /* First count the full size TLVs */
1739 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
1740 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
1742 /* The last TLV, if any */
1743 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
1744 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
1745 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
1750 int send_csnp(struct isis_circuit
*circuit
, int level
)
1752 if (circuit
->area
->lspdb
[level
- 1] == NULL
1753 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1756 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1757 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
1758 : L2_COMPLETE_SEQ_NUM
,
1759 circuit
->snd_stream
);
1761 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1762 stream_putw(circuit
->snd_stream
, 0);
1763 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1764 /* with zero circuit id - ref 9.10, 9.11 */
1765 stream_putc(circuit
->snd_stream
, 0);
1767 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
1768 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1769 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
1770 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1772 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1773 ? &circuit
->area
->area_passwd
1774 : &circuit
->area
->domain_passwd
;
1776 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1778 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1779 isis_tlvs_add_auth(tlvs
, passwd
);
1781 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1782 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1784 isis_free_tlvs(tlvs
);
1785 return ISIS_WARNING
;
1787 isis_free_tlvs(tlvs
);
1790 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1792 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
1793 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
1794 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
1795 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1799 tlvs
= isis_alloc_tlvs();
1800 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1801 isis_tlvs_add_auth(tlvs
, passwd
);
1803 struct isis_lsp
*last_lsp
;
1804 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
1805 circuit
->area
->lspdb
[level
- 1],
1808 * Update the stop lsp_id before encoding this CSNP.
1810 if (tlvs
->lsp_entries
.count
< num_lsps
) {
1811 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1813 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
1816 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
1817 ISIS_SYS_ID_LEN
+ 2);
1818 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
1819 ISIS_SYS_ID_LEN
+ 2);
1820 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1821 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1823 isis_free_tlvs(tlvs
);
1824 return ISIS_WARNING
;
1827 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1829 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
1830 circuit
->area
->area_tag
, level
,
1831 circuit
->interface
->name
,
1832 stream_get_endp(circuit
->snd_stream
));
1833 log_multiline(LOG_DEBUG
, " ", "%s",
1834 isis_format_tlvs(tlvs
));
1835 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1837 STREAM_DATA(circuit
->snd_stream
),
1838 stream_get_endp(circuit
->snd_stream
));
1841 int retval
= circuit
->tx(circuit
, level
);
1842 if (retval
!= ISIS_OK
) {
1843 zlog_err("ISIS-Snp (%s): Send L%d CSNP on %s failed",
1844 circuit
->area
->area_tag
, level
,
1845 circuit
->interface
->name
);
1846 isis_free_tlvs(tlvs
);
1851 * Start lsp_id of the next CSNP should be one plus the
1852 * stop lsp_id in this current CSNP.
1854 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
1856 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
1857 if (start
[i
] < (uint8_t)0xff) {
1863 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1864 isis_free_tlvs(tlvs
);
1870 int send_l1_csnp(struct thread
*thread
)
1872 struct isis_circuit
*circuit
;
1873 int retval
= ISIS_OK
;
1875 circuit
= THREAD_ARG(thread
);
1878 circuit
->t_send_csnp
[0] = NULL
;
1880 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1881 && circuit
->u
.bc
.is_dr
[0]) {
1882 send_csnp(circuit
, 1);
1884 /* set next timer thread */
1885 thread_add_timer(master
, send_l1_csnp
, circuit
,
1886 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
1887 &circuit
->t_send_csnp
[0]);
1892 int send_l2_csnp(struct thread
*thread
)
1894 struct isis_circuit
*circuit
;
1895 int retval
= ISIS_OK
;
1897 circuit
= THREAD_ARG(thread
);
1900 circuit
->t_send_csnp
[1] = NULL
;
1902 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1903 && circuit
->u
.bc
.is_dr
[1]) {
1904 send_csnp(circuit
, 2);
1906 /* set next timer thread */
1907 thread_add_timer(master
, send_l2_csnp
, circuit
,
1908 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
1909 &circuit
->t_send_csnp
[1]);
1915 * 7.3.15.4 action on expiration of partial SNP interval
1918 static int send_psnp(int level
, struct isis_circuit
*circuit
)
1920 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1921 && circuit
->u
.bc
.is_dr
[level
- 1])
1924 if (circuit
->area
->lspdb
[level
- 1] == NULL
1925 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1928 if (!circuit
->snd_stream
)
1931 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1932 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
1933 : L2_PARTIAL_SEQ_NUM
,
1934 circuit
->snd_stream
);
1936 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1937 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1938 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1939 stream_putc(circuit
->snd_stream
, circuit
->idx
);
1941 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1942 ? &circuit
->area
->area_passwd
1943 : &circuit
->area
->domain_passwd
;
1945 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1947 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1948 isis_tlvs_add_auth(tlvs
, passwd
);
1950 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1951 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1953 isis_free_tlvs(tlvs
);
1954 return ISIS_WARNING
;
1956 isis_free_tlvs(tlvs
);
1959 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1962 tlvs
= isis_alloc_tlvs();
1963 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1964 isis_tlvs_add_auth(tlvs
, passwd
);
1966 for (dnode_t
*dnode
=
1967 dict_first(circuit
->area
->lspdb
[level
- 1]);
1968 dnode
; dnode
= dict_next(circuit
->area
->lspdb
[level
- 1],
1970 struct isis_lsp
*lsp
= dnode_get(dnode
);
1972 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
1973 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
1975 if (tlvs
->lsp_entries
.count
== num_lsps
)
1979 if (!tlvs
->lsp_entries
.count
) {
1980 isis_free_tlvs(tlvs
);
1984 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1985 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1987 isis_free_tlvs(tlvs
);
1988 return ISIS_WARNING
;
1991 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1993 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
1994 circuit
->area
->area_tag
, level
,
1995 circuit
->interface
->name
,
1996 stream_get_endp(circuit
->snd_stream
));
1997 log_multiline(LOG_DEBUG
, " ", "%s",
1998 isis_format_tlvs(tlvs
));
1999 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2001 STREAM_DATA(circuit
->snd_stream
),
2002 stream_get_endp(circuit
->snd_stream
));
2005 int retval
= circuit
->tx(circuit
, level
);
2006 if (retval
!= ISIS_OK
) {
2007 zlog_err("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2008 circuit
->area
->area_tag
, level
,
2009 circuit
->interface
->name
);
2010 isis_free_tlvs(tlvs
);
2015 * sending succeeded, we can clear SSN flags of this circuit
2016 * for the LSPs in list
2018 struct isis_lsp_entry
*entry_head
;
2019 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2020 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2021 entry
= entry
->next
)
2022 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2023 isis_free_tlvs(tlvs
);
2029 int send_l1_psnp(struct thread
*thread
)
2032 struct isis_circuit
*circuit
;
2033 int retval
= ISIS_OK
;
2035 circuit
= THREAD_ARG(thread
);
2038 circuit
->t_send_psnp
[0] = NULL
;
2040 send_psnp(1, circuit
);
2041 /* set next timer thread */
2042 thread_add_timer(master
, send_l1_psnp
, circuit
,
2043 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2044 &circuit
->t_send_psnp
[0]);
2050 * 7.3.15.4 action on expiration of partial SNP interval
2053 int send_l2_psnp(struct thread
*thread
)
2055 struct isis_circuit
*circuit
;
2056 int retval
= ISIS_OK
;
2058 circuit
= THREAD_ARG(thread
);
2061 circuit
->t_send_psnp
[1] = NULL
;
2063 send_psnp(2, circuit
);
2065 /* set next timer thread */
2066 thread_add_timer(master
, send_l2_psnp
, circuit
,
2067 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2068 &circuit
->t_send_psnp
[1]);
2074 * ISO 10589 - 7.3.14.3
2076 int send_lsp(struct thread
*thread
)
2078 struct isis_circuit
*circuit
;
2079 struct isis_lsp
*lsp
;
2081 int retval
= ISIS_OK
;
2083 circuit
= THREAD_ARG(thread
);
2085 circuit
->t_send_lsp
= NULL
;
2087 lsp
= isis_circuit_lsp_queue_pop(circuit
);
2091 if (!list_isempty(circuit
->lsp_queue
)) {
2092 isis_circuit_schedule_lsp_send(circuit
);
2095 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2099 * Do not send if levels do not match
2101 if (!(lsp
->level
& circuit
->is_type
))
2105 * Do not send if we do not have adjacencies in state up on the circuit
2107 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2110 /* stream_copy will assert and stop program execution if LSP is larger
2112 * the circuit's MTU. So handle and log this case here. */
2113 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2115 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2116 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2117 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2118 circuit
->area
->area_tag
, lsp
->level
,
2119 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2120 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2121 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2122 stream_get_size(circuit
->snd_stream
));
2123 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2124 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2125 stream_get_endp(lsp
->pdu
));
2126 retval
= ISIS_ERROR
;
2130 /* copy our lsp to the send buffer */
2131 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2133 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2134 zlog_debug("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08" PRIx32
2135 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2137 circuit
->area
->area_tag
, lsp
->level
,
2138 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2139 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2140 circuit
->interface
->name
);
2141 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2142 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2143 stream_get_endp(circuit
->snd_stream
));
2147 retval
= circuit
->tx(circuit
, lsp
->level
);
2148 if (retval
!= ISIS_OK
) {
2149 zlog_err("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2150 circuit
->area
->area_tag
, lsp
->level
,
2151 circuit
->interface
->name
,
2152 (retval
== ISIS_WARNING
) ? "temporarily"
2158 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2159 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2160 /* SRM flag will trigger retransmission. We will not retransmit
2162 * encountered a fatal error.
2163 * On success, they should only be cleared if it's a broadcast
2165 * On a P2P circuit, we will wait for the ack from the neighbor
2169 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);