1 /* $NetBSD: sctp_asconf.c,v 1.1 2015/10/13 21:28:35 rjs Exp $ */ 2 /* $KAME: sctp_asconf.c,v 1.25 2005/06/16 20:44:24 jinmei Exp $ */ 3 4 /* 5 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: sctp_asconf.c,v 1.1 2015/10/13 21:28:35 rjs Exp $"); 34 35 #ifdef _KERNEL_OPT 36 #include "opt_ipsec.h" 37 #include "opt_inet.h" 38 #include "opt_sctp.h" 39 #endif /* _KERNEL_OPT */ 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/malloc.h> 44 #include <sys/mbuf.h> 45 #include <sys/socket.h> 46 #include <sys/socketvar.h> 47 #include <sys/kernel.h> 48 #include <sys/sysctl.h> 49 50 #include <net/if.h> 51 #include <net/if_types.h> 52 #include <net/route.h> 53 54 #include <netinet/in.h> 55 #include <netinet/in_systm.h> 56 #include <netinet/ip.h> 57 #include <netinet/in_pcb.h> 58 #include <netinet/in_var.h> 59 #include <netinet/ip_var.h> 60 61 #ifdef INET6 62 #include <netinet/ip6.h> 63 #include <netinet6/ip6_var.h> 64 #include <netinet6/in6_pcb.h> 65 #include <netinet/icmp6.h> 66 #include <netinet6/nd6.h> 67 #include <netinet6/scope6_var.h> 68 #endif /* INET6 */ 69 70 #include <netinet/in_pcb.h> 71 72 #include <netinet/sctp_var.h> 73 #include <netinet/sctp_pcb.h> 74 #include <netinet/sctp_header.h> 75 #include <netinet/sctputil.h> 76 #include <netinet/sctp_output.h> 77 #include <netinet/sctp_asconf.h> 78 79 /* 80 * debug flags: 81 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors 82 * SCTP_DEBUG_ASCONF2: detailed info 83 */ 84 #ifdef SCTP_DEBUG 85 extern u_int32_t sctp_debug_on; 86 #endif /* SCTP_DEBUG */ 87 88 /* 89 * draft-ietf-tsvwg-addip-sctp 90 * 91 * Address management only currently supported 92 * For the bound all case: 93 * the asoc local addr list is always a "DO NOT USE" list 94 * For the subset bound case: 95 * If ASCONFs are allowed: 96 * the endpoint local addr list is the usable address list 97 * the asoc local addr list is the "DO NOT USE" list 98 * If ASCONFs are not allowed: 99 * the endpoint local addr list is the default usable list 100 * the asoc local addr list is the usable address list 101 * 102 * An ASCONF parameter queue exists per asoc which holds the pending 103 * address operations. Lists are updated upon receipt of ASCONF-ACK. 104 * 105 * Deleted addresses are always immediately removed from the lists as 106 * they will (shortly) no longer exist in the kernel. We send ASCONFs 107 * as a courtesy, only if allowed. 108 */ 109 110 /* 111 * ASCONF parameter processing 112 * response_required: set if a reply is required (eg. SUCCESS_REPORT) 113 * returns a mbuf to an "error" response parameter or NULL/"success" if ok 114 * FIX: allocating this many mbufs on the fly is pretty inefficient... 115 */ 116 117 static struct mbuf * 118 sctp_asconf_success_response(uint32_t id) 119 { 120 struct mbuf *m_reply = NULL; 121 struct sctp_asconf_paramhdr *aph; 122 123 MGET(m_reply, M_DONTWAIT, MT_DATA); 124 if (m_reply == NULL) { 125 #ifdef SCTP_DEBUG 126 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 127 printf("asconf_success_response: couldn't get mbuf!\n"); 128 } 129 #endif /* SCTP_DEBUG */ 130 return NULL; 131 } 132 aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 133 aph->correlation_id = id; 134 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT); 135 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr); 136 m_reply->m_len = aph->ph.param_length; 137 aph->ph.param_length = htons(aph->ph.param_length); 138 139 return m_reply; 140 } 141 142 static struct mbuf * 143 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv, 144 uint16_t tlv_length) 145 { 146 struct mbuf *m_reply = NULL; 147 struct sctp_asconf_paramhdr *aph; 148 struct sctp_error_cause *error; 149 uint8_t *tlv; 150 151 MGET(m_reply, M_DONTWAIT, MT_DATA); 152 if (m_reply == NULL) { 153 #ifdef SCTP_DEBUG 154 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 155 printf("asconf_error_response: couldn't get mbuf!\n"); 156 } 157 #endif /* SCTP_DEBUG */ 158 return NULL; 159 } 160 aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 161 error = (struct sctp_error_cause *)(aph + 1); 162 163 aph->correlation_id = id; 164 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND); 165 error->code = htons(cause); 166 error->length = tlv_length + sizeof(struct sctp_error_cause); 167 aph->ph.param_length = error->length + 168 sizeof(struct sctp_asconf_paramhdr); 169 170 if (aph->ph.param_length > MLEN) { 171 #ifdef SCTP_DEBUG 172 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 173 printf("asconf_error_response: tlv_length (%xh) too big\n", 174 tlv_length); 175 } 176 #endif /* SCTP_DEBUG */ 177 sctp_m_freem(m_reply); /* discard */ 178 return NULL; 179 } 180 181 if (error_tlv != NULL) { 182 tlv = (uint8_t *)(error + 1); 183 memcpy(tlv, error_tlv, tlv_length); 184 } 185 186 m_reply->m_len = aph->ph.param_length; 187 error->length = htons(error->length); 188 aph->ph.param_length = htons(aph->ph.param_length); 189 190 return m_reply; 191 } 192 193 static struct mbuf * 194 sctp_process_asconf_add_ip(struct sctp_asconf_paramhdr *aph, 195 struct sctp_tcb *stcb, int response_required) 196 { 197 struct mbuf *m_reply = NULL; 198 struct sockaddr_storage sa_store; 199 struct sctp_ipv4addr_param *v4addr; 200 uint16_t param_type, param_length, aparam_length; 201 struct sockaddr *sa; 202 struct sockaddr_in *sin; 203 #ifdef INET6 204 struct sockaddr_in6 *sin6; 205 struct sctp_ipv6addr_param *v6addr; 206 #endif /* INET6 */ 207 208 aparam_length = ntohs(aph->ph.param_length); 209 v4addr = (struct sctp_ipv4addr_param *)(aph + 1); 210 #ifdef INET6 211 v6addr = (struct sctp_ipv6addr_param *)(aph + 1); 212 #endif /* INET6 */ 213 param_type = ntohs(v4addr->ph.param_type); 214 param_length = ntohs(v4addr->ph.param_length); 215 216 sa = (struct sockaddr *)&sa_store; 217 switch (param_type) { 218 case SCTP_IPV4_ADDRESS: 219 if (param_length != sizeof(struct sctp_ipv4addr_param)) { 220 /* invalid param size */ 221 return NULL; 222 } 223 sin = (struct sockaddr_in *)&sa_store; 224 memset(sin, 0, sizeof(*sin)); 225 sin->sin_family = AF_INET; 226 sin->sin_len = sizeof(struct sockaddr_in); 227 sin->sin_port = stcb->rport; 228 sin->sin_addr.s_addr = v4addr->addr; 229 #ifdef SCTP_DEBUG 230 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 231 printf("process_asconf_add_ip: adding "); 232 sctp_print_address(sa); 233 } 234 #endif /* SCTP_DEBUG */ 235 break; 236 case SCTP_IPV6_ADDRESS: 237 #ifdef INET6 238 if (param_length != sizeof(struct sctp_ipv6addr_param)) { 239 /* invalid param size */ 240 return NULL; 241 } 242 sin6 = (struct sockaddr_in6 *)&sa_store; 243 memset(sin6, 0, sizeof(*sin6)); 244 sin6->sin6_family = AF_INET6; 245 sin6->sin6_len = sizeof(struct sockaddr_in6); 246 sin6->sin6_port = stcb->rport; 247 memcpy((void *)&sin6->sin6_addr, v6addr->addr, 248 sizeof(struct in6_addr)); 249 #ifdef SCTP_DEBUG 250 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 251 printf("process_asconf_add_ip: adding "); 252 sctp_print_address(sa); 253 } 254 #endif /* SCTP_DEBUG */ 255 #else 256 /* IPv6 not enabled! */ 257 /* FIX ME: currently sends back an invalid param error */ 258 m_reply = sctp_asconf_error_response(aph->correlation_id, 259 SCTP_ERROR_INVALID_PARAM, (uint8_t *)aph, aparam_length); 260 #ifdef SCTP_DEBUG 261 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 262 printf("process_asconf_add_ip: v6 disabled- skipping "); 263 sctp_print_address(sa); 264 } 265 #endif /* SCTP_DEBUG */ 266 return m_reply; 267 #endif /* INET6 */ 268 break; 269 default: 270 m_reply = sctp_asconf_error_response(aph->correlation_id, 271 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph, 272 aparam_length); 273 return m_reply; 274 } /* end switch */ 275 276 /* add the address */ 277 if (sctp_add_remote_addr(stcb, sa, 0, 6) != 0) { 278 #ifdef SCTP_DEBUG 279 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 280 printf("process_asconf_add_ip: error adding address\n"); 281 } 282 #endif /* SCTP_DEBUG */ 283 m_reply = sctp_asconf_error_response(aph->correlation_id, 284 SCTP_ERROR_RESOURCE_SHORTAGE, (uint8_t *)aph, 285 aparam_length); 286 } else { 287 /* notify upper layer */ 288 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa); 289 if (response_required) { 290 m_reply = 291 sctp_asconf_success_response(aph->correlation_id); 292 } 293 } 294 295 return m_reply; 296 } 297 298 static struct mbuf * 299 sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, 300 struct sctp_tcb *stcb, int response_required) 301 { 302 struct mbuf *m_reply = NULL; 303 struct sockaddr_storage sa_store, sa_source; 304 struct sctp_ipv4addr_param *v4addr; 305 uint16_t param_type, param_length, aparam_length; 306 struct sockaddr *sa; 307 struct sockaddr_in *sin; 308 struct ip *iph; 309 int result; 310 #ifdef INET6 311 struct sockaddr_in6 *sin6; 312 struct sctp_ipv6addr_param *v6addr; 313 #endif /* INET6 */ 314 315 aparam_length = ntohs(aph->ph.param_length); 316 v4addr = (struct sctp_ipv4addr_param *)(aph + 1); 317 #ifdef INET6 318 v6addr = (struct sctp_ipv6addr_param *)(aph + 1); 319 #endif /* INET6 */ 320 param_type = ntohs(v4addr->ph.param_type); 321 param_length = ntohs(v4addr->ph.param_length); 322 323 /* get the source IP address for deletion check */ 324 iph = mtod(m, struct ip *); 325 if (iph->ip_v == IPVERSION) { 326 /* IPv4 source */ 327 sin = (struct sockaddr_in *)&sa_source; 328 memset(sin, 0, sizeof(*sin)); 329 sin->sin_family = AF_INET; 330 sin->sin_len = sizeof(struct sockaddr_in); 331 sin->sin_port = stcb->rport; 332 sin->sin_addr.s_addr = iph->ip_src.s_addr; 333 } 334 #ifdef INET6 335 else if (iph->ip_v == (IPV6_VERSION >> 4)) { 336 /* IPv6 source */ 337 struct ip6_hdr *ip6; 338 339 sin6 = (struct sockaddr_in6 *)&sa_source; 340 memset(sin6, 0, sizeof(*sin6)); 341 sin6->sin6_family = AF_INET6; 342 sin6->sin6_len = sizeof(struct sockaddr_in6); 343 sin6->sin6_port = stcb->rport; 344 ip6 = mtod(m, struct ip6_hdr *); 345 sin6->sin6_addr = ip6->ip6_src; 346 } 347 #endif /* INET6 */ 348 else 349 return NULL; 350 351 sa = (struct sockaddr *)&sa_store; 352 switch (param_type) { 353 case SCTP_IPV4_ADDRESS: 354 if (param_length != sizeof(struct sctp_ipv4addr_param)) { 355 /* invalid param size */ 356 return NULL; 357 } 358 sin = (struct sockaddr_in *)&sa_store; 359 memset(sin, 0, sizeof(*sin)); 360 sin->sin_family = AF_INET; 361 sin->sin_len = sizeof(struct sockaddr_in); 362 sin->sin_port = stcb->rport; 363 sin->sin_addr.s_addr = v4addr->addr; 364 #ifdef SCTP_DEBUG 365 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 366 printf("process_asconf_delete_ip: deleting "); 367 sctp_print_address(sa); 368 } 369 #endif /* SCTP_DEBUG */ 370 break; 371 case SCTP_IPV6_ADDRESS: 372 if (param_length != sizeof(struct sctp_ipv6addr_param)) { 373 /* invalid param size */ 374 return NULL; 375 } 376 #ifdef INET6 377 sin6 = (struct sockaddr_in6 *)&sa_store; 378 memset(sin6, 0, sizeof(*sin6)); 379 sin6->sin6_family = AF_INET6; 380 sin6->sin6_len = sizeof(struct sockaddr_in6); 381 sin6->sin6_port = stcb->rport; 382 memcpy(&sin6->sin6_addr, v6addr->addr, 383 sizeof(struct in6_addr)); 384 #ifdef SCTP_DEBUG 385 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 386 printf("process_asconf_delete_ip: deleting "); 387 sctp_print_address(sa); 388 } 389 #endif /* SCTP_DEBUG */ 390 #else 391 /* IPv6 not enabled! No "action" needed; just ack it */ 392 #ifdef SCTP_DEBUG 393 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 394 printf("process_asconf_delete_ip: v6 disabled- ignoring: "); 395 sctp_print_address(sa); 396 } 397 #endif /* SCTP_DEBUG */ 398 /* just respond with a "success" ASCONF-ACK */ 399 return NULL; 400 #endif /* INET6 */ 401 break; 402 default: 403 m_reply = sctp_asconf_error_response(aph->correlation_id, 404 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph, 405 aparam_length); 406 return m_reply; 407 } /* end switch */ 408 409 /* make sure the source address is not being deleted */ 410 if ((memcmp(sa, &sa_source, sizeof(struct sockaddr_in)) == 0) 411 #ifdef INET6 412 || (memcmp(sa, &sa_source, sizeof(struct sockaddr_in6)) == 0) 413 #endif /* INET6 */ 414 ) { 415 /* trying to delete the source address! */ 416 #ifdef SCTP_DEBUG 417 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 418 printf("process_asconf_delete_ip: tried to delete source addr\n"); 419 } 420 #endif /* SCTP_DEBUG */ 421 m_reply = sctp_asconf_error_response(aph->correlation_id, 422 SCTP_ERROR_DELETE_SOURCE_ADDR, (uint8_t *)aph, 423 aparam_length); 424 return m_reply; 425 } 426 427 /* delete the address */ 428 result = sctp_del_remote_addr(stcb, sa); 429 /* 430 * note if result == -2, the address doesn't exist in the asoc 431 * but since it's being deleted anyways, we just ack the delete 432 * -- but this probably means something has already gone awry 433 */ 434 if (result == -1) { 435 /* only one address in the asoc */ 436 #ifdef SCTP_DEBUG 437 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 438 printf("process_asconf_delete_ip: tried to delete last IP addr!\n"); 439 } 440 #endif /* SCTP_DEBUG */ 441 m_reply = sctp_asconf_error_response(aph->correlation_id, 442 SCTP_ERROR_DELETE_LAST_ADDR, (uint8_t *)aph, 443 aparam_length); 444 } else { 445 /* notify upper layer */ 446 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa); 447 } 448 449 if (response_required) { 450 m_reply = sctp_asconf_success_response(aph->correlation_id); 451 } 452 return m_reply; 453 } 454 455 static struct mbuf * 456 sctp_process_asconf_set_primary(struct sctp_asconf_paramhdr *aph, 457 struct sctp_tcb *stcb, int response_required) 458 { 459 struct mbuf *m_reply = NULL; 460 struct sockaddr_storage sa_store; 461 struct sctp_ipv4addr_param *v4addr; 462 uint16_t param_type, param_length, aparam_length; 463 struct sockaddr *sa; 464 struct sockaddr_in *sin; 465 #ifdef INET6 466 struct sockaddr_in6 *sin6; 467 struct sctp_ipv6addr_param *v6addr; 468 #endif /* INET6 */ 469 470 aparam_length = ntohs(aph->ph.param_length); 471 v4addr = (struct sctp_ipv4addr_param *)(aph + 1); 472 #ifdef INET6 473 v6addr = (struct sctp_ipv6addr_param *)(aph + 1); 474 #endif /* INET6 */ 475 param_type = ntohs(v4addr->ph.param_type); 476 param_length = ntohs(v4addr->ph.param_length); 477 478 sa = (struct sockaddr *)&sa_store; 479 switch (param_type) { 480 case SCTP_IPV4_ADDRESS: 481 if (param_length != sizeof(struct sctp_ipv4addr_param)) { 482 /* invalid param size */ 483 return NULL; 484 } 485 sin = (struct sockaddr_in *)&sa_store; 486 memset(sin, 0, sizeof(*sin)); 487 sin->sin_family = AF_INET; 488 sin->sin_len = sizeof(struct sockaddr_in); 489 sin->sin_addr.s_addr = v4addr->addr; 490 #ifdef SCTP_DEBUG 491 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 492 printf("process_asconf_set_primary: "); 493 sctp_print_address(sa); 494 } 495 #endif /* SCTP_DEBUG */ 496 break; 497 case SCTP_IPV6_ADDRESS: 498 if (param_length != sizeof(struct sctp_ipv6addr_param)) { 499 /* invalid param size */ 500 return NULL; 501 } 502 #ifdef INET6 503 sin6 = (struct sockaddr_in6 *)&sa_store; 504 memset(sin6, 0, sizeof(*sin6)); 505 sin6->sin6_family = AF_INET6; 506 sin6->sin6_len = sizeof(struct sockaddr_in6); 507 memcpy((void *)&sin6->sin6_addr, v6addr->addr, 508 sizeof(struct in6_addr)); 509 #ifdef SCTP_DEBUG 510 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 511 printf("process_asconf_set_primary: "); 512 sctp_print_address(sa); 513 } 514 #endif /* SCTP_DEBUG */ 515 #else 516 /* IPv6 not enabled! No "action" needed; just ack it */ 517 #ifdef SCTP_DEBUG 518 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 519 printf("process_asconf_set_primary: v6 disabled- ignoring: "); 520 sctp_print_address(sa); 521 } 522 #endif /* SCTP_DEBUG */ 523 /* just respond with a "success" ASCONF-ACK */ 524 return NULL; 525 #endif /* INET6 */ 526 break; 527 default: 528 m_reply = sctp_asconf_error_response(aph->correlation_id, 529 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph, 530 aparam_length); 531 return m_reply; 532 } /* end switch */ 533 534 /* set the primary address */ 535 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) { 536 #ifdef SCTP_DEBUG 537 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 538 printf("process_asconf_set_primary: primary address set\n"); 539 } 540 #endif /* SCTP_DEBUG */ 541 /* notify upper layer */ 542 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa); 543 544 if (response_required) { 545 m_reply = sctp_asconf_success_response(aph->correlation_id); 546 } 547 } else { 548 /* couldn't set the requested primary address! */ 549 #ifdef SCTP_DEBUG 550 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 551 printf("process_asconf_set_primary: set primary failed!\n"); 552 } 553 #endif /* SCTP_DEBUG */ 554 /* must have been an invalid address, so report */ 555 m_reply = sctp_asconf_error_response(aph->correlation_id, 556 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph, 557 aparam_length); 558 } 559 560 return m_reply; 561 } 562 563 /* 564 * handles an ASCONF chunk 565 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK 566 */ 567 void 568 sctp_handle_asconf(struct mbuf *m, unsigned int offset, struct sctp_asconf_chunk *cp, 569 struct sctp_tcb *stcb, struct sctp_nets *net) 570 { 571 struct sctp_association *asoc; 572 uint32_t serial_num; 573 struct mbuf *m_ack, *m_result, *m_tail; 574 struct sctp_asconf_ack_chunk *ack_cp; 575 struct sctp_asconf_paramhdr *aph, *ack_aph; 576 struct sctp_ipv6addr_param *p_addr; 577 unsigned int asconf_limit; 578 int error = 0; /* did an error occur? */ 579 /* asconf param buffer */ 580 static u_int8_t aparam_buf[DEFAULT_PARAM_BUFFER]; 581 582 /* verify minimum length */ 583 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) { 584 #ifdef SCTP_DEBUG 585 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 586 printf("handle_asconf: chunk too small = %xh\n", 587 ntohs(cp->ch.chunk_length)); 588 } 589 #endif /* SCTP_DEBUG */ 590 return; 591 } 592 593 asoc = &stcb->asoc; 594 serial_num = ntohl(cp->serial_number); 595 596 if (serial_num == asoc->asconf_seq_in) { 597 /* got a duplicate ASCONF */ 598 #ifdef SCTP_DEBUG 599 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 600 printf("handle_asconf: got duplicate serial number = %xh\n", 601 serial_num); 602 } 603 #endif /* SCTP_DEBUG */ 604 /* resend last ASCONF-ACK... */ 605 sctp_send_asconf_ack(stcb, 1); 606 return; 607 } else if (serial_num != (asoc->asconf_seq_in + 1)) { 608 #ifdef SCTP_DEBUG 609 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 610 printf("handle_asconf: incorrect serial number = %xh (expected next = %xh)\n", 611 serial_num, asoc->asconf_seq_in+1); 612 } 613 #endif /* SCTP_DEBUG */ 614 return; 615 } 616 617 /* it's the expected "next" sequence number, so process it */ 618 asoc->asconf_seq_in = serial_num; /* update sequence */ 619 /* get length of all the param's in the ASCONF */ 620 asconf_limit = offset + ntohs(cp->ch.chunk_length); 621 #ifdef SCTP_DEBUG 622 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 623 printf("handle_asconf: asconf_limit=%u, sequence=%xh\n", 624 asconf_limit, serial_num); 625 } 626 #endif /* SCTP_DEBUG */ 627 if (asoc->last_asconf_ack_sent != NULL) { 628 /* free last ASCONF-ACK message sent */ 629 sctp_m_freem(asoc->last_asconf_ack_sent); 630 asoc->last_asconf_ack_sent = NULL; 631 } 632 MGETHDR(m_ack, M_DONTWAIT, MT_DATA); 633 if (m_ack == NULL) { 634 #ifdef SCTP_DEBUG 635 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 636 printf("handle_asconf: couldn't get mbuf!\n"); 637 } 638 #endif /* SCTP_DEBUG */ 639 return; 640 } 641 m_tail = m_ack; /* current reply chain's tail */ 642 643 /* fill in ASCONF-ACK header */ 644 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *); 645 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK; 646 ack_cp->ch.chunk_flags = 0; 647 ack_cp->serial_number = htonl(serial_num); 648 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */ 649 m_ack->m_len = sizeof(struct sctp_asconf_ack_chunk); 650 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk); 651 m_ack->m_pkthdr.len = sizeof(struct sctp_asconf_ack_chunk); 652 653 /* skip the lookup address parameter */ 654 offset += sizeof(struct sctp_asconf_chunk); 655 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf); 656 if (p_addr == NULL) { 657 #ifdef SCTP_DEBUG 658 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 659 printf("handle_asconf: couldn't get lookup addr!\n"); 660 } 661 #endif /* SCTP_DEBUG */ 662 663 /* respond with a missing/invalid mandatory parameter error */ 664 return; 665 } 666 /* param_length is already validated in process_control... */ 667 offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */ 668 669 /* get pointer to first asconf param in ASCONF */ 670 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf); 671 /* get pointer to first asconf param in ASCONF-ACK */ 672 if (aph == NULL) { 673 printf("Gak in asconf\n"); 674 return; 675 } 676 ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, vaddr_t) + sizeof(struct sctp_asconf_ack_chunk)); 677 if (ack_aph == NULL) { 678 printf("Gak in asconf2\n"); 679 return; 680 } 681 682 /* process through all parameters */ 683 while (aph != NULL) { 684 unsigned int param_length, param_type; 685 686 param_type = ntohs(aph->ph.param_type); 687 param_length = ntohs(aph->ph.param_length); 688 if (offset + param_length > asconf_limit) { 689 /* parameter goes beyond end of chunk! */ 690 sctp_m_freem(m_ack); 691 return; 692 } 693 m_result = NULL; 694 695 if (param_length > sizeof(aparam_buf)) { 696 #ifdef SCTP_DEBUG 697 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 698 printf("handle_asconf: param length (%u) larger than buffer size!\n", param_length); 699 } 700 #endif /* SCTP_DEBUG */ 701 sctp_m_freem(m_ack); 702 return; 703 } 704 if (param_length <= sizeof(struct sctp_paramhdr)) { 705 #ifdef SCTP_DEBUG 706 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 707 printf("handle_asconf: param length (%u) too short\n", param_length); 708 } 709 #endif /* SCTP_DEBUG */ 710 sctp_m_freem(m_ack); 711 } 712 713 /* get the entire parameter */ 714 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 715 if (aph == NULL) { 716 printf("Gag\n"); 717 sctp_m_freem(m_ack); 718 return; 719 } 720 switch (param_type) { 721 case SCTP_ADD_IP_ADDRESS: 722 asoc->peer_supports_asconf = 1; 723 m_result = sctp_process_asconf_add_ip(aph, stcb, error); 724 break; 725 case SCTP_DEL_IP_ADDRESS: 726 asoc->peer_supports_asconf = 1; 727 m_result = sctp_process_asconf_delete_ip(m, aph, stcb, 728 error); 729 break; 730 case SCTP_ERROR_CAUSE_IND: 731 /* not valid in an ASCONF chunk */ 732 break; 733 case SCTP_SET_PRIM_ADDR: 734 asoc->peer_supports_asconf_setprim = 1; 735 m_result = sctp_process_asconf_set_primary(aph, stcb, 736 error); 737 break; 738 case SCTP_SUCCESS_REPORT: 739 /* not valid in an ASCONF chunk */ 740 break; 741 case SCTP_ULP_ADAPTION: 742 /* FIX */ 743 break; 744 default: 745 if ((param_type & 0x8000) == 0) { 746 /* Been told to STOP at this param */ 747 asconf_limit = offset; 748 /* FIX FIX - We need to call sctp_arethere_unrecognized_parameters() 749 * to get a operr and send it for any param's with the 750 * 0x4000 bit set OR do it here ourselves... note we still 751 * must STOP if the 0x8000 bit is clear. 752 */ 753 } 754 /* unknown/invalid param type */ 755 break; 756 } /* switch */ 757 758 /* add any (error) result to the reply mbuf chain */ 759 if (m_result != NULL) { 760 #ifdef SCTP_DEBUG 761 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 762 printf("handle_asconf: adding reply...\n"); 763 } 764 #endif /* SCTP_DEBUG */ 765 m_tail->m_next = m_result; 766 m_tail = m_result; 767 /* update lengths, make sure it's aligned too */ 768 m_result->m_len = SCTP_SIZE32(m_result->m_len); 769 m_ack->m_pkthdr.len += m_result->m_len; 770 ack_cp->ch.chunk_length += m_result->m_len; 771 /* set flag to force success reports */ 772 error = 1; 773 } 774 775 offset += SCTP_SIZE32(param_length); 776 /* update remaining ASCONF message length to process */ 777 if (offset >= asconf_limit) { 778 /* no more data in the mbuf chain */ 779 break; 780 } 781 /* get pointer to next asconf param */ 782 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 783 sizeof(struct sctp_asconf_paramhdr), 784 (uint8_t *)&aparam_buf); 785 if (aph == NULL) { 786 /* can't get an asconf paramhdr */ 787 #ifdef SCTP_DEBUG 788 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 789 printf("handle_asconf: can't get asconf param hdr!\n"); 790 } 791 #endif /* SCTP_DEBUG */ 792 /* FIX ME - add error here... */ 793 } 794 } /* while */ 795 796 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length); 797 /* save the ASCONF-ACK reply */ 798 asoc->last_asconf_ack_sent = m_ack; 799 /* and send (a new one) it out... */ 800 sctp_send_asconf_ack(stcb, 0); 801 } 802 803 /* 804 * does the address match? 805 * returns 0 if not, 1 if so 806 */ 807 static uint32_t 808 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa) 809 { 810 #ifdef INET6 811 if (sa->sa_family == AF_INET6) { 812 /* IPv6 sa address */ 813 /* XXX scopeid */ 814 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 815 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) && 816 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr, 817 sizeof(struct in6_addr)) == 0)) { 818 return (1); 819 } 820 } else 821 #endif /* INET6 */ 822 if (sa->sa_family == AF_INET) { 823 /* IPv4 sa address */ 824 struct sockaddr_in *sin = (struct sockaddr_in *)sa; 825 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) && 826 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr, 827 sizeof(struct in_addr)) == 0)) { 828 return (1); 829 } 830 } 831 return (0); 832 } 833 834 /* 835 * Cleanup for non-responded/OP ERR'd ASCONF 836 */ 837 void 838 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net) 839 { 840 #ifdef SCTP_DEBUG 841 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 842 printf("asconf_cleanup: marking peer ASCONF incapable and cleaning up\n"); 843 } 844 #endif /* SCTP_DEBUG */ 845 /* mark peer as ASCONF incapable */ 846 stcb->asoc.peer_supports_asconf = 0; 847 stcb->asoc.peer_supports_asconf_setprim = 0; 848 /* 849 * clear out any existing asconfs going out 850 */ 851 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net); 852 stcb->asoc.asconf_seq_out++; 853 /* remove the old ASCONF on our outbound queue */ 854 sctp_toss_old_asconf(stcb); 855 } 856 857 /* 858 * process an ADD/DELETE IP ack from peer 859 * ifa: corresponding ifaddr to the address being added/deleted 860 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS 861 * flag: 1=success, 0=failure 862 */ 863 static void 864 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct ifaddr *addr, 865 uint16_t type, uint32_t flag) 866 { 867 868 /* 869 * do the necessary asoc list work- 870 * if we get a failure indication, leave the address on the 871 * "do not use" asoc list 872 * if we get a success indication, remove the address from 873 * the list 874 */ 875 /* 876 * Note: this will only occur for ADD_IP_ADDRESS, since 877 * DEL_IP_ADDRESS is never actually added to the list... 878 */ 879 if (flag) { 880 /* success case, so remove from the list */ 881 sctp_del_local_addr_assoc(stcb, addr); 882 } 883 /* else, leave it on the list */ 884 } 885 886 /* 887 * add an asconf add/delete IP address parameter to the queue 888 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR 889 * returns 0 if completed, non-zero if not completed 890 * NOTE: if adding, but delete already scheduled (and not yet 891 * sent out), simply remove from queue. Same for deleting 892 * an address already scheduled for add. If a duplicate 893 * operation is found, ignore the new one. 894 */ 895 static uint32_t 896 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct ifaddr *ifa, uint16_t type) 897 { 898 struct sctp_asconf_addr *aa, *aa_next; 899 #ifdef SCTP_DEBUG 900 char buf[128]; /* for address in string format */ 901 #endif /* SCTP_DEBUG */ 902 903 /* see if peer supports ASCONF */ 904 if (stcb->asoc.peer_supports_asconf == 0) { 905 #ifdef SCTP_DEBUG 906 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 907 printf("asconf_queue_add: peer doesn't support ASCONF\n"); 908 } 909 #endif /* SCTP_DEBUG */ 910 return (-1); 911 } 912 913 /* make sure the request isn't already in the queue */ 914 for (aa=TAILQ_FIRST(&stcb->asoc.asconf_queue); aa!=NULL; aa=aa_next) { 915 aa_next = TAILQ_NEXT(aa, next); 916 /* address match? */ 917 if (sctp_asconf_addr_match(aa, ifa->ifa_addr) == 0) 918 continue; 919 /* is the request already in queue (sent or not) */ 920 if (aa->ap.aph.ph.param_type == type) { 921 #ifdef SCTP_DEBUG 922 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 923 printf("asconf_queue_add: request already exists\n"); 924 } 925 #endif /* SCTP_DEBUG */ 926 return (-1); 927 } 928 /* is the negative request already in queue, and not sent */ 929 if (aa->sent == 0 && 930 /* add requested, delete already queued */ 931 ((type == SCTP_ADD_IP_ADDRESS && 932 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) || 933 /* delete requested, add already queued */ 934 (type == SCTP_DEL_IP_ADDRESS && 935 aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS))) { 936 /* delete the existing entry in the queue */ 937 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 938 /* take the entry off the appropriate list */ 939 sctp_asconf_addr_mgmt_ack(stcb, aa->ifa, type, 1); 940 /* free the entry */ 941 free(aa, M_PCB); 942 943 #ifdef SCTP_DEBUG 944 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 945 printf("asconf_queue_add: removing 'opposite' queued request\n"); 946 } 947 #endif /* SCTP_DEBUG */ 948 return (-1); 949 } 950 } /* for each aa */ 951 952 /* adding new request to the queue */ 953 aa = malloc(sizeof(*aa), M_PCB, M_NOWAIT); 954 if (aa == NULL) { 955 /* didn't get memory */ 956 #ifdef SCTP_DEBUG 957 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 958 printf("asconf_queue_add: failed to get memory!\n"); 959 } 960 #endif /* SCTP_DEBUG */ 961 return (-1); 962 } 963 /* fill in asconf address parameter fields */ 964 /* top level elements are "networked" during send */ 965 aa->ap.aph.ph.param_type = type; 966 aa->ifa = ifa; 967 /* correlation_id filled in during send routine later... */ 968 if (ifa->ifa_addr->sa_family == AF_INET6) { 969 /* IPv6 address */ 970 struct sockaddr_in6 *sin6; 971 972 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; 973 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 974 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 975 aa->ap.aph.ph.param_length = 976 sizeof(struct sctp_asconf_paramhdr) + 977 sizeof(struct sctp_ipv6addr_param); 978 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 979 sizeof(struct in6_addr)); 980 #ifdef SCTP_DEBUG 981 strlcpy(buf, ip6_sprintf(&sin6->sin6_addr), sizeof(buf)); 982 #endif /* SCTP_DEBUG */ 983 984 } else if (ifa->ifa_addr->sa_family == AF_INET) { 985 /* IPv4 address */ 986 struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr; 987 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 988 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 989 aa->ap.aph.ph.param_length = 990 sizeof(struct sctp_asconf_paramhdr) + 991 sizeof(struct sctp_ipv4addr_param); 992 memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 993 sizeof(struct in_addr)); 994 #ifdef SCTP_DEBUG 995 strlcpy(buf, inet_ntoa(sin->sin_addr), sizeof(buf)); 996 #endif /* SCTP_DEBUG */ 997 } else { 998 /* invalid family! */ 999 return (-1); 1000 } 1001 aa->sent = 0; /* clear sent flag */ 1002 1003 /* 1004 * if we are deleting an address it should go out last 1005 * otherwise, add it to front of the pending queue 1006 */ 1007 if (type == SCTP_ADD_IP_ADDRESS) { 1008 /* add goes to the front of the queue */ 1009 TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next); 1010 #ifdef SCTP_DEBUG 1011 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1012 printf("asconf_queue_add: appended asconf ADD_IP_ADDRESS: %s\n", buf); 1013 } 1014 #endif /* SCTP_DEBUG */ 1015 } else { 1016 /* delete and set primary goes to the back of the queue */ 1017 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1018 #ifdef SCTP_DEBUG 1019 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1020 if (type == SCTP_DEL_IP_ADDRESS) { 1021 printf("asconf_queue_add: inserted asconf DEL_IP_ADDRESS: %s\n", buf); 1022 } else { 1023 printf("asconf_queue_add: inserted asconf SET_PRIM_ADDR: %s\n", buf); 1024 } 1025 } 1026 #endif /* SCTP_DEBUG */ 1027 } 1028 1029 return (0); 1030 } 1031 1032 /* 1033 * add an asconf add/delete IP address parameter to the queue by addr 1034 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR 1035 * returns 0 if completed, non-zero if not completed 1036 * NOTE: if adding, but delete already scheduled (and not yet 1037 * sent out), simply remove from queue. Same for deleting 1038 * an address already scheduled for add. If a duplicate 1039 * operation is found, ignore the new one. 1040 */ 1041 static uint32_t 1042 sctp_asconf_queue_add_sa(struct sctp_tcb *stcb, struct sockaddr *sa, 1043 uint16_t type) 1044 { 1045 struct sctp_asconf_addr *aa, *aa_next; 1046 1047 /* see if peer supports ASCONF */ 1048 if (stcb->asoc.peer_supports_asconf == 0) { 1049 #ifdef SCTP_DEBUG 1050 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1051 printf("asconf_queue_add_sa: peer doesn't support ASCONF\n"); 1052 } 1053 #endif /* SCTP_DEBUG */ 1054 return (-1); 1055 } 1056 1057 /* make sure the request isn't already in the queue */ 1058 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL; 1059 aa = aa_next) { 1060 aa_next = TAILQ_NEXT(aa, next); 1061 /* address match? */ 1062 if (sctp_asconf_addr_match(aa, sa) == 0) 1063 continue; 1064 /* is the request already in queue (sent or not) */ 1065 if (aa->ap.aph.ph.param_type == type) { 1066 #ifdef SCTP_DEBUG 1067 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1068 printf("asconf_queue_add_sa: request already exists\n"); 1069 } 1070 #endif /* SCTP_DEBUG */ 1071 return (-1); 1072 } 1073 1074 /* is the negative request already in queue, and not sent */ 1075 if (aa->sent == 1) 1076 continue; 1077 if (type == SCTP_ADD_IP_ADDRESS && 1078 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 1079 /* add requested, delete already queued */ 1080 1081 /* delete the existing entry in the queue */ 1082 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 1083 /* free the entry */ 1084 free(aa, M_PCB); 1085 #ifdef SCTP_DEBUG 1086 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1087 printf("asconf_queue_add_sa: removing queued delete request\n"); 1088 } 1089 #endif /* SCTP_DEBUG */ 1090 return (-1); 1091 } else if (type == SCTP_DEL_IP_ADDRESS && 1092 aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) { 1093 /* delete requested, add already queued */ 1094 1095 /* delete the existing entry in the queue */ 1096 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 1097 /* take the entry off the appropriate list */ 1098 sctp_asconf_addr_mgmt_ack(stcb, aa->ifa, type, 1); 1099 /* free the entry */ 1100 free(aa, M_PCB); 1101 #ifdef SCTP_DEBUG 1102 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1103 printf("asconf_queue_add_sa: removing queued add request\n"); 1104 } 1105 #endif /* SCTP_DEBUG */ 1106 return (-1); 1107 } 1108 } /* for each aa */ 1109 1110 /* adding new request to the queue */ 1111 aa = malloc(sizeof(*aa), M_PCB, M_NOWAIT); 1112 if (aa == NULL) { 1113 /* didn't get memory */ 1114 #ifdef SCTP_DEBUG 1115 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1116 printf("asconf_queue_add_sa: failed to get memory!\n"); 1117 } 1118 #endif /* SCTP_DEBUG */ 1119 return (-1); 1120 } 1121 /* fill in asconf address parameter fields */ 1122 /* top level elements are "networked" during send */ 1123 aa->ap.aph.ph.param_type = type; 1124 aa->ifa = sctp_find_ifa_by_addr(sa); 1125 /* correlation_id filled in during send routine later... */ 1126 if (sa->sa_family == AF_INET6) { 1127 /* IPv6 address */ 1128 struct sockaddr_in6 *sin6; 1129 1130 sin6 = (struct sockaddr_in6 *)sa; 1131 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1132 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 1133 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param); 1134 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1135 sizeof(struct in6_addr)); 1136 } else if (sa->sa_family == AF_INET) { 1137 /* IPv4 address */ 1138 struct sockaddr_in *sin = (struct sockaddr_in *)sa; 1139 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1140 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 1141 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param); 1142 memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1143 sizeof(struct in_addr)); 1144 } else { 1145 /* invalid family! */ 1146 return (-1); 1147 } 1148 aa->sent = 0; /* clear sent flag */ 1149 1150 /* 1151 * if we are deleting an address it should go out last 1152 * otherwise, add it to front of the pending queue 1153 */ 1154 if (type == SCTP_ADD_IP_ADDRESS) { 1155 /* add goes to the front of the queue */ 1156 TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next); 1157 #ifdef SCTP_DEBUG 1158 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1159 printf("asconf_queue_add_sa: appended asconf ADD_IP_ADDRESS\n"); 1160 } 1161 #endif /* SCTP_DEBUG */ 1162 } else { 1163 /* delete and set primary goes to the back of the queue */ 1164 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1165 #ifdef SCTP_DEBUG 1166 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1167 if (type == SCTP_DEL_IP_ADDRESS) { 1168 printf("asconf_queue_add_sa: inserted asconf DEL_IP_ADDRESS\n"); 1169 } else { 1170 printf("asconf_queue_add_sa: inserted asconf SET_PRIM_ADDR\n"); 1171 } 1172 } 1173 #endif /* SCTP_DEBUG */ 1174 } 1175 1176 return (0); 1177 } 1178 1179 /* 1180 * find a specific asconf param on our "sent" queue 1181 */ 1182 static struct sctp_asconf_addr * 1183 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id) 1184 { 1185 struct sctp_asconf_addr *aa; 1186 1187 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 1188 if (aa->ap.aph.correlation_id == correlation_id && 1189 aa->sent == 1) { 1190 /* found it */ 1191 return (aa); 1192 } 1193 } 1194 /* didn't find it */ 1195 return (NULL); 1196 } 1197 1198 /* 1199 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter 1200 * and do notifications based on the error response 1201 */ 1202 static void 1203 sctp_asconf_process_error(struct sctp_tcb *stcb, 1204 struct sctp_asconf_paramhdr *aph) 1205 { 1206 struct sctp_error_cause *eh; 1207 struct sctp_paramhdr *ph; 1208 uint16_t param_type; 1209 uint16_t error_code; 1210 1211 eh = (struct sctp_error_cause *)(aph + 1); 1212 ph = (struct sctp_paramhdr *)(eh + 1); 1213 /* validate lengths */ 1214 if (htons(eh->length) + sizeof(struct sctp_error_cause) > 1215 htons(aph->ph.param_length)) { 1216 /* invalid error cause length */ 1217 #ifdef SCTP_DEBUG 1218 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1219 printf("asconf_process_error: cause element too long\n"); 1220 } 1221 #endif /* SCTP_DEBUG */ 1222 return; 1223 } 1224 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) > 1225 htons(eh->length)) { 1226 /* invalid included TLV length */ 1227 #ifdef SCTP_DEBUG 1228 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1229 printf("asconf_process_error: included TLV too long\n"); 1230 } 1231 #endif /* SCTP_DEBUG */ 1232 return; 1233 } 1234 1235 /* which error code ? */ 1236 error_code = ntohs(eh->code); 1237 param_type = ntohs(aph->ph.param_type); 1238 /* FIX: this should go back up the REMOTE_ERROR ULP notify */ 1239 switch (error_code) { 1240 case SCTP_ERROR_RESOURCE_SHORTAGE: 1241 /* we allow ourselves to "try again" for this error */ 1242 break; 1243 default: 1244 /* peer can't handle it... */ 1245 switch (param_type) { 1246 case SCTP_ADD_IP_ADDRESS: 1247 case SCTP_DEL_IP_ADDRESS: 1248 stcb->asoc.peer_supports_asconf = 0; 1249 break; 1250 case SCTP_SET_PRIM_ADDR: 1251 stcb->asoc.peer_supports_asconf_setprim = 0; 1252 break; 1253 default: 1254 break; 1255 } 1256 } 1257 } 1258 1259 /* 1260 * process an asconf queue param 1261 * aparam: parameter to process, will be removed from the queue 1262 * flag: 1=success, 0=failure 1263 */ 1264 static void 1265 sctp_asconf_process_param_ack(struct sctp_tcb *stcb, 1266 struct sctp_asconf_addr *aparam, uint32_t flag) 1267 { 1268 uint16_t param_type; 1269 1270 /* process this param */ 1271 param_type = aparam->ap.aph.ph.param_type; 1272 #ifdef SCTP_DEBUG 1273 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1274 printf("process_param_ack: handling asconf parameter type=%xh\n", param_type); 1275 } 1276 #endif /* SCTP_DEBUG */ 1277 switch (param_type) { 1278 case SCTP_ADD_IP_ADDRESS: 1279 #ifdef SCTP_DEBUG 1280 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1281 printf("process_param_ack: added IP address\n"); 1282 } 1283 #endif /* SCTP_DEBUG */ 1284 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, param_type, flag); 1285 break; 1286 case SCTP_DEL_IP_ADDRESS: 1287 #ifdef SCTP_DEBUG 1288 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1289 printf("process_param_ack: deleted IP address\n"); 1290 } 1291 #endif /* SCTP_DEBUG */ 1292 /* nothing really to do... lists already updated */ 1293 break; 1294 case SCTP_SET_PRIM_ADDR: 1295 /* nothing to do... peer may start using this addr */ 1296 if (flag == 0) 1297 stcb->asoc.peer_supports_asconf_setprim = 0; 1298 break; 1299 default: 1300 /* should NEVER happen */ 1301 break; 1302 } /* switch */ 1303 1304 /* remove the param and free it */ 1305 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next); 1306 free(aparam, M_PCB); 1307 } 1308 1309 /* 1310 * cleanup from a bad asconf ack parameter 1311 */ 1312 static void 1313 sctp_asconf_ack_clear(struct sctp_tcb *stcb) 1314 { 1315 /* assume peer doesn't really know how to do asconfs */ 1316 stcb->asoc.peer_supports_asconf = 0; 1317 stcb->asoc.peer_supports_asconf_setprim = 0; 1318 /* XXX we could free the pending queue here */ 1319 } 1320 1321 void 1322 sctp_handle_asconf_ack(struct mbuf *m, int offset, 1323 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb, 1324 struct sctp_nets *net) 1325 { 1326 struct sctp_association *asoc; 1327 uint32_t serial_num; 1328 uint16_t ack_length; 1329 struct sctp_asconf_paramhdr *aph; 1330 struct sctp_asconf_addr *aa, *aa_next; 1331 uint32_t last_error_id = 0; /* last error correlation id */ 1332 uint32_t id; 1333 struct sctp_asconf_addr *ap; 1334 /* asconf param buffer */ 1335 static u_int8_t aparam_buf[DEFAULT_PARAM_BUFFER]; 1336 1337 /* verify minimum length */ 1338 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) { 1339 #ifdef SCTP_DEBUG 1340 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1341 printf("handle_asconf_ack: chunk too small = %xh\n", 1342 ntohs(cp->ch.chunk_length)); 1343 } 1344 #endif /* SCTP_DEBUG */ 1345 return; 1346 } 1347 1348 asoc = &stcb->asoc; 1349 serial_num = ntohl(cp->serial_number); 1350 1351 /* 1352 * NOTE: we may want to handle this differently- currently, we 1353 * will abort when we get an ack for the expected serial number + 1 1354 * (eg. we didn't send it), process an ack normally if it is the 1355 * expected serial number, and re-send the previous ack for *ALL* 1356 * other serial numbers 1357 */ 1358 1359 /* 1360 * if the serial number is the next expected, but I didn't send it, 1361 * abort the asoc, since someone probably just hijacked us... 1362 */ 1363 if (serial_num == (asoc->asconf_seq_out + 1)) { 1364 sctp_abort_an_association(stcb->sctp_ep, stcb, 1365 SCTP_ERROR_ILLEGAL_ASCONF_ACK, NULL); 1366 #ifdef SCTP_DEBUG 1367 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1368 printf("handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n"); 1369 } 1370 #endif /* SCTP_DEBUG */ 1371 return; 1372 } 1373 1374 if (serial_num != asoc->asconf_seq_out) { 1375 /* got a duplicate/unexpected ASCONF-ACK */ 1376 #ifdef SCTP_DEBUG 1377 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1378 printf("handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", serial_num, asoc->asconf_seq_out); 1379 } 1380 #endif /* SCTP_DEBUG */ 1381 return; 1382 } 1383 /* stop our timer */ 1384 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net); 1385 1386 /* process the ASCONF-ACK contents */ 1387 ack_length = ntohs(cp->ch.chunk_length) - 1388 sizeof(struct sctp_asconf_ack_chunk); 1389 offset += sizeof(struct sctp_asconf_ack_chunk); 1390 /* process through all parameters */ 1391 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) { 1392 unsigned int param_length, param_type; 1393 1394 /* get pointer to next asconf parameter */ 1395 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 1396 sizeof(struct sctp_asconf_paramhdr), aparam_buf); 1397 if (aph == NULL) { 1398 /* can't get an asconf paramhdr */ 1399 sctp_asconf_ack_clear(stcb); 1400 return; 1401 } 1402 param_type = ntohs(aph->ph.param_type); 1403 param_length = ntohs(aph->ph.param_length); 1404 if (param_length > ack_length) { 1405 sctp_asconf_ack_clear(stcb); 1406 return; 1407 } 1408 if (param_length < sizeof(struct sctp_paramhdr)) { 1409 sctp_asconf_ack_clear(stcb); 1410 return; 1411 } 1412 1413 /* get the complete parameter... */ 1414 if (param_length > sizeof(aparam_buf)) { 1415 #ifdef SCTP_DEBUG 1416 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1417 printf("param length (%u) larger than buffer size!\n", param_length); 1418 } 1419 #endif /* SCTP_DEBUG */ 1420 sctp_asconf_ack_clear(stcb); 1421 return; 1422 } 1423 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 1424 if (aph == NULL) { 1425 sctp_asconf_ack_clear(stcb); 1426 return; 1427 } 1428 /* correlation_id is transparent to peer, no ntohl needed */ 1429 id = aph->correlation_id; 1430 1431 switch (param_type) { 1432 case SCTP_ERROR_CAUSE_IND: 1433 last_error_id = id; 1434 /* find the corresponding asconf param in our queue */ 1435 ap = sctp_asconf_find_param(stcb, id); 1436 if (ap == NULL) { 1437 /* hmm... can't find this in our queue! */ 1438 break; 1439 } 1440 /* process the parameter, failed flag */ 1441 sctp_asconf_process_param_ack(stcb, ap, 0); 1442 /* process the error response */ 1443 sctp_asconf_process_error(stcb, aph); 1444 break; 1445 case SCTP_SUCCESS_REPORT: 1446 /* find the corresponding asconf param in our queue */ 1447 ap = sctp_asconf_find_param(stcb, id); 1448 if (ap == NULL) { 1449 /* hmm... can't find this in our queue! */ 1450 break; 1451 } 1452 /* process the parameter, success flag */ 1453 sctp_asconf_process_param_ack(stcb, ap, 1); 1454 break; 1455 default: 1456 break; 1457 } /* switch */ 1458 1459 /* update remaining ASCONF-ACK message length to process */ 1460 ack_length -= SCTP_SIZE32(param_length); 1461 if (ack_length <= 0) { 1462 /* no more data in the mbuf chain */ 1463 break; 1464 } 1465 offset += SCTP_SIZE32(param_length); 1466 } /* while */ 1467 1468 /* 1469 * if there are any "sent" params still on the queue, these are 1470 * implicitly "success", or "failed" (if we got an error back) 1471 * ... so process these appropriately 1472 * 1473 * we assume that the correlation_id's are monotonically increasing 1474 * beginning from 1 and that we don't have *that* many outstanding 1475 * at any given time 1476 */ 1477 if (last_error_id == 0) 1478 last_error_id--; /* set to "max" value */ 1479 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL; 1480 aa = aa_next) { 1481 aa_next = TAILQ_NEXT(aa, next); 1482 if (aa->sent == 1) { 1483 /* 1484 * implicitly successful or failed 1485 * if correlation_id < last_error_id, then success 1486 * else, failure 1487 */ 1488 if (aa->ap.aph.correlation_id < last_error_id) 1489 sctp_asconf_process_param_ack(stcb, aa, 1490 SCTP_SUCCESS_REPORT); 1491 else 1492 sctp_asconf_process_param_ack(stcb, aa, 1493 SCTP_ERROR_CAUSE_IND); 1494 } else { 1495 /* 1496 * since we always process in order (FIFO queue) 1497 * if we reach one that hasn't been sent, the 1498 * rest should not have been sent either. 1499 * so, we're done... 1500 */ 1501 break; 1502 } 1503 } 1504 1505 /* update the next sequence number to use */ 1506 asoc->asconf_seq_out++; 1507 /* remove the old ASCONF on our outbound queue */ 1508 sctp_toss_old_asconf(stcb); 1509 /* clear the sent flag to allow new ASCONFs */ 1510 asoc->asconf_sent = 0; 1511 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) { 1512 /* we have more params, so restart our timer */ 1513 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, 1514 stcb, net); 1515 } 1516 } 1517 1518 /* is this an interface that we care about at all? */ 1519 static uint32_t 1520 sctp_is_desired_interface_type(struct ifaddr *ifa) 1521 { 1522 int result; 1523 1524 /* check the interface type to see if it's one we care about */ 1525 switch (ifa->ifa_ifp->if_type) { 1526 case IFT_ETHER: 1527 case IFT_ISO88023: 1528 case IFT_ISO88025: 1529 case IFT_STARLAN: 1530 case IFT_P10: 1531 case IFT_P80: 1532 case IFT_HY: 1533 case IFT_FDDI: 1534 case IFT_PPP: 1535 case IFT_XETHER: 1536 case IFT_SLIP: 1537 case IFT_GIF: 1538 result = 1; 1539 break; 1540 default: 1541 #ifdef SCTP_DEBUG 1542 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1543 printf("ignoring interface type = %u\n", 1544 ifa->ifa_ifp->if_type); 1545 } 1546 #endif /* SCTP_DEBUG */ 1547 result = 0; 1548 } /* end switch */ 1549 1550 return (result); 1551 } 1552 1553 static uint32_t 1554 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa) 1555 { 1556 struct sockaddr_in6 *sin6 /* , *net6 */ ; 1557 /*struct sctp_nets *net;*/ 1558 1559 if (sa->sa_family != AF_INET6) { 1560 /* wrong family */ 1561 return (0); 1562 } 1563 1564 sin6 = (struct sockaddr_in6 *)sa; 1565 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) { 1566 /* not link local address */ 1567 return (0); 1568 } 1569 #if 0 1570 /* hunt through our destination nets list for this scope_id */ 1571 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1572 if ((rtcache_getdst(&net->ro))->sa_family != 1573 AF_INET6) 1574 continue; 1575 net6 = (struct sockaddr_in6 *)rtcache_getdst(&net->ro); 1576 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0) 1577 continue; 1578 if (sctp_is_same_scope(sin6, net6)) { 1579 /* found one */ 1580 return (1); 1581 } 1582 } 1583 #endif 1584 /* didn't find one */ 1585 return (0); 1586 } 1587 1588 /* 1589 * address management functions 1590 */ 1591 static void 1592 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 1593 struct ifaddr *ifa, uint16_t type) 1594 { 1595 int status; 1596 #ifdef SCTP_DEBUG 1597 char buf[128]; /* for address in string format */ 1598 #endif /* SCTP_DEBUG */ 1599 1600 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 && 1601 (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) == 0) { 1602 /* subset bound, no ASCONF allowed case, so ignore */ 1603 return; 1604 } 1605 1606 /* 1607 * note: we know this is not the subset bound, no ASCONF case 1608 * eg. this is boundall or subset bound w/ASCONF allowed 1609 */ 1610 1611 /* first, make sure it's a good address family */ 1612 if (ifa->ifa_addr->sa_family != AF_INET6 && 1613 ifa->ifa_addr->sa_family != AF_INET) { 1614 return; 1615 } 1616 1617 /* make sure we're "allowed" to add this type of addr */ 1618 if (ifa->ifa_addr->sa_family == AF_INET6) { 1619 struct in6_ifaddr *ifa6; 1620 1621 /* invalid if we're not a v6 endpoint */ 1622 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) 1623 return; 1624 /* is the v6 addr really valid ? */ 1625 ifa6 = (struct in6_ifaddr *)ifa; 1626 if (IFA6_IS_DEPRECATED(ifa6) || 1627 (ifa6->ia6_flags & 1628 (IN6_IFF_DETACHED | IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { 1629 /* can't use an invalid address */ 1630 return; 1631 } 1632 } 1633 1634 /* put this address on the "pending/do not use yet" list */ 1635 /* 1636 * Note: we do this primarily for the subset bind case 1637 * We don't have scoping flags at the EP level, so we must 1638 * add link local/site local addresses to the EP, then need 1639 * to "negate" them here. Recall that this routine is only 1640 * called for the subset bound w/ASCONF allowed case. 1641 */ 1642 1643 /* 1644 * do a scope_id check against any link local addresses 1645 * in the destination nets list to see if we should put 1646 * this local address on the pending list or not 1647 * eg. don't put on the list if we have a link local 1648 * destination with the same scope_id 1649 */ 1650 if (type == SCTP_ADD_IP_ADDRESS) { 1651 if (sctp_is_scopeid_in_nets(stcb, ifa->ifa_addr) == 0) { 1652 sctp_add_local_addr_assoc(stcb, ifa); 1653 #ifdef SCTP_DEBUG 1654 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1655 printf("addr_mgmt_assoc: added to pending list "); 1656 sctp_print_address(ifa->ifa_addr); 1657 } 1658 #endif /* SCTP_DEBUG */ 1659 } 1660 } 1661 /* 1662 * check address scope 1663 * if address is out of scope, don't queue anything... 1664 * note: this would leave the address on both inp and asoc lists 1665 */ 1666 if (ifa->ifa_addr->sa_family == AF_INET6) { 1667 struct sockaddr_in6 *sin6; 1668 1669 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; 1670 #ifdef SCTP_DEBUG 1671 strlcpy(buf, ip6_sprintf(&sin6->sin6_addr), sizeof(buf)); 1672 #endif /* SCTP_DEBUG */ 1673 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 1674 /* we skip unspecifed addresses */ 1675 #ifdef SCTP_DEBUG 1676 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1677 printf("addr_mgmt_assoc: unspecified IPv6 addr\n"); 1678 } 1679 #endif /* SCTP_DEBUG */ 1680 return; 1681 } 1682 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 1683 if (stcb->asoc.local_scope == 0) { 1684 #ifdef SCTP_DEBUG 1685 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1686 printf("addr_mgmt_assoc: skipping link local IPv6 addr: %s\n", buf); 1687 } 1688 #endif /* SCTP_DEBUG */ 1689 return; 1690 } 1691 /* is it the right link local scope? */ 1692 if (sctp_is_scopeid_in_nets(stcb, ifa->ifa_addr) == 0) { 1693 #ifdef SCTP_DEBUG 1694 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1695 printf("addr_mgmt_assoc: skipping link local IPv6 addr: %s, wrong scope_id\n", buf); 1696 } 1697 #endif /* SCTP_DEBUG */ 1698 return; 1699 } 1700 } 1701 if (stcb->asoc.site_scope == 0 && 1702 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { 1703 #ifdef SCTP_DEBUG 1704 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1705 printf("addr_mgmt_assoc: skipping site local IPv6 addr: %s\n", buf); 1706 } 1707 #endif /* SCTP_DEBUG */ 1708 return; 1709 } 1710 } else if (ifa->ifa_addr->sa_family == AF_INET) { 1711 struct sockaddr_in *sin; 1712 struct in6pcb *inp6; 1713 1714 inp6 = (struct in6pcb *)&inp->ip_inp.inp; 1715 /* invalid if we are a v6 only endpoint */ 1716 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 1717 (inp6->in6p_flags & IN6P_IPV6_V6ONLY) 1718 ) 1719 return; 1720 1721 sin = (struct sockaddr_in *)ifa->ifa_addr; 1722 #ifdef SCTP_DEBUG 1723 strlcpy(buf, inet_ntoa(sin->sin_addr), sizeof(buf)); 1724 #endif /* SCTP_DEBUG */ 1725 if (sin->sin_addr.s_addr == 0) { 1726 /* we skip unspecifed addresses */ 1727 #ifdef SCTP_DEBUG 1728 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1729 printf("addr_mgmt_assoc: unspecified IPv4 addr\n"); 1730 } 1731 #endif /* SCTP_DEBUG */ 1732 return; 1733 } 1734 if (stcb->asoc.ipv4_local_scope == 0 && 1735 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 1736 #ifdef SCTP_DEBUG 1737 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1738 printf("addr_mgmt_assoc: skipping private IPv4 addr: %s\n", buf); 1739 } 1740 #endif /* SCTP_DEBUG */ 1741 return; 1742 } 1743 } else { 1744 /* else, not AF_INET or AF_INET6, so skip */ 1745 #ifdef SCTP_DEBUG 1746 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1747 printf("addr_mgmt_assoc: not AF_INET or AF_INET6\n"); 1748 } 1749 #endif /* SCTP_DEBUG */ 1750 return; 1751 } 1752 1753 /* queue an asconf for this address add/delete */ 1754 if (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) { 1755 /* does the peer do asconf? */ 1756 if (stcb->asoc.peer_supports_asconf) { 1757 /* queue an asconf for this addr */ 1758 status = sctp_asconf_queue_add(stcb, ifa, type); 1759 /* 1760 * if queued ok, and in correct state, set the 1761 * ASCONF timer 1762 * if in non-open state, we will set this timer 1763 * when the state does go open and do all the 1764 * asconf's 1765 */ 1766 if (status == 0 && 1767 SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 1768 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, 1769 stcb, stcb->asoc.primary_destination); 1770 } 1771 } 1772 } else { 1773 /* this is the boundall, no ASCONF case */ 1774 #if 0 /* assume kernel will delete this very shortly; add done above */ 1775 if (type == SCTP_DEL_IP_ADDRESS) { 1776 /* if deleting, add this addr to the do not use list */ 1777 sctp_add_local_addr_assoc(stcb, ifa); 1778 } 1779 #endif 1780 } 1781 } 1782 1783 static void 1784 sctp_addr_mgmt_ep(struct sctp_inpcb *inp, struct ifaddr *ifa, uint16_t type) 1785 { 1786 struct sctp_tcb *stcb; 1787 int s; 1788 1789 SCTP_INP_WLOCK(inp); 1790 /* make sure we're "allowed" to add this type of addr */ 1791 if (ifa->ifa_addr->sa_family == AF_INET6) { 1792 struct in6_ifaddr *ifa6; 1793 1794 /* invalid if we're not a v6 endpoint */ 1795 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 1796 SCTP_INP_WUNLOCK(inp); 1797 return; 1798 } 1799 /* is the v6 addr really valid ? */ 1800 ifa6 = (struct in6_ifaddr *)ifa; 1801 if (IFA6_IS_DEPRECATED(ifa6) || 1802 (ifa6->ia6_flags & 1803 (IN6_IFF_DETACHED | IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { 1804 /* can't use an invalid address */ 1805 SCTP_INP_WUNLOCK(inp); 1806 return; 1807 } 1808 } else if (ifa->ifa_addr->sa_family == AF_INET) { 1809 /* invalid if we are a v6 only endpoint */ 1810 struct in6pcb *inp6; 1811 inp6 = (struct in6pcb *)&inp->ip_inp.inp; 1812 1813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 1814 (inp6->in6p_flags & IN6P_IPV6_V6ONLY) 1815 ) { 1816 SCTP_INP_WUNLOCK(inp); 1817 return; 1818 } 1819 } else { 1820 /* invalid address family */ 1821 SCTP_INP_WUNLOCK(inp); 1822 return; 1823 } 1824 /* is this endpoint subset bound ? */ 1825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { 1826 /* subset bound endpoint */ 1827 if ((inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) == 0) { 1828 /* 1829 * subset bound, but ASCONFs not allowed... 1830 * if adding, nothing to do, since not allowed 1831 * if deleting, remove address from endpoint 1832 * peer will have to "timeout" this addr 1833 */ 1834 if (type == SCTP_DEL_IP_ADDRESS) { 1835 sctp_del_local_addr_ep(inp, ifa); 1836 } 1837 /* no asconfs to queue for this inp... */ 1838 SCTP_INP_WUNLOCK(inp); 1839 return; 1840 } else { 1841 /* 1842 * subset bound, ASCONFs allowed... 1843 * if adding, add address to endpoint list 1844 * if deleting, remove address from endpoint 1845 */ 1846 if (type == SCTP_ADD_IP_ADDRESS) { 1847 sctp_add_local_addr_ep(inp, ifa); 1848 } else { 1849 sctp_del_local_addr_ep(inp, ifa); 1850 } 1851 /* drop through and notify all asocs */ 1852 } 1853 } 1854 1855 s = splsoftnet(); 1856 /* process for all associations for this endpoint */ 1857 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { 1858 SCTP_TCB_LOCK(stcb); 1859 sctp_addr_mgmt_assoc(inp, stcb, ifa, type); 1860 SCTP_TCB_UNLOCK(stcb); 1861 } /* for each stcb */ 1862 splx(s); 1863 SCTP_INP_WUNLOCK(inp); 1864 } 1865 1866 /* 1867 * restrict the use of this address 1868 */ 1869 static void 1870 sctp_addr_mgmt_restrict_ep(struct sctp_inpcb *inp, struct ifaddr *ifa) 1871 { 1872 struct sctp_tcb *stcb; 1873 int s; 1874 1875 /* is this endpoint bound to all? */ 1876 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { 1877 /* 1878 * Nothing to do for subset bound case. 1879 * Allow sctp_bindx() to manage the address lists 1880 */ 1881 return; 1882 } 1883 1884 s = splsoftnet(); 1885 SCTP_INP_RLOCK(inp); 1886 /* process for all associations for this endpoint */ 1887 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { 1888 /* put this address on the "pending/do not use yet" list */ 1889 SCTP_TCB_LOCK(stcb); 1890 sctp_add_local_addr_assoc(stcb, ifa); 1891 SCTP_TCB_UNLOCK(stcb); 1892 #ifdef SCTP_DEBUG 1893 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1894 printf("restrict_ep: added addr to unusable list\n"); 1895 } 1896 #endif /* SCTP_DEBUG */ 1897 } /* for each stcb */ 1898 splx(s); 1899 SCTP_INP_RUNLOCK(inp); 1900 } 1901 1902 /* 1903 * this is only called for kernel initiated address changes 1904 * eg. it will check the PCB_FLAGS_AUTO_ASCONF flag 1905 */ 1906 static void 1907 sctp_addr_mgmt(struct ifaddr *ifa, uint16_t type) { 1908 struct sockaddr *sa; 1909 struct sctp_inpcb *inp; 1910 1911 /* make sure we care about this interface... */ 1912 if (!sctp_is_desired_interface_type(ifa)) { 1913 #ifdef SCTP_DEBUG 1914 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1915 printf("sctp_addr_mgmt: ignoring this interface\n"); 1916 } 1917 #endif /* SCTP_DEBUG */ 1918 return; 1919 } 1920 1921 sa = ifa->ifa_addr; 1922 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) 1923 return; 1924 1925 #ifdef SCTP_DEBUG 1926 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1927 if (type == SCTP_ADD_IP_ADDRESS) 1928 printf("sctp_addr_mgmt: kernel adds "); 1929 else 1930 printf("sctp_addr_mgmt: kernel deletes "); 1931 sctp_print_address(sa); 1932 } 1933 #endif /* SCTP_DEBUG */ 1934 1935 /* go through all our PCB's */ 1936 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) { 1937 if (inp->sctp_flags & SCTP_PCB_FLAGS_AUTO_ASCONF) { 1938 sctp_addr_mgmt_ep(inp, ifa, type); 1939 } else { 1940 /* this address is going away anyways... */ 1941 if (type == SCTP_DEL_IP_ADDRESS) 1942 return; 1943 /* (temporarily) restrict this address */ 1944 sctp_addr_mgmt_restrict_ep(inp, ifa); 1945 } 1946 /* else, not allowing automatic asconf's, so ignore */ 1947 } /* for each inp */ 1948 } 1949 1950 /* 1951 * add/delete IP address requests from kernel (via routing change) 1952 * assumed that the address is non-broadcast, non-multicast 1953 * all addresses are passed from any type of interface-- need to filter 1954 * duplicate addresses may get requested 1955 */ 1956 1957 void 1958 sctp_add_ip_address(struct ifaddr *ifa) 1959 { 1960 sctp_addr_mgmt(ifa, SCTP_ADD_IP_ADDRESS); 1961 } 1962 1963 void 1964 sctp_delete_ip_address(struct ifaddr *ifa) 1965 { 1966 struct sctp_inpcb *inp; 1967 1968 /* process the delete */ 1969 sctp_addr_mgmt(ifa, SCTP_DEL_IP_ADDRESS); 1970 1971 /* 1972 * need to remove this ifaddr from any cached routes 1973 * and also any from any assoc "restricted/pending" lists 1974 */ 1975 /* make sure we care about this interface... */ 1976 if (!sctp_is_desired_interface_type(ifa)) { 1977 #ifdef SCTP_DEBUG 1978 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 1979 printf("sctp_delete_ip_address: ignoring this interface\n"); 1980 } 1981 #endif /* SCTP_DEBUG */ 1982 return; 1983 } 1984 1985 /* go through all our PCB's */ 1986 SCTP_INP_INFO_RLOCK(); 1987 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) { 1988 struct sctp_tcb *stcb; 1989 struct sctp_laddr *laddr, *laddr_next; 1990 1991 /* process for all associations for this endpoint */ 1992 SCTP_INP_RLOCK(inp); 1993 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { 1994 struct sctp_nets *net; 1995 1996 /* process through the nets list */ 1997 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1998 rtcache_free(&net->ro); /* XXX - was clear */ 1999 } /* for each net */ 2000 /* process through the asoc "pending" list */ 2001 laddr = LIST_FIRST(&stcb->asoc.sctp_local_addr_list); 2002 while (laddr != NULL) { 2003 laddr_next = LIST_NEXT(laddr, sctp_nxt_addr); 2004 /* remove if in use */ 2005 if (laddr->ifa == ifa) { 2006 sctp_remove_laddr(laddr); 2007 } 2008 laddr = laddr_next; 2009 } /* while */ 2010 } /* for each stcb */ 2011 /* process through the inp bound addr list */ 2012 laddr = LIST_FIRST(&inp->sctp_addr_list); 2013 while (laddr != NULL) { 2014 laddr_next = LIST_NEXT(laddr, sctp_nxt_addr); 2015 /* remove if in use */ 2016 if (laddr->ifa == ifa) { 2017 sctp_remove_laddr(laddr); 2018 } 2019 laddr = laddr_next; 2020 } /* while */ 2021 SCTP_INP_RUNLOCK(inp); 2022 } /* for each inp */ 2023 SCTP_INP_INFO_RUNLOCK(); 2024 } 2025 2026 /* 2027 * sa is the sockaddr to ask the peer to set primary to 2028 * returns: 0 = completed, -1 = error 2029 */ 2030 int32_t 2031 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa) 2032 { 2033 /* NOTE: we currently don't check the validity of the address! */ 2034 2035 /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 2036 if (!sctp_asconf_queue_add_sa(stcb, sa, SCTP_SET_PRIM_ADDR)) { 2037 /* set primary queuing succeeded */ 2038 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 2039 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2040 stcb->sctp_ep, stcb, 2041 stcb->asoc.primary_destination); 2042 } 2043 #ifdef SCTP_DEBUG 2044 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2045 printf("set_primary_ip_address_sa: queued on tcb=%p, ", 2046 stcb); 2047 sctp_print_address(sa); 2048 } 2049 #endif /* SCTP_DEBUG */ 2050 } else { 2051 #ifdef SCTP_DEBUG 2052 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2053 printf("set_primary_ip_address_sa: failed to add to queue on tcb=%p, ", 2054 stcb); 2055 sctp_print_address(sa); 2056 } 2057 #endif /* SCTP_DEBUG */ 2058 return (-1); 2059 } 2060 return (0); 2061 } 2062 2063 void 2064 sctp_set_primary_ip_address(struct ifaddr *ifa) 2065 { 2066 struct sctp_inpcb *inp; 2067 2068 /* make sure we care about this interface... */ 2069 if (!sctp_is_desired_interface_type(ifa)) { 2070 #ifdef SCTP_DEBUG 2071 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2072 printf("set_primary_ip_address: ignoring this interface\n"); 2073 } 2074 #endif /* SCTP_DEBUG */ 2075 return; 2076 } 2077 2078 /* go through all our PCB's */ 2079 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) { 2080 struct sctp_tcb *stcb; 2081 2082 /* process for all associations for this endpoint */ 2083 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { 2084 /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 2085 if (!sctp_asconf_queue_add(stcb, ifa, 2086 SCTP_SET_PRIM_ADDR)) { 2087 /* set primary queuing succeeded */ 2088 if (SCTP_GET_STATE(&stcb->asoc) == 2089 SCTP_STATE_OPEN) { 2090 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2091 stcb->sctp_ep, stcb, 2092 stcb->asoc.primary_destination); 2093 } 2094 #ifdef SCTP_DEBUG 2095 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2096 printf("set_primary_ip_address: queued on stcb=%p, ", 2097 stcb); 2098 sctp_print_address(ifa->ifa_addr); 2099 } 2100 #endif /* SCTP_DEBUG */ 2101 } else { 2102 #ifdef SCTP_DEBUG 2103 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2104 printf("set_primary_ip_address: failed to add to queue, "); 2105 sctp_print_address(ifa->ifa_addr); 2106 } 2107 #endif /* SCTP_DEBUG */ 2108 } 2109 } /* for each stcb */ 2110 } /* for each inp */ 2111 } 2112 2113 static struct sockaddr * 2114 sctp_find_valid_localaddr(struct sctp_tcb *stcb) 2115 { 2116 struct ifnet *ifn; 2117 struct ifaddr *ifa, *nifa; 2118 2119 TAILQ_FOREACH(ifn, &ifnet_list, if_list) { 2120 if (stcb->asoc.loopback_scope == 0 && ifn->if_type == IFT_LOOP) { 2121 /* Skip if loopback_scope not set */ 2122 continue; 2123 } 2124 IFADDR_FOREACH_SAFE(ifa, ifn, nifa) { 2125 if (ifa->ifa_addr->sa_family == AF_INET && 2126 stcb->asoc.ipv4_addr_legal) { 2127 struct sockaddr_in *sin; 2128 2129 sin = (struct sockaddr_in *)ifa->ifa_addr; 2130 if (sin->sin_addr.s_addr == 0) { 2131 /* skip unspecifed addresses */ 2132 continue; 2133 } 2134 if (stcb->asoc.ipv4_local_scope == 0 && 2135 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) 2136 continue; 2137 2138 if (sctp_is_addr_restricted(stcb, 2139 ifa->ifa_addr)) 2140 continue; 2141 /* found a valid local v4 address to use */ 2142 return (ifa->ifa_addr); 2143 } else if (ifa->ifa_addr->sa_family == AF_INET6 && 2144 stcb->asoc.ipv6_addr_legal) { 2145 struct sockaddr_in6 *sin6; 2146 struct in6_ifaddr *ifa6; 2147 2148 ifa6 = (struct in6_ifaddr *)ifa; 2149 if (IFA6_IS_DEPRECATED(ifa6) || 2150 (ifa6->ia6_flags & (IN6_IFF_DETACHED | 2151 IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) 2152 continue; 2153 2154 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; 2155 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2156 /* we skip unspecifed addresses */ 2157 continue; 2158 } 2159 if (stcb->asoc.local_scope == 0 && 2160 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) 2161 continue; 2162 if (stcb->asoc.site_scope == 0 && 2163 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) 2164 continue; 2165 2166 /* found a valid local v6 address to use */ 2167 return (ifa->ifa_addr); 2168 } 2169 } 2170 } 2171 /* no valid addresses found */ 2172 return (NULL); 2173 } 2174 2175 static struct sockaddr * 2176 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb) 2177 { 2178 struct sctp_laddr *laddr; 2179 2180 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 2181 if (laddr->ifa == NULL) { 2182 #ifdef SCTP_DEBUG 2183 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2184 printf("find_valid_localaddr_ep: laddr error\n"); 2185 } 2186 #endif /* SCTP_DEBUG */ 2187 continue; 2188 } 2189 if (laddr->ifa->ifa_addr == NULL) { 2190 #ifdef SCTP_DEBUG 2191 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2192 printf("find_valid_localaddr_ep: laddr->ifa error\n"); 2193 } 2194 #endif /* SCTP_DEBUG */ 2195 continue; 2196 } 2197 /* is the address restricted ? */ 2198 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr)) 2199 continue; 2200 2201 /* found a valid local address to use */ 2202 return (laddr->ifa->ifa_addr); 2203 } 2204 /* no valid addresses found */ 2205 return (NULL); 2206 } 2207 2208 /* 2209 * builds an ASCONF chunk from queued ASCONF params 2210 * returns NULL on error (no mbuf, no ASCONF params queued, etc) 2211 */ 2212 struct mbuf * 2213 sctp_compose_asconf(struct sctp_tcb *stcb) 2214 { 2215 struct mbuf *m_asconf, *m_asconf_chk; 2216 struct sctp_asconf_addr *aa; 2217 struct sctp_asconf_chunk *acp; 2218 struct sctp_asconf_paramhdr *aph; 2219 struct sctp_asconf_addr_param *aap; 2220 uint32_t p_length; 2221 uint32_t correlation_id = 1; /* 0 is reserved... */ 2222 vaddr_t ptr, lookup_ptr; 2223 uint8_t lookup_used = 0; 2224 2225 /* are there any asconf params to send? */ 2226 if (TAILQ_EMPTY(&stcb->asoc.asconf_queue)) { 2227 return (NULL); 2228 } 2229 2230 /* 2231 * get a chunk header mbuf and a cluster for the asconf params 2232 * since it's simpler to fill in the asconf chunk header lookup 2233 * address on the fly 2234 */ 2235 m_asconf_chk = NULL; 2236 MGETHDR(m_asconf_chk, M_DONTWAIT, MT_DATA); 2237 if (m_asconf_chk == NULL) { 2238 /* no mbuf's */ 2239 #ifdef SCTP_DEBUG 2240 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) 2241 printf("compose_asconf: couldn't get chunk mbuf!\n"); 2242 #endif /* SCTP_DEBUG */ 2243 return (NULL); 2244 } 2245 m_asconf = NULL; 2246 MGETHDR(m_asconf, M_DONTWAIT, MT_HEADER); 2247 if (m_asconf == NULL) { 2248 /* no mbuf's */ 2249 #ifdef SCTP_DEBUG 2250 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) 2251 printf("compose_asconf: couldn't get mbuf!\n"); 2252 #endif /* SCTP_DEBUG */ 2253 sctp_m_freem(m_asconf_chk); 2254 return (NULL); 2255 } 2256 MCLGET(m_asconf, M_DONTWAIT); 2257 if ((m_asconf->m_flags & M_EXT) != M_EXT) { 2258 /* failed to get cluster buffer */ 2259 #ifdef SCTP_DEBUG 2260 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) 2261 printf("compose_asconf: couldn't get cluster!\n"); 2262 #endif /* SCTP_DEBUG */ 2263 sctp_m_freem(m_asconf_chk); 2264 sctp_m_freem(m_asconf); 2265 return (NULL); 2266 } 2267 2268 m_asconf_chk->m_len = sizeof(struct sctp_asconf_chunk); 2269 m_asconf->m_len = 0; 2270 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *); 2271 memset(acp, 0, sizeof(struct sctp_asconf_chunk)); 2272 /* save pointers to lookup address and asconf params */ 2273 lookup_ptr = (vaddr_t)(acp + 1); /* after the header */ 2274 ptr = mtod(m_asconf, vaddr_t); /* beginning of cluster */ 2275 2276 /* fill in chunk header info */ 2277 acp->ch.chunk_type = SCTP_ASCONF; 2278 acp->ch.chunk_flags = 0; 2279 acp->serial_number = htonl(stcb->asoc.asconf_seq_out); 2280 2281 /* add parameters... up to smallest MTU allowed */ 2282 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2283 /* get the parameter length */ 2284 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length); 2285 /* will it fit in current chunk? */ 2286 if (m_asconf->m_len + p_length > stcb->asoc.smallest_mtu) { 2287 /* won't fit, so we're done with this chunk */ 2288 break; 2289 } 2290 /* assign (and store) a correlation id */ 2291 aa->ap.aph.correlation_id = correlation_id++; 2292 2293 /* 2294 * fill in address if we're doing a delete 2295 * this is a simple way for us to fill in the correlation 2296 * address, which should only be used by the peer if we're 2297 * deleting our source address and adding a new address 2298 * (e.g. renumbering case) 2299 */ 2300 if (lookup_used == 0 && 2301 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 2302 struct sctp_ipv6addr_param *lookup; 2303 uint16_t p_size, addr_size; 2304 2305 lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2306 lookup->ph.param_type = 2307 htons(aa->ap.addrp.ph.param_type); 2308 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) { 2309 /* copy IPv6 address */ 2310 p_size = sizeof(struct sctp_ipv6addr_param); 2311 addr_size = sizeof(struct in6_addr); 2312 } else { 2313 /* copy IPv4 address */ 2314 p_size = sizeof(struct sctp_ipv4addr_param); 2315 addr_size = sizeof(struct in_addr); 2316 } 2317 lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2318 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size); 2319 m_asconf_chk->m_len += SCTP_SIZE32(p_size); 2320 lookup_used = 1; 2321 } 2322 2323 /* copy into current space */ 2324 memcpy((void *)ptr, &aa->ap, p_length); 2325 2326 /* network elements and update lengths */ 2327 aph = (struct sctp_asconf_paramhdr *) ptr; 2328 aap = (struct sctp_asconf_addr_param *) ptr; 2329 /* correlation_id is transparent to peer, no htonl needed */ 2330 aph->ph.param_type = htons(aph->ph.param_type); 2331 aph->ph.param_length = htons(aph->ph.param_length); 2332 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type); 2333 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length); 2334 2335 m_asconf->m_len += SCTP_SIZE32(p_length); 2336 ptr += SCTP_SIZE32(p_length); 2337 2338 /* 2339 * these params are removed off the pending list upon 2340 * getting an ASCONF-ACK back from the peer, just set flag 2341 */ 2342 aa->sent = 1; 2343 } 2344 /* check to see if the lookup addr has been populated yet */ 2345 if (lookup_used == 0) { 2346 /* NOTE: if the address param is optional, can skip this... */ 2347 /* add any valid (existing) address... */ 2348 struct sctp_ipv6addr_param *lookup; 2349 uint16_t p_size, addr_size; 2350 struct sockaddr *found_addr; 2351 vaddr_t addr_ptr; 2352 2353 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) 2354 found_addr = sctp_find_valid_localaddr(stcb); 2355 else 2356 found_addr = sctp_find_valid_localaddr_ep(stcb); 2357 2358 lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2359 if (found_addr != NULL) { 2360 if (found_addr->sa_family == AF_INET6) { 2361 /* copy IPv6 address */ 2362 lookup->ph.param_type = 2363 htons(SCTP_IPV6_ADDRESS); 2364 p_size = sizeof(struct sctp_ipv6addr_param); 2365 addr_size = sizeof(struct in6_addr); 2366 addr_ptr = (vaddr_t)&((struct sockaddr_in6 *) 2367 found_addr)->sin6_addr; 2368 } else { 2369 /* copy IPv4 address */ 2370 lookup->ph.param_type = 2371 htons(SCTP_IPV4_ADDRESS); 2372 p_size = sizeof(struct sctp_ipv4addr_param); 2373 addr_size = sizeof(struct in_addr); 2374 addr_ptr = (vaddr_t)&((struct sockaddr_in *) 2375 found_addr)->sin_addr; 2376 } 2377 lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2378 memcpy(lookup->addr, (void *)addr_ptr, addr_size); 2379 m_asconf_chk->m_len += SCTP_SIZE32(p_size); 2380 lookup_used = 1; 2381 } else { 2382 /* uh oh... don't have any address?? */ 2383 #ifdef SCTP_DEBUG 2384 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) 2385 printf("compose_asconf: no lookup addr!\n"); 2386 #endif /* SCTP_DEBUG */ 2387 /* for now, we send a IPv4 address of 0.0.0.0 */ 2388 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS); 2389 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param))); 2390 memset(lookup->addr, 0, sizeof(struct in_addr)); 2391 m_asconf_chk->m_len += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)); 2392 lookup_used = 1; 2393 } 2394 } 2395 2396 /* chain it all together */ 2397 m_asconf_chk->m_next = m_asconf; 2398 m_asconf_chk->m_pkthdr.len = m_asconf_chk->m_len + m_asconf->m_len; 2399 acp->ch.chunk_length = ntohs(m_asconf_chk->m_pkthdr.len); 2400 2401 /* update "sent" flag */ 2402 stcb->asoc.asconf_sent++; 2403 2404 return (m_asconf_chk); 2405 } 2406 2407 /* 2408 * section to handle address changes before an association is up 2409 * eg. changes during INIT/INIT-ACK/COOKIE-ECHO handshake 2410 */ 2411 2412 /* 2413 * processes the (local) addresses in the INIT-ACK chunk 2414 */ 2415 static void 2416 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, 2417 unsigned int offset, unsigned int length) 2418 { 2419 struct sctp_paramhdr tmp_param, *ph; 2420 uint16_t plen, ptype; 2421 struct sctp_ipv6addr_param addr_store; 2422 struct sockaddr_in6 sin6; 2423 struct sockaddr_in sin; 2424 struct sockaddr *sa; 2425 struct ifaddr *ifa; 2426 2427 #ifdef SCTP_DEBUG 2428 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2429 printf("processing init-ack addresses\n"); 2430 } 2431 #endif /* SCTP_DEBUG */ 2432 2433 /* convert to upper bound */ 2434 length += offset; 2435 2436 if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2437 #ifdef SCTP_DEBUG 2438 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2439 printf("process_initack_addrs: invalid offset?\n"); 2440 } 2441 #endif /* SCTP_DEBUG */ 2442 return; 2443 } 2444 2445 /* init the addresses */ 2446 memset(&sin6, 0, sizeof(sin6)); 2447 sin6.sin6_family = AF_INET6; 2448 sin6.sin6_len = sizeof(sin6); 2449 sin6.sin6_port = stcb->rport; 2450 2451 memset(&sin, 0, sizeof(sin)); 2452 sin.sin_len = sizeof(sin); 2453 sin.sin_family = AF_INET; 2454 sin.sin_port = stcb->rport; 2455 2456 /* go through the addresses in the init-ack */ 2457 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2458 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); 2459 while (ph != NULL) { 2460 ptype = ntohs(ph->param_type); 2461 plen = ntohs(ph->param_length); 2462 if (ptype == SCTP_IPV6_ADDRESS) { 2463 struct sctp_ipv6addr_param *a6p; 2464 /* get the entire IPv6 address param */ 2465 #ifdef SCTP_DEBUG 2466 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2467 printf("process_initack_addrs: checking IPv6 param\n"); 2468 } 2469 #endif /* SCTP_DEBUG */ 2470 a6p = (struct sctp_ipv6addr_param *) 2471 sctp_m_getptr(m, offset, 2472 sizeof(struct sctp_ipv6addr_param), 2473 (uint8_t *)&addr_store); 2474 if (plen != sizeof(struct sctp_ipv6addr_param) || 2475 a6p == NULL) { 2476 #ifdef SCTP_DEBUG 2477 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2478 printf("process_initack_addrs: invalid IPv6 param length\n"); 2479 } 2480 #endif /* SCTP_DEBUG */ 2481 return; 2482 } 2483 memcpy(&sin6.sin6_addr, a6p->addr, 2484 sizeof(struct in6_addr)); 2485 sa = (struct sockaddr *)&sin6; 2486 } else if (ptype == SCTP_IPV4_ADDRESS) { 2487 struct sctp_ipv4addr_param *a4p; 2488 /* get the entire IPv4 address param */ 2489 #ifdef SCTP_DEBUG 2490 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2491 printf("process_initack_addrs: checking IPv4 param\n"); 2492 } 2493 #endif /* SCTP_DEBUG */ 2494 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_ipv4addr_param), (uint8_t *)&addr_store); 2495 if (plen != sizeof(struct sctp_ipv4addr_param) || 2496 a4p == NULL) { 2497 #ifdef SCTP_DEBUG 2498 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2499 printf("process_initack_addrs: invalid IPv4 param length\n"); 2500 } 2501 #endif /* SCTP_DEBUG */ 2502 return; 2503 } 2504 sin.sin_addr.s_addr = a4p->addr; 2505 sa = (struct sockaddr *)&sin; 2506 } else { 2507 #ifdef SCTP_DEBUG 2508 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2509 printf("process_initack_addrs: skipping param type=%xh\n", ptype); 2510 } 2511 #endif /* SCTP_DEBUG */ 2512 goto next_addr; 2513 } 2514 2515 /* see if this address really (still) exists */ 2516 ifa = sctp_find_ifa_by_addr(sa); 2517 if (ifa == NULL) { 2518 /* address doesn't exist anymore */ 2519 int status; 2520 /* are ASCONFs allowed ? */ 2521 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) && 2522 stcb->asoc.peer_supports_asconf) { 2523 /* queue an ASCONF DEL_IP_ADDRESS */ 2524 status = sctp_asconf_queue_add_sa(stcb, sa, 2525 SCTP_DEL_IP_ADDRESS); 2526 /* 2527 * if queued ok, and in correct state, 2528 * set the ASCONF timer 2529 */ 2530 if (status == 0 && 2531 SCTP_GET_STATE(&stcb->asoc) == 2532 SCTP_STATE_OPEN) { 2533 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2534 stcb->sctp_ep, stcb, 2535 stcb->asoc.primary_destination); 2536 } 2537 } 2538 } else { 2539 /* address still exists */ 2540 /* 2541 * if subset bound, ep addr's managed by default 2542 * if not doing ASCONF, add the address to the assoc 2543 */ 2544 if ((stcb->sctp_ep->sctp_flags & 2545 SCTP_PCB_FLAGS_BOUNDALL) == 0 && 2546 (stcb->sctp_ep->sctp_flags & 2547 SCTP_PCB_FLAGS_DO_ASCONF) == 0) { 2548 #ifdef SCTP_DEBUG 2549 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2550 printf("process_initack_addrs: adding local addr to asoc\n"); 2551 } 2552 #endif /* SCTP_DEBUG */ 2553 sctp_add_local_addr_assoc(stcb, ifa); 2554 } 2555 } 2556 2557 next_addr: 2558 /* get next parameter */ 2559 offset += SCTP_SIZE32(plen); 2560 if ((offset + sizeof(struct sctp_paramhdr)) > length) 2561 return; 2562 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2563 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); 2564 } /* while */ 2565 } 2566 2567 /* FIX ME: need to verify return result for v6 address type if v6 disabled */ 2568 /* 2569 * checks to see if a specific address is in the initack address list 2570 * returns 1 if found, 0 if not 2571 */ 2572 static uint32_t 2573 sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, unsigned int offset, 2574 unsigned int length, struct sockaddr *sa) 2575 { 2576 struct sctp_paramhdr tmp_param, *ph; 2577 uint16_t plen, ptype; 2578 struct sctp_ipv6addr_param addr_store; 2579 struct sockaddr_in *sin; 2580 struct sctp_ipv4addr_param *a4p; 2581 #ifdef INET6 2582 struct sockaddr_in6 *sin6, sin6_tmp; 2583 struct sctp_ipv6addr_param *a6p; 2584 #endif /* INET6 */ 2585 2586 if ( 2587 #ifdef INET6 2588 (sa->sa_family != AF_INET6) && 2589 #endif /* INET6 */ 2590 (sa->sa_family != AF_INET)) 2591 return (0); 2592 2593 #ifdef SCTP_DEBUG 2594 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2595 printf("find_initack_addr: starting search for "); 2596 sctp_print_address(sa); 2597 } 2598 #endif /* SCTP_DEBUG */ 2599 /* convert to upper bound */ 2600 length += offset; 2601 2602 if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2603 #ifdef SCTP_DEBUG 2604 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2605 printf("find_initack_addr: invalid offset?\n"); 2606 } 2607 #endif /* SCTP_DEBUG */ 2608 return (0); 2609 } 2610 2611 /* go through the addresses in the init-ack */ 2612 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2613 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); 2614 while (ph != NULL) { 2615 ptype = ntohs(ph->param_type); 2616 plen = ntohs(ph->param_length); 2617 #ifdef INET6 2618 if (ptype == SCTP_IPV6_ADDRESS && sa->sa_family == AF_INET6) { 2619 /* get the entire IPv6 address param */ 2620 #ifdef SCTP_DEBUG 2621 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2622 printf("addr_in_initack: checking IPv6 param\n"); 2623 } 2624 #endif /* SCTP_DEBUG */ 2625 a6p = (struct sctp_ipv6addr_param *) 2626 sctp_m_getptr(m, offset, 2627 sizeof(struct sctp_ipv6addr_param), 2628 (uint8_t *)&addr_store); 2629 if (plen != sizeof(struct sctp_ipv6addr_param) || 2630 ph == NULL) { 2631 #ifdef SCTP_DEBUG 2632 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2633 printf("addr_in_initack: invalid IPv6 param length\n"); 2634 } 2635 #endif /* SCTP_DEBUG */ 2636 return (0); 2637 } 2638 sin6 = (struct sockaddr_in6 *)sa; 2639 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { 2640 /* create a copy and clear scope */ 2641 memcpy(&sin6_tmp, sin6, 2642 sizeof(struct sockaddr_in6)); 2643 sin6 = &sin6_tmp; 2644 in6_clearscope(&sin6->sin6_addr); 2645 } 2646 if (memcmp(&sin6->sin6_addr, a6p->addr, 2647 sizeof(struct in6_addr)) == 0) { 2648 /* found it */ 2649 #ifdef SCTP_DEBUG 2650 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2651 printf("addr_in_initack: found IPv6 addr\n"); 2652 } 2653 #endif /* SCTP_DEBUG */ 2654 return (1); 2655 } 2656 } else 2657 #endif /* INET6 */ 2658 2659 if (ptype == SCTP_IPV4_ADDRESS && 2660 sa->sa_family == AF_INET) { 2661 /* get the entire IPv4 address param */ 2662 #ifdef SCTP_DEBUG 2663 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2664 printf("addr_in_initack: checking IPv4 param\n"); 2665 } 2666 #endif /* SCTP_DEBUG */ 2667 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, 2668 offset, sizeof(struct sctp_ipv4addr_param), 2669 (uint8_t *)&addr_store); 2670 if (plen != sizeof(struct sctp_ipv4addr_param) || 2671 ph == NULL) { 2672 #ifdef SCTP_DEBUG 2673 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2674 printf("addr_in_initack: invalid IPv4 param length\n"); 2675 } 2676 #endif /* SCTP_DEBUG */ 2677 return (0); 2678 } 2679 sin = (struct sockaddr_in *)sa; 2680 if (sin->sin_addr.s_addr == a4p->addr) { 2681 /* found it */ 2682 #ifdef SCTP_DEBUG 2683 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2684 printf("addr_in_initack: found IPv4 addr\n"); 2685 } 2686 #endif /* SCTP_DEBUG */ 2687 return (1); 2688 } 2689 } else { 2690 #ifdef SCTP_DEBUG 2691 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2692 printf("addr_in_initack: skipping param type=%xh\n", ptype); 2693 } 2694 #endif /* SCTP_DEBUG */ 2695 } 2696 /* get next parameter */ 2697 offset += SCTP_SIZE32(plen); 2698 if (offset + sizeof(struct sctp_paramhdr) > length) 2699 return (0); 2700 ph = (struct sctp_paramhdr *) 2701 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), 2702 (uint8_t *)&tmp_param); 2703 } /* while */ 2704 /* not found! */ 2705 #ifdef SCTP_DEBUG 2706 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2707 printf("addr_in_initack: not found!\n"); 2708 } 2709 #endif /* SCTP_DEBUG */ 2710 return (0); 2711 } 2712 2713 /* 2714 * makes sure that the current endpoint local addr list is consistent 2715 * with the new association (eg. subset bound, asconf allowed) 2716 * adds addresses as necessary 2717 */ 2718 static void 2719 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset, 2720 int length, struct sockaddr *init_addr) 2721 { 2722 struct sctp_laddr *laddr; 2723 2724 /* go through the endpoint list */ 2725 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 2726 /* be paranoid and validate the laddr */ 2727 if (laddr->ifa == NULL) { 2728 #ifdef SCTP_DEBUG 2729 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2730 printf("check_addr_list_ep: laddr->ifa is NULL"); 2731 } 2732 #endif 2733 continue; 2734 } 2735 if (laddr->ifa->ifa_addr == NULL) { 2736 #ifdef SCTP_DEBUG 2737 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2738 printf("check_addr_list_ep: laddr->ifa->ifa_addr is NULL"); 2739 } 2740 #endif 2741 continue; 2742 } 2743 /* do i have it implicitly? */ 2744 if (sctp_cmpaddr(laddr->ifa->ifa_addr, init_addr)) { 2745 #ifdef SCTP_DEBUG 2746 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2747 printf("check_address_list_all: skipping "); 2748 sctp_print_address(laddr->ifa->ifa_addr); 2749 } 2750 #endif /* SCTP_DEBUG */ 2751 continue; 2752 } 2753 /* check to see if in the init-ack */ 2754 if (!sctp_addr_in_initack(stcb, m, offset, length, 2755 laddr->ifa->ifa_addr)) { 2756 /* try to add it */ 2757 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa, 2758 SCTP_ADD_IP_ADDRESS); 2759 } 2760 } 2761 } 2762 2763 /* 2764 * makes sure that the current kernel address list is consistent 2765 * with the new association (with all addrs bound) 2766 * adds addresses as necessary 2767 */ 2768 static void 2769 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset, 2770 int length, struct sockaddr *init_addr, uint16_t local_scope, 2771 uint16_t site_scope, uint16_t ipv4_scope, uint16_t loopback_scope) 2772 { 2773 struct ifnet *ifn; 2774 struct ifaddr *ifa; 2775 2776 /* go through all our known interfaces */ 2777 TAILQ_FOREACH(ifn, &ifnet_list, if_list) { 2778 if (loopback_scope == 0 && ifn->if_type == IFT_LOOP) { 2779 /* skip loopback interface */ 2780 continue; 2781 } 2782 2783 /* go through each interface address */ 2784 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) { 2785 /* do i have it implicitly? */ 2786 if (sctp_cmpaddr(ifa->ifa_addr, init_addr)) { 2787 #ifdef SCTP_DEBUG 2788 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) { 2789 printf("check_address_list_all: skipping "); 2790 sctp_print_address(ifa->ifa_addr); 2791 } 2792 #endif /* SCTP_DEBUG */ 2793 continue; 2794 } 2795 /* check to see if in the init-ack */ 2796 if (!sctp_addr_in_initack(stcb, m, offset, length, 2797 ifa->ifa_addr)) { 2798 /* try to add it */ 2799 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, 2800 ifa, SCTP_ADD_IP_ADDRESS); 2801 } 2802 } /* end foreach ifa */ 2803 } /* end foreach ifn */ 2804 } 2805 2806 /* 2807 * validates an init-ack chunk (from a cookie-echo) with current addresses 2808 * adds addresses from the init-ack into our local address list, if needed 2809 * queues asconf adds/deletes addresses as needed and makes appropriate 2810 * list changes for source address selection 2811 * m, offset: points to the start of the address list in an init-ack chunk 2812 * length: total length of the address params only 2813 * init_addr: address where my INIT-ACK was sent from 2814 */ 2815 void 2816 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset, 2817 int length, struct sockaddr *init_addr, uint16_t local_scope, 2818 uint16_t site_scope, uint16_t ipv4_scope, uint16_t loopback_scope) 2819 { 2820 2821 /* process the local addresses in the initack */ 2822 sctp_process_initack_addresses(stcb, m, offset, length); 2823 2824 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 2825 /* bound all case */ 2826 sctp_check_address_list_all(stcb, m, offset, length, init_addr, 2827 local_scope, site_scope, ipv4_scope, loopback_scope); 2828 } else { 2829 /* subset bound case */ 2830 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) { 2831 /* asconf's allowed */ 2832 sctp_check_address_list_ep(stcb, m, offset, length, 2833 init_addr); 2834 } 2835 /* else, no asconfs allowed, so what we sent is what we get */ 2836 } 2837 } 2838 2839 /* 2840 * sctp_bindx() support 2841 */ 2842 uint32_t 2843 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, uint16_t type) 2844 { 2845 struct ifaddr *ifa; 2846 2847 if (sa->sa_len == 0) 2848 return (EINVAL); 2849 2850 ifa = sctp_find_ifa_by_addr(sa); 2851 if (ifa != NULL) { 2852 #ifdef INET6 2853 if (ifa->ifa_addr->sa_family == AF_INET6) { 2854 struct in6_ifaddr *ifa6; 2855 ifa6 = (struct in6_ifaddr *)ifa; 2856 if (IFA6_IS_DEPRECATED(ifa6) || 2857 (ifa6->ia6_flags & (IN6_IFF_DETACHED | 2858 IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { 2859 /* Can't bind a non-existent addr. */ 2860 return (EINVAL); 2861 } 2862 } 2863 #endif /* INET6 */ 2864 /* add this address */ 2865 sctp_addr_mgmt_ep(inp, ifa, type); 2866 } else { 2867 /* invalid address! */ 2868 #ifdef SCTP_DEBUG 2869 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) { 2870 printf("addr_mgmt_ep_sa: got invalid address!\n"); 2871 } 2872 #endif /* SCTP_DEBUG */ 2873 return (EADDRNOTAVAIL); 2874 } 2875 return (0); 2876 } 2877