Deleted Added
full compact
sctputil.c (171440) sctputil.c (171477)
1/*-
2 * Copyright (c) 2001-2007, by 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, by 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 171440 2007-07-14 09:36:28Z rrs $");
34__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 171477 2007-07-17 20:58:26Z 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>

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

913 asoc->peer_vtag_nonce = sctp_select_a_tag(m);
914 asoc->vrf_id = vrf_id;
915
916 if (sctp_is_feature_on(m, SCTP_PCB_FLAGS_DONOT_HEARTBEAT))
917 asoc->hb_is_disabled = 1;
918 else
919 asoc->hb_is_disabled = 0;
920
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>

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

913 asoc->peer_vtag_nonce = sctp_select_a_tag(m);
914 asoc->vrf_id = vrf_id;
915
916 if (sctp_is_feature_on(m, SCTP_PCB_FLAGS_DONOT_HEARTBEAT))
917 asoc->hb_is_disabled = 1;
918 else
919 asoc->hb_is_disabled = 0;
920
921#ifdef SCTP_ASOCLOG_OF_TSNS
922 asoc->tsn_in_at = 0;
923 asoc->tsn_out_at = 0;
924 asoc->tsn_in_wrapped = 0;
925 asoc->tsn_out_wrapped = 0;
926 asoc->cumack_log_at = 0;
927#endif
928#ifdef SCTP_FS_SPEC_LOG
929 asoc->fs_index = 0;
930#endif
921 asoc->refcnt = 0;
922 asoc->assoc_up_sent = 0;
923 asoc->assoc_id = asoc->my_vtag;
924 asoc->asconf_seq_out = asoc->str_reset_seq_out = asoc->init_seq_number = asoc->sending_seq =
925 sctp_select_initial_TSN(&m->sctp_ep);
926 /* we are optimisitic here */
927 asoc->peer_supports_pktdrop = 1;
928

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

2560/*
2561 * given an association and starting time of the current RTT period return
2562 * RTO in number of msecs net should point to the current network
2563 */
2564uint32_t
2565sctp_calculate_rto(struct sctp_tcb *stcb,
2566 struct sctp_association *asoc,
2567 struct sctp_nets *net,
931 asoc->refcnt = 0;
932 asoc->assoc_up_sent = 0;
933 asoc->assoc_id = asoc->my_vtag;
934 asoc->asconf_seq_out = asoc->str_reset_seq_out = asoc->init_seq_number = asoc->sending_seq =
935 sctp_select_initial_TSN(&m->sctp_ep);
936 /* we are optimisitic here */
937 asoc->peer_supports_pktdrop = 1;
938

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

2570/*
2571 * given an association and starting time of the current RTT period return
2572 * RTO in number of msecs net should point to the current network
2573 */
2574uint32_t
2575sctp_calculate_rto(struct sctp_tcb *stcb,
2576 struct sctp_association *asoc,
2577 struct sctp_nets *net,
2568 struct timeval *old)
2578 struct timeval *told,
2579 int safe)
2569{
2580{
2570 /*
2581 /*-
2571 * given an association and the starting time of the current RTT
2572 * period (in value1/value2) return RTO in number of msecs.
2573 */
2574 int calc_time = 0;
2575 int o_calctime;
2576 uint32_t new_rto = 0;
2577 int first_measure = 0;
2582 * given an association and the starting time of the current RTT
2583 * period (in value1/value2) return RTO in number of msecs.
2584 */
2585 int calc_time = 0;
2586 int o_calctime;
2587 uint32_t new_rto = 0;
2588 int first_measure = 0;
2578 struct timeval now;
2589 struct timeval now, then, *old;
2579
2590
2591 /* Copy it out for sparc64 */
2592 if (safe == sctp_align_unsafe_makecopy) {
2593 old = &then;
2594 memcpy(&then, told, sizeof(struct timeval));
2595 } else if (safe == sctp_align_safe_nocopy) {
2596 old = told;
2597 } else {
2598 /* error */
2599 SCTP_PRINTF("Huh, bad rto calc call\n");
2600 return (0);
2601 }
2580 /************************/
2581 /* 1. calculate new RTT */
2582 /************************/
2583 /* get the current time */
2584 (void)SCTP_GETTIME_TIMEVAL(&now);
2585 /* compute the RTT value */
2586 if ((u_long)now.tv_sec > (u_long)old->tv_sec) {
2587 calc_time = ((u_long)now.tv_sec - (u_long)old->tv_sec) * 1000;

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

3645 }
3646 }
3647}
3648
3649#ifdef SCTP_ASOCLOG_OF_TSNS
3650void
3651sctp_print_out_track_log(struct sctp_tcb *stcb)
3652{
2602 /************************/
2603 /* 1. calculate new RTT */
2604 /************************/
2605 /* get the current time */
2606 (void)SCTP_GETTIME_TIMEVAL(&now);
2607 /* compute the RTT value */
2608 if ((u_long)now.tv_sec > (u_long)old->tv_sec) {
2609 calc_time = ((u_long)now.tv_sec - (u_long)old->tv_sec) * 1000;

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

3667 }
3668 }
3669}
3670
3671#ifdef SCTP_ASOCLOG_OF_TSNS
3672void
3673sctp_print_out_track_log(struct sctp_tcb *stcb)
3674{
3675#ifdef NOSIY_PRINTS
3653 int i;
3654
3655 SCTP_PRINTF("Last ep reason:%x\n", stcb->sctp_ep->last_abort_code);
3656 SCTP_PRINTF("IN bound TSN log-aaa\n");
3657 if ((stcb->asoc.tsn_in_at == 0) && (stcb->asoc.tsn_in_wrapped == 0)) {
3658 SCTP_PRINTF("None rcvd\n");
3659 goto none_in;
3660 }

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

3699 SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
3700 stcb->asoc.out_tsnlog[i].tsn,
3701 stcb->asoc.out_tsnlog[i].strm,
3702 stcb->asoc.out_tsnlog[i].seq,
3703 stcb->asoc.out_tsnlog[i].flgs,
3704 stcb->asoc.out_tsnlog[i].sz);
3705 }
3706 }
3676 int i;
3677
3678 SCTP_PRINTF("Last ep reason:%x\n", stcb->sctp_ep->last_abort_code);
3679 SCTP_PRINTF("IN bound TSN log-aaa\n");
3680 if ((stcb->asoc.tsn_in_at == 0) && (stcb->asoc.tsn_in_wrapped == 0)) {
3681 SCTP_PRINTF("None rcvd\n");
3682 goto none_in;
3683 }

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

