Deleted Added
full compact
sctputil.c (168961) sctputil.c (169208)
1/*-
2 * Copyright (c) 2001-2007, Cisco Systems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/* $KAME: sctputil.c,v 1.37 2005/03/07 23:26:09 itojun Exp $ */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001-2007, Cisco Systems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/* $KAME: sctputil.c,v 1.37 2005/03/07 23:26:09 itojun Exp $ */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 168961 2007-04-23 00:51:49Z rrs $");
34__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 169208 2007-05-02 12:50:13Z rrs $");
35
36#include <netinet/sctp_os.h>
37#include <netinet/sctp_pcb.h>
38#include <netinet/sctputil.h>
39#include <netinet/sctp_var.h>
40#include <netinet/sctp_sysctl.h>
41#ifdef INET6
42#include <netinet6/sctp6_var.h>

--- 3798 unchanged lines hidden (view full) ---

3841 printf("dest: ");
3842 sctp_print_address((struct sockaddr *)&fsa6);
3843 }
3844}
3845
3846void
3847sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
3848 struct sctp_inpcb *new_inp,
35
36#include <netinet/sctp_os.h>
37#include <netinet/sctp_pcb.h>
38#include <netinet/sctputil.h>
39#include <netinet/sctp_var.h>
40#include <netinet/sctp_sysctl.h>
41#ifdef INET6
42#include <netinet6/sctp6_var.h>

--- 3798 unchanged lines hidden (view full) ---

