]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
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 | */ | |
23 | #include <stdlib.h> | |
24 | #include <stdio.h> | |
25 | #include <zebra.h> | |
eb5d44eb | 26 | |
27 | #include "linklist.h" | |
28 | #include "thread.h" | |
29 | #include "vty.h" | |
30 | #include "stream.h" | |
31 | #include "memory.h" | |
32 | #include "log.h" | |
33 | #include "prefix.h" | |
34 | #include "command.h" | |
35 | #include "hash.h" | |
36 | #include "if.h" | |
37 | ||
38 | #include "isisd/dict.h" | |
39 | #include "isisd/isis_constants.h" | |
40 | #include "isisd/isis_common.h" | |
41 | #include "isisd/isis_circuit.h" | |
42 | #include "isisd/isisd.h" | |
43 | #include "isisd/isis_tlv.h" | |
44 | #include "isisd/isis_lsp.h" | |
45 | #include "isisd/isis_pdu.h" | |
46 | #include "isisd/isis_dynhn.h" | |
47 | #include "isisd/isis_misc.h" | |
48 | #include "isisd/isis_flags.h" | |
49 | #include "isisd/iso_checksum.h" | |
50 | #include "isisd/isis_csm.h" | |
51 | #include "isisd/isis_adjacency.h" | |
52 | #include "isisd/isis_spf.h" | |
53 | ||
54 | #ifdef TOPOLOGY_GENERATE | |
55 | #include "spgrid.h" | |
56 | #endif | |
57 | ||
f390d2c7 | 58 | #define LSP_MEMORY_PREASSIGN |
eb5d44eb | 59 | |
60 | extern struct isis *isis; | |
61 | extern struct thread_master *master; | |
eb5d44eb | 62 | |
73d1aead | 63 | /* staticly assigned vars for printing purposes */ |
64 | char lsp_bits_string[200]; /* FIXME: enough ? */ | |
65 | ||
f390d2c7 | 66 | int |
67 | lsp_id_cmp (u_char * id1, u_char * id2) | |
68 | { | |
eb5d44eb | 69 | return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2); |
70 | } | |
71 | ||
72 | dict_t * | |
f390d2c7 | 73 | lsp_db_init (void) |
eb5d44eb | 74 | { |
75 | dict_t *dict; | |
f390d2c7 | 76 | |
77 | dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp); | |
78 | ||
eb5d44eb | 79 | return dict; |
80 | } | |
81 | ||
82 | struct isis_lsp * | |
f390d2c7 | 83 | lsp_search (u_char * id, dict_t * lspdb) |
eb5d44eb | 84 | { |
85 | dnode_t *node; | |
86 | ||
f390d2c7 | 87 | #ifdef EXTREME_DEBUG |
eb5d44eb | 88 | dnode_t *dn; |
89 | ||
f390d2c7 | 90 | zlog_warn ("searching db"); |
91 | for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn)) | |
92 | { | |
93 | zlog_warn ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)), | |
94 | dnode_get (dn)); | |
95 | } | |
eb5d44eb | 96 | #endif /* EXTREME DEBUG */ |
97 | ||
98 | node = dict_lookup (lspdb, id); | |
f390d2c7 | 99 | |
eb5d44eb | 100 | if (node) |
f390d2c7 | 101 | return (struct isis_lsp *) dnode_get (node); |
eb5d44eb | 102 | |
103 | return NULL; | |
104 | } | |
105 | ||
106 | void | |
107 | lsp_clear_data (struct isis_lsp *lsp) | |
108 | { | |
109 | if (!lsp) | |
110 | return; | |
f390d2c7 | 111 | |
112 | if (lsp->own_lsp) | |
113 | { | |
114 | if (lsp->tlv_data.nlpids) | |
115 | XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids); | |
116 | if (lsp->tlv_data.hostname) | |
117 | XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname); | |
118 | } | |
eb5d44eb | 119 | if (lsp->tlv_data.is_neighs) |
120 | list_delete (lsp->tlv_data.is_neighs); | |
121 | if (lsp->tlv_data.area_addrs) | |
122 | list_delete (lsp->tlv_data.area_addrs); | |
123 | if (lsp->tlv_data.es_neighs) | |
124 | list_delete (lsp->tlv_data.es_neighs); | |
125 | if (lsp->tlv_data.ipv4_addrs) | |
126 | list_delete (lsp->tlv_data.ipv4_addrs); | |
127 | if (lsp->tlv_data.ipv4_int_reachs) | |
128 | list_delete (lsp->tlv_data.ipv4_int_reachs); | |
129 | if (lsp->tlv_data.ipv4_ext_reachs) | |
130 | list_delete (lsp->tlv_data.ipv4_ext_reachs); | |
131 | #ifdef HAVE_IPV6 | |
132 | if (lsp->tlv_data.ipv6_addrs) | |
133 | list_delete (lsp->tlv_data.ipv6_addrs); | |
134 | if (lsp->tlv_data.ipv6_reachs) | |
135 | list_delete (lsp->tlv_data.ipv6_reachs); | |
136 | #endif /* HAVE_IPV6 */ | |
137 | ||
138 | memset (&lsp->tlv_data, 0, sizeof (struct tlvs)); | |
139 | ||
140 | return; | |
141 | } | |
142 | ||
143 | void | |
144 | lsp_destroy (struct isis_lsp *lsp) | |
145 | { | |
146 | if (!lsp) | |
147 | return; | |
f390d2c7 | 148 | |
eb5d44eb | 149 | lsp_clear_data (lsp); |
f390d2c7 | 150 | |
151 | if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags) | |
152 | { | |
eb5d44eb | 153 | list_delete (lsp->lspu.frags); |
f390d2c7 | 154 | } |
155 | ||
eb5d44eb | 156 | if (lsp->pdu) |
157 | stream_free (lsp->pdu); | |
158 | XFREE (MTYPE_ISIS_LSP, lsp); | |
159 | } | |
160 | ||
f390d2c7 | 161 | void |
162 | lsp_db_destroy (dict_t * lspdb) | |
eb5d44eb | 163 | { |
164 | dnode_t *dnode, *next; | |
165 | struct isis_lsp *lsp; | |
f390d2c7 | 166 | |
eb5d44eb | 167 | dnode = dict_first (lspdb); |
f390d2c7 | 168 | while (dnode) |
169 | { | |
170 | next = dict_next (lspdb, dnode); | |
171 | lsp = dnode_get (dnode); | |
172 | lsp_destroy (lsp); | |
173 | dict_delete_free (lspdb, dnode); | |
174 | dnode = next; | |
175 | } | |
176 | ||
eb5d44eb | 177 | dict_free (lspdb); |
f390d2c7 | 178 | |
eb5d44eb | 179 | return; |
180 | } | |
181 | ||
182 | /* | |
183 | * Remove all the frags belonging to the given lsp | |
184 | */ | |
185 | void | |
f390d2c7 | 186 | lsp_remove_frags (struct list *frags, dict_t * lspdb) |
eb5d44eb | 187 | { |
188 | dnode_t *dnode; | |
189 | struct listnode *lnode; | |
190 | struct isis_lsp *lsp; | |
191 | ||
f390d2c7 | 192 | for (lnode = listhead (frags); lnode; nextnode (lnode)) |
193 | { | |
194 | lsp = getdata (lnode); | |
195 | dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id); | |
196 | lsp_destroy (lsp); | |
197 | dnode_destroy (dict_delete (lspdb, dnode)); | |
198 | } | |
199 | ||
eb5d44eb | 200 | list_delete_all_node (frags); |
f390d2c7 | 201 | |
eb5d44eb | 202 | return; |
203 | } | |
204 | ||
205 | void | |
f390d2c7 | 206 | lsp_search_and_destroy (u_char * id, dict_t * lspdb) |
eb5d44eb | 207 | { |
208 | dnode_t *node; | |
209 | struct isis_lsp *lsp; | |
210 | ||
211 | node = dict_lookup (lspdb, id); | |
f390d2c7 | 212 | if (node) |
213 | { | |
214 | node = dict_delete (lspdb, node); | |
215 | lsp = dnode_get (node); | |
216 | /* | |
217 | * If this is a zero lsp, remove all the frags now | |
218 | */ | |
219 | if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0) | |
220 | { | |
221 | if (lsp->lspu.frags) | |
222 | lsp_remove_frags (lsp->lspu.frags, lspdb); | |
223 | } | |
224 | else | |
225 | { | |
226 | /* | |
227 | * else just remove this frag, from the zero lsps' frag list | |
228 | */ | |
229 | if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags) | |
230 | listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp); | |
231 | } | |
232 | lsp_destroy (lsp); | |
233 | dnode_destroy (node); | |
234 | } | |
eb5d44eb | 235 | } |
236 | ||
237 | /* | |
238 | * Compares a LSP to given values | |
239 | * Params are given in net order | |
240 | */ | |
f390d2c7 | 241 | int |
242 | lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num, | |
eb5d44eb | 243 | u_int16_t checksum, u_int16_t rem_lifetime) |
244 | { | |
f390d2c7 | 245 | /* no point in double ntohl on seqnum */ |
246 | if (lsp->lsp_header->seq_num == seq_num && | |
eb5d44eb | 247 | lsp->lsp_header->checksum == checksum && |
248 | /*comparing with 0, no need to do ntohl */ | |
249 | ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) || | |
f390d2c7 | 250 | (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0))) |
251 | { | |
252 | if (isis->debugs & DEBUG_SNP_PACKETS) | |
253 | { | |
254 | zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x," | |
255 | " lifetime %us", | |
256 | areatag, | |
257 | rawlspid_print (lsp->lsp_header->lsp_id), | |
258 | ntohl (lsp->lsp_header->seq_num), | |
259 | ntohs (lsp->lsp_header->checksum), | |
260 | ntohs (lsp->lsp_header->rem_lifetime)); | |
261 | zlog_info ("ISIS-Snp (%s): is equal to ours seq 0x%08x," | |
262 | " cksum 0x%04x, lifetime %us", | |
263 | areatag, | |
264 | ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime)); | |
265 | } | |
266 | return LSP_EQUAL; | |
267 | } | |
eb5d44eb | 268 | |
f390d2c7 | 269 | if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num)) |
270 | { | |
271 | if (isis->debugs & DEBUG_SNP_PACKETS) | |
272 | { | |
273 | zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x," | |
274 | " lifetime %us", | |
275 | areatag, | |
276 | rawlspid_print (lsp->lsp_header->lsp_id), | |
277 | ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime)); | |
278 | zlog_info ("ISIS-Snp (%s): is newer than ours seq 0x%08x, " | |
279 | "cksum 0x%04x, lifetime %us", | |
280 | areatag, | |
281 | ntohl (lsp->lsp_header->seq_num), | |
282 | ntohs (lsp->lsp_header->checksum), | |
283 | ntohs (lsp->lsp_header->rem_lifetime)); | |
284 | } | |
285 | return LSP_NEWER; | |
286 | } | |
287 | if (isis->debugs & DEBUG_SNP_PACKETS) | |
288 | { | |
289 | zlog_info | |
290 | ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us", | |
291 | areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num), | |
292 | ntohs (checksum), ntohs (rem_lifetime)); | |
293 | zlog_info ("ISIS-Snp (%s): is older than ours seq 0x%08x," | |
294 | " cksum 0x%04x, lifetime %us", areatag, | |
295 | ntohl (lsp->lsp_header->seq_num), | |
296 | ntohs (lsp->lsp_header->checksum), | |
297 | ntohs (lsp->lsp_header->rem_lifetime)); | |
298 | } | |
eb5d44eb | 299 | |
300 | return LSP_OLDER; | |
301 | } | |
302 | ||
f390d2c7 | 303 | void |
eb5d44eb | 304 | lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num) |
305 | { | |
306 | u_int32_t newseq; | |
f390d2c7 | 307 | |
eb5d44eb | 308 | if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num) |
309 | newseq = ntohl (lsp->lsp_header->seq_num) + 1; | |
310 | else | |
f390d2c7 | 311 | newseq = seq_num++; |
312 | ||
eb5d44eb | 313 | lsp->lsp_header->seq_num = htonl (newseq); |
f390d2c7 | 314 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, |
315 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); | |
eb5d44eb | 316 | |
317 | return; | |
318 | } | |
319 | ||
320 | /* | |
321 | * Genetates checksum for LSP and its frags | |
322 | */ | |
323 | void | |
324 | lsp_seqnum_update (struct isis_lsp *lsp0) | |
325 | { | |
326 | struct isis_lsp *lsp; | |
327 | struct listnode *node; | |
f390d2c7 | 328 | |
eb5d44eb | 329 | lsp_inc_seqnum (lsp0, 0); |
330 | ||
331 | if (!lsp0->lspu.frags) | |
332 | return; | |
333 | ||
f390d2c7 | 334 | for (node = listhead (lsp0->lspu.frags); node; nextnode (node)) |
335 | { | |
336 | lsp = getdata (node); | |
337 | lsp_inc_seqnum (lsp, 0); | |
338 | } | |
339 | ||
eb5d44eb | 340 | return; |
341 | } | |
342 | ||
f390d2c7 | 343 | int |
eb5d44eb | 344 | isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area, |
f390d2c7 | 345 | int pdulen, struct isis_passwd *passwd) |
eb5d44eb | 346 | { |
347 | uint32_t expected = 0, found; | |
348 | struct tlvs tlvs; | |
349 | int retval = 0; | |
350 | ||
351 | expected |= TLVFLAG_AUTH_INFO; | |
352 | retval = parse_tlvs (area->area_tag, stream->data + | |
f390d2c7 | 353 | ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN, |
354 | pdulen - ISIS_FIXED_HDR_LEN | |
355 | - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs); | |
eb5d44eb | 356 | if (retval || !(found & TLVFLAG_AUTH_INFO)) |
f390d2c7 | 357 | return 1; /* Auth fail (parsing failed or no auth-tlv) */ |
eb5d44eb | 358 | |
359 | return authentication_check (passwd, &tlvs.auth_info); | |
360 | } | |
361 | ||
362 | void | |
f390d2c7 | 363 | lsp_update_data (struct isis_lsp *lsp, struct stream *stream, |
364 | struct isis_area *area) | |
eb5d44eb | 365 | { |
f390d2c7 | 366 | uint32_t expected = 0, found; |
eb5d44eb | 367 | int retval; |
f390d2c7 | 368 | |
eb5d44eb | 369 | /* copying only the relevant part of our stream */ |
370 | lsp->pdu = stream_new (stream->endp); | |
371 | lsp->pdu->putp = stream->putp; | |
372 | lsp->pdu->getp = stream->getp; | |
373 | lsp->pdu->endp = stream->endp; | |
374 | memcpy (lsp->pdu->data, stream->data, stream->endp); | |
375 | ||
376 | /* setting pointers to the correct place */ | |
f390d2c7 | 377 | lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu)); |
378 | lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) + | |
379 | ISIS_FIXED_HDR_LEN); | |
eb5d44eb | 380 | lsp->age_out = ZERO_AGE_LIFETIME; |
f390d2c7 | 381 | lsp->installed = time (NULL); |
eb5d44eb | 382 | /* |
383 | * Get LSP data i.e. TLVs | |
384 | */ | |
385 | expected |= TLVFLAG_AUTH_INFO; | |
386 | expected |= TLVFLAG_AREA_ADDRS; | |
387 | expected |= TLVFLAG_IS_NEIGHS; | |
f390d2c7 | 388 | if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */ |
eb5d44eb | 389 | expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS; |
390 | expected |= TLVFLAG_NLPID; | |
391 | if (area->dynhostname) | |
392 | expected |= TLVFLAG_DYN_HOSTNAME; | |
f390d2c7 | 393 | if (area->newmetric) |
394 | { | |
395 | expected |= TLVFLAG_TE_IS_NEIGHS; | |
396 | expected |= TLVFLAG_TE_IPV4_REACHABILITY; | |
397 | expected |= TLVFLAG_TE_ROUTER_ID; | |
398 | } | |
eb5d44eb | 399 | expected |= TLVFLAG_IPV4_ADDR; |
400 | expected |= TLVFLAG_IPV4_INT_REACHABILITY; | |
401 | expected |= TLVFLAG_IPV4_EXT_REACHABILITY; | |
402 | #ifdef HAVE_IPV6 | |
403 | expected |= TLVFLAG_IPV6_ADDR; | |
404 | expected |= TLVFLAG_IPV6_REACHABILITY; | |
405 | #endif /* HAVE_IPV6 */ | |
406 | ||
407 | retval = parse_tlvs (area->area_tag, lsp->pdu->data + | |
f390d2c7 | 408 | ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN, |
409 | ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN | |
410 | - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data); | |
411 | ||
412 | if (found & TLVFLAG_DYN_HOSTNAME) | |
413 | { | |
414 | if (area->dynhostname) | |
415 | isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname, | |
416 | (lsp->lsp_header->lsp_bits & LSPBIT_IST) == | |
417 | IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : | |
418 | (lsp->lsp_header->lsp_bits & LSPBIT_IST)); | |
419 | } | |
eb5d44eb | 420 | |
421 | } | |
422 | ||
423 | void | |
424 | lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr, | |
f390d2c7 | 425 | struct stream *stream, struct isis_area *area) |
eb5d44eb | 426 | { |
f390d2c7 | 427 | /* free the old lsp data */ |
eb5d44eb | 428 | XFREE (MTYPE_STREAM_DATA, lsp->pdu); |
429 | lsp_clear_data (lsp); | |
430 | ||
431 | /* rebuild the lsp data */ | |
432 | lsp_update_data (lsp, stream, area); | |
433 | ||
f390d2c7 | 434 | /* set the new values for lsp header */ |
eb5d44eb | 435 | memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN); |
eb5d44eb | 436 | } |
437 | ||
eb5d44eb | 438 | /* creation of LSP directly from what we received */ |
439 | struct isis_lsp * | |
f390d2c7 | 440 | lsp_new_from_stream_ptr (struct stream *stream, |
441 | u_int16_t pdu_len, struct isis_lsp *lsp0, | |
442 | struct isis_area *area) | |
eb5d44eb | 443 | { |
444 | struct isis_lsp *lsp; | |
445 | ||
446 | lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp)); | |
447 | memset (lsp, 0, sizeof (struct isis_lsp)); | |
f390d2c7 | 448 | |
eb5d44eb | 449 | lsp_update_data (lsp, stream, area); |
f390d2c7 | 450 | |
451 | if (lsp0 == NULL) | |
452 | { | |
453 | /* | |
454 | * zero lsp -> create the list for fragments | |
455 | */ | |
456 | lsp->lspu.frags = list_new (); | |
457 | } | |
458 | else | |
459 | { | |
460 | /* | |
461 | * a fragment -> set the backpointer and add this to zero lsps frag list | |
462 | */ | |
463 | lsp->lspu.zero_lsp = lsp0; | |
464 | listnode_add (lsp0->lspu.frags, lsp); | |
465 | } | |
466 | ||
eb5d44eb | 467 | return lsp; |
468 | } | |
469 | ||
470 | struct isis_lsp * | |
f390d2c7 | 471 | lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num, |
472 | u_int8_t lsp_bits, u_int16_t checksum, int level) | |
eb5d44eb | 473 | { |
474 | struct isis_lsp *lsp; | |
475 | ||
476 | lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp)); | |
f390d2c7 | 477 | if (!lsp) |
478 | { | |
479 | /* FIXME: set lspdbol bit */ | |
480 | zlog_warn ("lsp_new(): out of memory"); | |
481 | return NULL; | |
482 | } | |
eb5d44eb | 483 | memset (lsp, 0, sizeof (struct isis_lsp)); |
484 | #ifdef LSP_MEMORY_PREASSIGN | |
f390d2c7 | 485 | lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */ |
eb5d44eb | 486 | #else |
f390d2c7 | 487 | /* We need to do realloc on TLVs additions */ |
488 | lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); | |
eb5d44eb | 489 | #endif /* LSP_MEMORY_PREASSIGN */ |
490 | if (LSP_FRAGMENT (lsp_id) == 0) | |
491 | lsp->lspu.frags = list_new (); | |
f390d2c7 | 492 | lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu)); |
493 | lsp->lsp_header = (struct isis_link_state_hdr *) | |
494 | (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN); | |
495 | ||
eb5d44eb | 496 | /* at first we fill the FIXED HEADER */ |
f390d2c7 | 497 | (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) : |
498 | fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE); | |
499 | ||
eb5d44eb | 500 | /* now for the LSP HEADER */ |
501 | /* Minimal LSP PDU size */ | |
f390d2c7 | 502 | lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
eb5d44eb | 503 | memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2); |
f390d2c7 | 504 | lsp->lsp_header->checksum = checksum; /* Provided in network order */ |
eb5d44eb | 505 | lsp->lsp_header->seq_num = htonl (seq_num); |
506 | lsp->lsp_header->rem_lifetime = htons (rem_lifetime); | |
507 | lsp->lsp_header->lsp_bits = lsp_bits; | |
508 | lsp->level = level; | |
509 | lsp->age_out = ZERO_AGE_LIFETIME; | |
510 | ||
511 | stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); | |
512 | ||
513 | /* #ifdef EXTREME_DEBUG */ | |
514 | /* logging */ | |
515 | zlog_info ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id), | |
f390d2c7 | 516 | LSP_PSEUDO_ID (lsp->lsp_header->lsp_id), |
517 | LSP_FRAGMENT (lsp->lsp_header->lsp_id), | |
518 | ntohl (lsp->lsp_header->seq_num)); | |
eb5d44eb | 519 | /* #endif EXTREME DEBUG */ |
520 | ||
521 | return lsp; | |
522 | } | |
523 | ||
524 | void | |
f390d2c7 | 525 | lsp_insert (struct isis_lsp *lsp, dict_t * lspdb) |
eb5d44eb | 526 | { |
527 | dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp); | |
528 | } | |
529 | ||
530 | /* | |
531 | * Build a list of LSPs with non-zero ht bounded by start and stop ids | |
532 | */ | |
f390d2c7 | 533 | void |
534 | lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id, | |
535 | struct list *list, dict_t * lspdb) | |
eb5d44eb | 536 | { |
537 | dnode_t *first, *last, *curr; | |
538 | ||
539 | first = dict_lower_bound (lspdb, start_id); | |
540 | if (!first) | |
541 | return; | |
f390d2c7 | 542 | |
eb5d44eb | 543 | last = dict_upper_bound (lspdb, stop_id); |
f390d2c7 | 544 | |
eb5d44eb | 545 | curr = first; |
f390d2c7 | 546 | |
547 | if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime) | |
eb5d44eb | 548 | listnode_add (list, first->dict_data); |
549 | ||
f390d2c7 | 550 | while (curr) |
551 | { | |
552 | curr = dict_next (lspdb, curr); | |
553 | if (curr && | |
554 | ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime) | |
555 | listnode_add (list, curr->dict_data); | |
556 | if (curr == last) | |
557 | break; | |
558 | } | |
559 | ||
eb5d44eb | 560 | return; |
561 | } | |
562 | ||
563 | /* | |
564 | * Build a list of all LSPs bounded by start and stop ids | |
565 | */ | |
f390d2c7 | 566 | void |
567 | lsp_build_list (u_char * start_id, u_char * stop_id, | |
568 | struct list *list, dict_t * lspdb) | |
eb5d44eb | 569 | { |
570 | dnode_t *first, *last, *curr; | |
571 | ||
572 | first = dict_lower_bound (lspdb, start_id); | |
573 | if (!first) | |
574 | return; | |
f390d2c7 | 575 | |
eb5d44eb | 576 | last = dict_upper_bound (lspdb, stop_id); |
f390d2c7 | 577 | |
eb5d44eb | 578 | curr = first; |
f390d2c7 | 579 | |
eb5d44eb | 580 | listnode_add (list, first->dict_data); |
581 | ||
f390d2c7 | 582 | while (curr) |
583 | { | |
584 | curr = dict_next (lspdb, curr); | |
585 | if (curr) | |
586 | listnode_add (list, curr->dict_data); | |
587 | if (curr == last) | |
588 | break; | |
589 | } | |
590 | ||
eb5d44eb | 591 | return; |
592 | } | |
593 | ||
594 | /* | |
595 | * Build a list of LSPs with SSN flag set for the given circuit | |
596 | */ | |
597 | void | |
f390d2c7 | 598 | lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list, |
599 | dict_t * lspdb) | |
eb5d44eb | 600 | { |
601 | dnode_t *dnode, *next; | |
602 | struct isis_lsp *lsp; | |
f390d2c7 | 603 | |
eb5d44eb | 604 | dnode = dict_first (lspdb); |
f390d2c7 | 605 | while (dnode != NULL) |
606 | { | |
607 | next = dict_next (lspdb, dnode); | |
608 | lsp = dnode_get (dnode); | |
609 | if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit)) | |
610 | listnode_add (list, lsp); | |
611 | dnode = next; | |
612 | } | |
613 | ||
eb5d44eb | 614 | return; |
615 | } | |
616 | ||
617 | void | |
618 | lsp_set_time (struct isis_lsp *lsp) | |
619 | { | |
620 | assert (lsp); | |
f390d2c7 | 621 | |
622 | if (lsp->lsp_header->rem_lifetime == 0) | |
623 | { | |
624 | if (lsp->age_out != 0) | |
625 | lsp->age_out--; | |
626 | return; | |
627 | } | |
eb5d44eb | 628 | |
629 | /* If we are turning 0 */ | |
630 | /* ISO 10589 - 7.3.16.4 first paragraph */ | |
631 | ||
f390d2c7 | 632 | if (ntohs (lsp->lsp_header->rem_lifetime) == 1) |
633 | { | |
634 | /* 7.3.16.4 a) set SRM flags on all */ | |
635 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
636 | /* 7.3.16.4 b) retain only the header FIXME */ | |
637 | /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */ | |
638 | } | |
eb5d44eb | 639 | |
f390d2c7 | 640 | lsp->lsp_header->rem_lifetime = |
eb5d44eb | 641 | htons (ntohs (lsp->lsp_header->rem_lifetime) - 1); |
642 | } | |
643 | ||
644 | void | |
f390d2c7 | 645 | lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag) |
eb5d44eb | 646 | { |
647 | struct isis_dynhn *dyn = NULL; | |
f390d2c7 | 648 | u_char id[SYSID_STRLEN]; |
eb5d44eb | 649 | |
650 | if (dynhost) | |
651 | dyn = dynhn_find_by_id (lsp_id); | |
652 | else | |
653 | dyn = NULL; | |
654 | ||
655 | if (dyn) | |
f7c43dcb | 656 | sprintf ((char *)id, "%.14s", dyn->name.name); |
eb5d44eb | 657 | else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost) |
f7c43dcb | 658 | sprintf ((char *)id, "%.14s", unix_hostname ()); |
f390d2c7 | 659 | else |
660 | { | |
661 | memcpy (id, sysid_print (lsp_id), 15); | |
662 | } | |
eb5d44eb | 663 | if (frag) |
f7c43dcb | 664 | sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id), |
f390d2c7 | 665 | LSP_FRAGMENT (lsp_id)); |
eb5d44eb | 666 | else |
f7c43dcb | 667 | sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id)); |
eb5d44eb | 668 | } |
669 | ||
f390d2c7 | 670 | /* Convert the lsp attribute bits to attribute string */ |
671 | char * | |
672 | lsp_bits2string (u_char * lsp_bits) | |
673 | { | |
674 | char *pos = lsp_bits_string; | |
eb5d44eb | 675 | |
f390d2c7 | 676 | if (!*lsp_bits) |
eb5d44eb | 677 | return " none"; |
678 | ||
679 | /* we only focus on the default metric */ | |
680 | pos += sprintf (pos, "%d/", | |
f390d2c7 | 681 | ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0); |
eb5d44eb | 682 | |
683 | pos += sprintf (pos, "%d/", | |
f390d2c7 | 684 | ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0); |
685 | ||
686 | pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0); | |
eb5d44eb | 687 | |
eb5d44eb | 688 | *(pos) = '\0'; |
eb5d44eb | 689 | |
f390d2c7 | 690 | return lsp_bits_string; |
eb5d44eb | 691 | } |
692 | ||
693 | /* this function prints the lsp on show isis database */ | |
694 | void | |
f390d2c7 | 695 | lsp_print (dnode_t * node, struct vty *vty, char dynhost) |
eb5d44eb | 696 | { |
f390d2c7 | 697 | struct isis_lsp *lsp = dnode_get (node); |
eb5d44eb | 698 | u_char LSPid[255]; |
699 | ||
700 | lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1); | |
f390d2c7 | 701 | vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' '); |
702 | vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num)); | |
703 | vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum)); | |
eb5d44eb | 704 | |
f390d2c7 | 705 | if (ntohs (lsp->lsp_header->rem_lifetime) == 0) |
706 | vty_out (vty, " (%2u)", lsp->age_out); | |
eb5d44eb | 707 | else |
f390d2c7 | 708 | vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime)); |
eb5d44eb | 709 | |
710 | vty_out (vty, " %s%s", | |
f390d2c7 | 711 | lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE); |
eb5d44eb | 712 | } |
713 | ||
714 | void | |
f390d2c7 | 715 | lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) |
eb5d44eb | 716 | { |
717 | struct isis_lsp *lsp = dnode_get (node); | |
718 | struct area_addr *area_addr; | |
f390d2c7 | 719 | char nlpidstr[2]; |
720 | int i; | |
eb5d44eb | 721 | struct listnode *lnode; |
722 | struct is_neigh *is_neigh; | |
723 | struct te_is_neigh *te_is_neigh; | |
724 | struct ipv4_reachability *ipv4_reach; | |
725 | struct in_addr *ipv4_addr; | |
726 | struct te_ipv4_reachability *te_ipv4_reach; | |
727 | #ifdef HAVE_IPV6 | |
728 | struct ipv6_reachability *ipv6_reach; | |
729 | struct in6_addr in6; | |
730 | #endif | |
731 | u_char LSPid[255]; | |
732 | u_char hostname[255]; | |
733 | u_char buff[BUFSIZ]; | |
f390d2c7 | 734 | u_int32_t now, helper; |
eb5d44eb | 735 | u_char ipv4_reach_prefix[20]; |
736 | u_char ipv4_reach_mask[20]; | |
737 | u_char ipv4_address[20]; | |
738 | ||
739 | lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1); | |
f390d2c7 | 740 | lsp_print (node, vty, dynhost); |
eb5d44eb | 741 | |
742 | /* for all area address */ | |
f390d2c7 | 743 | if (lsp->tlv_data.area_addrs) |
744 | { | |
745 | LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode) | |
746 | { | |
747 | vty_out (vty, " Area Address: %s%s", | |
748 | isonet_print (area_addr->area_addr, area_addr->addr_len), | |
749 | VTY_NEWLINE); | |
750 | } | |
eb5d44eb | 751 | } |
eb5d44eb | 752 | |
753 | /* for the nlpid tlv */ | |
f390d2c7 | 754 | if (lsp->tlv_data.nlpids) |
755 | { | |
756 | for (i = 0; i < lsp->tlv_data.nlpids->count; i++) | |
757 | { | |
758 | switch (lsp->tlv_data.nlpids->nlpids[i]) | |
759 | { | |
760 | case NLPID_IP: | |
761 | case NLPID_IPV6: | |
762 | vty_out (vty, " NLPID: 0x%X%s", | |
763 | lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE); | |
764 | break; | |
765 | default: | |
766 | vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE); | |
767 | break; | |
768 | } | |
769 | } | |
770 | } | |
eb5d44eb | 771 | |
772 | /* for the hostname tlv */ | |
f390d2c7 | 773 | if (lsp->tlv_data.hostname) |
774 | { | |
775 | bzero (hostname, sizeof (hostname)); | |
776 | memcpy (hostname, lsp->tlv_data.hostname->name, | |
777 | lsp->tlv_data.hostname->namelen); | |
778 | vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE); | |
779 | } | |
eb5d44eb | 780 | |
f390d2c7 | 781 | if (lsp->tlv_data.ipv4_addrs) |
782 | { | |
783 | LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode) | |
784 | { | |
785 | memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address)); | |
786 | vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE); | |
787 | } | |
eb5d44eb | 788 | } |
f390d2c7 | 789 | |
eb5d44eb | 790 | /* for the internal reachable tlv */ |
791 | if (lsp->tlv_data.ipv4_int_reachs) | |
f390d2c7 | 792 | LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) |
793 | { | |
794 | memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), | |
795 | sizeof (ipv4_reach_prefix)); | |
796 | memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask), | |
797 | sizeof (ipv4_reach_mask)); | |
2097cd8a | 798 | vty_out (vty, " Metric: %d IP %s %s%s", |
f390d2c7 | 799 | ipv4_reach->metrics.metric_default, ipv4_reach_prefix, |
800 | ipv4_reach_mask, VTY_NEWLINE); | |
801 | } | |
2097cd8a | 802 | |
803 | /* for the external reachable tlv */ | |
804 | if (lsp->tlv_data.ipv4_ext_reachs) | |
f390d2c7 | 805 | LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode) |
806 | { | |
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)); | |
2097cd8a | 811 | vty_out (vty, " Metric: %d IP-External %s %s%s", |
f390d2c7 | 812 | ipv4_reach->metrics.metric_default, ipv4_reach_prefix, |
813 | ipv4_reach_mask, VTY_NEWLINE); | |
814 | } | |
eb5d44eb | 815 | |
816 | /* for the IS neighbor tlv */ | |
f390d2c7 | 817 | if (lsp->tlv_data.is_neighs) |
818 | { | |
819 | LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode) | |
820 | { | |
821 | lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0); | |
822 | vty_out (vty, " Metric: %d IS %s%s", | |
823 | is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE); | |
824 | } | |
eb5d44eb | 825 | } |
eb5d44eb | 826 | |
2097cd8a | 827 | /* IPv6 tlv */ |
828 | #ifdef HAVE_IPV6 | |
829 | if (lsp->tlv_data.ipv6_reachs) | |
f390d2c7 | 830 | LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) |
831 | { | |
832 | memset (&in6, 0, sizeof (in6)); | |
833 | memcpy (in6.s6_addr, ipv6_reach->prefix, | |
834 | PSIZE (ipv6_reach->prefix_len)); | |
f7c43dcb | 835 | inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ); |
2097cd8a | 836 | if ((ipv6_reach->control_info && |
f390d2c7 | 837 | CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL) |
838 | vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s", | |
839 | ntohl (ipv6_reach->metric), | |
840 | buff, ipv6_reach->prefix_len, VTY_NEWLINE); | |
2097cd8a | 841 | else |
f390d2c7 | 842 | vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s", |
843 | ntohl (ipv6_reach->metric), | |
844 | buff, ipv6_reach->prefix_len, VTY_NEWLINE); | |
2097cd8a | 845 | } |
846 | #endif | |
847 | ||
eb5d44eb | 848 | /* FIXME: Other tlvs such as te or external tlv will be added later */ |
f390d2c7 | 849 | #if 0 |
eb5d44eb | 850 | vty_out (vty, "%s %s %c%s", |
f390d2c7 | 851 | VTY_NEWLINE, LSPid, lsp->own_lsp ? '*' : ' ', VTY_NEWLINE); |
eb5d44eb | 852 | |
853 | vty_out (vty, " Sequence: 0x%08x Checksum: 0x%04x Lifetime: ", | |
854 | ntohl (lsp->lsp_header->seq_num), | |
855 | ntohs (lsp->lsp_header->checksum)); | |
856 | ||
857 | if (ntohs (lsp->lsp_header->rem_lifetime) == 0) | |
858 | vty_out (vty, " (%2u) ", lsp->age_out); | |
859 | else | |
860 | vty_out (vty, "%5u ", ntohs (lsp->lsp_header->rem_lifetime)); | |
861 | ||
862 | vty_out (vty, "%s Attributes:%s", | |
f390d2c7 | 863 | VTY_NEWLINE, lsp_bits2string (&lsp->lsp_header->lsp_bits)); |
eb5d44eb | 864 | |
865 | /* if this is a self originated LSP then print | |
866 | * the generation time plus when we sent it last | |
867 | * if it is a non self-originated LSP then print the | |
868 | * time when the LSP has been installed | |
869 | */ | |
870 | ||
f390d2c7 | 871 | if (lsp->own_lsp) |
872 | { | |
eb5d44eb | 873 | |
f390d2c7 | 874 | now = time (NULL); |
875 | helper = now - lsp->last_generated; | |
876 | if (!lsp->last_generated) | |
877 | helper = 0; | |
eb5d44eb | 878 | |
f390d2c7 | 879 | vty_out (vty, ", Generated: %s ago", time2string (helper)); |
eb5d44eb | 880 | |
f390d2c7 | 881 | now = time (NULL); |
882 | helper = now - lsp->last_sent; | |
883 | if (!lsp->last_sent) | |
884 | helper = 0; | |
eb5d44eb | 885 | |
f390d2c7 | 886 | vty_out (vty, ", Last sent: %s ago", time2string (helper)); |
887 | } | |
888 | else | |
889 | { | |
890 | now = time (NULL); | |
891 | helper = now - lsp->installed; | |
892 | if (!lsp->installed) | |
893 | helper = 0; | |
eb5d44eb | 894 | |
f390d2c7 | 895 | vty_out (vty, ", Installed: %s ago", time2string (helper)); |
eb5d44eb | 896 | |
f390d2c7 | 897 | } |
eb5d44eb | 898 | |
899 | vty_out (vty, "%s", VTY_NEWLINE); | |
900 | ||
f390d2c7 | 901 | if (lsp->tlv_data.nlpids) |
902 | { | |
903 | vty_out (vty, " Speaks: %s%s", nlpid2string (lsp->tlv_data.nlpids), | |
904 | VTY_NEWLINE); | |
905 | } | |
eb5d44eb | 906 | |
f390d2c7 | 907 | if (lsp->tlv_data.router_id) |
908 | { | |
909 | vty_out (vty, " Router ID: %s%s", | |
910 | inet_ntoa (lsp->tlv_data.router_id->id), VTY_NEWLINE); | |
911 | } | |
eb5d44eb | 912 | |
913 | if (lsp->tlv_data.is_neighs) | |
f390d2c7 | 914 | LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode) |
915 | { | |
916 | lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0); | |
917 | vty_out (vty, " IS %s, Metric: %d%s", | |
918 | LSPid, is_neigh->metrics.metric_default, VTY_NEWLINE); | |
919 | } | |
eb5d44eb | 920 | |
921 | if (lsp->tlv_data.te_is_neighs) | |
f390d2c7 | 922 | LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode) |
923 | { | |
924 | /* FIXME: metric display is wrong */ | |
925 | lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0); | |
926 | vty_out (vty, " extd-IS %s, Metric: %d%s", | |
927 | LSPid, te_is_neigh->te_metric[0], VTY_NEWLINE); | |
928 | } | |
eb5d44eb | 929 | |
930 | if (lsp->tlv_data.ipv4_int_reachs) | |
f390d2c7 | 931 | LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) |
932 | { | |
933 | vty_out (vty, " int-IP %s/%d, Metric: %d%s", | |
934 | inet_ntoa (ipv4_reach->prefix), | |
935 | ip_masklen (ipv4_reach->mask), | |
936 | ipv4_reach->metrics.metric_default, VTY_NEWLINE); | |
937 | } | |
eb5d44eb | 938 | |
939 | if (lsp->tlv_data.ipv4_ext_reachs) | |
f390d2c7 | 940 | LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode) |
941 | { | |
942 | vty_out (vty, " ext-IP %s/%d, Metric: %d%s", | |
943 | inet_ntoa (ipv4_reach->prefix), | |
944 | ip_masklen (ipv4_reach->mask), | |
945 | ipv4_reach->metrics.metric_default, VTY_NEWLINE); | |
946 | } | |
eb5d44eb | 947 | |
948 | if (lsp->tlv_data.te_ipv4_reachs) | |
f390d2c7 | 949 | LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode) |
950 | { | |
951 | vty_out (vty, " extd-IP %s/%d, Metric: %d%s", | |
952 | inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start, | |
953 | te_ipv4_reach->control)), | |
954 | te_ipv4_reach->control & 0x3F, | |
955 | ntohl (te_ipv4_reach->te_metric), VTY_NEWLINE); | |
956 | } | |
eb5d44eb | 957 | |
958 | #ifdef HAVE_IPV6 | |
959 | if (lsp->tlv_data.ipv6_reachs) | |
f390d2c7 | 960 | LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) |
961 | { | |
962 | memcpy (in6.s6_addr, ipv6_reach->prefix, 16); | |
963 | inet_ntop (AF_INET6, &in6, buff, BUFSIZ); | |
964 | if ((ipv6_reach->control_info && | |
965 | CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL) | |
966 | vty_out (vty, " int-IPv6 %s/%d, Metric: %d%s", | |
967 | buff, | |
968 | ipv6_reach->prefix_len, | |
969 | ntohl (ipv6_reach->metric), VTY_NEWLINE); | |
970 | else | |
971 | vty_out (vty, " ext-IPv6 %s/%d, Metric: %d%s", | |
972 | buff, | |
973 | ipv6_reach->prefix_len, | |
974 | ntohl (ipv6_reach->metric), VTY_NEWLINE); | |
975 | ||
976 | } | |
eb5d44eb | 977 | #endif |
f390d2c7 | 978 | if (lsp->tlv_data.hostname) |
979 | { | |
980 | memset (hostname, 0, sizeof (hostname)); | |
981 | memcpy (hostname, lsp->tlv_data.hostname->name, | |
982 | lsp->tlv_data.hostname->namelen); | |
983 | vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE); | |
984 | } | |
eb5d44eb | 985 | #endif |
f390d2c7 | 986 | return; |
eb5d44eb | 987 | } |
988 | ||
989 | /* print all the lsps info in the local lspdb */ | |
f390d2c7 | 990 | int |
991 | lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost) | |
eb5d44eb | 992 | { |
993 | ||
f390d2c7 | 994 | dnode_t *node = dict_first (lspdb), *next; |
eb5d44eb | 995 | int lsp_count = 0; |
996 | ||
997 | /* print the title, for both modes */ | |
998 | vty_out (vty, "LSP ID LSP Seq Num LSP Checksum " | |
f390d2c7 | 999 | "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE); |
1000 | ||
1001 | if (detail == ISIS_UI_LEVEL_BRIEF) | |
1002 | { | |
1003 | while (node != NULL) | |
1004 | { | |
1005 | /* I think it is unnecessary, so I comment it out */ | |
1006 | /* dict_contains (lspdb, node); */ | |
1007 | next = dict_next (lspdb, node); | |
1008 | lsp_print (node, vty, dynhost); | |
1009 | node = next; | |
1010 | lsp_count++; | |
1011 | } | |
1012 | } | |
1013 | else if (detail == ISIS_UI_LEVEL_DETAIL) | |
1014 | { | |
1015 | while (node != NULL) | |
1016 | { | |
1017 | next = dict_next (lspdb, node); | |
1018 | lsp_print_detail (node, vty, dynhost); | |
1019 | node = next; | |
1020 | lsp_count++; | |
1021 | } | |
eb5d44eb | 1022 | } |
eb5d44eb | 1023 | |
1024 | return lsp_count; | |
1025 | } | |
1026 | ||
1027 | /* this function reallocate memory to an lsp pdu, with an additional | |
1028 | * size of memory, it scans the lsp and moves all pointers the | |
1029 | * way they should */ | |
1030 | u_char * | |
f390d2c7 | 1031 | lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size) |
eb5d44eb | 1032 | { |
1033 | u_char *retval; | |
f390d2c7 | 1034 | |
1035 | retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len); | |
eb5d44eb | 1036 | #ifdef LSP_MEMORY_PREASSIGN |
f390d2c7 | 1037 | lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size); |
eb5d44eb | 1038 | return retval; |
f390d2c7 | 1039 | #else /* otherwise we have to move all pointers */ |
eb5d44eb | 1040 | u_char *newpdu; |
1041 | newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size); | |
f390d2c7 | 1042 | memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu), |
1043 | ntohs (lsp->lsp_header->pdu_len)); | |
eb5d44eb | 1044 | XFREE (memorytype, lsp->pdu); |
1045 | lsp->pdu = newpdu; | |
f390d2c7 | 1046 | lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu); |
1047 | lsp->lsp_header = (struct isis_link_state_hdr *) | |
1048 | (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN); | |
eb5d44eb | 1049 | htons (ntohs (lsp->lsp_header->pdu_len) += size); |
f390d2c7 | 1050 | return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size); |
eb5d44eb | 1051 | #endif /* LSP_MEMORY_PREASSIGN */ |
1052 | } | |
1053 | ||
f390d2c7 | 1054 | #if 0 /* Saving the old one just in case :) */ |
eb5d44eb | 1055 | /* |
1056 | * Builds the lsp->tlv_data | |
1057 | * and writes the tlvs into lsp->pdu | |
1058 | */ | |
1059 | void | |
1060 | lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) | |
1061 | { | |
1062 | struct is_neigh *is_neigh; | |
1063 | struct listnode *node, *ipnode; | |
1064 | int level = lsp->level; | |
1065 | struct isis_circuit *circuit; | |
1066 | struct prefix_ipv4 *ipv4; | |
1067 | struct ipv4_reachability *ipreach; | |
1068 | struct isis_adjacency *nei; | |
1069 | #ifdef HAVE_IPV6 | |
1070 | struct prefix_ipv6 *ipv6; | |
1071 | struct ipv6_reachability *ip6reach; | |
1072 | #endif /* HAVE_IPV6 */ | |
f390d2c7 | 1073 | |
eb5d44eb | 1074 | /* |
1075 | * First add the tlvs related to area | |
1076 | */ | |
f390d2c7 | 1077 | |
eb5d44eb | 1078 | /* Area addresses */ |
1079 | if (lsp->tlv_data.area_addrs == NULL) | |
1080 | lsp->tlv_data.area_addrs = list_new (); | |
1081 | list_add_list (lsp->tlv_data.area_addrs, area->area_addrs); | |
1082 | /* Protocols Supported */ | |
f390d2c7 | 1083 | if (area->ip_circuits > 0 |
eb5d44eb | 1084 | #ifdef HAVE_IPV6 |
1085 | || area->ipv6_circuits > 0 | |
1086 | #endif /* HAVE_IPV6 */ | |
f390d2c7 | 1087 | ) |
eb5d44eb | 1088 | { |
1089 | lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids)); | |
1090 | lsp->tlv_data.nlpids->count = 0; | |
f390d2c7 | 1091 | if (area->ip_circuits > 0) |
1092 | { | |
1093 | lsp->tlv_data.nlpids->count++; | |
1094 | lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP; | |
1095 | } | |
eb5d44eb | 1096 | #ifdef HAVE_IPV6 |
f390d2c7 | 1097 | if (area->ipv6_circuits > 0) |
1098 | { | |
1099 | lsp->tlv_data.nlpids->count++; | |
1100 | lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] = | |
1101 | NLPID_IPV6; | |
1102 | } | |
eb5d44eb | 1103 | #endif /* HAVE_IPV6 */ |
1104 | } | |
1105 | /* Dynamic Hostname */ | |
f390d2c7 | 1106 | if (area->dynhostname) |
1107 | { | |
1108 | lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, | |
1109 | sizeof (struct hostname)); | |
1110 | memcpy (&lsp->tlv_data.hostname->name, unix_hostname (), | |
1111 | strlen (unix_hostname ())); | |
1112 | lsp->tlv_data.hostname->namelen = strlen (unix_hostname ()); | |
1113 | } | |
eb5d44eb | 1114 | #ifdef TOPOLOGY_GENERATE |
1115 | /* | |
1116 | * If we have a topology in this area, we need to connect this lsp to | |
1117 | * the first topology lsp | |
1118 | */ | |
f390d2c7 | 1119 | if ((area->topology) && (level == 1)) |
1120 | { | |
1121 | if (lsp->tlv_data.is_neighs == NULL) | |
1122 | lsp->tlv_data.is_neighs = list_new (); | |
1123 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); | |
1124 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1125 | memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN); | |
1126 | /* connected to the first */ | |
1127 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01); | |
1128 | /* this is actually the same system, why mess the SPT */ | |
1129 | is_neigh->metrics.metric_default = 0; | |
1130 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; | |
1131 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; | |
1132 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; | |
1133 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); | |
eb5d44eb | 1134 | |
f390d2c7 | 1135 | } |
eb5d44eb | 1136 | #endif |
1137 | ||
1138 | /* | |
1139 | * Then add tlvs related to circuits | |
1140 | */ | |
f390d2c7 | 1141 | for (node = listhead (area->circuit_list); node; nextnode (node)) |
1142 | { | |
1143 | circuit = getdata (node); | |
1144 | if (circuit->state != C_STATE_UP) | |
1145 | continue; | |
1146 | ||
1147 | /* | |
1148 | * Add IPv4 internal reachability of this circuit | |
1149 | */ | |
1150 | if (circuit->ip_router && circuit->ip_addrs && | |
1151 | circuit->ip_addrs->count > 0) | |
1152 | { | |
1153 | if (lsp->tlv_data.ipv4_int_reachs == NULL) | |
1154 | { | |
1155 | lsp->tlv_data.ipv4_int_reachs = list_new (); | |
1156 | lsp->tlv_data.ipv4_int_reachs->del = free_tlv; | |
1157 | } | |
1158 | for (ipnode = listhead (circuit->ip_addrs); ipnode; | |
1159 | nextnode (ipnode)) | |
1160 | { | |
1161 | ipv4 = getdata (ipnode); | |
1162 | ipreach = | |
1163 | XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability)); | |
1164 | ipreach->metrics = circuit->metrics[level - 1]; | |
1165 | ipreach->prefix = ipv4->prefix; | |
1166 | masklen2ip (ipv4->prefixlen, &ipreach->mask); | |
1167 | listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach); | |
1168 | } | |
1169 | } | |
eb5d44eb | 1170 | #ifdef HAVE_IPV6 |
f390d2c7 | 1171 | /* |
1172 | * Add IPv6 reachability of this circuit | |
1173 | */ | |
1174 | if (circuit->ipv6_router && circuit->ipv6_non_link && | |
1175 | circuit->ipv6_non_link->count > 0) | |
1176 | { | |
1177 | if (lsp->tlv_data.ipv6_reachs == NULL) | |
1178 | { | |
1179 | lsp->tlv_data.ipv6_reachs = list_new (); | |
1180 | lsp->tlv_data.ipv6_reachs->del = free_tlv; | |
1181 | } | |
1182 | for (ipnode = listhead (circuit->ipv6_non_link); ipnode; | |
1183 | nextnode (ipnode)) | |
1184 | { | |
1185 | ipv6 = getdata (ipnode); | |
1186 | ip6reach = | |
1187 | XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability)); | |
1188 | memset (ip6reach, 0, sizeof (struct ipv6_reachability)); | |
1189 | ip6reach->metric = | |
1190 | htonl (circuit->metrics[level - 1].metric_default); | |
1191 | ip6reach->control_info = 0; | |
1192 | ip6reach->prefix_len = ipv6->prefixlen; | |
1193 | memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr, | |
1194 | (ipv6->prefixlen + 7) / 8); | |
1195 | listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach); | |
1196 | } | |
1197 | } | |
eb5d44eb | 1198 | #endif /* HAVE_IPV6 */ |
f390d2c7 | 1199 | |
1200 | switch (circuit->circ_type) | |
1201 | { | |
1202 | case CIRCUIT_T_BROADCAST: | |
1203 | if (level & circuit->circuit_is_type) | |
1204 | { | |
1205 | if (lsp->tlv_data.is_neighs == NULL) | |
1206 | { | |
1207 | lsp->tlv_data.is_neighs = list_new (); | |
1208 | lsp->tlv_data.is_neighs->del = free_tlv; | |
1209 | } | |
1210 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); | |
1211 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1212 | if (level == 1) | |
1213 | memcpy (&is_neigh->neigh_id, | |
1214 | circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); | |
1215 | else | |
1216 | memcpy (&is_neigh->neigh_id, | |
1217 | circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); | |
1218 | is_neigh->metrics = circuit->metrics[level - 1]; | |
1219 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); | |
1220 | } | |
1221 | break; | |
1222 | case CIRCUIT_T_P2P: | |
1223 | nei = circuit->u.p2p.neighbor; | |
1224 | if (nei && (level & nei->circuit_t)) | |
1225 | { | |
1226 | if (lsp->tlv_data.is_neighs == NULL) | |
1227 | { | |
1228 | lsp->tlv_data.is_neighs = list_new (); | |
1229 | lsp->tlv_data.is_neighs->del = free_tlv; | |
1230 | } | |
1231 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); | |
1232 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1233 | memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN); | |
1234 | is_neigh->metrics = circuit->metrics[level - 1]; | |
1235 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); | |
1236 | } | |
1237 | break; | |
1238 | case CIRCUIT_T_STATIC_IN: | |
1239 | zlog_warn ("lsp_area_create: unsupported circuit type"); | |
1240 | break; | |
1241 | case CIRCUIT_T_STATIC_OUT: | |
1242 | zlog_warn ("lsp_area_create: unsupported circuit type"); | |
1243 | break; | |
1244 | case CIRCUIT_T_DA: | |
1245 | zlog_warn ("lsp_area_create: unsupported circuit type"); | |
1246 | break; | |
1247 | default: | |
1248 | zlog_warn ("lsp_area_create: unknown circuit type"); | |
1249 | } | |
eb5d44eb | 1250 | } |
f390d2c7 | 1251 | |
eb5d44eb | 1252 | stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
f390d2c7 | 1253 | |
eb5d44eb | 1254 | if (lsp->tlv_data.nlpids) |
1255 | tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu); | |
1256 | if (lsp->tlv_data.hostname) | |
1257 | tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu); | |
f390d2c7 | 1258 | if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0) |
eb5d44eb | 1259 | tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu); |
1260 | if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0) | |
1261 | tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu); | |
f390d2c7 | 1262 | if (lsp->tlv_data.ipv4_int_reachs && |
eb5d44eb | 1263 | listcount (lsp->tlv_data.ipv4_int_reachs) > 0) |
1264 | tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu); | |
f390d2c7 | 1265 | #ifdef HAVE_IPV6 |
1266 | if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0) | |
eb5d44eb | 1267 | tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu); |
1268 | #endif /* HAVE_IPV6 */ | |
1269 | ||
1270 | lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu)); | |
1271 | ||
1272 | return; | |
1273 | } | |
1274 | #endif | |
1275 | ||
1276 | #define FRAG_THOLD(S,T) \ | |
1277 | ((STREAM_SIZE(S)*T)/100) | |
1278 | ||
1279 | /* stream*, area->lsp_frag_threshold, increment */ | |
1280 | #define FRAG_NEEDED(S,T,I) \ | |
1281 | (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T)) | |
1282 | ||
1283 | void | |
1284 | lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to, | |
f390d2c7 | 1285 | int tlvsize, int frag_thold, |
1286 | int tlv_build_func (struct list *, struct stream *)) | |
eb5d44eb | 1287 | { |
1288 | int count, i; | |
f390d2c7 | 1289 | |
eb5d44eb | 1290 | /* can we fit all ? */ |
f390d2c7 | 1291 | if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2)) |
1292 | { | |
1293 | tlv_build_func (*from, lsp->pdu); | |
1294 | *to = *from; | |
1295 | *from = NULL; | |
1296 | } | |
1297 | else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2)) | |
1298 | { | |
1299 | /* fit all we can */ | |
1300 | count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 - | |
1301 | (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu)); | |
1302 | if (count) | |
1303 | count = count / tlvsize; | |
1304 | for (i = 0; i < count; i++) | |
1305 | { | |
1306 | listnode_add (*to, getdata (listhead (*from))); | |
1307 | listnode_delete (*from, getdata (listhead (*from))); | |
1308 | } | |
1309 | tlv_build_func (*to, lsp->pdu); | |
1310 | } | |
1311 | lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu)); | |
eb5d44eb | 1312 | return; |
1313 | } | |
1314 | ||
f390d2c7 | 1315 | struct isis_lsp * |
1316 | lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area, | |
1317 | int level) | |
eb5d44eb | 1318 | { |
1319 | struct isis_lsp *lsp; | |
f390d2c7 | 1320 | u_char frag_id[ISIS_SYS_ID_LEN + 2]; |
1321 | ||
eb5d44eb | 1322 | memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1); |
1323 | LSP_FRAGMENT (frag_id) = frag_num; | |
1324 | lsp = lsp_search (frag_id, area->lspdb[level - 1]); | |
f390d2c7 | 1325 | if (lsp) |
1326 | { | |
1327 | /* | |
1328 | * Clear the TLVs, but inherit the authinfo | |
1329 | */ | |
1330 | lsp_clear_data (lsp); | |
1331 | if (lsp0->tlv_data.auth_info.type) | |
1332 | { | |
1333 | memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info, | |
1334 | sizeof (struct isis_passwd)); | |
1335 | tlv_add_authinfo (lsp->tlv_data.auth_info.type, | |
1336 | lsp->tlv_data.auth_info.len, | |
1337 | lsp->tlv_data.auth_info.passwd, lsp->pdu); | |
1338 | } | |
1339 | return lsp; | |
eb5d44eb | 1340 | } |
eb5d44eb | 1341 | lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type, |
f390d2c7 | 1342 | 0, level); |
eb5d44eb | 1343 | lsp->own_lsp = 1; |
f390d2c7 | 1344 | lsp_insert (lsp, area->lspdb[level - 1]); |
eb5d44eb | 1345 | listnode_add (lsp0->lspu.frags, lsp); |
1346 | lsp->lspu.zero_lsp = lsp0; | |
1347 | /* | |
1348 | * Copy the authinfo from zero LSP | |
1349 | */ | |
f390d2c7 | 1350 | if (lsp0->tlv_data.auth_info.type) |
1351 | { | |
1352 | memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info, | |
1353 | sizeof (struct isis_passwd)); | |
1354 | tlv_add_authinfo (lsp->tlv_data.auth_info.type, | |
1355 | lsp->tlv_data.auth_info.len, | |
1356 | lsp->tlv_data.auth_info.passwd, lsp->pdu); | |
1357 | } | |
eb5d44eb | 1358 | return lsp; |
1359 | } | |
1360 | ||
1361 | /* | |
1362 | * Builds the LSP data part. This func creates a new frag whenever | |
1363 | * area->lsp_frag_threshold is exceeded. | |
1364 | */ | |
1365 | #if 1 | |
1366 | void | |
1367 | lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) | |
1368 | { | |
1369 | struct is_neigh *is_neigh; | |
1370 | struct listnode *node, *ipnode; | |
1371 | int level = lsp->level; | |
1372 | struct isis_circuit *circuit; | |
1373 | struct prefix_ipv4 *ipv4; | |
1374 | struct ipv4_reachability *ipreach; | |
1375 | struct isis_adjacency *nei; | |
1376 | #ifdef HAVE_IPV6 | |
6785157b | 1377 | struct prefix_ipv6 *ipv6, *ip6prefix; |
eb5d44eb | 1378 | struct ipv6_reachability *ip6reach; |
1379 | #endif /* HAVE_IPV6 */ | |
1380 | struct tlvs tlv_data; | |
1381 | struct isis_lsp *lsp0 = lsp; | |
1382 | struct isis_passwd *passwd; | |
1383 | ||
1384 | /* | |
1385 | * First add the tlvs related to area | |
1386 | */ | |
f390d2c7 | 1387 | |
eb5d44eb | 1388 | /* Area addresses */ |
1389 | if (lsp->tlv_data.area_addrs == NULL) | |
1390 | lsp->tlv_data.area_addrs = list_new (); | |
1391 | list_add_list (lsp->tlv_data.area_addrs, area->area_addrs); | |
1392 | /* Protocols Supported */ | |
f390d2c7 | 1393 | if (area->ip_circuits > 0 |
eb5d44eb | 1394 | #ifdef HAVE_IPV6 |
1395 | || area->ipv6_circuits > 0 | |
1396 | #endif /* HAVE_IPV6 */ | |
f390d2c7 | 1397 | ) |
eb5d44eb | 1398 | { |
1399 | lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids)); | |
1400 | lsp->tlv_data.nlpids->count = 0; | |
f390d2c7 | 1401 | if (area->ip_circuits > 0) |
1402 | { | |
1403 | lsp->tlv_data.nlpids->count++; | |
1404 | lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP; | |
1405 | } | |
eb5d44eb | 1406 | #ifdef HAVE_IPV6 |
f390d2c7 | 1407 | if (area->ipv6_circuits > 0) |
1408 | { | |
1409 | lsp->tlv_data.nlpids->count++; | |
1410 | lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] = | |
1411 | NLPID_IPV6; | |
1412 | } | |
eb5d44eb | 1413 | #endif /* HAVE_IPV6 */ |
1414 | } | |
1415 | /* Dynamic Hostname */ | |
f390d2c7 | 1416 | if (area->dynhostname) |
1417 | { | |
1418 | lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, | |
1419 | sizeof (struct hostname)); | |
9e867fe6 | 1420 | |
f390d2c7 | 1421 | memcpy (lsp->tlv_data.hostname->name, unix_hostname (), |
1422 | strlen (unix_hostname ())); | |
1423 | lsp->tlv_data.hostname->namelen = strlen (unix_hostname ()); | |
1424 | } | |
eb5d44eb | 1425 | |
1426 | /* | |
1427 | * Building the zero lsp | |
1428 | */ | |
f390d2c7 | 1429 | stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
eb5d44eb | 1430 | /* |
1431 | * Add the authentication info if its present | |
1432 | */ | |
f390d2c7 | 1433 | (level == 1) ? (passwd = &area->area_passwd) : |
1434 | (passwd = &area->domain_passwd); | |
1435 | if (passwd->type) | |
1436 | { | |
1437 | memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd)); | |
1438 | tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu); | |
1439 | } | |
eb5d44eb | 1440 | if (lsp->tlv_data.nlpids) |
1441 | tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu); | |
1442 | if (lsp->tlv_data.hostname) | |
1443 | tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu); | |
f390d2c7 | 1444 | if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0) |
eb5d44eb | 1445 | tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu); |
f390d2c7 | 1446 | |
eb5d44eb | 1447 | memset (&tlv_data, 0, sizeof (struct tlvs)); |
1448 | /* | |
1449 | * Then build lists of tlvs related to circuits | |
1450 | */ | |
f390d2c7 | 1451 | for (node = listhead (area->circuit_list); node; nextnode (node)) |
1452 | { | |
1453 | circuit = getdata (node); | |
1454 | if (circuit->state != C_STATE_UP) | |
1455 | continue; | |
eb5d44eb | 1456 | |
f390d2c7 | 1457 | /* |
1458 | * Add IPv4 internal reachability of this circuit | |
1459 | */ | |
1460 | if (circuit->ip_router && circuit->ip_addrs && | |
1461 | circuit->ip_addrs->count > 0) | |
1462 | { | |
1463 | if (tlv_data.ipv4_int_reachs == NULL) | |
1464 | { | |
1465 | tlv_data.ipv4_int_reachs = list_new (); | |
1466 | } | |
1467 | for (ipnode = listhead (circuit->ip_addrs); ipnode; | |
1468 | nextnode (ipnode)) | |
1469 | { | |
1470 | ipv4 = getdata (ipnode); | |
1471 | ipreach = | |
1472 | XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability)); | |
1473 | ipreach->metrics = circuit->metrics[level - 1]; | |
f390d2c7 | 1474 | masklen2ip (ipv4->prefixlen, &ipreach->mask); |
6785157b | 1475 | ipreach->prefix.s_addr = ((ipreach->mask.s_addr) & |
1476 | (ipv4->prefix.s_addr)); | |
f390d2c7 | 1477 | listnode_add (tlv_data.ipv4_int_reachs, ipreach); |
1478 | } | |
1479 | ||
1480 | } | |
eb5d44eb | 1481 | #ifdef HAVE_IPV6 |
f390d2c7 | 1482 | /* |
1483 | * Add IPv6 reachability of this circuit | |
1484 | */ | |
1485 | if (circuit->ipv6_router && circuit->ipv6_non_link && | |
1486 | circuit->ipv6_non_link->count > 0) | |
1487 | { | |
1488 | ||
1489 | if (tlv_data.ipv6_reachs == NULL) | |
1490 | { | |
1491 | tlv_data.ipv6_reachs = list_new (); | |
1492 | } | |
1493 | for (ipnode = listhead (circuit->ipv6_non_link); ipnode; | |
1494 | nextnode (ipnode)) | |
1495 | { | |
1496 | ipv6 = getdata (ipnode); | |
1497 | ip6reach = | |
1498 | XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability)); | |
1499 | memset (ip6reach, 0, sizeof (struct ipv6_reachability)); | |
1500 | ip6reach->metric = | |
1501 | htonl (circuit->metrics[level - 1].metric_default); | |
1502 | ip6reach->control_info = 0; | |
1503 | ip6reach->prefix_len = ipv6->prefixlen; | |
6785157b | 1504 | memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix)); |
1505 | apply_mask_ipv6 (ip6prefix); | |
1506 | memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr, | |
1507 | sizeof (ip6reach->prefix)); | |
f390d2c7 | 1508 | listnode_add (tlv_data.ipv6_reachs, ip6reach); |
1509 | } | |
1510 | } | |
eb5d44eb | 1511 | #endif /* HAVE_IPV6 */ |
f390d2c7 | 1512 | |
1513 | switch (circuit->circ_type) | |
1514 | { | |
1515 | case CIRCUIT_T_BROADCAST: | |
1516 | if (level & circuit->circuit_is_type) | |
1517 | { | |
1518 | if (tlv_data.is_neighs == NULL) | |
1519 | { | |
1520 | tlv_data.is_neighs = list_new (); | |
1521 | } | |
1522 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); | |
1523 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1524 | if (level == 1) | |
1525 | memcpy (is_neigh->neigh_id, | |
1526 | circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); | |
1527 | else | |
1528 | memcpy (is_neigh->neigh_id, | |
1529 | circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); | |
1530 | is_neigh->metrics = circuit->metrics[level - 1]; | |
1531 | listnode_add (tlv_data.is_neighs, is_neigh); | |
1532 | } | |
1533 | break; | |
1534 | case CIRCUIT_T_P2P: | |
1535 | nei = circuit->u.p2p.neighbor; | |
1536 | if (nei && (level & nei->circuit_t)) | |
1537 | { | |
1538 | if (tlv_data.is_neighs == NULL) | |
1539 | { | |
1540 | tlv_data.is_neighs = list_new (); | |
1541 | tlv_data.is_neighs->del = free_tlv; | |
1542 | } | |
1543 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); | |
1544 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1545 | memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN); | |
1546 | is_neigh->metrics = circuit->metrics[level - 1]; | |
1547 | listnode_add (tlv_data.is_neighs, is_neigh); | |
1548 | } | |
1549 | break; | |
1550 | case CIRCUIT_T_STATIC_IN: | |
1551 | zlog_warn ("lsp_area_create: unsupported circuit type"); | |
1552 | break; | |
1553 | case CIRCUIT_T_STATIC_OUT: | |
1554 | zlog_warn ("lsp_area_create: unsupported circuit type"); | |
1555 | break; | |
1556 | case CIRCUIT_T_DA: | |
1557 | zlog_warn ("lsp_area_create: unsupported circuit type"); | |
1558 | break; | |
1559 | default: | |
1560 | zlog_warn ("lsp_area_create: unknown circuit type"); | |
1561 | } | |
eb5d44eb | 1562 | } |
eb5d44eb | 1563 | |
f390d2c7 | 1564 | while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs)) |
1565 | { | |
1566 | if (lsp->tlv_data.ipv4_int_reachs == NULL) | |
1567 | lsp->tlv_data.ipv4_int_reachs = list_new (); | |
1568 | lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs, | |
1569 | &lsp->tlv_data.ipv4_int_reachs, | |
1570 | IPV4_REACH_LEN, area->lsp_frag_threshold, | |
1571 | tlv_add_ipv4_reachs); | |
1572 | if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs)) | |
1573 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, | |
1574 | lsp0, area, level); | |
1575 | } | |
1576 | ||
1577 | #ifdef HAVE_IPV6 | |
1578 | while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs)) | |
1579 | { | |
1580 | if (lsp->tlv_data.ipv6_reachs == NULL) | |
1581 | lsp->tlv_data.ipv6_reachs = list_new (); | |
1582 | lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs, | |
1583 | &lsp->tlv_data.ipv6_reachs, | |
1584 | IPV6_REACH_LEN, area->lsp_frag_threshold, | |
1585 | tlv_add_ipv6_reachs); | |
1586 | if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs)) | |
1587 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, | |
1588 | lsp0, area, level); | |
1589 | } | |
1590 | #endif /* HAVE_IPV6 */ | |
1591 | ||
1592 | while (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) | |
1593 | { | |
1594 | if (lsp->tlv_data.is_neighs == NULL) | |
1595 | lsp->tlv_data.is_neighs = list_new (); | |
1596 | lsp_tlv_fit (lsp, &tlv_data.is_neighs, | |
1597 | &lsp->tlv_data.is_neighs, | |
1598 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, | |
1599 | tlv_add_is_neighs); | |
1600 | if (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) | |
1601 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, | |
1602 | lsp0, area, level); | |
1603 | } | |
eb5d44eb | 1604 | |
eb5d44eb | 1605 | return; |
1606 | } | |
1607 | #endif | |
1608 | ||
1609 | void | |
1610 | build_lsp_data (struct isis_lsp *lsp, struct isis_area *area) | |
1611 | { | |
1612 | struct list *circuit_list = area->circuit_list; | |
1613 | struct isis_circuit *circuit; | |
1614 | u_char *tlv_ptr; | |
1615 | struct is_neigh *is_neigh; | |
1616 | ||
f390d2c7 | 1617 | |
eb5d44eb | 1618 | /* add our nlpids */ |
f390d2c7 | 1619 | /* the 2 is for the TL plus 1 for the nlpid */ |
1620 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3); | |
1621 | *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */ | |
1622 | *(tlv_ptr + 1) = 1; /* one protocol */ | |
1623 | #ifdef HAVE_IPV6 /*dunno if its right */ | |
1624 | *(tlv_ptr + 2) = NLPID_IPV6; | |
eb5d44eb | 1625 | #else |
f390d2c7 | 1626 | *(tlv_ptr + 2) = NLPID_IP; |
eb5d44eb | 1627 | #endif /* HAVE_IPV6 */ |
1628 | ||
1629 | /* we should add our areas here | |
1630 | * FIXME: we need to figure out which should be added? Adj? All? First? */ | |
1631 | ||
1632 | /* first, lets add ourselves to the IS neighbours info */ | |
f390d2c7 | 1633 | /* the 2 is for the TL plus 1 for the virtual field */ |
1634 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3); | |
1635 | *tlv_ptr = IS_NEIGHBOURS; /* Type */ | |
1636 | *(tlv_ptr + 2) = 0; /* virtual is zero */ | |
1637 | lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */ | |
eb5d44eb | 1638 | /* assign space for the is_neigh at the pdu end */ |
f390d2c7 | 1639 | is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV, |
1640 | sizeof (struct is_neigh)); | |
eb5d44eb | 1641 | /* add this node to our list */ |
f390d2c7 | 1642 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); |
eb5d44eb | 1643 | /* FIXME: Do we need our designated address here? */ |
f390d2c7 | 1644 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1); |
eb5d44eb | 1645 | /* FIXME: Where should we really get our own LSPs metrics from? */ |
f390d2c7 | 1646 | circuit = (struct isis_circuit *) listhead (circuit_list); |
1647 | /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */ | |
eb5d44eb | 1648 | /* Length */ |
f390d2c7 | 1649 | *(tlv_ptr + 1) = |
1650 | (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1); | |
eb5d44eb | 1651 | |
1652 | /* FIXME: scan for adjencecies and add them */ | |
1653 | ||
1654 | /* FIXME: add reachability info */ | |
1655 | ||
f390d2c7 | 1656 | /* adding dynamic hostname if needed */ |
1657 | if (area->dynhostname) | |
1658 | { | |
1659 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */ | |
1660 | *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */ | |
1661 | *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */ | |
1662 | lsp->tlv_data.hostname = (struct hostname *) | |
1663 | (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, | |
1664 | /* the -1 is to fit the length in the struct */ | |
1665 | strlen (unix_hostname ())) - 1); | |
1666 | memcpy (lsp->tlv_data.hostname->name, unix_hostname (), | |
1667 | strlen (unix_hostname ())); | |
1668 | } | |
eb5d44eb | 1669 | |
1670 | } | |
1671 | ||
1672 | /* | |
1673 | * 7.3.7 Generation on non-pseudonode LSPs | |
1674 | */ | |
1675 | int | |
f390d2c7 | 1676 | lsp_generate_non_pseudo (struct isis_area *area, int level) |
1677 | { | |
eb5d44eb | 1678 | struct isis_lsp *oldlsp, *newlsp; |
1679 | u_int32_t seq_num = 0; | |
1680 | u_char lspid[ISIS_SYS_ID_LEN + 2]; | |
1681 | ||
1682 | memset (&lspid, 0, ISIS_SYS_ID_LEN + 2); | |
1683 | memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN); | |
1684 | ||
1685 | /* only builds the lsp if the area shares the level */ | |
f390d2c7 | 1686 | if ((area->is_type & level) == level) |
1687 | { | |
1688 | oldlsp = lsp_search (lspid, area->lspdb[level - 1]); | |
1689 | if (oldlsp) | |
1690 | { | |
1691 | seq_num = ntohl (oldlsp->lsp_header->seq_num); | |
1692 | lsp_search_and_destroy (oldlsp->lsp_header->lsp_id, | |
1693 | area->lspdb[level - 1]); | |
1694 | /* FIXME: we should actually initiate a purge */ | |
1695 | } | |
1696 | newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num, | |
1697 | area->is_type, 0, level); | |
1698 | newlsp->own_lsp = 1; | |
1699 | ||
1700 | lsp_insert (newlsp, area->lspdb[level - 1]); | |
1701 | /* build_lsp_data (newlsp, area); */ | |
1702 | lsp_build_nonpseudo (newlsp, area); | |
1703 | /* time to calculate our checksum */ | |
1704 | lsp_seqnum_update (newlsp); | |
1705 | } | |
eb5d44eb | 1706 | |
1707 | /* DEBUG_ADJ_PACKETS */ | |
f390d2c7 | 1708 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
1709 | { | |
1710 | /* FIXME: is this place right? fix missing info */ | |
1711 | zlog_info ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level); | |
1712 | } | |
eb5d44eb | 1713 | |
1714 | return ISIS_OK; | |
1715 | } | |
1716 | ||
1717 | /* | |
1718 | * 7.3.9 Generation of level 1 LSPs (non-pseudonode) | |
1719 | */ | |
1720 | int | |
1721 | lsp_l1_generate (struct isis_area *area) | |
1722 | { | |
f390d2c7 | 1723 | THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area, |
1724 | MAX_LSP_GEN_INTERVAL); | |
eb5d44eb | 1725 | |
1726 | return lsp_generate_non_pseudo (area, 1); | |
1727 | } | |
1728 | ||
eb5d44eb | 1729 | /* |
1730 | * 7.3.9 Generation of level 2 LSPs (non-pseudonode) | |
1731 | */ | |
1732 | int | |
1733 | lsp_l2_generate (struct isis_area *area) | |
1734 | { | |
f390d2c7 | 1735 | THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area, |
1736 | MAX_LSP_GEN_INTERVAL); | |
eb5d44eb | 1737 | |
1738 | return lsp_generate_non_pseudo (area, 2); | |
1739 | } | |
1740 | ||
1741 | int | |
1742 | lsp_non_pseudo_regenerate (struct isis_area *area, int level) | |
1743 | { | |
1744 | dict_t *lspdb = area->lspdb[level - 1]; | |
1745 | struct isis_lsp *lsp, *frag; | |
1746 | struct listnode *node; | |
1747 | u_char lspid[ISIS_SYS_ID_LEN + 2]; | |
1748 | ||
1749 | memset (lspid, 0, ISIS_SYS_ID_LEN + 2); | |
1750 | memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN); | |
f390d2c7 | 1751 | |
eb5d44eb | 1752 | lsp = lsp_search (lspid, lspdb); |
eb5d44eb | 1753 | |
f390d2c7 | 1754 | if (!lsp) |
1755 | { | |
1756 | zlog_err | |
1757 | ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!", | |
1758 | area->area_tag, level); | |
eb5d44eb | 1759 | |
f390d2c7 | 1760 | return ISIS_ERROR; |
1761 | } | |
1762 | ||
1763 | lsp_clear_data (lsp); | |
eb5d44eb | 1764 | lsp_build_nonpseudo (lsp, area); |
f390d2c7 | 1765 | lsp->lsp_header->rem_lifetime = htons (isis_jitter |
1766 | (area->max_lsp_lifetime[level - 1], | |
1767 | MAX_AGE_JITTER)); | |
eb5d44eb | 1768 | lsp_seqnum_update (lsp); |
f390d2c7 | 1769 | |
1770 | if (isis->debugs & DEBUG_UPDATE_PACKETS) | |
1771 | { | |
1772 | zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, " | |
1773 | "seq 0x%08x, cksum 0x%04x lifetime %us", | |
1774 | area->area_tag, | |
1775 | level, | |
1776 | rawlspid_print (lsp->lsp_header->lsp_id), | |
1777 | ntohl (lsp->lsp_header->seq_num), | |
1778 | ntohs (lsp->lsp_header->checksum), | |
1779 | ntohs (lsp->lsp_header->rem_lifetime)); | |
1780 | } | |
eb5d44eb | 1781 | |
1782 | lsp->last_generated = time (NULL); | |
1783 | area->lsp_regenerate_pending[level - 1] = 0; | |
1784 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
f390d2c7 | 1785 | for (node = listhead (lsp->lspu.frags); node; nextnode (node)) |
1786 | { | |
1787 | frag = getdata (node); | |
1788 | frag->lsp_header->rem_lifetime = htons (isis_jitter | |
1789 | (area-> | |
1790 | max_lsp_lifetime[level - 1], | |
1791 | MAX_AGE_JITTER)); | |
1792 | ISIS_FLAGS_SET_ALL (frag->SRMflags); | |
1793 | } | |
eb5d44eb | 1794 | |
1795 | if (area->ip_circuits) | |
1796 | isis_spf_schedule (area, level); | |
1797 | #ifdef HAVE_IPV6 | |
1798 | if (area->ipv6_circuits) | |
1799 | isis_spf_schedule6 (area, level); | |
1800 | #endif | |
1801 | return ISIS_OK; | |
1802 | } | |
1803 | ||
eb5d44eb | 1804 | /* |
1805 | * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding | |
1806 | * time and set SRM | |
1807 | */ | |
f390d2c7 | 1808 | int |
eb5d44eb | 1809 | lsp_refresh_l1 (struct thread *thread) |
1810 | { | |
1811 | struct isis_area *area; | |
1812 | unsigned long ref_time; | |
1813 | ||
1814 | area = THREAD_ARG (thread); | |
1815 | assert (area); | |
f390d2c7 | 1816 | |
eb5d44eb | 1817 | area->t_lsp_refresh[0] = NULL; |
f390d2c7 | 1818 | if (area->is_type & IS_LEVEL_1) |
eb5d44eb | 1819 | lsp_non_pseudo_regenerate (area, 1); |
f390d2c7 | 1820 | |
1821 | ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? | |
eb5d44eb | 1822 | MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0]; |
1823 | ||
f390d2c7 | 1824 | THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area, |
1825 | isis_jitter (ref_time, MAX_AGE_JITTER)); | |
d70f99e1 | 1826 | |
eb5d44eb | 1827 | return ISIS_OK; |
1828 | } | |
1829 | ||
f390d2c7 | 1830 | int |
eb5d44eb | 1831 | lsp_refresh_l2 (struct thread *thread) |
1832 | { | |
1833 | struct isis_area *area; | |
1834 | unsigned long ref_time; | |
1835 | ||
1836 | area = THREAD_ARG (thread); | |
1837 | assert (area); | |
f390d2c7 | 1838 | |
eb5d44eb | 1839 | area->t_lsp_refresh[1] = NULL; |
f390d2c7 | 1840 | if (area->is_type & IS_LEVEL_2) |
eb5d44eb | 1841 | lsp_non_pseudo_regenerate (area, 2); |
1842 | ||
f390d2c7 | 1843 | ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? |
eb5d44eb | 1844 | MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1]; |
1845 | ||
f390d2c7 | 1846 | THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area, |
1847 | isis_jitter (ref_time, MAX_AGE_JITTER)); | |
eb5d44eb | 1848 | |
eb5d44eb | 1849 | return ISIS_OK; |
1850 | } | |
1851 | ||
eb5d44eb | 1852 | /* |
1853 | * Something has changed -> regenerate LSP | |
1854 | */ | |
1855 | ||
1856 | int | |
1857 | lsp_l1_regenerate (struct thread *thread) | |
1858 | { | |
1859 | struct isis_area *area; | |
1860 | ||
1861 | area = THREAD_ARG (thread); | |
1862 | area->lsp_regenerate_pending[0] = 0; | |
1863 | ||
1864 | return lsp_non_pseudo_regenerate (area, 1); | |
1865 | } | |
1866 | ||
1867 | int | |
1868 | lsp_l2_regenerate (struct thread *thread) | |
1869 | { | |
1870 | struct isis_area *area; | |
1871 | ||
1872 | area = THREAD_ARG (thread); | |
1873 | area->lsp_regenerate_pending[1] = 0; | |
f390d2c7 | 1874 | |
eb5d44eb | 1875 | return lsp_non_pseudo_regenerate (area, 2); |
1876 | } | |
1877 | ||
f390d2c7 | 1878 | int |
eb5d44eb | 1879 | lsp_regenerate_schedule (struct isis_area *area) |
1880 | { | |
1881 | struct isis_lsp *lsp; | |
1882 | u_char id[ISIS_SYS_ID_LEN + 2]; | |
1883 | time_t now, diff; | |
f390d2c7 | 1884 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
1885 | LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0; | |
eb5d44eb | 1886 | now = time (NULL); |
1887 | /* | |
1888 | * First level 1 | |
1889 | */ | |
f390d2c7 | 1890 | if (area->is_type & IS_LEVEL_1) |
1891 | { | |
1892 | lsp = lsp_search (id, area->lspdb[0]); | |
1893 | if (!lsp || area->lsp_regenerate_pending[0]) | |
1894 | goto L2; | |
1895 | /* | |
1896 | * Throttle avoidance | |
1897 | */ | |
1898 | diff = now - lsp->last_generated; | |
1899 | if (diff < MIN_LSP_GEN_INTERVAL) | |
1900 | { | |
1901 | area->lsp_regenerate_pending[0] = 1; | |
1902 | thread_add_timer (master, lsp_l1_regenerate, area, | |
1903 | MIN_LSP_GEN_INTERVAL - diff); | |
12a5cae7 | 1904 | goto L2; |
f390d2c7 | 1905 | } |
1906 | else | |
1907 | lsp_non_pseudo_regenerate (area, 1); | |
1908 | } | |
eb5d44eb | 1909 | /* |
1910 | * then 2 | |
1911 | */ | |
f390d2c7 | 1912 | L2: |
1913 | if (area->is_type & IS_LEVEL_2) | |
1914 | { | |
1915 | lsp = lsp_search (id, area->lspdb[1]); | |
1916 | if (!lsp || area->lsp_regenerate_pending[1]) | |
1917 | return ISIS_OK; | |
1918 | /* | |
1919 | * Throttle avoidance | |
1920 | */ | |
1921 | diff = now - lsp->last_generated; | |
1922 | if (diff < MIN_LSP_GEN_INTERVAL) | |
1923 | { | |
1924 | area->lsp_regenerate_pending[1] = 1; | |
1925 | thread_add_timer (master, lsp_l2_regenerate, area, | |
1926 | MIN_LSP_GEN_INTERVAL - diff); | |
1927 | return ISIS_OK; | |
1928 | } | |
1929 | else | |
1930 | lsp_non_pseudo_regenerate (area, 2); | |
1931 | } | |
1932 | ||
1933 | return ISIS_OK; | |
eb5d44eb | 1934 | } |
1935 | ||
1936 | /* | |
1937 | * Funcs for pseudonode LSPs | |
1938 | */ | |
1939 | ||
1940 | /* | |
1941 | * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs | |
1942 | */ | |
1943 | void | |
f390d2c7 | 1944 | lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit, |
1945 | int level) | |
eb5d44eb | 1946 | { |
1947 | struct isis_adjacency *adj; | |
1948 | struct is_neigh *is_neigh; | |
1949 | struct es_neigh *es_neigh; | |
1950 | struct list *adj_list; | |
1951 | struct listnode *node; | |
1952 | struct isis_passwd *passwd; | |
1953 | ||
1954 | assert (circuit); | |
1955 | assert (circuit->circ_type == CIRCUIT_T_BROADCAST); | |
f390d2c7 | 1956 | |
eb5d44eb | 1957 | if (!circuit->u.bc.is_dr[level - 1]) |
f390d2c7 | 1958 | return; /* we are not DIS on this circuit */ |
1959 | ||
eb5d44eb | 1960 | lsp->level = level; |
1961 | if (level == 1) | |
1962 | lsp->lsp_header->lsp_bits |= IS_LEVEL_1; | |
1963 | else | |
1964 | lsp->lsp_header->lsp_bits |= IS_LEVEL_2; | |
1965 | ||
1966 | /* | |
1967 | * add self to IS neighbours | |
1968 | */ | |
f390d2c7 | 1969 | if (lsp->tlv_data.is_neighs == NULL) |
1970 | { | |
1971 | lsp->tlv_data.is_neighs = list_new (); | |
1972 | lsp->tlv_data.is_neighs->del = free_tlv; | |
1973 | } | |
eb5d44eb | 1974 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
1975 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1976 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); | |
1977 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); | |
f390d2c7 | 1978 | |
1979 | adj_list = list_new (); | |
1980 | isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list); | |
1981 | ||
1982 | for (node = listhead (adj_list); node; nextnode (node)) | |
1983 | { | |
1984 | adj = getdata (node); | |
1985 | if (adj->circuit_t & level) | |
1986 | { | |
1987 | if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) || | |
1988 | (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS && | |
1989 | adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
1990 | (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) | |
1991 | { | |
1992 | /* an IS neighbour -> add it */ | |
1993 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); | |
1994 | memset (is_neigh, 0, sizeof (struct is_neigh)); | |
1995 | memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN); | |
1996 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); | |
1997 | } | |
1998 | else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES) | |
1999 | { | |
2000 | /* an ES neigbour add it, if we are building level 1 LSP */ | |
2001 | /* FIXME: the tlv-format is hard to use here */ | |
2002 | if (lsp->tlv_data.es_neighs == NULL) | |
2003 | { | |
2004 | lsp->tlv_data.es_neighs = list_new (); | |
2005 | lsp->tlv_data.es_neighs->del = free_tlv; | |
2006 | } | |
2007 | es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh)); | |
2008 | memset (es_neigh, 0, sizeof (struct es_neigh)); | |
2009 | memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN); | |
2010 | listnode_add (lsp->tlv_data.es_neighs, is_neigh); | |
2011 | } | |
2012 | } | |
eb5d44eb | 2013 | } |
f390d2c7 | 2014 | |
eb5d44eb | 2015 | stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
2016 | /* | |
2017 | * Add the authentication info if it's present | |
2018 | */ | |
f390d2c7 | 2019 | (level == 1) ? (passwd = &circuit->area->area_passwd) : |
2020 | (passwd = &circuit->area->domain_passwd); | |
2021 | if (passwd->type) | |
2022 | { | |
2023 | memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd)); | |
2024 | tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu); | |
2025 | } | |
eb5d44eb | 2026 | |
2027 | if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0) | |
2028 | tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu); | |
2029 | ||
2030 | if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0) | |
2031 | tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu); | |
2032 | ||
2033 | lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu)); | |
f390d2c7 | 2034 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, |
2035 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); | |
2036 | ||
eb5d44eb | 2037 | list_delete (adj_list); |
2038 | ||
2039 | return; | |
2040 | } | |
2041 | ||
2042 | int | |
2043 | lsp_pseudo_regenerate (struct isis_circuit *circuit, int level) | |
2044 | { | |
2045 | dict_t *lspdb = circuit->area->lspdb[level - 1]; | |
2046 | struct isis_lsp *lsp; | |
2047 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; | |
f390d2c7 | 2048 | |
eb5d44eb | 2049 | memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
f390d2c7 | 2050 | LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id; |
2051 | LSP_FRAGMENT (lsp_id) = 0; | |
2052 | ||
eb5d44eb | 2053 | lsp = lsp_search (lsp_id, lspdb); |
f390d2c7 | 2054 | |
2055 | if (!lsp) | |
2056 | { | |
2057 | zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level, | |
2058 | rawlspid_print (lsp_id)); | |
2059 | return ISIS_ERROR; | |
2060 | } | |
2061 | lsp_clear_data (lsp); | |
eb5d44eb | 2062 | |
2063 | lsp_build_pseudo (lsp, circuit, level); | |
2064 | ||
f390d2c7 | 2065 | lsp->lsp_header->rem_lifetime = |
eb5d44eb | 2066 | htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1], |
f390d2c7 | 2067 | MAX_AGE_JITTER)); |
eb5d44eb | 2068 | |
2069 | lsp_inc_seqnum (lsp, 0); | |
f390d2c7 | 2070 | |
2071 | if (isis->debugs & DEBUG_UPDATE_PACKETS) | |
2072 | { | |
2073 | zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s", | |
2074 | circuit->area->area_tag, level, | |
2075 | rawlspid_print (lsp->lsp_header->lsp_id)); | |
2076 | } | |
eb5d44eb | 2077 | |
2078 | lsp->last_generated = time (NULL); | |
2079 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
f390d2c7 | 2080 | |
eb5d44eb | 2081 | return ISIS_OK; |
2082 | } | |
2083 | ||
eb5d44eb | 2084 | int |
2085 | lsp_l1_refresh_pseudo (struct thread *thread) | |
2086 | { | |
2087 | struct isis_circuit *circuit; | |
2088 | int retval; | |
2089 | unsigned long ref_time; | |
2090 | ||
f390d2c7 | 2091 | circuit = THREAD_ARG (thread); |
2092 | ||
eb5d44eb | 2093 | if (!circuit->u.bc.is_dr[0]) |
f390d2c7 | 2094 | return ISIS_ERROR; /* FIXME: purge and such */ |
2095 | ||
13c48f72 | 2096 | circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL; |
2097 | ||
eb5d44eb | 2098 | retval = lsp_pseudo_regenerate (circuit, 1); |
f390d2c7 | 2099 | |
2100 | ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? | |
eb5d44eb | 2101 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0]; |
2102 | ||
f390d2c7 | 2103 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0], |
2104 | lsp_l1_refresh_pseudo, circuit, | |
2105 | isis_jitter (ref_time, MAX_AGE_JITTER)); | |
2106 | ||
eb5d44eb | 2107 | return retval; |
2108 | } | |
2109 | ||
f390d2c7 | 2110 | int |
eb5d44eb | 2111 | lsp_l1_pseudo_generate (struct isis_circuit *circuit) |
2112 | { | |
2113 | struct isis_lsp *lsp; | |
2114 | u_char id[ISIS_SYS_ID_LEN + 2]; | |
2115 | unsigned long ref_time; | |
2116 | ||
f390d2c7 | 2117 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
2118 | LSP_FRAGMENT (id) = 0; | |
2119 | LSP_PSEUDO_ID (id) = circuit->circuit_id; | |
eb5d44eb | 2120 | |
2121 | /* | |
2122 | * If for some reason have a pseudo LSP in the db already -> regenerate | |
2123 | */ | |
2124 | if (lsp_search (id, circuit->area->lspdb[0])) | |
2125 | return lsp_pseudo_regenerate (circuit, 1); | |
2126 | lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0], | |
f390d2c7 | 2127 | 1, circuit->area->is_type, 0, 1); |
2128 | ||
eb5d44eb | 2129 | lsp_build_pseudo (lsp, circuit, 1); |
f390d2c7 | 2130 | |
eb5d44eb | 2131 | lsp->own_lsp = 1; |
2132 | lsp_insert (lsp, circuit->area->lspdb[0]); | |
2133 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
2134 | ||
f390d2c7 | 2135 | ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? |
eb5d44eb | 2136 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0]; |
2137 | ||
f390d2c7 | 2138 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0], |
2139 | lsp_l1_refresh_pseudo, circuit, | |
2140 | isis_jitter (ref_time, MAX_AGE_JITTER)); | |
eb5d44eb | 2141 | |
2142 | return lsp_regenerate_schedule (circuit->area); | |
2143 | } | |
2144 | ||
2145 | int | |
2146 | lsp_l2_refresh_pseudo (struct thread *thread) | |
2147 | { | |
2148 | struct isis_circuit *circuit; | |
2149 | int retval; | |
2150 | unsigned long ref_time; | |
f390d2c7 | 2151 | circuit = THREAD_ARG (thread); |
2152 | ||
eb5d44eb | 2153 | if (!circuit->u.bc.is_dr[1]) |
f390d2c7 | 2154 | return ISIS_ERROR; /* FIXME: purge and such */ |
2155 | ||
13c48f72 | 2156 | circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL; |
2157 | ||
eb5d44eb | 2158 | retval = lsp_pseudo_regenerate (circuit, 2); |
2159 | ||
f390d2c7 | 2160 | ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? |
eb5d44eb | 2161 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1]; |
2162 | ||
f390d2c7 | 2163 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1], |
2164 | lsp_l2_refresh_pseudo, circuit, | |
2165 | isis_jitter (ref_time, MAX_AGE_JITTER)); | |
eb5d44eb | 2166 | |
eb5d44eb | 2167 | return retval; |
2168 | } | |
2169 | ||
f390d2c7 | 2170 | int |
eb5d44eb | 2171 | lsp_l2_pseudo_generate (struct isis_circuit *circuit) |
2172 | { | |
2173 | struct isis_lsp *lsp; | |
2174 | u_char id[ISIS_SYS_ID_LEN + 2]; | |
2175 | unsigned long ref_time; | |
2176 | ||
f390d2c7 | 2177 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
2178 | LSP_FRAGMENT (id) = 0; | |
2179 | LSP_PSEUDO_ID (id) = circuit->circuit_id; | |
eb5d44eb | 2180 | |
2181 | if (lsp_search (id, circuit->area->lspdb[1])) | |
2182 | return lsp_pseudo_regenerate (circuit, 2); | |
2183 | ||
2184 | lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1], | |
f390d2c7 | 2185 | 1, circuit->area->is_type, 0, 2); |
eb5d44eb | 2186 | |
2187 | lsp_build_pseudo (lsp, circuit, 2); | |
f390d2c7 | 2188 | |
2189 | ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? | |
eb5d44eb | 2190 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1]; |
2191 | ||
2192 | ||
2193 | lsp->own_lsp = 1; | |
2194 | lsp_insert (lsp, circuit->area->lspdb[1]); | |
2195 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
eb5d44eb | 2196 | |
f390d2c7 | 2197 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1], |
2198 | lsp_l2_refresh_pseudo, circuit, | |
2199 | isis_jitter (ref_time, MAX_AGE_JITTER)); | |
eb5d44eb | 2200 | |
f390d2c7 | 2201 | return lsp_regenerate_schedule (circuit->area); |
2202 | } | |
eb5d44eb | 2203 | |
2204 | /* | |
2205 | * Walk through LSPs for an area | |
2206 | * - set remaining lifetime | |
2207 | * - set LSPs with SRMflag set for sending | |
2208 | */ | |
f390d2c7 | 2209 | int |
eb5d44eb | 2210 | lsp_tick (struct thread *thread) |
2211 | { | |
2212 | struct isis_area *area; | |
2213 | struct isis_circuit *circuit; | |
2214 | struct isis_lsp *lsp; | |
2215 | struct list *lsp_list; | |
2216 | struct listnode *lspnode, *cnode; | |
2217 | dnode_t *dnode, *dnode_next; | |
2218 | int level; | |
2219 | ||
2220 | lsp_list = list_new (); | |
f390d2c7 | 2221 | |
eb5d44eb | 2222 | area = THREAD_ARG (thread); |
2223 | assert (area); | |
13c48f72 | 2224 | area->t_tick = NULL; |
f390d2c7 | 2225 | THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1); |
eb5d44eb | 2226 | |
2227 | /* | |
2228 | * Build a list of LSPs with (any) SRMflag set | |
2229 | * and removed the ones that have aged out | |
2230 | */ | |
f390d2c7 | 2231 | for (level = 0; level < ISIS_LEVELS; level++) |
2232 | { | |
2233 | if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0) | |
2234 | { | |
2235 | dnode = dict_first (area->lspdb[level]); | |
2236 | while (dnode != NULL) | |
2237 | { | |
2238 | dnode_next = dict_next (area->lspdb[level], dnode); | |
2239 | lsp = dnode_get (dnode); | |
2240 | lsp_set_time (lsp); | |
2241 | if (lsp->age_out == 0) | |
2242 | { | |
2243 | ||
2244 | zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out", | |
2245 | area->area_tag, | |
2246 | lsp->level, | |
2247 | rawlspid_print (lsp->lsp_header->lsp_id), | |
2248 | ntohl (lsp->lsp_header->seq_num)); | |
2249 | ||
2250 | lsp_destroy (lsp); | |
2251 | dict_delete (area->lspdb[level], dnode); | |
2252 | } | |
2253 | else if (flags_any_set (lsp->SRMflags)) | |
2254 | listnode_add (lsp_list, lsp); | |
2255 | dnode = dnode_next; | |
2256 | } | |
2257 | ||
2258 | /* | |
2259 | * Send LSPs on circuits indicated by the SRMflags | |
2260 | */ | |
2261 | if (listcount (lsp_list) > 0) | |
2262 | { | |
2263 | for (cnode = listhead (area->circuit_list); cnode; | |
2264 | nextnode (cnode)) | |
2265 | { | |
2266 | circuit = getdata (cnode); | |
2267 | for (lspnode = listhead (lsp_list); lspnode; | |
2268 | nextnode (lspnode)) | |
2269 | { | |
2270 | lsp = getdata (lspnode); | |
2271 | if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) | |
2272 | { | |
2273 | /* FIXME: if same or elder lsp is already in lsp | |
2274 | * queue */ | |
2275 | listnode_add (circuit->lsp_queue, lsp); | |
2276 | thread_add_event (master, send_lsp, circuit, 0); | |
2277 | } | |
2278 | } | |
2279 | } | |
2280 | } | |
2281 | list_delete_all_node (lsp_list); | |
2282 | } | |
eb5d44eb | 2283 | } |
eb5d44eb | 2284 | |
2285 | list_delete (lsp_list); | |
2286 | ||
2287 | return ISIS_OK; | |
2288 | } | |
2289 | ||
eb5d44eb | 2290 | void |
f390d2c7 | 2291 | lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level) |
eb5d44eb | 2292 | { |
2293 | struct isis_lsp *lsp; | |
f390d2c7 | 2294 | |
eb5d44eb | 2295 | lsp = lsp_search (id, circuit->area->lspdb[level - 1]); |
f390d2c7 | 2296 | |
2297 | if (lsp && lsp->purged == 0) | |
2298 | { | |
2299 | lsp->lsp_header->rem_lifetime = htons (0); | |
2300 | lsp->lsp_header->pdu_len = | |
2301 | htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); | |
2302 | lsp->purged = 0; | |
2303 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, | |
2304 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); | |
2305 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
2306 | } | |
2307 | ||
eb5d44eb | 2308 | return; |
2309 | } | |
2310 | ||
2311 | /* | |
2312 | * Purge own LSP that is received and we don't have. | |
2313 | * -> Do as in 7.3.16.4 | |
2314 | */ | |
2315 | void | |
f390d2c7 | 2316 | lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr, |
2317 | struct isis_area *area) | |
eb5d44eb | 2318 | { |
2319 | struct isis_lsp *lsp; | |
2320 | ||
2321 | /* | |
2322 | * We need to create the LSP to be purged | |
2323 | */ | |
2324 | zlog_info ("LSP PURGE NON EXIST"); | |
2325 | lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp)); | |
2326 | memset (lsp, 0, sizeof (struct isis_lsp)); | |
f390d2c7 | 2327 | /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */ |
2328 | /*did smt here, maybe good probably not */ | |
eb5d44eb | 2329 | lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2; |
2330 | lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); | |
f390d2c7 | 2331 | lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu); |
eb5d44eb | 2332 | fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE |
f390d2c7 | 2333 | : L2_LINK_STATE); |
2334 | lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) + | |
2335 | ISIS_FIXED_HDR_LEN); | |
eb5d44eb | 2336 | memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN); |
f390d2c7 | 2337 | |
eb5d44eb | 2338 | /* |
2339 | * Retain only LSP header | |
2340 | */ | |
2341 | lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); | |
2342 | /* | |
2343 | * Set the remaining lifetime to 0 | |
2344 | */ | |
2345 | lsp->lsp_header->rem_lifetime = 0; | |
2346 | /* | |
2347 | * Put the lsp into LSPdb | |
2348 | */ | |
f390d2c7 | 2349 | lsp_insert (lsp, area->lspdb[lsp->level - 1]); |
eb5d44eb | 2350 | |
2351 | /* | |
2352 | * Send in to whole area | |
2353 | */ | |
2354 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
f390d2c7 | 2355 | |
eb5d44eb | 2356 | return; |
2357 | } | |
2358 | ||
2359 | #ifdef TOPOLOGY_GENERATE | |
2360 | int | |
2361 | top_lsp_refresh (struct thread *thread) | |
2362 | { | |
f390d2c7 | 2363 | struct isis_lsp *lsp; |
eb5d44eb | 2364 | |
2365 | lsp = THREAD_ARG (thread); | |
2366 | assert (lsp); | |
2367 | ||
2368 | lsp->t_lsp_top_ref = NULL; | |
2369 | ||
f390d2c7 | 2370 | lsp->lsp_header->rem_lifetime = |
2371 | htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER)); | |
2372 | lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1); | |
eb5d44eb | 2373 | |
2374 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
f390d2c7 | 2375 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
2376 | { | |
2377 | zlog_info ("ISIS-Upd (): refreshing Topology L1 %s", | |
2378 | rawlspid_print (lsp->lsp_header->lsp_id)); | |
2379 | } | |
eb5d44eb | 2380 | |
2381 | /* time to calculate our checksum */ | |
2382 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, | |
f390d2c7 | 2383 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
2384 | THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp, | |
2385 | isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER)); | |
eb5d44eb | 2386 | |
2387 | return ISIS_OK; | |
2388 | } | |
2389 | ||
2390 | void | |
2391 | generate_topology_lsps (struct isis_area *area) | |
2392 | { | |
2393 | struct listnode *node; | |
2394 | int i, max = 0; | |
2395 | struct arc *arc; | |
2396 | u_char lspid[ISIS_SYS_ID_LEN + 2]; | |
2397 | struct isis_lsp *lsp; | |
2398 | ||
2399 | /* first we find the maximal node */ | |
f390d2c7 | 2400 | LIST_LOOP (area->topology, arc, node) |
2401 | { | |
2402 | if (arc->from_node > max) | |
2403 | max = arc->from_node; | |
2404 | if (arc->to_node > max) | |
2405 | max = arc->to_node; | |
eb5d44eb | 2406 | } |
2407 | ||
f390d2c7 | 2408 | for (i = 1; i < (max + 1); i++) |
2409 | { | |
2410 | memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN); | |
2411 | LSP_PSEUDO_ID (lspid) = 0x00; | |
2412 | LSP_FRAGMENT (lspid) = 0x00; | |
2413 | lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF); | |
2414 | lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF); | |
2415 | ||
2416 | lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0], | |
2417 | MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, | |
2418 | 1); | |
2419 | lsp->from_topology = 1; | |
2420 | /* creating data based on topology */ | |
2421 | build_topology_lsp_data (lsp, area, i); | |
2422 | /* time to calculate our checksum */ | |
2423 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, | |
2424 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); | |
2425 | THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp, | |
2426 | isis_jitter (MAX_LSP_GEN_INTERVAL, | |
2427 | MAX_LSP_GEN_JITTER)); | |
2428 | ||
2429 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
2430 | lsp_insert (lsp, area->lspdb[0]); | |
eb5d44eb | 2431 | |
f390d2c7 | 2432 | } |
eb5d44eb | 2433 | } |
2434 | ||
2435 | void | |
2436 | remove_topology_lsps (struct isis_area *area) | |
2437 | { | |
2438 | struct isis_lsp *lsp; | |
2439 | dnode_t *dnode, *dnode_next; | |
2440 | ||
2441 | dnode = dict_first (area->lspdb[0]); | |
f390d2c7 | 2442 | while (dnode != NULL) |
2443 | { | |
2444 | dnode_next = dict_next (area->lspdb[0], dnode); | |
2445 | lsp = dnode_get (dnode); | |
2446 | if (lsp->from_topology) | |
2447 | { | |
2448 | THREAD_TIMER_OFF (lsp->t_lsp_top_ref); | |
2449 | lsp_destroy (lsp); | |
2450 | dict_delete (area->lspdb[0], dnode); | |
2451 | } | |
2452 | dnode = dnode_next; | |
eb5d44eb | 2453 | } |
eb5d44eb | 2454 | } |
2455 | ||
2456 | void | |
f390d2c7 | 2457 | build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area, |
eb5d44eb | 2458 | int lsp_top_num) |
2459 | { | |
2460 | struct listnode *node; | |
2461 | struct arc *arc; | |
2462 | u_char *tlv_ptr; | |
2463 | struct is_neigh *is_neigh; | |
2464 | int to_lsp = 0; | |
2465 | char buff[200]; | |
2466 | ||
2467 | /* add our nlpids */ | |
f390d2c7 | 2468 | /* the 2 is for the TL plus 1 for the nlpid */ |
2469 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3); | |
2470 | *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */ | |
2471 | *(tlv_ptr + 1) = 1; /* one protocol */ | |
2472 | *(tlv_ptr + 2) = NLPID_IP; | |
2473 | lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1); | |
eb5d44eb | 2474 | |
2475 | /* first, lets add the tops */ | |
f390d2c7 | 2476 | /* the 2 is for the TL plus 1 for the virtual field */ |
2477 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3); | |
2478 | *tlv_ptr = IS_NEIGHBOURS; /* Type */ | |
2479 | *(tlv_ptr + 1) = 1; /* this is the virtual char len */ | |
2480 | *(tlv_ptr + 2) = 0; /* virtual is zero */ | |
2481 | lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */ | |
eb5d44eb | 2482 | |
2483 | /* add reachability for this IS for simulated 1 */ | |
f390d2c7 | 2484 | if (lsp_top_num == 1) |
2485 | { | |
eb5d44eb | 2486 | /* assign space for the is_neigh at the pdu end */ |
f390d2c7 | 2487 | is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV, |
2488 | sizeof (struct | |
2489 | is_neigh)); | |
eb5d44eb | 2490 | /* add this node to our list */ |
f390d2c7 | 2491 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); |
2492 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); | |
eb5d44eb | 2493 | LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00; |
f390d2c7 | 2494 | is_neigh->metrics.metric_default = 0x00; /* no special reason */ |
eb5d44eb | 2495 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; |
2496 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; | |
2497 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; | |
2498 | /* don't forget the length */ | |
f390d2c7 | 2499 | *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */ |
2500 | /* no need to check for fragging here, it is a lonely is_reach */ | |
eb5d44eb | 2501 | } |
eb5d44eb | 2502 | |
f390d2c7 | 2503 | /* addding is reachabilities */ |
2504 | LIST_LOOP (area->topology, arc, node) | |
2505 | { | |
2506 | if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num)) | |
2507 | { | |
2508 | if (arc->to_node == lsp_top_num) | |
2509 | to_lsp = arc->from_node; | |
2510 | if (arc->from_node == lsp_top_num) | |
2511 | to_lsp = arc->to_node; | |
2512 | ||
2513 | /* if the length here is about to cross the FF limit, we reTLV */ | |
2514 | if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN)) | |
2515 | { | |
2516 | /* retlv */ | |
2517 | /* the 2 is for the TL plus 1 for the virtual field */ | |
2518 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3); | |
2519 | *tlv_ptr = IS_NEIGHBOURS; /* Type */ | |
2520 | *(tlv_ptr + 1) = 1; /* this is the virtual char len */ | |
2521 | *(tlv_ptr + 2) = 0; /* virtual is zero */ | |
2522 | } | |
2523 | /* doing this here assures us that we won't add an "empty" tlv */ | |
2524 | /* assign space for the is_neigh at the pdu end */ | |
2525 | is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV, | |
2526 | sizeof (struct | |
2527 | is_neigh)); | |
2528 | /* add this node to our list */ | |
2529 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); | |
2530 | memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN); | |
2531 | LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00; | |
2532 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF); | |
2533 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF); | |
2534 | is_neigh->metrics.metric_default = arc->distance; | |
2535 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; | |
2536 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; | |
2537 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; | |
2538 | /* don't forget the length */ | |
2539 | *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */ | |
2540 | } | |
eb5d44eb | 2541 | } |
2542 | ||
f390d2c7 | 2543 | /* adding dynamic hostname if needed */ |
2544 | if (area->dynhostname) | |
2545 | { | |
2546 | memset (buff, 0x00, 200); | |
2547 | sprintf (buff, "feedme%d", lsp_top_num); | |
2548 | /* the 2 is for the TL */ | |
2549 | tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); | |
2550 | *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */ | |
2551 | *(tlv_ptr + 1) = strlen (buff); /* Length */ | |
2552 | /* the -1 is to fit the length in the struct */ | |
2553 | lsp->tlv_data.hostname = (struct hostname *) | |
2554 | (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1); | |
2555 | memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff)); | |
2556 | } | |
2557 | ||
eb5d44eb | 2558 | /* thanks to hannes, another bug bites the dust */ |
f390d2c7 | 2559 | lsp->pdu->putp = ntohs (lsp->lsp_header->pdu_len); |
2560 | lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len); | |
eb5d44eb | 2561 | } |
2562 | #endif /* TOPOLOGY_GENERATE */ |