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