From b9ef107414848cd42bfb431cc80e5187bdfb53fa Mon Sep 17 00:00:00 2001 From: tuexen Date: Tue, 27 Dec 2011 10:16:24 +0000 Subject: Address issues found by clang. While there, fix also some style issues. MFC after: 3 months. --- sys/netinet/sctp_asconf.c | 46 ++++++++--------- sys/netinet/sctp_auth.c | 2 - sys/netinet/sctp_cc_functions.c | 35 +++++++------ sys/netinet/sctp_constants.h | 4 +- sys/netinet/sctp_indata.c | 32 +++++------- sys/netinet/sctp_input.c | 59 ++++++++++------------ sys/netinet/sctp_output.c | 107 +++++++++++++++------------------------- sys/netinet/sctp_pcb.c | 36 +++++--------- sys/netinet/sctp_ss_functions.c | 2 +- sys/netinet/sctp_sysctl.c | 20 ++++---- sys/netinet/sctp_timer.c | 45 +++++++++-------- sys/netinet/sctp_usrreq.c | 61 ++++++++++------------- sys/netinet/sctp_var.h | 13 ++--- sys/netinet/sctputil.c | 72 ++++++++++++++------------- 14 files changed, 239 insertions(+), 295 deletions(-) (limited to 'sys/netinet') diff --git a/sys/netinet/sctp_asconf.c b/sys/netinet/sctp_asconf.c index 73371cc..ec030d5 100644 --- a/sys/netinet/sctp_asconf.c +++ b/sys/netinet/sctp_asconf.c @@ -138,7 +138,7 @@ sctp_asconf_success_response(uint32_t id) if (m_reply == NULL) { SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_success_response: couldn't get mbuf!\n"); - return NULL; + return (NULL); } aph = mtod(m_reply, struct sctp_asconf_paramhdr *); aph->correlation_id = id; @@ -147,7 +147,7 @@ sctp_asconf_success_response(uint32_t id) SCTP_BUF_LEN(m_reply) = aph->ph.param_length; aph->ph.param_length = htons(aph->ph.param_length); - return m_reply; + return (m_reply); } static struct mbuf * @@ -166,7 +166,7 @@ sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, if (m_reply == NULL) { SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_error_response: couldn't get mbuf!\n"); - return NULL; + return (NULL); } aph = mtod(m_reply, struct sctp_asconf_paramhdr *); error = (struct sctp_error_cause *)(aph + 1); @@ -183,7 +183,7 @@ sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, "asconf_error_response: tlv_length (%xh) too big\n", tlv_length); sctp_m_freem(m_reply); /* discard */ - return NULL; + return (NULL); } if (error_tlv != NULL) { tlv = (uint8_t *) (error + 1); @@ -193,7 +193,7 @@ sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, error->length = htons(error->length); aph->ph.param_length = htons(aph->ph.param_length); - return m_reply; + return (m_reply); } static struct mbuf * @@ -231,7 +231,7 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, case SCTP_IPV4_ADDRESS: if (param_length != sizeof(struct sctp_ipv4addr_param)) { /* invalid param size */ - return NULL; + return (NULL); } v4addr = (struct sctp_ipv4addr_param *)ph; sin = (struct sockaddr_in *)&sa_store; @@ -254,7 +254,7 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, case SCTP_IPV6_ADDRESS: if (param_length != sizeof(struct sctp_ipv6addr_param)) { /* invalid param size */ - return NULL; + return (NULL); } v6addr = (struct sctp_ipv6addr_param *)ph; sin6 = (struct sockaddr_in6 *)&sa_store; @@ -277,7 +277,7 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, m_reply = sctp_asconf_error_response(aph->correlation_id, SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, aparam_length); - return m_reply; + return (m_reply); } /* end switch */ /* if 0.0.0.0/::0, add the source address instead */ @@ -314,7 +314,7 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); } } - return m_reply; + return (m_reply); } static int @@ -326,7 +326,7 @@ sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src) src_net = sctp_findnet(stcb, src); if (src_net == NULL) { /* not found */ - return -1; + return (-1); } /* delete all destination addresses except the source */ TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { @@ -342,7 +342,7 @@ sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src) (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED); } } - return 0; + return (0); } static struct mbuf * @@ -382,7 +382,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, case SCTP_IPV4_ADDRESS: if (param_length != sizeof(struct sctp_ipv4addr_param)) { /* invalid param size */ - return NULL; + return (NULL); } v4addr = (struct sctp_ipv4addr_param *)ph; sin = (struct sockaddr_in *)&sa_store; @@ -402,7 +402,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, case SCTP_IPV6_ADDRESS: if (param_length != sizeof(struct sctp_ipv6addr_param)) { /* invalid param size */ - return NULL; + return (NULL); } v6addr = (struct sctp_ipv6addr_param *)ph; sin6 = (struct sockaddr_in6 *)&sa_store; @@ -423,7 +423,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, m_reply = sctp_asconf_error_response(aph->correlation_id, SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, aparam_length); - return m_reply; + return (m_reply); } /* make sure the source address is not being deleted */ @@ -433,7 +433,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, m_reply = sctp_asconf_error_response(aph->correlation_id, SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph, aparam_length); - return m_reply; + return (m_reply); } /* if deleting 0.0.0.0/::0, delete all addresses except src addr */ if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { @@ -452,7 +452,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, m_reply = sctp_asconf_success_response(aph->correlation_id); } - return m_reply; + return (m_reply); } /* delete the address */ result = sctp_del_remote_addr(stcb, sa); @@ -474,7 +474,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, /* notify upper layer */ sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); } - return m_reply; + return (m_reply); } static struct mbuf * @@ -511,7 +511,7 @@ sctp_process_asconf_set_primary(struct mbuf *m, case SCTP_IPV4_ADDRESS: if (param_length != sizeof(struct sctp_ipv4addr_param)) { /* invalid param size */ - return NULL; + return (NULL); } v4addr = (struct sctp_ipv4addr_param *)ph; sin = (struct sockaddr_in *)&sa_store; @@ -529,7 +529,7 @@ sctp_process_asconf_set_primary(struct mbuf *m, case SCTP_IPV6_ADDRESS: if (param_length != sizeof(struct sctp_ipv6addr_param)) { /* invalid param size */ - return NULL; + return (NULL); } v6addr = (struct sctp_ipv6addr_param *)ph; sin6 = (struct sockaddr_in6 *)&sa_store; @@ -548,7 +548,7 @@ sctp_process_asconf_set_primary(struct mbuf *m, m_reply = sctp_asconf_error_response(aph->correlation_id, SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, aparam_length); - return m_reply; + return (m_reply); } /* if 0.0.0.0/::0, use the source address instead */ @@ -620,7 +620,7 @@ sctp_process_asconf_set_primary(struct mbuf *m, aparam_length); } - return m_reply; + return (m_reply); } /* @@ -2530,9 +2530,9 @@ sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa) */ if (add_cnt > del_cnt || (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) { - return 1; + return (1); } - return 0; + return (0); } static struct sockaddr * diff --git a/sys/netinet/sctp_auth.c b/sys/netinet/sctp_auth.c index 2d4ab22..b5bae4d 100644 --- a/sys/netinet/sctp_auth.c +++ b/sys/netinet/sctp_auth.c @@ -469,7 +469,6 @@ sctp_compute_hashkey(sctp_key_t * key1, sctp_key_t * key2, sctp_key_t * shared) } if (sctp_get_keylen(key2)) { bcopy(key2->key, key_ptr, key2->keylen); - key_ptr += key2->keylen; } } else { /* key is shared + key2 + key1 */ @@ -483,7 +482,6 @@ sctp_compute_hashkey(sctp_key_t * key1, sctp_key_t * key2, sctp_key_t * shared) } if (sctp_get_keylen(key1)) { bcopy(key1->key, key_ptr, key1->keylen); - key_ptr += key1->keylen; } } return (new_key); diff --git a/sys/netinet/sctp_cc_functions.c b/sys/netinet/sctp_cc_functions.c index 52b92b4..cd0cbba 100644 --- a/sys/netinet/sctp_cc_functions.c +++ b/sys/netinet/sctp_cc_functions.c @@ -80,7 +80,6 @@ sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net) } } net->ssthresh = assoc->peers_rwnd; - SDT_PROBE(sctp, cwnd, net, init, stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, 0, net->cwnd); @@ -339,7 +338,6 @@ cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), net->flight_size, probepoint); - if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) { if (net->cc_mod.rtcc.last_step_state == 5) net->cc_mod.rtcc.step_cnt++; @@ -389,7 +387,6 @@ cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint6 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), net->flight_size, probepoint); - if (net->cc_mod.rtcc.ret_from_eq) { /* * Switch over to CA if we are less @@ -408,7 +405,6 @@ cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint6 ((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt), net->flight_size, probepoint); - /* Someone else - fight for more? */ if (net->cc_mod.rtcc.steady_step) { oth = net->cc_mod.rtcc.vol_reduce; @@ -553,7 +549,8 @@ cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint6 static int cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) { - uint64_t bw_offset, rtt_offset, rtt, vtag, probepoint; + uint64_t bw_offset, rtt_offset; + uint64_t probepoint, rtt, vtag; uint64_t bytes_for_this_rtt, inst_bw; uint64_t div, inst_off; int bw_shift; @@ -619,15 +616,15 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) inst_ind = SCTP_INST_NEUTRAL; probepoint |= ((0xb << 16) | inst_ind); } else { + inst_ind = net->cc_mod.rtcc.last_inst_ind; inst_bw = bytes_for_this_rtt / (uint64_t) (net->rtt); /* Can't determine do not change */ - inst_ind = net->cc_mod.rtcc.last_inst_ind; probepoint |= ((0xc << 16) | inst_ind); } } else { + inst_ind = net->cc_mod.rtcc.last_inst_ind; inst_bw = bytes_for_this_rtt; /* Can't determine do not change */ - inst_ind = net->cc_mod.rtcc.last_inst_ind; probepoint |= ((0xd << 16) | inst_ind); } SDT_PROBE(sctp, cwnd, net, rttvar, @@ -702,15 +699,18 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, } } } - if (t_ucwnd_sbw == 0) { - t_ucwnd_sbw = 1; - } if (t_path_mptcp > 0) { mptcp_like_alpha = max_path / (t_path_mptcp * t_path_mptcp); } else { mptcp_like_alpha = 1; } } + if (t_ssthresh == 0) { + t_ssthresh = 1; + } + if (t_ucwnd_sbw == 0) { + t_ucwnd_sbw = 1; + } /******************************/ /* update cwnd and Early FR */ /******************************/ @@ -1012,6 +1012,9 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) t_ucwnd_sbw += (uint64_t) lnet->cwnd / (uint64_t) srtt; } } + if (t_ssthresh < 1) { + t_ssthresh = 1; + } if (t_ucwnd_sbw < 1) { t_ucwnd_sbw = 1; } @@ -1841,19 +1844,19 @@ static int use_bandwidth_switch = 1; static inline int between(uint32_t seq1, uint32_t seq2, uint32_t seq3) { - return seq3 - seq2 >= seq1 - seq2; + return (seq3 - seq2 >= seq1 - seq2); } static inline uint32_t htcp_cong_time(struct htcp *ca) { - return sctp_get_tick_count() - ca->last_cong; + return (sctp_get_tick_count() - ca->last_cong); } static inline uint32_t htcp_ccount(struct htcp *ca) { - return htcp_cong_time(ca) / ca->minRTT; + return (htcp_cong_time(ca) / ca->minRTT); } static inline void @@ -1873,7 +1876,7 @@ htcp_cwnd_undo(struct sctp_tcb *stcb, struct sctp_nets *net) net->cc_mod.htcp_ca.last_cong = net->cc_mod.htcp_ca.undo_last_cong; net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.undo_maxRTT; net->cc_mod.htcp_ca.old_maxB = net->cc_mod.htcp_ca.undo_old_maxB; - return max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu); + return (max(net->cwnd, ((net->ssthresh / net->mtu << 7) / net->cc_mod.htcp_ca.beta) * net->mtu)); } #endif @@ -2017,7 +2020,7 @@ static uint32_t htcp_recalc_ssthresh(struct sctp_nets *net) { htcp_param_update(net); - return max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu); + return (max(((net->cwnd / net->mtu * net->cc_mod.htcp_ca.beta) >> 7) * net->mtu, 2U * net->mtu)); } static void @@ -2087,7 +2090,7 @@ htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net) static uint32_t htcp_min_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net) { - return net->ssthresh; + return (net->ssthresh); } #endif diff --git a/sys/netinet/sctp_constants.h b/sys/netinet/sctp_constants.h index 6d475fc..55e3be9 100644 --- a/sys/netinet/sctp_constants.h +++ b/sys/netinet/sctp_constants.h @@ -396,7 +396,7 @@ __FBSDID("$FreeBSD$"); /* SCTP chunk types are moved sctp.h for application (NAT, FW) use */ /* align to 32-bit sizes */ -#define SCTP_SIZE32(x) ((((x)+3) >> 2) << 2) +#define SCTP_SIZE32(x) ((((x) + 3) >> 2) << 2) #define IS_SCTP_CONTROL(a) ((a)->chunk_type != SCTP_DATA) #define IS_SCTP_DATA(a) ((a)->chunk_type == SCTP_DATA) @@ -933,7 +933,7 @@ __FBSDID("$FreeBSD$"); } else { \ gap = (MAX_TSN - mapping_tsn) + tsn + 1; \ } \ - } while(0) + } while (0) #define SCTP_RETRAN_DONE -1 diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c index 97bb608..54372ac 100644 --- a/sys/netinet/sctp_indata.c +++ b/sys/netinet/sctp_indata.c @@ -845,7 +845,7 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, struct sctp_tmit_chunk *chk, int *abort_flag) { struct mbuf *oper; - uint32_t cum_ackp1, last_tsn, prev_tsn, post_tsn; + uint32_t cum_ackp1, prev_tsn, post_tsn; struct sctp_tmit_chunk *at, *prev, *next; prev = next = NULL; @@ -1032,7 +1032,6 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); return; } else { - last_tsn = at->rec.data.TSN_seq; prev = at; if (TAILQ_NEXT(at, sctp_next) == NULL) { /* @@ -1698,12 +1697,10 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { struct mbuf *mat; - mat = dmbuf; - while (mat) { + for (mat = dmbuf; mat; mat = SCTP_BUF_NEXT(mat)) { if (SCTP_BUF_IS_EXTENDED(mat)) { sctp_log_mb(mat, SCTP_MBUF_ICOPY); } - mat = SCTP_BUF_NEXT(mat); } } #endif @@ -1724,10 +1721,8 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, struct mbuf *lat; l_len = 0; - lat = dmbuf; - while (lat) { + for (lat = dmbuf; lat; lat = SCTP_BUF_NEXT(lat)) { l_len += SCTP_BUF_LEN(lat); - lat = SCTP_BUF_NEXT(lat); } } if (l_len > the_len) { @@ -1804,15 +1799,10 @@ failed_express_del: if (tsn == (control->sinfo_tsn + 1)) { /* Yep, we can add it on */ int end = 0; - uint32_t cumack; if (chunk_flags & SCTP_DATA_LAST_FRAG) { end = 1; } - cumack = asoc->cumulative_tsn; - if ((cumack + 1) == tsn) - cumack = tsn; - if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end, tsn, &stcb->sctp_socket->so_rcv)) { @@ -2634,7 +2624,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, if (length - *offset < chk_length) { /* all done, mutulated chunk */ stop_proc = 1; - break; + continue; } if (ch->ch.chunk_type == SCTP_DATA) { if ((size_t)chk_length < sizeof(struct sctp_data_chunk) + 1) { @@ -2690,7 +2680,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, * drop rep space left. */ stop_proc = 1; - break; + continue; } } else { /* not a data chunk in the data region */ @@ -2698,7 +2688,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, case SCTP_INITIATION: case SCTP_INITIATION_ACK: case SCTP_SELECTIVE_ACK: - case SCTP_NR_SELECTIVE_ACK: /* EY */ + case SCTP_NR_SELECTIVE_ACK: case SCTP_HEARTBEAT_REQUEST: case SCTP_HEARTBEAT_ACK: case SCTP_ABORT_ASSOCIATION: @@ -2772,7 +2762,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, } /* else skip this bad chunk and * continue... */ break; - }; /* switch of chunk type */ + } /* switch of chunk type */ } *offset += SCTP_SIZE32(chk_length); if ((*offset >= length) || stop_proc) { @@ -2785,10 +2775,9 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, if (ch == NULL) { *offset = length; stop_proc = 1; - break; - + continue; } - } /* while */ + } if (break_flag) { /* * we need to report rwnd overrun drops. @@ -3598,7 +3587,8 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, * this guy had a RTO calculation pending on * it, cancel it */ - if (tp1->whoTo->rto_needed == 0) { + if ((tp1->whoTo != NULL) && + (tp1->whoTo->rto_needed == 0)) { tp1->whoTo->rto_needed = 1; } tp1->do_rtt = 0; diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c index be70b10..cd5c76a 100644 --- a/sys/netinet/sctp_input.c +++ b/sys/netinet/sctp_input.c @@ -1418,7 +1418,6 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, struct sctp_nets *net; struct mbuf *op_err; struct sctp_paramhdr *ph; - int chk_length; int init_offset, initack_offset, i; int retval; int spec_flag = 0; @@ -1468,7 +1467,6 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, /* could not pull a INIT chunk in cookie */ return (NULL); } - chk_length = ntohs(init_cp->ch.chunk_length); if (init_cp->ch.chunk_type != SCTP_INITIATION) { return (NULL); } @@ -1476,7 +1474,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, * find and validate the INIT-ACK chunk in the cookie (my info) the * INIT-ACK follows the INIT chunk */ - initack_offset = init_offset + SCTP_SIZE32(chk_length); + initack_offset = init_offset + SCTP_SIZE32(ntohs(init_cp->ch.chunk_length)); initack_cp = (struct sctp_init_ack_chunk *) sctp_m_getptr(m, initack_offset, sizeof(struct sctp_init_ack_chunk), (uint8_t *) & initack_buf); @@ -1484,7 +1482,6 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, /* could not pull INIT-ACK chunk in cookie */ return (NULL); } - chk_length = ntohs(initack_cp->ch.chunk_length); if (initack_cp->ch.chunk_type != SCTP_INITIATION_ACK) { return (NULL); } @@ -1984,11 +1981,9 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, struct sockaddr_storage sa_store; struct sockaddr *initack_src = (struct sockaddr *)&sa_store; struct sctp_association *asoc; - int chk_length; int init_offset, initack_offset, initack_limit; int retval; int error = 0; - uint32_t old_tag; uint8_t auth_chunk_buf[SCTP_PARAM_BUFFER_SIZE]; #ifdef INET @@ -2020,12 +2015,11 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, "process_cookie_new: could not pull INIT chunk hdr\n"); return (NULL); } - chk_length = ntohs(init_cp->ch.chunk_length); if (init_cp->ch.chunk_type != SCTP_INITIATION) { SCTPDBG(SCTP_DEBUG_INPUT1, "HUH? process_cookie_new: could not find INIT chunk!\n"); return (NULL); } - initack_offset = init_offset + SCTP_SIZE32(chk_length); + initack_offset = init_offset + SCTP_SIZE32(ntohs(init_cp->ch.chunk_length)); /* * find and validate the INIT-ACK chunk in the cookie (my info) the * INIT-ACK follows the INIT chunk @@ -2038,7 +2032,6 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, SCTPDBG(SCTP_DEBUG_INPUT1, "process_cookie_new: could not pull INIT-ACK chunk hdr\n"); return (NULL); } - chk_length = ntohs(initack_cp->ch.chunk_length); if (initack_cp->ch.chunk_type != SCTP_INITIATION_ACK) { return (NULL); } @@ -2115,7 +2108,6 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, return (NULL); } /* process the INIT-ACK info (my info) */ - old_tag = asoc->my_vtag; asoc->my_vtag = ntohl(initack_cp->init.initiate_tag); asoc->my_rwnd = ntohl(initack_cp->init.a_rwnd); asoc->pre_open_streams = ntohs(initack_cp->init.num_outbound_streams); @@ -2702,10 +2694,9 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset, */ if (netl == NULL) { /* TSNH! Huh, why do I need to add this address here? */ - int ret; - - ret = sctp_add_remote_addr(*stcb, to, NULL, SCTP_DONOT_SETSCOPE, - SCTP_IN_COOKIE_PROC); + if (sctp_add_remote_addr(*stcb, to, NULL, SCTP_DONOT_SETSCOPE, SCTP_IN_COOKIE_PROC)) { + return (NULL); + } netl = sctp_findnet(*stcb, to); } if (netl) { @@ -3003,7 +2994,7 @@ sctp_handle_ecn_echo(struct sctp_ecne_chunk *cp, struct sctp_nets *net; struct sctp_tmit_chunk *lchk; struct sctp_ecne_chunk bkup; - uint8_t override_bit = 0; + uint8_t override_bit; uint32_t tsn, window_data_tsn; int len; unsigned int pkt_cnt; @@ -3050,27 +3041,33 @@ sctp_handle_ecn_echo(struct sctp_ecne_chunk *cp, TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { if (tsn == net->last_cwr_tsn) { /* Found him, send it off */ - goto out; + break; } } - /* - * If we reach here, we need to send a special CWR that says - * hey, we did this a long time ago and you lost the - * response. - */ - net = TAILQ_FIRST(&stcb->asoc.nets); - override_bit = SCTP_CWR_REDUCE_OVERRIDE; + if (net == NULL) { + /* + * If we reach here, we need to send a special CWR + * that says hey, we did this a long time ago and + * you lost the response. + */ + net = TAILQ_FIRST(&stcb->asoc.nets); + if (net == NULL) { + /* TSNH */ + return; + } + override_bit = SCTP_CWR_REDUCE_OVERRIDE; + } else { + override_bit = 0; + } + } else { + override_bit = 0; } -out: if (SCTP_TSN_GT(tsn, net->cwr_window_tsn) && ((override_bit & SCTP_CWR_REDUCE_OVERRIDE) == 0)) { /* * JRS - Use the congestion control given in the pluggable * CC module */ - int ocwnd; - - ocwnd = net->cwnd; stcb->asoc.cc_functions.sctp_cwnd_update_after_ecn_echo(stcb, net, 0, pkt_cnt); /* * We reduce once every RTT. So we will only lower cwnd at @@ -5074,7 +5071,6 @@ process_control_chunks: } SCTPDBG(SCTP_DEBUG_INPUT3, "GAK, null buffer\n"); - auth_skipped = 0; *offset = length; return (NULL); } @@ -5697,7 +5693,8 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, */ } /* take care of ecn */ - if ((stcb->asoc.ecn_allowed == 1) && + if ((data_processed == 1) && + (stcb->asoc.ecn_allowed == 1) && ((ecn_bits & SCTP_CE_BITS) == SCTP_CE_BITS)) { /* Yep, we need to add a ECNE */ sctp_send_ecn_echo(stcb, net, high_tsn); @@ -5807,12 +5804,10 @@ sctp_input_with_port(struct mbuf *i_pak, int off, uint16_t port) #ifdef SCTP_MBUF_LOGGING /* Log in any input mbufs */ if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { - mat = m; - while (mat) { + for (mat = m; mat; mat = SCTP_BUF_NEXT(mat)) { if (SCTP_BUF_IS_EXTENDED(mat)) { sctp_log_mb(mat, SCTP_MBUF_INPUT); } - mat = SCTP_BUF_NEXT(mat); } } #endif diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c index 3032366..fc91e97 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -2156,23 +2156,20 @@ skip_count: } cnt++; } - if (cnt > SCTP_ADDRESS_LIMIT) { - limit_out = 1; - } /* * To get through a NAT we only list addresses if we have * more than one. That way if you just bind a single address * we let the source of the init dictate our address. */ if (cnt > 1) { + cnt = cnt_inits_to; LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { - cnt = 0; if (laddr->ifa == NULL) { continue; } - if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) + if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) { continue; - + } if (sctp_is_address_in_scope(laddr->ifa, scope->ipv4_addr_legal, scope->ipv6_addr_legal, @@ -3758,7 +3755,6 @@ sctp_add_cookie(struct mbuf *init, int init_offset, /* tack the INIT and then the INIT-ACK onto the chain */ cookie_sz = 0; - m_at = mret; for (m_at = mret; m_at; m_at = SCTP_BUF_NEXT(m_at)) { cookie_sz += SCTP_BUF_LEN(m_at); if (SCTP_BUF_NEXT(m_at) == NULL) { @@ -3766,7 +3762,6 @@ sctp_add_cookie(struct mbuf *init, int init_offset, break; } } - for (m_at = copy_init; m_at; m_at = SCTP_BUF_NEXT(m_at)) { cookie_sz += SCTP_BUF_LEN(m_at); if (SCTP_BUF_NEXT(m_at) == NULL) { @@ -3774,7 +3769,6 @@ sctp_add_cookie(struct mbuf *init, int init_offset, break; } } - for (m_at = copy_initack; m_at; m_at = SCTP_BUF_NEXT(m_at)) { cookie_sz += SCTP_BUF_LEN(m_at); if (SCTP_BUF_NEXT(m_at) == NULL) { @@ -4804,7 +4798,6 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked SCTP_BUF_LEN(m) += SCTP_SIZE32(p_len); } } - m_at = m; /* now the addresses */ { struct sctp_scoping scp; @@ -4813,9 +4806,10 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked * To optimize this we could put the scoping stuff into a * structure and remove the individual uint8's from the * assoc structure. Then we could just sifa in the address - * within the stcb.. but for now this is a quick hack to get + * within the stcb. But for now this is a quick hack to get * the address stuff teased apart. */ + scp.ipv4_addr_legal = stcb->asoc.ipv4_addr_legal; scp.ipv6_addr_legal = stcb->asoc.ipv6_addr_legal; scp.loopback_scope = stcb->asoc.loopback_scope; @@ -4823,7 +4817,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked scp.local_scope = stcb->asoc.local_scope; scp.site_scope = stcb->asoc.site_scope; - m_at = sctp_add_addresses_to_i_ia(inp, stcb, &scp, m_at, cnt_inits_to); + sctp_add_addresses_to_i_ia(inp, stcb, &scp, m, cnt_inits_to); } /* calulate the size and update pkt header and chunk header */ @@ -4853,7 +4847,6 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked sctp_m_freem(m); return; } - p_len += padval; } SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - calls lowlevel_output\n"); ret = sctp_lowlevel_chunk_output(inp, stcb, net, @@ -5074,7 +5067,6 @@ sctp_arethere_unrecognized_parameters(struct mbuf *in_initpkt, return (NULL); } m_copyback(op_err, err_at, plen, (caddr_t)phdr); - err_at += plen; } return (op_err); break; @@ -5317,6 +5309,7 @@ sctp_are_there_new_addresses(struct sctp_association *asoc, p4 = (struct sctp_ipv4addr_param *)phdr; sin4.sin_addr.s_addr = p4->addr; sa_touse = (struct sockaddr *)&sin4; + break; } #endif #ifdef INET6 @@ -5334,10 +5327,12 @@ sctp_are_there_new_addresses(struct sctp_association *asoc, memcpy((caddr_t)&sin6.sin6_addr, p6->addr, sizeof(p6->addr)); sa_touse = (struct sockaddr *)&sin6; + break; } #endif default: sa_touse = NULL; + break; } if (sa_touse) { /* ok, sa_touse points to one to check */ @@ -5546,7 +5541,7 @@ do_a_abort: default: goto do_a_abort; break; - }; + } if (net == NULL) { to = (struct sockaddr *)&store; @@ -5966,6 +5961,7 @@ do_a_abort: llen = 0; ol = op_err; + while (ol) { llen += SCTP_BUF_LEN(ol); ol = SCTP_BUF_NEXT(ol); @@ -6035,15 +6031,11 @@ do_a_abort: padval = p_len % 4; if ((padval) && (mp_last)) { /* see my previous comments on mp_last */ - int ret; - - ret = sctp_add_pad_tombuf(mp_last, (4 - padval)); - if (ret) { + if (sctp_add_pad_tombuf(mp_last, (4 - padval))) { /* Houston we have a problem, no space */ sctp_m_freem(m); return; } - p_len += padval; } if (stc.loopback_scope) { over_addr = &store1; @@ -6242,7 +6234,7 @@ sctp_msg_append(struct sctp_tcb *stcb, struct mbuf *m, struct sctp_sndrcvinfo *srcv, int hold_stcb_lock) { - int error = 0, holds_lock; + int error = 0; struct mbuf *at; struct sctp_stream_queue_pending *sp = NULL; struct sctp_stream_out *strm; @@ -6251,7 +6243,6 @@ sctp_msg_append(struct sctp_tcb *stcb, * Given an mbuf chain, put it into the association send queue and * place it on the wheel */ - holds_lock = hold_stcb_lock; if (srcv->sinfo_stream >= stcb->asoc.streamoutcnt) { /* Invalid stream number */ SCTP_LTRACE_ERR_RET_PKT(m, NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); @@ -6320,7 +6311,9 @@ sctp_msg_append(struct sctp_tcb *stcb, sctp_auth_key_acquire(stcb, sp->auth_keyid); sp->holds_key_ref = 1; } - SCTP_TCB_SEND_LOCK(stcb); + if (hold_stcb_lock == 0) { + SCTP_TCB_SEND_LOCK(stcb); + } sctp_snd_sb_alloc(stcb, sp->length); atomic_add_int(&stcb->asoc.stream_queue_cnt, 1); TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); @@ -6330,7 +6323,9 @@ sctp_msg_append(struct sctp_tcb *stcb, } stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, strm, sp, 1); m = NULL; - SCTP_TCB_SEND_UNLOCK(stcb); + if (hold_stcb_lock == 0) { + SCTP_TCB_SEND_UNLOCK(stcb); + } out_now: if (m) { sctp_m_freem(m); @@ -7597,7 +7592,6 @@ dont_do_it: out_of: if (send_lock_up) { SCTP_TCB_SEND_UNLOCK(stcb); - send_lock_up = 0; } return (to_move); } @@ -7612,7 +7606,7 @@ sctp_fill_outqueue(struct sctp_tcb *stcb, ) { struct sctp_association *asoc; - struct sctp_stream_out *strq, *strqn; + struct sctp_stream_out *strq; int goal_mtu, moved_how_much, total_moved = 0, bail = 0; int locked, giveup; @@ -7641,7 +7635,6 @@ sctp_fill_outqueue(struct sctp_tcb *stcb, strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc); locked = 0; } - strqn = strq; while ((goal_mtu > 0) && strq) { giveup = 0; bail = 0; @@ -7954,7 +7947,7 @@ again_one_more_time: */ continue; } - ctl_cnt = bundle_at = 0; + bundle_at = 0; endoutchain = outchain = NULL; no_fragmentflg = 1; one_chunk = 0; @@ -8652,7 +8645,6 @@ again_one_more_time: chk->window_probe = 0; data_list[bundle_at++] = chk; if (bundle_at >= SCTP_MAX_DATA_BUNDLING) { - mtu = 0; break; } if (chk->sent == SCTP_DATAGRAM_UNSENT) { @@ -8769,7 +8761,7 @@ no_data_fill: } else { asoc->ifp_had_enobuf = 0; } - outchain = endoutchain = NULL; + endoutchain = NULL; auth = NULL; auth_offset = 0; if (bundle_at || hbflag) { @@ -9233,7 +9225,7 @@ sctp_send_asconf_ack(struct sctp_tcb *stcb) */ struct sctp_tmit_chunk *chk; struct sctp_asconf_ack *ack, *latest_ack; - struct mbuf *m_ack, *m; + struct mbuf *m_ack; struct sctp_nets *net = NULL; SCTP_TCB_LOCK_ASSERT(stcb); @@ -9312,7 +9304,6 @@ sctp_send_asconf_ack(struct sctp_tcb *stcb) chk->data = m_ack; chk->send_size = 0; /* Get size */ - m = m_ack; chk->send_size = ack->len; chk->rec.chunk_id.id = SCTP_ASCONF_ACK; chk->rec.chunk_id.can_take_data = 1; @@ -9405,7 +9396,6 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp, ctl_cnt++; if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) { fwd_tsn = 1; - fwd = chk; } /* * Add an AUTH chunk, if chunk requires it save the @@ -9443,7 +9433,7 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp, SCTP_STAT_INCR(sctps_lowlevelerr); return (error); } - m = endofchain = NULL; + endofchain = NULL; auth = NULL; auth_offset = 0; /* @@ -9613,16 +9603,13 @@ one_chunk_around: * now are there anymore forward from chk to pick * up? */ - fwd = TAILQ_NEXT(chk, sctp_next); - while (fwd) { + for (fwd = TAILQ_NEXT(chk, sctp_next); fwd != NULL; fwd = TAILQ_NEXT(fwd, sctp_next)) { if (fwd->sent != SCTP_DATAGRAM_RESEND) { /* Nope, not for retran */ - fwd = TAILQ_NEXT(fwd, sctp_next); continue; } if (fwd->whoTo != net) { /* Nope, not the net in question */ - fwd = TAILQ_NEXT(fwd, sctp_next); continue; } if (data_auth_reqd && (auth == NULL)) { @@ -9670,7 +9657,6 @@ one_chunk_around: if (bundle_at >= SCTP_MAX_DATA_BUNDLING) { break; } - fwd = TAILQ_NEXT(fwd, sctp_next); } else { /* can't fit so we are done */ break; @@ -9702,7 +9688,7 @@ one_chunk_around: SCTP_STAT_INCR(sctps_lowlevelerr); return (error); } - m = endofchain = NULL; + endofchain = NULL; auth = NULL; auth_offset = 0; /* For HB's */ @@ -10264,12 +10250,14 @@ sctp_fill_in_rest: * we report. */ at = TAILQ_FIRST(&asoc->sent_queue); - for (i = 0; i < cnt_of_skipped; i++) { - tp1 = TAILQ_NEXT(at, sctp_next); - if (tp1 == NULL) { - break; + if (at != NULL) { + for (i = 0; i < cnt_of_skipped; i++) { + tp1 = TAILQ_NEXT(at, sctp_next); + if (tp1 == NULL) { + break; + } + at = tp1; } - at = tp1; } if (at && SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { sctp_misc_ints(SCTP_FWD_TSN_CHECK, @@ -10333,7 +10321,6 @@ sctp_fill_in_rest: } } return; - } void @@ -12943,15 +12930,12 @@ sctp_lower_sosend(struct socket *so, if (top) { struct mbuf *cntm = NULL; - mm = sctp_get_mbuf_for_msg(1, 0, M_WAIT, 1, MT_DATA); + mm = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_WAIT, 1, MT_DATA); if (sndlen != 0) { - cntm = top; - while (cntm) { + for (cntm = top; cntm; cntm = SCTP_BUF_NEXT(cntm)) { tot_out += SCTP_BUF_LEN(cntm); - cntm = SCTP_BUF_NEXT(cntm); } } - tot_demand = (tot_out + sizeof(struct sctp_paramhdr)); } else { /* Must fit in a MTU */ tot_out = sndlen; @@ -13002,7 +12986,6 @@ sctp_lower_sosend(struct socket *so, } if (hold_tcblock == 0) { SCTP_TCB_LOCK(stcb); - hold_tcblock = 1; } atomic_add_int(&stcb->asoc.refcnt, -1); free_cnt_applied = 0; @@ -13640,8 +13623,6 @@ skip_out_eof: stcb->asoc.total_flight, stcb->asoc.chunks_on_out_queue, stcb->asoc.total_flight_count); } - if (queue_only_for_init) - queue_only_for_init = 0; if ((queue_only == 0) && (nagle_applies == 0) && (stcb->asoc.peers_rwnd && un_sent)) { /* we can attempt to send too. */ if (hold_tcblock == 0) { @@ -13687,11 +13668,9 @@ out_unlocked: if (local_soresv && stcb) { atomic_subtract_int(&stcb->asoc.sb_send_resv, sndlen); - local_soresv = 0; } if (create_lock_applied) { SCTP_ASOC_CREATE_UNLOCK(inp); - create_lock_applied = 0; } if ((stcb) && hold_tcblock) { SCTP_TCB_UNLOCK(stcb); @@ -13737,6 +13716,7 @@ sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, struct mbuf *m_auth; struct sctp_auth_chunk *auth; int chunk_len; + struct mbuf *cn; if ((m_end == NULL) || (auth_ret == NULL) || (offset == NULL) || (stcb == NULL)) @@ -13774,17 +13754,10 @@ sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, /* key id and hmac digest will be computed and filled in upon send */ /* save the offset where the auth was inserted into the chain */ - if (m != NULL) { - struct mbuf *cn; - - *offset = 0; - cn = m; - while (cn) { - *offset += SCTP_BUF_LEN(cn); - cn = SCTP_BUF_NEXT(cn); - } - } else - *offset = 0; + *offset = 0; + for (cn = m; cn; cn = SCTP_BUF_NEXT(cn)) { + *offset += SCTP_BUF_LEN(cn); + } /* update length and return pointer to the auth chunk */ SCTP_BUF_LEN(m_auth) = chunk_len; diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index e5f1ea5..f81d638 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -69,11 +69,11 @@ SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b) memcpy(&tmp_a, a, sizeof(struct sockaddr_in6)); if (sa6_embedscope(&tmp_a, MODULE_GLOBAL(ip6_use_defzone)) != 0) { - return 0; + return (0); } memcpy(&tmp_b, b, sizeof(struct sockaddr_in6)); if (sa6_embedscope(&tmp_b, MODULE_GLOBAL(ip6_use_defzone)) != 0) { - return 0; + return (0); } return (IN6_ARE_ADDR_EQUAL(&tmp_a.sin6_addr, &tmp_b.sin6_addr)); } @@ -439,8 +439,6 @@ sctp_add_ifa_to_ifn(struct sctp_ifn *sctp_ifnp, struct sctp_ifa *sctp_ifap) static void sctp_remove_ifa_from_ifn(struct sctp_ifa *sctp_ifap) { - uint32_t ifn_index; - LIST_REMOVE(sctp_ifap, next_ifa); if (sctp_ifap->ifn_p) { /* update address counts */ @@ -460,7 +458,6 @@ sctp_remove_ifa_from_ifn(struct sctp_ifa *sctp_ifap) break; } - ifn_index = sctp_ifap->ifn_p->ifn_index; if (LIST_EMPTY(&sctp_ifap->ifn_p->ifalist)) { /* remove the ifn, possibly freeing it */ sctp_delete_ifn(sctp_ifap->ifn_p, SCTP_ADDR_LOCKED); @@ -468,13 +465,13 @@ sctp_remove_ifa_from_ifn(struct sctp_ifa *sctp_ifap) /* re-register address family type, if needed */ if ((sctp_ifap->ifn_p->num_v6 == 0) && (sctp_ifap->ifn_p->registered_af == AF_INET6)) { - SCTP_DEREGISTER_INTERFACE(ifn_index, AF_INET6); - SCTP_REGISTER_INTERFACE(ifn_index, AF_INET); + SCTP_DEREGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET6); + SCTP_REGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET); sctp_ifap->ifn_p->registered_af = AF_INET; } else if ((sctp_ifap->ifn_p->num_v4 == 0) && (sctp_ifap->ifn_p->registered_af == AF_INET)) { - SCTP_DEREGISTER_INTERFACE(ifn_index, AF_INET); - SCTP_REGISTER_INTERFACE(ifn_index, AF_INET6); + SCTP_DEREGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET); + SCTP_REGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET6); sctp_ifap->ifn_p->registered_af = AF_INET6; } /* free the ifn refcount */ @@ -1837,13 +1834,13 @@ sctp_pcb_findep(struct sockaddr *nam, int find_tcp_pool, int have_lock, #ifdef INET case AF_INET: sin = (struct sockaddr_in *)nam; - lport = ((struct sockaddr_in *)nam)->sin_port; + lport = sin->sin_port; break; #endif #ifdef INET6 case AF_INET6: sin6 = (struct sockaddr_in6 *)nam; - lport = ((struct sockaddr_in6 *)nam)->sin6_port; + lport = sin6->sin6_port; break; #endif default: @@ -2112,7 +2109,7 @@ sctp_findassoc_by_vtag(struct sockaddr *from, struct sockaddr *to, uint32_t vtag if (skip_src_check) { conclusive: if (from) { - net = sctp_findnet(stcb, from); + *netp = sctp_findnet(stcb, from); } else { *netp = NULL; /* unknown */ } @@ -3310,7 +3307,6 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from) * freeing. a) Any local lists. b) Any associations. c) The hash of * all associations. d) finally the ep itself. */ - struct sctp_pcb *m; struct sctp_tcb *asoc, *nasoc; struct sctp_laddr *laddr, *nladdr; struct inpcb *ip_pcb; @@ -3361,7 +3357,6 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from) sctp_m_freem(inp->pkt); inp->pkt = NULL; } - m = &inp->sctp_ep; ip_pcb = &inp->ip_inp.inp; /* we could just cast the main pointer * here but I will be nice :> (i.e. * ip_pcb = ep;) */ @@ -3409,8 +3404,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from) if ((asoc->asoc.size_on_reasm_queue > 0) || (asoc->asoc.control_pdapi) || (asoc->asoc.size_on_all_streams > 0) || - (so && (so->so_rcv.sb_cc > 0)) - ) { + (so && (so->so_rcv.sb_cc > 0))) { /* Left with Data unread */ struct mbuf *op_err; @@ -3718,7 +3712,6 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from) * macro here since le_next will get freed as part of the * sctp_free_assoc() call. */ - cnt = 0; if (so) { #ifdef IPSEC ipsec_delete_pcbpolicy(ip_pcb); @@ -5548,7 +5541,6 @@ sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa) void sctp_add_local_addr_restricted(struct sctp_tcb *stcb, struct sctp_ifa *ifa) { - struct sctp_inpcb *inp; struct sctp_laddr *laddr; struct sctpladdr *list; @@ -5558,7 +5550,6 @@ sctp_add_local_addr_restricted(struct sctp_tcb *stcb, struct sctp_ifa *ifa) */ list = &stcb->asoc.sctp_restricted_addrs; - inp = stcb->sctp_ep; #ifdef INET6 if (ifa->address.sa.sa_family == AF_INET6) { if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { @@ -5768,7 +5759,7 @@ skip_sleep: msleep(&wkq->running, &wkq->core_mtx, 0, "wait for pkt", 0); - }; + } } static void @@ -6115,7 +6106,7 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m, * with either INIT or INIT-ACK's as long as the m points to the IP * packet and the offset points to the beginning of the parameters. */ - struct sctp_inpcb *inp, *l_inp; + struct sctp_inpcb *inp; struct sctp_nets *net, *nnet, *net_tmp; struct ip *iph; struct sctp_paramhdr *phdr, parm_buf; @@ -6229,8 +6220,7 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m, net->dest_state |= SCTP_ADDR_NOT_IN_ASSOC; } /* does the source address already exist? if so skip it */ - l_inp = inp = stcb->sctp_ep; - + inp = stcb->sctp_ep; atomic_add_int(&stcb->asoc.refcnt, 1); stcb_tmp = sctp_findassociation_ep_addr(&inp, sa, &net_tmp, local_sa, stcb); atomic_add_int(&stcb->asoc.refcnt, -1); diff --git a/sys/netinet/sctp_ss_functions.c b/sys/netinet/sctp_ss_functions.c index 3f77427..e586647 100644 --- a/sys/netinet/sctp_ss_functions.c +++ b/sys/netinet/sctp_ss_functions.c @@ -286,7 +286,7 @@ static struct sctp_stream_out * sctp_ss_rrp_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net SCTP_UNUSED, struct sctp_association *asoc) { - return asoc->last_out_stream; + return (asoc->last_out_stream); } static void diff --git a/sys/netinet/sctp_sysctl.c b/sys/netinet/sctp_sysctl.c index 4716bab..0ae50f7 100644 --- a/sys/netinet/sctp_sysctl.c +++ b/sys/netinet/sctp_sysctl.c @@ -388,12 +388,12 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) /* request some more memory than needed */ req->oldidx = (n + n / 8); - return 0; + return (0); } if (req->newptr != USER_ADDR_NULL) { SCTP_INP_INFO_RUNLOCK(); SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM); - return EPERM; + return (EPERM); } LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) { SCTP_INP_RLOCK(inp); @@ -424,14 +424,14 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb)); if (error) { SCTP_INP_DECR_REF(inp); - return error; + return (error); } SCTP_INP_INFO_RLOCK(); SCTP_INP_RLOCK(inp); error = copy_out_local_addresses(inp, NULL, req); if (error) { SCTP_INP_DECR_REF(inp); - return error; + return (error); } LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { SCTP_TCB_LOCK(stcb); @@ -475,7 +475,7 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) if (error) { SCTP_INP_DECR_REF(inp); atomic_subtract_int(&stcb->asoc.refcnt, 1); - return error; + return (error); } SCTP_INP_INFO_RLOCK(); SCTP_INP_RLOCK(inp); @@ -483,7 +483,7 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) if (error) { SCTP_INP_DECR_REF(inp); atomic_subtract_int(&stcb->asoc.refcnt, 1); - return error; + return (error); } TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { xraddr.last = 0; @@ -509,7 +509,7 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) if (error) { SCTP_INP_DECR_REF(inp); atomic_subtract_int(&stcb->asoc.refcnt, 1); - return error; + return (error); } SCTP_INP_INFO_RLOCK(); SCTP_INP_RLOCK(inp); @@ -522,7 +522,7 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr)); if (error) { SCTP_INP_DECR_REF(inp); - return error; + return (error); } SCTP_INP_INFO_RLOCK(); SCTP_INP_RLOCK(inp); @@ -534,7 +534,7 @@ sctp_assoclist(SYSCTL_HANDLER_ARGS) xstcb.last = 1; error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb)); if (error) { - return error; + return (error); } skip: SCTP_INP_INFO_RLOCK(); @@ -544,7 +544,7 @@ skip: memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb)); xinpcb.last = 1; error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb)); - return error; + return (error); } diff --git a/sys/netinet/sctp_timer.c b/sys/netinet/sctp_timer.c index 1e7b5b2..f347105 100644 --- a/sys/netinet/sctp_timer.c +++ b/sys/netinet/sctp_timer.c @@ -1402,32 +1402,31 @@ sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, { uint8_t net_was_pf; - net_was_pf = 0; - if (net) { - if (net->dest_state & SCTP_ADDR_PF) { - net_was_pf = 1; - } - if (net->hb_responded == 0) { - if (net->ro._s_addr) { - /* - * Invalidate the src address if we did not - * get a response last time. - */ - sctp_free_ifa(net->ro._s_addr); - net->ro._s_addr = NULL; - net->src_addr_selected = 0; - } - sctp_backoff_on_timeout(stcb, net, 1, 0, 0); - if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) { - /* Assoc is over */ - return (1); - } + if (net->dest_state & SCTP_ADDR_PF) { + net_was_pf = 1; + } else { + net_was_pf = 0; + } + if (net->hb_responded == 0) { + if (net->ro._s_addr) { + /* + * Invalidate the src address if we did not get a + * response last time. + */ + sctp_free_ifa(net->ro._s_addr); + net->ro._s_addr = NULL; + net->src_addr_selected = 0; } - /* Zero PBA, if it needs it */ - if (net->partial_bytes_acked) { - net->partial_bytes_acked = 0; + sctp_backoff_on_timeout(stcb, net, 1, 0, 0); + if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) { + /* Assoc is over */ + return (1); } } + /* Zero PBA, if it needs it */ + if (net->partial_bytes_acked) { + net->partial_bytes_acked = 0; + } if ((stcb->asoc.total_output_queue_size > 0) && (TAILQ_EMPTY(&stcb->asoc.send_queue)) && (TAILQ_EMPTY(&stcb->asoc.sent_queue))) { diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index 92051f2..3f3c62d 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -502,17 +502,17 @@ sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUS inp = (struct sctp_inpcb *)so->so_pcb; if (inp != 0) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace)); if (error) { - return error; + return (error); } } error = sctp_inpcb_alloc(so, vrf_id); if (error) { - return error; + return (error); } inp = (struct sctp_inpcb *)so->so_pcb; SCTP_INP_WLOCK(inp); @@ -544,11 +544,11 @@ try_again: SCTP_INP_WUNLOCK(inp); } } - return error; + return (error); } #endif /* IPSEC */ SCTP_INP_WUNLOCK(inp); - return 0; + return (0); } static int @@ -561,20 +561,20 @@ sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p) if (addr && addr->sa_family != AF_INET) { /* must be a v4 address! */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } #endif /* INET6 */ if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } inp = (struct sctp_inpcb *)so->so_pcb; if (inp == 0) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } error = sctp_inpcb_bind(so, addr, NULL, p); - return error; + return (error); } #endif @@ -657,13 +657,12 @@ sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, } SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); sctp_m_freem(m); - return EINVAL; + return (EINVAL); } /* Got to have an to address if we are NOT a connected socket */ if ((addr == NULL) && ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) || - (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE)) - ) { + (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) { goto connected_type; } else if (addr == NULL) { SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ); @@ -920,7 +919,7 @@ sctp_disconnect(struct socket *so) /* UDP model does not support this */ SCTP_INP_RUNLOCK(inp); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); - return EOPNOTSUPP; + return (EOPNOTSUPP); } } @@ -938,7 +937,7 @@ sctp_flush(struct socket *so, int how) inp = (struct sctp_inpcb *)so->so_pcb; if (inp == NULL) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } SCTP_INP_RLOCK(inp); /* For the 1 to many model this does nothing */ @@ -982,7 +981,7 @@ sctp_shutdown(struct socket *so) inp = (struct sctp_inpcb *)so->so_pcb; if (inp == 0) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } SCTP_INP_RLOCK(inp); /* For UDP model this is a invalid call */ @@ -1123,7 +1122,7 @@ sctp_shutdown(struct socket *so) } skip_unlock: SCTP_INP_RUNLOCK(inp); - return 0; + return (0); } /* @@ -1592,7 +1591,7 @@ out_now: SCTP_ASOC_CREATE_UNLOCK(inp); } SCTP_INP_DECR_REF(inp); - return error; + return (error); } #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \ @@ -3321,7 +3320,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, if (inp == 0) { SCTP_PRINTF("inp is NULL?\n"); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return EINVAL; + return (EINVAL); } vrf_id = inp->def_vrf_id; @@ -5968,7 +5967,7 @@ out_now: SCTP_ASOC_CREATE_UNLOCK(inp); } SCTP_INP_DECR_REF(inp); - return error; + return (error); } #endif @@ -6278,7 +6277,7 @@ sctp_ingetaddr(struct socket *so, struct sockaddr **addr) if (!inp) { SCTP_FREE_SONAME(sin); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return ECONNRESET; + return (ECONNRESET); } SCTP_INP_RLOCK(inp); sin->sin_port = inp->sctp_lport; @@ -6347,7 +6346,7 @@ sctp_ingetaddr(struct socket *so, struct sockaddr **addr) SCTP_FREE_SONAME(sin); SCTP_INP_RUNLOCK(inp); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); - return ENOENT; + return (ENOENT); } } SCTP_INP_RUNLOCK(inp); @@ -6366,25 +6365,19 @@ sctp_peeraddr(struct socket *so, struct sockaddr **addr) struct sctp_nets *net; /* Do the malloc first in case it blocks. */ - inp = (struct sctp_inpcb *)so->so_pcb; - if ((inp == NULL) || - ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) { - /* UDP type and listeners will drop out here */ - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); - return (ENOTCONN); - } SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); if (sin == NULL) return (ENOMEM); sin->sin_family = AF_INET; sin->sin_len = sizeof(*sin); - /* We must recapture incase we blocked */ inp = (struct sctp_inpcb *)so->so_pcb; - if (!inp) { + if ((inp == NULL) || + ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) { + /* UDP type and listeners will drop out here */ SCTP_FREE_SONAME(sin); - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return ECONNRESET; + SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); + return (ENOTCONN); } SCTP_INP_RLOCK(inp); stcb = LIST_FIRST(&inp->sctp_asoc_list); @@ -6395,7 +6388,7 @@ sctp_peeraddr(struct socket *so, struct sockaddr **addr) if (stcb == NULL) { SCTP_FREE_SONAME(sin); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); - return ECONNRESET; + return (ECONNRESET); } fnd = 0; TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { @@ -6412,7 +6405,7 @@ sctp_peeraddr(struct socket *so, struct sockaddr **addr) /* No IPv4 address */ SCTP_FREE_SONAME(sin); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); - return ENOENT; + return (ENOENT); } (*addr) = (struct sockaddr *)sin; return (0); diff --git a/sys/netinet/sctp_var.h b/sys/netinet/sctp_var.h index 09c0dd8..24c5544 100644 --- a/sys/netinet/sctp_var.h +++ b/sys/netinet/sctp_var.h @@ -53,27 +53,28 @@ extern struct pr_usrreqs sctp_usrreqs; #define sctp_stcb_feature_on(inp, stcb, feature) {\ if (stcb) { \ stcb->asoc.sctp_features |= feature; \ - } else { \ + } else if (inp) { \ inp->sctp_features |= feature; \ } \ } #define sctp_stcb_feature_off(inp, stcb, feature) {\ if (stcb) { \ stcb->asoc.sctp_features &= ~feature; \ - } else { \ + } else if (inp) { \ inp->sctp_features &= ~feature; \ } \ } #define sctp_stcb_is_feature_on(inp, stcb, feature) \ (((stcb != NULL) && \ ((stcb->asoc.sctp_features & feature) == feature)) || \ - ((stcb == NULL) && \ + ((stcb == NULL) && (inp != NULL) && \ ((inp->sctp_features & feature) == feature))) #define sctp_stcb_is_feature_off(inp, stcb, feature) \ (((stcb != NULL) && \ ((stcb->asoc.sctp_features & feature) == 0)) || \ - ((stcb == NULL) && \ - ((inp->sctp_features & feature) == 0))) + ((stcb == NULL) && (inp != NULL) && \ + ((inp->sctp_features & feature) == 0)) || \ + ((stcb == NULL) && (inp == NULL))) /* managing mobility_feature in inpcb (by micchie) */ #define sctp_mobility_feature_on(inp, feature) (inp->sctp_mobility_features |= feature) @@ -235,7 +236,7 @@ extern struct pr_usrreqs sctp_usrreqs; #define sctp_mbuf_crush(data) do { \ struct mbuf *_m; \ _m = (data); \ - while(_m && (SCTP_BUF_LEN(_m) == 0)) { \ + while (_m && (SCTP_BUF_LEN(_m) == 0)) { \ (data) = SCTP_BUF_NEXT(_m); \ SCTP_BUF_NEXT(_m) = NULL; \ sctp_m_free(_m); \ diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index aa78064..5f42d6e 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -162,7 +162,6 @@ sctp_log_nagle_event(struct sctp_tcb *stcb, int action) sctp_clog.x.misc.log4); } - void sctp_log_sack(uint32_t old_cumack, uint32_t cumack, uint32_t tsn, uint16_t gaps, uint16_t dups, int from) { @@ -219,7 +218,6 @@ sctp_log_fr(uint32_t biggest_tsn, uint32_t biggest_new_tsn, uint32_t tsn, sctp_clog.x.misc.log4); } - void sctp_log_mb(struct mbuf *m, int from) { @@ -245,7 +243,6 @@ sctp_log_mb(struct mbuf *m, int from) sctp_clog.x.misc.log4); } - void sctp_log_strm_del(struct sctp_queued_to_read *control, struct sctp_queued_to_read *poschk, int from) @@ -1137,7 +1134,7 @@ sctp_print_mapping_array(struct sctp_association *asoc) asoc->highest_tsn_inside_map, asoc->highest_tsn_inside_nr_map); for (limit = asoc->mapping_array_size; limit > 1; limit--) { - if (asoc->mapping_array[limit - 1]) { + if (asoc->mapping_array[limit - 1] != 0) { break; } } @@ -1409,9 +1406,6 @@ sctp_handle_addr_wq(void) } } -int retcode = 0; -int cur_oerr = 0; - void sctp_timeout_handler(void *t) { @@ -1572,9 +1566,7 @@ sctp_timeout_handler(void *t) stcb->asoc.num_send_timers_up = 0; } SCTP_TCB_LOCK_ASSERT(stcb); - cur_oerr = stcb->asoc.overall_error_count; - retcode = sctp_t3rxt_timer(inp, stcb, net); - if (retcode) { + if (sctp_t3rxt_timer(inp, stcb, net)) { /* no need to unlock on tcb its gone */ goto out_decr; @@ -1825,7 +1817,7 @@ sctp_timeout_handler(void *t) SCTPDBG(SCTP_DEBUG_TIMER1, "sctp_timeout_handler:unknown timer %d\n", tmr->type); break; - }; + } #ifdef SCTP_AUDITING_ENABLED sctp_audit_log(0xF1, (uint8_t) tmr->type); if (inp) @@ -1865,8 +1857,6 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb, if ((t_type != SCTP_TIMER_TYPE_ADDR_WQ) && (inp == NULL)) return; - to_ticks = 0; - tmr = NULL; if (stcb) { SCTP_TCB_LOCK_ASSERT(stcb); @@ -2122,7 +2112,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb, __FUNCTION__, t_type); return; break; - }; + } if ((to_ticks <= 0) || (tmr == NULL)) { SCTPDBG(SCTP_DEBUG_TIMER1, "%s: %d:software error to_ticks:%d tmr:%p not set ??\n", __FUNCTION__, t_type, to_ticks, tmr); @@ -2283,7 +2273,7 @@ sctp_timer_stop(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb, SCTPDBG(SCTP_DEBUG_TIMER1, "%s: Unknown timer type %d\n", __FUNCTION__, t_type); break; - }; + } if (tmr == NULL) { return; } @@ -2727,7 +2717,8 @@ sctp_notify_peer_addr_change(struct sctp_tcb *stcb, uint32_t state, struct sctp_paddr_change *spc; struct sctp_queued_to_read *control; - if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT)) { + if ((stcb == NULL) || + sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT)) { /* event not enabled */ return; } @@ -2810,7 +2801,8 @@ sctp_notify_send_failed(struct sctp_tcb *stcb, uint32_t error, struct sctp_queued_to_read *control; int length; - if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)) { + if ((stcb == NULL) || + sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)) { /* event not enabled */ return; } @@ -2893,7 +2885,8 @@ sctp_notify_send_failed2(struct sctp_tcb *stcb, uint32_t error, struct sctp_queued_to_read *control; int length; - if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)) { + if ((stcb == NULL) || + sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)) { /* event not enabled */ return; } @@ -2962,7 +2955,8 @@ sctp_notify_adaptation_layer(struct sctp_tcb *stcb) struct sctp_adaptation_event *sai; struct sctp_queued_to_read *control; - if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT)) { + if ((stcb == NULL) || + sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT)) { /* event not enabled */ return; } @@ -3013,7 +3007,8 @@ sctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, uint32_t error, struct sctp_queued_to_read *control; struct sockbuf *sb; - if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_PDAPIEVNT)) { + if ((stcb == NULL) || + sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_PDAPIEVNT)) { /* event not enabled */ return; } @@ -3173,7 +3168,8 @@ sctp_notify_sender_dry_event(struct sctp_tcb *stcb, struct sctp_sender_dry_event *event; struct sctp_queued_to_read *control; - if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_DRYEVNT)) { + if ((stcb == NULL) || + sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_DRYEVNT)) { /* event not enabled */ return; } @@ -4270,11 +4266,15 @@ sctp_add_to_readq(struct sctp_inpcb *inp, so = SCTP_INP_SO(inp); if (!so_locked) { - atomic_add_int(&stcb->asoc.refcnt, 1); - SCTP_TCB_UNLOCK(stcb); + if (stcb) { + atomic_add_int(&stcb->asoc.refcnt, 1); + SCTP_TCB_UNLOCK(stcb); + } SCTP_SOCKET_LOCK(so, 1); - SCTP_TCB_LOCK(stcb); - atomic_subtract_int(&stcb->asoc.refcnt, 1); + if (stcb) { + SCTP_TCB_LOCK(stcb); + atomic_subtract_int(&stcb->asoc.refcnt, 1); + } if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) { SCTP_SOCKET_UNLOCK(so, 1); return; @@ -4325,7 +4325,7 @@ get_out: } if (inp && (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_CANT_READ)) { SCTP_INP_READ_UNLOCK(inp); - return 0; + return (0); } if (control->end_added) { /* huh this one is complete? */ @@ -4419,11 +4419,15 @@ get_out: struct socket *so; so = SCTP_INP_SO(inp); - atomic_add_int(&stcb->asoc.refcnt, 1); - SCTP_TCB_UNLOCK(stcb); + if (stcb) { + atomic_add_int(&stcb->asoc.refcnt, 1); + SCTP_TCB_UNLOCK(stcb); + } SCTP_SOCKET_LOCK(so, 1); - SCTP_TCB_LOCK(stcb); - atomic_subtract_int(&stcb->asoc.refcnt, 1); + if (stcb) { + SCTP_TCB_LOCK(stcb); + atomic_subtract_int(&stcb->asoc.refcnt, 1); + } if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) { SCTP_SOCKET_UNLOCK(so, 1); return (0); @@ -5160,7 +5164,6 @@ restart_nosblocks: */ if (hold_rlock == 0) { SCTP_INP_READ_LOCK(inp); - hold_rlock = 1; } control = TAILQ_FIRST(&inp->read_queue); if ((control == NULL) && (so->so_rcv.sb_cc != 0)) { @@ -5806,7 +5809,9 @@ wait_some_more: } if (control->end_added) { out_flags |= MSG_EOR; - if ((control->do_not_ref_stcb == 0) && ((control->spec_flags & M_NOTIFICATION) == 0)) + if ((control->do_not_ref_stcb == 0) && + (control->stcb != NULL) && + ((control->spec_flags & M_NOTIFICATION) == 0)) control->stcb->asoc.strmin[control->sinfo_stream].delivery_started = 0; } if (control->spec_flags & M_NOTIFICATION) { @@ -5875,11 +5880,9 @@ out: } if (hold_rlock == 1) { SCTP_INP_READ_UNLOCK(inp); - hold_rlock = 0; } if (hold_sblock) { SOCKBUF_UNLOCK(&so->so_rcv); - hold_sblock = 0; } if (sockbuf_lock) { sbunlock(&so->so_rcv); @@ -5900,7 +5903,6 @@ out: #endif } atomic_add_int(&stcb->asoc.refcnt, -1); - freecnt_applied = 0; /* Save the value back for next time */ stcb->freed_by_sorcv_sincelast = freed_so_far; } -- cgit v1.1