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
37 #include "lib_errors.h"
39 #include "isisd/dict.h"
40 #include "isisd/isis_constants.h"
41 #include "isisd/isis_common.h"
42 #include "isisd/isis_flags.h"
43 #include "isisd/isis_adjacency.h"
44 #include "isisd/isis_circuit.h"
45 #include "isisd/isis_network.h"
46 #include "isisd/isis_misc.h"
47 #include "isisd/isis_dr.h"
48 #include "isisd/isisd.h"
49 #include "isisd/isis_dynhn.h"
50 #include "isisd/isis_lsp.h"
51 #include "isisd/isis_pdu.h"
52 #include "isisd/iso_checksum.h"
53 #include "isisd/isis_csm.h"
54 #include "isisd/isis_events.h"
55 #include "isisd/isis_te.h"
56 #include "isisd/isis_mt.h"
57 #include "isisd/isis_tlvs.h"
58 #include "isisd/isis_errors.h"
60 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
67 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
69 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
71 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
73 lenp
= stream_get_endp(circuit
->snd_stream
);
74 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
75 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
76 stream_putc(circuit
->snd_stream
, circuit
->idx
);
77 stream_putc(circuit
->snd_stream
, 9); /* code */
78 stream_putc(circuit
->snd_stream
, 16); /* len */
80 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
81 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
82 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
83 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
85 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
86 /* Update PDU length */
87 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
89 retval
= circuit
->tx(circuit
, level
);
90 if (retval
!= ISIS_OK
)
91 flog_err(ISIS_ERR_PACKET
,
92 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
93 circuit
->area
->area_tag
, level
,
94 circuit
->interface
->name
);
104 struct isis_circuit
*circuit
;
109 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
116 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
121 struct isis_tlvs
*tlvs
;
124 static int process_p2p_hello(struct iih_info
*iih
)
126 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
128 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
129 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
130 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d\n",
131 iih
->circuit
->area
->area_tag
,
132 iih
->circuit
->interface
->name
,
138 if (tw_adj
->neighbor_set
139 && (memcmp(tw_adj
->neighbor_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)
140 || tw_adj
->neighbor_circuit_id
!= (uint32_t) iih
->circuit
->idx
)) {
142 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
143 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.\n",
144 iih
->circuit
->area
->area_tag
,
145 iih
->circuit
->interface
->name
);
153 * My interpertation of the ISO, if no adj exists we will create one for
156 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
157 /* If an adjacency exists, check it is with the source of the hello
160 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
162 "hello source and adjacency do not match, set adj down\n");
163 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
168 if (!adj
|| adj
->level
!= iih
->circ_type
) {
170 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
173 adj
->level
= iih
->circ_type
;
175 iih
->circuit
->u
.p2p
.neighbor
= adj
;
176 /* Build lsp with the new neighbor entry when a new
177 * adjacency is formed. Set adjacency circuit type to
178 * IIH PDU header circuit type before lsp is regenerated
179 * when an adjacency is up. This will result in the new
180 * adjacency entry getting added to the lsp tlv neighbor list.
182 adj
->circuit_t
= iih
->circ_type
;
183 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
184 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
187 if (tw_adj
&& adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
188 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
190 /* 8.2.6 Monitoring point-to-point adjacencies */
191 adj
->hold_time
= iih
->holdtime
;
192 adj
->last_upd
= time(NULL
);
195 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
196 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
199 /* Update MPLS TE Remote IP address parameter if possible */
200 if (IS_MPLS_TE(isisMplsTE
) && iih
->circuit
->mtc
201 && IS_CIRCUIT_TE(iih
->circuit
->mtc
) && adj
->ipv4_address_count
)
202 set_circuitparams_rmt_ipaddr(iih
->circuit
->mtc
,
203 adj
->ipv4_addresses
[0]);
205 /* lets take care of the expiry */
206 THREAD_TIMER_OFF(adj
->t_expire
);
207 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
210 /* 8.2.5.2 a) a match was detected */
211 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
212 iih
->circuit
->area
->area_addrs
)) {
213 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
214 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
215 switch (iih
->circ_type
) {
217 case IS_LEVEL_1_AND_2
:
218 if (adj
->adj_state
!= ISIS_ADJ_UP
219 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
220 isis_adj_process_threeway(adj
, tw_adj
,
225 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
226 /* (7) reject - wrong system type event
228 zlog_warn("wrongSystemType");
230 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
231 /* (6) down - wrong system */
232 isis_adj_state_change(adj
,
240 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
241 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
242 switch (iih
->circ_type
) {
244 if (adj
->adj_state
!= ISIS_ADJ_UP
245 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
246 isis_adj_process_threeway(adj
, tw_adj
,
248 } else if ((adj
->adj_usage
249 == ISIS_ADJ_LEVEL1AND2
)
251 == ISIS_ADJ_LEVEL2
)) {
252 /* (8) down - wrong system */
253 isis_adj_state_change(adj
,
259 if (adj
->adj_state
!= ISIS_ADJ_UP
260 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
261 isis_adj_process_threeway(adj
, tw_adj
,
263 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
265 == ISIS_ADJ_LEVEL1AND2
)) {
266 /* (8) down - wrong system */
267 isis_adj_state_change(adj
,
272 case IS_LEVEL_1_AND_2
:
273 if (adj
->adj_state
!= ISIS_ADJ_UP
274 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
275 isis_adj_process_threeway(adj
, tw_adj
,
276 ISIS_ADJ_LEVEL1AND2
);
277 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
279 == ISIS_ADJ_LEVEL2
)) {
280 /* (8) down - wrong system */
281 isis_adj_state_change(adj
,
289 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
290 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
291 switch (iih
->circ_type
) {
293 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
294 /* (5) reject - wrong system type event
296 zlog_warn("wrongSystemType");
298 } else if ((adj
->adj_usage
299 == ISIS_ADJ_LEVEL1AND2
)
301 == ISIS_ADJ_LEVEL2
)) {
302 /* (6) down - wrong system */
303 isis_adj_state_change(adj
,
308 case IS_LEVEL_1_AND_2
:
310 if (adj
->adj_state
!= ISIS_ADJ_UP
311 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
312 isis_adj_process_threeway(adj
, tw_adj
,
314 } else if (adj
->adj_usage
315 == ISIS_ADJ_LEVEL1AND2
) {
316 /* (6) down - wrong system */
317 isis_adj_state_change(adj
,
325 /* 8.2.5.2 b) if no match was detected */
326 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
327 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
328 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
329 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
330 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
332 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
334 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
335 "Down - Area Mismatch");
338 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
340 switch (iih
->circ_type
) {
342 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
343 /* (6) reject - Area Mismatch event */
344 zlog_warn("AreaMismatch");
346 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
347 /* (7) down - area mismatch */
348 isis_adj_state_change(adj
,
352 } else if ((adj
->adj_usage
353 == ISIS_ADJ_LEVEL1AND2
)
355 == ISIS_ADJ_LEVEL2
)) {
356 /* (7) down - wrong system */
357 isis_adj_state_change(adj
,
362 case IS_LEVEL_1_AND_2
:
364 if (adj
->adj_state
!= ISIS_ADJ_UP
365 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
366 isis_adj_process_threeway(adj
, tw_adj
,
368 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
369 /* (7) down - wrong system */
370 isis_adj_state_change(adj
,
373 } else if (adj
->adj_usage
374 == ISIS_ADJ_LEVEL1AND2
) {
375 if (iih
->circ_type
== IS_LEVEL_2
) {
376 /* (7) down - wrong system */
377 isis_adj_state_change(
381 /* (7) down - area mismatch */
382 isis_adj_state_change(
391 /* down - area mismatch */
392 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
395 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
396 lsp_regenerate_schedule(adj
->circuit
->area
,
397 isis_adj_usage2levels(adj
->adj_usage
),
401 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
402 /* FIXME - Missing parts */
404 /* some of my own understanding of the ISO, why the heck does
405 * it not say what should I change the system_type to...
407 switch (adj
->adj_usage
) {
408 case ISIS_ADJ_LEVEL1
:
409 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
411 case ISIS_ADJ_LEVEL2
:
412 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
414 case ISIS_ADJ_LEVEL1AND2
:
415 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
418 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
422 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
424 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
425 " cir id %hhu, length %" PRIu16
,
426 iih
->circuit
->area
->area_tag
,
427 iih
->circuit
->interface
->name
,
428 circuit_t2string(iih
->circuit
->is_type
),
429 iih
->circuit
->circuit_id
, iih
->pdu_len
);
435 static int process_lan_hello(struct iih_info
*iih
)
437 struct isis_adjacency
*adj
;
438 adj
= isis_adj_lookup(iih
->sys_id
,
439 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
440 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
441 || (adj
->level
!= iih
->level
)) {
443 /* Do as in 8.4.2.5 */
444 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
448 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
450 memset(adj
->snpa
, ' ', 6);
452 adj
->level
= iih
->level
;
454 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
456 if (iih
->level
== IS_LEVEL_1
)
457 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
459 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
460 list_delete_all_node(
461 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
462 isis_adj_build_neigh_list(
463 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
464 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
467 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
468 uint8_t *dis
= (iih
->level
== 1)
469 ? iih
->circuit
->u
.bc
.l1_desig_is
470 : iih
->circuit
->u
.bc
.l2_desig_is
;
472 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
473 thread_add_event(master
, isis_event_dis_status_change
,
474 iih
->circuit
, 0, NULL
);
475 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
479 adj
->circuit_t
= iih
->circ_type
;
480 adj
->hold_time
= iih
->holdtime
;
481 adj
->last_upd
= time(NULL
);
482 adj
->prio
[iih
->level
- 1] = iih
->priority
;
483 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
486 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
487 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
490 /* lets take care of the expiry */
491 THREAD_TIMER_OFF(adj
->t_expire
);
492 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
496 * If the snpa for this circuit is found from LAN Neighbours TLV
497 * we have two-way communication -> adjacency can be put to state "up"
499 bool own_snpa_found
=
500 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
502 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
503 if (own_snpa_found
) {
504 isis_adj_state_change(
506 "own SNPA found in LAN Neighbours TLV");
509 if (!own_snpa_found
) {
510 isis_adj_state_change(
511 adj
, ISIS_ADJ_INITIALIZING
,
512 "own SNPA not found in LAN Neighbours TLV");
516 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
517 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
519 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
521 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
522 iih
->circuit
->area
->area_tag
, iih
->level
,
523 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
524 circuit_t2string(iih
->circuit
->is_type
),
525 iih
->circuit
->circuit_id
,
526 stream_get_endp(iih
->circuit
->rcv_stream
));
531 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
533 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
534 || pdu_len
> ISO_MTU(circuit
)
535 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
538 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
539 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
543 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
546 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
547 int level
= p2p_hello
? 0
548 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
550 const char *pdu_name
=
553 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
555 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
556 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
557 circuit
->area
->area_tag
, pdu_name
,
558 circuit
->interface
->name
,
559 circuit_t2string(circuit
->is_type
),
560 circuit
->circuit_id
);
561 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
562 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
563 stream_get_endp(circuit
->rcv_stream
));
567 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
568 zlog_warn("p2p hello on non p2p circuit");
572 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
573 zlog_warn("lan hello on non broadcast circuit");
577 if (circuit
->ext_domain
) {
579 "level %d LAN Hello received over circuit with externalDomain = true",
584 if (!(circuit
->is_type
& level
)) {
585 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
587 "ISIS-Adj (%s): Interface level mismatch, %s",
588 circuit
->area
->area_tag
,
589 circuit
->interface
->name
);
595 struct iih_info iih
= {
596 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
598 /* Generic IIH Header */
599 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
600 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
601 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
602 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
605 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
607 iih
.priority
= stream_getc(circuit
->rcv_stream
);
608 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
611 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
613 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
614 circuit
->area
->area_tag
, pdu_name
,
615 circuit
->interface
->name
, iih
.pdu_len
);
619 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
620 flog_err(ISIS_ERR_PACKET
,
621 "Level %d LAN Hello with Circuit Type %d", level
,
626 const char *error_log
;
627 int retval
= ISIS_WARNING
;
629 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
630 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
631 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
635 if (!iih
.tlvs
->area_addresses
.count
) {
636 zlog_warn("No Area addresses TLV in %s", pdu_name
);
640 if (!iih
.tlvs
->protocols_supported
.count
) {
641 zlog_warn("No supported protocols TLV in %s", pdu_name
);
645 if (!isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
646 circuit
->rcv_stream
, false)) {
647 isis_event_auth_failure(circuit
->area
->area_tag
,
648 "IIH authentication failure",
653 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
655 "ISIS-Adj (%s): Received IIH with own sysid - discard",
656 circuit
->area
->area_tag
);
661 && (listcount(circuit
->area
->area_addrs
) == 0
662 || (level
== ISIS_LEVEL1
663 && !isis_tlvs_area_addresses_match(
664 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
665 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
667 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
668 circuit
->area
->area_tag
, level
,
669 circuit
->interface
->name
);
674 iih
.v4_usable
= (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
)
675 && iih
.tlvs
->ipv4_address
.count
);
677 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
678 && iih
.tlvs
->ipv6_address
.count
);
680 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
681 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
683 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
684 circuit
->area
->area_tag
);
690 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
692 isis_free_tlvs(iih
.tlvs
);
698 * Process Level 1/2 Link State
700 * Section 7.3.15.1 - Action on receipt of a link state PDU
702 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
703 const uint8_t *ssnpa
)
705 int level
= (pdu_type
== L1_LINK_STATE
) ? ISIS_LEVEL1
: ISIS_LEVEL2
;
707 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
709 "ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
710 circuit
->area
->area_tag
, level
,
711 circuit
->interface
->name
,
712 circuit_t2string(circuit
->is_type
),
713 circuit
->circuit_id
);
714 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
715 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
716 stream_get_endp(circuit
->rcv_stream
));
719 struct isis_lsp_hdr hdr
= {};
721 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
722 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
723 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
724 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
725 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
726 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
728 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
729 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
730 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
735 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
736 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
737 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
738 "s, len %" PRIu16
", on %s",
739 circuit
->area
->area_tag
, level
,
740 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
741 hdr
.rem_lifetime
, hdr
.pdu_len
,
742 circuit
->interface
->name
);
745 /* lsp is_type check */
746 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
748 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
749 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
750 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
751 /* continue as per RFC1122 Be liberal in what you accept, and
752 * conservative in what you send */
755 /* Checksum sanity check - FIXME: move to correct place */
756 /* 12 = sysid+pdu+remtime */
757 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
758 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
760 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
761 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
766 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
767 if (circuit
->ext_domain
) {
769 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
770 "externalDomain = true",
771 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
776 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
777 if (!(circuit
->is_type
& level
)) {
779 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
781 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
782 level
, circuit_t2string(circuit
->is_type
));
786 struct isis_tlvs
*tlvs
= NULL
;
787 int retval
= ISIS_WARNING
;
788 const char *error_log
;
790 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
791 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
792 zlog_warn("Something went wrong unpacking the LSP: %s",
797 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
799 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
802 /* 7.3.15.1 a) 7 - password check */
803 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
804 ? &circuit
->area
->area_passwd
805 : &circuit
->area
->domain_passwd
;
806 if (!isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
, true)) {
807 isis_event_auth_failure(circuit
->area
->area_tag
,
808 "LSP authentication failure",
813 /* Find the LSP in our database and compare it to this Link State header
815 struct isis_lsp
*lsp
=
816 lsp_search(hdr
.lsp_id
, circuit
->area
->lspdb
[level
- 1]);
819 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
820 hdr
.checksum
, hdr
.rem_lifetime
);
821 if (lsp
&& (lsp
->own_lsp
))
824 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
826 /* for broadcast circuits, snpa should be compared */
828 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
829 if (!isis_adj_lookup_snpa(ssnpa
,
830 circuit
->u
.bc
.adjdb
[level
- 1])) {
831 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
832 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
834 circuit
->area
->area_tag
,
835 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
836 hdr
.checksum
, hdr
.rem_lifetime
,
837 circuit
->interface
->name
);
838 goto out
; /* Silently discard */
841 /* for non broadcast, we just need to find same level adj */
843 /* If no adj, or no sharing of level */
844 if (!circuit
->u
.p2p
.neighbor
) {
848 if (((level
== IS_LEVEL_1
)
849 && (circuit
->u
.p2p
.neighbor
->adj_usage
851 || ((level
== IS_LEVEL_2
)
852 && (circuit
->u
.p2p
.neighbor
->adj_usage
853 == ISIS_ADJ_LEVEL1
)))
861 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
863 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
865 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
868 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
870 * wrong checksum, initiate a purge. */
871 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
872 && (lsp
->hdr
.checksum
!= hdr
.checksum
)) {
873 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
874 " with confused checksum received.",
875 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
877 hdr
.rem_lifetime
= 0;
878 lsp_confusion
= true;
880 lsp_confusion
= false;
882 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
883 if (hdr
.rem_lifetime
== 0) {
885 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
887 /* only needed on explicit update, eg - p2p */
888 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
889 ack_lsp(&hdr
, circuit
, level
);
890 goto out
; /* FIXME: do we need a purge? */
892 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
893 /* LSP by some other system -> do 7.3.16.4 b) */
895 if (comp
== LSP_NEWER
) {
896 lsp_update(lsp
, &hdr
, tlvs
,
898 circuit
->area
, level
,
902 lsp_set_all_srmflags(lsp
);
904 ISIS_FLAGS_CLEAR_ALL(
905 lsp
->SSNflags
); /* FIXME:
910 /* For the case of lsp confusion, flood
911 * the purge back to its
912 * originator so that it can react.
913 * Otherwise, don't reflood
914 * through incoming circuit as usual */
915 if (!lsp_confusion
) {
917 ISIS_CLEAR_FLAG(lsp
->SRMflags
,
920 if (circuit
->circ_type
921 != CIRCUIT_T_BROADCAST
)
926 } /* 7.3.16.4 b) 2) */
927 else if (comp
== LSP_EQUAL
) {
929 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
931 if (circuit
->circ_type
932 != CIRCUIT_T_BROADCAST
)
933 ISIS_SET_FLAG(lsp
->SSNflags
,
935 } /* 7.3.16.4 b) 3) */
937 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
938 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
940 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
941 /* our own LSP -> 7.3.16.4 c) */
942 if (comp
== LSP_NEWER
) {
943 lsp_inc_seqno(lsp
, hdr
.seqno
);
944 lsp_set_all_srmflags(lsp
);
946 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
947 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
949 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
951 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08" PRIx32
,
952 circuit
->area
->area_tag
,
953 rawlspid_print(hdr
.lsp_id
),
959 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
961 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
963 /* 7.3.16.4: initiate a purge */
964 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
968 /* 7.3.15.1 d) - If this is our own lsp and we have it */
970 /* In 7.3.16.1, If an Intermediate system R somewhere in the
972 * has information that the current sequence number for source S
974 * "greater" than that held by S, ... */
976 if (hdr
.seqno
> lsp
->hdr
.seqno
) {
978 lsp_inc_seqno(lsp
, hdr
.seqno
);
979 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
981 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
982 circuit
->area
->area_tag
,
983 rawlspid_print(hdr
.lsp_id
),
986 /* If the received LSP is older or equal,
987 * resend the LSP which will act as ACK */
988 lsp_set_all_srmflags(lsp
);
990 /* 7.3.15.1 e) - This lsp originated on another system */
992 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
994 if ((!lsp
|| comp
== LSP_NEWER
)) {
996 * If this lsp is a frag, need to see if we have zero
999 struct isis_lsp
*lsp0
= NULL
;
1000 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1001 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1002 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1003 LSP_FRAGMENT(lspid
) = 0;
1005 lspid
, circuit
->area
->lspdb
[level
- 1]);
1008 "Got lsp frag, while zero lsp not in database");
1014 lsp
= lsp_new_from_recv(
1015 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1016 circuit
->area
, level
);
1019 circuit
->area
->lspdb
[level
- 1]);
1020 } else /* exists, so we overwrite */
1022 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1023 circuit
->area
, level
, false);
1027 lsp_set_all_srmflags(lsp
);
1029 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1032 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1033 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1036 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1037 else if (comp
== LSP_EQUAL
) {
1038 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1039 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1040 circuit
->area
, level
, false);
1042 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1043 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1045 /* 7.3.15.1 e) 3) LSP older than the one in db */
1047 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1048 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1055 isis_free_tlvs(tlvs
);
1060 * Process Sequence Numbers
1062 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1065 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1066 const uint8_t *ssnpa
)
1068 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1069 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1070 char typechar
= is_csnp
? 'C' : 'P';
1071 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1072 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1076 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1077 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1078 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1079 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1081 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1082 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1085 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1086 ISIS_SYS_ID_LEN
+ 2);
1087 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1088 ISIS_SYS_ID_LEN
+ 2);
1091 if (pdu_len_validate(pdu_len
, circuit
)) {
1092 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1093 return ISIS_WARNING
;
1096 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1098 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1099 circuit
->area
->area_tag
, level
, typechar
,
1100 circuit
->interface
->name
,
1101 circuit_t2string(circuit
->is_type
),
1102 circuit
->circuit_id
);
1103 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1104 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1105 stream_get_endp(circuit
->rcv_stream
));
1108 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1109 if (circuit
->ext_domain
) {
1112 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1113 "skipping: circuit externalDomain = true",
1114 circuit
->area
->area_tag
, level
, typechar
,
1115 circuit
->interface
->name
);
1120 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1121 if (!(circuit
->is_type
& level
)) {
1123 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1124 "skipping: circuit type %s does not match level %d",
1125 circuit
->area
->area_tag
, level
, typechar
,
1126 circuit
->interface
->name
,
1127 circuit_t2string(circuit
->is_type
), level
);
1132 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1133 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1134 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1136 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1137 "skipping: we are not the DIS",
1138 circuit
->area
->area_tag
, level
, typechar
,
1139 snpa_print(ssnpa
), circuit
->interface
->name
);
1144 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1147 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1149 * - already checked */
1151 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1153 /* for broadcast circuits, snpa should be compared */
1154 /* FIXME : Do we need to check SNPA? */
1155 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1156 if (!isis_adj_lookup(rem_sys_id
,
1157 circuit
->u
.bc
.adjdb
[level
- 1]))
1158 return ISIS_OK
; /* Silently discard */
1160 if (!circuit
->u
.p2p
.neighbor
) {
1161 zlog_warn("no p2p neighbor on circuit %s",
1162 circuit
->interface
->name
);
1163 return ISIS_OK
; /* Silently discard */
1167 struct isis_tlvs
*tlvs
;
1168 int retval
= ISIS_WARNING
;
1169 const char *error_log
;
1171 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1172 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1173 zlog_warn("Something went wrong unpacking the SNP: %s",
1178 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1179 ? &circuit
->area
->area_passwd
1180 : &circuit
->area
->domain_passwd
;
1181 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)
1182 && !isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
,
1184 isis_event_auth_failure(circuit
->area
->area_tag
,
1185 "SNP authentication failure",
1190 struct isis_lsp_entry
*entry_head
=
1191 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1193 /* debug isis snp-packets */
1194 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1195 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1196 circuit
->area
->area_tag
, level
, typechar
,
1197 snpa_print(ssnpa
), circuit
->interface
->name
);
1198 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1199 entry
= entry
->next
) {
1201 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1202 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1203 circuit
->area
->area_tag
, typechar
,
1204 rawlspid_print(entry
->id
), entry
->seqno
,
1205 entry
->checksum
, entry
->rem_lifetime
);
1209 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1210 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1211 entry
= entry
->next
) {
1212 struct isis_lsp
*lsp
=
1213 lsp_search(entry
->id
, circuit
->area
->lspdb
[level
- 1]);
1214 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1216 /* 7.3.15.2 b) 1) is this LSP newer */
1217 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1218 entry
->seqno
, entry
->checksum
,
1219 entry
->rem_lifetime
);
1220 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1221 if (cmp
== LSP_EQUAL
) {
1222 /* if (circuit->circ_type !=
1223 * CIRCUIT_T_BROADCAST) */
1224 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1226 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1228 else if (cmp
== LSP_OLDER
) {
1229 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1230 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1232 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1236 lsp_inc_seqno(lsp
, entry
->seqno
);
1237 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1239 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1240 /* if (circuit->circ_type !=
1241 * CIRCUIT_T_BROADCAST) */
1242 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);
1246 /* 7.3.15.2 b) 5) if it was not found, and all of those
1248 * insert it and set SSN on it */
1249 if (entry
->rem_lifetime
&& entry
->checksum
1250 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1252 struct isis_lsp
*lsp0
= NULL
;
1254 if (LSP_FRAGMENT(entry
->id
)) {
1255 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1257 memcpy(lspid
, entry
->id
,
1258 ISIS_SYS_ID_LEN
+ 1);
1259 LSP_FRAGMENT(lspid
) = 0;
1262 circuit
->area
->lspdb
[level
- 1]);
1264 zlog_debug("Got lsp frag in snp, while zero not in database");
1268 struct isis_lsp
*lsp
=
1269 lsp_new(circuit
->area
, entry
->id
,
1270 entry
->rem_lifetime
, 0, 0,
1271 entry
->checksum
, lsp0
, level
);
1273 circuit
->area
->lspdb
[level
- 1]);
1274 ISIS_FLAGS_CLEAR_ALL(lsp
->SRMflags
);
1275 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1280 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1284 * Build a list from our own LSP db bounded with
1285 * start_lsp_id and stop_lsp_id
1287 struct list
*lsp_list
= list_new();
1288 lsp_build_list_nonzero_ht(start_lsp_id
, stop_lsp_id
, lsp_list
,
1289 circuit
->area
->lspdb
[level
- 1]);
1291 /* Fixme: Find a better solution */
1292 struct listnode
*node
, *nnode
;
1293 struct isis_lsp
*lsp
;
1294 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1295 entry
= entry
->next
) {
1296 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1297 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1299 list_delete_node(lsp_list
, node
);
1305 /* on remaining LSPs we set SRM (neighbor knew not of) */
1306 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
))
1307 ISIS_SET_FLAG(lsp
->SRMflags
, circuit
);
1309 list_delete_and_null(&lsp_list
);
1314 isis_free_tlvs(tlvs
);
1318 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1323 *size
= ISIS_LANHELLO_HDRLEN
;
1326 *size
= ISIS_P2PHELLO_HDRLEN
;
1330 *size
= ISIS_LSP_HDR_LEN
;
1332 case L1_COMPLETE_SEQ_NUM
:
1333 case L2_COMPLETE_SEQ_NUM
:
1334 *size
= ISIS_CSNP_HDRLEN
;
1336 case L1_PARTIAL_SEQ_NUM
:
1337 case L2_PARTIAL_SEQ_NUM
:
1338 *size
= ISIS_PSNP_HDRLEN
;
1343 *size
+= ISIS_FIXED_HDR_LEN
;
1351 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1353 int retval
= ISIS_OK
;
1355 /* Verify that at least the 8 bytes fixed header have been received */
1356 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1357 flog_err(ISIS_ERR_PACKET
, "PDU is too short to be IS-IS.");
1361 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1362 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1363 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1364 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1365 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1366 & 0x1f; /* bits 6-8 are reserved */
1367 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1368 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1369 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1371 if (idrp
== ISO9542_ESIS
) {
1372 flog_err(LIB_ERR_DEVELOPMENT
,
1373 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1377 if (idrp
!= ISO10589_ISIS
) {
1378 flog_err(ISIS_ERR_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1383 if (version1
!= 1) {
1384 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1385 return ISIS_WARNING
;
1388 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1391 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1392 ", while the parameter for this IS is %u",
1393 id_len
, ISIS_SYS_ID_LEN
);
1397 uint8_t expected_length
;
1398 if (pdu_size(pdu_type
, &expected_length
)) {
1399 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1400 return ISIS_WARNING
;
1403 if (length
!= expected_length
) {
1404 flog_err(ISIS_ERR_PACKET
,
1405 "Exepected fixed header length = %" PRIu8
1407 expected_length
, length
);
1411 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1414 "PDU is too short to contain fixed header of given PDU type.");
1418 if (version2
!= 1) {
1419 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1420 return ISIS_WARNING
;
1423 if (circuit
->is_passive
) {
1424 zlog_warn("Received ISIS PDU on passive circuit %s",
1425 circuit
->interface
->name
);
1426 return ISIS_WARNING
;
1430 if (max_area_addrs
!= 0 && max_area_addrs
!= isis
->max_area_addrs
) {
1433 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1434 " while the parameter for this IS is %u",
1435 max_area_addrs
, isis
->max_area_addrs
);
1443 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1447 retval
= process_lsp(pdu_type
, circuit
, ssnpa
);
1449 case L1_COMPLETE_SEQ_NUM
:
1450 case L2_COMPLETE_SEQ_NUM
:
1451 case L1_PARTIAL_SEQ_NUM
:
1452 case L2_PARTIAL_SEQ_NUM
:
1453 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1462 int isis_receive(struct thread
*thread
)
1464 struct isis_circuit
*circuit
;
1465 uint8_t ssnpa
[ETH_ALEN
];
1471 circuit
= THREAD_ARG(thread
);
1474 circuit
->t_read
= NULL
;
1476 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1478 retval
= circuit
->rx(circuit
, ssnpa
);
1480 #if ISIS_METHOD != ISIS_METHOD_BPF
1481 if (retval
== ISIS_OK
)
1482 retval
= isis_handle_pdu(circuit
, ssnpa
);
1483 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1486 * prepare for next packet.
1488 if (!circuit
->is_passive
)
1489 isis_circuit_prepare(circuit
);
1497 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1501 if (pdu_size(pdu_type
, &length
))
1502 assert(!"Unknown PDU Type");
1504 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1505 stream_putc(stream
, length
); /* Length of fixed header */
1506 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1507 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1508 stream_putc(stream
, pdu_type
);
1509 stream_putc(stream
, 1); /* Subversion */
1510 stream_putc(stream
, 0); /* Reserved */
1511 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1514 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1515 size_t *len_pointer
)
1519 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1520 pdu_type
= (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1522 pdu_type
= P2P_HELLO
;
1524 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1525 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1527 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1528 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1531 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1532 * circuit
->hello_interval
[level
- 1];
1534 if (holdtime
> 0xffff)
1537 stream_putw(circuit
->snd_stream
, holdtime
);
1538 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1539 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1541 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1542 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1543 ? circuit
->u
.bc
.l1_desig_is
1544 : circuit
->u
.bc
.l2_desig_is
;
1545 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1546 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1548 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1552 int send_hello(struct isis_circuit
*circuit
, int level
)
1557 if (circuit
->is_passive
)
1560 if (circuit
->interface
->mtu
== 0) {
1561 zlog_warn("circuit has zero MTU");
1562 return ISIS_WARNING
;
1565 put_hello_hdr(circuit
, level
, &len_pointer
);
1567 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1569 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1571 if (!listcount(circuit
->area
->area_addrs
)) {
1572 isis_free_tlvs(tlvs
);
1573 return ISIS_WARNING
;
1576 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1578 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1579 isis_tlvs_add_lan_neighbors(
1580 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1581 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1582 && !circuit
->disable_threeway_adj
) {
1583 uint32_t ext_circuit_id
= circuit
->idx
;
1584 if (circuit
->u
.p2p
.neighbor
) {
1585 isis_tlvs_add_threeway_adj(tlvs
,
1586 circuit
->u
.p2p
.neighbor
->threeway_state
,
1588 circuit
->u
.p2p
.neighbor
->sysid
,
1589 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1591 isis_tlvs_add_threeway_adj(tlvs
,
1598 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1603 * TLV gets included if no topology is enabled on the interface,
1604 * if one topology other than #0 is enabled, or if multiple topologies
1607 struct isis_circuit_mt_setting
**mt_settings
;
1608 unsigned int mt_count
;
1610 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1611 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1612 tlvs
->mt_router_info_empty
= true;
1613 } else if ((mt_count
== 1
1614 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1615 || (mt_count
> 1)) {
1616 for (unsigned int i
= 0; i
< mt_count
; i
++)
1617 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1621 if (circuit
->ip_router
&& circuit
->ip_addrs
)
1622 isis_tlvs_add_ipv4_addresses(tlvs
, circuit
->ip_addrs
);
1624 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1625 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1627 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1628 circuit
->pad_hellos
, false)) {
1629 isis_free_tlvs(tlvs
);
1630 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1633 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1634 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1636 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1637 circuit
->area
->area_tag
, level
,
1638 circuit
->interface
->name
,
1639 stream_get_endp(circuit
->snd_stream
));
1642 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1643 circuit
->area
->area_tag
,
1644 circuit
->interface
->name
,
1645 stream_get_endp(circuit
->snd_stream
));
1647 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1648 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1649 stream_get_endp(circuit
->snd_stream
));
1652 isis_free_tlvs(tlvs
);
1654 retval
= circuit
->tx(circuit
, level
);
1655 if (retval
!= ISIS_OK
)
1656 flog_err(ISIS_ERR_PACKET
,
1657 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1658 circuit
->area
->area_tag
, level
,
1659 circuit
->interface
->name
);
1664 int send_lan_l1_hello(struct thread
*thread
)
1666 struct isis_circuit
*circuit
;
1669 circuit
= THREAD_ARG(thread
);
1671 circuit
->u
.bc
.t_send_lan_hello
[0] = NULL
;
1673 if (!(circuit
->area
->is_type
& IS_LEVEL_1
)) {
1675 "ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
1676 circuit
->area
->area_tag
);
1680 if (circuit
->u
.bc
.run_dr_elect
[0])
1681 isis_dr_elect(circuit
, 1);
1683 retval
= send_hello(circuit
, 1);
1685 /* set next timer thread */
1686 thread_add_timer(master
, send_lan_l1_hello
, circuit
,
1687 isis_jitter(circuit
->hello_interval
[0], IIH_JITTER
),
1688 &circuit
->u
.bc
.t_send_lan_hello
[0]);
1693 int send_lan_l2_hello(struct thread
*thread
)
1695 struct isis_circuit
*circuit
;
1698 circuit
= THREAD_ARG(thread
);
1700 circuit
->u
.bc
.t_send_lan_hello
[1] = NULL
;
1702 if (!(circuit
->area
->is_type
& IS_LEVEL_2
)) {
1703 zlog_warn("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
1704 circuit
->area
->area_tag
);
1708 if (circuit
->u
.bc
.run_dr_elect
[1])
1709 isis_dr_elect(circuit
, 2);
1711 retval
= send_hello(circuit
, 2);
1713 /* set next timer thread */
1714 thread_add_timer(master
, send_lan_l2_hello
, circuit
,
1715 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1716 &circuit
->u
.bc
.t_send_lan_hello
[1]);
1721 int send_p2p_hello(struct thread
*thread
)
1723 struct isis_circuit
*circuit
;
1725 circuit
= THREAD_ARG(thread
);
1727 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1729 send_hello(circuit
, 1);
1731 /* set next timer thread */
1732 thread_add_timer(master
, send_p2p_hello
, circuit
,
1733 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1734 &circuit
->u
.p2p
.t_send_p2p_hello
);
1740 * Count the maximum number of lsps that can be accomodated by a given size.
1742 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
1743 static uint16_t get_max_lsp_count(uint16_t size
)
1747 uint16_t remaining_size
;
1749 /* First count the full size TLVs */
1750 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
1751 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
1753 /* The last TLV, if any */
1754 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
1755 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
1756 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
1761 int send_csnp(struct isis_circuit
*circuit
, int level
)
1763 if (circuit
->area
->lspdb
[level
- 1] == NULL
1764 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1767 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1768 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
1769 : L2_COMPLETE_SEQ_NUM
,
1770 circuit
->snd_stream
);
1772 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1773 stream_putw(circuit
->snd_stream
, 0);
1774 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1775 /* with zero circuit id - ref 9.10, 9.11 */
1776 stream_putc(circuit
->snd_stream
, 0);
1778 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
1779 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1780 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
1781 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1783 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1784 ? &circuit
->area
->area_passwd
1785 : &circuit
->area
->domain_passwd
;
1787 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1789 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1790 isis_tlvs_add_auth(tlvs
, passwd
);
1792 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1793 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1795 isis_free_tlvs(tlvs
);
1796 return ISIS_WARNING
;
1798 isis_free_tlvs(tlvs
);
1801 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1803 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
1804 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
1805 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
1806 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1810 tlvs
= isis_alloc_tlvs();
1811 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1812 isis_tlvs_add_auth(tlvs
, passwd
);
1814 struct isis_lsp
*last_lsp
;
1815 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
1816 circuit
->area
->lspdb
[level
- 1],
1819 * Update the stop lsp_id before encoding this CSNP.
1821 if (tlvs
->lsp_entries
.count
< num_lsps
) {
1822 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1824 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
1827 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
1828 ISIS_SYS_ID_LEN
+ 2);
1829 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
1830 ISIS_SYS_ID_LEN
+ 2);
1831 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1832 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1834 isis_free_tlvs(tlvs
);
1835 return ISIS_WARNING
;
1838 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1840 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
1841 circuit
->area
->area_tag
, level
,
1842 circuit
->interface
->name
,
1843 stream_get_endp(circuit
->snd_stream
));
1844 log_multiline(LOG_DEBUG
, " ", "%s",
1845 isis_format_tlvs(tlvs
));
1846 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1848 STREAM_DATA(circuit
->snd_stream
),
1849 stream_get_endp(circuit
->snd_stream
));
1852 int retval
= circuit
->tx(circuit
, level
);
1853 if (retval
!= ISIS_OK
) {
1854 flog_err(ISIS_ERR_PACKET
,
1855 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
1856 circuit
->area
->area_tag
, level
,
1857 circuit
->interface
->name
);
1858 isis_free_tlvs(tlvs
);
1863 * Start lsp_id of the next CSNP should be one plus the
1864 * stop lsp_id in this current CSNP.
1866 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
1868 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
1869 if (start
[i
] < (uint8_t)0xff) {
1875 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1876 isis_free_tlvs(tlvs
);
1882 int send_l1_csnp(struct thread
*thread
)
1884 struct isis_circuit
*circuit
;
1885 int retval
= ISIS_OK
;
1887 circuit
= THREAD_ARG(thread
);
1890 circuit
->t_send_csnp
[0] = NULL
;
1892 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1893 && circuit
->u
.bc
.is_dr
[0]) {
1894 send_csnp(circuit
, 1);
1896 /* set next timer thread */
1897 thread_add_timer(master
, send_l1_csnp
, circuit
,
1898 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
1899 &circuit
->t_send_csnp
[0]);
1904 int send_l2_csnp(struct thread
*thread
)
1906 struct isis_circuit
*circuit
;
1907 int retval
= ISIS_OK
;
1909 circuit
= THREAD_ARG(thread
);
1912 circuit
->t_send_csnp
[1] = NULL
;
1914 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1915 && circuit
->u
.bc
.is_dr
[1]) {
1916 send_csnp(circuit
, 2);
1918 /* set next timer thread */
1919 thread_add_timer(master
, send_l2_csnp
, circuit
,
1920 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
1921 &circuit
->t_send_csnp
[1]);
1927 * 7.3.15.4 action on expiration of partial SNP interval
1930 static int send_psnp(int level
, struct isis_circuit
*circuit
)
1932 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
1933 && circuit
->u
.bc
.is_dr
[level
- 1])
1936 if (circuit
->area
->lspdb
[level
- 1] == NULL
1937 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1940 if (!circuit
->snd_stream
)
1943 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1944 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
1945 : L2_PARTIAL_SEQ_NUM
,
1946 circuit
->snd_stream
);
1948 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1949 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1950 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1951 stream_putc(circuit
->snd_stream
, circuit
->idx
);
1953 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1954 ? &circuit
->area
->area_passwd
1955 : &circuit
->area
->domain_passwd
;
1957 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1959 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1960 isis_tlvs_add_auth(tlvs
, passwd
);
1962 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1963 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1965 isis_free_tlvs(tlvs
);
1966 return ISIS_WARNING
;
1968 isis_free_tlvs(tlvs
);
1971 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1974 tlvs
= isis_alloc_tlvs();
1975 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1976 isis_tlvs_add_auth(tlvs
, passwd
);
1978 for (dnode_t
*dnode
=
1979 dict_first(circuit
->area
->lspdb
[level
- 1]);
1980 dnode
; dnode
= dict_next(circuit
->area
->lspdb
[level
- 1],
1982 struct isis_lsp
*lsp
= dnode_get(dnode
);
1984 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
1985 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
1987 if (tlvs
->lsp_entries
.count
== num_lsps
)
1991 if (!tlvs
->lsp_entries
.count
) {
1992 isis_free_tlvs(tlvs
);
1996 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1997 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1999 isis_free_tlvs(tlvs
);
2000 return ISIS_WARNING
;
2003 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2005 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2006 circuit
->area
->area_tag
, level
,
2007 circuit
->interface
->name
,
2008 stream_get_endp(circuit
->snd_stream
));
2009 log_multiline(LOG_DEBUG
, " ", "%s",
2010 isis_format_tlvs(tlvs
));
2011 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2013 STREAM_DATA(circuit
->snd_stream
),
2014 stream_get_endp(circuit
->snd_stream
));
2017 int retval
= circuit
->tx(circuit
, level
);
2018 if (retval
!= ISIS_OK
) {
2019 flog_err(ISIS_ERR_PACKET
,
2020 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2021 circuit
->area
->area_tag
, level
,
2022 circuit
->interface
->name
);
2023 isis_free_tlvs(tlvs
);
2028 * sending succeeded, we can clear SSN flags of this circuit
2029 * for the LSPs in list
2031 struct isis_lsp_entry
*entry_head
;
2032 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2033 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2034 entry
= entry
->next
)
2035 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2036 isis_free_tlvs(tlvs
);
2042 int send_l1_psnp(struct thread
*thread
)
2045 struct isis_circuit
*circuit
;
2046 int retval
= ISIS_OK
;
2048 circuit
= THREAD_ARG(thread
);
2051 circuit
->t_send_psnp
[0] = NULL
;
2053 send_psnp(1, circuit
);
2054 /* set next timer thread */
2055 thread_add_timer(master
, send_l1_psnp
, circuit
,
2056 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2057 &circuit
->t_send_psnp
[0]);
2063 * 7.3.15.4 action on expiration of partial SNP interval
2066 int send_l2_psnp(struct thread
*thread
)
2068 struct isis_circuit
*circuit
;
2069 int retval
= ISIS_OK
;
2071 circuit
= THREAD_ARG(thread
);
2074 circuit
->t_send_psnp
[1] = NULL
;
2076 send_psnp(2, circuit
);
2078 /* set next timer thread */
2079 thread_add_timer(master
, send_l2_psnp
, circuit
,
2080 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2081 &circuit
->t_send_psnp
[1]);
2087 * ISO 10589 - 7.3.14.3
2089 int send_lsp(struct thread
*thread
)
2091 struct isis_circuit
*circuit
;
2092 struct isis_lsp
*lsp
;
2094 int retval
= ISIS_OK
;
2096 circuit
= THREAD_ARG(thread
);
2098 circuit
->t_send_lsp
= NULL
;
2100 lsp
= isis_circuit_lsp_queue_pop(circuit
);
2104 if (!list_isempty(circuit
->lsp_queue
)) {
2105 isis_circuit_schedule_lsp_send(circuit
);
2108 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2112 * Do not send if levels do not match
2114 if (!(lsp
->level
& circuit
->is_type
))
2118 * Do not send if we do not have adjacencies in state up on the circuit
2120 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2123 /* stream_copy will assert and stop program execution if LSP is larger
2125 * the circuit's MTU. So handle and log this case here. */
2126 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2129 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2130 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2131 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2132 circuit
->area
->area_tag
, lsp
->level
,
2133 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2134 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2135 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2136 stream_get_size(circuit
->snd_stream
));
2137 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2138 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2139 stream_get_endp(lsp
->pdu
));
2140 retval
= ISIS_ERROR
;
2144 /* copy our lsp to the send buffer */
2145 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2147 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2148 zlog_debug("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08" PRIx32
2149 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2151 circuit
->area
->area_tag
, lsp
->level
,
2152 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2153 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2154 circuit
->interface
->name
);
2155 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2156 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2157 stream_get_endp(circuit
->snd_stream
));
2161 retval
= circuit
->tx(circuit
, lsp
->level
);
2162 if (retval
!= ISIS_OK
) {
2163 flog_err(ISIS_ERR_PACKET
,
2164 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2165 circuit
->area
->area_tag
, lsp
->level
,
2166 circuit
->interface
->name
,
2167 (retval
== ISIS_WARNING
) ? "temporarily"
2173 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2174 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2175 /* SRM flag will trigger retransmission. We will not retransmit
2177 * encountered a fatal error.
2178 * On success, they should only be cleared if it's a broadcast
2180 * On a P2P circuit, we will wait for the ack from the neighbor
2184 ISIS_CLEAR_FLAG(lsp
->SRMflags
, circuit
);