Skip to content

Commit 4910280

Browse files
lxindavem330
authored andcommitted
sctp: add support for snd flag SCTP_SENDALL process in sendmsg
This patch is to add support for snd flag SCTP_SENDALL process in sendmsg, as described in section 5.3.4 of RFC6458. With this flag, you can send the same data to all the asocs of this sk once. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2c0dbaa commit 4910280

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

include/uapi/linux/sctp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ enum sctp_sinfo_flags {
284284
SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */
285285
SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */
286286
SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */
287+
/* 2 bits here have been used by SCTP_PR_SCTP_MASK */
288+
SCTP_SENDALL = (1 << 6),
287289
SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */
288290
SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */
289291
};

net/sctp/socket.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
18201820
if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
18211821
return -EPIPE;
18221822

1823+
if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
1824+
!sctp_state(asoc, ESTABLISHED))
1825+
return 0;
1826+
18231827
if (sflags & SCTP_EOF) {
18241828
pr_debug("%s: shutting down association:%p\n", __func__, asoc);
18251829
sctp_primitive_SHUTDOWN(net, asoc, NULL);
@@ -2007,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
20072011

20082012
lock_sock(sk);
20092013

2014+
/* SCTP_SENDALL process */
2015+
if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
2016+
list_for_each_entry(asoc, &ep->asocs, asocs) {
2017+
err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
2018+
msg_len);
2019+
if (err == 0)
2020+
continue;
2021+
if (err < 0)
2022+
goto out_unlock;
2023+
2024+
sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
2025+
2026+
err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
2027+
NULL, sinfo);
2028+
if (err < 0)
2029+
goto out_unlock;
2030+
2031+
iov_iter_revert(&msg->msg_iter, err);
2032+
}
2033+
2034+
goto out_unlock;
2035+
}
2036+
20102037
/* Get and check or create asoc */
20112038
if (daddr) {
20122039
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
@@ -7792,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
77927819

77937820
if (cmsgs->srinfo->sinfo_flags &
77947821
~(SCTP_UNORDERED | SCTP_ADDR_OVER |
7795-
SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
7796-
SCTP_ABORT | SCTP_EOF))
7822+
SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
7823+
SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
77977824
return -EINVAL;
77987825
break;
77997826

@@ -7816,8 +7843,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
78167843

78177844
if (cmsgs->sinfo->snd_flags &
78187845
~(SCTP_UNORDERED | SCTP_ADDR_OVER |
7819-
SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
7820-
SCTP_ABORT | SCTP_EOF))
7846+
SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
7847+
SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
78217848
return -EINVAL;
78227849
break;
78237850
case SCTP_PRINFO:

0 commit comments

Comments
 (0)