blob: 02b50bf4885db91c1b32e6d73eb8e2144fa2656e [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_pdu.c
3 * PDU processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "memory.h"
27#include "thread.h"
28#include "linklist.h"
29#include "log.h"
30#include "stream.h"
31#include "vty.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070032#include "hash.h"
jardineb5d44e2003-12-23 08:09:43 +000033#include "prefix.h"
34#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010035#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070036#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000037
38#include "isisd/dict.h"
39#include "isisd/include-netbsd/iso.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_adjacency.h"
44#include "isisd/isis_circuit.h"
45#include "isisd/isis_network.h"
46#include "isisd/isis_misc.h"
47#include "isisd/isis_dr.h"
jardineb5d44e2003-12-23 08:09:43 +000048#include "isisd/isis_tlv.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_lsp.h"
52#include "isisd/isis_pdu.h"
53#include "isisd/iso_checksum.h"
54#include "isisd/isis_csm.h"
55#include "isisd/isis_events.h"
56
jardineb5d44e2003-12-23 08:09:43 +000057#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000058#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000059
60#ifndef PNBBY
61#define PNBBY 8
62#endif /* PNBBY */
63
64/* Utility mask array. */
Stephen Hemminger88d37b92014-11-03 01:20:09 +000065static const u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000066 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
67};
68
69/*
70 * HELPER FUNCS
71 */
72
73/*
74 * Compares two sets of area addresses
75 */
hassof390d2c2004-09-10 20:48:21 +000076static int
jardineb5d44e2003-12-23 08:09:43 +000077area_match (struct list *left, struct list *right)
78{
79 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000080 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000081
hasso3fdb2dd2005-09-28 18:45:54 +000082 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000083 {
hasso3fdb2dd2005-09-28 18:45:54 +000084 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000085 {
86 if (addr1->addr_len == addr2->addr_len &&
87 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
88 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000089 }
90 }
91
hassof390d2c2004-09-10 20:48:21 +000092 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000093}
94
95/*
96 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
97 * param ip1 the IS interface ip address structure
98 * param ip2 the IIH's ip address
99 * return 0 the IIH's IP is not in the IS's subnetwork
100 * 1 the IIH's IP is in the IS's subnetwork
101 */
hasso92365882005-01-18 13:53:33 +0000102static int
hassof390d2c2004-09-10 20:48:21 +0000103ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000104{
105 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000106 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000107 int len;
hassof390d2c2004-09-10 20:48:21 +0000108
109 addr1 = (u_char *) & ip1->prefix.s_addr;
110 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000111 len = ip1->prefixlen;
112
113 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000114 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000115
hasso53c997c2004-09-15 16:21:59 +0000116 while (offsetloop--)
117 if (addr1[offsetloop] != addr2[offsetloop])
118 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000119
hassof390d2c2004-09-10 20:48:21 +0000120 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000121 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
122 return 0;
hassof390d2c2004-09-10 20:48:21 +0000123
124 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000125}
126
jardineb5d44e2003-12-23 08:09:43 +0000127/*
128 * Compares two set of ip addresses
129 * param left the local interface's ip addresses
130 * param right the iih interface's ip address
131 * return 0 no match;
132 * 1 match;
133 */
hassof390d2c2004-09-10 20:48:21 +0000134static int
jardineb5d44e2003-12-23 08:09:43 +0000135ip_match (struct list *left, struct list *right)
136{
137 struct prefix_ipv4 *ip1;
138 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000139 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000140
hassoe082ac12004-09-27 18:13:57 +0000141 if ((left == NULL) || (right == NULL))
142 return 0;
143
hasso3fdb2dd2005-09-28 18:45:54 +0000144 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000145 {
hasso3fdb2dd2005-09-28 18:45:54 +0000146 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000147 {
148 if (ip_same_subnet (ip1, ip2))
149 {
150 return 1; /* match */
151 }
jardineb5d44e2003-12-23 08:09:43 +0000152 }
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 }
155 return 0;
156}
157
158/*
159 * Checks whether we should accept a PDU of given level
160 */
161static int
162accept_level (int level, int circuit_t)
163{
hassof390d2c2004-09-10 20:48:21 +0000164 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000165
166 return retval;
167}
168
Josh Bailey3f045a02012-03-24 08:35:20 -0700169/*
170 * Verify authentication information
171 * Support cleartext and HMAC MD5 authentication
172 */
173static int
174authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
175 struct stream *stream, uint32_t auth_tlv_offset)
jardineb5d44e2003-12-23 08:09:43 +0000176{
Josh Bailey3f045a02012-03-24 08:35:20 -0700177 unsigned char digest[ISIS_AUTH_MD5_SIZE];
178
179 /* Auth fail () - passwd type mismatch */
180 if (local->type != remote->type)
181 return ISIS_ERROR;
182
183 switch (local->type)
184 {
185 /* No authentication required */
186 case ISIS_PASSWD_TYPE_UNUSED:
187 break;
188
189 /* Cleartext (ISO 10589) */
hassof390d2c2004-09-10 20:48:21 +0000190 case ISIS_PASSWD_TYPE_CLEARTXT:
Josh Bailey3f045a02012-03-24 08:35:20 -0700191 /* Auth fail () - passwd len mismatch */
192 if (remote->len != local->len)
193 return ISIS_ERROR;
194 return memcmp (local->passwd, remote->passwd, local->len);
195
196 /* HMAC MD5 (RFC 3567) */
197 case ISIS_PASSWD_TYPE_HMAC_MD5:
198 /* Auth fail () - passwd len mismatch */
199 if (remote->len != ISIS_AUTH_MD5_SIZE)
200 return ISIS_ERROR;
201 /* Set the authentication value to 0 before the check */
202 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
203 ISIS_AUTH_MD5_SIZE);
204 /* Compute the digest */
205 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
206 (unsigned char *) &(local->passwd), local->len,
David Lamparter21401f32015-03-03 08:55:26 +0100207 (unsigned char *) &digest);
Josh Bailey3f045a02012-03-24 08:35:20 -0700208 /* Copy back the authentication value after the check */
209 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
210 remote->passwd, ISIS_AUTH_MD5_SIZE);
211 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
212
hassof390d2c2004-09-10 20:48:21 +0000213 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700214 zlog_err ("Unsupported authentication type");
215 return ISIS_ERROR;
216 }
217
218 /* Authentication pass when no authentication is configured */
219 return ISIS_OK;
220}
221
222static int
223lsp_authentication_check (struct stream *stream, struct isis_area *area,
224 int level, struct isis_passwd *passwd)
225{
226 struct isis_link_state_hdr *hdr;
227 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700228 uint16_t checksum, rem_lifetime, pdu_len;
Josh Bailey3f045a02012-03-24 08:35:20 -0700229 struct tlvs tlvs;
230 int retval = ISIS_OK;
231
232 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700233 pdu_len = ntohs (hdr->pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700234 expected |= TLVFLAG_AUTH_INFO;
235 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
236 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700237 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
Josh Bailey3f045a02012-03-24 08:35:20 -0700238 &expected, &found, &tlvs, &auth_tlv_offset);
239
240 if (retval != ISIS_OK)
241 {
242 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
243 "cksum 0x%04x, lifetime %us, len %u",
244 area->area_tag, level, rawlspid_print (hdr->lsp_id),
245 ntohl (hdr->seq_num), ntohs (hdr->checksum),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700246 ntohs (hdr->rem_lifetime), pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700247 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
248 (isis->debugs & DEBUG_PACKET_DUMP))
249 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
250 return retval;
hassof390d2c2004-09-10 20:48:21 +0000251 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700252
253 if (!(found & TLVFLAG_AUTH_INFO))
254 {
255 zlog_err ("No authentication tlv in LSP");
256 return ISIS_ERROR;
257 }
258
259 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
260 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
261 {
262 zlog_err ("Unknown authentication type in LSP");
263 return ISIS_ERROR;
264 }
265
266 /*
267 * RFC 5304 set checksum and remaining lifetime to zero before
268 * verification and reset to old values after verification.
269 */
270 checksum = hdr->checksum;
271 rem_lifetime = hdr->rem_lifetime;
272 hdr->checksum = 0;
273 hdr->rem_lifetime = 0;
274 retval = authentication_check (&tlvs.auth_info, passwd, stream,
275 auth_tlv_offset);
276 hdr->checksum = checksum;
277 hdr->rem_lifetime = rem_lifetime;
278
279 return retval;
jardineb5d44e2003-12-23 08:09:43 +0000280}
281
282/*
283 * Processing helper functions
284 */
hasso92365882005-01-18 13:53:33 +0000285static void
Josh Bailey3f045a02012-03-24 08:35:20 -0700286del_addr (void *val)
287{
288 XFREE (MTYPE_ISIS_TMP, val);
289}
290
291static void
292tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
293{
294 struct listnode *node;
295 struct area_addr *area_addr, *malloced;
296
297 if (adj->area_addrs)
298 {
299 adj->area_addrs->del = del_addr;
300 list_delete (adj->area_addrs);
301 }
302 adj->area_addrs = list_new ();
303 if (tlvs->area_addrs)
304 {
305 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
306 {
307 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
308 memcpy (malloced, area_addr, sizeof (struct area_addr));
309 listnode_add (adj->area_addrs, malloced);
310 }
311 }
312}
313
David Lamparter655071f2012-05-08 13:32:53 +0200314static int
hassof390d2c2004-09-10 20:48:21 +0000315tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000316{
317 int i;
318 struct nlpids *tlv_nlpids;
319
hassof390d2c2004-09-10 20:48:21 +0000320 if (tlvs->nlpids)
321 {
jardineb5d44e2003-12-23 08:09:43 +0000322
hassof390d2c2004-09-10 20:48:21 +0000323 tlv_nlpids = tlvs->nlpids;
David Lamparter655071f2012-05-08 13:32:53 +0200324 if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
325 return 1;
jardineb5d44e2003-12-23 08:09:43 +0000326
hassof390d2c2004-09-10 20:48:21 +0000327 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000328
hassof390d2c2004-09-10 20:48:21 +0000329 for (i = 0; i < tlv_nlpids->count; i++)
330 {
331 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
332 }
jardineb5d44e2003-12-23 08:09:43 +0000333 }
David Lamparter655071f2012-05-08 13:32:53 +0200334 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000335}
336
hasso92365882005-01-18 13:53:33 +0000337static void
hassof390d2c2004-09-10 20:48:21 +0000338tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000339{
hasso3fdb2dd2005-09-28 18:45:54 +0000340 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000341 struct in_addr *ipv4_addr, *malloced;
342
hassof390d2c2004-09-10 20:48:21 +0000343 if (adj->ipv4_addrs)
344 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700345 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000346 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000347 }
hassof390d2c2004-09-10 20:48:21 +0000348 adj->ipv4_addrs = list_new ();
349 if (tlvs->ipv4_addrs)
350 {
hasso3fdb2dd2005-09-28 18:45:54 +0000351 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000352 {
353 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
354 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
355 listnode_add (adj->ipv4_addrs, malloced);
356 }
357 }
jardineb5d44e2003-12-23 08:09:43 +0000358}
359
360#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000361static void
hassof390d2c2004-09-10 20:48:21 +0000362tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000363{
hasso3fdb2dd2005-09-28 18:45:54 +0000364 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000365 struct in6_addr *ipv6_addr, *malloced;
366
hassof390d2c2004-09-10 20:48:21 +0000367 if (adj->ipv6_addrs)
368 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700369 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000370 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000371 }
hassof390d2c2004-09-10 20:48:21 +0000372 adj->ipv6_addrs = list_new ();
373 if (tlvs->ipv6_addrs)
374 {
hasso3fdb2dd2005-09-28 18:45:54 +0000375 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000376 {
377 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
378 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
379 listnode_add (adj->ipv6_addrs, malloced);
380 }
381 }
jardineb5d44e2003-12-23 08:09:43 +0000382
383}
384#endif /* HAVE_IPV6 */
385
jardineb5d44e2003-12-23 08:09:43 +0000386/*
387 * RECEIVE SIDE
388 */
389
390/*
391 * Process P2P IIH
392 * ISO - 10589
393 * Section 8.2.5 - Receiving point-to-point IIH PDUs
394 *
395 */
396static int
397process_p2p_hello (struct isis_circuit *circuit)
398{
399 int retval = ISIS_OK;
400 struct isis_p2p_hello_hdr *hdr;
401 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700402 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700403 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000404 struct tlvs tlvs;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200405 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000406
Josh Bailey3f045a02012-03-24 08:35:20 -0700407 if (isis->debugs & DEBUG_ADJ_PACKETS)
408 {
409 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
410 circuit->area->area_tag, circuit->interface->name,
411 circuit_t2string (circuit->is_type), circuit->circuit_id);
412 if (isis->debugs & DEBUG_PACKET_DUMP)
413 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
414 stream_get_endp (circuit->rcv_stream));
415 }
416
417 if (circuit->circ_type != CIRCUIT_T_P2P)
418 {
419 zlog_warn ("p2p hello on non p2p circuit");
420 return ISIS_WARNING;
421 }
422
hassof390d2c2004-09-10 20:48:21 +0000423 if ((stream_get_endp (circuit->rcv_stream) -
424 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
425 {
426 zlog_warn ("Packet too short");
427 return ISIS_WARNING;
428 }
jardineb5d44e2003-12-23 08:09:43 +0000429
430 /* 8.2.5.1 PDU acceptance tests */
431
432 /* 8.2.5.1 a) external domain untrue */
433 /* FIXME: not useful at all? */
434
435 /* 8.2.5.1 b) ID Length mismatch */
436 /* checked at the handle_pdu */
437
438 /* 8.2.5.2 IIH PDU Processing */
439
440 /* 8.2.5.2 a) 1) Maximum Area Addresses */
441 /* Already checked, and can also be ommited */
442
443 /*
444 * Get the header
445 */
hassof390d2c2004-09-10 20:48:21 +0000446 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700447 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000448
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700449 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
450 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700451 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000452 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700453 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
454 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700455 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700456 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000457 }
jardineb5d44e2003-12-23 08:09:43 +0000458
jardineb5d44e2003-12-23 08:09:43 +0000459 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700460 * Set the stream endp to PDU length, ignoring additional padding
461 * introduced by transport chips.
462 */
463 if (pdu_len < stream_get_endp (circuit->rcv_stream))
464 stream_set_endp (circuit->rcv_stream, pdu_len);
465
466 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
467
468 /*
jardineb5d44e2003-12-23 08:09:43 +0000469 * Lets get the TLVS now
470 */
471 expected |= TLVFLAG_AREA_ADDRS;
472 expected |= TLVFLAG_AUTH_INFO;
473 expected |= TLVFLAG_NLPID;
474 expected |= TLVFLAG_IPV4_ADDR;
475 expected |= TLVFLAG_IPV6_ADDR;
476
Josh Bailey3f045a02012-03-24 08:35:20 -0700477 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000478 retval = parse_tlvs (circuit->area->area_tag,
479 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700480 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
481 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000482
hassof390d2c2004-09-10 20:48:21 +0000483 if (retval > ISIS_WARNING)
484 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700485 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000486 free_tlvs (&tlvs);
487 return retval;
488 };
jardineb5d44e2003-12-23 08:09:43 +0000489
Josh Bailey3f045a02012-03-24 08:35:20 -0700490 if (!(found & TLVFLAG_AREA_ADDRS))
491 {
492 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
493 free_tlvs (&tlvs);
494 return ISIS_WARNING;
495 }
496
David Lamparterb72f3452012-11-27 01:10:26 +0000497 if (!(found & TLVFLAG_NLPID))
498 {
499 zlog_warn ("No supported protocols TLV in P2P IS to IS hello");
500 free_tlvs (&tlvs);
501 return ISIS_WARNING;
502 }
503
jardineb5d44e2003-12-23 08:09:43 +0000504 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000505 if (circuit->passwd.type)
506 {
507 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700508 authentication_check (&tlvs.auth_info, &circuit->passwd,
509 circuit->rcv_stream, auth_tlv_offset))
510 {
511 isis_event_auth_failure (circuit->area->area_tag,
512 "P2P hello authentication failure",
513 hdr->source_id);
514 free_tlvs (&tlvs);
515 return ISIS_OK;
516 }
jardineb5d44e2003-12-23 08:09:43 +0000517 }
jardineb5d44e2003-12-23 08:09:43 +0000518
Josh Bailey3f045a02012-03-24 08:35:20 -0700519 /*
520 * check if it's own interface ip match iih ip addrs
521 */
David Lamparter28a8cfc2014-06-29 13:48:18 +0200522 if (found & TLVFLAG_IPV4_ADDR)
Josh Bailey3f045a02012-03-24 08:35:20 -0700523 {
David Lamparter28a8cfc2014-06-29 13:48:18 +0200524 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
525 v4_usable = 1;
526 else
527 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
528 "in P2P IIH from %s\n", circuit->interface->name);
529 }
530#ifndef HAVE_IPV6
531 else /* !(found & TLVFLAG_IPV4_ADDR) */
532 zlog_warn ("ISIS-Adj: no IPv4 in P2P IIH from %s "
533 "(this isisd has no IPv6)\n", circuit->interface->name);
534
535#else
536 if (found & TLVFLAG_IPV6_ADDR)
537 {
538 /* TBA: check that we have a linklocal ourselves? */
539 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +0200540 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200541 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
542 if (IN6_IS_ADDR_LINKLOCAL (ip))
543 {
544 v6_usable = 1;
545 break;
546 }
547
548 if (!v6_usable)
549 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
550 "in P2P IIH from %s\n", circuit->interface->name);
551 }
552
553 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
554 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n",
555 circuit->interface->name);
556#endif
557
558 if (!v6_usable && !v4_usable)
559 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700560 free_tlvs (&tlvs);
561 return ISIS_WARNING;
562 }
563
564 /*
565 * My interpertation of the ISO, if no adj exists we will create one for
566 * the circuit
567 */
568 adj = circuit->u.p2p.neighbor;
Amritha Nambiar3c28aaf2015-01-28 18:09:30 +0000569 /* If an adjacency exists, check it is with the source of the hello
570 * packets */
571 if (adj)
572 {
573 if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
574 {
575 zlog_debug("hello source and adjacency do not match, set adj down\n");
576 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
577 return 0;
578 }
579 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700580 if (!adj || adj->level != hdr->circuit_t)
581 {
582 if (!adj)
583 {
584 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
585 if (adj == NULL)
586 return ISIS_ERROR;
587 }
588 else
589 {
590 adj->level = hdr->circuit_t;
591 }
592 circuit->u.p2p.neighbor = adj;
593 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
594 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
595 }
596
597 /* 8.2.6 Monitoring point-to-point adjacencies */
598 adj->hold_time = ntohs (hdr->hold_time);
599 adj->last_upd = time (NULL);
600
jardineb5d44e2003-12-23 08:09:43 +0000601 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700602 tlvs_to_adj_area_addrs (&tlvs, adj);
603
604 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +0000605 if (tlvs_to_adj_nlpids (&tlvs, adj))
606 {
607 free_tlvs (&tlvs);
608 return ISIS_WARNING;
609 }
jardineb5d44e2003-12-23 08:09:43 +0000610
611 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700612 if (found & TLVFLAG_IPV4_ADDR)
613 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000614
615#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700616 if (found & TLVFLAG_IPV6_ADDR)
617 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000618#endif /* HAVE_IPV6 */
619
620 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000621 THREAD_TIMER_OFF (adj->t_expire);
622 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
623 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000624
625 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000626 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
627 {
628 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
629 if (circuit->area->is_type == IS_LEVEL_1)
630 {
631 switch (hdr->circuit_t)
632 {
633 case IS_LEVEL_1:
634 case IS_LEVEL_1_AND_2:
635 if (adj->adj_state != ISIS_ADJ_UP)
636 {
637 /* (4) adj state up */
638 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
639 /* (5) adj usage level 1 */
640 adj->adj_usage = ISIS_ADJ_LEVEL1;
641 }
642 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
643 {
644 ; /* accept */
645 }
646 break;
647 case IS_LEVEL_2:
648 if (adj->adj_state != ISIS_ADJ_UP)
649 {
650 /* (7) reject - wrong system type event */
651 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700652 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000653 return ISIS_WARNING; /* Reject */
654 }
655 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
656 {
657 /* (6) down - wrong system */
658 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
659 }
660 break;
661 }
662 }
jardineb5d44e2003-12-23 08:09:43 +0000663
hassof390d2c2004-09-10 20:48:21 +0000664 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
665 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
666 {
667 switch (hdr->circuit_t)
668 {
669 case IS_LEVEL_1:
670 if (adj->adj_state != ISIS_ADJ_UP)
671 {
672 /* (6) adj state up */
673 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
674 /* (7) adj usage level 1 */
675 adj->adj_usage = ISIS_ADJ_LEVEL1;
676 }
677 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
678 {
679 ; /* accept */
680 }
681 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
682 (adj->adj_usage == ISIS_ADJ_LEVEL2))
683 {
684 /* (8) down - wrong system */
685 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
686 }
687 break;
688 case IS_LEVEL_2:
689 if (adj->adj_state != ISIS_ADJ_UP)
690 {
691 /* (6) adj state up */
692 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
693 /* (9) adj usage level 2 */
694 adj->adj_usage = ISIS_ADJ_LEVEL2;
695 }
696 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
697 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
698 {
699 /* (8) down - wrong system */
700 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
701 }
702 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
703 {
704 ; /* Accept */
705 }
706 break;
707 case IS_LEVEL_1_AND_2:
708 if (adj->adj_state != ISIS_ADJ_UP)
709 {
710 /* (6) adj state up */
711 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
712 /* (10) adj usage level 1 */
713 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
714 }
715 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
716 (adj->adj_usage == ISIS_ADJ_LEVEL2))
717 {
718 /* (8) down - wrong system */
719 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
720 }
721 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
722 {
723 ; /* Accept */
724 }
725 break;
726 }
727 }
jardineb5d44e2003-12-23 08:09:43 +0000728
hassof390d2c2004-09-10 20:48:21 +0000729 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
730 if (circuit->area->is_type == IS_LEVEL_2)
731 {
732 switch (hdr->circuit_t)
733 {
734 case IS_LEVEL_1:
735 if (adj->adj_state != ISIS_ADJ_UP)
736 {
737 /* (5) reject - wrong system type event */
738 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700739 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000740 return ISIS_WARNING; /* Reject */
741 }
742 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
743 (adj->adj_usage == ISIS_ADJ_LEVEL2))
744 {
745 /* (6) down - wrong system */
746 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
747 }
748 break;
749 case IS_LEVEL_1_AND_2:
750 case IS_LEVEL_2:
751 if (adj->adj_state != ISIS_ADJ_UP)
752 {
753 /* (7) adj state up */
754 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
755 /* (8) adj usage level 2 */
756 adj->adj_usage = ISIS_ADJ_LEVEL2;
757 }
758 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
759 {
760 /* (6) down - wrong system */
761 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
762 }
763 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
764 {
765 ; /* Accept */
766 }
767 break;
768 }
769 }
jardineb5d44e2003-12-23 08:09:43 +0000770 }
jardineb5d44e2003-12-23 08:09:43 +0000771 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700772 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000773 {
hassof390d2c2004-09-10 20:48:21 +0000774 if (circuit->area->is_type == IS_LEVEL_1)
775 {
776 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
777 if (adj->adj_state != ISIS_ADJ_UP)
778 {
779 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
780 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
781 }
782 else
783 {
784 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
785 "Down - Area Mismatch");
786 }
787 }
788 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
789 else
790 {
791 switch (hdr->circuit_t)
792 {
793 case IS_LEVEL_1:
794 if (adj->adj_state != ISIS_ADJ_UP)
795 {
796 /* (6) reject - Area Mismatch event */
797 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700798 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000799 return ISIS_WARNING; /* Reject */
800 }
801 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
802 {
803 /* (7) down - area mismatch */
804 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000805
hassof390d2c2004-09-10 20:48:21 +0000806 }
807 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
808 (adj->adj_usage == ISIS_ADJ_LEVEL2))
809 {
810 /* (7) down - wrong system */
811 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
812 }
813 break;
814 case IS_LEVEL_1_AND_2:
815 case IS_LEVEL_2:
816 if (adj->adj_state != ISIS_ADJ_UP)
817 {
818 /* (8) adj state up */
819 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
820 /* (9) adj usage level 2 */
821 adj->adj_usage = ISIS_ADJ_LEVEL2;
822 }
823 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
824 {
825 /* (7) down - wrong system */
826 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
827 }
828 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
829 {
830 if (hdr->circuit_t == IS_LEVEL_2)
831 {
832 /* (7) down - wrong system */
833 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
834 "Wrong System");
835 }
836 else
837 {
838 /* (7) down - area mismatch */
839 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
840 "Area Mismatch");
841 }
842 }
843 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
844 {
845 ; /* Accept */
846 }
847 break;
848 }
849 }
jardineb5d44e2003-12-23 08:09:43 +0000850 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700851 else
852 {
853 /* down - area mismatch */
854 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
855 }
jardineb5d44e2003-12-23 08:09:43 +0000856 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
857 /* FIXME - Missing parts */
858
jardineb5d44e2003-12-23 08:09:43 +0000859 /* some of my own understanding of the ISO, why the heck does
860 * it not say what should I change the system_type to...
861 */
hassof390d2c2004-09-10 20:48:21 +0000862 switch (adj->adj_usage)
863 {
jardineb5d44e2003-12-23 08:09:43 +0000864 case ISIS_ADJ_LEVEL1:
865 adj->sys_type = ISIS_SYSTYPE_L1_IS;
866 break;
867 case ISIS_ADJ_LEVEL2:
868 adj->sys_type = ISIS_SYSTYPE_L2_IS;
869 break;
870 case ISIS_ADJ_LEVEL1AND2:
871 adj->sys_type = ISIS_SYSTYPE_L2_IS;
872 break;
873 case ISIS_ADJ_NONE:
874 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
875 break;
hassof390d2c2004-09-10 20:48:21 +0000876 }
jardineb5d44e2003-12-23 08:09:43 +0000877
878 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700879
880 if (isis->debugs & DEBUG_ADJ_PACKETS)
881 {
882 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
883 " cir id %02d, length %d",
884 circuit->area->area_tag, circuit->interface->name,
885 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700886 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700887 }
jardineb5d44e2003-12-23 08:09:43 +0000888
889 free_tlvs (&tlvs);
890
891 return retval;
892}
893
jardineb5d44e2003-12-23 08:09:43 +0000894/*
895 * Process IS-IS LAN Level 1/2 Hello PDU
896 */
hassof390d2c2004-09-10 20:48:21 +0000897static int
898process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000899{
900 int retval = ISIS_OK;
901 struct isis_lan_hello_hdr hdr;
902 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700903 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000904 struct tlvs tlvs;
905 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000906 struct listnode *node;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200907 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000908
Josh Bailey3f045a02012-03-24 08:35:20 -0700909 if (isis->debugs & DEBUG_ADJ_PACKETS)
910 {
911 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
912 "cirID %u",
913 circuit->area->area_tag, level, circuit->interface->name,
914 circuit_t2string (circuit->is_type), circuit->circuit_id);
915 if (isis->debugs & DEBUG_PACKET_DUMP)
916 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
917 stream_get_endp (circuit->rcv_stream));
918 }
919
920 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
921 {
922 zlog_warn ("lan hello on non broadcast circuit");
923 return ISIS_WARNING;
924 }
925
hassof390d2c2004-09-10 20:48:21 +0000926 if ((stream_get_endp (circuit->rcv_stream) -
927 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
928 {
929 zlog_warn ("Packet too short");
930 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000931 }
hassof390d2c2004-09-10 20:48:21 +0000932
933 if (circuit->ext_domain)
934 {
hasso529d65b2004-12-24 00:14:50 +0000935 zlog_debug ("level %d LAN Hello received over circuit with "
936 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000937 return ISIS_WARNING;
938 }
939
Josh Bailey3f045a02012-03-24 08:35:20 -0700940 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000941 {
942 if (isis->debugs & DEBUG_ADJ_PACKETS)
943 {
hasso529d65b2004-12-24 00:14:50 +0000944 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
945 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000946 }
947 return ISIS_WARNING;
948 }
jardineb5d44e2003-12-23 08:09:43 +0000949
950#if 0
951 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000952 if (!accept_level (level, circuit->area->is_type))
953 {
954 if (isis->debugs & DEBUG_ADJ_PACKETS)
955 {
hasso529d65b2004-12-24 00:14:50 +0000956 zlog_debug ("ISIS-Adj (%s): is type mismatch",
957 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000958 }
959 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000960 }
jardineb5d44e2003-12-23 08:09:43 +0000961#endif
962 /*
963 * Fill the header
964 */
965 hdr.circuit_t = stream_getc (circuit->rcv_stream);
966 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
967 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000968 hdr.pdu_len = stream_getw (circuit->rcv_stream);
969 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000970 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
971
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700972 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
973 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700974 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000975 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700976 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
977 "invalid pdu length %d",
978 circuit->area->area_tag, circuit->interface->name,
979 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700980 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700981 }
982
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700983 /*
984 * Set the stream endp to PDU length, ignoring additional padding
985 * introduced by transport chips.
986 */
987 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
988 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
989
Josh Bailey3f045a02012-03-24 08:35:20 -0700990 if (hdr.circuit_t != IS_LEVEL_1 &&
991 hdr.circuit_t != IS_LEVEL_2 &&
992 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
993 (level & hdr.circuit_t) == 0)
994 {
995 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
996 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000997 return ISIS_ERROR;
998 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700999
jardineb5d44e2003-12-23 08:09:43 +00001000 /*
1001 * Then get the tlvs
1002 */
1003 expected |= TLVFLAG_AUTH_INFO;
1004 expected |= TLVFLAG_AREA_ADDRS;
1005 expected |= TLVFLAG_LAN_NEIGHS;
1006 expected |= TLVFLAG_NLPID;
1007 expected |= TLVFLAG_IPV4_ADDR;
1008 expected |= TLVFLAG_IPV6_ADDR;
1009
Josh Bailey3f045a02012-03-24 08:35:20 -07001010 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001011 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -07001012 STREAM_PNT (circuit->rcv_stream),
1013 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
1014 &expected, &found, &tlvs,
1015 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001016
hassof390d2c2004-09-10 20:48:21 +00001017 if (retval > ISIS_WARNING)
1018 {
1019 zlog_warn ("parse_tlvs() failed");
1020 goto out;
1021 }
jardineb5d44e2003-12-23 08:09:43 +00001022
hassof390d2c2004-09-10 20:48:21 +00001023 if (!(found & TLVFLAG_AREA_ADDRS))
1024 {
1025 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
1026 level);
jardineb5d44e2003-12-23 08:09:43 +00001027 retval = ISIS_WARNING;
1028 goto out;
1029 }
hassof390d2c2004-09-10 20:48:21 +00001030
David Lamparterb72f3452012-11-27 01:10:26 +00001031 if (!(found & TLVFLAG_NLPID))
1032 {
1033 zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
1034 level);
1035 retval = ISIS_WARNING;
1036 goto out;
1037 }
1038
Josh Bailey3f045a02012-03-24 08:35:20 -07001039 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +00001040 if (circuit->passwd.type)
1041 {
1042 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001043 authentication_check (&tlvs.auth_info, &circuit->passwd,
1044 circuit->rcv_stream, auth_tlv_offset))
1045 {
1046 isis_event_auth_failure (circuit->area->area_tag,
1047 "LAN hello authentication failure",
1048 hdr.source_id);
1049 retval = ISIS_WARNING;
1050 goto out;
1051 }
hassof390d2c2004-09-10 20:48:21 +00001052 }
jardineb5d44e2003-12-23 08:09:43 +00001053
David Lamparter19f78ce2012-11-27 01:10:25 +00001054 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
1055 {
1056 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
1057 circuit->area->area_tag, circuit->interface->name);
1058 return ISIS_WARNING;
1059 }
1060
jardineb5d44e2003-12-23 08:09:43 +00001061 /*
1062 * Accept the level 1 adjacency only if a match between local and
1063 * remote area addresses is found
1064 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001065 if (listcount (circuit->area->area_addrs) == 0 ||
1066 (level == IS_LEVEL_1 &&
1067 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +00001068 {
1069 if (isis->debugs & DEBUG_ADJ_PACKETS)
1070 {
hasso529d65b2004-12-24 00:14:50 +00001071 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1072 circuit->area->area_tag, level,
1073 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001074 }
1075 retval = ISIS_OK;
1076 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001077 }
jardineb5d44e2003-12-23 08:09:43 +00001078
1079 /*
1080 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001081 */
1082 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1083 {
hasso529d65b2004-12-24 00:14:50 +00001084 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1085 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001086
hassof390d2c2004-09-10 20:48:21 +00001087 retval = ISIS_OK;
1088 goto out;
1089 }
jardineb5d44e2003-12-23 08:09:43 +00001090
1091 /*
1092 * check if it's own interface ip match iih ip addrs
1093 */
David Lamparter28a8cfc2014-06-29 13:48:18 +02001094 if (found & TLVFLAG_IPV4_ADDR)
hassof390d2c2004-09-10 20:48:21 +00001095 {
David Lamparter28a8cfc2014-06-29 13:48:18 +02001096 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
1097 v4_usable = 1;
1098 else
1099 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
1100 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001101 }
David Lamparter28a8cfc2014-06-29 13:48:18 +02001102#ifndef HAVE_IPV6
1103 else /* !(found & TLVFLAG_IPV4_ADDR) */
1104 zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s "
1105 "(this isisd has no IPv6)\n", circuit->interface->name);
1106
1107#else
1108 if (found & TLVFLAG_IPV6_ADDR)
1109 {
1110 /* TBA: check that we have a linklocal ourselves? */
1111 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +02001112 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +02001113 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
1114 if (IN6_IS_ADDR_LINKLOCAL (ip))
1115 {
1116 v6_usable = 1;
1117 break;
1118 }
1119
1120 if (!v6_usable)
1121 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
1122 "in LAN IIH from %s\n", circuit->interface->name);
1123 }
1124
1125 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
1126 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
1127 circuit->interface->name);
1128#endif
1129
1130 if (!v6_usable && !v4_usable)
1131 {
1132 free_tlvs (&tlvs);
1133 return ISIS_WARNING;
1134 }
1135
jardineb5d44e2003-12-23 08:09:43 +00001136
1137 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001138 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1139 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001140 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001141 if (!adj)
1142 {
1143 /*
1144 * Do as in 8.4.2.5
1145 */
1146 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1147 if (adj == NULL)
1148 {
1149 retval = ISIS_ERROR;
1150 goto out;
1151 }
1152 }
1153 else
1154 {
1155 if (ssnpa) {
1156 memcpy (adj->snpa, ssnpa, 6);
1157 } else {
1158 memset (adj->snpa, ' ', 6);
1159 }
1160 adj->level = level;
1161 }
hassof390d2c2004-09-10 20:48:21 +00001162 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001163
Josh Bailey3f045a02012-03-24 08:35:20 -07001164 if (level == IS_LEVEL_1)
1165 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001166 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001167 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001168 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1169 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001170 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001171 }
jardineb5d44e2003-12-23 08:09:43 +00001172
hassoa211d652004-09-20 14:55:29 +00001173 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1174 switch (level)
1175 {
1176 case 1:
1177 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1178 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001179 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001180 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1181 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001182 }
1183 break;
1184 case 2:
1185 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1186 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001187 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001188 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1189 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001190 }
1191 break;
1192 }
jardineb5d44e2003-12-23 08:09:43 +00001193
1194 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001195 adj->last_upd = time (NULL);
1196 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001197
1198 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1199
Josh Bailey3f045a02012-03-24 08:35:20 -07001200 tlvs_to_adj_area_addrs (&tlvs, adj);
1201
jardineb5d44e2003-12-23 08:09:43 +00001202 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +00001203 if (tlvs_to_adj_nlpids (&tlvs, adj))
1204 {
1205 retval = ISIS_WARNING;
1206 goto out;
1207 }
jardineb5d44e2003-12-23 08:09:43 +00001208
1209 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001210 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001211 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1212
1213#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001214 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001215 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1216#endif /* HAVE_IPV6 */
1217
1218 adj->circuit_t = hdr.circuit_t;
1219
1220 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001221 THREAD_TIMER_OFF (adj->t_expire);
1222 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001223 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001224
1225 /*
1226 * If the snpa for this circuit is found from LAN Neighbours TLV
1227 * we have two-way communication -> adjacency can be put to state "up"
1228 */
1229
hassof390d2c2004-09-10 20:48:21 +00001230 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001231 {
1232 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001233 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001234 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1235 {
1236 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1237 {
1238 isis_adj_state_change (adj, ISIS_ADJ_UP,
1239 "own SNPA found in LAN Neighbours TLV");
1240 }
1241 }
jardineb5d44e2003-12-23 08:09:43 +00001242 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001243 else
1244 {
1245 int found = 0;
1246 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1247 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1248 {
1249 found = 1;
1250 break;
1251 }
1252 if (found == 0)
1253 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1254 "own SNPA not found in LAN Neighbours TLV");
1255 }
1256 }
1257 else if (adj->adj_state == ISIS_ADJ_UP)
1258 {
1259 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1260 "no LAN Neighbours TLV found");
1261 }
jardineb5d44e2003-12-23 08:09:43 +00001262
hassof390d2c2004-09-10 20:48:21 +00001263out:
hassof390d2c2004-09-10 20:48:21 +00001264 if (isis->debugs & DEBUG_ADJ_PACKETS)
1265 {
hasso529d65b2004-12-24 00:14:50 +00001266 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
David Lamparter01da6172015-04-10 09:10:11 +02001267 "cirID %u, length %zd",
hasso529d65b2004-12-24 00:14:50 +00001268 circuit->area->area_tag,
1269 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001270 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001271 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001272 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001273 }
jardineb5d44e2003-12-23 08:09:43 +00001274
1275 free_tlvs (&tlvs);
1276
1277 return retval;
1278}
1279
1280/*
1281 * Process Level 1/2 Link State
1282 * ISO - 10589
1283 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001284 */
1285static int
1286process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001287{
1288 struct isis_link_state_hdr *hdr;
1289 struct isis_adjacency *adj = NULL;
1290 struct isis_lsp *lsp, *lsp0 = NULL;
1291 int retval = ISIS_OK, comp = 0;
1292 u_char lspid[ISIS_SYS_ID_LEN + 2];
1293 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001294 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001295
Josh Bailey3f045a02012-03-24 08:35:20 -07001296 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1297 {
1298 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1299 circuit->area->area_tag, level, circuit->interface->name,
1300 circuit_t2string (circuit->is_type), circuit->circuit_id);
1301 if (isis->debugs & DEBUG_PACKET_DUMP)
1302 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1303 stream_get_endp (circuit->rcv_stream));
1304 }
1305
hassof390d2c2004-09-10 20:48:21 +00001306 if ((stream_get_endp (circuit->rcv_stream) -
1307 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1308 {
1309 zlog_warn ("Packet too short");
1310 return ISIS_WARNING;
1311 }
jardineb5d44e2003-12-23 08:09:43 +00001312
1313 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001314 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001315 pdu_len = ntohs (hdr->pdu_len);
1316
1317 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001318 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001319 pdu_len > ISO_MTU(circuit) ||
1320 pdu_len > stream_get_endp (circuit->rcv_stream))
1321 {
1322 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1323 circuit->area->area_tag,
1324 rawlspid_print (hdr->lsp_id), pdu_len);
1325
1326 return ISIS_WARNING;
1327 }
1328
1329 /*
1330 * Set the stream endp to PDU length, ignoring additional padding
1331 * introduced by transport chips.
1332 */
1333 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1334 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001335
hassof390d2c2004-09-10 20:48:21 +00001336 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1337 {
hasso529d65b2004-12-24 00:14:50 +00001338 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001339 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001340 circuit->area->area_tag,
1341 level,
1342 rawlspid_print (hdr->lsp_id),
1343 ntohl (hdr->seq_num),
1344 ntohs (hdr->checksum),
1345 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001346 pdu_len,
paul15935e92005-05-03 09:27:23 +00001347 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001348 }
jardineb5d44e2003-12-23 08:09:43 +00001349
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001350 /* lsp is_type check */
1351 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1352 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001353 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001354 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001355 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001356 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1357 /* continue as per RFC1122 Be liberal in what you accept, and
1358 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001359 }
jardineb5d44e2003-12-23 08:09:43 +00001360
1361 /* Checksum sanity check - FIXME: move to correct place */
1362 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001363 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001364 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001365 {
hasso529d65b2004-12-24 00:14:50 +00001366 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1367 circuit->area->area_tag,
1368 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001369
hassof390d2c2004-09-10 20:48:21 +00001370 return ISIS_WARNING;
1371 }
jardineb5d44e2003-12-23 08:09:43 +00001372
1373 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001374 if (circuit->ext_domain)
1375 {
hasso529d65b2004-12-24 00:14:50 +00001376 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001377 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1378 "externalDomain = true", circuit->area->area_tag,
1379 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001380
hassof390d2c2004-09-10 20:48:21 +00001381 return ISIS_WARNING;
1382 }
jardineb5d44e2003-12-23 08:09:43 +00001383
1384 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001385 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001386 {
hasso529d65b2004-12-24 00:14:50 +00001387 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1388 " type %s",
1389 circuit->area->area_tag,
1390 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001391 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001392
hassof390d2c2004-09-10 20:48:21 +00001393 return ISIS_WARNING;
1394 }
jardineb5d44e2003-12-23 08:09:43 +00001395
1396 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1397
1398 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1399
1400 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001401 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1402 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001403 if (passwd->type)
1404 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001405 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1406 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001407 {
1408 isis_event_auth_failure (circuit->area->area_tag,
1409 "LSP authentication failure", hdr->lsp_id);
1410 return ISIS_WARNING;
1411 }
jardineb5d44e2003-12-23 08:09:43 +00001412 }
jardineb5d44e2003-12-23 08:09:43 +00001413 /* Find the LSP in our database and compare it to this Link State header */
1414 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1415 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001416 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1417 hdr->checksum, hdr->rem_lifetime);
1418 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001419#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001420 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001421#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001422 ))
jardineb5d44e2003-12-23 08:09:43 +00001423 goto dontcheckadj;
1424
1425 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1426 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001427
hassof390d2c2004-09-10 20:48:21 +00001428 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1429 {
1430 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1431 if (!adj)
1432 {
hasso529d65b2004-12-24 00:14:50 +00001433 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1434 "lifetime %us on %s",
1435 circuit->area->area_tag,
1436 rawlspid_print (hdr->lsp_id),
1437 ntohl (hdr->seq_num),
1438 ntohs (hdr->checksum),
1439 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001440 return ISIS_WARNING; /* Silently discard */
1441 }
jardineb5d44e2003-12-23 08:09:43 +00001442 }
jardineb5d44e2003-12-23 08:09:43 +00001443 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001444 else
1445 {
1446 /* If no adj, or no sharing of level */
1447 if (!circuit->u.p2p.neighbor)
1448 {
1449 return ISIS_OK; /* Silently discard */
1450 }
1451 else
1452 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001453 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001454 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001455 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001456 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1457 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001458 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001459 }
jardineb5d44e2003-12-23 08:09:43 +00001460 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001461
hassof390d2c2004-09-10 20:48:21 +00001462dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001463 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1464
1465 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1466
hassof390d2c2004-09-10 20:48:21 +00001467 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001468
hassof390d2c2004-09-10 20:48:21 +00001469 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1470 if (hdr->rem_lifetime == 0)
1471 {
1472 if (!lsp)
1473 {
1474 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1475 /* only needed on explicit update, eg - p2p */
1476 if (circuit->circ_type == CIRCUIT_T_P2P)
1477 ack_lsp (hdr, circuit, level);
1478 return retval; /* FIXME: do we need a purge? */
1479 }
1480 else
1481 {
1482 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1483 {
1484 /* LSP by some other system -> do 7.3.16.4 b) */
1485 /* 7.3.16.4 b) 1) */
1486 if (comp == LSP_NEWER)
1487 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001488 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001489 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001490 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001491 /* iii */
1492 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1493 /* v */
1494 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1495 /* iv */
1496 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1497 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001498
hassof390d2c2004-09-10 20:48:21 +00001499 } /* 7.3.16.4 b) 2) */
1500 else if (comp == LSP_EQUAL)
1501 {
1502 /* i */
1503 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1504 /* ii */
1505 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1506 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1507 } /* 7.3.16.4 b) 3) */
1508 else
1509 {
1510 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1511 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1512 }
1513 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001514 else if (lsp->lsp_header->rem_lifetime != 0)
1515 {
1516 /* our own LSP -> 7.3.16.4 c) */
1517 if (comp == LSP_NEWER)
1518 {
1519 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1520 lsp_set_all_srmflags (lsp);
1521 }
1522 else
1523 {
1524 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1525 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1526 }
1527 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1528 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1529 "seq 0x%08x", circuit->area->area_tag,
1530 rawlspid_print (hdr->lsp_id),
1531 ntohl (lsp->lsp_header->seq_num));
1532 }
hassof390d2c2004-09-10 20:48:21 +00001533 }
1534 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001535 }
jardineb5d44e2003-12-23 08:09:43 +00001536 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1537 * purge */
hassof390d2c2004-09-10 20:48:21 +00001538 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1539 {
1540 if (!lsp)
1541 {
1542 /* 7.3.16.4: initiate a purge */
1543 lsp_purge_non_exist (hdr, circuit->area);
1544 return ISIS_OK;
1545 }
1546 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1547
1548 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1549 * has information that the current sequence number for source S is
1550 * "greater" than that held by S, ... */
1551
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001552 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001553 {
1554 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001555 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001556 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1557 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1558 "0x%08x", circuit->area->area_tag,
1559 rawlspid_print (hdr->lsp_id),
1560 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001561 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001562 /* If the received LSP is older or equal,
1563 * resend the LSP which will act as ACK */
1564 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001565 }
hassof390d2c2004-09-10 20:48:21 +00001566 else
1567 {
1568 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001569
hassof390d2c2004-09-10 20:48:21 +00001570 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1571 if ((!lsp || comp == LSP_NEWER))
1572 {
hassof390d2c2004-09-10 20:48:21 +00001573 /*
1574 * If this lsp is a frag, need to see if we have zero lsp present
1575 */
1576 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1577 {
1578 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1579 LSP_FRAGMENT (lspid) = 0;
1580 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1581 if (!lsp0)
1582 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001583 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001584 return ISIS_OK;
1585 }
1586 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001587 /* i */
1588 if (!lsp)
1589 {
1590 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001591 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001592 circuit->area, level);
1593 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1594 }
1595 else /* exists, so we overwrite */
1596 {
1597 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1598 }
hassof390d2c2004-09-10 20:48:21 +00001599 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001600 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001601 /* iii */
1602 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001603
hassof390d2c2004-09-10 20:48:21 +00001604 /* iv */
1605 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1606 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1607 /* FIXME: v) */
1608 }
1609 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1610 else if (comp == LSP_EQUAL)
1611 {
1612 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001613 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001614 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001615 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001616 }
1617 /* 7.3.15.1 e) 3) LSP older than the one in db */
1618 else
1619 {
1620 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1621 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1622 }
jardineb5d44e2003-12-23 08:09:43 +00001623 }
jardineb5d44e2003-12-23 08:09:43 +00001624 return retval;
1625}
1626
1627/*
1628 * Process Sequence Numbers
1629 * ISO - 10589
1630 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1631 */
1632
hasso92365882005-01-18 13:53:33 +00001633static int
hassof390d2c2004-09-10 20:48:21 +00001634process_snp (int snp_type, int level, struct isis_circuit *circuit,
1635 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001636{
1637 int retval = ISIS_OK;
1638 int cmp, own_lsp;
1639 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001640 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001641 struct isis_adjacency *adj;
1642 struct isis_complete_seqnum_hdr *chdr = NULL;
1643 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001644 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001645 struct isis_lsp *lsp;
1646 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001647 struct listnode *node, *nnode;
1648 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001649 struct tlvs tlvs;
1650 struct list *lsp_list = NULL;
1651 struct isis_passwd *passwd;
1652
hassof390d2c2004-09-10 20:48:21 +00001653 if (snp_type == ISIS_SNP_CSNP_FLAG)
1654 {
1655 /* getting the header info */
1656 typechar = 'C';
1657 chdr =
1658 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001659 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1660 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001661 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001662 pdu_len > ISO_MTU(circuit) ||
1663 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001664 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001665 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1666 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001667 }
jardineb5d44e2003-12-23 08:09:43 +00001668 }
hassof390d2c2004-09-10 20:48:21 +00001669 else
1670 {
1671 typechar = 'P';
1672 phdr =
1673 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001674 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1675 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001676 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001677 pdu_len > ISO_MTU(circuit) ||
1678 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001679 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001680 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1681 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001682 }
jardineb5d44e2003-12-23 08:09:43 +00001683 }
jardineb5d44e2003-12-23 08:09:43 +00001684
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001685 /*
1686 * Set the stream endp to PDU length, ignoring additional padding
1687 * introduced by transport chips.
1688 */
1689 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1690 stream_set_endp (circuit->rcv_stream, pdu_len);
1691
jardineb5d44e2003-12-23 08:09:43 +00001692 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001693 if (circuit->ext_domain)
1694 {
jardineb5d44e2003-12-23 08:09:43 +00001695
hasso529d65b2004-12-24 00:14:50 +00001696 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1697 "skipping: circuit externalDomain = true",
1698 circuit->area->area_tag,
1699 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001700
1701 return ISIS_OK;
1702 }
hassof390d2c2004-09-10 20:48:21 +00001703
1704 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001705 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001706 {
1707
hasso529d65b2004-12-24 00:14:50 +00001708 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1709 "skipping: circuit type %s does not match level %d",
1710 circuit->area->area_tag,
1711 level,
1712 typechar,
1713 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001714 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001715
1716 return ISIS_OK;
1717 }
1718
1719 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1720 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001721 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1722 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001723 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001724 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1725 "skipping: we are not the DIS",
1726 circuit->area->area_tag,
1727 level,
1728 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001729
Josh Bailey3f045a02012-03-24 08:35:20 -07001730 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001731 }
jardineb5d44e2003-12-23 08:09:43 +00001732
1733 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1734
1735 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1736 * - already checked */
1737
1738 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1739 /* for broadcast circuits, snpa should be compared */
1740 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001741 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1742 {
1743 if (snp_type == ISIS_SNP_CSNP_FLAG)
1744 {
1745 adj =
1746 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1747 }
1748 else
1749 {
1750 /* a psnp on a broadcast, how lovely of Juniper :) */
1751 adj =
1752 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1753 }
1754 if (!adj)
1755 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001756 }
hassof390d2c2004-09-10 20:48:21 +00001757 else
1758 {
1759 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001760 {
1761 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1762 return ISIS_OK; /* Silently discard */
1763 }
hassof390d2c2004-09-10 20:48:21 +00001764 }
jardineb5d44e2003-12-23 08:09:43 +00001765
1766 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1767
1768 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1769
1770 memset (&tlvs, 0, sizeof (struct tlvs));
1771
1772 /* parse the SNP */
1773 expected |= TLVFLAG_LSP_ENTRIES;
1774 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001775
1776 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001777 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001778 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001779 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001780 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001781
hassof390d2c2004-09-10 20:48:21 +00001782 if (retval > ISIS_WARNING)
1783 {
1784 zlog_warn ("something went very wrong processing SNP");
1785 free_tlvs (&tlvs);
1786 return retval;
1787 }
jardineb5d44e2003-12-23 08:09:43 +00001788
Josh Bailey3f045a02012-03-24 08:35:20 -07001789 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001790 passwd = &circuit->area->area_passwd;
1791 else
1792 passwd = &circuit->area->domain_passwd;
1793
1794 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001795 {
hasso1cbc5622005-01-01 10:29:51 +00001796 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001797 {
1798 if (!(found & TLVFLAG_AUTH_INFO) ||
1799 authentication_check (&tlvs.auth_info, passwd,
1800 circuit->rcv_stream, auth_tlv_offset))
1801 {
1802 isis_event_auth_failure (circuit->area->area_tag,
1803 "SNP authentication" " failure",
1804 phdr ? phdr->source_id :
1805 chdr->source_id);
1806 free_tlvs (&tlvs);
1807 return ISIS_OK;
1808 }
1809 }
hassof390d2c2004-09-10 20:48:21 +00001810 }
jardineb5d44e2003-12-23 08:09:43 +00001811
1812 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001813 if (isis->debugs & DEBUG_SNP_PACKETS)
1814 {
hasso529d65b2004-12-24 00:14:50 +00001815 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1816 circuit->area->area_tag,
1817 level,
1818 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001819 if (tlvs.lsp_entries)
1820 {
hasso3fdb2dd2005-09-28 18:45:54 +00001821 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001822 {
hasso529d65b2004-12-24 00:14:50 +00001823 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1824 " cksum 0x%04x, lifetime %us",
1825 circuit->area->area_tag,
1826 typechar,
1827 rawlspid_print (entry->lsp_id),
1828 ntohl (entry->seq_num),
1829 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001830 }
1831 }
jardineb5d44e2003-12-23 08:09:43 +00001832 }
jardineb5d44e2003-12-23 08:09:43 +00001833
1834 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001835 if (tlvs.lsp_entries)
1836 {
hasso3fdb2dd2005-09-28 18:45:54 +00001837 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001838 {
1839 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1840 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1841 if (lsp)
1842 {
1843 /* 7.3.15.2 b) 1) is this LSP newer */
1844 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1845 entry->checksum, entry->rem_lifetime);
1846 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1847 if (cmp == LSP_EQUAL)
1848 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001849 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1850 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001851 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001852 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001853 else if (cmp == LSP_OLDER)
1854 {
1855 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1856 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1857 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001858 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001859 else
1860 {
hassof390d2c2004-09-10 20:48:21 +00001861 if (own_lsp)
1862 {
1863 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1864 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1865 }
1866 else
1867 {
1868 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001869 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1870 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001871 }
1872 }
1873 }
1874 else
1875 {
1876 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1877 * insert it and set SSN on it */
1878 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1879 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1880 {
1881 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1882 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001883 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001884 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001885 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001886 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1887 }
1888 }
jardineb5d44e2003-12-23 08:09:43 +00001889 }
1890 }
jardineb5d44e2003-12-23 08:09:43 +00001891
1892 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001893 if (snp_type == ISIS_SNP_CSNP_FLAG)
1894 {
1895 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001896 * Build a list from our own LSP db bounded with
1897 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001898 */
1899 lsp_list = list_new ();
1900 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1901 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001902
hassof390d2c2004-09-10 20:48:21 +00001903 /* Fixme: Find a better solution */
1904 if (tlvs.lsp_entries)
1905 {
paul1eb8ef22005-04-07 07:30:20 +00001906 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001907 {
paul1eb8ef22005-04-07 07:30:20 +00001908 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001909 {
1910 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1911 {
1912 list_delete_node (lsp_list, node2);
1913 break;
1914 }
1915 }
1916 }
1917 }
1918 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001919 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001920 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001921 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001922 list_delete (lsp_list);
1923
jardineb5d44e2003-12-23 08:09:43 +00001924 }
jardineb5d44e2003-12-23 08:09:43 +00001925
1926 free_tlvs (&tlvs);
1927 return retval;
1928}
1929
hasso92365882005-01-18 13:53:33 +00001930static int
hassof390d2c2004-09-10 20:48:21 +00001931process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001932{
Josh Bailey3f045a02012-03-24 08:35:20 -07001933 if (isis->debugs & DEBUG_SNP_PACKETS)
1934 {
1935 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1936 circuit->area->area_tag, level, circuit->interface->name,
1937 circuit_t2string (circuit->is_type), circuit->circuit_id);
1938 if (isis->debugs & DEBUG_PACKET_DUMP)
1939 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1940 stream_get_endp (circuit->rcv_stream));
1941 }
1942
jardineb5d44e2003-12-23 08:09:43 +00001943 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001944 if ((stream_get_endp (circuit->rcv_stream) -
1945 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1946 {
1947 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1948 return ISIS_WARNING;
1949 }
jardineb5d44e2003-12-23 08:09:43 +00001950
1951 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1952}
1953
hasso92365882005-01-18 13:53:33 +00001954static int
hassof390d2c2004-09-10 20:48:21 +00001955process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001956{
Josh Bailey3f045a02012-03-24 08:35:20 -07001957 if (isis->debugs & DEBUG_SNP_PACKETS)
1958 {
1959 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1960 circuit->area->area_tag, level, circuit->interface->name,
1961 circuit_t2string (circuit->is_type), circuit->circuit_id);
1962 if (isis->debugs & DEBUG_PACKET_DUMP)
1963 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1964 stream_get_endp (circuit->rcv_stream));
1965 }
1966
hassof390d2c2004-09-10 20:48:21 +00001967 if ((stream_get_endp (circuit->rcv_stream) -
1968 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1969 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001970 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001971 return ISIS_WARNING;
1972 }
jardineb5d44e2003-12-23 08:09:43 +00001973
1974 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1975}
1976
jardineb5d44e2003-12-23 08:09:43 +00001977/*
jardineb5d44e2003-12-23 08:09:43 +00001978 * PDU Dispatcher
1979 */
1980
hasso92365882005-01-18 13:53:33 +00001981static int
hassof390d2c2004-09-10 20:48:21 +00001982isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001983{
jardineb5d44e2003-12-23 08:09:43 +00001984 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00001985
hassof390d2c2004-09-10 20:48:21 +00001986 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001987
1988 /*
1989 * Let's first read data from stream to the header
1990 */
hassof390d2c2004-09-10 20:48:21 +00001991 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001992
hassof390d2c2004-09-10 20:48:21 +00001993 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1994 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001995 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00001996 return ISIS_ERROR;
1997 }
jardineb5d44e2003-12-23 08:09:43 +00001998
1999 /* now we need to know if this is an ISO 9542 packet and
2000 * take real good care of it, waaa!
2001 */
hassof390d2c2004-09-10 20:48:21 +00002002 if (hdr->idrp == ISO9542_ESIS)
2003 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002004 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
2005 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002006 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002007 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
2008
jardineb5d44e2003-12-23 08:09:43 +00002009 /*
2010 * and then process it
2011 */
2012
hassof390d2c2004-09-10 20:48:21 +00002013 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
2014 {
2015 zlog_err ("Fixed header length = %d", hdr->length);
2016 return ISIS_ERROR;
2017 }
jardineb5d44e2003-12-23 08:09:43 +00002018
hassof390d2c2004-09-10 20:48:21 +00002019 if (hdr->version1 != 1)
2020 {
2021 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
2022 return ISIS_WARNING;
2023 }
jardineb5d44e2003-12-23 08:09:43 +00002024 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002025 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2026 {
2027 zlog_err
2028 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2029 "while the parameter for this IS is %u", hdr->id_len,
2030 ISIS_SYS_ID_LEN);
2031 return ISIS_ERROR;
2032 }
jardineb5d44e2003-12-23 08:09:43 +00002033
hassof390d2c2004-09-10 20:48:21 +00002034 if (hdr->version2 != 1)
2035 {
2036 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2037 return ISIS_WARNING;
2038 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002039
2040 if (circuit->is_passive)
2041 {
2042 zlog_warn ("Received ISIS PDU on passive circuit %s",
2043 circuit->interface->name);
2044 return ISIS_WARNING;
2045 }
2046
jardineb5d44e2003-12-23 08:09:43 +00002047 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002048 if ((hdr->max_area_addrs != 0)
2049 && (hdr->max_area_addrs != isis->max_area_addrs))
2050 {
2051 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2052 "received PDU %u while the parameter for this IS is %u",
2053 hdr->max_area_addrs, isis->max_area_addrs);
2054 return ISIS_ERROR;
2055 }
jardineb5d44e2003-12-23 08:09:43 +00002056
hassof390d2c2004-09-10 20:48:21 +00002057 switch (hdr->pdu_type)
2058 {
2059 case L1_LAN_HELLO:
2060 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2061 break;
2062 case L2_LAN_HELLO:
2063 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2064 break;
2065 case P2P_HELLO:
2066 retval = process_p2p_hello (circuit);
2067 break;
2068 case L1_LINK_STATE:
2069 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2070 break;
2071 case L2_LINK_STATE:
2072 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2073 break;
2074 case L1_COMPLETE_SEQ_NUM:
2075 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2076 break;
2077 case L2_COMPLETE_SEQ_NUM:
2078 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2079 break;
2080 case L1_PARTIAL_SEQ_NUM:
2081 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2082 break;
2083 case L2_PARTIAL_SEQ_NUM:
2084 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2085 break;
2086 default:
2087 return ISIS_ERROR;
2088 }
jardineb5d44e2003-12-23 08:09:43 +00002089
2090 return retval;
2091}
2092
jardineb5d44e2003-12-23 08:09:43 +00002093#ifdef GNU_LINUX
2094int
2095isis_receive (struct thread *thread)
2096{
jardineb5d44e2003-12-23 08:09:43 +00002097 struct isis_circuit *circuit;
2098 u_char ssnpa[ETH_ALEN];
2099 int retval;
2100
2101 /*
2102 * Get the circuit
2103 */
2104 circuit = THREAD_ARG (thread);
2105 assert (circuit);
2106
2107 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002108 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002109 else
2110 stream_reset (circuit->rcv_stream);
2111
2112 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002113 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002114
2115 if (retval == ISIS_OK)
2116 retval = isis_handle_pdu (circuit, ssnpa);
2117
2118 /*
2119 * prepare for next packet.
2120 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002121 if (!circuit->is_passive)
2122 {
2123 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2124 circuit->fd);
2125 }
jardineb5d44e2003-12-23 08:09:43 +00002126
2127 return retval;
2128}
2129
2130#else
2131int
2132isis_receive (struct thread *thread)
2133{
jardineb5d44e2003-12-23 08:09:43 +00002134 struct isis_circuit *circuit;
2135 u_char ssnpa[ETH_ALEN];
2136 int retval;
2137
2138 /*
2139 * Get the circuit
2140 */
2141 circuit = THREAD_ARG (thread);
2142 assert (circuit);
2143
hassof390d2c2004-09-10 20:48:21 +00002144 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002145
2146 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002147 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002148 else
2149 stream_reset (circuit->rcv_stream);
2150
2151 retval = circuit->rx (circuit, ssnpa);
2152
2153 if (retval == ISIS_OK)
2154 retval = isis_handle_pdu (circuit, ssnpa);
2155
2156 /*
2157 * prepare for next packet.
2158 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002159 if (!circuit->is_passive)
2160 {
2161 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2162 listcount
2163 (circuit->area->circuit_list) *
2164 100);
2165 }
jardineb5d44e2003-12-23 08:09:43 +00002166
2167 return retval;
2168}
2169
2170#endif
2171
2172 /* filling of the fixed isis header */
2173void
2174fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2175{
2176 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2177
2178 hdr->idrp = ISO10589_ISIS;
2179
hassof390d2c2004-09-10 20:48:21 +00002180 switch (pdu_type)
2181 {
2182 case L1_LAN_HELLO:
2183 case L2_LAN_HELLO:
2184 hdr->length = ISIS_LANHELLO_HDRLEN;
2185 break;
2186 case P2P_HELLO:
2187 hdr->length = ISIS_P2PHELLO_HDRLEN;
2188 break;
2189 case L1_LINK_STATE:
2190 case L2_LINK_STATE:
2191 hdr->length = ISIS_LSP_HDR_LEN;
2192 break;
2193 case L1_COMPLETE_SEQ_NUM:
2194 case L2_COMPLETE_SEQ_NUM:
2195 hdr->length = ISIS_CSNP_HDRLEN;
2196 break;
2197 case L1_PARTIAL_SEQ_NUM:
2198 case L2_PARTIAL_SEQ_NUM:
2199 hdr->length = ISIS_PSNP_HDRLEN;
2200 break;
2201 default:
2202 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2203 return;
2204 }
jardineb5d44e2003-12-23 08:09:43 +00002205 hdr->length += ISIS_FIXED_HDR_LEN;
2206 hdr->pdu_type = pdu_type;
2207 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002208 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002209 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002210 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002211}
2212
jardineb5d44e2003-12-23 08:09:43 +00002213/*
2214 * SEND SIDE
2215 */
hasso92365882005-01-18 13:53:33 +00002216static void
jardineb5d44e2003-12-23 08:09:43 +00002217fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002218 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002219{
hassof390d2c2004-09-10 20:48:21 +00002220 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002221
2222 stream_putc (stream, hdr->idrp);
2223 stream_putc (stream, hdr->length);
2224 stream_putc (stream, hdr->version1);
2225 stream_putc (stream, hdr->id_len);
2226 stream_putc (stream, hdr->pdu_type);
2227 stream_putc (stream, hdr->version2);
2228 stream_putc (stream, hdr->reserved);
2229 stream_putc (stream, hdr->max_area_addrs);
2230
2231 return;
2232}
2233
jardineb5d44e2003-12-23 08:09:43 +00002234int
2235send_hello (struct isis_circuit *circuit, int level)
2236{
2237 struct isis_fixed_hdr fixed_hdr;
2238 struct isis_lan_hello_hdr hello_hdr;
2239 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002240 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
David Lamparter01da6172015-04-10 09:10:11 +02002241 size_t len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002242 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002243 int retval;
2244
Josh Bailey3f045a02012-03-24 08:35:20 -07002245 if (circuit->is_passive)
2246 return ISIS_OK;
2247
hassof390d2c2004-09-10 20:48:21 +00002248 if (circuit->interface->mtu == 0)
2249 {
2250 zlog_warn ("circuit has zero MTU");
2251 return ISIS_WARNING;
2252 }
jardineb5d44e2003-12-23 08:09:43 +00002253
2254 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002255 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002256 else
2257 stream_reset (circuit->snd_stream);
2258
2259 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002260 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002261 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2262 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002263 else
hassof390d2c2004-09-10 20:48:21 +00002264 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2265 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002266 else
hassof390d2c2004-09-10 20:48:21 +00002267 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002268
2269 /*
2270 * Fill LAN Level 1 or 2 Hello PDU header
2271 */
2272 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002273 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002274 circuit->hello_interval[level - 1];
2275 if (interval > USHRT_MAX)
2276 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002277 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002278 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002279 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002280
hassof390d2c2004-09-10 20:48:21 +00002281 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002282 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002283
2284 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002285 if (circuit->circ_type == CIRCUIT_T_P2P)
2286 {
2287 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2288 p2p_hello_hdr.local_id = circuit->circuit_id;
2289 /* FIXME: need better understanding */
2290 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002291 }
hassof390d2c2004-09-10 20:48:21 +00002292 else
2293 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002294 hello_hdr.prio = circuit->priority[level - 1];
2295 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002296 {
2297 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2298 ISIS_SYS_ID_LEN + 1);
2299 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002300 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002301 {
2302 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2303 ISIS_SYS_ID_LEN + 1);
2304 }
2305 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2306 }
jardineb5d44e2003-12-23 08:09:43 +00002307
2308 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002309 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002310 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002311
jardineb5d44e2003-12-23 08:09:43 +00002312 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002313 switch (circuit->passwd.type)
2314 {
2315 /* Cleartext */
2316 case ISIS_PASSWD_TYPE_CLEARTXT:
2317 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2318 circuit->passwd.passwd, circuit->snd_stream))
2319 return ISIS_WARNING;
2320 break;
2321
2322 /* HMAC MD5 */
2323 case ISIS_PASSWD_TYPE_HMAC_MD5:
2324 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2325 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2326 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2327 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2328 hmac_md5_hash, circuit->snd_stream))
2329 return ISIS_WARNING;
2330 break;
2331
2332 default:
2333 break;
2334 }
2335
jardineb5d44e2003-12-23 08:09:43 +00002336 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002337 if (listcount (circuit->area->area_addrs) == 0)
2338 return ISIS_WARNING;
2339 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2340 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002341
2342 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002343 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2344 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002345 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2346 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002347 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2348 circuit->snd_stream))
2349 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002350 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2351 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002352 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2353 circuit->snd_stream))
2354 return ISIS_WARNING;
2355 }
jardineb5d44e2003-12-23 08:09:43 +00002356
2357 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002358 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002359 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2360 return ISIS_WARNING;
2361 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002362 if (circuit->ip_router && circuit->ip_addrs &&
2363 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002364 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2365 return ISIS_WARNING;
2366
hassof390d2c2004-09-10 20:48:21 +00002367#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002368 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002369 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002370 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002371 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2372 return ISIS_WARNING;
2373#endif /* HAVE_IPV6 */
2374
Josh Bailey3f045a02012-03-24 08:35:20 -07002375 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002376 if (tlv_add_padding (circuit->snd_stream))
2377 return ISIS_WARNING;
2378
paul9985f832005-02-09 15:51:56 +00002379 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002380 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002381 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002382
Josh Bailey3f045a02012-03-24 08:35:20 -07002383 /* For HMAC MD5 we need to compute the md5 hash and store it */
2384 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2385 {
2386 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2387 stream_get_endp (circuit->snd_stream),
2388 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
David Lamparter21401f32015-03-03 08:55:26 +01002389 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002390 /* Copy the hash into the stream */
2391 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2392 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2393 }
jardineb5d44e2003-12-23 08:09:43 +00002394
hassof390d2c2004-09-10 20:48:21 +00002395 if (isis->debugs & DEBUG_ADJ_PACKETS)
2396 {
2397 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2398 {
David Lamparter01da6172015-04-10 09:10:11 +02002399 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002400 circuit->area->area_tag, level, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002401 length);
hassof390d2c2004-09-10 20:48:21 +00002402 }
2403 else
2404 {
David Lamparter01da6172015-04-10 09:10:11 +02002405 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002406 circuit->area->area_tag, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002407 length);
hassof390d2c2004-09-10 20:48:21 +00002408 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002409 if (isis->debugs & DEBUG_PACKET_DUMP)
2410 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2411 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002412 }
jardineb5d44e2003-12-23 08:09:43 +00002413
Josh Bailey3f045a02012-03-24 08:35:20 -07002414 retval = circuit->tx (circuit, level);
2415 if (retval != ISIS_OK)
2416 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2417 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002418
Josh Bailey3f045a02012-03-24 08:35:20 -07002419 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002420}
2421
2422int
2423send_lan_l1_hello (struct thread *thread)
2424{
jardineb5d44e2003-12-23 08:09:43 +00002425 struct isis_circuit *circuit;
2426 int retval;
2427
2428 circuit = THREAD_ARG (thread);
2429 assert (circuit);
2430 circuit->u.bc.t_send_lan_hello[0] = NULL;
2431
2432 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002433 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002434
Josh Bailey3f045a02012-03-24 08:35:20 -07002435 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002436
2437 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002438 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2439 send_lan_l1_hello, circuit,
2440 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002441
2442 return retval;
2443}
2444
2445int
2446send_lan_l2_hello (struct thread *thread)
2447{
2448 struct isis_circuit *circuit;
2449 int retval;
2450
2451 circuit = THREAD_ARG (thread);
2452 assert (circuit);
2453 circuit->u.bc.t_send_lan_hello[1] = NULL;
2454
2455 if (circuit->u.bc.run_dr_elect[1])
2456 retval = isis_dr_elect (circuit, 2);
2457
Josh Bailey3f045a02012-03-24 08:35:20 -07002458 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002459
hassof390d2c2004-09-10 20:48:21 +00002460 /* set next timer thread */
2461 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2462 send_lan_l2_hello, circuit,
2463 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002464
2465 return retval;
2466}
2467
2468int
2469send_p2p_hello (struct thread *thread)
2470{
2471 struct isis_circuit *circuit;
2472
2473 circuit = THREAD_ARG (thread);
2474 assert (circuit);
2475 circuit->u.p2p.t_send_p2p_hello = NULL;
2476
hassof390d2c2004-09-10 20:48:21 +00002477 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002478
hassof390d2c2004-09-10 20:48:21 +00002479 /* set next timer thread */
2480 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2481 circuit, isis_jitter (circuit->hello_interval[1],
2482 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002483
2484 return ISIS_OK;
2485}
2486
hasso92365882005-01-18 13:53:33 +00002487static int
hassof390d2c2004-09-10 20:48:21 +00002488build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2489 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002490{
2491 struct isis_fixed_hdr fixed_hdr;
2492 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002493 unsigned long lenp;
2494 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002495 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2496 unsigned long auth_tlv_offset = 0;
2497 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002498
Josh Bailey3f045a02012-03-24 08:35:20 -07002499 if (circuit->snd_stream == NULL)
2500 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2501 else
2502 stream_reset (circuit->snd_stream);
2503
2504 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002505 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2506 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002507 else
hassof390d2c2004-09-10 20:48:21 +00002508 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2509 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002510
2511 /*
2512 * Fill Level 1 or 2 Complete Sequence Numbers header
2513 */
2514
paul9985f832005-02-09 15:51:56 +00002515 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002516 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002517 /* no need to send the source here, it is always us if we csnp */
2518 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2519 /* with zero circuit id - ref 9.10, 9.11 */
2520 stream_putc (circuit->snd_stream, 0x00);
2521
2522 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2523 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2524
2525 /*
2526 * And TLVs
2527 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002528 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002529 passwd = &circuit->area->area_passwd;
2530 else
2531 passwd = &circuit->area->domain_passwd;
2532
hasso1cbc5622005-01-01 10:29:51 +00002533 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002534 {
2535 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002536 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002537 /* Cleartext */
2538 case ISIS_PASSWD_TYPE_CLEARTXT:
2539 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2540 passwd->passwd, circuit->snd_stream))
2541 return ISIS_WARNING;
2542 break;
2543
2544 /* HMAC MD5 */
2545 case ISIS_PASSWD_TYPE_HMAC_MD5:
2546 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2547 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2548 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2549 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2550 hmac_md5_hash, circuit->snd_stream))
2551 return ISIS_WARNING;
2552 break;
2553
2554 default:
2555 break;
hassof390d2c2004-09-10 20:48:21 +00002556 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002557 }
2558
2559 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2560 if (retval != ISIS_OK)
2561 return retval;
2562
paul9985f832005-02-09 15:51:56 +00002563 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002564 /* Update PU length */
2565 stream_putw_at (circuit->snd_stream, lenp, length);
2566
Josh Bailey3f045a02012-03-24 08:35:20 -07002567 /* For HMAC MD5 we need to compute the md5 hash and store it */
2568 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2569 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2570 {
2571 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2572 stream_get_endp(circuit->snd_stream),
2573 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002574 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002575 /* Copy the hash into the stream */
2576 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2577 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2578 }
2579
jardineb5d44e2003-12-23 08:09:43 +00002580 return retval;
2581}
2582
2583/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002584 * Count the maximum number of lsps that can be accomodated by a given size.
2585 */
2586static uint16_t
2587get_max_lsp_count (uint16_t size)
2588{
2589 uint16_t tlv_count;
2590 uint16_t lsp_count;
2591 uint16_t remaining_size;
2592
2593 /* First count the full size TLVs */
2594 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2595 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2596
2597 /* The last TLV, if any */
2598 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2599 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2600 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2601
2602 return lsp_count;
2603}
2604
2605/*
2606 * Calculate the length of Authentication Info. TLV.
2607 */
2608static uint16_t
2609auth_tlv_length (int level, struct isis_circuit *circuit)
2610{
2611 struct isis_passwd *passwd;
2612 uint16_t length;
2613
2614 if (level == IS_LEVEL_1)
2615 passwd = &circuit->area->area_passwd;
2616 else
2617 passwd = &circuit->area->domain_passwd;
2618
2619 /* Also include the length of TLV header */
2620 length = AUTH_INFO_HDRLEN;
2621 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2622 {
2623 switch (passwd->type)
2624 {
2625 /* Cleartext */
2626 case ISIS_PASSWD_TYPE_CLEARTXT:
2627 length += passwd->len;
2628 break;
2629
2630 /* HMAC MD5 */
2631 case ISIS_PASSWD_TYPE_HMAC_MD5:
2632 length += ISIS_AUTH_MD5_SIZE;
2633 break;
2634
2635 default:
2636 break;
2637 }
2638 }
2639
2640 return length;
2641}
2642
2643/*
2644 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2645 */
2646static uint16_t
2647max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2648{
2649 int snp_hdr_len;
2650 int auth_tlv_len;
2651 uint16_t lsp_count;
2652
2653 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2654 if (snp_type == ISIS_SNP_CSNP_FLAG)
2655 snp_hdr_len += ISIS_CSNP_HDRLEN;
2656 else
2657 snp_hdr_len += ISIS_PSNP_HDRLEN;
2658
2659 auth_tlv_len = auth_tlv_length (level, circuit);
2660 lsp_count = get_max_lsp_count (
2661 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002662 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002663}
2664
2665/*
jardineb5d44e2003-12-23 08:09:43 +00002666 * FIXME: support multiple CSNPs
2667 */
2668
2669int
2670send_csnp (struct isis_circuit *circuit, int level)
2671{
jardineb5d44e2003-12-23 08:09:43 +00002672 u_char start[ISIS_SYS_ID_LEN + 2];
2673 u_char stop[ISIS_SYS_ID_LEN + 2];
2674 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002675 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002676 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002677 u_char num_lsps, loop = 1;
2678 int i, retval = ISIS_OK;
2679
2680 if (circuit->area->lspdb[level - 1] == NULL ||
2681 dict_count (circuit->area->lspdb[level - 1]) == 0)
2682 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002683
hassof390d2c2004-09-10 20:48:21 +00002684 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002685 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2686
Josh Bailey3f045a02012-03-24 08:35:20 -07002687 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2688
2689 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002690 {
2691 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002692 lsp_build_list (start, stop, num_lsps, list,
2693 circuit->area->lspdb[level - 1]);
2694 /*
2695 * Update the stop lsp_id before encoding this CSNP.
2696 */
2697 if (listcount (list) < num_lsps)
2698 {
2699 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2700 }
hassof390d2c2004-09-10 20:48:21 +00002701 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002702 {
2703 node = listtail (list);
2704 lsp = listgetdata (node);
2705 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2706 }
jardineb5d44e2003-12-23 08:09:43 +00002707
hassof390d2c2004-09-10 20:48:21 +00002708 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002709 if (retval != ISIS_OK)
2710 {
2711 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2712 circuit->area->area_tag, level, circuit->interface->name);
2713 list_delete (list);
2714 return retval;
2715 }
jardineb5d44e2003-12-23 08:09:43 +00002716
hassof390d2c2004-09-10 20:48:21 +00002717 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002718 {
David Lamparter01da6172015-04-10 09:10:11 +02002719 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07002720 circuit->area->area_tag, level, circuit->interface->name,
2721 stream_get_endp (circuit->snd_stream));
2722 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2723 {
2724 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2725 " cksum 0x%04x, lifetime %us",
2726 circuit->area->area_tag,
2727 rawlspid_print (lsp->lsp_header->lsp_id),
2728 ntohl (lsp->lsp_header->seq_num),
2729 ntohs (lsp->lsp_header->checksum),
2730 ntohs (lsp->lsp_header->rem_lifetime));
2731 }
2732 if (isis->debugs & DEBUG_PACKET_DUMP)
2733 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2734 stream_get_endp (circuit->snd_stream));
2735 }
hassof390d2c2004-09-10 20:48:21 +00002736
Josh Bailey3f045a02012-03-24 08:35:20 -07002737 retval = circuit->tx (circuit, level);
2738 if (retval != ISIS_OK)
2739 {
2740 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2741 circuit->area->area_tag, level,
2742 circuit->interface->name);
2743 list_delete (list);
2744 return retval;
2745 }
2746
2747 /*
2748 * Start lsp_id of the next CSNP should be one plus the
2749 * stop lsp_id in this current CSNP.
2750 */
2751 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2752 loop = 0;
2753 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2754 {
2755 if (start[i] < (u_char)0xff)
2756 {
2757 start[i] += 1;
2758 loop = 1;
2759 break;
2760 }
2761 }
2762 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002763 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002764 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002765
jardineb5d44e2003-12-23 08:09:43 +00002766 return retval;
2767}
2768
2769int
2770send_l1_csnp (struct thread *thread)
2771{
2772 struct isis_circuit *circuit;
2773 int retval = ISIS_OK;
2774
2775 circuit = THREAD_ARG (thread);
2776 assert (circuit);
2777
2778 circuit->t_send_csnp[0] = NULL;
2779
hassof390d2c2004-09-10 20:48:21 +00002780 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2781 {
2782 send_csnp (circuit, 1);
2783 }
jardineb5d44e2003-12-23 08:09:43 +00002784 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002785 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2786 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002787
2788 return retval;
2789}
2790
2791int
2792send_l2_csnp (struct thread *thread)
2793{
2794 struct isis_circuit *circuit;
2795 int retval = ISIS_OK;
2796
2797 circuit = THREAD_ARG (thread);
2798 assert (circuit);
2799
2800 circuit->t_send_csnp[1] = NULL;
2801
hassof390d2c2004-09-10 20:48:21 +00002802 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2803 {
2804 send_csnp (circuit, 2);
2805 }
jardineb5d44e2003-12-23 08:09:43 +00002806 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002807 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2808 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002809
jardineb5d44e2003-12-23 08:09:43 +00002810 return retval;
2811}
2812
hasso92365882005-01-18 13:53:33 +00002813static int
jardineb5d44e2003-12-23 08:09:43 +00002814build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2815{
2816 struct isis_fixed_hdr fixed_hdr;
2817 unsigned long lenp;
2818 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002819 struct isis_lsp *lsp;
2820 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002821 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002822 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2823 unsigned long auth_tlv_offset = 0;
2824 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002825
Josh Bailey3f045a02012-03-24 08:35:20 -07002826 if (circuit->snd_stream == NULL)
2827 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2828 else
2829 stream_reset (circuit->snd_stream);
2830
2831 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002832 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2833 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002834 else
2835 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002836 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002837
2838 /*
2839 * Fill Level 1 or 2 Partial Sequence Numbers header
2840 */
paul9985f832005-02-09 15:51:56 +00002841 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002842 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002843 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2844 stream_putc (circuit->snd_stream, circuit->idx);
2845
2846 /*
2847 * And TLVs
2848 */
2849
Josh Bailey3f045a02012-03-24 08:35:20 -07002850 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002851 passwd = &circuit->area->area_passwd;
2852 else
2853 passwd = &circuit->area->domain_passwd;
2854
hasso1cbc5622005-01-01 10:29:51 +00002855 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002856 {
2857 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002858 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002859 /* Cleartext */
2860 case ISIS_PASSWD_TYPE_CLEARTXT:
2861 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2862 passwd->passwd, circuit->snd_stream))
2863 return ISIS_WARNING;
2864 break;
2865
2866 /* HMAC MD5 */
2867 case ISIS_PASSWD_TYPE_HMAC_MD5:
2868 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2869 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2870 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2871 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2872 hmac_md5_hash, circuit->snd_stream))
2873 return ISIS_WARNING;
2874 break;
2875
2876 default:
2877 break;
jardineb5d44e2003-12-23 08:09:43 +00002878 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002879 }
2880
2881 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2882 if (retval != ISIS_OK)
2883 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002884
hassof390d2c2004-09-10 20:48:21 +00002885 if (isis->debugs & DEBUG_SNP_PACKETS)
2886 {
hasso3fdb2dd2005-09-28 18:45:54 +00002887 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002888 {
hasso529d65b2004-12-24 00:14:50 +00002889 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2890 " cksum 0x%04x, lifetime %us",
2891 circuit->area->area_tag,
2892 rawlspid_print (lsp->lsp_header->lsp_id),
2893 ntohl (lsp->lsp_header->seq_num),
2894 ntohs (lsp->lsp_header->checksum),
2895 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002896 }
2897 }
2898
paul9985f832005-02-09 15:51:56 +00002899 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002900 /* Update PDU length */
2901 stream_putw_at (circuit->snd_stream, lenp, length);
2902
Josh Bailey3f045a02012-03-24 08:35:20 -07002903 /* For HMAC MD5 we need to compute the md5 hash and store it */
2904 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2905 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2906 {
2907 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2908 stream_get_endp(circuit->snd_stream),
2909 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002910 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002911 /* Copy the hash into the stream */
2912 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2913 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2914 }
2915
jardineb5d44e2003-12-23 08:09:43 +00002916 return ISIS_OK;
2917}
2918
2919/*
2920 * 7.3.15.4 action on expiration of partial SNP interval
2921 * level 1
2922 */
hasso92365882005-01-18 13:53:33 +00002923static int
jardineb5d44e2003-12-23 08:09:43 +00002924send_psnp (int level, struct isis_circuit *circuit)
2925{
jardineb5d44e2003-12-23 08:09:43 +00002926 struct isis_lsp *lsp;
2927 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002928 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002929 u_char num_lsps;
2930 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002931
Josh Bailey3f045a02012-03-24 08:35:20 -07002932 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2933 circuit->u.bc.is_dr[level - 1])
2934 return ISIS_OK;
2935
2936 if (circuit->area->lspdb[level - 1] == NULL ||
2937 dict_count (circuit->area->lspdb[level - 1]) == 0)
2938 return ISIS_OK;
2939
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002940 if (! circuit->snd_stream)
2941 return ISIS_ERROR;
2942
Josh Bailey3f045a02012-03-24 08:35:20 -07002943 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2944
2945 while (1)
hassof390d2c2004-09-10 20:48:21 +00002946 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002947 list = list_new ();
2948 lsp_build_list_ssn (circuit, num_lsps, list,
2949 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002950
Josh Bailey3f045a02012-03-24 08:35:20 -07002951 if (listcount (list) == 0)
2952 {
2953 list_delete (list);
2954 return ISIS_OK;
2955 }
jardineb5d44e2003-12-23 08:09:43 +00002956
Josh Bailey3f045a02012-03-24 08:35:20 -07002957 retval = build_psnp (level, circuit, list);
2958 if (retval != ISIS_OK)
2959 {
2960 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2961 circuit->area->area_tag, level, circuit->interface->name);
2962 list_delete (list);
2963 return retval;
2964 }
jardineb5d44e2003-12-23 08:09:43 +00002965
Josh Bailey3f045a02012-03-24 08:35:20 -07002966 if (isis->debugs & DEBUG_SNP_PACKETS)
2967 {
David Lamparter01da6172015-04-10 09:10:11 +02002968 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07002969 circuit->area->area_tag, level,
2970 circuit->interface->name,
2971 stream_get_endp (circuit->snd_stream));
2972 if (isis->debugs & DEBUG_PACKET_DUMP)
2973 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2974 stream_get_endp (circuit->snd_stream));
2975 }
jardineb5d44e2003-12-23 08:09:43 +00002976
Josh Bailey3f045a02012-03-24 08:35:20 -07002977 retval = circuit->tx (circuit, level);
2978 if (retval != ISIS_OK)
2979 {
2980 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2981 circuit->area->area_tag, level,
2982 circuit->interface->name);
2983 list_delete (list);
2984 return retval;
2985 }
jardineb5d44e2003-12-23 08:09:43 +00002986
Josh Bailey3f045a02012-03-24 08:35:20 -07002987 /*
2988 * sending succeeded, we can clear SSN flags of this circuit
2989 * for the LSPs in list
2990 */
2991 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2992 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2993 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002994 }
jardineb5d44e2003-12-23 08:09:43 +00002995
2996 return retval;
2997}
2998
2999int
3000send_l1_psnp (struct thread *thread)
3001{
3002
3003 struct isis_circuit *circuit;
3004 int retval = ISIS_OK;
3005
3006 circuit = THREAD_ARG (thread);
3007 assert (circuit);
3008
3009 circuit->t_send_psnp[0] = NULL;
3010
3011 send_psnp (1, circuit);
3012 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003013 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
3014 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003015
3016 return retval;
3017}
3018
3019/*
3020 * 7.3.15.4 action on expiration of partial SNP interval
3021 * level 2
3022 */
3023int
3024send_l2_psnp (struct thread *thread)
3025{
jardineb5d44e2003-12-23 08:09:43 +00003026 struct isis_circuit *circuit;
3027 int retval = ISIS_OK;
3028
3029 circuit = THREAD_ARG (thread);
3030 assert (circuit);
3031
3032 circuit->t_send_psnp[1] = NULL;
3033
3034 send_psnp (2, circuit);
3035
3036 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003037 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3038 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003039
3040 return retval;
3041}
3042
jardineb5d44e2003-12-23 08:09:43 +00003043/*
3044 * ISO 10589 - 7.3.14.3
3045 */
3046int
3047send_lsp (struct thread *thread)
3048{
3049 struct isis_circuit *circuit;
3050 struct isis_lsp *lsp;
3051 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003052 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003053
3054 circuit = THREAD_ARG (thread);
3055 assert (circuit);
3056
Josh Bailey3f045a02012-03-24 08:35:20 -07003057 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3058 {
3059 return retval;
3060 }
3061
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003062 node = listhead (circuit->lsp_queue);
3063
3064 /*
3065 * Handle case where there are no LSPs on the queue. This can
3066 * happen, for instance, if an adjacency goes down before this
3067 * thread gets a chance to run.
3068 */
3069 if (!node)
3070 {
3071 return retval;
3072 }
3073
3074 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003075
3076 /*
3077 * Do not send if levels do not match
3078 */
3079 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003080 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003081 list_delete_node (circuit->lsp_queue, node);
3082 return retval;
hassof390d2c2004-09-10 20:48:21 +00003083 }
jardineb5d44e2003-12-23 08:09:43 +00003084
Josh Bailey3f045a02012-03-24 08:35:20 -07003085 /*
3086 * Do not send if we do not have adjacencies in state up on the circuit
3087 */
3088 if (circuit->upadjcount[lsp->level - 1] == 0)
3089 {
3090 list_delete_node (circuit->lsp_queue, node);
3091 return retval;
3092 }
3093
3094 /* copy our lsp to the send buffer */
3095 stream_copy (circuit->snd_stream, lsp->pdu);
3096
3097 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3098 {
3099 zlog_debug
3100 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3101 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3102 rawlspid_print (lsp->lsp_header->lsp_id),
3103 ntohl (lsp->lsp_header->seq_num),
3104 ntohs (lsp->lsp_header->checksum),
3105 ntohs (lsp->lsp_header->rem_lifetime),
3106 circuit->interface->name);
3107 if (isis->debugs & DEBUG_PACKET_DUMP)
3108 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3109 stream_get_endp (circuit->snd_stream));
3110 }
3111
3112 retval = circuit->tx (circuit, lsp->level);
3113 if (retval != ISIS_OK)
3114 {
3115 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3116 circuit->area->area_tag, lsp->level,
3117 circuit->interface->name);
3118 return retval;
3119 }
3120
3121 /*
3122 * If the sending succeeded, we can del the lsp from circuits
3123 * lsp_queue
3124 */
3125 list_delete_node (circuit->lsp_queue, node);
3126
3127 /* Set the last-cleared time if the queue is empty. */
3128 /* TODO: Is is possible that new lsps keep being added to the queue
3129 * that the queue is never empty? */
3130 if (list_isempty (circuit->lsp_queue))
3131 circuit->lsp_queue_last_cleared = time (NULL);
3132
3133 /*
3134 * On broadcast circuits also the SRMflag can be cleared
3135 */
3136 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3137 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3138
jardineb5d44e2003-12-23 08:09:43 +00003139 return retval;
hassof390d2c2004-09-10 20:48:21 +00003140}
jardineb5d44e2003-12-23 08:09:43 +00003141
3142int
hassof390d2c2004-09-10 20:48:21 +00003143ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3144 int level)
jardineb5d44e2003-12-23 08:09:43 +00003145{
3146 unsigned long lenp;
3147 int retval;
3148 u_int16_t length;
3149 struct isis_fixed_hdr fixed_hdr;
3150
3151 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003152 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003153 else
3154 stream_reset (circuit->snd_stream);
3155
Josh Bailey3f045a02012-03-24 08:35:20 -07003156 // fill_llc_hdr (stream);
3157 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003158 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3159 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003160 else
hassof390d2c2004-09-10 20:48:21 +00003161 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3162 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003163
3164
paul9985f832005-02-09 15:51:56 +00003165 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003166 stream_putw (circuit->snd_stream, 0); /* PDU length */
3167 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003168 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003169 stream_putc (circuit->snd_stream, 9); /* code */
3170 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003171
hassof390d2c2004-09-10 20:48:21 +00003172 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3173 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3174 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3175 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003176
paul9985f832005-02-09 15:51:56 +00003177 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003178 /* Update PDU length */
3179 stream_putw_at (circuit->snd_stream, lenp, length);
3180
3181 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003182 if (retval != ISIS_OK)
3183 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3184 circuit->area->area_tag, level,
3185 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003186
3187 return retval;
3188}