blob: d147c650bad26e1e5ccf8383fb5856eea1e06b98 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_lsp.c
3 * LSP 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 */
paul15935e92005-05-03 09:27:23 +000023
jardineb5d44e2003-12-23 08:09:43 +000024#include <stdlib.h>
25#include <stdio.h>
26#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000027
28#include "linklist.h"
29#include "thread.h"
30#include "vty.h"
31#include "stream.h"
32#include "memory.h"
33#include "log.h"
34#include "prefix.h"
35#include "command.h"
36#include "hash.h"
37#include "if.h"
38
39#include "isisd/dict.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
42#include "isisd/isis_circuit.h"
43#include "isisd/isisd.h"
44#include "isisd/isis_tlv.h"
45#include "isisd/isis_lsp.h"
46#include "isisd/isis_pdu.h"
47#include "isisd/isis_dynhn.h"
48#include "isisd/isis_misc.h"
49#include "isisd/isis_flags.h"
50#include "isisd/iso_checksum.h"
51#include "isisd/isis_csm.h"
52#include "isisd/isis_adjacency.h"
53#include "isisd/isis_spf.h"
54
55#ifdef TOPOLOGY_GENERATE
56#include "spgrid.h"
57#endif
58
hassof390d2c2004-09-10 20:48:21 +000059#define LSP_MEMORY_PREASSIGN
jardineb5d44e2003-12-23 08:09:43 +000060
61extern struct isis *isis;
62extern struct thread_master *master;
hasso18a6dce2004-10-03 18:18:34 +000063extern struct in_addr router_id_zebra;
jardineb5d44e2003-12-23 08:09:43 +000064
hasso73d1aea2004-09-24 10:45:28 +000065/* staticly assigned vars for printing purposes */
66char lsp_bits_string[200]; /* FIXME: enough ? */
67
hassof390d2c2004-09-10 20:48:21 +000068int
69lsp_id_cmp (u_char * id1, u_char * id2)
70{
jardineb5d44e2003-12-23 08:09:43 +000071 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
72}
73
74dict_t *
hassof390d2c2004-09-10 20:48:21 +000075lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000076{
77 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000078
79 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
80
jardineb5d44e2003-12-23 08:09:43 +000081 return dict;
82}
83
84struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000085lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000086{
87 dnode_t *node;
88
hassof390d2c2004-09-10 20:48:21 +000089#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000090 dnode_t *dn;
91
hasso529d65b2004-12-24 00:14:50 +000092 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000093 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
94 {
hasso529d65b2004-12-24 00:14:50 +000095 zlog_debug ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)),
96 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000097 }
jardineb5d44e2003-12-23 08:09:43 +000098#endif /* EXTREME DEBUG */
99
100 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000101
jardineb5d44e2003-12-23 08:09:43 +0000102 if (node)
hassof390d2c2004-09-10 20:48:21 +0000103 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000104
105 return NULL;
106}
107
hasso92365882005-01-18 13:53:33 +0000108static void
jardineb5d44e2003-12-23 08:09:43 +0000109lsp_clear_data (struct isis_lsp *lsp)
110{
111 if (!lsp)
112 return;
hassof390d2c2004-09-10 20:48:21 +0000113
114 if (lsp->own_lsp)
115 {
116 if (lsp->tlv_data.nlpids)
117 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
118 if (lsp->tlv_data.hostname)
119 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
120 }
jardineb5d44e2003-12-23 08:09:43 +0000121 if (lsp->tlv_data.is_neighs)
122 list_delete (lsp->tlv_data.is_neighs);
123 if (lsp->tlv_data.area_addrs)
124 list_delete (lsp->tlv_data.area_addrs);
125 if (lsp->tlv_data.es_neighs)
126 list_delete (lsp->tlv_data.es_neighs);
127 if (lsp->tlv_data.ipv4_addrs)
128 list_delete (lsp->tlv_data.ipv4_addrs);
129 if (lsp->tlv_data.ipv4_int_reachs)
130 list_delete (lsp->tlv_data.ipv4_int_reachs);
131 if (lsp->tlv_data.ipv4_ext_reachs)
132 list_delete (lsp->tlv_data.ipv4_ext_reachs);
133#ifdef HAVE_IPV6
134 if (lsp->tlv_data.ipv6_addrs)
135 list_delete (lsp->tlv_data.ipv6_addrs);
136 if (lsp->tlv_data.ipv6_reachs)
137 list_delete (lsp->tlv_data.ipv6_reachs);
138#endif /* HAVE_IPV6 */
139
140 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
141
142 return;
143}
144
hasso92365882005-01-18 13:53:33 +0000145static void
jardineb5d44e2003-12-23 08:09:43 +0000146lsp_destroy (struct isis_lsp *lsp)
147{
148 if (!lsp)
149 return;
hassof390d2c2004-09-10 20:48:21 +0000150
jardineb5d44e2003-12-23 08:09:43 +0000151 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000152
153 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
154 {
jardineb5d44e2003-12-23 08:09:43 +0000155 list_delete (lsp->lspu.frags);
hassof390d2c2004-09-10 20:48:21 +0000156 }
157
jardineb5d44e2003-12-23 08:09:43 +0000158 if (lsp->pdu)
159 stream_free (lsp->pdu);
160 XFREE (MTYPE_ISIS_LSP, lsp);
161}
162
hassof390d2c2004-09-10 20:48:21 +0000163void
164lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000165{
166 dnode_t *dnode, *next;
167 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000168
jardineb5d44e2003-12-23 08:09:43 +0000169 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000170 while (dnode)
171 {
172 next = dict_next (lspdb, dnode);
173 lsp = dnode_get (dnode);
174 lsp_destroy (lsp);
175 dict_delete_free (lspdb, dnode);
176 dnode = next;
177 }
178
jardineb5d44e2003-12-23 08:09:43 +0000179 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000180
jardineb5d44e2003-12-23 08:09:43 +0000181 return;
182}
183
184/*
185 * Remove all the frags belonging to the given lsp
186 */
hasso92365882005-01-18 13:53:33 +0000187static void
hassof390d2c2004-09-10 20:48:21 +0000188lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000189{
190 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000191 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000192 struct isis_lsp *lsp;
193
paul1eb8ef22005-04-07 07:30:20 +0000194 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000195 {
hassof390d2c2004-09-10 20:48:21 +0000196 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
197 lsp_destroy (lsp);
198 dnode_destroy (dict_delete (lspdb, dnode));
199 }
200
jardineb5d44e2003-12-23 08:09:43 +0000201 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000202
jardineb5d44e2003-12-23 08:09:43 +0000203 return;
204}
205
206void
hassof390d2c2004-09-10 20:48:21 +0000207lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000208{
209 dnode_t *node;
210 struct isis_lsp *lsp;
211
212 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000213 if (node)
214 {
215 node = dict_delete (lspdb, node);
216 lsp = dnode_get (node);
217 /*
218 * If this is a zero lsp, remove all the frags now
219 */
220 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
221 {
222 if (lsp->lspu.frags)
223 lsp_remove_frags (lsp->lspu.frags, lspdb);
224 }
225 else
226 {
227 /*
228 * else just remove this frag, from the zero lsps' frag list
229 */
230 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
231 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
232 }
233 lsp_destroy (lsp);
234 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000235 }
jardineb5d44e2003-12-23 08:09:43 +0000236}
237
238/*
239 * Compares a LSP to given values
240 * Params are given in net order
241 */
hassof390d2c2004-09-10 20:48:21 +0000242int
243lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000244 u_int16_t checksum, u_int16_t rem_lifetime)
245{
hassof390d2c2004-09-10 20:48:21 +0000246 /* no point in double ntohl on seqnum */
247 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000248 lsp->lsp_header->checksum == checksum &&
249 /*comparing with 0, no need to do ntohl */
250 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000251 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
252 {
253 if (isis->debugs & DEBUG_SNP_PACKETS)
254 {
hasso529d65b2004-12-24 00:14:50 +0000255 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
256 " lifetime %us",
257 areatag,
258 rawlspid_print (lsp->lsp_header->lsp_id),
259 ntohl (lsp->lsp_header->seq_num),
260 ntohs (lsp->lsp_header->checksum),
261 ntohs (lsp->lsp_header->rem_lifetime));
262 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
263 " cksum 0x%04x, lifetime %us",
264 areatag,
265 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000266 }
267 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000268 }
jardineb5d44e2003-12-23 08:09:43 +0000269
hassof390d2c2004-09-10 20:48:21 +0000270 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
271 {
272 if (isis->debugs & DEBUG_SNP_PACKETS)
273 {
hasso529d65b2004-12-24 00:14:50 +0000274 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
275 " lifetime %us",
276 areatag,
277 rawlspid_print (lsp->lsp_header->lsp_id),
278 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
279 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
280 "cksum 0x%04x, lifetime %us",
281 areatag,
282 ntohl (lsp->lsp_header->seq_num),
283 ntohs (lsp->lsp_header->checksum),
284 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000285 }
286 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000287 }
hassof390d2c2004-09-10 20:48:21 +0000288 if (isis->debugs & DEBUG_SNP_PACKETS)
289 {
hasso529d65b2004-12-24 00:14:50 +0000290 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000291 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
292 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
293 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000294 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
295 " cksum 0x%04x, lifetime %us", areatag,
296 ntohl (lsp->lsp_header->seq_num),
297 ntohs (lsp->lsp_header->checksum),
298 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000299 }
jardineb5d44e2003-12-23 08:09:43 +0000300
301 return LSP_OLDER;
302}
303
hassof390d2c2004-09-10 20:48:21 +0000304void
jardineb5d44e2003-12-23 08:09:43 +0000305lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
306{
307 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000308
jardineb5d44e2003-12-23 08:09:43 +0000309 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
310 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
311 else
hassof390d2c2004-09-10 20:48:21 +0000312 newseq = seq_num++;
313
jardineb5d44e2003-12-23 08:09:43 +0000314 lsp->lsp_header->seq_num = htonl (newseq);
hassof390d2c2004-09-10 20:48:21 +0000315 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
316 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000317
318 return;
319}
320
321/*
322 * Genetates checksum for LSP and its frags
323 */
hasso92365882005-01-18 13:53:33 +0000324static void
jardineb5d44e2003-12-23 08:09:43 +0000325lsp_seqnum_update (struct isis_lsp *lsp0)
326{
327 struct isis_lsp *lsp;
paul1eb8ef22005-04-07 07:30:20 +0000328 struct listnode *node, *nnode;
hassof390d2c2004-09-10 20:48:21 +0000329
jardineb5d44e2003-12-23 08:09:43 +0000330 lsp_inc_seqnum (lsp0, 0);
331
332 if (!lsp0->lspu.frags)
333 return;
334
paul1eb8ef22005-04-07 07:30:20 +0000335 for (ALL_LIST_ELEMENTS (lsp0->lspu.frags, node, nnode, lsp))
336 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000337
jardineb5d44e2003-12-23 08:09:43 +0000338 return;
339}
340
hassof390d2c2004-09-10 20:48:21 +0000341int
jardineb5d44e2003-12-23 08:09:43 +0000342isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000343 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000344{
345 uint32_t expected = 0, found;
346 struct tlvs tlvs;
347 int retval = 0;
348
349 expected |= TLVFLAG_AUTH_INFO;
350 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000351 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
352 pdulen - ISIS_FIXED_HDR_LEN
353 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000354 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000355 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000356
357 return authentication_check (passwd, &tlvs.auth_info);
358}
359
hasso92365882005-01-18 13:53:33 +0000360static void
hassof390d2c2004-09-10 20:48:21 +0000361lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
362 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000363{
hassof390d2c2004-09-10 20:48:21 +0000364 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000365 int retval;
hassof390d2c2004-09-10 20:48:21 +0000366
jardineb5d44e2003-12-23 08:09:43 +0000367 /* copying only the relevant part of our stream */
paul15935e92005-05-03 09:27:23 +0000368 lsp->pdu = stream_dup (stream);
369
jardineb5d44e2003-12-23 08:09:43 +0000370 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000371 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
372 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
373 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000374 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000375 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000376 /*
377 * Get LSP data i.e. TLVs
378 */
379 expected |= TLVFLAG_AUTH_INFO;
380 expected |= TLVFLAG_AREA_ADDRS;
381 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000382 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000383 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
384 expected |= TLVFLAG_NLPID;
385 if (area->dynhostname)
386 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000387 if (area->newmetric)
388 {
389 expected |= TLVFLAG_TE_IS_NEIGHS;
390 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
391 expected |= TLVFLAG_TE_ROUTER_ID;
392 }
jardineb5d44e2003-12-23 08:09:43 +0000393 expected |= TLVFLAG_IPV4_ADDR;
394 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
395 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
396#ifdef HAVE_IPV6
397 expected |= TLVFLAG_IPV6_ADDR;
398 expected |= TLVFLAG_IPV6_REACHABILITY;
399#endif /* HAVE_IPV6 */
400
401 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000402 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
403 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
404 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000405
hassof390d2c2004-09-10 20:48:21 +0000406 if (found & TLVFLAG_DYN_HOSTNAME)
407 {
408 if (area->dynhostname)
409 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
410 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
411 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
412 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
413 }
jardineb5d44e2003-12-23 08:09:43 +0000414
415}
416
417void
418lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassoa96d8d12005-09-16 14:44:23 +0000419 struct stream *stream, struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000420{
hassoa96d8d12005-09-16 14:44:23 +0000421 dnode_t *dnode;
422
423 /* Remove old LSP from LSP database. */
424 dnode = dict_lookup (area->lspdb[level], lsp->lsp_header->lsp_id);
425 dnode_destroy (dict_delete (area->lspdb[level], dnode));
426
hassof390d2c2004-09-10 20:48:21 +0000427 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000428 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
429 lsp_clear_data (lsp);
430
431 /* rebuild the lsp data */
432 lsp_update_data (lsp, stream, area);
433
hassof390d2c2004-09-10 20:48:21 +0000434 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000435 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassoa96d8d12005-09-16 14:44:23 +0000436
437 /* Put LSP back into LSP database, now with updated data. */
438 lsp_insert (lsp, area->lspdb[level]);
jardineb5d44e2003-12-23 08:09:43 +0000439}
440
jardineb5d44e2003-12-23 08:09:43 +0000441/* creation of LSP directly from what we received */
442struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000443lsp_new_from_stream_ptr (struct stream *stream,
444 u_int16_t pdu_len, struct isis_lsp *lsp0,
445 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000446{
447 struct isis_lsp *lsp;
448
hassoaac372f2005-09-01 17:52:33 +0000449 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
jardineb5d44e2003-12-23 08:09:43 +0000450 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000451
452 if (lsp0 == NULL)
453 {
454 /*
455 * zero lsp -> create the list for fragments
456 */
457 lsp->lspu.frags = list_new ();
458 }
459 else
460 {
461 /*
462 * a fragment -> set the backpointer and add this to zero lsps frag list
463 */
464 lsp->lspu.zero_lsp = lsp0;
465 listnode_add (lsp0->lspu.frags, lsp);
466 }
467
jardineb5d44e2003-12-23 08:09:43 +0000468 return lsp;
469}
470
471struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000472lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
473 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000474{
475 struct isis_lsp *lsp;
476
hassoaac372f2005-09-01 17:52:33 +0000477 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000478 if (!lsp)
479 {
480 /* FIXME: set lspdbol bit */
481 zlog_warn ("lsp_new(): out of memory");
482 return NULL;
483 }
jardineb5d44e2003-12-23 08:09:43 +0000484#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000485 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000486#else
hassof390d2c2004-09-10 20:48:21 +0000487 /* We need to do realloc on TLVs additions */
488 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000489#endif /* LSP_MEMORY_PREASSIGN */
490 if (LSP_FRAGMENT (lsp_id) == 0)
491 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000492 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
493 lsp->lsp_header = (struct isis_link_state_hdr *)
494 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
495
jardineb5d44e2003-12-23 08:09:43 +0000496 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000497 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
498 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
499
jardineb5d44e2003-12-23 08:09:43 +0000500 /* now for the LSP HEADER */
501 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000502 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000503 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000504 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000505 lsp->lsp_header->seq_num = htonl (seq_num);
506 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
507 lsp->lsp_header->lsp_bits = lsp_bits;
508 lsp->level = level;
509 lsp->age_out = ZERO_AGE_LIFETIME;
510
paul9985f832005-02-09 15:51:56 +0000511 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000512
hassoc89c05d2005-09-04 21:36:36 +0000513 if (isis->debugs & DEBUG_EVENTS)
514 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x",
515 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
516 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
517 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000518
519 return lsp;
520}
521
522void
hassof390d2c2004-09-10 20:48:21 +0000523lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000524{
525 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
526}
527
528/*
529 * Build a list of LSPs with non-zero ht bounded by start and stop ids
530 */
hassof390d2c2004-09-10 20:48:21 +0000531void
532lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
533 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000534{
535 dnode_t *first, *last, *curr;
536
537 first = dict_lower_bound (lspdb, start_id);
538 if (!first)
539 return;
hassof390d2c2004-09-10 20:48:21 +0000540
jardineb5d44e2003-12-23 08:09:43 +0000541 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000542
jardineb5d44e2003-12-23 08:09:43 +0000543 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000544
545 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000546 listnode_add (list, first->dict_data);
547
hassof390d2c2004-09-10 20:48:21 +0000548 while (curr)
549 {
550 curr = dict_next (lspdb, curr);
551 if (curr &&
552 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
553 listnode_add (list, curr->dict_data);
554 if (curr == last)
555 break;
556 }
557
jardineb5d44e2003-12-23 08:09:43 +0000558 return;
559}
560
561/*
562 * Build a list of all LSPs bounded by start and stop ids
563 */
hassof390d2c2004-09-10 20:48:21 +0000564void
565lsp_build_list (u_char * start_id, u_char * stop_id,
566 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000567{
568 dnode_t *first, *last, *curr;
569
570 first = dict_lower_bound (lspdb, start_id);
571 if (!first)
572 return;
hassof390d2c2004-09-10 20:48:21 +0000573
jardineb5d44e2003-12-23 08:09:43 +0000574 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000575
jardineb5d44e2003-12-23 08:09:43 +0000576 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000577
jardineb5d44e2003-12-23 08:09:43 +0000578 listnode_add (list, first->dict_data);
579
hassof390d2c2004-09-10 20:48:21 +0000580 while (curr)
581 {
582 curr = dict_next (lspdb, curr);
583 if (curr)
584 listnode_add (list, curr->dict_data);
585 if (curr == last)
586 break;
587 }
588
jardineb5d44e2003-12-23 08:09:43 +0000589 return;
590}
591
592/*
593 * Build a list of LSPs with SSN flag set for the given circuit
594 */
595void
hassof390d2c2004-09-10 20:48:21 +0000596lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
597 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000598{
599 dnode_t *dnode, *next;
600 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000601
jardineb5d44e2003-12-23 08:09:43 +0000602 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000603 while (dnode != NULL)
604 {
605 next = dict_next (lspdb, dnode);
606 lsp = dnode_get (dnode);
607 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
608 listnode_add (list, lsp);
609 dnode = next;
610 }
611
jardineb5d44e2003-12-23 08:09:43 +0000612 return;
613}
614
hasso92365882005-01-18 13:53:33 +0000615static void
jardineb5d44e2003-12-23 08:09:43 +0000616lsp_set_time (struct isis_lsp *lsp)
617{
618 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000619
620 if (lsp->lsp_header->rem_lifetime == 0)
621 {
622 if (lsp->age_out != 0)
623 lsp->age_out--;
624 return;
625 }
jardineb5d44e2003-12-23 08:09:43 +0000626
627 /* If we are turning 0 */
628 /* ISO 10589 - 7.3.16.4 first paragraph */
629
hassof390d2c2004-09-10 20:48:21 +0000630 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
631 {
632 /* 7.3.16.4 a) set SRM flags on all */
633 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
634 /* 7.3.16.4 b) retain only the header FIXME */
635 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
636 }
jardineb5d44e2003-12-23 08:09:43 +0000637
hassof390d2c2004-09-10 20:48:21 +0000638 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000639 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
640}
641
hasso92365882005-01-18 13:53:33 +0000642static void
hassof390d2c2004-09-10 20:48:21 +0000643lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000644{
645 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000646 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000647
648 if (dynhost)
649 dyn = dynhn_find_by_id (lsp_id);
650 else
651 dyn = NULL;
652
653 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000654 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000655 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000656 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000657 else
hassof390d2c2004-09-10 20:48:21 +0000658 {
659 memcpy (id, sysid_print (lsp_id), 15);
660 }
661 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000662 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000663 LSP_FRAGMENT (lsp_id));
664 else
hassof7c43dc2004-09-26 16:24:14 +0000665 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000666}
667
hassof390d2c2004-09-10 20:48:21 +0000668/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000669const char *
hassof390d2c2004-09-10 20:48:21 +0000670lsp_bits2string (u_char * lsp_bits)
671{
672 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000673
hassof390d2c2004-09-10 20:48:21 +0000674 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000675 return " none";
676
677 /* we only focus on the default metric */
678 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000679 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000680
681 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000682 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000683
hassof390d2c2004-09-10 20:48:21 +0000684 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
685
jardineb5d44e2003-12-23 08:09:43 +0000686 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000687
hassof390d2c2004-09-10 20:48:21 +0000688 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000689}
690
691/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000692static void
hassof390d2c2004-09-10 20:48:21 +0000693lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000694{
hassof390d2c2004-09-10 20:48:21 +0000695 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000696 u_char LSPid[255];
697
698 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000699 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
700 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
701 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000702
hassof390d2c2004-09-10 20:48:21 +0000703 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
704 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000705 else
hassof390d2c2004-09-10 20:48:21 +0000706 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000707
708 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000709 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000710}
711
hasso92365882005-01-18 13:53:33 +0000712static void
hassof390d2c2004-09-10 20:48:21 +0000713lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000714{
715 struct isis_lsp *lsp = dnode_get (node);
716 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000717 int i;
paul1eb8ef22005-04-07 07:30:20 +0000718 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000719 struct is_neigh *is_neigh;
720 struct te_is_neigh *te_is_neigh;
721 struct ipv4_reachability *ipv4_reach;
722 struct in_addr *ipv4_addr;
723 struct te_ipv4_reachability *te_ipv4_reach;
724#ifdef HAVE_IPV6
725 struct ipv6_reachability *ipv6_reach;
726 struct in6_addr in6;
727#endif
728 u_char LSPid[255];
729 u_char hostname[255];
730 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000731 u_char ipv4_reach_prefix[20];
732 u_char ipv4_reach_mask[20];
733 u_char ipv4_address[20];
734
735 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000736 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000737
738 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000739 if (lsp->tlv_data.area_addrs)
paul1eb8ef22005-04-07 07:30:20 +0000740 for (ALL_LIST_ELEMENTS (lsp->tlv_data.area_addrs, lnode,
741 lnnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000742 {
hasso1cd80842004-10-07 20:07:40 +0000743 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000744 isonet_print (area_addr->area_addr, area_addr->addr_len),
745 VTY_NEWLINE);
746 }
paul1eb8ef22005-04-07 07:30:20 +0000747
jardineb5d44e2003-12-23 08:09:43 +0000748 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000749 if (lsp->tlv_data.nlpids)
750 {
751 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
752 {
753 switch (lsp->tlv_data.nlpids->nlpids[i])
754 {
755 case NLPID_IP:
756 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000757 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000758 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
759 break;
760 default:
hasso1cd80842004-10-07 20:07:40 +0000761 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000762 break;
763 }
764 }
765 }
jardineb5d44e2003-12-23 08:09:43 +0000766
767 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000768 if (lsp->tlv_data.hostname)
769 {
770 bzero (hostname, sizeof (hostname));
771 memcpy (hostname, lsp->tlv_data.hostname->name,
772 lsp->tlv_data.hostname->namelen);
773 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000774 }
hassof390d2c2004-09-10 20:48:21 +0000775
776 if (lsp->tlv_data.ipv4_addrs)
paul1eb8ef22005-04-07 07:30:20 +0000777 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_addrs, lnode,
778 lnnode, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000779 {
780 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
781 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
782 }
hassof390d2c2004-09-10 20:48:21 +0000783
hasso1cd80842004-10-07 20:07:40 +0000784 /* TE router id */
785 if (lsp->tlv_data.router_id)
786 {
787 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
788 sizeof (ipv4_address));
789 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
790 }
791
792 /* for the IS neighbor tlv */
793 if (lsp->tlv_data.is_neighs)
paul1eb8ef22005-04-07 07:30:20 +0000794 for (ALL_LIST_ELEMENTS (lsp->tlv_data.is_neighs, lnode, lnnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000795 {
796 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
797 vty_out (vty, " Metric: %d IS %s%s",
798 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
799 }
hasso1cd80842004-10-07 20:07:40 +0000800
jardineb5d44e2003-12-23 08:09:43 +0000801 /* for the internal reachable tlv */
802 if (lsp->tlv_data.ipv4_int_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000803 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_int_reachs, lnode,
804 lnnode, ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000805 {
806 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
807 sizeof (ipv4_reach_prefix));
808 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
809 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000810 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000811 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
812 ipv4_reach_mask, VTY_NEWLINE);
813 }
hasso2097cd82003-12-23 11:51:08 +0000814
815 /* for the external reachable tlv */
816 if (lsp->tlv_data.ipv4_ext_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000817 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_ext_reachs, lnode,
818 lnnode, ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000819 {
820 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
821 sizeof (ipv4_reach_prefix));
822 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
823 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000824 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000825 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
826 ipv4_reach_mask, VTY_NEWLINE);
827 }
paul1eb8ef22005-04-07 07:30:20 +0000828
hasso2097cd82003-12-23 11:51:08 +0000829 /* IPv6 tlv */
830#ifdef HAVE_IPV6
831 if (lsp->tlv_data.ipv6_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000832 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv6_reachs, lnode,
833 lnnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000834 {
835 memset (&in6, 0, sizeof (in6));
836 memcpy (in6.s6_addr, ipv6_reach->prefix,
837 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000838 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000839 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000840 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
841 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
842 ntohl (ipv6_reach->metric),
843 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000844 else
hassof390d2c2004-09-10 20:48:21 +0000845 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
846 ntohl (ipv6_reach->metric),
847 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000848 }
849#endif
paul1eb8ef22005-04-07 07:30:20 +0000850
hasso1cd80842004-10-07 20:07:40 +0000851 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000852 if (lsp->tlv_data.te_is_neighs)
paul1eb8ef22005-04-07 07:30:20 +0000853 for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_is_neighs, lnode,
854 lnnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000855 {
hasso1cd80842004-10-07 20:07:40 +0000856 /* FIXME: metric display is wrong. */
hassof390d2c2004-09-10 20:48:21 +0000857 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso1cd80842004-10-07 20:07:40 +0000858 vty_out (vty, " Metric: %d extd-IS %s%s",
859 te_is_neigh->te_metric[0], LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000860 }
jardineb5d44e2003-12-23 08:09:43 +0000861
hasso1cd80842004-10-07 20:07:40 +0000862 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000863 if (lsp->tlv_data.te_ipv4_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000864 for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_ipv4_reachs, lnode,
865 lnnode, te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000866 {
hasso1cd80842004-10-07 20:07:40 +0000867 /* FIXME: There should be better way to output this stuff. */
hasso2e864cf2004-10-08 06:40:24 +0000868 vty_out (vty, " Metric: %d extd-IP %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000869 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000870 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
871 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000872 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000873 }
jardineb5d44e2003-12-23 08:09:43 +0000874
hassof390d2c2004-09-10 20:48:21 +0000875 return;
jardineb5d44e2003-12-23 08:09:43 +0000876}
877
878/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000879int
880lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000881{
882
hassof390d2c2004-09-10 20:48:21 +0000883 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000884 int lsp_count = 0;
885
886 /* print the title, for both modes */
887 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000888 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
889
890 if (detail == ISIS_UI_LEVEL_BRIEF)
891 {
892 while (node != NULL)
893 {
894 /* I think it is unnecessary, so I comment it out */
895 /* dict_contains (lspdb, node); */
896 next = dict_next (lspdb, node);
897 lsp_print (node, vty, dynhost);
898 node = next;
899 lsp_count++;
900 }
jardineb5d44e2003-12-23 08:09:43 +0000901 }
hassof390d2c2004-09-10 20:48:21 +0000902 else if (detail == ISIS_UI_LEVEL_DETAIL)
903 {
904 while (node != NULL)
905 {
906 next = dict_next (lspdb, node);
907 lsp_print_detail (node, vty, dynhost);
908 node = next;
909 lsp_count++;
910 }
jardineb5d44e2003-12-23 08:09:43 +0000911 }
jardineb5d44e2003-12-23 08:09:43 +0000912
913 return lsp_count;
914}
915
916/* this function reallocate memory to an lsp pdu, with an additional
917 * size of memory, it scans the lsp and moves all pointers the
918 * way they should */
hasso92365882005-01-18 13:53:33 +0000919static u_char *
hassof390d2c2004-09-10 20:48:21 +0000920lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +0000921{
922 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +0000923
924 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000925#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000926 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +0000927 return retval;
hassof390d2c2004-09-10 20:48:21 +0000928#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +0000929 u_char *newpdu;
930 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassoaac372f2005-09-01 17:52:33 +0000931 stream_put (newpdu, STREAM_DATA(lsp->pdu), ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +0000932 XFREE (memorytype, lsp->pdu);
933 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +0000934 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
935 lsp->lsp_header = (struct isis_link_state_hdr *)
936 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000937 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +0000938 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +0000939#endif /* LSP_MEMORY_PREASSIGN */
940}
941
hassof390d2c2004-09-10 20:48:21 +0000942#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +0000943/*
944 * Builds the lsp->tlv_data
945 * and writes the tlvs into lsp->pdu
946 */
947void
948lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
949{
950 struct is_neigh *is_neigh;
paul1eb8ef22005-04-07 07:30:20 +0000951 struct listnode *node, *nnode, *ipnode, *ipnnode;
jardineb5d44e2003-12-23 08:09:43 +0000952 int level = lsp->level;
953 struct isis_circuit *circuit;
954 struct prefix_ipv4 *ipv4;
955 struct ipv4_reachability *ipreach;
956 struct isis_adjacency *nei;
957#ifdef HAVE_IPV6
958 struct prefix_ipv6 *ipv6;
959 struct ipv6_reachability *ip6reach;
960#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000961
jardineb5d44e2003-12-23 08:09:43 +0000962 /*
963 * First add the tlvs related to area
964 */
hassof390d2c2004-09-10 20:48:21 +0000965
jardineb5d44e2003-12-23 08:09:43 +0000966 /* Area addresses */
967 if (lsp->tlv_data.area_addrs == NULL)
968 lsp->tlv_data.area_addrs = list_new ();
969 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
970 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +0000971 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +0000972#ifdef HAVE_IPV6
973 || area->ipv6_circuits > 0
974#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000975 )
jardineb5d44e2003-12-23 08:09:43 +0000976 {
977 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
978 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +0000979 if (area->ip_circuits > 0)
980 {
981 lsp->tlv_data.nlpids->count++;
982 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
983 }
jardineb5d44e2003-12-23 08:09:43 +0000984#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000985 if (area->ipv6_circuits > 0)
986 {
987 lsp->tlv_data.nlpids->count++;
988 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
989 NLPID_IPV6;
990 }
jardineb5d44e2003-12-23 08:09:43 +0000991#endif /* HAVE_IPV6 */
992 }
993 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +0000994 if (area->dynhostname)
995 {
996 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
997 sizeof (struct hostname));
998 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
999 strlen (unix_hostname ()));
1000 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1001 }
jardineb5d44e2003-12-23 08:09:43 +00001002#ifdef TOPOLOGY_GENERATE
1003 /*
1004 * If we have a topology in this area, we need to connect this lsp to
1005 * the first topology lsp
1006 */
hassof390d2c2004-09-10 20:48:21 +00001007 if ((area->topology) && (level == 1))
1008 {
1009 if (lsp->tlv_data.is_neighs == NULL)
1010 lsp->tlv_data.is_neighs = list_new ();
hassoaac372f2005-09-01 17:52:33 +00001011 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001012 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1013 /* connected to the first */
1014 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1015 /* this is actually the same system, why mess the SPT */
1016 is_neigh->metrics.metric_default = 0;
1017 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1018 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1019 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1020 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001021
hassof390d2c2004-09-10 20:48:21 +00001022 }
jardineb5d44e2003-12-23 08:09:43 +00001023#endif
1024
1025 /*
1026 * Then add tlvs related to circuits
1027 */
paul1eb8ef22005-04-07 07:30:20 +00001028 for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00001029 {
hassof390d2c2004-09-10 20:48:21 +00001030 if (circuit->state != C_STATE_UP)
1031 continue;
1032
1033 /*
1034 * Add IPv4 internal reachability of this circuit
1035 */
1036 if (circuit->ip_router && circuit->ip_addrs &&
1037 circuit->ip_addrs->count > 0)
1038 {
1039 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1040 {
1041 lsp->tlv_data.ipv4_int_reachs = list_new ();
1042 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1043 }
paul1eb8ef22005-04-07 07:30:20 +00001044 for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4))
hassof390d2c2004-09-10 20:48:21 +00001045 {
hassof390d2c2004-09-10 20:48:21 +00001046 ipreach =
hassoaac372f2005-09-01 17:52:33 +00001047 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
hassof390d2c2004-09-10 20:48:21 +00001048 ipreach->metrics = circuit->metrics[level - 1];
1049 ipreach->prefix = ipv4->prefix;
1050 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1051 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1052 }
1053 }
jardineb5d44e2003-12-23 08:09:43 +00001054#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001055 /*
1056 * Add IPv6 reachability of this circuit
1057 */
1058 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1059 circuit->ipv6_non_link->count > 0)
1060 {
1061 if (lsp->tlv_data.ipv6_reachs == NULL)
1062 {
1063 lsp->tlv_data.ipv6_reachs = list_new ();
1064 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1065 }
paul1eb8ef22005-04-07 07:30:20 +00001066 for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode,
1067 ipnnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001068 {
hassof390d2c2004-09-10 20:48:21 +00001069 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001070 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hassof390d2c2004-09-10 20:48:21 +00001071 ip6reach->metric =
1072 htonl (circuit->metrics[level - 1].metric_default);
1073 ip6reach->control_info = 0;
1074 ip6reach->prefix_len = ipv6->prefixlen;
1075 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1076 (ipv6->prefixlen + 7) / 8);
1077 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1078 }
1079 }
jardineb5d44e2003-12-23 08:09:43 +00001080#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001081
1082 switch (circuit->circ_type)
1083 {
1084 case CIRCUIT_T_BROADCAST:
1085 if (level & circuit->circuit_is_type)
1086 {
1087 if (lsp->tlv_data.is_neighs == NULL)
1088 {
1089 lsp->tlv_data.is_neighs = list_new ();
1090 lsp->tlv_data.is_neighs->del = free_tlv;
1091 }
hassoaac372f2005-09-01 17:52:33 +00001092 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001093 if (level == 1)
1094 memcpy (&is_neigh->neigh_id,
1095 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1096 else
1097 memcpy (&is_neigh->neigh_id,
1098 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1099 is_neigh->metrics = circuit->metrics[level - 1];
1100 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1101 }
1102 break;
1103 case CIRCUIT_T_P2P:
1104 nei = circuit->u.p2p.neighbor;
1105 if (nei && (level & nei->circuit_t))
1106 {
1107 if (lsp->tlv_data.is_neighs == NULL)
1108 {
1109 lsp->tlv_data.is_neighs = list_new ();
1110 lsp->tlv_data.is_neighs->del = free_tlv;
1111 }
hassoaac372f2005-09-01 17:52:33 +00001112 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001113 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1114 is_neigh->metrics = circuit->metrics[level - 1];
1115 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1116 }
1117 break;
1118 case CIRCUIT_T_STATIC_IN:
1119 zlog_warn ("lsp_area_create: unsupported circuit type");
1120 break;
1121 case CIRCUIT_T_STATIC_OUT:
1122 zlog_warn ("lsp_area_create: unsupported circuit type");
1123 break;
1124 case CIRCUIT_T_DA:
1125 zlog_warn ("lsp_area_create: unsupported circuit type");
1126 break;
1127 default:
1128 zlog_warn ("lsp_area_create: unknown circuit type");
1129 }
jardineb5d44e2003-12-23 08:09:43 +00001130 }
hassof390d2c2004-09-10 20:48:21 +00001131
jardineb5d44e2003-12-23 08:09:43 +00001132 if (lsp->tlv_data.nlpids)
1133 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1134 if (lsp->tlv_data.hostname)
1135 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001136 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001137 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1138 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1139 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001140 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001141 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1142 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001143#ifdef HAVE_IPV6
1144 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001145 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1146#endif /* HAVE_IPV6 */
1147
paul9985f832005-02-09 15:51:56 +00001148 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001149
1150 return;
1151}
1152#endif
1153
1154#define FRAG_THOLD(S,T) \
1155((STREAM_SIZE(S)*T)/100)
1156
1157/* stream*, area->lsp_frag_threshold, increment */
1158#define FRAG_NEEDED(S,T,I) \
1159 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1160
hasso92365882005-01-18 13:53:33 +00001161static void
jardineb5d44e2003-12-23 08:09:43 +00001162lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001163 int tlvsize, int frag_thold,
1164 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001165{
1166 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001167
jardineb5d44e2003-12-23 08:09:43 +00001168 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001169 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1170 {
1171 tlv_build_func (*from, lsp->pdu);
1172 *to = *from;
1173 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001174 }
hassof390d2c2004-09-10 20:48:21 +00001175 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1176 {
1177 /* fit all we can */
1178 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1179 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1180 if (count)
1181 count = count / tlvsize;
1182 for (i = 0; i < count; i++)
1183 {
paul1eb8ef22005-04-07 07:30:20 +00001184 listnode_add (*to, listgetdata (listhead (*from)));
1185 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001186 }
1187 tlv_build_func (*to, lsp->pdu);
1188 }
paul9985f832005-02-09 15:51:56 +00001189 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001190 return;
1191}
1192
hasso92365882005-01-18 13:53:33 +00001193static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001194lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1195 int level)
jardineb5d44e2003-12-23 08:09:43 +00001196{
1197 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001198 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1199
jardineb5d44e2003-12-23 08:09:43 +00001200 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1201 LSP_FRAGMENT (frag_id) = frag_num;
1202 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001203 if (lsp)
1204 {
1205 /*
1206 * Clear the TLVs, but inherit the authinfo
1207 */
1208 lsp_clear_data (lsp);
1209 if (lsp0->tlv_data.auth_info.type)
1210 {
1211 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1212 sizeof (struct isis_passwd));
1213 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1214 lsp->tlv_data.auth_info.len,
1215 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1216 }
1217 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001218 }
jardineb5d44e2003-12-23 08:09:43 +00001219 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001220 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001221 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001222 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001223 listnode_add (lsp0->lspu.frags, lsp);
1224 lsp->lspu.zero_lsp = lsp0;
1225 /*
1226 * Copy the authinfo from zero LSP
1227 */
hassof390d2c2004-09-10 20:48:21 +00001228 if (lsp0->tlv_data.auth_info.type)
1229 {
1230 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1231 sizeof (struct isis_passwd));
1232 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1233 lsp->tlv_data.auth_info.len,
1234 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1235 }
jardineb5d44e2003-12-23 08:09:43 +00001236 return lsp;
1237}
1238
1239/*
1240 * Builds the LSP data part. This func creates a new frag whenever
1241 * area->lsp_frag_threshold is exceeded.
1242 */
1243#if 1
hasso92365882005-01-18 13:53:33 +00001244static void
jardineb5d44e2003-12-23 08:09:43 +00001245lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1246{
1247 struct is_neigh *is_neigh;
paul1eb8ef22005-04-07 07:30:20 +00001248 struct listnode *node, *nnode, *ipnode, *ipnnode;
jardineb5d44e2003-12-23 08:09:43 +00001249 int level = lsp->level;
1250 struct isis_circuit *circuit;
1251 struct prefix_ipv4 *ipv4;
1252 struct ipv4_reachability *ipreach;
1253 struct isis_adjacency *nei;
1254#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001255 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001256 struct ipv6_reachability *ip6reach;
1257#endif /* HAVE_IPV6 */
1258 struct tlvs tlv_data;
1259 struct isis_lsp *lsp0 = lsp;
1260 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001261 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001262
1263 /*
1264 * First add the tlvs related to area
1265 */
hassof390d2c2004-09-10 20:48:21 +00001266
jardineb5d44e2003-12-23 08:09:43 +00001267 /* Area addresses */
1268 if (lsp->tlv_data.area_addrs == NULL)
1269 lsp->tlv_data.area_addrs = list_new ();
1270 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1271 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001272 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001273#ifdef HAVE_IPV6
1274 || area->ipv6_circuits > 0
1275#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001276 )
jardineb5d44e2003-12-23 08:09:43 +00001277 {
hassoaac372f2005-09-01 17:52:33 +00001278 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001279 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001280 if (area->ip_circuits > 0)
1281 {
1282 lsp->tlv_data.nlpids->count++;
1283 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1284 }
jardineb5d44e2003-12-23 08:09:43 +00001285#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001286 if (area->ipv6_circuits > 0)
1287 {
1288 lsp->tlv_data.nlpids->count++;
1289 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1290 NLPID_IPV6;
1291 }
jardineb5d44e2003-12-23 08:09:43 +00001292#endif /* HAVE_IPV6 */
1293 }
1294 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001295 if (area->dynhostname)
1296 {
1297 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1298 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001299
hassof390d2c2004-09-10 20:48:21 +00001300 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1301 strlen (unix_hostname ()));
1302 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1303 }
jardineb5d44e2003-12-23 08:09:43 +00001304
1305 /*
1306 * Building the zero lsp
1307 */
hassoaac372f2005-09-01 17:52:33 +00001308
1309 /* Reset stream endp. Stream is always there and on every LSP refresh only
1310 * TLV part of it is overwritten. So we must seek past header we will not
1311 * touch. */
hassoc89c05d2005-09-04 21:36:36 +00001312 stream_reset (lsp->pdu);
hassoaac372f2005-09-01 17:52:33 +00001313 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1314
jardineb5d44e2003-12-23 08:09:43 +00001315 /*
1316 * Add the authentication info if its present
1317 */
hassof390d2c2004-09-10 20:48:21 +00001318 (level == 1) ? (passwd = &area->area_passwd) :
1319 (passwd = &area->domain_passwd);
1320 if (passwd->type)
1321 {
1322 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1323 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1324 }
jardineb5d44e2003-12-23 08:09:43 +00001325 if (lsp->tlv_data.nlpids)
1326 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1327 if (lsp->tlv_data.hostname)
1328 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001329 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001330 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001331
jardineb5d44e2003-12-23 08:09:43 +00001332 memset (&tlv_data, 0, sizeof (struct tlvs));
1333 /*
hasso18a6dce2004-10-03 18:18:34 +00001334 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1335 * one IPv4 address is put into LSP and this address is same as router id.
1336 */
1337 if (router_id_zebra.s_addr != 0)
1338 {
hasso18a6dce2004-10-03 18:18:34 +00001339 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001340 {
1341 lsp->tlv_data.ipv4_addrs = list_new ();
1342 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1343 }
hasso18a6dce2004-10-03 18:18:34 +00001344
1345 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1346 routerid->s_addr = router_id_zebra.s_addr;
1347
1348 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
1349
1350 /*
1351 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1352 * expects list of prefix_ipv4 structures, but we have list of
1353 * in_addr structures.
1354 */
1355 add_tlv (IPV4_ADDR, IPV4_MAX_BYTELEN, (u_char *) &routerid->s_addr,
1356 lsp->pdu);
1357 }
1358 /*
jardineb5d44e2003-12-23 08:09:43 +00001359 * Then build lists of tlvs related to circuits
1360 */
paul1eb8ef22005-04-07 07:30:20 +00001361 for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00001362 {
hassof390d2c2004-09-10 20:48:21 +00001363 if (circuit->state != C_STATE_UP)
1364 continue;
jardineb5d44e2003-12-23 08:09:43 +00001365
hassof390d2c2004-09-10 20:48:21 +00001366 /*
1367 * Add IPv4 internal reachability of this circuit
1368 */
1369 if (circuit->ip_router && circuit->ip_addrs &&
1370 circuit->ip_addrs->count > 0)
1371 {
1372 if (tlv_data.ipv4_int_reachs == NULL)
1373 {
1374 tlv_data.ipv4_int_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001375 tlv_data.ipv4_int_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001376 }
paul1eb8ef22005-04-07 07:30:20 +00001377 for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4))
hassof390d2c2004-09-10 20:48:21 +00001378 {
hassof390d2c2004-09-10 20:48:21 +00001379 ipreach =
hassoaac372f2005-09-01 17:52:33 +00001380 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
hassof390d2c2004-09-10 20:48:21 +00001381 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001382 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001383 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1384 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001385 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1386 }
1387
1388 }
jardineb5d44e2003-12-23 08:09:43 +00001389#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001390 /*
1391 * Add IPv6 reachability of this circuit
1392 */
1393 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1394 circuit->ipv6_non_link->count > 0)
1395 {
1396
1397 if (tlv_data.ipv6_reachs == NULL)
1398 {
1399 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001400 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001401 }
paul1eb8ef22005-04-07 07:30:20 +00001402 for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode, ipnnode,
1403 ipv6))
hassof390d2c2004-09-10 20:48:21 +00001404 {
hassof390d2c2004-09-10 20:48:21 +00001405 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001406 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hassof390d2c2004-09-10 20:48:21 +00001407 ip6reach->metric =
1408 htonl (circuit->metrics[level - 1].metric_default);
1409 ip6reach->control_info = 0;
1410 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001411 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1412 apply_mask_ipv6 (ip6prefix);
1413 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1414 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001415 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1416 }
1417 }
1418#endif /* HAVE_IPV6 */
1419
1420 switch (circuit->circ_type)
1421 {
1422 case CIRCUIT_T_BROADCAST:
1423 if (level & circuit->circuit_is_type)
1424 {
1425 if (tlv_data.is_neighs == NULL)
1426 {
1427 tlv_data.is_neighs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001428 tlv_data.is_neighs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001429 }
hassoaac372f2005-09-01 17:52:33 +00001430 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001431 if (level == 1)
1432 memcpy (is_neigh->neigh_id,
1433 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1434 else
1435 memcpy (is_neigh->neigh_id,
1436 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1437 is_neigh->metrics = circuit->metrics[level - 1];
1438 listnode_add (tlv_data.is_neighs, is_neigh);
1439 }
1440 break;
1441 case CIRCUIT_T_P2P:
1442 nei = circuit->u.p2p.neighbor;
1443 if (nei && (level & nei->circuit_t))
1444 {
1445 if (tlv_data.is_neighs == NULL)
1446 {
1447 tlv_data.is_neighs = list_new ();
1448 tlv_data.is_neighs->del = free_tlv;
1449 }
hassoaac372f2005-09-01 17:52:33 +00001450 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001451 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1452 is_neigh->metrics = circuit->metrics[level - 1];
1453 listnode_add (tlv_data.is_neighs, is_neigh);
1454 }
1455 break;
1456 case CIRCUIT_T_STATIC_IN:
1457 zlog_warn ("lsp_area_create: unsupported circuit type");
1458 break;
1459 case CIRCUIT_T_STATIC_OUT:
1460 zlog_warn ("lsp_area_create: unsupported circuit type");
1461 break;
1462 case CIRCUIT_T_DA:
1463 zlog_warn ("lsp_area_create: unsupported circuit type");
1464 break;
1465 default:
1466 zlog_warn ("lsp_area_create: unknown circuit type");
1467 }
1468 }
1469
1470 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1471 {
1472 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1473 lsp->tlv_data.ipv4_int_reachs = list_new ();
1474 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1475 &lsp->tlv_data.ipv4_int_reachs,
1476 IPV4_REACH_LEN, area->lsp_frag_threshold,
1477 tlv_add_ipv4_reachs);
1478 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1479 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1480 lsp0, area, level);
1481 }
1482
1483#ifdef HAVE_IPV6
1484 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1485 {
1486 if (lsp->tlv_data.ipv6_reachs == NULL)
1487 lsp->tlv_data.ipv6_reachs = list_new ();
1488 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1489 &lsp->tlv_data.ipv6_reachs,
1490 IPV6_REACH_LEN, area->lsp_frag_threshold,
1491 tlv_add_ipv6_reachs);
1492 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1493 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1494 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001495 }
1496#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001497
1498 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1499 {
1500 if (lsp->tlv_data.is_neighs == NULL)
1501 lsp->tlv_data.is_neighs = list_new ();
1502 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1503 &lsp->tlv_data.is_neighs,
1504 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1505 tlv_add_is_neighs);
1506 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1507 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1508 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001509 }
jardineb5d44e2003-12-23 08:09:43 +00001510
jardineb5d44e2003-12-23 08:09:43 +00001511 return;
1512}
1513#endif
1514
hasso92365882005-01-18 13:53:33 +00001515#if 0 /* Old code? */
1516static void
jardineb5d44e2003-12-23 08:09:43 +00001517build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1518{
1519 struct list *circuit_list = area->circuit_list;
1520 struct isis_circuit *circuit;
1521 u_char *tlv_ptr;
1522 struct is_neigh *is_neigh;
1523
hassof390d2c2004-09-10 20:48:21 +00001524
jardineb5d44e2003-12-23 08:09:43 +00001525 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001526 /* the 2 is for the TL plus 1 for the nlpid */
1527 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1528 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1529 *(tlv_ptr + 1) = 1; /* one protocol */
1530#ifdef HAVE_IPV6 /*dunno if its right */
1531 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001532#else
hassof390d2c2004-09-10 20:48:21 +00001533 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001534#endif /* HAVE_IPV6 */
1535
1536 /* we should add our areas here
1537 * FIXME: we need to figure out which should be added? Adj? All? First? */
1538
1539 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001540 /* the 2 is for the TL plus 1 for the virtual field */
1541 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1542 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1543 *(tlv_ptr + 2) = 0; /* virtual is zero */
1544 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001545 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001546 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1547 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001548 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001549 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001550 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001551 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001552 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001553 circuit = (struct isis_circuit *) listhead (circuit_list);
1554 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001555 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001556 *(tlv_ptr + 1) =
1557 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001558
1559 /* FIXME: scan for adjencecies and add them */
1560
1561 /* FIXME: add reachability info */
1562
hassof390d2c2004-09-10 20:48:21 +00001563 /* adding dynamic hostname if needed */
1564 if (area->dynhostname)
1565 {
1566 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1567 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1568 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1569 lsp->tlv_data.hostname = (struct hostname *)
1570 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1571 /* the -1 is to fit the length in the struct */
1572 strlen (unix_hostname ())) - 1);
1573 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1574 strlen (unix_hostname ()));
1575 }
jardineb5d44e2003-12-23 08:09:43 +00001576
1577}
hasso92365882005-01-18 13:53:33 +00001578#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +00001579
1580/*
1581 * 7.3.7 Generation on non-pseudonode LSPs
1582 */
hasso92365882005-01-18 13:53:33 +00001583static int
hassof390d2c2004-09-10 20:48:21 +00001584lsp_generate_non_pseudo (struct isis_area *area, int level)
1585{
jardineb5d44e2003-12-23 08:09:43 +00001586 struct isis_lsp *oldlsp, *newlsp;
1587 u_int32_t seq_num = 0;
1588 u_char lspid[ISIS_SYS_ID_LEN + 2];
1589
1590 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1591 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1592
1593 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001594 if ((area->is_type & level) == level)
1595 {
1596 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1597 if (oldlsp)
1598 {
1599 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1600 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1601 area->lspdb[level - 1]);
1602 /* FIXME: we should actually initiate a purge */
1603 }
1604 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1605 area->is_type, 0, level);
1606 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001607
hassof390d2c2004-09-10 20:48:21 +00001608 lsp_insert (newlsp, area->lspdb[level - 1]);
1609 /* build_lsp_data (newlsp, area); */
1610 lsp_build_nonpseudo (newlsp, area);
1611 /* time to calculate our checksum */
1612 lsp_seqnum_update (newlsp);
1613 }
jardineb5d44e2003-12-23 08:09:43 +00001614
1615 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001616 if (isis->debugs & DEBUG_ADJ_PACKETS)
1617 {
1618 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001619 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001620 }
jardineb5d44e2003-12-23 08:09:43 +00001621
1622 return ISIS_OK;
1623}
1624
1625/*
1626 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1627 */
1628int
1629lsp_l1_generate (struct isis_area *area)
1630{
hassof390d2c2004-09-10 20:48:21 +00001631 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1632 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001633
1634 return lsp_generate_non_pseudo (area, 1);
1635}
1636
jardineb5d44e2003-12-23 08:09:43 +00001637/*
1638 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1639 */
1640int
1641lsp_l2_generate (struct isis_area *area)
1642{
hassof390d2c2004-09-10 20:48:21 +00001643 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1644 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001645
1646 return lsp_generate_non_pseudo (area, 2);
1647}
1648
hasso92365882005-01-18 13:53:33 +00001649static int
jardineb5d44e2003-12-23 08:09:43 +00001650lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1651{
1652 dict_t *lspdb = area->lspdb[level - 1];
1653 struct isis_lsp *lsp, *frag;
1654 struct listnode *node;
1655 u_char lspid[ISIS_SYS_ID_LEN + 2];
1656
1657 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1658 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001659
jardineb5d44e2003-12-23 08:09:43 +00001660 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001661
hassof390d2c2004-09-10 20:48:21 +00001662 if (!lsp)
1663 {
1664 zlog_err
1665 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1666 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001667
hassof390d2c2004-09-10 20:48:21 +00001668 return ISIS_ERROR;
1669 }
1670
1671 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001672 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001673 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1674 (area->max_lsp_lifetime[level - 1],
1675 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001676 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001677
1678 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1679 {
hasso529d65b2004-12-24 00:14:50 +00001680 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1681 "seq 0x%08x, cksum 0x%04x lifetime %us",
1682 area->area_tag,
1683 level,
1684 rawlspid_print (lsp->lsp_header->lsp_id),
1685 ntohl (lsp->lsp_header->seq_num),
1686 ntohs (lsp->lsp_header->checksum),
1687 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001688 }
jardineb5d44e2003-12-23 08:09:43 +00001689
1690 lsp->last_generated = time (NULL);
1691 area->lsp_regenerate_pending[level - 1] = 0;
1692 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
paul1eb8ef22005-04-07 07:30:20 +00001693 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
hassof390d2c2004-09-10 20:48:21 +00001694 {
hassof390d2c2004-09-10 20:48:21 +00001695 frag->lsp_header->rem_lifetime = htons (isis_jitter
1696 (area->
1697 max_lsp_lifetime[level - 1],
1698 MAX_AGE_JITTER));
1699 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1700 }
jardineb5d44e2003-12-23 08:09:43 +00001701
1702 if (area->ip_circuits)
1703 isis_spf_schedule (area, level);
1704#ifdef HAVE_IPV6
1705 if (area->ipv6_circuits)
1706 isis_spf_schedule6 (area, level);
1707#endif
1708 return ISIS_OK;
1709}
1710
jardineb5d44e2003-12-23 08:09:43 +00001711/*
1712 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1713 * time and set SRM
1714 */
hassof390d2c2004-09-10 20:48:21 +00001715int
jardineb5d44e2003-12-23 08:09:43 +00001716lsp_refresh_l1 (struct thread *thread)
1717{
1718 struct isis_area *area;
1719 unsigned long ref_time;
1720
1721 area = THREAD_ARG (thread);
1722 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001723
jardineb5d44e2003-12-23 08:09:43 +00001724 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001725 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001726 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001727
1728 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001729 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1730
hassof390d2c2004-09-10 20:48:21 +00001731 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1732 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001733
jardineb5d44e2003-12-23 08:09:43 +00001734 return ISIS_OK;
1735}
1736
hassof390d2c2004-09-10 20:48:21 +00001737int
jardineb5d44e2003-12-23 08:09:43 +00001738lsp_refresh_l2 (struct thread *thread)
1739{
1740 struct isis_area *area;
1741 unsigned long ref_time;
1742
1743 area = THREAD_ARG (thread);
1744 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001745
jardineb5d44e2003-12-23 08:09:43 +00001746 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001747 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001748 lsp_non_pseudo_regenerate (area, 2);
1749
hassof390d2c2004-09-10 20:48:21 +00001750 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001751 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1752
hassof390d2c2004-09-10 20:48:21 +00001753 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1754 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001755
jardineb5d44e2003-12-23 08:09:43 +00001756 return ISIS_OK;
1757}
1758
jardineb5d44e2003-12-23 08:09:43 +00001759/*
1760 * Something has changed -> regenerate LSP
1761 */
1762
hasso92365882005-01-18 13:53:33 +00001763static int
jardineb5d44e2003-12-23 08:09:43 +00001764lsp_l1_regenerate (struct thread *thread)
1765{
1766 struct isis_area *area;
1767
1768 area = THREAD_ARG (thread);
1769 area->lsp_regenerate_pending[0] = 0;
1770
1771 return lsp_non_pseudo_regenerate (area, 1);
1772}
1773
hasso92365882005-01-18 13:53:33 +00001774static int
jardineb5d44e2003-12-23 08:09:43 +00001775lsp_l2_regenerate (struct thread *thread)
1776{
1777 struct isis_area *area;
1778
1779 area = THREAD_ARG (thread);
1780 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001781
jardineb5d44e2003-12-23 08:09:43 +00001782 return lsp_non_pseudo_regenerate (area, 2);
1783}
1784
hassof390d2c2004-09-10 20:48:21 +00001785int
jardineb5d44e2003-12-23 08:09:43 +00001786lsp_regenerate_schedule (struct isis_area *area)
1787{
1788 struct isis_lsp *lsp;
1789 u_char id[ISIS_SYS_ID_LEN + 2];
1790 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001791 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1792 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001793 now = time (NULL);
1794 /*
1795 * First level 1
1796 */
hassof390d2c2004-09-10 20:48:21 +00001797 if (area->is_type & IS_LEVEL_1)
1798 {
1799 lsp = lsp_search (id, area->lspdb[0]);
1800 if (!lsp || area->lsp_regenerate_pending[0])
1801 goto L2;
1802 /*
1803 * Throttle avoidance
1804 */
1805 diff = now - lsp->last_generated;
1806 if (diff < MIN_LSP_GEN_INTERVAL)
1807 {
1808 area->lsp_regenerate_pending[0] = 1;
1809 thread_add_timer (master, lsp_l1_regenerate, area,
1810 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001811 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001812 }
1813 else
1814 lsp_non_pseudo_regenerate (area, 1);
1815 }
jardineb5d44e2003-12-23 08:09:43 +00001816 /*
1817 * then 2
1818 */
hassof390d2c2004-09-10 20:48:21 +00001819L2:
1820 if (area->is_type & IS_LEVEL_2)
1821 {
1822 lsp = lsp_search (id, area->lspdb[1]);
1823 if (!lsp || area->lsp_regenerate_pending[1])
1824 return ISIS_OK;
1825 /*
1826 * Throttle avoidance
1827 */
1828 diff = now - lsp->last_generated;
1829 if (diff < MIN_LSP_GEN_INTERVAL)
1830 {
1831 area->lsp_regenerate_pending[1] = 1;
1832 thread_add_timer (master, lsp_l2_regenerate, area,
1833 MIN_LSP_GEN_INTERVAL - diff);
1834 return ISIS_OK;
1835 }
1836 else
1837 lsp_non_pseudo_regenerate (area, 2);
1838 }
1839
1840 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001841}
1842
1843/*
1844 * Funcs for pseudonode LSPs
1845 */
1846
1847/*
1848 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1849 */
hasso92365882005-01-18 13:53:33 +00001850static void
hassof390d2c2004-09-10 20:48:21 +00001851lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1852 int level)
jardineb5d44e2003-12-23 08:09:43 +00001853{
1854 struct isis_adjacency *adj;
1855 struct is_neigh *is_neigh;
1856 struct es_neigh *es_neigh;
1857 struct list *adj_list;
paul1eb8ef22005-04-07 07:30:20 +00001858 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00001859 struct isis_passwd *passwd;
1860
1861 assert (circuit);
1862 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001863
jardineb5d44e2003-12-23 08:09:43 +00001864 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001865 return; /* we are not DIS on this circuit */
1866
jardineb5d44e2003-12-23 08:09:43 +00001867 lsp->level = level;
1868 if (level == 1)
1869 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1870 else
1871 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1872
1873 /*
1874 * add self to IS neighbours
1875 */
hassof390d2c2004-09-10 20:48:21 +00001876 if (lsp->tlv_data.is_neighs == NULL)
1877 {
1878 lsp->tlv_data.is_neighs = list_new ();
1879 lsp->tlv_data.is_neighs->del = free_tlv;
1880 }
paul15935e92005-05-03 09:27:23 +00001881 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1882
jardineb5d44e2003-12-23 08:09:43 +00001883 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1884 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001885
1886 adj_list = list_new ();
1887 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1888
paul1eb8ef22005-04-07 07:30:20 +00001889 for (ALL_LIST_ELEMENTS (adj_list, node, nnode, adj))
hassof390d2c2004-09-10 20:48:21 +00001890 {
hassof390d2c2004-09-10 20:48:21 +00001891 if (adj->circuit_t & level)
1892 {
1893 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1894 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1895 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1896 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1897 {
1898 /* an IS neighbour -> add it */
paul15935e92005-05-03 09:27:23 +00001899 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1900
hassof390d2c2004-09-10 20:48:21 +00001901 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1902 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1903 }
1904 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1905 {
1906 /* an ES neigbour add it, if we are building level 1 LSP */
1907 /* FIXME: the tlv-format is hard to use here */
1908 if (lsp->tlv_data.es_neighs == NULL)
1909 {
1910 lsp->tlv_data.es_neighs = list_new ();
1911 lsp->tlv_data.es_neighs->del = free_tlv;
1912 }
paul15935e92005-05-03 09:27:23 +00001913 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1914
hassof390d2c2004-09-10 20:48:21 +00001915 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001916 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001917 }
1918 }
jardineb5d44e2003-12-23 08:09:43 +00001919 }
hassof390d2c2004-09-10 20:48:21 +00001920
hassoc0fb2a52005-09-03 16:29:40 +00001921 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001922 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001923 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1924
jardineb5d44e2003-12-23 08:09:43 +00001925 /*
1926 * Add the authentication info if it's present
1927 */
hassof390d2c2004-09-10 20:48:21 +00001928 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1929 (passwd = &circuit->area->domain_passwd);
1930 if (passwd->type)
1931 {
1932 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1933 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1934 }
jardineb5d44e2003-12-23 08:09:43 +00001935
1936 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1937 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1938
1939 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1940 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1941
paul9985f832005-02-09 15:51:56 +00001942 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001943 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1944 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1945
jardineb5d44e2003-12-23 08:09:43 +00001946 list_delete (adj_list);
1947
1948 return;
1949}
1950
hasso92365882005-01-18 13:53:33 +00001951static int
jardineb5d44e2003-12-23 08:09:43 +00001952lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1953{
1954 dict_t *lspdb = circuit->area->lspdb[level - 1];
1955 struct isis_lsp *lsp;
1956 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001957
jardineb5d44e2003-12-23 08:09:43 +00001958 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001959 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1960 LSP_FRAGMENT (lsp_id) = 0;
1961
jardineb5d44e2003-12-23 08:09:43 +00001962 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001963
1964 if (!lsp)
1965 {
1966 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1967 rawlspid_print (lsp_id));
1968 return ISIS_ERROR;
1969 }
1970 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001971
1972 lsp_build_pseudo (lsp, circuit, level);
1973
hassof390d2c2004-09-10 20:48:21 +00001974 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001975 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001976 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001977
1978 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001979
1980 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1981 {
hasso529d65b2004-12-24 00:14:50 +00001982 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1983 circuit->area->area_tag, level,
1984 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001985 }
jardineb5d44e2003-12-23 08:09:43 +00001986
1987 lsp->last_generated = time (NULL);
1988 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001989
jardineb5d44e2003-12-23 08:09:43 +00001990 return ISIS_OK;
1991}
1992
jardineb5d44e2003-12-23 08:09:43 +00001993int
1994lsp_l1_refresh_pseudo (struct thread *thread)
1995{
1996 struct isis_circuit *circuit;
1997 int retval;
1998 unsigned long ref_time;
1999
hassof390d2c2004-09-10 20:48:21 +00002000 circuit = THREAD_ARG (thread);
2001
jardineb5d44e2003-12-23 08:09:43 +00002002 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002003 return ISIS_ERROR; /* FIXME: purge and such */
2004
hasso13c48f72004-09-10 21:19:13 +00002005 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2006
jardineb5d44e2003-12-23 08:09:43 +00002007 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002008
2009 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002010 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2011
hassof390d2c2004-09-10 20:48:21 +00002012 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2013 lsp_l1_refresh_pseudo, circuit,
2014 isis_jitter (ref_time, MAX_AGE_JITTER));
2015
jardineb5d44e2003-12-23 08:09:43 +00002016 return retval;
2017}
2018
hassof390d2c2004-09-10 20:48:21 +00002019int
jardineb5d44e2003-12-23 08:09:43 +00002020lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2021{
2022 struct isis_lsp *lsp;
2023 u_char id[ISIS_SYS_ID_LEN + 2];
2024 unsigned long ref_time;
2025
hassof390d2c2004-09-10 20:48:21 +00002026 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2027 LSP_FRAGMENT (id) = 0;
2028 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002029
2030 /*
2031 * If for some reason have a pseudo LSP in the db already -> regenerate
2032 */
2033 if (lsp_search (id, circuit->area->lspdb[0]))
2034 return lsp_pseudo_regenerate (circuit, 1);
2035 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002036 1, circuit->area->is_type, 0, 1);
2037
jardineb5d44e2003-12-23 08:09:43 +00002038 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002039
jardineb5d44e2003-12-23 08:09:43 +00002040 lsp->own_lsp = 1;
2041 lsp_insert (lsp, circuit->area->lspdb[0]);
2042 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2043
hassof390d2c2004-09-10 20:48:21 +00002044 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002045 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2046
hassof390d2c2004-09-10 20:48:21 +00002047 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2048 lsp_l1_refresh_pseudo, circuit,
2049 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002050
2051 return lsp_regenerate_schedule (circuit->area);
2052}
2053
2054int
2055lsp_l2_refresh_pseudo (struct thread *thread)
2056{
2057 struct isis_circuit *circuit;
2058 int retval;
2059 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002060 circuit = THREAD_ARG (thread);
2061
jardineb5d44e2003-12-23 08:09:43 +00002062 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002063 return ISIS_ERROR; /* FIXME: purge and such */
2064
hasso13c48f72004-09-10 21:19:13 +00002065 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2066
jardineb5d44e2003-12-23 08:09:43 +00002067 retval = lsp_pseudo_regenerate (circuit, 2);
2068
hassof390d2c2004-09-10 20:48:21 +00002069 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002070 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2071
hassof390d2c2004-09-10 20:48:21 +00002072 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2073 lsp_l2_refresh_pseudo, circuit,
2074 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002075
jardineb5d44e2003-12-23 08:09:43 +00002076 return retval;
2077}
2078
hassof390d2c2004-09-10 20:48:21 +00002079int
jardineb5d44e2003-12-23 08:09:43 +00002080lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2081{
2082 struct isis_lsp *lsp;
2083 u_char id[ISIS_SYS_ID_LEN + 2];
2084 unsigned long ref_time;
2085
hassof390d2c2004-09-10 20:48:21 +00002086 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2087 LSP_FRAGMENT (id) = 0;
2088 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002089
2090 if (lsp_search (id, circuit->area->lspdb[1]))
2091 return lsp_pseudo_regenerate (circuit, 2);
2092
2093 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002094 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002095
2096 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002097
2098 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002099 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2100
2101
2102 lsp->own_lsp = 1;
2103 lsp_insert (lsp, circuit->area->lspdb[1]);
2104 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002105
2106 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2107 lsp_l2_refresh_pseudo, circuit,
2108 isis_jitter (ref_time, MAX_AGE_JITTER));
2109
jardineb5d44e2003-12-23 08:09:43 +00002110 return lsp_regenerate_schedule (circuit->area);
2111}
2112
jardineb5d44e2003-12-23 08:09:43 +00002113/*
2114 * Walk through LSPs for an area
2115 * - set remaining lifetime
2116 * - set LSPs with SRMflag set for sending
2117 */
hassof390d2c2004-09-10 20:48:21 +00002118int
jardineb5d44e2003-12-23 08:09:43 +00002119lsp_tick (struct thread *thread)
2120{
2121 struct isis_area *area;
2122 struct isis_circuit *circuit;
2123 struct isis_lsp *lsp;
2124 struct list *lsp_list;
paul1eb8ef22005-04-07 07:30:20 +00002125 struct listnode *lspnode, *lspnnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002126 dnode_t *dnode, *dnode_next;
2127 int level;
2128
2129 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002130
jardineb5d44e2003-12-23 08:09:43 +00002131 area = THREAD_ARG (thread);
2132 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002133 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002134 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002135
2136 /*
2137 * Build a list of LSPs with (any) SRMflag set
2138 * and removed the ones that have aged out
2139 */
hassof390d2c2004-09-10 20:48:21 +00002140 for (level = 0; level < ISIS_LEVELS; level++)
2141 {
2142 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2143 {
2144 dnode = dict_first (area->lspdb[level]);
2145 while (dnode != NULL)
2146 {
2147 dnode_next = dict_next (area->lspdb[level], dnode);
2148 lsp = dnode_get (dnode);
2149 lsp_set_time (lsp);
2150 if (lsp->age_out == 0)
2151 {
jardineb5d44e2003-12-23 08:09:43 +00002152
hasso529d65b2004-12-24 00:14:50 +00002153 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2154 area->area_tag,
2155 lsp->level,
2156 rawlspid_print (lsp->lsp_header->lsp_id),
2157 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002158
hassof390d2c2004-09-10 20:48:21 +00002159 lsp_destroy (lsp);
2160 dict_delete (area->lspdb[level], dnode);
2161 }
2162 else if (flags_any_set (lsp->SRMflags))
2163 listnode_add (lsp_list, lsp);
2164 dnode = dnode_next;
2165 }
jardineb5d44e2003-12-23 08:09:43 +00002166
hassof390d2c2004-09-10 20:48:21 +00002167 /*
2168 * Send LSPs on circuits indicated by the SRMflags
2169 */
2170 if (listcount (lsp_list) > 0)
2171 {
paul1eb8ef22005-04-07 07:30:20 +00002172 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00002173 {
paul1eb8ef22005-04-07 07:30:20 +00002174 for (ALL_LIST_ELEMENTS (lsp_list, lspnode, lspnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002175 {
hassof390d2c2004-09-10 20:48:21 +00002176 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2177 {
2178 /* FIXME: if same or elder lsp is already in lsp
2179 * queue */
2180 listnode_add (circuit->lsp_queue, lsp);
2181 thread_add_event (master, send_lsp, circuit, 0);
2182 }
2183 }
2184 }
2185 }
2186 list_delete_all_node (lsp_list);
2187 }
jardineb5d44e2003-12-23 08:09:43 +00002188 }
jardineb5d44e2003-12-23 08:09:43 +00002189
2190 list_delete (lsp_list);
2191
2192 return ISIS_OK;
2193}
2194
jardineb5d44e2003-12-23 08:09:43 +00002195void
hassof390d2c2004-09-10 20:48:21 +00002196lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002197{
2198 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002199
jardineb5d44e2003-12-23 08:09:43 +00002200 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002201
2202 if (lsp && lsp->purged == 0)
2203 {
2204 lsp->lsp_header->rem_lifetime = htons (0);
2205 lsp->lsp_header->pdu_len =
2206 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2207 lsp->purged = 0;
2208 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2209 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2210 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2211 }
2212
jardineb5d44e2003-12-23 08:09:43 +00002213 return;
2214}
2215
2216/*
2217 * Purge own LSP that is received and we don't have.
2218 * -> Do as in 7.3.16.4
2219 */
2220void
hassof390d2c2004-09-10 20:48:21 +00002221lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2222 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002223{
2224 struct isis_lsp *lsp;
2225
2226 /*
2227 * We need to create the LSP to be purged
2228 */
hasso529d65b2004-12-24 00:14:50 +00002229 zlog_debug ("LSP PURGE NON EXIST");
hassoaac372f2005-09-01 17:52:33 +00002230 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002231 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2232 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002233 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2234 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002235 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002236 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002237 : L2_LINK_STATE);
2238 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2239 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002240 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002241
jardineb5d44e2003-12-23 08:09:43 +00002242 /*
2243 * Retain only LSP header
2244 */
2245 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2246 /*
2247 * Set the remaining lifetime to 0
2248 */
2249 lsp->lsp_header->rem_lifetime = 0;
2250 /*
2251 * Put the lsp into LSPdb
2252 */
hassof390d2c2004-09-10 20:48:21 +00002253 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002254
2255 /*
2256 * Send in to whole area
2257 */
2258 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002259
jardineb5d44e2003-12-23 08:09:43 +00002260 return;
2261}
2262
2263#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002264static int
jardineb5d44e2003-12-23 08:09:43 +00002265top_lsp_refresh (struct thread *thread)
2266{
hassof390d2c2004-09-10 20:48:21 +00002267 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002268
2269 lsp = THREAD_ARG (thread);
2270 assert (lsp);
2271
2272 lsp->t_lsp_top_ref = NULL;
2273
hassof390d2c2004-09-10 20:48:21 +00002274 lsp->lsp_header->rem_lifetime =
2275 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2276 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002277
2278 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002279 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2280 {
hasso529d65b2004-12-24 00:14:50 +00002281 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2282 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002283 }
jardineb5d44e2003-12-23 08:09:43 +00002284
2285 /* time to calculate our checksum */
2286 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002287 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2288 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2289 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 return ISIS_OK;
2292}
2293
2294void
2295generate_topology_lsps (struct isis_area *area)
2296{
2297 struct listnode *node;
2298 int i, max = 0;
2299 struct arc *arc;
2300 u_char lspid[ISIS_SYS_ID_LEN + 2];
2301 struct isis_lsp *lsp;
2302
2303 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002304 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002305 {
2306 if (arc->from_node > max)
2307 max = arc->from_node;
2308 if (arc->to_node > max)
2309 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002310 }
2311
hassof390d2c2004-09-10 20:48:21 +00002312 for (i = 1; i < (max + 1); i++)
2313 {
2314 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2315 LSP_PSEUDO_ID (lspid) = 0x00;
2316 LSP_FRAGMENT (lspid) = 0x00;
2317 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2318 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002319
hassof390d2c2004-09-10 20:48:21 +00002320 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2321 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2322 1);
2323 lsp->from_topology = 1;
2324 /* creating data based on topology */
2325 build_topology_lsp_data (lsp, area, i);
2326 /* time to calculate our checksum */
2327 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2328 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2329 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2330 isis_jitter (MAX_LSP_GEN_INTERVAL,
2331 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002332
hassof390d2c2004-09-10 20:48:21 +00002333 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2334 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002335
hassof390d2c2004-09-10 20:48:21 +00002336 }
jardineb5d44e2003-12-23 08:09:43 +00002337}
2338
2339void
2340remove_topology_lsps (struct isis_area *area)
2341{
2342 struct isis_lsp *lsp;
2343 dnode_t *dnode, *dnode_next;
2344
2345 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002346 while (dnode != NULL)
2347 {
2348 dnode_next = dict_next (area->lspdb[0], dnode);
2349 lsp = dnode_get (dnode);
2350 if (lsp->from_topology)
2351 {
2352 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2353 lsp_destroy (lsp);
2354 dict_delete (area->lspdb[0], dnode);
2355 }
2356 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002357 }
jardineb5d44e2003-12-23 08:09:43 +00002358}
2359
2360void
hassof390d2c2004-09-10 20:48:21 +00002361build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002362 int lsp_top_num)
2363{
paula8f03df2005-04-10 15:58:10 +00002364 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00002365 struct arc *arc;
2366 u_char *tlv_ptr;
2367 struct is_neigh *is_neigh;
2368 int to_lsp = 0;
2369 char buff[200];
2370
2371 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002372 /* the 2 is for the TL plus 1 for the nlpid */
2373 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2374 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2375 *(tlv_ptr + 1) = 1; /* one protocol */
2376 *(tlv_ptr + 2) = NLPID_IP;
2377 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002378
2379 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002380 /* the 2 is for the TL plus 1 for the virtual field */
2381 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2382 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2383 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2384 *(tlv_ptr + 2) = 0; /* virtual is zero */
2385 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002386
2387 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002388 if (lsp_top_num == 1)
2389 {
jardineb5d44e2003-12-23 08:09:43 +00002390 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002391 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2392 sizeof (struct
2393 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002394 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002395 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2396 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002397 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002398 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002399 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2400 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2401 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2402 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002403 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2404 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002405 }
hassof390d2c2004-09-10 20:48:21 +00002406
2407 /* addding is reachabilities */
paula8f03df2005-04-10 15:58:10 +00002408 for (ALL_LIST_ELEMENTS (area->topology, node, nnode, arc))
hassof390d2c2004-09-10 20:48:21 +00002409 {
2410 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2411 {
2412 if (arc->to_node == lsp_top_num)
2413 to_lsp = arc->from_node;
2414 if (arc->from_node == lsp_top_num)
2415 to_lsp = arc->to_node;
2416
2417 /* if the length here is about to cross the FF limit, we reTLV */
2418 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2419 {
2420 /* retlv */
2421 /* the 2 is for the TL plus 1 for the virtual field */
2422 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2423 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2424 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2425 *(tlv_ptr + 2) = 0; /* virtual is zero */
2426 }
2427 /* doing this here assures us that we won't add an "empty" tlv */
2428 /* assign space for the is_neigh at the pdu end */
2429 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2430 sizeof (struct
2431 is_neigh));
2432 /* add this node to our list */
2433 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2434 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2435 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2436 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2437 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2438 is_neigh->metrics.metric_default = arc->distance;
2439 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2440 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2441 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2442 /* don't forget the length */
2443 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2444 }
jardineb5d44e2003-12-23 08:09:43 +00002445 }
2446
hassof390d2c2004-09-10 20:48:21 +00002447 /* adding dynamic hostname if needed */
2448 if (area->dynhostname)
2449 {
2450 memset (buff, 0x00, 200);
2451 sprintf (buff, "feedme%d", lsp_top_num);
2452 /* the 2 is for the TL */
2453 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2454 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2455 *(tlv_ptr + 1) = strlen (buff); /* Length */
2456 /* the -1 is to fit the length in the struct */
2457 lsp->tlv_data.hostname = (struct hostname *)
2458 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2459 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2460 }
jardineb5d44e2003-12-23 08:09:43 +00002461}
2462#endif /* TOPOLOGY_GENERATE */