blob: bfa1e4e931fe7c11d1f52eec366989b4f7681f9a [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;
405
Josh Bailey3f045a02012-03-24 08:35:20 -0700406 if (isis->debugs & DEBUG_ADJ_PACKETS)
407 {
408 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
409 circuit->area->area_tag, circuit->interface->name,
410 circuit_t2string (circuit->is_type), circuit->circuit_id);
411 if (isis->debugs & DEBUG_PACKET_DUMP)
412 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
413 stream_get_endp (circuit->rcv_stream));
414 }
415
416 if (circuit->circ_type != CIRCUIT_T_P2P)
417 {
418 zlog_warn ("p2p hello on non p2p circuit");
419 return ISIS_WARNING;
420 }
421
hassof390d2c2004-09-10 20:48:21 +0000422 if ((stream_get_endp (circuit->rcv_stream) -
423 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
424 {
425 zlog_warn ("Packet too short");
426 return ISIS_WARNING;
427 }
jardineb5d44e2003-12-23 08:09:43 +0000428
429 /* 8.2.5.1 PDU acceptance tests */
430
431 /* 8.2.5.1 a) external domain untrue */
432 /* FIXME: not useful at all? */
433
434 /* 8.2.5.1 b) ID Length mismatch */
435 /* checked at the handle_pdu */
436
437 /* 8.2.5.2 IIH PDU Processing */
438
439 /* 8.2.5.2 a) 1) Maximum Area Addresses */
440 /* Already checked, and can also be ommited */
441
442 /*
443 * Get the header
444 */
hassof390d2c2004-09-10 20:48:21 +0000445 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700446 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000447
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700448 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
449 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700450 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000451 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700452 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
453 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700454 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700455 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000456 }
jardineb5d44e2003-12-23 08:09:43 +0000457
jardineb5d44e2003-12-23 08:09:43 +0000458 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700459 * Set the stream endp to PDU length, ignoring additional padding
460 * introduced by transport chips.
461 */
462 if (pdu_len < stream_get_endp (circuit->rcv_stream))
463 stream_set_endp (circuit->rcv_stream, pdu_len);
464
465 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
466
467 /*
jardineb5d44e2003-12-23 08:09:43 +0000468 * Lets get the TLVS now
469 */
470 expected |= TLVFLAG_AREA_ADDRS;
471 expected |= TLVFLAG_AUTH_INFO;
472 expected |= TLVFLAG_NLPID;
473 expected |= TLVFLAG_IPV4_ADDR;
474 expected |= TLVFLAG_IPV6_ADDR;
475
Josh Bailey3f045a02012-03-24 08:35:20 -0700476 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000477 retval = parse_tlvs (circuit->area->area_tag,
478 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700479 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
480 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000481
hassof390d2c2004-09-10 20:48:21 +0000482 if (retval > ISIS_WARNING)
483 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700484 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000485 free_tlvs (&tlvs);
486 return retval;
487 };
jardineb5d44e2003-12-23 08:09:43 +0000488
Josh Bailey3f045a02012-03-24 08:35:20 -0700489 if (!(found & TLVFLAG_AREA_ADDRS))
490 {
491 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
492 free_tlvs (&tlvs);
493 return ISIS_WARNING;
494 }
495
jardineb5d44e2003-12-23 08:09:43 +0000496 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000497 if (circuit->passwd.type)
498 {
499 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700500 authentication_check (&tlvs.auth_info, &circuit->passwd,
501 circuit->rcv_stream, auth_tlv_offset))
502 {
503 isis_event_auth_failure (circuit->area->area_tag,
504 "P2P hello authentication failure",
505 hdr->source_id);
506 free_tlvs (&tlvs);
507 return ISIS_OK;
508 }
jardineb5d44e2003-12-23 08:09:43 +0000509 }
jardineb5d44e2003-12-23 08:09:43 +0000510
Josh Bailey3f045a02012-03-24 08:35:20 -0700511 /*
512 * check if it's own interface ip match iih ip addrs
513 */
514 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
515 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
516 {
517 zlog_warn ("ISIS-Adj: No usable IP interface addresses "
518 "in LAN IIH from %s\n", circuit->interface->name);
519 free_tlvs (&tlvs);
520 return ISIS_WARNING;
521 }
522
523 /*
524 * My interpertation of the ISO, if no adj exists we will create one for
525 * the circuit
526 */
527 adj = circuit->u.p2p.neighbor;
528 if (!adj || adj->level != hdr->circuit_t)
529 {
530 if (!adj)
531 {
532 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
533 if (adj == NULL)
534 return ISIS_ERROR;
535 }
536 else
537 {
538 adj->level = hdr->circuit_t;
539 }
540 circuit->u.p2p.neighbor = adj;
541 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
542 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
543 }
544
545 /* 8.2.6 Monitoring point-to-point adjacencies */
546 adj->hold_time = ntohs (hdr->hold_time);
547 adj->last_upd = time (NULL);
548
jardineb5d44e2003-12-23 08:09:43 +0000549 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700550 tlvs_to_adj_area_addrs (&tlvs, adj);
551
552 /* which protocol are spoken ??? */
553 if (found & TLVFLAG_NLPID)
David Lamparter655071f2012-05-08 13:32:53 +0200554 if (tlvs_to_adj_nlpids (&tlvs, adj))
555 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +0000556
557 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700558 if (found & TLVFLAG_IPV4_ADDR)
559 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000560
561#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700562 if (found & TLVFLAG_IPV6_ADDR)
563 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000564#endif /* HAVE_IPV6 */
565
566 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000567 THREAD_TIMER_OFF (adj->t_expire);
568 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
569 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000570
571 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000572 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
573 {
574 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
575 if (circuit->area->is_type == IS_LEVEL_1)
576 {
577 switch (hdr->circuit_t)
578 {
579 case IS_LEVEL_1:
580 case IS_LEVEL_1_AND_2:
581 if (adj->adj_state != ISIS_ADJ_UP)
582 {
583 /* (4) adj state up */
584 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
585 /* (5) adj usage level 1 */
586 adj->adj_usage = ISIS_ADJ_LEVEL1;
587 }
588 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
589 {
590 ; /* accept */
591 }
592 break;
593 case IS_LEVEL_2:
594 if (adj->adj_state != ISIS_ADJ_UP)
595 {
596 /* (7) reject - wrong system type event */
597 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700598 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000599 return ISIS_WARNING; /* Reject */
600 }
601 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
602 {
603 /* (6) down - wrong system */
604 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
605 }
606 break;
607 }
608 }
jardineb5d44e2003-12-23 08:09:43 +0000609
hassof390d2c2004-09-10 20:48:21 +0000610 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
611 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
612 {
613 switch (hdr->circuit_t)
614 {
615 case IS_LEVEL_1:
616 if (adj->adj_state != ISIS_ADJ_UP)
617 {
618 /* (6) adj state up */
619 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
620 /* (7) adj usage level 1 */
621 adj->adj_usage = ISIS_ADJ_LEVEL1;
622 }
623 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
624 {
625 ; /* accept */
626 }
627 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
628 (adj->adj_usage == ISIS_ADJ_LEVEL2))
629 {
630 /* (8) down - wrong system */
631 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
632 }
633 break;
634 case IS_LEVEL_2:
635 if (adj->adj_state != ISIS_ADJ_UP)
636 {
637 /* (6) adj state up */
638 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
639 /* (9) adj usage level 2 */
640 adj->adj_usage = ISIS_ADJ_LEVEL2;
641 }
642 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
643 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
644 {
645 /* (8) down - wrong system */
646 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
647 }
648 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
649 {
650 ; /* Accept */
651 }
652 break;
653 case IS_LEVEL_1_AND_2:
654 if (adj->adj_state != ISIS_ADJ_UP)
655 {
656 /* (6) adj state up */
657 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
658 /* (10) adj usage level 1 */
659 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
660 }
661 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
662 (adj->adj_usage == ISIS_ADJ_LEVEL2))
663 {
664 /* (8) down - wrong system */
665 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
666 }
667 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
668 {
669 ; /* Accept */
670 }
671 break;
672 }
673 }
jardineb5d44e2003-12-23 08:09:43 +0000674
hassof390d2c2004-09-10 20:48:21 +0000675 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
676 if (circuit->area->is_type == IS_LEVEL_2)
677 {
678 switch (hdr->circuit_t)
679 {
680 case IS_LEVEL_1:
681 if (adj->adj_state != ISIS_ADJ_UP)
682 {
683 /* (5) reject - wrong system type event */
684 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700685 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000686 return ISIS_WARNING; /* Reject */
687 }
688 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
689 (adj->adj_usage == ISIS_ADJ_LEVEL2))
690 {
691 /* (6) down - wrong system */
692 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
693 }
694 break;
695 case IS_LEVEL_1_AND_2:
696 case IS_LEVEL_2:
697 if (adj->adj_state != ISIS_ADJ_UP)
698 {
699 /* (7) adj state up */
700 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
701 /* (8) adj usage level 2 */
702 adj->adj_usage = ISIS_ADJ_LEVEL2;
703 }
704 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
705 {
706 /* (6) down - wrong system */
707 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
708 }
709 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
710 {
711 ; /* Accept */
712 }
713 break;
714 }
715 }
jardineb5d44e2003-12-23 08:09:43 +0000716 }
jardineb5d44e2003-12-23 08:09:43 +0000717 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700718 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000719 {
hassof390d2c2004-09-10 20:48:21 +0000720 if (circuit->area->is_type == IS_LEVEL_1)
721 {
722 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
723 if (adj->adj_state != ISIS_ADJ_UP)
724 {
725 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
726 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
727 }
728 else
729 {
730 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
731 "Down - Area Mismatch");
732 }
733 }
734 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
735 else
736 {
737 switch (hdr->circuit_t)
738 {
739 case IS_LEVEL_1:
740 if (adj->adj_state != ISIS_ADJ_UP)
741 {
742 /* (6) reject - Area Mismatch event */
743 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700744 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000745 return ISIS_WARNING; /* Reject */
746 }
747 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
748 {
749 /* (7) down - area mismatch */
750 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000751
hassof390d2c2004-09-10 20:48:21 +0000752 }
753 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
754 (adj->adj_usage == ISIS_ADJ_LEVEL2))
755 {
756 /* (7) down - wrong system */
757 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
758 }
759 break;
760 case IS_LEVEL_1_AND_2:
761 case IS_LEVEL_2:
762 if (adj->adj_state != ISIS_ADJ_UP)
763 {
764 /* (8) adj state up */
765 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
766 /* (9) adj usage level 2 */
767 adj->adj_usage = ISIS_ADJ_LEVEL2;
768 }
769 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
770 {
771 /* (7) down - wrong system */
772 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
773 }
774 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
775 {
776 if (hdr->circuit_t == IS_LEVEL_2)
777 {
778 /* (7) down - wrong system */
779 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
780 "Wrong System");
781 }
782 else
783 {
784 /* (7) down - area mismatch */
785 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
786 "Area Mismatch");
787 }
788 }
789 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
790 {
791 ; /* Accept */
792 }
793 break;
794 }
795 }
jardineb5d44e2003-12-23 08:09:43 +0000796 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700797 else
798 {
799 /* down - area mismatch */
800 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
801 }
jardineb5d44e2003-12-23 08:09:43 +0000802 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
803 /* FIXME - Missing parts */
804
jardineb5d44e2003-12-23 08:09:43 +0000805 /* some of my own understanding of the ISO, why the heck does
806 * it not say what should I change the system_type to...
807 */
hassof390d2c2004-09-10 20:48:21 +0000808 switch (adj->adj_usage)
809 {
jardineb5d44e2003-12-23 08:09:43 +0000810 case ISIS_ADJ_LEVEL1:
811 adj->sys_type = ISIS_SYSTYPE_L1_IS;
812 break;
813 case ISIS_ADJ_LEVEL2:
814 adj->sys_type = ISIS_SYSTYPE_L2_IS;
815 break;
816 case ISIS_ADJ_LEVEL1AND2:
817 adj->sys_type = ISIS_SYSTYPE_L2_IS;
818 break;
819 case ISIS_ADJ_NONE:
820 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
821 break;
hassof390d2c2004-09-10 20:48:21 +0000822 }
jardineb5d44e2003-12-23 08:09:43 +0000823
824 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700825
826 if (isis->debugs & DEBUG_ADJ_PACKETS)
827 {
828 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
829 " cir id %02d, length %d",
830 circuit->area->area_tag, circuit->interface->name,
831 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700832 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700833 }
jardineb5d44e2003-12-23 08:09:43 +0000834
835 free_tlvs (&tlvs);
836
837 return retval;
838}
839
jardineb5d44e2003-12-23 08:09:43 +0000840/*
841 * Process IS-IS LAN Level 1/2 Hello PDU
842 */
hassof390d2c2004-09-10 20:48:21 +0000843static int
844process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000845{
846 int retval = ISIS_OK;
847 struct isis_lan_hello_hdr hdr;
848 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700849 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000850 struct tlvs tlvs;
851 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000852 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000853
Josh Bailey3f045a02012-03-24 08:35:20 -0700854 if (isis->debugs & DEBUG_ADJ_PACKETS)
855 {
856 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
857 "cirID %u",
858 circuit->area->area_tag, level, circuit->interface->name,
859 circuit_t2string (circuit->is_type), circuit->circuit_id);
860 if (isis->debugs & DEBUG_PACKET_DUMP)
861 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
862 stream_get_endp (circuit->rcv_stream));
863 }
864
865 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
866 {
867 zlog_warn ("lan hello on non broadcast circuit");
868 return ISIS_WARNING;
869 }
870
hassof390d2c2004-09-10 20:48:21 +0000871 if ((stream_get_endp (circuit->rcv_stream) -
872 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
873 {
874 zlog_warn ("Packet too short");
875 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000876 }
hassof390d2c2004-09-10 20:48:21 +0000877
878 if (circuit->ext_domain)
879 {
hasso529d65b2004-12-24 00:14:50 +0000880 zlog_debug ("level %d LAN Hello received over circuit with "
881 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000882 return ISIS_WARNING;
883 }
884
Josh Bailey3f045a02012-03-24 08:35:20 -0700885 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000886 {
887 if (isis->debugs & DEBUG_ADJ_PACKETS)
888 {
hasso529d65b2004-12-24 00:14:50 +0000889 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
890 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000891 }
892 return ISIS_WARNING;
893 }
jardineb5d44e2003-12-23 08:09:43 +0000894
895#if 0
896 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000897 if (!accept_level (level, circuit->area->is_type))
898 {
899 if (isis->debugs & DEBUG_ADJ_PACKETS)
900 {
hasso529d65b2004-12-24 00:14:50 +0000901 zlog_debug ("ISIS-Adj (%s): is type mismatch",
902 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000903 }
904 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000905 }
jardineb5d44e2003-12-23 08:09:43 +0000906#endif
907 /*
908 * Fill the header
909 */
910 hdr.circuit_t = stream_getc (circuit->rcv_stream);
911 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
912 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000913 hdr.pdu_len = stream_getw (circuit->rcv_stream);
914 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000915 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
916
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700917 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
918 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700919 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000920 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700921 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
922 "invalid pdu length %d",
923 circuit->area->area_tag, circuit->interface->name,
924 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700925 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700926 }
927
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700928 /*
929 * Set the stream endp to PDU length, ignoring additional padding
930 * introduced by transport chips.
931 */
932 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
933 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
934
Josh Bailey3f045a02012-03-24 08:35:20 -0700935 if (hdr.circuit_t != IS_LEVEL_1 &&
936 hdr.circuit_t != IS_LEVEL_2 &&
937 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
938 (level & hdr.circuit_t) == 0)
939 {
940 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
941 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000942 return ISIS_ERROR;
943 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700944
jardineb5d44e2003-12-23 08:09:43 +0000945 /*
946 * Then get the tlvs
947 */
948 expected |= TLVFLAG_AUTH_INFO;
949 expected |= TLVFLAG_AREA_ADDRS;
950 expected |= TLVFLAG_LAN_NEIGHS;
951 expected |= TLVFLAG_NLPID;
952 expected |= TLVFLAG_IPV4_ADDR;
953 expected |= TLVFLAG_IPV6_ADDR;
954
Josh Bailey3f045a02012-03-24 08:35:20 -0700955 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000956 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -0700957 STREAM_PNT (circuit->rcv_stream),
958 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
959 &expected, &found, &tlvs,
960 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000961
hassof390d2c2004-09-10 20:48:21 +0000962 if (retval > ISIS_WARNING)
963 {
964 zlog_warn ("parse_tlvs() failed");
965 goto out;
966 }
jardineb5d44e2003-12-23 08:09:43 +0000967
hassof390d2c2004-09-10 20:48:21 +0000968 if (!(found & TLVFLAG_AREA_ADDRS))
969 {
970 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
971 level);
jardineb5d44e2003-12-23 08:09:43 +0000972 retval = ISIS_WARNING;
973 goto out;
974 }
hassof390d2c2004-09-10 20:48:21 +0000975
Josh Bailey3f045a02012-03-24 08:35:20 -0700976 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +0000977 if (circuit->passwd.type)
978 {
979 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700980 authentication_check (&tlvs.auth_info, &circuit->passwd,
981 circuit->rcv_stream, auth_tlv_offset))
982 {
983 isis_event_auth_failure (circuit->area->area_tag,
984 "LAN hello authentication failure",
985 hdr.source_id);
986 retval = ISIS_WARNING;
987 goto out;
988 }
hassof390d2c2004-09-10 20:48:21 +0000989 }
jardineb5d44e2003-12-23 08:09:43 +0000990
991 /*
992 * Accept the level 1 adjacency only if a match between local and
993 * remote area addresses is found
994 */
Josh Bailey3f045a02012-03-24 08:35:20 -0700995 if (listcount (circuit->area->area_addrs) == 0 ||
996 (level == IS_LEVEL_1 &&
997 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +0000998 {
999 if (isis->debugs & DEBUG_ADJ_PACKETS)
1000 {
hasso529d65b2004-12-24 00:14:50 +00001001 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1002 circuit->area->area_tag, level,
1003 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001004 }
1005 retval = ISIS_OK;
1006 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001007 }
jardineb5d44e2003-12-23 08:09:43 +00001008
1009 /*
1010 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001011 */
1012 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1013 {
hasso529d65b2004-12-24 00:14:50 +00001014 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1015 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001016
hassof390d2c2004-09-10 20:48:21 +00001017 retval = ISIS_OK;
1018 goto out;
1019 }
jardineb5d44e2003-12-23 08:09:43 +00001020
1021 /*
1022 * check if it's own interface ip match iih ip addrs
1023 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001024 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
1025 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
hassof390d2c2004-09-10 20:48:21 +00001026 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001027 zlog_debug ("ISIS-Adj: No usable IP interface addresses "
1028 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001029 retval = ISIS_WARNING;
1030 goto out;
1031 }
jardineb5d44e2003-12-23 08:09:43 +00001032
1033 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001034 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1035 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001036 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001037 if (!adj)
1038 {
1039 /*
1040 * Do as in 8.4.2.5
1041 */
1042 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1043 if (adj == NULL)
1044 {
1045 retval = ISIS_ERROR;
1046 goto out;
1047 }
1048 }
1049 else
1050 {
1051 if (ssnpa) {
1052 memcpy (adj->snpa, ssnpa, 6);
1053 } else {
1054 memset (adj->snpa, ' ', 6);
1055 }
1056 adj->level = level;
1057 }
hassof390d2c2004-09-10 20:48:21 +00001058 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001059
Josh Bailey3f045a02012-03-24 08:35:20 -07001060 if (level == IS_LEVEL_1)
1061 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001062 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001063 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001064 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1065 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001066 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001067 }
jardineb5d44e2003-12-23 08:09:43 +00001068
hassoa211d652004-09-20 14:55:29 +00001069 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1070 switch (level)
1071 {
1072 case 1:
1073 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1074 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001075 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001076 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1077 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001078 }
1079 break;
1080 case 2:
1081 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1082 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001083 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001084 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1085 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001086 }
1087 break;
1088 }
jardineb5d44e2003-12-23 08:09:43 +00001089
1090 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001091 adj->last_upd = time (NULL);
1092 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001093
1094 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1095
Josh Bailey3f045a02012-03-24 08:35:20 -07001096 tlvs_to_adj_area_addrs (&tlvs, adj);
1097
jardineb5d44e2003-12-23 08:09:43 +00001098 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +00001099 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +00001100 tlvs_to_adj_nlpids (&tlvs, adj);
1101
1102 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001103 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001104 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1105
1106#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001107 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001108 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1109#endif /* HAVE_IPV6 */
1110
1111 adj->circuit_t = hdr.circuit_t;
1112
1113 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001114 THREAD_TIMER_OFF (adj->t_expire);
1115 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001116 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001117
1118 /*
1119 * If the snpa for this circuit is found from LAN Neighbours TLV
1120 * we have two-way communication -> adjacency can be put to state "up"
1121 */
1122
hassof390d2c2004-09-10 20:48:21 +00001123 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001124 {
1125 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001126 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001127 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1128 {
1129 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1130 {
1131 isis_adj_state_change (adj, ISIS_ADJ_UP,
1132 "own SNPA found in LAN Neighbours TLV");
1133 }
1134 }
jardineb5d44e2003-12-23 08:09:43 +00001135 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001136 else
1137 {
1138 int found = 0;
1139 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1140 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1141 {
1142 found = 1;
1143 break;
1144 }
1145 if (found == 0)
1146 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1147 "own SNPA not found in LAN Neighbours TLV");
1148 }
1149 }
1150 else if (adj->adj_state == ISIS_ADJ_UP)
1151 {
1152 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1153 "no LAN Neighbours TLV found");
1154 }
jardineb5d44e2003-12-23 08:09:43 +00001155
hassof390d2c2004-09-10 20:48:21 +00001156out:
hassof390d2c2004-09-10 20:48:21 +00001157 if (isis->debugs & DEBUG_ADJ_PACKETS)
1158 {
hasso529d65b2004-12-24 00:14:50 +00001159 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
1160 "cirID %u, length %ld",
1161 circuit->area->area_tag,
1162 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001163 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001164 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001165 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001166 }
jardineb5d44e2003-12-23 08:09:43 +00001167
1168 free_tlvs (&tlvs);
1169
1170 return retval;
1171}
1172
1173/*
1174 * Process Level 1/2 Link State
1175 * ISO - 10589
1176 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001177 */
1178static int
1179process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001180{
1181 struct isis_link_state_hdr *hdr;
1182 struct isis_adjacency *adj = NULL;
1183 struct isis_lsp *lsp, *lsp0 = NULL;
1184 int retval = ISIS_OK, comp = 0;
1185 u_char lspid[ISIS_SYS_ID_LEN + 2];
1186 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001187 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001188
Josh Bailey3f045a02012-03-24 08:35:20 -07001189 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1190 {
1191 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1192 circuit->area->area_tag, level, circuit->interface->name,
1193 circuit_t2string (circuit->is_type), circuit->circuit_id);
1194 if (isis->debugs & DEBUG_PACKET_DUMP)
1195 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1196 stream_get_endp (circuit->rcv_stream));
1197 }
1198
hassof390d2c2004-09-10 20:48:21 +00001199 if ((stream_get_endp (circuit->rcv_stream) -
1200 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1201 {
1202 zlog_warn ("Packet too short");
1203 return ISIS_WARNING;
1204 }
jardineb5d44e2003-12-23 08:09:43 +00001205
1206 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001207 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001208 pdu_len = ntohs (hdr->pdu_len);
1209
1210 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001211 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001212 pdu_len > ISO_MTU(circuit) ||
1213 pdu_len > stream_get_endp (circuit->rcv_stream))
1214 {
1215 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1216 circuit->area->area_tag,
1217 rawlspid_print (hdr->lsp_id), pdu_len);
1218
1219 return ISIS_WARNING;
1220 }
1221
1222 /*
1223 * Set the stream endp to PDU length, ignoring additional padding
1224 * introduced by transport chips.
1225 */
1226 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1227 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001228
hassof390d2c2004-09-10 20:48:21 +00001229 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1230 {
hasso529d65b2004-12-24 00:14:50 +00001231 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001232 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001233 circuit->area->area_tag,
1234 level,
1235 rawlspid_print (hdr->lsp_id),
1236 ntohl (hdr->seq_num),
1237 ntohs (hdr->checksum),
1238 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001239 pdu_len,
paul15935e92005-05-03 09:27:23 +00001240 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001241 }
jardineb5d44e2003-12-23 08:09:43 +00001242
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001243 /* lsp is_type check */
1244 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1245 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001246 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001247 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001248 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001249 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1250 /* continue as per RFC1122 Be liberal in what you accept, and
1251 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001252 }
jardineb5d44e2003-12-23 08:09:43 +00001253
1254 /* Checksum sanity check - FIXME: move to correct place */
1255 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001256 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001257 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001258 {
hasso529d65b2004-12-24 00:14:50 +00001259 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1260 circuit->area->area_tag,
1261 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001262
hassof390d2c2004-09-10 20:48:21 +00001263 return ISIS_WARNING;
1264 }
jardineb5d44e2003-12-23 08:09:43 +00001265
1266 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001267 if (circuit->ext_domain)
1268 {
hasso529d65b2004-12-24 00:14:50 +00001269 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001270 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1271 "externalDomain = true", circuit->area->area_tag,
1272 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001273
hassof390d2c2004-09-10 20:48:21 +00001274 return ISIS_WARNING;
1275 }
jardineb5d44e2003-12-23 08:09:43 +00001276
1277 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001278 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001279 {
hasso529d65b2004-12-24 00:14:50 +00001280 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1281 " type %s",
1282 circuit->area->area_tag,
1283 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001284 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001285
hassof390d2c2004-09-10 20:48:21 +00001286 return ISIS_WARNING;
1287 }
jardineb5d44e2003-12-23 08:09:43 +00001288
1289 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1290
1291 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1292
1293 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001294 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1295 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001296 if (passwd->type)
1297 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001298 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1299 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001300 {
1301 isis_event_auth_failure (circuit->area->area_tag,
1302 "LSP authentication failure", hdr->lsp_id);
1303 return ISIS_WARNING;
1304 }
jardineb5d44e2003-12-23 08:09:43 +00001305 }
jardineb5d44e2003-12-23 08:09:43 +00001306 /* Find the LSP in our database and compare it to this Link State header */
1307 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1308 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001309 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1310 hdr->checksum, hdr->rem_lifetime);
1311 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001312#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001313 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001314#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001315 ))
jardineb5d44e2003-12-23 08:09:43 +00001316 goto dontcheckadj;
1317
1318 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1319 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001320
hassof390d2c2004-09-10 20:48:21 +00001321 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1322 {
1323 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1324 if (!adj)
1325 {
hasso529d65b2004-12-24 00:14:50 +00001326 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1327 "lifetime %us on %s",
1328 circuit->area->area_tag,
1329 rawlspid_print (hdr->lsp_id),
1330 ntohl (hdr->seq_num),
1331 ntohs (hdr->checksum),
1332 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001333 return ISIS_WARNING; /* Silently discard */
1334 }
jardineb5d44e2003-12-23 08:09:43 +00001335 }
jardineb5d44e2003-12-23 08:09:43 +00001336 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001337 else
1338 {
1339 /* If no adj, or no sharing of level */
1340 if (!circuit->u.p2p.neighbor)
1341 {
1342 return ISIS_OK; /* Silently discard */
1343 }
1344 else
1345 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001346 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001347 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001348 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001349 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1350 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001351 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001352 }
jardineb5d44e2003-12-23 08:09:43 +00001353 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001354
hassof390d2c2004-09-10 20:48:21 +00001355dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001356 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1357
1358 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1359
hassof390d2c2004-09-10 20:48:21 +00001360 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001361
hassof390d2c2004-09-10 20:48:21 +00001362 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1363 if (hdr->rem_lifetime == 0)
1364 {
1365 if (!lsp)
1366 {
1367 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1368 /* only needed on explicit update, eg - p2p */
1369 if (circuit->circ_type == CIRCUIT_T_P2P)
1370 ack_lsp (hdr, circuit, level);
1371 return retval; /* FIXME: do we need a purge? */
1372 }
1373 else
1374 {
1375 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1376 {
1377 /* LSP by some other system -> do 7.3.16.4 b) */
1378 /* 7.3.16.4 b) 1) */
1379 if (comp == LSP_NEWER)
1380 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001381 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001382 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001383 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001384 /* iii */
1385 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1386 /* v */
1387 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1388 /* iv */
1389 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1390 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001391
hassof390d2c2004-09-10 20:48:21 +00001392 } /* 7.3.16.4 b) 2) */
1393 else if (comp == LSP_EQUAL)
1394 {
1395 /* i */
1396 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1397 /* ii */
1398 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1399 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1400 } /* 7.3.16.4 b) 3) */
1401 else
1402 {
1403 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1404 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1405 }
1406 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001407 else if (lsp->lsp_header->rem_lifetime != 0)
1408 {
1409 /* our own LSP -> 7.3.16.4 c) */
1410 if (comp == LSP_NEWER)
1411 {
1412 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1413 lsp_set_all_srmflags (lsp);
1414 }
1415 else
1416 {
1417 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1418 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1419 }
1420 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1421 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1422 "seq 0x%08x", circuit->area->area_tag,
1423 rawlspid_print (hdr->lsp_id),
1424 ntohl (lsp->lsp_header->seq_num));
1425 }
hassof390d2c2004-09-10 20:48:21 +00001426 }
1427 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001428 }
jardineb5d44e2003-12-23 08:09:43 +00001429 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1430 * purge */
hassof390d2c2004-09-10 20:48:21 +00001431 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1432 {
1433 if (!lsp)
1434 {
1435 /* 7.3.16.4: initiate a purge */
1436 lsp_purge_non_exist (hdr, circuit->area);
1437 return ISIS_OK;
1438 }
1439 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1440
1441 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1442 * has information that the current sequence number for source S is
1443 * "greater" than that held by S, ... */
1444
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001445 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001446 {
1447 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001448 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001449 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1450 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1451 "0x%08x", circuit->area->area_tag,
1452 rawlspid_print (hdr->lsp_id),
1453 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001454 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001455 /* If the received LSP is older or equal,
1456 * resend the LSP which will act as ACK */
1457 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001458 }
hassof390d2c2004-09-10 20:48:21 +00001459 else
1460 {
1461 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001462
hassof390d2c2004-09-10 20:48:21 +00001463 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1464 if ((!lsp || comp == LSP_NEWER))
1465 {
hassof390d2c2004-09-10 20:48:21 +00001466 /*
1467 * If this lsp is a frag, need to see if we have zero lsp present
1468 */
1469 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1470 {
1471 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1472 LSP_FRAGMENT (lspid) = 0;
1473 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1474 if (!lsp0)
1475 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001476 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001477 return ISIS_OK;
1478 }
1479 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001480 /* i */
1481 if (!lsp)
1482 {
1483 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001484 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001485 circuit->area, level);
1486 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1487 }
1488 else /* exists, so we overwrite */
1489 {
1490 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1491 }
hassof390d2c2004-09-10 20:48:21 +00001492 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001493 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001494 /* iii */
1495 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001496
hassof390d2c2004-09-10 20:48:21 +00001497 /* iv */
1498 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1499 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1500 /* FIXME: v) */
1501 }
1502 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1503 else if (comp == LSP_EQUAL)
1504 {
1505 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001506 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001507 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001508 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001509 }
1510 /* 7.3.15.1 e) 3) LSP older than the one in db */
1511 else
1512 {
1513 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1514 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1515 }
jardineb5d44e2003-12-23 08:09:43 +00001516 }
jardineb5d44e2003-12-23 08:09:43 +00001517 return retval;
1518}
1519
1520/*
1521 * Process Sequence Numbers
1522 * ISO - 10589
1523 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1524 */
1525
hasso92365882005-01-18 13:53:33 +00001526static int
hassof390d2c2004-09-10 20:48:21 +00001527process_snp (int snp_type, int level, struct isis_circuit *circuit,
1528 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001529{
1530 int retval = ISIS_OK;
1531 int cmp, own_lsp;
1532 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001533 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001534 struct isis_adjacency *adj;
1535 struct isis_complete_seqnum_hdr *chdr = NULL;
1536 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001537 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001538 struct isis_lsp *lsp;
1539 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001540 struct listnode *node, *nnode;
1541 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001542 struct tlvs tlvs;
1543 struct list *lsp_list = NULL;
1544 struct isis_passwd *passwd;
1545
hassof390d2c2004-09-10 20:48:21 +00001546 if (snp_type == ISIS_SNP_CSNP_FLAG)
1547 {
1548 /* getting the header info */
1549 typechar = 'C';
1550 chdr =
1551 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001552 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1553 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001554 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001555 pdu_len > ISO_MTU(circuit) ||
1556 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001557 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001558 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1559 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001560 }
jardineb5d44e2003-12-23 08:09:43 +00001561 }
hassof390d2c2004-09-10 20:48:21 +00001562 else
1563 {
1564 typechar = 'P';
1565 phdr =
1566 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001567 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1568 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001569 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001570 pdu_len > ISO_MTU(circuit) ||
1571 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001572 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001573 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1574 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001575 }
jardineb5d44e2003-12-23 08:09:43 +00001576 }
jardineb5d44e2003-12-23 08:09:43 +00001577
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001578 /*
1579 * Set the stream endp to PDU length, ignoring additional padding
1580 * introduced by transport chips.
1581 */
1582 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1583 stream_set_endp (circuit->rcv_stream, pdu_len);
1584
jardineb5d44e2003-12-23 08:09:43 +00001585 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001586 if (circuit->ext_domain)
1587 {
jardineb5d44e2003-12-23 08:09:43 +00001588
hasso529d65b2004-12-24 00:14:50 +00001589 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1590 "skipping: circuit externalDomain = true",
1591 circuit->area->area_tag,
1592 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001593
1594 return ISIS_OK;
1595 }
hassof390d2c2004-09-10 20:48:21 +00001596
1597 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001598 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001599 {
1600
hasso529d65b2004-12-24 00:14:50 +00001601 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1602 "skipping: circuit type %s does not match level %d",
1603 circuit->area->area_tag,
1604 level,
1605 typechar,
1606 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001607 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001608
1609 return ISIS_OK;
1610 }
1611
1612 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1613 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001614 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1615 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001616 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001617 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1618 "skipping: we are not the DIS",
1619 circuit->area->area_tag,
1620 level,
1621 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001622
Josh Bailey3f045a02012-03-24 08:35:20 -07001623 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001624 }
jardineb5d44e2003-12-23 08:09:43 +00001625
1626 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1627
1628 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1629 * - already checked */
1630
1631 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1632 /* for broadcast circuits, snpa should be compared */
1633 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001634 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1635 {
1636 if (snp_type == ISIS_SNP_CSNP_FLAG)
1637 {
1638 adj =
1639 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1640 }
1641 else
1642 {
1643 /* a psnp on a broadcast, how lovely of Juniper :) */
1644 adj =
1645 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1646 }
1647 if (!adj)
1648 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001649 }
hassof390d2c2004-09-10 20:48:21 +00001650 else
1651 {
1652 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001653 {
1654 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1655 return ISIS_OK; /* Silently discard */
1656 }
hassof390d2c2004-09-10 20:48:21 +00001657 }
jardineb5d44e2003-12-23 08:09:43 +00001658
1659 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1660
1661 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1662
1663 memset (&tlvs, 0, sizeof (struct tlvs));
1664
1665 /* parse the SNP */
1666 expected |= TLVFLAG_LSP_ENTRIES;
1667 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001668
1669 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001670 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001671 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001672 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001673 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001674
hassof390d2c2004-09-10 20:48:21 +00001675 if (retval > ISIS_WARNING)
1676 {
1677 zlog_warn ("something went very wrong processing SNP");
1678 free_tlvs (&tlvs);
1679 return retval;
1680 }
jardineb5d44e2003-12-23 08:09:43 +00001681
Josh Bailey3f045a02012-03-24 08:35:20 -07001682 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001683 passwd = &circuit->area->area_passwd;
1684 else
1685 passwd = &circuit->area->domain_passwd;
1686
1687 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001688 {
hasso1cbc5622005-01-01 10:29:51 +00001689 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001690 {
1691 if (!(found & TLVFLAG_AUTH_INFO) ||
1692 authentication_check (&tlvs.auth_info, passwd,
1693 circuit->rcv_stream, auth_tlv_offset))
1694 {
1695 isis_event_auth_failure (circuit->area->area_tag,
1696 "SNP authentication" " failure",
1697 phdr ? phdr->source_id :
1698 chdr->source_id);
1699 free_tlvs (&tlvs);
1700 return ISIS_OK;
1701 }
1702 }
hassof390d2c2004-09-10 20:48:21 +00001703 }
jardineb5d44e2003-12-23 08:09:43 +00001704
1705 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001706 if (isis->debugs & DEBUG_SNP_PACKETS)
1707 {
hasso529d65b2004-12-24 00:14:50 +00001708 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1709 circuit->area->area_tag,
1710 level,
1711 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001712 if (tlvs.lsp_entries)
1713 {
hasso3fdb2dd2005-09-28 18:45:54 +00001714 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001715 {
hasso529d65b2004-12-24 00:14:50 +00001716 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1717 " cksum 0x%04x, lifetime %us",
1718 circuit->area->area_tag,
1719 typechar,
1720 rawlspid_print (entry->lsp_id),
1721 ntohl (entry->seq_num),
1722 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001723 }
1724 }
jardineb5d44e2003-12-23 08:09:43 +00001725 }
jardineb5d44e2003-12-23 08:09:43 +00001726
1727 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001728 if (tlvs.lsp_entries)
1729 {
hasso3fdb2dd2005-09-28 18:45:54 +00001730 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001731 {
1732 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1733 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1734 if (lsp)
1735 {
1736 /* 7.3.15.2 b) 1) is this LSP newer */
1737 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1738 entry->checksum, entry->rem_lifetime);
1739 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1740 if (cmp == LSP_EQUAL)
1741 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001742 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1743 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001744 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001745 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001746 else if (cmp == LSP_OLDER)
1747 {
1748 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1749 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1750 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001751 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001752 else
1753 {
hassof390d2c2004-09-10 20:48:21 +00001754 if (own_lsp)
1755 {
1756 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1757 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1758 }
1759 else
1760 {
1761 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001762 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1763 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001764 }
1765 }
1766 }
1767 else
1768 {
1769 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1770 * insert it and set SSN on it */
1771 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1772 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1773 {
1774 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1775 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001776 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001777 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001778 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001779 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1780 }
1781 }
jardineb5d44e2003-12-23 08:09:43 +00001782 }
1783 }
jardineb5d44e2003-12-23 08:09:43 +00001784
1785 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001786 if (snp_type == ISIS_SNP_CSNP_FLAG)
1787 {
1788 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001789 * Build a list from our own LSP db bounded with
1790 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001791 */
1792 lsp_list = list_new ();
1793 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1794 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001795
hassof390d2c2004-09-10 20:48:21 +00001796 /* Fixme: Find a better solution */
1797 if (tlvs.lsp_entries)
1798 {
paul1eb8ef22005-04-07 07:30:20 +00001799 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001800 {
paul1eb8ef22005-04-07 07:30:20 +00001801 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001802 {
1803 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1804 {
1805 list_delete_node (lsp_list, node2);
1806 break;
1807 }
1808 }
1809 }
1810 }
1811 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001812 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001813 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001814 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001815 list_delete (lsp_list);
1816
jardineb5d44e2003-12-23 08:09:43 +00001817 }
jardineb5d44e2003-12-23 08:09:43 +00001818
1819 free_tlvs (&tlvs);
1820 return retval;
1821}
1822
hasso92365882005-01-18 13:53:33 +00001823static int
hassof390d2c2004-09-10 20:48:21 +00001824process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001825{
Josh Bailey3f045a02012-03-24 08:35:20 -07001826 if (isis->debugs & DEBUG_SNP_PACKETS)
1827 {
1828 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1829 circuit->area->area_tag, level, circuit->interface->name,
1830 circuit_t2string (circuit->is_type), circuit->circuit_id);
1831 if (isis->debugs & DEBUG_PACKET_DUMP)
1832 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1833 stream_get_endp (circuit->rcv_stream));
1834 }
1835
jardineb5d44e2003-12-23 08:09:43 +00001836 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001837 if ((stream_get_endp (circuit->rcv_stream) -
1838 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1839 {
1840 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1841 return ISIS_WARNING;
1842 }
jardineb5d44e2003-12-23 08:09:43 +00001843
1844 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1845}
1846
hasso92365882005-01-18 13:53:33 +00001847static int
hassof390d2c2004-09-10 20:48:21 +00001848process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001849{
Josh Bailey3f045a02012-03-24 08:35:20 -07001850 if (isis->debugs & DEBUG_SNP_PACKETS)
1851 {
1852 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1853 circuit->area->area_tag, level, circuit->interface->name,
1854 circuit_t2string (circuit->is_type), circuit->circuit_id);
1855 if (isis->debugs & DEBUG_PACKET_DUMP)
1856 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1857 stream_get_endp (circuit->rcv_stream));
1858 }
1859
hassof390d2c2004-09-10 20:48:21 +00001860 if ((stream_get_endp (circuit->rcv_stream) -
1861 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1862 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001863 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001864 return ISIS_WARNING;
1865 }
jardineb5d44e2003-12-23 08:09:43 +00001866
1867 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1868}
1869
jardineb5d44e2003-12-23 08:09:43 +00001870/*
1871 * Process ISH
1872 * ISO - 10589
1873 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1874 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001875 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1876 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1877 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001878 */
hasso92365882005-01-18 13:53:33 +00001879static int
jardineb5d44e2003-12-23 08:09:43 +00001880process_is_hello (struct isis_circuit *circuit)
1881{
1882 struct isis_adjacency *adj;
1883 int retval = ISIS_OK;
1884 u_char neigh_len;
1885 u_char *sysid;
1886
Josh Bailey3f045a02012-03-24 08:35:20 -07001887 if (isis->debugs & DEBUG_ADJ_PACKETS)
1888 {
1889 zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u",
1890 circuit->area->area_tag, circuit->interface->name,
1891 circuit_t2string (circuit->is_type), circuit->circuit_id);
1892 if (isis->debugs & DEBUG_PACKET_DUMP)
1893 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1894 stream_get_endp (circuit->rcv_stream));
1895 }
1896
jardineb5d44e2003-12-23 08:09:43 +00001897 /* In this point in time we are not yet able to handle is_hellos
1898 * on lan - Sorry juniper...
1899 */
1900 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1901 return retval;
1902
1903 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001904 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001905 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001906 if (!adj)
1907 {
1908 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00001909 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001910 if (adj == NULL)
1911 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001912
hassof390d2c2004-09-10 20:48:21 +00001913 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1914 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1915 circuit->u.p2p.neighbor = adj;
1916 }
1917 /* 8.2.2 a) */
1918 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1919 ISIS_SYS_ID_LEN))
1920 {
1921 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1922 /* 8.2.2 a) 2) delete the adj */
1923 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1924 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00001925 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001926 if (adj == NULL)
1927 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001928
hassof390d2c2004-09-10 20:48:21 +00001929 /* 8.2.2 a) 3) i */
1930 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1931 /* 8.2.2 a) 3) ii */
1932 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1933 /* 8.2.2 a) 4) quite meaningless */
1934 }
jardineb5d44e2003-12-23 08:09:43 +00001935 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001936 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1937 (adj->sys_type == ISIS_SYSTYPE_IS))
1938 {
1939 /* do nothing */
1940 }
1941 else
1942 {
1943 /* 8.2.2 c) respond with a p2p IIH */
1944 send_hello (circuit, 1);
1945 }
jardineb5d44e2003-12-23 08:09:43 +00001946 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001947 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001948 /* 8.2.2 e) FIXME: Circuit type of? */
1949
jardineb5d44e2003-12-23 08:09:43 +00001950 return retval;
1951}
1952
jardineb5d44e2003-12-23 08:09:43 +00001953/*
1954 * PDU Dispatcher
1955 */
1956
hasso92365882005-01-18 13:53:33 +00001957static int
hassof390d2c2004-09-10 20:48:21 +00001958isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001959{
jardineb5d44e2003-12-23 08:09:43 +00001960 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00001961
hassof390d2c2004-09-10 20:48:21 +00001962 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001963
1964 /*
1965 * Let's first read data from stream to the header
1966 */
hassof390d2c2004-09-10 20:48:21 +00001967 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001968
hassof390d2c2004-09-10 20:48:21 +00001969 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1970 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001971 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00001972 return ISIS_ERROR;
1973 }
jardineb5d44e2003-12-23 08:09:43 +00001974
1975 /* now we need to know if this is an ISO 9542 packet and
1976 * take real good care of it, waaa!
1977 */
hassof390d2c2004-09-10 20:48:21 +00001978 if (hdr->idrp == ISO9542_ESIS)
1979 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001980 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
1981 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00001982 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001983 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1984
jardineb5d44e2003-12-23 08:09:43 +00001985 /*
1986 * and then process it
1987 */
1988
hassof390d2c2004-09-10 20:48:21 +00001989 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1990 {
1991 zlog_err ("Fixed header length = %d", hdr->length);
1992 return ISIS_ERROR;
1993 }
jardineb5d44e2003-12-23 08:09:43 +00001994
hassof390d2c2004-09-10 20:48:21 +00001995 if (hdr->version1 != 1)
1996 {
1997 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1998 return ISIS_WARNING;
1999 }
jardineb5d44e2003-12-23 08:09:43 +00002000 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002001 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2002 {
2003 zlog_err
2004 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2005 "while the parameter for this IS is %u", hdr->id_len,
2006 ISIS_SYS_ID_LEN);
2007 return ISIS_ERROR;
2008 }
jardineb5d44e2003-12-23 08:09:43 +00002009
hassof390d2c2004-09-10 20:48:21 +00002010 if (hdr->version2 != 1)
2011 {
2012 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2013 return ISIS_WARNING;
2014 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002015
2016 if (circuit->is_passive)
2017 {
2018 zlog_warn ("Received ISIS PDU on passive circuit %s",
2019 circuit->interface->name);
2020 return ISIS_WARNING;
2021 }
2022
jardineb5d44e2003-12-23 08:09:43 +00002023 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002024 if ((hdr->max_area_addrs != 0)
2025 && (hdr->max_area_addrs != isis->max_area_addrs))
2026 {
2027 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2028 "received PDU %u while the parameter for this IS is %u",
2029 hdr->max_area_addrs, isis->max_area_addrs);
2030 return ISIS_ERROR;
2031 }
jardineb5d44e2003-12-23 08:09:43 +00002032
hassof390d2c2004-09-10 20:48:21 +00002033 switch (hdr->pdu_type)
2034 {
2035 case L1_LAN_HELLO:
2036 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2037 break;
2038 case L2_LAN_HELLO:
2039 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2040 break;
2041 case P2P_HELLO:
2042 retval = process_p2p_hello (circuit);
2043 break;
2044 case L1_LINK_STATE:
2045 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2046 break;
2047 case L2_LINK_STATE:
2048 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2049 break;
2050 case L1_COMPLETE_SEQ_NUM:
2051 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2052 break;
2053 case L2_COMPLETE_SEQ_NUM:
2054 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2055 break;
2056 case L1_PARTIAL_SEQ_NUM:
2057 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2058 break;
2059 case L2_PARTIAL_SEQ_NUM:
2060 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2061 break;
2062 default:
2063 return ISIS_ERROR;
2064 }
jardineb5d44e2003-12-23 08:09:43 +00002065
2066 return retval;
2067}
2068
jardineb5d44e2003-12-23 08:09:43 +00002069#ifdef GNU_LINUX
2070int
2071isis_receive (struct thread *thread)
2072{
jardineb5d44e2003-12-23 08:09:43 +00002073 struct isis_circuit *circuit;
2074 u_char ssnpa[ETH_ALEN];
2075 int retval;
2076
2077 /*
2078 * Get the circuit
2079 */
2080 circuit = THREAD_ARG (thread);
2081 assert (circuit);
2082
2083 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002084 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002085 else
2086 stream_reset (circuit->rcv_stream);
2087
2088 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002089 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002090
2091 if (retval == ISIS_OK)
2092 retval = isis_handle_pdu (circuit, ssnpa);
2093
2094 /*
2095 * prepare for next packet.
2096 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002097 if (!circuit->is_passive)
2098 {
2099 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2100 circuit->fd);
2101 }
jardineb5d44e2003-12-23 08:09:43 +00002102
2103 return retval;
2104}
2105
2106#else
2107int
2108isis_receive (struct thread *thread)
2109{
jardineb5d44e2003-12-23 08:09:43 +00002110 struct isis_circuit *circuit;
2111 u_char ssnpa[ETH_ALEN];
2112 int retval;
2113
2114 /*
2115 * Get the circuit
2116 */
2117 circuit = THREAD_ARG (thread);
2118 assert (circuit);
2119
hassof390d2c2004-09-10 20:48:21 +00002120 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002121
2122 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002123 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002124 else
2125 stream_reset (circuit->rcv_stream);
2126
2127 retval = circuit->rx (circuit, ssnpa);
2128
2129 if (retval == ISIS_OK)
2130 retval = isis_handle_pdu (circuit, ssnpa);
2131
2132 /*
2133 * prepare for next packet.
2134 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002135 if (!circuit->is_passive)
2136 {
2137 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2138 listcount
2139 (circuit->area->circuit_list) *
2140 100);
2141 }
jardineb5d44e2003-12-23 08:09:43 +00002142
2143 return retval;
2144}
2145
2146#endif
2147
2148 /* filling of the fixed isis header */
2149void
2150fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2151{
2152 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2153
2154 hdr->idrp = ISO10589_ISIS;
2155
hassof390d2c2004-09-10 20:48:21 +00002156 switch (pdu_type)
2157 {
2158 case L1_LAN_HELLO:
2159 case L2_LAN_HELLO:
2160 hdr->length = ISIS_LANHELLO_HDRLEN;
2161 break;
2162 case P2P_HELLO:
2163 hdr->length = ISIS_P2PHELLO_HDRLEN;
2164 break;
2165 case L1_LINK_STATE:
2166 case L2_LINK_STATE:
2167 hdr->length = ISIS_LSP_HDR_LEN;
2168 break;
2169 case L1_COMPLETE_SEQ_NUM:
2170 case L2_COMPLETE_SEQ_NUM:
2171 hdr->length = ISIS_CSNP_HDRLEN;
2172 break;
2173 case L1_PARTIAL_SEQ_NUM:
2174 case L2_PARTIAL_SEQ_NUM:
2175 hdr->length = ISIS_PSNP_HDRLEN;
2176 break;
2177 default:
2178 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2179 return;
2180 }
jardineb5d44e2003-12-23 08:09:43 +00002181 hdr->length += ISIS_FIXED_HDR_LEN;
2182 hdr->pdu_type = pdu_type;
2183 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002184 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002185 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002186 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002187}
2188
jardineb5d44e2003-12-23 08:09:43 +00002189/*
2190 * SEND SIDE
2191 */
hasso92365882005-01-18 13:53:33 +00002192static void
jardineb5d44e2003-12-23 08:09:43 +00002193fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002194 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002195{
hassof390d2c2004-09-10 20:48:21 +00002196 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002197
2198 stream_putc (stream, hdr->idrp);
2199 stream_putc (stream, hdr->length);
2200 stream_putc (stream, hdr->version1);
2201 stream_putc (stream, hdr->id_len);
2202 stream_putc (stream, hdr->pdu_type);
2203 stream_putc (stream, hdr->version2);
2204 stream_putc (stream, hdr->reserved);
2205 stream_putc (stream, hdr->max_area_addrs);
2206
2207 return;
2208}
2209
jardineb5d44e2003-12-23 08:09:43 +00002210int
2211send_hello (struct isis_circuit *circuit, int level)
2212{
2213 struct isis_fixed_hdr fixed_hdr;
2214 struct isis_lan_hello_hdr hello_hdr;
2215 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002216 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2217 unsigned long len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002218 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002219 int retval;
2220
Josh Bailey3f045a02012-03-24 08:35:20 -07002221 if (circuit->is_passive)
2222 return ISIS_OK;
2223
hassof390d2c2004-09-10 20:48:21 +00002224 if (circuit->interface->mtu == 0)
2225 {
2226 zlog_warn ("circuit has zero MTU");
2227 return ISIS_WARNING;
2228 }
jardineb5d44e2003-12-23 08:09:43 +00002229
2230 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002231 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002232 else
2233 stream_reset (circuit->snd_stream);
2234
2235 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002236 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002237 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2238 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002239 else
hassof390d2c2004-09-10 20:48:21 +00002240 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2241 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002242 else
hassof390d2c2004-09-10 20:48:21 +00002243 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002244
2245 /*
2246 * Fill LAN Level 1 or 2 Hello PDU header
2247 */
2248 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002249 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002250 circuit->hello_interval[level - 1];
2251 if (interval > USHRT_MAX)
2252 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002253 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002254 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002255 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002256
hassof390d2c2004-09-10 20:48:21 +00002257 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002258 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002259
2260 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002261 if (circuit->circ_type == CIRCUIT_T_P2P)
2262 {
2263 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2264 p2p_hello_hdr.local_id = circuit->circuit_id;
2265 /* FIXME: need better understanding */
2266 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002267 }
hassof390d2c2004-09-10 20:48:21 +00002268 else
2269 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002270 hello_hdr.prio = circuit->priority[level - 1];
2271 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002272 {
2273 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2274 ISIS_SYS_ID_LEN + 1);
2275 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002276 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002277 {
2278 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2279 ISIS_SYS_ID_LEN + 1);
2280 }
2281 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2282 }
jardineb5d44e2003-12-23 08:09:43 +00002283
2284 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002285 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002286 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002287
jardineb5d44e2003-12-23 08:09:43 +00002288 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002289 switch (circuit->passwd.type)
2290 {
2291 /* Cleartext */
2292 case ISIS_PASSWD_TYPE_CLEARTXT:
2293 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2294 circuit->passwd.passwd, circuit->snd_stream))
2295 return ISIS_WARNING;
2296 break;
2297
2298 /* HMAC MD5 */
2299 case ISIS_PASSWD_TYPE_HMAC_MD5:
2300 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2301 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2302 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2303 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2304 hmac_md5_hash, circuit->snd_stream))
2305 return ISIS_WARNING;
2306 break;
2307
2308 default:
2309 break;
2310 }
2311
jardineb5d44e2003-12-23 08:09:43 +00002312 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002313 if (listcount (circuit->area->area_addrs) == 0)
2314 return ISIS_WARNING;
2315 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2316 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002317
2318 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002319 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2320 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002321 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2322 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002323 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2324 circuit->snd_stream))
2325 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002326 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2327 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002328 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2329 circuit->snd_stream))
2330 return ISIS_WARNING;
2331 }
jardineb5d44e2003-12-23 08:09:43 +00002332
2333 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002334 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002335 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2336 return ISIS_WARNING;
2337 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002338 if (circuit->ip_router && circuit->ip_addrs &&
2339 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002340 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2341 return ISIS_WARNING;
2342
hassof390d2c2004-09-10 20:48:21 +00002343#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002344 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002345 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002346 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002347 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2348 return ISIS_WARNING;
2349#endif /* HAVE_IPV6 */
2350
Josh Bailey3f045a02012-03-24 08:35:20 -07002351 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002352 if (tlv_add_padding (circuit->snd_stream))
2353 return ISIS_WARNING;
2354
paul9985f832005-02-09 15:51:56 +00002355 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002356 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002357 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002358
Josh Bailey3f045a02012-03-24 08:35:20 -07002359 /* For HMAC MD5 we need to compute the md5 hash and store it */
2360 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2361 {
2362 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2363 stream_get_endp (circuit->snd_stream),
2364 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
2365 (caddr_t) &hmac_md5_hash);
2366 /* Copy the hash into the stream */
2367 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2368 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2369 }
jardineb5d44e2003-12-23 08:09:43 +00002370
hassof390d2c2004-09-10 20:48:21 +00002371 if (isis->debugs & DEBUG_ADJ_PACKETS)
2372 {
2373 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2374 {
hasso529d65b2004-12-24 00:14:50 +00002375 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2376 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002377 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002378 length);
hassof390d2c2004-09-10 20:48:21 +00002379 }
2380 else
2381 {
hasso529d65b2004-12-24 00:14:50 +00002382 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2383 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002384 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002385 length);
hassof390d2c2004-09-10 20:48:21 +00002386 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002387 if (isis->debugs & DEBUG_PACKET_DUMP)
2388 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2389 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002390 }
jardineb5d44e2003-12-23 08:09:43 +00002391
Josh Bailey3f045a02012-03-24 08:35:20 -07002392 retval = circuit->tx (circuit, level);
2393 if (retval != ISIS_OK)
2394 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2395 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002396
Josh Bailey3f045a02012-03-24 08:35:20 -07002397 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002398}
2399
2400int
2401send_lan_l1_hello (struct thread *thread)
2402{
jardineb5d44e2003-12-23 08:09:43 +00002403 struct isis_circuit *circuit;
2404 int retval;
2405
2406 circuit = THREAD_ARG (thread);
2407 assert (circuit);
2408 circuit->u.bc.t_send_lan_hello[0] = NULL;
2409
2410 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002411 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002412
Josh Bailey3f045a02012-03-24 08:35:20 -07002413 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002414
2415 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002416 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2417 send_lan_l1_hello, circuit,
2418 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002419
2420 return retval;
2421}
2422
2423int
2424send_lan_l2_hello (struct thread *thread)
2425{
2426 struct isis_circuit *circuit;
2427 int retval;
2428
2429 circuit = THREAD_ARG (thread);
2430 assert (circuit);
2431 circuit->u.bc.t_send_lan_hello[1] = NULL;
2432
2433 if (circuit->u.bc.run_dr_elect[1])
2434 retval = isis_dr_elect (circuit, 2);
2435
Josh Bailey3f045a02012-03-24 08:35:20 -07002436 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002437
hassof390d2c2004-09-10 20:48:21 +00002438 /* set next timer thread */
2439 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2440 send_lan_l2_hello, circuit,
2441 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002442
2443 return retval;
2444}
2445
2446int
2447send_p2p_hello (struct thread *thread)
2448{
2449 struct isis_circuit *circuit;
2450
2451 circuit = THREAD_ARG (thread);
2452 assert (circuit);
2453 circuit->u.p2p.t_send_p2p_hello = NULL;
2454
hassof390d2c2004-09-10 20:48:21 +00002455 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002456
hassof390d2c2004-09-10 20:48:21 +00002457 /* set next timer thread */
2458 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2459 circuit, isis_jitter (circuit->hello_interval[1],
2460 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002461
2462 return ISIS_OK;
2463}
2464
hasso92365882005-01-18 13:53:33 +00002465static int
hassof390d2c2004-09-10 20:48:21 +00002466build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2467 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002468{
2469 struct isis_fixed_hdr fixed_hdr;
2470 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002471 unsigned long lenp;
2472 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002473 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2474 unsigned long auth_tlv_offset = 0;
2475 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002476
Josh Bailey3f045a02012-03-24 08:35:20 -07002477 if (circuit->snd_stream == NULL)
2478 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2479 else
2480 stream_reset (circuit->snd_stream);
2481
2482 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002483 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2484 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002485 else
hassof390d2c2004-09-10 20:48:21 +00002486 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2487 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002488
2489 /*
2490 * Fill Level 1 or 2 Complete Sequence Numbers header
2491 */
2492
paul9985f832005-02-09 15:51:56 +00002493 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002494 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002495 /* no need to send the source here, it is always us if we csnp */
2496 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2497 /* with zero circuit id - ref 9.10, 9.11 */
2498 stream_putc (circuit->snd_stream, 0x00);
2499
2500 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2501 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2502
2503 /*
2504 * And TLVs
2505 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002506 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002507 passwd = &circuit->area->area_passwd;
2508 else
2509 passwd = &circuit->area->domain_passwd;
2510
hasso1cbc5622005-01-01 10:29:51 +00002511 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002512 {
2513 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002514 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002515 /* Cleartext */
2516 case ISIS_PASSWD_TYPE_CLEARTXT:
2517 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2518 passwd->passwd, circuit->snd_stream))
2519 return ISIS_WARNING;
2520 break;
2521
2522 /* HMAC MD5 */
2523 case ISIS_PASSWD_TYPE_HMAC_MD5:
2524 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2525 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2526 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2527 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2528 hmac_md5_hash, circuit->snd_stream))
2529 return ISIS_WARNING;
2530 break;
2531
2532 default:
2533 break;
hassof390d2c2004-09-10 20:48:21 +00002534 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002535 }
2536
2537 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2538 if (retval != ISIS_OK)
2539 return retval;
2540
paul9985f832005-02-09 15:51:56 +00002541 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002542 /* Update PU length */
2543 stream_putw_at (circuit->snd_stream, lenp, length);
2544
Josh Bailey3f045a02012-03-24 08:35:20 -07002545 /* For HMAC MD5 we need to compute the md5 hash and store it */
2546 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2547 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2548 {
2549 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2550 stream_get_endp(circuit->snd_stream),
2551 (unsigned char *) &passwd->passwd, passwd->len,
2552 (caddr_t) &hmac_md5_hash);
2553 /* Copy the hash into the stream */
2554 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2555 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2556 }
2557
jardineb5d44e2003-12-23 08:09:43 +00002558 return retval;
2559}
2560
2561/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002562 * Count the maximum number of lsps that can be accomodated by a given size.
2563 */
2564static uint16_t
2565get_max_lsp_count (uint16_t size)
2566{
2567 uint16_t tlv_count;
2568 uint16_t lsp_count;
2569 uint16_t remaining_size;
2570
2571 /* First count the full size TLVs */
2572 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2573 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2574
2575 /* The last TLV, if any */
2576 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2577 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2578 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2579
2580 return lsp_count;
2581}
2582
2583/*
2584 * Calculate the length of Authentication Info. TLV.
2585 */
2586static uint16_t
2587auth_tlv_length (int level, struct isis_circuit *circuit)
2588{
2589 struct isis_passwd *passwd;
2590 uint16_t length;
2591
2592 if (level == IS_LEVEL_1)
2593 passwd = &circuit->area->area_passwd;
2594 else
2595 passwd = &circuit->area->domain_passwd;
2596
2597 /* Also include the length of TLV header */
2598 length = AUTH_INFO_HDRLEN;
2599 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2600 {
2601 switch (passwd->type)
2602 {
2603 /* Cleartext */
2604 case ISIS_PASSWD_TYPE_CLEARTXT:
2605 length += passwd->len;
2606 break;
2607
2608 /* HMAC MD5 */
2609 case ISIS_PASSWD_TYPE_HMAC_MD5:
2610 length += ISIS_AUTH_MD5_SIZE;
2611 break;
2612
2613 default:
2614 break;
2615 }
2616 }
2617
2618 return length;
2619}
2620
2621/*
2622 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2623 */
2624static uint16_t
2625max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2626{
2627 int snp_hdr_len;
2628 int auth_tlv_len;
2629 uint16_t lsp_count;
2630
2631 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2632 if (snp_type == ISIS_SNP_CSNP_FLAG)
2633 snp_hdr_len += ISIS_CSNP_HDRLEN;
2634 else
2635 snp_hdr_len += ISIS_PSNP_HDRLEN;
2636
2637 auth_tlv_len = auth_tlv_length (level, circuit);
2638 lsp_count = get_max_lsp_count (
2639 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002640 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002641}
2642
2643/*
jardineb5d44e2003-12-23 08:09:43 +00002644 * FIXME: support multiple CSNPs
2645 */
2646
2647int
2648send_csnp (struct isis_circuit *circuit, int level)
2649{
jardineb5d44e2003-12-23 08:09:43 +00002650 u_char start[ISIS_SYS_ID_LEN + 2];
2651 u_char stop[ISIS_SYS_ID_LEN + 2];
2652 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002653 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002654 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002655 u_char num_lsps, loop = 1;
2656 int i, retval = ISIS_OK;
2657
2658 if (circuit->area->lspdb[level - 1] == NULL ||
2659 dict_count (circuit->area->lspdb[level - 1]) == 0)
2660 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002661
hassof390d2c2004-09-10 20:48:21 +00002662 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002663 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2664
Josh Bailey3f045a02012-03-24 08:35:20 -07002665 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2666
2667 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002668 {
2669 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002670 lsp_build_list (start, stop, num_lsps, list,
2671 circuit->area->lspdb[level - 1]);
2672 /*
2673 * Update the stop lsp_id before encoding this CSNP.
2674 */
2675 if (listcount (list) < num_lsps)
2676 {
2677 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2678 }
hassof390d2c2004-09-10 20:48:21 +00002679 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002680 {
2681 node = listtail (list);
2682 lsp = listgetdata (node);
2683 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2684 }
jardineb5d44e2003-12-23 08:09:43 +00002685
hassof390d2c2004-09-10 20:48:21 +00002686 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002687 if (retval != ISIS_OK)
2688 {
2689 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2690 circuit->area->area_tag, level, circuit->interface->name);
2691 list_delete (list);
2692 return retval;
2693 }
jardineb5d44e2003-12-23 08:09:43 +00002694
hassof390d2c2004-09-10 20:48:21 +00002695 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002696 {
2697 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2698 circuit->area->area_tag, level, circuit->interface->name,
2699 stream_get_endp (circuit->snd_stream));
2700 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2701 {
2702 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2703 " cksum 0x%04x, lifetime %us",
2704 circuit->area->area_tag,
2705 rawlspid_print (lsp->lsp_header->lsp_id),
2706 ntohl (lsp->lsp_header->seq_num),
2707 ntohs (lsp->lsp_header->checksum),
2708 ntohs (lsp->lsp_header->rem_lifetime));
2709 }
2710 if (isis->debugs & DEBUG_PACKET_DUMP)
2711 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2712 stream_get_endp (circuit->snd_stream));
2713 }
hassof390d2c2004-09-10 20:48:21 +00002714
Josh Bailey3f045a02012-03-24 08:35:20 -07002715 retval = circuit->tx (circuit, level);
2716 if (retval != ISIS_OK)
2717 {
2718 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2719 circuit->area->area_tag, level,
2720 circuit->interface->name);
2721 list_delete (list);
2722 return retval;
2723 }
2724
2725 /*
2726 * Start lsp_id of the next CSNP should be one plus the
2727 * stop lsp_id in this current CSNP.
2728 */
2729 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2730 loop = 0;
2731 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2732 {
2733 if (start[i] < (u_char)0xff)
2734 {
2735 start[i] += 1;
2736 loop = 1;
2737 break;
2738 }
2739 }
2740 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002741 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002742 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002743
jardineb5d44e2003-12-23 08:09:43 +00002744 return retval;
2745}
2746
2747int
2748send_l1_csnp (struct thread *thread)
2749{
2750 struct isis_circuit *circuit;
2751 int retval = ISIS_OK;
2752
2753 circuit = THREAD_ARG (thread);
2754 assert (circuit);
2755
2756 circuit->t_send_csnp[0] = NULL;
2757
hassof390d2c2004-09-10 20:48:21 +00002758 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2759 {
2760 send_csnp (circuit, 1);
2761 }
jardineb5d44e2003-12-23 08:09:43 +00002762 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002763 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2764 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002765
2766 return retval;
2767}
2768
2769int
2770send_l2_csnp (struct thread *thread)
2771{
2772 struct isis_circuit *circuit;
2773 int retval = ISIS_OK;
2774
2775 circuit = THREAD_ARG (thread);
2776 assert (circuit);
2777
2778 circuit->t_send_csnp[1] = NULL;
2779
hassof390d2c2004-09-10 20:48:21 +00002780 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2781 {
2782 send_csnp (circuit, 2);
2783 }
jardineb5d44e2003-12-23 08:09:43 +00002784 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002785 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2786 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002787
jardineb5d44e2003-12-23 08:09:43 +00002788 return retval;
2789}
2790
hasso92365882005-01-18 13:53:33 +00002791static int
jardineb5d44e2003-12-23 08:09:43 +00002792build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2793{
2794 struct isis_fixed_hdr fixed_hdr;
2795 unsigned long lenp;
2796 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002797 struct isis_lsp *lsp;
2798 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002799 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002800 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2801 unsigned long auth_tlv_offset = 0;
2802 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002803
Josh Bailey3f045a02012-03-24 08:35:20 -07002804 if (circuit->snd_stream == NULL)
2805 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2806 else
2807 stream_reset (circuit->snd_stream);
2808
2809 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002810 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2811 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002812 else
2813 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002814 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002815
2816 /*
2817 * Fill Level 1 or 2 Partial Sequence Numbers header
2818 */
paul9985f832005-02-09 15:51:56 +00002819 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002820 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002821 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2822 stream_putc (circuit->snd_stream, circuit->idx);
2823
2824 /*
2825 * And TLVs
2826 */
2827
Josh Bailey3f045a02012-03-24 08:35:20 -07002828 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002829 passwd = &circuit->area->area_passwd;
2830 else
2831 passwd = &circuit->area->domain_passwd;
2832
hasso1cbc5622005-01-01 10:29:51 +00002833 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002834 {
2835 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002836 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002837 /* Cleartext */
2838 case ISIS_PASSWD_TYPE_CLEARTXT:
2839 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2840 passwd->passwd, circuit->snd_stream))
2841 return ISIS_WARNING;
2842 break;
2843
2844 /* HMAC MD5 */
2845 case ISIS_PASSWD_TYPE_HMAC_MD5:
2846 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2847 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2848 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2849 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2850 hmac_md5_hash, circuit->snd_stream))
2851 return ISIS_WARNING;
2852 break;
2853
2854 default:
2855 break;
jardineb5d44e2003-12-23 08:09:43 +00002856 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002857 }
2858
2859 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2860 if (retval != ISIS_OK)
2861 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002862
hassof390d2c2004-09-10 20:48:21 +00002863 if (isis->debugs & DEBUG_SNP_PACKETS)
2864 {
hasso3fdb2dd2005-09-28 18:45:54 +00002865 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002866 {
hasso529d65b2004-12-24 00:14:50 +00002867 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2868 " cksum 0x%04x, lifetime %us",
2869 circuit->area->area_tag,
2870 rawlspid_print (lsp->lsp_header->lsp_id),
2871 ntohl (lsp->lsp_header->seq_num),
2872 ntohs (lsp->lsp_header->checksum),
2873 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002874 }
2875 }
2876
paul9985f832005-02-09 15:51:56 +00002877 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002878 /* Update PDU length */
2879 stream_putw_at (circuit->snd_stream, lenp, length);
2880
Josh Bailey3f045a02012-03-24 08:35:20 -07002881 /* For HMAC MD5 we need to compute the md5 hash and store it */
2882 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2883 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2884 {
2885 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2886 stream_get_endp(circuit->snd_stream),
2887 (unsigned char *) &passwd->passwd, passwd->len,
2888 (caddr_t) &hmac_md5_hash);
2889 /* Copy the hash into the stream */
2890 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2891 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2892 }
2893
jardineb5d44e2003-12-23 08:09:43 +00002894 return ISIS_OK;
2895}
2896
2897/*
2898 * 7.3.15.4 action on expiration of partial SNP interval
2899 * level 1
2900 */
hasso92365882005-01-18 13:53:33 +00002901static int
jardineb5d44e2003-12-23 08:09:43 +00002902send_psnp (int level, struct isis_circuit *circuit)
2903{
jardineb5d44e2003-12-23 08:09:43 +00002904 struct isis_lsp *lsp;
2905 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002906 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002907 u_char num_lsps;
2908 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002909
Josh Bailey3f045a02012-03-24 08:35:20 -07002910 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2911 circuit->u.bc.is_dr[level - 1])
2912 return ISIS_OK;
2913
2914 if (circuit->area->lspdb[level - 1] == NULL ||
2915 dict_count (circuit->area->lspdb[level - 1]) == 0)
2916 return ISIS_OK;
2917
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002918 if (! circuit->snd_stream)
2919 return ISIS_ERROR;
2920
Josh Bailey3f045a02012-03-24 08:35:20 -07002921 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2922
2923 while (1)
hassof390d2c2004-09-10 20:48:21 +00002924 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002925 list = list_new ();
2926 lsp_build_list_ssn (circuit, num_lsps, list,
2927 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002928
Josh Bailey3f045a02012-03-24 08:35:20 -07002929 if (listcount (list) == 0)
2930 {
2931 list_delete (list);
2932 return ISIS_OK;
2933 }
jardineb5d44e2003-12-23 08:09:43 +00002934
Josh Bailey3f045a02012-03-24 08:35:20 -07002935 retval = build_psnp (level, circuit, list);
2936 if (retval != ISIS_OK)
2937 {
2938 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2939 circuit->area->area_tag, level, circuit->interface->name);
2940 list_delete (list);
2941 return retval;
2942 }
jardineb5d44e2003-12-23 08:09:43 +00002943
Josh Bailey3f045a02012-03-24 08:35:20 -07002944 if (isis->debugs & DEBUG_SNP_PACKETS)
2945 {
2946 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2947 circuit->area->area_tag, level,
2948 circuit->interface->name,
2949 stream_get_endp (circuit->snd_stream));
2950 if (isis->debugs & DEBUG_PACKET_DUMP)
2951 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2952 stream_get_endp (circuit->snd_stream));
2953 }
jardineb5d44e2003-12-23 08:09:43 +00002954
Josh Bailey3f045a02012-03-24 08:35:20 -07002955 retval = circuit->tx (circuit, level);
2956 if (retval != ISIS_OK)
2957 {
2958 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2959 circuit->area->area_tag, level,
2960 circuit->interface->name);
2961 list_delete (list);
2962 return retval;
2963 }
jardineb5d44e2003-12-23 08:09:43 +00002964
Josh Bailey3f045a02012-03-24 08:35:20 -07002965 /*
2966 * sending succeeded, we can clear SSN flags of this circuit
2967 * for the LSPs in list
2968 */
2969 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2970 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2971 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002972 }
jardineb5d44e2003-12-23 08:09:43 +00002973
2974 return retval;
2975}
2976
2977int
2978send_l1_psnp (struct thread *thread)
2979{
2980
2981 struct isis_circuit *circuit;
2982 int retval = ISIS_OK;
2983
2984 circuit = THREAD_ARG (thread);
2985 assert (circuit);
2986
2987 circuit->t_send_psnp[0] = NULL;
2988
2989 send_psnp (1, circuit);
2990 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002991 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2992 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002993
2994 return retval;
2995}
2996
2997/*
2998 * 7.3.15.4 action on expiration of partial SNP interval
2999 * level 2
3000 */
3001int
3002send_l2_psnp (struct thread *thread)
3003{
jardineb5d44e2003-12-23 08:09:43 +00003004 struct isis_circuit *circuit;
3005 int retval = ISIS_OK;
3006
3007 circuit = THREAD_ARG (thread);
3008 assert (circuit);
3009
3010 circuit->t_send_psnp[1] = NULL;
3011
3012 send_psnp (2, circuit);
3013
3014 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003015 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3016 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003017
3018 return retval;
3019}
3020
jardineb5d44e2003-12-23 08:09:43 +00003021/*
3022 * ISO 10589 - 7.3.14.3
3023 */
3024int
3025send_lsp (struct thread *thread)
3026{
3027 struct isis_circuit *circuit;
3028 struct isis_lsp *lsp;
3029 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003030 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003031
3032 circuit = THREAD_ARG (thread);
3033 assert (circuit);
3034
Josh Bailey3f045a02012-03-24 08:35:20 -07003035 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3036 {
3037 return retval;
3038 }
3039
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003040 node = listhead (circuit->lsp_queue);
3041
3042 /*
3043 * Handle case where there are no LSPs on the queue. This can
3044 * happen, for instance, if an adjacency goes down before this
3045 * thread gets a chance to run.
3046 */
3047 if (!node)
3048 {
3049 return retval;
3050 }
3051
3052 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003053
3054 /*
3055 * Do not send if levels do not match
3056 */
3057 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003058 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003059 list_delete_node (circuit->lsp_queue, node);
3060 return retval;
hassof390d2c2004-09-10 20:48:21 +00003061 }
jardineb5d44e2003-12-23 08:09:43 +00003062
Josh Bailey3f045a02012-03-24 08:35:20 -07003063 /*
3064 * Do not send if we do not have adjacencies in state up on the circuit
3065 */
3066 if (circuit->upadjcount[lsp->level - 1] == 0)
3067 {
3068 list_delete_node (circuit->lsp_queue, node);
3069 return retval;
3070 }
3071
3072 /* copy our lsp to the send buffer */
3073 stream_copy (circuit->snd_stream, lsp->pdu);
3074
3075 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3076 {
3077 zlog_debug
3078 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3079 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3080 rawlspid_print (lsp->lsp_header->lsp_id),
3081 ntohl (lsp->lsp_header->seq_num),
3082 ntohs (lsp->lsp_header->checksum),
3083 ntohs (lsp->lsp_header->rem_lifetime),
3084 circuit->interface->name);
3085 if (isis->debugs & DEBUG_PACKET_DUMP)
3086 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3087 stream_get_endp (circuit->snd_stream));
3088 }
3089
3090 retval = circuit->tx (circuit, lsp->level);
3091 if (retval != ISIS_OK)
3092 {
3093 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3094 circuit->area->area_tag, lsp->level,
3095 circuit->interface->name);
3096 return retval;
3097 }
3098
3099 /*
3100 * If the sending succeeded, we can del the lsp from circuits
3101 * lsp_queue
3102 */
3103 list_delete_node (circuit->lsp_queue, node);
3104
3105 /* Set the last-cleared time if the queue is empty. */
3106 /* TODO: Is is possible that new lsps keep being added to the queue
3107 * that the queue is never empty? */
3108 if (list_isempty (circuit->lsp_queue))
3109 circuit->lsp_queue_last_cleared = time (NULL);
3110
3111 /*
3112 * On broadcast circuits also the SRMflag can be cleared
3113 */
3114 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3115 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3116
jardineb5d44e2003-12-23 08:09:43 +00003117 return retval;
hassof390d2c2004-09-10 20:48:21 +00003118}
jardineb5d44e2003-12-23 08:09:43 +00003119
3120int
hassof390d2c2004-09-10 20:48:21 +00003121ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3122 int level)
jardineb5d44e2003-12-23 08:09:43 +00003123{
3124 unsigned long lenp;
3125 int retval;
3126 u_int16_t length;
3127 struct isis_fixed_hdr fixed_hdr;
3128
3129 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003130 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003131 else
3132 stream_reset (circuit->snd_stream);
3133
Josh Bailey3f045a02012-03-24 08:35:20 -07003134 // fill_llc_hdr (stream);
3135 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003136 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3137 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003138 else
hassof390d2c2004-09-10 20:48:21 +00003139 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3140 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003141
3142
paul9985f832005-02-09 15:51:56 +00003143 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003144 stream_putw (circuit->snd_stream, 0); /* PDU length */
3145 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003146 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003147 stream_putc (circuit->snd_stream, 9); /* code */
3148 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003149
hassof390d2c2004-09-10 20:48:21 +00003150 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3151 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3152 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3153 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003154
paul9985f832005-02-09 15:51:56 +00003155 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003156 /* Update PDU length */
3157 stream_putw_at (circuit->snd_stream, lenp, length);
3158
3159 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003160 if (retval != ISIS_OK)
3161 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3162 circuit->area->area_tag, level,
3163 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003164
3165 return retval;
3166}