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