blob: 7c04f44a181ad2011ed71737563137d953977ac8 [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 /*
Amritha Nambiar491417a2015-04-23 15:36:55 -0700565 * it's own p2p IIH PDU - discard
566 */
567 if (!memcmp (hdr->source_id, isis->sysid, ISIS_SYS_ID_LEN))
568 {
569 zlog_warn ("ISIS-Adj (%s): it's own IIH PDU - discarded",
570 circuit->area->area_tag);
571 free_tlvs (&tlvs);
572 return ISIS_WARNING;
573 }
574
575 /*
Josh Bailey3f045a02012-03-24 08:35:20 -0700576 * My interpertation of the ISO, if no adj exists we will create one for
577 * the circuit
578 */
579 adj = circuit->u.p2p.neighbor;
Amritha Nambiar3c28aaf2015-01-28 18:09:30 +0000580 /* If an adjacency exists, check it is with the source of the hello
581 * packets */
582 if (adj)
583 {
584 if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
585 {
586 zlog_debug("hello source and adjacency do not match, set adj down\n");
587 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
588 return 0;
589 }
590 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700591 if (!adj || adj->level != hdr->circuit_t)
592 {
593 if (!adj)
594 {
595 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
596 if (adj == NULL)
597 return ISIS_ERROR;
598 }
599 else
600 {
601 adj->level = hdr->circuit_t;
602 }
603 circuit->u.p2p.neighbor = adj;
604 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
605 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
606 }
607
608 /* 8.2.6 Monitoring point-to-point adjacencies */
609 adj->hold_time = ntohs (hdr->hold_time);
610 adj->last_upd = time (NULL);
611
jardineb5d44e2003-12-23 08:09:43 +0000612 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700613 tlvs_to_adj_area_addrs (&tlvs, adj);
614
615 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +0000616 if (tlvs_to_adj_nlpids (&tlvs, adj))
617 {
618 free_tlvs (&tlvs);
619 return ISIS_WARNING;
620 }
jardineb5d44e2003-12-23 08:09:43 +0000621
622 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700623 if (found & TLVFLAG_IPV4_ADDR)
624 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000625
626#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700627 if (found & TLVFLAG_IPV6_ADDR)
628 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000629#endif /* HAVE_IPV6 */
630
631 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000632 THREAD_TIMER_OFF (adj->t_expire);
633 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
634 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000635
636 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000637 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
638 {
639 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
640 if (circuit->area->is_type == IS_LEVEL_1)
641 {
642 switch (hdr->circuit_t)
643 {
644 case IS_LEVEL_1:
645 case IS_LEVEL_1_AND_2:
646 if (adj->adj_state != ISIS_ADJ_UP)
647 {
648 /* (4) adj state up */
649 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
650 /* (5) adj usage level 1 */
651 adj->adj_usage = ISIS_ADJ_LEVEL1;
652 }
653 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
654 {
655 ; /* accept */
656 }
657 break;
658 case IS_LEVEL_2:
659 if (adj->adj_state != ISIS_ADJ_UP)
660 {
661 /* (7) reject - wrong system type event */
662 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700663 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000664 return ISIS_WARNING; /* Reject */
665 }
666 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
667 {
668 /* (6) down - wrong system */
669 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
670 }
671 break;
672 }
673 }
jardineb5d44e2003-12-23 08:09:43 +0000674
hassof390d2c2004-09-10 20:48:21 +0000675 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
676 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
677 {
678 switch (hdr->circuit_t)
679 {
680 case IS_LEVEL_1:
681 if (adj->adj_state != ISIS_ADJ_UP)
682 {
683 /* (6) adj state up */
684 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
685 /* (7) adj usage level 1 */
686 adj->adj_usage = ISIS_ADJ_LEVEL1;
687 }
688 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
689 {
690 ; /* accept */
691 }
692 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
693 (adj->adj_usage == ISIS_ADJ_LEVEL2))
694 {
695 /* (8) down - wrong system */
696 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
697 }
698 break;
699 case IS_LEVEL_2:
700 if (adj->adj_state != ISIS_ADJ_UP)
701 {
702 /* (6) adj state up */
703 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
704 /* (9) adj usage level 2 */
705 adj->adj_usage = ISIS_ADJ_LEVEL2;
706 }
707 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
708 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
709 {
710 /* (8) down - wrong system */
711 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
712 }
713 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
714 {
715 ; /* Accept */
716 }
717 break;
718 case IS_LEVEL_1_AND_2:
719 if (adj->adj_state != ISIS_ADJ_UP)
720 {
721 /* (6) adj state up */
722 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
723 /* (10) adj usage level 1 */
724 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
725 }
726 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
727 (adj->adj_usage == ISIS_ADJ_LEVEL2))
728 {
729 /* (8) down - wrong system */
730 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
731 }
732 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
733 {
734 ; /* Accept */
735 }
736 break;
737 }
738 }
jardineb5d44e2003-12-23 08:09:43 +0000739
hassof390d2c2004-09-10 20:48:21 +0000740 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
741 if (circuit->area->is_type == IS_LEVEL_2)
742 {
743 switch (hdr->circuit_t)
744 {
745 case IS_LEVEL_1:
746 if (adj->adj_state != ISIS_ADJ_UP)
747 {
748 /* (5) reject - wrong system type event */
749 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700750 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000751 return ISIS_WARNING; /* Reject */
752 }
753 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
754 (adj->adj_usage == ISIS_ADJ_LEVEL2))
755 {
756 /* (6) down - wrong system */
757 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
758 }
759 break;
760 case IS_LEVEL_1_AND_2:
761 case IS_LEVEL_2:
762 if (adj->adj_state != ISIS_ADJ_UP)
763 {
764 /* (7) adj state up */
765 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
766 /* (8) adj usage level 2 */
767 adj->adj_usage = ISIS_ADJ_LEVEL2;
768 }
769 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
770 {
771 /* (6) down - wrong system */
772 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
773 }
774 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
775 {
776 ; /* Accept */
777 }
778 break;
779 }
780 }
jardineb5d44e2003-12-23 08:09:43 +0000781 }
jardineb5d44e2003-12-23 08:09:43 +0000782 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700783 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000784 {
hassof390d2c2004-09-10 20:48:21 +0000785 if (circuit->area->is_type == IS_LEVEL_1)
786 {
787 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
788 if (adj->adj_state != ISIS_ADJ_UP)
789 {
790 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
791 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
792 }
793 else
794 {
795 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
796 "Down - Area Mismatch");
797 }
798 }
799 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
800 else
801 {
802 switch (hdr->circuit_t)
803 {
804 case IS_LEVEL_1:
805 if (adj->adj_state != ISIS_ADJ_UP)
806 {
807 /* (6) reject - Area Mismatch event */
808 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700809 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000810 return ISIS_WARNING; /* Reject */
811 }
812 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
813 {
814 /* (7) down - area mismatch */
815 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000816
hassof390d2c2004-09-10 20:48:21 +0000817 }
818 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
819 (adj->adj_usage == ISIS_ADJ_LEVEL2))
820 {
821 /* (7) down - wrong system */
822 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
823 }
824 break;
825 case IS_LEVEL_1_AND_2:
826 case IS_LEVEL_2:
827 if (adj->adj_state != ISIS_ADJ_UP)
828 {
829 /* (8) adj state up */
830 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
831 /* (9) adj usage level 2 */
832 adj->adj_usage = ISIS_ADJ_LEVEL2;
833 }
834 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
835 {
836 /* (7) down - wrong system */
837 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
838 }
839 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
840 {
841 if (hdr->circuit_t == IS_LEVEL_2)
842 {
843 /* (7) down - wrong system */
844 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
845 "Wrong System");
846 }
847 else
848 {
849 /* (7) down - area mismatch */
850 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
851 "Area Mismatch");
852 }
853 }
854 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
855 {
856 ; /* Accept */
857 }
858 break;
859 }
860 }
jardineb5d44e2003-12-23 08:09:43 +0000861 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700862 else
863 {
864 /* down - area mismatch */
865 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
866 }
jardineb5d44e2003-12-23 08:09:43 +0000867 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
868 /* FIXME - Missing parts */
869
jardineb5d44e2003-12-23 08:09:43 +0000870 /* some of my own understanding of the ISO, why the heck does
871 * it not say what should I change the system_type to...
872 */
hassof390d2c2004-09-10 20:48:21 +0000873 switch (adj->adj_usage)
874 {
jardineb5d44e2003-12-23 08:09:43 +0000875 case ISIS_ADJ_LEVEL1:
876 adj->sys_type = ISIS_SYSTYPE_L1_IS;
877 break;
878 case ISIS_ADJ_LEVEL2:
879 adj->sys_type = ISIS_SYSTYPE_L2_IS;
880 break;
881 case ISIS_ADJ_LEVEL1AND2:
882 adj->sys_type = ISIS_SYSTYPE_L2_IS;
883 break;
884 case ISIS_ADJ_NONE:
885 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
886 break;
hassof390d2c2004-09-10 20:48:21 +0000887 }
jardineb5d44e2003-12-23 08:09:43 +0000888
889 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700890
891 if (isis->debugs & DEBUG_ADJ_PACKETS)
892 {
893 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
894 " cir id %02d, length %d",
895 circuit->area->area_tag, circuit->interface->name,
896 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700897 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700898 }
jardineb5d44e2003-12-23 08:09:43 +0000899
900 free_tlvs (&tlvs);
901
902 return retval;
903}
904
jardineb5d44e2003-12-23 08:09:43 +0000905/*
906 * Process IS-IS LAN Level 1/2 Hello PDU
907 */
hassof390d2c2004-09-10 20:48:21 +0000908static int
909process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000910{
911 int retval = ISIS_OK;
912 struct isis_lan_hello_hdr hdr;
913 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700914 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000915 struct tlvs tlvs;
916 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000917 struct listnode *node;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200918 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000919
Josh Bailey3f045a02012-03-24 08:35:20 -0700920 if (isis->debugs & DEBUG_ADJ_PACKETS)
921 {
922 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
923 "cirID %u",
924 circuit->area->area_tag, level, circuit->interface->name,
925 circuit_t2string (circuit->is_type), circuit->circuit_id);
926 if (isis->debugs & DEBUG_PACKET_DUMP)
927 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
928 stream_get_endp (circuit->rcv_stream));
929 }
930
931 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
932 {
933 zlog_warn ("lan hello on non broadcast circuit");
934 return ISIS_WARNING;
935 }
936
hassof390d2c2004-09-10 20:48:21 +0000937 if ((stream_get_endp (circuit->rcv_stream) -
938 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
939 {
940 zlog_warn ("Packet too short");
941 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000942 }
hassof390d2c2004-09-10 20:48:21 +0000943
944 if (circuit->ext_domain)
945 {
hasso529d65b2004-12-24 00:14:50 +0000946 zlog_debug ("level %d LAN Hello received over circuit with "
947 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000948 return ISIS_WARNING;
949 }
950
Josh Bailey3f045a02012-03-24 08:35:20 -0700951 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000952 {
953 if (isis->debugs & DEBUG_ADJ_PACKETS)
954 {
hasso529d65b2004-12-24 00:14:50 +0000955 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
956 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000957 }
958 return ISIS_WARNING;
959 }
jardineb5d44e2003-12-23 08:09:43 +0000960
961#if 0
962 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000963 if (!accept_level (level, circuit->area->is_type))
964 {
965 if (isis->debugs & DEBUG_ADJ_PACKETS)
966 {
hasso529d65b2004-12-24 00:14:50 +0000967 zlog_debug ("ISIS-Adj (%s): is type mismatch",
968 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000969 }
970 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000971 }
jardineb5d44e2003-12-23 08:09:43 +0000972#endif
973 /*
974 * Fill the header
975 */
976 hdr.circuit_t = stream_getc (circuit->rcv_stream);
977 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
978 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000979 hdr.pdu_len = stream_getw (circuit->rcv_stream);
980 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000981 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
982
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700983 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
984 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700985 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000986 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700987 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
988 "invalid pdu length %d",
989 circuit->area->area_tag, circuit->interface->name,
990 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700991 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700992 }
993
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700994 /*
995 * Set the stream endp to PDU length, ignoring additional padding
996 * introduced by transport chips.
997 */
998 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
999 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
1000
Josh Bailey3f045a02012-03-24 08:35:20 -07001001 if (hdr.circuit_t != IS_LEVEL_1 &&
1002 hdr.circuit_t != IS_LEVEL_2 &&
1003 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
1004 (level & hdr.circuit_t) == 0)
1005 {
1006 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
1007 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +00001008 return ISIS_ERROR;
1009 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001010
jardineb5d44e2003-12-23 08:09:43 +00001011 /*
1012 * Then get the tlvs
1013 */
1014 expected |= TLVFLAG_AUTH_INFO;
1015 expected |= TLVFLAG_AREA_ADDRS;
1016 expected |= TLVFLAG_LAN_NEIGHS;
1017 expected |= TLVFLAG_NLPID;
1018 expected |= TLVFLAG_IPV4_ADDR;
1019 expected |= TLVFLAG_IPV6_ADDR;
1020
Josh Bailey3f045a02012-03-24 08:35:20 -07001021 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001022 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -07001023 STREAM_PNT (circuit->rcv_stream),
1024 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
1025 &expected, &found, &tlvs,
1026 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001027
hassof390d2c2004-09-10 20:48:21 +00001028 if (retval > ISIS_WARNING)
1029 {
1030 zlog_warn ("parse_tlvs() failed");
1031 goto out;
1032 }
jardineb5d44e2003-12-23 08:09:43 +00001033
hassof390d2c2004-09-10 20:48:21 +00001034 if (!(found & TLVFLAG_AREA_ADDRS))
1035 {
1036 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
1037 level);
jardineb5d44e2003-12-23 08:09:43 +00001038 retval = ISIS_WARNING;
1039 goto out;
1040 }
hassof390d2c2004-09-10 20:48:21 +00001041
David Lamparterb72f3452012-11-27 01:10:26 +00001042 if (!(found & TLVFLAG_NLPID))
1043 {
1044 zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
1045 level);
1046 retval = ISIS_WARNING;
1047 goto out;
1048 }
1049
Josh Bailey3f045a02012-03-24 08:35:20 -07001050 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +00001051 if (circuit->passwd.type)
1052 {
1053 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001054 authentication_check (&tlvs.auth_info, &circuit->passwd,
1055 circuit->rcv_stream, auth_tlv_offset))
1056 {
1057 isis_event_auth_failure (circuit->area->area_tag,
1058 "LAN hello authentication failure",
1059 hdr.source_id);
1060 retval = ISIS_WARNING;
1061 goto out;
1062 }
hassof390d2c2004-09-10 20:48:21 +00001063 }
jardineb5d44e2003-12-23 08:09:43 +00001064
David Lamparter19f78ce2012-11-27 01:10:25 +00001065 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
1066 {
1067 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
1068 circuit->area->area_tag, circuit->interface->name);
1069 return ISIS_WARNING;
1070 }
1071
jardineb5d44e2003-12-23 08:09:43 +00001072 /*
1073 * Accept the level 1 adjacency only if a match between local and
1074 * remote area addresses is found
1075 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001076 if (listcount (circuit->area->area_addrs) == 0 ||
1077 (level == IS_LEVEL_1 &&
1078 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +00001079 {
1080 if (isis->debugs & DEBUG_ADJ_PACKETS)
1081 {
hasso529d65b2004-12-24 00:14:50 +00001082 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1083 circuit->area->area_tag, level,
1084 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001085 }
1086 retval = ISIS_OK;
1087 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001088 }
jardineb5d44e2003-12-23 08:09:43 +00001089
1090 /*
1091 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001092 */
1093 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1094 {
hasso529d65b2004-12-24 00:14:50 +00001095 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1096 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001097
hassof390d2c2004-09-10 20:48:21 +00001098 retval = ISIS_OK;
1099 goto out;
1100 }
jardineb5d44e2003-12-23 08:09:43 +00001101
1102 /*
1103 * check if it's own interface ip match iih ip addrs
1104 */
David Lamparter28a8cfc2014-06-29 13:48:18 +02001105 if (found & TLVFLAG_IPV4_ADDR)
hassof390d2c2004-09-10 20:48:21 +00001106 {
David Lamparter28a8cfc2014-06-29 13:48:18 +02001107 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
1108 v4_usable = 1;
1109 else
1110 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
1111 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001112 }
David Lamparter28a8cfc2014-06-29 13:48:18 +02001113#ifndef HAVE_IPV6
1114 else /* !(found & TLVFLAG_IPV4_ADDR) */
1115 zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s "
1116 "(this isisd has no IPv6)\n", circuit->interface->name);
1117
1118#else
1119 if (found & TLVFLAG_IPV6_ADDR)
1120 {
1121 /* TBA: check that we have a linklocal ourselves? */
1122 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +02001123 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +02001124 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
1125 if (IN6_IS_ADDR_LINKLOCAL (ip))
1126 {
1127 v6_usable = 1;
1128 break;
1129 }
1130
1131 if (!v6_usable)
1132 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
1133 "in LAN IIH from %s\n", circuit->interface->name);
1134 }
1135
1136 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
1137 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
1138 circuit->interface->name);
1139#endif
1140
1141 if (!v6_usable && !v4_usable)
1142 {
1143 free_tlvs (&tlvs);
1144 return ISIS_WARNING;
1145 }
1146
jardineb5d44e2003-12-23 08:09:43 +00001147
1148 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001149 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1150 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001151 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001152 if (!adj)
1153 {
1154 /*
1155 * Do as in 8.4.2.5
1156 */
1157 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1158 if (adj == NULL)
1159 {
1160 retval = ISIS_ERROR;
1161 goto out;
1162 }
1163 }
1164 else
1165 {
1166 if (ssnpa) {
1167 memcpy (adj->snpa, ssnpa, 6);
1168 } else {
1169 memset (adj->snpa, ' ', 6);
1170 }
1171 adj->level = level;
1172 }
hassof390d2c2004-09-10 20:48:21 +00001173 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001174
Josh Bailey3f045a02012-03-24 08:35:20 -07001175 if (level == IS_LEVEL_1)
1176 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001177 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001178 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001179 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1180 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001181 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001182 }
jardineb5d44e2003-12-23 08:09:43 +00001183
hassoa211d652004-09-20 14:55:29 +00001184 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1185 switch (level)
1186 {
1187 case 1:
1188 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1189 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001190 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001191 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1192 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001193 }
1194 break;
1195 case 2:
1196 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1197 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001198 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001199 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1200 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001201 }
1202 break;
1203 }
jardineb5d44e2003-12-23 08:09:43 +00001204
1205 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001206 adj->last_upd = time (NULL);
1207 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001208
1209 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1210
Josh Bailey3f045a02012-03-24 08:35:20 -07001211 tlvs_to_adj_area_addrs (&tlvs, adj);
1212
jardineb5d44e2003-12-23 08:09:43 +00001213 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +00001214 if (tlvs_to_adj_nlpids (&tlvs, adj))
1215 {
1216 retval = ISIS_WARNING;
1217 goto out;
1218 }
jardineb5d44e2003-12-23 08:09:43 +00001219
1220 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001221 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001222 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1223
1224#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001225 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001226 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1227#endif /* HAVE_IPV6 */
1228
1229 adj->circuit_t = hdr.circuit_t;
1230
1231 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001232 THREAD_TIMER_OFF (adj->t_expire);
1233 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001234 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001235
1236 /*
1237 * If the snpa for this circuit is found from LAN Neighbours TLV
1238 * we have two-way communication -> adjacency can be put to state "up"
1239 */
1240
hassof390d2c2004-09-10 20:48:21 +00001241 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001242 {
1243 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001244 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001245 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1246 {
1247 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1248 {
1249 isis_adj_state_change (adj, ISIS_ADJ_UP,
1250 "own SNPA found in LAN Neighbours TLV");
1251 }
1252 }
jardineb5d44e2003-12-23 08:09:43 +00001253 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001254 else
1255 {
1256 int found = 0;
1257 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1258 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1259 {
1260 found = 1;
1261 break;
1262 }
1263 if (found == 0)
1264 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1265 "own SNPA not found in LAN Neighbours TLV");
1266 }
1267 }
1268 else if (adj->adj_state == ISIS_ADJ_UP)
1269 {
1270 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1271 "no LAN Neighbours TLV found");
1272 }
jardineb5d44e2003-12-23 08:09:43 +00001273
hassof390d2c2004-09-10 20:48:21 +00001274out:
hassof390d2c2004-09-10 20:48:21 +00001275 if (isis->debugs & DEBUG_ADJ_PACKETS)
1276 {
hasso529d65b2004-12-24 00:14:50 +00001277 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
David Lamparter01da6172015-04-10 09:10:11 +02001278 "cirID %u, length %zd",
hasso529d65b2004-12-24 00:14:50 +00001279 circuit->area->area_tag,
1280 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001281 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001282 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001283 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001284 }
jardineb5d44e2003-12-23 08:09:43 +00001285
1286 free_tlvs (&tlvs);
1287
1288 return retval;
1289}
1290
1291/*
1292 * Process Level 1/2 Link State
1293 * ISO - 10589
1294 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001295 */
1296static int
1297process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001298{
1299 struct isis_link_state_hdr *hdr;
1300 struct isis_adjacency *adj = NULL;
1301 struct isis_lsp *lsp, *lsp0 = NULL;
1302 int retval = ISIS_OK, comp = 0;
1303 u_char lspid[ISIS_SYS_ID_LEN + 2];
1304 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001305 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001306
Josh Bailey3f045a02012-03-24 08:35:20 -07001307 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1308 {
1309 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1310 circuit->area->area_tag, level, circuit->interface->name,
1311 circuit_t2string (circuit->is_type), circuit->circuit_id);
1312 if (isis->debugs & DEBUG_PACKET_DUMP)
1313 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1314 stream_get_endp (circuit->rcv_stream));
1315 }
1316
hassof390d2c2004-09-10 20:48:21 +00001317 if ((stream_get_endp (circuit->rcv_stream) -
1318 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1319 {
1320 zlog_warn ("Packet too short");
1321 return ISIS_WARNING;
1322 }
jardineb5d44e2003-12-23 08:09:43 +00001323
1324 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001325 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001326 pdu_len = ntohs (hdr->pdu_len);
1327
1328 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001329 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001330 pdu_len > ISO_MTU(circuit) ||
1331 pdu_len > stream_get_endp (circuit->rcv_stream))
1332 {
1333 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1334 circuit->area->area_tag,
1335 rawlspid_print (hdr->lsp_id), pdu_len);
1336
1337 return ISIS_WARNING;
1338 }
1339
1340 /*
1341 * Set the stream endp to PDU length, ignoring additional padding
1342 * introduced by transport chips.
1343 */
1344 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1345 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001346
hassof390d2c2004-09-10 20:48:21 +00001347 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1348 {
hasso529d65b2004-12-24 00:14:50 +00001349 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001350 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001351 circuit->area->area_tag,
1352 level,
1353 rawlspid_print (hdr->lsp_id),
1354 ntohl (hdr->seq_num),
1355 ntohs (hdr->checksum),
1356 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001357 pdu_len,
paul15935e92005-05-03 09:27:23 +00001358 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001359 }
jardineb5d44e2003-12-23 08:09:43 +00001360
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001361 /* lsp is_type check */
1362 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1363 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001364 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001365 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001366 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001367 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1368 /* continue as per RFC1122 Be liberal in what you accept, and
1369 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001370 }
jardineb5d44e2003-12-23 08:09:43 +00001371
1372 /* Checksum sanity check - FIXME: move to correct place */
1373 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001374 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001375 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001376 {
hasso529d65b2004-12-24 00:14:50 +00001377 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1378 circuit->area->area_tag,
1379 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
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) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001385 if (circuit->ext_domain)
1386 {
hasso529d65b2004-12-24 00:14:50 +00001387 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001388 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1389 "externalDomain = true", circuit->area->area_tag,
1390 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001391
hassof390d2c2004-09-10 20:48:21 +00001392 return ISIS_WARNING;
1393 }
jardineb5d44e2003-12-23 08:09:43 +00001394
1395 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001396 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001397 {
hasso529d65b2004-12-24 00:14:50 +00001398 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1399 " type %s",
1400 circuit->area->area_tag,
1401 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001402 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001403
hassof390d2c2004-09-10 20:48:21 +00001404 return ISIS_WARNING;
1405 }
jardineb5d44e2003-12-23 08:09:43 +00001406
1407 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1408
1409 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1410
1411 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001412 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1413 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001414 if (passwd->type)
1415 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001416 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1417 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001418 {
1419 isis_event_auth_failure (circuit->area->area_tag,
1420 "LSP authentication failure", hdr->lsp_id);
1421 return ISIS_WARNING;
1422 }
jardineb5d44e2003-12-23 08:09:43 +00001423 }
jardineb5d44e2003-12-23 08:09:43 +00001424 /* Find the LSP in our database and compare it to this Link State header */
1425 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1426 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001427 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1428 hdr->checksum, hdr->rem_lifetime);
1429 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001430#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001431 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001432#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001433 ))
jardineb5d44e2003-12-23 08:09:43 +00001434 goto dontcheckadj;
1435
1436 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1437 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001438
hassof390d2c2004-09-10 20:48:21 +00001439 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1440 {
1441 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1442 if (!adj)
1443 {
hasso529d65b2004-12-24 00:14:50 +00001444 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1445 "lifetime %us on %s",
1446 circuit->area->area_tag,
1447 rawlspid_print (hdr->lsp_id),
1448 ntohl (hdr->seq_num),
1449 ntohs (hdr->checksum),
1450 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001451 return ISIS_WARNING; /* Silently discard */
1452 }
jardineb5d44e2003-12-23 08:09:43 +00001453 }
jardineb5d44e2003-12-23 08:09:43 +00001454 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001455 else
1456 {
1457 /* If no adj, or no sharing of level */
1458 if (!circuit->u.p2p.neighbor)
1459 {
1460 return ISIS_OK; /* Silently discard */
1461 }
1462 else
1463 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001464 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001465 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001466 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001467 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1468 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001469 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001470 }
jardineb5d44e2003-12-23 08:09:43 +00001471 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001472
hassof390d2c2004-09-10 20:48:21 +00001473dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001474 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1475
1476 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1477
hassof390d2c2004-09-10 20:48:21 +00001478 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001479
hassof390d2c2004-09-10 20:48:21 +00001480 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1481 if (hdr->rem_lifetime == 0)
1482 {
1483 if (!lsp)
1484 {
1485 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1486 /* only needed on explicit update, eg - p2p */
1487 if (circuit->circ_type == CIRCUIT_T_P2P)
1488 ack_lsp (hdr, circuit, level);
1489 return retval; /* FIXME: do we need a purge? */
1490 }
1491 else
1492 {
1493 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1494 {
1495 /* LSP by some other system -> do 7.3.16.4 b) */
1496 /* 7.3.16.4 b) 1) */
1497 if (comp == LSP_NEWER)
1498 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001499 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001500 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001501 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001502 /* iii */
1503 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1504 /* v */
1505 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1506 /* iv */
1507 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1508 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001509
hassof390d2c2004-09-10 20:48:21 +00001510 } /* 7.3.16.4 b) 2) */
1511 else if (comp == LSP_EQUAL)
1512 {
1513 /* i */
1514 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1515 /* ii */
1516 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1517 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1518 } /* 7.3.16.4 b) 3) */
1519 else
1520 {
1521 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1522 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1523 }
1524 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001525 else if (lsp->lsp_header->rem_lifetime != 0)
1526 {
1527 /* our own LSP -> 7.3.16.4 c) */
1528 if (comp == LSP_NEWER)
1529 {
1530 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1531 lsp_set_all_srmflags (lsp);
1532 }
1533 else
1534 {
1535 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1536 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1537 }
1538 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1539 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1540 "seq 0x%08x", circuit->area->area_tag,
1541 rawlspid_print (hdr->lsp_id),
1542 ntohl (lsp->lsp_header->seq_num));
1543 }
hassof390d2c2004-09-10 20:48:21 +00001544 }
1545 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001546 }
jardineb5d44e2003-12-23 08:09:43 +00001547 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1548 * purge */
hassof390d2c2004-09-10 20:48:21 +00001549 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1550 {
1551 if (!lsp)
1552 {
1553 /* 7.3.16.4: initiate a purge */
1554 lsp_purge_non_exist (hdr, circuit->area);
1555 return ISIS_OK;
1556 }
1557 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1558
1559 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1560 * has information that the current sequence number for source S is
1561 * "greater" than that held by S, ... */
1562
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001563 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001564 {
1565 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001566 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001567 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1568 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1569 "0x%08x", circuit->area->area_tag,
1570 rawlspid_print (hdr->lsp_id),
1571 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001572 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001573 /* If the received LSP is older or equal,
1574 * resend the LSP which will act as ACK */
1575 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001576 }
hassof390d2c2004-09-10 20:48:21 +00001577 else
1578 {
1579 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001580
hassof390d2c2004-09-10 20:48:21 +00001581 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1582 if ((!lsp || comp == LSP_NEWER))
1583 {
hassof390d2c2004-09-10 20:48:21 +00001584 /*
1585 * If this lsp is a frag, need to see if we have zero lsp present
1586 */
1587 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1588 {
1589 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1590 LSP_FRAGMENT (lspid) = 0;
1591 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1592 if (!lsp0)
1593 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001594 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001595 return ISIS_OK;
1596 }
1597 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001598 /* i */
1599 if (!lsp)
1600 {
1601 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001602 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001603 circuit->area, level);
1604 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1605 }
1606 else /* exists, so we overwrite */
1607 {
1608 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1609 }
hassof390d2c2004-09-10 20:48:21 +00001610 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001611 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001612 /* iii */
1613 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001614
hassof390d2c2004-09-10 20:48:21 +00001615 /* iv */
1616 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1617 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1618 /* FIXME: v) */
1619 }
1620 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1621 else if (comp == LSP_EQUAL)
1622 {
1623 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001624 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001625 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001626 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001627 }
1628 /* 7.3.15.1 e) 3) LSP older than the one in db */
1629 else
1630 {
1631 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1632 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1633 }
jardineb5d44e2003-12-23 08:09:43 +00001634 }
jardineb5d44e2003-12-23 08:09:43 +00001635 return retval;
1636}
1637
1638/*
1639 * Process Sequence Numbers
1640 * ISO - 10589
1641 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1642 */
1643
hasso92365882005-01-18 13:53:33 +00001644static int
hassof390d2c2004-09-10 20:48:21 +00001645process_snp (int snp_type, int level, struct isis_circuit *circuit,
1646 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001647{
1648 int retval = ISIS_OK;
1649 int cmp, own_lsp;
1650 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001651 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001652 struct isis_adjacency *adj;
1653 struct isis_complete_seqnum_hdr *chdr = NULL;
1654 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001655 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001656 struct isis_lsp *lsp;
1657 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001658 struct listnode *node, *nnode;
1659 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001660 struct tlvs tlvs;
1661 struct list *lsp_list = NULL;
1662 struct isis_passwd *passwd;
1663
hassof390d2c2004-09-10 20:48:21 +00001664 if (snp_type == ISIS_SNP_CSNP_FLAG)
1665 {
1666 /* getting the header info */
1667 typechar = 'C';
1668 chdr =
1669 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001670 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1671 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001672 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001673 pdu_len > ISO_MTU(circuit) ||
1674 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001675 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001676 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1677 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001678 }
jardineb5d44e2003-12-23 08:09:43 +00001679 }
hassof390d2c2004-09-10 20:48:21 +00001680 else
1681 {
1682 typechar = 'P';
1683 phdr =
1684 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001685 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1686 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001687 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001688 pdu_len > ISO_MTU(circuit) ||
1689 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001690 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001691 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1692 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001693 }
jardineb5d44e2003-12-23 08:09:43 +00001694 }
jardineb5d44e2003-12-23 08:09:43 +00001695
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001696 /*
1697 * Set the stream endp to PDU length, ignoring additional padding
1698 * introduced by transport chips.
1699 */
1700 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1701 stream_set_endp (circuit->rcv_stream, pdu_len);
1702
jardineb5d44e2003-12-23 08:09:43 +00001703 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001704 if (circuit->ext_domain)
1705 {
jardineb5d44e2003-12-23 08:09:43 +00001706
hasso529d65b2004-12-24 00:14:50 +00001707 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1708 "skipping: circuit externalDomain = true",
1709 circuit->area->area_tag,
1710 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001711
1712 return ISIS_OK;
1713 }
hassof390d2c2004-09-10 20:48:21 +00001714
1715 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001716 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001717 {
1718
hasso529d65b2004-12-24 00:14:50 +00001719 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1720 "skipping: circuit type %s does not match level %d",
1721 circuit->area->area_tag,
1722 level,
1723 typechar,
1724 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001725 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001726
1727 return ISIS_OK;
1728 }
1729
1730 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1731 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001732 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1733 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001734 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001735 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1736 "skipping: we are not the DIS",
1737 circuit->area->area_tag,
1738 level,
1739 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001740
Josh Bailey3f045a02012-03-24 08:35:20 -07001741 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001742 }
jardineb5d44e2003-12-23 08:09:43 +00001743
1744 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1745
1746 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1747 * - already checked */
1748
1749 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1750 /* for broadcast circuits, snpa should be compared */
1751 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001752 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1753 {
1754 if (snp_type == ISIS_SNP_CSNP_FLAG)
1755 {
1756 adj =
1757 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1758 }
1759 else
1760 {
1761 /* a psnp on a broadcast, how lovely of Juniper :) */
1762 adj =
1763 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1764 }
1765 if (!adj)
1766 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001767 }
hassof390d2c2004-09-10 20:48:21 +00001768 else
1769 {
1770 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001771 {
1772 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1773 return ISIS_OK; /* Silently discard */
1774 }
hassof390d2c2004-09-10 20:48:21 +00001775 }
jardineb5d44e2003-12-23 08:09:43 +00001776
1777 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1778
1779 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1780
1781 memset (&tlvs, 0, sizeof (struct tlvs));
1782
1783 /* parse the SNP */
1784 expected |= TLVFLAG_LSP_ENTRIES;
1785 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001786
1787 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001788 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001789 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001790 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001791 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001792
hassof390d2c2004-09-10 20:48:21 +00001793 if (retval > ISIS_WARNING)
1794 {
1795 zlog_warn ("something went very wrong processing SNP");
1796 free_tlvs (&tlvs);
1797 return retval;
1798 }
jardineb5d44e2003-12-23 08:09:43 +00001799
Josh Bailey3f045a02012-03-24 08:35:20 -07001800 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001801 passwd = &circuit->area->area_passwd;
1802 else
1803 passwd = &circuit->area->domain_passwd;
1804
1805 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001806 {
hasso1cbc5622005-01-01 10:29:51 +00001807 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001808 {
1809 if (!(found & TLVFLAG_AUTH_INFO) ||
1810 authentication_check (&tlvs.auth_info, passwd,
1811 circuit->rcv_stream, auth_tlv_offset))
1812 {
1813 isis_event_auth_failure (circuit->area->area_tag,
1814 "SNP authentication" " failure",
1815 phdr ? phdr->source_id :
1816 chdr->source_id);
1817 free_tlvs (&tlvs);
1818 return ISIS_OK;
1819 }
1820 }
hassof390d2c2004-09-10 20:48:21 +00001821 }
jardineb5d44e2003-12-23 08:09:43 +00001822
1823 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001824 if (isis->debugs & DEBUG_SNP_PACKETS)
1825 {
hasso529d65b2004-12-24 00:14:50 +00001826 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1827 circuit->area->area_tag,
1828 level,
1829 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001830 if (tlvs.lsp_entries)
1831 {
hasso3fdb2dd2005-09-28 18:45:54 +00001832 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001833 {
hasso529d65b2004-12-24 00:14:50 +00001834 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1835 " cksum 0x%04x, lifetime %us",
1836 circuit->area->area_tag,
1837 typechar,
1838 rawlspid_print (entry->lsp_id),
1839 ntohl (entry->seq_num),
1840 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001841 }
1842 }
jardineb5d44e2003-12-23 08:09:43 +00001843 }
jardineb5d44e2003-12-23 08:09:43 +00001844
1845 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001846 if (tlvs.lsp_entries)
1847 {
hasso3fdb2dd2005-09-28 18:45:54 +00001848 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001849 {
1850 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1851 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1852 if (lsp)
1853 {
1854 /* 7.3.15.2 b) 1) is this LSP newer */
1855 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1856 entry->checksum, entry->rem_lifetime);
1857 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1858 if (cmp == LSP_EQUAL)
1859 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001860 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1861 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001862 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001863 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001864 else if (cmp == LSP_OLDER)
1865 {
1866 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1867 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1868 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001869 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001870 else
1871 {
hassof390d2c2004-09-10 20:48:21 +00001872 if (own_lsp)
1873 {
1874 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1875 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1876 }
1877 else
1878 {
1879 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001880 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1881 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001882 }
1883 }
1884 }
1885 else
1886 {
1887 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1888 * insert it and set SSN on it */
1889 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1890 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1891 {
1892 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1893 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001894 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001895 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001896 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001897 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1898 }
1899 }
jardineb5d44e2003-12-23 08:09:43 +00001900 }
1901 }
jardineb5d44e2003-12-23 08:09:43 +00001902
1903 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001904 if (snp_type == ISIS_SNP_CSNP_FLAG)
1905 {
1906 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001907 * Build a list from our own LSP db bounded with
1908 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001909 */
1910 lsp_list = list_new ();
1911 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1912 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001913
hassof390d2c2004-09-10 20:48:21 +00001914 /* Fixme: Find a better solution */
1915 if (tlvs.lsp_entries)
1916 {
paul1eb8ef22005-04-07 07:30:20 +00001917 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001918 {
paul1eb8ef22005-04-07 07:30:20 +00001919 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001920 {
1921 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1922 {
1923 list_delete_node (lsp_list, node2);
1924 break;
1925 }
1926 }
1927 }
1928 }
1929 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001930 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001931 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001932 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001933 list_delete (lsp_list);
1934
jardineb5d44e2003-12-23 08:09:43 +00001935 }
jardineb5d44e2003-12-23 08:09:43 +00001936
1937 free_tlvs (&tlvs);
1938 return retval;
1939}
1940
hasso92365882005-01-18 13:53:33 +00001941static int
hassof390d2c2004-09-10 20:48:21 +00001942process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001943{
Josh Bailey3f045a02012-03-24 08:35:20 -07001944 if (isis->debugs & DEBUG_SNP_PACKETS)
1945 {
1946 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1947 circuit->area->area_tag, level, circuit->interface->name,
1948 circuit_t2string (circuit->is_type), circuit->circuit_id);
1949 if (isis->debugs & DEBUG_PACKET_DUMP)
1950 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1951 stream_get_endp (circuit->rcv_stream));
1952 }
1953
jardineb5d44e2003-12-23 08:09:43 +00001954 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001955 if ((stream_get_endp (circuit->rcv_stream) -
1956 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1957 {
1958 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1959 return ISIS_WARNING;
1960 }
jardineb5d44e2003-12-23 08:09:43 +00001961
1962 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1963}
1964
hasso92365882005-01-18 13:53:33 +00001965static int
hassof390d2c2004-09-10 20:48:21 +00001966process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001967{
Josh Bailey3f045a02012-03-24 08:35:20 -07001968 if (isis->debugs & DEBUG_SNP_PACKETS)
1969 {
1970 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1971 circuit->area->area_tag, level, circuit->interface->name,
1972 circuit_t2string (circuit->is_type), circuit->circuit_id);
1973 if (isis->debugs & DEBUG_PACKET_DUMP)
1974 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1975 stream_get_endp (circuit->rcv_stream));
1976 }
1977
hassof390d2c2004-09-10 20:48:21 +00001978 if ((stream_get_endp (circuit->rcv_stream) -
1979 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1980 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001981 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001982 return ISIS_WARNING;
1983 }
jardineb5d44e2003-12-23 08:09:43 +00001984
1985 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1986}
1987
jardineb5d44e2003-12-23 08:09:43 +00001988/*
jardineb5d44e2003-12-23 08:09:43 +00001989 * PDU Dispatcher
1990 */
1991
hasso92365882005-01-18 13:53:33 +00001992static int
hassof390d2c2004-09-10 20:48:21 +00001993isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001994{
jardineb5d44e2003-12-23 08:09:43 +00001995 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00001996
hassof390d2c2004-09-10 20:48:21 +00001997 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001998
1999 /*
2000 * Let's first read data from stream to the header
2001 */
hassof390d2c2004-09-10 20:48:21 +00002002 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00002003
hassof390d2c2004-09-10 20:48:21 +00002004 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
2005 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002006 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00002007 return ISIS_ERROR;
2008 }
jardineb5d44e2003-12-23 08:09:43 +00002009
2010 /* now we need to know if this is an ISO 9542 packet and
2011 * take real good care of it, waaa!
2012 */
hassof390d2c2004-09-10 20:48:21 +00002013 if (hdr->idrp == ISO9542_ESIS)
2014 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002015 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
2016 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002017 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002018 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
2019
jardineb5d44e2003-12-23 08:09:43 +00002020 /*
2021 * and then process it
2022 */
2023
hassof390d2c2004-09-10 20:48:21 +00002024 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
2025 {
2026 zlog_err ("Fixed header length = %d", hdr->length);
2027 return ISIS_ERROR;
2028 }
jardineb5d44e2003-12-23 08:09:43 +00002029
hassof390d2c2004-09-10 20:48:21 +00002030 if (hdr->version1 != 1)
2031 {
2032 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
2033 return ISIS_WARNING;
2034 }
jardineb5d44e2003-12-23 08:09:43 +00002035 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002036 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2037 {
2038 zlog_err
2039 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2040 "while the parameter for this IS is %u", hdr->id_len,
2041 ISIS_SYS_ID_LEN);
2042 return ISIS_ERROR;
2043 }
jardineb5d44e2003-12-23 08:09:43 +00002044
hassof390d2c2004-09-10 20:48:21 +00002045 if (hdr->version2 != 1)
2046 {
2047 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2048 return ISIS_WARNING;
2049 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002050
2051 if (circuit->is_passive)
2052 {
2053 zlog_warn ("Received ISIS PDU on passive circuit %s",
2054 circuit->interface->name);
2055 return ISIS_WARNING;
2056 }
2057
jardineb5d44e2003-12-23 08:09:43 +00002058 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002059 if ((hdr->max_area_addrs != 0)
2060 && (hdr->max_area_addrs != isis->max_area_addrs))
2061 {
2062 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2063 "received PDU %u while the parameter for this IS is %u",
2064 hdr->max_area_addrs, isis->max_area_addrs);
2065 return ISIS_ERROR;
2066 }
jardineb5d44e2003-12-23 08:09:43 +00002067
hassof390d2c2004-09-10 20:48:21 +00002068 switch (hdr->pdu_type)
2069 {
2070 case L1_LAN_HELLO:
2071 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2072 break;
2073 case L2_LAN_HELLO:
2074 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2075 break;
2076 case P2P_HELLO:
2077 retval = process_p2p_hello (circuit);
2078 break;
2079 case L1_LINK_STATE:
2080 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2081 break;
2082 case L2_LINK_STATE:
2083 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2084 break;
2085 case L1_COMPLETE_SEQ_NUM:
2086 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2087 break;
2088 case L2_COMPLETE_SEQ_NUM:
2089 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2090 break;
2091 case L1_PARTIAL_SEQ_NUM:
2092 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2093 break;
2094 case L2_PARTIAL_SEQ_NUM:
2095 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2096 break;
2097 default:
2098 return ISIS_ERROR;
2099 }
jardineb5d44e2003-12-23 08:09:43 +00002100
2101 return retval;
2102}
2103
jardineb5d44e2003-12-23 08:09:43 +00002104#ifdef GNU_LINUX
2105int
2106isis_receive (struct thread *thread)
2107{
jardineb5d44e2003-12-23 08:09:43 +00002108 struct isis_circuit *circuit;
2109 u_char ssnpa[ETH_ALEN];
2110 int retval;
2111
2112 /*
2113 * Get the circuit
2114 */
2115 circuit = THREAD_ARG (thread);
2116 assert (circuit);
2117
2118 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002119 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002120 else
2121 stream_reset (circuit->rcv_stream);
2122
2123 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002124 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002125
2126 if (retval == ISIS_OK)
2127 retval = isis_handle_pdu (circuit, ssnpa);
2128
2129 /*
2130 * prepare for next packet.
2131 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002132 if (!circuit->is_passive)
2133 {
2134 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2135 circuit->fd);
2136 }
jardineb5d44e2003-12-23 08:09:43 +00002137
2138 return retval;
2139}
2140
2141#else
2142int
2143isis_receive (struct thread *thread)
2144{
jardineb5d44e2003-12-23 08:09:43 +00002145 struct isis_circuit *circuit;
2146 u_char ssnpa[ETH_ALEN];
2147 int retval;
2148
2149 /*
2150 * Get the circuit
2151 */
2152 circuit = THREAD_ARG (thread);
2153 assert (circuit);
2154
hassof390d2c2004-09-10 20:48:21 +00002155 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002156
2157 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002158 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002159 else
2160 stream_reset (circuit->rcv_stream);
2161
2162 retval = circuit->rx (circuit, ssnpa);
2163
2164 if (retval == ISIS_OK)
2165 retval = isis_handle_pdu (circuit, ssnpa);
2166
2167 /*
2168 * prepare for next packet.
2169 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002170 if (!circuit->is_passive)
2171 {
2172 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2173 listcount
2174 (circuit->area->circuit_list) *
2175 100);
2176 }
jardineb5d44e2003-12-23 08:09:43 +00002177
2178 return retval;
2179}
2180
2181#endif
2182
2183 /* filling of the fixed isis header */
2184void
2185fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2186{
2187 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2188
2189 hdr->idrp = ISO10589_ISIS;
2190
hassof390d2c2004-09-10 20:48:21 +00002191 switch (pdu_type)
2192 {
2193 case L1_LAN_HELLO:
2194 case L2_LAN_HELLO:
2195 hdr->length = ISIS_LANHELLO_HDRLEN;
2196 break;
2197 case P2P_HELLO:
2198 hdr->length = ISIS_P2PHELLO_HDRLEN;
2199 break;
2200 case L1_LINK_STATE:
2201 case L2_LINK_STATE:
2202 hdr->length = ISIS_LSP_HDR_LEN;
2203 break;
2204 case L1_COMPLETE_SEQ_NUM:
2205 case L2_COMPLETE_SEQ_NUM:
2206 hdr->length = ISIS_CSNP_HDRLEN;
2207 break;
2208 case L1_PARTIAL_SEQ_NUM:
2209 case L2_PARTIAL_SEQ_NUM:
2210 hdr->length = ISIS_PSNP_HDRLEN;
2211 break;
2212 default:
2213 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2214 return;
2215 }
jardineb5d44e2003-12-23 08:09:43 +00002216 hdr->length += ISIS_FIXED_HDR_LEN;
2217 hdr->pdu_type = pdu_type;
2218 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002219 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002220 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002221 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002222}
2223
jardineb5d44e2003-12-23 08:09:43 +00002224/*
2225 * SEND SIDE
2226 */
hasso92365882005-01-18 13:53:33 +00002227static void
jardineb5d44e2003-12-23 08:09:43 +00002228fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002229 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002230{
hassof390d2c2004-09-10 20:48:21 +00002231 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002232
2233 stream_putc (stream, hdr->idrp);
2234 stream_putc (stream, hdr->length);
2235 stream_putc (stream, hdr->version1);
2236 stream_putc (stream, hdr->id_len);
2237 stream_putc (stream, hdr->pdu_type);
2238 stream_putc (stream, hdr->version2);
2239 stream_putc (stream, hdr->reserved);
2240 stream_putc (stream, hdr->max_area_addrs);
2241
2242 return;
2243}
2244
jardineb5d44e2003-12-23 08:09:43 +00002245int
2246send_hello (struct isis_circuit *circuit, int level)
2247{
2248 struct isis_fixed_hdr fixed_hdr;
2249 struct isis_lan_hello_hdr hello_hdr;
2250 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002251 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
David Lamparter01da6172015-04-10 09:10:11 +02002252 size_t len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002253 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002254 int retval;
2255
Josh Bailey3f045a02012-03-24 08:35:20 -07002256 if (circuit->is_passive)
2257 return ISIS_OK;
2258
hassof390d2c2004-09-10 20:48:21 +00002259 if (circuit->interface->mtu == 0)
2260 {
2261 zlog_warn ("circuit has zero MTU");
2262 return ISIS_WARNING;
2263 }
jardineb5d44e2003-12-23 08:09:43 +00002264
2265 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002266 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002267 else
2268 stream_reset (circuit->snd_stream);
2269
2270 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002271 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002272 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2273 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002274 else
hassof390d2c2004-09-10 20:48:21 +00002275 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2276 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002277 else
hassof390d2c2004-09-10 20:48:21 +00002278 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002279
2280 /*
2281 * Fill LAN Level 1 or 2 Hello PDU header
2282 */
2283 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002284 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002285 circuit->hello_interval[level - 1];
2286 if (interval > USHRT_MAX)
2287 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002288 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002289 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002290 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002291
hassof390d2c2004-09-10 20:48:21 +00002292 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002293 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002294
2295 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002296 if (circuit->circ_type == CIRCUIT_T_P2P)
2297 {
2298 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2299 p2p_hello_hdr.local_id = circuit->circuit_id;
2300 /* FIXME: need better understanding */
2301 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002302 }
hassof390d2c2004-09-10 20:48:21 +00002303 else
2304 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002305 hello_hdr.prio = circuit->priority[level - 1];
2306 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002307 {
2308 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2309 ISIS_SYS_ID_LEN + 1);
2310 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002311 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002312 {
2313 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2314 ISIS_SYS_ID_LEN + 1);
2315 }
2316 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2317 }
jardineb5d44e2003-12-23 08:09:43 +00002318
2319 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002320 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002321 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002322
jardineb5d44e2003-12-23 08:09:43 +00002323 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002324 switch (circuit->passwd.type)
2325 {
2326 /* Cleartext */
2327 case ISIS_PASSWD_TYPE_CLEARTXT:
2328 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2329 circuit->passwd.passwd, circuit->snd_stream))
2330 return ISIS_WARNING;
2331 break;
2332
2333 /* HMAC MD5 */
2334 case ISIS_PASSWD_TYPE_HMAC_MD5:
2335 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2336 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2337 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2338 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2339 hmac_md5_hash, circuit->snd_stream))
2340 return ISIS_WARNING;
2341 break;
2342
2343 default:
2344 break;
2345 }
2346
jardineb5d44e2003-12-23 08:09:43 +00002347 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002348 if (listcount (circuit->area->area_addrs) == 0)
2349 return ISIS_WARNING;
2350 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2351 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002352
2353 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002354 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2355 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002356 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2357 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002358 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2359 circuit->snd_stream))
2360 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002361 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2362 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002363 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2364 circuit->snd_stream))
2365 return ISIS_WARNING;
2366 }
jardineb5d44e2003-12-23 08:09:43 +00002367
2368 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002369 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002370 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2371 return ISIS_WARNING;
2372 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002373 if (circuit->ip_router && circuit->ip_addrs &&
2374 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002375 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2376 return ISIS_WARNING;
2377
hassof390d2c2004-09-10 20:48:21 +00002378#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002379 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002380 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002381 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002382 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2383 return ISIS_WARNING;
2384#endif /* HAVE_IPV6 */
2385
Josh Bailey3f045a02012-03-24 08:35:20 -07002386 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002387 if (tlv_add_padding (circuit->snd_stream))
2388 return ISIS_WARNING;
2389
paul9985f832005-02-09 15:51:56 +00002390 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002391 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002392 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002393
Josh Bailey3f045a02012-03-24 08:35:20 -07002394 /* For HMAC MD5 we need to compute the md5 hash and store it */
2395 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2396 {
2397 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2398 stream_get_endp (circuit->snd_stream),
2399 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
David Lamparter21401f32015-03-03 08:55:26 +01002400 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002401 /* Copy the hash into the stream */
2402 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2403 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2404 }
jardineb5d44e2003-12-23 08:09:43 +00002405
hassof390d2c2004-09-10 20:48:21 +00002406 if (isis->debugs & DEBUG_ADJ_PACKETS)
2407 {
2408 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2409 {
David Lamparter01da6172015-04-10 09:10:11 +02002410 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002411 circuit->area->area_tag, level, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002412 length);
hassof390d2c2004-09-10 20:48:21 +00002413 }
2414 else
2415 {
David Lamparter01da6172015-04-10 09:10:11 +02002416 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002417 circuit->area->area_tag, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002418 length);
hassof390d2c2004-09-10 20:48:21 +00002419 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002420 if (isis->debugs & DEBUG_PACKET_DUMP)
2421 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2422 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002423 }
jardineb5d44e2003-12-23 08:09:43 +00002424
Josh Bailey3f045a02012-03-24 08:35:20 -07002425 retval = circuit->tx (circuit, level);
2426 if (retval != ISIS_OK)
2427 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2428 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002429
Josh Bailey3f045a02012-03-24 08:35:20 -07002430 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002431}
2432
2433int
2434send_lan_l1_hello (struct thread *thread)
2435{
jardineb5d44e2003-12-23 08:09:43 +00002436 struct isis_circuit *circuit;
2437 int retval;
2438
2439 circuit = THREAD_ARG (thread);
2440 assert (circuit);
2441 circuit->u.bc.t_send_lan_hello[0] = NULL;
2442
2443 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002444 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002445
Josh Bailey3f045a02012-03-24 08:35:20 -07002446 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002447
2448 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002449 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2450 send_lan_l1_hello, circuit,
2451 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002452
2453 return retval;
2454}
2455
2456int
2457send_lan_l2_hello (struct thread *thread)
2458{
2459 struct isis_circuit *circuit;
2460 int retval;
2461
2462 circuit = THREAD_ARG (thread);
2463 assert (circuit);
2464 circuit->u.bc.t_send_lan_hello[1] = NULL;
2465
2466 if (circuit->u.bc.run_dr_elect[1])
2467 retval = isis_dr_elect (circuit, 2);
2468
Josh Bailey3f045a02012-03-24 08:35:20 -07002469 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002470
hassof390d2c2004-09-10 20:48:21 +00002471 /* set next timer thread */
2472 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2473 send_lan_l2_hello, circuit,
2474 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002475
2476 return retval;
2477}
2478
2479int
2480send_p2p_hello (struct thread *thread)
2481{
2482 struct isis_circuit *circuit;
2483
2484 circuit = THREAD_ARG (thread);
2485 assert (circuit);
2486 circuit->u.p2p.t_send_p2p_hello = NULL;
2487
hassof390d2c2004-09-10 20:48:21 +00002488 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002489
hassof390d2c2004-09-10 20:48:21 +00002490 /* set next timer thread */
2491 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2492 circuit, isis_jitter (circuit->hello_interval[1],
2493 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002494
2495 return ISIS_OK;
2496}
2497
hasso92365882005-01-18 13:53:33 +00002498static int
hassof390d2c2004-09-10 20:48:21 +00002499build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2500 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002501{
2502 struct isis_fixed_hdr fixed_hdr;
2503 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002504 unsigned long lenp;
2505 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002506 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2507 unsigned long auth_tlv_offset = 0;
2508 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002509
Josh Bailey3f045a02012-03-24 08:35:20 -07002510 if (circuit->snd_stream == NULL)
2511 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2512 else
2513 stream_reset (circuit->snd_stream);
2514
2515 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002516 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2517 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002518 else
hassof390d2c2004-09-10 20:48:21 +00002519 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2520 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002521
2522 /*
2523 * Fill Level 1 or 2 Complete Sequence Numbers header
2524 */
2525
paul9985f832005-02-09 15:51:56 +00002526 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002527 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002528 /* no need to send the source here, it is always us if we csnp */
2529 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2530 /* with zero circuit id - ref 9.10, 9.11 */
2531 stream_putc (circuit->snd_stream, 0x00);
2532
2533 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2534 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2535
2536 /*
2537 * And TLVs
2538 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002539 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002540 passwd = &circuit->area->area_passwd;
2541 else
2542 passwd = &circuit->area->domain_passwd;
2543
hasso1cbc5622005-01-01 10:29:51 +00002544 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002545 {
2546 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002547 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002548 /* Cleartext */
2549 case ISIS_PASSWD_TYPE_CLEARTXT:
2550 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2551 passwd->passwd, circuit->snd_stream))
2552 return ISIS_WARNING;
2553 break;
2554
2555 /* HMAC MD5 */
2556 case ISIS_PASSWD_TYPE_HMAC_MD5:
2557 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2558 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2559 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2560 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2561 hmac_md5_hash, circuit->snd_stream))
2562 return ISIS_WARNING;
2563 break;
2564
2565 default:
2566 break;
hassof390d2c2004-09-10 20:48:21 +00002567 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002568 }
2569
2570 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2571 if (retval != ISIS_OK)
2572 return retval;
2573
paul9985f832005-02-09 15:51:56 +00002574 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002575 /* Update PU length */
2576 stream_putw_at (circuit->snd_stream, lenp, length);
2577
Josh Bailey3f045a02012-03-24 08:35:20 -07002578 /* For HMAC MD5 we need to compute the md5 hash and store it */
2579 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2580 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2581 {
2582 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2583 stream_get_endp(circuit->snd_stream),
2584 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002585 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002586 /* Copy the hash into the stream */
2587 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2588 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2589 }
2590
jardineb5d44e2003-12-23 08:09:43 +00002591 return retval;
2592}
2593
2594/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002595 * Count the maximum number of lsps that can be accomodated by a given size.
2596 */
2597static uint16_t
2598get_max_lsp_count (uint16_t size)
2599{
2600 uint16_t tlv_count;
2601 uint16_t lsp_count;
2602 uint16_t remaining_size;
2603
2604 /* First count the full size TLVs */
2605 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2606 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2607
2608 /* The last TLV, if any */
2609 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2610 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2611 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2612
2613 return lsp_count;
2614}
2615
2616/*
2617 * Calculate the length of Authentication Info. TLV.
2618 */
2619static uint16_t
2620auth_tlv_length (int level, struct isis_circuit *circuit)
2621{
2622 struct isis_passwd *passwd;
2623 uint16_t length;
2624
2625 if (level == IS_LEVEL_1)
2626 passwd = &circuit->area->area_passwd;
2627 else
2628 passwd = &circuit->area->domain_passwd;
2629
2630 /* Also include the length of TLV header */
2631 length = AUTH_INFO_HDRLEN;
2632 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2633 {
2634 switch (passwd->type)
2635 {
2636 /* Cleartext */
2637 case ISIS_PASSWD_TYPE_CLEARTXT:
2638 length += passwd->len;
2639 break;
2640
2641 /* HMAC MD5 */
2642 case ISIS_PASSWD_TYPE_HMAC_MD5:
2643 length += ISIS_AUTH_MD5_SIZE;
2644 break;
2645
2646 default:
2647 break;
2648 }
2649 }
2650
2651 return length;
2652}
2653
2654/*
2655 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2656 */
2657static uint16_t
2658max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2659{
2660 int snp_hdr_len;
2661 int auth_tlv_len;
2662 uint16_t lsp_count;
2663
2664 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2665 if (snp_type == ISIS_SNP_CSNP_FLAG)
2666 snp_hdr_len += ISIS_CSNP_HDRLEN;
2667 else
2668 snp_hdr_len += ISIS_PSNP_HDRLEN;
2669
2670 auth_tlv_len = auth_tlv_length (level, circuit);
2671 lsp_count = get_max_lsp_count (
2672 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002673 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002674}
2675
2676/*
jardineb5d44e2003-12-23 08:09:43 +00002677 * FIXME: support multiple CSNPs
2678 */
2679
2680int
2681send_csnp (struct isis_circuit *circuit, int level)
2682{
jardineb5d44e2003-12-23 08:09:43 +00002683 u_char start[ISIS_SYS_ID_LEN + 2];
2684 u_char stop[ISIS_SYS_ID_LEN + 2];
2685 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002686 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002687 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002688 u_char num_lsps, loop = 1;
2689 int i, retval = ISIS_OK;
2690
2691 if (circuit->area->lspdb[level - 1] == NULL ||
2692 dict_count (circuit->area->lspdb[level - 1]) == 0)
2693 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002694
hassof390d2c2004-09-10 20:48:21 +00002695 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002696 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2697
Josh Bailey3f045a02012-03-24 08:35:20 -07002698 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2699
2700 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002701 {
2702 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002703 lsp_build_list (start, stop, num_lsps, list,
2704 circuit->area->lspdb[level - 1]);
2705 /*
2706 * Update the stop lsp_id before encoding this CSNP.
2707 */
2708 if (listcount (list) < num_lsps)
2709 {
2710 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2711 }
hassof390d2c2004-09-10 20:48:21 +00002712 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002713 {
2714 node = listtail (list);
2715 lsp = listgetdata (node);
2716 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2717 }
jardineb5d44e2003-12-23 08:09:43 +00002718
hassof390d2c2004-09-10 20:48:21 +00002719 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002720 if (retval != ISIS_OK)
2721 {
2722 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2723 circuit->area->area_tag, level, circuit->interface->name);
2724 list_delete (list);
2725 return retval;
2726 }
jardineb5d44e2003-12-23 08:09:43 +00002727
hassof390d2c2004-09-10 20:48:21 +00002728 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002729 {
David Lamparter01da6172015-04-10 09:10:11 +02002730 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07002731 circuit->area->area_tag, level, circuit->interface->name,
2732 stream_get_endp (circuit->snd_stream));
2733 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2734 {
2735 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2736 " cksum 0x%04x, lifetime %us",
2737 circuit->area->area_tag,
2738 rawlspid_print (lsp->lsp_header->lsp_id),
2739 ntohl (lsp->lsp_header->seq_num),
2740 ntohs (lsp->lsp_header->checksum),
2741 ntohs (lsp->lsp_header->rem_lifetime));
2742 }
2743 if (isis->debugs & DEBUG_PACKET_DUMP)
2744 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2745 stream_get_endp (circuit->snd_stream));
2746 }
hassof390d2c2004-09-10 20:48:21 +00002747
Josh Bailey3f045a02012-03-24 08:35:20 -07002748 retval = circuit->tx (circuit, level);
2749 if (retval != ISIS_OK)
2750 {
2751 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2752 circuit->area->area_tag, level,
2753 circuit->interface->name);
2754 list_delete (list);
2755 return retval;
2756 }
2757
2758 /*
2759 * Start lsp_id of the next CSNP should be one plus the
2760 * stop lsp_id in this current CSNP.
2761 */
2762 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2763 loop = 0;
2764 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2765 {
2766 if (start[i] < (u_char)0xff)
2767 {
2768 start[i] += 1;
2769 loop = 1;
2770 break;
2771 }
2772 }
2773 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002774 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002775 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002776
jardineb5d44e2003-12-23 08:09:43 +00002777 return retval;
2778}
2779
2780int
2781send_l1_csnp (struct thread *thread)
2782{
2783 struct isis_circuit *circuit;
2784 int retval = ISIS_OK;
2785
2786 circuit = THREAD_ARG (thread);
2787 assert (circuit);
2788
2789 circuit->t_send_csnp[0] = NULL;
2790
hassof390d2c2004-09-10 20:48:21 +00002791 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2792 {
2793 send_csnp (circuit, 1);
2794 }
jardineb5d44e2003-12-23 08:09:43 +00002795 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002796 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2797 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002798
2799 return retval;
2800}
2801
2802int
2803send_l2_csnp (struct thread *thread)
2804{
2805 struct isis_circuit *circuit;
2806 int retval = ISIS_OK;
2807
2808 circuit = THREAD_ARG (thread);
2809 assert (circuit);
2810
2811 circuit->t_send_csnp[1] = NULL;
2812
hassof390d2c2004-09-10 20:48:21 +00002813 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2814 {
2815 send_csnp (circuit, 2);
2816 }
jardineb5d44e2003-12-23 08:09:43 +00002817 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002818 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2819 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002820
jardineb5d44e2003-12-23 08:09:43 +00002821 return retval;
2822}
2823
hasso92365882005-01-18 13:53:33 +00002824static int
jardineb5d44e2003-12-23 08:09:43 +00002825build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2826{
2827 struct isis_fixed_hdr fixed_hdr;
2828 unsigned long lenp;
2829 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002830 struct isis_lsp *lsp;
2831 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002832 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002833 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2834 unsigned long auth_tlv_offset = 0;
2835 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002836
Josh Bailey3f045a02012-03-24 08:35:20 -07002837 if (circuit->snd_stream == NULL)
2838 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2839 else
2840 stream_reset (circuit->snd_stream);
2841
2842 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002843 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2844 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002845 else
2846 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002847 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002848
2849 /*
2850 * Fill Level 1 or 2 Partial Sequence Numbers header
2851 */
paul9985f832005-02-09 15:51:56 +00002852 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002853 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002854 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2855 stream_putc (circuit->snd_stream, circuit->idx);
2856
2857 /*
2858 * And TLVs
2859 */
2860
Josh Bailey3f045a02012-03-24 08:35:20 -07002861 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002862 passwd = &circuit->area->area_passwd;
2863 else
2864 passwd = &circuit->area->domain_passwd;
2865
hasso1cbc5622005-01-01 10:29:51 +00002866 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002867 {
2868 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002869 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002870 /* Cleartext */
2871 case ISIS_PASSWD_TYPE_CLEARTXT:
2872 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2873 passwd->passwd, circuit->snd_stream))
2874 return ISIS_WARNING;
2875 break;
2876
2877 /* HMAC MD5 */
2878 case ISIS_PASSWD_TYPE_HMAC_MD5:
2879 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2880 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2881 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2882 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2883 hmac_md5_hash, circuit->snd_stream))
2884 return ISIS_WARNING;
2885 break;
2886
2887 default:
2888 break;
jardineb5d44e2003-12-23 08:09:43 +00002889 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002890 }
2891
2892 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2893 if (retval != ISIS_OK)
2894 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002895
hassof390d2c2004-09-10 20:48:21 +00002896 if (isis->debugs & DEBUG_SNP_PACKETS)
2897 {
hasso3fdb2dd2005-09-28 18:45:54 +00002898 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002899 {
hasso529d65b2004-12-24 00:14:50 +00002900 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2901 " cksum 0x%04x, lifetime %us",
2902 circuit->area->area_tag,
2903 rawlspid_print (lsp->lsp_header->lsp_id),
2904 ntohl (lsp->lsp_header->seq_num),
2905 ntohs (lsp->lsp_header->checksum),
2906 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002907 }
2908 }
2909
paul9985f832005-02-09 15:51:56 +00002910 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002911 /* Update PDU length */
2912 stream_putw_at (circuit->snd_stream, lenp, length);
2913
Josh Bailey3f045a02012-03-24 08:35:20 -07002914 /* For HMAC MD5 we need to compute the md5 hash and store it */
2915 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2916 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2917 {
2918 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2919 stream_get_endp(circuit->snd_stream),
2920 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002921 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002922 /* Copy the hash into the stream */
2923 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2924 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2925 }
2926
jardineb5d44e2003-12-23 08:09:43 +00002927 return ISIS_OK;
2928}
2929
2930/*
2931 * 7.3.15.4 action on expiration of partial SNP interval
2932 * level 1
2933 */
hasso92365882005-01-18 13:53:33 +00002934static int
jardineb5d44e2003-12-23 08:09:43 +00002935send_psnp (int level, struct isis_circuit *circuit)
2936{
jardineb5d44e2003-12-23 08:09:43 +00002937 struct isis_lsp *lsp;
2938 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002939 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002940 u_char num_lsps;
2941 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002942
Josh Bailey3f045a02012-03-24 08:35:20 -07002943 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2944 circuit->u.bc.is_dr[level - 1])
2945 return ISIS_OK;
2946
2947 if (circuit->area->lspdb[level - 1] == NULL ||
2948 dict_count (circuit->area->lspdb[level - 1]) == 0)
2949 return ISIS_OK;
2950
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002951 if (! circuit->snd_stream)
2952 return ISIS_ERROR;
2953
Josh Bailey3f045a02012-03-24 08:35:20 -07002954 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2955
2956 while (1)
hassof390d2c2004-09-10 20:48:21 +00002957 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002958 list = list_new ();
2959 lsp_build_list_ssn (circuit, num_lsps, list,
2960 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002961
Josh Bailey3f045a02012-03-24 08:35:20 -07002962 if (listcount (list) == 0)
2963 {
2964 list_delete (list);
2965 return ISIS_OK;
2966 }
jardineb5d44e2003-12-23 08:09:43 +00002967
Josh Bailey3f045a02012-03-24 08:35:20 -07002968 retval = build_psnp (level, circuit, list);
2969 if (retval != ISIS_OK)
2970 {
2971 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2972 circuit->area->area_tag, level, circuit->interface->name);
2973 list_delete (list);
2974 return retval;
2975 }
jardineb5d44e2003-12-23 08:09:43 +00002976
Josh Bailey3f045a02012-03-24 08:35:20 -07002977 if (isis->debugs & DEBUG_SNP_PACKETS)
2978 {
David Lamparter01da6172015-04-10 09:10:11 +02002979 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07002980 circuit->area->area_tag, level,
2981 circuit->interface->name,
2982 stream_get_endp (circuit->snd_stream));
2983 if (isis->debugs & DEBUG_PACKET_DUMP)
2984 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2985 stream_get_endp (circuit->snd_stream));
2986 }
jardineb5d44e2003-12-23 08:09:43 +00002987
Josh Bailey3f045a02012-03-24 08:35:20 -07002988 retval = circuit->tx (circuit, level);
2989 if (retval != ISIS_OK)
2990 {
2991 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2992 circuit->area->area_tag, level,
2993 circuit->interface->name);
2994 list_delete (list);
2995 return retval;
2996 }
jardineb5d44e2003-12-23 08:09:43 +00002997
Josh Bailey3f045a02012-03-24 08:35:20 -07002998 /*
2999 * sending succeeded, we can clear SSN flags of this circuit
3000 * for the LSPs in list
3001 */
3002 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
3003 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
3004 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00003005 }
jardineb5d44e2003-12-23 08:09:43 +00003006
3007 return retval;
3008}
3009
3010int
3011send_l1_psnp (struct thread *thread)
3012{
3013
3014 struct isis_circuit *circuit;
3015 int retval = ISIS_OK;
3016
3017 circuit = THREAD_ARG (thread);
3018 assert (circuit);
3019
3020 circuit->t_send_psnp[0] = NULL;
3021
3022 send_psnp (1, circuit);
3023 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003024 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
3025 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003026
3027 return retval;
3028}
3029
3030/*
3031 * 7.3.15.4 action on expiration of partial SNP interval
3032 * level 2
3033 */
3034int
3035send_l2_psnp (struct thread *thread)
3036{
jardineb5d44e2003-12-23 08:09:43 +00003037 struct isis_circuit *circuit;
3038 int retval = ISIS_OK;
3039
3040 circuit = THREAD_ARG (thread);
3041 assert (circuit);
3042
3043 circuit->t_send_psnp[1] = NULL;
3044
3045 send_psnp (2, circuit);
3046
3047 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003048 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3049 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003050
3051 return retval;
3052}
3053
jardineb5d44e2003-12-23 08:09:43 +00003054/*
3055 * ISO 10589 - 7.3.14.3
3056 */
3057int
3058send_lsp (struct thread *thread)
3059{
3060 struct isis_circuit *circuit;
3061 struct isis_lsp *lsp;
3062 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003063 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003064
3065 circuit = THREAD_ARG (thread);
3066 assert (circuit);
3067
Josh Bailey3f045a02012-03-24 08:35:20 -07003068 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3069 {
3070 return retval;
3071 }
3072
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003073 node = listhead (circuit->lsp_queue);
3074
3075 /*
3076 * Handle case where there are no LSPs on the queue. This can
3077 * happen, for instance, if an adjacency goes down before this
3078 * thread gets a chance to run.
3079 */
3080 if (!node)
3081 {
3082 return retval;
3083 }
3084
3085 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003086
3087 /*
3088 * Do not send if levels do not match
3089 */
3090 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003091 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003092 list_delete_node (circuit->lsp_queue, node);
3093 return retval;
hassof390d2c2004-09-10 20:48:21 +00003094 }
jardineb5d44e2003-12-23 08:09:43 +00003095
Josh Bailey3f045a02012-03-24 08:35:20 -07003096 /*
3097 * Do not send if we do not have adjacencies in state up on the circuit
3098 */
3099 if (circuit->upadjcount[lsp->level - 1] == 0)
3100 {
3101 list_delete_node (circuit->lsp_queue, node);
3102 return retval;
3103 }
3104
3105 /* copy our lsp to the send buffer */
3106 stream_copy (circuit->snd_stream, lsp->pdu);
3107
3108 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3109 {
3110 zlog_debug
3111 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3112 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3113 rawlspid_print (lsp->lsp_header->lsp_id),
3114 ntohl (lsp->lsp_header->seq_num),
3115 ntohs (lsp->lsp_header->checksum),
3116 ntohs (lsp->lsp_header->rem_lifetime),
3117 circuit->interface->name);
3118 if (isis->debugs & DEBUG_PACKET_DUMP)
3119 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3120 stream_get_endp (circuit->snd_stream));
3121 }
3122
3123 retval = circuit->tx (circuit, lsp->level);
3124 if (retval != ISIS_OK)
3125 {
3126 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3127 circuit->area->area_tag, lsp->level,
3128 circuit->interface->name);
3129 return retval;
3130 }
3131
3132 /*
3133 * If the sending succeeded, we can del the lsp from circuits
3134 * lsp_queue
3135 */
3136 list_delete_node (circuit->lsp_queue, node);
3137
3138 /* Set the last-cleared time if the queue is empty. */
3139 /* TODO: Is is possible that new lsps keep being added to the queue
3140 * that the queue is never empty? */
3141 if (list_isempty (circuit->lsp_queue))
3142 circuit->lsp_queue_last_cleared = time (NULL);
3143
3144 /*
3145 * On broadcast circuits also the SRMflag can be cleared
3146 */
3147 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3148 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3149
jardineb5d44e2003-12-23 08:09:43 +00003150 return retval;
hassof390d2c2004-09-10 20:48:21 +00003151}
jardineb5d44e2003-12-23 08:09:43 +00003152
3153int
hassof390d2c2004-09-10 20:48:21 +00003154ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3155 int level)
jardineb5d44e2003-12-23 08:09:43 +00003156{
3157 unsigned long lenp;
3158 int retval;
3159 u_int16_t length;
3160 struct isis_fixed_hdr fixed_hdr;
3161
3162 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003163 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003164 else
3165 stream_reset (circuit->snd_stream);
3166
Josh Bailey3f045a02012-03-24 08:35:20 -07003167 // fill_llc_hdr (stream);
3168 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003169 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3170 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003171 else
hassof390d2c2004-09-10 20:48:21 +00003172 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3173 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003174
3175
paul9985f832005-02-09 15:51:56 +00003176 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003177 stream_putw (circuit->snd_stream, 0); /* PDU length */
3178 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003179 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003180 stream_putc (circuit->snd_stream, 9); /* code */
3181 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003182
hassof390d2c2004-09-10 20:48:21 +00003183 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3184 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3185 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3186 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003187
paul9985f832005-02-09 15:51:56 +00003188 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003189 /* Update PDU length */
3190 stream_putw_at (circuit->snd_stream, lenp, length);
3191
3192 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003193 if (retval != ISIS_OK)
3194 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3195 circuit->area->area_tag, level,
3196 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003197
3198 return retval;
3199}