Simplify conditions and don't send ERROR chunks when not ready.
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 362153 2020-06-13 18:38:59Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 362722 2020-06-28 14:11:36Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -5583,7 +5583,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
break;
case SCTP_STREAM_RESET:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_STREAM_RESET\n");
- if (((stcb == NULL) || (ch == NULL) || (chk_length < sizeof(struct sctp_stream_reset_tsn_req)))) {
+ if ((stcb == NULL) || (chk_length < sizeof(struct sctp_stream_reset_tsn_req))) {
/* Its not ours */
*offset = length;
return (stcb);
@@ -5606,7 +5606,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
return (stcb);
}
- if ((ch != NULL) && (stcb != NULL) && (netp != NULL) && (*netp != NULL)) {
+ if ((stcb != NULL) && (netp != NULL) && (*netp != NULL)) {
if (stcb->asoc.pktdrop_supported == 0) {
goto unknown_chunk;
}
@@ -5642,8 +5642,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
goto next_chunk;
}
got_auth = 1;
- if ((ch == NULL) || sctp_handle_auth(stcb, (struct sctp_auth_chunk *)ch,
- m, *offset)) {
+ if (sctp_handle_auth(stcb, (struct sctp_auth_chunk *)ch, m, *offset)) {
/* auth HMAC failed so dump the packet */
*offset = length;
return (stcb);
@@ -5656,7 +5655,11 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
default:
unknown_chunk:
/* it's an unknown chunk! */
- if ((ch->chunk_type & 0x40) && (stcb != NULL)) {
+ if ((ch->chunk_type & 0x40) &&
+ (stcb != NULL) &&
+ (SCTP_GET_STATE(stcb) != SCTP_STATE_EMPTY) &&
+ (SCTP_GET_STATE(stcb) != SCTP_STATE_INUSE) &&
+ (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT)) {
struct sctp_gen_error_cause *cause;
int len;
