blob: 497fad20fd215fa84134e62382f9499aefa4388a [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
314static void
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;
jardineb5d44e2003-12-23 08:09:43 +0000324
hassof390d2c2004-09-10 20:48:21 +0000325 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000326
hassof390d2c2004-09-10 20:48:21 +0000327 for (i = 0; i < tlv_nlpids->count; i++)
328 {
329 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
330 }
jardineb5d44e2003-12-23 08:09:43 +0000331 }
jardineb5d44e2003-12-23 08:09:43 +0000332}
333
hasso92365882005-01-18 13:53:33 +0000334static void
hassof390d2c2004-09-10 20:48:21 +0000335tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000336{
hasso3fdb2dd2005-09-28 18:45:54 +0000337 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000338 struct in_addr *ipv4_addr, *malloced;
339
hassof390d2c2004-09-10 20:48:21 +0000340 if (adj->ipv4_addrs)
341 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700342 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000343 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000344 }
hassof390d2c2004-09-10 20:48:21 +0000345 adj->ipv4_addrs = list_new ();
346 if (tlvs->ipv4_addrs)
347 {
hasso3fdb2dd2005-09-28 18:45:54 +0000348 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000349 {
350 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
351 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
352 listnode_add (adj->ipv4_addrs, malloced);
353 }
354 }
jardineb5d44e2003-12-23 08:09:43 +0000355}
356
357#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000358static void
hassof390d2c2004-09-10 20:48:21 +0000359tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000360{
hasso3fdb2dd2005-09-28 18:45:54 +0000361 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000362 struct in6_addr *ipv6_addr, *malloced;
363
hassof390d2c2004-09-10 20:48:21 +0000364 if (adj->ipv6_addrs)
365 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700366 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000367 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000368 }
hassof390d2c2004-09-10 20:48:21 +0000369 adj->ipv6_addrs = list_new ();
370 if (tlvs->ipv6_addrs)
371 {
hasso3fdb2dd2005-09-28 18:45:54 +0000372 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000373 {
374 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
375 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
376 listnode_add (adj->ipv6_addrs, malloced);
377 }
378 }
jardineb5d44e2003-12-23 08:09:43 +0000379
380}
381#endif /* HAVE_IPV6 */
382
jardineb5d44e2003-12-23 08:09:43 +0000383/*
384 * RECEIVE SIDE
385 */
386
387/*
388 * Process P2P IIH
389 * ISO - 10589
390 * Section 8.2.5 - Receiving point-to-point IIH PDUs
391 *
392 */
393static int
394process_p2p_hello (struct isis_circuit *circuit)
395{
396 int retval = ISIS_OK;
397 struct isis_p2p_hello_hdr *hdr;
398 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700399 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700400 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000401 struct tlvs tlvs;
402
Josh Bailey3f045a02012-03-24 08:35:20 -0700403 if (isis->debugs & DEBUG_ADJ_PACKETS)
404 {
405 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
406 circuit->area->area_tag, circuit->interface->name,
407 circuit_t2string (circuit->is_type), circuit->circuit_id);
408 if (isis->debugs & DEBUG_PACKET_DUMP)
409 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
410 stream_get_endp (circuit->rcv_stream));
411 }
412
413 if (circuit->circ_type != CIRCUIT_T_P2P)
414 {
415 zlog_warn ("p2p hello on non p2p circuit");
416 return ISIS_WARNING;
417 }
418
hassof390d2c2004-09-10 20:48:21 +0000419 if ((stream_get_endp (circuit->rcv_stream) -
420 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
421 {
422 zlog_warn ("Packet too short");
423 return ISIS_WARNING;
424 }
jardineb5d44e2003-12-23 08:09:43 +0000425
426 /* 8.2.5.1 PDU acceptance tests */
427
428 /* 8.2.5.1 a) external domain untrue */
429 /* FIXME: not useful at all? */
430
431 /* 8.2.5.1 b) ID Length mismatch */
432 /* checked at the handle_pdu */
433
434 /* 8.2.5.2 IIH PDU Processing */
435
436 /* 8.2.5.2 a) 1) Maximum Area Addresses */
437 /* Already checked, and can also be ommited */
438
439 /*
440 * Get the header
441 */
hassof390d2c2004-09-10 20:48:21 +0000442 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700443 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000444
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700445 if (pdu_len > ISO_MTU(circuit) ||
446 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000447 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700448 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
449 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700450 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700451 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000452 }
jardineb5d44e2003-12-23 08:09:43 +0000453
jardineb5d44e2003-12-23 08:09:43 +0000454 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700455 * Set the stream endp to PDU length, ignoring additional padding
456 * introduced by transport chips.
457 */
458 if (pdu_len < stream_get_endp (circuit->rcv_stream))
459 stream_set_endp (circuit->rcv_stream, pdu_len);
460
461 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
462
463 /*
jardineb5d44e2003-12-23 08:09:43 +0000464 * Lets get the TLVS now
465 */
466 expected |= TLVFLAG_AREA_ADDRS;
467 expected |= TLVFLAG_AUTH_INFO;
468 expected |= TLVFLAG_NLPID;
469 expected |= TLVFLAG_IPV4_ADDR;
470 expected |= TLVFLAG_IPV6_ADDR;
471
Josh Bailey3f045a02012-03-24 08:35:20 -0700472 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000473 retval = parse_tlvs (circuit->area->area_tag,
474 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700475 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
476 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000477
hassof390d2c2004-09-10 20:48:21 +0000478 if (retval > ISIS_WARNING)
479 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700480 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000481 free_tlvs (&tlvs);
482 return retval;
483 };
jardineb5d44e2003-12-23 08:09:43 +0000484
Josh Bailey3f045a02012-03-24 08:35:20 -0700485 if (!(found & TLVFLAG_AREA_ADDRS))
486 {
487 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
488 free_tlvs (&tlvs);
489 return ISIS_WARNING;
490 }
491
jardineb5d44e2003-12-23 08:09:43 +0000492 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000493 if (circuit->passwd.type)
494 {
495 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700496 authentication_check (&tlvs.auth_info, &circuit->passwd,
497 circuit->rcv_stream, auth_tlv_offset))
498 {
499 isis_event_auth_failure (circuit->area->area_tag,
500 "P2P hello authentication failure",
501 hdr->source_id);
502 free_tlvs (&tlvs);
503 return ISIS_OK;
504 }
jardineb5d44e2003-12-23 08:09:43 +0000505 }
jardineb5d44e2003-12-23 08:09:43 +0000506
Josh Bailey3f045a02012-03-24 08:35:20 -0700507 /*
508 * check if it's own interface ip match iih ip addrs
509 */
510 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
511 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
512 {
513 zlog_warn ("ISIS-Adj: No usable IP interface addresses "
514 "in LAN IIH from %s\n", circuit->interface->name);
515 free_tlvs (&tlvs);
516 return ISIS_WARNING;
517 }
518
519 /*
520 * My interpertation of the ISO, if no adj exists we will create one for
521 * the circuit
522 */
523 adj = circuit->u.p2p.neighbor;
524 if (!adj || adj->level != hdr->circuit_t)
525 {
526 if (!adj)
527 {
528 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
529 if (adj == NULL)
530 return ISIS_ERROR;
531 }
532 else
533 {
534 adj->level = hdr->circuit_t;
535 }
536 circuit->u.p2p.neighbor = adj;
537 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
538 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
539 }
540
541 /* 8.2.6 Monitoring point-to-point adjacencies */
542 adj->hold_time = ntohs (hdr->hold_time);
543 adj->last_upd = time (NULL);
544
jardineb5d44e2003-12-23 08:09:43 +0000545 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700546 tlvs_to_adj_area_addrs (&tlvs, adj);
547
548 /* which protocol are spoken ??? */
549 if (found & TLVFLAG_NLPID)
550 tlvs_to_adj_nlpids (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000551
552 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700553 if (found & TLVFLAG_IPV4_ADDR)
554 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000555
556#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700557 if (found & TLVFLAG_IPV6_ADDR)
558 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000559#endif /* HAVE_IPV6 */
560
561 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000562 THREAD_TIMER_OFF (adj->t_expire);
563 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
564 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000565
566 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000567 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
568 {
569 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
570 if (circuit->area->is_type == IS_LEVEL_1)
571 {
572 switch (hdr->circuit_t)
573 {
574 case IS_LEVEL_1:
575 case IS_LEVEL_1_AND_2:
576 if (adj->adj_state != ISIS_ADJ_UP)
577 {
578 /* (4) adj state up */
579 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
580 /* (5) adj usage level 1 */
581 adj->adj_usage = ISIS_ADJ_LEVEL1;
582 }
583 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
584 {
585 ; /* accept */
586 }
587 break;
588 case IS_LEVEL_2:
589 if (adj->adj_state != ISIS_ADJ_UP)
590 {
591 /* (7) reject - wrong system type event */
592 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700593 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000594 return ISIS_WARNING; /* Reject */
595 }
596 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
597 {
598 /* (6) down - wrong system */
599 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
600 }
601 break;
602 }
603 }
jardineb5d44e2003-12-23 08:09:43 +0000604
hassof390d2c2004-09-10 20:48:21 +0000605 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
606 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
607 {
608 switch (hdr->circuit_t)
609 {
610 case IS_LEVEL_1:
611 if (adj->adj_state != ISIS_ADJ_UP)
612 {
613 /* (6) adj state up */
614 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
615 /* (7) adj usage level 1 */
616 adj->adj_usage = ISIS_ADJ_LEVEL1;
617 }
618 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
619 {
620 ; /* accept */
621 }
622 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
623 (adj->adj_usage == ISIS_ADJ_LEVEL2))
624 {
625 /* (8) down - wrong system */
626 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
627 }
628 break;
629 case IS_LEVEL_2:
630 if (adj->adj_state != ISIS_ADJ_UP)
631 {
632 /* (6) adj state up */
633 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
634 /* (9) adj usage level 2 */
635 adj->adj_usage = ISIS_ADJ_LEVEL2;
636 }
637 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
638 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
639 {
640 /* (8) down - wrong system */
641 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
642 }
643 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
644 {
645 ; /* Accept */
646 }
647 break;
648 case IS_LEVEL_1_AND_2:
649 if (adj->adj_state != ISIS_ADJ_UP)
650 {
651 /* (6) adj state up */
652 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
653 /* (10) adj usage level 1 */
654 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
655 }
656 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
657 (adj->adj_usage == ISIS_ADJ_LEVEL2))
658 {
659 /* (8) down - wrong system */
660 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
661 }
662 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
663 {
664 ; /* Accept */
665 }
666 break;
667 }
668 }
jardineb5d44e2003-12-23 08:09:43 +0000669
hassof390d2c2004-09-10 20:48:21 +0000670 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
671 if (circuit->area->is_type == IS_LEVEL_2)
672 {
673 switch (hdr->circuit_t)
674 {
675 case IS_LEVEL_1:
676 if (adj->adj_state != ISIS_ADJ_UP)
677 {
678 /* (5) reject - wrong system type event */
679 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700680 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000681 return ISIS_WARNING; /* Reject */
682 }
683 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
684 (adj->adj_usage == ISIS_ADJ_LEVEL2))
685 {
686 /* (6) down - wrong system */
687 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
688 }
689 break;
690 case IS_LEVEL_1_AND_2:
691 case IS_LEVEL_2:
692 if (adj->adj_state != ISIS_ADJ_UP)
693 {
694 /* (7) adj state up */
695 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
696 /* (8) adj usage level 2 */
697 adj->adj_usage = ISIS_ADJ_LEVEL2;
698 }
699 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
700 {
701 /* (6) down - wrong system */
702 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
703 }
704 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
705 {
706 ; /* Accept */
707 }
708 break;
709 }
710 }
jardineb5d44e2003-12-23 08:09:43 +0000711 }
jardineb5d44e2003-12-23 08:09:43 +0000712 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700713 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000714 {
hassof390d2c2004-09-10 20:48:21 +0000715 if (circuit->area->is_type == IS_LEVEL_1)
716 {
717 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
718 if (adj->adj_state != ISIS_ADJ_UP)
719 {
720 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
721 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
722 }
723 else
724 {
725 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
726 "Down - Area Mismatch");
727 }
728 }
729 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
730 else
731 {
732 switch (hdr->circuit_t)
733 {
734 case IS_LEVEL_1:
735 if (adj->adj_state != ISIS_ADJ_UP)
736 {
737 /* (6) reject - Area Mismatch event */
738 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700739 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000740 return ISIS_WARNING; /* Reject */
741 }
742 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
743 {
744 /* (7) down - area mismatch */
745 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000746
hassof390d2c2004-09-10 20:48:21 +0000747 }
748 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
749 (adj->adj_usage == ISIS_ADJ_LEVEL2))
750 {
751 /* (7) down - wrong system */
752 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
753 }
754 break;
755 case IS_LEVEL_1_AND_2:
756 case IS_LEVEL_2:
757 if (adj->adj_state != ISIS_ADJ_UP)
758 {
759 /* (8) adj state up */
760 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
761 /* (9) adj usage level 2 */
762 adj->adj_usage = ISIS_ADJ_LEVEL2;
763 }
764 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
765 {
766 /* (7) down - wrong system */
767 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
768 }
769 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
770 {
771 if (hdr->circuit_t == IS_LEVEL_2)
772 {
773 /* (7) down - wrong system */
774 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
775 "Wrong System");
776 }
777 else
778 {
779 /* (7) down - area mismatch */
780 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
781 "Area Mismatch");
782 }
783 }
784 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
785 {
786 ; /* Accept */
787 }
788 break;
789 }
790 }
jardineb5d44e2003-12-23 08:09:43 +0000791 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700792 else
793 {
794 /* down - area mismatch */
795 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
796 }
jardineb5d44e2003-12-23 08:09:43 +0000797 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
798 /* FIXME - Missing parts */
799
jardineb5d44e2003-12-23 08:09:43 +0000800 /* some of my own understanding of the ISO, why the heck does
801 * it not say what should I change the system_type to...
802 */
hassof390d2c2004-09-10 20:48:21 +0000803 switch (adj->adj_usage)
804 {
jardineb5d44e2003-12-23 08:09:43 +0000805 case ISIS_ADJ_LEVEL1:
806 adj->sys_type = ISIS_SYSTYPE_L1_IS;
807 break;
808 case ISIS_ADJ_LEVEL2:
809 adj->sys_type = ISIS_SYSTYPE_L2_IS;
810 break;
811 case ISIS_ADJ_LEVEL1AND2:
812 adj->sys_type = ISIS_SYSTYPE_L2_IS;
813 break;
814 case ISIS_ADJ_NONE:
815 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
816 break;
hassof390d2c2004-09-10 20:48:21 +0000817 }
jardineb5d44e2003-12-23 08:09:43 +0000818
819 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700820
821 if (isis->debugs & DEBUG_ADJ_PACKETS)
822 {
823 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
824 " cir id %02d, length %d",
825 circuit->area->area_tag, circuit->interface->name,
826 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700827 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700828 }
jardineb5d44e2003-12-23 08:09:43 +0000829
830 free_tlvs (&tlvs);
831
832 return retval;
833}
834
jardineb5d44e2003-12-23 08:09:43 +0000835/*
836 * Process IS-IS LAN Level 1/2 Hello PDU
837 */
hassof390d2c2004-09-10 20:48:21 +0000838static int
839process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000840{
841 int retval = ISIS_OK;
842 struct isis_lan_hello_hdr hdr;
843 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700844 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000845 struct tlvs tlvs;
846 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000847 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000848
Josh Bailey3f045a02012-03-24 08:35:20 -0700849 if (isis->debugs & DEBUG_ADJ_PACKETS)
850 {
851 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
852 "cirID %u",
853 circuit->area->area_tag, level, circuit->interface->name,
854 circuit_t2string (circuit->is_type), circuit->circuit_id);
855 if (isis->debugs & DEBUG_PACKET_DUMP)
856 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
857 stream_get_endp (circuit->rcv_stream));
858 }
859
860 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
861 {
862 zlog_warn ("lan hello on non broadcast circuit");
863 return ISIS_WARNING;
864 }
865
hassof390d2c2004-09-10 20:48:21 +0000866 if ((stream_get_endp (circuit->rcv_stream) -
867 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
868 {
869 zlog_warn ("Packet too short");
870 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000871 }
hassof390d2c2004-09-10 20:48:21 +0000872
873 if (circuit->ext_domain)
874 {
hasso529d65b2004-12-24 00:14:50 +0000875 zlog_debug ("level %d LAN Hello received over circuit with "
876 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000877 return ISIS_WARNING;
878 }
879
Josh Bailey3f045a02012-03-24 08:35:20 -0700880 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000881 {
882 if (isis->debugs & DEBUG_ADJ_PACKETS)
883 {
hasso529d65b2004-12-24 00:14:50 +0000884 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
885 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000886 }
887 return ISIS_WARNING;
888 }
jardineb5d44e2003-12-23 08:09:43 +0000889
890#if 0
891 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000892 if (!accept_level (level, circuit->area->is_type))
893 {
894 if (isis->debugs & DEBUG_ADJ_PACKETS)
895 {
hasso529d65b2004-12-24 00:14:50 +0000896 zlog_debug ("ISIS-Adj (%s): is type mismatch",
897 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000898 }
899 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000900 }
jardineb5d44e2003-12-23 08:09:43 +0000901#endif
902 /*
903 * Fill the header
904 */
905 hdr.circuit_t = stream_getc (circuit->rcv_stream);
906 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
907 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000908 hdr.pdu_len = stream_getw (circuit->rcv_stream);
909 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000910 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
911
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700912 if (hdr.pdu_len > ISO_MTU(circuit) ||
913 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000914 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700915 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
916 "invalid pdu length %d",
917 circuit->area->area_tag, circuit->interface->name,
918 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700919 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700920 }
921
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700922 /*
923 * Set the stream endp to PDU length, ignoring additional padding
924 * introduced by transport chips.
925 */
926 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
927 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
928
Josh Bailey3f045a02012-03-24 08:35:20 -0700929 if (hdr.circuit_t != IS_LEVEL_1 &&
930 hdr.circuit_t != IS_LEVEL_2 &&
931 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
932 (level & hdr.circuit_t) == 0)
933 {
934 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
935 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000936 return ISIS_ERROR;
937 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700938
jardineb5d44e2003-12-23 08:09:43 +0000939 /*
940 * Then get the tlvs
941 */
942 expected |= TLVFLAG_AUTH_INFO;
943 expected |= TLVFLAG_AREA_ADDRS;
944 expected |= TLVFLAG_LAN_NEIGHS;
945 expected |= TLVFLAG_NLPID;
946 expected |= TLVFLAG_IPV4_ADDR;
947 expected |= TLVFLAG_IPV6_ADDR;
948
Josh Bailey3f045a02012-03-24 08:35:20 -0700949 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000950 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -0700951 STREAM_PNT (circuit->rcv_stream),
952 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
953 &expected, &found, &tlvs,
954 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000955
hassof390d2c2004-09-10 20:48:21 +0000956 if (retval > ISIS_WARNING)
957 {
958 zlog_warn ("parse_tlvs() failed");
959 goto out;
960 }
jardineb5d44e2003-12-23 08:09:43 +0000961
hassof390d2c2004-09-10 20:48:21 +0000962 if (!(found & TLVFLAG_AREA_ADDRS))
963 {
964 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
965 level);
jardineb5d44e2003-12-23 08:09:43 +0000966 retval = ISIS_WARNING;
967 goto out;
968 }
hassof390d2c2004-09-10 20:48:21 +0000969
Josh Bailey3f045a02012-03-24 08:35:20 -0700970 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +0000971 if (circuit->passwd.type)
972 {
973 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700974 authentication_check (&tlvs.auth_info, &circuit->passwd,
975 circuit->rcv_stream, auth_tlv_offset))
976 {
977 isis_event_auth_failure (circuit->area->area_tag,
978 "LAN hello authentication failure",
979 hdr.source_id);
980 retval = ISIS_WARNING;
981 goto out;
982 }
hassof390d2c2004-09-10 20:48:21 +0000983 }
jardineb5d44e2003-12-23 08:09:43 +0000984
985 /*
986 * Accept the level 1 adjacency only if a match between local and
987 * remote area addresses is found
988 */
Josh Bailey3f045a02012-03-24 08:35:20 -0700989 if (listcount (circuit->area->area_addrs) == 0 ||
990 (level == IS_LEVEL_1 &&
991 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +0000992 {
993 if (isis->debugs & DEBUG_ADJ_PACKETS)
994 {
hasso529d65b2004-12-24 00:14:50 +0000995 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
996 circuit->area->area_tag, level,
997 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000998 }
999 retval = ISIS_OK;
1000 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001001 }
jardineb5d44e2003-12-23 08:09:43 +00001002
1003 /*
1004 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001005 */
1006 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1007 {
hasso529d65b2004-12-24 00:14:50 +00001008 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1009 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001010
hassof390d2c2004-09-10 20:48:21 +00001011 retval = ISIS_OK;
1012 goto out;
1013 }
jardineb5d44e2003-12-23 08:09:43 +00001014
1015 /*
1016 * check if it's own interface ip match iih ip addrs
1017 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001018 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
1019 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
hassof390d2c2004-09-10 20:48:21 +00001020 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001021 zlog_debug ("ISIS-Adj: No usable IP interface addresses "
1022 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001023 retval = ISIS_WARNING;
1024 goto out;
1025 }
jardineb5d44e2003-12-23 08:09:43 +00001026
1027 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001028 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1029 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001030 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001031 if (!adj)
1032 {
1033 /*
1034 * Do as in 8.4.2.5
1035 */
1036 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1037 if (adj == NULL)
1038 {
1039 retval = ISIS_ERROR;
1040 goto out;
1041 }
1042 }
1043 else
1044 {
1045 if (ssnpa) {
1046 memcpy (adj->snpa, ssnpa, 6);
1047 } else {
1048 memset (adj->snpa, ' ', 6);
1049 }
1050 adj->level = level;
1051 }
hassof390d2c2004-09-10 20:48:21 +00001052 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001053
Josh Bailey3f045a02012-03-24 08:35:20 -07001054 if (level == IS_LEVEL_1)
1055 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001056 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001057 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001058 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1059 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001060 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001061 }
jardineb5d44e2003-12-23 08:09:43 +00001062
hassoa211d652004-09-20 14:55:29 +00001063 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1064 switch (level)
1065 {
1066 case 1:
1067 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1068 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001069 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001070 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1071 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001072 }
1073 break;
1074 case 2:
1075 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1076 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001077 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001078 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1079 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001080 }
1081 break;
1082 }
jardineb5d44e2003-12-23 08:09:43 +00001083
1084 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001085 adj->last_upd = time (NULL);
1086 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001087
1088 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1089
Josh Bailey3f045a02012-03-24 08:35:20 -07001090 tlvs_to_adj_area_addrs (&tlvs, adj);
1091
jardineb5d44e2003-12-23 08:09:43 +00001092 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +00001093 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +00001094 tlvs_to_adj_nlpids (&tlvs, adj);
1095
1096 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001097 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001098 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1099
1100#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001101 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001102 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1103#endif /* HAVE_IPV6 */
1104
1105 adj->circuit_t = hdr.circuit_t;
1106
1107 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001108 THREAD_TIMER_OFF (adj->t_expire);
1109 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001110 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001111
1112 /*
1113 * If the snpa for this circuit is found from LAN Neighbours TLV
1114 * we have two-way communication -> adjacency can be put to state "up"
1115 */
1116
hassof390d2c2004-09-10 20:48:21 +00001117 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001118 {
1119 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001120 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001121 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1122 {
1123 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1124 {
1125 isis_adj_state_change (adj, ISIS_ADJ_UP,
1126 "own SNPA found in LAN Neighbours TLV");
1127 }
1128 }
jardineb5d44e2003-12-23 08:09:43 +00001129 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001130 else
1131 {
1132 int found = 0;
1133 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1134 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1135 {
1136 found = 1;
1137 break;
1138 }
1139 if (found == 0)
1140 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1141 "own SNPA not found in LAN Neighbours TLV");
1142 }
1143 }
1144 else if (adj->adj_state == ISIS_ADJ_UP)
1145 {
1146 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1147 "no LAN Neighbours TLV found");
1148 }
jardineb5d44e2003-12-23 08:09:43 +00001149
hassof390d2c2004-09-10 20:48:21 +00001150out:
hassof390d2c2004-09-10 20:48:21 +00001151 if (isis->debugs & DEBUG_ADJ_PACKETS)
1152 {
hasso529d65b2004-12-24 00:14:50 +00001153 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
1154 "cirID %u, length %ld",
1155 circuit->area->area_tag,
1156 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001157 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001158 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001159 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001160 }
jardineb5d44e2003-12-23 08:09:43 +00001161
1162 free_tlvs (&tlvs);
1163
1164 return retval;
1165}
1166
1167/*
1168 * Process Level 1/2 Link State
1169 * ISO - 10589
1170 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001171 */
1172static int
1173process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001174{
1175 struct isis_link_state_hdr *hdr;
1176 struct isis_adjacency *adj = NULL;
1177 struct isis_lsp *lsp, *lsp0 = NULL;
1178 int retval = ISIS_OK, comp = 0;
1179 u_char lspid[ISIS_SYS_ID_LEN + 2];
1180 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001181 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001182
Josh Bailey3f045a02012-03-24 08:35:20 -07001183 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1184 {
1185 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1186 circuit->area->area_tag, level, circuit->interface->name,
1187 circuit_t2string (circuit->is_type), circuit->circuit_id);
1188 if (isis->debugs & DEBUG_PACKET_DUMP)
1189 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1190 stream_get_endp (circuit->rcv_stream));
1191 }
1192
hassof390d2c2004-09-10 20:48:21 +00001193 if ((stream_get_endp (circuit->rcv_stream) -
1194 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1195 {
1196 zlog_warn ("Packet too short");
1197 return ISIS_WARNING;
1198 }
jardineb5d44e2003-12-23 08:09:43 +00001199
1200 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001201 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001202 pdu_len = ntohs (hdr->pdu_len);
1203
1204 /* lsp length check */
1205 if (pdu_len < ISIS_LSP_HDR_LEN ||
1206 pdu_len > ISO_MTU(circuit) ||
1207 pdu_len > stream_get_endp (circuit->rcv_stream))
1208 {
1209 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1210 circuit->area->area_tag,
1211 rawlspid_print (hdr->lsp_id), pdu_len);
1212
1213 return ISIS_WARNING;
1214 }
1215
1216 /*
1217 * Set the stream endp to PDU length, ignoring additional padding
1218 * introduced by transport chips.
1219 */
1220 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1221 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001222
hassof390d2c2004-09-10 20:48:21 +00001223 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1224 {
hasso529d65b2004-12-24 00:14:50 +00001225 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001226 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001227 circuit->area->area_tag,
1228 level,
1229 rawlspid_print (hdr->lsp_id),
1230 ntohl (hdr->seq_num),
1231 ntohs (hdr->checksum),
1232 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001233 pdu_len,
paul15935e92005-05-03 09:27:23 +00001234 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001235 }
jardineb5d44e2003-12-23 08:09:43 +00001236
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001237 /* lsp is_type check */
1238 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1239 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001240 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001241 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001242 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001243 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1244 /* continue as per RFC1122 Be liberal in what you accept, and
1245 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001246 }
jardineb5d44e2003-12-23 08:09:43 +00001247
1248 /* Checksum sanity check - FIXME: move to correct place */
1249 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001250 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001251 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001252 {
hasso529d65b2004-12-24 00:14:50 +00001253 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1254 circuit->area->area_tag,
1255 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001256
hassof390d2c2004-09-10 20:48:21 +00001257 return ISIS_WARNING;
1258 }
jardineb5d44e2003-12-23 08:09:43 +00001259
1260 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001261 if (circuit->ext_domain)
1262 {
hasso529d65b2004-12-24 00:14:50 +00001263 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001264 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1265 "externalDomain = true", circuit->area->area_tag,
1266 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001267
hassof390d2c2004-09-10 20:48:21 +00001268 return ISIS_WARNING;
1269 }
jardineb5d44e2003-12-23 08:09:43 +00001270
1271 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001272 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001273 {
hasso529d65b2004-12-24 00:14:50 +00001274 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1275 " type %s",
1276 circuit->area->area_tag,
1277 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001278 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001279
hassof390d2c2004-09-10 20:48:21 +00001280 return ISIS_WARNING;
1281 }
jardineb5d44e2003-12-23 08:09:43 +00001282
1283 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1284
1285 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1286
1287 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001288 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1289 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001290 if (passwd->type)
1291 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001292 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1293 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001294 {
1295 isis_event_auth_failure (circuit->area->area_tag,
1296 "LSP authentication failure", hdr->lsp_id);
1297 return ISIS_WARNING;
1298 }
jardineb5d44e2003-12-23 08:09:43 +00001299 }
jardineb5d44e2003-12-23 08:09:43 +00001300 /* Find the LSP in our database and compare it to this Link State header */
1301 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1302 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001303 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1304 hdr->checksum, hdr->rem_lifetime);
1305 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001306#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001307 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001308#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001309 ))
jardineb5d44e2003-12-23 08:09:43 +00001310 goto dontcheckadj;
1311
1312 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1313 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001314
hassof390d2c2004-09-10 20:48:21 +00001315 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1316 {
1317 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1318 if (!adj)
1319 {
hasso529d65b2004-12-24 00:14:50 +00001320 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1321 "lifetime %us on %s",
1322 circuit->area->area_tag,
1323 rawlspid_print (hdr->lsp_id),
1324 ntohl (hdr->seq_num),
1325 ntohs (hdr->checksum),
1326 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001327 return ISIS_WARNING; /* Silently discard */
1328 }
jardineb5d44e2003-12-23 08:09:43 +00001329 }
jardineb5d44e2003-12-23 08:09:43 +00001330 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001331 else
1332 {
1333 /* If no adj, or no sharing of level */
1334 if (!circuit->u.p2p.neighbor)
1335 {
1336 return ISIS_OK; /* Silently discard */
1337 }
1338 else
1339 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001340 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001341 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001342 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001343 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1344 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001345 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001346 }
jardineb5d44e2003-12-23 08:09:43 +00001347 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001348
hassof390d2c2004-09-10 20:48:21 +00001349dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001350 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1351
1352 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1353
hassof390d2c2004-09-10 20:48:21 +00001354 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001355
hassof390d2c2004-09-10 20:48:21 +00001356 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1357 if (hdr->rem_lifetime == 0)
1358 {
1359 if (!lsp)
1360 {
1361 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1362 /* only needed on explicit update, eg - p2p */
1363 if (circuit->circ_type == CIRCUIT_T_P2P)
1364 ack_lsp (hdr, circuit, level);
1365 return retval; /* FIXME: do we need a purge? */
1366 }
1367 else
1368 {
1369 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1370 {
1371 /* LSP by some other system -> do 7.3.16.4 b) */
1372 /* 7.3.16.4 b) 1) */
1373 if (comp == LSP_NEWER)
1374 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001375 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001376 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001377 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001378 /* iii */
1379 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1380 /* v */
1381 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1382 /* iv */
1383 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1384 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001385
hassof390d2c2004-09-10 20:48:21 +00001386 } /* 7.3.16.4 b) 2) */
1387 else if (comp == LSP_EQUAL)
1388 {
1389 /* i */
1390 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1391 /* ii */
1392 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1393 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1394 } /* 7.3.16.4 b) 3) */
1395 else
1396 {
1397 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1398 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1399 }
1400 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001401 else if (lsp->lsp_header->rem_lifetime != 0)
1402 {
1403 /* our own LSP -> 7.3.16.4 c) */
1404 if (comp == LSP_NEWER)
1405 {
1406 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1407 lsp_set_all_srmflags (lsp);
1408 }
1409 else
1410 {
1411 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1412 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1413 }
1414 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1415 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1416 "seq 0x%08x", circuit->area->area_tag,
1417 rawlspid_print (hdr->lsp_id),
1418 ntohl (lsp->lsp_header->seq_num));
1419 }
hassof390d2c2004-09-10 20:48:21 +00001420 }
1421 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001422 }
jardineb5d44e2003-12-23 08:09:43 +00001423 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1424 * purge */
hassof390d2c2004-09-10 20:48:21 +00001425 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1426 {
1427 if (!lsp)
1428 {
1429 /* 7.3.16.4: initiate a purge */
1430 lsp_purge_non_exist (hdr, circuit->area);
1431 return ISIS_OK;
1432 }
1433 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1434
1435 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1436 * has information that the current sequence number for source S is
1437 * "greater" than that held by S, ... */
1438
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001439 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001440 {
1441 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001442 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001443 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1444 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1445 "0x%08x", circuit->area->area_tag,
1446 rawlspid_print (hdr->lsp_id),
1447 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001448 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001449 /* If the received LSP is older or equal,
1450 * resend the LSP which will act as ACK */
1451 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001452 }
hassof390d2c2004-09-10 20:48:21 +00001453 else
1454 {
1455 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001456
hassof390d2c2004-09-10 20:48:21 +00001457 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1458 if ((!lsp || comp == LSP_NEWER))
1459 {
hassof390d2c2004-09-10 20:48:21 +00001460 /*
1461 * If this lsp is a frag, need to see if we have zero lsp present
1462 */
1463 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1464 {
1465 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1466 LSP_FRAGMENT (lspid) = 0;
1467 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1468 if (!lsp0)
1469 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001470 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001471 return ISIS_OK;
1472 }
1473 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001474 /* i */
1475 if (!lsp)
1476 {
1477 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001478 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001479 circuit->area, level);
1480 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1481 }
1482 else /* exists, so we overwrite */
1483 {
1484 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1485 }
hassof390d2c2004-09-10 20:48:21 +00001486 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001487 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001488 /* iii */
1489 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001490
hassof390d2c2004-09-10 20:48:21 +00001491 /* iv */
1492 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1493 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1494 /* FIXME: v) */
1495 }
1496 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1497 else if (comp == LSP_EQUAL)
1498 {
1499 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001500 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001501 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001502 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001503 }
1504 /* 7.3.15.1 e) 3) LSP older than the one in db */
1505 else
1506 {
1507 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1508 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1509 }
jardineb5d44e2003-12-23 08:09:43 +00001510 }
jardineb5d44e2003-12-23 08:09:43 +00001511 return retval;
1512}
1513
1514/*
1515 * Process Sequence Numbers
1516 * ISO - 10589
1517 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1518 */
1519
hasso92365882005-01-18 13:53:33 +00001520static int
hassof390d2c2004-09-10 20:48:21 +00001521process_snp (int snp_type, int level, struct isis_circuit *circuit,
1522 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001523{
1524 int retval = ISIS_OK;
1525 int cmp, own_lsp;
1526 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001527 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001528 struct isis_adjacency *adj;
1529 struct isis_complete_seqnum_hdr *chdr = NULL;
1530 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001531 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001532 struct isis_lsp *lsp;
1533 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001534 struct listnode *node, *nnode;
1535 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001536 struct tlvs tlvs;
1537 struct list *lsp_list = NULL;
1538 struct isis_passwd *passwd;
1539
hassof390d2c2004-09-10 20:48:21 +00001540 if (snp_type == ISIS_SNP_CSNP_FLAG)
1541 {
1542 /* getting the header info */
1543 typechar = 'C';
1544 chdr =
1545 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001546 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1547 pdu_len = ntohs (chdr->pdu_len);
1548 if (pdu_len < ISIS_CSNP_HDRLEN ||
1549 pdu_len > ISO_MTU(circuit) ||
1550 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001551 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001552 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1553 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001554 }
jardineb5d44e2003-12-23 08:09:43 +00001555 }
hassof390d2c2004-09-10 20:48:21 +00001556 else
1557 {
1558 typechar = 'P';
1559 phdr =
1560 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001561 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1562 pdu_len = ntohs (phdr->pdu_len);
1563 if (pdu_len < ISIS_PSNP_HDRLEN ||
1564 pdu_len > ISO_MTU(circuit) ||
1565 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001566 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001567 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1568 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001569 }
jardineb5d44e2003-12-23 08:09:43 +00001570 }
jardineb5d44e2003-12-23 08:09:43 +00001571
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001572 /*
1573 * Set the stream endp to PDU length, ignoring additional padding
1574 * introduced by transport chips.
1575 */
1576 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1577 stream_set_endp (circuit->rcv_stream, pdu_len);
1578
jardineb5d44e2003-12-23 08:09:43 +00001579 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001580 if (circuit->ext_domain)
1581 {
jardineb5d44e2003-12-23 08:09:43 +00001582
hasso529d65b2004-12-24 00:14:50 +00001583 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1584 "skipping: circuit externalDomain = true",
1585 circuit->area->area_tag,
1586 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001587
1588 return ISIS_OK;
1589 }
hassof390d2c2004-09-10 20:48:21 +00001590
1591 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001592 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001593 {
1594
hasso529d65b2004-12-24 00:14:50 +00001595 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1596 "skipping: circuit type %s does not match level %d",
1597 circuit->area->area_tag,
1598 level,
1599 typechar,
1600 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001601 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001602
1603 return ISIS_OK;
1604 }
1605
1606 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1607 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001608 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1609 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001610 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001611 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1612 "skipping: we are not the DIS",
1613 circuit->area->area_tag,
1614 level,
1615 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001616
Josh Bailey3f045a02012-03-24 08:35:20 -07001617 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001618 }
jardineb5d44e2003-12-23 08:09:43 +00001619
1620 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1621
1622 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1623 * - already checked */
1624
1625 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1626 /* for broadcast circuits, snpa should be compared */
1627 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001628 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1629 {
1630 if (snp_type == ISIS_SNP_CSNP_FLAG)
1631 {
1632 adj =
1633 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1634 }
1635 else
1636 {
1637 /* a psnp on a broadcast, how lovely of Juniper :) */
1638 adj =
1639 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1640 }
1641 if (!adj)
1642 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001643 }
hassof390d2c2004-09-10 20:48:21 +00001644 else
1645 {
1646 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001647 {
1648 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1649 return ISIS_OK; /* Silently discard */
1650 }
hassof390d2c2004-09-10 20:48:21 +00001651 }
jardineb5d44e2003-12-23 08:09:43 +00001652
1653 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1654
1655 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1656
1657 memset (&tlvs, 0, sizeof (struct tlvs));
1658
1659 /* parse the SNP */
1660 expected |= TLVFLAG_LSP_ENTRIES;
1661 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001662
1663 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001664 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001665 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001666 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001667 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001668
hassof390d2c2004-09-10 20:48:21 +00001669 if (retval > ISIS_WARNING)
1670 {
1671 zlog_warn ("something went very wrong processing SNP");
1672 free_tlvs (&tlvs);
1673 return retval;
1674 }
jardineb5d44e2003-12-23 08:09:43 +00001675
Josh Bailey3f045a02012-03-24 08:35:20 -07001676 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001677 passwd = &circuit->area->area_passwd;
1678 else
1679 passwd = &circuit->area->domain_passwd;
1680
1681 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001682 {
hasso1cbc5622005-01-01 10:29:51 +00001683 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001684 {
1685 if (!(found & TLVFLAG_AUTH_INFO) ||
1686 authentication_check (&tlvs.auth_info, passwd,
1687 circuit->rcv_stream, auth_tlv_offset))
1688 {
1689 isis_event_auth_failure (circuit->area->area_tag,
1690 "SNP authentication" " failure",
1691 phdr ? phdr->source_id :
1692 chdr->source_id);
1693 free_tlvs (&tlvs);
1694 return ISIS_OK;
1695 }
1696 }
hassof390d2c2004-09-10 20:48:21 +00001697 }
jardineb5d44e2003-12-23 08:09:43 +00001698
1699 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001700 if (isis->debugs & DEBUG_SNP_PACKETS)
1701 {
hasso529d65b2004-12-24 00:14:50 +00001702 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1703 circuit->area->area_tag,
1704 level,
1705 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001706 if (tlvs.lsp_entries)
1707 {
hasso3fdb2dd2005-09-28 18:45:54 +00001708 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001709 {
hasso529d65b2004-12-24 00:14:50 +00001710 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1711 " cksum 0x%04x, lifetime %us",
1712 circuit->area->area_tag,
1713 typechar,
1714 rawlspid_print (entry->lsp_id),
1715 ntohl (entry->seq_num),
1716 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001717 }
1718 }
jardineb5d44e2003-12-23 08:09:43 +00001719 }
jardineb5d44e2003-12-23 08:09:43 +00001720
1721 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001722 if (tlvs.lsp_entries)
1723 {
hasso3fdb2dd2005-09-28 18:45:54 +00001724 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001725 {
1726 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1727 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1728 if (lsp)
1729 {
1730 /* 7.3.15.2 b) 1) is this LSP newer */
1731 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1732 entry->checksum, entry->rem_lifetime);
1733 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1734 if (cmp == LSP_EQUAL)
1735 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001736 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1737 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001738 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001739 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001740 else if (cmp == LSP_OLDER)
1741 {
1742 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1743 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1744 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001745 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001746 else
1747 {
hassof390d2c2004-09-10 20:48:21 +00001748 if (own_lsp)
1749 {
1750 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1751 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1752 }
1753 else
1754 {
1755 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001756 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1757 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001758 }
1759 }
1760 }
1761 else
1762 {
1763 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1764 * insert it and set SSN on it */
1765 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1766 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1767 {
1768 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1769 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001770 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001771 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001772 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001773 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1774 }
1775 }
jardineb5d44e2003-12-23 08:09:43 +00001776 }
1777 }
jardineb5d44e2003-12-23 08:09:43 +00001778
1779 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001780 if (snp_type == ISIS_SNP_CSNP_FLAG)
1781 {
1782 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001783 * Build a list from our own LSP db bounded with
1784 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001785 */
1786 lsp_list = list_new ();
1787 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1788 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001789
hassof390d2c2004-09-10 20:48:21 +00001790 /* Fixme: Find a better solution */
1791 if (tlvs.lsp_entries)
1792 {
paul1eb8ef22005-04-07 07:30:20 +00001793 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001794 {
paul1eb8ef22005-04-07 07:30:20 +00001795 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001796 {
1797 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1798 {
1799 list_delete_node (lsp_list, node2);
1800 break;
1801 }
1802 }
1803 }
1804 }
1805 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001806 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001807 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001808 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001809 list_delete (lsp_list);
1810
jardineb5d44e2003-12-23 08:09:43 +00001811 }
jardineb5d44e2003-12-23 08:09:43 +00001812
1813 free_tlvs (&tlvs);
1814 return retval;
1815}
1816
hasso92365882005-01-18 13:53:33 +00001817static int
hassof390d2c2004-09-10 20:48:21 +00001818process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001819{
Josh Bailey3f045a02012-03-24 08:35:20 -07001820 if (isis->debugs & DEBUG_SNP_PACKETS)
1821 {
1822 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1823 circuit->area->area_tag, level, circuit->interface->name,
1824 circuit_t2string (circuit->is_type), circuit->circuit_id);
1825 if (isis->debugs & DEBUG_PACKET_DUMP)
1826 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1827 stream_get_endp (circuit->rcv_stream));
1828 }
1829
jardineb5d44e2003-12-23 08:09:43 +00001830 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001831 if ((stream_get_endp (circuit->rcv_stream) -
1832 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1833 {
1834 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1835 return ISIS_WARNING;
1836 }
jardineb5d44e2003-12-23 08:09:43 +00001837
1838 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1839}
1840
hasso92365882005-01-18 13:53:33 +00001841static int
hassof390d2c2004-09-10 20:48:21 +00001842process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001843{
Josh Bailey3f045a02012-03-24 08:35:20 -07001844 if (isis->debugs & DEBUG_SNP_PACKETS)
1845 {
1846 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1847 circuit->area->area_tag, level, circuit->interface->name,
1848 circuit_t2string (circuit->is_type), circuit->circuit_id);
1849 if (isis->debugs & DEBUG_PACKET_DUMP)
1850 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1851 stream_get_endp (circuit->rcv_stream));
1852 }
1853
hassof390d2c2004-09-10 20:48:21 +00001854 if ((stream_get_endp (circuit->rcv_stream) -
1855 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1856 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001857 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001858 return ISIS_WARNING;
1859 }
jardineb5d44e2003-12-23 08:09:43 +00001860
1861 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1862}
1863
jardineb5d44e2003-12-23 08:09:43 +00001864/*
1865 * Process ISH
1866 * ISO - 10589
1867 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1868 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001869 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1870 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1871 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001872 */
hasso92365882005-01-18 13:53:33 +00001873static int
jardineb5d44e2003-12-23 08:09:43 +00001874process_is_hello (struct isis_circuit *circuit)
1875{
1876 struct isis_adjacency *adj;
1877 int retval = ISIS_OK;
1878 u_char neigh_len;
1879 u_char *sysid;
1880
Josh Bailey3f045a02012-03-24 08:35:20 -07001881 if (isis->debugs & DEBUG_ADJ_PACKETS)
1882 {
1883 zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u",
1884 circuit->area->area_tag, circuit->interface->name,
1885 circuit_t2string (circuit->is_type), circuit->circuit_id);
1886 if (isis->debugs & DEBUG_PACKET_DUMP)
1887 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1888 stream_get_endp (circuit->rcv_stream));
1889 }
1890
jardineb5d44e2003-12-23 08:09:43 +00001891 /* In this point in time we are not yet able to handle is_hellos
1892 * on lan - Sorry juniper...
1893 */
1894 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1895 return retval;
1896
1897 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001898 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001899 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001900 if (!adj)
1901 {
1902 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00001903 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001904 if (adj == NULL)
1905 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001906
hassof390d2c2004-09-10 20:48:21 +00001907 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1908 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1909 circuit->u.p2p.neighbor = adj;
1910 }
1911 /* 8.2.2 a) */
1912 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1913 ISIS_SYS_ID_LEN))
1914 {
1915 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1916 /* 8.2.2 a) 2) delete the adj */
1917 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1918 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00001919 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001920 if (adj == NULL)
1921 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001922
hassof390d2c2004-09-10 20:48:21 +00001923 /* 8.2.2 a) 3) i */
1924 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1925 /* 8.2.2 a) 3) ii */
1926 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1927 /* 8.2.2 a) 4) quite meaningless */
1928 }
jardineb5d44e2003-12-23 08:09:43 +00001929 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001930 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1931 (adj->sys_type == ISIS_SYSTYPE_IS))
1932 {
1933 /* do nothing */
1934 }
1935 else
1936 {
1937 /* 8.2.2 c) respond with a p2p IIH */
1938 send_hello (circuit, 1);
1939 }
jardineb5d44e2003-12-23 08:09:43 +00001940 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001941 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001942 /* 8.2.2 e) FIXME: Circuit type of? */
1943
jardineb5d44e2003-12-23 08:09:43 +00001944 return retval;
1945}
1946
jardineb5d44e2003-12-23 08:09:43 +00001947/*
1948 * PDU Dispatcher
1949 */
1950
hasso92365882005-01-18 13:53:33 +00001951static int
hassof390d2c2004-09-10 20:48:21 +00001952isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001953{
jardineb5d44e2003-12-23 08:09:43 +00001954 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00001955
hassof390d2c2004-09-10 20:48:21 +00001956 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001957
1958 /*
1959 * Let's first read data from stream to the header
1960 */
hassof390d2c2004-09-10 20:48:21 +00001961 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001962
hassof390d2c2004-09-10 20:48:21 +00001963 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1964 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001965 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00001966 return ISIS_ERROR;
1967 }
jardineb5d44e2003-12-23 08:09:43 +00001968
1969 /* now we need to know if this is an ISO 9542 packet and
1970 * take real good care of it, waaa!
1971 */
hassof390d2c2004-09-10 20:48:21 +00001972 if (hdr->idrp == ISO9542_ESIS)
1973 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001974 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
1975 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00001976 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001977 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1978
jardineb5d44e2003-12-23 08:09:43 +00001979 /*
1980 * and then process it
1981 */
1982
hassof390d2c2004-09-10 20:48:21 +00001983 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1984 {
1985 zlog_err ("Fixed header length = %d", hdr->length);
1986 return ISIS_ERROR;
1987 }
jardineb5d44e2003-12-23 08:09:43 +00001988
hassof390d2c2004-09-10 20:48:21 +00001989 if (hdr->version1 != 1)
1990 {
1991 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1992 return ISIS_WARNING;
1993 }
jardineb5d44e2003-12-23 08:09:43 +00001994 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001995 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1996 {
1997 zlog_err
1998 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
1999 "while the parameter for this IS is %u", hdr->id_len,
2000 ISIS_SYS_ID_LEN);
2001 return ISIS_ERROR;
2002 }
jardineb5d44e2003-12-23 08:09:43 +00002003
hassof390d2c2004-09-10 20:48:21 +00002004 if (hdr->version2 != 1)
2005 {
2006 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2007 return ISIS_WARNING;
2008 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002009
2010 if (circuit->is_passive)
2011 {
2012 zlog_warn ("Received ISIS PDU on passive circuit %s",
2013 circuit->interface->name);
2014 return ISIS_WARNING;
2015 }
2016
jardineb5d44e2003-12-23 08:09:43 +00002017 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002018 if ((hdr->max_area_addrs != 0)
2019 && (hdr->max_area_addrs != isis->max_area_addrs))
2020 {
2021 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2022 "received PDU %u while the parameter for this IS is %u",
2023 hdr->max_area_addrs, isis->max_area_addrs);
2024 return ISIS_ERROR;
2025 }
jardineb5d44e2003-12-23 08:09:43 +00002026
hassof390d2c2004-09-10 20:48:21 +00002027 switch (hdr->pdu_type)
2028 {
2029 case L1_LAN_HELLO:
2030 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2031 break;
2032 case L2_LAN_HELLO:
2033 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2034 break;
2035 case P2P_HELLO:
2036 retval = process_p2p_hello (circuit);
2037 break;
2038 case L1_LINK_STATE:
2039 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2040 break;
2041 case L2_LINK_STATE:
2042 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2043 break;
2044 case L1_COMPLETE_SEQ_NUM:
2045 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2046 break;
2047 case L2_COMPLETE_SEQ_NUM:
2048 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2049 break;
2050 case L1_PARTIAL_SEQ_NUM:
2051 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2052 break;
2053 case L2_PARTIAL_SEQ_NUM:
2054 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2055 break;
2056 default:
2057 return ISIS_ERROR;
2058 }
jardineb5d44e2003-12-23 08:09:43 +00002059
2060 return retval;
2061}
2062
jardineb5d44e2003-12-23 08:09:43 +00002063#ifdef GNU_LINUX
2064int
2065isis_receive (struct thread *thread)
2066{
jardineb5d44e2003-12-23 08:09:43 +00002067 struct isis_circuit *circuit;
2068 u_char ssnpa[ETH_ALEN];
2069 int retval;
2070
2071 /*
2072 * Get the circuit
2073 */
2074 circuit = THREAD_ARG (thread);
2075 assert (circuit);
2076
2077 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002078 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002079 else
2080 stream_reset (circuit->rcv_stream);
2081
2082 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002083 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002084
2085 if (retval == ISIS_OK)
2086 retval = isis_handle_pdu (circuit, ssnpa);
2087
2088 /*
2089 * prepare for next packet.
2090 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002091 if (!circuit->is_passive)
2092 {
2093 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2094 circuit->fd);
2095 }
jardineb5d44e2003-12-23 08:09:43 +00002096
2097 return retval;
2098}
2099
2100#else
2101int
2102isis_receive (struct thread *thread)
2103{
jardineb5d44e2003-12-23 08:09:43 +00002104 struct isis_circuit *circuit;
2105 u_char ssnpa[ETH_ALEN];
2106 int retval;
2107
2108 /*
2109 * Get the circuit
2110 */
2111 circuit = THREAD_ARG (thread);
2112 assert (circuit);
2113
hassof390d2c2004-09-10 20:48:21 +00002114 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002115
2116 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002117 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002118 else
2119 stream_reset (circuit->rcv_stream);
2120
2121 retval = circuit->rx (circuit, ssnpa);
2122
2123 if (retval == ISIS_OK)
2124 retval = isis_handle_pdu (circuit, ssnpa);
2125
2126 /*
2127 * prepare for next packet.
2128 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002129 if (!circuit->is_passive)
2130 {
2131 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2132 listcount
2133 (circuit->area->circuit_list) *
2134 100);
2135 }
jardineb5d44e2003-12-23 08:09:43 +00002136
2137 return retval;
2138}
2139
2140#endif
2141
2142 /* filling of the fixed isis header */
2143void
2144fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2145{
2146 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2147
2148 hdr->idrp = ISO10589_ISIS;
2149
hassof390d2c2004-09-10 20:48:21 +00002150 switch (pdu_type)
2151 {
2152 case L1_LAN_HELLO:
2153 case L2_LAN_HELLO:
2154 hdr->length = ISIS_LANHELLO_HDRLEN;
2155 break;
2156 case P2P_HELLO:
2157 hdr->length = ISIS_P2PHELLO_HDRLEN;
2158 break;
2159 case L1_LINK_STATE:
2160 case L2_LINK_STATE:
2161 hdr->length = ISIS_LSP_HDR_LEN;
2162 break;
2163 case L1_COMPLETE_SEQ_NUM:
2164 case L2_COMPLETE_SEQ_NUM:
2165 hdr->length = ISIS_CSNP_HDRLEN;
2166 break;
2167 case L1_PARTIAL_SEQ_NUM:
2168 case L2_PARTIAL_SEQ_NUM:
2169 hdr->length = ISIS_PSNP_HDRLEN;
2170 break;
2171 default:
2172 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2173 return;
2174 }
jardineb5d44e2003-12-23 08:09:43 +00002175 hdr->length += ISIS_FIXED_HDR_LEN;
2176 hdr->pdu_type = pdu_type;
2177 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002178 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002179 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002180 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002181}
2182
jardineb5d44e2003-12-23 08:09:43 +00002183/*
2184 * SEND SIDE
2185 */
hasso92365882005-01-18 13:53:33 +00002186static void
jardineb5d44e2003-12-23 08:09:43 +00002187fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002188 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002189{
hassof390d2c2004-09-10 20:48:21 +00002190 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002191
2192 stream_putc (stream, hdr->idrp);
2193 stream_putc (stream, hdr->length);
2194 stream_putc (stream, hdr->version1);
2195 stream_putc (stream, hdr->id_len);
2196 stream_putc (stream, hdr->pdu_type);
2197 stream_putc (stream, hdr->version2);
2198 stream_putc (stream, hdr->reserved);
2199 stream_putc (stream, hdr->max_area_addrs);
2200
2201 return;
2202}
2203
jardineb5d44e2003-12-23 08:09:43 +00002204int
2205send_hello (struct isis_circuit *circuit, int level)
2206{
2207 struct isis_fixed_hdr fixed_hdr;
2208 struct isis_lan_hello_hdr hello_hdr;
2209 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002210 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2211 unsigned long len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002212 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002213 int retval;
2214
Josh Bailey3f045a02012-03-24 08:35:20 -07002215 if (circuit->is_passive)
2216 return ISIS_OK;
2217
hassof390d2c2004-09-10 20:48:21 +00002218 if (circuit->interface->mtu == 0)
2219 {
2220 zlog_warn ("circuit has zero MTU");
2221 return ISIS_WARNING;
2222 }
jardineb5d44e2003-12-23 08:09:43 +00002223
2224 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002225 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002226 else
2227 stream_reset (circuit->snd_stream);
2228
2229 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002230 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002231 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2232 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002233 else
hassof390d2c2004-09-10 20:48:21 +00002234 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2235 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002236 else
hassof390d2c2004-09-10 20:48:21 +00002237 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002238
2239 /*
2240 * Fill LAN Level 1 or 2 Hello PDU header
2241 */
2242 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002243 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002244 circuit->hello_interval[level - 1];
2245 if (interval > USHRT_MAX)
2246 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002247 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002248 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002249 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002250
hassof390d2c2004-09-10 20:48:21 +00002251 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002252 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002253
2254 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002255 if (circuit->circ_type == CIRCUIT_T_P2P)
2256 {
2257 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2258 p2p_hello_hdr.local_id = circuit->circuit_id;
2259 /* FIXME: need better understanding */
2260 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002261 }
hassof390d2c2004-09-10 20:48:21 +00002262 else
2263 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002264 hello_hdr.prio = circuit->priority[level - 1];
2265 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002266 {
2267 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2268 ISIS_SYS_ID_LEN + 1);
2269 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002270 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002271 {
2272 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2273 ISIS_SYS_ID_LEN + 1);
2274 }
2275 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2276 }
jardineb5d44e2003-12-23 08:09:43 +00002277
2278 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002279 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002280 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002281
jardineb5d44e2003-12-23 08:09:43 +00002282 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002283 switch (circuit->passwd.type)
2284 {
2285 /* Cleartext */
2286 case ISIS_PASSWD_TYPE_CLEARTXT:
2287 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2288 circuit->passwd.passwd, circuit->snd_stream))
2289 return ISIS_WARNING;
2290 break;
2291
2292 /* HMAC MD5 */
2293 case ISIS_PASSWD_TYPE_HMAC_MD5:
2294 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2295 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2296 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2297 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2298 hmac_md5_hash, circuit->snd_stream))
2299 return ISIS_WARNING;
2300 break;
2301
2302 default:
2303 break;
2304 }
2305
jardineb5d44e2003-12-23 08:09:43 +00002306 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002307 if (listcount (circuit->area->area_addrs) == 0)
2308 return ISIS_WARNING;
2309 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2310 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002311
2312 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002313 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2314 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002315 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2316 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002317 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2318 circuit->snd_stream))
2319 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002320 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2321 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002322 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2323 circuit->snd_stream))
2324 return ISIS_WARNING;
2325 }
jardineb5d44e2003-12-23 08:09:43 +00002326
2327 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002328 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002329 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2330 return ISIS_WARNING;
2331 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002332 if (circuit->ip_router && circuit->ip_addrs &&
2333 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002334 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2335 return ISIS_WARNING;
2336
hassof390d2c2004-09-10 20:48:21 +00002337#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002338 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002339 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002340 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002341 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2342 return ISIS_WARNING;
2343#endif /* HAVE_IPV6 */
2344
Josh Bailey3f045a02012-03-24 08:35:20 -07002345 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002346 if (tlv_add_padding (circuit->snd_stream))
2347 return ISIS_WARNING;
2348
paul9985f832005-02-09 15:51:56 +00002349 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002350 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002351 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002352
Josh Bailey3f045a02012-03-24 08:35:20 -07002353 /* For HMAC MD5 we need to compute the md5 hash and store it */
2354 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2355 {
2356 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2357 stream_get_endp (circuit->snd_stream),
2358 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
2359 (caddr_t) &hmac_md5_hash);
2360 /* Copy the hash into the stream */
2361 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2362 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2363 }
jardineb5d44e2003-12-23 08:09:43 +00002364
hassof390d2c2004-09-10 20:48:21 +00002365 if (isis->debugs & DEBUG_ADJ_PACKETS)
2366 {
2367 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2368 {
hasso529d65b2004-12-24 00:14:50 +00002369 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2370 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002371 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002372 length);
hassof390d2c2004-09-10 20:48:21 +00002373 }
2374 else
2375 {
hasso529d65b2004-12-24 00:14:50 +00002376 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2377 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002378 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002379 length);
hassof390d2c2004-09-10 20:48:21 +00002380 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002381 if (isis->debugs & DEBUG_PACKET_DUMP)
2382 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2383 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002384 }
jardineb5d44e2003-12-23 08:09:43 +00002385
Josh Bailey3f045a02012-03-24 08:35:20 -07002386 retval = circuit->tx (circuit, level);
2387 if (retval != ISIS_OK)
2388 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2389 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002390
Josh Bailey3f045a02012-03-24 08:35:20 -07002391 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002392}
2393
2394int
2395send_lan_l1_hello (struct thread *thread)
2396{
jardineb5d44e2003-12-23 08:09:43 +00002397 struct isis_circuit *circuit;
2398 int retval;
2399
2400 circuit = THREAD_ARG (thread);
2401 assert (circuit);
2402 circuit->u.bc.t_send_lan_hello[0] = NULL;
2403
2404 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002405 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002406
Josh Bailey3f045a02012-03-24 08:35:20 -07002407 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002408
2409 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002410 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2411 send_lan_l1_hello, circuit,
2412 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002413
2414 return retval;
2415}
2416
2417int
2418send_lan_l2_hello (struct thread *thread)
2419{
2420 struct isis_circuit *circuit;
2421 int retval;
2422
2423 circuit = THREAD_ARG (thread);
2424 assert (circuit);
2425 circuit->u.bc.t_send_lan_hello[1] = NULL;
2426
2427 if (circuit->u.bc.run_dr_elect[1])
2428 retval = isis_dr_elect (circuit, 2);
2429
Josh Bailey3f045a02012-03-24 08:35:20 -07002430 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002431
hassof390d2c2004-09-10 20:48:21 +00002432 /* set next timer thread */
2433 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2434 send_lan_l2_hello, circuit,
2435 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002436
2437 return retval;
2438}
2439
2440int
2441send_p2p_hello (struct thread *thread)
2442{
2443 struct isis_circuit *circuit;
2444
2445 circuit = THREAD_ARG (thread);
2446 assert (circuit);
2447 circuit->u.p2p.t_send_p2p_hello = NULL;
2448
hassof390d2c2004-09-10 20:48:21 +00002449 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002450
hassof390d2c2004-09-10 20:48:21 +00002451 /* set next timer thread */
2452 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2453 circuit, isis_jitter (circuit->hello_interval[1],
2454 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002455
2456 return ISIS_OK;
2457}
2458
hasso92365882005-01-18 13:53:33 +00002459static int
hassof390d2c2004-09-10 20:48:21 +00002460build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2461 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002462{
2463 struct isis_fixed_hdr fixed_hdr;
2464 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002465 unsigned long lenp;
2466 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002467 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2468 unsigned long auth_tlv_offset = 0;
2469 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002470
Josh Bailey3f045a02012-03-24 08:35:20 -07002471 if (circuit->snd_stream == NULL)
2472 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2473 else
2474 stream_reset (circuit->snd_stream);
2475
2476 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002477 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2478 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002479 else
hassof390d2c2004-09-10 20:48:21 +00002480 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2481 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002482
2483 /*
2484 * Fill Level 1 or 2 Complete Sequence Numbers header
2485 */
2486
paul9985f832005-02-09 15:51:56 +00002487 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002488 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002489 /* no need to send the source here, it is always us if we csnp */
2490 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2491 /* with zero circuit id - ref 9.10, 9.11 */
2492 stream_putc (circuit->snd_stream, 0x00);
2493
2494 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2495 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2496
2497 /*
2498 * And TLVs
2499 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002500 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002501 passwd = &circuit->area->area_passwd;
2502 else
2503 passwd = &circuit->area->domain_passwd;
2504
hasso1cbc5622005-01-01 10:29:51 +00002505 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002506 {
2507 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002508 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002509 /* Cleartext */
2510 case ISIS_PASSWD_TYPE_CLEARTXT:
2511 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2512 passwd->passwd, circuit->snd_stream))
2513 return ISIS_WARNING;
2514 break;
2515
2516 /* HMAC MD5 */
2517 case ISIS_PASSWD_TYPE_HMAC_MD5:
2518 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2519 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2520 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2521 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2522 hmac_md5_hash, circuit->snd_stream))
2523 return ISIS_WARNING;
2524 break;
2525
2526 default:
2527 break;
hassof390d2c2004-09-10 20:48:21 +00002528 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002529 }
2530
2531 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2532 if (retval != ISIS_OK)
2533 return retval;
2534
paul9985f832005-02-09 15:51:56 +00002535 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002536 /* Update PU length */
2537 stream_putw_at (circuit->snd_stream, lenp, length);
2538
Josh Bailey3f045a02012-03-24 08:35:20 -07002539 /* For HMAC MD5 we need to compute the md5 hash and store it */
2540 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2541 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2542 {
2543 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2544 stream_get_endp(circuit->snd_stream),
2545 (unsigned char *) &passwd->passwd, passwd->len,
2546 (caddr_t) &hmac_md5_hash);
2547 /* Copy the hash into the stream */
2548 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2549 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2550 }
2551
jardineb5d44e2003-12-23 08:09:43 +00002552 return retval;
2553}
2554
2555/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002556 * Count the maximum number of lsps that can be accomodated by a given size.
2557 */
2558static uint16_t
2559get_max_lsp_count (uint16_t size)
2560{
2561 uint16_t tlv_count;
2562 uint16_t lsp_count;
2563 uint16_t remaining_size;
2564
2565 /* First count the full size TLVs */
2566 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2567 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2568
2569 /* The last TLV, if any */
2570 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2571 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2572 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2573
2574 return lsp_count;
2575}
2576
2577/*
2578 * Calculate the length of Authentication Info. TLV.
2579 */
2580static uint16_t
2581auth_tlv_length (int level, struct isis_circuit *circuit)
2582{
2583 struct isis_passwd *passwd;
2584 uint16_t length;
2585
2586 if (level == IS_LEVEL_1)
2587 passwd = &circuit->area->area_passwd;
2588 else
2589 passwd = &circuit->area->domain_passwd;
2590
2591 /* Also include the length of TLV header */
2592 length = AUTH_INFO_HDRLEN;
2593 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2594 {
2595 switch (passwd->type)
2596 {
2597 /* Cleartext */
2598 case ISIS_PASSWD_TYPE_CLEARTXT:
2599 length += passwd->len;
2600 break;
2601
2602 /* HMAC MD5 */
2603 case ISIS_PASSWD_TYPE_HMAC_MD5:
2604 length += ISIS_AUTH_MD5_SIZE;
2605 break;
2606
2607 default:
2608 break;
2609 }
2610 }
2611
2612 return length;
2613}
2614
2615/*
2616 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2617 */
2618static uint16_t
2619max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2620{
2621 int snp_hdr_len;
2622 int auth_tlv_len;
2623 uint16_t lsp_count;
2624
2625 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2626 if (snp_type == ISIS_SNP_CSNP_FLAG)
2627 snp_hdr_len += ISIS_CSNP_HDRLEN;
2628 else
2629 snp_hdr_len += ISIS_PSNP_HDRLEN;
2630
2631 auth_tlv_len = auth_tlv_length (level, circuit);
2632 lsp_count = get_max_lsp_count (
2633 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002634 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002635}
2636
2637/*
jardineb5d44e2003-12-23 08:09:43 +00002638 * FIXME: support multiple CSNPs
2639 */
2640
2641int
2642send_csnp (struct isis_circuit *circuit, int level)
2643{
jardineb5d44e2003-12-23 08:09:43 +00002644 u_char start[ISIS_SYS_ID_LEN + 2];
2645 u_char stop[ISIS_SYS_ID_LEN + 2];
2646 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002647 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002648 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002649 u_char num_lsps, loop = 1;
2650 int i, retval = ISIS_OK;
2651
2652 if (circuit->area->lspdb[level - 1] == NULL ||
2653 dict_count (circuit->area->lspdb[level - 1]) == 0)
2654 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002655
hassof390d2c2004-09-10 20:48:21 +00002656 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002657 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2658
Josh Bailey3f045a02012-03-24 08:35:20 -07002659 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2660
2661 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002662 {
2663 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002664 lsp_build_list (start, stop, num_lsps, list,
2665 circuit->area->lspdb[level - 1]);
2666 /*
2667 * Update the stop lsp_id before encoding this CSNP.
2668 */
2669 if (listcount (list) < num_lsps)
2670 {
2671 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2672 }
hassof390d2c2004-09-10 20:48:21 +00002673 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002674 {
2675 node = listtail (list);
2676 lsp = listgetdata (node);
2677 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2678 }
jardineb5d44e2003-12-23 08:09:43 +00002679
hassof390d2c2004-09-10 20:48:21 +00002680 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002681 if (retval != ISIS_OK)
2682 {
2683 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2684 circuit->area->area_tag, level, circuit->interface->name);
2685 list_delete (list);
2686 return retval;
2687 }
jardineb5d44e2003-12-23 08:09:43 +00002688
hassof390d2c2004-09-10 20:48:21 +00002689 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002690 {
2691 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2692 circuit->area->area_tag, level, circuit->interface->name,
2693 stream_get_endp (circuit->snd_stream));
2694 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2695 {
2696 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2697 " cksum 0x%04x, lifetime %us",
2698 circuit->area->area_tag,
2699 rawlspid_print (lsp->lsp_header->lsp_id),
2700 ntohl (lsp->lsp_header->seq_num),
2701 ntohs (lsp->lsp_header->checksum),
2702 ntohs (lsp->lsp_header->rem_lifetime));
2703 }
2704 if (isis->debugs & DEBUG_PACKET_DUMP)
2705 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2706 stream_get_endp (circuit->snd_stream));
2707 }
hassof390d2c2004-09-10 20:48:21 +00002708
Josh Bailey3f045a02012-03-24 08:35:20 -07002709 retval = circuit->tx (circuit, level);
2710 if (retval != ISIS_OK)
2711 {
2712 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2713 circuit->area->area_tag, level,
2714 circuit->interface->name);
2715 list_delete (list);
2716 return retval;
2717 }
2718
2719 /*
2720 * Start lsp_id of the next CSNP should be one plus the
2721 * stop lsp_id in this current CSNP.
2722 */
2723 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2724 loop = 0;
2725 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2726 {
2727 if (start[i] < (u_char)0xff)
2728 {
2729 start[i] += 1;
2730 loop = 1;
2731 break;
2732 }
2733 }
2734 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002735 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002736 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002737
jardineb5d44e2003-12-23 08:09:43 +00002738 return retval;
2739}
2740
2741int
2742send_l1_csnp (struct thread *thread)
2743{
2744 struct isis_circuit *circuit;
2745 int retval = ISIS_OK;
2746
2747 circuit = THREAD_ARG (thread);
2748 assert (circuit);
2749
2750 circuit->t_send_csnp[0] = NULL;
2751
hassof390d2c2004-09-10 20:48:21 +00002752 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2753 {
2754 send_csnp (circuit, 1);
2755 }
jardineb5d44e2003-12-23 08:09:43 +00002756 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002757 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2758 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002759
2760 return retval;
2761}
2762
2763int
2764send_l2_csnp (struct thread *thread)
2765{
2766 struct isis_circuit *circuit;
2767 int retval = ISIS_OK;
2768
2769 circuit = THREAD_ARG (thread);
2770 assert (circuit);
2771
2772 circuit->t_send_csnp[1] = NULL;
2773
hassof390d2c2004-09-10 20:48:21 +00002774 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2775 {
2776 send_csnp (circuit, 2);
2777 }
jardineb5d44e2003-12-23 08:09:43 +00002778 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002779 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2780 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002781
jardineb5d44e2003-12-23 08:09:43 +00002782 return retval;
2783}
2784
hasso92365882005-01-18 13:53:33 +00002785static int
jardineb5d44e2003-12-23 08:09:43 +00002786build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2787{
2788 struct isis_fixed_hdr fixed_hdr;
2789 unsigned long lenp;
2790 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002791 struct isis_lsp *lsp;
2792 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002793 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002794 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2795 unsigned long auth_tlv_offset = 0;
2796 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002797
Josh Bailey3f045a02012-03-24 08:35:20 -07002798 if (circuit->snd_stream == NULL)
2799 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2800 else
2801 stream_reset (circuit->snd_stream);
2802
2803 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002804 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2805 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002806 else
2807 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002808 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002809
2810 /*
2811 * Fill Level 1 or 2 Partial Sequence Numbers header
2812 */
paul9985f832005-02-09 15:51:56 +00002813 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002814 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002815 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2816 stream_putc (circuit->snd_stream, circuit->idx);
2817
2818 /*
2819 * And TLVs
2820 */
2821
Josh Bailey3f045a02012-03-24 08:35:20 -07002822 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002823 passwd = &circuit->area->area_passwd;
2824 else
2825 passwd = &circuit->area->domain_passwd;
2826
hasso1cbc5622005-01-01 10:29:51 +00002827 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002828 {
2829 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002830 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002831 /* Cleartext */
2832 case ISIS_PASSWD_TYPE_CLEARTXT:
2833 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2834 passwd->passwd, circuit->snd_stream))
2835 return ISIS_WARNING;
2836 break;
2837
2838 /* HMAC MD5 */
2839 case ISIS_PASSWD_TYPE_HMAC_MD5:
2840 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2841 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2842 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2843 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2844 hmac_md5_hash, circuit->snd_stream))
2845 return ISIS_WARNING;
2846 break;
2847
2848 default:
2849 break;
jardineb5d44e2003-12-23 08:09:43 +00002850 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002851 }
2852
2853 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2854 if (retval != ISIS_OK)
2855 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002856
hassof390d2c2004-09-10 20:48:21 +00002857 if (isis->debugs & DEBUG_SNP_PACKETS)
2858 {
hasso3fdb2dd2005-09-28 18:45:54 +00002859 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002860 {
hasso529d65b2004-12-24 00:14:50 +00002861 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2862 " cksum 0x%04x, lifetime %us",
2863 circuit->area->area_tag,
2864 rawlspid_print (lsp->lsp_header->lsp_id),
2865 ntohl (lsp->lsp_header->seq_num),
2866 ntohs (lsp->lsp_header->checksum),
2867 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002868 }
2869 }
2870
paul9985f832005-02-09 15:51:56 +00002871 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002872 /* Update PDU length */
2873 stream_putw_at (circuit->snd_stream, lenp, length);
2874
Josh Bailey3f045a02012-03-24 08:35:20 -07002875 /* For HMAC MD5 we need to compute the md5 hash and store it */
2876 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2877 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2878 {
2879 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2880 stream_get_endp(circuit->snd_stream),
2881 (unsigned char *) &passwd->passwd, passwd->len,
2882 (caddr_t) &hmac_md5_hash);
2883 /* Copy the hash into the stream */
2884 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2885 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2886 }
2887
jardineb5d44e2003-12-23 08:09:43 +00002888 return ISIS_OK;
2889}
2890
2891/*
2892 * 7.3.15.4 action on expiration of partial SNP interval
2893 * level 1
2894 */
hasso92365882005-01-18 13:53:33 +00002895static int
jardineb5d44e2003-12-23 08:09:43 +00002896send_psnp (int level, struct isis_circuit *circuit)
2897{
jardineb5d44e2003-12-23 08:09:43 +00002898 struct isis_lsp *lsp;
2899 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002900 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002901 u_char num_lsps;
2902 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002903
Josh Bailey3f045a02012-03-24 08:35:20 -07002904 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2905 circuit->u.bc.is_dr[level - 1])
2906 return ISIS_OK;
2907
2908 if (circuit->area->lspdb[level - 1] == NULL ||
2909 dict_count (circuit->area->lspdb[level - 1]) == 0)
2910 return ISIS_OK;
2911
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002912 if (! circuit->snd_stream)
2913 return ISIS_ERROR;
2914
Josh Bailey3f045a02012-03-24 08:35:20 -07002915 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2916
2917 while (1)
hassof390d2c2004-09-10 20:48:21 +00002918 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002919 list = list_new ();
2920 lsp_build_list_ssn (circuit, num_lsps, list,
2921 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002922
Josh Bailey3f045a02012-03-24 08:35:20 -07002923 if (listcount (list) == 0)
2924 {
2925 list_delete (list);
2926 return ISIS_OK;
2927 }
jardineb5d44e2003-12-23 08:09:43 +00002928
Josh Bailey3f045a02012-03-24 08:35:20 -07002929 retval = build_psnp (level, circuit, list);
2930 if (retval != ISIS_OK)
2931 {
2932 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2933 circuit->area->area_tag, level, circuit->interface->name);
2934 list_delete (list);
2935 return retval;
2936 }
jardineb5d44e2003-12-23 08:09:43 +00002937
Josh Bailey3f045a02012-03-24 08:35:20 -07002938 if (isis->debugs & DEBUG_SNP_PACKETS)
2939 {
2940 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2941 circuit->area->area_tag, level,
2942 circuit->interface->name,
2943 stream_get_endp (circuit->snd_stream));
2944 if (isis->debugs & DEBUG_PACKET_DUMP)
2945 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2946 stream_get_endp (circuit->snd_stream));
2947 }
jardineb5d44e2003-12-23 08:09:43 +00002948
Josh Bailey3f045a02012-03-24 08:35:20 -07002949 retval = circuit->tx (circuit, level);
2950 if (retval != ISIS_OK)
2951 {
2952 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2953 circuit->area->area_tag, level,
2954 circuit->interface->name);
2955 list_delete (list);
2956 return retval;
2957 }
jardineb5d44e2003-12-23 08:09:43 +00002958
Josh Bailey3f045a02012-03-24 08:35:20 -07002959 /*
2960 * sending succeeded, we can clear SSN flags of this circuit
2961 * for the LSPs in list
2962 */
2963 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2964 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2965 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002966 }
jardineb5d44e2003-12-23 08:09:43 +00002967
2968 return retval;
2969}
2970
2971int
2972send_l1_psnp (struct thread *thread)
2973{
2974
2975 struct isis_circuit *circuit;
2976 int retval = ISIS_OK;
2977
2978 circuit = THREAD_ARG (thread);
2979 assert (circuit);
2980
2981 circuit->t_send_psnp[0] = NULL;
2982
2983 send_psnp (1, circuit);
2984 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002985 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2986 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002987
2988 return retval;
2989}
2990
2991/*
2992 * 7.3.15.4 action on expiration of partial SNP interval
2993 * level 2
2994 */
2995int
2996send_l2_psnp (struct thread *thread)
2997{
jardineb5d44e2003-12-23 08:09:43 +00002998 struct isis_circuit *circuit;
2999 int retval = ISIS_OK;
3000
3001 circuit = THREAD_ARG (thread);
3002 assert (circuit);
3003
3004 circuit->t_send_psnp[1] = NULL;
3005
3006 send_psnp (2, circuit);
3007
3008 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003009 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3010 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003011
3012 return retval;
3013}
3014
jardineb5d44e2003-12-23 08:09:43 +00003015/*
3016 * ISO 10589 - 7.3.14.3
3017 */
3018int
3019send_lsp (struct thread *thread)
3020{
3021 struct isis_circuit *circuit;
3022 struct isis_lsp *lsp;
3023 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003024 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003025
3026 circuit = THREAD_ARG (thread);
3027 assert (circuit);
3028
Josh Bailey3f045a02012-03-24 08:35:20 -07003029 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3030 {
3031 return retval;
3032 }
3033
3034 lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
3035
3036 /*
3037 * Do not send if levels do not match
3038 */
3039 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003040 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003041 list_delete_node (circuit->lsp_queue, node);
3042 return retval;
hassof390d2c2004-09-10 20:48:21 +00003043 }
jardineb5d44e2003-12-23 08:09:43 +00003044
Josh Bailey3f045a02012-03-24 08:35:20 -07003045 /*
3046 * Do not send if we do not have adjacencies in state up on the circuit
3047 */
3048 if (circuit->upadjcount[lsp->level - 1] == 0)
3049 {
3050 list_delete_node (circuit->lsp_queue, node);
3051 return retval;
3052 }
3053
3054 /* copy our lsp to the send buffer */
3055 stream_copy (circuit->snd_stream, lsp->pdu);
3056
3057 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3058 {
3059 zlog_debug
3060 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3061 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3062 rawlspid_print (lsp->lsp_header->lsp_id),
3063 ntohl (lsp->lsp_header->seq_num),
3064 ntohs (lsp->lsp_header->checksum),
3065 ntohs (lsp->lsp_header->rem_lifetime),
3066 circuit->interface->name);
3067 if (isis->debugs & DEBUG_PACKET_DUMP)
3068 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3069 stream_get_endp (circuit->snd_stream));
3070 }
3071
3072 retval = circuit->tx (circuit, lsp->level);
3073 if (retval != ISIS_OK)
3074 {
3075 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3076 circuit->area->area_tag, lsp->level,
3077 circuit->interface->name);
3078 return retval;
3079 }
3080
3081 /*
3082 * If the sending succeeded, we can del the lsp from circuits
3083 * lsp_queue
3084 */
3085 list_delete_node (circuit->lsp_queue, node);
3086
3087 /* Set the last-cleared time if the queue is empty. */
3088 /* TODO: Is is possible that new lsps keep being added to the queue
3089 * that the queue is never empty? */
3090 if (list_isempty (circuit->lsp_queue))
3091 circuit->lsp_queue_last_cleared = time (NULL);
3092
3093 /*
3094 * On broadcast circuits also the SRMflag can be cleared
3095 */
3096 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3097 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3098
jardineb5d44e2003-12-23 08:09:43 +00003099 return retval;
hassof390d2c2004-09-10 20:48:21 +00003100}
jardineb5d44e2003-12-23 08:09:43 +00003101
3102int
hassof390d2c2004-09-10 20:48:21 +00003103ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3104 int level)
jardineb5d44e2003-12-23 08:09:43 +00003105{
3106 unsigned long lenp;
3107 int retval;
3108 u_int16_t length;
3109 struct isis_fixed_hdr fixed_hdr;
3110
3111 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003112 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003113 else
3114 stream_reset (circuit->snd_stream);
3115
Josh Bailey3f045a02012-03-24 08:35:20 -07003116 // fill_llc_hdr (stream);
3117 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003118 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3119 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003120 else
hassof390d2c2004-09-10 20:48:21 +00003121 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3122 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003123
3124
paul9985f832005-02-09 15:51:56 +00003125 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003126 stream_putw (circuit->snd_stream, 0); /* PDU length */
3127 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003128 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003129 stream_putc (circuit->snd_stream, 9); /* code */
3130 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003131
hassof390d2c2004-09-10 20:48:21 +00003132 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3133 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3134 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3135 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003136
paul9985f832005-02-09 15:51:56 +00003137 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003138 /* Update PDU length */
3139 stream_putw_at (circuit->snd_stream, lenp, length);
3140
3141 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003142 if (retval != ISIS_OK)
3143 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3144 circuit->area->area_tag, level,
3145 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003146
3147 return retval;
3148}