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); |
| 1202 | te_ipreach->te_metric = htonl (*circuit->te_metric); |
| 1203 | te_ipreach->control = (ipv4->prefixlen & 0x3F); |
| 1204 | memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr, |
| 1205 | (ipv4->prefixlen + 7)/8); |
| 1206 | listnode_add (tlv_data.te_ipv4_reachs, te_ipreach); |
| 1207 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1208 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1209 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1210 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1211 | /* |
| 1212 | * Add IPv6 reachability of this circuit |
| 1213 | */ |
| 1214 | if (circuit->ipv6_router && circuit->ipv6_non_link && |
| 1215 | circuit->ipv6_non_link->count > 0) |
| 1216 | { |
| 1217 | |
| 1218 | if (tlv_data.ipv6_reachs == NULL) |
| 1219 | { |
| 1220 | tlv_data.ipv6_reachs = list_new (); |
hasso | be7d65d | 2005-09-02 01:38:16 +0000 | [diff] [blame] | 1221 | tlv_data.ipv6_reachs->del = free_tlv; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1222 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1223 | for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode, ipnnode, |
| 1224 | ipv6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1225 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1226 | ip6reach = |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 1227 | XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1228 | ip6reach->metric = |
| 1229 | htonl (circuit->metrics[level - 1].metric_default); |
| 1230 | ip6reach->control_info = 0; |
| 1231 | ip6reach->prefix_len = ipv6->prefixlen; |
hasso | 6785157 | 2004-09-21 14:17:04 +0000 | [diff] [blame] | 1232 | memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix)); |
| 1233 | apply_mask_ipv6 (ip6prefix); |
| 1234 | memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr, |
| 1235 | sizeof (ip6reach->prefix)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1236 | listnode_add (tlv_data.ipv6_reachs, ip6reach); |
| 1237 | } |
| 1238 | } |
| 1239 | #endif /* HAVE_IPV6 */ |
| 1240 | |
| 1241 | switch (circuit->circ_type) |
| 1242 | { |
| 1243 | case CIRCUIT_T_BROADCAST: |
| 1244 | if (level & circuit->circuit_is_type) |
| 1245 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1246 | if (area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1247 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1248 | if (tlv_data.is_neighs == NULL) |
| 1249 | { |
| 1250 | tlv_data.is_neighs = list_new (); |
| 1251 | tlv_data.is_neighs->del = free_tlv; |
| 1252 | } |
| 1253 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
| 1254 | if (level == 1) |
| 1255 | memcpy (is_neigh->neigh_id, |
| 1256 | circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1257 | else |
| 1258 | memcpy (is_neigh->neigh_id, |
| 1259 | circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1260 | is_neigh->metrics = circuit->metrics[level - 1]; |
| 1261 | listnode_add (tlv_data.is_neighs, is_neigh); |
hasso | be7d65d | 2005-09-02 01:38:16 +0000 | [diff] [blame] | 1262 | tlv_data.is_neighs->del = free_tlv; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1263 | } |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1264 | if (area->newmetric) |
| 1265 | { |
| 1266 | uint32_t metric; |
| 1267 | |
| 1268 | if (tlv_data.te_is_neighs == NULL) |
| 1269 | { |
| 1270 | tlv_data.te_is_neighs = list_new (); |
| 1271 | tlv_data.te_is_neighs->del = free_tlv; |
| 1272 | } |
| 1273 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, |
| 1274 | sizeof (struct te_is_neigh)); |
| 1275 | if (level == 1) |
| 1276 | memcpy (te_is_neigh->neigh_id, |
| 1277 | circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1278 | else |
| 1279 | memcpy (te_is_neigh->neigh_id, |
| 1280 | circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1281 | metric = ((htonl(*circuit->te_metric) >> 8) & 0xffffff); |
| 1282 | memcpy (te_is_neigh->te_metric, &metric, 3); |
| 1283 | listnode_add (tlv_data.te_is_neighs, te_is_neigh); |
| 1284 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1285 | } |
| 1286 | break; |
| 1287 | case CIRCUIT_T_P2P: |
| 1288 | nei = circuit->u.p2p.neighbor; |
| 1289 | if (nei && (level & nei->circuit_t)) |
| 1290 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1291 | if (area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1292 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1293 | if (tlv_data.is_neighs == NULL) |
| 1294 | { |
| 1295 | tlv_data.is_neighs = list_new (); |
| 1296 | tlv_data.is_neighs->del = free_tlv; |
| 1297 | } |
| 1298 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
| 1299 | memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN); |
| 1300 | is_neigh->metrics = circuit->metrics[level - 1]; |
| 1301 | listnode_add (tlv_data.is_neighs, is_neigh); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1302 | } |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1303 | if (area->newmetric) |
| 1304 | { |
| 1305 | uint32_t metric; |
| 1306 | |
| 1307 | if (tlv_data.te_is_neighs == NULL) |
| 1308 | { |
| 1309 | tlv_data.te_is_neighs = list_new (); |
| 1310 | tlv_data.te_is_neighs->del = free_tlv; |
| 1311 | } |
| 1312 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, |
| 1313 | sizeof (struct te_is_neigh)); |
| 1314 | memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN); |
| 1315 | metric = ((htonl(*circuit->te_metric) >> 8) & 0xffffff); |
| 1316 | memcpy (te_is_neigh->te_metric, &metric, 3); |
| 1317 | listnode_add (tlv_data.te_is_neighs, te_is_neigh); |
| 1318 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1319 | } |
| 1320 | break; |
| 1321 | case CIRCUIT_T_STATIC_IN: |
| 1322 | zlog_warn ("lsp_area_create: unsupported circuit type"); |
| 1323 | break; |
| 1324 | case CIRCUIT_T_STATIC_OUT: |
| 1325 | zlog_warn ("lsp_area_create: unsupported circuit type"); |
| 1326 | break; |
| 1327 | case CIRCUIT_T_DA: |
| 1328 | zlog_warn ("lsp_area_create: unsupported circuit type"); |
| 1329 | break; |
| 1330 | default: |
| 1331 | zlog_warn ("lsp_area_create: unknown circuit type"); |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs)) |
| 1336 | { |
| 1337 | if (lsp->tlv_data.ipv4_int_reachs == NULL) |
| 1338 | lsp->tlv_data.ipv4_int_reachs = list_new (); |
| 1339 | lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs, |
| 1340 | &lsp->tlv_data.ipv4_int_reachs, |
| 1341 | IPV4_REACH_LEN, area->lsp_frag_threshold, |
| 1342 | tlv_add_ipv4_reachs); |
| 1343 | if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs)) |
| 1344 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1345 | lsp0, area, level); |
| 1346 | } |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1347 | /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit() |
| 1348 | * for now. lsp_tlv_fit() needs to be fixed to deal with variable length |
| 1349 | * TLVs (sub TLVs!). */ |
| 1350 | while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs)) |
| 1351 | { |
| 1352 | if (lsp->tlv_data.te_ipv4_reachs == NULL) |
| 1353 | lsp->tlv_data.te_ipv4_reachs = list_new (); |
| 1354 | lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs, |
| 1355 | &lsp->tlv_data.te_ipv4_reachs, |
| 1356 | 9, area->lsp_frag_threshold, tlv_add_te_ipv4_reachs); |
| 1357 | if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs)) |
| 1358 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1359 | lsp0, area, level); |
| 1360 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1361 | |
| 1362 | #ifdef HAVE_IPV6 |
| 1363 | while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs)) |
| 1364 | { |
| 1365 | if (lsp->tlv_data.ipv6_reachs == NULL) |
| 1366 | lsp->tlv_data.ipv6_reachs = list_new (); |
| 1367 | lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs, |
| 1368 | &lsp->tlv_data.ipv6_reachs, |
| 1369 | IPV6_REACH_LEN, area->lsp_frag_threshold, |
| 1370 | tlv_add_ipv6_reachs); |
| 1371 | if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs)) |
| 1372 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1373 | lsp0, area, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1374 | } |
| 1375 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1376 | |
| 1377 | while (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 1378 | { |
| 1379 | if (lsp->tlv_data.is_neighs == NULL) |
| 1380 | lsp->tlv_data.is_neighs = list_new (); |
| 1381 | lsp_tlv_fit (lsp, &tlv_data.is_neighs, |
| 1382 | &lsp->tlv_data.is_neighs, |
| 1383 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 1384 | tlv_add_is_neighs); |
| 1385 | if (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 1386 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1387 | lsp0, area, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1388 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1389 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1390 | while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs)) |
| 1391 | { |
| 1392 | if (lsp->tlv_data.te_is_neighs == NULL) |
| 1393 | lsp->tlv_data.te_is_neighs = list_new (); |
| 1394 | lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs, |
| 1395 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 1396 | tlv_add_te_is_neighs); |
| 1397 | if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs)) |
| 1398 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1399 | lsp0, area, level); |
| 1400 | } |
| 1401 | |
| 1402 | free_tlvs (&tlv_data); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1403 | return; |
| 1404 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1405 | |
| 1406 | /* |
| 1407 | * 7.3.7 Generation on non-pseudonode LSPs |
| 1408 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1409 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1410 | lsp_generate_non_pseudo (struct isis_area *area, int level) |
| 1411 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1412 | struct isis_lsp *oldlsp, *newlsp; |
| 1413 | u_int32_t seq_num = 0; |
| 1414 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 1415 | |
| 1416 | memset (&lspid, 0, ISIS_SYS_ID_LEN + 2); |
| 1417 | memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN); |
| 1418 | |
| 1419 | /* only builds the lsp if the area shares the level */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1420 | if ((area->is_type & level) == level) |
| 1421 | { |
| 1422 | oldlsp = lsp_search (lspid, area->lspdb[level - 1]); |
| 1423 | if (oldlsp) |
| 1424 | { |
| 1425 | seq_num = ntohl (oldlsp->lsp_header->seq_num); |
| 1426 | lsp_search_and_destroy (oldlsp->lsp_header->lsp_id, |
| 1427 | area->lspdb[level - 1]); |
| 1428 | /* FIXME: we should actually initiate a purge */ |
| 1429 | } |
| 1430 | newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num, |
| 1431 | area->is_type, 0, level); |
| 1432 | newlsp->own_lsp = 1; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1433 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1434 | lsp_insert (newlsp, area->lspdb[level - 1]); |
| 1435 | /* build_lsp_data (newlsp, area); */ |
| 1436 | lsp_build_nonpseudo (newlsp, area); |
| 1437 | /* time to calculate our checksum */ |
| 1438 | lsp_seqnum_update (newlsp); |
| 1439 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1440 | |
| 1441 | /* DEBUG_ADJ_PACKETS */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1442 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 1443 | { |
| 1444 | /* FIXME: is this place right? fix missing info */ |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1445 | zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1446 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1447 | |
| 1448 | return ISIS_OK; |
| 1449 | } |
| 1450 | |
| 1451 | /* |
| 1452 | * 7.3.9 Generation of level 1 LSPs (non-pseudonode) |
| 1453 | */ |
| 1454 | int |
| 1455 | lsp_l1_generate (struct isis_area *area) |
| 1456 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1457 | THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area, |
| 1458 | MAX_LSP_GEN_INTERVAL); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1459 | |
| 1460 | return lsp_generate_non_pseudo (area, 1); |
| 1461 | } |
| 1462 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1463 | /* |
| 1464 | * 7.3.9 Generation of level 2 LSPs (non-pseudonode) |
| 1465 | */ |
| 1466 | int |
| 1467 | lsp_l2_generate (struct isis_area *area) |
| 1468 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1469 | THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area, |
| 1470 | MAX_LSP_GEN_INTERVAL); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1471 | |
| 1472 | return lsp_generate_non_pseudo (area, 2); |
| 1473 | } |
| 1474 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1475 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1476 | lsp_non_pseudo_regenerate (struct isis_area *area, int level) |
| 1477 | { |
| 1478 | dict_t *lspdb = area->lspdb[level - 1]; |
| 1479 | struct isis_lsp *lsp, *frag; |
| 1480 | struct listnode *node; |
| 1481 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 1482 | |
| 1483 | memset (lspid, 0, ISIS_SYS_ID_LEN + 2); |
| 1484 | memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1485 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1486 | lsp = lsp_search (lspid, lspdb); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1487 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1488 | if (!lsp) |
| 1489 | { |
| 1490 | zlog_err |
| 1491 | ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!", |
| 1492 | area->area_tag, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1493 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1494 | return ISIS_ERROR; |
| 1495 | } |
| 1496 | |
| 1497 | lsp_clear_data (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1498 | lsp_build_nonpseudo (lsp, area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1499 | lsp->lsp_header->rem_lifetime = htons (isis_jitter |
| 1500 | (area->max_lsp_lifetime[level - 1], |
| 1501 | MAX_AGE_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1502 | lsp_seqnum_update (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1503 | |
| 1504 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1505 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1506 | zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, " |
| 1507 | "seq 0x%08x, cksum 0x%04x lifetime %us", |
| 1508 | area->area_tag, |
| 1509 | level, |
| 1510 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 1511 | ntohl (lsp->lsp_header->seq_num), |
| 1512 | ntohs (lsp->lsp_header->checksum), |
| 1513 | ntohs (lsp->lsp_header->rem_lifetime)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1514 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1515 | |
| 1516 | lsp->last_generated = time (NULL); |
| 1517 | area->lsp_regenerate_pending[level - 1] = 0; |
| 1518 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1519 | for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1520 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1521 | frag->lsp_header->rem_lifetime = htons (isis_jitter |
| 1522 | (area-> |
| 1523 | max_lsp_lifetime[level - 1], |
| 1524 | MAX_AGE_JITTER)); |
| 1525 | ISIS_FLAGS_SET_ALL (frag->SRMflags); |
| 1526 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1527 | |
| 1528 | if (area->ip_circuits) |
| 1529 | isis_spf_schedule (area, level); |
| 1530 | #ifdef HAVE_IPV6 |
| 1531 | if (area->ipv6_circuits) |
| 1532 | isis_spf_schedule6 (area, level); |
| 1533 | #endif |
| 1534 | return ISIS_OK; |
| 1535 | } |
| 1536 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1537 | /* |
| 1538 | * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding |
| 1539 | * time and set SRM |
| 1540 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1541 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1542 | lsp_refresh_l1 (struct thread *thread) |
| 1543 | { |
| 1544 | struct isis_area *area; |
| 1545 | unsigned long ref_time; |
| 1546 | |
| 1547 | area = THREAD_ARG (thread); |
| 1548 | assert (area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1549 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1550 | area->t_lsp_refresh[0] = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1551 | if (area->is_type & IS_LEVEL_1) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1552 | lsp_non_pseudo_regenerate (area, 1); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1553 | |
| 1554 | ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1555 | MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0]; |
| 1556 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1557 | THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area, |
| 1558 | isis_jitter (ref_time, MAX_AGE_JITTER)); |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 1559 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1560 | return ISIS_OK; |
| 1561 | } |
| 1562 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1563 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1564 | lsp_refresh_l2 (struct thread *thread) |
| 1565 | { |
| 1566 | struct isis_area *area; |
| 1567 | unsigned long ref_time; |
| 1568 | |
| 1569 | area = THREAD_ARG (thread); |
| 1570 | assert (area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1571 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1572 | area->t_lsp_refresh[1] = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1573 | if (area->is_type & IS_LEVEL_2) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1574 | lsp_non_pseudo_regenerate (area, 2); |
| 1575 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1576 | ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1577 | MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1]; |
| 1578 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1579 | THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area, |
| 1580 | isis_jitter (ref_time, MAX_AGE_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1581 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1582 | return ISIS_OK; |
| 1583 | } |
| 1584 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1585 | /* |
| 1586 | * Something has changed -> regenerate LSP |
| 1587 | */ |
| 1588 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1589 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1590 | lsp_l1_regenerate (struct thread *thread) |
| 1591 | { |
| 1592 | struct isis_area *area; |
| 1593 | |
| 1594 | area = THREAD_ARG (thread); |
| 1595 | area->lsp_regenerate_pending[0] = 0; |
| 1596 | |
| 1597 | return lsp_non_pseudo_regenerate (area, 1); |
| 1598 | } |
| 1599 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1600 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1601 | lsp_l2_regenerate (struct thread *thread) |
| 1602 | { |
| 1603 | struct isis_area *area; |
| 1604 | |
| 1605 | area = THREAD_ARG (thread); |
| 1606 | area->lsp_regenerate_pending[1] = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1607 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1608 | return lsp_non_pseudo_regenerate (area, 2); |
| 1609 | } |
| 1610 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1611 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1612 | lsp_regenerate_schedule (struct isis_area *area) |
| 1613 | { |
| 1614 | struct isis_lsp *lsp; |
| 1615 | u_char id[ISIS_SYS_ID_LEN + 2]; |
| 1616 | time_t now, diff; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1617 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1618 | LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1619 | now = time (NULL); |
| 1620 | /* |
| 1621 | * First level 1 |
| 1622 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1623 | if (area->is_type & IS_LEVEL_1) |
| 1624 | { |
| 1625 | lsp = lsp_search (id, area->lspdb[0]); |
| 1626 | if (!lsp || area->lsp_regenerate_pending[0]) |
| 1627 | goto L2; |
| 1628 | /* |
| 1629 | * Throttle avoidance |
| 1630 | */ |
| 1631 | diff = now - lsp->last_generated; |
| 1632 | if (diff < MIN_LSP_GEN_INTERVAL) |
| 1633 | { |
| 1634 | area->lsp_regenerate_pending[0] = 1; |
| 1635 | thread_add_timer (master, lsp_l1_regenerate, area, |
| 1636 | MIN_LSP_GEN_INTERVAL - diff); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1637 | goto L2; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1638 | } |
| 1639 | else |
| 1640 | lsp_non_pseudo_regenerate (area, 1); |
| 1641 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1642 | /* |
| 1643 | * then 2 |
| 1644 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1645 | L2: |
| 1646 | if (area->is_type & IS_LEVEL_2) |
| 1647 | { |
| 1648 | lsp = lsp_search (id, area->lspdb[1]); |
| 1649 | if (!lsp || area->lsp_regenerate_pending[1]) |
| 1650 | return ISIS_OK; |
| 1651 | /* |
| 1652 | * Throttle avoidance |
| 1653 | */ |
| 1654 | diff = now - lsp->last_generated; |
| 1655 | if (diff < MIN_LSP_GEN_INTERVAL) |
| 1656 | { |
| 1657 | area->lsp_regenerate_pending[1] = 1; |
| 1658 | thread_add_timer (master, lsp_l2_regenerate, area, |
| 1659 | MIN_LSP_GEN_INTERVAL - diff); |
| 1660 | return ISIS_OK; |
| 1661 | } |
| 1662 | else |
| 1663 | lsp_non_pseudo_regenerate (area, 2); |
| 1664 | } |
| 1665 | |
| 1666 | return ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | /* |
| 1670 | * Funcs for pseudonode LSPs |
| 1671 | */ |
| 1672 | |
| 1673 | /* |
| 1674 | * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs |
| 1675 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1676 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1677 | lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit, |
| 1678 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1679 | { |
| 1680 | struct isis_adjacency *adj; |
| 1681 | struct is_neigh *is_neigh; |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1682 | struct te_is_neigh *te_is_neigh; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1683 | struct es_neigh *es_neigh; |
| 1684 | struct list *adj_list; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1685 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1686 | struct isis_passwd *passwd; |
| 1687 | |
| 1688 | assert (circuit); |
| 1689 | assert (circuit->circ_type == CIRCUIT_T_BROADCAST); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1690 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1691 | if (!circuit->u.bc.is_dr[level - 1]) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1692 | return; /* we are not DIS on this circuit */ |
| 1693 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1694 | lsp->level = level; |
| 1695 | if (level == 1) |
| 1696 | lsp->lsp_header->lsp_bits |= IS_LEVEL_1; |
| 1697 | else |
| 1698 | lsp->lsp_header->lsp_bits |= IS_LEVEL_2; |
| 1699 | |
| 1700 | /* |
| 1701 | * add self to IS neighbours |
| 1702 | */ |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1703 | if (circuit->area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1704 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1705 | if (lsp->tlv_data.is_neighs == NULL) |
| 1706 | { |
| 1707 | lsp->tlv_data.is_neighs = list_new (); |
| 1708 | lsp->tlv_data.is_neighs->del = free_tlv; |
| 1709 | } |
| 1710 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1711 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1712 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1713 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); |
| 1714 | } |
| 1715 | if (circuit->area->newmetric) |
| 1716 | { |
| 1717 | if (lsp->tlv_data.te_is_neighs == NULL) |
| 1718 | { |
| 1719 | lsp->tlv_data.te_is_neighs = list_new (); |
| 1720 | lsp->tlv_data.te_is_neighs->del = free_tlv; |
| 1721 | } |
| 1722 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh)); |
| 1723 | |
| 1724 | memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1725 | listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh); |
| 1726 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1727 | |
| 1728 | adj_list = list_new (); |
| 1729 | isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list); |
| 1730 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1731 | for (ALL_LIST_ELEMENTS (adj_list, node, nnode, adj)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1732 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1733 | if (adj->circuit_t & level) |
| 1734 | { |
| 1735 | if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) || |
| 1736 | (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS && |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1737 | adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1738 | (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) |
| 1739 | { |
| 1740 | /* an IS neighbour -> add it */ |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1741 | if (circuit->area->oldmetric) |
| 1742 | { |
| 1743 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1744 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1745 | memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 1746 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); |
| 1747 | } |
| 1748 | if (circuit->area->newmetric) |
| 1749 | { |
| 1750 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, |
| 1751 | sizeof (struct te_is_neigh)); |
| 1752 | memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 1753 | listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh); |
| 1754 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1755 | } |
| 1756 | else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES) |
| 1757 | { |
| 1758 | /* an ES neigbour add it, if we are building level 1 LSP */ |
| 1759 | /* FIXME: the tlv-format is hard to use here */ |
| 1760 | if (lsp->tlv_data.es_neighs == NULL) |
| 1761 | { |
| 1762 | lsp->tlv_data.es_neighs = list_new (); |
| 1763 | lsp->tlv_data.es_neighs->del = free_tlv; |
| 1764 | } |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1765 | es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh)); |
| 1766 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1767 | memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN); |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 1768 | listnode_add (lsp->tlv_data.es_neighs, es_neigh); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1769 | } |
| 1770 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1771 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1772 | |
hasso | c0fb2a5 | 2005-09-03 16:29:40 +0000 | [diff] [blame] | 1773 | /* Reset endp of stream to overwrite only TLV part of it. */ |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 1774 | stream_reset (lsp->pdu); |
hasso | c0fb2a5 | 2005-09-03 16:29:40 +0000 | [diff] [blame] | 1775 | stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 1776 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1777 | /* |
| 1778 | * Add the authentication info if it's present |
| 1779 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1780 | (level == 1) ? (passwd = &circuit->area->area_passwd) : |
| 1781 | (passwd = &circuit->area->domain_passwd); |
| 1782 | if (passwd->type) |
| 1783 | { |
| 1784 | memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd)); |
| 1785 | tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu); |
| 1786 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1787 | |
| 1788 | if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0) |
| 1789 | tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu); |
| 1790 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1791 | if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0) |
| 1792 | tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu); |
| 1793 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1794 | if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0) |
| 1795 | tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu); |
| 1796 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 1797 | lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1798 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, |
| 1799 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
| 1800 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1801 | list_delete (adj_list); |
| 1802 | |
| 1803 | return; |
| 1804 | } |
| 1805 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1806 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1807 | lsp_pseudo_regenerate (struct isis_circuit *circuit, int level) |
| 1808 | { |
| 1809 | dict_t *lspdb = circuit->area->lspdb[level - 1]; |
| 1810 | struct isis_lsp *lsp; |
| 1811 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1812 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1813 | memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1814 | LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id; |
| 1815 | LSP_FRAGMENT (lsp_id) = 0; |
| 1816 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1817 | lsp = lsp_search (lsp_id, lspdb); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1818 | |
| 1819 | if (!lsp) |
| 1820 | { |
| 1821 | zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level, |
| 1822 | rawlspid_print (lsp_id)); |
| 1823 | return ISIS_ERROR; |
| 1824 | } |
| 1825 | lsp_clear_data (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1826 | |
| 1827 | lsp_build_pseudo (lsp, circuit, level); |
| 1828 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1829 | lsp->lsp_header->rem_lifetime = |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1830 | htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1], |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1831 | MAX_AGE_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1832 | |
| 1833 | lsp_inc_seqnum (lsp, 0); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1834 | |
| 1835 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1836 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1837 | zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s", |
| 1838 | circuit->area->area_tag, level, |
| 1839 | rawlspid_print (lsp->lsp_header->lsp_id)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1840 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1841 | |
| 1842 | lsp->last_generated = time (NULL); |
| 1843 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1844 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1845 | return ISIS_OK; |
| 1846 | } |
| 1847 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1848 | int |
| 1849 | lsp_l1_refresh_pseudo (struct thread *thread) |
| 1850 | { |
| 1851 | struct isis_circuit *circuit; |
| 1852 | int retval; |
| 1853 | unsigned long ref_time; |
| 1854 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1855 | circuit = THREAD_ARG (thread); |
| 1856 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1857 | if (!circuit->u.bc.is_dr[0]) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1858 | return ISIS_ERROR; /* FIXME: purge and such */ |
| 1859 | |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 1860 | circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL; |
| 1861 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1862 | retval = lsp_pseudo_regenerate (circuit, 1); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1863 | |
| 1864 | ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1865 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0]; |
| 1866 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1867 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0], |
| 1868 | lsp_l1_refresh_pseudo, circuit, |
| 1869 | isis_jitter (ref_time, MAX_AGE_JITTER)); |
| 1870 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1871 | return retval; |
| 1872 | } |
| 1873 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1874 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1875 | lsp_l1_pseudo_generate (struct isis_circuit *circuit) |
| 1876 | { |
| 1877 | struct isis_lsp *lsp; |
| 1878 | u_char id[ISIS_SYS_ID_LEN + 2]; |
| 1879 | unsigned long ref_time; |
| 1880 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1881 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1882 | LSP_FRAGMENT (id) = 0; |
| 1883 | LSP_PSEUDO_ID (id) = circuit->circuit_id; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1884 | |
| 1885 | /* |
| 1886 | * If for some reason have a pseudo LSP in the db already -> regenerate |
| 1887 | */ |
| 1888 | if (lsp_search (id, circuit->area->lspdb[0])) |
| 1889 | return lsp_pseudo_regenerate (circuit, 1); |
| 1890 | lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0], |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1891 | 1, circuit->area->is_type, 0, 1); |
| 1892 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1893 | lsp_build_pseudo (lsp, circuit, 1); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1894 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1895 | lsp->own_lsp = 1; |
| 1896 | lsp_insert (lsp, circuit->area->lspdb[0]); |
| 1897 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 1898 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1899 | ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1900 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0]; |
| 1901 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1902 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0], |
| 1903 | lsp_l1_refresh_pseudo, circuit, |
| 1904 | isis_jitter (ref_time, MAX_AGE_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1905 | |
| 1906 | return lsp_regenerate_schedule (circuit->area); |
| 1907 | } |
| 1908 | |
| 1909 | int |
| 1910 | lsp_l2_refresh_pseudo (struct thread *thread) |
| 1911 | { |
| 1912 | struct isis_circuit *circuit; |
| 1913 | int retval; |
| 1914 | unsigned long ref_time; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1915 | circuit = THREAD_ARG (thread); |
| 1916 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1917 | if (!circuit->u.bc.is_dr[1]) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1918 | return ISIS_ERROR; /* FIXME: purge and such */ |
| 1919 | |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 1920 | circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL; |
| 1921 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1922 | retval = lsp_pseudo_regenerate (circuit, 2); |
| 1923 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1924 | ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1925 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1]; |
| 1926 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1927 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1], |
| 1928 | lsp_l2_refresh_pseudo, circuit, |
| 1929 | isis_jitter (ref_time, MAX_AGE_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1930 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1931 | return retval; |
| 1932 | } |
| 1933 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1934 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1935 | lsp_l2_pseudo_generate (struct isis_circuit *circuit) |
| 1936 | { |
| 1937 | struct isis_lsp *lsp; |
| 1938 | u_char id[ISIS_SYS_ID_LEN + 2]; |
| 1939 | unsigned long ref_time; |
| 1940 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1941 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1942 | LSP_FRAGMENT (id) = 0; |
| 1943 | LSP_PSEUDO_ID (id) = circuit->circuit_id; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1944 | |
| 1945 | if (lsp_search (id, circuit->area->lspdb[1])) |
| 1946 | return lsp_pseudo_regenerate (circuit, 2); |
| 1947 | |
| 1948 | lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1], |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1949 | 1, circuit->area->is_type, 0, 2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1950 | |
| 1951 | lsp_build_pseudo (lsp, circuit, 2); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1952 | |
| 1953 | ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1954 | MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1]; |
| 1955 | |
| 1956 | |
| 1957 | lsp->own_lsp = 1; |
| 1958 | lsp_insert (lsp, circuit->area->lspdb[1]); |
| 1959 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1960 | |
| 1961 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1], |
| 1962 | lsp_l2_refresh_pseudo, circuit, |
| 1963 | isis_jitter (ref_time, MAX_AGE_JITTER)); |
| 1964 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1965 | return lsp_regenerate_schedule (circuit->area); |
| 1966 | } |
| 1967 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1968 | /* |
| 1969 | * Walk through LSPs for an area |
| 1970 | * - set remaining lifetime |
| 1971 | * - set LSPs with SRMflag set for sending |
| 1972 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1973 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1974 | lsp_tick (struct thread *thread) |
| 1975 | { |
| 1976 | struct isis_area *area; |
| 1977 | struct isis_circuit *circuit; |
| 1978 | struct isis_lsp *lsp; |
| 1979 | struct list *lsp_list; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1980 | struct listnode *lspnode, *lspnnode, *cnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1981 | dnode_t *dnode, *dnode_next; |
| 1982 | int level; |
| 1983 | |
| 1984 | lsp_list = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1985 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1986 | area = THREAD_ARG (thread); |
| 1987 | assert (area); |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 1988 | area->t_tick = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1989 | THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1990 | |
| 1991 | /* |
| 1992 | * Build a list of LSPs with (any) SRMflag set |
| 1993 | * and removed the ones that have aged out |
| 1994 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1995 | for (level = 0; level < ISIS_LEVELS; level++) |
| 1996 | { |
| 1997 | if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0) |
| 1998 | { |
| 1999 | dnode = dict_first (area->lspdb[level]); |
| 2000 | while (dnode != NULL) |
| 2001 | { |
| 2002 | dnode_next = dict_next (area->lspdb[level], dnode); |
| 2003 | lsp = dnode_get (dnode); |
| 2004 | lsp_set_time (lsp); |
| 2005 | if (lsp->age_out == 0) |
| 2006 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2007 | |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2008 | zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out", |
| 2009 | area->area_tag, |
| 2010 | lsp->level, |
| 2011 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2012 | ntohl (lsp->lsp_header->seq_num)); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2013 | #ifdef TOPOLOGY_GENERATE |
| 2014 | if (lsp->from_topology) |
| 2015 | THREAD_TIMER_OFF (lsp->t_lsp_top_ref); |
| 2016 | #endif /* TOPOLOGY_GENERATE */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2017 | lsp_destroy (lsp); |
| 2018 | dict_delete (area->lspdb[level], dnode); |
| 2019 | } |
| 2020 | else if (flags_any_set (lsp->SRMflags)) |
| 2021 | listnode_add (lsp_list, lsp); |
| 2022 | dnode = dnode_next; |
| 2023 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2024 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2025 | /* |
| 2026 | * Send LSPs on circuits indicated by the SRMflags |
| 2027 | */ |
| 2028 | if (listcount (lsp_list) > 0) |
| 2029 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2030 | for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2031 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2032 | for (ALL_LIST_ELEMENTS (lsp_list, lspnode, lspnnode, lsp)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2033 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2034 | if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) |
| 2035 | { |
| 2036 | /* FIXME: if same or elder lsp is already in lsp |
| 2037 | * queue */ |
| 2038 | listnode_add (circuit->lsp_queue, lsp); |
| 2039 | thread_add_event (master, send_lsp, circuit, 0); |
| 2040 | } |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | list_delete_all_node (lsp_list); |
| 2045 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2046 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2047 | |
| 2048 | list_delete (lsp_list); |
| 2049 | |
| 2050 | return ISIS_OK; |
| 2051 | } |
| 2052 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2053 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2054 | lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2055 | { |
| 2056 | struct isis_lsp *lsp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2057 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2058 | lsp = lsp_search (id, circuit->area->lspdb[level - 1]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2059 | |
| 2060 | if (lsp && lsp->purged == 0) |
| 2061 | { |
| 2062 | lsp->lsp_header->rem_lifetime = htons (0); |
| 2063 | lsp->lsp_header->pdu_len = |
| 2064 | htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 2065 | lsp->purged = 0; |
| 2066 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, |
| 2067 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
| 2068 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 2069 | } |
| 2070 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2071 | return; |
| 2072 | } |
| 2073 | |
| 2074 | /* |
| 2075 | * Purge own LSP that is received and we don't have. |
| 2076 | * -> Do as in 7.3.16.4 |
| 2077 | */ |
| 2078 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2079 | lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr, |
| 2080 | struct isis_area *area) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2081 | { |
| 2082 | struct isis_lsp *lsp; |
| 2083 | |
| 2084 | /* |
| 2085 | * We need to create the LSP to be purged |
| 2086 | */ |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2087 | zlog_debug ("LSP PURGE NON EXIST"); |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 2088 | lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2089 | /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */ |
| 2090 | /*did smt here, maybe good probably not */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2091 | lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2; |
| 2092 | lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2093 | lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2094 | fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2095 | : L2_LINK_STATE); |
| 2096 | lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) + |
| 2097 | ISIS_FIXED_HDR_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2098 | memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2099 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2100 | /* |
| 2101 | * Retain only LSP header |
| 2102 | */ |
| 2103 | lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 2104 | /* |
| 2105 | * Set the remaining lifetime to 0 |
| 2106 | */ |
| 2107 | lsp->lsp_header->rem_lifetime = 0; |
| 2108 | /* |
| 2109 | * Put the lsp into LSPdb |
| 2110 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2111 | lsp_insert (lsp, area->lspdb[lsp->level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2112 | |
| 2113 | /* |
| 2114 | * Send in to whole area |
| 2115 | */ |
| 2116 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2117 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2118 | return; |
| 2119 | } |
| 2120 | |
| 2121 | #ifdef TOPOLOGY_GENERATE |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2122 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2123 | top_lsp_refresh (struct thread *thread) |
| 2124 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2125 | struct isis_lsp *lsp; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2126 | unsigned long ref_time; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2127 | |
| 2128 | lsp = THREAD_ARG (thread); |
| 2129 | assert (lsp); |
| 2130 | |
| 2131 | lsp->t_lsp_top_ref = NULL; |
| 2132 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2133 | lsp_seqnum_update (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2134 | |
| 2135 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2136 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 2137 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2138 | zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s", |
| 2139 | rawlspid_print (lsp->lsp_header->lsp_id)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2140 | } |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2141 | lsp->lsp_header->rem_lifetime = |
| 2142 | htons (isis_jitter (lsp->area->max_lsp_lifetime[0], MAX_AGE_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2143 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2144 | ref_time = lsp->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? |
| 2145 | MAX_LSP_GEN_INTERVAL : lsp->area->lsp_refresh[0]; |
| 2146 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2147 | THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp, |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2148 | isis_jitter (ref_time, MAX_LSP_GEN_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2149 | |
| 2150 | return ISIS_OK; |
| 2151 | } |
| 2152 | |
| 2153 | void |
| 2154 | generate_topology_lsps (struct isis_area *area) |
| 2155 | { |
| 2156 | struct listnode *node; |
| 2157 | int i, max = 0; |
| 2158 | struct arc *arc; |
| 2159 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 2160 | struct isis_lsp *lsp; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2161 | unsigned long ref_time; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2162 | |
| 2163 | /* first we find the maximal node */ |
paul | a8f03df | 2005-04-10 15:58:10 +0000 | [diff] [blame] | 2164 | for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2165 | { |
| 2166 | if (arc->from_node > max) |
| 2167 | max = arc->from_node; |
| 2168 | if (arc->to_node > max) |
| 2169 | max = arc->to_node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2172 | for (i = 1; i < (max + 1); i++) |
| 2173 | { |
| 2174 | memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN); |
| 2175 | LSP_PSEUDO_ID (lspid) = 0x00; |
| 2176 | LSP_FRAGMENT (lspid) = 0x00; |
| 2177 | lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF); |
| 2178 | lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2179 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2180 | lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0], |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2181 | MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, 1); |
| 2182 | if (!lsp) |
| 2183 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2184 | lsp->from_topology = 1; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2185 | lsp->area = area; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2186 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2187 | /* Creating LSP data based on topology info. */ |
| 2188 | build_topology_lsp_data (lsp, area, i); |
| 2189 | /* Checksum is also calculated here. */ |
| 2190 | lsp_seqnum_update (lsp); |
| 2191 | |
| 2192 | ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? |
| 2193 | MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0]; |
| 2194 | |
| 2195 | THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp, |
| 2196 | isis_jitter (ref_time, MAX_LSP_GEN_JITTER)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2197 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 2198 | lsp_insert (lsp, area->lspdb[0]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2199 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | void |
| 2203 | remove_topology_lsps (struct isis_area *area) |
| 2204 | { |
| 2205 | struct isis_lsp *lsp; |
| 2206 | dnode_t *dnode, *dnode_next; |
| 2207 | |
| 2208 | dnode = dict_first (area->lspdb[0]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2209 | while (dnode != NULL) |
| 2210 | { |
| 2211 | dnode_next = dict_next (area->lspdb[0], dnode); |
| 2212 | lsp = dnode_get (dnode); |
| 2213 | if (lsp->from_topology) |
| 2214 | { |
| 2215 | THREAD_TIMER_OFF (lsp->t_lsp_top_ref); |
| 2216 | lsp_destroy (lsp); |
| 2217 | dict_delete (area->lspdb[0], dnode); |
| 2218 | } |
| 2219 | dnode = dnode_next; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2220 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2224 | build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2225 | int lsp_top_num) |
| 2226 | { |
paul | a8f03df | 2005-04-10 15:58:10 +0000 | [diff] [blame] | 2227 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2228 | struct arc *arc; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2229 | struct is_neigh *is_neigh; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2230 | char buff[200]; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2231 | struct tlvs tlv_data; |
| 2232 | struct isis_lsp *lsp0 = lsp; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2233 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2234 | /* Add area addresses. FIXME: Is it needed at all? */ |
| 2235 | if (lsp->tlv_data.area_addrs == NULL) |
| 2236 | lsp->tlv_data.area_addrs = list_new (); |
| 2237 | list_add_list (lsp->tlv_data.area_addrs, area->area_addrs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2238 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2239 | if (lsp->tlv_data.nlpids == NULL) |
| 2240 | lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids)); |
| 2241 | lsp->tlv_data.nlpids->count = 1; |
| 2242 | lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2243 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2244 | if (area->dynhostname) |
| 2245 | { |
| 2246 | lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, |
| 2247 | sizeof (struct hostname)); |
| 2248 | memset (buff, 0x00, 200); |
| 2249 | sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh : |
| 2250 | "feedme", lsp_top_num); |
| 2251 | memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff)); |
| 2252 | lsp->tlv_data.hostname->namelen = strlen (buff); |
| 2253 | } |
| 2254 | |
| 2255 | if (lsp->tlv_data.nlpids) |
| 2256 | tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu); |
| 2257 | if (lsp->tlv_data.hostname) |
| 2258 | tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu); |
| 2259 | if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0) |
| 2260 | tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu); |
| 2261 | |
| 2262 | memset (&tlv_data, 0, sizeof (struct tlvs)); |
| 2263 | if (tlv_data.is_neighs == NULL) |
| 2264 | tlv_data.is_neighs = list_new (); |
| 2265 | |
| 2266 | /* Add reachability for this IS for simulated 1. */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2267 | if (lsp_top_num == 1) |
| 2268 | { |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2269 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
| 2270 | memset (is_neigh, 0, sizeof (struct is_neigh)); |
| 2271 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2272 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2273 | LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2274 | /* Metric MUST NOT be 0, unless it's not alias TLV. */ |
| 2275 | is_neigh->metrics.metric_default = 0x01; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2276 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; |
| 2277 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; |
| 2278 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2279 | listnode_add (tlv_data.is_neighs, is_neigh); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2280 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2281 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2282 | /* Add IS reachabilities. */ |
paul | a8f03df | 2005-04-10 15:58:10 +0000 | [diff] [blame] | 2283 | for (ALL_LIST_ELEMENTS (area->topology, node, nnode, arc)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2284 | { |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2285 | int to_lsp = 0; |
| 2286 | |
| 2287 | if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node)) |
| 2288 | continue; |
| 2289 | |
| 2290 | if (lsp_top_num == arc->from_node) |
| 2291 | to_lsp = arc->to_node; |
| 2292 | else |
| 2293 | to_lsp = arc->from_node; |
| 2294 | |
| 2295 | is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
| 2296 | memset (is_neigh, 0, sizeof (struct is_neigh)); |
| 2297 | |
| 2298 | memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN); |
| 2299 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF); |
| 2300 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF); |
| 2301 | is_neigh->metrics.metric_default = arc->distance; |
| 2302 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; |
| 2303 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; |
| 2304 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; |
| 2305 | listnode_add (tlv_data.is_neighs, is_neigh); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2306 | } |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2307 | |
| 2308 | while (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 2309 | { |
| 2310 | if (lsp->tlv_data.is_neighs == NULL) |
| 2311 | lsp->tlv_data.is_neighs = list_new (); |
| 2312 | lsp_tlv_fit (lsp, &tlv_data.is_neighs, |
| 2313 | &lsp->tlv_data.is_neighs, |
| 2314 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 2315 | tlv_add_is_neighs); |
| 2316 | if (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 2317 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 2318 | lsp0, area, IS_LEVEL_1); |
| 2319 | } |
| 2320 | |
| 2321 | free_tlvs (&tlv_data); |
| 2322 | return; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2323 | } |
| 2324 | #endif /* TOPOLOGY_GENERATE */ |