blob: 2dc821560d15a898bd0bb75238c3040b6c158a16 [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
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "memory.h"
27#include "thread.h"
28#include "linklist.h"
29#include "log.h"
30#include "stream.h"
31#include "vty.h"
32#include "hash.c"
33#include "prefix.h"
34#include "if.h"
35
36#include "isisd/dict.h"
37#include "isisd/include-netbsd/iso.h"
38#include "isisd/isis_constants.h"
39#include "isisd/isis_common.h"
40#include "isisd/isis_adjacency.h"
41#include "isisd/isis_circuit.h"
42#include "isisd/isis_network.h"
43#include "isisd/isis_misc.h"
44#include "isisd/isis_dr.h"
45#include "isisd/isis_flags.h"
46#include "isisd/isis_tlv.h"
47#include "isisd/isisd.h"
48#include "isisd/isis_dynhn.h"
49#include "isisd/isis_lsp.h"
50#include "isisd/isis_pdu.h"
51#include "isisd/iso_checksum.h"
52#include "isisd/isis_csm.h"
53#include "isisd/isis_events.h"
54
55extern struct thread_master *master;
56extern struct isis *isis;
57
58#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000059#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000060
61#ifndef PNBBY
62#define PNBBY 8
63#endif /* PNBBY */
64
65/* Utility mask array. */
hassof390d2c2004-09-10 20:48:21 +000066static u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000067 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
68};
69
70/*
71 * HELPER FUNCS
72 */
73
74/*
75 * Compares two sets of area addresses
76 */
hassof390d2c2004-09-10 20:48:21 +000077static int
jardineb5d44e2003-12-23 08:09:43 +000078area_match (struct list *left, struct list *right)
79{
80 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000081 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000082
hasso3fdb2dd2005-09-28 18:45:54 +000083 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000084 {
hasso3fdb2dd2005-09-28 18:45:54 +000085 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000086 {
87 if (addr1->addr_len == addr2->addr_len &&
88 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
89 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000090 }
91 }
92
hassof390d2c2004-09-10 20:48:21 +000093 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000094}
95
96/*
97 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
98 * param ip1 the IS interface ip address structure
99 * param ip2 the IIH's ip address
100 * return 0 the IIH's IP is not in the IS's subnetwork
101 * 1 the IIH's IP is in the IS's subnetwork
102 */
hasso92365882005-01-18 13:53:33 +0000103static int
hassof390d2c2004-09-10 20:48:21 +0000104ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000105{
106 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000107 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000108 int len;
hassof390d2c2004-09-10 20:48:21 +0000109
110 addr1 = (u_char *) & ip1->prefix.s_addr;
111 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000112 len = ip1->prefixlen;
113
114 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000115 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000116
hasso53c997c2004-09-15 16:21:59 +0000117 while (offsetloop--)
118 if (addr1[offsetloop] != addr2[offsetloop])
119 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000120
hassof390d2c2004-09-10 20:48:21 +0000121 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000122 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
123 return 0;
hassof390d2c2004-09-10 20:48:21 +0000124
125 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000126}
127
jardineb5d44e2003-12-23 08:09:43 +0000128/*
129 * Compares two set of ip addresses
130 * param left the local interface's ip addresses
131 * param right the iih interface's ip address
132 * return 0 no match;
133 * 1 match;
134 */
hassof390d2c2004-09-10 20:48:21 +0000135static int
jardineb5d44e2003-12-23 08:09:43 +0000136ip_match (struct list *left, struct list *right)
137{
138 struct prefix_ipv4 *ip1;
139 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000140 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000141
hassoe082ac12004-09-27 18:13:57 +0000142 if ((left == NULL) || (right == NULL))
143 return 0;
144
hasso3fdb2dd2005-09-28 18:45:54 +0000145 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000146 {
hasso3fdb2dd2005-09-28 18:45:54 +0000147 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000148 {
149 if (ip_same_subnet (ip1, ip2))
150 {
151 return 1; /* match */
152 }
jardineb5d44e2003-12-23 08:09:43 +0000153 }
hassof390d2c2004-09-10 20:48:21 +0000154
jardineb5d44e2003-12-23 08:09:43 +0000155 }
156 return 0;
157}
158
159/*
160 * Checks whether we should accept a PDU of given level
161 */
162static int
163accept_level (int level, int circuit_t)
164{
hassof390d2c2004-09-10 20:48:21 +0000165 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000166
167 return retval;
168}
169
hassof390d2c2004-09-10 20:48:21 +0000170int
jardineb5d44e2003-12-23 08:09:43 +0000171authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
172{
hassof390d2c2004-09-10 20:48:21 +0000173 if (one->type != theother->type)
174 {
175 zlog_warn ("Unsupported authentication type %d", theother->type);
176 return 1; /* Auth fail (different authentication types) */
177 }
178 switch (one->type)
179 {
180 case ISIS_PASSWD_TYPE_CLEARTXT:
181 if (one->len != theother->len)
182 return 1; /* Auth fail () - passwd len mismatch */
183 return memcmp (one->passwd, theother->passwd, one->len);
184 break;
185 default:
186 zlog_warn ("Unsupported authentication type");
187 break;
188 }
189 return 0; /* Auth pass */
jardineb5d44e2003-12-23 08:09:43 +0000190}
191
192/*
193 * Processing helper functions
194 */
hasso92365882005-01-18 13:53:33 +0000195static void
hassof390d2c2004-09-10 20:48:21 +0000196tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000197{
198 int i;
199 struct nlpids *tlv_nlpids;
200
hassof390d2c2004-09-10 20:48:21 +0000201 if (tlvs->nlpids)
202 {
jardineb5d44e2003-12-23 08:09:43 +0000203
hassof390d2c2004-09-10 20:48:21 +0000204 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000205
hassof390d2c2004-09-10 20:48:21 +0000206 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000207
hassof390d2c2004-09-10 20:48:21 +0000208 for (i = 0; i < tlv_nlpids->count; i++)
209 {
210 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
211 }
jardineb5d44e2003-12-23 08:09:43 +0000212 }
jardineb5d44e2003-12-23 08:09:43 +0000213}
214
hasso92365882005-01-18 13:53:33 +0000215static void
jardineb5d44e2003-12-23 08:09:43 +0000216del_ip_addr (void *val)
217{
218 XFREE (MTYPE_ISIS_TMP, val);
219}
220
hasso92365882005-01-18 13:53:33 +0000221static void
hassof390d2c2004-09-10 20:48:21 +0000222tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000223{
hasso3fdb2dd2005-09-28 18:45:54 +0000224 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000225 struct in_addr *ipv4_addr, *malloced;
226
hassof390d2c2004-09-10 20:48:21 +0000227 if (adj->ipv4_addrs)
228 {
229 adj->ipv4_addrs->del = del_ip_addr;
230 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000231 }
hassof390d2c2004-09-10 20:48:21 +0000232 adj->ipv4_addrs = list_new ();
233 if (tlvs->ipv4_addrs)
234 {
hasso3fdb2dd2005-09-28 18:45:54 +0000235 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000236 {
237 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
238 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
239 listnode_add (adj->ipv4_addrs, malloced);
240 }
241 }
jardineb5d44e2003-12-23 08:09:43 +0000242}
243
244#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000245static void
hassof390d2c2004-09-10 20:48:21 +0000246tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000247{
hasso3fdb2dd2005-09-28 18:45:54 +0000248 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000249 struct in6_addr *ipv6_addr, *malloced;
250
hassof390d2c2004-09-10 20:48:21 +0000251 if (adj->ipv6_addrs)
252 {
253 adj->ipv6_addrs->del = del_ip_addr;
254 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000255 }
hassof390d2c2004-09-10 20:48:21 +0000256 adj->ipv6_addrs = list_new ();
257 if (tlvs->ipv6_addrs)
258 {
hasso3fdb2dd2005-09-28 18:45:54 +0000259 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000260 {
261 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
262 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
263 listnode_add (adj->ipv6_addrs, malloced);
264 }
265 }
jardineb5d44e2003-12-23 08:09:43 +0000266
267}
268#endif /* HAVE_IPV6 */
269
jardineb5d44e2003-12-23 08:09:43 +0000270/*
271 * RECEIVE SIDE
272 */
273
274/*
275 * Process P2P IIH
276 * ISO - 10589
277 * Section 8.2.5 - Receiving point-to-point IIH PDUs
278 *
279 */
280static int
281process_p2p_hello (struct isis_circuit *circuit)
282{
283 int retval = ISIS_OK;
284 struct isis_p2p_hello_hdr *hdr;
285 struct isis_adjacency *adj;
286 u_int32_t expected = 0, found;
287 struct tlvs tlvs;
288
hassof390d2c2004-09-10 20:48:21 +0000289 if ((stream_get_endp (circuit->rcv_stream) -
290 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
291 {
292 zlog_warn ("Packet too short");
293 return ISIS_WARNING;
294 }
jardineb5d44e2003-12-23 08:09:43 +0000295
296 /* 8.2.5.1 PDU acceptance tests */
297
298 /* 8.2.5.1 a) external domain untrue */
299 /* FIXME: not useful at all? */
300
301 /* 8.2.5.1 b) ID Length mismatch */
302 /* checked at the handle_pdu */
303
304 /* 8.2.5.2 IIH PDU Processing */
305
306 /* 8.2.5.2 a) 1) Maximum Area Addresses */
307 /* Already checked, and can also be ommited */
308
309 /*
310 * Get the header
311 */
hassof390d2c2004-09-10 20:48:21 +0000312 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000313 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
314
315 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000316 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
317 hdr.hold_time = stream_getw (stream);
318 hdr.pdu_len = stream_getw (stream);
319 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000320
321 /*
322 * My interpertation of the ISO, if no adj exists we will create one for
323 * the circuit
324 */
325
hassof390d2c2004-09-10 20:48:21 +0000326 if (isis->debugs & DEBUG_ADJ_PACKETS)
327 {
hasso529d65b2004-12-24 00:14:50 +0000328 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
329 " cir id %02d, length %d",
330 circuit->area->area_tag, circuit->interface->name,
331 circuit_t2string (circuit->circuit_is_type),
332 circuit->circuit_id, ntohs (hdr->pdu_len));
hassof390d2c2004-09-10 20:48:21 +0000333 }
jardineb5d44e2003-12-23 08:09:43 +0000334
335 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000336 if (!adj)
337 {
hassof7c43dc2004-09-26 16:24:14 +0000338 adj = isis_new_adj (hdr->source_id, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +0000339 if (adj == NULL)
340 return ISIS_ERROR;
341 circuit->u.p2p.neighbor = adj;
342 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
343 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
344 }
jardineb5d44e2003-12-23 08:09:43 +0000345
346 /* 8.2.6 Monitoring point-to-point adjacencies */
347 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000348 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000349
350 /*
351 * Lets get the TLVS now
352 */
353 expected |= TLVFLAG_AREA_ADDRS;
354 expected |= TLVFLAG_AUTH_INFO;
355 expected |= TLVFLAG_NLPID;
356 expected |= TLVFLAG_IPV4_ADDR;
357 expected |= TLVFLAG_IPV6_ADDR;
358
359 retval = parse_tlvs (circuit->area->area_tag,
360 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000361 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
362 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000363
hassof390d2c2004-09-10 20:48:21 +0000364 if (retval > ISIS_WARNING)
365 {
366 free_tlvs (&tlvs);
367 return retval;
368 };
jardineb5d44e2003-12-23 08:09:43 +0000369
370 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000371 if (circuit->passwd.type)
372 {
373 if (!(found & TLVFLAG_AUTH_INFO) ||
374 authentication_check (&circuit->passwd, &tlvs.auth_info))
375 {
376 isis_event_auth_failure (circuit->area->area_tag,
377 "P2P hello authentication failure",
378 hdr->source_id);
379 return ISIS_OK;
380 }
jardineb5d44e2003-12-23 08:09:43 +0000381 }
jardineb5d44e2003-12-23 08:09:43 +0000382
383 /* we do this now because the adj may not survive till the end... */
384
385 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000386 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000387
388#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000389 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000390#endif /* HAVE_IPV6 */
391
392 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000393 THREAD_TIMER_OFF (adj->t_expire);
394 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
395 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000396
397 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000398 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
399 {
400 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
401 if (circuit->area->is_type == IS_LEVEL_1)
402 {
403 switch (hdr->circuit_t)
404 {
405 case IS_LEVEL_1:
406 case IS_LEVEL_1_AND_2:
407 if (adj->adj_state != ISIS_ADJ_UP)
408 {
409 /* (4) adj state up */
410 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
411 /* (5) adj usage level 1 */
412 adj->adj_usage = ISIS_ADJ_LEVEL1;
413 }
414 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
415 {
416 ; /* accept */
417 }
418 break;
419 case IS_LEVEL_2:
420 if (adj->adj_state != ISIS_ADJ_UP)
421 {
422 /* (7) reject - wrong system type event */
423 zlog_warn ("wrongSystemType");
424 return ISIS_WARNING; /* Reject */
425 }
426 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
427 {
428 /* (6) down - wrong system */
429 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
430 }
431 break;
432 }
433 }
jardineb5d44e2003-12-23 08:09:43 +0000434
hassof390d2c2004-09-10 20:48:21 +0000435 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
436 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
437 {
438 switch (hdr->circuit_t)
439 {
440 case IS_LEVEL_1:
441 if (adj->adj_state != ISIS_ADJ_UP)
442 {
443 /* (6) adj state up */
444 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
445 /* (7) adj usage level 1 */
446 adj->adj_usage = ISIS_ADJ_LEVEL1;
447 }
448 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
449 {
450 ; /* accept */
451 }
452 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
453 (adj->adj_usage == ISIS_ADJ_LEVEL2))
454 {
455 /* (8) down - wrong system */
456 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
457 }
458 break;
459 case IS_LEVEL_2:
460 if (adj->adj_state != ISIS_ADJ_UP)
461 {
462 /* (6) adj state up */
463 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
464 /* (9) adj usage level 2 */
465 adj->adj_usage = ISIS_ADJ_LEVEL2;
466 }
467 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
468 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
469 {
470 /* (8) down - wrong system */
471 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
472 }
473 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
474 {
475 ; /* Accept */
476 }
477 break;
478 case IS_LEVEL_1_AND_2:
479 if (adj->adj_state != ISIS_ADJ_UP)
480 {
481 /* (6) adj state up */
482 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
483 /* (10) adj usage level 1 */
484 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
485 }
486 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
487 (adj->adj_usage == ISIS_ADJ_LEVEL2))
488 {
489 /* (8) down - wrong system */
490 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
491 }
492 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
493 {
494 ; /* Accept */
495 }
496 break;
497 }
498 }
jardineb5d44e2003-12-23 08:09:43 +0000499
hassof390d2c2004-09-10 20:48:21 +0000500 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
501 if (circuit->area->is_type == IS_LEVEL_2)
502 {
503 switch (hdr->circuit_t)
504 {
505 case IS_LEVEL_1:
506 if (adj->adj_state != ISIS_ADJ_UP)
507 {
508 /* (5) reject - wrong system type event */
509 zlog_warn ("wrongSystemType");
510 return ISIS_WARNING; /* Reject */
511 }
512 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
513 (adj->adj_usage == ISIS_ADJ_LEVEL2))
514 {
515 /* (6) down - wrong system */
516 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
517 }
518 break;
519 case IS_LEVEL_1_AND_2:
520 case IS_LEVEL_2:
521 if (adj->adj_state != ISIS_ADJ_UP)
522 {
523 /* (7) adj state up */
524 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
525 /* (8) adj usage level 2 */
526 adj->adj_usage = ISIS_ADJ_LEVEL2;
527 }
528 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
529 {
530 /* (6) down - wrong system */
531 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
532 }
533 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
534 {
535 ; /* Accept */
536 }
537 break;
538 }
539 }
jardineb5d44e2003-12-23 08:09:43 +0000540 }
jardineb5d44e2003-12-23 08:09:43 +0000541 /* 8.2.5.2 b) if no match was detected */
542 else
jardineb5d44e2003-12-23 08:09:43 +0000543 {
hassof390d2c2004-09-10 20:48:21 +0000544 if (circuit->area->is_type == IS_LEVEL_1)
545 {
546 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
547 if (adj->adj_state != ISIS_ADJ_UP)
548 {
549 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
550 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
551 }
552 else
553 {
554 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
555 "Down - Area Mismatch");
556 }
557 }
558 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
559 else
560 {
561 switch (hdr->circuit_t)
562 {
563 case IS_LEVEL_1:
564 if (adj->adj_state != ISIS_ADJ_UP)
565 {
566 /* (6) reject - Area Mismatch event */
567 zlog_warn ("AreaMismatch");
568 return ISIS_WARNING; /* Reject */
569 }
570 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
571 {
572 /* (7) down - area mismatch */
573 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000574
hassof390d2c2004-09-10 20:48:21 +0000575 }
576 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
577 (adj->adj_usage == ISIS_ADJ_LEVEL2))
578 {
579 /* (7) down - wrong system */
580 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
581 }
582 break;
583 case IS_LEVEL_1_AND_2:
584 case IS_LEVEL_2:
585 if (adj->adj_state != ISIS_ADJ_UP)
586 {
587 /* (8) adj state up */
588 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
589 /* (9) adj usage level 2 */
590 adj->adj_usage = ISIS_ADJ_LEVEL2;
591 }
592 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
593 {
594 /* (7) down - wrong system */
595 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
596 }
597 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
598 {
599 if (hdr->circuit_t == IS_LEVEL_2)
600 {
601 /* (7) down - wrong system */
602 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
603 "Wrong System");
604 }
605 else
606 {
607 /* (7) down - area mismatch */
608 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
609 "Area Mismatch");
610 }
611 }
612 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
613 {
614 ; /* Accept */
615 }
616 break;
617 }
618 }
jardineb5d44e2003-12-23 08:09:43 +0000619 }
jardineb5d44e2003-12-23 08:09:43 +0000620 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
621 /* FIXME - Missing parts */
622
jardineb5d44e2003-12-23 08:09:43 +0000623 /* some of my own understanding of the ISO, why the heck does
624 * it not say what should I change the system_type to...
625 */
hassof390d2c2004-09-10 20:48:21 +0000626 switch (adj->adj_usage)
627 {
jardineb5d44e2003-12-23 08:09:43 +0000628 case ISIS_ADJ_LEVEL1:
629 adj->sys_type = ISIS_SYSTYPE_L1_IS;
630 break;
631 case ISIS_ADJ_LEVEL2:
632 adj->sys_type = ISIS_SYSTYPE_L2_IS;
633 break;
634 case ISIS_ADJ_LEVEL1AND2:
635 adj->sys_type = ISIS_SYSTYPE_L2_IS;
636 break;
637 case ISIS_ADJ_NONE:
638 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
639 break;
hassof390d2c2004-09-10 20:48:21 +0000640 }
jardineb5d44e2003-12-23 08:09:43 +0000641
642 adj->circuit_t = hdr->circuit_t;
643 adj->level = hdr->circuit_t;
644
645 free_tlvs (&tlvs);
646
647 return retval;
648}
649
jardineb5d44e2003-12-23 08:09:43 +0000650/*
651 * Process IS-IS LAN Level 1/2 Hello PDU
652 */
hassof390d2c2004-09-10 20:48:21 +0000653static int
654process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000655{
656 int retval = ISIS_OK;
657 struct isis_lan_hello_hdr hdr;
658 struct isis_adjacency *adj;
659 u_int32_t expected = 0, found;
660 struct tlvs tlvs;
661 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000662 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000663
hassof390d2c2004-09-10 20:48:21 +0000664 if ((stream_get_endp (circuit->rcv_stream) -
665 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
666 {
667 zlog_warn ("Packet too short");
668 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000669 }
hassof390d2c2004-09-10 20:48:21 +0000670
671 if (circuit->ext_domain)
672 {
hasso529d65b2004-12-24 00:14:50 +0000673 zlog_debug ("level %d LAN Hello received over circuit with "
674 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000675 return ISIS_WARNING;
676 }
677
678 if (!accept_level (level, circuit->circuit_is_type))
679 {
680 if (isis->debugs & DEBUG_ADJ_PACKETS)
681 {
hasso529d65b2004-12-24 00:14:50 +0000682 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
683 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000684 }
685 return ISIS_WARNING;
686 }
jardineb5d44e2003-12-23 08:09:43 +0000687
688#if 0
689 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000690 if (!accept_level (level, circuit->area->is_type))
691 {
692 if (isis->debugs & DEBUG_ADJ_PACKETS)
693 {
hasso529d65b2004-12-24 00:14:50 +0000694 zlog_debug ("ISIS-Adj (%s): is type mismatch",
695 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000696 }
697 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000698 }
jardineb5d44e2003-12-23 08:09:43 +0000699#endif
700 /*
701 * Fill the header
702 */
703 hdr.circuit_t = stream_getc (circuit->rcv_stream);
704 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
705 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000706 hdr.pdu_len = stream_getw (circuit->rcv_stream);
707 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000708 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
709
710 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000711 hdr.circuit_t != IS_LEVEL_1_AND_2)
712 {
713 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
714 hdr.circuit_t);
715 return ISIS_ERROR;
716 }
jardineb5d44e2003-12-23 08:09:43 +0000717 /*
718 * Then get the tlvs
719 */
720 expected |= TLVFLAG_AUTH_INFO;
721 expected |= TLVFLAG_AREA_ADDRS;
722 expected |= TLVFLAG_LAN_NEIGHS;
723 expected |= TLVFLAG_NLPID;
724 expected |= TLVFLAG_IPV4_ADDR;
725 expected |= TLVFLAG_IPV6_ADDR;
726
727 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000728 STREAM_PNT (circuit->rcv_stream),
729 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
730 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000731
hassof390d2c2004-09-10 20:48:21 +0000732 if (retval > ISIS_WARNING)
733 {
734 zlog_warn ("parse_tlvs() failed");
735 goto out;
736 }
jardineb5d44e2003-12-23 08:09:43 +0000737
hassof390d2c2004-09-10 20:48:21 +0000738 if (!(found & TLVFLAG_AREA_ADDRS))
739 {
740 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
741 level);
jardineb5d44e2003-12-23 08:09:43 +0000742 retval = ISIS_WARNING;
743 goto out;
744 }
hassof390d2c2004-09-10 20:48:21 +0000745
746 if (circuit->passwd.type)
747 {
748 if (!(found & TLVFLAG_AUTH_INFO) ||
749 authentication_check (&circuit->passwd, &tlvs.auth_info))
750 {
751 isis_event_auth_failure (circuit->area->area_tag,
752 "LAN hello authentication failure",
753 hdr.source_id);
754 retval = ISIS_WARNING;
755 goto out;
756 }
757 }
jardineb5d44e2003-12-23 08:09:43 +0000758
759 /*
760 * Accept the level 1 adjacency only if a match between local and
761 * remote area addresses is found
762 */
hassof390d2c2004-09-10 20:48:21 +0000763 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
764 {
765 if (isis->debugs & DEBUG_ADJ_PACKETS)
766 {
hasso529d65b2004-12-24 00:14:50 +0000767 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
768 circuit->area->area_tag, level,
769 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000770 }
771 retval = ISIS_OK;
772 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000773 }
jardineb5d44e2003-12-23 08:09:43 +0000774
775 /*
776 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000777 */
778 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
779 {
hasso529d65b2004-12-24 00:14:50 +0000780 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
781 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000782
hassof390d2c2004-09-10 20:48:21 +0000783 retval = ISIS_OK;
784 goto out;
785 }
jardineb5d44e2003-12-23 08:09:43 +0000786
787 /*
788 * check if it's own interface ip match iih ip addrs
789 */
hassof390d2c2004-09-10 20:48:21 +0000790 if (!(found & TLVFLAG_IPV4_ADDR)
791 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
792 {
hasso529d65b2004-12-24 00:14:50 +0000793 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000794 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
795 circuit->interface->name);
796 retval = ISIS_WARNING;
797 goto out;
798 }
jardineb5d44e2003-12-23 08:09:43 +0000799
800 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000801 if (!adj)
802 {
803 /*
804 * Do as in 8.4.2.5
805 */
806 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
807 if (adj == NULL)
hasso13c48f72004-09-10 21:19:13 +0000808 {
809 retval = ISIS_ERROR;
810 goto out;
811 }
jardineb5d44e2003-12-23 08:09:43 +0000812
hassof390d2c2004-09-10 20:48:21 +0000813 adj->level = level;
814 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000815
hassof390d2c2004-09-10 20:48:21 +0000816 if (level == 1)
817 {
818 adj->sys_type = ISIS_SYSTYPE_L1_IS;
819 }
820 else
821 {
822 adj->sys_type = ISIS_SYSTYPE_L2_IS;
823 }
824 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
825 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
826 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000827 }
jardineb5d44e2003-12-23 08:09:43 +0000828
hassoa211d652004-09-20 14:55:29 +0000829 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
830 switch (level)
831 {
832 case 1:
833 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
834 {
835 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000836 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
837 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000838 }
839 break;
840 case 2:
841 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
842 {
843 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000844 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
845 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000846 }
847 break;
848 }
jardineb5d44e2003-12-23 08:09:43 +0000849
850 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000851 adj->last_upd = time (NULL);
852 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000853
854 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
855
856 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000857 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000858 tlvs_to_adj_nlpids (&tlvs, adj);
859
860 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000861 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000862 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
863
864#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000865 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000866 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
867#endif /* HAVE_IPV6 */
868
869 adj->circuit_t = hdr.circuit_t;
870
871 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000872 THREAD_TIMER_OFF (adj->t_expire);
873 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
874 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000875
876 /*
877 * If the snpa for this circuit is found from LAN Neighbours TLV
878 * we have two-way communication -> adjacency can be put to state "up"
879 */
880
hassof390d2c2004-09-10 20:48:21 +0000881 if (found & TLVFLAG_LAN_NEIGHS)
882 {
883 if (adj->adj_state != ISIS_ADJ_UP)
884 {
hasso3fdb2dd2005-09-28 18:45:54 +0000885 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
hassof390d2c2004-09-10 20:48:21 +0000886 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
887 {
888 isis_adj_state_change (adj, ISIS_ADJ_UP,
889 "own SNPA found in LAN Neighbours TLV");
890 }
891 }
jardineb5d44e2003-12-23 08:09:43 +0000892 }
jardineb5d44e2003-12-23 08:09:43 +0000893
hassof390d2c2004-09-10 20:48:21 +0000894out:
jardineb5d44e2003-12-23 08:09:43 +0000895 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000896 if (isis->debugs & DEBUG_ADJ_PACKETS)
897 {
898 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +0000899 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
900 "cirID %u, length %ld",
901 circuit->area->area_tag,
902 level, snpa_print (ssnpa), circuit->interface->name,
903 circuit_t2string (circuit->circuit_is_type),
hasso29e50b22005-09-01 18:18:47 +0000904 circuit->circuit_id,
905 /* FIXME: use %z when we stop supporting old compilers. */
906 (unsigned long) stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +0000907 }
jardineb5d44e2003-12-23 08:09:43 +0000908
909 free_tlvs (&tlvs);
910
911 return retval;
912}
913
914/*
915 * Process Level 1/2 Link State
916 * ISO - 10589
917 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000918 */
919static int
920process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000921{
922 struct isis_link_state_hdr *hdr;
923 struct isis_adjacency *adj = NULL;
924 struct isis_lsp *lsp, *lsp0 = NULL;
925 int retval = ISIS_OK, comp = 0;
926 u_char lspid[ISIS_SYS_ID_LEN + 2];
927 struct isis_passwd *passwd;
928
929 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000930 if ((stream_get_endp (circuit->rcv_stream) -
931 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
932 {
933 zlog_warn ("Packet too short");
934 return ISIS_WARNING;
935 }
jardineb5d44e2003-12-23 08:09:43 +0000936
937 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000938 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000939
hassof390d2c2004-09-10 20:48:21 +0000940 if (isis->debugs & DEBUG_UPDATE_PACKETS)
941 {
hasso529d65b2004-12-24 00:14:50 +0000942 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
943 "lifetime %us, len %lu, on %s",
944 circuit->area->area_tag,
945 level,
946 rawlspid_print (hdr->lsp_id),
947 ntohl (hdr->seq_num),
948 ntohs (hdr->checksum),
949 ntohs (hdr->rem_lifetime),
hasso29e50b22005-09-01 18:18:47 +0000950 /* FIXME: use %z when we stop supporting old compilers. */
951 (unsigned long) stream_get_endp (circuit->rcv_stream),
paul15935e92005-05-03 09:27:23 +0000952 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000953 }
jardineb5d44e2003-12-23 08:09:43 +0000954
955 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
956
957 /* Checksum sanity check - FIXME: move to correct place */
958 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000959 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
960 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
961 {
hasso529d65b2004-12-24 00:14:50 +0000962 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
963 circuit->area->area_tag,
964 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000965
hassof390d2c2004-09-10 20:48:21 +0000966 return ISIS_WARNING;
967 }
jardineb5d44e2003-12-23 08:09:43 +0000968
969 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000970 if (circuit->ext_domain)
971 {
hasso529d65b2004-12-24 00:14:50 +0000972 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000973 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
974 "externalDomain = true", circuit->area->area_tag,
975 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000976
hassof390d2c2004-09-10 20:48:21 +0000977 return ISIS_WARNING;
978 }
jardineb5d44e2003-12-23 08:09:43 +0000979
980 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000981 if (!accept_level (level, circuit->circuit_is_type))
982 {
hasso529d65b2004-12-24 00:14:50 +0000983 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
984 " type %s",
985 circuit->area->area_tag,
986 rawlspid_print (hdr->lsp_id),
987 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +0000988
hassof390d2c2004-09-10 20:48:21 +0000989 return ISIS_WARNING;
990 }
jardineb5d44e2003-12-23 08:09:43 +0000991
992 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
993
994 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
995
996 /* 7.3.15.1 a) 7 - password check */
997 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
998 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +0000999 if (passwd->type)
1000 {
1001 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1002 ntohs (hdr->pdu_len), passwd))
1003 {
1004 isis_event_auth_failure (circuit->area->area_tag,
1005 "LSP authentication failure", hdr->lsp_id);
1006 return ISIS_WARNING;
1007 }
jardineb5d44e2003-12-23 08:09:43 +00001008 }
jardineb5d44e2003-12-23 08:09:43 +00001009 /* Find the LSP in our database and compare it to this Link State header */
1010 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1011 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001012 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1013 hdr->checksum, hdr->rem_lifetime);
1014 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001015#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001016 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001017#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001018 ))
jardineb5d44e2003-12-23 08:09:43 +00001019 goto dontcheckadj;
1020
1021 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1022 /* for broadcast circuits, snpa should be compared */
1023 /* FIXME : Point To Point */
1024
hassof390d2c2004-09-10 20:48:21 +00001025 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1026 {
1027 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1028 if (!adj)
1029 {
hasso529d65b2004-12-24 00:14:50 +00001030 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1031 "lifetime %us on %s",
1032 circuit->area->area_tag,
1033 rawlspid_print (hdr->lsp_id),
1034 ntohl (hdr->seq_num),
1035 ntohs (hdr->checksum),
1036 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001037 return ISIS_WARNING; /* Silently discard */
1038 }
jardineb5d44e2003-12-23 08:09:43 +00001039 }
jardineb5d44e2003-12-23 08:09:43 +00001040
1041 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001042 else
1043 {
1044 /* If no adj, or no sharing of level */
1045 if (!circuit->u.p2p.neighbor)
1046 {
1047 return ISIS_OK; /* Silently discard */
1048 }
1049 else
1050 {
1051 if (((level == 1) &&
1052 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1053 ((level == 2) &&
1054 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1055 return ISIS_WARNING; /* Silently discard */
1056 }
jardineb5d44e2003-12-23 08:09:43 +00001057 }
hassof390d2c2004-09-10 20:48:21 +00001058dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001059 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1060
1061 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1062
hassof390d2c2004-09-10 20:48:21 +00001063 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001064
hassof390d2c2004-09-10 20:48:21 +00001065 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1066 if (hdr->rem_lifetime == 0)
1067 {
1068 if (!lsp)
1069 {
1070 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1071 /* only needed on explicit update, eg - p2p */
1072 if (circuit->circ_type == CIRCUIT_T_P2P)
1073 ack_lsp (hdr, circuit, level);
1074 return retval; /* FIXME: do we need a purge? */
1075 }
1076 else
1077 {
1078 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1079 {
1080 /* LSP by some other system -> do 7.3.16.4 b) */
1081 /* 7.3.16.4 b) 1) */
1082 if (comp == LSP_NEWER)
1083 {
hassoa96d8d12005-09-16 14:44:23 +00001084 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area,
1085 level);
hassof390d2c2004-09-10 20:48:21 +00001086 /* 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);
hassoc89c05d2005-09-04 21:36:36 +00001121 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1122 zlog_debug ("LSP LEN: %d",
1123 ntohs (lsp->lsp_header->pdu_len));
hassof390d2c2004-09-10 20:48:21 +00001124 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1125 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1126 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001127 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1128 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1129 "seq 0x%08x", circuit->area->area_tag,
1130 rawlspid_print (hdr->lsp_id),
1131 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001132 lsp->lsp_header->rem_lifetime =
1133 htons (isis_jitter
1134 (circuit->area->max_lsp_lifetime[level - 1],
1135 MAX_AGE_JITTER));
1136 }
1137 else
1138 {
1139 /* Got purge for own pseudo-lsp, and we are not DR */
1140 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1141 }
1142 }
1143 }
1144 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001145 }
jardineb5d44e2003-12-23 08:09:43 +00001146 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1147 * purge */
hassof390d2c2004-09-10 20:48:21 +00001148 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1149 {
1150 if (!lsp)
1151 {
1152 /* 7.3.16.4: initiate a purge */
1153 lsp_purge_non_exist (hdr, circuit->area);
1154 return ISIS_OK;
1155 }
1156 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1157
1158 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1159 * has information that the current sequence number for source S is
1160 * "greater" than that held by S, ... */
1161
1162 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1163 {
1164 /* 7.3.16.1 */
1165 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1166
1167 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1168 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1169
1170 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001171 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1172 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1173 "0x%08x", circuit->area->area_tag,
1174 rawlspid_print (hdr->lsp_id),
1175 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001176 lsp->lsp_header->rem_lifetime =
1177 htons (isis_jitter
1178 (circuit->area->max_lsp_lifetime[level - 1],
1179 MAX_AGE_JITTER));
1180 }
jardineb5d44e2003-12-23 08:09:43 +00001181 }
hassof390d2c2004-09-10 20:48:21 +00001182 else
1183 {
1184 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001185
hassof390d2c2004-09-10 20:48:21 +00001186 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1187 if ((!lsp || comp == LSP_NEWER))
1188 {
1189 /* i */
1190 if (lsp)
1191 {
jardineb5d44e2003-12-23 08:09:43 +00001192#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001193 zlog_debug ("level %d number is - %ld", level,
1194 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001195#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001196 lsp_search_and_destroy (hdr->lsp_id,
1197 circuit->area->lspdb[level - 1]);
1198 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001199#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001200 zlog_debug ("level %d number is - %ld", level,
1201 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001202#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001203 }
1204 /*
1205 * If this lsp is a frag, need to see if we have zero lsp present
1206 */
1207 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1208 {
1209 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1210 LSP_FRAGMENT (lspid) = 0;
1211 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1212 if (!lsp0)
1213 {
hasso529d65b2004-12-24 00:14:50 +00001214 zlog_debug ("Got lsp frag, while zero lsp not database");
hassof390d2c2004-09-10 20:48:21 +00001215 return ISIS_OK;
1216 }
1217 }
1218 lsp =
1219 lsp_new_from_stream_ptr (circuit->rcv_stream,
1220 ntohs (hdr->pdu_len), lsp0,
1221 circuit->area);
1222 lsp->level = level;
1223 lsp->adj = adj;
1224 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1225 /* ii */
1226 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1227 /* iii */
1228 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001229
hassof390d2c2004-09-10 20:48:21 +00001230 /* iv */
1231 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1232 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1233 /* FIXME: v) */
1234 }
1235 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1236 else if (comp == LSP_EQUAL)
1237 {
1238 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassoa96d8d12005-09-16 14:44:23 +00001239 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001240 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1241 {
1242 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1243 }
1244 }
1245 /* 7.3.15.1 e) 3) LSP older than the one in db */
1246 else
1247 {
1248 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1249 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1250 }
jardineb5d44e2003-12-23 08:09:43 +00001251 }
jardineb5d44e2003-12-23 08:09:43 +00001252 if (lsp)
1253 lsp->adj = adj;
1254 return retval;
1255}
1256
1257/*
1258 * Process Sequence Numbers
1259 * ISO - 10589
1260 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1261 */
1262
hasso92365882005-01-18 13:53:33 +00001263static int
hassof390d2c2004-09-10 20:48:21 +00001264process_snp (int snp_type, int level, struct isis_circuit *circuit,
1265 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001266{
1267 int retval = ISIS_OK;
1268 int cmp, own_lsp;
1269 char typechar = ' ';
1270 int len;
1271 struct isis_adjacency *adj;
1272 struct isis_complete_seqnum_hdr *chdr = NULL;
1273 struct isis_partial_seqnum_hdr *phdr = NULL;
1274 uint32_t found = 0, expected = 0;
1275 struct isis_lsp *lsp;
1276 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001277 struct listnode *node, *nnode;
1278 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001279 struct tlvs tlvs;
1280 struct list *lsp_list = NULL;
1281 struct isis_passwd *passwd;
1282
hassof390d2c2004-09-10 20:48:21 +00001283 if (snp_type == ISIS_SNP_CSNP_FLAG)
1284 {
1285 /* getting the header info */
1286 typechar = 'C';
1287 chdr =
1288 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1289 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1290 len = ntohs (chdr->pdu_len);
1291 if (len < ISIS_CSNP_HDRLEN)
1292 {
1293 zlog_warn ("Received a CSNP with bogus length!");
1294 return ISIS_OK;
1295 }
jardineb5d44e2003-12-23 08:09:43 +00001296 }
hassof390d2c2004-09-10 20:48:21 +00001297 else
1298 {
1299 typechar = 'P';
1300 phdr =
1301 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1302 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1303 len = ntohs (phdr->pdu_len);
1304 if (len < ISIS_PSNP_HDRLEN)
1305 {
1306 zlog_warn ("Received a CSNP with bogus length!");
1307 return ISIS_OK;
1308 }
jardineb5d44e2003-12-23 08:09:43 +00001309 }
jardineb5d44e2003-12-23 08:09:43 +00001310
1311 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001312 if (circuit->ext_domain)
1313 {
jardineb5d44e2003-12-23 08:09:43 +00001314
hasso529d65b2004-12-24 00:14:50 +00001315 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1316 "skipping: circuit externalDomain = true",
1317 circuit->area->area_tag,
1318 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001319
1320 return ISIS_OK;
1321 }
hassof390d2c2004-09-10 20:48:21 +00001322
1323 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1324 if (!accept_level (level, circuit->circuit_is_type))
1325 {
1326
hasso529d65b2004-12-24 00:14:50 +00001327 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1328 "skipping: circuit type %s does not match level %d",
1329 circuit->area->area_tag,
1330 level,
1331 typechar,
1332 circuit->interface->name,
1333 circuit_t2string (circuit->circuit_is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001334
1335 return ISIS_OK;
1336 }
1337
1338 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1339 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1340 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1341 {
1342 if (!circuit->u.bc.is_dr[level - 1])
1343 {
1344
hasso529d65b2004-12-24 00:14:50 +00001345 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1346 "skipping: we are not the DIS",
1347 circuit->area->area_tag,
1348 level,
1349 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001350
1351 return ISIS_OK;
1352 }
1353 }
jardineb5d44e2003-12-23 08:09:43 +00001354
1355 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1356
1357 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1358 * - already checked */
1359
1360 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1361 /* for broadcast circuits, snpa should be compared */
1362 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001363 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1364 {
1365 if (snp_type == ISIS_SNP_CSNP_FLAG)
1366 {
1367 adj =
1368 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1369 }
1370 else
1371 {
1372 /* a psnp on a broadcast, how lovely of Juniper :) */
1373 adj =
1374 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1375 }
1376 if (!adj)
1377 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001378 }
hassof390d2c2004-09-10 20:48:21 +00001379 else
1380 {
1381 if (!circuit->u.p2p.neighbor)
1382 return ISIS_OK; /* Silently discard */
1383 }
jardineb5d44e2003-12-23 08:09:43 +00001384
1385 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1386
1387 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1388
1389 memset (&tlvs, 0, sizeof (struct tlvs));
1390
1391 /* parse the SNP */
1392 expected |= TLVFLAG_LSP_ENTRIES;
1393 expected |= TLVFLAG_AUTH_INFO;
1394 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001395 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001396 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001397 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001398
hassof390d2c2004-09-10 20:48:21 +00001399 if (retval > ISIS_WARNING)
1400 {
1401 zlog_warn ("something went very wrong processing SNP");
1402 free_tlvs (&tlvs);
1403 return retval;
1404 }
jardineb5d44e2003-12-23 08:09:43 +00001405
hasso1cbc5622005-01-01 10:29:51 +00001406 if (level == 1)
1407 passwd = &circuit->area->area_passwd;
1408 else
1409 passwd = &circuit->area->domain_passwd;
1410
1411 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001412 {
hasso1cbc5622005-01-01 10:29:51 +00001413 if (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00001414 {
hasso1cbc5622005-01-01 10:29:51 +00001415 if (!(found & TLVFLAG_AUTH_INFO) ||
1416 authentication_check (passwd, &tlvs.auth_info))
1417 {
1418 isis_event_auth_failure (circuit->area->area_tag,
1419 "SNP authentication" " failure",
1420 phdr ? phdr->source_id : chdr->source_id);
1421 return ISIS_OK;
1422 }
hassof390d2c2004-09-10 20:48:21 +00001423 }
1424 }
jardineb5d44e2003-12-23 08:09:43 +00001425
1426 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001427 if (isis->debugs & DEBUG_SNP_PACKETS)
1428 {
hasso529d65b2004-12-24 00:14:50 +00001429 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1430 circuit->area->area_tag,
1431 level,
1432 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001433 if (tlvs.lsp_entries)
1434 {
hasso3fdb2dd2005-09-28 18:45:54 +00001435 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001436 {
hasso529d65b2004-12-24 00:14:50 +00001437 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1438 " cksum 0x%04x, lifetime %us",
1439 circuit->area->area_tag,
1440 typechar,
1441 rawlspid_print (entry->lsp_id),
1442 ntohl (entry->seq_num),
1443 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001444 }
1445 }
jardineb5d44e2003-12-23 08:09:43 +00001446 }
jardineb5d44e2003-12-23 08:09:43 +00001447
1448 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001449 if (tlvs.lsp_entries)
1450 {
hasso3fdb2dd2005-09-28 18:45:54 +00001451 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001452 {
1453 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1454 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1455 if (lsp)
1456 {
1457 /* 7.3.15.2 b) 1) is this LSP newer */
1458 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1459 entry->checksum, entry->rem_lifetime);
1460 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1461 if (cmp == LSP_EQUAL)
1462 {
1463 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1464 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1465 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1466 }
1467 else if (cmp == LSP_OLDER)
1468 {
1469 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1470 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1471 }
1472 else
1473 {
1474 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1475 * on p2p */
1476 if (own_lsp)
1477 {
1478 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1479 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1480 }
1481 else
1482 {
1483 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1484 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1485 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1486 }
1487 }
1488 }
1489 else
1490 {
1491 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1492 * insert it and set SSN on it */
1493 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1494 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1495 {
1496 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1497 0, 0, entry->checksum, level);
1498 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1499 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1500 }
1501 }
jardineb5d44e2003-12-23 08:09:43 +00001502 }
1503 }
jardineb5d44e2003-12-23 08:09:43 +00001504
1505 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001506 if (snp_type == ISIS_SNP_CSNP_FLAG)
1507 {
1508 /*
1509 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1510 */
1511 lsp_list = list_new ();
1512 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1513 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001514
hassof390d2c2004-09-10 20:48:21 +00001515 /* Fixme: Find a better solution */
1516 if (tlvs.lsp_entries)
1517 {
paul1eb8ef22005-04-07 07:30:20 +00001518 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001519 {
paul1eb8ef22005-04-07 07:30:20 +00001520 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001521 {
1522 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1523 {
1524 list_delete_node (lsp_list, node2);
1525 break;
1526 }
1527 }
1528 }
1529 }
1530 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001531 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001532 {
1533 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001534 }
hassof390d2c2004-09-10 20:48:21 +00001535 /* lets free it */
1536 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001537 }
jardineb5d44e2003-12-23 08:09:43 +00001538
1539 free_tlvs (&tlvs);
1540 return retval;
1541}
1542
hasso92365882005-01-18 13:53:33 +00001543static int
hassof390d2c2004-09-10 20:48:21 +00001544process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001545{
jardineb5d44e2003-12-23 08:09:43 +00001546 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001547 if ((stream_get_endp (circuit->rcv_stream) -
1548 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1549 {
1550 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1551 return ISIS_WARNING;
1552 }
jardineb5d44e2003-12-23 08:09:43 +00001553
1554 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1555}
1556
hasso92365882005-01-18 13:53:33 +00001557static int
hassof390d2c2004-09-10 20:48:21 +00001558process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001559{
hassof390d2c2004-09-10 20:48:21 +00001560 if ((stream_get_endp (circuit->rcv_stream) -
1561 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1562 {
1563 zlog_warn ("Packet too short");
1564 return ISIS_WARNING;
1565 }
jardineb5d44e2003-12-23 08:09:43 +00001566
1567 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1568}
1569
jardineb5d44e2003-12-23 08:09:43 +00001570/*
1571 * Process ISH
1572 * ISO - 10589
1573 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1574 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001575 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1576 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1577 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001578 */
hasso92365882005-01-18 13:53:33 +00001579static int
jardineb5d44e2003-12-23 08:09:43 +00001580process_is_hello (struct isis_circuit *circuit)
1581{
1582 struct isis_adjacency *adj;
1583 int retval = ISIS_OK;
1584 u_char neigh_len;
1585 u_char *sysid;
1586
1587 /* In this point in time we are not yet able to handle is_hellos
1588 * on lan - Sorry juniper...
1589 */
1590 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1591 return retval;
1592
1593 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001594 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001595 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001596 if (!adj)
1597 {
1598 /* 8.2.2 */
hassof7c43dc2004-09-26 16:24:14 +00001599 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001600 if (adj == NULL)
1601 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001602
hassof390d2c2004-09-10 20:48:21 +00001603 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1604 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1605 circuit->u.p2p.neighbor = adj;
1606 }
1607 /* 8.2.2 a) */
1608 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1609 ISIS_SYS_ID_LEN))
1610 {
1611 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1612 /* 8.2.2 a) 2) delete the adj */
1613 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1614 /* 8.2.2 a) 3) create a new adj */
hassof7c43dc2004-09-26 16:24:14 +00001615 adj = isis_new_adj (sysid, (u_char *) " ", 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001616 if (adj == NULL)
1617 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001618
hassof390d2c2004-09-10 20:48:21 +00001619 /* 8.2.2 a) 3) i */
1620 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1621 /* 8.2.2 a) 3) ii */
1622 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1623 /* 8.2.2 a) 4) quite meaningless */
1624 }
jardineb5d44e2003-12-23 08:09:43 +00001625 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001626 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1627 (adj->sys_type == ISIS_SYSTYPE_IS))
1628 {
1629 /* do nothing */
1630 }
1631 else
1632 {
1633 /* 8.2.2 c) respond with a p2p IIH */
1634 send_hello (circuit, 1);
1635 }
jardineb5d44e2003-12-23 08:09:43 +00001636 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001637 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001638 /* 8.2.2 e) FIXME: Circuit type of? */
1639
jardineb5d44e2003-12-23 08:09:43 +00001640 return retval;
1641}
1642
jardineb5d44e2003-12-23 08:09:43 +00001643/*
1644 * PDU Dispatcher
1645 */
1646
hasso92365882005-01-18 13:53:33 +00001647static int
hassof390d2c2004-09-10 20:48:21 +00001648isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001649{
jardineb5d44e2003-12-23 08:09:43 +00001650 struct isis_fixed_hdr *hdr;
1651 struct esis_fixed_hdr *esis_hdr;
1652
hassof390d2c2004-09-10 20:48:21 +00001653 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001654
1655 /*
1656 * Let's first read data from stream to the header
1657 */
hassof390d2c2004-09-10 20:48:21 +00001658 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001659
hassof390d2c2004-09-10 20:48:21 +00001660 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1661 {
1662 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1663 return ISIS_ERROR;
1664 }
jardineb5d44e2003-12-23 08:09:43 +00001665
1666 /* now we need to know if this is an ISO 9542 packet and
1667 * take real good care of it, waaa!
1668 */
hassof390d2c2004-09-10 20:48:21 +00001669 if (hdr->idrp == ISO9542_ESIS)
1670 {
1671 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1672 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1673 /* FIXME: Need to do some acceptence tests */
1674 /* example length... */
1675 switch (esis_hdr->pdu_type)
1676 {
1677 case ESH_PDU:
1678 /* FIXME */
1679 break;
1680 case ISH_PDU:
hasso529d65b2004-12-24 00:14:50 +00001681 zlog_debug ("AN ISH PDU!!");
hassof390d2c2004-09-10 20:48:21 +00001682 retval = process_is_hello (circuit);
1683 break;
1684 default:
1685 return ISIS_ERROR;
1686 }
1687 return retval;
1688 }
1689 else
1690 {
1691 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1692 }
jardineb5d44e2003-12-23 08:09:43 +00001693 /*
1694 * and then process it
1695 */
1696
hassof390d2c2004-09-10 20:48:21 +00001697 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1698 {
1699 zlog_err ("Fixed header length = %d", hdr->length);
1700 return ISIS_ERROR;
1701 }
jardineb5d44e2003-12-23 08:09:43 +00001702
hassof390d2c2004-09-10 20:48:21 +00001703 if (hdr->version1 != 1)
1704 {
1705 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1706 return ISIS_WARNING;
1707 }
jardineb5d44e2003-12-23 08:09:43 +00001708 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001709 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1710 {
1711 zlog_err
1712 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1713 "while the parameter for this IS is %u", hdr->id_len,
1714 ISIS_SYS_ID_LEN);
1715 return ISIS_ERROR;
1716 }
jardineb5d44e2003-12-23 08:09:43 +00001717
hassof390d2c2004-09-10 20:48:21 +00001718 if (hdr->version2 != 1)
1719 {
1720 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1721 return ISIS_WARNING;
1722 }
jardineb5d44e2003-12-23 08:09:43 +00001723 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001724 if ((hdr->max_area_addrs != 0)
1725 && (hdr->max_area_addrs != isis->max_area_addrs))
1726 {
1727 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1728 "received PDU %u while the parameter for this IS is %u",
1729 hdr->max_area_addrs, isis->max_area_addrs);
1730 return ISIS_ERROR;
1731 }
jardineb5d44e2003-12-23 08:09:43 +00001732
hassof390d2c2004-09-10 20:48:21 +00001733 switch (hdr->pdu_type)
1734 {
1735 case L1_LAN_HELLO:
1736 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1737 break;
1738 case L2_LAN_HELLO:
1739 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1740 break;
1741 case P2P_HELLO:
1742 retval = process_p2p_hello (circuit);
1743 break;
1744 case L1_LINK_STATE:
1745 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1746 break;
1747 case L2_LINK_STATE:
1748 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1749 break;
1750 case L1_COMPLETE_SEQ_NUM:
1751 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1752 break;
1753 case L2_COMPLETE_SEQ_NUM:
1754 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1755 break;
1756 case L1_PARTIAL_SEQ_NUM:
1757 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1758 break;
1759 case L2_PARTIAL_SEQ_NUM:
1760 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1761 break;
1762 default:
1763 return ISIS_ERROR;
1764 }
jardineb5d44e2003-12-23 08:09:43 +00001765
1766 return retval;
1767}
1768
jardineb5d44e2003-12-23 08:09:43 +00001769#ifdef GNU_LINUX
1770int
1771isis_receive (struct thread *thread)
1772{
jardineb5d44e2003-12-23 08:09:43 +00001773 struct isis_circuit *circuit;
1774 u_char ssnpa[ETH_ALEN];
1775 int retval;
1776
1777 /*
1778 * Get the circuit
1779 */
1780 circuit = THREAD_ARG (thread);
1781 assert (circuit);
1782
1783 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001784 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001785 else
1786 stream_reset (circuit->rcv_stream);
1787
1788 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001789 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001790
1791 if (retval == ISIS_OK)
1792 retval = isis_handle_pdu (circuit, ssnpa);
1793
1794 /*
1795 * prepare for next packet.
1796 */
hassof390d2c2004-09-10 20:48:21 +00001797 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1798 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001799
1800 return retval;
1801}
1802
1803#else
1804int
1805isis_receive (struct thread *thread)
1806{
jardineb5d44e2003-12-23 08:09:43 +00001807 struct isis_circuit *circuit;
1808 u_char ssnpa[ETH_ALEN];
1809 int retval;
1810
1811 /*
1812 * Get the circuit
1813 */
1814 circuit = THREAD_ARG (thread);
1815 assert (circuit);
1816
hassof390d2c2004-09-10 20:48:21 +00001817 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001818
1819 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001820 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001821 else
1822 stream_reset (circuit->rcv_stream);
1823
1824 retval = circuit->rx (circuit, ssnpa);
1825
1826 if (retval == ISIS_OK)
1827 retval = isis_handle_pdu (circuit, ssnpa);
1828
1829 /*
1830 * prepare for next packet.
1831 */
hassof390d2c2004-09-10 20:48:21 +00001832 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1833 listcount
1834 (circuit->area->circuit_list) *
1835 100);
jardineb5d44e2003-12-23 08:09:43 +00001836
1837 return retval;
1838}
1839
1840#endif
1841
1842 /* filling of the fixed isis header */
1843void
1844fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1845{
1846 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1847
1848 hdr->idrp = ISO10589_ISIS;
1849
hassof390d2c2004-09-10 20:48:21 +00001850 switch (pdu_type)
1851 {
1852 case L1_LAN_HELLO:
1853 case L2_LAN_HELLO:
1854 hdr->length = ISIS_LANHELLO_HDRLEN;
1855 break;
1856 case P2P_HELLO:
1857 hdr->length = ISIS_P2PHELLO_HDRLEN;
1858 break;
1859 case L1_LINK_STATE:
1860 case L2_LINK_STATE:
1861 hdr->length = ISIS_LSP_HDR_LEN;
1862 break;
1863 case L1_COMPLETE_SEQ_NUM:
1864 case L2_COMPLETE_SEQ_NUM:
1865 hdr->length = ISIS_CSNP_HDRLEN;
1866 break;
1867 case L1_PARTIAL_SEQ_NUM:
1868 case L2_PARTIAL_SEQ_NUM:
1869 hdr->length = ISIS_PSNP_HDRLEN;
1870 break;
1871 default:
1872 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1873 return;
1874 }
jardineb5d44e2003-12-23 08:09:43 +00001875 hdr->length += ISIS_FIXED_HDR_LEN;
1876 hdr->pdu_type = pdu_type;
1877 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001878 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001879 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001880 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001881}
1882
jardineb5d44e2003-12-23 08:09:43 +00001883/*
1884 * SEND SIDE
1885 */
hasso92365882005-01-18 13:53:33 +00001886static void
jardineb5d44e2003-12-23 08:09:43 +00001887fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001888 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001889{
hassof390d2c2004-09-10 20:48:21 +00001890 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001891
1892 stream_putc (stream, hdr->idrp);
1893 stream_putc (stream, hdr->length);
1894 stream_putc (stream, hdr->version1);
1895 stream_putc (stream, hdr->id_len);
1896 stream_putc (stream, hdr->pdu_type);
1897 stream_putc (stream, hdr->version2);
1898 stream_putc (stream, hdr->reserved);
1899 stream_putc (stream, hdr->max_area_addrs);
1900
1901 return;
1902}
1903
jardineb5d44e2003-12-23 08:09:43 +00001904int
1905send_hello (struct isis_circuit *circuit, int level)
1906{
1907 struct isis_fixed_hdr fixed_hdr;
1908 struct isis_lan_hello_hdr hello_hdr;
1909 struct isis_p2p_hello_hdr p2p_hello_hdr;
1910
1911 u_int32_t interval;
1912 unsigned long len_pointer, length;
1913 int retval;
1914
hassof390d2c2004-09-10 20:48:21 +00001915 if (circuit->interface->mtu == 0)
1916 {
1917 zlog_warn ("circuit has zero MTU");
1918 return ISIS_WARNING;
1919 }
jardineb5d44e2003-12-23 08:09:43 +00001920
1921 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001922 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001923 else
1924 stream_reset (circuit->snd_stream);
1925
1926 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1927 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001928 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1929 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001930 else
hassof390d2c2004-09-10 20:48:21 +00001931 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1932 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001933 else
hassof390d2c2004-09-10 20:48:21 +00001934 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001935
1936 /*
1937 * Fill LAN Level 1 or 2 Hello PDU header
1938 */
1939 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001940 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001941 circuit->hello_interval[level - 1];
1942 if (interval > USHRT_MAX)
1943 interval = USHRT_MAX;
1944 hello_hdr.circuit_t = circuit->circuit_is_type;
1945 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001946 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001947
hassof390d2c2004-09-10 20:48:21 +00001948 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00001949 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001950
1951 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001952 if (circuit->circ_type == CIRCUIT_T_P2P)
1953 {
1954 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1955 p2p_hello_hdr.local_id = circuit->circuit_id;
1956 /* FIXME: need better understanding */
1957 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001958 }
hassof390d2c2004-09-10 20:48:21 +00001959 else
1960 {
1961 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1962 if (level == 1 && circuit->u.bc.l1_desig_is)
1963 {
1964 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1965 ISIS_SYS_ID_LEN + 1);
1966 }
1967 else if (level == 2 && circuit->u.bc.l2_desig_is)
1968 {
1969 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1970 ISIS_SYS_ID_LEN + 1);
1971 }
1972 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1973 }
jardineb5d44e2003-12-23 08:09:43 +00001974
1975 /*
1976 * Then the variable length part
1977 */
1978 /* add circuit password */
1979 if (circuit->passwd.type)
1980 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1981 circuit->passwd.passwd, circuit->snd_stream))
1982 return ISIS_WARNING;
1983 /* Area Addresses TLV */
1984 assert (circuit->area);
1985 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
1986 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
1987 return ISIS_WARNING;
1988
1989 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00001990 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1991 {
1992 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
1993 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
1994 circuit->snd_stream))
1995 return ISIS_WARNING;
1996 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
1997 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
1998 circuit->snd_stream))
1999 return ISIS_WARNING;
2000 }
jardineb5d44e2003-12-23 08:09:43 +00002001
2002 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002003 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002004 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2005 return ISIS_WARNING;
2006 /* IP interface Address TLV */
2007 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2008 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2009 return ISIS_WARNING;
2010
hassof390d2c2004-09-10 20:48:21 +00002011#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002012 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002013 if (circuit->ipv6_router && circuit->ipv6_link &&
jardineb5d44e2003-12-23 08:09:43 +00002014 circuit->ipv6_link->count > 0)
2015 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2016 return ISIS_WARNING;
2017#endif /* HAVE_IPV6 */
2018
2019 if (circuit->u.bc.pad_hellos)
2020 if (tlv_add_padding (circuit->snd_stream))
2021 return ISIS_WARNING;
2022
paul9985f832005-02-09 15:51:56 +00002023 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002024 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002025 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002026
2027 retval = circuit->tx (circuit, level);
2028 if (retval)
2029 zlog_warn ("sending of LAN Level %d Hello failed", level);
2030
2031 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002032 if (isis->debugs & DEBUG_ADJ_PACKETS)
2033 {
2034 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2035 {
hasso529d65b2004-12-24 00:14:50 +00002036 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2037 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002038 /* FIXME: use %z when we stop supporting old compilers. */
2039 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002040 }
2041 else
2042 {
hasso529d65b2004-12-24 00:14:50 +00002043 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2044 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002045 /* FIXME: use %z when we stop supporting old compilers. */
2046 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002047 }
jardineb5d44e2003-12-23 08:09:43 +00002048 }
jardineb5d44e2003-12-23 08:09:43 +00002049
2050 return retval;
2051}
2052
hasso92365882005-01-18 13:53:33 +00002053static int
jardineb5d44e2003-12-23 08:09:43 +00002054send_lan_hello (struct isis_circuit *circuit, int level)
2055{
hassof390d2c2004-09-10 20:48:21 +00002056 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002057}
2058
2059int
2060send_lan_l1_hello (struct thread *thread)
2061{
jardineb5d44e2003-12-23 08:09:43 +00002062 struct isis_circuit *circuit;
2063 int retval;
2064
2065 circuit = THREAD_ARG (thread);
2066 assert (circuit);
2067 circuit->u.bc.t_send_lan_hello[0] = NULL;
2068
2069 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002070 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002071
2072 retval = send_lan_hello (circuit, 1);
2073
2074 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002075 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2076 send_lan_l1_hello, circuit,
2077 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002078
2079 return retval;
2080}
2081
2082int
2083send_lan_l2_hello (struct thread *thread)
2084{
2085 struct isis_circuit *circuit;
2086 int retval;
2087
2088 circuit = THREAD_ARG (thread);
2089 assert (circuit);
2090 circuit->u.bc.t_send_lan_hello[1] = NULL;
2091
2092 if (circuit->u.bc.run_dr_elect[1])
2093 retval = isis_dr_elect (circuit, 2);
2094
2095 retval = send_lan_hello (circuit, 2);
2096
hassof390d2c2004-09-10 20:48:21 +00002097 /* set next timer thread */
2098 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2099 send_lan_l2_hello, circuit,
2100 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002101
2102 return retval;
2103}
2104
2105int
2106send_p2p_hello (struct thread *thread)
2107{
2108 struct isis_circuit *circuit;
2109
2110 circuit = THREAD_ARG (thread);
2111 assert (circuit);
2112 circuit->u.p2p.t_send_p2p_hello = NULL;
2113
hassof390d2c2004-09-10 20:48:21 +00002114 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002115
hassof390d2c2004-09-10 20:48:21 +00002116 /* set next timer thread */
2117 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2118 circuit, isis_jitter (circuit->hello_interval[1],
2119 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002120
2121 return ISIS_OK;
2122}
2123
hasso92365882005-01-18 13:53:33 +00002124static int
hassof390d2c2004-09-10 20:48:21 +00002125build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2126 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002127{
2128 struct isis_fixed_hdr fixed_hdr;
2129 struct isis_passwd *passwd;
2130 int retval = ISIS_OK;
2131 unsigned long lenp;
2132 u_int16_t length;
2133
hassof390d2c2004-09-10 20:48:21 +00002134 if (level == 1)
2135 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2136 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002137 else
hassof390d2c2004-09-10 20:48:21 +00002138 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2139 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002140
2141 /*
2142 * Fill Level 1 or 2 Complete Sequence Numbers header
2143 */
2144
paul9985f832005-02-09 15:51:56 +00002145 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002146 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002147 /* no need to send the source here, it is always us if we csnp */
2148 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2149 /* with zero circuit id - ref 9.10, 9.11 */
2150 stream_putc (circuit->snd_stream, 0x00);
2151
2152 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2153 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2154
2155 /*
2156 * And TLVs
2157 */
2158 if (level == 1)
2159 passwd = &circuit->area->area_passwd;
2160 else
2161 passwd = &circuit->area->domain_passwd;
2162
hasso1cbc5622005-01-01 10:29:51 +00002163 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2164 if (passwd->type)
2165 retval = tlv_add_authinfo (passwd->type, passwd->len,
2166 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002167
hassof390d2c2004-09-10 20:48:21 +00002168 if (!retval && lsps)
2169 {
2170 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2171 }
paul9985f832005-02-09 15:51:56 +00002172 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002173 assert (length >= ISIS_CSNP_HDRLEN);
2174 /* Update PU length */
2175 stream_putw_at (circuit->snd_stream, lenp, length);
2176
2177 return retval;
2178}
2179
2180/*
2181 * FIXME: support multiple CSNPs
2182 */
2183
2184int
2185send_csnp (struct isis_circuit *circuit, int level)
2186{
2187 int retval = ISIS_OK;
2188 u_char start[ISIS_SYS_ID_LEN + 2];
2189 u_char stop[ISIS_SYS_ID_LEN + 2];
2190 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002191 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002192 struct isis_lsp *lsp;
2193
hassof390d2c2004-09-10 20:48:21 +00002194 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002195 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2196
hassof390d2c2004-09-10 20:48:21 +00002197 if (circuit->area->lspdb[level - 1] &&
2198 dict_count (circuit->area->lspdb[level - 1]) > 0)
2199 {
2200 list = list_new ();
2201 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002202
hassof390d2c2004-09-10 20:48:21 +00002203 if (circuit->snd_stream == NULL)
2204 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2205 else
2206 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002207
hassof390d2c2004-09-10 20:48:21 +00002208 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002209
hassof390d2c2004-09-10 20:48:21 +00002210 if (isis->debugs & DEBUG_SNP_PACKETS)
2211 {
hasso529d65b2004-12-24 00:14:50 +00002212 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
paul1eb8ef22005-04-07 07:30:20 +00002213 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002214 /* FIXME: use %z when we stop supporting old compilers. */
2215 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hasso3fdb2dd2005-09-28 18:45:54 +00002216 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002217 {
hasso529d65b2004-12-24 00:14:50 +00002218 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2219 " cksum 0x%04x, lifetime %us",
2220 circuit->area->area_tag,
2221 rawlspid_print (lsp->lsp_header->lsp_id),
2222 ntohl (lsp->lsp_header->seq_num),
2223 ntohs (lsp->lsp_header->checksum),
2224 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002225 }
2226 }
2227
2228 list_delete (list);
2229
2230 if (retval == ISIS_OK)
2231 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002232 }
jardineb5d44e2003-12-23 08:09:43 +00002233 return retval;
2234}
2235
2236int
2237send_l1_csnp (struct thread *thread)
2238{
2239 struct isis_circuit *circuit;
2240 int retval = ISIS_OK;
2241
2242 circuit = THREAD_ARG (thread);
2243 assert (circuit);
2244
2245 circuit->t_send_csnp[0] = NULL;
2246
hassof390d2c2004-09-10 20:48:21 +00002247 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2248 {
2249 send_csnp (circuit, 1);
2250 }
jardineb5d44e2003-12-23 08:09:43 +00002251 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002252 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2253 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002254
2255 return retval;
2256}
2257
2258int
2259send_l2_csnp (struct thread *thread)
2260{
2261 struct isis_circuit *circuit;
2262 int retval = ISIS_OK;
2263
2264 circuit = THREAD_ARG (thread);
2265 assert (circuit);
2266
2267 circuit->t_send_csnp[1] = NULL;
2268
hassof390d2c2004-09-10 20:48:21 +00002269 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2270 {
2271 send_csnp (circuit, 2);
2272 }
jardineb5d44e2003-12-23 08:09:43 +00002273 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002274 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2275 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002276
jardineb5d44e2003-12-23 08:09:43 +00002277 return retval;
2278}
2279
hasso92365882005-01-18 13:53:33 +00002280static int
jardineb5d44e2003-12-23 08:09:43 +00002281build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2282{
2283 struct isis_fixed_hdr fixed_hdr;
2284 unsigned long lenp;
2285 u_int16_t length;
2286 int retval = 0;
2287 struct isis_lsp *lsp;
2288 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002289 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002292 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2293 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002294 else
2295 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002296 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002297
2298 /*
2299 * Fill Level 1 or 2 Partial Sequence Numbers header
2300 */
paul9985f832005-02-09 15:51:56 +00002301 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002302 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002303 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2304 stream_putc (circuit->snd_stream, circuit->idx);
2305
2306 /*
2307 * And TLVs
2308 */
2309
2310 if (level == 1)
2311 passwd = &circuit->area->area_passwd;
2312 else
2313 passwd = &circuit->area->domain_passwd;
2314
hasso1cbc5622005-01-01 10:29:51 +00002315 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2316 if (passwd->type)
2317 retval = tlv_add_authinfo (passwd->type, passwd->len,
2318 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002319
hassof390d2c2004-09-10 20:48:21 +00002320 if (!retval && lsps)
2321 {
2322 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002323 }
jardineb5d44e2003-12-23 08:09:43 +00002324
hassof390d2c2004-09-10 20:48:21 +00002325 if (isis->debugs & DEBUG_SNP_PACKETS)
2326 {
hasso3fdb2dd2005-09-28 18:45:54 +00002327 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002328 {
hasso529d65b2004-12-24 00:14:50 +00002329 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2330 " cksum 0x%04x, lifetime %us",
2331 circuit->area->area_tag,
2332 rawlspid_print (lsp->lsp_header->lsp_id),
2333 ntohl (lsp->lsp_header->seq_num),
2334 ntohs (lsp->lsp_header->checksum),
2335 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002336 }
2337 }
2338
paul9985f832005-02-09 15:51:56 +00002339 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002340 assert (length >= ISIS_PSNP_HDRLEN);
2341 /* Update PDU length */
2342 stream_putw_at (circuit->snd_stream, lenp, length);
2343
2344 return ISIS_OK;
2345}
2346
2347/*
2348 * 7.3.15.4 action on expiration of partial SNP interval
2349 * level 1
2350 */
hasso92365882005-01-18 13:53:33 +00002351static int
jardineb5d44e2003-12-23 08:09:43 +00002352send_psnp (int level, struct isis_circuit *circuit)
2353{
2354 int retval = ISIS_OK;
2355 struct isis_lsp *lsp;
2356 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002357 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002358
hassof390d2c2004-09-10 20:48:21 +00002359 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002360 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002361 circuit->circ_type != CIRCUIT_T_BROADCAST)
2362 {
jardineb5d44e2003-12-23 08:09:43 +00002363
hassof390d2c2004-09-10 20:48:21 +00002364 if (circuit->area->lspdb[level - 1] &&
2365 dict_count (circuit->area->lspdb[level - 1]) > 0)
2366 {
2367 list = list_new ();
2368 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002369
hassof390d2c2004-09-10 20:48:21 +00002370 if (listcount (list) > 0)
2371 {
2372 if (circuit->snd_stream == NULL)
2373 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2374 else
2375 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002376
2377
hassof390d2c2004-09-10 20:48:21 +00002378 if (isis->debugs & DEBUG_SNP_PACKETS)
hasso529d65b2004-12-24 00:14:50 +00002379 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2380 circuit->area->area_tag, level,
2381 circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002382 /* FIXME: use %z when we stop supporting old
2383 * compilers. */
2384 (unsigned long) STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002385
hassof390d2c2004-09-10 20:48:21 +00002386 retval = build_psnp (level, circuit, list);
2387 if (retval == ISIS_OK)
2388 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002389
hassof390d2c2004-09-10 20:48:21 +00002390 if (retval == ISIS_OK)
2391 {
2392 /*
2393 * sending succeeded, we can clear SSN flags of this circuit
2394 * for the LSPs in list
2395 */
hasso3fdb2dd2005-09-28 18:45:54 +00002396 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +00002397 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002398 }
2399 }
2400 list_delete (list);
2401 }
jardineb5d44e2003-12-23 08:09:43 +00002402 }
jardineb5d44e2003-12-23 08:09:43 +00002403
2404 return retval;
2405}
2406
2407int
2408send_l1_psnp (struct thread *thread)
2409{
2410
2411 struct isis_circuit *circuit;
2412 int retval = ISIS_OK;
2413
2414 circuit = THREAD_ARG (thread);
2415 assert (circuit);
2416
2417 circuit->t_send_psnp[0] = NULL;
2418
2419 send_psnp (1, circuit);
2420 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002421 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2422 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002423
2424 return retval;
2425}
2426
2427/*
2428 * 7.3.15.4 action on expiration of partial SNP interval
2429 * level 2
2430 */
2431int
2432send_l2_psnp (struct thread *thread)
2433{
jardineb5d44e2003-12-23 08:09:43 +00002434 struct isis_circuit *circuit;
2435 int retval = ISIS_OK;
2436
2437 circuit = THREAD_ARG (thread);
2438 assert (circuit);
2439
2440 circuit->t_send_psnp[1] = NULL;
2441
2442 send_psnp (2, circuit);
2443
2444 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002445 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2446 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002447
2448 return retval;
2449}
2450
jardineb5d44e2003-12-23 08:09:43 +00002451/*
2452 * ISO 10589 - 7.3.14.3
2453 */
2454int
2455send_lsp (struct thread *thread)
2456{
2457 struct isis_circuit *circuit;
2458 struct isis_lsp *lsp;
2459 struct listnode *node;
2460 int retval = 0;
2461
2462 circuit = THREAD_ARG (thread);
2463 assert (circuit);
2464
hassof390d2c2004-09-10 20:48:21 +00002465 if (circuit->state == C_STATE_UP)
2466 {
paul1eb8ef22005-04-07 07:30:20 +00002467 lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
jardineb5d44e2003-12-23 08:09:43 +00002468
2469 /*
hassof390d2c2004-09-10 20:48:21 +00002470 * Do not send if levels do not match
jardineb5d44e2003-12-23 08:09:43 +00002471 */
hassof390d2c2004-09-10 20:48:21 +00002472 if (!(lsp->level & circuit->circuit_is_type))
2473 goto dontsend;
jardineb5d44e2003-12-23 08:09:43 +00002474
hassof390d2c2004-09-10 20:48:21 +00002475 /*
2476 * Do not send if we do not have adjacencies in state up on the circuit
2477 */
2478 if (circuit->upadjcount[lsp->level - 1] == 0)
2479 goto dontsend;
2480 /* only send if it needs sending */
2481 if ((time (NULL) - lsp->last_sent) >=
2482 circuit->area->lsp_gen_interval[lsp->level - 1])
2483 {
jardineb5d44e2003-12-23 08:09:43 +00002484
hassof390d2c2004-09-10 20:48:21 +00002485 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2486 {
hasso529d65b2004-12-24 00:14:50 +00002487 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00002488 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2489 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2490 rawlspid_print (lsp->lsp_header->lsp_id),
2491 ntohl (lsp->lsp_header->seq_num),
2492 ntohs (lsp->lsp_header->checksum),
2493 ntohs (lsp->lsp_header->rem_lifetime),
2494 circuit->interface->name);
2495 }
2496 /* copy our lsp to the send buffer */
paul15935e92005-05-03 09:27:23 +00002497 stream_copy (circuit->snd_stream, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00002498
2499 retval = circuit->tx (circuit, lsp->level);
2500
jardineb5d44e2003-12-23 08:09:43 +00002501 /*
hassof390d2c2004-09-10 20:48:21 +00002502 * If the sending succeeded, we can del the lsp from circuits
2503 * lsp_queue
jardineb5d44e2003-12-23 08:09:43 +00002504 */
hassof390d2c2004-09-10 20:48:21 +00002505 if (retval == ISIS_OK)
2506 {
2507 list_delete_node (circuit->lsp_queue, node);
2508
2509 /*
2510 * On broadcast circuits also the SRMflag can be cleared
2511 */
2512 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2513 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
2514
2515 if (flags_any_set (lsp->SRMflags) == 0)
2516 {
2517 /*
2518 * need to remember when we were last sent
2519 */
2520 lsp->last_sent = time (NULL);
2521 }
2522 }
2523 else
2524 {
hasso529d65b2004-12-24 00:14:50 +00002525 zlog_debug ("sending of level %d link state failed", lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002526 }
jardineb5d44e2003-12-23 08:09:43 +00002527 }
hassof390d2c2004-09-10 20:48:21 +00002528 else
2529 {
2530 /* my belief is that if it wasn't his time, the lsp can be removed
2531 * from the queue
2532 */
2533 dontsend:
2534 list_delete_node (circuit->lsp_queue, node);
2535 }
jardineb5d44e2003-12-23 08:09:43 +00002536#if 0
hassof390d2c2004-09-10 20:48:21 +00002537 /*
2538 * If there are still LSPs send next one after lsp-interval (33 msecs)
2539 */
2540 if (listcount (circuit->lsp_queue) > 0)
2541 thread_add_timer (master, send_lsp, circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002542#endif
hassof390d2c2004-09-10 20:48:21 +00002543 }
jardineb5d44e2003-12-23 08:09:43 +00002544
2545 return retval;
hassof390d2c2004-09-10 20:48:21 +00002546}
jardineb5d44e2003-12-23 08:09:43 +00002547
2548int
hassof390d2c2004-09-10 20:48:21 +00002549ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2550 int level)
jardineb5d44e2003-12-23 08:09:43 +00002551{
2552 unsigned long lenp;
2553 int retval;
2554 u_int16_t length;
2555 struct isis_fixed_hdr fixed_hdr;
2556
2557 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002558 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002559 else
2560 stream_reset (circuit->snd_stream);
2561
2562// fill_llc_hdr (stream);
2563 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002564 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2565 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002566 else
hassof390d2c2004-09-10 20:48:21 +00002567 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2568 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002569
2570
paul9985f832005-02-09 15:51:56 +00002571 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002572 stream_putw (circuit->snd_stream, 0); /* PDU length */
2573 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002574 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002575 stream_putc (circuit->snd_stream, 9); /* code */
2576 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002577
hassof390d2c2004-09-10 20:48:21 +00002578 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2579 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2580 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2581 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002582
paul9985f832005-02-09 15:51:56 +00002583 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002584 /* Update PDU length */
2585 stream_putw_at (circuit->snd_stream, lenp, length);
2586
2587 retval = circuit->tx (circuit, level);
2588
2589 return retval;
2590}
2591