blob: a294bc8f0c464c2e3ebf95121c01edf9d02ff894 [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{
hasso4eda93a2005-09-18 17:51:02 +0000421 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000422
423 /* Remove old LSP from LSP database. */
hasso4eda93a2005-09-18 17:51:02 +0000424 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
425 if (dnode)
426 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000427
hassof390d2c2004-09-10 20:48:21 +0000428 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000429 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
430 lsp_clear_data (lsp);
431
432 /* rebuild the lsp data */
433 lsp_update_data (lsp, stream, area);
434
hassof390d2c2004-09-10 20:48:21 +0000435 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000436 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassoa96d8d12005-09-16 14:44:23 +0000437
hasso4eda93a2005-09-18 17:51:02 +0000438 if (dnode)
439 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000440}
441
jardineb5d44e2003-12-23 08:09:43 +0000442/* creation of LSP directly from what we received */
443struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000444lsp_new_from_stream_ptr (struct stream *stream,
445 u_int16_t pdu_len, struct isis_lsp *lsp0,
446 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000447{
448 struct isis_lsp *lsp;
449
hassoaac372f2005-09-01 17:52:33 +0000450 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
jardineb5d44e2003-12-23 08:09:43 +0000451 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000452
453 if (lsp0 == NULL)
454 {
455 /*
456 * zero lsp -> create the list for fragments
457 */
458 lsp->lspu.frags = list_new ();
459 }
460 else
461 {
462 /*
463 * a fragment -> set the backpointer and add this to zero lsps frag list
464 */
465 lsp->lspu.zero_lsp = lsp0;
466 listnode_add (lsp0->lspu.frags, lsp);
467 }
468
jardineb5d44e2003-12-23 08:09:43 +0000469 return lsp;
470}
471
472struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000473lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
474 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000475{
476 struct isis_lsp *lsp;
477
hassoaac372f2005-09-01 17:52:33 +0000478 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000479 if (!lsp)
480 {
481 /* FIXME: set lspdbol bit */
482 zlog_warn ("lsp_new(): out of memory");
483 return NULL;
484 }
jardineb5d44e2003-12-23 08:09:43 +0000485#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000486 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000487#else
hassof390d2c2004-09-10 20:48:21 +0000488 /* We need to do realloc on TLVs additions */
489 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000490#endif /* LSP_MEMORY_PREASSIGN */
491 if (LSP_FRAGMENT (lsp_id) == 0)
492 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000493 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
494 lsp->lsp_header = (struct isis_link_state_hdr *)
495 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
496
jardineb5d44e2003-12-23 08:09:43 +0000497 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000498 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
499 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
500
jardineb5d44e2003-12-23 08:09:43 +0000501 /* now for the LSP HEADER */
502 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000503 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000504 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000505 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000506 lsp->lsp_header->seq_num = htonl (seq_num);
507 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
508 lsp->lsp_header->lsp_bits = lsp_bits;
509 lsp->level = level;
510 lsp->age_out = ZERO_AGE_LIFETIME;
511
paul9985f832005-02-09 15:51:56 +0000512 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000513
hassoc89c05d2005-09-04 21:36:36 +0000514 if (isis->debugs & DEBUG_EVENTS)
515 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x",
516 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
517 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
518 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000519
520 return lsp;
521}
522
523void
hassof390d2c2004-09-10 20:48:21 +0000524lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000525{
526 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
527}
528
529/*
530 * Build a list of LSPs with non-zero ht bounded by start and stop ids
531 */
hassof390d2c2004-09-10 20:48:21 +0000532void
533lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
534 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000535{
536 dnode_t *first, *last, *curr;
537
538 first = dict_lower_bound (lspdb, start_id);
539 if (!first)
540 return;
hassof390d2c2004-09-10 20:48:21 +0000541
jardineb5d44e2003-12-23 08:09:43 +0000542 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000543
jardineb5d44e2003-12-23 08:09:43 +0000544 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000545
546 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000547 listnode_add (list, first->dict_data);
548
hassof390d2c2004-09-10 20:48:21 +0000549 while (curr)
550 {
551 curr = dict_next (lspdb, curr);
552 if (curr &&
553 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
554 listnode_add (list, curr->dict_data);
555 if (curr == last)
556 break;
557 }
558
jardineb5d44e2003-12-23 08:09:43 +0000559 return;
560}
561
562/*
563 * Build a list of all LSPs bounded by start and stop ids
564 */
hassof390d2c2004-09-10 20:48:21 +0000565void
566lsp_build_list (u_char * start_id, u_char * stop_id,
567 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000568{
569 dnode_t *first, *last, *curr;
570
571 first = dict_lower_bound (lspdb, start_id);
572 if (!first)
573 return;
hassof390d2c2004-09-10 20:48:21 +0000574
jardineb5d44e2003-12-23 08:09:43 +0000575 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000576
jardineb5d44e2003-12-23 08:09:43 +0000577 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000578
jardineb5d44e2003-12-23 08:09:43 +0000579 listnode_add (list, first->dict_data);
580
hassof390d2c2004-09-10 20:48:21 +0000581 while (curr)
582 {
583 curr = dict_next (lspdb, curr);
584 if (curr)
585 listnode_add (list, curr->dict_data);
586 if (curr == last)
587 break;
588 }
589
jardineb5d44e2003-12-23 08:09:43 +0000590 return;
591}
592
593/*
594 * Build a list of LSPs with SSN flag set for the given circuit
595 */
596void
hassof390d2c2004-09-10 20:48:21 +0000597lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
598 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000599{
600 dnode_t *dnode, *next;
601 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000602
jardineb5d44e2003-12-23 08:09:43 +0000603 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000604 while (dnode != NULL)
605 {
606 next = dict_next (lspdb, dnode);
607 lsp = dnode_get (dnode);
608 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
609 listnode_add (list, lsp);
610 dnode = next;
611 }
612
jardineb5d44e2003-12-23 08:09:43 +0000613 return;
614}
615
hasso92365882005-01-18 13:53:33 +0000616static void
jardineb5d44e2003-12-23 08:09:43 +0000617lsp_set_time (struct isis_lsp *lsp)
618{
619 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000620
621 if (lsp->lsp_header->rem_lifetime == 0)
622 {
623 if (lsp->age_out != 0)
624 lsp->age_out--;
625 return;
626 }
jardineb5d44e2003-12-23 08:09:43 +0000627
628 /* If we are turning 0 */
629 /* ISO 10589 - 7.3.16.4 first paragraph */
630
hassof390d2c2004-09-10 20:48:21 +0000631 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
632 {
633 /* 7.3.16.4 a) set SRM flags on all */
634 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
635 /* 7.3.16.4 b) retain only the header FIXME */
636 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
637 }
jardineb5d44e2003-12-23 08:09:43 +0000638
hassof390d2c2004-09-10 20:48:21 +0000639 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000640 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
641}
642
hasso92365882005-01-18 13:53:33 +0000643static void
hassof390d2c2004-09-10 20:48:21 +0000644lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000645{
646 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000647 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000648
649 if (dynhost)
650 dyn = dynhn_find_by_id (lsp_id);
651 else
652 dyn = NULL;
653
654 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000655 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000656 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000657 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000658 else
hassof390d2c2004-09-10 20:48:21 +0000659 {
660 memcpy (id, sysid_print (lsp_id), 15);
661 }
662 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000663 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000664 LSP_FRAGMENT (lsp_id));
665 else
hassof7c43dc2004-09-26 16:24:14 +0000666 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000667}
668
hassof390d2c2004-09-10 20:48:21 +0000669/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000670const char *
hassof390d2c2004-09-10 20:48:21 +0000671lsp_bits2string (u_char * lsp_bits)
672{
673 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000674
hassof390d2c2004-09-10 20:48:21 +0000675 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000676 return " none";
677
678 /* we only focus on the default metric */
679 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000680 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000681
682 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000683 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000684
hassof390d2c2004-09-10 20:48:21 +0000685 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
686
jardineb5d44e2003-12-23 08:09:43 +0000687 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000688
hassof390d2c2004-09-10 20:48:21 +0000689 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000690}
691
692/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000693static void
hassof390d2c2004-09-10 20:48:21 +0000694lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000695{
hassof390d2c2004-09-10 20:48:21 +0000696 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000697 u_char LSPid[255];
698
699 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000700 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
701 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
702 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000703
hassof390d2c2004-09-10 20:48:21 +0000704 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
705 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000706 else
hassof390d2c2004-09-10 20:48:21 +0000707 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000708
709 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000710 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000711}
712
hasso92365882005-01-18 13:53:33 +0000713static void
hassof390d2c2004-09-10 20:48:21 +0000714lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000715{
716 struct isis_lsp *lsp = dnode_get (node);
717 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000718 int i;
paul1eb8ef22005-04-07 07:30:20 +0000719 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000720 struct is_neigh *is_neigh;
721 struct te_is_neigh *te_is_neigh;
722 struct ipv4_reachability *ipv4_reach;
723 struct in_addr *ipv4_addr;
724 struct te_ipv4_reachability *te_ipv4_reach;
725#ifdef HAVE_IPV6
726 struct ipv6_reachability *ipv6_reach;
727 struct in6_addr in6;
728#endif
729 u_char LSPid[255];
730 u_char hostname[255];
731 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000732 u_char ipv4_reach_prefix[20];
733 u_char ipv4_reach_mask[20];
734 u_char ipv4_address[20];
735
736 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000737 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000738
739 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000740 if (lsp->tlv_data.area_addrs)
paul1eb8ef22005-04-07 07:30:20 +0000741 for (ALL_LIST_ELEMENTS (lsp->tlv_data.area_addrs, lnode,
742 lnnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000743 {
hasso1cd80842004-10-07 20:07:40 +0000744 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000745 isonet_print (area_addr->area_addr, area_addr->addr_len),
746 VTY_NEWLINE);
747 }
paul1eb8ef22005-04-07 07:30:20 +0000748
jardineb5d44e2003-12-23 08:09:43 +0000749 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000750 if (lsp->tlv_data.nlpids)
751 {
752 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
753 {
754 switch (lsp->tlv_data.nlpids->nlpids[i])
755 {
756 case NLPID_IP:
757 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000758 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000759 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
760 break;
761 default:
hasso1cd80842004-10-07 20:07:40 +0000762 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000763 break;
764 }
765 }
766 }
jardineb5d44e2003-12-23 08:09:43 +0000767
768 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000769 if (lsp->tlv_data.hostname)
770 {
771 bzero (hostname, sizeof (hostname));
772 memcpy (hostname, lsp->tlv_data.hostname->name,
773 lsp->tlv_data.hostname->namelen);
774 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000775 }
hassof390d2c2004-09-10 20:48:21 +0000776
777 if (lsp->tlv_data.ipv4_addrs)
paul1eb8ef22005-04-07 07:30:20 +0000778 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_addrs, lnode,
779 lnnode, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000780 {
781 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
782 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
783 }
hassof390d2c2004-09-10 20:48:21 +0000784
hasso1cd80842004-10-07 20:07:40 +0000785 /* TE router id */
786 if (lsp->tlv_data.router_id)
787 {
788 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
789 sizeof (ipv4_address));
790 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
791 }
792
793 /* for the IS neighbor tlv */
794 if (lsp->tlv_data.is_neighs)
paul1eb8ef22005-04-07 07:30:20 +0000795 for (ALL_LIST_ELEMENTS (lsp->tlv_data.is_neighs, lnode, lnnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000796 {
797 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
798 vty_out (vty, " Metric: %d IS %s%s",
799 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
800 }
hasso1cd80842004-10-07 20:07:40 +0000801
jardineb5d44e2003-12-23 08:09:43 +0000802 /* for the internal reachable tlv */
803 if (lsp->tlv_data.ipv4_int_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000804 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_int_reachs, lnode,
805 lnnode, ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000806 {
807 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
808 sizeof (ipv4_reach_prefix));
809 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
810 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000811 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000812 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
813 ipv4_reach_mask, VTY_NEWLINE);
814 }
hasso2097cd82003-12-23 11:51:08 +0000815
816 /* for the external reachable tlv */
817 if (lsp->tlv_data.ipv4_ext_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000818 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_ext_reachs, lnode,
819 lnnode, ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000820 {
821 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
822 sizeof (ipv4_reach_prefix));
823 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
824 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000825 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000826 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
827 ipv4_reach_mask, VTY_NEWLINE);
828 }
paul1eb8ef22005-04-07 07:30:20 +0000829
hasso2097cd82003-12-23 11:51:08 +0000830 /* IPv6 tlv */
831#ifdef HAVE_IPV6
832 if (lsp->tlv_data.ipv6_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000833 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv6_reachs, lnode,
834 lnnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000835 {
836 memset (&in6, 0, sizeof (in6));
837 memcpy (in6.s6_addr, ipv6_reach->prefix,
838 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000839 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000840 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000841 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
842 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
843 ntohl (ipv6_reach->metric),
844 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000845 else
hassof390d2c2004-09-10 20:48:21 +0000846 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
847 ntohl (ipv6_reach->metric),
848 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000849 }
850#endif
paul1eb8ef22005-04-07 07:30:20 +0000851
hasso1cd80842004-10-07 20:07:40 +0000852 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000853 if (lsp->tlv_data.te_is_neighs)
paul1eb8ef22005-04-07 07:30:20 +0000854 for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_is_neighs, lnode,
855 lnnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000856 {
hasso1cd80842004-10-07 20:07:40 +0000857 /* FIXME: metric display is wrong. */
hassof390d2c2004-09-10 20:48:21 +0000858 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso1cd80842004-10-07 20:07:40 +0000859 vty_out (vty, " Metric: %d extd-IS %s%s",
860 te_is_neigh->te_metric[0], LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000861 }
jardineb5d44e2003-12-23 08:09:43 +0000862
hasso1cd80842004-10-07 20:07:40 +0000863 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000864 if (lsp->tlv_data.te_ipv4_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000865 for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_ipv4_reachs, lnode,
866 lnnode, te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000867 {
hasso1cd80842004-10-07 20:07:40 +0000868 /* FIXME: There should be better way to output this stuff. */
hasso2e864cf2004-10-08 06:40:24 +0000869 vty_out (vty, " Metric: %d extd-IP %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000870 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000871 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
872 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000873 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000874 }
jardineb5d44e2003-12-23 08:09:43 +0000875
hassof390d2c2004-09-10 20:48:21 +0000876 return;
jardineb5d44e2003-12-23 08:09:43 +0000877}
878
879/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000880int
881lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000882{
883
hassof390d2c2004-09-10 20:48:21 +0000884 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000885 int lsp_count = 0;
886
887 /* print the title, for both modes */
888 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000889 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
890
891 if (detail == ISIS_UI_LEVEL_BRIEF)
892 {
893 while (node != NULL)
894 {
895 /* I think it is unnecessary, so I comment it out */
896 /* dict_contains (lspdb, node); */
897 next = dict_next (lspdb, node);
898 lsp_print (node, vty, dynhost);
899 node = next;
900 lsp_count++;
901 }
jardineb5d44e2003-12-23 08:09:43 +0000902 }
hassof390d2c2004-09-10 20:48:21 +0000903 else if (detail == ISIS_UI_LEVEL_DETAIL)
904 {
905 while (node != NULL)
906 {
907 next = dict_next (lspdb, node);
908 lsp_print_detail (node, vty, dynhost);
909 node = next;
910 lsp_count++;
911 }
jardineb5d44e2003-12-23 08:09:43 +0000912 }
jardineb5d44e2003-12-23 08:09:43 +0000913
914 return lsp_count;
915}
916
917/* this function reallocate memory to an lsp pdu, with an additional
918 * size of memory, it scans the lsp and moves all pointers the
919 * way they should */
hasso92365882005-01-18 13:53:33 +0000920static u_char *
hassof390d2c2004-09-10 20:48:21 +0000921lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +0000922{
923 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +0000924
925 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000926#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000927 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +0000928 return retval;
hassof390d2c2004-09-10 20:48:21 +0000929#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +0000930 u_char *newpdu;
931 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassoaac372f2005-09-01 17:52:33 +0000932 stream_put (newpdu, STREAM_DATA(lsp->pdu), ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +0000933 XFREE (memorytype, lsp->pdu);
934 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +0000935 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
936 lsp->lsp_header = (struct isis_link_state_hdr *)
937 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000938 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +0000939 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +0000940#endif /* LSP_MEMORY_PREASSIGN */
941}
942
hassof390d2c2004-09-10 20:48:21 +0000943#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +0000944/*
945 * Builds the lsp->tlv_data
946 * and writes the tlvs into lsp->pdu
947 */
948void
949lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
950{
951 struct is_neigh *is_neigh;
paul1eb8ef22005-04-07 07:30:20 +0000952 struct listnode *node, *nnode, *ipnode, *ipnnode;
jardineb5d44e2003-12-23 08:09:43 +0000953 int level = lsp->level;
954 struct isis_circuit *circuit;
955 struct prefix_ipv4 *ipv4;
956 struct ipv4_reachability *ipreach;
957 struct isis_adjacency *nei;
958#ifdef HAVE_IPV6
959 struct prefix_ipv6 *ipv6;
960 struct ipv6_reachability *ip6reach;
961#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000962
jardineb5d44e2003-12-23 08:09:43 +0000963 /*
964 * First add the tlvs related to area
965 */
hassof390d2c2004-09-10 20:48:21 +0000966
jardineb5d44e2003-12-23 08:09:43 +0000967 /* Area addresses */
968 if (lsp->tlv_data.area_addrs == NULL)
969 lsp->tlv_data.area_addrs = list_new ();
970 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
971 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +0000972 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +0000973#ifdef HAVE_IPV6
974 || area->ipv6_circuits > 0
975#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000976 )
jardineb5d44e2003-12-23 08:09:43 +0000977 {
978 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
979 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +0000980 if (area->ip_circuits > 0)
981 {
982 lsp->tlv_data.nlpids->count++;
983 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
984 }
jardineb5d44e2003-12-23 08:09:43 +0000985#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000986 if (area->ipv6_circuits > 0)
987 {
988 lsp->tlv_data.nlpids->count++;
989 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
990 NLPID_IPV6;
991 }
jardineb5d44e2003-12-23 08:09:43 +0000992#endif /* HAVE_IPV6 */
993 }
994 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +0000995 if (area->dynhostname)
996 {
997 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
998 sizeof (struct hostname));
999 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
1000 strlen (unix_hostname ()));
1001 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1002 }
jardineb5d44e2003-12-23 08:09:43 +00001003#ifdef TOPOLOGY_GENERATE
1004 /*
1005 * If we have a topology in this area, we need to connect this lsp to
1006 * the first topology lsp
1007 */
hassof390d2c2004-09-10 20:48:21 +00001008 if ((area->topology) && (level == 1))
1009 {
1010 if (lsp->tlv_data.is_neighs == NULL)
1011 lsp->tlv_data.is_neighs = list_new ();
hassoaac372f2005-09-01 17:52:33 +00001012 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001013 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1014 /* connected to the first */
1015 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1016 /* this is actually the same system, why mess the SPT */
1017 is_neigh->metrics.metric_default = 0;
1018 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1019 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1020 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1021 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001022
hassof390d2c2004-09-10 20:48:21 +00001023 }
jardineb5d44e2003-12-23 08:09:43 +00001024#endif
1025
1026 /*
1027 * Then add tlvs related to circuits
1028 */
paul1eb8ef22005-04-07 07:30:20 +00001029 for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00001030 {
hassof390d2c2004-09-10 20:48:21 +00001031 if (circuit->state != C_STATE_UP)
1032 continue;
1033
1034 /*
1035 * Add IPv4 internal reachability of this circuit
1036 */
1037 if (circuit->ip_router && circuit->ip_addrs &&
1038 circuit->ip_addrs->count > 0)
1039 {
1040 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1041 {
1042 lsp->tlv_data.ipv4_int_reachs = list_new ();
1043 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1044 }
paul1eb8ef22005-04-07 07:30:20 +00001045 for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4))
hassof390d2c2004-09-10 20:48:21 +00001046 {
hassof390d2c2004-09-10 20:48:21 +00001047 ipreach =
hassoaac372f2005-09-01 17:52:33 +00001048 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
hassof390d2c2004-09-10 20:48:21 +00001049 ipreach->metrics = circuit->metrics[level - 1];
1050 ipreach->prefix = ipv4->prefix;
1051 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1052 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1053 }
1054 }
jardineb5d44e2003-12-23 08:09:43 +00001055#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001056 /*
1057 * Add IPv6 reachability of this circuit
1058 */
1059 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1060 circuit->ipv6_non_link->count > 0)
1061 {
1062 if (lsp->tlv_data.ipv6_reachs == NULL)
1063 {
1064 lsp->tlv_data.ipv6_reachs = list_new ();
1065 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1066 }
paul1eb8ef22005-04-07 07:30:20 +00001067 for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode,
1068 ipnnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001069 {
hassof390d2c2004-09-10 20:48:21 +00001070 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001071 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hassof390d2c2004-09-10 20:48:21 +00001072 ip6reach->metric =
1073 htonl (circuit->metrics[level - 1].metric_default);
1074 ip6reach->control_info = 0;
1075 ip6reach->prefix_len = ipv6->prefixlen;
1076 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1077 (ipv6->prefixlen + 7) / 8);
1078 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1079 }
1080 }
jardineb5d44e2003-12-23 08:09:43 +00001081#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001082
1083 switch (circuit->circ_type)
1084 {
1085 case CIRCUIT_T_BROADCAST:
1086 if (level & circuit->circuit_is_type)
1087 {
1088 if (lsp->tlv_data.is_neighs == NULL)
1089 {
1090 lsp->tlv_data.is_neighs = list_new ();
1091 lsp->tlv_data.is_neighs->del = free_tlv;
1092 }
hassoaac372f2005-09-01 17:52:33 +00001093 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001094 if (level == 1)
1095 memcpy (&is_neigh->neigh_id,
1096 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1097 else
1098 memcpy (&is_neigh->neigh_id,
1099 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1100 is_neigh->metrics = circuit->metrics[level - 1];
1101 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1102 }
1103 break;
1104 case CIRCUIT_T_P2P:
1105 nei = circuit->u.p2p.neighbor;
1106 if (nei && (level & nei->circuit_t))
1107 {
1108 if (lsp->tlv_data.is_neighs == NULL)
1109 {
1110 lsp->tlv_data.is_neighs = list_new ();
1111 lsp->tlv_data.is_neighs->del = free_tlv;
1112 }
hassoaac372f2005-09-01 17:52:33 +00001113 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001114 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1115 is_neigh->metrics = circuit->metrics[level - 1];
1116 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1117 }
1118 break;
1119 case CIRCUIT_T_STATIC_IN:
1120 zlog_warn ("lsp_area_create: unsupported circuit type");
1121 break;
1122 case CIRCUIT_T_STATIC_OUT:
1123 zlog_warn ("lsp_area_create: unsupported circuit type");
1124 break;
1125 case CIRCUIT_T_DA:
1126 zlog_warn ("lsp_area_create: unsupported circuit type");
1127 break;
1128 default:
1129 zlog_warn ("lsp_area_create: unknown circuit type");
1130 }
jardineb5d44e2003-12-23 08:09:43 +00001131 }
hassof390d2c2004-09-10 20:48:21 +00001132
jardineb5d44e2003-12-23 08:09:43 +00001133 if (lsp->tlv_data.nlpids)
1134 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1135 if (lsp->tlv_data.hostname)
1136 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001137 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001138 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1139 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1140 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001141 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001142 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1143 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001144#ifdef HAVE_IPV6
1145 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001146 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1147#endif /* HAVE_IPV6 */
1148
paul9985f832005-02-09 15:51:56 +00001149 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001150
1151 return;
1152}
1153#endif
1154
1155#define FRAG_THOLD(S,T) \
1156((STREAM_SIZE(S)*T)/100)
1157
1158/* stream*, area->lsp_frag_threshold, increment */
1159#define FRAG_NEEDED(S,T,I) \
1160 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1161
hasso92365882005-01-18 13:53:33 +00001162static void
jardineb5d44e2003-12-23 08:09:43 +00001163lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001164 int tlvsize, int frag_thold,
1165 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001166{
1167 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001168
jardineb5d44e2003-12-23 08:09:43 +00001169 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001170 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1171 {
1172 tlv_build_func (*from, lsp->pdu);
1173 *to = *from;
1174 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001175 }
hassof390d2c2004-09-10 20:48:21 +00001176 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1177 {
1178 /* fit all we can */
1179 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1180 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1181 if (count)
1182 count = count / tlvsize;
1183 for (i = 0; i < count; i++)
1184 {
paul1eb8ef22005-04-07 07:30:20 +00001185 listnode_add (*to, listgetdata (listhead (*from)));
1186 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001187 }
1188 tlv_build_func (*to, lsp->pdu);
1189 }
paul9985f832005-02-09 15:51:56 +00001190 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001191 return;
1192}
1193
hasso92365882005-01-18 13:53:33 +00001194static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001195lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1196 int level)
jardineb5d44e2003-12-23 08:09:43 +00001197{
1198 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001199 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1200
jardineb5d44e2003-12-23 08:09:43 +00001201 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1202 LSP_FRAGMENT (frag_id) = frag_num;
1203 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001204 if (lsp)
1205 {
1206 /*
1207 * Clear the TLVs, but inherit the authinfo
1208 */
1209 lsp_clear_data (lsp);
1210 if (lsp0->tlv_data.auth_info.type)
1211 {
1212 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1213 sizeof (struct isis_passwd));
1214 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1215 lsp->tlv_data.auth_info.len,
1216 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1217 }
1218 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001219 }
jardineb5d44e2003-12-23 08:09:43 +00001220 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001221 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001222 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001223 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001224 listnode_add (lsp0->lspu.frags, lsp);
1225 lsp->lspu.zero_lsp = lsp0;
1226 /*
1227 * Copy the authinfo from zero LSP
1228 */
hassof390d2c2004-09-10 20:48:21 +00001229 if (lsp0->tlv_data.auth_info.type)
1230 {
1231 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1232 sizeof (struct isis_passwd));
1233 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1234 lsp->tlv_data.auth_info.len,
1235 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1236 }
jardineb5d44e2003-12-23 08:09:43 +00001237 return lsp;
1238}
1239
1240/*
1241 * Builds the LSP data part. This func creates a new frag whenever
1242 * area->lsp_frag_threshold is exceeded.
1243 */
1244#if 1
hasso92365882005-01-18 13:53:33 +00001245static void
jardineb5d44e2003-12-23 08:09:43 +00001246lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1247{
1248 struct is_neigh *is_neigh;
paul1eb8ef22005-04-07 07:30:20 +00001249 struct listnode *node, *nnode, *ipnode, *ipnnode;
jardineb5d44e2003-12-23 08:09:43 +00001250 int level = lsp->level;
1251 struct isis_circuit *circuit;
1252 struct prefix_ipv4 *ipv4;
1253 struct ipv4_reachability *ipreach;
1254 struct isis_adjacency *nei;
1255#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001256 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001257 struct ipv6_reachability *ip6reach;
1258#endif /* HAVE_IPV6 */
1259 struct tlvs tlv_data;
1260 struct isis_lsp *lsp0 = lsp;
1261 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001262 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001263
1264 /*
1265 * First add the tlvs related to area
1266 */
hassof390d2c2004-09-10 20:48:21 +00001267
jardineb5d44e2003-12-23 08:09:43 +00001268 /* Area addresses */
1269 if (lsp->tlv_data.area_addrs == NULL)
1270 lsp->tlv_data.area_addrs = list_new ();
1271 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1272 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001273 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001274#ifdef HAVE_IPV6
1275 || area->ipv6_circuits > 0
1276#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001277 )
jardineb5d44e2003-12-23 08:09:43 +00001278 {
hassoaac372f2005-09-01 17:52:33 +00001279 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001280 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001281 if (area->ip_circuits > 0)
1282 {
1283 lsp->tlv_data.nlpids->count++;
1284 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1285 }
jardineb5d44e2003-12-23 08:09:43 +00001286#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001287 if (area->ipv6_circuits > 0)
1288 {
1289 lsp->tlv_data.nlpids->count++;
1290 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1291 NLPID_IPV6;
1292 }
jardineb5d44e2003-12-23 08:09:43 +00001293#endif /* HAVE_IPV6 */
1294 }
1295 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001296 if (area->dynhostname)
1297 {
1298 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1299 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001300
hassof390d2c2004-09-10 20:48:21 +00001301 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1302 strlen (unix_hostname ()));
1303 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1304 }
jardineb5d44e2003-12-23 08:09:43 +00001305
1306 /*
1307 * Building the zero lsp
1308 */
hassoaac372f2005-09-01 17:52:33 +00001309
1310 /* Reset stream endp. Stream is always there and on every LSP refresh only
1311 * TLV part of it is overwritten. So we must seek past header we will not
1312 * touch. */
hassoc89c05d2005-09-04 21:36:36 +00001313 stream_reset (lsp->pdu);
hassoaac372f2005-09-01 17:52:33 +00001314 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1315
jardineb5d44e2003-12-23 08:09:43 +00001316 /*
1317 * Add the authentication info if its present
1318 */
hassof390d2c2004-09-10 20:48:21 +00001319 (level == 1) ? (passwd = &area->area_passwd) :
1320 (passwd = &area->domain_passwd);
1321 if (passwd->type)
1322 {
1323 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1324 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1325 }
jardineb5d44e2003-12-23 08:09:43 +00001326 if (lsp->tlv_data.nlpids)
1327 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1328 if (lsp->tlv_data.hostname)
1329 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001330 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001331 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001332
jardineb5d44e2003-12-23 08:09:43 +00001333 memset (&tlv_data, 0, sizeof (struct tlvs));
1334 /*
hasso18a6dce2004-10-03 18:18:34 +00001335 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1336 * one IPv4 address is put into LSP and this address is same as router id.
1337 */
1338 if (router_id_zebra.s_addr != 0)
1339 {
hasso18a6dce2004-10-03 18:18:34 +00001340 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001341 {
1342 lsp->tlv_data.ipv4_addrs = list_new ();
1343 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1344 }
hasso18a6dce2004-10-03 18:18:34 +00001345
1346 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1347 routerid->s_addr = router_id_zebra.s_addr;
1348
1349 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
1350
1351 /*
1352 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1353 * expects list of prefix_ipv4 structures, but we have list of
1354 * in_addr structures.
1355 */
1356 add_tlv (IPV4_ADDR, IPV4_MAX_BYTELEN, (u_char *) &routerid->s_addr,
1357 lsp->pdu);
1358 }
1359 /*
jardineb5d44e2003-12-23 08:09:43 +00001360 * Then build lists of tlvs related to circuits
1361 */
paul1eb8ef22005-04-07 07:30:20 +00001362 for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00001363 {
hassof390d2c2004-09-10 20:48:21 +00001364 if (circuit->state != C_STATE_UP)
1365 continue;
jardineb5d44e2003-12-23 08:09:43 +00001366
hassof390d2c2004-09-10 20:48:21 +00001367 /*
1368 * Add IPv4 internal reachability of this circuit
1369 */
1370 if (circuit->ip_router && circuit->ip_addrs &&
1371 circuit->ip_addrs->count > 0)
1372 {
1373 if (tlv_data.ipv4_int_reachs == NULL)
1374 {
1375 tlv_data.ipv4_int_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001376 tlv_data.ipv4_int_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001377 }
paul1eb8ef22005-04-07 07:30:20 +00001378 for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4))
hassof390d2c2004-09-10 20:48:21 +00001379 {
hassof390d2c2004-09-10 20:48:21 +00001380 ipreach =
hassoaac372f2005-09-01 17:52:33 +00001381 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
hassof390d2c2004-09-10 20:48:21 +00001382 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001383 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001384 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1385 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001386 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1387 }
1388
1389 }
jardineb5d44e2003-12-23 08:09:43 +00001390#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001391 /*
1392 * Add IPv6 reachability of this circuit
1393 */
1394 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1395 circuit->ipv6_non_link->count > 0)
1396 {
1397
1398 if (tlv_data.ipv6_reachs == NULL)
1399 {
1400 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001401 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001402 }
paul1eb8ef22005-04-07 07:30:20 +00001403 for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode, ipnnode,
1404 ipv6))
hassof390d2c2004-09-10 20:48:21 +00001405 {
hassof390d2c2004-09-10 20:48:21 +00001406 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001407 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hassof390d2c2004-09-10 20:48:21 +00001408 ip6reach->metric =
1409 htonl (circuit->metrics[level - 1].metric_default);
1410 ip6reach->control_info = 0;
1411 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001412 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1413 apply_mask_ipv6 (ip6prefix);
1414 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1415 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001416 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1417 }
1418 }
1419#endif /* HAVE_IPV6 */
1420
1421 switch (circuit->circ_type)
1422 {
1423 case CIRCUIT_T_BROADCAST:
1424 if (level & circuit->circuit_is_type)
1425 {
1426 if (tlv_data.is_neighs == NULL)
1427 {
1428 tlv_data.is_neighs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001429 tlv_data.is_neighs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001430 }
hassoaac372f2005-09-01 17:52:33 +00001431 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001432 if (level == 1)
1433 memcpy (is_neigh->neigh_id,
1434 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1435 else
1436 memcpy (is_neigh->neigh_id,
1437 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1438 is_neigh->metrics = circuit->metrics[level - 1];
1439 listnode_add (tlv_data.is_neighs, is_neigh);
1440 }
1441 break;
1442 case CIRCUIT_T_P2P:
1443 nei = circuit->u.p2p.neighbor;
1444 if (nei && (level & nei->circuit_t))
1445 {
1446 if (tlv_data.is_neighs == NULL)
1447 {
1448 tlv_data.is_neighs = list_new ();
1449 tlv_data.is_neighs->del = free_tlv;
1450 }
hassoaac372f2005-09-01 17:52:33 +00001451 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof390d2c2004-09-10 20:48:21 +00001452 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1453 is_neigh->metrics = circuit->metrics[level - 1];
1454 listnode_add (tlv_data.is_neighs, is_neigh);
1455 }
1456 break;
1457 case CIRCUIT_T_STATIC_IN:
1458 zlog_warn ("lsp_area_create: unsupported circuit type");
1459 break;
1460 case CIRCUIT_T_STATIC_OUT:
1461 zlog_warn ("lsp_area_create: unsupported circuit type");
1462 break;
1463 case CIRCUIT_T_DA:
1464 zlog_warn ("lsp_area_create: unsupported circuit type");
1465 break;
1466 default:
1467 zlog_warn ("lsp_area_create: unknown circuit type");
1468 }
1469 }
1470
1471 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1472 {
1473 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1474 lsp->tlv_data.ipv4_int_reachs = list_new ();
1475 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1476 &lsp->tlv_data.ipv4_int_reachs,
1477 IPV4_REACH_LEN, area->lsp_frag_threshold,
1478 tlv_add_ipv4_reachs);
1479 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1480 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1481 lsp0, area, level);
1482 }
1483
1484#ifdef HAVE_IPV6
1485 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1486 {
1487 if (lsp->tlv_data.ipv6_reachs == NULL)
1488 lsp->tlv_data.ipv6_reachs = list_new ();
1489 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1490 &lsp->tlv_data.ipv6_reachs,
1491 IPV6_REACH_LEN, area->lsp_frag_threshold,
1492 tlv_add_ipv6_reachs);
1493 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1494 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1495 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001496 }
1497#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001498
1499 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1500 {
1501 if (lsp->tlv_data.is_neighs == NULL)
1502 lsp->tlv_data.is_neighs = list_new ();
1503 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1504 &lsp->tlv_data.is_neighs,
1505 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1506 tlv_add_is_neighs);
1507 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1508 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1509 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001510 }
jardineb5d44e2003-12-23 08:09:43 +00001511
jardineb5d44e2003-12-23 08:09:43 +00001512 return;
1513}
1514#endif
1515
hasso92365882005-01-18 13:53:33 +00001516#if 0 /* Old code? */
1517static void
jardineb5d44e2003-12-23 08:09:43 +00001518build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1519{
1520 struct list *circuit_list = area->circuit_list;
1521 struct isis_circuit *circuit;
1522 u_char *tlv_ptr;
1523 struct is_neigh *is_neigh;
1524
hassof390d2c2004-09-10 20:48:21 +00001525
jardineb5d44e2003-12-23 08:09:43 +00001526 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001527 /* the 2 is for the TL plus 1 for the nlpid */
1528 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1529 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1530 *(tlv_ptr + 1) = 1; /* one protocol */
1531#ifdef HAVE_IPV6 /*dunno if its right */
1532 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001533#else
hassof390d2c2004-09-10 20:48:21 +00001534 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001535#endif /* HAVE_IPV6 */
1536
1537 /* we should add our areas here
1538 * FIXME: we need to figure out which should be added? Adj? All? First? */
1539
1540 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001541 /* the 2 is for the TL plus 1 for the virtual field */
1542 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1543 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1544 *(tlv_ptr + 2) = 0; /* virtual is zero */
1545 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001546 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001547 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1548 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001549 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001550 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001551 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001552 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001553 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001554 circuit = (struct isis_circuit *) listhead (circuit_list);
1555 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001556 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001557 *(tlv_ptr + 1) =
1558 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001559
1560 /* FIXME: scan for adjencecies and add them */
1561
1562 /* FIXME: add reachability info */
1563
hassof390d2c2004-09-10 20:48:21 +00001564 /* adding dynamic hostname if needed */
1565 if (area->dynhostname)
1566 {
1567 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1568 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1569 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1570 lsp->tlv_data.hostname = (struct hostname *)
1571 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1572 /* the -1 is to fit the length in the struct */
1573 strlen (unix_hostname ())) - 1);
1574 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1575 strlen (unix_hostname ()));
1576 }
jardineb5d44e2003-12-23 08:09:43 +00001577
1578}
hasso92365882005-01-18 13:53:33 +00001579#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +00001580
1581/*
1582 * 7.3.7 Generation on non-pseudonode LSPs
1583 */
hasso92365882005-01-18 13:53:33 +00001584static int
hassof390d2c2004-09-10 20:48:21 +00001585lsp_generate_non_pseudo (struct isis_area *area, int level)
1586{
jardineb5d44e2003-12-23 08:09:43 +00001587 struct isis_lsp *oldlsp, *newlsp;
1588 u_int32_t seq_num = 0;
1589 u_char lspid[ISIS_SYS_ID_LEN + 2];
1590
1591 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1592 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1593
1594 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001595 if ((area->is_type & level) == level)
1596 {
1597 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1598 if (oldlsp)
1599 {
1600 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1601 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1602 area->lspdb[level - 1]);
1603 /* FIXME: we should actually initiate a purge */
1604 }
1605 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1606 area->is_type, 0, level);
1607 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001608
hassof390d2c2004-09-10 20:48:21 +00001609 lsp_insert (newlsp, area->lspdb[level - 1]);
1610 /* build_lsp_data (newlsp, area); */
1611 lsp_build_nonpseudo (newlsp, area);
1612 /* time to calculate our checksum */
1613 lsp_seqnum_update (newlsp);
1614 }
jardineb5d44e2003-12-23 08:09:43 +00001615
1616 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001617 if (isis->debugs & DEBUG_ADJ_PACKETS)
1618 {
1619 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001620 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001621 }
jardineb5d44e2003-12-23 08:09:43 +00001622
1623 return ISIS_OK;
1624}
1625
1626/*
1627 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1628 */
1629int
1630lsp_l1_generate (struct isis_area *area)
1631{
hassof390d2c2004-09-10 20:48:21 +00001632 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1633 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001634
1635 return lsp_generate_non_pseudo (area, 1);
1636}
1637
jardineb5d44e2003-12-23 08:09:43 +00001638/*
1639 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1640 */
1641int
1642lsp_l2_generate (struct isis_area *area)
1643{
hassof390d2c2004-09-10 20:48:21 +00001644 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1645 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001646
1647 return lsp_generate_non_pseudo (area, 2);
1648}
1649
hasso92365882005-01-18 13:53:33 +00001650static int
jardineb5d44e2003-12-23 08:09:43 +00001651lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1652{
1653 dict_t *lspdb = area->lspdb[level - 1];
1654 struct isis_lsp *lsp, *frag;
1655 struct listnode *node;
1656 u_char lspid[ISIS_SYS_ID_LEN + 2];
1657
1658 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1659 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001660
jardineb5d44e2003-12-23 08:09:43 +00001661 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001662
hassof390d2c2004-09-10 20:48:21 +00001663 if (!lsp)
1664 {
1665 zlog_err
1666 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1667 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001668
hassof390d2c2004-09-10 20:48:21 +00001669 return ISIS_ERROR;
1670 }
1671
1672 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001673 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001674 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1675 (area->max_lsp_lifetime[level - 1],
1676 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001677 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001678
1679 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1680 {
hasso529d65b2004-12-24 00:14:50 +00001681 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1682 "seq 0x%08x, cksum 0x%04x lifetime %us",
1683 area->area_tag,
1684 level,
1685 rawlspid_print (lsp->lsp_header->lsp_id),
1686 ntohl (lsp->lsp_header->seq_num),
1687 ntohs (lsp->lsp_header->checksum),
1688 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001689 }
jardineb5d44e2003-12-23 08:09:43 +00001690
1691 lsp->last_generated = time (NULL);
1692 area->lsp_regenerate_pending[level - 1] = 0;
1693 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
paul1eb8ef22005-04-07 07:30:20 +00001694 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
hassof390d2c2004-09-10 20:48:21 +00001695 {
hassof390d2c2004-09-10 20:48:21 +00001696 frag->lsp_header->rem_lifetime = htons (isis_jitter
1697 (area->
1698 max_lsp_lifetime[level - 1],
1699 MAX_AGE_JITTER));
1700 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1701 }
jardineb5d44e2003-12-23 08:09:43 +00001702
1703 if (area->ip_circuits)
1704 isis_spf_schedule (area, level);
1705#ifdef HAVE_IPV6
1706 if (area->ipv6_circuits)
1707 isis_spf_schedule6 (area, level);
1708#endif
1709 return ISIS_OK;
1710}
1711
jardineb5d44e2003-12-23 08:09:43 +00001712/*
1713 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1714 * time and set SRM
1715 */
hassof390d2c2004-09-10 20:48:21 +00001716int
jardineb5d44e2003-12-23 08:09:43 +00001717lsp_refresh_l1 (struct thread *thread)
1718{
1719 struct isis_area *area;
1720 unsigned long ref_time;
1721
1722 area = THREAD_ARG (thread);
1723 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001724
jardineb5d44e2003-12-23 08:09:43 +00001725 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001726 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001727 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001728
1729 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001730 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1731
hassof390d2c2004-09-10 20:48:21 +00001732 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1733 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001734
jardineb5d44e2003-12-23 08:09:43 +00001735 return ISIS_OK;
1736}
1737
hassof390d2c2004-09-10 20:48:21 +00001738int
jardineb5d44e2003-12-23 08:09:43 +00001739lsp_refresh_l2 (struct thread *thread)
1740{
1741 struct isis_area *area;
1742 unsigned long ref_time;
1743
1744 area = THREAD_ARG (thread);
1745 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001746
jardineb5d44e2003-12-23 08:09:43 +00001747 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001748 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001749 lsp_non_pseudo_regenerate (area, 2);
1750
hassof390d2c2004-09-10 20:48:21 +00001751 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001752 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1753
hassof390d2c2004-09-10 20:48:21 +00001754 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1755 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001756
jardineb5d44e2003-12-23 08:09:43 +00001757 return ISIS_OK;
1758}
1759
jardineb5d44e2003-12-23 08:09:43 +00001760/*
1761 * Something has changed -> regenerate LSP
1762 */
1763
hasso92365882005-01-18 13:53:33 +00001764static int
jardineb5d44e2003-12-23 08:09:43 +00001765lsp_l1_regenerate (struct thread *thread)
1766{
1767 struct isis_area *area;
1768
1769 area = THREAD_ARG (thread);
1770 area->lsp_regenerate_pending[0] = 0;
1771
1772 return lsp_non_pseudo_regenerate (area, 1);
1773}
1774
hasso92365882005-01-18 13:53:33 +00001775static int
jardineb5d44e2003-12-23 08:09:43 +00001776lsp_l2_regenerate (struct thread *thread)
1777{
1778 struct isis_area *area;
1779
1780 area = THREAD_ARG (thread);
1781 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001782
jardineb5d44e2003-12-23 08:09:43 +00001783 return lsp_non_pseudo_regenerate (area, 2);
1784}
1785
hassof390d2c2004-09-10 20:48:21 +00001786int
jardineb5d44e2003-12-23 08:09:43 +00001787lsp_regenerate_schedule (struct isis_area *area)
1788{
1789 struct isis_lsp *lsp;
1790 u_char id[ISIS_SYS_ID_LEN + 2];
1791 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001792 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1793 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001794 now = time (NULL);
1795 /*
1796 * First level 1
1797 */
hassof390d2c2004-09-10 20:48:21 +00001798 if (area->is_type & IS_LEVEL_1)
1799 {
1800 lsp = lsp_search (id, area->lspdb[0]);
1801 if (!lsp || area->lsp_regenerate_pending[0])
1802 goto L2;
1803 /*
1804 * Throttle avoidance
1805 */
1806 diff = now - lsp->last_generated;
1807 if (diff < MIN_LSP_GEN_INTERVAL)
1808 {
1809 area->lsp_regenerate_pending[0] = 1;
1810 thread_add_timer (master, lsp_l1_regenerate, area,
1811 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001812 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001813 }
1814 else
1815 lsp_non_pseudo_regenerate (area, 1);
1816 }
jardineb5d44e2003-12-23 08:09:43 +00001817 /*
1818 * then 2
1819 */
hassof390d2c2004-09-10 20:48:21 +00001820L2:
1821 if (area->is_type & IS_LEVEL_2)
1822 {
1823 lsp = lsp_search (id, area->lspdb[1]);
1824 if (!lsp || area->lsp_regenerate_pending[1])
1825 return ISIS_OK;
1826 /*
1827 * Throttle avoidance
1828 */
1829 diff = now - lsp->last_generated;
1830 if (diff < MIN_LSP_GEN_INTERVAL)
1831 {
1832 area->lsp_regenerate_pending[1] = 1;
1833 thread_add_timer (master, lsp_l2_regenerate, area,
1834 MIN_LSP_GEN_INTERVAL - diff);
1835 return ISIS_OK;
1836 }
1837 else
1838 lsp_non_pseudo_regenerate (area, 2);
1839 }
1840
1841 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001842}
1843
1844/*
1845 * Funcs for pseudonode LSPs
1846 */
1847
1848/*
1849 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1850 */
hasso92365882005-01-18 13:53:33 +00001851static void
hassof390d2c2004-09-10 20:48:21 +00001852lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1853 int level)
jardineb5d44e2003-12-23 08:09:43 +00001854{
1855 struct isis_adjacency *adj;
1856 struct is_neigh *is_neigh;
1857 struct es_neigh *es_neigh;
1858 struct list *adj_list;
paul1eb8ef22005-04-07 07:30:20 +00001859 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00001860 struct isis_passwd *passwd;
1861
1862 assert (circuit);
1863 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001864
jardineb5d44e2003-12-23 08:09:43 +00001865 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001866 return; /* we are not DIS on this circuit */
1867
jardineb5d44e2003-12-23 08:09:43 +00001868 lsp->level = level;
1869 if (level == 1)
1870 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1871 else
1872 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1873
1874 /*
1875 * add self to IS neighbours
1876 */
hassof390d2c2004-09-10 20:48:21 +00001877 if (lsp->tlv_data.is_neighs == NULL)
1878 {
1879 lsp->tlv_data.is_neighs = list_new ();
1880 lsp->tlv_data.is_neighs->del = free_tlv;
1881 }
paul15935e92005-05-03 09:27:23 +00001882 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1883
jardineb5d44e2003-12-23 08:09:43 +00001884 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1885 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001886
1887 adj_list = list_new ();
1888 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1889
paul1eb8ef22005-04-07 07:30:20 +00001890 for (ALL_LIST_ELEMENTS (adj_list, node, nnode, adj))
hassof390d2c2004-09-10 20:48:21 +00001891 {
hassof390d2c2004-09-10 20:48:21 +00001892 if (adj->circuit_t & level)
1893 {
1894 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1895 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1896 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1897 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1898 {
1899 /* an IS neighbour -> add it */
paul15935e92005-05-03 09:27:23 +00001900 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1901
hassof390d2c2004-09-10 20:48:21 +00001902 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1903 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1904 }
1905 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1906 {
1907 /* an ES neigbour add it, if we are building level 1 LSP */
1908 /* FIXME: the tlv-format is hard to use here */
1909 if (lsp->tlv_data.es_neighs == NULL)
1910 {
1911 lsp->tlv_data.es_neighs = list_new ();
1912 lsp->tlv_data.es_neighs->del = free_tlv;
1913 }
paul15935e92005-05-03 09:27:23 +00001914 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1915
hassof390d2c2004-09-10 20:48:21 +00001916 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001917 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001918 }
1919 }
jardineb5d44e2003-12-23 08:09:43 +00001920 }
hassof390d2c2004-09-10 20:48:21 +00001921
hassoc0fb2a52005-09-03 16:29:40 +00001922 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001923 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001924 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1925
jardineb5d44e2003-12-23 08:09:43 +00001926 /*
1927 * Add the authentication info if it's present
1928 */
hassof390d2c2004-09-10 20:48:21 +00001929 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1930 (passwd = &circuit->area->domain_passwd);
1931 if (passwd->type)
1932 {
1933 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1934 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1935 }
jardineb5d44e2003-12-23 08:09:43 +00001936
1937 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1938 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1939
1940 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1941 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1942
paul9985f832005-02-09 15:51:56 +00001943 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001944 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1945 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1946
jardineb5d44e2003-12-23 08:09:43 +00001947 list_delete (adj_list);
1948
1949 return;
1950}
1951
hasso92365882005-01-18 13:53:33 +00001952static int
jardineb5d44e2003-12-23 08:09:43 +00001953lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1954{
1955 dict_t *lspdb = circuit->area->lspdb[level - 1];
1956 struct isis_lsp *lsp;
1957 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001958
jardineb5d44e2003-12-23 08:09:43 +00001959 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001960 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1961 LSP_FRAGMENT (lsp_id) = 0;
1962
jardineb5d44e2003-12-23 08:09:43 +00001963 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001964
1965 if (!lsp)
1966 {
1967 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1968 rawlspid_print (lsp_id));
1969 return ISIS_ERROR;
1970 }
1971 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001972
1973 lsp_build_pseudo (lsp, circuit, level);
1974
hassof390d2c2004-09-10 20:48:21 +00001975 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001976 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001977 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001978
1979 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001980
1981 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1982 {
hasso529d65b2004-12-24 00:14:50 +00001983 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1984 circuit->area->area_tag, level,
1985 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001986 }
jardineb5d44e2003-12-23 08:09:43 +00001987
1988 lsp->last_generated = time (NULL);
1989 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001990
jardineb5d44e2003-12-23 08:09:43 +00001991 return ISIS_OK;
1992}
1993
jardineb5d44e2003-12-23 08:09:43 +00001994int
1995lsp_l1_refresh_pseudo (struct thread *thread)
1996{
1997 struct isis_circuit *circuit;
1998 int retval;
1999 unsigned long ref_time;
2000
hassof390d2c2004-09-10 20:48:21 +00002001 circuit = THREAD_ARG (thread);
2002
jardineb5d44e2003-12-23 08:09:43 +00002003 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002004 return ISIS_ERROR; /* FIXME: purge and such */
2005
hasso13c48f72004-09-10 21:19:13 +00002006 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2007
jardineb5d44e2003-12-23 08:09:43 +00002008 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002009
2010 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002011 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2012
hassof390d2c2004-09-10 20:48:21 +00002013 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2014 lsp_l1_refresh_pseudo, circuit,
2015 isis_jitter (ref_time, MAX_AGE_JITTER));
2016
jardineb5d44e2003-12-23 08:09:43 +00002017 return retval;
2018}
2019
hassof390d2c2004-09-10 20:48:21 +00002020int
jardineb5d44e2003-12-23 08:09:43 +00002021lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2022{
2023 struct isis_lsp *lsp;
2024 u_char id[ISIS_SYS_ID_LEN + 2];
2025 unsigned long ref_time;
2026
hassof390d2c2004-09-10 20:48:21 +00002027 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2028 LSP_FRAGMENT (id) = 0;
2029 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002030
2031 /*
2032 * If for some reason have a pseudo LSP in the db already -> regenerate
2033 */
2034 if (lsp_search (id, circuit->area->lspdb[0]))
2035 return lsp_pseudo_regenerate (circuit, 1);
2036 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002037 1, circuit->area->is_type, 0, 1);
2038
jardineb5d44e2003-12-23 08:09:43 +00002039 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002040
jardineb5d44e2003-12-23 08:09:43 +00002041 lsp->own_lsp = 1;
2042 lsp_insert (lsp, circuit->area->lspdb[0]);
2043 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2044
hassof390d2c2004-09-10 20:48:21 +00002045 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002046 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2047
hassof390d2c2004-09-10 20:48:21 +00002048 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2049 lsp_l1_refresh_pseudo, circuit,
2050 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002051
2052 return lsp_regenerate_schedule (circuit->area);
2053}
2054
2055int
2056lsp_l2_refresh_pseudo (struct thread *thread)
2057{
2058 struct isis_circuit *circuit;
2059 int retval;
2060 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002061 circuit = THREAD_ARG (thread);
2062
jardineb5d44e2003-12-23 08:09:43 +00002063 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002064 return ISIS_ERROR; /* FIXME: purge and such */
2065
hasso13c48f72004-09-10 21:19:13 +00002066 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2067
jardineb5d44e2003-12-23 08:09:43 +00002068 retval = lsp_pseudo_regenerate (circuit, 2);
2069
hassof390d2c2004-09-10 20:48:21 +00002070 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002071 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2072
hassof390d2c2004-09-10 20:48:21 +00002073 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2074 lsp_l2_refresh_pseudo, circuit,
2075 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002076
jardineb5d44e2003-12-23 08:09:43 +00002077 return retval;
2078}
2079
hassof390d2c2004-09-10 20:48:21 +00002080int
jardineb5d44e2003-12-23 08:09:43 +00002081lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2082{
2083 struct isis_lsp *lsp;
2084 u_char id[ISIS_SYS_ID_LEN + 2];
2085 unsigned long ref_time;
2086
hassof390d2c2004-09-10 20:48:21 +00002087 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2088 LSP_FRAGMENT (id) = 0;
2089 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002090
2091 if (lsp_search (id, circuit->area->lspdb[1]))
2092 return lsp_pseudo_regenerate (circuit, 2);
2093
2094 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002095 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002096
2097 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002098
2099 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002100 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2101
2102
2103 lsp->own_lsp = 1;
2104 lsp_insert (lsp, circuit->area->lspdb[1]);
2105 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002106
2107 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2108 lsp_l2_refresh_pseudo, circuit,
2109 isis_jitter (ref_time, MAX_AGE_JITTER));
2110
jardineb5d44e2003-12-23 08:09:43 +00002111 return lsp_regenerate_schedule (circuit->area);
2112}
2113
jardineb5d44e2003-12-23 08:09:43 +00002114/*
2115 * Walk through LSPs for an area
2116 * - set remaining lifetime
2117 * - set LSPs with SRMflag set for sending
2118 */
hassof390d2c2004-09-10 20:48:21 +00002119int
jardineb5d44e2003-12-23 08:09:43 +00002120lsp_tick (struct thread *thread)
2121{
2122 struct isis_area *area;
2123 struct isis_circuit *circuit;
2124 struct isis_lsp *lsp;
2125 struct list *lsp_list;
paul1eb8ef22005-04-07 07:30:20 +00002126 struct listnode *lspnode, *lspnnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002127 dnode_t *dnode, *dnode_next;
2128 int level;
2129
2130 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002131
jardineb5d44e2003-12-23 08:09:43 +00002132 area = THREAD_ARG (thread);
2133 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002134 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002135 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002136
2137 /*
2138 * Build a list of LSPs with (any) SRMflag set
2139 * and removed the ones that have aged out
2140 */
hassof390d2c2004-09-10 20:48:21 +00002141 for (level = 0; level < ISIS_LEVELS; level++)
2142 {
2143 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2144 {
2145 dnode = dict_first (area->lspdb[level]);
2146 while (dnode != NULL)
2147 {
2148 dnode_next = dict_next (area->lspdb[level], dnode);
2149 lsp = dnode_get (dnode);
2150 lsp_set_time (lsp);
2151 if (lsp->age_out == 0)
2152 {
jardineb5d44e2003-12-23 08:09:43 +00002153
hasso529d65b2004-12-24 00:14:50 +00002154 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2155 area->area_tag,
2156 lsp->level,
2157 rawlspid_print (lsp->lsp_header->lsp_id),
2158 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002159
hassof390d2c2004-09-10 20:48:21 +00002160 lsp_destroy (lsp);
2161 dict_delete (area->lspdb[level], dnode);
2162 }
2163 else if (flags_any_set (lsp->SRMflags))
2164 listnode_add (lsp_list, lsp);
2165 dnode = dnode_next;
2166 }
jardineb5d44e2003-12-23 08:09:43 +00002167
hassof390d2c2004-09-10 20:48:21 +00002168 /*
2169 * Send LSPs on circuits indicated by the SRMflags
2170 */
2171 if (listcount (lsp_list) > 0)
2172 {
paul1eb8ef22005-04-07 07:30:20 +00002173 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00002174 {
paul1eb8ef22005-04-07 07:30:20 +00002175 for (ALL_LIST_ELEMENTS (lsp_list, lspnode, lspnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002176 {
hassof390d2c2004-09-10 20:48:21 +00002177 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2178 {
2179 /* FIXME: if same or elder lsp is already in lsp
2180 * queue */
2181 listnode_add (circuit->lsp_queue, lsp);
2182 thread_add_event (master, send_lsp, circuit, 0);
2183 }
2184 }
2185 }
2186 }
2187 list_delete_all_node (lsp_list);
2188 }
jardineb5d44e2003-12-23 08:09:43 +00002189 }
jardineb5d44e2003-12-23 08:09:43 +00002190
2191 list_delete (lsp_list);
2192
2193 return ISIS_OK;
2194}
2195
jardineb5d44e2003-12-23 08:09:43 +00002196void
hassof390d2c2004-09-10 20:48:21 +00002197lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002198{
2199 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002200
jardineb5d44e2003-12-23 08:09:43 +00002201 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002202
2203 if (lsp && lsp->purged == 0)
2204 {
2205 lsp->lsp_header->rem_lifetime = htons (0);
2206 lsp->lsp_header->pdu_len =
2207 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2208 lsp->purged = 0;
2209 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2210 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2211 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2212 }
2213
jardineb5d44e2003-12-23 08:09:43 +00002214 return;
2215}
2216
2217/*
2218 * Purge own LSP that is received and we don't have.
2219 * -> Do as in 7.3.16.4
2220 */
2221void
hassof390d2c2004-09-10 20:48:21 +00002222lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2223 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002224{
2225 struct isis_lsp *lsp;
2226
2227 /*
2228 * We need to create the LSP to be purged
2229 */
hasso529d65b2004-12-24 00:14:50 +00002230 zlog_debug ("LSP PURGE NON EXIST");
hassoaac372f2005-09-01 17:52:33 +00002231 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002232 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2233 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002234 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2235 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002236 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002237 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002238 : L2_LINK_STATE);
2239 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2240 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002241 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002242
jardineb5d44e2003-12-23 08:09:43 +00002243 /*
2244 * Retain only LSP header
2245 */
2246 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2247 /*
2248 * Set the remaining lifetime to 0
2249 */
2250 lsp->lsp_header->rem_lifetime = 0;
2251 /*
2252 * Put the lsp into LSPdb
2253 */
hassof390d2c2004-09-10 20:48:21 +00002254 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002255
2256 /*
2257 * Send in to whole area
2258 */
2259 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002260
jardineb5d44e2003-12-23 08:09:43 +00002261 return;
2262}
2263
2264#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002265static int
jardineb5d44e2003-12-23 08:09:43 +00002266top_lsp_refresh (struct thread *thread)
2267{
hassof390d2c2004-09-10 20:48:21 +00002268 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002269
2270 lsp = THREAD_ARG (thread);
2271 assert (lsp);
2272
2273 lsp->t_lsp_top_ref = NULL;
2274
hassof390d2c2004-09-10 20:48:21 +00002275 lsp->lsp_header->rem_lifetime =
2276 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2277 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002278
2279 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002280 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2281 {
hasso529d65b2004-12-24 00:14:50 +00002282 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2283 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002284 }
jardineb5d44e2003-12-23 08:09:43 +00002285
2286 /* time to calculate our checksum */
2287 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002288 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2289 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2290 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002291
2292 return ISIS_OK;
2293}
2294
2295void
2296generate_topology_lsps (struct isis_area *area)
2297{
2298 struct listnode *node;
2299 int i, max = 0;
2300 struct arc *arc;
2301 u_char lspid[ISIS_SYS_ID_LEN + 2];
2302 struct isis_lsp *lsp;
2303
2304 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002305 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002306 {
2307 if (arc->from_node > max)
2308 max = arc->from_node;
2309 if (arc->to_node > max)
2310 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002311 }
2312
hassof390d2c2004-09-10 20:48:21 +00002313 for (i = 1; i < (max + 1); i++)
2314 {
2315 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2316 LSP_PSEUDO_ID (lspid) = 0x00;
2317 LSP_FRAGMENT (lspid) = 0x00;
2318 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2319 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002320
hassof390d2c2004-09-10 20:48:21 +00002321 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2322 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2323 1);
2324 lsp->from_topology = 1;
2325 /* creating data based on topology */
2326 build_topology_lsp_data (lsp, area, i);
2327 /* time to calculate our checksum */
2328 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2329 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2330 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2331 isis_jitter (MAX_LSP_GEN_INTERVAL,
2332 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002333
hassof390d2c2004-09-10 20:48:21 +00002334 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2335 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002336
hassof390d2c2004-09-10 20:48:21 +00002337 }
jardineb5d44e2003-12-23 08:09:43 +00002338}
2339
2340void
2341remove_topology_lsps (struct isis_area *area)
2342{
2343 struct isis_lsp *lsp;
2344 dnode_t *dnode, *dnode_next;
2345
2346 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002347 while (dnode != NULL)
2348 {
2349 dnode_next = dict_next (area->lspdb[0], dnode);
2350 lsp = dnode_get (dnode);
2351 if (lsp->from_topology)
2352 {
2353 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2354 lsp_destroy (lsp);
2355 dict_delete (area->lspdb[0], dnode);
2356 }
2357 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002358 }
jardineb5d44e2003-12-23 08:09:43 +00002359}
2360
2361void
hassof390d2c2004-09-10 20:48:21 +00002362build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002363 int lsp_top_num)
2364{
paula8f03df2005-04-10 15:58:10 +00002365 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00002366 struct arc *arc;
2367 u_char *tlv_ptr;
2368 struct is_neigh *is_neigh;
2369 int to_lsp = 0;
2370 char buff[200];
2371
2372 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002373 /* the 2 is for the TL plus 1 for the nlpid */
2374 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2375 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2376 *(tlv_ptr + 1) = 1; /* one protocol */
2377 *(tlv_ptr + 2) = NLPID_IP;
2378 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002379
2380 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002381 /* the 2 is for the TL plus 1 for the virtual field */
2382 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2383 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2384 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2385 *(tlv_ptr + 2) = 0; /* virtual is zero */
2386 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002387
2388 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002389 if (lsp_top_num == 1)
2390 {
jardineb5d44e2003-12-23 08:09:43 +00002391 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002392 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2393 sizeof (struct
2394 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002395 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002396 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2397 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002398 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002399 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002400 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2401 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2402 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2403 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002404 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2405 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002406 }
hassof390d2c2004-09-10 20:48:21 +00002407
2408 /* addding is reachabilities */
paula8f03df2005-04-10 15:58:10 +00002409 for (ALL_LIST_ELEMENTS (area->topology, node, nnode, arc))
hassof390d2c2004-09-10 20:48:21 +00002410 {
2411 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2412 {
2413 if (arc->to_node == lsp_top_num)
2414 to_lsp = arc->from_node;
2415 if (arc->from_node == lsp_top_num)
2416 to_lsp = arc->to_node;
2417
2418 /* if the length here is about to cross the FF limit, we reTLV */
2419 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2420 {
2421 /* retlv */
2422 /* the 2 is for the TL plus 1 for the virtual field */
2423 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2424 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2425 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2426 *(tlv_ptr + 2) = 0; /* virtual is zero */
2427 }
2428 /* doing this here assures us that we won't add an "empty" tlv */
2429 /* assign space for the is_neigh at the pdu end */
2430 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2431 sizeof (struct
2432 is_neigh));
2433 /* add this node to our list */
2434 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2435 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2436 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2437 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2438 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2439 is_neigh->metrics.metric_default = arc->distance;
2440 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2441 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2442 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2443 /* don't forget the length */
2444 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2445 }
jardineb5d44e2003-12-23 08:09:43 +00002446 }
2447
hassof390d2c2004-09-10 20:48:21 +00002448 /* adding dynamic hostname if needed */
2449 if (area->dynhostname)
2450 {
2451 memset (buff, 0x00, 200);
2452 sprintf (buff, "feedme%d", lsp_top_num);
2453 /* the 2 is for the TL */
2454 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2455 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2456 *(tlv_ptr + 1) = strlen (buff); /* Length */
2457 /* the -1 is to fit the length in the struct */
2458 lsp->tlv_data.hostname = (struct hostname *)
2459 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2460 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2461 }
jardineb5d44e2003-12-23 08:09:43 +00002462}
2463#endif /* TOPOLOGY_GENERATE */