blob: b83c6339dbd5da33cf7852f480d5d835fe37f777 [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;
paul1eb8ef22005-04-07 07:30:20 +000083 struct listnode *node1, *nnode1;
84 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +000085
paul1eb8ef22005-04-07 07:30:20 +000086 for (ALL_LIST_ELEMENTS (left, node1, nnode1, addr1))
hassof390d2c2004-09-10 20:48:21 +000087 {
paul1eb8ef22005-04-07 07:30:20 +000088 for (ALL_LIST_ELEMENTS (right, node2, nnode2, addr2))
hassof390d2c2004-09-10 20:48:21 +000089 {
90 if (addr1->addr_len == addr2->addr_len &&
91 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
92 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000093 }
94 }
95
hassof390d2c2004-09-10 20:48:21 +000096 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000097}
98
99/*
100 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
101 * param ip1 the IS interface ip address structure
102 * param ip2 the IIH's ip address
103 * return 0 the IIH's IP is not in the IS's subnetwork
104 * 1 the IIH's IP is in the IS's subnetwork
105 */
hasso92365882005-01-18 13:53:33 +0000106static int
hassof390d2c2004-09-10 20:48:21 +0000107ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000108{
109 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000110 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000111 int len;
hassof390d2c2004-09-10 20:48:21 +0000112
113 addr1 = (u_char *) & ip1->prefix.s_addr;
114 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000115 len = ip1->prefixlen;
116
117 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000118 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000119
hasso53c997c2004-09-15 16:21:59 +0000120 while (offsetloop--)
121 if (addr1[offsetloop] != addr2[offsetloop])
122 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000123
hassof390d2c2004-09-10 20:48:21 +0000124 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000125 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
126 return 0;
hassof390d2c2004-09-10 20:48:21 +0000127
128 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000129}
130
jardineb5d44e2003-12-23 08:09:43 +0000131/*
132 * Compares two set of ip addresses
133 * param left the local interface's ip addresses
134 * param right the iih interface's ip address
135 * return 0 no match;
136 * 1 match;
137 */
hassof390d2c2004-09-10 20:48:21 +0000138static int
jardineb5d44e2003-12-23 08:09:43 +0000139ip_match (struct list *left, struct list *right)
140{
141 struct prefix_ipv4 *ip1;
142 struct in_addr *ip2;
paul1eb8ef22005-04-07 07:30:20 +0000143 struct listnode *node1, *nnode1;
144 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +0000145
hassoe082ac12004-09-27 18:13:57 +0000146 if ((left == NULL) || (right == NULL))
147 return 0;
148
paul1eb8ef22005-04-07 07:30:20 +0000149 for (ALL_LIST_ELEMENTS (left, node1, nnode1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000150 {
paul1eb8ef22005-04-07 07:30:20 +0000151 for (ALL_LIST_ELEMENTS (right, node2, nnode2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000152 {
153 if (ip_same_subnet (ip1, ip2))
154 {
155 return 1; /* match */
156 }
jardineb5d44e2003-12-23 08:09:43 +0000157 }
hassof390d2c2004-09-10 20:48:21 +0000158
jardineb5d44e2003-12-23 08:09:43 +0000159 }
160 return 0;
161}
162
163/*
164 * Checks whether we should accept a PDU of given level
165 */
166static int
167accept_level (int level, int circuit_t)
168{
hassof390d2c2004-09-10 20:48:21 +0000169 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000170
171 return retval;
172}
173
hassof390d2c2004-09-10 20:48:21 +0000174int
jardineb5d44e2003-12-23 08:09:43 +0000175authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
176{
hassof390d2c2004-09-10 20:48:21 +0000177 if (one->type != theother->type)
178 {
179 zlog_warn ("Unsupported authentication type %d", theother->type);
180 return 1; /* Auth fail (different authentication types) */
181 }
182 switch (one->type)
183 {
184 case ISIS_PASSWD_TYPE_CLEARTXT:
185 if (one->len != theother->len)
186 return 1; /* Auth fail () - passwd len mismatch */
187 return memcmp (one->passwd, theother->passwd, one->len);
188 break;
189 default:
190 zlog_warn ("Unsupported authentication type");
191 break;
192 }
193 return 0; /* Auth pass */
jardineb5d44e2003-12-23 08:09:43 +0000194}
195
196/*
197 * Processing helper functions
198 */
hasso92365882005-01-18 13:53:33 +0000199static void
hassof390d2c2004-09-10 20:48:21 +0000200tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000201{
202 int i;
203 struct nlpids *tlv_nlpids;
204
hassof390d2c2004-09-10 20:48:21 +0000205 if (tlvs->nlpids)
206 {
jardineb5d44e2003-12-23 08:09:43 +0000207
hassof390d2c2004-09-10 20:48:21 +0000208 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000209
hassof390d2c2004-09-10 20:48:21 +0000210 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000211
hassof390d2c2004-09-10 20:48:21 +0000212 for (i = 0; i < tlv_nlpids->count; i++)
213 {
214 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
215 }
jardineb5d44e2003-12-23 08:09:43 +0000216 }
jardineb5d44e2003-12-23 08:09:43 +0000217}
218
hasso92365882005-01-18 13:53:33 +0000219static void
jardineb5d44e2003-12-23 08:09:43 +0000220del_ip_addr (void *val)
221{
222 XFREE (MTYPE_ISIS_TMP, val);
223}
224
hasso92365882005-01-18 13:53:33 +0000225static void
hassof390d2c2004-09-10 20:48:21 +0000226tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000227{
paul1eb8ef22005-04-07 07:30:20 +0000228 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +0000229 struct in_addr *ipv4_addr, *malloced;
230
hassof390d2c2004-09-10 20:48:21 +0000231 if (adj->ipv4_addrs)
232 {
233 adj->ipv4_addrs->del = del_ip_addr;
234 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000235 }
hassof390d2c2004-09-10 20:48:21 +0000236 adj->ipv4_addrs = list_new ();
237 if (tlvs->ipv4_addrs)
238 {
paul1eb8ef22005-04-07 07:30:20 +0000239 for (ALL_LIST_ELEMENTS (tlvs->ipv4_addrs, node, nnode, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000240 {
241 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
242 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
243 listnode_add (adj->ipv4_addrs, malloced);
244 }
245 }
jardineb5d44e2003-12-23 08:09:43 +0000246}
247
248#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000249static void
hassof390d2c2004-09-10 20:48:21 +0000250tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000251{
paul1eb8ef22005-04-07 07:30:20 +0000252 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +0000253 struct in6_addr *ipv6_addr, *malloced;
254
hassof390d2c2004-09-10 20:48:21 +0000255 if (adj->ipv6_addrs)
256 {
257 adj->ipv6_addrs->del = del_ip_addr;
258 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000259 }
hassof390d2c2004-09-10 20:48:21 +0000260 adj->ipv6_addrs = list_new ();
261 if (tlvs->ipv6_addrs)
262 {
paul1eb8ef22005-04-07 07:30:20 +0000263 for (ALL_LIST_ELEMENTS (tlvs->ipv6_addrs, node, nnode, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000264 {
265 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
266 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
267 listnode_add (adj->ipv6_addrs, malloced);
268 }
269 }
jardineb5d44e2003-12-23 08:09:43 +0000270
271}
272#endif /* HAVE_IPV6 */
273
jardineb5d44e2003-12-23 08:09:43 +0000274/*
275 * RECEIVE SIDE
276 */
277
278/*
279 * Process P2P IIH
280 * ISO - 10589
281 * Section 8.2.5 - Receiving point-to-point IIH PDUs
282 *
283 */
284static int
285process_p2p_hello (struct isis_circuit *circuit)
286{
287 int retval = ISIS_OK;
288 struct isis_p2p_hello_hdr *hdr;
289 struct isis_adjacency *adj;
290 u_int32_t expected = 0, found;
291 struct tlvs tlvs;
292
hassof390d2c2004-09-10 20:48:21 +0000293 if ((stream_get_endp (circuit->rcv_stream) -
294 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
295 {
296 zlog_warn ("Packet too short");
297 return ISIS_WARNING;
298 }
jardineb5d44e2003-12-23 08:09:43 +0000299
300 /* 8.2.5.1 PDU acceptance tests */
301
302 /* 8.2.5.1 a) external domain untrue */
303 /* FIXME: not useful at all? */
304
305 /* 8.2.5.1 b) ID Length mismatch */
306 /* checked at the handle_pdu */
307
308 /* 8.2.5.2 IIH PDU Processing */
309
310 /* 8.2.5.2 a) 1) Maximum Area Addresses */
311 /* Already checked, and can also be ommited */
312
313 /*
314 * Get the header
315 */
hassof390d2c2004-09-10 20:48:21 +0000316 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000317 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
318
319 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000320 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
321 hdr.hold_time = stream_getw (stream);
322 hdr.pdu_len = stream_getw (stream);
323 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000324
325 /*
326 * My interpertation of the ISO, if no adj exists we will create one for
327 * the circuit
328 */
329
hassof390d2c2004-09-10 20:48:21 +0000330 if (isis->debugs & DEBUG_ADJ_PACKETS)
331 {
hasso529d65b2004-12-24 00:14:50 +0000332 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
333 " cir id %02d, length %d",
334 circuit->area->area_tag, circuit->interface->name,
335 circuit_t2string (circuit->circuit_is_type),
336 circuit->circuit_id, ntohs (hdr->pdu_len));
hassof390d2c2004-09-10 20:48:21 +0000337 }
jardineb5d44e2003-12-23 08:09:43 +0000338
339 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000340 if (!adj)
341 {
hassof7c43dc2004-09-26 16:24:14 +0000342 adj = isis_new_adj (hdr->source_id, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +0000343 if (adj == NULL)
344 return ISIS_ERROR;
345 circuit->u.p2p.neighbor = adj;
346 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
347 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
348 }
jardineb5d44e2003-12-23 08:09:43 +0000349
350 /* 8.2.6 Monitoring point-to-point adjacencies */
351 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000352 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000353
354 /*
355 * Lets get the TLVS now
356 */
357 expected |= TLVFLAG_AREA_ADDRS;
358 expected |= TLVFLAG_AUTH_INFO;
359 expected |= TLVFLAG_NLPID;
360 expected |= TLVFLAG_IPV4_ADDR;
361 expected |= TLVFLAG_IPV6_ADDR;
362
363 retval = parse_tlvs (circuit->area->area_tag,
364 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000365 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
366 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000367
hassof390d2c2004-09-10 20:48:21 +0000368 if (retval > ISIS_WARNING)
369 {
370 free_tlvs (&tlvs);
371 return retval;
372 };
jardineb5d44e2003-12-23 08:09:43 +0000373
374 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000375 if (circuit->passwd.type)
376 {
377 if (!(found & TLVFLAG_AUTH_INFO) ||
378 authentication_check (&circuit->passwd, &tlvs.auth_info))
379 {
380 isis_event_auth_failure (circuit->area->area_tag,
381 "P2P hello authentication failure",
382 hdr->source_id);
383 return ISIS_OK;
384 }
jardineb5d44e2003-12-23 08:09:43 +0000385 }
jardineb5d44e2003-12-23 08:09:43 +0000386
387 /* we do this now because the adj may not survive till the end... */
388
389 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000390 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000391
392#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000393 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000394#endif /* HAVE_IPV6 */
395
396 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000397 THREAD_TIMER_OFF (adj->t_expire);
398 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
399 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000400
401 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000402 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
403 {
404 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
405 if (circuit->area->is_type == IS_LEVEL_1)
406 {
407 switch (hdr->circuit_t)
408 {
409 case IS_LEVEL_1:
410 case IS_LEVEL_1_AND_2:
411 if (adj->adj_state != ISIS_ADJ_UP)
412 {
413 /* (4) adj state up */
414 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
415 /* (5) adj usage level 1 */
416 adj->adj_usage = ISIS_ADJ_LEVEL1;
417 }
418 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
419 {
420 ; /* accept */
421 }
422 break;
423 case IS_LEVEL_2:
424 if (adj->adj_state != ISIS_ADJ_UP)
425 {
426 /* (7) reject - wrong system type event */
427 zlog_warn ("wrongSystemType");
428 return ISIS_WARNING; /* Reject */
429 }
430 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
431 {
432 /* (6) down - wrong system */
433 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
434 }
435 break;
436 }
437 }
jardineb5d44e2003-12-23 08:09:43 +0000438
hassof390d2c2004-09-10 20:48:21 +0000439 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
440 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
441 {
442 switch (hdr->circuit_t)
443 {
444 case IS_LEVEL_1:
445 if (adj->adj_state != ISIS_ADJ_UP)
446 {
447 /* (6) adj state up */
448 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
449 /* (7) adj usage level 1 */
450 adj->adj_usage = ISIS_ADJ_LEVEL1;
451 }
452 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
453 {
454 ; /* accept */
455 }
456 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
457 (adj->adj_usage == ISIS_ADJ_LEVEL2))
458 {
459 /* (8) down - wrong system */
460 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
461 }
462 break;
463 case IS_LEVEL_2:
464 if (adj->adj_state != ISIS_ADJ_UP)
465 {
466 /* (6) adj state up */
467 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
468 /* (9) adj usage level 2 */
469 adj->adj_usage = ISIS_ADJ_LEVEL2;
470 }
471 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
472 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
473 {
474 /* (8) down - wrong system */
475 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
476 }
477 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
478 {
479 ; /* Accept */
480 }
481 break;
482 case IS_LEVEL_1_AND_2:
483 if (adj->adj_state != ISIS_ADJ_UP)
484 {
485 /* (6) adj state up */
486 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
487 /* (10) adj usage level 1 */
488 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
489 }
490 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
491 (adj->adj_usage == ISIS_ADJ_LEVEL2))
492 {
493 /* (8) down - wrong system */
494 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
495 }
496 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
497 {
498 ; /* Accept */
499 }
500 break;
501 }
502 }
jardineb5d44e2003-12-23 08:09:43 +0000503
hassof390d2c2004-09-10 20:48:21 +0000504 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
505 if (circuit->area->is_type == IS_LEVEL_2)
506 {
507 switch (hdr->circuit_t)
508 {
509 case IS_LEVEL_1:
510 if (adj->adj_state != ISIS_ADJ_UP)
511 {
512 /* (5) reject - wrong system type event */
513 zlog_warn ("wrongSystemType");
514 return ISIS_WARNING; /* Reject */
515 }
516 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
517 (adj->adj_usage == ISIS_ADJ_LEVEL2))
518 {
519 /* (6) down - wrong system */
520 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
521 }
522 break;
523 case IS_LEVEL_1_AND_2:
524 case IS_LEVEL_2:
525 if (adj->adj_state != ISIS_ADJ_UP)
526 {
527 /* (7) adj state up */
528 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
529 /* (8) adj usage level 2 */
530 adj->adj_usage = ISIS_ADJ_LEVEL2;
531 }
532 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
533 {
534 /* (6) down - wrong system */
535 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
536 }
537 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
538 {
539 ; /* Accept */
540 }
541 break;
542 }
543 }
jardineb5d44e2003-12-23 08:09:43 +0000544 }
jardineb5d44e2003-12-23 08:09:43 +0000545 /* 8.2.5.2 b) if no match was detected */
546 else
jardineb5d44e2003-12-23 08:09:43 +0000547 {
hassof390d2c2004-09-10 20:48:21 +0000548 if (circuit->area->is_type == IS_LEVEL_1)
549 {
550 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
551 if (adj->adj_state != ISIS_ADJ_UP)
552 {
553 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
554 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
555 }
556 else
557 {
558 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
559 "Down - Area Mismatch");
560 }
561 }
562 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
563 else
564 {
565 switch (hdr->circuit_t)
566 {
567 case IS_LEVEL_1:
568 if (adj->adj_state != ISIS_ADJ_UP)
569 {
570 /* (6) reject - Area Mismatch event */
571 zlog_warn ("AreaMismatch");
572 return ISIS_WARNING; /* Reject */
573 }
574 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
575 {
576 /* (7) down - area mismatch */
577 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000578
hassof390d2c2004-09-10 20:48:21 +0000579 }
580 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
581 (adj->adj_usage == ISIS_ADJ_LEVEL2))
582 {
583 /* (7) down - wrong system */
584 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
585 }
586 break;
587 case IS_LEVEL_1_AND_2:
588 case IS_LEVEL_2:
589 if (adj->adj_state != ISIS_ADJ_UP)
590 {
591 /* (8) adj state up */
592 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
593 /* (9) adj usage level 2 */
594 adj->adj_usage = ISIS_ADJ_LEVEL2;
595 }
596 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
597 {
598 /* (7) down - wrong system */
599 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
600 }
601 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
602 {
603 if (hdr->circuit_t == IS_LEVEL_2)
604 {
605 /* (7) down - wrong system */
606 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
607 "Wrong System");
608 }
609 else
610 {
611 /* (7) down - area mismatch */
612 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
613 "Area Mismatch");
614 }
615 }
616 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
617 {
618 ; /* Accept */
619 }
620 break;
621 }
622 }
jardineb5d44e2003-12-23 08:09:43 +0000623 }
jardineb5d44e2003-12-23 08:09:43 +0000624 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
625 /* FIXME - Missing parts */
626
jardineb5d44e2003-12-23 08:09:43 +0000627 /* some of my own understanding of the ISO, why the heck does
628 * it not say what should I change the system_type to...
629 */
hassof390d2c2004-09-10 20:48:21 +0000630 switch (adj->adj_usage)
631 {
jardineb5d44e2003-12-23 08:09:43 +0000632 case ISIS_ADJ_LEVEL1:
633 adj->sys_type = ISIS_SYSTYPE_L1_IS;
634 break;
635 case ISIS_ADJ_LEVEL2:
636 adj->sys_type = ISIS_SYSTYPE_L2_IS;
637 break;
638 case ISIS_ADJ_LEVEL1AND2:
639 adj->sys_type = ISIS_SYSTYPE_L2_IS;
640 break;
641 case ISIS_ADJ_NONE:
642 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
643 break;
hassof390d2c2004-09-10 20:48:21 +0000644 }
jardineb5d44e2003-12-23 08:09:43 +0000645
646 adj->circuit_t = hdr->circuit_t;
647 adj->level = hdr->circuit_t;
648
649 free_tlvs (&tlvs);
650
651 return retval;
652}
653
jardineb5d44e2003-12-23 08:09:43 +0000654/*
655 * Process IS-IS LAN Level 1/2 Hello PDU
656 */
hassof390d2c2004-09-10 20:48:21 +0000657static int
658process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000659{
660 int retval = ISIS_OK;
661 struct isis_lan_hello_hdr hdr;
662 struct isis_adjacency *adj;
663 u_int32_t expected = 0, found;
664 struct tlvs tlvs;
665 u_char *snpa;
paul1eb8ef22005-04-07 07:30:20 +0000666 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +0000667
hassof390d2c2004-09-10 20:48:21 +0000668 if ((stream_get_endp (circuit->rcv_stream) -
669 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
670 {
671 zlog_warn ("Packet too short");
672 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000673 }
hassof390d2c2004-09-10 20:48:21 +0000674
675 if (circuit->ext_domain)
676 {
hasso529d65b2004-12-24 00:14:50 +0000677 zlog_debug ("level %d LAN Hello received over circuit with "
678 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000679 return ISIS_WARNING;
680 }
681
682 if (!accept_level (level, circuit->circuit_is_type))
683 {
684 if (isis->debugs & DEBUG_ADJ_PACKETS)
685 {
hasso529d65b2004-12-24 00:14:50 +0000686 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
687 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000688 }
689 return ISIS_WARNING;
690 }
jardineb5d44e2003-12-23 08:09:43 +0000691
692#if 0
693 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000694 if (!accept_level (level, circuit->area->is_type))
695 {
696 if (isis->debugs & DEBUG_ADJ_PACKETS)
697 {
hasso529d65b2004-12-24 00:14:50 +0000698 zlog_debug ("ISIS-Adj (%s): is type mismatch",
699 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000700 }
701 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000702 }
jardineb5d44e2003-12-23 08:09:43 +0000703#endif
704 /*
705 * Fill the header
706 */
707 hdr.circuit_t = stream_getc (circuit->rcv_stream);
708 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
709 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000710 hdr.pdu_len = stream_getw (circuit->rcv_stream);
711 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000712 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
713
714 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000715 hdr.circuit_t != IS_LEVEL_1_AND_2)
716 {
717 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
718 hdr.circuit_t);
719 return ISIS_ERROR;
720 }
jardineb5d44e2003-12-23 08:09:43 +0000721 /*
722 * Then get the tlvs
723 */
724 expected |= TLVFLAG_AUTH_INFO;
725 expected |= TLVFLAG_AREA_ADDRS;
726 expected |= TLVFLAG_LAN_NEIGHS;
727 expected |= TLVFLAG_NLPID;
728 expected |= TLVFLAG_IPV4_ADDR;
729 expected |= TLVFLAG_IPV6_ADDR;
730
731 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000732 STREAM_PNT (circuit->rcv_stream),
733 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
734 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000735
hassof390d2c2004-09-10 20:48:21 +0000736 if (retval > ISIS_WARNING)
737 {
738 zlog_warn ("parse_tlvs() failed");
739 goto out;
740 }
jardineb5d44e2003-12-23 08:09:43 +0000741
hassof390d2c2004-09-10 20:48:21 +0000742 if (!(found & TLVFLAG_AREA_ADDRS))
743 {
744 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
745 level);
jardineb5d44e2003-12-23 08:09:43 +0000746 retval = ISIS_WARNING;
747 goto out;
748 }
hassof390d2c2004-09-10 20:48:21 +0000749
750 if (circuit->passwd.type)
751 {
752 if (!(found & TLVFLAG_AUTH_INFO) ||
753 authentication_check (&circuit->passwd, &tlvs.auth_info))
754 {
755 isis_event_auth_failure (circuit->area->area_tag,
756 "LAN hello authentication failure",
757 hdr.source_id);
758 retval = ISIS_WARNING;
759 goto out;
760 }
761 }
jardineb5d44e2003-12-23 08:09:43 +0000762
763 /*
764 * Accept the level 1 adjacency only if a match between local and
765 * remote area addresses is found
766 */
hassof390d2c2004-09-10 20:48:21 +0000767 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
768 {
769 if (isis->debugs & DEBUG_ADJ_PACKETS)
770 {
hasso529d65b2004-12-24 00:14:50 +0000771 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
772 circuit->area->area_tag, level,
773 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000774 }
775 retval = ISIS_OK;
776 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000777 }
jardineb5d44e2003-12-23 08:09:43 +0000778
779 /*
780 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000781 */
782 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
783 {
hasso529d65b2004-12-24 00:14:50 +0000784 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
785 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000786
hassof390d2c2004-09-10 20:48:21 +0000787 retval = ISIS_OK;
788 goto out;
789 }
jardineb5d44e2003-12-23 08:09:43 +0000790
791 /*
792 * check if it's own interface ip match iih ip addrs
793 */
hassof390d2c2004-09-10 20:48:21 +0000794 if (!(found & TLVFLAG_IPV4_ADDR)
795 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
796 {
hasso529d65b2004-12-24 00:14:50 +0000797 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000798 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
799 circuit->interface->name);
800 retval = ISIS_WARNING;
801 goto out;
802 }
jardineb5d44e2003-12-23 08:09:43 +0000803
804 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000805 if (!adj)
806 {
807 /*
808 * Do as in 8.4.2.5
809 */
810 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
811 if (adj == NULL)
hasso13c48f72004-09-10 21:19:13 +0000812 {
813 retval = ISIS_ERROR;
814 goto out;
815 }
jardineb5d44e2003-12-23 08:09:43 +0000816
hassof390d2c2004-09-10 20:48:21 +0000817 adj->level = level;
818 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000819
hassof390d2c2004-09-10 20:48:21 +0000820 if (level == 1)
821 {
822 adj->sys_type = ISIS_SYSTYPE_L1_IS;
823 }
824 else
825 {
826 adj->sys_type = ISIS_SYSTYPE_L2_IS;
827 }
828 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
829 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
830 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000831 }
jardineb5d44e2003-12-23 08:09:43 +0000832
hassoa211d652004-09-20 14:55:29 +0000833 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
834 switch (level)
835 {
836 case 1:
837 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
838 {
839 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000840 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
841 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000842 }
843 break;
844 case 2:
845 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
846 {
847 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000848 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
849 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000850 }
851 break;
852 }
jardineb5d44e2003-12-23 08:09:43 +0000853
854 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000855 adj->last_upd = time (NULL);
856 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000857
858 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
859
860 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000861 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000862 tlvs_to_adj_nlpids (&tlvs, adj);
863
864 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000865 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000866 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
867
868#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000869 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000870 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
871#endif /* HAVE_IPV6 */
872
873 adj->circuit_t = hdr.circuit_t;
874
875 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000876 THREAD_TIMER_OFF (adj->t_expire);
877 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
878 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000879
880 /*
881 * If the snpa for this circuit is found from LAN Neighbours TLV
882 * we have two-way communication -> adjacency can be put to state "up"
883 */
884
hassof390d2c2004-09-10 20:48:21 +0000885 if (found & TLVFLAG_LAN_NEIGHS)
886 {
887 if (adj->adj_state != ISIS_ADJ_UP)
888 {
paul1eb8ef22005-04-07 07:30:20 +0000889 for (ALL_LIST_ELEMENTS (tlvs.lan_neighs, node, nnode, snpa))
hassof390d2c2004-09-10 20:48:21 +0000890 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
891 {
892 isis_adj_state_change (adj, ISIS_ADJ_UP,
893 "own SNPA found in LAN Neighbours TLV");
894 }
895 }
jardineb5d44e2003-12-23 08:09:43 +0000896 }
jardineb5d44e2003-12-23 08:09:43 +0000897
hassof390d2c2004-09-10 20:48:21 +0000898out:
jardineb5d44e2003-12-23 08:09:43 +0000899 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000900 if (isis->debugs & DEBUG_ADJ_PACKETS)
901 {
902 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +0000903 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
904 "cirID %u, length %ld",
905 circuit->area->area_tag,
906 level, snpa_print (ssnpa), circuit->interface->name,
907 circuit_t2string (circuit->circuit_is_type),
908 circuit->circuit_id, 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),
paul15935e92005-05-03 09:27:23 +0000952 stream_get_endp (circuit->rcv_stream),
953 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000954 }
jardineb5d44e2003-12-23 08:09:43 +0000955
956 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
957
958 /* Checksum sanity check - FIXME: move to correct place */
959 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000960 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
961 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
962 {
hasso529d65b2004-12-24 00:14:50 +0000963 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
964 circuit->area->area_tag,
965 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000966
hassof390d2c2004-09-10 20:48:21 +0000967 return ISIS_WARNING;
968 }
jardineb5d44e2003-12-23 08:09:43 +0000969
970 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000971 if (circuit->ext_domain)
972 {
hasso529d65b2004-12-24 00:14:50 +0000973 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000974 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
975 "externalDomain = true", circuit->area->area_tag,
976 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000977
hassof390d2c2004-09-10 20:48:21 +0000978 return ISIS_WARNING;
979 }
jardineb5d44e2003-12-23 08:09:43 +0000980
981 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000982 if (!accept_level (level, circuit->circuit_is_type))
983 {
hasso529d65b2004-12-24 00:14:50 +0000984 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
985 " type %s",
986 circuit->area->area_tag,
987 rawlspid_print (hdr->lsp_id),
988 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +0000989
hassof390d2c2004-09-10 20:48:21 +0000990 return ISIS_WARNING;
991 }
jardineb5d44e2003-12-23 08:09:43 +0000992
993 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
994
995 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
996
997 /* 7.3.15.1 a) 7 - password check */
998 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
999 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001000 if (passwd->type)
1001 {
1002 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1003 ntohs (hdr->pdu_len), passwd))
1004 {
1005 isis_event_auth_failure (circuit->area->area_tag,
1006 "LSP authentication failure", hdr->lsp_id);
1007 return ISIS_WARNING;
1008 }
jardineb5d44e2003-12-23 08:09:43 +00001009 }
jardineb5d44e2003-12-23 08:09:43 +00001010 /* Find the LSP in our database and compare it to this Link State header */
1011 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1012 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001013 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1014 hdr->checksum, hdr->rem_lifetime);
1015 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001016#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001017 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001018#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001019 ))
jardineb5d44e2003-12-23 08:09:43 +00001020 goto dontcheckadj;
1021
1022 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1023 /* for broadcast circuits, snpa should be compared */
1024 /* FIXME : Point To Point */
1025
hassof390d2c2004-09-10 20:48:21 +00001026 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1027 {
1028 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1029 if (!adj)
1030 {
hasso529d65b2004-12-24 00:14:50 +00001031 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1032 "lifetime %us on %s",
1033 circuit->area->area_tag,
1034 rawlspid_print (hdr->lsp_id),
1035 ntohl (hdr->seq_num),
1036 ntohs (hdr->checksum),
1037 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001038 return ISIS_WARNING; /* Silently discard */
1039 }
jardineb5d44e2003-12-23 08:09:43 +00001040 }
jardineb5d44e2003-12-23 08:09:43 +00001041
1042 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001043 else
1044 {
1045 /* If no adj, or no sharing of level */
1046 if (!circuit->u.p2p.neighbor)
1047 {
1048 return ISIS_OK; /* Silently discard */
1049 }
1050 else
1051 {
1052 if (((level == 1) &&
1053 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1054 ((level == 2) &&
1055 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1056 return ISIS_WARNING; /* Silently discard */
1057 }
jardineb5d44e2003-12-23 08:09:43 +00001058 }
hassof390d2c2004-09-10 20:48:21 +00001059dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001060 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1061
1062 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1063
hassof390d2c2004-09-10 20:48:21 +00001064 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001065
hassof390d2c2004-09-10 20:48:21 +00001066 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1067 if (hdr->rem_lifetime == 0)
1068 {
1069 if (!lsp)
1070 {
1071 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1072 /* only needed on explicit update, eg - p2p */
1073 if (circuit->circ_type == CIRCUIT_T_P2P)
1074 ack_lsp (hdr, circuit, level);
1075 return retval; /* FIXME: do we need a purge? */
1076 }
1077 else
1078 {
1079 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1080 {
1081 /* LSP by some other system -> do 7.3.16.4 b) */
1082 /* 7.3.16.4 b) 1) */
1083 if (comp == LSP_NEWER)
1084 {
1085 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1086 /* ii */
1087 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1088 /* iii */
1089 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1090 /* v */
1091 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1092 /* iv */
1093 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1094 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001095
hassof390d2c2004-09-10 20:48:21 +00001096 } /* 7.3.16.4 b) 2) */
1097 else if (comp == LSP_EQUAL)
1098 {
1099 /* i */
1100 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1101 /* ii */
1102 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1103 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1104 } /* 7.3.16.4 b) 3) */
1105 else
1106 {
1107 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1108 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1109 }
1110 }
1111 else
1112 {
1113 /* our own LSP -> 7.3.16.4 c) */
1114 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1115 circuit->circuit_id
1116 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1117 circuit->circuit_id
1118 && circuit->u.bc.is_dr[level - 1] == 1))
1119 {
1120 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
hasso529d65b2004-12-24 00:14:50 +00001121 zlog_debug ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len));
hassof390d2c2004-09-10 20:48:21 +00001122 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1123 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1124 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hasso529d65b2004-12-24 00:14:50 +00001125 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001126 ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1127 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1128 ntohl (lsp->lsp_header->seq_num));
1129 lsp->lsp_header->rem_lifetime =
1130 htons (isis_jitter
1131 (circuit->area->max_lsp_lifetime[level - 1],
1132 MAX_AGE_JITTER));
1133 }
1134 else
1135 {
1136 /* Got purge for own pseudo-lsp, and we are not DR */
1137 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1138 }
1139 }
1140 }
1141 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001142 }
jardineb5d44e2003-12-23 08:09:43 +00001143 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1144 * purge */
hassof390d2c2004-09-10 20:48:21 +00001145 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1146 {
1147 if (!lsp)
1148 {
1149 /* 7.3.16.4: initiate a purge */
1150 lsp_purge_non_exist (hdr, circuit->area);
1151 return ISIS_OK;
1152 }
1153 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1154
1155 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1156 * has information that the current sequence number for source S is
1157 * "greater" than that held by S, ... */
1158
1159 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1160 {
1161 /* 7.3.16.1 */
1162 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1163
1164 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1165 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1166
1167 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hasso529d65b2004-12-24 00:14:50 +00001168 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001169 ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1170 circuit->area->area_tag, rawlspid_print (hdr->lsp_id),
1171 ntohl (lsp->lsp_header->seq_num));
1172 lsp->lsp_header->rem_lifetime =
1173 htons (isis_jitter
1174 (circuit->area->max_lsp_lifetime[level - 1],
1175 MAX_AGE_JITTER));
1176 }
jardineb5d44e2003-12-23 08:09:43 +00001177 }
hassof390d2c2004-09-10 20:48:21 +00001178 else
1179 {
1180 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001181
hassof390d2c2004-09-10 20:48:21 +00001182 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1183 if ((!lsp || comp == LSP_NEWER))
1184 {
1185 /* i */
1186 if (lsp)
1187 {
jardineb5d44e2003-12-23 08:09:43 +00001188#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001189 zlog_debug ("level %d number is - %ld", level,
1190 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001191#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001192 lsp_search_and_destroy (hdr->lsp_id,
1193 circuit->area->lspdb[level - 1]);
1194 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001195#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001196 zlog_debug ("level %d number is - %ld", level,
1197 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001198#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001199 }
1200 /*
1201 * If this lsp is a frag, need to see if we have zero lsp present
1202 */
1203 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1204 {
1205 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1206 LSP_FRAGMENT (lspid) = 0;
1207 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1208 if (!lsp0)
1209 {
hasso529d65b2004-12-24 00:14:50 +00001210 zlog_debug ("Got lsp frag, while zero lsp not database");
hassof390d2c2004-09-10 20:48:21 +00001211 return ISIS_OK;
1212 }
1213 }
1214 lsp =
1215 lsp_new_from_stream_ptr (circuit->rcv_stream,
1216 ntohs (hdr->pdu_len), lsp0,
1217 circuit->area);
1218 lsp->level = level;
1219 lsp->adj = adj;
1220 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1221 /* ii */
1222 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1223 /* iii */
1224 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001225
hassof390d2c2004-09-10 20:48:21 +00001226 /* iv */
1227 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1228 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1229 /* FIXME: v) */
1230 }
1231 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1232 else if (comp == LSP_EQUAL)
1233 {
1234 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1235 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area);
1236 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1237 {
1238 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1239 }
1240 }
1241 /* 7.3.15.1 e) 3) LSP older than the one in db */
1242 else
1243 {
1244 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1245 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1246 }
jardineb5d44e2003-12-23 08:09:43 +00001247 }
jardineb5d44e2003-12-23 08:09:43 +00001248 if (lsp)
1249 lsp->adj = adj;
1250 return retval;
1251}
1252
1253/*
1254 * Process Sequence Numbers
1255 * ISO - 10589
1256 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1257 */
1258
hasso92365882005-01-18 13:53:33 +00001259static int
hassof390d2c2004-09-10 20:48:21 +00001260process_snp (int snp_type, int level, struct isis_circuit *circuit,
1261 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001262{
1263 int retval = ISIS_OK;
1264 int cmp, own_lsp;
1265 char typechar = ' ';
1266 int len;
1267 struct isis_adjacency *adj;
1268 struct isis_complete_seqnum_hdr *chdr = NULL;
1269 struct isis_partial_seqnum_hdr *phdr = NULL;
1270 uint32_t found = 0, expected = 0;
1271 struct isis_lsp *lsp;
1272 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001273 struct listnode *node, *nnode;
1274 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001275 struct tlvs tlvs;
1276 struct list *lsp_list = NULL;
1277 struct isis_passwd *passwd;
1278
hassof390d2c2004-09-10 20:48:21 +00001279 if (snp_type == ISIS_SNP_CSNP_FLAG)
1280 {
1281 /* getting the header info */
1282 typechar = 'C';
1283 chdr =
1284 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1285 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1286 len = ntohs (chdr->pdu_len);
1287 if (len < ISIS_CSNP_HDRLEN)
1288 {
1289 zlog_warn ("Received a CSNP with bogus length!");
1290 return ISIS_OK;
1291 }
jardineb5d44e2003-12-23 08:09:43 +00001292 }
hassof390d2c2004-09-10 20:48:21 +00001293 else
1294 {
1295 typechar = 'P';
1296 phdr =
1297 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1298 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1299 len = ntohs (phdr->pdu_len);
1300 if (len < ISIS_PSNP_HDRLEN)
1301 {
1302 zlog_warn ("Received a CSNP with bogus length!");
1303 return ISIS_OK;
1304 }
jardineb5d44e2003-12-23 08:09:43 +00001305 }
jardineb5d44e2003-12-23 08:09:43 +00001306
1307 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001308 if (circuit->ext_domain)
1309 {
jardineb5d44e2003-12-23 08:09:43 +00001310
hasso529d65b2004-12-24 00:14:50 +00001311 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1312 "skipping: circuit externalDomain = true",
1313 circuit->area->area_tag,
1314 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001315
1316 return ISIS_OK;
1317 }
hassof390d2c2004-09-10 20:48:21 +00001318
1319 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1320 if (!accept_level (level, circuit->circuit_is_type))
1321 {
1322
hasso529d65b2004-12-24 00:14:50 +00001323 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1324 "skipping: circuit type %s does not match level %d",
1325 circuit->area->area_tag,
1326 level,
1327 typechar,
1328 circuit->interface->name,
1329 circuit_t2string (circuit->circuit_is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001330
1331 return ISIS_OK;
1332 }
1333
1334 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1335 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1336 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1337 {
1338 if (!circuit->u.bc.is_dr[level - 1])
1339 {
1340
hasso529d65b2004-12-24 00:14:50 +00001341 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1342 "skipping: we are not the DIS",
1343 circuit->area->area_tag,
1344 level,
1345 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001346
1347 return ISIS_OK;
1348 }
1349 }
jardineb5d44e2003-12-23 08:09:43 +00001350
1351 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1352
1353 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1354 * - already checked */
1355
1356 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1357 /* for broadcast circuits, snpa should be compared */
1358 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001359 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1360 {
1361 if (snp_type == ISIS_SNP_CSNP_FLAG)
1362 {
1363 adj =
1364 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1365 }
1366 else
1367 {
1368 /* a psnp on a broadcast, how lovely of Juniper :) */
1369 adj =
1370 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1371 }
1372 if (!adj)
1373 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001374 }
hassof390d2c2004-09-10 20:48:21 +00001375 else
1376 {
1377 if (!circuit->u.p2p.neighbor)
1378 return ISIS_OK; /* Silently discard */
1379 }
jardineb5d44e2003-12-23 08:09:43 +00001380
1381 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1382
1383 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1384
1385 memset (&tlvs, 0, sizeof (struct tlvs));
1386
1387 /* parse the SNP */
1388 expected |= TLVFLAG_LSP_ENTRIES;
1389 expected |= TLVFLAG_AUTH_INFO;
1390 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001391 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001392 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001393 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001394
hassof390d2c2004-09-10 20:48:21 +00001395 if (retval > ISIS_WARNING)
1396 {
1397 zlog_warn ("something went very wrong processing SNP");
1398 free_tlvs (&tlvs);
1399 return retval;
1400 }
jardineb5d44e2003-12-23 08:09:43 +00001401
hasso1cbc5622005-01-01 10:29:51 +00001402 if (level == 1)
1403 passwd = &circuit->area->area_passwd;
1404 else
1405 passwd = &circuit->area->domain_passwd;
1406
1407 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001408 {
hasso1cbc5622005-01-01 10:29:51 +00001409 if (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00001410 {
hasso1cbc5622005-01-01 10:29:51 +00001411 if (!(found & TLVFLAG_AUTH_INFO) ||
1412 authentication_check (passwd, &tlvs.auth_info))
1413 {
1414 isis_event_auth_failure (circuit->area->area_tag,
1415 "SNP authentication" " failure",
1416 phdr ? phdr->source_id : chdr->source_id);
1417 return ISIS_OK;
1418 }
hassof390d2c2004-09-10 20:48:21 +00001419 }
1420 }
jardineb5d44e2003-12-23 08:09:43 +00001421
1422 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001423 if (isis->debugs & DEBUG_SNP_PACKETS)
1424 {
hasso529d65b2004-12-24 00:14:50 +00001425 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1426 circuit->area->area_tag,
1427 level,
1428 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001429 if (tlvs.lsp_entries)
1430 {
paul1eb8ef22005-04-07 07:30:20 +00001431 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001432 {
hasso529d65b2004-12-24 00:14:50 +00001433 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1434 " cksum 0x%04x, lifetime %us",
1435 circuit->area->area_tag,
1436 typechar,
1437 rawlspid_print (entry->lsp_id),
1438 ntohl (entry->seq_num),
1439 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001440 }
1441 }
jardineb5d44e2003-12-23 08:09:43 +00001442 }
jardineb5d44e2003-12-23 08:09:43 +00001443
1444 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001445 if (tlvs.lsp_entries)
1446 {
paul1eb8ef22005-04-07 07:30:20 +00001447 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001448 {
1449 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1450 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1451 if (lsp)
1452 {
1453 /* 7.3.15.2 b) 1) is this LSP newer */
1454 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1455 entry->checksum, entry->rem_lifetime);
1456 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1457 if (cmp == LSP_EQUAL)
1458 {
1459 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1460 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1461 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1462 }
1463 else if (cmp == LSP_OLDER)
1464 {
1465 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1466 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1467 }
1468 else
1469 {
1470 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1471 * on p2p */
1472 if (own_lsp)
1473 {
1474 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1475 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1476 }
1477 else
1478 {
1479 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1480 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1481 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1482 }
1483 }
1484 }
1485 else
1486 {
1487 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1488 * insert it and set SSN on it */
1489 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1490 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1491 {
1492 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1493 0, 0, entry->checksum, level);
1494 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1495 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1496 }
1497 }
jardineb5d44e2003-12-23 08:09:43 +00001498 }
1499 }
jardineb5d44e2003-12-23 08:09:43 +00001500
1501 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001502 if (snp_type == ISIS_SNP_CSNP_FLAG)
1503 {
1504 /*
1505 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1506 */
1507 lsp_list = list_new ();
1508 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1509 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001510
hassof390d2c2004-09-10 20:48:21 +00001511 /* Fixme: Find a better solution */
1512 if (tlvs.lsp_entries)
1513 {
paul1eb8ef22005-04-07 07:30:20 +00001514 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001515 {
paul1eb8ef22005-04-07 07:30:20 +00001516 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001517 {
1518 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1519 {
1520 list_delete_node (lsp_list, node2);
1521 break;
1522 }
1523 }
1524 }
1525 }
1526 /* on remaining LSPs we set SRM (neighbor knew not of) */
paul1eb8ef22005-04-07 07:30:20 +00001527 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001528 {
1529 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001530 }
hassof390d2c2004-09-10 20:48:21 +00001531 /* lets free it */
1532 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001533 }
jardineb5d44e2003-12-23 08:09:43 +00001534
1535 free_tlvs (&tlvs);
1536 return retval;
1537}
1538
hasso92365882005-01-18 13:53:33 +00001539static int
hassof390d2c2004-09-10 20:48:21 +00001540process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001541{
jardineb5d44e2003-12-23 08:09:43 +00001542 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001543 if ((stream_get_endp (circuit->rcv_stream) -
1544 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1545 {
1546 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1547 return ISIS_WARNING;
1548 }
jardineb5d44e2003-12-23 08:09:43 +00001549
1550 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1551}
1552
hasso92365882005-01-18 13:53:33 +00001553static int
hassof390d2c2004-09-10 20:48:21 +00001554process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001555{
hassof390d2c2004-09-10 20:48:21 +00001556 if ((stream_get_endp (circuit->rcv_stream) -
1557 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1558 {
1559 zlog_warn ("Packet too short");
1560 return ISIS_WARNING;
1561 }
jardineb5d44e2003-12-23 08:09:43 +00001562
1563 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1564}
1565
jardineb5d44e2003-12-23 08:09:43 +00001566/*
1567 * Process ISH
1568 * ISO - 10589
1569 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1570 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001571 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1572 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1573 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001574 */
hasso92365882005-01-18 13:53:33 +00001575static int
jardineb5d44e2003-12-23 08:09:43 +00001576process_is_hello (struct isis_circuit *circuit)
1577{
1578 struct isis_adjacency *adj;
1579 int retval = ISIS_OK;
1580 u_char neigh_len;
1581 u_char *sysid;
1582
1583 /* In this point in time we are not yet able to handle is_hellos
1584 * on lan - Sorry juniper...
1585 */
1586 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1587 return retval;
1588
1589 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001590 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001591 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001592 if (!adj)
1593 {
1594 /* 8.2.2 */
hassof7c43dc2004-09-26 16:24:14 +00001595 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001596 if (adj == NULL)
1597 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001598
hassof390d2c2004-09-10 20:48:21 +00001599 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1600 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1601 circuit->u.p2p.neighbor = adj;
1602 }
1603 /* 8.2.2 a) */
1604 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1605 ISIS_SYS_ID_LEN))
1606 {
1607 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1608 /* 8.2.2 a) 2) delete the adj */
1609 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1610 /* 8.2.2 a) 3) create a new adj */
hassof7c43dc2004-09-26 16:24:14 +00001611 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001612 if (adj == NULL)
1613 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001614
hassof390d2c2004-09-10 20:48:21 +00001615 /* 8.2.2 a) 3) i */
1616 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1617 /* 8.2.2 a) 3) ii */
1618 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1619 /* 8.2.2 a) 4) quite meaningless */
1620 }
jardineb5d44e2003-12-23 08:09:43 +00001621 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001622 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1623 (adj->sys_type == ISIS_SYSTYPE_IS))
1624 {
1625 /* do nothing */
1626 }
1627 else
1628 {
1629 /* 8.2.2 c) respond with a p2p IIH */
1630 send_hello (circuit, 1);
1631 }
jardineb5d44e2003-12-23 08:09:43 +00001632 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001633 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001634 /* 8.2.2 e) FIXME: Circuit type of? */
1635
jardineb5d44e2003-12-23 08:09:43 +00001636 return retval;
1637}
1638
jardineb5d44e2003-12-23 08:09:43 +00001639/*
1640 * PDU Dispatcher
1641 */
1642
hasso92365882005-01-18 13:53:33 +00001643static int
hassof390d2c2004-09-10 20:48:21 +00001644isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001645{
jardineb5d44e2003-12-23 08:09:43 +00001646 struct isis_fixed_hdr *hdr;
1647 struct esis_fixed_hdr *esis_hdr;
1648
hassof390d2c2004-09-10 20:48:21 +00001649 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001650
1651 /*
1652 * Let's first read data from stream to the header
1653 */
hassof390d2c2004-09-10 20:48:21 +00001654 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001655
hassof390d2c2004-09-10 20:48:21 +00001656 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1657 {
1658 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1659 return ISIS_ERROR;
1660 }
jardineb5d44e2003-12-23 08:09:43 +00001661
1662 /* now we need to know if this is an ISO 9542 packet and
1663 * take real good care of it, waaa!
1664 */
hassof390d2c2004-09-10 20:48:21 +00001665 if (hdr->idrp == ISO9542_ESIS)
1666 {
1667 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1668 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1669 /* FIXME: Need to do some acceptence tests */
1670 /* example length... */
1671 switch (esis_hdr->pdu_type)
1672 {
1673 case ESH_PDU:
1674 /* FIXME */
1675 break;
1676 case ISH_PDU:
hasso529d65b2004-12-24 00:14:50 +00001677 zlog_debug ("AN ISH PDU!!");
hassof390d2c2004-09-10 20:48:21 +00001678 retval = process_is_hello (circuit);
1679 break;
1680 default:
1681 return ISIS_ERROR;
1682 }
1683 return retval;
1684 }
1685 else
1686 {
1687 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1688 }
jardineb5d44e2003-12-23 08:09:43 +00001689 /*
1690 * and then process it
1691 */
1692
hassof390d2c2004-09-10 20:48:21 +00001693 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1694 {
1695 zlog_err ("Fixed header length = %d", hdr->length);
1696 return ISIS_ERROR;
1697 }
jardineb5d44e2003-12-23 08:09:43 +00001698
hassof390d2c2004-09-10 20:48:21 +00001699 if (hdr->version1 != 1)
1700 {
1701 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1702 return ISIS_WARNING;
1703 }
jardineb5d44e2003-12-23 08:09:43 +00001704 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001705 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1706 {
1707 zlog_err
1708 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1709 "while the parameter for this IS is %u", hdr->id_len,
1710 ISIS_SYS_ID_LEN);
1711 return ISIS_ERROR;
1712 }
jardineb5d44e2003-12-23 08:09:43 +00001713
hassof390d2c2004-09-10 20:48:21 +00001714 if (hdr->version2 != 1)
1715 {
1716 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1717 return ISIS_WARNING;
1718 }
jardineb5d44e2003-12-23 08:09:43 +00001719 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001720 if ((hdr->max_area_addrs != 0)
1721 && (hdr->max_area_addrs != isis->max_area_addrs))
1722 {
1723 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1724 "received PDU %u while the parameter for this IS is %u",
1725 hdr->max_area_addrs, isis->max_area_addrs);
1726 return ISIS_ERROR;
1727 }
jardineb5d44e2003-12-23 08:09:43 +00001728
hassof390d2c2004-09-10 20:48:21 +00001729 switch (hdr->pdu_type)
1730 {
1731 case L1_LAN_HELLO:
1732 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1733 break;
1734 case L2_LAN_HELLO:
1735 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1736 break;
1737 case P2P_HELLO:
1738 retval = process_p2p_hello (circuit);
1739 break;
1740 case L1_LINK_STATE:
1741 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1742 break;
1743 case L2_LINK_STATE:
1744 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1745 break;
1746 case L1_COMPLETE_SEQ_NUM:
1747 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1748 break;
1749 case L2_COMPLETE_SEQ_NUM:
1750 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1751 break;
1752 case L1_PARTIAL_SEQ_NUM:
1753 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1754 break;
1755 case L2_PARTIAL_SEQ_NUM:
1756 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1757 break;
1758 default:
1759 return ISIS_ERROR;
1760 }
jardineb5d44e2003-12-23 08:09:43 +00001761
1762 return retval;
1763}
1764
jardineb5d44e2003-12-23 08:09:43 +00001765#ifdef GNU_LINUX
1766int
1767isis_receive (struct thread *thread)
1768{
jardineb5d44e2003-12-23 08:09:43 +00001769 struct isis_circuit *circuit;
1770 u_char ssnpa[ETH_ALEN];
1771 int retval;
1772
1773 /*
1774 * Get the circuit
1775 */
1776 circuit = THREAD_ARG (thread);
1777 assert (circuit);
1778
1779 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001780 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001781 else
1782 stream_reset (circuit->rcv_stream);
1783
1784 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001785 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001786
1787 if (retval == ISIS_OK)
1788 retval = isis_handle_pdu (circuit, ssnpa);
1789
1790 /*
1791 * prepare for next packet.
1792 */
hassof390d2c2004-09-10 20:48:21 +00001793 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1794 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001795
1796 return retval;
1797}
1798
1799#else
1800int
1801isis_receive (struct thread *thread)
1802{
jardineb5d44e2003-12-23 08:09:43 +00001803 struct isis_circuit *circuit;
1804 u_char ssnpa[ETH_ALEN];
1805 int retval;
1806
1807 /*
1808 * Get the circuit
1809 */
1810 circuit = THREAD_ARG (thread);
1811 assert (circuit);
1812
hassof390d2c2004-09-10 20:48:21 +00001813 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001814
1815 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001816 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001817 else
1818 stream_reset (circuit->rcv_stream);
1819
1820 retval = circuit->rx (circuit, ssnpa);
1821
1822 if (retval == ISIS_OK)
1823 retval = isis_handle_pdu (circuit, ssnpa);
1824
1825 /*
1826 * prepare for next packet.
1827 */
hassof390d2c2004-09-10 20:48:21 +00001828 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1829 listcount
1830 (circuit->area->circuit_list) *
1831 100);
jardineb5d44e2003-12-23 08:09:43 +00001832
1833 return retval;
1834}
1835
1836#endif
1837
1838 /* filling of the fixed isis header */
1839void
1840fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1841{
1842 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1843
1844 hdr->idrp = ISO10589_ISIS;
1845
hassof390d2c2004-09-10 20:48:21 +00001846 switch (pdu_type)
1847 {
1848 case L1_LAN_HELLO:
1849 case L2_LAN_HELLO:
1850 hdr->length = ISIS_LANHELLO_HDRLEN;
1851 break;
1852 case P2P_HELLO:
1853 hdr->length = ISIS_P2PHELLO_HDRLEN;
1854 break;
1855 case L1_LINK_STATE:
1856 case L2_LINK_STATE:
1857 hdr->length = ISIS_LSP_HDR_LEN;
1858 break;
1859 case L1_COMPLETE_SEQ_NUM:
1860 case L2_COMPLETE_SEQ_NUM:
1861 hdr->length = ISIS_CSNP_HDRLEN;
1862 break;
1863 case L1_PARTIAL_SEQ_NUM:
1864 case L2_PARTIAL_SEQ_NUM:
1865 hdr->length = ISIS_PSNP_HDRLEN;
1866 break;
1867 default:
1868 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1869 return;
1870 }
jardineb5d44e2003-12-23 08:09:43 +00001871 hdr->length += ISIS_FIXED_HDR_LEN;
1872 hdr->pdu_type = pdu_type;
1873 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001874 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001875 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001876 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001877}
1878
jardineb5d44e2003-12-23 08:09:43 +00001879/*
1880 * SEND SIDE
1881 */
hasso92365882005-01-18 13:53:33 +00001882static void
jardineb5d44e2003-12-23 08:09:43 +00001883fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001884 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001885{
hassof390d2c2004-09-10 20:48:21 +00001886 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001887
1888 stream_putc (stream, hdr->idrp);
1889 stream_putc (stream, hdr->length);
1890 stream_putc (stream, hdr->version1);
1891 stream_putc (stream, hdr->id_len);
1892 stream_putc (stream, hdr->pdu_type);
1893 stream_putc (stream, hdr->version2);
1894 stream_putc (stream, hdr->reserved);
1895 stream_putc (stream, hdr->max_area_addrs);
1896
1897 return;
1898}
1899
jardineb5d44e2003-12-23 08:09:43 +00001900int
1901send_hello (struct isis_circuit *circuit, int level)
1902{
1903 struct isis_fixed_hdr fixed_hdr;
1904 struct isis_lan_hello_hdr hello_hdr;
1905 struct isis_p2p_hello_hdr p2p_hello_hdr;
1906
1907 u_int32_t interval;
1908 unsigned long len_pointer, length;
1909 int retval;
1910
hassof390d2c2004-09-10 20:48:21 +00001911 if (circuit->interface->mtu == 0)
1912 {
1913 zlog_warn ("circuit has zero MTU");
1914 return ISIS_WARNING;
1915 }
jardineb5d44e2003-12-23 08:09:43 +00001916
1917 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001918 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001919 else
1920 stream_reset (circuit->snd_stream);
1921
1922 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1923 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001924 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1925 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001926 else
hassof390d2c2004-09-10 20:48:21 +00001927 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1928 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001929 else
hassof390d2c2004-09-10 20:48:21 +00001930 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001931
1932 /*
1933 * Fill LAN Level 1 or 2 Hello PDU header
1934 */
1935 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001936 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001937 circuit->hello_interval[level - 1];
1938 if (interval > USHRT_MAX)
1939 interval = USHRT_MAX;
1940 hello_hdr.circuit_t = circuit->circuit_is_type;
1941 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001942 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001943
hassof390d2c2004-09-10 20:48:21 +00001944 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00001945 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001946
1947 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001948 if (circuit->circ_type == CIRCUIT_T_P2P)
1949 {
1950 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1951 p2p_hello_hdr.local_id = circuit->circuit_id;
1952 /* FIXME: need better understanding */
1953 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001954 }
hassof390d2c2004-09-10 20:48:21 +00001955 else
1956 {
1957 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1958 if (level == 1 && circuit->u.bc.l1_desig_is)
1959 {
1960 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1961 ISIS_SYS_ID_LEN + 1);
1962 }
1963 else if (level == 2 && circuit->u.bc.l2_desig_is)
1964 {
1965 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1966 ISIS_SYS_ID_LEN + 1);
1967 }
1968 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1969 }
jardineb5d44e2003-12-23 08:09:43 +00001970
1971 /*
1972 * Then the variable length part
1973 */
1974 /* add circuit password */
1975 if (circuit->passwd.type)
1976 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1977 circuit->passwd.passwd, circuit->snd_stream))
1978 return ISIS_WARNING;
1979 /* Area Addresses TLV */
1980 assert (circuit->area);
1981 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1982 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1983 return ISIS_WARNING;
1984
1985 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00001986 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1987 {
1988 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1989 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1990 circuit->snd_stream))
1991 return ISIS_WARNING;
1992 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
1993 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
1994 circuit->snd_stream))
1995 return ISIS_WARNING;
1996 }
jardineb5d44e2003-12-23 08:09:43 +00001997
1998 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00001999 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002000 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2001 return ISIS_WARNING;
2002 /* IP interface Address TLV */
2003 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2004 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2005 return ISIS_WARNING;
2006
hassof390d2c2004-09-10 20:48:21 +00002007#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002008 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002009 if (circuit->ipv6_router && circuit->ipv6_link &&
jardineb5d44e2003-12-23 08:09:43 +00002010 circuit->ipv6_link->count > 0)
2011 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2012 return ISIS_WARNING;
2013#endif /* HAVE_IPV6 */
2014
2015 if (circuit->u.bc.pad_hellos)
2016 if (tlv_add_padding (circuit->snd_stream))
2017 return ISIS_WARNING;
2018
paul9985f832005-02-09 15:51:56 +00002019 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002020 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002021 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002022
2023 retval = circuit->tx (circuit, level);
2024 if (retval)
2025 zlog_warn ("sending of LAN Level %d Hello failed", level);
2026
2027 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002028 if (isis->debugs & DEBUG_ADJ_PACKETS)
2029 {
2030 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2031 {
hasso529d65b2004-12-24 00:14:50 +00002032 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2033 circuit->area->area_tag, level, circuit->interface->name,
2034 STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002035 }
2036 else
2037 {
hasso529d65b2004-12-24 00:14:50 +00002038 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2039 circuit->area->area_tag, circuit->interface->name,
2040 STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002041 }
jardineb5d44e2003-12-23 08:09:43 +00002042 }
jardineb5d44e2003-12-23 08:09:43 +00002043
2044 return retval;
2045}
2046
hasso92365882005-01-18 13:53:33 +00002047static int
jardineb5d44e2003-12-23 08:09:43 +00002048send_lan_hello (struct isis_circuit *circuit, int level)
2049{
hassof390d2c2004-09-10 20:48:21 +00002050 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002051}
2052
2053int
2054send_lan_l1_hello (struct thread *thread)
2055{
jardineb5d44e2003-12-23 08:09:43 +00002056 struct isis_circuit *circuit;
2057 int retval;
2058
2059 circuit = THREAD_ARG (thread);
2060 assert (circuit);
2061 circuit->u.bc.t_send_lan_hello[0] = NULL;
2062
2063 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002064 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002065
2066 retval = send_lan_hello (circuit, 1);
2067
2068 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002069 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2070 send_lan_l1_hello, circuit,
2071 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002072
2073 return retval;
2074}
2075
2076int
2077send_lan_l2_hello (struct thread *thread)
2078{
2079 struct isis_circuit *circuit;
2080 int retval;
2081
2082 circuit = THREAD_ARG (thread);
2083 assert (circuit);
2084 circuit->u.bc.t_send_lan_hello[1] = NULL;
2085
2086 if (circuit->u.bc.run_dr_elect[1])
2087 retval = isis_dr_elect (circuit, 2);
2088
2089 retval = send_lan_hello (circuit, 2);
2090
hassof390d2c2004-09-10 20:48:21 +00002091 /* set next timer thread */
2092 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2093 send_lan_l2_hello, circuit,
2094 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002095
2096 return retval;
2097}
2098
2099int
2100send_p2p_hello (struct thread *thread)
2101{
2102 struct isis_circuit *circuit;
2103
2104 circuit = THREAD_ARG (thread);
2105 assert (circuit);
2106 circuit->u.p2p.t_send_p2p_hello = NULL;
2107
hassof390d2c2004-09-10 20:48:21 +00002108 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002109
hassof390d2c2004-09-10 20:48:21 +00002110 /* set next timer thread */
2111 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2112 circuit, isis_jitter (circuit->hello_interval[1],
2113 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002114
2115 return ISIS_OK;
2116}
2117
hasso92365882005-01-18 13:53:33 +00002118static int
hassof390d2c2004-09-10 20:48:21 +00002119build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2120 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002121{
2122 struct isis_fixed_hdr fixed_hdr;
2123 struct isis_passwd *passwd;
2124 int retval = ISIS_OK;
2125 unsigned long lenp;
2126 u_int16_t length;
2127
hassof390d2c2004-09-10 20:48:21 +00002128 if (level == 1)
2129 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2130 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002131 else
hassof390d2c2004-09-10 20:48:21 +00002132 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2133 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002134
2135 /*
2136 * Fill Level 1 or 2 Complete Sequence Numbers header
2137 */
2138
paul9985f832005-02-09 15:51:56 +00002139 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002140 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002141 /* no need to send the source here, it is always us if we csnp */
2142 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2143 /* with zero circuit id - ref 9.10, 9.11 */
2144 stream_putc (circuit->snd_stream, 0x00);
2145
2146 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2147 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2148
2149 /*
2150 * And TLVs
2151 */
2152 if (level == 1)
2153 passwd = &circuit->area->area_passwd;
2154 else
2155 passwd = &circuit->area->domain_passwd;
2156
hasso1cbc5622005-01-01 10:29:51 +00002157 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2158 if (passwd->type)
2159 retval = tlv_add_authinfo (passwd->type, passwd->len,
2160 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002161
hassof390d2c2004-09-10 20:48:21 +00002162 if (!retval && lsps)
2163 {
2164 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2165 }
paul9985f832005-02-09 15:51:56 +00002166 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002167 assert (length >= ISIS_CSNP_HDRLEN);
2168 /* Update PU length */
2169 stream_putw_at (circuit->snd_stream, lenp, length);
2170
2171 return retval;
2172}
2173
2174/*
2175 * FIXME: support multiple CSNPs
2176 */
2177
2178int
2179send_csnp (struct isis_circuit *circuit, int level)
2180{
2181 int retval = ISIS_OK;
2182 u_char start[ISIS_SYS_ID_LEN + 2];
2183 u_char stop[ISIS_SYS_ID_LEN + 2];
2184 struct list *list = NULL;
paul1eb8ef22005-04-07 07:30:20 +00002185 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00002186 struct isis_lsp *lsp;
2187
hassof390d2c2004-09-10 20:48:21 +00002188 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002189 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2190
hassof390d2c2004-09-10 20:48:21 +00002191 if (circuit->area->lspdb[level - 1] &&
2192 dict_count (circuit->area->lspdb[level - 1]) > 0)
2193 {
2194 list = list_new ();
2195 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002196
hassof390d2c2004-09-10 20:48:21 +00002197 if (circuit->snd_stream == NULL)
2198 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2199 else
2200 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002201
hassof390d2c2004-09-10 20:48:21 +00002202 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002203
hassof390d2c2004-09-10 20:48:21 +00002204 if (isis->debugs & DEBUG_SNP_PACKETS)
2205 {
hasso529d65b2004-12-24 00:14:50 +00002206 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
paul1eb8ef22005-04-07 07:30:20 +00002207 circuit->area->area_tag, level, circuit->interface->name,
2208 STREAM_SIZE (circuit->snd_stream));
2209 for (ALL_LIST_ELEMENTS (list, node, nnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002210 {
hasso529d65b2004-12-24 00:14:50 +00002211 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2212 " cksum 0x%04x, lifetime %us",
2213 circuit->area->area_tag,
2214 rawlspid_print (lsp->lsp_header->lsp_id),
2215 ntohl (lsp->lsp_header->seq_num),
2216 ntohs (lsp->lsp_header->checksum),
2217 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002218 }
2219 }
2220
2221 list_delete (list);
2222
2223 if (retval == ISIS_OK)
2224 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002225 }
jardineb5d44e2003-12-23 08:09:43 +00002226 return retval;
2227}
2228
2229int
2230send_l1_csnp (struct thread *thread)
2231{
2232 struct isis_circuit *circuit;
2233 int retval = ISIS_OK;
2234
2235 circuit = THREAD_ARG (thread);
2236 assert (circuit);
2237
2238 circuit->t_send_csnp[0] = NULL;
2239
hassof390d2c2004-09-10 20:48:21 +00002240 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2241 {
2242 send_csnp (circuit, 1);
2243 }
jardineb5d44e2003-12-23 08:09:43 +00002244 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002245 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2246 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002247
2248 return retval;
2249}
2250
2251int
2252send_l2_csnp (struct thread *thread)
2253{
2254 struct isis_circuit *circuit;
2255 int retval = ISIS_OK;
2256
2257 circuit = THREAD_ARG (thread);
2258 assert (circuit);
2259
2260 circuit->t_send_csnp[1] = NULL;
2261
hassof390d2c2004-09-10 20:48:21 +00002262 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2263 {
2264 send_csnp (circuit, 2);
2265 }
jardineb5d44e2003-12-23 08:09:43 +00002266 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002267 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2268 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002269
jardineb5d44e2003-12-23 08:09:43 +00002270 return retval;
2271}
2272
hasso92365882005-01-18 13:53:33 +00002273static int
jardineb5d44e2003-12-23 08:09:43 +00002274build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2275{
2276 struct isis_fixed_hdr fixed_hdr;
2277 unsigned long lenp;
2278 u_int16_t length;
2279 int retval = 0;
2280 struct isis_lsp *lsp;
2281 struct isis_passwd *passwd;
paul1eb8ef22005-04-07 07:30:20 +00002282 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00002283
2284 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002285 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2286 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002287 else
2288 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002289 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 /*
2292 * Fill Level 1 or 2 Partial Sequence Numbers header
2293 */
paul9985f832005-02-09 15:51:56 +00002294 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002295 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002296 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2297 stream_putc (circuit->snd_stream, circuit->idx);
2298
2299 /*
2300 * And TLVs
2301 */
2302
2303 if (level == 1)
2304 passwd = &circuit->area->area_passwd;
2305 else
2306 passwd = &circuit->area->domain_passwd;
2307
hasso1cbc5622005-01-01 10:29:51 +00002308 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2309 if (passwd->type)
2310 retval = tlv_add_authinfo (passwd->type, passwd->len,
2311 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002312
hassof390d2c2004-09-10 20:48:21 +00002313 if (!retval && lsps)
2314 {
2315 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002316 }
jardineb5d44e2003-12-23 08:09:43 +00002317
hassof390d2c2004-09-10 20:48:21 +00002318 if (isis->debugs & DEBUG_SNP_PACKETS)
2319 {
paul1eb8ef22005-04-07 07:30:20 +00002320 for (ALL_LIST_ELEMENTS (lsps, node, nnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002321 {
hasso529d65b2004-12-24 00:14:50 +00002322 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2323 " cksum 0x%04x, lifetime %us",
2324 circuit->area->area_tag,
2325 rawlspid_print (lsp->lsp_header->lsp_id),
2326 ntohl (lsp->lsp_header->seq_num),
2327 ntohs (lsp->lsp_header->checksum),
2328 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002329 }
2330 }
2331
paul9985f832005-02-09 15:51:56 +00002332 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002333 assert (length >= ISIS_PSNP_HDRLEN);
2334 /* Update PDU length */
2335 stream_putw_at (circuit->snd_stream, lenp, length);
2336
2337 return ISIS_OK;
2338}
2339
2340/*
2341 * 7.3.15.4 action on expiration of partial SNP interval
2342 * level 1
2343 */
hasso92365882005-01-18 13:53:33 +00002344static int
jardineb5d44e2003-12-23 08:09:43 +00002345send_psnp (int level, struct isis_circuit *circuit)
2346{
2347 int retval = ISIS_OK;
2348 struct isis_lsp *lsp;
2349 struct list *list = NULL;
paul1eb8ef22005-04-07 07:30:20 +00002350 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00002351
hassof390d2c2004-09-10 20:48:21 +00002352 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002353 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002354 circuit->circ_type != CIRCUIT_T_BROADCAST)
2355 {
jardineb5d44e2003-12-23 08:09:43 +00002356
hassof390d2c2004-09-10 20:48:21 +00002357 if (circuit->area->lspdb[level - 1] &&
2358 dict_count (circuit->area->lspdb[level - 1]) > 0)
2359 {
2360 list = list_new ();
2361 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002362
hassof390d2c2004-09-10 20:48:21 +00002363 if (listcount (list) > 0)
2364 {
2365 if (circuit->snd_stream == NULL)
2366 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2367 else
2368 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002369
2370
hassof390d2c2004-09-10 20:48:21 +00002371 if (isis->debugs & DEBUG_SNP_PACKETS)
hasso529d65b2004-12-24 00:14:50 +00002372 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2373 circuit->area->area_tag, level,
2374 circuit->interface->name,
2375 STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002376
hassof390d2c2004-09-10 20:48:21 +00002377 retval = build_psnp (level, circuit, list);
2378 if (retval == ISIS_OK)
2379 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002380
hassof390d2c2004-09-10 20:48:21 +00002381 if (retval == ISIS_OK)
2382 {
2383 /*
2384 * sending succeeded, we can clear SSN flags of this circuit
2385 * for the LSPs in list
2386 */
paul1eb8ef22005-04-07 07:30:20 +00002387 for (ALL_LIST_ELEMENTS (list, node, nnode, lsp))
2388 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002389 }
2390 }
2391 list_delete (list);
2392 }
jardineb5d44e2003-12-23 08:09:43 +00002393 }
jardineb5d44e2003-12-23 08:09:43 +00002394
2395 return retval;
2396}
2397
2398int
2399send_l1_psnp (struct thread *thread)
2400{
2401
2402 struct isis_circuit *circuit;
2403 int retval = ISIS_OK;
2404
2405 circuit = THREAD_ARG (thread);
2406 assert (circuit);
2407
2408 circuit->t_send_psnp[0] = NULL;
2409
2410 send_psnp (1, circuit);
2411 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002412 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2413 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002414
2415 return retval;
2416}
2417
2418/*
2419 * 7.3.15.4 action on expiration of partial SNP interval
2420 * level 2
2421 */
2422int
2423send_l2_psnp (struct thread *thread)
2424{
jardineb5d44e2003-12-23 08:09:43 +00002425 struct isis_circuit *circuit;
2426 int retval = ISIS_OK;
2427
2428 circuit = THREAD_ARG (thread);
2429 assert (circuit);
2430
2431 circuit->t_send_psnp[1] = NULL;
2432
2433 send_psnp (2, circuit);
2434
2435 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002436 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2437 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002438
2439 return retval;
2440}
2441
hasso92365882005-01-18 13:53:33 +00002442/* FIXME: Not used any more? */
2443/* static void
jardineb5d44e2003-12-23 08:09:43 +00002444build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit,
hassof390d2c2004-09-10 20:48:21 +00002445 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002446{
2447 unsigned long length;
2448
hassof390d2c2004-09-10 20:48:21 +00002449 stream_put (stream, lsp->pdu, ntohs (lsp->lsp_header->pdu_len));
paul9985f832005-02-09 15:51:56 +00002450 length = stream_get_endp (stream);
jardineb5d44e2003-12-23 08:09:43 +00002451
2452 return;
hasso92365882005-01-18 13:53:33 +00002453} */
jardineb5d44e2003-12-23 08:09:43 +00002454
jardineb5d44e2003-12-23 08:09:43 +00002455/*
2456 * ISO 10589 - 7.3.14.3
2457 */
2458int
2459send_lsp (struct thread *thread)
2460{
2461 struct isis_circuit *circuit;
2462 struct isis_lsp *lsp;
2463 struct listnode *node;
2464 int retval = 0;
2465
2466 circuit = THREAD_ARG (thread);
2467 assert (circuit);
2468
hassof390d2c2004-09-10 20:48:21 +00002469 if (circuit->state == C_STATE_UP)
2470 {
paul1eb8ef22005-04-07 07:30:20 +00002471 lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
jardineb5d44e2003-12-23 08:09:43 +00002472
2473 /*
hassof390d2c2004-09-10 20:48:21 +00002474 * Do not send if levels do not match
jardineb5d44e2003-12-23 08:09:43 +00002475 */
hassof390d2c2004-09-10 20:48:21 +00002476 if (!(lsp->level & circuit->circuit_is_type))
2477 goto dontsend;
jardineb5d44e2003-12-23 08:09:43 +00002478
hassof390d2c2004-09-10 20:48:21 +00002479 /*
2480 * Do not send if we do not have adjacencies in state up on the circuit
2481 */
2482 if (circuit->upadjcount[lsp->level - 1] == 0)
2483 goto dontsend;
2484 /* only send if it needs sending */
2485 if ((time (NULL) - lsp->last_sent) >=
2486 circuit->area->lsp_gen_interval[lsp->level - 1])
2487 {
jardineb5d44e2003-12-23 08:09:43 +00002488
hassof390d2c2004-09-10 20:48:21 +00002489 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2490 {
hasso529d65b2004-12-24 00:14:50 +00002491 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00002492 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2493 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2494 rawlspid_print (lsp->lsp_header->lsp_id),
2495 ntohl (lsp->lsp_header->seq_num),
2496 ntohs (lsp->lsp_header->checksum),
2497 ntohs (lsp->lsp_header->rem_lifetime),
2498 circuit->interface->name);
2499 }
2500 /* copy our lsp to the send buffer */
paul15935e92005-05-03 09:27:23 +00002501 stream_copy (circuit->snd_stream, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00002502
2503 retval = circuit->tx (circuit, lsp->level);
2504
jardineb5d44e2003-12-23 08:09:43 +00002505 /*
hassof390d2c2004-09-10 20:48:21 +00002506 * If the sending succeeded, we can del the lsp from circuits
2507 * lsp_queue
jardineb5d44e2003-12-23 08:09:43 +00002508 */
hassof390d2c2004-09-10 20:48:21 +00002509 if (retval == ISIS_OK)
2510 {
2511 list_delete_node (circuit->lsp_queue, node);
2512
2513 /*
2514 * On broadcast circuits also the SRMflag can be cleared
2515 */
2516 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2517 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2518
2519 if (flags_any_set (lsp->SRMflags) == 0)
2520 {
2521 /*
2522 * need to remember when we were last sent
2523 */
2524 lsp->last_sent = time (NULL);
2525 }
2526 }
2527 else
2528 {
hasso529d65b2004-12-24 00:14:50 +00002529 zlog_debug ("sending of level %d link state failed", lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002530 }
jardineb5d44e2003-12-23 08:09:43 +00002531 }
hassof390d2c2004-09-10 20:48:21 +00002532 else
2533 {
2534 /* my belief is that if it wasn't his time, the lsp can be removed
2535 * from the queue
2536 */
2537 dontsend:
2538 list_delete_node (circuit->lsp_queue, node);
2539 }
jardineb5d44e2003-12-23 08:09:43 +00002540#if 0
hassof390d2c2004-09-10 20:48:21 +00002541 /*
2542 * If there are still LSPs send next one after lsp-interval (33 msecs)
2543 */
2544 if (listcount (circuit->lsp_queue) > 0)
2545 thread_add_timer (master, send_lsp, circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002546#endif
hassof390d2c2004-09-10 20:48:21 +00002547 }
jardineb5d44e2003-12-23 08:09:43 +00002548
2549 return retval;
hassof390d2c2004-09-10 20:48:21 +00002550}
jardineb5d44e2003-12-23 08:09:43 +00002551
2552int
hassof390d2c2004-09-10 20:48:21 +00002553ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2554 int level)
jardineb5d44e2003-12-23 08:09:43 +00002555{
2556 unsigned long lenp;
2557 int retval;
2558 u_int16_t length;
2559 struct isis_fixed_hdr fixed_hdr;
2560
2561 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002562 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002563 else
2564 stream_reset (circuit->snd_stream);
2565
2566// fill_llc_hdr (stream);
2567 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002568 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2569 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002570 else
hassof390d2c2004-09-10 20:48:21 +00002571 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2572 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002573
2574
paul9985f832005-02-09 15:51:56 +00002575 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002576 stream_putw (circuit->snd_stream, 0); /* PDU length */
2577 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002578 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002579 stream_putc (circuit->snd_stream, 9); /* code */
2580 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002581
hassof390d2c2004-09-10 20:48:21 +00002582 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2583 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2584 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2585 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002586
paul9985f832005-02-09 15:51:56 +00002587 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002588 /* Update PDU length */
2589 stream_putw_at (circuit->snd_stream, lenp, length);
2590
2591 retval = circuit->tx (circuit, level);
2592
2593 return retval;
2594}
2595
2596#if 0
2597/*
2598 * ISH PDU Processing
2599 */
2600
jardineb5d44e2003-12-23 08:09:43 +00002601 /*
2602 * Let's first check if the local and remote system have any common area
2603 * addresses
2604 */
hassof390d2c2004-09-10 20:48:21 +00002605if (area_match (tlvs.area_addrs, isis->man_area_addrs) == 0)
2606 {
2607 if (circuit->circuit_t == IS_LEVEL_2)
2608 {
2609 /* do as in table 8 (p. 40) */
2610 switch (circuit_type)
2611 {
2612 case IS_LEVEL_1:
2613 if (adj->adj_state != ISIS_ADJ_UP)
2614 {
2615 /* Reject */
2616 zlog_warn ("areaMismatch");
2617 retval = ISIS_WARNING;
2618 }
2619 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2620 {
2621 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2622 circuit->adjdb);
2623 }
2624 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 ||
2625 adj->adj_usage == ISIS_ADJ_LEVEL2)
2626 {
2627 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2628 circuit->adjdb);
2629 }
2630 break;
2631 case IS_LEVEL_2:
2632 if (adj->adj_state != ISIS_ADJ_UP)
2633 {
2634 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2635 circuit->adjdb);
2636 adj->adj_usage = ISIS_ADJ_LEVEL2;
2637 }
2638 else if (adj->adj_usage == ISIS_ADJ_LEVEL1 ||
2639 adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2640 {
2641 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2642 circuit->adjdb);
2643 }
2644 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2645 {
2646 ; /* Accept */
2647 }
2648 break;
2649 case IS_LEVEL_1_AND_2:
2650 if (adj->adj_state != ISIS_ADJ_UP)
2651 {
2652 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL,
2653 circuit->adjdb);
2654 adj->adj_usage = ISIS_ADJ_LEVEL2;
2655 }
2656 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
2657 {
2658 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System",
2659 circuit->adjdb);
2660 }
2661 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
2662 {
2663 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch",
2664 circuit->adjdb);
2665 }
2666 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
2667 {
2668 ; /* Accept */
2669 }
2670 break;
2671 }
2672 goto mismatch;
jardineb5d44e2003-12-23 08:09:43 +00002673 }
hassof390d2c2004-09-10 20:48:21 +00002674 else
2675 {
2676 isis_delete_adj (adj, circuit->adjdb);
2677 zlog_warn ("areaMismatch");
2678 return ISIS_WARNING;
2679 }
jardineb5d44e2003-12-23 08:09:43 +00002680 }
2681
2682mismatch:
2683#endif