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