blob: 90a51a21870768424467fe0af67f8b6e12a29779 [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;
hasso3fdb2dd2005-09-28 18:45:54 +000083 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000084
hasso3fdb2dd2005-09-28 18:45:54 +000085 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000086 {
hasso3fdb2dd2005-09-28 18:45:54 +000087 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000088 {
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 */
hasso92365882005-01-18 13:53:33 +0000105static int
hassof390d2c2004-09-10 20:48:21 +0000106ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000107{
108 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000109 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000110 int len;
hassof390d2c2004-09-10 20:48:21 +0000111
112 addr1 = (u_char *) & ip1->prefix.s_addr;
113 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000114 len = ip1->prefixlen;
115
116 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000117 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000118
hasso53c997c2004-09-15 16:21:59 +0000119 while (offsetloop--)
120 if (addr1[offsetloop] != addr2[offsetloop])
121 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000122
hassof390d2c2004-09-10 20:48:21 +0000123 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000124 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
125 return 0;
hassof390d2c2004-09-10 20:48:21 +0000126
127 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000128}
129
jardineb5d44e2003-12-23 08:09:43 +0000130/*
131 * Compares two set of ip addresses
132 * param left the local interface's ip addresses
133 * param right the iih interface's ip address
134 * return 0 no match;
135 * 1 match;
136 */
hassof390d2c2004-09-10 20:48:21 +0000137static int
jardineb5d44e2003-12-23 08:09:43 +0000138ip_match (struct list *left, struct list *right)
139{
140 struct prefix_ipv4 *ip1;
141 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000142 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000143
hassoe082ac12004-09-27 18:13:57 +0000144 if ((left == NULL) || (right == NULL))
145 return 0;
146
hasso3fdb2dd2005-09-28 18:45:54 +0000147 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000148 {
hasso3fdb2dd2005-09-28 18:45:54 +0000149 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000150 {
151 if (ip_same_subnet (ip1, ip2))
152 {
153 return 1; /* match */
154 }
jardineb5d44e2003-12-23 08:09:43 +0000155 }
hassof390d2c2004-09-10 20:48:21 +0000156
jardineb5d44e2003-12-23 08:09:43 +0000157 }
158 return 0;
159}
160
161/*
162 * Checks whether we should accept a PDU of given level
163 */
164static int
165accept_level (int level, int circuit_t)
166{
hassof390d2c2004-09-10 20:48:21 +0000167 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000168
169 return retval;
170}
171
hassof390d2c2004-09-10 20:48:21 +0000172int
jardineb5d44e2003-12-23 08:09:43 +0000173authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
174{
hassof390d2c2004-09-10 20:48:21 +0000175 if (one->type != theother->type)
176 {
177 zlog_warn ("Unsupported authentication type %d", theother->type);
178 return 1; /* Auth fail (different authentication types) */
179 }
180 switch (one->type)
181 {
182 case ISIS_PASSWD_TYPE_CLEARTXT:
183 if (one->len != theother->len)
184 return 1; /* Auth fail () - passwd len mismatch */
185 return memcmp (one->passwd, theother->passwd, one->len);
186 break;
187 default:
188 zlog_warn ("Unsupported authentication type");
189 break;
190 }
191 return 0; /* Auth pass */
jardineb5d44e2003-12-23 08:09:43 +0000192}
193
194/*
195 * Processing helper functions
196 */
hasso92365882005-01-18 13:53:33 +0000197static void
hassof390d2c2004-09-10 20:48:21 +0000198tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000199{
200 int i;
201 struct nlpids *tlv_nlpids;
202
hassof390d2c2004-09-10 20:48:21 +0000203 if (tlvs->nlpids)
204 {
jardineb5d44e2003-12-23 08:09:43 +0000205
hassof390d2c2004-09-10 20:48:21 +0000206 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000207
hassof390d2c2004-09-10 20:48:21 +0000208 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000209
hassof390d2c2004-09-10 20:48:21 +0000210 for (i = 0; i < tlv_nlpids->count; i++)
211 {
212 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
213 }
jardineb5d44e2003-12-23 08:09:43 +0000214 }
jardineb5d44e2003-12-23 08:09:43 +0000215}
216
hasso92365882005-01-18 13:53:33 +0000217static void
jardineb5d44e2003-12-23 08:09:43 +0000218del_ip_addr (void *val)
219{
220 XFREE (MTYPE_ISIS_TMP, val);
221}
222
hasso92365882005-01-18 13:53:33 +0000223static void
hassof390d2c2004-09-10 20:48:21 +0000224tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000225{
hasso3fdb2dd2005-09-28 18:45:54 +0000226 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000227 struct in_addr *ipv4_addr, *malloced;
228
hassof390d2c2004-09-10 20:48:21 +0000229 if (adj->ipv4_addrs)
230 {
231 adj->ipv4_addrs->del = del_ip_addr;
232 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000233 }
hassof390d2c2004-09-10 20:48:21 +0000234 adj->ipv4_addrs = list_new ();
235 if (tlvs->ipv4_addrs)
236 {
hasso3fdb2dd2005-09-28 18:45:54 +0000237 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000238 {
239 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
240 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
241 listnode_add (adj->ipv4_addrs, malloced);
242 }
243 }
jardineb5d44e2003-12-23 08:09:43 +0000244}
245
246#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000247static void
hassof390d2c2004-09-10 20:48:21 +0000248tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000249{
hasso3fdb2dd2005-09-28 18:45:54 +0000250 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000251 struct in6_addr *ipv6_addr, *malloced;
252
hassof390d2c2004-09-10 20:48:21 +0000253 if (adj->ipv6_addrs)
254 {
255 adj->ipv6_addrs->del = del_ip_addr;
256 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000257 }
hassof390d2c2004-09-10 20:48:21 +0000258 adj->ipv6_addrs = list_new ();
259 if (tlvs->ipv6_addrs)
260 {
hasso3fdb2dd2005-09-28 18:45:54 +0000261 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000262 {
263 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
264 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
265 listnode_add (adj->ipv6_addrs, malloced);
266 }
267 }
jardineb5d44e2003-12-23 08:09:43 +0000268
269}
270#endif /* HAVE_IPV6 */
271
jardineb5d44e2003-12-23 08:09:43 +0000272/*
273 * RECEIVE SIDE
274 */
275
276/*
277 * Process P2P IIH
278 * ISO - 10589
279 * Section 8.2.5 - Receiving point-to-point IIH PDUs
280 *
281 */
282static int
283process_p2p_hello (struct isis_circuit *circuit)
284{
285 int retval = ISIS_OK;
286 struct isis_p2p_hello_hdr *hdr;
287 struct isis_adjacency *adj;
288 u_int32_t expected = 0, found;
289 struct tlvs tlvs;
290
hassof390d2c2004-09-10 20:48:21 +0000291 if ((stream_get_endp (circuit->rcv_stream) -
292 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
293 {
294 zlog_warn ("Packet too short");
295 return ISIS_WARNING;
296 }
jardineb5d44e2003-12-23 08:09:43 +0000297
298 /* 8.2.5.1 PDU acceptance tests */
299
300 /* 8.2.5.1 a) external domain untrue */
301 /* FIXME: not useful at all? */
302
303 /* 8.2.5.1 b) ID Length mismatch */
304 /* checked at the handle_pdu */
305
306 /* 8.2.5.2 IIH PDU Processing */
307
308 /* 8.2.5.2 a) 1) Maximum Area Addresses */
309 /* Already checked, and can also be ommited */
310
311 /*
312 * Get the header
313 */
hassof390d2c2004-09-10 20:48:21 +0000314 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000315 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
316
317 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000318 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
319 hdr.hold_time = stream_getw (stream);
320 hdr.pdu_len = stream_getw (stream);
321 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000322
323 /*
324 * My interpertation of the ISO, if no adj exists we will create one for
325 * the circuit
326 */
327
hassof390d2c2004-09-10 20:48:21 +0000328 if (isis->debugs & DEBUG_ADJ_PACKETS)
329 {
hasso529d65b2004-12-24 00:14:50 +0000330 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
331 " cir id %02d, length %d",
332 circuit->area->area_tag, circuit->interface->name,
333 circuit_t2string (circuit->circuit_is_type),
334 circuit->circuit_id, ntohs (hdr->pdu_len));
hassof390d2c2004-09-10 20:48:21 +0000335 }
jardineb5d44e2003-12-23 08:09:43 +0000336
337 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000338 if (!adj)
339 {
hassof7c43dc2004-09-26 16:24:14 +0000340 adj = isis_new_adj (hdr->source_id, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +0000341 if (adj == NULL)
342 return ISIS_ERROR;
343 circuit->u.p2p.neighbor = adj;
344 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
345 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
346 }
jardineb5d44e2003-12-23 08:09:43 +0000347
348 /* 8.2.6 Monitoring point-to-point adjacencies */
349 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000350 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000351
352 /*
353 * Lets get the TLVS now
354 */
355 expected |= TLVFLAG_AREA_ADDRS;
356 expected |= TLVFLAG_AUTH_INFO;
357 expected |= TLVFLAG_NLPID;
358 expected |= TLVFLAG_IPV4_ADDR;
359 expected |= TLVFLAG_IPV6_ADDR;
360
361 retval = parse_tlvs (circuit->area->area_tag,
362 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000363 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
364 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000365
hassof390d2c2004-09-10 20:48:21 +0000366 if (retval > ISIS_WARNING)
367 {
368 free_tlvs (&tlvs);
369 return retval;
370 };
jardineb5d44e2003-12-23 08:09:43 +0000371
372 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000373 if (circuit->passwd.type)
374 {
375 if (!(found & TLVFLAG_AUTH_INFO) ||
376 authentication_check (&circuit->passwd, &tlvs.auth_info))
377 {
378 isis_event_auth_failure (circuit->area->area_tag,
379 "P2P hello authentication failure",
380 hdr->source_id);
381 return ISIS_OK;
382 }
jardineb5d44e2003-12-23 08:09:43 +0000383 }
jardineb5d44e2003-12-23 08:09:43 +0000384
385 /* we do this now because the adj may not survive till the end... */
386
387 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000388 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000389
390#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000391 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000392#endif /* HAVE_IPV6 */
393
394 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000395 THREAD_TIMER_OFF (adj->t_expire);
396 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
397 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000398
399 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000400 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
401 {
402 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
403 if (circuit->area->is_type == IS_LEVEL_1)
404 {
405 switch (hdr->circuit_t)
406 {
407 case IS_LEVEL_1:
408 case IS_LEVEL_1_AND_2:
409 if (adj->adj_state != ISIS_ADJ_UP)
410 {
411 /* (4) adj state up */
412 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
413 /* (5) adj usage level 1 */
414 adj->adj_usage = ISIS_ADJ_LEVEL1;
415 }
416 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
417 {
418 ; /* accept */
419 }
420 break;
421 case IS_LEVEL_2:
422 if (adj->adj_state != ISIS_ADJ_UP)
423 {
424 /* (7) reject - wrong system type event */
425 zlog_warn ("wrongSystemType");
426 return ISIS_WARNING; /* Reject */
427 }
428 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
429 {
430 /* (6) down - wrong system */
431 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
432 }
433 break;
434 }
435 }
jardineb5d44e2003-12-23 08:09:43 +0000436
hassof390d2c2004-09-10 20:48:21 +0000437 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
438 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
439 {
440 switch (hdr->circuit_t)
441 {
442 case IS_LEVEL_1:
443 if (adj->adj_state != ISIS_ADJ_UP)
444 {
445 /* (6) adj state up */
446 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
447 /* (7) adj usage level 1 */
448 adj->adj_usage = ISIS_ADJ_LEVEL1;
449 }
450 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
451 {
452 ; /* accept */
453 }
454 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
455 (adj->adj_usage == ISIS_ADJ_LEVEL2))
456 {
457 /* (8) down - wrong system */
458 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
459 }
460 break;
461 case IS_LEVEL_2:
462 if (adj->adj_state != ISIS_ADJ_UP)
463 {
464 /* (6) adj state up */
465 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
466 /* (9) adj usage level 2 */
467 adj->adj_usage = ISIS_ADJ_LEVEL2;
468 }
469 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
470 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
471 {
472 /* (8) down - wrong system */
473 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
474 }
475 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
476 {
477 ; /* Accept */
478 }
479 break;
480 case IS_LEVEL_1_AND_2:
481 if (adj->adj_state != ISIS_ADJ_UP)
482 {
483 /* (6) adj state up */
484 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
485 /* (10) adj usage level 1 */
486 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
487 }
488 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
489 (adj->adj_usage == ISIS_ADJ_LEVEL2))
490 {
491 /* (8) down - wrong system */
492 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
493 }
494 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
495 {
496 ; /* Accept */
497 }
498 break;
499 }
500 }
jardineb5d44e2003-12-23 08:09:43 +0000501
hassof390d2c2004-09-10 20:48:21 +0000502 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
503 if (circuit->area->is_type == IS_LEVEL_2)
504 {
505 switch (hdr->circuit_t)
506 {
507 case IS_LEVEL_1:
508 if (adj->adj_state != ISIS_ADJ_UP)
509 {
510 /* (5) reject - wrong system type event */
511 zlog_warn ("wrongSystemType");
512 return ISIS_WARNING; /* Reject */
513 }
514 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
515 (adj->adj_usage == ISIS_ADJ_LEVEL2))
516 {
517 /* (6) down - wrong system */
518 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
519 }
520 break;
521 case IS_LEVEL_1_AND_2:
522 case IS_LEVEL_2:
523 if (adj->adj_state != ISIS_ADJ_UP)
524 {
525 /* (7) adj state up */
526 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
527 /* (8) adj usage level 2 */
528 adj->adj_usage = ISIS_ADJ_LEVEL2;
529 }
530 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
531 {
532 /* (6) down - wrong system */
533 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
534 }
535 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
536 {
537 ; /* Accept */
538 }
539 break;
540 }
541 }
jardineb5d44e2003-12-23 08:09:43 +0000542 }
jardineb5d44e2003-12-23 08:09:43 +0000543 /* 8.2.5.2 b) if no match was detected */
544 else
jardineb5d44e2003-12-23 08:09:43 +0000545 {
hassof390d2c2004-09-10 20:48:21 +0000546 if (circuit->area->is_type == IS_LEVEL_1)
547 {
548 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
549 if (adj->adj_state != ISIS_ADJ_UP)
550 {
551 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
552 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
553 }
554 else
555 {
556 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
557 "Down - Area Mismatch");
558 }
559 }
560 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
561 else
562 {
563 switch (hdr->circuit_t)
564 {
565 case IS_LEVEL_1:
566 if (adj->adj_state != ISIS_ADJ_UP)
567 {
568 /* (6) reject - Area Mismatch event */
569 zlog_warn ("AreaMismatch");
570 return ISIS_WARNING; /* Reject */
571 }
572 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
573 {
574 /* (7) down - area mismatch */
575 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000576
hassof390d2c2004-09-10 20:48:21 +0000577 }
578 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
579 (adj->adj_usage == ISIS_ADJ_LEVEL2))
580 {
581 /* (7) down - wrong system */
582 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
583 }
584 break;
585 case IS_LEVEL_1_AND_2:
586 case IS_LEVEL_2:
587 if (adj->adj_state != ISIS_ADJ_UP)
588 {
589 /* (8) adj state up */
590 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
591 /* (9) adj usage level 2 */
592 adj->adj_usage = ISIS_ADJ_LEVEL2;
593 }
594 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
595 {
596 /* (7) down - wrong system */
597 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
598 }
599 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
600 {
601 if (hdr->circuit_t == IS_LEVEL_2)
602 {
603 /* (7) down - wrong system */
604 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
605 "Wrong System");
606 }
607 else
608 {
609 /* (7) down - area mismatch */
610 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
611 "Area Mismatch");
612 }
613 }
614 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
615 {
616 ; /* Accept */
617 }
618 break;
619 }
620 }
jardineb5d44e2003-12-23 08:09:43 +0000621 }
jardineb5d44e2003-12-23 08:09:43 +0000622 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
623 /* FIXME - Missing parts */
624
jardineb5d44e2003-12-23 08:09:43 +0000625 /* some of my own understanding of the ISO, why the heck does
626 * it not say what should I change the system_type to...
627 */
hassof390d2c2004-09-10 20:48:21 +0000628 switch (adj->adj_usage)
629 {
jardineb5d44e2003-12-23 08:09:43 +0000630 case ISIS_ADJ_LEVEL1:
631 adj->sys_type = ISIS_SYSTYPE_L1_IS;
632 break;
633 case ISIS_ADJ_LEVEL2:
634 adj->sys_type = ISIS_SYSTYPE_L2_IS;
635 break;
636 case ISIS_ADJ_LEVEL1AND2:
637 adj->sys_type = ISIS_SYSTYPE_L2_IS;
638 break;
639 case ISIS_ADJ_NONE:
640 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
641 break;
hassof390d2c2004-09-10 20:48:21 +0000642 }
jardineb5d44e2003-12-23 08:09:43 +0000643
644 adj->circuit_t = hdr->circuit_t;
645 adj->level = hdr->circuit_t;
646
647 free_tlvs (&tlvs);
648
649 return retval;
650}
651
jardineb5d44e2003-12-23 08:09:43 +0000652/*
653 * Process IS-IS LAN Level 1/2 Hello PDU
654 */
hassof390d2c2004-09-10 20:48:21 +0000655static int
656process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000657{
658 int retval = ISIS_OK;
659 struct isis_lan_hello_hdr hdr;
660 struct isis_adjacency *adj;
661 u_int32_t expected = 0, found;
662 struct tlvs tlvs;
663 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000664 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000665
hassof390d2c2004-09-10 20:48:21 +0000666 if ((stream_get_endp (circuit->rcv_stream) -
667 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
668 {
669 zlog_warn ("Packet too short");
670 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000671 }
hassof390d2c2004-09-10 20:48:21 +0000672
673 if (circuit->ext_domain)
674 {
hasso529d65b2004-12-24 00:14:50 +0000675 zlog_debug ("level %d LAN Hello received over circuit with "
676 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000677 return ISIS_WARNING;
678 }
679
680 if (!accept_level (level, circuit->circuit_is_type))
681 {
682 if (isis->debugs & DEBUG_ADJ_PACKETS)
683 {
hasso529d65b2004-12-24 00:14:50 +0000684 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
685 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000686 }
687 return ISIS_WARNING;
688 }
jardineb5d44e2003-12-23 08:09:43 +0000689
690#if 0
691 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000692 if (!accept_level (level, circuit->area->is_type))
693 {
694 if (isis->debugs & DEBUG_ADJ_PACKETS)
695 {
hasso529d65b2004-12-24 00:14:50 +0000696 zlog_debug ("ISIS-Adj (%s): is type mismatch",
697 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000698 }
699 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000700 }
jardineb5d44e2003-12-23 08:09:43 +0000701#endif
702 /*
703 * Fill the header
704 */
705 hdr.circuit_t = stream_getc (circuit->rcv_stream);
706 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
707 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000708 hdr.pdu_len = stream_getw (circuit->rcv_stream);
709 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000710 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
711
712 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000713 hdr.circuit_t != IS_LEVEL_1_AND_2)
714 {
715 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
716 hdr.circuit_t);
717 return ISIS_ERROR;
718 }
jardineb5d44e2003-12-23 08:09:43 +0000719 /*
720 * Then get the tlvs
721 */
722 expected |= TLVFLAG_AUTH_INFO;
723 expected |= TLVFLAG_AREA_ADDRS;
724 expected |= TLVFLAG_LAN_NEIGHS;
725 expected |= TLVFLAG_NLPID;
726 expected |= TLVFLAG_IPV4_ADDR;
727 expected |= TLVFLAG_IPV6_ADDR;
728
729 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000730 STREAM_PNT (circuit->rcv_stream),
731 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
732 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000733
hassof390d2c2004-09-10 20:48:21 +0000734 if (retval > ISIS_WARNING)
735 {
736 zlog_warn ("parse_tlvs() failed");
737 goto out;
738 }
jardineb5d44e2003-12-23 08:09:43 +0000739
hassof390d2c2004-09-10 20:48:21 +0000740 if (!(found & TLVFLAG_AREA_ADDRS))
741 {
742 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
743 level);
jardineb5d44e2003-12-23 08:09:43 +0000744 retval = ISIS_WARNING;
745 goto out;
746 }
hassof390d2c2004-09-10 20:48:21 +0000747
748 if (circuit->passwd.type)
749 {
750 if (!(found & TLVFLAG_AUTH_INFO) ||
751 authentication_check (&circuit->passwd, &tlvs.auth_info))
752 {
753 isis_event_auth_failure (circuit->area->area_tag,
754 "LAN hello authentication failure",
755 hdr.source_id);
756 retval = ISIS_WARNING;
757 goto out;
758 }
759 }
jardineb5d44e2003-12-23 08:09:43 +0000760
761 /*
762 * Accept the level 1 adjacency only if a match between local and
763 * remote area addresses is found
764 */
hassof390d2c2004-09-10 20:48:21 +0000765 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
766 {
767 if (isis->debugs & DEBUG_ADJ_PACKETS)
768 {
hasso529d65b2004-12-24 00:14:50 +0000769 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
770 circuit->area->area_tag, level,
771 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000772 }
773 retval = ISIS_OK;
774 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000775 }
jardineb5d44e2003-12-23 08:09:43 +0000776
777 /*
778 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000779 */
780 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
781 {
hasso529d65b2004-12-24 00:14:50 +0000782 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
783 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000784
hassof390d2c2004-09-10 20:48:21 +0000785 retval = ISIS_OK;
786 goto out;
787 }
jardineb5d44e2003-12-23 08:09:43 +0000788
789 /*
790 * check if it's own interface ip match iih ip addrs
791 */
hassof390d2c2004-09-10 20:48:21 +0000792 if (!(found & TLVFLAG_IPV4_ADDR)
793 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
794 {
hasso529d65b2004-12-24 00:14:50 +0000795 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000796 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
797 circuit->interface->name);
798 retval = ISIS_WARNING;
799 goto out;
800 }
jardineb5d44e2003-12-23 08:09:43 +0000801
802 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000803 if (!adj)
804 {
805 /*
806 * Do as in 8.4.2.5
807 */
808 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
809 if (adj == NULL)
hasso13c48f72004-09-10 21:19:13 +0000810 {
811 retval = ISIS_ERROR;
812 goto out;
813 }
jardineb5d44e2003-12-23 08:09:43 +0000814
hassof390d2c2004-09-10 20:48:21 +0000815 adj->level = level;
816 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000817
hassof390d2c2004-09-10 20:48:21 +0000818 if (level == 1)
819 {
820 adj->sys_type = ISIS_SYSTYPE_L1_IS;
821 }
822 else
823 {
824 adj->sys_type = ISIS_SYSTYPE_L2_IS;
825 }
826 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
827 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
828 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000829 }
jardineb5d44e2003-12-23 08:09:43 +0000830
hassoa211d652004-09-20 14:55:29 +0000831 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
832 switch (level)
833 {
834 case 1:
835 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
836 {
837 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000838 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
839 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000840 }
841 break;
842 case 2:
843 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
844 {
845 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000846 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
847 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000848 }
849 break;
850 }
jardineb5d44e2003-12-23 08:09:43 +0000851
852 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000853 adj->last_upd = time (NULL);
854 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000855
856 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
857
858 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000859 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000860 tlvs_to_adj_nlpids (&tlvs, adj);
861
862 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000863 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000864 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
865
866#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000867 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000868 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
869#endif /* HAVE_IPV6 */
870
871 adj->circuit_t = hdr.circuit_t;
872
873 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000874 THREAD_TIMER_OFF (adj->t_expire);
875 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
876 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000877
878 /*
879 * If the snpa for this circuit is found from LAN Neighbours TLV
880 * we have two-way communication -> adjacency can be put to state "up"
881 */
882
hassof390d2c2004-09-10 20:48:21 +0000883 if (found & TLVFLAG_LAN_NEIGHS)
884 {
885 if (adj->adj_state != ISIS_ADJ_UP)
886 {
hasso3fdb2dd2005-09-28 18:45:54 +0000887 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
hassof390d2c2004-09-10 20:48:21 +0000888 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
889 {
890 isis_adj_state_change (adj, ISIS_ADJ_UP,
891 "own SNPA found in LAN Neighbours TLV");
892 }
893 }
jardineb5d44e2003-12-23 08:09:43 +0000894 }
jardineb5d44e2003-12-23 08:09:43 +0000895
hassof390d2c2004-09-10 20:48:21 +0000896out:
jardineb5d44e2003-12-23 08:09:43 +0000897 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000898 if (isis->debugs & DEBUG_ADJ_PACKETS)
899 {
900 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +0000901 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
902 "cirID %u, length %ld",
903 circuit->area->area_tag,
904 level, snpa_print (ssnpa), circuit->interface->name,
905 circuit_t2string (circuit->circuit_is_type),
hasso29e50b22005-09-01 18:18:47 +0000906 circuit->circuit_id,
907 /* FIXME: use %z when we stop supporting old compilers. */
908 (unsigned long) stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +0000909 }
jardineb5d44e2003-12-23 08:09:43 +0000910
911 free_tlvs (&tlvs);
912
913 return retval;
914}
915
916/*
917 * Process Level 1/2 Link State
918 * ISO - 10589
919 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000920 */
921static int
922process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000923{
924 struct isis_link_state_hdr *hdr;
925 struct isis_adjacency *adj = NULL;
926 struct isis_lsp *lsp, *lsp0 = NULL;
927 int retval = ISIS_OK, comp = 0;
928 u_char lspid[ISIS_SYS_ID_LEN + 2];
929 struct isis_passwd *passwd;
930
931 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000932 if ((stream_get_endp (circuit->rcv_stream) -
933 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
934 {
935 zlog_warn ("Packet too short");
936 return ISIS_WARNING;
937 }
jardineb5d44e2003-12-23 08:09:43 +0000938
939 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000940 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000941
hassof390d2c2004-09-10 20:48:21 +0000942 if (isis->debugs & DEBUG_UPDATE_PACKETS)
943 {
hasso529d65b2004-12-24 00:14:50 +0000944 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
945 "lifetime %us, len %lu, on %s",
946 circuit->area->area_tag,
947 level,
948 rawlspid_print (hdr->lsp_id),
949 ntohl (hdr->seq_num),
950 ntohs (hdr->checksum),
951 ntohs (hdr->rem_lifetime),
hasso29e50b22005-09-01 18:18:47 +0000952 /* FIXME: use %z when we stop supporting old compilers. */
953 (unsigned long) stream_get_endp (circuit->rcv_stream),
paul15935e92005-05-03 09:27:23 +0000954 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000955 }
jardineb5d44e2003-12-23 08:09:43 +0000956
957 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
958
959 /* Checksum sanity check - FIXME: move to correct place */
960 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000961 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
962 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
963 {
hasso529d65b2004-12-24 00:14:50 +0000964 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
965 circuit->area->area_tag,
966 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000967
hassof390d2c2004-09-10 20:48:21 +0000968 return ISIS_WARNING;
969 }
jardineb5d44e2003-12-23 08:09:43 +0000970
971 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000972 if (circuit->ext_domain)
973 {
hasso529d65b2004-12-24 00:14:50 +0000974 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000975 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
976 "externalDomain = true", circuit->area->area_tag,
977 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000978
hassof390d2c2004-09-10 20:48:21 +0000979 return ISIS_WARNING;
980 }
jardineb5d44e2003-12-23 08:09:43 +0000981
982 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000983 if (!accept_level (level, circuit->circuit_is_type))
984 {
hasso529d65b2004-12-24 00:14:50 +0000985 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
986 " type %s",
987 circuit->area->area_tag,
988 rawlspid_print (hdr->lsp_id),
989 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +0000990
hassof390d2c2004-09-10 20:48:21 +0000991 return ISIS_WARNING;
992 }
jardineb5d44e2003-12-23 08:09:43 +0000993
994 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
995
996 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
997
998 /* 7.3.15.1 a) 7 - password check */
999 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
1000 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001001 if (passwd->type)
1002 {
1003 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1004 ntohs (hdr->pdu_len), passwd))
1005 {
1006 isis_event_auth_failure (circuit->area->area_tag,
1007 "LSP authentication failure", hdr->lsp_id);
1008 return ISIS_WARNING;
1009 }
jardineb5d44e2003-12-23 08:09:43 +00001010 }
jardineb5d44e2003-12-23 08:09:43 +00001011 /* Find the LSP in our database and compare it to this Link State header */
1012 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1013 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001014 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1015 hdr->checksum, hdr->rem_lifetime);
1016 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001017#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001018 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001019#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001020 ))
jardineb5d44e2003-12-23 08:09:43 +00001021 goto dontcheckadj;
1022
1023 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1024 /* for broadcast circuits, snpa should be compared */
1025 /* FIXME : Point To Point */
1026
hassof390d2c2004-09-10 20:48:21 +00001027 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1028 {
1029 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1030 if (!adj)
1031 {
hasso529d65b2004-12-24 00:14:50 +00001032 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1033 "lifetime %us on %s",
1034 circuit->area->area_tag,
1035 rawlspid_print (hdr->lsp_id),
1036 ntohl (hdr->seq_num),
1037 ntohs (hdr->checksum),
1038 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001039 return ISIS_WARNING; /* Silently discard */
1040 }
jardineb5d44e2003-12-23 08:09:43 +00001041 }
jardineb5d44e2003-12-23 08:09:43 +00001042
1043 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001044 else
1045 {
1046 /* If no adj, or no sharing of level */
1047 if (!circuit->u.p2p.neighbor)
1048 {
1049 return ISIS_OK; /* Silently discard */
1050 }
1051 else
1052 {
1053 if (((level == 1) &&
1054 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1055 ((level == 2) &&
1056 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1057 return ISIS_WARNING; /* Silently discard */
1058 }
jardineb5d44e2003-12-23 08:09:43 +00001059 }
hassof390d2c2004-09-10 20:48:21 +00001060dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001061 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1062
1063 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1064
hassof390d2c2004-09-10 20:48:21 +00001065 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001066
hassof390d2c2004-09-10 20:48:21 +00001067 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1068 if (hdr->rem_lifetime == 0)
1069 {
1070 if (!lsp)
1071 {
1072 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1073 /* only needed on explicit update, eg - p2p */
1074 if (circuit->circ_type == CIRCUIT_T_P2P)
1075 ack_lsp (hdr, circuit, level);
1076 return retval; /* FIXME: do we need a purge? */
1077 }
1078 else
1079 {
1080 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1081 {
1082 /* LSP by some other system -> do 7.3.16.4 b) */
1083 /* 7.3.16.4 b) 1) */
1084 if (comp == LSP_NEWER)
1085 {
hassoa96d8d12005-09-16 14:44:23 +00001086 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area,
1087 level);
hassof390d2c2004-09-10 20:48:21 +00001088 /* ii */
1089 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1090 /* iii */
1091 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1092 /* v */
1093 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1094 /* iv */
1095 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1096 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001097
hassof390d2c2004-09-10 20:48:21 +00001098 } /* 7.3.16.4 b) 2) */
1099 else if (comp == LSP_EQUAL)
1100 {
1101 /* i */
1102 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1103 /* ii */
1104 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1105 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1106 } /* 7.3.16.4 b) 3) */
1107 else
1108 {
1109 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1110 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1111 }
1112 }
1113 else
1114 {
1115 /* our own LSP -> 7.3.16.4 c) */
1116 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1117 circuit->circuit_id
1118 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1119 circuit->circuit_id
1120 && circuit->u.bc.is_dr[level - 1] == 1))
1121 {
1122 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
hassoc89c05d2005-09-04 21:36:36 +00001123 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1124 zlog_debug ("LSP LEN: %d",
1125 ntohs (lsp->lsp_header->pdu_len));
hassof390d2c2004-09-10 20:48:21 +00001126 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1127 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1128 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001129 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1130 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1131 "seq 0x%08x", circuit->area->area_tag,
1132 rawlspid_print (hdr->lsp_id),
1133 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001134 lsp->lsp_header->rem_lifetime =
1135 htons (isis_jitter
1136 (circuit->area->max_lsp_lifetime[level - 1],
1137 MAX_AGE_JITTER));
1138 }
1139 else
1140 {
1141 /* Got purge for own pseudo-lsp, and we are not DR */
1142 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1143 }
1144 }
1145 }
1146 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001147 }
jardineb5d44e2003-12-23 08:09:43 +00001148 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1149 * purge */
hassof390d2c2004-09-10 20:48:21 +00001150 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1151 {
1152 if (!lsp)
1153 {
1154 /* 7.3.16.4: initiate a purge */
1155 lsp_purge_non_exist (hdr, circuit->area);
1156 return ISIS_OK;
1157 }
1158 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1159
1160 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1161 * has information that the current sequence number for source S is
1162 * "greater" than that held by S, ... */
1163
1164 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1165 {
1166 /* 7.3.16.1 */
1167 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1168
1169 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1170 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1171
1172 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001173 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1174 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1175 "0x%08x", circuit->area->area_tag,
1176 rawlspid_print (hdr->lsp_id),
1177 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001178 lsp->lsp_header->rem_lifetime =
1179 htons (isis_jitter
1180 (circuit->area->max_lsp_lifetime[level - 1],
1181 MAX_AGE_JITTER));
1182 }
jardineb5d44e2003-12-23 08:09:43 +00001183 }
hassof390d2c2004-09-10 20:48:21 +00001184 else
1185 {
1186 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001187
hassof390d2c2004-09-10 20:48:21 +00001188 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1189 if ((!lsp || comp == LSP_NEWER))
1190 {
1191 /* i */
1192 if (lsp)
1193 {
jardineb5d44e2003-12-23 08:09:43 +00001194#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001195 zlog_debug ("level %d number is - %ld", level,
1196 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001197#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001198 lsp_search_and_destroy (hdr->lsp_id,
1199 circuit->area->lspdb[level - 1]);
1200 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001201#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001202 zlog_debug ("level %d number is - %ld", level,
1203 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001204#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001205 }
1206 /*
1207 * If this lsp is a frag, need to see if we have zero lsp present
1208 */
1209 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1210 {
1211 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1212 LSP_FRAGMENT (lspid) = 0;
1213 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1214 if (!lsp0)
1215 {
hasso529d65b2004-12-24 00:14:50 +00001216 zlog_debug ("Got lsp frag, while zero lsp not database");
hassof390d2c2004-09-10 20:48:21 +00001217 return ISIS_OK;
1218 }
1219 }
1220 lsp =
1221 lsp_new_from_stream_ptr (circuit->rcv_stream,
1222 ntohs (hdr->pdu_len), lsp0,
1223 circuit->area);
1224 lsp->level = level;
1225 lsp->adj = adj;
1226 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1227 /* ii */
1228 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1229 /* iii */
1230 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001231
hassof390d2c2004-09-10 20:48:21 +00001232 /* iv */
1233 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1234 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1235 /* FIXME: v) */
1236 }
1237 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1238 else if (comp == LSP_EQUAL)
1239 {
1240 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassoa96d8d12005-09-16 14:44:23 +00001241 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001242 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1243 {
1244 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1245 }
1246 }
1247 /* 7.3.15.1 e) 3) LSP older than the one in db */
1248 else
1249 {
1250 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1251 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1252 }
jardineb5d44e2003-12-23 08:09:43 +00001253 }
jardineb5d44e2003-12-23 08:09:43 +00001254 if (lsp)
1255 lsp->adj = adj;
1256 return retval;
1257}
1258
1259/*
1260 * Process Sequence Numbers
1261 * ISO - 10589
1262 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1263 */
1264
hasso92365882005-01-18 13:53:33 +00001265static int
hassof390d2c2004-09-10 20:48:21 +00001266process_snp (int snp_type, int level, struct isis_circuit *circuit,
1267 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001268{
1269 int retval = ISIS_OK;
1270 int cmp, own_lsp;
1271 char typechar = ' ';
1272 int len;
1273 struct isis_adjacency *adj;
1274 struct isis_complete_seqnum_hdr *chdr = NULL;
1275 struct isis_partial_seqnum_hdr *phdr = NULL;
1276 uint32_t found = 0, expected = 0;
1277 struct isis_lsp *lsp;
1278 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001279 struct listnode *node, *nnode;
1280 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001281 struct tlvs tlvs;
1282 struct list *lsp_list = NULL;
1283 struct isis_passwd *passwd;
1284
hassof390d2c2004-09-10 20:48:21 +00001285 if (snp_type == ISIS_SNP_CSNP_FLAG)
1286 {
1287 /* getting the header info */
1288 typechar = 'C';
1289 chdr =
1290 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1291 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1292 len = ntohs (chdr->pdu_len);
1293 if (len < ISIS_CSNP_HDRLEN)
1294 {
1295 zlog_warn ("Received a CSNP with bogus length!");
1296 return ISIS_OK;
1297 }
jardineb5d44e2003-12-23 08:09:43 +00001298 }
hassof390d2c2004-09-10 20:48:21 +00001299 else
1300 {
1301 typechar = 'P';
1302 phdr =
1303 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1304 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1305 len = ntohs (phdr->pdu_len);
1306 if (len < ISIS_PSNP_HDRLEN)
1307 {
1308 zlog_warn ("Received a CSNP with bogus length!");
1309 return ISIS_OK;
1310 }
jardineb5d44e2003-12-23 08:09:43 +00001311 }
jardineb5d44e2003-12-23 08:09:43 +00001312
1313 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001314 if (circuit->ext_domain)
1315 {
jardineb5d44e2003-12-23 08:09:43 +00001316
hasso529d65b2004-12-24 00:14:50 +00001317 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1318 "skipping: circuit externalDomain = true",
1319 circuit->area->area_tag,
1320 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001321
1322 return ISIS_OK;
1323 }
hassof390d2c2004-09-10 20:48:21 +00001324
1325 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1326 if (!accept_level (level, circuit->circuit_is_type))
1327 {
1328
hasso529d65b2004-12-24 00:14:50 +00001329 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1330 "skipping: circuit type %s does not match level %d",
1331 circuit->area->area_tag,
1332 level,
1333 typechar,
1334 circuit->interface->name,
1335 circuit_t2string (circuit->circuit_is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001336
1337 return ISIS_OK;
1338 }
1339
1340 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1341 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1342 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1343 {
1344 if (!circuit->u.bc.is_dr[level - 1])
1345 {
1346
hasso529d65b2004-12-24 00:14:50 +00001347 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1348 "skipping: we are not the DIS",
1349 circuit->area->area_tag,
1350 level,
1351 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001352
1353 return ISIS_OK;
1354 }
1355 }
jardineb5d44e2003-12-23 08:09:43 +00001356
1357 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1358
1359 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1360 * - already checked */
1361
1362 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1363 /* for broadcast circuits, snpa should be compared */
1364 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001365 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1366 {
1367 if (snp_type == ISIS_SNP_CSNP_FLAG)
1368 {
1369 adj =
1370 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1371 }
1372 else
1373 {
1374 /* a psnp on a broadcast, how lovely of Juniper :) */
1375 adj =
1376 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1377 }
1378 if (!adj)
1379 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001380 }
hassof390d2c2004-09-10 20:48:21 +00001381 else
1382 {
1383 if (!circuit->u.p2p.neighbor)
1384 return ISIS_OK; /* Silently discard */
1385 }
jardineb5d44e2003-12-23 08:09:43 +00001386
1387 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1388
1389 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1390
1391 memset (&tlvs, 0, sizeof (struct tlvs));
1392
1393 /* parse the SNP */
1394 expected |= TLVFLAG_LSP_ENTRIES;
1395 expected |= TLVFLAG_AUTH_INFO;
1396 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001397 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001398 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001399 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001400
hassof390d2c2004-09-10 20:48:21 +00001401 if (retval > ISIS_WARNING)
1402 {
1403 zlog_warn ("something went very wrong processing SNP");
1404 free_tlvs (&tlvs);
1405 return retval;
1406 }
jardineb5d44e2003-12-23 08:09:43 +00001407
hasso1cbc5622005-01-01 10:29:51 +00001408 if (level == 1)
1409 passwd = &circuit->area->area_passwd;
1410 else
1411 passwd = &circuit->area->domain_passwd;
1412
1413 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001414 {
hasso1cbc5622005-01-01 10:29:51 +00001415 if (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00001416 {
hasso1cbc5622005-01-01 10:29:51 +00001417 if (!(found & TLVFLAG_AUTH_INFO) ||
1418 authentication_check (passwd, &tlvs.auth_info))
1419 {
1420 isis_event_auth_failure (circuit->area->area_tag,
1421 "SNP authentication" " failure",
1422 phdr ? phdr->source_id : chdr->source_id);
1423 return ISIS_OK;
1424 }
hassof390d2c2004-09-10 20:48:21 +00001425 }
1426 }
jardineb5d44e2003-12-23 08:09:43 +00001427
1428 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001429 if (isis->debugs & DEBUG_SNP_PACKETS)
1430 {
hasso529d65b2004-12-24 00:14:50 +00001431 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1432 circuit->area->area_tag,
1433 level,
1434 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001435 if (tlvs.lsp_entries)
1436 {
hasso3fdb2dd2005-09-28 18:45:54 +00001437 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001438 {
hasso529d65b2004-12-24 00:14:50 +00001439 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1440 " cksum 0x%04x, lifetime %us",
1441 circuit->area->area_tag,
1442 typechar,
1443 rawlspid_print (entry->lsp_id),
1444 ntohl (entry->seq_num),
1445 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001446 }
1447 }
jardineb5d44e2003-12-23 08:09:43 +00001448 }
jardineb5d44e2003-12-23 08:09:43 +00001449
1450 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001451 if (tlvs.lsp_entries)
1452 {
hasso3fdb2dd2005-09-28 18:45:54 +00001453 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001454 {
1455 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1456 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1457 if (lsp)
1458 {
1459 /* 7.3.15.2 b) 1) is this LSP newer */
1460 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1461 entry->checksum, entry->rem_lifetime);
1462 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1463 if (cmp == LSP_EQUAL)
1464 {
1465 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1466 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1467 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1468 }
1469 else if (cmp == LSP_OLDER)
1470 {
1471 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1472 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1473 }
1474 else
1475 {
1476 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1477 * on p2p */
1478 if (own_lsp)
1479 {
1480 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1481 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1482 }
1483 else
1484 {
1485 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1486 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1487 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1488 }
1489 }
1490 }
1491 else
1492 {
1493 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1494 * insert it and set SSN on it */
1495 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1496 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1497 {
1498 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1499 0, 0, entry->checksum, level);
1500 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1501 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1502 }
1503 }
jardineb5d44e2003-12-23 08:09:43 +00001504 }
1505 }
jardineb5d44e2003-12-23 08:09:43 +00001506
1507 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001508 if (snp_type == ISIS_SNP_CSNP_FLAG)
1509 {
1510 /*
1511 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1512 */
1513 lsp_list = list_new ();
1514 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1515 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001516
hassof390d2c2004-09-10 20:48:21 +00001517 /* Fixme: Find a better solution */
1518 if (tlvs.lsp_entries)
1519 {
paul1eb8ef22005-04-07 07:30:20 +00001520 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001521 {
paul1eb8ef22005-04-07 07:30:20 +00001522 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001523 {
1524 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1525 {
1526 list_delete_node (lsp_list, node2);
1527 break;
1528 }
1529 }
1530 }
1531 }
1532 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001533 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001534 {
1535 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001536 }
hassof390d2c2004-09-10 20:48:21 +00001537 /* lets free it */
1538 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001539 }
jardineb5d44e2003-12-23 08:09:43 +00001540
1541 free_tlvs (&tlvs);
1542 return retval;
1543}
1544
hasso92365882005-01-18 13:53:33 +00001545static int
hassof390d2c2004-09-10 20:48:21 +00001546process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001547{
jardineb5d44e2003-12-23 08:09:43 +00001548 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001549 if ((stream_get_endp (circuit->rcv_stream) -
1550 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1551 {
1552 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1553 return ISIS_WARNING;
1554 }
jardineb5d44e2003-12-23 08:09:43 +00001555
1556 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1557}
1558
hasso92365882005-01-18 13:53:33 +00001559static int
hassof390d2c2004-09-10 20:48:21 +00001560process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001561{
hassof390d2c2004-09-10 20:48:21 +00001562 if ((stream_get_endp (circuit->rcv_stream) -
1563 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1564 {
1565 zlog_warn ("Packet too short");
1566 return ISIS_WARNING;
1567 }
jardineb5d44e2003-12-23 08:09:43 +00001568
1569 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1570}
1571
jardineb5d44e2003-12-23 08:09:43 +00001572/*
1573 * Process ISH
1574 * ISO - 10589
1575 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1576 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001577 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1578 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1579 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001580 */
hasso92365882005-01-18 13:53:33 +00001581static int
jardineb5d44e2003-12-23 08:09:43 +00001582process_is_hello (struct isis_circuit *circuit)
1583{
1584 struct isis_adjacency *adj;
1585 int retval = ISIS_OK;
1586 u_char neigh_len;
1587 u_char *sysid;
1588
1589 /* In this point in time we are not yet able to handle is_hellos
1590 * on lan - Sorry juniper...
1591 */
1592 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1593 return retval;
1594
1595 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001596 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001597 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001598 if (!adj)
1599 {
1600 /* 8.2.2 */
hassof7c43dc2004-09-26 16:24:14 +00001601 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001602 if (adj == NULL)
1603 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001604
hassof390d2c2004-09-10 20:48:21 +00001605 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1606 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1607 circuit->u.p2p.neighbor = adj;
1608 }
1609 /* 8.2.2 a) */
1610 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1611 ISIS_SYS_ID_LEN))
1612 {
1613 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1614 /* 8.2.2 a) 2) delete the adj */
1615 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1616 /* 8.2.2 a) 3) create a new adj */
hassof7c43dc2004-09-26 16:24:14 +00001617 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001618 if (adj == NULL)
1619 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001620
hassof390d2c2004-09-10 20:48:21 +00001621 /* 8.2.2 a) 3) i */
1622 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1623 /* 8.2.2 a) 3) ii */
1624 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1625 /* 8.2.2 a) 4) quite meaningless */
1626 }
jardineb5d44e2003-12-23 08:09:43 +00001627 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001628 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1629 (adj->sys_type == ISIS_SYSTYPE_IS))
1630 {
1631 /* do nothing */
1632 }
1633 else
1634 {
1635 /* 8.2.2 c) respond with a p2p IIH */
1636 send_hello (circuit, 1);
1637 }
jardineb5d44e2003-12-23 08:09:43 +00001638 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001639 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001640 /* 8.2.2 e) FIXME: Circuit type of? */
1641
jardineb5d44e2003-12-23 08:09:43 +00001642 return retval;
1643}
1644
jardineb5d44e2003-12-23 08:09:43 +00001645/*
1646 * PDU Dispatcher
1647 */
1648
hasso92365882005-01-18 13:53:33 +00001649static int
hassof390d2c2004-09-10 20:48:21 +00001650isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001651{
jardineb5d44e2003-12-23 08:09:43 +00001652 struct isis_fixed_hdr *hdr;
1653 struct esis_fixed_hdr *esis_hdr;
1654
hassof390d2c2004-09-10 20:48:21 +00001655 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001656
1657 /*
1658 * Let's first read data from stream to the header
1659 */
hassof390d2c2004-09-10 20:48:21 +00001660 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001661
hassof390d2c2004-09-10 20:48:21 +00001662 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1663 {
1664 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1665 return ISIS_ERROR;
1666 }
jardineb5d44e2003-12-23 08:09:43 +00001667
1668 /* now we need to know if this is an ISO 9542 packet and
1669 * take real good care of it, waaa!
1670 */
hassof390d2c2004-09-10 20:48:21 +00001671 if (hdr->idrp == ISO9542_ESIS)
1672 {
1673 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1674 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1675 /* FIXME: Need to do some acceptence tests */
1676 /* example length... */
1677 switch (esis_hdr->pdu_type)
1678 {
1679 case ESH_PDU:
1680 /* FIXME */
1681 break;
1682 case ISH_PDU:
hasso529d65b2004-12-24 00:14:50 +00001683 zlog_debug ("AN ISH PDU!!");
hassof390d2c2004-09-10 20:48:21 +00001684 retval = process_is_hello (circuit);
1685 break;
1686 default:
1687 return ISIS_ERROR;
1688 }
1689 return retval;
1690 }
1691 else
1692 {
1693 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1694 }
jardineb5d44e2003-12-23 08:09:43 +00001695 /*
1696 * and then process it
1697 */
1698
hassof390d2c2004-09-10 20:48:21 +00001699 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1700 {
1701 zlog_err ("Fixed header length = %d", hdr->length);
1702 return ISIS_ERROR;
1703 }
jardineb5d44e2003-12-23 08:09:43 +00001704
hassof390d2c2004-09-10 20:48:21 +00001705 if (hdr->version1 != 1)
1706 {
1707 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1708 return ISIS_WARNING;
1709 }
jardineb5d44e2003-12-23 08:09:43 +00001710 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001711 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1712 {
1713 zlog_err
1714 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1715 "while the parameter for this IS is %u", hdr->id_len,
1716 ISIS_SYS_ID_LEN);
1717 return ISIS_ERROR;
1718 }
jardineb5d44e2003-12-23 08:09:43 +00001719
hassof390d2c2004-09-10 20:48:21 +00001720 if (hdr->version2 != 1)
1721 {
1722 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1723 return ISIS_WARNING;
1724 }
jardineb5d44e2003-12-23 08:09:43 +00001725 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001726 if ((hdr->max_area_addrs != 0)
1727 && (hdr->max_area_addrs != isis->max_area_addrs))
1728 {
1729 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1730 "received PDU %u while the parameter for this IS is %u",
1731 hdr->max_area_addrs, isis->max_area_addrs);
1732 return ISIS_ERROR;
1733 }
jardineb5d44e2003-12-23 08:09:43 +00001734
hassof390d2c2004-09-10 20:48:21 +00001735 switch (hdr->pdu_type)
1736 {
1737 case L1_LAN_HELLO:
1738 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1739 break;
1740 case L2_LAN_HELLO:
1741 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1742 break;
1743 case P2P_HELLO:
1744 retval = process_p2p_hello (circuit);
1745 break;
1746 case L1_LINK_STATE:
1747 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1748 break;
1749 case L2_LINK_STATE:
1750 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1751 break;
1752 case L1_COMPLETE_SEQ_NUM:
1753 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1754 break;
1755 case L2_COMPLETE_SEQ_NUM:
1756 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1757 break;
1758 case L1_PARTIAL_SEQ_NUM:
1759 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1760 break;
1761 case L2_PARTIAL_SEQ_NUM:
1762 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1763 break;
1764 default:
1765 return ISIS_ERROR;
1766 }
jardineb5d44e2003-12-23 08:09:43 +00001767
1768 return retval;
1769}
1770
jardineb5d44e2003-12-23 08:09:43 +00001771#ifdef GNU_LINUX
1772int
1773isis_receive (struct thread *thread)
1774{
jardineb5d44e2003-12-23 08:09:43 +00001775 struct isis_circuit *circuit;
1776 u_char ssnpa[ETH_ALEN];
1777 int retval;
1778
1779 /*
1780 * Get the circuit
1781 */
1782 circuit = THREAD_ARG (thread);
1783 assert (circuit);
1784
1785 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001786 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001787 else
1788 stream_reset (circuit->rcv_stream);
1789
1790 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001791 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001792
1793 if (retval == ISIS_OK)
1794 retval = isis_handle_pdu (circuit, ssnpa);
1795
1796 /*
1797 * prepare for next packet.
1798 */
hassof390d2c2004-09-10 20:48:21 +00001799 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1800 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001801
1802 return retval;
1803}
1804
1805#else
1806int
1807isis_receive (struct thread *thread)
1808{
jardineb5d44e2003-12-23 08:09:43 +00001809 struct isis_circuit *circuit;
1810 u_char ssnpa[ETH_ALEN];
1811 int retval;
1812
1813 /*
1814 * Get the circuit
1815 */
1816 circuit = THREAD_ARG (thread);
1817 assert (circuit);
1818
hassof390d2c2004-09-10 20:48:21 +00001819 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001820
1821 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001822 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001823 else
1824 stream_reset (circuit->rcv_stream);
1825
1826 retval = circuit->rx (circuit, ssnpa);
1827
1828 if (retval == ISIS_OK)
1829 retval = isis_handle_pdu (circuit, ssnpa);
1830
1831 /*
1832 * prepare for next packet.
1833 */
hassof390d2c2004-09-10 20:48:21 +00001834 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1835 listcount
1836 (circuit->area->circuit_list) *
1837 100);
jardineb5d44e2003-12-23 08:09:43 +00001838
1839 return retval;
1840}
1841
1842#endif
1843
1844 /* filling of the fixed isis header */
1845void
1846fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1847{
1848 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1849
1850 hdr->idrp = ISO10589_ISIS;
1851
hassof390d2c2004-09-10 20:48:21 +00001852 switch (pdu_type)
1853 {
1854 case L1_LAN_HELLO:
1855 case L2_LAN_HELLO:
1856 hdr->length = ISIS_LANHELLO_HDRLEN;
1857 break;
1858 case P2P_HELLO:
1859 hdr->length = ISIS_P2PHELLO_HDRLEN;
1860 break;
1861 case L1_LINK_STATE:
1862 case L2_LINK_STATE:
1863 hdr->length = ISIS_LSP_HDR_LEN;
1864 break;
1865 case L1_COMPLETE_SEQ_NUM:
1866 case L2_COMPLETE_SEQ_NUM:
1867 hdr->length = ISIS_CSNP_HDRLEN;
1868 break;
1869 case L1_PARTIAL_SEQ_NUM:
1870 case L2_PARTIAL_SEQ_NUM:
1871 hdr->length = ISIS_PSNP_HDRLEN;
1872 break;
1873 default:
1874 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1875 return;
1876 }
jardineb5d44e2003-12-23 08:09:43 +00001877 hdr->length += ISIS_FIXED_HDR_LEN;
1878 hdr->pdu_type = pdu_type;
1879 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001880 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001881 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001882 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001883}
1884
jardineb5d44e2003-12-23 08:09:43 +00001885/*
1886 * SEND SIDE
1887 */
hasso92365882005-01-18 13:53:33 +00001888static void
jardineb5d44e2003-12-23 08:09:43 +00001889fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001890 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001891{
hassof390d2c2004-09-10 20:48:21 +00001892 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001893
1894 stream_putc (stream, hdr->idrp);
1895 stream_putc (stream, hdr->length);
1896 stream_putc (stream, hdr->version1);
1897 stream_putc (stream, hdr->id_len);
1898 stream_putc (stream, hdr->pdu_type);
1899 stream_putc (stream, hdr->version2);
1900 stream_putc (stream, hdr->reserved);
1901 stream_putc (stream, hdr->max_area_addrs);
1902
1903 return;
1904}
1905
jardineb5d44e2003-12-23 08:09:43 +00001906int
1907send_hello (struct isis_circuit *circuit, int level)
1908{
1909 struct isis_fixed_hdr fixed_hdr;
1910 struct isis_lan_hello_hdr hello_hdr;
1911 struct isis_p2p_hello_hdr p2p_hello_hdr;
1912
1913 u_int32_t interval;
1914 unsigned long len_pointer, length;
1915 int retval;
1916
hassof390d2c2004-09-10 20:48:21 +00001917 if (circuit->interface->mtu == 0)
1918 {
1919 zlog_warn ("circuit has zero MTU");
1920 return ISIS_WARNING;
1921 }
jardineb5d44e2003-12-23 08:09:43 +00001922
1923 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001924 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001925 else
1926 stream_reset (circuit->snd_stream);
1927
1928 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1929 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001930 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1931 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001932 else
hassof390d2c2004-09-10 20:48:21 +00001933 fill_fixed_hdr_andstream (&fixed_hdr, L2_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, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001937
1938 /*
1939 * Fill LAN Level 1 or 2 Hello PDU header
1940 */
1941 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001942 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001943 circuit->hello_interval[level - 1];
1944 if (interval > USHRT_MAX)
1945 interval = USHRT_MAX;
1946 hello_hdr.circuit_t = circuit->circuit_is_type;
1947 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001948 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001949
hassof390d2c2004-09-10 20:48:21 +00001950 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00001951 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001952
1953 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001954 if (circuit->circ_type == CIRCUIT_T_P2P)
1955 {
1956 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1957 p2p_hello_hdr.local_id = circuit->circuit_id;
1958 /* FIXME: need better understanding */
1959 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001960 }
hassof390d2c2004-09-10 20:48:21 +00001961 else
1962 {
1963 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1964 if (level == 1 && circuit->u.bc.l1_desig_is)
1965 {
1966 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1967 ISIS_SYS_ID_LEN + 1);
1968 }
1969 else if (level == 2 && circuit->u.bc.l2_desig_is)
1970 {
1971 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1972 ISIS_SYS_ID_LEN + 1);
1973 }
1974 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1975 }
jardineb5d44e2003-12-23 08:09:43 +00001976
1977 /*
1978 * Then the variable length part
1979 */
1980 /* add circuit password */
1981 if (circuit->passwd.type)
1982 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1983 circuit->passwd.passwd, circuit->snd_stream))
1984 return ISIS_WARNING;
1985 /* Area Addresses TLV */
1986 assert (circuit->area);
1987 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1988 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1989 return ISIS_WARNING;
1990
1991 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00001992 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1993 {
1994 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1995 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1996 circuit->snd_stream))
1997 return ISIS_WARNING;
1998 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
1999 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2000 circuit->snd_stream))
2001 return ISIS_WARNING;
2002 }
jardineb5d44e2003-12-23 08:09:43 +00002003
2004 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002005 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002006 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2007 return ISIS_WARNING;
2008 /* IP interface Address TLV */
2009 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2010 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2011 return ISIS_WARNING;
2012
hassof390d2c2004-09-10 20:48:21 +00002013#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002014 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002015 if (circuit->ipv6_router && circuit->ipv6_link &&
jardineb5d44e2003-12-23 08:09:43 +00002016 circuit->ipv6_link->count > 0)
2017 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2018 return ISIS_WARNING;
2019#endif /* HAVE_IPV6 */
2020
2021 if (circuit->u.bc.pad_hellos)
2022 if (tlv_add_padding (circuit->snd_stream))
2023 return ISIS_WARNING;
2024
paul9985f832005-02-09 15:51:56 +00002025 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002026 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002027 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002028
2029 retval = circuit->tx (circuit, level);
2030 if (retval)
2031 zlog_warn ("sending of LAN Level %d Hello failed", level);
2032
2033 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002034 if (isis->debugs & DEBUG_ADJ_PACKETS)
2035 {
2036 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2037 {
hasso529d65b2004-12-24 00:14:50 +00002038 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2039 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002040 /* FIXME: use %z when we stop supporting old compilers. */
2041 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002042 }
2043 else
2044 {
hasso529d65b2004-12-24 00:14:50 +00002045 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2046 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002047 /* FIXME: use %z when we stop supporting old compilers. */
2048 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002049 }
jardineb5d44e2003-12-23 08:09:43 +00002050 }
jardineb5d44e2003-12-23 08:09:43 +00002051
2052 return retval;
2053}
2054
hasso92365882005-01-18 13:53:33 +00002055static int
jardineb5d44e2003-12-23 08:09:43 +00002056send_lan_hello (struct isis_circuit *circuit, int level)
2057{
hassof390d2c2004-09-10 20:48:21 +00002058 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002059}
2060
2061int
2062send_lan_l1_hello (struct thread *thread)
2063{
jardineb5d44e2003-12-23 08:09:43 +00002064 struct isis_circuit *circuit;
2065 int retval;
2066
2067 circuit = THREAD_ARG (thread);
2068 assert (circuit);
2069 circuit->u.bc.t_send_lan_hello[0] = NULL;
2070
2071 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002072 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002073
2074 retval = send_lan_hello (circuit, 1);
2075
2076 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002077 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2078 send_lan_l1_hello, circuit,
2079 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002080
2081 return retval;
2082}
2083
2084int
2085send_lan_l2_hello (struct thread *thread)
2086{
2087 struct isis_circuit *circuit;
2088 int retval;
2089
2090 circuit = THREAD_ARG (thread);
2091 assert (circuit);
2092 circuit->u.bc.t_send_lan_hello[1] = NULL;
2093
2094 if (circuit->u.bc.run_dr_elect[1])
2095 retval = isis_dr_elect (circuit, 2);
2096
2097 retval = send_lan_hello (circuit, 2);
2098
hassof390d2c2004-09-10 20:48:21 +00002099 /* set next timer thread */
2100 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2101 send_lan_l2_hello, circuit,
2102 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002103
2104 return retval;
2105}
2106
2107int
2108send_p2p_hello (struct thread *thread)
2109{
2110 struct isis_circuit *circuit;
2111
2112 circuit = THREAD_ARG (thread);
2113 assert (circuit);
2114 circuit->u.p2p.t_send_p2p_hello = NULL;
2115
hassof390d2c2004-09-10 20:48:21 +00002116 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002117
hassof390d2c2004-09-10 20:48:21 +00002118 /* set next timer thread */
2119 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2120 circuit, isis_jitter (circuit->hello_interval[1],
2121 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002122
2123 return ISIS_OK;
2124}
2125
hasso92365882005-01-18 13:53:33 +00002126static int
hassof390d2c2004-09-10 20:48:21 +00002127build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2128 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002129{
2130 struct isis_fixed_hdr fixed_hdr;
2131 struct isis_passwd *passwd;
2132 int retval = ISIS_OK;
2133 unsigned long lenp;
2134 u_int16_t length;
2135
hassof390d2c2004-09-10 20:48:21 +00002136 if (level == 1)
2137 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2138 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002139 else
hassof390d2c2004-09-10 20:48:21 +00002140 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2141 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002142
2143 /*
2144 * Fill Level 1 or 2 Complete Sequence Numbers header
2145 */
2146
paul9985f832005-02-09 15:51:56 +00002147 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002148 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002149 /* no need to send the source here, it is always us if we csnp */
2150 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2151 /* with zero circuit id - ref 9.10, 9.11 */
2152 stream_putc (circuit->snd_stream, 0x00);
2153
2154 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2155 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2156
2157 /*
2158 * And TLVs
2159 */
2160 if (level == 1)
2161 passwd = &circuit->area->area_passwd;
2162 else
2163 passwd = &circuit->area->domain_passwd;
2164
hasso1cbc5622005-01-01 10:29:51 +00002165 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2166 if (passwd->type)
2167 retval = tlv_add_authinfo (passwd->type, passwd->len,
2168 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002169
hassof390d2c2004-09-10 20:48:21 +00002170 if (!retval && lsps)
2171 {
2172 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2173 }
paul9985f832005-02-09 15:51:56 +00002174 length = (u_int16_t) stream_get_endp (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;
hasso3fdb2dd2005-09-28 18:45:54 +00002193 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002194 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 {
hasso529d65b2004-12-24 00:14:50 +00002214 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
paul1eb8ef22005-04-07 07:30:20 +00002215 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002216 /* FIXME: use %z when we stop supporting old compilers. */
2217 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hasso3fdb2dd2005-09-28 18:45:54 +00002218 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002219 {
hasso529d65b2004-12-24 00:14:50 +00002220 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2221 " cksum 0x%04x, lifetime %us",
2222 circuit->area->area_tag,
2223 rawlspid_print (lsp->lsp_header->lsp_id),
2224 ntohl (lsp->lsp_header->seq_num),
2225 ntohs (lsp->lsp_header->checksum),
2226 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002227 }
2228 }
2229
2230 list_delete (list);
2231
2232 if (retval == ISIS_OK)
2233 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002234 }
jardineb5d44e2003-12-23 08:09:43 +00002235 return retval;
2236}
2237
2238int
2239send_l1_csnp (struct thread *thread)
2240{
2241 struct isis_circuit *circuit;
2242 int retval = ISIS_OK;
2243
2244 circuit = THREAD_ARG (thread);
2245 assert (circuit);
2246
2247 circuit->t_send_csnp[0] = NULL;
2248
hassof390d2c2004-09-10 20:48:21 +00002249 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2250 {
2251 send_csnp (circuit, 1);
2252 }
jardineb5d44e2003-12-23 08:09:43 +00002253 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002254 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2255 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002256
2257 return retval;
2258}
2259
2260int
2261send_l2_csnp (struct thread *thread)
2262{
2263 struct isis_circuit *circuit;
2264 int retval = ISIS_OK;
2265
2266 circuit = THREAD_ARG (thread);
2267 assert (circuit);
2268
2269 circuit->t_send_csnp[1] = NULL;
2270
hassof390d2c2004-09-10 20:48:21 +00002271 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2272 {
2273 send_csnp (circuit, 2);
2274 }
jardineb5d44e2003-12-23 08:09:43 +00002275 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002276 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2277 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002278
jardineb5d44e2003-12-23 08:09:43 +00002279 return retval;
2280}
2281
hasso92365882005-01-18 13:53:33 +00002282static int
jardineb5d44e2003-12-23 08:09:43 +00002283build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2284{
2285 struct isis_fixed_hdr fixed_hdr;
2286 unsigned long lenp;
2287 u_int16_t length;
2288 int retval = 0;
2289 struct isis_lsp *lsp;
2290 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002291 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002292
2293 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002294 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2295 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002296 else
2297 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002298 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002299
2300 /*
2301 * Fill Level 1 or 2 Partial Sequence Numbers header
2302 */
paul9985f832005-02-09 15:51:56 +00002303 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002304 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002305 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2306 stream_putc (circuit->snd_stream, circuit->idx);
2307
2308 /*
2309 * And TLVs
2310 */
2311
2312 if (level == 1)
2313 passwd = &circuit->area->area_passwd;
2314 else
2315 passwd = &circuit->area->domain_passwd;
2316
hasso1cbc5622005-01-01 10:29:51 +00002317 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2318 if (passwd->type)
2319 retval = tlv_add_authinfo (passwd->type, passwd->len,
2320 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002321
hassof390d2c2004-09-10 20:48:21 +00002322 if (!retval && lsps)
2323 {
2324 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002325 }
jardineb5d44e2003-12-23 08:09:43 +00002326
hassof390d2c2004-09-10 20:48:21 +00002327 if (isis->debugs & DEBUG_SNP_PACKETS)
2328 {
hasso3fdb2dd2005-09-28 18:45:54 +00002329 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002330 {
hasso529d65b2004-12-24 00:14:50 +00002331 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2332 " cksum 0x%04x, lifetime %us",
2333 circuit->area->area_tag,
2334 rawlspid_print (lsp->lsp_header->lsp_id),
2335 ntohl (lsp->lsp_header->seq_num),
2336 ntohs (lsp->lsp_header->checksum),
2337 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002338 }
2339 }
2340
paul9985f832005-02-09 15:51:56 +00002341 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002342 assert (length >= ISIS_PSNP_HDRLEN);
2343 /* Update PDU length */
2344 stream_putw_at (circuit->snd_stream, lenp, length);
2345
2346 return ISIS_OK;
2347}
2348
2349/*
2350 * 7.3.15.4 action on expiration of partial SNP interval
2351 * level 1
2352 */
hasso92365882005-01-18 13:53:33 +00002353static int
jardineb5d44e2003-12-23 08:09:43 +00002354send_psnp (int level, struct isis_circuit *circuit)
2355{
2356 int retval = ISIS_OK;
2357 struct isis_lsp *lsp;
2358 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002359 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002360
hassof390d2c2004-09-10 20:48:21 +00002361 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002362 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002363 circuit->circ_type != CIRCUIT_T_BROADCAST)
2364 {
jardineb5d44e2003-12-23 08:09:43 +00002365
hassof390d2c2004-09-10 20:48:21 +00002366 if (circuit->area->lspdb[level - 1] &&
2367 dict_count (circuit->area->lspdb[level - 1]) > 0)
2368 {
2369 list = list_new ();
2370 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002371
hassof390d2c2004-09-10 20:48:21 +00002372 if (listcount (list) > 0)
2373 {
2374 if (circuit->snd_stream == NULL)
2375 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2376 else
2377 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002378
2379
hassof390d2c2004-09-10 20:48:21 +00002380 if (isis->debugs & DEBUG_SNP_PACKETS)
hasso529d65b2004-12-24 00:14:50 +00002381 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2382 circuit->area->area_tag, level,
2383 circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002384 /* FIXME: use %z when we stop supporting old
2385 * compilers. */
2386 (unsigned long) STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002387
hassof390d2c2004-09-10 20:48:21 +00002388 retval = build_psnp (level, circuit, list);
2389 if (retval == ISIS_OK)
2390 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002391
hassof390d2c2004-09-10 20:48:21 +00002392 if (retval == ISIS_OK)
2393 {
2394 /*
2395 * sending succeeded, we can clear SSN flags of this circuit
2396 * for the LSPs in list
2397 */
hasso3fdb2dd2005-09-28 18:45:54 +00002398 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +00002399 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002400 }
2401 }
2402 list_delete (list);
2403 }
jardineb5d44e2003-12-23 08:09:43 +00002404 }
jardineb5d44e2003-12-23 08:09:43 +00002405
2406 return retval;
2407}
2408
2409int
2410send_l1_psnp (struct thread *thread)
2411{
2412
2413 struct isis_circuit *circuit;
2414 int retval = ISIS_OK;
2415
2416 circuit = THREAD_ARG (thread);
2417 assert (circuit);
2418
2419 circuit->t_send_psnp[0] = NULL;
2420
2421 send_psnp (1, circuit);
2422 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002423 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2424 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002425
2426 return retval;
2427}
2428
2429/*
2430 * 7.3.15.4 action on expiration of partial SNP interval
2431 * level 2
2432 */
2433int
2434send_l2_psnp (struct thread *thread)
2435{
jardineb5d44e2003-12-23 08:09:43 +00002436 struct isis_circuit *circuit;
2437 int retval = ISIS_OK;
2438
2439 circuit = THREAD_ARG (thread);
2440 assert (circuit);
2441
2442 circuit->t_send_psnp[1] = NULL;
2443
2444 send_psnp (2, circuit);
2445
2446 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002447 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2448 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002449
2450 return retval;
2451}
2452
jardineb5d44e2003-12-23 08:09:43 +00002453/*
2454 * ISO 10589 - 7.3.14.3
2455 */
2456int
2457send_lsp (struct thread *thread)
2458{
2459 struct isis_circuit *circuit;
2460 struct isis_lsp *lsp;
2461 struct listnode *node;
2462 int retval = 0;
2463
2464 circuit = THREAD_ARG (thread);
2465 assert (circuit);
2466
hassof390d2c2004-09-10 20:48:21 +00002467 if (circuit->state == C_STATE_UP)
2468 {
paul1eb8ef22005-04-07 07:30:20 +00002469 lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
jardineb5d44e2003-12-23 08:09:43 +00002470
2471 /*
hassof390d2c2004-09-10 20:48:21 +00002472 * Do not send if levels do not match
jardineb5d44e2003-12-23 08:09:43 +00002473 */
hassof390d2c2004-09-10 20:48:21 +00002474 if (!(lsp->level & circuit->circuit_is_type))
2475 goto dontsend;
jardineb5d44e2003-12-23 08:09:43 +00002476
hassof390d2c2004-09-10 20:48:21 +00002477 /*
2478 * Do not send if we do not have adjacencies in state up on the circuit
2479 */
2480 if (circuit->upadjcount[lsp->level - 1] == 0)
2481 goto dontsend;
2482 /* only send if it needs sending */
2483 if ((time (NULL) - lsp->last_sent) >=
2484 circuit->area->lsp_gen_interval[lsp->level - 1])
2485 {
jardineb5d44e2003-12-23 08:09:43 +00002486
hassof390d2c2004-09-10 20:48:21 +00002487 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2488 {
hasso529d65b2004-12-24 00:14:50 +00002489 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00002490 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2491 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2492 rawlspid_print (lsp->lsp_header->lsp_id),
2493 ntohl (lsp->lsp_header->seq_num),
2494 ntohs (lsp->lsp_header->checksum),
2495 ntohs (lsp->lsp_header->rem_lifetime),
2496 circuit->interface->name);
2497 }
2498 /* copy our lsp to the send buffer */
paul15935e92005-05-03 09:27:23 +00002499 stream_copy (circuit->snd_stream, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00002500
2501 retval = circuit->tx (circuit, lsp->level);
2502
jardineb5d44e2003-12-23 08:09:43 +00002503 /*
hassof390d2c2004-09-10 20:48:21 +00002504 * If the sending succeeded, we can del the lsp from circuits
2505 * lsp_queue
jardineb5d44e2003-12-23 08:09:43 +00002506 */
hassof390d2c2004-09-10 20:48:21 +00002507 if (retval == ISIS_OK)
2508 {
2509 list_delete_node (circuit->lsp_queue, node);
2510
2511 /*
2512 * On broadcast circuits also the SRMflag can be cleared
2513 */
2514 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2515 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2516
2517 if (flags_any_set (lsp->SRMflags) == 0)
2518 {
2519 /*
2520 * need to remember when we were last sent
2521 */
2522 lsp->last_sent = time (NULL);
2523 }
2524 }
2525 else
2526 {
hasso529d65b2004-12-24 00:14:50 +00002527 zlog_debug ("sending of level %d link state failed", lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002528 }
jardineb5d44e2003-12-23 08:09:43 +00002529 }
hassof390d2c2004-09-10 20:48:21 +00002530 else
2531 {
2532 /* my belief is that if it wasn't his time, the lsp can be removed
2533 * from the queue
2534 */
2535 dontsend:
2536 list_delete_node (circuit->lsp_queue, node);
2537 }
jardineb5d44e2003-12-23 08:09:43 +00002538#if 0
hassof390d2c2004-09-10 20:48:21 +00002539 /*
2540 * If there are still LSPs send next one after lsp-interval (33 msecs)
2541 */
2542 if (listcount (circuit->lsp_queue) > 0)
2543 thread_add_timer (master, send_lsp, circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002544#endif
hassof390d2c2004-09-10 20:48:21 +00002545 }
jardineb5d44e2003-12-23 08:09:43 +00002546
2547 return retval;
hassof390d2c2004-09-10 20:48:21 +00002548}
jardineb5d44e2003-12-23 08:09:43 +00002549
2550int
hassof390d2c2004-09-10 20:48:21 +00002551ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2552 int level)
jardineb5d44e2003-12-23 08:09:43 +00002553{
2554 unsigned long lenp;
2555 int retval;
2556 u_int16_t length;
2557 struct isis_fixed_hdr fixed_hdr;
2558
2559 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002560 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002561 else
2562 stream_reset (circuit->snd_stream);
2563
2564// fill_llc_hdr (stream);
2565 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002566 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2567 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002568 else
hassof390d2c2004-09-10 20:48:21 +00002569 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2570 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002571
2572
paul9985f832005-02-09 15:51:56 +00002573 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002574 stream_putw (circuit->snd_stream, 0); /* PDU length */
2575 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002576 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002577 stream_putc (circuit->snd_stream, 9); /* code */
2578 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002579
hassof390d2c2004-09-10 20:48:21 +00002580 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2581 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2582 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2583 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002584
paul9985f832005-02-09 15:51:56 +00002585 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002586 /* Update PDU length */
2587 stream_putw_at (circuit->snd_stream, lenp, length);
2588
2589 retval = circuit->tx (circuit, level);
2590
2591 return retval;
2592}
2593