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