blob: cae346109015998ece08d5ce8bdaa3af2b424292 [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;
109 int shift, offset;
110 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;
117 offset = len / PNBBY;
118
hassof390d2c2004-09-10 20:48:21 +0000119 while (offset--)
120 {
121 if (addr1[offset] != addr2[offset])
122 {
123 return 0;
124 }
jardineb5d44e2003-12-23 08:09:43 +0000125 }
jardineb5d44e2003-12-23 08:09:43 +0000126
hassof390d2c2004-09-10 20:48:21 +0000127 if (shift)
128 {
129 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
130 {
131 return 0;
132 }
jardineb5d44e2003-12-23 08:09:43 +0000133 }
hassof390d2c2004-09-10 20:48:21 +0000134
135 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000136}
137
jardineb5d44e2003-12-23 08:09:43 +0000138/*
139 * Compares two set of ip addresses
140 * param left the local interface's ip addresses
141 * param right the iih interface's ip address
142 * return 0 no match;
143 * 1 match;
144 */
hassof390d2c2004-09-10 20:48:21 +0000145static int
jardineb5d44e2003-12-23 08:09:43 +0000146ip_match (struct list *left, struct list *right)
147{
148 struct prefix_ipv4 *ip1;
149 struct in_addr *ip2;
150 struct listnode *node1, *node2;
151
hassof390d2c2004-09-10 20:48:21 +0000152 LIST_LOOP (left, ip1, node1)
153 {
154 LIST_LOOP (right, ip2, node2)
155 {
156 if (ip_same_subnet (ip1, ip2))
157 {
158 return 1; /* match */
159 }
jardineb5d44e2003-12-23 08:09:43 +0000160 }
hassof390d2c2004-09-10 20:48:21 +0000161
jardineb5d44e2003-12-23 08:09:43 +0000162 }
163 return 0;
164}
165
166/*
167 * Checks whether we should accept a PDU of given level
168 */
169static int
170accept_level (int level, int circuit_t)
171{
hassof390d2c2004-09-10 20:48:21 +0000172 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000173
174 return retval;
175}
176
hassof390d2c2004-09-10 20:48:21 +0000177int
jardineb5d44e2003-12-23 08:09:43 +0000178authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
179{
hassof390d2c2004-09-10 20:48:21 +0000180 if (one->type != theother->type)
181 {
182 zlog_warn ("Unsupported authentication type %d", theother->type);
183 return 1; /* Auth fail (different authentication types) */
184 }
185 switch (one->type)
186 {
187 case ISIS_PASSWD_TYPE_CLEARTXT:
188 if (one->len != theother->len)
189 return 1; /* Auth fail () - passwd len mismatch */
190 return memcmp (one->passwd, theother->passwd, one->len);
191 break;
192 default:
193 zlog_warn ("Unsupported authentication type");
194 break;
195 }
196 return 0; /* Auth pass */
jardineb5d44e2003-12-23 08:09:43 +0000197}
198
199/*
200 * Processing helper functions
201 */
202void
hassof390d2c2004-09-10 20:48:21 +0000203tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000204{
205 int i;
206 struct nlpids *tlv_nlpids;
207
hassof390d2c2004-09-10 20:48:21 +0000208 if (tlvs->nlpids)
209 {
jardineb5d44e2003-12-23 08:09:43 +0000210
hassof390d2c2004-09-10 20:48:21 +0000211 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000212
hassof390d2c2004-09-10 20:48:21 +0000213 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000214
hassof390d2c2004-09-10 20:48:21 +0000215 for (i = 0; i < tlv_nlpids->count; i++)
216 {
217 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
218 }
jardineb5d44e2003-12-23 08:09:43 +0000219 }
jardineb5d44e2003-12-23 08:09:43 +0000220}
221
hassof390d2c2004-09-10 20:48:21 +0000222void
jardineb5d44e2003-12-23 08:09:43 +0000223del_ip_addr (void *val)
224{
225 XFREE (MTYPE_ISIS_TMP, val);
226}
227
228void
hassof390d2c2004-09-10 20:48:21 +0000229tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000230{
231 struct listnode *node;
232 struct in_addr *ipv4_addr, *malloced;
233
hassof390d2c2004-09-10 20:48:21 +0000234 if (adj->ipv4_addrs)
235 {
236 adj->ipv4_addrs->del = del_ip_addr;
237 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000238 }
hassof390d2c2004-09-10 20:48:21 +0000239 adj->ipv4_addrs = list_new ();
240 if (tlvs->ipv4_addrs)
241 {
242 LIST_LOOP (tlvs->ipv4_addrs, ipv4_addr, node)
243 {
244 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
245 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
246 listnode_add (adj->ipv4_addrs, malloced);
247 }
248 }
jardineb5d44e2003-12-23 08:09:43 +0000249}
250
251#ifdef HAVE_IPV6
252void
hassof390d2c2004-09-10 20:48:21 +0000253tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000254{
255 struct listnode *node;
256 struct in6_addr *ipv6_addr, *malloced;
257
hassof390d2c2004-09-10 20:48:21 +0000258 if (adj->ipv6_addrs)
259 {
260 adj->ipv6_addrs->del = del_ip_addr;
261 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000262 }
hassof390d2c2004-09-10 20:48:21 +0000263 adj->ipv6_addrs = list_new ();
264 if (tlvs->ipv6_addrs)
265 {
266 LIST_LOOP (tlvs->ipv6_addrs, ipv6_addr, node)
267 {
268 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
269 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
270 listnode_add (adj->ipv6_addrs, malloced);
271 }
272 }
jardineb5d44e2003-12-23 08:09:43 +0000273
274}
275#endif /* HAVE_IPV6 */
276
jardineb5d44e2003-12-23 08:09:43 +0000277/*
278 * RECEIVE SIDE
279 */
280
281/*
282 * Process P2P IIH
283 * ISO - 10589
284 * Section 8.2.5 - Receiving point-to-point IIH PDUs
285 *
286 */
287static int
288process_p2p_hello (struct isis_circuit *circuit)
289{
290 int retval = ISIS_OK;
291 struct isis_p2p_hello_hdr *hdr;
292 struct isis_adjacency *adj;
293 u_int32_t expected = 0, found;
294 struct tlvs tlvs;
295
hassof390d2c2004-09-10 20:48:21 +0000296 if ((stream_get_endp (circuit->rcv_stream) -
297 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
298 {
299 zlog_warn ("Packet too short");
300 return ISIS_WARNING;
301 }
jardineb5d44e2003-12-23 08:09:43 +0000302
303 /* 8.2.5.1 PDU acceptance tests */
304
305 /* 8.2.5.1 a) external domain untrue */
306 /* FIXME: not useful at all? */
307
308 /* 8.2.5.1 b) ID Length mismatch */
309 /* checked at the handle_pdu */
310
311 /* 8.2.5.2 IIH PDU Processing */
312
313 /* 8.2.5.2 a) 1) Maximum Area Addresses */
314 /* Already checked, and can also be ommited */
315
316 /*
317 * Get the header
318 */
hassof390d2c2004-09-10 20:48:21 +0000319 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000320 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
321
322 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000323 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
324 hdr.hold_time = stream_getw (stream);
325 hdr.pdu_len = stream_getw (stream);
326 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000327
328 /*
329 * My interpertation of the ISO, if no adj exists we will create one for
330 * the circuit
331 */
332
hassof390d2c2004-09-10 20:48:21 +0000333 if (isis->debugs & DEBUG_ADJ_PACKETS)
334 {
335 zlog_info ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
336 " cir id %02d, length %d",
337 circuit->area->area_tag, circuit->interface->name,
338 circuit_t2string (circuit->circuit_is_type),
339 circuit->circuit_id, ntohs (hdr->pdu_len));
340 }
jardineb5d44e2003-12-23 08:09:43 +0000341
342 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000343 if (!adj)
344 {
345 adj = isis_new_adj (hdr->source_id, " ", 0, circuit);
346 if (adj == NULL)
347 return ISIS_ERROR;
348 circuit->u.p2p.neighbor = adj;
349 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
350 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
351 }
jardineb5d44e2003-12-23 08:09:43 +0000352
353 /* 8.2.6 Monitoring point-to-point adjacencies */
354 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000355 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000356
357 /*
358 * Lets get the TLVS now
359 */
360 expected |= TLVFLAG_AREA_ADDRS;
361 expected |= TLVFLAG_AUTH_INFO;
362 expected |= TLVFLAG_NLPID;
363 expected |= TLVFLAG_IPV4_ADDR;
364 expected |= TLVFLAG_IPV6_ADDR;
365
366 retval = parse_tlvs (circuit->area->area_tag,
367 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000368 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
369 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000370
hassof390d2c2004-09-10 20:48:21 +0000371 if (retval > ISIS_WARNING)
372 {
373 free_tlvs (&tlvs);
374 return retval;
375 };
jardineb5d44e2003-12-23 08:09:43 +0000376
377 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000378 if (circuit->passwd.type)
379 {
380 if (!(found & TLVFLAG_AUTH_INFO) ||
381 authentication_check (&circuit->passwd, &tlvs.auth_info))
382 {
383 isis_event_auth_failure (circuit->area->area_tag,
384 "P2P hello authentication failure",
385 hdr->source_id);
386 return ISIS_OK;
387 }
jardineb5d44e2003-12-23 08:09:43 +0000388 }
jardineb5d44e2003-12-23 08:09:43 +0000389
390 /* we do this now because the adj may not survive till the end... */
391
392 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000393 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000394
395#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000396 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000397#endif /* HAVE_IPV6 */
398
399 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000400 THREAD_TIMER_OFF (adj->t_expire);
401 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
402 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000403
404 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000405 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
406 {
407 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
408 if (circuit->area->is_type == IS_LEVEL_1)
409 {
410 switch (hdr->circuit_t)
411 {
412 case IS_LEVEL_1:
413 case IS_LEVEL_1_AND_2:
414 if (adj->adj_state != ISIS_ADJ_UP)
415 {
416 /* (4) adj state up */
417 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
418 /* (5) adj usage level 1 */
419 adj->adj_usage = ISIS_ADJ_LEVEL1;
420 }
421 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
422 {
423 ; /* accept */
424 }
425 break;
426 case IS_LEVEL_2:
427 if (adj->adj_state != ISIS_ADJ_UP)
428 {
429 /* (7) reject - wrong system type event */
430 zlog_warn ("wrongSystemType");
431 return ISIS_WARNING; /* Reject */
432 }
433 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
434 {
435 /* (6) down - wrong system */
436 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
437 }
438 break;
439 }
440 }
jardineb5d44e2003-12-23 08:09:43 +0000441
hassof390d2c2004-09-10 20:48:21 +0000442 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
443 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
444 {
445 switch (hdr->circuit_t)
446 {
447 case IS_LEVEL_1:
448 if (adj->adj_state != ISIS_ADJ_UP)
449 {
450 /* (6) adj state up */
451 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
452 /* (7) adj usage level 1 */
453 adj->adj_usage = ISIS_ADJ_LEVEL1;
454 }
455 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
456 {
457 ; /* accept */
458 }
459 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
460 (adj->adj_usage == ISIS_ADJ_LEVEL2))
461 {
462 /* (8) down - wrong system */
463 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
464 }
465 break;
466 case IS_LEVEL_2:
467 if (adj->adj_state != ISIS_ADJ_UP)
468 {
469 /* (6) adj state up */
470 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
471 /* (9) adj usage level 2 */
472 adj->adj_usage = ISIS_ADJ_LEVEL2;
473 }
474 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
475 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
476 {
477 /* (8) down - wrong system */
478 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
479 }
480 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
481 {
482 ; /* Accept */
483 }
484 break;
485 case IS_LEVEL_1_AND_2:
486 if (adj->adj_state != ISIS_ADJ_UP)
487 {
488 /* (6) adj state up */
489 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
490 /* (10) adj usage level 1 */
491 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
492 }
493 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
494 (adj->adj_usage == ISIS_ADJ_LEVEL2))
495 {
496 /* (8) down - wrong system */
497 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
498 }
499 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
500 {
501 ; /* Accept */
502 }
503 break;
504 }
505 }
jardineb5d44e2003-12-23 08:09:43 +0000506
hassof390d2c2004-09-10 20:48:21 +0000507 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
508 if (circuit->area->is_type == IS_LEVEL_2)
509 {
510 switch (hdr->circuit_t)
511 {
512 case IS_LEVEL_1:
513 if (adj->adj_state != ISIS_ADJ_UP)
514 {
515 /* (5) reject - wrong system type event */
516 zlog_warn ("wrongSystemType");
517 return ISIS_WARNING; /* Reject */
518 }
519 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
520 (adj->adj_usage == ISIS_ADJ_LEVEL2))
521 {
522 /* (6) down - wrong system */
523 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
524 }
525 break;
526 case IS_LEVEL_1_AND_2:
527 case IS_LEVEL_2:
528 if (adj->adj_state != ISIS_ADJ_UP)
529 {
530 /* (7) adj state up */
531 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
532 /* (8) adj usage level 2 */
533 adj->adj_usage = ISIS_ADJ_LEVEL2;
534 }
535 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
536 {
537 /* (6) down - wrong system */
538 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
539 }
540 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
541 {
542 ; /* Accept */
543 }
544 break;
545 }
546 }
jardineb5d44e2003-12-23 08:09:43 +0000547 }
jardineb5d44e2003-12-23 08:09:43 +0000548 /* 8.2.5.2 b) if no match was detected */
549 else
jardineb5d44e2003-12-23 08:09:43 +0000550 {
hassof390d2c2004-09-10 20:48:21 +0000551 if (circuit->area->is_type == IS_LEVEL_1)
552 {
553 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
554 if (adj->adj_state != ISIS_ADJ_UP)
555 {
556 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
557 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
558 }
559 else
560 {
561 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
562 "Down - Area Mismatch");
563 }
564 }
565 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
566 else
567 {
568 switch (hdr->circuit_t)
569 {
570 case IS_LEVEL_1:
571 if (adj->adj_state != ISIS_ADJ_UP)
572 {
573 /* (6) reject - Area Mismatch event */
574 zlog_warn ("AreaMismatch");
575 return ISIS_WARNING; /* Reject */
576 }
577 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
578 {
579 /* (7) down - area mismatch */
580 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000581
hassof390d2c2004-09-10 20:48:21 +0000582 }
583 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
584 (adj->adj_usage == ISIS_ADJ_LEVEL2))
585 {
586 /* (7) down - wrong system */
587 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
588 }
589 break;
590 case IS_LEVEL_1_AND_2:
591 case IS_LEVEL_2:
592 if (adj->adj_state != ISIS_ADJ_UP)
593 {
594 /* (8) adj state up */
595 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
596 /* (9) adj usage level 2 */
597 adj->adj_usage = ISIS_ADJ_LEVEL2;
598 }
599 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
600 {
601 /* (7) down - wrong system */
602 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
603 }
604 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
605 {
606 if (hdr->circuit_t == IS_LEVEL_2)
607 {
608 /* (7) down - wrong system */
609 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
610 "Wrong System");
611 }
612 else
613 {
614 /* (7) down - area mismatch */
615 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
616 "Area Mismatch");
617 }
618 }
619 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
620 {
621 ; /* Accept */
622 }
623 break;
624 }
625 }
jardineb5d44e2003-12-23 08:09:43 +0000626 }
jardineb5d44e2003-12-23 08:09:43 +0000627 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
628 /* FIXME - Missing parts */
629
jardineb5d44e2003-12-23 08:09:43 +0000630 /* some of my own understanding of the ISO, why the heck does
631 * it not say what should I change the system_type to...
632 */
hassof390d2c2004-09-10 20:48:21 +0000633 switch (adj->adj_usage)
634 {
jardineb5d44e2003-12-23 08:09:43 +0000635 case ISIS_ADJ_LEVEL1:
636 adj->sys_type = ISIS_SYSTYPE_L1_IS;
637 break;
638 case ISIS_ADJ_LEVEL2:
639 adj->sys_type = ISIS_SYSTYPE_L2_IS;
640 break;
641 case ISIS_ADJ_LEVEL1AND2:
642 adj->sys_type = ISIS_SYSTYPE_L2_IS;
643 break;
644 case ISIS_ADJ_NONE:
645 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
646 break;
hassof390d2c2004-09-10 20:48:21 +0000647 }
jardineb5d44e2003-12-23 08:09:43 +0000648
649 adj->circuit_t = hdr->circuit_t;
650 adj->level = hdr->circuit_t;
651
652 free_tlvs (&tlvs);
653
654 return retval;
655}
656
jardineb5d44e2003-12-23 08:09:43 +0000657/*
658 * Process IS-IS LAN Level 1/2 Hello PDU
659 */
hassof390d2c2004-09-10 20:48:21 +0000660static int
661process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000662{
663 int retval = ISIS_OK;
664 struct isis_lan_hello_hdr hdr;
665 struct isis_adjacency *adj;
666 u_int32_t expected = 0, found;
667 struct tlvs tlvs;
668 u_char *snpa;
669 struct listnode *node;
670
hassof390d2c2004-09-10 20:48:21 +0000671 if ((stream_get_endp (circuit->rcv_stream) -
672 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
673 {
674 zlog_warn ("Packet too short");
675 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000676 }
hassof390d2c2004-09-10 20:48:21 +0000677
678 if (circuit->ext_domain)
679 {
680 zlog_info ("level %d LAN Hello received over circuit with "
681 "externalDomain = true", level);
682 return ISIS_WARNING;
683 }
684
685 if (!accept_level (level, circuit->circuit_is_type))
686 {
687 if (isis->debugs & DEBUG_ADJ_PACKETS)
688 {
689 zlog_info ("ISIS-Adj (%s): Interface level mismatch, %s",
690 circuit->area->area_tag, circuit->interface->name);
691 }
692 return ISIS_WARNING;
693 }
jardineb5d44e2003-12-23 08:09:43 +0000694
695#if 0
696 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000697 if (!accept_level (level, circuit->area->is_type))
698 {
699 if (isis->debugs & DEBUG_ADJ_PACKETS)
700 {
701 zlog_info ("ISIS-Adj (%s): is type mismatch",
702 circuit->area->area_tag);
703 }
704 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000705 }
jardineb5d44e2003-12-23 08:09:43 +0000706#endif
707 /*
708 * Fill the header
709 */
710 hdr.circuit_t = stream_getc (circuit->rcv_stream);
711 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
712 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000713 hdr.pdu_len = stream_getw (circuit->rcv_stream);
714 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000715 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
716
717 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000718 hdr.circuit_t != IS_LEVEL_1_AND_2)
719 {
720 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
721 hdr.circuit_t);
722 return ISIS_ERROR;
723 }
jardineb5d44e2003-12-23 08:09:43 +0000724 /*
725 * Then get the tlvs
726 */
727 expected |= TLVFLAG_AUTH_INFO;
728 expected |= TLVFLAG_AREA_ADDRS;
729 expected |= TLVFLAG_LAN_NEIGHS;
730 expected |= TLVFLAG_NLPID;
731 expected |= TLVFLAG_IPV4_ADDR;
732 expected |= TLVFLAG_IPV6_ADDR;
733
734 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000735 STREAM_PNT (circuit->rcv_stream),
736 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
737 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000738
hassof390d2c2004-09-10 20:48:21 +0000739 if (retval > ISIS_WARNING)
740 {
741 zlog_warn ("parse_tlvs() failed");
742 goto out;
743 }
jardineb5d44e2003-12-23 08:09:43 +0000744
hassof390d2c2004-09-10 20:48:21 +0000745 if (!(found & TLVFLAG_AREA_ADDRS))
746 {
747 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
748 level);
jardineb5d44e2003-12-23 08:09:43 +0000749 retval = ISIS_WARNING;
750 goto out;
751 }
hassof390d2c2004-09-10 20:48:21 +0000752
753 if (circuit->passwd.type)
754 {
755 if (!(found & TLVFLAG_AUTH_INFO) ||
756 authentication_check (&circuit->passwd, &tlvs.auth_info))
757 {
758 isis_event_auth_failure (circuit->area->area_tag,
759 "LAN hello authentication failure",
760 hdr.source_id);
761 retval = ISIS_WARNING;
762 goto out;
763 }
764 }
jardineb5d44e2003-12-23 08:09:43 +0000765
766 /*
767 * Accept the level 1 adjacency only if a match between local and
768 * remote area addresses is found
769 */
hassof390d2c2004-09-10 20:48:21 +0000770 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
771 {
772 if (isis->debugs & DEBUG_ADJ_PACKETS)
773 {
774 zlog_info ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
775 circuit->area->area_tag, level,
776 circuit->interface->name);
777 }
778 retval = ISIS_OK;
779 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000780 }
jardineb5d44e2003-12-23 08:09:43 +0000781
782 /*
783 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000784 */
785 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
786 {
787 zlog_info ("ISIS-Adj (%s): it's own IIH PDU - discarded",
788 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000789
hassof390d2c2004-09-10 20:48:21 +0000790 retval = ISIS_OK;
791 goto out;
792 }
jardineb5d44e2003-12-23 08:09:43 +0000793
794 /*
795 * check if it's own interface ip match iih ip addrs
796 */
hassof390d2c2004-09-10 20:48:21 +0000797 if (!(found & TLVFLAG_IPV4_ADDR)
798 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
799 {
800 zlog_info
801 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
802 circuit->interface->name);
803 retval = ISIS_WARNING;
804 goto out;
805 }
jardineb5d44e2003-12-23 08:09:43 +0000806
807 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000808 if (!adj)
809 {
810 /*
811 * Do as in 8.4.2.5
812 */
813 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
814 if (adj == NULL)
815 retval = ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +0000816 goto out;
817
hassof390d2c2004-09-10 20:48:21 +0000818 adj->level = level;
819 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000820
hassof390d2c2004-09-10 20:48:21 +0000821 if (level == 1)
822 {
823 adj->sys_type = ISIS_SYSTYPE_L1_IS;
824 }
825 else
826 {
827 adj->sys_type = ISIS_SYSTYPE_L2_IS;
828 }
829 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
830 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
831 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000832 }
jardineb5d44e2003-12-23 08:09:43 +0000833
hassof390d2c2004-09-10 20:48:21 +0000834 switch (level)
835 {
836 case 1:
837 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
838 {
839 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
840 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
841 ISIS_SYS_ID_LEN + 1);
842 }
843 break;
844 case 2:
845 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
846 {
847 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
848 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
849 ISIS_SYS_ID_LEN + 1);
850 }
851 break;
jardineb5d44e2003-12-23 08:09:43 +0000852 }
jardineb5d44e2003-12-23 08:09:43 +0000853
854#if 0
hassof390d2c2004-09-10 20:48:21 +0000855 /* Old solution: believe the lan-header always
856 */
857 if (level == 1)
858 {
859 memcpy (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
860 }
861 else if (level == 2)
862 {
863 memcpy (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
864 }
jardineb5d44e2003-12-23 08:09:43 +0000865#endif
866
867 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000868 adj->last_upd = time (NULL);
869 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000870
871 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
872
873 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000874 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000875 tlvs_to_adj_nlpids (&tlvs, adj);
876
877 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000878 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000879 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
880
881#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000882 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000883 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
884#endif /* HAVE_IPV6 */
885
886 adj->circuit_t = hdr.circuit_t;
887
888 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000889 THREAD_TIMER_OFF (adj->t_expire);
890 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
891 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000892
893 /*
894 * If the snpa for this circuit is found from LAN Neighbours TLV
895 * we have two-way communication -> adjacency can be put to state "up"
896 */
897
hassof390d2c2004-09-10 20:48:21 +0000898 if (found & TLVFLAG_LAN_NEIGHS)
899 {
900 if (adj->adj_state != ISIS_ADJ_UP)
901 {
902 LIST_LOOP (tlvs.lan_neighs, snpa, node)
903 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
904 {
905 isis_adj_state_change (adj, ISIS_ADJ_UP,
906 "own SNPA found in LAN Neighbours TLV");
907 }
908 }
jardineb5d44e2003-12-23 08:09:43 +0000909 }
jardineb5d44e2003-12-23 08:09:43 +0000910
hassof390d2c2004-09-10 20:48:21 +0000911out:
jardineb5d44e2003-12-23 08:09:43 +0000912 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000913 if (isis->debugs & DEBUG_ADJ_PACKETS)
914 {
915 /* FIXME: is this place right? fix missing info */
916 zlog_info ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
917 "cirID %u, length %ld",
918 circuit->area->area_tag,
919 level, snpa_print (ssnpa), circuit->interface->name,
920 circuit_t2string (circuit->circuit_is_type),
921 circuit->circuit_id, stream_get_endp (circuit->rcv_stream));
922 }
jardineb5d44e2003-12-23 08:09:43 +0000923
924 free_tlvs (&tlvs);
925
926 return retval;
927}
928
929/*
930 * Process Level 1/2 Link State
931 * ISO - 10589
932 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000933 */
934static int
935process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000936{
937 struct isis_link_state_hdr *hdr;
938 struct isis_adjacency *adj = NULL;
939 struct isis_lsp *lsp, *lsp0 = NULL;
940 int retval = ISIS_OK, comp = 0;
941 u_char lspid[ISIS_SYS_ID_LEN + 2];
942 struct isis_passwd *passwd;
943
944 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000945 if ((stream_get_endp (circuit->rcv_stream) -
946 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
947 {
948 zlog_warn ("Packet too short");
949 return ISIS_WARNING;
950 }
jardineb5d44e2003-12-23 08:09:43 +0000951
952 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000953 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000954
hassof390d2c2004-09-10 20:48:21 +0000955 if (isis->debugs & DEBUG_UPDATE_PACKETS)
956 {
957 zlog_info ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
958 "lifetime %us, len %lu, on %s",
959 circuit->area->area_tag,
960 level,
961 rawlspid_print (hdr->lsp_id),
962 ntohl (hdr->seq_num),
963 ntohs (hdr->checksum),
964 ntohs (hdr->rem_lifetime),
965 circuit->rcv_stream->endp, circuit->interface->name);
966 }
jardineb5d44e2003-12-23 08:09:43 +0000967
968 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
969
970 /* Checksum sanity check - FIXME: move to correct place */
971 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000972 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
973 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
974 {
975 zlog_info ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
976 circuit->area->area_tag,
977 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000978
hassof390d2c2004-09-10 20:48:21 +0000979 return ISIS_WARNING;
980 }
jardineb5d44e2003-12-23 08:09:43 +0000981
982 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000983 if (circuit->ext_domain)
984 {
985 zlog_info
986 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
987 "externalDomain = true", circuit->area->area_tag,
988 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000989
hassof390d2c2004-09-10 20:48:21 +0000990 return ISIS_WARNING;
991 }
jardineb5d44e2003-12-23 08:09:43 +0000992
993 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000994 if (!accept_level (level, circuit->circuit_is_type))
995 {
996 zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
997 " type %s",
998 circuit->area->area_tag,
999 rawlspid_print (hdr->lsp_id),
1000 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +00001001
hassof390d2c2004-09-10 20:48:21 +00001002 return ISIS_WARNING;
1003 }
jardineb5d44e2003-12-23 08:09:43 +00001004
1005 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1006
1007 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1008
1009 /* 7.3.15.1 a) 7 - password check */
1010 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
1011 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001012 if (passwd->type)
1013 {
1014 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1015 ntohs (hdr->pdu_len), passwd))
1016 {
1017 isis_event_auth_failure (circuit->area->area_tag,
1018 "LSP authentication failure", hdr->lsp_id);
1019 return ISIS_WARNING;
1020 }
jardineb5d44e2003-12-23 08:09:43 +00001021 }
jardineb5d44e2003-12-23 08:09:43 +00001022 /* Find the LSP in our database and compare it to this Link State header */
1023 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1024 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001025 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1026 hdr->checksum, hdr->rem_lifetime);
1027 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001028#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001029 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001030#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001031 ))
jardineb5d44e2003-12-23 08:09:43 +00001032 goto dontcheckadj;
1033
1034 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1035 /* for broadcast circuits, snpa should be compared */
1036 /* FIXME : Point To Point */
1037
hassof390d2c2004-09-10 20:48:21 +00001038 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1039 {
1040 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1041 if (!adj)
1042 {
1043 zlog_info ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1044 "lifetime %us on %s",
1045 circuit->area->area_tag,
1046 rawlspid_print (hdr->lsp_id),
1047 ntohl (hdr->seq_num),
1048 ntohs (hdr->checksum),
1049 ntohs (hdr->rem_lifetime), circuit->interface->name);
1050 return ISIS_WARNING; /* Silently discard */
1051 }
jardineb5d44e2003-12-23 08:09:43 +00001052 }
jardineb5d44e2003-12-23 08:09:43 +00001053
1054 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001055 else
1056 {
1057 /* If no adj, or no sharing of level */
1058 if (!circuit->u.p2p.neighbor)
1059 {
1060 return ISIS_OK; /* Silently discard */
1061 }
1062 else
1063 {
1064 if (((level == 1) &&
1065 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1066 ((level == 2) &&
1067 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1068 return ISIS_WARNING; /* Silently discard */
1069 }
jardineb5d44e2003-12-23 08:09:43 +00001070 }
hassof390d2c2004-09-10 20:48:21 +00001071dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001072 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1073
1074 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1075
hassof390d2c2004-09-10 20:48:21 +00001076 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001077
hassof390d2c2004-09-10 20:48:21 +00001078 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1079 if (hdr->rem_lifetime == 0)
1080 {
1081 if (!lsp)
1082 {
1083 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1084 /* only needed on explicit update, eg - p2p */
1085 if (circuit->circ_type == CIRCUIT_T_P2P)
1086 ack_lsp (hdr, circuit, level);
1087 return retval; /* FIXME: do we need a purge? */
1088 }
1089 else
1090 {
1091 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1092 {
1093 /* LSP by some other system -> do 7.3.16.4 b) */
1094 /* 7.3.16.4 b) 1) */
1095 if (comp == LSP_NEWER)
1096 {
1097 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1098 /* ii */
1099 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1100 /* iii */
1101 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1102 /* v */
1103 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1104 /* iv */
1105 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1106 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001107
hassof390d2c2004-09-10 20:48:21 +00001108 } /* 7.3.16.4 b) 2) */
1109 else if (comp == LSP_EQUAL)
1110 {
1111 /* i */
1112 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1113 /* ii */
1114 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1115 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1116 } /* 7.3.16.4 b) 3) */
1117 else
1118 {
1119 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1120 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1121 }
1122 }
1123 else
1124 {
1125 /* our own LSP -> 7.3.16.4 c) */
1126 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1127 circuit->circuit_id
1128 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1129 circuit->circuit_id
1130 && circuit->u.bc.is_dr[level - 1] == 1))
1131 {
1132 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1133 zlog_info ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len));
1134 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1135 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1136 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1137 zlog_info
1138 ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1139 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1140 ntohl (lsp->lsp_header->seq_num));
1141 lsp->lsp_header->rem_lifetime =
1142 htons (isis_jitter
1143 (circuit->area->max_lsp_lifetime[level - 1],
1144 MAX_AGE_JITTER));
1145 }
1146 else
1147 {
1148 /* Got purge for own pseudo-lsp, and we are not DR */
1149 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1150 }
1151 }
1152 }
1153 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001154 }
jardineb5d44e2003-12-23 08:09:43 +00001155 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1156 * purge */
hassof390d2c2004-09-10 20:48:21 +00001157 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1158 {
1159 if (!lsp)
1160 {
1161 /* 7.3.16.4: initiate a purge */
1162 lsp_purge_non_exist (hdr, circuit->area);
1163 return ISIS_OK;
1164 }
1165 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1166
1167 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1168 * has information that the current sequence number for source S is
1169 * "greater" than that held by S, ... */
1170
1171 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1172 {
1173 /* 7.3.16.1 */
1174 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1175
1176 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1177 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1178
1179 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1180 zlog_info
1181 ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1182 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1183 ntohl (lsp->lsp_header->seq_num));
1184 lsp->lsp_header->rem_lifetime =
1185 htons (isis_jitter
1186 (circuit->area->max_lsp_lifetime[level - 1],
1187 MAX_AGE_JITTER));
1188 }
jardineb5d44e2003-12-23 08:09:43 +00001189 }
hassof390d2c2004-09-10 20:48:21 +00001190 else
1191 {
1192 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001193
hassof390d2c2004-09-10 20:48:21 +00001194 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1195 if ((!lsp || comp == LSP_NEWER))
1196 {
1197 /* i */
1198 if (lsp)
1199 {
jardineb5d44e2003-12-23 08:09:43 +00001200#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +00001201 zlog_info ("level %d number is - %ld", level,
1202 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001203#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001204 lsp_search_and_destroy (hdr->lsp_id,
1205 circuit->area->lspdb[level - 1]);
1206 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001207#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +00001208 zlog_info ("level %d number is - %ld", level,
1209 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001210#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001211 }
1212 /*
1213 * If this lsp is a frag, need to see if we have zero lsp present
1214 */
1215 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1216 {
1217 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1218 LSP_FRAGMENT (lspid) = 0;
1219 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1220 if (!lsp0)
1221 {
1222 zlog_info ("Got lsp frag, while zero lsp not database");
1223 return ISIS_OK;
1224 }
1225 }
1226 lsp =
1227 lsp_new_from_stream_ptr (circuit->rcv_stream,
1228 ntohs (hdr->pdu_len), lsp0,
1229 circuit->area);
1230 lsp->level = level;
1231 lsp->adj = adj;
1232 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1233 /* ii */
1234 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1235 /* iii */
1236 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001237
hassof390d2c2004-09-10 20:48:21 +00001238 /* iv */
1239 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1240 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1241 /* FIXME: v) */
1242 }
1243 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1244 else if (comp == LSP_EQUAL)
1245 {
1246 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1247 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1248 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1249 {
1250 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1251 }
1252 }
1253 /* 7.3.15.1 e) 3) LSP older than the one in db */
1254 else
1255 {
1256 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1257 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1258 }
jardineb5d44e2003-12-23 08:09:43 +00001259 }
jardineb5d44e2003-12-23 08:09:43 +00001260 if (lsp)
1261 lsp->adj = adj;
1262 return retval;
1263}
1264
1265/*
1266 * Process Sequence Numbers
1267 * ISO - 10589
1268 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1269 */
1270
1271int
hassof390d2c2004-09-10 20:48:21 +00001272process_snp (int snp_type, int level, struct isis_circuit *circuit,
1273 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001274{
1275 int retval = ISIS_OK;
1276 int cmp, own_lsp;
1277 char typechar = ' ';
1278 int len;
1279 struct isis_adjacency *adj;
1280 struct isis_complete_seqnum_hdr *chdr = NULL;
1281 struct isis_partial_seqnum_hdr *phdr = NULL;
1282 uint32_t found = 0, expected = 0;
1283 struct isis_lsp *lsp;
1284 struct lsp_entry *entry;
hassof390d2c2004-09-10 20:48:21 +00001285 struct listnode *node, *node2;
jardineb5d44e2003-12-23 08:09:43 +00001286 struct tlvs tlvs;
1287 struct list *lsp_list = NULL;
1288 struct isis_passwd *passwd;
1289
hassof390d2c2004-09-10 20:48:21 +00001290 if (snp_type == ISIS_SNP_CSNP_FLAG)
1291 {
1292 /* getting the header info */
1293 typechar = 'C';
1294 chdr =
1295 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1296 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1297 len = ntohs (chdr->pdu_len);
1298 if (len < ISIS_CSNP_HDRLEN)
1299 {
1300 zlog_warn ("Received a CSNP with bogus length!");
1301 return ISIS_OK;
1302 }
jardineb5d44e2003-12-23 08:09:43 +00001303 }
hassof390d2c2004-09-10 20:48:21 +00001304 else
1305 {
1306 typechar = 'P';
1307 phdr =
1308 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1309 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1310 len = ntohs (phdr->pdu_len);
1311 if (len < ISIS_PSNP_HDRLEN)
1312 {
1313 zlog_warn ("Received a CSNP with bogus length!");
1314 return ISIS_OK;
1315 }
jardineb5d44e2003-12-23 08:09:43 +00001316 }
jardineb5d44e2003-12-23 08:09:43 +00001317
1318 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001319 if (circuit->ext_domain)
1320 {
jardineb5d44e2003-12-23 08:09:43 +00001321
hassof390d2c2004-09-10 20:48:21 +00001322 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1323 "skipping: circuit externalDomain = true",
jardineb5d44e2003-12-23 08:09:43 +00001324 circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001325 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001326
1327 return ISIS_OK;
1328 }
hassof390d2c2004-09-10 20:48:21 +00001329
1330 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1331 if (!accept_level (level, circuit->circuit_is_type))
1332 {
1333
1334 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1335 "skipping: circuit type %s does not match level %d",
1336 circuit->area->area_tag,
1337 level,
1338 typechar,
1339 circuit->interface->name,
1340 circuit_t2string (circuit->circuit_is_type), level);
1341
1342 return ISIS_OK;
1343 }
1344
1345 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1346 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1347 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1348 {
1349 if (!circuit->u.bc.is_dr[level - 1])
1350 {
1351
1352 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1353 "skipping: we are not the DIS",
1354 circuit->area->area_tag,
1355 level,
1356 typechar, snpa_print (ssnpa), circuit->interface->name);
1357
1358 return ISIS_OK;
1359 }
1360 }
jardineb5d44e2003-12-23 08:09:43 +00001361
1362 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1363
1364 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1365 * - already checked */
1366
1367 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1368 /* for broadcast circuits, snpa should be compared */
1369 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001370 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1371 {
1372 if (snp_type == ISIS_SNP_CSNP_FLAG)
1373 {
1374 adj =
1375 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1376 }
1377 else
1378 {
1379 /* a psnp on a broadcast, how lovely of Juniper :) */
1380 adj =
1381 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1382 }
1383 if (!adj)
1384 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001385 }
hassof390d2c2004-09-10 20:48:21 +00001386 else
1387 {
1388 if (!circuit->u.p2p.neighbor)
1389 return ISIS_OK; /* Silently discard */
1390 }
jardineb5d44e2003-12-23 08:09:43 +00001391
1392 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1393
1394 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1395
1396 memset (&tlvs, 0, sizeof (struct tlvs));
1397
1398 /* parse the SNP */
1399 expected |= TLVFLAG_LSP_ENTRIES;
1400 expected |= TLVFLAG_AUTH_INFO;
1401 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001402 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001403 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001404 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001405
hassof390d2c2004-09-10 20:48:21 +00001406 if (retval > ISIS_WARNING)
1407 {
1408 zlog_warn ("something went very wrong processing SNP");
1409 free_tlvs (&tlvs);
1410 return retval;
1411 }
jardineb5d44e2003-12-23 08:09:43 +00001412
1413 (level == 1) ? (passwd = &circuit->area->area_passwd) :
hassof390d2c2004-09-10 20:48:21 +00001414 (passwd = &circuit->area->domain_passwd);
1415 if (passwd->type)
1416 {
1417 if (!(found & TLVFLAG_AUTH_INFO) ||
1418 authentication_check (passwd, &tlvs.auth_info))
1419 {
1420 isis_event_auth_failure (circuit->area->area_tag,
1421 "SNP authentication" " failure",
1422 phdr ? phdr->source_id : chdr->source_id);
1423 return ISIS_OK;
1424 }
1425 }
jardineb5d44e2003-12-23 08:09:43 +00001426
1427 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001428 if (isis->debugs & DEBUG_SNP_PACKETS)
1429 {
1430 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1431 circuit->area->area_tag,
1432 level,
1433 typechar, snpa_print (ssnpa), circuit->interface->name);
1434 if (tlvs.lsp_entries)
1435 {
1436 LIST_LOOP (tlvs.lsp_entries, entry, node)
1437 {
1438 zlog_info ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1439 " cksum 0x%04x, lifetime %us",
1440 circuit->area->area_tag,
1441 typechar,
1442 rawlspid_print (entry->lsp_id),
1443 ntohl (entry->seq_num),
1444 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
1445 }
1446 }
jardineb5d44e2003-12-23 08:09:43 +00001447 }
jardineb5d44e2003-12-23 08:09:43 +00001448
1449 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001450 if (tlvs.lsp_entries)
1451 {
1452 LIST_LOOP (tlvs.lsp_entries, entry, node)
1453 {
1454 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1455 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1456 if (lsp)
1457 {
1458 /* 7.3.15.2 b) 1) is this LSP newer */
1459 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1460 entry->checksum, entry->rem_lifetime);
1461 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1462 if (cmp == LSP_EQUAL)
1463 {
1464 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1465 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1466 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1467 }
1468 else if (cmp == LSP_OLDER)
1469 {
1470 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1471 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1472 }
1473 else
1474 {
1475 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1476 * on p2p */
1477 if (own_lsp)
1478 {
1479 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1480 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1481 }
1482 else
1483 {
1484 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1485 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1486 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1487 }
1488 }
1489 }
1490 else
1491 {
1492 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1493 * insert it and set SSN on it */
1494 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1495 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1496 {
1497 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1498 0, 0, entry->checksum, level);
1499 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1500 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1501 }
1502 }
jardineb5d44e2003-12-23 08:09:43 +00001503 }
1504 }
jardineb5d44e2003-12-23 08:09:43 +00001505
1506 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001507 if (snp_type == ISIS_SNP_CSNP_FLAG)
1508 {
1509 /*
1510 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1511 */
1512 lsp_list = list_new ();
1513 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1514 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001515
hassof390d2c2004-09-10 20:48:21 +00001516 /* Fixme: Find a better solution */
1517 if (tlvs.lsp_entries)
1518 {
1519 LIST_LOOP (tlvs.lsp_entries, entry, node)
1520 {
1521 LIST_LOOP (lsp_list, lsp, node2)
1522 {
1523 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1524 {
1525 list_delete_node (lsp_list, node2);
1526 break;
1527 }
1528 }
1529 }
1530 }
1531 /* on remaining LSPs we set SRM (neighbor knew not of) */
1532 LIST_LOOP (lsp_list, lsp, node2)
1533 {
1534 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001535 }
hassof390d2c2004-09-10 20:48:21 +00001536 /* lets free it */
1537 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001538 }
jardineb5d44e2003-12-23 08:09:43 +00001539
1540 free_tlvs (&tlvs);
1541 return retval;
1542}
1543
1544int
hassof390d2c2004-09-10 20:48:21 +00001545process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001546{
jardineb5d44e2003-12-23 08:09:43 +00001547 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001548 if ((stream_get_endp (circuit->rcv_stream) -
1549 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1550 {
1551 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1552 return ISIS_WARNING;
1553 }
jardineb5d44e2003-12-23 08:09:43 +00001554
1555 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1556}
1557
hassof390d2c2004-09-10 20:48:21 +00001558int
1559process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001560{
hassof390d2c2004-09-10 20:48:21 +00001561 if ((stream_get_endp (circuit->rcv_stream) -
1562 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1563 {
1564 zlog_warn ("Packet too short");
1565 return ISIS_WARNING;
1566 }
jardineb5d44e2003-12-23 08:09:43 +00001567
1568 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1569}
1570
jardineb5d44e2003-12-23 08:09:43 +00001571/*
1572 * Process ISH
1573 * ISO - 10589
1574 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1575 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001576 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1577 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1578 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001579 */
1580int
1581process_is_hello (struct isis_circuit *circuit)
1582{
1583 struct isis_adjacency *adj;
1584 int retval = ISIS_OK;
1585 u_char neigh_len;
1586 u_char *sysid;
1587
1588 /* In this point in time we are not yet able to handle is_hellos
1589 * on lan - Sorry juniper...
1590 */
1591 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1592 return retval;
1593
1594 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001595 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001596 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001597 if (!adj)
1598 {
1599 /* 8.2.2 */
1600 adj = isis_new_adj (sysid, " ", 0, circuit);
1601 if (adj == NULL)
1602 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001603
hassof390d2c2004-09-10 20:48:21 +00001604 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1605 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1606 circuit->u.p2p.neighbor = adj;
1607 }
1608 /* 8.2.2 a) */
1609 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1610 ISIS_SYS_ID_LEN))
1611 {
1612 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1613 /* 8.2.2 a) 2) delete the adj */
1614 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1615 /* 8.2.2 a) 3) create a new adj */
1616 adj = isis_new_adj (sysid, " ", 0, circuit);
1617 if (adj == NULL)
1618 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001619
hassof390d2c2004-09-10 20:48:21 +00001620 /* 8.2.2 a) 3) i */
1621 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1622 /* 8.2.2 a) 3) ii */
1623 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1624 /* 8.2.2 a) 4) quite meaningless */
1625 }
jardineb5d44e2003-12-23 08:09:43 +00001626 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001627 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1628 (adj->sys_type == ISIS_SYSTYPE_IS))
1629 {
1630 /* do nothing */
1631 }
1632 else
1633 {
1634 /* 8.2.2 c) respond with a p2p IIH */
1635 send_hello (circuit, 1);
1636 }
jardineb5d44e2003-12-23 08:09:43 +00001637 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001638 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001639 /* 8.2.2 e) FIXME: Circuit type of? */
1640
jardineb5d44e2003-12-23 08:09:43 +00001641 return retval;
1642}
1643
jardineb5d44e2003-12-23 08:09:43 +00001644/*
1645 * PDU Dispatcher
1646 */
1647
hassof390d2c2004-09-10 20:48:21 +00001648int
1649isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001650{
jardineb5d44e2003-12-23 08:09:43 +00001651 struct isis_fixed_hdr *hdr;
1652 struct esis_fixed_hdr *esis_hdr;
1653
hassof390d2c2004-09-10 20:48:21 +00001654 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001655
1656 /*
1657 * Let's first read data from stream to the header
1658 */
hassof390d2c2004-09-10 20:48:21 +00001659 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001660
hassof390d2c2004-09-10 20:48:21 +00001661 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1662 {
1663 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1664 return ISIS_ERROR;
1665 }
jardineb5d44e2003-12-23 08:09:43 +00001666
1667 /* now we need to know if this is an ISO 9542 packet and
1668 * take real good care of it, waaa!
1669 */
hassof390d2c2004-09-10 20:48:21 +00001670 if (hdr->idrp == ISO9542_ESIS)
1671 {
1672 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1673 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1674 /* FIXME: Need to do some acceptence tests */
1675 /* example length... */
1676 switch (esis_hdr->pdu_type)
1677 {
1678 case ESH_PDU:
1679 /* FIXME */
1680 break;
1681 case ISH_PDU:
1682 zlog_info ("AN ISH PDU!!");
1683 retval = process_is_hello (circuit);
1684 break;
1685 default:
1686 return ISIS_ERROR;
1687 }
1688 return retval;
1689 }
1690 else
1691 {
1692 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1693 }
jardineb5d44e2003-12-23 08:09:43 +00001694 /*
1695 * and then process it
1696 */
1697
hassof390d2c2004-09-10 20:48:21 +00001698 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1699 {
1700 zlog_err ("Fixed header length = %d", hdr->length);
1701 return ISIS_ERROR;
1702 }
jardineb5d44e2003-12-23 08:09:43 +00001703
hassof390d2c2004-09-10 20:48:21 +00001704 if (hdr->version1 != 1)
1705 {
1706 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1707 return ISIS_WARNING;
1708 }
jardineb5d44e2003-12-23 08:09:43 +00001709 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001710 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1711 {
1712 zlog_err
1713 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1714 "while the parameter for this IS is %u", hdr->id_len,
1715 ISIS_SYS_ID_LEN);
1716 return ISIS_ERROR;
1717 }
jardineb5d44e2003-12-23 08:09:43 +00001718
hassof390d2c2004-09-10 20:48:21 +00001719 if (hdr->version2 != 1)
1720 {
1721 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1722 return ISIS_WARNING;
1723 }
jardineb5d44e2003-12-23 08:09:43 +00001724 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001725 if ((hdr->max_area_addrs != 0)
1726 && (hdr->max_area_addrs != isis->max_area_addrs))
1727 {
1728 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1729 "received PDU %u while the parameter for this IS is %u",
1730 hdr->max_area_addrs, isis->max_area_addrs);
1731 return ISIS_ERROR;
1732 }
jardineb5d44e2003-12-23 08:09:43 +00001733
hassof390d2c2004-09-10 20:48:21 +00001734 switch (hdr->pdu_type)
1735 {
1736 case L1_LAN_HELLO:
1737 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1738 break;
1739 case L2_LAN_HELLO:
1740 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1741 break;
1742 case P2P_HELLO:
1743 retval = process_p2p_hello (circuit);
1744 break;
1745 case L1_LINK_STATE:
1746 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1747 break;
1748 case L2_LINK_STATE:
1749 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1750 break;
1751 case L1_COMPLETE_SEQ_NUM:
1752 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1753 break;
1754 case L2_COMPLETE_SEQ_NUM:
1755 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1756 break;
1757 case L1_PARTIAL_SEQ_NUM:
1758 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1759 break;
1760 case L2_PARTIAL_SEQ_NUM:
1761 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1762 break;
1763 default:
1764 return ISIS_ERROR;
1765 }
jardineb5d44e2003-12-23 08:09:43 +00001766
1767 return retval;
1768}
1769
jardineb5d44e2003-12-23 08:09:43 +00001770#ifdef GNU_LINUX
1771int
1772isis_receive (struct thread *thread)
1773{
jardineb5d44e2003-12-23 08:09:43 +00001774 struct isis_circuit *circuit;
1775 u_char ssnpa[ETH_ALEN];
1776 int retval;
1777
1778 /*
1779 * Get the circuit
1780 */
1781 circuit = THREAD_ARG (thread);
1782 assert (circuit);
1783
1784 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001785 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001786 else
1787 stream_reset (circuit->rcv_stream);
1788
1789 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001790 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001791
1792 if (retval == ISIS_OK)
1793 retval = isis_handle_pdu (circuit, ssnpa);
1794
1795 /*
1796 * prepare for next packet.
1797 */
hassof390d2c2004-09-10 20:48:21 +00001798 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1799 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001800
1801 return retval;
1802}
1803
1804#else
1805int
1806isis_receive (struct thread *thread)
1807{
jardineb5d44e2003-12-23 08:09:43 +00001808 struct isis_circuit *circuit;
1809 u_char ssnpa[ETH_ALEN];
1810 int retval;
1811
1812 /*
1813 * Get the circuit
1814 */
1815 circuit = THREAD_ARG (thread);
1816 assert (circuit);
1817
hassof390d2c2004-09-10 20:48:21 +00001818 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001819
1820 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001821 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001822 else
1823 stream_reset (circuit->rcv_stream);
1824
1825 retval = circuit->rx (circuit, ssnpa);
1826
1827 if (retval == ISIS_OK)
1828 retval = isis_handle_pdu (circuit, ssnpa);
1829
1830 /*
1831 * prepare for next packet.
1832 */
hassof390d2c2004-09-10 20:48:21 +00001833 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1834 listcount
1835 (circuit->area->circuit_list) *
1836 100);
jardineb5d44e2003-12-23 08:09:43 +00001837
1838 return retval;
1839}
1840
1841#endif
1842
1843 /* filling of the fixed isis header */
1844void
1845fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1846{
1847 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1848
1849 hdr->idrp = ISO10589_ISIS;
1850
hassof390d2c2004-09-10 20:48:21 +00001851 switch (pdu_type)
1852 {
1853 case L1_LAN_HELLO:
1854 case L2_LAN_HELLO:
1855 hdr->length = ISIS_LANHELLO_HDRLEN;
1856 break;
1857 case P2P_HELLO:
1858 hdr->length = ISIS_P2PHELLO_HDRLEN;
1859 break;
1860 case L1_LINK_STATE:
1861 case L2_LINK_STATE:
1862 hdr->length = ISIS_LSP_HDR_LEN;
1863 break;
1864 case L1_COMPLETE_SEQ_NUM:
1865 case L2_COMPLETE_SEQ_NUM:
1866 hdr->length = ISIS_CSNP_HDRLEN;
1867 break;
1868 case L1_PARTIAL_SEQ_NUM:
1869 case L2_PARTIAL_SEQ_NUM:
1870 hdr->length = ISIS_PSNP_HDRLEN;
1871 break;
1872 default:
1873 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1874 return;
1875 }
jardineb5d44e2003-12-23 08:09:43 +00001876 hdr->length += ISIS_FIXED_HDR_LEN;
1877 hdr->pdu_type = pdu_type;
1878 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001879 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001880 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001881 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001882}
1883
jardineb5d44e2003-12-23 08:09:43 +00001884/*
1885 * SEND SIDE
1886 */
1887void
1888fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001889 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001890{
hassof390d2c2004-09-10 20:48:21 +00001891 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001892
1893 stream_putc (stream, hdr->idrp);
1894 stream_putc (stream, hdr->length);
1895 stream_putc (stream, hdr->version1);
1896 stream_putc (stream, hdr->id_len);
1897 stream_putc (stream, hdr->pdu_type);
1898 stream_putc (stream, hdr->version2);
1899 stream_putc (stream, hdr->reserved);
1900 stream_putc (stream, hdr->max_area_addrs);
1901
1902 return;
1903}
1904
jardineb5d44e2003-12-23 08:09:43 +00001905int
1906send_hello (struct isis_circuit *circuit, int level)
1907{
1908 struct isis_fixed_hdr fixed_hdr;
1909 struct isis_lan_hello_hdr hello_hdr;
1910 struct isis_p2p_hello_hdr p2p_hello_hdr;
1911
1912 u_int32_t interval;
1913 unsigned long len_pointer, length;
1914 int retval;
1915
hassof390d2c2004-09-10 20:48:21 +00001916 if (circuit->interface->mtu == 0)
1917 {
1918 zlog_warn ("circuit has zero MTU");
1919 return ISIS_WARNING;
1920 }
jardineb5d44e2003-12-23 08:09:43 +00001921
1922 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001923 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001924 else
1925 stream_reset (circuit->snd_stream);
1926
1927 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1928 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001929 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1930 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001931 else
hassof390d2c2004-09-10 20:48:21 +00001932 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1933 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001934 else
hassof390d2c2004-09-10 20:48:21 +00001935 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001936
1937 /*
1938 * Fill LAN Level 1 or 2 Hello PDU header
1939 */
1940 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001941 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001942 circuit->hello_interval[level - 1];
1943 if (interval > USHRT_MAX)
1944 interval = USHRT_MAX;
1945 hello_hdr.circuit_t = circuit->circuit_is_type;
1946 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001947 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001948
hassof390d2c2004-09-10 20:48:21 +00001949 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
1950 len_pointer = stream_get_putp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001951
1952 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001953 if (circuit->circ_type == CIRCUIT_T_P2P)
1954 {
1955 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1956 p2p_hello_hdr.local_id = circuit->circuit_id;
1957 /* FIXME: need better understanding */
1958 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001959 }
hassof390d2c2004-09-10 20:48:21 +00001960 else
1961 {
1962 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1963 if (level == 1 && circuit->u.bc.l1_desig_is)
1964 {
1965 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1966 ISIS_SYS_ID_LEN + 1);
1967 }
1968 else if (level == 2 && circuit->u.bc.l2_desig_is)
1969 {
1970 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1971 ISIS_SYS_ID_LEN + 1);
1972 }
1973 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1974 }
jardineb5d44e2003-12-23 08:09:43 +00001975
1976 /*
1977 * Then the variable length part
1978 */
1979 /* add circuit password */
1980 if (circuit->passwd.type)
1981 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1982 circuit->passwd.passwd, circuit->snd_stream))
1983 return ISIS_WARNING;
1984 /* Area Addresses TLV */
1985 assert (circuit->area);
1986 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1987 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1988 return ISIS_WARNING;
1989
1990 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00001991 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1992 {
1993 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1994 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1995 circuit->snd_stream))
1996 return ISIS_WARNING;
1997 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
1998 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
1999 circuit->snd_stream))
2000 return ISIS_WARNING;
2001 }
jardineb5d44e2003-12-23 08:09:43 +00002002
2003 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002004 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002005 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2006 return ISIS_WARNING;
2007 /* IP interface Address TLV */
2008 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2009 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2010 return ISIS_WARNING;
2011
hassof390d2c2004-09-10 20:48:21 +00002012#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002013 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002014 if (circuit->ipv6_router && circuit->ipv6_link &&
jardineb5d44e2003-12-23 08:09:43 +00002015 circuit->ipv6_link->count > 0)
2016 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2017 return ISIS_WARNING;
2018#endif /* HAVE_IPV6 */
2019
2020 if (circuit->u.bc.pad_hellos)
2021 if (tlv_add_padding (circuit->snd_stream))
2022 return ISIS_WARNING;
2023
2024 length = stream_get_putp (circuit->snd_stream);
2025 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002026 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002027
2028 retval = circuit->tx (circuit, level);
2029 if (retval)
2030 zlog_warn ("sending of LAN Level %d Hello failed", level);
2031
2032 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002033 if (isis->debugs & DEBUG_ADJ_PACKETS)
2034 {
2035 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2036 {
2037 zlog_info ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2038 circuit->area->area_tag, level, circuit->interface->name,
2039 STREAM_SIZE (circuit->snd_stream));
2040 }
2041 else
2042 {
2043 zlog_info ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2044 circuit->area->area_tag, circuit->interface->name,
2045 STREAM_SIZE (circuit->snd_stream));
2046 }
jardineb5d44e2003-12-23 08:09:43 +00002047 }
jardineb5d44e2003-12-23 08:09:43 +00002048
2049 return retval;
2050}
2051
2052int
2053send_lan_hello (struct isis_circuit *circuit, int level)
2054{
hassof390d2c2004-09-10 20:48:21 +00002055 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002056}
2057
2058int
2059send_lan_l1_hello (struct thread *thread)
2060{
jardineb5d44e2003-12-23 08:09:43 +00002061 struct isis_circuit *circuit;
2062 int retval;
2063
2064 circuit = THREAD_ARG (thread);
2065 assert (circuit);
2066 circuit->u.bc.t_send_lan_hello[0] = NULL;
2067
2068 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002069 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002070
2071 retval = send_lan_hello (circuit, 1);
2072
2073 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002074 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2075 send_lan_l1_hello, circuit,
2076 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002077
2078 return retval;
2079}
2080
2081int
2082send_lan_l2_hello (struct thread *thread)
2083{
2084 struct isis_circuit *circuit;
2085 int retval;
2086
2087 circuit = THREAD_ARG (thread);
2088 assert (circuit);
2089 circuit->u.bc.t_send_lan_hello[1] = NULL;
2090
2091 if (circuit->u.bc.run_dr_elect[1])
2092 retval = isis_dr_elect (circuit, 2);
2093
2094 retval = send_lan_hello (circuit, 2);
2095
hassof390d2c2004-09-10 20:48:21 +00002096 /* set next timer thread */
2097 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2098 send_lan_l2_hello, circuit,
2099 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002100
2101 return retval;
2102}
2103
2104int
2105send_p2p_hello (struct thread *thread)
2106{
2107 struct isis_circuit *circuit;
2108
2109 circuit = THREAD_ARG (thread);
2110 assert (circuit);
2111 circuit->u.p2p.t_send_p2p_hello = NULL;
2112
hassof390d2c2004-09-10 20:48:21 +00002113 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002114
hassof390d2c2004-09-10 20:48:21 +00002115 /* set next timer thread */
2116 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2117 circuit, isis_jitter (circuit->hello_interval[1],
2118 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002119
2120 return ISIS_OK;
2121}
2122
2123int
hassof390d2c2004-09-10 20:48:21 +00002124build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2125 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002126{
2127 struct isis_fixed_hdr fixed_hdr;
2128 struct isis_passwd *passwd;
2129 int retval = ISIS_OK;
2130 unsigned long lenp;
2131 u_int16_t length;
2132
hassof390d2c2004-09-10 20:48:21 +00002133 if (level == 1)
2134 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2135 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002136 else
hassof390d2c2004-09-10 20:48:21 +00002137 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2138 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002139
2140 /*
2141 * Fill Level 1 or 2 Complete Sequence Numbers header
2142 */
2143
2144 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002145 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002146 /* no need to send the source here, it is always us if we csnp */
2147 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2148 /* with zero circuit id - ref 9.10, 9.11 */
2149 stream_putc (circuit->snd_stream, 0x00);
2150
2151 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2152 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2153
2154 /*
2155 * And TLVs
2156 */
2157 if (level == 1)
2158 passwd = &circuit->area->area_passwd;
2159 else
2160 passwd = &circuit->area->domain_passwd;
2161
2162 if (passwd->type)
2163 retval = tlv_add_authinfo (passwd->type, passwd->len,
2164 passwd->passwd, circuit->snd_stream);
2165
hassof390d2c2004-09-10 20:48:21 +00002166 if (!retval && lsps)
2167 {
2168 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2169 }
2170 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002171 assert (length >= ISIS_CSNP_HDRLEN);
2172 /* Update PU length */
2173 stream_putw_at (circuit->snd_stream, lenp, length);
2174
2175 return retval;
2176}
2177
2178/*
2179 * FIXME: support multiple CSNPs
2180 */
2181
2182int
2183send_csnp (struct isis_circuit *circuit, int level)
2184{
2185 int retval = ISIS_OK;
2186 u_char start[ISIS_SYS_ID_LEN + 2];
2187 u_char stop[ISIS_SYS_ID_LEN + 2];
2188 struct list *list = NULL;
2189 struct listnode *node;
2190 struct isis_lsp *lsp;
2191
hassof390d2c2004-09-10 20:48:21 +00002192 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002193 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2194
hassof390d2c2004-09-10 20:48:21 +00002195 if (circuit->area->lspdb[level - 1] &&
2196 dict_count (circuit->area->lspdb[level - 1]) > 0)
2197 {
2198 list = list_new ();
2199 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002200
hassof390d2c2004-09-10 20:48:21 +00002201 if (circuit->snd_stream == NULL)
2202 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2203 else
2204 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002205
hassof390d2c2004-09-10 20:48:21 +00002206 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002207
hassof390d2c2004-09-10 20:48:21 +00002208 if (isis->debugs & DEBUG_SNP_PACKETS)
2209 {
2210 zlog_info ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2211 circuit->area->area_tag, level, circuit->interface->name,
2212 STREAM_SIZE (circuit->snd_stream));
2213 LIST_LOOP (list, lsp, node)
2214 {
2215 zlog_info ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2216 " cksum 0x%04x, lifetime %us",
2217 circuit->area->area_tag,
2218 rawlspid_print (lsp->lsp_header->lsp_id),
2219 ntohl (lsp->lsp_header->seq_num),
2220 ntohs (lsp->lsp_header->checksum),
2221 ntohs (lsp->lsp_header->rem_lifetime));
2222 }
2223 }
2224
2225 list_delete (list);
2226
2227 if (retval == ISIS_OK)
2228 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002229 }
jardineb5d44e2003-12-23 08:09:43 +00002230 return retval;
2231}
2232
2233int
2234send_l1_csnp (struct thread *thread)
2235{
2236 struct isis_circuit *circuit;
2237 int retval = ISIS_OK;
2238
2239 circuit = THREAD_ARG (thread);
2240 assert (circuit);
2241
2242 circuit->t_send_csnp[0] = NULL;
2243
hassof390d2c2004-09-10 20:48:21 +00002244 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2245 {
2246 send_csnp (circuit, 1);
2247 }
jardineb5d44e2003-12-23 08:09:43 +00002248 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002249 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2250 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002251
2252 return retval;
2253}
2254
2255int
2256send_l2_csnp (struct thread *thread)
2257{
2258 struct isis_circuit *circuit;
2259 int retval = ISIS_OK;
2260
2261 circuit = THREAD_ARG (thread);
2262 assert (circuit);
2263
2264 circuit->t_send_csnp[1] = NULL;
2265
hassof390d2c2004-09-10 20:48:21 +00002266 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2267 {
2268 send_csnp (circuit, 2);
2269 }
jardineb5d44e2003-12-23 08:09:43 +00002270 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002271 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2272 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002273
jardineb5d44e2003-12-23 08:09:43 +00002274 return retval;
2275}
2276
2277int
2278build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2279{
2280 struct isis_fixed_hdr fixed_hdr;
2281 unsigned long lenp;
2282 u_int16_t length;
2283 int retval = 0;
2284 struct isis_lsp *lsp;
2285 struct isis_passwd *passwd;
2286 struct listnode *node;
2287
2288 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002289 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2290 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002291 else
2292 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002293 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002294
2295 /*
2296 * Fill Level 1 or 2 Partial Sequence Numbers header
2297 */
2298 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002299 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002300 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2301 stream_putc (circuit->snd_stream, circuit->idx);
2302
2303 /*
2304 * And TLVs
2305 */
2306
2307 if (level == 1)
2308 passwd = &circuit->area->area_passwd;
2309 else
2310 passwd = &circuit->area->domain_passwd;
2311
2312 if (passwd->type)
2313 retval = tlv_add_authinfo (passwd->type, passwd->len,
2314 passwd->passwd, circuit->snd_stream);
2315
hassof390d2c2004-09-10 20:48:21 +00002316 if (!retval && lsps)
2317 {
2318 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002319 }
jardineb5d44e2003-12-23 08:09:43 +00002320
hassof390d2c2004-09-10 20:48:21 +00002321 if (isis->debugs & DEBUG_SNP_PACKETS)
2322 {
2323 LIST_LOOP (lsps, lsp, node)
2324 {
2325 zlog_info ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2326 " cksum 0x%04x, lifetime %us",
2327 circuit->area->area_tag,
2328 rawlspid_print (lsp->lsp_header->lsp_id),
2329 ntohl (lsp->lsp_header->seq_num),
2330 ntohs (lsp->lsp_header->checksum),
2331 ntohs (lsp->lsp_header->rem_lifetime));
2332 }
2333 }
2334
2335 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002336 assert (length >= ISIS_PSNP_HDRLEN);
2337 /* Update PDU length */
2338 stream_putw_at (circuit->snd_stream, lenp, length);
2339
2340 return ISIS_OK;
2341}
2342
2343/*
2344 * 7.3.15.4 action on expiration of partial SNP interval
2345 * level 1
2346 */
2347int
2348send_psnp (int level, struct isis_circuit *circuit)
2349{
2350 int retval = ISIS_OK;
2351 struct isis_lsp *lsp;
2352 struct list *list = NULL;
2353 struct listnode *node;
2354
hassof390d2c2004-09-10 20:48:21 +00002355 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002356 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002357 circuit->circ_type != CIRCUIT_T_BROADCAST)
2358 {
jardineb5d44e2003-12-23 08:09:43 +00002359
hassof390d2c2004-09-10 20:48:21 +00002360 if (circuit->area->lspdb[level - 1] &&
2361 dict_count (circuit->area->lspdb[level - 1]) > 0)
2362 {
2363 list = list_new ();
2364 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002365
hassof390d2c2004-09-10 20:48:21 +00002366 if (listcount (list) > 0)
2367 {
2368 if (circuit->snd_stream == NULL)
2369 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2370 else
2371 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002372
2373
hassof390d2c2004-09-10 20:48:21 +00002374 if (isis->debugs & DEBUG_SNP_PACKETS)
2375 zlog_info ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2376 circuit->area->area_tag, level,
2377 circuit->interface->name,
2378 STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002379
hassof390d2c2004-09-10 20:48:21 +00002380 retval = build_psnp (level, circuit, list);
2381 if (retval == ISIS_OK)
2382 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002383
hassof390d2c2004-09-10 20:48:21 +00002384 if (retval == ISIS_OK)
2385 {
2386 /*
2387 * sending succeeded, we can clear SSN flags of this circuit
2388 * for the LSPs in list
2389 */
2390 for (node = listhead (list); node; nextnode (node))
2391 {
2392 lsp = getdata (node);
2393 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2394 }
2395 }
2396 }
2397 list_delete (list);
2398 }
jardineb5d44e2003-12-23 08:09:43 +00002399 }
jardineb5d44e2003-12-23 08:09:43 +00002400
2401 return retval;
2402}
2403
2404int
2405send_l1_psnp (struct thread *thread)
2406{
2407
2408 struct isis_circuit *circuit;
2409 int retval = ISIS_OK;
2410
2411 circuit = THREAD_ARG (thread);
2412 assert (circuit);
2413
2414 circuit->t_send_psnp[0] = NULL;
2415
2416 send_psnp (1, circuit);
2417 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002418 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2419 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002420
2421 return retval;
2422}
2423
2424/*
2425 * 7.3.15.4 action on expiration of partial SNP interval
2426 * level 2
2427 */
2428int
2429send_l2_psnp (struct thread *thread)
2430{
jardineb5d44e2003-12-23 08:09:43 +00002431 struct isis_circuit *circuit;
2432 int retval = ISIS_OK;
2433
2434 circuit = THREAD_ARG (thread);
2435 assert (circuit);
2436
2437 circuit->t_send_psnp[1] = NULL;
2438
2439 send_psnp (2, circuit);
2440
2441 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002442 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2443 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002444
2445 return retval;
2446}
2447
jardineb5d44e2003-12-23 08:09:43 +00002448void
2449build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit,
hassof390d2c2004-09-10 20:48:21 +00002450 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002451{
2452 unsigned long length;
2453
hassof390d2c2004-09-10 20:48:21 +00002454 stream_put (stream, lsp->pdu, ntohs (lsp->lsp_header->pdu_len));
2455 length = stream_get_putp (stream);
jardineb5d44e2003-12-23 08:09:43 +00002456
2457 return;
2458}
2459
jardineb5d44e2003-12-23 08:09:43 +00002460/*
2461 * ISO 10589 - 7.3.14.3
2462 */
2463int
2464send_lsp (struct thread *thread)
2465{
2466 struct isis_circuit *circuit;
2467 struct isis_lsp *lsp;
2468 struct listnode *node;
2469 int retval = 0;
2470
2471 circuit = THREAD_ARG (thread);
2472 assert (circuit);
2473
hassof390d2c2004-09-10 20:48:21 +00002474 if (circuit->state == C_STATE_UP)
2475 {
2476 node = listhead (circuit->lsp_queue);
2477 assert (node);
jardineb5d44e2003-12-23 08:09:43 +00002478
hassof390d2c2004-09-10 20:48:21 +00002479 lsp = getdata (node);
jardineb5d44e2003-12-23 08:09:43 +00002480
2481 /*
hassof390d2c2004-09-10 20:48:21 +00002482 * Do not send if levels do not match
jardineb5d44e2003-12-23 08:09:43 +00002483 */
hassof390d2c2004-09-10 20:48:21 +00002484 if (!(lsp->level & circuit->circuit_is_type))
2485 goto dontsend;
jardineb5d44e2003-12-23 08:09:43 +00002486
hassof390d2c2004-09-10 20:48:21 +00002487 /*
2488 * Do not send if we do not have adjacencies in state up on the circuit
2489 */
2490 if (circuit->upadjcount[lsp->level - 1] == 0)
2491 goto dontsend;
2492 /* only send if it needs sending */
2493 if ((time (NULL) - lsp->last_sent) >=
2494 circuit->area->lsp_gen_interval[lsp->level - 1])
2495 {
jardineb5d44e2003-12-23 08:09:43 +00002496
hassof390d2c2004-09-10 20:48:21 +00002497 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2498 {
2499 zlog_info
2500 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2501 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2502 rawlspid_print (lsp->lsp_header->lsp_id),
2503 ntohl (lsp->lsp_header->seq_num),
2504 ntohs (lsp->lsp_header->checksum),
2505 ntohs (lsp->lsp_header->rem_lifetime),
2506 circuit->interface->name);
2507 }
2508 /* copy our lsp to the send buffer */
2509 circuit->snd_stream->getp = lsp->pdu->getp;
2510 circuit->snd_stream->putp = lsp->pdu->putp;
2511 circuit->snd_stream->endp = lsp->pdu->endp;
2512 memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp);
2513
2514 retval = circuit->tx (circuit, lsp->level);
2515
jardineb5d44e2003-12-23 08:09:43 +00002516 /*
hassof390d2c2004-09-10 20:48:21 +00002517 * If the sending succeeded, we can del the lsp from circuits
2518 * lsp_queue
jardineb5d44e2003-12-23 08:09:43 +00002519 */
hassof390d2c2004-09-10 20:48:21 +00002520 if (retval == ISIS_OK)
2521 {
2522 list_delete_node (circuit->lsp_queue, node);
2523
2524 /*
2525 * On broadcast circuits also the SRMflag can be cleared
2526 */
2527 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2528 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2529
2530 if (flags_any_set (lsp->SRMflags) == 0)
2531 {
2532 /*
2533 * need to remember when we were last sent
2534 */
2535 lsp->last_sent = time (NULL);
2536 }
2537 }
2538 else
2539 {
2540 zlog_info ("sending of level %d link state failed", lsp->level);
2541 }
jardineb5d44e2003-12-23 08:09:43 +00002542 }
hassof390d2c2004-09-10 20:48:21 +00002543 else
2544 {
2545 /* my belief is that if it wasn't his time, the lsp can be removed
2546 * from the queue
2547 */
2548 dontsend:
2549 list_delete_node (circuit->lsp_queue, node);
2550 }
jardineb5d44e2003-12-23 08:09:43 +00002551#if 0
hassof390d2c2004-09-10 20:48:21 +00002552 /*
2553 * If there are still LSPs send next one after lsp-interval (33 msecs)
2554 */
2555 if (listcount (circuit->lsp_queue) > 0)
2556 thread_add_timer (master, send_lsp, circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002557#endif
hassof390d2c2004-09-10 20:48:21 +00002558 }
jardineb5d44e2003-12-23 08:09:43 +00002559
2560 return retval;
hassof390d2c2004-09-10 20:48:21 +00002561}
jardineb5d44e2003-12-23 08:09:43 +00002562
2563int
hassof390d2c2004-09-10 20:48:21 +00002564ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2565 int level)
jardineb5d44e2003-12-23 08:09:43 +00002566{
2567 unsigned long lenp;
2568 int retval;
2569 u_int16_t length;
2570 struct isis_fixed_hdr fixed_hdr;
2571
2572 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002573 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002574 else
2575 stream_reset (circuit->snd_stream);
2576
2577// fill_llc_hdr (stream);
2578 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002579 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2580 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002581 else
hassof390d2c2004-09-10 20:48:21 +00002582 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2583 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002584
2585
2586 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002587 stream_putw (circuit->snd_stream, 0); /* PDU length */
2588 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002589 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002590 stream_putc (circuit->snd_stream, 9); /* code */
2591 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002592
hassof390d2c2004-09-10 20:48:21 +00002593 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2594 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2595 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2596 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002597
hassof390d2c2004-09-10 20:48:21 +00002598 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002599 /* Update PDU length */
2600 stream_putw_at (circuit->snd_stream, lenp, length);
2601
2602 retval = circuit->tx (circuit, level);
2603
2604 return retval;
2605}
2606
2607#if 0
2608/*
2609 * ISH PDU Processing
2610 */
2611
jardineb5d44e2003-12-23 08:09:43 +00002612 /*
2613 * Let's first check if the local and remote system have any common area
2614 * addresses
2615 */
hassof390d2c2004-09-10 20:48:21 +00002616if (area_match (tlvs.area_addrs, isis->man_area_addrs) == 0)
2617 {
2618 if (circuit->circuit_t == IS_LEVEL_2)
2619 {
2620 /* do as in table 8 (p. 40) */
2621 switch (circuit_type)
2622 {
2623 case IS_LEVEL_1:
2624 if (adj->adj_state != ISIS_ADJ_UP)
2625 {
2626 /* Reject */
2627 zlog_warn ("areaMismatch");
2628 retval = ISIS_WARNING;
2629 }
2630 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2631 {
2632 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2633 circuit->adjdb);
2634 }
2635 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 ||
2636 adj->adj_usage == ISIS_ADJ_LEVEL2)
2637 {
2638 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2639 circuit->adjdb);
2640 }
2641 break;
2642 case IS_LEVEL_2:
2643 if (adj->adj_state != ISIS_ADJ_UP)
2644 {
2645 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2646 circuit->adjdb);
2647 adj->adj_usage = ISIS_ADJ_LEVEL2;
2648 }
2649 else if (adj->adj_usage == ISIS_ADJ_LEVEL1 ||
2650 adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2651 {
2652 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2653 circuit->adjdb);
2654 }
2655 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2656 {
2657 ; /* Accept */
2658 }
2659 break;
2660 case IS_LEVEL_1_AND_2:
2661 if (adj->adj_state != ISIS_ADJ_UP)
2662 {
2663 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2664 circuit->adjdb);
2665 adj->adj_usage = ISIS_ADJ_LEVEL2;
2666 }
2667 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2668 {
2669 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2670 circuit->adjdb);
2671 }
2672 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2673 {
2674 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2675 circuit->adjdb);
2676 }
2677 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2678 {
2679 ; /* Accept */
2680 }
2681 break;
2682 }
2683 goto mismatch;
jardineb5d44e2003-12-23 08:09:43 +00002684 }
hassof390d2c2004-09-10 20:48:21 +00002685 else
2686 {
2687 isis_delete_adj (adj, circuit->adjdb);
2688 zlog_warn ("areaMismatch");
2689 return ISIS_WARNING;
2690 }
jardineb5d44e2003-12-23 08:09:43 +00002691 }
2692
2693mismatch:
2694#endif