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