3722 SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
3723 stcb->asoc.out_tsnlog[i].tsn,
3724 stcb->asoc.out_tsnlog[i].strm,
3725 stcb->asoc.out_tsnlog[i].seq,
3726 stcb->asoc.out_tsnlog[i].flgs,
3727 stcb->asoc.out_tsnlog[i].sz);
3728 }
3729 }
3730#endif
3707}
3708
3709#endif
3710
3711void
3712sctp_abort_an_association(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
3713 int error, struct mbuf *op_err)
3714{

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

4227#ifdef INVARIANTS
4228 panic("Nothing left to add?");
4229#else
4230 goto get_out;
4231#endif
4232 }
4233 tail = m;
4234 }
3731}
3732
3733#endif
3734
3735void
3736sctp_abort_an_association(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
3737 int error, struct mbuf *op_err)
3738{

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

4251#ifdef INVARIANTS
4252 panic("Nothing left to add?");
4253#else
4254 goto get_out;
4255#endif
4256 }
4257 tail = m;
4258 }
4235 if (end) {
4236 /* message is complete */
4237 if (stcb && (control == stcb->asoc.control_pdapi)) {
4238 stcb->asoc.control_pdapi = NULL;
4239 }
4240 control->held_length = 0;
4241 control->end_added = 1;
4242 }
4243 atomic_add_int(&control->length, len);
4244 if (control->tail_mbuf) {
4245 /* append */
4246 SCTP_BUF_NEXT(control->tail_mbuf) = m;
4247 control->tail_mbuf = tail;
4248 } else {
4249 /* nothing there */
4250#ifdef INVARIANTS
4251 if (control->data != NULL) {
4252 panic("This should NOT happen");
4253 }
4254#endif
4255 control->data = m;
4256 control->tail_mbuf = tail;
4257 }
4259 if (control->tail_mbuf) {
4260 /* append */
4261 SCTP_BUF_NEXT(control->tail_mbuf) = m;
4262 control->tail_mbuf = tail;
4263 } else {
4264 /* nothing there */
4265#ifdef INVARIANTS
4266 if (control->data != NULL) {
4267 panic("This should NOT happen");
4268 }
4269#endif
4270 control->data = m;
4271 control->tail_mbuf = tail;
4272 }
4273 atomic_add_int(&control->length, len);
4274 if (end) {
4275 /* message is complete */
4276 if (stcb && (control == stcb->asoc.control_pdapi)) {
4277 stcb->asoc.control_pdapi = NULL;
4278 }
4279 control->held_length = 0;
4280 control->end_added = 1;
4281 }
4258 if (stcb == NULL) {
4259 control->do_not_ref_stcb = 1;
4260 }
4261 /*
4262 * When we are appending in partial delivery, the cum-ack is used
4263 * for the actual pd-api highest tsn on this mbuf. The true cum-ack
4264 * is populated in the outbound sinfo structure from the true cumack
4265 * if the association exists...

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

4651 int block_allowed = 1;
4652 uint32_t freed_so_far = 0;
4653 int copied_so_far = 0;
4654 int in_eeor_mode = 0;
4655 int no_rcv_needed = 0;
4656 uint32_t rwnd_req = 0;
4657 int hold_sblock = 0;
4658 int hold_rlock = 0;
4282 if (stcb == NULL) {
4283 control->do_not_ref_stcb = 1;
4284 }
4285 /*
4286 * When we are appending in partial delivery, the cum-ack is used
4287 * for the actual pd-api highest tsn on this mbuf. The true cum-ack
4288 * is populated in the outbound sinfo structure from the true cumack
4289 * if the association exists...

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

4675 int block_allowed = 1;
4676 uint32_t freed_so_far = 0;
4677 int copied_so_far = 0;
4678 int in_eeor_mode = 0;
4679 int no_rcv_needed = 0;
4680 uint32_t rwnd_req = 0;
4681 int hold_sblock = 0;
4682 int hold_rlock = 0;
4659 int alen = 0;
4660 int slen = 0;
4661 uint32_t held_length = 0;
4662 int sockbuf_lock = 0;
4663
4664 if (uio == NULL) {
4665 return (EINVAL);
4666 }
4667 if (msg_flags) {

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

5054 * mask off the high bits, we keep the actual chunk bits in
5055 * there.
5056 */
5057 sinfo->sinfo_flags &= 0x00ff;
5058 if ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) {
5059 sinfo->sinfo_flags |= SCTP_UNORDERED;
5060 }
5061 }
4683 int slen = 0;
4684 uint32_t held_length = 0;
4685 int sockbuf_lock = 0;
4686
4687 if (uio == NULL) {
4688 return (EINVAL);
4689 }
4690 if (msg_flags) {

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

5077 * mask off the high bits, we keep the actual chunk bits in
5078 * there.
5079 */
5080 sinfo->sinfo_flags &= 0x00ff;
5081 if ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) {
5082 sinfo->sinfo_flags |= SCTP_UNORDERED;
5083 }
5084 }
5085#ifdef SCTP_ASOCLOG_OF_TSNS
5086 {
5087 int index, newindex;
5088 struct sctp_pcbtsn_rlog *entry;
5089
5090 do {
5091 index = inp->readlog_index;
5092 newindex = index + 1;
5093 if (newindex >= SCTP_READ_LOG_SIZE) {
5094 newindex = 0;
5095 }
5096 } while (atomic_cmpset_int(&inp->readlog_index, index, newindex) == 0);
5097 entry = &inp->readlog[index];
5098 entry->vtag = control->sinfo_assoc_id;
5099 entry->strm = control->sinfo_stream;
5100 entry->seq = control->sinfo_ssn;
5101 entry->sz = control->length;
5102 entry->flgs = control->sinfo_flags;
5103 }
5104#endif
5062 if (fromlen && from) {
5063 struct sockaddr *to;
5064
5065#ifdef INET
5066 cp_len = min(fromlen, control->whoFrom->ro._l_addr.sin.sin_len);
5067 memcpy(from, &control->whoFrom->ro._l_addr, cp_len);
5068 ((struct sockaddr_in *)from)->sin_port = control->port_from;
5069#else

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

5166 sctp_sbfree(control, stcb, &so->so_rcv, m);
5167 if (sctp_logging_level & SCTP_SB_LOGGING_ENABLE) {
5168 sctp_sblog(&so->so_rcv,
5169 control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
5170 }
5171 embuf = m;
5172 copied_so_far += cp_len;
5173 freed_so_far += cp_len;
5105 if (fromlen && from) {
5106 struct sockaddr *to;
5107
5108#ifdef INET
5109 cp_len = min(fromlen, control->whoFrom->ro._l_addr.sin.sin_len);
5110 memcpy(from, &control->whoFrom->ro._l_addr, cp_len);
5111 ((struct sockaddr_in *)from)->sin_port = control->port_from;
5112#else

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

5209 sctp_sbfree(control, stcb, &so->so_rcv, m);
5210 if (sctp_logging_level & SCTP_SB_LOGGING_ENABLE) {
5211 sctp_sblog(&so->so_rcv,
5212 control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
5213 }
5214 embuf = m;
5215 copied_so_far += cp_len;
5216 freed_so_far += cp_len;
5174 alen = atomic_fetchadd_int(&control->length, -(cp_len));
5175 if (alen < cp_len) {
5176 panic("Control length goes negative?");
5177 }
5217 atomic_subtract_int(&control->length, cp_len);
5178 control->data = sctp_m_free(m);
5179 m = control->data;
5180 /*
5181 * been through it all, must hold sb
5182 * lock ok to null tail
5183 */
5184 if (control->data == NULL) {
5185#ifdef INVARIANTS

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

5223 }
5224 copied_so_far += cp_len;
5225 embuf = m;
5226 freed_so_far += cp_len;
5227 if (sctp_logging_level & SCTP_SB_LOGGING_ENABLE) {
5228 sctp_sblog(&so->so_rcv, control->do_not_ref_stcb ? NULL : stcb,
5229 SCTP_LOG_SBRESULT, 0);
5230 }
5218 control->data = sctp_m_free(m);
5219 m = control->data;
5220 /*
5221 * been through it all, must hold sb
5222 * lock ok to null tail
5223 */
5224 if (control->data == NULL) {
5225#ifdef INVARIANTS

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

5263 }
5264 copied_so_far += cp_len;
5265 embuf = m;
5266 freed_so_far += cp_len;
5267 if (sctp_logging_level & SCTP_SB_LOGGING_ENABLE) {
5268 sctp_sblog(&so->so_rcv, control->do_not_ref_stcb ? NULL : stcb,
5269 SCTP_LOG_SBRESULT, 0);
5270 }
5231 alen = atomic_fetchadd_int(&control->length, -(cp_len));
5232 if (alen < cp_len) {
5233 panic("Control length goes negative2?");
5234 }
5271 atomic_subtract_int(&control->length, cp_len);
5235 } else {
5236 copied_so_far += cp_len;
5237 }
5238 }
5239 if ((out_flags & MSG_EOR) || (uio->uio_resid == 0)) {
5240 break;
5241 }
5242 if (((stcb) && (in_flags & MSG_PEEK) == 0) &&

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

5890 }
5891 }
5892 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
5893 if (p == NULL) {
5894 /* Can't get proc for Net/Open BSD */
5895 *error = EINVAL;
5896 return;
5897 }
5272 } else {
5273 copied_so_far += cp_len;
5274 }
5275 }
5276 if ((out_flags & MSG_EOR) || (uio->uio_resid == 0)) {
5277 break;
5278 }
5279 if (((stcb) && (in_flags & MSG_PEEK) == 0) &&

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

5927 }
5928 }
5929 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
5930 if (p == NULL) {
5931 /* Can't get proc for Net/Open BSD */
5932 *error = EINVAL;
5933 return;
5934 }
5898 *error = sctp_inpcb_bind(so, addr_touse, NULL, p);
5935 *error = sctp_inpcb_bind(so, addr_touse, p);
5899 return;
5900 }
5901 /*
5902 * No locks required here since bind and mgmt_ep_sa all do their own
5903 * locking. If we do something for the FIX: below we may need to
5904 * lock in that case.
5905 */
5906 if (assoc_id == 0) {

--- 115 unchanged lines hidden ---
5936 return;
5937 }
5938 /*
5939 * No locks required here since bind and mgmt_ep_sa all do their own
5940 * locking. If we do something for the FIX: below we may need to
5941 * lock in that case.
5942 */
5943 if (assoc_id == 0) {

--- 115 unchanged lines hidden ---