1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-25 07:49:18 +00:00

sctp: update zero checksum support

Implement support for the error detection method identifier.
MFC after:	2 weeks
This commit is contained in:
Michael Tuexen 2023-07-23 06:41:32 +02:00
parent b8f1c9dd9b
commit 52640d6174
9 changed files with 125 additions and 42 deletions

View File

@ -207,7 +207,7 @@ struct sctp_state_cookie { /* this is our definition... */
uint8_t ipv4_scope; /* IPv4 private addr scope */
uint8_t loopback_scope; /* loopback scope information */
uint8_t zero_checksum; /* copy of the inp value */
uint8_t rcv_edmid; /* copy of the inp value */
uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
/*
* at the end is tacked on the INIT chunk and the INIT-ACK chunk
@ -520,6 +520,13 @@ struct sctp_auth_chunk {
uint8_t hmac[];
} SCTP_PACKED;
/* Zero checksum support draft-ietf-tsvwg-sctp-zero-checksum */
struct sctp_zero_checksum_acceptable {
struct sctp_paramhdr ph;
uint32_t edmid;
} SCTP_PACKED;
/*
* we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
* pieces. If ENCE is missing we could have a couple of blocks. This way we

View File

@ -1883,7 +1883,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
}
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), aack);
}
asoc->zero_checksum = cookie->zero_checksum;
asoc->rcv_edmid = cookie->rcv_edmid;
/* process the INIT-ACK info (my info) */
asoc->my_vtag = ntohl(initack_cp->init.initiate_tag);
@ -2080,7 +2080,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
SCTP_FROM_SCTP_INPUT + SCTP_LOC_18);
return (NULL);
}
asoc->zero_checksum = cookie->zero_checksum;
asoc->rcv_edmid = cookie->rcv_edmid;
/* process the INIT-ACK info (my info) */
asoc->my_rwnd = ntohl(initack_cp->init.a_rwnd);
@ -5381,9 +5381,14 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt
stcb = sctp_findassociation_addr(m, offset, src, dst,
sh, ch, &inp, &net, vrf_id);
stcb_looked_up = true;
if ((stcb == NULL) || (stcb->asoc.zero_checksum == 0)) {
if (stcb == NULL) {
goto validate_cksum;
}
if (stcb->asoc.rcv_edmid == SCTP_EDMID_NONE) {
goto validate_cksum;
}
KASSERT(stcb->asoc.rcv_edmid == SCTP_EDMID_LOWER_LAYER_DTLS,
("Unexpected EDMID %u", stcb->asoc.rcv_edmid));
SCTP_STAT_INCR(sctps_recvzerocrc);
}
}

View File

