Commit 1c02e377 authored by David S. Miller's avatar David S. Miller

Merge branch 'sctp-add-support-for-some-msg_control-options-from-RFC6458'

Xin Long says:

====================
sctp: add support for some msg_control options from RFC6458

This patchset is to add support for 3 msg_control options described
in RFC6458:

    5.3.7.  SCTP PR-SCTP Information Structure (SCTP_PRINFO)
    5.3.9.  SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
    5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)

one send flag described in RFC6458:

    SCTP_SENDALL:  This flag, if set, will cause a one-to-many
    style socket to send the message to all associations that
    are currently established on this socket.  For the one-to-
    one style socket, this flag has no effect.

Note there is another msg_control option:

    5.3.8.  SCTP AUTH Information Structure (SCTP_AUTHINFO)

It's a little complicated, I will post it in another patchset after
this.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5c3d0fd4 49102805
...@@ -2112,6 +2112,8 @@ struct sctp_cmsgs { ...@@ -2112,6 +2112,8 @@ struct sctp_cmsgs {
struct sctp_initmsg *init; struct sctp_initmsg *init;
struct sctp_sndrcvinfo *srinfo; struct sctp_sndrcvinfo *srinfo;
struct sctp_sndinfo *sinfo; struct sctp_sndinfo *sinfo;
struct sctp_prinfo *prinfo;
struct msghdr *addrs_msg;
}; };
/* Structure for tracking memory objects */ /* Structure for tracking memory objects */
......
...@@ -260,6 +260,19 @@ struct sctp_nxtinfo { ...@@ -260,6 +260,19 @@ struct sctp_nxtinfo {
sctp_assoc_t nxt_assoc_id; sctp_assoc_t nxt_assoc_id;
}; };
/* 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
*
* This cmsghdr structure specifies SCTP options for sendmsg().
*
* cmsg_level cmsg_type cmsg_data[]
* ------------ ------------ -------------------
* IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo
*/
struct sctp_prinfo {
__u16 pr_policy;
__u32 pr_value;
};
/* /*
* sinfo_flags: 16 bits (unsigned integer) * sinfo_flags: 16 bits (unsigned integer)
* *
...@@ -271,6 +284,8 @@ enum sctp_sinfo_flags { ...@@ -271,6 +284,8 @@ enum sctp_sinfo_flags {
SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */ SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */
SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */ SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */
SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */ SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */
/* 2 bits here have been used by SCTP_PR_SCTP_MASK */
SCTP_SENDALL = (1 << 6),
SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */ SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */
SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */ SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */
}; };
...@@ -293,6 +308,14 @@ typedef enum sctp_cmsg_type { ...@@ -293,6 +308,14 @@ typedef enum sctp_cmsg_type {
#define SCTP_RCVINFO SCTP_RCVINFO #define SCTP_RCVINFO SCTP_RCVINFO
SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */ SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
#define SCTP_NXTINFO SCTP_NXTINFO #define SCTP_NXTINFO SCTP_NXTINFO
SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
#define SCTP_PRINFO SCTP_PRINFO
SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
#define SCTP_AUTHINFO SCTP_AUTHINFO
SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
} sctp_cmsg_t; } sctp_cmsg_t;
/* /*
......
...@@ -1644,6 +1644,12 @@ static int sctp_sendmsg_parse(struct sock *sk, struct sctp_cmsgs *cmsgs, ...@@ -1644,6 +1644,12 @@ static int sctp_sendmsg_parse(struct sock *sk, struct sctp_cmsgs *cmsgs,
srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id; srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id;
} }
if (cmsgs->prinfo) {
srinfo->sinfo_timetolive = cmsgs->prinfo->pr_value;
SCTP_PR_SET_POLICY(srinfo->sinfo_flags,
cmsgs->prinfo->pr_policy);
}
sflags = srinfo->sinfo_flags; sflags = srinfo->sinfo_flags;
if (!sflags && msg_len) if (!sflags && msg_len)
return 0; return 0;
...@@ -1670,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags, ...@@ -1670,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct sctp_association *asoc; struct sctp_association *asoc;
enum sctp_scope scope; enum sctp_scope scope;
struct cmsghdr *cmsg;
int err = -EINVAL; int err = -EINVAL;
*tp = NULL; *tp = NULL;
...@@ -1735,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags, ...@@ -1735,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
goto free; goto free;
} }
if (!cmsgs->addrs_msg)
return 0;
/* sendv addr list parse */
for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
struct sctp_transport *transport;
struct sctp_association *old;
union sctp_addr _daddr;
int dlen;
if (cmsg->cmsg_level != IPPROTO_SCTP ||
(cmsg->cmsg_type != SCTP_DSTADDRV4 &&
cmsg->cmsg_type != SCTP_DSTADDRV6))
continue;
daddr = &_daddr;
memset(daddr, 0, sizeof(*daddr));
dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
if (dlen < sizeof(struct in_addr))
goto free;
dlen = sizeof(struct in_addr);
daddr->v4.sin_family = AF_INET;
daddr->v4.sin_port = htons(asoc->peer.port);
memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
} else {
if (dlen < sizeof(struct in6_addr))
goto free;
dlen = sizeof(struct in6_addr);
daddr->v6.sin6_family = AF_INET6;
daddr->v6.sin6_port = htons(asoc->peer.port);
memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
}
err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
if (err)
goto free;
old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
if (old && old != asoc) {
if (old->state >= SCTP_STATE_ESTABLISHED)
err = -EISCONN;
else
err = -EALREADY;
goto free;
}
if (sctp_endpoint_is_peeled_off(ep, daddr)) {
err = -EADDRNOTAVAIL;
goto free;
}
transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
SCTP_UNKNOWN);
if (!transport) {
err = -ENOMEM;
goto free;
}
}
return 0; return 0;
free: free:
...@@ -1752,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc, ...@@ -1752,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP)) if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
return -EPIPE; return -EPIPE;
if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
!sctp_state(asoc, ESTABLISHED))
return 0;
if (sflags & SCTP_EOF) { if (sflags & SCTP_EOF) {
pr_debug("%s: shutting down association:%p\n", __func__, asoc); pr_debug("%s: shutting down association:%p\n", __func__, asoc);
sctp_primitive_SHUTDOWN(net, asoc, NULL); sctp_primitive_SHUTDOWN(net, asoc, NULL);
...@@ -1901,9 +1973,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc, ...@@ -1901,9 +1973,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
sinfo->sinfo_ppid = asoc->default_ppid; sinfo->sinfo_ppid = asoc->default_ppid;
sinfo->sinfo_context = asoc->default_context; sinfo->sinfo_context = asoc->default_context;
sinfo->sinfo_assoc_id = sctp_assoc2id(asoc); sinfo->sinfo_assoc_id = sctp_assoc2id(asoc);
if (!cmsgs->prinfo)
sinfo->sinfo_flags = asoc->default_flags;
} }
if (!cmsgs->srinfo) if (!cmsgs->srinfo && !cmsgs->prinfo)
sinfo->sinfo_timetolive = asoc->default_timetolive; sinfo->sinfo_timetolive = asoc->default_timetolive;
} }
...@@ -1936,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len) ...@@ -1936,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
lock_sock(sk); lock_sock(sk);
/* SCTP_SENDALL process */
if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
list_for_each_entry(asoc, &ep->asocs, asocs) {
err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
msg_len);
if (err == 0)
continue;
if (err < 0)
goto out_unlock;
sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
NULL, sinfo);
if (err < 0)
goto out_unlock;
iov_iter_revert(&msg->msg_iter, err);
}
goto out_unlock;
}
/* Get and check or create asoc */ /* Get and check or create asoc */
if (daddr) { if (daddr) {
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport); asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
...@@ -7721,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs) ...@@ -7721,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->srinfo->sinfo_flags & if (cmsgs->srinfo->sinfo_flags &
~(SCTP_UNORDERED | SCTP_ADDR_OVER | ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK | SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
SCTP_ABORT | SCTP_EOF)) SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
return -EINVAL; return -EINVAL;
break; break;
...@@ -7745,10 +7843,45 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs) ...@@ -7745,10 +7843,45 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->sinfo->snd_flags & if (cmsgs->sinfo->snd_flags &
~(SCTP_UNORDERED | SCTP_ADDR_OVER | ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK | SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
SCTP_ABORT | SCTP_EOF)) SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
return -EINVAL; return -EINVAL;
break; break;
case SCTP_PRINFO:
/* SCTP Socket API Extension
* 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
*
* This cmsghdr structure specifies SCTP options for sendmsg().
*
* cmsg_level cmsg_type cmsg_data[]
* ------------ ------------ ---------------------
* IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo
*/
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_prinfo)))
return -EINVAL;
cmsgs->prinfo = CMSG_DATA(cmsg);
if (cmsgs->prinfo->pr_policy & ~SCTP_PR_SCTP_MASK)
return -EINVAL;
if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
cmsgs->prinfo->pr_value = 0;
break;
case SCTP_DSTADDRV4:
case SCTP_DSTADDRV6:
/* SCTP Socket API Extension
* 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
*
* This cmsghdr structure specifies SCTP options for sendmsg().
*
* cmsg_level cmsg_type cmsg_data[]
* ------------ ------------ ---------------------
* IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
* ------------ ------------ ---------------------
* IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
*/
cmsgs->addrs_msg = my_msg;
break;
default: default:
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment