]>
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; |
2ab5a2d1 EDP |
1426 | size_t pdu_start = stream_get_getp(circuit->rcv_stream); |
1427 | size_t pdu_end = stream_get_endp(circuit->rcv_stream); | |
1428 | char raw_pdu[pdu_end - pdu_start]; | |
1429 | ||
1430 | stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start, | |
1431 | pdu_end - pdu_start); | |
eb5d44eb | 1432 | |
88f9d911 CF |
1433 | /* Verify that at least the 8 bytes fixed header have been received */ |
1434 | if (stream_get_endp(circuit->rcv_stream) < ISIS_FIXED_HDR_LEN) { | |
1a7ecb96 | 1435 | flog_err(EC_ISIS_PACKET, "PDU is too short to be IS-IS."); |
88f9d911 CF |
1436 | return ISIS_ERROR; |
1437 | } | |
eb5d44eb | 1438 | |
88f9d911 CF |
1439 | uint8_t idrp = stream_getc(circuit->rcv_stream); |
1440 | uint8_t length = stream_getc(circuit->rcv_stream); | |
1441 | uint8_t version1 = stream_getc(circuit->rcv_stream); | |
1442 | uint8_t id_len = stream_getc(circuit->rcv_stream); | |
1443 | uint8_t pdu_type = stream_getc(circuit->rcv_stream) | |
1444 | & 0x1f; /* bits 6-8 are reserved */ | |
1445 | uint8_t version2 = stream_getc(circuit->rcv_stream); | |
2ab5a2d1 | 1446 | |
88f9d911 CF |
1447 | stream_forward_getp(circuit->rcv_stream, 1); /* reserved */ |
1448 | uint8_t max_area_addrs = stream_getc(circuit->rcv_stream); | |
1449 | ||
39bb53d6 CF |
1450 | pdu_counter_count(circuit->area->pdu_rx_counters, pdu_type); |
1451 | ||
88f9d911 | 1452 | if (idrp == ISO9542_ESIS) { |
450971aa | 1453 | flog_err(EC_LIB_DEVELOPMENT, |
1c50c1c0 | 1454 | "No support for ES-IS packet IDRP=%" PRIx8, idrp); |
d62a17ae | 1455 | return ISIS_ERROR; |
1456 | } | |
eb5d44eb | 1457 | |
88f9d911 | 1458 | if (idrp != ISO10589_ISIS) { |
1a7ecb96 | 1459 | flog_err(EC_ISIS_PACKET, "Not an IS-IS packet IDRP=%" PRIx8, |
1c50c1c0 | 1460 | idrp); |
d62a17ae | 1461 | return ISIS_ERROR; |
1462 | } | |
3f045a08 | 1463 | |
88f9d911 CF |
1464 | if (version1 != 1) { |
1465 | zlog_warn("Unsupported ISIS version %" PRIu8, version1); | |
1466 | return ISIS_WARNING; | |
1467 | } | |
eb5d44eb | 1468 | |
88f9d911 | 1469 | if (id_len != 0 && id_len != ISIS_SYS_ID_LEN) { |
af4c2728 | 1470 | flog_err( |
1a7ecb96 | 1471 | EC_ISIS_PACKET, |
88f9d911 CF |
1472 | "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8 |
1473 | ", while the parameter for this IS is %u", | |
1474 | id_len, ISIS_SYS_ID_LEN); | |
d62a17ae | 1475 | return ISIS_ERROR; |
1476 | } | |
eb5d44eb | 1477 | |
88f9d911 CF |
1478 | uint8_t expected_length; |
1479 | if (pdu_size(pdu_type, &expected_length)) { | |
1480 | zlog_warn("Unsupported ISIS PDU %" PRIu8, pdu_type); | |
d62a17ae | 1481 | return ISIS_WARNING; |
1482 | } | |
88f9d911 CF |
1483 | |
1484 | if (length != expected_length) { | |
1a7ecb96 | 1485 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
1486 | "Exepected fixed header length = %" PRIu8 |
1487 | " but got %" PRIu8, | |
1488 | expected_length, length); | |
88f9d911 CF |
1489 | return ISIS_ERROR; |
1490 | } | |
1491 | ||
1492 | if (stream_get_endp(circuit->rcv_stream) < length) { | |
af4c2728 | 1493 | flog_err( |
1a7ecb96 | 1494 | EC_ISIS_PACKET, |
88f9d911 | 1495 | "PDU is too short to contain fixed header of given PDU type."); |
d62a17ae | 1496 | return ISIS_ERROR; |
1497 | } | |
eb5d44eb | 1498 | |
88f9d911 CF |
1499 | if (version2 != 1) { |
1500 | zlog_warn("Unsupported ISIS PDU version %" PRIu8, version2); | |
d62a17ae | 1501 | return ISIS_WARNING; |
1502 | } | |
3f045a08 | 1503 | |
d62a17ae | 1504 | if (circuit->is_passive) { |
1505 | zlog_warn("Received ISIS PDU on passive circuit %s", | |
1506 | circuit->interface->name); | |
1507 | return ISIS_WARNING; | |
1508 | } | |
3f045a08 | 1509 | |
d62a17ae | 1510 | /* either 3 or 0 */ |
1cbd5b37 CF |
1511 | if (pdu_type != FS_LINK_STATE /* FS PDU doesn't contain max area addr field */ |
1512 | && max_area_addrs != 0 | |
1513 | && max_area_addrs != isis->max_area_addrs) { | |
af4c2728 | 1514 | flog_err( |
1a7ecb96 | 1515 | EC_ISIS_PACKET, |
88f9d911 CF |
1516 | "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8 |
1517 | " while the parameter for this IS is %u", | |
1518 | max_area_addrs, isis->max_area_addrs); | |
2ab5a2d1 EDP |
1519 | #ifndef FABRICD |
1520 | /* send northbound notification */ | |
1521 | isis_notif_max_area_addr_mismatch(circuit, max_area_addrs, | |
1522 | raw_pdu); | |
1523 | #endif /* ifndef FABRICD */ | |
d62a17ae | 1524 | return ISIS_ERROR; |
1525 | } | |
eb5d44eb | 1526 | |
88f9d911 | 1527 | switch (pdu_type) { |
d62a17ae | 1528 | case L1_LAN_HELLO: |
d62a17ae | 1529 | case L2_LAN_HELLO: |
d62a17ae | 1530 | case P2P_HELLO: |
a2d41bb0 CF |
1531 | if (fabricd && pdu_type != P2P_HELLO) |
1532 | return ISIS_ERROR; | |
0c1bd758 | 1533 | retval = process_hello(pdu_type, circuit, ssnpa); |
d62a17ae | 1534 | break; |
1535 | case L1_LINK_STATE: | |
d62a17ae | 1536 | case L2_LINK_STATE: |
1cbd5b37 | 1537 | case FS_LINK_STATE: |
a2d41bb0 CF |
1538 | if (fabricd |
1539 | && pdu_type != L2_LINK_STATE | |
1540 | && pdu_type != FS_LINK_STATE) | |
1541 | return ISIS_ERROR; | |
9b39405f | 1542 | retval = process_lsp(pdu_type, circuit, ssnpa, max_area_addrs); |
d62a17ae | 1543 | break; |
1544 | case L1_COMPLETE_SEQ_NUM: | |
d62a17ae | 1545 | case L2_COMPLETE_SEQ_NUM: |
d62a17ae | 1546 | case L1_PARTIAL_SEQ_NUM: |
d62a17ae | 1547 | case L2_PARTIAL_SEQ_NUM: |
17c9dcd5 | 1548 | retval = process_snp(pdu_type, circuit, ssnpa); |
d62a17ae | 1549 | break; |
1550 | default: | |
1551 | return ISIS_ERROR; | |
1552 | } | |
eb5d44eb | 1553 | |
d62a17ae | 1554 | return retval; |
eb5d44eb | 1555 | } |
1556 | ||
d62a17ae | 1557 | int isis_receive(struct thread *thread) |
eb5d44eb | 1558 | { |
d62a17ae | 1559 | struct isis_circuit *circuit; |
d7c0a89a | 1560 | uint8_t ssnpa[ETH_ALEN]; |
d62a17ae | 1561 | int retval; |
eb5d44eb | 1562 | |
d62a17ae | 1563 | /* |
1564 | * Get the circuit | |
1565 | */ | |
1566 | circuit = THREAD_ARG(thread); | |
1567 | assert(circuit); | |
eb5d44eb | 1568 | |
d62a17ae | 1569 | circuit->t_read = NULL; |
eb5d44eb | 1570 | |
d62a17ae | 1571 | isis_circuit_stream(circuit, &circuit->rcv_stream); |
eb5d44eb | 1572 | |
d62a17ae | 1573 | retval = circuit->rx(circuit, ssnpa); |
eb5d44eb | 1574 | |
b9347997 | 1575 | #if ISIS_METHOD != ISIS_METHOD_BPF |
d62a17ae | 1576 | if (retval == ISIS_OK) |
1577 | retval = isis_handle_pdu(circuit, ssnpa); | |
b9347997 | 1578 | #endif //ISIS_METHOD != ISIS_METHOD_BPF |
eb5d44eb | 1579 | |
d62a17ae | 1580 | /* |
1581 | * prepare for next packet. | |
1582 | */ | |
1583 | if (!circuit->is_passive) | |
1584 | isis_circuit_prepare(circuit); | |
eb5d44eb | 1585 | |
d62a17ae | 1586 | return retval; |
eb5d44eb | 1587 | } |
1588 | ||
eb5d44eb | 1589 | /* |
d62a17ae | 1590 | * SEND SIDE |
eb5d44eb | 1591 | */ |
88f9d911 | 1592 | void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream) |
eb5d44eb | 1593 | { |
88f9d911 CF |
1594 | uint8_t length; |
1595 | ||
1596 | if (pdu_size(pdu_type, &length)) | |
1597 | assert(!"Unknown PDU Type"); | |
1598 | ||
1599 | stream_putc(stream, ISO10589_ISIS); /* IDRP */ | |
1600 | stream_putc(stream, length); /* Length of fixed header */ | |
1601 | stream_putc(stream, 1); /* Version/Protocol ID Extension 1 */ | |
1602 | stream_putc(stream, 0); /* ID Length, 0 => 6 */ | |
1603 | stream_putc(stream, pdu_type); | |
1604 | stream_putc(stream, 1); /* Subversion */ | |
1605 | stream_putc(stream, 0); /* Reserved */ | |
1606 | stream_putc(stream, 0); /* Max Area Addresses 0 => 3 */ | |
eb5d44eb | 1607 | } |
1608 | ||
39bb53d6 | 1609 | static uint8_t hello_pdu_type(struct isis_circuit *circuit, int level) |
eb5d44eb | 1610 | { |
d62a17ae | 1611 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
39bb53d6 | 1612 | return (level == IS_LEVEL_1) ? L1_LAN_HELLO : L2_LAN_HELLO; |
d62a17ae | 1613 | else |
39bb53d6 CF |
1614 | return P2P_HELLO; |
1615 | } | |
1616 | ||
1617 | static void put_hello_hdr(struct isis_circuit *circuit, int level, | |
1618 | size_t *len_pointer) | |
1619 | { | |
1620 | uint8_t pdu_type = hello_pdu_type(circuit, level); | |
88f9d911 | 1621 | |
0c1bd758 | 1622 | isis_circuit_stream(circuit, &circuit->snd_stream); |
88f9d911 | 1623 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
d62a17ae | 1624 | |
0c1bd758 CF |
1625 | stream_putc(circuit->snd_stream, circuit->is_type); |
1626 | stream_put(circuit->snd_stream, circuit->area->isis->sysid, | |
1627 | ISIS_SYS_ID_LEN); | |
eb5d44eb | 1628 | |
0c1bd758 CF |
1629 | uint32_t holdtime = circuit->hello_multiplier[level - 1] |
1630 | * circuit->hello_interval[level - 1]; | |
d62a17ae | 1631 | |
0c1bd758 CF |
1632 | if (holdtime > 0xffff) |
1633 | holdtime = 0xffff; | |
d62a17ae | 1634 | |
0c1bd758 CF |
1635 | stream_putw(circuit->snd_stream, holdtime); |
1636 | *len_pointer = stream_get_endp(circuit->snd_stream); | |
1637 | stream_putw(circuit->snd_stream, 0); /* length is filled in later */ | |
d62a17ae | 1638 | |
0c1bd758 | 1639 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
d7c0a89a QY |
1640 | uint8_t *desig_is = (level == IS_LEVEL_1) |
1641 | ? circuit->u.bc.l1_desig_is | |
1642 | : circuit->u.bc.l2_desig_is; | |
0c1bd758 CF |
1643 | stream_putc(circuit->snd_stream, circuit->priority[level - 1]); |
1644 | stream_put(circuit->snd_stream, desig_is, ISIS_SYS_ID_LEN + 1); | |
1645 | } else { | |
1646 | stream_putc(circuit->snd_stream, circuit->circuit_id); | |
d62a17ae | 1647 | } |
0c1bd758 | 1648 | } |
eb5d44eb | 1649 | |
0c1bd758 CF |
1650 | int send_hello(struct isis_circuit *circuit, int level) |
1651 | { | |
1652 | size_t len_pointer; | |
1653 | int retval; | |
1654 | ||
1655 | if (circuit->is_passive) | |
1656 | return ISIS_OK; | |
1657 | ||
1658 | if (circuit->interface->mtu == 0) { | |
1659 | zlog_warn("circuit has zero MTU"); | |
d62a17ae | 1660 | return ISIS_WARNING; |
0c1bd758 CF |
1661 | } |
1662 | ||
1663 | put_hello_hdr(circuit, level, &len_pointer); | |
1664 | ||
1665 | struct isis_tlvs *tlvs = isis_alloc_tlvs(); | |
1666 | ||
1667 | isis_tlvs_add_auth(tlvs, &circuit->passwd); | |
1668 | ||
a3acf37d DS |
1669 | if (!listcount(circuit->area->area_addrs)) { |
1670 | isis_free_tlvs(tlvs); | |
d62a17ae | 1671 | return ISIS_WARNING; |
a3acf37d DS |
1672 | } |
1673 | ||
0c1bd758 | 1674 | isis_tlvs_add_area_addresses(tlvs, circuit->area->area_addrs); |
d62a17ae | 1675 | |
42fe2621 | 1676 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { |
0c1bd758 CF |
1677 | isis_tlvs_add_lan_neighbors( |
1678 | tlvs, circuit->u.bc.lan_neighs[level - 1]); | |
58e5d748 CF |
1679 | } else if (circuit->circ_type == CIRCUIT_T_P2P |
1680 | && !circuit->disable_threeway_adj) { | |
42fe2621 CF |
1681 | uint32_t ext_circuit_id = circuit->idx; |
1682 | if (circuit->u.p2p.neighbor) { | |
8e6fb83b CF |
1683 | uint8_t threeway_state; |
1684 | ||
1685 | if (fabricd_initial_sync_is_in_progress(circuit->area) | |
1686 | && fabricd_initial_sync_circuit(circuit->area) != circuit) | |
1687 | threeway_state = ISIS_THREEWAY_DOWN; | |
1688 | else | |
1689 | threeway_state = circuit->u.p2p.neighbor->threeway_state; | |
42fe2621 | 1690 | isis_tlvs_add_threeway_adj(tlvs, |
8e6fb83b | 1691 | threeway_state, |
42fe2621 CF |
1692 | ext_circuit_id, |
1693 | circuit->u.p2p.neighbor->sysid, | |
1694 | circuit->u.p2p.neighbor->ext_circuit_id); | |
1695 | } else { | |
1696 | isis_tlvs_add_threeway_adj(tlvs, | |
1697 | ISIS_THREEWAY_DOWN, | |
1698 | ext_circuit_id, | |
1699 | NULL, 0); | |
1700 | } | |
1701 | } | |
0c1bd758 CF |
1702 | |
1703 | isis_tlvs_set_protocols_supported(tlvs, &circuit->nlpids); | |
d62a17ae | 1704 | |
1705 | /* | |
1706 | * MT Supported TLV | |
1707 | * | |
1708 | * TLV gets included if no topology is enabled on the interface, | |
1709 | * if one topology other than #0 is enabled, or if multiple topologies | |
1710 | * are enabled. | |
1711 | */ | |
1712 | struct isis_circuit_mt_setting **mt_settings; | |
1713 | unsigned int mt_count; | |
1714 | ||
1715 | mt_settings = circuit_mt_settings(circuit, &mt_count); | |
0c1bd758 CF |
1716 | if (mt_count == 0 && area_is_mt(circuit->area)) { |
1717 | tlvs->mt_router_info_empty = true; | |
1718 | } else if ((mt_count == 1 | |
1719 | && mt_settings[0]->mtid != ISIS_MT_IPV4_UNICAST) | |
1720 | || (mt_count > 1)) { | |
1721 | for (unsigned int i = 0; i < mt_count; i++) | |
1722 | isis_tlvs_add_mt_router_info(tlvs, mt_settings[i]->mtid, | |
1723 | false, false); | |
d62a17ae | 1724 | } |
eb5d44eb | 1725 | |
41415888 CF |
1726 | if (circuit->ip_router) { |
1727 | struct list *circuit_ip_addrs = fabricd_ip_addrs(circuit); | |
1728 | ||
1729 | if (circuit_ip_addrs) | |
1730 | isis_tlvs_add_ipv4_addresses(tlvs, circuit_ip_addrs); | |
1731 | } | |
d62a17ae | 1732 | |
0c1bd758 CF |
1733 | if (circuit->ipv6_router && circuit->ipv6_link) |
1734 | isis_tlvs_add_ipv6_addresses(tlvs, circuit->ipv6_link); | |
d62a17ae | 1735 | |
0c1bd758 | 1736 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, |
af8ac8f9 | 1737 | circuit->pad_hellos, false)) { |
0c1bd758 CF |
1738 | isis_free_tlvs(tlvs); |
1739 | return ISIS_WARNING; /* XXX: Maybe Log TLV structure? */ | |
f390d2c7 | 1740 | } |
d62a17ae | 1741 | |
1742 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
1743 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
1744 | zlog_debug( | |
1745 | "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd", | |
1746 | circuit->area->area_tag, level, | |
0c1bd758 CF |
1747 | circuit->interface->name, |
1748 | stream_get_endp(circuit->snd_stream)); | |
d62a17ae | 1749 | } else { |
1750 | zlog_debug( | |
1751 | "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd", | |
1752 | circuit->area->area_tag, | |
0c1bd758 CF |
1753 | circuit->interface->name, |
1754 | stream_get_endp(circuit->snd_stream)); | |
d62a17ae | 1755 | } |
1756 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
1757 | zlog_dump_data(STREAM_DATA(circuit->snd_stream), | |
1758 | stream_get_endp(circuit->snd_stream)); | |
f390d2c7 | 1759 | } |
eb5d44eb | 1760 | |
0c1bd758 CF |
1761 | isis_free_tlvs(tlvs); |
1762 | ||
89cdc4df RM |
1763 | pdu_counter_count(circuit->area->pdu_tx_counters, |
1764 | hello_pdu_type(circuit, level)); | |
d62a17ae | 1765 | retval = circuit->tx(circuit, level); |
1766 | if (retval != ISIS_OK) | |
1a7ecb96 | 1767 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
1768 | "ISIS-Adj (%s): Send L%d IIH on %s failed", |
1769 | circuit->area->area_tag, level, | |
1770 | circuit->interface->name); | |
eb5d44eb | 1771 | |
d62a17ae | 1772 | return retval; |
eb5d44eb | 1773 | } |
1774 | ||
a0a707ee | 1775 | static int send_hello_cb(struct thread *thread) |
eb5d44eb | 1776 | { |
7c4f7aab | 1777 | struct isis_circuit_arg *arg = THREAD_ARG(thread); |
7c4f7aab | 1778 | assert(arg); |
89cdc4df | 1779 | |
7c4f7aab CF |
1780 | struct isis_circuit *circuit = arg->circuit; |
1781 | int level = arg->level; | |
d62a17ae | 1782 | |
d62a17ae | 1783 | assert(circuit); |
ddfdbd32 | 1784 | |
7c4f7aab CF |
1785 | if (circuit->circ_type == CIRCUIT_T_P2P) { |
1786 | circuit->u.p2p.t_send_p2p_hello = NULL; | |
7c4f7aab | 1787 | send_hello(circuit, 1); |
a0a707ee CF |
1788 | send_hello_sched(circuit, ISIS_LEVEL1, |
1789 | 1000 * circuit->hello_interval[1]); | |
7c4f7aab | 1790 | return ISIS_OK; |
d62a17ae | 1791 | } |
ddfdbd32 | 1792 | |
7c4f7aab CF |
1793 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) { |
1794 | zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d", | |
1795 | circuit->area->area_tag, circuit->circ_type); | |
1796 | return ISIS_WARNING; | |
1797 | } | |
eb5d44eb | 1798 | |
7c4f7aab CF |
1799 | circuit->u.bc.t_send_lan_hello[level - 1] = NULL; |
1800 | if (!(circuit->is_type & level)) { | |
1801 | zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit", | |
1802 | circuit->area->area_tag, level, 3 - level); | |
1803 | return ISIS_WARNING; | |
1804 | } | |
eb5d44eb | 1805 | |
7c4f7aab CF |
1806 | if (circuit->u.bc.run_dr_elect[level - 1]) |
1807 | isis_dr_elect(circuit, level); | |
eb5d44eb | 1808 | |
7c4f7aab | 1809 | int rv = send_hello(circuit, level); |
eb5d44eb | 1810 | |
d62a17ae | 1811 | /* set next timer thread */ |
a0a707ee | 1812 | send_hello_sched(circuit, level, 1000 * circuit->hello_interval[level - 1]); |
7c4f7aab | 1813 | return rv; |
eb5d44eb | 1814 | } |
1815 | ||
a0a707ee CF |
1816 | static void _send_hello_sched(struct isis_circuit *circuit, |
1817 | struct thread **threadp, | |
1818 | int level, long delay) | |
1819 | { | |
1820 | if (*threadp) { | |
1821 | if (thread_timer_remain_msec(*threadp) < (unsigned long)delay) | |
1822 | return; | |
1823 | ||
1824 | thread_cancel(*threadp); | |
1825 | } | |
1826 | ||
1827 | thread_add_timer_msec(master, send_hello_cb, | |
1828 | &circuit->level_arg[level - 1], | |
1829 | isis_jitter(delay, IIH_JITTER), | |
1830 | threadp); | |
1831 | } | |
1832 | ||
1833 | void send_hello_sched(struct isis_circuit *circuit, int level, long delay) | |
1834 | { | |
1835 | if (circuit->circ_type == CIRCUIT_T_P2P) { | |
1836 | _send_hello_sched(circuit, &circuit->u.p2p.t_send_p2p_hello, | |
1837 | ISIS_LEVEL1, delay); | |
1838 | return; | |
1839 | } | |
1840 | ||
1841 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) { | |
1842 | zlog_warn("%s: encountered unknown circuit type %d on %s", | |
1843 | __func__, circuit->circ_type, | |
1844 | circuit->interface->name); | |
1845 | return; | |
1846 | } | |
1847 | ||
1848 | for (int loop_level = ISIS_LEVEL1; loop_level <= ISIS_LEVEL2; loop_level++) { | |
1849 | if (!(loop_level & level)) | |
1850 | continue; | |
1851 | ||
1852 | _send_hello_sched( | |
1853 | circuit, | |
1854 | &circuit->u.bc.t_send_lan_hello[loop_level - 1], | |
1855 | loop_level, | |
1856 | delay | |
1857 | ); | |
1858 | } | |
1859 | } | |
1860 | ||
1861 | ||
3f045a08 JB |
1862 | /* |
1863 | * Count the maximum number of lsps that can be accomodated by a given size. | |
1864 | */ | |
af8ac8f9 | 1865 | #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN) |
d62a17ae | 1866 | static uint16_t get_max_lsp_count(uint16_t size) |
3f045a08 | 1867 | { |
d62a17ae | 1868 | uint16_t tlv_count; |
1869 | uint16_t lsp_count; | |
1870 | uint16_t remaining_size; | |
3f045a08 | 1871 | |
d62a17ae | 1872 | /* First count the full size TLVs */ |
1873 | tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE; | |
1874 | lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN); | |
3f045a08 | 1875 | |
d62a17ae | 1876 | /* The last TLV, if any */ |
1877 | remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE; | |
1878 | if (remaining_size - 2 >= LSP_ENTRIES_LEN) | |
1879 | lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN; | |
3f045a08 | 1880 | |
d62a17ae | 1881 | return lsp_count; |
3f045a08 JB |
1882 | } |
1883 | ||
17c9dcd5 | 1884 | int send_csnp(struct isis_circuit *circuit, int level) |
3f045a08 | 1885 | { |
17c9dcd5 CF |
1886 | if (circuit->area->lspdb[level - 1] == NULL |
1887 | || dict_count(circuit->area->lspdb[level - 1]) == 0) | |
1888 | return ISIS_OK; | |
d62a17ae | 1889 | |
39bb53d6 CF |
1890 | uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_COMPLETE_SEQ_NUM |
1891 | : L2_COMPLETE_SEQ_NUM; | |
1892 | ||
17c9dcd5 | 1893 | isis_circuit_stream(circuit, &circuit->snd_stream); |
39bb53d6 | 1894 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
3f045a08 | 1895 | |
17c9dcd5 CF |
1896 | size_t len_pointer = stream_get_endp(circuit->snd_stream); |
1897 | stream_putw(circuit->snd_stream, 0); | |
1898 | stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
1899 | /* with zero circuit id - ref 9.10, 9.11 */ | |
1900 | stream_putc(circuit->snd_stream, 0); | |
3f045a08 | 1901 | |
17c9dcd5 CF |
1902 | size_t start_pointer = stream_get_endp(circuit->snd_stream); |
1903 | stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2); | |
1904 | size_t end_pointer = stream_get_endp(circuit->snd_stream); | |
1905 | stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2); | |
d62a17ae | 1906 | |
17c9dcd5 CF |
1907 | struct isis_passwd *passwd = (level == ISIS_LEVEL1) |
1908 | ? &circuit->area->area_passwd | |
1909 | : &circuit->area->domain_passwd; | |
d62a17ae | 1910 | |
17c9dcd5 | 1911 | struct isis_tlvs *tlvs = isis_alloc_tlvs(); |
3f045a08 | 1912 | |
17c9dcd5 CF |
1913 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
1914 | isis_tlvs_add_auth(tlvs, passwd); | |
eb5d44eb | 1915 | |
17c9dcd5 | 1916 | size_t tlv_start = stream_get_endp(circuit->snd_stream); |
af8ac8f9 CF |
1917 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false, |
1918 | false)) { | |
17c9dcd5 CF |
1919 | isis_free_tlvs(tlvs); |
1920 | return ISIS_WARNING; | |
1921 | } | |
1922 | isis_free_tlvs(tlvs); | |
d62a17ae | 1923 | |
17c9dcd5 CF |
1924 | uint16_t num_lsps = |
1925 | get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream)); | |
d62a17ae | 1926 | |
17c9dcd5 | 1927 | uint8_t start[ISIS_SYS_ID_LEN + 2]; |
d62a17ae | 1928 | memset(start, 0x00, ISIS_SYS_ID_LEN + 2); |
17c9dcd5 | 1929 | uint8_t stop[ISIS_SYS_ID_LEN + 2]; |
d62a17ae | 1930 | memset(stop, 0xff, ISIS_SYS_ID_LEN + 2); |
1931 | ||
17c9dcd5 | 1932 | bool loop = true; |
d62a17ae | 1933 | while (loop) { |
17c9dcd5 CF |
1934 | tlvs = isis_alloc_tlvs(); |
1935 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
1936 | isis_tlvs_add_auth(tlvs, passwd); | |
1937 | ||
1938 | struct isis_lsp *last_lsp; | |
1939 | isis_tlvs_add_csnp_entries(tlvs, start, stop, num_lsps, | |
1940 | circuit->area->lspdb[level - 1], | |
1941 | &last_lsp); | |
d62a17ae | 1942 | /* |
1943 | * Update the stop lsp_id before encoding this CSNP. | |
1944 | */ | |
17c9dcd5 | 1945 | if (tlvs->lsp_entries.count < num_lsps) { |
d62a17ae | 1946 | memset(stop, 0xff, ISIS_SYS_ID_LEN + 2); |
1947 | } else { | |
af8ac8f9 | 1948 | memcpy(stop, last_lsp->hdr.lsp_id, sizeof(stop)); |
d62a17ae | 1949 | } |
3f045a08 | 1950 | |
17c9dcd5 CF |
1951 | memcpy(STREAM_DATA(circuit->snd_stream) + start_pointer, start, |
1952 | ISIS_SYS_ID_LEN + 2); | |
1953 | memcpy(STREAM_DATA(circuit->snd_stream) + end_pointer, stop, | |
1954 | ISIS_SYS_ID_LEN + 2); | |
1955 | stream_set_endp(circuit->snd_stream, tlv_start); | |
1956 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, | |
af8ac8f9 | 1957 | false, false)) { |
17c9dcd5 CF |
1958 | isis_free_tlvs(tlvs); |
1959 | return ISIS_WARNING; | |
d62a17ae | 1960 | } |
eb5d44eb | 1961 | |
d62a17ae | 1962 | if (isis->debugs & DEBUG_SNP_PACKETS) { |
1963 | zlog_debug( | |
1964 | "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd", | |
1965 | circuit->area->area_tag, level, | |
1966 | circuit->interface->name, | |
1967 | stream_get_endp(circuit->snd_stream)); | |
17c9dcd5 CF |
1968 | log_multiline(LOG_DEBUG, " ", "%s", |
1969 | isis_format_tlvs(tlvs)); | |
d62a17ae | 1970 | if (isis->debugs & DEBUG_PACKET_DUMP) |
1971 | zlog_dump_data( | |
1972 | STREAM_DATA(circuit->snd_stream), | |
1973 | stream_get_endp(circuit->snd_stream)); | |
1974 | } | |
eb5d44eb | 1975 | |
39bb53d6 | 1976 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
17c9dcd5 | 1977 | int retval = circuit->tx(circuit, level); |
d62a17ae | 1978 | if (retval != ISIS_OK) { |
1a7ecb96 | 1979 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
1980 | "ISIS-Snp (%s): Send L%d CSNP on %s failed", |
1981 | circuit->area->area_tag, level, | |
1982 | circuit->interface->name); | |
17c9dcd5 | 1983 | isis_free_tlvs(tlvs); |
d62a17ae | 1984 | return retval; |
1985 | } | |
3f045a08 | 1986 | |
d62a17ae | 1987 | /* |
1988 | * Start lsp_id of the next CSNP should be one plus the | |
1989 | * stop lsp_id in this current CSNP. | |
1990 | */ | |
1991 | memcpy(start, stop, ISIS_SYS_ID_LEN + 2); | |
1992 | loop = 0; | |
17c9dcd5 | 1993 | for (int i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) { |
d7c0a89a | 1994 | if (start[i] < (uint8_t)0xff) { |
d62a17ae | 1995 | start[i] += 1; |
1996 | loop = 1; | |
1997 | break; | |
1998 | } | |
1999 | } | |
2000 | memset(stop, 0xff, ISIS_SYS_ID_LEN + 2); | |
17c9dcd5 | 2001 | isis_free_tlvs(tlvs); |
d62a17ae | 2002 | } |
3f045a08 | 2003 | |
17c9dcd5 | 2004 | return ISIS_OK; |
eb5d44eb | 2005 | } |
2006 | ||
d62a17ae | 2007 | int send_l1_csnp(struct thread *thread) |
eb5d44eb | 2008 | { |
d62a17ae | 2009 | struct isis_circuit *circuit; |
2010 | int retval = ISIS_OK; | |
eb5d44eb | 2011 | |
d62a17ae | 2012 | circuit = THREAD_ARG(thread); |
2013 | assert(circuit); | |
eb5d44eb | 2014 | |
d62a17ae | 2015 | circuit->t_send_csnp[0] = NULL; |
eb5d44eb | 2016 | |
8e6fb83b CF |
2017 | if ((circuit->circ_type == CIRCUIT_T_BROADCAST |
2018 | && circuit->u.bc.is_dr[0]) | |
2019 | || circuit->circ_type == CIRCUIT_T_P2P) { | |
d62a17ae | 2020 | send_csnp(circuit, 1); |
2021 | } | |
2022 | /* set next timer thread */ | |
2023 | thread_add_timer(master, send_l1_csnp, circuit, | |
2024 | isis_jitter(circuit->csnp_interval[0], CSNP_JITTER), | |
2025 | &circuit->t_send_csnp[0]); | |
eb5d44eb | 2026 | |
d62a17ae | 2027 | return retval; |
eb5d44eb | 2028 | } |
2029 | ||
d62a17ae | 2030 | int send_l2_csnp(struct thread *thread) |
eb5d44eb | 2031 | { |
d62a17ae | 2032 | struct isis_circuit *circuit; |
2033 | int retval = ISIS_OK; | |
eb5d44eb | 2034 | |
d62a17ae | 2035 | circuit = THREAD_ARG(thread); |
2036 | assert(circuit); | |
eb5d44eb | 2037 | |
d62a17ae | 2038 | circuit->t_send_csnp[1] = NULL; |
eb5d44eb | 2039 | |
8e6fb83b CF |
2040 | if ((circuit->circ_type == CIRCUIT_T_BROADCAST |
2041 | && circuit->u.bc.is_dr[1]) | |
2042 | || circuit->circ_type == CIRCUIT_T_P2P) { | |
d62a17ae | 2043 | send_csnp(circuit, 2); |
2044 | } | |
2045 | /* set next timer thread */ | |
2046 | thread_add_timer(master, send_l2_csnp, circuit, | |
2047 | isis_jitter(circuit->csnp_interval[1], CSNP_JITTER), | |
2048 | &circuit->t_send_csnp[1]); | |
d70f99e1 | 2049 | |
d62a17ae | 2050 | return retval; |
eb5d44eb | 2051 | } |
2052 | ||
eb5d44eb | 2053 | /* |
2054 | * 7.3.15.4 action on expiration of partial SNP interval | |
2055 | * level 1 | |
2056 | */ | |
d62a17ae | 2057 | static int send_psnp(int level, struct isis_circuit *circuit) |
eb5d44eb | 2058 | { |
d62a17ae | 2059 | if (circuit->circ_type == CIRCUIT_T_BROADCAST |
2060 | && circuit->u.bc.is_dr[level - 1]) | |
2061 | return ISIS_OK; | |
eb5d44eb | 2062 | |
d62a17ae | 2063 | if (circuit->area->lspdb[level - 1] == NULL |
2064 | || dict_count(circuit->area->lspdb[level - 1]) == 0) | |
2065 | return ISIS_OK; | |
f390d2c7 | 2066 | |
d62a17ae | 2067 | if (!circuit->snd_stream) |
2068 | return ISIS_ERROR; | |
e38e0df0 | 2069 | |
39bb53d6 CF |
2070 | uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_PARTIAL_SEQ_NUM |
2071 | : L2_PARTIAL_SEQ_NUM; | |
2072 | ||
17c9dcd5 | 2073 | isis_circuit_stream(circuit, &circuit->snd_stream); |
39bb53d6 | 2074 | fill_fixed_hdr(pdu_type, circuit->snd_stream); |
17c9dcd5 CF |
2075 | |
2076 | size_t len_pointer = stream_get_endp(circuit->snd_stream); | |
2077 | stream_putw(circuit->snd_stream, 0); /* length is filled in later */ | |
2078 | stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
2079 | stream_putc(circuit->snd_stream, circuit->idx); | |
2080 | ||
2081 | struct isis_passwd *passwd = (level == ISIS_LEVEL1) | |
2082 | ? &circuit->area->area_passwd | |
2083 | : &circuit->area->domain_passwd; | |
2084 | ||
2085 | struct isis_tlvs *tlvs = isis_alloc_tlvs(); | |
2086 | ||
2087 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
2088 | isis_tlvs_add_auth(tlvs, passwd); | |
2089 | ||
2090 | size_t tlv_start = stream_get_endp(circuit->snd_stream); | |
af8ac8f9 CF |
2091 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false, |
2092 | false)) { | |
17c9dcd5 CF |
2093 | isis_free_tlvs(tlvs); |
2094 | return ISIS_WARNING; | |
2095 | } | |
2096 | isis_free_tlvs(tlvs); | |
2097 | ||
2098 | uint16_t num_lsps = | |
2099 | get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream)); | |
f390d2c7 | 2100 | |
d62a17ae | 2101 | while (1) { |
17c9dcd5 CF |
2102 | tlvs = isis_alloc_tlvs(); |
2103 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
2104 | isis_tlvs_add_auth(tlvs, passwd); | |
2105 | ||
2106 | for (dnode_t *dnode = | |
2107 | dict_first(circuit->area->lspdb[level - 1]); | |
2108 | dnode; dnode = dict_next(circuit->area->lspdb[level - 1], | |
2109 | dnode)) { | |
2110 | struct isis_lsp *lsp = dnode_get(dnode); | |
2111 | ||
2112 | if (ISIS_CHECK_FLAG(lsp->SSNflags, circuit)) | |
2113 | isis_tlvs_add_lsp_entry(tlvs, lsp); | |
eb5d44eb | 2114 | |
17c9dcd5 CF |
2115 | if (tlvs->lsp_entries.count == num_lsps) |
2116 | break; | |
2117 | } | |
2118 | ||
2119 | if (!tlvs->lsp_entries.count) { | |
2120 | isis_free_tlvs(tlvs); | |
d62a17ae | 2121 | return ISIS_OK; |
2122 | } | |
2123 | ||
17c9dcd5 CF |
2124 | stream_set_endp(circuit->snd_stream, tlv_start); |
2125 | if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, | |
af8ac8f9 | 2126 | false, false)) { |
17c9dcd5 CF |
2127 | isis_free_tlvs(tlvs); |
2128 | return ISIS_WARNING; | |
d62a17ae | 2129 | } |
2130 | ||
2131 | if (isis->debugs & DEBUG_SNP_PACKETS) { | |
2132 | zlog_debug( | |
2133 | "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd", | |
2134 | circuit->area->area_tag, level, | |
2135 | circuit->interface->name, | |
2136 | stream_get_endp(circuit->snd_stream)); | |
17c9dcd5 CF |
2137 | log_multiline(LOG_DEBUG, " ", "%s", |
2138 | isis_format_tlvs(tlvs)); | |
d62a17ae | 2139 | if (isis->debugs & DEBUG_PACKET_DUMP) |
2140 | zlog_dump_data( | |
2141 | STREAM_DATA(circuit->snd_stream), | |
2142 | stream_get_endp(circuit->snd_stream)); | |
2143 | } | |
2144 | ||
39bb53d6 | 2145 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
17c9dcd5 | 2146 | int retval = circuit->tx(circuit, level); |
d62a17ae | 2147 | if (retval != ISIS_OK) { |
1a7ecb96 | 2148 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
2149 | "ISIS-Snp (%s): Send L%d PSNP on %s failed", |
2150 | circuit->area->area_tag, level, | |
2151 | circuit->interface->name); | |
17c9dcd5 | 2152 | isis_free_tlvs(tlvs); |
d62a17ae | 2153 | return retval; |
2154 | } | |
2155 | ||
2156 | /* | |
2157 | * sending succeeded, we can clear SSN flags of this circuit | |
2158 | * for the LSPs in list | |
2159 | */ | |
17c9dcd5 CF |
2160 | struct isis_lsp_entry *entry_head; |
2161 | entry_head = (struct isis_lsp_entry *)tlvs->lsp_entries.head; | |
2162 | for (struct isis_lsp_entry *entry = entry_head; entry; | |
2163 | entry = entry->next) | |
2164 | ISIS_CLEAR_FLAG(entry->lsp->SSNflags, circuit); | |
2165 | isis_free_tlvs(tlvs); | |
d62a17ae | 2166 | } |
2167 | ||
17c9dcd5 | 2168 | return ISIS_OK; |
eb5d44eb | 2169 | } |
2170 | ||
d62a17ae | 2171 | int send_l1_psnp(struct thread *thread) |
eb5d44eb | 2172 | { |
2173 | ||
d62a17ae | 2174 | struct isis_circuit *circuit; |
2175 | int retval = ISIS_OK; | |
eb5d44eb | 2176 | |
d62a17ae | 2177 | circuit = THREAD_ARG(thread); |
2178 | assert(circuit); | |
eb5d44eb | 2179 | |
d62a17ae | 2180 | circuit->t_send_psnp[0] = NULL; |
eb5d44eb | 2181 | |
d62a17ae | 2182 | send_psnp(1, circuit); |
2183 | /* set next timer thread */ | |
2184 | thread_add_timer(master, send_l1_psnp, circuit, | |
2185 | isis_jitter(circuit->psnp_interval[0], PSNP_JITTER), | |
2186 | &circuit->t_send_psnp[0]); | |
eb5d44eb | 2187 | |
d62a17ae | 2188 | return retval; |
eb5d44eb | 2189 | } |
2190 | ||
2191 | /* | |
2192 | * 7.3.15.4 action on expiration of partial SNP interval | |
2193 | * level 2 | |
2194 | */ | |
d62a17ae | 2195 | int send_l2_psnp(struct thread *thread) |
eb5d44eb | 2196 | { |
d62a17ae | 2197 | struct isis_circuit *circuit; |
2198 | int retval = ISIS_OK; | |
eb5d44eb | 2199 | |
d62a17ae | 2200 | circuit = THREAD_ARG(thread); |
2201 | assert(circuit); | |
eb5d44eb | 2202 | |
d62a17ae | 2203 | circuit->t_send_psnp[1] = NULL; |
eb5d44eb | 2204 | |
d62a17ae | 2205 | send_psnp(2, circuit); |
eb5d44eb | 2206 | |
d62a17ae | 2207 | /* set next timer thread */ |
2208 | thread_add_timer(master, send_l2_psnp, circuit, | |
2209 | isis_jitter(circuit->psnp_interval[1], PSNP_JITTER), | |
2210 | &circuit->t_send_psnp[1]); | |
eb5d44eb | 2211 | |
d62a17ae | 2212 | return retval; |
eb5d44eb | 2213 | } |
2214 | ||
eb5d44eb | 2215 | /* |
2216 | * ISO 10589 - 7.3.14.3 | |
2217 | */ | |
161fa356 CF |
2218 | void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp, |
2219 | enum isis_tx_type tx_type) | |
eb5d44eb | 2220 | { |
d62a17ae | 2221 | int clear_srm = 1; |
2222 | int retval = ISIS_OK; | |
2223 | ||
d62a17ae | 2224 | if (circuit->state != C_STATE_UP || circuit->is_passive == 1) |
2225 | goto out; | |
2226 | ||
2227 | /* | |
2228 | * Do not send if levels do not match | |
2229 | */ | |
2230 | if (!(lsp->level & circuit->is_type)) | |
2231 | goto out; | |
2232 | ||
2233 | /* | |
2234 | * Do not send if we do not have adjacencies in state up on the circuit | |
2235 | */ | |
2236 | if (circuit->upadjcount[lsp->level - 1] == 0) | |
2237 | goto out; | |
2238 | ||
2239 | /* stream_copy will assert and stop program execution if LSP is larger | |
2240 | * than | |
2241 | * the circuit's MTU. So handle and log this case here. */ | |
2242 | if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) { | |
af4c2728 | 2243 | flog_err( |
1a7ecb96 | 2244 | EC_ISIS_PACKET, |
af8ac8f9 CF |
2245 | "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32 |
2246 | ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16 | |
2247 | "s on %s. LSP Size is %zu while interface stream size is %zu.", | |
d62a17ae | 2248 | circuit->area->area_tag, lsp->level, |
af8ac8f9 CF |
2249 | rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno, |
2250 | lsp->hdr.checksum, lsp->hdr.rem_lifetime, | |
d62a17ae | 2251 | circuit->interface->name, stream_get_endp(lsp->pdu), |
2252 | stream_get_size(circuit->snd_stream)); | |
56e22fb6 EDP |
2253 | #ifndef FABRICD |
2254 | /* send a northbound notification */ | |
2255 | isis_notif_lsp_too_large(circuit, stream_get_endp(lsp->pdu), | |
2256 | rawlspid_print(lsp->hdr.lsp_id)); | |
2257 | #endif /* ifndef FABRICD */ | |
d62a17ae | 2258 | if (isis->debugs & DEBUG_PACKET_DUMP) |
2259 | zlog_dump_data(STREAM_DATA(lsp->pdu), | |
2260 | stream_get_endp(lsp->pdu)); | |
2261 | retval = ISIS_ERROR; | |
2262 | goto out; | |
2263 | } | |
eb5d44eb | 2264 | |
d62a17ae | 2265 | /* copy our lsp to the send buffer */ |
2266 | stream_copy(circuit->snd_stream, lsp->pdu); | |
2267 | ||
1cbd5b37 CF |
2268 | if (tx_type == TX_LSP_CIRCUIT_SCOPED) { |
2269 | stream_putc_at(circuit->snd_stream, 4, FS_LINK_STATE); | |
89cdc4df RM |
2270 | stream_putc_at(circuit->snd_stream, 7, |
2271 | L2_CIRCUIT_FLOODING_SCOPE); | |
1cbd5b37 CF |
2272 | } |
2273 | ||
d62a17ae | 2274 | if (isis->debugs & DEBUG_UPDATE_PACKETS) { |
161fa356 | 2275 | zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32 |
af8ac8f9 CF |
2276 | ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16 |
2277 | "s on %s", | |
161fa356 CF |
2278 | circuit->area->area_tag, |
2279 | (tx_type == TX_LSP_CIRCUIT_SCOPED) | |
2280 | ? "Circuit scoped " : "", | |
2281 | lsp->level, | |
af8ac8f9 CF |
2282 | rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno, |
2283 | lsp->hdr.checksum, lsp->hdr.rem_lifetime, | |
2284 | circuit->interface->name); | |
d62a17ae | 2285 | if (isis->debugs & DEBUG_PACKET_DUMP) |
2286 | zlog_dump_data(STREAM_DATA(circuit->snd_stream), | |
2287 | stream_get_endp(circuit->snd_stream)); | |
2288 | } | |
3f045a08 | 2289 | |
39bb53d6 CF |
2290 | uint8_t pdu_type = (tx_type == TX_LSP_CIRCUIT_SCOPED) ? FS_LINK_STATE |
2291 | : (lsp->level == ISIS_LEVEL1) ? L1_LINK_STATE | |
2292 | : L2_LINK_STATE; | |
2293 | ||
d62a17ae | 2294 | clear_srm = 0; |
39bb53d6 | 2295 | pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type); |
d62a17ae | 2296 | retval = circuit->tx(circuit, lsp->level); |
2297 | if (retval != ISIS_OK) { | |
1a7ecb96 | 2298 | flog_err(EC_ISIS_PACKET, |
1c50c1c0 QY |
2299 | "ISIS-Upd (%s): Send L%d LSP on %s failed %s", |
2300 | circuit->area->area_tag, lsp->level, | |
2301 | circuit->interface->name, | |
2302 | (retval == ISIS_WARNING) ? "temporarily" | |
2303 | : "permanently"); | |
d62a17ae | 2304 | } |
f390d2c7 | 2305 | |
cfd1f27b | 2306 | out: |
d62a17ae | 2307 | if (clear_srm |
2308 | || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST) | |
2309 | || (retval != ISIS_OK && retval != ISIS_WARNING)) { | |
2310 | /* SRM flag will trigger retransmission. We will not retransmit | |
2311 | * if we | |
2312 | * encountered a fatal error. | |
2313 | * On success, they should only be cleared if it's a broadcast | |
2314 | * circuit. | |
2315 | * On a P2P circuit, we will wait for the ack from the neighbor | |
2316 | * to clear | |
2317 | * the fag. | |
2318 | */ | |
9b39405f | 2319 | isis_tx_queue_del(circuit->tx_queue, lsp); |
d62a17ae | 2320 | } |
f390d2c7 | 2321 | } |