History

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.

Xin Long committed 8 years ago

Commit ed63afb1 parent 5c3d0fd3 files · +46 −1Browse files

Unified · Split

3 files
  1. include/net/sctp/structs.h +1 −0
  2. include/uapi/linux/sctp.h +15 −0
  3. net/sctp/socket.c +30 −1
include/net/sctp/structs.h+1−0
@@ -2112,6 +2112,7 @@ struct sctp_cmsgs { · 2111 unmodified lines
21122112 struct sctp_initmsg *init;
21132113 struct sctp_sndrcvinfo *srinfo;
21142114 struct sctp_sndinfo *sinfo;
2115+ struct sctp_prinfo *prinfo;
21152116 };
21162117
21172118 /* Structure for tracking memory objects */
include/uapi/linux/sctp.h+15−0
@@ -260,6 +260,19 @@ struct sctp_nxtinfo { · 259 unmodified lines
260260 sctp_assoc_t nxt_assoc_id;
261261 };
262262
263+/* 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
264+ *
265+ * This cmsghdr structure specifies SCTP options for sendmsg().
266+ *
267+ * cmsg_level cmsg_type cmsg_data[]
268+ * ------------ ------------ -------------------
269+ * IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo
270+ */
271+struct sctp_prinfo {
272+ __u16 pr_policy;
273+ __u32 pr_value;
274+};
275+
263276 /*
264277 * sinfo_flags: 16 bits (unsigned integer)
265278 *
@@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type { · 27 unmodified lines
293306 #define SCTP_RCVINFO SCTP_RCVINFO
294307 SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
295308 #define SCTP_NXTINFO SCTP_NXTINFO
309+ SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
310+#define SCTP_PRINFO SCTP_PRINFO
296311 } sctp_cmsg_t;
297312
298313 /*
net/sctp/socket.c+30−1
@@ -1644,6 +1644,12 @@ static int sctp_sendmsg_parse(struct sock *sk, struct sctp_cmsgs *cmsgs, · 1643 unmodified lines
16441644 srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id;
16451645 }
16461646
1647+ if (cmsgs->prinfo) {
1648+ srinfo->sinfo_timetolive = cmsgs->prinfo->pr_value;
1649+ SCTP_PR_SET_POLICY(srinfo->sinfo_flags,
1650+ cmsgs->prinfo->pr_policy);
1651+ }
1652+
16471653 sflags = srinfo->sinfo_flags;
16481654 if (!sflags && msg_len)
16491655 return 0;
@@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc, · 251 unmodified lines
19011907 sinfo->sinfo_ppid = asoc->default_ppid;
19021908 sinfo->sinfo_context = asoc->default_context;
19031909 sinfo->sinfo_assoc_id = sctp_assoc2id(asoc);
1910+
1911+ if (!cmsgs->prinfo)
1912+ sinfo->sinfo_flags = asoc->default_flags;
19041913 }
19051914
1906− if (!cmsgs->srinfo)
1915+ if (!cmsgs->srinfo && !cmsgs->prinfo)
19071916 sinfo->sinfo_timetolive = asoc->default_timetolive;
19081917 }
19091918
@@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs) · 5839 unmodified lines
77497758 SCTP_ABORT | SCTP_EOF))
77507759 return -EINVAL;
77517760 break;
7761+ case SCTP_PRINFO:
7762+ /* SCTP Socket API Extension
7763+ * 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
7764+ *
7765+ * This cmsghdr structure specifies SCTP options for sendmsg().
7766+ *
7767+ * cmsg_level cmsg_type cmsg_data[]
7768+ * ------------ ------------ ---------------------
7769+ * IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo
7770+ */
7771+ if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_prinfo)))
7772+ return -EINVAL;
7773+
7774+ cmsgs->prinfo = CMSG_DATA(cmsg);
7775+ if (cmsgs->prinfo->pr_policy & ~SCTP_PR_SCTP_MASK)
7776+ return -EINVAL;
7777+
7778+ if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
7779+ cmsgs->prinfo->pr_value = 0;
7780+ break;
77527781 default:
77537782 return -EINVAL;
77547783 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t