Skip to content

Commit 1c16a18

Browse files
lxinkuba-moo
authored andcommitted
sctp: handle the init chunk matching an existing asoc
This is from Section 4 of draft-tuexen-tsvwg-sctp-udp-encaps-cons-03, and it requires responding with an abort chunk with an error cause when the udp source port of the received init chunk doesn't match the encap port of the transport. Signed-off-by: Xin Long <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e38d86b commit 1c16a18

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

net/sctp/sm_statefuns.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8(
8787
const union sctp_subtype type,
8888
void *arg,
8989
struct sctp_cmd_seq *commands);
90+
static enum sctp_disposition sctp_sf_new_encap_port(
91+
struct net *net,
92+
const struct sctp_endpoint *ep,
93+
const struct sctp_association *asoc,
94+
const union sctp_subtype type,
95+
void *arg,
96+
struct sctp_cmd_seq *commands);
9097
static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
9198

9299
static enum sctp_disposition sctp_stop_t1_and_abort(
@@ -1493,6 +1500,10 @@ static enum sctp_disposition sctp_sf_do_unexpected_init(
14931500
if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
14941501
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
14951502
commands);
1503+
1504+
if (SCTP_INPUT_CB(chunk->skb)->encap_port != chunk->transport->encap_port)
1505+
return sctp_sf_new_encap_port(net, ep, asoc, type, arg, commands);
1506+
14961507
/* Grab the INIT header. */
14971508
chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
14981509

@@ -3392,6 +3403,45 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8(
33923403

33933404
sctp_packet_append_chunk(packet, abort);
33943405

3406+
sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet));
3407+
3408+
SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
3409+
3410+
sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3411+
return SCTP_DISPOSITION_CONSUME;
3412+
}
3413+
3414+
/* Handling of SCTP Packets Containing an INIT Chunk Matching an
3415+
* Existing Associations when the UDP encap port is incorrect.
3416+
*
3417+
* From Section 4 at draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
3418+
*/
3419+
static enum sctp_disposition sctp_sf_new_encap_port(
3420+
struct net *net,
3421+
const struct sctp_endpoint *ep,
3422+
const struct sctp_association *asoc,
3423+
const union sctp_subtype type,
3424+
void *arg,
3425+
struct sctp_cmd_seq *commands)
3426+
{
3427+
struct sctp_packet *packet = NULL;
3428+
struct sctp_chunk *chunk = arg;
3429+
struct sctp_chunk *abort;
3430+
3431+
packet = sctp_ootb_pkt_new(net, asoc, chunk);
3432+
if (!packet)
3433+
return SCTP_DISPOSITION_NOMEM;
3434+
3435+
abort = sctp_make_new_encap_port(asoc, chunk);
3436+
if (!abort) {
3437+
sctp_ootb_pkt_free(packet);
3438+
return SCTP_DISPOSITION_NOMEM;
3439+
}
3440+
3441+
abort->skb->sk = ep->base.sk;
3442+
3443+
sctp_packet_append_chunk(packet, abort);
3444+
33953445
sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
33963446
SCTP_PACKET(packet));
33973447

0 commit comments

Comments
 (0)