blob: 4bc2b5464c55ef46ea88309a58a8b5b552dfc141 [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>
jardineb5d44e2003-12-23 08:09:43 +000027
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
hassof390d2c2004-09-10 20:48:21 +000061#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000062
63#ifndef PNBBY
64#define PNBBY 8
65#endif /* PNBBY */
66
67/* Utility mask array. */
hassof390d2c2004-09-10 20:48:21 +000068static u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000069 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 */
hassof390d2c2004-09-10 20:48:21 +000079static int
jardineb5d44e2003-12-23 08:09:43 +000080area_match (struct list *left, struct list *right)
81{
82 struct area_addr *addr1, *addr2;
83 struct listnode *node1, *node2;
84
hassof390d2c2004-09-10 20:48:21 +000085 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 */
jardineb5d44e2003-12-23 08:09:43 +000092 }
93 }
94
hassof390d2c2004-09-10 20:48:21 +000095 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000096}
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
hassof390d2c2004-09-10 20:48:21 +0000106ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000107{
108 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000109 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000110 int len;
hassof390d2c2004-09-10 20:48:21 +0000111
112 addr1 = (u_char *) & ip1->prefix.s_addr;
113 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000114 len = ip1->prefixlen;
115
116 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000117 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000118
hasso53c997c2004-09-15 16:21:59 +0000119 while (offsetloop--)
120 if (addr1[offsetloop] != addr2[offsetloop])
121 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000122
hassof390d2c2004-09-10 20:48:21 +0000123 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000124 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
125 return 0;
hassof390d2c2004-09-10 20:48:21 +0000126
127 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000128}
129
jardineb5d44e2003-12-23 08:09:43 +0000130/*
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 */
hassof390d2c2004-09-10 20:48:21 +0000137static int
jardineb5d44e2003-12-23 08:09:43 +0000138ip_match (struct list *left, struct list *right)
139{
140 struct prefix_ipv4 *ip1;
141 struct in_addr *ip2;
142 struct listnode *node1, *node2;
143
hassoe082ac12004-09-27 18:13:57 +0000144 if ((left == NULL) || (right == NULL))
145 return 0;
146
hassof390d2c2004-09-10 20:48:21 +0000147 LIST_LOOP (left, ip1, node1)
148 {
149 LIST_LOOP (right, ip2, node2)
150 {
151 if (ip_same_subnet (ip1, ip2))
152 {
153 return 1; /* match */
154 }
jardineb5d44e2003-12-23 08:09:43 +0000155 }
hassof390d2c2004-09-10 20:48:21 +0000156
jardineb5d44e2003-12-23 08:09:43 +0000157 }
158 return 0;
159}
160
161/*
162 * Checks whether we should accept a PDU of given level
163 */
164static int
165accept_level (int level, int circuit_t)
166{
hassof390d2c2004-09-10 20:48:21 +0000167 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000168
169 return retval;
170}
171
hassof390d2c2004-09-10 20:48:21 +0000172int
jardineb5d44e2003-12-23 08:09:43 +0000173authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
174{
hassof390d2c2004-09-10 20:48:21 +0000175 if (one->type != theother->type)
176 {
177 zlog_warn ("Unsupported authentication type %d", theother->type);
178 return 1; /* Auth fail (different authentication types) */
179 }
180 switch (one->type)
181 {
182 case ISIS_PASSWD_TYPE_CLEARTXT:
183 if (one->len != theother->len)
184 return 1; /* Auth fail () - passwd len mismatch */
185 return memcmp (one->passwd, theother->passwd, one->len);
186 break;
187 default:
188 zlog_warn ("Unsupported authentication type");
189 break;
190 }
191 return 0; /* Auth pass */
jardineb5d44e2003-12-23 08:09:43 +0000192}
193
194/*
195 * Processing helper functions
196 */
197void
hassof390d2c2004-09-10 20:48:21 +0000198tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000199{
200 int i;
201 struct nlpids *tlv_nlpids;
202
hassof390d2c2004-09-10 20:48:21 +0000203 if (tlvs->nlpids)
204 {
jardineb5d44e2003-12-23 08:09:43 +0000205
hassof390d2c2004-09-10 20:48:21 +0000206 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000207
hassof390d2c2004-09-10 20:48:21 +0000208 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000209
hassof390d2c2004-09-10 20:48:21 +0000210 for (i = 0; i < tlv_nlpids->count; i++)
211 {
212 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
213 }
jardineb5d44e2003-12-23 08:09:43 +0000214 }
jardineb5d44e2003-12-23 08:09:43 +0000215}
216
hassof390d2c2004-09-10 20:48:21 +0000217void
jardineb5d44e2003-12-23 08:09:43 +0000218del_ip_addr (void *val)
219{
220 XFREE (MTYPE_ISIS_TMP, val);
221}
222
223void
hassof390d2c2004-09-10 20:48:21 +0000224tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000225{
226 struct listnode *node;
227 struct in_addr *ipv4_addr, *malloced;
228
hassof390d2c2004-09-10 20:48:21 +0000229 if (adj->ipv4_addrs)
230 {
231 adj->ipv4_addrs->del = del_ip_addr;
232 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000233 }
hassof390d2c2004-09-10 20:48:21 +0000234 adj->ipv4_addrs = list_new ();
235 if (tlvs->ipv4_addrs)
236 {
237 LIST_LOOP (tlvs->ipv4_addrs, ipv4_addr, node)
238 {
239 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
240 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
241 listnode_add (adj->ipv4_addrs, malloced);
242 }
243 }
jardineb5d44e2003-12-23 08:09:43 +0000244}
245
246#ifdef HAVE_IPV6
247void
hassof390d2c2004-09-10 20:48:21 +0000248tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000249{
250 struct listnode *node;
251 struct in6_addr *ipv6_addr, *malloced;
252
hassof390d2c2004-09-10 20:48:21 +0000253 if (adj->ipv6_addrs)
254 {
255 adj->ipv6_addrs->del = del_ip_addr;
256 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000257 }
hassof390d2c2004-09-10 20:48:21 +0000258 adj->ipv6_addrs = list_new ();
259 if (tlvs->ipv6_addrs)
260 {
261 LIST_LOOP (tlvs->ipv6_addrs, ipv6_addr, node)
262 {
263 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
264 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
265 listnode_add (adj->ipv6_addrs, malloced);
266 }
267 }
jardineb5d44e2003-12-23 08:09:43 +0000268
269}
270#endif /* HAVE_IPV6 */
271
jardineb5d44e2003-12-23 08:09:43 +0000272/*
273 * RECEIVE SIDE
274 */
275
276/*
277 * Process P2P IIH
278 * ISO - 10589
279 * Section 8.2.5 - Receiving point-to-point IIH PDUs
280 *
281 */
282static int
283process_p2p_hello (struct isis_circuit *circuit)
284{
285 int retval = ISIS_OK;
286 struct isis_p2p_hello_hdr *hdr;
287 struct isis_adjacency *adj;
288 u_int32_t expected = 0, found;
289 struct tlvs tlvs;
290
hassof390d2c2004-09-10 20:48:21 +0000291 if ((stream_get_endp (circuit->rcv_stream) -
292 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
293 {
294 zlog_warn ("Packet too short");
295 return ISIS_WARNING;
296 }
jardineb5d44e2003-12-23 08:09:43 +0000297
298 /* 8.2.5.1 PDU acceptance tests */
299
300 /* 8.2.5.1 a) external domain untrue */
301 /* FIXME: not useful at all? */
302
303 /* 8.2.5.1 b) ID Length mismatch */
304 /* checked at the handle_pdu */
305
306 /* 8.2.5.2 IIH PDU Processing */
307
308 /* 8.2.5.2 a) 1) Maximum Area Addresses */
309 /* Already checked, and can also be ommited */
310
311 /*
312 * Get the header
313 */
hassof390d2c2004-09-10 20:48:21 +0000314 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000315 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
316
317 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000318 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
319 hdr.hold_time = stream_getw (stream);
320 hdr.pdu_len = stream_getw (stream);
321 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000322
323 /*
324 * My interpertation of the ISO, if no adj exists we will create one for
325 * the circuit
326 */
327
hassof390d2c2004-09-10 20:48:21 +0000328 if (isis->debugs & DEBUG_ADJ_PACKETS)
329 {
330 zlog_info ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
331 " cir id %02d, length %d",
332 circuit->area->area_tag, circuit->interface->name,
333 circuit_t2string (circuit->circuit_is_type),
334 circuit->circuit_id, ntohs (hdr->pdu_len));
335 }
jardineb5d44e2003-12-23 08:09:43 +0000336
337 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000338 if (!adj)
339 {
hassof7c43dc2004-09-26 16:24:14 +0000340 adj = isis_new_adj (hdr->source_id, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +0000341 if (adj == NULL)
342 return ISIS_ERROR;
343 circuit->u.p2p.neighbor = adj;
344 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
345 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
346 }
jardineb5d44e2003-12-23 08:09:43 +0000347
348 /* 8.2.6 Monitoring point-to-point adjacencies */
349 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000350 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000351
352 /*
353 * Lets get the TLVS now
354 */
355 expected |= TLVFLAG_AREA_ADDRS;
356 expected |= TLVFLAG_AUTH_INFO;
357 expected |= TLVFLAG_NLPID;
358 expected |= TLVFLAG_IPV4_ADDR;
359 expected |= TLVFLAG_IPV6_ADDR;
360
361 retval = parse_tlvs (circuit->area->area_tag,
362 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000363 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
364 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000365
hassof390d2c2004-09-10 20:48:21 +0000366 if (retval > ISIS_WARNING)
367 {
368 free_tlvs (&tlvs);
369 return retval;
370 };
jardineb5d44e2003-12-23 08:09:43 +0000371
372 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000373 if (circuit->passwd.type)
374 {
375 if (!(found & TLVFLAG_AUTH_INFO) ||
376 authentication_check (&circuit->passwd, &tlvs.auth_info))
377 {
378 isis_event_auth_failure (circuit->area->area_tag,
379 "P2P hello authentication failure",
380 hdr->source_id);
381 return ISIS_OK;
382 }
jardineb5d44e2003-12-23 08:09:43 +0000383 }
jardineb5d44e2003-12-23 08:09:43 +0000384
385 /* we do this now because the adj may not survive till the end... */
386
387 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000388 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000389
390#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000391 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000392#endif /* HAVE_IPV6 */
393
394 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000395 THREAD_TIMER_OFF (adj->t_expire);
396 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
397 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000398
399 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000400 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
401 {
402 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
403 if (circuit->area->is_type == IS_LEVEL_1)
404 {
405 switch (hdr->circuit_t)
406 {
407 case IS_LEVEL_1:
408 case IS_LEVEL_1_AND_2:
409 if (adj->adj_state != ISIS_ADJ_UP)
410 {
411 /* (4) adj state up */
412 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
413 /* (5) adj usage level 1 */
414 adj->adj_usage = ISIS_ADJ_LEVEL1;
415 }
416 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
417 {
418 ; /* accept */
419 }
420 break;
421 case IS_LEVEL_2:
422 if (adj->adj_state != ISIS_ADJ_UP)
423 {
424 /* (7) reject - wrong system type event */
425 zlog_warn ("wrongSystemType");
426 return ISIS_WARNING; /* Reject */
427 }
428 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
429 {
430 /* (6) down - wrong system */
431 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
432 }
433 break;
434 }
435 }
jardineb5d44e2003-12-23 08:09:43 +0000436
hassof390d2c2004-09-10 20:48:21 +0000437 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
438 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
439 {
440 switch (hdr->circuit_t)
441 {
442 case IS_LEVEL_1:
443 if (adj->adj_state != ISIS_ADJ_UP)
444 {
445 /* (6) adj state up */
446 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
447 /* (7) adj usage level 1 */
448 adj->adj_usage = ISIS_ADJ_LEVEL1;
449 }
450 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
451 {
452 ; /* accept */
453 }
454 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
455 (adj->adj_usage == ISIS_ADJ_LEVEL2))
456 {
457 /* (8) down - wrong system */
458 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
459 }
460 break;
461 case IS_LEVEL_2:
462 if (adj->adj_state != ISIS_ADJ_UP)
463 {
464 /* (6) adj state up */
465 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
466 /* (9) adj usage level 2 */
467 adj->adj_usage = ISIS_ADJ_LEVEL2;
468 }
469 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
470 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
471 {
472 /* (8) down - wrong system */
473 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
474 }
475 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
476 {
477 ; /* Accept */
478 }
479 break;
480 case IS_LEVEL_1_AND_2:
481 if (adj->adj_state != ISIS_ADJ_UP)
482 {
483 /* (6) adj state up */
484 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
485 /* (10) adj usage level 1 */
486 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
487 }
488 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
489 (adj->adj_usage == ISIS_ADJ_LEVEL2))
490 {
491 /* (8) down - wrong system */
492 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
493 }
494 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
495 {
496 ; /* Accept */
497 }
498 break;
499 }
500 }
jardineb5d44e2003-12-23 08:09:43 +0000501
hassof390d2c2004-09-10 20:48:21 +0000502 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
503 if (circuit->area->is_type == IS_LEVEL_2)
504 {
505 switch (hdr->circuit_t)
506 {
507 case IS_LEVEL_1:
508 if (adj->adj_state != ISIS_ADJ_UP)
509 {
510 /* (5) reject - wrong system type event */
511 zlog_warn ("wrongSystemType");
512 return ISIS_WARNING; /* Reject */
513 }
514 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
515 (adj->adj_usage == ISIS_ADJ_LEVEL2))
516 {
517 /* (6) down - wrong system */
518 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
519 }
520 break;
521 case IS_LEVEL_1_AND_2:
522 case IS_LEVEL_2:
523 if (adj->adj_state != ISIS_ADJ_UP)
524 {
525 /* (7) adj state up */
526 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
527 /* (8) adj usage level 2 */
528 adj->adj_usage = ISIS_ADJ_LEVEL2;
529 }
530 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
531 {
532 /* (6) down - wrong system */
533 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
534 }
535 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
536 {
537 ; /* Accept */
538 }
539 break;
540 }
541 }
jardineb5d44e2003-12-23 08:09:43 +0000542 }
jardineb5d44e2003-12-23 08:09:43 +0000543 /* 8.2.5.2 b) if no match was detected */
544 else
jardineb5d44e2003-12-23 08:09:43 +0000545 {
hassof390d2c2004-09-10 20:48:21 +0000546 if (circuit->area->is_type == IS_LEVEL_1)
547 {
548 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
549 if (adj->adj_state != ISIS_ADJ_UP)
550 {
551 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
552 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
553 }
554 else
555 {
556 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
557 "Down - Area Mismatch");
558 }
559 }
560 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
561 else
562 {
563 switch (hdr->circuit_t)
564 {
565 case IS_LEVEL_1:
566 if (adj->adj_state != ISIS_ADJ_UP)
567 {
568 /* (6) reject - Area Mismatch event */
569 zlog_warn ("AreaMismatch");
570 return ISIS_WARNING; /* Reject */
571 }
572 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
573 {
574 /* (7) down - area mismatch */
575 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000576
hassof390d2c2004-09-10 20:48:21 +0000577 }
578 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
579 (adj->adj_usage == ISIS_ADJ_LEVEL2))
580 {
581 /* (7) down - wrong system */
582 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
583 }
584 break;
585 case IS_LEVEL_1_AND_2:
586 case IS_LEVEL_2:
587 if (adj->adj_state != ISIS_ADJ_UP)
588 {
589 /* (8) adj state up */
590 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
591 /* (9) adj usage level 2 */
592 adj->adj_usage = ISIS_ADJ_LEVEL2;
593 }
594 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
595 {
596 /* (7) down - wrong system */
597 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
598 }
599 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
600 {
601 if (hdr->circuit_t == IS_LEVEL_2)
602 {
603 /* (7) down - wrong system */
604 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
605 "Wrong System");
606 }
607 else
608 {
609 /* (7) down - area mismatch */
610 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
611 "Area Mismatch");
612 }
613 }
614 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
615 {
616 ; /* Accept */
617 }
618 break;
619 }
620 }
jardineb5d44e2003-12-23 08:09:43 +0000621 }
jardineb5d44e2003-12-23 08:09:43 +0000622 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
623 /* FIXME - Missing parts */
624
jardineb5d44e2003-12-23 08:09:43 +0000625 /* some of my own understanding of the ISO, why the heck does
626 * it not say what should I change the system_type to...
627 */
hassof390d2c2004-09-10 20:48:21 +0000628 switch (adj->adj_usage)
629 {
jardineb5d44e2003-12-23 08:09:43 +0000630 case ISIS_ADJ_LEVEL1:
631 adj->sys_type = ISIS_SYSTYPE_L1_IS;
632 break;
633 case ISIS_ADJ_LEVEL2:
634 adj->sys_type = ISIS_SYSTYPE_L2_IS;
635 break;
636 case ISIS_ADJ_LEVEL1AND2:
637 adj->sys_type = ISIS_SYSTYPE_L2_IS;
638 break;
639 case ISIS_ADJ_NONE:
640 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
641 break;
hassof390d2c2004-09-10 20:48:21 +0000642 }
jardineb5d44e2003-12-23 08:09:43 +0000643
644 adj->circuit_t = hdr->circuit_t;
645 adj->level = hdr->circuit_t;
646
647 free_tlvs (&tlvs);
648
649 return retval;
650}
651
jardineb5d44e2003-12-23 08:09:43 +0000652/*
653 * Process IS-IS LAN Level 1/2 Hello PDU
654 */
hassof390d2c2004-09-10 20:48:21 +0000655static int
656process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000657{
658 int retval = ISIS_OK;
659 struct isis_lan_hello_hdr hdr;
660 struct isis_adjacency *adj;
661 u_int32_t expected = 0, found;
662 struct tlvs tlvs;
663 u_char *snpa;
664 struct listnode *node;
665
hassof390d2c2004-09-10 20:48:21 +0000666 if ((stream_get_endp (circuit->rcv_stream) -
667 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
668 {
669 zlog_warn ("Packet too short");
670 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000671 }
hassof390d2c2004-09-10 20:48:21 +0000672
673 if (circuit->ext_domain)
674 {
675 zlog_info ("level %d LAN Hello received over circuit with "
676 "externalDomain = true", level);
677 return ISIS_WARNING;
678 }
679
680 if (!accept_level (level, circuit->circuit_is_type))
681 {
682 if (isis->debugs & DEBUG_ADJ_PACKETS)
683 {
684 zlog_info ("ISIS-Adj (%s): Interface level mismatch, %s",
685 circuit->area->area_tag, circuit->interface->name);
686 }
687 return ISIS_WARNING;
688 }
jardineb5d44e2003-12-23 08:09:43 +0000689
690#if 0
691 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000692 if (!accept_level (level, circuit->area->is_type))
693 {
694 if (isis->debugs & DEBUG_ADJ_PACKETS)
695 {
696 zlog_info ("ISIS-Adj (%s): is type mismatch",
697 circuit->area->area_tag);
698 }
699 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000700 }
jardineb5d44e2003-12-23 08:09:43 +0000701#endif
702 /*
703 * Fill the header
704 */
705 hdr.circuit_t = stream_getc (circuit->rcv_stream);
706 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
707 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000708 hdr.pdu_len = stream_getw (circuit->rcv_stream);
709 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000710 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
711
712 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000713 hdr.circuit_t != IS_LEVEL_1_AND_2)
714 {
715 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
716 hdr.circuit_t);
717 return ISIS_ERROR;
718 }
jardineb5d44e2003-12-23 08:09:43 +0000719 /*
720 * Then get the tlvs
721 */
722 expected |= TLVFLAG_AUTH_INFO;
723 expected |= TLVFLAG_AREA_ADDRS;
724 expected |= TLVFLAG_LAN_NEIGHS;
725 expected |= TLVFLAG_NLPID;
726 expected |= TLVFLAG_IPV4_ADDR;
727 expected |= TLVFLAG_IPV6_ADDR;
728
729 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000730 STREAM_PNT (circuit->rcv_stream),
731 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
732 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000733
hassof390d2c2004-09-10 20:48:21 +0000734 if (retval > ISIS_WARNING)
735 {
736 zlog_warn ("parse_tlvs() failed");
737 goto out;
738 }
jardineb5d44e2003-12-23 08:09:43 +0000739
hassof390d2c2004-09-10 20:48:21 +0000740 if (!(found & TLVFLAG_AREA_ADDRS))
741 {
742 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
743 level);
jardineb5d44e2003-12-23 08:09:43 +0000744 retval = ISIS_WARNING;
745 goto out;
746 }
hassof390d2c2004-09-10 20:48:21 +0000747
748 if (circuit->passwd.type)
749 {
750 if (!(found & TLVFLAG_AUTH_INFO) ||
751 authentication_check (&circuit->passwd, &tlvs.auth_info))
752 {
753 isis_event_auth_failure (circuit->area->area_tag,
754 "LAN hello authentication failure",
755 hdr.source_id);
756 retval = ISIS_WARNING;
757 goto out;
758 }
759 }
jardineb5d44e2003-12-23 08:09:43 +0000760
761 /*
762 * Accept the level 1 adjacency only if a match between local and
763 * remote area addresses is found
764 */
hassof390d2c2004-09-10 20:48:21 +0000765 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
766 {
767 if (isis->debugs & DEBUG_ADJ_PACKETS)
768 {
769 zlog_info ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
770 circuit->area->area_tag, level,
771 circuit->interface->name);
772 }
773 retval = ISIS_OK;
774 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000775 }
jardineb5d44e2003-12-23 08:09:43 +0000776
777 /*
778 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000779 */
780 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
781 {
782 zlog_info ("ISIS-Adj (%s): it's own IIH PDU - discarded",
783 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000784
hassof390d2c2004-09-10 20:48:21 +0000785 retval = ISIS_OK;
786 goto out;
787 }
jardineb5d44e2003-12-23 08:09:43 +0000788
789 /*
790 * check if it's own interface ip match iih ip addrs
791 */
hassof390d2c2004-09-10 20:48:21 +0000792 if (!(found & TLVFLAG_IPV4_ADDR)
793 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
794 {
795 zlog_info
796 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
797 circuit->interface->name);
798 retval = ISIS_WARNING;
799 goto out;
800 }
jardineb5d44e2003-12-23 08:09:43 +0000801
802 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000803 if (!adj)
804 {
805 /*
806 * Do as in 8.4.2.5
807 */
808 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
809 if (adj == NULL)
hasso13c48f72004-09-10 21:19:13 +0000810 {
811 retval = ISIS_ERROR;
812 goto out;
813 }
jardineb5d44e2003-12-23 08:09:43 +0000814
hassof390d2c2004-09-10 20:48:21 +0000815 adj->level = level;
816 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000817
hassof390d2c2004-09-10 20:48:21 +0000818 if (level == 1)
819 {
820 adj->sys_type = ISIS_SYSTYPE_L1_IS;
821 }
822 else
823 {
824 adj->sys_type = ISIS_SYSTYPE_L2_IS;
825 }
826 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
827 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
828 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000829 }
jardineb5d44e2003-12-23 08:09:43 +0000830
hassoa211d652004-09-20 14:55:29 +0000831 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
832 switch (level)
833 {
834 case 1:
835 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
836 {
837 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000838 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
839 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000840 }
841 break;
842 case 2:
843 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
844 {
845 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000846 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
847 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000848 }
849 break;
850 }
jardineb5d44e2003-12-23 08:09:43 +0000851
852 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000853 adj->last_upd = time (NULL);
854 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000855
856 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
857
858 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000859 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000860 tlvs_to_adj_nlpids (&tlvs, adj);
861
862 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000863 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000864 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
865
866#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000867 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000868 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
869#endif /* HAVE_IPV6 */
870
871 adj->circuit_t = hdr.circuit_t;
872
873 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000874 THREAD_TIMER_OFF (adj->t_expire);
875 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
876 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000877
878 /*
879 * If the snpa for this circuit is found from LAN Neighbours TLV
880 * we have two-way communication -> adjacency can be put to state "up"
881 */
882
hassof390d2c2004-09-10 20:48:21 +0000883 if (found & TLVFLAG_LAN_NEIGHS)
884 {
885 if (adj->adj_state != ISIS_ADJ_UP)
886 {
887 LIST_LOOP (tlvs.lan_neighs, snpa, node)
888 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
889 {
890 isis_adj_state_change (adj, ISIS_ADJ_UP,
891 "own SNPA found in LAN Neighbours TLV");
892 }
893 }
jardineb5d44e2003-12-23 08:09:43 +0000894 }
jardineb5d44e2003-12-23 08:09:43 +0000895
hassof390d2c2004-09-10 20:48:21 +0000896out:
jardineb5d44e2003-12-23 08:09:43 +0000897 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000898 if (isis->debugs & DEBUG_ADJ_PACKETS)
899 {
900 /* FIXME: is this place right? fix missing info */
901 zlog_info ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
902 "cirID %u, length %ld",
903 circuit->area->area_tag,
904 level, snpa_print (ssnpa), circuit->interface->name,
905 circuit_t2string (circuit->circuit_is_type),
906 circuit->circuit_id, stream_get_endp (circuit->rcv_stream));
907 }
jardineb5d44e2003-12-23 08:09:43 +0000908
909 free_tlvs (&tlvs);
910
911 return retval;
912}
913
914/*
915 * Process Level 1/2 Link State
916 * ISO - 10589
917 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000918 */
919static int
920process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000921{
922 struct isis_link_state_hdr *hdr;
923 struct isis_adjacency *adj = NULL;
924 struct isis_lsp *lsp, *lsp0 = NULL;
925 int retval = ISIS_OK, comp = 0;
926 u_char lspid[ISIS_SYS_ID_LEN + 2];
927 struct isis_passwd *passwd;
928
929 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000930 if ((stream_get_endp (circuit->rcv_stream) -
931 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
932 {
933 zlog_warn ("Packet too short");
934 return ISIS_WARNING;
935 }
jardineb5d44e2003-12-23 08:09:43 +0000936
937 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000938 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000939
hassof390d2c2004-09-10 20:48:21 +0000940 if (isis->debugs & DEBUG_UPDATE_PACKETS)
941 {
942 zlog_info ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
943 "lifetime %us, len %lu, on %s",
944 circuit->area->area_tag,
945 level,
946 rawlspid_print (hdr->lsp_id),
947 ntohl (hdr->seq_num),
948 ntohs (hdr->checksum),
949 ntohs (hdr->rem_lifetime),
950 circuit->rcv_stream->endp, circuit->interface->name);
951 }
jardineb5d44e2003-12-23 08:09:43 +0000952
953 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
954
955 /* Checksum sanity check - FIXME: move to correct place */
956 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000957 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
958 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
959 {
960 zlog_info ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
961 circuit->area->area_tag,
962 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000963
hassof390d2c2004-09-10 20:48:21 +0000964 return ISIS_WARNING;
965 }
jardineb5d44e2003-12-23 08:09:43 +0000966
967 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000968 if (circuit->ext_domain)
969 {
970 zlog_info
971 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
972 "externalDomain = true", circuit->area->area_tag,
973 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000974
hassof390d2c2004-09-10 20:48:21 +0000975 return ISIS_WARNING;
976 }
jardineb5d44e2003-12-23 08:09:43 +0000977
978 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000979 if (!accept_level (level, circuit->circuit_is_type))
980 {
981 zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
982 " type %s",
983 circuit->area->area_tag,
984 rawlspid_print (hdr->lsp_id),
985 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +0000986
hassof390d2c2004-09-10 20:48:21 +0000987 return ISIS_WARNING;
988 }
jardineb5d44e2003-12-23 08:09:43 +0000989
990 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
991
992 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
993
994 /* 7.3.15.1 a) 7 - password check */
995 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
996 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +0000997 if (passwd->type)
998 {
999 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1000 ntohs (hdr->pdu_len), passwd))
1001 {
1002 isis_event_auth_failure (circuit->area->area_tag,
1003 "LSP authentication failure", hdr->lsp_id);
1004 return ISIS_WARNING;
1005 }
jardineb5d44e2003-12-23 08:09:43 +00001006 }
jardineb5d44e2003-12-23 08:09:43 +00001007 /* Find the LSP in our database and compare it to this Link State header */
1008 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1009 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001010 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1011 hdr->checksum, hdr->rem_lifetime);
1012 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001013#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001014 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001015#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001016 ))
jardineb5d44e2003-12-23 08:09:43 +00001017 goto dontcheckadj;
1018
1019 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1020 /* for broadcast circuits, snpa should be compared */
1021 /* FIXME : Point To Point */
1022
hassof390d2c2004-09-10 20:48:21 +00001023 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1024 {
1025 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1026 if (!adj)
1027 {
1028 zlog_info ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1029 "lifetime %us on %s",
1030 circuit->area->area_tag,
1031 rawlspid_print (hdr->lsp_id),
1032 ntohl (hdr->seq_num),
1033 ntohs (hdr->checksum),
1034 ntohs (hdr->rem_lifetime), circuit->interface->name);
1035 return ISIS_WARNING; /* Silently discard */
1036 }
jardineb5d44e2003-12-23 08:09:43 +00001037 }
jardineb5d44e2003-12-23 08:09:43 +00001038
1039 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001040 else
1041 {
1042 /* If no adj, or no sharing of level */
1043 if (!circuit->u.p2p.neighbor)
1044 {
1045 return ISIS_OK; /* Silently discard */
1046 }
1047 else
1048 {
1049 if (((level == 1) &&
1050 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1051 ((level == 2) &&
1052 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1053 return ISIS_WARNING; /* Silently discard */
1054 }
jardineb5d44e2003-12-23 08:09:43 +00001055 }
hassof390d2c2004-09-10 20:48:21 +00001056dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001057 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1058
1059 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1060
hassof390d2c2004-09-10 20:48:21 +00001061 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001062
hassof390d2c2004-09-10 20:48:21 +00001063 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1064 if (hdr->rem_lifetime == 0)
1065 {
1066 if (!lsp)
1067 {
1068 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1069 /* only needed on explicit update, eg - p2p */
1070 if (circuit->circ_type == CIRCUIT_T_P2P)
1071 ack_lsp (hdr, circuit, level);
1072 return retval; /* FIXME: do we need a purge? */
1073 }
1074 else
1075 {
1076 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1077 {
1078 /* LSP by some other system -> do 7.3.16.4 b) */
1079 /* 7.3.16.4 b) 1) */
1080 if (comp == LSP_NEWER)
1081 {
1082 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1083 /* ii */
1084 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1085 /* iii */
1086 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1087 /* v */
1088 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1089 /* iv */
1090 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1091 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001092
hassof390d2c2004-09-10 20:48:21 +00001093 } /* 7.3.16.4 b) 2) */
1094 else if (comp == LSP_EQUAL)
1095 {
1096 /* i */
1097 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1098 /* ii */
1099 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1100 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1101 } /* 7.3.16.4 b) 3) */
1102 else
1103 {
1104 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1105 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1106 }
1107 }
1108 else
1109 {
1110 /* our own LSP -> 7.3.16.4 c) */
1111 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1112 circuit->circuit_id
1113 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1114 circuit->circuit_id
1115 && circuit->u.bc.is_dr[level - 1] == 1))
1116 {
1117 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1118 zlog_info ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len));
1119 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1120 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1121 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1122 zlog_info
1123 ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1124 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1125 ntohl (lsp->lsp_header->seq_num));
1126 lsp->lsp_header->rem_lifetime =
1127 htons (isis_jitter
1128 (circuit->area->max_lsp_lifetime[level - 1],
1129 MAX_AGE_JITTER));
1130 }
1131 else
1132 {
1133 /* Got purge for own pseudo-lsp, and we are not DR */
1134 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1135 }
1136 }
1137 }
1138 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001139 }
jardineb5d44e2003-12-23 08:09:43 +00001140 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1141 * purge */
hassof390d2c2004-09-10 20:48:21 +00001142 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1143 {
1144 if (!lsp)
1145 {
1146 /* 7.3.16.4: initiate a purge */
1147 lsp_purge_non_exist (hdr, circuit->area);
1148 return ISIS_OK;
1149 }
1150 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1151
1152 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1153 * has information that the current sequence number for source S is
1154 * "greater" than that held by S, ... */
1155
1156 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1157 {
1158 /* 7.3.16.1 */
1159 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1160
1161 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1162 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1163
1164 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1165 zlog_info
1166 ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1167 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1168 ntohl (lsp->lsp_header->seq_num));
1169 lsp->lsp_header->rem_lifetime =
1170 htons (isis_jitter
1171 (circuit->area->max_lsp_lifetime[level - 1],
1172 MAX_AGE_JITTER));
1173 }
jardineb5d44e2003-12-23 08:09:43 +00001174 }
hassof390d2c2004-09-10 20:48:21 +00001175 else
1176 {
1177 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001178
hassof390d2c2004-09-10 20:48:21 +00001179 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1180 if ((!lsp || comp == LSP_NEWER))
1181 {
1182 /* i */
1183 if (lsp)
1184 {
jardineb5d44e2003-12-23 08:09:43 +00001185#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +00001186 zlog_info ("level %d number is - %ld", level,
1187 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001188#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001189 lsp_search_and_destroy (hdr->lsp_id,
1190 circuit->area->lspdb[level - 1]);
1191 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001192#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +00001193 zlog_info ("level %d number is - %ld", level,
1194 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001195#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001196 }
1197 /*
1198 * If this lsp is a frag, need to see if we have zero lsp present
1199 */
1200 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1201 {
1202 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1203 LSP_FRAGMENT (lspid) = 0;
1204 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1205 if (!lsp0)
1206 {
1207 zlog_info ("Got lsp frag, while zero lsp not database");
1208 return ISIS_OK;
1209 }
1210 }
1211 lsp =
1212 lsp_new_from_stream_ptr (circuit->rcv_stream,
1213 ntohs (hdr->pdu_len), lsp0,
1214 circuit->area);
1215 lsp->level = level;
1216 lsp->adj = adj;
1217 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1218 /* ii */
1219 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1220 /* iii */
1221 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001222
hassof390d2c2004-09-10 20:48:21 +00001223 /* iv */
1224 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1225 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1226 /* FIXME: v) */
1227 }
1228 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1229 else if (comp == LSP_EQUAL)
1230 {
1231 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1232 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1233 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1234 {
1235 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1236 }
1237 }
1238 /* 7.3.15.1 e) 3) LSP older than the one in db */
1239 else
1240 {
1241 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1242 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1243 }
jardineb5d44e2003-12-23 08:09:43 +00001244 }
jardineb5d44e2003-12-23 08:09:43 +00001245 if (lsp)
1246 lsp->adj = adj;
1247 return retval;
1248}
1249
1250/*
1251 * Process Sequence Numbers
1252 * ISO - 10589
1253 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1254 */
1255
1256int
hassof390d2c2004-09-10 20:48:21 +00001257process_snp (int snp_type, int level, struct isis_circuit *circuit,
1258 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001259{
1260 int retval = ISIS_OK;
1261 int cmp, own_lsp;
1262 char typechar = ' ';
1263 int len;
1264 struct isis_adjacency *adj;
1265 struct isis_complete_seqnum_hdr *chdr = NULL;
1266 struct isis_partial_seqnum_hdr *phdr = NULL;
1267 uint32_t found = 0, expected = 0;
1268 struct isis_lsp *lsp;
1269 struct lsp_entry *entry;
hassof390d2c2004-09-10 20:48:21 +00001270 struct listnode *node, *node2;
jardineb5d44e2003-12-23 08:09:43 +00001271 struct tlvs tlvs;
1272 struct list *lsp_list = NULL;
hasso1cd80842004-10-07 20:07:40 +00001273 /* TODO: Implement SNP authentication. */
1274#if 0
jardineb5d44e2003-12-23 08:09:43 +00001275 struct isis_passwd *passwd;
hasso1cd80842004-10-07 20:07:40 +00001276#endif
jardineb5d44e2003-12-23 08:09:43 +00001277
hassof390d2c2004-09-10 20:48:21 +00001278 if (snp_type == ISIS_SNP_CSNP_FLAG)
1279 {
1280 /* getting the header info */
1281 typechar = 'C';
1282 chdr =
1283 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1284 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1285 len = ntohs (chdr->pdu_len);
1286 if (len < ISIS_CSNP_HDRLEN)
1287 {
1288 zlog_warn ("Received a CSNP with bogus length!");
1289 return ISIS_OK;
1290 }
jardineb5d44e2003-12-23 08:09:43 +00001291 }
hassof390d2c2004-09-10 20:48:21 +00001292 else
1293 {
1294 typechar = 'P';
1295 phdr =
1296 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1297 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1298 len = ntohs (phdr->pdu_len);
1299 if (len < ISIS_PSNP_HDRLEN)
1300 {
1301 zlog_warn ("Received a CSNP with bogus length!");
1302 return ISIS_OK;
1303 }
jardineb5d44e2003-12-23 08:09:43 +00001304 }
jardineb5d44e2003-12-23 08:09:43 +00001305
1306 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001307 if (circuit->ext_domain)
1308 {
jardineb5d44e2003-12-23 08:09:43 +00001309
hassof390d2c2004-09-10 20:48:21 +00001310 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1311 "skipping: circuit externalDomain = true",
jardineb5d44e2003-12-23 08:09:43 +00001312 circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001313 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001314
1315 return ISIS_OK;
1316 }
hassof390d2c2004-09-10 20:48:21 +00001317
1318 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1319 if (!accept_level (level, circuit->circuit_is_type))
1320 {
1321
1322 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1323 "skipping: circuit type %s does not match level %d",
1324 circuit->area->area_tag,
1325 level,
1326 typechar,
1327 circuit->interface->name,
1328 circuit_t2string (circuit->circuit_is_type), level);
1329
1330 return ISIS_OK;
1331 }
1332
1333 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1334 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1335 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1336 {
1337 if (!circuit->u.bc.is_dr[level - 1])
1338 {
1339
1340 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1341 "skipping: we are not the DIS",
1342 circuit->area->area_tag,
1343 level,
1344 typechar, snpa_print (ssnpa), circuit->interface->name);
1345
1346 return ISIS_OK;
1347 }
1348 }
jardineb5d44e2003-12-23 08:09:43 +00001349
1350 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1351
1352 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1353 * - already checked */
1354
1355 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1356 /* for broadcast circuits, snpa should be compared */
1357 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001358 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1359 {
1360 if (snp_type == ISIS_SNP_CSNP_FLAG)
1361 {
1362 adj =
1363 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1364 }
1365 else
1366 {
1367 /* a psnp on a broadcast, how lovely of Juniper :) */
1368 adj =
1369 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1370 }
1371 if (!adj)
1372 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001373 }
hassof390d2c2004-09-10 20:48:21 +00001374 else
1375 {
1376 if (!circuit->u.p2p.neighbor)
1377 return ISIS_OK; /* Silently discard */
1378 }
jardineb5d44e2003-12-23 08:09:43 +00001379
1380 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1381
1382 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1383
1384 memset (&tlvs, 0, sizeof (struct tlvs));
1385
1386 /* parse the SNP */
1387 expected |= TLVFLAG_LSP_ENTRIES;
1388 expected |= TLVFLAG_AUTH_INFO;
1389 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001390 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001391 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001392 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001393
hassof390d2c2004-09-10 20:48:21 +00001394 if (retval > ISIS_WARNING)
1395 {
1396 zlog_warn ("something went very wrong processing SNP");
1397 free_tlvs (&tlvs);
1398 return retval;
1399 }
jardineb5d44e2003-12-23 08:09:43 +00001400
hasso53c997c2004-09-15 16:21:59 +00001401 /* FIXME: Authentication in LSPs does not mean authentication in SNPs...
1402 * In fact by default IOS only deals with LSPs authentication!!
1403 * To force authentication in SNPs, one must specify the 'authenticate
1404 * snp' command after 'area-password WORD' or 'domain-password WORD'.
1405 * This command is not supported for the moment.
1406 */
1407#if 0
jardineb5d44e2003-12-23 08:09:43 +00001408 (level == 1) ? (passwd = &circuit->area->area_passwd) :
hassof390d2c2004-09-10 20:48:21 +00001409 (passwd = &circuit->area->domain_passwd);
1410 if (passwd->type)
1411 {
1412 if (!(found & TLVFLAG_AUTH_INFO) ||
1413 authentication_check (passwd, &tlvs.auth_info))
1414 {
1415 isis_event_auth_failure (circuit->area->area_tag,
1416 "SNP authentication" " failure",
1417 phdr ? phdr->source_id : chdr->source_id);
1418 return ISIS_OK;
1419 }
1420 }
hasso53c997c2004-09-15 16:21:59 +00001421#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +00001422
1423 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001424 if (isis->debugs & DEBUG_SNP_PACKETS)
1425 {
1426 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1427 circuit->area->area_tag,
1428 level,
1429 typechar, snpa_print (ssnpa), circuit->interface->name);
1430 if (tlvs.lsp_entries)
1431 {
1432 LIST_LOOP (tlvs.lsp_entries, entry, node)
1433 {
1434 zlog_info ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1435 " cksum 0x%04x, lifetime %us",
1436 circuit->area->area_tag,
1437 typechar,
1438 rawlspid_print (entry->lsp_id),
1439 ntohl (entry->seq_num),
1440 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
1441 }
1442 }
jardineb5d44e2003-12-23 08:09:43 +00001443 }
jardineb5d44e2003-12-23 08:09:43 +00001444
1445 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001446 if (tlvs.lsp_entries)
1447 {
1448 LIST_LOOP (tlvs.lsp_entries, entry, node)
1449 {
1450 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1451 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1452 if (lsp)
1453 {
1454 /* 7.3.15.2 b) 1) is this LSP newer */
1455 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1456 entry->checksum, entry->rem_lifetime);
1457 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1458 if (cmp == LSP_EQUAL)
1459 {
1460 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1461 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1462 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1463 }
1464 else if (cmp == LSP_OLDER)
1465 {
1466 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1467 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1468 }
1469 else
1470 {
1471 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1472 * on p2p */
1473 if (own_lsp)
1474 {
1475 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1476 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1477 }
1478 else
1479 {
1480 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1481 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1482 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1483 }
1484 }
1485 }
1486 else
1487 {
1488 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1489 * insert it and set SSN on it */
1490 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1491 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1492 {
1493 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1494 0, 0, entry->checksum, level);
1495 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1496 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1497 }
1498 }
jardineb5d44e2003-12-23 08:09:43 +00001499 }
1500 }
jardineb5d44e2003-12-23 08:09:43 +00001501
1502 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001503 if (snp_type == ISIS_SNP_CSNP_FLAG)
1504 {
1505 /*
1506 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1507 */
1508 lsp_list = list_new ();
1509 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1510 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001511
hassof390d2c2004-09-10 20:48:21 +00001512 /* Fixme: Find a better solution */
1513 if (tlvs.lsp_entries)
1514 {
1515 LIST_LOOP (tlvs.lsp_entries, entry, node)
1516 {
1517 LIST_LOOP (lsp_list, lsp, node2)
1518 {
1519 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1520 {
1521 list_delete_node (lsp_list, node2);
1522 break;
1523 }
1524 }
1525 }
1526 }
1527 /* on remaining LSPs we set SRM (neighbor knew not of) */
1528 LIST_LOOP (lsp_list, lsp, node2)
1529 {
1530 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001531 }
hassof390d2c2004-09-10 20:48:21 +00001532 /* lets free it */
1533 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001534 }
jardineb5d44e2003-12-23 08:09:43 +00001535
1536 free_tlvs (&tlvs);
1537 return retval;
1538}
1539
1540int
hassof390d2c2004-09-10 20:48:21 +00001541process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001542{
jardineb5d44e2003-12-23 08:09:43 +00001543 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001544 if ((stream_get_endp (circuit->rcv_stream) -
1545 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1546 {
1547 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1548 return ISIS_WARNING;
1549 }
jardineb5d44e2003-12-23 08:09:43 +00001550
1551 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1552}
1553
hassof390d2c2004-09-10 20:48:21 +00001554int
1555process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001556{
hassof390d2c2004-09-10 20:48:21 +00001557 if ((stream_get_endp (circuit->rcv_stream) -
1558 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1559 {
1560 zlog_warn ("Packet too short");
1561 return ISIS_WARNING;
1562 }
jardineb5d44e2003-12-23 08:09:43 +00001563
1564 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1565}
1566
jardineb5d44e2003-12-23 08:09:43 +00001567/*
1568 * Process ISH
1569 * ISO - 10589
1570 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1571 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001572 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1573 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1574 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001575 */
1576int
1577process_is_hello (struct isis_circuit *circuit)
1578{
1579 struct isis_adjacency *adj;
1580 int retval = ISIS_OK;
1581 u_char neigh_len;
1582 u_char *sysid;
1583
1584 /* In this point in time we are not yet able to handle is_hellos
1585 * on lan - Sorry juniper...
1586 */
1587 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1588 return retval;
1589
1590 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001591 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001592 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001593 if (!adj)
1594 {
1595 /* 8.2.2 */
hassof7c43dc2004-09-26 16:24:14 +00001596 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001597 if (adj == NULL)
1598 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001599
hassof390d2c2004-09-10 20:48:21 +00001600 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1601 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1602 circuit->u.p2p.neighbor = adj;
1603 }
1604 /* 8.2.2 a) */
1605 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1606 ISIS_SYS_ID_LEN))
1607 {
1608 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1609 /* 8.2.2 a) 2) delete the adj */
1610 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1611 /* 8.2.2 a) 3) create a new adj */
hassof7c43dc2004-09-26 16:24:14 +00001612 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001613 if (adj == NULL)
1614 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001615
hassof390d2c2004-09-10 20:48:21 +00001616 /* 8.2.2 a) 3) i */
1617 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1618 /* 8.2.2 a) 3) ii */
1619 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1620 /* 8.2.2 a) 4) quite meaningless */
1621 }
jardineb5d44e2003-12-23 08:09:43 +00001622 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001623 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1624 (adj->sys_type == ISIS_SYSTYPE_IS))
1625 {
1626 /* do nothing */
1627 }
1628 else
1629 {
1630 /* 8.2.2 c) respond with a p2p IIH */
1631 send_hello (circuit, 1);
1632 }
jardineb5d44e2003-12-23 08:09:43 +00001633 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001634 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001635 /* 8.2.2 e) FIXME: Circuit type of? */
1636
jardineb5d44e2003-12-23 08:09:43 +00001637 return retval;
1638}
1639
jardineb5d44e2003-12-23 08:09:43 +00001640/*
1641 * PDU Dispatcher
1642 */
1643
hassof390d2c2004-09-10 20:48:21 +00001644int
1645isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001646{
jardineb5d44e2003-12-23 08:09:43 +00001647 struct isis_fixed_hdr *hdr;
1648 struct esis_fixed_hdr *esis_hdr;
1649
hassof390d2c2004-09-10 20:48:21 +00001650 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001651
1652 /*
1653 * Let's first read data from stream to the header
1654 */
hassof390d2c2004-09-10 20:48:21 +00001655 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001656
hassof390d2c2004-09-10 20:48:21 +00001657 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1658 {
1659 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1660 return ISIS_ERROR;
1661 }
jardineb5d44e2003-12-23 08:09:43 +00001662
1663 /* now we need to know if this is an ISO 9542 packet and
1664 * take real good care of it, waaa!
1665 */
hassof390d2c2004-09-10 20:48:21 +00001666 if (hdr->idrp == ISO9542_ESIS)
1667 {
1668 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1669 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1670 /* FIXME: Need to do some acceptence tests */
1671 /* example length... */
1672 switch (esis_hdr->pdu_type)
1673 {
1674 case ESH_PDU:
1675 /* FIXME */
1676 break;
1677 case ISH_PDU:
1678 zlog_info ("AN ISH PDU!!");
1679 retval = process_is_hello (circuit);
1680 break;
1681 default:
1682 return ISIS_ERROR;
1683 }
1684 return retval;
1685 }
1686 else
1687 {
1688 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1689 }
jardineb5d44e2003-12-23 08:09:43 +00001690 /*
1691 * and then process it
1692 */
1693
hassof390d2c2004-09-10 20:48:21 +00001694 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1695 {
1696 zlog_err ("Fixed header length = %d", hdr->length);
1697 return ISIS_ERROR;
1698 }
jardineb5d44e2003-12-23 08:09:43 +00001699
hassof390d2c2004-09-10 20:48:21 +00001700 if (hdr->version1 != 1)
1701 {
1702 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1703 return ISIS_WARNING;
1704 }
jardineb5d44e2003-12-23 08:09:43 +00001705 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001706 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1707 {
1708 zlog_err
1709 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1710 "while the parameter for this IS is %u", hdr->id_len,
1711 ISIS_SYS_ID_LEN);
1712 return ISIS_ERROR;
1713 }
jardineb5d44e2003-12-23 08:09:43 +00001714
hassof390d2c2004-09-10 20:48:21 +00001715 if (hdr->version2 != 1)
1716 {
1717 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1718 return ISIS_WARNING;
1719 }
jardineb5d44e2003-12-23 08:09:43 +00001720 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001721 if ((hdr->max_area_addrs != 0)
1722 && (hdr->max_area_addrs != isis->max_area_addrs))
1723 {
1724 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1725 "received PDU %u while the parameter for this IS is %u",
1726 hdr->max_area_addrs, isis->max_area_addrs);
1727 return ISIS_ERROR;
1728 }
jardineb5d44e2003-12-23 08:09:43 +00001729
hassof390d2c2004-09-10 20:48:21 +00001730 switch (hdr->pdu_type)
1731 {
1732 case L1_LAN_HELLO:
1733 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1734 break;
1735 case L2_LAN_HELLO:
1736 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1737 break;
1738 case P2P_HELLO:
1739 retval = process_p2p_hello (circuit);
1740 break;
1741 case L1_LINK_STATE:
1742 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1743 break;
1744 case L2_LINK_STATE:
1745 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1746 break;
1747 case L1_COMPLETE_SEQ_NUM:
1748 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1749 break;
1750 case L2_COMPLETE_SEQ_NUM:
1751 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1752 break;
1753 case L1_PARTIAL_SEQ_NUM:
1754 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1755 break;
1756 case L2_PARTIAL_SEQ_NUM:
1757 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1758 break;
1759 default:
1760 return ISIS_ERROR;
1761 }
jardineb5d44e2003-12-23 08:09:43 +00001762
1763 return retval;
1764}
1765
jardineb5d44e2003-12-23 08:09:43 +00001766#ifdef GNU_LINUX
1767int
1768isis_receive (struct thread *thread)
1769{
jardineb5d44e2003-12-23 08:09:43 +00001770 struct isis_circuit *circuit;
1771 u_char ssnpa[ETH_ALEN];
1772 int retval;
1773
1774 /*
1775 * Get the circuit
1776 */
1777 circuit = THREAD_ARG (thread);
1778 assert (circuit);
1779
1780 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001781 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001782 else
1783 stream_reset (circuit->rcv_stream);
1784
1785 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001786 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001787
1788 if (retval == ISIS_OK)
1789 retval = isis_handle_pdu (circuit, ssnpa);
1790
1791 /*
1792 * prepare for next packet.
1793 */
hassof390d2c2004-09-10 20:48:21 +00001794 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1795 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001796
1797 return retval;
1798}
1799
1800#else
1801int
1802isis_receive (struct thread *thread)
1803{
jardineb5d44e2003-12-23 08:09:43 +00001804 struct isis_circuit *circuit;
1805 u_char ssnpa[ETH_ALEN];
1806 int retval;
1807
1808 /*
1809 * Get the circuit
1810 */
1811 circuit = THREAD_ARG (thread);
1812 assert (circuit);
1813
hassof390d2c2004-09-10 20:48:21 +00001814 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001815
1816 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001817 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001818 else
1819 stream_reset (circuit->rcv_stream);
1820
1821 retval = circuit->rx (circuit, ssnpa);
1822
1823 if (retval == ISIS_OK)
1824 retval = isis_handle_pdu (circuit, ssnpa);
1825
1826 /*
1827 * prepare for next packet.
1828 */
hassof390d2c2004-09-10 20:48:21 +00001829 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1830 listcount
1831 (circuit->area->circuit_list) *
1832 100);
jardineb5d44e2003-12-23 08:09:43 +00001833
1834 return retval;
1835}
1836
1837#endif
1838
1839 /* filling of the fixed isis header */
1840void
1841fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1842{
1843 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1844
1845 hdr->idrp = ISO10589_ISIS;
1846
hassof390d2c2004-09-10 20:48:21 +00001847 switch (pdu_type)
1848 {
1849 case L1_LAN_HELLO:
1850 case L2_LAN_HELLO:
1851 hdr->length = ISIS_LANHELLO_HDRLEN;
1852 break;
1853 case P2P_HELLO:
1854 hdr->length = ISIS_P2PHELLO_HDRLEN;
1855 break;
1856 case L1_LINK_STATE:
1857 case L2_LINK_STATE:
1858 hdr->length = ISIS_LSP_HDR_LEN;
1859 break;
1860 case L1_COMPLETE_SEQ_NUM:
1861 case L2_COMPLETE_SEQ_NUM:
1862 hdr->length = ISIS_CSNP_HDRLEN;
1863 break;
1864 case L1_PARTIAL_SEQ_NUM:
1865 case L2_PARTIAL_SEQ_NUM:
1866 hdr->length = ISIS_PSNP_HDRLEN;
1867 break;
1868 default:
1869 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1870 return;
1871 }
jardineb5d44e2003-12-23 08:09:43 +00001872 hdr->length += ISIS_FIXED_HDR_LEN;
1873 hdr->pdu_type = pdu_type;
1874 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001875 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001876 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001877 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001878}
1879
jardineb5d44e2003-12-23 08:09:43 +00001880/*
1881 * SEND SIDE
1882 */
1883void
1884fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001885 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001886{
hassof390d2c2004-09-10 20:48:21 +00001887 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001888
1889 stream_putc (stream, hdr->idrp);
1890 stream_putc (stream, hdr->length);
1891 stream_putc (stream, hdr->version1);
1892 stream_putc (stream, hdr->id_len);
1893 stream_putc (stream, hdr->pdu_type);
1894 stream_putc (stream, hdr->version2);
1895 stream_putc (stream, hdr->reserved);
1896 stream_putc (stream, hdr->max_area_addrs);
1897
1898 return;
1899}
1900
jardineb5d44e2003-12-23 08:09:43 +00001901int
1902send_hello (struct isis_circuit *circuit, int level)
1903{
1904 struct isis_fixed_hdr fixed_hdr;
1905 struct isis_lan_hello_hdr hello_hdr;
1906 struct isis_p2p_hello_hdr p2p_hello_hdr;
1907
1908 u_int32_t interval;
1909 unsigned long len_pointer, length;
1910 int retval;
1911
hassof390d2c2004-09-10 20:48:21 +00001912 if (circuit->interface->mtu == 0)
1913 {
1914 zlog_warn ("circuit has zero MTU");
1915 return ISIS_WARNING;
1916 }
jardineb5d44e2003-12-23 08:09:43 +00001917
1918 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001919 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001920 else
1921 stream_reset (circuit->snd_stream);
1922
1923 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1924 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001925 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1926 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001927 else
hassof390d2c2004-09-10 20:48:21 +00001928 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1929 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001930 else
hassof390d2c2004-09-10 20:48:21 +00001931 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001932
1933 /*
1934 * Fill LAN Level 1 or 2 Hello PDU header
1935 */
1936 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001937 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001938 circuit->hello_interval[level - 1];
1939 if (interval > USHRT_MAX)
1940 interval = USHRT_MAX;
1941 hello_hdr.circuit_t = circuit->circuit_is_type;
1942 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001943 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001944
hassof390d2c2004-09-10 20:48:21 +00001945 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
1946 len_pointer = stream_get_putp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001947
1948 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001949 if (circuit->circ_type == CIRCUIT_T_P2P)
1950 {
1951 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1952 p2p_hello_hdr.local_id = circuit->circuit_id;
1953 /* FIXME: need better understanding */
1954 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001955 }
hassof390d2c2004-09-10 20:48:21 +00001956 else
1957 {
1958 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1959 if (level == 1 && circuit->u.bc.l1_desig_is)
1960 {
1961 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1962 ISIS_SYS_ID_LEN + 1);
1963 }
1964 else if (level == 2 && circuit->u.bc.l2_desig_is)
1965 {
1966 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1967 ISIS_SYS_ID_LEN + 1);
1968 }
1969 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1970 }
jardineb5d44e2003-12-23 08:09:43 +00001971
1972 /*
1973 * Then the variable length part
1974 */
1975 /* add circuit password */
1976 if (circuit->passwd.type)
1977 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1978 circuit->passwd.passwd, circuit->snd_stream))
1979 return ISIS_WARNING;
1980 /* Area Addresses TLV */
1981 assert (circuit->area);
1982 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1983 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1984 return ISIS_WARNING;
1985
1986 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00001987 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1988 {
1989 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1990 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1991 circuit->snd_stream))
1992 return ISIS_WARNING;
1993 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
1994 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
1995 circuit->snd_stream))
1996 return ISIS_WARNING;
1997 }
jardineb5d44e2003-12-23 08:09:43 +00001998
1999 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002000 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002001 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2002 return ISIS_WARNING;
2003 /* IP interface Address TLV */
2004 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2005 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2006 return ISIS_WARNING;
2007
hassof390d2c2004-09-10 20:48:21 +00002008#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002009 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002010 if (circuit->ipv6_router && circuit->ipv6_link &&
jardineb5d44e2003-12-23 08:09:43 +00002011 circuit->ipv6_link->count > 0)
2012 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2013 return ISIS_WARNING;
2014#endif /* HAVE_IPV6 */
2015
2016 if (circuit->u.bc.pad_hellos)
2017 if (tlv_add_padding (circuit->snd_stream))
2018 return ISIS_WARNING;
2019
2020 length = stream_get_putp (circuit->snd_stream);
2021 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002022 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002023
2024 retval = circuit->tx (circuit, level);
2025 if (retval)
2026 zlog_warn ("sending of LAN Level %d Hello failed", level);
2027
2028 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002029 if (isis->debugs & DEBUG_ADJ_PACKETS)
2030 {
2031 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2032 {
2033 zlog_info ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2034 circuit->area->area_tag, level, circuit->interface->name,
2035 STREAM_SIZE (circuit->snd_stream));
2036 }
2037 else
2038 {
2039 zlog_info ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2040 circuit->area->area_tag, circuit->interface->name,
2041 STREAM_SIZE (circuit->snd_stream));
2042 }
jardineb5d44e2003-12-23 08:09:43 +00002043 }
jardineb5d44e2003-12-23 08:09:43 +00002044
2045 return retval;
2046}
2047
2048int
2049send_lan_hello (struct isis_circuit *circuit, int level)
2050{
hassof390d2c2004-09-10 20:48:21 +00002051 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002052}
2053
2054int
2055send_lan_l1_hello (struct thread *thread)
2056{
jardineb5d44e2003-12-23 08:09:43 +00002057 struct isis_circuit *circuit;
2058 int retval;
2059
2060 circuit = THREAD_ARG (thread);
2061 assert (circuit);
2062 circuit->u.bc.t_send_lan_hello[0] = NULL;
2063
2064 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002065 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002066
2067 retval = send_lan_hello (circuit, 1);
2068
2069 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002070 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2071 send_lan_l1_hello, circuit,
2072 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002073
2074 return retval;
2075}
2076
2077int
2078send_lan_l2_hello (struct thread *thread)
2079{
2080 struct isis_circuit *circuit;
2081 int retval;
2082
2083 circuit = THREAD_ARG (thread);
2084 assert (circuit);
2085 circuit->u.bc.t_send_lan_hello[1] = NULL;
2086
2087 if (circuit->u.bc.run_dr_elect[1])
2088 retval = isis_dr_elect (circuit, 2);
2089
2090 retval = send_lan_hello (circuit, 2);
2091
hassof390d2c2004-09-10 20:48:21 +00002092 /* set next timer thread */
2093 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2094 send_lan_l2_hello, circuit,
2095 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002096
2097 return retval;
2098}
2099
2100int
2101send_p2p_hello (struct thread *thread)
2102{
2103 struct isis_circuit *circuit;
2104
2105 circuit = THREAD_ARG (thread);
2106 assert (circuit);
2107 circuit->u.p2p.t_send_p2p_hello = NULL;
2108
hassof390d2c2004-09-10 20:48:21 +00002109 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002110
hassof390d2c2004-09-10 20:48:21 +00002111 /* set next timer thread */
2112 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2113 circuit, isis_jitter (circuit->hello_interval[1],
2114 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002115
2116 return ISIS_OK;
2117}
2118
2119int
hassof390d2c2004-09-10 20:48:21 +00002120build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2121 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002122{
2123 struct isis_fixed_hdr fixed_hdr;
2124 struct isis_passwd *passwd;
2125 int retval = ISIS_OK;
2126 unsigned long lenp;
2127 u_int16_t length;
2128
hassof390d2c2004-09-10 20:48:21 +00002129 if (level == 1)
2130 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2131 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002132 else
hassof390d2c2004-09-10 20:48:21 +00002133 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2134 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002135
2136 /*
2137 * Fill Level 1 or 2 Complete Sequence Numbers header
2138 */
2139
2140 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002141 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002142 /* no need to send the source here, it is always us if we csnp */
2143 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2144 /* with zero circuit id - ref 9.10, 9.11 */
2145 stream_putc (circuit->snd_stream, 0x00);
2146
2147 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2148 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2149
2150 /*
2151 * And TLVs
2152 */
2153 if (level == 1)
2154 passwd = &circuit->area->area_passwd;
2155 else
2156 passwd = &circuit->area->domain_passwd;
2157
2158 if (passwd->type)
2159 retval = tlv_add_authinfo (passwd->type, passwd->len,
2160 passwd->passwd, circuit->snd_stream);
2161
hassof390d2c2004-09-10 20:48:21 +00002162 if (!retval && lsps)
2163 {
2164 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2165 }
2166 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002167 assert (length >= ISIS_CSNP_HDRLEN);
2168 /* Update PU length */
2169 stream_putw_at (circuit->snd_stream, lenp, length);
2170
2171 return retval;
2172}
2173
2174/*
2175 * FIXME: support multiple CSNPs
2176 */
2177
2178int
2179send_csnp (struct isis_circuit *circuit, int level)
2180{
2181 int retval = ISIS_OK;
2182 u_char start[ISIS_SYS_ID_LEN + 2];
2183 u_char stop[ISIS_SYS_ID_LEN + 2];
2184 struct list *list = NULL;
2185 struct listnode *node;
2186 struct isis_lsp *lsp;
2187
hassof390d2c2004-09-10 20:48:21 +00002188 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002189 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2190
hassof390d2c2004-09-10 20:48:21 +00002191 if (circuit->area->lspdb[level - 1] &&
2192 dict_count (circuit->area->lspdb[level - 1]) > 0)
2193 {
2194 list = list_new ();
2195 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002196
hassof390d2c2004-09-10 20:48:21 +00002197 if (circuit->snd_stream == NULL)
2198 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2199 else
2200 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002201
hassof390d2c2004-09-10 20:48:21 +00002202 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002203
hassof390d2c2004-09-10 20:48:21 +00002204 if (isis->debugs & DEBUG_SNP_PACKETS)
2205 {
2206 zlog_info ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2207 circuit->area->area_tag, level, circuit->interface->name,
2208 STREAM_SIZE (circuit->snd_stream));
2209 LIST_LOOP (list, lsp, node)
2210 {
2211 zlog_info ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2212 " cksum 0x%04x, lifetime %us",
2213 circuit->area->area_tag,
2214 rawlspid_print (lsp->lsp_header->lsp_id),
2215 ntohl (lsp->lsp_header->seq_num),
2216 ntohs (lsp->lsp_header->checksum),
2217 ntohs (lsp->lsp_header->rem_lifetime));
2218 }
2219 }
2220
2221 list_delete (list);
2222
2223 if (retval == ISIS_OK)
2224 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002225 }
jardineb5d44e2003-12-23 08:09:43 +00002226 return retval;
2227}
2228
2229int
2230send_l1_csnp (struct thread *thread)
2231{
2232 struct isis_circuit *circuit;
2233 int retval = ISIS_OK;
2234
2235 circuit = THREAD_ARG (thread);
2236 assert (circuit);
2237
2238 circuit->t_send_csnp[0] = NULL;
2239
hassof390d2c2004-09-10 20:48:21 +00002240 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2241 {
2242 send_csnp (circuit, 1);
2243 }
jardineb5d44e2003-12-23 08:09:43 +00002244 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002245 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2246 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002247
2248 return retval;
2249}
2250
2251int
2252send_l2_csnp (struct thread *thread)
2253{
2254 struct isis_circuit *circuit;
2255 int retval = ISIS_OK;
2256
2257 circuit = THREAD_ARG (thread);
2258 assert (circuit);
2259
2260 circuit->t_send_csnp[1] = NULL;
2261
hassof390d2c2004-09-10 20:48:21 +00002262 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2263 {
2264 send_csnp (circuit, 2);
2265 }
jardineb5d44e2003-12-23 08:09:43 +00002266 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002267 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2268 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002269
jardineb5d44e2003-12-23 08:09:43 +00002270 return retval;
2271}
2272
2273int
2274build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2275{
2276 struct isis_fixed_hdr fixed_hdr;
2277 unsigned long lenp;
2278 u_int16_t length;
2279 int retval = 0;
2280 struct isis_lsp *lsp;
2281 struct isis_passwd *passwd;
2282 struct listnode *node;
2283
2284 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002285 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2286 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002287 else
2288 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002289 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 /*
2292 * Fill Level 1 or 2 Partial Sequence Numbers header
2293 */
2294 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002295 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002296 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2297 stream_putc (circuit->snd_stream, circuit->idx);
2298
2299 /*
2300 * And TLVs
2301 */
2302
2303 if (level == 1)
2304 passwd = &circuit->area->area_passwd;
2305 else
2306 passwd = &circuit->area->domain_passwd;
2307
2308 if (passwd->type)
2309 retval = tlv_add_authinfo (passwd->type, passwd->len,
2310 passwd->passwd, circuit->snd_stream);
2311
hassof390d2c2004-09-10 20:48:21 +00002312 if (!retval && lsps)
2313 {
2314 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002315 }
jardineb5d44e2003-12-23 08:09:43 +00002316
hassof390d2c2004-09-10 20:48:21 +00002317 if (isis->debugs & DEBUG_SNP_PACKETS)
2318 {
2319 LIST_LOOP (lsps, lsp, node)
2320 {
2321 zlog_info ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2322 " cksum 0x%04x, lifetime %us",
2323 circuit->area->area_tag,
2324 rawlspid_print (lsp->lsp_header->lsp_id),
2325 ntohl (lsp->lsp_header->seq_num),
2326 ntohs (lsp->lsp_header->checksum),
2327 ntohs (lsp->lsp_header->rem_lifetime));
2328 }
2329 }
2330
2331 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002332 assert (length >= ISIS_PSNP_HDRLEN);
2333 /* Update PDU length */
2334 stream_putw_at (circuit->snd_stream, lenp, length);
2335
2336 return ISIS_OK;
2337}
2338
2339/*
2340 * 7.3.15.4 action on expiration of partial SNP interval
2341 * level 1
2342 */
2343int
2344send_psnp (int level, struct isis_circuit *circuit)
2345{
2346 int retval = ISIS_OK;
2347 struct isis_lsp *lsp;
2348 struct list *list = NULL;
2349 struct listnode *node;
2350
hassof390d2c2004-09-10 20:48:21 +00002351 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002352 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002353 circuit->circ_type != CIRCUIT_T_BROADCAST)
2354 {
jardineb5d44e2003-12-23 08:09:43 +00002355
hassof390d2c2004-09-10 20:48:21 +00002356 if (circuit->area->lspdb[level - 1] &&
2357 dict_count (circuit->area->lspdb[level - 1]) > 0)
2358 {
2359 list = list_new ();
2360 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002361
hassof390d2c2004-09-10 20:48:21 +00002362 if (listcount (list) > 0)
2363 {
2364 if (circuit->snd_stream == NULL)
2365 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2366 else
2367 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002368
2369
hassof390d2c2004-09-10 20:48:21 +00002370 if (isis->debugs & DEBUG_SNP_PACKETS)
2371 zlog_info ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2372 circuit->area->area_tag, level,
2373 circuit->interface->name,
2374 STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002375
hassof390d2c2004-09-10 20:48:21 +00002376 retval = build_psnp (level, circuit, list);
2377 if (retval == ISIS_OK)
2378 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002379
hassof390d2c2004-09-10 20:48:21 +00002380 if (retval == ISIS_OK)
2381 {
2382 /*
2383 * sending succeeded, we can clear SSN flags of this circuit
2384 * for the LSPs in list
2385 */
2386 for (node = listhead (list); node; nextnode (node))
2387 {
2388 lsp = getdata (node);
2389 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2390 }
2391 }
2392 }
2393 list_delete (list);
2394 }
jardineb5d44e2003-12-23 08:09:43 +00002395 }
jardineb5d44e2003-12-23 08:09:43 +00002396
2397 return retval;
2398}
2399
2400int
2401send_l1_psnp (struct thread *thread)
2402{
2403
2404 struct isis_circuit *circuit;
2405 int retval = ISIS_OK;
2406
2407 circuit = THREAD_ARG (thread);
2408 assert (circuit);
2409
2410 circuit->t_send_psnp[0] = NULL;
2411
2412 send_psnp (1, circuit);
2413 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002414 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2415 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002416
2417 return retval;
2418}
2419
2420/*
2421 * 7.3.15.4 action on expiration of partial SNP interval
2422 * level 2
2423 */
2424int
2425send_l2_psnp (struct thread *thread)
2426{
jardineb5d44e2003-12-23 08:09:43 +00002427 struct isis_circuit *circuit;
2428 int retval = ISIS_OK;
2429
2430 circuit = THREAD_ARG (thread);
2431 assert (circuit);
2432
2433 circuit->t_send_psnp[1] = NULL;
2434
2435 send_psnp (2, circuit);
2436
2437 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002438 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2439 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002440
2441 return retval;
2442}
2443
jardineb5d44e2003-12-23 08:09:43 +00002444void
2445build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit,
hassof390d2c2004-09-10 20:48:21 +00002446 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002447{
2448 unsigned long length;
2449
hassof390d2c2004-09-10 20:48:21 +00002450 stream_put (stream, lsp->pdu, ntohs (lsp->lsp_header->pdu_len));
2451 length = stream_get_putp (stream);
jardineb5d44e2003-12-23 08:09:43 +00002452
2453 return;
2454}
2455
jardineb5d44e2003-12-23 08:09:43 +00002456/*
2457 * ISO 10589 - 7.3.14.3
2458 */
2459int
2460send_lsp (struct thread *thread)
2461{
2462 struct isis_circuit *circuit;
2463 struct isis_lsp *lsp;
2464 struct listnode *node;
2465 int retval = 0;
2466
2467 circuit = THREAD_ARG (thread);
2468 assert (circuit);
2469
hassof390d2c2004-09-10 20:48:21 +00002470 if (circuit->state == C_STATE_UP)
2471 {
2472 node = listhead (circuit->lsp_queue);
2473 assert (node);
jardineb5d44e2003-12-23 08:09:43 +00002474
hassof390d2c2004-09-10 20:48:21 +00002475 lsp = getdata (node);
jardineb5d44e2003-12-23 08:09:43 +00002476
2477 /*
hassof390d2c2004-09-10 20:48:21 +00002478 * Do not send if levels do not match
jardineb5d44e2003-12-23 08:09:43 +00002479 */
hassof390d2c2004-09-10 20:48:21 +00002480 if (!(lsp->level & circuit->circuit_is_type))
2481 goto dontsend;
jardineb5d44e2003-12-23 08:09:43 +00002482
hassof390d2c2004-09-10 20:48:21 +00002483 /*
2484 * Do not send if we do not have adjacencies in state up on the circuit
2485 */
2486 if (circuit->upadjcount[lsp->level - 1] == 0)
2487 goto dontsend;
2488 /* only send if it needs sending */
2489 if ((time (NULL) - lsp->last_sent) >=
2490 circuit->area->lsp_gen_interval[lsp->level - 1])
2491 {
jardineb5d44e2003-12-23 08:09:43 +00002492
hassof390d2c2004-09-10 20:48:21 +00002493 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2494 {
2495 zlog_info
2496 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2497 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2498 rawlspid_print (lsp->lsp_header->lsp_id),
2499 ntohl (lsp->lsp_header->seq_num),
2500 ntohs (lsp->lsp_header->checksum),
2501 ntohs (lsp->lsp_header->rem_lifetime),
2502 circuit->interface->name);
2503 }
2504 /* copy our lsp to the send buffer */
2505 circuit->snd_stream->getp = lsp->pdu->getp;
2506 circuit->snd_stream->putp = lsp->pdu->putp;
2507 circuit->snd_stream->endp = lsp->pdu->endp;
2508 memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp);
2509
2510 retval = circuit->tx (circuit, lsp->level);
2511
jardineb5d44e2003-12-23 08:09:43 +00002512 /*
hassof390d2c2004-09-10 20:48:21 +00002513 * If the sending succeeded, we can del the lsp from circuits
2514 * lsp_queue
jardineb5d44e2003-12-23 08:09:43 +00002515 */
hassof390d2c2004-09-10 20:48:21 +00002516 if (retval == ISIS_OK)
2517 {
2518 list_delete_node (circuit->lsp_queue, node);
2519
2520 /*
2521 * On broadcast circuits also the SRMflag can be cleared
2522 */
2523 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2524 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2525
2526 if (flags_any_set (lsp->SRMflags) == 0)
2527 {
2528 /*
2529 * need to remember when we were last sent
2530 */
2531 lsp->last_sent = time (NULL);
2532 }
2533 }
2534 else
2535 {
2536 zlog_info ("sending of level %d link state failed", lsp->level);
2537 }
jardineb5d44e2003-12-23 08:09:43 +00002538 }
hassof390d2c2004-09-10 20:48:21 +00002539 else
2540 {
2541 /* my belief is that if it wasn't his time, the lsp can be removed
2542 * from the queue
2543 */
2544 dontsend:
2545 list_delete_node (circuit->lsp_queue, node);
2546 }
jardineb5d44e2003-12-23 08:09:43 +00002547#if 0
hassof390d2c2004-09-10 20:48:21 +00002548 /*
2549 * If there are still LSPs send next one after lsp-interval (33 msecs)
2550 */
2551 if (listcount (circuit->lsp_queue) > 0)
2552 thread_add_timer (master, send_lsp, circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002553#endif
hassof390d2c2004-09-10 20:48:21 +00002554 }
jardineb5d44e2003-12-23 08:09:43 +00002555
2556 return retval;
hassof390d2c2004-09-10 20:48:21 +00002557}
jardineb5d44e2003-12-23 08:09:43 +00002558
2559int
hassof390d2c2004-09-10 20:48:21 +00002560ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2561 int level)
jardineb5d44e2003-12-23 08:09:43 +00002562{
2563 unsigned long lenp;
2564 int retval;
2565 u_int16_t length;
2566 struct isis_fixed_hdr fixed_hdr;
2567
2568 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002569 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002570 else
2571 stream_reset (circuit->snd_stream);
2572
2573// fill_llc_hdr (stream);
2574 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002575 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2576 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002577 else
hassof390d2c2004-09-10 20:48:21 +00002578 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2579 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002580
2581
2582 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002583 stream_putw (circuit->snd_stream, 0); /* PDU length */
2584 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002585 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002586 stream_putc (circuit->snd_stream, 9); /* code */
2587 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002588
hassof390d2c2004-09-10 20:48:21 +00002589 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2590 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2591 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2592 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002593
hassof390d2c2004-09-10 20:48:21 +00002594 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002595 /* Update PDU length */
2596 stream_putw_at (circuit->snd_stream, lenp, length);
2597
2598 retval = circuit->tx (circuit, level);
2599
2600 return retval;
2601}
2602
2603#if 0
2604/*
2605 * ISH PDU Processing
2606 */
2607
jardineb5d44e2003-12-23 08:09:43 +00002608 /*
2609 * Let's first check if the local and remote system have any common area
2610 * addresses
2611 */
hassof390d2c2004-09-10 20:48:21 +00002612if (area_match (tlvs.area_addrs, isis->man_area_addrs) == 0)
2613 {
2614 if (circuit->circuit_t == IS_LEVEL_2)
2615 {
2616 /* do as in table 8 (p. 40) */
2617 switch (circuit_type)
2618 {
2619 case IS_LEVEL_1:
2620 if (adj->adj_state != ISIS_ADJ_UP)
2621 {
2622 /* Reject */
2623 zlog_warn ("areaMismatch");
2624 retval = ISIS_WARNING;
2625 }
2626 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2627 {
2628 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2629 circuit->adjdb);
2630 }
2631 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 ||
2632 adj->adj_usage == ISIS_ADJ_LEVEL2)
2633 {
2634 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2635 circuit->adjdb);
2636 }
2637 break;
2638 case IS_LEVEL_2:
2639 if (adj->adj_state != ISIS_ADJ_UP)
2640 {
2641 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2642 circuit->adjdb);
2643 adj->adj_usage = ISIS_ADJ_LEVEL2;
2644 }
2645 else if (adj->adj_usage == ISIS_ADJ_LEVEL1 ||
2646 adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2647 {
2648 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2649 circuit->adjdb);
2650 }
2651 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2652 {
2653 ; /* Accept */
2654 }
2655 break;
2656 case IS_LEVEL_1_AND_2:
2657 if (adj->adj_state != ISIS_ADJ_UP)
2658 {
2659 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2660 circuit->adjdb);
2661 adj->adj_usage = ISIS_ADJ_LEVEL2;
2662 }
2663 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2664 {
2665 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2666 circuit->adjdb);
2667 }
2668 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2669 {
2670 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2671 circuit->adjdb);
2672 }
2673 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2674 {
2675 ; /* Accept */
2676 }
2677 break;
2678 }
2679 goto mismatch;
jardineb5d44e2003-12-23 08:09:43 +00002680 }
hassof390d2c2004-09-10 20:48:21 +00002681 else
2682 {
2683 isis_delete_adj (adj, circuit->adjdb);
2684 zlog_warn ("areaMismatch");
2685 return ISIS_WARNING;
2686 }
jardineb5d44e2003-12-23 08:09:43 +00002687 }
2688
2689mismatch:
2690#endif