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