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