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