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)); |
Christian Franke | 390f16e | 2015-11-10 18:04:44 +0100 | [diff] [blame] | 584 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 585 | /* FIXME: Should be minimal mtu? */ |
| 586 | lsp->pdu = stream_new (1500); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 587 | if (LSP_FRAGMENT (lsp_id) == 0) |
| 588 | lsp->lspu.frags = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 589 | lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu)); |
| 590 | lsp->lsp_header = (struct isis_link_state_hdr *) |
| 591 | (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN); |
| 592 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 593 | /* at first we fill the FIXED HEADER */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 594 | (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) : |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 595 | fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE); |
| 596 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 597 | /* now for the LSP HEADER */ |
| 598 | /* Minimal LSP PDU size */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 599 | 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] | 600 | memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 601 | lsp->lsp_header->checksum = checksum; /* Provided in network order */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 602 | lsp->lsp_header->seq_num = htonl (seq_num); |
| 603 | lsp->lsp_header->rem_lifetime = htons (rem_lifetime); |
| 604 | lsp->lsp_header->lsp_bits = lsp_bits; |
| 605 | lsp->level = level; |
| 606 | lsp->age_out = ZERO_AGE_LIFETIME; |
| 607 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 608 | stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 609 | |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 610 | if (isis->debugs & DEBUG_EVENTS) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 611 | zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x", |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 612 | sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id), |
| 613 | LSP_FRAGMENT (lsp->lsp_header->lsp_id), |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 614 | ntohl (lsp->lsp_header->pdu_len), |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 615 | ntohl (lsp->lsp_header->seq_num)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 616 | |
| 617 | return lsp; |
| 618 | } |
| 619 | |
| 620 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 621 | lsp_insert (struct isis_lsp *lsp, dict_t * lspdb) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 622 | { |
| 623 | dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 624 | if (lsp->lsp_header->seq_num != 0) |
| 625 | { |
| 626 | isis_spf_schedule (lsp->area, lsp->level); |
| 627 | #ifdef HAVE_IPV6 |
| 628 | isis_spf_schedule6 (lsp->area, lsp->level); |
| 629 | #endif |
| 630 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* |
| 634 | * Build a list of LSPs with non-zero ht bounded by start and stop ids |
| 635 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 636 | void |
| 637 | lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id, |
| 638 | struct list *list, dict_t * lspdb) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 639 | { |
| 640 | dnode_t *first, *last, *curr; |
| 641 | |
| 642 | first = dict_lower_bound (lspdb, start_id); |
| 643 | if (!first) |
| 644 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 645 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 646 | last = dict_upper_bound (lspdb, stop_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 647 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 648 | curr = first; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 649 | |
| 650 | if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 651 | listnode_add (list, first->dict_data); |
| 652 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 653 | while (curr) |
| 654 | { |
| 655 | curr = dict_next (lspdb, curr); |
| 656 | if (curr && |
| 657 | ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime) |
| 658 | listnode_add (list, curr->dict_data); |
| 659 | if (curr == last) |
| 660 | break; |
| 661 | } |
| 662 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 663 | return; |
| 664 | } |
| 665 | |
| 666 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 667 | * 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] | 668 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 669 | void |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 670 | 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] | 671 | struct list *list, dict_t * lspdb) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 672 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 673 | u_char count; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 674 | dnode_t *first, *last, *curr; |
| 675 | |
| 676 | first = dict_lower_bound (lspdb, start_id); |
| 677 | if (!first) |
| 678 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 679 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 680 | last = dict_upper_bound (lspdb, stop_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 681 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 682 | curr = first; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 683 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 684 | listnode_add (list, first->dict_data); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 685 | count = 1; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 686 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 687 | while (curr) |
| 688 | { |
| 689 | curr = dict_next (lspdb, curr); |
| 690 | if (curr) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 691 | { |
| 692 | listnode_add (list, curr->dict_data); |
| 693 | count++; |
| 694 | } |
| 695 | if (count == num_lsps || curr == last) |
| 696 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 697 | } |
| 698 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * Build a list of LSPs with SSN flag set for the given circuit |
| 704 | */ |
| 705 | void |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 706 | lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps, |
| 707 | struct list *list, dict_t * lspdb) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 708 | { |
| 709 | dnode_t *dnode, *next; |
| 710 | struct isis_lsp *lsp; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 711 | u_char count = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 712 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 713 | dnode = dict_first (lspdb); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 714 | while (dnode != NULL) |
| 715 | { |
| 716 | next = dict_next (lspdb, dnode); |
| 717 | lsp = dnode_get (dnode); |
| 718 | if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit)) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 719 | { |
| 720 | listnode_add (list, lsp); |
| 721 | ++count; |
| 722 | } |
| 723 | if (count == num_lsps) |
| 724 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 725 | dnode = next; |
| 726 | } |
| 727 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 728 | return; |
| 729 | } |
| 730 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 731 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 732 | lsp_set_time (struct isis_lsp *lsp) |
| 733 | { |
| 734 | assert (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 735 | |
| 736 | if (lsp->lsp_header->rem_lifetime == 0) |
| 737 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 738 | if (lsp->age_out > 0) |
| 739 | lsp->age_out--; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 740 | return; |
| 741 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 742 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 743 | lsp->lsp_header->rem_lifetime = |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 744 | htons (ntohs (lsp->lsp_header->rem_lifetime) - 1); |
| 745 | } |
| 746 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 747 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 748 | lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 749 | { |
| 750 | struct isis_dynhn *dyn = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 751 | u_char id[SYSID_STRLEN]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 752 | |
| 753 | if (dynhost) |
| 754 | dyn = dynhn_find_by_id (lsp_id); |
| 755 | else |
| 756 | dyn = NULL; |
| 757 | |
| 758 | if (dyn) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 759 | sprintf ((char *)id, "%.14s", dyn->name.name); |
| 760 | else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost) |
| 761 | sprintf ((char *)id, "%.14s", unix_hostname ()); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 762 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 763 | memcpy (id, sysid_print (lsp_id), 15); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 764 | if (frag) |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 765 | sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id), |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 766 | LSP_FRAGMENT (lsp_id)); |
| 767 | else |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 768 | sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 769 | } |
| 770 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 771 | /* Convert the lsp attribute bits to attribute string */ |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 772 | const char * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 773 | lsp_bits2string (u_char * lsp_bits) |
| 774 | { |
| 775 | char *pos = lsp_bits_string; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 776 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 777 | if (!*lsp_bits) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 778 | return " none"; |
| 779 | |
| 780 | /* we only focus on the default metric */ |
| 781 | pos += sprintf (pos, "%d/", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 782 | ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 783 | |
| 784 | pos += sprintf (pos, "%d/", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 785 | ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 786 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 787 | pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0); |
| 788 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 789 | *(pos) = '\0'; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 790 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 791 | return lsp_bits_string; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* this function prints the lsp on show isis database */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 795 | void |
| 796 | lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 797 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 798 | u_char LSPid[255]; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 799 | char age_out[8]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 800 | |
| 801 | lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 802 | vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' '); |
| 803 | vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len)); |
| 804 | vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num)); |
| 805 | vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 806 | if (ntohs (lsp->lsp_header->rem_lifetime) == 0) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 807 | { |
| 808 | snprintf (age_out, 8, "(%u)", lsp->age_out); |
| 809 | age_out[7] = '\0'; |
| 810 | vty_out (vty, "%7s ", age_out); |
| 811 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 812 | else |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 813 | vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime)); |
| 814 | vty_out (vty, "%s%s", |
| 815 | lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 818 | void |
| 819 | lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 820 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 821 | struct area_addr *area_addr; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 822 | int i; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 823 | struct listnode *lnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 824 | struct is_neigh *is_neigh; |
| 825 | struct te_is_neigh *te_is_neigh; |
| 826 | struct ipv4_reachability *ipv4_reach; |
| 827 | struct in_addr *ipv4_addr; |
| 828 | struct te_ipv4_reachability *te_ipv4_reach; |
| 829 | #ifdef HAVE_IPV6 |
| 830 | struct ipv6_reachability *ipv6_reach; |
| 831 | struct in6_addr in6; |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 832 | u_char buff[BUFSIZ]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 833 | #endif |
| 834 | u_char LSPid[255]; |
| 835 | u_char hostname[255]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 836 | u_char ipv4_reach_prefix[20]; |
| 837 | u_char ipv4_reach_mask[20]; |
| 838 | u_char ipv4_address[20]; |
| 839 | |
| 840 | lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 841 | lsp_print (lsp, vty, dynhost); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 842 | |
| 843 | /* for all area address */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 844 | if (lsp->tlv_data.area_addrs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 845 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 846 | { |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 847 | vty_out (vty, " Area Address: %s%s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 848 | isonet_print (area_addr->area_addr, area_addr->addr_len), |
| 849 | VTY_NEWLINE); |
| 850 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 851 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 852 | /* for the nlpid tlv */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 853 | if (lsp->tlv_data.nlpids) |
| 854 | { |
| 855 | for (i = 0; i < lsp->tlv_data.nlpids->count; i++) |
| 856 | { |
| 857 | switch (lsp->tlv_data.nlpids->nlpids[i]) |
| 858 | { |
| 859 | case NLPID_IP: |
| 860 | case NLPID_IPV6: |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 861 | vty_out (vty, " NLPID : 0x%X%s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 862 | lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE); |
| 863 | break; |
| 864 | default: |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 865 | vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 866 | break; |
| 867 | } |
| 868 | } |
| 869 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 870 | |
| 871 | /* for the hostname tlv */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 872 | if (lsp->tlv_data.hostname) |
| 873 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 874 | bzero (hostname, sizeof (hostname)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 875 | memcpy (hostname, lsp->tlv_data.hostname->name, |
| 876 | lsp->tlv_data.hostname->namelen); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 877 | vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 878 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 879 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 880 | /* authentication tlv */ |
| 881 | if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED) |
| 882 | { |
| 883 | if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5) |
| 884 | vty_out (vty, " Auth type : md5%s", VTY_NEWLINE); |
| 885 | else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT) |
| 886 | vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE); |
| 887 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 888 | |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 889 | /* TE router id */ |
| 890 | if (lsp->tlv_data.router_id) |
| 891 | { |
| 892 | memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id), |
| 893 | sizeof (ipv4_address)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 894 | vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE); |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 897 | if (lsp->tlv_data.ipv4_addrs) |
| 898 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr)) |
| 899 | { |
| 900 | memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address)); |
| 901 | vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE); |
| 902 | } |
| 903 | |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 904 | /* for the IS neighbor tlv */ |
| 905 | if (lsp->tlv_data.is_neighs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 906 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh)) |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 907 | { |
| 908 | lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 909 | vty_out (vty, " Metric : %-8d IS : %s%s", |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 910 | is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE); |
| 911 | } |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 912 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 913 | /* for the internal reachable tlv */ |
| 914 | if (lsp->tlv_data.ipv4_int_reachs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 915 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode, |
| 916 | ipv4_reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 917 | { |
| 918 | memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), |
| 919 | sizeof (ipv4_reach_prefix)); |
| 920 | memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask), |
| 921 | sizeof (ipv4_reach_mask)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 922 | vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 923 | ipv4_reach->metrics.metric_default, ipv4_reach_prefix, |
| 924 | ipv4_reach_mask, VTY_NEWLINE); |
| 925 | } |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 926 | |
| 927 | /* for the external reachable tlv */ |
| 928 | if (lsp->tlv_data.ipv4_ext_reachs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 929 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode, |
| 930 | ipv4_reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 931 | { |
| 932 | memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), |
| 933 | sizeof (ipv4_reach_prefix)); |
| 934 | memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask), |
| 935 | sizeof (ipv4_reach_mask)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 936 | vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 937 | ipv4_reach->metrics.metric_default, ipv4_reach_prefix, |
| 938 | ipv4_reach_mask, VTY_NEWLINE); |
| 939 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 940 | |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 941 | /* IPv6 tlv */ |
| 942 | #ifdef HAVE_IPV6 |
| 943 | if (lsp->tlv_data.ipv6_reachs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 944 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 945 | { |
| 946 | memset (&in6, 0, sizeof (in6)); |
| 947 | memcpy (in6.s6_addr, ipv6_reach->prefix, |
| 948 | PSIZE (ipv6_reach->prefix_len)); |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 949 | inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ); |
David Lamparter | 6db3ef6 | 2015-03-03 09:07:43 +0100 | [diff] [blame] | 950 | if ((ipv6_reach->control_info & |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 951 | CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 952 | vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 953 | ntohl (ipv6_reach->metric), |
| 954 | buff, ipv6_reach->prefix_len, VTY_NEWLINE); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 955 | else |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 956 | vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 957 | ntohl (ipv6_reach->metric), |
| 958 | buff, ipv6_reach->prefix_len, VTY_NEWLINE); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 959 | } |
| 960 | #endif |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 961 | |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 962 | /* TE IS neighbor tlv */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 963 | if (lsp->tlv_data.te_is_neighs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 964 | 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] | 965 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 966 | lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 967 | vty_out (vty, " Metric : %-8d IS-Extended : %s%s", |
| 968 | GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 969 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 970 | |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 971 | /* TE IPv4 tlv */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 972 | if (lsp->tlv_data.te_ipv4_reachs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 973 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode, |
| 974 | te_ipv4_reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 975 | { |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 976 | /* FIXME: There should be better way to output this stuff. */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 977 | vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s", |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 978 | ntohl (te_ipv4_reach->te_metric), |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 979 | inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start, |
| 980 | te_ipv4_reach->control)), |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 981 | te_ipv4_reach->control & 0x3F, VTY_NEWLINE); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 982 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 983 | vty_out (vty, "%s", VTY_NEWLINE); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 984 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 985 | return; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /* print all the lsps info in the local lspdb */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 989 | int |
| 990 | lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 991 | { |
| 992 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 993 | dnode_t *node = dict_first (lspdb), *next; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 994 | int lsp_count = 0; |
| 995 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 996 | if (detail == ISIS_UI_LEVEL_BRIEF) |
| 997 | { |
| 998 | while (node != NULL) |
| 999 | { |
| 1000 | /* I think it is unnecessary, so I comment it out */ |
| 1001 | /* dict_contains (lspdb, node); */ |
| 1002 | next = dict_next (lspdb, node); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1003 | lsp_print (dnode_get (node), vty, dynhost); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1004 | node = next; |
| 1005 | lsp_count++; |
| 1006 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1007 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1008 | else if (detail == ISIS_UI_LEVEL_DETAIL) |
| 1009 | { |
| 1010 | while (node != NULL) |
| 1011 | { |
| 1012 | next = dict_next (lspdb, node); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1013 | lsp_print_detail (dnode_get (node), vty, dynhost); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1014 | node = next; |
| 1015 | lsp_count++; |
| 1016 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1017 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1018 | |
| 1019 | return lsp_count; |
| 1020 | } |
| 1021 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1022 | #define FRAG_THOLD(S,T) \ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1023 | ((STREAM_SIZE(S)*T)/100) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1024 | |
| 1025 | /* stream*, area->lsp_frag_threshold, increment */ |
| 1026 | #define FRAG_NEEDED(S,T,I) \ |
| 1027 | (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T)) |
| 1028 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1029 | /* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have |
| 1030 | * variable length (TE TLVs, sub TLVs). */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1031 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1032 | lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1033 | int tlvsize, int frag_thold, |
| 1034 | int tlv_build_func (struct list *, struct stream *)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1035 | { |
| 1036 | int count, i; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1037 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1038 | /* can we fit all ? */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1039 | if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2)) |
| 1040 | { |
| 1041 | tlv_build_func (*from, lsp->pdu); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1042 | if (listcount (*to) != 0) |
| 1043 | { |
| 1044 | struct listnode *node, *nextnode; |
| 1045 | void *elem; |
| 1046 | |
| 1047 | for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem)) |
| 1048 | { |
| 1049 | listnode_add (*to, elem); |
| 1050 | list_delete_node (*from, node); |
| 1051 | } |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | list_free (*to); |
| 1056 | *to = *from; |
| 1057 | *from = NULL; |
| 1058 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1059 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1060 | else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2)) |
| 1061 | { |
| 1062 | /* fit all we can */ |
| 1063 | count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 - |
| 1064 | (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1065 | count = count / tlvsize; |
| 1066 | if (count > (int)listcount (*from)) |
| 1067 | count = listcount (*from); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1068 | for (i = 0; i < count; i++) |
| 1069 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1070 | listnode_add (*to, listgetdata (listhead (*from))); |
| 1071 | listnode_delete (*from, listgetdata (listhead (*from))); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1072 | } |
| 1073 | tlv_build_func (*to, lsp->pdu); |
| 1074 | } |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 1075 | lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1076 | return; |
| 1077 | } |
| 1078 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1079 | static u_int16_t |
| 1080 | lsp_rem_lifetime (struct isis_area *area, int level) |
| 1081 | { |
| 1082 | u_int16_t rem_lifetime; |
| 1083 | |
| 1084 | /* Add jitter to configured LSP lifetime */ |
| 1085 | rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1], |
| 1086 | MAX_AGE_JITTER); |
| 1087 | |
| 1088 | /* No jitter if the max refresh will be less than configure gen interval */ |
| 1089 | if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300)) |
| 1090 | rem_lifetime = area->max_lsp_lifetime[level - 1]; |
| 1091 | |
| 1092 | return rem_lifetime; |
| 1093 | } |
| 1094 | |
| 1095 | static u_int16_t |
| 1096 | lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime) |
| 1097 | { |
| 1098 | struct isis_area *area = lsp->area; |
| 1099 | int level = lsp->level; |
| 1100 | u_int16_t refresh_time; |
| 1101 | |
| 1102 | /* Add jitter to LSP refresh time */ |
| 1103 | refresh_time = isis_jitter (area->lsp_refresh[level - 1], |
| 1104 | MAX_LSP_GEN_JITTER); |
| 1105 | |
| 1106 | /* RFC 4444 : make sure the refresh time is at least less than 300 |
| 1107 | * of the remaining lifetime and more than gen interval */ |
| 1108 | if (refresh_time <= area->lsp_gen_interval[level - 1] || |
| 1109 | refresh_time > (rem_lifetime - 300)) |
| 1110 | refresh_time = rem_lifetime - 300; |
| 1111 | |
| 1112 | assert (area->lsp_gen_interval[level - 1] < refresh_time); |
| 1113 | |
| 1114 | return refresh_time; |
| 1115 | } |
| 1116 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1117 | static struct isis_lsp * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1118 | lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area, |
| 1119 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1120 | { |
| 1121 | struct isis_lsp *lsp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1122 | u_char frag_id[ISIS_SYS_ID_LEN + 2]; |
| 1123 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1124 | memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1); |
| 1125 | LSP_FRAGMENT (frag_id) = frag_num; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1126 | /* FIXME add authentication TLV for fragment LSPs */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1127 | lsp = lsp_search (frag_id, area->lspdb[level - 1]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1128 | if (lsp) |
| 1129 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1130 | /* Clear the TLVs */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1131 | lsp_clear_data (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1132 | return lsp; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1133 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1134 | lsp = lsp_new (frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0, |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 1135 | lsp_bits_generate (level, area->overload_bit, |
| 1136 | area->attached_bit), 0, level); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1137 | lsp->area = area; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1138 | lsp->own_lsp = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1139 | lsp_insert (lsp, area->lspdb[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1140 | listnode_add (lsp0->lspu.frags, lsp); |
| 1141 | lsp->lspu.zero_lsp = lsp0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1142 | return lsp; |
| 1143 | } |
| 1144 | |
| 1145 | /* |
| 1146 | * Builds the LSP data part. This func creates a new frag whenever |
| 1147 | * area->lsp_frag_threshold is exceeded. |
| 1148 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1149 | static void |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1150 | lsp_build (struct isis_lsp *lsp, struct isis_area *area) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1151 | { |
| 1152 | struct is_neigh *is_neigh; |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1153 | struct te_is_neigh *te_is_neigh; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1154 | struct listnode *node, *ipnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1155 | int level = lsp->level; |
| 1156 | struct isis_circuit *circuit; |
| 1157 | struct prefix_ipv4 *ipv4; |
| 1158 | struct ipv4_reachability *ipreach; |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1159 | struct te_ipv4_reachability *te_ipreach; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1160 | struct isis_adjacency *nei; |
| 1161 | #ifdef HAVE_IPV6 |
hasso | 6785157 | 2004-09-21 14:17:04 +0000 | [diff] [blame] | 1162 | struct prefix_ipv6 *ipv6, *ip6prefix; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1163 | struct ipv6_reachability *ip6reach; |
| 1164 | #endif /* HAVE_IPV6 */ |
| 1165 | struct tlvs tlv_data; |
| 1166 | struct isis_lsp *lsp0 = lsp; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1167 | struct in_addr *routerid; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1168 | uint32_t expected = 0, found = 0; |
| 1169 | uint32_t metric; |
| 1170 | u_char zero_id[ISIS_SYS_ID_LEN + 1]; |
| 1171 | int retval = ISIS_OK; |
| 1172 | |
| 1173 | /* |
| 1174 | * Building the zero lsp |
| 1175 | */ |
| 1176 | memset (zero_id, 0, ISIS_SYS_ID_LEN + 1); |
| 1177 | |
| 1178 | /* Reset stream endp. Stream is always there and on every LSP refresh only |
| 1179 | * TLV part of it is overwritten. So we must seek past header we will not |
| 1180 | * touch. */ |
| 1181 | stream_reset (lsp->pdu); |
| 1182 | stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 1183 | |
| 1184 | /* |
| 1185 | * Add the authentication info if its present |
| 1186 | */ |
| 1187 | lsp_auth_add (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1188 | |
| 1189 | /* |
| 1190 | * First add the tlvs related to area |
| 1191 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1192 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1193 | /* Area addresses */ |
| 1194 | if (lsp->tlv_data.area_addrs == NULL) |
| 1195 | lsp->tlv_data.area_addrs = list_new (); |
| 1196 | list_add_list (lsp->tlv_data.area_addrs, area->area_addrs); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1197 | if (listcount (lsp->tlv_data.area_addrs) > 0) |
| 1198 | tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu); |
| 1199 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1200 | /* Protocols Supported */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1201 | if (area->ip_circuits > 0 |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1202 | #ifdef HAVE_IPV6 |
| 1203 | || area->ipv6_circuits > 0 |
| 1204 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1205 | ) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1206 | { |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 1207 | lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1208 | lsp->tlv_data.nlpids->count = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1209 | if (area->ip_circuits > 0) |
| 1210 | { |
| 1211 | lsp->tlv_data.nlpids->count++; |
| 1212 | lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP; |
| 1213 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1214 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1215 | if (area->ipv6_circuits > 0) |
| 1216 | { |
| 1217 | lsp->tlv_data.nlpids->count++; |
| 1218 | lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] = |
| 1219 | NLPID_IPV6; |
| 1220 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1221 | #endif /* HAVE_IPV6 */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1222 | tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1223 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1224 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1225 | /* Dynamic Hostname */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1226 | if (area->dynhostname) |
| 1227 | { |
| 1228 | lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, |
| 1229 | sizeof (struct hostname)); |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 1230 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1231 | memcpy (lsp->tlv_data.hostname->name, unix_hostname (), |
| 1232 | strlen (unix_hostname ())); |
| 1233 | lsp->tlv_data.hostname->namelen = strlen (unix_hostname ()); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1234 | tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1235 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1236 | |
hasso | 81ad8f6 | 2005-09-26 17:58:24 +0000 | [diff] [blame] | 1237 | /* IPv4 address and TE router ID TLVs. In case of the first one we don't |
| 1238 | * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into |
| 1239 | * LSP and this address is same as router id. */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1240 | if (isis->router_id != 0) |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1241 | { |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1242 | if (lsp->tlv_data.ipv4_addrs == NULL) |
hasso | be7d65d | 2005-09-02 01:38:16 +0000 | [diff] [blame] | 1243 | { |
| 1244 | lsp->tlv_data.ipv4_addrs = list_new (); |
| 1245 | lsp->tlv_data.ipv4_addrs->del = free_tlv; |
| 1246 | } |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1247 | |
| 1248 | routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1249 | routerid->s_addr = isis->router_id; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1250 | listnode_add (lsp->tlv_data.ipv4_addrs, routerid); |
hasso | 81ad8f6 | 2005-09-26 17:58:24 +0000 | [diff] [blame] | 1251 | tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1252 | |
hasso | 81ad8f6 | 2005-09-26 17:58:24 +0000 | [diff] [blame] | 1253 | /* Exactly same data is put into TE router ID TLV, but only if new style |
| 1254 | * TLV's are in use. */ |
| 1255 | if (area->newmetric) |
| 1256 | { |
| 1257 | lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV, |
| 1258 | sizeof (struct in_addr)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1259 | lsp->tlv_data.router_id->id.s_addr = isis->router_id; |
| 1260 | tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu, |
| 1261 | TE_ROUTER_ID); |
hasso | 81ad8f6 | 2005-09-26 17:58:24 +0000 | [diff] [blame] | 1262 | } |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1263 | } |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 1264 | |
hasso | 81ad8f6 | 2005-09-26 17:58:24 +0000 | [diff] [blame] | 1265 | memset (&tlv_data, 0, sizeof (struct tlvs)); |
| 1266 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 1267 | #ifdef TOPOLOGY_GENERATE |
| 1268 | /* If topology exists (and we create topology for level 1 only), create |
| 1269 | * (hardcoded) link to topology. */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1270 | if (area->topology && level == IS_LEVEL_1) |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 1271 | { |
| 1272 | if (tlv_data.is_neighs == NULL) |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1273 | { |
| 1274 | tlv_data.is_neighs = list_new (); |
| 1275 | tlv_data.is_neighs->del = free_tlv; |
| 1276 | } |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1277 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 1278 | |
| 1279 | memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN); |
| 1280 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF); |
| 1281 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF); |
| 1282 | is_neigh->metrics.metric_default = 0x01; |
| 1283 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; |
| 1284 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; |
| 1285 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; |
| 1286 | listnode_add (tlv_data.is_neighs, is_neigh); |
| 1287 | } |
| 1288 | #endif /* TOPOLOGY_GENERATE */ |
| 1289 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1290 | /* |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1291 | * Then build lists of tlvs related to circuits |
| 1292 | */ |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1293 | for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1294 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1295 | if (circuit->state != C_STATE_UP) |
| 1296 | continue; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1297 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1298 | /* |
| 1299 | * Add IPv4 internal reachability of this circuit |
| 1300 | */ |
| 1301 | if (circuit->ip_router && circuit->ip_addrs && |
| 1302 | circuit->ip_addrs->count > 0) |
| 1303 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1304 | if (area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1305 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1306 | if (tlv_data.ipv4_int_reachs == NULL) |
| 1307 | { |
| 1308 | tlv_data.ipv4_int_reachs = list_new (); |
| 1309 | tlv_data.ipv4_int_reachs->del = free_tlv; |
| 1310 | } |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1311 | for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4)) |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1312 | { |
| 1313 | ipreach = |
| 1314 | XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability)); |
| 1315 | ipreach->metrics = circuit->metrics[level - 1]; |
| 1316 | masklen2ip (ipv4->prefixlen, &ipreach->mask); |
| 1317 | ipreach->prefix.s_addr = ((ipreach->mask.s_addr) & |
| 1318 | (ipv4->prefix.s_addr)); |
| 1319 | listnode_add (tlv_data.ipv4_int_reachs, ipreach); |
| 1320 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1321 | } |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1322 | if (area->newmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1323 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1324 | if (tlv_data.te_ipv4_reachs == NULL) |
| 1325 | { |
| 1326 | tlv_data.te_ipv4_reachs = list_new (); |
| 1327 | tlv_data.te_ipv4_reachs->del = free_tlv; |
| 1328 | } |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1329 | for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4)) |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1330 | { |
| 1331 | /* FIXME All this assumes that we have no sub TLVs. */ |
| 1332 | te_ipreach = XCALLOC (MTYPE_ISIS_TLV, |
| 1333 | sizeof (struct te_ipv4_reachability) + |
| 1334 | ((ipv4->prefixlen + 7)/8) - 1); |
hasso | 309ddb1 | 2005-09-26 18:06:47 +0000 | [diff] [blame] | 1335 | |
| 1336 | if (area->oldmetric) |
| 1337 | te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default); |
| 1338 | else |
| 1339 | te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]); |
| 1340 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1341 | te_ipreach->control = (ipv4->prefixlen & 0x3F); |
| 1342 | memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr, |
| 1343 | (ipv4->prefixlen + 7)/8); |
| 1344 | listnode_add (tlv_data.te_ipv4_reachs, te_ipreach); |
| 1345 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1346 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1347 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1348 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1349 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1350 | /* |
| 1351 | * Add IPv6 reachability of this circuit |
| 1352 | */ |
| 1353 | if (circuit->ipv6_router && circuit->ipv6_non_link && |
| 1354 | circuit->ipv6_non_link->count > 0) |
| 1355 | { |
| 1356 | |
| 1357 | if (tlv_data.ipv6_reachs == NULL) |
| 1358 | { |
| 1359 | tlv_data.ipv6_reachs = list_new (); |
hasso | be7d65d | 2005-09-02 01:38:16 +0000 | [diff] [blame] | 1360 | tlv_data.ipv6_reachs->del = free_tlv; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1361 | } |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1362 | for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1363 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1364 | ip6reach = |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 1365 | XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability)); |
hasso | 309ddb1 | 2005-09-26 18:06:47 +0000 | [diff] [blame] | 1366 | |
| 1367 | if (area->oldmetric) |
| 1368 | ip6reach->metric = |
| 1369 | htonl (circuit->metrics[level - 1].metric_default); |
| 1370 | else |
| 1371 | ip6reach->metric = htonl (circuit->te_metric[level - 1]); |
| 1372 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1373 | ip6reach->control_info = 0; |
| 1374 | ip6reach->prefix_len = ipv6->prefixlen; |
hasso | 6785157 | 2004-09-21 14:17:04 +0000 | [diff] [blame] | 1375 | memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix)); |
| 1376 | apply_mask_ipv6 (ip6prefix); |
| 1377 | memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr, |
| 1378 | sizeof (ip6reach->prefix)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1379 | listnode_add (tlv_data.ipv6_reachs, ip6reach); |
| 1380 | } |
| 1381 | } |
| 1382 | #endif /* HAVE_IPV6 */ |
| 1383 | |
| 1384 | switch (circuit->circ_type) |
| 1385 | { |
| 1386 | case CIRCUIT_T_BROADCAST: |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1387 | if (level & circuit->is_type) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1388 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1389 | if (area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1390 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1391 | if (tlv_data.is_neighs == NULL) |
| 1392 | { |
| 1393 | tlv_data.is_neighs = list_new (); |
| 1394 | tlv_data.is_neighs->del = free_tlv; |
| 1395 | } |
| 1396 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1397 | if (level == IS_LEVEL_1) |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1398 | memcpy (is_neigh->neigh_id, |
| 1399 | circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1400 | else |
| 1401 | memcpy (is_neigh->neigh_id, |
| 1402 | circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1403 | is_neigh->metrics = circuit->metrics[level - 1]; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1404 | if (!memcmp (is_neigh->neigh_id, zero_id, |
| 1405 | ISIS_SYS_ID_LEN + 1)) |
| 1406 | XFREE (MTYPE_ISIS_TLV, is_neigh); |
| 1407 | else |
| 1408 | listnode_add (tlv_data.is_neighs, is_neigh); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1409 | } |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1410 | if (area->newmetric) |
| 1411 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1412 | if (tlv_data.te_is_neighs == NULL) |
| 1413 | { |
| 1414 | tlv_data.te_is_neighs = list_new (); |
| 1415 | tlv_data.te_is_neighs->del = free_tlv; |
| 1416 | } |
| 1417 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, |
| 1418 | sizeof (struct te_is_neigh)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1419 | if (level == IS_LEVEL_1) |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1420 | memcpy (te_is_neigh->neigh_id, |
| 1421 | circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 1422 | else |
| 1423 | memcpy (te_is_neigh->neigh_id, |
| 1424 | circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
hasso | 309ddb1 | 2005-09-26 18:06:47 +0000 | [diff] [blame] | 1425 | if (area->oldmetric) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1426 | metric = circuit->metrics[level - 1].metric_default; |
hasso | 309ddb1 | 2005-09-26 18:06:47 +0000 | [diff] [blame] | 1427 | else |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1428 | metric = circuit->te_metric[level - 1]; |
| 1429 | SET_TE_METRIC(te_is_neigh, metric); |
| 1430 | if (!memcmp (te_is_neigh->neigh_id, zero_id, |
| 1431 | ISIS_SYS_ID_LEN + 1)) |
| 1432 | XFREE (MTYPE_ISIS_TLV, te_is_neigh); |
| 1433 | else |
| 1434 | listnode_add (tlv_data.te_is_neighs, te_is_neigh); |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1435 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1436 | } |
| 1437 | break; |
| 1438 | case CIRCUIT_T_P2P: |
| 1439 | nei = circuit->u.p2p.neighbor; |
| 1440 | if (nei && (level & nei->circuit_t)) |
| 1441 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1442 | if (area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1443 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1444 | if (tlv_data.is_neighs == NULL) |
| 1445 | { |
| 1446 | tlv_data.is_neighs = list_new (); |
| 1447 | tlv_data.is_neighs->del = free_tlv; |
| 1448 | } |
| 1449 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
| 1450 | memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN); |
| 1451 | is_neigh->metrics = circuit->metrics[level - 1]; |
| 1452 | listnode_add (tlv_data.is_neighs, is_neigh); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1453 | } |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1454 | if (area->newmetric) |
| 1455 | { |
| 1456 | uint32_t metric; |
| 1457 | |
| 1458 | if (tlv_data.te_is_neighs == NULL) |
| 1459 | { |
| 1460 | tlv_data.te_is_neighs = list_new (); |
| 1461 | tlv_data.te_is_neighs->del = free_tlv; |
| 1462 | } |
| 1463 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, |
| 1464 | sizeof (struct te_is_neigh)); |
| 1465 | memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1466 | metric = circuit->te_metric[level - 1]; |
| 1467 | SET_TE_METRIC(te_is_neigh, metric); |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1468 | listnode_add (tlv_data.te_is_neighs, te_is_neigh); |
| 1469 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1470 | } |
| 1471 | break; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1472 | case CIRCUIT_T_LOOPBACK: |
| 1473 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1474 | default: |
| 1475 | zlog_warn ("lsp_area_create: unknown circuit type"); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs)) |
| 1480 | { |
| 1481 | if (lsp->tlv_data.ipv4_int_reachs == NULL) |
| 1482 | lsp->tlv_data.ipv4_int_reachs = list_new (); |
| 1483 | lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs, |
| 1484 | &lsp->tlv_data.ipv4_int_reachs, |
| 1485 | IPV4_REACH_LEN, area->lsp_frag_threshold, |
| 1486 | tlv_add_ipv4_reachs); |
| 1487 | if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs)) |
| 1488 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1489 | lsp0, area, level); |
| 1490 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1491 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1492 | /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit() |
| 1493 | * for now. lsp_tlv_fit() needs to be fixed to deal with variable length |
| 1494 | * TLVs (sub TLVs!). */ |
| 1495 | while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs)) |
| 1496 | { |
| 1497 | if (lsp->tlv_data.te_ipv4_reachs == NULL) |
| 1498 | lsp->tlv_data.te_ipv4_reachs = list_new (); |
| 1499 | lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs, |
| 1500 | &lsp->tlv_data.te_ipv4_reachs, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1501 | TE_IPV4_REACH_LEN, area->lsp_frag_threshold, |
| 1502 | tlv_add_te_ipv4_reachs); |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1503 | if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs)) |
| 1504 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1505 | lsp0, area, level); |
| 1506 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1507 | |
| 1508 | #ifdef HAVE_IPV6 |
| 1509 | while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs)) |
| 1510 | { |
| 1511 | if (lsp->tlv_data.ipv6_reachs == NULL) |
| 1512 | lsp->tlv_data.ipv6_reachs = list_new (); |
| 1513 | lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs, |
| 1514 | &lsp->tlv_data.ipv6_reachs, |
| 1515 | IPV6_REACH_LEN, area->lsp_frag_threshold, |
| 1516 | tlv_add_ipv6_reachs); |
| 1517 | if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs)) |
| 1518 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1519 | lsp0, area, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1520 | } |
| 1521 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1522 | |
| 1523 | while (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 1524 | { |
| 1525 | if (lsp->tlv_data.is_neighs == NULL) |
| 1526 | lsp->tlv_data.is_neighs = list_new (); |
| 1527 | lsp_tlv_fit (lsp, &tlv_data.is_neighs, |
| 1528 | &lsp->tlv_data.is_neighs, |
| 1529 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 1530 | tlv_add_is_neighs); |
| 1531 | if (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 1532 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1533 | lsp0, area, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1534 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1535 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1536 | while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs)) |
| 1537 | { |
| 1538 | if (lsp->tlv_data.te_is_neighs == NULL) |
| 1539 | lsp->tlv_data.te_is_neighs = list_new (); |
| 1540 | lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs, |
| 1541 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 1542 | tlv_add_te_is_neighs); |
| 1543 | if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs)) |
| 1544 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 1545 | lsp0, area, level); |
| 1546 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1547 | lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu)); |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1548 | |
| 1549 | free_tlvs (&tlv_data); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1550 | |
| 1551 | /* Validate the LSP */ |
| 1552 | retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) + |
| 1553 | ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN, |
| 1554 | stream_get_endp (lsp->pdu) - |
| 1555 | ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN, |
| 1556 | &expected, &found, &tlv_data, NULL); |
| 1557 | assert (retval == ISIS_OK); |
| 1558 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1559 | return; |
| 1560 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1561 | |
| 1562 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1563 | * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1564 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1565 | int |
| 1566 | lsp_generate (struct isis_area *area, int level) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1567 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1568 | struct isis_lsp *oldlsp, *newlsp; |
| 1569 | u_int32_t seq_num = 0; |
| 1570 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1571 | u_int16_t rem_lifetime, refresh_time; |
| 1572 | |
| 1573 | if ((area == NULL) || (area->is_type & level) != level) |
| 1574 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1575 | |
| 1576 | memset (&lspid, 0, ISIS_SYS_ID_LEN + 2); |
| 1577 | memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN); |
| 1578 | |
| 1579 | /* only builds the lsp if the area shares the level */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1580 | oldlsp = lsp_search (lspid, area->lspdb[level - 1]); |
| 1581 | if (oldlsp) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1582 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1583 | /* FIXME: we should actually initiate a purge */ |
| 1584 | seq_num = ntohl (oldlsp->lsp_header->seq_num); |
| 1585 | lsp_search_and_destroy (oldlsp->lsp_header->lsp_id, |
| 1586 | area->lspdb[level - 1]); |
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 | rem_lifetime = lsp_rem_lifetime (area, level); |
| 1589 | newlsp = lsp_new (lspid, rem_lifetime, seq_num, |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 1590 | area->is_type | area->overload_bit | area->attached_bit, |
| 1591 | 0, level); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1592 | newlsp->area = area; |
| 1593 | newlsp->own_lsp = 1; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1594 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1595 | lsp_insert (newlsp, area->lspdb[level - 1]); |
| 1596 | /* build_lsp_data (newlsp, area); */ |
| 1597 | lsp_build (newlsp, area); |
| 1598 | /* time to calculate our checksum */ |
| 1599 | lsp_seqnum_update (newlsp); |
| 1600 | lsp_set_all_srmflags (newlsp); |
| 1601 | |
| 1602 | refresh_time = lsp_refresh_time (newlsp, rem_lifetime); |
| 1603 | THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]); |
| 1604 | if (level == IS_LEVEL_1) |
| 1605 | THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1], |
| 1606 | lsp_l1_refresh, area, refresh_time); |
| 1607 | else if (level == IS_LEVEL_2) |
| 1608 | THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1], |
| 1609 | lsp_l2_refresh, area, refresh_time); |
| 1610 | |
| 1611 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1612 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1613 | zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, " |
| 1614 | "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us", |
| 1615 | area->area_tag, level, |
| 1616 | rawlspid_print (newlsp->lsp_header->lsp_id), |
| 1617 | ntohl (newlsp->lsp_header->pdu_len), |
| 1618 | ntohl (newlsp->lsp_header->seq_num), |
| 1619 | ntohs (newlsp->lsp_header->checksum), |
| 1620 | ntohs (newlsp->lsp_header->rem_lifetime), |
| 1621 | refresh_time); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1622 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1623 | |
| 1624 | return ISIS_OK; |
| 1625 | } |
| 1626 | |
| 1627 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1628 | * Search own LSPs, update holding time and set SRM |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1629 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1630 | static int |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1631 | lsp_regenerate (struct isis_area *area, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1632 | { |
David Lamparter | e8aca32 | 2012-11-27 01:10:30 +0000 | [diff] [blame] | 1633 | dict_t *lspdb; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1634 | struct isis_lsp *lsp, *frag; |
| 1635 | struct listnode *node; |
| 1636 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1637 | u_int16_t rem_lifetime, refresh_time; |
| 1638 | |
| 1639 | if ((area == NULL) || (area->is_type & level) != level) |
| 1640 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1641 | |
David Lamparter | e8aca32 | 2012-11-27 01:10:30 +0000 | [diff] [blame] | 1642 | lspdb = area->lspdb[level - 1]; |
| 1643 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1644 | memset (lspid, 0, ISIS_SYS_ID_LEN + 2); |
| 1645 | memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1646 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1647 | lsp = lsp_search (lspid, lspdb); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1648 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1649 | if (!lsp) |
| 1650 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1651 | zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!", |
| 1652 | area->area_tag, level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1653 | return ISIS_ERROR; |
| 1654 | } |
| 1655 | |
| 1656 | lsp_clear_data (lsp); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1657 | lsp_build (lsp, area); |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 1658 | lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit, |
| 1659 | area->attached_bit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1660 | rem_lifetime = lsp_rem_lifetime (area, level); |
| 1661 | lsp->lsp_header->rem_lifetime = htons (rem_lifetime); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1662 | lsp_seqnum_update (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1663 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1664 | lsp->last_generated = time (NULL); |
| 1665 | lsp_set_all_srmflags (lsp); |
| 1666 | for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag)) |
| 1667 | { |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1668 | frag->lsp_header->lsp_bits = lsp_bits_generate (level, |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 1669 | area->overload_bit, |
| 1670 | area->attached_bit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1671 | /* Set the lifetime values of all the fragments to the same value, |
| 1672 | * so that no fragment expires before the lsp is refreshed. |
| 1673 | */ |
| 1674 | frag->lsp_header->rem_lifetime = htons (rem_lifetime); |
| 1675 | lsp_set_all_srmflags (frag); |
| 1676 | } |
| 1677 | |
| 1678 | refresh_time = lsp_refresh_time (lsp, rem_lifetime); |
| 1679 | if (level == IS_LEVEL_1) |
| 1680 | THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1], |
| 1681 | lsp_l1_refresh, area, refresh_time); |
| 1682 | else if (level == IS_LEVEL_2) |
| 1683 | THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1], |
| 1684 | lsp_l2_refresh, area, refresh_time); |
| 1685 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1686 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1687 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1688 | zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, " |
| 1689 | "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us", |
| 1690 | area->area_tag, level, |
| 1691 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 1692 | ntohl (lsp->lsp_header->pdu_len), |
| 1693 | ntohl (lsp->lsp_header->seq_num), |
| 1694 | ntohs (lsp->lsp_header->checksum), |
| 1695 | ntohs (lsp->lsp_header->rem_lifetime), |
| 1696 | refresh_time); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1697 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1698 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1699 | return ISIS_OK; |
| 1700 | } |
| 1701 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1702 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1703 | * Something has changed or periodic refresh -> regenerate LSP |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1704 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1705 | static int |
| 1706 | lsp_l1_refresh (struct thread *thread) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1707 | { |
| 1708 | struct isis_area *area; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1709 | |
| 1710 | area = THREAD_ARG (thread); |
| 1711 | assert (area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1712 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1713 | area->t_lsp_refresh[0] = NULL; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1714 | area->lsp_regenerate_pending[0] = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1715 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1716 | if ((area->is_type & IS_LEVEL_1) == 0) |
| 1717 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1718 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1719 | return lsp_regenerate (area, IS_LEVEL_1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1722 | static int |
| 1723 | lsp_l2_refresh (struct thread *thread) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1724 | { |
| 1725 | struct isis_area *area; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1726 | |
| 1727 | area = THREAD_ARG (thread); |
| 1728 | assert (area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1729 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1730 | area->t_lsp_refresh[1] = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1731 | area->lsp_regenerate_pending[1] = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1732 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1733 | if ((area->is_type & IS_LEVEL_2) == 0) |
| 1734 | return ISIS_ERROR; |
| 1735 | |
| 1736 | return lsp_regenerate (area, IS_LEVEL_2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1739 | int |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1740 | lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1741 | { |
| 1742 | struct isis_lsp *lsp; |
| 1743 | u_char id[ISIS_SYS_ID_LEN + 2]; |
| 1744 | time_t now, diff; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1745 | struct listnode *cnode; |
| 1746 | struct isis_circuit *circuit; |
| 1747 | int lvl; |
| 1748 | |
| 1749 | if (area == NULL) |
| 1750 | return ISIS_ERROR; |
| 1751 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1752 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1753 | LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1754 | now = time (NULL); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1755 | |
| 1756 | for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1757 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1758 | if (!((level & lvl) && (area->is_type & lvl))) |
| 1759 | continue; |
| 1760 | |
| 1761 | if (area->lsp_regenerate_pending[lvl - 1]) |
| 1762 | continue; |
| 1763 | |
| 1764 | lsp = lsp_search (id, area->lspdb[lvl - 1]); |
| 1765 | if (!lsp) |
| 1766 | continue; |
| 1767 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1768 | /* |
| 1769 | * Throttle avoidance |
| 1770 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1771 | THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1772 | diff = now - lsp->last_generated; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1773 | if (diff < area->lsp_gen_interval[lvl - 1]) |
| 1774 | { |
| 1775 | area->lsp_regenerate_pending[lvl - 1] = 1; |
| 1776 | if (lvl == IS_LEVEL_1) |
| 1777 | THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1], |
| 1778 | lsp_l1_refresh, area, |
| 1779 | area->lsp_gen_interval[lvl - 1] - diff); |
| 1780 | else if (lvl == IS_LEVEL_2) |
| 1781 | THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1], |
| 1782 | lsp_l2_refresh, area, |
| 1783 | area->lsp_gen_interval[lvl - 1] - diff); |
| 1784 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1785 | else |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1786 | { |
Michael Zingg | be62b17 | 2012-10-26 11:18:19 +0200 | [diff] [blame] | 1787 | /* |
| 1788 | * lsps are not regenerated if lsp_regenerate function is called |
| 1789 | * directly. However if the lsp_regenerate call is queued for |
| 1790 | * later execution it works. |
| 1791 | */ |
| 1792 | area->lsp_regenerate_pending[lvl - 1] = 1; |
| 1793 | if (lvl == IS_LEVEL_1) |
| 1794 | THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1], |
| 1795 | lsp_l1_refresh, area, 0); |
| 1796 | else if (lvl == IS_LEVEL_2) |
| 1797 | THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1], |
| 1798 | lsp_l2_refresh, area, 0); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1799 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1800 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1801 | |
| 1802 | if (all_pseudo) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1803 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1804 | for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit)) |
| 1805 | lsp_regenerate_schedule_pseudo (circuit, level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | return ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /* |
| 1812 | * Funcs for pseudonode LSPs |
| 1813 | */ |
| 1814 | |
| 1815 | /* |
| 1816 | * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs |
| 1817 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1818 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1819 | lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit, |
| 1820 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1821 | { |
| 1822 | struct isis_adjacency *adj; |
| 1823 | struct is_neigh *is_neigh; |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1824 | struct te_is_neigh *te_is_neigh; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1825 | struct es_neigh *es_neigh; |
| 1826 | struct list *adj_list; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1827 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1828 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1829 | lsp->level = level; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1830 | /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */ |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 1831 | lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0, |
| 1832 | circuit->area->attached_bit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1833 | |
| 1834 | /* |
| 1835 | * add self to IS neighbours |
| 1836 | */ |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1837 | if (circuit->area->oldmetric) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1838 | { |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1839 | if (lsp->tlv_data.is_neighs == NULL) |
| 1840 | { |
| 1841 | lsp->tlv_data.is_neighs = list_new (); |
| 1842 | lsp->tlv_data.is_neighs->del = free_tlv; |
| 1843 | } |
| 1844 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1845 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1846 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1847 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); |
| 1848 | } |
| 1849 | if (circuit->area->newmetric) |
| 1850 | { |
| 1851 | if (lsp->tlv_data.te_is_neighs == NULL) |
| 1852 | { |
| 1853 | lsp->tlv_data.te_is_neighs = list_new (); |
| 1854 | lsp->tlv_data.te_is_neighs->del = free_tlv; |
| 1855 | } |
| 1856 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh)); |
| 1857 | |
| 1858 | memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1859 | listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh); |
| 1860 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1861 | |
| 1862 | adj_list = list_new (); |
| 1863 | isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list); |
| 1864 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1865 | for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1866 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1867 | if (adj->level & level) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1868 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1869 | if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) || |
| 1870 | (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS && |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1871 | adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1872 | (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1873 | { |
| 1874 | /* an IS neighbour -> add it */ |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1875 | if (circuit->area->oldmetric) |
| 1876 | { |
| 1877 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1878 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1879 | memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 1880 | listnode_add (lsp->tlv_data.is_neighs, is_neigh); |
| 1881 | } |
| 1882 | if (circuit->area->newmetric) |
| 1883 | { |
| 1884 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, |
| 1885 | sizeof (struct te_is_neigh)); |
| 1886 | memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 1887 | listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh); |
| 1888 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1889 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1890 | else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1891 | { |
| 1892 | /* an ES neigbour add it, if we are building level 1 LSP */ |
| 1893 | /* FIXME: the tlv-format is hard to use here */ |
| 1894 | if (lsp->tlv_data.es_neighs == NULL) |
| 1895 | { |
| 1896 | lsp->tlv_data.es_neighs = list_new (); |
| 1897 | lsp->tlv_data.es_neighs->del = free_tlv; |
| 1898 | } |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1899 | es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh)); |
| 1900 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1901 | memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN); |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 1902 | listnode_add (lsp->tlv_data.es_neighs, es_neigh); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1903 | } |
| 1904 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1905 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1906 | list_delete (adj_list); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1907 | |
hasso | c0fb2a5 | 2005-09-03 16:29:40 +0000 | [diff] [blame] | 1908 | /* Reset endp of stream to overwrite only TLV part of it. */ |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 1909 | stream_reset (lsp->pdu); |
hasso | c0fb2a5 | 2005-09-03 16:29:40 +0000 | [diff] [blame] | 1910 | stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 1911 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1912 | /* |
| 1913 | * Add the authentication info if it's present |
| 1914 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1915 | lsp_auth_add (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1916 | |
| 1917 | if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0) |
| 1918 | tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu); |
| 1919 | |
hasso | aa4376e | 2005-09-26 17:39:48 +0000 | [diff] [blame] | 1920 | if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0) |
| 1921 | tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu); |
| 1922 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1923 | if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0) |
| 1924 | tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu); |
| 1925 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 1926 | lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1927 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1928 | /* Recompute authentication and checksum information */ |
| 1929 | lsp_auth_update (lsp); |
| 1930 | fletcher_checksum(STREAM_DATA (lsp->pdu) + 12, |
| 1931 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1932 | |
| 1933 | return; |
| 1934 | } |
| 1935 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1936 | int |
| 1937 | lsp_generate_pseudo (struct isis_circuit *circuit, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1938 | { |
| 1939 | dict_t *lspdb = circuit->area->lspdb[level - 1]; |
| 1940 | struct isis_lsp *lsp; |
| 1941 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1942 | u_int16_t rem_lifetime, refresh_time; |
| 1943 | |
| 1944 | if ((circuit->is_type & level) != level || |
| 1945 | (circuit->state != C_STATE_UP) || |
| 1946 | (circuit->circ_type != CIRCUIT_T_BROADCAST) || |
| 1947 | (circuit->u.bc.is_dr[level - 1] == 0)) |
| 1948 | return ISIS_ERROR; |
| 1949 | |
| 1950 | memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1951 | LSP_FRAGMENT (lsp_id) = 0; |
| 1952 | LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id; |
| 1953 | |
| 1954 | /* |
| 1955 | * If for some reason have a pseudo LSP in the db already -> regenerate |
| 1956 | */ |
| 1957 | if (lsp_search (lsp_id, lspdb)) |
| 1958 | return lsp_regenerate_schedule_pseudo (circuit, level); |
| 1959 | |
| 1960 | rem_lifetime = lsp_rem_lifetime (circuit->area, level); |
| 1961 | /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */ |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 1962 | lsp = lsp_new (lsp_id, rem_lifetime, 1, |
| 1963 | circuit->area->is_type | circuit->area->attached_bit, |
| 1964 | 0, level); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1965 | lsp->area = circuit->area; |
| 1966 | |
| 1967 | lsp_build_pseudo (lsp, circuit, level); |
| 1968 | |
| 1969 | lsp->own_lsp = 1; |
| 1970 | lsp_insert (lsp, lspdb); |
| 1971 | lsp_set_all_srmflags (lsp); |
| 1972 | |
| 1973 | refresh_time = lsp_refresh_time (lsp, rem_lifetime); |
| 1974 | THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]); |
| 1975 | circuit->lsp_regenerate_pending[level - 1] = 0; |
| 1976 | if (level == IS_LEVEL_1) |
| 1977 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1], |
| 1978 | lsp_l1_refresh_pseudo, circuit, refresh_time); |
| 1979 | else if (level == IS_LEVEL_2) |
| 1980 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1], |
| 1981 | lsp_l2_refresh_pseudo, circuit, refresh_time); |
| 1982 | |
| 1983 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1984 | { |
| 1985 | zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, " |
| 1986 | "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us", |
| 1987 | circuit->area->area_tag, level, |
| 1988 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 1989 | ntohl (lsp->lsp_header->pdu_len), |
| 1990 | ntohl (lsp->lsp_header->seq_num), |
| 1991 | ntohs (lsp->lsp_header->checksum), |
| 1992 | ntohs (lsp->lsp_header->rem_lifetime), |
| 1993 | refresh_time); |
| 1994 | } |
| 1995 | |
| 1996 | return ISIS_OK; |
| 1997 | } |
| 1998 | |
| 1999 | static int |
| 2000 | lsp_regenerate_pseudo (struct isis_circuit *circuit, int level) |
| 2001 | { |
| 2002 | dict_t *lspdb = circuit->area->lspdb[level - 1]; |
| 2003 | struct isis_lsp *lsp; |
| 2004 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 2005 | u_int16_t rem_lifetime, refresh_time; |
| 2006 | |
| 2007 | if ((circuit->is_type & level) != level || |
| 2008 | (circuit->state != C_STATE_UP) || |
| 2009 | (circuit->circ_type != CIRCUIT_T_BROADCAST) || |
| 2010 | (circuit->u.bc.is_dr[level - 1] == 0)) |
| 2011 | return ISIS_ERROR; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2012 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2013 | memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2014 | LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id; |
| 2015 | LSP_FRAGMENT (lsp_id) = 0; |
| 2016 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2017 | lsp = lsp_search (lsp_id, lspdb); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2018 | |
| 2019 | if (!lsp) |
| 2020 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2021 | zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!", |
| 2022 | level, rawlspid_print (lsp_id)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2023 | return ISIS_ERROR; |
| 2024 | } |
| 2025 | lsp_clear_data (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2026 | |
| 2027 | lsp_build_pseudo (lsp, circuit, level); |
| 2028 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2029 | /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */ |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 2030 | lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0, |
| 2031 | circuit->area->attached_bit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2032 | rem_lifetime = lsp_rem_lifetime (circuit->area, level); |
| 2033 | lsp->lsp_header->rem_lifetime = htons (rem_lifetime); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2034 | lsp_inc_seqnum (lsp, 0); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2035 | lsp->last_generated = time (NULL); |
| 2036 | lsp_set_all_srmflags (lsp); |
| 2037 | |
| 2038 | refresh_time = lsp_refresh_time (lsp, rem_lifetime); |
| 2039 | if (level == IS_LEVEL_1) |
| 2040 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1], |
| 2041 | lsp_l1_refresh_pseudo, circuit, refresh_time); |
| 2042 | else if (level == IS_LEVEL_2) |
| 2043 | THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1], |
| 2044 | lsp_l2_refresh_pseudo, circuit, refresh_time); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2045 | |
| 2046 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 2047 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2048 | zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, " |
| 2049 | "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us", |
| 2050 | circuit->area->area_tag, level, |
| 2051 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2052 | ntohl (lsp->lsp_header->pdu_len), |
| 2053 | ntohl (lsp->lsp_header->seq_num), |
| 2054 | ntohs (lsp->lsp_header->checksum), |
| 2055 | ntohs (lsp->lsp_header->rem_lifetime), |
| 2056 | refresh_time); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2057 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2058 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2059 | return ISIS_OK; |
| 2060 | } |
| 2061 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2062 | /* |
| 2063 | * Something has changed or periodic refresh -> regenerate pseudo LSP |
| 2064 | */ |
| 2065 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2066 | lsp_l1_refresh_pseudo (struct thread *thread) |
| 2067 | { |
| 2068 | struct isis_circuit *circuit; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2069 | u_char id[ISIS_SYS_ID_LEN + 2]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2070 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2071 | circuit = THREAD_ARG (thread); |
| 2072 | |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 2073 | circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2074 | circuit->lsp_regenerate_pending[0] = 0; |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 2075 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2076 | if ((circuit->u.bc.is_dr[0] == 0) || |
| 2077 | (circuit->is_type & IS_LEVEL_1) == 0) |
| 2078 | { |
| 2079 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
| 2080 | LSP_PSEUDO_ID (id) = circuit->circuit_id; |
| 2081 | LSP_FRAGMENT (id) = 0; |
| 2082 | lsp_purge_pseudo (id, circuit, IS_LEVEL_1); |
| 2083 | return ISIS_ERROR; |
| 2084 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2085 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2086 | return lsp_regenerate_pseudo (circuit, IS_LEVEL_1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2089 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2090 | lsp_l2_refresh_pseudo (struct thread *thread) |
| 2091 | { |
| 2092 | struct isis_circuit *circuit; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2093 | u_char id[ISIS_SYS_ID_LEN + 2]; |
| 2094 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2095 | circuit = THREAD_ARG (thread); |
| 2096 | |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 2097 | circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2098 | circuit->lsp_regenerate_pending[1] = 0; |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 2099 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2100 | if ((circuit->u.bc.is_dr[1] == 0) || |
| 2101 | (circuit->is_type & IS_LEVEL_2) == 0) |
| 2102 | { |
| 2103 | memcpy (id, isis->sysid, ISIS_SYS_ID_LEN); |
| 2104 | LSP_PSEUDO_ID (id) = circuit->circuit_id; |
| 2105 | LSP_FRAGMENT (id) = 0; |
| 2106 | lsp_purge_pseudo (id, circuit, IS_LEVEL_2); |
| 2107 | return ISIS_ERROR; |
| 2108 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2109 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2110 | return lsp_regenerate_pseudo (circuit, IS_LEVEL_2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2113 | int |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2114 | lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2115 | { |
| 2116 | struct isis_lsp *lsp; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2117 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 2118 | time_t now, diff; |
| 2119 | int lvl; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2120 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2121 | if (circuit == NULL || |
| 2122 | circuit->circ_type != CIRCUIT_T_BROADCAST || |
| 2123 | circuit->state != C_STATE_UP) |
| 2124 | return ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2125 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2126 | memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 2127 | LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id; |
| 2128 | LSP_FRAGMENT (lsp_id) = 0; |
| 2129 | now = time (NULL); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2130 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2131 | for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++) |
| 2132 | { |
| 2133 | if (!((level & lvl) && (circuit->is_type & lvl))) |
| 2134 | continue; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2135 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2136 | if (circuit->u.bc.is_dr[lvl - 1] == 0 || |
| 2137 | circuit->lsp_regenerate_pending[lvl - 1]) |
| 2138 | continue; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2139 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2140 | lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]); |
| 2141 | if (!lsp) |
| 2142 | continue; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2143 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2144 | /* |
| 2145 | * Throttle avoidance |
| 2146 | */ |
| 2147 | THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]); |
| 2148 | diff = now - lsp->last_generated; |
| 2149 | if (diff < circuit->area->lsp_gen_interval[lvl - 1]) |
| 2150 | { |
| 2151 | circuit->lsp_regenerate_pending[lvl - 1] = 1; |
| 2152 | if (lvl == IS_LEVEL_1) |
| 2153 | THREAD_TIMER_ON (master, |
| 2154 | circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1], |
| 2155 | lsp_l1_refresh_pseudo, circuit, |
| 2156 | circuit->area->lsp_gen_interval[lvl - 1] - diff); |
| 2157 | else if (lvl == IS_LEVEL_2) |
| 2158 | THREAD_TIMER_ON (master, |
| 2159 | circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1], |
| 2160 | lsp_l2_refresh_pseudo, circuit, |
| 2161 | circuit->area->lsp_gen_interval[lvl - 1] - diff); |
| 2162 | } |
| 2163 | else |
| 2164 | { |
| 2165 | lsp_regenerate_pseudo (circuit, lvl); |
| 2166 | } |
| 2167 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2168 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2169 | return ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2172 | /* |
| 2173 | * Walk through LSPs for an area |
| 2174 | * - set remaining lifetime |
| 2175 | * - set LSPs with SRMflag set for sending |
| 2176 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2177 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2178 | lsp_tick (struct thread *thread) |
| 2179 | { |
| 2180 | struct isis_area *area; |
| 2181 | struct isis_circuit *circuit; |
| 2182 | struct isis_lsp *lsp; |
| 2183 | struct list *lsp_list; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2184 | struct listnode *lspnode, *cnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2185 | dnode_t *dnode, *dnode_next; |
| 2186 | int level; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2187 | u_int16_t rem_lifetime; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2188 | |
| 2189 | lsp_list = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2190 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2191 | area = THREAD_ARG (thread); |
| 2192 | assert (area); |
hasso | 13c48f7 | 2004-09-10 21:19:13 +0000 | [diff] [blame] | 2193 | area->t_tick = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2194 | THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2195 | |
| 2196 | /* |
| 2197 | * Build a list of LSPs with (any) SRMflag set |
| 2198 | * and removed the ones that have aged out |
| 2199 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2200 | for (level = 0; level < ISIS_LEVELS; level++) |
| 2201 | { |
| 2202 | if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2203 | { |
| 2204 | for (dnode = dict_first (area->lspdb[level]); |
| 2205 | dnode != NULL; dnode = dnode_next) |
| 2206 | { |
| 2207 | dnode_next = dict_next (area->lspdb[level], dnode); |
| 2208 | lsp = dnode_get (dnode); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2209 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2210 | /* |
| 2211 | * The lsp rem_lifetime is kept at 0 for MaxAge or |
| 2212 | * ZeroAgeLifetime depending on explicit purge or |
| 2213 | * natural age out. So schedule spf only once when |
| 2214 | * the first time rem_lifetime becomes 0. |
| 2215 | */ |
| 2216 | rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime); |
| 2217 | lsp_set_time (lsp); |
| 2218 | |
| 2219 | /* |
| 2220 | * Schedule may run spf which should be done only after |
| 2221 | * the lsp rem_lifetime becomes 0 for the first time. |
| 2222 | * ISO 10589 - 7.3.16.4 first paragraph. |
| 2223 | */ |
| 2224 | if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0) |
| 2225 | { |
| 2226 | /* 7.3.16.4 a) set SRM flags on all */ |
| 2227 | lsp_set_all_srmflags (lsp); |
| 2228 | /* 7.3.16.4 b) retain only the header FIXME */ |
| 2229 | /* 7.3.16.4 c) record the time to purge FIXME */ |
| 2230 | /* run/schedule spf */ |
| 2231 | /* isis_spf_schedule is called inside lsp_destroy() below; |
| 2232 | * so it is not needed here. */ |
| 2233 | /* isis_spf_schedule (lsp->area, lsp->level); */ |
| 2234 | } |
| 2235 | |
| 2236 | if (lsp->age_out == 0) |
| 2237 | { |
| 2238 | zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out", |
| 2239 | area->area_tag, |
| 2240 | lsp->level, |
| 2241 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2242 | ntohl (lsp->lsp_header->seq_num)); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2243 | #ifdef TOPOLOGY_GENERATE |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2244 | if (lsp->from_topology) |
| 2245 | THREAD_TIMER_OFF (lsp->t_lsp_top_ref); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2246 | #endif /* TOPOLOGY_GENERATE */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2247 | lsp_destroy (lsp); |
| 2248 | lsp = NULL; |
| 2249 | dict_delete_free (area->lspdb[level], dnode); |
| 2250 | } |
| 2251 | else if (flags_any_set (lsp->SRMflags)) |
| 2252 | listnode_add (lsp_list, lsp); |
| 2253 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2254 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2255 | /* |
| 2256 | * Send LSPs on circuits indicated by the SRMflags |
| 2257 | */ |
| 2258 | if (listcount (lsp_list) > 0) |
| 2259 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2260 | for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit)) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2261 | { |
| 2262 | int diff = time (NULL) - circuit->lsp_queue_last_cleared; |
| 2263 | if (circuit->lsp_queue == NULL || |
| 2264 | diff < MIN_LSP_TRANS_INTERVAL) |
| 2265 | continue; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2266 | for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp)) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2267 | { |
| 2268 | if (circuit->upadjcount[lsp->level - 1] && |
| 2269 | ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) |
| 2270 | { |
| 2271 | /* Add the lsp only if it is not already in lsp |
| 2272 | * queue */ |
| 2273 | if (! listnode_lookup (circuit->lsp_queue, lsp)) |
| 2274 | { |
| 2275 | listnode_add (circuit->lsp_queue, lsp); |
| 2276 | thread_add_event (master, send_lsp, circuit, 0); |
| 2277 | } |
| 2278 | } |
| 2279 | } |
| 2280 | } |
| 2281 | list_delete_all_node (lsp_list); |
| 2282 | } |
| 2283 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2284 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2285 | |
| 2286 | list_delete (lsp_list); |
| 2287 | |
| 2288 | return ISIS_OK; |
| 2289 | } |
| 2290 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2291 | void |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2292 | lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2293 | { |
| 2294 | struct isis_lsp *lsp; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2295 | u_int16_t seq_num; |
| 2296 | u_int8_t lsp_bits; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2297 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2298 | lsp = lsp_search (id, circuit->area->lspdb[level - 1]); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2299 | if (!lsp) |
| 2300 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2301 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2302 | /* store old values */ |
| 2303 | seq_num = lsp->lsp_header->seq_num; |
| 2304 | lsp_bits = lsp->lsp_header->lsp_bits; |
| 2305 | |
| 2306 | /* reset stream */ |
| 2307 | lsp_clear_data (lsp); |
| 2308 | stream_reset (lsp->pdu); |
| 2309 | |
| 2310 | /* update header */ |
| 2311 | lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 2312 | memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2); |
| 2313 | lsp->lsp_header->checksum = 0; |
| 2314 | lsp->lsp_header->seq_num = seq_num; |
| 2315 | lsp->lsp_header->rem_lifetime = 0; |
| 2316 | lsp->lsp_header->lsp_bits = lsp_bits; |
| 2317 | lsp->level = level; |
| 2318 | lsp->age_out = lsp->area->max_lsp_lifetime[level-1]; |
| 2319 | stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
| 2320 | |
| 2321 | /* |
| 2322 | * Add and update the authentication info if its present |
| 2323 | */ |
| 2324 | lsp_auth_add (lsp); |
| 2325 | lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu)); |
| 2326 | lsp_auth_update (lsp); |
| 2327 | fletcher_checksum(STREAM_DATA (lsp->pdu) + 12, |
| 2328 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
| 2329 | |
| 2330 | lsp_set_all_srmflags (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2331 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2332 | return; |
| 2333 | } |
| 2334 | |
| 2335 | /* |
| 2336 | * Purge own LSP that is received and we don't have. |
| 2337 | * -> Do as in 7.3.16.4 |
| 2338 | */ |
| 2339 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2340 | lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr, |
| 2341 | struct isis_area *area) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2342 | { |
| 2343 | struct isis_lsp *lsp; |
| 2344 | |
| 2345 | /* |
| 2346 | * We need to create the LSP to be purged |
| 2347 | */ |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 2348 | lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp)); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2349 | lsp->area = area; |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 2350 | lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? |
| 2351 | IS_LEVEL_1 : IS_LEVEL_2; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2352 | /* FIXME: Should be minimal mtu? */ |
| 2353 | lsp->pdu = stream_new (1500); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2354 | lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2355 | 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] | 2356 | : L2_LINK_STATE); |
| 2357 | lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) + |
| 2358 | ISIS_FIXED_HDR_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2359 | memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2360 | stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2361 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2362 | /* |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2363 | * Set the remaining lifetime to 0 |
| 2364 | */ |
| 2365 | lsp->lsp_header->rem_lifetime = 0; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2366 | |
| 2367 | /* |
| 2368 | * Add and update the authentication info if its present |
| 2369 | */ |
| 2370 | lsp_auth_add (lsp); |
| 2371 | lsp_auth_update (lsp); |
| 2372 | |
| 2373 | /* |
| 2374 | * Update the PDU length to header plus any authentication TLV. |
| 2375 | */ |
| 2376 | lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu)); |
| 2377 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2378 | /* |
| 2379 | * Put the lsp into LSPdb |
| 2380 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2381 | lsp_insert (lsp, area->lspdb[lsp->level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2382 | |
| 2383 | /* |
| 2384 | * Send in to whole area |
| 2385 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2386 | lsp_set_all_srmflags (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2387 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2388 | return; |
| 2389 | } |
| 2390 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2391 | void lsp_set_all_srmflags (struct isis_lsp *lsp) |
| 2392 | { |
| 2393 | struct listnode *node; |
| 2394 | struct isis_circuit *circuit; |
| 2395 | |
| 2396 | assert (lsp); |
| 2397 | |
| 2398 | ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags); |
| 2399 | |
| 2400 | if (lsp->area) |
| 2401 | { |
| 2402 | struct list *circuit_list = lsp->area->circuit_list; |
| 2403 | for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit)) |
| 2404 | { |
| 2405 | ISIS_SET_FLAG(lsp->SRMflags, circuit); |
| 2406 | } |
| 2407 | } |
| 2408 | } |
| 2409 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2410 | #ifdef TOPOLOGY_GENERATE |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2411 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2412 | top_lsp_refresh (struct thread *thread) |
| 2413 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2414 | struct isis_lsp *lsp; |
David Lamparter | f50ee93 | 2015-03-04 07:13:38 +0100 | [diff] [blame] | 2415 | u_int16_t rem_lifetime; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2416 | |
| 2417 | lsp = THREAD_ARG (thread); |
| 2418 | assert (lsp); |
| 2419 | |
| 2420 | lsp->t_lsp_top_ref = NULL; |
| 2421 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2422 | lsp_seqnum_update (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2423 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2424 | lsp_set_all_srmflags (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2425 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 2426 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2427 | zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s", |
| 2428 | rawlspid_print (lsp->lsp_header->lsp_id)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2429 | } |
hasso | d3d7474 | 2005-09-28 18:30:51 +0000 | [diff] [blame] | 2430 | /* Refresh dynamic hostname in the cache. */ |
| 2431 | isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname, |
| 2432 | IS_LEVEL_1); |
| 2433 | |
David Lamparter | a47c583 | 2012-06-21 09:55:38 +0200 | [diff] [blame] | 2434 | lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level, |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 2435 | lsp->area->overload_bit, |
| 2436 | lsp->area->attached_bit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2437 | rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1); |
| 2438 | lsp->lsp_header->rem_lifetime = htons (rem_lifetime); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2439 | |
David Lamparter | f50ee93 | 2015-03-04 07:13:38 +0100 | [diff] [blame] | 2440 | /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2441 | 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] | 2442 | lsp->area->lsp_refresh[0]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2443 | |
| 2444 | return ISIS_OK; |
| 2445 | } |
| 2446 | |
| 2447 | void |
| 2448 | generate_topology_lsps (struct isis_area *area) |
| 2449 | { |
| 2450 | struct listnode *node; |
| 2451 | int i, max = 0; |
| 2452 | struct arc *arc; |
| 2453 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 2454 | struct isis_lsp *lsp; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2455 | u_int16_t rem_lifetime, refresh_time; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2456 | |
| 2457 | /* first we find the maximal node */ |
paul | a8f03df | 2005-04-10 15:58:10 +0000 | [diff] [blame] | 2458 | for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc)) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2459 | { |
| 2460 | if (arc->from_node > max) |
| 2461 | max = arc->from_node; |
| 2462 | if (arc->to_node > max) |
| 2463 | max = arc->to_node; |
| 2464 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2465 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2466 | for (i = 1; i < (max + 1); i++) |
| 2467 | { |
| 2468 | memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN); |
| 2469 | LSP_PSEUDO_ID (lspid) = 0x00; |
| 2470 | LSP_FRAGMENT (lspid) = 0x00; |
| 2471 | lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF); |
| 2472 | lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2473 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2474 | rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1); |
Amritha Nambiar | c8ee940 | 2015-08-24 16:40:14 -0700 | [diff] [blame] | 2475 | lsp = lsp_new (lspid, rem_lifetime, 1, IS_LEVEL_1 | area->overload_bit |
| 2476 | | area->attached_bit, 0, 1); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2477 | if (!lsp) |
| 2478 | return; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2479 | lsp->area = area; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2480 | lsp->from_topology = 1; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2481 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2482 | /* Creating LSP data based on topology info. */ |
| 2483 | build_topology_lsp_data (lsp, area, i); |
| 2484 | /* Checksum is also calculated here. */ |
| 2485 | lsp_seqnum_update (lsp); |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2486 | /* Take care of inserting dynamic hostname into cache. */ |
| 2487 | isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2488 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2489 | refresh_time = lsp_refresh_time (lsp, rem_lifetime); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2490 | 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] | 2491 | refresh_time); |
| 2492 | lsp_set_all_srmflags (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2493 | lsp_insert (lsp, area->lspdb[0]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2494 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | void |
| 2498 | remove_topology_lsps (struct isis_area *area) |
| 2499 | { |
| 2500 | struct isis_lsp *lsp; |
| 2501 | dnode_t *dnode, *dnode_next; |
| 2502 | |
| 2503 | dnode = dict_first (area->lspdb[0]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2504 | while (dnode != NULL) |
| 2505 | { |
| 2506 | dnode_next = dict_next (area->lspdb[0], dnode); |
| 2507 | lsp = dnode_get (dnode); |
| 2508 | if (lsp->from_topology) |
| 2509 | { |
| 2510 | THREAD_TIMER_OFF (lsp->t_lsp_top_ref); |
| 2511 | lsp_destroy (lsp); |
| 2512 | dict_delete (area->lspdb[0], dnode); |
| 2513 | } |
| 2514 | dnode = dnode_next; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2515 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2519 | build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2520 | int lsp_top_num) |
| 2521 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2522 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2523 | struct arc *arc; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2524 | struct is_neigh *is_neigh; |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2525 | struct te_is_neigh *te_is_neigh; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2526 | char buff[200]; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2527 | struct tlvs tlv_data; |
| 2528 | struct isis_lsp *lsp0 = lsp; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2529 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2530 | /* Add area addresses. FIXME: Is it needed at all? */ |
| 2531 | if (lsp->tlv_data.area_addrs == NULL) |
| 2532 | lsp->tlv_data.area_addrs = list_new (); |
| 2533 | list_add_list (lsp->tlv_data.area_addrs, area->area_addrs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2534 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2535 | if (lsp->tlv_data.nlpids == NULL) |
| 2536 | lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids)); |
| 2537 | lsp->tlv_data.nlpids->count = 1; |
| 2538 | lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2539 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2540 | if (area->dynhostname) |
| 2541 | { |
| 2542 | lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, |
| 2543 | sizeof (struct hostname)); |
| 2544 | memset (buff, 0x00, 200); |
| 2545 | sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh : |
| 2546 | "feedme", lsp_top_num); |
| 2547 | memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff)); |
| 2548 | lsp->tlv_data.hostname->namelen = strlen (buff); |
| 2549 | } |
| 2550 | |
| 2551 | if (lsp->tlv_data.nlpids) |
| 2552 | tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu); |
| 2553 | if (lsp->tlv_data.hostname) |
| 2554 | tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu); |
| 2555 | if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0) |
| 2556 | tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu); |
| 2557 | |
| 2558 | memset (&tlv_data, 0, sizeof (struct tlvs)); |
| 2559 | if (tlv_data.is_neighs == NULL) |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2560 | { |
| 2561 | tlv_data.is_neighs = list_new (); |
| 2562 | tlv_data.is_neighs->del = free_tlv; |
| 2563 | } |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2564 | |
| 2565 | /* Add reachability for this IS for simulated 1. */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2566 | if (lsp_top_num == 1) |
| 2567 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2568 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2569 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2570 | memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2571 | LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2572 | /* Metric MUST NOT be 0, unless it's not alias TLV. */ |
| 2573 | is_neigh->metrics.metric_default = 0x01; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2574 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; |
| 2575 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; |
| 2576 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2577 | listnode_add (tlv_data.is_neighs, is_neigh); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2578 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2579 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2580 | /* Add IS reachabilities. */ |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2581 | for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2582 | { |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2583 | int to_lsp = 0; |
| 2584 | |
| 2585 | if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node)) |
| 2586 | continue; |
| 2587 | |
| 2588 | if (lsp_top_num == arc->from_node) |
| 2589 | to_lsp = arc->to_node; |
| 2590 | else |
| 2591 | to_lsp = arc->from_node; |
| 2592 | |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2593 | if (area->oldmetric) |
| 2594 | { |
| 2595 | is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2596 | |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2597 | memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN); |
| 2598 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF); |
| 2599 | is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF); |
| 2600 | is_neigh->metrics.metric_default = arc->distance; |
| 2601 | is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED; |
| 2602 | is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED; |
| 2603 | is_neigh->metrics.metric_error = METRICS_UNSUPPORTED; |
| 2604 | listnode_add (tlv_data.is_neighs, is_neigh); |
| 2605 | } |
| 2606 | |
| 2607 | if (area->newmetric) |
| 2608 | { |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2609 | if (tlv_data.te_is_neighs == NULL) |
| 2610 | { |
| 2611 | tlv_data.te_is_neighs = list_new (); |
| 2612 | tlv_data.te_is_neighs->del = free_tlv; |
| 2613 | } |
| 2614 | te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh)); |
| 2615 | memcpy (&te_is_neigh->neigh_id, area->topology_baseis, |
| 2616 | ISIS_SYS_ID_LEN); |
| 2617 | te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF); |
| 2618 | 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] | 2619 | SET_TE_METRIC(te_is_neigh, arc->distance); |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2620 | listnode_add (tlv_data.te_is_neighs, te_is_neigh); |
| 2621 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2622 | } |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2623 | |
| 2624 | while (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 2625 | { |
| 2626 | if (lsp->tlv_data.is_neighs == NULL) |
| 2627 | lsp->tlv_data.is_neighs = list_new (); |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2628 | lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs, |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2629 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 2630 | tlv_add_is_neighs); |
| 2631 | if (tlv_data.is_neighs && listcount (tlv_data.is_neighs)) |
| 2632 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 2633 | lsp0, area, IS_LEVEL_1); |
| 2634 | } |
| 2635 | |
hasso | 9551eea | 2005-09-28 18:26:25 +0000 | [diff] [blame] | 2636 | while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs)) |
| 2637 | { |
| 2638 | if (lsp->tlv_data.te_is_neighs == NULL) |
| 2639 | lsp->tlv_data.te_is_neighs = list_new (); |
| 2640 | lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs, |
| 2641 | IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, |
| 2642 | tlv_add_te_is_neighs); |
| 2643 | if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs)) |
| 2644 | lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1, |
| 2645 | lsp0, area, IS_LEVEL_1); |
| 2646 | } |
| 2647 | |
hasso | f1082d1 | 2005-09-19 04:23:34 +0000 | [diff] [blame] | 2648 | free_tlvs (&tlv_data); |
| 2649 | return; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2650 | } |
| 2651 | #endif /* TOPOLOGY_GENERATE */ |