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