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