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