blob: ffc67178b4a04ac93cc6f6ceb7c419bc25142f77 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_pdu.c
3 * PDU processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "memory.h"
27#include "thread.h"
28#include "linklist.h"
29#include "log.h"
30#include "stream.h"
31#include "vty.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070032#include "hash.h"
jardineb5d44e2003-12-23 08:09:43 +000033#include "prefix.h"
34#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010035#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070036#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000037
38#include "isisd/dict.h"
39#include "isisd/include-netbsd/iso.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_adjacency.h"
44#include "isisd/isis_circuit.h"
45#include "isisd/isis_network.h"
46#include "isisd/isis_misc.h"
47#include "isisd/isis_dr.h"
jardineb5d44e2003-12-23 08:09:43 +000048#include "isisd/isis_tlv.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_lsp.h"
52#include "isisd/isis_pdu.h"
53#include "isisd/iso_checksum.h"
54#include "isisd/isis_csm.h"
55#include "isisd/isis_events.h"
56
jardineb5d44e2003-12-23 08:09:43 +000057#define ISIS_MINIMUM_FIXED_HDR_LEN 15
hassof390d2c2004-09-10 20:48:21 +000058#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
jardineb5d44e2003-12-23 08:09:43 +000059
60#ifndef PNBBY
61#define PNBBY 8
62#endif /* PNBBY */
63
64/* Utility mask array. */
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -070065static u_char maskbit[] = {
jardineb5d44e2003-12-23 08:09:43 +000066 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
67};
68
69/*
70 * HELPER FUNCS
71 */
72
73/*
74 * Compares two sets of area addresses
75 */
hassof390d2c2004-09-10 20:48:21 +000076static int
jardineb5d44e2003-12-23 08:09:43 +000077area_match (struct list *left, struct list *right)
78{
79 struct area_addr *addr1, *addr2;
hasso3fdb2dd2005-09-28 18:45:54 +000080 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +000081
hasso3fdb2dd2005-09-28 18:45:54 +000082 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
hassof390d2c2004-09-10 20:48:21 +000083 {
hasso3fdb2dd2005-09-28 18:45:54 +000084 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
hassof390d2c2004-09-10 20:48:21 +000085 {
86 if (addr1->addr_len == addr2->addr_len &&
87 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
88 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +000089 }
90 }
91
hassof390d2c2004-09-10 20:48:21 +000092 return 0; /* mismatch */
jardineb5d44e2003-12-23 08:09:43 +000093}
94
95/*
96 * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
97 * param ip1 the IS interface ip address structure
98 * param ip2 the IIH's ip address
99 * return 0 the IIH's IP is not in the IS's subnetwork
100 * 1 the IIH's IP is in the IS's subnetwork
101 */
hasso92365882005-01-18 13:53:33 +0000102static int
hassof390d2c2004-09-10 20:48:21 +0000103ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
jardineb5d44e2003-12-23 08:09:43 +0000104{
105 u_char *addr1, *addr2;
hasso53c997c2004-09-15 16:21:59 +0000106 int shift, offset, offsetloop;
jardineb5d44e2003-12-23 08:09:43 +0000107 int len;
hassof390d2c2004-09-10 20:48:21 +0000108
109 addr1 = (u_char *) & ip1->prefix.s_addr;
110 addr2 = (u_char *) & ip2->s_addr;
jardineb5d44e2003-12-23 08:09:43 +0000111 len = ip1->prefixlen;
112
113 shift = len % PNBBY;
hasso53c997c2004-09-15 16:21:59 +0000114 offsetloop = offset = len / PNBBY;
jardineb5d44e2003-12-23 08:09:43 +0000115
hasso53c997c2004-09-15 16:21:59 +0000116 while (offsetloop--)
117 if (addr1[offsetloop] != addr2[offsetloop])
118 return 0;
jardineb5d44e2003-12-23 08:09:43 +0000119
hassof390d2c2004-09-10 20:48:21 +0000120 if (shift)
hasso53c997c2004-09-15 16:21:59 +0000121 if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
122 return 0;
hassof390d2c2004-09-10 20:48:21 +0000123
124 return 1; /* match */
jardineb5d44e2003-12-23 08:09:43 +0000125}
126
jardineb5d44e2003-12-23 08:09:43 +0000127/*
128 * Compares two set of ip addresses
129 * param left the local interface's ip addresses
130 * param right the iih interface's ip address
131 * return 0 no match;
132 * 1 match;
133 */
hassof390d2c2004-09-10 20:48:21 +0000134static int
jardineb5d44e2003-12-23 08:09:43 +0000135ip_match (struct list *left, struct list *right)
136{
137 struct prefix_ipv4 *ip1;
138 struct in_addr *ip2;
hasso3fdb2dd2005-09-28 18:45:54 +0000139 struct listnode *node1, *node2;
jardineb5d44e2003-12-23 08:09:43 +0000140
hassoe082ac12004-09-27 18:13:57 +0000141 if ((left == NULL) || (right == NULL))
142 return 0;
143
hasso3fdb2dd2005-09-28 18:45:54 +0000144 for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
hassof390d2c2004-09-10 20:48:21 +0000145 {
hasso3fdb2dd2005-09-28 18:45:54 +0000146 for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
hassof390d2c2004-09-10 20:48:21 +0000147 {
148 if (ip_same_subnet (ip1, ip2))
149 {
150 return 1; /* match */
151 }
jardineb5d44e2003-12-23 08:09:43 +0000152 }
hassof390d2c2004-09-10 20:48:21 +0000153
jardineb5d44e2003-12-23 08:09:43 +0000154 }
155 return 0;
156}
157
158/*
159 * Checks whether we should accept a PDU of given level
160 */
161static int
162accept_level (int level, int circuit_t)
163{
hassof390d2c2004-09-10 20:48:21 +0000164 int retval = ((circuit_t & level) == level); /* simple approach */
jardineb5d44e2003-12-23 08:09:43 +0000165
166 return retval;
167}
168
Josh Bailey3f045a02012-03-24 08:35:20 -0700169/*
170 * Verify authentication information
171 * Support cleartext and HMAC MD5 authentication
172 */
173static int
174authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
175 struct stream *stream, uint32_t auth_tlv_offset)
jardineb5d44e2003-12-23 08:09:43 +0000176{
Josh Bailey3f045a02012-03-24 08:35:20 -0700177 unsigned char digest[ISIS_AUTH_MD5_SIZE];
178
179 /* Auth fail () - passwd type mismatch */
180 if (local->type != remote->type)
181 return ISIS_ERROR;
182
183 switch (local->type)
184 {
185 /* No authentication required */
186 case ISIS_PASSWD_TYPE_UNUSED:
187 break;
188
189 /* Cleartext (ISO 10589) */
hassof390d2c2004-09-10 20:48:21 +0000190 case ISIS_PASSWD_TYPE_CLEARTXT:
Josh Bailey3f045a02012-03-24 08:35:20 -0700191 /* Auth fail () - passwd len mismatch */
192 if (remote->len != local->len)
193 return ISIS_ERROR;
194 return memcmp (local->passwd, remote->passwd, local->len);
195
196 /* HMAC MD5 (RFC 3567) */
197 case ISIS_PASSWD_TYPE_HMAC_MD5:
198 /* Auth fail () - passwd len mismatch */
199 if (remote->len != ISIS_AUTH_MD5_SIZE)
200 return ISIS_ERROR;
201 /* Set the authentication value to 0 before the check */
202 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
203 ISIS_AUTH_MD5_SIZE);
204 /* Compute the digest */
205 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
206 (unsigned char *) &(local->passwd), local->len,
207 (caddr_t) &digest);
208 /* Copy back the authentication value after the check */
209 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
210 remote->passwd, ISIS_AUTH_MD5_SIZE);
211 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
212
hassof390d2c2004-09-10 20:48:21 +0000213 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700214 zlog_err ("Unsupported authentication type");
215 return ISIS_ERROR;
216 }
217
218 /* Authentication pass when no authentication is configured */
219 return ISIS_OK;
220}
221
222static int
223lsp_authentication_check (struct stream *stream, struct isis_area *area,
224 int level, struct isis_passwd *passwd)
225{
226 struct isis_link_state_hdr *hdr;
227 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700228 uint16_t checksum, rem_lifetime, pdu_len;
Josh Bailey3f045a02012-03-24 08:35:20 -0700229 struct tlvs tlvs;
230 int retval = ISIS_OK;
231
232 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700233 pdu_len = ntohs (hdr->pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700234 expected |= TLVFLAG_AUTH_INFO;
235 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
236 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700237 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
Josh Bailey3f045a02012-03-24 08:35:20 -0700238 &expected, &found, &tlvs, &auth_tlv_offset);
239
240 if (retval != ISIS_OK)
241 {
242 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
243 "cksum 0x%04x, lifetime %us, len %u",
244 area->area_tag, level, rawlspid_print (hdr->lsp_id),
245 ntohl (hdr->seq_num), ntohs (hdr->checksum),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700246 ntohs (hdr->rem_lifetime), pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700247 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
248 (isis->debugs & DEBUG_PACKET_DUMP))
249 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
250 return retval;
hassof390d2c2004-09-10 20:48:21 +0000251 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700252
253 if (!(found & TLVFLAG_AUTH_INFO))
254 {
255 zlog_err ("No authentication tlv in LSP");
256 return ISIS_ERROR;
257 }
258
259 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
260 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
261 {
262 zlog_err ("Unknown authentication type in LSP");
263 return ISIS_ERROR;
264 }
265
266 /*
267 * RFC 5304 set checksum and remaining lifetime to zero before
268 * verification and reset to old values after verification.
269 */
270 checksum = hdr->checksum;
271 rem_lifetime = hdr->rem_lifetime;
272 hdr->checksum = 0;
273 hdr->rem_lifetime = 0;
274 retval = authentication_check (&tlvs.auth_info, passwd, stream,
275 auth_tlv_offset);
276 hdr->checksum = checksum;
277 hdr->rem_lifetime = rem_lifetime;
278
279 return retval;
jardineb5d44e2003-12-23 08:09:43 +0000280}
281
282/*
283 * Processing helper functions
284 */
hasso92365882005-01-18 13:53:33 +0000285static void
Josh Bailey3f045a02012-03-24 08:35:20 -0700286del_addr (void *val)
287{
288 XFREE (MTYPE_ISIS_TMP, val);
289}
290
291static void
292tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
293{
294 struct listnode *node;
295 struct area_addr *area_addr, *malloced;
296
297 if (adj->area_addrs)
298 {
299 adj->area_addrs->del = del_addr;
300 list_delete (adj->area_addrs);
301 }
302 adj->area_addrs = list_new ();
303 if (tlvs->area_addrs)
304 {
305 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
306 {
307 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
308 memcpy (malloced, area_addr, sizeof (struct area_addr));
309 listnode_add (adj->area_addrs, malloced);
310 }
311 }
312}
313
314static void
hassof390d2c2004-09-10 20:48:21 +0000315tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000316{
317 int i;
318 struct nlpids *tlv_nlpids;
319
hassof390d2c2004-09-10 20:48:21 +0000320 if (tlvs->nlpids)
321 {
jardineb5d44e2003-12-23 08:09:43 +0000322
hassof390d2c2004-09-10 20:48:21 +0000323 tlv_nlpids = tlvs->nlpids;
jardineb5d44e2003-12-23 08:09:43 +0000324
hassof390d2c2004-09-10 20:48:21 +0000325 adj->nlpids.count = tlv_nlpids->count;
jardineb5d44e2003-12-23 08:09:43 +0000326
hassof390d2c2004-09-10 20:48:21 +0000327 for (i = 0; i < tlv_nlpids->count; i++)
328 {
329 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
330 }
jardineb5d44e2003-12-23 08:09:43 +0000331 }
jardineb5d44e2003-12-23 08:09:43 +0000332}
333
hasso92365882005-01-18 13:53:33 +0000334static void
hassof390d2c2004-09-10 20:48:21 +0000335tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000336{
hasso3fdb2dd2005-09-28 18:45:54 +0000337 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000338 struct in_addr *ipv4_addr, *malloced;
339
hassof390d2c2004-09-10 20:48:21 +0000340 if (adj->ipv4_addrs)
341 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700342 adj->ipv4_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000343 list_delete (adj->ipv4_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000344 }
hassof390d2c2004-09-10 20:48:21 +0000345 adj->ipv4_addrs = list_new ();
346 if (tlvs->ipv4_addrs)
347 {
hasso3fdb2dd2005-09-28 18:45:54 +0000348 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000349 {
350 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
351 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
352 listnode_add (adj->ipv4_addrs, malloced);
353 }
354 }
jardineb5d44e2003-12-23 08:09:43 +0000355}
356
357#ifdef HAVE_IPV6
hasso92365882005-01-18 13:53:33 +0000358static void
hassof390d2c2004-09-10 20:48:21 +0000359tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
jardineb5d44e2003-12-23 08:09:43 +0000360{
hasso3fdb2dd2005-09-28 18:45:54 +0000361 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000362 struct in6_addr *ipv6_addr, *malloced;
363
hassof390d2c2004-09-10 20:48:21 +0000364 if (adj->ipv6_addrs)
365 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700366 adj->ipv6_addrs->del = del_addr;
hassof390d2c2004-09-10 20:48:21 +0000367 list_delete (adj->ipv6_addrs);
jardineb5d44e2003-12-23 08:09:43 +0000368 }
hassof390d2c2004-09-10 20:48:21 +0000369 adj->ipv6_addrs = list_new ();
370 if (tlvs->ipv6_addrs)
371 {
hasso3fdb2dd2005-09-28 18:45:54 +0000372 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
hassof390d2c2004-09-10 20:48:21 +0000373 {
374 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
375 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
376 listnode_add (adj->ipv6_addrs, malloced);
377 }
378 }
jardineb5d44e2003-12-23 08:09:43 +0000379
380}
381#endif /* HAVE_IPV6 */
382
jardineb5d44e2003-12-23 08:09:43 +0000383/*
384 * RECEIVE SIDE
385 */
386
387/*
388 * Process P2P IIH
389 * ISO - 10589
390 * Section 8.2.5 - Receiving point-to-point IIH PDUs
391 *
392 */
393static int
394process_p2p_hello (struct isis_circuit *circuit)
395{
396 int retval = ISIS_OK;
397 struct isis_p2p_hello_hdr *hdr;
398 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700399 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700400 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +0000401 struct tlvs tlvs;
402
Josh Bailey3f045a02012-03-24 08:35:20 -0700403 if (isis->debugs & DEBUG_ADJ_PACKETS)
404 {
405 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
406 circuit->area->area_tag, circuit->interface->name,
407 circuit_t2string (circuit->is_type), circuit->circuit_id);
408 if (isis->debugs & DEBUG_PACKET_DUMP)
409 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
410 stream_get_endp (circuit->rcv_stream));
411 }
412
413 if (circuit->circ_type != CIRCUIT_T_P2P)
414 {
415 zlog_warn ("p2p hello on non p2p circuit");
416 return ISIS_WARNING;
417 }
418
hassof390d2c2004-09-10 20:48:21 +0000419 if ((stream_get_endp (circuit->rcv_stream) -
420 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
421 {
422 zlog_warn ("Packet too short");
423 return ISIS_WARNING;
424 }
jardineb5d44e2003-12-23 08:09:43 +0000425
426 /* 8.2.5.1 PDU acceptance tests */
427
428 /* 8.2.5.1 a) external domain untrue */
429 /* FIXME: not useful at all? */
430
431 /* 8.2.5.1 b) ID Length mismatch */
432 /* checked at the handle_pdu */
433
434 /* 8.2.5.2 IIH PDU Processing */
435
436 /* 8.2.5.2 a) 1) Maximum Area Addresses */
437 /* Already checked, and can also be ommited */
438
439 /*
440 * Get the header
441 */
hassof390d2c2004-09-10 20:48:21 +0000442 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700443 pdu_len = ntohs (hdr->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000444
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700445 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
446 pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700447 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000448 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700449 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
450 "invalid pdu length %d",
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700451 circuit->area->area_tag, circuit->interface->name, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700452 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +0000453 }
jardineb5d44e2003-12-23 08:09:43 +0000454
jardineb5d44e2003-12-23 08:09:43 +0000455 /*
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700456 * Set the stream endp to PDU length, ignoring additional padding
457 * introduced by transport chips.
458 */
459 if (pdu_len < stream_get_endp (circuit->rcv_stream))
460 stream_set_endp (circuit->rcv_stream, pdu_len);
461
462 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
463
464 /*
jardineb5d44e2003-12-23 08:09:43 +0000465 * Lets get the TLVS now
466 */
467 expected |= TLVFLAG_AREA_ADDRS;
468 expected |= TLVFLAG_AUTH_INFO;
469 expected |= TLVFLAG_NLPID;
470 expected |= TLVFLAG_IPV4_ADDR;
471 expected |= TLVFLAG_IPV6_ADDR;
472
Josh Bailey3f045a02012-03-24 08:35:20 -0700473 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000474 retval = parse_tlvs (circuit->area->area_tag,
475 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700476 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
477 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000478
hassof390d2c2004-09-10 20:48:21 +0000479 if (retval > ISIS_WARNING)
480 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700481 zlog_warn ("parse_tlvs() failed");
hassof390d2c2004-09-10 20:48:21 +0000482 free_tlvs (&tlvs);
483 return retval;
484 };
jardineb5d44e2003-12-23 08:09:43 +0000485
Josh Bailey3f045a02012-03-24 08:35:20 -0700486 if (!(found & TLVFLAG_AREA_ADDRS))
487 {
488 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
489 free_tlvs (&tlvs);
490 return ISIS_WARNING;
491 }
492
jardineb5d44e2003-12-23 08:09:43 +0000493 /* 8.2.5.1 c) Authentication */
hassof390d2c2004-09-10 20:48:21 +0000494 if (circuit->passwd.type)
495 {
496 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700497 authentication_check (&tlvs.auth_info, &circuit->passwd,
498 circuit->rcv_stream, auth_tlv_offset))
499 {
500 isis_event_auth_failure (circuit->area->area_tag,
501 "P2P hello authentication failure",
502 hdr->source_id);
503 free_tlvs (&tlvs);
504 return ISIS_OK;
505 }
jardineb5d44e2003-12-23 08:09:43 +0000506 }
jardineb5d44e2003-12-23 08:09:43 +0000507
Josh Bailey3f045a02012-03-24 08:35:20 -0700508 /*
509 * check if it's own interface ip match iih ip addrs
510 */
511 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
512 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
513 {
514 zlog_warn ("ISIS-Adj: No usable IP interface addresses "
515 "in LAN IIH from %s\n", circuit->interface->name);
516 free_tlvs (&tlvs);
517 return ISIS_WARNING;
518 }
519
520 /*
521 * My interpertation of the ISO, if no adj exists we will create one for
522 * the circuit
523 */
524 adj = circuit->u.p2p.neighbor;
525 if (!adj || adj->level != hdr->circuit_t)
526 {
527 if (!adj)
528 {
529 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
530 if (adj == NULL)
531 return ISIS_ERROR;
532 }
533 else
534 {
535 adj->level = hdr->circuit_t;
536 }
537 circuit->u.p2p.neighbor = adj;
538 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
539 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
540 }
541
542 /* 8.2.6 Monitoring point-to-point adjacencies */
543 adj->hold_time = ntohs (hdr->hold_time);
544 adj->last_upd = time (NULL);
545
jardineb5d44e2003-12-23 08:09:43 +0000546 /* we do this now because the adj may not survive till the end... */
Josh Bailey3f045a02012-03-24 08:35:20 -0700547 tlvs_to_adj_area_addrs (&tlvs, adj);
548
549 /* which protocol are spoken ??? */
550 if (found & TLVFLAG_NLPID)
551 tlvs_to_adj_nlpids (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000552
553 /* we need to copy addresses to the adj */
Josh Bailey3f045a02012-03-24 08:35:20 -0700554 if (found & TLVFLAG_IPV4_ADDR)
555 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000556
557#ifdef HAVE_IPV6
Josh Bailey3f045a02012-03-24 08:35:20 -0700558 if (found & TLVFLAG_IPV6_ADDR)
559 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
jardineb5d44e2003-12-23 08:09:43 +0000560#endif /* HAVE_IPV6 */
561
562 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +0000563 THREAD_TIMER_OFF (adj->t_expire);
564 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
565 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +0000566
567 /* 8.2.5.2 a) a match was detected */
hassof390d2c2004-09-10 20:48:21 +0000568 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
569 {
570 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
571 if (circuit->area->is_type == IS_LEVEL_1)
572 {
573 switch (hdr->circuit_t)
574 {
575 case IS_LEVEL_1:
576 case IS_LEVEL_1_AND_2:
577 if (adj->adj_state != ISIS_ADJ_UP)
578 {
579 /* (4) adj state up */
580 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
581 /* (5) adj usage level 1 */
582 adj->adj_usage = ISIS_ADJ_LEVEL1;
583 }
584 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
585 {
586 ; /* accept */
587 }
588 break;
589 case IS_LEVEL_2:
590 if (adj->adj_state != ISIS_ADJ_UP)
591 {
592 /* (7) reject - wrong system type event */
593 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700594 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000595 return ISIS_WARNING; /* Reject */
596 }
597 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
598 {
599 /* (6) down - wrong system */
600 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
601 }
602 break;
603 }
604 }
jardineb5d44e2003-12-23 08:09:43 +0000605
hassof390d2c2004-09-10 20:48:21 +0000606 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
607 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
608 {
609 switch (hdr->circuit_t)
610 {
611 case IS_LEVEL_1:
612 if (adj->adj_state != ISIS_ADJ_UP)
613 {
614 /* (6) adj state up */
615 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
616 /* (7) adj usage level 1 */
617 adj->adj_usage = ISIS_ADJ_LEVEL1;
618 }
619 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
620 {
621 ; /* accept */
622 }
623 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
624 (adj->adj_usage == ISIS_ADJ_LEVEL2))
625 {
626 /* (8) down - wrong system */
627 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
628 }
629 break;
630 case IS_LEVEL_2:
631 if (adj->adj_state != ISIS_ADJ_UP)
632 {
633 /* (6) adj state up */
634 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
635 /* (9) adj usage level 2 */
636 adj->adj_usage = ISIS_ADJ_LEVEL2;
637 }
638 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
639 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
640 {
641 /* (8) down - wrong system */
642 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
643 }
644 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
645 {
646 ; /* Accept */
647 }
648 break;
649 case IS_LEVEL_1_AND_2:
650 if (adj->adj_state != ISIS_ADJ_UP)
651 {
652 /* (6) adj state up */
653 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
654 /* (10) adj usage level 1 */
655 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
656 }
657 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
658 (adj->adj_usage == ISIS_ADJ_LEVEL2))
659 {
660 /* (8) down - wrong system */
661 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
662 }
663 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
664 {
665 ; /* Accept */
666 }
667 break;
668 }
669 }
jardineb5d44e2003-12-23 08:09:43 +0000670
hassof390d2c2004-09-10 20:48:21 +0000671 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
672 if (circuit->area->is_type == IS_LEVEL_2)
673 {
674 switch (hdr->circuit_t)
675 {
676 case IS_LEVEL_1:
677 if (adj->adj_state != ISIS_ADJ_UP)
678 {
679 /* (5) reject - wrong system type event */
680 zlog_warn ("wrongSystemType");
Josh Bailey3f045a02012-03-24 08:35:20 -0700681 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000682 return ISIS_WARNING; /* Reject */
683 }
684 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
685 (adj->adj_usage == ISIS_ADJ_LEVEL2))
686 {
687 /* (6) down - wrong system */
688 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
689 }
690 break;
691 case IS_LEVEL_1_AND_2:
692 case IS_LEVEL_2:
693 if (adj->adj_state != ISIS_ADJ_UP)
694 {
695 /* (7) adj state up */
696 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
697 /* (8) adj usage level 2 */
698 adj->adj_usage = ISIS_ADJ_LEVEL2;
699 }
700 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
701 {
702 /* (6) down - wrong system */
703 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
704 }
705 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
706 {
707 ; /* Accept */
708 }
709 break;
710 }
711 }
jardineb5d44e2003-12-23 08:09:43 +0000712 }
jardineb5d44e2003-12-23 08:09:43 +0000713 /* 8.2.5.2 b) if no match was detected */
Josh Bailey3f045a02012-03-24 08:35:20 -0700714 else if (listcount (circuit->area->area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +0000715 {
hassof390d2c2004-09-10 20:48:21 +0000716 if (circuit->area->is_type == IS_LEVEL_1)
717 {
718 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
719 if (adj->adj_state != ISIS_ADJ_UP)
720 {
721 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
722 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
723 }
724 else
725 {
726 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
727 "Down - Area Mismatch");
728 }
729 }
730 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
731 else
732 {
733 switch (hdr->circuit_t)
734 {
735 case IS_LEVEL_1:
736 if (adj->adj_state != ISIS_ADJ_UP)
737 {
738 /* (6) reject - Area Mismatch event */
739 zlog_warn ("AreaMismatch");
Josh Bailey3f045a02012-03-24 08:35:20 -0700740 free_tlvs (&tlvs);
hassof390d2c2004-09-10 20:48:21 +0000741 return ISIS_WARNING; /* Reject */
742 }
743 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
744 {
745 /* (7) down - area mismatch */
746 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
jardineb5d44e2003-12-23 08:09:43 +0000747
hassof390d2c2004-09-10 20:48:21 +0000748 }
749 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
750 (adj->adj_usage == ISIS_ADJ_LEVEL2))
751 {
752 /* (7) down - wrong system */
753 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
754 }
755 break;
756 case IS_LEVEL_1_AND_2:
757 case IS_LEVEL_2:
758 if (adj->adj_state != ISIS_ADJ_UP)
759 {
760 /* (8) adj state up */
761 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
762 /* (9) adj usage level 2 */
763 adj->adj_usage = ISIS_ADJ_LEVEL2;
764 }
765 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
766 {
767 /* (7) down - wrong system */
768 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
769 }
770 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
771 {
772 if (hdr->circuit_t == IS_LEVEL_2)
773 {
774 /* (7) down - wrong system */
775 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
776 "Wrong System");
777 }
778 else
779 {
780 /* (7) down - area mismatch */
781 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
782 "Area Mismatch");
783 }
784 }
785 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
786 {
787 ; /* Accept */
788 }
789 break;
790 }
791 }
jardineb5d44e2003-12-23 08:09:43 +0000792 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700793 else
794 {
795 /* down - area mismatch */
796 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
797 }
jardineb5d44e2003-12-23 08:09:43 +0000798 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
799 /* FIXME - Missing parts */
800
jardineb5d44e2003-12-23 08:09:43 +0000801 /* some of my own understanding of the ISO, why the heck does
802 * it not say what should I change the system_type to...
803 */
hassof390d2c2004-09-10 20:48:21 +0000804 switch (adj->adj_usage)
805 {
jardineb5d44e2003-12-23 08:09:43 +0000806 case ISIS_ADJ_LEVEL1:
807 adj->sys_type = ISIS_SYSTYPE_L1_IS;
808 break;
809 case ISIS_ADJ_LEVEL2:
810 adj->sys_type = ISIS_SYSTYPE_L2_IS;
811 break;
812 case ISIS_ADJ_LEVEL1AND2:
813 adj->sys_type = ISIS_SYSTYPE_L2_IS;
814 break;
815 case ISIS_ADJ_NONE:
816 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
817 break;
hassof390d2c2004-09-10 20:48:21 +0000818 }
jardineb5d44e2003-12-23 08:09:43 +0000819
820 adj->circuit_t = hdr->circuit_t;
Josh Bailey3f045a02012-03-24 08:35:20 -0700821
822 if (isis->debugs & DEBUG_ADJ_PACKETS)
823 {
824 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
825 " cir id %02d, length %d",
826 circuit->area->area_tag, circuit->interface->name,
827 circuit_t2string (circuit->is_type),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700828 circuit->circuit_id, pdu_len);
Josh Bailey3f045a02012-03-24 08:35:20 -0700829 }
jardineb5d44e2003-12-23 08:09:43 +0000830
831 free_tlvs (&tlvs);
832
833 return retval;
834}
835
jardineb5d44e2003-12-23 08:09:43 +0000836/*
837 * Process IS-IS LAN Level 1/2 Hello PDU
838 */
hassof390d2c2004-09-10 20:48:21 +0000839static int
840process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +0000841{
842 int retval = ISIS_OK;
843 struct isis_lan_hello_hdr hdr;
844 struct isis_adjacency *adj;
Josh Bailey3f045a02012-03-24 08:35:20 -0700845 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +0000846 struct tlvs tlvs;
847 u_char *snpa;
hasso3fdb2dd2005-09-28 18:45:54 +0000848 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000849
Josh Bailey3f045a02012-03-24 08:35:20 -0700850 if (isis->debugs & DEBUG_ADJ_PACKETS)
851 {
852 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
853 "cirID %u",
854 circuit->area->area_tag, level, circuit->interface->name,
855 circuit_t2string (circuit->is_type), circuit->circuit_id);
856 if (isis->debugs & DEBUG_PACKET_DUMP)
857 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
858 stream_get_endp (circuit->rcv_stream));
859 }
860
861 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
862 {
863 zlog_warn ("lan hello on non broadcast circuit");
864 return ISIS_WARNING;
865 }
866
hassof390d2c2004-09-10 20:48:21 +0000867 if ((stream_get_endp (circuit->rcv_stream) -
868 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
869 {
870 zlog_warn ("Packet too short");
871 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000872 }
hassof390d2c2004-09-10 20:48:21 +0000873
874 if (circuit->ext_domain)
875 {
hasso529d65b2004-12-24 00:14:50 +0000876 zlog_debug ("level %d LAN Hello received over circuit with "
877 "externalDomain = true", level);
hassof390d2c2004-09-10 20:48:21 +0000878 return ISIS_WARNING;
879 }
880
Josh Bailey3f045a02012-03-24 08:35:20 -0700881 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +0000882 {
883 if (isis->debugs & DEBUG_ADJ_PACKETS)
884 {
hasso529d65b2004-12-24 00:14:50 +0000885 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
886 circuit->area->area_tag, circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +0000887 }
888 return ISIS_WARNING;
889 }
jardineb5d44e2003-12-23 08:09:43 +0000890
891#if 0
892 /* Cisco's debug message compatability */
hassof390d2c2004-09-10 20:48:21 +0000893 if (!accept_level (level, circuit->area->is_type))
894 {
895 if (isis->debugs & DEBUG_ADJ_PACKETS)
896 {
hasso529d65b2004-12-24 00:14:50 +0000897 zlog_debug ("ISIS-Adj (%s): is type mismatch",
898 circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000899 }
900 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +0000901 }
jardineb5d44e2003-12-23 08:09:43 +0000902#endif
903 /*
904 * Fill the header
905 */
906 hdr.circuit_t = stream_getc (circuit->rcv_stream);
907 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
908 hdr.hold_time = stream_getw (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +0000909 hdr.pdu_len = stream_getw (circuit->rcv_stream);
910 hdr.prio = stream_getc (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000911 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
912
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -0700913 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
914 hdr.pdu_len > ISO_MTU(circuit) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700915 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +0000916 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700917 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
918 "invalid pdu length %d",
919 circuit->area->area_tag, circuit->interface->name,
920 hdr.pdu_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700921 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -0700922 }
923
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700924 /*
925 * Set the stream endp to PDU length, ignoring additional padding
926 * introduced by transport chips.
927 */
928 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
929 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
930
Josh Bailey3f045a02012-03-24 08:35:20 -0700931 if (hdr.circuit_t != IS_LEVEL_1 &&
932 hdr.circuit_t != IS_LEVEL_2 &&
933 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
934 (level & hdr.circuit_t) == 0)
935 {
936 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
937 hdr.circuit_t);
hassof390d2c2004-09-10 20:48:21 +0000938 return ISIS_ERROR;
939 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700940
jardineb5d44e2003-12-23 08:09:43 +0000941 /*
942 * Then get the tlvs
943 */
944 expected |= TLVFLAG_AUTH_INFO;
945 expected |= TLVFLAG_AREA_ADDRS;
946 expected |= TLVFLAG_LAN_NEIGHS;
947 expected |= TLVFLAG_NLPID;
948 expected |= TLVFLAG_IPV4_ADDR;
949 expected |= TLVFLAG_IPV6_ADDR;
950
Josh Bailey3f045a02012-03-24 08:35:20 -0700951 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +0000952 retval = parse_tlvs (circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -0700953 STREAM_PNT (circuit->rcv_stream),
954 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
955 &expected, &found, &tlvs,
956 &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +0000957
hassof390d2c2004-09-10 20:48:21 +0000958 if (retval > ISIS_WARNING)
959 {
960 zlog_warn ("parse_tlvs() failed");
961 goto out;
962 }
jardineb5d44e2003-12-23 08:09:43 +0000963
hassof390d2c2004-09-10 20:48:21 +0000964 if (!(found & TLVFLAG_AREA_ADDRS))
965 {
966 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
967 level);
jardineb5d44e2003-12-23 08:09:43 +0000968 retval = ISIS_WARNING;
969 goto out;
970 }
hassof390d2c2004-09-10 20:48:21 +0000971
Josh Bailey3f045a02012-03-24 08:35:20 -0700972 /* Verify authentication, either cleartext of HMAC MD5 */
hassof390d2c2004-09-10 20:48:21 +0000973 if (circuit->passwd.type)
974 {
975 if (!(found & TLVFLAG_AUTH_INFO) ||
Josh Bailey3f045a02012-03-24 08:35:20 -0700976 authentication_check (&tlvs.auth_info, &circuit->passwd,
977 circuit->rcv_stream, auth_tlv_offset))
978 {
979 isis_event_auth_failure (circuit->area->area_tag,
980 "LAN hello authentication failure",
981 hdr.source_id);
982 retval = ISIS_WARNING;
983 goto out;
984 }
hassof390d2c2004-09-10 20:48:21 +0000985 }
jardineb5d44e2003-12-23 08:09:43 +0000986
987 /*
988 * Accept the level 1 adjacency only if a match between local and
989 * remote area addresses is found
990 */
Josh Bailey3f045a02012-03-24 08:35:20 -0700991 if (listcount (circuit->area->area_addrs) == 0 ||
992 (level == IS_LEVEL_1 &&
993 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
hassof390d2c2004-09-10 20:48:21 +0000994 {
995 if (isis->debugs & DEBUG_ADJ_PACKETS)
996 {
hasso529d65b2004-12-24 00:14:50 +0000997 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
998 circuit->area->area_tag, level,
999 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001000 }
1001 retval = ISIS_OK;
1002 goto out;
jardineb5d44e2003-12-23 08:09:43 +00001003 }
jardineb5d44e2003-12-23 08:09:43 +00001004
1005 /*
1006 * it's own IIH PDU - discard silently
hassof390d2c2004-09-10 20:48:21 +00001007 */
1008 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1009 {
hasso529d65b2004-12-24 00:14:50 +00001010 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1011 circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +00001012
hassof390d2c2004-09-10 20:48:21 +00001013 retval = ISIS_OK;
1014 goto out;
1015 }
jardineb5d44e2003-12-23 08:09:43 +00001016
1017 /*
1018 * check if it's own interface ip match iih ip addrs
1019 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001020 if ((found & TLVFLAG_IPV4_ADDR) == 0 ||
1021 ip_match (circuit->ip_addrs, tlvs.ipv4_addrs) == 0)
hassof390d2c2004-09-10 20:48:21 +00001022 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001023 zlog_debug ("ISIS-Adj: No usable IP interface addresses "
1024 "in LAN IIH from %s\n", circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001025 retval = ISIS_WARNING;
1026 goto out;
1027 }
jardineb5d44e2003-12-23 08:09:43 +00001028
1029 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001030 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1031 (adj->level != level))
hassof390d2c2004-09-10 20:48:21 +00001032 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001033 if (!adj)
1034 {
1035 /*
1036 * Do as in 8.4.2.5
1037 */
1038 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1039 if (adj == NULL)
1040 {
1041 retval = ISIS_ERROR;
1042 goto out;
1043 }
1044 }
1045 else
1046 {
1047 if (ssnpa) {
1048 memcpy (adj->snpa, ssnpa, 6);
1049 } else {
1050 memset (adj->snpa, ' ', 6);
1051 }
1052 adj->level = level;
1053 }
hassof390d2c2004-09-10 20:48:21 +00001054 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
jardineb5d44e2003-12-23 08:09:43 +00001055
Josh Bailey3f045a02012-03-24 08:35:20 -07001056 if (level == IS_LEVEL_1)
1057 adj->sys_type = ISIS_SYSTYPE_L1_IS;
hassof390d2c2004-09-10 20:48:21 +00001058 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001059 adj->sys_type = ISIS_SYSTYPE_L2_IS;
hassof390d2c2004-09-10 20:48:21 +00001060 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1061 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
Josh Bailey3f045a02012-03-24 08:35:20 -07001062 circuit->u.bc.lan_neighs[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001063 }
jardineb5d44e2003-12-23 08:09:43 +00001064
hassoa211d652004-09-20 14:55:29 +00001065 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1066 switch (level)
1067 {
1068 case 1:
1069 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1070 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001071 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001072 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1073 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001074 }
1075 break;
1076 case 2:
1077 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1078 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001079 thread_add_event (master, isis_event_dis_status_change, circuit, 0);
hasso64a7afd2004-09-14 11:05:13 +00001080 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1081 ISIS_SYS_ID_LEN + 1);
hassoa211d652004-09-20 14:55:29 +00001082 }
1083 break;
1084 }
jardineb5d44e2003-12-23 08:09:43 +00001085
1086 adj->hold_time = hdr.hold_time;
hassof390d2c2004-09-10 20:48:21 +00001087 adj->last_upd = time (NULL);
1088 adj->prio[level - 1] = hdr.prio;
jardineb5d44e2003-12-23 08:09:43 +00001089
1090 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1091
Josh Bailey3f045a02012-03-24 08:35:20 -07001092 tlvs_to_adj_area_addrs (&tlvs, adj);
1093
jardineb5d44e2003-12-23 08:09:43 +00001094 /* which protocol are spoken ??? */
hassof390d2c2004-09-10 20:48:21 +00001095 if (found & TLVFLAG_NLPID)
jardineb5d44e2003-12-23 08:09:43 +00001096 tlvs_to_adj_nlpids (&tlvs, adj);
1097
1098 /* we need to copy addresses to the adj */
hassof390d2c2004-09-10 20:48:21 +00001099 if (found & TLVFLAG_IPV4_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001100 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1101
1102#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001103 if (found & TLVFLAG_IPV6_ADDR)
jardineb5d44e2003-12-23 08:09:43 +00001104 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1105#endif /* HAVE_IPV6 */
1106
1107 adj->circuit_t = hdr.circuit_t;
1108
1109 /* lets take care of the expiry */
hassof390d2c2004-09-10 20:48:21 +00001110 THREAD_TIMER_OFF (adj->t_expire);
1111 THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
Josh Bailey3f045a02012-03-24 08:35:20 -07001112 (long) adj->hold_time);
jardineb5d44e2003-12-23 08:09:43 +00001113
1114 /*
1115 * If the snpa for this circuit is found from LAN Neighbours TLV
1116 * we have two-way communication -> adjacency can be put to state "up"
1117 */
1118
hassof390d2c2004-09-10 20:48:21 +00001119 if (found & TLVFLAG_LAN_NEIGHS)
Josh Bailey3f045a02012-03-24 08:35:20 -07001120 {
1121 if (adj->adj_state != ISIS_ADJ_UP)
hassof390d2c2004-09-10 20:48:21 +00001122 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001123 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1124 {
1125 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1126 {
1127 isis_adj_state_change (adj, ISIS_ADJ_UP,
1128 "own SNPA found in LAN Neighbours TLV");
1129 }
1130 }
jardineb5d44e2003-12-23 08:09:43 +00001131 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001132 else
1133 {
1134 int found = 0;
1135 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1136 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1137 {
1138 found = 1;
1139 break;
1140 }
1141 if (found == 0)
1142 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1143 "own SNPA not found in LAN Neighbours TLV");
1144 }
1145 }
1146 else if (adj->adj_state == ISIS_ADJ_UP)
1147 {
1148 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1149 "no LAN Neighbours TLV found");
1150 }
jardineb5d44e2003-12-23 08:09:43 +00001151
hassof390d2c2004-09-10 20:48:21 +00001152out:
hassof390d2c2004-09-10 20:48:21 +00001153 if (isis->debugs & DEBUG_ADJ_PACKETS)
1154 {
hasso529d65b2004-12-24 00:14:50 +00001155 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
1156 "cirID %u, length %ld",
1157 circuit->area->area_tag,
1158 level, snpa_print (ssnpa), circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001159 circuit_t2string (circuit->is_type),
hasso29e50b22005-09-01 18:18:47 +00001160 circuit->circuit_id,
Josh Bailey3f045a02012-03-24 08:35:20 -07001161 stream_get_endp (circuit->rcv_stream));
hassof390d2c2004-09-10 20:48:21 +00001162 }
jardineb5d44e2003-12-23 08:09:43 +00001163
1164 free_tlvs (&tlvs);
1165
1166 return retval;
1167}
1168
1169/*
1170 * Process Level 1/2 Link State
1171 * ISO - 10589
1172 * Section 7.3.15.1 - Action on receipt of a link state PDU
hassof390d2c2004-09-10 20:48:21 +00001173 */
1174static int
1175process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001176{
1177 struct isis_link_state_hdr *hdr;
1178 struct isis_adjacency *adj = NULL;
1179 struct isis_lsp *lsp, *lsp0 = NULL;
1180 int retval = ISIS_OK, comp = 0;
1181 u_char lspid[ISIS_SYS_ID_LEN + 2];
1182 struct isis_passwd *passwd;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001183 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001184
Josh Bailey3f045a02012-03-24 08:35:20 -07001185 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1186 {
1187 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1188 circuit->area->area_tag, level, circuit->interface->name,
1189 circuit_t2string (circuit->is_type), circuit->circuit_id);
1190 if (isis->debugs & DEBUG_PACKET_DUMP)
1191 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1192 stream_get_endp (circuit->rcv_stream));
1193 }
1194
hassof390d2c2004-09-10 20:48:21 +00001195 if ((stream_get_endp (circuit->rcv_stream) -
1196 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1197 {
1198 zlog_warn ("Packet too short");
1199 return ISIS_WARNING;
1200 }
jardineb5d44e2003-12-23 08:09:43 +00001201
1202 /* Reference the header */
hassof390d2c2004-09-10 20:48:21 +00001203 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001204 pdu_len = ntohs (hdr->pdu_len);
1205
1206 /* lsp length check */
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001207 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001208 pdu_len > ISO_MTU(circuit) ||
1209 pdu_len > stream_get_endp (circuit->rcv_stream))
1210 {
1211 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1212 circuit->area->area_tag,
1213 rawlspid_print (hdr->lsp_id), pdu_len);
1214
1215 return ISIS_WARNING;
1216 }
1217
1218 /*
1219 * Set the stream endp to PDU length, ignoring additional padding
1220 * introduced by transport chips.
1221 */
1222 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1223 stream_set_endp (circuit->rcv_stream, pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001224
hassof390d2c2004-09-10 20:48:21 +00001225 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1226 {
hasso529d65b2004-12-24 00:14:50 +00001227 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
Josh Bailey3f045a02012-03-24 08:35:20 -07001228 "lifetime %us, len %u, on %s",
hasso529d65b2004-12-24 00:14:50 +00001229 circuit->area->area_tag,
1230 level,
1231 rawlspid_print (hdr->lsp_id),
1232 ntohl (hdr->seq_num),
1233 ntohs (hdr->checksum),
1234 ntohs (hdr->rem_lifetime),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001235 pdu_len,
paul15935e92005-05-03 09:27:23 +00001236 circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001237 }
jardineb5d44e2003-12-23 08:09:43 +00001238
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001239 /* lsp is_type check */
1240 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1241 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
Josh Bailey3f045a02012-03-24 08:35:20 -07001242 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001243 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
Josh Bailey3f045a02012-03-24 08:35:20 -07001244 circuit->area->area_tag,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001245 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1246 /* continue as per RFC1122 Be liberal in what you accept, and
1247 * conservative in what you send */
Josh Bailey3f045a02012-03-24 08:35:20 -07001248 }
jardineb5d44e2003-12-23 08:09:43 +00001249
1250 /* Checksum sanity check - FIXME: move to correct place */
1251 /* 12 = sysid+pdu+remtime */
hassof390d2c2004-09-10 20:48:21 +00001252 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001253 pdu_len - 12, &hdr->checksum))
hassof390d2c2004-09-10 20:48:21 +00001254 {
hasso529d65b2004-12-24 00:14:50 +00001255 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1256 circuit->area->area_tag,
1257 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00001258
hassof390d2c2004-09-10 20:48:21 +00001259 return ISIS_WARNING;
1260 }
jardineb5d44e2003-12-23 08:09:43 +00001261
1262 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
hassof390d2c2004-09-10 20:48:21 +00001263 if (circuit->ext_domain)
1264 {
hasso529d65b2004-12-24 00:14:50 +00001265 zlog_debug
hassof390d2c2004-09-10 20:48:21 +00001266 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1267 "externalDomain = true", circuit->area->area_tag,
1268 rawlspid_print (hdr->lsp_id), level);
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) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001274 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001275 {
hasso529d65b2004-12-24 00:14:50 +00001276 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1277 " type %s",
1278 circuit->area->area_tag,
1279 rawlspid_print (hdr->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -07001280 level, circuit_t2string (circuit->is_type));
jardineb5d44e2003-12-23 08:09:43 +00001281
hassof390d2c2004-09-10 20:48:21 +00001282 return ISIS_WARNING;
1283 }
jardineb5d44e2003-12-23 08:09:43 +00001284
1285 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1286
1287 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1288
1289 /* 7.3.15.1 a) 7 - password check */
Josh Bailey3f045a02012-03-24 08:35:20 -07001290 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1291 (passwd = &circuit->area->domain_passwd);
hassof390d2c2004-09-10 20:48:21 +00001292 if (passwd->type)
1293 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001294 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1295 level, passwd))
hassof390d2c2004-09-10 20:48:21 +00001296 {
1297 isis_event_auth_failure (circuit->area->area_tag,
1298 "LSP authentication failure", hdr->lsp_id);
1299 return ISIS_WARNING;
1300 }
jardineb5d44e2003-12-23 08:09:43 +00001301 }
jardineb5d44e2003-12-23 08:09:43 +00001302 /* Find the LSP in our database and compare it to this Link State header */
1303 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1304 if (lsp)
hassof390d2c2004-09-10 20:48:21 +00001305 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1306 hdr->checksum, hdr->rem_lifetime);
1307 if (lsp && (lsp->own_lsp
jardineb5d44e2003-12-23 08:09:43 +00001308#ifdef TOPOLOGY_GENERATE
hassof390d2c2004-09-10 20:48:21 +00001309 || lsp->from_topology
jardineb5d44e2003-12-23 08:09:43 +00001310#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00001311 ))
jardineb5d44e2003-12-23 08:09:43 +00001312 goto dontcheckadj;
1313
1314 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1315 /* for broadcast circuits, snpa should be compared */
jardineb5d44e2003-12-23 08:09:43 +00001316
hassof390d2c2004-09-10 20:48:21 +00001317 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1318 {
1319 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1320 if (!adj)
1321 {
hasso529d65b2004-12-24 00:14:50 +00001322 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1323 "lifetime %us on %s",
1324 circuit->area->area_tag,
1325 rawlspid_print (hdr->lsp_id),
1326 ntohl (hdr->seq_num),
1327 ntohs (hdr->checksum),
1328 ntohs (hdr->rem_lifetime), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001329 return ISIS_WARNING; /* Silently discard */
1330 }
jardineb5d44e2003-12-23 08:09:43 +00001331 }
jardineb5d44e2003-12-23 08:09:43 +00001332 /* for non broadcast, we just need to find same level adj */
hassof390d2c2004-09-10 20:48:21 +00001333 else
1334 {
1335 /* If no adj, or no sharing of level */
1336 if (!circuit->u.p2p.neighbor)
1337 {
1338 return ISIS_OK; /* Silently discard */
1339 }
1340 else
1341 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001342 if (((level == IS_LEVEL_1) &&
hassof390d2c2004-09-10 20:48:21 +00001343 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001344 ((level == IS_LEVEL_2) &&
hassof390d2c2004-09-10 20:48:21 +00001345 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1346 return ISIS_WARNING; /* Silently discard */
Josh Bailey3f045a02012-03-24 08:35:20 -07001347 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001348 }
jardineb5d44e2003-12-23 08:09:43 +00001349 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001350
hassof390d2c2004-09-10 20:48:21 +00001351dontcheckadj:
jardineb5d44e2003-12-23 08:09:43 +00001352 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1353
1354 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1355
hassof390d2c2004-09-10 20:48:21 +00001356 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
jardineb5d44e2003-12-23 08:09:43 +00001357
hassof390d2c2004-09-10 20:48:21 +00001358 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1359 if (hdr->rem_lifetime == 0)
1360 {
1361 if (!lsp)
1362 {
1363 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1364 /* only needed on explicit update, eg - p2p */
1365 if (circuit->circ_type == CIRCUIT_T_P2P)
1366 ack_lsp (hdr, circuit, level);
1367 return retval; /* FIXME: do we need a purge? */
1368 }
1369 else
1370 {
1371 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1372 {
1373 /* LSP by some other system -> do 7.3.16.4 b) */
1374 /* 7.3.16.4 b) 1) */
1375 if (comp == LSP_NEWER)
1376 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001377 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001378 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001379 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001380 /* iii */
1381 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1382 /* v */
1383 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1384 /* iv */
1385 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1386 ISIS_SET_FLAG (lsp->SSNflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001387
hassof390d2c2004-09-10 20:48:21 +00001388 } /* 7.3.16.4 b) 2) */
1389 else if (comp == LSP_EQUAL)
1390 {
1391 /* i */
1392 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1393 /* ii */
1394 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1395 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1396 } /* 7.3.16.4 b) 3) */
1397 else
1398 {
1399 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1400 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1401 }
1402 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001403 else if (lsp->lsp_header->rem_lifetime != 0)
1404 {
1405 /* our own LSP -> 7.3.16.4 c) */
1406 if (comp == LSP_NEWER)
1407 {
1408 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1409 lsp_set_all_srmflags (lsp);
1410 }
1411 else
1412 {
1413 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1414 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1415 }
1416 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1417 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1418 "seq 0x%08x", circuit->area->area_tag,
1419 rawlspid_print (hdr->lsp_id),
1420 ntohl (lsp->lsp_header->seq_num));
1421 }
hassof390d2c2004-09-10 20:48:21 +00001422 }
1423 return retval;
jardineb5d44e2003-12-23 08:09:43 +00001424 }
jardineb5d44e2003-12-23 08:09:43 +00001425 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1426 * purge */
hassof390d2c2004-09-10 20:48:21 +00001427 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1428 {
1429 if (!lsp)
1430 {
1431 /* 7.3.16.4: initiate a purge */
1432 lsp_purge_non_exist (hdr, circuit->area);
1433 return ISIS_OK;
1434 }
1435 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1436
1437 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1438 * has information that the current sequence number for source S is
1439 * "greater" than that held by S, ... */
1440
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001441 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
hassof390d2c2004-09-10 20:48:21 +00001442 {
1443 /* 7.3.16.1 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001444 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
hassoc89c05d2005-09-04 21:36:36 +00001445 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1446 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1447 "0x%08x", circuit->area->area_tag,
1448 rawlspid_print (hdr->lsp_id),
1449 ntohl (lsp->lsp_header->seq_num));
hassof390d2c2004-09-10 20:48:21 +00001450 }
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001451 /* If the received LSP is older or equal,
1452 * resend the LSP which will act as ACK */
1453 lsp_set_all_srmflags (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001454 }
hassof390d2c2004-09-10 20:48:21 +00001455 else
1456 {
1457 /* 7.3.15.1 e) - This lsp originated on another system */
jardineb5d44e2003-12-23 08:09:43 +00001458
hassof390d2c2004-09-10 20:48:21 +00001459 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1460 if ((!lsp || comp == LSP_NEWER))
1461 {
hassof390d2c2004-09-10 20:48:21 +00001462 /*
1463 * If this lsp is a frag, need to see if we have zero lsp present
1464 */
1465 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1466 {
1467 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1468 LSP_FRAGMENT (lspid) = 0;
1469 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1470 if (!lsp0)
1471 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001472 zlog_debug ("Got lsp frag, while zero lsp not in database");
hassof390d2c2004-09-10 20:48:21 +00001473 return ISIS_OK;
1474 }
1475 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001476 /* i */
1477 if (!lsp)
1478 {
1479 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001480 pdu_len, lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -07001481 circuit->area, level);
1482 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1483 }
1484 else /* exists, so we overwrite */
1485 {
1486 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1487 }
hassof390d2c2004-09-10 20:48:21 +00001488 /* ii */
Josh Bailey3f045a02012-03-24 08:35:20 -07001489 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00001490 /* iii */
1491 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
jardineb5d44e2003-12-23 08:09:43 +00001492
hassof390d2c2004-09-10 20:48:21 +00001493 /* iv */
1494 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1495 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1496 /* FIXME: v) */
1497 }
1498 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1499 else if (comp == LSP_EQUAL)
1500 {
1501 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001502 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
hassof390d2c2004-09-10 20:48:21 +00001503 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07001504 ISIS_SET_FLAG (lsp->SSNflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001505 }
1506 /* 7.3.15.1 e) 3) LSP older than the one in db */
1507 else
1508 {
1509 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1510 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1511 }
jardineb5d44e2003-12-23 08:09:43 +00001512 }
jardineb5d44e2003-12-23 08:09:43 +00001513 return retval;
1514}
1515
1516/*
1517 * Process Sequence Numbers
1518 * ISO - 10589
1519 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1520 */
1521
hasso92365882005-01-18 13:53:33 +00001522static int
hassof390d2c2004-09-10 20:48:21 +00001523process_snp (int snp_type, int level, struct isis_circuit *circuit,
1524 u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001525{
1526 int retval = ISIS_OK;
1527 int cmp, own_lsp;
1528 char typechar = ' ';
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001529 uint16_t pdu_len;
jardineb5d44e2003-12-23 08:09:43 +00001530 struct isis_adjacency *adj;
1531 struct isis_complete_seqnum_hdr *chdr = NULL;
1532 struct isis_partial_seqnum_hdr *phdr = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001533 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00001534 struct isis_lsp *lsp;
1535 struct lsp_entry *entry;
paul1eb8ef22005-04-07 07:30:20 +00001536 struct listnode *node, *nnode;
1537 struct listnode *node2, *nnode2;
jardineb5d44e2003-12-23 08:09:43 +00001538 struct tlvs tlvs;
1539 struct list *lsp_list = NULL;
1540 struct isis_passwd *passwd;
1541
hassof390d2c2004-09-10 20:48:21 +00001542 if (snp_type == ISIS_SNP_CSNP_FLAG)
1543 {
1544 /* getting the header info */
1545 typechar = 'C';
1546 chdr =
1547 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001548 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1549 pdu_len = ntohs (chdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001550 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001551 pdu_len > ISO_MTU(circuit) ||
1552 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001553 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001554 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1555 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001556 }
jardineb5d44e2003-12-23 08:09:43 +00001557 }
hassof390d2c2004-09-10 20:48:21 +00001558 else
1559 {
1560 typechar = 'P';
1561 phdr =
1562 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001563 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1564 pdu_len = ntohs (phdr->pdu_len);
Avneesh Sachdeva22ab5a2012-05-05 23:50:30 -07001565 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001566 pdu_len > ISO_MTU(circuit) ||
1567 pdu_len > stream_get_endp (circuit->rcv_stream))
hassof390d2c2004-09-10 20:48:21 +00001568 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001569 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1570 return ISIS_WARNING;
hassof390d2c2004-09-10 20:48:21 +00001571 }
jardineb5d44e2003-12-23 08:09:43 +00001572 }
jardineb5d44e2003-12-23 08:09:43 +00001573
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001574 /*
1575 * Set the stream endp to PDU length, ignoring additional padding
1576 * introduced by transport chips.
1577 */
1578 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1579 stream_set_endp (circuit->rcv_stream, pdu_len);
1580
jardineb5d44e2003-12-23 08:09:43 +00001581 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
hassof390d2c2004-09-10 20:48:21 +00001582 if (circuit->ext_domain)
1583 {
jardineb5d44e2003-12-23 08:09:43 +00001584
hasso529d65b2004-12-24 00:14:50 +00001585 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1586 "skipping: circuit externalDomain = true",
1587 circuit->area->area_tag,
1588 level, typechar, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00001589
1590 return ISIS_OK;
1591 }
hassof390d2c2004-09-10 20:48:21 +00001592
1593 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
Josh Bailey3f045a02012-03-24 08:35:20 -07001594 if (!accept_level (level, circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00001595 {
1596
hasso529d65b2004-12-24 00:14:50 +00001597 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1598 "skipping: circuit type %s does not match level %d",
1599 circuit->area->area_tag,
1600 level,
1601 typechar,
1602 circuit->interface->name,
Josh Bailey3f045a02012-03-24 08:35:20 -07001603 circuit_t2string (circuit->is_type), level);
hassof390d2c2004-09-10 20:48:21 +00001604
1605 return ISIS_OK;
1606 }
1607
1608 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1609 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
Josh Bailey3f045a02012-03-24 08:35:20 -07001610 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1611 (!circuit->u.bc.is_dr[level - 1]))
hassof390d2c2004-09-10 20:48:21 +00001612 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001613 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1614 "skipping: we are not the DIS",
1615 circuit->area->area_tag,
1616 level,
1617 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001618
Josh Bailey3f045a02012-03-24 08:35:20 -07001619 return ISIS_OK;
hassof390d2c2004-09-10 20:48:21 +00001620 }
jardineb5d44e2003-12-23 08:09:43 +00001621
1622 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1623
1624 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1625 * - already checked */
1626
1627 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1628 /* for broadcast circuits, snpa should be compared */
1629 /* FIXME : Do we need to check SNPA? */
hassof390d2c2004-09-10 20:48:21 +00001630 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1631 {
1632 if (snp_type == ISIS_SNP_CSNP_FLAG)
1633 {
1634 adj =
1635 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1636 }
1637 else
1638 {
1639 /* a psnp on a broadcast, how lovely of Juniper :) */
1640 adj =
1641 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1642 }
1643 if (!adj)
1644 return ISIS_OK; /* Silently discard */
jardineb5d44e2003-12-23 08:09:43 +00001645 }
hassof390d2c2004-09-10 20:48:21 +00001646 else
1647 {
1648 if (!circuit->u.p2p.neighbor)
Josh Bailey3f045a02012-03-24 08:35:20 -07001649 {
1650 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1651 return ISIS_OK; /* Silently discard */
1652 }
hassof390d2c2004-09-10 20:48:21 +00001653 }
jardineb5d44e2003-12-23 08:09:43 +00001654
1655 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1656
1657 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1658
1659 memset (&tlvs, 0, sizeof (struct tlvs));
1660
1661 /* parse the SNP */
1662 expected |= TLVFLAG_LSP_ENTRIES;
1663 expected |= TLVFLAG_AUTH_INFO;
Josh Bailey3f045a02012-03-24 08:35:20 -07001664
1665 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001666 retval = parse_tlvs (circuit->area->area_tag,
hassof390d2c2004-09-10 20:48:21 +00001667 STREAM_PNT (circuit->rcv_stream),
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001668 pdu_len - stream_get_getp (circuit->rcv_stream),
Josh Bailey3f045a02012-03-24 08:35:20 -07001669 &expected, &found, &tlvs, &auth_tlv_offset);
jardineb5d44e2003-12-23 08:09:43 +00001670
hassof390d2c2004-09-10 20:48:21 +00001671 if (retval > ISIS_WARNING)
1672 {
1673 zlog_warn ("something went very wrong processing SNP");
1674 free_tlvs (&tlvs);
1675 return retval;
1676 }
jardineb5d44e2003-12-23 08:09:43 +00001677
Josh Bailey3f045a02012-03-24 08:35:20 -07001678 if (level == IS_LEVEL_1)
hasso1cbc5622005-01-01 10:29:51 +00001679 passwd = &circuit->area->area_passwd;
1680 else
1681 passwd = &circuit->area->domain_passwd;
1682
1683 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
hassof390d2c2004-09-10 20:48:21 +00001684 {
hasso1cbc5622005-01-01 10:29:51 +00001685 if (passwd->type)
Josh Bailey3f045a02012-03-24 08:35:20 -07001686 {
1687 if (!(found & TLVFLAG_AUTH_INFO) ||
1688 authentication_check (&tlvs.auth_info, passwd,
1689 circuit->rcv_stream, auth_tlv_offset))
1690 {
1691 isis_event_auth_failure (circuit->area->area_tag,
1692 "SNP authentication" " failure",
1693 phdr ? phdr->source_id :
1694 chdr->source_id);
1695 free_tlvs (&tlvs);
1696 return ISIS_OK;
1697 }
1698 }
hassof390d2c2004-09-10 20:48:21 +00001699 }
jardineb5d44e2003-12-23 08:09:43 +00001700
1701 /* debug isis snp-packets */
hassof390d2c2004-09-10 20:48:21 +00001702 if (isis->debugs & DEBUG_SNP_PACKETS)
1703 {
hasso529d65b2004-12-24 00:14:50 +00001704 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1705 circuit->area->area_tag,
1706 level,
1707 typechar, snpa_print (ssnpa), circuit->interface->name);
hassof390d2c2004-09-10 20:48:21 +00001708 if (tlvs.lsp_entries)
1709 {
hasso3fdb2dd2005-09-28 18:45:54 +00001710 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001711 {
hasso529d65b2004-12-24 00:14:50 +00001712 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1713 " cksum 0x%04x, lifetime %us",
1714 circuit->area->area_tag,
1715 typechar,
1716 rawlspid_print (entry->lsp_id),
1717 ntohl (entry->seq_num),
1718 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001719 }
1720 }
jardineb5d44e2003-12-23 08:09:43 +00001721 }
jardineb5d44e2003-12-23 08:09:43 +00001722
1723 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
hassof390d2c2004-09-10 20:48:21 +00001724 if (tlvs.lsp_entries)
1725 {
hasso3fdb2dd2005-09-28 18:45:54 +00001726 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
hassof390d2c2004-09-10 20:48:21 +00001727 {
1728 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1729 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1730 if (lsp)
1731 {
1732 /* 7.3.15.2 b) 1) is this LSP newer */
1733 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1734 entry->checksum, entry->rem_lifetime);
1735 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1736 if (cmp == LSP_EQUAL)
1737 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001738 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1739 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001740 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001741 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
hassof390d2c2004-09-10 20:48:21 +00001742 else if (cmp == LSP_OLDER)
1743 {
1744 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1745 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1746 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001747 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
hassof390d2c2004-09-10 20:48:21 +00001748 else
1749 {
hassof390d2c2004-09-10 20:48:21 +00001750 if (own_lsp)
1751 {
1752 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1753 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1754 }
1755 else
1756 {
1757 ISIS_SET_FLAG (lsp->SSNflags, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001758 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1759 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001760 }
1761 }
1762 }
1763 else
1764 {
1765 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1766 * insert it and set SSN on it */
1767 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1768 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1769 {
1770 lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime),
1771 0, 0, entry->checksum, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001772 lsp->area = circuit->area;
hassof390d2c2004-09-10 20:48:21 +00001773 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07001774 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001775 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1776 }
1777 }
jardineb5d44e2003-12-23 08:09:43 +00001778 }
1779 }
jardineb5d44e2003-12-23 08:09:43 +00001780
1781 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
hassof390d2c2004-09-10 20:48:21 +00001782 if (snp_type == ISIS_SNP_CSNP_FLAG)
1783 {
1784 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07001785 * Build a list from our own LSP db bounded with
1786 * start_lsp_id and stop_lsp_id
hassof390d2c2004-09-10 20:48:21 +00001787 */
1788 lsp_list = list_new ();
1789 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1790 lsp_list, circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001791
hassof390d2c2004-09-10 20:48:21 +00001792 /* Fixme: Find a better solution */
1793 if (tlvs.lsp_entries)
1794 {
paul1eb8ef22005-04-07 07:30:20 +00001795 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
hassof390d2c2004-09-10 20:48:21 +00001796 {
paul1eb8ef22005-04-07 07:30:20 +00001797 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
hassof390d2c2004-09-10 20:48:21 +00001798 {
1799 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1800 {
1801 list_delete_node (lsp_list, node2);
1802 break;
1803 }
1804 }
1805 }
1806 }
1807 /* on remaining LSPs we set SRM (neighbor knew not of) */
hasso3fdb2dd2005-09-28 18:45:54 +00001808 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00001809 ISIS_SET_FLAG (lsp->SRMflags, circuit);
hassof390d2c2004-09-10 20:48:21 +00001810 /* lets free it */
Josh Bailey3f045a02012-03-24 08:35:20 -07001811 list_delete (lsp_list);
1812
jardineb5d44e2003-12-23 08:09:43 +00001813 }
jardineb5d44e2003-12-23 08:09:43 +00001814
1815 free_tlvs (&tlvs);
1816 return retval;
1817}
1818
hasso92365882005-01-18 13:53:33 +00001819static int
hassof390d2c2004-09-10 20:48:21 +00001820process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001821{
Josh Bailey3f045a02012-03-24 08:35:20 -07001822 if (isis->debugs & DEBUG_SNP_PACKETS)
1823 {
1824 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1825 circuit->area->area_tag, level, circuit->interface->name,
1826 circuit_t2string (circuit->is_type), circuit->circuit_id);
1827 if (isis->debugs & DEBUG_PACKET_DUMP)
1828 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1829 stream_get_endp (circuit->rcv_stream));
1830 }
1831
jardineb5d44e2003-12-23 08:09:43 +00001832 /* Sanity check - FIXME: move to correct place */
hassof390d2c2004-09-10 20:48:21 +00001833 if ((stream_get_endp (circuit->rcv_stream) -
1834 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1835 {
1836 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1837 return ISIS_WARNING;
1838 }
jardineb5d44e2003-12-23 08:09:43 +00001839
1840 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1841}
1842
hasso92365882005-01-18 13:53:33 +00001843static int
hassof390d2c2004-09-10 20:48:21 +00001844process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001845{
Josh Bailey3f045a02012-03-24 08:35:20 -07001846 if (isis->debugs & DEBUG_SNP_PACKETS)
1847 {
1848 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1849 circuit->area->area_tag, level, circuit->interface->name,
1850 circuit_t2string (circuit->is_type), circuit->circuit_id);
1851 if (isis->debugs & DEBUG_PACKET_DUMP)
1852 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1853 stream_get_endp (circuit->rcv_stream));
1854 }
1855
hassof390d2c2004-09-10 20:48:21 +00001856 if ((stream_get_endp (circuit->rcv_stream) -
1857 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1858 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001859 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
hassof390d2c2004-09-10 20:48:21 +00001860 return ISIS_WARNING;
1861 }
jardineb5d44e2003-12-23 08:09:43 +00001862
1863 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1864}
1865
jardineb5d44e2003-12-23 08:09:43 +00001866/*
1867 * Process ISH
1868 * ISO - 10589
1869 * Section 8.2.2 - Receiving ISH PDUs by an intermediate system
1870 * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid
hassof390d2c2004-09-10 20:48:21 +00001871 * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59
1872 * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00
1873 * 0x03 0x00 0x81 0x01 0xcc
jardineb5d44e2003-12-23 08:09:43 +00001874 */
hasso92365882005-01-18 13:53:33 +00001875static int
jardineb5d44e2003-12-23 08:09:43 +00001876process_is_hello (struct isis_circuit *circuit)
1877{
1878 struct isis_adjacency *adj;
1879 int retval = ISIS_OK;
1880 u_char neigh_len;
1881 u_char *sysid;
1882
Josh Bailey3f045a02012-03-24 08:35:20 -07001883 if (isis->debugs & DEBUG_ADJ_PACKETS)
1884 {
1885 zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u",
1886 circuit->area->area_tag, circuit->interface->name,
1887 circuit_t2string (circuit->is_type), circuit->circuit_id);
1888 if (isis->debugs & DEBUG_PACKET_DUMP)
1889 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1890 stream_get_endp (circuit->rcv_stream));
1891 }
1892
jardineb5d44e2003-12-23 08:09:43 +00001893 /* In this point in time we are not yet able to handle is_hellos
1894 * on lan - Sorry juniper...
1895 */
1896 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1897 return retval;
1898
1899 neigh_len = stream_getc (circuit->rcv_stream);
hassof390d2c2004-09-10 20:48:21 +00001900 sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00001901 adj = circuit->u.p2p.neighbor;
hassof390d2c2004-09-10 20:48:21 +00001902 if (!adj)
1903 {
1904 /* 8.2.2 */
Paul Jakma41b36e92006-12-08 01:09:50 +00001905 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001906 if (adj == NULL)
1907 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001908
hassof390d2c2004-09-10 20:48:21 +00001909 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1910 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1911 circuit->u.p2p.neighbor = adj;
1912 }
1913 /* 8.2.2 a) */
1914 if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid,
1915 ISIS_SYS_ID_LEN))
1916 {
1917 /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */
1918 /* 8.2.2 a) 2) delete the adj */
1919 XFREE (MTYPE_ISIS_ADJACENCY, adj);
1920 /* 8.2.2 a) 3) create a new adj */
Paul Jakma41b36e92006-12-08 01:09:50 +00001921 adj = isis_new_adj (sysid, NULL, 0, circuit);
hassof390d2c2004-09-10 20:48:21 +00001922 if (adj == NULL)
1923 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001924
hassof390d2c2004-09-10 20:48:21 +00001925 /* 8.2.2 a) 3) i */
1926 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1927 /* 8.2.2 a) 3) ii */
1928 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
1929 /* 8.2.2 a) 4) quite meaningless */
1930 }
jardineb5d44e2003-12-23 08:09:43 +00001931 /* 8.2.2 b) ignore on condition */
hassof390d2c2004-09-10 20:48:21 +00001932 if ((adj->adj_state == ISIS_ADJ_INITIALIZING) &&
1933 (adj->sys_type == ISIS_SYSTYPE_IS))
1934 {
1935 /* do nothing */
1936 }
1937 else
1938 {
1939 /* 8.2.2 c) respond with a p2p IIH */
1940 send_hello (circuit, 1);
1941 }
jardineb5d44e2003-12-23 08:09:43 +00001942 /* 8.2.2 d) type is IS */
hassof390d2c2004-09-10 20:48:21 +00001943 adj->sys_type = ISIS_SYSTYPE_IS;
jardineb5d44e2003-12-23 08:09:43 +00001944 /* 8.2.2 e) FIXME: Circuit type of? */
1945
jardineb5d44e2003-12-23 08:09:43 +00001946 return retval;
1947}
1948
jardineb5d44e2003-12-23 08:09:43 +00001949/*
1950 * PDU Dispatcher
1951 */
1952
hasso92365882005-01-18 13:53:33 +00001953static int
hassof390d2c2004-09-10 20:48:21 +00001954isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
jardineb5d44e2003-12-23 08:09:43 +00001955{
jardineb5d44e2003-12-23 08:09:43 +00001956 struct isis_fixed_hdr *hdr;
jardineb5d44e2003-12-23 08:09:43 +00001957
hassof390d2c2004-09-10 20:48:21 +00001958 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001959
1960 /*
1961 * Let's first read data from stream to the header
1962 */
hassof390d2c2004-09-10 20:48:21 +00001963 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
jardineb5d44e2003-12-23 08:09:43 +00001964
hassof390d2c2004-09-10 20:48:21 +00001965 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1966 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001967 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
hassof390d2c2004-09-10 20:48:21 +00001968 return ISIS_ERROR;
1969 }
jardineb5d44e2003-12-23 08:09:43 +00001970
1971 /* now we need to know if this is an ISO 9542 packet and
1972 * take real good care of it, waaa!
1973 */
hassof390d2c2004-09-10 20:48:21 +00001974 if (hdr->idrp == ISO9542_ESIS)
1975 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001976 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
1977 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00001978 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001979 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1980
jardineb5d44e2003-12-23 08:09:43 +00001981 /*
1982 * and then process it
1983 */
1984
hassof390d2c2004-09-10 20:48:21 +00001985 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1986 {
1987 zlog_err ("Fixed header length = %d", hdr->length);
1988 return ISIS_ERROR;
1989 }
jardineb5d44e2003-12-23 08:09:43 +00001990
hassof390d2c2004-09-10 20:48:21 +00001991 if (hdr->version1 != 1)
1992 {
1993 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1994 return ISIS_WARNING;
1995 }
jardineb5d44e2003-12-23 08:09:43 +00001996 /* either 6 or 0 */
hassof390d2c2004-09-10 20:48:21 +00001997 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1998 {
1999 zlog_err
2000 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2001 "while the parameter for this IS is %u", hdr->id_len,
2002 ISIS_SYS_ID_LEN);
2003 return ISIS_ERROR;
2004 }
jardineb5d44e2003-12-23 08:09:43 +00002005
hassof390d2c2004-09-10 20:48:21 +00002006 if (hdr->version2 != 1)
2007 {
2008 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2009 return ISIS_WARNING;
2010 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002011
2012 if (circuit->is_passive)
2013 {
2014 zlog_warn ("Received ISIS PDU on passive circuit %s",
2015 circuit->interface->name);
2016 return ISIS_WARNING;
2017 }
2018
jardineb5d44e2003-12-23 08:09:43 +00002019 /* either 3 or 0 */
hassof390d2c2004-09-10 20:48:21 +00002020 if ((hdr->max_area_addrs != 0)
2021 && (hdr->max_area_addrs != isis->max_area_addrs))
2022 {
2023 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2024 "received PDU %u while the parameter for this IS is %u",
2025 hdr->max_area_addrs, isis->max_area_addrs);
2026 return ISIS_ERROR;
2027 }
jardineb5d44e2003-12-23 08:09:43 +00002028
hassof390d2c2004-09-10 20:48:21 +00002029 switch (hdr->pdu_type)
2030 {
2031 case L1_LAN_HELLO:
2032 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2033 break;
2034 case L2_LAN_HELLO:
2035 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2036 break;
2037 case P2P_HELLO:
2038 retval = process_p2p_hello (circuit);
2039 break;
2040 case L1_LINK_STATE:
2041 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2042 break;
2043 case L2_LINK_STATE:
2044 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2045 break;
2046 case L1_COMPLETE_SEQ_NUM:
2047 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2048 break;
2049 case L2_COMPLETE_SEQ_NUM:
2050 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2051 break;
2052 case L1_PARTIAL_SEQ_NUM:
2053 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2054 break;
2055 case L2_PARTIAL_SEQ_NUM:
2056 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2057 break;
2058 default:
2059 return ISIS_ERROR;
2060 }
jardineb5d44e2003-12-23 08:09:43 +00002061
2062 return retval;
2063}
2064
jardineb5d44e2003-12-23 08:09:43 +00002065#ifdef GNU_LINUX
2066int
2067isis_receive (struct thread *thread)
2068{
jardineb5d44e2003-12-23 08:09:43 +00002069 struct isis_circuit *circuit;
2070 u_char ssnpa[ETH_ALEN];
2071 int retval;
2072
2073 /*
2074 * Get the circuit
2075 */
2076 circuit = THREAD_ARG (thread);
2077 assert (circuit);
2078
2079 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002080 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002081 else
2082 stream_reset (circuit->rcv_stream);
2083
2084 retval = circuit->rx (circuit, ssnpa);
hassof390d2c2004-09-10 20:48:21 +00002085 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002086
2087 if (retval == ISIS_OK)
2088 retval = isis_handle_pdu (circuit, ssnpa);
2089
2090 /*
2091 * prepare for next packet.
2092 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002093 if (!circuit->is_passive)
2094 {
2095 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
2096 circuit->fd);
2097 }
jardineb5d44e2003-12-23 08:09:43 +00002098
2099 return retval;
2100}
2101
2102#else
2103int
2104isis_receive (struct thread *thread)
2105{
jardineb5d44e2003-12-23 08:09:43 +00002106 struct isis_circuit *circuit;
2107 u_char ssnpa[ETH_ALEN];
2108 int retval;
2109
2110 /*
2111 * Get the circuit
2112 */
2113 circuit = THREAD_ARG (thread);
2114 assert (circuit);
2115
hassof390d2c2004-09-10 20:48:21 +00002116 circuit->t_read = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002117
2118 if (circuit->rcv_stream == NULL)
hassof390d2c2004-09-10 20:48:21 +00002119 circuit->rcv_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002120 else
2121 stream_reset (circuit->rcv_stream);
2122
2123 retval = circuit->rx (circuit, ssnpa);
2124
2125 if (retval == ISIS_OK)
2126 retval = isis_handle_pdu (circuit, ssnpa);
2127
2128 /*
2129 * prepare for next packet.
2130 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002131 if (!circuit->is_passive)
2132 {
2133 circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
2134 listcount
2135 (circuit->area->circuit_list) *
2136 100);
2137 }
jardineb5d44e2003-12-23 08:09:43 +00002138
2139 return retval;
2140}
2141
2142#endif
2143
2144 /* filling of the fixed isis header */
2145void
2146fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2147{
2148 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2149
2150 hdr->idrp = ISO10589_ISIS;
2151
hassof390d2c2004-09-10 20:48:21 +00002152 switch (pdu_type)
2153 {
2154 case L1_LAN_HELLO:
2155 case L2_LAN_HELLO:
2156 hdr->length = ISIS_LANHELLO_HDRLEN;
2157 break;
2158 case P2P_HELLO:
2159 hdr->length = ISIS_P2PHELLO_HDRLEN;
2160 break;
2161 case L1_LINK_STATE:
2162 case L2_LINK_STATE:
2163 hdr->length = ISIS_LSP_HDR_LEN;
2164 break;
2165 case L1_COMPLETE_SEQ_NUM:
2166 case L2_COMPLETE_SEQ_NUM:
2167 hdr->length = ISIS_CSNP_HDRLEN;
2168 break;
2169 case L1_PARTIAL_SEQ_NUM:
2170 case L2_PARTIAL_SEQ_NUM:
2171 hdr->length = ISIS_PSNP_HDRLEN;
2172 break;
2173 default:
2174 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2175 return;
2176 }
jardineb5d44e2003-12-23 08:09:43 +00002177 hdr->length += ISIS_FIXED_HDR_LEN;
2178 hdr->pdu_type = pdu_type;
2179 hdr->version1 = 1;
hassof390d2c2004-09-10 20:48:21 +00002180 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
jardineb5d44e2003-12-23 08:09:43 +00002181 hdr->version2 = 1;
hassof390d2c2004-09-10 20:48:21 +00002182 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
jardineb5d44e2003-12-23 08:09:43 +00002183}
2184
jardineb5d44e2003-12-23 08:09:43 +00002185/*
2186 * SEND SIDE
2187 */
hasso92365882005-01-18 13:53:33 +00002188static void
jardineb5d44e2003-12-23 08:09:43 +00002189fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
hassof390d2c2004-09-10 20:48:21 +00002190 struct stream *stream)
jardineb5d44e2003-12-23 08:09:43 +00002191{
hassof390d2c2004-09-10 20:48:21 +00002192 fill_fixed_hdr (hdr, pdu_type);
jardineb5d44e2003-12-23 08:09:43 +00002193
2194 stream_putc (stream, hdr->idrp);
2195 stream_putc (stream, hdr->length);
2196 stream_putc (stream, hdr->version1);
2197 stream_putc (stream, hdr->id_len);
2198 stream_putc (stream, hdr->pdu_type);
2199 stream_putc (stream, hdr->version2);
2200 stream_putc (stream, hdr->reserved);
2201 stream_putc (stream, hdr->max_area_addrs);
2202
2203 return;
2204}
2205
jardineb5d44e2003-12-23 08:09:43 +00002206int
2207send_hello (struct isis_circuit *circuit, int level)
2208{
2209 struct isis_fixed_hdr fixed_hdr;
2210 struct isis_lan_hello_hdr hello_hdr;
2211 struct isis_p2p_hello_hdr p2p_hello_hdr;
Josh Bailey3f045a02012-03-24 08:35:20 -07002212 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2213 unsigned long len_pointer, length, auth_tlv_offset = 0;
jardineb5d44e2003-12-23 08:09:43 +00002214 u_int32_t interval;
jardineb5d44e2003-12-23 08:09:43 +00002215 int retval;
2216
Josh Bailey3f045a02012-03-24 08:35:20 -07002217 if (circuit->is_passive)
2218 return ISIS_OK;
2219
hassof390d2c2004-09-10 20:48:21 +00002220 if (circuit->interface->mtu == 0)
2221 {
2222 zlog_warn ("circuit has zero MTU");
2223 return ISIS_WARNING;
2224 }
jardineb5d44e2003-12-23 08:09:43 +00002225
2226 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00002227 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00002228 else
2229 stream_reset (circuit->snd_stream);
2230
2231 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
Josh Bailey3f045a02012-03-24 08:35:20 -07002232 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002233 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2234 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002235 else
hassof390d2c2004-09-10 20:48:21 +00002236 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2237 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002238 else
hassof390d2c2004-09-10 20:48:21 +00002239 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002240
2241 /*
2242 * Fill LAN Level 1 or 2 Hello PDU header
2243 */
2244 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
hassof390d2c2004-09-10 20:48:21 +00002245 interval = circuit->hello_multiplier[level - 1] *
jardineb5d44e2003-12-23 08:09:43 +00002246 circuit->hello_interval[level - 1];
2247 if (interval > USHRT_MAX)
2248 interval = USHRT_MAX;
Josh Bailey3f045a02012-03-24 08:35:20 -07002249 hello_hdr.circuit_t = circuit->is_type;
jardineb5d44e2003-12-23 08:09:43 +00002250 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002251 hello_hdr.hold_time = htons ((u_int16_t) interval);
jardineb5d44e2003-12-23 08:09:43 +00002252
hassof390d2c2004-09-10 20:48:21 +00002253 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
paul9985f832005-02-09 15:51:56 +00002254 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
jardineb5d44e2003-12-23 08:09:43 +00002255
2256 /* copy the shared part of the hello to the p2p hello if needed */
hassof390d2c2004-09-10 20:48:21 +00002257 if (circuit->circ_type == CIRCUIT_T_P2P)
2258 {
2259 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2260 p2p_hello_hdr.local_id = circuit->circuit_id;
2261 /* FIXME: need better understanding */
2262 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
jardineb5d44e2003-12-23 08:09:43 +00002263 }
hassof390d2c2004-09-10 20:48:21 +00002264 else
2265 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002266 hello_hdr.prio = circuit->priority[level - 1];
2267 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002268 {
2269 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2270 ISIS_SYS_ID_LEN + 1);
2271 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002272 else if (level == IS_LEVEL_2)
hassof390d2c2004-09-10 20:48:21 +00002273 {
2274 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2275 ISIS_SYS_ID_LEN + 1);
2276 }
2277 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2278 }
jardineb5d44e2003-12-23 08:09:43 +00002279
2280 /*
Josh Bailey3f045a02012-03-24 08:35:20 -07002281 * Then the variable length part.
jardineb5d44e2003-12-23 08:09:43 +00002282 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002283
jardineb5d44e2003-12-23 08:09:43 +00002284 /* add circuit password */
Josh Bailey3f045a02012-03-24 08:35:20 -07002285 switch (circuit->passwd.type)
2286 {
2287 /* Cleartext */
2288 case ISIS_PASSWD_TYPE_CLEARTXT:
2289 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2290 circuit->passwd.passwd, circuit->snd_stream))
2291 return ISIS_WARNING;
2292 break;
2293
2294 /* HMAC MD5 */
2295 case ISIS_PASSWD_TYPE_HMAC_MD5:
2296 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2297 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2298 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2299 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2300 hmac_md5_hash, circuit->snd_stream))
2301 return ISIS_WARNING;
2302 break;
2303
2304 default:
2305 break;
2306 }
2307
jardineb5d44e2003-12-23 08:09:43 +00002308 /* Area Addresses TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002309 if (listcount (circuit->area->area_addrs) == 0)
2310 return ISIS_WARNING;
2311 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2312 return ISIS_WARNING;
jardineb5d44e2003-12-23 08:09:43 +00002313
2314 /* LAN Neighbors TLV */
hassof390d2c2004-09-10 20:48:21 +00002315 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2316 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002317 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2318 listcount (circuit->u.bc.lan_neighs[0]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002319 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2320 circuit->snd_stream))
2321 return ISIS_WARNING;
Josh Bailey3f045a02012-03-24 08:35:20 -07002322 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2323 listcount (circuit->u.bc.lan_neighs[1]) > 0)
hassof390d2c2004-09-10 20:48:21 +00002324 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2325 circuit->snd_stream))
2326 return ISIS_WARNING;
2327 }
jardineb5d44e2003-12-23 08:09:43 +00002328
2329 /* Protocols Supported TLV */
hassof390d2c2004-09-10 20:48:21 +00002330 if (circuit->nlpids.count > 0)
jardineb5d44e2003-12-23 08:09:43 +00002331 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2332 return ISIS_WARNING;
2333 /* IP interface Address TLV */
Josh Bailey3f045a02012-03-24 08:35:20 -07002334 if (circuit->ip_router && circuit->ip_addrs &&
2335 listcount (circuit->ip_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002336 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2337 return ISIS_WARNING;
2338
hassof390d2c2004-09-10 20:48:21 +00002339#ifdef HAVE_IPV6
jardineb5d44e2003-12-23 08:09:43 +00002340 /* IPv6 Interface Address TLV */
hassof390d2c2004-09-10 20:48:21 +00002341 if (circuit->ipv6_router && circuit->ipv6_link &&
Josh Bailey3f045a02012-03-24 08:35:20 -07002342 listcount (circuit->ipv6_link) > 0)
jardineb5d44e2003-12-23 08:09:43 +00002343 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2344 return ISIS_WARNING;
2345#endif /* HAVE_IPV6 */
2346
Josh Bailey3f045a02012-03-24 08:35:20 -07002347 if (circuit->pad_hellos)
jardineb5d44e2003-12-23 08:09:43 +00002348 if (tlv_add_padding (circuit->snd_stream))
2349 return ISIS_WARNING;
2350
paul9985f832005-02-09 15:51:56 +00002351 length = stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002352 /* Update PDU length */
hassof390d2c2004-09-10 20:48:21 +00002353 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
jardineb5d44e2003-12-23 08:09:43 +00002354
Josh Bailey3f045a02012-03-24 08:35:20 -07002355 /* For HMAC MD5 we need to compute the md5 hash and store it */
2356 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2357 {
2358 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2359 stream_get_endp (circuit->snd_stream),
2360 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
2361 (caddr_t) &hmac_md5_hash);
2362 /* Copy the hash into the stream */
2363 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2364 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2365 }
jardineb5d44e2003-12-23 08:09:43 +00002366
hassof390d2c2004-09-10 20:48:21 +00002367 if (isis->debugs & DEBUG_ADJ_PACKETS)
2368 {
2369 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2370 {
hasso529d65b2004-12-24 00:14:50 +00002371 zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld",
2372 circuit->area->area_tag, level, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002373 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002374 length);
hassof390d2c2004-09-10 20:48:21 +00002375 }
2376 else
2377 {
hasso529d65b2004-12-24 00:14:50 +00002378 zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld",
2379 circuit->area->area_tag, circuit->interface->name,
hasso29e50b22005-09-01 18:18:47 +00002380 /* FIXME: use %z when we stop supporting old compilers. */
Josh Bailey3f045a02012-03-24 08:35:20 -07002381 length);
hassof390d2c2004-09-10 20:48:21 +00002382 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002383 if (isis->debugs & DEBUG_PACKET_DUMP)
2384 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2385 stream_get_endp (circuit->snd_stream));
jardineb5d44e2003-12-23 08:09:43 +00002386 }
jardineb5d44e2003-12-23 08:09:43 +00002387
Josh Bailey3f045a02012-03-24 08:35:20 -07002388 retval = circuit->tx (circuit, level);
2389 if (retval != ISIS_OK)
2390 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2391 circuit->area->area_tag, level, circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00002392
Josh Bailey3f045a02012-03-24 08:35:20 -07002393 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002394}
2395
2396int
2397send_lan_l1_hello (struct thread *thread)
2398{
jardineb5d44e2003-12-23 08:09:43 +00002399 struct isis_circuit *circuit;
2400 int retval;
2401
2402 circuit = THREAD_ARG (thread);
2403 assert (circuit);
2404 circuit->u.bc.t_send_lan_hello[0] = NULL;
2405
2406 if (circuit->u.bc.run_dr_elect[0])
hassof390d2c2004-09-10 20:48:21 +00002407 retval = isis_dr_elect (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002408
Josh Bailey3f045a02012-03-24 08:35:20 -07002409 retval = send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002410
2411 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002412 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
2413 send_lan_l1_hello, circuit,
2414 isis_jitter (circuit->hello_interval[0], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002415
2416 return retval;
2417}
2418
2419int
2420send_lan_l2_hello (struct thread *thread)
2421{
2422 struct isis_circuit *circuit;
2423 int retval;
2424
2425 circuit = THREAD_ARG (thread);
2426 assert (circuit);
2427 circuit->u.bc.t_send_lan_hello[1] = NULL;
2428
2429 if (circuit->u.bc.run_dr_elect[1])
2430 retval = isis_dr_elect (circuit, 2);
2431
Josh Bailey3f045a02012-03-24 08:35:20 -07002432 retval = send_hello (circuit, 2);
jardineb5d44e2003-12-23 08:09:43 +00002433
hassof390d2c2004-09-10 20:48:21 +00002434 /* set next timer thread */
2435 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
2436 send_lan_l2_hello, circuit,
2437 isis_jitter (circuit->hello_interval[1], IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002438
2439 return retval;
2440}
2441
2442int
2443send_p2p_hello (struct thread *thread)
2444{
2445 struct isis_circuit *circuit;
2446
2447 circuit = THREAD_ARG (thread);
2448 assert (circuit);
2449 circuit->u.p2p.t_send_p2p_hello = NULL;
2450
hassof390d2c2004-09-10 20:48:21 +00002451 send_hello (circuit, 1);
jardineb5d44e2003-12-23 08:09:43 +00002452
hassof390d2c2004-09-10 20:48:21 +00002453 /* set next timer thread */
2454 THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
2455 circuit, isis_jitter (circuit->hello_interval[1],
2456 IIH_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002457
2458 return ISIS_OK;
2459}
2460
hasso92365882005-01-18 13:53:33 +00002461static int
hassof390d2c2004-09-10 20:48:21 +00002462build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2463 struct isis_circuit *circuit)
jardineb5d44e2003-12-23 08:09:43 +00002464{
2465 struct isis_fixed_hdr fixed_hdr;
2466 struct isis_passwd *passwd;
jardineb5d44e2003-12-23 08:09:43 +00002467 unsigned long lenp;
2468 u_int16_t length;
Josh Bailey3f045a02012-03-24 08:35:20 -07002469 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2470 unsigned long auth_tlv_offset = 0;
2471 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002472
Josh Bailey3f045a02012-03-24 08:35:20 -07002473 if (circuit->snd_stream == NULL)
2474 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2475 else
2476 stream_reset (circuit->snd_stream);
2477
2478 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002479 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2480 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002481 else
hassof390d2c2004-09-10 20:48:21 +00002482 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2483 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002484
2485 /*
2486 * Fill Level 1 or 2 Complete Sequence Numbers header
2487 */
2488
paul9985f832005-02-09 15:51:56 +00002489 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002490 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002491 /* no need to send the source here, it is always us if we csnp */
2492 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2493 /* with zero circuit id - ref 9.10, 9.11 */
2494 stream_putc (circuit->snd_stream, 0x00);
2495
2496 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2497 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2498
2499 /*
2500 * And TLVs
2501 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002502 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002503 passwd = &circuit->area->area_passwd;
2504 else
2505 passwd = &circuit->area->domain_passwd;
2506
hasso1cbc5622005-01-01 10:29:51 +00002507 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002508 {
2509 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002510 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002511 /* Cleartext */
2512 case ISIS_PASSWD_TYPE_CLEARTXT:
2513 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2514 passwd->passwd, circuit->snd_stream))
2515 return ISIS_WARNING;
2516 break;
2517
2518 /* HMAC MD5 */
2519 case ISIS_PASSWD_TYPE_HMAC_MD5:
2520 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2521 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2522 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2523 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2524 hmac_md5_hash, circuit->snd_stream))
2525 return ISIS_WARNING;
2526 break;
2527
2528 default:
2529 break;
hassof390d2c2004-09-10 20:48:21 +00002530 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002531 }
2532
2533 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2534 if (retval != ISIS_OK)
2535 return retval;
2536
paul9985f832005-02-09 15:51:56 +00002537 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002538 /* Update PU length */
2539 stream_putw_at (circuit->snd_stream, lenp, length);
2540
Josh Bailey3f045a02012-03-24 08:35:20 -07002541 /* For HMAC MD5 we need to compute the md5 hash and store it */
2542 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2543 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2544 {
2545 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2546 stream_get_endp(circuit->snd_stream),
2547 (unsigned char *) &passwd->passwd, passwd->len,
2548 (caddr_t) &hmac_md5_hash);
2549 /* Copy the hash into the stream */
2550 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2551 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2552 }
2553
jardineb5d44e2003-12-23 08:09:43 +00002554 return retval;
2555}
2556
2557/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002558 * Count the maximum number of lsps that can be accomodated by a given size.
2559 */
2560static uint16_t
2561get_max_lsp_count (uint16_t size)
2562{
2563 uint16_t tlv_count;
2564 uint16_t lsp_count;
2565 uint16_t remaining_size;
2566
2567 /* First count the full size TLVs */
2568 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2569 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2570
2571 /* The last TLV, if any */
2572 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2573 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2574 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2575
2576 return lsp_count;
2577}
2578
2579/*
2580 * Calculate the length of Authentication Info. TLV.
2581 */
2582static uint16_t
2583auth_tlv_length (int level, struct isis_circuit *circuit)
2584{
2585 struct isis_passwd *passwd;
2586 uint16_t length;
2587
2588 if (level == IS_LEVEL_1)
2589 passwd = &circuit->area->area_passwd;
2590 else
2591 passwd = &circuit->area->domain_passwd;
2592
2593 /* Also include the length of TLV header */
2594 length = AUTH_INFO_HDRLEN;
2595 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2596 {
2597 switch (passwd->type)
2598 {
2599 /* Cleartext */
2600 case ISIS_PASSWD_TYPE_CLEARTXT:
2601 length += passwd->len;
2602 break;
2603
2604 /* HMAC MD5 */
2605 case ISIS_PASSWD_TYPE_HMAC_MD5:
2606 length += ISIS_AUTH_MD5_SIZE;
2607 break;
2608
2609 default:
2610 break;
2611 }
2612 }
2613
2614 return length;
2615}
2616
2617/*
2618 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2619 */
2620static uint16_t
2621max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2622{
2623 int snp_hdr_len;
2624 int auth_tlv_len;
2625 uint16_t lsp_count;
2626
2627 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2628 if (snp_type == ISIS_SNP_CSNP_FLAG)
2629 snp_hdr_len += ISIS_CSNP_HDRLEN;
2630 else
2631 snp_hdr_len += ISIS_PSNP_HDRLEN;
2632
2633 auth_tlv_len = auth_tlv_length (level, circuit);
2634 lsp_count = get_max_lsp_count (
2635 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002636 return lsp_count;
Josh Bailey3f045a02012-03-24 08:35:20 -07002637}
2638
2639/*
jardineb5d44e2003-12-23 08:09:43 +00002640 * FIXME: support multiple CSNPs
2641 */
2642
2643int
2644send_csnp (struct isis_circuit *circuit, int level)
2645{
jardineb5d44e2003-12-23 08:09:43 +00002646 u_char start[ISIS_SYS_ID_LEN + 2];
2647 u_char stop[ISIS_SYS_ID_LEN + 2];
2648 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002649 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002650 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002651 u_char num_lsps, loop = 1;
2652 int i, retval = ISIS_OK;
2653
2654 if (circuit->area->lspdb[level - 1] == NULL ||
2655 dict_count (circuit->area->lspdb[level - 1]) == 0)
2656 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002657
hassof390d2c2004-09-10 20:48:21 +00002658 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
jardineb5d44e2003-12-23 08:09:43 +00002659 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2660
Josh Bailey3f045a02012-03-24 08:35:20 -07002661 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2662
2663 while (loop)
hassof390d2c2004-09-10 20:48:21 +00002664 {
2665 list = list_new ();
Josh Bailey3f045a02012-03-24 08:35:20 -07002666 lsp_build_list (start, stop, num_lsps, list,
2667 circuit->area->lspdb[level - 1]);
2668 /*
2669 * Update the stop lsp_id before encoding this CSNP.
2670 */
2671 if (listcount (list) < num_lsps)
2672 {
2673 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2674 }
hassof390d2c2004-09-10 20:48:21 +00002675 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002676 {
2677 node = listtail (list);
2678 lsp = listgetdata (node);
2679 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2680 }
jardineb5d44e2003-12-23 08:09:43 +00002681
hassof390d2c2004-09-10 20:48:21 +00002682 retval = build_csnp (level, start, stop, list, circuit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002683 if (retval != ISIS_OK)
2684 {
2685 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2686 circuit->area->area_tag, level, circuit->interface->name);
2687 list_delete (list);
2688 return retval;
2689 }
jardineb5d44e2003-12-23 08:09:43 +00002690
hassof390d2c2004-09-10 20:48:21 +00002691 if (isis->debugs & DEBUG_SNP_PACKETS)
Josh Bailey3f045a02012-03-24 08:35:20 -07002692 {
2693 zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld",
2694 circuit->area->area_tag, level, circuit->interface->name,
2695 stream_get_endp (circuit->snd_stream));
2696 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2697 {
2698 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2699 " cksum 0x%04x, lifetime %us",
2700 circuit->area->area_tag,
2701 rawlspid_print (lsp->lsp_header->lsp_id),
2702 ntohl (lsp->lsp_header->seq_num),
2703 ntohs (lsp->lsp_header->checksum),
2704 ntohs (lsp->lsp_header->rem_lifetime));
2705 }
2706 if (isis->debugs & DEBUG_PACKET_DUMP)
2707 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2708 stream_get_endp (circuit->snd_stream));
2709 }
hassof390d2c2004-09-10 20:48:21 +00002710
Josh Bailey3f045a02012-03-24 08:35:20 -07002711 retval = circuit->tx (circuit, level);
2712 if (retval != ISIS_OK)
2713 {
2714 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2715 circuit->area->area_tag, level,
2716 circuit->interface->name);
2717 list_delete (list);
2718 return retval;
2719 }
2720
2721 /*
2722 * Start lsp_id of the next CSNP should be one plus the
2723 * stop lsp_id in this current CSNP.
2724 */
2725 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2726 loop = 0;
2727 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2728 {
2729 if (start[i] < (u_char)0xff)
2730 {
2731 start[i] += 1;
2732 loop = 1;
2733 break;
2734 }
2735 }
2736 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +00002737 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002738 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002739
jardineb5d44e2003-12-23 08:09:43 +00002740 return retval;
2741}
2742
2743int
2744send_l1_csnp (struct thread *thread)
2745{
2746 struct isis_circuit *circuit;
2747 int retval = ISIS_OK;
2748
2749 circuit = THREAD_ARG (thread);
2750 assert (circuit);
2751
2752 circuit->t_send_csnp[0] = NULL;
2753
hassof390d2c2004-09-10 20:48:21 +00002754 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2755 {
2756 send_csnp (circuit, 1);
2757 }
jardineb5d44e2003-12-23 08:09:43 +00002758 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002759 THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
2760 isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002761
2762 return retval;
2763}
2764
2765int
2766send_l2_csnp (struct thread *thread)
2767{
2768 struct isis_circuit *circuit;
2769 int retval = ISIS_OK;
2770
2771 circuit = THREAD_ARG (thread);
2772 assert (circuit);
2773
2774 circuit->t_send_csnp[1] = NULL;
2775
hassof390d2c2004-09-10 20:48:21 +00002776 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2777 {
2778 send_csnp (circuit, 2);
2779 }
jardineb5d44e2003-12-23 08:09:43 +00002780 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002781 THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
2782 isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +00002783
jardineb5d44e2003-12-23 08:09:43 +00002784 return retval;
2785}
2786
hasso92365882005-01-18 13:53:33 +00002787static int
jardineb5d44e2003-12-23 08:09:43 +00002788build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2789{
2790 struct isis_fixed_hdr fixed_hdr;
2791 unsigned long lenp;
2792 u_int16_t length;
jardineb5d44e2003-12-23 08:09:43 +00002793 struct isis_lsp *lsp;
2794 struct isis_passwd *passwd;
hasso3fdb2dd2005-09-28 18:45:54 +00002795 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002796 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2797 unsigned long auth_tlv_offset = 0;
2798 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002799
Josh Bailey3f045a02012-03-24 08:35:20 -07002800 if (circuit->snd_stream == NULL)
2801 circuit->snd_stream = stream_new (ISO_MTU (circuit));
2802 else
2803 stream_reset (circuit->snd_stream);
2804
2805 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00002806 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2807 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002808 else
2809 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
hassof390d2c2004-09-10 20:48:21 +00002810 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002811
2812 /*
2813 * Fill Level 1 or 2 Partial Sequence Numbers header
2814 */
paul9985f832005-02-09 15:51:56 +00002815 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00002816 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
jardineb5d44e2003-12-23 08:09:43 +00002817 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2818 stream_putc (circuit->snd_stream, circuit->idx);
2819
2820 /*
2821 * And TLVs
2822 */
2823
Josh Bailey3f045a02012-03-24 08:35:20 -07002824 if (level == IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00002825 passwd = &circuit->area->area_passwd;
2826 else
2827 passwd = &circuit->area->domain_passwd;
2828
hasso1cbc5622005-01-01 10:29:51 +00002829 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
Josh Bailey3f045a02012-03-24 08:35:20 -07002830 {
2831 switch (passwd->type)
hassof390d2c2004-09-10 20:48:21 +00002832 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002833 /* Cleartext */
2834 case ISIS_PASSWD_TYPE_CLEARTXT:
2835 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2836 passwd->passwd, circuit->snd_stream))
2837 return ISIS_WARNING;
2838 break;
2839
2840 /* HMAC MD5 */
2841 case ISIS_PASSWD_TYPE_HMAC_MD5:
2842 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2843 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2844 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2845 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2846 hmac_md5_hash, circuit->snd_stream))
2847 return ISIS_WARNING;
2848 break;
2849
2850 default:
2851 break;
jardineb5d44e2003-12-23 08:09:43 +00002852 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002853 }
2854
2855 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2856 if (retval != ISIS_OK)
2857 return retval;
jardineb5d44e2003-12-23 08:09:43 +00002858
hassof390d2c2004-09-10 20:48:21 +00002859 if (isis->debugs & DEBUG_SNP_PACKETS)
2860 {
hasso3fdb2dd2005-09-28 18:45:54 +00002861 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
hassof390d2c2004-09-10 20:48:21 +00002862 {
hasso529d65b2004-12-24 00:14:50 +00002863 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2864 " cksum 0x%04x, lifetime %us",
2865 circuit->area->area_tag,
2866 rawlspid_print (lsp->lsp_header->lsp_id),
2867 ntohl (lsp->lsp_header->seq_num),
2868 ntohs (lsp->lsp_header->checksum),
2869 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00002870 }
2871 }
2872
paul9985f832005-02-09 15:51:56 +00002873 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00002874 /* Update PDU length */
2875 stream_putw_at (circuit->snd_stream, lenp, length);
2876
Josh Bailey3f045a02012-03-24 08:35:20 -07002877 /* For HMAC MD5 we need to compute the md5 hash and store it */
2878 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2879 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2880 {
2881 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2882 stream_get_endp(circuit->snd_stream),
2883 (unsigned char *) &passwd->passwd, passwd->len,
2884 (caddr_t) &hmac_md5_hash);
2885 /* Copy the hash into the stream */
2886 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2887 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2888 }
2889
jardineb5d44e2003-12-23 08:09:43 +00002890 return ISIS_OK;
2891}
2892
2893/*
2894 * 7.3.15.4 action on expiration of partial SNP interval
2895 * level 1
2896 */
hasso92365882005-01-18 13:53:33 +00002897static int
jardineb5d44e2003-12-23 08:09:43 +00002898send_psnp (int level, struct isis_circuit *circuit)
2899{
jardineb5d44e2003-12-23 08:09:43 +00002900 struct isis_lsp *lsp;
2901 struct list *list = NULL;
hasso3fdb2dd2005-09-28 18:45:54 +00002902 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07002903 u_char num_lsps;
2904 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002905
Josh Bailey3f045a02012-03-24 08:35:20 -07002906 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2907 circuit->u.bc.is_dr[level - 1])
2908 return ISIS_OK;
2909
2910 if (circuit->area->lspdb[level - 1] == NULL ||
2911 dict_count (circuit->area->lspdb[level - 1]) == 0)
2912 return ISIS_OK;
2913
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002914 if (! circuit->snd_stream)
2915 return ISIS_ERROR;
2916
Josh Bailey3f045a02012-03-24 08:35:20 -07002917 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2918
2919 while (1)
hassof390d2c2004-09-10 20:48:21 +00002920 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002921 list = list_new ();
2922 lsp_build_list_ssn (circuit, num_lsps, list,
2923 circuit->area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002924
Josh Bailey3f045a02012-03-24 08:35:20 -07002925 if (listcount (list) == 0)
2926 {
2927 list_delete (list);
2928 return ISIS_OK;
2929 }
jardineb5d44e2003-12-23 08:09:43 +00002930
Josh Bailey3f045a02012-03-24 08:35:20 -07002931 retval = build_psnp (level, circuit, list);
2932 if (retval != ISIS_OK)
2933 {
2934 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2935 circuit->area->area_tag, level, circuit->interface->name);
2936 list_delete (list);
2937 return retval;
2938 }
jardineb5d44e2003-12-23 08:09:43 +00002939
Josh Bailey3f045a02012-03-24 08:35:20 -07002940 if (isis->debugs & DEBUG_SNP_PACKETS)
2941 {
2942 zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld",
2943 circuit->area->area_tag, level,
2944 circuit->interface->name,
2945 stream_get_endp (circuit->snd_stream));
2946 if (isis->debugs & DEBUG_PACKET_DUMP)
2947 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2948 stream_get_endp (circuit->snd_stream));
2949 }
jardineb5d44e2003-12-23 08:09:43 +00002950
Josh Bailey3f045a02012-03-24 08:35:20 -07002951 retval = circuit->tx (circuit, level);
2952 if (retval != ISIS_OK)
2953 {
2954 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2955 circuit->area->area_tag, level,
2956 circuit->interface->name);
2957 list_delete (list);
2958 return retval;
2959 }
jardineb5d44e2003-12-23 08:09:43 +00002960
Josh Bailey3f045a02012-03-24 08:35:20 -07002961 /*
2962 * sending succeeded, we can clear SSN flags of this circuit
2963 * for the LSPs in list
2964 */
2965 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2966 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2967 list_delete (list);
jardineb5d44e2003-12-23 08:09:43 +00002968 }
jardineb5d44e2003-12-23 08:09:43 +00002969
2970 return retval;
2971}
2972
2973int
2974send_l1_psnp (struct thread *thread)
2975{
2976
2977 struct isis_circuit *circuit;
2978 int retval = ISIS_OK;
2979
2980 circuit = THREAD_ARG (thread);
2981 assert (circuit);
2982
2983 circuit->t_send_psnp[0] = NULL;
2984
2985 send_psnp (1, circuit);
2986 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00002987 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
2988 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002989
2990 return retval;
2991}
2992
2993/*
2994 * 7.3.15.4 action on expiration of partial SNP interval
2995 * level 2
2996 */
2997int
2998send_l2_psnp (struct thread *thread)
2999{
jardineb5d44e2003-12-23 08:09:43 +00003000 struct isis_circuit *circuit;
3001 int retval = ISIS_OK;
3002
3003 circuit = THREAD_ARG (thread);
3004 assert (circuit);
3005
3006 circuit->t_send_psnp[1] = NULL;
3007
3008 send_psnp (2, circuit);
3009
3010 /* set next timer thread */
hassof390d2c2004-09-10 20:48:21 +00003011 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
3012 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00003013
3014 return retval;
3015}
3016
jardineb5d44e2003-12-23 08:09:43 +00003017/*
3018 * ISO 10589 - 7.3.14.3
3019 */
3020int
3021send_lsp (struct thread *thread)
3022{
3023 struct isis_circuit *circuit;
3024 struct isis_lsp *lsp;
3025 struct listnode *node;
Josh Bailey3f045a02012-03-24 08:35:20 -07003026 int retval = ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00003027
3028 circuit = THREAD_ARG (thread);
3029 assert (circuit);
3030
Josh Bailey3f045a02012-03-24 08:35:20 -07003031 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3032 {
3033 return retval;
3034 }
3035
Avneesh Sachdev0fece072012-05-06 00:03:07 -07003036 node = listhead (circuit->lsp_queue);
3037
3038 /*
3039 * Handle case where there are no LSPs on the queue. This can
3040 * happen, for instance, if an adjacency goes down before this
3041 * thread gets a chance to run.
3042 */
3043 if (!node)
3044 {
3045 return retval;
3046 }
3047
3048 lsp = listgetdata(node);
Josh Bailey3f045a02012-03-24 08:35:20 -07003049
3050 /*
3051 * Do not send if levels do not match
3052 */
3053 if (!(lsp->level & circuit->is_type))
hassof390d2c2004-09-10 20:48:21 +00003054 {
Josh Bailey3f045a02012-03-24 08:35:20 -07003055 list_delete_node (circuit->lsp_queue, node);
3056 return retval;
hassof390d2c2004-09-10 20:48:21 +00003057 }
jardineb5d44e2003-12-23 08:09:43 +00003058
Josh Bailey3f045a02012-03-24 08:35:20 -07003059 /*
3060 * Do not send if we do not have adjacencies in state up on the circuit
3061 */
3062 if (circuit->upadjcount[lsp->level - 1] == 0)
3063 {
3064 list_delete_node (circuit->lsp_queue, node);
3065 return retval;
3066 }
3067
3068 /* copy our lsp to the send buffer */
3069 stream_copy (circuit->snd_stream, lsp->pdu);
3070
3071 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3072 {
3073 zlog_debug
3074 ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3075 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3076 rawlspid_print (lsp->lsp_header->lsp_id),
3077 ntohl (lsp->lsp_header->seq_num),
3078 ntohs (lsp->lsp_header->checksum),
3079 ntohs (lsp->lsp_header->rem_lifetime),
3080 circuit->interface->name);
3081 if (isis->debugs & DEBUG_PACKET_DUMP)
3082 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3083 stream_get_endp (circuit->snd_stream));
3084 }
3085
3086 retval = circuit->tx (circuit, lsp->level);
3087 if (retval != ISIS_OK)
3088 {
3089 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed",
3090 circuit->area->area_tag, lsp->level,
3091 circuit->interface->name);
3092 return retval;
3093 }
3094
3095 /*
3096 * If the sending succeeded, we can del the lsp from circuits
3097 * lsp_queue
3098 */
3099 list_delete_node (circuit->lsp_queue, node);
3100
3101 /* Set the last-cleared time if the queue is empty. */
3102 /* TODO: Is is possible that new lsps keep being added to the queue
3103 * that the queue is never empty? */
3104 if (list_isempty (circuit->lsp_queue))
3105 circuit->lsp_queue_last_cleared = time (NULL);
3106
3107 /*
3108 * On broadcast circuits also the SRMflag can be cleared
3109 */
3110 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
3111 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3112
jardineb5d44e2003-12-23 08:09:43 +00003113 return retval;
hassof390d2c2004-09-10 20:48:21 +00003114}
jardineb5d44e2003-12-23 08:09:43 +00003115
3116int
hassof390d2c2004-09-10 20:48:21 +00003117ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3118 int level)
jardineb5d44e2003-12-23 08:09:43 +00003119{
3120 unsigned long lenp;
3121 int retval;
3122 u_int16_t length;
3123 struct isis_fixed_hdr fixed_hdr;
3124
3125 if (!circuit->snd_stream)
hassof390d2c2004-09-10 20:48:21 +00003126 circuit->snd_stream = stream_new (ISO_MTU (circuit));
jardineb5d44e2003-12-23 08:09:43 +00003127 else
3128 stream_reset (circuit->snd_stream);
3129
Josh Bailey3f045a02012-03-24 08:35:20 -07003130 // fill_llc_hdr (stream);
3131 if (level == IS_LEVEL_1)
hassof390d2c2004-09-10 20:48:21 +00003132 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3133 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003134 else
hassof390d2c2004-09-10 20:48:21 +00003135 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3136 circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003137
3138
paul9985f832005-02-09 15:51:56 +00003139 lenp = stream_get_endp (circuit->snd_stream);
hassof390d2c2004-09-10 20:48:21 +00003140 stream_putw (circuit->snd_stream, 0); /* PDU length */
3141 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00003142 stream_putc (circuit->snd_stream, circuit->idx);
hassof390d2c2004-09-10 20:48:21 +00003143 stream_putc (circuit->snd_stream, 9); /* code */
3144 stream_putc (circuit->snd_stream, 16); /* len */
jardineb5d44e2003-12-23 08:09:43 +00003145
hassof390d2c2004-09-10 20:48:21 +00003146 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3147 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3148 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3149 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
jardineb5d44e2003-12-23 08:09:43 +00003150
paul9985f832005-02-09 15:51:56 +00003151 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
jardineb5d44e2003-12-23 08:09:43 +00003152 /* Update PDU length */
3153 stream_putw_at (circuit->snd_stream, lenp, length);
3154
3155 retval = circuit->tx (circuit, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07003156 if (retval != ISIS_OK)
3157 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3158 circuit->area->area_tag, level,
3159 circuit->interface->name);
jardineb5d44e2003-12-23 08:09:43 +00003160
3161 return retval;
3162}