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