blob: dfc613cf2e4b30920eb64c608e67227824bafb14 [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"
Peter Szilagyi306ca832011-09-13 17:37:06 +040032#include "hash.h"
jardineb5d44e2003-12-23 08:09:43 +000033#include "prefix.h"
34#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010035#include "checksum.h"
jardineb5d44e2003-12-23 08:09:43 +000036
37#include "isisd/dict.h"
38#include "isisd/include-netbsd/iso.h"
39#include "isisd/isis_constants.h"
40#include "isisd/isis_common.h"
41#include "isisd/isis_adjacency.h"
42#include "isisd/isis_circuit.h"
43#include "isisd/isis_network.h"
44#include "isisd/isis_misc.h"
45#include "isisd/isis_dr.h"
46#include "isisd/isis_flags.h"
47#include "isisd/isis_tlv.h"
48#include "isisd/isisd.h"
49#include "isisd/isis_dynhn.h"
50#include "isisd/isis_lsp.h"
51#include "isisd/isis_pdu.h"
52#include "isisd/iso_checksum.h"
53#include "isisd/isis_csm.h"
54#include "isisd/isis_events.h"
55
56extern struct thread_master *master;
57extern struct isis *isis;
58
59#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000060#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000061
62#ifndef PNBBY
63#define PNBBY 8
64#endif /* PNBBY */
65
66/* Utility mask array. */
Stephen Hemminger2d362d12009-12-21 12:54:58 +030067static const u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000068 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
69};
70
71/*
72 * HELPER FUNCS
73 */
74
75/*
76 * Compares two sets of area addresses
77 */
hassof390d2c2004-09-10 20:48:21 +000078static int
jardineb5d44e2003-12-23 08:09:43 +000079area_match (struct list *left, struct list *right)
80{
81 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000082 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000083
hasso3fdb2dd2005-09-28 18:45:54 +000084 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000085 {
hasso3fdb2dd2005-09-28 18:45:54 +000086 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000087 {
88 if (addr1->addr_len == addr2->addr_len &&
89 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
90 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000091 }
92 }
93
hassof390d2c2004-09-10 20:48:21 +000094 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000095}
96
97/*
98 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
99 * param ip1 the IS interface ip address structure
100 * param ip2 the IIH's ip address
101 * return 0 the IIH's IP is not in the IS's subnetwork
102 * 1 the IIH's IP is in the IS's subnetwork
103 */
hasso92365882005-01-18 13:53:33 +0000104static int
hassof390d2c2004-09-10 20:48:21 +0000105ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000106{
107 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000108 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000109 int len;
hassof390d2c2004-09-10 20:48:21 +0000110
111 addr1 = (u_char *) & ip1->prefix.s_addr;
112 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000113 len = ip1->prefixlen;
114
115 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000116 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000117
hasso53c997c2004-09-15 16:21:59 +0000118 while (offsetloop--)
119 if (addr1[offsetloop] != addr2[offsetloop])
120 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000121
hassof390d2c2004-09-10 20:48:21 +0000122 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000123 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
124 return 0;
hassof390d2c2004-09-10 20:48:21 +0000125
126 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000127}
128
jardineb5d44e2003-12-23 08:09:43 +0000129/*
130 * Compares two set of ip addresses
131 * param left the local interface's ip addresses
132 * param right the iih interface's ip address
133 * return 0 no match;
134 * 1 match;
135 */
hassof390d2c2004-09-10 20:48:21 +0000136static int
jardineb5d44e2003-12-23 08:09:43 +0000137ip_match (struct list *left, struct list *right)
138{
139 struct prefix_ipv4 *ip1;
140 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000141 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000142
hassoe082ac12004-09-27 18:13:57 +0000143 if ((left == NULL) || (right == NULL))
144 return 0;
145
hasso3fdb2dd2005-09-28 18:45:54 +0000146 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000147 {
hasso3fdb2dd2005-09-28 18:45:54 +0000148 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000149 {
150 if (ip_same_subnet (ip1, ip2))
151 {
152 return 1; /* match */
153 }
jardineb5d44e2003-12-23 08:09:43 +0000154 }
hassof390d2c2004-09-10 20:48:21 +0000155
jardineb5d44e2003-12-23 08:09:43 +0000156 }
157 return 0;
158}
159
160/*
161 * Checks whether we should accept a PDU of given level
162 */
163static int
164accept_level (int level, int circuit_t)
165{
hassof390d2c2004-09-10 20:48:21 +0000166 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000167
168 return retval;
169}
170
hassof390d2c2004-09-10 20:48:21 +0000171int
jardineb5d44e2003-12-23 08:09:43 +0000172authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
173{
hassof390d2c2004-09-10 20:48:21 +0000174 if (one->type != theother->type)
175 {
176 zlog_warn ("Unsupported authentication type %d", theother->type);
177 return 1; /* Auth fail (different authentication types) */
178 }
179 switch (one->type)
180 {
181 case ISIS_PASSWD_TYPE_CLEARTXT:
182 if (one->len != theother->len)
183 return 1; /* Auth fail () - passwd len mismatch */
184 return memcmp (one->passwd, theother->passwd, one->len);
185 break;
186 default:
187 zlog_warn ("Unsupported authentication type");
188 break;
189 }
190 return 0; /* Auth pass */
jardineb5d44e2003-12-23 08:09:43 +0000191}
192
193/*
194 * Processing helper functions
195 */
hasso92365882005-01-18 13:53:33 +0000196static void
hassof390d2c2004-09-10 20:48:21 +0000197tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000198{
199 int i;
200 struct nlpids *tlv_nlpids;
201
hassof390d2c2004-09-10 20:48:21 +0000202 if (tlvs->nlpids)
203 {
jardineb5d44e2003-12-23 08:09:43 +0000204
hassof390d2c2004-09-10 20:48:21 +0000205 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000206
hassof390d2c2004-09-10 20:48:21 +0000207 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000208
hassof390d2c2004-09-10 20:48:21 +0000209 for (i = 0; i < tlv_nlpids->count; i++)
210 {
211 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
212 }
jardineb5d44e2003-12-23 08:09:43 +0000213 }
jardineb5d44e2003-12-23 08:09:43 +0000214}
215
hasso92365882005-01-18 13:53:33 +0000216static void
jardineb5d44e2003-12-23 08:09:43 +0000217del_ip_addr (void *val)
218{
219 XFREE (MTYPE_ISIS_TMP, val);
220}
221
hasso92365882005-01-18 13:53:33 +0000222static void
hassof390d2c2004-09-10 20:48:21 +0000223tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000224{
hasso3fdb2dd2005-09-28 18:45:54 +0000225 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000226 struct in_addr *ipv4_addr, *malloced;
227
hassof390d2c2004-09-10 20:48:21 +0000228 if (adj->ipv4_addrs)
229 {
230 adj->ipv4_addrs->del = del_ip_addr;
231 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000232 }
hassof390d2c2004-09-10 20:48:21 +0000233 adj->ipv4_addrs = list_new ();
234 if (tlvs->ipv4_addrs)
235 {
hasso3fdb2dd2005-09-28 18:45:54 +0000236 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000237 {
238 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
239 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
240 listnode_add (adj->ipv4_addrs, malloced);
241 }
242 }
jardineb5d44e2003-12-23 08:09:43 +0000243}
244
245#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000246static void
hassof390d2c2004-09-10 20:48:21 +0000247tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000248{
hasso3fdb2dd2005-09-28 18:45:54 +0000249 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000250 struct in6_addr *ipv6_addr, *malloced;
251
hassof390d2c2004-09-10 20:48:21 +0000252 if (adj->ipv6_addrs)
253 {
254 adj->ipv6_addrs->del = del_ip_addr;
255 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000256 }
hassof390d2c2004-09-10 20:48:21 +0000257 adj->ipv6_addrs = list_new ();
258 if (tlvs->ipv6_addrs)
259 {
hasso3fdb2dd2005-09-28 18:45:54 +0000260 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000261 {
262 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
263 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
264 listnode_add (adj->ipv6_addrs, malloced);
265 }
266 }
jardineb5d44e2003-12-23 08:09:43 +0000267
268}
269#endif /* HAVE_IPV6 */
270
jardineb5d44e2003-12-23 08:09:43 +0000271/*
272 * RECEIVE SIDE
273 */
274
275/*
276 * Process P2P IIH
277 * ISO - 10589
278 * Section 8.2.5 - Receiving point-to-point IIH PDUs
279 *
280 */
281static int
282process_p2p_hello (struct isis_circuit *circuit)
283{
284 int retval = ISIS_OK;
285 struct isis_p2p_hello_hdr *hdr;
286 struct isis_adjacency *adj;
287 u_int32_t expected = 0, found;
288 struct tlvs tlvs;
289
hassof390d2c2004-09-10 20:48:21 +0000290 if ((stream_get_endp (circuit->rcv_stream) -
291 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
292 {
293 zlog_warn ("Packet too short");
294 return ISIS_WARNING;
295 }
jardineb5d44e2003-12-23 08:09:43 +0000296
297 /* 8.2.5.1 PDU acceptance tests */
298
299 /* 8.2.5.1 a) external domain untrue */
300 /* FIXME: not useful at all? */
301
302 /* 8.2.5.1 b) ID Length mismatch */
303 /* checked at the handle_pdu */
304
305 /* 8.2.5.2 IIH PDU Processing */
306
307 /* 8.2.5.2 a) 1) Maximum Area Addresses */
308 /* Already checked, and can also be ommited */
309
310 /*
311 * Get the header
312 */
hassof390d2c2004-09-10 20:48:21 +0000313 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000314 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
315
316 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000317 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
318 hdr.hold_time = stream_getw (stream);
319 hdr.pdu_len = stream_getw (stream);
320 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000321
322 /*
323 * My interpertation of the ISO, if no adj exists we will create one for
324 * the circuit
325 */
326
hassof390d2c2004-09-10 20:48:21 +0000327 if (isis->debugs & DEBUG_ADJ_PACKETS)
328 {
hasso529d65b2004-12-24 00:14:50 +0000329 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
330 " cir id %02d, length %d",
331 circuit->area->area_tag, circuit->interface->name,
332 circuit_t2string (circuit->circuit_is_type),
333 circuit->circuit_id, ntohs (hdr->pdu_len));
hassof390d2c2004-09-10 20:48:21 +0000334 }
jardineb5d44e2003-12-23 08:09:43 +0000335
336 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000337 if (!adj)
338 {
Paul Jakma41b36e92006-12-08 01:09:50 +0000339 adj = isis_new_adj (hdr->source_id, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +0000340 if (adj == NULL)
341 return ISIS_ERROR;
342 circuit->u.p2p.neighbor = adj;
343 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
344 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
345 }
jardineb5d44e2003-12-23 08:09:43 +0000346
347 /* 8.2.6 Monitoring point-to-point adjacencies */
348 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000349 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000350
351 /*
352 * Lets get the TLVS now
353 */
354 expected |= TLVFLAG_AREA_ADDRS;
355 expected |= TLVFLAG_AUTH_INFO;
356 expected |= TLVFLAG_NLPID;
357 expected |= TLVFLAG_IPV4_ADDR;
358 expected |= TLVFLAG_IPV6_ADDR;
359
360 retval = parse_tlvs (circuit->area->area_tag,
361 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000362 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
363 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000364
hassof390d2c2004-09-10 20:48:21 +0000365 if (retval > ISIS_WARNING)
366 {
367 free_tlvs (&tlvs);
368 return retval;
369 };
jardineb5d44e2003-12-23 08:09:43 +0000370
371 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000372 if (circuit->passwd.type)
373 {
374 if (!(found & TLVFLAG_AUTH_INFO) ||
375 authentication_check (&circuit->passwd, &tlvs.auth_info))
376 {
377 isis_event_auth_failure (circuit->area->area_tag,
378 "P2P hello authentication failure",
379 hdr->source_id);
380 return ISIS_OK;
381 }
jardineb5d44e2003-12-23 08:09:43 +0000382 }
jardineb5d44e2003-12-23 08:09:43 +0000383
384 /* we do this now because the adj may not survive till the end... */
385
386 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000387 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000388
389#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000390 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000391#endif /* HAVE_IPV6 */
392
393 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000394 THREAD_TIMER_OFF (adj->t_expire);
395 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
396 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000397
398 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000399 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
400 {
401 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
402 if (circuit->area->is_type == IS_LEVEL_1)
403 {
404 switch (hdr->circuit_t)
405 {
406 case IS_LEVEL_1:
407 case IS_LEVEL_1_AND_2:
408 if (adj->adj_state != ISIS_ADJ_UP)
409 {
410 /* (4) adj state up */
411 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
412 /* (5) adj usage level 1 */
413 adj->adj_usage = ISIS_ADJ_LEVEL1;
414 }
415 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
416 {
417 ; /* accept */
418 }
419 break;
420 case IS_LEVEL_2:
421 if (adj->adj_state != ISIS_ADJ_UP)
422 {
423 /* (7) reject - wrong system type event */
424 zlog_warn ("wrongSystemType");
425 return ISIS_WARNING; /* Reject */
426 }
427 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
428 {
429 /* (6) down - wrong system */
430 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
431 }
432 break;
433 }
434 }
jardineb5d44e2003-12-23 08:09:43 +0000435
hassof390d2c2004-09-10 20:48:21 +0000436 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
437 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
438 {
439 switch (hdr->circuit_t)
440 {
441 case IS_LEVEL_1:
442 if (adj->adj_state != ISIS_ADJ_UP)
443 {
444 /* (6) adj state up */
445 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
446 /* (7) adj usage level 1 */
447 adj->adj_usage = ISIS_ADJ_LEVEL1;
448 }
449 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
450 {
451 ; /* accept */
452 }
453 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
454 (adj->adj_usage == ISIS_ADJ_LEVEL2))
455 {
456 /* (8) down - wrong system */
457 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
458 }
459 break;
460 case IS_LEVEL_2:
461 if (adj->adj_state != ISIS_ADJ_UP)
462 {
463 /* (6) adj state up */
464 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
465 /* (9) adj usage level 2 */
466 adj->adj_usage = ISIS_ADJ_LEVEL2;
467 }
468 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
469 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
470 {
471 /* (8) down - wrong system */
472 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
473 }
474 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
475 {
476 ; /* Accept */
477 }
478 break;
479 case IS_LEVEL_1_AND_2:
480 if (adj->adj_state != ISIS_ADJ_UP)
481 {
482 /* (6) adj state up */
483 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
484 /* (10) adj usage level 1 */
485 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
486 }
487 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
488 (adj->adj_usage == ISIS_ADJ_LEVEL2))
489 {
490 /* (8) down - wrong system */
491 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
492 }
493 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
494 {
495 ; /* Accept */
496 }
497 break;
498 }
499 }
jardineb5d44e2003-12-23 08:09:43 +0000500
hassof390d2c2004-09-10 20:48:21 +0000501 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
502 if (circuit->area->is_type == IS_LEVEL_2)
503 {
504 switch (hdr->circuit_t)
505 {
506 case IS_LEVEL_1:
507 if (adj->adj_state != ISIS_ADJ_UP)
508 {
509 /* (5) reject - wrong system type event */
510 zlog_warn ("wrongSystemType");
511 return ISIS_WARNING; /* Reject */
512 }
513 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
514 (adj->adj_usage == ISIS_ADJ_LEVEL2))
515 {
516 /* (6) down - wrong system */
517 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
518 }
519 break;
520 case IS_LEVEL_1_AND_2:
521 case IS_LEVEL_2:
522 if (adj->adj_state != ISIS_ADJ_UP)
523 {
524 /* (7) adj state up */
525 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
526 /* (8) adj usage level 2 */
527 adj->adj_usage = ISIS_ADJ_LEVEL2;
528 }
529 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
530 {
531 /* (6) down - wrong system */
532 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
533 }
534 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
535 {
536 ; /* Accept */
537 }
538 break;
539 }
540 }
jardineb5d44e2003-12-23 08:09:43 +0000541 }
jardineb5d44e2003-12-23 08:09:43 +0000542 /* 8.2.5.2 b) if no match was detected */
543 else
jardineb5d44e2003-12-23 08:09:43 +0000544 {
hassof390d2c2004-09-10 20:48:21 +0000545 if (circuit->area->is_type == IS_LEVEL_1)
546 {
547 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
548 if (adj->adj_state != ISIS_ADJ_UP)
549 {
550 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
551 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
552 }
553 else
554 {
555 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
556 "Down - Area Mismatch");
557 }
558 }
559 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
560 else
561 {
562 switch (hdr->circuit_t)
563 {
564 case IS_LEVEL_1:
565 if (adj->adj_state != ISIS_ADJ_UP)
566 {
567 /* (6) reject - Area Mismatch event */
568 zlog_warn ("AreaMismatch");
569 return ISIS_WARNING; /* Reject */
570 }
571 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
572 {
573 /* (7) down - area mismatch */
574 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000575
hassof390d2c2004-09-10 20:48:21 +0000576 }
577 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
578 (adj->adj_usage == ISIS_ADJ_LEVEL2))
579 {
580 /* (7) down - wrong system */
581 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
582 }
583 break;
584 case IS_LEVEL_1_AND_2:
585 case IS_LEVEL_2:
586 if (adj->adj_state != ISIS_ADJ_UP)
587 {
588 /* (8) adj state up */
589 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
590 /* (9) adj usage level 2 */
591 adj->adj_usage = ISIS_ADJ_LEVEL2;
592 }
593 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
594 {
595 /* (7) down - wrong system */
596 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
597 }
598 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
599 {
600 if (hdr->circuit_t == IS_LEVEL_2)
601 {
602 /* (7) down - wrong system */
603 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
604 "Wrong System");
605 }
606 else
607 {
608 /* (7) down - area mismatch */
609 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
610 "Area Mismatch");
611 }
612 }
613 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
614 {
615 ; /* Accept */
616 }
617 break;
618 }
619 }
jardineb5d44e2003-12-23 08:09:43 +0000620 }
jardineb5d44e2003-12-23 08:09:43 +0000621 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
622 /* FIXME - Missing parts */
623
jardineb5d44e2003-12-23 08:09:43 +0000624 /* some of my own understanding of the ISO, why the heck does
625 * it not say what should I change the system_type to...
626 */
hassof390d2c2004-09-10 20:48:21 +0000627 switch (adj->adj_usage)
628 {
jardineb5d44e2003-12-23 08:09:43 +0000629 case ISIS_ADJ_LEVEL1:
630 adj->sys_type = ISIS_SYSTYPE_L1_IS;
631 break;
632 case ISIS_ADJ_LEVEL2:
633 adj->sys_type = ISIS_SYSTYPE_L2_IS;
634 break;
635 case ISIS_ADJ_LEVEL1AND2:
636 adj->sys_type = ISIS_SYSTYPE_L2_IS;
637 break;
638 case ISIS_ADJ_NONE:
639 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
640 break;
hassof390d2c2004-09-10 20:48:21 +0000641 }
jardineb5d44e2003-12-23 08:09:43 +0000642
643 adj->circuit_t = hdr->circuit_t;
644 adj->level = hdr->circuit_t;
645
646 free_tlvs (&tlvs);
647
648 return retval;
649}
650
jardineb5d44e2003-12-23 08:09:43 +0000651/*
652 * Process IS-IS LAN Level 1/2 Hello PDU
653 */
hassof390d2c2004-09-10 20:48:21 +0000654static int
655process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000656{
657 int retval = ISIS_OK;
658 struct isis_lan_hello_hdr hdr;
659 struct isis_adjacency *adj;
660 u_int32_t expected = 0, found;
661 struct tlvs tlvs;
662 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000663 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000664
hassof390d2c2004-09-10 20:48:21 +0000665 if ((stream_get_endp (circuit->rcv_stream) -
666 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
667 {
668 zlog_warn ("Packet too short");
669 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000670 }
hassof390d2c2004-09-10 20:48:21 +0000671
672 if (circuit->ext_domain)
673 {
hasso529d65b2004-12-24 00:14:50 +0000674 zlog_debug ("level %d LAN Hello received over circuit with "
675 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000676 return ISIS_WARNING;
677 }
678
679 if (!accept_level (level, circuit->circuit_is_type))
680 {
681 if (isis->debugs & DEBUG_ADJ_PACKETS)
682 {
hasso529d65b2004-12-24 00:14:50 +0000683 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
684 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000685 }
686 return ISIS_WARNING;
687 }
jardineb5d44e2003-12-23 08:09:43 +0000688
689#if 0
690 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000691 if (!accept_level (level, circuit->area->is_type))
692 {
693 if (isis->debugs & DEBUG_ADJ_PACKETS)
694 {
hasso529d65b2004-12-24 00:14:50 +0000695 zlog_debug ("ISIS-Adj (%s): is type mismatch",
696 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000697 }
698 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000699 }
jardineb5d44e2003-12-23 08:09:43 +0000700#endif
701 /*
702 * Fill the header
703 */
704 hdr.circuit_t = stream_getc (circuit->rcv_stream);
705 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
706 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000707 hdr.pdu_len = stream_getw (circuit->rcv_stream);
708 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000709 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
710
711 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000712 hdr.circuit_t != IS_LEVEL_1_AND_2)
713 {
714 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
715 hdr.circuit_t);
716 return ISIS_ERROR;
717 }
jardineb5d44e2003-12-23 08:09:43 +0000718 /*
719 * Then get the tlvs
720 */
721 expected |= TLVFLAG_AUTH_INFO;
722 expected |= TLVFLAG_AREA_ADDRS;
723 expected |= TLVFLAG_LAN_NEIGHS;
724 expected |= TLVFLAG_NLPID;
725 expected |= TLVFLAG_IPV4_ADDR;
726 expected |= TLVFLAG_IPV6_ADDR;
727
728 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000729 STREAM_PNT (circuit->rcv_stream),
730 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
731 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000732
hassof390d2c2004-09-10 20:48:21 +0000733 if (retval > ISIS_WARNING)
734 {
735 zlog_warn ("parse_tlvs() failed");
736 goto out;
737 }
jardineb5d44e2003-12-23 08:09:43 +0000738
hassof390d2c2004-09-10 20:48:21 +0000739 if (!(found & TLVFLAG_AREA_ADDRS))
740 {
741 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
742 level);
jardineb5d44e2003-12-23 08:09:43 +0000743 retval = ISIS_WARNING;
744 goto out;
745 }
hassof390d2c2004-09-10 20:48:21 +0000746
747 if (circuit->passwd.type)
748 {
749 if (!(found & TLVFLAG_AUTH_INFO) ||
750 authentication_check (&circuit->passwd, &tlvs.auth_info))
751 {
752 isis_event_auth_failure (circuit->area->area_tag,
753 "LAN hello authentication failure",
754 hdr.source_id);
755 retval = ISIS_WARNING;
756 goto out;
757 }
758 }
jardineb5d44e2003-12-23 08:09:43 +0000759
760 /*
761 * Accept the level 1 adjacency only if a match between local and
762 * remote area addresses is found
763 */
hassof390d2c2004-09-10 20:48:21 +0000764 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
765 {
766 if (isis->debugs & DEBUG_ADJ_PACKETS)
767 {
hasso529d65b2004-12-24 00:14:50 +0000768 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
769 circuit->area->area_tag, level,
770 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000771 }
772 retval = ISIS_OK;
773 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000774 }
jardineb5d44e2003-12-23 08:09:43 +0000775
776 /*
777 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000778 */
779 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
780 {
hasso529d65b2004-12-24 00:14:50 +0000781 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
782 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000783
hassof390d2c2004-09-10 20:48:21 +0000784 retval = ISIS_OK;
785 goto out;
786 }
jardineb5d44e2003-12-23 08:09:43 +0000787
788 /*
789 * check if it's own interface ip match iih ip addrs
790 */
hassof390d2c2004-09-10 20:48:21 +0000791 if (!(found & TLVFLAG_IPV4_ADDR)
792 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
793 {
hasso529d65b2004-12-24 00:14:50 +0000794 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000795 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
796 circuit->interface->name);
797 retval = ISIS_WARNING;
798 goto out;
799 }
jardineb5d44e2003-12-23 08:09:43 +0000800
801 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000802 if (!adj)
803 {
804 /*
805 * Do as in 8.4.2.5
806 */
807 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
808 if (adj == NULL)
hasso13c48f72004-09-10 21:19:13 +0000809 {
810 retval = ISIS_ERROR;
811 goto out;
812 }
jardineb5d44e2003-12-23 08:09:43 +0000813
hassof390d2c2004-09-10 20:48:21 +0000814 adj->level = level;
815 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000816
hassof390d2c2004-09-10 20:48:21 +0000817 if (level == 1)
818 {
819 adj->sys_type = ISIS_SYSTYPE_L1_IS;
820 }
821 else
822 {
823 adj->sys_type = ISIS_SYSTYPE_L2_IS;
824 }
825 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
826 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
827 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000828 }
jardineb5d44e2003-12-23 08:09:43 +0000829
hassoa211d652004-09-20 14:55:29 +0000830 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
831 switch (level)
832 {
833 case 1:
834 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
835 {
836 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000837 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
838 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000839 }
840 break;
841 case 2:
842 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
843 {
844 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000845 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
846 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000847 }
848 break;
849 }
jardineb5d44e2003-12-23 08:09:43 +0000850
851 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000852 adj->last_upd = time (NULL);
853 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000854
855 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
856
857 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000858 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000859 tlvs_to_adj_nlpids (&tlvs, adj);
860
861 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000862 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000863 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
864
865#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000866 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000867 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
868#endif /* HAVE_IPV6 */
869
870 adj->circuit_t = hdr.circuit_t;
871
872 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000873 THREAD_TIMER_OFF (adj->t_expire);
874 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
875 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000876
877 /*
878 * If the snpa for this circuit is found from LAN Neighbours TLV
879 * we have two-way communication -> adjacency can be put to state "up"
880 */
881
hassof390d2c2004-09-10 20:48:21 +0000882 if (found & TLVFLAG_LAN_NEIGHS)
883 {
884 if (adj->adj_state != ISIS_ADJ_UP)
885 {
hasso3fdb2dd2005-09-28 18:45:54 +0000886 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
hassof390d2c2004-09-10 20:48:21 +0000887 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
888 {
889 isis_adj_state_change (adj, ISIS_ADJ_UP,
890 "own SNPA found in LAN Neighbours TLV");
891 }
892 }
jardineb5d44e2003-12-23 08:09:43 +0000893 }
jardineb5d44e2003-12-23 08:09:43 +0000894
hassof390d2c2004-09-10 20:48:21 +0000895out:
jardineb5d44e2003-12-23 08:09:43 +0000896 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000897 if (isis->debugs & DEBUG_ADJ_PACKETS)
898 {
899 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +0000900 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
901 "cirID %u, length %ld",
902 circuit->area->area_tag,
903 level, snpa_print (ssnpa), circuit->interface->name,
904 circuit_t2string (circuit->circuit_is_type),
hasso29e50b22005-09-01 18:18:47 +0000905 circuit->circuit_id,
906 /* FIXME: use %z when we stop supporting old compilers. */
907 (unsigned long) stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +0000908 }
jardineb5d44e2003-12-23 08:09:43 +0000909
910 free_tlvs (&tlvs);
911
912 return retval;
913}
914
915/*
916 * Process Level 1/2 Link State
917 * ISO - 10589
918 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000919 */
920static int
921process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000922{
923 struct isis_link_state_hdr *hdr;
924 struct isis_adjacency *adj = NULL;
925 struct isis_lsp *lsp, *lsp0 = NULL;
926 int retval = ISIS_OK, comp = 0;
927 u_char lspid[ISIS_SYS_ID_LEN + 2];
928 struct isis_passwd *passwd;
929
930 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000931 if ((stream_get_endp (circuit->rcv_stream) -
932 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
933 {
934 zlog_warn ("Packet too short");
935 return ISIS_WARNING;
936 }
jardineb5d44e2003-12-23 08:09:43 +0000937
938 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000939 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000940
hassof390d2c2004-09-10 20:48:21 +0000941 if (isis->debugs & DEBUG_UPDATE_PACKETS)
942 {
hasso529d65b2004-12-24 00:14:50 +0000943 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
944 "lifetime %us, len %lu, on %s",
945 circuit->area->area_tag,
946 level,
947 rawlspid_print (hdr->lsp_id),
948 ntohl (hdr->seq_num),
949 ntohs (hdr->checksum),
950 ntohs (hdr->rem_lifetime),
hasso29e50b22005-09-01 18:18:47 +0000951 /* FIXME: use %z when we stop supporting old compilers. */
952 (unsigned long) stream_get_endp (circuit->rcv_stream),
paul15935e92005-05-03 09:27:23 +0000953 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000954 }
jardineb5d44e2003-12-23 08:09:43 +0000955
956 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
957
958 /* Checksum sanity check - FIXME: move to correct place */
959 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000960 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
961 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
962 {
hasso529d65b2004-12-24 00:14:50 +0000963 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
964 circuit->area->area_tag,
965 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000966
hassof390d2c2004-09-10 20:48:21 +0000967 return ISIS_WARNING;
968 }
jardineb5d44e2003-12-23 08:09:43 +0000969
970 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000971 if (circuit->ext_domain)
972 {
hasso529d65b2004-12-24 00:14:50 +0000973 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000974 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
975 "externalDomain = true", circuit->area->area_tag,
976 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000977
hassof390d2c2004-09-10 20:48:21 +0000978 return ISIS_WARNING;
979 }
jardineb5d44e2003-12-23 08:09:43 +0000980
981 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000982 if (!accept_level (level, circuit->circuit_is_type))
983 {
hasso529d65b2004-12-24 00:14:50 +0000984 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
985 " type %s",
986 circuit->area->area_tag,
987 rawlspid_print (hdr->lsp_id),
988 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +0000989
hassof390d2c2004-09-10 20:48:21 +0000990 return ISIS_WARNING;
991 }
jardineb5d44e2003-12-23 08:09:43 +0000992
993 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
994
995 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
996
997 /* 7.3.15.1 a) 7 - password check */
998 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
999 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001000 if (passwd->type)
1001 {
1002 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1003 ntohs (hdr->pdu_len), passwd))
1004 {
1005 isis_event_auth_failure (circuit->area->area_tag,
1006 "LSP authentication failure", hdr->lsp_id);
1007 return ISIS_WARNING;
1008 }
jardineb5d44e2003-12-23 08:09:43 +00001009 }
jardineb5d44e2003-12-23 08:09:43 +00001010 /* Find the LSP in our database and compare it to this Link State header */
1011 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1012 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001013 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1014 hdr->checksum, hdr->rem_lifetime);
1015 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001016#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001017 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001018#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001019 ))
jardineb5d44e2003-12-23 08:09:43 +00001020 goto dontcheckadj;
1021
1022 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1023 /* for broadcast circuits, snpa should be compared */
1024 /* FIXME : Point To Point */
1025
hassof390d2c2004-09-10 20:48:21 +00001026 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1027 {
1028 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1029 if (!adj)
1030 {
hasso529d65b2004-12-24 00:14:50 +00001031 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1032 "lifetime %us on %s",
1033 circuit->area->area_tag,
1034 rawlspid_print (hdr->lsp_id),
1035 ntohl (hdr->seq_num),
1036 ntohs (hdr->checksum),
1037 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001038 return ISIS_WARNING; /* Silently discard */
1039 }
jardineb5d44e2003-12-23 08:09:43 +00001040 }
jardineb5d44e2003-12-23 08:09:43 +00001041
1042 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001043 else
1044 {
1045 /* If no adj, or no sharing of level */
1046 if (!circuit->u.p2p.neighbor)
1047 {
1048 return ISIS_OK; /* Silently discard */
1049 }
1050 else
1051 {
1052 if (((level == 1) &&
1053 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1054 ((level == 2) &&
1055 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1056 return ISIS_WARNING; /* Silently discard */
1057 }
jardineb5d44e2003-12-23 08:09:43 +00001058 }
hassof390d2c2004-09-10 20:48:21 +00001059dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001060 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1061
1062 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1063
hassof390d2c2004-09-10 20:48:21 +00001064 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001065
hassof390d2c2004-09-10 20:48:21 +00001066 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1067 if (hdr->rem_lifetime == 0)
1068 {
1069 if (!lsp)
1070 {
1071 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1072 /* only needed on explicit update, eg - p2p */
1073 if (circuit->circ_type == CIRCUIT_T_P2P)
1074 ack_lsp (hdr, circuit, level);
1075 return retval; /* FIXME: do we need a purge? */
1076 }
1077 else
1078 {
1079 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1080 {
1081 /* LSP by some other system -> do 7.3.16.4 b) */
1082 /* 7.3.16.4 b) 1) */
1083 if (comp == LSP_NEWER)
1084 {
hassoa96d8d12005-09-16 14:44:23 +00001085 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area,
1086 level);
hassof390d2c2004-09-10 20:48:21 +00001087 /* ii */
1088 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1089 /* iii */
1090 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1091 /* v */
1092 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1093 /* iv */
1094 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1095 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001096
hassof390d2c2004-09-10 20:48:21 +00001097 } /* 7.3.16.4 b) 2) */
1098 else if (comp == LSP_EQUAL)
1099 {
1100 /* i */
1101 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1102 /* ii */
1103 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1104 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1105 } /* 7.3.16.4 b) 3) */
1106 else
1107 {
1108 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1109 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1110 }
1111 }
1112 else
1113 {
1114 /* our own LSP -> 7.3.16.4 c) */
1115 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1116 circuit->circuit_id
1117 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1118 circuit->circuit_id
1119 && circuit->u.bc.is_dr[level - 1] == 1))
1120 {
1121 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
hassoc89c05d2005-09-04 21:36:36 +00001122 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1123 zlog_debug ("LSP LEN: %d",
1124 ntohs (lsp->lsp_header->pdu_len));
Jingjing Duan6a270cd2008-08-13 19:09:10 +01001125 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00001126 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1127 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001128 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1129 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1130 "seq 0x%08x", circuit->area->area_tag,
1131 rawlspid_print (hdr->lsp_id),
1132 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001133 lsp->lsp_header->rem_lifetime =
1134 htons (isis_jitter
1135 (circuit->area->max_lsp_lifetime[level - 1],
1136 MAX_AGE_JITTER));
1137 }
1138 else
1139 {
1140 /* Got purge for own pseudo-lsp, and we are not DR */
1141 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1142 }
1143 }
1144 }
1145 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001146 }
jardineb5d44e2003-12-23 08:09:43 +00001147 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1148 * purge */
hassof390d2c2004-09-10 20:48:21 +00001149 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1150 {
1151 if (!lsp)
1152 {
1153 /* 7.3.16.4: initiate a purge */
1154 lsp_purge_non_exist (hdr, circuit->area);
1155 return ISIS_OK;
1156 }
1157 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1158
1159 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1160 * has information that the current sequence number for source S is
1161 * "greater" than that held by S, ... */
1162
1163 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1164 {
1165 /* 7.3.16.1 */
1166 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1167
Jingjing Duan6a270cd2008-08-13 19:09:10 +01001168 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00001169 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1170
1171 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001172 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1173 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1174 "0x%08x", circuit->area->area_tag,
1175 rawlspid_print (hdr->lsp_id),
1176 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001177 lsp->lsp_header->rem_lifetime =
1178 htons (isis_jitter
1179 (circuit->area->max_lsp_lifetime[level - 1],
1180 MAX_AGE_JITTER));
1181 }
jardineb5d44e2003-12-23 08:09:43 +00001182 }
hassof390d2c2004-09-10 20:48:21 +00001183 else
1184 {
1185 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001186
hassof390d2c2004-09-10 20:48:21 +00001187 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1188 if ((!lsp || comp == LSP_NEWER))
1189 {
Peter Szilagyi907fd952011-10-01 17:15:46 +04001190 int regenerate = (lsp == NULL);
hassof390d2c2004-09-10 20:48:21 +00001191 /* i */
1192 if (lsp)
1193 {
jardineb5d44e2003-12-23 08:09:43 +00001194#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001195 zlog_debug ("level %d number is - %ld", level,
1196 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001197#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001198 lsp_search_and_destroy (hdr->lsp_id,
1199 circuit->area->lspdb[level - 1]);
1200 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001201#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001202 zlog_debug ("level %d number is - %ld", level,
1203 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001204#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001205 }
1206 /*
1207 * If this lsp is a frag, need to see if we have zero lsp present
1208 */
1209 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1210 {
1211 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1212 LSP_FRAGMENT (lspid) = 0;
1213 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1214 if (!lsp0)
1215 {
hasso529d65b2004-12-24 00:14:50 +00001216 zlog_debug ("Got lsp frag, while zero lsp not database");
hassof390d2c2004-09-10 20:48:21 +00001217 return ISIS_OK;
1218 }
1219 }
1220 lsp =
1221 lsp_new_from_stream_ptr (circuit->rcv_stream,
1222 ntohs (hdr->pdu_len), lsp0,
1223 circuit->area);
1224 lsp->level = level;
hassof390d2c2004-09-10 20:48:21 +00001225 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1226 /* ii */
1227 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1228 /* iii */
1229 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001230
hassof390d2c2004-09-10 20:48:21 +00001231 /* iv */
1232 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1233 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1234 /* FIXME: v) */
Peter Szilagyi907fd952011-10-01 17:15:46 +04001235 if (regenerate && circuit->u.bc.is_dr[level - 1]) {
1236 lsp_l1_pseudo_generate (circuit);
1237 }
hassof390d2c2004-09-10 20:48:21 +00001238 }
1239 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1240 else if (comp == LSP_EQUAL)
1241 {
1242 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassoa96d8d12005-09-16 14:44:23 +00001243 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001244 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1245 {
1246 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1247 }
1248 }
1249 /* 7.3.15.1 e) 3) LSP older than the one in db */
1250 else
1251 {
1252 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1253 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1254 }
jardineb5d44e2003-12-23 08:09:43 +00001255 }
Peter Szilagyid034aa02011-10-01 17:22:51 +04001256
jardineb5d44e2003-12-23 08:09:43 +00001257 return retval;
1258}
1259
1260/*
1261 * Process Sequence Numbers
1262 * ISO - 10589
1263 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1264 */
1265
hasso92365882005-01-18 13:53:33 +00001266static int
hassof390d2c2004-09-10 20:48:21 +00001267process_snp (int snp_type, int level, struct isis_circuit *circuit,
1268 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001269{
1270 int retval = ISIS_OK;
1271 int cmp, own_lsp;
1272 char typechar = ' ';
1273 int len;
1274 struct isis_adjacency *adj;
1275 struct isis_complete_seqnum_hdr *chdr = NULL;
1276 struct isis_partial_seqnum_hdr *phdr = NULL;
1277 uint32_t found = 0, expected = 0;
1278 struct isis_lsp *lsp;
1279 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001280 struct listnode *node, *nnode;
1281 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001282 struct tlvs tlvs;
1283 struct list *lsp_list = NULL;
1284 struct isis_passwd *passwd;
1285
hassof390d2c2004-09-10 20:48:21 +00001286 if (snp_type == ISIS_SNP_CSNP_FLAG)
1287 {
1288 /* getting the header info */
1289 typechar = 'C';
1290 chdr =
1291 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1292 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1293 len = ntohs (chdr->pdu_len);
1294 if (len < ISIS_CSNP_HDRLEN)
1295 {
1296 zlog_warn ("Received a CSNP with bogus length!");
1297 return ISIS_OK;
1298 }
jardineb5d44e2003-12-23 08:09:43 +00001299 }
hassof390d2c2004-09-10 20:48:21 +00001300 else
1301 {
1302 typechar = 'P';
1303 phdr =
1304 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1305 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1306 len = ntohs (phdr->pdu_len);
1307 if (len < ISIS_PSNP_HDRLEN)
1308 {
1309 zlog_warn ("Received a CSNP with bogus length!");
1310 return ISIS_OK;
1311 }
jardineb5d44e2003-12-23 08:09:43 +00001312 }
jardineb5d44e2003-12-23 08:09:43 +00001313
1314 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001315 if (circuit->ext_domain)
1316 {
jardineb5d44e2003-12-23 08:09:43 +00001317
hasso529d65b2004-12-24 00:14:50 +00001318 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1319 "skipping: circuit externalDomain = true",
1320 circuit->area->area_tag,
1321 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001322
1323 return ISIS_OK;
1324 }
hassof390d2c2004-09-10 20:48:21 +00001325
1326 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1327 if (!accept_level (level, circuit->circuit_is_type))
1328 {
1329
hasso529d65b2004-12-24 00:14:50 +00001330 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1331 "skipping: circuit type %s does not match level %d",
1332 circuit->area->area_tag,
1333 level,
1334 typechar,
1335 circuit->interface->name,
1336 circuit_t2string (circuit->circuit_is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001337
1338 return ISIS_OK;
1339 }
1340
1341 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1342 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1343 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1344 {
1345 if (!circuit->u.bc.is_dr[level - 1])
1346 {
1347
hasso529d65b2004-12-24 00:14:50 +00001348 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1349 "skipping: we are not the DIS",
1350 circuit->area->area_tag,
1351 level,
1352 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001353
1354 return ISIS_OK;
1355 }
1356 }
jardineb5d44e2003-12-23 08:09:43 +00001357
1358 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1359
1360 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1361 * - already checked */
1362
1363 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1364 /* for broadcast circuits, snpa should be compared */
1365 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001366 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1367 {
1368 if (snp_type == ISIS_SNP_CSNP_FLAG)
1369 {
1370 adj =
1371 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1372 }
1373 else
1374 {
1375 /* a psnp on a broadcast, how lovely of Juniper :) */
1376 adj =
1377 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1378 }
1379 if (!adj)
1380 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001381 }
hassof390d2c2004-09-10 20:48:21 +00001382 else
1383 {
1384 if (!circuit->u.p2p.neighbor)
1385 return ISIS_OK; /* Silently discard */
1386 }
jardineb5d44e2003-12-23 08:09:43 +00001387
1388 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1389
1390 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1391
1392 memset (&tlvs, 0, sizeof (struct tlvs));
1393
1394 /* parse the SNP */
1395 expected |= TLVFLAG_LSP_ENTRIES;
1396 expected |= TLVFLAG_AUTH_INFO;
1397 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001398 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001399 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001400 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001401
hassof390d2c2004-09-10 20:48:21 +00001402 if (retval > ISIS_WARNING)
1403 {
1404 zlog_warn ("something went very wrong processing SNP");
1405 free_tlvs (&tlvs);
1406 return retval;
1407 }
jardineb5d44e2003-12-23 08:09:43 +00001408
hasso1cbc5622005-01-01 10:29:51 +00001409 if (level == 1)
1410 passwd = &circuit->area->area_passwd;
1411 else
1412 passwd = &circuit->area->domain_passwd;
1413
1414 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001415 {
hasso1cbc5622005-01-01 10:29:51 +00001416 if (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00001417 {
hasso1cbc5622005-01-01 10:29:51 +00001418 if (!(found & TLVFLAG_AUTH_INFO) ||
1419 authentication_check (passwd, &tlvs.auth_info))
1420 {
1421 isis_event_auth_failure (circuit->area->area_tag,
1422 "SNP authentication" " failure",
1423 phdr ? phdr->source_id : chdr->source_id);
1424 return ISIS_OK;
1425 }
hassof390d2c2004-09-10 20:48:21 +00001426 }
1427 }
jardineb5d44e2003-12-23 08:09:43 +00001428
1429 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001430 if (isis->debugs & DEBUG_SNP_PACKETS)
1431 {
hasso529d65b2004-12-24 00:14:50 +00001432 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1433 circuit->area->area_tag,
1434 level,
1435 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001436 if (tlvs.lsp_entries)
1437 {
hasso3fdb2dd2005-09-28 18:45:54 +00001438 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001439 {
hasso529d65b2004-12-24 00:14:50 +00001440 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1441 " cksum 0x%04x, lifetime %us",
1442 circuit->area->area_tag,
1443 typechar,
1444 rawlspid_print (entry->lsp_id),
1445 ntohl (entry->seq_num),
1446 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001447 }
1448 }
jardineb5d44e2003-12-23 08:09:43 +00001449 }
jardineb5d44e2003-12-23 08:09:43 +00001450
1451 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001452 if (tlvs.lsp_entries)
1453 {
hasso3fdb2dd2005-09-28 18:45:54 +00001454 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001455 {
1456 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1457 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1458 if (lsp)
1459 {
1460 /* 7.3.15.2 b) 1) is this LSP newer */
1461 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1462 entry->checksum, entry->rem_lifetime);
1463 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1464 if (cmp == LSP_EQUAL)
1465 {
1466 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1467 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1468 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1469 }
1470 else if (cmp == LSP_OLDER)
1471 {
1472 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1473 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1474 }
1475 else
1476 {
1477 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1478 * on p2p */
1479 if (own_lsp)
1480 {
1481 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1482 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1483 }
1484 else
1485 {
1486 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1487 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1488 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1489 }
1490 }
1491 }
1492 else
1493 {
1494 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1495 * insert it and set SSN on it */
1496 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1497 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1498 {
1499 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1500 0, 0, entry->checksum, level);
1501 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1502 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1503 }
1504 }
jardineb5d44e2003-12-23 08:09:43 +00001505 }
1506 }
jardineb5d44e2003-12-23 08:09:43 +00001507
1508 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001509 if (snp_type == ISIS_SNP_CSNP_FLAG)
1510 {
1511 /*
1512 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1513 */
1514 lsp_list = list_new ();
1515 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1516 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001517
hassof390d2c2004-09-10 20:48:21 +00001518 /* Fixme: Find a better solution */
1519 if (tlvs.lsp_entries)
1520 {
paul1eb8ef22005-04-07 07:30:20 +00001521 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001522 {
paul1eb8ef22005-04-07 07:30:20 +00001523 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001524 {
1525 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1526 {
1527 list_delete_node (lsp_list, node2);
1528 break;
1529 }
1530 }
1531 }
1532 }
1533 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001534 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001535 {
1536 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001537 }
hassof390d2c2004-09-10 20:48:21 +00001538 /* lets free it */
1539 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001540 }
jardineb5d44e2003-12-23 08:09:43 +00001541
1542 free_tlvs (&tlvs);
1543 return retval;
1544}
1545
hasso92365882005-01-18 13:53:33 +00001546static int
hassof390d2c2004-09-10 20:48:21 +00001547process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001548{
jardineb5d44e2003-12-23 08:09:43 +00001549 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001550 if ((stream_get_endp (circuit->rcv_stream) -
1551 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1552 {
1553 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1554 return ISIS_WARNING;
1555 }
jardineb5d44e2003-12-23 08:09:43 +00001556
1557 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1558}
1559
hasso92365882005-01-18 13:53:33 +00001560static int
hassof390d2c2004-09-10 20:48:21 +00001561process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001562{
hassof390d2c2004-09-10 20:48:21 +00001563 if ((stream_get_endp (circuit->rcv_stream) -
1564 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1565 {
1566 zlog_warn ("Packet too short");
1567 return ISIS_WARNING;
1568 }
jardineb5d44e2003-12-23 08:09:43 +00001569
1570 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1571}
1572
jardineb5d44e2003-12-23 08:09:43 +00001573/*
1574 * Process ISH
1575 * ISO - 10589
1576 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1577 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001578 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1579 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1580 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001581 */
hasso92365882005-01-18 13:53:33 +00001582static int
jardineb5d44e2003-12-23 08:09:43 +00001583process_is_hello (struct isis_circuit *circuit)
1584{
1585 struct isis_adjacency *adj;
1586 int retval = ISIS_OK;
1587 u_char neigh_len;
1588 u_char *sysid;
1589
1590 /* In this point in time we are not yet able to handle is_hellos
1591 * on lan - Sorry juniper...
1592 */
1593 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1594 return retval;
1595
1596 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001597 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001598 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001599 if (!adj)
1600 {
1601 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00001602 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001603 if (adj == NULL)
1604 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001605
hassof390d2c2004-09-10 20:48:21 +00001606 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1607 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1608 circuit->u.p2p.neighbor = adj;
1609 }
1610 /* 8.2.2 a) */
1611 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1612 ISIS_SYS_ID_LEN))
1613 {
1614 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1615 /* 8.2.2 a) 2) delete the adj */
1616 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1617 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00001618 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001619 if (adj == NULL)
1620 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001621
hassof390d2c2004-09-10 20:48:21 +00001622 /* 8.2.2 a) 3) i */
1623 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1624 /* 8.2.2 a) 3) ii */
1625 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1626 /* 8.2.2 a) 4) quite meaningless */
1627 }
jardineb5d44e2003-12-23 08:09:43 +00001628 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001629 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1630 (adj->sys_type == ISIS_SYSTYPE_IS))
1631 {
1632 /* do nothing */
1633 }
1634 else
1635 {
1636 /* 8.2.2 c) respond with a p2p IIH */
1637 send_hello (circuit, 1);
1638 }
jardineb5d44e2003-12-23 08:09:43 +00001639 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001640 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001641 /* 8.2.2 e) FIXME: Circuit type of? */
1642
jardineb5d44e2003-12-23 08:09:43 +00001643 return retval;
1644}
1645
jardineb5d44e2003-12-23 08:09:43 +00001646/*
1647 * PDU Dispatcher
1648 */
1649
hasso92365882005-01-18 13:53:33 +00001650static int
hassof390d2c2004-09-10 20:48:21 +00001651isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001652{
jardineb5d44e2003-12-23 08:09:43 +00001653 struct isis_fixed_hdr *hdr;
1654 struct esis_fixed_hdr *esis_hdr;
1655
hassof390d2c2004-09-10 20:48:21 +00001656 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001657
1658 /*
1659 * Let's first read data from stream to the header
1660 */
hassof390d2c2004-09-10 20:48:21 +00001661 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001662
hassof390d2c2004-09-10 20:48:21 +00001663 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1664 {
1665 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1666 return ISIS_ERROR;
1667 }
jardineb5d44e2003-12-23 08:09:43 +00001668
1669 /* now we need to know if this is an ISO 9542 packet and
1670 * take real good care of it, waaa!
1671 */
hassof390d2c2004-09-10 20:48:21 +00001672 if (hdr->idrp == ISO9542_ESIS)
1673 {
1674 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1675 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1676 /* FIXME: Need to do some acceptence tests */
1677 /* example length... */
1678 switch (esis_hdr->pdu_type)
1679 {
1680 case ESH_PDU:
1681 /* FIXME */
1682 break;
1683 case ISH_PDU:
hasso529d65b2004-12-24 00:14:50 +00001684 zlog_debug ("AN ISH PDU!!");
hassof390d2c2004-09-10 20:48:21 +00001685 retval = process_is_hello (circuit);
1686 break;
1687 default:
1688 return ISIS_ERROR;
1689 }
1690 return retval;
1691 }
1692 else
1693 {
1694 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1695 }
jardineb5d44e2003-12-23 08:09:43 +00001696 /*
1697 * and then process it
1698 */
1699
hassof390d2c2004-09-10 20:48:21 +00001700 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1701 {
1702 zlog_err ("Fixed header length = %d", hdr->length);
1703 return ISIS_ERROR;
1704 }
jardineb5d44e2003-12-23 08:09:43 +00001705
hassof390d2c2004-09-10 20:48:21 +00001706 if (hdr->version1 != 1)
1707 {
1708 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1709 return ISIS_WARNING;
1710 }
jardineb5d44e2003-12-23 08:09:43 +00001711 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001712 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1713 {
1714 zlog_err
1715 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1716 "while the parameter for this IS is %u", hdr->id_len,
1717 ISIS_SYS_ID_LEN);
1718 return ISIS_ERROR;
1719 }
jardineb5d44e2003-12-23 08:09:43 +00001720
hassof390d2c2004-09-10 20:48:21 +00001721 if (hdr->version2 != 1)
1722 {
1723 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1724 return ISIS_WARNING;
1725 }
jardineb5d44e2003-12-23 08:09:43 +00001726 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001727 if ((hdr->max_area_addrs != 0)
1728 && (hdr->max_area_addrs != isis->max_area_addrs))
1729 {
1730 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1731 "received PDU %u while the parameter for this IS is %u",
1732 hdr->max_area_addrs, isis->max_area_addrs);
1733 return ISIS_ERROR;
1734 }
jardineb5d44e2003-12-23 08:09:43 +00001735
hassof390d2c2004-09-10 20:48:21 +00001736 switch (hdr->pdu_type)
1737 {
1738 case L1_LAN_HELLO:
1739 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1740 break;
1741 case L2_LAN_HELLO:
1742 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1743 break;
1744 case P2P_HELLO:
1745 retval = process_p2p_hello (circuit);
1746 break;
1747 case L1_LINK_STATE:
1748 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1749 break;
1750 case L2_LINK_STATE:
1751 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1752 break;
1753 case L1_COMPLETE_SEQ_NUM:
1754 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1755 break;
1756 case L2_COMPLETE_SEQ_NUM:
1757 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1758 break;
1759 case L1_PARTIAL_SEQ_NUM:
1760 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1761 break;
1762 case L2_PARTIAL_SEQ_NUM:
1763 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1764 break;
1765 default:
1766 return ISIS_ERROR;
1767 }
jardineb5d44e2003-12-23 08:09:43 +00001768
1769 return retval;
1770}
1771
jardineb5d44e2003-12-23 08:09:43 +00001772#ifdef GNU_LINUX
1773int
1774isis_receive (struct thread *thread)
1775{
jardineb5d44e2003-12-23 08:09:43 +00001776 struct isis_circuit *circuit;
1777 u_char ssnpa[ETH_ALEN];
1778 int retval;
1779
1780 /*
1781 * Get the circuit
1782 */
1783 circuit = THREAD_ARG (thread);
1784 assert (circuit);
1785
Fritz Reichmann55749992011-09-14 19:31:51 +04001786 if (!circuit->area)
1787 return ISIS_OK;
1788
jardineb5d44e2003-12-23 08:09:43 +00001789 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001790 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001791 else
1792 stream_reset (circuit->rcv_stream);
1793
1794 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001795 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001796
1797 if (retval == ISIS_OK)
1798 retval = isis_handle_pdu (circuit, ssnpa);
1799
1800 /*
1801 * prepare for next packet.
1802 */
hassof390d2c2004-09-10 20:48:21 +00001803 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1804 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001805
1806 return retval;
1807}
1808
1809#else
1810int
1811isis_receive (struct thread *thread)
1812{
jardineb5d44e2003-12-23 08:09:43 +00001813 struct isis_circuit *circuit;
1814 u_char ssnpa[ETH_ALEN];
1815 int retval;
1816
1817 /*
1818 * Get the circuit
1819 */
1820 circuit = THREAD_ARG (thread);
1821 assert (circuit);
1822
hassof390d2c2004-09-10 20:48:21 +00001823 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001824
1825 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001826 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001827 else
1828 stream_reset (circuit->rcv_stream);
1829
1830 retval = circuit->rx (circuit, ssnpa);
1831
1832 if (retval == ISIS_OK)
1833 retval = isis_handle_pdu (circuit, ssnpa);
1834
1835 /*
1836 * prepare for next packet.
1837 */
hassof390d2c2004-09-10 20:48:21 +00001838 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1839 listcount
1840 (circuit->area->circuit_list) *
1841 100);
jardineb5d44e2003-12-23 08:09:43 +00001842
1843 return retval;
1844}
1845
1846#endif
1847
1848 /* filling of the fixed isis header */
1849void
1850fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1851{
1852 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1853
1854 hdr->idrp = ISO10589_ISIS;
1855
hassof390d2c2004-09-10 20:48:21 +00001856 switch (pdu_type)
1857 {
1858 case L1_LAN_HELLO:
1859 case L2_LAN_HELLO:
1860 hdr->length = ISIS_LANHELLO_HDRLEN;
1861 break;
1862 case P2P_HELLO:
1863 hdr->length = ISIS_P2PHELLO_HDRLEN;
1864 break;
1865 case L1_LINK_STATE:
1866 case L2_LINK_STATE:
1867 hdr->length = ISIS_LSP_HDR_LEN;
1868 break;
1869 case L1_COMPLETE_SEQ_NUM:
1870 case L2_COMPLETE_SEQ_NUM:
1871 hdr->length = ISIS_CSNP_HDRLEN;
1872 break;
1873 case L1_PARTIAL_SEQ_NUM:
1874 case L2_PARTIAL_SEQ_NUM:
1875 hdr->length = ISIS_PSNP_HDRLEN;
1876 break;
1877 default:
1878 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1879 return;
1880 }
jardineb5d44e2003-12-23 08:09:43 +00001881 hdr->length += ISIS_FIXED_HDR_LEN;
1882 hdr->pdu_type = pdu_type;
1883 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001884 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001885 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001886 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001887}
1888
jardineb5d44e2003-12-23 08:09:43 +00001889/*
1890 * SEND SIDE
1891 */
hasso92365882005-01-18 13:53:33 +00001892static void
jardineb5d44e2003-12-23 08:09:43 +00001893fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001894 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001895{
hassof390d2c2004-09-10 20:48:21 +00001896 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001897
1898 stream_putc (stream, hdr->idrp);
1899 stream_putc (stream, hdr->length);
1900 stream_putc (stream, hdr->version1);
1901 stream_putc (stream, hdr->id_len);
1902 stream_putc (stream, hdr->pdu_type);
1903 stream_putc (stream, hdr->version2);
1904 stream_putc (stream, hdr->reserved);
1905 stream_putc (stream, hdr->max_area_addrs);
1906
1907 return;
1908}
1909
jardineb5d44e2003-12-23 08:09:43 +00001910int
1911send_hello (struct isis_circuit *circuit, int level)
1912{
1913 struct isis_fixed_hdr fixed_hdr;
1914 struct isis_lan_hello_hdr hello_hdr;
1915 struct isis_p2p_hello_hdr p2p_hello_hdr;
1916
1917 u_int32_t interval;
1918 unsigned long len_pointer, length;
1919 int retval;
1920
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04001921 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
1922 return ISIS_WARNING;
1923
hassof390d2c2004-09-10 20:48:21 +00001924 if (circuit->interface->mtu == 0)
1925 {
1926 zlog_warn ("circuit has zero MTU");
1927 return ISIS_WARNING;
1928 }
jardineb5d44e2003-12-23 08:09:43 +00001929
1930 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001931 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001932 else
1933 stream_reset (circuit->snd_stream);
1934
1935 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1936 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001937 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1938 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001939 else
hassof390d2c2004-09-10 20:48:21 +00001940 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1941 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001942 else
hassof390d2c2004-09-10 20:48:21 +00001943 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001944
1945 /*
1946 * Fill LAN Level 1 or 2 Hello PDU header
1947 */
1948 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001949 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001950 circuit->hello_interval[level - 1];
Fritz Reichmann89980752011-09-14 20:46:57 +04001951 /* If we are the DIS then hello interval is divided by three, as is the hold-timer */
1952 if (circuit->u.bc.is_dr[level - 1])
1953 interval=interval/3;
jardineb5d44e2003-12-23 08:09:43 +00001954 if (interval > USHRT_MAX)
1955 interval = USHRT_MAX;
1956 hello_hdr.circuit_t = circuit->circuit_is_type;
1957 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001958 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001959
hassof390d2c2004-09-10 20:48:21 +00001960 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00001961 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001962
1963 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001964 if (circuit->circ_type == CIRCUIT_T_P2P)
1965 {
1966 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1967 p2p_hello_hdr.local_id = circuit->circuit_id;
1968 /* FIXME: need better understanding */
1969 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001970 }
hassof390d2c2004-09-10 20:48:21 +00001971 else
1972 {
1973 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1974 if (level == 1 && circuit->u.bc.l1_desig_is)
1975 {
1976 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1977 ISIS_SYS_ID_LEN + 1);
1978 }
1979 else if (level == 2 && circuit->u.bc.l2_desig_is)
1980 {
1981 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1982 ISIS_SYS_ID_LEN + 1);
1983 }
1984 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
1985 }
jardineb5d44e2003-12-23 08:09:43 +00001986
1987 /*
1988 * Then the variable length part
1989 */
1990 /* add circuit password */
1991 if (circuit->passwd.type)
1992 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
1993 circuit->passwd.passwd, circuit->snd_stream))
1994 return ISIS_WARNING;
Fritz Reichmannc25eaff2011-10-01 17:43:12 +04001995
1996 /* Protocols Supported TLV */
1997 if (circuit->nlpids.count > 0)
1998 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
1999 return ISIS_WARNING;
2000
jardineb5d44e2003-12-23 08:09:43 +00002001 /* Area Addresses TLV */
2002 assert (circuit->area);
2003 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
2004 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2005 return ISIS_WARNING;
2006
Fritz Reichmannc25eaff2011-10-01 17:43:12 +04002007 /* IP interface Address TLV */
2008 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2009 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2010 return ISIS_WARNING;
2011
2012#ifdef HAVE_IPV6
2013 /* IPv6 Interface Address TLV */
2014 if (circuit->ipv6_router && circuit->ipv6_link &&
2015 circuit->ipv6_link->count > 0)
2016 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2017 return ISIS_WARNING;
2018#endif /* HAVE_IPV6 */
2019
2020 /* Restart signaling, vendor C sends it too */
2021 retval = add_tlv (211, 3, 0, circuit->snd_stream);
2022
jardineb5d44e2003-12-23 08:09:43 +00002023 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002024 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2025 {
2026 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
2027 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2028 circuit->snd_stream))
2029 return ISIS_WARNING;
2030 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
2031 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2032 circuit->snd_stream))
2033 return ISIS_WARNING;
2034 }
jardineb5d44e2003-12-23 08:09:43 +00002035
jardineb5d44e2003-12-23 08:09:43 +00002036 if (circuit->u.bc.pad_hellos)
2037 if (tlv_add_padding (circuit->snd_stream))
2038 return ISIS_WARNING;
2039
paul9985f832005-02-09 15:51:56 +00002040 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002041 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002042 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002043
2044 retval = circuit->tx (circuit, level);
2045 if (retval)
2046 zlog_warn ("sending of LAN Level %d Hello failed", level);
2047
2048 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002049 if (isis->debugs & DEBUG_ADJ_PACKETS)
2050 {
2051 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2052 {
hasso529d65b2004-12-24 00:14:50 +00002053 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2054 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002055 /* FIXME: use %z when we stop supporting old compilers. */
2056 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002057 }
2058 else
2059 {
hasso529d65b2004-12-24 00:14:50 +00002060 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2061 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002062 /* FIXME: use %z when we stop supporting old compilers. */
2063 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002064 }
jardineb5d44e2003-12-23 08:09:43 +00002065 }
jardineb5d44e2003-12-23 08:09:43 +00002066
2067 return retval;
2068}
2069
hasso92365882005-01-18 13:53:33 +00002070static int
jardineb5d44e2003-12-23 08:09:43 +00002071send_lan_hello (struct isis_circuit *circuit, int level)
2072{
hassof390d2c2004-09-10 20:48:21 +00002073 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002074}
2075
2076int
2077send_lan_l1_hello (struct thread *thread)
2078{
jardineb5d44e2003-12-23 08:09:43 +00002079 struct isis_circuit *circuit;
2080 int retval;
Fritz Reichmann89980752011-09-14 20:46:57 +04002081 unsigned long next_hello;
jardineb5d44e2003-12-23 08:09:43 +00002082
2083 circuit = THREAD_ARG (thread);
2084 assert (circuit);
Fritz Reichmann89980752011-09-14 20:46:57 +04002085
2086 if (!circuit->area) {
2087 return ISIS_OK;
2088 }
2089
2090 /* Pseudonode sends hellos three times more than the other nodes */
2091 if (circuit->u.bc.is_dr[0])
2092 next_hello=circuit->hello_interval[0]/3+1;
2093 else
2094 next_hello=circuit->hello_interval[0];
2095
jardineb5d44e2003-12-23 08:09:43 +00002096 circuit->u.bc.t_send_lan_hello[0] = NULL;
2097
2098 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002099 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002100
2101 retval = send_lan_hello (circuit, 1);
2102
2103 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002104 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2105 send_lan_l1_hello, circuit,
Fritz Reichmann89980752011-09-14 20:46:57 +04002106 isis_jitter (next_hello, IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002107
2108 return retval;
2109}
2110
2111int
2112send_lan_l2_hello (struct thread *thread)
2113{
2114 struct isis_circuit *circuit;
2115 int retval;
Fritz Reichmann89980752011-09-14 20:46:57 +04002116 unsigned long next_hello;
jardineb5d44e2003-12-23 08:09:43 +00002117
2118 circuit = THREAD_ARG (thread);
2119 assert (circuit);
Fritz Reichmann55749992011-09-14 19:31:51 +04002120
2121 if (!circuit->area) {
2122 return ISIS_OK;
2123 }
2124
Fritz Reichmann89980752011-09-14 20:46:57 +04002125 /* Pseudonode sends hellos three times more than the other nodes */
2126 if (circuit->u.bc.is_dr[1])
2127 next_hello=circuit->hello_interval[1]/3+1;
2128 else
2129 next_hello=circuit->hello_interval[1];
2130
jardineb5d44e2003-12-23 08:09:43 +00002131 circuit->u.bc.t_send_lan_hello[1] = NULL;
2132
2133 if (circuit->u.bc.run_dr_elect[1])
2134 retval = isis_dr_elect (circuit, 2);
2135
2136 retval = send_lan_hello (circuit, 2);
2137
hassof390d2c2004-09-10 20:48:21 +00002138 /* set next timer thread */
2139 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2140 send_lan_l2_hello, circuit,
Fritz Reichmann89980752011-09-14 20:46:57 +04002141 isis_jitter (next_hello, IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002142
2143 return retval;
2144}
2145
2146int
2147send_p2p_hello (struct thread *thread)
2148{
2149 struct isis_circuit *circuit;
2150
2151 circuit = THREAD_ARG (thread);
2152 assert (circuit);
2153 circuit->u.p2p.t_send_p2p_hello = NULL;
2154
hassof390d2c2004-09-10 20:48:21 +00002155 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002156
hassof390d2c2004-09-10 20:48:21 +00002157 /* set next timer thread */
2158 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2159 circuit, isis_jitter (circuit->hello_interval[1],
2160 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002161
2162 return ISIS_OK;
2163}
2164
hasso92365882005-01-18 13:53:33 +00002165static int
hassof390d2c2004-09-10 20:48:21 +00002166build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2167 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002168{
2169 struct isis_fixed_hdr fixed_hdr;
2170 struct isis_passwd *passwd;
2171 int retval = ISIS_OK;
2172 unsigned long lenp;
2173 u_int16_t length;
2174
hassof390d2c2004-09-10 20:48:21 +00002175 if (level == 1)
2176 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2177 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002178 else
hassof390d2c2004-09-10 20:48:21 +00002179 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2180 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002181
2182 /*
2183 * Fill Level 1 or 2 Complete Sequence Numbers header
2184 */
2185
paul9985f832005-02-09 15:51:56 +00002186 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002187 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002188 /* no need to send the source here, it is always us if we csnp */
2189 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2190 /* with zero circuit id - ref 9.10, 9.11 */
2191 stream_putc (circuit->snd_stream, 0x00);
2192
2193 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2194 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2195
2196 /*
2197 * And TLVs
2198 */
2199 if (level == 1)
2200 passwd = &circuit->area->area_passwd;
2201 else
2202 passwd = &circuit->area->domain_passwd;
2203
hasso1cbc5622005-01-01 10:29:51 +00002204 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2205 if (passwd->type)
2206 retval = tlv_add_authinfo (passwd->type, passwd->len,
2207 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002208
hassof390d2c2004-09-10 20:48:21 +00002209 if (!retval && lsps)
2210 {
2211 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2212 }
paul9985f832005-02-09 15:51:56 +00002213 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002214 assert (length >= ISIS_CSNP_HDRLEN);
2215 /* Update PU length */
2216 stream_putw_at (circuit->snd_stream, lenp, length);
2217
2218 return retval;
2219}
2220
2221/*
2222 * FIXME: support multiple CSNPs
2223 */
2224
2225int
2226send_csnp (struct isis_circuit *circuit, int level)
2227{
2228 int retval = ISIS_OK;
2229 u_char start[ISIS_SYS_ID_LEN + 2];
2230 u_char stop[ISIS_SYS_ID_LEN + 2];
2231 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002232 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002233 struct isis_lsp *lsp;
2234
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002235 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
2236 return ISIS_WARNING;
2237
hassof390d2c2004-09-10 20:48:21 +00002238 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002239 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2240
hassof390d2c2004-09-10 20:48:21 +00002241 if (circuit->area->lspdb[level - 1] &&
2242 dict_count (circuit->area->lspdb[level - 1]) > 0)
2243 {
2244 list = list_new ();
2245 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002246
hassof390d2c2004-09-10 20:48:21 +00002247 if (circuit->snd_stream == NULL)
2248 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2249 else
2250 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002251
hassof390d2c2004-09-10 20:48:21 +00002252 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002253
hassof390d2c2004-09-10 20:48:21 +00002254 if (isis->debugs & DEBUG_SNP_PACKETS)
2255 {
hasso529d65b2004-12-24 00:14:50 +00002256 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
paul1eb8ef22005-04-07 07:30:20 +00002257 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002258 /* FIXME: use %z when we stop supporting old compilers. */
2259 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hasso3fdb2dd2005-09-28 18:45:54 +00002260 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002261 {
hasso529d65b2004-12-24 00:14:50 +00002262 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2263 " cksum 0x%04x, lifetime %us",
2264 circuit->area->area_tag,
2265 rawlspid_print (lsp->lsp_header->lsp_id),
2266 ntohl (lsp->lsp_header->seq_num),
2267 ntohs (lsp->lsp_header->checksum),
2268 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002269 }
2270 }
2271
2272 list_delete (list);
2273
2274 if (retval == ISIS_OK)
2275 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002276 }
jardineb5d44e2003-12-23 08:09:43 +00002277 return retval;
2278}
2279
2280int
2281send_l1_csnp (struct thread *thread)
2282{
2283 struct isis_circuit *circuit;
2284 int retval = ISIS_OK;
2285
2286 circuit = THREAD_ARG (thread);
2287 assert (circuit);
2288
2289 circuit->t_send_csnp[0] = NULL;
2290
hassof390d2c2004-09-10 20:48:21 +00002291 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002292 send_csnp (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002293 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002294 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2295 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002296
2297 return retval;
2298}
2299
2300int
2301send_l2_csnp (struct thread *thread)
2302{
2303 struct isis_circuit *circuit;
2304 int retval = ISIS_OK;
2305
2306 circuit = THREAD_ARG (thread);
2307 assert (circuit);
2308
2309 circuit->t_send_csnp[1] = NULL;
2310
hassof390d2c2004-09-10 20:48:21 +00002311 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002312 send_csnp (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002313 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002314 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2315 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002316
jardineb5d44e2003-12-23 08:09:43 +00002317 return retval;
2318}
2319
hasso92365882005-01-18 13:53:33 +00002320static int
jardineb5d44e2003-12-23 08:09:43 +00002321build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2322{
2323 struct isis_fixed_hdr fixed_hdr;
2324 unsigned long lenp;
2325 u_int16_t length;
2326 int retval = 0;
2327 struct isis_lsp *lsp;
2328 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002329 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002330
2331 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002332 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2333 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002334 else
2335 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002336 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002337
2338 /*
2339 * Fill Level 1 or 2 Partial Sequence Numbers header
2340 */
paul9985f832005-02-09 15:51:56 +00002341 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002342 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002343 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2344 stream_putc (circuit->snd_stream, circuit->idx);
2345
2346 /*
2347 * And TLVs
2348 */
2349
2350 if (level == 1)
2351 passwd = &circuit->area->area_passwd;
2352 else
2353 passwd = &circuit->area->domain_passwd;
2354
hasso1cbc5622005-01-01 10:29:51 +00002355 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2356 if (passwd->type)
2357 retval = tlv_add_authinfo (passwd->type, passwd->len,
2358 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002359
hassof390d2c2004-09-10 20:48:21 +00002360 if (!retval && lsps)
2361 {
2362 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002363 }
jardineb5d44e2003-12-23 08:09:43 +00002364
hassof390d2c2004-09-10 20:48:21 +00002365 if (isis->debugs & DEBUG_SNP_PACKETS)
2366 {
hasso3fdb2dd2005-09-28 18:45:54 +00002367 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002368 {
hasso529d65b2004-12-24 00:14:50 +00002369 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2370 " cksum 0x%04x, lifetime %us",
2371 circuit->area->area_tag,
2372 rawlspid_print (lsp->lsp_header->lsp_id),
2373 ntohl (lsp->lsp_header->seq_num),
2374 ntohs (lsp->lsp_header->checksum),
2375 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002376 }
2377 }
2378
paul9985f832005-02-09 15:51:56 +00002379 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002380 assert (length >= ISIS_PSNP_HDRLEN);
2381 /* Update PDU length */
2382 stream_putw_at (circuit->snd_stream, lenp, length);
2383
2384 return ISIS_OK;
2385}
2386
2387/*
2388 * 7.3.15.4 action on expiration of partial SNP interval
2389 * level 1
2390 */
hasso92365882005-01-18 13:53:33 +00002391static int
jardineb5d44e2003-12-23 08:09:43 +00002392send_psnp (int level, struct isis_circuit *circuit)
2393{
2394 int retval = ISIS_OK;
2395 struct isis_lsp *lsp;
2396 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002397 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002398
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002399 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
2400 return ISIS_WARNING;
2401
hassof390d2c2004-09-10 20:48:21 +00002402 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002403 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002404 circuit->circ_type != CIRCUIT_T_BROADCAST)
2405 {
jardineb5d44e2003-12-23 08:09:43 +00002406
hassof390d2c2004-09-10 20:48:21 +00002407 if (circuit->area->lspdb[level - 1] &&
2408 dict_count (circuit->area->lspdb[level - 1]) > 0)
2409 {
2410 list = list_new ();
2411 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002412
hassof390d2c2004-09-10 20:48:21 +00002413 if (listcount (list) > 0)
2414 {
2415 if (circuit->snd_stream == NULL)
2416 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2417 else
2418 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002419
2420
hassof390d2c2004-09-10 20:48:21 +00002421 if (isis->debugs & DEBUG_SNP_PACKETS)
hasso529d65b2004-12-24 00:14:50 +00002422 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2423 circuit->area->area_tag, level,
2424 circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002425 /* FIXME: use %z when we stop supporting old
2426 * compilers. */
2427 (unsigned long) STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002428
hassof390d2c2004-09-10 20:48:21 +00002429 retval = build_psnp (level, circuit, list);
2430 if (retval == ISIS_OK)
2431 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002432
hassof390d2c2004-09-10 20:48:21 +00002433 if (retval == ISIS_OK)
2434 {
2435 /*
2436 * sending succeeded, we can clear SSN flags of this circuit
2437 * for the LSPs in list
2438 */
hasso3fdb2dd2005-09-28 18:45:54 +00002439 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +00002440 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002441 }
2442 }
2443 list_delete (list);
2444 }
jardineb5d44e2003-12-23 08:09:43 +00002445 }
jardineb5d44e2003-12-23 08:09:43 +00002446
2447 return retval;
2448}
2449
2450int
2451send_l1_psnp (struct thread *thread)
2452{
2453
2454 struct isis_circuit *circuit;
2455 int retval = ISIS_OK;
2456
2457 circuit = THREAD_ARG (thread);
2458 assert (circuit);
2459
2460 circuit->t_send_psnp[0] = NULL;
2461
2462 send_psnp (1, circuit);
2463 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002464 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2465 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002466
2467 return retval;
2468}
2469
2470/*
2471 * 7.3.15.4 action on expiration of partial SNP interval
2472 * level 2
2473 */
2474int
2475send_l2_psnp (struct thread *thread)
2476{
jardineb5d44e2003-12-23 08:09:43 +00002477 struct isis_circuit *circuit;
2478 int retval = ISIS_OK;
2479
2480 circuit = THREAD_ARG (thread);
2481 assert (circuit);
2482
2483 circuit->t_send_psnp[1] = NULL;
2484
2485 send_psnp (2, circuit);
2486
2487 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002488 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2489 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002490
2491 return retval;
2492}
2493
jardineb5d44e2003-12-23 08:09:43 +00002494/*
2495 * ISO 10589 - 7.3.14.3
2496 */
2497int
2498send_lsp (struct thread *thread)
2499{
2500 struct isis_circuit *circuit;
2501 struct isis_lsp *lsp;
2502 struct listnode *node;
2503 int retval = 0;
2504
2505 circuit = THREAD_ARG (thread);
2506 assert (circuit);
2507
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002508 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
2509 return ISIS_WARNING;
2510
2511 lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
2512
2513 /*
2514 * Do not send if levels do not match
2515 */
2516 if (!(lsp->level & circuit->circuit_is_type))
2517 goto dontsend;
2518
2519 /*
2520 * Do not send if we do not have adjacencies in state up on the circuit
2521 */
2522 if (circuit->upadjcount[lsp->level - 1] == 0)
2523 goto dontsend;
2524 /* only send if it needs sending */
2525 if ((time (NULL) - lsp->last_sent) >=
2526 circuit->area->lsp_gen_interval[lsp->level - 1])
hassof390d2c2004-09-10 20:48:21 +00002527 {
jardineb5d44e2003-12-23 08:09:43 +00002528
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002529 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00002530 {
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002531 zlog_debug
2532 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2533 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2534 rawlspid_print (lsp->lsp_header->lsp_id),
2535 ntohl (lsp->lsp_header->seq_num),
2536 ntohs (lsp->lsp_header->checksum),
2537 ntohs (lsp->lsp_header->rem_lifetime),
2538 circuit->interface->name);
2539 }
2540 /* copy our lsp to the send buffer */
2541 stream_copy (circuit->snd_stream, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002542
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002543 retval = circuit->tx (circuit, lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002544
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002545 /*
2546 * If the sending succeeded, we can del the lsp from circuits
2547 * lsp_queue
2548 */
2549 if (retval == ISIS_OK)
2550 {
2551 list_delete_node (circuit->lsp_queue, node);
hassof390d2c2004-09-10 20:48:21 +00002552
jardineb5d44e2003-12-23 08:09:43 +00002553 /*
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002554 * On broadcast circuits also the SRMflag can be cleared
jardineb5d44e2003-12-23 08:09:43 +00002555 */
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002556 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2557 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002558
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002559 if (flags_any_set (lsp->SRMflags) == 0)
2560 {
hassof390d2c2004-09-10 20:48:21 +00002561 /*
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002562 * need to remember when we were last sent
hassof390d2c2004-09-10 20:48:21 +00002563 */
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002564 lsp->last_sent = time (NULL);
hassof390d2c2004-09-10 20:48:21 +00002565 }
jardineb5d44e2003-12-23 08:09:43 +00002566 }
hassof390d2c2004-09-10 20:48:21 +00002567 else
2568 {
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002569 zlog_debug ("sending of level %d link state failed", lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002570 }
hassof390d2c2004-09-10 20:48:21 +00002571 }
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002572 else
2573 {
2574 /* my belief is that if it wasn't his time, the lsp can be removed
2575 * from the queue
2576 */
2577 dontsend:
2578 list_delete_node (circuit->lsp_queue, node);
2579 }
2580#if 0
2581 /*
2582 * If there are still LSPs send next one after lsp-interval (33 msecs)
2583 */
2584 if (listcount (circuit->lsp_queue) > 0)
2585 thread_add_timer (master, send_lsp, circuit, 1);
2586#endif
jardineb5d44e2003-12-23 08:09:43 +00002587
2588 return retval;
hassof390d2c2004-09-10 20:48:21 +00002589}
jardineb5d44e2003-12-23 08:09:43 +00002590
2591int
hassof390d2c2004-09-10 20:48:21 +00002592ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2593 int level)
jardineb5d44e2003-12-23 08:09:43 +00002594{
2595 unsigned long lenp;
2596 int retval;
2597 u_int16_t length;
2598 struct isis_fixed_hdr fixed_hdr;
2599
2600 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002601 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002602 else
2603 stream_reset (circuit->snd_stream);
2604
2605// fill_llc_hdr (stream);
2606 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002607 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2608 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002609 else
hassof390d2c2004-09-10 20:48:21 +00002610 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2611 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002612
2613
paul9985f832005-02-09 15:51:56 +00002614 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002615 stream_putw (circuit->snd_stream, 0); /* PDU length */
2616 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002617 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002618 stream_putc (circuit->snd_stream, 9); /* code */
2619 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002620
hassof390d2c2004-09-10 20:48:21 +00002621 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2622 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2623 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2624 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002625
paul9985f832005-02-09 15:51:56 +00002626 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002627 /* Update PDU length */
2628 stream_putw_at (circuit->snd_stream, lenp, length);
2629
2630 retval = circuit->tx (circuit, level);
2631
2632 return retval;
2633}
2634