Skip to content

Commit 3ff547c

Browse files
lxindavem330
authored andcommitted
sctp: add support for SCTP AUTH Information for sendmsg
This patch is to add support for SCTP AUTH Information for sendmsg, as described in section 5.3.8 of RFC6458. With this option, you can provide shared key identifier used for sending the user message. It's also a necessary send info for sctp_sendv. Note that it reuses sinfo->sinfo_tsn to indicate if this option is set and sinfo->sinfo_ssn to save the shkey ID which can be 0. 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 1b1e0bc commit 3ff547c

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

include/net/sctp/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,7 @@ struct sctp_cmsgs {
21182118
struct sctp_sndrcvinfo *srinfo;
21192119
struct sctp_sndinfo *sinfo;
21202120
struct sctp_prinfo *prinfo;
2121+
struct sctp_authinfo *authinfo;
21212122
struct msghdr *addrs_msg;
21222123
};
21232124

include/uapi/linux/sctp.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ struct sctp_prinfo {
273273
__u32 pr_value;
274274
};
275275

276+
/* 5.3.8 SCTP AUTH Information Structure (SCTP_AUTHINFO)
277+
*
278+
* This cmsghdr structure specifies SCTP options for sendmsg().
279+
*
280+
* cmsg_level cmsg_type cmsg_data[]
281+
* ------------ ------------ -------------------
282+
* IPPROTO_SCTP SCTP_AUTHINFO struct sctp_authinfo
283+
*/
284+
struct sctp_authinfo {
285+
__u16 auth_keynumber;
286+
};
287+
276288
/*
277289
* sinfo_flags: 16 bits (unsigned integer)
278290
*
@@ -310,7 +322,7 @@ typedef enum sctp_cmsg_type {
310322
#define SCTP_NXTINFO SCTP_NXTINFO
311323
SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
312324
#define SCTP_PRINFO SCTP_PRINFO
313-
SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
325+
SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure */
314326
#define SCTP_AUTHINFO SCTP_AUTHINFO
315327
SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
316328
#define SCTP_DSTADDRV4 SCTP_DSTADDRV4

net/sctp/chunk.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,16 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
206206
max_data -= SCTP_PAD4(sizeof(struct sctp_auth_chunk) +
207207
hmac_desc->hmac_len);
208208

209-
shkey = asoc->shkey;
209+
if (sinfo->sinfo_tsn &&
210+
sinfo->sinfo_ssn != asoc->active_key_id) {
211+
shkey = sctp_auth_get_shkey(asoc, sinfo->sinfo_ssn);
212+
if (!shkey) {
213+
err = -EINVAL;
214+
goto errout;
215+
}
216+
} else {
217+
shkey = asoc->shkey;
218+
}
210219
}
211220

212221
/* Check what's our max considering the above */

net/sctp/socket.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,14 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
19871987

19881988
if (!cmsgs->srinfo && !cmsgs->prinfo)
19891989
sinfo->sinfo_timetolive = asoc->default_timetolive;
1990+
1991+
if (cmsgs->authinfo) {
1992+
/* Reuse sinfo_tsn to indicate that authinfo was set and
1993+
* sinfo_ssn to save the keyid on tx path.
1994+
*/
1995+
sinfo->sinfo_tsn = 1;
1996+
sinfo->sinfo_ssn = cmsgs->authinfo->auth_keynumber;
1997+
}
19901998
}
19911999

19922000
static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
@@ -7874,6 +7882,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
78747882
if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
78757883
cmsgs->prinfo->pr_value = 0;
78767884
break;
7885+
case SCTP_AUTHINFO:
7886+
/* SCTP Socket API Extension
7887+
* 5.3.8 SCTP AUTH Information Structure (SCTP_AUTHINFO)
7888+
*
7889+
* This cmsghdr structure specifies SCTP options for sendmsg().
7890+
*
7891+
* cmsg_level cmsg_type cmsg_data[]
7892+
* ------------ ------------ ---------------------
7893+
* IPPROTO_SCTP SCTP_AUTHINFO struct sctp_authinfo
7894+
*/
7895+
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_authinfo)))
7896+
return -EINVAL;
7897+
7898+
cmsgs->authinfo = CMSG_DATA(cmsg);
7899+
break;
78777900
case SCTP_DSTADDRV4:
78787901
case SCTP_DSTADDRV6:
78797902
/* SCTP Socket API Extension

0 commit comments

Comments
 (0)