diff options
author | Frank Filz <ffilzlnx@us.ibm.com> | 2005-06-20 16:14:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-06-20 16:14:57 -0400 |
commit | 3f7a87d2fa9b42f7aade43914f060df68cc89cc7 (patch) | |
tree | 15162d2dd770428f98a0d39f8dc6063aba0ad1e6 /net/sctp/associola.c | |
parent | 8b22c249e7de453961e4d253b19fc2a0bdd65d53 (diff) |
[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>
Diffstat (limited to 'net/sctp/associola.c')
-rw-r--r-- | net/sctp/associola.c | 151 |
1 files changed, 114 insertions, 37 deletions
diff --git a/net/sctp/associola.c b/net/sctp/associola.c index 663843d97a92..7ae6aa772dab 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c | |||
@@ -191,10 +191,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a | |||
191 | asoc->last_cwr_tsn = asoc->ctsn_ack_point; | 191 | asoc->last_cwr_tsn = asoc->ctsn_ack_point; |
192 | asoc->unack_data = 0; | 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 | /* ADDIP Section 4.1 Asconf Chunk Procedures | 194 | /* ADDIP Section 4.1 Asconf Chunk Procedures |
199 | * | 195 | * |
200 | * When an endpoint has an ASCONF signaled change to be sent to the | 196 | * When an endpoint has an ASCONF signaled change to be sent to the |
@@ -211,6 +207,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a | |||
211 | 207 | ||
212 | /* Make an empty list of remote transport addresses. */ | 208 | /* Make an empty list of remote transport addresses. */ |
213 | INIT_LIST_HEAD(&asoc->peer.transport_addr_list); | 209 | INIT_LIST_HEAD(&asoc->peer.transport_addr_list); |
210 | asoc->peer.transport_count = 0; | ||
214 | 211 | ||
215 | /* RFC 2960 5.1 Normal Establishment of an Association | 212 | /* RFC 2960 5.1 Normal Establishment of an Association |
216 | * | 213 | * |
@@ -288,6 +285,7 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep, | |||
288 | 285 | ||
289 | asoc->base.malloced = 1; | 286 | asoc->base.malloced = 1; |
290 | SCTP_DBG_OBJCNT_INC(assoc); | 287 | SCTP_DBG_OBJCNT_INC(assoc); |
288 | SCTP_DEBUG_PRINTK("Created asoc %p\n", asoc); | ||
291 | 289 | ||
292 | return asoc; | 290 | return asoc; |
293 | 291 | ||
@@ -356,6 +354,8 @@ void sctp_association_free(struct sctp_association *asoc) | |||
356 | sctp_transport_free(transport); | 354 | sctp_transport_free(transport); |
357 | } | 355 | } |
358 | 356 | ||
357 | asoc->peer.transport_count = 0; | ||
358 | |||
359 | /* Free any cached ASCONF_ACK chunk. */ | 359 | /* Free any cached ASCONF_ACK chunk. */ |
360 | if (asoc->addip_last_asconf_ack) | 360 | if (asoc->addip_last_asconf_ack) |
361 | sctp_chunk_free(asoc->addip_last_asconf_ack); | 361 | sctp_chunk_free(asoc->addip_last_asconf_ack); |
@@ -400,7 +400,7 @@ void sctp_assoc_set_primary(struct sctp_association *asoc, | |||
400 | /* If the primary path is changing, assume that the | 400 | /* If the primary path is changing, assume that the |
401 | * user wants to use this new path. | 401 | * user wants to use this new path. |
402 | */ | 402 | */ |
403 | if (transport->active) | 403 | if (transport->state != SCTP_INACTIVE) |
404 | asoc->peer.active_path = transport; | 404 | asoc->peer.active_path = transport; |
405 | 405 | ||
406 | /* | 406 | /* |
@@ -428,10 +428,58 @@ void sctp_assoc_set_primary(struct sctp_association *asoc, | |||
428 | transport->cacc.next_tsn_at_change = asoc->next_tsn; | 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 | /* Add a transport address to an association. */ | 478 | /* Add a transport address to an association. */ |
432 | struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, | 479 | struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, |
433 | const union sctp_addr *addr, | 480 | const union sctp_addr *addr, |
434 | int gfp) | 481 | const int gfp, |
482 | const int peer_state) | ||
435 | { | 483 | { |
436 | struct sctp_transport *peer; | 484 | struct sctp_transport *peer; |
437 | struct sctp_sock *sp; | 485 | struct sctp_sock *sp; |
@@ -442,14 +490,25 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, | |||
442 | /* AF_INET and AF_INET6 share common port field. */ | 490 | /* AF_INET and AF_INET6 share common port field. */ |
443 | port = addr->v4.sin_port; | 491 | port = addr->v4.sin_port; |
444 | 492 | ||
493 | SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_add_peer:association %p addr: ", | ||
494 | " port: %d state:%s\n", | ||
495 | asoc, | ||
496 | addr, | ||
497 | addr->v4.sin_port, | ||
498 | peer_state == SCTP_UNKNOWN?"UNKNOWN":"ACTIVE"); | ||
499 | |||
445 | /* Set the port if it has not been set yet. */ | 500 | /* Set the port if it has not been set yet. */ |
446 | if (0 == asoc->peer.port) | 501 | if (0 == asoc->peer.port) |
447 | asoc->peer.port = port; | 502 | asoc->peer.port = port; |
448 | 503 | ||
449 | /* Check to see if this is a duplicate. */ | 504 | /* Check to see if this is a duplicate. */ |
450 | peer = sctp_assoc_lookup_paddr(asoc, addr); | 505 | peer = sctp_assoc_lookup_paddr(asoc, addr); |
451 | if (peer) | 506 | if (peer) { |
507 | if (peer_state == SCTP_ACTIVE && | ||
508 | peer->state == SCTP_UNKNOWN) | ||
509 | peer->state = SCTP_ACTIVE; | ||
452 | return peer; | 510 | return peer; |
511 | } | ||
453 | 512 | ||
454 | peer = sctp_transport_new(addr, gfp); | 513 | peer = sctp_transport_new(addr, gfp); |
455 | if (!peer) | 514 | if (!peer) |
@@ -516,8 +575,12 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, | |||
516 | /* Set the transport's RTO.initial value */ | 575 | /* Set the transport's RTO.initial value */ |
517 | peer->rto = asoc->rto_initial; | 576 | peer->rto = asoc->rto_initial; |
518 | 577 | ||
578 | /* Set the peer's active state. */ | ||
579 | peer->state = peer_state; | ||
580 | |||
519 | /* Attach the remote transport to our asoc. */ | 581 | /* Attach the remote transport to our asoc. */ |
520 | list_add_tail(&peer->transports, &asoc->peer.transport_addr_list); | 582 | list_add_tail(&peer->transports, &asoc->peer.transport_addr_list); |
583 | asoc->peer.transport_count++; | ||
521 | 584 | ||
522 | /* If we do not yet have a primary path, set one. */ | 585 | /* If we do not yet have a primary path, set one. */ |
523 | if (!asoc->peer.primary_path) { | 586 | if (!asoc->peer.primary_path) { |
@@ -525,8 +588,9 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, | |||
525 | asoc->peer.retran_path = peer; | 588 | asoc->peer.retran_path = peer; |
526 | } | 589 | } |
527 | 590 | ||
528 | if (asoc->peer.active_path == asoc->peer.retran_path) | 591 | if (asoc->peer.active_path == asoc->peer.retran_path) { |
529 | asoc->peer.retran_path = peer; | 592 | asoc->peer.retran_path = peer; |
593 | } | ||
530 | 594 | ||
531 | return peer; | 595 | return peer; |
532 | } | 596 | } |
@@ -537,37 +601,16 @@ void sctp_assoc_del_peer(struct sctp_association *asoc, | |||
537 | { | 601 | { |
538 | struct list_head *pos; | 602 | struct list_head *pos; |
539 | struct list_head *temp; | 603 | struct list_head *temp; |
540 | struct sctp_transport *peer = NULL; | ||
541 | struct sctp_transport *transport; | 604 | struct sctp_transport *transport; |
542 | 605 | ||
543 | list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { | 606 | list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { |
544 | transport = list_entry(pos, struct sctp_transport, transports); | 607 | transport = list_entry(pos, struct sctp_transport, transports); |
545 | if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) { | 608 | if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) { |
546 | peer = transport; | 609 | /* Do book keeping for removing the peer and free it. */ |
547 | list_del(pos); | 610 | sctp_assoc_rm_peer(asoc, transport); |
548 | break; | 611 | break; |
549 | } | 612 | } |
550 | } | 613 | } |
551 | |||
552 | /* The address we want delete is not in the association. */ | ||
553 | if (!peer) | ||
554 | return; | ||
555 | |||
556 | /* Get the first transport of asoc. */ | ||
557 | pos = asoc->peer.transport_addr_list.next; | ||
558 | transport = list_entry(pos, struct sctp_transport, transports); | ||
559 | |||
560 | /* Update any entries that match the peer to be deleted. */ | ||
561 | if (asoc->peer.primary_path == peer) | ||
562 | sctp_assoc_set_primary(asoc, transport); | ||
563 | if (asoc->peer.active_path == peer) | ||
564 | asoc->peer.active_path = transport; | ||
565 | if (asoc->peer.retran_path == peer) | ||
566 | asoc->peer.retran_path = transport; | ||
567 | if (asoc->peer.last_data_from == peer) | ||
568 | asoc->peer.last_data_from = transport; | ||
569 | |||
570 | sctp_transport_free(peer); | ||
571 | } | 614 | } |
572 | 615 | ||
573 | /* Lookup a transport by address. */ | 616 | /* Lookup a transport by address. */ |
@@ -608,12 +651,12 @@ void sctp_assoc_control_transport(struct sctp_association *asoc, | |||
608 | /* Record the transition on the transport. */ | 651 | /* Record the transition on the transport. */ |
609 | switch (command) { | 652 | switch (command) { |
610 | case SCTP_TRANSPORT_UP: | 653 | case SCTP_TRANSPORT_UP: |
611 | transport->active = SCTP_ACTIVE; | 654 | transport->state = SCTP_ACTIVE; |
612 | spc_state = SCTP_ADDR_AVAILABLE; | 655 | spc_state = SCTP_ADDR_AVAILABLE; |
613 | break; | 656 | break; |
614 | 657 | ||
615 | case SCTP_TRANSPORT_DOWN: | 658 | case SCTP_TRANSPORT_DOWN: |
616 | transport->active = SCTP_INACTIVE; | 659 | transport->state = SCTP_INACTIVE; |
617 | spc_state = SCTP_ADDR_UNREACHABLE; | 660 | spc_state = SCTP_ADDR_UNREACHABLE; |
618 | break; | 661 | break; |
619 | 662 | ||
@@ -643,7 +686,7 @@ void sctp_assoc_control_transport(struct sctp_association *asoc, | |||
643 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 686 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
644 | t = list_entry(pos, struct sctp_transport, transports); | 687 | t = list_entry(pos, struct sctp_transport, transports); |
645 | 688 | ||
646 | if (!t->active) | 689 | if (t->state == SCTP_INACTIVE) |
647 | continue; | 690 | continue; |
648 | if (!first || t->last_time_heard > first->last_time_heard) { | 691 | if (!first || t->last_time_heard > first->last_time_heard) { |
649 | second = first; | 692 | second = first; |
@@ -663,7 +706,7 @@ void sctp_assoc_control_transport(struct sctp_association *asoc, | |||
663 | * [If the primary is active but not most recent, bump the most | 706 | * [If the primary is active but not most recent, bump the most |
664 | * recently used transport.] | 707 | * recently used transport.] |
665 | */ | 708 | */ |
666 | if (asoc->peer.primary_path->active && | 709 | if (asoc->peer.primary_path->state != SCTP_INACTIVE && |
667 | first != asoc->peer.primary_path) { | 710 | first != asoc->peer.primary_path) { |
668 | second = first; | 711 | second = first; |
669 | first = asoc->peer.primary_path; | 712 | first = asoc->peer.primary_path; |
@@ -958,7 +1001,7 @@ void sctp_assoc_update(struct sctp_association *asoc, | |||
958 | transports); | 1001 | transports); |
959 | if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr)) | 1002 | if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr)) |
960 | sctp_assoc_add_peer(asoc, &trans->ipaddr, | 1003 | sctp_assoc_add_peer(asoc, &trans->ipaddr, |
961 | GFP_ATOMIC); | 1004 | GFP_ATOMIC, SCTP_ACTIVE); |
962 | } | 1005 | } |
963 | 1006 | ||
964 | asoc->ctsn_ack_point = asoc->next_tsn - 1; | 1007 | asoc->ctsn_ack_point = asoc->next_tsn - 1; |
@@ -998,7 +1041,7 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc) | |||
998 | 1041 | ||
999 | /* Try to find an active transport. */ | 1042 | /* Try to find an active transport. */ |
1000 | 1043 | ||
1001 | if (t->active) { | 1044 | if (t->state != SCTP_INACTIVE) { |
1002 | break; | 1045 | break; |
1003 | } else { | 1046 | } else { |
1004 | /* Keep track of the next transport in case | 1047 | /* Keep track of the next transport in case |
@@ -1019,6 +1062,40 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc) | |||
1019 | } | 1062 | } |
1020 | 1063 | ||
1021 | asoc->peer.retran_path = t; | 1064 | asoc->peer.retran_path = t; |
1065 | |||
1066 | SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association" | ||
1067 | " %p addr: ", | ||
1068 | " port: %d\n", | ||
1069 | asoc, | ||
1070 | (&t->ipaddr), | ||
1071 | t->ipaddr.v4.sin_port); | ||
1072 | } | ||
1073 | |||
1074 | /* Choose the transport for sending a INIT packet. */ | ||
1075 | struct sctp_transport *sctp_assoc_choose_init_transport( | ||
1076 | struct sctp_association *asoc) | ||
1077 | { | ||
1078 | struct sctp_transport *t; | ||
1079 | |||
1080 | /* Use the retran path. If the last INIT was sent over the | ||
1081 | * retran path, update the retran path and use it. | ||
1082 | */ | ||
1083 | if (!asoc->init_last_sent_to) { | ||
1084 | t = asoc->peer.active_path; | ||
1085 | } else { | ||
1086 | if (asoc->init_last_sent_to == asoc->peer.retran_path) | ||
1087 | sctp_assoc_update_retran_path(asoc); | ||
1088 | t = asoc->peer.retran_path; | ||
1089 | } | ||
1090 | |||
1091 | SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association" | ||
1092 | " %p addr: ", | ||
1093 | " port: %d\n", | ||
1094 | asoc, | ||
1095 | (&t->ipaddr), | ||
1096 | t->ipaddr.v4.sin_port); | ||
1097 | |||
1098 | return t; | ||
1022 | } | 1099 | } |
1023 | 1100 | ||
1024 | /* Choose the transport for sending a SHUTDOWN packet. */ | 1101 | /* Choose the transport for sending a SHUTDOWN packet. */ |