sctp_asconf.c revision 360744
1/*- 2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. 4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * a) Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * b) Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the distribution. 15 * 16 * c) Neither the name of Cisco Systems, Inc. nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> 34__FBSDID("$FreeBSD: stable/11/sys/netinet/sctp_asconf.c 360744 2020-05-07 02:10:44Z tuexen $"); 35 36#include <netinet/sctp_os.h> 37#include <netinet/sctp_var.h> 38#include <netinet/sctp_sysctl.h> 39#include <netinet/sctp_pcb.h> 40#include <netinet/sctp_header.h> 41#include <netinet/sctputil.h> 42#include <netinet/sctp_output.h> 43#include <netinet/sctp_asconf.h> 44#include <netinet/sctp_timer.h> 45 46/* 47 * debug flags: 48 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors 49 * SCTP_DEBUG_ASCONF2: detailed info 50 */ 51 52 53/* 54 * RFC 5061 55 * 56 * An ASCONF parameter queue exists per asoc which holds the pending address 57 * operations. Lists are updated upon receipt of ASCONF-ACK. 58 * 59 * A restricted_addrs list exists per assoc to hold local addresses that are 60 * not (yet) usable by the assoc as a source address. These addresses are 61 * either pending an ASCONF operation (and exist on the ASCONF parameter 62 * queue), or they are permanently restricted (the peer has returned an 63 * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF). 64 * 65 * Deleted addresses are always immediately removed from the lists as they will 66 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy, 67 * only if allowed. 68 */ 69 70/* 71 * ASCONF parameter processing. 72 * response_required: set if a reply is required (eg. SUCCESS_REPORT). 73 * returns a mbuf to an "error" response parameter or NULL/"success" if ok. 74 * FIX: allocating this many mbufs on the fly is pretty inefficient... 75 */ 76static struct mbuf * 77sctp_asconf_success_response(uint32_t id) 78{ 79 struct mbuf *m_reply = NULL; 80 struct sctp_asconf_paramhdr *aph; 81 82 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr), 83 0, M_NOWAIT, 1, MT_DATA); 84 if (m_reply == NULL) { 85 SCTPDBG(SCTP_DEBUG_ASCONF1, 86 "asconf_success_response: couldn't get mbuf!\n"); 87 return (NULL); 88 } 89 aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 90 aph->correlation_id = id; 91 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT); 92 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr); 93 SCTP_BUF_LEN(m_reply) = aph->ph.param_length; 94 aph->ph.param_length = htons(aph->ph.param_length); 95 96 return (m_reply); 97} 98 99static struct mbuf * 100sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv, 101 uint16_t tlv_length) 102{ 103 struct mbuf *m_reply = NULL; 104 struct sctp_asconf_paramhdr *aph; 105 struct sctp_error_cause *error; 106 size_t buf_len; 107 uint16_t i, param_length, cause_length, padding_length; 108 uint8_t *tlv; 109 110 if (error_tlv == NULL) { 111 tlv_length = 0; 112 } 113 cause_length = sizeof(struct sctp_error_cause) + tlv_length; 114 param_length = sizeof(struct sctp_asconf_paramhdr) + cause_length; 115 padding_length = tlv_length % 4; 116 if (padding_length != 0) { 117 padding_length = 4 - padding_length; 118 } 119 buf_len = param_length + padding_length; 120 if (buf_len > MLEN) { 121 SCTPDBG(SCTP_DEBUG_ASCONF1, 122 "asconf_error_response: tlv_length (%xh) too big\n", 123 tlv_length); 124 return (NULL); 125 } 126 m_reply = sctp_get_mbuf_for_msg(buf_len, 0, M_NOWAIT, 1, MT_DATA); 127 if (m_reply == NULL) { 128 SCTPDBG(SCTP_DEBUG_ASCONF1, 129 "asconf_error_response: couldn't get mbuf!\n"); 130 return (NULL); 131 } 132 aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 133 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND); 134 aph->ph.param_length = htons(param_length); 135 aph->correlation_id = id; 136 error = (struct sctp_error_cause *)(aph + 1); 137 error->code = htons(cause); 138 error->length = htons(cause_length); 139 if (error_tlv != NULL) { 140 tlv = (uint8_t *)(error + 1); 141 memcpy(tlv, error_tlv, tlv_length); 142 for (i = 0; i < padding_length; i++) { 143 tlv[tlv_length + i] = 0; 144 } 145 } 146 SCTP_BUF_LEN(m_reply) = buf_len; 147 return (m_reply); 148} 149 150static struct mbuf * 151sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph, 152 struct sctp_tcb *stcb, int send_hb, int response_required) 153{ 154 struct sctp_nets *net; 155 struct mbuf *m_reply = NULL; 156 union sctp_sockstore store; 157 struct sctp_paramhdr *ph; 158 uint16_t param_type, aparam_length; 159#if defined(INET) || defined(INET6) 160 uint16_t param_length; 161#endif 162 struct sockaddr *sa; 163 int zero_address = 0; 164 int bad_address = 0; 165#ifdef INET 166 struct sockaddr_in *sin; 167 struct sctp_ipv4addr_param *v4addr; 168#endif 169#ifdef INET6 170 struct sockaddr_in6 *sin6; 171 struct sctp_ipv6addr_param *v6addr; 172#endif 173 174 aparam_length = ntohs(aph->ph.param_length); 175 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) { 176 return (NULL); 177 } 178 ph = (struct sctp_paramhdr *)(aph + 1); 179 param_type = ntohs(ph->param_type); 180#if defined(INET) || defined(INET6) 181 param_length = ntohs(ph->param_length); 182 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) { 183 return (NULL); 184 } 185#endif 186 sa = &store.sa; 187 switch (param_type) { 188#ifdef INET 189 case SCTP_IPV4_ADDRESS: 190 if (param_length != sizeof(struct sctp_ipv4addr_param)) { 191 /* invalid param size */ 192 return (NULL); 193 } 194 v4addr = (struct sctp_ipv4addr_param *)ph; 195 sin = &store.sin; 196 memset(sin, 0, sizeof(*sin)); 197 sin->sin_family = AF_INET; 198 sin->sin_len = sizeof(struct sockaddr_in); 199 sin->sin_port = stcb->rport; 200 sin->sin_addr.s_addr = v4addr->addr; 201 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) || 202 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) { 203 bad_address = 1; 204 } 205 if (sin->sin_addr.s_addr == INADDR_ANY) 206 zero_address = 1; 207 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); 208 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 209 break; 210#endif 211#ifdef INET6 212 case SCTP_IPV6_ADDRESS: 213 if (param_length != sizeof(struct sctp_ipv6addr_param)) { 214 /* invalid param size */ 215 return (NULL); 216 } 217 v6addr = (struct sctp_ipv6addr_param *)ph; 218 sin6 = &store.sin6; 219 memset(sin6, 0, sizeof(*sin6)); 220 sin6->sin6_family = AF_INET6; 221 sin6->sin6_len = sizeof(struct sockaddr_in6); 222 sin6->sin6_port = stcb->rport; 223 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, 224 sizeof(struct in6_addr)); 225 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) { 226 bad_address = 1; 227 } 228 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 229 zero_address = 1; 230 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); 231 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 232 break; 233#endif 234 default: 235 m_reply = sctp_asconf_error_response(aph->correlation_id, 236 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph, 237 aparam_length); 238 return (m_reply); 239 } /* end switch */ 240 241 /* if 0.0.0.0/::0, add the source address instead */ 242 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 243 sa = src; 244 SCTPDBG(SCTP_DEBUG_ASCONF1, 245 "process_asconf_add_ip: using source addr "); 246 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src); 247 } 248 net = NULL; 249 /* add the address */ 250 if (bad_address) { 251 m_reply = sctp_asconf_error_response(aph->correlation_id, 252 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph, 253 aparam_length); 254 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port, 255 SCTP_DONOT_SETSCOPE, 256 SCTP_ADDR_DYNAMIC_ADDED) != 0) { 257 SCTPDBG(SCTP_DEBUG_ASCONF1, 258 "process_asconf_add_ip: error adding address\n"); 259 m_reply = sctp_asconf_error_response(aph->correlation_id, 260 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph, 261 aparam_length); 262 } else { 263 if (response_required) { 264 m_reply = 265 sctp_asconf_success_response(aph->correlation_id); 266 } 267 if (net != NULL) { 268 /* notify upper layer */ 269 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 270 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net); 271 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, 272 stcb, net); 273 if (send_hb) { 274 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); 275 } 276 } 277 } 278 return (m_reply); 279} 280 281static int 282sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src) 283{ 284 struct sctp_nets *src_net, *net, *nnet; 285 286 /* make sure the source address exists as a destination net */ 287 src_net = sctp_findnet(stcb, src); 288 if (src_net == NULL) { 289 /* not found */ 290 return (-1); 291 } 292 293 /* delete all destination addresses except the source */ 294 TAILQ_FOREACH_SAFE(net, &stcb->asoc.nets, sctp_next, nnet) { 295 if (net != src_net) { 296 /* delete this address */ 297 SCTPDBG(SCTP_DEBUG_ASCONF1, 298 "asconf_del_remote_addrs_except: deleting "); 299 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, 300 (struct sockaddr *)&net->ro._l_addr); 301 /* notify upper layer */ 302 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, 303 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED); 304 sctp_remove_net(stcb, net); 305 } 306 } 307 return (0); 308} 309 310static struct mbuf * 311sctp_process_asconf_delete_ip(struct sockaddr *src, 312 struct sctp_asconf_paramhdr *aph, 313 struct sctp_tcb *stcb, int response_required) 314{ 315 struct mbuf *m_reply = NULL; 316 union sctp_sockstore store; 317 struct sctp_paramhdr *ph; 318 uint16_t param_type, aparam_length; 319#if defined(INET) || defined(INET6) 320 uint16_t param_length; 321#endif 322 struct sockaddr *sa; 323 int zero_address = 0; 324 int result; 325#ifdef INET 326 struct sockaddr_in *sin; 327 struct sctp_ipv4addr_param *v4addr; 328#endif 329#ifdef INET6 330 struct sockaddr_in6 *sin6; 331 struct sctp_ipv6addr_param *v6addr; 332#endif 333 334 aparam_length = ntohs(aph->ph.param_length); 335 ph = (struct sctp_paramhdr *)(aph + 1); 336 param_type = ntohs(ph->param_type); 337 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) { 338 return (NULL); 339 } 340#if defined(INET) || defined(INET6) 341 param_length = ntohs(ph->param_length); 342 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) { 343 return (NULL); 344 } 345#endif 346 sa = &store.sa; 347 switch (param_type) { 348#ifdef INET 349 case SCTP_IPV4_ADDRESS: 350 if (param_length != sizeof(struct sctp_ipv4addr_param)) { 351 /* invalid param size */ 352 return (NULL); 353 } 354 v4addr = (struct sctp_ipv4addr_param *)ph; 355 sin = &store.sin; 356 memset(sin, 0, sizeof(*sin)); 357 sin->sin_family = AF_INET; 358 sin->sin_len = sizeof(struct sockaddr_in); 359 sin->sin_port = stcb->rport; 360 sin->sin_addr.s_addr = v4addr->addr; 361 if (sin->sin_addr.s_addr == INADDR_ANY) 362 zero_address = 1; 363 SCTPDBG(SCTP_DEBUG_ASCONF1, 364 "process_asconf_delete_ip: deleting "); 365 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 366 break; 367#endif 368#ifdef INET6 369 case SCTP_IPV6_ADDRESS: 370 if (param_length != sizeof(struct sctp_ipv6addr_param)) { 371 /* invalid param size */ 372 return (NULL); 373 } 374 v6addr = (struct sctp_ipv6addr_param *)ph; 375 sin6 = &store.sin6; 376 memset(sin6, 0, sizeof(*sin6)); 377 sin6->sin6_family = AF_INET6; 378 sin6->sin6_len = sizeof(struct sockaddr_in6); 379 sin6->sin6_port = stcb->rport; 380 memcpy(&sin6->sin6_addr, v6addr->addr, 381 sizeof(struct in6_addr)); 382 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 383 zero_address = 1; 384 SCTPDBG(SCTP_DEBUG_ASCONF1, 385 "process_asconf_delete_ip: deleting "); 386 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 387 break; 388#endif 389 default: 390 m_reply = sctp_asconf_error_response(aph->correlation_id, 391 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph, 392 aparam_length); 393 return (m_reply); 394 } 395 396 /* make sure the source address is not being deleted */ 397 if (sctp_cmpaddr(sa, src)) { 398 /* trying to delete the source address! */ 399 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n"); 400 m_reply = sctp_asconf_error_response(aph->correlation_id, 401 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph, 402 aparam_length); 403 return (m_reply); 404 } 405 406 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */ 407 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 408 result = sctp_asconf_del_remote_addrs_except(stcb, src); 409 410 if (result) { 411 /* src address did not exist? */ 412 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n"); 413 /* what error to reply with?? */ 414 m_reply = 415 sctp_asconf_error_response(aph->correlation_id, 416 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph, 417 aparam_length); 418 } else if (response_required) { 419 m_reply = 420 sctp_asconf_success_response(aph->correlation_id); 421 } 422 return (m_reply); 423 } 424 425 /* delete the address */ 426 result = sctp_del_remote_addr(stcb, sa); 427 /* 428 * note if result == -2, the address doesn't exist in the asoc but 429 * since it's being deleted anyways, we just ack the delete -- but 430 * this probably means something has already gone awry 431 */ 432 if (result == -1) { 433 /* only one address in the asoc */ 434 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n"); 435 m_reply = sctp_asconf_error_response(aph->correlation_id, 436 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph, 437 aparam_length); 438 } else { 439 if (response_required) { 440 m_reply = sctp_asconf_success_response(aph->correlation_id); 441 } 442 /* notify upper layer */ 443 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 444 } 445 return (m_reply); 446} 447 448static struct mbuf * 449sctp_process_asconf_set_primary(struct sockaddr *src, 450 struct sctp_asconf_paramhdr *aph, 451 struct sctp_tcb *stcb, int response_required) 452{ 453 struct mbuf *m_reply = NULL; 454 union sctp_sockstore store; 455 struct sctp_paramhdr *ph; 456 uint16_t param_type, aparam_length; 457#if defined(INET) || defined(INET6) 458 uint16_t param_length; 459#endif 460 struct sockaddr *sa; 461 int zero_address = 0; 462#ifdef INET 463 struct sockaddr_in *sin; 464 struct sctp_ipv4addr_param *v4addr; 465#endif 466#ifdef INET6 467 struct sockaddr_in6 *sin6; 468 struct sctp_ipv6addr_param *v6addr; 469#endif 470 471 aparam_length = ntohs(aph->ph.param_length); 472 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) { 473 return (NULL); 474 } 475 ph = (struct sctp_paramhdr *)(aph + 1); 476 param_type = ntohs(ph->param_type); 477#if defined(INET) || defined(INET6) 478 param_length = ntohs(ph->param_length); 479 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) { 480 return (NULL); 481 } 482#endif 483 sa = &store.sa; 484 switch (param_type) { 485#ifdef INET 486 case SCTP_IPV4_ADDRESS: 487 if (param_length != sizeof(struct sctp_ipv4addr_param)) { 488 /* invalid param size */ 489 return (NULL); 490 } 491 v4addr = (struct sctp_ipv4addr_param *)ph; 492 sin = &store.sin; 493 memset(sin, 0, sizeof(*sin)); 494 sin->sin_family = AF_INET; 495 sin->sin_len = sizeof(struct sockaddr_in); 496 sin->sin_addr.s_addr = v4addr->addr; 497 if (sin->sin_addr.s_addr == INADDR_ANY) 498 zero_address = 1; 499 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); 500 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 501 break; 502#endif 503#ifdef INET6 504 case SCTP_IPV6_ADDRESS: 505 if (param_length != sizeof(struct sctp_ipv6addr_param)) { 506 /* invalid param size */ 507 return (NULL); 508 } 509 v6addr = (struct sctp_ipv6addr_param *)ph; 510 sin6 = &store.sin6; 511 memset(sin6, 0, sizeof(*sin6)); 512 sin6->sin6_family = AF_INET6; 513 sin6->sin6_len = sizeof(struct sockaddr_in6); 514 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, 515 sizeof(struct in6_addr)); 516 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 517 zero_address = 1; 518 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); 519 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 520 break; 521#endif 522 default: 523 m_reply = sctp_asconf_error_response(aph->correlation_id, 524 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph, 525 aparam_length); 526 return (m_reply); 527 } 528 529 /* if 0.0.0.0/::0, use the source address instead */ 530 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 531 sa = src; 532 SCTPDBG(SCTP_DEBUG_ASCONF1, 533 "process_asconf_set_primary: using source addr "); 534 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src); 535 } 536 /* set the primary address */ 537 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) { 538 SCTPDBG(SCTP_DEBUG_ASCONF1, 539 "process_asconf_set_primary: primary address set\n"); 540 /* notify upper layer */ 541 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 542 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) && 543 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) && 544 (stcb->asoc.alternate)) { 545 sctp_free_remote_addr(stcb->asoc.alternate); 546 stcb->asoc.alternate = NULL; 547 } 548 if (response_required) { 549 m_reply = sctp_asconf_success_response(aph->correlation_id); 550 } 551 /* 552 * Mobility adaptation. Ideally, when the reception of SET 553 * PRIMARY with DELETE IP ADDRESS of the previous primary 554 * destination, unacknowledged DATA are retransmitted 555 * immediately to the new primary destination for seamless 556 * handover. If the destination is UNCONFIRMED and marked to 557 * REQ_PRIM, The retransmission occur when reception of the 558 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in 559 * sctp_input.c) Also, when change of the primary 560 * destination, it is better that all subsequent new DATA 561 * containing already queued DATA are transmitted to the new 562 * primary destination. (by micchie) 563 */ 564 if ((sctp_is_mobility_feature_on(stcb->sctp_ep, 565 SCTP_MOBILITY_BASE) || 566 sctp_is_mobility_feature_on(stcb->sctp_ep, 567 SCTP_MOBILITY_FASTHANDOFF)) && 568 sctp_is_mobility_feature_on(stcb->sctp_ep, 569 SCTP_MOBILITY_PRIM_DELETED) && 570 (stcb->asoc.primary_destination->dest_state & 571 SCTP_ADDR_UNCONFIRMED) == 0) { 572 573 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED, 574 stcb->sctp_ep, stcb, NULL, 575 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1); 576 if (sctp_is_mobility_feature_on(stcb->sctp_ep, 577 SCTP_MOBILITY_FASTHANDOFF)) { 578 sctp_assoc_immediate_retrans(stcb, 579 stcb->asoc.primary_destination); 580 } 581 if (sctp_is_mobility_feature_on(stcb->sctp_ep, 582 SCTP_MOBILITY_BASE)) { 583 sctp_move_chunks_from_net(stcb, 584 stcb->asoc.deleted_primary); 585 } 586 sctp_delete_prim_timer(stcb->sctp_ep, stcb, 587 stcb->asoc.deleted_primary); 588 } 589 } else { 590 /* couldn't set the requested primary address! */ 591 SCTPDBG(SCTP_DEBUG_ASCONF1, 592 "process_asconf_set_primary: set primary failed!\n"); 593 /* must have been an invalid address, so report */ 594 m_reply = sctp_asconf_error_response(aph->correlation_id, 595 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph, 596 aparam_length); 597 } 598 599 return (m_reply); 600} 601 602/* 603 * handles an ASCONF chunk. 604 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK 605 */ 606void 607sctp_handle_asconf(struct mbuf *m, unsigned int offset, 608 struct sockaddr *src, 609 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb, 610 int first) 611{ 612 struct sctp_association *asoc; 613 uint32_t serial_num; 614 struct mbuf *n, *m_ack, *m_result, *m_tail; 615 struct sctp_asconf_ack_chunk *ack_cp; 616 struct sctp_asconf_paramhdr *aph; 617 struct sctp_ipv6addr_param *p_addr; 618 unsigned int asconf_limit, cnt; 619 int error = 0; /* did an error occur? */ 620 621 /* asconf param buffer */ 622 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 623 struct sctp_asconf_ack *ack, *ack_next; 624 625 /* verify minimum length */ 626 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) { 627 SCTPDBG(SCTP_DEBUG_ASCONF1, 628 "handle_asconf: chunk too small = %xh\n", 629 ntohs(cp->ch.chunk_length)); 630 return; 631 } 632 asoc = &stcb->asoc; 633 serial_num = ntohl(cp->serial_number); 634 635 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) { 636 /* got a duplicate ASCONF */ 637 SCTPDBG(SCTP_DEBUG_ASCONF1, 638 "handle_asconf: got duplicate serial number = %xh\n", 639 serial_num); 640 return; 641 } else if (serial_num != (asoc->asconf_seq_in + 1)) { 642 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n", 643 serial_num, asoc->asconf_seq_in + 1); 644 return; 645 } 646 647 /* it's the expected "next" sequence number, so process it */ 648 asoc->asconf_seq_in = serial_num; /* update sequence */ 649 /* get length of all the param's in the ASCONF */ 650 asconf_limit = offset + ntohs(cp->ch.chunk_length); 651 SCTPDBG(SCTP_DEBUG_ASCONF1, 652 "handle_asconf: asconf_limit=%u, sequence=%xh\n", 653 asconf_limit, serial_num); 654 655 if (first) { 656 /* delete old cache */ 657 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n"); 658 659 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) { 660 if (ack->serial_number == serial_num) 661 break; 662 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n", 663 ack->serial_number, serial_num); 664 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next); 665 if (ack->data != NULL) { 666 sctp_m_freem(ack->data); 667 } 668 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack); 669 } 670 } 671 672 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0, 673 M_NOWAIT, 1, MT_DATA); 674 if (m_ack == NULL) { 675 SCTPDBG(SCTP_DEBUG_ASCONF1, 676 "handle_asconf: couldn't get mbuf!\n"); 677 return; 678 } 679 m_tail = m_ack; /* current reply chain's tail */ 680 681 /* fill in ASCONF-ACK header */ 682 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *); 683 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK; 684 ack_cp->ch.chunk_flags = 0; 685 ack_cp->serial_number = htonl(serial_num); 686 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */ 687 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk); 688 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk); 689 690 /* skip the lookup address parameter */ 691 offset += sizeof(struct sctp_asconf_chunk); 692 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf); 693 if (p_addr == NULL) { 694 SCTPDBG(SCTP_DEBUG_ASCONF1, 695 "handle_asconf: couldn't get lookup addr!\n"); 696 /* respond with a missing/invalid mandatory parameter error */ 697 sctp_m_freem(m_ack); 698 return; 699 } 700 /* skip lookup addr */ 701 offset += SCTP_SIZE32(ntohs(p_addr->ph.param_length)); 702 /* get pointer to first asconf param in ASCONF */ 703 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf); 704 if (aph == NULL) { 705 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n"); 706 goto send_reply; 707 } 708 /* process through all parameters */ 709 cnt = 0; 710 while (aph != NULL) { 711 unsigned int param_length, param_type; 712 713 param_type = ntohs(aph->ph.param_type); 714 param_length = ntohs(aph->ph.param_length); 715 if (offset + param_length > asconf_limit) { 716 /* parameter goes beyond end of chunk! */ 717 sctp_m_freem(m_ack); 718 return; 719 } 720 m_result = NULL; 721 722 if (param_length > sizeof(aparam_buf)) { 723 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length); 724 sctp_m_freem(m_ack); 725 return; 726 } 727 if (param_length <= sizeof(struct sctp_paramhdr)) { 728 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length); 729 sctp_m_freem(m_ack); 730 return; 731 } 732 /* get the entire parameter */ 733 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 734 if (aph == NULL) { 735 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n"); 736 sctp_m_freem(m_ack); 737 return; 738 } 739 switch (param_type) { 740 case SCTP_ADD_IP_ADDRESS: 741 m_result = sctp_process_asconf_add_ip(src, aph, stcb, 742 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error); 743 cnt++; 744 break; 745 case SCTP_DEL_IP_ADDRESS: 746 m_result = sctp_process_asconf_delete_ip(src, aph, stcb, 747 error); 748 break; 749 case SCTP_ERROR_CAUSE_IND: 750 /* not valid in an ASCONF chunk */ 751 break; 752 case SCTP_SET_PRIM_ADDR: 753 m_result = sctp_process_asconf_set_primary(src, aph, 754 stcb, error); 755 break; 756 case SCTP_NAT_VTAGS: 757 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n"); 758 break; 759 case SCTP_SUCCESS_REPORT: 760 /* not valid in an ASCONF chunk */ 761 break; 762 case SCTP_ULP_ADAPTATION: 763 /* FIX */ 764 break; 765 default: 766 if ((param_type & 0x8000) == 0) { 767 /* Been told to STOP at this param */ 768 asconf_limit = offset; 769 /* 770 * FIX FIX - We need to call 771 * sctp_arethere_unrecognized_parameters() 772 * to get a operr and send it for any 773 * param's with the 0x4000 bit set OR do it 774 * here ourselves... note we still must STOP 775 * if the 0x8000 bit is clear. 776 */ 777 } 778 /* unknown/invalid param type */ 779 break; 780 } /* switch */ 781 782 /* add any (error) result to the reply mbuf chain */ 783 if (m_result != NULL) { 784 SCTP_BUF_NEXT(m_tail) = m_result; 785 m_tail = m_result; 786 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result); 787 /* set flag to force success reports */ 788 error = 1; 789 } 790 offset += SCTP_SIZE32(param_length); 791 /* update remaining ASCONF message length to process */ 792 if (offset >= asconf_limit) { 793 /* no more data in the mbuf chain */ 794 break; 795 } 796 /* get pointer to next asconf param */ 797 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 798 sizeof(struct sctp_asconf_paramhdr), 799 (uint8_t *)&aparam_buf); 800 if (aph == NULL) { 801 /* can't get an asconf paramhdr */ 802 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n"); 803 /* FIX ME - add error here... */ 804 } 805 } 806 807send_reply: 808 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length); 809 /* save the ASCONF-ACK reply */ 810 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack), 811 struct sctp_asconf_ack); 812 if (ack == NULL) { 813 sctp_m_freem(m_ack); 814 return; 815 } 816 ack->serial_number = serial_num; 817 ack->last_sent_to = NULL; 818 ack->data = m_ack; 819 ack->len = 0; 820 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) { 821 ack->len += SCTP_BUF_LEN(n); 822 } 823 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next); 824 825 /* see if last_control_chunk_from is set properly (use IP src addr) */ 826 if (stcb->asoc.last_control_chunk_from == NULL) { 827 /* 828 * this could happen if the source address was just newly 829 * added 830 */ 831 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n"); 832 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: "); 833 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src); 834 /* look up the from address */ 835 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src); 836#ifdef SCTP_DEBUG 837 if (stcb->asoc.last_control_chunk_from == NULL) { 838 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n"); 839 } 840#endif 841 } 842} 843 844/* 845 * does the address match? returns 0 if not, 1 if so 846 */ 847static uint32_t 848sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa) 849{ 850 switch (sa->sa_family) { 851#ifdef INET6 852 case AF_INET6: 853 { 854 /* XXX scopeid */ 855 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 856 857 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) && 858 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr, 859 sizeof(struct in6_addr)) == 0)) { 860 return (1); 861 } 862 break; 863 } 864#endif 865#ifdef INET 866 case AF_INET: 867 { 868 struct sockaddr_in *sin = (struct sockaddr_in *)sa; 869 870 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) && 871 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr, 872 sizeof(struct in_addr)) == 0)) { 873 return (1); 874 } 875 break; 876 } 877#endif 878 default: 879 break; 880 } 881 return (0); 882} 883 884/* 885 * does the address match? returns 0 if not, 1 if so 886 */ 887static uint32_t 888sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa) 889{ 890#if defined(INET) || defined(INET6) 891 uint16_t param_type, param_length; 892 893 param_type = ntohs(ph->param_type); 894 param_length = ntohs(ph->param_length); 895#endif 896 switch (sa->sa_family) { 897#ifdef INET6 898 case AF_INET6: 899 { 900 /* XXX scopeid */ 901 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 902 struct sctp_ipv6addr_param *v6addr; 903 904 v6addr = (struct sctp_ipv6addr_param *)ph; 905 if ((param_type == SCTP_IPV6_ADDRESS) && 906 (param_length == sizeof(struct sctp_ipv6addr_param)) && 907 (memcmp(&v6addr->addr, &sin6->sin6_addr, 908 sizeof(struct in6_addr)) == 0)) { 909 return (1); 910 } 911 break; 912 } 913#endif 914#ifdef INET 915 case AF_INET: 916 { 917 struct sockaddr_in *sin = (struct sockaddr_in *)sa; 918 struct sctp_ipv4addr_param *v4addr; 919 920 v4addr = (struct sctp_ipv4addr_param *)ph; 921 if ((param_type == SCTP_IPV4_ADDRESS) && 922 (param_length == sizeof(struct sctp_ipv4addr_param)) && 923 (memcmp(&v4addr->addr, &sin->sin_addr, 924 sizeof(struct in_addr)) == 0)) { 925 return (1); 926 } 927 break; 928 } 929#endif 930 default: 931 break; 932 } 933 return (0); 934} 935 936/* 937 * Cleanup for non-responded/OP ERR'd ASCONF 938 */ 939void 940sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net) 941{ 942 /* 943 * clear out any existing asconfs going out 944 */ 945 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, 946 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2); 947 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out; 948 /* remove the old ASCONF on our outbound queue */ 949 sctp_toss_old_asconf(stcb); 950} 951 952/* 953 * cleanup any cached source addresses that may be topologically 954 * incorrect after a new address has been added to this interface. 955 */ 956static void 957sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn) 958{ 959 struct sctp_nets *net; 960 961 /* 962 * Ideally, we want to only clear cached routes and source addresses 963 * that are topologically incorrect. But since there is no easy way 964 * to know whether the newly added address on the ifn would cause a 965 * routing change (i.e. a new egress interface would be chosen) 966 * without doing a new routing lookup and source address selection, 967 * we will (for now) just flush any cached route using a different 968 * ifn (and cached source addrs) and let output re-choose them 969 * during the next send on that net. 970 */ 971 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 972 /* 973 * clear any cached route (and cached source address) if the 974 * route's interface is NOT the same as the address change. 975 * If it's the same interface, just clear the cached source 976 * address. 977 */ 978 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) && 979 ((ifn == NULL) || 980 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) { 981 /* clear any cached route */ 982 RTFREE(net->ro.ro_rt); 983 net->ro.ro_rt = NULL; 984 } 985 /* clear any cached source address */ 986 if (net->src_addr_selected) { 987 sctp_free_ifa(net->ro._s_addr); 988 net->ro._s_addr = NULL; 989 net->src_addr_selected = 0; 990 } 991 } 992} 993 994 995void 996sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet) 997{ 998 int error; 999 1000 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) { 1001 return; 1002 } 1003 if (stcb->asoc.deleted_primary == NULL) { 1004 return; 1005 } 1006 1007 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) { 1008 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is "); 1009 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa); 1010 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is "); 1011 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa); 1012 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, 1013 stcb->asoc.deleted_primary, 1014 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3); 1015 stcb->asoc.num_send_timers_up--; 1016 if (stcb->asoc.num_send_timers_up < 0) { 1017 stcb->asoc.num_send_timers_up = 0; 1018 } 1019 SCTP_TCB_LOCK_ASSERT(stcb); 1020 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb, 1021 stcb->asoc.deleted_primary); 1022 if (error) { 1023 SCTP_INP_DECR_REF(stcb->sctp_ep); 1024 return; 1025 } 1026 SCTP_TCB_LOCK_ASSERT(stcb); 1027#ifdef SCTP_AUDITING_ENABLED 1028 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary); 1029#endif 1030 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); 1031 if ((stcb->asoc.num_send_timers_up == 0) && 1032 (stcb->asoc.sent_queue_cnt > 0)) { 1033 struct sctp_tmit_chunk *chk; 1034 1035 chk = TAILQ_FIRST(&stcb->asoc.sent_queue); 1036 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 1037 stcb, chk->whoTo); 1038 } 1039 } 1040 return; 1041} 1042 1043static int 1044 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t); 1045 1046void 1047sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net) 1048{ 1049 struct sctp_tmit_chunk *chk; 1050 1051 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO); 1052 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net, 1053 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4); 1054 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); 1055 net->error_count = 0; 1056 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { 1057 if (chk->whoTo == net) { 1058 if (chk->sent < SCTP_DATAGRAM_RESEND) { 1059 chk->sent = SCTP_DATAGRAM_RESEND; 1060 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 1061 sctp_flight_size_decrease(chk); 1062 sctp_total_flight_decrease(stcb, chk); 1063 net->marked_retrans++; 1064 stcb->asoc.marked_retrans++; 1065 } 1066 } 1067 } 1068 if (net->marked_retrans) { 1069 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); 1070 } 1071} 1072 1073static void 1074sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) 1075{ 1076 struct sctp_nets *net; 1077 int addrnum, changed; 1078 1079 /* 1080 * If number of local valid addresses is 1, the valid address is 1081 * probably newly added address. Several valid addresses in this 1082 * association. A source address may not be changed. Additionally, 1083 * they can be configured on a same interface as "alias" addresses. 1084 * (by micchie) 1085 */ 1086 addrnum = sctp_local_addr_count(stcb); 1087 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n", 1088 addrnum); 1089 if (addrnum == 1) { 1090 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1091 /* clear any cached route and source address */ 1092 if (net->ro.ro_rt) { 1093 RTFREE(net->ro.ro_rt); 1094 net->ro.ro_rt = NULL; 1095 } 1096 if (net->src_addr_selected) { 1097 sctp_free_ifa(net->ro._s_addr); 1098 net->ro._s_addr = NULL; 1099 net->src_addr_selected = 0; 1100 } 1101 /* Retransmit unacknowledged DATA chunks immediately */ 1102 if (sctp_is_mobility_feature_on(stcb->sctp_ep, 1103 SCTP_MOBILITY_FASTHANDOFF)) { 1104 sctp_net_immediate_retrans(stcb, net); 1105 } 1106 /* also, SET PRIMARY is maybe already sent */ 1107 } 1108 return; 1109 } 1110 1111 /* Multiple local addresses exsist in the association. */ 1112 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1113 /* clear any cached route and source address */ 1114 if (net->ro.ro_rt) { 1115 RTFREE(net->ro.ro_rt); 1116 net->ro.ro_rt = NULL; 1117 } 1118 if (net->src_addr_selected) { 1119 sctp_free_ifa(net->ro._s_addr); 1120 net->ro._s_addr = NULL; 1121 net->src_addr_selected = 0; 1122 } 1123 /* 1124 * Check if the nexthop is corresponding to the new address. 1125 * If the new address is corresponding to the current 1126 * nexthop, the path will be changed. If the new address is 1127 * NOT corresponding to the current nexthop, the path will 1128 * not be changed. 1129 */ 1130 SCTP_RTALLOC((sctp_route_t *)&net->ro, 1131 stcb->sctp_ep->def_vrf_id, 1132 stcb->sctp_ep->fibnum); 1133 if (net->ro.ro_rt == NULL) 1134 continue; 1135 1136 changed = 0; 1137 switch (net->ro._l_addr.sa.sa_family) { 1138#ifdef INET 1139 case AF_INET: 1140 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) { 1141 changed = 1; 1142 } 1143 break; 1144#endif 1145#ifdef INET6 1146 case AF_INET6: 1147 if (sctp_v6src_match_nexthop( 1148 &newifa->address.sin6, (sctp_route_t *)&net->ro)) { 1149 changed = 1; 1150 } 1151 break; 1152#endif 1153 default: 1154 break; 1155 } 1156 /* 1157 * if the newly added address does not relate routing 1158 * information, we skip. 1159 */ 1160 if (changed == 0) 1161 continue; 1162 /* Retransmit unacknowledged DATA chunks immediately */ 1163 if (sctp_is_mobility_feature_on(stcb->sctp_ep, 1164 SCTP_MOBILITY_FASTHANDOFF)) { 1165 sctp_net_immediate_retrans(stcb, net); 1166 } 1167 /* Send SET PRIMARY for this new address */ 1168 if (net == stcb->asoc.primary_destination) { 1169 (void)sctp_asconf_queue_mgmt(stcb, newifa, 1170 SCTP_SET_PRIM_ADDR); 1171 } 1172 } 1173} 1174 1175/* 1176 * process an ADD/DELETE IP ack from peer. 1177 * addr: corresponding sctp_ifa to the address being added/deleted. 1178 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS. 1179 * flag: 1=success, 0=failure. 1180 */ 1181static void 1182sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag) 1183{ 1184 /* 1185 * do the necessary asoc list work- if we get a failure indication, 1186 * leave the address on the assoc's restricted list. If we get a 1187 * success indication, remove the address from the restricted list. 1188 */ 1189 /* 1190 * Note: this will only occur for ADD_IP_ADDRESS, since 1191 * DEL_IP_ADDRESS is never actually added to the list... 1192 */ 1193 if (flag) { 1194 /* success case, so remove from the restricted list */ 1195 sctp_del_local_addr_restricted(stcb, addr); 1196 1197 if (sctp_is_mobility_feature_on(stcb->sctp_ep, 1198 SCTP_MOBILITY_BASE) || 1199 sctp_is_mobility_feature_on(stcb->sctp_ep, 1200 SCTP_MOBILITY_FASTHANDOFF)) { 1201 sctp_path_check_and_react(stcb, addr); 1202 return; 1203 } 1204 /* clear any cached/topologically incorrect source addresses */ 1205 sctp_asconf_nets_cleanup(stcb, addr->ifn_p); 1206 } 1207 /* else, leave it on the list */ 1208} 1209 1210/* 1211 * add an asconf add/delete/set primary IP address parameter to the queue. 1212 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. 1213 * returns 0 if queued, -1 if not queued/removed. 1214 * NOTE: if adding, but a delete for the same address is already scheduled 1215 * (and not yet sent out), simply remove it from queue. Same for deleting 1216 * an address already scheduled for add. If a duplicate operation is found, 1217 * ignore the new one. 1218 */ 1219static int 1220sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa, 1221 uint16_t type) 1222{ 1223 struct sctp_asconf_addr *aa, *aa_next; 1224 1225 /* make sure the request isn't already in the queue */ 1226 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { 1227 /* address match? */ 1228 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0) 1229 continue; 1230 /* 1231 * is the request already in queue but not sent? pass the 1232 * request already sent in order to resolve the following 1233 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we 1234 * can't remove the ADD request already sent 3. arrival of 1235 * ADD 1236 */ 1237 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) { 1238 return (-1); 1239 } 1240 /* is the negative request already in queue, and not sent */ 1241 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) && 1242 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) { 1243 /* add requested, delete already queued */ 1244 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 1245 /* remove the ifa from the restricted list */ 1246 sctp_del_local_addr_restricted(stcb, ifa); 1247 /* free the asconf param */ 1248 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1249 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n"); 1250 return (-1); 1251 } 1252 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) && 1253 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) { 1254 /* delete requested, add already queued */ 1255 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 1256 /* remove the aa->ifa from the restricted list */ 1257 sctp_del_local_addr_restricted(stcb, aa->ifa); 1258 /* free the asconf param */ 1259 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1260 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n"); 1261 return (-1); 1262 } 1263 } /* for each aa */ 1264 1265 /* adding new request to the queue */ 1266 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 1267 SCTP_M_ASC_ADDR); 1268 if (aa == NULL) { 1269 /* didn't get memory */ 1270 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n"); 1271 return (-1); 1272 } 1273 aa->special_del = 0; 1274 /* fill in asconf address parameter fields */ 1275 /* top level elements are "networked" during send */ 1276 aa->ap.aph.ph.param_type = type; 1277 aa->ifa = ifa; 1278 atomic_add_int(&ifa->refcount, 1); 1279 /* correlation_id filled in during send routine later... */ 1280 switch (ifa->address.sa.sa_family) { 1281#ifdef INET6 1282 case AF_INET6: 1283 { 1284 struct sockaddr_in6 *sin6; 1285 1286 sin6 = &ifa->address.sin6; 1287 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1288 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 1289 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + 1290 sizeof(struct sctp_ipv6addr_param); 1291 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1292 sizeof(struct in6_addr)); 1293 break; 1294 } 1295#endif 1296#ifdef INET 1297 case AF_INET: 1298 { 1299 struct sockaddr_in *sin; 1300 1301 sin = &ifa->address.sin; 1302 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1303 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 1304 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + 1305 sizeof(struct sctp_ipv4addr_param); 1306 memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1307 sizeof(struct in_addr)); 1308 break; 1309 } 1310#endif 1311 default: 1312 /* invalid family! */ 1313 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1314 sctp_free_ifa(ifa); 1315 return (-1); 1316 } 1317 aa->sent = 0; /* clear sent flag */ 1318 1319 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1320#ifdef SCTP_DEBUG 1321 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) { 1322 if (type == SCTP_ADD_IP_ADDRESS) { 1323 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: "); 1324 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa); 1325 } else if (type == SCTP_DEL_IP_ADDRESS) { 1326 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: "); 1327 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa); 1328 } else { 1329 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: "); 1330 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa); 1331 } 1332 } 1333#endif 1334 1335 return (0); 1336} 1337 1338 1339/* 1340 * add an asconf operation for the given ifa and type. 1341 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. 1342 * returns 0 if completed, -1 if not completed, 1 if immediate send is 1343 * advisable. 1344 */ 1345static int 1346sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, 1347 uint16_t type) 1348{ 1349 uint32_t status; 1350 int pending_delete_queued = 0; 1351 int last; 1352 1353 /* see if peer supports ASCONF */ 1354 if (stcb->asoc.asconf_supported == 0) { 1355 return (-1); 1356 } 1357 1358 /* 1359 * if this is deleting the last address from the assoc, mark it as 1360 * pending. 1361 */ 1362 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) { 1363 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 1364 last = (sctp_local_addr_count(stcb) == 0); 1365 } else { 1366 last = (sctp_local_addr_count(stcb) == 1); 1367 } 1368 if (last) { 1369 /* set the pending delete info only */ 1370 stcb->asoc.asconf_del_pending = 1; 1371 stcb->asoc.asconf_addr_del_pending = ifa; 1372 atomic_add_int(&ifa->refcount, 1); 1373 SCTPDBG(SCTP_DEBUG_ASCONF2, 1374 "asconf_queue_add: mark delete last address pending\n"); 1375 return (-1); 1376 } 1377 } 1378 1379 /* queue an asconf parameter */ 1380 status = sctp_asconf_queue_mgmt(stcb, ifa, type); 1381 1382 /* 1383 * if this is an add, and there is a delete also pending (i.e. the 1384 * last local address is being changed), queue the pending delete 1385 * too. 1386 */ 1387 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) { 1388 /* queue in the pending delete */ 1389 if (sctp_asconf_queue_mgmt(stcb, 1390 stcb->asoc.asconf_addr_del_pending, 1391 SCTP_DEL_IP_ADDRESS) == 0) { 1392 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queuing pending delete\n"); 1393 pending_delete_queued = 1; 1394 /* clear out the pending delete info */ 1395 stcb->asoc.asconf_del_pending = 0; 1396 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending); 1397 stcb->asoc.asconf_addr_del_pending = NULL; 1398 } 1399 } 1400 1401 if (pending_delete_queued) { 1402 struct sctp_nets *net; 1403 1404 /* 1405 * since we know that the only/last address is now being 1406 * changed in this case, reset the cwnd/rto on all nets to 1407 * start as a new address and path. Also clear the error 1408 * counts to give the assoc the best chance to complete the 1409 * address change. 1410 */ 1411 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1412 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, 1413 net); 1414 net->RTO = 0; 1415 net->error_count = 0; 1416 } 1417 stcb->asoc.overall_error_count = 0; 1418 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 1419 sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 1420 stcb->asoc.overall_error_count, 1421 0, 1422 SCTP_FROM_SCTP_ASCONF, 1423 __LINE__); 1424 } 1425 1426 /* queue in an advisory set primary too */ 1427 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR); 1428 /* let caller know we should send this out immediately */ 1429 status = 1; 1430 } 1431 return (status); 1432} 1433 1434/*- 1435 * add an asconf delete IP address parameter to the queue by sockaddr and 1436 * possibly with no sctp_ifa available. This is only called by the routine 1437 * that checks the addresses in an INIT-ACK against the current address list. 1438 * returns 0 if completed, non-zero if not completed. 1439 * NOTE: if an add is already scheduled (and not yet sent out), simply 1440 * remove it from queue. If a duplicate operation is found, ignore the 1441 * new one. 1442 */ 1443static int 1444sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa) 1445{ 1446 struct sctp_ifa *ifa; 1447 struct sctp_asconf_addr *aa, *aa_next; 1448 1449 if (stcb == NULL) { 1450 return (-1); 1451 } 1452 /* see if peer supports ASCONF */ 1453 if (stcb->asoc.asconf_supported == 0) { 1454 return (-1); 1455 } 1456 /* make sure the request isn't already in the queue */ 1457 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { 1458 /* address match? */ 1459 if (sctp_asconf_addr_match(aa, sa) == 0) 1460 continue; 1461 /* is the request already in queue (sent or not) */ 1462 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 1463 return (-1); 1464 } 1465 /* is the negative request already in queue, and not sent */ 1466 if (aa->sent == 1) 1467 continue; 1468 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) { 1469 /* add already queued, so remove existing entry */ 1470 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 1471 sctp_del_local_addr_restricted(stcb, aa->ifa); 1472 /* free the entry */ 1473 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1474 return (-1); 1475 } 1476 } /* for each aa */ 1477 1478 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */ 1479 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED); 1480 1481 /* adding new request to the queue */ 1482 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 1483 SCTP_M_ASC_ADDR); 1484 if (aa == NULL) { 1485 /* didn't get memory */ 1486 SCTPDBG(SCTP_DEBUG_ASCONF1, 1487 "sctp_asconf_queue_sa_delete: failed to get memory!\n"); 1488 return (-1); 1489 } 1490 aa->special_del = 0; 1491 /* fill in asconf address parameter fields */ 1492 /* top level elements are "networked" during send */ 1493 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; 1494 aa->ifa = ifa; 1495 if (ifa) 1496 atomic_add_int(&ifa->refcount, 1); 1497 /* correlation_id filled in during send routine later... */ 1498 switch (sa->sa_family) { 1499#ifdef INET6 1500 case AF_INET6: 1501 { 1502 /* IPv6 address */ 1503 struct sockaddr_in6 *sin6; 1504 1505 sin6 = (struct sockaddr_in6 *)sa; 1506 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1507 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 1508 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param); 1509 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1510 sizeof(struct in6_addr)); 1511 break; 1512 } 1513#endif 1514#ifdef INET 1515 case AF_INET: 1516 { 1517 /* IPv4 address */ 1518 struct sockaddr_in *sin = (struct sockaddr_in *)sa; 1519 1520 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1521 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 1522 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param); 1523 memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1524 sizeof(struct in_addr)); 1525 break; 1526 } 1527#endif 1528 default: 1529 /* invalid family! */ 1530 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1531 if (ifa) 1532 sctp_free_ifa(ifa); 1533 return (-1); 1534 } 1535 aa->sent = 0; /* clear sent flag */ 1536 1537 /* delete goes to the back of the queue */ 1538 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1539 1540 /* sa_ignore MEMLEAK {memory is put on the tailq} */ 1541 return (0); 1542} 1543 1544/* 1545 * find a specific asconf param on our "sent" queue 1546 */ 1547static struct sctp_asconf_addr * 1548sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id) 1549{ 1550 struct sctp_asconf_addr *aa; 1551 1552 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 1553 if (aa->ap.aph.correlation_id == correlation_id && 1554 aa->sent == 1) { 1555 /* found it */ 1556 return (aa); 1557 } 1558 } 1559 /* didn't find it */ 1560 return (NULL); 1561} 1562 1563/* 1564 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do 1565 * notifications based on the error response 1566 */ 1567static void 1568sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED, 1569 struct sctp_asconf_paramhdr *aph) 1570{ 1571 struct sctp_error_cause *eh; 1572 struct sctp_paramhdr *ph; 1573 uint16_t param_type; 1574 uint16_t error_code; 1575 1576 eh = (struct sctp_error_cause *)(aph + 1); 1577 ph = (struct sctp_paramhdr *)(eh + 1); 1578 /* validate lengths */ 1579 if (htons(eh->length) + sizeof(struct sctp_error_cause) > 1580 htons(aph->ph.param_length)) { 1581 /* invalid error cause length */ 1582 SCTPDBG(SCTP_DEBUG_ASCONF1, 1583 "asconf_process_error: cause element too long\n"); 1584 return; 1585 } 1586 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) > 1587 htons(eh->length)) { 1588 /* invalid included TLV length */ 1589 SCTPDBG(SCTP_DEBUG_ASCONF1, 1590 "asconf_process_error: included TLV too long\n"); 1591 return; 1592 } 1593 /* which error code ? */ 1594 error_code = ntohs(eh->code); 1595 param_type = ntohs(aph->ph.param_type); 1596 /* FIX: this should go back up the REMOTE_ERROR ULP notify */ 1597 switch (error_code) { 1598 case SCTP_CAUSE_RESOURCE_SHORTAGE: 1599 /* we allow ourselves to "try again" for this error */ 1600 break; 1601 default: 1602 /* peer can't handle it... */ 1603 switch (param_type) { 1604 case SCTP_ADD_IP_ADDRESS: 1605 case SCTP_DEL_IP_ADDRESS: 1606 case SCTP_SET_PRIM_ADDR: 1607 break; 1608 default: 1609 break; 1610 } 1611 } 1612} 1613 1614/* 1615 * process an asconf queue param. 1616 * aparam: parameter to process, will be removed from the queue. 1617 * flag: 1=success case, 0=failure case 1618 */ 1619static void 1620sctp_asconf_process_param_ack(struct sctp_tcb *stcb, 1621 struct sctp_asconf_addr *aparam, uint32_t flag) 1622{ 1623 uint16_t param_type; 1624 1625 /* process this param */ 1626 param_type = aparam->ap.aph.ph.param_type; 1627 switch (param_type) { 1628 case SCTP_ADD_IP_ADDRESS: 1629 SCTPDBG(SCTP_DEBUG_ASCONF1, 1630 "process_param_ack: added IP address\n"); 1631 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag); 1632 break; 1633 case SCTP_DEL_IP_ADDRESS: 1634 SCTPDBG(SCTP_DEBUG_ASCONF1, 1635 "process_param_ack: deleted IP address\n"); 1636 /* nothing really to do... lists already updated */ 1637 break; 1638 case SCTP_SET_PRIM_ADDR: 1639 SCTPDBG(SCTP_DEBUG_ASCONF1, 1640 "process_param_ack: set primary IP address\n"); 1641 /* nothing to do... peer may start using this addr */ 1642 break; 1643 default: 1644 /* should NEVER happen */ 1645 break; 1646 } 1647 1648 /* remove the param and free it */ 1649 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next); 1650 if (aparam->ifa) 1651 sctp_free_ifa(aparam->ifa); 1652 SCTP_FREE(aparam, SCTP_M_ASC_ADDR); 1653} 1654 1655/* 1656 * cleanup from a bad asconf ack parameter 1657 */ 1658static void 1659sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED) 1660{ 1661 /* assume peer doesn't really know how to do asconfs */ 1662 /* XXX we could free the pending queue here */ 1663 1664} 1665 1666void 1667sctp_handle_asconf_ack(struct mbuf *m, int offset, 1668 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb, 1669 struct sctp_nets *net, int *abort_no_unlock) 1670{ 1671 struct sctp_association *asoc; 1672 uint32_t serial_num; 1673 uint16_t ack_length; 1674 struct sctp_asconf_paramhdr *aph; 1675 struct sctp_asconf_addr *aa, *aa_next; 1676 uint32_t last_error_id = 0; /* last error correlation id */ 1677 uint32_t id; 1678 struct sctp_asconf_addr *ap; 1679 1680 /* asconf param buffer */ 1681 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 1682 1683 /* verify minimum length */ 1684 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) { 1685 SCTPDBG(SCTP_DEBUG_ASCONF1, 1686 "handle_asconf_ack: chunk too small = %xh\n", 1687 ntohs(cp->ch.chunk_length)); 1688 return; 1689 } 1690 asoc = &stcb->asoc; 1691 serial_num = ntohl(cp->serial_number); 1692 1693 /* 1694 * NOTE: we may want to handle this differently- currently, we will 1695 * abort when we get an ack for the expected serial number + 1 (eg. 1696 * we didn't send it), process an ack normally if it is the expected 1697 * serial number, and re-send the previous ack for *ALL* other 1698 * serial numbers 1699 */ 1700 1701 /* 1702 * if the serial number is the next expected, but I didn't send it, 1703 * abort the asoc, since someone probably just hijacked us... 1704 */ 1705 if (serial_num == (asoc->asconf_seq_out + 1)) { 1706 struct mbuf *op_err; 1707 char msg[SCTP_DIAG_INFO_LEN]; 1708 1709 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n"); 1710 snprintf(msg, sizeof(msg), "Never sent serial number %8.8x", 1711 serial_num); 1712 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); 1713 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); 1714 *abort_no_unlock = 1; 1715 return; 1716 } 1717 if (serial_num != asoc->asconf_seq_out_acked + 1) { 1718 /* got a duplicate/unexpected ASCONF-ACK */ 1719 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", 1720 serial_num, asoc->asconf_seq_out_acked + 1); 1721 return; 1722 } 1723 1724 if (serial_num == asoc->asconf_seq_out - 1) { 1725 /* stop our timer */ 1726 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, 1727 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5); 1728 } 1729 1730 /* process the ASCONF-ACK contents */ 1731 ack_length = ntohs(cp->ch.chunk_length) - 1732 sizeof(struct sctp_asconf_ack_chunk); 1733 offset += sizeof(struct sctp_asconf_ack_chunk); 1734 /* process through all parameters */ 1735 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) { 1736 unsigned int param_length, param_type; 1737 1738 /* get pointer to next asconf parameter */ 1739 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 1740 sizeof(struct sctp_asconf_paramhdr), aparam_buf); 1741 if (aph == NULL) { 1742 /* can't get an asconf paramhdr */ 1743 sctp_asconf_ack_clear(stcb); 1744 return; 1745 } 1746 param_type = ntohs(aph->ph.param_type); 1747 param_length = ntohs(aph->ph.param_length); 1748 if (param_length > ack_length) { 1749 sctp_asconf_ack_clear(stcb); 1750 return; 1751 } 1752 if (param_length < sizeof(struct sctp_paramhdr)) { 1753 sctp_asconf_ack_clear(stcb); 1754 return; 1755 } 1756 /* get the complete parameter... */ 1757 if (param_length > sizeof(aparam_buf)) { 1758 SCTPDBG(SCTP_DEBUG_ASCONF1, 1759 "param length (%u) larger than buffer size!\n", param_length); 1760 sctp_asconf_ack_clear(stcb); 1761 return; 1762 } 1763 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 1764 if (aph == NULL) { 1765 sctp_asconf_ack_clear(stcb); 1766 return; 1767 } 1768 /* correlation_id is transparent to peer, no ntohl needed */ 1769 id = aph->correlation_id; 1770 1771 switch (param_type) { 1772 case SCTP_ERROR_CAUSE_IND: 1773 last_error_id = id; 1774 /* find the corresponding asconf param in our queue */ 1775 ap = sctp_asconf_find_param(stcb, id); 1776 if (ap == NULL) { 1777 /* hmm... can't find this in our queue! */ 1778 break; 1779 } 1780 /* process the parameter, failed flag */ 1781 sctp_asconf_process_param_ack(stcb, ap, 0); 1782 /* process the error response */ 1783 sctp_asconf_process_error(stcb, aph); 1784 break; 1785 case SCTP_SUCCESS_REPORT: 1786 /* find the corresponding asconf param in our queue */ 1787 ap = sctp_asconf_find_param(stcb, id); 1788 if (ap == NULL) { 1789 /* hmm... can't find this in our queue! */ 1790 break; 1791 } 1792 /* process the parameter, success flag */ 1793 sctp_asconf_process_param_ack(stcb, ap, 1); 1794 break; 1795 default: 1796 break; 1797 } /* switch */ 1798 1799 /* update remaining ASCONF-ACK message length to process */ 1800 ack_length -= SCTP_SIZE32(param_length); 1801 if (ack_length <= 0) { 1802 /* no more data in the mbuf chain */ 1803 break; 1804 } 1805 offset += SCTP_SIZE32(param_length); 1806 } /* while */ 1807 1808 /* 1809 * if there are any "sent" params still on the queue, these are 1810 * implicitly "success", or "failed" (if we got an error back) ... 1811 * so process these appropriately 1812 * 1813 * we assume that the correlation_id's are monotonically increasing 1814 * beginning from 1 and that we don't have *that* many outstanding 1815 * at any given time 1816 */ 1817 if (last_error_id == 0) 1818 last_error_id--; /* set to "max" value */ 1819 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { 1820 if (aa->sent == 1) { 1821 /* 1822 * implicitly successful or failed if correlation_id 1823 * < last_error_id, then success else, failure 1824 */ 1825 if (aa->ap.aph.correlation_id < last_error_id) 1826 sctp_asconf_process_param_ack(stcb, aa, 1); 1827 else 1828 sctp_asconf_process_param_ack(stcb, aa, 0); 1829 } else { 1830 /* 1831 * since we always process in order (FIFO queue) if 1832 * we reach one that hasn't been sent, the rest 1833 * should not have been sent either. so, we're 1834 * done... 1835 */ 1836 break; 1837 } 1838 } 1839 1840 /* update the next sequence number to use */ 1841 asoc->asconf_seq_out_acked++; 1842 /* remove the old ASCONF on our outbound queue */ 1843 sctp_toss_old_asconf(stcb); 1844 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) { 1845#ifdef SCTP_TIMER_BASED_ASCONF 1846 /* we have more params, so restart our timer */ 1847 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, 1848 stcb, net); 1849#else 1850 /* we have more params, so send out more */ 1851 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); 1852#endif 1853 } 1854} 1855 1856#ifdef INET6 1857static uint32_t 1858sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa) 1859{ 1860 struct sockaddr_in6 *sin6, *net6; 1861 struct sctp_nets *net; 1862 1863 if (sa->sa_family != AF_INET6) { 1864 /* wrong family */ 1865 return (0); 1866 } 1867 sin6 = (struct sockaddr_in6 *)sa; 1868 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) { 1869 /* not link local address */ 1870 return (0); 1871 } 1872 /* hunt through our destination nets list for this scope_id */ 1873 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1874 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family != 1875 AF_INET6) 1876 continue; 1877 net6 = (struct sockaddr_in6 *)&net->ro._l_addr; 1878 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0) 1879 continue; 1880 if (sctp_is_same_scope(sin6, net6)) { 1881 /* found one */ 1882 return (1); 1883 } 1884 } 1885 /* didn't find one */ 1886 return (0); 1887} 1888#endif 1889 1890/* 1891 * address management functions 1892 */ 1893static void 1894sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 1895 struct sctp_ifa *ifa, uint16_t type, int addr_locked) 1896{ 1897 int status; 1898 1899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 || 1900 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { 1901 /* subset bound, no ASCONF allowed case, so ignore */ 1902 return; 1903 } 1904 /* 1905 * note: we know this is not the subset bound, no ASCONF case eg. 1906 * this is boundall or subset bound w/ASCONF allowed 1907 */ 1908 1909 /* first, make sure that the address is IPv4 or IPv6 and not jailed */ 1910 switch (ifa->address.sa.sa_family) { 1911#ifdef INET6 1912 case AF_INET6: 1913 if (prison_check_ip6(inp->ip_inp.inp.inp_cred, 1914 &ifa->address.sin6.sin6_addr) != 0) { 1915 return; 1916 } 1917 break; 1918#endif 1919#ifdef INET 1920 case AF_INET: 1921 if (prison_check_ip4(inp->ip_inp.inp.inp_cred, 1922 &ifa->address.sin.sin_addr) != 0) { 1923 return; 1924 } 1925 break; 1926#endif 1927 default: 1928 return; 1929 } 1930#ifdef INET6 1931 /* make sure we're "allowed" to add this type of addr */ 1932 if (ifa->address.sa.sa_family == AF_INET6) { 1933 /* invalid if we're not a v6 endpoint */ 1934 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) 1935 return; 1936 /* is the v6 addr really valid ? */ 1937 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { 1938 return; 1939 } 1940 } 1941#endif 1942 /* put this address on the "pending/do not use yet" list */ 1943 sctp_add_local_addr_restricted(stcb, ifa); 1944 /* 1945 * check address scope if address is out of scope, don't queue 1946 * anything... note: this would leave the address on both inp and 1947 * asoc lists 1948 */ 1949 switch (ifa->address.sa.sa_family) { 1950#ifdef INET6 1951 case AF_INET6: 1952 { 1953 struct sockaddr_in6 *sin6; 1954 1955 sin6 = &ifa->address.sin6; 1956 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 1957 /* we skip unspecifed addresses */ 1958 return; 1959 } 1960 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 1961 if (stcb->asoc.scope.local_scope == 0) { 1962 return; 1963 } 1964 /* is it the right link local scope? */ 1965 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { 1966 return; 1967 } 1968 } 1969 if (stcb->asoc.scope.site_scope == 0 && 1970 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { 1971 return; 1972 } 1973 break; 1974 } 1975#endif 1976#ifdef INET 1977 case AF_INET: 1978 { 1979 struct sockaddr_in *sin; 1980 struct in6pcb *inp6; 1981 1982 inp6 = (struct in6pcb *)&inp->ip_inp.inp; 1983 /* invalid if we are a v6 only endpoint */ 1984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 1985 SCTP_IPV6_V6ONLY(inp6)) 1986 return; 1987 1988 sin = &ifa->address.sin; 1989 if (sin->sin_addr.s_addr == 0) { 1990 /* we skip unspecifed addresses */ 1991 return; 1992 } 1993 if (stcb->asoc.scope.ipv4_local_scope == 0 && 1994 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 1995 return; 1996 } 1997 break; 1998 } 1999#endif 2000 default: 2001 /* else, not AF_INET or AF_INET6, so skip */ 2002 return; 2003 } 2004 2005 /* queue an asconf for this address add/delete */ 2006 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { 2007 /* does the peer do asconf? */ 2008 if (stcb->asoc.asconf_supported) { 2009 /* queue an asconf for this addr */ 2010 status = sctp_asconf_queue_add(stcb, ifa, type); 2011 2012 /* 2013 * if queued ok, and in the open state, send out the 2014 * ASCONF. If in the non-open state, these will be 2015 * sent when the state goes open. 2016 */ 2017 if (status == 0 && 2018 ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || 2019 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED))) { 2020#ifdef SCTP_TIMER_BASED_ASCONF 2021 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, 2022 stcb, stcb->asoc.primary_destination); 2023#else 2024 sctp_send_asconf(stcb, NULL, addr_locked); 2025#endif 2026 } 2027 } 2028 } 2029} 2030 2031 2032int 2033sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED) 2034{ 2035 struct sctp_asconf_iterator *asc; 2036 struct sctp_ifa *ifa; 2037 struct sctp_laddr *l; 2038 int cnt_invalid = 0; 2039 2040 asc = (struct sctp_asconf_iterator *)ptr; 2041 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 2042 ifa = l->ifa; 2043 switch (ifa->address.sa.sa_family) { 2044#ifdef INET6 2045 case AF_INET6: 2046 /* invalid if we're not a v6 endpoint */ 2047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 2048 cnt_invalid++; 2049 if (asc->cnt == cnt_invalid) 2050 return (1); 2051 } 2052 break; 2053#endif 2054#ifdef INET 2055 case AF_INET: 2056 { 2057 /* invalid if we are a v6 only endpoint */ 2058 struct in6pcb *inp6; 2059 2060 inp6 = (struct in6pcb *)&inp->ip_inp.inp; 2061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 2062 SCTP_IPV6_V6ONLY(inp6)) { 2063 cnt_invalid++; 2064 if (asc->cnt == cnt_invalid) 2065 return (1); 2066 } 2067 break; 2068 } 2069#endif 2070 default: 2071 /* invalid address family */ 2072 cnt_invalid++; 2073 if (asc->cnt == cnt_invalid) 2074 return (1); 2075 } 2076 } 2077 return (0); 2078} 2079 2080static int 2081sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED) 2082{ 2083 struct sctp_ifa *ifa; 2084 struct sctp_asconf_iterator *asc; 2085 struct sctp_laddr *laddr, *nladdr, *l; 2086 2087 /* Only for specific case not bound all */ 2088 asc = (struct sctp_asconf_iterator *)ptr; 2089 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 2090 ifa = l->ifa; 2091 if (l->action == SCTP_ADD_IP_ADDRESS) { 2092 LIST_FOREACH(laddr, &inp->sctp_addr_list, 2093 sctp_nxt_addr) { 2094 if (laddr->ifa == ifa) { 2095 laddr->action = 0; 2096 break; 2097 } 2098 2099 } 2100 } else if (l->action == SCTP_DEL_IP_ADDRESS) { 2101 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) { 2102 /* remove only after all guys are done */ 2103 if (laddr->ifa == ifa) { 2104 sctp_del_local_addr_ep(inp, ifa); 2105 } 2106 } 2107 } 2108 } 2109 return (0); 2110} 2111 2112void 2113sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 2114 void *ptr, uint32_t val SCTP_UNUSED) 2115{ 2116 struct sctp_asconf_iterator *asc; 2117 struct sctp_ifa *ifa; 2118 struct sctp_laddr *l; 2119 int cnt_invalid = 0; 2120 int type, status; 2121 int num_queued = 0; 2122 2123 asc = (struct sctp_asconf_iterator *)ptr; 2124 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 2125 ifa = l->ifa; 2126 type = l->action; 2127 2128 /* address's vrf_id must be the vrf_id of the assoc */ 2129 if (ifa->vrf_id != stcb->asoc.vrf_id) { 2130 continue; 2131 } 2132 2133 /* Same checks again for assoc */ 2134 switch (ifa->address.sa.sa_family) { 2135#ifdef INET6 2136 case AF_INET6: 2137 { 2138 /* invalid if we're not a v6 endpoint */ 2139 struct sockaddr_in6 *sin6; 2140 2141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 2142 cnt_invalid++; 2143 if (asc->cnt == cnt_invalid) 2144 return; 2145 else 2146 continue; 2147 } 2148 sin6 = &ifa->address.sin6; 2149 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2150 /* we skip unspecifed addresses */ 2151 continue; 2152 } 2153 if (prison_check_ip6(inp->ip_inp.inp.inp_cred, 2154 &sin6->sin6_addr) != 0) { 2155 continue; 2156 } 2157 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 2158 if (stcb->asoc.scope.local_scope == 0) { 2159 continue; 2160 } 2161 /* is it the right link local scope? */ 2162 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { 2163 continue; 2164 } 2165 } 2166 break; 2167 } 2168#endif 2169#ifdef INET 2170 case AF_INET: 2171 { 2172 /* invalid if we are a v6 only endpoint */ 2173 struct in6pcb *inp6; 2174 struct sockaddr_in *sin; 2175 2176 inp6 = (struct in6pcb *)&inp->ip_inp.inp; 2177 /* invalid if we are a v6 only endpoint */ 2178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 2179 SCTP_IPV6_V6ONLY(inp6)) 2180 continue; 2181 2182 sin = &ifa->address.sin; 2183 if (sin->sin_addr.s_addr == 0) { 2184 /* we skip unspecifed addresses */ 2185 continue; 2186 } 2187 if (prison_check_ip4(inp->ip_inp.inp.inp_cred, 2188 &sin->sin_addr) != 0) { 2189 continue; 2190 } 2191 if (stcb->asoc.scope.ipv4_local_scope == 0 && 2192 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 2193 continue; 2194 } 2195 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 2196 SCTP_IPV6_V6ONLY(inp6)) { 2197 cnt_invalid++; 2198 if (asc->cnt == cnt_invalid) 2199 return; 2200 else 2201 continue; 2202 } 2203 break; 2204 } 2205#endif 2206 default: 2207 /* invalid address family */ 2208 cnt_invalid++; 2209 if (asc->cnt == cnt_invalid) 2210 return; 2211 else 2212 continue; 2213 break; 2214 } 2215 2216 if (type == SCTP_ADD_IP_ADDRESS) { 2217 /* prevent this address from being used as a source */ 2218 sctp_add_local_addr_restricted(stcb, ifa); 2219 } else if (type == SCTP_DEL_IP_ADDRESS) { 2220 struct sctp_nets *net; 2221 2222 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 2223 sctp_rtentry_t *rt; 2224 2225 /* delete this address if cached */ 2226 if (net->ro._s_addr == ifa) { 2227 sctp_free_ifa(net->ro._s_addr); 2228 net->ro._s_addr = NULL; 2229 net->src_addr_selected = 0; 2230 rt = net->ro.ro_rt; 2231 if (rt) { 2232 RTFREE(rt); 2233 net->ro.ro_rt = NULL; 2234 } 2235 /* 2236 * Now we deleted our src address, 2237 * should we not also now reset the 2238 * cwnd/rto to start as if its a new 2239 * address? 2240 */ 2241 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); 2242 net->RTO = 0; 2243 2244 } 2245 } 2246 } else if (type == SCTP_SET_PRIM_ADDR) { 2247 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { 2248 /* must validate the ifa is in the ep */ 2249 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) { 2250 continue; 2251 } 2252 } else { 2253 /* Need to check scopes for this guy */ 2254 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) { 2255 continue; 2256 } 2257 } 2258 } 2259 /* queue an asconf for this address add/delete */ 2260 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) && 2261 stcb->asoc.asconf_supported == 1) { 2262 /* queue an asconf for this addr */ 2263 status = sctp_asconf_queue_add(stcb, ifa, type); 2264 /* 2265 * if queued ok, and in the open state, update the 2266 * count of queued params. If in the non-open 2267 * state, these get sent when the assoc goes open. 2268 */ 2269 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || 2270 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 2271 if (status >= 0) { 2272 num_queued++; 2273 } 2274 } 2275 } 2276 } 2277 /* 2278 * If we have queued params in the open state, send out an ASCONF. 2279 */ 2280 if (num_queued > 0) { 2281 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); 2282 } 2283} 2284 2285void 2286sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED) 2287{ 2288 struct sctp_asconf_iterator *asc; 2289 struct sctp_ifa *ifa; 2290 struct sctp_laddr *l, *nl; 2291 2292 asc = (struct sctp_asconf_iterator *)ptr; 2293 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) { 2294 ifa = l->ifa; 2295 if (l->action == SCTP_ADD_IP_ADDRESS) { 2296 /* Clear the defer use flag */ 2297 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; 2298 } 2299 sctp_free_ifa(ifa); 2300 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l); 2301 SCTP_DECR_LADDR_COUNT(); 2302 } 2303 SCTP_FREE(asc, SCTP_M_ASC_IT); 2304} 2305 2306/* 2307 * sa is the sockaddr to ask the peer to set primary to. 2308 * returns: 0 = completed, -1 = error 2309 */ 2310int32_t 2311sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa) 2312{ 2313 uint32_t vrf_id; 2314 struct sctp_ifa *ifa; 2315 2316 /* find the ifa for the desired set primary */ 2317 vrf_id = stcb->asoc.vrf_id; 2318 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 2319 if (ifa == NULL) { 2320 /* Invalid address */ 2321 return (-1); 2322 } 2323 2324 /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 2325 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) { 2326 /* set primary queuing succeeded */ 2327 SCTPDBG(SCTP_DEBUG_ASCONF1, 2328 "set_primary_ip_address_sa: queued on tcb=%p, ", 2329 (void *)stcb); 2330 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 2331 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || 2332 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 2333#ifdef SCTP_TIMER_BASED_ASCONF 2334 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2335 stcb->sctp_ep, stcb, 2336 stcb->asoc.primary_destination); 2337#else 2338 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); 2339#endif 2340 } 2341 } else { 2342 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ", 2343 (void *)stcb); 2344 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 2345 return (-1); 2346 } 2347 return (0); 2348} 2349 2350int 2351sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa) 2352{ 2353 struct sctp_tmit_chunk *chk, *nchk; 2354 unsigned int offset, asconf_limit; 2355 struct sctp_asconf_chunk *acp; 2356 struct sctp_asconf_paramhdr *aph; 2357 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 2358 struct sctp_paramhdr *ph; 2359 int add_cnt, del_cnt; 2360 uint16_t last_param_type; 2361 2362 add_cnt = del_cnt = 0; 2363 last_param_type = 0; 2364 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) { 2365 if (chk->data == NULL) { 2366 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n"); 2367 continue; 2368 } 2369 offset = 0; 2370 acp = mtod(chk->data, struct sctp_asconf_chunk *); 2371 offset += sizeof(struct sctp_asconf_chunk); 2372 asconf_limit = ntohs(acp->ch.chunk_length); 2373 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf); 2374 if (ph == NULL) { 2375 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n"); 2376 continue; 2377 } 2378 offset += ntohs(ph->param_length); 2379 2380 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); 2381 if (aph == NULL) { 2382 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n"); 2383 continue; 2384 } 2385 while (aph != NULL) { 2386 unsigned int param_length, param_type; 2387 2388 param_type = ntohs(aph->ph.param_type); 2389 param_length = ntohs(aph->ph.param_length); 2390 if (offset + param_length > asconf_limit) { 2391 /* parameter goes beyond end of chunk! */ 2392 break; 2393 } 2394 if (param_length > sizeof(aparam_buf)) { 2395 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length); 2396 break; 2397 } 2398 if (param_length <= sizeof(struct sctp_paramhdr)) { 2399 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length); 2400 break; 2401 } 2402 2403 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf); 2404 if (aph == NULL) { 2405 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n"); 2406 break; 2407 } 2408 2409 ph = (struct sctp_paramhdr *)(aph + 1); 2410 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) { 2411 switch (param_type) { 2412 case SCTP_ADD_IP_ADDRESS: 2413 add_cnt++; 2414 break; 2415 case SCTP_DEL_IP_ADDRESS: 2416 del_cnt++; 2417 break; 2418 default: 2419 break; 2420 } 2421 last_param_type = param_type; 2422 } 2423 2424 offset += SCTP_SIZE32(param_length); 2425 if (offset >= asconf_limit) { 2426 /* no more data in the mbuf chain */ 2427 break; 2428 } 2429 /* get pointer to next asconf param */ 2430 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); 2431 } 2432 } 2433 2434 /* 2435 * we want to find the sequences which consist of ADD -> DEL -> ADD 2436 * or DEL -> ADD 2437 */ 2438 if (add_cnt > del_cnt || 2439 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) { 2440 return (1); 2441 } 2442 return (0); 2443} 2444 2445static struct sockaddr * 2446sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) 2447{ 2448 struct sctp_vrf *vrf = NULL; 2449 struct sctp_ifn *sctp_ifn; 2450 struct sctp_ifa *sctp_ifa; 2451 2452 if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2453 SCTP_IPI_ADDR_RLOCK(); 2454 vrf = sctp_find_vrf(stcb->asoc.vrf_id); 2455 if (vrf == NULL) { 2456 if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2457 SCTP_IPI_ADDR_RUNLOCK(); 2458 return (NULL); 2459 } 2460 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { 2461 if (stcb->asoc.scope.loopback_scope == 0 && 2462 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { 2463 /* Skip if loopback_scope not set */ 2464 continue; 2465 } 2466 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { 2467 switch (sctp_ifa->address.sa.sa_family) { 2468#ifdef INET 2469 case AF_INET: 2470 if (stcb->asoc.scope.ipv4_addr_legal) { 2471 struct sockaddr_in *sin; 2472 2473 sin = &sctp_ifa->address.sin; 2474 if (sin->sin_addr.s_addr == 0) { 2475 /* skip unspecifed addresses */ 2476 continue; 2477 } 2478 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred, 2479 &sin->sin_addr) != 0) { 2480 continue; 2481 } 2482 if (stcb->asoc.scope.ipv4_local_scope == 0 && 2483 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) 2484 continue; 2485 2486 if (sctp_is_addr_restricted(stcb, sctp_ifa) && 2487 (!sctp_is_addr_pending(stcb, sctp_ifa))) 2488 continue; 2489 /* 2490 * found a valid local v4 address to 2491 * use 2492 */ 2493 if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2494 SCTP_IPI_ADDR_RUNLOCK(); 2495 return (&sctp_ifa->address.sa); 2496 } 2497 break; 2498#endif 2499#ifdef INET6 2500 case AF_INET6: 2501 if (stcb->asoc.scope.ipv6_addr_legal) { 2502 struct sockaddr_in6 *sin6; 2503 2504 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { 2505 continue; 2506 } 2507 2508 sin6 = &sctp_ifa->address.sin6; 2509 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2510 /* 2511 * we skip unspecifed 2512 * addresses 2513 */ 2514 continue; 2515 } 2516 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred, 2517 &sin6->sin6_addr) != 0) { 2518 continue; 2519 } 2520 if (stcb->asoc.scope.local_scope == 0 && 2521 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) 2522 continue; 2523 if (stcb->asoc.scope.site_scope == 0 && 2524 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) 2525 continue; 2526 2527 if (sctp_is_addr_restricted(stcb, sctp_ifa) && 2528 (!sctp_is_addr_pending(stcb, sctp_ifa))) 2529 continue; 2530 /* 2531 * found a valid local v6 address to 2532 * use 2533 */ 2534 if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2535 SCTP_IPI_ADDR_RUNLOCK(); 2536 return (&sctp_ifa->address.sa); 2537 } 2538 break; 2539#endif 2540 default: 2541 break; 2542 } 2543 } 2544 } 2545 /* no valid addresses found */ 2546 if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2547 SCTP_IPI_ADDR_RUNLOCK(); 2548 return (NULL); 2549} 2550 2551static struct sockaddr * 2552sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb) 2553{ 2554 struct sctp_laddr *laddr; 2555 2556 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 2557 if (laddr->ifa == NULL) { 2558 continue; 2559 } 2560 /* is the address restricted ? */ 2561 if (sctp_is_addr_restricted(stcb, laddr->ifa) && 2562 (!sctp_is_addr_pending(stcb, laddr->ifa))) 2563 continue; 2564 2565 /* found a valid local address to use */ 2566 return (&laddr->ifa->address.sa); 2567 } 2568 /* no valid addresses found */ 2569 return (NULL); 2570} 2571 2572/* 2573 * builds an ASCONF chunk from queued ASCONF params. 2574 * returns NULL on error (no mbuf, no ASCONF params queued, etc). 2575 */ 2576struct mbuf * 2577sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked) 2578{ 2579 struct mbuf *m_asconf, *m_asconf_chk; 2580 struct sctp_asconf_addr *aa; 2581 struct sctp_asconf_chunk *acp; 2582 struct sctp_asconf_paramhdr *aph; 2583 struct sctp_asconf_addr_param *aap; 2584 uint32_t p_length; 2585 uint32_t correlation_id = 1; /* 0 is reserved... */ 2586 caddr_t ptr, lookup_ptr; 2587 uint8_t lookup_used = 0; 2588 2589 /* are there any asconf params to send? */ 2590 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2591 if (aa->sent == 0) 2592 break; 2593 } 2594 if (aa == NULL) 2595 return (NULL); 2596 2597 /* 2598 * get a chunk header mbuf and a cluster for the asconf params since 2599 * it's simpler to fill in the asconf chunk header lookup address on 2600 * the fly 2601 */ 2602 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA); 2603 if (m_asconf_chk == NULL) { 2604 /* no mbuf's */ 2605 SCTPDBG(SCTP_DEBUG_ASCONF1, 2606 "compose_asconf: couldn't get chunk mbuf!\n"); 2607 return (NULL); 2608 } 2609 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); 2610 if (m_asconf == NULL) { 2611 /* no mbuf's */ 2612 SCTPDBG(SCTP_DEBUG_ASCONF1, 2613 "compose_asconf: couldn't get mbuf!\n"); 2614 sctp_m_freem(m_asconf_chk); 2615 return (NULL); 2616 } 2617 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk); 2618 SCTP_BUF_LEN(m_asconf) = 0; 2619 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *); 2620 memset(acp, 0, sizeof(struct sctp_asconf_chunk)); 2621 /* save pointers to lookup address and asconf params */ 2622 lookup_ptr = (caddr_t)(acp + 1); /* after the header */ 2623 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */ 2624 2625 /* fill in chunk header info */ 2626 acp->ch.chunk_type = SCTP_ASCONF; 2627 acp->ch.chunk_flags = 0; 2628 acp->serial_number = htonl(stcb->asoc.asconf_seq_out); 2629 stcb->asoc.asconf_seq_out++; 2630 2631 /* add parameters... up to smallest MTU allowed */ 2632 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2633 if (aa->sent) 2634 continue; 2635 /* get the parameter length */ 2636 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length); 2637 /* will it fit in current chunk? */ 2638 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) || 2639 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) { 2640 /* won't fit, so we're done with this chunk */ 2641 break; 2642 } 2643 /* assign (and store) a correlation id */ 2644 aa->ap.aph.correlation_id = correlation_id++; 2645 2646 /* 2647 * fill in address if we're doing a delete this is a simple 2648 * way for us to fill in the correlation address, which 2649 * should only be used by the peer if we're deleting our 2650 * source address and adding a new address (e.g. renumbering 2651 * case) 2652 */ 2653 if (lookup_used == 0 && 2654 (aa->special_del == 0) && 2655 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 2656 struct sctp_ipv6addr_param *lookup; 2657 uint16_t p_size, addr_size; 2658 2659 lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2660 lookup->ph.param_type = 2661 htons(aa->ap.addrp.ph.param_type); 2662 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) { 2663 /* copy IPv6 address */ 2664 p_size = sizeof(struct sctp_ipv6addr_param); 2665 addr_size = sizeof(struct in6_addr); 2666 } else { 2667 /* copy IPv4 address */ 2668 p_size = sizeof(struct sctp_ipv4addr_param); 2669 addr_size = sizeof(struct in_addr); 2670 } 2671 lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2672 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size); 2673 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); 2674 lookup_used = 1; 2675 } 2676 /* copy into current space */ 2677 memcpy(ptr, &aa->ap, p_length); 2678 2679 /* network elements and update lengths */ 2680 aph = (struct sctp_asconf_paramhdr *)ptr; 2681 aap = (struct sctp_asconf_addr_param *)ptr; 2682 /* correlation_id is transparent to peer, no htonl needed */ 2683 aph->ph.param_type = htons(aph->ph.param_type); 2684 aph->ph.param_length = htons(aph->ph.param_length); 2685 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type); 2686 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length); 2687 2688 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length); 2689 ptr += SCTP_SIZE32(p_length); 2690 2691 /* 2692 * these params are removed off the pending list upon 2693 * getting an ASCONF-ACK back from the peer, just set flag 2694 */ 2695 aa->sent = 1; 2696 } 2697 /* check to see if the lookup addr has been populated yet */ 2698 if (lookup_used == 0) { 2699 /* NOTE: if the address param is optional, can skip this... */ 2700 /* add any valid (existing) address... */ 2701 struct sctp_ipv6addr_param *lookup; 2702 uint16_t p_size, addr_size; 2703 struct sockaddr *found_addr; 2704 caddr_t addr_ptr; 2705 2706 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) 2707 found_addr = sctp_find_valid_localaddr(stcb, 2708 addr_locked); 2709 else 2710 found_addr = sctp_find_valid_localaddr_ep(stcb); 2711 2712 lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2713 if (found_addr != NULL) { 2714 switch (found_addr->sa_family) { 2715#ifdef INET6 2716 case AF_INET6: 2717 /* copy IPv6 address */ 2718 lookup->ph.param_type = 2719 htons(SCTP_IPV6_ADDRESS); 2720 p_size = sizeof(struct sctp_ipv6addr_param); 2721 addr_size = sizeof(struct in6_addr); 2722 addr_ptr = (caddr_t)&((struct sockaddr_in6 *) 2723 found_addr)->sin6_addr; 2724 break; 2725#endif 2726#ifdef INET 2727 case AF_INET: 2728 /* copy IPv4 address */ 2729 lookup->ph.param_type = 2730 htons(SCTP_IPV4_ADDRESS); 2731 p_size = sizeof(struct sctp_ipv4addr_param); 2732 addr_size = sizeof(struct in_addr); 2733 addr_ptr = (caddr_t)&((struct sockaddr_in *) 2734 found_addr)->sin_addr; 2735 break; 2736#endif 2737 default: 2738 p_size = 0; 2739 addr_size = 0; 2740 addr_ptr = NULL; 2741 break; 2742 } 2743 lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2744 memcpy(lookup->addr, addr_ptr, addr_size); 2745 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); 2746 } else { 2747 /* uh oh... don't have any address?? */ 2748 SCTPDBG(SCTP_DEBUG_ASCONF1, 2749 "compose_asconf: no lookup addr!\n"); 2750 /* XXX for now, we send a IPv4 address of 0.0.0.0 */ 2751 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS); 2752 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param))); 2753 memset(lookup->addr, 0, sizeof(struct in_addr)); 2754 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)); 2755 } 2756 } 2757 /* chain it all together */ 2758 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf; 2759 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf); 2760 acp->ch.chunk_length = htons(*retlen); 2761 2762 return (m_asconf_chk); 2763} 2764 2765/* 2766 * section to handle address changes before an association is up eg. changes 2767 * during INIT/INIT-ACK/COOKIE-ECHO handshake 2768 */ 2769 2770/* 2771 * processes the (local) addresses in the INIT-ACK chunk 2772 */ 2773static void 2774sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, 2775 unsigned int offset, unsigned int length) 2776{ 2777 struct sctp_paramhdr tmp_param, *ph; 2778 uint16_t plen, ptype; 2779 struct sctp_ifa *sctp_ifa; 2780 union sctp_sockstore store; 2781#ifdef INET6 2782 struct sctp_ipv6addr_param addr6_store; 2783#endif 2784#ifdef INET 2785 struct sctp_ipv4addr_param addr4_store; 2786#endif 2787 2788 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n"); 2789 if (stcb == NULL) /* Un-needed check for SA */ 2790 return; 2791 2792 /* convert to upper bound */ 2793 length += offset; 2794 2795 if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2796 return; 2797 } 2798 /* go through the addresses in the init-ack */ 2799 ph = (struct sctp_paramhdr *) 2800 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), 2801 (uint8_t *)&tmp_param); 2802 while (ph != NULL) { 2803 ptype = ntohs(ph->param_type); 2804 plen = ntohs(ph->param_length); 2805 switch (ptype) { 2806#ifdef INET6 2807 case SCTP_IPV6_ADDRESS: 2808 { 2809 struct sctp_ipv6addr_param *a6p; 2810 2811 /* get the entire IPv6 address param */ 2812 a6p = (struct sctp_ipv6addr_param *) 2813 sctp_m_getptr(m, offset, 2814 sizeof(struct sctp_ipv6addr_param), 2815 (uint8_t *)&addr6_store); 2816 if (plen != sizeof(struct sctp_ipv6addr_param) || 2817 a6p == NULL) { 2818 return; 2819 } 2820 memset(&store, 0, sizeof(union sctp_sockstore)); 2821 store.sin6.sin6_family = AF_INET6; 2822 store.sin6.sin6_len = sizeof(struct sockaddr_in6); 2823 store.sin6.sin6_port = stcb->rport; 2824 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr)); 2825 break; 2826 } 2827#endif 2828#ifdef INET 2829 case SCTP_IPV4_ADDRESS: 2830 { 2831 struct sctp_ipv4addr_param *a4p; 2832 2833 /* get the entire IPv4 address param */ 2834 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, 2835 sizeof(struct sctp_ipv4addr_param), 2836 (uint8_t *)&addr4_store); 2837 if (plen != sizeof(struct sctp_ipv4addr_param) || 2838 a4p == NULL) { 2839 return; 2840 } 2841 memset(&store, 0, sizeof(union sctp_sockstore)); 2842 store.sin.sin_family = AF_INET; 2843 store.sin.sin_len = sizeof(struct sockaddr_in); 2844 store.sin.sin_port = stcb->rport; 2845 store.sin.sin_addr.s_addr = a4p->addr; 2846 break; 2847 } 2848#endif 2849 default: 2850 goto next_addr; 2851 } 2852 2853 /* see if this address really (still) exists */ 2854 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id, 2855 SCTP_ADDR_NOT_LOCKED); 2856 if (sctp_ifa == NULL) { 2857 /* address doesn't exist anymore */ 2858 int status; 2859 2860 /* are ASCONFs allowed ? */ 2861 if ((sctp_is_feature_on(stcb->sctp_ep, 2862 SCTP_PCB_FLAGS_DO_ASCONF)) && 2863 stcb->asoc.asconf_supported) { 2864 /* queue an ASCONF DEL_IP_ADDRESS */ 2865 status = sctp_asconf_queue_sa_delete(stcb, &store.sa); 2866 /* 2867 * if queued ok, and in correct state, send 2868 * out the ASCONF. 2869 */ 2870 if (status == 0 && 2871 SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) { 2872#ifdef SCTP_TIMER_BASED_ASCONF 2873 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2874 stcb->sctp_ep, stcb, 2875 stcb->asoc.primary_destination); 2876#else 2877 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); 2878#endif 2879 } 2880 } 2881 } 2882 2883next_addr: 2884 /* 2885 * Sanity check: Make sure the length isn't 0, otherwise 2886 * we'll be stuck in this loop for a long time... 2887 */ 2888 if (SCTP_SIZE32(plen) == 0) { 2889 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n", 2890 plen, ptype); 2891 return; 2892 } 2893 /* get next parameter */ 2894 offset += SCTP_SIZE32(plen); 2895 if ((offset + sizeof(struct sctp_paramhdr)) > length) 2896 return; 2897 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2898 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); 2899 } /* while */ 2900} 2901 2902/* FIX ME: need to verify return result for v6 address type if v6 disabled */ 2903/* 2904 * checks to see if a specific address is in the initack address list returns 2905 * 1 if found, 0 if not 2906 */ 2907static uint32_t 2908sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa) 2909{ 2910 struct sctp_paramhdr tmp_param, *ph; 2911 uint16_t plen, ptype; 2912#ifdef INET 2913 struct sockaddr_in *sin; 2914 struct sctp_ipv4addr_param *a4p; 2915 struct sctp_ipv6addr_param addr4_store; 2916#endif 2917#ifdef INET6 2918 struct sockaddr_in6 *sin6; 2919 struct sctp_ipv6addr_param *a6p; 2920 struct sctp_ipv6addr_param addr6_store; 2921 struct sockaddr_in6 sin6_tmp; 2922#endif 2923 2924 switch (sa->sa_family) { 2925#ifdef INET 2926 case AF_INET: 2927 break; 2928#endif 2929#ifdef INET6 2930 case AF_INET6: 2931 break; 2932#endif 2933 default: 2934 return (0); 2935 } 2936 2937 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for "); 2938 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 2939 /* convert to upper bound */ 2940 length += offset; 2941 2942 if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2943 SCTPDBG(SCTP_DEBUG_ASCONF1, 2944 "find_initack_addr: invalid offset?\n"); 2945 return (0); 2946 } 2947 /* go through the addresses in the init-ack */ 2948 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2949 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); 2950 while (ph != NULL) { 2951 ptype = ntohs(ph->param_type); 2952 plen = ntohs(ph->param_length); 2953 switch (ptype) { 2954#ifdef INET6 2955 case SCTP_IPV6_ADDRESS: 2956 if (sa->sa_family == AF_INET6) { 2957 /* get the entire IPv6 address param */ 2958 if (plen != sizeof(struct sctp_ipv6addr_param)) { 2959 break; 2960 } 2961 /* get the entire IPv6 address param */ 2962 a6p = (struct sctp_ipv6addr_param *) 2963 sctp_m_getptr(m, offset, 2964 sizeof(struct sctp_ipv6addr_param), 2965 (uint8_t *)&addr6_store); 2966 if (a6p == NULL) { 2967 return (0); 2968 } 2969 sin6 = (struct sockaddr_in6 *)sa; 2970 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { 2971 /* create a copy and clear scope */ 2972 memcpy(&sin6_tmp, sin6, 2973 sizeof(struct sockaddr_in6)); 2974 sin6 = &sin6_tmp; 2975 in6_clearscope(&sin6->sin6_addr); 2976 } 2977 if (memcmp(&sin6->sin6_addr, a6p->addr, 2978 sizeof(struct in6_addr)) == 0) { 2979 /* found it */ 2980 return (1); 2981 } 2982 } 2983 break; 2984#endif /* INET6 */ 2985#ifdef INET 2986 case SCTP_IPV4_ADDRESS: 2987 if (sa->sa_family == AF_INET) { 2988 if (plen != sizeof(struct sctp_ipv4addr_param)) { 2989 break; 2990 } 2991 /* get the entire IPv4 address param */ 2992 a4p = (struct sctp_ipv4addr_param *) 2993 sctp_m_getptr(m, offset, 2994 sizeof(struct sctp_ipv4addr_param), 2995 (uint8_t *)&addr4_store); 2996 if (a4p == NULL) { 2997 return (0); 2998 } 2999 sin = (struct sockaddr_in *)sa; 3000 if (sin->sin_addr.s_addr == a4p->addr) { 3001 /* found it */ 3002 return (1); 3003 } 3004 } 3005 break; 3006#endif 3007 default: 3008 break; 3009 } 3010 /* get next parameter */ 3011 offset += SCTP_SIZE32(plen); 3012 if (offset + sizeof(struct sctp_paramhdr) > length) { 3013 return (0); 3014 } 3015 ph = (struct sctp_paramhdr *) 3016 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), 3017 (uint8_t *)&tmp_param); 3018 } /* while */ 3019 /* not found! */ 3020 return (0); 3021} 3022 3023/* 3024 * makes sure that the current endpoint local addr list is consistent with 3025 * the new association (eg. subset bound, asconf allowed) adds addresses as 3026 * necessary 3027 */ 3028static void 3029sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3030 int length, struct sockaddr *init_addr) 3031{ 3032 struct sctp_laddr *laddr; 3033 3034 /* go through the endpoint list */ 3035 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 3036 /* be paranoid and validate the laddr */ 3037 if (laddr->ifa == NULL) { 3038 SCTPDBG(SCTP_DEBUG_ASCONF1, 3039 "check_addr_list_ep: laddr->ifa is NULL"); 3040 continue; 3041 } 3042 if (laddr->ifa == NULL) { 3043 SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL"); 3044 continue; 3045 } 3046 /* do i have it implicitly? */ 3047 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) { 3048 continue; 3049 } 3050 /* check to see if in the init-ack */ 3051 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) { 3052 /* try to add it */ 3053 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa, 3054 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED); 3055 } 3056 } 3057} 3058 3059/* 3060 * makes sure that the current kernel address list is consistent with the new 3061 * association (with all addrs bound) adds addresses as necessary 3062 */ 3063static void 3064sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3065 int length, struct sockaddr *init_addr, 3066 uint16_t local_scope, uint16_t site_scope, 3067 uint16_t ipv4_scope, uint16_t loopback_scope) 3068{ 3069 struct sctp_vrf *vrf = NULL; 3070 struct sctp_ifn *sctp_ifn; 3071 struct sctp_ifa *sctp_ifa; 3072 uint32_t vrf_id; 3073#ifdef INET 3074 struct sockaddr_in *sin; 3075#endif 3076#ifdef INET6 3077 struct sockaddr_in6 *sin6; 3078#endif 3079 3080 if (stcb) { 3081 vrf_id = stcb->asoc.vrf_id; 3082 } else { 3083 return; 3084 } 3085 SCTP_IPI_ADDR_RLOCK(); 3086 vrf = sctp_find_vrf(vrf_id); 3087 if (vrf == NULL) { 3088 SCTP_IPI_ADDR_RUNLOCK(); 3089 return; 3090 } 3091 /* go through all our known interfaces */ 3092 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { 3093 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { 3094 /* skip loopback interface */ 3095 continue; 3096 } 3097 /* go through each interface address */ 3098 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { 3099 /* do i have it implicitly? */ 3100 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) { 3101 continue; 3102 } 3103 switch (sctp_ifa->address.sa.sa_family) { 3104#ifdef INET 3105 case AF_INET: 3106 sin = &sctp_ifa->address.sin; 3107 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred, 3108 &sin->sin_addr) != 0) { 3109 continue; 3110 } 3111 if ((ipv4_scope == 0) && 3112 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) { 3113 /* private address not in scope */ 3114 continue; 3115 } 3116 break; 3117#endif 3118#ifdef INET6 3119 case AF_INET6: 3120 sin6 = &sctp_ifa->address.sin6; 3121 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred, 3122 &sin6->sin6_addr) != 0) { 3123 continue; 3124 } 3125 if ((local_scope == 0) && 3126 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) { 3127 continue; 3128 } 3129 if ((site_scope == 0) && 3130 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) { 3131 continue; 3132 } 3133 break; 3134#endif 3135 default: 3136 break; 3137 } 3138 /* check to see if in the init-ack */ 3139 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) { 3140 /* try to add it */ 3141 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, 3142 sctp_ifa, SCTP_ADD_IP_ADDRESS, 3143 SCTP_ADDR_LOCKED); 3144 } 3145 } /* end foreach ifa */ 3146 } /* end foreach ifn */ 3147 SCTP_IPI_ADDR_RUNLOCK(); 3148} 3149 3150/* 3151 * validates an init-ack chunk (from a cookie-echo) with current addresses 3152 * adds addresses from the init-ack into our local address list, if needed 3153 * queues asconf adds/deletes addresses as needed and makes appropriate list 3154 * changes for source address selection m, offset: points to the start of the 3155 * address list in an init-ack chunk length: total length of the address 3156 * params only init_addr: address where my INIT-ACK was sent from 3157 */ 3158void 3159sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3160 int length, struct sockaddr *init_addr, 3161 uint16_t local_scope, uint16_t site_scope, 3162 uint16_t ipv4_scope, uint16_t loopback_scope) 3163{ 3164 /* process the local addresses in the initack */ 3165 sctp_process_initack_addresses(stcb, m, offset, length); 3166 3167 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 3168 /* bound all case */ 3169 sctp_check_address_list_all(stcb, m, offset, length, init_addr, 3170 local_scope, site_scope, ipv4_scope, loopback_scope); 3171 } else { 3172 /* subset bound case */ 3173 if (sctp_is_feature_on(stcb->sctp_ep, 3174 SCTP_PCB_FLAGS_DO_ASCONF)) { 3175 /* asconf's allowed */ 3176 sctp_check_address_list_ep(stcb, m, offset, length, 3177 init_addr); 3178 } 3179 /* else, no asconfs allowed, so what we sent is what we get */ 3180 } 3181} 3182 3183/* 3184 * sctp_bindx() support 3185 */ 3186uint32_t 3187sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, 3188 uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap) 3189{ 3190 struct sctp_ifa *ifa; 3191 struct sctp_laddr *laddr, *nladdr; 3192 3193 if (sa->sa_len == 0) { 3194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); 3195 return (EINVAL); 3196 } 3197 if (sctp_ifap) { 3198 ifa = sctp_ifap; 3199 } else if (type == SCTP_ADD_IP_ADDRESS) { 3200 /* For an add the address MUST be on the system */ 3201 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 3202 } else if (type == SCTP_DEL_IP_ADDRESS) { 3203 /* For a delete we need to find it in the inp */ 3204 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED); 3205 } else { 3206 ifa = NULL; 3207 } 3208 if (ifa != NULL) { 3209 if (type == SCTP_ADD_IP_ADDRESS) { 3210 sctp_add_local_addr_ep(inp, ifa, type); 3211 } else if (type == SCTP_DEL_IP_ADDRESS) { 3212 if (inp->laddr_count < 2) { 3213 /* can't delete the last local address */ 3214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); 3215 return (EINVAL); 3216 } 3217 LIST_FOREACH(laddr, &inp->sctp_addr_list, 3218 sctp_nxt_addr) { 3219 if (ifa == laddr->ifa) { 3220 /* Mark in the delete */ 3221 laddr->action = type; 3222 } 3223 } 3224 } 3225 if (LIST_EMPTY(&inp->sctp_asoc_list)) { 3226 /* 3227 * There is no need to start the iterator if the inp 3228 * has no associations. 3229 */ 3230 if (type == SCTP_DEL_IP_ADDRESS) { 3231 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) { 3232 if (laddr->ifa == ifa) { 3233 sctp_del_local_addr_ep(inp, ifa); 3234 } 3235 } 3236 } 3237 } else { 3238 struct sctp_asconf_iterator *asc; 3239 struct sctp_laddr *wi; 3240 int ret; 3241 3242 SCTP_MALLOC(asc, struct sctp_asconf_iterator *, 3243 sizeof(struct sctp_asconf_iterator), 3244 SCTP_M_ASC_IT); 3245 if (asc == NULL) { 3246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); 3247 return (ENOMEM); 3248 } 3249 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr); 3250 if (wi == NULL) { 3251 SCTP_FREE(asc, SCTP_M_ASC_IT); 3252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); 3253 return (ENOMEM); 3254 } 3255 LIST_INIT(&asc->list_of_work); 3256 asc->cnt = 1; 3257 SCTP_INCR_LADDR_COUNT(); 3258 wi->ifa = ifa; 3259 wi->action = type; 3260 atomic_add_int(&ifa->refcount, 1); 3261 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr); 3262 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep, 3263 sctp_asconf_iterator_stcb, 3264 sctp_asconf_iterator_ep_end, 3265 SCTP_PCB_ANY_FLAGS, 3266 SCTP_PCB_ANY_FEATURES, 3267 SCTP_ASOC_ANY_STATE, 3268 (void *)asc, 0, 3269 sctp_asconf_iterator_end, inp, 0); 3270 if (ret) { 3271 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n"); 3272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT); 3273 sctp_asconf_iterator_end(asc, 0); 3274 return (EFAULT); 3275 } 3276 } 3277 return (0); 3278 } else { 3279 /* invalid address! */ 3280 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL); 3281 return (EADDRNOTAVAIL); 3282 } 3283} 3284 3285void 3286sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, 3287 struct sctp_nets *net) 3288{ 3289 struct sctp_asconf_addr *aa; 3290 struct sctp_ifa *sctp_ifap; 3291 struct sctp_asconf_tag_param *vtag; 3292#ifdef INET 3293 struct sockaddr_in *to; 3294#endif 3295#ifdef INET6 3296 struct sockaddr_in6 *to6; 3297#endif 3298 if (net == NULL) { 3299 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n"); 3300 return; 3301 } 3302 if (stcb == NULL) { 3303 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n"); 3304 return; 3305 } 3306 /* 3307 * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) - 3308 * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr) 3309 */ 3310 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3311 SCTP_M_ASC_ADDR); 3312 if (aa == NULL) { 3313 /* didn't get memory */ 3314 SCTPDBG(SCTP_DEBUG_ASCONF1, 3315 "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3316 return; 3317 } 3318 aa->special_del = 0; 3319 /* fill in asconf address parameter fields */ 3320 /* top level elements are "networked" during send */ 3321 aa->ifa = NULL; 3322 aa->sent = 0; /* clear sent flag */ 3323 vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph; 3324 vtag->aph.ph.param_type = SCTP_NAT_VTAGS; 3325 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param); 3326 vtag->local_vtag = htonl(stcb->asoc.my_vtag); 3327 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag); 3328 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3329 3330 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3331 SCTP_M_ASC_ADDR); 3332 if (aa == NULL) { 3333 /* didn't get memory */ 3334 SCTPDBG(SCTP_DEBUG_ASCONF1, 3335 "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3336 return; 3337 } 3338 memset(aa, 0, sizeof(struct sctp_asconf_addr)); 3339 /* fill in asconf address parameter fields */ 3340 /* ADD(0.0.0.0) */ 3341 switch (net->ro._l_addr.sa.sa_family) { 3342#ifdef INET 3343 case AF_INET: 3344 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3345 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); 3346 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 3347 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); 3348 /* No need to add an address, we are using 0.0.0.0 */ 3349 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3350 break; 3351#endif 3352#ifdef INET6 3353 case AF_INET6: 3354 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3355 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); 3356 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 3357 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); 3358 /* No need to add an address, we are using 0.0.0.0 */ 3359 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3360 break; 3361#endif 3362 default: 3363 SCTPDBG(SCTP_DEBUG_ASCONF1, 3364 "sctp_asconf_send_nat_state_update: unknown address family\n"); 3365 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 3366 return; 3367 } 3368 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3369 SCTP_M_ASC_ADDR); 3370 if (aa == NULL) { 3371 /* didn't get memory */ 3372 SCTPDBG(SCTP_DEBUG_ASCONF1, 3373 "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3374 return; 3375 } 3376 memset(aa, 0, sizeof(struct sctp_asconf_addr)); 3377 /* fill in asconf address parameter fields */ 3378 /* ADD(0.0.0.0) */ 3379 switch (net->ro._l_addr.sa.sa_family) { 3380#ifdef INET 3381 case AF_INET: 3382 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3383 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); 3384 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 3385 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); 3386 /* No need to add an address, we are using 0.0.0.0 */ 3387 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3388 break; 3389#endif 3390#ifdef INET6 3391 case AF_INET6: 3392 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; 3393 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); 3394 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 3395 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); 3396 /* No need to add an address, we are using 0.0.0.0 */ 3397 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3398 break; 3399#endif 3400 default: 3401 SCTPDBG(SCTP_DEBUG_ASCONF1, 3402 "sctp_asconf_send_nat_state_update: unknown address family\n"); 3403 SCTP_FREE(aa, SCTP_M_ASC_ADDR); 3404 return; 3405 } 3406 /* Now we must hunt the addresses and add all global addresses */ 3407 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 3408 struct sctp_vrf *vrf = NULL; 3409 struct sctp_ifn *sctp_ifnp; 3410 uint32_t vrf_id; 3411 3412 vrf_id = stcb->sctp_ep->def_vrf_id; 3413 vrf = sctp_find_vrf(vrf_id); 3414 if (vrf == NULL) { 3415 goto skip_rest; 3416 } 3417 3418 SCTP_IPI_ADDR_RLOCK(); 3419 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { 3420 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { 3421 switch (sctp_ifap->address.sa.sa_family) { 3422#ifdef INET 3423 case AF_INET: 3424 to = &sctp_ifap->address.sin; 3425 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred, 3426 &to->sin_addr) != 0) { 3427 continue; 3428 } 3429 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { 3430 continue; 3431 } 3432 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { 3433 continue; 3434 } 3435 break; 3436#endif 3437#ifdef INET6 3438 case AF_INET6: 3439 to6 = &sctp_ifap->address.sin6; 3440 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred, 3441 &to6->sin6_addr) != 0) { 3442 continue; 3443 } 3444 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { 3445 continue; 3446 } 3447 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { 3448 continue; 3449 } 3450 break; 3451#endif 3452 default: 3453 continue; 3454 } 3455 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); 3456 } 3457 } 3458 SCTP_IPI_ADDR_RUNLOCK(); 3459 } else { 3460 struct sctp_laddr *laddr; 3461 3462 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 3463 if (laddr->ifa == NULL) { 3464 continue; 3465 } 3466 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) 3467 /* 3468 * Address being deleted by the system, dont 3469 * list. 3470 */ 3471 continue; 3472 if (laddr->action == SCTP_DEL_IP_ADDRESS) { 3473 /* 3474 * Address being deleted on this ep don't 3475 * list. 3476 */ 3477 continue; 3478 } 3479 sctp_ifap = laddr->ifa; 3480 switch (sctp_ifap->address.sa.sa_family) { 3481#ifdef INET 3482 case AF_INET: 3483 to = &sctp_ifap->address.sin; 3484 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { 3485 continue; 3486 } 3487 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { 3488 continue; 3489 } 3490 break; 3491#endif 3492#ifdef INET6 3493 case AF_INET6: 3494 to6 = &sctp_ifap->address.sin6; 3495 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { 3496 continue; 3497 } 3498 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { 3499 continue; 3500 } 3501 break; 3502#endif 3503 default: 3504 continue; 3505 } 3506 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); 3507 } 3508 } 3509skip_rest: 3510 /* Now we must send the asconf into the queue */ 3511 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); 3512} 3513