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