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