blob: 557dc01028cffc281782b0e921520fac685b4ea8 [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, "
1267 "cirID %u, length %ld",
1268 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];
2324 unsigned long 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 {
hasso529d65b2004-12-24 00:14:50 +00002482 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2483 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002484 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002485 length);
hassof390d2c2004-09-10 20:48:21 +00002486 }
2487 else
2488 {
hasso529d65b2004-12-24 00:14:50 +00002489 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2490 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002491 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002492 length);
hassof390d2c2004-09-10 20:48:21 +00002493 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002494 if (isis->debugs & DEBUG_PACKET_DUMP)
2495 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2496 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002497 }
jardineb5d44e2003-12-23 08:09:43 +00002498
Josh Bailey3f045a02012-03-24 08:35:20 -07002499 retval = circuit->tx (circuit, level);
2500 if (retval != ISIS_OK)
2501 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2502 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002503
Josh Bailey3f045a02012-03-24 08:35:20 -07002504 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002505}
2506
2507int
2508send_lan_l1_hello (struct thread *thread)
2509{
jardineb5d44e2003-12-23 08:09:43 +00002510 struct isis_circuit *circuit;
2511 int retval;
2512
2513 circuit = THREAD_ARG (thread);
2514 assert (circuit);
2515 circuit->u.bc.t_send_lan_hello[0] = NULL;
2516
2517 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002518 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002519
Josh Bailey3f045a02012-03-24 08:35:20 -07002520 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002521
2522 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002523 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2524 send_lan_l1_hello, circuit,
2525 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002526
2527 return retval;
2528}
2529
2530int
2531send_lan_l2_hello (struct thread *thread)
2532{
2533 struct isis_circuit *circuit;
2534 int retval;
2535
2536 circuit = THREAD_ARG (thread);
2537 assert (circuit);
2538 circuit->u.bc.t_send_lan_hello[1] = NULL;
2539
2540 if (circuit->u.bc.run_dr_elect[1])
2541 retval = isis_dr_elect (circuit, 2);
2542
Josh Bailey3f045a02012-03-24 08:35:20 -07002543 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002544
hassof390d2c2004-09-10 20:48:21 +00002545 /* set next timer thread */
2546 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2547 send_lan_l2_hello, circuit,
2548 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002549
2550 return retval;
2551}
2552
2553int
2554send_p2p_hello (struct thread *thread)
2555{
2556 struct isis_circuit *circuit;
2557
2558 circuit = THREAD_ARG (thread);
2559 assert (circuit);
2560 circuit->u.p2p.t_send_p2p_hello = NULL;
2561
hassof390d2c2004-09-10 20:48:21 +00002562 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002563
hassof390d2c2004-09-10 20:48:21 +00002564 /* set next timer thread */
2565 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2566 circuit, isis_jitter (circuit->hello_interval[1],
2567 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002568
2569 return ISIS_OK;
2570}
2571
hasso92365882005-01-18 13:53:33 +00002572static int
hassof390d2c2004-09-10 20:48:21 +00002573build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2574 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002575{
2576 struct isis_fixed_hdr fixed_hdr;
2577 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002578 unsigned long lenp;
2579 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002580 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2581 unsigned long auth_tlv_offset = 0;
2582 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002583
Josh Bailey3f045a02012-03-24 08:35:20 -07002584 if (circuit->snd_stream == NULL)
2585 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2586 else
2587 stream_reset (circuit->snd_stream);
2588
2589 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002590 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2591 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002592 else
hassof390d2c2004-09-10 20:48:21 +00002593 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2594 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002595
2596 /*
2597 * Fill Level 1 or 2 Complete Sequence Numbers header
2598 */
2599
paul9985f832005-02-09 15:51:56 +00002600 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002601 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002602 /* no need to send the source here, it is always us if we csnp */
2603 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2604 /* with zero circuit id - ref 9.10, 9.11 */
2605 stream_putc (circuit->snd_stream, 0x00);
2606
2607 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2608 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2609
2610 /*
2611 * And TLVs
2612 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002613 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002614 passwd = &circuit->area->area_passwd;
2615 else
2616 passwd = &circuit->area->domain_passwd;
2617
hasso1cbc5622005-01-01 10:29:51 +00002618 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002619 {
2620 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002621 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002622 /* Cleartext */
2623 case ISIS_PASSWD_TYPE_CLEARTXT:
2624 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2625 passwd->passwd, circuit->snd_stream))
2626 return ISIS_WARNING;
2627 break;
2628
2629 /* HMAC MD5 */
2630 case ISIS_PASSWD_TYPE_HMAC_MD5:
2631 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2632 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2633 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2634 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2635 hmac_md5_hash, circuit->snd_stream))
2636 return ISIS_WARNING;
2637 break;
2638
2639 default:
2640 break;
hassof390d2c2004-09-10 20:48:21 +00002641 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002642 }
2643
2644 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2645 if (retval != ISIS_OK)
2646 return retval;
2647
paul9985f832005-02-09 15:51:56 +00002648 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002649 /* Update PU length */
2650 stream_putw_at (circuit->snd_stream, lenp, length);
2651
Josh Bailey3f045a02012-03-24 08:35:20 -07002652 /* For HMAC MD5 we need to compute the md5 hash and store it */
2653 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2654 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2655 {
2656 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2657 stream_get_endp(circuit->snd_stream),
2658 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002659 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002660 /* Copy the hash into the stream */
2661 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2662 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2663 }
2664
jardineb5d44e2003-12-23 08:09:43 +00002665 return retval;
2666}
2667
2668/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002669 * Count the maximum number of lsps that can be accomodated by a given size.
2670 */
2671static uint16_t
2672get_max_lsp_count (uint16_t size)
2673{
2674 uint16_t tlv_count;
2675 uint16_t lsp_count;
2676 uint16_t remaining_size;
2677
2678 /* First count the full size TLVs */
2679 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2680 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2681
2682 /* The last TLV, if any */
2683 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2684 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2685 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2686
2687 return lsp_count;
2688}
2689
2690/*
2691 * Calculate the length of Authentication Info. TLV.
2692 */
2693static uint16_t
2694auth_tlv_length (int level, struct isis_circuit *circuit)
2695{
2696 struct isis_passwd *passwd;
2697 uint16_t length;
2698
2699 if (level == IS_LEVEL_1)
2700 passwd = &circuit->area->area_passwd;
2701 else
2702 passwd = &circuit->area->domain_passwd;
2703
2704 /* Also include the length of TLV header */
2705 length = AUTH_INFO_HDRLEN;
2706 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2707 {
2708 switch (passwd->type)
2709 {
2710 /* Cleartext */
2711 case ISIS_PASSWD_TYPE_CLEARTXT:
2712 length += passwd->len;
2713 break;
2714
2715 /* HMAC MD5 */
2716 case ISIS_PASSWD_TYPE_HMAC_MD5:
2717 length += ISIS_AUTH_MD5_SIZE;
2718 break;
2719
2720 default:
2721 break;
2722 }
2723 }
2724
2725 return length;
2726}
2727
2728/*
2729 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2730 */
2731static uint16_t
2732max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2733{
2734 int snp_hdr_len;
2735 int auth_tlv_len;
2736 uint16_t lsp_count;
2737
2738 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2739 if (snp_type == ISIS_SNP_CSNP_FLAG)
2740 snp_hdr_len += ISIS_CSNP_HDRLEN;
2741 else
2742 snp_hdr_len += ISIS_PSNP_HDRLEN;
2743
2744 auth_tlv_len = auth_tlv_length (level, circuit);
2745 lsp_count = get_max_lsp_count (
2746 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002747 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002748}
2749
2750/*
jardineb5d44e2003-12-23 08:09:43 +00002751 * FIXME: support multiple CSNPs
2752 */
2753
2754int
2755send_csnp (struct isis_circuit *circuit, int level)
2756{
jardineb5d44e2003-12-23 08:09:43 +00002757 u_char start[ISIS_SYS_ID_LEN + 2];
2758 u_char stop[ISIS_SYS_ID_LEN + 2];
2759 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002760 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002761 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002762 u_char num_lsps, loop = 1;
2763 int i, retval = ISIS_OK;
2764
2765 if (circuit->area->lspdb[level - 1] == NULL ||
2766 dict_count (circuit->area->lspdb[level - 1]) == 0)
2767 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002768
hassof390d2c2004-09-10 20:48:21 +00002769 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002770 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2771
Josh Bailey3f045a02012-03-24 08:35:20 -07002772 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2773
2774 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002775 {
2776 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002777 lsp_build_list (start, stop, num_lsps, list,
2778 circuit->area->lspdb[level - 1]);
2779 /*
2780 * Update the stop lsp_id before encoding this CSNP.
2781 */
2782 if (listcount (list) < num_lsps)
2783 {
2784 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2785 }
hassof390d2c2004-09-10 20:48:21 +00002786 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002787 {
2788 node = listtail (list);
2789 lsp = listgetdata (node);
2790 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2791 }
jardineb5d44e2003-12-23 08:09:43 +00002792
hassof390d2c2004-09-10 20:48:21 +00002793 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002794 if (retval != ISIS_OK)
2795 {
2796 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2797 circuit->area->area_tag, level, circuit->interface->name);
2798 list_delete (list);
2799 return retval;
2800 }
jardineb5d44e2003-12-23 08:09:43 +00002801
hassof390d2c2004-09-10 20:48:21 +00002802 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002803 {
2804 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2805 circuit->area->area_tag, level, circuit->interface->name,
2806 stream_get_endp (circuit->snd_stream));
2807 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2808 {
2809 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2810 " cksum 0x%04x, lifetime %us",
2811 circuit->area->area_tag,
2812 rawlspid_print (lsp->lsp_header->lsp_id),
2813 ntohl (lsp->lsp_header->seq_num),
2814 ntohs (lsp->lsp_header->checksum),
2815 ntohs (lsp->lsp_header->rem_lifetime));
2816 }
2817 if (isis->debugs & DEBUG_PACKET_DUMP)
2818 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2819 stream_get_endp (circuit->snd_stream));
2820 }
hassof390d2c2004-09-10 20:48:21 +00002821
Josh Bailey3f045a02012-03-24 08:35:20 -07002822 retval = circuit->tx (circuit, level);
2823 if (retval != ISIS_OK)
2824 {
2825 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2826 circuit->area->area_tag, level,
2827 circuit->interface->name);
2828 list_delete (list);
2829 return retval;
2830 }
2831
2832 /*
2833 * Start lsp_id of the next CSNP should be one plus the
2834 * stop lsp_id in this current CSNP.
2835 */
2836 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2837 loop = 0;
2838 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2839 {
2840 if (start[i] < (u_char)0xff)
2841 {
2842 start[i] += 1;
2843 loop = 1;
2844 break;
2845 }
2846 }
2847 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002848 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002849 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002850
jardineb5d44e2003-12-23 08:09:43 +00002851 return retval;
2852}
2853
2854int
2855send_l1_csnp (struct thread *thread)
2856{
2857 struct isis_circuit *circuit;
2858 int retval = ISIS_OK;
2859
2860 circuit = THREAD_ARG (thread);
2861 assert (circuit);
2862
2863 circuit->t_send_csnp[0] = NULL;
2864
hassof390d2c2004-09-10 20:48:21 +00002865 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2866 {
2867 send_csnp (circuit, 1);
2868 }
jardineb5d44e2003-12-23 08:09:43 +00002869 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002870 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2871 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002872
2873 return retval;
2874}
2875
2876int
2877send_l2_csnp (struct thread *thread)
2878{
2879 struct isis_circuit *circuit;
2880 int retval = ISIS_OK;
2881
2882 circuit = THREAD_ARG (thread);
2883 assert (circuit);
2884
2885 circuit->t_send_csnp[1] = NULL;
2886
hassof390d2c2004-09-10 20:48:21 +00002887 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2888 {
2889 send_csnp (circuit, 2);
2890 }
jardineb5d44e2003-12-23 08:09:43 +00002891 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002892 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2893 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002894
jardineb5d44e2003-12-23 08:09:43 +00002895 return retval;
2896}
2897
hasso92365882005-01-18 13:53:33 +00002898static int
jardineb5d44e2003-12-23 08:09:43 +00002899build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2900{
2901 struct isis_fixed_hdr fixed_hdr;
2902 unsigned long lenp;
2903 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002904 struct isis_lsp *lsp;
2905 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002906 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002907 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2908 unsigned long auth_tlv_offset = 0;
2909 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002910
Josh Bailey3f045a02012-03-24 08:35:20 -07002911 if (circuit->snd_stream == NULL)
2912 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2913 else
2914 stream_reset (circuit->snd_stream);
2915
2916 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002917 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2918 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002919 else
2920 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002921 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002922
2923 /*
2924 * Fill Level 1 or 2 Partial Sequence Numbers header
2925 */
paul9985f832005-02-09 15:51:56 +00002926 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002927 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002928 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2929 stream_putc (circuit->snd_stream, circuit->idx);
2930
2931 /*
2932 * And TLVs
2933 */
2934
Josh Bailey3f045a02012-03-24 08:35:20 -07002935 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002936 passwd = &circuit->area->area_passwd;
2937 else
2938 passwd = &circuit->area->domain_passwd;
2939
hasso1cbc5622005-01-01 10:29:51 +00002940 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002941 {
2942 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002943 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002944 /* Cleartext */
2945 case ISIS_PASSWD_TYPE_CLEARTXT:
2946 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2947 passwd->passwd, circuit->snd_stream))
2948 return ISIS_WARNING;
2949 break;
2950
2951 /* HMAC MD5 */
2952 case ISIS_PASSWD_TYPE_HMAC_MD5:
2953 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2954 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2955 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2956 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2957 hmac_md5_hash, circuit->snd_stream))
2958 return ISIS_WARNING;
2959 break;
2960
2961 default:
2962 break;
jardineb5d44e2003-12-23 08:09:43 +00002963 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002964 }
2965
2966 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2967 if (retval != ISIS_OK)
2968 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002969
hassof390d2c2004-09-10 20:48:21 +00002970 if (isis->debugs & DEBUG_SNP_PACKETS)
2971 {
hasso3fdb2dd2005-09-28 18:45:54 +00002972 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002973 {
hasso529d65b2004-12-24 00:14:50 +00002974 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2975 " cksum 0x%04x, lifetime %us",
2976 circuit->area->area_tag,
2977 rawlspid_print (lsp->lsp_header->lsp_id),
2978 ntohl (lsp->lsp_header->seq_num),
2979 ntohs (lsp->lsp_header->checksum),
2980 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002981 }
2982 }
2983
paul9985f832005-02-09 15:51:56 +00002984 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002985 /* Update PDU length */
2986 stream_putw_at (circuit->snd_stream, lenp, length);
2987
Josh Bailey3f045a02012-03-24 08:35:20 -07002988 /* For HMAC MD5 we need to compute the md5 hash and store it */
2989 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2990 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2991 {
2992 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2993 stream_get_endp(circuit->snd_stream),
2994 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002995 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002996 /* Copy the hash into the stream */
2997 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2998 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2999 }
3000
jardineb5d44e2003-12-23 08:09:43 +00003001 return ISIS_OK;
3002}
3003
3004/*
3005 * 7.3.15.4 action on expiration of partial SNP interval
3006 * level 1
3007 */
hasso92365882005-01-18 13:53:33 +00003008static int
jardineb5d44e2003-12-23 08:09:43 +00003009send_psnp (int level, struct isis_circuit *circuit)
3010{
jardineb5d44e2003-12-23 08:09:43 +00003011 struct isis_lsp *lsp;
3012 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00003013 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003014 u_char num_lsps;
3015 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003016
Josh Bailey3f045a02012-03-24 08:35:20 -07003017 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
3018 circuit->u.bc.is_dr[level - 1])
3019 return ISIS_OK;
3020
3021 if (circuit->area->lspdb[level - 1] == NULL ||
3022 dict_count (circuit->area->lspdb[level - 1]) == 0)
3023 return ISIS_OK;
3024
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07003025 if (! circuit->snd_stream)
3026 return ISIS_ERROR;
3027
Josh Bailey3f045a02012-03-24 08:35:20 -07003028 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
3029
3030 while (1)
hassof390d2c2004-09-10 20:48:21 +00003031 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003032 list = list_new ();
3033 lsp_build_list_ssn (circuit, num_lsps, list,
3034 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00003035
Josh Bailey3f045a02012-03-24 08:35:20 -07003036 if (listcount (list) == 0)
3037 {
3038 list_delete (list);
3039 return ISIS_OK;
3040 }
jardineb5d44e2003-12-23 08:09:43 +00003041
Josh Bailey3f045a02012-03-24 08:35:20 -07003042 retval = build_psnp (level, circuit, list);
3043 if (retval != ISIS_OK)
3044 {
3045 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
3046 circuit->area->area_tag, level, circuit->interface->name);
3047 list_delete (list);
3048 return retval;
3049 }
jardineb5d44e2003-12-23 08:09:43 +00003050
Josh Bailey3f045a02012-03-24 08:35:20 -07003051 if (isis->debugs & DEBUG_SNP_PACKETS)
3052 {
3053 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
3054 circuit->area->area_tag, level,
3055 circuit->interface->name,
3056 stream_get_endp (circuit->snd_stream));
3057 if (isis->debugs & DEBUG_PACKET_DUMP)
3058 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3059 stream_get_endp (circuit->snd_stream));
3060 }
jardineb5d44e2003-12-23 08:09:43 +00003061
Josh Bailey3f045a02012-03-24 08:35:20 -07003062 retval = circuit->tx (circuit, level);
3063 if (retval != ISIS_OK)
3064 {
3065 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
3066 circuit->area->area_tag, level,
3067 circuit->interface->name);
3068 list_delete (list);
3069 return retval;
3070 }
jardineb5d44e2003-12-23 08:09:43 +00003071
Josh Bailey3f045a02012-03-24 08:35:20 -07003072 /*
3073 * sending succeeded, we can clear SSN flags of this circuit
3074 * for the LSPs in list
3075 */
3076 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
3077 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
3078 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00003079 }
jardineb5d44e2003-12-23 08:09:43 +00003080
3081 return retval;
3082}
3083
3084int
3085send_l1_psnp (struct thread *thread)
3086{
3087
3088 struct isis_circuit *circuit;
3089 int retval = ISIS_OK;
3090
3091 circuit = THREAD_ARG (thread);
3092 assert (circuit);
3093
3094 circuit->t_send_psnp[0] = NULL;
3095
3096 send_psnp (1, circuit);
3097 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003098 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
3099 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003100
3101 return retval;
3102}
3103
3104/*
3105 * 7.3.15.4 action on expiration of partial SNP interval
3106 * level 2
3107 */
3108int
3109send_l2_psnp (struct thread *thread)
3110{
jardineb5d44e2003-12-23 08:09:43 +00003111 struct isis_circuit *circuit;
3112 int retval = ISIS_OK;
3113
3114 circuit = THREAD_ARG (thread);
3115 assert (circuit);
3116
3117 circuit->t_send_psnp[1] = NULL;
3118
3119 send_psnp (2, circuit);
3120
3121 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003122 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3123 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003124
3125 return retval;
3126}
3127
jardineb5d44e2003-12-23 08:09:43 +00003128/*
3129 * ISO 10589 - 7.3.14.3
3130 */
3131int
3132send_lsp (struct thread *thread)
3133{
3134 struct isis_circuit *circuit;
3135 struct isis_lsp *lsp;
3136 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003137 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003138
3139 circuit = THREAD_ARG (thread);
3140 assert (circuit);
3141
Josh Bailey3f045a02012-03-24 08:35:20 -07003142 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3143 {
3144 return retval;
3145 }
3146
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003147 node = listhead (circuit->lsp_queue);
3148
3149 /*
3150 * Handle case where there are no LSPs on the queue. This can
3151 * happen, for instance, if an adjacency goes down before this
3152 * thread gets a chance to run.
3153 */
3154 if (!node)
3155 {
3156 return retval;
3157 }
3158
3159 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003160
3161 /*
3162 * Do not send if levels do not match
3163 */
3164 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003165 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003166 list_delete_node (circuit->lsp_queue, node);
3167 return retval;
hassof390d2c2004-09-10 20:48:21 +00003168 }
jardineb5d44e2003-12-23 08:09:43 +00003169
Josh Bailey3f045a02012-03-24 08:35:20 -07003170 /*
3171 * Do not send if we do not have adjacencies in state up on the circuit
3172 */
3173 if (circuit->upadjcount[lsp->level - 1] == 0)
3174 {
3175 list_delete_node (circuit->lsp_queue, node);
3176 return retval;
3177 }
3178
3179 /* copy our lsp to the send buffer */
3180 stream_copy (circuit->snd_stream, lsp->pdu);
3181
3182 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3183 {
3184 zlog_debug
3185 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3186 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3187 rawlspid_print (lsp->lsp_header->lsp_id),
3188 ntohl (lsp->lsp_header->seq_num),
3189 ntohs (lsp->lsp_header->checksum),
3190 ntohs (lsp->lsp_header->rem_lifetime),
3191 circuit->interface->name);
3192 if (isis->debugs & DEBUG_PACKET_DUMP)
3193 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3194 stream_get_endp (circuit->snd_stream));
3195 }
3196
3197 retval = circuit->tx (circuit, lsp->level);
3198 if (retval != ISIS_OK)
3199 {
3200 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3201 circuit->area->area_tag, lsp->level,
3202 circuit->interface->name);
3203 return retval;
3204 }
3205
3206 /*
3207 * If the sending succeeded, we can del the lsp from circuits
3208 * lsp_queue
3209 */
3210 list_delete_node (circuit->lsp_queue, node);
3211
3212 /* Set the last-cleared time if the queue is empty. */
3213 /* TODO: Is is possible that new lsps keep being added to the queue
3214 * that the queue is never empty? */
3215 if (list_isempty (circuit->lsp_queue))
3216 circuit->lsp_queue_last_cleared = time (NULL);
3217
3218 /*
3219 * On broadcast circuits also the SRMflag can be cleared
3220 */
3221 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3222 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3223
jardineb5d44e2003-12-23 08:09:43 +00003224 return retval;
hassof390d2c2004-09-10 20:48:21 +00003225}
jardineb5d44e2003-12-23 08:09:43 +00003226
3227int
hassof390d2c2004-09-10 20:48:21 +00003228ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3229 int level)
jardineb5d44e2003-12-23 08:09:43 +00003230{
3231 unsigned long lenp;
3232 int retval;
3233 u_int16_t length;
3234 struct isis_fixed_hdr fixed_hdr;
3235
3236 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003237 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003238 else
3239 stream_reset (circuit->snd_stream);
3240
Josh Bailey3f045a02012-03-24 08:35:20 -07003241 // fill_llc_hdr (stream);
3242 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003243 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3244 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003245 else
hassof390d2c2004-09-10 20:48:21 +00003246 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3247 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003248
3249
paul9985f832005-02-09 15:51:56 +00003250 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003251 stream_putw (circuit->snd_stream, 0); /* PDU length */
3252 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003253 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003254 stream_putc (circuit->snd_stream, 9); /* code */
3255 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003256
hassof390d2c2004-09-10 20:48:21 +00003257 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3258 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3259 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3260 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003261
paul9985f832005-02-09 15:51:56 +00003262 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003263 /* Update PDU length */
3264 stream_putw_at (circuit->snd_stream, lenp, length);
3265
3266 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003267 if (retval != ISIS_OK)
3268 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3269 circuit->area->area_tag, level,
3270 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003271
3272 return retval;
3273}