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