blob: 2178d95517f5046ab73b76661379b639903b2414 [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"
Josh Bailey3f045a02012-03-24 08:35:20 -070032#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"
Josh Bailey3f045a02012-03-24 08:35:20 -070036#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"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_adjacency.h"
44#include "isisd/isis_circuit.h"
45#include "isisd/isis_network.h"
46#include "isisd/isis_misc.h"
47#include "isisd/isis_dr.h"
jardineb5d44e2003-12-23 08:09:43 +000048#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
jardineb5d44e2003-12-23 08:09:43 +000057#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000058#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000059
60#ifndef PNBBY
61#define PNBBY 8
62#endif /* PNBBY */
63
64/* Utility mask array. */
Stephen Hemminger88d37b92014-11-03 01:20:09 +000065static const u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000066 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
67};
68
69/*
70 * HELPER FUNCS
71 */
72
73/*
74 * Compares two sets of area addresses
75 */
hassof390d2c2004-09-10 20:48:21 +000076static int
jardineb5d44e2003-12-23 08:09:43 +000077area_match (struct list *left, struct list *right)
78{
79 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000080 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000081
hasso3fdb2dd2005-09-28 18:45:54 +000082 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000083 {
hasso3fdb2dd2005-09-28 18:45:54 +000084 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000085 {
86 if (addr1->addr_len == addr2->addr_len &&
87 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
88 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000089 }
90 }
91
hassof390d2c2004-09-10 20:48:21 +000092 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000093}
94
95/*
96 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
97 * param ip1 the IS interface ip address structure
98 * param ip2 the IIH's ip address
99 * return 0 the IIH's IP is not in the IS's subnetwork
100 * 1 the IIH's IP is in the IS's subnetwork
101 */
hasso92365882005-01-18 13:53:33 +0000102static int
hassof390d2c2004-09-10 20:48:21 +0000103ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000104{
105 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000106 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000107 int len;
hassof390d2c2004-09-10 20:48:21 +0000108
109 addr1 = (u_char *) & ip1->prefix.s_addr;
110 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000111 len = ip1->prefixlen;
112
113 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000114 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000115
hasso53c997c2004-09-15 16:21:59 +0000116 while (offsetloop--)
117 if (addr1[offsetloop] != addr2[offsetloop])
118 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000119
hassof390d2c2004-09-10 20:48:21 +0000120 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000121 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
122 return 0;
hassof390d2c2004-09-10 20:48:21 +0000123
124 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000125}
126
jardineb5d44e2003-12-23 08:09:43 +0000127/*
128 * Compares two set of ip addresses
129 * param left the local interface's ip addresses
130 * param right the iih interface's ip address
131 * return 0 no match;
132 * 1 match;
133 */
hassof390d2c2004-09-10 20:48:21 +0000134static int
jardineb5d44e2003-12-23 08:09:43 +0000135ip_match (struct list *left, struct list *right)
136{
137 struct prefix_ipv4 *ip1;
138 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000139 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000140
hassoe082ac12004-09-27 18:13:57 +0000141 if ((left == NULL) || (right == NULL))
142 return 0;
143
hasso3fdb2dd2005-09-28 18:45:54 +0000144 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000145 {
hasso3fdb2dd2005-09-28 18:45:54 +0000146 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000147 {
148 if (ip_same_subnet (ip1, ip2))
149 {
150 return 1; /* match */
151 }
jardineb5d44e2003-12-23 08:09:43 +0000152 }
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 }
155 return 0;
156}
157
158/*
159 * Checks whether we should accept a PDU of given level
160 */
161static int
162accept_level (int level, int circuit_t)
163{
hassof390d2c2004-09-10 20:48:21 +0000164 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000165
166 return retval;
167}
168
Josh Bailey3f045a02012-03-24 08:35:20 -0700169/*
170 * Verify authentication information
171 * Support cleartext and HMAC MD5 authentication
172 */
173static int
174authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
175 struct stream *stream, uint32_t auth_tlv_offset)
jardineb5d44e2003-12-23 08:09:43 +0000176{
Josh Bailey3f045a02012-03-24 08:35:20 -0700177 unsigned char digest[ISIS_AUTH_MD5_SIZE];
178
179 /* Auth fail () - passwd type mismatch */
180 if (local->type != remote->type)
181 return ISIS_ERROR;
182
183 switch (local->type)
184 {
185 /* No authentication required */
186 case ISIS_PASSWD_TYPE_UNUSED:
187 break;
188
189 /* Cleartext (ISO 10589) */
hassof390d2c2004-09-10 20:48:21 +0000190 case ISIS_PASSWD_TYPE_CLEARTXT:
Josh Bailey3f045a02012-03-24 08:35:20 -0700191 /* Auth fail () - passwd len mismatch */
192 if (remote->len != local->len)
193 return ISIS_ERROR;
194 return memcmp (local->passwd, remote->passwd, local->len);
195
196 /* HMAC MD5 (RFC 3567) */
197 case ISIS_PASSWD_TYPE_HMAC_MD5:
198 /* Auth fail () - passwd len mismatch */
199 if (remote->len != ISIS_AUTH_MD5_SIZE)
200 return ISIS_ERROR;
201 /* Set the authentication value to 0 before the check */
202 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
203 ISIS_AUTH_MD5_SIZE);
204 /* Compute the digest */
205 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
206 (unsigned char *) &(local->passwd), local->len,
David Lamparter21401f32015-03-03 08:55:26 +0100207 (unsigned char *) &digest);
Josh Bailey3f045a02012-03-24 08:35:20 -0700208 /* Copy back the authentication value after the check */
209 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
210 remote->passwd, ISIS_AUTH_MD5_SIZE);
211 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
212
hassof390d2c2004-09-10 20:48:21 +0000213 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700214 zlog_err ("Unsupported authentication type");
215 return ISIS_ERROR;
216 }
217
218 /* Authentication pass when no authentication is configured */
219 return ISIS_OK;
220}
221
222static int
223lsp_authentication_check (struct stream *stream, struct isis_area *area,
224 int level, struct isis_passwd *passwd)
225{
226 struct isis_link_state_hdr *hdr;
227 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700228 uint16_t checksum, rem_lifetime, pdu_len;
Josh Bailey3f045a02012-03-24 08:35:20 -0700229 struct tlvs tlvs;
230 int retval = ISIS_OK;
231
232 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700233 pdu_len = ntohs (hdr->pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700234 expected |= TLVFLAG_AUTH_INFO;
235 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
236 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700237 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
Josh Bailey3f045a02012-03-24 08:35:20 -0700238 &expected, &found, &tlvs, &auth_tlv_offset);
239
240 if (retval != ISIS_OK)
241 {
242 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
243 "cksum 0x%04x, lifetime %us, len %u",
244 area->area_tag, level, rawlspid_print (hdr->lsp_id),
245 ntohl (hdr->seq_num), ntohs (hdr->checksum),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700246 ntohs (hdr->rem_lifetime), pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700247 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
248 (isis->debugs & DEBUG_PACKET_DUMP))
249 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
250 return retval;
hassof390d2c2004-09-10 20:48:21 +0000251 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700252
253 if (!(found & TLVFLAG_AUTH_INFO))
254 {
255 zlog_err ("No authentication tlv in LSP");
256 return ISIS_ERROR;
257 }
258
259 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
260 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
261 {
262 zlog_err ("Unknown authentication type in LSP");
263 return ISIS_ERROR;
264 }
265
266 /*
267 * RFC 5304 set checksum and remaining lifetime to zero before
268 * verification and reset to old values after verification.
269 */
270 checksum = hdr->checksum;
271 rem_lifetime = hdr->rem_lifetime;
272 hdr->checksum = 0;
273 hdr->rem_lifetime = 0;
274 retval = authentication_check (&tlvs.auth_info, passwd, stream,
275 auth_tlv_offset);
276 hdr->checksum = checksum;
277 hdr->rem_lifetime = rem_lifetime;
278
279 return retval;
jardineb5d44e2003-12-23 08:09:43 +0000280}
281
282/*
283 * Processing helper functions
284 */
hasso92365882005-01-18 13:53:33 +0000285static void
Josh Bailey3f045a02012-03-24 08:35:20 -0700286del_addr (void *val)
287{
288 XFREE (MTYPE_ISIS_TMP, val);
289}
290
291static void
292tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
293{
294 struct listnode *node;
295 struct area_addr *area_addr, *malloced;
296
297 if (adj->area_addrs)
298 {
299 adj->area_addrs->del = del_addr;
300 list_delete (adj->area_addrs);
301 }
302 adj->area_addrs = list_new ();
303 if (tlvs->area_addrs)
304 {
305 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
306 {
307 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
308 memcpy (malloced, area_addr, sizeof (struct area_addr));
309 listnode_add (adj->area_addrs, malloced);
310 }
311 }
312}
313
David Lamparter655071f2012-05-08 13:32:53 +0200314static int
hassof390d2c2004-09-10 20:48:21 +0000315tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000316{
317 int i;
318 struct nlpids *tlv_nlpids;
319
hassof390d2c2004-09-10 20:48:21 +0000320 if (tlvs->nlpids)
321 {
jardineb5d44e2003-12-23 08:09:43 +0000322
hassof390d2c2004-09-10 20:48:21 +0000323 tlv_nlpids = tlvs->nlpids;
David Lamparter655071f2012-05-08 13:32:53 +0200324 if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
325 return 1;
jardineb5d44e2003-12-23 08:09:43 +0000326
hassof390d2c2004-09-10 20:48:21 +0000327 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000328
hassof390d2c2004-09-10 20:48:21 +0000329 for (i = 0; i < tlv_nlpids->count; i++)
330 {
331 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
332 }
jardineb5d44e2003-12-23 08:09:43 +0000333 }
David Lamparter655071f2012-05-08 13:32:53 +0200334 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000335}
336
hasso92365882005-01-18 13:53:33 +0000337static void
hassof390d2c2004-09-10 20:48:21 +0000338tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000339{
hasso3fdb2dd2005-09-28 18:45:54 +0000340 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000341 struct in_addr *ipv4_addr, *malloced;
342
hassof390d2c2004-09-10 20:48:21 +0000343 if (adj->ipv4_addrs)
344 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700345 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000346 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000347 }
hassof390d2c2004-09-10 20:48:21 +0000348 adj->ipv4_addrs = list_new ();
349 if (tlvs->ipv4_addrs)
350 {
hasso3fdb2dd2005-09-28 18:45:54 +0000351 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000352 {
353 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
354 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
355 listnode_add (adj->ipv4_addrs, malloced);
356 }
357 }
jardineb5d44e2003-12-23 08:09:43 +0000358}
359
360#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000361static void
hassof390d2c2004-09-10 20:48:21 +0000362tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000363{
hasso3fdb2dd2005-09-28 18:45:54 +0000364 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000365 struct in6_addr *ipv6_addr, *malloced;
366
hassof390d2c2004-09-10 20:48:21 +0000367 if (adj->ipv6_addrs)
368 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700369 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000370 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000371 }
hassof390d2c2004-09-10 20:48:21 +0000372 adj->ipv6_addrs = list_new ();
373 if (tlvs->ipv6_addrs)
374 {
hasso3fdb2dd2005-09-28 18:45:54 +0000375 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000376 {
377 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
378 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
379 listnode_add (adj->ipv6_addrs, malloced);
380 }
381 }
jardineb5d44e2003-12-23 08:09:43 +0000382
383}
384#endif /* HAVE_IPV6 */
385
jardineb5d44e2003-12-23 08:09:43 +0000386/*
387 * RECEIVE SIDE
388 */
389
390/*
391 * Process P2P IIH
392 * ISO - 10589
393 * Section 8.2.5 - Receiving point-to-point IIH PDUs
394 *
395 */
396static int
397process_p2p_hello (struct isis_circuit *circuit)
398{
399 int retval = ISIS_OK;
400 struct isis_p2p_hello_hdr *hdr;
401 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700402 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700403 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000404 struct tlvs tlvs;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200405 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000406
Josh Bailey3f045a02012-03-24 08:35:20 -0700407 if (isis->debugs & DEBUG_ADJ_PACKETS)
408 {
409 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
410 circuit->area->area_tag, circuit->interface->name,
411 circuit_t2string (circuit->is_type), circuit->circuit_id);
412 if (isis->debugs & DEBUG_PACKET_DUMP)
413 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
414 stream_get_endp (circuit->rcv_stream));
415 }
416
417 if (circuit->circ_type != CIRCUIT_T_P2P)
418 {
419 zlog_warn ("p2p hello on non p2p circuit");
420 return ISIS_WARNING;
421 }
422
hassof390d2c2004-09-10 20:48:21 +0000423 if ((stream_get_endp (circuit->rcv_stream) -
424 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
425 {
426 zlog_warn ("Packet too short");
427 return ISIS_WARNING;
428 }
jardineb5d44e2003-12-23 08:09:43 +0000429
430 /* 8.2.5.1 PDU acceptance tests */
431
432 /* 8.2.5.1 a) external domain untrue */
433 /* FIXME: not useful at all? */
434
435 /* 8.2.5.1 b) ID Length mismatch */
436 /* checked at the handle_pdu */
437
438 /* 8.2.5.2 IIH PDU Processing */
439
440 /* 8.2.5.2 a) 1) Maximum Area Addresses */
441 /* Already checked, and can also be ommited */
442
443 /*
444 * Get the header
445 */
hassof390d2c2004-09-10 20:48:21 +0000446 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700447 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000448
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700449 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
450 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700451 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000452 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700453 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
454 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700455 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700456 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000457 }
jardineb5d44e2003-12-23 08:09:43 +0000458
jardineb5d44e2003-12-23 08:09:43 +0000459 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700460 * Set the stream endp to PDU length, ignoring additional padding
461 * introduced by transport chips.
462 */
463 if (pdu_len < stream_get_endp (circuit->rcv_stream))
464 stream_set_endp (circuit->rcv_stream, pdu_len);
465
466 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
467
468 /*
jardineb5d44e2003-12-23 08:09:43 +0000469 * Lets get the TLVS now
470 */
471 expected |= TLVFLAG_AREA_ADDRS;
472 expected |= TLVFLAG_AUTH_INFO;
473 expected |= TLVFLAG_NLPID;
474 expected |= TLVFLAG_IPV4_ADDR;
475 expected |= TLVFLAG_IPV6_ADDR;
476
Josh Bailey3f045a02012-03-24 08:35:20 -0700477 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000478 retval = parse_tlvs (circuit->area->area_tag,
479 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700480 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
481 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000482
hassof390d2c2004-09-10 20:48:21 +0000483 if (retval > ISIS_WARNING)
484 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700485 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000486 free_tlvs (&tlvs);
487 return retval;
488 };
jardineb5d44e2003-12-23 08:09:43 +0000489
Josh Bailey3f045a02012-03-24 08:35:20 -0700490 if (!(found & TLVFLAG_AREA_ADDRS))
491 {
492 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
493 free_tlvs (&tlvs);
494 return ISIS_WARNING;
495 }
496
David Lamparterb72f3452012-11-27 01:10:26 +0000497 if (!(found & TLVFLAG_NLPID))
498 {
499 zlog_warn ("No supported protocols TLV in P2P IS to IS hello");
500 free_tlvs (&tlvs);
501 return ISIS_WARNING;
502 }
503
jardineb5d44e2003-12-23 08:09:43 +0000504 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000505 if (circuit->passwd.type)
506 {
507 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700508 authentication_check (&tlvs.auth_info, &circuit->passwd,
509 circuit->rcv_stream, auth_tlv_offset))
510 {
511 isis_event_auth_failure (circuit->area->area_tag,
512 "P2P hello authentication failure",
513 hdr->source_id);
514 free_tlvs (&tlvs);
515 return ISIS_OK;
516 }
jardineb5d44e2003-12-23 08:09:43 +0000517 }
jardineb5d44e2003-12-23 08:09:43 +0000518
Josh Bailey3f045a02012-03-24 08:35:20 -0700519 /*
520 * check if it's own interface ip match iih ip addrs
521 */
David Lamparter28a8cfc2014-06-29 13:48:18 +0200522 if (found & TLVFLAG_IPV4_ADDR)
Josh Bailey3f045a02012-03-24 08:35:20 -0700523 {
David Lamparter28a8cfc2014-06-29 13:48:18 +0200524 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
525 v4_usable = 1;
526 else
527 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
528 "in P2P IIH from %s\n", circuit->interface->name);
529 }
530#ifndef HAVE_IPV6
531 else /* !(found & TLVFLAG_IPV4_ADDR) */
532 zlog_warn ("ISIS-Adj: no IPv4 in P2P IIH from %s "
533 "(this isisd has no IPv6)\n", circuit->interface->name);
534
535#else
536 if (found & TLVFLAG_IPV6_ADDR)
537 {
538 /* TBA: check that we have a linklocal ourselves? */
539 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +0200540 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200541 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
542 if (IN6_IS_ADDR_LINKLOCAL (ip))
543 {
544 v6_usable = 1;
545 break;
546 }
547
548 if (!v6_usable)
549 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
550 "in P2P IIH from %s\n", circuit->interface->name);
551 }
552
553 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
554 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n",
555 circuit->interface->name);
556#endif
557
558 if (!v6_usable && !v4_usable)
559 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700560 free_tlvs (&tlvs);
561 return ISIS_WARNING;
562 }
563
564 /*
565 * My interpertation of the ISO, if no adj exists we will create one for
566 * the circuit
567 */
568 adj = circuit->u.p2p.neighbor;
Amritha Nambiar3c28aaf2015-01-28 18:09:30 +0000569 /* If an adjacency exists, check it is with the source of the hello
570 * packets */
571 if (adj)
572 {
573 if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
574 {
575 zlog_debug("hello source and adjacency do not match, set adj down\n");
576 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
577 return 0;
578 }
579 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700580 if (!adj || adj->level != hdr->circuit_t)
581 {
582 if (!adj)
583 {
584 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
585 if (adj == NULL)
586 return ISIS_ERROR;
587 }
588 else
589 {
590 adj->level = hdr->circuit_t;
591 }
592 circuit->u.p2p.neighbor = adj;
593 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
594 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
595 }
596
597 /* 8.2.6 Monitoring point-to-point adjacencies */
598 adj->hold_time = ntohs (hdr->hold_time);
599 adj->last_upd = time (NULL);
600
jardineb5d44e2003-12-23 08:09:43 +0000601 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700602 tlvs_to_adj_area_addrs (&tlvs, adj);
603
604 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +0000605 if (tlvs_to_adj_nlpids (&tlvs, adj))
606 {
607 free_tlvs (&tlvs);
608 return ISIS_WARNING;
609 }
jardineb5d44e2003-12-23 08:09:43 +0000610
611 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700612 if (found & TLVFLAG_IPV4_ADDR)
613 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000614
615#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700616 if (found & TLVFLAG_IPV6_ADDR)
617 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000618#endif /* HAVE_IPV6 */
619
620 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000621 THREAD_TIMER_OFF (adj->t_expire);
622 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
623 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000624
625 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000626 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
627 {
628 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
629 if (circuit->area->is_type == IS_LEVEL_1)
630 {
631 switch (hdr->circuit_t)
632 {
633 case IS_LEVEL_1:
634 case IS_LEVEL_1_AND_2:
635 if (adj->adj_state != ISIS_ADJ_UP)
636 {
637 /* (4) adj state up */
638 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
639 /* (5) adj usage level 1 */
640 adj->adj_usage = ISIS_ADJ_LEVEL1;
641 }
642 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
643 {
644 ; /* accept */
645 }
646 break;
647 case IS_LEVEL_2:
648 if (adj->adj_state != ISIS_ADJ_UP)
649 {
650 /* (7) reject - wrong system type event */
651 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700652 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000653 return ISIS_WARNING; /* Reject */
654 }
655 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
656 {
657 /* (6) down - wrong system */
658 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
659 }
660 break;
661 }
662 }
jardineb5d44e2003-12-23 08:09:43 +0000663
hassof390d2c2004-09-10 20:48:21 +0000664 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
665 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
666 {
667 switch (hdr->circuit_t)
668 {
669 case IS_LEVEL_1:
670 if (adj->adj_state != ISIS_ADJ_UP)
671 {
672 /* (6) adj state up */
673 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
674 /* (7) adj usage level 1 */
675 adj->adj_usage = ISIS_ADJ_LEVEL1;
676 }
677 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
678 {
679 ; /* accept */
680 }
681 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
682 (adj->adj_usage == ISIS_ADJ_LEVEL2))
683 {
684 /* (8) down - wrong system */
685 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
686 }
687 break;
688 case IS_LEVEL_2:
689 if (adj->adj_state != ISIS_ADJ_UP)
690 {
691 /* (6) adj state up */
692 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
693 /* (9) adj usage level 2 */
694 adj->adj_usage = ISIS_ADJ_LEVEL2;
695 }
696 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
697 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
698 {
699 /* (8) down - wrong system */
700 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
701 }
702 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
703 {
704 ; /* Accept */
705 }
706 break;
707 case IS_LEVEL_1_AND_2:
708 if (adj->adj_state != ISIS_ADJ_UP)
709 {
710 /* (6) adj state up */
711 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
712 /* (10) adj usage level 1 */
713 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
714 }
715 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
716 (adj->adj_usage == ISIS_ADJ_LEVEL2))
717 {
718 /* (8) down - wrong system */
719 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
720 }
721 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
722 {
723 ; /* Accept */
724 }
725 break;
726 }
727 }
jardineb5d44e2003-12-23 08:09:43 +0000728
hassof390d2c2004-09-10 20:48:21 +0000729 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
730 if (circuit->area->is_type == IS_LEVEL_2)
731 {
732 switch (hdr->circuit_t)
733 {
734 case IS_LEVEL_1:
735 if (adj->adj_state != ISIS_ADJ_UP)
736 {
737 /* (5) reject - wrong system type event */
738 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700739 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000740 return ISIS_WARNING; /* Reject */
741 }
742 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
743 (adj->adj_usage == ISIS_ADJ_LEVEL2))
744 {
745 /* (6) down - wrong system */
746 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
747 }
748 break;
749 case IS_LEVEL_1_AND_2:
750 case IS_LEVEL_2:
751 if (adj->adj_state != ISIS_ADJ_UP)
752 {
753 /* (7) adj state up */
754 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
755 /* (8) adj usage level 2 */
756 adj->adj_usage = ISIS_ADJ_LEVEL2;
757 }
758 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
759 {
760 /* (6) down - wrong system */
761 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
762 }
763 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
764 {
765 ; /* Accept */
766 }
767 break;
768 }
769 }
jardineb5d44e2003-12-23 08:09:43 +0000770 }
jardineb5d44e2003-12-23 08:09:43 +0000771 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700772 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000773 {
hassof390d2c2004-09-10 20:48:21 +0000774 if (circuit->area->is_type == IS_LEVEL_1)
775 {
776 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
777 if (adj->adj_state != ISIS_ADJ_UP)
778 {
779 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
780 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
781 }
782 else
783 {
784 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
785 "Down - Area Mismatch");
786 }
787 }
788 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
789 else
790 {
791 switch (hdr->circuit_t)
792 {
793 case IS_LEVEL_1:
794 if (adj->adj_state != ISIS_ADJ_UP)
795 {
796 /* (6) reject - Area Mismatch event */
797 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700798 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000799 return ISIS_WARNING; /* Reject */
800 }
801 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
802 {
803 /* (7) down - area mismatch */
804 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000805
hassof390d2c2004-09-10 20:48:21 +0000806 }
807 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
808 (adj->adj_usage == ISIS_ADJ_LEVEL2))
809 {
810 /* (7) down - wrong system */
811 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
812 }
813 break;
814 case IS_LEVEL_1_AND_2:
815 case IS_LEVEL_2:
816 if (adj->adj_state != ISIS_ADJ_UP)
817 {
818 /* (8) adj state up */
819 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
820 /* (9) adj usage level 2 */
821 adj->adj_usage = ISIS_ADJ_LEVEL2;
822 }
823 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
824 {
825 /* (7) down - wrong system */
826 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
827 }
828 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
829 {
830 if (hdr->circuit_t == IS_LEVEL_2)
831 {
832 /* (7) down - wrong system */
833 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
834 "Wrong System");
835 }
836 else
837 {
838 /* (7) down - area mismatch */
839 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
840 "Area Mismatch");
841 }
842 }
843 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
844 {
845 ; /* Accept */
846 }
847 break;
848 }
849 }
jardineb5d44e2003-12-23 08:09:43 +0000850 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700851 else
852 {
853 /* down - area mismatch */
854 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
855 }
jardineb5d44e2003-12-23 08:09:43 +0000856 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
857 /* FIXME - Missing parts */
858
jardineb5d44e2003-12-23 08:09:43 +0000859 /* some of my own understanding of the ISO, why the heck does
860 * it not say what should I change the system_type to...
861 */
hassof390d2c2004-09-10 20:48:21 +0000862 switch (adj->adj_usage)
863 {
jardineb5d44e2003-12-23 08:09:43 +0000864 case ISIS_ADJ_LEVEL1:
865 adj->sys_type = ISIS_SYSTYPE_L1_IS;
866 break;
867 case ISIS_ADJ_LEVEL2:
868 adj->sys_type = ISIS_SYSTYPE_L2_IS;
869 break;
870 case ISIS_ADJ_LEVEL1AND2:
871 adj->sys_type = ISIS_SYSTYPE_L2_IS;
872 break;
873 case ISIS_ADJ_NONE:
874 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
875 break;
hassof390d2c2004-09-10 20:48:21 +0000876 }
jardineb5d44e2003-12-23 08:09:43 +0000877
878 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700879
880 if (isis->debugs & DEBUG_ADJ_PACKETS)
881 {
882 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
883 " cir id %02d, length %d",
884 circuit->area->area_tag, circuit->interface->name,
885 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700886 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700887 }
jardineb5d44e2003-12-23 08:09:43 +0000888
889 free_tlvs (&tlvs);
890
891 return retval;
892}
893
jardineb5d44e2003-12-23 08:09:43 +0000894/*
895 * Process IS-IS LAN Level 1/2 Hello PDU
896 */
hassof390d2c2004-09-10 20:48:21 +0000897static int
898process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000899{
900 int retval = ISIS_OK;
901 struct isis_lan_hello_hdr hdr;
902 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700903 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000904 struct tlvs tlvs;
905 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000906 struct listnode *node;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200907 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000908
Josh Bailey3f045a02012-03-24 08:35:20 -0700909 if (isis->debugs & DEBUG_ADJ_PACKETS)
910 {
911 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
912 "cirID %u",
913 circuit->area->area_tag, level, circuit->interface->name,
914 circuit_t2string (circuit->is_type), circuit->circuit_id);
915 if (isis->debugs & DEBUG_PACKET_DUMP)
916 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
917 stream_get_endp (circuit->rcv_stream));
918 }
919
920 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
921 {
922 zlog_warn ("lan hello on non broadcast circuit");
923 return ISIS_WARNING;
924 }
925
hassof390d2c2004-09-10 20:48:21 +0000926 if ((stream_get_endp (circuit->rcv_stream) -
927 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
928 {
929 zlog_warn ("Packet too short");
930 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000931 }
hassof390d2c2004-09-10 20:48:21 +0000932
933 if (circuit->ext_domain)
934 {
hasso529d65b2004-12-24 00:14:50 +0000935 zlog_debug ("level %d LAN Hello received over circuit with "
936 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000937 return ISIS_WARNING;
938 }
939
Josh Bailey3f045a02012-03-24 08:35:20 -0700940 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000941 {
942 if (isis->debugs & DEBUG_ADJ_PACKETS)
943 {
hasso529d65b2004-12-24 00:14:50 +0000944 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
945 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000946 }
947 return ISIS_WARNING;
948 }
jardineb5d44e2003-12-23 08:09:43 +0000949
950#if 0
951 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000952 if (!accept_level (level, circuit->area->is_type))
953 {
954 if (isis->debugs & DEBUG_ADJ_PACKETS)
955 {
hasso529d65b2004-12-24 00:14:50 +0000956 zlog_debug ("ISIS-Adj (%s): is type mismatch",
957 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000958 }
959 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000960 }
jardineb5d44e2003-12-23 08:09:43 +0000961#endif
962 /*
963 * Fill the header
964 */
965 hdr.circuit_t = stream_getc (circuit->rcv_stream);
966 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
967 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000968 hdr.pdu_len = stream_getw (circuit->rcv_stream);
969 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000970 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
971
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700972 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
973 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700974 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000975 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700976 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
977 "invalid pdu length %d",
978 circuit->area->area_tag, circuit->interface->name,
979 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700980 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700981 }
982
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700983 /*
984 * Set the stream endp to PDU length, ignoring additional padding
985 * introduced by transport chips.
986 */
987 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
988 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
989
Josh Bailey3f045a02012-03-24 08:35:20 -0700990 if (hdr.circuit_t != IS_LEVEL_1 &&
991 hdr.circuit_t != IS_LEVEL_2 &&
992 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
993 (level & hdr.circuit_t) == 0)
994 {
995 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
996 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000997 return ISIS_ERROR;
998 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700999
jardineb5d44e2003-12-23 08:09:43 +00001000 /*
1001 * Then get the tlvs
1002 */
1003 expected |= TLVFLAG_AUTH_INFO;
1004 expected |= TLVFLAG_AREA_ADDRS;
1005 expected |= TLVFLAG_LAN_NEIGHS;
1006 expected |= TLVFLAG_NLPID;
1007 expected |= TLVFLAG_IPV4_ADDR;
1008 expected |= TLVFLAG_IPV6_ADDR;
1009
Josh Bailey3f045a02012-03-24 08:35:20 -07001010 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001011 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -07001012 STREAM_PNT (circuit->rcv_stream),
1013 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
1014 &expected, &found, &tlvs,
1015 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001016
hassof390d2c2004-09-10 20:48:21 +00001017 if (retval > ISIS_WARNING)
1018 {
1019 zlog_warn ("parse_tlvs() failed");
1020 goto out;
1021 }
jardineb5d44e2003-12-23 08:09:43 +00001022
hassof390d2c2004-09-10 20:48:21 +00001023 if (!(found & TLVFLAG_AREA_ADDRS))
1024 {
1025 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
1026 level);
jardineb5d44e2003-12-23 08:09:43 +00001027 retval = ISIS_WARNING;
1028 goto out;
1029 }
hassof390d2c2004-09-10 20:48:21 +00001030
David Lamparterb72f3452012-11-27 01:10:26 +00001031 if (!(found & TLVFLAG_NLPID))
1032 {
1033 zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
1034 level);
1035 retval = ISIS_WARNING;
1036 goto out;
1037 }
1038
Josh Bailey3f045a02012-03-24 08:35:20 -07001039 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +00001040 if (circuit->passwd.type)
1041 {
1042 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001043 authentication_check (&tlvs.auth_info, &circuit->passwd,
1044 circuit->rcv_stream, auth_tlv_offset))
1045 {
1046 isis_event_auth_failure (circuit->area->area_tag,
1047 "LAN hello authentication failure",
1048 hdr.source_id);
1049 retval = ISIS_WARNING;
1050 goto out;
1051 }
hassof390d2c2004-09-10 20:48:21 +00001052 }
jardineb5d44e2003-12-23 08:09:43 +00001053
David Lamparter19f78ce2012-11-27 01:10:25 +00001054 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
1055 {
1056 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
1057 circuit->area->area_tag, circuit->interface->name);
1058 return ISIS_WARNING;
1059 }
1060
jardineb5d44e2003-12-23 08:09:43 +00001061 /*
1062 * Accept the level 1 adjacency only if a match between local and
1063 * remote area addresses is found
1064 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001065 if (listcount (circuit->area->area_addrs) == 0 ||
1066 (level == IS_LEVEL_1 &&
1067 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +00001068 {
1069 if (isis->debugs & DEBUG_ADJ_PACKETS)
1070 {
hasso529d65b2004-12-24 00:14:50 +00001071 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1072 circuit->area->area_tag, level,
1073 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001074 }
1075 retval = ISIS_OK;
1076 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001077 }
jardineb5d44e2003-12-23 08:09:43 +00001078
1079 /*
1080 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001081 */
1082 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1083 {
hasso529d65b2004-12-24 00:14:50 +00001084 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1085 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001086
hassof390d2c2004-09-10 20:48:21 +00001087 retval = ISIS_OK;
1088 goto out;
1089 }
jardineb5d44e2003-12-23 08:09:43 +00001090
1091 /*
1092 * check if it's own interface ip match iih ip addrs
1093 */
David Lamparter28a8cfc2014-06-29 13:48:18 +02001094 if (found & TLVFLAG_IPV4_ADDR)
hassof390d2c2004-09-10 20:48:21 +00001095 {
David Lamparter28a8cfc2014-06-29 13:48:18 +02001096 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
1097 v4_usable = 1;
1098 else
1099 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
1100 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001101 }
David Lamparter28a8cfc2014-06-29 13:48:18 +02001102#ifndef HAVE_IPV6
1103 else /* !(found & TLVFLAG_IPV4_ADDR) */
1104 zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s "
1105 "(this isisd has no IPv6)\n", circuit->interface->name);
1106
1107#else
1108 if (found & TLVFLAG_IPV6_ADDR)
1109 {
1110 /* TBA: check that we have a linklocal ourselves? */
1111 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +02001112 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +02001113 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
1114 if (IN6_IS_ADDR_LINKLOCAL (ip))
1115 {
1116 v6_usable = 1;
1117 break;
1118 }
1119
1120 if (!v6_usable)
1121 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
1122 "in LAN IIH from %s\n", circuit->interface->name);
1123 }
1124
1125 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
1126 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
1127 circuit->interface->name);
1128#endif
1129
1130 if (!v6_usable && !v4_usable)
1131 {
1132 free_tlvs (&tlvs);
1133 return ISIS_WARNING;
1134 }
1135
jardineb5d44e2003-12-23 08:09:43 +00001136
1137 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001138 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1139 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001140 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001141 if (!adj)
1142 {
1143 /*
1144 * Do as in 8.4.2.5
1145 */
1146 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1147 if (adj == NULL)
1148 {
1149 retval = ISIS_ERROR;
1150 goto out;
1151 }
1152 }
1153 else
1154 {
1155 if (ssnpa) {
1156 memcpy (adj->snpa, ssnpa, 6);
1157 } else {
1158 memset (adj->snpa, ' ', 6);
1159 }
1160 adj->level = level;
1161 }
hassof390d2c2004-09-10 20:48:21 +00001162 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001163
Josh Bailey3f045a02012-03-24 08:35:20 -07001164 if (level == IS_LEVEL_1)
1165 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001166 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001167 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001168 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1169 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001170 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001171 }
jardineb5d44e2003-12-23 08:09:43 +00001172
hassoa211d652004-09-20 14:55:29 +00001173 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1174 switch (level)
1175 {
1176 case 1:
1177 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1178 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001179 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001180 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1181 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001182 }
1183 break;
1184 case 2:
1185 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1186 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001187 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001188 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1189 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001190 }
1191 break;
1192 }
jardineb5d44e2003-12-23 08:09:43 +00001193
1194 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001195 adj->last_upd = time (NULL);
1196 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001197
1198 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1199
Josh Bailey3f045a02012-03-24 08:35:20 -07001200 tlvs_to_adj_area_addrs (&tlvs, adj);
1201
jardineb5d44e2003-12-23 08:09:43 +00001202 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +00001203 if (tlvs_to_adj_nlpids (&tlvs, adj))
1204 {
1205 retval = ISIS_WARNING;
1206 goto out;
1207 }
jardineb5d44e2003-12-23 08:09:43 +00001208
1209 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001210 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001211 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1212
1213#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001214 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001215 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1216#endif /* HAVE_IPV6 */
1217
1218 adj->circuit_t = hdr.circuit_t;
1219
1220 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001221 THREAD_TIMER_OFF (adj->t_expire);
1222 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001223 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001224
1225 /*
1226 * If the snpa for this circuit is found from LAN Neighbours TLV
1227 * we have two-way communication -> adjacency can be put to state "up"
1228 */
1229
hassof390d2c2004-09-10 20:48:21 +00001230 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001231 {
1232 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001233 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001234 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1235 {
1236 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1237 {
1238 isis_adj_state_change (adj, ISIS_ADJ_UP,
1239 "own SNPA found in LAN Neighbours TLV");
1240 }
1241 }
jardineb5d44e2003-12-23 08:09:43 +00001242 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001243 else
1244 {
1245 int found = 0;
1246 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1247 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1248 {
1249 found = 1;
1250 break;
1251 }
1252 if (found == 0)
1253 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1254 "own SNPA not found in LAN Neighbours TLV");
1255 }
1256 }
1257 else if (adj->adj_state == ISIS_ADJ_UP)
1258 {
1259 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1260 "no LAN Neighbours TLV found");
1261 }
jardineb5d44e2003-12-23 08:09:43 +00001262
hassof390d2c2004-09-10 20:48:21 +00001263out:
hassof390d2c2004-09-10 20:48:21 +00001264 if (isis->debugs & DEBUG_ADJ_PACKETS)
1265 {
hasso529d65b2004-12-24 00:14:50 +00001266 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
David Lamparter01da6172015-04-10 09:10:11 +02001267 "cirID %u, length %zd",
hasso529d65b2004-12-24 00:14:50 +00001268 circuit->area->area_tag,
1269 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001270 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001271 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001272 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001273 }
jardineb5d44e2003-12-23 08:09:43 +00001274
1275 free_tlvs (&tlvs);
1276
1277 return retval;
1278}
1279
1280/*
1281 * Process Level 1/2 Link State
1282 * ISO - 10589
1283 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001284 */
1285static int
1286process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001287{
1288 struct isis_link_state_hdr *hdr;
1289 struct isis_adjacency *adj = NULL;
1290 struct isis_lsp *lsp, *lsp0 = NULL;
1291 int retval = ISIS_OK, comp = 0;
1292 u_char lspid[ISIS_SYS_ID_LEN + 2];
1293 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001294 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001295
Josh Bailey3f045a02012-03-24 08:35:20 -07001296 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1297 {
1298 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1299 circuit->area->area_tag, level, circuit->interface->name,
1300 circuit_t2string (circuit->is_type), circuit->circuit_id);
1301 if (isis->debugs & DEBUG_PACKET_DUMP)
1302 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1303 stream_get_endp (circuit->rcv_stream));
1304 }
1305
hassof390d2c2004-09-10 20:48:21 +00001306 if ((stream_get_endp (circuit->rcv_stream) -
1307 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1308 {
1309 zlog_warn ("Packet too short");
1310 return ISIS_WARNING;
1311 }
jardineb5d44e2003-12-23 08:09:43 +00001312
1313 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001314 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001315 pdu_len = ntohs (hdr->pdu_len);
1316
1317 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001318 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001319 pdu_len > ISO_MTU(circuit) ||
1320 pdu_len > stream_get_endp (circuit->rcv_stream))
1321 {
1322 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1323 circuit->area->area_tag,
1324 rawlspid_print (hdr->lsp_id), pdu_len);
1325
1326 return ISIS_WARNING;
1327 }
1328
1329 /*
1330 * Set the stream endp to PDU length, ignoring additional padding
1331 * introduced by transport chips.
1332 */
1333 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1334 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001335
hassof390d2c2004-09-10 20:48:21 +00001336 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1337 {
hasso529d65b2004-12-24 00:14:50 +00001338 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001339 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001340 circuit->area->area_tag,
1341 level,
1342 rawlspid_print (hdr->lsp_id),
1343 ntohl (hdr->seq_num),
1344 ntohs (hdr->checksum),
1345 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001346 pdu_len,
paul15935e92005-05-03 09:27:23 +00001347 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001348 }
jardineb5d44e2003-12-23 08:09:43 +00001349
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001350 /* lsp is_type check */
1351 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1352 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001353 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001354 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001355 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001356 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1357 /* continue as per RFC1122 Be liberal in what you accept, and
1358 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001359 }
jardineb5d44e2003-12-23 08:09:43 +00001360
1361 /* Checksum sanity check - FIXME: move to correct place */
1362 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001363 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001364 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001365 {
hasso529d65b2004-12-24 00:14:50 +00001366 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1367 circuit->area->area_tag,
1368 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001369
hassof390d2c2004-09-10 20:48:21 +00001370 return ISIS_WARNING;
1371 }
jardineb5d44e2003-12-23 08:09:43 +00001372
1373 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001374 if (circuit->ext_domain)
1375 {
hasso529d65b2004-12-24 00:14:50 +00001376 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001377 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1378 "externalDomain = true", circuit->area->area_tag,
1379 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001380
hassof390d2c2004-09-10 20:48:21 +00001381 return ISIS_WARNING;
1382 }
jardineb5d44e2003-12-23 08:09:43 +00001383
1384 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001385 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001386 {
hasso529d65b2004-12-24 00:14:50 +00001387 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1388 " type %s",
1389 circuit->area->area_tag,
1390 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001391 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001392
hassof390d2c2004-09-10 20:48:21 +00001393 return ISIS_WARNING;
1394 }
jardineb5d44e2003-12-23 08:09:43 +00001395
1396 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1397
1398 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1399
1400 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001401 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1402 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001403 if (passwd->type)
1404 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001405 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1406 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001407 {
1408 isis_event_auth_failure (circuit->area->area_tag,
1409 "LSP authentication failure", hdr->lsp_id);
1410 return ISIS_WARNING;
1411 }
jardineb5d44e2003-12-23 08:09:43 +00001412 }
jardineb5d44e2003-12-23 08:09:43 +00001413 /* Find the LSP in our database and compare it to this Link State header */
1414 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1415 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001416 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1417 hdr->checksum, hdr->rem_lifetime);
1418 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001419#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001420 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001421#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001422 ))
jardineb5d44e2003-12-23 08:09:43 +00001423 goto dontcheckadj;
1424
1425 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1426 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001427
hassof390d2c2004-09-10 20:48:21 +00001428 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1429 {
1430 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1431 if (!adj)
1432 {
hasso529d65b2004-12-24 00:14:50 +00001433 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1434 "lifetime %us on %s",
1435 circuit->area->area_tag,
1436 rawlspid_print (hdr->lsp_id),
1437 ntohl (hdr->seq_num),
1438 ntohs (hdr->checksum),
1439 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001440 return ISIS_WARNING; /* Silently discard */
1441 }
jardineb5d44e2003-12-23 08:09:43 +00001442 }
jardineb5d44e2003-12-23 08:09:43 +00001443 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001444 else
1445 {
1446 /* If no adj, or no sharing of level */
1447 if (!circuit->u.p2p.neighbor)
1448 {
1449 return ISIS_OK; /* Silently discard */
1450 }
1451 else
1452 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001453 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001454 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001455 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001456 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1457 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001458 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001459 }
jardineb5d44e2003-12-23 08:09:43 +00001460 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001461
hassof390d2c2004-09-10 20:48:21 +00001462dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001463 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1464
1465 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1466
hassof390d2c2004-09-10 20:48:21 +00001467 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001468
hassof390d2c2004-09-10 20:48:21 +00001469 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1470 if (hdr->rem_lifetime == 0)
1471 {
1472 if (!lsp)
1473 {
1474 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1475 /* only needed on explicit update, eg - p2p */
1476 if (circuit->circ_type == CIRCUIT_T_P2P)
1477 ack_lsp (hdr, circuit, level);
1478 return retval; /* FIXME: do we need a purge? */
1479 }
1480 else
1481 {
1482 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1483 {
1484 /* LSP by some other system -> do 7.3.16.4 b) */
1485 /* 7.3.16.4 b) 1) */
1486 if (comp == LSP_NEWER)
1487 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001488 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001489 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001490 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001491 /* iii */
1492 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1493 /* v */
1494 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1495 /* iv */
1496 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1497 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001498
hassof390d2c2004-09-10 20:48:21 +00001499 } /* 7.3.16.4 b) 2) */
1500 else if (comp == LSP_EQUAL)
1501 {
1502 /* i */
1503 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1504 /* ii */
1505 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1506 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1507 } /* 7.3.16.4 b) 3) */
1508 else
1509 {
1510 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1511 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1512 }
1513 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001514 else if (lsp->lsp_header->rem_lifetime != 0)
1515 {
1516 /* our own LSP -> 7.3.16.4 c) */
1517 if (comp == LSP_NEWER)
1518 {
1519 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1520 lsp_set_all_srmflags (lsp);
1521 }
1522 else
1523 {
1524 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1525 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1526 }
1527 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1528 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1529 "seq 0x%08x", circuit->area->area_tag,
1530 rawlspid_print (hdr->lsp_id),
1531 ntohl (lsp->lsp_header->seq_num));
1532 }
hassof390d2c2004-09-10 20:48:21 +00001533 }
1534 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001535 }
jardineb5d44e2003-12-23 08:09:43 +00001536 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1537 * purge */
hassof390d2c2004-09-10 20:48:21 +00001538 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1539 {
1540 if (!lsp)
1541 {
1542 /* 7.3.16.4: initiate a purge */
1543 lsp_purge_non_exist (hdr, circuit->area);
1544 return ISIS_OK;
1545 }
1546 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1547
1548 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1549 * has information that the current sequence number for source S is
1550 * "greater" than that held by S, ... */
1551
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001552 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001553 {
1554 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001555 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001556 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1557 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1558 "0x%08x", circuit->area->area_tag,
1559 rawlspid_print (hdr->lsp_id),
1560 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001561 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001562 /* If the received LSP is older or equal,
1563 * resend the LSP which will act as ACK */
1564 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001565 }
hassof390d2c2004-09-10 20:48:21 +00001566 else
1567 {
1568 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001569
hassof390d2c2004-09-10 20:48:21 +00001570 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1571 if ((!lsp || comp == LSP_NEWER))
1572 {
hassof390d2c2004-09-10 20:48:21 +00001573 /*
1574 * If this lsp is a frag, need to see if we have zero lsp present
1575 */
1576 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1577 {
1578 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1579 LSP_FRAGMENT (lspid) = 0;
1580 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1581 if (!lsp0)
1582 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001583 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001584 return ISIS_OK;
1585 }
1586 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001587 /* i */
1588 if (!lsp)
1589 {
1590 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001591 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001592 circuit->area, level);
1593 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1594 }
1595 else /* exists, so we overwrite */
1596 {
1597 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1598 }
hassof390d2c2004-09-10 20:48:21 +00001599 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001600 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001601 /* iii */
1602 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001603
hassof390d2c2004-09-10 20:48:21 +00001604 /* iv */
1605 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1606 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1607 /* FIXME: v) */
1608 }
1609 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1610 else if (comp == LSP_EQUAL)
1611 {
1612 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001613 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001614 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001615 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001616 }
1617 /* 7.3.15.1 e) 3) LSP older than the one in db */
1618 else
1619 {
1620 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1621 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1622 }
jardineb5d44e2003-12-23 08:09:43 +00001623 }
jardineb5d44e2003-12-23 08:09:43 +00001624 return retval;
1625}
1626
1627/*
1628 * Process Sequence Numbers
1629 * ISO - 10589
1630 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1631 */
1632
hasso92365882005-01-18 13:53:33 +00001633static int
hassof390d2c2004-09-10 20:48:21 +00001634process_snp (int snp_type, int level, struct isis_circuit *circuit,
1635 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001636{
1637 int retval = ISIS_OK;
1638 int cmp, own_lsp;
1639 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001640 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001641 struct isis_adjacency *adj;
1642 struct isis_complete_seqnum_hdr *chdr = NULL;
1643 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001644 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001645 struct isis_lsp *lsp;
1646 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001647 struct listnode *node, *nnode;
1648 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001649 struct tlvs tlvs;
1650 struct list *lsp_list = NULL;
1651 struct isis_passwd *passwd;
1652
hassof390d2c2004-09-10 20:48:21 +00001653 if (snp_type == ISIS_SNP_CSNP_FLAG)
1654 {
1655 /* getting the header info */
1656 typechar = 'C';
1657 chdr =
1658 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001659 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1660 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001661 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001662 pdu_len > ISO_MTU(circuit) ||
1663 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001664 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001665 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1666 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001667 }
jardineb5d44e2003-12-23 08:09:43 +00001668 }
hassof390d2c2004-09-10 20:48:21 +00001669 else
1670 {
1671 typechar = 'P';
1672 phdr =
1673 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001674 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1675 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001676 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001677 pdu_len > ISO_MTU(circuit) ||
1678 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001679 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001680 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1681 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001682 }
jardineb5d44e2003-12-23 08:09:43 +00001683 }
jardineb5d44e2003-12-23 08:09:43 +00001684
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001685 /*
1686 * Set the stream endp to PDU length, ignoring additional padding
1687 * introduced by transport chips.
1688 */
1689 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1690 stream_set_endp (circuit->rcv_stream, pdu_len);
1691
jardineb5d44e2003-12-23 08:09:43 +00001692 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001693 if (circuit->ext_domain)
1694 {
jardineb5d44e2003-12-23 08:09:43 +00001695
hasso529d65b2004-12-24 00:14:50 +00001696 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1697 "skipping: circuit externalDomain = true",
1698 circuit->area->area_tag,
1699 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001700
1701 return ISIS_OK;
1702 }
hassof390d2c2004-09-10 20:48:21 +00001703
1704 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001705 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001706 {
1707
hasso529d65b2004-12-24 00:14:50 +00001708 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1709 "skipping: circuit type %s does not match level %d",
1710 circuit->area->area_tag,
1711 level,
1712 typechar,
1713 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001714 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001715
1716 return ISIS_OK;
1717 }
1718
1719 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1720 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001721 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1722 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001723 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001724 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1725 "skipping: we are not the DIS",
1726 circuit->area->area_tag,
1727 level,
1728 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001729
Josh Bailey3f045a02012-03-24 08:35:20 -07001730 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001731 }
jardineb5d44e2003-12-23 08:09:43 +00001732
1733 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1734
1735 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1736 * - already checked */
1737
1738 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1739 /* for broadcast circuits, snpa should be compared */
1740 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001741 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1742 {
1743 if (snp_type == ISIS_SNP_CSNP_FLAG)
1744 {
1745 adj =
1746 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1747 }
1748 else
1749 {
1750 /* a psnp on a broadcast, how lovely of Juniper :) */
1751 adj =
1752 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1753 }
1754 if (!adj)
1755 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001756 }
hassof390d2c2004-09-10 20:48:21 +00001757 else
1758 {
1759 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001760 {
1761 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1762 return ISIS_OK; /* Silently discard */
1763 }
hassof390d2c2004-09-10 20:48:21 +00001764 }
jardineb5d44e2003-12-23 08:09:43 +00001765
1766 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1767
1768 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1769
1770 memset (&tlvs, 0, sizeof (struct tlvs));
1771
1772 /* parse the SNP */
1773 expected |= TLVFLAG_LSP_ENTRIES;
1774 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001775
1776 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001777 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001778 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001779 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001780 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001781
hassof390d2c2004-09-10 20:48:21 +00001782 if (retval > ISIS_WARNING)
1783 {
1784 zlog_warn ("something went very wrong processing SNP");
1785 free_tlvs (&tlvs);
1786 return retval;
1787 }
jardineb5d44e2003-12-23 08:09:43 +00001788
Josh Bailey3f045a02012-03-24 08:35:20 -07001789 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001790 passwd = &circuit->area->area_passwd;
1791 else
1792 passwd = &circuit->area->domain_passwd;
1793
1794 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001795 {
hasso1cbc5622005-01-01 10:29:51 +00001796 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001797 {
1798 if (!(found & TLVFLAG_AUTH_INFO) ||
1799 authentication_check (&tlvs.auth_info, passwd,
1800 circuit->rcv_stream, auth_tlv_offset))
1801 {
1802 isis_event_auth_failure (circuit->area->area_tag,
1803 "SNP authentication" " failure",
1804 phdr ? phdr->source_id :
1805 chdr->source_id);
1806 free_tlvs (&tlvs);
1807 return ISIS_OK;
1808 }
1809 }
hassof390d2c2004-09-10 20:48:21 +00001810 }
jardineb5d44e2003-12-23 08:09:43 +00001811
1812 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001813 if (isis->debugs & DEBUG_SNP_PACKETS)
1814 {
hasso529d65b2004-12-24 00:14:50 +00001815 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1816 circuit->area->area_tag,
1817 level,
1818 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001819 if (tlvs.lsp_entries)
1820 {
hasso3fdb2dd2005-09-28 18:45:54 +00001821 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001822 {
hasso529d65b2004-12-24 00:14:50 +00001823 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1824 " cksum 0x%04x, lifetime %us",
1825 circuit->area->area_tag,
1826 typechar,
1827 rawlspid_print (entry->lsp_id),
1828 ntohl (entry->seq_num),
1829 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001830 }
1831 }
jardineb5d44e2003-12-23 08:09:43 +00001832 }
jardineb5d44e2003-12-23 08:09:43 +00001833
1834 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001835 if (tlvs.lsp_entries)
1836 {
hasso3fdb2dd2005-09-28 18:45:54 +00001837 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001838 {
1839 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1840 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1841 if (lsp)
1842 {
1843 /* 7.3.15.2 b) 1) is this LSP newer */
1844 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1845 entry->checksum, entry->rem_lifetime);
1846 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1847 if (cmp == LSP_EQUAL)
1848 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001849 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1850 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001851 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001852 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001853 else if (cmp == LSP_OLDER)
1854 {
1855 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1856 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1857 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001858 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001859 else
1860 {
hassof390d2c2004-09-10 20:48:21 +00001861 if (own_lsp)
1862 {
1863 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1864 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1865 }
1866 else
1867 {
1868 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001869 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1870 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001871 }
1872 }
1873 }
1874 else
1875 {
1876 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1877 * insert it and set SSN on it */
1878 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1879 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1880 {
1881 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1882 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001883 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001884 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001885 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001886 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1887 }
1888 }
jardineb5d44e2003-12-23 08:09:43 +00001889 }
1890 }
jardineb5d44e2003-12-23 08:09:43 +00001891
1892 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001893 if (snp_type == ISIS_SNP_CSNP_FLAG)
1894 {
1895 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001896 * Build a list from our own LSP db bounded with
1897 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001898 */
1899 lsp_list = list_new ();
1900 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1901 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001902
hassof390d2c2004-09-10 20:48:21 +00001903 /* Fixme: Find a better solution */
1904 if (tlvs.lsp_entries)
1905 {
paul1eb8ef22005-04-07 07:30:20 +00001906 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001907 {
paul1eb8ef22005-04-07 07:30:20 +00001908 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001909 {
1910 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1911 {
1912 list_delete_node (lsp_list, node2);
1913 break;
1914 }
1915 }
1916 }
1917 }
1918 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001919 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001920 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001921 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001922 list_delete (lsp_list);
1923
jardineb5d44e2003-12-23 08:09:43 +00001924 }
jardineb5d44e2003-12-23 08:09:43 +00001925
1926 free_tlvs (&tlvs);
1927 return retval;
1928}
1929
hasso92365882005-01-18 13:53:33 +00001930static int
hassof390d2c2004-09-10 20:48:21 +00001931process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001932{
Josh Bailey3f045a02012-03-24 08:35:20 -07001933 if (isis->debugs & DEBUG_SNP_PACKETS)
1934 {
1935 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1936 circuit->area->area_tag, level, circuit->interface->name,
1937 circuit_t2string (circuit->is_type), circuit->circuit_id);
1938 if (isis->debugs & DEBUG_PACKET_DUMP)
1939 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1940 stream_get_endp (circuit->rcv_stream));
1941 }
1942
jardineb5d44e2003-12-23 08:09:43 +00001943 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001944 if ((stream_get_endp (circuit->rcv_stream) -
1945 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1946 {
1947 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1948 return ISIS_WARNING;
1949 }
jardineb5d44e2003-12-23 08:09:43 +00001950
1951 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1952}
1953
hasso92365882005-01-18 13:53:33 +00001954static int
hassof390d2c2004-09-10 20:48:21 +00001955process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001956{
Josh Bailey3f045a02012-03-24 08:35:20 -07001957 if (isis->debugs & DEBUG_SNP_PACKETS)
1958 {
1959 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1960 circuit->area->area_tag, level, circuit->interface->name,
1961 circuit_t2string (circuit->is_type), circuit->circuit_id);
1962 if (isis->debugs & DEBUG_PACKET_DUMP)
1963 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1964 stream_get_endp (circuit->rcv_stream));
1965 }
1966
hassof390d2c2004-09-10 20:48:21 +00001967 if ((stream_get_endp (circuit->rcv_stream) -
1968 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1969 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001970 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001971 return ISIS_WARNING;
1972 }
jardineb5d44e2003-12-23 08:09:43 +00001973
1974 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1975}
1976
jardineb5d44e2003-12-23 08:09:43 +00001977/*
1978 * Process ISH
1979 * ISO - 10589
1980 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1981 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001982 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1983 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1984 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001985 */
hasso92365882005-01-18 13:53:33 +00001986static int
jardineb5d44e2003-12-23 08:09:43 +00001987process_is_hello (struct isis_circuit *circuit)
1988{
1989 struct isis_adjacency *adj;
1990 int retval = ISIS_OK;
1991 u_char neigh_len;
1992 u_char *sysid;
1993
Josh Bailey3f045a02012-03-24 08:35:20 -07001994 if (isis->debugs & DEBUG_ADJ_PACKETS)
1995 {
1996 zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u",
1997 circuit->area->area_tag, circuit->interface->name,
1998 circuit_t2string (circuit->is_type), circuit->circuit_id);
1999 if (isis->debugs & DEBUG_PACKET_DUMP)
2000 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
2001 stream_get_endp (circuit->rcv_stream));
2002 }
2003
jardineb5d44e2003-12-23 08:09:43 +00002004 /* In this point in time we are not yet able to handle is_hellos
2005 * on lan - Sorry juniper...
2006 */
2007 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2008 return retval;
2009
2010 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00002011 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002012 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00002013 if (!adj)
2014 {
2015 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00002016 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00002017 if (adj == NULL)
2018 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00002019
hassof390d2c2004-09-10 20:48:21 +00002020 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
2021 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
2022 circuit->u.p2p.neighbor = adj;
2023 }
2024 /* 8.2.2 a) */
2025 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
2026 ISIS_SYS_ID_LEN))
2027 {
2028 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
2029 /* 8.2.2 a) 2) delete the adj */
2030 XFREE (MTYPE_ISIS_ADJACENCY, adj);
2031 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00002032 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00002033 if (adj == NULL)
2034 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00002035
hassof390d2c2004-09-10 20:48:21 +00002036 /* 8.2.2 a) 3) i */
2037 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
2038 /* 8.2.2 a) 3) ii */
2039 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
2040 /* 8.2.2 a) 4) quite meaningless */
2041 }
jardineb5d44e2003-12-23 08:09:43 +00002042 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00002043 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
2044 (adj->sys_type == ISIS_SYSTYPE_IS))
2045 {
2046 /* do nothing */
2047 }
2048 else
2049 {
2050 /* 8.2.2 c) respond with a p2p IIH */
2051 send_hello (circuit, 1);
2052 }
jardineb5d44e2003-12-23 08:09:43 +00002053 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00002054 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00002055 /* 8.2.2 e) FIXME: Circuit type of? */
2056
jardineb5d44e2003-12-23 08:09:43 +00002057 return retval;
2058}
2059
jardineb5d44e2003-12-23 08:09:43 +00002060/*
2061 * PDU Dispatcher
2062 */
2063
hasso92365882005-01-18 13:53:33 +00002064static int
hassof390d2c2004-09-10 20:48:21 +00002065isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00002066{
jardineb5d44e2003-12-23 08:09:43 +00002067 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00002068
hassof390d2c2004-09-10 20:48:21 +00002069 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002070
2071 /*
2072 * Let's first read data from stream to the header
2073 */
hassof390d2c2004-09-10 20:48:21 +00002074 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00002075
hassof390d2c2004-09-10 20:48:21 +00002076 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
2077 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002078 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00002079 return ISIS_ERROR;
2080 }
jardineb5d44e2003-12-23 08:09:43 +00002081
2082 /* now we need to know if this is an ISO 9542 packet and
2083 * take real good care of it, waaa!
2084 */
hassof390d2c2004-09-10 20:48:21 +00002085 if (hdr->idrp == ISO9542_ESIS)
2086 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002087 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
2088 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002089 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002090 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
2091
jardineb5d44e2003-12-23 08:09:43 +00002092 /*
2093 * and then process it
2094 */
2095
hassof390d2c2004-09-10 20:48:21 +00002096 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
2097 {
2098 zlog_err ("Fixed header length = %d", hdr->length);
2099 return ISIS_ERROR;
2100 }
jardineb5d44e2003-12-23 08:09:43 +00002101
hassof390d2c2004-09-10 20:48:21 +00002102 if (hdr->version1 != 1)
2103 {
2104 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
2105 return ISIS_WARNING;
2106 }
jardineb5d44e2003-12-23 08:09:43 +00002107 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002108 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2109 {
2110 zlog_err
2111 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2112 "while the parameter for this IS is %u", hdr->id_len,
2113 ISIS_SYS_ID_LEN);
2114 return ISIS_ERROR;
2115 }
jardineb5d44e2003-12-23 08:09:43 +00002116
hassof390d2c2004-09-10 20:48:21 +00002117 if (hdr->version2 != 1)
2118 {
2119 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2120 return ISIS_WARNING;
2121 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002122
2123 if (circuit->is_passive)
2124 {
2125 zlog_warn ("Received ISIS PDU on passive circuit %s",
2126 circuit->interface->name);
2127 return ISIS_WARNING;
2128 }
2129
jardineb5d44e2003-12-23 08:09:43 +00002130 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002131 if ((hdr->max_area_addrs != 0)
2132 && (hdr->max_area_addrs != isis->max_area_addrs))
2133 {
2134 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2135 "received PDU %u while the parameter for this IS is %u",
2136 hdr->max_area_addrs, isis->max_area_addrs);
2137 return ISIS_ERROR;
2138 }
jardineb5d44e2003-12-23 08:09:43 +00002139
hassof390d2c2004-09-10 20:48:21 +00002140 switch (hdr->pdu_type)
2141 {
2142 case L1_LAN_HELLO:
2143 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2144 break;
2145 case L2_LAN_HELLO:
2146 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2147 break;
2148 case P2P_HELLO:
2149 retval = process_p2p_hello (circuit);
2150 break;
2151 case L1_LINK_STATE:
2152 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2153 break;
2154 case L2_LINK_STATE:
2155 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2156 break;
2157 case L1_COMPLETE_SEQ_NUM:
2158 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2159 break;
2160 case L2_COMPLETE_SEQ_NUM:
2161 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2162 break;
2163 case L1_PARTIAL_SEQ_NUM:
2164 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2165 break;
2166 case L2_PARTIAL_SEQ_NUM:
2167 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2168 break;
2169 default:
2170 return ISIS_ERROR;
2171 }
jardineb5d44e2003-12-23 08:09:43 +00002172
2173 return retval;
2174}
2175
jardineb5d44e2003-12-23 08:09:43 +00002176#ifdef GNU_LINUX
2177int
2178isis_receive (struct thread *thread)
2179{
jardineb5d44e2003-12-23 08:09:43 +00002180 struct isis_circuit *circuit;
2181 u_char ssnpa[ETH_ALEN];
2182 int retval;
2183
2184 /*
2185 * Get the circuit
2186 */
2187 circuit = THREAD_ARG (thread);
2188 assert (circuit);
2189
2190 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002191 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002192 else
2193 stream_reset (circuit->rcv_stream);
2194
2195 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002196 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002197
2198 if (retval == ISIS_OK)
2199 retval = isis_handle_pdu (circuit, ssnpa);
2200
2201 /*
2202 * prepare for next packet.
2203 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002204 if (!circuit->is_passive)
2205 {
2206 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2207 circuit->fd);
2208 }
jardineb5d44e2003-12-23 08:09:43 +00002209
2210 return retval;
2211}
2212
2213#else
2214int
2215isis_receive (struct thread *thread)
2216{
jardineb5d44e2003-12-23 08:09:43 +00002217 struct isis_circuit *circuit;
2218 u_char ssnpa[ETH_ALEN];
2219 int retval;
2220
2221 /*
2222 * Get the circuit
2223 */
2224 circuit = THREAD_ARG (thread);
2225 assert (circuit);
2226
hassof390d2c2004-09-10 20:48:21 +00002227 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002228
2229 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002230 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002231 else
2232 stream_reset (circuit->rcv_stream);
2233
2234 retval = circuit->rx (circuit, ssnpa);
2235
2236 if (retval == ISIS_OK)
2237 retval = isis_handle_pdu (circuit, ssnpa);
2238
2239 /*
2240 * prepare for next packet.
2241 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002242 if (!circuit->is_passive)
2243 {
2244 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2245 listcount
2246 (circuit->area->circuit_list) *
2247 100);
2248 }
jardineb5d44e2003-12-23 08:09:43 +00002249
2250 return retval;
2251}
2252
2253#endif
2254
2255 /* filling of the fixed isis header */
2256void
2257fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2258{
2259 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2260
2261 hdr->idrp = ISO10589_ISIS;
2262
hassof390d2c2004-09-10 20:48:21 +00002263 switch (pdu_type)
2264 {
2265 case L1_LAN_HELLO:
2266 case L2_LAN_HELLO:
2267 hdr->length = ISIS_LANHELLO_HDRLEN;
2268 break;
2269 case P2P_HELLO:
2270 hdr->length = ISIS_P2PHELLO_HDRLEN;
2271 break;
2272 case L1_LINK_STATE:
2273 case L2_LINK_STATE:
2274 hdr->length = ISIS_LSP_HDR_LEN;
2275 break;
2276 case L1_COMPLETE_SEQ_NUM:
2277 case L2_COMPLETE_SEQ_NUM:
2278 hdr->length = ISIS_CSNP_HDRLEN;
2279 break;
2280 case L1_PARTIAL_SEQ_NUM:
2281 case L2_PARTIAL_SEQ_NUM:
2282 hdr->length = ISIS_PSNP_HDRLEN;
2283 break;
2284 default:
2285 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2286 return;
2287 }
jardineb5d44e2003-12-23 08:09:43 +00002288 hdr->length += ISIS_FIXED_HDR_LEN;
2289 hdr->pdu_type = pdu_type;
2290 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002291 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002292 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002293 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002294}
2295
jardineb5d44e2003-12-23 08:09:43 +00002296/*
2297 * SEND SIDE
2298 */
hasso92365882005-01-18 13:53:33 +00002299static void
jardineb5d44e2003-12-23 08:09:43 +00002300fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002301 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002302{
hassof390d2c2004-09-10 20:48:21 +00002303 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002304
2305 stream_putc (stream, hdr->idrp);
2306 stream_putc (stream, hdr->length);
2307 stream_putc (stream, hdr->version1);
2308 stream_putc (stream, hdr->id_len);
2309 stream_putc (stream, hdr->pdu_type);
2310 stream_putc (stream, hdr->version2);
2311 stream_putc (stream, hdr->reserved);
2312 stream_putc (stream, hdr->max_area_addrs);
2313
2314 return;
2315}
2316
jardineb5d44e2003-12-23 08:09:43 +00002317int
2318send_hello (struct isis_circuit *circuit, int level)
2319{
2320 struct isis_fixed_hdr fixed_hdr;
2321 struct isis_lan_hello_hdr hello_hdr;
2322 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002323 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
David Lamparter01da6172015-04-10 09:10:11 +02002324 size_t len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002325 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002326 int retval;
2327
Josh Bailey3f045a02012-03-24 08:35:20 -07002328 if (circuit->is_passive)
2329 return ISIS_OK;
2330
hassof390d2c2004-09-10 20:48:21 +00002331 if (circuit->interface->mtu == 0)
2332 {
2333 zlog_warn ("circuit has zero MTU");
2334 return ISIS_WARNING;
2335 }
jardineb5d44e2003-12-23 08:09:43 +00002336
2337 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002338 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002339 else
2340 stream_reset (circuit->snd_stream);
2341
2342 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002343 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002344 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2345 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002346 else
hassof390d2c2004-09-10 20:48:21 +00002347 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2348 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002349 else
hassof390d2c2004-09-10 20:48:21 +00002350 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002351
2352 /*
2353 * Fill LAN Level 1 or 2 Hello PDU header
2354 */
2355 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002356 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002357 circuit->hello_interval[level - 1];
2358 if (interval > USHRT_MAX)
2359 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002360 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002361 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002362 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002363
hassof390d2c2004-09-10 20:48:21 +00002364 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002365 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002366
2367 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002368 if (circuit->circ_type == CIRCUIT_T_P2P)
2369 {
2370 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2371 p2p_hello_hdr.local_id = circuit->circuit_id;
2372 /* FIXME: need better understanding */
2373 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002374 }
hassof390d2c2004-09-10 20:48:21 +00002375 else
2376 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002377 hello_hdr.prio = circuit->priority[level - 1];
2378 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002379 {
2380 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2381 ISIS_SYS_ID_LEN + 1);
2382 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002383 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002384 {
2385 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2386 ISIS_SYS_ID_LEN + 1);
2387 }
2388 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2389 }
jardineb5d44e2003-12-23 08:09:43 +00002390
2391 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002392 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002393 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002394
jardineb5d44e2003-12-23 08:09:43 +00002395 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002396 switch (circuit->passwd.type)
2397 {
2398 /* Cleartext */
2399 case ISIS_PASSWD_TYPE_CLEARTXT:
2400 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2401 circuit->passwd.passwd, circuit->snd_stream))
2402 return ISIS_WARNING;
2403 break;
2404
2405 /* HMAC MD5 */
2406 case ISIS_PASSWD_TYPE_HMAC_MD5:
2407 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2408 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2409 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2410 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2411 hmac_md5_hash, circuit->snd_stream))
2412 return ISIS_WARNING;
2413 break;
2414
2415 default:
2416 break;
2417 }
2418
jardineb5d44e2003-12-23 08:09:43 +00002419 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002420 if (listcount (circuit->area->area_addrs) == 0)
2421 return ISIS_WARNING;
2422 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2423 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002424
2425 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002426 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2427 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002428 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2429 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002430 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2431 circuit->snd_stream))
2432 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002433 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2434 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002435 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2436 circuit->snd_stream))
2437 return ISIS_WARNING;
2438 }
jardineb5d44e2003-12-23 08:09:43 +00002439
2440 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002441 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002442 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2443 return ISIS_WARNING;
2444 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002445 if (circuit->ip_router && circuit->ip_addrs &&
2446 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002447 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2448 return ISIS_WARNING;
2449
hassof390d2c2004-09-10 20:48:21 +00002450#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002451 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002452 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002453 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002454 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2455 return ISIS_WARNING;
2456#endif /* HAVE_IPV6 */
2457
Josh Bailey3f045a02012-03-24 08:35:20 -07002458 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002459 if (tlv_add_padding (circuit->snd_stream))
2460 return ISIS_WARNING;
2461
paul9985f832005-02-09 15:51:56 +00002462 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002463 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002464 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002465
Josh Bailey3f045a02012-03-24 08:35:20 -07002466 /* For HMAC MD5 we need to compute the md5 hash and store it */
2467 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2468 {
2469 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2470 stream_get_endp (circuit->snd_stream),
2471 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
David Lamparter21401f32015-03-03 08:55:26 +01002472 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002473 /* Copy the hash into the stream */
2474 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2475 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2476 }
jardineb5d44e2003-12-23 08:09:43 +00002477
hassof390d2c2004-09-10 20:48:21 +00002478 if (isis->debugs & DEBUG_ADJ_PACKETS)
2479 {
2480 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2481 {
David Lamparter01da6172015-04-10 09:10:11 +02002482 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002483 circuit->area->area_tag, level, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002484 length);
hassof390d2c2004-09-10 20:48:21 +00002485 }
2486 else
2487 {
David Lamparter01da6172015-04-10 09:10:11 +02002488 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002489 circuit->area->area_tag, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002490 length);
hassof390d2c2004-09-10 20:48:21 +00002491 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002492 if (isis->debugs & DEBUG_PACKET_DUMP)
2493 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2494 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002495 }
jardineb5d44e2003-12-23 08:09:43 +00002496
Josh Bailey3f045a02012-03-24 08:35:20 -07002497 retval = circuit->tx (circuit, level);
2498 if (retval != ISIS_OK)
2499 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2500 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002501
Josh Bailey3f045a02012-03-24 08:35:20 -07002502 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002503}
2504
2505int
2506send_lan_l1_hello (struct thread *thread)
2507{
jardineb5d44e2003-12-23 08:09:43 +00002508 struct isis_circuit *circuit;
2509 int retval;
2510
2511 circuit = THREAD_ARG (thread);
2512 assert (circuit);
2513 circuit->u.bc.t_send_lan_hello[0] = NULL;
2514
2515 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002516 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002517
Josh Bailey3f045a02012-03-24 08:35:20 -07002518 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002519
2520 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002521 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2522 send_lan_l1_hello, circuit,
2523 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002524
2525 return retval;
2526}
2527
2528int
2529send_lan_l2_hello (struct thread *thread)
2530{
2531 struct isis_circuit *circuit;
2532 int retval;
2533
2534 circuit = THREAD_ARG (thread);
2535 assert (circuit);
2536 circuit->u.bc.t_send_lan_hello[1] = NULL;
2537
2538 if (circuit->u.bc.run_dr_elect[1])
2539 retval = isis_dr_elect (circuit, 2);
2540
Josh Bailey3f045a02012-03-24 08:35:20 -07002541 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002542
hassof390d2c2004-09-10 20:48:21 +00002543 /* set next timer thread */
2544 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2545 send_lan_l2_hello, circuit,
2546 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002547
2548 return retval;
2549}
2550
2551int
2552send_p2p_hello (struct thread *thread)
2553{
2554 struct isis_circuit *circuit;
2555
2556 circuit = THREAD_ARG (thread);
2557 assert (circuit);
2558 circuit->u.p2p.t_send_p2p_hello = NULL;
2559
hassof390d2c2004-09-10 20:48:21 +00002560 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002561
hassof390d2c2004-09-10 20:48:21 +00002562 /* set next timer thread */
2563 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2564 circuit, isis_jitter (circuit->hello_interval[1],
2565 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002566
2567 return ISIS_OK;
2568}
2569
hasso92365882005-01-18 13:53:33 +00002570static int
hassof390d2c2004-09-10 20:48:21 +00002571build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2572 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002573{
2574 struct isis_fixed_hdr fixed_hdr;
2575 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002576 unsigned long lenp;
2577 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002578 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2579 unsigned long auth_tlv_offset = 0;
2580 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002581
Josh Bailey3f045a02012-03-24 08:35:20 -07002582 if (circuit->snd_stream == NULL)
2583 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2584 else
2585 stream_reset (circuit->snd_stream);
2586
2587 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002588 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2589 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002590 else
hassof390d2c2004-09-10 20:48:21 +00002591 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2592 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002593
2594 /*
2595 * Fill Level 1 or 2 Complete Sequence Numbers header
2596 */
2597
paul9985f832005-02-09 15:51:56 +00002598 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002599 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002600 /* no need to send the source here, it is always us if we csnp */
2601 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2602 /* with zero circuit id - ref 9.10, 9.11 */
2603 stream_putc (circuit->snd_stream, 0x00);
2604
2605 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2606 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2607
2608 /*
2609 * And TLVs
2610 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002611 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002612 passwd = &circuit->area->area_passwd;
2613 else
2614 passwd = &circuit->area->domain_passwd;
2615
hasso1cbc5622005-01-01 10:29:51 +00002616 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002617 {
2618 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002619 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002620 /* Cleartext */
2621 case ISIS_PASSWD_TYPE_CLEARTXT:
2622 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2623 passwd->passwd, circuit->snd_stream))
2624 return ISIS_WARNING;
2625 break;
2626
2627 /* HMAC MD5 */
2628 case ISIS_PASSWD_TYPE_HMAC_MD5:
2629 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2630 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2631 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2632 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2633 hmac_md5_hash, circuit->snd_stream))
2634 return ISIS_WARNING;
2635 break;
2636
2637 default:
2638 break;
hassof390d2c2004-09-10 20:48:21 +00002639 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002640 }
2641
2642 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2643 if (retval != ISIS_OK)
2644 return retval;
2645
paul9985f832005-02-09 15:51:56 +00002646 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002647 /* Update PU length */
2648 stream_putw_at (circuit->snd_stream, lenp, length);
2649
Josh Bailey3f045a02012-03-24 08:35:20 -07002650 /* For HMAC MD5 we need to compute the md5 hash and store it */
2651 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2652 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2653 {
2654 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2655 stream_get_endp(circuit->snd_stream),
2656 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002657 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002658 /* Copy the hash into the stream */
2659 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2660 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2661 }
2662
jardineb5d44e2003-12-23 08:09:43 +00002663 return retval;
2664}
2665
2666/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002667 * Count the maximum number of lsps that can be accomodated by a given size.
2668 */
2669static uint16_t
2670get_max_lsp_count (uint16_t size)
2671{
2672 uint16_t tlv_count;
2673 uint16_t lsp_count;
2674 uint16_t remaining_size;
2675
2676 /* First count the full size TLVs */
2677 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2678 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2679
2680 /* The last TLV, if any */
2681 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2682 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2683 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2684
2685 return lsp_count;
2686}
2687
2688/*
2689 * Calculate the length of Authentication Info. TLV.
2690 */
2691static uint16_t
2692auth_tlv_length (int level, struct isis_circuit *circuit)
2693{
2694 struct isis_passwd *passwd;
2695 uint16_t length;
2696
2697 if (level == IS_LEVEL_1)
2698 passwd = &circuit->area->area_passwd;
2699 else
2700 passwd = &circuit->area->domain_passwd;
2701
2702 /* Also include the length of TLV header */
2703 length = AUTH_INFO_HDRLEN;
2704 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2705 {
2706 switch (passwd->type)
2707 {
2708 /* Cleartext */
2709 case ISIS_PASSWD_TYPE_CLEARTXT:
2710 length += passwd->len;
2711 break;
2712
2713 /* HMAC MD5 */
2714 case ISIS_PASSWD_TYPE_HMAC_MD5:
2715 length += ISIS_AUTH_MD5_SIZE;
2716 break;
2717
2718 default:
2719 break;
2720 }
2721 }
2722
2723 return length;
2724}
2725
2726/*
2727 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2728 */
2729static uint16_t
2730max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2731{
2732 int snp_hdr_len;
2733 int auth_tlv_len;
2734 uint16_t lsp_count;
2735
2736 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2737 if (snp_type == ISIS_SNP_CSNP_FLAG)
2738 snp_hdr_len += ISIS_CSNP_HDRLEN;
2739 else
2740 snp_hdr_len += ISIS_PSNP_HDRLEN;
2741
2742 auth_tlv_len = auth_tlv_length (level, circuit);
2743 lsp_count = get_max_lsp_count (
2744 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002745 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002746}
2747
2748/*
jardineb5d44e2003-12-23 08:09:43 +00002749 * FIXME: support multiple CSNPs
2750 */
2751
2752int
2753send_csnp (struct isis_circuit *circuit, int level)
2754{
jardineb5d44e2003-12-23 08:09:43 +00002755 u_char start[ISIS_SYS_ID_LEN + 2];
2756 u_char stop[ISIS_SYS_ID_LEN + 2];
2757 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002758 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002759 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002760 u_char num_lsps, loop = 1;
2761 int i, retval = ISIS_OK;
2762
2763 if (circuit->area->lspdb[level - 1] == NULL ||
2764 dict_count (circuit->area->lspdb[level - 1]) == 0)
2765 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002766
hassof390d2c2004-09-10 20:48:21 +00002767 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002768 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2769
Josh Bailey3f045a02012-03-24 08:35:20 -07002770 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2771
2772 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002773 {
2774 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002775 lsp_build_list (start, stop, num_lsps, list,
2776 circuit->area->lspdb[level - 1]);
2777 /*
2778 * Update the stop lsp_id before encoding this CSNP.
2779 */
2780 if (listcount (list) < num_lsps)
2781 {
2782 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2783 }
hassof390d2c2004-09-10 20:48:21 +00002784 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002785 {
2786 node = listtail (list);
2787 lsp = listgetdata (node);
2788 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2789 }
jardineb5d44e2003-12-23 08:09:43 +00002790
hassof390d2c2004-09-10 20:48:21 +00002791 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002792 if (retval != ISIS_OK)
2793 {
2794 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2795 circuit->area->area_tag, level, circuit->interface->name);
2796 list_delete (list);
2797 return retval;
2798 }
jardineb5d44e2003-12-23 08:09:43 +00002799
hassof390d2c2004-09-10 20:48:21 +00002800 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002801 {
David Lamparter01da6172015-04-10 09:10:11 +02002802 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07002803 circuit->area->area_tag, level, circuit->interface->name,
2804 stream_get_endp (circuit->snd_stream));
2805 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2806 {
2807 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2808 " cksum 0x%04x, lifetime %us",
2809 circuit->area->area_tag,
2810 rawlspid_print (lsp->lsp_header->lsp_id),
2811 ntohl (lsp->lsp_header->seq_num),
2812 ntohs (lsp->lsp_header->checksum),
2813 ntohs (lsp->lsp_header->rem_lifetime));
2814 }
2815 if (isis->debugs & DEBUG_PACKET_DUMP)
2816 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2817 stream_get_endp (circuit->snd_stream));
2818 }
hassof390d2c2004-09-10 20:48:21 +00002819
Josh Bailey3f045a02012-03-24 08:35:20 -07002820 retval = circuit->tx (circuit, level);
2821 if (retval != ISIS_OK)
2822 {
2823 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2824 circuit->area->area_tag, level,
2825 circuit->interface->name);
2826 list_delete (list);
2827 return retval;
2828 }
2829
2830 /*
2831 * Start lsp_id of the next CSNP should be one plus the
2832 * stop lsp_id in this current CSNP.
2833 */
2834 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2835 loop = 0;
2836 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2837 {
2838 if (start[i] < (u_char)0xff)
2839 {
2840 start[i] += 1;
2841 loop = 1;
2842 break;
2843 }
2844 }
2845 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002846 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002847 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002848
jardineb5d44e2003-12-23 08:09:43 +00002849 return retval;
2850}
2851
2852int
2853send_l1_csnp (struct thread *thread)
2854{
2855 struct isis_circuit *circuit;
2856 int retval = ISIS_OK;
2857
2858 circuit = THREAD_ARG (thread);
2859 assert (circuit);
2860
2861 circuit->t_send_csnp[0] = NULL;
2862
hassof390d2c2004-09-10 20:48:21 +00002863 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2864 {
2865 send_csnp (circuit, 1);
2866 }
jardineb5d44e2003-12-23 08:09:43 +00002867 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002868 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2869 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002870
2871 return retval;
2872}
2873
2874int
2875send_l2_csnp (struct thread *thread)
2876{
2877 struct isis_circuit *circuit;
2878 int retval = ISIS_OK;
2879
2880 circuit = THREAD_ARG (thread);
2881 assert (circuit);
2882
2883 circuit->t_send_csnp[1] = NULL;
2884
hassof390d2c2004-09-10 20:48:21 +00002885 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2886 {
2887 send_csnp (circuit, 2);
2888 }
jardineb5d44e2003-12-23 08:09:43 +00002889 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002890 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2891 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002892
jardineb5d44e2003-12-23 08:09:43 +00002893 return retval;
2894}
2895
hasso92365882005-01-18 13:53:33 +00002896static int
jardineb5d44e2003-12-23 08:09:43 +00002897build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2898{
2899 struct isis_fixed_hdr fixed_hdr;
2900 unsigned long lenp;
2901 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002902 struct isis_lsp *lsp;
2903 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002904 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002905 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2906 unsigned long auth_tlv_offset = 0;
2907 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002908
Josh Bailey3f045a02012-03-24 08:35:20 -07002909 if (circuit->snd_stream == NULL)
2910 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2911 else
2912 stream_reset (circuit->snd_stream);
2913
2914 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002915 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2916 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002917 else
2918 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002919 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002920
2921 /*
2922 * Fill Level 1 or 2 Partial Sequence Numbers header
2923 */
paul9985f832005-02-09 15:51:56 +00002924 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002925 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002926 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2927 stream_putc (circuit->snd_stream, circuit->idx);
2928
2929 /*
2930 * And TLVs
2931 */
2932
Josh Bailey3f045a02012-03-24 08:35:20 -07002933 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002934 passwd = &circuit->area->area_passwd;
2935 else
2936 passwd = &circuit->area->domain_passwd;
2937
hasso1cbc5622005-01-01 10:29:51 +00002938 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002939 {
2940 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002941 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002942 /* Cleartext */
2943 case ISIS_PASSWD_TYPE_CLEARTXT:
2944 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2945 passwd->passwd, circuit->snd_stream))
2946 return ISIS_WARNING;
2947 break;
2948
2949 /* HMAC MD5 */
2950 case ISIS_PASSWD_TYPE_HMAC_MD5:
2951 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2952 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2953 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2954 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2955 hmac_md5_hash, circuit->snd_stream))
2956 return ISIS_WARNING;
2957 break;
2958
2959 default:
2960 break;
jardineb5d44e2003-12-23 08:09:43 +00002961 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002962 }
2963
2964 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2965 if (retval != ISIS_OK)
2966 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002967
hassof390d2c2004-09-10 20:48:21 +00002968 if (isis->debugs & DEBUG_SNP_PACKETS)
2969 {
hasso3fdb2dd2005-09-28 18:45:54 +00002970 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002971 {
hasso529d65b2004-12-24 00:14:50 +00002972 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2973 " cksum 0x%04x, lifetime %us",
2974 circuit->area->area_tag,
2975 rawlspid_print (lsp->lsp_header->lsp_id),
2976 ntohl (lsp->lsp_header->seq_num),
2977 ntohs (lsp->lsp_header->checksum),
2978 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002979 }
2980 }
2981
paul9985f832005-02-09 15:51:56 +00002982 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002983 /* Update PDU length */
2984 stream_putw_at (circuit->snd_stream, lenp, length);
2985
Josh Bailey3f045a02012-03-24 08:35:20 -07002986 /* For HMAC MD5 we need to compute the md5 hash and store it */
2987 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2988 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2989 {
2990 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2991 stream_get_endp(circuit->snd_stream),
2992 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002993 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002994 /* Copy the hash into the stream */
2995 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2996 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2997 }
2998
jardineb5d44e2003-12-23 08:09:43 +00002999 return ISIS_OK;
3000}
3001
3002/*
3003 * 7.3.15.4 action on expiration of partial SNP interval
3004 * level 1
3005 */
hasso92365882005-01-18 13:53:33 +00003006static int
jardineb5d44e2003-12-23 08:09:43 +00003007send_psnp (int level, struct isis_circuit *circuit)
3008{
jardineb5d44e2003-12-23 08:09:43 +00003009 struct isis_lsp *lsp;
3010 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00003011 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003012 u_char num_lsps;
3013 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003014
Josh Bailey3f045a02012-03-24 08:35:20 -07003015 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
3016 circuit->u.bc.is_dr[level - 1])
3017 return ISIS_OK;
3018
3019 if (circuit->area->lspdb[level - 1] == NULL ||
3020 dict_count (circuit->area->lspdb[level - 1]) == 0)
3021 return ISIS_OK;
3022
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07003023 if (! circuit->snd_stream)
3024 return ISIS_ERROR;
3025
Josh Bailey3f045a02012-03-24 08:35:20 -07003026 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
3027
3028 while (1)
hassof390d2c2004-09-10 20:48:21 +00003029 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003030 list = list_new ();
3031 lsp_build_list_ssn (circuit, num_lsps, list,
3032 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00003033
Josh Bailey3f045a02012-03-24 08:35:20 -07003034 if (listcount (list) == 0)
3035 {
3036 list_delete (list);
3037 return ISIS_OK;
3038 }
jardineb5d44e2003-12-23 08:09:43 +00003039
Josh Bailey3f045a02012-03-24 08:35:20 -07003040 retval = build_psnp (level, circuit, list);
3041 if (retval != ISIS_OK)
3042 {
3043 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
3044 circuit->area->area_tag, level, circuit->interface->name);
3045 list_delete (list);
3046 return retval;
3047 }
jardineb5d44e2003-12-23 08:09:43 +00003048
Josh Bailey3f045a02012-03-24 08:35:20 -07003049 if (isis->debugs & DEBUG_SNP_PACKETS)
3050 {
David Lamparter01da6172015-04-10 09:10:11 +02003051 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07003052 circuit->area->area_tag, level,
3053 circuit->interface->name,
3054 stream_get_endp (circuit->snd_stream));
3055 if (isis->debugs & DEBUG_PACKET_DUMP)
3056 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3057 stream_get_endp (circuit->snd_stream));
3058 }
jardineb5d44e2003-12-23 08:09:43 +00003059
Josh Bailey3f045a02012-03-24 08:35:20 -07003060 retval = circuit->tx (circuit, level);
3061 if (retval != ISIS_OK)
3062 {
3063 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
3064 circuit->area->area_tag, level,
3065 circuit->interface->name);
3066 list_delete (list);
3067 return retval;
3068 }
jardineb5d44e2003-12-23 08:09:43 +00003069
Josh Bailey3f045a02012-03-24 08:35:20 -07003070 /*
3071 * sending succeeded, we can clear SSN flags of this circuit
3072 * for the LSPs in list
3073 */
3074 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
3075 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
3076 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00003077 }
jardineb5d44e2003-12-23 08:09:43 +00003078
3079 return retval;
3080}
3081
3082int
3083send_l1_psnp (struct thread *thread)
3084{
3085
3086 struct isis_circuit *circuit;
3087 int retval = ISIS_OK;
3088
3089 circuit = THREAD_ARG (thread);
3090 assert (circuit);
3091
3092 circuit->t_send_psnp[0] = NULL;
3093
3094 send_psnp (1, circuit);
3095 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003096 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
3097 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003098
3099 return retval;
3100}
3101
3102/*
3103 * 7.3.15.4 action on expiration of partial SNP interval
3104 * level 2
3105 */
3106int
3107send_l2_psnp (struct thread *thread)
3108{
jardineb5d44e2003-12-23 08:09:43 +00003109 struct isis_circuit *circuit;
3110 int retval = ISIS_OK;
3111
3112 circuit = THREAD_ARG (thread);
3113 assert (circuit);
3114
3115 circuit->t_send_psnp[1] = NULL;
3116
3117 send_psnp (2, circuit);
3118
3119 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003120 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3121 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003122
3123 return retval;
3124}
3125
jardineb5d44e2003-12-23 08:09:43 +00003126/*
3127 * ISO 10589 - 7.3.14.3
3128 */
3129int
3130send_lsp (struct thread *thread)
3131{
3132 struct isis_circuit *circuit;
3133 struct isis_lsp *lsp;
3134 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003135 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003136
3137 circuit = THREAD_ARG (thread);
3138 assert (circuit);
3139
Josh Bailey3f045a02012-03-24 08:35:20 -07003140 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3141 {
3142 return retval;
3143 }
3144
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003145 node = listhead (circuit->lsp_queue);
3146
3147 /*
3148 * Handle case where there are no LSPs on the queue. This can
3149 * happen, for instance, if an adjacency goes down before this
3150 * thread gets a chance to run.
3151 */
3152 if (!node)
3153 {
3154 return retval;
3155 }
3156
3157 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003158
3159 /*
3160 * Do not send if levels do not match
3161 */
3162 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003163 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003164 list_delete_node (circuit->lsp_queue, node);
3165 return retval;
hassof390d2c2004-09-10 20:48:21 +00003166 }
jardineb5d44e2003-12-23 08:09:43 +00003167
Josh Bailey3f045a02012-03-24 08:35:20 -07003168 /*
3169 * Do not send if we do not have adjacencies in state up on the circuit
3170 */
3171 if (circuit->upadjcount[lsp->level - 1] == 0)
3172 {
3173 list_delete_node (circuit->lsp_queue, node);
3174 return retval;
3175 }
3176
3177 /* copy our lsp to the send buffer */
3178 stream_copy (circuit->snd_stream, lsp->pdu);
3179
3180 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3181 {
3182 zlog_debug
3183 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3184 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3185 rawlspid_print (lsp->lsp_header->lsp_id),
3186 ntohl (lsp->lsp_header->seq_num),
3187 ntohs (lsp->lsp_header->checksum),
3188 ntohs (lsp->lsp_header->rem_lifetime),
3189 circuit->interface->name);
3190 if (isis->debugs & DEBUG_PACKET_DUMP)
3191 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3192 stream_get_endp (circuit->snd_stream));
3193 }
3194
3195 retval = circuit->tx (circuit, lsp->level);
3196 if (retval != ISIS_OK)
3197 {
3198 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3199 circuit->area->area_tag, lsp->level,
3200 circuit->interface->name);
3201 return retval;
3202 }
3203
3204 /*
3205 * If the sending succeeded, we can del the lsp from circuits
3206 * lsp_queue
3207 */
3208 list_delete_node (circuit->lsp_queue, node);
3209
3210 /* Set the last-cleared time if the queue is empty. */
3211 /* TODO: Is is possible that new lsps keep being added to the queue
3212 * that the queue is never empty? */
3213 if (list_isempty (circuit->lsp_queue))
3214 circuit->lsp_queue_last_cleared = time (NULL);
3215
3216 /*
3217 * On broadcast circuits also the SRMflag can be cleared
3218 */
3219 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3220 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3221
jardineb5d44e2003-12-23 08:09:43 +00003222 return retval;
hassof390d2c2004-09-10 20:48:21 +00003223}
jardineb5d44e2003-12-23 08:09:43 +00003224
3225int
hassof390d2c2004-09-10 20:48:21 +00003226ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3227 int level)
jardineb5d44e2003-12-23 08:09:43 +00003228{
3229 unsigned long lenp;
3230 int retval;
3231 u_int16_t length;
3232 struct isis_fixed_hdr fixed_hdr;
3233
3234 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003235 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003236 else
3237 stream_reset (circuit->snd_stream);
3238
Josh Bailey3f045a02012-03-24 08:35:20 -07003239 // fill_llc_hdr (stream);
3240 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003241 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3242 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003243 else
hassof390d2c2004-09-10 20:48:21 +00003244 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3245 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003246
3247
paul9985f832005-02-09 15:51:56 +00003248 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003249 stream_putw (circuit->snd_stream, 0); /* PDU length */
3250 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003251 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003252 stream_putc (circuit->snd_stream, 9); /* code */
3253 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003254
hassof390d2c2004-09-10 20:48:21 +00003255 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3256 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3257 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3258 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003259
paul9985f832005-02-09 15:51:56 +00003260 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003261 /* Update PDU length */
3262 stream_putw_at (circuit->snd_stream, lenp, length);
3263
3264 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003265 if (retval != ISIS_OK)
3266 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3267 circuit->area->area_tag, level,
3268 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003269
3270 return retval;
3271}