blob: 5f18135e871f28c922740e0db5cfd30136fcea42 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_pdu.c
3 * PDU processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "memory.h"
27#include "thread.h"
28#include "linklist.h"
29#include "log.h"
30#include "stream.h"
31#include "vty.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070032#include "hash.h"
jardineb5d44e2003-12-23 08:09:43 +000033#include "prefix.h"
34#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010035#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070036#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000037
38#include "isisd/dict.h"
39#include "isisd/include-netbsd/iso.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_adjacency.h"
44#include "isisd/isis_circuit.h"
45#include "isisd/isis_network.h"
46#include "isisd/isis_misc.h"
47#include "isisd/isis_dr.h"
jardineb5d44e2003-12-23 08:09:43 +000048#include "isisd/isis_tlv.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_lsp.h"
52#include "isisd/isis_pdu.h"
53#include "isisd/iso_checksum.h"
54#include "isisd/isis_csm.h"
55#include "isisd/isis_events.h"
56
jardineb5d44e2003-12-23 08:09:43 +000057#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000058#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000059
60#ifndef PNBBY
61#define PNBBY 8
62#endif /* PNBBY */
63
64/* Utility mask array. */
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -070065static u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000066 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
67};
68
69/*
70 * HELPER FUNCS
71 */
72
73/*
74 * Compares two sets of area addresses
75 */
hassof390d2c2004-09-10 20:48:21 +000076static int
jardineb5d44e2003-12-23 08:09:43 +000077area_match (struct list *left, struct list *right)
78{
79 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000080 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000081
hasso3fdb2dd2005-09-28 18:45:54 +000082 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000083 {
hasso3fdb2dd2005-09-28 18:45:54 +000084 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000085 {
86 if (addr1->addr_len == addr2->addr_len &&
87 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
88 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000089 }
90 }
91
hassof390d2c2004-09-10 20:48:21 +000092 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000093}
94
95/*
96 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
97 * param ip1 the IS interface ip address structure
98 * param ip2 the IIH's ip address
99 * return 0 the IIH's IP is not in the IS's subnetwork
100 * 1 the IIH's IP is in the IS's subnetwork
101 */
hasso92365882005-01-18 13:53:33 +0000102static int
hassof390d2c2004-09-10 20:48:21 +0000103ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000104{
105 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000106 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000107 int len;
hassof390d2c2004-09-10 20:48:21 +0000108
109 addr1 = (u_char *) & ip1->prefix.s_addr;
110 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000111 len = ip1->prefixlen;
112
113 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000114 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000115
hasso53c997c2004-09-15 16:21:59 +0000116 while (offsetloop--)
117 if (addr1[offsetloop] != addr2[offsetloop])
118 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000119
hassof390d2c2004-09-10 20:48:21 +0000120 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000121 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
122 return 0;
hassof390d2c2004-09-10 20:48:21 +0000123
124 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000125}
126
jardineb5d44e2003-12-23 08:09:43 +0000127/*
128 * Compares two set of ip addresses
129 * param left the local interface's ip addresses
130 * param right the iih interface's ip address
131 * return 0 no match;
132 * 1 match;
133 */
hassof390d2c2004-09-10 20:48:21 +0000134static int
jardineb5d44e2003-12-23 08:09:43 +0000135ip_match (struct list *left, struct list *right)
136{
137 struct prefix_ipv4 *ip1;
138 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000139 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000140
hassoe082ac12004-09-27 18:13:57 +0000141 if ((left == NULL) || (right == NULL))
142 return 0;
143
hasso3fdb2dd2005-09-28 18:45:54 +0000144 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000145 {
hasso3fdb2dd2005-09-28 18:45:54 +0000146 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000147 {
148 if (ip_same_subnet (ip1, ip2))
149 {
150 return 1; /* match */
151 }
jardineb5d44e2003-12-23 08:09:43 +0000152 }
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 }
155 return 0;
156}
157
158/*
159 * Checks whether we should accept a PDU of given level
160 */
161static int
162accept_level (int level, int circuit_t)
163{
hassof390d2c2004-09-10 20:48:21 +0000164 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000165
166 return retval;
167}
168
Josh Bailey3f045a02012-03-24 08:35:20 -0700169/*
170 * Verify authentication information
171 * Support cleartext and HMAC MD5 authentication
172 */
173static int
174authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
175 struct stream *stream, uint32_t auth_tlv_offset)
jardineb5d44e2003-12-23 08:09:43 +0000176{
Josh Bailey3f045a02012-03-24 08:35:20 -0700177 unsigned char digest[ISIS_AUTH_MD5_SIZE];
178
179 /* Auth fail () - passwd type mismatch */
180 if (local->type != remote->type)
181 return ISIS_ERROR;
182
183 switch (local->type)
184 {
185 /* No authentication required */
186 case ISIS_PASSWD_TYPE_UNUSED:
187 break;
188
189 /* Cleartext (ISO 10589) */
hassof390d2c2004-09-10 20:48:21 +0000190 case ISIS_PASSWD_TYPE_CLEARTXT:
Josh Bailey3f045a02012-03-24 08:35:20 -0700191 /* Auth fail () - passwd len mismatch */
192 if (remote->len != local->len)
193 return ISIS_ERROR;
194 return memcmp (local->passwd, remote->passwd, local->len);
195
196 /* HMAC MD5 (RFC 3567) */
197 case ISIS_PASSWD_TYPE_HMAC_MD5:
198 /* Auth fail () - passwd len mismatch */
199 if (remote->len != ISIS_AUTH_MD5_SIZE)
200 return ISIS_ERROR;
201 /* Set the authentication value to 0 before the check */
202 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
203 ISIS_AUTH_MD5_SIZE);
204 /* Compute the digest */
205 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
206 (unsigned char *) &(local->passwd), local->len,
207 (caddr_t) &digest);
208 /* Copy back the authentication value after the check */
209 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
210 remote->passwd, ISIS_AUTH_MD5_SIZE);
211 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
212
hassof390d2c2004-09-10 20:48:21 +0000213 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700214 zlog_err ("Unsupported authentication type");
215 return ISIS_ERROR;
216 }
217
218 /* Authentication pass when no authentication is configured */
219 return ISIS_OK;
220}
221
222static int
223lsp_authentication_check (struct stream *stream, struct isis_area *area,
224 int level, struct isis_passwd *passwd)
225{
226 struct isis_link_state_hdr *hdr;
227 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700228 uint16_t checksum, rem_lifetime, pdu_len;
Josh Bailey3f045a02012-03-24 08:35:20 -0700229 struct tlvs tlvs;
230 int retval = ISIS_OK;
231
232 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700233 pdu_len = ntohs (hdr->pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700234 expected |= TLVFLAG_AUTH_INFO;
235 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
236 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700237 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
Josh Bailey3f045a02012-03-24 08:35:20 -0700238 &expected, &found, &tlvs, &auth_tlv_offset);
239
240 if (retval != ISIS_OK)
241 {
242 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
243 "cksum 0x%04x, lifetime %us, len %u",
244 area->area_tag, level, rawlspid_print (hdr->lsp_id),
245 ntohl (hdr->seq_num), ntohs (hdr->checksum),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700246 ntohs (hdr->rem_lifetime), pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700247 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
248 (isis->debugs & DEBUG_PACKET_DUMP))
249 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
250 return retval;
hassof390d2c2004-09-10 20:48:21 +0000251 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700252
253 if (!(found & TLVFLAG_AUTH_INFO))
254 {
255 zlog_err ("No authentication tlv in LSP");
256 return ISIS_ERROR;
257 }
258
259 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
260 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
261 {
262 zlog_err ("Unknown authentication type in LSP");
263 return ISIS_ERROR;
264 }
265
266 /*
267 * RFC 5304 set checksum and remaining lifetime to zero before
268 * verification and reset to old values after verification.
269 */
270 checksum = hdr->checksum;
271 rem_lifetime = hdr->rem_lifetime;
272 hdr->checksum = 0;
273 hdr->rem_lifetime = 0;
274 retval = authentication_check (&tlvs.auth_info, passwd, stream,
275 auth_tlv_offset);
276 hdr->checksum = checksum;
277 hdr->rem_lifetime = rem_lifetime;
278
279 return retval;
jardineb5d44e2003-12-23 08:09:43 +0000280}
281
282/*
283 * Processing helper functions
284 */
hasso92365882005-01-18 13:53:33 +0000285static void
Josh Bailey3f045a02012-03-24 08:35:20 -0700286del_addr (void *val)
287{
288 XFREE (MTYPE_ISIS_TMP, val);
289}
290
291static void
292tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
293{
294 struct listnode *node;
295 struct area_addr *area_addr, *malloced;
296
297 if (adj->area_addrs)
298 {
299 adj->area_addrs->del = del_addr;
300 list_delete (adj->area_addrs);
301 }
302 adj->area_addrs = list_new ();
303 if (tlvs->area_addrs)
304 {
305 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
306 {
307 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
308 memcpy (malloced, area_addr, sizeof (struct area_addr));
309 listnode_add (adj->area_addrs, malloced);
310 }
311 }
312}
313
David Lamparter655071f2012-05-08 13:32:53 +0200314static int
hassof390d2c2004-09-10 20:48:21 +0000315tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000316{
317 int i;
318 struct nlpids *tlv_nlpids;
319
hassof390d2c2004-09-10 20:48:21 +0000320 if (tlvs->nlpids)
321 {
jardineb5d44e2003-12-23 08:09:43 +0000322
hassof390d2c2004-09-10 20:48:21 +0000323 tlv_nlpids = tlvs->nlpids;
David Lamparter655071f2012-05-08 13:32:53 +0200324 if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
325 return 1;
jardineb5d44e2003-12-23 08:09:43 +0000326
hassof390d2c2004-09-10 20:48:21 +0000327 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000328
hassof390d2c2004-09-10 20:48:21 +0000329 for (i = 0; i < tlv_nlpids->count; i++)
330 {
331 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
332 }
jardineb5d44e2003-12-23 08:09:43 +0000333 }
David Lamparter655071f2012-05-08 13:32:53 +0200334 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000335}
336
hasso92365882005-01-18 13:53:33 +0000337static void
hassof390d2c2004-09-10 20:48:21 +0000338tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000339{
hasso3fdb2dd2005-09-28 18:45:54 +0000340 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000341 struct in_addr *ipv4_addr, *malloced;
342
hassof390d2c2004-09-10 20:48:21 +0000343 if (adj->ipv4_addrs)
344 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700345 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000346 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000347 }
hassof390d2c2004-09-10 20:48:21 +0000348 adj->ipv4_addrs = list_new ();
349 if (tlvs->ipv4_addrs)
350 {
hasso3fdb2dd2005-09-28 18:45:54 +0000351 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000352 {
353 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
354 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
355 listnode_add (adj->ipv4_addrs, malloced);
356 }
357 }
jardineb5d44e2003-12-23 08:09:43 +0000358}
359
360#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000361static void
hassof390d2c2004-09-10 20:48:21 +0000362tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000363{
hasso3fdb2dd2005-09-28 18:45:54 +0000364 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000365 struct in6_addr *ipv6_addr, *malloced;
366
hassof390d2c2004-09-10 20:48:21 +0000367 if (adj->ipv6_addrs)
368 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700369 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000370 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000371 }
hassof390d2c2004-09-10 20:48:21 +0000372 adj->ipv6_addrs = list_new ();
373 if (tlvs->ipv6_addrs)
374 {
hasso3fdb2dd2005-09-28 18:45:54 +0000375 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000376 {
377 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
378 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
379 listnode_add (adj->ipv6_addrs, malloced);
380 }
381 }
jardineb5d44e2003-12-23 08:09:43 +0000382
383}
384#endif /* HAVE_IPV6 */
385
jardineb5d44e2003-12-23 08:09:43 +0000386/*
387 * RECEIVE SIDE
388 */
389
390/*
391 * Process P2P IIH
392 * ISO - 10589
393 * Section 8.2.5 - Receiving point-to-point IIH PDUs
394 *
395 */
396static int
397process_p2p_hello (struct isis_circuit *circuit)
398{
399 int retval = ISIS_OK;
400 struct isis_p2p_hello_hdr *hdr;
401 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700402 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700403 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000404 struct tlvs tlvs;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200405 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000406
Josh Bailey3f045a02012-03-24 08:35:20 -0700407 if (isis->debugs & DEBUG_ADJ_PACKETS)
408 {
409 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
410 circuit->area->area_tag, circuit->interface->name,
411 circuit_t2string (circuit->is_type), circuit->circuit_id);
412 if (isis->debugs & DEBUG_PACKET_DUMP)
413 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
414 stream_get_endp (circuit->rcv_stream));
415 }
416
417 if (circuit->circ_type != CIRCUIT_T_P2P)
418 {
419 zlog_warn ("p2p hello on non p2p circuit");
420 return ISIS_WARNING;
421 }
422
hassof390d2c2004-09-10 20:48:21 +0000423 if ((stream_get_endp (circuit->rcv_stream) -
424 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
425 {
426 zlog_warn ("Packet too short");
427 return ISIS_WARNING;
428 }
jardineb5d44e2003-12-23 08:09:43 +0000429
430 /* 8.2.5.1 PDU acceptance tests */
431
432 /* 8.2.5.1 a) external domain untrue */
433 /* FIXME: not useful at all? */
434
435 /* 8.2.5.1 b) ID Length mismatch */
436 /* checked at the handle_pdu */
437
438 /* 8.2.5.2 IIH PDU Processing */
439
440 /* 8.2.5.2 a) 1) Maximum Area Addresses */
441 /* Already checked, and can also be ommited */
442
443 /*
444 * Get the header
445 */
hassof390d2c2004-09-10 20:48:21 +0000446 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700447 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000448
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700449 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
450 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700451 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000452 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700453 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
454 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700455 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700456 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000457 }
jardineb5d44e2003-12-23 08:09:43 +0000458
jardineb5d44e2003-12-23 08:09:43 +0000459 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700460 * Set the stream endp to PDU length, ignoring additional padding
461 * introduced by transport chips.
462 */
463 if (pdu_len < stream_get_endp (circuit->rcv_stream))
464 stream_set_endp (circuit->rcv_stream, pdu_len);
465
466 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
467
468 /*
jardineb5d44e2003-12-23 08:09:43 +0000469 * Lets get the TLVS now
470 */
471 expected |= TLVFLAG_AREA_ADDRS;
472 expected |= TLVFLAG_AUTH_INFO;
473 expected |= TLVFLAG_NLPID;
474 expected |= TLVFLAG_IPV4_ADDR;
475 expected |= TLVFLAG_IPV6_ADDR;
476
Josh Bailey3f045a02012-03-24 08:35:20 -0700477 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000478 retval = parse_tlvs (circuit->area->area_tag,
479 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700480 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
481 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000482
hassof390d2c2004-09-10 20:48:21 +0000483 if (retval > ISIS_WARNING)
484 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700485 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000486 free_tlvs (&tlvs);
487 return retval;
488 };
jardineb5d44e2003-12-23 08:09:43 +0000489
Josh Bailey3f045a02012-03-24 08:35:20 -0700490 if (!(found & TLVFLAG_AREA_ADDRS))
491 {
492 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
493 free_tlvs (&tlvs);
494 return ISIS_WARNING;
495 }
496
David Lamparterb72f3452012-11-27 01:10:26 +0000497 if (!(found & TLVFLAG_NLPID))
498 {
499 zlog_warn ("No supported protocols TLV in P2P IS to IS hello");
500 free_tlvs (&tlvs);
501 return ISIS_WARNING;
502 }
503
jardineb5d44e2003-12-23 08:09:43 +0000504 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000505 if (circuit->passwd.type)
506 {
507 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700508 authentication_check (&tlvs.auth_info, &circuit->passwd,
509 circuit->rcv_stream, auth_tlv_offset))
510 {
511 isis_event_auth_failure (circuit->area->area_tag,
512 "P2P hello authentication failure",
513 hdr->source_id);
514 free_tlvs (&tlvs);
515 return ISIS_OK;
516 }
jardineb5d44e2003-12-23 08:09:43 +0000517 }
jardineb5d44e2003-12-23 08:09:43 +0000518
Josh Bailey3f045a02012-03-24 08:35:20 -0700519 /*
520 * check if it's own interface ip match iih ip addrs
521 */
David Lamparter28a8cfc2014-06-29 13:48:18 +0200522 if (found & TLVFLAG_IPV4_ADDR)
Josh Bailey3f045a02012-03-24 08:35:20 -0700523 {
David Lamparter28a8cfc2014-06-29 13:48:18 +0200524 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
525 v4_usable = 1;
526 else
527 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
528 "in P2P IIH from %s\n", circuit->interface->name);
529 }
530#ifndef HAVE_IPV6
531 else /* !(found & TLVFLAG_IPV4_ADDR) */
532 zlog_warn ("ISIS-Adj: no IPv4 in P2P IIH from %s "
533 "(this isisd has no IPv6)\n", circuit->interface->name);
534
535#else
536 if (found & TLVFLAG_IPV6_ADDR)
537 {
538 /* TBA: check that we have a linklocal ourselves? */
539 struct listnode *node;
540 struct prefix_ipv6 *ip;
541 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
542 if (IN6_IS_ADDR_LINKLOCAL (ip))
543 {
544 v6_usable = 1;
545 break;
546 }
547
548 if (!v6_usable)
549 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
550 "in P2P IIH from %s\n", circuit->interface->name);
551 }
552
553 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
554 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n",
555 circuit->interface->name);
556#endif
557
558 if (!v6_usable && !v4_usable)
559 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700560 free_tlvs (&tlvs);
561 return ISIS_WARNING;
562 }
563
564 /*
565 * My interpertation of the ISO, if no adj exists we will create one for
566 * the circuit
567 */
568 adj = circuit->u.p2p.neighbor;
569 if (!adj || adj->level != hdr->circuit_t)
570 {
571 if (!adj)
572 {
573 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
574 if (adj == NULL)
575 return ISIS_ERROR;
576 }
577 else
578 {
579 adj->level = hdr->circuit_t;
580 }
581 circuit->u.p2p.neighbor = adj;
582 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
583 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
584 }
585
586 /* 8.2.6 Monitoring point-to-point adjacencies */
587 adj->hold_time = ntohs (hdr->hold_time);
588 adj->last_upd = time (NULL);
589
jardineb5d44e2003-12-23 08:09:43 +0000590 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700591 tlvs_to_adj_area_addrs (&tlvs, adj);
592
593 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +0000594 if (tlvs_to_adj_nlpids (&tlvs, adj))
595 {
596 free_tlvs (&tlvs);
597 return ISIS_WARNING;
598 }
jardineb5d44e2003-12-23 08:09:43 +0000599
600 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700601 if (found & TLVFLAG_IPV4_ADDR)
602 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000603
604#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700605 if (found & TLVFLAG_IPV6_ADDR)
606 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000607#endif /* HAVE_IPV6 */
608
609 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000610 THREAD_TIMER_OFF (adj->t_expire);
611 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
612 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000613
614 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000615 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
616 {
617 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
618 if (circuit->area->is_type == IS_LEVEL_1)
619 {
620 switch (hdr->circuit_t)
621 {
622 case IS_LEVEL_1:
623 case IS_LEVEL_1_AND_2:
624 if (adj->adj_state != ISIS_ADJ_UP)
625 {
626 /* (4) adj state up */
627 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
628 /* (5) adj usage level 1 */
629 adj->adj_usage = ISIS_ADJ_LEVEL1;
630 }
631 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
632 {
633 ; /* accept */
634 }
635 break;
636 case IS_LEVEL_2:
637 if (adj->adj_state != ISIS_ADJ_UP)
638 {
639 /* (7) reject - wrong system type event */
640 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700641 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000642 return ISIS_WARNING; /* Reject */
643 }
644 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
645 {
646 /* (6) down - wrong system */
647 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
648 }
649 break;
650 }
651 }
jardineb5d44e2003-12-23 08:09:43 +0000652
hassof390d2c2004-09-10 20:48:21 +0000653 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
654 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
655 {
656 switch (hdr->circuit_t)
657 {
658 case IS_LEVEL_1:
659 if (adj->adj_state != ISIS_ADJ_UP)
660 {
661 /* (6) adj state up */
662 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
663 /* (7) adj usage level 1 */
664 adj->adj_usage = ISIS_ADJ_LEVEL1;
665 }
666 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
667 {
668 ; /* accept */
669 }
670 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
671 (adj->adj_usage == ISIS_ADJ_LEVEL2))
672 {
673 /* (8) down - wrong system */
674 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
675 }
676 break;
677 case IS_LEVEL_2:
678 if (adj->adj_state != ISIS_ADJ_UP)
679 {
680 /* (6) adj state up */
681 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
682 /* (9) adj usage level 2 */
683 adj->adj_usage = ISIS_ADJ_LEVEL2;
684 }
685 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
686 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
687 {
688 /* (8) down - wrong system */
689 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
690 }
691 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
692 {
693 ; /* Accept */
694 }
695 break;
696 case IS_LEVEL_1_AND_2:
697 if (adj->adj_state != ISIS_ADJ_UP)
698 {
699 /* (6) adj state up */
700 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
701 /* (10) adj usage level 1 */
702 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
703 }
704 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
705 (adj->adj_usage == ISIS_ADJ_LEVEL2))
706 {
707 /* (8) down - wrong system */
708 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
709 }
710 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
711 {
712 ; /* Accept */
713 }
714 break;
715 }
716 }
jardineb5d44e2003-12-23 08:09:43 +0000717
hassof390d2c2004-09-10 20:48:21 +0000718 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
719 if (circuit->area->is_type == IS_LEVEL_2)
720 {
721 switch (hdr->circuit_t)
722 {
723 case IS_LEVEL_1:
724 if (adj->adj_state != ISIS_ADJ_UP)
725 {
726 /* (5) reject - wrong system type event */
727 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700728 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000729 return ISIS_WARNING; /* Reject */
730 }
731 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
732 (adj->adj_usage == ISIS_ADJ_LEVEL2))
733 {
734 /* (6) down - wrong system */
735 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
736 }
737 break;
738 case IS_LEVEL_1_AND_2:
739 case IS_LEVEL_2:
740 if (adj->adj_state != ISIS_ADJ_UP)
741 {
742 /* (7) adj state up */
743 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
744 /* (8) adj usage level 2 */
745 adj->adj_usage = ISIS_ADJ_LEVEL2;
746 }
747 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
748 {
749 /* (6) down - wrong system */
750 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
751 }
752 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
753 {
754 ; /* Accept */
755 }
756 break;
757 }
758 }
jardineb5d44e2003-12-23 08:09:43 +0000759 }
jardineb5d44e2003-12-23 08:09:43 +0000760 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700761 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000762 {
hassof390d2c2004-09-10 20:48:21 +0000763 if (circuit->area->is_type == IS_LEVEL_1)
764 {
765 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
766 if (adj->adj_state != ISIS_ADJ_UP)
767 {
768 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
769 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
770 }
771 else
772 {
773 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
774 "Down - Area Mismatch");
775 }
776 }
777 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
778 else
779 {
780 switch (hdr->circuit_t)
781 {
782 case IS_LEVEL_1:
783 if (adj->adj_state != ISIS_ADJ_UP)
784 {
785 /* (6) reject - Area Mismatch event */
786 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700787 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000788 return ISIS_WARNING; /* Reject */
789 }
790 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
791 {
792 /* (7) down - area mismatch */
793 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000794
hassof390d2c2004-09-10 20:48:21 +0000795 }
796 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
797 (adj->adj_usage == ISIS_ADJ_LEVEL2))
798 {
799 /* (7) down - wrong system */
800 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
801 }
802 break;
803 case IS_LEVEL_1_AND_2:
804 case IS_LEVEL_2:
805 if (adj->adj_state != ISIS_ADJ_UP)
806 {
807 /* (8) adj state up */
808 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
809 /* (9) adj usage level 2 */
810 adj->adj_usage = ISIS_ADJ_LEVEL2;
811 }
812 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
813 {
814 /* (7) down - wrong system */
815 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
816 }
817 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
818 {
819 if (hdr->circuit_t == IS_LEVEL_2)
820 {
821 /* (7) down - wrong system */
822 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
823 "Wrong System");
824 }
825 else
826 {
827 /* (7) down - area mismatch */
828 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
829 "Area Mismatch");
830 }
831 }
832 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
833 {
834 ; /* Accept */
835 }
836 break;
837 }
838 }
jardineb5d44e2003-12-23 08:09:43 +0000839 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700840 else
841 {
842 /* down - area mismatch */
843 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
844 }
jardineb5d44e2003-12-23 08:09:43 +0000845 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
846 /* FIXME - Missing parts */
847
jardineb5d44e2003-12-23 08:09:43 +0000848 /* some of my own understanding of the ISO, why the heck does
849 * it not say what should I change the system_type to...
850 */
hassof390d2c2004-09-10 20:48:21 +0000851 switch (adj->adj_usage)
852 {
jardineb5d44e2003-12-23 08:09:43 +0000853 case ISIS_ADJ_LEVEL1:
854 adj->sys_type = ISIS_SYSTYPE_L1_IS;
855 break;
856 case ISIS_ADJ_LEVEL2:
857 adj->sys_type = ISIS_SYSTYPE_L2_IS;
858 break;
859 case ISIS_ADJ_LEVEL1AND2:
860 adj->sys_type = ISIS_SYSTYPE_L2_IS;
861 break;
862 case ISIS_ADJ_NONE:
863 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
864 break;
hassof390d2c2004-09-10 20:48:21 +0000865 }
jardineb5d44e2003-12-23 08:09:43 +0000866
867 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700868
869 if (isis->debugs & DEBUG_ADJ_PACKETS)
870 {
871 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
872 " cir id %02d, length %d",
873 circuit->area->area_tag, circuit->interface->name,
874 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700875 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700876 }
jardineb5d44e2003-12-23 08:09:43 +0000877
878 free_tlvs (&tlvs);
879
880 return retval;
881}
882
jardineb5d44e2003-12-23 08:09:43 +0000883/*
884 * Process IS-IS LAN Level 1/2 Hello PDU
885 */
hassof390d2c2004-09-10 20:48:21 +0000886static int
887process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000888{
889 int retval = ISIS_OK;
890 struct isis_lan_hello_hdr hdr;
891 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700892 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000893 struct tlvs tlvs;
894 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000895 struct listnode *node;
David Lamparter28a8cfc2014-06-29 13:48:18 +0200896 int v4_usable = 0, v6_usable = 0;
jardineb5d44e2003-12-23 08:09:43 +0000897
Josh Bailey3f045a02012-03-24 08:35:20 -0700898 if (isis->debugs & DEBUG_ADJ_PACKETS)
899 {
900 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
901 "cirID %u",
902 circuit->area->area_tag, level, circuit->interface->name,
903 circuit_t2string (circuit->is_type), circuit->circuit_id);
904 if (isis->debugs & DEBUG_PACKET_DUMP)
905 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
906 stream_get_endp (circuit->rcv_stream));
907 }
908
909 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
910 {
911 zlog_warn ("lan hello on non broadcast circuit");
912 return ISIS_WARNING;
913 }
914
hassof390d2c2004-09-10 20:48:21 +0000915 if ((stream_get_endp (circuit->rcv_stream) -
916 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
917 {
918 zlog_warn ("Packet too short");
919 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000920 }
hassof390d2c2004-09-10 20:48:21 +0000921
922 if (circuit->ext_domain)
923 {
hasso529d65b2004-12-24 00:14:50 +0000924 zlog_debug ("level %d LAN Hello received over circuit with "
925 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000926 return ISIS_WARNING;
927 }
928
Josh Bailey3f045a02012-03-24 08:35:20 -0700929 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000930 {
931 if (isis->debugs & DEBUG_ADJ_PACKETS)
932 {
hasso529d65b2004-12-24 00:14:50 +0000933 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
934 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000935 }
936 return ISIS_WARNING;
937 }
jardineb5d44e2003-12-23 08:09:43 +0000938
939#if 0
940 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000941 if (!accept_level (level, circuit->area->is_type))
942 {
943 if (isis->debugs & DEBUG_ADJ_PACKETS)
944 {
hasso529d65b2004-12-24 00:14:50 +0000945 zlog_debug ("ISIS-Adj (%s): is type mismatch",
946 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000947 }
948 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000949 }
jardineb5d44e2003-12-23 08:09:43 +0000950#endif
951 /*
952 * Fill the header
953 */
954 hdr.circuit_t = stream_getc (circuit->rcv_stream);
955 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
956 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000957 hdr.pdu_len = stream_getw (circuit->rcv_stream);
958 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000959 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
960
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700961 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
962 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700963 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000964 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700965 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
966 "invalid pdu length %d",
967 circuit->area->area_tag, circuit->interface->name,
968 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700969 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700970 }
971
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700972 /*
973 * Set the stream endp to PDU length, ignoring additional padding
974 * introduced by transport chips.
975 */
976 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
977 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
978
Josh Bailey3f045a02012-03-24 08:35:20 -0700979 if (hdr.circuit_t != IS_LEVEL_1 &&
980 hdr.circuit_t != IS_LEVEL_2 &&
981 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
982 (level & hdr.circuit_t) == 0)
983 {
984 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
985 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000986 return ISIS_ERROR;
987 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700988
jardineb5d44e2003-12-23 08:09:43 +0000989 /*
990 * Then get the tlvs
991 */
992 expected |= TLVFLAG_AUTH_INFO;
993 expected |= TLVFLAG_AREA_ADDRS;
994 expected |= TLVFLAG_LAN_NEIGHS;
995 expected |= TLVFLAG_NLPID;
996 expected |= TLVFLAG_IPV4_ADDR;
997 expected |= TLVFLAG_IPV6_ADDR;
998
Josh Bailey3f045a02012-03-24 08:35:20 -0700999 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001000 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -07001001 STREAM_PNT (circuit->rcv_stream),
1002 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
1003 &expected, &found, &tlvs,
1004 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001005
hassof390d2c2004-09-10 20:48:21 +00001006 if (retval > ISIS_WARNING)
1007 {
1008 zlog_warn ("parse_tlvs() failed");
1009 goto out;
1010 }
jardineb5d44e2003-12-23 08:09:43 +00001011
hassof390d2c2004-09-10 20:48:21 +00001012 if (!(found & TLVFLAG_AREA_ADDRS))
1013 {
1014 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
1015 level);
jardineb5d44e2003-12-23 08:09:43 +00001016 retval = ISIS_WARNING;
1017 goto out;
1018 }
hassof390d2c2004-09-10 20:48:21 +00001019
David Lamparterb72f3452012-11-27 01:10:26 +00001020 if (!(found & TLVFLAG_NLPID))
1021 {
1022 zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
1023 level);
1024 retval = ISIS_WARNING;
1025 goto out;
1026 }
1027
Josh Bailey3f045a02012-03-24 08:35:20 -07001028 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +00001029 if (circuit->passwd.type)
1030 {
1031 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001032 authentication_check (&tlvs.auth_info, &circuit->passwd,
1033 circuit->rcv_stream, auth_tlv_offset))
1034 {
1035 isis_event_auth_failure (circuit->area->area_tag,
1036 "LAN hello authentication failure",
1037 hdr.source_id);
1038 retval = ISIS_WARNING;
1039 goto out;
1040 }
hassof390d2c2004-09-10 20:48:21 +00001041 }
jardineb5d44e2003-12-23 08:09:43 +00001042
David Lamparter19f78ce2012-11-27 01:10:25 +00001043 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
1044 {
1045 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
1046 circuit->area->area_tag, circuit->interface->name);
1047 return ISIS_WARNING;
1048 }
1049
jardineb5d44e2003-12-23 08:09:43 +00001050 /*
1051 * Accept the level 1 adjacency only if a match between local and
1052 * remote area addresses is found
1053 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001054 if (listcount (circuit->area->area_addrs) == 0 ||
1055 (level == IS_LEVEL_1 &&
1056 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +00001057 {
1058 if (isis->debugs & DEBUG_ADJ_PACKETS)
1059 {
hasso529d65b2004-12-24 00:14:50 +00001060 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1061 circuit->area->area_tag, level,
1062 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001063 }
1064 retval = ISIS_OK;
1065 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001066 }
jardineb5d44e2003-12-23 08:09:43 +00001067
1068 /*
1069 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001070 */
1071 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1072 {
hasso529d65b2004-12-24 00:14:50 +00001073 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1074 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001075
hassof390d2c2004-09-10 20:48:21 +00001076 retval = ISIS_OK;
1077 goto out;
1078 }
jardineb5d44e2003-12-23 08:09:43 +00001079
1080 /*
1081 * check if it's own interface ip match iih ip addrs
1082 */
David Lamparter28a8cfc2014-06-29 13:48:18 +02001083 if (found & TLVFLAG_IPV4_ADDR)
hassof390d2c2004-09-10 20:48:21 +00001084 {
David Lamparter28a8cfc2014-06-29 13:48:18 +02001085 if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
1086 v4_usable = 1;
1087 else
1088 zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
1089 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001090 }
David Lamparter28a8cfc2014-06-29 13:48:18 +02001091#ifndef HAVE_IPV6
1092 else /* !(found & TLVFLAG_IPV4_ADDR) */
1093 zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s "
1094 "(this isisd has no IPv6)\n", circuit->interface->name);
1095
1096#else
1097 if (found & TLVFLAG_IPV6_ADDR)
1098 {
1099 /* TBA: check that we have a linklocal ourselves? */
1100 struct listnode *node;
1101 struct prefix_ipv6 *ip;
1102 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
1103 if (IN6_IS_ADDR_LINKLOCAL (ip))
1104 {
1105 v6_usable = 1;
1106 break;
1107 }
1108
1109 if (!v6_usable)
1110 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
1111 "in LAN IIH from %s\n", circuit->interface->name);
1112 }
1113
1114 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
1115 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
1116 circuit->interface->name);
1117#endif
1118
1119 if (!v6_usable && !v4_usable)
1120 {
1121 free_tlvs (&tlvs);
1122 return ISIS_WARNING;
1123 }
1124
jardineb5d44e2003-12-23 08:09:43 +00001125
1126 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001127 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1128 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001129 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001130 if (!adj)
1131 {
1132 /*
1133 * Do as in 8.4.2.5
1134 */
1135 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1136 if (adj == NULL)
1137 {
1138 retval = ISIS_ERROR;
1139 goto out;
1140 }
1141 }
1142 else
1143 {
1144 if (ssnpa) {
1145 memcpy (adj->snpa, ssnpa, 6);
1146 } else {
1147 memset (adj->snpa, ' ', 6);
1148 }
1149 adj->level = level;
1150 }
hassof390d2c2004-09-10 20:48:21 +00001151 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001152
Josh Bailey3f045a02012-03-24 08:35:20 -07001153 if (level == IS_LEVEL_1)
1154 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001155 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001156 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001157 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1158 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001159 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001160 }
jardineb5d44e2003-12-23 08:09:43 +00001161
hassoa211d652004-09-20 14:55:29 +00001162 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1163 switch (level)
1164 {
1165 case 1:
1166 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1167 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001168 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001169 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1170 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001171 }
1172 break;
1173 case 2:
1174 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1175 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001176 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001177 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1178 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001179 }
1180 break;
1181 }
jardineb5d44e2003-12-23 08:09:43 +00001182
1183 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001184 adj->last_upd = time (NULL);
1185 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001186
1187 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1188
Josh Bailey3f045a02012-03-24 08:35:20 -07001189 tlvs_to_adj_area_addrs (&tlvs, adj);
1190
jardineb5d44e2003-12-23 08:09:43 +00001191 /* which protocol are spoken ??? */
David Lamparterb72f3452012-11-27 01:10:26 +00001192 if (tlvs_to_adj_nlpids (&tlvs, adj))
1193 {
1194 retval = ISIS_WARNING;
1195 goto out;
1196 }
jardineb5d44e2003-12-23 08:09:43 +00001197
1198 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001199 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001200 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1201
1202#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001203 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001204 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1205#endif /* HAVE_IPV6 */
1206
1207 adj->circuit_t = hdr.circuit_t;
1208
1209 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001210 THREAD_TIMER_OFF (adj->t_expire);
1211 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001212 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001213
1214 /*
1215 * If the snpa for this circuit is found from LAN Neighbours TLV
1216 * we have two-way communication -> adjacency can be put to state "up"
1217 */
1218
hassof390d2c2004-09-10 20:48:21 +00001219 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001220 {
1221 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001222 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001223 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1224 {
1225 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1226 {
1227 isis_adj_state_change (adj, ISIS_ADJ_UP,
1228 "own SNPA found in LAN Neighbours TLV");
1229 }
1230 }
jardineb5d44e2003-12-23 08:09:43 +00001231 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001232 else
1233 {
1234 int found = 0;
1235 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1236 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1237 {
1238 found = 1;
1239 break;
1240 }
1241 if (found == 0)
1242 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1243 "own SNPA not found in LAN Neighbours TLV");
1244 }
1245 }
1246 else if (adj->adj_state == ISIS_ADJ_UP)
1247 {
1248 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1249 "no LAN Neighbours TLV found");
1250 }
jardineb5d44e2003-12-23 08:09:43 +00001251
hassof390d2c2004-09-10 20:48:21 +00001252out:
hassof390d2c2004-09-10 20:48:21 +00001253 if (isis->debugs & DEBUG_ADJ_PACKETS)
1254 {
hasso529d65b2004-12-24 00:14:50 +00001255 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
1256 "cirID %u, length %ld",
1257 circuit->area->area_tag,
1258 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001259 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001260 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001261 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001262 }
jardineb5d44e2003-12-23 08:09:43 +00001263
1264 free_tlvs (&tlvs);
1265
1266 return retval;
1267}
1268
1269/*
1270 * Process Level 1/2 Link State
1271 * ISO - 10589
1272 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001273 */
1274static int
1275process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001276{
1277 struct isis_link_state_hdr *hdr;
1278 struct isis_adjacency *adj = NULL;
1279 struct isis_lsp *lsp, *lsp0 = NULL;
1280 int retval = ISIS_OK, comp = 0;
1281 u_char lspid[ISIS_SYS_ID_LEN + 2];
1282 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001283 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001284
Josh Bailey3f045a02012-03-24 08:35:20 -07001285 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1286 {
1287 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1288 circuit->area->area_tag, level, circuit->interface->name,
1289 circuit_t2string (circuit->is_type), circuit->circuit_id);
1290 if (isis->debugs & DEBUG_PACKET_DUMP)
1291 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1292 stream_get_endp (circuit->rcv_stream));
1293 }
1294
hassof390d2c2004-09-10 20:48:21 +00001295 if ((stream_get_endp (circuit->rcv_stream) -
1296 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1297 {
1298 zlog_warn ("Packet too short");
1299 return ISIS_WARNING;
1300 }
jardineb5d44e2003-12-23 08:09:43 +00001301
1302 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001303 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001304 pdu_len = ntohs (hdr->pdu_len);
1305
1306 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001307 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001308 pdu_len > ISO_MTU(circuit) ||
1309 pdu_len > stream_get_endp (circuit->rcv_stream))
1310 {
1311 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1312 circuit->area->area_tag,
1313 rawlspid_print (hdr->lsp_id), pdu_len);
1314
1315 return ISIS_WARNING;
1316 }
1317
1318 /*
1319 * Set the stream endp to PDU length, ignoring additional padding
1320 * introduced by transport chips.
1321 */
1322 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1323 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001324
hassof390d2c2004-09-10 20:48:21 +00001325 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1326 {
hasso529d65b2004-12-24 00:14:50 +00001327 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001328 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001329 circuit->area->area_tag,
1330 level,
1331 rawlspid_print (hdr->lsp_id),
1332 ntohl (hdr->seq_num),
1333 ntohs (hdr->checksum),
1334 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001335 pdu_len,
paul15935e92005-05-03 09:27:23 +00001336 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001337 }
jardineb5d44e2003-12-23 08:09:43 +00001338
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001339 /* lsp is_type check */
1340 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1341 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001342 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001343 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001344 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001345 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1346 /* continue as per RFC1122 Be liberal in what you accept, and
1347 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001348 }
jardineb5d44e2003-12-23 08:09:43 +00001349
1350 /* Checksum sanity check - FIXME: move to correct place */
1351 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001352 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001353 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001354 {
hasso529d65b2004-12-24 00:14:50 +00001355 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1356 circuit->area->area_tag,
1357 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001358
hassof390d2c2004-09-10 20:48:21 +00001359 return ISIS_WARNING;
1360 }
jardineb5d44e2003-12-23 08:09:43 +00001361
1362 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001363 if (circuit->ext_domain)
1364 {
hasso529d65b2004-12-24 00:14:50 +00001365 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001366 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1367 "externalDomain = true", circuit->area->area_tag,
1368 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001369
hassof390d2c2004-09-10 20:48:21 +00001370 return ISIS_WARNING;
1371 }
jardineb5d44e2003-12-23 08:09:43 +00001372
1373 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001374 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001375 {
hasso529d65b2004-12-24 00:14:50 +00001376 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1377 " type %s",
1378 circuit->area->area_tag,
1379 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001380 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001381
hassof390d2c2004-09-10 20:48:21 +00001382 return ISIS_WARNING;
1383 }
jardineb5d44e2003-12-23 08:09:43 +00001384
1385 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1386
1387 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1388
1389 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001390 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1391 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001392 if (passwd->type)
1393 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001394 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1395 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001396 {
1397 isis_event_auth_failure (circuit->area->area_tag,
1398 "LSP authentication failure", hdr->lsp_id);
1399 return ISIS_WARNING;
1400 }
jardineb5d44e2003-12-23 08:09:43 +00001401 }
jardineb5d44e2003-12-23 08:09:43 +00001402 /* Find the LSP in our database and compare it to this Link State header */
1403 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1404 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001405 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1406 hdr->checksum, hdr->rem_lifetime);
1407 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001408#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001409 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001410#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001411 ))
jardineb5d44e2003-12-23 08:09:43 +00001412 goto dontcheckadj;
1413
1414 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1415 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001416
hassof390d2c2004-09-10 20:48:21 +00001417 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1418 {
1419 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1420 if (!adj)
1421 {
hasso529d65b2004-12-24 00:14:50 +00001422 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1423 "lifetime %us on %s",
1424 circuit->area->area_tag,
1425 rawlspid_print (hdr->lsp_id),
1426 ntohl (hdr->seq_num),
1427 ntohs (hdr->checksum),
1428 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001429 return ISIS_WARNING; /* Silently discard */
1430 }
jardineb5d44e2003-12-23 08:09:43 +00001431 }
jardineb5d44e2003-12-23 08:09:43 +00001432 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001433 else
1434 {
1435 /* If no adj, or no sharing of level */
1436 if (!circuit->u.p2p.neighbor)
1437 {
1438 return ISIS_OK; /* Silently discard */
1439 }
1440 else
1441 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001442 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001443 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001444 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001445 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1446 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001447 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001448 }
jardineb5d44e2003-12-23 08:09:43 +00001449 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001450
hassof390d2c2004-09-10 20:48:21 +00001451dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001452 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1453
1454 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1455
hassof390d2c2004-09-10 20:48:21 +00001456 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001457
hassof390d2c2004-09-10 20:48:21 +00001458 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1459 if (hdr->rem_lifetime == 0)
1460 {
1461 if (!lsp)
1462 {
1463 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1464 /* only needed on explicit update, eg - p2p */
1465 if (circuit->circ_type == CIRCUIT_T_P2P)
1466 ack_lsp (hdr, circuit, level);
1467 return retval; /* FIXME: do we need a purge? */
1468 }
1469 else
1470 {
1471 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1472 {
1473 /* LSP by some other system -> do 7.3.16.4 b) */
1474 /* 7.3.16.4 b) 1) */
1475 if (comp == LSP_NEWER)
1476 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001477 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001478 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001479 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001480 /* iii */
1481 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1482 /* v */
1483 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1484 /* iv */
1485 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1486 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001487
hassof390d2c2004-09-10 20:48:21 +00001488 } /* 7.3.16.4 b) 2) */
1489 else if (comp == LSP_EQUAL)
1490 {
1491 /* i */
1492 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1493 /* ii */
1494 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1495 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1496 } /* 7.3.16.4 b) 3) */
1497 else
1498 {
1499 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1500 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1501 }
1502 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001503 else if (lsp->lsp_header->rem_lifetime != 0)
1504 {
1505 /* our own LSP -> 7.3.16.4 c) */
1506 if (comp == LSP_NEWER)
1507 {
1508 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1509 lsp_set_all_srmflags (lsp);
1510 }
1511 else
1512 {
1513 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1514 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1515 }
1516 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1517 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1518 "seq 0x%08x", circuit->area->area_tag,
1519 rawlspid_print (hdr->lsp_id),
1520 ntohl (lsp->lsp_header->seq_num));
1521 }
hassof390d2c2004-09-10 20:48:21 +00001522 }
1523 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001524 }
jardineb5d44e2003-12-23 08:09:43 +00001525 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1526 * purge */
hassof390d2c2004-09-10 20:48:21 +00001527 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1528 {
1529 if (!lsp)
1530 {
1531 /* 7.3.16.4: initiate a purge */
1532 lsp_purge_non_exist (hdr, circuit->area);
1533 return ISIS_OK;
1534 }
1535 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1536
1537 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1538 * has information that the current sequence number for source S is
1539 * "greater" than that held by S, ... */
1540
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001541 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001542 {
1543 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001544 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001545 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1546 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1547 "0x%08x", circuit->area->area_tag,
1548 rawlspid_print (hdr->lsp_id),
1549 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001550 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001551 /* If the received LSP is older or equal,
1552 * resend the LSP which will act as ACK */
1553 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001554 }
hassof390d2c2004-09-10 20:48:21 +00001555 else
1556 {
1557 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001558
hassof390d2c2004-09-10 20:48:21 +00001559 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1560 if ((!lsp || comp == LSP_NEWER))
1561 {
hassof390d2c2004-09-10 20:48:21 +00001562 /*
1563 * If this lsp is a frag, need to see if we have zero lsp present
1564 */
1565 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1566 {
1567 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1568 LSP_FRAGMENT (lspid) = 0;
1569 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1570 if (!lsp0)
1571 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001572 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001573 return ISIS_OK;
1574 }
1575 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001576 /* i */
1577 if (!lsp)
1578 {
1579 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001580 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001581 circuit->area, level);
1582 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1583 }
1584 else /* exists, so we overwrite */
1585 {
1586 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1587 }
hassof390d2c2004-09-10 20:48:21 +00001588 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001589 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001590 /* iii */
1591 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001592
hassof390d2c2004-09-10 20:48:21 +00001593 /* iv */
1594 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1595 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1596 /* FIXME: v) */
1597 }
1598 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1599 else if (comp == LSP_EQUAL)
1600 {
1601 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001602 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001603 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001604 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001605 }
1606 /* 7.3.15.1 e) 3) LSP older than the one in db */
1607 else
1608 {
1609 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1610 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1611 }
jardineb5d44e2003-12-23 08:09:43 +00001612 }
jardineb5d44e2003-12-23 08:09:43 +00001613 return retval;
1614}
1615
1616/*
1617 * Process Sequence Numbers
1618 * ISO - 10589
1619 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1620 */
1621
hasso92365882005-01-18 13:53:33 +00001622static int
hassof390d2c2004-09-10 20:48:21 +00001623process_snp (int snp_type, int level, struct isis_circuit *circuit,
1624 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001625{
1626 int retval = ISIS_OK;
1627 int cmp, own_lsp;
1628 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001629 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001630 struct isis_adjacency *adj;
1631 struct isis_complete_seqnum_hdr *chdr = NULL;
1632 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001633 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001634 struct isis_lsp *lsp;
1635 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001636 struct listnode *node, *nnode;
1637 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001638 struct tlvs tlvs;
1639 struct list *lsp_list = NULL;
1640 struct isis_passwd *passwd;
1641
hassof390d2c2004-09-10 20:48:21 +00001642 if (snp_type == ISIS_SNP_CSNP_FLAG)
1643 {
1644 /* getting the header info */
1645 typechar = 'C';
1646 chdr =
1647 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001648 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1649 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001650 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001651 pdu_len > ISO_MTU(circuit) ||
1652 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001653 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001654 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1655 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001656 }
jardineb5d44e2003-12-23 08:09:43 +00001657 }
hassof390d2c2004-09-10 20:48:21 +00001658 else
1659 {
1660 typechar = 'P';
1661 phdr =
1662 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001663 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1664 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001665 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001666 pdu_len > ISO_MTU(circuit) ||
1667 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001668 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001669 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1670 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001671 }
jardineb5d44e2003-12-23 08:09:43 +00001672 }
jardineb5d44e2003-12-23 08:09:43 +00001673
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001674 /*
1675 * Set the stream endp to PDU length, ignoring additional padding
1676 * introduced by transport chips.
1677 */
1678 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1679 stream_set_endp (circuit->rcv_stream, pdu_len);
1680
jardineb5d44e2003-12-23 08:09:43 +00001681 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001682 if (circuit->ext_domain)
1683 {
jardineb5d44e2003-12-23 08:09:43 +00001684
hasso529d65b2004-12-24 00:14:50 +00001685 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1686 "skipping: circuit externalDomain = true",
1687 circuit->area->area_tag,
1688 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001689
1690 return ISIS_OK;
1691 }
hassof390d2c2004-09-10 20:48:21 +00001692
1693 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001694 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001695 {
1696
hasso529d65b2004-12-24 00:14:50 +00001697 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1698 "skipping: circuit type %s does not match level %d",
1699 circuit->area->area_tag,
1700 level,
1701 typechar,
1702 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001703 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001704
1705 return ISIS_OK;
1706 }
1707
1708 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1709 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001710 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1711 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001712 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001713 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1714 "skipping: we are not the DIS",
1715 circuit->area->area_tag,
1716 level,
1717 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001718
Josh Bailey3f045a02012-03-24 08:35:20 -07001719 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001720 }
jardineb5d44e2003-12-23 08:09:43 +00001721
1722 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1723
1724 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1725 * - already checked */
1726
1727 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1728 /* for broadcast circuits, snpa should be compared */
1729 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001730 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1731 {
1732 if (snp_type == ISIS_SNP_CSNP_FLAG)
1733 {
1734 adj =
1735 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1736 }
1737 else
1738 {
1739 /* a psnp on a broadcast, how lovely of Juniper :) */
1740 adj =
1741 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1742 }
1743 if (!adj)
1744 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001745 }
hassof390d2c2004-09-10 20:48:21 +00001746 else
1747 {
1748 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001749 {
1750 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1751 return ISIS_OK; /* Silently discard */
1752 }
hassof390d2c2004-09-10 20:48:21 +00001753 }
jardineb5d44e2003-12-23 08:09:43 +00001754
1755 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1756
1757 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1758
1759 memset (&tlvs, 0, sizeof (struct tlvs));
1760
1761 /* parse the SNP */
1762 expected |= TLVFLAG_LSP_ENTRIES;
1763 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001764
1765 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001766 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001767 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001768 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001769 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001770
hassof390d2c2004-09-10 20:48:21 +00001771 if (retval > ISIS_WARNING)
1772 {
1773 zlog_warn ("something went very wrong processing SNP");
1774 free_tlvs (&tlvs);
1775 return retval;
1776 }
jardineb5d44e2003-12-23 08:09:43 +00001777
Josh Bailey3f045a02012-03-24 08:35:20 -07001778 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001779 passwd = &circuit->area->area_passwd;
1780 else
1781 passwd = &circuit->area->domain_passwd;
1782
1783 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001784 {
hasso1cbc5622005-01-01 10:29:51 +00001785 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001786 {
1787 if (!(found & TLVFLAG_AUTH_INFO) ||
1788 authentication_check (&tlvs.auth_info, passwd,
1789 circuit->rcv_stream, auth_tlv_offset))
1790 {
1791 isis_event_auth_failure (circuit->area->area_tag,
1792 "SNP authentication" " failure",
1793 phdr ? phdr->source_id :
1794 chdr->source_id);
1795 free_tlvs (&tlvs);
1796 return ISIS_OK;
1797 }
1798 }
hassof390d2c2004-09-10 20:48:21 +00001799 }
jardineb5d44e2003-12-23 08:09:43 +00001800
1801 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001802 if (isis->debugs & DEBUG_SNP_PACKETS)
1803 {
hasso529d65b2004-12-24 00:14:50 +00001804 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1805 circuit->area->area_tag,
1806 level,
1807 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001808 if (tlvs.lsp_entries)
1809 {
hasso3fdb2dd2005-09-28 18:45:54 +00001810 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001811 {
hasso529d65b2004-12-24 00:14:50 +00001812 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1813 " cksum 0x%04x, lifetime %us",
1814 circuit->area->area_tag,
1815 typechar,
1816 rawlspid_print (entry->lsp_id),
1817 ntohl (entry->seq_num),
1818 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001819 }
1820 }
jardineb5d44e2003-12-23 08:09:43 +00001821 }
jardineb5d44e2003-12-23 08:09:43 +00001822
1823 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001824 if (tlvs.lsp_entries)
1825 {
hasso3fdb2dd2005-09-28 18:45:54 +00001826 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001827 {
1828 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1829 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1830 if (lsp)
1831 {
1832 /* 7.3.15.2 b) 1) is this LSP newer */
1833 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1834 entry->checksum, entry->rem_lifetime);
1835 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1836 if (cmp == LSP_EQUAL)
1837 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001838 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1839 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001840 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001841 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001842 else if (cmp == LSP_OLDER)
1843 {
1844 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1845 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1846 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001847 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001848 else
1849 {
hassof390d2c2004-09-10 20:48:21 +00001850 if (own_lsp)
1851 {
1852 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1853 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1854 }
1855 else
1856 {
1857 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001858 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1859 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001860 }
1861 }
1862 }
1863 else
1864 {
1865 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1866 * insert it and set SSN on it */
1867 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1868 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1869 {
1870 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1871 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001872 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001873 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001874 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001875 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1876 }
1877 }
jardineb5d44e2003-12-23 08:09:43 +00001878 }
1879 }
jardineb5d44e2003-12-23 08:09:43 +00001880
1881 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001882 if (snp_type == ISIS_SNP_CSNP_FLAG)
1883 {
1884 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001885 * Build a list from our own LSP db bounded with
1886 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001887 */
1888 lsp_list = list_new ();
1889 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1890 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001891
hassof390d2c2004-09-10 20:48:21 +00001892 /* Fixme: Find a better solution */
1893 if (tlvs.lsp_entries)
1894 {
paul1eb8ef22005-04-07 07:30:20 +00001895 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001896 {
paul1eb8ef22005-04-07 07:30:20 +00001897 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001898 {
1899 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1900 {
1901 list_delete_node (lsp_list, node2);
1902 break;
1903 }
1904 }
1905 }
1906 }
1907 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001908 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001909 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001910 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001911 list_delete (lsp_list);
1912
jardineb5d44e2003-12-23 08:09:43 +00001913 }
jardineb5d44e2003-12-23 08:09:43 +00001914
1915 free_tlvs (&tlvs);
1916 return retval;
1917}
1918
hasso92365882005-01-18 13:53:33 +00001919static int
hassof390d2c2004-09-10 20:48:21 +00001920process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001921{
Josh Bailey3f045a02012-03-24 08:35:20 -07001922 if (isis->debugs & DEBUG_SNP_PACKETS)
1923 {
1924 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1925 circuit->area->area_tag, level, circuit->interface->name,
1926 circuit_t2string (circuit->is_type), circuit->circuit_id);
1927 if (isis->debugs & DEBUG_PACKET_DUMP)
1928 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1929 stream_get_endp (circuit->rcv_stream));
1930 }
1931
jardineb5d44e2003-12-23 08:09:43 +00001932 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001933 if ((stream_get_endp (circuit->rcv_stream) -
1934 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1935 {
1936 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1937 return ISIS_WARNING;
1938 }
jardineb5d44e2003-12-23 08:09:43 +00001939
1940 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1941}
1942
hasso92365882005-01-18 13:53:33 +00001943static int
hassof390d2c2004-09-10 20:48:21 +00001944process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001945{
Josh Bailey3f045a02012-03-24 08:35:20 -07001946 if (isis->debugs & DEBUG_SNP_PACKETS)
1947 {
1948 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1949 circuit->area->area_tag, level, circuit->interface->name,
1950 circuit_t2string (circuit->is_type), circuit->circuit_id);
1951 if (isis->debugs & DEBUG_PACKET_DUMP)
1952 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1953 stream_get_endp (circuit->rcv_stream));
1954 }
1955
hassof390d2c2004-09-10 20:48:21 +00001956 if ((stream_get_endp (circuit->rcv_stream) -
1957 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1958 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001959 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001960 return ISIS_WARNING;
1961 }
jardineb5d44e2003-12-23 08:09:43 +00001962
1963 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1964}
1965
jardineb5d44e2003-12-23 08:09:43 +00001966/*
1967 * Process ISH
1968 * ISO - 10589
1969 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1970 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001971 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1972 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1973 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001974 */
hasso92365882005-01-18 13:53:33 +00001975static int
jardineb5d44e2003-12-23 08:09:43 +00001976process_is_hello (struct isis_circuit *circuit)
1977{
1978 struct isis_adjacency *adj;
1979 int retval = ISIS_OK;
1980 u_char neigh_len;
1981 u_char *sysid;
1982
Josh Bailey3f045a02012-03-24 08:35:20 -07001983 if (isis->debugs & DEBUG_ADJ_PACKETS)
1984 {
1985 zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u",
1986 circuit->area->area_tag, circuit->interface->name,
1987 circuit_t2string (circuit->is_type), circuit->circuit_id);
1988 if (isis->debugs & DEBUG_PACKET_DUMP)
1989 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1990 stream_get_endp (circuit->rcv_stream));
1991 }
1992
jardineb5d44e2003-12-23 08:09:43 +00001993 /* In this point in time we are not yet able to handle is_hellos
1994 * on lan - Sorry juniper...
1995 */
1996 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1997 return retval;
1998
1999 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00002000 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002001 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00002002 if (!adj)
2003 {
2004 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00002005 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00002006 if (adj == NULL)
2007 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00002008
hassof390d2c2004-09-10 20:48:21 +00002009 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
2010 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
2011 circuit->u.p2p.neighbor = adj;
2012 }
2013 /* 8.2.2 a) */
2014 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
2015 ISIS_SYS_ID_LEN))
2016 {
2017 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
2018 /* 8.2.2 a) 2) delete the adj */
2019 XFREE (MTYPE_ISIS_ADJACENCY, adj);
2020 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00002021 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00002022 if (adj == NULL)
2023 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00002024
hassof390d2c2004-09-10 20:48:21 +00002025 /* 8.2.2 a) 3) i */
2026 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
2027 /* 8.2.2 a) 3) ii */
2028 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
2029 /* 8.2.2 a) 4) quite meaningless */
2030 }
jardineb5d44e2003-12-23 08:09:43 +00002031 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00002032 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
2033 (adj->sys_type == ISIS_SYSTYPE_IS))
2034 {
2035 /* do nothing */
2036 }
2037 else
2038 {
2039 /* 8.2.2 c) respond with a p2p IIH */
2040 send_hello (circuit, 1);
2041 }
jardineb5d44e2003-12-23 08:09:43 +00002042 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00002043 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00002044 /* 8.2.2 e) FIXME: Circuit type of? */
2045
jardineb5d44e2003-12-23 08:09:43 +00002046 return retval;
2047}
2048
jardineb5d44e2003-12-23 08:09:43 +00002049/*
2050 * PDU Dispatcher
2051 */
2052
hasso92365882005-01-18 13:53:33 +00002053static int
hassof390d2c2004-09-10 20:48:21 +00002054isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00002055{
jardineb5d44e2003-12-23 08:09:43 +00002056 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00002057
hassof390d2c2004-09-10 20:48:21 +00002058 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002059
2060 /*
2061 * Let's first read data from stream to the header
2062 */
hassof390d2c2004-09-10 20:48:21 +00002063 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00002064
hassof390d2c2004-09-10 20:48:21 +00002065 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
2066 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002067 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00002068 return ISIS_ERROR;
2069 }
jardineb5d44e2003-12-23 08:09:43 +00002070
2071 /* now we need to know if this is an ISO 9542 packet and
2072 * take real good care of it, waaa!
2073 */
hassof390d2c2004-09-10 20:48:21 +00002074 if (hdr->idrp == ISO9542_ESIS)
2075 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002076 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
2077 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002078 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002079 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
2080
jardineb5d44e2003-12-23 08:09:43 +00002081 /*
2082 * and then process it
2083 */
2084
hassof390d2c2004-09-10 20:48:21 +00002085 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
2086 {
2087 zlog_err ("Fixed header length = %d", hdr->length);
2088 return ISIS_ERROR;
2089 }
jardineb5d44e2003-12-23 08:09:43 +00002090
hassof390d2c2004-09-10 20:48:21 +00002091 if (hdr->version1 != 1)
2092 {
2093 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
2094 return ISIS_WARNING;
2095 }
jardineb5d44e2003-12-23 08:09:43 +00002096 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002097 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2098 {
2099 zlog_err
2100 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2101 "while the parameter for this IS is %u", hdr->id_len,
2102 ISIS_SYS_ID_LEN);
2103 return ISIS_ERROR;
2104 }
jardineb5d44e2003-12-23 08:09:43 +00002105
hassof390d2c2004-09-10 20:48:21 +00002106 if (hdr->version2 != 1)
2107 {
2108 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2109 return ISIS_WARNING;
2110 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002111
2112 if (circuit->is_passive)
2113 {
2114 zlog_warn ("Received ISIS PDU on passive circuit %s",
2115 circuit->interface->name);
2116 return ISIS_WARNING;
2117 }
2118
jardineb5d44e2003-12-23 08:09:43 +00002119 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002120 if ((hdr->max_area_addrs != 0)
2121 && (hdr->max_area_addrs != isis->max_area_addrs))
2122 {
2123 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2124 "received PDU %u while the parameter for this IS is %u",
2125 hdr->max_area_addrs, isis->max_area_addrs);
2126 return ISIS_ERROR;
2127 }
jardineb5d44e2003-12-23 08:09:43 +00002128
hassof390d2c2004-09-10 20:48:21 +00002129 switch (hdr->pdu_type)
2130 {
2131 case L1_LAN_HELLO:
2132 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2133 break;
2134 case L2_LAN_HELLO:
2135 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2136 break;
2137 case P2P_HELLO:
2138 retval = process_p2p_hello (circuit);
2139 break;
2140 case L1_LINK_STATE:
2141 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2142 break;
2143 case L2_LINK_STATE:
2144 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2145 break;
2146 case L1_COMPLETE_SEQ_NUM:
2147 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2148 break;
2149 case L2_COMPLETE_SEQ_NUM:
2150 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2151 break;
2152 case L1_PARTIAL_SEQ_NUM:
2153 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2154 break;
2155 case L2_PARTIAL_SEQ_NUM:
2156 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2157 break;
2158 default:
2159 return ISIS_ERROR;
2160 }
jardineb5d44e2003-12-23 08:09:43 +00002161
2162 return retval;
2163}
2164
jardineb5d44e2003-12-23 08:09:43 +00002165#ifdef GNU_LINUX
2166int
2167isis_receive (struct thread *thread)
2168{
jardineb5d44e2003-12-23 08:09:43 +00002169 struct isis_circuit *circuit;
2170 u_char ssnpa[ETH_ALEN];
2171 int retval;
2172
2173 /*
2174 * Get the circuit
2175 */
2176 circuit = THREAD_ARG (thread);
2177 assert (circuit);
2178
2179 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002180 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002181 else
2182 stream_reset (circuit->rcv_stream);
2183
2184 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002185 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002186
2187 if (retval == ISIS_OK)
2188 retval = isis_handle_pdu (circuit, ssnpa);
2189
2190 /*
2191 * prepare for next packet.
2192 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002193 if (!circuit->is_passive)
2194 {
2195 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2196 circuit->fd);
2197 }
jardineb5d44e2003-12-23 08:09:43 +00002198
2199 return retval;
2200}
2201
2202#else
2203int
2204isis_receive (struct thread *thread)
2205{
jardineb5d44e2003-12-23 08:09:43 +00002206 struct isis_circuit *circuit;
2207 u_char ssnpa[ETH_ALEN];
2208 int retval;
2209
2210 /*
2211 * Get the circuit
2212 */
2213 circuit = THREAD_ARG (thread);
2214 assert (circuit);
2215
hassof390d2c2004-09-10 20:48:21 +00002216 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002217
2218 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002219 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002220 else
2221 stream_reset (circuit->rcv_stream);
2222
2223 retval = circuit->rx (circuit, ssnpa);
2224
2225 if (retval == ISIS_OK)
2226 retval = isis_handle_pdu (circuit, ssnpa);
2227
2228 /*
2229 * prepare for next packet.
2230 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002231 if (!circuit->is_passive)
2232 {
2233 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2234 listcount
2235 (circuit->area->circuit_list) *
2236 100);
2237 }
jardineb5d44e2003-12-23 08:09:43 +00002238
2239 return retval;
2240}
2241
2242#endif
2243
2244 /* filling of the fixed isis header */
2245void
2246fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2247{
2248 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2249
2250 hdr->idrp = ISO10589_ISIS;
2251
hassof390d2c2004-09-10 20:48:21 +00002252 switch (pdu_type)
2253 {
2254 case L1_LAN_HELLO:
2255 case L2_LAN_HELLO:
2256 hdr->length = ISIS_LANHELLO_HDRLEN;
2257 break;
2258 case P2P_HELLO:
2259 hdr->length = ISIS_P2PHELLO_HDRLEN;
2260 break;
2261 case L1_LINK_STATE:
2262 case L2_LINK_STATE:
2263 hdr->length = ISIS_LSP_HDR_LEN;
2264 break;
2265 case L1_COMPLETE_SEQ_NUM:
2266 case L2_COMPLETE_SEQ_NUM:
2267 hdr->length = ISIS_CSNP_HDRLEN;
2268 break;
2269 case L1_PARTIAL_SEQ_NUM:
2270 case L2_PARTIAL_SEQ_NUM:
2271 hdr->length = ISIS_PSNP_HDRLEN;
2272 break;
2273 default:
2274 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2275 return;
2276 }
jardineb5d44e2003-12-23 08:09:43 +00002277 hdr->length += ISIS_FIXED_HDR_LEN;
2278 hdr->pdu_type = pdu_type;
2279 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002280 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002281 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002282 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002283}
2284
jardineb5d44e2003-12-23 08:09:43 +00002285/*
2286 * SEND SIDE
2287 */
hasso92365882005-01-18 13:53:33 +00002288static void
jardineb5d44e2003-12-23 08:09:43 +00002289fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002290 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002291{
hassof390d2c2004-09-10 20:48:21 +00002292 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002293
2294 stream_putc (stream, hdr->idrp);
2295 stream_putc (stream, hdr->length);
2296 stream_putc (stream, hdr->version1);
2297 stream_putc (stream, hdr->id_len);
2298 stream_putc (stream, hdr->pdu_type);
2299 stream_putc (stream, hdr->version2);
2300 stream_putc (stream, hdr->reserved);
2301 stream_putc (stream, hdr->max_area_addrs);
2302
2303 return;
2304}
2305
jardineb5d44e2003-12-23 08:09:43 +00002306int
2307send_hello (struct isis_circuit *circuit, int level)
2308{
2309 struct isis_fixed_hdr fixed_hdr;
2310 struct isis_lan_hello_hdr hello_hdr;
2311 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002312 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2313 unsigned long len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002314 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002315 int retval;
2316
Josh Bailey3f045a02012-03-24 08:35:20 -07002317 if (circuit->is_passive)
2318 return ISIS_OK;
2319
hassof390d2c2004-09-10 20:48:21 +00002320 if (circuit->interface->mtu == 0)
2321 {
2322 zlog_warn ("circuit has zero MTU");
2323 return ISIS_WARNING;
2324 }
jardineb5d44e2003-12-23 08:09:43 +00002325
2326 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002327 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002328 else
2329 stream_reset (circuit->snd_stream);
2330
2331 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002332 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002333 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2334 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002335 else
hassof390d2c2004-09-10 20:48:21 +00002336 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2337 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002338 else
hassof390d2c2004-09-10 20:48:21 +00002339 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002340
2341 /*
2342 * Fill LAN Level 1 or 2 Hello PDU header
2343 */
2344 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002345 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002346 circuit->hello_interval[level - 1];
2347 if (interval > USHRT_MAX)
2348 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002349 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002350 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002351 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002352
hassof390d2c2004-09-10 20:48:21 +00002353 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002354 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002355
2356 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002357 if (circuit->circ_type == CIRCUIT_T_P2P)
2358 {
2359 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2360 p2p_hello_hdr.local_id = circuit->circuit_id;
2361 /* FIXME: need better understanding */
2362 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002363 }
hassof390d2c2004-09-10 20:48:21 +00002364 else
2365 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002366 hello_hdr.prio = circuit->priority[level - 1];
2367 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002368 {
2369 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2370 ISIS_SYS_ID_LEN + 1);
2371 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002372 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002373 {
2374 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2375 ISIS_SYS_ID_LEN + 1);
2376 }
2377 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2378 }
jardineb5d44e2003-12-23 08:09:43 +00002379
2380 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002381 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002382 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002383
jardineb5d44e2003-12-23 08:09:43 +00002384 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002385 switch (circuit->passwd.type)
2386 {
2387 /* Cleartext */
2388 case ISIS_PASSWD_TYPE_CLEARTXT:
2389 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2390 circuit->passwd.passwd, circuit->snd_stream))
2391 return ISIS_WARNING;
2392 break;
2393
2394 /* HMAC MD5 */
2395 case ISIS_PASSWD_TYPE_HMAC_MD5:
2396 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2397 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2398 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2399 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2400 hmac_md5_hash, circuit->snd_stream))
2401 return ISIS_WARNING;
2402 break;
2403
2404 default:
2405 break;
2406 }
2407
jardineb5d44e2003-12-23 08:09:43 +00002408 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002409 if (listcount (circuit->area->area_addrs) == 0)
2410 return ISIS_WARNING;
2411 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2412 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002413
2414 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002415 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2416 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002417 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2418 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002419 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2420 circuit->snd_stream))
2421 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002422 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2423 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002424 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2425 circuit->snd_stream))
2426 return ISIS_WARNING;
2427 }
jardineb5d44e2003-12-23 08:09:43 +00002428
2429 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002430 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002431 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2432 return ISIS_WARNING;
2433 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002434 if (circuit->ip_router && circuit->ip_addrs &&
2435 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002436 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2437 return ISIS_WARNING;
2438
hassof390d2c2004-09-10 20:48:21 +00002439#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002440 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002441 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002442 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002443 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2444 return ISIS_WARNING;
2445#endif /* HAVE_IPV6 */
2446
Josh Bailey3f045a02012-03-24 08:35:20 -07002447 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002448 if (tlv_add_padding (circuit->snd_stream))
2449 return ISIS_WARNING;
2450
paul9985f832005-02-09 15:51:56 +00002451 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002452 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002453 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002454
Josh Bailey3f045a02012-03-24 08:35:20 -07002455 /* For HMAC MD5 we need to compute the md5 hash and store it */
2456 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2457 {
2458 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2459 stream_get_endp (circuit->snd_stream),
2460 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
2461 (caddr_t) &hmac_md5_hash);
2462 /* Copy the hash into the stream */
2463 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2464 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2465 }
jardineb5d44e2003-12-23 08:09:43 +00002466
hassof390d2c2004-09-10 20:48:21 +00002467 if (isis->debugs & DEBUG_ADJ_PACKETS)
2468 {
2469 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2470 {
hasso529d65b2004-12-24 00:14:50 +00002471 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2472 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002473 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002474 length);
hassof390d2c2004-09-10 20:48:21 +00002475 }
2476 else
2477 {
hasso529d65b2004-12-24 00:14:50 +00002478 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2479 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002480 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002481 length);
hassof390d2c2004-09-10 20:48:21 +00002482 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002483 if (isis->debugs & DEBUG_PACKET_DUMP)
2484 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2485 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002486 }
jardineb5d44e2003-12-23 08:09:43 +00002487
Josh Bailey3f045a02012-03-24 08:35:20 -07002488 retval = circuit->tx (circuit, level);
2489 if (retval != ISIS_OK)
2490 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2491 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002492
Josh Bailey3f045a02012-03-24 08:35:20 -07002493 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002494}
2495
2496int
2497send_lan_l1_hello (struct thread *thread)
2498{
jardineb5d44e2003-12-23 08:09:43 +00002499 struct isis_circuit *circuit;
2500 int retval;
2501
2502 circuit = THREAD_ARG (thread);
2503 assert (circuit);
2504 circuit->u.bc.t_send_lan_hello[0] = NULL;
2505
2506 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002507 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002508
Josh Bailey3f045a02012-03-24 08:35:20 -07002509 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002510
2511 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002512 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2513 send_lan_l1_hello, circuit,
2514 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002515
2516 return retval;
2517}
2518
2519int
2520send_lan_l2_hello (struct thread *thread)
2521{
2522 struct isis_circuit *circuit;
2523 int retval;
2524
2525 circuit = THREAD_ARG (thread);
2526 assert (circuit);
2527 circuit->u.bc.t_send_lan_hello[1] = NULL;
2528
2529 if (circuit->u.bc.run_dr_elect[1])
2530 retval = isis_dr_elect (circuit, 2);
2531
Josh Bailey3f045a02012-03-24 08:35:20 -07002532 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002533
hassof390d2c2004-09-10 20:48:21 +00002534 /* set next timer thread */
2535 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2536 send_lan_l2_hello, circuit,
2537 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002538
2539 return retval;
2540}
2541
2542int
2543send_p2p_hello (struct thread *thread)
2544{
2545 struct isis_circuit *circuit;
2546
2547 circuit = THREAD_ARG (thread);
2548 assert (circuit);
2549 circuit->u.p2p.t_send_p2p_hello = NULL;
2550
hassof390d2c2004-09-10 20:48:21 +00002551 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002552
hassof390d2c2004-09-10 20:48:21 +00002553 /* set next timer thread */
2554 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2555 circuit, isis_jitter (circuit->hello_interval[1],
2556 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002557
2558 return ISIS_OK;
2559}
2560
hasso92365882005-01-18 13:53:33 +00002561static int
hassof390d2c2004-09-10 20:48:21 +00002562build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2563 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002564{
2565 struct isis_fixed_hdr fixed_hdr;
2566 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002567 unsigned long lenp;
2568 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002569 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2570 unsigned long auth_tlv_offset = 0;
2571 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002572
Josh Bailey3f045a02012-03-24 08:35:20 -07002573 if (circuit->snd_stream == NULL)
2574 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2575 else
2576 stream_reset (circuit->snd_stream);
2577
2578 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002579 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2580 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002581 else
hassof390d2c2004-09-10 20:48:21 +00002582 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2583 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002584
2585 /*
2586 * Fill Level 1 or 2 Complete Sequence Numbers header
2587 */
2588
paul9985f832005-02-09 15:51:56 +00002589 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002590 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002591 /* no need to send the source here, it is always us if we csnp */
2592 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2593 /* with zero circuit id - ref 9.10, 9.11 */
2594 stream_putc (circuit->snd_stream, 0x00);
2595
2596 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2597 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2598
2599 /*
2600 * And TLVs
2601 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002602 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002603 passwd = &circuit->area->area_passwd;
2604 else
2605 passwd = &circuit->area->domain_passwd;
2606
hasso1cbc5622005-01-01 10:29:51 +00002607 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002608 {
2609 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002610 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002611 /* Cleartext */
2612 case ISIS_PASSWD_TYPE_CLEARTXT:
2613 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2614 passwd->passwd, circuit->snd_stream))
2615 return ISIS_WARNING;
2616 break;
2617
2618 /* HMAC MD5 */
2619 case ISIS_PASSWD_TYPE_HMAC_MD5:
2620 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2621 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2622 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2623 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2624 hmac_md5_hash, circuit->snd_stream))
2625 return ISIS_WARNING;
2626 break;
2627
2628 default:
2629 break;
hassof390d2c2004-09-10 20:48:21 +00002630 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002631 }
2632
2633 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2634 if (retval != ISIS_OK)
2635 return retval;
2636
paul9985f832005-02-09 15:51:56 +00002637 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002638 /* Update PU length */
2639 stream_putw_at (circuit->snd_stream, lenp, length);
2640
Josh Bailey3f045a02012-03-24 08:35:20 -07002641 /* For HMAC MD5 we need to compute the md5 hash and store it */
2642 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2643 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2644 {
2645 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2646 stream_get_endp(circuit->snd_stream),
2647 (unsigned char *) &passwd->passwd, passwd->len,
2648 (caddr_t) &hmac_md5_hash);
2649 /* Copy the hash into the stream */
2650 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2651 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2652 }
2653
jardineb5d44e2003-12-23 08:09:43 +00002654 return retval;
2655}
2656
2657/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002658 * Count the maximum number of lsps that can be accomodated by a given size.
2659 */
2660static uint16_t
2661get_max_lsp_count (uint16_t size)
2662{
2663 uint16_t tlv_count;
2664 uint16_t lsp_count;
2665 uint16_t remaining_size;
2666
2667 /* First count the full size TLVs */
2668 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2669 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2670
2671 /* The last TLV, if any */
2672 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2673 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2674 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2675
2676 return lsp_count;
2677}
2678
2679/*
2680 * Calculate the length of Authentication Info. TLV.
2681 */
2682static uint16_t
2683auth_tlv_length (int level, struct isis_circuit *circuit)
2684{
2685 struct isis_passwd *passwd;
2686 uint16_t length;
2687
2688 if (level == IS_LEVEL_1)
2689 passwd = &circuit->area->area_passwd;
2690 else
2691 passwd = &circuit->area->domain_passwd;
2692
2693 /* Also include the length of TLV header */
2694 length = AUTH_INFO_HDRLEN;
2695 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2696 {
2697 switch (passwd->type)
2698 {
2699 /* Cleartext */
2700 case ISIS_PASSWD_TYPE_CLEARTXT:
2701 length += passwd->len;
2702 break;
2703
2704 /* HMAC MD5 */
2705 case ISIS_PASSWD_TYPE_HMAC_MD5:
2706 length += ISIS_AUTH_MD5_SIZE;
2707 break;
2708
2709 default:
2710 break;
2711 }
2712 }
2713
2714 return length;
2715}
2716
2717/*
2718 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2719 */
2720static uint16_t
2721max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2722{
2723 int snp_hdr_len;
2724 int auth_tlv_len;
2725 uint16_t lsp_count;
2726
2727 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2728 if (snp_type == ISIS_SNP_CSNP_FLAG)
2729 snp_hdr_len += ISIS_CSNP_HDRLEN;
2730 else
2731 snp_hdr_len += ISIS_PSNP_HDRLEN;
2732
2733 auth_tlv_len = auth_tlv_length (level, circuit);
2734 lsp_count = get_max_lsp_count (
2735 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002736 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002737}
2738
2739/*
jardineb5d44e2003-12-23 08:09:43 +00002740 * FIXME: support multiple CSNPs
2741 */
2742
2743int
2744send_csnp (struct isis_circuit *circuit, int level)
2745{
jardineb5d44e2003-12-23 08:09:43 +00002746 u_char start[ISIS_SYS_ID_LEN + 2];
2747 u_char stop[ISIS_SYS_ID_LEN + 2];
2748 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002749 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002750 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002751 u_char num_lsps, loop = 1;
2752 int i, retval = ISIS_OK;
2753
2754 if (circuit->area->lspdb[level - 1] == NULL ||
2755 dict_count (circuit->area->lspdb[level - 1]) == 0)
2756 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002757
hassof390d2c2004-09-10 20:48:21 +00002758 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002759 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2760
Josh Bailey3f045a02012-03-24 08:35:20 -07002761 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2762
2763 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002764 {
2765 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002766 lsp_build_list (start, stop, num_lsps, list,
2767 circuit->area->lspdb[level - 1]);
2768 /*
2769 * Update the stop lsp_id before encoding this CSNP.
2770 */
2771 if (listcount (list) < num_lsps)
2772 {
2773 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2774 }
hassof390d2c2004-09-10 20:48:21 +00002775 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002776 {
2777 node = listtail (list);
2778 lsp = listgetdata (node);
2779 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2780 }
jardineb5d44e2003-12-23 08:09:43 +00002781
hassof390d2c2004-09-10 20:48:21 +00002782 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002783 if (retval != ISIS_OK)
2784 {
2785 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2786 circuit->area->area_tag, level, circuit->interface->name);
2787 list_delete (list);
2788 return retval;
2789 }
jardineb5d44e2003-12-23 08:09:43 +00002790
hassof390d2c2004-09-10 20:48:21 +00002791 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002792 {
2793 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2794 circuit->area->area_tag, level, circuit->interface->name,
2795 stream_get_endp (circuit->snd_stream));
2796 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2797 {
2798 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2799 " cksum 0x%04x, lifetime %us",
2800 circuit->area->area_tag,
2801 rawlspid_print (lsp->lsp_header->lsp_id),
2802 ntohl (lsp->lsp_header->seq_num),
2803 ntohs (lsp->lsp_header->checksum),
2804 ntohs (lsp->lsp_header->rem_lifetime));
2805 }
2806 if (isis->debugs & DEBUG_PACKET_DUMP)
2807 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2808 stream_get_endp (circuit->snd_stream));
2809 }
hassof390d2c2004-09-10 20:48:21 +00002810
Josh Bailey3f045a02012-03-24 08:35:20 -07002811 retval = circuit->tx (circuit, level);
2812 if (retval != ISIS_OK)
2813 {
2814 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2815 circuit->area->area_tag, level,
2816 circuit->interface->name);
2817 list_delete (list);
2818 return retval;
2819 }
2820
2821 /*
2822 * Start lsp_id of the next CSNP should be one plus the
2823 * stop lsp_id in this current CSNP.
2824 */
2825 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2826 loop = 0;
2827 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2828 {
2829 if (start[i] < (u_char)0xff)
2830 {
2831 start[i] += 1;
2832 loop = 1;
2833 break;
2834 }
2835 }
2836 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002837 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002838 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002839
jardineb5d44e2003-12-23 08:09:43 +00002840 return retval;
2841}
2842
2843int
2844send_l1_csnp (struct thread *thread)
2845{
2846 struct isis_circuit *circuit;
2847 int retval = ISIS_OK;
2848
2849 circuit = THREAD_ARG (thread);
2850 assert (circuit);
2851
2852 circuit->t_send_csnp[0] = NULL;
2853
hassof390d2c2004-09-10 20:48:21 +00002854 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2855 {
2856 send_csnp (circuit, 1);
2857 }
jardineb5d44e2003-12-23 08:09:43 +00002858 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002859 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2860 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002861
2862 return retval;
2863}
2864
2865int
2866send_l2_csnp (struct thread *thread)
2867{
2868 struct isis_circuit *circuit;
2869 int retval = ISIS_OK;
2870
2871 circuit = THREAD_ARG (thread);
2872 assert (circuit);
2873
2874 circuit->t_send_csnp[1] = NULL;
2875
hassof390d2c2004-09-10 20:48:21 +00002876 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2877 {
2878 send_csnp (circuit, 2);
2879 }
jardineb5d44e2003-12-23 08:09:43 +00002880 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002881 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2882 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002883
jardineb5d44e2003-12-23 08:09:43 +00002884 return retval;
2885}
2886
hasso92365882005-01-18 13:53:33 +00002887static int
jardineb5d44e2003-12-23 08:09:43 +00002888build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2889{
2890 struct isis_fixed_hdr fixed_hdr;
2891 unsigned long lenp;
2892 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002893 struct isis_lsp *lsp;
2894 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002895 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002896 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2897 unsigned long auth_tlv_offset = 0;
2898 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002899
Josh Bailey3f045a02012-03-24 08:35:20 -07002900 if (circuit->snd_stream == NULL)
2901 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2902 else
2903 stream_reset (circuit->snd_stream);
2904
2905 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002906 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2907 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002908 else
2909 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002910 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002911
2912 /*
2913 * Fill Level 1 or 2 Partial Sequence Numbers header
2914 */
paul9985f832005-02-09 15:51:56 +00002915 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002916 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002917 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2918 stream_putc (circuit->snd_stream, circuit->idx);
2919
2920 /*
2921 * And TLVs
2922 */
2923
Josh Bailey3f045a02012-03-24 08:35:20 -07002924 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002925 passwd = &circuit->area->area_passwd;
2926 else
2927 passwd = &circuit->area->domain_passwd;
2928
hasso1cbc5622005-01-01 10:29:51 +00002929 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002930 {
2931 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002932 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002933 /* Cleartext */
2934 case ISIS_PASSWD_TYPE_CLEARTXT:
2935 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2936 passwd->passwd, circuit->snd_stream))
2937 return ISIS_WARNING;
2938 break;
2939
2940 /* HMAC MD5 */
2941 case ISIS_PASSWD_TYPE_HMAC_MD5:
2942 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2943 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2944 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2945 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2946 hmac_md5_hash, circuit->snd_stream))
2947 return ISIS_WARNING;
2948 break;
2949
2950 default:
2951 break;
jardineb5d44e2003-12-23 08:09:43 +00002952 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002953 }
2954
2955 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2956 if (retval != ISIS_OK)
2957 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002958
hassof390d2c2004-09-10 20:48:21 +00002959 if (isis->debugs & DEBUG_SNP_PACKETS)
2960 {
hasso3fdb2dd2005-09-28 18:45:54 +00002961 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002962 {
hasso529d65b2004-12-24 00:14:50 +00002963 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2964 " cksum 0x%04x, lifetime %us",
2965 circuit->area->area_tag,
2966 rawlspid_print (lsp->lsp_header->lsp_id),
2967 ntohl (lsp->lsp_header->seq_num),
2968 ntohs (lsp->lsp_header->checksum),
2969 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002970 }
2971 }
2972
paul9985f832005-02-09 15:51:56 +00002973 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002974 /* Update PDU length */
2975 stream_putw_at (circuit->snd_stream, lenp, length);
2976
Josh Bailey3f045a02012-03-24 08:35:20 -07002977 /* For HMAC MD5 we need to compute the md5 hash and store it */
2978 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2979 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2980 {
2981 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2982 stream_get_endp(circuit->snd_stream),
2983 (unsigned char *) &passwd->passwd, passwd->len,
2984 (caddr_t) &hmac_md5_hash);
2985 /* Copy the hash into the stream */
2986 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2987 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2988 }
2989
jardineb5d44e2003-12-23 08:09:43 +00002990 return ISIS_OK;
2991}
2992
2993/*
2994 * 7.3.15.4 action on expiration of partial SNP interval
2995 * level 1
2996 */
hasso92365882005-01-18 13:53:33 +00002997static int
jardineb5d44e2003-12-23 08:09:43 +00002998send_psnp (int level, struct isis_circuit *circuit)
2999{
jardineb5d44e2003-12-23 08:09:43 +00003000 struct isis_lsp *lsp;
3001 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00003002 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003003 u_char num_lsps;
3004 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003005
Josh Bailey3f045a02012-03-24 08:35:20 -07003006 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
3007 circuit->u.bc.is_dr[level - 1])
3008 return ISIS_OK;
3009
3010 if (circuit->area->lspdb[level - 1] == NULL ||
3011 dict_count (circuit->area->lspdb[level - 1]) == 0)
3012 return ISIS_OK;
3013
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07003014 if (! circuit->snd_stream)
3015 return ISIS_ERROR;
3016
Josh Bailey3f045a02012-03-24 08:35:20 -07003017 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
3018
3019 while (1)
hassof390d2c2004-09-10 20:48:21 +00003020 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003021 list = list_new ();
3022 lsp_build_list_ssn (circuit, num_lsps, list,
3023 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00003024
Josh Bailey3f045a02012-03-24 08:35:20 -07003025 if (listcount (list) == 0)
3026 {
3027 list_delete (list);
3028 return ISIS_OK;
3029 }
jardineb5d44e2003-12-23 08:09:43 +00003030
Josh Bailey3f045a02012-03-24 08:35:20 -07003031 retval = build_psnp (level, circuit, list);
3032 if (retval != ISIS_OK)
3033 {
3034 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
3035 circuit->area->area_tag, level, circuit->interface->name);
3036 list_delete (list);
3037 return retval;
3038 }
jardineb5d44e2003-12-23 08:09:43 +00003039
Josh Bailey3f045a02012-03-24 08:35:20 -07003040 if (isis->debugs & DEBUG_SNP_PACKETS)
3041 {
3042 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
3043 circuit->area->area_tag, level,
3044 circuit->interface->name,
3045 stream_get_endp (circuit->snd_stream));
3046 if (isis->debugs & DEBUG_PACKET_DUMP)
3047 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3048 stream_get_endp (circuit->snd_stream));
3049 }
jardineb5d44e2003-12-23 08:09:43 +00003050
Josh Bailey3f045a02012-03-24 08:35:20 -07003051 retval = circuit->tx (circuit, level);
3052 if (retval != ISIS_OK)
3053 {
3054 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
3055 circuit->area->area_tag, level,
3056 circuit->interface->name);
3057 list_delete (list);
3058 return retval;
3059 }
jardineb5d44e2003-12-23 08:09:43 +00003060
Josh Bailey3f045a02012-03-24 08:35:20 -07003061 /*
3062 * sending succeeded, we can clear SSN flags of this circuit
3063 * for the LSPs in list
3064 */
3065 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
3066 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
3067 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00003068 }
jardineb5d44e2003-12-23 08:09:43 +00003069
3070 return retval;
3071}
3072
3073int
3074send_l1_psnp (struct thread *thread)
3075{
3076
3077 struct isis_circuit *circuit;
3078 int retval = ISIS_OK;
3079
3080 circuit = THREAD_ARG (thread);
3081 assert (circuit);
3082
3083 circuit->t_send_psnp[0] = NULL;
3084
3085 send_psnp (1, circuit);
3086 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003087 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
3088 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003089
3090 return retval;
3091}
3092
3093/*
3094 * 7.3.15.4 action on expiration of partial SNP interval
3095 * level 2
3096 */
3097int
3098send_l2_psnp (struct thread *thread)
3099{
jardineb5d44e2003-12-23 08:09:43 +00003100 struct isis_circuit *circuit;
3101 int retval = ISIS_OK;
3102
3103 circuit = THREAD_ARG (thread);
3104 assert (circuit);
3105
3106 circuit->t_send_psnp[1] = NULL;
3107
3108 send_psnp (2, circuit);
3109
3110 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003111 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3112 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003113
3114 return retval;
3115}
3116
jardineb5d44e2003-12-23 08:09:43 +00003117/*
3118 * ISO 10589 - 7.3.14.3
3119 */
3120int
3121send_lsp (struct thread *thread)
3122{
3123 struct isis_circuit *circuit;
3124 struct isis_lsp *lsp;
3125 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003126 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003127
3128 circuit = THREAD_ARG (thread);
3129 assert (circuit);
3130
Josh Bailey3f045a02012-03-24 08:35:20 -07003131 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3132 {
3133 return retval;
3134 }
3135
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003136 node = listhead (circuit->lsp_queue);
3137
3138 /*
3139 * Handle case where there are no LSPs on the queue. This can
3140 * happen, for instance, if an adjacency goes down before this
3141 * thread gets a chance to run.
3142 */
3143 if (!node)
3144 {
3145 return retval;
3146 }
3147
3148 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003149
3150 /*
3151 * Do not send if levels do not match
3152 */
3153 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003154 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003155 list_delete_node (circuit->lsp_queue, node);
3156 return retval;
hassof390d2c2004-09-10 20:48:21 +00003157 }
jardineb5d44e2003-12-23 08:09:43 +00003158
Josh Bailey3f045a02012-03-24 08:35:20 -07003159 /*
3160 * Do not send if we do not have adjacencies in state up on the circuit
3161 */
3162 if (circuit->upadjcount[lsp->level - 1] == 0)
3163 {
3164 list_delete_node (circuit->lsp_queue, node);
3165 return retval;
3166 }
3167
3168 /* copy our lsp to the send buffer */
3169 stream_copy (circuit->snd_stream, lsp->pdu);
3170
3171 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3172 {
3173 zlog_debug
3174 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3175 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3176 rawlspid_print (lsp->lsp_header->lsp_id),
3177 ntohl (lsp->lsp_header->seq_num),
3178 ntohs (lsp->lsp_header->checksum),
3179 ntohs (lsp->lsp_header->rem_lifetime),
3180 circuit->interface->name);
3181 if (isis->debugs & DEBUG_PACKET_DUMP)
3182 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3183 stream_get_endp (circuit->snd_stream));
3184 }
3185
3186 retval = circuit->tx (circuit, lsp->level);
3187 if (retval != ISIS_OK)
3188 {
3189 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3190 circuit->area->area_tag, lsp->level,
3191 circuit->interface->name);
3192 return retval;
3193 }
3194
3195 /*
3196 * If the sending succeeded, we can del the lsp from circuits
3197 * lsp_queue
3198 */
3199 list_delete_node (circuit->lsp_queue, node);
3200
3201 /* Set the last-cleared time if the queue is empty. */
3202 /* TODO: Is is possible that new lsps keep being added to the queue
3203 * that the queue is never empty? */
3204 if (list_isempty (circuit->lsp_queue))
3205 circuit->lsp_queue_last_cleared = time (NULL);
3206
3207 /*
3208 * On broadcast circuits also the SRMflag can be cleared
3209 */
3210 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3211 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3212
jardineb5d44e2003-12-23 08:09:43 +00003213 return retval;
hassof390d2c2004-09-10 20:48:21 +00003214}
jardineb5d44e2003-12-23 08:09:43 +00003215
3216int
hassof390d2c2004-09-10 20:48:21 +00003217ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3218 int level)
jardineb5d44e2003-12-23 08:09:43 +00003219{
3220 unsigned long lenp;
3221 int retval;
3222 u_int16_t length;
3223 struct isis_fixed_hdr fixed_hdr;
3224
3225 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003226 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003227 else
3228 stream_reset (circuit->snd_stream);
3229
Josh Bailey3f045a02012-03-24 08:35:20 -07003230 // fill_llc_hdr (stream);
3231 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003232 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3233 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003234 else
hassof390d2c2004-09-10 20:48:21 +00003235 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3236 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003237
3238
paul9985f832005-02-09 15:51:56 +00003239 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003240 stream_putw (circuit->snd_stream, 0); /* PDU length */
3241 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003242 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003243 stream_putc (circuit->snd_stream, 9); /* code */
3244 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003245
hassof390d2c2004-09-10 20:48:21 +00003246 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3247 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3248 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3249 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003250
paul9985f832005-02-09 15:51:56 +00003251 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003252 /* Update PDU length */
3253 stream_putw_at (circuit->snd_stream, lenp, length);
3254
3255 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003256 if (retval != ISIS_OK)
3257 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3258 circuit->area->area_tag, level,
3259 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003260
3261 return retval;
3262}