aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sctp/socket.c')
-rw-r--r--net/sctp/socket.c77
1 files changed, 21 insertions, 56 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 935bc9187fd8..02b27145b279 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -229,11 +229,9 @@ static struct sctp_transport *sctp_addr_id2transport(struct sock *sk,
229 struct sctp_transport *transport; 229 struct sctp_transport *transport;
230 union sctp_addr *laddr = (union sctp_addr *)addr; 230 union sctp_addr *laddr = (union sctp_addr *)addr;
231 231
232 laddr->v4.sin_port = ntohs(laddr->v4.sin_port);
233 addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep, 232 addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep,
234 (union sctp_addr *)addr, 233 laddr,
235 &transport); 234 &transport);
236 laddr->v4.sin_port = htons(laddr->v4.sin_port);
237 235
238 if (!addr_asoc) 236 if (!addr_asoc)
239 return NULL; 237 return NULL;
@@ -368,9 +366,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
368 sctp_write_lock(&ep->base.addr_lock); 366 sctp_write_lock(&ep->base.addr_lock);
369 367
370 /* Use GFP_ATOMIC since BHs are disabled. */ 368 /* Use GFP_ATOMIC since BHs are disabled. */
371 addr->v4.sin_port = ntohs(addr->v4.sin_port);
372 ret = sctp_add_bind_addr(bp, addr, 1, GFP_ATOMIC); 369 ret = sctp_add_bind_addr(bp, addr, 1, GFP_ATOMIC);
373 addr->v4.sin_port = htons(addr->v4.sin_port);
374 sctp_write_unlock(&ep->base.addr_lock); 370 sctp_write_unlock(&ep->base.addr_lock);
375 sctp_local_bh_enable(); 371 sctp_local_bh_enable();
376 372
@@ -572,7 +568,6 @@ static int sctp_send_asconf_add_ip(struct sock *sk,
572 addr = (union sctp_addr *)addr_buf; 568 addr = (union sctp_addr *)addr_buf;
573 af = sctp_get_af_specific(addr->v4.sin_family); 569 af = sctp_get_af_specific(addr->v4.sin_family);
574 memcpy(&saveaddr, addr, af->sockaddr_len); 570 memcpy(&saveaddr, addr, af->sockaddr_len);
575 saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port);
576 retval = sctp_add_bind_addr(bp, &saveaddr, 0, 571 retval = sctp_add_bind_addr(bp, &saveaddr, 0,
577 GFP_ATOMIC); 572 GFP_ATOMIC);
578 addr_buf += af->sockaddr_len; 573 addr_buf += af->sockaddr_len;
@@ -607,9 +602,8 @@ int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt)
607 int cnt; 602 int cnt;
608 struct sctp_bind_addr *bp = &ep->base.bind_addr; 603 struct sctp_bind_addr *bp = &ep->base.bind_addr;
609 int retval = 0; 604 int retval = 0;
610 union sctp_addr saveaddr;
611 void *addr_buf; 605 void *addr_buf;
612 struct sockaddr *sa_addr; 606 union sctp_addr *sa_addr;
613 struct sctp_af *af; 607 struct sctp_af *af;
614 608
615 SCTP_DEBUG_PRINTK("sctp_bindx_rem (sk: %p, addrs: %p, addrcnt: %d)\n", 609 SCTP_DEBUG_PRINTK("sctp_bindx_rem (sk: %p, addrs: %p, addrcnt: %d)\n",
@@ -627,19 +621,13 @@ int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt)
627 goto err_bindx_rem; 621 goto err_bindx_rem;
628 } 622 }
629 623
630 /* The list may contain either IPv4 or IPv6 address; 624 sa_addr = (union sctp_addr *)addr_buf;
631 * determine the address length to copy the address to 625 af = sctp_get_af_specific(sa_addr->sa.sa_family);
632 * saveaddr.
633 */
634 sa_addr = (struct sockaddr *)addr_buf;
635 af = sctp_get_af_specific(sa_addr->sa_family);
636 if (!af) { 626 if (!af) {
637 retval = -EINVAL; 627 retval = -EINVAL;
638 goto err_bindx_rem; 628 goto err_bindx_rem;
639 } 629 }
640 memcpy(&saveaddr, sa_addr, af->sockaddr_len); 630 if (sa_addr->v4.sin_port != htons(bp->port)) {
641 saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port);
642 if (saveaddr.v4.sin_port != bp->port) {
643 retval = -EINVAL; 631 retval = -EINVAL;
644 goto err_bindx_rem; 632 goto err_bindx_rem;
645 } 633 }
@@ -654,7 +642,7 @@ int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt)
654 sctp_local_bh_disable(); 642 sctp_local_bh_disable();
655 sctp_write_lock(&ep->base.addr_lock); 643 sctp_write_lock(&ep->base.addr_lock);
656 644
657 retval = sctp_del_bind_addr(bp, &saveaddr); 645 retval = sctp_del_bind_addr(bp, sa_addr);
658 646
659 sctp_write_unlock(&ep->base.addr_lock); 647 sctp_write_unlock(&ep->base.addr_lock);
660 sctp_local_bh_enable(); 648 sctp_local_bh_enable();
@@ -693,7 +681,6 @@ static int sctp_send_asconf_del_ip(struct sock *sk,
693 struct sctp_bind_addr *bp; 681 struct sctp_bind_addr *bp;
694 struct sctp_chunk *chunk; 682 struct sctp_chunk *chunk;
695 union sctp_addr *laddr; 683 union sctp_addr *laddr;
696 union sctp_addr saveaddr;
697 void *addr_buf; 684 void *addr_buf;
698 struct sctp_af *af; 685 struct sctp_af *af;
699 struct list_head *pos, *pos1; 686 struct list_head *pos, *pos1;
@@ -773,13 +760,11 @@ static int sctp_send_asconf_del_ip(struct sock *sk,
773 for (i = 0; i < addrcnt; i++) { 760 for (i = 0; i < addrcnt; i++) {
774 laddr = (union sctp_addr *)addr_buf; 761 laddr = (union sctp_addr *)addr_buf;
775 af = sctp_get_af_specific(laddr->v4.sin_family); 762 af = sctp_get_af_specific(laddr->v4.sin_family);
776 memcpy(&saveaddr, laddr, af->sockaddr_len);
777 saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port);
778 list_for_each(pos1, &bp->address_list) { 763 list_for_each(pos1, &bp->address_list) {
779 saddr = list_entry(pos1, 764 saddr = list_entry(pos1,
780 struct sctp_sockaddr_entry, 765 struct sctp_sockaddr_entry,
781 list); 766 list);
782 if (sctp_cmp_addr_exact(&saddr->a, &saveaddr)) 767 if (sctp_cmp_addr_exact(&saddr->a, laddr))
783 saddr->use_as_src = 0; 768 saddr->use_as_src = 0;
784 } 769 }
785 addr_buf += af->sockaddr_len; 770 addr_buf += af->sockaddr_len;
@@ -979,7 +964,7 @@ static int __sctp_connect(struct sock* sk,
979 int err = 0; 964 int err = 0;
980 int addrcnt = 0; 965 int addrcnt = 0;
981 int walk_size = 0; 966 int walk_size = 0;
982 struct sockaddr *sa_addr; 967 union sctp_addr *sa_addr;
983 void *addr_buf; 968 void *addr_buf;
984 969
985 sp = sctp_sk(sk); 970 sp = sctp_sk(sk);
@@ -999,8 +984,8 @@ static int __sctp_connect(struct sock* sk,
999 /* Walk through the addrs buffer and count the number of addresses. */ 984 /* Walk through the addrs buffer and count the number of addresses. */
1000 addr_buf = kaddrs; 985 addr_buf = kaddrs;
1001 while (walk_size < addrs_size) { 986 while (walk_size < addrs_size) {
1002 sa_addr = (struct sockaddr *)addr_buf; 987 sa_addr = (union sctp_addr *)addr_buf;
1003 af = sctp_get_af_specific(sa_addr->sa_family); 988 af = sctp_get_af_specific(sa_addr->sa.sa_family);
1004 989
1005 /* If the address family is not supported or if this address 990 /* If the address family is not supported or if this address
1006 * causes the address buffer to overflow return EINVAL. 991 * causes the address buffer to overflow return EINVAL.
@@ -1010,18 +995,16 @@ static int __sctp_connect(struct sock* sk,
1010 goto out_free; 995 goto out_free;
1011 } 996 }
1012 997
1013 err = sctp_verify_addr(sk, (union sctp_addr *)sa_addr, 998 err = sctp_verify_addr(sk, sa_addr, af->sockaddr_len);
1014 af->sockaddr_len);
1015 if (err) 999 if (err)
1016 goto out_free; 1000 goto out_free;
1017 1001
1018 memcpy(&to, sa_addr, af->sockaddr_len); 1002 memcpy(&to, sa_addr, af->sockaddr_len);
1019 to.v4.sin_port = ntohs(to.v4.sin_port);
1020 1003
1021 /* Check if there already is a matching association on the 1004 /* Check if there already is a matching association on the
1022 * endpoint (other than the one created here). 1005 * endpoint (other than the one created here).
1023 */ 1006 */
1024 asoc2 = sctp_endpoint_lookup_assoc(ep, &to, &transport); 1007 asoc2 = sctp_endpoint_lookup_assoc(ep, sa_addr, &transport);
1025 if (asoc2 && asoc2 != asoc) { 1008 if (asoc2 && asoc2 != asoc) {
1026 if (asoc2->state >= SCTP_STATE_ESTABLISHED) 1009 if (asoc2->state >= SCTP_STATE_ESTABLISHED)
1027 err = -EISCONN; 1010 err = -EISCONN;
@@ -1034,7 +1017,7 @@ static int __sctp_connect(struct sock* sk,
1034 * make sure that there is no peeled-off association matching 1017 * make sure that there is no peeled-off association matching
1035 * the peer address even on another socket. 1018 * the peer address even on another socket.
1036 */ 1019 */
1037 if (sctp_endpoint_is_peeled_off(ep, &to)) { 1020 if (sctp_endpoint_is_peeled_off(ep, sa_addr)) {
1038 err = -EADDRNOTAVAIL; 1021 err = -EADDRNOTAVAIL;
1039 goto out_free; 1022 goto out_free;
1040 } 1023 }
@@ -1065,7 +1048,7 @@ static int __sctp_connect(struct sock* sk,
1065 } 1048 }
1066 } 1049 }
1067 1050
1068 scope = sctp_scope(&to); 1051 scope = sctp_scope(sa_addr);
1069 asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); 1052 asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL);
1070 if (!asoc) { 1053 if (!asoc) {
1071 err = -ENOMEM; 1054 err = -ENOMEM;
@@ -1074,7 +1057,7 @@ static int __sctp_connect(struct sock* sk,
1074 } 1057 }
1075 1058
1076 /* Prime the peer's transport structures. */ 1059 /* Prime the peer's transport structures. */
1077 transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, 1060 transport = sctp_assoc_add_peer(asoc, sa_addr, GFP_KERNEL,
1078 SCTP_UNKNOWN); 1061 SCTP_UNKNOWN);
1079 if (!transport) { 1062 if (!transport) {
1080 err = -ENOMEM; 1063 err = -ENOMEM;
@@ -1427,11 +1410,6 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1427 if (msg_namelen > sizeof(to)) 1410 if (msg_namelen > sizeof(to))
1428 msg_namelen = sizeof(to); 1411 msg_namelen = sizeof(to);
1429 memcpy(&to, msg->msg_name, msg_namelen); 1412 memcpy(&to, msg->msg_name, msg_namelen);
1430 SCTP_DEBUG_PRINTK("Just memcpy'd. msg_name is "
1431 "0x%x:%u.\n",
1432 to.v4.sin_addr.s_addr, to.v4.sin_port);
1433
1434 to.v4.sin_port = ntohs(to.v4.sin_port);
1435 msg_name = msg->msg_name; 1413 msg_name = msg->msg_name;
1436 } 1414 }
1437 1415
@@ -3217,8 +3195,8 @@ static int sctp_getsockopt_sctp_status(struct sock *sk, int len,
3217 status.sstat_outstrms = asoc->c.sinit_num_ostreams; 3195 status.sstat_outstrms = asoc->c.sinit_num_ostreams;
3218 status.sstat_fragmentation_point = asoc->frag_point; 3196 status.sstat_fragmentation_point = asoc->frag_point;
3219 status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc); 3197 status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc);
3220 memcpy(&status.sstat_primary.spinfo_address, 3198 memcpy(&status.sstat_primary.spinfo_address, &transport->ipaddr,
3221 &(transport->ipaddr), sizeof(union sctp_addr)); 3199 transport->af_specific->sockaddr_len);
3222 /* Map ipv4 address into v4-mapped-on-v6 address. */ 3200 /* Map ipv4 address into v4-mapped-on-v6 address. */
3223 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), 3201 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk),
3224 (union sctp_addr *)&status.sstat_primary.spinfo_address); 3202 (union sctp_addr *)&status.sstat_primary.spinfo_address);
@@ -3770,7 +3748,6 @@ static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len,
3770 memcpy(&temp, &from->ipaddr, sizeof(temp)); 3748 memcpy(&temp, &from->ipaddr, sizeof(temp));
3771 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); 3749 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp);
3772 addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; 3750 addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len;
3773 temp.v4.sin_port = htons(temp.v4.sin_port);
3774 if (copy_to_user(to, &temp, addrlen)) 3751 if (copy_to_user(to, &temp, addrlen))
3775 return -EFAULT; 3752 return -EFAULT;
3776 to += addrlen ; 3753 to += addrlen ;
@@ -3821,7 +3798,6 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
3821 addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; 3798 addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len;
3822 if(space_left < addrlen) 3799 if(space_left < addrlen)
3823 return -ENOMEM; 3800 return -ENOMEM;
3824 temp.v4.sin_port = htons(temp.v4.sin_port);
3825 if (copy_to_user(to, &temp, addrlen)) 3801 if (copy_to_user(to, &temp, addrlen))
3826 return -EFAULT; 3802 return -EFAULT;
3827 to += addrlen; 3803 to += addrlen;
@@ -3889,7 +3865,7 @@ static int sctp_getsockopt_local_addrs_num_old(struct sock *sk, int len,
3889 struct sctp_sockaddr_entry, 3865 struct sctp_sockaddr_entry,
3890 list); 3866 list);
3891 if ((PF_INET == sk->sk_family) && 3867 if ((PF_INET == sk->sk_family) &&
3892 (AF_INET6 == addr->a.sa.sa_family)) 3868 (AF_INET6 == addr->a.sa.sa_family))
3893 continue; 3869 continue;
3894 cnt++; 3870 cnt++;
3895 } 3871 }
@@ -3933,7 +3909,6 @@ static int sctp_copy_laddrs_to_user_old(struct sock *sk, __u16 port, int max_add
3933 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), 3909 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk),
3934 &temp); 3910 &temp);
3935 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; 3911 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
3936 temp.v4.sin_port = htons(port);
3937 if (copy_to_user(to, &temp, addrlen)) { 3912 if (copy_to_user(to, &temp, addrlen)) {
3938 sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, 3913 sctp_spin_unlock_irqrestore(&sctp_local_addr_lock,
3939 flags); 3914 flags);
@@ -3970,7 +3945,6 @@ static int sctp_copy_laddrs_to_user(struct sock *sk, __u16 port,
3970 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; 3945 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
3971 if(space_left<addrlen) 3946 if(space_left<addrlen)
3972 return -ENOMEM; 3947 return -ENOMEM;
3973 temp.v4.sin_port = htons(port);
3974 if (copy_to_user(*to, &temp, addrlen)) { 3948 if (copy_to_user(*to, &temp, addrlen)) {
3975 sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, 3949 sctp_spin_unlock_irqrestore(&sctp_local_addr_lock,
3976 flags); 3950 flags);
@@ -4055,7 +4029,6 @@ static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len,
4055 memcpy(&temp, &addr->a, sizeof(temp)); 4029 memcpy(&temp, &addr->a, sizeof(temp));
4056 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); 4030 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp);
4057 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; 4031 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
4058 temp.v4.sin_port = htons(temp.v4.sin_port);
4059 if (copy_to_user(to, &temp, addrlen)) { 4032 if (copy_to_user(to, &temp, addrlen)) {
4060 err = -EFAULT; 4033 err = -EFAULT;
4061 goto unlock; 4034 goto unlock;
@@ -4146,7 +4119,6 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
4146 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; 4119 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
4147 if(space_left < addrlen) 4120 if(space_left < addrlen)
4148 return -ENOMEM; /*fixme: right error?*/ 4121 return -ENOMEM; /*fixme: right error?*/
4149 temp.v4.sin_port = htons(temp.v4.sin_port);
4150 if (copy_to_user(to, &temp, addrlen)) { 4122 if (copy_to_user(to, &temp, addrlen)) {
4151 err = -EFAULT; 4123 err = -EFAULT;
4152 goto unlock; 4124 goto unlock;
@@ -4194,12 +4166,8 @@ static int sctp_getsockopt_primary_addr(struct sock *sk, int len,
4194 if (!asoc->peer.primary_path) 4166 if (!asoc->peer.primary_path)
4195 return -ENOTCONN; 4167 return -ENOTCONN;
4196 4168
4197 asoc->peer.primary_path->ipaddr.v4.sin_port =
4198 htons(asoc->peer.primary_path->ipaddr.v4.sin_port);
4199 memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr, 4169 memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr,
4200 sizeof(union sctp_addr)); 4170 asoc->peer.primary_path->af_specific->sockaddr_len);
4201 asoc->peer.primary_path->ipaddr.v4.sin_port =
4202 ntohs(asoc->peer.primary_path->ipaddr.v4.sin_port);
4203 4171
4204 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, 4172 sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp,
4205 (union sctp_addr *)&prim.ssp_addr); 4173 (union sctp_addr *)&prim.ssp_addr);
@@ -4645,9 +4613,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
4645 unsigned short snum; 4613 unsigned short snum;
4646 int ret; 4614 int ret;
4647 4615
4648 /* NOTE: Remember to put this back to net order. */ 4616 snum = ntohs(addr->v4.sin_port);
4649 addr->v4.sin_port = ntohs(addr->v4.sin_port);
4650 snum = addr->v4.sin_port;
4651 4617
4652 SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum); 4618 SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum);
4653 sctp_local_bh_disable(); 4619 sctp_local_bh_disable();
@@ -4784,7 +4750,6 @@ fail_unlock:
4784 4750
4785fail: 4751fail:
4786 sctp_local_bh_enable(); 4752 sctp_local_bh_enable();
4787 addr->v4.sin_port = htons(addr->v4.sin_port);
4788 return ret; 4753 return ret;
4789} 4754}
4790 4755
@@ -5083,7 +5048,7 @@ static int sctp_autobind(struct sock *sk)
5083{ 5048{
5084 union sctp_addr autoaddr; 5049 union sctp_addr autoaddr;
5085 struct sctp_af *af; 5050 struct sctp_af *af;
5086 unsigned short port; 5051 __be16 port;
5087 5052
5088 /* Initialize a local sockaddr structure to INADDR_ANY. */ 5053 /* Initialize a local sockaddr structure to INADDR_ANY. */
5089 af = sctp_sk(sk)->pf->af; 5054 af = sctp_sk(sk)->pf->af;