Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCTP] sctp_connectx() API support

Implements sctp_connectx() as defined in the SCTP sockets API draft by
tunneling the request through a setsockopt().

Signed-off-by: Frank Filz <ffilzlnx@us.ibm.com>
Signed-off-by: Sridhar Samudrala <sri@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Frank Filz and committed by
David S. Miller
3f7a87d2 8b22c249

+677 -260
+4 -4
include/net/sctp/command.h
··· 65 65 SCTP_CMD_TIMER_START, /* Start a timer. */ 66 66 SCTP_CMD_TIMER_RESTART, /* Restart a timer. */ 67 67 SCTP_CMD_TIMER_STOP, /* Stop a timer. */ 68 - SCTP_CMD_COUNTER_RESET, /* Reset a counter. */ 69 - SCTP_CMD_COUNTER_INC, /* Increment a counter. */ 68 + SCTP_CMD_INIT_CHOOSE_TRANSPORT, /* Choose transport for an INIT. */ 69 + SCTP_CMD_INIT_COUNTER_RESET, /* Reset init counter. */ 70 + SCTP_CMD_INIT_COUNTER_INC, /* Increment init counter. */ 70 71 SCTP_CMD_INIT_RESTART, /* High level, do init timer work. */ 72 + SCTP_CMD_COOKIEECHO_RESTART, /* High level, do cookie-echo timer work. */ 71 73 SCTP_CMD_INIT_FAILED, /* High level, do init failure work. */ 72 74 SCTP_CMD_REPORT_DUP, /* Report a duplicate TSN. */ 73 75 SCTP_CMD_STRIKE, /* Mark a strike against a transport. */ ··· 120 118 int error; 121 119 sctp_state_t state; 122 120 sctp_event_timeout_t to; 123 - sctp_counter_t counter; 124 121 void *ptr; 125 122 struct sctp_chunk *chunk; 126 123 struct sctp_association *asoc; ··· 166 165 SCTP_ARG_CONSTRUCTOR(U8, __u8, u8) 167 166 SCTP_ARG_CONSTRUCTOR(ERROR, int, error) 168 167 SCTP_ARG_CONSTRUCTOR(STATE, sctp_state_t, state) 169 - SCTP_ARG_CONSTRUCTOR(COUNTER, sctp_counter_t, counter) 170 168 SCTP_ARG_CONSTRUCTOR(TO, sctp_event_timeout_t, to) 171 169 SCTP_ARG_CONSTRUCTOR(PTR, void *, ptr) 172 170 SCTP_ARG_CONSTRUCTOR(CHUNK, struct sctp_chunk *, chunk)
-7
include/net/sctp/constants.h
··· 263 263 enum { SCTP_MAX_DUP_TSNS = 16 }; 264 264 enum { SCTP_MAX_GABS = 16 }; 265 265 266 - typedef enum { 267 - SCTP_COUNTER_INIT_ERROR, 268 - } sctp_counter_t; 269 - 270 - /* How many counters does an association need? */ 271 - #define SCTP_NUMBER_COUNTERS 5 272 - 273 266 /* Here we define the default timers. */ 274 267 275 268 /* cookie timer def = ? seconds */
+17
include/net/sctp/sctp.h
··· 223 223 extern int sctp_debug_flag; 224 224 #define SCTP_DEBUG_PRINTK(whatever...) \ 225 225 ((void) (sctp_debug_flag && printk(KERN_DEBUG whatever))) 226 + #define SCTP_DEBUG_PRINTK_IPADDR(lead, trail, leadparm, saddr, otherparms...) \ 227 + if (sctp_debug_flag) { \ 228 + if (saddr->sa.sa_family == AF_INET6) { \ 229 + printk(KERN_DEBUG \ 230 + lead "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x" trail, \ 231 + leadparm, \ 232 + NIP6(saddr->v6.sin6_addr), \ 233 + otherparms); \ 234 + } else { \ 235 + printk(KERN_DEBUG \ 236 + lead "%u.%u.%u.%u" trail, \ 237 + leadparm, \ 238 + NIPQUAD(saddr->v4.sin_addr.s_addr), \ 239 + otherparms); \ 240 + } \ 241 + } 226 242 #define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; } 227 243 #define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; } 228 244 ··· 252 236 #else /* SCTP_DEBUG */ 253 237 254 238 #define SCTP_DEBUG_PRINTK(whatever...) 239 + #define SCTP_DEBUG_PRINTK_IPADDR(whatever...) 255 240 #define SCTP_ENABLE_DEBUG 256 241 #define SCTP_DISABLE_DEBUG 257 242 #define SCTP_ASSERT(expr, str, func)
+6 -2
include/net/sctp/sm.h
··· 116 116 sctp_state_fn_t sctp_sf_eat_sack_6_2; 117 117 sctp_state_fn_t sctp_sf_tabort_8_4_8; 118 118 sctp_state_fn_t sctp_sf_operr_notify; 119 - sctp_state_fn_t sctp_sf_t1_timer_expire; 119 + sctp_state_fn_t sctp_sf_t1_init_timer_expire; 120 + sctp_state_fn_t sctp_sf_t1_cookie_timer_expire; 120 121 sctp_state_fn_t sctp_sf_t2_timer_expire; 121 122 sctp_state_fn_t sctp_sf_t4_timer_expire; 122 123 sctp_state_fn_t sctp_sf_t5_timer_expire; ··· 259 258 void sctp_chunk_assign_tsn(struct sctp_chunk *); 260 259 void sctp_chunk_assign_ssn(struct sctp_chunk *); 261 260 262 - void sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, __u16 error); 261 + sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, 262 + __u16 error, 263 + const struct sctp_association *asoc, 264 + struct sctp_transport *transport); 263 265 264 266 /* Prototypes for statetable processing. */ 265 267
+32 -9
include/net/sctp/structs.h
··· 867 867 */ 868 868 unsigned long last_time_ecne_reduced; 869 869 870 - /* active : The current active state of this destination, 871 - * : i.e. DOWN, UP, etc. 870 + /* The number of times INIT has been sent on this transport. */ 871 + int init_sent_count; 872 + 873 + /* state : The current state of this destination, 874 + * : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKOWN. 872 875 */ 873 - int active; 876 + int state; 874 877 875 878 /* hb_allowed : The current heartbeat state of this destination, 876 879 * : i.e. ALLOW-HB, NO-HEARTBEAT, etc. ··· 1225 1222 1226 1223 /* sendbuf acct. policy. */ 1227 1224 __u32 sndbuf_policy; 1228 - 1229 - /* Name for debugging output... */ 1230 - char *debug_name; 1231 1225 }; 1232 1226 1233 1227 /* Recover the outter endpoint structure. */ ··· 1314 1314 * : association. Normally this information is 1315 1315 * : hashed or keyed for quick lookup and access 1316 1316 * : of the TCB. 1317 + * : The list is also initialized with the list 1318 + * : of addresses passed with the sctp_connectx() 1319 + * : call. 1317 1320 * 1318 1321 * It is a list of SCTP_transport's. 1319 1322 */ 1320 1323 struct list_head transport_addr_list; 1324 + 1325 + /* transport_count 1326 + * 1327 + * Peer : A count of the number of peer addresses 1328 + * Transport : in the Peer Transport Address List. 1329 + * Address : 1330 + * Count : 1331 + */ 1332 + __u16 transport_count; 1321 1333 1322 1334 /* port 1323 1335 * The transport layer port number. ··· 1498 1486 /* Transport to which SHUTDOWN chunk was last sent. */ 1499 1487 struct sctp_transport *shutdown_last_sent_to; 1500 1488 1489 + /* Transport to which INIT chunk was last sent. */ 1490 + struct sctp_transport *init_last_sent_to; 1491 + 1501 1492 /* Next TSN : The next TSN number to be assigned to a new 1502 1493 * : DATA chunk. This is sent in the INIT or INIT 1503 1494 * : ACK chunk to the peer and incremented each ··· 1564 1549 /* The message size at which SCTP fragmentation will occur. */ 1565 1550 __u32 frag_point; 1566 1551 1567 - /* Currently only one counter is used to count INIT errors. */ 1568 - int counters[SCTP_NUMBER_COUNTERS]; 1552 + /* Counter used to count INIT errors. */ 1553 + int init_err_counter; 1554 + 1555 + /* Count the number of INIT cycles (for doubling timeout). */ 1556 + int init_cycle; 1569 1557 1570 1558 /* Default send parameters. */ 1571 1559 __u16 default_stream; ··· 1726 1708 void sctp_association_put(struct sctp_association *); 1727 1709 void sctp_association_hold(struct sctp_association *); 1728 1710 1711 + struct sctp_transport *sctp_assoc_choose_init_transport( 1712 + struct sctp_association *); 1729 1713 struct sctp_transport *sctp_assoc_choose_shutdown_transport( 1730 1714 struct sctp_association *); 1731 1715 void sctp_assoc_update_retran_path(struct sctp_association *); ··· 1737 1717 const union sctp_addr *laddr); 1738 1718 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *, 1739 1719 const union sctp_addr *address, 1740 - const int gfp); 1720 + const int gfp, 1721 + const int peer_state); 1741 1722 void sctp_assoc_del_peer(struct sctp_association *asoc, 1742 1723 const union sctp_addr *addr); 1724 + void sctp_assoc_rm_peer(struct sctp_association *asoc, 1725 + struct sctp_transport *peer); 1743 1726 void sctp_assoc_control_transport(struct sctp_association *, 1744 1727 struct sctp_transport *, 1745 1728 sctp_transport_cmd_t, sctp_sn_error_t);
+3
include/net/sctp/user.h
··· 111 111 #define SCTP_GET_LOCAL_ADDRS_NUM SCTP_GET_LOCAL_ADDRS_NUM 112 112 SCTP_GET_LOCAL_ADDRS, /* Get all local addresss. */ 113 113 #define SCTP_GET_LOCAL_ADDRS SCTP_GET_LOCAL_ADDRS 114 + SCTP_SOCKOPT_CONNECTX, /* CONNECTX requests. */ 115 + #define SCTP_SOCKOPT_CONNECTX SCTP_SOCKOPT_CONNECTX 114 116 }; 115 117 116 118 /* ··· 529 527 enum sctp_spinfo_state { 530 528 SCTP_INACTIVE, 531 529 SCTP_ACTIVE, 530 + SCTP_UNKNOWN = 0xffff /* Value used for transport state unknown */ 532 531 }; 533 532 534 533 /*
+114 -37
net/sctp/associola.c
··· 191 191 asoc->last_cwr_tsn = asoc->ctsn_ack_point; 192 192 asoc->unack_data = 0; 193 193 194 - SCTP_DEBUG_PRINTK("myctsnap for %s INIT as 0x%x.\n", 195 - asoc->ep->debug_name, 196 - asoc->ctsn_ack_point); 197 - 198 194 /* ADDIP Section 4.1 Asconf Chunk Procedures 199 195 * 200 196 * When an endpoint has an ASCONF signaled change to be sent to the ··· 207 211 208 212 /* Make an empty list of remote transport addresses. */ 209 213 INIT_LIST_HEAD(&asoc->peer.transport_addr_list); 214 + asoc->peer.transport_count = 0; 210 215 211 216 /* RFC 2960 5.1 Normal Establishment of an Association 212 217 * ··· 285 288 286 289 asoc->base.malloced = 1; 287 290 SCTP_DBG_OBJCNT_INC(assoc); 291 + SCTP_DEBUG_PRINTK("Created asoc %p\n", asoc); 288 292 289 293 return asoc; 290 294 ··· 354 356 sctp_transport_free(transport); 355 357 } 356 358 359 + asoc->peer.transport_count = 0; 360 + 357 361 /* Free any cached ASCONF_ACK chunk. */ 358 362 if (asoc->addip_last_asconf_ack) 359 363 sctp_chunk_free(asoc->addip_last_asconf_ack); ··· 400 400 /* If the primary path is changing, assume that the 401 401 * user wants to use this new path. 402 402 */ 403 - if (transport->active) 403 + if (transport->state != SCTP_INACTIVE) 404 404 asoc->peer.active_path = transport; 405 405 406 406 /* ··· 428 428 transport->cacc.next_tsn_at_change = asoc->next_tsn; 429 429 } 430 430 431 + /* Remove a transport from an association. */ 432 + void sctp_assoc_rm_peer(struct sctp_association *asoc, 433 + struct sctp_transport *peer) 434 + { 435 + struct list_head *pos; 436 + struct sctp_transport *transport; 437 + 438 + SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_rm_peer:association %p addr: ", 439 + " port: %d\n", 440 + asoc, 441 + (&peer->ipaddr), 442 + peer->ipaddr.v4.sin_port); 443 + 444 + /* If we are to remove the current retran_path, update it 445 + * to the next peer before removing this peer from the list. 446 + */ 447 + if (asoc->peer.retran_path == peer) 448 + sctp_assoc_update_retran_path(asoc); 449 + 450 + /* Remove this peer from the list. */ 451 + list_del(&peer->transports); 452 + 453 + /* Get the first transport of asoc. */ 454 + pos = asoc->peer.transport_addr_list.next; 455 + transport = list_entry(pos, struct sctp_transport, transports); 456 + 457 + /* Update any entries that match the peer to be deleted. */ 458 + if (asoc->peer.primary_path == peer) 459 + sctp_assoc_set_primary(asoc, transport); 460 + if (asoc->peer.active_path == peer) 461 + asoc->peer.active_path = transport; 462 + if (asoc->peer.last_data_from == peer) 463 + asoc->peer.last_data_from = transport; 464 + 465 + /* If we remove the transport an INIT was last sent to, set it to 466 + * NULL. Combined with the update of the retran path above, this 467 + * will cause the next INIT to be sent to the next available 468 + * transport, maintaining the cycle. 469 + */ 470 + if (asoc->init_last_sent_to == peer) 471 + asoc->init_last_sent_to = NULL; 472 + 473 + asoc->peer.transport_count--; 474 + 475 + sctp_transport_free(peer); 476 + } 477 + 431 478 /* Add a transport address to an association. */ 432 479 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, 433 480 const union sctp_addr *addr, 434 - int gfp) 481 + const int gfp, 482 + const int peer_state) 435 483 { 436 484 struct sctp_transport *peer; 437 485 struct sctp_sock *sp; ··· 490 442 /* AF_INET and AF_INET6 share common port field. */ 491 443 port = addr->v4.sin_port; 492 444 445 + SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_add_peer:association %p addr: ", 446 + " port: %d state:%s\n", 447 + asoc, 448 + addr, 449 + addr->v4.sin_port, 450 + peer_state == SCTP_UNKNOWN?"UNKNOWN":"ACTIVE"); 451 + 493 452 /* Set the port if it has not been set yet. */ 494 453 if (0 == asoc->peer.port) 495 454 asoc->peer.port = port; 496 455 497 456 /* Check to see if this is a duplicate. */ 498 457 peer = sctp_assoc_lookup_paddr(asoc, addr); 499 - if (peer) 458 + if (peer) { 459 + if (peer_state == SCTP_ACTIVE && 460 + peer->state == SCTP_UNKNOWN) 461 + peer->state = SCTP_ACTIVE; 500 462 return peer; 463 + } 501 464 502 465 peer = sctp_transport_new(addr, gfp); 503 466 if (!peer) ··· 575 516 /* Set the transport's RTO.initial value */ 576 517 peer->rto = asoc->rto_initial; 577 518 519 + /* Set the peer's active state. */ 520 + peer->state = peer_state; 521 + 578 522 /* Attach the remote transport to our asoc. */ 579 523 list_add_tail(&peer->transports, &asoc->peer.transport_addr_list); 524 + asoc->peer.transport_count++; 580 525 581 526 /* If we do not yet have a primary path, set one. */ 582 527 if (!asoc->peer.primary_path) { ··· 588 525 asoc->peer.retran_path = peer; 589 526 } 590 527 591 - if (asoc->peer.active_path == asoc->peer.retran_path) 528 + if (asoc->peer.active_path == asoc->peer.retran_path) { 592 529 asoc->peer.retran_path = peer; 530 + } 593 531 594 532 return peer; 595 533 } ··· 601 537 { 602 538 struct list_head *pos; 603 539 struct list_head *temp; 604 - struct sctp_transport *peer = NULL; 605 540 struct sctp_transport *transport; 606 541 607 542 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { 608 543 transport = list_entry(pos, struct sctp_transport, transports); 609 544 if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) { 610 - peer = transport; 611 - list_del(pos); 545 + /* Do book keeping for removing the peer and free it. */ 546 + sctp_assoc_rm_peer(asoc, transport); 612 547 break; 613 548 } 614 549 } 615 - 616 - /* The address we want delete is not in the association. */ 617 - if (!peer) 618 - return; 619 - 620 - /* Get the first transport of asoc. */ 621 - pos = asoc->peer.transport_addr_list.next; 622 - transport = list_entry(pos, struct sctp_transport, transports); 623 - 624 - /* Update any entries that match the peer to be deleted. */ 625 - if (asoc->peer.primary_path == peer) 626 - sctp_assoc_set_primary(asoc, transport); 627 - if (asoc->peer.active_path == peer) 628 - asoc->peer.active_path = transport; 629 - if (asoc->peer.retran_path == peer) 630 - asoc->peer.retran_path = transport; 631 - if (asoc->peer.last_data_from == peer) 632 - asoc->peer.last_data_from = transport; 633 - 634 - sctp_transport_free(peer); 635 550 } 636 551 637 552 /* Lookup a transport by address. */ ··· 651 608 /* Record the transition on the transport. */ 652 609 switch (command) { 653 610 case SCTP_TRANSPORT_UP: 654 - transport->active = SCTP_ACTIVE; 611 + transport->state = SCTP_ACTIVE; 655 612 spc_state = SCTP_ADDR_AVAILABLE; 656 613 break; 657 614 658 615 case SCTP_TRANSPORT_DOWN: 659 - transport->active = SCTP_INACTIVE; 616 + transport->state = SCTP_INACTIVE; 660 617 spc_state = SCTP_ADDR_UNREACHABLE; 661 618 break; 662 619 ··· 686 643 list_for_each(pos, &asoc->peer.transport_addr_list) { 687 644 t = list_entry(pos, struct sctp_transport, transports); 688 645 689 - if (!t->active) 646 + if (t->state == SCTP_INACTIVE) 690 647 continue; 691 648 if (!first || t->last_time_heard > first->last_time_heard) { 692 649 second = first; ··· 706 663 * [If the primary is active but not most recent, bump the most 707 664 * recently used transport.] 708 665 */ 709 - if (asoc->peer.primary_path->active && 666 + if (asoc->peer.primary_path->state != SCTP_INACTIVE && 710 667 first != asoc->peer.primary_path) { 711 668 second = first; 712 669 first = asoc->peer.primary_path; ··· 1001 958 transports); 1002 959 if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr)) 1003 960 sctp_assoc_add_peer(asoc, &trans->ipaddr, 1004 - GFP_ATOMIC); 961 + GFP_ATOMIC, SCTP_ACTIVE); 1005 962 } 1006 963 1007 964 asoc->ctsn_ack_point = asoc->next_tsn - 1; ··· 1041 998 1042 999 /* Try to find an active transport. */ 1043 1000 1044 - if (t->active) { 1001 + if (t->state != SCTP_INACTIVE) { 1045 1002 break; 1046 1003 } else { 1047 1004 /* Keep track of the next transport in case ··· 1062 1019 } 1063 1020 1064 1021 asoc->peer.retran_path = t; 1022 + 1023 + SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association" 1024 + " %p addr: ", 1025 + " port: %d\n", 1026 + asoc, 1027 + (&t->ipaddr), 1028 + t->ipaddr.v4.sin_port); 1029 + } 1030 + 1031 + /* Choose the transport for sending a INIT packet. */ 1032 + struct sctp_transport *sctp_assoc_choose_init_transport( 1033 + struct sctp_association *asoc) 1034 + { 1035 + struct sctp_transport *t; 1036 + 1037 + /* Use the retran path. If the last INIT was sent over the 1038 + * retran path, update the retran path and use it. 1039 + */ 1040 + if (!asoc->init_last_sent_to) { 1041 + t = asoc->peer.active_path; 1042 + } else { 1043 + if (asoc->init_last_sent_to == asoc->peer.retran_path) 1044 + sctp_assoc_update_retran_path(asoc); 1045 + t = asoc->peer.retran_path; 1046 + } 1047 + 1048 + SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association" 1049 + " %p addr: ", 1050 + " port: %d\n", 1051 + asoc, 1052 + (&t->ipaddr), 1053 + t->ipaddr.v4.sin_port); 1054 + 1055 + return t; 1065 1056 } 1066 1057 1067 1058 /* Choose the transport for sending a SHUTDOWN packet. */
-1
net/sctp/endpointola.c
··· 134 134 ep->last_key = ep->current_key = 0; 135 135 ep->key_changed_at = jiffies; 136 136 137 - ep->debug_name = "unnamedEndpoint"; 138 137 return ep; 139 138 } 140 139
+1 -1
net/sctp/input.c
··· 353 353 354 354 sctp_do_sm(SCTP_EVENT_T_OTHER, 355 355 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH), 356 - asoc->state, asoc->ep, asoc, NULL, 356 + asoc->state, asoc->ep, asoc, t, 357 357 GFP_ATOMIC); 358 358 359 359 }
+6 -5
net/sctp/outqueue.c
··· 682 682 683 683 if (!new_transport) { 684 684 new_transport = asoc->peer.active_path; 685 - } else if (!new_transport->active) { 686 - /* If the chunk is Heartbeat or Heartbeat Ack, 687 - * send it to chunk->transport, even if it's 685 + } else if (new_transport->state == SCTP_INACTIVE) { 686 + /* If the chunk is Heartbeat or Heartbeat Ack, 687 + * send it to chunk->transport, even if it's 688 688 * inactive. 689 689 * 690 690 * 3.3.6 Heartbeat Acknowledgement: ··· 840 840 * Otherwise, we want to use the active path. 841 841 */ 842 842 new_transport = chunk->transport; 843 - if (!new_transport || !new_transport->active) 843 + if (!new_transport || 844 + new_transport->state == SCTP_INACTIVE) 844 845 new_transport = asoc->peer.active_path; 845 846 846 847 /* Change packets if necessary. */ ··· 1455 1454 /* Mark the destination transport address as 1456 1455 * active if it is not so marked. 1457 1456 */ 1458 - if (!transport->active) { 1457 + if (transport->state == SCTP_INACTIVE) { 1459 1458 sctp_assoc_control_transport( 1460 1459 transport->asoc, 1461 1460 transport,
+16 -4
net/sctp/sm_make_chunk.c
··· 1830 1830 * be a a better choice than any of the embedded addresses. 1831 1831 */ 1832 1832 if (peer_addr) 1833 - if(!sctp_assoc_add_peer(asoc, peer_addr, gfp)) 1833 + if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE)) 1834 1834 goto nomem; 1835 1835 1836 1836 /* Process the initialization parameters. */ ··· 1839 1839 1840 1840 if (!sctp_process_param(asoc, param, peer_addr, gfp)) 1841 1841 goto clean_up; 1842 + } 1843 + 1844 + /* Walk list of transports, removing transports in the UNKNOWN state. */ 1845 + list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { 1846 + transport = list_entry(pos, struct sctp_transport, transports); 1847 + if (transport->state == SCTP_UNKNOWN) { 1848 + sctp_assoc_rm_peer(asoc, transport); 1849 + } 1842 1850 } 1843 1851 1844 1852 /* The fixed INIT headers are always in network byte ··· 1914 1906 * stream sequence number shall be set to 0. 1915 1907 */ 1916 1908 1917 - /* Allocate storage for the negotiated streams if it is not a temporary * association. 1909 + /* Allocate storage for the negotiated streams if it is not a temporary 1910 + * association. 1918 1911 */ 1919 1912 if (!asoc->temp) { 1920 1913 int assoc_id; ··· 1961 1952 list_del_init(pos); 1962 1953 sctp_transport_free(transport); 1963 1954 } 1955 + 1956 + asoc->peer.transport_count = 0; 1957 + 1964 1958 nomem: 1965 1959 return 0; 1966 1960 } ··· 2007 1995 af->from_addr_param(&addr, param.addr, asoc->peer.port, 0); 2008 1996 scope = sctp_scope(peer_addr); 2009 1997 if (sctp_in_scope(&addr, scope)) 2010 - if (!sctp_assoc_add_peer(asoc, &addr, gfp)) 1998 + if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_ACTIVE)) 2011 1999 return 0; 2012 2000 break; 2013 2001 ··· 2408 2396 * Due to Resource Shortage'. 2409 2397 */ 2410 2398 2411 - peer = sctp_assoc_add_peer(asoc, &addr, GFP_ATOMIC); 2399 + peer = sctp_assoc_add_peer(asoc, &addr, GFP_ATOMIC, SCTP_ACTIVE); 2412 2400 if (!peer) 2413 2401 return SCTP_ERROR_RSRC_LOW; 2414 2402
+85 -20
net/sctp/sm_sideeffect.c
··· 414 414 */ 415 415 asoc->overall_error_count++; 416 416 417 - if (transport->active && 417 + if (transport->state != SCTP_INACTIVE && 418 418 (transport->error_count++ >= transport->max_retrans)) { 419 - SCTP_DEBUG_PRINTK("transport_strike: transport " 420 - "IP:%d.%d.%d.%d failed.\n", 421 - NIPQUAD(transport->ipaddr.v4.sin_addr)); 419 + SCTP_DEBUG_PRINTK_IPADDR("transport_strike:association %p", 420 + " transport IP: port:%d failed.\n", 421 + asoc, 422 + (&transport->ipaddr), 423 + transport->ipaddr.v4.sin_port); 422 424 sctp_assoc_control_transport(asoc, transport, 423 425 SCTP_TRANSPORT_DOWN, 424 426 SCTP_FAILED_THRESHOLD); ··· 595 593 /* Mark the destination transport address as active if it is not so 596 594 * marked. 597 595 */ 598 - if (!t->active) 596 + if (t->state == SCTP_INACTIVE) 599 597 sctp_assoc_control_transport(asoc, t, SCTP_TRANSPORT_UP, 600 598 SCTP_HEARTBEAT_SUCCESS); 601 599 ··· 667 665 668 666 asoc->state = state; 669 667 668 + SCTP_DEBUG_PRINTK("sctp_cmd_new_state: asoc %p[%s]\n", 669 + asoc, sctp_state_tbl[state]); 670 + 670 671 if (sctp_style(sk, TCP)) { 671 - /* Change the sk->sk_state of a TCP-style socket that has 672 + /* Change the sk->sk_state of a TCP-style socket that has 672 673 * sucessfully completed a connect() call. 673 674 */ 674 675 if (sctp_state(asoc, ESTABLISHED) && sctp_sstate(sk, CLOSED)) ··· 681 676 if (sctp_state(asoc, SHUTDOWN_RECEIVED) && 682 677 sctp_sstate(sk, ESTABLISHED)) 683 678 sk->sk_shutdown |= RCV_SHUTDOWN; 679 + } 680 + 681 + if (sctp_state(asoc, COOKIE_WAIT)) { 682 + /* Reset init timeouts since they may have been 683 + * increased due to timer expirations. 684 + */ 685 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = 686 + asoc->ep->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT]; 687 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = 688 + asoc->ep->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE]; 684 689 } 685 690 686 691 if (sctp_state(asoc, ESTABLISHED) || ··· 1135 1120 * to be executed only during failed attempts of 1136 1121 * association establishment. 1137 1122 */ 1138 - if ((asoc->peer.retran_path != 1139 - asoc->peer.primary_path) && 1140 - (asoc->counters[SCTP_COUNTER_INIT_ERROR] > 0)) { 1141 - sctp_add_cmd_sf(commands, 1123 + if ((asoc->peer.retran_path != 1124 + asoc->peer.primary_path) && 1125 + (asoc->init_err_counter > 0)) { 1126 + sctp_add_cmd_sf(commands, 1142 1127 SCTP_CMD_FORCE_PRIM_RETRAN, 1143 1128 SCTP_NULL()); 1144 1129 } ··· 1252 1237 sctp_association_put(asoc); 1253 1238 break; 1254 1239 1240 + case SCTP_CMD_INIT_CHOOSE_TRANSPORT: 1241 + chunk = cmd->obj.ptr; 1242 + t = sctp_assoc_choose_init_transport(asoc); 1243 + asoc->init_last_sent_to = t; 1244 + chunk->transport = t; 1245 + t->init_sent_count++; 1246 + break; 1247 + 1255 1248 case SCTP_CMD_INIT_RESTART: 1256 1249 /* Do the needed accounting and updates 1257 1250 * associated with restarting an initialization 1258 - * timer. 1251 + * timer. Only multiply the timeout by two if 1252 + * all transports have been tried at the current 1253 + * timeout. 1259 1254 */ 1260 - asoc->counters[SCTP_COUNTER_INIT_ERROR]++; 1261 - asoc->timeouts[cmd->obj.to] *= 2; 1262 - if (asoc->timeouts[cmd->obj.to] > 1255 + t = asoc->init_last_sent_to; 1256 + asoc->init_err_counter++; 1257 + 1258 + if (t->init_sent_count > (asoc->init_cycle + 1)) { 1259 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] *= 2; 1260 + if (asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] > 1261 + asoc->max_init_timeo) { 1262 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = 1263 + asoc->max_init_timeo; 1264 + } 1265 + asoc->init_cycle++; 1266 + SCTP_DEBUG_PRINTK( 1267 + "T1 INIT Timeout adjustment" 1268 + " init_err_counter: %d" 1269 + " cycle: %d" 1270 + " timeout: %d\n", 1271 + asoc->init_err_counter, 1272 + asoc->init_cycle, 1273 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT]); 1274 + } 1275 + 1276 + sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 1277 + SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 1278 + break; 1279 + 1280 + case SCTP_CMD_COOKIEECHO_RESTART: 1281 + /* Do the needed accounting and updates 1282 + * associated with restarting an initialization 1283 + * timer. Only multiply the timeout by two if 1284 + * all transports have been tried at the current 1285 + * timeout. 1286 + */ 1287 + asoc->init_err_counter++; 1288 + 1289 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] *= 2; 1290 + if (asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] > 1263 1291 asoc->max_init_timeo) { 1264 - asoc->timeouts[cmd->obj.to] = 1292 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = 1265 1293 asoc->max_init_timeo; 1266 1294 } 1295 + SCTP_DEBUG_PRINTK( 1296 + "T1 COOKIE Timeout adjustment" 1297 + " init_err_counter: %d" 1298 + " timeout: %d\n", 1299 + asoc->init_err_counter, 1300 + asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE]); 1267 1301 1268 1302 /* If we've sent any data bundled with 1269 1303 * COOKIE-ECHO we need to resend. ··· 1325 1261 1326 1262 sctp_add_cmd_sf(commands, 1327 1263 SCTP_CMD_TIMER_RESTART, 1328 - SCTP_TO(cmd->obj.to)); 1264 + SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 1329 1265 break; 1330 1266 1331 1267 case SCTP_CMD_INIT_FAILED: ··· 1337 1273 subtype, chunk, cmd->obj.u32); 1338 1274 break; 1339 1275 1340 - case SCTP_CMD_COUNTER_INC: 1341 - asoc->counters[cmd->obj.counter]++; 1276 + case SCTP_CMD_INIT_COUNTER_INC: 1277 + asoc->init_err_counter++; 1342 1278 break; 1343 1279 1344 - case SCTP_CMD_COUNTER_RESET: 1345 - asoc->counters[cmd->obj.counter] = 0; 1280 + case SCTP_CMD_INIT_COUNTER_RESET: 1281 + asoc->init_err_counter = 0; 1282 + asoc->init_cycle = 0; 1346 1283 break; 1347 1284 1348 1285 case SCTP_CMD_REPORT_DUP:
+98 -50
net/sctp/sm_statefuns.c
··· 533 533 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT, 534 534 SCTP_PEER_INIT(initchunk)); 535 535 536 + /* Reset init error count upon receipt of INIT-ACK. */ 537 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); 538 + 536 539 /* 5.1 C) "A" shall stop the T1-init timer and leave 537 540 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie 538 541 * timer, and enter the COOKIE-ECHOED state. ··· 778 775 * from the COOKIE-ECHOED state to the COOKIE-WAIT 779 776 * state is performed. 780 777 */ 781 - sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET, 782 - SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR)); 778 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); 783 779 784 780 /* RFC 2960 5.1 Normal Establishment of an Association 785 781 * ··· 1021 1019 link = sctp_assoc_lookup_paddr(asoc, &from_addr); 1022 1020 1023 1021 /* This should never happen, but lets log it if so. */ 1024 - if (!link) { 1025 - printk(KERN_WARNING 1026 - "%s: Could not find address %d.%d.%d.%d\n", 1027 - __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr)); 1022 + if (unlikely(!link)) { 1023 + if (from_addr.sa.sa_family == AF_INET6) { 1024 + printk(KERN_WARNING 1025 + "%s association %p could not find address " 1026 + "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", 1027 + __FUNCTION__, 1028 + asoc, 1029 + NIP6(from_addr.v6.sin6_addr)); 1030 + } else { 1031 + printk(KERN_WARNING 1032 + "%s association %p could not find address " 1033 + "%u.%u.%u.%u\n", 1034 + __FUNCTION__, 1035 + asoc, 1036 + NIPQUAD(from_addr.v4.sin_addr.s_addr)); 1037 + } 1028 1038 return SCTP_DISPOSITION_DISCARD; 1029 1039 } 1030 1040 ··· 2109 2095 sctp_errhdr_t *err; 2110 2096 struct sctp_chunk *reply; 2111 2097 struct sctp_bind_addr *bp; 2112 - int attempts; 2113 - 2114 - attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1; 2098 + int attempts = asoc->init_err_counter + 1; 2115 2099 2116 2100 if (attempts >= asoc->max_init_attempts) { 2117 2101 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, ··· 2169 2157 /* Cast away the const modifier, as we want to just 2170 2158 * rerun it through as a sideffect. 2171 2159 */ 2172 - sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC, 2173 - SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR)); 2160 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL()); 2174 2161 2175 2162 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 2176 2163 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); ··· 2292 2281 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) 2293 2282 error = ((sctp_errhdr_t *)chunk->skb->data)->cause; 2294 2283 2295 - sctp_stop_t1_and_abort(commands, error); 2296 - return SCTP_DISPOSITION_ABORT; 2284 + return sctp_stop_t1_and_abort(commands, error, asoc, chunk->transport); 2297 2285 } 2298 2286 2299 2287 /* ··· 2304 2294 void *arg, 2305 2295 sctp_cmd_seq_t *commands) 2306 2296 { 2307 - sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR); 2308 - return SCTP_DISPOSITION_ABORT; 2297 + return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR, asoc, 2298 + (struct sctp_transport *)arg); 2309 2299 } 2310 2300 2311 2301 /* ··· 2328 2318 * 2329 2319 * This is common code called by several sctp_sf_*_abort() functions above. 2330 2320 */ 2331 - void sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, __u16 error) 2321 + sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, 2322 + __u16 error, 2323 + const struct sctp_association *asoc, 2324 + struct sctp_transport *transport) 2332 2325 { 2326 + SCTP_DEBUG_PRINTK("ABORT received (INIT).\n"); 2333 2327 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, 2334 2328 SCTP_STATE(SCTP_STATE_CLOSED)); 2335 2329 SCTP_INC_STATS(SCTP_MIB_ABORTEDS); ··· 2342 2328 /* CMD_INIT_FAILED will DELETE_TCB. */ 2343 2329 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 2344 2330 SCTP_U32(error)); 2331 + return SCTP_DISPOSITION_ABORT; 2345 2332 } 2346 2333 2347 2334 /* ··· 3820 3805 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, 3821 3806 SCTP_ASOC((struct sctp_association *) asoc)); 3822 3807 3808 + /* Choose transport for INIT. */ 3809 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, 3810 + SCTP_CHUNK(repl)); 3811 + 3823 3812 /* After sending the INIT, "A" starts the T1-init timer and 3824 3813 * enters the COOKIE-WAIT state. 3825 3814 */ ··· 4608 4589 } 4609 4590 4610 4591 /* 4611 - * sctp_sf_t1_timer_expire 4592 + * sctp_sf_t1_init_timer_expire 4612 4593 * 4613 4594 * Section: 4 Note: 2 4614 4595 * Verification Tag: ··· 4622 4603 * endpoint MUST abort the initialization process and report the 4623 4604 * error to SCTP user. 4624 4605 * 4625 - * 3) If the T1-cookie timer expires, the endpoint MUST retransmit 4606 + * Outputs 4607 + * (timers, events) 4608 + * 4609 + */ 4610 + sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep, 4611 + const struct sctp_association *asoc, 4612 + const sctp_subtype_t type, 4613 + void *arg, 4614 + sctp_cmd_seq_t *commands) 4615 + { 4616 + struct sctp_chunk *repl = NULL; 4617 + struct sctp_bind_addr *bp; 4618 + int attempts = asoc->init_err_counter + 1; 4619 + 4620 + SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n"); 4621 + 4622 + if (attempts < asoc->max_init_attempts) { 4623 + bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; 4624 + repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); 4625 + if (!repl) 4626 + return SCTP_DISPOSITION_NOMEM; 4627 + 4628 + /* Choose transport for INIT. */ 4629 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, 4630 + SCTP_CHUNK(repl)); 4631 + 4632 + /* Issue a sideeffect to do the needed accounting. */ 4633 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, 4634 + SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); 4635 + 4636 + sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 4637 + } else { 4638 + SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d" 4639 + " max_init_attempts: %d\n", 4640 + attempts, asoc->max_init_attempts); 4641 + sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, 4642 + SCTP_U32(SCTP_ERROR_NO_ERROR)); 4643 + return SCTP_DISPOSITION_DELETE_TCB; 4644 + } 4645 + 4646 + return SCTP_DISPOSITION_CONSUME; 4647 + } 4648 + 4649 + /* 4650 + * sctp_sf_t1_cookie_timer_expire 4651 + * 4652 + * Section: 4 Note: 2 4653 + * Verification Tag: 4654 + * Inputs 4655 + * (endpoint, asoc) 4656 + * 4657 + * RFC 2960 Section 4 Notes 4658 + * 3) If the T1-cookie timer expires, the endpoint MUST retransmit 4626 4659 * COOKIE ECHO and re-start the T1-cookie timer without changing 4627 4660 * state. This MUST be repeated up to 'Max.Init.Retransmits' times. 4628 4661 * After that, the endpoint MUST abort the initialization process and ··· 4684 4613 * (timers, events) 4685 4614 * 4686 4615 */ 4687 - sctp_disposition_t sctp_sf_t1_timer_expire(const struct sctp_endpoint *ep, 4616 + sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep, 4688 4617 const struct sctp_association *asoc, 4689 4618 const sctp_subtype_t type, 4690 4619 void *arg, 4691 4620 sctp_cmd_seq_t *commands) 4692 4621 { 4693 - struct sctp_chunk *repl; 4694 - struct sctp_bind_addr *bp; 4695 - sctp_event_timeout_t timer = (sctp_event_timeout_t) arg; 4696 - int timeout; 4697 - int attempts; 4622 + struct sctp_chunk *repl = NULL; 4623 + int attempts = asoc->init_err_counter + 1; 4698 4624 4699 - timeout = asoc->timeouts[timer]; 4700 - attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1; 4701 - repl = NULL; 4702 - 4703 - SCTP_DEBUG_PRINTK("Timer T1 expired.\n"); 4625 + SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n"); 4704 4626 4705 4627 if (attempts < asoc->max_init_attempts) { 4706 - switch (timer) { 4707 - case SCTP_EVENT_TIMEOUT_T1_INIT: 4708 - bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; 4709 - repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); 4710 - break; 4711 - 4712 - case SCTP_EVENT_TIMEOUT_T1_COOKIE: 4713 - repl = sctp_make_cookie_echo(asoc, NULL); 4714 - break; 4715 - 4716 - default: 4717 - BUG(); 4718 - break; 4719 - }; 4720 - 4628 + repl = sctp_make_cookie_echo(asoc, NULL); 4721 4629 if (!repl) 4722 - goto nomem; 4630 + return SCTP_DISPOSITION_NOMEM; 4723 4631 4724 4632 /* Issue a sideeffect to do the needed accounting. */ 4725 - sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, 4726 - SCTP_TO(timer)); 4633 + sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART, 4634 + SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); 4635 + 4727 4636 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); 4728 4637 } else { 4729 4638 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, ··· 4712 4661 } 4713 4662 4714 4663 return SCTP_DISPOSITION_CONSUME; 4715 - 4716 - nomem: 4717 - return SCTP_DISPOSITION_NOMEM; 4718 4664 } 4719 4665 4720 4666 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
+4 -2
net/sctp/sm_statetable.c
··· 783 783 /* SCTP_STATE_COOKIE_WAIT */ \ 784 784 {.fn = sctp_sf_bug, .name = "sctp_sf_bug"}, \ 785 785 /* SCTP_STATE_COOKIE_ECHOED */ \ 786 - {.fn = sctp_sf_t1_timer_expire, .name = "sctp_sf_t1_timer_expire"}, \ 786 + {.fn = sctp_sf_t1_cookie_timer_expire, \ 787 + .name = "sctp_sf_t1_cookie_timer_expire"}, \ 787 788 /* SCTP_STATE_ESTABLISHED */ \ 788 789 {.fn = sctp_sf_timer_ignore, .name = "sctp_sf_timer_ignore"}, \ 789 790 /* SCTP_STATE_SHUTDOWN_PENDING */ \ ··· 803 802 /* SCTP_STATE_CLOSED */ \ 804 803 {.fn = sctp_sf_timer_ignore, .name = "sctp_sf_timer_ignore"}, \ 805 804 /* SCTP_STATE_COOKIE_WAIT */ \ 806 - {.fn = sctp_sf_t1_timer_expire, .name = "sctp_sf_t1_timer_expire"}, \ 805 + {.fn = sctp_sf_t1_init_timer_expire, \ 806 + .name = "sctp_sf_t1_init_timer_expire"}, \ 807 807 /* SCTP_STATE_COOKIE_ECHOED */ \ 808 808 {.fn = sctp_sf_timer_ignore, .name = "sctp_sf_timer_ignore"}, \ 809 809 /* SCTP_STATE_ESTABLISHED */ \
+288 -117
net/sctp/socket.c
··· 262 262 * sockaddr_in6 [RFC 2553]), 263 263 * addr_len - the size of the address structure. 264 264 */ 265 - SCTP_STATIC int sctp_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) 265 + SCTP_STATIC int sctp_bind(struct sock *sk, struct sockaddr *addr, int addr_len) 266 266 { 267 267 int retval = 0; 268 268 269 269 sctp_lock_sock(sk); 270 270 271 - SCTP_DEBUG_PRINTK("sctp_bind(sk: %p, uaddr: %p, addr_len: %d)\n", 272 - sk, uaddr, addr_len); 271 + SCTP_DEBUG_PRINTK("sctp_bind(sk: %p, addr: %p, addr_len: %d)\n", 272 + sk, addr, addr_len); 273 273 274 274 /* Disallow binding twice. */ 275 275 if (!sctp_sk(sk)->ep->base.bind_addr.port) 276 - retval = sctp_do_bind(sk, (union sctp_addr *)uaddr, 276 + retval = sctp_do_bind(sk, (union sctp_addr *)addr, 277 277 addr_len); 278 278 else 279 279 retval = -EINVAL; ··· 318 318 unsigned short snum; 319 319 int ret = 0; 320 320 321 - SCTP_DEBUG_PRINTK("sctp_do_bind(sk: %p, newaddr: %p, len: %d)\n", 322 - sk, addr, len); 323 - 324 321 /* Common sockaddr verification. */ 325 322 af = sctp_sockaddr_af(sp, addr, len); 326 - if (!af) 323 + if (!af) { 324 + SCTP_DEBUG_PRINTK("sctp_do_bind(sk: %p, newaddr: %p, len: %d) EINVAL\n", 325 + sk, addr, len); 327 326 return -EINVAL; 327 + } 328 + 329 + snum = ntohs(addr->v4.sin_port); 330 + 331 + SCTP_DEBUG_PRINTK_IPADDR("sctp_do_bind(sk: %p, new addr: ", 332 + ", port: %d, new port: %d, len: %d)\n", 333 + sk, 334 + addr, 335 + bp->port, snum, 336 + len); 328 337 329 338 /* PF specific bind() address verification. */ 330 339 if (!sp->pf->bind_verify(sp, addr)) 331 340 return -EADDRNOTAVAIL; 332 - 333 - snum= ntohs(addr->v4.sin_port); 334 - 335 - SCTP_DEBUG_PRINTK("sctp_do_bind: port: %d, new port: %d\n", 336 - bp->port, snum); 337 341 338 342 /* We must either be unbound, or bind to the same port. */ 339 343 if (bp->port && (snum != bp->port)) { ··· 820 816 * 821 817 * Basically do nothing but copying the addresses from user to kernel 822 818 * land and invoking either sctp_bindx_add() or sctp_bindx_rem() on the sk. 823 - * This is used for tunneling the sctp_bindx() request through sctp_setsockopt() * from userspace. 819 + * This is used for tunneling the sctp_bindx() request through sctp_setsockopt() 820 + * from userspace. 824 821 * 825 822 * We don't use copy_from_user() for optimization: we first do the 826 823 * sanity checks (buffer size -fast- and access check-healthy ··· 915 910 out: 916 911 kfree(kaddrs); 917 912 913 + return err; 914 + } 915 + 916 + /* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size) 917 + * 918 + * Common routine for handling connect() and sctp_connectx(). 919 + * Connect will come in with just a single address. 920 + */ 921 + static int __sctp_connect(struct sock* sk, 922 + struct sockaddr *kaddrs, 923 + int addrs_size) 924 + { 925 + struct sctp_sock *sp; 926 + struct sctp_endpoint *ep; 927 + struct sctp_association *asoc = NULL; 928 + struct sctp_association *asoc2; 929 + struct sctp_transport *transport; 930 + union sctp_addr to; 931 + struct sctp_af *af; 932 + sctp_scope_t scope; 933 + long timeo; 934 + int err = 0; 935 + int addrcnt = 0; 936 + int walk_size = 0; 937 + struct sockaddr *sa_addr; 938 + void *addr_buf; 939 + 940 + sp = sctp_sk(sk); 941 + ep = sp->ep; 942 + 943 + /* connect() cannot be done on a socket that is already in ESTABLISHED 944 + * state - UDP-style peeled off socket or a TCP-style socket that 945 + * is already connected. 946 + * It cannot be done even on a TCP-style listening socket. 947 + */ 948 + if (sctp_sstate(sk, ESTABLISHED) || 949 + (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) { 950 + err = -EISCONN; 951 + goto out_free; 952 + } 953 + 954 + /* Walk through the addrs buffer and count the number of addresses. */ 955 + addr_buf = kaddrs; 956 + while (walk_size < addrs_size) { 957 + sa_addr = (struct sockaddr *)addr_buf; 958 + af = sctp_get_af_specific(sa_addr->sa_family); 959 + 960 + /* If the address family is not supported or if this address 961 + * causes the address buffer to overflow return EINVAL. 962 + */ 963 + if (!af || (walk_size + af->sockaddr_len) > addrs_size) { 964 + err = -EINVAL; 965 + goto out_free; 966 + } 967 + 968 + err = sctp_verify_addr(sk, (union sctp_addr *)sa_addr, 969 + af->sockaddr_len); 970 + if (err) 971 + goto out_free; 972 + 973 + memcpy(&to, sa_addr, af->sockaddr_len); 974 + to.v4.sin_port = ntohs(to.v4.sin_port); 975 + 976 + /* Check if there already is a matching association on the 977 + * endpoint (other than the one created here). 978 + */ 979 + asoc2 = sctp_endpoint_lookup_assoc(ep, &to, &transport); 980 + if (asoc2 && asoc2 != asoc) { 981 + if (asoc2->state >= SCTP_STATE_ESTABLISHED) 982 + err = -EISCONN; 983 + else 984 + err = -EALREADY; 985 + goto out_free; 986 + } 987 + 988 + /* If we could not find a matching association on the endpoint, 989 + * make sure that there is no peeled-off association matching 990 + * the peer address even on another socket. 991 + */ 992 + if (sctp_endpoint_is_peeled_off(ep, &to)) { 993 + err = -EADDRNOTAVAIL; 994 + goto out_free; 995 + } 996 + 997 + if (!asoc) { 998 + /* If a bind() or sctp_bindx() is not called prior to 999 + * an sctp_connectx() call, the system picks an 1000 + * ephemeral port and will choose an address set 1001 + * equivalent to binding with a wildcard address. 1002 + */ 1003 + if (!ep->base.bind_addr.port) { 1004 + if (sctp_autobind(sk)) { 1005 + err = -EAGAIN; 1006 + goto out_free; 1007 + } 1008 + } 1009 + 1010 + scope = sctp_scope(&to); 1011 + asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); 1012 + if (!asoc) { 1013 + err = -ENOMEM; 1014 + goto out_free; 1015 + } 1016 + } 1017 + 1018 + /* Prime the peer's transport structures. */ 1019 + transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, 1020 + SCTP_UNKNOWN); 1021 + if (!transport) { 1022 + err = -ENOMEM; 1023 + goto out_free; 1024 + } 1025 + 1026 + addrcnt++; 1027 + addr_buf += af->sockaddr_len; 1028 + walk_size += af->sockaddr_len; 1029 + } 1030 + 1031 + err = sctp_assoc_set_bind_addr_from_ep(asoc, GFP_KERNEL); 1032 + if (err < 0) { 1033 + goto out_free; 1034 + } 1035 + 1036 + err = sctp_primitive_ASSOCIATE(asoc, NULL); 1037 + if (err < 0) { 1038 + goto out_free; 1039 + } 1040 + 1041 + /* Initialize sk's dport and daddr for getpeername() */ 1042 + inet_sk(sk)->dport = htons(asoc->peer.port); 1043 + af = sctp_get_af_specific(to.sa.sa_family); 1044 + af->to_sk_daddr(&to, sk); 1045 + 1046 + timeo = sock_sndtimeo(sk, sk->sk_socket->file->f_flags & O_NONBLOCK); 1047 + err = sctp_wait_for_connect(asoc, &timeo); 1048 + 1049 + /* Don't free association on exit. */ 1050 + asoc = NULL; 1051 + 1052 + out_free: 1053 + 1054 + SCTP_DEBUG_PRINTK("About to exit __sctp_connect() free asoc: %p" 1055 + " kaddrs: %p err: %d\n", 1056 + asoc, kaddrs, err); 1057 + if (asoc) 1058 + sctp_association_free(asoc); 1059 + return err; 1060 + } 1061 + 1062 + /* Helper for tunneling sctp_connectx() requests through sctp_setsockopt() 1063 + * 1064 + * API 8.9 1065 + * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt); 1066 + * 1067 + * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses. 1068 + * If the sd is an IPv6 socket, the addresses passed can either be IPv4 1069 + * or IPv6 addresses. 1070 + * 1071 + * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see 1072 + * Section 3.1.2 for this usage. 1073 + * 1074 + * addrs is a pointer to an array of one or more socket addresses. Each 1075 + * address is contained in its appropriate structure (i.e. struct 1076 + * sockaddr_in or struct sockaddr_in6) the family of the address type 1077 + * must be used to distengish the address length (note that this 1078 + * representation is termed a "packed array" of addresses). The caller 1079 + * specifies the number of addresses in the array with addrcnt. 1080 + * 1081 + * On success, sctp_connectx() returns 0. On failure, sctp_connectx() returns 1082 + * -1, and sets errno to the appropriate error code. 1083 + * 1084 + * For SCTP, the port given in each socket address must be the same, or 1085 + * sctp_connectx() will fail, setting errno to EINVAL. 1086 + * 1087 + * An application can use sctp_connectx to initiate an association with 1088 + * an endpoint that is multi-homed. Much like sctp_bindx() this call 1089 + * allows a caller to specify multiple addresses at which a peer can be 1090 + * reached. The way the SCTP stack uses the list of addresses to set up 1091 + * the association is implementation dependant. This function only 1092 + * specifies that the stack will try to make use of all the addresses in 1093 + * the list when needed. 1094 + * 1095 + * Note that the list of addresses passed in is only used for setting up 1096 + * the association. It does not necessarily equal the set of addresses 1097 + * the peer uses for the resulting association. If the caller wants to 1098 + * find out the set of peer addresses, it must use sctp_getpaddrs() to 1099 + * retrieve them after the association has been set up. 1100 + * 1101 + * Basically do nothing but copying the addresses from user to kernel 1102 + * land and invoking either sctp_connectx(). This is used for tunneling 1103 + * the sctp_connectx() request through sctp_setsockopt() from userspace. 1104 + * 1105 + * We don't use copy_from_user() for optimization: we first do the 1106 + * sanity checks (buffer size -fast- and access check-healthy 1107 + * pointer); if all of those succeed, then we can alloc the memory 1108 + * (expensive operation) needed to copy the data to kernel. Then we do 1109 + * the copying without checking the user space area 1110 + * (__copy_from_user()). 1111 + * 1112 + * On exit there is no need to do sockfd_put(), sys_setsockopt() does 1113 + * it. 1114 + * 1115 + * sk The sk of the socket 1116 + * addrs The pointer to the addresses in user land 1117 + * addrssize Size of the addrs buffer 1118 + * 1119 + * Returns 0 if ok, <0 errno code on error. 1120 + */ 1121 + SCTP_STATIC int sctp_setsockopt_connectx(struct sock* sk, 1122 + struct sockaddr __user *addrs, 1123 + int addrs_size) 1124 + { 1125 + int err = 0; 1126 + struct sockaddr *kaddrs; 1127 + 1128 + SCTP_DEBUG_PRINTK("%s - sk %p addrs %p addrs_size %d\n", 1129 + __FUNCTION__, sk, addrs, addrs_size); 1130 + 1131 + if (unlikely(addrs_size <= 0)) 1132 + return -EINVAL; 1133 + 1134 + /* Check the user passed a healthy pointer. */ 1135 + if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size))) 1136 + return -EFAULT; 1137 + 1138 + /* Alloc space for the address array in kernel memory. */ 1139 + kaddrs = (struct sockaddr *)kmalloc(addrs_size, GFP_KERNEL); 1140 + if (unlikely(!kaddrs)) 1141 + return -ENOMEM; 1142 + 1143 + if (__copy_from_user(kaddrs, addrs, addrs_size)) { 1144 + err = -EFAULT; 1145 + } else { 1146 + err = __sctp_connect(sk, kaddrs, addrs_size); 1147 + } 1148 + 1149 + kfree(kaddrs); 918 1150 return err; 919 1151 } 920 1152 ··· 1337 1095 sp = sctp_sk(sk); 1338 1096 ep = sp->ep; 1339 1097 1340 - SCTP_DEBUG_PRINTK("Using endpoint: %s.\n", ep->debug_name); 1098 + SCTP_DEBUG_PRINTK("Using endpoint: %p.\n", ep); 1341 1099 1342 1100 /* We cannot send a message over a TCP-style listening socket. */ 1343 1101 if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) { ··· 1548 1306 } 1549 1307 1550 1308 /* Prime the peer's transport structures. */ 1551 - transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL); 1309 + transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, SCTP_UNKNOWN); 1552 1310 if (!transport) { 1553 1311 err = -ENOMEM; 1554 1312 goto out_free; ··· 2450 2208 optlen, SCTP_BINDX_REM_ADDR); 2451 2209 break; 2452 2210 2211 + case SCTP_SOCKOPT_CONNECTX: 2212 + /* 'optlen' is the size of the addresses buffer. */ 2213 + retval = sctp_setsockopt_connectx(sk, (struct sockaddr __user *)optval, 2214 + optlen); 2215 + break; 2216 + 2453 2217 case SCTP_DISABLE_FRAGMENTS: 2454 2218 retval = sctp_setsockopt_disable_fragments(sk, optval, optlen); 2455 2219 break; ··· 2531 2283 * 2532 2284 * len: the size of the address. 2533 2285 */ 2534 - SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *uaddr, 2286 + SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *addr, 2535 2287 int addr_len) 2536 2288 { 2537 - struct sctp_sock *sp; 2538 - struct sctp_endpoint *ep; 2539 - struct sctp_association *asoc; 2540 - struct sctp_transport *transport; 2541 - union sctp_addr to; 2542 - struct sctp_af *af; 2543 - sctp_scope_t scope; 2544 - long timeo; 2545 2289 int err = 0; 2290 + struct sctp_af *af; 2546 2291 2547 2292 sctp_lock_sock(sk); 2548 2293 2549 - SCTP_DEBUG_PRINTK("%s - sk: %p, sockaddr: %p, addr_len: %d)\n", 2550 - __FUNCTION__, sk, uaddr, addr_len); 2294 + SCTP_DEBUG_PRINTK("%s - sk: %p, sockaddr: %p, addr_len: %d\n", 2295 + __FUNCTION__, sk, addr, addr_len); 2551 2296 2552 - sp = sctp_sk(sk); 2553 - ep = sp->ep; 2554 - 2555 - /* connect() cannot be done on a socket that is already in ESTABLISHED 2556 - * state - UDP-style peeled off socket or a TCP-style socket that 2557 - * is already connected. 2558 - * It cannot be done even on a TCP-style listening socket. 2559 - */ 2560 - if (sctp_sstate(sk, ESTABLISHED) || 2561 - (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) { 2562 - err = -EISCONN; 2563 - goto out_unlock; 2297 + /* Validate addr_len before calling common connect/connectx routine. */ 2298 + af = sctp_get_af_specific(addr->sa_family); 2299 + if (!af || addr_len < af->sockaddr_len) { 2300 + err = -EINVAL; 2301 + } else { 2302 + /* Pass correct addr len to common routine (so it knows there 2303 + * is only one address being passed. 2304 + */ 2305 + err = __sctp_connect(sk, addr, af->sockaddr_len); 2564 2306 } 2565 2307 2566 - err = sctp_verify_addr(sk, (union sctp_addr *)uaddr, addr_len); 2567 - if (err) 2568 - goto out_unlock; 2569 - 2570 - if (addr_len > sizeof(to)) 2571 - addr_len = sizeof(to); 2572 - memcpy(&to, uaddr, addr_len); 2573 - to.v4.sin_port = ntohs(to.v4.sin_port); 2574 - 2575 - asoc = sctp_endpoint_lookup_assoc(ep, &to, &transport); 2576 - if (asoc) { 2577 - if (asoc->state >= SCTP_STATE_ESTABLISHED) 2578 - err = -EISCONN; 2579 - else 2580 - err = -EALREADY; 2581 - goto out_unlock; 2582 - } 2583 - 2584 - /* If we could not find a matching association on the endpoint, 2585 - * make sure that there is no peeled-off association matching the 2586 - * peer address even on another socket. 2587 - */ 2588 - if (sctp_endpoint_is_peeled_off(ep, &to)) { 2589 - err = -EADDRNOTAVAIL; 2590 - goto out_unlock; 2591 - } 2592 - 2593 - /* If a bind() or sctp_bindx() is not called prior to a connect() 2594 - * call, the system picks an ephemeral port and will choose an address 2595 - * set equivalent to binding with a wildcard address. 2596 - */ 2597 - if (!ep->base.bind_addr.port) { 2598 - if (sctp_autobind(sk)) { 2599 - err = -EAGAIN; 2600 - goto out_unlock; 2601 - } 2602 - } 2603 - 2604 - scope = sctp_scope(&to); 2605 - asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); 2606 - if (!asoc) { 2607 - err = -ENOMEM; 2608 - goto out_unlock; 2609 - } 2610 - 2611 - /* Prime the peer's transport structures. */ 2612 - transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL); 2613 - if (!transport) { 2614 - sctp_association_free(asoc); 2615 - goto out_unlock; 2616 - } 2617 - err = sctp_assoc_set_bind_addr_from_ep(asoc, GFP_KERNEL); 2618 - if (err < 0) { 2619 - sctp_association_free(asoc); 2620 - goto out_unlock; 2621 - } 2622 - 2623 - err = sctp_primitive_ASSOCIATE(asoc, NULL); 2624 - if (err < 0) { 2625 - sctp_association_free(asoc); 2626 - goto out_unlock; 2627 - } 2628 - 2629 - /* Initialize sk's dport and daddr for getpeername() */ 2630 - inet_sk(sk)->dport = htons(asoc->peer.port); 2631 - af = sctp_get_af_specific(to.sa.sa_family); 2632 - af->to_sk_daddr(&to, sk); 2633 - 2634 - timeo = sock_sndtimeo(sk, sk->sk_socket->file->f_flags & O_NONBLOCK); 2635 - err = sctp_wait_for_connect(asoc, &timeo); 2636 - 2637 - out_unlock: 2638 2308 sctp_release_sock(sk); 2639 - 2640 2309 return err; 2641 2310 } 2642 2311 ··· 2842 2677 /* Map ipv4 address into v4-mapped-on-v6 address. */ 2843 2678 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), 2844 2679 (union sctp_addr *)&status.sstat_primary.spinfo_address); 2845 - status.sstat_primary.spinfo_state = transport->active; 2680 + status.sstat_primary.spinfo_state = transport->state; 2846 2681 status.sstat_primary.spinfo_cwnd = transport->cwnd; 2847 2682 status.sstat_primary.spinfo_srtt = transport->srtt; 2848 2683 status.sstat_primary.spinfo_rto = jiffies_to_msecs(transport->rto); 2849 2684 status.sstat_primary.spinfo_mtu = transport->pmtu; 2685 + 2686 + if (status.sstat_primary.spinfo_state == SCTP_UNKNOWN) 2687 + status.sstat_primary.spinfo_state = SCTP_ACTIVE; 2850 2688 2851 2689 if (put_user(len, optlen)) { 2852 2690 retval = -EFAULT; ··· 2901 2733 return -EINVAL; 2902 2734 2903 2735 pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc); 2904 - pinfo.spinfo_state = transport->active; 2736 + pinfo.spinfo_state = transport->state; 2905 2737 pinfo.spinfo_cwnd = transport->cwnd; 2906 2738 pinfo.spinfo_srtt = transport->srtt; 2907 2739 pinfo.spinfo_rto = jiffies_to_msecs(transport->rto); 2908 2740 pinfo.spinfo_mtu = transport->pmtu; 2741 + 2742 + if (pinfo.spinfo_state == SCTP_UNKNOWN) 2743 + pinfo.spinfo_state = SCTP_ACTIVE; 2909 2744 2910 2745 if (put_user(len, optlen)) { 2911 2746 retval = -EFAULT; ··· 3762 3591 int retval = 0; 3763 3592 int len; 3764 3593 3765 - SCTP_DEBUG_PRINTK("sctp_getsockopt(sk: %p, ...)\n", sk); 3594 + SCTP_DEBUG_PRINTK("sctp_getsockopt(sk: %p... optname: %d)\n", 3595 + sk, optname); 3766 3596 3767 3597 /* I can hardly begin to describe how wrong this is. This is 3768 3598 * so broken as to be worse than useless. The API draft ··· 4768 4596 return err; 4769 4597 4770 4598 do_error: 4771 - if (asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1 >= 4772 - asoc->max_init_attempts) 4599 + if (asoc->init_err_counter + 1 >= asoc->max_init_attempts) 4773 4600 err = -ETIMEDOUT; 4774 4601 else 4775 4602 err = -ECONNREFUSED;
+3 -1
net/sctp/transport.c
··· 83 83 peer->last_time_used = jiffies; 84 84 peer->last_time_ecne_reduced = jiffies; 85 85 86 - peer->active = SCTP_ACTIVE; 86 + peer->init_sent_count = 0; 87 + 88 + peer->state = SCTP_ACTIVE; 87 89 peer->hb_allowed = 0; 88 90 89 91 /* Initialize the default path max_retrans. */