Skip to content

Commit ed63afb

Browse files
lxindavem330
authored andcommitted
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: 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 5c3d0fd commit ed63afb

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

include/net/sctp/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,7 @@ struct sctp_cmsgs {
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,19 @@ struct sctp_nxtinfo {
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 {
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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,12 @@ static int sctp_sendmsg_parse(struct sock *sk, struct sctp_cmsgs *cmsgs,
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,
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)
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
}

0 commit comments

Comments
 (0)