blob: 1ecdab48cca3c8adae83d752727a03842e7cbb2b [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)
hasso13c48f72004-09-10 21:19:13 +0000815 {
816 retval = ISIS_ERROR;
817 goto out;
818 }
jardineb5d44e2003-12-23 08:09:43 +0000819
hassof390d2c2004-09-10 20:48:21 +0000820 adj->level = level;
821 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000822
hassof390d2c2004-09-10 20:48:21 +0000823 if (level == 1)
824 {
825 adj->sys_type = ISIS_SYSTYPE_L1_IS;
826 }
827 else
828 {
829 adj->sys_type = ISIS_SYSTYPE_L2_IS;
830 }
831 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
832 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
833 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000834 }
jardineb5d44e2003-12-23 08:09:43 +0000835
hassof390d2c2004-09-10 20:48:21 +0000836 switch (level)
837 {
838 case 1:
839 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
840 {
841 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000842 if (adj->dis_record[level-1].dis == ISIS_IS_DIS)
843 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
844 ISIS_SYS_ID_LEN + 1);
hassof390d2c2004-09-10 20:48:21 +0000845 }
846 break;
847 case 2:
848 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
849 {
850 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000851 if (adj->dis_record[level-1].dis == ISIS_IS_DIS)
852 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
853 ISIS_SYS_ID_LEN + 1);
hassof390d2c2004-09-10 20:48:21 +0000854 }
855 break;
jardineb5d44e2003-12-23 08:09:43 +0000856 }
jardineb5d44e2003-12-23 08:09:43 +0000857
858#if 0
hassof390d2c2004-09-10 20:48:21 +0000859 /* Old solution: believe the lan-header always
860 */
861 if (level == 1)
862 {
863 memcpy (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
864 }
865 else if (level == 2)
866 {
867 memcpy (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
868 }
jardineb5d44e2003-12-23 08:09:43 +0000869#endif
870
871 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000872 adj->last_upd = time (NULL);
873 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000874
875 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
876
877 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000878 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000879 tlvs_to_adj_nlpids (&tlvs, adj);
880
881 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000882 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000883 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
884
885#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000886 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000887 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
888#endif /* HAVE_IPV6 */
889
890 adj->circuit_t = hdr.circuit_t;
891
892 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000893 THREAD_TIMER_OFF (adj->t_expire);
894 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
895 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000896
897 /*
898 * If the snpa for this circuit is found from LAN Neighbours TLV
899 * we have two-way communication -> adjacency can be put to state "up"
900 */
901
hassof390d2c2004-09-10 20:48:21 +0000902 if (found & TLVFLAG_LAN_NEIGHS)
903 {
904 if (adj->adj_state != ISIS_ADJ_UP)
905 {
906 LIST_LOOP (tlvs.lan_neighs, snpa, node)
907 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
908 {
909 isis_adj_state_change (adj, ISIS_ADJ_UP,
910 "own SNPA found in LAN Neighbours TLV");
911 }
912 }
jardineb5d44e2003-12-23 08:09:43 +0000913 }
jardineb5d44e2003-12-23 08:09:43 +0000914
hassof390d2c2004-09-10 20:48:21 +0000915out:
jardineb5d44e2003-12-23 08:09:43 +0000916 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000917 if (isis->debugs & DEBUG_ADJ_PACKETS)
918 {
919 /* FIXME: is this place right? fix missing info */
920 zlog_info ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
921 "cirID %u, length %ld",
922 circuit->area->area_tag,
923 level, snpa_print (ssnpa), circuit->interface->name,
924 circuit_t2string (circuit->circuit_is_type),
925 circuit->circuit_id, stream_get_endp (circuit->rcv_stream));
926 }
jardineb5d44e2003-12-23 08:09:43 +0000927
928 free_tlvs (&tlvs);
929
930 return retval;
931}
932
933/*
934 * Process Level 1/2 Link State
935 * ISO - 10589
936 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000937 */
938static int
939process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000940{
941 struct isis_link_state_hdr *hdr;
942 struct isis_adjacency *adj = NULL;
943 struct isis_lsp *lsp, *lsp0 = NULL;
944 int retval = ISIS_OK, comp = 0;
945 u_char lspid[ISIS_SYS_ID_LEN + 2];
946 struct isis_passwd *passwd;
947
948 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000949 if ((stream_get_endp (circuit->rcv_stream) -
950 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
951 {
952 zlog_warn ("Packet too short");
953 return ISIS_WARNING;
954 }
jardineb5d44e2003-12-23 08:09:43 +0000955
956 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000957 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000958
hassof390d2c2004-09-10 20:48:21 +0000959 if (isis->debugs & DEBUG_UPDATE_PACKETS)
960 {
961 zlog_info ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
962 "lifetime %us, len %lu, on %s",
963 circuit->area->area_tag,
964 level,
965 rawlspid_print (hdr->lsp_id),
966 ntohl (hdr->seq_num),
967 ntohs (hdr->checksum),
968 ntohs (hdr->rem_lifetime),
969 circuit->rcv_stream->endp, circuit->interface->name);
970 }
jardineb5d44e2003-12-23 08:09:43 +0000971
972 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
973
974 /* Checksum sanity check - FIXME: move to correct place */
975 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000976 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
977 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
978 {
979 zlog_info ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
980 circuit->area->area_tag,
981 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000982
hassof390d2c2004-09-10 20:48:21 +0000983 return ISIS_WARNING;
984 }
jardineb5d44e2003-12-23 08:09:43 +0000985
986 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000987 if (circuit->ext_domain)
988 {
989 zlog_info
990 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
991 "externalDomain = true", circuit->area->area_tag,
992 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000993
hassof390d2c2004-09-10 20:48:21 +0000994 return ISIS_WARNING;
995 }
jardineb5d44e2003-12-23 08:09:43 +0000996
997 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000998 if (!accept_level (level, circuit->circuit_is_type))
999 {
1000 zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1001 " type %s",
1002 circuit->area->area_tag,
1003 rawlspid_print (hdr->lsp_id),
1004 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +00001005
hassof390d2c2004-09-10 20:48:21 +00001006 return ISIS_WARNING;
1007 }
jardineb5d44e2003-12-23 08:09:43 +00001008
1009 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1010
1011 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1012
1013 /* 7.3.15.1 a) 7 - password check */
1014 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
1015 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001016 if (passwd->type)
1017 {
1018 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1019 ntohs (hdr->pdu_len), passwd))
1020 {
1021 isis_event_auth_failure (circuit->area->area_tag,
1022 "LSP authentication failure", hdr->lsp_id);
1023 return ISIS_WARNING;
1024 }
jardineb5d44e2003-12-23 08:09:43 +00001025 }
jardineb5d44e2003-12-23 08:09:43 +00001026 /* Find the LSP in our database and compare it to this Link State header */
1027 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1028 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001029 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1030 hdr->checksum, hdr->rem_lifetime);
1031 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001032#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001033 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001034#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001035 ))
jardineb5d44e2003-12-23 08:09:43 +00001036 goto dontcheckadj;
1037
1038 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1039 /* for broadcast circuits, snpa should be compared */
1040 /* FIXME : Point To Point */
1041
hassof390d2c2004-09-10 20:48:21 +00001042 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1043 {
1044 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1045 if (!adj)
1046 {
1047 zlog_info ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1048 "lifetime %us on %s",
1049 circuit->area->area_tag,
1050 rawlspid_print (hdr->lsp_id),
1051 ntohl (hdr->seq_num),
1052 ntohs (hdr->checksum),
1053 ntohs (hdr->rem_lifetime), circuit->interface->name);
1054 return ISIS_WARNING; /* Silently discard */
1055 }
jardineb5d44e2003-12-23 08:09:43 +00001056 }
jardineb5d44e2003-12-23 08:09:43 +00001057
1058 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001059 else
1060 {
1061 /* If no adj, or no sharing of level */
1062 if (!circuit->u.p2p.neighbor)
1063 {
1064 return ISIS_OK; /* Silently discard */
1065 }
1066 else
1067 {
1068 if (((level == 1) &&
1069 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1070 ((level == 2) &&
1071 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1072 return ISIS_WARNING; /* Silently discard */
1073 }
jardineb5d44e2003-12-23 08:09:43 +00001074 }
hassof390d2c2004-09-10 20:48:21 +00001075dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001076 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1077
1078 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1079
hassof390d2c2004-09-10 20:48:21 +00001080 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001081
hassof390d2c2004-09-10 20:48:21 +00001082 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1083 if (hdr->rem_lifetime == 0)
1084 {
1085 if (!lsp)
1086 {
1087 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1088 /* only needed on explicit update, eg - p2p */
1089 if (circuit->circ_type == CIRCUIT_T_P2P)
1090 ack_lsp (hdr, circuit, level);
1091 return retval; /* FIXME: do we need a purge? */
1092 }
1093 else
1094 {
1095 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1096 {
1097 /* LSP by some other system -> do 7.3.16.4 b) */
1098 /* 7.3.16.4 b) 1) */
1099 if (comp == LSP_NEWER)
1100 {
1101 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1102 /* ii */
1103 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1104 /* iii */
1105 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1106 /* v */
1107 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1108 /* iv */
1109 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1110 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001111
hassof390d2c2004-09-10 20:48:21 +00001112 } /* 7.3.16.4 b) 2) */
1113 else if (comp == LSP_EQUAL)
1114 {
1115 /* i */
1116 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1117 /* ii */
1118 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1119 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1120 } /* 7.3.16.4 b) 3) */
1121 else
1122 {
1123 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1124 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1125 }
1126 }
1127 else
1128 {
1129 /* our own LSP -> 7.3.16.4 c) */
1130 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1131 circuit->circuit_id
1132 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1133 circuit->circuit_id
1134 && circuit->u.bc.is_dr[level - 1] == 1))
1135 {
1136 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1137 zlog_info ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len));
1138 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1139 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1140 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1141 zlog_info
1142 ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1143 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1144 ntohl (lsp->lsp_header->seq_num));
1145 lsp->lsp_header->rem_lifetime =
1146 htons (isis_jitter
1147 (circuit->area->max_lsp_lifetime[level - 1],
1148 MAX_AGE_JITTER));
1149 }
1150 else
1151 {
1152 /* Got purge for own pseudo-lsp, and we are not DR */
1153 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1154 }
1155 }
1156 }
1157 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001158 }
jardineb5d44e2003-12-23 08:09:43 +00001159 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1160 * purge */
hassof390d2c2004-09-10 20:48:21 +00001161 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1162 {
1163 if (!lsp)
1164 {
1165 /* 7.3.16.4: initiate a purge */
1166 lsp_purge_non_exist (hdr, circuit->area);
1167 return ISIS_OK;
1168 }
1169 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1170
1171 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1172 * has information that the current sequence number for source S is
1173 * "greater" than that held by S, ... */
1174
1175 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1176 {
1177 /* 7.3.16.1 */
1178 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1179
1180 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1181 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1182
1183 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1184 zlog_info
1185 ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1186 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1187 ntohl (lsp->lsp_header->seq_num));
1188 lsp->lsp_header->rem_lifetime =
1189 htons (isis_jitter
1190 (circuit->area->max_lsp_lifetime[level - 1],
1191 MAX_AGE_JITTER));
1192 }
jardineb5d44e2003-12-23 08:09:43 +00001193 }
hassof390d2c2004-09-10 20:48:21 +00001194 else
1195 {
1196 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001197
hassof390d2c2004-09-10 20:48:21 +00001198 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1199 if ((!lsp || comp == LSP_NEWER))
1200 {
1201 /* i */
1202 if (lsp)
1203 {
jardineb5d44e2003-12-23 08:09:43 +00001204#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +00001205 zlog_info ("level %d number is - %ld", level,
1206 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001207#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001208 lsp_search_and_destroy (hdr->lsp_id,
1209 circuit->area->lspdb[level - 1]);
1210 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001211#ifdef EXTREME_DEBUG
hassof390d2c2004-09-10 20:48:21 +00001212 zlog_info ("level %d number is - %ld", level,
1213 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001214#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001215 }
1216 /*
1217 * If this lsp is a frag, need to see if we have zero lsp present
1218 */
1219 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1220 {
1221 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1222 LSP_FRAGMENT (lspid) = 0;
1223 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1224 if (!lsp0)
1225 {
1226 zlog_info ("Got lsp frag, while zero lsp not database");
1227 return ISIS_OK;
1228 }
1229 }
1230 lsp =
1231 lsp_new_from_stream_ptr (circuit->rcv_stream,
1232 ntohs (hdr->pdu_len), lsp0,
1233 circuit->area);
1234 lsp->level = level;
1235 lsp->adj = adj;
1236 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1237 /* ii */
1238 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1239 /* iii */
1240 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001241
hassof390d2c2004-09-10 20:48:21 +00001242 /* iv */
1243 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1244 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1245 /* FIXME: v) */
1246 }
1247 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1248 else if (comp == LSP_EQUAL)
1249 {
1250 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1251 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1252 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1253 {
1254 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1255 }
1256 }
1257 /* 7.3.15.1 e) 3) LSP older than the one in db */
1258 else
1259 {
1260 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1261 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1262 }
jardineb5d44e2003-12-23 08:09:43 +00001263 }
jardineb5d44e2003-12-23 08:09:43 +00001264 if (lsp)
1265 lsp->adj = adj;
1266 return retval;
1267}
1268
1269/*
1270 * Process Sequence Numbers
1271 * ISO - 10589
1272 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1273 */
1274
1275int
hassof390d2c2004-09-10 20:48:21 +00001276process_snp (int snp_type, int level, struct isis_circuit *circuit,
1277 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001278{
1279 int retval = ISIS_OK;
1280 int cmp, own_lsp;
1281 char typechar = ' ';
1282 int len;
1283 struct isis_adjacency *adj;
1284 struct isis_complete_seqnum_hdr *chdr = NULL;
1285 struct isis_partial_seqnum_hdr *phdr = NULL;
1286 uint32_t found = 0, expected = 0;
1287 struct isis_lsp *lsp;
1288 struct lsp_entry *entry;
hassof390d2c2004-09-10 20:48:21 +00001289 struct listnode *node, *node2;
jardineb5d44e2003-12-23 08:09:43 +00001290 struct tlvs tlvs;
1291 struct list *lsp_list = NULL;
1292 struct isis_passwd *passwd;
1293
hassof390d2c2004-09-10 20:48:21 +00001294 if (snp_type == ISIS_SNP_CSNP_FLAG)
1295 {
1296 /* getting the header info */
1297 typechar = 'C';
1298 chdr =
1299 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1300 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1301 len = ntohs (chdr->pdu_len);
1302 if (len < ISIS_CSNP_HDRLEN)
1303 {
1304 zlog_warn ("Received a CSNP with bogus length!");
1305 return ISIS_OK;
1306 }
jardineb5d44e2003-12-23 08:09:43 +00001307 }
hassof390d2c2004-09-10 20:48:21 +00001308 else
1309 {
1310 typechar = 'P';
1311 phdr =
1312 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1313 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1314 len = ntohs (phdr->pdu_len);
1315 if (len < ISIS_PSNP_HDRLEN)
1316 {
1317 zlog_warn ("Received a CSNP with bogus length!");
1318 return ISIS_OK;
1319 }
jardineb5d44e2003-12-23 08:09:43 +00001320 }
jardineb5d44e2003-12-23 08:09:43 +00001321
1322 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001323 if (circuit->ext_domain)
1324 {
jardineb5d44e2003-12-23 08:09:43 +00001325
hassof390d2c2004-09-10 20:48:21 +00001326 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1327 "skipping: circuit externalDomain = true",
jardineb5d44e2003-12-23 08:09:43 +00001328 circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001329 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001330
1331 return ISIS_OK;
1332 }
hassof390d2c2004-09-10 20:48:21 +00001333
1334 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1335 if (!accept_level (level, circuit->circuit_is_type))
1336 {
1337
1338 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1339 "skipping: circuit type %s does not match level %d",
1340 circuit->area->area_tag,
1341 level,
1342 typechar,
1343 circuit->interface->name,
1344 circuit_t2string (circuit->circuit_is_type), level);
1345
1346 return ISIS_OK;
1347 }
1348
1349 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1350 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1351 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1352 {
1353 if (!circuit->u.bc.is_dr[level - 1])
1354 {
1355
1356 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1357 "skipping: we are not the DIS",
1358 circuit->area->area_tag,
1359 level,
1360 typechar, snpa_print (ssnpa), circuit->interface->name);
1361
1362 return ISIS_OK;
1363 }
1364 }
jardineb5d44e2003-12-23 08:09:43 +00001365
1366 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1367
1368 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1369 * - already checked */
1370
1371 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1372 /* for broadcast circuits, snpa should be compared */
1373 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001374 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1375 {
1376 if (snp_type == ISIS_SNP_CSNP_FLAG)
1377 {
1378 adj =
1379 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1380 }
1381 else
1382 {
1383 /* a psnp on a broadcast, how lovely of Juniper :) */
1384 adj =
1385 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1386 }
1387 if (!adj)
1388 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001389 }
hassof390d2c2004-09-10 20:48:21 +00001390 else
1391 {
1392 if (!circuit->u.p2p.neighbor)
1393 return ISIS_OK; /* Silently discard */
1394 }
jardineb5d44e2003-12-23 08:09:43 +00001395
1396 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1397
1398 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1399
1400 memset (&tlvs, 0, sizeof (struct tlvs));
1401
1402 /* parse the SNP */
1403 expected |= TLVFLAG_LSP_ENTRIES;
1404 expected |= TLVFLAG_AUTH_INFO;
1405 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001406 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001407 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001408 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001409
hassof390d2c2004-09-10 20:48:21 +00001410 if (retval > ISIS_WARNING)
1411 {
1412 zlog_warn ("something went very wrong processing SNP");
1413 free_tlvs (&tlvs);
1414 return retval;
1415 }
jardineb5d44e2003-12-23 08:09:43 +00001416
1417 (level == 1) ? (passwd = &circuit->area->area_passwd) :
hassof390d2c2004-09-10 20:48:21 +00001418 (passwd = &circuit->area->domain_passwd);
1419 if (passwd->type)
1420 {
1421 if (!(found & TLVFLAG_AUTH_INFO) ||
1422 authentication_check (passwd, &tlvs.auth_info))
1423 {
1424 isis_event_auth_failure (circuit->area->area_tag,
1425 "SNP authentication" " failure",
1426 phdr ? phdr->source_id : chdr->source_id);
1427 return ISIS_OK;
1428 }
1429 }
jardineb5d44e2003-12-23 08:09:43 +00001430
1431 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001432 if (isis->debugs & DEBUG_SNP_PACKETS)
1433 {
1434 zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1435 circuit->area->area_tag,
1436 level,
1437 typechar, snpa_print (ssnpa), circuit->interface->name);
1438 if (tlvs.lsp_entries)
1439 {
1440 LIST_LOOP (tlvs.lsp_entries, entry, node)
1441 {
1442 zlog_info ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1443 " cksum 0x%04x, lifetime %us",
1444 circuit->area->area_tag,
1445 typechar,
1446 rawlspid_print (entry->lsp_id),
1447 ntohl (entry->seq_num),
1448 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
1449 }
1450 }
jardineb5d44e2003-12-23 08:09:43 +00001451 }
jardineb5d44e2003-12-23 08:09:43 +00001452
1453 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001454 if (tlvs.lsp_entries)
1455 {
1456 LIST_LOOP (tlvs.lsp_entries, entry, node)
1457 {
1458 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1459 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1460 if (lsp)
1461 {
1462 /* 7.3.15.2 b) 1) is this LSP newer */
1463 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1464 entry->checksum, entry->rem_lifetime);
1465 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1466 if (cmp == LSP_EQUAL)
1467 {
1468 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1469 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1470 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1471 }
1472 else if (cmp == LSP_OLDER)
1473 {
1474 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1475 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1476 }
1477 else
1478 {
1479 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1480 * on p2p */
1481 if (own_lsp)
1482 {
1483 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1484 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1485 }
1486 else
1487 {
1488 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1489 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1490 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1491 }
1492 }
1493 }
1494 else
1495 {
1496 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1497 * insert it and set SSN on it */
1498 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1499 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1500 {
1501 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1502 0, 0, entry->checksum, level);
1503 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1504 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1505 }
1506 }
jardineb5d44e2003-12-23 08:09:43 +00001507 }
1508 }
jardineb5d44e2003-12-23 08:09:43 +00001509
1510 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001511 if (snp_type == ISIS_SNP_CSNP_FLAG)
1512 {
1513 /*
1514 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1515 */
1516 lsp_list = list_new ();
1517 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1518 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001519
hassof390d2c2004-09-10 20:48:21 +00001520 /* Fixme: Find a better solution */
1521 if (tlvs.lsp_entries)
1522 {
1523 LIST_LOOP (tlvs.lsp_entries, entry, node)
1524 {
1525 LIST_LOOP (lsp_list, lsp, node2)
1526 {
1527 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1528 {
1529 list_delete_node (lsp_list, node2);
1530 break;
1531 }
1532 }
1533 }
1534 }
1535 /* on remaining LSPs we set SRM (neighbor knew not of) */
1536 LIST_LOOP (lsp_list, lsp, node2)
1537 {
1538 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001539 }
hassof390d2c2004-09-10 20:48:21 +00001540 /* lets free it */
1541 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001542 }
jardineb5d44e2003-12-23 08:09:43 +00001543
1544 free_tlvs (&tlvs);
1545 return retval;
1546}
1547
1548int
hassof390d2c2004-09-10 20:48:21 +00001549process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001550{
jardineb5d44e2003-12-23 08:09:43 +00001551 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001552 if ((stream_get_endp (circuit->rcv_stream) -
1553 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1554 {
1555 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1556 return ISIS_WARNING;
1557 }
jardineb5d44e2003-12-23 08:09:43 +00001558
1559 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1560}
1561
hassof390d2c2004-09-10 20:48:21 +00001562int
1563process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001564{
hassof390d2c2004-09-10 20:48:21 +00001565 if ((stream_get_endp (circuit->rcv_stream) -
1566 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1567 {
1568 zlog_warn ("Packet too short");
1569 return ISIS_WARNING;
1570 }
jardineb5d44e2003-12-23 08:09:43 +00001571
1572 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1573}
1574
jardineb5d44e2003-12-23 08:09:43 +00001575/*
1576 * Process ISH
1577 * ISO - 10589
1578 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1579 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001580 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1581 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1582 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001583 */
1584int
1585process_is_hello (struct isis_circuit *circuit)
1586{
1587 struct isis_adjacency *adj;
1588 int retval = ISIS_OK;
1589 u_char neigh_len;
1590 u_char *sysid;
1591
1592 /* In this point in time we are not yet able to handle is_hellos
1593 * on lan - Sorry juniper...
1594 */
1595 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1596 return retval;
1597
1598 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001599 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001600 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001601 if (!adj)
1602 {
1603 /* 8.2.2 */
1604 adj = isis_new_adj (sysid, " ", 0, circuit);
1605 if (adj == NULL)
1606 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001607
hassof390d2c2004-09-10 20:48:21 +00001608 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1609 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1610 circuit->u.p2p.neighbor = adj;
1611 }
1612 /* 8.2.2 a) */
1613 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1614 ISIS_SYS_ID_LEN))
1615 {
1616 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1617 /* 8.2.2 a) 2) delete the adj */
1618 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1619 /* 8.2.2 a) 3) create a new adj */
1620 adj = isis_new_adj (sysid, " ", 0, circuit);
1621 if (adj == NULL)
1622 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001623
hassof390d2c2004-09-10 20:48:21 +00001624 /* 8.2.2 a) 3) i */
1625 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1626 /* 8.2.2 a) 3) ii */
1627 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1628 /* 8.2.2 a) 4) quite meaningless */
1629 }
jardineb5d44e2003-12-23 08:09:43 +00001630 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001631 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1632 (adj->sys_type == ISIS_SYSTYPE_IS))
1633 {
1634 /* do nothing */
1635 }
1636 else
1637 {
1638 /* 8.2.2 c) respond with a p2p IIH */
1639 send_hello (circuit, 1);
1640 }
jardineb5d44e2003-12-23 08:09:43 +00001641 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001642 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001643 /* 8.2.2 e) FIXME: Circuit type of? */
1644
jardineb5d44e2003-12-23 08:09:43 +00001645 return retval;
1646}
1647
jardineb5d44e2003-12-23 08:09:43 +00001648/*
1649 * PDU Dispatcher
1650 */
1651
hassof390d2c2004-09-10 20:48:21 +00001652int
1653isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001654{
jardineb5d44e2003-12-23 08:09:43 +00001655 struct isis_fixed_hdr *hdr;
1656 struct esis_fixed_hdr *esis_hdr;
1657
hassof390d2c2004-09-10 20:48:21 +00001658 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001659
1660 /*
1661 * Let's first read data from stream to the header
1662 */
hassof390d2c2004-09-10 20:48:21 +00001663 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001664
hassof390d2c2004-09-10 20:48:21 +00001665 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1666 {
1667 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1668 return ISIS_ERROR;
1669 }
jardineb5d44e2003-12-23 08:09:43 +00001670
1671 /* now we need to know if this is an ISO 9542 packet and
1672 * take real good care of it, waaa!
1673 */
hassof390d2c2004-09-10 20:48:21 +00001674 if (hdr->idrp == ISO9542_ESIS)
1675 {
1676 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1677 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1678 /* FIXME: Need to do some acceptence tests */
1679 /* example length... */
1680 switch (esis_hdr->pdu_type)
1681 {
1682 case ESH_PDU:
1683 /* FIXME */
1684 break;
1685 case ISH_PDU:
1686 zlog_info ("AN ISH PDU!!");
1687 retval = process_is_hello (circuit);
1688 break;
1689 default:
1690 return ISIS_ERROR;
1691 }
1692 return retval;
1693 }
1694 else
1695 {
1696 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1697 }
jardineb5d44e2003-12-23 08:09:43 +00001698 /*
1699 * and then process it
1700 */
1701
hassof390d2c2004-09-10 20:48:21 +00001702 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1703 {
1704 zlog_err ("Fixed header length = %d", hdr->length);
1705 return ISIS_ERROR;
1706 }
jardineb5d44e2003-12-23 08:09:43 +00001707
hassof390d2c2004-09-10 20:48:21 +00001708 if (hdr->version1 != 1)
1709 {
1710 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1711 return ISIS_WARNING;
1712 }
jardineb5d44e2003-12-23 08:09:43 +00001713 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001714 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1715 {
1716 zlog_err
1717 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1718 "while the parameter for this IS is %u", hdr->id_len,
1719 ISIS_SYS_ID_LEN);
1720 return ISIS_ERROR;
1721 }
jardineb5d44e2003-12-23 08:09:43 +00001722
hassof390d2c2004-09-10 20:48:21 +00001723 if (hdr->version2 != 1)
1724 {
1725 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1726 return ISIS_WARNING;
1727 }
jardineb5d44e2003-12-23 08:09:43 +00001728 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001729 if ((hdr->max_area_addrs != 0)
1730 && (hdr->max_area_addrs != isis->max_area_addrs))
1731 {
1732 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1733 "received PDU %u while the parameter for this IS is %u",
1734 hdr->max_area_addrs, isis->max_area_addrs);
1735 return ISIS_ERROR;
1736 }
jardineb5d44e2003-12-23 08:09:43 +00001737
hassof390d2c2004-09-10 20:48:21 +00001738 switch (hdr->pdu_type)
1739 {
1740 case L1_LAN_HELLO:
1741 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1742 break;
1743 case L2_LAN_HELLO:
1744 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1745 break;
1746 case P2P_HELLO:
1747 retval = process_p2p_hello (circuit);
1748 break;
1749 case L1_LINK_STATE:
1750 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1751 break;
1752 case L2_LINK_STATE:
1753 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1754 break;
1755 case L1_COMPLETE_SEQ_NUM:
1756 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1757 break;
1758 case L2_COMPLETE_SEQ_NUM:
1759 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1760 break;
1761 case L1_PARTIAL_SEQ_NUM:
1762 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1763 break;
1764 case L2_PARTIAL_SEQ_NUM:
1765 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1766 break;
1767 default:
1768 return ISIS_ERROR;
1769 }
jardineb5d44e2003-12-23 08:09:43 +00001770
1771 return retval;
1772}
1773
jardineb5d44e2003-12-23 08:09:43 +00001774#ifdef GNU_LINUX
1775int
1776isis_receive (struct thread *thread)
1777{
jardineb5d44e2003-12-23 08:09:43 +00001778 struct isis_circuit *circuit;
1779 u_char ssnpa[ETH_ALEN];
1780 int retval;
1781
1782 /*
1783 * Get the circuit
1784 */
1785 circuit = THREAD_ARG (thread);
1786 assert (circuit);
1787
1788 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001789 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001790 else
1791 stream_reset (circuit->rcv_stream);
1792
1793 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001794 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001795
1796 if (retval == ISIS_OK)
1797 retval = isis_handle_pdu (circuit, ssnpa);
1798
1799 /*
1800 * prepare for next packet.
1801 */
hassof390d2c2004-09-10 20:48:21 +00001802 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1803 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001804
1805 return retval;
1806}
1807
1808#else
1809int
1810isis_receive (struct thread *thread)
1811{
jardineb5d44e2003-12-23 08:09:43 +00001812 struct isis_circuit *circuit;
1813 u_char ssnpa[ETH_ALEN];
1814 int retval;
1815
1816 /*
1817 * Get the circuit
1818 */
1819 circuit = THREAD_ARG (thread);
1820 assert (circuit);
1821
hassof390d2c2004-09-10 20:48:21 +00001822 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001823
1824 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001825 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001826 else
1827 stream_reset (circuit->rcv_stream);
1828
1829 retval = circuit->rx (circuit, ssnpa);
1830
1831 if (retval == ISIS_OK)
1832 retval = isis_handle_pdu (circuit, ssnpa);
1833
1834 /*
1835 * prepare for next packet.
1836 */
hassof390d2c2004-09-10 20:48:21 +00001837 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1838 listcount
1839 (circuit->area->circuit_list) *
1840 100);
jardineb5d44e2003-12-23 08:09:43 +00001841
1842 return retval;
1843}
1844
1845#endif
1846
1847 /* filling of the fixed isis header */
1848void
1849fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1850{
1851 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1852
1853 hdr->idrp = ISO10589_ISIS;
1854
hassof390d2c2004-09-10 20:48:21 +00001855 switch (pdu_type)
1856 {
1857 case L1_LAN_HELLO:
1858 case L2_LAN_HELLO:
1859 hdr->length = ISIS_LANHELLO_HDRLEN;
1860 break;
1861 case P2P_HELLO:
1862 hdr->length = ISIS_P2PHELLO_HDRLEN;
1863 break;
1864 case L1_LINK_STATE:
1865 case L2_LINK_STATE:
1866 hdr->length = ISIS_LSP_HDR_LEN;
1867 break;
1868 case L1_COMPLETE_SEQ_NUM:
1869 case L2_COMPLETE_SEQ_NUM:
1870 hdr->length = ISIS_CSNP_HDRLEN;
1871 break;
1872 case L1_PARTIAL_SEQ_NUM:
1873 case L2_PARTIAL_SEQ_NUM:
1874 hdr->length = ISIS_PSNP_HDRLEN;
1875 break;
1876 default:
1877 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1878 return;
1879 }
jardineb5d44e2003-12-23 08:09:43 +00001880 hdr->length += ISIS_FIXED_HDR_LEN;
1881 hdr->pdu_type = pdu_type;
1882 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001883 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001884 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001885 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001886}
1887
jardineb5d44e2003-12-23 08:09:43 +00001888/*
1889 * SEND SIDE
1890 */
1891void
1892fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001893 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001894{
hassof390d2c2004-09-10 20:48:21 +00001895 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001896
1897 stream_putc (stream, hdr->idrp);
1898 stream_putc (stream, hdr->length);
1899 stream_putc (stream, hdr->version1);
1900 stream_putc (stream, hdr->id_len);
1901 stream_putc (stream, hdr->pdu_type);
1902 stream_putc (stream, hdr->version2);
1903 stream_putc (stream, hdr->reserved);
1904 stream_putc (stream, hdr->max_area_addrs);
1905
1906 return;
1907}
1908
jardineb5d44e2003-12-23 08:09:43 +00001909int
1910send_hello (struct isis_circuit *circuit, int level)
1911{
1912 struct isis_fixed_hdr fixed_hdr;
1913 struct isis_lan_hello_hdr hello_hdr;
1914 struct isis_p2p_hello_hdr p2p_hello_hdr;
1915
1916 u_int32_t interval;
1917 unsigned long len_pointer, length;
1918 int retval;
1919
hassof390d2c2004-09-10 20:48:21 +00001920 if (circuit->interface->mtu == 0)
1921 {
1922 zlog_warn ("circuit has zero MTU");
1923 return ISIS_WARNING;
1924 }
jardineb5d44e2003-12-23 08:09:43 +00001925
1926 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001927 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001928 else
1929 stream_reset (circuit->snd_stream);
1930
1931 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1932 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001933 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1934 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001935 else
hassof390d2c2004-09-10 20:48:21 +00001936 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1937 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001938 else
hassof390d2c2004-09-10 20:48:21 +00001939 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001940
1941 /*
1942 * Fill LAN Level 1 or 2 Hello PDU header
1943 */
1944 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001945 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001946 circuit->hello_interval[level - 1];
1947 if (interval > USHRT_MAX)
1948 interval = USHRT_MAX;
1949 hello_hdr.circuit_t = circuit->circuit_is_type;
1950 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001951 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001952
hassof390d2c2004-09-10 20:48:21 +00001953 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
1954 len_pointer = stream_get_putp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001955
1956 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001957 if (circuit->circ_type == CIRCUIT_T_P2P)
1958 {
1959 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1960 p2p_hello_hdr.local_id = circuit->circuit_id;
1961 /* FIXME: need better understanding */
1962 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001963 }
hassof390d2c2004-09-10 20:48:21 +00001964 else
1965 {
1966 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1967 if (level == 1 && circuit->u.bc.l1_desig_is)
1968 {
1969 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1970 ISIS_SYS_ID_LEN + 1);
1971 }
1972 else if (level == 2 && circuit->u.bc.l2_desig_is)
1973 {
1974 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1975 ISIS_SYS_ID_LEN + 1);
1976 }
1977 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1978 }
jardineb5d44e2003-12-23 08:09:43 +00001979
1980 /*
1981 * Then the variable length part
1982 */
1983 /* add circuit password */
1984 if (circuit->passwd.type)
1985 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1986 circuit->passwd.passwd, circuit->snd_stream))
1987 return ISIS_WARNING;
1988 /* Area Addresses TLV */
1989 assert (circuit->area);
1990 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1991 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1992 return ISIS_WARNING;
1993
1994 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00001995 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1996 {
1997 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1998 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1999 circuit->snd_stream))
2000 return ISIS_WARNING;
2001 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
2002 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2003 circuit->snd_stream))
2004 return ISIS_WARNING;
2005 }
jardineb5d44e2003-12-23 08:09:43 +00002006
2007 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002008 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002009 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2010 return ISIS_WARNING;
2011 /* IP interface Address TLV */
2012 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2013 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2014 return ISIS_WARNING;
2015
hassof390d2c2004-09-10 20:48:21 +00002016#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002017 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002018 if (circuit->ipv6_router && circuit->ipv6_link &&
jardineb5d44e2003-12-23 08:09:43 +00002019 circuit->ipv6_link->count > 0)
2020 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2021 return ISIS_WARNING;
2022#endif /* HAVE_IPV6 */
2023
2024 if (circuit->u.bc.pad_hellos)
2025 if (tlv_add_padding (circuit->snd_stream))
2026 return ISIS_WARNING;
2027
2028 length = stream_get_putp (circuit->snd_stream);
2029 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002030 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002031
2032 retval = circuit->tx (circuit, level);
2033 if (retval)
2034 zlog_warn ("sending of LAN Level %d Hello failed", level);
2035
2036 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002037 if (isis->debugs & DEBUG_ADJ_PACKETS)
2038 {
2039 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2040 {
2041 zlog_info ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2042 circuit->area->area_tag, level, circuit->interface->name,
2043 STREAM_SIZE (circuit->snd_stream));
2044 }
2045 else
2046 {
2047 zlog_info ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2048 circuit->area->area_tag, circuit->interface->name,
2049 STREAM_SIZE (circuit->snd_stream));
2050 }
jardineb5d44e2003-12-23 08:09:43 +00002051 }
jardineb5d44e2003-12-23 08:09:43 +00002052
2053 return retval;
2054}
2055
2056int
2057send_lan_hello (struct isis_circuit *circuit, int level)
2058{
hassof390d2c2004-09-10 20:48:21 +00002059 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002060}
2061
2062int
2063send_lan_l1_hello (struct thread *thread)
2064{
jardineb5d44e2003-12-23 08:09:43 +00002065 struct isis_circuit *circuit;
2066 int retval;
2067
2068 circuit = THREAD_ARG (thread);
2069 assert (circuit);
2070 circuit->u.bc.t_send_lan_hello[0] = NULL;
2071
2072 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002073 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002074
2075 retval = send_lan_hello (circuit, 1);
2076
2077 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002078 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2079 send_lan_l1_hello, circuit,
2080 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002081
2082 return retval;
2083}
2084
2085int
2086send_lan_l2_hello (struct thread *thread)
2087{
2088 struct isis_circuit *circuit;
2089 int retval;
2090
2091 circuit = THREAD_ARG (thread);
2092 assert (circuit);
2093 circuit->u.bc.t_send_lan_hello[1] = NULL;
2094
2095 if (circuit->u.bc.run_dr_elect[1])
2096 retval = isis_dr_elect (circuit, 2);
2097
2098 retval = send_lan_hello (circuit, 2);
2099
hassof390d2c2004-09-10 20:48:21 +00002100 /* set next timer thread */
2101 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2102 send_lan_l2_hello, circuit,
2103 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002104
2105 return retval;
2106}
2107
2108int
2109send_p2p_hello (struct thread *thread)
2110{
2111 struct isis_circuit *circuit;
2112
2113 circuit = THREAD_ARG (thread);
2114 assert (circuit);
2115 circuit->u.p2p.t_send_p2p_hello = NULL;
2116
hassof390d2c2004-09-10 20:48:21 +00002117 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002118
hassof390d2c2004-09-10 20:48:21 +00002119 /* set next timer thread */
2120 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2121 circuit, isis_jitter (circuit->hello_interval[1],
2122 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002123
2124 return ISIS_OK;
2125}
2126
2127int
hassof390d2c2004-09-10 20:48:21 +00002128build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2129 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002130{
2131 struct isis_fixed_hdr fixed_hdr;
2132 struct isis_passwd *passwd;
2133 int retval = ISIS_OK;
2134 unsigned long lenp;
2135 u_int16_t length;
2136
hassof390d2c2004-09-10 20:48:21 +00002137 if (level == 1)
2138 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2139 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002140 else
hassof390d2c2004-09-10 20:48:21 +00002141 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2142 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002143
2144 /*
2145 * Fill Level 1 or 2 Complete Sequence Numbers header
2146 */
2147
2148 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002149 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002150 /* no need to send the source here, it is always us if we csnp */
2151 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2152 /* with zero circuit id - ref 9.10, 9.11 */
2153 stream_putc (circuit->snd_stream, 0x00);
2154
2155 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2156 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2157
2158 /*
2159 * And TLVs
2160 */
2161 if (level == 1)
2162 passwd = &circuit->area->area_passwd;
2163 else
2164 passwd = &circuit->area->domain_passwd;
2165
2166 if (passwd->type)
2167 retval = tlv_add_authinfo (passwd->type, passwd->len,
2168 passwd->passwd, circuit->snd_stream);
2169
hassof390d2c2004-09-10 20:48:21 +00002170 if (!retval && lsps)
2171 {
2172 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2173 }
2174 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002175 assert (length >= ISIS_CSNP_HDRLEN);
2176 /* Update PU length */
2177 stream_putw_at (circuit->snd_stream, lenp, length);
2178
2179 return retval;
2180}
2181
2182/*
2183 * FIXME: support multiple CSNPs
2184 */
2185
2186int
2187send_csnp (struct isis_circuit *circuit, int level)
2188{
2189 int retval = ISIS_OK;
2190 u_char start[ISIS_SYS_ID_LEN + 2];
2191 u_char stop[ISIS_SYS_ID_LEN + 2];
2192 struct list *list = NULL;
2193 struct listnode *node;
2194 struct isis_lsp *lsp;
2195
hassof390d2c2004-09-10 20:48:21 +00002196 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002197 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2198
hassof390d2c2004-09-10 20:48:21 +00002199 if (circuit->area->lspdb[level - 1] &&
2200 dict_count (circuit->area->lspdb[level - 1]) > 0)
2201 {
2202 list = list_new ();
2203 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002204
hassof390d2c2004-09-10 20:48:21 +00002205 if (circuit->snd_stream == NULL)
2206 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2207 else
2208 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002209
hassof390d2c2004-09-10 20:48:21 +00002210 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002211
hassof390d2c2004-09-10 20:48:21 +00002212 if (isis->debugs & DEBUG_SNP_PACKETS)
2213 {
2214 zlog_info ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2215 circuit->area->area_tag, level, circuit->interface->name,
2216 STREAM_SIZE (circuit->snd_stream));
2217 LIST_LOOP (list, lsp, node)
2218 {
2219 zlog_info ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2220 " cksum 0x%04x, lifetime %us",
2221 circuit->area->area_tag,
2222 rawlspid_print (lsp->lsp_header->lsp_id),
2223 ntohl (lsp->lsp_header->seq_num),
2224 ntohs (lsp->lsp_header->checksum),
2225 ntohs (lsp->lsp_header->rem_lifetime));
2226 }
2227 }
2228
2229 list_delete (list);
2230
2231 if (retval == ISIS_OK)
2232 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002233 }
jardineb5d44e2003-12-23 08:09:43 +00002234 return retval;
2235}
2236
2237int
2238send_l1_csnp (struct thread *thread)
2239{
2240 struct isis_circuit *circuit;
2241 int retval = ISIS_OK;
2242
2243 circuit = THREAD_ARG (thread);
2244 assert (circuit);
2245
2246 circuit->t_send_csnp[0] = NULL;
2247
hassof390d2c2004-09-10 20:48:21 +00002248 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2249 {
2250 send_csnp (circuit, 1);
2251 }
jardineb5d44e2003-12-23 08:09:43 +00002252 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002253 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2254 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002255
2256 return retval;
2257}
2258
2259int
2260send_l2_csnp (struct thread *thread)
2261{
2262 struct isis_circuit *circuit;
2263 int retval = ISIS_OK;
2264
2265 circuit = THREAD_ARG (thread);
2266 assert (circuit);
2267
2268 circuit->t_send_csnp[1] = NULL;
2269
hassof390d2c2004-09-10 20:48:21 +00002270 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2271 {
2272 send_csnp (circuit, 2);
2273 }
jardineb5d44e2003-12-23 08:09:43 +00002274 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002275 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2276 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002277
jardineb5d44e2003-12-23 08:09:43 +00002278 return retval;
2279}
2280
2281int
2282build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2283{
2284 struct isis_fixed_hdr fixed_hdr;
2285 unsigned long lenp;
2286 u_int16_t length;
2287 int retval = 0;
2288 struct isis_lsp *lsp;
2289 struct isis_passwd *passwd;
2290 struct listnode *node;
2291
2292 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002293 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2294 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002295 else
2296 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002297 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002298
2299 /*
2300 * Fill Level 1 or 2 Partial Sequence Numbers header
2301 */
2302 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002303 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002304 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2305 stream_putc (circuit->snd_stream, circuit->idx);
2306
2307 /*
2308 * And TLVs
2309 */
2310
2311 if (level == 1)
2312 passwd = &circuit->area->area_passwd;
2313 else
2314 passwd = &circuit->area->domain_passwd;
2315
2316 if (passwd->type)
2317 retval = tlv_add_authinfo (passwd->type, passwd->len,
2318 passwd->passwd, circuit->snd_stream);
2319
hassof390d2c2004-09-10 20:48:21 +00002320 if (!retval && lsps)
2321 {
2322 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002323 }
jardineb5d44e2003-12-23 08:09:43 +00002324
hassof390d2c2004-09-10 20:48:21 +00002325 if (isis->debugs & DEBUG_SNP_PACKETS)
2326 {
2327 LIST_LOOP (lsps, lsp, node)
2328 {
2329 zlog_info ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2330 " cksum 0x%04x, lifetime %us",
2331 circuit->area->area_tag,
2332 rawlspid_print (lsp->lsp_header->lsp_id),
2333 ntohl (lsp->lsp_header->seq_num),
2334 ntohs (lsp->lsp_header->checksum),
2335 ntohs (lsp->lsp_header->rem_lifetime));
2336 }
2337 }
2338
2339 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002340 assert (length >= ISIS_PSNP_HDRLEN);
2341 /* Update PDU length */
2342 stream_putw_at (circuit->snd_stream, lenp, length);
2343
2344 return ISIS_OK;
2345}
2346
2347/*
2348 * 7.3.15.4 action on expiration of partial SNP interval
2349 * level 1
2350 */
2351int
2352send_psnp (int level, struct isis_circuit *circuit)
2353{
2354 int retval = ISIS_OK;
2355 struct isis_lsp *lsp;
2356 struct list *list = NULL;
2357 struct listnode *node;
2358
hassof390d2c2004-09-10 20:48:21 +00002359 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002360 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002361 circuit->circ_type != CIRCUIT_T_BROADCAST)
2362 {
jardineb5d44e2003-12-23 08:09:43 +00002363
hassof390d2c2004-09-10 20:48:21 +00002364 if (circuit->area->lspdb[level - 1] &&
2365 dict_count (circuit->area->lspdb[level - 1]) > 0)
2366 {
2367 list = list_new ();
2368 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002369
hassof390d2c2004-09-10 20:48:21 +00002370 if (listcount (list) > 0)
2371 {
2372 if (circuit->snd_stream == NULL)
2373 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2374 else
2375 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002376
2377
hassof390d2c2004-09-10 20:48:21 +00002378 if (isis->debugs & DEBUG_SNP_PACKETS)
2379 zlog_info ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2380 circuit->area->area_tag, level,
2381 circuit->interface->name,
2382 STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002383
hassof390d2c2004-09-10 20:48:21 +00002384 retval = build_psnp (level, circuit, list);
2385 if (retval == ISIS_OK)
2386 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002387
hassof390d2c2004-09-10 20:48:21 +00002388 if (retval == ISIS_OK)
2389 {
2390 /*
2391 * sending succeeded, we can clear SSN flags of this circuit
2392 * for the LSPs in list
2393 */
2394 for (node = listhead (list); node; nextnode (node))
2395 {
2396 lsp = getdata (node);
2397 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2398 }
2399 }
2400 }
2401 list_delete (list);
2402 }
jardineb5d44e2003-12-23 08:09:43 +00002403 }
jardineb5d44e2003-12-23 08:09:43 +00002404
2405 return retval;
2406}
2407
2408int
2409send_l1_psnp (struct thread *thread)
2410{
2411
2412 struct isis_circuit *circuit;
2413 int retval = ISIS_OK;
2414
2415 circuit = THREAD_ARG (thread);
2416 assert (circuit);
2417
2418 circuit->t_send_psnp[0] = NULL;
2419
2420 send_psnp (1, circuit);
2421 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002422 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2423 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002424
2425 return retval;
2426}
2427
2428/*
2429 * 7.3.15.4 action on expiration of partial SNP interval
2430 * level 2
2431 */
2432int
2433send_l2_psnp (struct thread *thread)
2434{
jardineb5d44e2003-12-23 08:09:43 +00002435 struct isis_circuit *circuit;
2436 int retval = ISIS_OK;
2437
2438 circuit = THREAD_ARG (thread);
2439 assert (circuit);
2440
2441 circuit->t_send_psnp[1] = NULL;
2442
2443 send_psnp (2, circuit);
2444
2445 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002446 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2447 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002448
2449 return retval;
2450}
2451
jardineb5d44e2003-12-23 08:09:43 +00002452void
2453build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit,
hassof390d2c2004-09-10 20:48:21 +00002454 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002455{
2456 unsigned long length;
2457
hassof390d2c2004-09-10 20:48:21 +00002458 stream_put (stream, lsp->pdu, ntohs (lsp->lsp_header->pdu_len));
2459 length = stream_get_putp (stream);
jardineb5d44e2003-12-23 08:09:43 +00002460
2461 return;
2462}
2463
jardineb5d44e2003-12-23 08:09:43 +00002464/*
2465 * ISO 10589 - 7.3.14.3
2466 */
2467int
2468send_lsp (struct thread *thread)
2469{
2470 struct isis_circuit *circuit;
2471 struct isis_lsp *lsp;
2472 struct listnode *node;
2473 int retval = 0;
2474
2475 circuit = THREAD_ARG (thread);
2476 assert (circuit);
2477
hassof390d2c2004-09-10 20:48:21 +00002478 if (circuit->state == C_STATE_UP)
2479 {
2480 node = listhead (circuit->lsp_queue);
2481 assert (node);
jardineb5d44e2003-12-23 08:09:43 +00002482
hassof390d2c2004-09-10 20:48:21 +00002483 lsp = getdata (node);
jardineb5d44e2003-12-23 08:09:43 +00002484
2485 /*
hassof390d2c2004-09-10 20:48:21 +00002486 * Do not send if levels do not match
jardineb5d44e2003-12-23 08:09:43 +00002487 */
hassof390d2c2004-09-10 20:48:21 +00002488 if (!(lsp->level & circuit->circuit_is_type))
2489 goto dontsend;
jardineb5d44e2003-12-23 08:09:43 +00002490
hassof390d2c2004-09-10 20:48:21 +00002491 /*
2492 * Do not send if we do not have adjacencies in state up on the circuit
2493 */
2494 if (circuit->upadjcount[lsp->level - 1] == 0)
2495 goto dontsend;
2496 /* only send if it needs sending */
2497 if ((time (NULL) - lsp->last_sent) >=
2498 circuit->area->lsp_gen_interval[lsp->level - 1])
2499 {
jardineb5d44e2003-12-23 08:09:43 +00002500
hassof390d2c2004-09-10 20:48:21 +00002501 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2502 {
2503 zlog_info
2504 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2505 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2506 rawlspid_print (lsp->lsp_header->lsp_id),
2507 ntohl (lsp->lsp_header->seq_num),
2508 ntohs (lsp->lsp_header->checksum),
2509 ntohs (lsp->lsp_header->rem_lifetime),
2510 circuit->interface->name);
2511 }
2512 /* copy our lsp to the send buffer */
2513 circuit->snd_stream->getp = lsp->pdu->getp;
2514 circuit->snd_stream->putp = lsp->pdu->putp;
2515 circuit->snd_stream->endp = lsp->pdu->endp;
2516 memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp);
2517
2518 retval = circuit->tx (circuit, lsp->level);
2519
jardineb5d44e2003-12-23 08:09:43 +00002520 /*
hassof390d2c2004-09-10 20:48:21 +00002521 * If the sending succeeded, we can del the lsp from circuits
2522 * lsp_queue
jardineb5d44e2003-12-23 08:09:43 +00002523 */
hassof390d2c2004-09-10 20:48:21 +00002524 if (retval == ISIS_OK)
2525 {
2526 list_delete_node (circuit->lsp_queue, node);
2527
2528 /*
2529 * On broadcast circuits also the SRMflag can be cleared
2530 */
2531 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2532 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2533
2534 if (flags_any_set (lsp->SRMflags) == 0)
2535 {
2536 /*
2537 * need to remember when we were last sent
2538 */
2539 lsp->last_sent = time (NULL);
2540 }
2541 }
2542 else
2543 {
2544 zlog_info ("sending of level %d link state failed", lsp->level);
2545 }
jardineb5d44e2003-12-23 08:09:43 +00002546 }
hassof390d2c2004-09-10 20:48:21 +00002547 else
2548 {
2549 /* my belief is that if it wasn't his time, the lsp can be removed
2550 * from the queue
2551 */
2552 dontsend:
2553 list_delete_node (circuit->lsp_queue, node);
2554 }
jardineb5d44e2003-12-23 08:09:43 +00002555#if 0
hassof390d2c2004-09-10 20:48:21 +00002556 /*
2557 * If there are still LSPs send next one after lsp-interval (33 msecs)
2558 */
2559 if (listcount (circuit->lsp_queue) > 0)
2560 thread_add_timer (master, send_lsp, circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002561#endif
hassof390d2c2004-09-10 20:48:21 +00002562 }
jardineb5d44e2003-12-23 08:09:43 +00002563
2564 return retval;
hassof390d2c2004-09-10 20:48:21 +00002565}
jardineb5d44e2003-12-23 08:09:43 +00002566
2567int
hassof390d2c2004-09-10 20:48:21 +00002568ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2569 int level)
jardineb5d44e2003-12-23 08:09:43 +00002570{
2571 unsigned long lenp;
2572 int retval;
2573 u_int16_t length;
2574 struct isis_fixed_hdr fixed_hdr;
2575
2576 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002577 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002578 else
2579 stream_reset (circuit->snd_stream);
2580
2581// fill_llc_hdr (stream);
2582 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002583 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2584 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002585 else
hassof390d2c2004-09-10 20:48:21 +00002586 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2587 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002588
2589
2590 lenp = stream_get_putp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002591 stream_putw (circuit->snd_stream, 0); /* PDU length */
2592 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002593 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002594 stream_putc (circuit->snd_stream, 9); /* code */
2595 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002596
hassof390d2c2004-09-10 20:48:21 +00002597 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2598 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2599 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2600 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002601
hassof390d2c2004-09-10 20:48:21 +00002602 length = (u_int16_t) stream_get_putp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002603 /* Update PDU length */
2604 stream_putw_at (circuit->snd_stream, lenp, length);
2605
2606 retval = circuit->tx (circuit, level);
2607
2608 return retval;
2609}
2610
2611#if 0
2612/*
2613 * ISH PDU Processing
2614 */
2615
jardineb5d44e2003-12-23 08:09:43 +00002616 /*
2617 * Let's first check if the local and remote system have any common area
2618 * addresses
2619 */
hassof390d2c2004-09-10 20:48:21 +00002620if (area_match (tlvs.area_addrs, isis->man_area_addrs) == 0)
2621 {
2622 if (circuit->circuit_t == IS_LEVEL_2)
2623 {
2624 /* do as in table 8 (p. 40) */
2625 switch (circuit_type)
2626 {
2627 case IS_LEVEL_1:
2628 if (adj->adj_state != ISIS_ADJ_UP)
2629 {
2630 /* Reject */
2631 zlog_warn ("areaMismatch");
2632 retval = ISIS_WARNING;
2633 }
2634 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2635 {
2636 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2637 circuit->adjdb);
2638 }
2639 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 ||
2640 adj->adj_usage == ISIS_ADJ_LEVEL2)
2641 {
2642 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2643 circuit->adjdb);
2644 }
2645 break;
2646 case IS_LEVEL_2:
2647 if (adj->adj_state != ISIS_ADJ_UP)
2648 {
2649 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2650 circuit->adjdb);
2651 adj->adj_usage = ISIS_ADJ_LEVEL2;
2652 }
2653 else if (adj->adj_usage == ISIS_ADJ_LEVEL1 ||
2654 adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2655 {
2656 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2657 circuit->adjdb);
2658 }
2659 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2660 {
2661 ; /* Accept */
2662 }
2663 break;
2664 case IS_LEVEL_1_AND_2:
2665 if (adj->adj_state != ISIS_ADJ_UP)
2666 {
2667 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2668 circuit->adjdb);
2669 adj->adj_usage = ISIS_ADJ_LEVEL2;
2670 }
2671 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2672 {
2673 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2674 circuit->adjdb);
2675 }
2676 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2677 {
2678 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2679 circuit->adjdb);
2680 }
2681 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2682 {
2683 ; /* Accept */
2684 }
2685 break;
2686 }
2687 goto mismatch;
jardineb5d44e2003-12-23 08:09:43 +00002688 }
hassof390d2c2004-09-10 20:48:21 +00002689 else
2690 {
2691 isis_delete_adj (adj, circuit->adjdb);
2692 zlog_warn ("areaMismatch");
2693 return ISIS_WARNING;
2694 }
jardineb5d44e2003-12-23 08:09:43 +00002695 }
2696
2697mismatch:
2698#endif