]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_pdu.c | |
3 | * PDU processing | |
4 | * | |
5 | * Copyright (C) 2001,2002 Sampo Saaristo | |
6 | * Tampere University of Technology | |
7 | * Institute of Communications Engineering | |
8 | * | |
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) | |
12 | * any later version. | |
13 | * | |
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 | |
17 | * more details. | |
18 | ||
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
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" | |
39 | #include "isisd/include-netbsd/iso.h" | |
40 | #include "isisd/isis_constants.h" | |
41 | #include "isisd/isis_common.h" | |
3f045a08 | 42 | #include "isisd/isis_flags.h" |
eb5d44eb | 43 | #include "isisd/isis_adjacency.h" |
44 | #include "isisd/isis_circuit.h" | |
45 | #include "isisd/isis_network.h" | |
46 | #include "isisd/isis_misc.h" | |
47 | #include "isisd/isis_dr.h" | |
eb5d44eb | 48 | #include "isisd/isis_tlv.h" |
49 | #include "isisd/isisd.h" | |
50 | #include "isisd/isis_dynhn.h" | |
51 | #include "isisd/isis_lsp.h" | |
52 | #include "isisd/isis_pdu.h" | |
53 | #include "isisd/iso_checksum.h" | |
54 | #include "isisd/isis_csm.h" | |
55 | #include "isisd/isis_events.h" | |
f8c06e2c | 56 | #include "isisd/isis_te.h" |
eb5d44eb | 57 | |
eb5d44eb | 58 | #define ISIS_MINIMUM_FIXED_HDR_LEN 15 |
f390d2c7 | 59 | #define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */ |
eb5d44eb | 60 | |
61 | #ifndef PNBBY | |
62 | #define PNBBY 8 | |
63 | #endif /* PNBBY */ | |
64 | ||
65 | /* Utility mask array. */ | |
bdcf8f59 | 66 | static const u_char maskbit[] = { |
eb5d44eb | 67 | 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff |
68 | }; | |
69 | ||
70 | /* | |
71 | * HELPER FUNCS | |
72 | */ | |
73 | ||
74 | /* | |
75 | * Compares two sets of area addresses | |
76 | */ | |
f390d2c7 | 77 | static int |
eb5d44eb | 78 | area_match (struct list *left, struct list *right) |
79 | { | |
80 | struct area_addr *addr1, *addr2; | |
3fdb2dd9 | 81 | struct listnode *node1, *node2; |
eb5d44eb | 82 | |
3fdb2dd9 | 83 | for (ALL_LIST_ELEMENTS_RO (left, node1, addr1)) |
f390d2c7 | 84 | { |
3fdb2dd9 | 85 | for (ALL_LIST_ELEMENTS_RO (right, node2, addr2)) |
f390d2c7 | 86 | { |
87 | if (addr1->addr_len == addr2->addr_len && | |
88 | !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len)) | |
89 | return 1; /* match */ | |
eb5d44eb | 90 | } |
91 | } | |
92 | ||
f390d2c7 | 93 | return 0; /* mismatch */ |
eb5d44eb | 94 | } |
95 | ||
96 | /* | |
97 | * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() ) | |
98 | * param ip1 the IS interface ip address structure | |
99 | * param ip2 the IIH's ip address | |
100 | * return 0 the IIH's IP is not in the IS's subnetwork | |
101 | * 1 the IIH's IP is in the IS's subnetwork | |
102 | */ | |
92365889 | 103 | static int |
f390d2c7 | 104 | ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2) |
eb5d44eb | 105 | { |
106 | u_char *addr1, *addr2; | |
53c997c9 | 107 | int shift, offset, offsetloop; |
eb5d44eb | 108 | int len; |
f390d2c7 | 109 | |
110 | addr1 = (u_char *) & ip1->prefix.s_addr; | |
111 | addr2 = (u_char *) & ip2->s_addr; | |
eb5d44eb | 112 | len = ip1->prefixlen; |
113 | ||
114 | shift = len % PNBBY; | |
53c997c9 | 115 | offsetloop = offset = len / PNBBY; |
eb5d44eb | 116 | |
53c997c9 | 117 | while (offsetloop--) |
118 | if (addr1[offsetloop] != addr2[offsetloop]) | |
119 | return 0; | |
eb5d44eb | 120 | |
f390d2c7 | 121 | if (shift) |
53c997c9 | 122 | if (maskbit[shift] & (addr1[offset] ^ addr2[offset])) |
123 | return 0; | |
eb5d44eb | 124 | |
f390d2c7 | 125 | return 1; /* match */ |
126 | } | |
eb5d44eb | 127 | |
128 | /* | |
129 | * Compares two set of ip addresses | |
130 | * param left the local interface's ip addresses | |
131 | * param right the iih interface's ip address | |
132 | * return 0 no match; | |
133 | * 1 match; | |
134 | */ | |
f390d2c7 | 135 | static int |
eb5d44eb | 136 | ip_match (struct list *left, struct list *right) |
137 | { | |
138 | struct prefix_ipv4 *ip1; | |
139 | struct in_addr *ip2; | |
3fdb2dd9 | 140 | struct listnode *node1, *node2; |
eb5d44eb | 141 | |
e082ac1d | 142 | if ((left == NULL) || (right == NULL)) |
143 | return 0; | |
144 | ||
3fdb2dd9 | 145 | for (ALL_LIST_ELEMENTS_RO (left, node1, ip1)) |
f390d2c7 | 146 | { |
3fdb2dd9 | 147 | for (ALL_LIST_ELEMENTS_RO (right, node2, ip2)) |
f390d2c7 | 148 | { |
149 | if (ip_same_subnet (ip1, ip2)) | |
150 | { | |
151 | return 1; /* match */ | |
152 | } | |
eb5d44eb | 153 | } |
f390d2c7 | 154 | |
eb5d44eb | 155 | } |
156 | return 0; | |
157 | } | |
158 | ||
159 | /* | |
160 | * Checks whether we should accept a PDU of given level | |
161 | */ | |
162 | static int | |
163 | accept_level (int level, int circuit_t) | |
164 | { | |
f390d2c7 | 165 | int retval = ((circuit_t & level) == level); /* simple approach */ |
eb5d44eb | 166 | |
167 | return retval; | |
168 | } | |
169 | ||
3f045a08 JB |
170 | /* |
171 | * Verify authentication information | |
172 | * Support cleartext and HMAC MD5 authentication | |
173 | */ | |
174 | static int | |
175 | authentication_check (struct isis_passwd *remote, struct isis_passwd *local, | |
176 | struct stream *stream, uint32_t auth_tlv_offset) | |
eb5d44eb | 177 | { |
3f045a08 JB |
178 | unsigned char digest[ISIS_AUTH_MD5_SIZE]; |
179 | ||
180 | /* Auth fail () - passwd type mismatch */ | |
181 | if (local->type != remote->type) | |
182 | return ISIS_ERROR; | |
183 | ||
184 | switch (local->type) | |
185 | { | |
186 | /* No authentication required */ | |
187 | case ISIS_PASSWD_TYPE_UNUSED: | |
188 | break; | |
189 | ||
190 | /* Cleartext (ISO 10589) */ | |
191 | case ISIS_PASSWD_TYPE_CLEARTXT: | |
192 | /* Auth fail () - passwd len mismatch */ | |
193 | if (remote->len != local->len) | |
194 | return ISIS_ERROR; | |
195 | return memcmp (local->passwd, remote->passwd, local->len); | |
196 | ||
197 | /* HMAC MD5 (RFC 3567) */ | |
198 | case ISIS_PASSWD_TYPE_HMAC_MD5: | |
199 | /* Auth fail () - passwd len mismatch */ | |
200 | if (remote->len != ISIS_AUTH_MD5_SIZE) | |
201 | return ISIS_ERROR; | |
202 | /* Set the authentication value to 0 before the check */ | |
203 | memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0, | |
204 | ISIS_AUTH_MD5_SIZE); | |
205 | /* Compute the digest */ | |
206 | hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream), | |
207 | (unsigned char *) &(local->passwd), local->len, | |
f2bce9a5 | 208 | (unsigned char *) &digest); |
3f045a08 JB |
209 | /* Copy back the authentication value after the check */ |
210 | memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3, | |
211 | remote->passwd, ISIS_AUTH_MD5_SIZE); | |
212 | return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE); | |
213 | ||
214 | default: | |
215 | zlog_err ("Unsupported authentication type"); | |
216 | return ISIS_ERROR; | |
217 | } | |
218 | ||
219 | /* Authentication pass when no authentication is configured */ | |
220 | return ISIS_OK; | |
221 | } | |
222 | ||
223 | static int | |
224 | lsp_authentication_check (struct stream *stream, struct isis_area *area, | |
225 | int level, struct isis_passwd *passwd) | |
226 | { | |
227 | struct isis_link_state_hdr *hdr; | |
228 | uint32_t expected = 0, found = 0, auth_tlv_offset = 0; | |
e38e0df0 | 229 | uint16_t checksum, rem_lifetime, pdu_len; |
3f045a08 JB |
230 | struct tlvs tlvs; |
231 | int retval = ISIS_OK; | |
232 | ||
233 | hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream)); | |
e38e0df0 | 234 | pdu_len = ntohs (hdr->pdu_len); |
3f045a08 JB |
235 | expected |= TLVFLAG_AUTH_INFO; |
236 | auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN; | |
237 | retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN, | |
e38e0df0 | 238 | pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN, |
3f045a08 JB |
239 | &expected, &found, &tlvs, &auth_tlv_offset); |
240 | ||
241 | if (retval != ISIS_OK) | |
242 | { | |
243 | zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, " | |
244 | "cksum 0x%04x, lifetime %us, len %u", | |
245 | area->area_tag, level, rawlspid_print (hdr->lsp_id), | |
246 | ntohl (hdr->seq_num), ntohs (hdr->checksum), | |
e38e0df0 | 247 | ntohs (hdr->rem_lifetime), pdu_len); |
3f045a08 JB |
248 | if ((isis->debugs & DEBUG_UPDATE_PACKETS) && |
249 | (isis->debugs & DEBUG_PACKET_DUMP)) | |
250 | zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream)); | |
251 | return retval; | |
252 | } | |
253 | ||
254 | if (!(found & TLVFLAG_AUTH_INFO)) | |
f390d2c7 | 255 | { |
3f045a08 JB |
256 | zlog_err ("No authentication tlv in LSP"); |
257 | return ISIS_ERROR; | |
f390d2c7 | 258 | } |
3f045a08 JB |
259 | |
260 | if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT && | |
261 | tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5) | |
f390d2c7 | 262 | { |
3f045a08 JB |
263 | zlog_err ("Unknown authentication type in LSP"); |
264 | return ISIS_ERROR; | |
f390d2c7 | 265 | } |
3f045a08 JB |
266 | |
267 | /* | |
268 | * RFC 5304 set checksum and remaining lifetime to zero before | |
269 | * verification and reset to old values after verification. | |
270 | */ | |
271 | checksum = hdr->checksum; | |
272 | rem_lifetime = hdr->rem_lifetime; | |
273 | hdr->checksum = 0; | |
274 | hdr->rem_lifetime = 0; | |
275 | retval = authentication_check (&tlvs.auth_info, passwd, stream, | |
276 | auth_tlv_offset); | |
277 | hdr->checksum = checksum; | |
278 | hdr->rem_lifetime = rem_lifetime; | |
279 | ||
280 | return retval; | |
eb5d44eb | 281 | } |
282 | ||
283 | /* | |
284 | * Processing helper functions | |
285 | */ | |
3f045a08 JB |
286 | static void |
287 | del_addr (void *val) | |
288 | { | |
289 | XFREE (MTYPE_ISIS_TMP, val); | |
290 | } | |
291 | ||
292 | static void | |
293 | tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) | |
294 | { | |
295 | struct listnode *node; | |
296 | struct area_addr *area_addr, *malloced; | |
297 | ||
298 | if (adj->area_addrs) | |
299 | { | |
300 | adj->area_addrs->del = del_addr; | |
301 | list_delete (adj->area_addrs); | |
302 | } | |
303 | adj->area_addrs = list_new (); | |
304 | if (tlvs->area_addrs) | |
305 | { | |
306 | for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr)) | |
307 | { | |
308 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr)); | |
309 | memcpy (malloced, area_addr, sizeof (struct area_addr)); | |
310 | listnode_add (adj->area_addrs, malloced); | |
311 | } | |
312 | } | |
313 | } | |
314 | ||
655071f4 | 315 | static int |
f390d2c7 | 316 | tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj) |
eb5d44eb | 317 | { |
318 | int i; | |
319 | struct nlpids *tlv_nlpids; | |
320 | ||
f390d2c7 | 321 | if (tlvs->nlpids) |
322 | { | |
eb5d44eb | 323 | |
f390d2c7 | 324 | tlv_nlpids = tlvs->nlpids; |
655071f4 DL |
325 | if (tlv_nlpids->count > array_size (adj->nlpids.nlpids)) |
326 | return 1; | |
eb5d44eb | 327 | |
f390d2c7 | 328 | adj->nlpids.count = tlv_nlpids->count; |
eb5d44eb | 329 | |
f390d2c7 | 330 | for (i = 0; i < tlv_nlpids->count; i++) |
331 | { | |
332 | adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i]; | |
333 | } | |
eb5d44eb | 334 | } |
655071f4 | 335 | return 0; |
eb5d44eb | 336 | } |
337 | ||
92365889 | 338 | static void |
f390d2c7 | 339 | tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) |
eb5d44eb | 340 | { |
3fdb2dd9 | 341 | struct listnode *node; |
eb5d44eb | 342 | struct in_addr *ipv4_addr, *malloced; |
343 | ||
f390d2c7 | 344 | if (adj->ipv4_addrs) |
345 | { | |
3f045a08 | 346 | adj->ipv4_addrs->del = del_addr; |
f390d2c7 | 347 | list_delete (adj->ipv4_addrs); |
348 | } | |
eb5d44eb | 349 | adj->ipv4_addrs = list_new (); |
f390d2c7 | 350 | if (tlvs->ipv4_addrs) |
351 | { | |
3fdb2dd9 | 352 | for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr)) |
f390d2c7 | 353 | { |
354 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr)); | |
355 | memcpy (malloced, ipv4_addr, sizeof (struct in_addr)); | |
356 | listnode_add (adj->ipv4_addrs, malloced); | |
357 | } | |
eb5d44eb | 358 | } |
eb5d44eb | 359 | } |
360 | ||
361 | #ifdef HAVE_IPV6 | |
92365889 | 362 | static void |
f390d2c7 | 363 | tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) |
eb5d44eb | 364 | { |
3fdb2dd9 | 365 | struct listnode *node; |
eb5d44eb | 366 | struct in6_addr *ipv6_addr, *malloced; |
367 | ||
f390d2c7 | 368 | if (adj->ipv6_addrs) |
369 | { | |
3f045a08 | 370 | adj->ipv6_addrs->del = del_addr; |
f390d2c7 | 371 | list_delete (adj->ipv6_addrs); |
372 | } | |
eb5d44eb | 373 | adj->ipv6_addrs = list_new (); |
f390d2c7 | 374 | if (tlvs->ipv6_addrs) |
375 | { | |
3fdb2dd9 | 376 | for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr)) |
f390d2c7 | 377 | { |
378 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr)); | |
379 | memcpy (malloced, ipv6_addr, sizeof (struct in6_addr)); | |
380 | listnode_add (adj->ipv6_addrs, malloced); | |
381 | } | |
eb5d44eb | 382 | } |
eb5d44eb | 383 | |
384 | } | |
385 | #endif /* HAVE_IPV6 */ | |
386 | ||
eb5d44eb | 387 | /* |
388 | * RECEIVE SIDE | |
389 | */ | |
390 | ||
391 | /* | |
392 | * Process P2P IIH | |
393 | * ISO - 10589 | |
394 | * Section 8.2.5 - Receiving point-to-point IIH PDUs | |
395 | * | |
396 | */ | |
397 | static int | |
398 | process_p2p_hello (struct isis_circuit *circuit) | |
399 | { | |
400 | int retval = ISIS_OK; | |
401 | struct isis_p2p_hello_hdr *hdr; | |
402 | struct isis_adjacency *adj; | |
3f045a08 | 403 | u_int32_t expected = 0, found = 0, auth_tlv_offset = 0; |
e38e0df0 | 404 | uint16_t pdu_len; |
eb5d44eb | 405 | struct tlvs tlvs; |
28a8cfcb | 406 | int v4_usable = 0, v6_usable = 0; |
eb5d44eb | 407 | |
3f045a08 JB |
408 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
409 | { | |
410 | zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u", | |
411 | circuit->area->area_tag, circuit->interface->name, | |
412 | circuit_t2string (circuit->is_type), circuit->circuit_id); | |
413 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
414 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), | |
415 | stream_get_endp (circuit->rcv_stream)); | |
416 | } | |
417 | ||
418 | if (circuit->circ_type != CIRCUIT_T_P2P) | |
419 | { | |
420 | zlog_warn ("p2p hello on non p2p circuit"); | |
421 | return ISIS_WARNING; | |
422 | } | |
423 | ||
f390d2c7 | 424 | if ((stream_get_endp (circuit->rcv_stream) - |
425 | stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN) | |
426 | { | |
427 | zlog_warn ("Packet too short"); | |
428 | return ISIS_WARNING; | |
429 | } | |
eb5d44eb | 430 | |
431 | /* 8.2.5.1 PDU acceptance tests */ | |
432 | ||
433 | /* 8.2.5.1 a) external domain untrue */ | |
434 | /* FIXME: not useful at all? */ | |
435 | ||
436 | /* 8.2.5.1 b) ID Length mismatch */ | |
437 | /* checked at the handle_pdu */ | |
438 | ||
439 | /* 8.2.5.2 IIH PDU Processing */ | |
440 | ||
441 | /* 8.2.5.2 a) 1) Maximum Area Addresses */ | |
442 | /* Already checked, and can also be ommited */ | |
443 | ||
444 | /* | |
445 | * Get the header | |
446 | */ | |
f390d2c7 | 447 | hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream); |
e38e0df0 | 448 | pdu_len = ntohs (hdr->pdu_len); |
eb5d44eb | 449 | |
a22ab5a5 AS |
450 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) || |
451 | pdu_len > ISO_MTU(circuit) || | |
e38e0df0 | 452 | pdu_len > stream_get_endp (circuit->rcv_stream)) |
f390d2c7 | 453 | { |
3f045a08 JB |
454 | zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with " |
455 | "invalid pdu length %d", | |
e38e0df0 | 456 | circuit->area->area_tag, circuit->interface->name, pdu_len); |
3f045a08 | 457 | return ISIS_WARNING; |
f390d2c7 | 458 | } |
eb5d44eb | 459 | |
e38e0df0 SV |
460 | /* |
461 | * Set the stream endp to PDU length, ignoring additional padding | |
462 | * introduced by transport chips. | |
463 | */ | |
464 | if (pdu_len < stream_get_endp (circuit->rcv_stream)) | |
465 | stream_set_endp (circuit->rcv_stream, pdu_len); | |
466 | ||
467 | stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN); | |
468 | ||
eb5d44eb | 469 | /* |
470 | * Lets get the TLVS now | |
471 | */ | |
472 | expected |= TLVFLAG_AREA_ADDRS; | |
473 | expected |= TLVFLAG_AUTH_INFO; | |
474 | expected |= TLVFLAG_NLPID; | |
475 | expected |= TLVFLAG_IPV4_ADDR; | |
476 | expected |= TLVFLAG_IPV6_ADDR; | |
477 | ||
3f045a08 | 478 | auth_tlv_offset = stream_get_getp (circuit->rcv_stream); |
eb5d44eb | 479 | retval = parse_tlvs (circuit->area->area_tag, |
480 | STREAM_PNT (circuit->rcv_stream), | |
e38e0df0 SV |
481 | pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN, |
482 | &expected, &found, &tlvs, &auth_tlv_offset); | |
f390d2c7 | 483 | |
484 | if (retval > ISIS_WARNING) | |
485 | { | |
3f045a08 | 486 | zlog_warn ("parse_tlvs() failed"); |
f390d2c7 | 487 | free_tlvs (&tlvs); |
488 | return retval; | |
489 | }; | |
eb5d44eb | 490 | |
3f045a08 JB |
491 | if (!(found & TLVFLAG_AREA_ADDRS)) |
492 | { | |
493 | zlog_warn ("No Area addresses TLV in P2P IS to IS hello"); | |
494 | free_tlvs (&tlvs); | |
495 | return ISIS_WARNING; | |
496 | } | |
497 | ||
b72f345d DL |
498 | if (!(found & TLVFLAG_NLPID)) |
499 | { | |
500 | zlog_warn ("No supported protocols TLV in P2P IS to IS hello"); | |
501 | free_tlvs (&tlvs); | |
502 | return ISIS_WARNING; | |
503 | } | |
504 | ||
eb5d44eb | 505 | /* 8.2.5.1 c) Authentication */ |
f390d2c7 | 506 | if (circuit->passwd.type) |
507 | { | |
508 | if (!(found & TLVFLAG_AUTH_INFO) || | |
3f045a08 JB |
509 | authentication_check (&tlvs.auth_info, &circuit->passwd, |
510 | circuit->rcv_stream, auth_tlv_offset)) | |
511 | { | |
512 | isis_event_auth_failure (circuit->area->area_tag, | |
513 | "P2P hello authentication failure", | |
514 | hdr->source_id); | |
515 | free_tlvs (&tlvs); | |
516 | return ISIS_OK; | |
517 | } | |
eb5d44eb | 518 | } |
eb5d44eb | 519 | |
3f045a08 JB |
520 | /* |
521 | * check if it's own interface ip match iih ip addrs | |
522 | */ | |
28a8cfcb DL |
523 | if (found & TLVFLAG_IPV4_ADDR) |
524 | { | |
525 | if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs)) | |
526 | v4_usable = 1; | |
527 | else | |
528 | zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap " | |
529 | "in P2P IIH from %s\n", circuit->interface->name); | |
530 | } | |
531 | #ifndef HAVE_IPV6 | |
532 | else /* !(found & TLVFLAG_IPV4_ADDR) */ | |
533 | zlog_warn ("ISIS-Adj: no IPv4 in P2P IIH from %s " | |
534 | "(this isisd has no IPv6)\n", circuit->interface->name); | |
535 | ||
536 | #else | |
537 | if (found & TLVFLAG_IPV6_ADDR) | |
538 | { | |
539 | /* TBA: check that we have a linklocal ourselves? */ | |
540 | struct listnode *node; | |
ad2f92b6 | 541 | struct in6_addr *ip; |
28a8cfcb DL |
542 | for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip)) |
543 | if (IN6_IS_ADDR_LINKLOCAL (ip)) | |
544 | { | |
545 | v6_usable = 1; | |
546 | break; | |
547 | } | |
548 | ||
549 | if (!v6_usable) | |
550 | zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local " | |
551 | "in P2P IIH from %s\n", circuit->interface->name); | |
552 | } | |
553 | ||
554 | if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR))) | |
555 | zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n", | |
556 | circuit->interface->name); | |
557 | #endif | |
558 | ||
559 | if (!v6_usable && !v4_usable) | |
3f045a08 | 560 | { |
3f045a08 JB |
561 | free_tlvs (&tlvs); |
562 | return ISIS_WARNING; | |
563 | } | |
564 | ||
0908a2fd AN |
565 | /* |
566 | * it's own p2p IIH PDU - discard | |
567 | */ | |
568 | if (!memcmp (hdr->source_id, isis->sysid, ISIS_SYS_ID_LEN)) | |
569 | { | |
570 | zlog_warn ("ISIS-Adj (%s): it's own IIH PDU - discarded", | |
571 | circuit->area->area_tag); | |
572 | free_tlvs (&tlvs); | |
573 | return ISIS_WARNING; | |
574 | } | |
575 | ||
3f045a08 JB |
576 | /* |
577 | * My interpertation of the ISO, if no adj exists we will create one for | |
578 | * the circuit | |
579 | */ | |
580 | adj = circuit->u.p2p.neighbor; | |
793ec473 AN |
581 | /* If an adjacency exists, check it is with the source of the hello |
582 | * packets */ | |
583 | if (adj) | |
584 | { | |
585 | if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN)) | |
586 | { | |
587 | zlog_debug("hello source and adjacency do not match, set adj down\n"); | |
588 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist"); | |
589 | return 0; | |
590 | } | |
591 | } | |
3f045a08 JB |
592 | if (!adj || adj->level != hdr->circuit_t) |
593 | { | |
594 | if (!adj) | |
595 | { | |
596 | adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit); | |
597 | if (adj == NULL) | |
598 | return ISIS_ERROR; | |
599 | } | |
600 | else | |
601 | { | |
602 | adj->level = hdr->circuit_t; | |
603 | } | |
604 | circuit->u.p2p.neighbor = adj; | |
a2d2c0d2 AN |
605 | /* Build lsp with the new neighbor entry when a new |
606 | * adjacency is formed. Set adjacency circuit type to | |
607 | * IIH PDU header circuit type before lsp is regenerated | |
608 | * when an adjacency is up. This will result in the new | |
609 | * adjacency entry getting added to the lsp tlv neighbor list. | |
610 | */ | |
611 | adj->circuit_t = hdr->circuit_t; | |
3f045a08 JB |
612 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
613 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
614 | } | |
615 | ||
616 | /* 8.2.6 Monitoring point-to-point adjacencies */ | |
617 | adj->hold_time = ntohs (hdr->hold_time); | |
618 | adj->last_upd = time (NULL); | |
619 | ||
eb5d44eb | 620 | /* we do this now because the adj may not survive till the end... */ |
3f045a08 JB |
621 | tlvs_to_adj_area_addrs (&tlvs, adj); |
622 | ||
623 | /* which protocol are spoken ??? */ | |
b72f345d DL |
624 | if (tlvs_to_adj_nlpids (&tlvs, adj)) |
625 | { | |
626 | free_tlvs (&tlvs); | |
627 | return ISIS_WARNING; | |
628 | } | |
eb5d44eb | 629 | |
630 | /* we need to copy addresses to the adj */ | |
3f045a08 JB |
631 | if (found & TLVFLAG_IPV4_ADDR) |
632 | tlvs_to_adj_ipv4_addrs (&tlvs, adj); | |
eb5d44eb | 633 | |
f8c06e2c OD |
634 | /* Update MPLS TE Remote IP address parameter if possible */ |
635 | if (IS_MPLS_TE(isisMplsTE) && circuit->mtc && IS_CIRCUIT_TE(circuit->mtc)) | |
636 | if (adj->ipv4_addrs != NULL && listcount(adj->ipv4_addrs) != 0) | |
637 | { | |
638 | struct in_addr *ip_addr; | |
639 | ip_addr = (struct in_addr *)listgetdata ((struct listnode *)listhead (adj->ipv4_addrs)); | |
640 | set_circuitparams_rmt_ipaddr (circuit->mtc, *ip_addr); | |
641 | } | |
642 | ||
eb5d44eb | 643 | #ifdef HAVE_IPV6 |
3f045a08 JB |
644 | if (found & TLVFLAG_IPV6_ADDR) |
645 | tlvs_to_adj_ipv6_addrs (&tlvs, adj); | |
eb5d44eb | 646 | #endif /* HAVE_IPV6 */ |
647 | ||
648 | /* lets take care of the expiry */ | |
f390d2c7 | 649 | THREAD_TIMER_OFF (adj->t_expire); |
650 | THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj, | |
651 | (long) adj->hold_time); | |
eb5d44eb | 652 | |
653 | /* 8.2.5.2 a) a match was detected */ | |
f390d2c7 | 654 | if (area_match (circuit->area->area_addrs, tlvs.area_addrs)) |
655 | { | |
656 | /* 8.2.5.2 a) 2) If the system is L1 - table 5 */ | |
657 | if (circuit->area->is_type == IS_LEVEL_1) | |
658 | { | |
659 | switch (hdr->circuit_t) | |
660 | { | |
661 | case IS_LEVEL_1: | |
662 | case IS_LEVEL_1_AND_2: | |
663 | if (adj->adj_state != ISIS_ADJ_UP) | |
664 | { | |
665 | /* (4) adj state up */ | |
666 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
667 | /* (5) adj usage level 1 */ | |
668 | adj->adj_usage = ISIS_ADJ_LEVEL1; | |
669 | } | |
670 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) | |
671 | { | |
672 | ; /* accept */ | |
673 | } | |
674 | break; | |
675 | case IS_LEVEL_2: | |
676 | if (adj->adj_state != ISIS_ADJ_UP) | |
677 | { | |
678 | /* (7) reject - wrong system type event */ | |
679 | zlog_warn ("wrongSystemType"); | |
3f045a08 | 680 | free_tlvs (&tlvs); |
f390d2c7 | 681 | return ISIS_WARNING; /* Reject */ |
682 | } | |
683 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) | |
684 | { | |
685 | /* (6) down - wrong system */ | |
686 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
687 | } | |
688 | break; | |
689 | } | |
690 | } | |
eb5d44eb | 691 | |
f390d2c7 | 692 | /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */ |
693 | if (circuit->area->is_type == IS_LEVEL_1_AND_2) | |
694 | { | |
695 | switch (hdr->circuit_t) | |
696 | { | |
697 | case IS_LEVEL_1: | |
698 | if (adj->adj_state != ISIS_ADJ_UP) | |
699 | { | |
700 | /* (6) adj state up */ | |
701 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
702 | /* (7) adj usage level 1 */ | |
703 | adj->adj_usage = ISIS_ADJ_LEVEL1; | |
704 | } | |
705 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) | |
706 | { | |
707 | ; /* accept */ | |
708 | } | |
709 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
710 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) | |
711 | { | |
712 | /* (8) down - wrong system */ | |
713 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
714 | } | |
715 | break; | |
716 | case IS_LEVEL_2: | |
717 | if (adj->adj_state != ISIS_ADJ_UP) | |
718 | { | |
719 | /* (6) adj state up */ | |
720 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
721 | /* (9) adj usage level 2 */ | |
722 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
723 | } | |
724 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || | |
725 | (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)) | |
726 | { | |
727 | /* (8) down - wrong system */ | |
728 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
729 | } | |
730 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) | |
731 | { | |
732 | ; /* Accept */ | |
733 | } | |
734 | break; | |
735 | case IS_LEVEL_1_AND_2: | |
736 | if (adj->adj_state != ISIS_ADJ_UP) | |
737 | { | |
738 | /* (6) adj state up */ | |
739 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
740 | /* (10) adj usage level 1 */ | |
741 | adj->adj_usage = ISIS_ADJ_LEVEL1AND2; | |
742 | } | |
743 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || | |
744 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) | |
745 | { | |
746 | /* (8) down - wrong system */ | |
747 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
748 | } | |
749 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) | |
750 | { | |
751 | ; /* Accept */ | |
752 | } | |
753 | break; | |
754 | } | |
755 | } | |
eb5d44eb | 756 | |
f390d2c7 | 757 | /* 8.2.5.2 a) 4) If the system is L2 - table 7 */ |
758 | if (circuit->area->is_type == IS_LEVEL_2) | |
759 | { | |
760 | switch (hdr->circuit_t) | |
761 | { | |
762 | case IS_LEVEL_1: | |
763 | if (adj->adj_state != ISIS_ADJ_UP) | |
764 | { | |
765 | /* (5) reject - wrong system type event */ | |
766 | zlog_warn ("wrongSystemType"); | |
3f045a08 | 767 | free_tlvs (&tlvs); |
f390d2c7 | 768 | return ISIS_WARNING; /* Reject */ |
769 | } | |
770 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
771 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) | |
772 | { | |
773 | /* (6) down - wrong system */ | |
774 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
775 | } | |
776 | break; | |
777 | case IS_LEVEL_1_AND_2: | |
778 | case IS_LEVEL_2: | |
779 | if (adj->adj_state != ISIS_ADJ_UP) | |
780 | { | |
781 | /* (7) adj state up */ | |
782 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
783 | /* (8) adj usage level 2 */ | |
784 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
785 | } | |
786 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) | |
787 | { | |
788 | /* (6) down - wrong system */ | |
789 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
790 | } | |
791 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) | |
792 | { | |
793 | ; /* Accept */ | |
794 | } | |
795 | break; | |
796 | } | |
797 | } | |
eb5d44eb | 798 | } |
eb5d44eb | 799 | /* 8.2.5.2 b) if no match was detected */ |
3f045a08 | 800 | else if (listcount (circuit->area->area_addrs) > 0) |
eb5d44eb | 801 | { |
f390d2c7 | 802 | if (circuit->area->is_type == IS_LEVEL_1) |
803 | { | |
804 | /* 8.2.5.2 b) 1) is_type L1 and adj is not up */ | |
805 | if (adj->adj_state != ISIS_ADJ_UP) | |
806 | { | |
807 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); | |
808 | /* 8.2.5.2 b) 2)is_type L1 and adj is up */ | |
809 | } | |
810 | else | |
811 | { | |
812 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, | |
813 | "Down - Area Mismatch"); | |
814 | } | |
815 | } | |
816 | /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */ | |
817 | else | |
818 | { | |
819 | switch (hdr->circuit_t) | |
820 | { | |
821 | case IS_LEVEL_1: | |
822 | if (adj->adj_state != ISIS_ADJ_UP) | |
823 | { | |
824 | /* (6) reject - Area Mismatch event */ | |
825 | zlog_warn ("AreaMismatch"); | |
3f045a08 | 826 | free_tlvs (&tlvs); |
f390d2c7 | 827 | return ISIS_WARNING; /* Reject */ |
828 | } | |
829 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) | |
830 | { | |
831 | /* (7) down - area mismatch */ | |
832 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); | |
833 | ||
834 | } | |
835 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
836 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) | |
837 | { | |
838 | /* (7) down - wrong system */ | |
839 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
840 | } | |
841 | break; | |
842 | case IS_LEVEL_1_AND_2: | |
843 | case IS_LEVEL_2: | |
844 | if (adj->adj_state != ISIS_ADJ_UP) | |
845 | { | |
846 | /* (8) adj state up */ | |
847 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
848 | /* (9) adj usage level 2 */ | |
849 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
850 | } | |
851 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) | |
852 | { | |
853 | /* (7) down - wrong system */ | |
854 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
855 | } | |
856 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) | |
857 | { | |
858 | if (hdr->circuit_t == IS_LEVEL_2) | |
859 | { | |
860 | /* (7) down - wrong system */ | |
861 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, | |
862 | "Wrong System"); | |
863 | } | |
864 | else | |
865 | { | |
866 | /* (7) down - area mismatch */ | |
867 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, | |
868 | "Area Mismatch"); | |
869 | } | |
870 | } | |
871 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) | |
872 | { | |
873 | ; /* Accept */ | |
874 | } | |
875 | break; | |
876 | } | |
877 | } | |
eb5d44eb | 878 | } |
3f045a08 JB |
879 | else |
880 | { | |
881 | /* down - area mismatch */ | |
882 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); | |
883 | } | |
eb5d44eb | 884 | /* 8.2.5.2 c) if the action was up - comparing circuit IDs */ |
885 | /* FIXME - Missing parts */ | |
886 | ||
eb5d44eb | 887 | /* some of my own understanding of the ISO, why the heck does |
888 | * it not say what should I change the system_type to... | |
889 | */ | |
f390d2c7 | 890 | switch (adj->adj_usage) |
891 | { | |
eb5d44eb | 892 | case ISIS_ADJ_LEVEL1: |
893 | adj->sys_type = ISIS_SYSTYPE_L1_IS; | |
894 | break; | |
895 | case ISIS_ADJ_LEVEL2: | |
896 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
897 | break; | |
898 | case ISIS_ADJ_LEVEL1AND2: | |
899 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
900 | break; | |
901 | case ISIS_ADJ_NONE: | |
902 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
903 | break; | |
f390d2c7 | 904 | } |
eb5d44eb | 905 | |
3f045a08 JB |
906 | |
907 | if (isis->debugs & DEBUG_ADJ_PACKETS) | |
908 | { | |
909 | zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s," | |
910 | " cir id %02d, length %d", | |
911 | circuit->area->area_tag, circuit->interface->name, | |
912 | circuit_t2string (circuit->is_type), | |
e38e0df0 | 913 | circuit->circuit_id, pdu_len); |
3f045a08 | 914 | } |
eb5d44eb | 915 | |
916 | free_tlvs (&tlvs); | |
917 | ||
918 | return retval; | |
919 | } | |
920 | ||
eb5d44eb | 921 | /* |
922 | * Process IS-IS LAN Level 1/2 Hello PDU | |
923 | */ | |
f390d2c7 | 924 | static int |
02e33d3e | 925 | process_lan_hello (int level, struct isis_circuit *circuit, const u_char *ssnpa) |
eb5d44eb | 926 | { |
927 | int retval = ISIS_OK; | |
928 | struct isis_lan_hello_hdr hdr; | |
929 | struct isis_adjacency *adj; | |
3f045a08 | 930 | u_int32_t expected = 0, found = 0, auth_tlv_offset = 0; |
eb5d44eb | 931 | struct tlvs tlvs; |
932 | u_char *snpa; | |
3fdb2dd9 | 933 | struct listnode *node; |
28a8cfcb | 934 | int v4_usable = 0, v6_usable = 0; |
eb5d44eb | 935 | |
3f045a08 JB |
936 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
937 | { | |
938 | zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, " | |
939 | "cirID %u", | |
940 | circuit->area->area_tag, level, circuit->interface->name, | |
941 | circuit_t2string (circuit->is_type), circuit->circuit_id); | |
942 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
943 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), | |
944 | stream_get_endp (circuit->rcv_stream)); | |
945 | } | |
946 | ||
947 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
948 | { | |
949 | zlog_warn ("lan hello on non broadcast circuit"); | |
950 | return ISIS_WARNING; | |
951 | } | |
952 | ||
f390d2c7 | 953 | if ((stream_get_endp (circuit->rcv_stream) - |
954 | stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN) | |
955 | { | |
956 | zlog_warn ("Packet too short"); | |
957 | return ISIS_WARNING; | |
958 | } | |
eb5d44eb | 959 | |
f390d2c7 | 960 | if (circuit->ext_domain) |
961 | { | |
529d65b3 | 962 | zlog_debug ("level %d LAN Hello received over circuit with " |
963 | "externalDomain = true", level); | |
f390d2c7 | 964 | return ISIS_WARNING; |
965 | } | |
eb5d44eb | 966 | |
3f045a08 | 967 | if (!accept_level (level, circuit->is_type)) |
f390d2c7 | 968 | { |
969 | if (isis->debugs & DEBUG_ADJ_PACKETS) | |
970 | { | |
529d65b3 | 971 | zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s", |
972 | circuit->area->area_tag, circuit->interface->name); | |
f390d2c7 | 973 | } |
974 | return ISIS_WARNING; | |
eb5d44eb | 975 | } |
eb5d44eb | 976 | |
977 | #if 0 | |
978 | /* Cisco's debug message compatability */ | |
f390d2c7 | 979 | if (!accept_level (level, circuit->area->is_type)) |
980 | { | |
981 | if (isis->debugs & DEBUG_ADJ_PACKETS) | |
982 | { | |
529d65b3 | 983 | zlog_debug ("ISIS-Adj (%s): is type mismatch", |
984 | circuit->area->area_tag); | |
f390d2c7 | 985 | } |
986 | return ISIS_WARNING; | |
eb5d44eb | 987 | } |
eb5d44eb | 988 | #endif |
989 | /* | |
990 | * Fill the header | |
991 | */ | |
992 | hdr.circuit_t = stream_getc (circuit->rcv_stream); | |
993 | stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN); | |
994 | hdr.hold_time = stream_getw (circuit->rcv_stream); | |
f390d2c7 | 995 | hdr.pdu_len = stream_getw (circuit->rcv_stream); |
996 | hdr.prio = stream_getc (circuit->rcv_stream); | |
eb5d44eb | 997 | stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1); |
998 | ||
a22ab5a5 AS |
999 | if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) || |
1000 | hdr.pdu_len > ISO_MTU(circuit) || | |
e38e0df0 | 1001 | hdr.pdu_len > stream_get_endp (circuit->rcv_stream)) |
f390d2c7 | 1002 | { |
3f045a08 JB |
1003 | zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with " |
1004 | "invalid pdu length %d", | |
1005 | circuit->area->area_tag, circuit->interface->name, | |
1006 | hdr.pdu_len); | |
e38e0df0 | 1007 | return ISIS_WARNING; |
3f045a08 JB |
1008 | } |
1009 | ||
e38e0df0 SV |
1010 | /* |
1011 | * Set the stream endp to PDU length, ignoring additional padding | |
1012 | * introduced by transport chips. | |
1013 | */ | |
1014 | if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream)) | |
1015 | stream_set_endp (circuit->rcv_stream, hdr.pdu_len); | |
1016 | ||
3f045a08 JB |
1017 | if (hdr.circuit_t != IS_LEVEL_1 && |
1018 | hdr.circuit_t != IS_LEVEL_2 && | |
1019 | hdr.circuit_t != IS_LEVEL_1_AND_2 && | |
1020 | (level & hdr.circuit_t) == 0) | |
1021 | { | |
1022 | zlog_err ("Level %d LAN Hello with Circuit Type %d", level, | |
1023 | hdr.circuit_t); | |
f390d2c7 | 1024 | return ISIS_ERROR; |
1025 | } | |
3f045a08 | 1026 | |
eb5d44eb | 1027 | /* |
1028 | * Then get the tlvs | |
1029 | */ | |
1030 | expected |= TLVFLAG_AUTH_INFO; | |
1031 | expected |= TLVFLAG_AREA_ADDRS; | |
1032 | expected |= TLVFLAG_LAN_NEIGHS; | |
1033 | expected |= TLVFLAG_NLPID; | |
1034 | expected |= TLVFLAG_IPV4_ADDR; | |
1035 | expected |= TLVFLAG_IPV6_ADDR; | |
1036 | ||
3f045a08 | 1037 | auth_tlv_offset = stream_get_getp (circuit->rcv_stream); |
eb5d44eb | 1038 | retval = parse_tlvs (circuit->area->area_tag, |
3f045a08 JB |
1039 | STREAM_PNT (circuit->rcv_stream), |
1040 | hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN, | |
1041 | &expected, &found, &tlvs, | |
1042 | &auth_tlv_offset); | |
eb5d44eb | 1043 | |
f390d2c7 | 1044 | if (retval > ISIS_WARNING) |
1045 | { | |
1046 | zlog_warn ("parse_tlvs() failed"); | |
1047 | goto out; | |
1048 | } | |
eb5d44eb | 1049 | |
f390d2c7 | 1050 | if (!(found & TLVFLAG_AREA_ADDRS)) |
1051 | { | |
1052 | zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello", | |
1053 | level); | |
eb5d44eb | 1054 | retval = ISIS_WARNING; |
1055 | goto out; | |
1056 | } | |
f390d2c7 | 1057 | |
b72f345d DL |
1058 | if (!(found & TLVFLAG_NLPID)) |
1059 | { | |
1060 | zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello", | |
1061 | level); | |
1062 | retval = ISIS_WARNING; | |
1063 | goto out; | |
1064 | } | |
1065 | ||
3f045a08 | 1066 | /* Verify authentication, either cleartext of HMAC MD5 */ |
f390d2c7 | 1067 | if (circuit->passwd.type) |
1068 | { | |
1069 | if (!(found & TLVFLAG_AUTH_INFO) || | |
3f045a08 JB |
1070 | authentication_check (&tlvs.auth_info, &circuit->passwd, |
1071 | circuit->rcv_stream, auth_tlv_offset)) | |
1072 | { | |
1073 | isis_event_auth_failure (circuit->area->area_tag, | |
1074 | "LAN hello authentication failure", | |
1075 | hdr.source_id); | |
1076 | retval = ISIS_WARNING; | |
1077 | goto out; | |
1078 | } | |
f390d2c7 | 1079 | } |
eb5d44eb | 1080 | |
19f78ceb DL |
1081 | if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN)) |
1082 | { | |
1083 | zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s", | |
1084 | circuit->area->area_tag, circuit->interface->name); | |
1085 | return ISIS_WARNING; | |
1086 | } | |
1087 | ||
eb5d44eb | 1088 | /* |
1089 | * Accept the level 1 adjacency only if a match between local and | |
1090 | * remote area addresses is found | |
1091 | */ | |
3f045a08 JB |
1092 | if (listcount (circuit->area->area_addrs) == 0 || |
1093 | (level == IS_LEVEL_1 && | |
1094 | area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0)) | |
f390d2c7 | 1095 | { |
1096 | if (isis->debugs & DEBUG_ADJ_PACKETS) | |
1097 | { | |
529d65b3 | 1098 | zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s", |
1099 | circuit->area->area_tag, level, | |
1100 | circuit->interface->name); | |
f390d2c7 | 1101 | } |
1102 | retval = ISIS_OK; | |
1103 | goto out; | |
eb5d44eb | 1104 | } |
eb5d44eb | 1105 | |
1106 | /* | |
1107 | * it's own IIH PDU - discard silently | |
f390d2c7 | 1108 | */ |
1109 | if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN)) | |
1110 | { | |
529d65b3 | 1111 | zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded", |
1112 | circuit->area->area_tag); | |
eb5d44eb | 1113 | |
f390d2c7 | 1114 | retval = ISIS_OK; |
1115 | goto out; | |
1116 | } | |
eb5d44eb | 1117 | |
1118 | /* | |
1119 | * check if it's own interface ip match iih ip addrs | |
1120 | */ | |
28a8cfcb | 1121 | if (found & TLVFLAG_IPV4_ADDR) |
f390d2c7 | 1122 | { |
28a8cfcb DL |
1123 | if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs)) |
1124 | v4_usable = 1; | |
1125 | else | |
1126 | zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap " | |
1127 | "in LAN IIH from %s\n", circuit->interface->name); | |
f390d2c7 | 1128 | } |
28a8cfcb DL |
1129 | #ifndef HAVE_IPV6 |
1130 | else /* !(found & TLVFLAG_IPV4_ADDR) */ | |
1131 | zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s " | |
1132 | "(this isisd has no IPv6)\n", circuit->interface->name); | |
1133 | ||
1134 | #else | |
1135 | if (found & TLVFLAG_IPV6_ADDR) | |
1136 | { | |
1137 | /* TBA: check that we have a linklocal ourselves? */ | |
1138 | struct listnode *node; | |
ad2f92b6 | 1139 | struct in6_addr *ip; |
28a8cfcb DL |
1140 | for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip)) |
1141 | if (IN6_IS_ADDR_LINKLOCAL (ip)) | |
1142 | { | |
1143 | v6_usable = 1; | |
1144 | break; | |
1145 | } | |
1146 | ||
1147 | if (!v6_usable) | |
1148 | zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local " | |
1149 | "in LAN IIH from %s\n", circuit->interface->name); | |
1150 | } | |
1151 | ||
1152 | if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR))) | |
1153 | zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n", | |
1154 | circuit->interface->name); | |
1155 | #endif | |
1156 | ||
1157 | if (!v6_usable && !v4_usable) | |
1158 | { | |
1159 | free_tlvs (&tlvs); | |
1160 | return ISIS_WARNING; | |
1161 | } | |
1162 | ||
eb5d44eb | 1163 | |
1164 | adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]); | |
3f045a08 JB |
1165 | if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) || |
1166 | (adj->level != level)) | |
f390d2c7 | 1167 | { |
3f045a08 JB |
1168 | if (!adj) |
1169 | { | |
1170 | /* | |
1171 | * Do as in 8.4.2.5 | |
1172 | */ | |
1173 | adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit); | |
1174 | if (adj == NULL) | |
1175 | { | |
1176 | retval = ISIS_ERROR; | |
1177 | goto out; | |
1178 | } | |
1179 | } | |
1180 | else | |
1181 | { | |
1182 | if (ssnpa) { | |
1183 | memcpy (adj->snpa, ssnpa, 6); | |
1184 | } else { | |
1185 | memset (adj->snpa, ' ', 6); | |
1186 | } | |
1187 | adj->level = level; | |
1188 | } | |
f390d2c7 | 1189 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
eb5d44eb | 1190 | |
3f045a08 JB |
1191 | if (level == IS_LEVEL_1) |
1192 | adj->sys_type = ISIS_SYSTYPE_L1_IS; | |
f390d2c7 | 1193 | else |
3f045a08 | 1194 | adj->sys_type = ISIS_SYSTYPE_L2_IS; |
f390d2c7 | 1195 | list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]); |
1196 | isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1], | |
3f045a08 | 1197 | circuit->u.bc.lan_neighs[level - 1]); |
eb5d44eb | 1198 | } |
eb5d44eb | 1199 | |
a211d65d | 1200 | if(adj->dis_record[level-1].dis==ISIS_IS_DIS) |
1201 | switch (level) | |
1202 | { | |
1203 | case 1: | |
1204 | if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) | |
1205 | { | |
3f045a08 | 1206 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); |
64a7afd6 | 1207 | memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id, |
1208 | ISIS_SYS_ID_LEN + 1); | |
a211d65d | 1209 | } |
1210 | break; | |
1211 | case 2: | |
1212 | if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) | |
1213 | { | |
3f045a08 | 1214 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); |
64a7afd6 | 1215 | memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id, |
1216 | ISIS_SYS_ID_LEN + 1); | |
a211d65d | 1217 | } |
1218 | break; | |
1219 | } | |
eb5d44eb | 1220 | |
1221 | adj->hold_time = hdr.hold_time; | |
f390d2c7 | 1222 | adj->last_upd = time (NULL); |
1223 | adj->prio[level - 1] = hdr.prio; | |
eb5d44eb | 1224 | |
1225 | memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1); | |
1226 | ||
3f045a08 JB |
1227 | tlvs_to_adj_area_addrs (&tlvs, adj); |
1228 | ||
eb5d44eb | 1229 | /* which protocol are spoken ??? */ |
b72f345d DL |
1230 | if (tlvs_to_adj_nlpids (&tlvs, adj)) |
1231 | { | |
1232 | retval = ISIS_WARNING; | |
1233 | goto out; | |
1234 | } | |
eb5d44eb | 1235 | |
1236 | /* we need to copy addresses to the adj */ | |
f390d2c7 | 1237 | if (found & TLVFLAG_IPV4_ADDR) |
eb5d44eb | 1238 | tlvs_to_adj_ipv4_addrs (&tlvs, adj); |
1239 | ||
1240 | #ifdef HAVE_IPV6 | |
f390d2c7 | 1241 | if (found & TLVFLAG_IPV6_ADDR) |
eb5d44eb | 1242 | tlvs_to_adj_ipv6_addrs (&tlvs, adj); |
1243 | #endif /* HAVE_IPV6 */ | |
1244 | ||
1245 | adj->circuit_t = hdr.circuit_t; | |
1246 | ||
1247 | /* lets take care of the expiry */ | |
f390d2c7 | 1248 | THREAD_TIMER_OFF (adj->t_expire); |
1249 | THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj, | |
3f045a08 | 1250 | (long) adj->hold_time); |
eb5d44eb | 1251 | |
1252 | /* | |
1253 | * If the snpa for this circuit is found from LAN Neighbours TLV | |
1254 | * we have two-way communication -> adjacency can be put to state "up" | |
1255 | */ | |
1256 | ||
f390d2c7 | 1257 | if (found & TLVFLAG_LAN_NEIGHS) |
3f045a08 JB |
1258 | { |
1259 | if (adj->adj_state != ISIS_ADJ_UP) | |
f390d2c7 | 1260 | { |
3f045a08 JB |
1261 | for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa)) |
1262 | { | |
1263 | if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) | |
1264 | { | |
1265 | isis_adj_state_change (adj, ISIS_ADJ_UP, | |
1266 | "own SNPA found in LAN Neighbours TLV"); | |
1267 | } | |
1268 | } | |
1269 | } | |
1270 | else | |
1271 | { | |
1272 | int found = 0; | |
1273 | for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa)) | |
1274 | if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) | |
1275 | { | |
1276 | found = 1; | |
1277 | break; | |
1278 | } | |
1279 | if (found == 0) | |
1280 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, | |
1281 | "own SNPA not found in LAN Neighbours TLV"); | |
eb5d44eb | 1282 | } |
3f045a08 JB |
1283 | } |
1284 | else if (adj->adj_state == ISIS_ADJ_UP) | |
1285 | { | |
1286 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, | |
1287 | "no LAN Neighbours TLV found"); | |
1288 | } | |
eb5d44eb | 1289 | |
f390d2c7 | 1290 | out: |
f390d2c7 | 1291 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
1292 | { | |
529d65b3 | 1293 | zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, " |
ee046671 | 1294 | "cirID %u, length %zd", |
529d65b3 | 1295 | circuit->area->area_tag, |
1296 | level, snpa_print (ssnpa), circuit->interface->name, | |
3f045a08 | 1297 | circuit_t2string (circuit->is_type), |
29e50b23 | 1298 | circuit->circuit_id, |
3f045a08 | 1299 | stream_get_endp (circuit->rcv_stream)); |
f390d2c7 | 1300 | } |
eb5d44eb | 1301 | |
1302 | free_tlvs (&tlvs); | |
1303 | ||
1304 | return retval; | |
1305 | } | |
1306 | ||
1307 | /* | |
1308 | * Process Level 1/2 Link State | |
1309 | * ISO - 10589 | |
1310 | * Section 7.3.15.1 - Action on receipt of a link state PDU | |
f390d2c7 | 1311 | */ |
1312 | static int | |
02e33d3e | 1313 | process_lsp (int level, struct isis_circuit *circuit, const u_char *ssnpa) |
eb5d44eb | 1314 | { |
1315 | struct isis_link_state_hdr *hdr; | |
1316 | struct isis_adjacency *adj = NULL; | |
1317 | struct isis_lsp *lsp, *lsp0 = NULL; | |
1318 | int retval = ISIS_OK, comp = 0; | |
1319 | u_char lspid[ISIS_SYS_ID_LEN + 2]; | |
1320 | struct isis_passwd *passwd; | |
e38e0df0 | 1321 | uint16_t pdu_len; |
0250758d | 1322 | int lsp_confusion; |
eb5d44eb | 1323 | |
3f045a08 JB |
1324 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
1325 | { | |
1326 | zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u", | |
1327 | circuit->area->area_tag, level, circuit->interface->name, | |
1328 | circuit_t2string (circuit->is_type), circuit->circuit_id); | |
1329 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
1330 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), | |
1331 | stream_get_endp (circuit->rcv_stream)); | |
1332 | } | |
1333 | ||
f390d2c7 | 1334 | if ((stream_get_endp (circuit->rcv_stream) - |
1335 | stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN) | |
1336 | { | |
1337 | zlog_warn ("Packet too short"); | |
1338 | return ISIS_WARNING; | |
1339 | } | |
eb5d44eb | 1340 | |
1341 | /* Reference the header */ | |
f390d2c7 | 1342 | hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream); |
e38e0df0 SV |
1343 | pdu_len = ntohs (hdr->pdu_len); |
1344 | ||
1345 | /* lsp length check */ | |
a22ab5a5 | 1346 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) || |
e38e0df0 SV |
1347 | pdu_len > ISO_MTU(circuit) || |
1348 | pdu_len > stream_get_endp (circuit->rcv_stream)) | |
1349 | { | |
1350 | zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d", | |
1351 | circuit->area->area_tag, | |
1352 | rawlspid_print (hdr->lsp_id), pdu_len); | |
1353 | ||
1354 | return ISIS_WARNING; | |
1355 | } | |
1356 | ||
1357 | /* | |
1358 | * Set the stream endp to PDU length, ignoring additional padding | |
1359 | * introduced by transport chips. | |
1360 | */ | |
1361 | if (pdu_len < stream_get_endp (circuit->rcv_stream)) | |
1362 | stream_set_endp (circuit->rcv_stream, pdu_len); | |
f390d2c7 | 1363 | |
1364 | if (isis->debugs & DEBUG_UPDATE_PACKETS) | |
1365 | { | |
529d65b3 | 1366 | zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, " |
3f045a08 | 1367 | "lifetime %us, len %u, on %s", |
529d65b3 | 1368 | circuit->area->area_tag, |
1369 | level, | |
1370 | rawlspid_print (hdr->lsp_id), | |
1371 | ntohl (hdr->seq_num), | |
1372 | ntohs (hdr->checksum), | |
1373 | ntohs (hdr->rem_lifetime), | |
e38e0df0 | 1374 | pdu_len, |
15935e9a | 1375 | circuit->interface->name); |
f390d2c7 | 1376 | } |
eb5d44eb | 1377 | |
e38e0df0 SV |
1378 | /* lsp is_type check */ |
1379 | if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 && | |
1380 | (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2) | |
3f045a08 | 1381 | { |
e38e0df0 | 1382 | zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x", |
3f045a08 | 1383 | circuit->area->area_tag, |
e38e0df0 SV |
1384 | rawlspid_print (hdr->lsp_id), hdr->lsp_bits); |
1385 | /* continue as per RFC1122 Be liberal in what you accept, and | |
1386 | * conservative in what you send */ | |
3f045a08 | 1387 | } |
eb5d44eb | 1388 | |
1389 | /* Checksum sanity check - FIXME: move to correct place */ | |
1390 | /* 12 = sysid+pdu+remtime */ | |
f390d2c7 | 1391 | if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4, |
e38e0df0 | 1392 | pdu_len - 12, &hdr->checksum)) |
f390d2c7 | 1393 | { |
529d65b3 | 1394 | zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x", |
1395 | circuit->area->area_tag, | |
1396 | rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum)); | |
f390d2c7 | 1397 | |
1398 | return ISIS_WARNING; | |
1399 | } | |
eb5d44eb | 1400 | |
1401 | /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */ | |
f390d2c7 | 1402 | if (circuit->ext_domain) |
1403 | { | |
529d65b3 | 1404 | zlog_debug |
f390d2c7 | 1405 | ("ISIS-Upd (%s): LSP %s received at level %d over circuit with " |
1406 | "externalDomain = true", circuit->area->area_tag, | |
1407 | rawlspid_print (hdr->lsp_id), level); | |
1408 | ||
1409 | return ISIS_WARNING; | |
1410 | } | |
eb5d44eb | 1411 | |
1412 | /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */ | |
3f045a08 | 1413 | if (!accept_level (level, circuit->is_type)) |
f390d2c7 | 1414 | { |
529d65b3 | 1415 | zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of" |
1416 | " type %s", | |
1417 | circuit->area->area_tag, | |
1418 | rawlspid_print (hdr->lsp_id), | |
3f045a08 | 1419 | level, circuit_t2string (circuit->is_type)); |
f390d2c7 | 1420 | |
1421 | return ISIS_WARNING; | |
1422 | } | |
eb5d44eb | 1423 | |
1424 | /* 7.3.15.1 a) 4 - need to make sure IDLength matches */ | |
1425 | ||
1426 | /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */ | |
1427 | ||
1428 | /* 7.3.15.1 a) 7 - password check */ | |
3f045a08 JB |
1429 | (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) : |
1430 | (passwd = &circuit->area->domain_passwd); | |
f390d2c7 | 1431 | if (passwd->type) |
1432 | { | |
3f045a08 JB |
1433 | if (lsp_authentication_check (circuit->rcv_stream, circuit->area, |
1434 | level, passwd)) | |
f390d2c7 | 1435 | { |
1436 | isis_event_auth_failure (circuit->area->area_tag, | |
1437 | "LSP authentication failure", hdr->lsp_id); | |
1438 | return ISIS_WARNING; | |
1439 | } | |
eb5d44eb | 1440 | } |
eb5d44eb | 1441 | /* Find the LSP in our database and compare it to this Link State header */ |
1442 | lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]); | |
1443 | if (lsp) | |
f390d2c7 | 1444 | comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num, |
1445 | hdr->checksum, hdr->rem_lifetime); | |
1446 | if (lsp && (lsp->own_lsp | |
eb5d44eb | 1447 | #ifdef TOPOLOGY_GENERATE |
f390d2c7 | 1448 | || lsp->from_topology |
eb5d44eb | 1449 | #endif /* TOPOLOGY_GENERATE */ |
f390d2c7 | 1450 | )) |
eb5d44eb | 1451 | goto dontcheckadj; |
1452 | ||
1453 | /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */ | |
1454 | /* for broadcast circuits, snpa should be compared */ | |
eb5d44eb | 1455 | |
f390d2c7 | 1456 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
1457 | { | |
1458 | adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]); | |
1459 | if (!adj) | |
1460 | { | |
529d65b3 | 1461 | zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, " |
1462 | "lifetime %us on %s", | |
1463 | circuit->area->area_tag, | |
1464 | rawlspid_print (hdr->lsp_id), | |
1465 | ntohl (hdr->seq_num), | |
1466 | ntohs (hdr->checksum), | |
1467 | ntohs (hdr->rem_lifetime), circuit->interface->name); | |
f390d2c7 | 1468 | return ISIS_WARNING; /* Silently discard */ |
1469 | } | |
eb5d44eb | 1470 | } |
eb5d44eb | 1471 | /* for non broadcast, we just need to find same level adj */ |
f390d2c7 | 1472 | else |
1473 | { | |
1474 | /* If no adj, or no sharing of level */ | |
1475 | if (!circuit->u.p2p.neighbor) | |
1476 | { | |
1477 | return ISIS_OK; /* Silently discard */ | |
1478 | } | |
1479 | else | |
1480 | { | |
3f045a08 | 1481 | if (((level == IS_LEVEL_1) && |
f390d2c7 | 1482 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) || |
3f045a08 | 1483 | ((level == IS_LEVEL_2) && |
f390d2c7 | 1484 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1))) |
1485 | return ISIS_WARNING; /* Silently discard */ | |
3f045a08 | 1486 | adj = circuit->u.p2p.neighbor; |
f390d2c7 | 1487 | } |
eb5d44eb | 1488 | } |
3f045a08 | 1489 | |
f390d2c7 | 1490 | dontcheckadj: |
eb5d44eb | 1491 | /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */ |
1492 | ||
1493 | /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */ | |
1494 | ||
f390d2c7 | 1495 | /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */ |
1496 | ||
0250758d CF |
1497 | /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num but |
1498 | * wrong checksum, initiate a purge. */ | |
1499 | if (lsp | |
1500 | && (lsp->lsp_header->seq_num == hdr->seq_num) | |
1501 | && (lsp->lsp_header->checksum != hdr->checksum)) | |
1502 | { | |
1503 | zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.", | |
1504 | circuit->area->area_tag, rawlspid_print(hdr->lsp_id), | |
1505 | ntohl(hdr->seq_num)); | |
1506 | hdr->rem_lifetime = 0; | |
1507 | lsp_confusion = 1; | |
1508 | } | |
1509 | else | |
1510 | lsp_confusion = 0; | |
1511 | ||
f390d2c7 | 1512 | /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */ |
1513 | if (hdr->rem_lifetime == 0) | |
1514 | { | |
1515 | if (!lsp) | |
1516 | { | |
1517 | /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */ | |
1518 | /* only needed on explicit update, eg - p2p */ | |
1519 | if (circuit->circ_type == CIRCUIT_T_P2P) | |
1520 | ack_lsp (hdr, circuit, level); | |
1521 | return retval; /* FIXME: do we need a purge? */ | |
1522 | } | |
1523 | else | |
1524 | { | |
1525 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) | |
1526 | { | |
1527 | /* LSP by some other system -> do 7.3.16.4 b) */ | |
1528 | /* 7.3.16.4 b) 1) */ | |
1529 | if (comp == LSP_NEWER) | |
1530 | { | |
3f045a08 | 1531 | lsp_update (lsp, circuit->rcv_stream, circuit->area, level); |
f390d2c7 | 1532 | /* ii */ |
3f045a08 | 1533 | lsp_set_all_srmflags (lsp); |
f390d2c7 | 1534 | /* v */ |
1535 | ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */ | |
f390d2c7 | 1536 | |
0250758d CF |
1537 | /* For the case of lsp confusion, flood the purge back to its |
1538 | * originator so that it can react. Otherwise, don't reflood | |
1539 | * through incoming circuit as usual */ | |
1540 | if (!lsp_confusion) | |
1541 | { | |
1542 | /* iii */ | |
1543 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1544 | /* iv */ | |
1545 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1546 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1547 | } | |
f390d2c7 | 1548 | } /* 7.3.16.4 b) 2) */ |
1549 | else if (comp == LSP_EQUAL) | |
1550 | { | |
1551 | /* i */ | |
1552 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1553 | /* ii */ | |
1554 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1555 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1556 | } /* 7.3.16.4 b) 3) */ | |
1557 | else | |
1558 | { | |
1559 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1560 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
1561 | } | |
1562 | } | |
3f045a08 JB |
1563 | else if (lsp->lsp_header->rem_lifetime != 0) |
1564 | { | |
1565 | /* our own LSP -> 7.3.16.4 c) */ | |
1566 | if (comp == LSP_NEWER) | |
1567 | { | |
1568 | lsp_inc_seqnum (lsp, ntohl (hdr->seq_num)); | |
1569 | lsp_set_all_srmflags (lsp); | |
1570 | } | |
1571 | else | |
1572 | { | |
1573 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1574 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
1575 | } | |
1576 | if (isis->debugs & DEBUG_UPDATE_PACKETS) | |
1577 | zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new " | |
1578 | "seq 0x%08x", circuit->area->area_tag, | |
1579 | rawlspid_print (hdr->lsp_id), | |
1580 | ntohl (lsp->lsp_header->seq_num)); | |
1581 | } | |
f390d2c7 | 1582 | } |
1583 | return retval; | |
eb5d44eb | 1584 | } |
eb5d44eb | 1585 | /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a |
1586 | * purge */ | |
f390d2c7 | 1587 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0) |
1588 | { | |
1589 | if (!lsp) | |
1590 | { | |
1591 | /* 7.3.16.4: initiate a purge */ | |
17baea9c | 1592 | lsp_purge_non_exist(level, hdr, circuit->area); |
f390d2c7 | 1593 | return ISIS_OK; |
1594 | } | |
1595 | /* 7.3.15.1 d) - If this is our own lsp and we have it */ | |
1596 | ||
1597 | /* In 7.3.16.1, If an Intermediate system R somewhere in the domain | |
1598 | * has information that the current sequence number for source S is | |
1599 | * "greater" than that held by S, ... */ | |
1600 | ||
e38e0df0 | 1601 | if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num)) |
f390d2c7 | 1602 | { |
1603 | /* 7.3.16.1 */ | |
3f045a08 | 1604 | lsp_inc_seqnum (lsp, ntohl (hdr->seq_num)); |
c89c05dd | 1605 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
1606 | zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq " | |
1607 | "0x%08x", circuit->area->area_tag, | |
1608 | rawlspid_print (hdr->lsp_id), | |
1609 | ntohl (lsp->lsp_header->seq_num)); | |
f390d2c7 | 1610 | } |
e38e0df0 SV |
1611 | /* If the received LSP is older or equal, |
1612 | * resend the LSP which will act as ACK */ | |
1613 | lsp_set_all_srmflags (lsp); | |
eb5d44eb | 1614 | } |
f390d2c7 | 1615 | else |
1616 | { | |
1617 | /* 7.3.15.1 e) - This lsp originated on another system */ | |
1618 | ||
1619 | /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */ | |
1620 | if ((!lsp || comp == LSP_NEWER)) | |
1621 | { | |
f390d2c7 | 1622 | /* |
1623 | * If this lsp is a frag, need to see if we have zero lsp present | |
1624 | */ | |
1625 | if (LSP_FRAGMENT (hdr->lsp_id) != 0) | |
1626 | { | |
1627 | memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1); | |
1628 | LSP_FRAGMENT (lspid) = 0; | |
1629 | lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]); | |
1630 | if (!lsp0) | |
1631 | { | |
3f045a08 | 1632 | zlog_debug ("Got lsp frag, while zero lsp not in database"); |
f390d2c7 | 1633 | return ISIS_OK; |
1634 | } | |
1635 | } | |
3f045a08 JB |
1636 | /* i */ |
1637 | if (!lsp) | |
1638 | { | |
1639 | lsp = lsp_new_from_stream_ptr (circuit->rcv_stream, | |
e38e0df0 | 1640 | pdu_len, lsp0, |
3f045a08 JB |
1641 | circuit->area, level); |
1642 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); | |
1643 | } | |
1644 | else /* exists, so we overwrite */ | |
1645 | { | |
1646 | lsp_update (lsp, circuit->rcv_stream, circuit->area, level); | |
1647 | } | |
f390d2c7 | 1648 | /* ii */ |
3f045a08 | 1649 | lsp_set_all_srmflags (lsp); |
f390d2c7 | 1650 | /* iii */ |
1651 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1652 | ||
1653 | /* iv */ | |
1654 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1655 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1656 | /* FIXME: v) */ | |
1657 | } | |
1658 | /* 7.3.15.1 e) 2) LSP equal to the one in db */ | |
1659 | else if (comp == LSP_EQUAL) | |
1660 | { | |
1661 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
3f045a08 | 1662 | lsp_update (lsp, circuit->rcv_stream, circuit->area, level); |
f390d2c7 | 1663 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
3f045a08 | 1664 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
f390d2c7 | 1665 | } |
1666 | /* 7.3.15.1 e) 3) LSP older than the one in db */ | |
1667 | else | |
1668 | { | |
1669 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1670 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
1671 | } | |
eb5d44eb | 1672 | } |
eb5d44eb | 1673 | return retval; |
1674 | } | |
1675 | ||
1676 | /* | |
1677 | * Process Sequence Numbers | |
1678 | * ISO - 10589 | |
1679 | * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU | |
1680 | */ | |
1681 | ||
92365889 | 1682 | static int |
f390d2c7 | 1683 | process_snp (int snp_type, int level, struct isis_circuit *circuit, |
02e33d3e | 1684 | const u_char *ssnpa) |
eb5d44eb | 1685 | { |
1686 | int retval = ISIS_OK; | |
1687 | int cmp, own_lsp; | |
1688 | char typechar = ' '; | |
e38e0df0 | 1689 | uint16_t pdu_len; |
eb5d44eb | 1690 | struct isis_adjacency *adj; |
1691 | struct isis_complete_seqnum_hdr *chdr = NULL; | |
1692 | struct isis_partial_seqnum_hdr *phdr = NULL; | |
3f045a08 | 1693 | uint32_t found = 0, expected = 0, auth_tlv_offset = 0; |
eb5d44eb | 1694 | struct isis_lsp *lsp; |
1695 | struct lsp_entry *entry; | |
1eb8ef25 | 1696 | struct listnode *node, *nnode; |
1697 | struct listnode *node2, *nnode2; | |
eb5d44eb | 1698 | struct tlvs tlvs; |
1699 | struct list *lsp_list = NULL; | |
1700 | struct isis_passwd *passwd; | |
1701 | ||
f390d2c7 | 1702 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
1703 | { | |
1704 | /* getting the header info */ | |
1705 | typechar = 'C'; | |
1706 | chdr = | |
1707 | (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream); | |
e38e0df0 SV |
1708 | stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN); |
1709 | pdu_len = ntohs (chdr->pdu_len); | |
a22ab5a5 | 1710 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) || |
e38e0df0 SV |
1711 | pdu_len > ISO_MTU(circuit) || |
1712 | pdu_len > stream_get_endp (circuit->rcv_stream)) | |
f390d2c7 | 1713 | { |
e38e0df0 SV |
1714 | zlog_warn ("Received a CSNP with bogus length %d", pdu_len); |
1715 | return ISIS_WARNING; | |
f390d2c7 | 1716 | } |
eb5d44eb | 1717 | } |
f390d2c7 | 1718 | else |
1719 | { | |
1720 | typechar = 'P'; | |
1721 | phdr = | |
1722 | (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream); | |
e38e0df0 SV |
1723 | stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN); |
1724 | pdu_len = ntohs (phdr->pdu_len); | |
a22ab5a5 | 1725 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) || |
e38e0df0 SV |
1726 | pdu_len > ISO_MTU(circuit) || |
1727 | pdu_len > stream_get_endp (circuit->rcv_stream)) | |
f390d2c7 | 1728 | { |
ac7d3169 | 1729 | zlog_warn ("Received a PSNP with bogus length %d", pdu_len); |
e38e0df0 | 1730 | return ISIS_WARNING; |
f390d2c7 | 1731 | } |
eb5d44eb | 1732 | } |
eb5d44eb | 1733 | |
e38e0df0 SV |
1734 | /* |
1735 | * Set the stream endp to PDU length, ignoring additional padding | |
1736 | * introduced by transport chips. | |
1737 | */ | |
1738 | if (pdu_len < stream_get_endp (circuit->rcv_stream)) | |
1739 | stream_set_endp (circuit->rcv_stream, pdu_len); | |
1740 | ||
eb5d44eb | 1741 | /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */ |
f390d2c7 | 1742 | if (circuit->ext_domain) |
1743 | { | |
eb5d44eb | 1744 | |
529d65b3 | 1745 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " |
1746 | "skipping: circuit externalDomain = true", | |
1747 | circuit->area->area_tag, | |
1748 | level, typechar, circuit->interface->name); | |
eb5d44eb | 1749 | |
f390d2c7 | 1750 | return ISIS_OK; |
1751 | } | |
eb5d44eb | 1752 | |
1753 | /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */ | |
3f045a08 | 1754 | if (!accept_level (level, circuit->is_type)) |
f390d2c7 | 1755 | { |
eb5d44eb | 1756 | |
529d65b3 | 1757 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " |
1758 | "skipping: circuit type %s does not match level %d", | |
1759 | circuit->area->area_tag, | |
1760 | level, | |
1761 | typechar, | |
1762 | circuit->interface->name, | |
3f045a08 | 1763 | circuit_t2string (circuit->is_type), level); |
eb5d44eb | 1764 | |
1765 | return ISIS_OK; | |
1766 | } | |
f390d2c7 | 1767 | |
1768 | /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */ | |
1769 | if ((snp_type == ISIS_SNP_PSNP_FLAG) && | |
3f045a08 JB |
1770 | (circuit->circ_type == CIRCUIT_T_BROADCAST) && |
1771 | (!circuit->u.bc.is_dr[level - 1])) | |
f390d2c7 | 1772 | { |
3f045a08 JB |
1773 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, " |
1774 | "skipping: we are not the DIS", | |
1775 | circuit->area->area_tag, | |
1776 | level, | |
1777 | typechar, snpa_print (ssnpa), circuit->interface->name); | |
f390d2c7 | 1778 | |
3f045a08 | 1779 | return ISIS_OK; |
f390d2c7 | 1780 | } |
eb5d44eb | 1781 | |
1782 | /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */ | |
1783 | ||
1784 | /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3 | |
1785 | * - already checked */ | |
1786 | ||
1787 | /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */ | |
1788 | /* for broadcast circuits, snpa should be compared */ | |
1789 | /* FIXME : Do we need to check SNPA? */ | |
f390d2c7 | 1790 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
1791 | { | |
1792 | if (snp_type == ISIS_SNP_CSNP_FLAG) | |
1793 | { | |
1794 | adj = | |
1795 | isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]); | |
1796 | } | |
1797 | else | |
1798 | { | |
1799 | /* a psnp on a broadcast, how lovely of Juniper :) */ | |
1800 | adj = | |
1801 | isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]); | |
1802 | } | |
1803 | if (!adj) | |
1804 | return ISIS_OK; /* Silently discard */ | |
1805 | } | |
1806 | else | |
1807 | { | |
1808 | if (!circuit->u.p2p.neighbor) | |
3f045a08 JB |
1809 | { |
1810 | zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name); | |
1811 | return ISIS_OK; /* Silently discard */ | |
1812 | } | |
f390d2c7 | 1813 | } |
eb5d44eb | 1814 | |
1815 | /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */ | |
1816 | ||
1817 | /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */ | |
1818 | ||
1819 | memset (&tlvs, 0, sizeof (struct tlvs)); | |
1820 | ||
1821 | /* parse the SNP */ | |
1822 | expected |= TLVFLAG_LSP_ENTRIES; | |
1823 | expected |= TLVFLAG_AUTH_INFO; | |
3f045a08 JB |
1824 | |
1825 | auth_tlv_offset = stream_get_getp (circuit->rcv_stream); | |
eb5d44eb | 1826 | retval = parse_tlvs (circuit->area->area_tag, |
f390d2c7 | 1827 | STREAM_PNT (circuit->rcv_stream), |
e38e0df0 | 1828 | pdu_len - stream_get_getp (circuit->rcv_stream), |
3f045a08 | 1829 | &expected, &found, &tlvs, &auth_tlv_offset); |
eb5d44eb | 1830 | |
f390d2c7 | 1831 | if (retval > ISIS_WARNING) |
1832 | { | |
1833 | zlog_warn ("something went very wrong processing SNP"); | |
1834 | free_tlvs (&tlvs); | |
1835 | return retval; | |
1836 | } | |
eb5d44eb | 1837 | |
3f045a08 | 1838 | if (level == IS_LEVEL_1) |
1cbc562b | 1839 | passwd = &circuit->area->area_passwd; |
1840 | else | |
1841 | passwd = &circuit->area->domain_passwd; | |
1842 | ||
1843 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV)) | |
f390d2c7 | 1844 | { |
1cbc562b | 1845 | if (passwd->type) |
3f045a08 JB |
1846 | { |
1847 | if (!(found & TLVFLAG_AUTH_INFO) || | |
1848 | authentication_check (&tlvs.auth_info, passwd, | |
1849 | circuit->rcv_stream, auth_tlv_offset)) | |
1850 | { | |
1851 | isis_event_auth_failure (circuit->area->area_tag, | |
1852 | "SNP authentication" " failure", | |
1853 | phdr ? phdr->source_id : | |
1854 | chdr->source_id); | |
1855 | free_tlvs (&tlvs); | |
1856 | return ISIS_OK; | |
1857 | } | |
1858 | } | |
f390d2c7 | 1859 | } |
eb5d44eb | 1860 | |
1861 | /* debug isis snp-packets */ | |
f390d2c7 | 1862 | if (isis->debugs & DEBUG_SNP_PACKETS) |
1863 | { | |
529d65b3 | 1864 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s", |
1865 | circuit->area->area_tag, | |
1866 | level, | |
1867 | typechar, snpa_print (ssnpa), circuit->interface->name); | |
f390d2c7 | 1868 | if (tlvs.lsp_entries) |
1869 | { | |
3fdb2dd9 | 1870 | for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry)) |
f390d2c7 | 1871 | { |
529d65b3 | 1872 | zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x," |
1873 | " cksum 0x%04x, lifetime %us", | |
1874 | circuit->area->area_tag, | |
1875 | typechar, | |
1876 | rawlspid_print (entry->lsp_id), | |
1877 | ntohl (entry->seq_num), | |
1878 | ntohs (entry->checksum), ntohs (entry->rem_lifetime)); | |
f390d2c7 | 1879 | } |
1880 | } | |
eb5d44eb | 1881 | } |
eb5d44eb | 1882 | |
1883 | /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */ | |
f390d2c7 | 1884 | if (tlvs.lsp_entries) |
1885 | { | |
3fdb2dd9 | 1886 | for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry)) |
f390d2c7 | 1887 | { |
1888 | lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]); | |
1889 | own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN); | |
1890 | if (lsp) | |
1891 | { | |
1892 | /* 7.3.15.2 b) 1) is this LSP newer */ | |
1893 | cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num, | |
1894 | entry->checksum, entry->rem_lifetime); | |
1895 | /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */ | |
1896 | if (cmp == LSP_EQUAL) | |
1897 | { | |
3f045a08 JB |
1898 | /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */ |
1899 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
f390d2c7 | 1900 | } |
3f045a08 | 1901 | /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */ |
f390d2c7 | 1902 | else if (cmp == LSP_OLDER) |
1903 | { | |
1904 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
1905 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1906 | } | |
3f045a08 | 1907 | /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */ |
f390d2c7 | 1908 | else |
1909 | { | |
f390d2c7 | 1910 | if (own_lsp) |
1911 | { | |
1912 | lsp_inc_seqnum (lsp, ntohl (entry->seq_num)); | |
1913 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1914 | } | |
1915 | else | |
1916 | { | |
1917 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
3f045a08 JB |
1918 | /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */ |
1919 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
f390d2c7 | 1920 | } |
1921 | } | |
1922 | } | |
1923 | else | |
1924 | { | |
1925 | /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0, | |
1926 | * insert it and set SSN on it */ | |
1927 | if (entry->rem_lifetime && entry->checksum && entry->seq_num && | |
1928 | memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) | |
1929 | { | |
b20ccb3a CF |
1930 | lsp = lsp_new(circuit->area, entry->lsp_id, |
1931 | ntohs(entry->rem_lifetime), | |
1932 | 0, 0, entry->checksum, level); | |
f390d2c7 | 1933 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); |
3f045a08 | 1934 | ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags); |
f390d2c7 | 1935 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
1936 | } | |
1937 | } | |
eb5d44eb | 1938 | } |
1939 | } | |
eb5d44eb | 1940 | |
1941 | /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */ | |
f390d2c7 | 1942 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
1943 | { | |
1944 | /* | |
3f045a08 JB |
1945 | * Build a list from our own LSP db bounded with |
1946 | * start_lsp_id and stop_lsp_id | |
f390d2c7 | 1947 | */ |
1948 | lsp_list = list_new (); | |
1949 | lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id, | |
1950 | lsp_list, circuit->area->lspdb[level - 1]); | |
1951 | ||
1952 | /* Fixme: Find a better solution */ | |
1953 | if (tlvs.lsp_entries) | |
1954 | { | |
1eb8ef25 | 1955 | for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry)) |
f390d2c7 | 1956 | { |
1eb8ef25 | 1957 | for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp)) |
f390d2c7 | 1958 | { |
1959 | if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0) | |
1960 | { | |
1961 | list_delete_node (lsp_list, node2); | |
1962 | break; | |
1963 | } | |
1964 | } | |
1965 | } | |
1966 | } | |
1967 | /* on remaining LSPs we set SRM (neighbor knew not of) */ | |
3fdb2dd9 | 1968 | for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp)) |
f390d2c7 | 1969 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
f390d2c7 | 1970 | /* lets free it */ |
3f045a08 JB |
1971 | list_delete (lsp_list); |
1972 | ||
eb5d44eb | 1973 | } |
eb5d44eb | 1974 | |
1975 | free_tlvs (&tlvs); | |
1976 | return retval; | |
1977 | } | |
1978 | ||
92365889 | 1979 | static int |
02e33d3e | 1980 | process_csnp (int level, struct isis_circuit *circuit, const u_char *ssnpa) |
eb5d44eb | 1981 | { |
3f045a08 JB |
1982 | if (isis->debugs & DEBUG_SNP_PACKETS) |
1983 | { | |
1984 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u", | |
1985 | circuit->area->area_tag, level, circuit->interface->name, | |
1986 | circuit_t2string (circuit->is_type), circuit->circuit_id); | |
1987 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
1988 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), | |
1989 | stream_get_endp (circuit->rcv_stream)); | |
1990 | } | |
1991 | ||
eb5d44eb | 1992 | /* Sanity check - FIXME: move to correct place */ |
f390d2c7 | 1993 | if ((stream_get_endp (circuit->rcv_stream) - |
1994 | stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN) | |
1995 | { | |
1996 | zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN); | |
1997 | return ISIS_WARNING; | |
1998 | } | |
eb5d44eb | 1999 | |
2000 | return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa); | |
2001 | } | |
2002 | ||
92365889 | 2003 | static int |
02e33d3e | 2004 | process_psnp (int level, struct isis_circuit *circuit, const u_char *ssnpa) |
eb5d44eb | 2005 | { |
3f045a08 JB |
2006 | if (isis->debugs & DEBUG_SNP_PACKETS) |
2007 | { | |
2008 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u", | |
2009 | circuit->area->area_tag, level, circuit->interface->name, | |
2010 | circuit_t2string (circuit->is_type), circuit->circuit_id); | |
2011 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
2012 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), | |
2013 | stream_get_endp (circuit->rcv_stream)); | |
2014 | } | |
2015 | ||
f390d2c7 | 2016 | if ((stream_get_endp (circuit->rcv_stream) - |
2017 | stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN) | |
2018 | { | |
3f045a08 | 2019 | zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN); |
f390d2c7 | 2020 | return ISIS_WARNING; |
2021 | } | |
eb5d44eb | 2022 | |
2023 | return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa); | |
2024 | } | |
2025 | ||
eb5d44eb | 2026 | /* |
2027 | * PDU Dispatcher | |
2028 | */ | |
2029 | ||
92365889 | 2030 | static int |
f390d2c7 | 2031 | isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa) |
eb5d44eb | 2032 | { |
eb5d44eb | 2033 | struct isis_fixed_hdr *hdr; |
eb5d44eb | 2034 | |
f390d2c7 | 2035 | int retval = ISIS_OK; |
eb5d44eb | 2036 | |
2037 | /* | |
2038 | * Let's first read data from stream to the header | |
2039 | */ | |
f390d2c7 | 2040 | hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream); |
eb5d44eb | 2041 | |
f390d2c7 | 2042 | if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS)) |
2043 | { | |
3f045a08 | 2044 | zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp); |
f390d2c7 | 2045 | return ISIS_ERROR; |
2046 | } | |
eb5d44eb | 2047 | |
2048 | /* now we need to know if this is an ISO 9542 packet and | |
2049 | * take real good care of it, waaa! | |
2050 | */ | |
f390d2c7 | 2051 | if (hdr->idrp == ISO9542_ESIS) |
2052 | { | |
3f045a08 JB |
2053 | zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp); |
2054 | return ISIS_ERROR; | |
f390d2c7 | 2055 | } |
3f045a08 JB |
2056 | stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN); |
2057 | ||
eb5d44eb | 2058 | /* |
2059 | * and then process it | |
2060 | */ | |
2061 | ||
f390d2c7 | 2062 | if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN) |
2063 | { | |
2064 | zlog_err ("Fixed header length = %d", hdr->length); | |
2065 | return ISIS_ERROR; | |
2066 | } | |
eb5d44eb | 2067 | |
f390d2c7 | 2068 | if (hdr->version1 != 1) |
2069 | { | |
2070 | zlog_warn ("Unsupported ISIS version %u", hdr->version1); | |
2071 | return ISIS_WARNING; | |
2072 | } | |
eb5d44eb | 2073 | /* either 6 or 0 */ |
f390d2c7 | 2074 | if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN)) |
2075 | { | |
2076 | zlog_err | |
2077 | ("IDFieldLengthMismatch: ID Length field in a received PDU %u, " | |
2078 | "while the parameter for this IS is %u", hdr->id_len, | |
2079 | ISIS_SYS_ID_LEN); | |
2080 | return ISIS_ERROR; | |
2081 | } | |
eb5d44eb | 2082 | |
f390d2c7 | 2083 | if (hdr->version2 != 1) |
2084 | { | |
2085 | zlog_warn ("Unsupported ISIS version %u", hdr->version2); | |
2086 | return ISIS_WARNING; | |
2087 | } | |
3f045a08 JB |
2088 | |
2089 | if (circuit->is_passive) | |
2090 | { | |
2091 | zlog_warn ("Received ISIS PDU on passive circuit %s", | |
2092 | circuit->interface->name); | |
2093 | return ISIS_WARNING; | |
2094 | } | |
2095 | ||
eb5d44eb | 2096 | /* either 3 or 0 */ |
f390d2c7 | 2097 | if ((hdr->max_area_addrs != 0) |
2098 | && (hdr->max_area_addrs != isis->max_area_addrs)) | |
2099 | { | |
2100 | zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a " | |
2101 | "received PDU %u while the parameter for this IS is %u", | |
2102 | hdr->max_area_addrs, isis->max_area_addrs); | |
2103 | return ISIS_ERROR; | |
2104 | } | |
eb5d44eb | 2105 | |
f390d2c7 | 2106 | switch (hdr->pdu_type) |
2107 | { | |
2108 | case L1_LAN_HELLO: | |
2109 | retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa); | |
2110 | break; | |
2111 | case L2_LAN_HELLO: | |
2112 | retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa); | |
2113 | break; | |
2114 | case P2P_HELLO: | |
2115 | retval = process_p2p_hello (circuit); | |
2116 | break; | |
2117 | case L1_LINK_STATE: | |
2118 | retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa); | |
2119 | break; | |
2120 | case L2_LINK_STATE: | |
2121 | retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa); | |
2122 | break; | |
2123 | case L1_COMPLETE_SEQ_NUM: | |
2124 | retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa); | |
2125 | break; | |
2126 | case L2_COMPLETE_SEQ_NUM: | |
2127 | retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa); | |
2128 | break; | |
2129 | case L1_PARTIAL_SEQ_NUM: | |
2130 | retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa); | |
2131 | break; | |
2132 | case L2_PARTIAL_SEQ_NUM: | |
2133 | retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa); | |
2134 | break; | |
2135 | default: | |
2136 | return ISIS_ERROR; | |
2137 | } | |
eb5d44eb | 2138 | |
2139 | return retval; | |
2140 | } | |
2141 | ||
eb5d44eb | 2142 | #ifdef GNU_LINUX |
2143 | int | |
2144 | isis_receive (struct thread *thread) | |
2145 | { | |
eb5d44eb | 2146 | struct isis_circuit *circuit; |
2147 | u_char ssnpa[ETH_ALEN]; | |
2148 | int retval; | |
2149 | ||
2150 | /* | |
2151 | * Get the circuit | |
2152 | */ | |
2153 | circuit = THREAD_ARG (thread); | |
2154 | assert (circuit); | |
2155 | ||
b20ccb3a | 2156 | isis_circuit_stream(circuit, &circuit->rcv_stream); |
eb5d44eb | 2157 | |
2158 | retval = circuit->rx (circuit, ssnpa); | |
f390d2c7 | 2159 | circuit->t_read = NULL; |
eb5d44eb | 2160 | |
2161 | if (retval == ISIS_OK) | |
2162 | retval = isis_handle_pdu (circuit, ssnpa); | |
2163 | ||
2164 | /* | |
2165 | * prepare for next packet. | |
2166 | */ | |
3f045a08 JB |
2167 | if (!circuit->is_passive) |
2168 | { | |
2169 | THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit, | |
2170 | circuit->fd); | |
2171 | } | |
eb5d44eb | 2172 | |
2173 | return retval; | |
2174 | } | |
2175 | ||
2176 | #else | |
2177 | int | |
2178 | isis_receive (struct thread *thread) | |
2179 | { | |
eb5d44eb | 2180 | struct isis_circuit *circuit; |
2181 | u_char ssnpa[ETH_ALEN]; | |
2182 | int retval; | |
2183 | ||
2184 | /* | |
2185 | * Get the circuit | |
2186 | */ | |
2187 | circuit = THREAD_ARG (thread); | |
2188 | assert (circuit); | |
2189 | ||
f390d2c7 | 2190 | circuit->t_read = NULL; |
eb5d44eb | 2191 | |
b20ccb3a | 2192 | isis_circuit_stream(circuit, &circuit->rcv_stream); |
eb5d44eb | 2193 | |
2194 | retval = circuit->rx (circuit, ssnpa); | |
2195 | ||
2196 | if (retval == ISIS_OK) | |
2197 | retval = isis_handle_pdu (circuit, ssnpa); | |
2198 | ||
2199 | /* | |
2200 | * prepare for next packet. | |
2201 | */ | |
3f045a08 JB |
2202 | if (!circuit->is_passive) |
2203 | { | |
2204 | circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit, | |
2205 | listcount | |
2206 | (circuit->area->circuit_list) * | |
2207 | 100); | |
2208 | } | |
eb5d44eb | 2209 | |
2210 | return retval; | |
2211 | } | |
2212 | ||
2213 | #endif | |
2214 | ||
2215 | /* filling of the fixed isis header */ | |
2216 | void | |
2217 | fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type) | |
2218 | { | |
2219 | memset (hdr, 0, sizeof (struct isis_fixed_hdr)); | |
2220 | ||
2221 | hdr->idrp = ISO10589_ISIS; | |
2222 | ||
f390d2c7 | 2223 | switch (pdu_type) |
2224 | { | |
2225 | case L1_LAN_HELLO: | |
2226 | case L2_LAN_HELLO: | |
2227 | hdr->length = ISIS_LANHELLO_HDRLEN; | |
2228 | break; | |
2229 | case P2P_HELLO: | |
2230 | hdr->length = ISIS_P2PHELLO_HDRLEN; | |
2231 | break; | |
2232 | case L1_LINK_STATE: | |
2233 | case L2_LINK_STATE: | |
2234 | hdr->length = ISIS_LSP_HDR_LEN; | |
2235 | break; | |
2236 | case L1_COMPLETE_SEQ_NUM: | |
2237 | case L2_COMPLETE_SEQ_NUM: | |
2238 | hdr->length = ISIS_CSNP_HDRLEN; | |
2239 | break; | |
2240 | case L1_PARTIAL_SEQ_NUM: | |
2241 | case L2_PARTIAL_SEQ_NUM: | |
2242 | hdr->length = ISIS_PSNP_HDRLEN; | |
2243 | break; | |
2244 | default: | |
2245 | zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type); | |
2246 | return; | |
2247 | } | |
eb5d44eb | 2248 | hdr->length += ISIS_FIXED_HDR_LEN; |
2249 | hdr->pdu_type = pdu_type; | |
2250 | hdr->version1 = 1; | |
f390d2c7 | 2251 | hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */ |
eb5d44eb | 2252 | hdr->version2 = 1; |
f390d2c7 | 2253 | hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */ |
eb5d44eb | 2254 | } |
2255 | ||
eb5d44eb | 2256 | /* |
2257 | * SEND SIDE | |
2258 | */ | |
92365889 | 2259 | static void |
eb5d44eb | 2260 | fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type, |
f390d2c7 | 2261 | struct stream *stream) |
eb5d44eb | 2262 | { |
f390d2c7 | 2263 | fill_fixed_hdr (hdr, pdu_type); |
eb5d44eb | 2264 | |
2265 | stream_putc (stream, hdr->idrp); | |
2266 | stream_putc (stream, hdr->length); | |
2267 | stream_putc (stream, hdr->version1); | |
2268 | stream_putc (stream, hdr->id_len); | |
2269 | stream_putc (stream, hdr->pdu_type); | |
2270 | stream_putc (stream, hdr->version2); | |
2271 | stream_putc (stream, hdr->reserved); | |
2272 | stream_putc (stream, hdr->max_area_addrs); | |
2273 | ||
2274 | return; | |
2275 | } | |
2276 | ||
eb5d44eb | 2277 | int |
2278 | send_hello (struct isis_circuit *circuit, int level) | |
2279 | { | |
2280 | struct isis_fixed_hdr fixed_hdr; | |
2281 | struct isis_lan_hello_hdr hello_hdr; | |
2282 | struct isis_p2p_hello_hdr p2p_hello_hdr; | |
3f045a08 | 2283 | unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE]; |
7b7a77a6 | 2284 | size_t len_pointer, length, auth_tlv_offset = 0; |
eb5d44eb | 2285 | u_int32_t interval; |
eb5d44eb | 2286 | int retval; |
2287 | ||
3f045a08 JB |
2288 | if (circuit->is_passive) |
2289 | return ISIS_OK; | |
2290 | ||
f390d2c7 | 2291 | if (circuit->interface->mtu == 0) |
2292 | { | |
2293 | zlog_warn ("circuit has zero MTU"); | |
2294 | return ISIS_WARNING; | |
2295 | } | |
eb5d44eb | 2296 | |
b20ccb3a | 2297 | isis_circuit_stream(circuit, &circuit->snd_stream); |
eb5d44eb | 2298 | |
2299 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
3f045a08 | 2300 | if (level == IS_LEVEL_1) |
f390d2c7 | 2301 | fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO, |
2302 | circuit->snd_stream); | |
eb5d44eb | 2303 | else |
f390d2c7 | 2304 | fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO, |
2305 | circuit->snd_stream); | |
eb5d44eb | 2306 | else |
f390d2c7 | 2307 | fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream); |
eb5d44eb | 2308 | |
2309 | /* | |
2310 | * Fill LAN Level 1 or 2 Hello PDU header | |
2311 | */ | |
2312 | memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr)); | |
f390d2c7 | 2313 | interval = circuit->hello_multiplier[level - 1] * |
eb5d44eb | 2314 | circuit->hello_interval[level - 1]; |
2315 | if (interval > USHRT_MAX) | |
2316 | interval = USHRT_MAX; | |
3f045a08 | 2317 | hello_hdr.circuit_t = circuit->is_type; |
eb5d44eb | 2318 | memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN); |
f390d2c7 | 2319 | hello_hdr.hold_time = htons ((u_int16_t) interval); |
eb5d44eb | 2320 | |
f390d2c7 | 2321 | hello_hdr.pdu_len = 0; /* Update the PDU Length later */ |
9985f83c | 2322 | len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN; |
eb5d44eb | 2323 | |
2324 | /* copy the shared part of the hello to the p2p hello if needed */ | |
f390d2c7 | 2325 | if (circuit->circ_type == CIRCUIT_T_P2P) |
2326 | { | |
2327 | memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN); | |
2328 | p2p_hello_hdr.local_id = circuit->circuit_id; | |
2329 | /* FIXME: need better understanding */ | |
2330 | stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN); | |
2331 | } | |
2332 | else | |
2333 | { | |
3f045a08 JB |
2334 | hello_hdr.prio = circuit->priority[level - 1]; |
2335 | if (level == IS_LEVEL_1) | |
f390d2c7 | 2336 | { |
2337 | memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is, | |
2338 | ISIS_SYS_ID_LEN + 1); | |
2339 | } | |
3f045a08 | 2340 | else if (level == IS_LEVEL_2) |
f390d2c7 | 2341 | { |
2342 | memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is, | |
2343 | ISIS_SYS_ID_LEN + 1); | |
2344 | } | |
2345 | stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN); | |
2346 | } | |
eb5d44eb | 2347 | |
2348 | /* | |
3f045a08 | 2349 | * Then the variable length part. |
eb5d44eb | 2350 | */ |
3f045a08 | 2351 | |
eb5d44eb | 2352 | /* add circuit password */ |
3f045a08 JB |
2353 | switch (circuit->passwd.type) |
2354 | { | |
2355 | /* Cleartext */ | |
2356 | case ISIS_PASSWD_TYPE_CLEARTXT: | |
2357 | if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len, | |
2358 | circuit->passwd.passwd, circuit->snd_stream)) | |
2359 | return ISIS_WARNING; | |
2360 | break; | |
2361 | ||
2362 | /* HMAC MD5 */ | |
2363 | case ISIS_PASSWD_TYPE_HMAC_MD5: | |
2364 | /* Remember where TLV is written so we can later overwrite the MD5 hash */ | |
2365 | auth_tlv_offset = stream_get_endp (circuit->snd_stream); | |
2366 | memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE); | |
2367 | if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE, | |
2368 | hmac_md5_hash, circuit->snd_stream)) | |
2369 | return ISIS_WARNING; | |
2370 | break; | |
2371 | ||
2372 | default: | |
2373 | break; | |
2374 | } | |
2375 | ||
eb5d44eb | 2376 | /* Area Addresses TLV */ |
3f045a08 JB |
2377 | if (listcount (circuit->area->area_addrs) == 0) |
2378 | return ISIS_WARNING; | |
2379 | if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream)) | |
2380 | return ISIS_WARNING; | |
eb5d44eb | 2381 | |
2382 | /* LAN Neighbors TLV */ | |
f390d2c7 | 2383 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
2384 | { | |
3f045a08 JB |
2385 | if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] && |
2386 | listcount (circuit->u.bc.lan_neighs[0]) > 0) | |
f390d2c7 | 2387 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0], |
2388 | circuit->snd_stream)) | |
2389 | return ISIS_WARNING; | |
3f045a08 JB |
2390 | if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] && |
2391 | listcount (circuit->u.bc.lan_neighs[1]) > 0) | |
f390d2c7 | 2392 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1], |
2393 | circuit->snd_stream)) | |
2394 | return ISIS_WARNING; | |
2395 | } | |
eb5d44eb | 2396 | |
2397 | /* Protocols Supported TLV */ | |
f390d2c7 | 2398 | if (circuit->nlpids.count > 0) |
eb5d44eb | 2399 | if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream)) |
2400 | return ISIS_WARNING; | |
2401 | /* IP interface Address TLV */ | |
3f045a08 JB |
2402 | if (circuit->ip_router && circuit->ip_addrs && |
2403 | listcount (circuit->ip_addrs) > 0) | |
eb5d44eb | 2404 | if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream)) |
2405 | return ISIS_WARNING; | |
2406 | ||
f390d2c7 | 2407 | #ifdef HAVE_IPV6 |
eb5d44eb | 2408 | /* IPv6 Interface Address TLV */ |
f390d2c7 | 2409 | if (circuit->ipv6_router && circuit->ipv6_link && |
3f045a08 | 2410 | listcount (circuit->ipv6_link) > 0) |
eb5d44eb | 2411 | if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream)) |
2412 | return ISIS_WARNING; | |
2413 | #endif /* HAVE_IPV6 */ | |
2414 | ||
3f045a08 | 2415 | if (circuit->pad_hellos) |
eb5d44eb | 2416 | if (tlv_add_padding (circuit->snd_stream)) |
2417 | return ISIS_WARNING; | |
2418 | ||
9985f83c | 2419 | length = stream_get_endp (circuit->snd_stream); |
eb5d44eb | 2420 | /* Update PDU length */ |
f390d2c7 | 2421 | stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length); |
eb5d44eb | 2422 | |
3f045a08 JB |
2423 | /* For HMAC MD5 we need to compute the md5 hash and store it */ |
2424 | if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) | |
2425 | { | |
2426 | hmac_md5 (STREAM_DATA (circuit->snd_stream), | |
2427 | stream_get_endp (circuit->snd_stream), | |
2428 | (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len, | |
f2bce9a5 | 2429 | (unsigned char *) &hmac_md5_hash); |
3f045a08 JB |
2430 | /* Copy the hash into the stream */ |
2431 | memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3, | |
2432 | hmac_md5_hash, ISIS_AUTH_MD5_SIZE); | |
2433 | } | |
eb5d44eb | 2434 | |
f390d2c7 | 2435 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
2436 | { | |
2437 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
2438 | { | |
7b7a77a6 | 2439 | zlog_debug ("ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd", |
529d65b3 | 2440 | circuit->area->area_tag, level, circuit->interface->name, |
3f045a08 | 2441 | length); |
f390d2c7 | 2442 | } |
2443 | else | |
2444 | { | |
7b7a77a6 | 2445 | zlog_debug ("ISIS-Adj (%s): Sending P2P IIH on %s, length %zd", |
529d65b3 | 2446 | circuit->area->area_tag, circuit->interface->name, |
3f045a08 | 2447 | length); |
f390d2c7 | 2448 | } |
3f045a08 JB |
2449 | if (isis->debugs & DEBUG_PACKET_DUMP) |
2450 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), | |
2451 | stream_get_endp (circuit->snd_stream)); | |
eb5d44eb | 2452 | } |
eb5d44eb | 2453 | |
3f045a08 JB |
2454 | retval = circuit->tx (circuit, level); |
2455 | if (retval != ISIS_OK) | |
2456 | zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed", | |
2457 | circuit->area->area_tag, level, circuit->interface->name); | |
eb5d44eb | 2458 | |
3f045a08 | 2459 | return retval; |
eb5d44eb | 2460 | } |
2461 | ||
2462 | int | |
2463 | send_lan_l1_hello (struct thread *thread) | |
2464 | { | |
eb5d44eb | 2465 | struct isis_circuit *circuit; |
2466 | int retval; | |
2467 | ||
2468 | circuit = THREAD_ARG (thread); | |
2469 | assert (circuit); | |
2470 | circuit->u.bc.t_send_lan_hello[0] = NULL; | |
2471 | ||
ddfdbd32 CF |
2472 | if (!(circuit->area->is_type & IS_LEVEL_1)) |
2473 | { | |
2474 | zlog_warn ("ISIS-Hello (%s): Trying to send L1 IIH in L2-only area", | |
2475 | circuit->area->area_tag); | |
2476 | return 1; | |
2477 | } | |
2478 | ||
eb5d44eb | 2479 | if (circuit->u.bc.run_dr_elect[0]) |
f390d2c7 | 2480 | retval = isis_dr_elect (circuit, 1); |
eb5d44eb | 2481 | |
3f045a08 | 2482 | retval = send_hello (circuit, 1); |
eb5d44eb | 2483 | |
2484 | /* set next timer thread */ | |
f390d2c7 | 2485 | THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0], |
2486 | send_lan_l1_hello, circuit, | |
2487 | isis_jitter (circuit->hello_interval[0], IIH_JITTER)); | |
eb5d44eb | 2488 | |
2489 | return retval; | |
2490 | } | |
2491 | ||
2492 | int | |
2493 | send_lan_l2_hello (struct thread *thread) | |
2494 | { | |
2495 | struct isis_circuit *circuit; | |
2496 | int retval; | |
2497 | ||
2498 | circuit = THREAD_ARG (thread); | |
2499 | assert (circuit); | |
2500 | circuit->u.bc.t_send_lan_hello[1] = NULL; | |
2501 | ||
ddfdbd32 CF |
2502 | if (!(circuit->area->is_type & IS_LEVEL_2)) |
2503 | { | |
2504 | zlog_warn ("ISIS-Hello (%s): Trying to send L2 IIH in L1 area", | |
2505 | circuit->area->area_tag); | |
2506 | return 1; | |
2507 | } | |
2508 | ||
eb5d44eb | 2509 | if (circuit->u.bc.run_dr_elect[1]) |
2510 | retval = isis_dr_elect (circuit, 2); | |
2511 | ||
3f045a08 | 2512 | retval = send_hello (circuit, 2); |
eb5d44eb | 2513 | |
f390d2c7 | 2514 | /* set next timer thread */ |
2515 | THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1], | |
2516 | send_lan_l2_hello, circuit, | |
2517 | isis_jitter (circuit->hello_interval[1], IIH_JITTER)); | |
eb5d44eb | 2518 | |
2519 | return retval; | |
2520 | } | |
2521 | ||
2522 | int | |
2523 | send_p2p_hello (struct thread *thread) | |
2524 | { | |
2525 | struct isis_circuit *circuit; | |
2526 | ||
2527 | circuit = THREAD_ARG (thread); | |
2528 | assert (circuit); | |
2529 | circuit->u.p2p.t_send_p2p_hello = NULL; | |
2530 | ||
f390d2c7 | 2531 | send_hello (circuit, 1); |
eb5d44eb | 2532 | |
f390d2c7 | 2533 | /* set next timer thread */ |
2534 | THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello, | |
2535 | circuit, isis_jitter (circuit->hello_interval[1], | |
2536 | IIH_JITTER)); | |
eb5d44eb | 2537 | |
2538 | return ISIS_OK; | |
2539 | } | |
2540 | ||
92365889 | 2541 | static int |
f390d2c7 | 2542 | build_csnp (int level, u_char * start, u_char * stop, struct list *lsps, |
2543 | struct isis_circuit *circuit) | |
eb5d44eb | 2544 | { |
2545 | struct isis_fixed_hdr fixed_hdr; | |
2546 | struct isis_passwd *passwd; | |
eb5d44eb | 2547 | unsigned long lenp; |
2548 | u_int16_t length; | |
3f045a08 JB |
2549 | unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE]; |
2550 | unsigned long auth_tlv_offset = 0; | |
2551 | int retval = ISIS_OK; | |
2552 | ||
b20ccb3a | 2553 | isis_circuit_stream(circuit, &circuit->snd_stream); |
eb5d44eb | 2554 | |
3f045a08 | 2555 | if (level == IS_LEVEL_1) |
f390d2c7 | 2556 | fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM, |
2557 | circuit->snd_stream); | |
eb5d44eb | 2558 | else |
f390d2c7 | 2559 | fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM, |
2560 | circuit->snd_stream); | |
eb5d44eb | 2561 | |
2562 | /* | |
2563 | * Fill Level 1 or 2 Complete Sequence Numbers header | |
2564 | */ | |
2565 | ||
9985f83c | 2566 | lenp = stream_get_endp (circuit->snd_stream); |
f390d2c7 | 2567 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ |
eb5d44eb | 2568 | /* no need to send the source here, it is always us if we csnp */ |
2569 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
2570 | /* with zero circuit id - ref 9.10, 9.11 */ | |
2571 | stream_putc (circuit->snd_stream, 0x00); | |
2572 | ||
2573 | stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2); | |
2574 | stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2); | |
2575 | ||
2576 | /* | |
2577 | * And TLVs | |
2578 | */ | |
3f045a08 | 2579 | if (level == IS_LEVEL_1) |
eb5d44eb | 2580 | passwd = &circuit->area->area_passwd; |
2581 | else | |
2582 | passwd = &circuit->area->domain_passwd; | |
2583 | ||
1cbc562b | 2584 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
3f045a08 JB |
2585 | { |
2586 | switch (passwd->type) | |
2587 | { | |
2588 | /* Cleartext */ | |
2589 | case ISIS_PASSWD_TYPE_CLEARTXT: | |
2590 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len, | |
2591 | passwd->passwd, circuit->snd_stream)) | |
2592 | return ISIS_WARNING; | |
2593 | break; | |
2594 | ||
2595 | /* HMAC MD5 */ | |
2596 | case ISIS_PASSWD_TYPE_HMAC_MD5: | |
2597 | /* Remember where TLV is written so we can later overwrite the MD5 hash */ | |
2598 | auth_tlv_offset = stream_get_endp (circuit->snd_stream); | |
2599 | memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE); | |
2600 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE, | |
2601 | hmac_md5_hash, circuit->snd_stream)) | |
2602 | return ISIS_WARNING; | |
2603 | break; | |
2604 | ||
2605 | default: | |
2606 | break; | |
f390d2c7 | 2607 | } |
3f045a08 JB |
2608 | } |
2609 | ||
2610 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); | |
2611 | if (retval != ISIS_OK) | |
2612 | return retval; | |
2613 | ||
9985f83c | 2614 | length = (u_int16_t) stream_get_endp (circuit->snd_stream); |
eb5d44eb | 2615 | /* Update PU length */ |
2616 | stream_putw_at (circuit->snd_stream, lenp, length); | |
2617 | ||
3f045a08 JB |
2618 | /* For HMAC MD5 we need to compute the md5 hash and store it */ |
2619 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) && | |
2620 | passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5) | |
2621 | { | |
2622 | hmac_md5 (STREAM_DATA (circuit->snd_stream), | |
2623 | stream_get_endp(circuit->snd_stream), | |
2624 | (unsigned char *) &passwd->passwd, passwd->len, | |
f2bce9a5 | 2625 | (unsigned char *) &hmac_md5_hash); |
3f045a08 JB |
2626 | /* Copy the hash into the stream */ |
2627 | memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3, | |
2628 | hmac_md5_hash, ISIS_AUTH_MD5_SIZE); | |
2629 | } | |
2630 | ||
eb5d44eb | 2631 | return retval; |
2632 | } | |
2633 | ||
3f045a08 JB |
2634 | /* |
2635 | * Count the maximum number of lsps that can be accomodated by a given size. | |
2636 | */ | |
2637 | static uint16_t | |
2638 | get_max_lsp_count (uint16_t size) | |
2639 | { | |
2640 | uint16_t tlv_count; | |
2641 | uint16_t lsp_count; | |
2642 | uint16_t remaining_size; | |
2643 | ||
2644 | /* First count the full size TLVs */ | |
2645 | tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE; | |
2646 | lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN); | |
2647 | ||
2648 | /* The last TLV, if any */ | |
2649 | remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE; | |
2650 | if (remaining_size - 2 >= LSP_ENTRIES_LEN) | |
2651 | lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN; | |
2652 | ||
2653 | return lsp_count; | |
2654 | } | |
2655 | ||
2656 | /* | |
2657 | * Calculate the length of Authentication Info. TLV. | |
2658 | */ | |
2659 | static uint16_t | |
2660 | auth_tlv_length (int level, struct isis_circuit *circuit) | |
2661 | { | |
2662 | struct isis_passwd *passwd; | |
2663 | uint16_t length; | |
2664 | ||
2665 | if (level == IS_LEVEL_1) | |
2666 | passwd = &circuit->area->area_passwd; | |
2667 | else | |
2668 | passwd = &circuit->area->domain_passwd; | |
2669 | ||
2670 | /* Also include the length of TLV header */ | |
2671 | length = AUTH_INFO_HDRLEN; | |
2672 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) | |
2673 | { | |
2674 | switch (passwd->type) | |
2675 | { | |
2676 | /* Cleartext */ | |
2677 | case ISIS_PASSWD_TYPE_CLEARTXT: | |
2678 | length += passwd->len; | |
2679 | break; | |
2680 | ||
2681 | /* HMAC MD5 */ | |
2682 | case ISIS_PASSWD_TYPE_HMAC_MD5: | |
2683 | length += ISIS_AUTH_MD5_SIZE; | |
2684 | break; | |
2685 | ||
2686 | default: | |
2687 | break; | |
2688 | } | |
2689 | } | |
2690 | ||
2691 | return length; | |
2692 | } | |
2693 | ||
2694 | /* | |
2695 | * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP. | |
2696 | */ | |
2697 | static uint16_t | |
2698 | max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit) | |
2699 | { | |
2700 | int snp_hdr_len; | |
2701 | int auth_tlv_len; | |
2702 | uint16_t lsp_count; | |
2703 | ||
2704 | snp_hdr_len = ISIS_FIXED_HDR_LEN; | |
2705 | if (snp_type == ISIS_SNP_CSNP_FLAG) | |
2706 | snp_hdr_len += ISIS_CSNP_HDRLEN; | |
2707 | else | |
2708 | snp_hdr_len += ISIS_PSNP_HDRLEN; | |
2709 | ||
2710 | auth_tlv_len = auth_tlv_length (level, circuit); | |
2711 | lsp_count = get_max_lsp_count ( | |
2712 | stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len); | |
e38e0df0 | 2713 | return lsp_count; |
3f045a08 JB |
2714 | } |
2715 | ||
eb5d44eb | 2716 | /* |
2717 | * FIXME: support multiple CSNPs | |
2718 | */ | |
2719 | ||
2720 | int | |
2721 | send_csnp (struct isis_circuit *circuit, int level) | |
2722 | { | |
eb5d44eb | 2723 | u_char start[ISIS_SYS_ID_LEN + 2]; |
2724 | u_char stop[ISIS_SYS_ID_LEN + 2]; | |
2725 | struct list *list = NULL; | |
3fdb2dd9 | 2726 | struct listnode *node; |
eb5d44eb | 2727 | struct isis_lsp *lsp; |
3f045a08 JB |
2728 | u_char num_lsps, loop = 1; |
2729 | int i, retval = ISIS_OK; | |
2730 | ||
2731 | if (circuit->area->lspdb[level - 1] == NULL || | |
2732 | dict_count (circuit->area->lspdb[level - 1]) == 0) | |
2733 | return retval; | |
eb5d44eb | 2734 | |
f390d2c7 | 2735 | memset (start, 0x00, ISIS_SYS_ID_LEN + 2); |
eb5d44eb | 2736 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); |
2737 | ||
3f045a08 JB |
2738 | num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit); |
2739 | ||
2740 | while (loop) | |
f390d2c7 | 2741 | { |
2742 | list = list_new (); | |
3f045a08 JB |
2743 | lsp_build_list (start, stop, num_lsps, list, |
2744 | circuit->area->lspdb[level - 1]); | |
2745 | /* | |
2746 | * Update the stop lsp_id before encoding this CSNP. | |
2747 | */ | |
2748 | if (listcount (list) < num_lsps) | |
2749 | { | |
2750 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); | |
2751 | } | |
f390d2c7 | 2752 | else |
3f045a08 JB |
2753 | { |
2754 | node = listtail (list); | |
2755 | lsp = listgetdata (node); | |
2756 | memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2); | |
2757 | } | |
f390d2c7 | 2758 | |
2759 | retval = build_csnp (level, start, stop, list, circuit); | |
3f045a08 JB |
2760 | if (retval != ISIS_OK) |
2761 | { | |
2762 | zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed", | |
2763 | circuit->area->area_tag, level, circuit->interface->name); | |
2764 | list_delete (list); | |
2765 | return retval; | |
2766 | } | |
f390d2c7 | 2767 | |
2768 | if (isis->debugs & DEBUG_SNP_PACKETS) | |
3f045a08 | 2769 | { |
0232bb72 | 2770 | zlog_debug ("ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd", |
3f045a08 JB |
2771 | circuit->area->area_tag, level, circuit->interface->name, |
2772 | stream_get_endp (circuit->snd_stream)); | |
2773 | for (ALL_LIST_ELEMENTS_RO (list, node, lsp)) | |
2774 | { | |
2775 | zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x," | |
2776 | " cksum 0x%04x, lifetime %us", | |
2777 | circuit->area->area_tag, | |
2778 | rawlspid_print (lsp->lsp_header->lsp_id), | |
2779 | ntohl (lsp->lsp_header->seq_num), | |
2780 | ntohs (lsp->lsp_header->checksum), | |
2781 | ntohs (lsp->lsp_header->rem_lifetime)); | |
2782 | } | |
2783 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
2784 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), | |
2785 | stream_get_endp (circuit->snd_stream)); | |
2786 | } | |
2787 | ||
2788 | retval = circuit->tx (circuit, level); | |
2789 | if (retval != ISIS_OK) | |
2790 | { | |
2791 | zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed", | |
2792 | circuit->area->area_tag, level, | |
2793 | circuit->interface->name); | |
2794 | list_delete (list); | |
2795 | return retval; | |
2796 | } | |
eb5d44eb | 2797 | |
3f045a08 JB |
2798 | /* |
2799 | * Start lsp_id of the next CSNP should be one plus the | |
2800 | * stop lsp_id in this current CSNP. | |
2801 | */ | |
2802 | memcpy (start, stop, ISIS_SYS_ID_LEN + 2); | |
2803 | loop = 0; | |
2804 | for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) | |
2805 | { | |
2806 | if (start[i] < (u_char)0xff) | |
2807 | { | |
2808 | start[i] += 1; | |
2809 | loop = 1; | |
2810 | break; | |
2811 | } | |
2812 | } | |
2813 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); | |
f390d2c7 | 2814 | list_delete (list); |
f390d2c7 | 2815 | } |
3f045a08 | 2816 | |
eb5d44eb | 2817 | return retval; |
2818 | } | |
2819 | ||
2820 | int | |
2821 | send_l1_csnp (struct thread *thread) | |
2822 | { | |
2823 | struct isis_circuit *circuit; | |
2824 | int retval = ISIS_OK; | |
2825 | ||
2826 | circuit = THREAD_ARG (thread); | |
2827 | assert (circuit); | |
2828 | ||
2829 | circuit->t_send_csnp[0] = NULL; | |
2830 | ||
f390d2c7 | 2831 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0]) |
2832 | { | |
2833 | send_csnp (circuit, 1); | |
2834 | } | |
eb5d44eb | 2835 | /* set next timer thread */ |
f390d2c7 | 2836 | THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit, |
2837 | isis_jitter (circuit->csnp_interval[0], CSNP_JITTER)); | |
eb5d44eb | 2838 | |
2839 | return retval; | |
2840 | } | |
2841 | ||
2842 | int | |
2843 | send_l2_csnp (struct thread *thread) | |
2844 | { | |
2845 | struct isis_circuit *circuit; | |
2846 | int retval = ISIS_OK; | |
2847 | ||
2848 | circuit = THREAD_ARG (thread); | |
2849 | assert (circuit); | |
2850 | ||
2851 | circuit->t_send_csnp[1] = NULL; | |
2852 | ||
f390d2c7 | 2853 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1]) |
2854 | { | |
2855 | send_csnp (circuit, 2); | |
2856 | } | |
eb5d44eb | 2857 | /* set next timer thread */ |
f390d2c7 | 2858 | THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit, |
2859 | isis_jitter (circuit->csnp_interval[1], CSNP_JITTER)); | |
d70f99e1 | 2860 | |
eb5d44eb | 2861 | return retval; |
2862 | } | |
2863 | ||
92365889 | 2864 | static int |
eb5d44eb | 2865 | build_psnp (int level, struct isis_circuit *circuit, struct list *lsps) |
2866 | { | |
2867 | struct isis_fixed_hdr fixed_hdr; | |
2868 | unsigned long lenp; | |
2869 | u_int16_t length; | |
eb5d44eb | 2870 | struct isis_lsp *lsp; |
2871 | struct isis_passwd *passwd; | |
3fdb2dd9 | 2872 | struct listnode *node; |
3f045a08 JB |
2873 | unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE]; |
2874 | unsigned long auth_tlv_offset = 0; | |
2875 | int retval = ISIS_OK; | |
eb5d44eb | 2876 | |
b20ccb3a | 2877 | isis_circuit_stream(circuit, &circuit->snd_stream); |
3f045a08 JB |
2878 | |
2879 | if (level == IS_LEVEL_1) | |
f390d2c7 | 2880 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, |
2881 | circuit->snd_stream); | |
eb5d44eb | 2882 | else |
2883 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, | |
f390d2c7 | 2884 | circuit->snd_stream); |
eb5d44eb | 2885 | |
2886 | /* | |
2887 | * Fill Level 1 or 2 Partial Sequence Numbers header | |
2888 | */ | |
9985f83c | 2889 | lenp = stream_get_endp (circuit->snd_stream); |
f390d2c7 | 2890 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ |
eb5d44eb | 2891 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
2892 | stream_putc (circuit->snd_stream, circuit->idx); | |
2893 | ||
2894 | /* | |
2895 | * And TLVs | |
2896 | */ | |
2897 | ||
3f045a08 | 2898 | if (level == IS_LEVEL_1) |
eb5d44eb | 2899 | passwd = &circuit->area->area_passwd; |
2900 | else | |
2901 | passwd = &circuit->area->domain_passwd; | |
2902 | ||
1cbc562b | 2903 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
3f045a08 JB |
2904 | { |
2905 | switch (passwd->type) | |
2906 | { | |
2907 | /* Cleartext */ | |
2908 | case ISIS_PASSWD_TYPE_CLEARTXT: | |
2909 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len, | |
2910 | passwd->passwd, circuit->snd_stream)) | |
2911 | return ISIS_WARNING; | |
2912 | break; | |
2913 | ||
2914 | /* HMAC MD5 */ | |
2915 | case ISIS_PASSWD_TYPE_HMAC_MD5: | |
2916 | /* Remember where TLV is written so we can later overwrite the MD5 hash */ | |
2917 | auth_tlv_offset = stream_get_endp (circuit->snd_stream); | |
2918 | memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE); | |
2919 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE, | |
2920 | hmac_md5_hash, circuit->snd_stream)) | |
2921 | return ISIS_WARNING; | |
2922 | break; | |
2923 | ||
2924 | default: | |
2925 | break; | |
f390d2c7 | 2926 | } |
3f045a08 JB |
2927 | } |
2928 | ||
2929 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); | |
2930 | if (retval != ISIS_OK) | |
2931 | return retval; | |
eb5d44eb | 2932 | |
f390d2c7 | 2933 | if (isis->debugs & DEBUG_SNP_PACKETS) |
2934 | { | |
3fdb2dd9 | 2935 | for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp)) |
f390d2c7 | 2936 | { |
529d65b3 | 2937 | zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x," |
2938 | " cksum 0x%04x, lifetime %us", | |
2939 | circuit->area->area_tag, | |
2940 | rawlspid_print (lsp->lsp_header->lsp_id), | |
2941 | ntohl (lsp->lsp_header->seq_num), | |
2942 | ntohs (lsp->lsp_header->checksum), | |
2943 | ntohs (lsp->lsp_header->rem_lifetime)); | |
f390d2c7 | 2944 | } |
eb5d44eb | 2945 | } |
eb5d44eb | 2946 | |
9985f83c | 2947 | length = (u_int16_t) stream_get_endp (circuit->snd_stream); |
eb5d44eb | 2948 | /* Update PDU length */ |
2949 | stream_putw_at (circuit->snd_stream, lenp, length); | |
2950 | ||
3f045a08 JB |
2951 | /* For HMAC MD5 we need to compute the md5 hash and store it */ |
2952 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) && | |
2953 | passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5) | |
2954 | { | |
2955 | hmac_md5 (STREAM_DATA (circuit->snd_stream), | |
2956 | stream_get_endp(circuit->snd_stream), | |
2957 | (unsigned char *) &passwd->passwd, passwd->len, | |
f2bce9a5 | 2958 | (unsigned char *) &hmac_md5_hash); |
3f045a08 JB |
2959 | /* Copy the hash into the stream */ |
2960 | memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3, | |
2961 | hmac_md5_hash, ISIS_AUTH_MD5_SIZE); | |
2962 | } | |
2963 | ||
eb5d44eb | 2964 | return ISIS_OK; |
2965 | } | |
2966 | ||
2967 | /* | |
2968 | * 7.3.15.4 action on expiration of partial SNP interval | |
2969 | * level 1 | |
2970 | */ | |
92365889 | 2971 | static int |
eb5d44eb | 2972 | send_psnp (int level, struct isis_circuit *circuit) |
2973 | { | |
eb5d44eb | 2974 | struct isis_lsp *lsp; |
2975 | struct list *list = NULL; | |
3fdb2dd9 | 2976 | struct listnode *node; |
3f045a08 JB |
2977 | u_char num_lsps; |
2978 | int retval = ISIS_OK; | |
eb5d44eb | 2979 | |
3f045a08 JB |
2980 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && |
2981 | circuit->u.bc.is_dr[level - 1]) | |
2982 | return ISIS_OK; | |
eb5d44eb | 2983 | |
3f045a08 JB |
2984 | if (circuit->area->lspdb[level - 1] == NULL || |
2985 | dict_count (circuit->area->lspdb[level - 1]) == 0) | |
2986 | return ISIS_OK; | |
f390d2c7 | 2987 | |
e38e0df0 SV |
2988 | if (! circuit->snd_stream) |
2989 | return ISIS_ERROR; | |
2990 | ||
3f045a08 | 2991 | num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit); |
f390d2c7 | 2992 | |
3f045a08 JB |
2993 | while (1) |
2994 | { | |
2995 | list = list_new (); | |
2996 | lsp_build_list_ssn (circuit, num_lsps, list, | |
2997 | circuit->area->lspdb[level - 1]); | |
2998 | ||
2999 | if (listcount (list) == 0) | |
3000 | { | |
3001 | list_delete (list); | |
3002 | return ISIS_OK; | |
3003 | } | |
3004 | ||
3005 | retval = build_psnp (level, circuit, list); | |
3006 | if (retval != ISIS_OK) | |
3007 | { | |
3008 | zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed", | |
3009 | circuit->area->area_tag, level, circuit->interface->name); | |
3010 | list_delete (list); | |
3011 | return retval; | |
3012 | } | |
f390d2c7 | 3013 | |
3f045a08 JB |
3014 | if (isis->debugs & DEBUG_SNP_PACKETS) |
3015 | { | |
0232bb72 | 3016 | zlog_debug ("ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd", |
3f045a08 JB |
3017 | circuit->area->area_tag, level, |
3018 | circuit->interface->name, | |
3019 | stream_get_endp (circuit->snd_stream)); | |
3020 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
3021 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), | |
3022 | stream_get_endp (circuit->snd_stream)); | |
3023 | } | |
3024 | ||
3025 | retval = circuit->tx (circuit, level); | |
3026 | if (retval != ISIS_OK) | |
3027 | { | |
3028 | zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed", | |
3029 | circuit->area->area_tag, level, | |
3030 | circuit->interface->name); | |
3031 | list_delete (list); | |
3032 | return retval; | |
3033 | } | |
f390d2c7 | 3034 | |
3f045a08 JB |
3035 | /* |
3036 | * sending succeeded, we can clear SSN flags of this circuit | |
3037 | * for the LSPs in list | |
3038 | */ | |
3039 | for (ALL_LIST_ELEMENTS_RO (list, node, lsp)) | |
3040 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
3041 | list_delete (list); | |
eb5d44eb | 3042 | } |
eb5d44eb | 3043 | |
3044 | return retval; | |
3045 | } | |
3046 | ||
3047 | int | |
3048 | send_l1_psnp (struct thread *thread) | |
3049 | { | |
3050 | ||
3051 | struct isis_circuit *circuit; | |
3052 | int retval = ISIS_OK; | |
3053 | ||
3054 | circuit = THREAD_ARG (thread); | |
3055 | assert (circuit); | |
3056 | ||
3057 | circuit->t_send_psnp[0] = NULL; | |
3058 | ||
3059 | send_psnp (1, circuit); | |
3060 | /* set next timer thread */ | |
f390d2c7 | 3061 | THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit, |
3062 | isis_jitter (circuit->psnp_interval[0], PSNP_JITTER)); | |
eb5d44eb | 3063 | |
3064 | return retval; | |
3065 | } | |
3066 | ||
3067 | /* | |
3068 | * 7.3.15.4 action on expiration of partial SNP interval | |
3069 | * level 2 | |
3070 | */ | |
3071 | int | |
3072 | send_l2_psnp (struct thread *thread) | |
3073 | { | |
eb5d44eb | 3074 | struct isis_circuit *circuit; |
3075 | int retval = ISIS_OK; | |
3076 | ||
3077 | circuit = THREAD_ARG (thread); | |
3078 | assert (circuit); | |
3079 | ||
3080 | circuit->t_send_psnp[1] = NULL; | |
3081 | ||
3082 | send_psnp (2, circuit); | |
3083 | ||
3084 | /* set next timer thread */ | |
f390d2c7 | 3085 | THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit, |
3086 | isis_jitter (circuit->psnp_interval[1], PSNP_JITTER)); | |
eb5d44eb | 3087 | |
3088 | return retval; | |
3089 | } | |
3090 | ||
eb5d44eb | 3091 | /* |
3092 | * ISO 10589 - 7.3.14.3 | |
3093 | */ | |
3094 | int | |
3095 | send_lsp (struct thread *thread) | |
3096 | { | |
3097 | struct isis_circuit *circuit; | |
3098 | struct isis_lsp *lsp; | |
3099 | struct listnode *node; | |
cfd1f27b | 3100 | int clear_srm = 1; |
3f045a08 | 3101 | int retval = ISIS_OK; |
eb5d44eb | 3102 | |
3103 | circuit = THREAD_ARG (thread); | |
3104 | assert (circuit); | |
3105 | ||
cfd1f27b CF |
3106 | if (!circuit->lsp_queue) |
3107 | return ISIS_OK; | |
eb5d44eb | 3108 | |
0fece074 AS |
3109 | node = listhead (circuit->lsp_queue); |
3110 | ||
3111 | /* | |
3112 | * Handle case where there are no LSPs on the queue. This can | |
3113 | * happen, for instance, if an adjacency goes down before this | |
3114 | * thread gets a chance to run. | |
3115 | */ | |
3116 | if (!node) | |
cfd1f27b | 3117 | return ISIS_OK; |
0fece074 | 3118 | |
cfd1f27b CF |
3119 | /* |
3120 | * Delete LSP from lsp_queue. If it's still in queue, it is assumed | |
3121 | * as 'transmit pending', but send_lsp may never be called again. | |
3122 | * Retry will happen because SRM flag will not be cleared. | |
3123 | */ | |
0fece074 | 3124 | lsp = listgetdata(node); |
cfd1f27b CF |
3125 | list_delete_node (circuit->lsp_queue, node); |
3126 | ||
3127 | /* Set the last-cleared time if the queue is empty. */ | |
3128 | /* TODO: Is is possible that new lsps keep being added to the queue | |
3129 | * that the queue is never empty? */ | |
3130 | if (list_isempty (circuit->lsp_queue)) | |
3131 | circuit->lsp_queue_last_cleared = time (NULL); | |
3132 | ||
3133 | if (circuit->state != C_STATE_UP || circuit->is_passive == 1) | |
3134 | goto out; | |
eb5d44eb | 3135 | |
3f045a08 JB |
3136 | /* |
3137 | * Do not send if levels do not match | |
3138 | */ | |
3139 | if (!(lsp->level & circuit->is_type)) | |
cfd1f27b | 3140 | goto out; |
f390d2c7 | 3141 | |
3f045a08 JB |
3142 | /* |
3143 | * Do not send if we do not have adjacencies in state up on the circuit | |
3144 | */ | |
3145 | if (circuit->upadjcount[lsp->level - 1] == 0) | |
cfd1f27b CF |
3146 | goto out; |
3147 | ||
3148 | /* stream_copy will assert and stop program execution if LSP is larger than | |
3149 | * the circuit's MTU. So handle and log this case here. */ | |
3150 | if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) | |
3151 | { | |
3152 | zlog_err("ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x," | |
3153 | " cksum 0x%04x, lifetime %us on %s. LSP Size is %zu" | |
3154 | " while interface stream size is %zu.", | |
3155 | circuit->area->area_tag, lsp->level, | |
3156 | rawlspid_print(lsp->lsp_header->lsp_id), | |
3157 | ntohl(lsp->lsp_header->seq_num), | |
3158 | ntohs(lsp->lsp_header->checksum), | |
3159 | ntohs(lsp->lsp_header->rem_lifetime), | |
3160 | circuit->interface->name, | |
3161 | stream_get_endp(lsp->pdu), | |
3162 | stream_get_size(circuit->snd_stream)); | |
3163 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
3164 | zlog_dump_data(STREAM_DATA(lsp->pdu), stream_get_endp(lsp->pdu)); | |
3165 | retval = ISIS_ERROR; | |
3166 | goto out; | |
3f045a08 | 3167 | } |
f390d2c7 | 3168 | |
3f045a08 JB |
3169 | /* copy our lsp to the send buffer */ |
3170 | stream_copy (circuit->snd_stream, lsp->pdu); | |
eb5d44eb | 3171 | |
3f045a08 JB |
3172 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
3173 | { | |
3174 | zlog_debug | |
0232bb72 | 3175 | ("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08x, cksum 0x%04x," |
3f045a08 JB |
3176 | " lifetime %us on %s", circuit->area->area_tag, lsp->level, |
3177 | rawlspid_print (lsp->lsp_header->lsp_id), | |
3178 | ntohl (lsp->lsp_header->seq_num), | |
3179 | ntohs (lsp->lsp_header->checksum), | |
3180 | ntohs (lsp->lsp_header->rem_lifetime), | |
3181 | circuit->interface->name); | |
3182 | if (isis->debugs & DEBUG_PACKET_DUMP) | |
3183 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), | |
3184 | stream_get_endp (circuit->snd_stream)); | |
3185 | } | |
3186 | ||
cfd1f27b | 3187 | clear_srm = 0; |
3f045a08 JB |
3188 | retval = circuit->tx (circuit, lsp->level); |
3189 | if (retval != ISIS_OK) | |
3190 | { | |
cfd1f27b | 3191 | zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed %s", |
3f045a08 | 3192 | circuit->area->area_tag, lsp->level, |
cfd1f27b CF |
3193 | circuit->interface->name, |
3194 | (retval == ISIS_WARNING) ? "temporarily" : "permanently"); | |
3f045a08 | 3195 | } |
f390d2c7 | 3196 | |
cfd1f27b CF |
3197 | out: |
3198 | if (clear_srm | |
3199 | || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST) | |
3200 | || (retval != ISIS_OK && retval != ISIS_WARNING)) | |
3201 | { | |
3202 | /* SRM flag will trigger retransmission. We will not retransmit if we | |
3203 | * encountered a fatal error. | |
3204 | * On success, they should only be cleared if it's a broadcast circuit. | |
3205 | * On a P2P circuit, we will wait for the ack from the neighbor to clear | |
3206 | * the fag. | |
3207 | */ | |
3208 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
3209 | } | |
eb5d44eb | 3210 | |
3211 | return retval; | |
f390d2c7 | 3212 | } |
eb5d44eb | 3213 | |
3214 | int | |
f390d2c7 | 3215 | ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit, |
3216 | int level) | |
eb5d44eb | 3217 | { |
3218 | unsigned long lenp; | |
3219 | int retval; | |
3220 | u_int16_t length; | |
3221 | struct isis_fixed_hdr fixed_hdr; | |
3222 | ||
b20ccb3a | 3223 | isis_circuit_stream(circuit, &circuit->snd_stream); |
eb5d44eb | 3224 | |
3f045a08 JB |
3225 | // fill_llc_hdr (stream); |
3226 | if (level == IS_LEVEL_1) | |
f390d2c7 | 3227 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, |
3228 | circuit->snd_stream); | |
eb5d44eb | 3229 | else |
f390d2c7 | 3230 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, |
3231 | circuit->snd_stream); | |
eb5d44eb | 3232 | |
3233 | ||
9985f83c | 3234 | lenp = stream_get_endp (circuit->snd_stream); |
f390d2c7 | 3235 | stream_putw (circuit->snd_stream, 0); /* PDU length */ |
3236 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
eb5d44eb | 3237 | stream_putc (circuit->snd_stream, circuit->idx); |
f390d2c7 | 3238 | stream_putc (circuit->snd_stream, 9); /* code */ |
3239 | stream_putc (circuit->snd_stream, 16); /* len */ | |
eb5d44eb | 3240 | |
f390d2c7 | 3241 | stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime)); |
3242 | stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2); | |
3243 | stream_putl (circuit->snd_stream, ntohl (hdr->seq_num)); | |
3244 | stream_putw (circuit->snd_stream, ntohs (hdr->checksum)); | |
eb5d44eb | 3245 | |
9985f83c | 3246 | length = (u_int16_t) stream_get_endp (circuit->snd_stream); |
eb5d44eb | 3247 | /* Update PDU length */ |
3248 | stream_putw_at (circuit->snd_stream, lenp, length); | |
3249 | ||
3250 | retval = circuit->tx (circuit, level); | |
3f045a08 JB |
3251 | if (retval != ISIS_OK) |
3252 | zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed", | |
3253 | circuit->area->area_tag, level, | |
3254 | circuit->interface->name); | |
eb5d44eb | 3255 | |
3256 | return retval; | |
3257 | } |