blob: 1dfb4623f67cadeaf5b593232b3d7856c71aee39 [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"
Olivier Dugeon4f593572016-04-19 19:03:05 +020056#include "isisd/isis_te.h"
jardineb5d44e2003-12-23 08:09:43 +000057
jardineb5d44e2003-12-23 08:09:43 +000058#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000059#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000060
61#ifndef PNBBY
62#define PNBBY 8
63#endif /* PNBBY */
64
65/* Utility mask array. */
Stephen Hemminger88d37b92014-11-03 01:20:09 +000066static const u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000067 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
68};
69
70/*
71 * HELPER FUNCS
72 */
73
74/*
75 * Compares two sets of area addresses
76 */
hassof390d2c2004-09-10 20:48:21 +000077static int
jardineb5d44e2003-12-23 08:09:43 +000078area_match (struct list *left, struct list *right)
79{
80 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000081 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000082
hasso3fdb2dd2005-09-28 18:45:54 +000083 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000084 {
hasso3fdb2dd2005-09-28 18:45:54 +000085 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000086 {
87 if (addr1->addr_len == addr2->addr_len &&
88 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
89 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000090 }
91 }
92
hassof390d2c2004-09-10 20:48:21 +000093 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000094}
95
96/*
97 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
98 * param ip1 the IS interface ip address structure
99 * param ip2 the IIH's ip address
100 * return 0 the IIH's IP is not in the IS's subnetwork
101 * 1 the IIH's IP is in the IS's subnetwork
102 */
hasso92365882005-01-18 13:53:33 +0000103static int
hassof390d2c2004-09-10 20:48:21 +0000104ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000105{
106 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000107 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000108 int len;
hassof390d2c2004-09-10 20:48:21 +0000109
110 addr1 = (u_char *) & ip1->prefix.s_addr;
111 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000112 len = ip1->prefixlen;
113
114 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000115 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000116
hasso53c997c2004-09-15 16:21:59 +0000117 while (offsetloop--)
118 if (addr1[offsetloop] != addr2[offsetloop])
119 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000120
hassof390d2c2004-09-10 20:48:21 +0000121 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000122 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
123 return 0;
hassof390d2c2004-09-10 20:48:21 +0000124
125 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000126}
127
jardineb5d44e2003-12-23 08:09:43 +0000128/*
129 * Compares two set of ip addresses
130 * param left the local interface's ip addresses
131 * param right the iih interface's ip address
132 * return 0 no match;
133 * 1 match;
134 */
hassof390d2c2004-09-10 20:48:21 +0000135static int
jardineb5d44e2003-12-23 08:09:43 +0000136ip_match (struct list *left, struct list *right)
137{
138 struct prefix_ipv4 *ip1;
139 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000140 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000141
hassoe082ac12004-09-27 18:13:57 +0000142 if ((left == NULL) || (right == NULL))
143 return 0;
144
hasso3fdb2dd2005-09-28 18:45:54 +0000145 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000146 {
hasso3fdb2dd2005-09-28 18:45:54 +0000147 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000148 {
149 if (ip_same_subnet (ip1, ip2))
150 {
151 return 1; /* match */
152 }
jardineb5d44e2003-12-23 08:09:43 +0000153 }
hassof390d2c2004-09-10 20:48:21 +0000154
jardineb5d44e2003-12-23 08:09:43 +0000155 }
156 return 0;
157}
158
159/*
160 * Checks whether we should accept a PDU of given level
161 */
162static int
163accept_level (int level, int circuit_t)
164{
hassof390d2c2004-09-10 20:48:21 +0000165 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000166
167 return retval;
168}
169
Josh Bailey3f045a02012-03-24 08:35:20 -0700170/*
171 * Verify authentication information
172 * Support cleartext and HMAC MD5 authentication
173 */
174static int
175authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
176 struct stream *stream, uint32_t auth_tlv_offset)
jardineb5d44e2003-12-23 08:09:43 +0000177{
Josh Bailey3f045a02012-03-24 08:35:20 -0700178 unsigned char digest[ISIS_AUTH_MD5_SIZE];
179
180 /* Auth fail () - passwd type mismatch */
181 if (local->type != remote->type)
182 return ISIS_ERROR;
183
184 switch (local->type)
185 {
186 /* No authentication required */
187 case ISIS_PASSWD_TYPE_UNUSED:
188 break;
189
190 /* Cleartext (ISO 10589) */
hassof390d2c2004-09-10 20:48:21 +0000191 case ISIS_PASSWD_TYPE_CLEARTXT:
Josh Bailey3f045a02012-03-24 08:35:20 -0700192 /* Auth fail () - passwd len mismatch */
193 if (remote->len != local->len)
194 return ISIS_ERROR;
195 return memcmp (local->passwd, remote->passwd, local->len);
196
197 /* HMAC MD5 (RFC 3567) */
198 case ISIS_PASSWD_TYPE_HMAC_MD5:
199 /* Auth fail () - passwd len mismatch */
200 if (remote->len != ISIS_AUTH_MD5_SIZE)
201 return ISIS_ERROR;
202 /* Set the authentication value to 0 before the check */
203 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
204 ISIS_AUTH_MD5_SIZE);
205 /* Compute the digest */
206 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
207 (unsigned char *) &(local->passwd), local->len,
David Lamparter21401f32015-03-03 08:55:26 +0100208 (unsigned char *) &digest);
Josh Bailey3f045a02012-03-24 08:35:20 -0700209 /* Copy back the authentication value after the check */
210 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
211 remote->passwd, ISIS_AUTH_MD5_SIZE);
212 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
213
hassof390d2c2004-09-10 20:48:21 +0000214 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700215 zlog_err ("Unsupported authentication type");
216 return ISIS_ERROR;
217 }
218
219 /* Authentication pass when no authentication is configured */
220 return ISIS_OK;
221}
222
223static int
224lsp_authentication_check (struct stream *stream, struct isis_area *area,
225 int level, struct isis_passwd *passwd)
226{
227 struct isis_link_state_hdr *hdr;
228 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700229 uint16_t checksum, rem_lifetime, pdu_len;
Josh Bailey3f045a02012-03-24 08:35:20 -0700230 struct tlvs tlvs;
231 int retval = ISIS_OK;
232
233 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700234 pdu_len = ntohs (hdr->pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700235 expected |= TLVFLAG_AUTH_INFO;
236 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
237 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700238 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
Josh Bailey3f045a02012-03-24 08:35:20 -0700239 &expected, &found, &tlvs, &auth_tlv_offset);
240
241 if (retval != ISIS_OK)
242 {
243 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
244 "cksum 0x%04x, lifetime %us, len %u",
245 area->area_tag, level, rawlspid_print (hdr->lsp_id),
246 ntohl (hdr->seq_num), ntohs (hdr->checksum),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700247 ntohs (hdr->rem_lifetime), pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700248 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
249 (isis->debugs & DEBUG_PACKET_DUMP))
250 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
251 return retval;
hassof390d2c2004-09-10 20:48:21 +0000252 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700253
254 if (!(found & TLVFLAG_AUTH_INFO))
255 {
256 zlog_err ("No authentication tlv in LSP");
257 return ISIS_ERROR;
258 }
259
260 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
261 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
262 {
263 zlog_err ("Unknown authentication type in LSP");
264 return ISIS_ERROR;
265 }
266
267 /*
268 * RFC 5304 set checksum and remaining lifetime to zero before
269 * verification and reset to old values after verification.
270 */
271 checksum = hdr->checksum;
272 rem_lifetime = hdr->rem_lifetime;
273 hdr->checksum = 0;
274 hdr->rem_lifetime = 0;
275 retval = authentication_check (&tlvs.auth_info, passwd, stream,
276 auth_tlv_offset);
277 hdr->checksum = checksum;
278 hdr->rem_lifetime = rem_lifetime;
279
280 return retval;
jardineb5d44e2003-12-23 08:09:43 +0000281}
282
283/*
284 * Processing helper functions
285 */
hasso92365882005-01-18 13:53:33 +0000286static void
Josh Bailey3f045a02012-03-24 08:35:20 -0700287del_addr (void *val)
288{
289 XFREE (MTYPE_ISIS_TMP, val);
290}
291
292static void
293tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
294{
295 struct listnode *node;
296 struct area_addr *area_addr, *malloced;
297
298 if (adj->area_addrs)
299 {
300 adj->area_addrs->del = del_addr;
301 list_delete (adj->area_addrs);
302 }
303 adj->area_addrs = list_new ();
304 if (tlvs->area_addrs)
305 {
306 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
307 {
308 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
309 memcpy (malloced, area_addr, sizeof (struct area_addr));
310 listnode_add (adj->area_addrs, malloced);
311 }
312 }
313}
314
David Lamparter655071f2012-05-08 13:32:53 +0200315static int
hassof390d2c2004-09-10 20:48:21 +0000316tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000317{
318 int i;
319 struct nlpids *tlv_nlpids;
320
hassof390d2c2004-09-10 20:48:21 +0000321 if (tlvs->nlpids)
322 {
jardineb5d44e2003-12-23 08:09:43 +0000323
hassof390d2c2004-09-10 20:48:21 +0000324 tlv_nlpids = tlvs->nlpids;
David Lamparter655071f2012-05-08 13:32:53 +0200325 if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
326 return 1;
jardineb5d44e2003-12-23 08:09:43 +0000327
hassof390d2c2004-09-10 20:48:21 +0000328 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000329
hassof390d2c2004-09-10 20:48:21 +0000330 for (i = 0; i < tlv_nlpids->count; i++)
331 {
332 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
333 }
jardineb5d44e2003-12-23 08:09:43 +0000334 }
David Lamparter655071f2012-05-08 13:32:53 +0200335 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000336}
337
hasso92365882005-01-18 13:53:33 +0000338static void
hassof390d2c2004-09-10 20:48:21 +0000339tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000340{
hasso3fdb2dd2005-09-28 18:45:54 +0000341 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000342 struct in_addr *ipv4_addr, *malloced;
343
hassof390d2c2004-09-10 20:48:21 +0000344 if (adj->ipv4_addrs)
345 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700346 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000347 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000348 }
hassof390d2c2004-09-10 20:48:21 +0000349 adj->ipv4_addrs = list_new ();
350 if (tlvs->ipv4_addrs)
351 {
hasso3fdb2dd2005-09-28 18:45:54 +0000352 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000353 {
354 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
355 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
356 listnode_add (adj->ipv4_addrs, malloced);
357 }
358 }
jardineb5d44e2003-12-23 08:09:43 +0000359}
360
361#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000362static void
hassof390d2c2004-09-10 20:48:21 +0000363tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000364{
hasso3fdb2dd2005-09-28 18:45:54 +0000365 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000366 struct in6_addr *ipv6_addr, *malloced;
367
hassof390d2c2004-09-10 20:48:21 +0000368 if (adj->ipv6_addrs)
369 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700370 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000371 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000372 }
hassof390d2c2004-09-10 20:48:21 +0000373 adj->ipv6_addrs = list_new ();
374 if (tlvs->ipv6_addrs)
375 {
hasso3fdb2dd2005-09-28 18:45:54 +0000376 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000377 {
378 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
379 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
380 listnode_add (adj->ipv6_addrs, malloced);
381 }
382 }
jardineb5d44e2003-12-23 08:09:43 +0000383
384}
385#endif /* HAVE_IPV6 */
386
jardineb5d44e2003-12-23 08:09:43 +0000387/*
388 * RECEIVE SIDE
389 */
390
391/*
392 * Process P2P IIH
393 * ISO - 10589
394 * Section 8.2.5 - Receiving point-to-point IIH PDUs
395 *
396 */
397static int
398process_p2p_hello (struct isis_circuit *circuit)
399{
400 int retval = ISIS_OK;
401 struct isis_p2p_hello_hdr *hdr;
402 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700403 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700404 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000405 struct tlvs tlvs;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200406 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000407
Josh Bailey3f045a02012-03-24 08:35:20 -0700408 if (isis->debugs & DEBUG_ADJ_PACKETS)
409 {
410 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
411 circuit->area->area_tag, circuit->interface->name,
412 circuit_t2string (circuit->is_type), circuit->circuit_id);
413 if (isis->debugs & DEBUG_PACKET_DUMP)
414 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
415 stream_get_endp (circuit->rcv_stream));
416 }
417
418 if (circuit->circ_type != CIRCUIT_T_P2P)
419 {
420 zlog_warn ("p2p hello on non p2p circuit");
421 return ISIS_WARNING;
422 }
423
hassof390d2c2004-09-10 20:48:21 +0000424 if ((stream_get_endp (circuit->rcv_stream) -
425 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
426 {
427 zlog_warn ("Packet too short");
428 return ISIS_WARNING;
429 }
jardineb5d44e2003-12-23 08:09:43 +0000430
431 /* 8.2.5.1 PDU acceptance tests */
432
433 /* 8.2.5.1 a) external domain untrue */
434 /* FIXME: not useful at all? */
435
436 /* 8.2.5.1 b) ID Length mismatch */
437 /* checked at the handle_pdu */
438
439 /* 8.2.5.2 IIH PDU Processing */
440
441 /* 8.2.5.2 a) 1) Maximum Area Addresses */
442 /* Already checked, and can also be ommited */
443
444 /*
445 * Get the header
446 */
hassof390d2c2004-09-10 20:48:21 +0000447 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700448 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000449
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700450 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
451 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700452 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000453 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700454 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
455 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700456 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700457 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000458 }
jardineb5d44e2003-12-23 08:09:43 +0000459
jardineb5d44e2003-12-23 08:09:43 +0000460 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700461 * Set the stream endp to PDU length, ignoring additional padding
462 * introduced by transport chips.
463 */
464 if (pdu_len < stream_get_endp (circuit->rcv_stream))
465 stream_set_endp (circuit->rcv_stream, pdu_len);
466
467 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
468
469 /*
jardineb5d44e2003-12-23 08:09:43 +0000470 * Lets get the TLVS now
471 */
472 expected |= TLVFLAG_AREA_ADDRS;
473 expected |= TLVFLAG_AUTH_INFO;
474 expected |= TLVFLAG_NLPID;
475 expected |= TLVFLAG_IPV4_ADDR;
476 expected |= TLVFLAG_IPV6_ADDR;
477
Josh Bailey3f045a02012-03-24 08:35:20 -0700478 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000479 retval = parse_tlvs (circuit->area->area_tag,
480 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700481 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
482 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000483
hassof390d2c2004-09-10 20:48:21 +0000484 if (retval > ISIS_WARNING)
485 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700486 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000487 free_tlvs (&tlvs);
488 return retval;
489 };
jardineb5d44e2003-12-23 08:09:43 +0000490
Josh Bailey3f045a02012-03-24 08:35:20 -0700491 if (!(found & TLVFLAG_AREA_ADDRS))
492 {
493 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
494 free_tlvs (&tlvs);
495 return ISIS_WARNING;
496 }
497
David Lamparterb72f3452012-11-27 01:10:26 +0000498 if (!(found & TLVFLAG_NLPID))
499 {
500 zlog_warn ("No supported protocols TLV in P2P IS to IS hello");
501 free_tlvs (&tlvs);
502 return ISIS_WARNING;
503 }
504
jardineb5d44e2003-12-23 08:09:43 +0000505 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000506 if (circuit->passwd.type)
507 {
508 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700509 authentication_check (&tlvs.auth_info, &circuit->passwd,
510 circuit->rcv_stream, auth_tlv_offset))
511 {
512 isis_event_auth_failure (circuit->area->area_tag,
513 "P2P hello authentication failure",
514 hdr->source_id);
515 free_tlvs (&tlvs);
516 return ISIS_OK;
517 }
jardineb5d44e2003-12-23 08:09:43 +0000518 }
jardineb5d44e2003-12-23 08:09:43 +0000519
Josh Bailey3f045a02012-03-24 08:35:20 -0700520 /*
521 * check if it's own interface ip match iih ip addrs
522 */
David Lamparter28a8cfc2014-06-29 13:48:18 +0200523 if (found & TLVFLAG_IPV4_ADDR)
Josh Bailey3f045a02012-03-24 08:35:20 -0700524 {
David Lamparter28a8cfc2014-06-29 13:48:18 +0200525 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
526 v4_usable = 1;
527 else
528 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
529 "in P2P IIH from %s\n", circuit->interface->name);
530 }
531#ifndef HAVE_IPV6
532 else /* !(found & TLVFLAG_IPV4_ADDR) */
533 zlog_warn ("ISIS-Adj: no IPv4 in P2P IIH from %s "
534 "(this isisd has no IPv6)\n", circuit->interface->name);
535
536#else
537 if (found & TLVFLAG_IPV6_ADDR)
538 {
539 /* TBA: check that we have a linklocal ourselves? */
540 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +0200541 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200542 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
543 if (IN6_IS_ADDR_LINKLOCAL (ip))
544 {
545 v6_usable = 1;
546 break;
547 }
548
549 if (!v6_usable)
550 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
551 "in P2P IIH from %s\n", circuit->interface->name);
552 }
553
554 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
555 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n",
556 circuit->interface->name);
557#endif
558
559 if (!v6_usable && !v4_usable)
560 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700561 free_tlvs (&tlvs);
562 return ISIS_WARNING;
563 }
564
565 /*
Amritha Nambiar491417a2015-04-23 15:36:55 -0700566 * it's own p2p IIH PDU - discard
567 */
568 if (!memcmp (hdr->source_id, isis->sysid, ISIS_SYS_ID_LEN))
569 {
570 zlog_warn ("ISIS-Adj (%s): it's own IIH PDU - discarded",
571 circuit->area->area_tag);
572 free_tlvs (&tlvs);
573 return ISIS_WARNING;
574 }
575
576 /*
Josh Bailey3f045a02012-03-24 08:35:20 -0700577 * My interpertation of the ISO, if no adj exists we will create one for
578 * the circuit
579 */
580 adj = circuit->u.p2p.neighbor;
Amritha Nambiar3c28aaf2015-01-28 18:09:30 +0000581 /* If an adjacency exists, check it is with the source of the hello
582 * packets */
583 if (adj)
584 {
585 if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
586 {
587 zlog_debug("hello source and adjacency do not match, set adj down\n");
588 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
589 return 0;
590 }
591 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700592 if (!adj || adj->level != hdr->circuit_t)
593 {
594 if (!adj)
595 {
596 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
597 if (adj == NULL)
598 return ISIS_ERROR;
599 }
600 else
601 {
602 adj->level = hdr->circuit_t;
603 }
604 circuit->u.p2p.neighbor = adj;
Amritha Nambiar06cc6552015-07-02 15:42:58 -0700605 /* Build lsp with the new neighbor entry when a new
606 * adjacency is formed. Set adjacency circuit type to
607 * IIH PDU header circuit type before lsp is regenerated
608 * when an adjacency is up. This will result in the new
609 * adjacency entry getting added to the lsp tlv neighbor list.
610 */
611 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700612 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
613 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
614 }
615
616 /* 8.2.6 Monitoring point-to-point adjacencies */
617 adj->hold_time = ntohs (hdr->hold_time);
618 adj->last_upd = time (NULL);
619
jardineb5d44e2003-12-23 08:09:43 +0000620 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700621 tlvs_to_adj_area_addrs (&tlvs, adj);
622
623 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +0000624 if (tlvs_to_adj_nlpids (&tlvs, adj))
625 {
626 free_tlvs (&tlvs);
627 return ISIS_WARNING;
628 }
jardineb5d44e2003-12-23 08:09:43 +0000629
630 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700631 if (found & TLVFLAG_IPV4_ADDR)
632 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000633
Olivier Dugeon4f593572016-04-19 19:03:05 +0200634 /* Update MPLS TE Remote IP address parameter if possible */
635 if (IS_MPLS_TE(isisMplsTE) && circuit->mtc && IS_CIRCUIT_TE(circuit->mtc))
636 if (adj->ipv4_addrs != NULL && listcount(adj->ipv4_addrs) != 0)
637 {
638 struct in_addr *ip_addr;
639 ip_addr = (struct in_addr *)listgetdata ((struct listnode *)listhead (adj->ipv4_addrs));
640 set_circuitparams_rmt_ipaddr (circuit->mtc, *ip_addr);
641 }
642
jardineb5d44e2003-12-23 08:09:43 +0000643#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700644 if (found & TLVFLAG_IPV6_ADDR)
645 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000646#endif /* HAVE_IPV6 */
647
648 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000649 THREAD_TIMER_OFF (adj->t_expire);
650 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
651 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000652
653 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000654 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
655 {
656 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
657 if (circuit->area->is_type == IS_LEVEL_1)
658 {
659 switch (hdr->circuit_t)
660 {
661 case IS_LEVEL_1:
662 case IS_LEVEL_1_AND_2:
663 if (adj->adj_state != ISIS_ADJ_UP)
664 {
665 /* (4) adj state up */
666 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
667 /* (5) adj usage level 1 */
668 adj->adj_usage = ISIS_ADJ_LEVEL1;
669 }
670 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
671 {
672 ; /* accept */
673 }
674 break;
675 case IS_LEVEL_2:
676 if (adj->adj_state != ISIS_ADJ_UP)
677 {
678 /* (7) reject - wrong system type event */
679 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700680 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000681 return ISIS_WARNING; /* Reject */
682 }
683 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
684 {
685 /* (6) down - wrong system */
686 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
687 }
688 break;
689 }
690 }
jardineb5d44e2003-12-23 08:09:43 +0000691
hassof390d2c2004-09-10 20:48:21 +0000692 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
693 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
694 {
695 switch (hdr->circuit_t)
696 {
697 case IS_LEVEL_1:
698 if (adj->adj_state != ISIS_ADJ_UP)
699 {
700 /* (6) adj state up */
701 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
702 /* (7) adj usage level 1 */
703 adj->adj_usage = ISIS_ADJ_LEVEL1;
704 }
705 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
706 {
707 ; /* accept */
708 }
709 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
710 (adj->adj_usage == ISIS_ADJ_LEVEL2))
711 {
712 /* (8) down - wrong system */
713 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
714 }
715 break;
716 case IS_LEVEL_2:
717 if (adj->adj_state != ISIS_ADJ_UP)
718 {
719 /* (6) adj state up */
720 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
721 /* (9) adj usage level 2 */
722 adj->adj_usage = ISIS_ADJ_LEVEL2;
723 }
724 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
725 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
726 {
727 /* (8) down - wrong system */
728 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
729 }
730 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
731 {
732 ; /* Accept */
733 }
734 break;
735 case IS_LEVEL_1_AND_2:
736 if (adj->adj_state != ISIS_ADJ_UP)
737 {
738 /* (6) adj state up */
739 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
740 /* (10) adj usage level 1 */
741 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
742 }
743 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
744 (adj->adj_usage == ISIS_ADJ_LEVEL2))
745 {
746 /* (8) down - wrong system */
747 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
748 }
749 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
750 {
751 ; /* Accept */
752 }
753 break;
754 }
755 }
jardineb5d44e2003-12-23 08:09:43 +0000756
hassof390d2c2004-09-10 20:48:21 +0000757 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
758 if (circuit->area->is_type == IS_LEVEL_2)
759 {
760 switch (hdr->circuit_t)
761 {
762 case IS_LEVEL_1:
763 if (adj->adj_state != ISIS_ADJ_UP)
764 {
765 /* (5) reject - wrong system type event */
766 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700767 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000768 return ISIS_WARNING; /* Reject */
769 }
770 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
771 (adj->adj_usage == ISIS_ADJ_LEVEL2))
772 {
773 /* (6) down - wrong system */
774 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
775 }
776 break;
777 case IS_LEVEL_1_AND_2:
778 case IS_LEVEL_2:
779 if (adj->adj_state != ISIS_ADJ_UP)
780 {
781 /* (7) adj state up */
782 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
783 /* (8) adj usage level 2 */
784 adj->adj_usage = ISIS_ADJ_LEVEL2;
785 }
786 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
787 {
788 /* (6) down - wrong system */
789 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
790 }
791 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
792 {
793 ; /* Accept */
794 }
795 break;
796 }
797 }
jardineb5d44e2003-12-23 08:09:43 +0000798 }
jardineb5d44e2003-12-23 08:09:43 +0000799 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700800 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000801 {
hassof390d2c2004-09-10 20:48:21 +0000802 if (circuit->area->is_type == IS_LEVEL_1)
803 {
804 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
805 if (adj->adj_state != ISIS_ADJ_UP)
806 {
807 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
808 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
809 }
810 else
811 {
812 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
813 "Down - Area Mismatch");
814 }
815 }
816 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
817 else
818 {
819 switch (hdr->circuit_t)
820 {
821 case IS_LEVEL_1:
822 if (adj->adj_state != ISIS_ADJ_UP)
823 {
824 /* (6) reject - Area Mismatch event */
825 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700826 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000827 return ISIS_WARNING; /* Reject */
828 }
829 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
830 {
831 /* (7) down - area mismatch */
832 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000833
hassof390d2c2004-09-10 20:48:21 +0000834 }
835 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
836 (adj->adj_usage == ISIS_ADJ_LEVEL2))
837 {
838 /* (7) down - wrong system */
839 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
840 }
841 break;
842 case IS_LEVEL_1_AND_2:
843 case IS_LEVEL_2:
844 if (adj->adj_state != ISIS_ADJ_UP)
845 {
846 /* (8) adj state up */
847 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
848 /* (9) adj usage level 2 */
849 adj->adj_usage = ISIS_ADJ_LEVEL2;
850 }
851 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
852 {
853 /* (7) down - wrong system */
854 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
855 }
856 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
857 {
858 if (hdr->circuit_t == IS_LEVEL_2)
859 {
860 /* (7) down - wrong system */
861 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
862 "Wrong System");
863 }
864 else
865 {
866 /* (7) down - area mismatch */
867 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
868 "Area Mismatch");
869 }
870 }
871 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
872 {
873 ; /* Accept */
874 }
875 break;
876 }
877 }
jardineb5d44e2003-12-23 08:09:43 +0000878 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700879 else
880 {
881 /* down - area mismatch */
882 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
883 }
jardineb5d44e2003-12-23 08:09:43 +0000884 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
885 /* FIXME - Missing parts */
886
jardineb5d44e2003-12-23 08:09:43 +0000887 /* some of my own understanding of the ISO, why the heck does
888 * it not say what should I change the system_type to...
889 */
hassof390d2c2004-09-10 20:48:21 +0000890 switch (adj->adj_usage)
891 {
jardineb5d44e2003-12-23 08:09:43 +0000892 case ISIS_ADJ_LEVEL1:
893 adj->sys_type = ISIS_SYSTYPE_L1_IS;
894 break;
895 case ISIS_ADJ_LEVEL2:
896 adj->sys_type = ISIS_SYSTYPE_L2_IS;
897 break;
898 case ISIS_ADJ_LEVEL1AND2:
899 adj->sys_type = ISIS_SYSTYPE_L2_IS;
900 break;
901 case ISIS_ADJ_NONE:
902 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
903 break;
hassof390d2c2004-09-10 20:48:21 +0000904 }
jardineb5d44e2003-12-23 08:09:43 +0000905
Josh Bailey3f045a02012-03-24 08:35:20 -0700906
907 if (isis->debugs & DEBUG_ADJ_PACKETS)
908 {
909 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
910 " cir id %02d, length %d",
911 circuit->area->area_tag, circuit->interface->name,
912 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700913 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700914 }
jardineb5d44e2003-12-23 08:09:43 +0000915
916 free_tlvs (&tlvs);
917
918 return retval;
919}
920
jardineb5d44e2003-12-23 08:09:43 +0000921/*
922 * Process IS-IS LAN Level 1/2 Hello PDU
923 */
hassof390d2c2004-09-10 20:48:21 +0000924static int
Christian Franke77277a12015-11-10 18:04:43 +0100925process_lan_hello (int level, struct isis_circuit *circuit, const u_char *ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000926{
927 int retval = ISIS_OK;
928 struct isis_lan_hello_hdr hdr;
929 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700930 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000931 struct tlvs tlvs;
932 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000933 struct listnode *node;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200934 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000935
Josh Bailey3f045a02012-03-24 08:35:20 -0700936 if (isis->debugs & DEBUG_ADJ_PACKETS)
937 {
938 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
939 "cirID %u",
940 circuit->area->area_tag, level, circuit->interface->name,
941 circuit_t2string (circuit->is_type), circuit->circuit_id);
942 if (isis->debugs & DEBUG_PACKET_DUMP)
943 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
944 stream_get_endp (circuit->rcv_stream));
945 }
946
947 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
948 {
949 zlog_warn ("lan hello on non broadcast circuit");
950 return ISIS_WARNING;
951 }
952
hassof390d2c2004-09-10 20:48:21 +0000953 if ((stream_get_endp (circuit->rcv_stream) -
954 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
955 {
956 zlog_warn ("Packet too short");
957 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000958 }
hassof390d2c2004-09-10 20:48:21 +0000959
960 if (circuit->ext_domain)
961 {
hasso529d65b2004-12-24 00:14:50 +0000962 zlog_debug ("level %d LAN Hello received over circuit with "
963 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000964 return ISIS_WARNING;
965 }
966
Josh Bailey3f045a02012-03-24 08:35:20 -0700967 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000968 {
969 if (isis->debugs & DEBUG_ADJ_PACKETS)
970 {
hasso529d65b2004-12-24 00:14:50 +0000971 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
972 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000973 }
974 return ISIS_WARNING;
975 }
jardineb5d44e2003-12-23 08:09:43 +0000976
977#if 0
978 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000979 if (!accept_level (level, circuit->area->is_type))
980 {
981 if (isis->debugs & DEBUG_ADJ_PACKETS)
982 {
hasso529d65b2004-12-24 00:14:50 +0000983 zlog_debug ("ISIS-Adj (%s): is type mismatch",
984 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000985 }
986 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000987 }
jardineb5d44e2003-12-23 08:09:43 +0000988#endif
989 /*
990 * Fill the header
991 */
992 hdr.circuit_t = stream_getc (circuit->rcv_stream);
993 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
994 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000995 hdr.pdu_len = stream_getw (circuit->rcv_stream);
996 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000997 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
998
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700999 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
1000 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001001 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001002 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001003 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
1004 "invalid pdu length %d",
1005 circuit->area->area_tag, circuit->interface->name,
1006 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001007 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07001008 }
1009
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001010 /*
1011 * Set the stream endp to PDU length, ignoring additional padding
1012 * introduced by transport chips.
1013 */
1014 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
1015 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
1016
Josh Bailey3f045a02012-03-24 08:35:20 -07001017 if (hdr.circuit_t != IS_LEVEL_1 &&
1018 hdr.circuit_t != IS_LEVEL_2 &&
1019 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
1020 (level & hdr.circuit_t) == 0)
1021 {
1022 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
1023 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +00001024 return ISIS_ERROR;
1025 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001026
jardineb5d44e2003-12-23 08:09:43 +00001027 /*
1028 * Then get the tlvs
1029 */
1030 expected |= TLVFLAG_AUTH_INFO;
1031 expected |= TLVFLAG_AREA_ADDRS;
1032 expected |= TLVFLAG_LAN_NEIGHS;
1033 expected |= TLVFLAG_NLPID;
1034 expected |= TLVFLAG_IPV4_ADDR;
1035 expected |= TLVFLAG_IPV6_ADDR;
1036
Josh Bailey3f045a02012-03-24 08:35:20 -07001037 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001038 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -07001039 STREAM_PNT (circuit->rcv_stream),
1040 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
1041 &expected, &found, &tlvs,
1042 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001043
hassof390d2c2004-09-10 20:48:21 +00001044 if (retval > ISIS_WARNING)
1045 {
1046 zlog_warn ("parse_tlvs() failed");
1047 goto out;
1048 }
jardineb5d44e2003-12-23 08:09:43 +00001049
hassof390d2c2004-09-10 20:48:21 +00001050 if (!(found & TLVFLAG_AREA_ADDRS))
1051 {
1052 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
1053 level);
jardineb5d44e2003-12-23 08:09:43 +00001054 retval = ISIS_WARNING;
1055 goto out;
1056 }
hassof390d2c2004-09-10 20:48:21 +00001057
David Lamparterb72f3452012-11-27 01:10:26 +00001058 if (!(found & TLVFLAG_NLPID))
1059 {
1060 zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
1061 level);
1062 retval = ISIS_WARNING;
1063 goto out;
1064 }
1065
Josh Bailey3f045a02012-03-24 08:35:20 -07001066 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +00001067 if (circuit->passwd.type)
1068 {
1069 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001070 authentication_check (&tlvs.auth_info, &circuit->passwd,
1071 circuit->rcv_stream, auth_tlv_offset))
1072 {
1073 isis_event_auth_failure (circuit->area->area_tag,
1074 "LAN hello authentication failure",
1075 hdr.source_id);
1076 retval = ISIS_WARNING;
1077 goto out;
1078 }
hassof390d2c2004-09-10 20:48:21 +00001079 }
jardineb5d44e2003-12-23 08:09:43 +00001080
David Lamparter19f78ce2012-11-27 01:10:25 +00001081 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
1082 {
1083 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
1084 circuit->area->area_tag, circuit->interface->name);
1085 return ISIS_WARNING;
1086 }
1087
jardineb5d44e2003-12-23 08:09:43 +00001088 /*
1089 * Accept the level 1 adjacency only if a match between local and
1090 * remote area addresses is found
1091 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001092 if (listcount (circuit->area->area_addrs) == 0 ||
1093 (level == IS_LEVEL_1 &&
1094 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +00001095 {
1096 if (isis->debugs & DEBUG_ADJ_PACKETS)
1097 {
hasso529d65b2004-12-24 00:14:50 +00001098 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1099 circuit->area->area_tag, level,
1100 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001101 }
1102 retval = ISIS_OK;
1103 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001104 }
jardineb5d44e2003-12-23 08:09:43 +00001105
1106 /*
1107 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001108 */
1109 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1110 {
hasso529d65b2004-12-24 00:14:50 +00001111 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1112 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001113
hassof390d2c2004-09-10 20:48:21 +00001114 retval = ISIS_OK;
1115 goto out;
1116 }
jardineb5d44e2003-12-23 08:09:43 +00001117
1118 /*
1119 * check if it's own interface ip match iih ip addrs
1120 */
David Lamparter28a8cfc2014-06-29 13:48:18 +02001121 if (found & TLVFLAG_IPV4_ADDR)
hassof390d2c2004-09-10 20:48:21 +00001122 {
David Lamparter28a8cfc2014-06-29 13:48:18 +02001123 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
1124 v4_usable = 1;
1125 else
1126 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
1127 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001128 }
David Lamparter28a8cfc2014-06-29 13:48:18 +02001129#ifndef HAVE_IPV6
1130 else /* !(found & TLVFLAG_IPV4_ADDR) */
1131 zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s "
1132 "(this isisd has no IPv6)\n", circuit->interface->name);
1133
1134#else
1135 if (found & TLVFLAG_IPV6_ADDR)
1136 {
1137 /* TBA: check that we have a linklocal ourselves? */
1138 struct listnode *node;
David Lamparterad2f92b2014-08-18 18:05:25 +02001139 struct in6_addr *ip;
David Lamparter28a8cfc2014-06-29 13:48:18 +02001140 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
1141 if (IN6_IS_ADDR_LINKLOCAL (ip))
1142 {
1143 v6_usable = 1;
1144 break;
1145 }
1146
1147 if (!v6_usable)
1148 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
1149 "in LAN IIH from %s\n", circuit->interface->name);
1150 }
1151
1152 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
1153 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
1154 circuit->interface->name);
1155#endif
1156
1157 if (!v6_usable && !v4_usable)
1158 {
1159 free_tlvs (&tlvs);
1160 return ISIS_WARNING;
1161 }
1162
jardineb5d44e2003-12-23 08:09:43 +00001163
1164 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001165 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1166 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001167 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001168 if (!adj)
1169 {
1170 /*
1171 * Do as in 8.4.2.5
1172 */
1173 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1174 if (adj == NULL)
1175 {
1176 retval = ISIS_ERROR;
1177 goto out;
1178 }
1179 }
1180 else
1181 {
1182 if (ssnpa) {
1183 memcpy (adj->snpa, ssnpa, 6);
1184 } else {
1185 memset (adj->snpa, ' ', 6);
1186 }
1187 adj->level = level;
1188 }
hassof390d2c2004-09-10 20:48:21 +00001189 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001190
Josh Bailey3f045a02012-03-24 08:35:20 -07001191 if (level == IS_LEVEL_1)
1192 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001193 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001194 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001195 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1196 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001197 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001198 }
jardineb5d44e2003-12-23 08:09:43 +00001199
hassoa211d652004-09-20 14:55:29 +00001200 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1201 switch (level)
1202 {
1203 case 1:
1204 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1205 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001206 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001207 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1208 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001209 }
1210 break;
1211 case 2:
1212 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1213 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001214 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001215 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1216 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001217 }
1218 break;
1219 }
jardineb5d44e2003-12-23 08:09:43 +00001220
1221 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001222 adj->last_upd = time (NULL);
1223 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001224
1225 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1226
Josh Bailey3f045a02012-03-24 08:35:20 -07001227 tlvs_to_adj_area_addrs (&tlvs, adj);
1228
jardineb5d44e2003-12-23 08:09:43 +00001229 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +00001230 if (tlvs_to_adj_nlpids (&tlvs, adj))
1231 {
1232 retval = ISIS_WARNING;
1233 goto out;
1234 }
jardineb5d44e2003-12-23 08:09:43 +00001235
1236 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001237 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001238 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1239
1240#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001241 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001242 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1243#endif /* HAVE_IPV6 */
1244
1245 adj->circuit_t = hdr.circuit_t;
1246
1247 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001248 THREAD_TIMER_OFF (adj->t_expire);
1249 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001250 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001251
1252 /*
1253 * If the snpa for this circuit is found from LAN Neighbours TLV
1254 * we have two-way communication -> adjacency can be put to state "up"
1255 */
1256
hassof390d2c2004-09-10 20:48:21 +00001257 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001258 {
1259 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001260 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001261 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1262 {
1263 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1264 {
1265 isis_adj_state_change (adj, ISIS_ADJ_UP,
1266 "own SNPA found in LAN Neighbours TLV");
1267 }
1268 }
jardineb5d44e2003-12-23 08:09:43 +00001269 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001270 else
1271 {
1272 int found = 0;
1273 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1274 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1275 {
1276 found = 1;
1277 break;
1278 }
1279 if (found == 0)
1280 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1281 "own SNPA not found in LAN Neighbours TLV");
1282 }
1283 }
1284 else if (adj->adj_state == ISIS_ADJ_UP)
1285 {
1286 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1287 "no LAN Neighbours TLV found");
1288 }
jardineb5d44e2003-12-23 08:09:43 +00001289
hassof390d2c2004-09-10 20:48:21 +00001290out:
hassof390d2c2004-09-10 20:48:21 +00001291 if (isis->debugs & DEBUG_ADJ_PACKETS)
1292 {
hasso529d65b2004-12-24 00:14:50 +00001293 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
David Lamparter01da6172015-04-10 09:10:11 +02001294 "cirID %u, length %zd",
hasso529d65b2004-12-24 00:14:50 +00001295 circuit->area->area_tag,
1296 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001297 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001298 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001299 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001300 }
jardineb5d44e2003-12-23 08:09:43 +00001301
1302 free_tlvs (&tlvs);
1303
1304 return retval;
1305}
1306
1307/*
1308 * Process Level 1/2 Link State
1309 * ISO - 10589
1310 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001311 */
1312static int
Christian Franke77277a12015-11-10 18:04:43 +01001313process_lsp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001314{
1315 struct isis_link_state_hdr *hdr;
1316 struct isis_adjacency *adj = NULL;
1317 struct isis_lsp *lsp, *lsp0 = NULL;
1318 int retval = ISIS_OK, comp = 0;
1319 u_char lspid[ISIS_SYS_ID_LEN + 2];
1320 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001321 uint16_t pdu_len;
Christian Franke80d6b4e2015-11-10 18:33:15 +01001322 int lsp_confusion;
jardineb5d44e2003-12-23 08:09:43 +00001323
Josh Bailey3f045a02012-03-24 08:35:20 -07001324 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1325 {
1326 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1327 circuit->area->area_tag, level, circuit->interface->name,
1328 circuit_t2string (circuit->is_type), circuit->circuit_id);
1329 if (isis->debugs & DEBUG_PACKET_DUMP)
1330 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1331 stream_get_endp (circuit->rcv_stream));
1332 }
1333
hassof390d2c2004-09-10 20:48:21 +00001334 if ((stream_get_endp (circuit->rcv_stream) -
1335 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1336 {
1337 zlog_warn ("Packet too short");
1338 return ISIS_WARNING;
1339 }
jardineb5d44e2003-12-23 08:09:43 +00001340
1341 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001342 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001343 pdu_len = ntohs (hdr->pdu_len);
1344
1345 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001346 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001347 pdu_len > ISO_MTU(circuit) ||
1348 pdu_len > stream_get_endp (circuit->rcv_stream))
1349 {
1350 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1351 circuit->area->area_tag,
1352 rawlspid_print (hdr->lsp_id), pdu_len);
1353
1354 return ISIS_WARNING;
1355 }
1356
1357 /*
1358 * Set the stream endp to PDU length, ignoring additional padding
1359 * introduced by transport chips.
1360 */
1361 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1362 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001363
hassof390d2c2004-09-10 20:48:21 +00001364 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1365 {
hasso529d65b2004-12-24 00:14:50 +00001366 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001367 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001368 circuit->area->area_tag,
1369 level,
1370 rawlspid_print (hdr->lsp_id),
1371 ntohl (hdr->seq_num),
1372 ntohs (hdr->checksum),
1373 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001374 pdu_len,
paul15935e92005-05-03 09:27:23 +00001375 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001376 }
jardineb5d44e2003-12-23 08:09:43 +00001377
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001378 /* lsp is_type check */
1379 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1380 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001381 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001382 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001383 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001384 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1385 /* continue as per RFC1122 Be liberal in what you accept, and
1386 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001387 }
jardineb5d44e2003-12-23 08:09:43 +00001388
1389 /* Checksum sanity check - FIXME: move to correct place */
1390 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001391 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001392 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001393 {
hasso529d65b2004-12-24 00:14:50 +00001394 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1395 circuit->area->area_tag,
1396 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001397
hassof390d2c2004-09-10 20:48:21 +00001398 return ISIS_WARNING;
1399 }
jardineb5d44e2003-12-23 08:09:43 +00001400
1401 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001402 if (circuit->ext_domain)
1403 {
hasso529d65b2004-12-24 00:14:50 +00001404 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001405 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1406 "externalDomain = true", circuit->area->area_tag,
1407 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001408
hassof390d2c2004-09-10 20:48:21 +00001409 return ISIS_WARNING;
1410 }
jardineb5d44e2003-12-23 08:09:43 +00001411
1412 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001413 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001414 {
hasso529d65b2004-12-24 00:14:50 +00001415 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1416 " type %s",
1417 circuit->area->area_tag,
1418 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001419 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001420
hassof390d2c2004-09-10 20:48:21 +00001421 return ISIS_WARNING;
1422 }
jardineb5d44e2003-12-23 08:09:43 +00001423
1424 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1425
1426 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1427
1428 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001429 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1430 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001431 if (passwd->type)
1432 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001433 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1434 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001435 {
1436 isis_event_auth_failure (circuit->area->area_tag,
1437 "LSP authentication failure", hdr->lsp_id);
1438 return ISIS_WARNING;
1439 }
jardineb5d44e2003-12-23 08:09:43 +00001440 }
jardineb5d44e2003-12-23 08:09:43 +00001441 /* Find the LSP in our database and compare it to this Link State header */
1442 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1443 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001444 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1445 hdr->checksum, hdr->rem_lifetime);
1446 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001447#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001448 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001449#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001450 ))
jardineb5d44e2003-12-23 08:09:43 +00001451 goto dontcheckadj;
1452
1453 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1454 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001455
hassof390d2c2004-09-10 20:48:21 +00001456 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1457 {
1458 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1459 if (!adj)
1460 {
hasso529d65b2004-12-24 00:14:50 +00001461 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1462 "lifetime %us on %s",
1463 circuit->area->area_tag,
1464 rawlspid_print (hdr->lsp_id),
1465 ntohl (hdr->seq_num),
1466 ntohs (hdr->checksum),
1467 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001468 return ISIS_WARNING; /* Silently discard */
1469 }
jardineb5d44e2003-12-23 08:09:43 +00001470 }
jardineb5d44e2003-12-23 08:09:43 +00001471 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001472 else
1473 {
1474 /* If no adj, or no sharing of level */
1475 if (!circuit->u.p2p.neighbor)
1476 {
1477 return ISIS_OK; /* Silently discard */
1478 }
1479 else
1480 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001481 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001482 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001483 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001484 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1485 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001486 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001487 }
jardineb5d44e2003-12-23 08:09:43 +00001488 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001489
hassof390d2c2004-09-10 20:48:21 +00001490dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001491 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1492
1493 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1494
hassof390d2c2004-09-10 20:48:21 +00001495 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001496
Christian Franke80d6b4e2015-11-10 18:33:15 +01001497 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num but
1498 * wrong checksum, initiate a purge. */
1499 if (lsp
1500 && (lsp->lsp_header->seq_num == hdr->seq_num)
1501 && (lsp->lsp_header->checksum != hdr->checksum))
1502 {
1503 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
1504 circuit->area->area_tag, rawlspid_print(hdr->lsp_id),
1505 ntohl(hdr->seq_num));
1506 hdr->rem_lifetime = 0;
1507 lsp_confusion = 1;
1508 }
1509 else
1510 lsp_confusion = 0;
1511
hassof390d2c2004-09-10 20:48:21 +00001512 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1513 if (hdr->rem_lifetime == 0)
1514 {
1515 if (!lsp)
1516 {
1517 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1518 /* only needed on explicit update, eg - p2p */
1519 if (circuit->circ_type == CIRCUIT_T_P2P)
1520 ack_lsp (hdr, circuit, level);
1521 return retval; /* FIXME: do we need a purge? */
1522 }
1523 else
1524 {
1525 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1526 {
1527 /* LSP by some other system -> do 7.3.16.4 b) */
1528 /* 7.3.16.4 b) 1) */
1529 if (comp == LSP_NEWER)
1530 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001531 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001532 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001533 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001534 /* v */
1535 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
jardineb5d44e2003-12-23 08:09:43 +00001536
Christian Franke80d6b4e2015-11-10 18:33:15 +01001537 /* For the case of lsp confusion, flood the purge back to its
1538 * originator so that it can react. Otherwise, don't reflood
1539 * through incoming circuit as usual */
1540 if (!lsp_confusion)
1541 {
1542 /* iii */
1543 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1544 /* iv */
1545 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1546 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1547 }
hassof390d2c2004-09-10 20:48:21 +00001548 } /* 7.3.16.4 b) 2) */
1549 else if (comp == LSP_EQUAL)
1550 {
1551 /* i */
1552 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1553 /* ii */
1554 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1555 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1556 } /* 7.3.16.4 b) 3) */
1557 else
1558 {
1559 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1560 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1561 }
1562 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001563 else if (lsp->lsp_header->rem_lifetime != 0)
1564 {
1565 /* our own LSP -> 7.3.16.4 c) */
1566 if (comp == LSP_NEWER)
1567 {
1568 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1569 lsp_set_all_srmflags (lsp);
1570 }
1571 else
1572 {
1573 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1574 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1575 }
1576 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1577 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1578 "seq 0x%08x", circuit->area->area_tag,
1579 rawlspid_print (hdr->lsp_id),
1580 ntohl (lsp->lsp_header->seq_num));
1581 }
hassof390d2c2004-09-10 20:48:21 +00001582 }
1583 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001584 }
jardineb5d44e2003-12-23 08:09:43 +00001585 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1586 * purge */
hassof390d2c2004-09-10 20:48:21 +00001587 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1588 {
1589 if (!lsp)
1590 {
1591 /* 7.3.16.4: initiate a purge */
Christian Franke749e87a2015-11-10 18:21:44 +01001592 lsp_purge_non_exist(level, hdr, circuit->area);
hassof390d2c2004-09-10 20:48:21 +00001593 return ISIS_OK;
1594 }
1595 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1596
1597 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1598 * has information that the current sequence number for source S is
1599 * "greater" than that held by S, ... */
1600
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001601 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001602 {
1603 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001604 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001605 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1606 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1607 "0x%08x", circuit->area->area_tag,
1608 rawlspid_print (hdr->lsp_id),
1609 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001610 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001611 /* If the received LSP is older or equal,
1612 * resend the LSP which will act as ACK */
1613 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001614 }
hassof390d2c2004-09-10 20:48:21 +00001615 else
1616 {
1617 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001618
hassof390d2c2004-09-10 20:48:21 +00001619 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1620 if ((!lsp || comp == LSP_NEWER))
1621 {
hassof390d2c2004-09-10 20:48:21 +00001622 /*
1623 * If this lsp is a frag, need to see if we have zero lsp present
1624 */
1625 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1626 {
1627 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1628 LSP_FRAGMENT (lspid) = 0;
1629 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1630 if (!lsp0)
1631 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001632 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001633 return ISIS_OK;
1634 }
1635 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001636 /* i */
1637 if (!lsp)
1638 {
1639 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001640 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001641 circuit->area, level);
1642 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1643 }
1644 else /* exists, so we overwrite */
1645 {
1646 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1647 }
hassof390d2c2004-09-10 20:48:21 +00001648 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001649 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001650 /* iii */
1651 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001652
hassof390d2c2004-09-10 20:48:21 +00001653 /* iv */
1654 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1655 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1656 /* FIXME: v) */
1657 }
1658 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1659 else if (comp == LSP_EQUAL)
1660 {
1661 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001662 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001663 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001664 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001665 }
1666 /* 7.3.15.1 e) 3) LSP older than the one in db */
1667 else
1668 {
1669 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1670 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1671 }
jardineb5d44e2003-12-23 08:09:43 +00001672 }
jardineb5d44e2003-12-23 08:09:43 +00001673 return retval;
1674}
1675
1676/*
1677 * Process Sequence Numbers
1678 * ISO - 10589
1679 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1680 */
1681
hasso92365882005-01-18 13:53:33 +00001682static int
hassof390d2c2004-09-10 20:48:21 +00001683process_snp (int snp_type, int level, struct isis_circuit *circuit,
Christian Franke77277a12015-11-10 18:04:43 +01001684 const u_char *ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001685{
1686 int retval = ISIS_OK;
1687 int cmp, own_lsp;
1688 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001689 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001690 struct isis_adjacency *adj;
1691 struct isis_complete_seqnum_hdr *chdr = NULL;
1692 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001693 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001694 struct isis_lsp *lsp;
1695 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001696 struct listnode *node, *nnode;
1697 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001698 struct tlvs tlvs;
1699 struct list *lsp_list = NULL;
1700 struct isis_passwd *passwd;
1701
hassof390d2c2004-09-10 20:48:21 +00001702 if (snp_type == ISIS_SNP_CSNP_FLAG)
1703 {
1704 /* getting the header info */
1705 typechar = 'C';
1706 chdr =
1707 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001708 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1709 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001710 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001711 pdu_len > ISO_MTU(circuit) ||
1712 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001713 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001714 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1715 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001716 }
jardineb5d44e2003-12-23 08:09:43 +00001717 }
hassof390d2c2004-09-10 20:48:21 +00001718 else
1719 {
1720 typechar = 'P';
1721 phdr =
1722 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001723 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1724 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001725 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001726 pdu_len > ISO_MTU(circuit) ||
1727 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001728 {
Christian Frankeb4616302015-11-10 18:04:45 +01001729 zlog_warn ("Received a PSNP with bogus length %d", pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001730 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001731 }
jardineb5d44e2003-12-23 08:09:43 +00001732 }
jardineb5d44e2003-12-23 08:09:43 +00001733
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001734 /*
1735 * Set the stream endp to PDU length, ignoring additional padding
1736 * introduced by transport chips.
1737 */
1738 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1739 stream_set_endp (circuit->rcv_stream, pdu_len);
1740
jardineb5d44e2003-12-23 08:09:43 +00001741 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001742 if (circuit->ext_domain)
1743 {
jardineb5d44e2003-12-23 08:09:43 +00001744
hasso529d65b2004-12-24 00:14:50 +00001745 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1746 "skipping: circuit externalDomain = true",
1747 circuit->area->area_tag,
1748 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001749
1750 return ISIS_OK;
1751 }
hassof390d2c2004-09-10 20:48:21 +00001752
1753 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001754 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001755 {
1756
hasso529d65b2004-12-24 00:14:50 +00001757 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1758 "skipping: circuit type %s does not match level %d",
1759 circuit->area->area_tag,
1760 level,
1761 typechar,
1762 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001763 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001764
1765 return ISIS_OK;
1766 }
1767
1768 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1769 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001770 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1771 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001772 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001773 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1774 "skipping: we are not the DIS",
1775 circuit->area->area_tag,
1776 level,
1777 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001778
Josh Bailey3f045a02012-03-24 08:35:20 -07001779 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001780 }
jardineb5d44e2003-12-23 08:09:43 +00001781
1782 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1783
1784 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1785 * - already checked */
1786
1787 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1788 /* for broadcast circuits, snpa should be compared */
1789 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001790 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1791 {
1792 if (snp_type == ISIS_SNP_CSNP_FLAG)
1793 {
1794 adj =
1795 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1796 }
1797 else
1798 {
1799 /* a psnp on a broadcast, how lovely of Juniper :) */
1800 adj =
1801 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1802 }
1803 if (!adj)
1804 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001805 }
hassof390d2c2004-09-10 20:48:21 +00001806 else
1807 {
1808 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001809 {
1810 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1811 return ISIS_OK; /* Silently discard */
1812 }
hassof390d2c2004-09-10 20:48:21 +00001813 }
jardineb5d44e2003-12-23 08:09:43 +00001814
1815 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1816
1817 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1818
1819 memset (&tlvs, 0, sizeof (struct tlvs));
1820
1821 /* parse the SNP */
1822 expected |= TLVFLAG_LSP_ENTRIES;
1823 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001824
1825 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001826 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001827 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001828 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001829 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001830
hassof390d2c2004-09-10 20:48:21 +00001831 if (retval > ISIS_WARNING)
1832 {
1833 zlog_warn ("something went very wrong processing SNP");
1834 free_tlvs (&tlvs);
1835 return retval;
1836 }
jardineb5d44e2003-12-23 08:09:43 +00001837
Josh Bailey3f045a02012-03-24 08:35:20 -07001838 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001839 passwd = &circuit->area->area_passwd;
1840 else
1841 passwd = &circuit->area->domain_passwd;
1842
1843 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001844 {
hasso1cbc5622005-01-01 10:29:51 +00001845 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001846 {
1847 if (!(found & TLVFLAG_AUTH_INFO) ||
1848 authentication_check (&tlvs.auth_info, passwd,
1849 circuit->rcv_stream, auth_tlv_offset))
1850 {
1851 isis_event_auth_failure (circuit->area->area_tag,
1852 "SNP authentication" " failure",
1853 phdr ? phdr->source_id :
1854 chdr->source_id);
1855 free_tlvs (&tlvs);
1856 return ISIS_OK;
1857 }
1858 }
hassof390d2c2004-09-10 20:48:21 +00001859 }
jardineb5d44e2003-12-23 08:09:43 +00001860
1861 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001862 if (isis->debugs & DEBUG_SNP_PACKETS)
1863 {
hasso529d65b2004-12-24 00:14:50 +00001864 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1865 circuit->area->area_tag,
1866 level,
1867 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001868 if (tlvs.lsp_entries)
1869 {
hasso3fdb2dd2005-09-28 18:45:54 +00001870 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001871 {
hasso529d65b2004-12-24 00:14:50 +00001872 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1873 " cksum 0x%04x, lifetime %us",
1874 circuit->area->area_tag,
1875 typechar,
1876 rawlspid_print (entry->lsp_id),
1877 ntohl (entry->seq_num),
1878 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001879 }
1880 }
jardineb5d44e2003-12-23 08:09:43 +00001881 }
jardineb5d44e2003-12-23 08:09:43 +00001882
1883 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001884 if (tlvs.lsp_entries)
1885 {
hasso3fdb2dd2005-09-28 18:45:54 +00001886 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001887 {
1888 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1889 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1890 if (lsp)
1891 {
1892 /* 7.3.15.2 b) 1) is this LSP newer */
1893 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1894 entry->checksum, entry->rem_lifetime);
1895 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1896 if (cmp == LSP_EQUAL)
1897 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001898 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1899 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001900 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001901 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001902 else if (cmp == LSP_OLDER)
1903 {
1904 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1905 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1906 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001907 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001908 else
1909 {
hassof390d2c2004-09-10 20:48:21 +00001910 if (own_lsp)
1911 {
1912 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1913 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1914 }
1915 else
1916 {
1917 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001918 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1919 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001920 }
1921 }
1922 }
1923 else
1924 {
1925 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1926 * insert it and set SSN on it */
1927 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1928 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1929 {
Christian Frankef1fc1db2015-11-10 18:43:31 +01001930 lsp = lsp_new(circuit->area, entry->lsp_id,
1931 ntohs(entry->rem_lifetime),
1932 0, 0, entry->checksum, level);
hassof390d2c2004-09-10 20:48:21 +00001933 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001934 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001935 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1936 }
1937 }
jardineb5d44e2003-12-23 08:09:43 +00001938 }
1939 }
jardineb5d44e2003-12-23 08:09:43 +00001940
1941 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001942 if (snp_type == ISIS_SNP_CSNP_FLAG)
1943 {
1944 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001945 * Build a list from our own LSP db bounded with
1946 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001947 */
1948 lsp_list = list_new ();
1949 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1950 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001951
hassof390d2c2004-09-10 20:48:21 +00001952 /* Fixme: Find a better solution */
1953 if (tlvs.lsp_entries)
1954 {
paul1eb8ef22005-04-07 07:30:20 +00001955 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001956 {
paul1eb8ef22005-04-07 07:30:20 +00001957 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001958 {
1959 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1960 {
1961 list_delete_node (lsp_list, node2);
1962 break;
1963 }
1964 }
1965 }
1966 }
1967 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001968 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001969 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001970 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001971 list_delete (lsp_list);
1972
jardineb5d44e2003-12-23 08:09:43 +00001973 }
jardineb5d44e2003-12-23 08:09:43 +00001974
1975 free_tlvs (&tlvs);
1976 return retval;
1977}
1978
hasso92365882005-01-18 13:53:33 +00001979static int
Christian Franke77277a12015-11-10 18:04:43 +01001980process_csnp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001981{
Josh Bailey3f045a02012-03-24 08:35:20 -07001982 if (isis->debugs & DEBUG_SNP_PACKETS)
1983 {
1984 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1985 circuit->area->area_tag, level, circuit->interface->name,
1986 circuit_t2string (circuit->is_type), circuit->circuit_id);
1987 if (isis->debugs & DEBUG_PACKET_DUMP)
1988 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1989 stream_get_endp (circuit->rcv_stream));
1990 }
1991
jardineb5d44e2003-12-23 08:09:43 +00001992 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001993 if ((stream_get_endp (circuit->rcv_stream) -
1994 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1995 {
1996 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1997 return ISIS_WARNING;
1998 }
jardineb5d44e2003-12-23 08:09:43 +00001999
2000 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
2001}
2002
hasso92365882005-01-18 13:53:33 +00002003static int
Christian Franke77277a12015-11-10 18:04:43 +01002004process_psnp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00002005{
Josh Bailey3f045a02012-03-24 08:35:20 -07002006 if (isis->debugs & DEBUG_SNP_PACKETS)
2007 {
2008 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
2009 circuit->area->area_tag, level, circuit->interface->name,
2010 circuit_t2string (circuit->is_type), circuit->circuit_id);
2011 if (isis->debugs & DEBUG_PACKET_DUMP)
2012 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
2013 stream_get_endp (circuit->rcv_stream));
2014 }
2015
hassof390d2c2004-09-10 20:48:21 +00002016 if ((stream_get_endp (circuit->rcv_stream) -
2017 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
2018 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002019 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00002020 return ISIS_WARNING;
2021 }
jardineb5d44e2003-12-23 08:09:43 +00002022
2023 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
2024}
2025
jardineb5d44e2003-12-23 08:09:43 +00002026/*
jardineb5d44e2003-12-23 08:09:43 +00002027 * PDU Dispatcher
2028 */
2029
hasso92365882005-01-18 13:53:33 +00002030static int
hassof390d2c2004-09-10 20:48:21 +00002031isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00002032{
jardineb5d44e2003-12-23 08:09:43 +00002033 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00002034
hassof390d2c2004-09-10 20:48:21 +00002035 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002036
2037 /*
2038 * Let's first read data from stream to the header
2039 */
hassof390d2c2004-09-10 20:48:21 +00002040 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00002041
hassof390d2c2004-09-10 20:48:21 +00002042 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
2043 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002044 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00002045 return ISIS_ERROR;
2046 }
jardineb5d44e2003-12-23 08:09:43 +00002047
2048 /* now we need to know if this is an ISO 9542 packet and
2049 * take real good care of it, waaa!
2050 */
hassof390d2c2004-09-10 20:48:21 +00002051 if (hdr->idrp == ISO9542_ESIS)
2052 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002053 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
2054 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002055 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002056 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
2057
jardineb5d44e2003-12-23 08:09:43 +00002058 /*
2059 * and then process it
2060 */
2061
hassof390d2c2004-09-10 20:48:21 +00002062 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
2063 {
2064 zlog_err ("Fixed header length = %d", hdr->length);
2065 return ISIS_ERROR;
2066 }
jardineb5d44e2003-12-23 08:09:43 +00002067
hassof390d2c2004-09-10 20:48:21 +00002068 if (hdr->version1 != 1)
2069 {
2070 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
2071 return ISIS_WARNING;
2072 }
jardineb5d44e2003-12-23 08:09:43 +00002073 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002074 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2075 {
2076 zlog_err
2077 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2078 "while the parameter for this IS is %u", hdr->id_len,
2079 ISIS_SYS_ID_LEN);
2080 return ISIS_ERROR;
2081 }
jardineb5d44e2003-12-23 08:09:43 +00002082
hassof390d2c2004-09-10 20:48:21 +00002083 if (hdr->version2 != 1)
2084 {
2085 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2086 return ISIS_WARNING;
2087 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002088
2089 if (circuit->is_passive)
2090 {
2091 zlog_warn ("Received ISIS PDU on passive circuit %s",
2092 circuit->interface->name);
2093 return ISIS_WARNING;
2094 }
2095
jardineb5d44e2003-12-23 08:09:43 +00002096 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002097 if ((hdr->max_area_addrs != 0)
2098 && (hdr->max_area_addrs != isis->max_area_addrs))
2099 {
2100 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2101 "received PDU %u while the parameter for this IS is %u",
2102 hdr->max_area_addrs, isis->max_area_addrs);
2103 return ISIS_ERROR;
2104 }
jardineb5d44e2003-12-23 08:09:43 +00002105
hassof390d2c2004-09-10 20:48:21 +00002106 switch (hdr->pdu_type)
2107 {
2108 case L1_LAN_HELLO:
2109 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2110 break;
2111 case L2_LAN_HELLO:
2112 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2113 break;
2114 case P2P_HELLO:
2115 retval = process_p2p_hello (circuit);
2116 break;
2117 case L1_LINK_STATE:
2118 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2119 break;
2120 case L2_LINK_STATE:
2121 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2122 break;
2123 case L1_COMPLETE_SEQ_NUM:
2124 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2125 break;
2126 case L2_COMPLETE_SEQ_NUM:
2127 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2128 break;
2129 case L1_PARTIAL_SEQ_NUM:
2130 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2131 break;
2132 case L2_PARTIAL_SEQ_NUM:
2133 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2134 break;
2135 default:
2136 return ISIS_ERROR;
2137 }
jardineb5d44e2003-12-23 08:09:43 +00002138
2139 return retval;
2140}
2141
jardineb5d44e2003-12-23 08:09:43 +00002142#ifdef GNU_LINUX
2143int
2144isis_receive (struct thread *thread)
2145{
jardineb5d44e2003-12-23 08:09:43 +00002146 struct isis_circuit *circuit;
2147 u_char ssnpa[ETH_ALEN];
2148 int retval;
2149
2150 /*
2151 * Get the circuit
2152 */
2153 circuit = THREAD_ARG (thread);
2154 assert (circuit);
2155
Christian Frankef1fc1db2015-11-10 18:43:31 +01002156 isis_circuit_stream(circuit, &circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00002157
2158 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002159 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002160
2161 if (retval == ISIS_OK)
2162 retval = isis_handle_pdu (circuit, ssnpa);
2163
2164 /*
2165 * prepare for next packet.
2166 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002167 if (!circuit->is_passive)
2168 {
2169 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2170 circuit->fd);
2171 }
jardineb5d44e2003-12-23 08:09:43 +00002172
2173 return retval;
2174}
2175
2176#else
2177int
2178isis_receive (struct thread *thread)
2179{
jardineb5d44e2003-12-23 08:09:43 +00002180 struct isis_circuit *circuit;
2181 u_char ssnpa[ETH_ALEN];
2182 int retval;
2183
2184 /*
2185 * Get the circuit
2186 */
2187 circuit = THREAD_ARG (thread);
2188 assert (circuit);
2189
hassof390d2c2004-09-10 20:48:21 +00002190 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002191
Christian Frankef1fc1db2015-11-10 18:43:31 +01002192 isis_circuit_stream(circuit, &circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00002193
2194 retval = circuit->rx (circuit, ssnpa);
2195
2196 if (retval == ISIS_OK)
2197 retval = isis_handle_pdu (circuit, ssnpa);
2198
2199 /*
2200 * prepare for next packet.
2201 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002202 if (!circuit->is_passive)
2203 {
2204 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2205 listcount
2206 (circuit->area->circuit_list) *
2207 100);
2208 }
jardineb5d44e2003-12-23 08:09:43 +00002209
2210 return retval;
2211}
2212
2213#endif
2214
2215 /* filling of the fixed isis header */
2216void
2217fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2218{
2219 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2220
2221 hdr->idrp = ISO10589_ISIS;
2222
hassof390d2c2004-09-10 20:48:21 +00002223 switch (pdu_type)
2224 {
2225 case L1_LAN_HELLO:
2226 case L2_LAN_HELLO:
2227 hdr->length = ISIS_LANHELLO_HDRLEN;
2228 break;
2229 case P2P_HELLO:
2230 hdr->length = ISIS_P2PHELLO_HDRLEN;
2231 break;
2232 case L1_LINK_STATE:
2233 case L2_LINK_STATE:
2234 hdr->length = ISIS_LSP_HDR_LEN;
2235 break;
2236 case L1_COMPLETE_SEQ_NUM:
2237 case L2_COMPLETE_SEQ_NUM:
2238 hdr->length = ISIS_CSNP_HDRLEN;
2239 break;
2240 case L1_PARTIAL_SEQ_NUM:
2241 case L2_PARTIAL_SEQ_NUM:
2242 hdr->length = ISIS_PSNP_HDRLEN;
2243 break;
2244 default:
2245 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2246 return;
2247 }
jardineb5d44e2003-12-23 08:09:43 +00002248 hdr->length += ISIS_FIXED_HDR_LEN;
2249 hdr->pdu_type = pdu_type;
2250 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002251 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002252 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002253 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002254}
2255
jardineb5d44e2003-12-23 08:09:43 +00002256/*
2257 * SEND SIDE
2258 */
hasso92365882005-01-18 13:53:33 +00002259static void
jardineb5d44e2003-12-23 08:09:43 +00002260fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002261 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002262{
hassof390d2c2004-09-10 20:48:21 +00002263 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002264
2265 stream_putc (stream, hdr->idrp);
2266 stream_putc (stream, hdr->length);
2267 stream_putc (stream, hdr->version1);
2268 stream_putc (stream, hdr->id_len);
2269 stream_putc (stream, hdr->pdu_type);
2270 stream_putc (stream, hdr->version2);
2271 stream_putc (stream, hdr->reserved);
2272 stream_putc (stream, hdr->max_area_addrs);
2273
2274 return;
2275}
2276
jardineb5d44e2003-12-23 08:09:43 +00002277int
2278send_hello (struct isis_circuit *circuit, int level)
2279{
2280 struct isis_fixed_hdr fixed_hdr;
2281 struct isis_lan_hello_hdr hello_hdr;
2282 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002283 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
David Lamparter01da6172015-04-10 09:10:11 +02002284 size_t len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002285 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002286 int retval;
2287
Josh Bailey3f045a02012-03-24 08:35:20 -07002288 if (circuit->is_passive)
2289 return ISIS_OK;
2290
hassof390d2c2004-09-10 20:48:21 +00002291 if (circuit->interface->mtu == 0)
2292 {
2293 zlog_warn ("circuit has zero MTU");
2294 return ISIS_WARNING;
2295 }
jardineb5d44e2003-12-23 08:09:43 +00002296
Christian Frankef1fc1db2015-11-10 18:43:31 +01002297 isis_circuit_stream(circuit, &circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002298
2299 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002300 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002301 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2302 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002303 else
hassof390d2c2004-09-10 20:48:21 +00002304 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2305 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002306 else
hassof390d2c2004-09-10 20:48:21 +00002307 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002308
2309 /*
2310 * Fill LAN Level 1 or 2 Hello PDU header
2311 */
2312 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002313 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002314 circuit->hello_interval[level - 1];
2315 if (interval > USHRT_MAX)
2316 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002317 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002318 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002319 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002320
hassof390d2c2004-09-10 20:48:21 +00002321 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002322 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002323
2324 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002325 if (circuit->circ_type == CIRCUIT_T_P2P)
2326 {
2327 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2328 p2p_hello_hdr.local_id = circuit->circuit_id;
2329 /* FIXME: need better understanding */
2330 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002331 }
hassof390d2c2004-09-10 20:48:21 +00002332 else
2333 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002334 hello_hdr.prio = circuit->priority[level - 1];
2335 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002336 {
2337 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2338 ISIS_SYS_ID_LEN + 1);
2339 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002340 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002341 {
2342 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2343 ISIS_SYS_ID_LEN + 1);
2344 }
2345 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2346 }
jardineb5d44e2003-12-23 08:09:43 +00002347
2348 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002349 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002350 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002351
jardineb5d44e2003-12-23 08:09:43 +00002352 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002353 switch (circuit->passwd.type)
2354 {
2355 /* Cleartext */
2356 case ISIS_PASSWD_TYPE_CLEARTXT:
2357 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2358 circuit->passwd.passwd, circuit->snd_stream))
2359 return ISIS_WARNING;
2360 break;
2361
2362 /* HMAC MD5 */
2363 case ISIS_PASSWD_TYPE_HMAC_MD5:
2364 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2365 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2366 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2367 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2368 hmac_md5_hash, circuit->snd_stream))
2369 return ISIS_WARNING;
2370 break;
2371
2372 default:
2373 break;
2374 }
2375
jardineb5d44e2003-12-23 08:09:43 +00002376 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002377 if (listcount (circuit->area->area_addrs) == 0)
2378 return ISIS_WARNING;
2379 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2380 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002381
2382 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002383 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2384 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002385 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2386 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002387 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2388 circuit->snd_stream))
2389 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002390 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2391 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002392 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2393 circuit->snd_stream))
2394 return ISIS_WARNING;
2395 }
jardineb5d44e2003-12-23 08:09:43 +00002396
2397 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002398 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002399 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2400 return ISIS_WARNING;
2401 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002402 if (circuit->ip_router && circuit->ip_addrs &&
2403 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002404 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2405 return ISIS_WARNING;
2406
hassof390d2c2004-09-10 20:48:21 +00002407#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002408 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002409 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002410 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002411 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2412 return ISIS_WARNING;
2413#endif /* HAVE_IPV6 */
2414
Josh Bailey3f045a02012-03-24 08:35:20 -07002415 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002416 if (tlv_add_padding (circuit->snd_stream))
2417 return ISIS_WARNING;
2418
paul9985f832005-02-09 15:51:56 +00002419 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002420 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002421 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002422
Josh Bailey3f045a02012-03-24 08:35:20 -07002423 /* For HMAC MD5 we need to compute the md5 hash and store it */
2424 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2425 {
2426 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2427 stream_get_endp (circuit->snd_stream),
2428 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
David Lamparter21401f32015-03-03 08:55:26 +01002429 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002430 /* Copy the hash into the stream */
2431 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2432 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2433 }
jardineb5d44e2003-12-23 08:09:43 +00002434
hassof390d2c2004-09-10 20:48:21 +00002435 if (isis->debugs & DEBUG_ADJ_PACKETS)
2436 {
2437 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2438 {
Christian Franke812f2822015-11-10 18:33:16 +01002439 zlog_debug ("ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002440 circuit->area->area_tag, level, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002441 length);
hassof390d2c2004-09-10 20:48:21 +00002442 }
2443 else
2444 {
Christian Franke812f2822015-11-10 18:33:16 +01002445 zlog_debug ("ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
hasso529d65b2004-12-24 00:14:50 +00002446 circuit->area->area_tag, circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07002447 length);
hassof390d2c2004-09-10 20:48:21 +00002448 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002449 if (isis->debugs & DEBUG_PACKET_DUMP)
2450 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2451 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002452 }
jardineb5d44e2003-12-23 08:09:43 +00002453
Josh Bailey3f045a02012-03-24 08:35:20 -07002454 retval = circuit->tx (circuit, level);
2455 if (retval != ISIS_OK)
2456 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2457 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002458
Josh Bailey3f045a02012-03-24 08:35:20 -07002459 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002460}
2461
2462int
2463send_lan_l1_hello (struct thread *thread)
2464{
jardineb5d44e2003-12-23 08:09:43 +00002465 struct isis_circuit *circuit;
2466 int retval;
2467
2468 circuit = THREAD_ARG (thread);
2469 assert (circuit);
2470 circuit->u.bc.t_send_lan_hello[0] = NULL;
2471
Christian Franke7324ae12015-11-10 18:04:48 +01002472 if (!(circuit->area->is_type & IS_LEVEL_1))
2473 {
2474 zlog_warn ("ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
2475 circuit->area->area_tag);
2476 return 1;
2477 }
2478
jardineb5d44e2003-12-23 08:09:43 +00002479 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002480 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002481
Josh Bailey3f045a02012-03-24 08:35:20 -07002482 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002483
2484 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002485 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2486 send_lan_l1_hello, circuit,
2487 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002488
2489 return retval;
2490}
2491
2492int
2493send_lan_l2_hello (struct thread *thread)
2494{
2495 struct isis_circuit *circuit;
2496 int retval;
2497
2498 circuit = THREAD_ARG (thread);
2499 assert (circuit);
2500 circuit->u.bc.t_send_lan_hello[1] = NULL;
2501
Christian Franke7324ae12015-11-10 18:04:48 +01002502 if (!(circuit->area->is_type & IS_LEVEL_2))
2503 {
2504 zlog_warn ("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
2505 circuit->area->area_tag);
2506 return 1;
2507 }
2508
jardineb5d44e2003-12-23 08:09:43 +00002509 if (circuit->u.bc.run_dr_elect[1])
2510 retval = isis_dr_elect (circuit, 2);
2511
Josh Bailey3f045a02012-03-24 08:35:20 -07002512 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002513
hassof390d2c2004-09-10 20:48:21 +00002514 /* set next timer thread */
2515 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2516 send_lan_l2_hello, circuit,
2517 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002518
2519 return retval;
2520}
2521
2522int
2523send_p2p_hello (struct thread *thread)
2524{
2525 struct isis_circuit *circuit;
2526
2527 circuit = THREAD_ARG (thread);
2528 assert (circuit);
2529 circuit->u.p2p.t_send_p2p_hello = NULL;
2530
hassof390d2c2004-09-10 20:48:21 +00002531 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002532
hassof390d2c2004-09-10 20:48:21 +00002533 /* set next timer thread */
2534 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2535 circuit, isis_jitter (circuit->hello_interval[1],
2536 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002537
2538 return ISIS_OK;
2539}
2540
hasso92365882005-01-18 13:53:33 +00002541static int
hassof390d2c2004-09-10 20:48:21 +00002542build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2543 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002544{
2545 struct isis_fixed_hdr fixed_hdr;
2546 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002547 unsigned long lenp;
2548 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002549 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2550 unsigned long auth_tlv_offset = 0;
2551 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002552
Christian Frankef1fc1db2015-11-10 18:43:31 +01002553 isis_circuit_stream(circuit, &circuit->snd_stream);
Josh Bailey3f045a02012-03-24 08:35:20 -07002554
2555 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002556 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2557 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002558 else
hassof390d2c2004-09-10 20:48:21 +00002559 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2560 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002561
2562 /*
2563 * Fill Level 1 or 2 Complete Sequence Numbers header
2564 */
2565
paul9985f832005-02-09 15:51:56 +00002566 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002567 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002568 /* no need to send the source here, it is always us if we csnp */
2569 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2570 /* with zero circuit id - ref 9.10, 9.11 */
2571 stream_putc (circuit->snd_stream, 0x00);
2572
2573 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2574 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2575
2576 /*
2577 * And TLVs
2578 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002579 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002580 passwd = &circuit->area->area_passwd;
2581 else
2582 passwd = &circuit->area->domain_passwd;
2583
hasso1cbc5622005-01-01 10:29:51 +00002584 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002585 {
2586 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002587 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002588 /* Cleartext */
2589 case ISIS_PASSWD_TYPE_CLEARTXT:
2590 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2591 passwd->passwd, circuit->snd_stream))
2592 return ISIS_WARNING;
2593 break;
2594
2595 /* HMAC MD5 */
2596 case ISIS_PASSWD_TYPE_HMAC_MD5:
2597 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2598 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2599 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2600 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2601 hmac_md5_hash, circuit->snd_stream))
2602 return ISIS_WARNING;
2603 break;
2604
2605 default:
2606 break;
hassof390d2c2004-09-10 20:48:21 +00002607 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002608 }
2609
2610 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2611 if (retval != ISIS_OK)
2612 return retval;
2613
paul9985f832005-02-09 15:51:56 +00002614 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002615 /* Update PU length */
2616 stream_putw_at (circuit->snd_stream, lenp, length);
2617
Josh Bailey3f045a02012-03-24 08:35:20 -07002618 /* For HMAC MD5 we need to compute the md5 hash and store it */
2619 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2620 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2621 {
2622 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2623 stream_get_endp(circuit->snd_stream),
2624 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002625 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002626 /* Copy the hash into the stream */
2627 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2628 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2629 }
2630
jardineb5d44e2003-12-23 08:09:43 +00002631 return retval;
2632}
2633
2634/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002635 * Count the maximum number of lsps that can be accomodated by a given size.
2636 */
2637static uint16_t
2638get_max_lsp_count (uint16_t size)
2639{
2640 uint16_t tlv_count;
2641 uint16_t lsp_count;
2642 uint16_t remaining_size;
2643
2644 /* First count the full size TLVs */
2645 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2646 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2647
2648 /* The last TLV, if any */
2649 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2650 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2651 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2652
2653 return lsp_count;
2654}
2655
2656/*
2657 * Calculate the length of Authentication Info. TLV.
2658 */
2659static uint16_t
2660auth_tlv_length (int level, struct isis_circuit *circuit)
2661{
2662 struct isis_passwd *passwd;
2663 uint16_t length;
2664
2665 if (level == IS_LEVEL_1)
2666 passwd = &circuit->area->area_passwd;
2667 else
2668 passwd = &circuit->area->domain_passwd;
2669
2670 /* Also include the length of TLV header */
2671 length = AUTH_INFO_HDRLEN;
2672 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2673 {
2674 switch (passwd->type)
2675 {
2676 /* Cleartext */
2677 case ISIS_PASSWD_TYPE_CLEARTXT:
2678 length += passwd->len;
2679 break;
2680
2681 /* HMAC MD5 */
2682 case ISIS_PASSWD_TYPE_HMAC_MD5:
2683 length += ISIS_AUTH_MD5_SIZE;
2684 break;
2685
2686 default:
2687 break;
2688 }
2689 }
2690
2691 return length;
2692}
2693
2694/*
2695 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2696 */
2697static uint16_t
2698max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2699{
2700 int snp_hdr_len;
2701 int auth_tlv_len;
2702 uint16_t lsp_count;
2703
2704 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2705 if (snp_type == ISIS_SNP_CSNP_FLAG)
2706 snp_hdr_len += ISIS_CSNP_HDRLEN;
2707 else
2708 snp_hdr_len += ISIS_PSNP_HDRLEN;
2709
2710 auth_tlv_len = auth_tlv_length (level, circuit);
2711 lsp_count = get_max_lsp_count (
2712 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002713 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002714}
2715
2716/*
jardineb5d44e2003-12-23 08:09:43 +00002717 * FIXME: support multiple CSNPs
2718 */
2719
2720int
2721send_csnp (struct isis_circuit *circuit, int level)
2722{
jardineb5d44e2003-12-23 08:09:43 +00002723 u_char start[ISIS_SYS_ID_LEN + 2];
2724 u_char stop[ISIS_SYS_ID_LEN + 2];
2725 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002726 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002727 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002728 u_char num_lsps, loop = 1;
2729 int i, retval = ISIS_OK;
2730
2731 if (circuit->area->lspdb[level - 1] == NULL ||
2732 dict_count (circuit->area->lspdb[level - 1]) == 0)
2733 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002734
hassof390d2c2004-09-10 20:48:21 +00002735 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002736 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2737
Josh Bailey3f045a02012-03-24 08:35:20 -07002738 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2739
2740 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002741 {
2742 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002743 lsp_build_list (start, stop, num_lsps, list,
2744 circuit->area->lspdb[level - 1]);
2745 /*
2746 * Update the stop lsp_id before encoding this CSNP.
2747 */
2748 if (listcount (list) < num_lsps)
2749 {
2750 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2751 }
hassof390d2c2004-09-10 20:48:21 +00002752 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002753 {
2754 node = listtail (list);
2755 lsp = listgetdata (node);
2756 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2757 }
jardineb5d44e2003-12-23 08:09:43 +00002758
hassof390d2c2004-09-10 20:48:21 +00002759 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002760 if (retval != ISIS_OK)
2761 {
2762 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2763 circuit->area->area_tag, level, circuit->interface->name);
2764 list_delete (list);
2765 return retval;
2766 }
jardineb5d44e2003-12-23 08:09:43 +00002767
hassof390d2c2004-09-10 20:48:21 +00002768 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002769 {
Christian Franke812f2822015-11-10 18:33:16 +01002770 zlog_debug ("ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07002771 circuit->area->area_tag, level, circuit->interface->name,
2772 stream_get_endp (circuit->snd_stream));
2773 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2774 {
2775 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2776 " cksum 0x%04x, lifetime %us",
2777 circuit->area->area_tag,
2778 rawlspid_print (lsp->lsp_header->lsp_id),
2779 ntohl (lsp->lsp_header->seq_num),
2780 ntohs (lsp->lsp_header->checksum),
2781 ntohs (lsp->lsp_header->rem_lifetime));
2782 }
2783 if (isis->debugs & DEBUG_PACKET_DUMP)
2784 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2785 stream_get_endp (circuit->snd_stream));
2786 }
hassof390d2c2004-09-10 20:48:21 +00002787
Josh Bailey3f045a02012-03-24 08:35:20 -07002788 retval = circuit->tx (circuit, level);
2789 if (retval != ISIS_OK)
2790 {
2791 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2792 circuit->area->area_tag, level,
2793 circuit->interface->name);
2794 list_delete (list);
2795 return retval;
2796 }
2797
2798 /*
2799 * Start lsp_id of the next CSNP should be one plus the
2800 * stop lsp_id in this current CSNP.
2801 */
2802 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2803 loop = 0;
2804 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2805 {
2806 if (start[i] < (u_char)0xff)
2807 {
2808 start[i] += 1;
2809 loop = 1;
2810 break;
2811 }
2812 }
2813 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002814 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002815 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002816
jardineb5d44e2003-12-23 08:09:43 +00002817 return retval;
2818}
2819
2820int
2821send_l1_csnp (struct thread *thread)
2822{
2823 struct isis_circuit *circuit;
2824 int retval = ISIS_OK;
2825
2826 circuit = THREAD_ARG (thread);
2827 assert (circuit);
2828
2829 circuit->t_send_csnp[0] = NULL;
2830
hassof390d2c2004-09-10 20:48:21 +00002831 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2832 {
2833 send_csnp (circuit, 1);
2834 }
jardineb5d44e2003-12-23 08:09:43 +00002835 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002836 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2837 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002838
2839 return retval;
2840}
2841
2842int
2843send_l2_csnp (struct thread *thread)
2844{
2845 struct isis_circuit *circuit;
2846 int retval = ISIS_OK;
2847
2848 circuit = THREAD_ARG (thread);
2849 assert (circuit);
2850
2851 circuit->t_send_csnp[1] = NULL;
2852
hassof390d2c2004-09-10 20:48:21 +00002853 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2854 {
2855 send_csnp (circuit, 2);
2856 }
jardineb5d44e2003-12-23 08:09:43 +00002857 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002858 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2859 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002860
jardineb5d44e2003-12-23 08:09:43 +00002861 return retval;
2862}
2863
hasso92365882005-01-18 13:53:33 +00002864static int
jardineb5d44e2003-12-23 08:09:43 +00002865build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2866{
2867 struct isis_fixed_hdr fixed_hdr;
2868 unsigned long lenp;
2869 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002870 struct isis_lsp *lsp;
2871 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002872 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002873 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2874 unsigned long auth_tlv_offset = 0;
2875 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002876
Christian Frankef1fc1db2015-11-10 18:43:31 +01002877 isis_circuit_stream(circuit, &circuit->snd_stream);
Josh Bailey3f045a02012-03-24 08:35:20 -07002878
2879 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002880 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2881 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002882 else
2883 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002884 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002885
2886 /*
2887 * Fill Level 1 or 2 Partial Sequence Numbers header
2888 */
paul9985f832005-02-09 15:51:56 +00002889 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002890 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002891 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2892 stream_putc (circuit->snd_stream, circuit->idx);
2893
2894 /*
2895 * And TLVs
2896 */
2897
Josh Bailey3f045a02012-03-24 08:35:20 -07002898 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002899 passwd = &circuit->area->area_passwd;
2900 else
2901 passwd = &circuit->area->domain_passwd;
2902
hasso1cbc5622005-01-01 10:29:51 +00002903 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002904 {
2905 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002906 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002907 /* Cleartext */
2908 case ISIS_PASSWD_TYPE_CLEARTXT:
2909 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2910 passwd->passwd, circuit->snd_stream))
2911 return ISIS_WARNING;
2912 break;
2913
2914 /* HMAC MD5 */
2915 case ISIS_PASSWD_TYPE_HMAC_MD5:
2916 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2917 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2918 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2919 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2920 hmac_md5_hash, circuit->snd_stream))
2921 return ISIS_WARNING;
2922 break;
2923
2924 default:
2925 break;
jardineb5d44e2003-12-23 08:09:43 +00002926 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002927 }
2928
2929 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2930 if (retval != ISIS_OK)
2931 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002932
hassof390d2c2004-09-10 20:48:21 +00002933 if (isis->debugs & DEBUG_SNP_PACKETS)
2934 {
hasso3fdb2dd2005-09-28 18:45:54 +00002935 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002936 {
hasso529d65b2004-12-24 00:14:50 +00002937 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2938 " cksum 0x%04x, lifetime %us",
2939 circuit->area->area_tag,
2940 rawlspid_print (lsp->lsp_header->lsp_id),
2941 ntohl (lsp->lsp_header->seq_num),
2942 ntohs (lsp->lsp_header->checksum),
2943 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002944 }
2945 }
2946
paul9985f832005-02-09 15:51:56 +00002947 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002948 /* Update PDU length */
2949 stream_putw_at (circuit->snd_stream, lenp, length);
2950
Josh Bailey3f045a02012-03-24 08:35:20 -07002951 /* For HMAC MD5 we need to compute the md5 hash and store it */
2952 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2953 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2954 {
2955 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2956 stream_get_endp(circuit->snd_stream),
2957 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +01002958 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -07002959 /* Copy the hash into the stream */
2960 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2961 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2962 }
2963
jardineb5d44e2003-12-23 08:09:43 +00002964 return ISIS_OK;
2965}
2966
2967/*
2968 * 7.3.15.4 action on expiration of partial SNP interval
2969 * level 1
2970 */
hasso92365882005-01-18 13:53:33 +00002971static int
jardineb5d44e2003-12-23 08:09:43 +00002972send_psnp (int level, struct isis_circuit *circuit)
2973{
jardineb5d44e2003-12-23 08:09:43 +00002974 struct isis_lsp *lsp;
2975 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002976 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002977 u_char num_lsps;
2978 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002979
Josh Bailey3f045a02012-03-24 08:35:20 -07002980 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2981 circuit->u.bc.is_dr[level - 1])
2982 return ISIS_OK;
2983
2984 if (circuit->area->lspdb[level - 1] == NULL ||
2985 dict_count (circuit->area->lspdb[level - 1]) == 0)
2986 return ISIS_OK;
2987
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002988 if (! circuit->snd_stream)
2989 return ISIS_ERROR;
2990
Josh Bailey3f045a02012-03-24 08:35:20 -07002991 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2992
2993 while (1)
hassof390d2c2004-09-10 20:48:21 +00002994 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002995 list = list_new ();
2996 lsp_build_list_ssn (circuit, num_lsps, list,
2997 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002998
Josh Bailey3f045a02012-03-24 08:35:20 -07002999 if (listcount (list) == 0)
3000 {
3001 list_delete (list);
3002 return ISIS_OK;
3003 }
jardineb5d44e2003-12-23 08:09:43 +00003004
Josh Bailey3f045a02012-03-24 08:35:20 -07003005 retval = build_psnp (level, circuit, list);
3006 if (retval != ISIS_OK)
3007 {
3008 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
3009 circuit->area->area_tag, level, circuit->interface->name);
3010 list_delete (list);
3011 return retval;
3012 }
jardineb5d44e2003-12-23 08:09:43 +00003013
Josh Bailey3f045a02012-03-24 08:35:20 -07003014 if (isis->debugs & DEBUG_SNP_PACKETS)
3015 {
Christian Franke812f2822015-11-10 18:33:16 +01003016 zlog_debug ("ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
Josh Bailey3f045a02012-03-24 08:35:20 -07003017 circuit->area->area_tag, level,
3018 circuit->interface->name,
3019 stream_get_endp (circuit->snd_stream));
3020 if (isis->debugs & DEBUG_PACKET_DUMP)
3021 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3022 stream_get_endp (circuit->snd_stream));
3023 }
jardineb5d44e2003-12-23 08:09:43 +00003024
Josh Bailey3f045a02012-03-24 08:35:20 -07003025 retval = circuit->tx (circuit, level);
3026 if (retval != ISIS_OK)
3027 {
3028 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
3029 circuit->area->area_tag, level,
3030 circuit->interface->name);
3031 list_delete (list);
3032 return retval;
3033 }
jardineb5d44e2003-12-23 08:09:43 +00003034
Josh Bailey3f045a02012-03-24 08:35:20 -07003035 /*
3036 * sending succeeded, we can clear SSN flags of this circuit
3037 * for the LSPs in list
3038 */
3039 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
3040 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
3041 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00003042 }
jardineb5d44e2003-12-23 08:09:43 +00003043
3044 return retval;
3045}
3046
3047int
3048send_l1_psnp (struct thread *thread)
3049{
3050
3051 struct isis_circuit *circuit;
3052 int retval = ISIS_OK;
3053
3054 circuit = THREAD_ARG (thread);
3055 assert (circuit);
3056
3057 circuit->t_send_psnp[0] = NULL;
3058
3059 send_psnp (1, circuit);
3060 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003061 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
3062 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003063
3064 return retval;
3065}
3066
3067/*
3068 * 7.3.15.4 action on expiration of partial SNP interval
3069 * level 2
3070 */
3071int
3072send_l2_psnp (struct thread *thread)
3073{
jardineb5d44e2003-12-23 08:09:43 +00003074 struct isis_circuit *circuit;
3075 int retval = ISIS_OK;
3076
3077 circuit = THREAD_ARG (thread);
3078 assert (circuit);
3079
3080 circuit->t_send_psnp[1] = NULL;
3081
3082 send_psnp (2, circuit);
3083
3084 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003085 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3086 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003087
3088 return retval;
3089}
3090
jardineb5d44e2003-12-23 08:09:43 +00003091/*
3092 * ISO 10589 - 7.3.14.3
3093 */
3094int
3095send_lsp (struct thread *thread)
3096{
3097 struct isis_circuit *circuit;
3098 struct isis_lsp *lsp;
3099 struct listnode *node;
Christian Franke8253b732015-11-12 14:24:28 +01003100 int clear_srm = 1;
Josh Bailey3f045a02012-03-24 08:35:20 -07003101 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003102
3103 circuit = THREAD_ARG (thread);
3104 assert (circuit);
3105
Christian Franke8253b732015-11-12 14:24:28 +01003106 if (!circuit->lsp_queue)
3107 return ISIS_OK;
Josh Bailey3f045a02012-03-24 08:35:20 -07003108
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003109 node = listhead (circuit->lsp_queue);
3110
3111 /*
3112 * Handle case where there are no LSPs on the queue. This can
3113 * happen, for instance, if an adjacency goes down before this
3114 * thread gets a chance to run.
3115 */
3116 if (!node)
Christian Franke8253b732015-11-12 14:24:28 +01003117 return ISIS_OK;
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003118
Christian Franke8253b732015-11-12 14:24:28 +01003119 /*
3120 * Delete LSP from lsp_queue. If it's still in queue, it is assumed
3121 * as 'transmit pending', but send_lsp may never be called again.
3122 * Retry will happen because SRM flag will not be cleared.
3123 */
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003124 lsp = listgetdata(node);
Christian Franke8253b732015-11-12 14:24:28 +01003125 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 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3134 goto out;
Josh Bailey3f045a02012-03-24 08:35:20 -07003135
3136 /*
3137 * Do not send if levels do not match
3138 */
3139 if (!(lsp->level & circuit->is_type))
Christian Franke8253b732015-11-12 14:24:28 +01003140 goto out;
jardineb5d44e2003-12-23 08:09:43 +00003141
Josh Bailey3f045a02012-03-24 08:35:20 -07003142 /*
3143 * Do not send if we do not have adjacencies in state up on the circuit
3144 */
3145 if (circuit->upadjcount[lsp->level - 1] == 0)
Christian Franke8253b732015-11-12 14:24:28 +01003146 goto out;
3147
3148 /* stream_copy will assert and stop program execution if LSP is larger than
3149 * the circuit's MTU. So handle and log this case here. */
3150 if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream))
Josh Bailey3f045a02012-03-24 08:35:20 -07003151 {
Christian Franke8253b732015-11-12 14:24:28 +01003152 zlog_err("ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x,"
3153 " cksum 0x%04x, lifetime %us on %s. LSP Size is %zu"
3154 " while interface stream size is %zu.",
3155 circuit->area->area_tag, lsp->level,
3156 rawlspid_print(lsp->lsp_header->lsp_id),
3157 ntohl(lsp->lsp_header->seq_num),
3158 ntohs(lsp->lsp_header->checksum),
3159 ntohs(lsp->lsp_header->rem_lifetime),
3160 circuit->interface->name,
3161 stream_get_endp(lsp->pdu),
3162 stream_get_size(circuit->snd_stream));
3163 if (isis->debugs & DEBUG_PACKET_DUMP)
3164 zlog_dump_data(STREAM_DATA(lsp->pdu), stream_get_endp(lsp->pdu));
3165 retval = ISIS_ERROR;
3166 goto out;
Josh Bailey3f045a02012-03-24 08:35:20 -07003167 }
3168
3169 /* copy our lsp to the send buffer */
3170 stream_copy (circuit->snd_stream, lsp->pdu);
3171
3172 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3173 {
3174 zlog_debug
Christian Franke812f2822015-11-10 18:33:16 +01003175 ("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
Josh Bailey3f045a02012-03-24 08:35:20 -07003176 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3177 rawlspid_print (lsp->lsp_header->lsp_id),
3178 ntohl (lsp->lsp_header->seq_num),
3179 ntohs (lsp->lsp_header->checksum),
3180 ntohs (lsp->lsp_header->rem_lifetime),
3181 circuit->interface->name);
3182 if (isis->debugs & DEBUG_PACKET_DUMP)
3183 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3184 stream_get_endp (circuit->snd_stream));
3185 }
3186
Christian Franke8253b732015-11-12 14:24:28 +01003187 clear_srm = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07003188 retval = circuit->tx (circuit, lsp->level);
3189 if (retval != ISIS_OK)
3190 {
Christian Franke8253b732015-11-12 14:24:28 +01003191 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
Josh Bailey3f045a02012-03-24 08:35:20 -07003192 circuit->area->area_tag, lsp->level,
Christian Franke8253b732015-11-12 14:24:28 +01003193 circuit->interface->name,
3194 (retval == ISIS_WARNING) ? "temporarily" : "permanently");
Josh Bailey3f045a02012-03-24 08:35:20 -07003195 }
3196
Christian Franke8253b732015-11-12 14:24:28 +01003197out:
3198 if (clear_srm
3199 || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST)
3200 || (retval != ISIS_OK && retval != ISIS_WARNING))
3201 {
3202 /* SRM flag will trigger retransmission. We will not retransmit if we
3203 * encountered a fatal error.
3204 * On success, they should only be cleared if it's a broadcast circuit.
3205 * On a P2P circuit, we will wait for the ack from the neighbor to clear
3206 * the fag.
3207 */
3208 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3209 }
Josh Bailey3f045a02012-03-24 08:35:20 -07003210
jardineb5d44e2003-12-23 08:09:43 +00003211 return retval;
hassof390d2c2004-09-10 20:48:21 +00003212}
jardineb5d44e2003-12-23 08:09:43 +00003213
3214int
hassof390d2c2004-09-10 20:48:21 +00003215ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3216 int level)
jardineb5d44e2003-12-23 08:09:43 +00003217{
3218 unsigned long lenp;
3219 int retval;
3220 u_int16_t length;
3221 struct isis_fixed_hdr fixed_hdr;
3222
Christian Frankef1fc1db2015-11-10 18:43:31 +01003223 isis_circuit_stream(circuit, &circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003224
Josh Bailey3f045a02012-03-24 08:35:20 -07003225 // fill_llc_hdr (stream);
3226 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003227 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3228 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003229 else
hassof390d2c2004-09-10 20:48:21 +00003230 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3231 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003232
3233
paul9985f832005-02-09 15:51:56 +00003234 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003235 stream_putw (circuit->snd_stream, 0); /* PDU length */
3236 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003237 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003238 stream_putc (circuit->snd_stream, 9); /* code */
3239 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003240
hassof390d2c2004-09-10 20:48:21 +00003241 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3242 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3243 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3244 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003245
paul9985f832005-02-09 15:51:56 +00003246 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003247 /* Update PDU length */
3248 stream_putw_at (circuit->snd_stream, lenp, length);
3249
3250 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003251 if (retval != ISIS_OK)
3252 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3253 circuit->area->area_tag, level,
3254 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003255
3256 return retval;
3257}