summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorrrs <rrs@FreeBSD.org>2007-05-09 13:30:06 +0000
committerrrs <rrs@FreeBSD.org>2007-05-09 13:30:06 +0000
commit8531fb6bb28e0296c5987623d099b38a08ba798a (patch)
tree5730ba11ad6842199a46899208f93c4ec22a9469 /sys
parentc7d189e526c975d0e57e55dcc56d1c34421395a0 (diff)
downloadFreeBSD-src-8531fb6bb28e0296c5987623d099b38a08ba798a.zip
FreeBSD-src-8531fb6bb28e0296c5987623d099b38a08ba798a.tar.gz
Two major items here:
- All printf that was surrounded by #ifdef SCTP_DEBUG moves to a macro that does all of this. This removes all printfs from the code and makes the code more portable and easier to read. - Static Analysis (cisco) - found a few bugs, but mostly we add checks for NULL pointers and such to make the tool happy. We now pass the Cisco SA tools checks except for where it does not understand tailq/lists. We still need to look at the coverity tools output too (this is like the cisco SA tool) and see if it wants us to fix any other items. Hopefully this will be the last major churn in the code other than bug fixes.
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet/sctp_asconf.c488
-rw-r--r--sys/netinet/sctp_auth.c127
-rw-r--r--sys/netinet/sctp_indata.c216
-rw-r--r--sys/netinet/sctp_input.c669
-rw-r--r--sys/netinet/sctp_os_bsd.h12
-rw-r--r--sys/netinet/sctp_output.c589
-rw-r--r--sys/netinet/sctp_pcb.c259
-rw-r--r--sys/netinet/sctp_pcb.h8
-rw-r--r--sys/netinet/sctp_peeloff.c13
-rw-r--r--sys/netinet/sctp_timer.c125
-rw-r--r--sys/netinet/sctp_usrreq.c66
-rw-r--r--sys/netinet/sctputil.c325
-rw-r--r--sys/netinet/sctputil.h14
-rw-r--r--sys/netinet6/sctp6_usrreq.c42
14 files changed, 1137 insertions, 1816 deletions
diff --git a/sys/netinet/sctp_asconf.c b/sys/netinet/sctp_asconf.c
index e56702b..92ab278 100644
--- a/sys/netinet/sctp_asconf.c
+++ b/sys/netinet/sctp_asconf.c
@@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$");
#endif /* SCTP_DEBUG */
-static int
+static void
sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa)
{
struct ip *iph;
@@ -70,7 +70,7 @@ sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa)
sin->sin_len = sizeof(struct sockaddr_in);
sin->sin_port = 0;
sin->sin_addr.s_addr = iph->ip_src.s_addr;
- return 0;
+ return;
}
#ifdef INET6
else if (iph->ip_v == (IPV6_VERSION >> 4)) {
@@ -84,11 +84,11 @@ sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa)
sin6->sin6_port = 0;
ip6 = mtod(m, struct ip6_hdr *);
sin6->sin6_addr = ip6->ip6_src;
- return 0;
+ return;
}
#endif /* INET6 */
else
- return -1;
+ return;
}
/*
@@ -124,11 +124,8 @@ sctp_asconf_success_response(uint32_t id)
m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
0, M_DONTWAIT, 1, MT_DATA);
if (m_reply == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_success_response: couldn't get mbuf!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_success_response: couldn't get mbuf!\n");
return NULL;
}
aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
@@ -155,11 +152,8 @@ sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv,
sizeof(struct sctp_error_cause)),
0, M_DONTWAIT, 1, MT_DATA);
if (m_reply == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_error_response: couldn't get mbuf!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_error_response: couldn't get mbuf!\n");
return NULL;
}
aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
@@ -173,12 +167,9 @@ sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv,
sizeof(struct sctp_asconf_paramhdr);
if (aph->ph.param_length > MLEN) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_error_response: tlv_length (%xh) too big\n",
- tlv_length);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_error_response: tlv_length (%xh) too big\n",
+ tlv_length);
sctp_m_freem(m_reply); /* discard */
return NULL;
}
@@ -234,12 +225,8 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
sin->sin_addr.s_addr = v4addr->addr;
if (sin->sin_addr.s_addr == INADDR_ANY)
zero_address = 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_add_ip: adding ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
break;
case SCTP_IPV6_ADDRESS:
#ifdef INET6
@@ -256,25 +243,18 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
sizeof(struct in6_addr));
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
zero_address = 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_add_ip: adding ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
#else
/* IPv6 not enabled! */
/* FIX ME: currently sends back an invalid param error */
m_reply = sctp_asconf_error_response(aph->correlation_id,
SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, aparam_length);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_add_ip: v6 disabled- skipping ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_add_ip: v6 disabled- skipping ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
return m_reply;
-#endif /* INET6 */
+#endif
break;
default:
m_reply = sctp_asconf_error_response(aph->correlation_id,
@@ -287,21 +267,15 @@ sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
if (zero_address && sctp_nat_friendly) {
sa = (struct sockaddr *)&sa_source;
sctp_asconf_get_source_ip(m, sa);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_add_ip: using source addr ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_add_ip: using source addr ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
}
/* add the address */
if (sctp_add_remote_addr(stcb, sa, SCTP_DONOT_SETSCOPE,
SCTP_ADDR_DYNAMIC_ADDED) != 0) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_add_ip: error adding address\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_add_ip: error adding address\n");
m_reply = sctp_asconf_error_response(aph->correlation_id,
SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph,
aparam_length);
@@ -336,12 +310,10 @@ sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb,
if (net != src_net) {
/* delete this address */
sctp_remove_net(stcb, net);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_del_remote_addrs_except: deleting ");
- sctp_print_address((struct sockaddr *)&net->ro._l_addr);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_del_remote_addrs_except: deleting ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
+ (struct sockaddr *)&net->ro._l_addr);
/* notify upper layer */
sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
(struct sockaddr *)&net->ro._l_addr);
@@ -395,12 +367,9 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
sin->sin_addr.s_addr = v4addr->addr;
if (sin->sin_addr.s_addr == INADDR_ANY)
zero_address = 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_delete_ip: deleting ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_delete_ip: deleting ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
break;
case SCTP_IPV6_ADDRESS:
if (param_length != sizeof(struct sctp_ipv6addr_param)) {
@@ -417,23 +386,17 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
sizeof(struct in6_addr));
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
zero_address = 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_delete_ip: deleting ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_delete_ip: deleting ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
#else
/* IPv6 not enabled! No "action" needed; just ack it */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_delete_ip: v6 disabled- ignoring: ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_delete_ip: v6 disabled- ignoring: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
/* just respond with a "success" ASCONF-ACK */
return NULL;
-#endif /* INET6 */
+#endif
break;
default:
m_reply = sctp_asconf_error_response(aph->correlation_id,
@@ -445,11 +408,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
/* make sure the source address is not being deleted */
if (sctp_cmpaddr(sa, (struct sockaddr *)&sa_source)) {
/* trying to delete the source address! */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_delete_ip: tried to delete source addr\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
m_reply = sctp_asconf_error_response(aph->correlation_id,
SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph,
aparam_length);
@@ -462,11 +421,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
if (result) {
/* src address did not exist? */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_delete_ip: src addr does not exist?\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
/* what error to reply with?? */
m_reply =
sctp_asconf_error_response(aph->correlation_id,
@@ -487,11 +442,7 @@ sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
*/
if (result == -1) {
/* only one address in the asoc */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_delete_ip: tried to delete last IP addr!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
m_reply = sctp_asconf_error_response(aph->correlation_id,
SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph,
aparam_length);
@@ -546,12 +497,8 @@ sctp_process_asconf_set_primary(struct mbuf *m,
sin->sin_addr.s_addr = v4addr->addr;
if (sin->sin_addr.s_addr == INADDR_ANY)
zero_address = 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_set_primary: ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
break;
case SCTP_IPV6_ADDRESS:
if (param_length != sizeof(struct sctp_ipv6addr_param)) {
@@ -567,23 +514,16 @@ sctp_process_asconf_set_primary(struct mbuf *m,
sizeof(struct in6_addr));
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
zero_address = 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_set_primary: ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
#else
/* IPv6 not enabled! No "action" needed; just ack it */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_set_primary: v6 disabled- ignoring: ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_set_primary: v6 disabled- ignoring: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
/* just respond with a "success" ASCONF-ACK */
return NULL;
-#endif /* INET6 */
+#endif
break;
default:
m_reply = sctp_asconf_error_response(aph->correlation_id,
@@ -596,20 +536,14 @@ sctp_process_asconf_set_primary(struct mbuf *m,
if (zero_address && sctp_nat_friendly) {
sa = (struct sockaddr *)&sa_source;
sctp_asconf_get_source_ip(m, sa);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_set_primary: using source addr ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_set_primary: using source addr ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
}
/* set the primary address */
if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_set_primary: primary address set\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_set_primary: primary address set\n");
/* notify upper layer */
sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa);
@@ -618,11 +552,8 @@ sctp_process_asconf_set_primary(struct mbuf *m,
}
} else {
/* couldn't set the requested primary address! */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_asconf_set_primary: set primary failed!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_asconf_set_primary: set primary failed!\n");
/* must have been an invalid address, so report */
m_reply = sctp_asconf_error_response(aph->correlation_id,
SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
@@ -654,12 +585,9 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
/* verify minimum length */
if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: chunk too small = %xh\n",
- ntohs(cp->ch.chunk_length));
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "handle_asconf: chunk too small = %xh\n",
+ ntohs(cp->ch.chunk_length));
return;
}
asoc = &stcb->asoc;
@@ -667,34 +595,24 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
if (serial_num == asoc->asconf_seq_in) {
/* got a duplicate ASCONF */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: got duplicate serial number = %xh\n",
- serial_num);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "handle_asconf: got duplicate serial number = %xh\n",
+ serial_num);
/* resend last ASCONF-ACK... */
sctp_send_asconf_ack(stcb, 1);
return;
} else if (serial_num != (asoc->asconf_seq_in + 1)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
- serial_num, asoc->asconf_seq_in + 1);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
+ serial_num, asoc->asconf_seq_in + 1);
return;
}
/* it's the expected "next" sequence number, so process it */
asoc->asconf_seq_in = serial_num; /* update sequence */
/* get length of all the param's in the ASCONF */
asconf_limit = offset + ntohs(cp->ch.chunk_length);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: asconf_limit=%u, sequence=%xh\n",
- asconf_limit, serial_num);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "handle_asconf: asconf_limit=%u, sequence=%xh\n",
+ asconf_limit, serial_num);
if (asoc->last_asconf_ack_sent != NULL) {
/* free last ASCONF-ACK message sent */
sctp_m_freem(asoc->last_asconf_ack_sent);
@@ -703,11 +621,8 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
M_DONTWAIT, 1, MT_DATA);
if (m_ack == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: couldn't get mbuf!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "handle_asconf: couldn't get mbuf!\n");
return;
}
m_tail = m_ack; /* current reply chain's tail */
@@ -725,12 +640,8 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
offset += sizeof(struct sctp_asconf_chunk);
p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf);
if (p_addr == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: couldn't get lookup addr!\n");
- }
-#endif /* SCTP_DEBUG */
-
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "handle_asconf: couldn't get lookup addr!\n");
/* respond with a missing/invalid mandatory parameter error */
return;
}
@@ -740,17 +651,13 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
/* get pointer to first asconf param in ASCONF-ACK */
ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t)+sizeof(struct sctp_asconf_ack_chunk));
if (ack_aph == NULL) {
-#ifdef SCTP_DEBUG
- printf("Gak in asconf2\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "Gak in asconf2\n");
return;
}
/* get pointer to first asconf param in ASCONF */
aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf);
if (aph == NULL) {
-#ifdef SCTP_DEBUG
- printf("Empty ASCONF received?\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
goto send_reply;
}
/* process through all parameters */
@@ -767,28 +674,18 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
m_result = NULL;
if (param_length > sizeof(aparam_buf)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: param length (%u) larger than buffer size!\n", param_length);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
sctp_m_freem(m_ack);
return;
}
if (param_length <= sizeof(struct sctp_paramhdr)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: param length (%u) too short\n", param_length);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
sctp_m_freem(m_ack);
}
/* get the entire parameter */
aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
if (aph == NULL) {
-#ifdef SCTP_DEBUG
- printf("Gag\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
sctp_m_freem(m_ack);
return;
}
@@ -856,14 +753,10 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
(uint8_t *) & aparam_buf);
if (aph == NULL) {
/* can't get an asconf paramhdr */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf: can't get asconf param hdr!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
/* FIX ME - add error here... */
}
- } /* while */
+ }
send_reply:
ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
@@ -881,10 +774,7 @@ send_reply:
struct sockaddr_storage from_store;
struct sockaddr *from = (struct sockaddr *)&from_store;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
- printf("handle_asconf: looking up net for IP source address\n");
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
/* pullup already done, IP options already stripped */
iph = mtod(m, struct ip *);
sh = (struct sctphdr *)((caddr_t)iph + sizeof(*iph));
@@ -917,19 +807,14 @@ send_reply:
from = NULL;
}
if (from != NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("Looking for IP source: ");
- sctp_print_address(from);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, from);
/* look up the from address */
stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, from);
#ifdef SCTP_DEBUG
- if ((stcb->asoc.last_control_chunk_from == NULL) &&
- (sctp_debug_on & SCTP_DEBUG_ASCONF1))
- printf("handle_asconf: IP source address not found?!\n");
-#endif /* SCTP_DEBUG */
+ if (stcb->asoc.last_control_chunk_from == NULL)
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
+#endif
}
}
/* and send it (a new one) out... */
@@ -1063,11 +948,8 @@ sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, uint16_t type
SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), "AsconfAddr");
if (aa == NULL) {
/* didn't get memory */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_queue_add: failed to get memory!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_queue_add: failed to get memory!\n");
return (-1);
}
/* fill in asconf address parameter fields */
@@ -1103,6 +985,7 @@ sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, uint16_t type
sizeof(struct in_addr));
} else {
/* invalid family! */
+ SCTP_FREE(aa);
return (-1);
}
aa->sent = 0; /* clear sent flag */
@@ -1114,26 +997,23 @@ sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, uint16_t type
if (type == SCTP_ADD_IP_ADDRESS) {
/* add goes to the front of the queue */
TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
- printf("asconf_queue_add: appended asconf ADD_IP_ADDRESS: ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF2,
+ "asconf_queue_add: appended asconf ADD_IP_ADDRESS: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
} else {
/* delete and set primary goes to the back of the queue */
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
+ if (sctp_debug_on && SCTP_DEBUG_ASCONF2) {
if (type == SCTP_DEL_IP_ADDRESS) {
- printf("asconf_queue_add: inserted asconf DEL_IP_ADDRESS: ");
- sctp_print_address(sa);
+ SCTP_PRINTF("asconf_queue_add: inserted asconf DEL_IP_ADDRESS: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
} else {
- printf("asconf_queue_add: inserted asconf SET_PRIM_ADDR: ");
- sctp_print_address(sa);
+ SCTP_PRINTF("asconf_queue_add: inserted asconf SET_PRIM_ADDR: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
}
}
-#endif /* SCTP_DEBUG */
+#endif
}
return (0);
@@ -1155,6 +1035,9 @@ sctp_asconf_queue_add_sa(struct sctp_tcb *stcb, struct sockaddr *sa,
struct sctp_asconf_addr *aa, *aa_next;
uint32_t vrf_id;
+ if (stcb == NULL) {
+ return (-1);
+ }
/* see if peer supports ASCONF */
if (stcb->asoc.peer_supports_asconf == 0) {
return (-1);
@@ -1212,11 +1095,8 @@ sctp_asconf_queue_add_sa(struct sctp_tcb *stcb, struct sockaddr *sa,
SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), "AsconfAddr");
if (aa == NULL) {
/* didn't get memory */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_queue_add_sa: failed to get memory!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_queue_add_sa: failed to get memory!\n");
return (-1);
}
/* fill in asconf address parameter fields */
@@ -1304,21 +1184,15 @@ sctp_asconf_process_error(struct sctp_tcb *stcb,
if (htons(eh->length) + sizeof(struct sctp_error_cause) >
htons(aph->ph.param_length)) {
/* invalid error cause length */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_process_error: cause element too long\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_process_error: cause element too long\n");
return;
}
if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
htons(eh->length)) {
/* invalid included TLV length */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("asconf_process_error: included TLV too long\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "asconf_process_error: included TLV too long\n");
return;
}
/* which error code ? */
@@ -1359,19 +1233,13 @@ sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
param_type = aparam->ap.aph.ph.param_type;
switch (param_type) {
case SCTP_ADD_IP_ADDRESS:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_param_ack: added IP address\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_param_ack: added IP address\n");
sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, param_type, flag);
break;
case SCTP_DEL_IP_ADDRESS:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("process_param_ack: deleted IP address\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "process_param_ack: deleted IP address\n");
/* nothing really to do... lists already updated */
break;
case SCTP_SET_PRIM_ADDR:
@@ -1420,12 +1288,9 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
/* verify minimum length */
if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf_ack: chunk too small = %xh\n",
- ntohs(cp->ch.chunk_length));
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "handle_asconf_ack: chunk too small = %xh\n",
+ ntohs(cp->ch.chunk_length));
return;
}
asoc = &stcb->asoc;
@@ -1444,31 +1309,21 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
* abort the asoc, since someone probably just hijacked us...
*/
if (serial_num == (asoc->asconf_seq_out + 1)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
sctp_abort_an_association(stcb->sctp_ep, stcb,
SCTP_CAUSE_ILLEGAL_ASCONF_ACK, NULL);
return;
}
if (serial_num != asoc->asconf_seq_out) {
/* got a duplicate/unexpected ASCONF-ACK */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", serial_num, asoc->asconf_seq_out);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
+ serial_num, asoc->asconf_seq_out);
return;
}
if (stcb->asoc.asconf_sent == 0) {
/* got a unexpected ASCONF-ACK for serial not in flight */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("handle_asconf_ack: got serial number = %xh but not in flight\n", serial_num);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got serial number = %xh but not in flight\n",
+ serial_num);
/* nothing to do... duplicate ACK received */
return;
}
@@ -1503,11 +1358,8 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
}
/* get the complete parameter... */
if (param_length > sizeof(aparam_buf)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("param length (%u) larger than buffer size!\n", param_length);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "param length (%u) larger than buffer size!\n", param_length);
sctp_asconf_ack_clear(stcb);
return;
}
@@ -2028,21 +1880,14 @@ sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
stcb->sctp_ep, stcb,
stcb->asoc.primary_destination);
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("set_primary_ip_address_sa: queued on tcb=%p, ",
- stcb);
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "set_primary_ip_address_sa: queued on tcb=%p, ",
+ stcb);
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
} else {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
- stcb);
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
+ stcb);
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
return (-1);
}
return (0);
@@ -2069,13 +1914,9 @@ sctp_set_primary_ip_address(struct sctp_ifa *ifa)
stcb->sctp_ep, stcb,
stcb->asoc.primary_destination);
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("set_primary_ip_address: queued on stcb=%p, ",
- stcb);
- sctp_print_address(&ifa->address.sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address: queued on stcb=%p, ",
+ stcb);
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &ifa->address.sa);
}
} /* for each stcb */
} /* for each inp */
@@ -2089,6 +1930,9 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb)
struct sctp_ifa *sctp_ifa;
vrf = sctp_find_vrf(stcb->asoc.vrf_id);
+ if (vrf == NULL) {
+ return (NULL);
+ }
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
if (stcb->asoc.loopback_scope == 0 &&
SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
@@ -2193,19 +2037,15 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen)
m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_DONTWAIT, 1, MT_DATA);
if (m_asconf_chk == NULL) {
/* no mbuf's */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
- printf("compose_asconf: couldn't get chunk mbuf!\n");
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "compose_asconf: couldn't get chunk mbuf!\n");
return (NULL);
}
m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_DONTWAIT, 1, MT_DATA);
if (m_asconf == NULL) {
/* no mbuf's */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
- printf("compose_asconf: couldn't get mbuf!\n");
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "compose_asconf: couldn't get mbuf!\n");
sctp_m_freem(m_asconf_chk);
return (NULL);
}
@@ -2323,10 +2163,8 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen)
lookup_used = 1;
} else {
/* uh oh... don't have any address?? */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
- printf("compose_asconf: no lookup addr!\n");
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "compose_asconf: no lookup addr!\n");
/* for now, we send a IPv4 address of 0.0.0.0 */
lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
@@ -2366,11 +2204,9 @@ sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
struct sockaddr *sa;
uint32_t vrf_id;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
- printf("processing init-ack addresses\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
+ if (stcb == NULL) /* Un-needed check for SA */
+ return;
/* convert to upper bound */
length += offset;
@@ -2465,10 +2301,8 @@ next_addr:
* we'll be stuck in this loop for a long time...
*/
if (SCTP_SIZE32(plen) == 0) {
-#ifdef SCTP_DEBUG
- printf("process_initack_addrs: bad len (%d) type=%xh\n",
+ SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
plen, ptype);
-#endif
return;
}
/* get next parameter */
@@ -2509,21 +2343,14 @@ sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset,
(sa->sa_family != AF_INET))
return (0);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
- printf("find_initack_addr: starting search for ");
- sctp_print_address(sa);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
+ SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
/* convert to upper bound */
length += offset;
if ((offset + sizeof(struct sctp_paramhdr)) > length) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("find_initack_addr: invalid offset?\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "find_initack_addr: invalid offset?\n");
return (0);
}
/* go through the addresses in the init-ack */
@@ -2540,7 +2367,8 @@ sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset,
sizeof(struct sctp_ipv6addr_param),
(uint8_t *) & addr_store);
if (plen != sizeof(struct sctp_ipv6addr_param) ||
- ph == NULL) {
+ (ph == NULL) ||
+ (a6p == NULL)) {
return (0);
}
sin6 = (struct sockaddr_in6 *)sa;
@@ -2566,7 +2394,8 @@ sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset,
offset, sizeof(struct sctp_ipv4addr_param),
(uint8_t *) & addr_store);
if (plen != sizeof(struct sctp_ipv4addr_param) ||
- ph == NULL) {
+ (ph == NULL) ||
+ (a4p == NULL)) {
return (0);
}
sin = (struct sockaddr_in *)sa;
@@ -2602,19 +2431,12 @@ sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
/* be paranoid and validate the laddr */
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("check_addr_list_ep: laddr->ifa is NULL");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1,
+ "check_addr_list_ep: laddr->ifa is NULL");
continue;
}
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
- printf("check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
continue;
}
/* do i have it implicitly? */
@@ -2649,7 +2471,7 @@ sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
if (stcb) {
vrf_id = stcb->asoc.vrf_id;
} else {
- vrf_id = SCTP_DEFAULT_VRFID;
+ return;
}
vrf = sctp_find_vrf(vrf_id);
if (vrf == NULL) {
@@ -2765,7 +2587,7 @@ sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, uint32_t type,
wi->action = type;
atomic_add_int(&ifa->refcount, 1);
LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
- sctp_initiate_iterator(sctp_iterator_ep,
+ (void)sctp_initiate_iterator(sctp_iterator_ep,
sctp_iterator_stcb,
sctp_iterator_ep_end,
SCTP_PCB_ANY_FLAGS,
diff --git a/sys/netinet/sctp_auth.c b/sys/netinet/sctp_auth.c
index b916ba6..5ea9ca9 100644
--- a/sys/netinet/sctp_auth.c
+++ b/sys/netinet/sctp_auth.c
@@ -63,11 +63,7 @@ sctp_alloc_chunklist(void)
SCTP_MALLOC(chklist, sctp_auth_chklist_t *, sizeof(*chklist),
"AUTH chklist");
if (chklist == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_AUTH_DEBUG) {
- printf("sctp_alloc_chunklist: failed to get memory!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_AUTH1, "sctp_alloc_chunklist: failed to get memory!\n");
} else {
sctp_clear_chunklist(chklist);
}
@@ -119,11 +115,9 @@ sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t * list)
if (list->chunks[chunk] == 0) {
list->chunks[chunk] = 1;
list->num_chunks++;
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP: added chunk %u (0x%02x) to Auth list\n",
- chunk, chunk);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: added chunk %u (0x%02x) to Auth list\n",
+ chunk, chunk);
}
return (0);
}
@@ -145,11 +139,9 @@ sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t * list)
if (list->chunks[chunk] == 1) {
list->chunks[chunk] = 0;
list->num_chunks--;
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP: deleted chunk %u (0x%02x) from Auth list\n",
- chunk, chunk);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: deleted chunk %u (0x%02x) from Auth list\n",
+ chunk, chunk);
}
return (0);
}
@@ -554,10 +546,9 @@ sctp_insert_sharedkey(struct sctp_keyhead *shared_keys,
return;
} else if (new_skey->keyid == skey->keyid) {
/* replace the existing key */
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("replacing shared key id %u\n", new_skey->keyid);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "replacing shared key id %u\n",
+ new_skey->keyid);
LIST_INSERT_BEFORE(skey, new_skey, next);
LIST_REMOVE(skey, next);
sctp_free_sharedkey(skey);
@@ -641,10 +632,8 @@ sctp_auth_add_hmacid(sctp_hmaclist_t * list, uint16_t hmac_id)
if (list == NULL)
return (-1);
if (list->num_algo == list->max_algo) {
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP: HMAC id list full, ignoring add %u\n", hmac_id);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: HMAC id list full, ignoring add %u\n", hmac_id);
return (-1);
}
if ((hmac_id != SCTP_AUTH_HMAC_ID_SHA1) &&
@@ -659,10 +648,7 @@ sctp_auth_add_hmacid(sctp_hmaclist_t * list, uint16_t hmac_id)
(hmac_id != SCTP_AUTH_HMAC_ID_MD5)) {
return (-1);
}
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP: add HMAC id %u to list\n", hmac_id);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1, "SCTP: add HMAC id %u to list\n", hmac_id);
list->hmac[list->num_algo++] = hmac_id;
return (0);
}
@@ -722,10 +708,9 @@ sctp_negotiate_hmacid(sctp_hmaclist_t * peer, sctp_hmaclist_t * local)
#endif
/* found the "best" one */
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP: negotiated peer HMAC id %u\n", peer->hmac[i]);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: negotiated peer HMAC id %u\n",
+ peer->hmac[i]);
return (peer->hmac[i]);
}
}
@@ -1360,8 +1345,9 @@ sctp_auth_setactivekey(struct sctp_tcb *stcb, uint16_t keyid)
}
if (skey == NULL) {
/* that key doesn't exist */
- if (using_ep_key)
+ if (using_ep_key) {
SCTP_INP_RUNLOCK(stcb->sctp_ep);
+ }
return (-1);
}
/* get the shared key text */
@@ -1380,8 +1366,9 @@ sctp_auth_setactivekey(struct sctp_tcb *stcb, uint16_t keyid)
sctp_print_key(stcb->asoc.authinfo.assoc_key, "Assoc Key");
#endif
- if (using_ep_key)
+ if (using_ep_key) {
SCTP_INP_RUNLOCK(stcb->sctp_ep);
+ }
return (0);
}
@@ -1583,12 +1570,12 @@ sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset,
stcb->asoc.authinfo.assoc_key =
sctp_compute_hashkey(stcb->asoc.authinfo.random,
stcb->asoc.authinfo.peer_random, key);
+ SCTPDBG(SCTP_DEBUG_AUTH1, "caching key id %u\n",
+ stcb->asoc.authinfo.assoc_keyid);
#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG) {
- printf("caching key id %u\n",
- stcb->asoc.authinfo.assoc_keyid);
- sctp_print_key(stcb->asoc.authinfo.assoc_key, "Assoc Key");
- }
+ if (SCTP_AUTH_DEBUG)
+ sctp_print_key(stcb->asoc.authinfo.assoc_key,
+ "Assoc Key");
#endif
}
/* set in the active key id */
@@ -1660,11 +1647,9 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
/* get the auth params */
shared_key_id = ntohs(auth->shared_key_id);
hmac_id = ntohs(auth->hmac_id);
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP AUTH Chunk: shared key %u, HMAC id %u\n",
- shared_key_id, hmac_id);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP AUTH Chunk: shared key %u, HMAC id %u\n",
+ shared_key_id, hmac_id);
/* is the indicated HMAC supported? */
if (!sctp_auth_is_supported_hmac(stcb->asoc.local_hmacs, hmac_id)) {
@@ -1672,15 +1657,15 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
struct sctp_auth_invalid_hmac *err;
SCTP_STAT_INCR(sctps_recvivalhmacid);
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP Auth: unsupported HMAC id %u\n", hmac_id);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP Auth: unsupported HMAC id %u\n",
+ hmac_id);
/*
* report this in an Error Chunk: Unsupported HMAC
* Identifier
*/
- m_err = sctp_get_mbuf_for_msg(sizeof(*err), 0, M_DONTWAIT, 1, MT_HEADER);
+ m_err = sctp_get_mbuf_for_msg(sizeof(*err), 0, M_DONTWAIT,
+ 1, MT_HEADER);
if (m_err != NULL) {
/* pre-reserve some space */
SCTP_BUF_RESV_UF(m_err, sizeof(struct sctp_chunkhdr));
@@ -1709,11 +1694,9 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
/* if the shared key isn't found, discard the chunk */
if (skey == NULL) {
SCTP_STAT_INCR(sctps_recvivalkeyid);
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP Auth: unknown key id %u\n",
- shared_key_id);
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP Auth: unknown key id %u\n",
+ shared_key_id);
return (-1);
}
/* generate a notification if this is a new key id */
@@ -1742,10 +1725,8 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
if (chunklen < (sizeof(*auth) + digestlen)) {
/* invalid digest length */
SCTP_STAT_INCR(sctps_recvauthfailed);
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP Auth: chunk too short for HMAC\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP Auth: chunk too short for HMAC\n");
return (-1);
}
/* save a copy of the digest, zero the pseudo header, and validate */
@@ -1757,10 +1738,8 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
/* compare the computed digest with the one in the AUTH chunk */
if (memcmp(digest, computed_digest, digestlen) != 0) {
SCTP_STAT_INCR(sctps_recvauthfailed);
-#ifdef SCTP_DEBUG
- if (SCTP_AUTH_DEBUG)
- printf("SCTP Auth: HMAC digest check failed\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP Auth: HMAC digest check failed\n");
return (-1);
}
return (0);
@@ -1875,10 +1854,8 @@ sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit)
/* enforce the random length */
if (plen != (sizeof(struct sctp_auth_random) +
SCTP_AUTH_RANDOM_SIZE_REQUIRED)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("SCTP: invalid RANDOM len\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: invalid RANDOM len\n");
return (-1);
}
} else if (ptype == SCTP_HMAC_LIST) {
@@ -1897,10 +1874,8 @@ sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit)
sizeof(hmacs->hmac_ids[0]);
/* validate the hmac list */
if (sctp_verify_hmac_param(hmacs, num_hmacs)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("SCTP: invalid HMAC param\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: invalid HMAC param\n");
return (-1);
}
got_hmacs = 1;
@@ -1923,18 +1898,14 @@ sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit)
peer_supports_auth = 0;
}
if (!peer_supports_auth && got_chklist) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("SCTP: peer sent chunk list w/o AUTH\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: peer sent chunk list w/o AUTH\n");
return (-1);
}
if (!sctp_asconf_auth_nochk && peer_supports_asconf &&
!peer_supports_auth) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("SCTP: peer supports ASCONF but not AUTH\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "SCTP: peer supports ASCONF but not AUTH\n");
return (-1);
}
return (0);
@@ -2012,7 +1983,7 @@ sctp_initialize_auth_params(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
plen = sizeof(*ph) + hmacs_len;
ph->param_length = htons(plen);
keylen += sizeof(*ph);
- sctp_serialize_hmaclist(stcb->asoc.local_hmacs,
+ (void)sctp_serialize_hmaclist(stcb->asoc.local_hmacs,
new_key->key + keylen);
}
#endif
diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c
index 92eee87..ba8a9a0 100644
--- a/sys/netinet/sctp_indata.c
+++ b/sys/netinet/sctp_indata.c
@@ -365,10 +365,12 @@ sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc)
int cntDel;
struct sctp_queued_to_read *control, *ctl, *ctlat;
+ if (stcb == NULL)
+ return;
+
cntDel = stream_no = 0;
- if (stcb &&
- ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
- (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET))) {
+ if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
+ (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
/* socket above is long gone */
asoc->fragmented_delivery_inprogress = 0;
chk = TAILQ_FIRST(&asoc->reasmqueue);
@@ -442,14 +444,12 @@ sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc)
* is corrupt, or there is a EOM already on
* the mbuf chain.
*/
- if (stcb->asoc.control_pdapi == NULL) {
+ if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) {
panic("This should not happen control_pdapi NULL?");
}
- if (stcb->asoc.control_pdapi->tail_mbuf == NULL) {
- panic("This should not happen, tail_mbuf not being maintained?");
- }
/* if we did not panic, it was a EOM */
panic("Bad chunking ??");
+ return;
}
cntDel++;
}
@@ -561,24 +561,17 @@ sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc,
#ifdef SCTP_STR_LOGGING
sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD);
#endif
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("queue to stream called for ssn:%u lastdel:%u nxt:%u\n",
- (uint32_t) control->sinfo_stream,
- (uint32_t) strm->last_sequence_delivered, (uint32_t) nxt_todel);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1,
+ "queue to stream called for ssn:%u lastdel:%u nxt:%u\n",
+ (uint32_t) control->sinfo_stream,
+ (uint32_t) strm->last_sequence_delivered,
+ (uint32_t) nxt_todel);
if (compare_with_wrap(strm->last_sequence_delivered,
control->sinfo_ssn, MAX_SEQ) ||
(strm->last_sequence_delivered == control->sinfo_ssn)) {
/* The incoming sseq is behind where we last delivered? */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n",
- control->sinfo_ssn,
- strm->last_sequence_delivered);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n",
+ control->sinfo_ssn, strm->last_sequence_delivered);
/*
* throw it in the stream so it gets cleaned up in
* association destruction
@@ -852,11 +845,7 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
* we hit the next one and it does NOT have
* a FIRST fragment mark.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Gak, Evil plot, its not first, no fragmented delivery in progress\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n");
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
@@ -890,11 +879,7 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
* NEXT chunk MUST be either the LAST or
* MIDDLE fragment NOT a FIRST
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Gak, Evil plot, it IS a first and fragmented delivery in progress\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n");
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -927,13 +912,9 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
if (chk->rec.data.stream_number !=
asoc->str_of_pdapi) {
/* Got to be the right STR No */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Gak, Evil plot, it IS not same stream number %d vs %d\n",
- chk->rec.data.stream_number,
- asoc->str_of_pdapi);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n",
+ chk->rec.data.stream_number,
+ asoc->str_of_pdapi);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -965,13 +946,9 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
chk->rec.data.stream_seq !=
asoc->ssn_of_pdapi) {
/* Got to be the right STR Seq */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Gak, Evil plot, it IS not same stream seq %d vs %d\n",
- chk->rec.data.stream_seq,
- asoc->ssn_of_pdapi);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n",
+ chk->rec.data.stream_seq,
+ asoc->ssn_of_pdapi);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1069,12 +1046,8 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
*/
if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
SCTP_DATA_FIRST_FRAG) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Prev check - It can be a midlle or last but not a first\n");
- printf("Gak, Evil plot, it's a FIRST!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n");
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n");
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1110,13 +1083,9 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
* Huh, need the correct STR here,
* they must be the same.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n",
- chk->rec.data.stream_number,
- prev->rec.data.stream_number);
- }
-#endif
+ SCTP_PRINTF("Prev check - Gak, Evil plot, ssn:%d not the same as at:%d\n",
+ chk->rec.data.stream_number,
+ prev->rec.data.stream_number);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1153,13 +1122,9 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
* Huh, need the correct STR here,
* they must be the same.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n",
- chk->rec.data.stream_seq,
- prev->rec.data.stream_seq);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n",
+ chk->rec.data.stream_seq,
+ prev->rec.data.stream_seq);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1194,11 +1159,7 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
/* Insert chk MUST be a FIRST */
if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
SCTP_DATA_FIRST_FRAG) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Prev check - Gak, evil plot, its not FIRST and it must be!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n");
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1243,12 +1204,8 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
/* Insert chk MUST be a last fragment */
if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK)
!= SCTP_DATA_LAST_FRAG) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Next chk - Next is FIRST, we must be LAST\n");
- printf("Gak, Evil plot, its not a last!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n");
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n");
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1288,12 +1245,8 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
*/
if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
SCTP_DATA_LAST_FRAG) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Next chk - Next is a MIDDLE/LAST\n");
- printf("Gak, Evil plot, new prev chunk is a LAST\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n");
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n");
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1330,13 +1283,9 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
* Huh, need the correct STR here,
* they must be the same.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n",
- chk->rec.data.stream_number,
- next->rec.data.stream_number);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n",
+ chk->rec.data.stream_number,
+ next->rec.data.stream_number);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1374,13 +1323,9 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
* Huh, need the correct STR here,
* they must be the same.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n",
- chk->rec.data.stream_seq,
- next->rec.data.stream_seq);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n",
+ chk->rec.data.stream_seq,
+ next->rec.data.stream_seq);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1509,6 +1454,9 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
#ifdef SCTP_MAP_LOGGING
sctp_log_map(0, tsn, asoc->cumulative_tsn, SCTP_MAP_PREPARE_SLIDE);
#endif
+ if (stcb == NULL) {
+ return (0);
+ }
if (compare_with_wrap(asoc->cumulative_tsn, tsn, MAX_TSN) ||
asoc->cumulative_tsn == tsn) {
/* It is a duplicate */
@@ -1554,7 +1502,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
* Check to see about the GONE flag, duplicates would cause a sack
* to be sent up above
*/
- if (stcb && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
+ if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
(stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET))
) {
@@ -1593,14 +1541,9 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
asoc->highest_tsn_inside_map, MAX_TSN)) {
/* Nope not in the valid range dump it */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("My rwnd overrun1:tsn:%lx rwnd %lu sbspace:%ld\n",
- (u_long)tsn, (u_long)asoc->my_rwnd,
- sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv));
-
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "My rwnd overrun1:tsn:%lx rwnd %lu sbspace:%ld\n",
+ (u_long)tsn, (u_long)asoc->my_rwnd,
+ sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv));
sctp_set_rwnd(stcb, asoc);
if ((asoc->cnt_on_all_streams +
asoc->cnt_on_reasm_queue +
@@ -1683,13 +1626,8 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
strmseq, MAX_SEQ) ||
asoc->strmin[strmno].last_sequence_delivered == strmseq)) {
/* The incoming sseq is behind where we last delivered? */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n",
- strmseq,
- asoc->strmin[strmno].last_sequence_delivered);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n",
+ strmseq, asoc->strmin[strmno].last_sequence_delivered);
oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + 3 * sizeof(uint32_t)),
0, M_DONTWAIT, 1, MT_DATA);
if (oper) {
@@ -1839,7 +1777,7 @@ failed_express_del:
if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end,
tsn,
&stcb->sctp_socket->so_rcv)) {
- printf("Append fails end:%d\n", end);
+ SCTP_PRINTF("Append fails end:%d\n", end);
goto failed_pdapi_express_del;
}
SCTP_STAT_INCR(sctps_recvexpressm);
@@ -2308,7 +2246,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
#ifdef INVARIANTS
panic("huh, cumack greater than high-tsn in map");
#else
- printf("huh, cumack greater than high-tsn in map - should panic?\n");
+ SCTP_PRINTF("huh, cumack greater than high-tsn in map - should panic?\n");
asoc->highest_tsn_inside_map = asoc->cumulative_tsn;
#endif
}
@@ -2465,7 +2403,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int ok_to_sack, int was_a_gap, int *abort
* first packet OR there are gaps or
* duplicates.
*/
- SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
sctp_send_sack(stcb);
}
} else {
@@ -2809,7 +2747,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
(stcb->asoc.delayed_ack == 0) ||
(stcb->asoc.send_sack == 1)) {
if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
- SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
}
sctp_send_sack(stcb);
} else {
@@ -3265,7 +3203,7 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
) {
/* Yes so drop it */
if (tp1->data != NULL) {
- sctp_release_pr_sctp_chunk(stcb, tp1,
+ (void)sctp_release_pr_sctp_chunk(stcb, tp1,
(SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
&asoc->sent_queue);
}
@@ -3278,7 +3216,7 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) {
/* Yes, so drop it */
if (tp1->data != NULL) {
- sctp_release_pr_sctp_chunk(stcb, tp1,
+ (void)sctp_release_pr_sctp_chunk(stcb, tp1,
(SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
&asoc->sent_queue);
}
@@ -3301,7 +3239,7 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
/*
* CMT : SFR algo (covers part of DAC and HTNA as well)
*/
- if (tp1->whoTo->saw_newack == 0) {
+ if (tp1->whoTo && tp1->whoTo->saw_newack == 0) {
/*
* No new acks were receieved for data sent to this
* dest. Therefore, according to the SFR algo for
@@ -3310,7 +3248,7 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
*/
tp1 = TAILQ_NEXT(tp1, sctp_next);
continue;
- } else if (compare_with_wrap(tp1->rec.data.TSN_seq,
+ } else if (tp1->whoTo && compare_with_wrap(tp1->rec.data.TSN_seq,
tp1->whoTo->this_sack_highest_newack, MAX_TSN)) {
/*
* CMT: New acks were receieved for data sent to
@@ -3521,6 +3459,9 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
tp1->no_fr_allowed = 1;
alt = tp1->whoTo;
alt = sctp_find_alternate_net(stcb, alt, 1);
+ if (alt == NULL) {
+ alt = tp1->whoTo;
+ }
/*
* CUCv2: If a different dest is picked for
* the retransmission, then new
@@ -3528,10 +3469,10 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
* for orig dest. Let CUCv2 track new (rtx-)
* pseudo-cumack always.
*/
- tp1->whoTo->find_pseudo_cumack = 1;
- tp1->whoTo->find_rtx_pseudo_cumack = 1;
-
-
+ if (tp1->whoTo) {
+ tp1->whoTo->find_pseudo_cumack = 1;
+ tp1->whoTo->find_rtx_pseudo_cumack = 1;
+ }
} else {/* CMT is OFF */
#ifdef SCTP_FR_TO_ALTERNATE
@@ -3593,9 +3534,10 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc,
(uintptr_t) tp1->whoTo,
tp1->rec.data.TSN_seq);
#endif
- tp1->whoTo->net_ack++;
- sctp_flight_size_decrease(tp1);
-
+ if (tp1->whoTo) {
+ tp1->whoTo->net_ack++;
+ sctp_flight_size_decrease(tp1);
+ }
#ifdef SCTP_LOG_RWND
sctp_log_rwnd(SCTP_INCREASE_PEER_RWND,
asoc->peers_rwnd, tp1->send_size, sctp_peer_chunk_oh);
@@ -3672,7 +3614,7 @@ sctp_try_advance_peer_ack_point(struct sctp_tcb *stcb,
if (timevalcmp(&now, &tp1->rec.data.timetodrop, >)) {
/* Yes so drop it */
if (tp1->data) {
- sctp_release_pr_sctp_chunk(stcb, tp1,
+ (void)sctp_release_pr_sctp_chunk(stcb, tp1,
(SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
&asoc->sent_queue);
}
@@ -3987,7 +3929,7 @@ sctp_cwnd_update(struct sctp_tcb *stcb,
SCTP_RECEIVED_SACK, (void *)net);
/* now was it the primary? if so restore */
if (net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
- sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
+ (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net);
}
}
}
@@ -4149,7 +4091,7 @@ sctp_fs_audit(struct sctp_association *asoc)
#ifdef INVARIANTS
panic("Flight size-express incorrect? \n");
#else
- printf("Flight size-express incorrect inflight:%d inbetween:%d\n",
+ SCTP_PRINTF("Flight size-express incorrect inflight:%d inbetween:%d\n",
inflight, inbetween);
#endif
}
@@ -4518,7 +4460,7 @@ again:
to_ticks = MSEC_TO_TICKS(net->RTO);
}
j++;
- SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks,
+ (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks,
sctp_timeout_handler, &net->rxt_timer);
} else {
if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
@@ -4744,7 +4686,7 @@ sctp_handle_sack(struct sctp_sack_chunk *ch, struct sctp_tcb *stcb,
}
} else {
- printf("Size invalid offset to dups:%d number dups:%d sack_len:%d num gaps:%d\n",
+ SCTP_PRINTF("Size invalid offset to dups:%d number dups:%d sack_len:%d num gaps:%d\n",
off_to_dup, num_dup, sack_length, num_seg);
}
}
@@ -5075,8 +5017,7 @@ skip_segments:
#ifdef INVARIANTS
panic("Warning flight size is postive and should be 0");
#else
-
- printf("Warning flight size incorrect should be 0 is %d\n",
+ SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n",
asoc->total_flight);
#endif
asoc->total_flight = 0;
@@ -5721,11 +5662,8 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb,
asoc = &stcb->asoc;
cnt_gone = 0;
if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Bad size too small/big fwd-tsn\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INDATA1,
+ "Bad size too small/big fwd-tsn\n");
return;
}
m_size = (stcb->asoc.mapping_array_size << 3);
diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c
index 84a2301..6ac5f6d 100644
--- a/sys/netinet/sctp_input.c
+++ b/sys/netinet/sctp_input.c
@@ -85,20 +85,15 @@ sctp_handle_init(struct mbuf *m, int iphlen, int offset, struct sctphdr *sh,
struct mbuf *op_err;
uint32_t init_limit;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_init: handling INIT tcb:%p\n", stcb);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "sctp_handle_init: handling INIT tcb:%p\n",
+ stcb);
op_err = NULL;
init = &cp->init;
/* First are we accepting? */
if ((inp->sctp_socket->so_qlimit == 0) && (stcb == NULL)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_init: Abort, so_qlimit:%d\n", inp->sctp_socket->so_qlimit);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_init: Abort, so_qlimit:%d\n",
+ inp->sctp_socket->so_qlimit);
/*
* FIX ME ?? What about TCP model and we have a
* match/restart case?
@@ -164,11 +159,7 @@ sctp_handle_init(struct mbuf *m, int iphlen, int offset, struct sctphdr *sh,
return;
}
/* send an INIT-ACK w/cookie */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("sctp_handle_init: sending INIT-ACK\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT3, "sctp_handle_init: sending INIT-ACK\n");
sctp_send_initiate_ack(inp, stcb, m, iphlen, offset, sh, cp, vrf_id,
table_id);
}
@@ -229,7 +220,7 @@ sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb,
sctp_free_remote_addr(sp->net);
sp->net = NULL;
/* Free the chunk */
- printf("sp:%p tcb:%p weird free case\n",
+ SCTP_PRINTF("sp:%p tcb:%p weird free case\n",
sp, stcb);
sctp_free_a_strmoq(stcb, sp);
@@ -280,11 +271,7 @@ sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb,
sizeof(struct sctp_stream_in), "StreamsIn");
if (asoc->strmin == NULL) {
/* we didn't get memory for the streams! */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("process_init: couldn't get memory for the streams!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "process_init: couldn't get memory for the streams!\n");
return (-1);
}
for (i = 0; i < asoc->streamincnt; i++) {
@@ -364,11 +351,9 @@ sctp_process_init_ack(struct mbuf *m, int iphlen, int offset,
(offset + sizeof(struct sctp_init_chunk)), initack_limit, sh,
NULL))) {
/* Huh, we should abort */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Load addresses from INIT causes an abort %d\n", retval);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1,
+ "Load addresses from INIT causes an abort %d\n",
+ retval);
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sh,
NULL, 0, 0);
*abort_no_unlock = 1;
@@ -474,11 +459,7 @@ sctp_handle_heartbeat_ack(struct sctp_heartbeat_chunk *cp,
}
r_net = sctp_findnet(stcb, (struct sockaddr *)sin);
if (r_net == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Huh? I can't find the address I sent it to, discard\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Huh? I can't find the address I sent it to, discard\n");
return;
}
if ((r_net && (r_net->dest_state & SCTP_ADDR_UNCONFIRMED)) &&
@@ -519,7 +500,7 @@ sctp_handle_heartbeat_ack(struct sctp_heartbeat_chunk *cp,
SCTP_HEARTBEAT_SUCCESS, (void *)r_net);
/* now was it the primary? if so restore */
if (r_net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
- sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, r_net);
+ (void)sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, r_net);
}
}
/* Now lets do a RTO with this */
@@ -530,16 +511,9 @@ static void
sctp_handle_abort(struct sctp_abort_chunk *cp,
struct sctp_tcb *stcb, struct sctp_nets *net)
{
-
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_abort: handling ABORT\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "sctp_handle_abort: handling ABORT\n");
if (stcb == NULL)
return;
- /* verify that the destination addr is in the association */
- /* ignore abort for addresses being deleted */
/* stop any receive timers */
sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INPUT + SCTP_LOC_5);
@@ -555,11 +529,7 @@ sctp_handle_abort(struct sctp_abort_chunk *cp,
sctp_print_out_track_log(stcb);
#endif
sctp_free_assoc(stcb->sctp_ep, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_INPUT + SCTP_LOC_6);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_abort: finished\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "sctp_handle_abort: finished\n");
}
static void
@@ -569,11 +539,8 @@ sctp_handle_shutdown(struct sctp_shutdown_chunk *cp,
struct sctp_association *asoc;
int some_on_streamwheel;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_shutdown: handling SHUTDOWN\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_shutdown: handling SHUTDOWN\n");
if (stcb == NULL)
return;
asoc = &stcb->asoc;
@@ -661,11 +628,8 @@ sctp_handle_shutdown_ack(struct sctp_shutdown_ack_chunk *cp,
{
struct sctp_association *asoc;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_shutdown_ack: handling SHUTDOWN ACK\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_shutdown_ack: handling SHUTDOWN ACK\n");
if (stcb == NULL)
return;
@@ -734,12 +698,9 @@ sctp_process_unrecog_chunk(struct sctp_tcb *stcb, struct sctp_paramhdr *phdr,
stcb->asoc.peer_supports_prsctp = 0;
break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("Peer does not support chunk type %d(%x)??\n",
- chk->chunk_type, (uint32_t) chk->chunk_type);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "Peer does not support chunk type %d(%x)??\n",
+ chk->chunk_type, (uint32_t) chk->chunk_type);
break;
}
}
@@ -775,21 +736,15 @@ sctp_process_unrecog_param(struct sctp_tcb *stcb, struct sctp_paramhdr *phdr)
break;
case SCTP_SUCCESS_REPORT:
case SCTP_ERROR_CAUSE_IND:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("Huh, the peer does not support success? or error cause?\n");
- printf("Turning off ASCONF to this strange peer\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "Huh, the peer does not support success? or error cause?\n");
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "Turning off ASCONF to this strange peer\n");
stcb->asoc.peer_supports_asconf = 0;
break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("Peer does not support param type %d(%x)??\n",
- pbad->param_type, (uint32_t) pbad->param_type);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "Peer does not support param type %d(%x)??\n",
+ pbad->param_type, (uint32_t) pbad->param_type);
break;
}
}
@@ -817,12 +772,8 @@ sctp_handle_error(struct sctp_chunkhdr *ch,
error_len = ntohs(phdr->param_length);
if ((error_len > chklen) || (error_len == 0)) {
/* invalid param length for this param */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Bogus length in error param- chunk left:%d errorlen:%d\n",
- chklen, error_len);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Bogus length in error param- chunk left:%d errorlen:%d\n",
+ chklen, error_len);
return (0);
}
switch (error_type) {
@@ -830,12 +781,8 @@ sctp_handle_error(struct sctp_chunkhdr *ch,
case SCTP_CAUSE_MISSING_PARAM:
case SCTP_CAUSE_INVALID_PARAM:
case SCTP_CAUSE_NO_USER_DATA:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Software error we got a %d back? We have a bug :/ (or do they?)\n",
- error_type);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Software error we got a %d back? We have a bug :/ (or do they?)\n",
+ error_type);
break;
case SCTP_CAUSE_STALE_COOKIE:
/*
@@ -898,12 +845,8 @@ sctp_handle_error(struct sctp_chunkhdr *ch,
* We should NOT get these here, but in a
* ASCONF-ACK.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("Peer sends ASCONF errors in a Operational Error?<%d>?\n",
- error_type);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "Peer sends ASCONF errors in a Operational Error?<%d>?\n",
+ error_type);
break;
case SCTP_CAUSE_OUT_OF_RESC:
/*
@@ -915,13 +858,8 @@ sctp_handle_error(struct sctp_chunkhdr *ch,
*/
break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- /* don't know what this error cause is... */
- printf("sctp_handle_error: unknown error type = 0x%xh\n",
- error_type);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1, "sctp_handle_error: unknown error type = 0x%xh\n",
+ error_type);
break;
}
adjust = SCTP_SIZE32(error_len);
@@ -941,17 +879,12 @@ sctp_handle_init_ack(struct mbuf *m, int iphlen, int offset,
int *state;
struct mbuf *op_err;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_init_ack: handling INIT-ACK\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_init_ack: handling INIT-ACK\n");
+
if (stcb == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_init_ack: TCB is null\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_init_ack: TCB is null\n");
return (-1);
}
if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_init_ack_chunk)) {
@@ -1022,11 +955,7 @@ sctp_handle_init_ack(struct mbuf *m, int iphlen, int offset,
return (-1);
}
/* update our state */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("moving to COOKIE-ECHOED state\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "moving to COOKIE-ECHOED state\n");
if (*state & SCTP_STATE_SHUTDOWN_PENDING) {
*state = SCTP_STATE_COOKIE_ECHOED |
SCTP_STATE_SHUTDOWN_PENDING;
@@ -1063,12 +992,8 @@ sctp_handle_init_ack(struct mbuf *m, int iphlen, int offset,
/* incorrect state... discard */
return (-1);
break;
- } /* end switch asoc state */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Leaving handle-init-ack end\n");
}
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Leaving handle-init-ack end\n");
return (0);
}
@@ -1175,8 +1100,9 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
#ifdef INVARIANTS
panic("Case D and non-match seq?");
#else
- printf("Case D, seq non-match %x vs %x?\n",
- ntohl(initack_cp->init.initial_tsn), asoc->init_seq_number);
+ SCTP_PRINTF("Case D, seq non-match %x vs %x?\n",
+ ntohl(initack_cp->init.initial_tsn),
+ asoc->init_seq_number);
#endif
}
switch SCTP_GET_STATE
@@ -1587,20 +1513,13 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
(uint8_t *) & init_buf);
if (init_cp == NULL) {
/* could not pull a INIT chunk in cookie */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("process_cookie_new: could not pull INIT chunk hdr\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1,
+ "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) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("HUH? process_cookie_new: could not find INIT chunk!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1, "HUH? process_cookie_new: could not find INIT chunk!\n");
return (NULL);
}
initack_offset = init_offset + SCTP_SIZE32(chk_length);
@@ -1613,11 +1532,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
(uint8_t *) & initack_buf);
if (initack_cp == NULL) {
/* could not pull INIT-ACK chunk in cookie */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("process_cookie_new: could not pull INIT-ACK chunk hdr\n");
- }
-#endif /* SCTP_DEBUG */
+ 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);
@@ -1642,18 +1557,17 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
struct mbuf *op_err;
/* memory problem? */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("process_cookie_new: no room for another TCB!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1,
+ "process_cookie_new: no room for another TCB!\n");
op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
sctp_abort_association(inp, (struct sctp_tcb *)NULL, m, iphlen,
sh, op_err, vrf_id, table_id);
return (NULL);
}
/* get the correct sctp_nets */
- *netp = sctp_findnet(stcb, init_src);
+ if (netp)
+ *netp = sctp_findnet(stcb, init_src);
+
asoc = &stcb->asoc;
/* save the table id (vrf_id is done in aloc_assoc) */
asoc->table_id = table_id;
@@ -1691,7 +1605,10 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
asoc->advanced_peer_ack_point = asoc->last_acked_seq;
/* process the INIT info (peer's info) */
- retval = sctp_process_init(init_cp, stcb, *netp);
+ if (netp)
+ retval = sctp_process_init(init_cp, stcb, *netp);
+ else
+ retval = 0;
if (retval < 0) {
sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_INPUT + SCTP_LOC_16);
return (NULL);
@@ -1715,12 +1632,10 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
auth = (struct sctp_auth_chunk *)
sctp_m_getptr(m, auth_offset, auth_len, auth_chunk_buf);
- if (sctp_handle_auth(stcb, auth, m, auth_offset)) {
+ if ((auth == NULL) || sctp_handle_auth(stcb, auth, m, auth_offset)) {
/* auth HMAC failed, dump the assoc and packet */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("COOKIE-ECHO: AUTH failed\n");
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "COOKIE-ECHO: AUTH failed\n");
sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_INPUT + SCTP_LOC_18);
return (NULL);
} else {
@@ -1729,11 +1644,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
}
}
/* update current state */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("moving to OPEN state\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "moving to OPEN state\n");
if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
asoc->state = SCTP_STATE_OPEN | SCTP_STATE_SHUTDOWN_PENDING;
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
@@ -1809,7 +1720,8 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
;
}
/* since we did not send a HB make sure we don't double things */
- (*netp)->hb_responded = 1;
+ if ((netp) && (*netp))
+ (*netp)->hb_responded = 1;
if (stcb->asoc.sctp_autoclose_ticks &&
sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE)) {
@@ -1817,8 +1729,9 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
}
/* respond with a COOKIE-ACK */
/* calculate the RTT */
- (*netp)->RTO = sctp_calculate_rto(stcb, asoc, *netp,
- &cookie->time_entered);
+ if ((netp) && (*netp))
+ (*netp)->RTO = sctp_calculate_rto(stcb, asoc, *netp,
+ &cookie->time_entered);
sctp_send_cookie_ack(stcb);
return (stcb);
}
@@ -1858,11 +1771,8 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
struct sctp_nets *netl;
int had_a_existing_tcb = 0;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_cookie: handling COOKIE-ECHO\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_cookie: handling COOKIE-ECHO\n");
if (inp_p == NULL) {
return (NULL);
@@ -2000,13 +1910,10 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
}
if (cookie_ok == 0) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("handle_cookie_echo: cookie signature validation failed!\n");
- printf("offset = %u, cookie_offset = %u, sig_offset = %u\n",
- (uint32_t) offset, cookie_offset, sig_offset);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "handle_cookie_echo: cookie signature validation failed!\n");
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "offset = %u, cookie_offset = %u, sig_offset = %u\n",
+ (uint32_t) offset, cookie_offset, sig_offset);
return (NULL);
}
/*
@@ -2075,6 +1982,9 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
sin.sin_port = sh->src_port;
sin.sin_addr.s_addr = cookie->address[0];
to = (struct sockaddr *)&sin;
+ } else {
+ /* This should not happen */
+ return (NULL);
}
if ((*stcb == NULL) && to) {
/* Yep, lets check */
@@ -2086,7 +1996,7 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
* original findep got back l_inp and now
*/
if (l_inp != *inp_p) {
- printf("Bad problem find_ep got a diff inp then special_locate?\n");
+ SCTP_PRINTF("Bad problem find_ep got a diff inp then special_locate?\n");
}
} else {
if (*locked_tcb == NULL) {
@@ -2109,12 +2019,15 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
*/
SCTP_INP_INCR_REF((*stcb)->sctp_ep);
if ((*stcb)->sctp_ep != l_inp) {
- printf("Huh? ep:%p diff then l_inp:%p?\n",
+ SCTP_PRINTF("Huh? ep:%p diff then l_inp:%p?\n",
(*stcb)->sctp_ep, l_inp);
}
}
}
}
+ if (to == NULL)
+ return (NULL);
+
cookie_len -= SCTP_SIGNATURE_SIZE;
if (*stcb == NULL) {
/* this is the "normal" case... get a new TCB */
@@ -2152,7 +2065,7 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
if (netl) {
if (netl->dest_state & SCTP_ADDR_UNCONFIRMED) {
netl->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
- sctp_set_primary_addr((*stcb), (struct sockaddr *)NULL,
+ (void)sctp_set_primary_addr((*stcb), (struct sockaddr *)NULL,
netl);
sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_CONFIRMED,
(*stcb), 0, (void *)netl);
@@ -2198,11 +2111,7 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
struct mbuf *op_err;
/* Too many sockets */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("process_cookie_new: no room for another socket!\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1, "process_cookie_new: no room for another socket!\n");
op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
sctp_abort_association(*inp_p, NULL, m, iphlen,
sh, op_err, vrf_id,
@@ -2291,11 +2200,8 @@ sctp_handle_cookie_ack(struct sctp_cookie_ack_chunk *cp,
/* cp must not be used, others call this without a c-ack :-) */
struct sctp_association *asoc;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_cookie_ack: handling COOKIE-ACK\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_cookie_ack: handling COOKIE-ACK\n");
if (stcb == NULL)
return;
@@ -2305,11 +2211,7 @@ sctp_handle_cookie_ack(struct sctp_cookie_ack_chunk *cp,
/* process according to association state */
if (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED) {
/* state change only needed when I am in right state */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("moving to OPEN state\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2, "moving to OPEN state\n");
if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
asoc->state = SCTP_STATE_OPEN | SCTP_STATE_SHUTDOWN_PENDING;
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
@@ -2487,11 +2389,8 @@ sctp_handle_shutdown_complete(struct sctp_shutdown_complete_chunk *cp,
{
struct sctp_association *asoc;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_handle_shutdown_complete: handling SHUTDOWN-COMPLETE\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT2,
+ "sctp_handle_shutdown_complete: handling SHUTDOWN-COMPLETE\n");
if (stcb == NULL)
return;
@@ -2654,7 +2553,7 @@ process_chunk_drop(struct sctp_tcb *stcb, struct sctp_chunk_desc *desc,
audit++;
}
if (audit != stcb->asoc.sent_queue_retran_cnt) {
- printf("**Local Audit finds cnt:%d asoc cnt:%d\n",
+ SCTP_PRINTF("**Local Audit finds cnt:%d asoc cnt:%d\n",
audit, stcb->asoc.sent_queue_retran_cnt);
#ifndef SCTP_AUDITING_ENABLED
stcb->asoc.sent_queue_retran_cnt = audit;
@@ -3224,7 +3123,7 @@ strres_nochunk:
seq = ntohl(req_out->response_seq);
if (seq == stcb->asoc.str_reset_seq_out) {
/* implicit ack */
- sctp_handle_stream_reset_response(stcb, seq, SCTP_STREAM_RESET_PERFORMED, NULL);
+ (void)sctp_handle_stream_reset_response(stcb, seq, SCTP_STREAM_RESET_PERFORMED, NULL);
}
}
sctp_handle_str_reset_request_out(stcb, chk, req_out);
@@ -3566,12 +3465,8 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
uint32_t auth_offset = 0, auth_len = 0;
int auth_skipped = 0;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("sctp_process_control: iphlen=%u, offset=%u, length=%u stcb:%p\n",
- iphlen, *offset, length, stcb);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1, "sctp_process_control: iphlen=%u, offset=%u, length=%u stcb:%p\n",
+ iphlen, *offset, length, stcb);
/* validate chunk header length... */
if (ntohs(ch->chunk_length) < sizeof(*ch)) {
@@ -3617,6 +3512,11 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
sizeof(struct sctp_chunkhdr), chunk_buf);
}
+ if (ch == NULL) {
+ /* Help */
+ *offset = length;
+ return (NULL);
+ }
if (ch->chunk_type == SCTP_COOKIE_ECHO) {
goto process_control_chunks;
}
@@ -3646,7 +3546,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
auth_len, chunk_buf);
got_auth = 1;
auth_skipped = 0;
- if (sctp_handle_auth(stcb, auth, m,
+ if ((auth == NULL) || sctp_handle_auth(stcb, auth, m,
auth_offset)) {
/* auth HMAC failed so dump it */
*offset = length;
@@ -3704,11 +3604,9 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
/* for all other chunks, vtag must match */
if (vtag_in != asoc->my_vtag) {
/* invalid vtag... */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("invalid vtag: %xh, expect %xh\n", vtag_in, asoc->my_vtag);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3,
+ "invalid vtag: %xh, expect %xh\n",
+ vtag_in, asoc->my_vtag);
SCTP_STAT_INCR(sctps_badvtag);
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -3733,12 +3631,8 @@ process_control_chunks:
while (IS_SCTP_CONTROL(ch)) {
/* validate chunk length */
chk_length = ntohs(ch->chunk_length);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
- printf("sctp_process_control: processing a chunk type=%u, len=%u\n",
- ch->chunk_type, chk_length);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT2, "sctp_process_control: processing a chunk type=%u, len=%u\n",
+ ch->chunk_type, chk_length);
if ((size_t)chk_length < sizeof(*ch) ||
(*offset + chk_length) > length) {
*offset = length;
@@ -3818,7 +3712,7 @@ process_control_chunks:
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
chk_length, chunk_buf);
if (ch == NULL) {
- printf("sctp_process_control: Can't get the all data....\n");
+ SCTP_PRINTF("sctp_process_control: Can't get the all data....\n");
*offset = length;
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -3829,13 +3723,14 @@ process_control_chunks:
num_chunks++;
/* Save off the last place we got a control from */
if (stcb != NULL) {
- if ((*netp != NULL) || (ch->chunk_type == SCTP_ASCONF)) {
+ if (((netp != NULL) && (*netp != NULL)) || (ch->chunk_type == SCTP_ASCONF)) {
/*
* allow last_control to be NULL if
* ASCONF... ASCONF processing will find the
* right net later
*/
- stcb->asoc.last_control_chunk_from = *netp;
+ if ((netp != NULL) && (*netp != NULL))
+ stcb->asoc.last_control_chunk_from = *netp;
}
}
#ifdef SCTP_AUDITING_ENABLED
@@ -3854,11 +3749,7 @@ process_control_chunks:
switch (ch->chunk_type) {
case SCTP_INITIATION:
/* must be first and only chunk */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_INIT\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_INIT\n");
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
/* We are not interested anymore? */
if ((stcb) && (stcb->asoc.total_output_queue_size)) {
@@ -3895,8 +3786,11 @@ process_control_chunks:
}
return (NULL);
}
- sctp_handle_init(m, iphlen, *offset, sh,
- (struct sctp_init_chunk *)ch, inp, stcb, *netp, &abort_no_unlock, vrf_id, table_id);
+ if (netp) {
+ sctp_handle_init(m, iphlen, *offset, sh,
+ (struct sctp_init_chunk *)ch, inp,
+ stcb, *netp, &abort_no_unlock, vrf_id, table_id);
+ }
if (abort_no_unlock)
return (NULL);
@@ -3908,11 +3802,7 @@ process_control_chunks:
break;
case SCTP_INITIATION_ACK:
/* must be first and only chunk */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_INIT-ACK\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_INIT-ACK\n");
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
/* We are not interested anymore */
if ((stcb) && (stcb->asoc.total_output_queue_size)) {
@@ -3936,8 +3826,12 @@ process_control_chunks:
}
return (NULL);
}
- ret = sctp_handle_init_ack(m, iphlen, *offset, sh,
- (struct sctp_init_ack_chunk *)ch, stcb, *netp, &abort_no_unlock, vrf_id, table_id);
+ if ((netp) && (*netp)) {
+ ret = sctp_handle_init_ack(m, iphlen, *offset, sh,
+ (struct sctp_init_ack_chunk *)ch, stcb, *netp, &abort_no_unlock, vrf_id, table_id);
+ } else {
+ ret = -1;
+ }
/*
* Special case, I must call the output routine to
* get the cookie echoed
@@ -3954,11 +3848,7 @@ process_control_chunks:
return (NULL);
break;
case SCTP_SELECTIVE_ACK:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_SACK\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SACK\n");
SCTP_STAT_INCR(sctps_recvsacks);
{
struct sctp_sack_chunk *sack;
@@ -3967,12 +3857,8 @@ process_control_chunks:
uint16_t num_seg;
int nonce_sum_flag;
- if (chk_length < sizeof(struct sctp_sack_chunk)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INDATA1) {
- printf("Bad size on sack chunk .. to small\n");
- }
-#endif
+ if ((stcb == NULL) || (chk_length < sizeof(struct sctp_sack_chunk))) {
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Bad size on sack chunk, too small\n");
*offset = length;
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -4004,7 +3890,8 @@ process_control_chunks:
sctp_express_handle_sack(stcb, cum_ack, a_rwnd, nonce_sum_flag,
&abort_now);
} else {
- sctp_handle_sack(sack, stcb, *netp, &abort_now, chk_length, a_rwnd);
+ if (netp && *netp)
+ sctp_handle_sack(sack, stcb, *netp, &abort_now, chk_length, a_rwnd);
}
if (abort_now) {
/* ABORT signal from sack processing */
@@ -4014,25 +3901,19 @@ process_control_chunks:
}
break;
case SCTP_HEARTBEAT_REQUEST:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_HEARTBEAT\n");
- }
-#endif /* SCTP_DEBUG */
- SCTP_STAT_INCR(sctps_recvheartbeat);
- sctp_send_heartbeat_ack(stcb, m, *offset, chk_length,
- *netp);
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_HEARTBEAT\n");
+ if ((stcb) && netp && *netp) {
+ SCTP_STAT_INCR(sctps_recvheartbeat);
+ sctp_send_heartbeat_ack(stcb, m, *offset,
+ chk_length, *netp);
- /* He's alive so give him credit */
- stcb->asoc.overall_error_count = 0;
+ /* He's alive so give him credit */
+ stcb->asoc.overall_error_count = 0;
+ }
break;
case SCTP_HEARTBEAT_ACK:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_HEARTBEAT-ACK\n");
- }
-#endif /* SCTP_DEBUG */
- if (chk_length != sizeof(struct sctp_heartbeat_chunk)) {
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_HEARTBEAT-ACK\n");
+ if ((stcb == NULL) || (chk_length != sizeof(struct sctp_heartbeat_chunk))) {
/* Its not ours */
*offset = length;
if (locked_tcb) {
@@ -4043,34 +3924,29 @@ process_control_chunks:
/* He's alive so give him credit */
stcb->asoc.overall_error_count = 0;
SCTP_STAT_INCR(sctps_recvheartbeatack);
- sctp_handle_heartbeat_ack((struct sctp_heartbeat_chunk *)ch,
- stcb, *netp);
+ if (netp && *netp)
+ sctp_handle_heartbeat_ack((struct sctp_heartbeat_chunk *)ch,
+ stcb, *netp);
break;
case SCTP_ABORT_ASSOCIATION:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_ABORT\n");
- }
-#endif /* SCTP_DEBUG */
- sctp_handle_abort((struct sctp_abort_chunk *)ch,
- stcb, *netp);
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ABORT\n");
+ if ((stcb) && netp && *netp)
+ sctp_handle_abort((struct sctp_abort_chunk *)ch,
+ stcb, *netp);
*offset = length;
return (NULL);
break;
case SCTP_SHUTDOWN:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_SHUTDOWN\n");
- }
-#endif /* SCTP_DEBUG */
- if (chk_length != sizeof(struct sctp_shutdown_chunk)) {
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN\n");
+ if ((stcb == NULL) || (chk_length != sizeof(struct sctp_shutdown_chunk))) {
*offset = length;
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
}
return (NULL);
- } {
+ }
+ if (netp && *netp) {
int abort_flag = 0;
sctp_handle_shutdown((struct sctp_shutdown_chunk *)ch,
@@ -4082,37 +3958,28 @@ process_control_chunks:
}
break;
case SCTP_SHUTDOWN_ACK:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_SHUTDOWN-ACK\n");
- }
-#endif /* SCTP_DEBUG */
- sctp_handle_shutdown_ack((struct sctp_shutdown_ack_chunk *)ch, stcb, *netp);
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN-ACK\n");
+ if ((stcb) && (netp) && (*netp))
+ sctp_handle_shutdown_ack((struct sctp_shutdown_ack_chunk *)ch, stcb, *netp);
*offset = length;
return (NULL);
break;
+
case SCTP_OPERATION_ERROR:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_OP-ERR\n");
- }
-#endif /* SCTP_DEBUG */
- if ((stcb) && sctp_handle_error(ch, stcb, *netp) < 0) {
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_OP-ERR\n");
+ if ((stcb) && netp && *netp && sctp_handle_error(ch, stcb, *netp) < 0) {
+
*offset = length;
return (NULL);
}
break;
case SCTP_COOKIE_ECHO:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_COOKIE-ECHO stcb is %p\n", stcb);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3,
+ "SCTP_COOKIE-ECHO stcb is %p\n", stcb);
if ((stcb) && (stcb->asoc.total_output_queue_size)) {
;
} else {
- if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) &&
- (stcb == NULL)) {
+ if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
/* We are not interested anymore */
*offset = length;
return (NULL);
@@ -4120,8 +3987,8 @@ process_control_chunks:
}
/*
* First are we accepting? We do this again here
- * since it is possible that a previous endpoint WAS
- * listening responded to a INIT-ACK and then
+ * sincen it is possible that a previous endpoint
+ * WAS listening responded to a INIT-ACK and then
* closed. We opened and bound.. and are now no
* longer listening.
*/
@@ -4174,35 +4041,39 @@ process_control_chunks:
struct mbuf *ret_buf;
struct sctp_inpcb *linp;
- if (stcb)
+ if (stcb) {
linp = NULL;
- else
+ } else {
linp = inp;
+ }
- if (linp)
+ if (linp) {
SCTP_ASOC_CREATE_LOCK(linp);
- ret_buf =
- sctp_handle_cookie_echo(m, iphlen,
- *offset, sh,
- (struct sctp_cookie_echo_chunk *)ch,
- &inp, &stcb, netp,
- auth_skipped,
- auth_offset,
- auth_len,
- &locked_tcb,
- vrf_id,
- table_id);
- if (linp)
+ }
+ if (netp) {
+ ret_buf =
+ sctp_handle_cookie_echo(m, iphlen,
+ *offset, sh,
+ (struct sctp_cookie_echo_chunk *)ch,
+ &inp, &stcb, netp,
+ auth_skipped,
+ auth_offset,
+ auth_len,
+ &locked_tcb,
+ vrf_id,
+ table_id);
+ } else {
+ ret_buf = NULL;
+ }
+ if (linp) {
SCTP_ASOC_CREATE_UNLOCK(linp);
+ }
if (ret_buf == NULL) {
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("GAK, null buffer\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3,
+ "GAK, null buffer\n");
auth_skipped = 0;
*offset = length;
return (NULL);
@@ -4229,12 +4100,8 @@ process_control_chunks:
}
break;
case SCTP_COOKIE_ACK:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_COOKIE-ACK\n");
- }
-#endif /* SCTP_DEBUG */
- if (chk_length != sizeof(struct sctp_cookie_ack_chunk)) {
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_COOKIE-ACK\n");
+ if ((stcb == NULL) || chk_length != sizeof(struct sctp_cookie_ack_chunk)) {
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
}
@@ -4244,26 +4111,22 @@ process_control_chunks:
/* We are not interested anymore */
if ((stcb) && (stcb->asoc.total_output_queue_size)) {
;
- } else {
+ } else if (stcb) {
sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_INPUT + SCTP_LOC_27);
*offset = length;
return (NULL);
}
}
/* He's alive so give him credit */
- if (stcb) {
+ if ((stcb) && netp && *netp) {
stcb->asoc.overall_error_count = 0;
sctp_handle_cookie_ack((struct sctp_cookie_ack_chunk *)ch, stcb, *netp);
}
break;
case SCTP_ECN_ECHO:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_ECN-ECHO\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ECN-ECHO\n");
/* He's alive so give him credit */
- if (chk_length != sizeof(struct sctp_ecne_chunk)) {
+ if ((stcb == NULL) || (chk_length != sizeof(struct sctp_ecne_chunk))) {
/* Its not ours */
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -4278,13 +4141,9 @@ process_control_chunks:
}
break;
case SCTP_ECN_CWR:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_ECN-CWR\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ECN-CWR\n");
/* He's alive so give him credit */
- if (chk_length != sizeof(struct sctp_cwr_chunk)) {
+ if ((stcb == NULL) || (chk_length != sizeof(struct sctp_cwr_chunk))) {
/* Its not ours */
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -4298,11 +4157,7 @@ process_control_chunks:
}
break;
case SCTP_SHUTDOWN_COMPLETE:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_SHUTDOWN-COMPLETE\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN-COMPLETE\n");
/* must be first and only chunk */
if ((num_chunks > 1) ||
(length - *offset > SCTP_SIZE32(chk_length))) {
@@ -4312,7 +4167,7 @@ process_control_chunks:
}
return (NULL);
}
- if (stcb) {
+ if ((stcb) && netp && *netp) {
sctp_handle_shutdown_complete((struct sctp_shutdown_complete_chunk *)ch,
stcb, *netp);
}
@@ -4320,11 +4175,7 @@ process_control_chunks:
return (NULL);
break;
case SCTP_ASCONF:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_ASCONF\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ASCONF\n");
/* He's alive so give him credit */
if (stcb) {
stcb->asoc.overall_error_count = 0;
@@ -4333,11 +4184,7 @@ process_control_chunks:
}
break;
case SCTP_ASCONF_ACK:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_ASCONF-ACK\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ASCONF-ACK\n");
if (chk_length < sizeof(struct sctp_asconf_ack_chunk)) {
/* Its not ours */
if (locked_tcb) {
@@ -4346,7 +4193,7 @@ process_control_chunks:
*offset = length;
return (NULL);
}
- if (stcb) {
+ if ((stcb) && netp && *netp) {
/* He's alive so give him credit */
stcb->asoc.overall_error_count = 0;
sctp_handle_asconf_ack(m, *offset,
@@ -4354,11 +4201,7 @@ process_control_chunks:
}
break;
case SCTP_FORWARD_CUM_TSN:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_FWD-TSN\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_FWD-TSN\n");
if (chk_length < sizeof(struct sctp_forward_tsn_chunk)) {
/* Its not ours */
if (locked_tcb) {
@@ -4391,14 +4234,10 @@ process_control_chunks:
}
break;
case SCTP_STREAM_RESET:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_STREAM_RESET\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_STREAM_RESET\n");
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
chk_length, chunk_buf);
- if (chk_length < sizeof(struct sctp_stream_reset_tsn_req)) {
+ if (((stcb == NULL) || (ch == NULL) || (chk_length < sizeof(struct sctp_stream_reset_tsn_req)))) {
/* Its not ours */
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -4412,29 +4251,22 @@ process_control_chunks:
*offset = length;
return (NULL);
}
- if (stcb) {
- if (stcb->asoc.peer_supports_strreset == 0) {
- /*
- * hmm, peer should have announced
- * this, but we will turn it on
- * since he is sending us a stream
- * reset.
- */
- stcb->asoc.peer_supports_strreset = 1;
- }
- if (sctp_handle_stream_reset(stcb, (struct sctp_stream_reset_out_req *)ch)) {
- /* stop processing */
- *offset = length;
- return (NULL);
- }
+ if (stcb->asoc.peer_supports_strreset == 0) {
+ /*
+ * hmm, peer should have announced this, but
+ * we will turn it on since he is sending us
+ * a stream reset.
+ */
+ stcb->asoc.peer_supports_strreset = 1;
+ }
+ if (sctp_handle_stream_reset(stcb, (struct sctp_stream_reset_out_req *)ch)) {
+ /* stop processing */
+ *offset = length;
+ return (NULL);
}
break;
case SCTP_PACKET_DROPPED:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_PACKET_DROPPED\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_PACKET_DROPPED\n");
/* re-get it all please */
if (chk_length < sizeof(struct sctp_pktdrop_chunk)) {
/* Its not ours */
@@ -4447,18 +4279,14 @@ process_control_chunks:
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
chk_length, chunk_buf);
- if ((stcb) && (*netp)) {
+ if (ch && (stcb) && netp && (*netp)) {
sctp_handle_packet_dropped((struct sctp_pktdrop_chunk *)ch,
stcb, *netp);
}
break;
case SCTP_AUTHENTICATION:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("SCTP_AUTHENTICATION\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_AUTHENTICATION\n");
if (sctp_auth_disable)
goto unknown_chunk;
@@ -4473,7 +4301,8 @@ process_control_chunks:
goto next_chunk;
}
if ((chk_length < (sizeof(struct sctp_auth_chunk))) ||
- (chk_length > (sizeof(struct sctp_auth_chunk) + SCTP_AUTH_DIGEST_LEN_MAX))) {
+ (chk_length > (sizeof(struct sctp_auth_chunk) +
+ SCTP_AUTH_DIGEST_LEN_MAX))) {
/* Its not ours */
if (locked_tcb) {
SCTP_TCB_UNLOCK(locked_tcb);
@@ -4488,7 +4317,7 @@ process_control_chunks:
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
chk_length, chunk_buf);
got_auth = 1;
- if (sctp_handle_auth(stcb, (struct sctp_auth_chunk *)ch,
+ if ((ch == NULL) || sctp_handle_auth(stcb, (struct sctp_auth_chunk *)ch,
m, *offset)) {
/* auth HMAC failed so dump the packet */
*offset = length;
@@ -4646,12 +4475,8 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset,
sctp_auditing(0, inp, stcb, net);
#endif
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Ok, Common input processing called, m:%p iphlen:%d offset:%d\n",
- m, iphlen, offset);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Ok, Common input processing called, m:%p iphlen:%d offset:%d\n",
+ m, iphlen, offset);
if (stcb) {
/* always clear this before beginning a packet */
@@ -4725,10 +4550,8 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset,
!stcb->asoc.authenticated) {
/* "silently" ignore */
SCTP_STAT_INCR(sctps_recvauthmissing);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("Data chunk requires AUTH, skipped\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1,
+ "Data chunk requires AUTH, skipped\n");
goto trigger_send;
}
if (length > offset) {
@@ -4819,31 +4642,20 @@ trigger_send:
sctp_audit_log(0xE0, 2);
sctp_auditing(1, inp, stcb, net);
#endif
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Check for chunk output prw:%d tqe:%d tf=%d\n",
- stcb->asoc.peers_rwnd,
- TAILQ_EMPTY(&stcb->asoc.control_send_queue),
- stcb->asoc.total_flight);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1,
+ "Check for chunk output prw:%d tqe:%d tf=%d\n",
+ stcb->asoc.peers_rwnd,
+ TAILQ_EMPTY(&stcb->asoc.control_send_queue),
+ stcb->asoc.total_flight);
un_sent = (stcb->asoc.total_output_queue_size - stcb->asoc.total_flight);
if (!TAILQ_EMPTY(&stcb->asoc.control_send_queue) ||
((un_sent) &&
(stcb->asoc.peers_rwnd > 0 ||
(stcb->asoc.peers_rwnd <= 0 && stcb->asoc.total_flight == 0)))) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("Calling chunk OUTPUT\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT3, "Calling chunk OUTPUT\n");
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CONTROL_PROC);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("chunk OUTPUT returns\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT3, "chunk OUTPUT returns\n");
}
#ifdef SCTP_AUDITING_ENABLED
sctp_audit_log(0xE0, 3);
@@ -4952,16 +4764,13 @@ sctp_input(i_pak, off)
sh->checksum = 0; /* prepare for calc */
calc_check = sctp_calculate_sum(m, &mlen, iphlen);
if (calc_check != check) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Bad CSUM on SCTP packet calc_check:%x check:%x m:%p mlen:%d iphlen:%d\n",
- calc_check, check, m, mlen, iphlen);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Bad CSUM on SCTP packet calc_check:%x check:%x m:%p mlen:%d iphlen:%d\n",
+ calc_check, check, m, mlen, iphlen);
stcb = sctp_findassociation_addr(m, iphlen,
offset - sizeof(*ch),
- sh, ch, &inp, &net, vrf_id);
+ sh, ch, &inp, &net,
+ vrf_id);
if ((inp) && (stcb)) {
sctp_send_packet_dropped(stcb, net, m, iphlen, 1);
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_INPUT_ERROR);
@@ -5005,11 +4814,8 @@ sctp_skip_csum_4:
if (badport_bandlim(0) < 0)
goto bad;
#endif /* ICMP_BANDLIM */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Sending a ABORT from packet entry!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1,
+ "Sending a ABORT from packet entry!\n");
if (ch->chunk_type == SCTP_INITIATION) {
/*
* we do a trick here to get the INIT tag, dig in
@@ -5073,9 +4879,9 @@ sctp_skip_csum_4:
}
return;
bad:
- if (stcb)
+ if (stcb) {
SCTP_TCB_UNLOCK(stcb);
-
+ }
if ((inp) && (refcount_up)) {
/* reduce ref-count */
SCTP_INP_WLOCK(inp);
@@ -5085,8 +4891,5 @@ bad:
if (m) {
sctp_m_freem(m);
}
- /* For BSD/MAC this does nothing */
- SCTP_DETACH_HEADER_FROM_CHAIN(i_pak);
- SCTP_RELEASE_HEADER(i_pak);
return;
}
diff --git a/sys/netinet/sctp_os_bsd.h b/sys/netinet/sctp_os_bsd.h
index 9bd267b..5847d422 100644
--- a/sys/netinet/sctp_os_bsd.h
+++ b/sys/netinet/sctp_os_bsd.h
@@ -124,12 +124,20 @@ __FBSDID("$FreeBSD$");
} \
} while (0); \
}
-#define SCTP_PRINTF(params...) printf(params)
+#define SCTPDBG_PKT(level, iph, sh) \
+{ \
+ do { \
+ if (sctp_debug_on & level) { \
+ sctp_print_address_pkt(iph, sh); \
+ } \
+ } while (0); \
+}
#else
#define SCTPDBG(level, params...)
#define SCTPDBG_ADDR(level, addr)
-#define SCTP_PRINTF(params...)
+#define SCTPDBG_PKT(level, iph, sh)
#endif
+#define SCTP_PRINTF(params...) printf(params)
/*
* Local address and interface list handling
diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index 5bae5f2..3ec5245 100644
--- a/sys/netinet/sctp_output.c
+++ b/sys/netinet/sctp_output.c
@@ -2184,42 +2184,24 @@ sctp_is_ifa_addr_preferred(struct sctp_ifa *ifa,
if ((dest_is_priv == 0) && (dest_is_loop == 0)) {
dest_is_global = 1;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Is destination preferred:");
- sctp_print_address(&ifa->address.sa);
- }
-#endif
-
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Is destination preferred:");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ifa->address.sa);
/* Ok the address may be ok */
if (fam == AF_INET6) {
/* ok to use deprecated addresses? */
if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:1\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:1\n");
return (NULL);
}
if (ifa->src_is_priv) {
if (dest_is_loop) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:2\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:2\n");
return (NULL);
}
}
if (ifa->src_is_glob) {
-
if (dest_is_loop) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:3\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:3\n");
return (NULL);
}
}
@@ -2229,54 +2211,28 @@ sctp_is_ifa_addr_preferred(struct sctp_ifa *ifa,
* theory be done slicker (it used to be), but this is
* straightforward and easier to validate :-)
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("src_loop:%d src_priv:%d src_glob:%d\n",
- ifa->src_is_loop, ifa->src_is_priv,
- ifa->src_is_glob);
- printf("dest_loop:%d dest_priv:%d dest_glob:%d\n",
- dest_is_loop, dest_is_priv,
- dest_is_global);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "src_loop:%d src_priv:%d src_glob:%d\n",
+ ifa->src_is_loop, ifa->src_is_priv, ifa->src_is_glob);
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "dest_loop:%d dest_priv:%d dest_glob:%d\n",
+ dest_is_loop, dest_is_priv, dest_is_global);
if ((ifa->src_is_loop) && (dest_is_priv)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:4\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:4\n");
return (NULL);
}
if ((ifa->src_is_glob) && (dest_is_priv)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:5\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:5\n");
return (NULL);
}
if ((ifa->src_is_loop) && (dest_is_global)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:6\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:6\n");
return (NULL);
}
if ((ifa->src_is_priv) && (dest_is_global)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("NO:7\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:7\n");
return (NULL);
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("YES\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "YES\n");
/* its a preferred address */
return (ifa);
}
@@ -2356,11 +2312,8 @@ sctp_is_addr_restricted(struct sctp_tcb *stcb, struct sctp_ifa *ifa)
}
LIST_FOREACH(laddr, &stcb->asoc.sctp_restricted_addrs, sctp_nxt_addr) {
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("Help I have fallen and I can't get up!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
+ __FUNCTION__);
continue;
}
if (laddr->ifa == ifa) {
@@ -2381,11 +2334,8 @@ sctp_is_addr_in_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
return (0);
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("Help I have fallen and I can't get up!\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
+ __FUNCTION__);
continue;
}
if ((laddr->ifa == ifa) && laddr->action == 0)
@@ -2621,7 +2571,8 @@ sctp_from_the_top2:
/* address has been removed */
continue;
}
- sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop, dest_is_priv, fam);
+ sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop,
+ dest_is_priv, fam);
if (sifa == NULL)
continue;
if ((non_asoc_addr_ok == 0) &&
@@ -2653,13 +2604,16 @@ sctp_select_nth_preferred_addr_from_ifn_boundall(struct sctp_ifn *ifn,
int num_eligible_addr = 0;
LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) {
- if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0))
+ if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
+ (non_asoc_addr_ok == 0))
continue;
- sifa = sctp_is_ifa_addr_preferred(ifa, dest_is_loop, dest_is_priv, fam);
+ sifa = sctp_is_ifa_addr_preferred(ifa, dest_is_loop,
+ dest_is_priv, fam);
if (sifa == NULL)
continue;
if (stcb) {
- if ((non_asoc_addr_ok == 0) && sctp_is_addr_restricted(stcb, sifa)) {
+ if ((non_asoc_addr_ok == 0) &&
+ sctp_is_addr_restricted(stcb, sifa)) {
/*
* It is restricted for some reason..
* probably not yet added.
@@ -2688,15 +2642,18 @@ sctp_count_num_preferred_boundall(struct sctp_ifn *ifn,
int num_eligible_addr = 0;
LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) {
- if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0)) {
+ if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
+ (non_asoc_addr_ok == 0)) {
continue;
}
- sifa = sctp_is_ifa_addr_preferred(ifa, dest_is_loop, dest_is_priv, fam);
+ sifa = sctp_is_ifa_addr_preferred(ifa, dest_is_loop,
+ dest_is_priv, fam);
if (sifa == NULL) {
continue;
}
if (stcb) {
- if ((non_asoc_addr_ok == 0) && sctp_is_addr_restricted(stcb, sifa)) {
+ if ((non_asoc_addr_ok == 0) &&
+ sctp_is_addr_restricted(stcb, sifa)) {
/*
* It is restricted for some reason..
* probably not yet added.
@@ -2728,7 +2685,7 @@ sctp_choose_boundall(struct sctp_inpcb *inp,
struct sctp_vrf *vrf;
/*
- * For boundall we can use any address in the association. If
+ * For boundall we can use any address in the association. If
* non_asoc_addr_ok is set we can use any address (at least in
* theory). So we look for preferred addresses first. If we find
* one, we use it. Otherwise we next try to get an address on the
@@ -2761,11 +2718,8 @@ sctp_choose_boundall(struct sctp_inpcb *inp,
non_asoc_addr_ok,
dest_is_loop,
dest_is_priv, fam);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Found %d preferred source addresses\n", num_preferred);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Found %d preferred source addresses\n",
+ num_preferred);
if (num_preferred == 0) {
/*
* no eligible addresses, we must use some other interface
@@ -2785,11 +2739,8 @@ sctp_choose_boundall(struct sctp_inpcb *inp,
* select the nth address from the list (where cur_addr_num is the
* nth) and 0 is the first one, 1 is the second one etc...
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("cur_addr_num:%d\n", cur_addr_num);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "cur_addr_num:%d\n", cur_addr_num);
+
sctp_ifa = sctp_select_nth_preferred_addr_from_ifn_boundall(sctp_ifn, stcb, non_asoc_addr_ok, dest_is_loop,
dest_is_priv, cur_addr_num, fam);
@@ -2807,11 +2758,7 @@ sctp_choose_boundall(struct sctp_inpcb *inp,
* no preferred fall through to plan_c.
*/
bound_all_plan_b:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Plan B?\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Trying Plan B\n");
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
if (dest_is_loop == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
/* wrong base scope */
@@ -2822,25 +2769,16 @@ bound_all_plan_b:
continue;
num_preferred = sctp_count_num_preferred_boundall(sctp_ifn, stcb, non_asoc_addr_ok,
dest_is_loop, dest_is_priv, fam);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Found ifn:%p %d preferred source addresses\n", ifn, num_preferred);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2,
+ "Found ifn:%p %d preferred source addresses\n",
+ ifn, num_preferred);
if (num_preferred == 0) {
- /*
- * None on this interface.
- */
+ /* None on this interface. */
continue;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("num preferred:%d on interface:%p cur_addr_num:%d\n",
- num_preferred,
- sctp_ifn,
- cur_addr_num);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2,
+ "num preferred:%d on interface:%p cur_addr_num:%d\n",
+ num_preferred, sctp_ifn, cur_addr_num);
/*
* Ok we have num_eligible_addr set with how many we can
@@ -2856,30 +2794,20 @@ bound_all_plan_b:
continue;
if (net) {
net->indx_of_eligible_next_to_use = cur_addr_num + 1;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("we selected %d\n", cur_addr_num);
- printf("Source:");
- sctp_print_address(&sifa->address.sa);
- printf("Dest:");
- sctp_print_address(&net->ro._l_addr.sa);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "we selected %d\n",
+ cur_addr_num);
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Source:");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa);
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Dest:");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &net->ro._l_addr.sa);
}
atomic_add_int(&sifa->refcount, 1);
return (sifa);
}
- /*
- * plan_c: See if we have an acceptable address on the emit
- * interface
- */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Plan C no preferred for Dest, acceptable for?\n");
- }
-#endif
+ /* plan_c: do we have an acceptable address on the emit interface */
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Trying Plan C: find acceptable on interface\n");
if (emit_ifn == NULL) {
goto plan_d;
}
@@ -2911,11 +2839,7 @@ plan_d:
* out and see if we can find an acceptable address somewhere
* amongst all interfaces.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Plan C fails plan D?\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Trying Plan D\n");
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
if (dest_is_loop == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
/* wrong base scope */
@@ -3072,22 +2996,16 @@ sctp_source_address_selection(struct sctp_inpcb *inp,
dest_is_priv = 1;
}
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("Select source for:");
- sctp_print_address((struct sockaddr *)to);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "Select source addr for:");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)to);
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
/*
* When bound to all if the address list is set it is a
* negative list. Addresses being added by asconf.
*/
answer = sctp_choose_boundall(inp, stcb, net, ro, vrf_id,
- dest_is_priv,
- dest_is_loop,
- non_asoc_addr_ok,
- fam);
+ dest_is_priv, dest_is_loop,
+ non_asoc_addr_ok, fam);
return (answer);
}
/*
@@ -3108,12 +3026,15 @@ sctp_source_address_selection(struct sctp_inpcb *inp,
* address selection.
*/
if (stcb) {
- answer = sctp_choose_boundspecific_stcb(inp, stcb, net, ro, vrf_id,
- dest_is_priv, dest_is_loop, non_asoc_addr_ok, fam);
-
+ answer = sctp_choose_boundspecific_stcb(inp, stcb, net, ro,
+ vrf_id, dest_is_priv,
+ dest_is_loop,
+ non_asoc_addr_ok, fam);
} else {
- answer = sctp_choose_boundspecific_inp(inp, ro, vrf_id, non_asoc_addr_ok, dest_is_priv, dest_is_loop, fam);
-
+ answer = sctp_choose_boundspecific_inp(inp, ro, vrf_id,
+ non_asoc_addr_ok,
+ dest_is_priv,
+ dest_is_loop, fam);
}
return (answer);
}
@@ -3179,10 +3100,9 @@ sctp_add_cookie(struct sctp_inpcb *inp, struct mbuf *init, int init_offset,
uint16_t cookie_sz;
mret = NULL;
-
-
mret = sctp_get_mbuf_for_msg((sizeof(struct sctp_state_cookie) +
- sizeof(struct sctp_paramhdr)), 0, M_DONTWAIT, 1, MT_DATA);
+ sizeof(struct sctp_paramhdr)), 0,
+ M_DONTWAIT, 1, MT_DATA);
if (mret == NULL) {
return (NULL);
}
@@ -3278,11 +3198,12 @@ sctp_get_ect(struct sctp_tcb *stcb,
if (chk == NULL)
return (SCTP_ECT0_BIT);
- if (((stcb->asoc.hb_random_idx == 3) &&
- (stcb->asoc.hb_ect_randombit > 7)) ||
- (stcb->asoc.hb_random_idx > 3)) {
+ if ((stcb->asoc.hb_random_idx > 3) ||
+ ((stcb->asoc.hb_random_idx == 3) &&
+ (stcb->asoc.hb_ect_randombit > 7))) {
uint32_t rndval;
+warp_drive_sa:
rndval = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep);
memcpy(stcb->asoc.hb_random_values, &rndval,
sizeof(stcb->asoc.hb_random_values));
@@ -3293,6 +3214,9 @@ sctp_get_ect(struct sctp_tcb *stcb,
if (stcb->asoc.hb_ect_randombit > 7) {
stcb->asoc.hb_ect_randombit = 0;
stcb->asoc.hb_random_idx++;
+ if (stcb->asoc.hb_random_idx > 3) {
+ goto warp_drive_sa;
+ }
}
this_random = stcb->asoc.hb_random_values[stcb->asoc.hb_random_idx];
}
@@ -3447,12 +3371,13 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
net->ro._s_addr = sctp_source_address_selection(inp, stcb,
ro, net, out_of_asoc_ok,
vrf_id);
- if (net->ro._s_addr == NULL) {
- /* No route to host */
- goto no_route;
- }
net->src_addr_selected = 1;
}
+ if (net->ro._s_addr == NULL) {
+ /* No route to host */
+ net->src_addr_selected = 0;
+ goto no_route;
+ }
ip->ip_src = net->ro._s_addr->address.sin.sin_addr;
} else {
struct sctp_ifa *_lsrc;
@@ -3480,19 +3405,17 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
* here (yet)!
*/
no_route:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("low_level_output: dropped packet - no valid source addr\n");
- if (net) {
- printf("Destination was ");
- sctp_print_address(&net->ro._l_addr.sa);
- }
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_OUTPUT1,
+ "%s: dropped packet - no valid source addr\n",
+ __FUNCTION__);
if (net) {
+ SCTPDBG(SCTP_DEBUG_OUTPUT1,
+ "Destination was ");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT1,
+ &net->ro._l_addr.sa);
if (net->dest_state & SCTP_ADDR_CONFIRMED) {
if ((net->dest_state & SCTP_ADDR_REACHABLE) && stcb) {
- printf("no route takes interface %p down\n", net);
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "no route takes interface %p down\n", net);
sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
stcb,
SCTP_FAILED_THRESHOLD,
@@ -3527,14 +3450,12 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
if (ro != &iproute) {
memcpy(&iproute, ro, sizeof(*ro));
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("Calling ipv4 output routine from low level src addr:%x\n",
- (uint32_t) (ntohl(ip->ip_src.s_addr)));
- printf("Destination is %x\n", (uint32_t) (ntohl(ip->ip_dst.s_addr)));
- printf("RTP route is %p through\n", ro->ro_rt);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Calling ipv4 output routine from low level src addr:%x\n",
+ (uint32_t) (ntohl(ip->ip_src.s_addr)));
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Destination is %x\n",
+ (uint32_t) (ntohl(ip->ip_dst.s_addr)));
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "RTP route is %p through\n",
+ ro->ro_rt);
if (SCTP_GET_HEADER_FOR_OUTPUT(o_pak)) {
/* failed to prepend data, give up */
@@ -3551,11 +3472,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
if (ret)
SCTP_STAT_INCR(sctps_senderrors);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("Ip output returns %d\n", ret);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "IP output returns %d\n", ret);
if (net == NULL) {
/* free tempy routes */
if (ro->ro_rt) {
@@ -3571,7 +3488,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
if (mtu &&
(stcb->asoc.smallest_mtu > mtu)) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("sctp_mtu_size_reset called after ip_output mtu-change:%d\n",
+ SCTP_PRINTF("sctp_mtu_size_reset called after ip_output mtu-change:%d\n",
mtu);
#endif
sctp_mtu_size_reset(inp, &stcb->asoc, mtu);
@@ -3684,14 +3601,13 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
net,
out_of_asoc_ok,
vrf_id);
- if (net->ro._s_addr == NULL) {
-#ifdef SCTP_DEBUG
- printf("V6:No route to host\n");
-#endif
- goto no_route;
- }
net->src_addr_selected = 1;
}
+ if (net->ro._s_addr == NULL) {
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "V6:No route to host\n");
+ net->src_addr_selected = 0;
+ goto no_route;
+ }
lsa6->sin6_addr = net->ro._s_addr->address.sin6.sin6_addr;
} else {
struct sctp_ifa *_lsrc;
@@ -3738,18 +3654,16 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
ifp = SCTP_GET_IFN_VOID_FROM_ROUTE(ro);
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- /* Copy to be sure something bad is not happening */
- sin6->sin6_addr = ip6h->ip6_dst;
- lsa6->sin6_addr = ip6h->ip6_src;
-
- printf("Calling ipv6 output routine from low level\n");
- printf("src: ");
- sctp_print_address((struct sockaddr *)lsa6);
- printf("dst: ");
- sctp_print_address((struct sockaddr *)sin6);
- }
+ /* Copy to be sure something bad is not happening */
+ sin6->sin6_addr = ip6h->ip6_dst;
+ lsa6->sin6_addr = ip6h->ip6_src;
#endif
+
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Calling ipv6 output routine from low level\n");
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "src: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, (struct sockaddr *)lsa6);
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "dst: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, (struct sockaddr *)sin6);
if (net) {
sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
/* preserve the port and scope for link local send */
@@ -3772,11 +3686,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
sin6->sin6_scope_id = prev_scope;
sin6->sin6_port = prev_port;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("return from send is %d\n", ret);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "return from send is %d\n", ret);
SCTP_STAT_INCR(sctps_sendpackets);
SCTP_STAT_INCR_COUNTER64(sctps_outpackets);
if (ret) {
@@ -3805,7 +3715,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
if (mtu &&
(stcb->asoc.smallest_mtu > mtu)) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("sctp_mtu_size_reset called after ip6_output mtu-change:%d\n",
+ SCTP_PRINTF("sctp_mtu_size_reset called after ip6_output mtu-change:%d\n",
mtu);
#endif
sctp_mtu_size_reset(inp, &stcb->asoc, mtu);
@@ -3815,7 +3725,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
if (ND_IFINFO(ifp)->linkmtu &&
(stcb->asoc.smallest_mtu > ND_IFINFO(ifp)->linkmtu)) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("sctp_mtu_size_reset called via ifp ND_IFINFO() linkmtu:%d\n",
+ SCTP_PRINTF("sctp_mtu_size_reset called via ifp ND_IFINFO() linkmtu:%d\n",
ND_IFINFO(ifp)->linkmtu);
#endif
sctp_mtu_size_reset(inp,
@@ -3828,11 +3738,8 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp,
}
#endif
else {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("Unknown protocol (TSNH) type %d\n", ((struct sockaddr *)to)->sa_family);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "Unknown protocol (TSNH) type %d\n",
+ ((struct sockaddr *)to)->sa_family);
sctp_m_freem(m);
return (EFAULT);
}
@@ -3866,16 +3773,12 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
}
/* we confirm any address we send an INIT to */
net->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
- sctp_set_primary_addr(stcb, NULL, net);
+ (void)sctp_set_primary_addr(stcb, NULL, net);
} else {
/* we confirm any address we send an INIT to */
net->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
- printf("Sending INIT\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT\n");
if (((struct sockaddr *)&(net->ro._l_addr))->sa_family == AF_INET6) {
/*
* special hook, if we are sending to link local it will not
@@ -3892,10 +3795,8 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
return;
}
/* start the INIT timer */
- if (sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, net)) {
- /* we are hosed since I can't start the INIT timer? */
- return;
- }
+ sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, net);
+
m = sctp_get_mbuf_for_msg(MCLBYTES, 1, M_DONTWAIT, 1, MT_DATA);
if (m == NULL) {
/* No memory, INIT timer will re-attempt. */
@@ -4074,7 +3975,6 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
m_at = sctp_add_addresses_to_i_ia(inp, &scp, m_at, cnt_inits_to);
}
-
/* calulate the size and update pkt header and chunk header */
p_len = 0;
for (m_at = m; m_at; m_at = SCTP_BUF_NEXT(m_at)) {
@@ -4251,11 +4151,7 @@ sctp_arethere_unrecognized_parameters(struct mbuf *in_initpkt,
/* We can NOT handle HOST NAME addresses!! */
int l_len;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
- printf("Can't handle hostname addresses.. abort processing\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT4, "Can't handle hostname addresses.. abort processing\n");
*abort_processing = 1;
if (op_err == NULL) {
/* Ok need to try to get a mbuf */
@@ -5163,7 +5059,7 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
}
p_len += padval;
}
- sctp_lowlevel_chunk_output(inp, NULL, NULL, to, m, 0, NULL, 0, 0,
+ (void)sctp_lowlevel_chunk_output(inp, NULL, NULL, to, m, 0, NULL, 0, 0,
NULL, 0);
SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks);
}
@@ -5176,8 +5072,9 @@ sctp_insert_on_wheel(struct sctp_tcb *stcb,
{
struct sctp_stream_out *stre, *strn;
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_TCB_SEND_LOCK(stcb);
+ }
if ((strq->next_spoke.tqe_next) ||
(strq->next_spoke.tqe_prev)) {
/* already on wheel */
@@ -5204,10 +5101,9 @@ sctp_insert_on_wheel(struct sctp_tcb *stcb,
}
}
outof_here:
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_TCB_SEND_UNLOCK(stcb);
-
-
+ }
}
static void
@@ -5399,11 +5295,9 @@ sctp_set_prsctp_policy(struct sctp_tcb *stcb,
sp->ts.tv_usec = 0;
break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_USRREQ1) {
- printf("Unknown PR_SCTP policy %u.\n", PR_SCTP_POLICY(sp->sinfo_flags));
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_USRREQ1,
+ "Unknown PR_SCTP policy %u.\n",
+ PR_SCTP_POLICY(sp->sinfo_flags));
break;
}
}
@@ -5831,7 +5725,7 @@ sctp_sendall_iterator(struct sctp_inpcb *inp, struct sctp_tcb *stcb, void *ptr,
int frag_point;
frag_point = sctp_get_frag_point(stcb, &stcb->asoc);
- sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out,
+ (void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out,
&reason, 1, &cwnd_full, 1, &now, &now_filled, frag_point);
}
no_chunk_output:
@@ -5954,13 +5848,12 @@ sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m,
ca->m = m;
}
ret = sctp_initiate_iterator(NULL, sctp_sendall_iterator, NULL,
- SCTP_PCB_ANY_FLAGS, SCTP_PCB_ANY_FEATURES, SCTP_ASOC_ANY_STATE,
+ SCTP_PCB_ANY_FLAGS, SCTP_PCB_ANY_FEATURES,
+ SCTP_ASOC_ANY_STATE,
(void *)ca, 0,
sctp_sendall_completes, inp, 1);
if (ret) {
-#ifdef SCTP_DEBUG
- printf("Failed to initiate iterator for sendall\n");
-#endif
+ SCTP_PRINTF("Failed to initiate iterator for sendall\n");
SCTP_FREE(ca);
return (EFAULT);
}
@@ -6229,8 +6122,9 @@ one_more_time:
goto one_more_time;
}
if (strq->last_msg_incomplete) {
- printf("Huh? Stream:%d lm_in_c=%d but queue is NULL\n",
- strq->stream_no, strq->last_msg_incomplete);
+ SCTP_PRINTF("Huh? Stream:%d lm_in_c=%d but queue is NULL\n",
+ strq->stream_no,
+ strq->last_msg_incomplete);
strq->last_msg_incomplete = 0;
}
SCTP_TCB_SEND_UNLOCK(stcb);
@@ -6245,8 +6139,8 @@ one_more_time:
* sender_all_done was not set.
*/
if (sp->put_last_out == 0) {
- printf("Gak, put out entire msg with NO end!-1\n");
- printf("sender_done:%d len:%d msg_comp:%d put_last_out:%d send_lock:%d\n",
+ SCTP_PRINTF("Gak, put out entire msg with NO end!-1\n");
+ SCTP_PRINTF("sender_done:%d len:%d msg_comp:%d put_last_out:%d send_lock:%d\n",
sp->sender_all_done,
sp->length,
sp->msg_is_complete,
@@ -6420,7 +6314,7 @@ out_gu:
#ifdef INVARIANTS
panic("Huh, freing tail? - TSNH");
#else
- printf("Huh, freeing tail? - TSNH\n");
+ SCTP_PRINTF("Huh, freeing tail? - TSNH\n");
sp->tail_mbuf = sp->data = NULL;
sp->length = 0;
#endif
@@ -6438,7 +6332,7 @@ out_gu:
#ifdef INVARIANTS
panic("Huh, how can to_move be larger?");
#else
- printf("Huh, how can to_move be larger?\n");
+ SCTP_PRINTF("Huh, how can to_move be larger?\n");
sp->length = 0;
#endif
} else {
@@ -6489,7 +6383,7 @@ out_gu:
#ifdef INVARIANTS
panic("prepend failes HELP?");
#else
- printf("prepend fails HELP?\n");
+ SCTP_PRINTF("prepend fails HELP?\n");
sctp_free_a_chunk(stcb, chk);
#endif
goto out_gu;
@@ -6581,13 +6475,17 @@ out_gu:
/* We only re-set the policy if it is on */
if (sp->pr_sctp_on) {
sctp_set_prsctp_policy(stcb, sp);
+ asoc->pr_sctp_cnt++;
+ chk->pr_sctp_on = 1;
+ } else {
+ chk->pr_sctp_on = 0;
}
if (sp->msg_is_complete && (sp->length == 0) && (sp->sender_all_done)) {
/* All done pull and kill the message */
atomic_subtract_int(&asoc->stream_queue_cnt, 1);
if (sp->put_last_out == 0) {
- printf("Gak, put out entire msg with NO end!-2\n");
- printf("sender_done:%d len:%d msg_comp:%d put_last_out:%d send_lock:%d\n",
+ SCTP_PRINTF("Gak, put out entire msg with NO end!-2\n");
+ SCTP_PRINTF("sender_done:%d len:%d msg_comp:%d put_last_out:%d send_lock:%d\n",
sp->sender_all_done,
sp->length,
sp->msg_is_complete,
@@ -6614,12 +6512,6 @@ out_gu:
*locked = 1;
}
asoc->chunks_on_out_queue++;
- if (sp->pr_sctp_on) {
- asoc->pr_sctp_cnt++;
- chk->pr_sctp_on = 1;
- } else {
- chk->pr_sctp_on = 0;
- }
TAILQ_INSERT_TAIL(&asoc->send_queue, chk, sctp_next);
asoc->send_queue_cnt++;
if (send_lock_up) {
@@ -6962,7 +6854,7 @@ skip_the_fill_from_streams:
again_one_more_time:
for (net = send_start_at; net != NULL; net = TAILQ_NEXT(net, sctp_next)) {
/* how much can we send? */
- /* printf("Examine for sending net:%x\n", (uint32_t)net); */
+ /* SCTPDBG("Examine for sending net:%x\n", (uint32_t)net); */
if (old_startat && (old_startat == net)) {
/* through list ocmpletely. */
break;
@@ -7302,10 +7194,8 @@ again_one_more_time:
* a warning. This really should not
* happen ...
*/
-#ifdef SCTP_DEBUG
- printf("Warning chunk of %d bytes > mtu:%d and yet PMTU disc missed\n",
+ SCTP_PRINTF("Warning chunk of %d bytes > mtu:%d and yet PMTU disc missed\n",
chk->send_size, mtu);
-#endif
chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
}
if (((chk->send_size <= mtu) && (chk->send_size <= r_mtu)) ||
@@ -7332,11 +7222,7 @@ again_one_more_time:
outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, 0,
chk->send_size, chk->copy_by_ref);
if (outchain == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("No memory?\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "No memory?\n");
if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net);
}
@@ -7364,7 +7250,7 @@ again_one_more_time:
#ifdef INVARIANTS
panic("Exceeding mtu of %d out size is %d", mx_mtu, to_out);
#else
- printf("Exceeding mtu of %d out size is %d\n",
+ SCTP_PRINTF("Exceeding mtu of %d out size is %d\n",
mx_mtu, to_out);
#endif
}
@@ -7461,11 +7347,7 @@ again_one_more_time:
SCTP_STAT_INCR(sctps_lowlevelerrusr);
}
errored_send:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("Gak send error %d\n", error);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error);
if (hbflag) {
if (*now_filled == 0) {
(void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time);
@@ -8050,12 +7932,8 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp,
#endif
if ((TAILQ_EMPTY(&asoc->sent_queue)) &&
(TAILQ_EMPTY(&asoc->control_send_queue))) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("SCTP hits empty queue with cnt set to %d?\n",
- asoc->sent_queue_retran_cnt);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "SCTP hits empty queue with cnt set to %d?\n",
+ asoc->sent_queue_retran_cnt);
asoc->sent_queue_cnt = 0;
asoc->sent_queue_cnt_removeable = 0;
/* send back 0/0 so we enter normal transmission */
@@ -8167,16 +8045,12 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp,
if (chk->sent != SCTP_DATAGRAM_RESEND) {
/* No, not sent to this net or not ready for rtx */
continue;
-
}
if ((sctp_max_retran_chunk) && (chk->snd_count >= sctp_max_retran_chunk)) {
/* Gak, we have exceeded max unlucky retran, abort! */
-
-#ifdef SCTP_DEBUG
- printf("Gak, chk->snd_count:%d >= max:%d - send abort\n",
+ SCTP_PRINTF("Gak, chk->snd_count:%d >= max:%d - send abort\n",
chk->snd_count,
sctp_max_retran_chunk);
-#endif
sctp_send_abort_tcb(stcb, NULL);
sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, stcb, NULL);
return (SCTP_RETRAN_EXIT);
@@ -8513,11 +8387,7 @@ sctp_timer_validation(struct sctp_inpcb *inp,
}
SCTP_TCB_LOCK_ASSERT(stcb);
/* Gak, we did not have a timer somewhere */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("Deadlock avoided starting timer on a dest at retran\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Deadlock avoided starting timer on a dest at retran\n");
sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->primary_destination);
return (ret);
}
@@ -8576,7 +8446,7 @@ sctp_chunk_output(struct sctp_inpcb *inp,
*/
if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
sctp_send_sack(stcb);
- SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
}
while (asoc->sent_queue_retran_cnt) {
/*-
@@ -8620,7 +8490,7 @@ sctp_chunk_output(struct sctp_inpcb *inp,
#ifdef SCTP_AUDITING_ENABLED
sctp_auditing(8, inp, stcb, NULL);
#endif
- sctp_timer_validation(inp, stcb, asoc, ret);
+ (void)sctp_timer_validation(inp, stcb, asoc, ret);
return;
}
if (ret < 0) {
@@ -8714,11 +8584,7 @@ sctp_chunk_output(struct sctp_inpcb *inp,
&reason_code, 0, &cwnd_full, from_where,
&now, &now_filled, frag_point);
if (error) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("Error %d was returned from med-c-op\n", error);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "Error %d was returned from med-c-op\n", error);
#ifdef SCTP_LOG_MAXBURST
sctp_log_maxburst(stcb, asoc->primary_destination, error, burst_cnt, SCTP_MAX_BURST_ERROR_STOP);
#endif
@@ -8729,11 +8595,8 @@ sctp_chunk_output(struct sctp_inpcb *inp,
break;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
- printf("m-c-o put out %d\n", num_out);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT3, "m-c-o put out %d\n", num_out);
+
tot_out += num_out;
burst_cnt++;
#ifdef SCTP_CWND_LOGGING
@@ -8783,11 +8646,9 @@ sctp_chunk_output(struct sctp_inpcb *inp,
#ifdef SCTP_CWND_LOGGING
sctp_log_cwnd(stcb, NULL, tot_out, SCTP_SEND_NOW_COMPLETES);
#endif
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("Ok, we have put out %d chunks\n", tot_out);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "Ok, we have put out %d chunks\n",
+ tot_out);
+
/*-
* Now we need to clean up the control chunk chain if a ECNE is on
* it. It must be marked as UNSENT again so next call will continue
@@ -8819,8 +8680,8 @@ sctp_output(inp, m, addr, control, p, flags)
(struct uio *)NULL,
m,
control,
- flags,
- p));
+ flags, p
+ ));
}
void
@@ -8854,9 +8715,10 @@ send_forward_tsn(struct sctp_tcb *stcb,
chk->rec.chunk_id.id = SCTP_FORWARD_CUM_TSN;
chk->rec.chunk_id.can_take_data = 0;
chk->asoc = asoc;
+ chk->whoTo = NULL;
+
chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_DONTWAIT, 1, MT_DATA);
if (chk->data == NULL) {
- atomic_subtract_int(&chk->whoTo->ref_count, 1);
sctp_free_a_chunk(stcb, chk);
return;
}
@@ -9050,6 +8912,7 @@ sctp_send_sack(struct sctp_tcb *stcb)
a_chk->snd_count = 0;
a_chk->send_size = 0; /* fill in later */
a_chk->sent = SCTP_DATAGRAM_UNSENT;
+ a_chk->whoTo = NULL;
if ((asoc->numduptsns) ||
(asoc->last_data_chunk_from->dest_state & SCTP_ADDR_NOT_REACHABLE)
@@ -9324,7 +9187,7 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr)
shdr->checksum = 0;
auth_offset += sizeof(struct sctphdr);
- sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb,
+ (void)sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb,
stcb->asoc.primary_destination,
(struct sockaddr *)&stcb->asoc.primary_destination->ro._l_addr,
m_out, auth_offset, auth, 1, 0, NULL, 0);
@@ -9354,7 +9217,7 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb,
comp_cp->sh.checksum = 0;
SCTP_BUF_LEN(m_shutdown_comp) = sizeof(struct sctp_shutdown_complete_msg);
- sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net,
+ (void)sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net,
(struct sockaddr *)&net->ro._l_addr,
m_shutdown_comp, 0, NULL, 1, 0, NULL, 0);
SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks);
@@ -9375,8 +9238,6 @@ sctp_send_shutdown_complete2(struct mbuf *m, int iphlen, struct sctphdr *sh,
/* Get room for the largest message */
len = (sizeof(struct ip6_hdr) + sizeof(struct sctp_shutdown_complete_msg));
-
-
mout = sctp_get_mbuf_for_msg(len, 1, M_DONTWAIT, 1, MT_DATA);
if (mout == NULL) {
return;
@@ -9548,19 +9409,18 @@ sctp_select_hb_destination(struct sctp_tcb *stcb, struct timeval *now)
state_overide = 0;
}
- if (highest_ms && (((unsigned int)highest_ms >= hnet->RTO) || state_overide)) {
+ if (hnet && highest_ms && (((unsigned int)highest_ms >= hnet->RTO) || state_overide)) {
/*-
* Found the one with longest delay bounds OR it is
* unconfirmed and still not marked unreachable.
*/
+ SCTPDBG(SCTP_DEBUG_OUTPUT4, "net:%p is the hb winner -", hnet);
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
- printf("net:%p is the hb winner -",
- hnet);
- if (hnet)
- sctp_print_address((struct sockaddr *)&hnet->ro._l_addr);
- else
- printf(" none\n");
+ if (hnet) {
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT4,
+ (struct sockaddr *)&hnet->ro._l_addr);
+ } else {
+ SCTPDBG(SCTP_DEBUG_OUTPUT4, " none\n");
}
#endif
/* update the timer now */
@@ -9614,11 +9474,7 @@ sctp_send_hb(struct sctp_tcb *stcb, int user_req, struct sctp_nets *u_net)
}
sctp_alloc_a_chunk(stcb, chk);
if (chk == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
- printf("Gak, can't get a chunk for hb\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT4, "Gak, can't get a chunk for hb\n");
return (0);
}
chk->copy_by_ref = 0;
@@ -10327,12 +10183,8 @@ sctp_send_abort(struct mbuf *m, int iphlen, struct sctphdr *sh, uint32_t vtag,
/* zap the stack pointer to the route */
bzero(&ro, sizeof ro);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("sctp_send_abort calling ip_output:\n");
- sctp_print_address_pkt(iph_out, &abm->sh);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "sctp_send_abort calling ip_output:\n");
+ SCTPDBG_PKT(SCTP_DEBUG_OUTPUT2, iph_out, &abm->sh);
/* set IPv4 length */
iph_out->ip_len = len;
/* out it goes */
@@ -10350,12 +10202,8 @@ sctp_send_abort(struct mbuf *m, int iphlen, struct sctphdr *sh, uint32_t vtag,
/* zap the stack pointer to the route */
bzero(&ro, sizeof(ro));
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("sctp_send_abort calling ip6_output:\n");
- sctp_print_address_pkt((struct ip *)ip6_out, &abm->sh);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "sctp_send_abort calling ip6_output:\n");
+ SCTPDBG_PKT(SCTP_DEBUG_OUTPUT2, (struct ip *)ip6_out, &abm->sh);
ip6_out->ip6_plen = len - sizeof(*ip6_out);
SCTP_ATTACH_CHAIN(o_pak, mout, len);
SCTP_IP6_OUTPUT(ret, o_pak, &ro, &ifp, stcb, vrf_id, table_id);
@@ -10486,6 +10334,7 @@ sctp_send_operr_to(struct mbuf *m, int iphlen, struct mbuf *scm, uint32_t vtag,
out6->ip6_src = in6->ip6_dst;
out6->ip6_dst = in6->ip6_src;
out6->ip6_plen = len - sizeof(struct ip6_hdr);
+
#ifdef SCTP_DEBUG
bzero(&lsa6, sizeof(lsa6));
lsa6.sin6_len = sizeof(lsa6);
@@ -10495,14 +10344,12 @@ sctp_send_operr_to(struct mbuf *m, int iphlen, struct mbuf *scm, uint32_t vtag,
fsa6.sin6_len = sizeof(fsa6);
fsa6.sin6_family = AF_INET6;
fsa6.sin6_addr = out6->ip6_dst;
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT2) {
- printf("sctp_operr_to calling ipv6 output:\n");
- printf("src: ");
- sctp_print_address((struct sockaddr *)&lsa6);
- printf("dst ");
- sctp_print_address((struct sockaddr *)&fsa6);
- }
-#endif /* SCTP_DEBUG */
+#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "sctp_operr_to calling ipv6 output:\n");
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "src: ");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)&lsa6);
+ SCTPDBG(SCTP_DEBUG_OUTPUT2, "dst ");
+ SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)&fsa6);
SCTP_ATTACH_CHAIN(o_pak, mout, len);
SCTP_IP6_OUTPUT(ret, o_pak, &ro, &ifp, stcb, vrf_id, table_id);
@@ -10627,8 +10474,6 @@ sctp_copy_it_in(struct sctp_tcb *stcb,
*error = sctp_copy_one(sp, uio, resv_in_first);
if (*error) {
sctp_free_a_strmoq(stcb, sp);
- sp->data = NULL;
- sp->net = NULL;
sp = NULL;
} else {
if (sp->sinfo_flags & SCTP_ADDR_OVER) {
@@ -10729,6 +10574,9 @@ sctp_lower_sosend(struct socket *so,
error = EFAULT;
goto out_unlocked;
}
+ if ((uio == NULL) && (top == NULL)) {
+ return (EINVAL);
+ }
atomic_add_int(&inp->total_sends, 1);
if (uio)
sndlen = uio->uio_resid;
@@ -10907,6 +10755,7 @@ sctp_lower_sosend(struct socket *so,
if ((use_rcvinfo) && (srcv) &&
((srcv->sinfo_flags & SCTP_ABORT) ||
((srcv->sinfo_flags & SCTP_EOF) &&
+ (uio) &&
(uio->uio_resid == 0)))) {
/*-
* User asks to abort a non-existant assoc,
@@ -10927,7 +10776,7 @@ sctp_lower_sosend(struct socket *so,
SCTP_ASOC_CREATE_UNLOCK(inp);
create_lock_applied = 0;
} else {
- printf("Huh-3? create lock should have been on??\n");
+ SCTP_PRINTF("Huh-3? create lock should have been on??\n");
}
/*
* Turn on queue only flag to prevent data from
@@ -10965,18 +10814,11 @@ sctp_lower_sosend(struct socket *so,
asoc->initial_init_rto_max = initm.sinit_max_init_timeo;
if (asoc->streamoutcnt < asoc->pre_open_streams) {
/* Default is NOT correct */
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("Ok, defout:%d pre_open:%d\n",
- asoc->streamoutcnt, asoc->pre_open_streams);
- }
-#endif
- SCTP_FREE(asoc->strmout);
- asoc->strmout = NULL;
- asoc->streamoutcnt = asoc->pre_open_streams;
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "Ok, defout:%d pre_open:%d\n",
+ asoc->streamoutcnt, asoc->pre_open_streams);
/*
* What happens if this
- * fails? .. we panic ...
+ * fails? we panic ...
*/
{
struct sctp_stream_out *tmp_str;
@@ -10988,17 +10830,18 @@ sctp_lower_sosend(struct socket *so,
}
SCTP_MALLOC(tmp_str,
struct sctp_stream_out *,
- asoc->streamoutcnt *
- sizeof(struct sctp_stream_out),
+ (asoc->pre_open_streams *
+ sizeof(struct sctp_stream_out)),
"StreamsOut");
if (had_lock) {
SCTP_TCB_LOCK(stcb);
}
- if (asoc->strmout == NULL) {
- asoc->strmout = tmp_str;
- } else {
+ if (tmp_str != NULL) {
SCTP_FREE(asoc->strmout);
asoc->strmout = tmp_str;
+ asoc->streamoutcnt = asoc->pre_open_streams;
+ } else {
+ asoc->pre_open_streams = asoc->streamoutcnt;
}
}
for (i = 0; i < asoc->streamoutcnt; i++) {
@@ -11144,7 +10987,7 @@ sctp_lower_sosend(struct socket *so,
/* Are we aborting? */
if (srcv->sinfo_flags & SCTP_ABORT) {
struct mbuf *mm;
- int tot_demand, tot_out, max;
+ int tot_demand, tot_out = 0, max;
SCTP_STAT_INCR(sctps_sends_with_abort);
if ((SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_WAIT) ||
@@ -11163,7 +11006,6 @@ sctp_lower_sosend(struct socket *so,
mm = sctp_get_mbuf_for_msg(1, 0, M_WAIT, 1, MT_DATA);
- tot_out = 0;
cntm = top;
while (cntm) {
tot_out += SCTP_BUF_LEN(cntm);
@@ -11172,7 +11014,8 @@ sctp_lower_sosend(struct socket *so,
tot_demand = (tot_out + sizeof(struct sctp_paramhdr));
} else {
/* Must fit in a MTU */
- tot_out = uio->uio_resid;
+ if (uio)
+ tot_out = uio->uio_resid;
tot_demand = (tot_out + sizeof(struct sctp_paramhdr));
mm = sctp_get_mbuf_for_msg(tot_demand, 0, M_WAIT, 1, MT_DATA);
}
@@ -11375,7 +11218,7 @@ sctp_lower_sosend(struct socket *so,
#ifdef INVARIANTS
panic("Warning: Last msg marked incomplete, yet nothing left?");
#else
- printf("Warning: Last msg marked incomplete, yet nothing left?\n");
+ SCTP_PRINTF("Warning: Last msg marked incomplete, yet nothing left?\n");
strm->last_msg_incomplete = 0;
#endif
goto do_a_copy_in;
@@ -11633,10 +11476,9 @@ sctp_lower_sosend(struct socket *so,
asoc->stream_locked = 0;
}
} else {
- printf("Huh no sp TSNH?\n");
+ SCTP_PRINTF("Huh no sp TSNH?\n");
strm->last_msg_incomplete = 0;
asoc->stream_locked = 0;
-
}
SCTP_TCB_SEND_UNLOCK(stcb);
if (uio->uio_resid == 0) {
@@ -11843,17 +11685,14 @@ skip_out_eof:
SCTP_TCB_LOCK(stcb);
}
frag_point = sctp_get_frag_point(stcb, &stcb->asoc);
- sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out,
+ (void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out,
&reason, 1, &cwnd_full, 1, &now, &now_filled, frag_point);
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_OUTPUT1) {
- printf("USR Send complete qo:%d prw:%d unsent:%d tf:%d cooq:%d toqs:%d \n",
- queue_only, stcb->asoc.peers_rwnd, un_sent,
- stcb->asoc.total_flight, stcb->asoc.chunks_on_out_queue,
- stcb->asoc.total_output_queue_size);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_OUTPUT1, "USR Send complete qo:%d prw:%d unsent:%d tf:%d cooq:%d toqs:%d \n",
+ queue_only, stcb->asoc.peers_rwnd, un_sent,
+ stcb->asoc.total_flight, stcb->asoc.chunks_on_out_queue,
+ stcb->asoc.total_output_queue_size);
+
out:
out_unlocked:
diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c
index 58413ec..09bdd2e 100644
--- a/sys/netinet/sctp_pcb.c
+++ b/sys/netinet/sctp_pcb.c
@@ -445,11 +445,7 @@ sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index,
* Gak, what can we do? We have lost an address
* change can you say HOSED?
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Lost and address change ???\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_PCB1, "Lost and address change ???\n");
/* Opps, must decrement the count */
sctp_del_addr_from_vrf(vrf_id, addr, ifn_index);
return (NULL);
@@ -487,9 +483,7 @@ sctp_del_addr_from_vrf(uint32_t vrf_id, struct sockaddr *addr,
vrf = sctp_find_vrf(vrf_id);
if (vrf == NULL) {
-#ifdef SCTP_DEBUG
- printf("Can't find vrf_id:%d\n", vrf_id);
-#endif
+ SCTP_PRINTF("Can't find vrf_id:%d\n", vrf_id);
goto out_now;
}
sctp_ifap = sctp_find_ifa_by_addr(addr, vrf->vrf_id, 1);
@@ -510,11 +504,12 @@ sctp_del_addr_from_vrf(uint32_t vrf_id, struct sockaddr *addr,
}
#ifdef SCTP_DEBUG
else {
- printf("Del Addr-ifn:%d Could not find address:",
+ SCTPDBG(SCTP_DEBUG_PCB1, "Del Addr-ifn:%d Could not find address:",
ifn_index);
- sctp_print_address(addr);
+ SCTPDBG_ADDR(SCTP_DEBUG_PCB1, addr);
}
#endif
+
out_now:
SCTP_IPI_ADDR_UNLOCK();
if (sctp_ifap) {
@@ -526,11 +521,7 @@ out_now:
* Gak, what can we do? We have lost an address
* change can you say HOSED?
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Lost and address change ???\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_PCB1, "Lost and address change ???\n");
/* Opps, must decrement the count */
sctp_free_ifa(sctp_ifap);
@@ -615,19 +606,11 @@ sctp_tcb_special_locate(struct sctp_inpcb **inp_p, struct sockaddr *from,
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("An ounce of prevention is worth a pound of cure\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "%s: NULL ifa\n", __FUNCTION__);
continue;
}
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("ifa being deleted\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "ifa being deleted\n");
continue;
}
if (laddr->ifa->address.sa.sa_family ==
@@ -1138,25 +1121,14 @@ sctp_endpoint_probe(struct sockaddr *nam, struct sctppcbhead *head,
}
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("An ounce of prevention is worth a pound of cure\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "%s: NULL ifa\n",
+ __FUNCTION__);
continue;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Ok laddr->ifa:%p is possible, ",
- laddr->ifa);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "Ok laddr->ifa:%p is possible, ",
+ laddr->ifa);
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Huh IFA being deleted\n");
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "Huh IFA being deleted\n");
continue;
}
if (laddr->ifa->address.sa.sa_family == nam->sa_family) {
@@ -1189,7 +1161,8 @@ sctp_endpoint_probe(struct sockaddr *nam, struct sctppcbhead *head,
struct sctp_inpcb *
-sctp_pcb_findep(struct sockaddr *nam, int find_tcp_pool, int have_lock, uint32_t vrf_id)
+sctp_pcb_findep(struct sockaddr *nam, int find_tcp_pool, int have_lock,
+ uint32_t vrf_id)
{
/*
* First we check the hash table to see if someone has this port
@@ -1442,7 +1415,8 @@ sctp_findassoc_by_vtag(struct sockaddr *from, uint32_t vtag,
}
if (skip_src_check) {
*netp = NULL; /* unknown */
- *inp_p = stcb->sctp_ep;
+ if (inp_p)
+ *inp_p = stcb->sctp_ep;
SCTP_INP_INFO_RUNLOCK();
return (stcb);
}
@@ -1567,11 +1541,7 @@ sctp_findassociation_addr(struct mbuf *m, int iphlen, int offset,
retval = sctp_findassociation_addr_sa(to, from, &inp, netp,
find_tcp_pool, vrf_id);
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("retval:%p inp:%p\n", retval, inp);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "retval:%p inp:%p\n", retval, inp);
if (retval == NULL && inp) {
/* Found a EP but not this address */
if ((ch->chunk_type == SCTP_INITIATION) ||
@@ -1597,11 +1567,7 @@ sctp_findassociation_addr(struct mbuf *m, int iphlen, int offset,
}
}
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("retval is %p\n", retval);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "retval is %p\n", retval);
return (retval);
}
@@ -1652,11 +1618,8 @@ sctp_findassociation_ep_asconf(struct mbuf *m, int iphlen, int offset,
phdr = sctp_get_next_param(m, offset + sizeof(struct sctp_asconf_chunk),
&parm_buf, sizeof(struct sctp_paramhdr));
if (phdr == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("findassociation_ep_asconf: failed to get asconf lookup addr\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "%s: failed to get asconf lookup addr\n",
+ __FUNCTION__);
return NULL;
}
ptype = (int)((uint32_t) ntohs(phdr->param_type));
@@ -1672,11 +1635,8 @@ sctp_findassociation_ep_asconf(struct mbuf *m, int iphlen, int offset,
offset + sizeof(struct sctp_asconf_chunk),
&p6_buf.ph, sizeof(*p6));
if (p6 == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("findassociation_ep_asconf: failed to get asconf v6 lookup addr\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "%s: failed to get asconf v6 lookup addr\n",
+ __FUNCTION__);
return (NULL);
}
sin6 = (struct sockaddr_in6 *)&remote_store;
@@ -1697,11 +1657,8 @@ sctp_findassociation_ep_asconf(struct mbuf *m, int iphlen, int offset,
offset + sizeof(struct sctp_asconf_chunk),
&p4_buf.ph, sizeof(*p4));
if (p4 == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
- printf("findassociation_ep_asconf: failed to get asconf v4 lookup addr\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_INPUT3, "%s: failed to get asconf v4 lookup addr\n",
+ __FUNCTION__);
return (NULL);
}
sin = (struct sockaddr_in *)&remote_store;
@@ -1759,7 +1716,7 @@ sctp_inpcb_alloc(struct socket *so)
SCTP_INP_INFO_WLOCK();
inp = SCTP_ZONE_GET(sctppcbinfo.ipi_zone_ep, struct sctp_inpcb);
if (inp == NULL) {
- printf("Out of SCTP-INPCB structures - no resources\n");
+ SCTP_PRINTF("Out of SCTP-INPCB structures - no resources\n");
SCTP_INP_INFO_WUNLOCK();
return (ENOBUFS);
}
@@ -1819,7 +1776,7 @@ sctp_inpcb_alloc(struct socket *so)
inp->sctp_tcbhash = SCTP_HASH_INIT(sctp_pcbtblsize,
&inp->sctp_hashmark);
if (inp->sctp_tcbhash == NULL) {
- printf("Out of SCTP-INPCB->hashinit - no resources\n");
+ SCTP_PRINTF("Out of SCTP-INPCB->hashinit - no resources\n");
SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_ep, inp);
return (ENOBUFS);
}
@@ -1995,11 +1952,7 @@ sctp_move_pcb_and_assoc(struct sctp_inpcb *old_inp, struct sctp_inpcb *new_inp,
* HOSED. We probably should send an abort
* here.
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Association hosed in TCP model, out of laddr memory\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_PCB1, "Association hosed in TCP model, out of laddr memory\n");
continue;
}
SCTP_INCR_LADDR_COUNT();
@@ -2103,15 +2056,13 @@ sctp_inpcb_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
inp = (struct sctp_inpcb *)so->so_pcb;
ip_inp = (struct inpcb *)so->so_pcb;
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- if (addr) {
- printf("Bind called port:%d\n",
- ntohs(((struct sockaddr_in *)addr)->sin_port));
- printf("Addr :");
- sctp_print_address(addr);
- }
+ if (addr) {
+ SCTPDBG(SCTP_DEBUG_PCB1, "Bind called port:%d\n",
+ ntohs(((struct sockaddr_in *)addr)->sin_port));
+ SCTPDBG(SCTP_DEBUG_PCB1, "Addr :");
+ SCTPDBG_ADDR(SCTP_DEBUG_PCB1, addr);
}
-#endif /* SCTP_DEBUG */
+#endif
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
/* already did a bind, subsequent binds NOT allowed ! */
return (EINVAL);
@@ -2415,11 +2366,8 @@ sctp_inpcb_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
sctppcbinfo.hashmark)];
/* put it in the bucket */
LIST_INSERT_HEAD(head, inp, sctp_hash);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Main hash to bind at head:%p, bound port:%d\n", head, ntohs(lport));
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "Main hash to bind at head:%p, bound port:%d\n",
+ head, ntohs(lport));
/* set in the port */
inp->sctp_lport = lport;
@@ -2519,7 +2467,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from)
so = inp->sctp_socket;
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
/* been here before.. eeks.. get out of here */
- printf("This conflict in free SHOULD not be happening!\n");
+ SCTP_PRINTF("This conflict in free SHOULD not be happening!\n");
SCTP_ITERATOR_UNLOCK();
#ifdef SCTP_LOG_CLOSING
sctp_log_closing(inp, NULL, 1);
@@ -2530,9 +2478,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from)
SCTP_INP_INFO_WLOCK();
SCTP_INP_WLOCK(inp);
- /*
- * First time through we have the socket lock, after that no more.
- */
+ /* First time through we have the socket lock, after that no more. */
if (from == SCTP_CALLED_AFTER_CMPSET_OFCLOSE) {
/*
* Once we are in we can remove the flag from = 1 is only
@@ -2651,7 +2597,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from)
sp = TAILQ_LAST(&((asoc->asoc.locked_on_sending)->outqueue),
sctp_streamhead);
if (sp == NULL) {
- printf("Error, sp is NULL, locked on sending is %p strm:%d\n",
+ SCTP_PRINTF("Error, sp is NULL, locked on sending is %p strm:%d\n",
asoc->asoc.locked_on_sending,
asoc->asoc.locked_on_sending->stream_no);
} else {
@@ -2930,11 +2876,6 @@ sctp_findnet(struct sctp_tcb *stcb, struct sockaddr *addr)
}
-/*
- * add's a remote endpoint address, done with the INIT/INIT-ACK as well as
- * when a ASCONF arrives that adds it. It will also initialize all the cwnd
- * stats of stuff.
- */
int
sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id)
{
@@ -2959,6 +2900,13 @@ sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
net->ssthresh = stcb->asoc.peers_rwnd;
}
+
+
+/*
+ * add's a remote endpoint address, done with the INIT/INIT-ACK as well as
+ * when a ASCONF arrives that adds it. It will also initialize all the cwnd
+ * stats of stuff.
+ */
int
sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
int set_scope, int from)
@@ -2971,12 +2919,9 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
struct sctp_nets *net, *netfirst;
int addr_inscope;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Adding an address (from:%d) to the peer: ", from);
- sctp_print_address(newaddr);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "Adding an address (from:%d) to the peer: ",
+ from);
+ SCTPDBG_ADDR(SCTP_DEBUG_PCB1, newaddr);
netfirst = sctp_findnet(stcb, newaddr);
if (netfirst) {
@@ -3162,7 +3107,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
net->mtu = 0;
}
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("We have found an interface mtu of %d\n", net->mtu);
+ SCTP_PRINTF("We have found an interface mtu of %d\n", net->mtu);
#endif
if (net->mtu == 0) {
/* Huh ?? */
@@ -3172,7 +3117,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
rmtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, net->ro.ro_rt);
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("The route mtu is %d\n", rmtu);
+ SCTP_PRINTF("The route mtu is %d\n", rmtu);
#endif
if (rmtu == 0) {
/*
@@ -3192,8 +3137,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
}
if (from == SCTP_ALLOC_ASOC) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("New assoc sets mtu to :%d\n",
- net->mtu);
+ SCTP_PRINTF("New assoc sets mtu to :%d\n", net->mtu);
#endif
stcb->asoc.smallest_mtu = net->mtu;
}
@@ -3202,7 +3146,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
}
if (stcb->asoc.smallest_mtu > net->mtu) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("new address mtu:%d smaller than smallest:%d\n",
+ SCTP_PRINTF("new address mtu:%d smaller than smallest:%d\n",
net->mtu, stcb->asoc.smallest_mtu);
#endif
stcb->asoc.smallest_mtu = net->mtu;
@@ -3327,6 +3271,10 @@ sctp_aloc_assoc(struct sctp_inpcb *inp, struct sockaddr *firstaddr,
*error = ENOBUFS;
return (NULL);
}
+ if (firstaddr == NULL) {
+ *error = EINVAL;
+ return (NULL);
+ }
SCTP_INP_RLOCK(inp);
if (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) {
/*
@@ -3339,15 +3287,14 @@ sctp_aloc_assoc(struct sctp_inpcb *inp, struct sockaddr *firstaddr,
*error = EINVAL;
return (NULL);
}
+ SCTPDBG(SCTP_DEBUG_PCB3, "Allocate an association for peer:");
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB3) {
- printf("Allocate an association for peer:");
- if (firstaddr) {
- sctp_print_address(firstaddr);
- printf("Port:%d\n",
- ntohs(((struct sockaddr_in *)firstaddr)->sin_port));
- } else
- printf("None\n");
+ if (firstaddr) {
+ SCTPDBG_ADDR(SCTP_DEBUG_PCB3, firstaddr);
+ SCTPDBG(SCTP_DEBUG_PCB3, "Port:%d\n",
+ ntohs(((struct sockaddr_in *)firstaddr)->sin_port));
+ } else {
+ SCTPDBG(SCTP_DEBUG_PCB3, "None\n");
}
#endif /* SCTP_DEBUG */
if (firstaddr->sa_family == AF_INET) {
@@ -3474,11 +3421,7 @@ sctp_aloc_assoc(struct sctp_inpcb *inp, struct sockaddr *firstaddr,
LIST_INSERT_HEAD(head, stcb, sctp_tcbhash);
}
SCTP_INP_WUNLOCK(inp);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Association %p now allocated\n", stcb);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_PCB1, "Association %p now allocated\n", stcb);
return (stcb);
}
@@ -4275,11 +4218,8 @@ sctp_update_ep_vflag(struct sctp_inpcb *inp)
/* set the flag based on addresses on the ep list */
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
if (laddr->ifa == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("An ounce of prevention is worth a pound of cure\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_PCB1, "%s: NULL ifa\n",
+ __FUNCTION__);
continue;
}
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
@@ -4297,22 +4237,22 @@ sctp_update_ep_vflag(struct sctp_inpcb *inp)
* Add the address to the endpoint local address list There is nothing to be
* done if we are bound to all addresses
*/
-int
+void
sctp_add_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa, uint32_t action)
{
struct sctp_laddr *laddr;
- int fnd, error;
+ int fnd, error = 0;
fnd = 0;
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
/* You are already bound to all. You have it already */
- return (0);
+ return;
}
if (ifa->address.sa.sa_family == AF_INET6) {
if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
/* Can't bind a non-useable addr. */
- return (-1);
+ return;
}
}
/* first, is it already present? */
@@ -4327,7 +4267,7 @@ sctp_add_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa, uint32_t ac
/* Not in the ep list */
error = sctp_insert_laddr(&inp->sctp_addr_list, ifa, action);
if (error != 0)
- return (error);
+ return;
inp->laddr_count++;
/* update inp_vflag flags */
if (ifa->address.sa.sa_family == AF_INET6) {
@@ -4336,7 +4276,7 @@ sctp_add_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa, uint32_t ac
inp->ip_inp.inp.inp_vflag |= INP_IPV4;
}
}
- return (0);
+ return;
}
@@ -4368,7 +4308,7 @@ sctp_select_primary_destination(struct sctp_tcb *stcb)
* Delete the address from the endpoint local address list There is nothing
* to be done if we are bound to all addresses
*/
-int
+void
sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
{
struct sctp_laddr *laddr;
@@ -4377,7 +4317,7 @@ sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
fnd = 0;
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
/* You are already bound to all. You have it already */
- return (EINVAL);
+ return;
}
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
if (laddr->ifa == ifa) {
@@ -4387,7 +4327,7 @@ sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
}
if (fnd && (inp->laddr_count < 2)) {
/* can't delete unless there are at LEAST 2 addresses */
- return (-1);
+ return;
}
if (fnd) {
/*
@@ -4440,7 +4380,7 @@ sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
/* update inp_vflag flags */
sctp_update_ep_vflag(inp);
}
- return (0);
+ return;
}
/*
@@ -4449,13 +4389,12 @@ sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
* ASCONF-ACK response) For the subset binding, static case, this is a
* "valid" address list
*/
-int
+void
sctp_add_local_addr_assoc(struct sctp_tcb *stcb, struct sctp_ifa *ifa, int restricted_list)
{
struct sctp_inpcb *inp;
struct sctp_laddr *laddr;
struct sctpladdr *list;
- int error;
/*
* Assumes TCB is locked.. and possibly the INP. May need to
@@ -4467,21 +4406,19 @@ sctp_add_local_addr_assoc(struct sctp_tcb *stcb, struct sctp_ifa *ifa, int restr
if (ifa->address.sa.sa_family == AF_INET6) {
if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
/* Can't bind a non-existent addr. */
- return (-1);
+ return;
}
}
/* does the address already exist? */
LIST_FOREACH(laddr, list, sctp_nxt_addr) {
if (laddr->ifa == ifa) {
- return (-1);
+ return;
}
}
/* add to the list */
- error = sctp_insert_laddr(list, ifa, 0);
- if (error != 0)
- return (error);
- return (0);
+ (void)sctp_insert_laddr(list, ifa, 0);
+ return;
}
/*
@@ -4525,7 +4462,7 @@ sctp_remove_laddr(struct sctp_laddr *laddr)
/*
* Remove an address from the TCB local address list
*/
-int
+void
sctp_del_local_addr_assoc(struct sctp_tcb *stcb, struct sctp_ifa *ifa)
{
struct sctp_inpcb *inp;
@@ -4547,7 +4484,7 @@ sctp_del_local_addr_assoc(struct sctp_tcb *stcb, struct sctp_ifa *ifa)
(sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF) == 0)) {
if (stcb->asoc.numnets < 2) {
/* can't delete last address */
- return (-1);
+ return;
}
}
LIST_FOREACH(laddr, &stcb->asoc.sctp_restricted_addrs, sctp_nxt_addr) {
@@ -4556,12 +4493,12 @@ sctp_del_local_addr_assoc(struct sctp_tcb *stcb, struct sctp_ifa *ifa)
continue;
if (laddr->ifa == ifa) {
sctp_remove_laddr(laddr);
- return (0);
+ return;
}
}
/* address not found! */
- return (-1);
+ return;
}
static char sctp_pcb_initialized = 0;
@@ -5017,7 +4954,7 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
if (lptype == SCTP_IPV4_ADDRESS) {
if (plen !=
sizeof(struct sctp_asconf_addrv4_param)) {
- printf("Sizeof setprim in init/init ack not %d but %d - ignored\n",
+ SCTP_PRINTF("Sizeof setprim in init/init ack not %d but %d - ignored\n",
(int)sizeof(struct sctp_asconf_addrv4_param),
plen);
} else {
@@ -5028,7 +4965,7 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
} else if (lptype == SCTP_IPV6_ADDRESS) {
if (plen !=
sizeof(struct sctp_asconf_addr_param)) {
- printf("Sizeof setprim (v6) in init/init ack not %d but %d - ignored\n",
+ SCTP_PRINTF("Sizeof setprim (v6) in init/init ack not %d but %d - ignored\n",
(int)sizeof(struct sctp_asconf_addr_param),
plen);
} else {
@@ -5039,7 +4976,7 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
}
}
if (lsa) {
- sctp_set_primary_addr(stcb, sa, NULL);
+ (void)sctp_set_primary_addr(stcb, sa, NULL);
}
} else if (ptype == SCTP_PRSCTP_SUPPORTED) {
/* Peer supports pr-sctp */
@@ -5106,10 +5043,7 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
random_len = plen - sizeof(*p_random);
/* enforce the random length */
if (random_len != SCTP_AUTH_RANDOM_SIZE_REQUIRED) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_AUTH1)
- printf("SCTP: invalid RANDOM len\n");
-#endif
+ SCTPDBG(SCTP_DEBUG_AUTH1, "SCTP: invalid RANDOM len\n");
return (-27);
}
got_random = 1;
@@ -5514,12 +5448,10 @@ sctp_drain_mbufs(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
* if we see a possible attack underway just abort the association.
*/
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- if (cnt) {
- printf("Freed %d chunks from reneg harvest\n", cnt);
- }
+ if (cnt) {
+ SCTPDBG(SCTP_DEBUG_PCB1, "Freed %d chunks from reneg harvest\n", cnt);
}
-#endif /* SCTP_DEBUG */
+#endif
if (cnt) {
/*
* Now do we need to find a new
@@ -5538,7 +5470,7 @@ sctp_drain_mbufs(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
* have found NO data... wierd... we will start at
* end of mapping array.
*/
- printf("Gap was larger than array?? %d set to max:%d maparraymax:%x\n",
+ SCTP_PRINTF("Gap was larger than array?? %d set to max:%d maparraymax:%x\n",
(int)gap,
(int)(asoc->mapping_array_size << 3),
(int)asoc->highest_tsn_inside_map);
@@ -5661,8 +5593,9 @@ sctp_initiate_iterator(inp_func inpf,
}
SCTP_IPI_ITERATOR_WQ_LOCK();
- if (it->inp)
+ if (it->inp) {
SCTP_INP_INCR_REF(it->inp);
+ }
TAILQ_INSERT_TAIL(&sctppcbinfo.iteratorhead, it, sctp_nxt_itr);
#if defined(SCTP_USE_THREAD_BASED_ITERATOR)
if (sctppcbinfo.iterator_running == 0) {
diff --git a/sys/netinet/sctp_pcb.h b/sys/netinet/sctp_pcb.h
index 6b0dfbb..230cbf5 100644
--- a/sys/netinet/sctp_pcb.h
+++ b/sys/netinet/sctp_pcb.h
@@ -486,13 +486,13 @@ int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
void
sctp_add_vtag_to_timewait(struct sctp_inpcb *, uint32_t, uint32_t);
-int sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
+void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
int sctp_insert_laddr(struct sctpladdr *, struct sctp_ifa *, uint32_t);
void sctp_remove_laddr(struct sctp_laddr *);
-int sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
+void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
void sctp_set_initial_cc_param(struct sctp_tcb *, struct sctp_nets *net);
@@ -505,9 +505,9 @@ int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
void sctp_pcb_init(void);
-int sctp_add_local_addr_assoc(struct sctp_tcb *, struct sctp_ifa *, int);
+void sctp_add_local_addr_assoc(struct sctp_tcb *, struct sctp_ifa *, int);
-int sctp_del_local_addr_assoc(struct sctp_tcb *, struct sctp_ifa *);
+void sctp_del_local_addr_assoc(struct sctp_tcb *, struct sctp_ifa *);
int
sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
diff --git a/sys/netinet/sctp_peeloff.c b/sys/netinet/sctp_peeloff.c
index 9618ae7..df4afdc 100644
--- a/sys/netinet/sctp_peeloff.c
+++ b/sys/netinet/sctp_peeloff.c
@@ -113,12 +113,7 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
struct sctp_inpcb *inp, *n_inp;
struct sctp_tcb *stcb;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PEEL1) {
- printf("SCTP peel-off called\n");
- }
-#endif /* SCTP_DEBUG */
-
+ SCTPDBG(SCTP_DEBUG_PEEL1, "SCTP peel-off called\n");
inp = (struct sctp_inpcb *)head->so_pcb;
if (inp == NULL) {
*error = EFAULT;
@@ -132,11 +127,7 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
newso = sonewconn(head, SS_ISCONNECTED
);
if (newso == NULL) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PEEL1) {
- printf("sctp_peeloff:sonewconn failed err\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_PEEL1, "sctp_peeloff:sonewconn failed\n");
*error = ENOMEM;
SCTP_TCB_UNLOCK(stcb);
return (NULL);
diff --git a/sys/netinet/sctp_timer.c b/sys/netinet/sctp_timer.c
index a8594c9..b027f0b 100644
--- a/sys/netinet/sctp_timer.c
+++ b/sys/netinet/sctp_timer.c
@@ -171,13 +171,9 @@ sctp_audit_retranmission_queue(struct sctp_association *asoc)
{
struct sctp_tmit_chunk *chk;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
- printf("Audit invoked on send queue cnt:%d onqueue:%d\n",
- asoc->sent_queue_retran_cnt,
- asoc->sent_queue_cnt);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER4, "Audit invoked on send queue cnt:%d onqueue:%d\n",
+ asoc->sent_queue_retran_cnt,
+ asoc->sent_queue_cnt);
asoc->sent_queue_retran_cnt = 0;
asoc->sent_queue_cnt = 0;
TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
@@ -191,13 +187,9 @@ sctp_audit_retranmission_queue(struct sctp_association *asoc)
sctp_ucount_incr(asoc->sent_queue_retran_cnt);
}
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
- printf("Audit completes retran:%d onqueue:%d\n",
- asoc->sent_queue_retran_cnt,
- asoc->sent_queue_cnt);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER4, "Audit completes retran:%d onqueue:%d\n",
+ asoc->sent_queue_retran_cnt,
+ asoc->sent_queue_cnt);
}
int
@@ -206,13 +198,9 @@ sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
{
if (net) {
net->error_count++;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
- printf("Error count for %p now %d thresh:%d\n",
- net, net->error_count,
- net->failure_threshold);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER4, "Error count for %p now %d thresh:%d\n",
+ net, net->error_count,
+ net->failure_threshold);
if (net->error_count > net->failure_threshold) {
/* We had a threshold failure */
if (net->dest_state & SCTP_ADDR_REACHABLE) {
@@ -245,15 +233,10 @@ sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
} else {
stcb->asoc.overall_error_count++;
}
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
- printf("Overall error count for %p now %d thresh:%u state:%x\n",
- &stcb->asoc,
- stcb->asoc.overall_error_count,
- (uint32_t) threshold,
- ((net == NULL) ? (uint32_t) 0 : (uint32_t) net->dest_state));
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER4, "Overall error count for %p now %d thresh:%u state:%x\n",
+ &stcb->asoc, stcb->asoc.overall_error_count,
+ (uint32_t) threshold,
+ ((net == NULL) ? (uint32_t) 0 : (uint32_t) net->dest_state));
/*
* We specifically do not do >= to give the assoc one more change
* before we fail it.
@@ -528,7 +511,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
MAX_TSN)) ||
(stcb->asoc.last_acked_seq == chk->rec.data.TSN_seq)) {
/* Strange case our list got out of order? */
- printf("Our list is out of order?\n");
+ SCTP_PRINTF("Our list is out of order?\n");
panic("Out of order list");
}
if ((chk->whoTo == net) && (chk->sent < SCTP_DATAGRAM_ACKED)) {
@@ -587,7 +570,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
(now.tv_usec > chk->rec.data.timetodrop.tv_usec))) {
/* Yes so drop it */
if (chk->data) {
- sctp_release_pr_sctp_chunk(stcb,
+ (void)sctp_release_pr_sctp_chunk(stcb,
chk,
(SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
&stcb->asoc.sent_queue);
@@ -599,7 +582,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
/* Has it been retransmitted tv_sec times? */
if (chk->snd_count > chk->rec.data.timetodrop.tv_sec) {
if (chk->data) {
- sctp_release_pr_sctp_chunk(stcb,
+ (void)sctp_release_pr_sctp_chunk(stcb,
chk,
(SCTP_RESPONSE_TO_USER_REQ | SCTP_NOTIFY_DATAGRAM_SENT),
&stcb->asoc.sent_queue);
@@ -678,17 +661,16 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
sctp_log_fr(tsnfirst, tsnlast, num_mk, SCTP_FR_T3_TIMEOUT);
#endif
#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- if (num_mk) {
- printf("LAST TSN marked was %x\n", tsnlast);
- printf("Num marked for retransmission was %d peer-rwd:%ld\n",
- num_mk, (u_long)stcb->asoc.peers_rwnd);
- printf("LAST TSN marked was %x\n", tsnlast);
- printf("Num marked for retransmission was %d peer-rwd:%d\n",
- num_mk,
- (int)stcb->asoc.peers_rwnd
- );
- }
+ if (num_mk) {
+ SCTPDBG(SCTP_DEBUG_TIMER1, "LAST TSN marked was %x\n",
+ tsnlast);
+ SCTPDBG(SCTP_DEBUG_TIMER1, "Num marked for retransmission was %d peer-rwd:%ld\n",
+ num_mk, (u_long)stcb->asoc.peers_rwnd);
+ SCTPDBG(SCTP_DEBUG_TIMER1, "LAST TSN marked was %x\n",
+ tsnlast);
+ SCTPDBG(SCTP_DEBUG_TIMER1, "Num marked for retransmission was %d peer-rwd:%d\n",
+ num_mk,
+ (int)stcb->asoc.peers_rwnd);
}
#endif
*num_marked = num_mk;
@@ -700,7 +682,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
}
if (stcb->asoc.sent_queue_retran_cnt != cnt_mk) {
#ifdef INVARIANTS
- printf("Local Audit says there are %d for retran asoc cnt:%d\n",
+ SCTP_PRINTF("Local Audit says there are %d for retran asoc cnt:%d\n",
cnt_mk, stcb->asoc.sent_queue_retran_cnt);
#endif
#ifndef SCTP_AUDITING_ENABLED
@@ -721,23 +703,17 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
}
}
if (audit_tf) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
- printf("Audit total flight due to negative value net:%p\n",
- net);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER4,
+ "Audit total flight due to negative value net:%p\n",
+ net);
stcb->asoc.total_flight = 0;
stcb->asoc.total_flight_count = 0;
/* Clear all networks flight size */
TAILQ_FOREACH(lnets, &stcb->asoc.nets, sctp_next) {
lnets->flight_size = 0;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
- printf("Net:%p c-f cwnd:%d ssthresh:%d\n",
- lnets, lnets->cwnd, lnets->ssthresh);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER4,
+ "Net:%p c-f cwnd:%d ssthresh:%d\n",
+ lnets, lnets->cwnd, lnets->ssthresh);
}
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
if (chk->sent < SCTP_DATAGRAM_RESEND) {
@@ -867,7 +843,7 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
alt = sctp_find_alternate_net(stcb, net, 0);
}
- sctp_mark_all_for_resend(stcb, net, alt, win_probe, &num_mk);
+ (void)sctp_mark_all_for_resend(stcb, net, alt, win_probe, &num_mk);
/* FR Loss recovery just ended with the T3. */
stcb->asoc.fast_retran_loss_recovery = 0;
@@ -1082,7 +1058,7 @@ sctp_cookie_timer(struct sctp_inpcb *inp,
#ifdef INVARIANTS
panic("Cookie timer expires in wrong state?");
#else
- printf("Strange in state %d not cookie-echoed yet c-e timer expires?\n", SCTP_GET_STATE(&stcb->asoc));
+ SCTP_PRINTF("Strange in state %d not cookie-echoed yet c-e timer expires?\n", SCTP_GET_STATE(&stcb->asoc));
return (0);
#endif
}
@@ -1130,7 +1106,7 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
return (0);
}
/* find the existing STRRESET, we use the seq number we sent out on */
- sctp_find_stream_reset(stcb, stcb->asoc.str_reset_seq_out, &strrst);
+ (void)sctp_find_stream_reset(stcb, stcb->asoc.str_reset_seq_out, &strrst);
if (strrst == NULL) {
return (0);
}
@@ -1222,11 +1198,7 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* properly handling the chunk type upper bits Mark
* this peer as ASCONF incapable and cleanup
*/
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("asconf_timer: Peer has not responded to our repeated ASCONFs\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER1, "asconf_timer: Peer has not responded to our repeated ASCONFs\n");
sctp_asconf_cleanup(stcb, net);
return (0);
}
@@ -1339,7 +1311,7 @@ sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp,
return;
if (stcb->asoc.sent_queue_retran_cnt) {
- printf("Hmm, sent_queue_retran_cnt is non-zero %d\n",
+ SCTP_PRINTF("Hmm, sent_queue_retran_cnt is non-zero %d\n",
stcb->asoc.sent_queue_retran_cnt);
stcb->asoc.sent_queue_retran_cnt = 0;
}
@@ -1356,7 +1328,7 @@ sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp,
}
if (cnt) {
/* yep, we lost a spoke or two */
- printf("Found an additional %d streams NOT on outwheel, corrected\n", cnt);
+ SCTP_PRINTF("Found an additional %d streams NOT on outwheel, corrected\n", cnt);
} else {
/* no spokes lost, */
stcb->asoc.total_output_queue_size = 0;
@@ -1376,7 +1348,7 @@ sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp,
}
}
if (chks_in_queue != stcb->asoc.stream_queue_cnt) {
- printf("Hmm, stream queue cnt at %d I counted %d in stream out wheel\n",
+ SCTP_PRINTF("Hmm, stream queue cnt at %d I counted %d in stream out wheel\n",
stcb->asoc.stream_queue_cnt, chks_in_queue);
}
if (chks_in_queue) {
@@ -1389,12 +1361,12 @@ sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp,
* and add fragments allowed
*/
if (being_filled == 0) {
- printf("Still nothing moved %d chunks are stuck\n",
+ SCTP_PRINTF("Still nothing moved %d chunks are stuck\n",
chks_in_queue);
}
}
} else {
- printf("Found no chunks on any queue tot:%lu\n",
+ SCTP_PRINTF("Found no chunks on any queue tot:%lu\n",
(u_long)stcb->asoc.total_output_queue_size);
stcb->asoc.total_output_queue_size = 0;
}
@@ -1544,15 +1516,16 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
if ((net->src_addr_selected == 0) ||
(net->ro._s_addr == NULL) ||
(net->ro._s_addr->localifa_flags & SCTP_BEING_DELETED)) {
- if ((net->ro._s_addr == NULL) && (net->ro._s_addr->localifa_flags & SCTP_BEING_DELETED)) {
+ if ((net->ro._s_addr != NULL) && (net->ro._s_addr->localifa_flags & SCTP_BEING_DELETED)) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
net->src_addr_selected = 0;
+ } else if (net->ro._s_addr == NULL) {
+ net->ro._s_addr = sctp_source_address_selection(inp,
+ stcb,
+ (sctp_route_t *) & net->ro,
+ net, 0, stcb->asoc.vrf_id);
}
- net->ro._s_addr = sctp_source_address_selection(inp,
- stcb,
- (sctp_route_t *) & net->ro,
- net, 0, stcb->asoc.vrf_id);
if (net->ro._s_addr)
net->src_addr_selected = 1;
}
@@ -1688,7 +1661,7 @@ select_a_new_ep:
}
if ((it->inp->inp_starting_point_for_iterator != NULL) &&
(it->inp->inp_starting_point_for_iterator != it)) {
- printf("Iterator collision, waiting for one at %p\n",
+ SCTP_PRINTF("Iterator collision, waiting for one at %p\n",
it->inp);
SCTP_INP_WUNLOCK(it->inp);
goto start_timer_return;
diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c
index 611c582..f5bbbfc 100644
--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -111,7 +111,7 @@ sctp_pathmtu_adjustment(struct sctp_inpcb *inp,
stcb->asoc.smallest_mtu = nxtsz;
/* now off to subtract IP_DF flag if needed */
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("sctp_pathmtu_adjust called inp:%p stcb:%p net:%p nxtsz:%d\n",
+ SCTP_PRINTF("sctp_pathmtu_adjust called inp:%p stcb:%p net:%p nxtsz:%d\n",
inp, stcb, net, nxtsz);
#endif
TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
@@ -160,8 +160,9 @@ sctp_notify_mbuf(struct sctp_inpcb *inp,
/* protection */
if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
(ip == NULL) || (sh == NULL)) {
- if (stcb != NULL)
+ if (stcb != NULL) {
SCTP_TCB_UNLOCK(stcb);
+ }
return;
}
/* First job is to verify the vtag matches what I would send */
@@ -205,7 +206,7 @@ sctp_notify_mbuf(struct sctp_inpcb *inp,
/* now what about the ep? */
if (stcb->asoc.smallest_mtu > nxtsz) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("notify_mbuf (ICMP) calls sctp_pathmtu_adjust mtu:%d\n",
+ SCTP_PRINTF("notify_mbuf (ICMP) calls sctp_pathmtu_adjust mtu:%d\n",
nxtsz);
#endif
sctp_pathmtu_adjustment(inp, stcb, net, nxtsz);
@@ -251,7 +252,7 @@ sctp_notify(struct sctp_inpcb *inp,
if ((error == EHOSTUNREACH) || (error == EHOSTDOWN)) {
if (net->dest_state & SCTP_ADDR_REACHABLE) {
/* Ok that destination is NOT reachable */
- printf("ICMP (thresh %d/%d) takes interface %p down\n",
+ SCTP_PRINTF("ICMP (thresh %d/%d) takes interface %p down\n",
net->error_count,
net->failure_threshold,
net);
@@ -263,8 +264,9 @@ sctp_notify(struct sctp_inpcb *inp,
stcb, SCTP_FAILED_THRESHOLD,
(void *)net);
}
- if (stcb)
+ if (stcb) {
SCTP_TCB_UNLOCK(stcb);
+ }
} else {
/*
* Here the peer is either playing tricks on us,
@@ -280,10 +282,9 @@ sctp_notify(struct sctp_inpcb *inp,
}
} else {
/* Send all others to the app */
- if (stcb)
+ if (stcb) {
SCTP_TCB_UNLOCK(stcb);
-
-
+ }
if (inp->sctp_socket) {
#ifdef SCTP_LOCK_LOGGING
sctp_log_lock(inp, stcb, SCTP_LOG_LOCK_SOCK);
@@ -665,7 +666,7 @@ connected_type:
/* now what about control */
if (control) {
if (inp->control) {
- printf("huh? control set?\n");
+ SCTP_PRINTF("huh? control set?\n");
sctp_m_freem(inp->control);
inp->control = NULL;
}
@@ -812,7 +813,7 @@ sctp_disconnect(struct socket *so)
sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
if (sp == NULL) {
- printf("Error, sp is NULL, locked on sending is non-null strm:%d\n",
+ SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
asoc->locked_on_sending->stream_no);
} else {
if ((sp->length == 0) && (sp->msg_is_complete == 0))
@@ -862,7 +863,6 @@ sctp_disconnect(struct socket *so)
return (0);
}
/* not reached */
- printf("Not reached reached?\n");
} else {
/* UDP model does not support this */
SCTP_INP_RUNLOCK(inp);
@@ -950,7 +950,7 @@ sctp_shutdown(struct socket *so)
sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
if (sp == NULL) {
- printf("Error, sp is NULL, locked on sending is non-null strm:%d\n",
+ SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
asoc->locked_on_sending->stream_no);
} else {
if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
@@ -1258,11 +1258,7 @@ sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
uint32_t vrf_id;
sctp_assoc_t *a_id;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_PCB1) {
- printf("Connectx called\n");
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
@@ -1374,7 +1370,7 @@ out_now:
return error;
}
-#define SCTP_FIND_STCB(inp, stcb, assoc_id) \
+#define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { \
SCTP_INP_RLOCK(inp); \
stcb = LIST_FIRST(&inp->sctp_asoc_list); \
@@ -1389,15 +1385,18 @@ out_now:
} \
} else { \
stcb = NULL; \
- }
+ } \
+ }
-#define SCTP_CHECK_AND_CAST(destp, srcp, type, size) \
+
+#define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
if (size < sizeof(type)) { \
error = EINVAL; \
break; \
} else { \
destp = (type *)srcp; \
- }
+ } \
+ }
static int
sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
@@ -2284,7 +2283,7 @@ sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
error = EINVAL;
} else {
/* copy in the chunks */
- sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
+ (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
}
SCTP_TCB_UNLOCK(stcb);
} else {
@@ -2297,7 +2296,7 @@ sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
error = EINVAL;
} else {
/* copy in the chunks */
- sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
+ (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
}
SCTP_INP_RUNLOCK(inp);
}
@@ -2322,7 +2321,7 @@ sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
error = EINVAL;
} else {
/* copy in the chunks */
- sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
+ (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
}
SCTP_TCB_UNLOCK(stcb);
} else {
@@ -2352,12 +2351,12 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
uint32_t vrf_id;
if (optval == NULL) {
- printf("optval is NULL\n");
+ SCTP_PRINTF("optval is NULL\n");
return (EINVAL);
}
inp = (struct sctp_inpcb *)so->so_pcb;
if (inp == 0) {
- printf("inp is NULL?\n");
+ SCTP_PRINTF("inp is NULL?\n");
return EINVAL;
}
vrf_id = inp->def_vrf_id;
@@ -2552,8 +2551,8 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
size_t size;
SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
- SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id)
- size = optsize - sizeof(*sca);
+ SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
+ size = optsize - sizeof(*sca);
if (stcb) {
/* set it on the assoc */
@@ -3052,7 +3051,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
net->mtu = paddrp->spp_pathmtu;
if (net->mtu < stcb->asoc.smallest_mtu) {
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("SCTP_PMTU_DISABLE calls sctp_pathmtu_adjustment:%d\n",
+ SCTP_PRINTF("SCTP_PMTU_DISABLE calls sctp_pathmtu_adjustment:%d\n",
net->mtu);
#endif
sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
@@ -3420,7 +3419,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
*/
if (addrs->sget_assoc_id == 0) {
/* delete the address */
- sctp_addr_mgmt_ep_sa(inp, addr_touse,
+ (void)sctp_addr_mgmt_ep_sa(inp, addr_touse,
SCTP_DEL_IP_ADDRESS, vrf_id);
} else {
/*
@@ -3587,9 +3586,9 @@ sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
sctp_send_initiate(inp, stcb);
SCTP_TCB_UNLOCK(stcb);
out_now:
- if (create_lock_on)
+ if (create_lock_on) {
SCTP_ASOC_CREATE_UNLOCK(inp);
-
+ }
SCTP_INP_DECR_REF(inp);
return error;
}
@@ -3870,8 +3869,9 @@ sctp_peeraddr(struct socket *so, struct sockaddr **addr)
}
SCTP_INP_RLOCK(inp);
stcb = LIST_FIRST(&inp->sctp_asoc_list);
- if (stcb)
+ if (stcb) {
SCTP_TCB_LOCK(stcb);
+ }
SCTP_INP_RUNLOCK(inp);
if (stcb == NULL) {
SCTP_FREE_SONAME(sin);
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index 58064da..0a2d4f4 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -244,7 +244,7 @@ sctp_log_strm_del(struct sctp_queued_to_read *control, struct sctp_queued_to_rea
int sctp_cwnd_log_at;
if (control == NULL) {
- printf("Gak log of NULL?\n");
+ SCTP_PRINTF("Gak log of NULL?\n");
return;
}
SCTP_STATLOG_GETREF(sctp_cwnd_log_at);
@@ -583,41 +583,41 @@ sctp_print_audit_report(void)
if ((sctp_audit_data[i][0] == 0xe0) &&
(sctp_audit_data[i][1] == 0x01)) {
cnt = 0;
- printf("\n");
+ SCTP_PRINTF("\n");
} else if (sctp_audit_data[i][0] == 0xf0) {
cnt = 0;
- printf("\n");
+ SCTP_PRINTF("\n");
} else if ((sctp_audit_data[i][0] == 0xc0) &&
(sctp_audit_data[i][1] == 0x01)) {
- printf("\n");
+ SCTP_PRINTF("\n");
cnt = 0;
}
- printf("%2.2x%2.2x ", (uint32_t) sctp_audit_data[i][0],
+ SCTP_PRINTF("%2.2x%2.2x ", (uint32_t) sctp_audit_data[i][0],
(uint32_t) sctp_audit_data[i][1]);
cnt++;
if ((cnt % 14) == 0)
- printf("\n");
+ SCTP_PRINTF("\n");
}
for (i = 0; i < sctp_audit_indx; i++) {
if ((sctp_audit_data[i][0] == 0xe0) &&
(sctp_audit_data[i][1] == 0x01)) {
cnt = 0;
- printf("\n");
+ SCTP_PRINTF("\n");
} else if (sctp_audit_data[i][0] == 0xf0) {
cnt = 0;
- printf("\n");
+ SCTP_PRINTF("\n");
} else if ((sctp_audit_data[i][0] == 0xc0) &&
(sctp_audit_data[i][1] == 0x01)) {
- printf("\n");
+ SCTP_PRINTF("\n");
cnt = 0;
}
- printf("%2.2x%2.2x ", (uint32_t) sctp_audit_data[i][0],
+ SCTP_PRINTF("%2.2x%2.2x ", (uint32_t) sctp_audit_data[i][0],
(uint32_t) sctp_audit_data[i][1]);
cnt++;
if ((cnt % 14) == 0)
- printf("\n");
+ SCTP_PRINTF("\n");
}
- printf("\n");
+ SCTP_PRINTF("\n");
}
void
@@ -677,7 +677,7 @@ sctp_auditing(int from, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
sctp_audit_indx = 0;
}
- printf("resend_cnt:%d asoc-tot:%d\n",
+ SCTP_PRINTF("resend_cnt:%d asoc-tot:%d\n",
resend_cnt, stcb->asoc.sent_queue_retran_cnt);
rep = 1;
stcb->asoc.sent_queue_retran_cnt = resend_cnt;
@@ -697,7 +697,7 @@ sctp_auditing(int from, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
sctp_audit_indx = 0;
}
rep = 1;
- printf("tot_flt:%d asoc_tot:%d\n", tot_out,
+ SCTP_PRINTF("tot_flt:%d asoc_tot:%d\n", tot_out,
(int)stcb->asoc.total_flight);
stcb->asoc.total_flight = tot_out;
}
@@ -709,7 +709,7 @@ sctp_auditing(int from, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
sctp_audit_indx = 0;
}
rep = 1;
- printf("tot_flt_book:%d\n", tot_book);
+ SCTP_PRINTF("tot_flt_book:%d\n", tot_book);
stcb->asoc.total_flight_count = tot_book_cnt;
}
@@ -725,7 +725,7 @@ sctp_auditing(int from, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
sctp_audit_indx = 0;
}
rep = 1;
- printf("real flight:%d net total was %d\n",
+ SCTP_PRINTF("real flight:%d net total was %d\n",
stcb->asoc.total_flight, tot_out);
/* now corrective action */
TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
@@ -738,8 +738,9 @@ sctp_auditing(int from, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
}
}
if (lnet->flight_size != tot_out) {
- printf("net:%x flight was %d corrected to %d\n",
- (uint32_t) lnet, lnet->flight_size, tot_out);
+ SCTP_PRINTF("net:%x flight was %d corrected to %d\n",
+ (uint32_t) lnet, lnet->flight_size,
+ tot_out);
lnet->flight_size = tot_out;
}
}
@@ -842,7 +843,7 @@ sctp_fill_random_store(struct sctp_pcb *m)
* numbers, but thats ok too since that is random as well :->
*/
m->store_at = 0;
- sctp_hmac(SCTP_HMAC, (uint8_t *) m->random_numbers,
+ (void)sctp_hmac(SCTP_HMAC, (uint8_t *) m->random_numbers,
sizeof(m->random_numbers), (uint8_t *) & m->random_counter,
sizeof(m->random_counter), (uint8_t *) m->random_store);
m->random_counter++;
@@ -950,6 +951,8 @@ sctp_init_asoc(struct sctp_inpcb *m, struct sctp_association *asoc,
asoc->my_vtag_nonce = sctp_select_a_tag(m);
asoc->peer_vtag_nonce = sctp_select_a_tag(m);
asoc->vrf_id = vrf_id;
+ /* Save the table id as well from the inp */
+ asoc->table_id = m->def_table_id;
if (sctp_is_feature_on(m, SCTP_PCB_FLAGS_DONOT_HEARTBEAT))
asoc->hb_is_disabled = 1;
@@ -1026,7 +1029,7 @@ sctp_init_asoc(struct sctp_inpcb *m, struct sctp_association *asoc,
asoc->smallest_mtu = m->sctp_frag_point;
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("smallest_mtu init'd with asoc to :%d\n",
+ SCTP_PRINTF("smallest_mtu init'd with asoc to :%d\n",
asoc->smallest_mtu);
#endif
asoc->minrto = m->sctp_ep.sctp_minrto;
@@ -1128,7 +1131,7 @@ sctp_expand_mapping_array(struct sctp_association *asoc)
SCTP_MALLOC(new_array, uint8_t *, new_size, "MappingArray");
if (new_array == NULL) {
/* can't get more, forget it */
- printf("No memory for expansion of SCTP mapping array %d\n",
+ SCTP_PRINTF("No memory for expansion of SCTP mapping array %d\n",
new_size);
return (-1);
}
@@ -1148,9 +1151,9 @@ sctp_iterator_work(struct sctp_iterator *it)
int inp_skip = 0;
SCTP_ITERATOR_LOCK();
- if (it->inp)
+ if (it->inp) {
SCTP_INP_DECR_REF(it->inp);
-
+ }
if (it->inp == NULL) {
/* iterator is complete */
done_with_iterator:
@@ -1332,7 +1335,7 @@ sctp_handle_addr_wq(void)
if (asc->cnt == 0) {
SCTP_FREE(asc);
} else {
- sctp_initiate_iterator(sctp_iterator_ep,
+ (void)sctp_initiate_iterator(sctp_iterator_ep,
sctp_iterator_stcb,
NULL, /* No ep end for boundall */
SCTP_PCB_FLAGS_BOUNDALL,
@@ -1368,7 +1371,7 @@ sctp_timeout_handler(void *t)
/* sanity checks... */
if (tmr->self != (void *)tmr) {
/*
- * printf("Stale SCTP timer fired (%p), ignoring...\n",
+ * SCTP_PRINTF("Stale SCTP timer fired (%p), ignoring...\n",
* tmr);
*/
return;
@@ -1376,7 +1379,7 @@ sctp_timeout_handler(void *t)
tmr->stopped_from = 0xa001;
if (!SCTP_IS_TIMER_TYPE_VALID(tmr->type)) {
/*
- * printf("SCTP timer fired with invalid type: 0x%x\n",
+ * SCTP_PRINTF("SCTP timer fired with invalid type: 0x%x\n",
* tmr->type);
*/
return;
@@ -1416,11 +1419,7 @@ sctp_timeout_handler(void *t)
}
}
tmr->stopped_from = 0xa005;
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("Timer type %d goes off\n", tmr->type);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER1, "Timer type %d goes off\n", tmr->type);
if (!SCTP_OS_TIMER_ACTIVE(&tmr->timer)) {
if (inp) {
SCTP_INP_DECR_REF(inp);
@@ -1461,6 +1460,9 @@ sctp_timeout_handler(void *t)
sctp_iterator_timer(it);
break;
case SCTP_TIMER_TYPE_SEND:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timodata);
stcb->asoc.timodata++;
stcb->asoc.num_send_timers_up--;
@@ -1493,6 +1495,9 @@ sctp_timeout_handler(void *t)
}
break;
case SCTP_TIMER_TYPE_INIT:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timoinit);
stcb->asoc.timoinit++;
if (sctp_t1init_timer(inp, stcb, net)) {
@@ -1503,6 +1508,9 @@ sctp_timeout_handler(void *t)
did_output = 0;
break;
case SCTP_TIMER_TYPE_RECV:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timosack);
stcb->asoc.timosack++;
sctp_send_sack(stcb);
@@ -1512,6 +1520,9 @@ sctp_timeout_handler(void *t)
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SACK_TMR);
break;
case SCTP_TIMER_TYPE_SHUTDOWN:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
if (sctp_shutdown_timer(inp, stcb, net)) {
/* no need to unlock on tcb its gone */
goto out_decr;
@@ -1528,6 +1539,9 @@ sctp_timeout_handler(void *t)
struct sctp_nets *net;
int cnt_of_unconf = 0;
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timoheartbeat);
stcb->asoc.timoheartbeat++;
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
@@ -1551,6 +1565,9 @@ sctp_timeout_handler(void *t)
}
break;
case SCTP_TIMER_TYPE_COOKIE:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
if (sctp_cookie_timer(inp, stcb, net)) {
/* no need to unlock on tcb its gone */
goto out_decr;
@@ -1571,6 +1588,9 @@ sctp_timeout_handler(void *t)
struct timeval tv;
int i, secret;
+ if (inp == NULL) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timosecret);
(void)SCTP_GETTIME_TIMEVAL(&tv);
SCTP_INP_WLOCK(inp);
@@ -1593,11 +1613,17 @@ sctp_timeout_handler(void *t)
did_output = 0;
break;
case SCTP_TIMER_TYPE_PATHMTURAISE:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timopathmtu);
sctp_pathmtu_timer(inp, stcb, net);
did_output = 0;
break;
case SCTP_TIMER_TYPE_SHUTDOWNACK:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
if (sctp_shutdownack_timer(inp, stcb, net)) {
/* no need to unlock on tcb its gone */
goto out_decr;
@@ -1610,14 +1636,19 @@ sctp_timeout_handler(void *t)
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SHUT_ACK_TMR);
break;
case SCTP_TIMER_TYPE_SHUTDOWNGUARD:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timoshutdownguard);
sctp_abort_an_association(inp, stcb,
SCTP_SHUTDOWN_GUARD_EXPIRES, NULL);
/* no need to unlock on tcb its gone */
goto out_decr;
- break;
case SCTP_TIMER_TYPE_STRRESET:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
if (sctp_strreset_timer(inp, stcb, net)) {
/* no need to unlock on tcb its gone */
goto out_decr;
@@ -1627,10 +1658,16 @@ sctp_timeout_handler(void *t)
break;
case SCTP_TIMER_TYPE_EARLYFR:
/* Need to do FR of things for net */
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timoearlyfr);
sctp_early_fr_timer(inp, stcb, net);
break;
case SCTP_TIMER_TYPE_ASCONF:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
if (sctp_asconf_timer(inp, stcb, net)) {
/* no need to unlock on tcb its gone */
goto out_decr;
@@ -1643,12 +1680,18 @@ sctp_timeout_handler(void *t)
break;
case SCTP_TIMER_TYPE_AUTOCLOSE:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timoautoclose);
sctp_autoclose_timer(inp, stcb, net);
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_AUTOCLOSE_TMR);
did_output = 0;
break;
case SCTP_TIMER_TYPE_ASOCKILL:
+ if ((stcb == NULL) || (inp == NULL)) {
+ break;
+ }
SCTP_STAT_INCR(sctps_timoassockill);
/* Can we free it yet? */
SCTP_INP_DECR_REF(inp);
@@ -1660,9 +1703,11 @@ sctp_timeout_handler(void *t)
*/
stcb = NULL;
goto out_no_decr;
- break;
case SCTP_TIMER_TYPE_INPKILL:
SCTP_STAT_INCR(sctps_timoinpkill);
+ if (inp == NULL) {
+ break;
+ }
/*
* special case, take away our increment since WE are the
* killer
@@ -1672,14 +1717,9 @@ sctp_timeout_handler(void *t)
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
SCTP_CALLED_DIRECTLY_NOCMPSET);
goto out_no_decr;
- break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("sctp_timeout_handler:unknown timer %d\n",
- tmr->type);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER1, "sctp_timeout_handler:unknown timer %d\n",
+ tmr->type);
break;
};
#ifdef SCTP_AUDITING_ENABLED
@@ -1706,17 +1746,13 @@ out_decr:
SCTP_INP_DECR_REF(inp);
}
out_no_decr:
-
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("Timer now complete (type %d)\n", tmr->type);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER1, "Timer now complete (type %d)\n",
+ tmr->type);
if (inp) {
}
}
-int
+void
sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net)
{
@@ -1724,7 +1760,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_timer *tmr;
if ((t_type != SCTP_TIMER_TYPE_ADDR_WQ) && (inp == NULL))
- return (EFAULT);
+ return;
to_ticks = 0;
@@ -1753,7 +1789,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
int rto_val;
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
tmr = &net->rxt_timer;
if (net->RTO == 0) {
@@ -1770,7 +1806,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* minute.
*/
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
tmr = &net->rxt_timer;
if (net->RTO == 0) {
@@ -1785,7 +1821,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* ususually about 200ms.
*/
if (stcb == NULL) {
- return (EFAULT);
+ return;
}
tmr = &stcb->asoc.dack_timer;
to_ticks = MSEC_TO_TICKS(stcb->asoc.delayed_ack);
@@ -1793,7 +1829,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
case SCTP_TIMER_TYPE_SHUTDOWN:
/* Here we use the RTO of the destination. */
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
if (net->RTO == 0) {
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
@@ -1808,9 +1844,9 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* though we use a different timer. We also add the HB timer
* PLUS a random jitter.
*/
- if (stcb == NULL) {
- return (EFAULT);
- } {
+ if ((inp == NULL) || (stcb == NULL)) {
+ return;
+ } else {
uint32_t rndval;
uint8_t this_random;
int cnt_of_unconf = 0;
@@ -1824,7 +1860,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
}
if (cnt_of_unconf) {
lnet = NULL;
- sctp_heartbeat_timer(inp, stcb, lnet, cnt_of_unconf);
+ (void)sctp_heartbeat_timer(inp, stcb, lnet, cnt_of_unconf);
}
if (stcb->asoc.hb_random_idx > 3) {
rndval = sctp_select_initial_TSN(&inp->sctp_ep);
@@ -1840,7 +1876,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
if ((stcb->asoc.hb_is_disabled) &&
(cnt_of_unconf == 0)) {
- return (0);
+ return;
}
if (net) {
struct sctp_nets *lnet;
@@ -1883,7 +1919,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* using the RTO initial value.
*/
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
if (net->RTO == 0) {
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
@@ -1897,12 +1933,15 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* nothing needed but the endpoint here ususually about 60
* minutes.
*/
+ if (inp == NULL) {
+ return;
+ }
tmr = &inp->sctp_ep.signature_change;
to_ticks = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_SIGNATURE];
break;
case SCTP_TIMER_TYPE_ASOCKILL:
if (stcb == NULL) {
- return (EFAULT);
+ return;
}
tmr = &stcb->asoc.strreset_timer;
to_ticks = MSEC_TO_TICKS(SCTP_ASOC_KILL_TIMEOUT);
@@ -1913,6 +1952,9 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* timer since that has stopped and we are in the GONE
* state.
*/
+ if (inp == NULL) {
+ return;
+ }
tmr = &inp->sctp_ep.signature_change;
to_ticks = MSEC_TO_TICKS(SCTP_INP_KILL_TIMEOUT);
break;
@@ -1921,11 +1963,11 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* Here we use the value found in the EP for PMTU ususually
* about 10 minutes.
*/
- if (stcb == NULL) {
- return (EFAULT);
+ if ((stcb == NULL) || (inp == NULL)) {
+ return;
}
if (net == NULL) {
- return (EFAULT);
+ return;
}
to_ticks = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_PMTU];
tmr = &net->pmtu_timer;
@@ -1933,7 +1975,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
case SCTP_TIMER_TYPE_SHUTDOWNACK:
/* Here we use the RTO of the destination */
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
if (net->RTO == 0) {
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
@@ -1947,8 +1989,8 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* Here we use the endpoints shutdown guard timer usually
* about 3 minutes.
*/
- if (stcb == NULL) {
- return (EFAULT);
+ if ((inp == NULL) || (stcb == NULL)) {
+ return;
}
to_ticks = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_MAXSHUTDOWN];
tmr = &stcb->asoc.shut_guard_timer;
@@ -1959,7 +2001,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* the RTO.
*/
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
if (net->RTO == 0) {
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
@@ -1974,11 +2016,11 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
unsigned int msec;
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
if (net->flight_size > net->cwnd) {
/* no need to start */
- return (0);
+ return;
}
SCTP_STAT_INCR(sctps_earlyfrstart);
if (net->lastsa == 0) {
@@ -2003,7 +2045,7 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* the RTO.
*/
if ((stcb == NULL) || (net == NULL)) {
- return (EFAULT);
+ return;
}
if (net->RTO == 0) {
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
@@ -2014,43 +2056,35 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
break;
case SCTP_TIMER_TYPE_AUTOCLOSE:
if (stcb == NULL) {
- return (EFAULT);
+ return;
}
if (stcb->asoc.sctp_autoclose_ticks == 0) {
/*
* Really an error since stcb is NOT set to
* autoclose
*/
- return (0);
+ return;
}
to_ticks = stcb->asoc.sctp_autoclose_ticks;
tmr = &stcb->asoc.autoclose_timer;
break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("sctp_timer_start:Unknown timer type %d\n",
- t_type);
- }
-#endif /* SCTP_DEBUG */
- return (EFAULT);
+ SCTPDBG(SCTP_DEBUG_TIMER1, "%s: Unknown timer type %d\n",
+ __FUNCTION__, t_type);
+ return;
break;
};
if ((to_ticks <= 0) || (tmr == NULL)) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("sctp_timer_start:%d:software error to_ticks:%d tmr:%p not set ??\n",
- t_type, to_ticks, tmr);
- }
-#endif /* SCTP_DEBUG */
- return (EFAULT);
+ SCTPDBG(SCTP_DEBUG_TIMER1, "%s: %d:software error to_ticks:%d tmr:%p not set ??\n",
+ __FUNCTION__, t_type, to_ticks, tmr);
+ return;
}
if (SCTP_OS_TIMER_PENDING(&tmr->timer)) {
/*
* we do NOT allow you to have it already running. if it is
* we leave the current one up unchanged
*/
- return (EALREADY);
+ return;
}
/* At this point we can proceed */
if (t_type == SCTP_TIMER_TYPE_SEND) {
@@ -2063,8 +2097,8 @@ sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
tmr->net = (void *)net;
tmr->self = (void *)tmr;
tmr->ticks = ticks;
- SCTP_OS_TIMER_START(&tmr->timer, to_ticks, sctp_timeout_handler, tmr);
- return (0);
+ (void)SCTP_OS_TIMER_START(&tmr->timer, to_ticks, sctp_timeout_handler, tmr);
+ return;
}
void
@@ -2199,12 +2233,8 @@ sctp_timer_stop(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
tmr = &stcb->asoc.autoclose_timer;
break;
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
- printf("sctp_timer_stop:Unknown timer type %d\n",
- t_type);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_TIMER1, "%s: Unknown timer type %d\n",
+ __FUNCTION__, t_type);
break;
};
if (tmr == NULL) {
@@ -2219,7 +2249,7 @@ sctp_timer_stop(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
return;
}
- if (t_type == SCTP_TIMER_TYPE_SEND) {
+ if ((t_type == SCTP_TIMER_TYPE_SEND) && (stcb != NULL)) {
stcb->asoc.num_send_timers_up--;
if (stcb->asoc.num_send_timers_up < 0) {
stcb->asoc.num_send_timers_up = 0;
@@ -2429,7 +2459,7 @@ sctp_mtu_size_reset(struct sctp_inpcb *inp,
unsigned int eff_mtu, ovh;
#ifdef SCTP_PRINT_FOR_B_AND_M
- printf("sctp_mtu_size_reset(%p, asoc:%p mtu:%d\n",
+ SCTP_PRINTF("sctp_mtu_size_reset(%p, asoc:%p mtu:%d\n",
inp, asoc, mtu);
#endif
asoc->smallest_mtu = mtu;
@@ -2701,7 +2731,8 @@ sctp_notify_assoc_change(uint32_t event, struct sctp_tcb *stcb,
* socket rcv queue.
*/
- if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
+ if ((stcb == NULL) ||
+ (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
(stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)
) {
@@ -2775,7 +2806,7 @@ 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_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVPADDREVNT))
+ if ((stcb == NULL) || (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVPADDREVNT)))
/* event not enabled */
return;
@@ -2840,7 +2871,7 @@ sctp_notify_send_failed(struct sctp_tcb *stcb, uint32_t error,
struct sctp_queued_to_read *control;
int length;
- if (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
+ if ((stcb == NULL) || (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)))
/* event not enabled */
return;
@@ -2905,7 +2936,7 @@ sctp_notify_send_failed2(struct sctp_tcb *stcb, uint32_t error,
struct sctp_queued_to_read *control;
int length;
- if (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
+ if ((stcb == NULL) || (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)))
/* event not enabled */
return;
@@ -2970,7 +3001,7 @@ sctp_notify_adaptation_layer(struct sctp_tcb *stcb,
struct sctp_adaptation_event *sai;
struct sctp_queued_to_read *control;
- if (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
+ if ((stcb == NULL) || (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_ADAPTATIONEVNT)))
/* event not enabled */
return;
@@ -3017,7 +3048,7 @@ sctp_notify_partial_delivery_indication(struct sctp_tcb *stcb,
struct sctp_queued_to_read *control;
struct sockbuf *sb;
- if (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_PDAPIEVNT))
+ if ((stcb == NULL) || sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_PDAPIEVNT))
/* event not enabled */
return;
@@ -3090,6 +3121,9 @@ sctp_notify_shutdown_event(struct sctp_tcb *stcb)
* For TCP model AND UDP connected sockets we will send an error up
* when an SHUTDOWN completes
*/
+ if (stcb == NULL) {
+ return;
+ }
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
/* mark socket closed for read/write and wakeup! */
@@ -3139,6 +3173,9 @@ sctp_notify_stream_reset(struct sctp_tcb *stcb,
struct sctp_stream_reset_event *strreset;
int len;
+ if (stcb == NULL) {
+ return;
+ }
if (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
/* event not enabled */
return;
@@ -3357,12 +3394,8 @@ sctp_ulp_notify(uint32_t notification, struct sctp_tcb *stcb,
default:
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_UTIL1) {
- printf("NOTIFY: unknown notification %xh (%u)\n",
- notification, notification);
- }
-#endif /* SCTP_DEBUG */
+ SCTPDBG(SCTP_DEBUG_UTIL1, "%s: unknown notification %xh (%u)\n",
+ __FUNCTION__, notification, notification);
break;
} /* end switch */
}
@@ -3378,14 +3411,18 @@ sctp_report_all_outbound(struct sctp_tcb *stcb, int holds_lock)
asoc = &stcb->asoc;
+ if (stcb == NULL) {
+ return;
+ }
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
(stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
return;
}
/* now through all the gunk freeing chunks */
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_TCB_SEND_LOCK(stcb);
+ }
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
/* For each stream */
outs = &stcb->asoc.strmout[i];
@@ -3470,14 +3507,18 @@ sctp_report_all_outbound(struct sctp_tcb *stcb, int holds_lock)
chk = TAILQ_FIRST(&asoc->sent_queue);
}
}
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_TCB_SEND_UNLOCK(stcb);
+ }
}
void
sctp_abort_notification(struct sctp_tcb *stcb, int error)
{
+ if (stcb == NULL) {
+ return;
+ }
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
(stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
@@ -3529,15 +3570,15 @@ sctp_print_out_track_log(struct sctp_tcb *stcb)
{
int i;
- printf("Last ep reason:%x\n", stcb->sctp_ep->last_abort_code);
- printf("IN bound TSN log-aaa\n");
+ SCTP_PRINTF("Last ep reason:%x\n", stcb->sctp_ep->last_abort_code);
+ SCTP_PRINTF("IN bound TSN log-aaa\n");
if ((stcb->asoc.tsn_in_at == 0) && (stcb->asoc.tsn_in_wrapped == 0)) {
- printf("None rcvd\n");
+ SCTP_PRINTF("None rcvd\n");
goto none_in;
}
if (stcb->asoc.tsn_in_wrapped) {
for (i = stcb->asoc.tsn_in_at; i < SCTP_TSN_LOG_SIZE; i++) {
- printf("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
+ SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
stcb->asoc.in_tsnlog[i].tsn,
stcb->asoc.in_tsnlog[i].strm,
stcb->asoc.in_tsnlog[i].seq,
@@ -3547,7 +3588,7 @@ sctp_print_out_track_log(struct sctp_tcb *stcb)
}
if (stcb->asoc.tsn_in_at) {
for (i = 0; i < stcb->asoc.tsn_in_at; i++) {
- printf("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
+ SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
stcb->asoc.in_tsnlog[i].tsn,
stcb->asoc.in_tsnlog[i].strm,
stcb->asoc.in_tsnlog[i].seq,
@@ -3556,13 +3597,14 @@ sctp_print_out_track_log(struct sctp_tcb *stcb)
}
}
none_in:
- printf("OUT bound TSN log-aaa\n");
- if ((stcb->asoc.tsn_out_at == 0) && (stcb->asoc.tsn_out_wrapped == 0)) {
- printf("None sent\n");
+ SCTP_PRINTF("OUT bound TSN log-aaa\n");
+ if ((stcb->asoc.tsn_out_at == 0) &&
+ (stcb->asoc.tsn_out_wrapped == 0)) {
+ SCTP_PRINTF("None sent\n");
}
if (stcb->asoc.tsn_out_wrapped) {
for (i = stcb->asoc.tsn_out_at; i < SCTP_TSN_LOG_SIZE; i++) {
- printf("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
+ SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
stcb->asoc.out_tsnlog[i].tsn,
stcb->asoc.out_tsnlog[i].strm,
stcb->asoc.out_tsnlog[i].seq,
@@ -3572,7 +3614,7 @@ none_in:
}
if (stcb->asoc.tsn_out_at) {
for (i = 0; i < stcb->asoc.tsn_out_at; i++) {
- printf("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
+ SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
stcb->asoc.out_tsnlog[i].tsn,
stcb->asoc.out_tsnlog[i].strm,
stcb->asoc.out_tsnlog[i].seq,
@@ -3804,13 +3846,14 @@ sctp_cmpaddr(struct sockaddr *sa1, struct sockaddr *sa2)
void
sctp_print_address(struct sockaddr *sa)
{
+ char ip6buf[INET6_ADDRSTRLEN];
+ ip6buf[0] = 0;
if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6;
- char ip6buf[INET6_ADDRSTRLEN];
sin6 = (struct sockaddr_in6 *)sa;
- printf("IPv6 address: %s:port:%d scope:%u\n",
+ SCTP_PRINTF("IPv6 address: %s:port:%d scope:%u\n",
ip6_sprintf(ip6buf, &sin6->sin6_addr),
ntohs(sin6->sin6_port),
sin6->sin6_scope_id);
@@ -3820,10 +3863,10 @@ sctp_print_address(struct sockaddr *sa)
sin = (struct sockaddr_in *)sa;
p = (unsigned char *)&sin->sin_addr;
- printf("IPv4 address: %u.%u.%u.%u:%d\n",
+ SCTP_PRINTF("IPv4 address: %u.%u.%u.%u:%d\n",
p[0], p[1], p[2], p[3], ntohs(sin->sin_port));
} else {
- printf("?\n");
+ SCTP_PRINTF("?\n");
}
}
@@ -3843,9 +3886,9 @@ sctp_print_address_pkt(struct ip *iph, struct sctphdr *sh)
fsa.sin_family = AF_INET;
fsa.sin_addr = iph->ip_dst;
fsa.sin_port = sh->dest_port;
- printf("src: ");
+ SCTP_PRINTF("src: ");
sctp_print_address((struct sockaddr *)&lsa);
- printf("dest: ");
+ SCTP_PRINTF("dest: ");
sctp_print_address((struct sockaddr *)&fsa);
} else if (iph->ip_v == (IPV6_VERSION >> 4)) {
struct ip6_hdr *ip6;
@@ -3862,9 +3905,9 @@ sctp_print_address_pkt(struct ip *iph, struct sctphdr *sh)
fsa6.sin6_family = AF_INET6;
fsa6.sin6_addr = ip6->ip6_dst;
fsa6.sin6_port = sh->dest_port;
- printf("src: ");
+ SCTP_PRINTF("src: ");
sctp_print_address((struct sockaddr *)&lsa6);
- printf("dest: ");
+ SCTP_PRINTF("dest: ");
sctp_print_address((struct sockaddr *)&fsa6);
}
}
@@ -4111,7 +4154,7 @@ get_out:
}
if (end) {
/* message is complete */
- if (control == stcb->asoc.control_pdapi) {
+ if (stcb && (control == stcb->asoc.control_pdapi)) {
stcb->asoc.control_pdapi = NULL;
}
control->held_length = 0;
@@ -4132,6 +4175,9 @@ get_out:
control->data = m;
control->tail_mbuf = tail;
}
+ if (stcb == NULL) {
+ control->do_not_ref_stcb = 1;
+ }
/*
* When we are appending in partial delivery, the cum-ack is used
* for the actual pd-api highest tsn on this mbuf. The true cum-ack
@@ -4272,7 +4318,7 @@ sctp_release_pr_sctp_chunk(struct sctp_tcb *stcb, struct sctp_tmit_chunk *tp1,
ret_sz += sctp_release_pr_sctp_chunk(stcb, tp1, reason,
&stcb->asoc.send_queue);
} else {
- printf("hmm, nothing on the send queue and no EOM?\n");
+ SCTP_PRINTF("hmm, nothing on the send queue and no EOM?\n");
}
}
return (ret_sz);
@@ -4289,9 +4335,9 @@ sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int holds_loc
{
struct sctp_laddr *laddr;
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_INP_RLOCK(inp);
-
+ }
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
if (laddr->ifa == NULL)
continue;
@@ -4301,8 +4347,9 @@ sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int holds_loc
if (((struct sockaddr_in *)addr)->sin_addr.s_addr ==
laddr->ifa->address.sin.sin_addr.s_addr) {
/* found him. */
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_INP_RUNLOCK(inp);
+ }
return (laddr->ifa);
break;
}
@@ -4310,15 +4357,17 @@ sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int holds_loc
if (SCTP6_ARE_ADDR_EQUAL(&((struct sockaddr_in6 *)addr)->sin6_addr,
&laddr->ifa->address.sin6.sin6_addr)) {
/* found him. */
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_INP_RUNLOCK(inp);
+ }
return (laddr->ifa);
break;
}
}
}
- if (holds_lock == 0)
+ if (holds_lock == 0) {
SCTP_INP_RUNLOCK(inp);
+ }
return (NULL);
}
@@ -4367,11 +4416,11 @@ sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock)
hash_head = &vrf->vrf_addr_hash[(hash_of_addr & vrf->vrf_addr_hashmark)];
if (hash_head == NULL) {
- printf("hash_of_addr:%x mask:%x table:%x - ",
+ SCTP_PRINTF("hash_of_addr:%x mask:%x table:%x - ",
(u_int)hash_of_addr, (u_int)vrf->vrf_addr_hashmark,
(u_int)(hash_of_addr & vrf->vrf_addr_hashmark));
sctp_print_address(addr);
- printf("No such bucket for address\n");
+ SCTP_PRINTF("No such bucket for address\n");
if (holds_lock == 0)
SCTP_IPI_ADDR_UNLOCK();
@@ -5192,7 +5241,7 @@ get_more_data:
#ifdef INVARIANTS
panic("control->data not null at read eor?");
#else
- printf("Strange, data left in the control buffer .. invarients would panic?\n");
+ SCTP_PRINTF("Strange, data left in the control buffer .. invarients would panic?\n");
sctp_m_freem(control->data);
control->data = NULL;
#endif
diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h
index acbeeb5..94acbdd 100644
--- a/sys/netinet/sctputil.h
+++ b/sys/netinet/sctputil.h
@@ -132,7 +132,7 @@ int sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t
void sctp_fill_random_store(struct sctp_pcb *);
-int
+void
sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
@@ -272,16 +272,16 @@ sctp_free_bufspace(struct sctp_tcb *, struct sctp_association *,
#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \
do { \
if (tp1->data != NULL) { \
- atomic_add_int(&((asoc)->chunks_on_out_queue), -chk_cnt); \
+ atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \
if ((asoc)->total_output_queue_size >= tp1->book_size) { \
- atomic_add_int(&((asoc)->total_output_queue_size), -tp1->book_size); \
+ atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \
} else { \
(asoc)->total_output_queue_size = 0; \
} \
if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \
- atomic_add_int(&((stcb)->sctp_socket->so_snd.sb_cc), -tp1->book_size); \
+ atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \
} else { \
stcb->sctp_socket->so_snd.sb_cc = 0; \
} \
@@ -294,16 +294,16 @@ do { \
#define sctp_free_spbufspace(stcb, asoc, sp) \
do { \
if (sp->data != NULL) { \
- atomic_add_int(&(asoc)->chunks_on_out_queue, -1); \
+ atomic_subtract_int(&(asoc)->chunks_on_out_queue, 1); \
if ((asoc)->total_output_queue_size >= sp->length) { \
- atomic_add_int(&(asoc)->total_output_queue_size,sp->length); \
+ atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \
} else { \
(asoc)->total_output_queue_size = 0; \
} \
if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \
- atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \
+ atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \
} else { \
stcb->sctp_socket->so_snd.sb_cc = 0; \
} \
diff --git a/sys/netinet6/sctp6_usrreq.c b/sys/netinet6/sctp6_usrreq.c
index f92ab7c..58fb8a5 100644
--- a/sys/netinet6/sctp6_usrreq.c
+++ b/sys/netinet6/sctp6_usrreq.c
@@ -109,12 +109,8 @@ sctp6_input(i_pak, offp, proto)
#endif /* NFAITH defined and > 0 */
SCTP_STAT_INCR(sctps_recvpackets);
SCTP_STAT_INCR_COUNTER64(sctps_inpackets);
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("V6 input gets a packet iphlen:%d pktlen:%d\n", iphlen,
- SCTP_HEADER_LEN((*i_pak)));
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1, "V6 input gets a packet iphlen:%d pktlen:%d\n",
+ iphlen, SCTP_HEADER_LEN((*i_pak)));
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
/* No multi-cast support in SCTP */
goto bad;
@@ -141,13 +137,8 @@ sctp6_input(i_pak, offp, proto)
sh->checksum = 0; /* prepare for calc */
calc_check = sctp_calculate_sum(m, &mlen, iphlen);
if (calc_check != check) {
-#ifdef SCTP_DEBUG
- if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
- printf("Bad CSUM on SCTP packet calc_check:%x check:%x m:%p mlen:%d iphlen:%d\n",
- calc_check, check, m,
- mlen, iphlen);
- }
-#endif
+ SCTPDBG(SCTP_DEBUG_INPUT1, "Bad CSUM on SCTP packet calc_check:%x check:%x m:%p mlen:%d iphlen:%d\n",
+ calc_check, check, m, mlen, iphlen);
stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch),
sh, ch, &in6p, &net, vrf_id);
/* in6p's ref-count increased && stcb locked */
@@ -185,7 +176,10 @@ sctp_skip_csum:
init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m,
iphlen + sizeof(*sh), sizeof(*init_chk),
(uint8_t *) & chunk_buf);
- sh->v_tag = init_chk->init.initiate_tag;
+ if (init_chk)
+ sh->v_tag = init_chk->init.initiate_tag;
+ else
+ sh->v_tag = 0;
}
if (ch->chunk_type == SCTP_SHUTDOWN_ACK) {
sctp_send_shutdown_complete2(m, iphlen, sh, vrf_id,
@@ -238,9 +232,9 @@ sctp_skip_csum:
return IPPROTO_DONE;
bad:
- if (stcb)
+ if (stcb) {
SCTP_TCB_UNLOCK(stcb);
-
+ }
if ((in6p) && refcount_up) {
/* reduce ref-count */
SCTP_INP_WLOCK(in6p);
@@ -249,9 +243,6 @@ bad:
}
if (m)
sctp_m_freem(m);
- /* For BSD/MAC this does nothing */
- SCTP_DETACH_HEADER_FROM_CHAIN(*i_pak);
- SCTP_RELEASE_HEADER(*i_pak);
return IPPROTO_DONE;
}
@@ -327,8 +318,9 @@ sctp6_notify_mbuf(struct sctp_inpcb *inp,
}
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL);
out:
- if (stcb)
+ if (stcb) {
SCTP_TCB_UNLOCK(stcb);
+ }
}
@@ -889,7 +881,7 @@ connected_type:
/* now what about control */
if (control) {
if (inp->control) {
- printf("huh? control set?\n");
+ SCTP_PRINTF("huh? control set?\n");
SCTP_RELEASE_PKT(inp->control);
inp->control = NULL;
}
@@ -1003,8 +995,9 @@ sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
/* Now do we connect? */
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
stcb = LIST_FIRST(&inp->sctp_asoc_list);
- if (stcb)
+ if (stcb) {
SCTP_TCB_UNLOCK(stcb);
+ }
SCTP_INP_RUNLOCK(inp);
} else {
SCTP_INP_RUNLOCK(inp);
@@ -1038,7 +1031,7 @@ sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
soisconnecting(so);
}
stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
- SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
+ (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
/* initialize authentication parameters for the assoc */
sctp_initialize_auth_params(inp, stcb);
@@ -1174,8 +1167,9 @@ sctp6_peeraddr(struct socket *so, struct sockaddr **addr)
}
SCTP_INP_RLOCK(inp);
stcb = LIST_FIRST(&inp->sctp_asoc_list);
- if (stcb)
+ if (stcb) {
SCTP_TCB_LOCK(stcb);
+ }
SCTP_INP_RUNLOCK(inp);
if (stcb == NULL) {
SCTP_FREE_SONAME(sin6);
OpenPOWER on IntegriCloud