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