Commit ed63afb8 authored by Xin Long's avatar Xin Long Committed by David S. Miller

sctp: add support for PR-SCTP Information for sendmsg

This patch is to add support for PR-SCTP Information for sendmsg,
as described in section 5.3.7 of RFC6458.

With this option, you can specify pr_policy and pr_value for user
data in sendmsg.

It's also a necessary send info for sctp_sendv.
Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
Acked-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5c3d0fd4
...@@ -2112,6 +2112,7 @@ struct sctp_cmsgs { ...@@ -2112,6 +2112,7 @@ 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;
}; };
/* 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)
* *
...@@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type { ...@@ -293,6 +306,8 @@ 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_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;
...@@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc, ...@@ -1901,9 +1907,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;
} }
...@@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs) ...@@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
SCTP_ABORT | SCTP_EOF)) 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;
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