]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
d62a17ae | 2 | * IS-IS Rout(e)ing protocol - isis_pdu.c |
eb5d44eb | 3 | * PDU processing |
4 | * | |
5 | * Copyright (C) 2001,2002 Sampo Saaristo | |
d62a17ae | 6 | * Tampere University of Technology |
eb5d44eb | 7 | * Institute of Communications Engineering |
8 | * | |
d62a17ae | 9 | * This program is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU General Public Licenseas published by the Free | |
11 | * Software Foundation; either version 2 of the License, or (at your option) | |
eb5d44eb | 12 | * any later version. |
13 | * | |
d62a17ae | 14 | * This program is distributed in the hope that it will be useful,but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
eb5d44eb | 17 | * more details. |
896014f4 DL |
18 | * |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; see the file COPYING; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
eb5d44eb | 22 | */ |
23 | ||
eb5d44eb | 24 | #include <zebra.h> |
eb5d44eb | 25 | |
26 | #include "memory.h" | |
27 | #include "thread.h" | |
28 | #include "linklist.h" | |
29 | #include "log.h" | |
30 | #include "stream.h" | |
31 | #include "vty.h" | |
3f045a08 | 32 | #include "hash.h" |
eb5d44eb | 33 | #include "prefix.h" |
34 | #include "if.h" | |
6a270cd9 | 35 | #include "checksum.h" |
3f045a08 | 36 | #include "md5.h" |
38937bd5 | 37 | #include "lib_errors.h" |
eb5d44eb | 38 | |
eb5d44eb | 39 | #include "isisd/isis_constants.h" |
40 | #include "isisd/isis_common.h" | |
3f045a08 | 41 | #include "isisd/isis_flags.h" |
eb5d44eb | 42 | #include "isisd/isis_adjacency.h" |
43 | #include "isisd/isis_circuit.h" | |
44 | #include "isisd/isis_network.h" | |
45 | #include "isisd/isis_misc.h" | |
46 | #include "isisd/isis_dr.h" | |
eb5d44eb | 47 | #include "isisd/isisd.h" |
48 | #include "isisd/isis_dynhn.h" | |
49 | #include "isisd/isis_lsp.h" | |
50 | #include "isisd/isis_pdu.h" | |
51 | #include "isisd/iso_checksum.h" | |
52 | #include "isisd/isis_csm.h" | |
53 | #include "isisd/isis_events.h" | |
f8c06e2c | 54 | #include "isisd/isis_te.h" |
99894f9a | 55 | #include "isisd/isis_mt.h" |
841791b6 | 56 | #include "isisd/isis_tlvs.h" |
54ece698 | 57 | #include "isisd/isis_errors.h" |
8e6fb83b | 58 | #include "isisd/fabricd.h" |
9b39405f | 59 | #include "isisd/isis_tx_queue.h" |
39bb53d6 | 60 | #include "isisd/isis_pdu_counter.h" |
2a1c520e | 61 | #include "isisd/isis_nb.h" |
eb5d44eb | 62 | |
af8ac8f9 CF |
63 | static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit, |
64 | int level) | |
eb5d44eb | 65 | { |
af8ac8f9 CF |
66 | unsigned long lenp; |
67 | int retval; | |
d7c0a89a | 68 | uint16_t length; |
af8ac8f9 CF |
69 | uint8_t pdu_type = |
70 | (level == IS_LEVEL_1) ? L1_PARTIAL_SEQ_NUM : L2_PARTIAL_SEQ_NUM; | |
d62a17ae | 71 | |
af8ac8f9 | 72 | isis_circuit_stream(circuit, &circuit->snd_stream); |
3f045a08 | 73 | |
af8ac8f9 | 74 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
d62a17ae | 75 | |
af8ac8f9 | 76 | lenp = stream_get_endp(circuit->snd_stream); |
eab88f36 | 77 | |
af8ac8f9 | 78 | stream_putw(circuit->snd_stream, 0); /* PDU length */ |
99e5d4af | 79 | stream_put(circuit->snd_stream, circuit->isis->sysid, ISIS_SYS_ID_LEN); |
af8ac8f9 CF |
80 | stream_putc(circuit->snd_stream, circuit->idx); |
81 | stream_putc(circuit->snd_stream, 9); /* code */ | |
82 | stream_putc(circuit->snd_stream, 16); /* len */ | |
d62a17ae | 83 | |
af8ac8f9 CF |
84 | stream_putw(circuit->snd_stream, hdr->rem_lifetime); |
85 | stream_put(circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2); | |
86 | stream_putl(circuit->snd_stream, hdr->seqno); | |
87 | stream_putw(circuit->snd_stream, hdr->checksum); | |
3f045a08 | 88 | |
d7c0a89a | 89 | length = (uint16_t)stream_get_endp(circuit->snd_stream); |
af8ac8f9 CF |
90 | /* Update PDU length */ |
91 | stream_putw_at(circuit->snd_stream, lenp, length); | |
3f045a08 | 92 | |
39bb53d6 | 93 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
af8ac8f9 CF |
94 | retval = circuit->tx(circuit, level); |
95 | if (retval != ISIS_OK) | |
1a7ecb96 | 96 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
97 | "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed", |
98 | circuit->area->area_tag, level, | |
99 | circuit->interface->name); | |
d62a17ae | 100 | |
101 | return retval; | |
eb5d44eb | 102 | } |
103 | ||
eb5d44eb | 104 | /* |
d62a17ae | 105 | * RECEIVE SIDE |
eb5d44eb | 106 | */ |
107 | ||
0c1bd758 CF |
108 | struct iih_info { |
109 | struct isis_circuit *circuit; | |
d7c0a89a | 110 | uint8_t *ssnpa; |
0c1bd758 | 111 | int level; |
eb5d44eb | 112 | |
0c1bd758 CF |
113 | uint8_t circ_type; |
114 | uint8_t sys_id[ISIS_SYS_ID_LEN]; | |
115 | uint16_t holdtime; | |
116 | uint16_t pdu_len; | |
d62a17ae | 117 | |
0c1bd758 | 118 | uint8_t circuit_id; |
eb5d44eb | 119 | |
0c1bd758 CF |
120 | uint8_t priority; |
121 | uint8_t dis[ISIS_SYS_ID_LEN + 1]; | |
d8fba7d9 | 122 | |
0c1bd758 CF |
123 | bool v4_usable; |
124 | bool v6_usable; | |
eb5d44eb | 125 | |
0c1bd758 CF |
126 | struct isis_tlvs *tlvs; |
127 | }; | |
eb5d44eb | 128 | |
0c1bd758 CF |
129 | static int process_p2p_hello(struct iih_info *iih) |
130 | { | |
42fe2621 | 131 | struct isis_threeway_adj *tw_adj = iih->tlvs->threeway_adj; |
eab88f36 | 132 | |
42fe2621 CF |
133 | if (tw_adj) { |
134 | if (tw_adj->state > ISIS_THREEWAY_DOWN) { | |
e740f9c1 | 135 | if (IS_DEBUG_ADJ_PACKETS) { |
9165c5f5 | 136 | zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d", |
42fe2621 CF |
137 | iih->circuit->area->area_tag, |
138 | iih->circuit->interface->name, | |
139 | tw_adj->state); | |
140 | } | |
141 | return ISIS_WARNING; | |
142 | } | |
143 | ||
144 | if (tw_adj->neighbor_set | |
99e5d4af DS |
145 | && (memcmp(tw_adj->neighbor_id, iih->circuit->isis->sysid, |
146 | ISIS_SYS_ID_LEN) | |
eab88f36 K |
147 | || tw_adj->neighbor_circuit_id |
148 | != (uint32_t)iih->circuit->idx)) { | |
42fe2621 | 149 | |
e740f9c1 | 150 | if (IS_DEBUG_ADJ_PACKETS) { |
9165c5f5 | 151 | zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.", |
42fe2621 CF |
152 | iih->circuit->area->area_tag, |
153 | iih->circuit->interface->name); | |
154 | } | |
155 | ||
156 | return ISIS_WARNING; | |
157 | } | |
158 | } | |
159 | ||
d62a17ae | 160 | /* |
161 | * My interpertation of the ISO, if no adj exists we will create one for | |
162 | * the circuit | |
163 | */ | |
0c1bd758 | 164 | struct isis_adjacency *adj = iih->circuit->u.p2p.neighbor; |
d62a17ae | 165 | /* If an adjacency exists, check it is with the source of the hello |
166 | * packets */ | |
167 | if (adj) { | |
0c1bd758 | 168 | if (memcmp(iih->sys_id, adj->sysid, ISIS_SYS_ID_LEN)) { |
d62a17ae | 169 | zlog_debug( |
1d5453d6 | 170 | "hello source and adjacency do not match, set adj down"); |
16167b31 | 171 | isis_adj_state_change(&adj, ISIS_ADJ_DOWN, |
d62a17ae | 172 | "adj do not exist"); |
0c1bd758 | 173 | return ISIS_OK; |
f390d2c7 | 174 | } |
d62a17ae | 175 | } |
0c1bd758 | 176 | if (!adj || adj->level != iih->circ_type) { |
d62a17ae | 177 | if (!adj) { |
0c1bd758 CF |
178 | adj = isis_new_adj(iih->sys_id, NULL, iih->circ_type, |
179 | iih->circuit); | |
d62a17ae | 180 | } else { |
0c1bd758 | 181 | adj->level = iih->circ_type; |
f390d2c7 | 182 | } |
0c1bd758 | 183 | iih->circuit->u.p2p.neighbor = adj; |
d62a17ae | 184 | /* Build lsp with the new neighbor entry when a new |
185 | * adjacency is formed. Set adjacency circuit type to | |
186 | * IIH PDU header circuit type before lsp is regenerated | |
187 | * when an adjacency is up. This will result in the new | |
188 | * adjacency entry getting added to the lsp tlv neighbor list. | |
189 | */ | |
0c1bd758 | 190 | adj->circuit_t = iih->circ_type; |
16167b31 | 191 | isis_adj_state_change(&adj, ISIS_ADJ_INITIALIZING, NULL); |
d62a17ae | 192 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
f390d2c7 | 193 | } |
eb5d44eb | 194 | |
df04b6af | 195 | if (tw_adj) |
42fe2621 CF |
196 | adj->ext_circuit_id = tw_adj->local_circuit_id; |
197 | ||
d62a17ae | 198 | /* 8.2.6 Monitoring point-to-point adjacencies */ |
0c1bd758 | 199 | adj->hold_time = iih->holdtime; |
d62a17ae | 200 | adj->last_upd = time(NULL); |
201 | ||
0c1bd758 CF |
202 | bool changed; |
203 | isis_tlvs_to_adj(iih->tlvs, adj, &changed); | |
204 | changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable, | |
205 | adj); | |
d62a17ae | 206 | |
d62a17ae | 207 | /* lets take care of the expiry */ |
50478845 | 208 | thread_cancel(&adj->t_expire); |
d62a17ae | 209 | thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time, |
210 | &adj->t_expire); | |
211 | ||
8e6fb83b CF |
212 | /* While fabricds initial sync is in progress, ignore hellos from other |
213 | * interfaces than the one we are performing the initial sync on. */ | |
214 | if (fabricd_initial_sync_is_in_progress(iih->circuit->area) | |
215 | && fabricd_initial_sync_circuit(iih->circuit->area) != iih->circuit) | |
216 | return ISIS_OK; | |
217 | ||
d62a17ae | 218 | /* 8.2.5.2 a) a match was detected */ |
0c1bd758 CF |
219 | if (isis_tlvs_area_addresses_match(iih->tlvs, |
220 | iih->circuit->area->area_addrs)) { | |
d62a17ae | 221 | /* 8.2.5.2 a) 2) If the system is L1 - table 5 */ |
0c1bd758 CF |
222 | if (iih->circuit->area->is_type == IS_LEVEL_1) { |
223 | switch (iih->circ_type) { | |
d62a17ae | 224 | case IS_LEVEL_1: |
225 | case IS_LEVEL_1_AND_2: | |
42fe2621 CF |
226 | if (adj->adj_state != ISIS_ADJ_UP |
227 | || adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
228 | isis_adj_process_threeway(adj, tw_adj, | |
229 | ISIS_ADJ_LEVEL1); | |
d62a17ae | 230 | } |
231 | break; | |
232 | case IS_LEVEL_2: | |
233 | if (adj->adj_state != ISIS_ADJ_UP) { | |
234 | /* (7) reject - wrong system type event | |
235 | */ | |
236 | zlog_warn("wrongSystemType"); | |
0c1bd758 | 237 | return ISIS_WARNING; |
d62a17ae | 238 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { |
239 | /* (6) down - wrong system */ | |
16167b31 | 240 | isis_adj_state_change(&adj, |
d62a17ae | 241 | ISIS_ADJ_DOWN, |
242 | "Wrong System"); | |
243 | } | |
244 | break; | |
245 | } | |
f390d2c7 | 246 | } |
d62a17ae | 247 | |
248 | /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */ | |
0c1bd758 CF |
249 | if (iih->circuit->area->is_type == IS_LEVEL_1_AND_2) { |
250 | switch (iih->circ_type) { | |
d62a17ae | 251 | case IS_LEVEL_1: |
42fe2621 CF |
252 | if (adj->adj_state != ISIS_ADJ_UP |
253 | || adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
254 | isis_adj_process_threeway(adj, tw_adj, | |
255 | ISIS_ADJ_LEVEL1); | |
d62a17ae | 256 | } else if ((adj->adj_usage |
257 | == ISIS_ADJ_LEVEL1AND2) | |
258 | || (adj->adj_usage | |
259 | == ISIS_ADJ_LEVEL2)) { | |
260 | /* (8) down - wrong system */ | |
16167b31 | 261 | isis_adj_state_change(&adj, |
d62a17ae | 262 | ISIS_ADJ_DOWN, |
263 | "Wrong System"); | |
264 | } | |
265 | break; | |
266 | case IS_LEVEL_2: | |
42fe2621 CF |
267 | if (adj->adj_state != ISIS_ADJ_UP |
268 | || adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
269 | isis_adj_process_threeway(adj, tw_adj, | |
270 | ISIS_ADJ_LEVEL2); | |
d62a17ae | 271 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) |
272 | || (adj->adj_usage | |
273 | == ISIS_ADJ_LEVEL1AND2)) { | |
274 | /* (8) down - wrong system */ | |
16167b31 | 275 | isis_adj_state_change(&adj, |
d62a17ae | 276 | ISIS_ADJ_DOWN, |
277 | "Wrong System"); | |
d62a17ae | 278 | } |
279 | break; | |
280 | case IS_LEVEL_1_AND_2: | |
42fe2621 CF |
281 | if (adj->adj_state != ISIS_ADJ_UP |
282 | || adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { | |
283 | isis_adj_process_threeway(adj, tw_adj, | |
284 | ISIS_ADJ_LEVEL1AND2); | |
d62a17ae | 285 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) |
286 | || (adj->adj_usage | |
287 | == ISIS_ADJ_LEVEL2)) { | |
288 | /* (8) down - wrong system */ | |
16167b31 | 289 | isis_adj_state_change(&adj, |
d62a17ae | 290 | ISIS_ADJ_DOWN, |
291 | "Wrong System"); | |
d62a17ae | 292 | } |
293 | break; | |
294 | } | |
f390d2c7 | 295 | } |
d62a17ae | 296 | |
297 | /* 8.2.5.2 a) 4) If the system is L2 - table 7 */ | |
0c1bd758 CF |
298 | if (iih->circuit->area->is_type == IS_LEVEL_2) { |
299 | switch (iih->circ_type) { | |
d62a17ae | 300 | case IS_LEVEL_1: |
301 | if (adj->adj_state != ISIS_ADJ_UP) { | |
302 | /* (5) reject - wrong system type event | |
303 | */ | |
304 | zlog_warn("wrongSystemType"); | |
0c1bd758 | 305 | return ISIS_WARNING; |
d62a17ae | 306 | } else if ((adj->adj_usage |
307 | == ISIS_ADJ_LEVEL1AND2) | |
308 | || (adj->adj_usage | |
309 | == ISIS_ADJ_LEVEL2)) { | |
310 | /* (6) down - wrong system */ | |
16167b31 | 311 | isis_adj_state_change(&adj, |
d62a17ae | 312 | ISIS_ADJ_DOWN, |
313 | "Wrong System"); | |
314 | } | |
315 | break; | |
316 | case IS_LEVEL_1_AND_2: | |
317 | case IS_LEVEL_2: | |
42fe2621 CF |
318 | if (adj->adj_state != ISIS_ADJ_UP |
319 | || adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
320 | isis_adj_process_threeway(adj, tw_adj, | |
321 | ISIS_ADJ_LEVEL2); | |
d62a17ae | 322 | } else if (adj->adj_usage |
323 | == ISIS_ADJ_LEVEL1AND2) { | |
324 | /* (6) down - wrong system */ | |
16167b31 | 325 | isis_adj_state_change(&adj, |
d62a17ae | 326 | ISIS_ADJ_DOWN, |
327 | "Wrong System"); | |
d62a17ae | 328 | } |
329 | break; | |
330 | } | |
f390d2c7 | 331 | } |
d62a17ae | 332 | } |
333 | /* 8.2.5.2 b) if no match was detected */ | |
0c1bd758 CF |
334 | else if (listcount(iih->circuit->area->area_addrs) > 0) { |
335 | if (iih->circuit->area->is_type == IS_LEVEL_1) { | |
d62a17ae | 336 | /* 8.2.5.2 b) 1) is_type L1 and adj is not up */ |
337 | if (adj->adj_state != ISIS_ADJ_UP) { | |
16167b31 | 338 | isis_adj_state_change(&adj, ISIS_ADJ_DOWN, |
d62a17ae | 339 | "Area Mismatch"); |
340 | /* 8.2.5.2 b) 2)is_type L1 and adj is up */ | |
341 | } else { | |
16167b31 | 342 | isis_adj_state_change(&adj, ISIS_ADJ_DOWN, |
d62a17ae | 343 | "Down - Area Mismatch"); |
344 | } | |
f390d2c7 | 345 | } |
d62a17ae | 346 | /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */ |
347 | else { | |
0c1bd758 | 348 | switch (iih->circ_type) { |
d62a17ae | 349 | case IS_LEVEL_1: |
350 | if (adj->adj_state != ISIS_ADJ_UP) { | |
351 | /* (6) reject - Area Mismatch event */ | |
352 | zlog_warn("AreaMismatch"); | |
0c1bd758 | 353 | return ISIS_WARNING; |
d62a17ae | 354 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { |
355 | /* (7) down - area mismatch */ | |
16167b31 | 356 | isis_adj_state_change(&adj, |
d62a17ae | 357 | ISIS_ADJ_DOWN, |
358 | "Area Mismatch"); | |
359 | ||
360 | } else if ((adj->adj_usage | |
361 | == ISIS_ADJ_LEVEL1AND2) | |
362 | || (adj->adj_usage | |
363 | == ISIS_ADJ_LEVEL2)) { | |
364 | /* (7) down - wrong system */ | |
16167b31 | 365 | isis_adj_state_change(&adj, |
d62a17ae | 366 | ISIS_ADJ_DOWN, |
367 | "Wrong System"); | |
368 | } | |
369 | break; | |
370 | case IS_LEVEL_1_AND_2: | |
371 | case IS_LEVEL_2: | |
42fe2621 CF |
372 | if (adj->adj_state != ISIS_ADJ_UP |
373 | || adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
374 | isis_adj_process_threeway(adj, tw_adj, | |
375 | ISIS_ADJ_LEVEL2); | |
d62a17ae | 376 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { |
377 | /* (7) down - wrong system */ | |
16167b31 | 378 | isis_adj_state_change(&adj, |
d62a17ae | 379 | ISIS_ADJ_DOWN, |
380 | "Wrong System"); | |
381 | } else if (adj->adj_usage | |
382 | == ISIS_ADJ_LEVEL1AND2) { | |
0c1bd758 | 383 | if (iih->circ_type == IS_LEVEL_2) { |
d62a17ae | 384 | /* (7) down - wrong system */ |
385 | isis_adj_state_change( | |
16167b31 | 386 | &adj, ISIS_ADJ_DOWN, |
d62a17ae | 387 | "Wrong System"); |
388 | } else { | |
389 | /* (7) down - area mismatch */ | |
390 | isis_adj_state_change( | |
16167b31 | 391 | &adj, ISIS_ADJ_DOWN, |
d62a17ae | 392 | "Area Mismatch"); |
393 | } | |
d62a17ae | 394 | } |
395 | break; | |
396 | } | |
f390d2c7 | 397 | } |
d62a17ae | 398 | } else { |
399 | /* down - area mismatch */ | |
16167b31 | 400 | isis_adj_state_change(&adj, ISIS_ADJ_DOWN, "Area Mismatch"); |
f390d2c7 | 401 | } |
d8fba7d9 | 402 | |
16167b31 DS |
403 | if (adj) { |
404 | if (adj->adj_state == ISIS_ADJ_UP && changed) { | |
405 | lsp_regenerate_schedule( | |
406 | adj->circuit->area, | |
407 | isis_adj_usage2levels(adj->adj_usage), 0); | |
408 | } | |
eb5d44eb | 409 | |
16167b31 DS |
410 | /* 8.2.5.2 c) if the action was up - comparing circuit IDs */ |
411 | /* FIXME - Missing parts */ | |
d62a17ae | 412 | |
16167b31 DS |
413 | /* some of my own understanding of the ISO, why the heck does |
414 | * it not say what should I change the system_type to... | |
415 | */ | |
416 | switch (adj->adj_usage) { | |
417 | case ISIS_ADJ_LEVEL1: | |
418 | adj->sys_type = ISIS_SYSTYPE_L1_IS; | |
419 | break; | |
420 | case ISIS_ADJ_LEVEL2: | |
421 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
422 | break; | |
423 | case ISIS_ADJ_LEVEL1AND2: | |
424 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
425 | break; | |
426 | case ISIS_ADJ_NONE: | |
427 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
428 | break; | |
429 | } | |
d62a17ae | 430 | } |
eb5d44eb | 431 | |
e740f9c1 | 432 | if (IS_DEBUG_ADJ_PACKETS) { |
d62a17ae | 433 | zlog_debug( |
6cde4b45 | 434 | "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s, cir id %hhu, length %hu", |
0c1bd758 CF |
435 | iih->circuit->area->area_tag, |
436 | iih->circuit->interface->name, | |
437 | circuit_t2string(iih->circuit->is_type), | |
438 | iih->circuit->circuit_id, iih->pdu_len); | |
d62a17ae | 439 | } |
eb5d44eb | 440 | |
0c1bd758 | 441 | return ISIS_OK; |
eb5d44eb | 442 | } |
443 | ||
0c1bd758 | 444 | static int process_lan_hello(struct iih_info *iih) |
eb5d44eb | 445 | { |
d62a17ae | 446 | struct isis_adjacency *adj; |
0c1bd758 CF |
447 | adj = isis_adj_lookup(iih->sys_id, |
448 | iih->circuit->u.bc.adjdb[iih->level - 1]); | |
449 | if ((adj == NULL) || (memcmp(adj->snpa, iih->ssnpa, ETH_ALEN)) | |
450 | || (adj->level != iih->level)) { | |
451 | if (!adj) { | |
452 | /* Do as in 8.4.2.5 */ | |
453 | adj = isis_new_adj(iih->sys_id, iih->ssnpa, iih->level, | |
454 | iih->circuit); | |
455 | } else { | |
456 | if (iih->ssnpa) { | |
457 | memcpy(adj->snpa, iih->ssnpa, 6); | |
458 | } else { | |
459 | memset(adj->snpa, ' ', 6); | |
460 | } | |
461 | adj->level = iih->level; | |
462 | } | |
16167b31 | 463 | isis_adj_state_change(&adj, ISIS_ADJ_INITIALIZING, NULL); |
d62a17ae | 464 | |
0c1bd758 CF |
465 | if (iih->level == IS_LEVEL_1) |
466 | adj->sys_type = ISIS_SYSTYPE_L1_IS; | |
467 | else | |
468 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
469 | list_delete_all_node( | |
470 | iih->circuit->u.bc.lan_neighs[iih->level - 1]); | |
471 | isis_adj_build_neigh_list( | |
472 | iih->circuit->u.bc.adjdb[iih->level - 1], | |
473 | iih->circuit->u.bc.lan_neighs[iih->level - 1]); | |
474 | } | |
475 | ||
476 | if (adj->dis_record[iih->level - 1].dis == ISIS_IS_DIS) { | |
d7c0a89a QY |
477 | uint8_t *dis = (iih->level == 1) |
478 | ? iih->circuit->u.bc.l1_desig_is | |
479 | : iih->circuit->u.bc.l2_desig_is; | |
0c1bd758 CF |
480 | |
481 | if (memcmp(dis, iih->dis, ISIS_SYS_ID_LEN + 1)) { | |
482 | thread_add_event(master, isis_event_dis_status_change, | |
483 | iih->circuit, 0, NULL); | |
484 | memcpy(dis, iih->dis, ISIS_SYS_ID_LEN + 1); | |
485 | } | |
d62a17ae | 486 | } |
3f045a08 | 487 | |
0c1bd758 CF |
488 | adj->circuit_t = iih->circ_type; |
489 | adj->hold_time = iih->holdtime; | |
490 | adj->last_upd = time(NULL); | |
491 | adj->prio[iih->level - 1] = iih->priority; | |
492 | memcpy(adj->lanid, iih->dis, ISIS_SYS_ID_LEN + 1); | |
3f045a08 | 493 | |
0c1bd758 CF |
494 | bool changed; |
495 | isis_tlvs_to_adj(iih->tlvs, adj, &changed); | |
496 | changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable, | |
497 | adj); | |
498 | ||
499 | /* lets take care of the expiry */ | |
50478845 | 500 | thread_cancel(&adj->t_expire); |
0c1bd758 CF |
501 | thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time, |
502 | &adj->t_expire); | |
503 | ||
504 | /* | |
505 | * If the snpa for this circuit is found from LAN Neighbours TLV | |
506 | * we have two-way communication -> adjacency can be put to state "up" | |
507 | */ | |
508 | bool own_snpa_found = | |
509 | isis_tlvs_own_snpa_found(iih->tlvs, iih->circuit->u.bc.snpa); | |
510 | ||
511 | if (adj->adj_state != ISIS_ADJ_UP) { | |
512 | if (own_snpa_found) { | |
513 | isis_adj_state_change( | |
16167b31 | 514 | &adj, ISIS_ADJ_UP, |
0c1bd758 CF |
515 | "own SNPA found in LAN Neighbours TLV"); |
516 | } | |
517 | } else { | |
518 | if (!own_snpa_found) { | |
519 | isis_adj_state_change( | |
16167b31 | 520 | &adj, ISIS_ADJ_INITIALIZING, |
0c1bd758 CF |
521 | "own SNPA not found in LAN Neighbours TLV"); |
522 | } | |
d62a17ae | 523 | } |
eb5d44eb | 524 | |
0c1bd758 CF |
525 | if (adj->adj_state == ISIS_ADJ_UP && changed) |
526 | lsp_regenerate_schedule(adj->circuit->area, iih->level, 0); | |
527 | ||
e740f9c1 | 528 | if (IS_DEBUG_ADJ_PACKETS) { |
d62a17ae | 529 | zlog_debug( |
0c1bd758 CF |
530 | "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd", |
531 | iih->circuit->area->area_tag, iih->level, | |
532 | snpa_print(iih->ssnpa), iih->circuit->interface->name, | |
533 | circuit_t2string(iih->circuit->is_type), | |
534 | iih->circuit->circuit_id, | |
535 | stream_get_endp(iih->circuit->rcv_stream)); | |
d62a17ae | 536 | } |
0c1bd758 CF |
537 | return ISIS_OK; |
538 | } | |
eb5d44eb | 539 | |
17c9dcd5 CF |
540 | static int pdu_len_validate(uint16_t pdu_len, struct isis_circuit *circuit) |
541 | { | |
542 | if (pdu_len < stream_get_getp(circuit->rcv_stream) | |
543 | || pdu_len > ISO_MTU(circuit) | |
544 | || pdu_len > stream_get_endp(circuit->rcv_stream)) | |
545 | return 1; | |
546 | ||
547 | if (pdu_len < stream_get_endp(circuit->rcv_stream)) | |
548 | stream_set_endp(circuit->rcv_stream, pdu_len); | |
549 | return 0; | |
550 | } | |
551 | ||
1ee746d9 | 552 | static void update_rej_adj_count(struct isis_circuit *circuit) |
553 | { | |
554 | circuit->rej_adjacencies++; | |
555 | if (circuit->is_type == IS_LEVEL_1) | |
556 | circuit->area->rej_adjacencies[0]++; | |
557 | else if (circuit->is_type == IS_LEVEL_2) | |
558 | circuit->area->rej_adjacencies[1]++; | |
559 | else { | |
560 | circuit->area->rej_adjacencies[0]++; | |
561 | circuit->area->rej_adjacencies[1]++; | |
562 | } | |
563 | } | |
564 | ||
0c1bd758 | 565 | static int process_hello(uint8_t pdu_type, struct isis_circuit *circuit, |
d7c0a89a | 566 | uint8_t *ssnpa) |
0c1bd758 | 567 | { |
3380c990 EDP |
568 | /* keep a copy of the raw pdu for NB notifications */ |
569 | size_t pdu_start = stream_get_getp(circuit->rcv_stream); | |
570 | size_t pdu_end = stream_get_endp(circuit->rcv_stream); | |
571 | char raw_pdu[pdu_end - pdu_start]; | |
0c1bd758 CF |
572 | bool p2p_hello = (pdu_type == P2P_HELLO); |
573 | int level = p2p_hello ? 0 | |
574 | : (pdu_type == L1_LAN_HELLO) ? ISIS_LEVEL1 | |
575 | : ISIS_LEVEL2; | |
576 | const char *pdu_name = | |
577 | p2p_hello | |
578 | ? "P2P IIH" | |
579 | : (level == ISIS_LEVEL1) ? "L1 LAN IIH" : "L2 LAN IIH"; | |
580 | ||
3380c990 EDP |
581 | stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start, |
582 | pdu_end - pdu_start); | |
e740f9c1 | 583 | if (IS_DEBUG_ADJ_PACKETS) { |
0c1bd758 CF |
584 | zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u", |
585 | circuit->area->area_tag, pdu_name, | |
586 | circuit->interface->name, | |
587 | circuit_t2string(circuit->is_type), | |
588 | circuit->circuit_id); | |
e740f9c1 | 589 | if (IS_DEBUG_PACKET_DUMP) |
0c1bd758 CF |
590 | zlog_dump_data(STREAM_DATA(circuit->rcv_stream), |
591 | stream_get_endp(circuit->rcv_stream)); | |
592 | } | |
593 | ||
594 | if (p2p_hello) { | |
595 | if (circuit->circ_type != CIRCUIT_T_P2P) { | |
596 | zlog_warn("p2p hello on non p2p circuit"); | |
1ee746d9 | 597 | update_rej_adj_count(circuit); |
af6911c9 EDP |
598 | #ifndef FABRICD |
599 | isis_notif_reject_adjacency( | |
600 | circuit, "p2p hello on non p2p circuit", | |
1ee746d9 | 601 | raw_pdu, sizeof(raw_pdu)); |
af6911c9 | 602 | #endif /* ifndef FABRICD */ |
0c1bd758 CF |
603 | return ISIS_WARNING; |
604 | } | |
605 | } else { | |
606 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) { | |
607 | zlog_warn("lan hello on non broadcast circuit"); | |
1ee746d9 | 608 | update_rej_adj_count(circuit); |
af6911c9 EDP |
609 | #ifndef FABRICD |
610 | isis_notif_reject_adjacency( | |
611 | circuit, "lan hello on non broadcast circuit", | |
1ee746d9 | 612 | raw_pdu, sizeof(raw_pdu)); |
af6911c9 | 613 | #endif /* ifndef FABRICD */ |
0c1bd758 CF |
614 | return ISIS_WARNING; |
615 | } | |
616 | ||
617 | if (circuit->ext_domain) { | |
d62a17ae | 618 | zlog_debug( |
0c1bd758 CF |
619 | "level %d LAN Hello received over circuit with externalDomain = true", |
620 | level); | |
1ee746d9 | 621 | update_rej_adj_count(circuit); |
af6911c9 EDP |
622 | #ifndef FABRICD |
623 | isis_notif_reject_adjacency( | |
624 | circuit, | |
625 | "LAN Hello received over circuit with externalDomain = true", | |
1ee746d9 | 626 | raw_pdu, sizeof(raw_pdu)); |
af6911c9 | 627 | #endif /* ifndef FABRICD */ |
0c1bd758 CF |
628 | return ISIS_WARNING; |
629 | } | |
630 | ||
af8ac8f9 | 631 | if (!(circuit->is_type & level)) { |
e740f9c1 | 632 | if (IS_DEBUG_ADJ_PACKETS) { |
0c1bd758 CF |
633 | zlog_debug( |
634 | "ISIS-Adj (%s): Interface level mismatch, %s", | |
635 | circuit->area->area_tag, | |
636 | circuit->interface->name); | |
637 | } | |
1ee746d9 | 638 | update_rej_adj_count(circuit); |
af6911c9 | 639 | #ifndef FABRICD |
1ee746d9 | 640 | isis_notif_reject_adjacency(circuit, |
641 | "Interface level mismatch", | |
642 | raw_pdu, sizeof(raw_pdu)); | |
af6911c9 | 643 | #endif /* ifndef FABRICD */ |
0c1bd758 | 644 | return ISIS_WARNING; |
d62a17ae | 645 | } |
f390d2c7 | 646 | } |
eb5d44eb | 647 | |
0c1bd758 CF |
648 | struct iih_info iih = { |
649 | .circuit = circuit, .ssnpa = ssnpa, .level = level}; | |
650 | ||
651 | /* Generic IIH Header */ | |
652 | iih.circ_type = stream_getc(circuit->rcv_stream) & 0x03; | |
653 | stream_get(iih.sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN); | |
654 | iih.holdtime = stream_getw(circuit->rcv_stream); | |
655 | iih.pdu_len = stream_getw(circuit->rcv_stream); | |
656 | ||
657 | if (p2p_hello) { | |
658 | iih.circuit_id = stream_getc(circuit->rcv_stream); | |
659 | } else { | |
660 | iih.priority = stream_getc(circuit->rcv_stream); | |
661 | stream_get(iih.dis, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1); | |
f390d2c7 | 662 | } |
0c1bd758 | 663 | |
17c9dcd5 | 664 | if (pdu_len_validate(iih.pdu_len, circuit)) { |
d62a17ae | 665 | zlog_warn( |
6cde4b45 | 666 | "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %hu", |
0c1bd758 CF |
667 | circuit->area->area_tag, pdu_name, |
668 | circuit->interface->name, iih.pdu_len); | |
1ee746d9 | 669 | update_rej_adj_count(circuit); |
af6911c9 EDP |
670 | #ifndef FABRICD |
671 | isis_notif_reject_adjacency(circuit, "Invalid PDU length", | |
1ee746d9 | 672 | raw_pdu, sizeof(raw_pdu)); |
af6911c9 | 673 | #endif /* ifndef FABRICD */ |
d62a17ae | 674 | return ISIS_WARNING; |
675 | } | |
3f045a08 | 676 | |
0c1bd758 | 677 | if (!p2p_hello && !(level & iih.circ_type)) { |
1a7ecb96 | 678 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
679 | "Level %d LAN Hello with Circuit Type %d", level, |
680 | iih.circ_type); | |
1ee746d9 | 681 | update_rej_adj_count(circuit); |
af6911c9 | 682 | #ifndef FABRICD |
1ee746d9 | 683 | isis_notif_reject_adjacency(circuit, |
684 | "LAN Hello with wrong IS-level", | |
685 | raw_pdu, sizeof(raw_pdu)); | |
af6911c9 | 686 | #endif /* ifndef FABRICD */ |
d62a17ae | 687 | return ISIS_ERROR; |
688 | } | |
3f045a08 | 689 | |
0c1bd758 CF |
690 | const char *error_log; |
691 | int retval = ISIS_WARNING; | |
d62a17ae | 692 | |
0c1bd758 CF |
693 | if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream), |
694 | circuit->rcv_stream, &iih.tlvs, &error_log)) { | |
695 | zlog_warn("isis_unpack_tlvs() failed: %s", error_log); | |
1ee746d9 | 696 | update_rej_adj_count(circuit); |
af6911c9 EDP |
697 | #ifndef FABRICD |
698 | isis_notif_reject_adjacency(circuit, "Failed to unpack TLVs", | |
1ee746d9 | 699 | raw_pdu, sizeof(raw_pdu)); |
af6911c9 | 700 | #endif /* ifndef FABRICD */ |
d62a17ae | 701 | goto out; |
702 | } | |
eb5d44eb | 703 | |
0c1bd758 CF |
704 | if (!iih.tlvs->area_addresses.count) { |
705 | zlog_warn("No Area addresses TLV in %s", pdu_name); | |
9d92b84b EDP |
706 | #ifndef FABRICD |
707 | /* send northbound notification */ | |
1ee746d9 | 708 | isis_notif_area_mismatch(circuit, raw_pdu, sizeof(raw_pdu)); |
9d92b84b | 709 | #endif /* ifndef FABRICD */ |
d62a17ae | 710 | goto out; |
711 | } | |
f390d2c7 | 712 | |
0c1bd758 CF |
713 | if (!iih.tlvs->protocols_supported.count) { |
714 | zlog_warn("No supported protocols TLV in %s", pdu_name); | |
1ee746d9 | 715 | update_rej_adj_count(circuit); |
af6911c9 | 716 | #ifndef FABRICD |
1ee746d9 | 717 | isis_notif_reject_adjacency(circuit, |
718 | "No supported protocols TLV", | |
719 | raw_pdu, sizeof(raw_pdu)); | |
af6911c9 | 720 | #endif /* ifndef FABRICD */ |
d62a17ae | 721 | goto out; |
722 | } | |
b72f345d | 723 | |
3380c990 EDP |
724 | int auth_code = isis_tlvs_auth_is_valid(iih.tlvs, &circuit->passwd, |
725 | circuit->rcv_stream, false); | |
726 | if (auth_code != ISIS_AUTH_OK) { | |
0c1bd758 CF |
727 | isis_event_auth_failure(circuit->area->area_tag, |
728 | "IIH authentication failure", | |
729 | iih.sys_id); | |
3380c990 EDP |
730 | #ifndef FABRICD |
731 | /* send northbound notification */ | |
732 | stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start, | |
733 | pdu_end - pdu_start); | |
c32496ee | 734 | if (auth_code == ISIS_AUTH_FAILURE) { |
1ee746d9 | 735 | update_rej_adj_count(circuit); |
736 | isis_notif_authentication_failure(circuit, raw_pdu, | |
737 | sizeof(raw_pdu)); | |
c32496ee | 738 | } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */ |
1ee746d9 | 739 | update_rej_adj_count(circuit); |
740 | isis_notif_authentication_type_failure(circuit, raw_pdu, | |
741 | sizeof(raw_pdu)); | |
c32496ee | 742 | } |
3380c990 | 743 | #endif /* ifndef FABRICD */ |
0c1bd758 | 744 | goto out; |
d62a17ae | 745 | } |
eb5d44eb | 746 | |
99e5d4af | 747 | if (!memcmp(iih.sys_id, circuit->isis->sysid, ISIS_SYS_ID_LEN)) { |
0c1bd758 | 748 | zlog_warn( |
f3abc412 | 749 | "ISIS-Adj (%s): Received IIH with own sysid on %s - discard", |
750 | circuit->area->area_tag, circuit->interface->name); | |
1ee746d9 | 751 | update_rej_adj_count(circuit); |
af6911c9 | 752 | #ifndef FABRICD |
1ee746d9 | 753 | isis_notif_reject_adjacency(circuit, |
754 | "Received IIH with our own sysid", | |
755 | raw_pdu, sizeof(raw_pdu)); | |
af6911c9 | 756 | #endif /* ifndef FABRICD */ |
0c1bd758 | 757 | goto out; |
d62a17ae | 758 | } |
19f78ceb | 759 | |
0c1bd758 CF |
760 | if (!p2p_hello |
761 | && (listcount(circuit->area->area_addrs) == 0 | |
762 | || (level == ISIS_LEVEL1 | |
763 | && !isis_tlvs_area_addresses_match( | |
764 | iih.tlvs, circuit->area->area_addrs)))) { | |
e740f9c1 | 765 | if (IS_DEBUG_ADJ_PACKETS) { |
d62a17ae | 766 | zlog_debug( |
767 | "ISIS-Adj (%s): Area mismatch, level %d IIH on %s", | |
768 | circuit->area->area_tag, level, | |
769 | circuit->interface->name); | |
770 | } | |
9d92b84b EDP |
771 | #ifndef FABRICD |
772 | /* send northbound notification */ | |
1ee746d9 | 773 | isis_notif_area_mismatch(circuit, raw_pdu, sizeof(raw_pdu)); |
9d92b84b | 774 | #endif /* ifndef FABRICD */ |
d62a17ae | 775 | goto out; |
f390d2c7 | 776 | } |
eb5d44eb | 777 | |
41415888 | 778 | iih.v4_usable = (fabricd_ip_addrs(circuit) |
0c1bd758 | 779 | && iih.tlvs->ipv4_address.count); |
d62a17ae | 780 | |
0c1bd758 CF |
781 | iih.v6_usable = (circuit->ipv6_link && listcount(circuit->ipv6_link) |
782 | && iih.tlvs->ipv6_address.count); | |
28a8cfcb | 783 | |
c9b0e434 | 784 | if (!iih.v4_usable && !iih.v6_usable) { |
e740f9c1 | 785 | if (IS_DEBUG_ADJ_PACKETS) { |
c9b0e434 CF |
786 | zlog_warn( |
787 | "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH", | |
788 | circuit->area->area_tag); | |
789 | } | |
1ee746d9 | 790 | update_rej_adj_count(circuit); |
af6911c9 EDP |
791 | #ifndef FABRICD |
792 | isis_notif_reject_adjacency( | |
793 | circuit, "Neither IPv4 not IPv6 considered usable", | |
1ee746d9 | 794 | raw_pdu, sizeof(raw_pdu)); |
af6911c9 | 795 | #endif /* ifndef FABRICD */ |
d62a17ae | 796 | goto out; |
c9b0e434 | 797 | } |
d8fba7d9 | 798 | |
0c1bd758 | 799 | retval = p2p_hello ? process_p2p_hello(&iih) : process_lan_hello(&iih); |
f390d2c7 | 800 | out: |
0c1bd758 | 801 | isis_free_tlvs(iih.tlvs); |
eb5d44eb | 802 | |
d62a17ae | 803 | return retval; |
eb5d44eb | 804 | } |
805 | ||
a6b60da9 CF |
806 | static void lsp_flood_or_update(struct isis_lsp *lsp, |
807 | struct isis_circuit *circuit, | |
808 | bool circuit_scoped) | |
809 | { | |
89cdc4df | 810 | if (!circuit_scoped) |
a6b60da9 | 811 | lsp_flood(lsp, circuit); |
89cdc4df | 812 | else |
a6b60da9 | 813 | fabricd_update_lsp_no_flood(lsp, circuit); |
a6b60da9 CF |
814 | } |
815 | ||
eb5d44eb | 816 | /* |
817 | * Process Level 1/2 Link State | |
818 | * ISO - 10589 | |
819 | * Section 7.3.15.1 - Action on receipt of a link state PDU | |
f390d2c7 | 820 | */ |
af8ac8f9 | 821 | static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit, |
9b39405f | 822 | const uint8_t *ssnpa, uint8_t max_area_addrs) |
eb5d44eb | 823 | { |
1cbd5b37 CF |
824 | int level; |
825 | bool circuit_scoped; | |
3380c990 EDP |
826 | size_t pdu_start = stream_get_getp(circuit->rcv_stream); |
827 | size_t pdu_end = stream_get_endp(circuit->rcv_stream); | |
828 | char raw_pdu[pdu_end - pdu_start]; | |
829 | ||
830 | stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start, | |
831 | pdu_end - pdu_start); | |
1cbd5b37 CF |
832 | |
833 | if (pdu_type == FS_LINK_STATE) { | |
834 | if (!fabricd) | |
835 | return ISIS_ERROR; | |
836 | if (max_area_addrs != L2_CIRCUIT_FLOODING_SCOPE) | |
837 | return ISIS_ERROR; | |
838 | level = ISIS_LEVEL2; | |
839 | circuit_scoped = true; | |
840 | ||
841 | /* The stream is used verbatim for sending out new LSPDUs. | |
842 | * So make sure we store it as an L2 LSPDU internally. | |
843 | * (compare for the reverse in `send_lsp`) */ | |
844 | stream_putc_at(circuit->rcv_stream, 4, L2_LINK_STATE); | |
845 | stream_putc_at(circuit->rcv_stream, 7, 0); | |
846 | } else { | |
847 | if (pdu_type == L1_LINK_STATE) | |
848 | level = ISIS_LEVEL1; | |
849 | else | |
850 | level = ISIS_LEVEL2; | |
851 | circuit_scoped = false; | |
852 | } | |
d62a17ae | 853 | |
e740f9c1 | 854 | if (IS_DEBUG_UPDATE_PACKETS) { |
d62a17ae | 855 | zlog_debug( |
1cbd5b37 CF |
856 | "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u", |
857 | circuit->area->area_tag, | |
858 | circuit_scoped ? "Circuit scoped " : "", level, | |
d62a17ae | 859 | circuit->interface->name, |
860 | circuit_t2string(circuit->is_type), | |
861 | circuit->circuit_id); | |
e740f9c1 | 862 | if (IS_DEBUG_PACKET_DUMP) |
d62a17ae | 863 | zlog_dump_data(STREAM_DATA(circuit->rcv_stream), |
864 | stream_get_endp(circuit->rcv_stream)); | |
865 | } | |
f390d2c7 | 866 | |
3e300703 | 867 | struct isis_lsp_hdr hdr = {}; |
eb5d44eb | 868 | |
af8ac8f9 CF |
869 | hdr.pdu_len = stream_getw(circuit->rcv_stream); |
870 | hdr.rem_lifetime = stream_getw(circuit->rcv_stream); | |
871 | stream_get(hdr.lsp_id, circuit->rcv_stream, sizeof(hdr.lsp_id)); | |
872 | hdr.seqno = stream_getl(circuit->rcv_stream); | |
873 | hdr.checksum = stream_getw(circuit->rcv_stream); | |
874 | hdr.lsp_bits = stream_getc(circuit->rcv_stream); | |
eb5d44eb | 875 | |
8375020a EDP |
876 | #ifndef FABRICD |
877 | /* send northbound notification */ | |
1ee746d9 | 878 | isis_notif_lsp_received(circuit, hdr.lsp_id, hdr.seqno, time(NULL), |
879 | sysid_print(hdr.lsp_id)); | |
8375020a EDP |
880 | #endif /* ifndef FABRICD */ |
881 | ||
af8ac8f9 | 882 | if (pdu_len_validate(hdr.pdu_len, circuit)) { |
6cde4b45 | 883 | zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %hu", |
af8ac8f9 CF |
884 | circuit->area->area_tag, rawlspid_print(hdr.lsp_id), |
885 | hdr.pdu_len); | |
d62a17ae | 886 | return ISIS_WARNING; |
f390d2c7 | 887 | } |
d62a17ae | 888 | |
e740f9c1 | 889 | if (IS_DEBUG_UPDATE_PACKETS) { |
6cde4b45 | 890 | zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s", |
af8ac8f9 CF |
891 | circuit->area->area_tag, level, |
892 | rawlspid_print(hdr.lsp_id), hdr.seqno, hdr.checksum, | |
893 | hdr.rem_lifetime, hdr.pdu_len, | |
894 | circuit->interface->name); | |
f390d2c7 | 895 | } |
d62a17ae | 896 | |
897 | /* lsp is_type check */ | |
af8ac8f9 CF |
898 | if ((hdr.lsp_bits & IS_LEVEL_1) != IS_LEVEL_1) { |
899 | zlog_debug( | |
47b13e9b | 900 | "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%x", |
af8ac8f9 CF |
901 | circuit->area->area_tag, rawlspid_print(hdr.lsp_id), |
902 | hdr.lsp_bits & IS_LEVEL_1_AND_2); | |
d62a17ae | 903 | /* continue as per RFC1122 Be liberal in what you accept, and |
904 | * conservative in what you send */ | |
f390d2c7 | 905 | } |
d62a17ae | 906 | |
907 | /* Checksum sanity check - FIXME: move to correct place */ | |
908 | /* 12 = sysid+pdu+remtime */ | |
af8ac8f9 CF |
909 | if (iso_csum_verify(STREAM_DATA(circuit->rcv_stream) + 12, |
910 | hdr.pdu_len - 12, hdr.checksum, 12)) { | |
911 | zlog_debug( | |
6cde4b45 | 912 | "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04hx", |
af8ac8f9 CF |
913 | circuit->area->area_tag, rawlspid_print(hdr.lsp_id), |
914 | hdr.checksum); | |
d62a17ae | 915 | return ISIS_WARNING; |
f390d2c7 | 916 | } |
3f045a08 | 917 | |
d62a17ae | 918 | /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */ |
919 | if (circuit->ext_domain) { | |
920 | zlog_debug( | |
3efd0893 | 921 | "ISIS-Upd (%s): LSP %s received at level %d over circuit with externalDomain = true", |
af8ac8f9 | 922 | circuit->area->area_tag, rawlspid_print(hdr.lsp_id), |
d62a17ae | 923 | level); |
d62a17ae | 924 | return ISIS_WARNING; |
925 | } | |
eb5d44eb | 926 | |
d62a17ae | 927 | /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */ |
af8ac8f9 | 928 | if (!(circuit->is_type & level)) { |
d62a17ae | 929 | zlog_debug( |
3efd0893 | 930 | "ISIS-Upd (%s): LSP %s received at level %d over circuit of type %s", |
af8ac8f9 | 931 | circuit->area->area_tag, rawlspid_print(hdr.lsp_id), |
d62a17ae | 932 | level, circuit_t2string(circuit->is_type)); |
d62a17ae | 933 | return ISIS_WARNING; |
934 | } | |
0250758d | 935 | |
af8ac8f9 CF |
936 | struct isis_tlvs *tlvs = NULL; |
937 | int retval = ISIS_WARNING; | |
938 | const char *error_log; | |
939 | ||
940 | if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream), | |
941 | circuit->rcv_stream, &tlvs, &error_log)) { | |
942 | zlog_warn("Something went wrong unpacking the LSP: %s", | |
943 | error_log); | |
86370604 EDP |
944 | #ifndef FABRICD |
945 | /* send northbound notification. Note that the tlv-type and | |
946 | * offset cannot correctly be set here as they are not returned | |
947 | * by isis_unpack_tlvs, but in there I cannot fire a | |
948 | * notification because I have no circuit information. So until | |
949 | * we change the code above to return those extra fields, we | |
950 | * will send dummy values which are ignored in the callback | |
951 | */ | |
1ee746d9 | 952 | circuit->lsp_error_counter++; |
953 | if (circuit->is_type == IS_LEVEL_1) { | |
954 | circuit->area->lsp_error_counter[0]++; | |
955 | } else if (circuit->is_type == IS_LEVEL_2) { | |
956 | circuit->area->lsp_error_counter[1]++; | |
957 | } else { | |
958 | circuit->area->lsp_error_counter[0]++; | |
959 | circuit->area->lsp_error_counter[1]++; | |
960 | } | |
961 | ||
962 | isis_notif_lsp_error(circuit, hdr.lsp_id, raw_pdu, | |
963 | sizeof(raw_pdu), 0, 0); | |
86370604 | 964 | #endif /* ifndef FABRICD */ |
af8ac8f9 CF |
965 | goto out; |
966 | } | |
967 | ||
d62a17ae | 968 | /* 7.3.15.1 a) 4 - need to make sure IDLength matches */ |
969 | ||
970 | /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use | |
971 | * 3 */ | |
972 | ||
973 | /* 7.3.15.1 a) 7 - password check */ | |
af8ac8f9 CF |
974 | struct isis_passwd *passwd = (level == ISIS_LEVEL1) |
975 | ? &circuit->area->area_passwd | |
976 | : &circuit->area->domain_passwd; | |
3380c990 EDP |
977 | int auth_code = isis_tlvs_auth_is_valid(tlvs, passwd, |
978 | circuit->rcv_stream, true); | |
979 | if (auth_code != ISIS_AUTH_OK) { | |
af8ac8f9 CF |
980 | isis_event_auth_failure(circuit->area->area_tag, |
981 | "LSP authentication failure", | |
982 | hdr.lsp_id); | |
3380c990 EDP |
983 | #ifndef FABRICD |
984 | /* send northbound notification */ | |
c32496ee RW |
985 | if (auth_code == ISIS_AUTH_FAILURE) { |
986 | circuit->auth_failures++; | |
1ee746d9 | 987 | if (circuit->is_type == IS_LEVEL_1) { |
988 | circuit->area->auth_failures[0]++; | |
989 | } else if (circuit->is_type == IS_LEVEL_2) { | |
990 | circuit->area->auth_failures[1]++; | |
991 | } else { | |
992 | circuit->area->auth_failures[0]++; | |
993 | circuit->area->auth_failures[1]++; | |
994 | } | |
995 | isis_notif_authentication_failure(circuit, raw_pdu, | |
996 | sizeof(raw_pdu)); | |
c32496ee RW |
997 | } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */ |
998 | circuit->auth_type_failures++; | |
1ee746d9 | 999 | if (circuit->is_type == IS_LEVEL_1) { |
1000 | circuit->area->auth_type_failures[0]++; | |
1001 | } else if (circuit->is_type == IS_LEVEL_2) { | |
1002 | circuit->area->auth_type_failures[1]++; | |
1003 | } else { | |
1004 | circuit->area->auth_type_failures[0]++; | |
1005 | circuit->area->auth_type_failures[1]++; | |
1006 | } | |
1007 | isis_notif_authentication_type_failure(circuit, raw_pdu, | |
1008 | sizeof(raw_pdu)); | |
c32496ee | 1009 | } |
3380c990 | 1010 | #endif /* ifndef FABRICD */ |
af8ac8f9 | 1011 | goto out; |
f390d2c7 | 1012 | } |
af8ac8f9 | 1013 | |
d62a17ae | 1014 | /* Find the LSP in our database and compare it to this Link State header |
1015 | */ | |
af8ac8f9 | 1016 | struct isis_lsp *lsp = |
4bef0ec4 | 1017 | lsp_search(&circuit->area->lspdb[level - 1], hdr.lsp_id); |
af8ac8f9 | 1018 | int comp = 0; |
d62a17ae | 1019 | if (lsp) |
af8ac8f9 CF |
1020 | comp = lsp_compare(circuit->area->area_tag, lsp, hdr.seqno, |
1021 | hdr.checksum, hdr.rem_lifetime); | |
d62a17ae | 1022 | if (lsp && (lsp->own_lsp)) |
1023 | goto dontcheckadj; | |
1024 | ||
1025 | /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same | |
1026 | * level */ | |
1027 | /* for broadcast circuits, snpa should be compared */ | |
1028 | ||
1029 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
af8ac8f9 CF |
1030 | if (!isis_adj_lookup_snpa(ssnpa, |
1031 | circuit->u.bc.adjdb[level - 1])) { | |
6cde4b45 | 1032 | zlog_debug("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s", |
af8ac8f9 CF |
1033 | circuit->area->area_tag, |
1034 | rawlspid_print(hdr.lsp_id), hdr.seqno, | |
1035 | hdr.checksum, hdr.rem_lifetime, | |
1036 | circuit->interface->name); | |
1037 | goto out; /* Silently discard */ | |
d62a17ae | 1038 | } |
1039 | } | |
1040 | /* for non broadcast, we just need to find same level adj */ | |
1041 | else { | |
1042 | /* If no adj, or no sharing of level */ | |
1043 | if (!circuit->u.p2p.neighbor) { | |
af8ac8f9 CF |
1044 | retval = ISIS_OK; |
1045 | goto out; | |
d62a17ae | 1046 | } else { |
1047 | if (((level == IS_LEVEL_1) | |
1048 | && (circuit->u.p2p.neighbor->adj_usage | |
1049 | == ISIS_ADJ_LEVEL2)) | |
1050 | || ((level == IS_LEVEL_2) | |
1051 | && (circuit->u.p2p.neighbor->adj_usage | |
1052 | == ISIS_ADJ_LEVEL1))) | |
af8ac8f9 | 1053 | goto out; |
f390d2c7 | 1054 | } |
f390d2c7 | 1055 | } |
f390d2c7 | 1056 | |
af8ac8f9 CF |
1057 | bool lsp_confusion; |
1058 | ||
d62a17ae | 1059 | dontcheckadj: |
1060 | /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */ | |
1061 | ||
1062 | /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */ | |
1063 | ||
1064 | /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do | |
1065 | * it */ | |
1066 | ||
1067 | /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num | |
1068 | * but | |
1069 | * wrong checksum, initiate a purge. */ | |
af8ac8f9 | 1070 | if (lsp && (lsp->hdr.seqno == hdr.seqno) |
2c92bee4 CF |
1071 | && (lsp->hdr.checksum != hdr.checksum) |
1072 | && hdr.rem_lifetime) { | |
6cde4b45 | 1073 | zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.", |
af8ac8f9 CF |
1074 | circuit->area->area_tag, rawlspid_print(hdr.lsp_id), |
1075 | hdr.seqno); | |
1076 | hdr.rem_lifetime = 0; | |
1077 | lsp_confusion = true; | |
d62a17ae | 1078 | } else |
af8ac8f9 | 1079 | lsp_confusion = false; |
d62a17ae | 1080 | |
1081 | /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */ | |
af8ac8f9 | 1082 | if (hdr.rem_lifetime == 0) { |
d62a17ae | 1083 | if (!lsp) { |
1084 | /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't | |
1085 | * save */ | |
1086 | /* only needed on explicit update, eg - p2p */ | |
1087 | if (circuit->circ_type == CIRCUIT_T_P2P) | |
af8ac8f9 CF |
1088 | ack_lsp(&hdr, circuit, level); |
1089 | goto out; /* FIXME: do we need a purge? */ | |
d62a17ae | 1090 | } else { |
99e5d4af | 1091 | if (memcmp(hdr.lsp_id, circuit->isis->sysid, |
eab88f36 | 1092 | ISIS_SYS_ID_LEN)) { |
d62a17ae | 1093 | /* LSP by some other system -> do 7.3.16.4 b) */ |
1094 | /* 7.3.16.4 b) 1) */ | |
1095 | if (comp == LSP_NEWER) { | |
af8ac8f9 CF |
1096 | lsp_update(lsp, &hdr, tlvs, |
1097 | circuit->rcv_stream, | |
164066e4 CF |
1098 | circuit->area, level, |
1099 | lsp_confusion); | |
ebeae7d5 DS |
1100 | if (lsp_confusion) |
1101 | isis_free_tlvs(tlvs); | |
af8ac8f9 | 1102 | tlvs = NULL; |
d62a17ae | 1103 | /* ii */ |
a6b60da9 CF |
1104 | lsp_flood_or_update(lsp, NULL, |
1105 | circuit_scoped); | |
d62a17ae | 1106 | /* v */ |
1107 | ISIS_FLAGS_CLEAR_ALL( | |
996c9314 LB |
1108 | lsp->SSNflags); /* FIXME: |
1109 | OTHER | |
1110 | than c | |
1111 | */ | |
d62a17ae | 1112 | |
1113 | /* For the case of lsp confusion, flood | |
1114 | * the purge back to its | |
1115 | * originator so that it can react. | |
1116 | * Otherwise, don't reflood | |
1117 | * through incoming circuit as usual */ | |
1118 | if (!lsp_confusion) { | |
9b39405f CF |
1119 | isis_tx_queue_del( |
1120 | circuit->tx_queue, | |
1121 | lsp); | |
1122 | ||
d62a17ae | 1123 | /* iv */ |
1124 | if (circuit->circ_type | |
1125 | != CIRCUIT_T_BROADCAST) | |
1126 | ISIS_SET_FLAG( | |
1127 | lsp->SSNflags, | |
1128 | circuit); | |
1129 | } | |
1130 | } /* 7.3.16.4 b) 2) */ | |
1131 | else if (comp == LSP_EQUAL) { | |
1132 | /* i */ | |
9b39405f CF |
1133 | isis_tx_queue_del(circuit->tx_queue, |
1134 | lsp); | |
d62a17ae | 1135 | /* ii */ |
1136 | if (circuit->circ_type | |
1137 | != CIRCUIT_T_BROADCAST) | |
1138 | ISIS_SET_FLAG(lsp->SSNflags, | |
1139 | circuit); | |
1140 | } /* 7.3.16.4 b) 3) */ | |
1141 | else { | |
9b39405f CF |
1142 | isis_tx_queue_add(circuit->tx_queue, |
1143 | lsp, TX_LSP_NORMAL); | |
d62a17ae | 1144 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); |
1145 | } | |
af8ac8f9 | 1146 | } else if (lsp->hdr.rem_lifetime != 0) { |
d62a17ae | 1147 | /* our own LSP -> 7.3.16.4 c) */ |
1148 | if (comp == LSP_NEWER) { | |
897989f8 EDP |
1149 | #ifndef FABRICD |
1150 | if (lsp->hdr.seqno < hdr.seqno) { | |
1151 | /* send northbound | |
1152 | * notification */ | |
1ee746d9 | 1153 | circuit->area |
1154 | ->lsp_seqno_skipped_counter++; | |
897989f8 | 1155 | isis_notif_seqno_skipped( |
1ee746d9 | 1156 | circuit, hdr.lsp_id); |
897989f8 EDP |
1157 | } |
1158 | #endif /* ifndef FABRICD */ | |
af8ac8f9 | 1159 | lsp_inc_seqno(lsp, hdr.seqno); |
89cdc4df RM |
1160 | lsp_flood_or_update(lsp, NULL, |
1161 | circuit_scoped); | |
d62a17ae | 1162 | } else { |
9b39405f CF |
1163 | isis_tx_queue_add(circuit->tx_queue, |
1164 | lsp, TX_LSP_NORMAL); | |
d62a17ae | 1165 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); |
1166 | } | |
e740f9c1 | 1167 | if (IS_DEBUG_UPDATE_PACKETS) |
d62a17ae | 1168 | zlog_debug( |
6cde4b45 | 1169 | "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x", |
d62a17ae | 1170 | circuit->area->area_tag, |
af8ac8f9 CF |
1171 | rawlspid_print(hdr.lsp_id), |
1172 | lsp->hdr.seqno); | |
d32f213a EDP |
1173 | } else { |
1174 | /* our own LSP with 0 remaining life time */ | |
1175 | #ifndef FABRICD | |
1176 | /* send northbound notification */ | |
1ee746d9 | 1177 | isis_notif_own_lsp_purge(circuit, hdr.lsp_id); |
d32f213a | 1178 | #endif /* ifndef FABRICD */ |
d62a17ae | 1179 | } |
f390d2c7 | 1180 | } |
af8ac8f9 | 1181 | goto out; |
f390d2c7 | 1182 | } |
d62a17ae | 1183 | /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a |
1184 | * purge */ | |
99e5d4af | 1185 | if (memcmp(hdr.lsp_id, circuit->isis->sysid, ISIS_SYS_ID_LEN) == 0) { |
d62a17ae | 1186 | if (!lsp) { |
1187 | /* 7.3.16.4: initiate a purge */ | |
af8ac8f9 CF |
1188 | lsp_purge_non_exist(level, &hdr, circuit->area); |
1189 | retval = ISIS_OK; | |
1190 | goto out; | |
d62a17ae | 1191 | } |
1192 | /* 7.3.15.1 d) - If this is our own lsp and we have it */ | |
1193 | ||
1194 | /* In 7.3.16.1, If an Intermediate system R somewhere in the | |
1195 | * domain | |
1196 | * has information that the current sequence number for source S | |
1197 | * is | |
1198 | * "greater" than that held by S, ... */ | |
1199 | ||
562d7ef7 | 1200 | if (comp == LSP_NEWER) { |
d62a17ae | 1201 | /* 7.3.16.1 */ |
af8ac8f9 | 1202 | lsp_inc_seqno(lsp, hdr.seqno); |
897989f8 EDP |
1203 | #ifndef FABRICD |
1204 | /* send northbound notification */ | |
1ee746d9 | 1205 | circuit->area->lsp_seqno_skipped_counter++; |
1206 | isis_notif_seqno_skipped(circuit, hdr.lsp_id); | |
897989f8 | 1207 | #endif /* ifndef FABRICD */ |
e740f9c1 | 1208 | if (IS_DEBUG_UPDATE_PACKETS) { |
d62a17ae | 1209 | zlog_debug( |
6cde4b45 | 1210 | "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x", |
d62a17ae | 1211 | circuit->area->area_tag, |
af8ac8f9 CF |
1212 | rawlspid_print(hdr.lsp_id), |
1213 | lsp->hdr.seqno); | |
562d7ef7 CF |
1214 | } |
1215 | lsp_flood(lsp, NULL); | |
1216 | } else if (comp == LSP_EQUAL) { | |
1217 | isis_tx_queue_del(circuit->tx_queue, lsp); | |
1218 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1219 | ISIS_SET_FLAG(lsp->SSNflags, circuit); | |
1220 | } else { | |
1221 | isis_tx_queue_add(circuit->tx_queue, lsp, | |
1222 | TX_LSP_NORMAL); | |
1223 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); | |
d62a17ae | 1224 | } |
d62a17ae | 1225 | } else { |
1226 | /* 7.3.15.1 e) - This lsp originated on another system */ | |
1227 | ||
1228 | /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db | |
1229 | */ | |
1230 | if ((!lsp || comp == LSP_NEWER)) { | |
1231 | /* | |
1232 | * If this lsp is a frag, need to see if we have zero | |
1233 | * lsp present | |
1234 | */ | |
af8ac8f9 CF |
1235 | struct isis_lsp *lsp0 = NULL; |
1236 | if (LSP_FRAGMENT(hdr.lsp_id) != 0) { | |
1237 | uint8_t lspid[ISIS_SYS_ID_LEN + 2]; | |
1238 | memcpy(lspid, hdr.lsp_id, ISIS_SYS_ID_LEN + 1); | |
d62a17ae | 1239 | LSP_FRAGMENT(lspid) = 0; |
1240 | lsp0 = lsp_search( | |
4bef0ec4 | 1241 | &circuit->area->lspdb[level - 1], lspid); |
d62a17ae | 1242 | if (!lsp0) { |
1243 | zlog_debug( | |
1244 | "Got lsp frag, while zero lsp not in database"); | |
df0ba689 | 1245 | goto out; |
d62a17ae | 1246 | } |
1247 | } | |
1248 | /* i */ | |
1249 | if (!lsp) { | |
af8ac8f9 CF |
1250 | lsp = lsp_new_from_recv( |
1251 | &hdr, tlvs, circuit->rcv_stream, lsp0, | |
d62a17ae | 1252 | circuit->area, level); |
af8ac8f9 | 1253 | tlvs = NULL; |
4bef0ec4 DL |
1254 | lsp_insert(&circuit->area->lspdb[level - 1], |
1255 | lsp); | |
d62a17ae | 1256 | } else /* exists, so we overwrite */ |
1257 | { | |
af8ac8f9 | 1258 | lsp_update(lsp, &hdr, tlvs, circuit->rcv_stream, |
164066e4 | 1259 | circuit->area, level, false); |
af8ac8f9 | 1260 | tlvs = NULL; |
d62a17ae | 1261 | } |
a6b60da9 | 1262 | lsp_flood_or_update(lsp, circuit, circuit_scoped); |
d62a17ae | 1263 | |
1264 | /* iv */ | |
1265 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1266 | ISIS_SET_FLAG(lsp->SSNflags, circuit); | |
1267 | /* FIXME: v) */ | |
1268 | } | |
1269 | /* 7.3.15.1 e) 2) LSP equal to the one in db */ | |
1270 | else if (comp == LSP_EQUAL) { | |
9b39405f | 1271 | isis_tx_queue_del(circuit->tx_queue, lsp); |
af8ac8f9 | 1272 | lsp_update(lsp, &hdr, tlvs, circuit->rcv_stream, |
164066e4 | 1273 | circuit->area, level, false); |
af8ac8f9 | 1274 | tlvs = NULL; |
d62a17ae | 1275 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
1276 | ISIS_SET_FLAG(lsp->SSNflags, circuit); | |
1277 | } | |
1278 | /* 7.3.15.1 e) 3) LSP older than the one in db */ | |
1279 | else { | |
9b39405f CF |
1280 | isis_tx_queue_add(circuit->tx_queue, lsp, |
1281 | TX_LSP_NORMAL); | |
d62a17ae | 1282 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); |
1283 | } | |
f390d2c7 | 1284 | } |
af8ac8f9 CF |
1285 | |
1286 | retval = ISIS_OK; | |
1287 | ||
1288 | out: | |
e923107c | 1289 | fabricd_trigger_csnp(circuit->area, circuit_scoped); |
df0ba689 | 1290 | |
af8ac8f9 | 1291 | isis_free_tlvs(tlvs); |
d62a17ae | 1292 | return retval; |
eb5d44eb | 1293 | } |
1294 | ||
1295 | /* | |
1296 | * Process Sequence Numbers | |
1297 | * ISO - 10589 | |
1298 | * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU | |
1299 | */ | |
1300 | ||
17c9dcd5 | 1301 | static int process_snp(uint8_t pdu_type, struct isis_circuit *circuit, |
d7c0a89a | 1302 | const uint8_t *ssnpa) |
eb5d44eb | 1303 | { |
3380c990 EDP |
1304 | #ifndef FABRICD |
1305 | size_t pdu_start = stream_get_getp(circuit->rcv_stream); | |
1306 | size_t pdu_end = stream_get_endp(circuit->rcv_stream); | |
1307 | char raw_pdu[pdu_end - pdu_start]; | |
1308 | #endif /* ifndef FABRICD */ | |
1309 | ||
17c9dcd5 CF |
1310 | bool is_csnp = (pdu_type == L1_COMPLETE_SEQ_NUM |
1311 | || pdu_type == L2_COMPLETE_SEQ_NUM); | |
1312 | char typechar = is_csnp ? 'C' : 'P'; | |
1313 | int level = (pdu_type == L1_COMPLETE_SEQ_NUM | |
1314 | || pdu_type == L1_PARTIAL_SEQ_NUM) | |
1315 | ? ISIS_LEVEL1 | |
1316 | : ISIS_LEVEL2; | |
1317 | ||
1318 | uint16_t pdu_len = stream_getw(circuit->rcv_stream); | |
1319 | uint8_t rem_sys_id[ISIS_SYS_ID_LEN]; | |
3380c990 | 1320 | |
17c9dcd5 CF |
1321 | stream_get(rem_sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN); |
1322 | stream_forward_getp(circuit->rcv_stream, 1); /* Circuit ID - unused */ | |
1323 | ||
3e300703 DL |
1324 | uint8_t start_lsp_id[ISIS_SYS_ID_LEN + 2] = {}; |
1325 | uint8_t stop_lsp_id[ISIS_SYS_ID_LEN + 2] = {}; | |
17c9dcd5 CF |
1326 | |
1327 | if (is_csnp) { | |
1328 | stream_get(start_lsp_id, circuit->rcv_stream, | |
1329 | ISIS_SYS_ID_LEN + 2); | |
1330 | stream_get(stop_lsp_id, circuit->rcv_stream, | |
1331 | ISIS_SYS_ID_LEN + 2); | |
1332 | } | |
1333 | ||
1334 | if (pdu_len_validate(pdu_len, circuit)) { | |
1335 | zlog_warn("Received a CSNP with bogus length %d", pdu_len); | |
1336 | return ISIS_WARNING; | |
f390d2c7 | 1337 | } |
eb5d44eb | 1338 | |
e740f9c1 | 1339 | if (IS_DEBUG_SNP_PACKETS) { |
17c9dcd5 CF |
1340 | zlog_debug( |
1341 | "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u", | |
1342 | circuit->area->area_tag, level, typechar, | |
1343 | circuit->interface->name, | |
1344 | circuit_t2string(circuit->is_type), | |
1345 | circuit->circuit_id); | |
e740f9c1 | 1346 | if (IS_DEBUG_PACKET_DUMP) |
17c9dcd5 CF |
1347 | zlog_dump_data(STREAM_DATA(circuit->rcv_stream), |
1348 | stream_get_endp(circuit->rcv_stream)); | |
1349 | } | |
eb5d44eb | 1350 | |
d62a17ae | 1351 | /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */ |
1352 | if (circuit->ext_domain) { | |
f390d2c7 | 1353 | |
d62a17ae | 1354 | zlog_debug( |
3efd0893 | 1355 | "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit externalDomain = true", |
d62a17ae | 1356 | circuit->area->area_tag, level, typechar, |
1357 | circuit->interface->name); | |
f390d2c7 | 1358 | |
d62a17ae | 1359 | return ISIS_OK; |
1360 | } | |
eb5d44eb | 1361 | |
d62a17ae | 1362 | /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */ |
af8ac8f9 | 1363 | if (!(circuit->is_type & level)) { |
d62a17ae | 1364 | zlog_debug( |
3efd0893 | 1365 | "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit type %s does not match level %d", |
d62a17ae | 1366 | circuit->area->area_tag, level, typechar, |
1367 | circuit->interface->name, | |
1368 | circuit_t2string(circuit->is_type), level); | |
eb5d44eb | 1369 | |
d62a17ae | 1370 | return ISIS_OK; |
f390d2c7 | 1371 | } |
eb5d44eb | 1372 | |
d62a17ae | 1373 | /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */ |
17c9dcd5 CF |
1374 | if (!is_csnp && (circuit->circ_type == CIRCUIT_T_BROADCAST) |
1375 | && !circuit->u.bc.is_dr[level - 1]) { | |
d62a17ae | 1376 | zlog_debug( |
3efd0893 | 1377 | "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, skipping: we are not the DIS", |
d62a17ae | 1378 | circuit->area->area_tag, level, typechar, |
1379 | snpa_print(ssnpa), circuit->interface->name); | |
1380 | ||
1381 | return ISIS_OK; | |
1382 | } | |
eb5d44eb | 1383 | |
d62a17ae | 1384 | /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked |
1385 | */ | |
1386 | ||
1387 | /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use | |
1388 | * 3 | |
1389 | * - already checked */ | |
1390 | ||
1391 | /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same | |
1392 | * level */ | |
1393 | /* for broadcast circuits, snpa should be compared */ | |
1394 | /* FIXME : Do we need to check SNPA? */ | |
1395 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
17c9dcd5 CF |
1396 | if (!isis_adj_lookup(rem_sys_id, |
1397 | circuit->u.bc.adjdb[level - 1])) | |
d62a17ae | 1398 | return ISIS_OK; /* Silently discard */ |
1399 | } else { | |
8e6fb83b | 1400 | if (!fabricd && !circuit->u.p2p.neighbor) { |
d62a17ae | 1401 | zlog_warn("no p2p neighbor on circuit %s", |
1402 | circuit->interface->name); | |
1403 | return ISIS_OK; /* Silently discard */ | |
1404 | } | |
1405 | } | |
eb5d44eb | 1406 | |
17c9dcd5 CF |
1407 | struct isis_tlvs *tlvs; |
1408 | int retval = ISIS_WARNING; | |
1409 | const char *error_log; | |
eb5d44eb | 1410 | |
17c9dcd5 CF |
1411 | if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream), |
1412 | circuit->rcv_stream, &tlvs, &error_log)) { | |
1413 | zlog_warn("Something went wrong unpacking the SNP: %s", | |
1414 | error_log); | |
1415 | goto out; | |
f390d2c7 | 1416 | } |
eb5d44eb | 1417 | |
17c9dcd5 CF |
1418 | struct isis_passwd *passwd = (level == IS_LEVEL_1) |
1419 | ? &circuit->area->area_passwd | |
1420 | : &circuit->area->domain_passwd; | |
eab88f36 | 1421 | |
3380c990 EDP |
1422 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV)) { |
1423 | int auth_code = isis_tlvs_auth_is_valid( | |
1424 | tlvs, passwd, circuit->rcv_stream, false); | |
1425 | if (auth_code != ISIS_AUTH_OK) { | |
1426 | isis_event_auth_failure(circuit->area->area_tag, | |
1427 | "SNP authentication failure", | |
1428 | rem_sys_id); | |
1429 | #ifndef FABRICD | |
1430 | /* send northbound notification */ | |
1431 | stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start, | |
1432 | pdu_end - pdu_start); | |
c32496ee RW |
1433 | if (auth_code == ISIS_AUTH_FAILURE) { |
1434 | circuit->auth_failures++; | |
1ee746d9 | 1435 | if (circuit->is_type == IS_LEVEL_1) { |
1436 | circuit->area->auth_failures[0]++; | |
1437 | } else if (circuit->is_type == IS_LEVEL_2) { | |
1438 | circuit->area->auth_failures[1]++; | |
1439 | } else { | |
1440 | circuit->area->auth_failures[0]++; | |
1441 | circuit->area->auth_failures[1]++; | |
1442 | } | |
1443 | isis_notif_authentication_failure( | |
1444 | circuit, raw_pdu, sizeof(raw_pdu)); | |
c32496ee RW |
1445 | } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */ |
1446 | circuit->auth_type_failures++; | |
1ee746d9 | 1447 | if (circuit->is_type == IS_LEVEL_1) { |
1448 | circuit->area->auth_type_failures[0]++; | |
1449 | } else if (circuit->is_type == IS_LEVEL_2) { | |
1450 | circuit->area->auth_type_failures[1]++; | |
1451 | } else { | |
1452 | circuit->area->auth_type_failures[0]++; | |
1453 | circuit->area->auth_type_failures[1]++; | |
1454 | } | |
1455 | isis_notif_authentication_type_failure( | |
1456 | circuit, raw_pdu, sizeof(raw_pdu)); | |
c32496ee | 1457 | } |
3380c990 EDP |
1458 | #endif /* ifndef FABRICD */ |
1459 | goto out; | |
1460 | } | |
d62a17ae | 1461 | } |
eb5d44eb | 1462 | |
17c9dcd5 CF |
1463 | struct isis_lsp_entry *entry_head = |
1464 | (struct isis_lsp_entry *)tlvs->lsp_entries.head; | |
1465 | ||
d62a17ae | 1466 | /* debug isis snp-packets */ |
e740f9c1 | 1467 | if (IS_DEBUG_SNP_PACKETS) { |
d62a17ae | 1468 | zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s", |
1469 | circuit->area->area_tag, level, typechar, | |
1470 | snpa_print(ssnpa), circuit->interface->name); | |
17c9dcd5 CF |
1471 | for (struct isis_lsp_entry *entry = entry_head; entry; |
1472 | entry = entry->next) { | |
1473 | zlog_debug( | |
6cde4b45 | 1474 | "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus", |
17c9dcd5 CF |
1475 | circuit->area->area_tag, typechar, |
1476 | rawlspid_print(entry->id), entry->seqno, | |
1477 | entry->checksum, entry->rem_lifetime); | |
f390d2c7 | 1478 | } |
f390d2c7 | 1479 | } |
3f045a08 | 1480 | |
df0ba689 CF |
1481 | bool resync_needed = false; |
1482 | ||
d62a17ae | 1483 | /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */ |
17c9dcd5 CF |
1484 | for (struct isis_lsp_entry *entry = entry_head; entry; |
1485 | entry = entry->next) { | |
1486 | struct isis_lsp *lsp = | |
4bef0ec4 | 1487 | lsp_search(&circuit->area->lspdb[level - 1], entry->id); |
99e5d4af | 1488 | bool own_lsp = !memcmp(entry->id, circuit->isis->sysid, |
eab88f36 | 1489 | ISIS_SYS_ID_LEN); |
17c9dcd5 CF |
1490 | if (lsp) { |
1491 | /* 7.3.15.2 b) 1) is this LSP newer */ | |
1492 | int cmp = lsp_compare(circuit->area->area_tag, lsp, | |
1493 | entry->seqno, entry->checksum, | |
1494 | entry->rem_lifetime); | |
1495 | /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */ | |
1496 | if (cmp == LSP_EQUAL) { | |
1497 | /* if (circuit->circ_type != | |
1498 | * CIRCUIT_T_BROADCAST) */ | |
9b39405f | 1499 | isis_tx_queue_del(circuit->tx_queue, lsp); |
17c9dcd5 CF |
1500 | } |
1501 | /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM | |
1502 | */ | |
1503 | else if (cmp == LSP_OLDER) { | |
1504 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); | |
9b39405f CF |
1505 | isis_tx_queue_add(circuit->tx_queue, lsp, |
1506 | TX_LSP_NORMAL); | |
17c9dcd5 CF |
1507 | } |
1508 | /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM | |
1509 | on p2p */ | |
1510 | else { | |
1511 | if (own_lsp) { | |
af8ac8f9 | 1512 | lsp_inc_seqno(lsp, entry->seqno); |
9b39405f CF |
1513 | isis_tx_queue_add(circuit->tx_queue, lsp, |
1514 | TX_LSP_NORMAL); | |
17c9dcd5 CF |
1515 | } else { |
1516 | ISIS_SET_FLAG(lsp->SSNflags, circuit); | |
d62a17ae | 1517 | /* if (circuit->circ_type != |
1518 | * CIRCUIT_T_BROADCAST) */ | |
9b39405f | 1519 | isis_tx_queue_del(circuit->tx_queue, lsp); |
df0ba689 | 1520 | resync_needed = true; |
d62a17ae | 1521 | } |
17c9dcd5 CF |
1522 | } |
1523 | } else { | |
1524 | /* 7.3.15.2 b) 5) if it was not found, and all of those | |
1525 | * are not 0, | |
1526 | * insert it and set SSN on it */ | |
1527 | if (entry->rem_lifetime && entry->checksum | |
eab88f36 | 1528 | && entry->seqno |
99e5d4af | 1529 | && memcmp(entry->id, circuit->isis->sysid, |
eab88f36 | 1530 | ISIS_SYS_ID_LEN)) { |
8f5dbe18 CF |
1531 | struct isis_lsp *lsp0 = NULL; |
1532 | ||
1533 | if (LSP_FRAGMENT(entry->id)) { | |
1534 | uint8_t lspid[ISIS_SYS_ID_LEN + 2]; | |
1535 | ||
1536 | memcpy(lspid, entry->id, | |
1537 | ISIS_SYS_ID_LEN + 1); | |
1538 | LSP_FRAGMENT(lspid) = 0; | |
1539 | lsp0 = lsp_search( | |
4bef0ec4 DL |
1540 | &circuit->area->lspdb[level - 1], |
1541 | lspid); | |
8f5dbe18 | 1542 | if (!lsp0) { |
98c5bc15 | 1543 | zlog_debug("Got lsp frag in snp, while zero not in database"); |
8f5dbe18 CF |
1544 | continue; |
1545 | } | |
1546 | } | |
f7813c7c | 1547 | lsp = lsp_new(circuit->area, entry->id, |
17c9dcd5 | 1548 | entry->rem_lifetime, 0, 0, |
8f5dbe18 | 1549 | entry->checksum, lsp0, level); |
4bef0ec4 DL |
1550 | lsp_insert(&circuit->area->lspdb[level - 1], |
1551 | lsp); | |
9b39405f CF |
1552 | |
1553 | lsp_set_all_srmflags(lsp, false); | |
17c9dcd5 | 1554 | ISIS_SET_FLAG(lsp->SSNflags, circuit); |
df0ba689 | 1555 | resync_needed = true; |
d62a17ae | 1556 | } |
1557 | } | |
1558 | } | |
eb5d44eb | 1559 | |
d62a17ae | 1560 | /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported |
1561 | */ | |
17c9dcd5 | 1562 | if (is_csnp) { |
d62a17ae | 1563 | /* |
1564 | * Build a list from our own LSP db bounded with | |
1565 | * start_lsp_id and stop_lsp_id | |
1566 | */ | |
17c9dcd5 | 1567 | struct list *lsp_list = list_new(); |
4bef0ec4 DL |
1568 | lsp_build_list_nonzero_ht(&circuit->area->lspdb[level - 1], |
1569 | start_lsp_id, stop_lsp_id, lsp_list); | |
d62a17ae | 1570 | |
1571 | /* Fixme: Find a better solution */ | |
17c9dcd5 CF |
1572 | struct listnode *node, *nnode; |
1573 | struct isis_lsp *lsp; | |
1574 | for (struct isis_lsp_entry *entry = entry_head; entry; | |
1575 | entry = entry->next) { | |
1576 | for (ALL_LIST_ELEMENTS(lsp_list, node, nnode, lsp)) { | |
af8ac8f9 | 1577 | if (lsp_id_cmp(lsp->hdr.lsp_id, entry->id) |
17c9dcd5 CF |
1578 | == 0) { |
1579 | list_delete_node(lsp_list, node); | |
1580 | break; | |
d62a17ae | 1581 | } |
1582 | } | |
1583 | } | |
17c9dcd5 | 1584 | |
d62a17ae | 1585 | /* on remaining LSPs we set SRM (neighbor knew not of) */ |
9b39405f CF |
1586 | for (ALL_LIST_ELEMENTS_RO(lsp_list, node, lsp)) { |
1587 | isis_tx_queue_add(circuit->tx_queue, lsp, TX_LSP_NORMAL); | |
df0ba689 | 1588 | resync_needed = true; |
9b39405f CF |
1589 | } |
1590 | ||
d62a17ae | 1591 | /* lets free it */ |
6a154c88 | 1592 | list_delete(&lsp_list); |
d62a17ae | 1593 | } |
1594 | ||
df0ba689 | 1595 | if (fabricd_initial_sync_is_complete(circuit->area) && resync_needed) |
9165c5f5 | 1596 | zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!"); |
df0ba689 | 1597 | |
17c9dcd5 CF |
1598 | retval = ISIS_OK; |
1599 | out: | |
1600 | isis_free_tlvs(tlvs); | |
d62a17ae | 1601 | return retval; |
eb5d44eb | 1602 | } |
1603 | ||
88f9d911 CF |
1604 | static int pdu_size(uint8_t pdu_type, uint8_t *size) |
1605 | { | |
1606 | switch (pdu_type) { | |
1607 | case L1_LAN_HELLO: | |
1608 | case L2_LAN_HELLO: | |
1609 | *size = ISIS_LANHELLO_HDRLEN; | |
1610 | break; | |
1611 | case P2P_HELLO: | |
1612 | *size = ISIS_P2PHELLO_HDRLEN; | |
1613 | break; | |
1614 | case L1_LINK_STATE: | |
1615 | case L2_LINK_STATE: | |
1cbd5b37 | 1616 | case FS_LINK_STATE: |
88f9d911 CF |
1617 | *size = ISIS_LSP_HDR_LEN; |
1618 | break; | |
1619 | case L1_COMPLETE_SEQ_NUM: | |
1620 | case L2_COMPLETE_SEQ_NUM: | |
1621 | *size = ISIS_CSNP_HDRLEN; | |
1622 | break; | |
1623 | case L1_PARTIAL_SEQ_NUM: | |
1624 | case L2_PARTIAL_SEQ_NUM: | |
1625 | *size = ISIS_PSNP_HDRLEN; | |
1626 | break; | |
1627 | default: | |
1628 | return 1; | |
1629 | } | |
1630 | *size += ISIS_FIXED_HDR_LEN; | |
1631 | return 0; | |
1632 | } | |
1633 | ||
eb5d44eb | 1634 | /* |
1635 | * PDU Dispatcher | |
1636 | */ | |
1637 | ||
d7c0a89a | 1638 | int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa) |
eb5d44eb | 1639 | { |
d62a17ae | 1640 | int retval = ISIS_OK; |
2ab5a2d1 EDP |
1641 | size_t pdu_start = stream_get_getp(circuit->rcv_stream); |
1642 | size_t pdu_end = stream_get_endp(circuit->rcv_stream); | |
1643 | char raw_pdu[pdu_end - pdu_start]; | |
1644 | ||
1645 | stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start, | |
1646 | pdu_end - pdu_start); | |
eb5d44eb | 1647 | |
88f9d911 CF |
1648 | /* Verify that at least the 8 bytes fixed header have been received */ |
1649 | if (stream_get_endp(circuit->rcv_stream) < ISIS_FIXED_HDR_LEN) { | |
1a7ecb96 | 1650 | flog_err(EC_ISIS_PACKET, "PDU is too short to be IS-IS."); |
88f9d911 CF |
1651 | return ISIS_ERROR; |
1652 | } | |
eb5d44eb | 1653 | |
88f9d911 CF |
1654 | uint8_t idrp = stream_getc(circuit->rcv_stream); |
1655 | uint8_t length = stream_getc(circuit->rcv_stream); | |
1656 | uint8_t version1 = stream_getc(circuit->rcv_stream); | |
1657 | uint8_t id_len = stream_getc(circuit->rcv_stream); | |
1658 | uint8_t pdu_type = stream_getc(circuit->rcv_stream) | |
1659 | & 0x1f; /* bits 6-8 are reserved */ | |
1660 | uint8_t version2 = stream_getc(circuit->rcv_stream); | |
2ab5a2d1 | 1661 | |
88f9d911 CF |
1662 | stream_forward_getp(circuit->rcv_stream, 1); /* reserved */ |
1663 | uint8_t max_area_addrs = stream_getc(circuit->rcv_stream); | |
1664 | ||
39bb53d6 CF |
1665 | pdu_counter_count(circuit->area->pdu_rx_counters, pdu_type); |
1666 | ||
88f9d911 | 1667 | if (idrp == ISO9542_ESIS) { |
450971aa | 1668 | flog_err(EC_LIB_DEVELOPMENT, |
6cde4b45 | 1669 | "No support for ES-IS packet IDRP=%hhx", idrp); |
d62a17ae | 1670 | return ISIS_ERROR; |
1671 | } | |
eb5d44eb | 1672 | |
88f9d911 | 1673 | if (idrp != ISO10589_ISIS) { |
6cde4b45 | 1674 | flog_err(EC_ISIS_PACKET, "Not an IS-IS packet IDRP=%hhx", |
1c50c1c0 | 1675 | idrp); |
d62a17ae | 1676 | return ISIS_ERROR; |
1677 | } | |
3f045a08 | 1678 | |
88f9d911 | 1679 | if (version1 != 1) { |
6cde4b45 | 1680 | zlog_warn("Unsupported ISIS version %hhu", version1); |
0532bd84 EDP |
1681 | #ifndef FABRICD |
1682 | /* send northbound notification */ | |
1ee746d9 | 1683 | isis_notif_version_skew(circuit, version1, raw_pdu, |
1684 | sizeof(raw_pdu)); | |
0532bd84 | 1685 | #endif /* ifndef FABRICD */ |
88f9d911 CF |
1686 | return ISIS_WARNING; |
1687 | } | |
eb5d44eb | 1688 | |
88f9d911 | 1689 | if (id_len != 0 && id_len != ISIS_SYS_ID_LEN) { |
af4c2728 | 1690 | flog_err( |
1a7ecb96 | 1691 | EC_ISIS_PACKET, |
6cde4b45 | 1692 | "IDFieldLengthMismatch: ID Length field in a received PDU %hhu, while the parameter for this IS is %u", |
88f9d911 | 1693 | id_len, ISIS_SYS_ID_LEN); |
c32496ee | 1694 | circuit->id_len_mismatches++; |
1ee746d9 | 1695 | if (circuit->is_type == IS_LEVEL_1) { |
1696 | circuit->area->id_len_mismatches[0]++; | |
1697 | } else if (circuit->is_type == IS_LEVEL_2) { | |
1698 | circuit->area->id_len_mismatches[1]++; | |
1699 | } else { | |
1700 | circuit->area->id_len_mismatches[0]++; | |
1701 | circuit->area->id_len_mismatches[1]++; | |
1702 | } | |
1703 | ||
e98d7633 EDP |
1704 | #ifndef FABRICD |
1705 | /* send northbound notification */ | |
1ee746d9 | 1706 | isis_notif_id_len_mismatch(circuit, id_len, raw_pdu, |
1707 | sizeof(raw_pdu)); | |
e98d7633 | 1708 | #endif /* ifndef FABRICD */ |
d62a17ae | 1709 | return ISIS_ERROR; |
1710 | } | |
eb5d44eb | 1711 | |
88f9d911 CF |
1712 | uint8_t expected_length; |
1713 | if (pdu_size(pdu_type, &expected_length)) { | |
6cde4b45 | 1714 | zlog_warn("Unsupported ISIS PDU %hhu", pdu_type); |
d62a17ae | 1715 | return ISIS_WARNING; |
1716 | } | |
88f9d911 CF |
1717 | |
1718 | if (length != expected_length) { | |
1a7ecb96 | 1719 | flog_err(EC_ISIS_PACKET, |
6cde4b45 | 1720 | "Expected fixed header length = %hhu but got %hhu", |
1c50c1c0 | 1721 | expected_length, length); |
88f9d911 CF |
1722 | return ISIS_ERROR; |
1723 | } | |
1724 | ||
1725 | if (stream_get_endp(circuit->rcv_stream) < length) { | |
af4c2728 | 1726 | flog_err( |
1a7ecb96 | 1727 | EC_ISIS_PACKET, |
88f9d911 | 1728 | "PDU is too short to contain fixed header of given PDU type."); |
d62a17ae | 1729 | return ISIS_ERROR; |
1730 | } | |
eb5d44eb | 1731 | |
88f9d911 | 1732 | if (version2 != 1) { |
6cde4b45 | 1733 | zlog_warn("Unsupported ISIS PDU version %hhu", version2); |
0532bd84 EDP |
1734 | #ifndef FABRICD |
1735 | /* send northbound notification */ | |
1ee746d9 | 1736 | isis_notif_version_skew(circuit, version2, raw_pdu, |
1737 | sizeof(raw_pdu)); | |
0532bd84 | 1738 | #endif /* ifndef FABRICD */ |
d62a17ae | 1739 | return ISIS_WARNING; |
1740 | } | |
3f045a08 | 1741 | |
d62a17ae | 1742 | if (circuit->is_passive) { |
1743 | zlog_warn("Received ISIS PDU on passive circuit %s", | |
1744 | circuit->interface->name); | |
1745 | return ISIS_WARNING; | |
1746 | } | |
3f045a08 | 1747 | |
d62a17ae | 1748 | /* either 3 or 0 */ |
eab88f36 K |
1749 | if (pdu_type != FS_LINK_STATE /* FS PDU doesn't contain max area addr |
1750 | field */ | |
1cbd5b37 | 1751 | && max_area_addrs != 0 |
99e5d4af | 1752 | && max_area_addrs != circuit->isis->max_area_addrs) { |
af4c2728 | 1753 | flog_err( |
1a7ecb96 | 1754 | EC_ISIS_PACKET, |
6cde4b45 | 1755 | "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %hhu while the parameter for this IS is %u", |
99e5d4af | 1756 | max_area_addrs, circuit->isis->max_area_addrs); |
c32496ee | 1757 | circuit->max_area_addr_mismatches++; |
2ab5a2d1 EDP |
1758 | #ifndef FABRICD |
1759 | /* send northbound notification */ | |
1760 | isis_notif_max_area_addr_mismatch(circuit, max_area_addrs, | |
1ee746d9 | 1761 | raw_pdu, sizeof(raw_pdu)); |
2ab5a2d1 | 1762 | #endif /* ifndef FABRICD */ |
d62a17ae | 1763 | return ISIS_ERROR; |
1764 | } | |
eb5d44eb | 1765 | |
88f9d911 | 1766 | switch (pdu_type) { |
d62a17ae | 1767 | case L1_LAN_HELLO: |
d62a17ae | 1768 | case L2_LAN_HELLO: |
d62a17ae | 1769 | case P2P_HELLO: |
a2d41bb0 CF |
1770 | if (fabricd && pdu_type != P2P_HELLO) |
1771 | return ISIS_ERROR; | |
0c1bd758 | 1772 | retval = process_hello(pdu_type, circuit, ssnpa); |
d62a17ae | 1773 | break; |
1774 | case L1_LINK_STATE: | |
d62a17ae | 1775 | case L2_LINK_STATE: |
1cbd5b37 | 1776 | case FS_LINK_STATE: |
a2d41bb0 CF |
1777 | if (fabricd |
1778 | && pdu_type != L2_LINK_STATE | |
1779 | && pdu_type != FS_LINK_STATE) | |
1780 | return ISIS_ERROR; | |
9b39405f | 1781 | retval = process_lsp(pdu_type, circuit, ssnpa, max_area_addrs); |
d62a17ae | 1782 | break; |
1783 | case L1_COMPLETE_SEQ_NUM: | |
d62a17ae | 1784 | case L2_COMPLETE_SEQ_NUM: |
d62a17ae | 1785 | case L1_PARTIAL_SEQ_NUM: |
d62a17ae | 1786 | case L2_PARTIAL_SEQ_NUM: |
17c9dcd5 | 1787 | retval = process_snp(pdu_type, circuit, ssnpa); |
d62a17ae | 1788 | break; |
1789 | default: | |
1790 | return ISIS_ERROR; | |
1791 | } | |
eb5d44eb | 1792 | |
d62a17ae | 1793 | return retval; |
eb5d44eb | 1794 | } |
1795 | ||
d62a17ae | 1796 | int isis_receive(struct thread *thread) |
eb5d44eb | 1797 | { |
d62a17ae | 1798 | struct isis_circuit *circuit; |
d7c0a89a | 1799 | uint8_t ssnpa[ETH_ALEN]; |
d62a17ae | 1800 | int retval; |
eb5d44eb | 1801 | |
d62a17ae | 1802 | /* |
1803 | * Get the circuit | |
1804 | */ | |
1805 | circuit = THREAD_ARG(thread); | |
1806 | assert(circuit); | |
eb5d44eb | 1807 | |
d62a17ae | 1808 | circuit->t_read = NULL; |
eb5d44eb | 1809 | |
d62a17ae | 1810 | isis_circuit_stream(circuit, &circuit->rcv_stream); |
eb5d44eb | 1811 | |
d62a17ae | 1812 | retval = circuit->rx(circuit, ssnpa); |
eb5d44eb | 1813 | |
b9347997 | 1814 | #if ISIS_METHOD != ISIS_METHOD_BPF |
d62a17ae | 1815 | if (retval == ISIS_OK) |
1816 | retval = isis_handle_pdu(circuit, ssnpa); | |
b9347997 | 1817 | #endif //ISIS_METHOD != ISIS_METHOD_BPF |
eb5d44eb | 1818 | |
d62a17ae | 1819 | /* |
1820 | * prepare for next packet. | |
1821 | */ | |
1822 | if (!circuit->is_passive) | |
1823 | isis_circuit_prepare(circuit); | |
eb5d44eb | 1824 | |
d62a17ae | 1825 | return retval; |
eb5d44eb | 1826 | } |
1827 | ||
eb5d44eb | 1828 | /* |
d62a17ae | 1829 | * SEND SIDE |
eb5d44eb | 1830 | */ |
88f9d911 | 1831 | void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream) |
eb5d44eb | 1832 | { |
88f9d911 CF |
1833 | uint8_t length; |
1834 | ||
1835 | if (pdu_size(pdu_type, &length)) | |
1836 | assert(!"Unknown PDU Type"); | |
1837 | ||
1838 | stream_putc(stream, ISO10589_ISIS); /* IDRP */ | |
1839 | stream_putc(stream, length); /* Length of fixed header */ | |
1840 | stream_putc(stream, 1); /* Version/Protocol ID Extension 1 */ | |
1841 | stream_putc(stream, 0); /* ID Length, 0 => 6 */ | |
1842 | stream_putc(stream, pdu_type); | |
1843 | stream_putc(stream, 1); /* Subversion */ | |
1844 | stream_putc(stream, 0); /* Reserved */ | |
1845 | stream_putc(stream, 0); /* Max Area Addresses 0 => 3 */ | |
eb5d44eb | 1846 | } |
1847 | ||
39bb53d6 | 1848 | static uint8_t hello_pdu_type(struct isis_circuit *circuit, int level) |
eb5d44eb | 1849 | { |
d62a17ae | 1850 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
39bb53d6 | 1851 | return (level == IS_LEVEL_1) ? L1_LAN_HELLO : L2_LAN_HELLO; |
d62a17ae | 1852 | else |
39bb53d6 CF |
1853 | return P2P_HELLO; |
1854 | } | |
1855 | ||
1856 | static void put_hello_hdr(struct isis_circuit *circuit, int level, | |
1857 | size_t *len_pointer) | |
1858 | { | |
1859 | uint8_t pdu_type = hello_pdu_type(circuit, level); | |
88f9d911 | 1860 | |
0c1bd758 | 1861 | isis_circuit_stream(circuit, &circuit->snd_stream); |
88f9d911 | 1862 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
d62a17ae | 1863 | |
0c1bd758 | 1864 | stream_putc(circuit->snd_stream, circuit->is_type); |
99e5d4af | 1865 | stream_put(circuit->snd_stream, circuit->isis->sysid, ISIS_SYS_ID_LEN); |
eb5d44eb | 1866 | |
0c1bd758 CF |
1867 | uint32_t holdtime = circuit->hello_multiplier[level - 1] |
1868 | * circuit->hello_interval[level - 1]; | |
d62a17ae | 1869 | |
0c1bd758 CF |
1870 | if (holdtime > 0xffff) |
1871 | holdtime = 0xffff; | |
d62a17ae | 1872 | |
0c1bd758 CF |
1873 | stream_putw(circuit->snd_stream, holdtime); |
1874 | *len_pointer = stream_get_endp(circuit->snd_stream); | |
1875 | stream_putw(circuit->snd_stream, 0); /* length is filled in later */ | |
d62a17ae | 1876 | |
0c1bd758 | 1877 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
d7c0a89a QY |
1878 | uint8_t *desig_is = (level == IS_LEVEL_1) |
1879 | ? circuit->u.bc.l1_desig_is | |
1880 | : circuit->u.bc.l2_desig_is; | |
0c1bd758 CF |
1881 | stream_putc(circuit->snd_stream, circuit->priority[level - 1]); |
1882 | stream_put(circuit->snd_stream, desig_is, ISIS_SYS_ID_LEN + 1); | |
1883 | } else { | |
1884 | stream_putc(circuit->snd_stream, circuit->circuit_id); | |
d62a17ae | 1885 | } |
0c1bd758 | 1886 | } |
eb5d44eb | 1887 | |
0c1bd758 CF |
1888 | int send_hello(struct isis_circuit *circuit, int level) |
1889 | { | |
1890 | size_t len_pointer; | |
1891 | int retval; | |
1892 | ||
1893 | if (circuit->is_passive) | |
1894 | return ISIS_OK; | |
1895 | ||
1896 | if (circuit->interface->mtu == 0) { | |
1897 | zlog_warn("circuit has zero MTU"); | |
d62a17ae | 1898 | return ISIS_WARNING; |
0c1bd758 CF |
1899 | } |
1900 | ||
1901 | put_hello_hdr(circuit, level, &len_pointer); | |
1902 | ||
1903 | struct isis_tlvs *tlvs = isis_alloc_tlvs(); | |
1904 | ||
1905 | isis_tlvs_add_auth(tlvs, &circuit->passwd); | |
1906 | ||
a3acf37d DS |
1907 | if (!listcount(circuit->area->area_addrs)) { |
1908 | isis_free_tlvs(tlvs); | |
d62a17ae | 1909 | return ISIS_WARNING; |
a3acf37d DS |
1910 | } |
1911 | ||
0c1bd758 | 1912 | isis_tlvs_add_area_addresses(tlvs, circuit->area->area_addrs); |
d62a17ae | 1913 | |
42fe2621 | 1914 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
0c1bd758 CF |
1915 | isis_tlvs_add_lan_neighbors( |
1916 | tlvs, circuit->u.bc.lan_neighs[level - 1]); | |
58e5d748 CF |
1917 | } else if (circuit->circ_type == CIRCUIT_T_P2P |
1918 | && !circuit->disable_threeway_adj) { | |
42fe2621 CF |
1919 | uint32_t ext_circuit_id = circuit->idx; |
1920 | if (circuit->u.p2p.neighbor) { | |
8e6fb83b CF |
1921 | uint8_t threeway_state; |
1922 | ||
1923 | if (fabricd_initial_sync_is_in_progress(circuit->area) | |
1924 | && fabricd_initial_sync_circuit(circuit->area) != circuit) | |
1925 | threeway_state = ISIS_THREEWAY_DOWN; | |
1926 | else | |
1927 | threeway_state = circuit->u.p2p.neighbor->threeway_state; | |
42fe2621 | 1928 | isis_tlvs_add_threeway_adj(tlvs, |
8e6fb83b | 1929 | threeway_state, |
42fe2621 CF |
1930 | ext_circuit_id, |
1931 | circuit->u.p2p.neighbor->sysid, | |
1932 | circuit->u.p2p.neighbor->ext_circuit_id); | |
1933 | } else { | |
1934 | isis_tlvs_add_threeway_adj(tlvs, | |
1935 | ISIS_THREEWAY_DOWN, | |
1936 | ext_circuit_id, | |
1937 | NULL, 0); | |
1938 | } | |
1939 | } | |
0c1bd758 CF |
1940 | |
1941 | isis_tlvs_set_protocols_supported(tlvs, &circuit->nlpids); | |
d62a17ae | 1942 | |
1943 | /* | |
1944 | * MT Supported TLV | |
1945 | * | |
1946 | * TLV gets included if no topology is enabled on the interface, | |
1947 | * if one topology other than #0 is enabled, or if multiple topologies | |
1948 | * are enabled. | |
1949 | */ | |
1950 | struct isis_circuit_mt_setting **mt_settings; | |
1951 | unsigned int mt_count; | |
1952 | ||
1953 | mt_settings = circuit_mt_settings(circuit, &mt_count); | |
0c1bd758 CF |
1954 | if (mt_count == 0 && area_is_mt(circuit->area)) { |
1955 | tlvs->mt_router_info_empty = true; | |
1956 | } else if ((mt_count == 1 | |
1957 | && mt_settings[0]->mtid != ISIS_MT_IPV4_UNICAST) | |
1958 | || (mt_count > 1)) { | |
1959 | for (unsigned int i = 0; i < mt_count; i++) | |
1960 | isis_tlvs_add_mt_router_info(tlvs, mt_settings[i]->mtid, | |
1961 | false, false); | |
d62a17ae | 1962 | } |
eb5d44eb | 1963 | |
41415888 CF |
1964 | if (circuit->ip_router) { |
1965 | struct list *circuit_ip_addrs = fabricd_ip_addrs(circuit); | |
1966 | ||
1967 | if (circuit_ip_addrs) | |
1968 | isis_tlvs_add_ipv4_addresses(tlvs, circuit_ip_addrs); | |
1969 | } | |
d62a17ae | 1970 | |
0c1bd758 CF |
1971 | if (circuit->ipv6_router && circuit->ipv6_link) |
1972 | isis_tlvs_add_ipv6_addresses(tlvs, circuit->ipv6_link); | |
d62a17ae | 1973 | |
0c1bd758 | 1974 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, |
af8ac8f9 | 1975 | circuit->pad_hellos, false)) { |
0c1bd758 CF |
1976 | isis_free_tlvs(tlvs); |
1977 | return ISIS_WARNING; /* XXX: Maybe Log TLV structure? */ | |
f390d2c7 | 1978 | } |
d62a17ae | 1979 | |
e740f9c1 | 1980 | if (IS_DEBUG_ADJ_PACKETS) { |
d62a17ae | 1981 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
1982 | zlog_debug( | |
1983 | "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd", | |
1984 | circuit->area->area_tag, level, | |
0c1bd758 CF |
1985 | circuit->interface->name, |
1986 | stream_get_endp(circuit->snd_stream)); | |
d62a17ae | 1987 | } else { |
1988 | zlog_debug( | |
1989 | "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd", | |
1990 | circuit->area->area_tag, | |
0c1bd758 CF |
1991 | circuit->interface->name, |
1992 | stream_get_endp(circuit->snd_stream)); | |
d62a17ae | 1993 | } |
e740f9c1 | 1994 | if (IS_DEBUG_PACKET_DUMP) |
d62a17ae | 1995 | zlog_dump_data(STREAM_DATA(circuit->snd_stream), |
1996 | stream_get_endp(circuit->snd_stream)); | |
f390d2c7 | 1997 | } |
eb5d44eb | 1998 | |
0c1bd758 CF |
1999 | isis_free_tlvs(tlvs); |
2000 | ||
89cdc4df RM |
2001 | pdu_counter_count(circuit->area->pdu_tx_counters, |
2002 | hello_pdu_type(circuit, level)); | |
d62a17ae | 2003 | retval = circuit->tx(circuit, level); |
2004 | if (retval != ISIS_OK) | |
1a7ecb96 | 2005 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
2006 | "ISIS-Adj (%s): Send L%d IIH on %s failed", |
2007 | circuit->area->area_tag, level, | |
2008 | circuit->interface->name); | |
eb5d44eb | 2009 | |
d62a17ae | 2010 | return retval; |
eb5d44eb | 2011 | } |
2012 | ||
a0a707ee | 2013 | static int send_hello_cb(struct thread *thread) |
eb5d44eb | 2014 | { |
7c4f7aab | 2015 | struct isis_circuit_arg *arg = THREAD_ARG(thread); |
7c4f7aab | 2016 | assert(arg); |
89cdc4df | 2017 | |
7c4f7aab CF |
2018 | struct isis_circuit *circuit = arg->circuit; |
2019 | int level = arg->level; | |
d62a17ae | 2020 | |
d62a17ae | 2021 | assert(circuit); |
ddfdbd32 | 2022 | |
7c4f7aab CF |
2023 | if (circuit->circ_type == CIRCUIT_T_P2P) { |
2024 | circuit->u.p2p.t_send_p2p_hello = NULL; | |
7c4f7aab | 2025 | send_hello(circuit, 1); |
a0a707ee CF |
2026 | send_hello_sched(circuit, ISIS_LEVEL1, |
2027 | 1000 * circuit->hello_interval[1]); | |
7c4f7aab | 2028 | return ISIS_OK; |
d62a17ae | 2029 | } |
ddfdbd32 | 2030 | |
7c4f7aab CF |
2031 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) { |
2032 | zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d", | |
2033 | circuit->area->area_tag, circuit->circ_type); | |
2034 | return ISIS_WARNING; | |
2035 | } | |
eb5d44eb | 2036 | |
7c4f7aab CF |
2037 | circuit->u.bc.t_send_lan_hello[level - 1] = NULL; |
2038 | if (!(circuit->is_type & level)) { | |
2039 | zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit", | |
2040 | circuit->area->area_tag, level, 3 - level); | |
2041 | return ISIS_WARNING; | |
2042 | } | |
eb5d44eb | 2043 | |
7c4f7aab CF |
2044 | if (circuit->u.bc.run_dr_elect[level - 1]) |
2045 | isis_dr_elect(circuit, level); | |
eb5d44eb | 2046 | |
7c4f7aab | 2047 | int rv = send_hello(circuit, level); |
eb5d44eb | 2048 | |
d62a17ae | 2049 | /* set next timer thread */ |
a0a707ee | 2050 | send_hello_sched(circuit, level, 1000 * circuit->hello_interval[level - 1]); |
7c4f7aab | 2051 | return rv; |
eb5d44eb | 2052 | } |
2053 | ||
a0a707ee CF |
2054 | static void _send_hello_sched(struct isis_circuit *circuit, |
2055 | struct thread **threadp, | |
2056 | int level, long delay) | |
2057 | { | |
2058 | if (*threadp) { | |
2059 | if (thread_timer_remain_msec(*threadp) < (unsigned long)delay) | |
2060 | return; | |
2061 | ||
b3d6bc6e | 2062 | thread_cancel(threadp); |
a0a707ee CF |
2063 | } |
2064 | ||
2065 | thread_add_timer_msec(master, send_hello_cb, | |
2066 | &circuit->level_arg[level - 1], | |
2067 | isis_jitter(delay, IIH_JITTER), | |
2068 | threadp); | |
2069 | } | |
2070 | ||
2071 | void send_hello_sched(struct isis_circuit *circuit, int level, long delay) | |
2072 | { | |
2073 | if (circuit->circ_type == CIRCUIT_T_P2P) { | |
2074 | _send_hello_sched(circuit, &circuit->u.p2p.t_send_p2p_hello, | |
2075 | ISIS_LEVEL1, delay); | |
2076 | return; | |
2077 | } | |
2078 | ||
2079 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) { | |
2080 | zlog_warn("%s: encountered unknown circuit type %d on %s", | |
2081 | __func__, circuit->circ_type, | |
2082 | circuit->interface->name); | |
2083 | return; | |
2084 | } | |
2085 | ||
2086 | for (int loop_level = ISIS_LEVEL1; loop_level <= ISIS_LEVEL2; loop_level++) { | |
2087 | if (!(loop_level & level)) | |
2088 | continue; | |
2089 | ||
2090 | _send_hello_sched( | |
2091 | circuit, | |
2092 | &circuit->u.bc.t_send_lan_hello[loop_level - 1], | |
2093 | loop_level, | |
2094 | delay | |
2095 | ); | |
2096 | } | |
2097 | } | |
2098 | ||
2099 | ||
3f045a08 JB |
2100 | /* |
2101 | * Count the maximum number of lsps that can be accomodated by a given size. | |
2102 | */ | |
af8ac8f9 | 2103 | #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN) |
d62a17ae | 2104 | static uint16_t get_max_lsp_count(uint16_t size) |
3f045a08 | 2105 | { |
d62a17ae | 2106 | uint16_t tlv_count; |
2107 | uint16_t lsp_count; | |
2108 | uint16_t remaining_size; | |
3f045a08 | 2109 | |
d62a17ae | 2110 | /* First count the full size TLVs */ |
2111 | tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE; | |
2112 | lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN); | |
3f045a08 | 2113 | |
d62a17ae | 2114 | /* The last TLV, if any */ |
2115 | remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE; | |
2116 | if (remaining_size - 2 >= LSP_ENTRIES_LEN) | |
2117 | lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN; | |
3f045a08 | 2118 | |
d62a17ae | 2119 | return lsp_count; |
3f045a08 JB |
2120 | } |
2121 | ||
17c9dcd5 | 2122 | int send_csnp(struct isis_circuit *circuit, int level) |
3f045a08 | 2123 | { |
4bef0ec4 | 2124 | if (lspdb_count(&circuit->area->lspdb[level - 1]) == 0) |
17c9dcd5 | 2125 | return ISIS_OK; |
d62a17ae | 2126 | |
39bb53d6 CF |
2127 | uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_COMPLETE_SEQ_NUM |
2128 | : L2_COMPLETE_SEQ_NUM; | |
2129 | ||
17c9dcd5 | 2130 | isis_circuit_stream(circuit, &circuit->snd_stream); |
39bb53d6 | 2131 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
3f045a08 | 2132 | |
17c9dcd5 | 2133 | size_t len_pointer = stream_get_endp(circuit->snd_stream); |
eab88f36 | 2134 | |
17c9dcd5 | 2135 | stream_putw(circuit->snd_stream, 0); |
99e5d4af | 2136 | stream_put(circuit->snd_stream, circuit->isis->sysid, ISIS_SYS_ID_LEN); |
17c9dcd5 CF |
2137 | /* with zero circuit id - ref 9.10, 9.11 */ |
2138 | stream_putc(circuit->snd_stream, 0); | |
3f045a08 | 2139 | |
17c9dcd5 CF |
2140 | size_t start_pointer = stream_get_endp(circuit->snd_stream); |
2141 | stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2); | |
2142 | size_t end_pointer = stream_get_endp(circuit->snd_stream); | |
2143 | stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2); | |
d62a17ae | 2144 | |
17c9dcd5 CF |
2145 | struct isis_passwd *passwd = (level == ISIS_LEVEL1) |
2146 | ? &circuit->area->area_passwd | |
2147 | : &circuit->area->domain_passwd; | |
d62a17ae | 2148 | |
17c9dcd5 | 2149 | struct isis_tlvs *tlvs = isis_alloc_tlvs(); |
3f045a08 | 2150 | |
17c9dcd5 CF |
2151 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
2152 | isis_tlvs_add_auth(tlvs, passwd); | |
eb5d44eb | 2153 | |
17c9dcd5 | 2154 | size_t tlv_start = stream_get_endp(circuit->snd_stream); |
af8ac8f9 CF |
2155 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false, |
2156 | false)) { | |
17c9dcd5 CF |
2157 | isis_free_tlvs(tlvs); |
2158 | return ISIS_WARNING; | |
2159 | } | |
2160 | isis_free_tlvs(tlvs); | |
d62a17ae | 2161 | |
17c9dcd5 CF |
2162 | uint16_t num_lsps = |
2163 | get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream)); | |
d62a17ae | 2164 | |
17c9dcd5 | 2165 | uint8_t start[ISIS_SYS_ID_LEN + 2]; |
d62a17ae | 2166 | memset(start, 0x00, ISIS_SYS_ID_LEN + 2); |
17c9dcd5 | 2167 | uint8_t stop[ISIS_SYS_ID_LEN + 2]; |
d62a17ae | 2168 | memset(stop, 0xff, ISIS_SYS_ID_LEN + 2); |
2169 | ||
17c9dcd5 | 2170 | bool loop = true; |
d62a17ae | 2171 | while (loop) { |
17c9dcd5 CF |
2172 | tlvs = isis_alloc_tlvs(); |
2173 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
2174 | isis_tlvs_add_auth(tlvs, passwd); | |
2175 | ||
2176 | struct isis_lsp *last_lsp; | |
2177 | isis_tlvs_add_csnp_entries(tlvs, start, stop, num_lsps, | |
4bef0ec4 | 2178 | &circuit->area->lspdb[level - 1], |
17c9dcd5 | 2179 | &last_lsp); |
d62a17ae | 2180 | /* |
2181 | * Update the stop lsp_id before encoding this CSNP. | |
2182 | */ | |
17c9dcd5 | 2183 | if (tlvs->lsp_entries.count < num_lsps) { |
d62a17ae | 2184 | memset(stop, 0xff, ISIS_SYS_ID_LEN + 2); |
2185 | } else { | |
af8ac8f9 | 2186 | memcpy(stop, last_lsp->hdr.lsp_id, sizeof(stop)); |
d62a17ae | 2187 | } |
3f045a08 | 2188 | |
17c9dcd5 CF |
2189 | memcpy(STREAM_DATA(circuit->snd_stream) + start_pointer, start, |
2190 | ISIS_SYS_ID_LEN + 2); | |
2191 | memcpy(STREAM_DATA(circuit->snd_stream) + end_pointer, stop, | |
2192 | ISIS_SYS_ID_LEN + 2); | |
2193 | stream_set_endp(circuit->snd_stream, tlv_start); | |
2194 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, | |
af8ac8f9 | 2195 | false, false)) { |
17c9dcd5 CF |
2196 | isis_free_tlvs(tlvs); |
2197 | return ISIS_WARNING; | |
d62a17ae | 2198 | } |
eb5d44eb | 2199 | |
e740f9c1 | 2200 | if (IS_DEBUG_SNP_PACKETS) { |
d62a17ae | 2201 | zlog_debug( |
2202 | "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd", | |
2203 | circuit->area->area_tag, level, | |
2204 | circuit->interface->name, | |
2205 | stream_get_endp(circuit->snd_stream)); | |
17c9dcd5 CF |
2206 | log_multiline(LOG_DEBUG, " ", "%s", |
2207 | isis_format_tlvs(tlvs)); | |
e740f9c1 | 2208 | if (IS_DEBUG_PACKET_DUMP) |
d62a17ae | 2209 | zlog_dump_data( |
2210 | STREAM_DATA(circuit->snd_stream), | |
2211 | stream_get_endp(circuit->snd_stream)); | |
2212 | } | |
eb5d44eb | 2213 | |
39bb53d6 | 2214 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
17c9dcd5 | 2215 | int retval = circuit->tx(circuit, level); |
d62a17ae | 2216 | if (retval != ISIS_OK) { |
1a7ecb96 | 2217 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
2218 | "ISIS-Snp (%s): Send L%d CSNP on %s failed", |
2219 | circuit->area->area_tag, level, | |
2220 | circuit->interface->name); | |
17c9dcd5 | 2221 | isis_free_tlvs(tlvs); |
d62a17ae | 2222 | return retval; |
2223 | } | |
3f045a08 | 2224 | |
d62a17ae | 2225 | /* |
2226 | * Start lsp_id of the next CSNP should be one plus the | |
2227 | * stop lsp_id in this current CSNP. | |
2228 | */ | |
2229 | memcpy(start, stop, ISIS_SYS_ID_LEN + 2); | |
d8729f8c | 2230 | loop = false; |
17c9dcd5 | 2231 | for (int i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) { |
d7c0a89a | 2232 | if (start[i] < (uint8_t)0xff) { |
d62a17ae | 2233 | start[i] += 1; |
d8729f8c | 2234 | loop = true; |
d62a17ae | 2235 | break; |
2236 | } | |
2237 | } | |
2238 | memset(stop, 0xff, ISIS_SYS_ID_LEN + 2); | |
17c9dcd5 | 2239 | isis_free_tlvs(tlvs); |
d62a17ae | 2240 | } |
3f045a08 | 2241 | |
17c9dcd5 | 2242 | return ISIS_OK; |
eb5d44eb | 2243 | } |
2244 | ||
d62a17ae | 2245 | int send_l1_csnp(struct thread *thread) |
eb5d44eb | 2246 | { |
d62a17ae | 2247 | struct isis_circuit *circuit; |
eb5d44eb | 2248 | |
d62a17ae | 2249 | circuit = THREAD_ARG(thread); |
2250 | assert(circuit); | |
eb5d44eb | 2251 | |
d62a17ae | 2252 | circuit->t_send_csnp[0] = NULL; |
eb5d44eb | 2253 | |
8e6fb83b CF |
2254 | if ((circuit->circ_type == CIRCUIT_T_BROADCAST |
2255 | && circuit->u.bc.is_dr[0]) | |
2256 | || circuit->circ_type == CIRCUIT_T_P2P) { | |
d62a17ae | 2257 | send_csnp(circuit, 1); |
2258 | } | |
2259 | /* set next timer thread */ | |
2260 | thread_add_timer(master, send_l1_csnp, circuit, | |
2261 | isis_jitter(circuit->csnp_interval[0], CSNP_JITTER), | |
2262 | &circuit->t_send_csnp[0]); | |
eb5d44eb | 2263 | |
9f2d0354 | 2264 | return ISIS_OK; |
eb5d44eb | 2265 | } |
2266 | ||
d62a17ae | 2267 | int send_l2_csnp(struct thread *thread) |
eb5d44eb | 2268 | { |
d62a17ae | 2269 | struct isis_circuit *circuit; |
eb5d44eb | 2270 | |
d62a17ae | 2271 | circuit = THREAD_ARG(thread); |
2272 | assert(circuit); | |
eb5d44eb | 2273 | |
d62a17ae | 2274 | circuit->t_send_csnp[1] = NULL; |
eb5d44eb | 2275 | |
8e6fb83b CF |
2276 | if ((circuit->circ_type == CIRCUIT_T_BROADCAST |
2277 | && circuit->u.bc.is_dr[1]) | |
2278 | || circuit->circ_type == CIRCUIT_T_P2P) { | |
d62a17ae | 2279 | send_csnp(circuit, 2); |
2280 | } | |
2281 | /* set next timer thread */ | |
2282 | thread_add_timer(master, send_l2_csnp, circuit, | |
2283 | isis_jitter(circuit->csnp_interval[1], CSNP_JITTER), | |
2284 | &circuit->t_send_csnp[1]); | |
d70f99e1 | 2285 | |
9f2d0354 | 2286 | return ISIS_OK; |
eb5d44eb | 2287 | } |
2288 | ||
eb5d44eb | 2289 | /* |
2290 | * 7.3.15.4 action on expiration of partial SNP interval | |
2291 | * level 1 | |
2292 | */ | |
d62a17ae | 2293 | static int send_psnp(int level, struct isis_circuit *circuit) |
eb5d44eb | 2294 | { |
d62a17ae | 2295 | if (circuit->circ_type == CIRCUIT_T_BROADCAST |
2296 | && circuit->u.bc.is_dr[level - 1]) | |
2297 | return ISIS_OK; | |
eb5d44eb | 2298 | |
4bef0ec4 | 2299 | if (lspdb_count(&circuit->area->lspdb[level - 1]) == 0) |
d62a17ae | 2300 | return ISIS_OK; |
f390d2c7 | 2301 | |
d62a17ae | 2302 | if (!circuit->snd_stream) |
2303 | return ISIS_ERROR; | |
e38e0df0 | 2304 | |
39bb53d6 CF |
2305 | uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_PARTIAL_SEQ_NUM |
2306 | : L2_PARTIAL_SEQ_NUM; | |
2307 | ||
17c9dcd5 | 2308 | isis_circuit_stream(circuit, &circuit->snd_stream); |
39bb53d6 | 2309 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
17c9dcd5 CF |
2310 | |
2311 | size_t len_pointer = stream_get_endp(circuit->snd_stream); | |
2312 | stream_putw(circuit->snd_stream, 0); /* length is filled in later */ | |
99e5d4af | 2313 | stream_put(circuit->snd_stream, circuit->isis->sysid, ISIS_SYS_ID_LEN); |
17c9dcd5 CF |
2314 | stream_putc(circuit->snd_stream, circuit->idx); |
2315 | ||
2316 | struct isis_passwd *passwd = (level == ISIS_LEVEL1) | |
2317 | ? &circuit->area->area_passwd | |
2318 | : &circuit->area->domain_passwd; | |
2319 | ||
2320 | struct isis_tlvs *tlvs = isis_alloc_tlvs(); | |
2321 | ||
2322 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
2323 | isis_tlvs_add_auth(tlvs, passwd); | |
2324 | ||
2325 | size_t tlv_start = stream_get_endp(circuit->snd_stream); | |
af8ac8f9 CF |
2326 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false, |
2327 | false)) { | |
17c9dcd5 CF |
2328 | isis_free_tlvs(tlvs); |
2329 | return ISIS_WARNING; | |
2330 | } | |
2331 | isis_free_tlvs(tlvs); | |
2332 | ||
2333 | uint16_t num_lsps = | |
2334 | get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream)); | |
f390d2c7 | 2335 | |
d62a17ae | 2336 | while (1) { |
4bef0ec4 DL |
2337 | struct isis_lsp *lsp; |
2338 | ||
17c9dcd5 CF |
2339 | tlvs = isis_alloc_tlvs(); |
2340 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
2341 | isis_tlvs_add_auth(tlvs, passwd); | |
2342 | ||
81fddbe7 | 2343 | frr_each (lspdb, &circuit->area->lspdb[level - 1], lsp) { |
17c9dcd5 CF |
2344 | if (ISIS_CHECK_FLAG(lsp->SSNflags, circuit)) |
2345 | isis_tlvs_add_lsp_entry(tlvs, lsp); | |
eb5d44eb | 2346 | |
17c9dcd5 CF |
2347 | if (tlvs->lsp_entries.count == num_lsps) |
2348 | break; | |
2349 | } | |
2350 | ||
2351 | if (!tlvs->lsp_entries.count) { | |
2352 | isis_free_tlvs(tlvs); | |
d62a17ae | 2353 | return ISIS_OK; |
2354 | } | |
2355 | ||
17c9dcd5 CF |
2356 | stream_set_endp(circuit->snd_stream, tlv_start); |
2357 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, | |
af8ac8f9 | 2358 | false, false)) { |
17c9dcd5 CF |
2359 | isis_free_tlvs(tlvs); |
2360 | return ISIS_WARNING; | |
d62a17ae | 2361 | } |
2362 | ||
e740f9c1 | 2363 | if (IS_DEBUG_SNP_PACKETS) { |
d62a17ae | 2364 | zlog_debug( |
2365 | "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd", | |
2366 | circuit->area->area_tag, level, | |
2367 | circuit->interface->name, | |
2368 | stream_get_endp(circuit->snd_stream)); | |
17c9dcd5 CF |
2369 | log_multiline(LOG_DEBUG, " ", "%s", |
2370 | isis_format_tlvs(tlvs)); | |
e740f9c1 | 2371 | if (IS_DEBUG_PACKET_DUMP) |
d62a17ae | 2372 | zlog_dump_data( |
2373 | STREAM_DATA(circuit->snd_stream), | |
2374 | stream_get_endp(circuit->snd_stream)); | |
2375 | } | |
2376 | ||
39bb53d6 | 2377 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
17c9dcd5 | 2378 | int retval = circuit->tx(circuit, level); |
d62a17ae | 2379 | if (retval != ISIS_OK) { |
1a7ecb96 | 2380 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
2381 | "ISIS-Snp (%s): Send L%d PSNP on %s failed", |
2382 | circuit->area->area_tag, level, | |
2383 | circuit->interface->name); | |
17c9dcd5 | 2384 | isis_free_tlvs(tlvs); |
d62a17ae | 2385 | return retval; |
2386 | } | |
2387 | ||
2388 | /* | |
2389 | * sending succeeded, we can clear SSN flags of this circuit | |
2390 | * for the LSPs in list | |
2391 | */ | |
17c9dcd5 CF |
2392 | struct isis_lsp_entry *entry_head; |
2393 | entry_head = (struct isis_lsp_entry *)tlvs->lsp_entries.head; | |
2394 | for (struct isis_lsp_entry *entry = entry_head; entry; | |
2395 | entry = entry->next) | |
2396 | ISIS_CLEAR_FLAG(entry->lsp->SSNflags, circuit); | |
2397 | isis_free_tlvs(tlvs); | |
d62a17ae | 2398 | } |
2399 | ||
17c9dcd5 | 2400 | return ISIS_OK; |
eb5d44eb | 2401 | } |
2402 | ||
d62a17ae | 2403 | int send_l1_psnp(struct thread *thread) |
eb5d44eb | 2404 | { |
2405 | ||
d62a17ae | 2406 | struct isis_circuit *circuit; |
eb5d44eb | 2407 | |
d62a17ae | 2408 | circuit = THREAD_ARG(thread); |
2409 | assert(circuit); | |
eb5d44eb | 2410 | |
d62a17ae | 2411 | circuit->t_send_psnp[0] = NULL; |
eb5d44eb | 2412 | |
d62a17ae | 2413 | send_psnp(1, circuit); |
2414 | /* set next timer thread */ | |
2415 | thread_add_timer(master, send_l1_psnp, circuit, | |
2416 | isis_jitter(circuit->psnp_interval[0], PSNP_JITTER), | |
2417 | &circuit->t_send_psnp[0]); | |
eb5d44eb | 2418 | |
9f2d0354 | 2419 | return ISIS_OK; |
eb5d44eb | 2420 | } |
2421 | ||
2422 | /* | |
2423 | * 7.3.15.4 action on expiration of partial SNP interval | |
2424 | * level 2 | |
2425 | */ | |
d62a17ae | 2426 | int send_l2_psnp(struct thread *thread) |
eb5d44eb | 2427 | { |
d62a17ae | 2428 | struct isis_circuit *circuit; |
eb5d44eb | 2429 | |
d62a17ae | 2430 | circuit = THREAD_ARG(thread); |
2431 | assert(circuit); | |
eb5d44eb | 2432 | |
d62a17ae | 2433 | circuit->t_send_psnp[1] = NULL; |
eb5d44eb | 2434 | |
d62a17ae | 2435 | send_psnp(2, circuit); |
eb5d44eb | 2436 | |
d62a17ae | 2437 | /* set next timer thread */ |
2438 | thread_add_timer(master, send_l2_psnp, circuit, | |
2439 | isis_jitter(circuit->psnp_interval[1], PSNP_JITTER), | |
2440 | &circuit->t_send_psnp[1]); | |
eb5d44eb | 2441 | |
9f2d0354 | 2442 | return ISIS_OK; |
eb5d44eb | 2443 | } |
2444 | ||
eb5d44eb | 2445 | /* |
2446 | * ISO 10589 - 7.3.14.3 | |
2447 | */ | |
161fa356 CF |
2448 | void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp, |
2449 | enum isis_tx_type tx_type) | |
eb5d44eb | 2450 | { |
d62a17ae | 2451 | int clear_srm = 1; |
2452 | int retval = ISIS_OK; | |
2453 | ||
d62a17ae | 2454 | if (circuit->state != C_STATE_UP || circuit->is_passive == 1) |
2455 | goto out; | |
2456 | ||
2457 | /* | |
2458 | * Do not send if levels do not match | |
2459 | */ | |
2460 | if (!(lsp->level & circuit->is_type)) | |
2461 | goto out; | |
2462 | ||
2463 | /* | |
2464 | * Do not send if we do not have adjacencies in state up on the circuit | |
2465 | */ | |
2466 | if (circuit->upadjcount[lsp->level - 1] == 0) | |
2467 | goto out; | |
2468 | ||
2469 | /* stream_copy will assert and stop program execution if LSP is larger | |
2470 | * than | |
2471 | * the circuit's MTU. So handle and log this case here. */ | |
2472 | if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) { | |
af4c2728 | 2473 | flog_err( |
1a7ecb96 | 2474 | EC_ISIS_PACKET, |
6cde4b45 | 2475 | "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s. LSP Size is %zu while interface stream size is %zu.", |
d62a17ae | 2476 | circuit->area->area_tag, lsp->level, |
af8ac8f9 CF |
2477 | rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno, |
2478 | lsp->hdr.checksum, lsp->hdr.rem_lifetime, | |
d62a17ae | 2479 | circuit->interface->name, stream_get_endp(lsp->pdu), |
2480 | stream_get_size(circuit->snd_stream)); | |
56e22fb6 EDP |
2481 | #ifndef FABRICD |
2482 | /* send a northbound notification */ | |
2483 | isis_notif_lsp_too_large(circuit, stream_get_endp(lsp->pdu), | |
1ee746d9 | 2484 | lsp->hdr.lsp_id); |
56e22fb6 | 2485 | #endif /* ifndef FABRICD */ |
e740f9c1 | 2486 | if (IS_DEBUG_PACKET_DUMP) |
d62a17ae | 2487 | zlog_dump_data(STREAM_DATA(lsp->pdu), |
2488 | stream_get_endp(lsp->pdu)); | |
2489 | retval = ISIS_ERROR; | |
2490 | goto out; | |
2491 | } | |
eb5d44eb | 2492 | |
d62a17ae | 2493 | /* copy our lsp to the send buffer */ |
2494 | stream_copy(circuit->snd_stream, lsp->pdu); | |
2495 | ||
1cbd5b37 CF |
2496 | if (tx_type == TX_LSP_CIRCUIT_SCOPED) { |
2497 | stream_putc_at(circuit->snd_stream, 4, FS_LINK_STATE); | |
89cdc4df RM |
2498 | stream_putc_at(circuit->snd_stream, 7, |
2499 | L2_CIRCUIT_FLOODING_SCOPE); | |
1cbd5b37 CF |
2500 | } |
2501 | ||
e740f9c1 | 2502 | if (IS_DEBUG_UPDATE_PACKETS) { |
6cde4b45 | 2503 | zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s", |
161fa356 CF |
2504 | circuit->area->area_tag, |
2505 | (tx_type == TX_LSP_CIRCUIT_SCOPED) | |
2506 | ? "Circuit scoped " : "", | |
2507 | lsp->level, | |
af8ac8f9 CF |
2508 | rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno, |
2509 | lsp->hdr.checksum, lsp->hdr.rem_lifetime, | |
2510 | circuit->interface->name); | |
e740f9c1 | 2511 | if (IS_DEBUG_PACKET_DUMP) |
d62a17ae | 2512 | zlog_dump_data(STREAM_DATA(circuit->snd_stream), |
2513 | stream_get_endp(circuit->snd_stream)); | |
2514 | } | |
3f045a08 | 2515 | |
39bb53d6 CF |
2516 | uint8_t pdu_type = (tx_type == TX_LSP_CIRCUIT_SCOPED) ? FS_LINK_STATE |
2517 | : (lsp->level == ISIS_LEVEL1) ? L1_LINK_STATE | |
2518 | : L2_LINK_STATE; | |
2519 | ||
d62a17ae | 2520 | clear_srm = 0; |
39bb53d6 | 2521 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
d62a17ae | 2522 | retval = circuit->tx(circuit, lsp->level); |
2523 | if (retval != ISIS_OK) { | |
1a7ecb96 | 2524 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
2525 | "ISIS-Upd (%s): Send L%d LSP on %s failed %s", |
2526 | circuit->area->area_tag, lsp->level, | |
2527 | circuit->interface->name, | |
2528 | (retval == ISIS_WARNING) ? "temporarily" | |
2529 | : "permanently"); | |
d62a17ae | 2530 | } |
f390d2c7 | 2531 | |
cfd1f27b | 2532 | out: |
d62a17ae | 2533 | if (clear_srm |
2534 | || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST) | |
2535 | || (retval != ISIS_OK && retval != ISIS_WARNING)) { | |
2536 | /* SRM flag will trigger retransmission. We will not retransmit | |
2537 | * if we | |
2538 | * encountered a fatal error. | |
2539 | * On success, they should only be cleared if it's a broadcast | |
2540 | * circuit. | |
2541 | * On a P2P circuit, we will wait for the ack from the neighbor | |
2542 | * to clear | |
2543 | * the fag. | |
2544 | */ | |
9b39405f | 2545 | isis_tx_queue_del(circuit->tx_queue, lsp); |
d62a17ae | 2546 | } |
f390d2c7 | 2547 | } |