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