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