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