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