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