3841 printf("dest: ");
3842 sctp_print_address((struct sockaddr *)&fsa6);
3843 }
3844}
3845
3846void
3847sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
3848 struct sctp_inpcb *new_inp,
3849 struct sctp_tcb *stcb)
3849 struct sctp_tcb *stcb,
3850 int waitflags)
3850{
3851 /*
3852 * go through our old INP and pull off any control structures that
3853 * belong to stcb and move then to the new inp.
3854 */
3855 struct socket *old_so, *new_so;
3856 struct sctp_queued_to_read *control, *nctl;
3857 struct sctp_readhead tmp_queue;
3858 struct mbuf *m;
3859 int error = 0;
3860
3861 old_so = old_inp->sctp_socket;
3862 new_so = new_inp->sctp_socket;
3863 TAILQ_INIT(&tmp_queue);
3851{
3852 /*
3853 * go through our old INP and pull off any control structures that
3854 * belong to stcb and move then to the new inp.
3855 */
3856 struct socket *old_so, *new_so;
3857 struct sctp_queued_to_read *control, *nctl;
3858 struct sctp_readhead tmp_queue;
3859 struct mbuf *m;
3860 int error = 0;
3861
3862 old_so = old_inp->sctp_socket;
3863 new_so = new_inp->sctp_socket;
3864 TAILQ_INIT(&tmp_queue);
3864
3865 SOCKBUF_LOCK(&(old_so->so_rcv));
3865 SOCKBUF_LOCK(&(old_so->so_rcv));
3866
3867 error = sblock(&old_so->so_rcv, 0);
3868
3866 error = sblock(&old_so->so_rcv, waitflags);
3869 SOCKBUF_UNLOCK(&(old_so->so_rcv));
3870 if (error) {
3871 /*
3872 * Gak, can't get sblock, we have a problem. data will be
3873 * left stranded.. and we don't dare look at it since the
3874 * other thread may be reading something. Oh well, its a
3875 * screwed up app that does a peeloff OR a accept while
3876 * reading from the main socket... actually its only the

--- 22 unchanged lines hidden (view full) ---

3899 sctp_sblog(&old_so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
3900#endif
3901 m = SCTP_BUF_NEXT(m);
3902 }
3903 }
3904 control = nctl;
3905 }
3906 SCTP_INP_READ_UNLOCK(old_inp);
3867 SOCKBUF_UNLOCK(&(old_so->so_rcv));
3868 if (error) {
3869 /*
3870 * Gak, can't get sblock, we have a problem. data will be
3871 * left stranded.. and we don't dare look at it since the
3872 * other thread may be reading something. Oh well, its a
3873 * screwed up app that does a peeloff OR a accept while
3874 * reading from the main socket... actually its only the

--- 22 unchanged lines hidden (view full) ---

3897 sctp_sblog(&old_so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
3898#endif
3899 m = SCTP_BUF_NEXT(m);
3900 }
3901 }
3902 control = nctl;
3903 }
3904 SCTP_INP_READ_UNLOCK(old_inp);
3907
3908 /* Remove the sb-lock on the old socket */
3909 SOCKBUF_LOCK(&(old_so->so_rcv));
3910
3911 sbunlock(&old_so->so_rcv);
3912 SOCKBUF_UNLOCK(&(old_so->so_rcv));
3905 /* Remove the sb-lock on the old socket */
3906 SOCKBUF_LOCK(&(old_so->so_rcv));
3907
3908 sbunlock(&old_so->so_rcv);
3909 SOCKBUF_UNLOCK(&(old_so->so_rcv));
3913
3914 /* Now we move them over to the new socket buffer */
3915 control = TAILQ_FIRST(&tmp_queue);
3916 SCTP_INP_READ_LOCK(new_inp);
3917 while (control) {
3918 nctl = TAILQ_NEXT(control, next);
3919 TAILQ_INSERT_TAIL(&new_inp->read_queue, control, next);
3920 m = control->data;
3921 while (m) {

--- 371 unchanged lines hidden (view full) ---

4293 }
4294 }
4295 }
4296 if (holds_lock == 0)
4297 SCTP_INP_RUNLOCK(inp);
4298 return (NULL);
4299}
4300
3910 /* Now we move them over to the new socket buffer */
3911 control = TAILQ_FIRST(&tmp_queue);
3912 SCTP_INP_READ_LOCK(new_inp);
3913 while (control) {
3914 nctl = TAILQ_NEXT(control, next);
3915 TAILQ_INSERT_TAIL(&new_inp->read_queue, control, next);
3916 m = control->data;
3917 while (m) {

--- 371 unchanged lines hidden (view full) ---

4289 }
4290 }
4291 }
4292 if (holds_lock == 0)
4293 SCTP_INP_RUNLOCK(inp);
4294 return (NULL);
4295}
4296
4301struct sctp_ifa *
4302sctp_find_ifa_in_ifn(struct sctp_ifn *sctp_ifnp, struct sockaddr *addr,
4303 int holds_lock)
4304{
4305 struct sctp_ifa *sctp_ifap;
4306
4307 if (holds_lock == 0)
4308 SCTP_IPI_ADDR_LOCK();
4309
4310 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
4311 if (addr->sa_family != sctp_ifap->address.sa.sa_family)
4312 continue;
4313 if (addr->sa_family == AF_INET) {
4314 if (((struct sockaddr_in *)addr)->sin_addr.s_addr ==
4315 sctp_ifap->address.sin.sin_addr.s_addr) {
4316 /* found him. */
4317 if (holds_lock == 0)
4318 SCTP_IPI_ADDR_UNLOCK();
4319 return (sctp_ifap);
4320 break;
4321 }
4322 } else if (addr->sa_family == AF_INET6) {
4323 if (SCTP6_ARE_ADDR_EQUAL(&((struct sockaddr_in6 *)addr)->sin6_addr,
4324 &sctp_ifap->address.sin6.sin6_addr)) {
4325 /* found him. */
4326 if (holds_lock == 0)
4327 SCTP_IPI_ADDR_UNLOCK();
4328 return (sctp_ifap);
4329 break;
4330 }
4331 }
4332 }
4333 if (holds_lock == 0)
4334 SCTP_IPI_ADDR_UNLOCK();
4335 return (NULL);
4336}
4337
4338uint32_t
4339sctp_get_ifa_hash_val(struct sockaddr *addr)
4340{
4341
4342 if (addr->sa_family == AF_INET) {
4343 struct sockaddr_in *sin;
4344
4345 sin = (struct sockaddr_in *)addr;

--- 390 unchanged lines hidden (view full) ---

4736 }
4737 goto out;
4738 }
4739 }
4740 error = EWOULDBLOCK;
4741 }
4742 goto out;
4743 }
4297uint32_t
4298sctp_get_ifa_hash_val(struct sockaddr *addr)
4299{
4300
4301 if (addr->sa_family == AF_INET) {
4302 struct sockaddr_in *sin;
4303
4304 sin = (struct sockaddr_in *)addr;

--- 390 unchanged lines hidden (view full) ---

4695 }
4696 goto out;
4697 }
4698 }
4699 error = EWOULDBLOCK;
4700 }
4701 goto out;
4702 }
4703 if (hold_sblock == 1) {
4704 SOCKBUF_UNLOCK(&so->so_rcv);
4705 hold_sblock = 0;
4706 }
4744 error = sblock(&so->so_rcv, (block_allowed ? M_WAITOK : 0));
4745 /* we possibly have data we can read */
4746 control = TAILQ_FIRST(&inp->read_queue);
4747 if (control == NULL) {
4748 /*
4749 * This could be happening since the appender did the
4750 * increment but as not yet did the tailq insert onto the
4751 * read_queue

--- 105 unchanged lines hidden (view full) ---

4857 SCTP_INP_READ_UNLOCK(inp);
4858 hold_rlock = 0;
4859 }
4860found_one:
4861 /*
4862 * If we reach here, control has a some data for us to read off.
4863 * Note that stcb COULD be NULL.
4864 */
4707 error = sblock(&so->so_rcv, (block_allowed ? M_WAITOK : 0));
4708 /* we possibly have data we can read */
4709 control = TAILQ_FIRST(&inp->read_queue);
4710 if (control == NULL) {
4711 /*
4712 * This could be happening since the appender did the
4713 * increment but as not yet did the tailq insert onto the
4714 * read_queue

--- 105 unchanged lines hidden (view full) ---

4820 SCTP_INP_READ_UNLOCK(inp);
4821 hold_rlock = 0;
4822 }
4823found_one:
4824 /*
4825 * If we reach here, control has a some data for us to read off.
4826 * Note that stcb COULD be NULL.
4827 */
4865 if (control->do_not_ref_stcb == 0) {
4866 control->stcb->asoc.strmin[control->sinfo_stream].delivery_started = 1;
4867 }
4868 control->some_taken = 1;
4869 if (hold_sblock) {
4870 SOCKBUF_UNLOCK(&so->so_rcv);
4871 hold_sblock = 0;
4872 }
4873 stcb = control->stcb;
4874 if (stcb) {
4875 if ((stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) &&

--- 20 unchanged lines hidden (view full) ---

4896 * will go to the sctp_user_rcvd() that will not
4897 * lock until it KNOWs it MUST send a WUP-SACK.
4898 *
4899 */
4900 freed_so_far = stcb->freed_by_sorcv_sincelast;
4901 stcb->freed_by_sorcv_sincelast = 0;
4902 }
4903 }
4828 control->some_taken = 1;
4829 if (hold_sblock) {
4830 SOCKBUF_UNLOCK(&so->so_rcv);
4831 hold_sblock = 0;
4832 }
4833 stcb = control->stcb;
4834 if (stcb) {
4835 if ((stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) &&

--- 20 unchanged lines hidden (view full) ---

4856 * will go to the sctp_user_rcvd() that will not
4857 * lock until it KNOWs it MUST send a WUP-SACK.
4858 *
4859 */
4860 freed_so_far = stcb->freed_by_sorcv_sincelast;
4861 stcb->freed_by_sorcv_sincelast = 0;
4862 }
4863 }
4864 if (stcb && control->do_not_ref_stcb == 0) {
4865 stcb->asoc.strmin[control->sinfo_stream].delivery_started = 1;
4866 }
4904 /* First lets get off the sinfo and sockaddr info */
4905 if ((sinfo) && filling_sinfo) {
4906 memcpy(sinfo, control, sizeof(struct sctp_nonpad_sndrcvinfo));
4907 nxt = TAILQ_NEXT(control, next);
4908 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) {
4909 struct sctp_extrcvinfo *s_extra;
4910
4911 s_extra = (struct sctp_extrcvinfo *)sinfo;

--- 853 unchanged lines hidden ---
4867 /* First lets get off the sinfo and sockaddr info */
4868 if ((sinfo) && filling_sinfo) {
4869 memcpy(sinfo, control, sizeof(struct sctp_nonpad_sndrcvinfo));
4870 nxt = TAILQ_NEXT(control, next);
4871 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) {
4872 struct sctp_extrcvinfo *s_extra;
4873
4874 s_extra = (struct sctp_extrcvinfo *)sinfo;

--- 853 unchanged lines hidden ---