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