@ -4627,6 +4627,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked)
struct sctp_init_chunk *init;
struct sctp_supported_addr_param *sup_addr;
struct sctp_adaptation_layer_indication *ali;
struct sctp_zero_checksum_acceptable *zero_chksum;
struct sctp_supported_chunk_types_param *pr_supported;
struct sctp_paramhdr *ph;
int cnt_inits_to = 0;
@ -4720,11 +4721,12 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked)
}
/* Zero checksum acceptable parameter */
if (stcb->asoc.zero_checksum > 0) {
parameter_len = (uint16_t)sizeof(struct sctp_paramhdr);
ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len);
ph->param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE);
ph->param_length = htons(parameter_len);
if (stcb->asoc.rcv_edmid != SCTP_EDMID_NONE) {
parameter_len = (uint16_t)sizeof(struct sctp_zero_checksum_acceptable);
zero_chksum = (struct sctp_zero_checksum_acceptable *)(mtod(m, caddr_t)+chunk_len);
zero_chksum->ph.param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE);
zero_chksum->ph.param_length = htons(parameter_len);
zero_chksum->edmid = htonl(stcb->asoc.rcv_edmid);
chunk_len += parameter_len;
}
@ -5483,6 +5485,7 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct mbuf *m, *m_tmp, *m_last, *m_cookie, *op_err;
struct sctp_init_ack_chunk *initack;
struct sctp_adaptation_layer_indication *ali;
struct sctp_zero_checksum_acceptable *zero_chksum;
struct sctp_supported_chunk_types_param *pr_supported;
struct sctp_paramhdr *ph;
union sctp_sockstore *over_addr;
@ -5805,9 +5808,9 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
}
}
if (asoc != NULL) {
stc.zero_checksum = asoc->zero_checksum > 0 ? 1 : 0;
stc.rcv_edmid = asoc->rcv_edmid;
} else {
stc.zero_checksum = inp->zero_checksum;
stc.rcv_edmid = inp->rcv_edmid;
}
/* Now lets put the SCTP header in place */
initack = mtod(m, struct sctp_init_ack_chunk *);
@ -5933,12 +5936,17 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
}
/* Zero checksum acceptable parameter */
if (((asoc != NULL) && (asoc->zero_checksum > 0)) ||
((asoc == NULL) && (inp->zero_checksum == 1))) {
parameter_len = (uint16_t)sizeof(struct sctp_paramhdr);
ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len);
ph->param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE);
ph->param_length = htons(parameter_len);
if (((asoc != NULL) && (asoc->rcv_edmid != SCTP_EDMID_NONE)) ||
((asoc == NULL) && (inp->rcv_edmid != SCTP_EDMID_NONE))) {
parameter_len = (uint16_t)sizeof(struct sctp_zero_checksum_acceptable);
zero_chksum = (struct sctp_zero_checksum_acceptable *)(mtod(m, caddr_t)+chunk_len);
zero_chksum->ph.param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE);
zero_chksum->ph.param_length = htons(parameter_len);
if (asoc != NULL) {
zero_chksum->edmid = htonl(asoc->rcv_edmid);
} else {
zero_chksum->edmid = htonl(inp->rcv_edmid);
}
chunk_len += parameter_len;
}
@ -8426,7 +8434,14 @@ sctp_med_chunk_output(struct sctp_inpcb *inp,
* flight size since this little guy
* is a control only packet.
*/
use_zero_crc = asoc->zero_checksum == 2;
switch (asoc->snd_edmid) {
case SCTP_EDMID_LOWER_LAYER_DTLS:
use_zero_crc = true;
break;
default:
use_zero_crc = false;
break;
}
if (asconf) {
sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, stcb, net);
use_zero_crc = false;
@ -8758,8 +8773,15 @@ sctp_med_chunk_output(struct sctp_inpcb *inp,
no_data_fill:
/* Is there something to send for this destination? */
if (outchain) {
switch (asoc->snd_edmid) {
case SCTP_EDMID_LOWER_LAYER_DTLS:
use_zero_crc = true;
break;
default:
use_zero_crc = false;
break;
}
/* We may need to start a control timer or two */
use_zero_crc = asoc->zero_checksum == 2;
if (asconf) {
sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
stcb, net);
@ -9495,7 +9517,14 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp,
/* do we have control chunks to retransmit? */
if (m != NULL) {
/* Start a timer no matter if we succeed or fail */
use_zero_crc = asoc->zero_checksum == 2;
switch (asoc->snd_edmid) {
case SCTP_EDMID_LOWER_LAYER_DTLS:
use_zero_crc = true;
break;
default:
use_zero_crc = false;
break;
}
if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) {
sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, inp, stcb, chk->whoTo);
use_zero_crc = false;
@ -9782,6 +9811,14 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp,
sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net);
tmr_started = 1;
}
switch (asoc->snd_edmid) {
case SCTP_EDMID_LOWER_LAYER_DTLS:
use_zero_crc = true;
break;
default:
use_zero_crc = false;
break;
}
/* Now lets send it, if there is anything to send :> */
if ((error = sctp_lowlevel_chunk_output(inp, stcb, net,
(struct sockaddr *)&net->ro._l_addr, m,
@ -9790,7 +9827,7 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp,
inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag),
net->port, NULL,
0, 0,
asoc->zero_checksum == 2,
use_zero_crc,
so_locked))) {
/* error, we could not output */
SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error);
@ -10875,6 +10912,7 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked)
uint32_t auth_offset = 0;
int error;
uint16_t cause_len, chunk_len, padding_len;
bool use_zero_crc;
SCTP_TCB_LOCK_ASSERT(stcb);
/*-
@ -10889,6 +10927,14 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked)
} else {
m_out = NULL;
}
switch (stcb->asoc.snd_edmid) {
case SCTP_EDMID_LOWER_LAYER_DTLS:
use_zero_crc = true;
break;
default:
use_zero_crc = false;
break;
}
m_abort = sctp_get_mbuf_for_msg(sizeof(struct sctp_abort_chunk), 0, M_NOWAIT, 1, MT_HEADER);
if (m_abort == NULL) {
if (m_out) {
@ -10951,7 +10997,7 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked)
stcb->sctp_ep->sctp_lport, stcb->rport, htonl(vtag),
stcb->asoc.primary_destination->port, NULL,
0, 0,
stcb->asoc.zero_checksum == 2,
use_zero_crc,
so_locked))) {
SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error);
if (error == ENOBUFS) {
@ -10975,6 +11021,7 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb,
uint32_t vtag;
int error;
uint8_t flags;
bool use_zero_crc;
m_shutdown_comp = sctp_get_mbuf_for_msg(sizeof(struct sctp_chunkhdr), 0, M_NOWAIT, 1, MT_HEADER);
if (m_shutdown_comp == NULL) {
@ -10988,6 +11035,14 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb,
flags = 0;
vtag = stcb->asoc.peer_vtag;
}
switch (stcb->asoc.snd_edmid) {
case SCTP_EDMID_LOWER_LAYER_DTLS:
use_zero_crc = true;
break;
default:
use_zero_crc = false;
break;
}
shutdown_complete = mtod(m_shutdown_comp, struct sctp_shutdown_complete_chunk *);
shutdown_complete->ch.chunk_type = SCTP_SHUTDOWN_COMPLETE;
shutdown_complete->ch.chunk_flags = flags;
@ -11000,7 +11055,7 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb,
htonl(vtag),
net->port, NULL,
0, 0,
stcb->asoc.zero_checksum == 2,
use_zero_crc,
SCTP_SO_NOT_LOCKED))) {
SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error);
if (error == ENOBUFS) {

View File

@ -2433,7 +2433,7 @@ sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id)
inp->nrsack_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_nrsack_enable);
inp->pktdrop_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_pktdrop_enable);
inp->idata_supported = 0;
inp->zero_checksum = 0;
inp->rcv_edmid = SCTP_EDMID_NONE;
inp->fibnum = so->so_fibnum;
/* init the small hash table we use to track asocid <-> tcb */
@ -6403,12 +6403,23 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
/* Peer supports pr-sctp */
peer_supports_prsctp = 1;
} else if (ptype == SCTP_ZERO_CHECKSUM_ACCEPTABLE) {
/*
* Only send zero checksums if the upper layer has
* also enabled the support for this.
*/
if (stcb->asoc.zero_checksum == 1) {
stcb->asoc.zero_checksum = 2;
struct sctp_zero_checksum_acceptable zero_chksum,
*zero_chksum_p;
phdr = sctp_get_next_param(m, offset,
(struct sctp_paramhdr *)&zero_chksum,
sizeof(struct sctp_zero_checksum_acceptable));
if (phdr != NULL) {
/*
* Only send zero checksums if the upper
* layer has enabled the support for the
* same method as allowed by the peer.
*/
zero_chksum_p = (struct sctp_zero_checksum_acceptable *)phdr;
if ((ntohl(zero_chksum_p->edmid) != SCTP_EDMID_NONE) &&
(ntohl(zero_chksum_p->edmid) == stcb->asoc.rcv_edmid)) {
stcb->asoc.snd_edmid = stcb->asoc.rcv_edmid;
}
}
} else if (ptype == SCTP_SUPPORTED_CHUNK_EXT) {
/* A supported extension chunk */

View File

@ -409,7 +409,7 @@ struct sctp_inpcb {
uint8_t reconfig_supported;
uint8_t nrsack_supported;
uint8_t pktdrop_supported;
uint8_t zero_checksum;
uint8_t rcv_edmid;
struct sctp_nonpad_sndrcvinfo def_send;
/*-
* These three are here for the sosend_dgram

View File

@ -1185,11 +1185,9 @@ struct sctp_association {
uint8_t pktdrop_supported;
uint8_t idata_supported;
/*
* Zero checksum supported information: 0: disabled 1: enabled for
* rcv 2: enabled for snd/rcv
*/
uint8_t zero_checksum;
/* Zero checksum supported information */
uint8_t rcv_edmid;
uint8_t snd_edmid;
/* Did the peer make the stream config (add out) request */
uint8_t peer_req_out;

View File

@ -790,6 +790,10 @@ struct sctp_get_nonce_values {
uint32_t gn_local_tag;
};
/* Values for SCTP_ACCEPT_ZERO_CHECKSUM */
#define SCTP_EDMID_NONE 0
#define SCTP_EDMID_LOWER_LAYER_DTLS 1
/* Debugging logs */
struct sctp_str_log {
void *stcb; /* FIXME: LP64 issue */

View File

@ -6839,13 +6839,15 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
uint32_t *value;
SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
SCTP_INP_WLOCK(inp);
if (*value != 0) {
inp->zero_checksum = 1;
if ((*value == SCTP_EDMID_NONE) ||
(*value == SCTP_EDMID_LOWER_LAYER_DTLS)) {
SCTP_INP_WLOCK(inp);
inp->rcv_edmid = *value;
SCTP_INP_WUNLOCK(inp);
} else {
inp->zero_checksum = 0;
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
error = EINVAL;
}
SCTP_INP_WUNLOCK(inp);
break;
}

View File

@ -1149,7 +1149,8 @@ sctp_init_asoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
asoc->nrsack_supported = inp->nrsack_supported;
asoc->pktdrop_supported = inp->pktdrop_supported;
asoc->idata_supported = inp->idata_supported;
asoc->zero_checksum = inp->zero_checksum;
asoc->rcv_edmid = inp->rcv_edmid;
asoc->snd_edmid = SCTP_EDMID_NONE;
asoc->sctp_cmt_pf = (uint8_t)0;
asoc->sctp_frag_point = inp->sctp_frag_point;
asoc->sctp_features = inp->sctp_features;