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