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
2112 struct sctp_initmsg *init;2112 struct sctp_initmsg *init;
2113 struct sctp_sndrcvinfo *srinfo;2113 struct sctp_sndrcvinfo *srinfo;
2114 struct sctp_sndinfo *sinfo;2114 struct sctp_sndinfo *sinfo;
2115 struct sctp_prinfo *prinfo;
2115};2116};
2116 2117
2117/* Structure for tracking memory objects */2118/* Structure for tracking memory objects */
include/uapi/linux/sctp.h+15−0
@@ -260,6 +260,19 @@ struct sctp_nxtinfo { · 259 unmodified lines
260 sctp_assoc_t nxt_assoc_id;260 sctp_assoc_t nxt_assoc_id;
261};261};
262 262
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 */
271struct sctp_prinfo {
272 __u16 pr_policy;
273 __u32 pr_value;
274};
275
263/*276/*
264 * sinfo_flags: 16 bits (unsigned integer)277 * sinfo_flags: 16 bits (unsigned integer)
265 *278 *
@@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type { · 27 unmodified lines
293#define SCTP_RCVINFO SCTP_RCVINFO306#define SCTP_RCVINFO SCTP_RCVINFO
294 SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */307 SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
295#define SCTP_NXTINFO SCTP_NXTINFO308#define SCTP_NXTINFO SCTP_NXTINFO
309 SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
310#define SCTP_PRINFO SCTP_PRINFO
296} sctp_cmsg_t;311} sctp_cmsg_t;
297 312
298/*313/*
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
1644 srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id;1644 srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id;
1645 }1645 }
1646 1646
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
1647 sflags = srinfo->sinfo_flags;1653 sflags = srinfo->sinfo_flags;
1648 if (!sflags && msg_len)1654 if (!sflags && msg_len)
1649 return 0;1655 return 0;
@@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc, · 251 unmodified lines
1901 sinfo->sinfo_ppid = asoc->default_ppid;1907 sinfo->sinfo_ppid = asoc->default_ppid;
1902 sinfo->sinfo_context = asoc->default_context;1908 sinfo->sinfo_context = asoc->default_context;
1903 sinfo->sinfo_assoc_id = sctp_assoc2id(asoc);1909 sinfo->sinfo_assoc_id = sctp_assoc2id(asoc);
1910
1911 if (!cmsgs->prinfo)
1912 sinfo->sinfo_flags = asoc->default_flags;
1904 }1913 }
1905 1914
1906 if (!cmsgs->srinfo)1915 if (!cmsgs->srinfo && !cmsgs->prinfo)
1907 sinfo->sinfo_timetolive = asoc->default_timetolive;1916 sinfo->sinfo_timetolive = asoc->default_timetolive;
1908}1917}
1909 1918
@@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs) · 5839 unmodified lines
7749 SCTP_ABORT | SCTP_EOF))7758 SCTP_ABORT | SCTP_EOF))
7750 return -EINVAL;7759 return -EINVAL;
7751 break;7760 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;
7752 default:7781 default:
7753 return -EINVAL;7782 return -EINVAL;
7754 }7783 }

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