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