blob: d67df31baa9bad99f98986b14d95d81ccd07d8a6 [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"
Fritz Reichmanne6b03b72011-10-01 17:49:48 +040036#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000037
38#include "isisd/dict.h"
39#include "isisd/include-netbsd/iso.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
42#include "isisd/isis_adjacency.h"
43#include "isisd/isis_circuit.h"
44#include "isisd/isis_network.h"
45#include "isisd/isis_misc.h"
46#include "isisd/isis_dr.h"
47#include "isisd/isis_flags.h"
48#include "isisd/isis_tlv.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_lsp.h"
52#include "isisd/isis_pdu.h"
53#include "isisd/iso_checksum.h"
54#include "isisd/isis_csm.h"
55#include "isisd/isis_events.h"
56
57extern struct thread_master *master;
58extern struct isis *isis;
59
60#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000061#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000062
63#ifndef PNBBY
64#define PNBBY 8
65#endif /* PNBBY */
66
67/* Utility mask array. */
Stephen Hemminger2d362d12009-12-21 12:54:58 +030068static const u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000069 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
70};
71
72/*
73 * HELPER FUNCS
74 */
75
76/*
77 * Compares two sets of area addresses
78 */
hassof390d2c2004-09-10 20:48:21 +000079static int
jardineb5d44e2003-12-23 08:09:43 +000080area_match (struct list *left, struct list *right)
81{
82 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000083 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000084
hasso3fdb2dd2005-09-28 18:45:54 +000085 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000086 {
hasso3fdb2dd2005-09-28 18:45:54 +000087 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000088 {
89 if (addr1->addr_len == addr2->addr_len &&
90 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
91 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000092 }
93 }
94
hassof390d2c2004-09-10 20:48:21 +000095 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000096}
97
98/*
99 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
100 * param ip1 the IS interface ip address structure
101 * param ip2 the IIH's ip address
102 * return 0 the IIH's IP is not in the IS's subnetwork
103 * 1 the IIH's IP is in the IS's subnetwork
104 */
hasso92365882005-01-18 13:53:33 +0000105static int
hassof390d2c2004-09-10 20:48:21 +0000106ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000107{
108 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000109 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000110 int len;
hassof390d2c2004-09-10 20:48:21 +0000111
112 addr1 = (u_char *) & ip1->prefix.s_addr;
113 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000114 len = ip1->prefixlen;
115
116 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000117 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000118
hasso53c997c2004-09-15 16:21:59 +0000119 while (offsetloop--)
120 if (addr1[offsetloop] != addr2[offsetloop])
121 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000122
hassof390d2c2004-09-10 20:48:21 +0000123 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000124 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
125 return 0;
hassof390d2c2004-09-10 20:48:21 +0000126
127 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000128}
129
jardineb5d44e2003-12-23 08:09:43 +0000130/*
131 * Compares two set of ip addresses
132 * param left the local interface's ip addresses
133 * param right the iih interface's ip address
134 * return 0 no match;
135 * 1 match;
136 */
hassof390d2c2004-09-10 20:48:21 +0000137static int
jardineb5d44e2003-12-23 08:09:43 +0000138ip_match (struct list *left, struct list *right)
139{
140 struct prefix_ipv4 *ip1;
141 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000142 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000143
hassoe082ac12004-09-27 18:13:57 +0000144 if ((left == NULL) || (right == NULL))
145 return 0;
146
hasso3fdb2dd2005-09-28 18:45:54 +0000147 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000148 {
hasso3fdb2dd2005-09-28 18:45:54 +0000149 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000150 {
151 if (ip_same_subnet (ip1, ip2))
152 {
153 return 1; /* match */
154 }
jardineb5d44e2003-12-23 08:09:43 +0000155 }
hassof390d2c2004-09-10 20:48:21 +0000156
jardineb5d44e2003-12-23 08:09:43 +0000157 }
158 return 0;
159}
160
161/*
162 * Checks whether we should accept a PDU of given level
163 */
164static int
165accept_level (int level, int circuit_t)
166{
hassof390d2c2004-09-10 20:48:21 +0000167 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000168
169 return retval;
170}
171
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400172
173/*
174 * Verify authentication information
175 * Support cleartext and HMAC MD5 authentication
176 */
hassof390d2c2004-09-10 20:48:21 +0000177int
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400178authentication_check (struct isis_passwd *remote, struct isis_passwd *local, struct isis_circuit* c)
jardineb5d44e2003-12-23 08:09:43 +0000179{
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400180 unsigned char digest[ISIS_AUTH_MD5_SIZE];
181
182 if (c->passwd.type)
hassof390d2c2004-09-10 20:48:21 +0000183 {
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400184 switch (c->passwd.type)
hassof390d2c2004-09-10 20:48:21 +0000185 {
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400186 case ISIS_PASSWD_TYPE_HMAC_MD5:
187 /* HMAC MD5 (RFC 3567) */
188 /* MD5 computation according to RFC 2104 */
189 hmac_md5(c->rcv_stream->data, stream_get_endp(c->rcv_stream), (unsigned char *) &(local->passwd), c->passwd.len, (unsigned char *) &digest);
190 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
191 break;
hassof390d2c2004-09-10 20:48:21 +0000192 case ISIS_PASSWD_TYPE_CLEARTXT:
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400193 /* Cleartext (ISO 10589) */
194 if (local->len != remote->len)
hassof390d2c2004-09-10 20:48:21 +0000195 return 1; /* Auth fail () - passwd len mismatch */
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400196 return memcmp (local->passwd, remote->passwd, local->len);
hassof390d2c2004-09-10 20:48:21 +0000197 break;
198 default:
199 zlog_warn ("Unsupported authentication type");
200 break;
201 }
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400202 }
203 return 0; /* Authentication pass when no authentication is configured */
jardineb5d44e2003-12-23 08:09:43 +0000204}
205
206/*
207 * Processing helper functions
208 */
hasso92365882005-01-18 13:53:33 +0000209static void
hassof390d2c2004-09-10 20:48:21 +0000210tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000211{
212 int i;
213 struct nlpids *tlv_nlpids;
214
hassof390d2c2004-09-10 20:48:21 +0000215 if (tlvs->nlpids)
216 {
jardineb5d44e2003-12-23 08:09:43 +0000217
hassof390d2c2004-09-10 20:48:21 +0000218 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000219
hassof390d2c2004-09-10 20:48:21 +0000220 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000221
hassof390d2c2004-09-10 20:48:21 +0000222 for (i = 0; i < tlv_nlpids->count; i++)
223 {
224 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
225 }
jardineb5d44e2003-12-23 08:09:43 +0000226 }
jardineb5d44e2003-12-23 08:09:43 +0000227}
228
hasso92365882005-01-18 13:53:33 +0000229static void
jardineb5d44e2003-12-23 08:09:43 +0000230del_ip_addr (void *val)
231{
232 XFREE (MTYPE_ISIS_TMP, val);
233}
234
hasso92365882005-01-18 13:53:33 +0000235static void
hassof390d2c2004-09-10 20:48:21 +0000236tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000237{
hasso3fdb2dd2005-09-28 18:45:54 +0000238 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000239 struct in_addr *ipv4_addr, *malloced;
240
hassof390d2c2004-09-10 20:48:21 +0000241 if (adj->ipv4_addrs)
242 {
243 adj->ipv4_addrs->del = del_ip_addr;
244 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000245 }
hassof390d2c2004-09-10 20:48:21 +0000246 adj->ipv4_addrs = list_new ();
247 if (tlvs->ipv4_addrs)
248 {
hasso3fdb2dd2005-09-28 18:45:54 +0000249 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000250 {
251 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
252 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
253 listnode_add (adj->ipv4_addrs, malloced);
254 }
255 }
jardineb5d44e2003-12-23 08:09:43 +0000256}
257
258#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000259static void
hassof390d2c2004-09-10 20:48:21 +0000260tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000261{
hasso3fdb2dd2005-09-28 18:45:54 +0000262 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000263 struct in6_addr *ipv6_addr, *malloced;
264
hassof390d2c2004-09-10 20:48:21 +0000265 if (adj->ipv6_addrs)
266 {
267 adj->ipv6_addrs->del = del_ip_addr;
268 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000269 }
hassof390d2c2004-09-10 20:48:21 +0000270 adj->ipv6_addrs = list_new ();
271 if (tlvs->ipv6_addrs)
272 {
hasso3fdb2dd2005-09-28 18:45:54 +0000273 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000274 {
275 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
276 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
277 listnode_add (adj->ipv6_addrs, malloced);
278 }
279 }
jardineb5d44e2003-12-23 08:09:43 +0000280
281}
282#endif /* HAVE_IPV6 */
283
jardineb5d44e2003-12-23 08:09:43 +0000284/*
285 * RECEIVE SIDE
286 */
287
288/*
289 * Process P2P IIH
290 * ISO - 10589
291 * Section 8.2.5 - Receiving point-to-point IIH PDUs
292 *
293 */
294static int
295process_p2p_hello (struct isis_circuit *circuit)
296{
297 int retval = ISIS_OK;
298 struct isis_p2p_hello_hdr *hdr;
299 struct isis_adjacency *adj;
300 u_int32_t expected = 0, found;
301 struct tlvs tlvs;
302
hassof390d2c2004-09-10 20:48:21 +0000303 if ((stream_get_endp (circuit->rcv_stream) -
304 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
305 {
306 zlog_warn ("Packet too short");
307 return ISIS_WARNING;
308 }
jardineb5d44e2003-12-23 08:09:43 +0000309
310 /* 8.2.5.1 PDU acceptance tests */
311
312 /* 8.2.5.1 a) external domain untrue */
313 /* FIXME: not useful at all? */
314
315 /* 8.2.5.1 b) ID Length mismatch */
316 /* checked at the handle_pdu */
317
318 /* 8.2.5.2 IIH PDU Processing */
319
320 /* 8.2.5.2 a) 1) Maximum Area Addresses */
321 /* Already checked, and can also be ommited */
322
323 /*
324 * Get the header
325 */
hassof390d2c2004-09-10 20:48:21 +0000326 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000327 circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
328
329 /* hdr.circuit_t = stream_getc (stream);
hassof390d2c2004-09-10 20:48:21 +0000330 stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
331 hdr.hold_time = stream_getw (stream);
332 hdr.pdu_len = stream_getw (stream);
333 hdr.local_id = stream_getc (stream); */
jardineb5d44e2003-12-23 08:09:43 +0000334
335 /*
336 * My interpertation of the ISO, if no adj exists we will create one for
337 * the circuit
338 */
339
hassof390d2c2004-09-10 20:48:21 +0000340 if (isis->debugs & DEBUG_ADJ_PACKETS)
341 {
hasso529d65b2004-12-24 00:14:50 +0000342 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
343 " cir id %02d, length %d",
344 circuit->area->area_tag, circuit->interface->name,
345 circuit_t2string (circuit->circuit_is_type),
346 circuit->circuit_id, ntohs (hdr->pdu_len));
hassof390d2c2004-09-10 20:48:21 +0000347 }
jardineb5d44e2003-12-23 08:09:43 +0000348
349 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +0000350 if (!adj)
351 {
Paul Jakma41b36e92006-12-08 01:09:50 +0000352 adj = isis_new_adj (hdr->source_id, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +0000353 if (adj == NULL)
354 return ISIS_ERROR;
355 circuit->u.p2p.neighbor = adj;
356 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
357 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
358 }
jardineb5d44e2003-12-23 08:09:43 +0000359
360 /* 8.2.6 Monitoring point-to-point adjacencies */
361 adj->hold_time = ntohs (hdr->hold_time);
hassof390d2c2004-09-10 20:48:21 +0000362 adj->last_upd = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000363
364 /*
365 * Lets get the TLVS now
366 */
367 expected |= TLVFLAG_AREA_ADDRS;
368 expected |= TLVFLAG_AUTH_INFO;
369 expected |= TLVFLAG_NLPID;
370 expected |= TLVFLAG_IPV4_ADDR;
371 expected |= TLVFLAG_IPV6_ADDR;
372
373 retval = parse_tlvs (circuit->area->area_tag,
374 STREAM_PNT (circuit->rcv_stream),
hassof390d2c2004-09-10 20:48:21 +0000375 ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
376 - ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000377
hassof390d2c2004-09-10 20:48:21 +0000378 if (retval > ISIS_WARNING)
379 {
380 free_tlvs (&tlvs);
381 return retval;
382 };
jardineb5d44e2003-12-23 08:09:43 +0000383
384 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000385 if (circuit->passwd.type)
386 {
387 if (!(found & TLVFLAG_AUTH_INFO) ||
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400388 authentication_check (&tlvs.auth_info, &circuit->passwd, circuit))
hassof390d2c2004-09-10 20:48:21 +0000389 {
390 isis_event_auth_failure (circuit->area->area_tag,
391 "P2P hello authentication failure",
392 hdr->source_id);
393 return ISIS_OK;
394 }
jardineb5d44e2003-12-23 08:09:43 +0000395 }
jardineb5d44e2003-12-23 08:09:43 +0000396
397 /* we do this now because the adj may not survive till the end... */
398
399 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000400 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000401
402#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000403 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000404#endif /* HAVE_IPV6 */
405
406 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000407 THREAD_TIMER_OFF (adj->t_expire);
408 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
409 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000410
411 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000412 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
413 {
414 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
415 if (circuit->area->is_type == IS_LEVEL_1)
416 {
417 switch (hdr->circuit_t)
418 {
419 case IS_LEVEL_1:
420 case IS_LEVEL_1_AND_2:
421 if (adj->adj_state != ISIS_ADJ_UP)
422 {
423 /* (4) adj state up */
424 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
425 /* (5) adj usage level 1 */
426 adj->adj_usage = ISIS_ADJ_LEVEL1;
427 }
428 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
429 {
430 ; /* accept */
431 }
432 break;
433 case IS_LEVEL_2:
434 if (adj->adj_state != ISIS_ADJ_UP)
435 {
436 /* (7) reject - wrong system type event */
437 zlog_warn ("wrongSystemType");
438 return ISIS_WARNING; /* Reject */
439 }
440 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
441 {
442 /* (6) down - wrong system */
443 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
444 }
445 break;
446 }
447 }
jardineb5d44e2003-12-23 08:09:43 +0000448
hassof390d2c2004-09-10 20:48:21 +0000449 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
450 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
451 {
452 switch (hdr->circuit_t)
453 {
454 case IS_LEVEL_1:
455 if (adj->adj_state != ISIS_ADJ_UP)
456 {
457 /* (6) adj state up */
458 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
459 /* (7) adj usage level 1 */
460 adj->adj_usage = ISIS_ADJ_LEVEL1;
461 }
462 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
463 {
464 ; /* accept */
465 }
466 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
467 (adj->adj_usage == ISIS_ADJ_LEVEL2))
468 {
469 /* (8) down - wrong system */
470 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
471 }
472 break;
473 case IS_LEVEL_2:
474 if (adj->adj_state != ISIS_ADJ_UP)
475 {
476 /* (6) adj state up */
477 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
478 /* (9) adj usage level 2 */
479 adj->adj_usage = ISIS_ADJ_LEVEL2;
480 }
481 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
482 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
483 {
484 /* (8) down - wrong system */
485 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
486 }
487 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
488 {
489 ; /* Accept */
490 }
491 break;
492 case IS_LEVEL_1_AND_2:
493 if (adj->adj_state != ISIS_ADJ_UP)
494 {
495 /* (6) adj state up */
496 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
497 /* (10) adj usage level 1 */
498 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
499 }
500 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
501 (adj->adj_usage == ISIS_ADJ_LEVEL2))
502 {
503 /* (8) down - wrong system */
504 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
505 }
506 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
507 {
508 ; /* Accept */
509 }
510 break;
511 }
512 }
jardineb5d44e2003-12-23 08:09:43 +0000513
hassof390d2c2004-09-10 20:48:21 +0000514 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
515 if (circuit->area->is_type == IS_LEVEL_2)
516 {
517 switch (hdr->circuit_t)
518 {
519 case IS_LEVEL_1:
520 if (adj->adj_state != ISIS_ADJ_UP)
521 {
522 /* (5) reject - wrong system type event */
523 zlog_warn ("wrongSystemType");
524 return ISIS_WARNING; /* Reject */
525 }
526 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
527 (adj->adj_usage == ISIS_ADJ_LEVEL2))
528 {
529 /* (6) down - wrong system */
530 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
531 }
532 break;
533 case IS_LEVEL_1_AND_2:
534 case IS_LEVEL_2:
535 if (adj->adj_state != ISIS_ADJ_UP)
536 {
537 /* (7) adj state up */
538 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
539 /* (8) adj usage level 2 */
540 adj->adj_usage = ISIS_ADJ_LEVEL2;
541 }
542 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
543 {
544 /* (6) down - wrong system */
545 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
546 }
547 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
548 {
549 ; /* Accept */
550 }
551 break;
552 }
553 }
jardineb5d44e2003-12-23 08:09:43 +0000554 }
jardineb5d44e2003-12-23 08:09:43 +0000555 /* 8.2.5.2 b) if no match was detected */
556 else
jardineb5d44e2003-12-23 08:09:43 +0000557 {
hassof390d2c2004-09-10 20:48:21 +0000558 if (circuit->area->is_type == IS_LEVEL_1)
559 {
560 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
561 if (adj->adj_state != ISIS_ADJ_UP)
562 {
563 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
564 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
565 }
566 else
567 {
568 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
569 "Down - Area Mismatch");
570 }
571 }
572 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
573 else
574 {
575 switch (hdr->circuit_t)
576 {
577 case IS_LEVEL_1:
578 if (adj->adj_state != ISIS_ADJ_UP)
579 {
580 /* (6) reject - Area Mismatch event */
581 zlog_warn ("AreaMismatch");
582 return ISIS_WARNING; /* Reject */
583 }
584 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
585 {
586 /* (7) down - area mismatch */
587 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000588
hassof390d2c2004-09-10 20:48:21 +0000589 }
590 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
591 (adj->adj_usage == ISIS_ADJ_LEVEL2))
592 {
593 /* (7) down - wrong system */
594 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
595 }
596 break;
597 case IS_LEVEL_1_AND_2:
598 case IS_LEVEL_2:
599 if (adj->adj_state != ISIS_ADJ_UP)
600 {
601 /* (8) adj state up */
602 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
603 /* (9) adj usage level 2 */
604 adj->adj_usage = ISIS_ADJ_LEVEL2;
605 }
606 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
607 {
608 /* (7) down - wrong system */
609 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
610 }
611 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
612 {
613 if (hdr->circuit_t == IS_LEVEL_2)
614 {
615 /* (7) down - wrong system */
616 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
617 "Wrong System");
618 }
619 else
620 {
621 /* (7) down - area mismatch */
622 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
623 "Area Mismatch");
624 }
625 }
626 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
627 {
628 ; /* Accept */
629 }
630 break;
631 }
632 }
jardineb5d44e2003-12-23 08:09:43 +0000633 }
jardineb5d44e2003-12-23 08:09:43 +0000634 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
635 /* FIXME - Missing parts */
636
jardineb5d44e2003-12-23 08:09:43 +0000637 /* some of my own understanding of the ISO, why the heck does
638 * it not say what should I change the system_type to...
639 */
hassof390d2c2004-09-10 20:48:21 +0000640 switch (adj->adj_usage)
641 {
jardineb5d44e2003-12-23 08:09:43 +0000642 case ISIS_ADJ_LEVEL1:
643 adj->sys_type = ISIS_SYSTYPE_L1_IS;
644 break;
645 case ISIS_ADJ_LEVEL2:
646 adj->sys_type = ISIS_SYSTYPE_L2_IS;
647 break;
648 case ISIS_ADJ_LEVEL1AND2:
649 adj->sys_type = ISIS_SYSTYPE_L2_IS;
650 break;
651 case ISIS_ADJ_NONE:
652 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
653 break;
hassof390d2c2004-09-10 20:48:21 +0000654 }
jardineb5d44e2003-12-23 08:09:43 +0000655
656 adj->circuit_t = hdr->circuit_t;
657 adj->level = hdr->circuit_t;
658
659 free_tlvs (&tlvs);
660
661 return retval;
662}
663
jardineb5d44e2003-12-23 08:09:43 +0000664/*
665 * Process IS-IS LAN Level 1/2 Hello PDU
666 */
hassof390d2c2004-09-10 20:48:21 +0000667static int
668process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000669{
670 int retval = ISIS_OK;
671 struct isis_lan_hello_hdr hdr;
672 struct isis_adjacency *adj;
673 u_int32_t expected = 0, found;
674 struct tlvs tlvs;
675 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000676 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000677
hassof390d2c2004-09-10 20:48:21 +0000678 if ((stream_get_endp (circuit->rcv_stream) -
679 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
680 {
681 zlog_warn ("Packet too short");
682 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000683 }
hassof390d2c2004-09-10 20:48:21 +0000684
685 if (circuit->ext_domain)
686 {
hasso529d65b2004-12-24 00:14:50 +0000687 zlog_debug ("level %d LAN Hello received over circuit with "
688 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000689 return ISIS_WARNING;
690 }
691
692 if (!accept_level (level, circuit->circuit_is_type))
693 {
694 if (isis->debugs & DEBUG_ADJ_PACKETS)
695 {
hasso529d65b2004-12-24 00:14:50 +0000696 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
697 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000698 }
699 return ISIS_WARNING;
700 }
jardineb5d44e2003-12-23 08:09:43 +0000701
702#if 0
703 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000704 if (!accept_level (level, circuit->area->is_type))
705 {
706 if (isis->debugs & DEBUG_ADJ_PACKETS)
707 {
hasso529d65b2004-12-24 00:14:50 +0000708 zlog_debug ("ISIS-Adj (%s): is type mismatch",
709 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000710 }
711 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000712 }
jardineb5d44e2003-12-23 08:09:43 +0000713#endif
714 /*
715 * Fill the header
716 */
717 hdr.circuit_t = stream_getc (circuit->rcv_stream);
718 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
719 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000720 hdr.pdu_len = stream_getw (circuit->rcv_stream);
721 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000722 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
723
724 if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hassof390d2c2004-09-10 20:48:21 +0000725 hdr.circuit_t != IS_LEVEL_1_AND_2)
726 {
727 zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
728 hdr.circuit_t);
729 return ISIS_ERROR;
730 }
jardineb5d44e2003-12-23 08:09:43 +0000731 /*
732 * Then get the tlvs
733 */
734 expected |= TLVFLAG_AUTH_INFO;
735 expected |= TLVFLAG_AREA_ADDRS;
736 expected |= TLVFLAG_LAN_NEIGHS;
737 expected |= TLVFLAG_NLPID;
738 expected |= TLVFLAG_IPV4_ADDR;
739 expected |= TLVFLAG_IPV6_ADDR;
740
741 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +0000742 STREAM_PNT (circuit->rcv_stream),
743 hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
744 ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000745
hassof390d2c2004-09-10 20:48:21 +0000746 if (retval > ISIS_WARNING)
747 {
748 zlog_warn ("parse_tlvs() failed");
749 goto out;
750 }
jardineb5d44e2003-12-23 08:09:43 +0000751
hassof390d2c2004-09-10 20:48:21 +0000752 if (!(found & TLVFLAG_AREA_ADDRS))
753 {
754 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
755 level);
jardineb5d44e2003-12-23 08:09:43 +0000756 retval = ISIS_WARNING;
757 goto out;
758 }
hassof390d2c2004-09-10 20:48:21 +0000759
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400760 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +0000761 if (circuit->passwd.type)
762 {
763 if (!(found & TLVFLAG_AUTH_INFO) ||
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400764 authentication_check (&tlvs.auth_info, &circuit->passwd, circuit))
hassof390d2c2004-09-10 20:48:21 +0000765 {
766 isis_event_auth_failure (circuit->area->area_tag,
767 "LAN hello authentication failure",
768 hdr.source_id);
769 retval = ISIS_WARNING;
770 goto out;
771 }
772 }
jardineb5d44e2003-12-23 08:09:43 +0000773
774 /*
775 * Accept the level 1 adjacency only if a match between local and
776 * remote area addresses is found
777 */
hassof390d2c2004-09-10 20:48:21 +0000778 if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
779 {
780 if (isis->debugs & DEBUG_ADJ_PACKETS)
781 {
hasso529d65b2004-12-24 00:14:50 +0000782 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
783 circuit->area->area_tag, level,
784 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000785 }
786 retval = ISIS_OK;
787 goto out;
jardineb5d44e2003-12-23 08:09:43 +0000788 }
jardineb5d44e2003-12-23 08:09:43 +0000789
790 /*
791 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +0000792 */
793 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
794 {
hasso529d65b2004-12-24 00:14:50 +0000795 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
796 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000797
hassof390d2c2004-09-10 20:48:21 +0000798 retval = ISIS_OK;
799 goto out;
800 }
jardineb5d44e2003-12-23 08:09:43 +0000801
802 /*
803 * check if it's own interface ip match iih ip addrs
804 */
hassof390d2c2004-09-10 20:48:21 +0000805 if (!(found & TLVFLAG_IPV4_ADDR)
806 || !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
807 {
hasso529d65b2004-12-24 00:14:50 +0000808 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000809 ("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
810 circuit->interface->name);
811 retval = ISIS_WARNING;
812 goto out;
813 }
jardineb5d44e2003-12-23 08:09:43 +0000814
815 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000816 if (!adj)
817 {
818 /*
819 * Do as in 8.4.2.5
820 */
821 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
822 if (adj == NULL)
hasso13c48f72004-09-10 21:19:13 +0000823 {
824 retval = ISIS_ERROR;
825 goto out;
826 }
jardineb5d44e2003-12-23 08:09:43 +0000827
hassof390d2c2004-09-10 20:48:21 +0000828 adj->level = level;
829 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +0000830
hassof390d2c2004-09-10 20:48:21 +0000831 if (level == 1)
832 {
833 adj->sys_type = ISIS_SYSTYPE_L1_IS;
834 }
835 else
836 {
837 adj->sys_type = ISIS_SYSTYPE_L2_IS;
838 }
839 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
840 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
841 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000842 }
jardineb5d44e2003-12-23 08:09:43 +0000843
hassoa211d652004-09-20 14:55:29 +0000844 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
845 switch (level)
846 {
847 case 1:
848 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
849 {
850 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000851 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
852 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000853 }
854 break;
855 case 2:
856 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
857 {
858 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +0000859 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
860 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +0000861 }
862 break;
863 }
jardineb5d44e2003-12-23 08:09:43 +0000864
865 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +0000866 adj->last_upd = time (NULL);
867 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +0000868
869 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
870
871 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +0000872 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +0000873 tlvs_to_adj_nlpids (&tlvs, adj);
874
875 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +0000876 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000877 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
878
879#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000880 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +0000881 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
882#endif /* HAVE_IPV6 */
883
884 adj->circuit_t = hdr.circuit_t;
885
886 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000887 THREAD_TIMER_OFF (adj->t_expire);
888 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
889 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000890
891 /*
892 * If the snpa for this circuit is found from LAN Neighbours TLV
893 * we have two-way communication -> adjacency can be put to state "up"
894 */
895
hassof390d2c2004-09-10 20:48:21 +0000896 if (found & TLVFLAG_LAN_NEIGHS)
897 {
898 if (adj->adj_state != ISIS_ADJ_UP)
899 {
hasso3fdb2dd2005-09-28 18:45:54 +0000900 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
hassof390d2c2004-09-10 20:48:21 +0000901 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
902 {
903 isis_adj_state_change (adj, ISIS_ADJ_UP,
904 "own SNPA found in LAN Neighbours TLV");
905 }
906 }
jardineb5d44e2003-12-23 08:09:43 +0000907 }
jardineb5d44e2003-12-23 08:09:43 +0000908
hassof390d2c2004-09-10 20:48:21 +0000909out:
jardineb5d44e2003-12-23 08:09:43 +0000910 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +0000911 if (isis->debugs & DEBUG_ADJ_PACKETS)
912 {
913 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +0000914 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
915 "cirID %u, length %ld",
916 circuit->area->area_tag,
917 level, snpa_print (ssnpa), circuit->interface->name,
918 circuit_t2string (circuit->circuit_is_type),
hasso29e50b22005-09-01 18:18:47 +0000919 circuit->circuit_id,
920 /* FIXME: use %z when we stop supporting old compilers. */
921 (unsigned long) stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +0000922 }
jardineb5d44e2003-12-23 08:09:43 +0000923
924 free_tlvs (&tlvs);
925
926 return retval;
927}
928
929/*
930 * Process Level 1/2 Link State
931 * ISO - 10589
932 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +0000933 */
934static int
935process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000936{
937 struct isis_link_state_hdr *hdr;
938 struct isis_adjacency *adj = NULL;
939 struct isis_lsp *lsp, *lsp0 = NULL;
940 int retval = ISIS_OK, comp = 0;
941 u_char lspid[ISIS_SYS_ID_LEN + 2];
942 struct isis_passwd *passwd;
943
944 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +0000945 if ((stream_get_endp (circuit->rcv_stream) -
946 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
947 {
948 zlog_warn ("Packet too short");
949 return ISIS_WARNING;
950 }
jardineb5d44e2003-12-23 08:09:43 +0000951
952 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +0000953 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000954
hassof390d2c2004-09-10 20:48:21 +0000955 if (isis->debugs & DEBUG_UPDATE_PACKETS)
956 {
hasso529d65b2004-12-24 00:14:50 +0000957 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
958 "lifetime %us, len %lu, on %s",
959 circuit->area->area_tag,
960 level,
961 rawlspid_print (hdr->lsp_id),
962 ntohl (hdr->seq_num),
963 ntohs (hdr->checksum),
964 ntohs (hdr->rem_lifetime),
hasso29e50b22005-09-01 18:18:47 +0000965 /* FIXME: use %z when we stop supporting old compilers. */
966 (unsigned long) stream_get_endp (circuit->rcv_stream),
paul15935e92005-05-03 09:27:23 +0000967 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000968 }
jardineb5d44e2003-12-23 08:09:43 +0000969
970 assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
971
972 /* Checksum sanity check - FIXME: move to correct place */
973 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +0000974 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
975 ntohs (hdr->pdu_len) - 12, &hdr->checksum))
976 {
hasso529d65b2004-12-24 00:14:50 +0000977 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
978 circuit->area->area_tag,
979 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000980
hassof390d2c2004-09-10 20:48:21 +0000981 return ISIS_WARNING;
982 }
jardineb5d44e2003-12-23 08:09:43 +0000983
984 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +0000985 if (circuit->ext_domain)
986 {
hasso529d65b2004-12-24 00:14:50 +0000987 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000988 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
989 "externalDomain = true", circuit->area->area_tag,
990 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +0000991
hassof390d2c2004-09-10 20:48:21 +0000992 return ISIS_WARNING;
993 }
jardineb5d44e2003-12-23 08:09:43 +0000994
995 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
hassof390d2c2004-09-10 20:48:21 +0000996 if (!accept_level (level, circuit->circuit_is_type))
997 {
hasso529d65b2004-12-24 00:14:50 +0000998 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
999 " type %s",
1000 circuit->area->area_tag,
1001 rawlspid_print (hdr->lsp_id),
1002 level, circuit_t2string (circuit->circuit_is_type));
jardineb5d44e2003-12-23 08:09:43 +00001003
hassof390d2c2004-09-10 20:48:21 +00001004 return ISIS_WARNING;
1005 }
jardineb5d44e2003-12-23 08:09:43 +00001006
1007 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1008
1009 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1010
1011 /* 7.3.15.1 a) 7 - password check */
1012 (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
1013 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001014 if (passwd->type)
1015 {
1016 if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area,
1017 ntohs (hdr->pdu_len), passwd))
1018 {
1019 isis_event_auth_failure (circuit->area->area_tag,
1020 "LSP authentication failure", hdr->lsp_id);
1021 return ISIS_WARNING;
1022 }
jardineb5d44e2003-12-23 08:09:43 +00001023 }
jardineb5d44e2003-12-23 08:09:43 +00001024 /* Find the LSP in our database and compare it to this Link State header */
1025 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1026 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001027 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1028 hdr->checksum, hdr->rem_lifetime);
1029 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001030#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001031 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001032#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001033 ))
jardineb5d44e2003-12-23 08:09:43 +00001034 goto dontcheckadj;
1035
1036 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1037 /* for broadcast circuits, snpa should be compared */
1038 /* FIXME : Point To Point */
1039
hassof390d2c2004-09-10 20:48:21 +00001040 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1041 {
1042 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1043 if (!adj)
1044 {
hasso529d65b2004-12-24 00:14:50 +00001045 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1046 "lifetime %us on %s",
1047 circuit->area->area_tag,
1048 rawlspid_print (hdr->lsp_id),
1049 ntohl (hdr->seq_num),
1050 ntohs (hdr->checksum),
1051 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001052 return ISIS_WARNING; /* Silently discard */
1053 }
jardineb5d44e2003-12-23 08:09:43 +00001054 }
jardineb5d44e2003-12-23 08:09:43 +00001055
1056 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001057 else
1058 {
1059 /* If no adj, or no sharing of level */
1060 if (!circuit->u.p2p.neighbor)
1061 {
1062 return ISIS_OK; /* Silently discard */
1063 }
1064 else
1065 {
1066 if (((level == 1) &&
1067 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1068 ((level == 2) &&
1069 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1070 return ISIS_WARNING; /* Silently discard */
1071 }
jardineb5d44e2003-12-23 08:09:43 +00001072 }
hassof390d2c2004-09-10 20:48:21 +00001073dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001074 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1075
1076 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1077
hassof390d2c2004-09-10 20:48:21 +00001078 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001079
hassof390d2c2004-09-10 20:48:21 +00001080 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1081 if (hdr->rem_lifetime == 0)
1082 {
1083 if (!lsp)
1084 {
1085 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1086 /* only needed on explicit update, eg - p2p */
1087 if (circuit->circ_type == CIRCUIT_T_P2P)
1088 ack_lsp (hdr, circuit, level);
1089 return retval; /* FIXME: do we need a purge? */
1090 }
1091 else
1092 {
1093 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1094 {
1095 /* LSP by some other system -> do 7.3.16.4 b) */
1096 /* 7.3.16.4 b) 1) */
1097 if (comp == LSP_NEWER)
1098 {
hassoa96d8d12005-09-16 14:44:23 +00001099 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area,
1100 level);
hassof390d2c2004-09-10 20:48:21 +00001101 /* ii */
1102 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1103 /* iii */
1104 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1105 /* v */
1106 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1107 /* iv */
1108 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1109 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001110
hassof390d2c2004-09-10 20:48:21 +00001111 } /* 7.3.16.4 b) 2) */
1112 else if (comp == LSP_EQUAL)
1113 {
1114 /* i */
1115 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1116 /* ii */
1117 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1118 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1119 } /* 7.3.16.4 b) 3) */
1120 else
1121 {
1122 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1123 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1124 }
1125 }
1126 else
1127 {
1128 /* our own LSP -> 7.3.16.4 c) */
1129 if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) !=
1130 circuit->circuit_id
1131 || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) ==
1132 circuit->circuit_id
1133 && circuit->u.bc.is_dr[level - 1] == 1))
1134 {
1135 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
hassoc89c05d2005-09-04 21:36:36 +00001136 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1137 zlog_debug ("LSP LEN: %d",
1138 ntohs (lsp->lsp_header->pdu_len));
Jingjing Duan6a270cd2008-08-13 19:09:10 +01001139 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00001140 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1141 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001142 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1143 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1144 "seq 0x%08x", circuit->area->area_tag,
1145 rawlspid_print (hdr->lsp_id),
1146 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001147 lsp->lsp_header->rem_lifetime =
1148 htons (isis_jitter
1149 (circuit->area->max_lsp_lifetime[level - 1],
1150 MAX_AGE_JITTER));
1151 }
1152 else
1153 {
1154 /* Got purge for own pseudo-lsp, and we are not DR */
1155 lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level);
1156 }
1157 }
1158 }
1159 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001160 }
jardineb5d44e2003-12-23 08:09:43 +00001161 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1162 * purge */
hassof390d2c2004-09-10 20:48:21 +00001163 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1164 {
1165 if (!lsp)
1166 {
1167 /* 7.3.16.4: initiate a purge */
1168 lsp_purge_non_exist (hdr, circuit->area);
1169 return ISIS_OK;
1170 }
1171 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1172
1173 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1174 * has information that the current sequence number for source S is
1175 * "greater" than that held by S, ... */
1176
1177 else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1178 {
1179 /* 7.3.16.1 */
1180 lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1);
1181
Jingjing Duan6a270cd2008-08-13 19:09:10 +01001182 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00001183 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1184
1185 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassoc89c05d2005-09-04 21:36:36 +00001186 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1187 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1188 "0x%08x", circuit->area->area_tag,
1189 rawlspid_print (hdr->lsp_id),
1190 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001191 lsp->lsp_header->rem_lifetime =
1192 htons (isis_jitter
1193 (circuit->area->max_lsp_lifetime[level - 1],
1194 MAX_AGE_JITTER));
1195 }
jardineb5d44e2003-12-23 08:09:43 +00001196 }
hassof390d2c2004-09-10 20:48:21 +00001197 else
1198 {
1199 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001200
hassof390d2c2004-09-10 20:48:21 +00001201 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1202 if ((!lsp || comp == LSP_NEWER))
1203 {
Peter Szilagyi907fd952011-10-01 17:15:46 +04001204 int regenerate = (lsp == NULL);
hassof390d2c2004-09-10 20:48:21 +00001205 /* i */
1206 if (lsp)
1207 {
jardineb5d44e2003-12-23 08:09:43 +00001208#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001209 zlog_debug ("level %d number is - %ld", level,
1210 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001211#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001212 lsp_search_and_destroy (hdr->lsp_id,
1213 circuit->area->lspdb[level - 1]);
1214 /* exists, so we overwrite */
jardineb5d44e2003-12-23 08:09:43 +00001215#ifdef EXTREME_DEBUG
hasso529d65b2004-12-24 00:14:50 +00001216 zlog_debug ("level %d number is - %ld", level,
1217 circuit->area->lspdb[level - 1]->dict_nodecount);
jardineb5d44e2003-12-23 08:09:43 +00001218#endif /* EXTREME DEBUG */
hassof390d2c2004-09-10 20:48:21 +00001219 }
1220 /*
1221 * If this lsp is a frag, need to see if we have zero lsp present
1222 */
1223 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1224 {
1225 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1226 LSP_FRAGMENT (lspid) = 0;
1227 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1228 if (!lsp0)
1229 {
hasso529d65b2004-12-24 00:14:50 +00001230 zlog_debug ("Got lsp frag, while zero lsp not database");
hassof390d2c2004-09-10 20:48:21 +00001231 return ISIS_OK;
1232 }
1233 }
1234 lsp =
1235 lsp_new_from_stream_ptr (circuit->rcv_stream,
1236 ntohs (hdr->pdu_len), lsp0,
1237 circuit->area);
1238 lsp->level = level;
hassof390d2c2004-09-10 20:48:21 +00001239 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1240 /* ii */
1241 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1242 /* iii */
1243 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001244
hassof390d2c2004-09-10 20:48:21 +00001245 /* iv */
1246 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1247 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1248 /* FIXME: v) */
Peter Szilagyi907fd952011-10-01 17:15:46 +04001249 if (regenerate && circuit->u.bc.is_dr[level - 1]) {
1250 lsp_l1_pseudo_generate (circuit);
1251 }
hassof390d2c2004-09-10 20:48:21 +00001252 }
1253 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1254 else if (comp == LSP_EQUAL)
1255 {
1256 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassoa96d8d12005-09-16 14:44:23 +00001257 lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001258 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1259 {
1260 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1261 }
1262 }
1263 /* 7.3.15.1 e) 3) LSP older than the one in db */
1264 else
1265 {
1266 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1267 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1268 }
jardineb5d44e2003-12-23 08:09:43 +00001269 }
Peter Szilagyid034aa02011-10-01 17:22:51 +04001270
jardineb5d44e2003-12-23 08:09:43 +00001271 return retval;
1272}
1273
1274/*
1275 * Process Sequence Numbers
1276 * ISO - 10589
1277 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1278 */
1279
hasso92365882005-01-18 13:53:33 +00001280static int
hassof390d2c2004-09-10 20:48:21 +00001281process_snp (int snp_type, int level, struct isis_circuit *circuit,
1282 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001283{
1284 int retval = ISIS_OK;
1285 int cmp, own_lsp;
1286 char typechar = ' ';
1287 int len;
1288 struct isis_adjacency *adj;
1289 struct isis_complete_seqnum_hdr *chdr = NULL;
1290 struct isis_partial_seqnum_hdr *phdr = NULL;
1291 uint32_t found = 0, expected = 0;
1292 struct isis_lsp *lsp;
1293 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001294 struct listnode *node, *nnode;
1295 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001296 struct tlvs tlvs;
1297 struct list *lsp_list = NULL;
1298 struct isis_passwd *passwd;
1299
hassof390d2c2004-09-10 20:48:21 +00001300 if (snp_type == ISIS_SNP_CSNP_FLAG)
1301 {
1302 /* getting the header info */
1303 typechar = 'C';
1304 chdr =
1305 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1306 circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN;
1307 len = ntohs (chdr->pdu_len);
1308 if (len < ISIS_CSNP_HDRLEN)
1309 {
1310 zlog_warn ("Received a CSNP with bogus length!");
1311 return ISIS_OK;
1312 }
jardineb5d44e2003-12-23 08:09:43 +00001313 }
hassof390d2c2004-09-10 20:48:21 +00001314 else
1315 {
1316 typechar = 'P';
1317 phdr =
1318 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1319 circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN;
1320 len = ntohs (phdr->pdu_len);
1321 if (len < ISIS_PSNP_HDRLEN)
1322 {
1323 zlog_warn ("Received a CSNP with bogus length!");
1324 return ISIS_OK;
1325 }
jardineb5d44e2003-12-23 08:09:43 +00001326 }
jardineb5d44e2003-12-23 08:09:43 +00001327
1328 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001329 if (circuit->ext_domain)
1330 {
jardineb5d44e2003-12-23 08:09:43 +00001331
hasso529d65b2004-12-24 00:14:50 +00001332 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1333 "skipping: circuit externalDomain = true",
1334 circuit->area->area_tag,
1335 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001336
1337 return ISIS_OK;
1338 }
hassof390d2c2004-09-10 20:48:21 +00001339
1340 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1341 if (!accept_level (level, circuit->circuit_is_type))
1342 {
1343
hasso529d65b2004-12-24 00:14:50 +00001344 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1345 "skipping: circuit type %s does not match level %d",
1346 circuit->area->area_tag,
1347 level,
1348 typechar,
1349 circuit->interface->name,
1350 circuit_t2string (circuit->circuit_is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001351
1352 return ISIS_OK;
1353 }
1354
1355 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1356 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1357 (circuit->circ_type == CIRCUIT_T_BROADCAST))
1358 {
1359 if (!circuit->u.bc.is_dr[level - 1])
1360 {
1361
hasso529d65b2004-12-24 00:14:50 +00001362 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1363 "skipping: we are not the DIS",
1364 circuit->area->area_tag,
1365 level,
1366 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001367
1368 return ISIS_OK;
1369 }
1370 }
jardineb5d44e2003-12-23 08:09:43 +00001371
1372 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1373
1374 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1375 * - already checked */
1376
1377 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1378 /* for broadcast circuits, snpa should be compared */
1379 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001380 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1381 {
1382 if (snp_type == ISIS_SNP_CSNP_FLAG)
1383 {
1384 adj =
1385 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1386 }
1387 else
1388 {
1389 /* a psnp on a broadcast, how lovely of Juniper :) */
1390 adj =
1391 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1392 }
1393 if (!adj)
1394 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001395 }
hassof390d2c2004-09-10 20:48:21 +00001396 else
1397 {
1398 if (!circuit->u.p2p.neighbor)
1399 return ISIS_OK; /* Silently discard */
1400 }
jardineb5d44e2003-12-23 08:09:43 +00001401
1402 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1403
1404 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1405
1406 memset (&tlvs, 0, sizeof (struct tlvs));
1407
1408 /* parse the SNP */
1409 expected |= TLVFLAG_LSP_ENTRIES;
1410 expected |= TLVFLAG_AUTH_INFO;
1411 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001412 STREAM_PNT (circuit->rcv_stream),
jardineb5d44e2003-12-23 08:09:43 +00001413 len - circuit->rcv_stream->getp,
hassof390d2c2004-09-10 20:48:21 +00001414 &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +00001415
hassof390d2c2004-09-10 20:48:21 +00001416 if (retval > ISIS_WARNING)
1417 {
1418 zlog_warn ("something went very wrong processing SNP");
1419 free_tlvs (&tlvs);
1420 return retval;
1421 }
jardineb5d44e2003-12-23 08:09:43 +00001422
hasso1cbc5622005-01-01 10:29:51 +00001423 if (level == 1)
1424 passwd = &circuit->area->area_passwd;
1425 else
1426 passwd = &circuit->area->domain_passwd;
1427
1428 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001429 {
hasso1cbc5622005-01-01 10:29:51 +00001430 if (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00001431 {
hasso1cbc5622005-01-01 10:29:51 +00001432 if (!(found & TLVFLAG_AUTH_INFO) ||
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04001433 authentication_check (&tlvs.auth_info, passwd, circuit))
hasso1cbc5622005-01-01 10:29:51 +00001434 {
1435 isis_event_auth_failure (circuit->area->area_tag,
1436 "SNP authentication" " failure",
1437 phdr ? phdr->source_id : chdr->source_id);
1438 return ISIS_OK;
1439 }
hassof390d2c2004-09-10 20:48:21 +00001440 }
1441 }
jardineb5d44e2003-12-23 08:09:43 +00001442
1443 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001444 if (isis->debugs & DEBUG_SNP_PACKETS)
1445 {
hasso529d65b2004-12-24 00:14:50 +00001446 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1447 circuit->area->area_tag,
1448 level,
1449 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001450 if (tlvs.lsp_entries)
1451 {
hasso3fdb2dd2005-09-28 18:45:54 +00001452 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001453 {
hasso529d65b2004-12-24 00:14:50 +00001454 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1455 " cksum 0x%04x, lifetime %us",
1456 circuit->area->area_tag,
1457 typechar,
1458 rawlspid_print (entry->lsp_id),
1459 ntohl (entry->seq_num),
1460 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001461 }
1462 }
jardineb5d44e2003-12-23 08:09:43 +00001463 }
jardineb5d44e2003-12-23 08:09:43 +00001464
1465 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001466 if (tlvs.lsp_entries)
1467 {
hasso3fdb2dd2005-09-28 18:45:54 +00001468 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001469 {
1470 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1471 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1472 if (lsp)
1473 {
1474 /* 7.3.15.2 b) 1) is this LSP newer */
1475 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1476 entry->checksum, entry->rem_lifetime);
1477 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1478 if (cmp == LSP_EQUAL)
1479 {
1480 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1481 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1482 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1483 }
1484 else if (cmp == LSP_OLDER)
1485 {
1486 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1487 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1488 }
1489 else
1490 {
1491 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1492 * on p2p */
1493 if (own_lsp)
1494 {
1495 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1496 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1497 }
1498 else
1499 {
1500 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1501 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1502 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1503 }
1504 }
1505 }
1506 else
1507 {
1508 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1509 * insert it and set SSN on it */
1510 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1511 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1512 {
1513 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1514 0, 0, entry->checksum, level);
1515 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1516 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1517 }
1518 }
jardineb5d44e2003-12-23 08:09:43 +00001519 }
1520 }
jardineb5d44e2003-12-23 08:09:43 +00001521
1522 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001523 if (snp_type == ISIS_SNP_CSNP_FLAG)
1524 {
1525 /*
1526 * Build a list from our own LSP db bounded with start_ and stop_lsp_id
1527 */
1528 lsp_list = list_new ();
1529 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1530 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001531
hassof390d2c2004-09-10 20:48:21 +00001532 /* Fixme: Find a better solution */
1533 if (tlvs.lsp_entries)
1534 {
paul1eb8ef22005-04-07 07:30:20 +00001535 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001536 {
paul1eb8ef22005-04-07 07:30:20 +00001537 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001538 {
1539 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1540 {
1541 list_delete_node (lsp_list, node2);
1542 break;
1543 }
1544 }
1545 }
1546 }
1547 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001548 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001549 {
1550 ISIS_SET_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001551 }
hassof390d2c2004-09-10 20:48:21 +00001552 /* lets free it */
1553 list_free (lsp_list);
jardineb5d44e2003-12-23 08:09:43 +00001554 }
jardineb5d44e2003-12-23 08:09:43 +00001555
1556 free_tlvs (&tlvs);
1557 return retval;
1558}
1559
hasso92365882005-01-18 13:53:33 +00001560static int
hassof390d2c2004-09-10 20:48:21 +00001561process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001562{
jardineb5d44e2003-12-23 08:09:43 +00001563 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001564 if ((stream_get_endp (circuit->rcv_stream) -
1565 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1566 {
1567 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1568 return ISIS_WARNING;
1569 }
jardineb5d44e2003-12-23 08:09:43 +00001570
1571 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1572}
1573
hasso92365882005-01-18 13:53:33 +00001574static int
hassof390d2c2004-09-10 20:48:21 +00001575process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001576{
hassof390d2c2004-09-10 20:48:21 +00001577 if ((stream_get_endp (circuit->rcv_stream) -
1578 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1579 {
1580 zlog_warn ("Packet too short");
1581 return ISIS_WARNING;
1582 }
jardineb5d44e2003-12-23 08:09:43 +00001583
1584 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1585}
1586
jardineb5d44e2003-12-23 08:09:43 +00001587/*
1588 * Process ISH
1589 * ISO - 10589
1590 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1591 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001592 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1593 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1594 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001595 */
hasso92365882005-01-18 13:53:33 +00001596static int
jardineb5d44e2003-12-23 08:09:43 +00001597process_is_hello (struct isis_circuit *circuit)
1598{
1599 struct isis_adjacency *adj;
1600 int retval = ISIS_OK;
1601 u_char neigh_len;
1602 u_char *sysid;
1603
1604 /* In this point in time we are not yet able to handle is_hellos
1605 * on lan - Sorry juniper...
1606 */
1607 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1608 return retval;
1609
1610 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001611 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001612 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001613 if (!adj)
1614 {
1615 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00001616 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001617 if (adj == NULL)
1618 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001619
hassof390d2c2004-09-10 20:48:21 +00001620 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1621 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1622 circuit->u.p2p.neighbor = adj;
1623 }
1624 /* 8.2.2 a) */
1625 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1626 ISIS_SYS_ID_LEN))
1627 {
1628 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1629 /* 8.2.2 a) 2) delete the adj */
1630 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1631 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00001632 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001633 if (adj == NULL)
1634 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001635
hassof390d2c2004-09-10 20:48:21 +00001636 /* 8.2.2 a) 3) i */
1637 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1638 /* 8.2.2 a) 3) ii */
1639 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1640 /* 8.2.2 a) 4) quite meaningless */
1641 }
jardineb5d44e2003-12-23 08:09:43 +00001642 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001643 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1644 (adj->sys_type == ISIS_SYSTYPE_IS))
1645 {
1646 /* do nothing */
1647 }
1648 else
1649 {
1650 /* 8.2.2 c) respond with a p2p IIH */
1651 send_hello (circuit, 1);
1652 }
jardineb5d44e2003-12-23 08:09:43 +00001653 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001654 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001655 /* 8.2.2 e) FIXME: Circuit type of? */
1656
jardineb5d44e2003-12-23 08:09:43 +00001657 return retval;
1658}
1659
jardineb5d44e2003-12-23 08:09:43 +00001660/*
1661 * PDU Dispatcher
1662 */
1663
hasso92365882005-01-18 13:53:33 +00001664static int
hassof390d2c2004-09-10 20:48:21 +00001665isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001666{
jardineb5d44e2003-12-23 08:09:43 +00001667 struct isis_fixed_hdr *hdr;
1668 struct esis_fixed_hdr *esis_hdr;
1669
hassof390d2c2004-09-10 20:48:21 +00001670 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001671
1672 /*
1673 * Let's first read data from stream to the header
1674 */
hassof390d2c2004-09-10 20:48:21 +00001675 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001676
hassof390d2c2004-09-10 20:48:21 +00001677 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1678 {
1679 zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1680 return ISIS_ERROR;
1681 }
jardineb5d44e2003-12-23 08:09:43 +00001682
1683 /* now we need to know if this is an ISO 9542 packet and
1684 * take real good care of it, waaa!
1685 */
hassof390d2c2004-09-10 20:48:21 +00001686 if (hdr->idrp == ISO9542_ESIS)
1687 {
1688 esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1689 stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN);
1690 /* FIXME: Need to do some acceptence tests */
1691 /* example length... */
1692 switch (esis_hdr->pdu_type)
1693 {
1694 case ESH_PDU:
1695 /* FIXME */
1696 break;
1697 case ISH_PDU:
hasso529d65b2004-12-24 00:14:50 +00001698 zlog_debug ("AN ISH PDU!!");
hassof390d2c2004-09-10 20:48:21 +00001699 retval = process_is_hello (circuit);
1700 break;
1701 default:
1702 return ISIS_ERROR;
1703 }
1704 return retval;
1705 }
1706 else
1707 {
1708 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1709 }
jardineb5d44e2003-12-23 08:09:43 +00001710 /*
1711 * and then process it
1712 */
1713
hassof390d2c2004-09-10 20:48:21 +00001714 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1715 {
1716 zlog_err ("Fixed header length = %d", hdr->length);
1717 return ISIS_ERROR;
1718 }
jardineb5d44e2003-12-23 08:09:43 +00001719
hassof390d2c2004-09-10 20:48:21 +00001720 if (hdr->version1 != 1)
1721 {
1722 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1723 return ISIS_WARNING;
1724 }
jardineb5d44e2003-12-23 08:09:43 +00001725 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001726 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1727 {
1728 zlog_err
1729 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1730 "while the parameter for this IS is %u", hdr->id_len,
1731 ISIS_SYS_ID_LEN);
1732 return ISIS_ERROR;
1733 }
jardineb5d44e2003-12-23 08:09:43 +00001734
hassof390d2c2004-09-10 20:48:21 +00001735 if (hdr->version2 != 1)
1736 {
1737 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
1738 return ISIS_WARNING;
1739 }
jardineb5d44e2003-12-23 08:09:43 +00001740 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001741 if ((hdr->max_area_addrs != 0)
1742 && (hdr->max_area_addrs != isis->max_area_addrs))
1743 {
1744 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
1745 "received PDU %u while the parameter for this IS is %u",
1746 hdr->max_area_addrs, isis->max_area_addrs);
1747 return ISIS_ERROR;
1748 }
jardineb5d44e2003-12-23 08:09:43 +00001749
hassof390d2c2004-09-10 20:48:21 +00001750 switch (hdr->pdu_type)
1751 {
1752 case L1_LAN_HELLO:
1753 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
1754 break;
1755 case L2_LAN_HELLO:
1756 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
1757 break;
1758 case P2P_HELLO:
1759 retval = process_p2p_hello (circuit);
1760 break;
1761 case L1_LINK_STATE:
1762 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
1763 break;
1764 case L2_LINK_STATE:
1765 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
1766 break;
1767 case L1_COMPLETE_SEQ_NUM:
1768 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
1769 break;
1770 case L2_COMPLETE_SEQ_NUM:
1771 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
1772 break;
1773 case L1_PARTIAL_SEQ_NUM:
1774 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
1775 break;
1776 case L2_PARTIAL_SEQ_NUM:
1777 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
1778 break;
1779 default:
1780 return ISIS_ERROR;
1781 }
jardineb5d44e2003-12-23 08:09:43 +00001782
1783 return retval;
1784}
1785
jardineb5d44e2003-12-23 08:09:43 +00001786#ifdef GNU_LINUX
1787int
1788isis_receive (struct thread *thread)
1789{
jardineb5d44e2003-12-23 08:09:43 +00001790 struct isis_circuit *circuit;
1791 u_char ssnpa[ETH_ALEN];
1792 int retval;
1793
1794 /*
1795 * Get the circuit
1796 */
1797 circuit = THREAD_ARG (thread);
1798 assert (circuit);
1799
Fritz Reichmann55749992011-09-14 19:31:51 +04001800 if (!circuit->area)
1801 return ISIS_OK;
1802
jardineb5d44e2003-12-23 08:09:43 +00001803 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001804 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001805 else
1806 stream_reset (circuit->rcv_stream);
1807
1808 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00001809 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001810
1811 if (retval == ISIS_OK)
1812 retval = isis_handle_pdu (circuit, ssnpa);
1813
1814 /*
1815 * prepare for next packet.
1816 */
hassof390d2c2004-09-10 20:48:21 +00001817 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
1818 circuit->fd);
jardineb5d44e2003-12-23 08:09:43 +00001819
1820 return retval;
1821}
1822
1823#else
1824int
1825isis_receive (struct thread *thread)
1826{
jardineb5d44e2003-12-23 08:09:43 +00001827 struct isis_circuit *circuit;
1828 u_char ssnpa[ETH_ALEN];
1829 int retval;
1830
1831 /*
1832 * Get the circuit
1833 */
1834 circuit = THREAD_ARG (thread);
1835 assert (circuit);
1836
hassof390d2c2004-09-10 20:48:21 +00001837 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001838
1839 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00001840 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001841 else
1842 stream_reset (circuit->rcv_stream);
1843
1844 retval = circuit->rx (circuit, ssnpa);
1845
1846 if (retval == ISIS_OK)
1847 retval = isis_handle_pdu (circuit, ssnpa);
1848
1849 /*
1850 * prepare for next packet.
1851 */
hassof390d2c2004-09-10 20:48:21 +00001852 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
1853 listcount
1854 (circuit->area->circuit_list) *
1855 100);
jardineb5d44e2003-12-23 08:09:43 +00001856
1857 return retval;
1858}
1859
1860#endif
1861
1862 /* filling of the fixed isis header */
1863void
1864fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
1865{
1866 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
1867
1868 hdr->idrp = ISO10589_ISIS;
1869
hassof390d2c2004-09-10 20:48:21 +00001870 switch (pdu_type)
1871 {
1872 case L1_LAN_HELLO:
1873 case L2_LAN_HELLO:
1874 hdr->length = ISIS_LANHELLO_HDRLEN;
1875 break;
1876 case P2P_HELLO:
1877 hdr->length = ISIS_P2PHELLO_HDRLEN;
1878 break;
1879 case L1_LINK_STATE:
1880 case L2_LINK_STATE:
1881 hdr->length = ISIS_LSP_HDR_LEN;
1882 break;
1883 case L1_COMPLETE_SEQ_NUM:
1884 case L2_COMPLETE_SEQ_NUM:
1885 hdr->length = ISIS_CSNP_HDRLEN;
1886 break;
1887 case L1_PARTIAL_SEQ_NUM:
1888 case L2_PARTIAL_SEQ_NUM:
1889 hdr->length = ISIS_PSNP_HDRLEN;
1890 break;
1891 default:
1892 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
1893 return;
1894 }
jardineb5d44e2003-12-23 08:09:43 +00001895 hdr->length += ISIS_FIXED_HDR_LEN;
1896 hdr->pdu_type = pdu_type;
1897 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00001898 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00001899 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00001900 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00001901}
1902
jardineb5d44e2003-12-23 08:09:43 +00001903/*
1904 * SEND SIDE
1905 */
hasso92365882005-01-18 13:53:33 +00001906static void
jardineb5d44e2003-12-23 08:09:43 +00001907fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00001908 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00001909{
hassof390d2c2004-09-10 20:48:21 +00001910 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00001911
1912 stream_putc (stream, hdr->idrp);
1913 stream_putc (stream, hdr->length);
1914 stream_putc (stream, hdr->version1);
1915 stream_putc (stream, hdr->id_len);
1916 stream_putc (stream, hdr->pdu_type);
1917 stream_putc (stream, hdr->version2);
1918 stream_putc (stream, hdr->reserved);
1919 stream_putc (stream, hdr->max_area_addrs);
1920
1921 return;
1922}
1923
jardineb5d44e2003-12-23 08:09:43 +00001924int
1925send_hello (struct isis_circuit *circuit, int level)
1926{
1927 struct isis_fixed_hdr fixed_hdr;
1928 struct isis_lan_hello_hdr hello_hdr;
1929 struct isis_p2p_hello_hdr p2p_hello_hdr;
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04001930 char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
jardineb5d44e2003-12-23 08:09:43 +00001931
1932 u_int32_t interval;
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04001933 unsigned long len_pointer, length, auth_tlv;
jardineb5d44e2003-12-23 08:09:43 +00001934 int retval;
1935
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04001936 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
1937 return ISIS_WARNING;
1938
hassof390d2c2004-09-10 20:48:21 +00001939 if (circuit->interface->mtu == 0)
1940 {
1941 zlog_warn ("circuit has zero MTU");
1942 return ISIS_WARNING;
1943 }
jardineb5d44e2003-12-23 08:09:43 +00001944
1945 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00001946 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00001947 else
1948 stream_reset (circuit->snd_stream);
1949
1950 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1951 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00001952 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
1953 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001954 else
hassof390d2c2004-09-10 20:48:21 +00001955 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
1956 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001957 else
hassof390d2c2004-09-10 20:48:21 +00001958 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00001959
1960 /*
1961 * Fill LAN Level 1 or 2 Hello PDU header
1962 */
1963 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00001964 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00001965 circuit->hello_interval[level - 1];
Fritz Reichmann89980752011-09-14 20:46:57 +04001966 /* If we are the DIS then hello interval is divided by three, as is the hold-timer */
1967 if (circuit->u.bc.is_dr[level - 1])
1968 interval=interval/3;
jardineb5d44e2003-12-23 08:09:43 +00001969 if (interval > USHRT_MAX)
1970 interval = USHRT_MAX;
1971 hello_hdr.circuit_t = circuit->circuit_is_type;
1972 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001973 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00001974
hassof390d2c2004-09-10 20:48:21 +00001975 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00001976 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001977
1978 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00001979 if (circuit->circ_type == CIRCUIT_T_P2P)
1980 {
1981 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
1982 p2p_hello_hdr.local_id = circuit->circuit_id;
1983 /* FIXME: need better understanding */
1984 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00001985 }
hassof390d2c2004-09-10 20:48:21 +00001986 else
1987 {
1988 hello_hdr.prio = circuit->u.bc.priority[level - 1];
1989 if (level == 1 && circuit->u.bc.l1_desig_is)
1990 {
1991 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
1992 ISIS_SYS_ID_LEN + 1);
1993 }
1994 else if (level == 2 && circuit->u.bc.l2_desig_is)
1995 {
1996 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
1997 ISIS_SYS_ID_LEN + 1);
1998 }
1999 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2000 }
jardineb5d44e2003-12-23 08:09:43 +00002001
2002 /*
2003 * Then the variable length part
2004 */
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04002005
jardineb5d44e2003-12-23 08:09:43 +00002006 /* add circuit password */
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04002007 /* Cleartext */
2008 if (circuit->passwd.type == ISIS_PASSWD_TYPE_CLEARTXT)
2009 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, circuit->passwd.len,
jardineb5d44e2003-12-23 08:09:43 +00002010 circuit->passwd.passwd, circuit->snd_stream))
2011 return ISIS_WARNING;
Fritz Reichmannc25eaff2011-10-01 17:43:12 +04002012
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04002013 /* or HMAC MD5 */
2014 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2015 {
2016 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2017 auth_tlv = stream_get_endp (circuit->snd_stream);
2018 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2019 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2020 hmac_md5_hash, circuit->snd_stream))
2021 return ISIS_WARNING;
2022 }
2023
Fritz Reichmannc25eaff2011-10-01 17:43:12 +04002024 /* Protocols Supported TLV */
2025 if (circuit->nlpids.count > 0)
2026 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2027 return ISIS_WARNING;
2028
jardineb5d44e2003-12-23 08:09:43 +00002029 /* Area Addresses TLV */
2030 assert (circuit->area);
2031 if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
2032 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2033 return ISIS_WARNING;
2034
Fritz Reichmannc25eaff2011-10-01 17:43:12 +04002035 /* IP interface Address TLV */
2036 if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
2037 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2038 return ISIS_WARNING;
2039
2040#ifdef HAVE_IPV6
2041 /* IPv6 Interface Address TLV */
2042 if (circuit->ipv6_router && circuit->ipv6_link &&
2043 circuit->ipv6_link->count > 0)
2044 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2045 return ISIS_WARNING;
2046#endif /* HAVE_IPV6 */
2047
2048 /* Restart signaling, vendor C sends it too */
2049 retval = add_tlv (211, 3, 0, circuit->snd_stream);
2050
jardineb5d44e2003-12-23 08:09:43 +00002051 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002052 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2053 {
2054 if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
2055 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2056 circuit->snd_stream))
2057 return ISIS_WARNING;
2058 if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
2059 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2060 circuit->snd_stream))
2061 return ISIS_WARNING;
2062 }
jardineb5d44e2003-12-23 08:09:43 +00002063
jardineb5d44e2003-12-23 08:09:43 +00002064 if (circuit->u.bc.pad_hellos)
2065 if (tlv_add_padding (circuit->snd_stream))
2066 return ISIS_WARNING;
2067
paul9985f832005-02-09 15:51:56 +00002068 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002069 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002070 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002071
Fritz Reichmanne6b03b72011-10-01 17:49:48 +04002072 /* For HMAC MD5 we need to compute the md5 hash and store it */
2073 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2074 {
2075 hmac_md5(circuit->snd_stream->data, stream_get_endp(circuit->snd_stream), (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len, (unsigned char *) &hmac_md5_hash);
2076 /* Copy the hash into the stream */
2077 memcpy(circuit->snd_stream->data+auth_tlv+3,hmac_md5_hash,ISIS_AUTH_MD5_SIZE);
2078 }
2079
jardineb5d44e2003-12-23 08:09:43 +00002080 retval = circuit->tx (circuit, level);
2081 if (retval)
2082 zlog_warn ("sending of LAN Level %d Hello failed", level);
2083
2084 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00002085 if (isis->debugs & DEBUG_ADJ_PACKETS)
2086 {
2087 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2088 {
hasso529d65b2004-12-24 00:14:50 +00002089 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2090 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002091 /* FIXME: use %z when we stop supporting old compilers. */
2092 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002093 }
2094 else
2095 {
hasso529d65b2004-12-24 00:14:50 +00002096 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2097 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002098 /* FIXME: use %z when we stop supporting old compilers. */
2099 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hassof390d2c2004-09-10 20:48:21 +00002100 }
jardineb5d44e2003-12-23 08:09:43 +00002101 }
jardineb5d44e2003-12-23 08:09:43 +00002102
2103 return retval;
2104}
2105
hasso92365882005-01-18 13:53:33 +00002106static int
jardineb5d44e2003-12-23 08:09:43 +00002107send_lan_hello (struct isis_circuit *circuit, int level)
2108{
hassof390d2c2004-09-10 20:48:21 +00002109 return send_hello (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002110}
2111
2112int
2113send_lan_l1_hello (struct thread *thread)
2114{
jardineb5d44e2003-12-23 08:09:43 +00002115 struct isis_circuit *circuit;
2116 int retval;
Fritz Reichmann89980752011-09-14 20:46:57 +04002117 unsigned long next_hello;
jardineb5d44e2003-12-23 08:09:43 +00002118
2119 circuit = THREAD_ARG (thread);
2120 assert (circuit);
Fritz Reichmann89980752011-09-14 20:46:57 +04002121
2122 if (!circuit->area) {
2123 return ISIS_OK;
2124 }
2125
2126 /* Pseudonode sends hellos three times more than the other nodes */
2127 if (circuit->u.bc.is_dr[0])
2128 next_hello=circuit->hello_interval[0]/3+1;
2129 else
2130 next_hello=circuit->hello_interval[0];
2131
jardineb5d44e2003-12-23 08:09:43 +00002132 circuit->u.bc.t_send_lan_hello[0] = NULL;
2133
2134 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002135 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002136
2137 retval = send_lan_hello (circuit, 1);
2138
2139 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002140 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2141 send_lan_l1_hello, circuit,
Fritz Reichmann89980752011-09-14 20:46:57 +04002142 isis_jitter (next_hello, IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002143
2144 return retval;
2145}
2146
2147int
2148send_lan_l2_hello (struct thread *thread)
2149{
2150 struct isis_circuit *circuit;
2151 int retval;
Fritz Reichmann89980752011-09-14 20:46:57 +04002152 unsigned long next_hello;
jardineb5d44e2003-12-23 08:09:43 +00002153
2154 circuit = THREAD_ARG (thread);
2155 assert (circuit);
Fritz Reichmann55749992011-09-14 19:31:51 +04002156
2157 if (!circuit->area) {
2158 return ISIS_OK;
2159 }
2160
Fritz Reichmann89980752011-09-14 20:46:57 +04002161 /* Pseudonode sends hellos three times more than the other nodes */
2162 if (circuit->u.bc.is_dr[1])
2163 next_hello=circuit->hello_interval[1]/3+1;
2164 else
2165 next_hello=circuit->hello_interval[1];
2166
jardineb5d44e2003-12-23 08:09:43 +00002167 circuit->u.bc.t_send_lan_hello[1] = NULL;
2168
2169 if (circuit->u.bc.run_dr_elect[1])
2170 retval = isis_dr_elect (circuit, 2);
2171
2172 retval = send_lan_hello (circuit, 2);
2173
hassof390d2c2004-09-10 20:48:21 +00002174 /* set next timer thread */
2175 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2176 send_lan_l2_hello, circuit,
Fritz Reichmann89980752011-09-14 20:46:57 +04002177 isis_jitter (next_hello, IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002178
2179 return retval;
2180}
2181
2182int
2183send_p2p_hello (struct thread *thread)
2184{
2185 struct isis_circuit *circuit;
2186
2187 circuit = THREAD_ARG (thread);
2188 assert (circuit);
2189 circuit->u.p2p.t_send_p2p_hello = NULL;
2190
hassof390d2c2004-09-10 20:48:21 +00002191 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002192
hassof390d2c2004-09-10 20:48:21 +00002193 /* set next timer thread */
2194 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2195 circuit, isis_jitter (circuit->hello_interval[1],
2196 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002197
2198 return ISIS_OK;
2199}
2200
hasso92365882005-01-18 13:53:33 +00002201static int
hassof390d2c2004-09-10 20:48:21 +00002202build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2203 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002204{
2205 struct isis_fixed_hdr fixed_hdr;
2206 struct isis_passwd *passwd;
2207 int retval = ISIS_OK;
2208 unsigned long lenp;
2209 u_int16_t length;
2210
hassof390d2c2004-09-10 20:48:21 +00002211 if (level == 1)
2212 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2213 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002214 else
hassof390d2c2004-09-10 20:48:21 +00002215 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2216 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002217
2218 /*
2219 * Fill Level 1 or 2 Complete Sequence Numbers header
2220 */
2221
paul9985f832005-02-09 15:51:56 +00002222 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002223 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002224 /* no need to send the source here, it is always us if we csnp */
2225 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2226 /* with zero circuit id - ref 9.10, 9.11 */
2227 stream_putc (circuit->snd_stream, 0x00);
2228
2229 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2230 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2231
2232 /*
2233 * And TLVs
2234 */
2235 if (level == 1)
2236 passwd = &circuit->area->area_passwd;
2237 else
2238 passwd = &circuit->area->domain_passwd;
2239
hasso1cbc5622005-01-01 10:29:51 +00002240 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2241 if (passwd->type)
2242 retval = tlv_add_authinfo (passwd->type, passwd->len,
2243 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002244
hassof390d2c2004-09-10 20:48:21 +00002245 if (!retval && lsps)
2246 {
2247 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2248 }
paul9985f832005-02-09 15:51:56 +00002249 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002250 assert (length >= ISIS_CSNP_HDRLEN);
2251 /* Update PU length */
2252 stream_putw_at (circuit->snd_stream, lenp, length);
2253
2254 return retval;
2255}
2256
2257/*
2258 * FIXME: support multiple CSNPs
2259 */
2260
2261int
2262send_csnp (struct isis_circuit *circuit, int level)
2263{
2264 int retval = ISIS_OK;
2265 u_char start[ISIS_SYS_ID_LEN + 2];
2266 u_char stop[ISIS_SYS_ID_LEN + 2];
2267 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002268 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002269 struct isis_lsp *lsp;
2270
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002271 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
2272 return ISIS_WARNING;
2273
hassof390d2c2004-09-10 20:48:21 +00002274 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002275 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2276
hassof390d2c2004-09-10 20:48:21 +00002277 if (circuit->area->lspdb[level - 1] &&
2278 dict_count (circuit->area->lspdb[level - 1]) > 0)
2279 {
2280 list = list_new ();
2281 lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002282
hassof390d2c2004-09-10 20:48:21 +00002283 if (circuit->snd_stream == NULL)
2284 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2285 else
2286 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002287
hassof390d2c2004-09-10 20:48:21 +00002288 retval = build_csnp (level, start, stop, list, circuit);
jardineb5d44e2003-12-23 08:09:43 +00002289
hassof390d2c2004-09-10 20:48:21 +00002290 if (isis->debugs & DEBUG_SNP_PACKETS)
2291 {
hasso529d65b2004-12-24 00:14:50 +00002292 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
paul1eb8ef22005-04-07 07:30:20 +00002293 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002294 /* FIXME: use %z when we stop supporting old compilers. */
2295 (unsigned long) STREAM_SIZE (circuit->snd_stream));
hasso3fdb2dd2005-09-28 18:45:54 +00002296 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002297 {
hasso529d65b2004-12-24 00:14:50 +00002298 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2299 " cksum 0x%04x, lifetime %us",
2300 circuit->area->area_tag,
2301 rawlspid_print (lsp->lsp_header->lsp_id),
2302 ntohl (lsp->lsp_header->seq_num),
2303 ntohs (lsp->lsp_header->checksum),
2304 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002305 }
2306 }
2307
2308 list_delete (list);
2309
2310 if (retval == ISIS_OK)
2311 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002312 }
jardineb5d44e2003-12-23 08:09:43 +00002313 return retval;
2314}
2315
2316int
2317send_l1_csnp (struct thread *thread)
2318{
2319 struct isis_circuit *circuit;
2320 int retval = ISIS_OK;
2321
2322 circuit = THREAD_ARG (thread);
2323 assert (circuit);
2324
2325 circuit->t_send_csnp[0] = NULL;
2326
hassof390d2c2004-09-10 20:48:21 +00002327 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002328 send_csnp (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002329 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002330 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2331 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002332
2333 return retval;
2334}
2335
2336int
2337send_l2_csnp (struct thread *thread)
2338{
2339 struct isis_circuit *circuit;
2340 int retval = ISIS_OK;
2341
2342 circuit = THREAD_ARG (thread);
2343 assert (circuit);
2344
2345 circuit->t_send_csnp[1] = NULL;
2346
hassof390d2c2004-09-10 20:48:21 +00002347 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002348 send_csnp (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002349 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002350 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2351 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002352
jardineb5d44e2003-12-23 08:09:43 +00002353 return retval;
2354}
2355
hasso92365882005-01-18 13:53:33 +00002356static int
jardineb5d44e2003-12-23 08:09:43 +00002357build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2358{
2359 struct isis_fixed_hdr fixed_hdr;
2360 unsigned long lenp;
2361 u_int16_t length;
2362 int retval = 0;
2363 struct isis_lsp *lsp;
2364 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002365 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002366
2367 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002368 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2369 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002370 else
2371 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002372 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002373
2374 /*
2375 * Fill Level 1 or 2 Partial Sequence Numbers header
2376 */
paul9985f832005-02-09 15:51:56 +00002377 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002378 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002379 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2380 stream_putc (circuit->snd_stream, circuit->idx);
2381
2382 /*
2383 * And TLVs
2384 */
2385
2386 if (level == 1)
2387 passwd = &circuit->area->area_passwd;
2388 else
2389 passwd = &circuit->area->domain_passwd;
2390
hasso1cbc5622005-01-01 10:29:51 +00002391 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2392 if (passwd->type)
2393 retval = tlv_add_authinfo (passwd->type, passwd->len,
2394 passwd->passwd, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002395
hassof390d2c2004-09-10 20:48:21 +00002396 if (!retval && lsps)
2397 {
2398 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002399 }
jardineb5d44e2003-12-23 08:09:43 +00002400
hassof390d2c2004-09-10 20:48:21 +00002401 if (isis->debugs & DEBUG_SNP_PACKETS)
2402 {
hasso3fdb2dd2005-09-28 18:45:54 +00002403 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002404 {
hasso529d65b2004-12-24 00:14:50 +00002405 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2406 " cksum 0x%04x, lifetime %us",
2407 circuit->area->area_tag,
2408 rawlspid_print (lsp->lsp_header->lsp_id),
2409 ntohl (lsp->lsp_header->seq_num),
2410 ntohs (lsp->lsp_header->checksum),
2411 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002412 }
2413 }
2414
paul9985f832005-02-09 15:51:56 +00002415 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002416 assert (length >= ISIS_PSNP_HDRLEN);
2417 /* Update PDU length */
2418 stream_putw_at (circuit->snd_stream, lenp, length);
2419
2420 return ISIS_OK;
2421}
2422
2423/*
2424 * 7.3.15.4 action on expiration of partial SNP interval
2425 * level 1
2426 */
hasso92365882005-01-18 13:53:33 +00002427static int
jardineb5d44e2003-12-23 08:09:43 +00002428send_psnp (int level, struct isis_circuit *circuit)
2429{
2430 int retval = ISIS_OK;
2431 struct isis_lsp *lsp;
2432 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002433 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002434
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002435 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
2436 return ISIS_WARNING;
2437
hassof390d2c2004-09-10 20:48:21 +00002438 if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
jardineb5d44e2003-12-23 08:09:43 +00002439 !circuit->u.bc.is_dr[level - 1]) ||
hassof390d2c2004-09-10 20:48:21 +00002440 circuit->circ_type != CIRCUIT_T_BROADCAST)
2441 {
jardineb5d44e2003-12-23 08:09:43 +00002442
hassof390d2c2004-09-10 20:48:21 +00002443 if (circuit->area->lspdb[level - 1] &&
2444 dict_count (circuit->area->lspdb[level - 1]) > 0)
2445 {
2446 list = list_new ();
2447 lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002448
hassof390d2c2004-09-10 20:48:21 +00002449 if (listcount (list) > 0)
2450 {
2451 if (circuit->snd_stream == NULL)
2452 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2453 else
2454 stream_reset (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002455
2456
hassof390d2c2004-09-10 20:48:21 +00002457 if (isis->debugs & DEBUG_SNP_PACKETS)
hasso529d65b2004-12-24 00:14:50 +00002458 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2459 circuit->area->area_tag, level,
2460 circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002461 /* FIXME: use %z when we stop supporting old
2462 * compilers. */
2463 (unsigned long) STREAM_SIZE (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002464
hassof390d2c2004-09-10 20:48:21 +00002465 retval = build_psnp (level, circuit, list);
2466 if (retval == ISIS_OK)
2467 retval = circuit->tx (circuit, level);
jardineb5d44e2003-12-23 08:09:43 +00002468
hassof390d2c2004-09-10 20:48:21 +00002469 if (retval == ISIS_OK)
2470 {
2471 /*
2472 * sending succeeded, we can clear SSN flags of this circuit
2473 * for the LSPs in list
2474 */
hasso3fdb2dd2005-09-28 18:45:54 +00002475 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +00002476 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002477 }
2478 }
2479 list_delete (list);
2480 }
jardineb5d44e2003-12-23 08:09:43 +00002481 }
jardineb5d44e2003-12-23 08:09:43 +00002482
2483 return retval;
2484}
2485
2486int
2487send_l1_psnp (struct thread *thread)
2488{
2489
2490 struct isis_circuit *circuit;
2491 int retval = ISIS_OK;
2492
2493 circuit = THREAD_ARG (thread);
2494 assert (circuit);
2495
2496 circuit->t_send_psnp[0] = NULL;
2497
2498 send_psnp (1, circuit);
2499 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002500 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2501 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002502
2503 return retval;
2504}
2505
2506/*
2507 * 7.3.15.4 action on expiration of partial SNP interval
2508 * level 2
2509 */
2510int
2511send_l2_psnp (struct thread *thread)
2512{
jardineb5d44e2003-12-23 08:09:43 +00002513 struct isis_circuit *circuit;
2514 int retval = ISIS_OK;
2515
2516 circuit = THREAD_ARG (thread);
2517 assert (circuit);
2518
2519 circuit->t_send_psnp[1] = NULL;
2520
2521 send_psnp (2, circuit);
2522
2523 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002524 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
2525 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002526
2527 return retval;
2528}
2529
jardineb5d44e2003-12-23 08:09:43 +00002530/*
2531 * ISO 10589 - 7.3.14.3
2532 */
2533int
2534send_lsp (struct thread *thread)
2535{
2536 struct isis_circuit *circuit;
2537 struct isis_lsp *lsp;
2538 struct listnode *node;
2539 int retval = 0;
2540
2541 circuit = THREAD_ARG (thread);
2542 assert (circuit);
2543
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002544 if (circuit->state != C_STATE_UP || circuit->interface == NULL)
2545 return ISIS_WARNING;
2546
2547 lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
2548
2549 /*
2550 * Do not send if levels do not match
2551 */
2552 if (!(lsp->level & circuit->circuit_is_type))
2553 goto dontsend;
2554
2555 /*
2556 * Do not send if we do not have adjacencies in state up on the circuit
2557 */
2558 if (circuit->upadjcount[lsp->level - 1] == 0)
2559 goto dontsend;
2560 /* only send if it needs sending */
2561 if ((time (NULL) - lsp->last_sent) >=
2562 circuit->area->lsp_gen_interval[lsp->level - 1])
hassof390d2c2004-09-10 20:48:21 +00002563 {
jardineb5d44e2003-12-23 08:09:43 +00002564
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002565 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00002566 {
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002567 zlog_debug
2568 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
2569 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
2570 rawlspid_print (lsp->lsp_header->lsp_id),
2571 ntohl (lsp->lsp_header->seq_num),
2572 ntohs (lsp->lsp_header->checksum),
2573 ntohs (lsp->lsp_header->rem_lifetime),
2574 circuit->interface->name);
2575 }
2576 /* copy our lsp to the send buffer */
2577 stream_copy (circuit->snd_stream, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002578
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002579 retval = circuit->tx (circuit, lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002580
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002581 /*
2582 * If the sending succeeded, we can del the lsp from circuits
2583 * lsp_queue
2584 */
2585 if (retval == ISIS_OK)
2586 {
2587 list_delete_node (circuit->lsp_queue, node);
hassof390d2c2004-09-10 20:48:21 +00002588
jardineb5d44e2003-12-23 08:09:43 +00002589 /*
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002590 * On broadcast circuits also the SRMflag can be cleared
jardineb5d44e2003-12-23 08:09:43 +00002591 */
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002592 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2593 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00002594
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002595 if (flags_any_set (lsp->SRMflags) == 0)
2596 {
hassof390d2c2004-09-10 20:48:21 +00002597 /*
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002598 * need to remember when we were last sent
hassof390d2c2004-09-10 20:48:21 +00002599 */
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002600 lsp->last_sent = time (NULL);
hassof390d2c2004-09-10 20:48:21 +00002601 }
jardineb5d44e2003-12-23 08:09:43 +00002602 }
hassof390d2c2004-09-10 20:48:21 +00002603 else
2604 {
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002605 zlog_debug ("sending of level %d link state failed", lsp->level);
hassof390d2c2004-09-10 20:48:21 +00002606 }
hassof390d2c2004-09-10 20:48:21 +00002607 }
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002608 else
2609 {
2610 /* my belief is that if it wasn't his time, the lsp can be removed
2611 * from the queue
2612 */
2613 dontsend:
2614 list_delete_node (circuit->lsp_queue, node);
2615 }
2616#if 0
2617 /*
2618 * If there are still LSPs send next one after lsp-interval (33 msecs)
2619 */
2620 if (listcount (circuit->lsp_queue) > 0)
2621 thread_add_timer (master, send_lsp, circuit, 1);
2622#endif
jardineb5d44e2003-12-23 08:09:43 +00002623
2624 return retval;
hassof390d2c2004-09-10 20:48:21 +00002625}
jardineb5d44e2003-12-23 08:09:43 +00002626
2627int
hassof390d2c2004-09-10 20:48:21 +00002628ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
2629 int level)
jardineb5d44e2003-12-23 08:09:43 +00002630{
2631 unsigned long lenp;
2632 int retval;
2633 u_int16_t length;
2634 struct isis_fixed_hdr fixed_hdr;
2635
2636 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002637 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002638 else
2639 stream_reset (circuit->snd_stream);
2640
2641// fill_llc_hdr (stream);
2642 if (level == 1)
hassof390d2c2004-09-10 20:48:21 +00002643 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2644 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002645 else
hassof390d2c2004-09-10 20:48:21 +00002646 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2647 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002648
2649
paul9985f832005-02-09 15:51:56 +00002650 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002651 stream_putw (circuit->snd_stream, 0); /* PDU length */
2652 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002653 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00002654 stream_putc (circuit->snd_stream, 9); /* code */
2655 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00002656
hassof390d2c2004-09-10 20:48:21 +00002657 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
2658 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
2659 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
2660 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00002661
paul9985f832005-02-09 15:51:56 +00002662 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002663 /* Update PDU length */
2664 stream_putw_at (circuit->snd_stream, lenp, length);
2665
2666 retval = circuit->tx (circuit, level);
2667
2668 return retval;
2669}
2670