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