jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_spf.c |
| 3 | * The SPT algorithm |
| 4 | * |
| 5 | * Copyright (C) 2001,2002 Sampo Saaristo |
| 6 | * Tampere University of Technology |
| 7 | * Institute of Communications Engineering |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public Licenseas published by the Free |
| 11 | * Software Foundation; either version 2 of the License, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 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 "thread.h" |
| 29 | #include "linklist.h" |
| 30 | #include "vty.h" |
| 31 | #include "log.h" |
| 32 | #include "command.h" |
| 33 | #include "memory.h" |
| 34 | #include "prefix.h" |
| 35 | #include "hash.h" |
| 36 | #include "if.h" |
| 37 | #include "table.h" |
| 38 | |
| 39 | #include "isis_constants.h" |
| 40 | #include "isis_common.h" |
| 41 | #include "dict.h" |
| 42 | #include "isisd.h" |
| 43 | #include "isis_misc.h" |
| 44 | #include "isis_adjacency.h" |
| 45 | #include "isis_circuit.h" |
| 46 | #include "isis_tlv.h" |
| 47 | #include "isis_pdu.h" |
| 48 | #include "isis_lsp.h" |
| 49 | #include "isis_dynhn.h" |
| 50 | #include "isis_spf.h" |
| 51 | #include "isis_route.h" |
| 52 | #include "isis_csm.h" |
| 53 | |
| 54 | extern struct isis *isis; |
| 55 | extern struct thread_master *master; |
| 56 | extern struct host host; |
| 57 | |
| 58 | int isis_run_spf_l1 (struct thread *thread); |
| 59 | int isis_run_spf_l2 (struct thread *thread); |
| 60 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 61 | #if 0 |
| 62 | /* performace issue ???? HT: Old or new code? */ |
| 63 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 64 | union_adjlist (struct list *target, struct list *source) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 65 | { |
| 66 | struct isis_adjacency *adj, *adj2; |
| 67 | struct listnode *node, *node2; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 68 | |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 69 | zlog_debug ("Union adjlist!"); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 70 | for (node = listhead (source); node; nextnode (node)) |
| 71 | { |
| 72 | adj = getdata (node); |
| 73 | |
| 74 | /* lookup adjacency in the source list */ |
| 75 | for (node2 = listhead (target); node2; nextnode (node2)) |
| 76 | { |
| 77 | adj2 = getdata (node2); |
| 78 | if (adj == adj2) |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | if (!node2) |
| 83 | listnode_add (target, adj); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 84 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 85 | } |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 86 | #endif |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 87 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 88 | /* 7.2.7 */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 89 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 90 | remove_excess_adjs (struct list *adjs) |
| 91 | { |
| 92 | struct listnode *node, *excess = NULL; |
| 93 | struct isis_adjacency *adj, *candidate = NULL; |
| 94 | int comp; |
| 95 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 96 | for (node = listhead (adjs); node; nextnode (node)) |
| 97 | { |
| 98 | if (excess == NULL) |
| 99 | excess = node; |
| 100 | candidate = getdata (excess); |
| 101 | adj = getdata (node); |
| 102 | if (candidate->sys_type < adj->sys_type) |
| 103 | { |
| 104 | excess = node; |
| 105 | candidate = adj; |
| 106 | continue; |
| 107 | } |
| 108 | if (candidate->sys_type > adj->sys_type) |
| 109 | continue; |
| 110 | |
| 111 | comp = memcmp (candidate->sysid, adj->sysid, ISIS_SYS_ID_LEN); |
| 112 | if (comp > 0) |
| 113 | { |
| 114 | excess = node; |
| 115 | candidate = adj; |
| 116 | continue; |
| 117 | } |
| 118 | if (comp < 0) |
| 119 | continue; |
| 120 | |
| 121 | if (candidate->circuit->circuit_id > adj->circuit->circuit_id) |
| 122 | { |
| 123 | excess = node; |
| 124 | candidate = adj; |
| 125 | continue; |
| 126 | } |
| 127 | |
| 128 | if (candidate->circuit->circuit_id < adj->circuit->circuit_id) |
| 129 | continue; |
| 130 | |
| 131 | comp = memcmp (candidate->snpa, adj->snpa, ETH_ALEN); |
| 132 | if (comp > 0) |
| 133 | { |
| 134 | excess = node; |
| 135 | candidate = adj; |
| 136 | continue; |
| 137 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 138 | } |
| 139 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 140 | list_delete_node (adjs, excess); |
| 141 | |
| 142 | return; |
| 143 | } |
| 144 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 145 | #ifdef EXTREME_DEBUG |
| 146 | static const char * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 147 | vtype2string (enum vertextype vtype) |
| 148 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 149 | switch (vtype) |
| 150 | { |
| 151 | case VTYPE_PSEUDO_IS: |
| 152 | return "pseudo_IS"; |
| 153 | break; |
| 154 | case VTYPE_NONPSEUDO_IS: |
| 155 | return "IS"; |
| 156 | break; |
| 157 | case VTYPE_ES: |
| 158 | return "ES"; |
| 159 | break; |
| 160 | case VTYPE_IPREACH_INTERNAL: |
| 161 | return "IP internal"; |
| 162 | break; |
| 163 | case VTYPE_IPREACH_EXTERNAL: |
| 164 | return "IP external"; |
| 165 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 166 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 167 | case VTYPE_IP6REACH_INTERNAL: |
| 168 | return "IP6 internal"; |
| 169 | break; |
| 170 | case VTYPE_IP6REACH_EXTERNAL: |
| 171 | return "IP6 external"; |
| 172 | break; |
| 173 | #endif /* HAVE_IPV6 */ |
| 174 | default: |
| 175 | return "UNKNOWN"; |
| 176 | } |
| 177 | return NULL; /* Not reached */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 178 | } |
| 179 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 180 | static const char * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 181 | vid2string (struct isis_vertex *vertex, u_char * buff) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 182 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 183 | switch (vertex->type) |
| 184 | { |
| 185 | case VTYPE_PSEUDO_IS: |
| 186 | return rawlspid_print (vertex->N.id); |
| 187 | break; |
| 188 | case VTYPE_NONPSEUDO_IS: |
| 189 | case VTYPE_ES: |
| 190 | return sysid_print (vertex->N.id); |
| 191 | break; |
| 192 | case VTYPE_IPREACH_INTERNAL: |
| 193 | case VTYPE_IPREACH_EXTERNAL: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 194 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 195 | case VTYPE_IP6REACH_INTERNAL: |
| 196 | case VTYPE_IP6REACH_EXTERNAL: |
| 197 | #endif /* HAVE_IPV6 */ |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 198 | prefix2str ((struct prefix *) &vertex->N.prefix, (char *) buff, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 199 | break; |
| 200 | default: |
| 201 | return "UNKNOWN"; |
| 202 | } |
| 203 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 204 | return (char *) buff; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 205 | } |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 206 | #endif /* EXTREME_DEBUG */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 207 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 208 | static struct isis_spftree * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 209 | isis_spftree_new () |
| 210 | { |
| 211 | struct isis_spftree *tree; |
| 212 | |
| 213 | tree = XMALLOC (MTYPE_ISIS_SPFTREE, sizeof (struct isis_spftree)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 214 | if (tree == NULL) |
| 215 | { |
| 216 | zlog_err ("ISIS-Spf: isis_spftree_new Out of memory!"); |
| 217 | return NULL; |
| 218 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 219 | memset (tree, 0, sizeof (struct isis_spftree)); |
| 220 | |
| 221 | tree->tents = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 222 | tree->paths = list_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 223 | return tree; |
| 224 | } |
| 225 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 226 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 227 | isis_vertex_del (struct isis_vertex *vertex) |
| 228 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 229 | list_delete (vertex->Adj_N); |
| 230 | |
| 231 | XFREE (MTYPE_ISIS_VERTEX, vertex); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 232 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 236 | #if 0 /* HT: Not used yet. */ |
| 237 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 238 | isis_spftree_del (struct isis_spftree *spftree) |
| 239 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 240 | spftree->tents->del = (void (*)(void *)) isis_vertex_del; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 241 | list_delete (spftree->tents); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 242 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 243 | spftree->paths->del = (void (*)(void *)) isis_vertex_del; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 244 | list_delete (spftree->paths); |
| 245 | |
| 246 | XFREE (MTYPE_ISIS_SPFTREE, spftree); |
| 247 | |
| 248 | return; |
| 249 | } |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 250 | #endif |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 251 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 252 | void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 253 | spftree_area_init (struct isis_area *area) |
| 254 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 255 | if ((area->is_type & IS_LEVEL_1) && area->spftree[0] == NULL) |
| 256 | { |
| 257 | area->spftree[0] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 258 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 259 | area->spftree6[0] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 260 | #endif |
| 261 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 262 | /* thread_add_timer (master, isis_run_spf_l1, area, |
| 263 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */ |
| 264 | } |
| 265 | |
| 266 | if ((area->is_type & IS_LEVEL_2) && area->spftree[1] == NULL) |
| 267 | { |
| 268 | area->spftree[1] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 269 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 270 | area->spftree6[1] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 271 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 272 | /* thread_add_timer (master, isis_run_spf_l2, area, |
| 273 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */ |
| 274 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 275 | |
| 276 | return; |
| 277 | } |
| 278 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 279 | static struct isis_vertex * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 280 | isis_vertex_new (void *id, enum vertextype vtype) |
| 281 | { |
| 282 | struct isis_vertex *vertex; |
| 283 | |
| 284 | vertex = XMALLOC (MTYPE_ISIS_VERTEX, sizeof (struct isis_vertex)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 285 | if (vertex == NULL) |
| 286 | { |
| 287 | zlog_err ("isis_vertex_new Out of memory!"); |
| 288 | return NULL; |
| 289 | } |
| 290 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 291 | memset (vertex, 0, sizeof (struct isis_vertex)); |
| 292 | vertex->type = vtype; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 293 | switch (vtype) |
| 294 | { |
| 295 | case VTYPE_ES: |
| 296 | case VTYPE_NONPSEUDO_IS: |
| 297 | memcpy (vertex->N.id, (u_char *) id, ISIS_SYS_ID_LEN); |
| 298 | break; |
| 299 | case VTYPE_PSEUDO_IS: |
| 300 | memcpy (vertex->N.id, (u_char *) id, ISIS_SYS_ID_LEN + 1); |
| 301 | break; |
| 302 | case VTYPE_IPREACH_INTERNAL: |
| 303 | case VTYPE_IPREACH_EXTERNAL: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 304 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 305 | case VTYPE_IP6REACH_INTERNAL: |
| 306 | case VTYPE_IP6REACH_EXTERNAL: |
| 307 | #endif /* HAVE_IPV6 */ |
| 308 | memcpy (&vertex->N.prefix, (struct prefix *) id, |
| 309 | sizeof (struct prefix)); |
| 310 | break; |
| 311 | default: |
| 312 | zlog_err ("WTF!"); |
| 313 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 314 | |
| 315 | vertex->Adj_N = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 316 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 317 | return vertex; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * Add this IS to the root of SPT |
| 322 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 323 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 324 | isis_spf_add_self (struct isis_spftree *spftree, struct isis_area *area, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 325 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 326 | { |
| 327 | struct isis_vertex *vertex; |
| 328 | struct isis_lsp *lsp; |
| 329 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 330 | #ifdef EXTREME_DEBUG |
| 331 | u_char buff[BUFSIZ]; |
| 332 | #endif /* EXTREME_DEBUG */ |
| 333 | memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 334 | LSP_PSEUDO_ID (lspid) = 0; |
| 335 | LSP_FRAGMENT (lspid) = 0; |
| 336 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 337 | lsp = lsp_search (lspid, area->lspdb[level - 1]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 338 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 339 | if (lsp == NULL) |
| 340 | zlog_warn ("ISIS-Spf: could not find own l%d LSP!", level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 341 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 342 | vertex = isis_vertex_new (isis->sysid, VTYPE_NONPSEUDO_IS); |
| 343 | vertex->lsp = lsp; |
| 344 | |
| 345 | listnode_add (spftree->paths, vertex); |
| 346 | |
| 347 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 348 | zlog_debug ("ISIS-Spf: added this IS %s %s depth %d dist %d to PATHS", |
| 349 | vtype2string (vertex->type), vid2string (vertex, buff), |
| 350 | vertex->depth, vertex->d_N); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 351 | #endif /* EXTREME_DEBUG */ |
| 352 | |
| 353 | return; |
| 354 | } |
| 355 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 356 | static struct isis_vertex * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 357 | isis_find_vertex (struct list *list, void *id, enum vertextype vtype) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 358 | { |
| 359 | struct listnode *node; |
| 360 | struct isis_vertex *vertex; |
| 361 | struct prefix *p1, *p2; |
| 362 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 363 | for (node = listhead (list); node; nextnode (node)) |
| 364 | { |
| 365 | vertex = getdata (node); |
| 366 | if (vertex->type != vtype) |
| 367 | continue; |
| 368 | switch (vtype) |
| 369 | { |
| 370 | case VTYPE_ES: |
| 371 | case VTYPE_NONPSEUDO_IS: |
| 372 | if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN) == 0) |
| 373 | return vertex; |
| 374 | break; |
| 375 | case VTYPE_PSEUDO_IS: |
| 376 | if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN + 1) == 0) |
| 377 | return vertex; |
| 378 | break; |
| 379 | case VTYPE_IPREACH_INTERNAL: |
| 380 | case VTYPE_IPREACH_EXTERNAL: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 381 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 382 | case VTYPE_IP6REACH_INTERNAL: |
| 383 | case VTYPE_IP6REACH_EXTERNAL: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 384 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 385 | p1 = (struct prefix *) id; |
| 386 | p2 = (struct prefix *) &vertex->N.id; |
| 387 | if (p1->family == p2->family && p1->prefixlen == p2->prefixlen && |
| 388 | memcmp (&p1->u.prefix, &p2->u.prefix, |
| 389 | PSIZE (p1->prefixlen)) == 0) |
| 390 | return vertex; |
| 391 | break; |
| 392 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 393 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 394 | |
| 395 | return NULL; |
| 396 | } |
| 397 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 398 | /* |
| 399 | * Add a vertex to TENT sorted by cost and by vertextype on tie break situation |
| 400 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 401 | static struct isis_vertex * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 402 | isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype, |
| 403 | void *id, struct isis_adjacency *adj, u_int16_t cost, |
| 404 | int depth, int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 405 | { |
| 406 | struct isis_vertex *vertex, *v; |
| 407 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 408 | #ifdef EXTREME_DEBUG |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 409 | u_char buff[BUFSIZ]; |
| 410 | #endif |
| 411 | |
| 412 | vertex = isis_vertex_new (id, vtype); |
| 413 | vertex->d_N = cost; |
| 414 | vertex->depth = depth; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 415 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 416 | if (adj) |
| 417 | listnode_add (vertex->Adj_N, adj); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 418 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 419 | zlog_debug ("ISIS-Spf: add to TENT %s %s depth %d dist %d", |
| 420 | vtype2string (vertex->type), vid2string (vertex, buff), |
| 421 | vertex->depth, vertex->d_N); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 422 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 423 | listnode_add (spftree->tents, vertex); |
| 424 | if (list_isempty (spftree->tents)) |
| 425 | { |
| 426 | listnode_add (spftree->tents, vertex); |
| 427 | return vertex; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 428 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 429 | for (node = listhead (spftree->tents); node; nextnode (node)) |
| 430 | { |
| 431 | v = getdata (node); |
| 432 | if (v->d_N > vertex->d_N) |
| 433 | { |
| 434 | list_add_node_prev (spftree->tents, node, vertex); |
| 435 | break; |
| 436 | } |
| 437 | else if (v->d_N == vertex->d_N) |
| 438 | { |
| 439 | /* Tie break, add according to type */ |
| 440 | while (v && v->d_N == vertex->d_N && v->type > vertex->type) |
| 441 | { |
| 442 | if (v->type > vertex->type) |
| 443 | { |
| 444 | break; |
| 445 | } |
| 446 | nextnode (node); |
| 447 | (node) ? (v = getdata (node)) : (v = NULL); |
| 448 | } |
| 449 | list_add_node_prev (spftree->tents, node, vertex); |
| 450 | break; |
| 451 | } |
| 452 | else if (node->next == NULL) |
| 453 | { |
| 454 | list_add_node_next (spftree->tents, node, vertex); |
| 455 | break; |
| 456 | } |
| 457 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 458 | return vertex; |
| 459 | } |
| 460 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 461 | static struct isis_vertex * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 462 | isis_spf_add_local (struct isis_spftree *spftree, enum vertextype vtype, |
| 463 | void *id, struct isis_adjacency *adj, u_int16_t cost, |
| 464 | int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 465 | { |
| 466 | struct isis_vertex *vertex; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 467 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 468 | vertex = isis_find_vertex (spftree->tents, id, vtype); |
| 469 | |
| 470 | if (vertex) |
| 471 | { |
| 472 | /* C.2.5 c) */ |
| 473 | if (vertex->d_N == cost) |
| 474 | { |
| 475 | if (adj) |
| 476 | listnode_add (vertex->Adj_N, adj); |
| 477 | /* d) */ |
| 478 | if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS) |
| 479 | remove_excess_adjs (vertex->Adj_N); |
| 480 | } |
| 481 | /* f) */ |
| 482 | else if (vertex->d_N > cost) |
| 483 | { |
| 484 | listnode_delete (spftree->tents, vertex); |
| 485 | goto add2tent; |
| 486 | } |
| 487 | /* e) do nothing */ |
| 488 | return vertex; |
| 489 | } |
| 490 | |
| 491 | add2tent: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 492 | return isis_spf_add2tent (spftree, vtype, id, adj, cost, 1, family); |
| 493 | } |
| 494 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 495 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 496 | process_N (struct isis_spftree *spftree, enum vertextype vtype, void *id, |
| 497 | u_int16_t dist, u_int16_t depth, struct isis_adjacency *adj, |
| 498 | int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 499 | { |
| 500 | struct isis_vertex *vertex; |
| 501 | #ifdef EXTREME_DEBUG |
| 502 | u_char buff[255]; |
| 503 | #endif |
| 504 | |
| 505 | /* C.2.6 b) */ |
| 506 | if (dist > MAX_PATH_METRIC) |
| 507 | return; |
| 508 | /* c) */ |
| 509 | vertex = isis_find_vertex (spftree->paths, id, vtype); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 510 | if (vertex) |
| 511 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 512 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 513 | zlog_debug ("ISIS-Spf: process_N %s %s dist %d already found from PATH", |
| 514 | vtype2string (vtype), vid2string (vertex, buff), dist); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 515 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 516 | assert (dist >= vertex->d_N); |
| 517 | return; |
| 518 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 519 | |
| 520 | vertex = isis_find_vertex (spftree->tents, id, vtype); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 521 | /* d) */ |
| 522 | if (vertex) |
| 523 | { |
| 524 | /* 1) */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 525 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 526 | zlog_debug ("ISIS-Spf: process_N %s %s dist %d", |
| 527 | vtype2string (vtype), vid2string (vertex, buff), dist); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 528 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 529 | if (vertex->d_N == dist) |
| 530 | { |
| 531 | if (adj) |
| 532 | listnode_add (vertex->Adj_N, adj); |
| 533 | /* 2) */ |
| 534 | if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS) |
| 535 | remove_excess_adjs (vertex->Adj_N); |
| 536 | /* 3) */ |
| 537 | return; |
| 538 | } |
| 539 | else if (vertex->d_N < dist) |
| 540 | { |
| 541 | return; |
| 542 | /* 4) */ |
| 543 | } |
| 544 | else |
| 545 | { |
| 546 | listnode_delete (spftree->tents, vertex); |
| 547 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 548 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 549 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 550 | isis_spf_add2tent (spftree, vtype, id, adj, dist, depth, family); |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * C.2.6 Step 1 |
| 556 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 557 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 558 | isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp, |
| 559 | uint16_t cost, uint16_t depth, int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 560 | { |
| 561 | struct listnode *node, *fragnode = NULL; |
| 562 | u_int16_t dist; |
| 563 | struct is_neigh *is_neigh; |
| 564 | struct ipv4_reachability *ipreach; |
| 565 | enum vertextype vtype; |
| 566 | struct prefix prefix; |
| 567 | #ifdef HAVE_IPV6 |
| 568 | struct ipv6_reachability *ip6reach; |
| 569 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 570 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 571 | |
| 572 | if (!lsp->adj) |
| 573 | return ISIS_WARNING; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 574 | if (lsp->tlv_data.nlpids == NULL || !speaks (lsp->tlv_data.nlpids, family)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 575 | return ISIS_OK; |
| 576 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 577 | lspfragloop: |
| 578 | if (lsp->lsp_header->seq_num == 0) |
| 579 | { |
| 580 | zlog_warn ("isis_spf_process_lsp(): lsp with 0 seq_num" |
| 581 | " - do not process"); |
| 582 | return ISIS_WARNING; |
| 583 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 584 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 585 | if (!ISIS_MASK_LSP_OL_BIT (lsp->lsp_header->lsp_bits)) |
| 586 | { |
| 587 | if (lsp->tlv_data.is_neighs) |
| 588 | { |
| 589 | for (node = listhead (lsp->tlv_data.is_neighs); node; |
| 590 | nextnode (node)) |
| 591 | { |
| 592 | is_neigh = getdata (node); |
| 593 | /* C.2.6 a) */ |
| 594 | /* Two way connectivity */ |
| 595 | if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 596 | continue; |
| 597 | dist = cost + is_neigh->metrics.metric_default; |
| 598 | vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS |
| 599 | : VTYPE_NONPSEUDO_IS; |
| 600 | process_N (spftree, vtype, (void *) is_neigh->neigh_id, dist, |
| 601 | depth + 1, lsp->adj, family); |
| 602 | } |
| 603 | } |
| 604 | if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs) |
| 605 | { |
| 606 | prefix.family = AF_INET; |
| 607 | for (node = listhead (lsp->tlv_data.ipv4_int_reachs); node; |
| 608 | nextnode (node)) |
| 609 | { |
| 610 | ipreach = getdata (node); |
| 611 | dist = cost + ipreach->metrics.metric_default; |
| 612 | vtype = VTYPE_IPREACH_INTERNAL; |
| 613 | prefix.u.prefix4 = ipreach->prefix; |
| 614 | prefix.prefixlen = ip_masklen (ipreach->mask); |
| 615 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
| 616 | lsp->adj, family); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs) |
| 621 | { |
| 622 | prefix.family = AF_INET; |
| 623 | for (node = listhead (lsp->tlv_data.ipv4_ext_reachs); node; |
| 624 | nextnode (node)) |
| 625 | { |
| 626 | ipreach = getdata (node); |
| 627 | dist = cost + ipreach->metrics.metric_default; |
| 628 | vtype = VTYPE_IPREACH_EXTERNAL; |
| 629 | prefix.u.prefix4 = ipreach->prefix; |
| 630 | prefix.prefixlen = ip_masklen (ipreach->mask); |
| 631 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
| 632 | lsp->adj, family); |
| 633 | } |
| 634 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 635 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 636 | if (family == AF_INET6 && lsp->tlv_data.ipv6_reachs) |
| 637 | { |
| 638 | prefix.family = AF_INET6; |
| 639 | for (node = listhead (lsp->tlv_data.ipv6_reachs); node; |
| 640 | nextnode (node)) |
| 641 | { |
| 642 | ip6reach = getdata (node); |
| 643 | dist = cost + ip6reach->metric; |
| 644 | vtype = (ip6reach->control_info & CTRL_INFO_DISTRIBUTION) ? |
| 645 | VTYPE_IP6REACH_EXTERNAL : VTYPE_IP6REACH_INTERNAL; |
| 646 | prefix.prefixlen = ip6reach->prefix_len; |
| 647 | memcpy (&prefix.u.prefix6.s6_addr, ip6reach->prefix, |
| 648 | PSIZE (ip6reach->prefix_len)); |
| 649 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
| 650 | lsp->adj, family); |
| 651 | } |
| 652 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 653 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 654 | } |
| 655 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 656 | if (fragnode == NULL) |
| 657 | fragnode = listhead (lsp->lspu.frags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 658 | else |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 659 | nextnode (fragnode); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 660 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 661 | if (fragnode) |
| 662 | { |
| 663 | lsp = getdata (fragnode); |
| 664 | goto lspfragloop; |
| 665 | } |
| 666 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 667 | return ISIS_OK; |
| 668 | } |
| 669 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 670 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 671 | isis_spf_process_pseudo_lsp (struct isis_spftree *spftree, |
| 672 | struct isis_lsp *lsp, uint16_t cost, |
| 673 | uint16_t depth, int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 674 | { |
| 675 | struct listnode *node, *fragnode = NULL; |
| 676 | struct is_neigh *is_neigh; |
| 677 | enum vertextype vtype; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 678 | |
| 679 | pseudofragloop: |
| 680 | |
| 681 | if (lsp->lsp_header->seq_num == 0) |
| 682 | { |
| 683 | zlog_warn ("isis_spf_process_pseudo_lsp(): lsp with 0 seq_num" |
| 684 | " - do not process"); |
| 685 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 686 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 687 | |
| 688 | for (node = (lsp->tlv_data.is_neighs ? |
| 689 | listhead (lsp->tlv_data.is_neighs) : NULL); |
| 690 | node; nextnode (node)) |
| 691 | { |
| 692 | is_neigh = getdata (node); |
| 693 | vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS |
| 694 | : VTYPE_NONPSEUDO_IS; |
| 695 | /* Two way connectivity */ |
| 696 | if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 697 | continue; |
| 698 | if (isis_find_vertex |
| 699 | (spftree->tents, (void *) is_neigh->neigh_id, vtype) == NULL |
| 700 | && isis_find_vertex (spftree->paths, (void *) is_neigh->neigh_id, |
| 701 | vtype) == NULL) |
| 702 | { |
| 703 | /* C.2.5 i) */ |
| 704 | isis_spf_add2tent (spftree, vtype, is_neigh->neigh_id, lsp->adj, |
| 705 | cost, depth, family); |
| 706 | } |
| 707 | } |
| 708 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 709 | if (fragnode == NULL) |
| 710 | fragnode = listhead (lsp->lspu.frags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 711 | else |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 712 | nextnode (fragnode); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 713 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 714 | if (fragnode) |
| 715 | { |
| 716 | lsp = getdata (fragnode); |
| 717 | goto pseudofragloop; |
| 718 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 719 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 720 | return ISIS_OK; |
| 721 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 722 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 723 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 724 | isis_spf_preload_tent (struct isis_spftree *spftree, |
| 725 | struct isis_area *area, int level, int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 726 | { |
| 727 | struct isis_vertex *vertex; |
| 728 | struct isis_circuit *circuit; |
| 729 | struct listnode *cnode, *anode, *ipnode; |
| 730 | struct isis_adjacency *adj; |
| 731 | struct isis_lsp *lsp; |
| 732 | struct list *adj_list; |
| 733 | struct list *adjdb; |
| 734 | struct prefix_ipv4 *ipv4; |
| 735 | struct prefix prefix; |
| 736 | int retval = ISIS_OK; |
| 737 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 738 | #ifdef HAVE_IPV6 |
| 739 | struct prefix_ipv6 *ipv6; |
| 740 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 741 | |
| 742 | for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) |
| 743 | { |
| 744 | circuit = getdata (cnode); |
| 745 | if (circuit->state != C_STATE_UP) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 746 | continue; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 747 | if (!(circuit->circuit_is_type & level)) |
| 748 | continue; |
| 749 | if (family == AF_INET && !circuit->ip_router) |
| 750 | continue; |
| 751 | #ifdef HAVE_IPV6 |
| 752 | if (family == AF_INET6 && !circuit->ipv6_router) |
| 753 | continue; |
| 754 | #endif /* HAVE_IPV6 */ |
| 755 | /* |
| 756 | * Add IP(v6) addresses of this circuit |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 757 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 758 | if (family == AF_INET) |
| 759 | { |
| 760 | prefix.family = AF_INET; |
| 761 | for (ipnode = |
| 762 | (circuit->ip_addrs ? listhead (circuit->ip_addrs) : NULL); |
| 763 | ipnode; nextnode (ipnode)) |
| 764 | { |
| 765 | ipv4 = getdata (ipnode); |
| 766 | prefix.u.prefix4 = ipv4->prefix; |
| 767 | prefix.prefixlen = ipv4->prefixlen; |
| 768 | isis_spf_add_local (spftree, VTYPE_IPREACH_INTERNAL, &prefix, |
| 769 | NULL, 0, family); |
| 770 | } |
| 771 | } |
| 772 | #ifdef HAVE_IPV6 |
| 773 | if (family == AF_INET6) |
| 774 | { |
| 775 | prefix.family = AF_INET6; |
| 776 | for (ipnode = (circuit->ipv6_non_link ? listhead |
| 777 | (circuit->ipv6_non_link) : NULL); ipnode; |
| 778 | nextnode (ipnode)) |
| 779 | { |
| 780 | ipv6 = getdata (ipnode); |
| 781 | prefix.prefixlen = ipv6->prefixlen; |
| 782 | prefix.u.prefix6 = ipv6->prefix; |
| 783 | isis_spf_add_local (spftree, VTYPE_IP6REACH_INTERNAL, |
| 784 | &prefix, NULL, 0, family); |
| 785 | } |
| 786 | } |
| 787 | #endif /* HAVE_IPV6 */ |
| 788 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 789 | { |
| 790 | /* |
| 791 | * Add the adjacencies |
| 792 | */ |
| 793 | adj_list = list_new (); |
| 794 | adjdb = circuit->u.bc.adjdb[level - 1]; |
| 795 | isis_adj_build_up_list (adjdb, adj_list); |
| 796 | if (listcount (adj_list) == 0) |
| 797 | { |
| 798 | list_delete (adj_list); |
| 799 | zlog_warn ("ISIS-Spf: no L%d adjacencies on circuit %s", |
| 800 | level, circuit->interface->name); |
| 801 | continue; |
| 802 | } |
| 803 | anode = listhead (adj_list); |
| 804 | while (anode) |
| 805 | { |
| 806 | adj = getdata (anode); |
| 807 | if (!speaks (&adj->nlpids, family)) |
| 808 | { |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 809 | nextnode (anode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 810 | continue; |
| 811 | } |
| 812 | switch (adj->sys_type) |
| 813 | { |
| 814 | case ISIS_SYSTYPE_ES: |
| 815 | isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, |
| 816 | circuit->metrics[level - |
| 817 | 1].metric_default, |
| 818 | family); |
| 819 | break; |
| 820 | case ISIS_SYSTYPE_IS: |
| 821 | case ISIS_SYSTYPE_L1_IS: |
| 822 | case ISIS_SYSTYPE_L2_IS: |
| 823 | vertex = |
| 824 | isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, |
| 825 | adj->sysid, adj, |
| 826 | circuit->metrics[level - |
| 827 | 1].metric_default, |
| 828 | family); |
| 829 | memcpy (lsp_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 830 | LSP_PSEUDO_ID (lsp_id) = 0; |
| 831 | LSP_FRAGMENT (lsp_id) = 0; |
| 832 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 833 | if (!lsp) |
| 834 | zlog_warn ("No lsp found for IS adjacency"); |
| 835 | /* else { |
| 836 | isis_spf_process_lsp (spftree, lsp, vertex->d_N, 1, family); |
| 837 | } */ |
| 838 | break; |
| 839 | case ISIS_SYSTYPE_UNKNOWN: |
| 840 | default: |
| 841 | zlog_warn ("isis_spf_preload_tent unknow adj type"); |
| 842 | } |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 843 | nextnode (anode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 844 | } |
| 845 | list_delete (adj_list); |
| 846 | /* |
| 847 | * Add the pseudonode |
| 848 | */ |
| 849 | if (level == 1) |
| 850 | memcpy (lsp_id, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 851 | else |
| 852 | memcpy (lsp_id, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
| 853 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 854 | adj = isis_adj_lookup (lsp_id, adjdb); |
| 855 | /* if no adj, we are the dis or error */ |
| 856 | if (!adj && !circuit->u.bc.is_dr[level - 1]) |
| 857 | { |
| 858 | zlog_warn ("ISIS-Spf: No adjacency found for DR"); |
| 859 | } |
| 860 | if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0) |
| 861 | { |
| 862 | zlog_warn ("ISIS-Spf: No lsp found for DR"); |
| 863 | } |
| 864 | else |
| 865 | { |
| 866 | isis_spf_process_pseudo_lsp |
| 867 | (spftree, lsp, circuit->metrics[level - 1].metric_default, 0, |
| 868 | family); |
| 869 | |
| 870 | } |
| 871 | } |
| 872 | else if (circuit->circ_type == CIRCUIT_T_P2P) |
| 873 | { |
| 874 | adj = circuit->u.p2p.neighbor; |
| 875 | if (!adj) |
| 876 | continue; |
| 877 | switch (adj->sys_type) |
| 878 | { |
| 879 | case ISIS_SYSTYPE_ES: |
| 880 | isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, |
| 881 | circuit->metrics[level - 1].metric_default, |
| 882 | family); |
| 883 | break; |
| 884 | case ISIS_SYSTYPE_IS: |
| 885 | case ISIS_SYSTYPE_L1_IS: |
| 886 | case ISIS_SYSTYPE_L2_IS: |
| 887 | if (speaks (&adj->nlpids, family)) |
| 888 | isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, adj->sysid, |
| 889 | adj, |
| 890 | circuit->metrics[level - |
| 891 | 1].metric_default, |
| 892 | family); |
| 893 | break; |
| 894 | case ISIS_SYSTYPE_UNKNOWN: |
| 895 | default: |
| 896 | zlog_warn ("isis_spf_preload_tent unknow adj type"); |
| 897 | break; |
| 898 | } |
| 899 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 900 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 901 | { |
| 902 | zlog_warn ("isis_spf_preload_tent unsupported media"); |
| 903 | retval = ISIS_WARNING; |
| 904 | } |
| 905 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 906 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 907 | |
| 908 | return retval; |
| 909 | } |
| 910 | |
| 911 | /* |
| 912 | * The parent(s) for vertex is set when added to TENT list |
| 913 | * now we just put the child pointer(s) in place |
| 914 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 915 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 916 | add_to_paths (struct isis_spftree *spftree, struct isis_vertex *vertex, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 917 | struct isis_area *area) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 918 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 919 | #ifdef EXTREME_DEBUG |
| 920 | u_char buff[BUFSIZ]; |
| 921 | #endif /* EXTREME_DEBUG */ |
| 922 | listnode_add (spftree->paths, vertex); |
| 923 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 924 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 925 | zlog_debug ("ISIS-Spf: added %s %s depth %d dist %d to PATHS", |
| 926 | vtype2string (vertex->type), vid2string (vertex, buff), |
| 927 | vertex->depth, vertex->d_N); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 928 | #endif /* EXTREME_DEBUG */ |
| 929 | if (vertex->type > VTYPE_ES) |
| 930 | { |
| 931 | if (listcount (vertex->Adj_N) > 0) |
| 932 | isis_route_create ((struct prefix *) &vertex->N.prefix, |
| 933 | vertex->d_N, vertex->depth, vertex->Adj_N, area); |
| 934 | else if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 935 | zlog_debug ("ISIS-Spf: no adjacencies do not install route"); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 936 | } |
| 937 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 938 | return; |
| 939 | } |
| 940 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 941 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 942 | init_spt (struct isis_spftree *spftree) |
| 943 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 944 | spftree->tents->del = spftree->paths->del = (void (*)(void *)) isis_vertex_del; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 945 | list_delete_all_node (spftree->tents); |
| 946 | list_delete_all_node (spftree->paths); |
| 947 | spftree->tents->del = spftree->paths->del = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 948 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 949 | return; |
| 950 | } |
| 951 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 952 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 953 | isis_run_spf (struct isis_area *area, int level, int family) |
| 954 | { |
| 955 | int retval = ISIS_OK; |
| 956 | struct listnode *node; |
| 957 | struct isis_vertex *vertex; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 958 | struct isis_spftree *spftree = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 959 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 960 | struct isis_lsp *lsp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 961 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 962 | if (family == AF_INET) |
| 963 | spftree = area->spftree[level - 1]; |
| 964 | #ifdef HAVE_IPV6 |
| 965 | else if (family == AF_INET6) |
| 966 | spftree = area->spftree6[level - 1]; |
| 967 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 968 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 969 | assert (spftree); |
| 970 | |
| 971 | /* |
| 972 | * C.2.5 Step 0 |
| 973 | */ |
| 974 | init_spt (spftree); |
| 975 | /* a) */ |
| 976 | isis_spf_add_self (spftree, area, level); |
| 977 | /* b) */ |
| 978 | retval = isis_spf_preload_tent (spftree, area, level, family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 979 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 980 | /* |
| 981 | * C.2.7 Step 2 |
| 982 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 983 | if (listcount (spftree->tents) == 0) |
| 984 | { |
| 985 | zlog_warn ("ISIS-Spf: TENT is empty"); |
| 986 | spftree->lastrun = time (NULL); |
| 987 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 988 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 989 | |
| 990 | while (listcount (spftree->tents) > 0) |
| 991 | { |
| 992 | node = listhead (spftree->tents); |
| 993 | vertex = getdata (node); |
| 994 | /* Remove from tent list */ |
| 995 | list_delete_node (spftree->tents, node); |
| 996 | if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type)) |
| 997 | continue; |
| 998 | add_to_paths (spftree, vertex, area); |
| 999 | if (vertex->type == VTYPE_PSEUDO_IS || |
| 1000 | vertex->type == VTYPE_NONPSEUDO_IS) |
| 1001 | { |
| 1002 | memcpy (lsp_id, vertex->N.id, ISIS_SYS_ID_LEN + 1); |
| 1003 | LSP_FRAGMENT (lsp_id) = 0; |
| 1004 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 1005 | if (lsp) |
| 1006 | { |
| 1007 | if (LSP_PSEUDO_ID (lsp_id)) |
| 1008 | { |
| 1009 | isis_spf_process_pseudo_lsp (spftree, lsp, vertex->d_N, |
| 1010 | vertex->depth, family); |
| 1011 | |
| 1012 | } |
| 1013 | else |
| 1014 | { |
| 1015 | isis_spf_process_lsp (spftree, lsp, vertex->d_N, |
| 1016 | vertex->depth, family); |
| 1017 | } |
| 1018 | } |
| 1019 | else |
| 1020 | { |
| 1021 | zlog_warn ("ISIS-Spf: No LSP found for %s", |
| 1022 | rawlspid_print (lsp_id)); |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1027 | thread_add_event (master, isis_route_validate, area, 0); |
| 1028 | spftree->lastrun = time (NULL); |
| 1029 | spftree->pending = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1030 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1031 | return retval; |
| 1032 | } |
| 1033 | |
| 1034 | int |
| 1035 | isis_run_spf_l1 (struct thread *thread) |
| 1036 | { |
| 1037 | struct isis_area *area; |
| 1038 | int retval = ISIS_OK; |
| 1039 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1040 | area = THREAD_ARG (thread); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1041 | assert (area); |
| 1042 | |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1043 | area->spftree[0]->t_spf = NULL; |
| 1044 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1045 | if (!(area->is_type & IS_LEVEL_1)) |
| 1046 | { |
| 1047 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1048 | zlog_warn ("ISIS-SPF (%s) area does not share level", |
| 1049 | area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1050 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1051 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1052 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1053 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1054 | zlog_debug ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1055 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1056 | if (area->ip_circuits) |
| 1057 | retval = isis_run_spf (area, 1, AF_INET); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1058 | |
| 1059 | THREAD_TIMER_ON (master, area->spftree[0]->t_spf, isis_run_spf_l1, area, |
| 1060 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1061 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1062 | return retval; |
| 1063 | } |
| 1064 | |
| 1065 | int |
| 1066 | isis_run_spf_l2 (struct thread *thread) |
| 1067 | { |
| 1068 | struct isis_area *area; |
| 1069 | int retval = ISIS_OK; |
| 1070 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1071 | area = THREAD_ARG (thread); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1072 | assert (area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1073 | |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1074 | area->spftree[1]->t_spf = NULL; |
| 1075 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1076 | if (!(area->is_type & IS_LEVEL_2)) |
| 1077 | { |
| 1078 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1079 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1080 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1081 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1082 | |
| 1083 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1084 | zlog_debug ("ISIS-Spf (%s) L2 SPF needed, periodic SPF", area->area_tag); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1085 | |
| 1086 | if (area->ip_circuits) |
| 1087 | retval = isis_run_spf (area, 2, AF_INET); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1088 | |
| 1089 | THREAD_TIMER_ON (master, area->spftree[1]->t_spf, isis_run_spf_l2, area, |
| 1090 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1091 | |
| 1092 | return retval; |
| 1093 | } |
| 1094 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1095 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1096 | isis_spf_schedule (struct isis_area *area, int level) |
| 1097 | { |
| 1098 | int retval = ISIS_OK; |
| 1099 | struct isis_spftree *spftree = area->spftree[level - 1]; |
| 1100 | time_t diff, now = time (NULL); |
| 1101 | |
| 1102 | if (spftree->pending) |
| 1103 | return retval; |
| 1104 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1105 | diff = now - spftree->lastrun; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1106 | |
| 1107 | /* FIXME: let's wait a minute before doing the SPF */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1108 | if (now - isis->uptime < 60 || isis->uptime == 0) |
| 1109 | { |
| 1110 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1111 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area, 60); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1112 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1113 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area, 60); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1114 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1115 | spftree->pending = 1; |
| 1116 | return retval; |
| 1117 | } |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1118 | |
| 1119 | THREAD_TIMER_OFF (spftree->t_spf); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1120 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1121 | if (diff < MINIMUM_SPF_INTERVAL) |
| 1122 | { |
| 1123 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1124 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area, |
| 1125 | MINIMUM_SPF_INTERVAL - diff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1126 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1127 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area, |
| 1128 | MINIMUM_SPF_INTERVAL - diff); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1129 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1130 | spftree->pending = 1; |
| 1131 | } |
| 1132 | else |
| 1133 | { |
| 1134 | spftree->pending = 0; |
| 1135 | retval = isis_run_spf (area, level, AF_INET); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1136 | if (level == 1) |
| 1137 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area, |
| 1138 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1139 | else |
| 1140 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area, |
| 1141 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1142 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1143 | |
| 1144 | return retval; |
| 1145 | } |
| 1146 | |
| 1147 | #ifdef HAVE_IPV6 |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1148 | static int |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1149 | isis_run_spf6_l1 (struct thread *thread) |
| 1150 | { |
| 1151 | struct isis_area *area; |
| 1152 | int retval = ISIS_OK; |
| 1153 | |
| 1154 | area = THREAD_ARG (thread); |
| 1155 | assert (area); |
| 1156 | |
| 1157 | area->spftree6[0]->t_spf = NULL; |
| 1158 | |
| 1159 | if (!(area->is_type & IS_LEVEL_1)) |
| 1160 | { |
| 1161 | if (isis->debugs & DEBUG_SPF_EVENTS) |
| 1162 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
| 1163 | return ISIS_WARNING; |
| 1164 | } |
| 1165 | |
| 1166 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1167 | zlog_debug ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", area->area_tag); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1168 | |
| 1169 | if (area->ipv6_circuits) |
| 1170 | retval = isis_run_spf (area, 1, AF_INET6); |
| 1171 | |
| 1172 | THREAD_TIMER_ON (master, area->spftree6[0]->t_spf, isis_run_spf6_l1, area, |
| 1173 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1174 | |
| 1175 | return retval; |
| 1176 | } |
| 1177 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1178 | static int |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1179 | isis_run_spf6_l2 (struct thread *thread) |
| 1180 | { |
| 1181 | struct isis_area *area; |
| 1182 | int retval = ISIS_OK; |
| 1183 | |
| 1184 | area = THREAD_ARG (thread); |
| 1185 | assert (area); |
| 1186 | |
| 1187 | area->spftree6[1]->t_spf = NULL; |
| 1188 | |
| 1189 | if (!(area->is_type & IS_LEVEL_2)) |
| 1190 | { |
| 1191 | if (isis->debugs & DEBUG_SPF_EVENTS) |
| 1192 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
| 1193 | return ISIS_WARNING; |
| 1194 | } |
| 1195 | |
| 1196 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1197 | zlog_debug ("ISIS-Spf (%s) L2 SPF needed, periodic SPF", area->area_tag); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1198 | |
| 1199 | if (area->ipv6_circuits) |
| 1200 | retval = isis_run_spf (area, 2, AF_INET6); |
| 1201 | |
| 1202 | THREAD_TIMER_ON (master, area->spftree6[1]->t_spf, isis_run_spf6_l2, area, |
| 1203 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1204 | |
| 1205 | return retval; |
| 1206 | } |
| 1207 | |
| 1208 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1209 | isis_spf_schedule6 (struct isis_area *area, int level) |
| 1210 | { |
| 1211 | int retval = ISIS_OK; |
| 1212 | struct isis_spftree *spftree = area->spftree6[level - 1]; |
| 1213 | time_t diff, now = time (NULL); |
| 1214 | |
| 1215 | if (spftree->pending) |
| 1216 | return retval; |
| 1217 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1218 | diff = now - spftree->lastrun; |
| 1219 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1220 | /* FIXME: let's wait a minute before doing the SPF */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1221 | if (now - isis->uptime < 60 || isis->uptime == 0) |
| 1222 | { |
| 1223 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1224 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area, 60); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1225 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1226 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area, 60); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1227 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1228 | spftree->pending = 1; |
| 1229 | return retval; |
| 1230 | } |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1231 | |
| 1232 | THREAD_TIMER_OFF (spftree->t_spf); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1233 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1234 | if (diff < MINIMUM_SPF_INTERVAL) |
| 1235 | { |
| 1236 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1237 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area, |
| 1238 | MINIMUM_SPF_INTERVAL - diff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1239 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1240 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area, |
| 1241 | MINIMUM_SPF_INTERVAL - diff); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1242 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1243 | spftree->pending = 1; |
| 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | spftree->pending = 0; |
| 1248 | retval = isis_run_spf (area, level, AF_INET6); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1249 | |
| 1250 | if (level == 1) |
| 1251 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area, |
| 1252 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1253 | else |
| 1254 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area, |
| 1255 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1256 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1257 | |
| 1258 | return retval; |
| 1259 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1260 | #endif |
| 1261 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1262 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1263 | isis_print_paths (struct vty *vty, struct list *paths) |
| 1264 | { |
| 1265 | struct listnode *node, *anode; |
| 1266 | struct isis_vertex *vertex; |
| 1267 | struct isis_dynhn *dyn, *nh_dyn = NULL; |
| 1268 | struct isis_adjacency *adj; |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1269 | #if 0 |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1270 | u_char buff[255]; |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1271 | #endif /* 0 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1272 | |
| 1273 | vty_out (vty, "System Id Metric Next-Hop" |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1274 | " Interface SNPA%s", VTY_NEWLINE); |
| 1275 | for (node = listhead (paths); node; nextnode (node)) |
| 1276 | { |
| 1277 | vertex = getdata (node); |
| 1278 | if (vertex->type != VTYPE_NONPSEUDO_IS) |
| 1279 | continue; |
| 1280 | if (memcmp (vertex->N.id, isis->sysid, ISIS_SYS_ID_LEN) == 0) |
| 1281 | { |
hasso | c3d26c7 | 2005-03-07 08:54:41 +0000 | [diff] [blame] | 1282 | vty_out (vty, "%s --%s", host.name?host.name:"", |
| 1283 | VTY_NEWLINE); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1284 | } |
| 1285 | else |
| 1286 | { |
| 1287 | dyn = dynhn_find_by_id ((u_char *) vertex->N.id); |
| 1288 | anode = listhead (vertex->Adj_N); |
| 1289 | adj = getdata (anode); |
| 1290 | if (adj) |
| 1291 | { |
| 1292 | nh_dyn = dynhn_find_by_id (adj->sysid); |
| 1293 | vty_out (vty, "%-20s %-10u %-20s %-11s %-5s%s", |
| 1294 | (dyn != NULL) ? dyn->name.name : |
| 1295 | (u_char *) rawlspid_print ((u_char *) vertex->N.id), |
| 1296 | vertex->d_N, (nh_dyn != NULL) ? nh_dyn->name.name : |
| 1297 | (u_char *) rawlspid_print (adj->sysid), |
| 1298 | adj->circuit->interface->name, |
| 1299 | snpa_print (adj->snpa), VTY_NEWLINE); |
| 1300 | } |
| 1301 | else |
| 1302 | { |
| 1303 | vty_out (vty, "%s %u %s", dyn ? dyn->name.name : |
| 1304 | (u_char *) rawlspid_print (vertex->N.id), |
| 1305 | vertex->d_N, VTY_NEWLINE); |
| 1306 | } |
| 1307 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1308 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1309 | vty_out (vty, "%s %s %u %s", vtype2string (vertex->type), |
| 1310 | vid2string (vertex, buff), vertex->d_N, VTY_NEWLINE); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1311 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1312 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | DEFUN (show_isis_topology, |
| 1316 | show_isis_topology_cmd, |
| 1317 | "show isis topology", |
| 1318 | SHOW_STR |
| 1319 | "IS-IS information\n" |
| 1320 | "IS-IS paths to Intermediate Systems\n") |
| 1321 | { |
| 1322 | struct listnode *node; |
| 1323 | struct isis_area *area; |
| 1324 | int level; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1325 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1326 | if (!isis->area_list || isis->area_list->count == 0) |
| 1327 | return CMD_SUCCESS; |
| 1328 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1329 | for (node = listhead (isis->area_list); node; nextnode (node)) |
| 1330 | { |
| 1331 | area = getdata (node); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1332 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1333 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1334 | VTY_NEWLINE); |
| 1335 | |
| 1336 | for (level = 0; level < ISIS_LEVELS; level++) |
| 1337 | { |
| 1338 | if (area->ip_circuits > 0 && area->spftree[level] |
| 1339 | && area->spftree[level]->paths->count > 0) |
| 1340 | { |
| 1341 | vty_out (vty, "IS-IS paths to level-%d routers that speak IP%s", |
| 1342 | level + 1, VTY_NEWLINE); |
| 1343 | isis_print_paths (vty, area->spftree[level]->paths); |
| 1344 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1345 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1346 | if (area->ipv6_circuits > 0 && area->spftree6[level] |
| 1347 | && area->spftree6[level]->paths->count > 0) |
| 1348 | { |
| 1349 | vty_out (vty, |
| 1350 | "IS-IS paths to level-%d routers that speak IPv6%s", |
| 1351 | level + 1, VTY_NEWLINE); |
| 1352 | isis_print_paths (vty, area->spftree6[level]->paths); |
| 1353 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1354 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1355 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1356 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1357 | |
| 1358 | return CMD_SUCCESS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1359 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1360 | |
| 1361 | DEFUN (show_isis_topology_l1, |
| 1362 | show_isis_topology_l1_cmd, |
| 1363 | "show isis topology level-1", |
| 1364 | SHOW_STR |
| 1365 | "IS-IS information\n" |
| 1366 | "IS-IS paths to Intermediate Systems\n" |
| 1367 | "Paths to all level-1 routers in the area\n") |
| 1368 | { |
| 1369 | struct listnode *node; |
| 1370 | struct isis_area *area; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1371 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1372 | if (!isis->area_list || isis->area_list->count == 0) |
| 1373 | return CMD_SUCCESS; |
| 1374 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1375 | for (node = listhead (isis->area_list); node; nextnode (node)) |
| 1376 | { |
| 1377 | area = getdata (node); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1378 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1379 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1380 | VTY_NEWLINE); |
| 1381 | |
| 1382 | if (area->ip_circuits > 0 && area->spftree[0] |
| 1383 | && area->spftree[0]->paths->count > 0) |
| 1384 | { |
| 1385 | vty_out (vty, "IS-IS paths to level-1 routers that speak IP%s", |
| 1386 | VTY_NEWLINE); |
| 1387 | isis_print_paths (vty, area->spftree[0]->paths); |
| 1388 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1389 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1390 | if (area->ipv6_circuits > 0 && area->spftree6[0] |
| 1391 | && area->spftree6[0]->paths->count > 0) |
| 1392 | { |
| 1393 | vty_out (vty, "IS-IS paths to level-1 routers that speak IPv6%s", |
| 1394 | VTY_NEWLINE); |
| 1395 | isis_print_paths (vty, area->spftree6[0]->paths); |
| 1396 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1397 | #endif /* HAVE_IPV6 */ |
| 1398 | } |
| 1399 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1400 | return CMD_SUCCESS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1401 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1402 | |
| 1403 | DEFUN (show_isis_topology_l2, |
| 1404 | show_isis_topology_l2_cmd, |
| 1405 | "show isis topology level-2", |
| 1406 | SHOW_STR |
| 1407 | "IS-IS information\n" |
| 1408 | "IS-IS paths to Intermediate Systems\n" |
| 1409 | "Paths to all level-2 routers in the domain\n") |
| 1410 | { |
| 1411 | struct listnode *node; |
| 1412 | struct isis_area *area; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1413 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1414 | if (!isis->area_list || isis->area_list->count == 0) |
| 1415 | return CMD_SUCCESS; |
| 1416 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1417 | for (node = listhead (isis->area_list); node; nextnode (node)) |
| 1418 | { |
| 1419 | area = getdata (node); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1420 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1421 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1422 | VTY_NEWLINE); |
| 1423 | |
| 1424 | if (area->ip_circuits > 0 && area->spftree[1] |
| 1425 | && area->spftree[1]->paths->count > 0) |
| 1426 | { |
| 1427 | vty_out (vty, "IS-IS paths to level-2 routers that speak IP%s", |
| 1428 | VTY_NEWLINE); |
| 1429 | isis_print_paths (vty, area->spftree[1]->paths); |
| 1430 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1431 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1432 | if (area->ipv6_circuits > 0 && area->spftree6[1] |
| 1433 | && area->spftree6[1]->paths->count > 0) |
| 1434 | { |
| 1435 | vty_out (vty, "IS-IS paths to level-2 routers that speak IPv6%s", |
| 1436 | VTY_NEWLINE); |
| 1437 | isis_print_paths (vty, area->spftree6[1]->paths); |
| 1438 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1439 | #endif /* HAVE_IPV6 */ |
| 1440 | } |
| 1441 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1442 | return CMD_SUCCESS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1443 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1444 | |
| 1445 | void |
| 1446 | isis_spf_cmds_init () |
| 1447 | { |
| 1448 | install_element (VIEW_NODE, &show_isis_topology_cmd); |
| 1449 | install_element (VIEW_NODE, &show_isis_topology_l1_cmd); |
| 1450 | install_element (VIEW_NODE, &show_isis_topology_l2_cmd); |
| 1451 | |
| 1452 | install_element (ENABLE_NODE, &show_isis_topology_cmd); |
| 1453 | install_element (ENABLE_NODE, &show_isis_topology_l1_cmd); |
| 1454 | install_element (ENABLE_NODE, &show_isis_topology_l2_cmd); |
| 1455 | } |