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