]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_pdu.c
2004-09-27 Paul Jakma <paul@dishone.st>
[mirror_frr.git] / isisd / isis_pdu.c
CommitLineData
eb5d44eb 1/*
2 * IS-IS Rout(e)ing protocol - isis_pdu.c
3 * PDU processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
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)
12 * any later version.
13 *
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
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24#include <stdio.h>
25#include <string.h>
26#include <zebra.h>
eb5d44eb 27
28#include "memory.h"
29#include "thread.h"
30#include "linklist.h"
31#include "log.h"
32#include "stream.h"
33#include "vty.h"
34#include "hash.c"
35#include "prefix.h"
36#include "if.h"
37
38#include "isisd/dict.h"
39#include "isisd/include-netbsd/iso.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.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/isis_flags.h"
48#include "isisd/isis_tlv.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_lsp.h"
52#include "isisd/isis_pdu.h"
53#include "isisd/iso_checksum.h"
54#include "isisd/isis_csm.h"
55#include "isisd/isis_events.h"
56
57extern struct thread_master *master;
58extern struct isis *isis;
59
60#define ISIS_MINIMUM_FIXED_HDR_LEN 15
f390d2c7 61#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
eb5d44eb 62
63#ifndef PNBBY
64#define PNBBY 8
65#endif /* PNBBY */
66
67/* Utility mask array. */
f390d2c7 68static u_char maskbit[] = {
eb5d44eb 69 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
70};
71
72/*
73 * HELPER FUNCS
74 */
75
76/*
77 * Compares two sets of area addresses
78 */
f390d2c7 79static int
eb5d44eb 80area_match (struct list *left, struct list *right)
81{
82 struct area_addr *addr1, *addr2;
83 struct listnode *node1, *node2;
84
f390d2c7 85 LIST_LOOP (left, addr1, node1)
86 {
87 LIST_LOOP (right, addr2, node2)
88 {
89 if (addr1->addr_len == addr2->addr_len &&
90 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
91 return 1; /* match */
eb5d44eb 92 }
93 }
94
f390d2c7 95 return 0; /* mismatch */
eb5d44eb 96}
97
98/*
99 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
100 * param ip1 the IS interface ip address structure
101 * param ip2 the IIH's ip address
102 * return 0 the IIH's IP is not in the IS's subnetwork
103 * 1 the IIH's IP is in the IS's subnetwork
104 */
105int
f390d2c7 106ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
eb5d44eb 107{
108 u_char *addr1, *addr2;
53c997c9 109 int shift, offset, offsetloop;
eb5d44eb 110 int len;
f390d2c7 111
112 addr1 = (u_char *) & ip1->prefix.s_addr;
113 addr2 = (u_char *) & ip2->s_addr;
eb5d44eb 114 len = ip1->prefixlen;
115
116 shift = len % PNBBY;
53c997c9 117 offsetloop = offset = len / PNBBY;
eb5d44eb 118
53c997c9 119 while (offsetloop--)
120 if (addr1[offsetloop] != addr2[offsetloop])
121 return 0;
eb5d44eb 122
f390d2c7 123 if (shift)
53c997c9 124 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
125 return 0;
eb5d44eb 126
f390d2c7 127 return 1; /* match */
128}
eb5d44eb 129
130/*
131 * Compares two set of ip addresses
132 * param left the local interface's ip addresses
133 * param right the iih interface's ip address
134 * return 0 no match;
135 * 1 match;
136 */
f390d2c7 137static int
eb5d44eb 138ip_match (struct list *left, struct list *right)
139{
140 struct prefix_ipv4 *ip1;
141 struct in_addr *ip2;
142 struct listnode *node1, *node2;
143
f390d2c7 144 LIST_LOOP (left, ip1, node1)
145 {
146 LIST_LOOP (right, ip2, node2)
147 {
148 if (ip_same_subnet (ip1, ip2))
149 {
150 return 1; /* match */
151 }
eb5d44eb 152 }
f390d2c7 153
eb5d44eb 154 }
155 return 0;
156}
157
158/*
159 * Checks whether we should accept a PDU of given level
160 */
161static int
162accept_level (int level, int circuit_t)
163{
f390d2c7 164 int retval = ((circuit_t & level) == level); /* simple approach */
eb5d44eb 165
166 return retval;
167}
168
f390d2c7 169int
eb5d44eb 170authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
171{
f390d2c7 172 if (one->type != theother->type)
173 {
174 zlog_warn ("Unsupported authentication type %d", theother->type);
175 return 1; /* Auth fail (different authentication types) */
176 }
177 switch (one->type)
178 {
179 case ISIS_PASSWD_TYPE_CLEARTXT:
180 if (one->len != theother->len)
181 return 1; /* Auth fail () - passwd len mismatch */
182 return memcmp (one->passwd, theother->passwd, one->len);
183 break;
184 default:
185 zlog_warn ("Unsupported authentication type");
186 break;
187 }
188 return 0; /* Auth pass */
eb5d44eb 189}
190
191/*
192 * Processing helper functions
193 */
194void
f390d2c7 195tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
eb5d44eb 196{
197 int i;
198 struct nlpids *tlv_nlpids;
199
f390d2c7 200 if (tlvs->nlpids)
201 {
eb5d44eb 202
f390d2c7 203 tlv_nlpids = tlvs->nlpids;
eb5d44eb 204
f390d2c7 205 adj->nlpids.count = tlv_nlpids->count;
eb5d44eb 206
f390d2c7 207 for (i = 0; i < tlv_nlpids->count; i++)
208 {
209 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
210 }
eb5d44eb 211 }
eb5d44eb 212}
213
f390d2c7 214void
eb5d44eb 215del_ip_addr (void *val)
216{
217 XFREE (MTYPE_ISIS_TMP, val);
218}
219
220void
f390d2c7 221tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
eb5d44eb 222{
223 struct listnode *node;
224 struct in_addr *ipv4_addr, *malloced;
225
f390d2c7 226 if (adj->ipv4_addrs)
227 {
228 adj->ipv4_addrs->del = del_ip_addr;
229 list_delete (adj->ipv4_addrs);
230 }
eb5d44eb 231 adj->ipv4_addrs = list_new ();
f390d2c7 232 if (tlvs->ipv4_addrs)
233 {
234 LIST_LOOP (tlvs->ipv4_addrs, ipv4_addr, node)
235 {
236 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
237 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
238 listnode_add (adj->ipv4_addrs, malloced);
239 }
eb5d44eb 240 }
eb5d44eb 241}
242
243#ifdef HAVE_IPV6
244void
f390d2c7 245tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
eb5d44eb 246{
247 struct listnode *node;
248 struct in6_addr *ipv6_addr, *malloced;
249
f390d2c7 250 if (adj->ipv6_addrs)
251 {
252 adj->ipv6_addrs->del = del_ip_addr;
253 list_delete (adj->ipv6_addrs);
254 }
eb5d44eb 255 adj->ipv6_addrs = list_new ();
f390d2c7 256 if (tlvs->ipv6_addrs)
257 {
258 LIST_LOOP (tlvs->ipv6_addrs, ipv6_addr, node)
259 {
260 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
261 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
262 listnode_add (adj->ipv6_addrs, malloced);
263 }
eb5d44eb 264 }
eb5d44eb 265
266}
267#endif /* HAVE_IPV6 */
268
eb5d44eb 269/*
270 * RECEIVE SIDE
271 */
272
273/*
274 * Process P2P IIH
275 * ISO - 10589
276 * Section 8.2.5 - Receiving point-to-point IIH PDUs
277 *
278 */
279static int
280process_p2p_hello (struct isis_circuit *circuit)
281{
282 int retval = ISIS_OK;
283 struct isis_p2p_hello_hdr *hdr;
284 struct isis_adjacency *adj;
285 u_int32_t expected = 0, found;
286 struct tlvs tlvs;
287
f390d2c7 288 if ((stream_get_endp (circuit->rcv_stream) -
289 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
290 {
291 zlog_warn ("Packet too short");
292 return ISIS_WARNING;
293 }
eb5d44eb 294
295 /* 8.2.5.1 PDU acceptance tests */
296
297 /* 8.2.5.1 a) external domain untrue */
298 /* FIXME: not useful at all? */
299
300 /* 8.2.5.1 b) ID Length mismatch */
301 /* checked at the handle_pdu */
302
303 /* 8.2.5.2 IIH PDU Processing */
304
305 /* 8.2.5.2 a) 1) Maximum Area Addresses */
306 /* Already checked, and can also be ommited */
307
308 /*
309 * Get the header
310 */
f390d2c7 311 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
eb5d44eb 312 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
313
314 /* hdr.circuit_t = stream_getc (stream);
f390d2c7 315 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
316 hdr.hold_time = stream_getw (stream);
317 hdr.pdu_len = stream_getw (stream);
318 hdr.local_id = stream_getc (stream); */
eb5d44eb 319
320 /*
321 * My interpertation of the ISO, if no adj exists we will create one for
322 * the circuit
323 */
324
f390d2c7 325 if (isis->debugs & DEBUG_ADJ_PACKETS)
326 {
327 zlog_info ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
328 " cir id %02d, length %d",
329 circuit->area->area_tag, circuit->interface->name,
330 circuit_t2string (circuit->circuit_is_type),
331 circuit->circuit_id, ntohs (hdr->pdu_len));
332 }
eb5d44eb 333
334 adj = circuit->u.p2p.neighbor;
f390d2c7 335 if (!adj)
336 {
f7c43dcb 337 adj = isis_new_adj (hdr->source_id, (u_char *) " ", 0, circuit);
f390d2c7 338 if (adj == NULL)
339 return ISIS_ERROR;
340 circuit->u.p2p.neighbor = adj;
341 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
342 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
343 }
eb5d44eb 344
345 /* 8.2.6 Monitoring point-to-point adjacencies */
346 adj->hold_time = ntohs (hdr->hold_time);
f390d2c7 347 adj->last_upd = time (NULL);
eb5d44eb 348
349 /*
350 * Lets get the TLVS now
351 */
352 expected |= TLVFLAG_AREA_ADDRS;
353 expected |= TLVFLAG_AUTH_INFO;
354 expected |= TLVFLAG_NLPID;
355 expected |= TLVFLAG_IPV4_ADDR;
356 expected |= TLVFLAG_IPV6_ADDR;
357
358 retval = parse_tlvs (circuit->area->area_tag,
359 STREAM_PNT (circuit->rcv_stream),
f390d2c7 360 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
361 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
362
363 if (retval > ISIS_WARNING)
364 {
365 free_tlvs (&tlvs);
366 return retval;
367 };
eb5d44eb 368
369 /* 8.2.5.1 c) Authentication */
f390d2c7 370 if (circuit->passwd.type)
371 {
372 if (!(found & TLVFLAG_AUTH_INFO) ||
373 authentication_check (&circuit->passwd, &tlvs.auth_info))
374 {
375 isis_event_auth_failure (circuit->area->area_tag,
376 "P2P hello authentication failure",
377 hdr->source_id);
378 return ISIS_OK;
379 }
eb5d44eb 380 }
eb5d44eb 381
382 /* we do this now because the adj may not survive till the end... */
383
384 /* we need to copy addresses to the adj */
f390d2c7 385 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
eb5d44eb 386
387#ifdef HAVE_IPV6
f390d2c7 388 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
eb5d44eb 389#endif /* HAVE_IPV6 */
390
391 /* lets take care of the expiry */
f390d2c7 392 THREAD_TIMER_OFF (adj->t_expire);
393 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
394 (long) adj->hold_time);
eb5d44eb 395
396 /* 8.2.5.2 a) a match was detected */
f390d2c7 397 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
398 {
399 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
400 if (circuit->area->is_type == IS_LEVEL_1)
401 {
402 switch (hdr->circuit_t)
403 {
404 case IS_LEVEL_1:
405 case IS_LEVEL_1_AND_2:
406 if (adj->adj_state != ISIS_ADJ_UP)
407 {
408 /* (4) adj state up */
409 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
410 /* (5) adj usage level 1 */
411 adj->adj_usage = ISIS_ADJ_LEVEL1;
412 }
413 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
414 {
415 ; /* accept */
416 }
417 break;
418 case IS_LEVEL_2:
419 if (adj->adj_state != ISIS_ADJ_UP)
420 {
421 /* (7) reject - wrong system type event */
422 zlog_warn ("wrongSystemType");
423 return ISIS_WARNING; /* Reject */
424 }
425 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
426 {
427 /* (6) down - wrong system */
428 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
429 }
430 break;
431 }
432 }
eb5d44eb 433
f390d2c7 434 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
435 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
436 {
437 switch (hdr->circuit_t)
438 {
439 case IS_LEVEL_1:
440 if (adj->adj_state != ISIS_ADJ_UP)
441 {
442 /* (6) adj state up */
443 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
444 /* (7) adj usage level 1 */
445 adj->adj_usage = ISIS_ADJ_LEVEL1;
446 }
447 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
448 {
449 ; /* accept */
450 }
451 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
452 (adj->adj_usage == ISIS_ADJ_LEVEL2))
453 {
454 /* (8) down - wrong system */
455 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
456 }
457 break;
458 case IS_LEVEL_2:
459 if (adj->adj_state != ISIS_ADJ_UP)
460 {
461 /* (6) adj state up */
462 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
463 /* (9) adj usage level 2 */
464 adj->adj_usage = ISIS_ADJ_LEVEL2;
465 }
466 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
467 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
468 {
469 /* (8) down - wrong system */
470 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
471 }
472 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
473 {
474 ; /* Accept */
475 }
476 break;
477 case IS_LEVEL_1_AND_2:
478 if (adj->adj_state != ISIS_ADJ_UP)
479 {
480 /* (6) adj state up */
481 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
482 /* (10) adj usage level 1 */
483 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
484 }
485 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
486 (adj->adj_usage == ISIS_ADJ_LEVEL2))
487 {
488 /* (8) down - wrong system */
489 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
490 }
491 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
492 {
493 ; /* Accept */
494 }
495 break;
496 }
497 }
eb5d44eb 498
f390d2c7 499 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
500 if (circuit->area->is_type == IS_LEVEL_2)
501 {
502 switch (hdr->circuit_t)
503 {
504 case IS_LEVEL_1:
505 if (adj->adj_state != ISIS_ADJ_UP)
506 {
507 /* (5) reject - wrong system type event */
508 zlog_warn ("wrongSystemType");
509 return ISIS_WARNING; /* Reject */
510 }
511 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
512 (adj->adj_usage == ISIS_ADJ_LEVEL2))
513 {
514 /* (6) down - wrong system */
515 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
516 }
517 break;
518 case IS_LEVEL_1_AND_2:
519 case IS_LEVEL_2:
520 if (adj->adj_state != ISIS_ADJ_UP)
521 {
522 /* (7) adj state up */
523 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
524 /* (8) adj usage level 2 */
525 adj->adj_usage = ISIS_ADJ_LEVEL2;
526 }
527 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
528 {
529 /* (6) down - wrong system */
530 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
531 }
532 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
533 {
534 ; /* Accept */
535 }
536 break;
537 }
538 }
eb5d44eb 539 }
eb5d44eb 540 /* 8.2.5.2 b) if no match was detected */
541 else
eb5d44eb 542 {
f390d2c7 543 if (circuit->area->is_type == IS_LEVEL_1)
544 {
545 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
546 if (adj->adj_state != ISIS_ADJ_UP)
547 {
548 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
549 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
550 }
551 else
552 {
553 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
554 "Down - Area Mismatch");
555 }
556 }
557 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
558 else
559 {
560 switch (hdr->circuit_t)
561 {
562 case IS_LEVEL_1:
563 if (adj->adj_state != ISIS_ADJ_UP)
564 {
565 /* (6) reject - Area Mismatch event */
566 zlog_warn ("AreaMismatch");
567 return ISIS_WARNING; /* Reject */
568 }
569 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
570 {
571 /* (7) down - area mismatch */
572 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
573
574 }
575 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
576 (adj->adj_usage == ISIS_ADJ_LEVEL2))
577 {
578 /* (7) down - wrong system */
579 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
580 }
581 break;
582 case IS_LEVEL_1_AND_2:
583 case IS_LEVEL_2:
584 if (adj->adj_state != ISIS_ADJ_UP)
585 {
586 /* (8) adj state up */
587 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
588 /* (9) adj usage level 2 */
589 adj->adj_usage = ISIS_ADJ_LEVEL2;
590 }
591 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
592 {
593 /* (7) down - wrong system */
594 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
595 }
596 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
597 {
598 if (hdr->circuit_t == IS_LEVEL_2)
599 {
600 /* (7) down - wrong system */
601 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
602 "Wrong System");
603 }
604 else
605 {
606 /* (7) down - area mismatch */
607 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
608 "Area Mismatch");
609 }
610 }
611 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
612 {
613 ; /* Accept */
614 }
615 break;
616 }
617 }
eb5d44eb 618 }
eb5d44eb 619 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
620 /* FIXME - Missing parts */
621
eb5d44eb 622 /* some of my own understanding of the ISO, why the heck does
623 * it not say what should I change the system_type to...
624 */
f390d2c7 625 switch (adj->adj_usage)
626 {
eb5d44eb 627 case ISIS_ADJ_LEVEL1:
628 adj->sys_type = ISIS_SYSTYPE_L1_IS;
629 break;
630 case ISIS_ADJ_LEVEL2:
631 adj->sys_type = ISIS_SYSTYPE_L2_IS;
632 break;
633 case ISIS_ADJ_LEVEL1AND2:
634 adj->sys_type = ISIS_SYSTYPE_L2_IS;
635 break;
636 case ISIS_ADJ_NONE:
637 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
638 break;
f390d2c7 639 }
eb5d44eb 640
641 adj->circuit_t = hdr->circuit_t;
642 adj->level = hdr->circuit_t;
643
644 free_tlvs (&tlvs);
645
646 return retval;
647}
648
eb5d44eb 649/*
650 * Process IS-IS LAN Level 1/2 Hello PDU
651 */
f390d2c7 652static int
653process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
eb5d44eb 654{
655 int retval = ISIS_OK;
656 struct isis_lan_hello_hdr hdr;
657 struct isis_adjacency *adj;
658 u_int32_t expected = 0, found;
659 struct tlvs tlvs;
660 u_char *snpa;
661 struct listnode *node;
662
f390d2c7 663 if ((stream_get_endp (circuit->rcv_stream) -
664 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
665 {
666 zlog_warn ("Packet too short");
667 return ISIS_WARNING;
668 }
eb5d44eb 669
f390d2c7 670 if (circuit->ext_domain)
671 {
672 zlog_info ("level %d LAN Hello received over circuit with "
673 "externalDomain = true", level);
674 return ISIS_WARNING;
675 }
eb5d44eb 676
f390d2c7 677 if (!accept_level (level, circuit->circuit_is_type))
678 {
679 if (isis->debugs & DEBUG_ADJ_PACKETS)
680 {
681 zlog_info ("ISIS-Adj (%s): Interface level mismatch, %s",
682 circuit->area->area_tag, circuit->interface->name);
683 }
684 return ISIS_WARNING;
eb5d44eb 685 }
eb5d44eb 686
687#if 0
688 /* Cisco's debug message compatability */
f390d2c7 689 if (!accept_level (level, circuit->area->is_type))
690 {
691 if (isis->debugs & DEBUG_ADJ_PACKETS)
692 {
693 zlog_info ("ISIS-Adj (%s): is type mismatch",
694 circuit->area->area_tag);
695 }
696 return ISIS_WARNING;
eb5d44eb 697 }
eb5d44eb 698#endif
699 /*
700 * Fill the header
701 */
702 hdr.circuit_t = stream_getc (circuit->rcv_stream);
703 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
704 hdr.hold_time = stream_getw (circuit->rcv_stream);
f390d2c7 705 hdr.pdu_len = stream_getw (circuit->rcv_stream);
706 hdr.prio = stream_getc (circuit->rcv_stream);
eb5d44eb 707 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
708
709 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
f390d2c7 710 hdr.circuit_t != IS_LEVEL_1_AND_2)
711 {
712 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
713 hdr.circuit_t);
714 return ISIS_ERROR;
715 }
eb5d44eb 716 /*
717 * Then get the tlvs
718 */
719 expected |= TLVFLAG_AUTH_INFO;
720 expected |= TLVFLAG_AREA_ADDRS;
721 expected |= TLVFLAG_LAN_NEIGHS;
722 expected |= TLVFLAG_NLPID;
723 expected |= TLVFLAG_IPV4_ADDR;
724 expected |= TLVFLAG_IPV6_ADDR;
725
726 retval = parse_tlvs (circuit->area->area_tag,
f390d2c7 727 STREAM_PNT (circuit->rcv_stream),
728 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
729 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
eb5d44eb 730
f390d2c7 731 if (retval > ISIS_WARNING)
732 {
733 zlog_warn ("parse_tlvs() failed");
734 goto out;
735 }
eb5d44eb 736
f390d2c7 737 if (!(found & TLVFLAG_AREA_ADDRS))
738 {
739 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
740 level);
eb5d44eb 741 retval = ISIS_WARNING;
742 goto out;
743 }
f390d2c7 744
745 if (circuit->passwd.type)
746 {
747 if (!(found & TLVFLAG_AUTH_INFO) ||
748 authentication_check (&circuit->passwd, &tlvs.auth_info))
749 {
750 isis_event_auth_failure (circuit->area->area_tag,
751 "LAN hello authentication failure",
752 hdr.source_id);
753 retval = ISIS_WARNING;
754 goto out;
755 }
756 }
eb5d44eb 757
758 /*
759 * Accept the level 1 adjacency only if a match between local and
760 * remote area addresses is found
761 */
f390d2c7 762 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
763 {
764 if (isis->debugs & DEBUG_ADJ_PACKETS)
765 {
766 zlog_info ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
767 circuit->area->area_tag, level,
768 circuit->interface->name);
769 }
770 retval = ISIS_OK;
771 goto out;
eb5d44eb 772 }
eb5d44eb 773
774 /*
775 * it's own IIH PDU - discard silently
f390d2c7 776 */
777 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
778 {
779 zlog_info ("ISIS-Adj (%s): it's own IIH PDU - discarded",
780 circuit->area->area_tag);
eb5d44eb 781
f390d2c7 782 retval = ISIS_OK;
783 goto out;
784 }
eb5d44eb 785
786 /*
787 * check if it's own interface ip match iih ip addrs
788 */
f390d2c7 789 if (!(found & TLVFLAG_IPV4_ADDR)
790 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
791 {
792 zlog_info
793 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
794 circuit->interface->name);
795 retval = ISIS_WARNING;
796 goto out;
797 }
eb5d44eb 798
799 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
f390d2c7 800 if (!adj)
801 {
802 /*
803 * Do as in 8.4.2.5
804 */
805 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
806 if (adj == NULL)
13c48f72 807 {
808 retval = ISIS_ERROR;
809 goto out;
810 }
eb5d44eb 811
f390d2c7 812 adj->level = level;
813 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
eb5d44eb 814
f390d2c7 815 if (level == 1)
816 {
817 adj->sys_type = ISIS_SYSTYPE_L1_IS;
818 }
819 else
820 {
821 adj->sys_type = ISIS_SYSTYPE_L2_IS;
822 }
823 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
824 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
825 circuit->u.bc.lan_neighs[level - 1]);
eb5d44eb 826 }
eb5d44eb 827
a211d65d 828 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
829 switch (level)
830 {
831 case 1:
832 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
833 {
834 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
64a7afd6 835 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
836 ISIS_SYS_ID_LEN + 1);
a211d65d 837 }
838 break;
839 case 2:
840 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
841 {
842 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
64a7afd6 843 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
844 ISIS_SYS_ID_LEN + 1);
a211d65d 845 }
846 break;
847 }
eb5d44eb 848
849 adj->hold_time = hdr.hold_time;
f390d2c7 850 adj->last_upd = time (NULL);
851 adj->prio[level - 1] = hdr.prio;
eb5d44eb 852
853 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
854
855 /* which protocol are spoken ??? */
f390d2c7 856 if (found & TLVFLAG_NLPID)
eb5d44eb 857 tlvs_to_adj_nlpids (&tlvs, adj);
858
859 /* we need to copy addresses to the adj */
f390d2c7 860 if (found & TLVFLAG_IPV4_ADDR)
eb5d44eb 861 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
862
863#ifdef HAVE_IPV6
f390d2c7 864 if (found & TLVFLAG_IPV6_ADDR)
eb5d44eb 865 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
866#endif /* HAVE_IPV6 */
867
868 adj->circuit_t = hdr.circuit_t;
869
870 /* lets take care of the expiry */
f390d2c7 871 THREAD_TIMER_OFF (adj->t_expire);
872 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
873 (long) adj->hold_time);
eb5d44eb 874
875 /*
876 * If the snpa for this circuit is found from LAN Neighbours TLV
877 * we have two-way communication -> adjacency can be put to state "up"
878 */
879
f390d2c7 880 if (found & TLVFLAG_LAN_NEIGHS)
881 {
882 if (adj->adj_state != ISIS_ADJ_UP)
883 {
884 LIST_LOOP (tlvs.lan_neighs, snpa, node)
885 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
886 {
887 isis_adj_state_change (adj, ISIS_ADJ_UP,
888 "own SNPA found in LAN Neighbours TLV");
889 }
890 }
eb5d44eb 891 }
eb5d44eb 892
f390d2c7 893out:
eb5d44eb 894 /* DEBUG_ADJ_PACKETS */
f390d2c7 895 if (isis->debugs & DEBUG_ADJ_PACKETS)
896 {
897 /* FIXME: is this place right? fix missing info */
898 zlog_info ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
899 "cirID %u, length %ld",
900 circuit->area->area_tag,
901 level, snpa_print (ssnpa), circuit->interface->name,
902 circuit_t2string (circuit->circuit_is_type),
903 circuit->circuit_id, stream_get_endp (circuit->rcv_stream));
904 }
eb5d44eb 905
906 free_tlvs (&tlvs);
907
908 return retval;
909}
910
911/*
912 * Process Level 1/2 Link State
913 * ISO - 10589
914 * Section 7.3.15.1 - Action on receipt of a link state PDU
f390d2c7 915 */
916static int
917process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
eb5d44eb 918{
919 struct isis_link_state_hdr *hdr;
920 struct isis_adjacency *adj = NULL;
921 struct isis_lsp *lsp, *lsp0 = NULL;
922 int retval = ISIS_OK, comp = 0;
923 u_char lspid[ISIS_SYS_ID_LEN + 2];
924 struct isis_passwd *passwd;
925
926 /* Sanity check - FIXME: move to correct place */
f390d2c7 927 if ((stream_get_endp (circuit->rcv_stream) -
928 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
929 {
930 zlog_warn ("Packet too short");
931 return ISIS_WARNING;
932 }
eb5d44eb 933
934 /* Reference the header */
f390d2c7 935 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
936
937 if (isis->debugs & DEBUG_UPDATE_PACKETS)
938 {
939 zlog_info ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
940 "lifetime %us, len %lu, on %s",
941 circuit->area->area_tag,
942 level,
943 rawlspid_print (hdr->lsp_id),
944 ntohl (hdr->seq_num),
945 ntohs (hdr->checksum),
946 ntohs (hdr->rem_lifetime),
947 circuit->rcv_stream->endp, circuit->interface->name);
948 }
eb5d44eb 949
950 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
951
952 /* Checksum sanity check - FIXME: move to correct place */
953 /* 12 = sysid+pdu+remtime */
f390d2c7 954 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
955 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
956 {
957 zlog_info ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
958 circuit->area->area_tag,
959 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
960
961 return ISIS_WARNING;
962 }
eb5d44eb 963
964 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
f390d2c7 965 if (circuit->ext_domain)
966 {
967 zlog_info
968 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
969 "externalDomain = true", circuit->area->area_tag,
970 rawlspid_print (hdr->lsp_id), level);
971
972 return ISIS_WARNING;
973 }
eb5d44eb 974
975 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
f390d2c7 976 if (!accept_level (level, circuit->circuit_is_type))
977 {
978 zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
979 " type %s",
980 circuit->area->area_tag,
981 rawlspid_print (hdr->lsp_id),
982 level, circuit_t2string (circuit->circuit_is_type));
983
984 return ISIS_WARNING;
985 }
eb5d44eb 986
987 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
988
989 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
990
991 /* 7.3.15.1 a) 7 - password check */
992 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
993 (passwd = &circuit->area->domain_passwd);
f390d2c7 994 if (passwd->type)
995 {
996 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
997 ntohs (hdr->pdu_len), passwd))
998 {
999 isis_event_auth_failure (circuit->area->area_tag,
1000 "LSP authentication failure", hdr->lsp_id);
1001 return ISIS_WARNING;
1002 }
eb5d44eb 1003 }
eb5d44eb 1004 /* Find the LSP in our database and compare it to this Link State header */
1005 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1006 if (lsp)
f390d2c7 1007 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1008 hdr->checksum, hdr->rem_lifetime);
1009 if (lsp && (lsp->own_lsp
eb5d44eb 1010#ifdef TOPOLOGY_GENERATE
f390d2c7 1011 || lsp->from_topology
eb5d44eb 1012#endif /* TOPOLOGY_GENERATE */
f390d2c7 1013 ))
eb5d44eb 1014 goto dontcheckadj;
1015
1016 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1017 /* for broadcast circuits, snpa should be compared */
1018 /* FIXME : Point To Point */
1019
f390d2c7 1020 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1021 {
1022 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1023 if (!adj)
1024 {
1025 zlog_info ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1026 "lifetime %us on %s",
1027 circuit->area->area_tag,
1028 rawlspid_print (hdr->lsp_id),
1029 ntohl (hdr->seq_num),
1030 ntohs (hdr->checksum),
1031 ntohs (hdr->rem_lifetime), circuit->interface->name);
1032 return ISIS_WARNING; /* Silently discard */
1033 }
eb5d44eb 1034 }
eb5d44eb 1035
1036 /* for non broadcast, we just need to find same level adj */
f390d2c7 1037 else
1038 {
1039 /* If no adj, or no sharing of level */
1040 if (!circuit->u.p2p.neighbor)
1041 {
1042 return ISIS_OK; /* Silently discard */
1043 }
1044 else
1045 {
1046 if (((level == 1) &&
1047 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1048 ((level == 2) &&
1049 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1050 return ISIS_WARNING; /* Silently discard */
1051 }
eb5d44eb 1052 }
f390d2c7 1053dontcheckadj:
eb5d44eb 1054 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1055
1056 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1057
f390d2c7 1058 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
1059
1060 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1061 if (hdr->rem_lifetime == 0)
1062 {
1063 if (!lsp)
1064 {
1065 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1066 /* only needed on explicit update, eg - p2p */
1067 if (circuit->circ_type == CIRCUIT_T_P2P)
1068 ack_lsp (hdr, circuit, level);
1069 return retval; /* FIXME: do we need a purge? */
1070 }
1071 else
1072 {
1073 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1074 {
1075 /* LSP by some other system -> do 7.3.16.4 b) */
1076 /* 7.3.16.4 b) 1) */
1077 if (comp == LSP_NEWER)
1078 {
1079 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1080 /* ii */
1081 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1082 /* iii */
1083 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1084 /* v */
1085 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1086 /* iv */
1087 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1088 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1089
1090 } /* 7.3.16.4 b) 2) */
1091 else if (comp == LSP_EQUAL)
1092 {
1093 /* i */
1094 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1095 /* ii */
1096 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1097 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1098 } /* 7.3.16.4 b) 3) */
1099 else
1100 {
1101 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1102 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1103 }
1104 }
1105 else
1106 {
1107 /* our own LSP -> 7.3.16.4 c) */
1108 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1109 circuit->circuit_id
1110 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1111 circuit->circuit_id
1112 && circuit->u.bc.is_dr[level - 1] == 1))
1113 {
1114 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1115 zlog_info ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len));
1116 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1117 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1118 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1119 zlog_info
1120 ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1121 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1122 ntohl (lsp->lsp_header->seq_num));
1123 lsp->lsp_header->rem_lifetime =
1124 htons (isis_jitter
1125 (circuit->area->max_lsp_lifetime[level - 1],
1126 MAX_AGE_JITTER));
1127 }
1128 else
1129 {
1130 /* Got purge for own pseudo-lsp, and we are not DR */
1131 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1132 }
1133 }
1134 }
1135 return retval;
eb5d44eb 1136 }
eb5d44eb 1137 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1138 * purge */
f390d2c7 1139 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1140 {
1141 if (!lsp)
1142 {
1143 /* 7.3.16.4: initiate a purge */
1144 lsp_purge_non_exist (hdr, circuit->area);
1145 return ISIS_OK;
1146 }
1147 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1148
1149 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1150 * has information that the current sequence number for source S is
1151 * "greater" than that held by S, ... */
1152
1153 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1154 {
1155 /* 7.3.16.1 */
1156 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1157
1158 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1159 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1160
1161 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1162 zlog_info
1163 ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1164 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1165 ntohl (lsp->lsp_header->seq_num));
1166 lsp->lsp_header->rem_lifetime =
1167 htons (isis_jitter
1168 (circuit->area->max_lsp_lifetime[level - 1],
1169 MAX_AGE_JITTER));
1170 }
eb5d44eb 1171 }
f390d2c7 1172 else
1173 {
1174 /* 7.3.15.1 e) - This lsp originated on another system */
1175
1176 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1177 if ((!lsp || comp == LSP_NEWER))
1178 {
1179 /* i */
1180 if (lsp)
1181 {
eb5d44eb 1182#ifdef EXTREME_DEBUG
f390d2c7 1183 zlog_info ("level %d number is - %ld", level,
1184 circuit->area->lspdb[level - 1]->dict_nodecount);
eb5d44eb 1185#endif /* EXTREME DEBUG */
f390d2c7 1186 lsp_search_and_destroy (hdr->lsp_id,
1187 circuit->area->lspdb[level - 1]);
1188 /* exists, so we overwrite */
eb5d44eb 1189#ifdef EXTREME_DEBUG
f390d2c7 1190 zlog_info ("level %d number is - %ld", level,
1191 circuit->area->lspdb[level - 1]->dict_nodecount);
eb5d44eb 1192#endif /* EXTREME DEBUG */
f390d2c7 1193 }
1194 /*
1195 * If this lsp is a frag, need to see if we have zero lsp present
1196 */
1197 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1198 {
1199 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1200 LSP_FRAGMENT (lspid) = 0;
1201 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1202 if (!lsp0)
1203 {
1204 zlog_info ("Got lsp frag, while zero lsp not database");
1205 return ISIS_OK;
1206 }
1207 }
1208 lsp =
1209 lsp_new_from_stream_ptr (circuit->rcv_stream,
1210 ntohs (hdr->pdu_len), lsp0,
1211 circuit->area);
1212 lsp->level = level;
1213 lsp->adj = adj;
1214 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1215 /* ii */
1216 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1217 /* iii */
1218 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1219
1220 /* iv */
1221 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1222 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1223 /* FIXME: v) */
1224 }
1225 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1226 else if (comp == LSP_EQUAL)
1227 {
1228 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1229 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1230 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1231 {
1232 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1233 }
1234 }
1235 /* 7.3.15.1 e) 3) LSP older than the one in db */
1236 else
1237 {
1238 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1239 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1240 }
eb5d44eb 1241 }
eb5d44eb 1242 if (lsp)
1243 lsp->adj = adj;
1244 return retval;
1245}
1246
1247/*
1248 * Process Sequence Numbers
1249 * ISO - 10589
1250 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1251 */
1252
1253int
f390d2c7 1254process_snp (int snp_type, int level, struct isis_circuit *circuit,
1255 u_char * ssnpa)
eb5d44eb 1256{
1257 int retval = ISIS_OK;
1258 int cmp, own_lsp;
1259 char typechar = ' ';
1260 int len;
1261 struct isis_adjacency *adj;
1262 struct isis_complete_seqnum_hdr *chdr = NULL;
1263 struct isis_partial_seqnum_hdr *phdr = NULL;
1264 uint32_t found = 0, expected = 0;
1265 struct isis_lsp *lsp;
1266 struct lsp_entry *entry;
f390d2c7 1267 struct listnode *node, *node2;
eb5d44eb 1268 struct tlvs tlvs;
1269 struct list *lsp_list = NULL;
1270 struct isis_passwd *passwd;
1271
f390d2c7 1272 if (snp_type == ISIS_SNP_CSNP_FLAG)
1273 {
1274 /* getting the header info */
1275 typechar = 'C';
1276 chdr =
1277 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1278 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1279 len = ntohs (chdr->pdu_len);
1280 if (len < ISIS_CSNP_HDRLEN)
1281 {
1282 zlog_warn ("Received a CSNP with bogus length!");
1283 return ISIS_OK;
1284 }
eb5d44eb 1285 }
f390d2c7 1286 else
1287 {
1288 typechar = 'P';
1289 phdr =
1290 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1291 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1292 len = ntohs (phdr->pdu_len);
1293 if (len < ISIS_PSNP_HDRLEN)
1294 {
1295 zlog_warn ("Received a CSNP with bogus length!");
1296 return ISIS_OK;
1297 }
eb5d44eb 1298 }
eb5d44eb 1299
1300 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
f390d2c7 1301 if (circuit->ext_domain)
1302 {
eb5d44eb 1303
f390d2c7 1304 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1305 "skipping: circuit externalDomain = true",
1306 circuit->area->area_tag,
1307 level, typechar, circuit->interface->name);
eb5d44eb 1308
f390d2c7 1309 return ISIS_OK;
1310 }
eb5d44eb 1311
1312 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
f390d2c7 1313 if (!accept_level (level, circuit->circuit_is_type))
1314 {
eb5d44eb 1315
f390d2c7 1316 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1317 "skipping: circuit type %s does not match level %d",
eb5d44eb 1318 circuit->area->area_tag,
f390d2c7 1319 level,
eb5d44eb 1320 typechar,
f390d2c7 1321 circuit->interface->name,
1322 circuit_t2string (circuit->circuit_is_type), level);
eb5d44eb 1323
1324 return ISIS_OK;
1325 }
f390d2c7 1326
1327 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1328 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1329 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1330 {
1331 if (!circuit->u.bc.is_dr[level - 1])
1332 {
1333
1334 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1335 "skipping: we are not the DIS",
1336 circuit->area->area_tag,
1337 level,
1338 typechar, snpa_print (ssnpa), circuit->interface->name);
1339
1340 return ISIS_OK;
1341 }
1342 }
eb5d44eb 1343
1344 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1345
1346 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1347 * - already checked */
1348
1349 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1350 /* for broadcast circuits, snpa should be compared */
1351 /* FIXME : Do we need to check SNPA? */
f390d2c7 1352 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1353 {
1354 if (snp_type == ISIS_SNP_CSNP_FLAG)
1355 {
1356 adj =
1357 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1358 }
1359 else
1360 {
1361 /* a psnp on a broadcast, how lovely of Juniper :) */
1362 adj =
1363 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1364 }
1365 if (!adj)
1366 return ISIS_OK; /* Silently discard */
1367 }
1368 else
1369 {
1370 if (!circuit->u.p2p.neighbor)
1371 return ISIS_OK; /* Silently discard */
1372 }
eb5d44eb 1373
1374 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1375
1376 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1377
1378 memset (&tlvs, 0, sizeof (struct tlvs));
1379
1380 /* parse the SNP */
1381 expected |= TLVFLAG_LSP_ENTRIES;
1382 expected |= TLVFLAG_AUTH_INFO;
1383 retval = parse_tlvs (circuit->area->area_tag,
f390d2c7 1384 STREAM_PNT (circuit->rcv_stream),
eb5d44eb 1385 len - circuit->rcv_stream->getp,
f390d2c7 1386 &expected, &found, &tlvs);
eb5d44eb 1387
f390d2c7 1388 if (retval > ISIS_WARNING)
1389 {
1390 zlog_warn ("something went very wrong processing SNP");
1391 free_tlvs (&tlvs);
1392 return retval;
1393 }
eb5d44eb 1394
53c997c9 1395 /* FIXME: Authentication in LSPs does not mean authentication in SNPs...
1396 * In fact by default IOS only deals with LSPs authentication!!
1397 * To force authentication in SNPs, one must specify the 'authenticate
1398 * snp' command after 'area-password WORD' or 'domain-password WORD'.
1399 * This command is not supported for the moment.
1400 */
1401#if 0
eb5d44eb 1402 (level == 1) ? (passwd = &circuit->area->area_passwd) :
f390d2c7 1403 (passwd = &circuit->area->domain_passwd);
1404 if (passwd->type)
1405 {
1406 if (!(found & TLVFLAG_AUTH_INFO) ||
1407 authentication_check (passwd, &tlvs.auth_info))
1408 {
1409 isis_event_auth_failure (circuit->area->area_tag,
1410 "SNP authentication" " failure",
1411 phdr ? phdr->source_id : chdr->source_id);
1412 return ISIS_OK;
1413 }
1414 }
53c997c9 1415#endif /* 0 */
eb5d44eb 1416
1417 /* debug isis snp-packets */
f390d2c7 1418 if (isis->debugs & DEBUG_SNP_PACKETS)
1419 {
1420 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1421 circuit->area->area_tag,
1422 level,
1423 typechar, snpa_print (ssnpa), circuit->interface->name);
1424 if (tlvs.lsp_entries)
1425 {
1426 LIST_LOOP (tlvs.lsp_entries, entry, node)
1427 {
1428 zlog_info ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1429 " cksum 0x%04x, lifetime %us",
1430 circuit->area->area_tag,
1431 typechar,
1432 rawlspid_print (entry->lsp_id),
1433 ntohl (entry->seq_num),
1434 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
1435 }
1436 }
eb5d44eb 1437 }
eb5d44eb 1438
1439 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
f390d2c7 1440 if (tlvs.lsp_entries)
1441 {
1442 LIST_LOOP (tlvs.lsp_entries, entry, node)
1443 {
1444 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1445 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1446 if (lsp)
1447 {
1448 /* 7.3.15.2 b) 1) is this LSP newer */
1449 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1450 entry->checksum, entry->rem_lifetime);
1451 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1452 if (cmp == LSP_EQUAL)
1453 {
1454 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1455 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1456 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1457 }
1458 else if (cmp == LSP_OLDER)
1459 {
1460 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1461 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1462 }
1463 else
1464 {
1465 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1466 * on p2p */
1467 if (own_lsp)
1468 {
1469 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1470 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1471 }
1472 else
1473 {
1474 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1475 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1476 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1477 }
1478 }
1479 }
1480 else
1481 {
1482 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1483 * insert it and set SSN on it */
1484 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1485 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1486 {
1487 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1488 0, 0, entry->checksum, level);
1489 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1490 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1491 }
1492 }
eb5d44eb 1493 }
1494 }
eb5d44eb 1495
1496 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
f390d2c7 1497 if (snp_type == ISIS_SNP_CSNP_FLAG)
1498 {
1499 /*
1500 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1501 */
1502 lsp_list = list_new ();
1503 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1504 lsp_list, circuit->area->lspdb[level - 1]);
1505
1506 /* Fixme: Find a better solution */
1507 if (tlvs.lsp_entries)
1508 {
1509 LIST_LOOP (tlvs.lsp_entries, entry, node)
1510 {
1511 LIST_LOOP (lsp_list, lsp, node2)
1512 {
1513 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1514 {
1515 list_delete_node (lsp_list, node2);
1516 break;
1517 }
1518 }
1519 }
1520 }
1521 /* on remaining LSPs we set SRM (neighbor knew not of) */
1522 LIST_LOOP (lsp_list, lsp, node2)
1523 {
1524 ISIS_SET_FLAG (lsp->SRMflags, circuit);
eb5d44eb 1525 }
f390d2c7 1526 /* lets free it */
1527 list_free (lsp_list);
eb5d44eb 1528 }
eb5d44eb 1529
1530 free_tlvs (&tlvs);
1531 return retval;
1532}
1533
1534int
f390d2c7 1535process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
eb5d44eb 1536{
eb5d44eb 1537 /* Sanity check - FIXME: move to correct place */
f390d2c7 1538 if ((stream_get_endp (circuit->rcv_stream) -
1539 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1540 {
1541 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1542 return ISIS_WARNING;
1543 }
eb5d44eb 1544
1545 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1546}
1547
f390d2c7 1548int
1549process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
eb5d44eb 1550{
f390d2c7 1551 if ((stream_get_endp (circuit->rcv_stream) -
1552 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1553 {
1554 zlog_warn ("Packet too short");
1555 return ISIS_WARNING;
1556 }
eb5d44eb 1557
1558 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1559}
1560
eb5d44eb 1561/*
1562 * Process ISH
1563 * ISO - 10589
1564 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1565 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
f390d2c7 1566 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1567 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1568 * 0x03 0x00 0x81 0x01 0xcc
eb5d44eb 1569 */
1570int
1571process_is_hello (struct isis_circuit *circuit)
1572{
1573 struct isis_adjacency *adj;
1574 int retval = ISIS_OK;
1575 u_char neigh_len;
1576 u_char *sysid;
1577
1578 /* In this point in time we are not yet able to handle is_hellos
1579 * on lan - Sorry juniper...
1580 */
1581 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1582 return retval;
1583
1584 neigh_len = stream_getc (circuit->rcv_stream);
f390d2c7 1585 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
eb5d44eb 1586 adj = circuit->u.p2p.neighbor;
f390d2c7 1587 if (!adj)
1588 {
1589 /* 8.2.2 */
f7c43dcb 1590 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
f390d2c7 1591 if (adj == NULL)
1592 return ISIS_ERROR;
eb5d44eb 1593
f390d2c7 1594 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1595 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1596 circuit->u.p2p.neighbor = adj;
1597 }
1598 /* 8.2.2 a) */
1599 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1600 ISIS_SYS_ID_LEN))
1601 {
1602 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1603 /* 8.2.2 a) 2) delete the adj */
1604 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1605 /* 8.2.2 a) 3) create a new adj */
f7c43dcb 1606 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
f390d2c7 1607 if (adj == NULL)
1608 return ISIS_ERROR;
1609
1610 /* 8.2.2 a) 3) i */
1611 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1612 /* 8.2.2 a) 3) ii */
1613 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1614 /* 8.2.2 a) 4) quite meaningless */
1615 }
eb5d44eb 1616 /* 8.2.2 b) ignore on condition */
f390d2c7 1617 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1618 (adj->sys_type == ISIS_SYSTYPE_IS))
1619 {
1620 /* do nothing */
1621 }
1622 else
1623 {
1624 /* 8.2.2 c) respond with a p2p IIH */
1625 send_hello (circuit, 1);
1626 }
eb5d44eb 1627 /* 8.2.2 d) type is IS */
f390d2c7 1628 adj->sys_type = ISIS_SYSTYPE_IS;
eb5d44eb 1629 /* 8.2.2 e) FIXME: Circuit type of? */
1630
eb5d44eb 1631 return retval;
1632}
1633
eb5d44eb 1634/*
1635 * PDU Dispatcher
1636 */
1637
f390d2c7 1638int
1639isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
eb5d44eb 1640{
eb5d44eb 1641 struct isis_fixed_hdr *hdr;
1642 struct esis_fixed_hdr *esis_hdr;
1643
f390d2c7 1644 int retval = ISIS_OK;
eb5d44eb 1645
1646 /*
1647 * Let's first read data from stream to the header
1648 */
f390d2c7 1649 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
eb5d44eb 1650
f390d2c7 1651 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1652 {
1653 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1654 return ISIS_ERROR;
1655 }
eb5d44eb 1656
1657 /* now we need to know if this is an ISO 9542 packet and
1658 * take real good care of it, waaa!
1659 */
f390d2c7 1660 if (hdr->idrp == ISO9542_ESIS)
1661 {
1662 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1663 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1664 /* FIXME: Need to do some acceptence tests */
1665 /* example length... */
1666 switch (esis_hdr->pdu_type)
1667 {
1668 case ESH_PDU:
1669 /* FIXME */
1670 break;
1671 case ISH_PDU:
1672 zlog_info ("AN ISH PDU!!");
1673 retval = process_is_hello (circuit);
1674 break;
1675 default:
1676 return ISIS_ERROR;
1677 }
1678 return retval;
1679 }
1680 else
1681 {
1682 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1683 }
eb5d44eb 1684 /*
1685 * and then process it
1686 */
1687
f390d2c7 1688 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1689 {
1690 zlog_err ("Fixed header length = %d", hdr->length);
1691 return ISIS_ERROR;
1692 }
eb5d44eb 1693
f390d2c7 1694 if (hdr->version1 != 1)
1695 {
1696 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1697 return ISIS_WARNING;
1698 }
eb5d44eb 1699 /* either 6 or 0 */
f390d2c7 1700 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1701 {
1702 zlog_err
1703 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1704 "while the parameter for this IS is %u", hdr->id_len,
1705 ISIS_SYS_ID_LEN);
1706 return ISIS_ERROR;
1707 }
eb5d44eb 1708
f390d2c7 1709 if (hdr->version2 != 1)
1710 {
1711 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1712 return ISIS_WARNING;
1713 }
eb5d44eb 1714 /* either 3 or 0 */
f390d2c7 1715 if ((hdr->max_area_addrs != 0)
1716 && (hdr->max_area_addrs != isis->max_area_addrs))
1717 {
1718 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1719 "received PDU %u while the parameter for this IS is %u",
1720 hdr->max_area_addrs, isis->max_area_addrs);
1721 return ISIS_ERROR;
1722 }
eb5d44eb 1723
f390d2c7 1724 switch (hdr->pdu_type)
1725 {
1726 case L1_LAN_HELLO:
1727 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1728 break;
1729 case L2_LAN_HELLO:
1730 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1731 break;
1732 case P2P_HELLO:
1733 retval = process_p2p_hello (circuit);
1734 break;
1735 case L1_LINK_STATE:
1736 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1737 break;
1738 case L2_LINK_STATE:
1739 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1740 break;
1741 case L1_COMPLETE_SEQ_NUM:
1742 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1743 break;
1744 case L2_COMPLETE_SEQ_NUM:
1745 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1746 break;
1747 case L1_PARTIAL_SEQ_NUM:
1748 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1749 break;
1750 case L2_PARTIAL_SEQ_NUM:
1751 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1752 break;
1753 default:
1754 return ISIS_ERROR;
1755 }
eb5d44eb 1756
1757 return retval;
1758}
1759
eb5d44eb 1760#ifdef GNU_LINUX
1761int
1762isis_receive (struct thread *thread)
1763{
eb5d44eb 1764 struct isis_circuit *circuit;
1765 u_char ssnpa[ETH_ALEN];
1766 int retval;
1767
1768 /*
1769 * Get the circuit
1770 */
1771 circuit = THREAD_ARG (thread);
1772 assert (circuit);
1773
1774 if (circuit->rcv_stream == NULL)
f390d2c7 1775 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
eb5d44eb 1776 else
1777 stream_reset (circuit->rcv_stream);
1778
1779 retval = circuit->rx (circuit, ssnpa);
f390d2c7 1780 circuit->t_read = NULL;
eb5d44eb 1781
1782 if (retval == ISIS_OK)
1783 retval = isis_handle_pdu (circuit, ssnpa);
1784
1785 /*
1786 * prepare for next packet.
1787 */
f390d2c7 1788 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1789 circuit->fd);
eb5d44eb 1790
1791 return retval;
1792}
1793
1794#else
1795int
1796isis_receive (struct thread *thread)
1797{
eb5d44eb 1798 struct isis_circuit *circuit;
1799 u_char ssnpa[ETH_ALEN];
1800 int retval;
1801
1802 /*
1803 * Get the circuit
1804 */
1805 circuit = THREAD_ARG (thread);
1806 assert (circuit);
1807
f390d2c7 1808 circuit->t_read = NULL;
eb5d44eb 1809
1810 if (circuit->rcv_stream == NULL)
f390d2c7 1811 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
eb5d44eb 1812 else
1813 stream_reset (circuit->rcv_stream);
1814
1815 retval = circuit->rx (circuit, ssnpa);
1816
1817 if (retval == ISIS_OK)
1818 retval = isis_handle_pdu (circuit, ssnpa);
1819
1820 /*
1821 * prepare for next packet.
1822 */
f390d2c7 1823 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1824 listcount
1825 (circuit->area->circuit_list) *
1826 100);
eb5d44eb 1827
1828 return retval;
1829}
1830
1831#endif
1832
1833 /* filling of the fixed isis header */
1834void
1835fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1836{
1837 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1838
1839 hdr->idrp = ISO10589_ISIS;
1840
f390d2c7 1841 switch (pdu_type)
1842 {
1843 case L1_LAN_HELLO:
1844 case L2_LAN_HELLO:
1845 hdr->length = ISIS_LANHELLO_HDRLEN;
1846 break;
1847 case P2P_HELLO:
1848 hdr->length = ISIS_P2PHELLO_HDRLEN;
1849 break;
1850 case L1_LINK_STATE:
1851 case L2_LINK_STATE:
1852 hdr->length = ISIS_LSP_HDR_LEN;
1853 break;
1854 case L1_COMPLETE_SEQ_NUM:
1855 case L2_COMPLETE_SEQ_NUM:
1856 hdr->length = ISIS_CSNP_HDRLEN;
1857 break;
1858 case L1_PARTIAL_SEQ_NUM:
1859 case L2_PARTIAL_SEQ_NUM:
1860 hdr->length = ISIS_PSNP_HDRLEN;
1861 break;
1862 default:
1863 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1864 return;
1865 }
eb5d44eb 1866 hdr->length += ISIS_FIXED_HDR_LEN;
1867 hdr->pdu_type = pdu_type;
1868 hdr->version1 = 1;
f390d2c7 1869 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
eb5d44eb 1870 hdr->version2 = 1;
f390d2c7 1871 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
eb5d44eb 1872}
1873
eb5d44eb 1874/*
1875 * SEND SIDE
1876 */
1877void
1878fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
f390d2c7 1879 struct stream *stream)
eb5d44eb 1880{
f390d2c7 1881 fill_fixed_hdr (hdr, pdu_type);
eb5d44eb 1882
1883 stream_putc (stream, hdr->idrp);
1884 stream_putc (stream, hdr->length);
1885 stream_putc (stream, hdr->version1);
1886 stream_putc (stream, hdr->id_len);
1887 stream_putc (stream, hdr->pdu_type);
1888 stream_putc (stream, hdr->version2);
1889 stream_putc (stream, hdr->reserved);
1890 stream_putc (stream, hdr->max_area_addrs);
1891
1892 return;
1893}
1894
eb5d44eb 1895int
1896send_hello (struct isis_circuit *circuit, int level)
1897{
1898 struct isis_fixed_hdr fixed_hdr;
1899 struct isis_lan_hello_hdr hello_hdr;
1900 struct isis_p2p_hello_hdr p2p_hello_hdr;
1901
1902 u_int32_t interval;
1903 unsigned long len_pointer, length;
1904 int retval;
1905
f390d2c7 1906 if (circuit->interface->mtu == 0)
1907 {
1908 zlog_warn ("circuit has zero MTU");
1909 return ISIS_WARNING;
1910 }
eb5d44eb 1911
1912 if (!circuit->snd_stream)
f390d2c7 1913 circuit->snd_stream = stream_new (ISO_MTU (circuit));
eb5d44eb 1914 else
1915 stream_reset (circuit->snd_stream);
1916
1917 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1918 if (level == 1)
f390d2c7 1919 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1920 circuit->snd_stream);
eb5d44eb 1921 else
f390d2c7 1922 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1923 circuit->snd_stream);
eb5d44eb 1924 else
f390d2c7 1925 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
eb5d44eb 1926
1927 /*
1928 * Fill LAN Level 1 or 2 Hello PDU header
1929 */
1930 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
f390d2c7 1931 interval = circuit->hello_multiplier[level - 1] *
eb5d44eb 1932 circuit->hello_interval[level - 1];
1933 if (interval > USHRT_MAX)
1934 interval = USHRT_MAX;
1935 hello_hdr.circuit_t = circuit->circuit_is_type;
1936 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
f390d2c7 1937 hello_hdr.hold_time = htons ((u_int16_t) interval);
eb5d44eb 1938
f390d2c7 1939 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
1940 len_pointer = stream_get_putp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
eb5d44eb 1941
1942 /* copy the shared part of the hello to the p2p hello if needed */
f390d2c7 1943 if (circuit->circ_type == CIRCUIT_T_P2P)
1944 {
1945 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1946 p2p_hello_hdr.local_id = circuit->circuit_id;
1947 /* FIXME: need better understanding */
1948 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
1949 }
1950 else
1951 {
1952 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1953 if (level == 1 && circuit->u.bc.l1_desig_is)
1954 {
1955 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1956 ISIS_SYS_ID_LEN + 1);
1957 }
1958 else if (level == 2 && circuit->u.bc.l2_desig_is)
1959 {
1960 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1961 ISIS_SYS_ID_LEN + 1);
1962 }
1963 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1964 }
eb5d44eb 1965
1966 /*
1967 * Then the variable length part
1968 */
1969 /* add circuit password */
1970 if (circuit->passwd.type)
1971 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1972 circuit->passwd.passwd, circuit->snd_stream))
1973 return ISIS_WARNING;
1974 /* Area Addresses TLV */
1975 assert (circuit->area);
1976 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1977 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1978 return ISIS_WARNING;
1979
1980 /* LAN Neighbors TLV */
f390d2c7 1981 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1982 {
1983 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1984 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1985 circuit->snd_stream))
1986 return ISIS_WARNING;
1987 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
1988 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
1989 circuit->snd_stream))
1990 return ISIS_WARNING;
1991 }
eb5d44eb 1992
1993 /* Protocols Supported TLV */
f390d2c7 1994 if (circuit->nlpids.count > 0)
eb5d44eb 1995 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
1996 return ISIS_WARNING;
1997 /* IP interface Address TLV */
1998 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
1999 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2000 return ISIS_WARNING;
2001
f390d2c7 2002#ifdef HAVE_IPV6
eb5d44eb 2003 /* IPv6 Interface Address TLV */
f390d2c7 2004 if (circuit->ipv6_router && circuit->ipv6_link &&
eb5d44eb 2005 circuit->ipv6_link->count > 0)
2006 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2007 return ISIS_WARNING;
2008#endif /* HAVE_IPV6 */
2009
2010 if (circuit->u.bc.pad_hellos)
2011 if (tlv_add_padding (circuit->snd_stream))
2012 return ISIS_WARNING;
2013
2014 length = stream_get_putp (circuit->snd_stream);
2015 /* Update PDU length */
f390d2c7 2016 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
eb5d44eb 2017
2018 retval = circuit->tx (circuit, level);
2019 if (retval)
2020 zlog_warn ("sending of LAN Level %d Hello failed", level);
2021
2022 /* DEBUG_ADJ_PACKETS */
f390d2c7 2023 if (isis->debugs & DEBUG_ADJ_PACKETS)
2024 {
2025 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2026 {
2027 zlog_info ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2028 circuit->area->area_tag, level, circuit->interface->name,
2029 STREAM_SIZE (circuit->snd_stream));
2030 }
2031 else
2032 {
2033 zlog_info ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2034 circuit->area->area_tag, circuit->interface->name,
2035 STREAM_SIZE (circuit->snd_stream));
2036 }
eb5d44eb 2037 }
eb5d44eb 2038
2039 return retval;
2040}
2041
2042int
2043send_lan_hello (struct isis_circuit *circuit, int level)
2044{
f390d2c7 2045 return send_hello (circuit, level);
eb5d44eb 2046}
2047
2048int
2049send_lan_l1_hello (struct thread *thread)
2050{
eb5d44eb 2051 struct isis_circuit *circuit;
2052 int retval;
2053
2054 circuit = THREAD_ARG (thread);
2055 assert (circuit);
2056 circuit->u.bc.t_send_lan_hello[0] = NULL;
2057
2058 if (circuit->u.bc.run_dr_elect[0])
f390d2c7 2059 retval = isis_dr_elect (circuit, 1);
eb5d44eb 2060
2061 retval = send_lan_hello (circuit, 1);
2062
2063 /* set next timer thread */
f390d2c7 2064 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2065 send_lan_l1_hello, circuit,
2066 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
eb5d44eb 2067
2068 return retval;
2069}
2070
2071int
2072send_lan_l2_hello (struct thread *thread)
2073{
2074 struct isis_circuit *circuit;
2075 int retval;
2076
2077 circuit = THREAD_ARG (thread);
2078 assert (circuit);
2079 circuit->u.bc.t_send_lan_hello[1] = NULL;
2080
2081 if (circuit->u.bc.run_dr_elect[1])
2082 retval = isis_dr_elect (circuit, 2);
2083
2084 retval = send_lan_hello (circuit, 2);
2085
f390d2c7 2086 /* set next timer thread */
2087 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2088 send_lan_l2_hello, circuit,
2089 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
eb5d44eb 2090
2091 return retval;
2092}
2093
2094int
2095send_p2p_hello (struct thread *thread)
2096{
2097 struct isis_circuit *circuit;
2098
2099 circuit = THREAD_ARG (thread);
2100 assert (circuit);
2101 circuit->u.p2p.t_send_p2p_hello = NULL;
2102
f390d2c7 2103 send_hello (circuit, 1);
eb5d44eb 2104
f390d2c7 2105 /* set next timer thread */
2106 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2107 circuit, isis_jitter (circuit->hello_interval[1],
2108 IIH_JITTER));
eb5d44eb 2109
2110 return ISIS_OK;
2111}
2112
2113int
f390d2c7 2114build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2115 struct isis_circuit *circuit)
eb5d44eb 2116{
2117 struct isis_fixed_hdr fixed_hdr;
2118 struct isis_passwd *passwd;
2119 int retval = ISIS_OK;
2120 unsigned long lenp;
2121 u_int16_t length;
2122
f390d2c7 2123 if (level == 1)
2124 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2125 circuit->snd_stream);
eb5d44eb 2126 else
f390d2c7 2127 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2128 circuit->snd_stream);
eb5d44eb 2129
2130 /*
2131 * Fill Level 1 or 2 Complete Sequence Numbers header
2132 */
2133
2134 lenp = stream_get_putp (circuit->snd_stream);
f390d2c7 2135 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
eb5d44eb 2136 /* no need to send the source here, it is always us if we csnp */
2137 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2138 /* with zero circuit id - ref 9.10, 9.11 */
2139 stream_putc (circuit->snd_stream, 0x00);
2140
2141 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2142 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2143
2144 /*
2145 * And TLVs
2146 */
2147 if (level == 1)
2148 passwd = &circuit->area->area_passwd;
2149 else
2150 passwd = &circuit->area->domain_passwd;
2151
2152 if (passwd->type)
2153 retval = tlv_add_authinfo (passwd->type, passwd->len,
2154 passwd->passwd, circuit->snd_stream);
2155
f390d2c7 2156 if (!retval && lsps)
2157 {
2158 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2159 }
2160 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
eb5d44eb 2161 assert (length >= ISIS_CSNP_HDRLEN);
2162 /* Update PU length */
2163 stream_putw_at (circuit->snd_stream, lenp, length);
2164
2165 return retval;
2166}
2167
2168/*
2169 * FIXME: support multiple CSNPs
2170 */
2171
2172int
2173send_csnp (struct isis_circuit *circuit, int level)
2174{
2175 int retval = ISIS_OK;
2176 u_char start[ISIS_SYS_ID_LEN + 2];
2177 u_char stop[ISIS_SYS_ID_LEN + 2];
2178 struct list *list = NULL;
2179 struct listnode *node;
2180 struct isis_lsp *lsp;
2181
f390d2c7 2182 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
eb5d44eb 2183 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2184
f390d2c7 2185 if (circuit->area->lspdb[level - 1] &&
2186 dict_count (circuit->area->lspdb[level - 1]) > 0)
2187 {
2188 list = list_new ();
2189 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
2190
2191 if (circuit->snd_stream == NULL)
2192 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2193 else
2194 stream_reset (circuit->snd_stream);
2195
2196 retval = build_csnp (level, start, stop, list, circuit);
2197
2198 if (isis->debugs & DEBUG_SNP_PACKETS)
2199 {
2200 zlog_info ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2201 circuit->area->area_tag, level, circuit->interface->name,
2202 STREAM_SIZE (circuit->snd_stream));
2203 LIST_LOOP (list, lsp, node)
2204 {
2205 zlog_info ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2206 " cksum 0x%04x, lifetime %us",
2207 circuit->area->area_tag,
2208 rawlspid_print (lsp->lsp_header->lsp_id),
2209 ntohl (lsp->lsp_header->seq_num),
2210 ntohs (lsp->lsp_header->checksum),
2211 ntohs (lsp->lsp_header->rem_lifetime));
2212 }
2213 }
eb5d44eb 2214
f390d2c7 2215 list_delete (list);
eb5d44eb 2216
f390d2c7 2217 if (retval == ISIS_OK)
2218 retval = circuit->tx (circuit, level);
2219 }
eb5d44eb 2220 return retval;
2221}
2222
2223int
2224send_l1_csnp (struct thread *thread)
2225{
2226 struct isis_circuit *circuit;
2227 int retval = ISIS_OK;
2228
2229 circuit = THREAD_ARG (thread);
2230 assert (circuit);
2231
2232 circuit->t_send_csnp[0] = NULL;
2233
f390d2c7 2234 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2235 {
2236 send_csnp (circuit, 1);
2237 }
eb5d44eb 2238 /* set next timer thread */
f390d2c7 2239 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2240 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
eb5d44eb 2241
2242 return retval;
2243}
2244
2245int
2246send_l2_csnp (struct thread *thread)
2247{
2248 struct isis_circuit *circuit;
2249 int retval = ISIS_OK;
2250
2251 circuit = THREAD_ARG (thread);
2252 assert (circuit);
2253
2254 circuit->t_send_csnp[1] = NULL;
2255
f390d2c7 2256 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2257 {
2258 send_csnp (circuit, 2);
2259 }
eb5d44eb 2260 /* set next timer thread */
f390d2c7 2261 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2262 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
d70f99e1 2263
eb5d44eb 2264 return retval;
2265}
2266
2267int
2268build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2269{
2270 struct isis_fixed_hdr fixed_hdr;
2271 unsigned long lenp;
2272 u_int16_t length;
2273 int retval = 0;
2274 struct isis_lsp *lsp;
2275 struct isis_passwd *passwd;
2276 struct listnode *node;
2277
2278 if (level == 1)
f390d2c7 2279 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2280 circuit->snd_stream);
eb5d44eb 2281 else
2282 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
f390d2c7 2283 circuit->snd_stream);
eb5d44eb 2284
2285 /*
2286 * Fill Level 1 or 2 Partial Sequence Numbers header
2287 */
2288 lenp = stream_get_putp (circuit->snd_stream);
f390d2c7 2289 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
eb5d44eb 2290 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2291 stream_putc (circuit->snd_stream, circuit->idx);
2292
2293 /*
2294 * And TLVs
2295 */
2296
2297 if (level == 1)
2298 passwd = &circuit->area->area_passwd;
2299 else
2300 passwd = &circuit->area->domain_passwd;
2301
2302 if (passwd->type)
2303 retval = tlv_add_authinfo (passwd->type, passwd->len,
2304 passwd->passwd, circuit->snd_stream);
2305
f390d2c7 2306 if (!retval && lsps)
2307 {
2308 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2309 }
eb5d44eb 2310
f390d2c7 2311 if (isis->debugs & DEBUG_SNP_PACKETS)
2312 {
2313 LIST_LOOP (lsps, lsp, node)
2314 {
2315 zlog_info ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2316 " cksum 0x%04x, lifetime %us",
2317 circuit->area->area_tag,
2318 rawlspid_print (lsp->lsp_header->lsp_id),
2319 ntohl (lsp->lsp_header->seq_num),
2320 ntohs (lsp->lsp_header->checksum),
2321 ntohs (lsp->lsp_header->rem_lifetime));
2322 }
eb5d44eb 2323 }
eb5d44eb 2324
f390d2c7 2325 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
eb5d44eb 2326 assert (length >= ISIS_PSNP_HDRLEN);
2327 /* Update PDU length */
2328 stream_putw_at (circuit->snd_stream, lenp, length);
2329
2330 return ISIS_OK;
2331}
2332
2333/*
2334 * 7.3.15.4 action on expiration of partial SNP interval
2335 * level 1
2336 */
2337int
2338send_psnp (int level, struct isis_circuit *circuit)
2339{
2340 int retval = ISIS_OK;
2341 struct isis_lsp *lsp;
2342 struct list *list = NULL;
2343 struct listnode *node;
2344
f390d2c7 2345 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
eb5d44eb 2346 !circuit->u.bc.is_dr[level - 1]) ||
f390d2c7 2347 circuit->circ_type != CIRCUIT_T_BROADCAST)
2348 {
eb5d44eb 2349
f390d2c7 2350 if (circuit->area->lspdb[level - 1] &&
2351 dict_count (circuit->area->lspdb[level - 1]) > 0)
2352 {
2353 list = list_new ();
2354 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
2355
2356 if (listcount (list) > 0)
2357 {
2358 if (circuit->snd_stream == NULL)
2359 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2360 else
2361 stream_reset (circuit->snd_stream);
2362
2363
2364 if (isis->debugs & DEBUG_SNP_PACKETS)
2365 zlog_info ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2366 circuit->area->area_tag, level,
2367 circuit->interface->name,
2368 STREAM_SIZE (circuit->snd_stream));
2369
2370 retval = build_psnp (level, circuit, list);
2371 if (retval == ISIS_OK)
2372 retval = circuit->tx (circuit, level);
2373
2374 if (retval == ISIS_OK)
2375 {
2376 /*
2377 * sending succeeded, we can clear SSN flags of this circuit
2378 * for the LSPs in list
2379 */
2380 for (node = listhead (list); node; nextnode (node))
2381 {
2382 lsp = getdata (node);
2383 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2384 }
2385 }
2386 }
2387 list_delete (list);
2388 }
eb5d44eb 2389 }
eb5d44eb 2390
2391 return retval;
2392}
2393
2394int
2395send_l1_psnp (struct thread *thread)
2396{
2397
2398 struct isis_circuit *circuit;
2399 int retval = ISIS_OK;
2400
2401 circuit = THREAD_ARG (thread);
2402 assert (circuit);
2403
2404 circuit->t_send_psnp[0] = NULL;
2405
2406 send_psnp (1, circuit);
2407 /* set next timer thread */
f390d2c7 2408 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2409 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
eb5d44eb 2410
2411 return retval;
2412}
2413
2414/*
2415 * 7.3.15.4 action on expiration of partial SNP interval
2416 * level 2
2417 */
2418int
2419send_l2_psnp (struct thread *thread)
2420{
eb5d44eb 2421 struct isis_circuit *circuit;
2422 int retval = ISIS_OK;
2423
2424 circuit = THREAD_ARG (thread);
2425 assert (circuit);
2426
2427 circuit->t_send_psnp[1] = NULL;
2428
2429 send_psnp (2, circuit);
2430
2431 /* set next timer thread */
f390d2c7 2432 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2433 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
eb5d44eb 2434
2435 return retval;
2436}
2437
eb5d44eb 2438void
2439build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit,
f390d2c7 2440 struct stream *stream)
eb5d44eb 2441{
2442 unsigned long length;
2443
f390d2c7 2444 stream_put (stream, lsp->pdu, ntohs (lsp->lsp_header->pdu_len));
2445 length = stream_get_putp (stream);
eb5d44eb 2446
2447 return;
2448}
2449
eb5d44eb 2450/*
2451 * ISO 10589 - 7.3.14.3
2452 */
2453int
2454send_lsp (struct thread *thread)
2455{
2456 struct isis_circuit *circuit;
2457 struct isis_lsp *lsp;
2458 struct listnode *node;
2459 int retval = 0;
2460
2461 circuit = THREAD_ARG (thread);
2462 assert (circuit);
2463
f390d2c7 2464 if (circuit->state == C_STATE_UP)
2465 {
2466 node = listhead (circuit->lsp_queue);
2467 assert (node);
eb5d44eb 2468
f390d2c7 2469 lsp = getdata (node);
eb5d44eb 2470
2471 /*
f390d2c7 2472 * Do not send if levels do not match
eb5d44eb 2473 */
f390d2c7 2474 if (!(lsp->level & circuit->circuit_is_type))
2475 goto dontsend;
eb5d44eb 2476
f390d2c7 2477 /*
2478 * Do not send if we do not have adjacencies in state up on the circuit
2479 */
2480 if (circuit->upadjcount[lsp->level - 1] == 0)
2481 goto dontsend;
2482 /* only send if it needs sending */
2483 if ((time (NULL) - lsp->last_sent) >=
2484 circuit->area->lsp_gen_interval[lsp->level - 1])
2485 {
2486
2487 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2488 {
2489 zlog_info
2490 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2491 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2492 rawlspid_print (lsp->lsp_header->lsp_id),
2493 ntohl (lsp->lsp_header->seq_num),
2494 ntohs (lsp->lsp_header->checksum),
2495 ntohs (lsp->lsp_header->rem_lifetime),
2496 circuit->interface->name);
2497 }
2498 /* copy our lsp to the send buffer */
2499 circuit->snd_stream->getp = lsp->pdu->getp;
2500 circuit->snd_stream->putp = lsp->pdu->putp;
2501 circuit->snd_stream->endp = lsp->pdu->endp;
2502 memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp);
2503
2504 retval = circuit->tx (circuit, lsp->level);
eb5d44eb 2505
eb5d44eb 2506 /*
f390d2c7 2507 * If the sending succeeded, we can del the lsp from circuits
2508 * lsp_queue
eb5d44eb 2509 */
f390d2c7 2510 if (retval == ISIS_OK)
2511 {
2512 list_delete_node (circuit->lsp_queue, node);
2513
2514 /*
2515 * On broadcast circuits also the SRMflag can be cleared
2516 */
2517 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2518 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2519
2520 if (flags_any_set (lsp->SRMflags) == 0)
2521 {
2522 /*
2523 * need to remember when we were last sent
2524 */
2525 lsp->last_sent = time (NULL);
2526 }
2527 }
2528 else
2529 {
2530 zlog_info ("sending of level %d link state failed", lsp->level);
2531 }
2532 }
2533 else
2534 {
2535 /* my belief is that if it wasn't his time, the lsp can be removed
2536 * from the queue
2537 */
2538 dontsend:
2539 list_delete_node (circuit->lsp_queue, node);
eb5d44eb 2540 }
eb5d44eb 2541#if 0
f390d2c7 2542 /*
2543 * If there are still LSPs send next one after lsp-interval (33 msecs)
2544 */
2545 if (listcount (circuit->lsp_queue) > 0)
2546 thread_add_timer (master, send_lsp, circuit, 1);
eb5d44eb 2547#endif
f390d2c7 2548 }
eb5d44eb 2549
2550 return retval;
f390d2c7 2551}
eb5d44eb 2552
2553int
f390d2c7 2554ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2555 int level)
eb5d44eb 2556{
2557 unsigned long lenp;
2558 int retval;
2559 u_int16_t length;
2560 struct isis_fixed_hdr fixed_hdr;
2561
2562 if (!circuit->snd_stream)
f390d2c7 2563 circuit->snd_stream = stream_new (ISO_MTU (circuit));
eb5d44eb 2564 else
2565 stream_reset (circuit->snd_stream);
2566
2567// fill_llc_hdr (stream);
2568 if (level == 1)
f390d2c7 2569 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2570 circuit->snd_stream);
eb5d44eb 2571 else
f390d2c7 2572 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2573 circuit->snd_stream);
eb5d44eb 2574
2575
2576 lenp = stream_get_putp (circuit->snd_stream);
f390d2c7 2577 stream_putw (circuit->snd_stream, 0); /* PDU length */
2578 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
eb5d44eb 2579 stream_putc (circuit->snd_stream, circuit->idx);
f390d2c7 2580 stream_putc (circuit->snd_stream, 9); /* code */
2581 stream_putc (circuit->snd_stream, 16); /* len */
eb5d44eb 2582
f390d2c7 2583 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2584 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2585 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2586 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
eb5d44eb 2587
f390d2c7 2588 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
eb5d44eb 2589 /* Update PDU length */
2590 stream_putw_at (circuit->snd_stream, lenp, length);
2591
2592 retval = circuit->tx (circuit, level);
2593
2594 return retval;
2595}
2596
2597#if 0
2598/*
2599 * ISH PDU Processing
2600 */
2601
eb5d44eb 2602 /*
2603 * Let's first check if the local and remote system have any common area
2604 * addresses
2605 */
f390d2c7 2606if (area_match (tlvs.area_addrs, isis->man_area_addrs) == 0)
2607 {
2608 if (circuit->circuit_t == IS_LEVEL_2)
2609 {
2610 /* do as in table 8 (p. 40) */
2611 switch (circuit_type)
2612 {
2613 case IS_LEVEL_1:
2614 if (adj->adj_state != ISIS_ADJ_UP)
2615 {
2616 /* Reject */
2617 zlog_warn ("areaMismatch");
2618 retval = ISIS_WARNING;
2619 }
2620 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2621 {
2622 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2623 circuit->adjdb);
2624 }
2625 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 ||
2626 adj->adj_usage == ISIS_ADJ_LEVEL2)
2627 {
2628 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2629 circuit->adjdb);
2630 }
2631 break;
2632 case IS_LEVEL_2:
2633 if (adj->adj_state != ISIS_ADJ_UP)
2634 {
2635 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2636 circuit->adjdb);
2637 adj->adj_usage = ISIS_ADJ_LEVEL2;
2638 }
2639 else if (adj->adj_usage == ISIS_ADJ_LEVEL1 ||
2640 adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2641 {
2642 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2643 circuit->adjdb);
2644 }
2645 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2646 {
2647 ; /* Accept */
2648 }
2649 break;
2650 case IS_LEVEL_1_AND_2:
2651 if (adj->adj_state != ISIS_ADJ_UP)
2652 {
2653 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2654 circuit->adjdb);
2655 adj->adj_usage = ISIS_ADJ_LEVEL2;
2656 }
2657 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2658 {
2659 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2660 circuit->adjdb);
2661 }
2662 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2663 {
2664 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2665 circuit->adjdb);
2666 }
2667 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2668 {
2669 ; /* Accept */
2670 }
2671 break;
2672 }
2673 goto mismatch;
2674 }
2675 else
2676 {
2677 isis_delete_adj (adj, circuit->adjdb);
2678 zlog_warn ("areaMismatch");
2679 return ISIS_WARNING;
eb5d44eb 2680 }
eb5d44eb 2681 }
2682
2683mismatch:
2684#endif