blob: 083ddc72b09406fe7d7cd5a0ee205ba7dc8a6e12 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_pdu.c
3 * PDU processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "memory.h"
27#include "thread.h"
28#include "linklist.h"
29#include "log.h"
30#include "stream.h"
31#include "vty.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070032#include "hash.h"
jardineb5d44e2003-12-23 08:09:43 +000033#include "prefix.h"
34#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010035#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070036#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000037
38#include "isisd/dict.h"
39#include "isisd/include-netbsd/iso.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_adjacency.h"
44#include "isisd/isis_circuit.h"
45#include "isisd/isis_network.h"
46#include "isisd/isis_misc.h"
47#include "isisd/isis_dr.h"
jardineb5d44e2003-12-23 08:09:43 +000048#include "isisd/isis_tlv.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_lsp.h"
52#include "isisd/isis_pdu.h"
53#include "isisd/iso_checksum.h"
54#include "isisd/isis_csm.h"
55#include "isisd/isis_events.h"
56
jardineb5d44e2003-12-23 08:09:43 +000057#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000058#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000059
60#ifndef PNBBY
61#define PNBBY 8
62#endif /* PNBBY */
63
64/* Utility mask array. */
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -070065static u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000066 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
67};
68
69/*
70 * HELPER FUNCS
71 */
72
73/*
74 * Compares two sets of area addresses
75 */
hassof390d2c2004-09-10 20:48:21 +000076static int
jardineb5d44e2003-12-23 08:09:43 +000077area_match (struct list *left, struct list *right)
78{
79 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000080 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000081
hasso3fdb2dd2005-09-28 18:45:54 +000082 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000083 {
hasso3fdb2dd2005-09-28 18:45:54 +000084 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000085 {
86 if (addr1->addr_len == addr2->addr_len &&
87 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
88 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000089 }
90 }
91
hassof390d2c2004-09-10 20:48:21 +000092 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000093}
94
95/*
96 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
97 * param ip1 the IS interface ip address structure
98 * param ip2 the IIH's ip address
99 * return 0 the IIH's IP is not in the IS's subnetwork
100 * 1 the IIH's IP is in the IS's subnetwork
101 */
hasso92365882005-01-18 13:53:33 +0000102static int
hassof390d2c2004-09-10 20:48:21 +0000103ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000104{
105 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000106 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000107 int len;
hassof390d2c2004-09-10 20:48:21 +0000108
109 addr1 = (u_char *) & ip1->prefix.s_addr;
110 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000111 len = ip1->prefixlen;
112
113 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000114 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000115
hasso53c997c2004-09-15 16:21:59 +0000116 while (offsetloop--)
117 if (addr1[offsetloop] != addr2[offsetloop])
118 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000119
hassof390d2c2004-09-10 20:48:21 +0000120 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000121 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
122 return 0;
hassof390d2c2004-09-10 20:48:21 +0000123
124 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000125}
126
jardineb5d44e2003-12-23 08:09:43 +0000127/*
128 * Compares two set of ip addresses
129 * param left the local interface's ip addresses
130 * param right the iih interface's ip address
131 * return 0 no match;
132 * 1 match;
133 */
hassof390d2c2004-09-10 20:48:21 +0000134static int
jardineb5d44e2003-12-23 08:09:43 +0000135ip_match (struct list *left, struct list *right)
136{
137 struct prefix_ipv4 *ip1;
138 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000139 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000140
hassoe082ac12004-09-27 18:13:57 +0000141 if ((left == NULL) || (right == NULL))
142 return 0;
143
hasso3fdb2dd2005-09-28 18:45:54 +0000144 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000145 {
hasso3fdb2dd2005-09-28 18:45:54 +0000146 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000147 {
148 if (ip_same_subnet (ip1, ip2))
149 {
150 return 1; /* match */
151 }
jardineb5d44e2003-12-23 08:09:43 +0000152 }
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 }
155 return 0;
156}
157
158/*
159 * Checks whether we should accept a PDU of given level
160 */
161static int
162accept_level (int level, int circuit_t)
163{
hassof390d2c2004-09-10 20:48:21 +0000164 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000165
166 return retval;
167}
168
Josh Bailey3f045a02012-03-24 08:35:20 -0700169/*
170 * Verify authentication information
171 * Support cleartext and HMAC MD5 authentication
172 */
173static int
174authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
175 struct stream *stream, uint32_t auth_tlv_offset)
jardineb5d44e2003-12-23 08:09:43 +0000176{
Josh Bailey3f045a02012-03-24 08:35:20 -0700177 unsigned char digest[ISIS_AUTH_MD5_SIZE];
178
179 /* Auth fail () - passwd type mismatch */
180 if (local->type != remote->type)
181 return ISIS_ERROR;
182
183 switch (local->type)
184 {
185 /* No authentication required */
186 case ISIS_PASSWD_TYPE_UNUSED:
187 break;
188
189 /* Cleartext (ISO 10589) */
hassof390d2c2004-09-10 20:48:21 +0000190 case ISIS_PASSWD_TYPE_CLEARTXT:
Josh Bailey3f045a02012-03-24 08:35:20 -0700191 /* Auth fail () - passwd len mismatch */
192 if (remote->len != local->len)
193 return ISIS_ERROR;
194 return memcmp (local->passwd, remote->passwd, local->len);
195
196 /* HMAC MD5 (RFC 3567) */
197 case ISIS_PASSWD_TYPE_HMAC_MD5:
198 /* Auth fail () - passwd len mismatch */
199 if (remote->len != ISIS_AUTH_MD5_SIZE)
200 return ISIS_ERROR;
201 /* Set the authentication value to 0 before the check */
202 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
203 ISIS_AUTH_MD5_SIZE);
204 /* Compute the digest */
205 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
206 (unsigned char *) &(local->passwd), local->len,
207 (caddr_t) &digest);
208 /* Copy back the authentication value after the check */
209 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
210 remote->passwd, ISIS_AUTH_MD5_SIZE);
211 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
212
hassof390d2c2004-09-10 20:48:21 +0000213 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700214 zlog_err ("Unsupported authentication type");
215 return ISIS_ERROR;
216 }
217
218 /* Authentication pass when no authentication is configured */
219 return ISIS_OK;
220}
221
222static int
223lsp_authentication_check (struct stream *stream, struct isis_area *area,
224 int level, struct isis_passwd *passwd)
225{
226 struct isis_link_state_hdr *hdr;
227 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700228 uint16_t checksum, rem_lifetime, pdu_len;
Josh Bailey3f045a02012-03-24 08:35:20 -0700229 struct tlvs tlvs;
230 int retval = ISIS_OK;
231
232 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700233 pdu_len = ntohs (hdr->pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700234 expected |= TLVFLAG_AUTH_INFO;
235 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
236 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700237 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
Josh Bailey3f045a02012-03-24 08:35:20 -0700238 &expected, &found, &tlvs, &auth_tlv_offset);
239
240 if (retval != ISIS_OK)
241 {
242 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
243 "cksum 0x%04x, lifetime %us, len %u",
244 area->area_tag, level, rawlspid_print (hdr->lsp_id),
245 ntohl (hdr->seq_num), ntohs (hdr->checksum),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700246 ntohs (hdr->rem_lifetime), pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700247 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
248 (isis->debugs & DEBUG_PACKET_DUMP))
249 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
250 return retval;
hassof390d2c2004-09-10 20:48:21 +0000251 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700252
253 if (!(found & TLVFLAG_AUTH_INFO))
254 {
255 zlog_err ("No authentication tlv in LSP");
256 return ISIS_ERROR;
257 }
258
259 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
260 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
261 {
262 zlog_err ("Unknown authentication type in LSP");
263 return ISIS_ERROR;
264 }
265
266 /*
267 * RFC 5304 set checksum and remaining lifetime to zero before
268 * verification and reset to old values after verification.
269 */
270 checksum = hdr->checksum;
271 rem_lifetime = hdr->rem_lifetime;
272 hdr->checksum = 0;
273 hdr->rem_lifetime = 0;
274 retval = authentication_check (&tlvs.auth_info, passwd, stream,
275 auth_tlv_offset);
276 hdr->checksum = checksum;
277 hdr->rem_lifetime = rem_lifetime;
278
279 return retval;
jardineb5d44e2003-12-23 08:09:43 +0000280}
281
282/*
283 * Processing helper functions
284 */
hasso92365882005-01-18 13:53:33 +0000285static void
Josh Bailey3f045a02012-03-24 08:35:20 -0700286del_addr (void *val)
287{
288 XFREE (MTYPE_ISIS_TMP, val);
289}
290
291static void
292tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
293{
294 struct listnode *node;
295 struct area_addr *area_addr, *malloced;
296
297 if (adj->area_addrs)
298 {
299 adj->area_addrs->del = del_addr;
300 list_delete (adj->area_addrs);
301 }
302 adj->area_addrs = list_new ();
303 if (tlvs->area_addrs)
304 {
305 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
306 {
307 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
308 memcpy (malloced, area_addr, sizeof (struct area_addr));
309 listnode_add (adj->area_addrs, malloced);
310 }
311 }
312}
313
David Lamparter655071f2012-05-08 13:32:53 +0200314static int
hassof390d2c2004-09-10 20:48:21 +0000315tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000316{
317 int i;
318 struct nlpids *tlv_nlpids;
319
hassof390d2c2004-09-10 20:48:21 +0000320 if (tlvs->nlpids)
321 {
jardineb5d44e2003-12-23 08:09:43 +0000322
hassof390d2c2004-09-10 20:48:21 +0000323 tlv_nlpids = tlvs->nlpids;
David Lamparter655071f2012-05-08 13:32:53 +0200324 if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
325 return 1;
jardineb5d44e2003-12-23 08:09:43 +0000326
hassof390d2c2004-09-10 20:48:21 +0000327 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000328
hassof390d2c2004-09-10 20:48:21 +0000329 for (i = 0; i < tlv_nlpids->count; i++)
330 {
331 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
332 }
jardineb5d44e2003-12-23 08:09:43 +0000333 }
David Lamparter655071f2012-05-08 13:32:53 +0200334 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000335}
336
hasso92365882005-01-18 13:53:33 +0000337static void
hassof390d2c2004-09-10 20:48:21 +0000338tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000339{
hasso3fdb2dd2005-09-28 18:45:54 +0000340 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000341 struct in_addr *ipv4_addr, *malloced;
342
hassof390d2c2004-09-10 20:48:21 +0000343 if (adj->ipv4_addrs)
344 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700345 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000346 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000347 }
hassof390d2c2004-09-10 20:48:21 +0000348 adj->ipv4_addrs = list_new ();
349 if (tlvs->ipv4_addrs)
350 {
hasso3fdb2dd2005-09-28 18:45:54 +0000351 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000352 {
353 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
354 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
355 listnode_add (adj->ipv4_addrs, malloced);
356 }
357 }
jardineb5d44e2003-12-23 08:09:43 +0000358}
359
360#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000361static void
hassof390d2c2004-09-10 20:48:21 +0000362tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000363{
hasso3fdb2dd2005-09-28 18:45:54 +0000364 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000365 struct in6_addr *ipv6_addr, *malloced;
366
hassof390d2c2004-09-10 20:48:21 +0000367 if (adj->ipv6_addrs)
368 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700369 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000370 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000371 }
hassof390d2c2004-09-10 20:48:21 +0000372 adj->ipv6_addrs = list_new ();
373 if (tlvs->ipv6_addrs)
374 {
hasso3fdb2dd2005-09-28 18:45:54 +0000375 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000376 {
377 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
378 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
379 listnode_add (adj->ipv6_addrs, malloced);
380 }
381 }
jardineb5d44e2003-12-23 08:09:43 +0000382
383}
384#endif /* HAVE_IPV6 */
385
jardineb5d44e2003-12-23 08:09:43 +0000386/*
387 * RECEIVE SIDE
388 */
389
390/*
391 * Process P2P IIH
392 * ISO - 10589
393 * Section 8.2.5 - Receiving point-to-point IIH PDUs
394 *
395 */
396static int
397process_p2p_hello (struct isis_circuit *circuit)
398{
399 int retval = ISIS_OK;
400 struct isis_p2p_hello_hdr *hdr;
401 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700402 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700403 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000404 struct tlvs tlvs;
405
Josh Bailey3f045a02012-03-24 08:35:20 -0700406 if (isis->debugs & DEBUG_ADJ_PACKETS)
407 {
408 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
409 circuit->area->area_tag, circuit->interface->name,
410 circuit_t2string (circuit->is_type), circuit->circuit_id);
411 if (isis->debugs & DEBUG_PACKET_DUMP)
412 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
413 stream_get_endp (circuit->rcv_stream));
414 }
415
416 if (circuit->circ_type != CIRCUIT_T_P2P)
417 {
418 zlog_warn ("p2p hello on non p2p circuit");
419 return ISIS_WARNING;
420 }
421
hassof390d2c2004-09-10 20:48:21 +0000422 if ((stream_get_endp (circuit->rcv_stream) -
423 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
424 {
425 zlog_warn ("Packet too short");
426 return ISIS_WARNING;
427 }
jardineb5d44e2003-12-23 08:09:43 +0000428
429 /* 8.2.5.1 PDU acceptance tests */
430
431 /* 8.2.5.1 a) external domain untrue */
432 /* FIXME: not useful at all? */
433
434 /* 8.2.5.1 b) ID Length mismatch */
435 /* checked at the handle_pdu */
436
437 /* 8.2.5.2 IIH PDU Processing */
438
439 /* 8.2.5.2 a) 1) Maximum Area Addresses */
440 /* Already checked, and can also be ommited */
441
442 /*
443 * Get the header
444 */
hassof390d2c2004-09-10 20:48:21 +0000445 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700446 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000447
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700448 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
449 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700450 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000451 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700452 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
453 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700454 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700455 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000456 }
jardineb5d44e2003-12-23 08:09:43 +0000457
jardineb5d44e2003-12-23 08:09:43 +0000458 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700459 * Set the stream endp to PDU length, ignoring additional padding
460 * introduced by transport chips.
461 */
462 if (pdu_len < stream_get_endp (circuit->rcv_stream))
463 stream_set_endp (circuit->rcv_stream, pdu_len);
464
465 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
466
467 /*
jardineb5d44e2003-12-23 08:09:43 +0000468 * Lets get the TLVS now
469 */
470 expected |= TLVFLAG_AREA_ADDRS;
471 expected |= TLVFLAG_AUTH_INFO;
472 expected |= TLVFLAG_NLPID;
473 expected |= TLVFLAG_IPV4_ADDR;
474 expected |= TLVFLAG_IPV6_ADDR;
475
Josh Bailey3f045a02012-03-24 08:35:20 -0700476 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000477 retval = parse_tlvs (circuit->area->area_tag,
478 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700479 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
480 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000481
hassof390d2c2004-09-10 20:48:21 +0000482 if (retval > ISIS_WARNING)
483 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700484 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000485 free_tlvs (&tlvs);
486 return retval;
487 };
jardineb5d44e2003-12-23 08:09:43 +0000488
Josh Bailey3f045a02012-03-24 08:35:20 -0700489 if (!(found & TLVFLAG_AREA_ADDRS))
490 {
491 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
492 free_tlvs (&tlvs);
493 return ISIS_WARNING;
494 }
495
jardineb5d44e2003-12-23 08:09:43 +0000496 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000497 if (circuit->passwd.type)
498 {
499 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700500 authentication_check (&tlvs.auth_info, &circuit->passwd,
501 circuit->rcv_stream, auth_tlv_offset))
502 {
503 isis_event_auth_failure (circuit->area->area_tag,
504 "P2P hello authentication failure",
505 hdr->source_id);
506 free_tlvs (&tlvs);
507 return ISIS_OK;
508 }
jardineb5d44e2003-12-23 08:09:43 +0000509 }
jardineb5d44e2003-12-23 08:09:43 +0000510
Josh Bailey3f045a02012-03-24 08:35:20 -0700511 /*
512 * check if it's own interface ip match iih ip addrs
513 */
514 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
515 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
516 {
517 zlog_warn ("ISIS-Adj: No usable IP interface addresses "
518 "in LAN IIH from %s\n", circuit->interface->name);
519 free_tlvs (&tlvs);
520 return ISIS_WARNING;
521 }
522
523 /*
524 * My interpertation of the ISO, if no adj exists we will create one for
525 * the circuit
526 */
527 adj = circuit->u.p2p.neighbor;
528 if (!adj || adj->level != hdr->circuit_t)
529 {
530 if (!adj)
531 {
532 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
533 if (adj == NULL)
534 return ISIS_ERROR;
535 }
536 else
537 {
538 adj->level = hdr->circuit_t;
539 }
540 circuit->u.p2p.neighbor = adj;
541 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
542 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
543 }
544
545 /* 8.2.6 Monitoring point-to-point adjacencies */
546 adj->hold_time = ntohs (hdr->hold_time);
547 adj->last_upd = time (NULL);
548
jardineb5d44e2003-12-23 08:09:43 +0000549 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700550 tlvs_to_adj_area_addrs (&tlvs, adj);
551
552 /* which protocol are spoken ??? */
553 if (found & TLVFLAG_NLPID)
David Lamparter655071f2012-05-08 13:32:53 +0200554 if (tlvs_to_adj_nlpids (&tlvs, adj))
555 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +0000556
557 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700558 if (found & TLVFLAG_IPV4_ADDR)
559 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000560
561#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700562 if (found & TLVFLAG_IPV6_ADDR)
563 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000564#endif /* HAVE_IPV6 */
565
566 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000567 THREAD_TIMER_OFF (adj->t_expire);
568 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
569 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000570
571 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000572 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
573 {
574 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
575 if (circuit->area->is_type == IS_LEVEL_1)
576 {
577 switch (hdr->circuit_t)
578 {
579 case IS_LEVEL_1:
580 case IS_LEVEL_1_AND_2:
581 if (adj->adj_state != ISIS_ADJ_UP)
582 {
583 /* (4) adj state up */
584 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
585 /* (5) adj usage level 1 */
586 adj->adj_usage = ISIS_ADJ_LEVEL1;
587 }
588 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
589 {
590 ; /* accept */
591 }
592 break;
593 case IS_LEVEL_2:
594 if (adj->adj_state != ISIS_ADJ_UP)
595 {
596 /* (7) reject - wrong system type event */
597 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700598 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000599 return ISIS_WARNING; /* Reject */
600 }
601 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
602 {
603 /* (6) down - wrong system */
604 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
605 }
606 break;
607 }
608 }
jardineb5d44e2003-12-23 08:09:43 +0000609
hassof390d2c2004-09-10 20:48:21 +0000610 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
611 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
612 {
613 switch (hdr->circuit_t)
614 {
615 case IS_LEVEL_1:
616 if (adj->adj_state != ISIS_ADJ_UP)
617 {
618 /* (6) adj state up */
619 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
620 /* (7) adj usage level 1 */
621 adj->adj_usage = ISIS_ADJ_LEVEL1;
622 }
623 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
624 {
625 ; /* accept */
626 }
627 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
628 (adj->adj_usage == ISIS_ADJ_LEVEL2))
629 {
630 /* (8) down - wrong system */
631 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
632 }
633 break;
634 case IS_LEVEL_2:
635 if (adj->adj_state != ISIS_ADJ_UP)
636 {
637 /* (6) adj state up */
638 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
639 /* (9) adj usage level 2 */
640 adj->adj_usage = ISIS_ADJ_LEVEL2;
641 }
642 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
643 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
644 {
645 /* (8) down - wrong system */
646 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
647 }
648 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
649 {
650 ; /* Accept */
651 }
652 break;
653 case IS_LEVEL_1_AND_2:
654 if (adj->adj_state != ISIS_ADJ_UP)
655 {
656 /* (6) adj state up */
657 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
658 /* (10) adj usage level 1 */
659 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
660 }
661 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
662 (adj->adj_usage == ISIS_ADJ_LEVEL2))
663 {
664 /* (8) down - wrong system */
665 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
666 }
667 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
668 {
669 ; /* Accept */
670 }
671 break;
672 }
673 }
jardineb5d44e2003-12-23 08:09:43 +0000674
hassof390d2c2004-09-10 20:48:21 +0000675 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
676 if (circuit->area->is_type == IS_LEVEL_2)
677 {
678 switch (hdr->circuit_t)
679 {
680 case IS_LEVEL_1:
681 if (adj->adj_state != ISIS_ADJ_UP)
682 {
683 /* (5) reject - wrong system type event */
684 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700685 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000686 return ISIS_WARNING; /* Reject */
687 }
688 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
689 (adj->adj_usage == ISIS_ADJ_LEVEL2))
690 {
691 /* (6) down - wrong system */
692 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
693 }
694 break;
695 case IS_LEVEL_1_AND_2:
696 case IS_LEVEL_2:
697 if (adj->adj_state != ISIS_ADJ_UP)
698 {
699 /* (7) adj state up */
700 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
701 /* (8) adj usage level 2 */
702 adj->adj_usage = ISIS_ADJ_LEVEL2;
703 }
704 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
705 {
706 /* (6) down - wrong system */
707 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
708 }
709 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
710 {
711 ; /* Accept */
712 }
713 break;
714 }
715 }
jardineb5d44e2003-12-23 08:09:43 +0000716 }
jardineb5d44e2003-12-23 08:09:43 +0000717 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700718 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000719 {
hassof390d2c2004-09-10 20:48:21 +0000720 if (circuit->area->is_type == IS_LEVEL_1)
721 {
722 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
723 if (adj->adj_state != ISIS_ADJ_UP)
724 {
725 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
726 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
727 }
728 else
729 {
730 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
731 "Down - Area Mismatch");
732 }
733 }
734 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
735 else
736 {
737 switch (hdr->circuit_t)
738 {
739 case IS_LEVEL_1:
740 if (adj->adj_state != ISIS_ADJ_UP)
741 {
742 /* (6) reject - Area Mismatch event */
743 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700744 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000745 return ISIS_WARNING; /* Reject */
746 }
747 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
748 {
749 /* (7) down - area mismatch */
750 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000751
hassof390d2c2004-09-10 20:48:21 +0000752 }
753 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
754 (adj->adj_usage == ISIS_ADJ_LEVEL2))
755 {
756 /* (7) down - wrong system */
757 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
758 }
759 break;
760 case IS_LEVEL_1_AND_2:
761 case IS_LEVEL_2:
762 if (adj->adj_state != ISIS_ADJ_UP)
763 {
764 /* (8) adj state up */
765 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
766 /* (9) adj usage level 2 */
767 adj->adj_usage = ISIS_ADJ_LEVEL2;
768 }
769 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
770 {
771 /* (7) down - wrong system */
772 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
773 }
774 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
775 {
776 if (hdr->circuit_t == IS_LEVEL_2)
777 {
778 /* (7) down - wrong system */
779 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
780 "Wrong System");
781 }
782 else
783 {
784 /* (7) down - area mismatch */
785 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
786 "Area Mismatch");
787 }
788 }
789 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
790 {
791 ; /* Accept */
792 }
793 break;
794 }
795 }
jardineb5d44e2003-12-23 08:09:43 +0000796 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700797 else
798 {
799 /* down - area mismatch */
800 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
801 }
jardineb5d44e2003-12-23 08:09:43 +0000802 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
803 /* FIXME - Missing parts */
804
jardineb5d44e2003-12-23 08:09:43 +0000805 /* some of my own understanding of the ISO, why the heck does
806 * it not say what should I change the system_type to...
807 */
hassof390d2c2004-09-10 20:48:21 +0000808 switch (adj->adj_usage)
809 {
jardineb5d44e2003-12-23 08:09:43 +0000810 case ISIS_ADJ_LEVEL1:
811 adj->sys_type = ISIS_SYSTYPE_L1_IS;
812 break;
813 case ISIS_ADJ_LEVEL2:
814 adj->sys_type = ISIS_SYSTYPE_L2_IS;
815 break;
816 case ISIS_ADJ_LEVEL1AND2:
817 adj->sys_type = ISIS_SYSTYPE_L2_IS;
818 break;
819 case ISIS_ADJ_NONE:
820 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
821 break;
hassof390d2c2004-09-10 20:48:21 +0000822 }
jardineb5d44e2003-12-23 08:09:43 +0000823
824 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700825
826 if (isis->debugs & DEBUG_ADJ_PACKETS)
827 {
828 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
829 " cir id %02d, length %d",
830 circuit->area->area_tag, circuit->interface->name,
831 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700832 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700833 }
jardineb5d44e2003-12-23 08:09:43 +0000834
835 free_tlvs (&tlvs);
836
837 return retval;
838}
839
jardineb5d44e2003-12-23 08:09:43 +0000840/*
841 * Process IS-IS LAN Level 1/2 Hello PDU
842 */
hassof390d2c2004-09-10 20:48:21 +0000843static int
844process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000845{
846 int retval = ISIS_OK;
847 struct isis_lan_hello_hdr hdr;
848 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700849 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000850 struct tlvs tlvs;
851 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000852 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000853
Josh Bailey3f045a02012-03-24 08:35:20 -0700854 if (isis->debugs & DEBUG_ADJ_PACKETS)
855 {
856 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
857 "cirID %u",
858 circuit->area->area_tag, level, circuit->interface->name,
859 circuit_t2string (circuit->is_type), circuit->circuit_id);
860 if (isis->debugs & DEBUG_PACKET_DUMP)
861 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
862 stream_get_endp (circuit->rcv_stream));
863 }
864
865 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
866 {
867 zlog_warn ("lan hello on non broadcast circuit");
868 return ISIS_WARNING;
869 }
870
hassof390d2c2004-09-10 20:48:21 +0000871 if ((stream_get_endp (circuit->rcv_stream) -
872 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
873 {
874 zlog_warn ("Packet too short");
875 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000876 }
hassof390d2c2004-09-10 20:48:21 +0000877
878 if (circuit->ext_domain)
879 {
hasso529d65b2004-12-24 00:14:50 +0000880 zlog_debug ("level %d LAN Hello received over circuit with "
881 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000882 return ISIS_WARNING;
883 }
884
Josh Bailey3f045a02012-03-24 08:35:20 -0700885 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000886 {
887 if (isis->debugs & DEBUG_ADJ_PACKETS)
888 {
hasso529d65b2004-12-24 00:14:50 +0000889 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
890 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000891 }
892 return ISIS_WARNING;
893 }
jardineb5d44e2003-12-23 08:09:43 +0000894
895#if 0
896 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000897 if (!accept_level (level, circuit->area->is_type))
898 {
899 if (isis->debugs & DEBUG_ADJ_PACKETS)
900 {
hasso529d65b2004-12-24 00:14:50 +0000901 zlog_debug ("ISIS-Adj (%s): is type mismatch",
902 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000903 }
904 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000905 }
jardineb5d44e2003-12-23 08:09:43 +0000906#endif
907 /*
908 * Fill the header
909 */
910 hdr.circuit_t = stream_getc (circuit->rcv_stream);
911 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
912 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000913 hdr.pdu_len = stream_getw (circuit->rcv_stream);
914 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000915 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
916
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700917 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
918 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700919 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000920 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700921 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
922 "invalid pdu length %d",
923 circuit->area->area_tag, circuit->interface->name,
924 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700925 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700926 }
927
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700928 /*
929 * Set the stream endp to PDU length, ignoring additional padding
930 * introduced by transport chips.
931 */
932 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
933 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
934
Josh Bailey3f045a02012-03-24 08:35:20 -0700935 if (hdr.circuit_t != IS_LEVEL_1 &&
936 hdr.circuit_t != IS_LEVEL_2 &&
937 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
938 (level & hdr.circuit_t) == 0)
939 {
940 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
941 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000942 return ISIS_ERROR;
943 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700944
jardineb5d44e2003-12-23 08:09:43 +0000945 /*
946 * Then get the tlvs
947 */
948 expected |= TLVFLAG_AUTH_INFO;
949 expected |= TLVFLAG_AREA_ADDRS;
950 expected |= TLVFLAG_LAN_NEIGHS;
951 expected |= TLVFLAG_NLPID;
952 expected |= TLVFLAG_IPV4_ADDR;
953 expected |= TLVFLAG_IPV6_ADDR;
954
Josh Bailey3f045a02012-03-24 08:35:20 -0700955 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000956 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -0700957 STREAM_PNT (circuit->rcv_stream),
958 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
959 &expected, &found, &tlvs,
960 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000961
hassof390d2c2004-09-10 20:48:21 +0000962 if (retval > ISIS_WARNING)
963 {
964 zlog_warn ("parse_tlvs() failed");
965 goto out;
966 }
jardineb5d44e2003-12-23 08:09:43 +0000967
hassof390d2c2004-09-10 20:48:21 +0000968 if (!(found & TLVFLAG_AREA_ADDRS))
969 {
970 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
971 level);
jardineb5d44e2003-12-23 08:09:43 +0000972 retval = ISIS_WARNING;
973 goto out;
974 }
hassof390d2c2004-09-10 20:48:21 +0000975
Josh Bailey3f045a02012-03-24 08:35:20 -0700976 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +0000977 if (circuit->passwd.type)
978 {
979 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700980 authentication_check (&tlvs.auth_info, &circuit->passwd,
981 circuit->rcv_stream, auth_tlv_offset))
982 {
983 isis_event_auth_failure (circuit->area->area_tag,
984 "LAN hello authentication failure",
985 hdr.source_id);
986 retval = ISIS_WARNING;
987 goto out;
988 }
hassof390d2c2004-09-10 20:48:21 +0000989 }
jardineb5d44e2003-12-23 08:09:43 +0000990
David Lamparter19f78ce2012-11-27 01:10:25 +0000991 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
992 {
993 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
994 circuit->area->area_tag, circuit->interface->name);
995 return ISIS_WARNING;
996 }
997
jardineb5d44e2003-12-23 08:09:43 +0000998 /*
999 * Accept the level 1 adjacency only if a match between local and
1000 * remote area addresses is found
1001 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001002 if (listcount (circuit->area->area_addrs) == 0 ||
1003 (level == IS_LEVEL_1 &&
1004 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +00001005 {
1006 if (isis->debugs & DEBUG_ADJ_PACKETS)
1007 {
hasso529d65b2004-12-24 00:14:50 +00001008 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1009 circuit->area->area_tag, level,
1010 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001011 }
1012 retval = ISIS_OK;
1013 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001014 }
jardineb5d44e2003-12-23 08:09:43 +00001015
1016 /*
1017 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001018 */
1019 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1020 {
hasso529d65b2004-12-24 00:14:50 +00001021 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1022 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001023
hassof390d2c2004-09-10 20:48:21 +00001024 retval = ISIS_OK;
1025 goto out;
1026 }
jardineb5d44e2003-12-23 08:09:43 +00001027
1028 /*
1029 * check if it's own interface ip match iih ip addrs
1030 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001031 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
1032 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
hassof390d2c2004-09-10 20:48:21 +00001033 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001034 zlog_debug ("ISIS-Adj: No usable IP interface addresses "
1035 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001036 retval = ISIS_WARNING;
1037 goto out;
1038 }
jardineb5d44e2003-12-23 08:09:43 +00001039
1040 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001041 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1042 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001043 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001044 if (!adj)
1045 {
1046 /*
1047 * Do as in 8.4.2.5
1048 */
1049 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1050 if (adj == NULL)
1051 {
1052 retval = ISIS_ERROR;
1053 goto out;
1054 }
1055 }
1056 else
1057 {
1058 if (ssnpa) {
1059 memcpy (adj->snpa, ssnpa, 6);
1060 } else {
1061 memset (adj->snpa, ' ', 6);
1062 }
1063 adj->level = level;
1064 }
hassof390d2c2004-09-10 20:48:21 +00001065 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001066
Josh Bailey3f045a02012-03-24 08:35:20 -07001067 if (level == IS_LEVEL_1)
1068 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001069 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001070 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001071 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1072 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001073 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001074 }
jardineb5d44e2003-12-23 08:09:43 +00001075
hassoa211d652004-09-20 14:55:29 +00001076 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1077 switch (level)
1078 {
1079 case 1:
1080 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1081 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001082 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001083 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1084 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001085 }
1086 break;
1087 case 2:
1088 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1089 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001090 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001091 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1092 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001093 }
1094 break;
1095 }
jardineb5d44e2003-12-23 08:09:43 +00001096
1097 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001098 adj->last_upd = time (NULL);
1099 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001100
1101 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1102
Josh Bailey3f045a02012-03-24 08:35:20 -07001103 tlvs_to_adj_area_addrs (&tlvs, adj);
1104
jardineb5d44e2003-12-23 08:09:43 +00001105 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +00001106 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +00001107 tlvs_to_adj_nlpids (&tlvs, adj);
1108
1109 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001110 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001111 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1112
1113#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001114 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001115 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1116#endif /* HAVE_IPV6 */
1117
1118 adj->circuit_t = hdr.circuit_t;
1119
1120 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001121 THREAD_TIMER_OFF (adj->t_expire);
1122 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001123 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001124
1125 /*
1126 * If the snpa for this circuit is found from LAN Neighbours TLV
1127 * we have two-way communication -> adjacency can be put to state "up"
1128 */
1129
hassof390d2c2004-09-10 20:48:21 +00001130 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001131 {
1132 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001133 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001134 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1135 {
1136 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1137 {
1138 isis_adj_state_change (adj, ISIS_ADJ_UP,
1139 "own SNPA found in LAN Neighbours TLV");
1140 }
1141 }
jardineb5d44e2003-12-23 08:09:43 +00001142 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001143 else
1144 {
1145 int found = 0;
1146 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1147 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1148 {
1149 found = 1;
1150 break;
1151 }
1152 if (found == 0)
1153 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1154 "own SNPA not found in LAN Neighbours TLV");
1155 }
1156 }
1157 else if (adj->adj_state == ISIS_ADJ_UP)
1158 {
1159 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1160 "no LAN Neighbours TLV found");
1161 }
jardineb5d44e2003-12-23 08:09:43 +00001162
hassof390d2c2004-09-10 20:48:21 +00001163out:
hassof390d2c2004-09-10 20:48:21 +00001164 if (isis->debugs & DEBUG_ADJ_PACKETS)
1165 {
hasso529d65b2004-12-24 00:14:50 +00001166 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
1167 "cirID %u, length %ld",
1168 circuit->area->area_tag,
1169 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001170 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001171 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001172 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001173 }
jardineb5d44e2003-12-23 08:09:43 +00001174
1175 free_tlvs (&tlvs);
1176
1177 return retval;
1178}
1179
1180/*
1181 * Process Level 1/2 Link State
1182 * ISO - 10589
1183 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001184 */
1185static int
1186process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001187{
1188 struct isis_link_state_hdr *hdr;
1189 struct isis_adjacency *adj = NULL;
1190 struct isis_lsp *lsp, *lsp0 = NULL;
1191 int retval = ISIS_OK, comp = 0;
1192 u_char lspid[ISIS_SYS_ID_LEN + 2];
1193 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001194 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001195
Josh Bailey3f045a02012-03-24 08:35:20 -07001196 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1197 {
1198 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1199 circuit->area->area_tag, level, circuit->interface->name,
1200 circuit_t2string (circuit->is_type), circuit->circuit_id);
1201 if (isis->debugs & DEBUG_PACKET_DUMP)
1202 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1203 stream_get_endp (circuit->rcv_stream));
1204 }
1205
hassof390d2c2004-09-10 20:48:21 +00001206 if ((stream_get_endp (circuit->rcv_stream) -
1207 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1208 {
1209 zlog_warn ("Packet too short");
1210 return ISIS_WARNING;
1211 }
jardineb5d44e2003-12-23 08:09:43 +00001212
1213 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001214 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001215 pdu_len = ntohs (hdr->pdu_len);
1216
1217 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001218 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001219 pdu_len > ISO_MTU(circuit) ||
1220 pdu_len > stream_get_endp (circuit->rcv_stream))
1221 {
1222 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1223 circuit->area->area_tag,
1224 rawlspid_print (hdr->lsp_id), pdu_len);
1225
1226 return ISIS_WARNING;
1227 }
1228
1229 /*
1230 * Set the stream endp to PDU length, ignoring additional padding
1231 * introduced by transport chips.
1232 */
1233 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1234 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001235
hassof390d2c2004-09-10 20:48:21 +00001236 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1237 {
hasso529d65b2004-12-24 00:14:50 +00001238 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001239 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001240 circuit->area->area_tag,
1241 level,
1242 rawlspid_print (hdr->lsp_id),
1243 ntohl (hdr->seq_num),
1244 ntohs (hdr->checksum),
1245 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001246 pdu_len,
paul15935e92005-05-03 09:27:23 +00001247 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001248 }
jardineb5d44e2003-12-23 08:09:43 +00001249
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001250 /* lsp is_type check */
1251 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1252 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001253 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001254 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001255 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001256 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1257 /* continue as per RFC1122 Be liberal in what you accept, and
1258 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001259 }
jardineb5d44e2003-12-23 08:09:43 +00001260
1261 /* Checksum sanity check - FIXME: move to correct place */
1262 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001263 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001264 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001265 {
hasso529d65b2004-12-24 00:14:50 +00001266 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1267 circuit->area->area_tag,
1268 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001269
hassof390d2c2004-09-10 20:48:21 +00001270 return ISIS_WARNING;
1271 }
jardineb5d44e2003-12-23 08:09:43 +00001272
1273 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001274 if (circuit->ext_domain)
1275 {
hasso529d65b2004-12-24 00:14:50 +00001276 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001277 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1278 "externalDomain = true", circuit->area->area_tag,
1279 rawlspid_print (hdr->lsp_id), level);
jardineb5d44e2003-12-23 08:09:43 +00001280
hassof390d2c2004-09-10 20:48:21 +00001281 return ISIS_WARNING;
1282 }
jardineb5d44e2003-12-23 08:09:43 +00001283
1284 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001285 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001286 {
hasso529d65b2004-12-24 00:14:50 +00001287 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1288 " type %s",
1289 circuit->area->area_tag,
1290 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001291 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001292
hassof390d2c2004-09-10 20:48:21 +00001293 return ISIS_WARNING;
1294 }
jardineb5d44e2003-12-23 08:09:43 +00001295
1296 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1297
1298 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1299
1300 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001301 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1302 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001303 if (passwd->type)
1304 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001305 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1306 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001307 {
1308 isis_event_auth_failure (circuit->area->area_tag,
1309 "LSP authentication failure", hdr->lsp_id);
1310 return ISIS_WARNING;
1311 }
jardineb5d44e2003-12-23 08:09:43 +00001312 }
jardineb5d44e2003-12-23 08:09:43 +00001313 /* Find the LSP in our database and compare it to this Link State header */
1314 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1315 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001316 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1317 hdr->checksum, hdr->rem_lifetime);
1318 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001319#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001320 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001321#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001322 ))
jardineb5d44e2003-12-23 08:09:43 +00001323 goto dontcheckadj;
1324
1325 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1326 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001327
hassof390d2c2004-09-10 20:48:21 +00001328 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1329 {
1330 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1331 if (!adj)
1332 {
hasso529d65b2004-12-24 00:14:50 +00001333 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1334 "lifetime %us on %s",
1335 circuit->area->area_tag,
1336 rawlspid_print (hdr->lsp_id),
1337 ntohl (hdr->seq_num),
1338 ntohs (hdr->checksum),
1339 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001340 return ISIS_WARNING; /* Silently discard */
1341 }
jardineb5d44e2003-12-23 08:09:43 +00001342 }
jardineb5d44e2003-12-23 08:09:43 +00001343 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001344 else
1345 {
1346 /* If no adj, or no sharing of level */
1347 if (!circuit->u.p2p.neighbor)
1348 {
1349 return ISIS_OK; /* Silently discard */
1350 }
1351 else
1352 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001353 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001354 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001355 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001356 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1357 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001358 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001359 }
jardineb5d44e2003-12-23 08:09:43 +00001360 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001361
hassof390d2c2004-09-10 20:48:21 +00001362dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001363 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1364
1365 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1366
hassof390d2c2004-09-10 20:48:21 +00001367 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001368
hassof390d2c2004-09-10 20:48:21 +00001369 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1370 if (hdr->rem_lifetime == 0)
1371 {
1372 if (!lsp)
1373 {
1374 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1375 /* only needed on explicit update, eg - p2p */
1376 if (circuit->circ_type == CIRCUIT_T_P2P)
1377 ack_lsp (hdr, circuit, level);
1378 return retval; /* FIXME: do we need a purge? */
1379 }
1380 else
1381 {
1382 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1383 {
1384 /* LSP by some other system -> do 7.3.16.4 b) */
1385 /* 7.3.16.4 b) 1) */
1386 if (comp == LSP_NEWER)
1387 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001388 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001389 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001390 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001391 /* iii */
1392 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1393 /* v */
1394 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1395 /* iv */
1396 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1397 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001398
hassof390d2c2004-09-10 20:48:21 +00001399 } /* 7.3.16.4 b) 2) */
1400 else if (comp == LSP_EQUAL)
1401 {
1402 /* i */
1403 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1404 /* ii */
1405 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1406 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1407 } /* 7.3.16.4 b) 3) */
1408 else
1409 {
1410 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1411 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1412 }
1413 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001414 else if (lsp->lsp_header->rem_lifetime != 0)
1415 {
1416 /* our own LSP -> 7.3.16.4 c) */
1417 if (comp == LSP_NEWER)
1418 {
1419 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1420 lsp_set_all_srmflags (lsp);
1421 }
1422 else
1423 {
1424 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1425 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1426 }
1427 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1428 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1429 "seq 0x%08x", circuit->area->area_tag,
1430 rawlspid_print (hdr->lsp_id),
1431 ntohl (lsp->lsp_header->seq_num));
1432 }
hassof390d2c2004-09-10 20:48:21 +00001433 }
1434 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001435 }
jardineb5d44e2003-12-23 08:09:43 +00001436 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1437 * purge */
hassof390d2c2004-09-10 20:48:21 +00001438 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1439 {
1440 if (!lsp)
1441 {
1442 /* 7.3.16.4: initiate a purge */
1443 lsp_purge_non_exist (hdr, circuit->area);
1444 return ISIS_OK;
1445 }
1446 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1447
1448 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1449 * has information that the current sequence number for source S is
1450 * "greater" than that held by S, ... */
1451
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001452 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001453 {
1454 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001455 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001456 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1457 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1458 "0x%08x", circuit->area->area_tag,
1459 rawlspid_print (hdr->lsp_id),
1460 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001461 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001462 /* If the received LSP is older or equal,
1463 * resend the LSP which will act as ACK */
1464 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001465 }
hassof390d2c2004-09-10 20:48:21 +00001466 else
1467 {
1468 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001469
hassof390d2c2004-09-10 20:48:21 +00001470 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1471 if ((!lsp || comp == LSP_NEWER))
1472 {
hassof390d2c2004-09-10 20:48:21 +00001473 /*
1474 * If this lsp is a frag, need to see if we have zero lsp present
1475 */
1476 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1477 {
1478 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1479 LSP_FRAGMENT (lspid) = 0;
1480 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1481 if (!lsp0)
1482 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001483 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001484 return ISIS_OK;
1485 }
1486 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001487 /* i */
1488 if (!lsp)
1489 {
1490 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001491 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001492 circuit->area, level);
1493 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1494 }
1495 else /* exists, so we overwrite */
1496 {
1497 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1498 }
hassof390d2c2004-09-10 20:48:21 +00001499 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001500 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001501 /* iii */
1502 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001503
hassof390d2c2004-09-10 20:48:21 +00001504 /* iv */
1505 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1506 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1507 /* FIXME: v) */
1508 }
1509 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1510 else if (comp == LSP_EQUAL)
1511 {
1512 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001513 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001514 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001515 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001516 }
1517 /* 7.3.15.1 e) 3) LSP older than the one in db */
1518 else
1519 {
1520 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1521 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1522 }
jardineb5d44e2003-12-23 08:09:43 +00001523 }
jardineb5d44e2003-12-23 08:09:43 +00001524 return retval;
1525}
1526
1527/*
1528 * Process Sequence Numbers
1529 * ISO - 10589
1530 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1531 */
1532
hasso92365882005-01-18 13:53:33 +00001533static int
hassof390d2c2004-09-10 20:48:21 +00001534process_snp (int snp_type, int level, struct isis_circuit *circuit,
1535 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001536{
1537 int retval = ISIS_OK;
1538 int cmp, own_lsp;
1539 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001540 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001541 struct isis_adjacency *adj;
1542 struct isis_complete_seqnum_hdr *chdr = NULL;
1543 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001544 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001545 struct isis_lsp *lsp;
1546 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001547 struct listnode *node, *nnode;
1548 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001549 struct tlvs tlvs;
1550 struct list *lsp_list = NULL;
1551 struct isis_passwd *passwd;
1552
hassof390d2c2004-09-10 20:48:21 +00001553 if (snp_type == ISIS_SNP_CSNP_FLAG)
1554 {
1555 /* getting the header info */
1556 typechar = 'C';
1557 chdr =
1558 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001559 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1560 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001561 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001562 pdu_len > ISO_MTU(circuit) ||
1563 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001564 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001565 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1566 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001567 }
jardineb5d44e2003-12-23 08:09:43 +00001568 }
hassof390d2c2004-09-10 20:48:21 +00001569 else
1570 {
1571 typechar = 'P';
1572 phdr =
1573 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001574 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1575 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001576 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001577 pdu_len > ISO_MTU(circuit) ||
1578 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001579 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001580 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1581 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001582 }
jardineb5d44e2003-12-23 08:09:43 +00001583 }
jardineb5d44e2003-12-23 08:09:43 +00001584
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001585 /*
1586 * Set the stream endp to PDU length, ignoring additional padding
1587 * introduced by transport chips.
1588 */
1589 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1590 stream_set_endp (circuit->rcv_stream, pdu_len);
1591
jardineb5d44e2003-12-23 08:09:43 +00001592 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001593 if (circuit->ext_domain)
1594 {
jardineb5d44e2003-12-23 08:09:43 +00001595
hasso529d65b2004-12-24 00:14:50 +00001596 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1597 "skipping: circuit externalDomain = true",
1598 circuit->area->area_tag,
1599 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001600
1601 return ISIS_OK;
1602 }
hassof390d2c2004-09-10 20:48:21 +00001603
1604 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001605 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001606 {
1607
hasso529d65b2004-12-24 00:14:50 +00001608 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1609 "skipping: circuit type %s does not match level %d",
1610 circuit->area->area_tag,
1611 level,
1612 typechar,
1613 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001614 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001615
1616 return ISIS_OK;
1617 }
1618
1619 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1620 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001621 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1622 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001623 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001624 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1625 "skipping: we are not the DIS",
1626 circuit->area->area_tag,
1627 level,
1628 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001629
Josh Bailey3f045a02012-03-24 08:35:20 -07001630 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001631 }
jardineb5d44e2003-12-23 08:09:43 +00001632
1633 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1634
1635 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1636 * - already checked */
1637
1638 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1639 /* for broadcast circuits, snpa should be compared */
1640 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001641 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1642 {
1643 if (snp_type == ISIS_SNP_CSNP_FLAG)
1644 {
1645 adj =
1646 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1647 }
1648 else
1649 {
1650 /* a psnp on a broadcast, how lovely of Juniper :) */
1651 adj =
1652 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1653 }
1654 if (!adj)
1655 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001656 }
hassof390d2c2004-09-10 20:48:21 +00001657 else
1658 {
1659 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001660 {
1661 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1662 return ISIS_OK; /* Silently discard */
1663 }
hassof390d2c2004-09-10 20:48:21 +00001664 }
jardineb5d44e2003-12-23 08:09:43 +00001665
1666 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1667
1668 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1669
1670 memset (&tlvs, 0, sizeof (struct tlvs));
1671
1672 /* parse the SNP */
1673 expected |= TLVFLAG_LSP_ENTRIES;
1674 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001675
1676 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001677 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001678 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001679 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001680 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001681
hassof390d2c2004-09-10 20:48:21 +00001682 if (retval > ISIS_WARNING)
1683 {
1684 zlog_warn ("something went very wrong processing SNP");
1685 free_tlvs (&tlvs);
1686 return retval;
1687 }
jardineb5d44e2003-12-23 08:09:43 +00001688
Josh Bailey3f045a02012-03-24 08:35:20 -07001689 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001690 passwd = &circuit->area->area_passwd;
1691 else
1692 passwd = &circuit->area->domain_passwd;
1693
1694 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001695 {
hasso1cbc5622005-01-01 10:29:51 +00001696 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001697 {
1698 if (!(found & TLVFLAG_AUTH_INFO) ||
1699 authentication_check (&tlvs.auth_info, passwd,
1700 circuit->rcv_stream, auth_tlv_offset))
1701 {
1702 isis_event_auth_failure (circuit->area->area_tag,
1703 "SNP authentication" " failure",
1704 phdr ? phdr->source_id :
1705 chdr->source_id);
1706 free_tlvs (&tlvs);
1707 return ISIS_OK;
1708 }
1709 }
hassof390d2c2004-09-10 20:48:21 +00001710 }
jardineb5d44e2003-12-23 08:09:43 +00001711
1712 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001713 if (isis->debugs & DEBUG_SNP_PACKETS)
1714 {
hasso529d65b2004-12-24 00:14:50 +00001715 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1716 circuit->area->area_tag,
1717 level,
1718 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001719 if (tlvs.lsp_entries)
1720 {
hasso3fdb2dd2005-09-28 18:45:54 +00001721 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001722 {
hasso529d65b2004-12-24 00:14:50 +00001723 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1724 " cksum 0x%04x, lifetime %us",
1725 circuit->area->area_tag,
1726 typechar,
1727 rawlspid_print (entry->lsp_id),
1728 ntohl (entry->seq_num),
1729 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001730 }
1731 }
jardineb5d44e2003-12-23 08:09:43 +00001732 }
jardineb5d44e2003-12-23 08:09:43 +00001733
1734 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001735 if (tlvs.lsp_entries)
1736 {
hasso3fdb2dd2005-09-28 18:45:54 +00001737 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001738 {
1739 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1740 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1741 if (lsp)
1742 {
1743 /* 7.3.15.2 b) 1) is this LSP newer */
1744 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1745 entry->checksum, entry->rem_lifetime);
1746 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1747 if (cmp == LSP_EQUAL)
1748 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001749 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1750 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001751 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001752 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001753 else if (cmp == LSP_OLDER)
1754 {
1755 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1756 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1757 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001758 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001759 else
1760 {
hassof390d2c2004-09-10 20:48:21 +00001761 if (own_lsp)
1762 {
1763 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1764 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1765 }
1766 else
1767 {
1768 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001769 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1770 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001771 }
1772 }
1773 }
1774 else
1775 {
1776 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1777 * insert it and set SSN on it */
1778 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1779 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1780 {
1781 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1782 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001783 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001784 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001785 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001786 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1787 }
1788 }
jardineb5d44e2003-12-23 08:09:43 +00001789 }
1790 }
jardineb5d44e2003-12-23 08:09:43 +00001791
1792 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001793 if (snp_type == ISIS_SNP_CSNP_FLAG)
1794 {
1795 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001796 * Build a list from our own LSP db bounded with
1797 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001798 */
1799 lsp_list = list_new ();
1800 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1801 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001802
hassof390d2c2004-09-10 20:48:21 +00001803 /* Fixme: Find a better solution */
1804 if (tlvs.lsp_entries)
1805 {
paul1eb8ef22005-04-07 07:30:20 +00001806 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001807 {
paul1eb8ef22005-04-07 07:30:20 +00001808 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001809 {
1810 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1811 {
1812 list_delete_node (lsp_list, node2);
1813 break;
1814 }
1815 }
1816 }
1817 }
1818 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001819 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001820 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001821 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001822 list_delete (lsp_list);
1823
jardineb5d44e2003-12-23 08:09:43 +00001824 }
jardineb5d44e2003-12-23 08:09:43 +00001825
1826 free_tlvs (&tlvs);
1827 return retval;
1828}
1829
hasso92365882005-01-18 13:53:33 +00001830static int
hassof390d2c2004-09-10 20:48:21 +00001831process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001832{
Josh Bailey3f045a02012-03-24 08:35:20 -07001833 if (isis->debugs & DEBUG_SNP_PACKETS)
1834 {
1835 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1836 circuit->area->area_tag, level, circuit->interface->name,
1837 circuit_t2string (circuit->is_type), circuit->circuit_id);
1838 if (isis->debugs & DEBUG_PACKET_DUMP)
1839 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1840 stream_get_endp (circuit->rcv_stream));
1841 }
1842
jardineb5d44e2003-12-23 08:09:43 +00001843 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001844 if ((stream_get_endp (circuit->rcv_stream) -
1845 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1846 {
1847 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1848 return ISIS_WARNING;
1849 }
jardineb5d44e2003-12-23 08:09:43 +00001850
1851 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1852}
1853
hasso92365882005-01-18 13:53:33 +00001854static int
hassof390d2c2004-09-10 20:48:21 +00001855process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001856{
Josh Bailey3f045a02012-03-24 08:35:20 -07001857 if (isis->debugs & DEBUG_SNP_PACKETS)
1858 {
1859 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1860 circuit->area->area_tag, level, circuit->interface->name,
1861 circuit_t2string (circuit->is_type), circuit->circuit_id);
1862 if (isis->debugs & DEBUG_PACKET_DUMP)
1863 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1864 stream_get_endp (circuit->rcv_stream));
1865 }
1866
hassof390d2c2004-09-10 20:48:21 +00001867 if ((stream_get_endp (circuit->rcv_stream) -
1868 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1869 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001870 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001871 return ISIS_WARNING;
1872 }
jardineb5d44e2003-12-23 08:09:43 +00001873
1874 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1875}
1876
jardineb5d44e2003-12-23 08:09:43 +00001877/*
1878 * Process ISH
1879 * ISO - 10589
1880 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1881 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001882 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1883 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1884 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001885 */
hasso92365882005-01-18 13:53:33 +00001886static int
jardineb5d44e2003-12-23 08:09:43 +00001887process_is_hello (struct isis_circuit *circuit)
1888{
1889 struct isis_adjacency *adj;
1890 int retval = ISIS_OK;
1891 u_char neigh_len;
1892 u_char *sysid;
1893
Josh Bailey3f045a02012-03-24 08:35:20 -07001894 if (isis->debugs & DEBUG_ADJ_PACKETS)
1895 {
1896 zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u",
1897 circuit->area->area_tag, circuit->interface->name,
1898 circuit_t2string (circuit->is_type), circuit->circuit_id);
1899 if (isis->debugs & DEBUG_PACKET_DUMP)
1900 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1901 stream_get_endp (circuit->rcv_stream));
1902 }
1903
jardineb5d44e2003-12-23 08:09:43 +00001904 /* In this point in time we are not yet able to handle is_hellos
1905 * on lan - Sorry juniper...
1906 */
1907 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1908 return retval;
1909
1910 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001911 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001912 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001913 if (!adj)
1914 {
1915 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00001916 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001917 if (adj == NULL)
1918 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001919
hassof390d2c2004-09-10 20:48:21 +00001920 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1921 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1922 circuit->u.p2p.neighbor = adj;
1923 }
1924 /* 8.2.2 a) */
1925 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1926 ISIS_SYS_ID_LEN))
1927 {
1928 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1929 /* 8.2.2 a) 2) delete the adj */
1930 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1931 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00001932 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001933 if (adj == NULL)
1934 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001935
hassof390d2c2004-09-10 20:48:21 +00001936 /* 8.2.2 a) 3) i */
1937 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1938 /* 8.2.2 a) 3) ii */
1939 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1940 /* 8.2.2 a) 4) quite meaningless */
1941 }
jardineb5d44e2003-12-23 08:09:43 +00001942 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001943 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1944 (adj->sys_type == ISIS_SYSTYPE_IS))
1945 {
1946 /* do nothing */
1947 }
1948 else
1949 {
1950 /* 8.2.2 c) respond with a p2p IIH */
1951 send_hello (circuit, 1);
1952 }
jardineb5d44e2003-12-23 08:09:43 +00001953 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001954 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001955 /* 8.2.2 e) FIXME: Circuit type of? */
1956
jardineb5d44e2003-12-23 08:09:43 +00001957 return retval;
1958}
1959
jardineb5d44e2003-12-23 08:09:43 +00001960/*
1961 * PDU Dispatcher
1962 */
1963
hasso92365882005-01-18 13:53:33 +00001964static int
hassof390d2c2004-09-10 20:48:21 +00001965isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001966{
jardineb5d44e2003-12-23 08:09:43 +00001967 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00001968
hassof390d2c2004-09-10 20:48:21 +00001969 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001970
1971 /*
1972 * Let's first read data from stream to the header
1973 */
hassof390d2c2004-09-10 20:48:21 +00001974 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001975
hassof390d2c2004-09-10 20:48:21 +00001976 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1977 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001978 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00001979 return ISIS_ERROR;
1980 }
jardineb5d44e2003-12-23 08:09:43 +00001981
1982 /* now we need to know if this is an ISO 9542 packet and
1983 * take real good care of it, waaa!
1984 */
hassof390d2c2004-09-10 20:48:21 +00001985 if (hdr->idrp == ISO9542_ESIS)
1986 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001987 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
1988 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00001989 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001990 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1991
jardineb5d44e2003-12-23 08:09:43 +00001992 /*
1993 * and then process it
1994 */
1995
hassof390d2c2004-09-10 20:48:21 +00001996 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1997 {
1998 zlog_err ("Fixed header length = %d", hdr->length);
1999 return ISIS_ERROR;
2000 }
jardineb5d44e2003-12-23 08:09:43 +00002001
hassof390d2c2004-09-10 20:48:21 +00002002 if (hdr->version1 != 1)
2003 {
2004 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
2005 return ISIS_WARNING;
2006 }
jardineb5d44e2003-12-23 08:09:43 +00002007 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002008 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
2009 {
2010 zlog_err
2011 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2012 "while the parameter for this IS is %u", hdr->id_len,
2013 ISIS_SYS_ID_LEN);
2014 return ISIS_ERROR;
2015 }
jardineb5d44e2003-12-23 08:09:43 +00002016
hassof390d2c2004-09-10 20:48:21 +00002017 if (hdr->version2 != 1)
2018 {
2019 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2020 return ISIS_WARNING;
2021 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002022
2023 if (circuit->is_passive)
2024 {
2025 zlog_warn ("Received ISIS PDU on passive circuit %s",
2026 circuit->interface->name);
2027 return ISIS_WARNING;
2028 }
2029
jardineb5d44e2003-12-23 08:09:43 +00002030 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002031 if ((hdr->max_area_addrs != 0)
2032 && (hdr->max_area_addrs != isis->max_area_addrs))
2033 {
2034 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2035 "received PDU %u while the parameter for this IS is %u",
2036 hdr->max_area_addrs, isis->max_area_addrs);
2037 return ISIS_ERROR;
2038 }
jardineb5d44e2003-12-23 08:09:43 +00002039
hassof390d2c2004-09-10 20:48:21 +00002040 switch (hdr->pdu_type)
2041 {
2042 case L1_LAN_HELLO:
2043 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2044 break;
2045 case L2_LAN_HELLO:
2046 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2047 break;
2048 case P2P_HELLO:
2049 retval = process_p2p_hello (circuit);
2050 break;
2051 case L1_LINK_STATE:
2052 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2053 break;
2054 case L2_LINK_STATE:
2055 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2056 break;
2057 case L1_COMPLETE_SEQ_NUM:
2058 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2059 break;
2060 case L2_COMPLETE_SEQ_NUM:
2061 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2062 break;
2063 case L1_PARTIAL_SEQ_NUM:
2064 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2065 break;
2066 case L2_PARTIAL_SEQ_NUM:
2067 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2068 break;
2069 default:
2070 return ISIS_ERROR;
2071 }
jardineb5d44e2003-12-23 08:09:43 +00002072
2073 return retval;
2074}
2075
jardineb5d44e2003-12-23 08:09:43 +00002076#ifdef GNU_LINUX
2077int
2078isis_receive (struct thread *thread)
2079{
jardineb5d44e2003-12-23 08:09:43 +00002080 struct isis_circuit *circuit;
2081 u_char ssnpa[ETH_ALEN];
2082 int retval;
2083
2084 /*
2085 * Get the circuit
2086 */
2087 circuit = THREAD_ARG (thread);
2088 assert (circuit);
2089
2090 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002091 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002092 else
2093 stream_reset (circuit->rcv_stream);
2094
2095 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002096 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002097
2098 if (retval == ISIS_OK)
2099 retval = isis_handle_pdu (circuit, ssnpa);
2100
2101 /*
2102 * prepare for next packet.
2103 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002104 if (!circuit->is_passive)
2105 {
2106 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2107 circuit->fd);
2108 }
jardineb5d44e2003-12-23 08:09:43 +00002109
2110 return retval;
2111}
2112
2113#else
2114int
2115isis_receive (struct thread *thread)
2116{
jardineb5d44e2003-12-23 08:09:43 +00002117 struct isis_circuit *circuit;
2118 u_char ssnpa[ETH_ALEN];
2119 int retval;
2120
2121 /*
2122 * Get the circuit
2123 */
2124 circuit = THREAD_ARG (thread);
2125 assert (circuit);
2126
hassof390d2c2004-09-10 20:48:21 +00002127 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002128
2129 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002130 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002131 else
2132 stream_reset (circuit->rcv_stream);
2133
2134 retval = circuit->rx (circuit, ssnpa);
2135
2136 if (retval == ISIS_OK)
2137 retval = isis_handle_pdu (circuit, ssnpa);
2138
2139 /*
2140 * prepare for next packet.
2141 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002142 if (!circuit->is_passive)
2143 {
2144 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2145 listcount
2146 (circuit->area->circuit_list) *
2147 100);
2148 }
jardineb5d44e2003-12-23 08:09:43 +00002149
2150 return retval;
2151}
2152
2153#endif
2154
2155 /* filling of the fixed isis header */
2156void
2157fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2158{
2159 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2160
2161 hdr->idrp = ISO10589_ISIS;
2162
hassof390d2c2004-09-10 20:48:21 +00002163 switch (pdu_type)
2164 {
2165 case L1_LAN_HELLO:
2166 case L2_LAN_HELLO:
2167 hdr->length = ISIS_LANHELLO_HDRLEN;
2168 break;
2169 case P2P_HELLO:
2170 hdr->length = ISIS_P2PHELLO_HDRLEN;
2171 break;
2172 case L1_LINK_STATE:
2173 case L2_LINK_STATE:
2174 hdr->length = ISIS_LSP_HDR_LEN;
2175 break;
2176 case L1_COMPLETE_SEQ_NUM:
2177 case L2_COMPLETE_SEQ_NUM:
2178 hdr->length = ISIS_CSNP_HDRLEN;
2179 break;
2180 case L1_PARTIAL_SEQ_NUM:
2181 case L2_PARTIAL_SEQ_NUM:
2182 hdr->length = ISIS_PSNP_HDRLEN;
2183 break;
2184 default:
2185 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2186 return;
2187 }
jardineb5d44e2003-12-23 08:09:43 +00002188 hdr->length += ISIS_FIXED_HDR_LEN;
2189 hdr->pdu_type = pdu_type;
2190 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002191 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002192 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002193 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002194}
2195
jardineb5d44e2003-12-23 08:09:43 +00002196/*
2197 * SEND SIDE
2198 */
hasso92365882005-01-18 13:53:33 +00002199static void
jardineb5d44e2003-12-23 08:09:43 +00002200fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002201 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002202{
hassof390d2c2004-09-10 20:48:21 +00002203 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002204
2205 stream_putc (stream, hdr->idrp);
2206 stream_putc (stream, hdr->length);
2207 stream_putc (stream, hdr->version1);
2208 stream_putc (stream, hdr->id_len);
2209 stream_putc (stream, hdr->pdu_type);
2210 stream_putc (stream, hdr->version2);
2211 stream_putc (stream, hdr->reserved);
2212 stream_putc (stream, hdr->max_area_addrs);
2213
2214 return;
2215}
2216
jardineb5d44e2003-12-23 08:09:43 +00002217int
2218send_hello (struct isis_circuit *circuit, int level)
2219{
2220 struct isis_fixed_hdr fixed_hdr;
2221 struct isis_lan_hello_hdr hello_hdr;
2222 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002223 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2224 unsigned long len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002225 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002226 int retval;
2227
Josh Bailey3f045a02012-03-24 08:35:20 -07002228 if (circuit->is_passive)
2229 return ISIS_OK;
2230
hassof390d2c2004-09-10 20:48:21 +00002231 if (circuit->interface->mtu == 0)
2232 {
2233 zlog_warn ("circuit has zero MTU");
2234 return ISIS_WARNING;
2235 }
jardineb5d44e2003-12-23 08:09:43 +00002236
2237 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002238 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002239 else
2240 stream_reset (circuit->snd_stream);
2241
2242 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002243 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002244 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2245 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002246 else
hassof390d2c2004-09-10 20:48:21 +00002247 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2248 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002249 else
hassof390d2c2004-09-10 20:48:21 +00002250 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002251
2252 /*
2253 * Fill LAN Level 1 or 2 Hello PDU header
2254 */
2255 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002256 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002257 circuit->hello_interval[level - 1];
2258 if (interval > USHRT_MAX)
2259 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002260 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002261 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002262 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002263
hassof390d2c2004-09-10 20:48:21 +00002264 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002265 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002266
2267 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002268 if (circuit->circ_type == CIRCUIT_T_P2P)
2269 {
2270 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2271 p2p_hello_hdr.local_id = circuit->circuit_id;
2272 /* FIXME: need better understanding */
2273 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002274 }
hassof390d2c2004-09-10 20:48:21 +00002275 else
2276 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002277 hello_hdr.prio = circuit->priority[level - 1];
2278 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002279 {
2280 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2281 ISIS_SYS_ID_LEN + 1);
2282 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002283 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002284 {
2285 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2286 ISIS_SYS_ID_LEN + 1);
2287 }
2288 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2289 }
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002292 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002293 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002294
jardineb5d44e2003-12-23 08:09:43 +00002295 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002296 switch (circuit->passwd.type)
2297 {
2298 /* Cleartext */
2299 case ISIS_PASSWD_TYPE_CLEARTXT:
2300 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2301 circuit->passwd.passwd, circuit->snd_stream))
2302 return ISIS_WARNING;
2303 break;
2304
2305 /* HMAC MD5 */
2306 case ISIS_PASSWD_TYPE_HMAC_MD5:
2307 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2308 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2309 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2310 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2311 hmac_md5_hash, circuit->snd_stream))
2312 return ISIS_WARNING;
2313 break;
2314
2315 default:
2316 break;
2317 }
2318
jardineb5d44e2003-12-23 08:09:43 +00002319 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002320 if (listcount (circuit->area->area_addrs) == 0)
2321 return ISIS_WARNING;
2322 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2323 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002324
2325 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002326 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2327 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002328 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2329 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002330 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2331 circuit->snd_stream))
2332 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002333 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2334 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002335 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2336 circuit->snd_stream))
2337 return ISIS_WARNING;
2338 }
jardineb5d44e2003-12-23 08:09:43 +00002339
2340 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002341 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002342 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2343 return ISIS_WARNING;
2344 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002345 if (circuit->ip_router && circuit->ip_addrs &&
2346 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002347 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2348 return ISIS_WARNING;
2349
hassof390d2c2004-09-10 20:48:21 +00002350#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002351 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002352 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002353 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002354 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2355 return ISIS_WARNING;
2356#endif /* HAVE_IPV6 */
2357
Josh Bailey3f045a02012-03-24 08:35:20 -07002358 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002359 if (tlv_add_padding (circuit->snd_stream))
2360 return ISIS_WARNING;
2361
paul9985f832005-02-09 15:51:56 +00002362 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002363 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002364 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002365
Josh Bailey3f045a02012-03-24 08:35:20 -07002366 /* For HMAC MD5 we need to compute the md5 hash and store it */
2367 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2368 {
2369 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2370 stream_get_endp (circuit->snd_stream),
2371 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
2372 (caddr_t) &hmac_md5_hash);
2373 /* Copy the hash into the stream */
2374 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2375 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2376 }
jardineb5d44e2003-12-23 08:09:43 +00002377
hassof390d2c2004-09-10 20:48:21 +00002378 if (isis->debugs & DEBUG_ADJ_PACKETS)
2379 {
2380 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2381 {
hasso529d65b2004-12-24 00:14:50 +00002382 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2383 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002384 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002385 length);
hassof390d2c2004-09-10 20:48:21 +00002386 }
2387 else
2388 {
hasso529d65b2004-12-24 00:14:50 +00002389 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2390 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002391 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002392 length);
hassof390d2c2004-09-10 20:48:21 +00002393 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002394 if (isis->debugs & DEBUG_PACKET_DUMP)
2395 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2396 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002397 }
jardineb5d44e2003-12-23 08:09:43 +00002398
Josh Bailey3f045a02012-03-24 08:35:20 -07002399 retval = circuit->tx (circuit, level);
2400 if (retval != ISIS_OK)
2401 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2402 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002403
Josh Bailey3f045a02012-03-24 08:35:20 -07002404 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002405}
2406
2407int
2408send_lan_l1_hello (struct thread *thread)
2409{
jardineb5d44e2003-12-23 08:09:43 +00002410 struct isis_circuit *circuit;
2411 int retval;
2412
2413 circuit = THREAD_ARG (thread);
2414 assert (circuit);
2415 circuit->u.bc.t_send_lan_hello[0] = NULL;
2416
2417 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002418 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002419
Josh Bailey3f045a02012-03-24 08:35:20 -07002420 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002421
2422 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002423 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2424 send_lan_l1_hello, circuit,
2425 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002426
2427 return retval;
2428}
2429
2430int
2431send_lan_l2_hello (struct thread *thread)
2432{
2433 struct isis_circuit *circuit;
2434 int retval;
2435
2436 circuit = THREAD_ARG (thread);
2437 assert (circuit);
2438 circuit->u.bc.t_send_lan_hello[1] = NULL;
2439
2440 if (circuit->u.bc.run_dr_elect[1])
2441 retval = isis_dr_elect (circuit, 2);
2442
Josh Bailey3f045a02012-03-24 08:35:20 -07002443 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002444
hassof390d2c2004-09-10 20:48:21 +00002445 /* set next timer thread */
2446 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2447 send_lan_l2_hello, circuit,
2448 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002449
2450 return retval;
2451}
2452
2453int
2454send_p2p_hello (struct thread *thread)
2455{
2456 struct isis_circuit *circuit;
2457
2458 circuit = THREAD_ARG (thread);
2459 assert (circuit);
2460 circuit->u.p2p.t_send_p2p_hello = NULL;
2461
hassof390d2c2004-09-10 20:48:21 +00002462 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002463
hassof390d2c2004-09-10 20:48:21 +00002464 /* set next timer thread */
2465 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2466 circuit, isis_jitter (circuit->hello_interval[1],
2467 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002468
2469 return ISIS_OK;
2470}
2471
hasso92365882005-01-18 13:53:33 +00002472static int
hassof390d2c2004-09-10 20:48:21 +00002473build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2474 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002475{
2476 struct isis_fixed_hdr fixed_hdr;
2477 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002478 unsigned long lenp;
2479 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002480 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2481 unsigned long auth_tlv_offset = 0;
2482 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002483
Josh Bailey3f045a02012-03-24 08:35:20 -07002484 if (circuit->snd_stream == NULL)
2485 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2486 else
2487 stream_reset (circuit->snd_stream);
2488
2489 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002490 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2491 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002492 else
hassof390d2c2004-09-10 20:48:21 +00002493 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2494 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002495
2496 /*
2497 * Fill Level 1 or 2 Complete Sequence Numbers header
2498 */
2499
paul9985f832005-02-09 15:51:56 +00002500 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002501 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002502 /* no need to send the source here, it is always us if we csnp */
2503 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2504 /* with zero circuit id - ref 9.10, 9.11 */
2505 stream_putc (circuit->snd_stream, 0x00);
2506
2507 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2508 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2509
2510 /*
2511 * And TLVs
2512 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002513 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002514 passwd = &circuit->area->area_passwd;
2515 else
2516 passwd = &circuit->area->domain_passwd;
2517
hasso1cbc5622005-01-01 10:29:51 +00002518 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002519 {
2520 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002521 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002522 /* Cleartext */
2523 case ISIS_PASSWD_TYPE_CLEARTXT:
2524 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2525 passwd->passwd, circuit->snd_stream))
2526 return ISIS_WARNING;
2527 break;
2528
2529 /* HMAC MD5 */
2530 case ISIS_PASSWD_TYPE_HMAC_MD5:
2531 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2532 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2533 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2534 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2535 hmac_md5_hash, circuit->snd_stream))
2536 return ISIS_WARNING;
2537 break;
2538
2539 default:
2540 break;
hassof390d2c2004-09-10 20:48:21 +00002541 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002542 }
2543
2544 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2545 if (retval != ISIS_OK)
2546 return retval;
2547
paul9985f832005-02-09 15:51:56 +00002548 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002549 /* Update PU length */
2550 stream_putw_at (circuit->snd_stream, lenp, length);
2551
Josh Bailey3f045a02012-03-24 08:35:20 -07002552 /* For HMAC MD5 we need to compute the md5 hash and store it */
2553 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2554 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2555 {
2556 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2557 stream_get_endp(circuit->snd_stream),
2558 (unsigned char *) &passwd->passwd, passwd->len,
2559 (caddr_t) &hmac_md5_hash);
2560 /* Copy the hash into the stream */
2561 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2562 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2563 }
2564
jardineb5d44e2003-12-23 08:09:43 +00002565 return retval;
2566}
2567
2568/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002569 * Count the maximum number of lsps that can be accomodated by a given size.
2570 */
2571static uint16_t
2572get_max_lsp_count (uint16_t size)
2573{
2574 uint16_t tlv_count;
2575 uint16_t lsp_count;
2576 uint16_t remaining_size;
2577
2578 /* First count the full size TLVs */
2579 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2580 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2581
2582 /* The last TLV, if any */
2583 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2584 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2585 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2586
2587 return lsp_count;
2588}
2589
2590/*
2591 * Calculate the length of Authentication Info. TLV.
2592 */
2593static uint16_t
2594auth_tlv_length (int level, struct isis_circuit *circuit)
2595{
2596 struct isis_passwd *passwd;
2597 uint16_t length;
2598
2599 if (level == IS_LEVEL_1)
2600 passwd = &circuit->area->area_passwd;
2601 else
2602 passwd = &circuit->area->domain_passwd;
2603
2604 /* Also include the length of TLV header */
2605 length = AUTH_INFO_HDRLEN;
2606 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2607 {
2608 switch (passwd->type)
2609 {
2610 /* Cleartext */
2611 case ISIS_PASSWD_TYPE_CLEARTXT:
2612 length += passwd->len;
2613 break;
2614
2615 /* HMAC MD5 */
2616 case ISIS_PASSWD_TYPE_HMAC_MD5:
2617 length += ISIS_AUTH_MD5_SIZE;
2618 break;
2619
2620 default:
2621 break;
2622 }
2623 }
2624
2625 return length;
2626}
2627
2628/*
2629 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2630 */
2631static uint16_t
2632max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2633{
2634 int snp_hdr_len;
2635 int auth_tlv_len;
2636 uint16_t lsp_count;
2637
2638 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2639 if (snp_type == ISIS_SNP_CSNP_FLAG)
2640 snp_hdr_len += ISIS_CSNP_HDRLEN;
2641 else
2642 snp_hdr_len += ISIS_PSNP_HDRLEN;
2643
2644 auth_tlv_len = auth_tlv_length (level, circuit);
2645 lsp_count = get_max_lsp_count (
2646 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002647 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002648}
2649
2650/*
jardineb5d44e2003-12-23 08:09:43 +00002651 * FIXME: support multiple CSNPs
2652 */
2653
2654int
2655send_csnp (struct isis_circuit *circuit, int level)
2656{
jardineb5d44e2003-12-23 08:09:43 +00002657 u_char start[ISIS_SYS_ID_LEN + 2];
2658 u_char stop[ISIS_SYS_ID_LEN + 2];
2659 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002660 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002661 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002662 u_char num_lsps, loop = 1;
2663 int i, retval = ISIS_OK;
2664
2665 if (circuit->area->lspdb[level - 1] == NULL ||
2666 dict_count (circuit->area->lspdb[level - 1]) == 0)
2667 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002668
hassof390d2c2004-09-10 20:48:21 +00002669 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002670 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2671
Josh Bailey3f045a02012-03-24 08:35:20 -07002672 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2673
2674 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002675 {
2676 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002677 lsp_build_list (start, stop, num_lsps, list,
2678 circuit->area->lspdb[level - 1]);
2679 /*
2680 * Update the stop lsp_id before encoding this CSNP.
2681 */
2682 if (listcount (list) < num_lsps)
2683 {
2684 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2685 }
hassof390d2c2004-09-10 20:48:21 +00002686 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002687 {
2688 node = listtail (list);
2689 lsp = listgetdata (node);
2690 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2691 }
jardineb5d44e2003-12-23 08:09:43 +00002692
hassof390d2c2004-09-10 20:48:21 +00002693 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002694 if (retval != ISIS_OK)
2695 {
2696 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2697 circuit->area->area_tag, level, circuit->interface->name);
2698 list_delete (list);
2699 return retval;
2700 }
jardineb5d44e2003-12-23 08:09:43 +00002701
hassof390d2c2004-09-10 20:48:21 +00002702 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002703 {
2704 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2705 circuit->area->area_tag, level, circuit->interface->name,
2706 stream_get_endp (circuit->snd_stream));
2707 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2708 {
2709 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2710 " cksum 0x%04x, lifetime %us",
2711 circuit->area->area_tag,
2712 rawlspid_print (lsp->lsp_header->lsp_id),
2713 ntohl (lsp->lsp_header->seq_num),
2714 ntohs (lsp->lsp_header->checksum),
2715 ntohs (lsp->lsp_header->rem_lifetime));
2716 }
2717 if (isis->debugs & DEBUG_PACKET_DUMP)
2718 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2719 stream_get_endp (circuit->snd_stream));
2720 }
hassof390d2c2004-09-10 20:48:21 +00002721
Josh Bailey3f045a02012-03-24 08:35:20 -07002722 retval = circuit->tx (circuit, level);
2723 if (retval != ISIS_OK)
2724 {
2725 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2726 circuit->area->area_tag, level,
2727 circuit->interface->name);
2728 list_delete (list);
2729 return retval;
2730 }
2731
2732 /*
2733 * Start lsp_id of the next CSNP should be one plus the
2734 * stop lsp_id in this current CSNP.
2735 */
2736 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2737 loop = 0;
2738 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2739 {
2740 if (start[i] < (u_char)0xff)
2741 {
2742 start[i] += 1;
2743 loop = 1;
2744 break;
2745 }
2746 }
2747 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002748 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002749 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002750
jardineb5d44e2003-12-23 08:09:43 +00002751 return retval;
2752}
2753
2754int
2755send_l1_csnp (struct thread *thread)
2756{
2757 struct isis_circuit *circuit;
2758 int retval = ISIS_OK;
2759
2760 circuit = THREAD_ARG (thread);
2761 assert (circuit);
2762
2763 circuit->t_send_csnp[0] = NULL;
2764
hassof390d2c2004-09-10 20:48:21 +00002765 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2766 {
2767 send_csnp (circuit, 1);
2768 }
jardineb5d44e2003-12-23 08:09:43 +00002769 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002770 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2771 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002772
2773 return retval;
2774}
2775
2776int
2777send_l2_csnp (struct thread *thread)
2778{
2779 struct isis_circuit *circuit;
2780 int retval = ISIS_OK;
2781
2782 circuit = THREAD_ARG (thread);
2783 assert (circuit);
2784
2785 circuit->t_send_csnp[1] = NULL;
2786
hassof390d2c2004-09-10 20:48:21 +00002787 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2788 {
2789 send_csnp (circuit, 2);
2790 }
jardineb5d44e2003-12-23 08:09:43 +00002791 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002792 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2793 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002794
jardineb5d44e2003-12-23 08:09:43 +00002795 return retval;
2796}
2797
hasso92365882005-01-18 13:53:33 +00002798static int
jardineb5d44e2003-12-23 08:09:43 +00002799build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2800{
2801 struct isis_fixed_hdr fixed_hdr;
2802 unsigned long lenp;
2803 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002804 struct isis_lsp *lsp;
2805 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002806 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002807 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2808 unsigned long auth_tlv_offset = 0;
2809 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002810
Josh Bailey3f045a02012-03-24 08:35:20 -07002811 if (circuit->snd_stream == NULL)
2812 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2813 else
2814 stream_reset (circuit->snd_stream);
2815
2816 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002817 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2818 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002819 else
2820 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002821 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002822
2823 /*
2824 * Fill Level 1 or 2 Partial Sequence Numbers header
2825 */
paul9985f832005-02-09 15:51:56 +00002826 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002827 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002828 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2829 stream_putc (circuit->snd_stream, circuit->idx);
2830
2831 /*
2832 * And TLVs
2833 */
2834
Josh Bailey3f045a02012-03-24 08:35:20 -07002835 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002836 passwd = &circuit->area->area_passwd;
2837 else
2838 passwd = &circuit->area->domain_passwd;
2839
hasso1cbc5622005-01-01 10:29:51 +00002840 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002841 {
2842 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002843 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002844 /* Cleartext */
2845 case ISIS_PASSWD_TYPE_CLEARTXT:
2846 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2847 passwd->passwd, circuit->snd_stream))
2848 return ISIS_WARNING;
2849 break;
2850
2851 /* HMAC MD5 */
2852 case ISIS_PASSWD_TYPE_HMAC_MD5:
2853 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2854 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2855 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2856 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2857 hmac_md5_hash, circuit->snd_stream))
2858 return ISIS_WARNING;
2859 break;
2860
2861 default:
2862 break;
jardineb5d44e2003-12-23 08:09:43 +00002863 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002864 }
2865
2866 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2867 if (retval != ISIS_OK)
2868 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002869
hassof390d2c2004-09-10 20:48:21 +00002870 if (isis->debugs & DEBUG_SNP_PACKETS)
2871 {
hasso3fdb2dd2005-09-28 18:45:54 +00002872 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002873 {
hasso529d65b2004-12-24 00:14:50 +00002874 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2875 " cksum 0x%04x, lifetime %us",
2876 circuit->area->area_tag,
2877 rawlspid_print (lsp->lsp_header->lsp_id),
2878 ntohl (lsp->lsp_header->seq_num),
2879 ntohs (lsp->lsp_header->checksum),
2880 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002881 }
2882 }
2883
paul9985f832005-02-09 15:51:56 +00002884 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002885 /* Update PDU length */
2886 stream_putw_at (circuit->snd_stream, lenp, length);
2887
Josh Bailey3f045a02012-03-24 08:35:20 -07002888 /* For HMAC MD5 we need to compute the md5 hash and store it */
2889 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2890 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2891 {
2892 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2893 stream_get_endp(circuit->snd_stream),
2894 (unsigned char *) &passwd->passwd, passwd->len,
2895 (caddr_t) &hmac_md5_hash);
2896 /* Copy the hash into the stream */
2897 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2898 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2899 }
2900
jardineb5d44e2003-12-23 08:09:43 +00002901 return ISIS_OK;
2902}
2903
2904/*
2905 * 7.3.15.4 action on expiration of partial SNP interval
2906 * level 1
2907 */
hasso92365882005-01-18 13:53:33 +00002908static int
jardineb5d44e2003-12-23 08:09:43 +00002909send_psnp (int level, struct isis_circuit *circuit)
2910{
jardineb5d44e2003-12-23 08:09:43 +00002911 struct isis_lsp *lsp;
2912 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002913 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002914 u_char num_lsps;
2915 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002916
Josh Bailey3f045a02012-03-24 08:35:20 -07002917 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2918 circuit->u.bc.is_dr[level - 1])
2919 return ISIS_OK;
2920
2921 if (circuit->area->lspdb[level - 1] == NULL ||
2922 dict_count (circuit->area->lspdb[level - 1]) == 0)
2923 return ISIS_OK;
2924
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002925 if (! circuit->snd_stream)
2926 return ISIS_ERROR;
2927
Josh Bailey3f045a02012-03-24 08:35:20 -07002928 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2929
2930 while (1)
hassof390d2c2004-09-10 20:48:21 +00002931 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002932 list = list_new ();
2933 lsp_build_list_ssn (circuit, num_lsps, list,
2934 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002935
Josh Bailey3f045a02012-03-24 08:35:20 -07002936 if (listcount (list) == 0)
2937 {
2938 list_delete (list);
2939 return ISIS_OK;
2940 }
jardineb5d44e2003-12-23 08:09:43 +00002941
Josh Bailey3f045a02012-03-24 08:35:20 -07002942 retval = build_psnp (level, circuit, list);
2943 if (retval != ISIS_OK)
2944 {
2945 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2946 circuit->area->area_tag, level, circuit->interface->name);
2947 list_delete (list);
2948 return retval;
2949 }
jardineb5d44e2003-12-23 08:09:43 +00002950
Josh Bailey3f045a02012-03-24 08:35:20 -07002951 if (isis->debugs & DEBUG_SNP_PACKETS)
2952 {
2953 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2954 circuit->area->area_tag, level,
2955 circuit->interface->name,
2956 stream_get_endp (circuit->snd_stream));
2957 if (isis->debugs & DEBUG_PACKET_DUMP)
2958 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2959 stream_get_endp (circuit->snd_stream));
2960 }
jardineb5d44e2003-12-23 08:09:43 +00002961
Josh Bailey3f045a02012-03-24 08:35:20 -07002962 retval = circuit->tx (circuit, level);
2963 if (retval != ISIS_OK)
2964 {
2965 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2966 circuit->area->area_tag, level,
2967 circuit->interface->name);
2968 list_delete (list);
2969 return retval;
2970 }
jardineb5d44e2003-12-23 08:09:43 +00002971
Josh Bailey3f045a02012-03-24 08:35:20 -07002972 /*
2973 * sending succeeded, we can clear SSN flags of this circuit
2974 * for the LSPs in list
2975 */
2976 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2977 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2978 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002979 }
jardineb5d44e2003-12-23 08:09:43 +00002980
2981 return retval;
2982}
2983
2984int
2985send_l1_psnp (struct thread *thread)
2986{
2987
2988 struct isis_circuit *circuit;
2989 int retval = ISIS_OK;
2990
2991 circuit = THREAD_ARG (thread);
2992 assert (circuit);
2993
2994 circuit->t_send_psnp[0] = NULL;
2995
2996 send_psnp (1, circuit);
2997 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002998 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2999 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003000
3001 return retval;
3002}
3003
3004/*
3005 * 7.3.15.4 action on expiration of partial SNP interval
3006 * level 2
3007 */
3008int
3009send_l2_psnp (struct thread *thread)
3010{
jardineb5d44e2003-12-23 08:09:43 +00003011 struct isis_circuit *circuit;
3012 int retval = ISIS_OK;
3013
3014 circuit = THREAD_ARG (thread);
3015 assert (circuit);
3016
3017 circuit->t_send_psnp[1] = NULL;
3018
3019 send_psnp (2, circuit);
3020
3021 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003022 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3023 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003024
3025 return retval;
3026}
3027
jardineb5d44e2003-12-23 08:09:43 +00003028/*
3029 * ISO 10589 - 7.3.14.3
3030 */
3031int
3032send_lsp (struct thread *thread)
3033{
3034 struct isis_circuit *circuit;
3035 struct isis_lsp *lsp;
3036 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003037 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003038
3039 circuit = THREAD_ARG (thread);
3040 assert (circuit);
3041
Josh Bailey3f045a02012-03-24 08:35:20 -07003042 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3043 {
3044 return retval;
3045 }
3046
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003047 node = listhead (circuit->lsp_queue);
3048
3049 /*
3050 * Handle case where there are no LSPs on the queue. This can
3051 * happen, for instance, if an adjacency goes down before this
3052 * thread gets a chance to run.
3053 */
3054 if (!node)
3055 {
3056 return retval;
3057 }
3058
3059 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003060
3061 /*
3062 * Do not send if levels do not match
3063 */
3064 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003065 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003066 list_delete_node (circuit->lsp_queue, node);
3067 return retval;
hassof390d2c2004-09-10 20:48:21 +00003068 }
jardineb5d44e2003-12-23 08:09:43 +00003069
Josh Bailey3f045a02012-03-24 08:35:20 -07003070 /*
3071 * Do not send if we do not have adjacencies in state up on the circuit
3072 */
3073 if (circuit->upadjcount[lsp->level - 1] == 0)
3074 {
3075 list_delete_node (circuit->lsp_queue, node);
3076 return retval;
3077 }
3078
3079 /* copy our lsp to the send buffer */
3080 stream_copy (circuit->snd_stream, lsp->pdu);
3081
3082 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3083 {
3084 zlog_debug
3085 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3086 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3087 rawlspid_print (lsp->lsp_header->lsp_id),
3088 ntohl (lsp->lsp_header->seq_num),
3089 ntohs (lsp->lsp_header->checksum),
3090 ntohs (lsp->lsp_header->rem_lifetime),
3091 circuit->interface->name);
3092 if (isis->debugs & DEBUG_PACKET_DUMP)
3093 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3094 stream_get_endp (circuit->snd_stream));
3095 }
3096
3097 retval = circuit->tx (circuit, lsp->level);
3098 if (retval != ISIS_OK)
3099 {
3100 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3101 circuit->area->area_tag, lsp->level,
3102 circuit->interface->name);
3103 return retval;
3104 }
3105
3106 /*
3107 * If the sending succeeded, we can del the lsp from circuits
3108 * lsp_queue
3109 */
3110 list_delete_node (circuit->lsp_queue, node);
3111
3112 /* Set the last-cleared time if the queue is empty. */
3113 /* TODO: Is is possible that new lsps keep being added to the queue
3114 * that the queue is never empty? */
3115 if (list_isempty (circuit->lsp_queue))
3116 circuit->lsp_queue_last_cleared = time (NULL);
3117
3118 /*
3119 * On broadcast circuits also the SRMflag can be cleared
3120 */
3121 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3122 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3123
jardineb5d44e2003-12-23 08:09:43 +00003124 return retval;
hassof390d2c2004-09-10 20:48:21 +00003125}
jardineb5d44e2003-12-23 08:09:43 +00003126
3127int
hassof390d2c2004-09-10 20:48:21 +00003128ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3129 int level)
jardineb5d44e2003-12-23 08:09:43 +00003130{
3131 unsigned long lenp;
3132 int retval;
3133 u_int16_t length;
3134 struct isis_fixed_hdr fixed_hdr;
3135
3136 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003137 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003138 else
3139 stream_reset (circuit->snd_stream);
3140
Josh Bailey3f045a02012-03-24 08:35:20 -07003141 // fill_llc_hdr (stream);
3142 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003143 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3144 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003145 else
hassof390d2c2004-09-10 20:48:21 +00003146 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3147 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003148
3149
paul9985f832005-02-09 15:51:56 +00003150 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003151 stream_putw (circuit->snd_stream, 0); /* PDU length */
3152 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003153 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003154 stream_putc (circuit->snd_stream, 9); /* code */
3155 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003156
hassof390d2c2004-09-10 20:48:21 +00003157 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3158 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3159 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3160 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003161
paul9985f832005-02-09 15:51:56 +00003162 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003163 /* Update PDU length */
3164 stream_putw_at (circuit->snd_stream, lenp, length);
3165
3166 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003167 if (retval != ISIS_OK)
3168 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3169 circuit->area->area_tag, level,
3170 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003171
3172 return retval;
3173}