* [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458
@ 2018-03-05 12:44 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This patchset is to add support for 3 msg_control options described
in RFC6458:
5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
5.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
one send flag described in RFC6458:
SCTP_SENDALL: This flag, if set, will cause a one-to-many
style socket to send the message to all associations that
are currently established on this socket. For the one-to-
one style socket, this flag has no effect.
Note there is another msg_control option:
5.3.8. SCTP AUTH Information Structure (SCTP_AUTHINFO)
It's a little complicated, I will post it in another patchset after
this.
Xin Long (3):
sctp: add support for PR-SCTP Information for sendmsg
sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
sctp: add support for snd flag SCTP_SENDALL process in sendmsg
include/net/sctp/structs.h | 2 +
include/uapi/linux/sctp.h | 23 ++++++++
net/sctp/socket.c | 143 +++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 163 insertions(+), 5 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458
@ 2018-03-05 12:44 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This patchset is to add support for 3 msg_control options described
in RFC6458:
5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
5.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
one send flag described in RFC6458:
SCTP_SENDALL: This flag, if set, will cause a one-to-many
style socket to send the message to all associations that
are currently established on this socket. For the one-to-
one style socket, this flag has no effect.
Note there is another msg_control option:
5.3.8. SCTP AUTH Information Structure (SCTP_AUTHINFO)
It's a little complicated, I will post it in another patchset after
this.
Xin Long (3):
sctp: add support for PR-SCTP Information for sendmsg
sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
sctp: add support for snd flag SCTP_SENDALL process in sendmsg
include/net/sctp/structs.h | 2 +
include/uapi/linux/sctp.h | 23 ++++++++
net/sctp/socket.c | 143 +++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 163 insertions(+), 5 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH net-next 1/3] sctp: add support for PR-SCTP Information for sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-05 12:44 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
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>
---
include/net/sctp/structs.h | 1 +
include/uapi/linux/sctp.h | 15 +++++++++++++++
net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++-
3 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 03e92dd..d40a2a3 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -2112,6 +2112,7 @@ struct sctp_cmsgs {
struct sctp_initmsg *init;
struct sctp_sndrcvinfo *srinfo;
struct sctp_sndinfo *sinfo;
+ struct sctp_prinfo *prinfo;
};
/* Structure for tracking memory objects */
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 4c4db14..0dd1f82 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -260,6 +260,19 @@ struct sctp_nxtinfo {
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)
*
@@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type {
#define SCTP_RCVINFO SCTP_RCVINFO
SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
#define SCTP_NXTINFO SCTP_NXTINFO
+ SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
+#define SCTP_PRINFO SCTP_PRINFO
} sctp_cmsg_t;
/*
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 7fa7603..fdde697 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -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;
}
+ 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;
if (!sflags && msg_len)
return 0;
@@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
sinfo->sinfo_ppid = asoc->default_ppid;
sinfo->sinfo_context = asoc->default_context;
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;
}
@@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
SCTP_ABORT | SCTP_EOF))
return -EINVAL;
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:
return -EINVAL;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 1/3] sctp: add support for PR-SCTP Information for sendmsg
@ 2018-03-05 12:44 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
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>
---
include/net/sctp/structs.h | 1 +
include/uapi/linux/sctp.h | 15 +++++++++++++++
net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++-
3 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 03e92dd..d40a2a3 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -2112,6 +2112,7 @@ struct sctp_cmsgs {
struct sctp_initmsg *init;
struct sctp_sndrcvinfo *srinfo;
struct sctp_sndinfo *sinfo;
+ struct sctp_prinfo *prinfo;
};
/* Structure for tracking memory objects */
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 4c4db14..0dd1f82 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -260,6 +260,19 @@ struct sctp_nxtinfo {
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)
*
@@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type {
#define SCTP_RCVINFO SCTP_RCVINFO
SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
#define SCTP_NXTINFO SCTP_NXTINFO
+ SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
+#define SCTP_PRINFO SCTP_PRINFO
} sctp_cmsg_t;
/*
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 7fa7603..fdde697 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -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;
}
+ 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;
if (!sflags && msg_len)
return 0;
@@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
sinfo->sinfo_ppid = asoc->default_ppid;
sinfo->sinfo_context = asoc->default_context;
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;
}
@@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
SCTP_ABORT | SCTP_EOF))
return -EINVAL;
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:
return -EINVAL;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-05 12:44 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This patch is to add support for Destination IPv4/6 Address options
for sendmsg, as described in section 5.3.9/10 of RFC6458.
With this option, you can provide more than one destination addrs
to sendmsg when creating asoc, like sctp_connectx.
It's also a necessary send info for sctp_sendv.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/structs.h | 1 +
include/uapi/linux/sctp.h | 6 ++++
net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index d40a2a3..ec6e46b 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
struct sctp_sndrcvinfo *srinfo;
struct sctp_sndinfo *sinfo;
struct sctp_prinfo *prinfo;
+ struct msghdr *addrs_msg;
};
/* Structure for tracking memory objects */
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 0dd1f82..a1bc350 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
#define SCTP_NXTINFO SCTP_NXTINFO
SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
#define SCTP_PRINFO SCTP_PRINFO
+ SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
+#define SCTP_AUTHINFO SCTP_AUTHINFO
+ SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
+#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
+ SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
+#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
} sctp_cmsg_t;
/*
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index fdde697..067b57a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
struct net *net = sock_net(sk);
struct sctp_association *asoc;
enum sctp_scope scope;
+ struct cmsghdr *cmsg;
int err = -EINVAL;
*tp = NULL;
@@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
goto free;
}
+ if (!cmsgs->addrs_msg)
+ return 0;
+
+ /* sendv addr list parse */
+ for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
+ struct sctp_transport *transport;
+ struct sctp_association *old;
+ union sctp_addr _daddr;
+ int dlen;
+
+ if (cmsg->cmsg_level != IPPROTO_SCTP ||
+ (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
+ cmsg->cmsg_type != SCTP_DSTADDRV6))
+ continue;
+
+ daddr = &_daddr;
+ memset(daddr, 0, sizeof(*daddr));
+ dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
+ if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
+ if (dlen < sizeof(struct in_addr))
+ goto free;
+
+ dlen = sizeof(struct in_addr);
+ daddr->v4.sin_family = AF_INET;
+ daddr->v4.sin_port = htons(asoc->peer.port);
+ memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
+ } else {
+ if (dlen < sizeof(struct in6_addr))
+ goto free;
+
+ dlen = sizeof(struct in6_addr);
+ daddr->v6.sin6_family = AF_INET6;
+ daddr->v6.sin6_port = htons(asoc->peer.port);
+ memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
+ }
+ err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
+ if (err)
+ goto free;
+
+ old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
+ if (old && old != asoc) {
+ if (old->state >= SCTP_STATE_ESTABLISHED)
+ err = -EISCONN;
+ else
+ err = -EALREADY;
+ goto free;
+ }
+
+ if (sctp_endpoint_is_peeled_off(ep, daddr)) {
+ err = -EADDRNOTAVAIL;
+ goto free;
+ }
+
+ transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
+ SCTP_UNKNOWN);
+ if (!transport) {
+ err = -ENOMEM;
+ goto free;
+ }
+ }
+
return 0;
free:
@@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
cmsgs->prinfo->pr_value = 0;
break;
+ case SCTP_DSTADDRV4:
+ case SCTP_DSTADDRV6:
+ /* SCTP Socket API Extension
+ * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
+ *
+ * This cmsghdr structure specifies SCTP options for sendmsg().
+ *
+ * cmsg_level cmsg_type cmsg_data[]
+ * ------------ ------------ ---------------------
+ * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
+ * ------------ ------------ ---------------------
+ * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
+ */
+ cmsgs->addrs_msg = my_msg;
+ break;
default:
return -EINVAL;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
@ 2018-03-05 12:44 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This patch is to add support for Destination IPv4/6 Address options
for sendmsg, as described in section 5.3.9/10 of RFC6458.
With this option, you can provide more than one destination addrs
to sendmsg when creating asoc, like sctp_connectx.
It's also a necessary send info for sctp_sendv.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/structs.h | 1 +
include/uapi/linux/sctp.h | 6 ++++
net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index d40a2a3..ec6e46b 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
struct sctp_sndrcvinfo *srinfo;
struct sctp_sndinfo *sinfo;
struct sctp_prinfo *prinfo;
+ struct msghdr *addrs_msg;
};
/* Structure for tracking memory objects */
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 0dd1f82..a1bc350 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
#define SCTP_NXTINFO SCTP_NXTINFO
SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
#define SCTP_PRINFO SCTP_PRINFO
+ SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
+#define SCTP_AUTHINFO SCTP_AUTHINFO
+ SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
+#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
+ SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
+#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
} sctp_cmsg_t;
/*
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index fdde697..067b57a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
struct net *net = sock_net(sk);
struct sctp_association *asoc;
enum sctp_scope scope;
+ struct cmsghdr *cmsg;
int err = -EINVAL;
*tp = NULL;
@@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
goto free;
}
+ if (!cmsgs->addrs_msg)
+ return 0;
+
+ /* sendv addr list parse */
+ for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
+ struct sctp_transport *transport;
+ struct sctp_association *old;
+ union sctp_addr _daddr;
+ int dlen;
+
+ if (cmsg->cmsg_level != IPPROTO_SCTP ||
+ (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
+ cmsg->cmsg_type != SCTP_DSTADDRV6))
+ continue;
+
+ daddr = &_daddr;
+ memset(daddr, 0, sizeof(*daddr));
+ dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
+ if (cmsg->cmsg_type = SCTP_DSTADDRV4) {
+ if (dlen < sizeof(struct in_addr))
+ goto free;
+
+ dlen = sizeof(struct in_addr);
+ daddr->v4.sin_family = AF_INET;
+ daddr->v4.sin_port = htons(asoc->peer.port);
+ memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
+ } else {
+ if (dlen < sizeof(struct in6_addr))
+ goto free;
+
+ dlen = sizeof(struct in6_addr);
+ daddr->v6.sin6_family = AF_INET6;
+ daddr->v6.sin6_port = htons(asoc->peer.port);
+ memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
+ }
+ err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
+ if (err)
+ goto free;
+
+ old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
+ if (old && old != asoc) {
+ if (old->state >= SCTP_STATE_ESTABLISHED)
+ err = -EISCONN;
+ else
+ err = -EALREADY;
+ goto free;
+ }
+
+ if (sctp_endpoint_is_peeled_off(ep, daddr)) {
+ err = -EADDRNOTAVAIL;
+ goto free;
+ }
+
+ transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
+ SCTP_UNKNOWN);
+ if (!transport) {
+ err = -ENOMEM;
+ goto free;
+ }
+ }
+
return 0;
free:
@@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->prinfo->pr_policy = SCTP_PR_SCTP_NONE)
cmsgs->prinfo->pr_value = 0;
break;
+ case SCTP_DSTADDRV4:
+ case SCTP_DSTADDRV6:
+ /* SCTP Socket API Extension
+ * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
+ *
+ * This cmsghdr structure specifies SCTP options for sendmsg().
+ *
+ * cmsg_level cmsg_type cmsg_data[]
+ * ------------ ------------ ---------------------
+ * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
+ * ------------ ------------ ---------------------
+ * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
+ */
+ cmsgs->addrs_msg = my_msg;
+ break;
default:
return -EINVAL;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 3/3] sctp: add support for snd flag SCTP_SENDALL process in sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-05 12:44 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This patch is to add support for snd flag SCTP_SENDALL process
in sendmsg, as described in section 5.3.4 of RFC6458.
With this flag, you can send the same data to all the asocs of
this sk once.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/uapi/linux/sctp.h | 2 ++
net/sctp/socket.c | 35 +++++++++++++++++++++++++++++++----
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index a1bc350..e94b6d2 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -284,6 +284,8 @@ enum sctp_sinfo_flags {
SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */
SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */
SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */
+ /* 2 bits here have been used by SCTP_PR_SCTP_MASK */
+ SCTP_SENDALL = (1 << 6),
SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */
SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */
};
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 067b57a..7d3476a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1820,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
return -EPIPE;
+ if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
+ !sctp_state(asoc, ESTABLISHED))
+ return 0;
+
if (sflags & SCTP_EOF) {
pr_debug("%s: shutting down association:%p\n", __func__, asoc);
sctp_primitive_SHUTDOWN(net, asoc, NULL);
@@ -2007,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
lock_sock(sk);
+ /* SCTP_SENDALL process */
+ if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
+ list_for_each_entry(asoc, &ep->asocs, asocs) {
+ err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
+ msg_len);
+ if (err == 0)
+ continue;
+ if (err < 0)
+ goto out_unlock;
+
+ sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
+
+ err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
+ NULL, sinfo);
+ if (err < 0)
+ goto out_unlock;
+
+ iov_iter_revert(&msg->msg_iter, err);
+ }
+
+ goto out_unlock;
+ }
+
/* Get and check or create asoc */
if (daddr) {
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
@@ -7792,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->srinfo->sinfo_flags &
~(SCTP_UNORDERED | SCTP_ADDR_OVER |
- SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
- SCTP_ABORT | SCTP_EOF))
+ SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
+ SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
return -EINVAL;
break;
@@ -7816,8 +7843,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->sinfo->snd_flags &
~(SCTP_UNORDERED | SCTP_ADDR_OVER |
- SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
- SCTP_ABORT | SCTP_EOF))
+ SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
+ SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
return -EINVAL;
break;
case SCTP_PRINFO:
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 3/3] sctp: add support for snd flag SCTP_SENDALL process in sendmsg
@ 2018-03-05 12:44 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-05 12:44 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This patch is to add support for snd flag SCTP_SENDALL process
in sendmsg, as described in section 5.3.4 of RFC6458.
With this flag, you can send the same data to all the asocs of
this sk once.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/uapi/linux/sctp.h | 2 ++
net/sctp/socket.c | 35 +++++++++++++++++++++++++++++++----
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index a1bc350..e94b6d2 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -284,6 +284,8 @@ enum sctp_sinfo_flags {
SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */
SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */
SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */
+ /* 2 bits here have been used by SCTP_PR_SCTP_MASK */
+ SCTP_SENDALL = (1 << 6),
SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */
SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */
};
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 067b57a..7d3476a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1820,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
return -EPIPE;
+ if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
+ !sctp_state(asoc, ESTABLISHED))
+ return 0;
+
if (sflags & SCTP_EOF) {
pr_debug("%s: shutting down association:%p\n", __func__, asoc);
sctp_primitive_SHUTDOWN(net, asoc, NULL);
@@ -2007,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
lock_sock(sk);
+ /* SCTP_SENDALL process */
+ if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
+ list_for_each_entry(asoc, &ep->asocs, asocs) {
+ err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
+ msg_len);
+ if (err = 0)
+ continue;
+ if (err < 0)
+ goto out_unlock;
+
+ sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
+
+ err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
+ NULL, sinfo);
+ if (err < 0)
+ goto out_unlock;
+
+ iov_iter_revert(&msg->msg_iter, err);
+ }
+
+ goto out_unlock;
+ }
+
/* Get and check or create asoc */
if (daddr) {
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
@@ -7792,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->srinfo->sinfo_flags &
~(SCTP_UNORDERED | SCTP_ADDR_OVER |
- SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
- SCTP_ABORT | SCTP_EOF))
+ SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
+ SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
return -EINVAL;
break;
@@ -7816,8 +7843,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
if (cmsgs->sinfo->snd_flags &
~(SCTP_UNORDERED | SCTP_ADDR_OVER |
- SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
- SCTP_ABORT | SCTP_EOF))
+ SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
+ SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
return -EINVAL;
break;
case SCTP_PRINFO:
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-05 23:39 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-05 23:39 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
> This patch is to add support for Destination IPv4/6 Address options
> for sendmsg, as described in section 5.3.9/10 of RFC6458.
>
> With this option, you can provide more than one destination addrs
> to sendmsg when creating asoc, like sctp_connectx.
>
> It's also a necessary send info for sctp_sendv.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
> include/net/sctp/structs.h | 1 +
> include/uapi/linux/sctp.h | 6 ++++
> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 84 insertions(+)
>
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index d40a2a3..ec6e46b 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
> struct sctp_sndrcvinfo *srinfo;
> struct sctp_sndinfo *sinfo;
> struct sctp_prinfo *prinfo;
> + struct msghdr *addrs_msg;
> };
>
> /* Structure for tracking memory objects */
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index 0dd1f82..a1bc350 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
> #define SCTP_NXTINFO SCTP_NXTINFO
> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> #define SCTP_PRINFO SCTP_PRINFO
> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
> +#define SCTP_AUTHINFO SCTP_AUTHINFO
> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
> } sctp_cmsg_t;
>
> /*
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index fdde697..067b57a 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> struct net *net = sock_net(sk);
> struct sctp_association *asoc;
> enum sctp_scope scope;
> + struct cmsghdr *cmsg;
> int err = -EINVAL;
>
> *tp = NULL;
> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> goto free;
> }
>
> + if (!cmsgs->addrs_msg)
> + return 0;
> +
> + /* sendv addr list parse */
> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
> + struct sctp_transport *transport;
> + struct sctp_association *old;
> + union sctp_addr _daddr;
> + int dlen;
> +
> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
> + cmsg->cmsg_type != SCTP_DSTADDRV6))
> + continue;
> +
> + daddr = &_daddr;
> + memset(daddr, 0, sizeof(*daddr));
> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
> + if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
> + if (dlen < sizeof(struct in_addr))
> + goto free;
> +
> + dlen = sizeof(struct in_addr);
> + daddr->v4.sin_family = AF_INET;
> + daddr->v4.sin_port = htons(asoc->peer.port);
> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
> + } else {
> + if (dlen < sizeof(struct in6_addr))
> + goto free;
> +
> + dlen = sizeof(struct in6_addr);
> + daddr->v6.sin6_family = AF_INET6;
> + daddr->v6.sin6_port = htons(asoc->peer.port);
> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
> + }
> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
> + if (err)
> + goto free;
> +
> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> + if (old && old != asoc) {
> + if (old->state >= SCTP_STATE_ESTABLISHED)
> + err = -EISCONN;
> + else
> + err = -EALREADY;
> + goto free;
> + }
> +
> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
> + err = -EADDRNOTAVAIL;
> + goto free;
> + }
> +
> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
> + SCTP_UNKNOWN);
> + if (!transport) {
> + err = -ENOMEM;
> + goto free;
> + }
> + }
> +
> return 0;
>
> free:
> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
> cmsgs->prinfo->pr_value = 0;
> break;
> + case SCTP_DSTADDRV4:
> + case SCTP_DSTADDRV6:
> + /* SCTP Socket API Extension
> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
> + *
> + * This cmsghdr structure specifies SCTP options for sendmsg().
> + *
> + * cmsg_level cmsg_type cmsg_data[]
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
> + */
> + cmsgs->addrs_msg = my_msg;
I think this is being handled differently from what the RFC specifies.
AFAIU the rfc defines these two options being each one an array of a
specific element type, in_addr and in6_addr.
The patch is saving both options into a single pointer, which later is
processed as a list of (in_addr or in6_addr) elements.
If an application specifies both options, each with a list of its own
addresses, it will ignore one of the options.
> + break;
> default:
> return -EINVAL;
> }
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
@ 2018-03-05 23:39 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-05 23:39 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
> This patch is to add support for Destination IPv4/6 Address options
> for sendmsg, as described in section 5.3.9/10 of RFC6458.
>
> With this option, you can provide more than one destination addrs
> to sendmsg when creating asoc, like sctp_connectx.
>
> It's also a necessary send info for sctp_sendv.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
> include/net/sctp/structs.h | 1 +
> include/uapi/linux/sctp.h | 6 ++++
> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 84 insertions(+)
>
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index d40a2a3..ec6e46b 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
> struct sctp_sndrcvinfo *srinfo;
> struct sctp_sndinfo *sinfo;
> struct sctp_prinfo *prinfo;
> + struct msghdr *addrs_msg;
> };
>
> /* Structure for tracking memory objects */
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index 0dd1f82..a1bc350 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
> #define SCTP_NXTINFO SCTP_NXTINFO
> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> #define SCTP_PRINFO SCTP_PRINFO
> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
> +#define SCTP_AUTHINFO SCTP_AUTHINFO
> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
> } sctp_cmsg_t;
>
> /*
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index fdde697..067b57a 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> struct net *net = sock_net(sk);
> struct sctp_association *asoc;
> enum sctp_scope scope;
> + struct cmsghdr *cmsg;
> int err = -EINVAL;
>
> *tp = NULL;
> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> goto free;
> }
>
> + if (!cmsgs->addrs_msg)
> + return 0;
> +
> + /* sendv addr list parse */
> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
> + struct sctp_transport *transport;
> + struct sctp_association *old;
> + union sctp_addr _daddr;
> + int dlen;
> +
> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
> + cmsg->cmsg_type != SCTP_DSTADDRV6))
> + continue;
> +
> + daddr = &_daddr;
> + memset(daddr, 0, sizeof(*daddr));
> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
> + if (cmsg->cmsg_type = SCTP_DSTADDRV4) {
> + if (dlen < sizeof(struct in_addr))
> + goto free;
> +
> + dlen = sizeof(struct in_addr);
> + daddr->v4.sin_family = AF_INET;
> + daddr->v4.sin_port = htons(asoc->peer.port);
> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
> + } else {
> + if (dlen < sizeof(struct in6_addr))
> + goto free;
> +
> + dlen = sizeof(struct in6_addr);
> + daddr->v6.sin6_family = AF_INET6;
> + daddr->v6.sin6_port = htons(asoc->peer.port);
> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
> + }
> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
> + if (err)
> + goto free;
> +
> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> + if (old && old != asoc) {
> + if (old->state >= SCTP_STATE_ESTABLISHED)
> + err = -EISCONN;
> + else
> + err = -EALREADY;
> + goto free;
> + }
> +
> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
> + err = -EADDRNOTAVAIL;
> + goto free;
> + }
> +
> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
> + SCTP_UNKNOWN);
> + if (!transport) {
> + err = -ENOMEM;
> + goto free;
> + }
> + }
> +
> return 0;
>
> free:
> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> if (cmsgs->prinfo->pr_policy = SCTP_PR_SCTP_NONE)
> cmsgs->prinfo->pr_value = 0;
> break;
> + case SCTP_DSTADDRV4:
> + case SCTP_DSTADDRV6:
> + /* SCTP Socket API Extension
> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
> + *
> + * This cmsghdr structure specifies SCTP options for sendmsg().
> + *
> + * cmsg_level cmsg_type cmsg_data[]
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
> + */
> + cmsgs->addrs_msg = my_msg;
I think this is being handled differently from what the RFC specifies.
AFAIU the rfc defines these two options being each one an array of a
specific element type, in_addr and in6_addr.
The patch is saving both options into a single pointer, which later is
processed as a list of (in_addr or in6_addr) elements.
If an application specifies both options, each with a list of its own
addresses, it will ignore one of the options.
> + break;
> default:
> return -EINVAL;
> }
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458
2018-03-05 12:44 ` Xin Long
@ 2018-03-05 23:52 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-05 23:52 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:17PM +0800, Xin Long wrote:
> This patchset is to add support for 3 msg_control options described
> in RFC6458:
>
> 5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
> 5.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
> 5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
>
> one send flag described in RFC6458:
>
> SCTP_SENDALL: This flag, if set, will cause a one-to-many
> style socket to send the message to all associations that
> are currently established on this socket. For the one-to-
> one style socket, this flag has no effect.
Other patches (than the 2nd one) LGTM.
Marcelo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458
@ 2018-03-05 23:52 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-05 23:52 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:17PM +0800, Xin Long wrote:
> This patchset is to add support for 3 msg_control options described
> in RFC6458:
>
> 5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
> 5.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
> 5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
>
> one send flag described in RFC6458:
>
> SCTP_SENDALL: This flag, if set, will cause a one-to-many
> style socket to send the message to all associations that
> are currently established on this socket. For the one-to-
> one style socket, this flag has no effect.
Other patches (than the 2nd one) LGTM.
Marcelo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
2018-03-05 23:39 ` Marcelo Ricardo Leitner
@ 2018-03-06 7:03 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-06 7:03 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: network dev, linux-sctp, Neil Horman, davem
On Tue, Mar 6, 2018 at 7:39 AM, Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
> On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
>> This patch is to add support for Destination IPv4/6 Address options
>> for sendmsg, as described in section 5.3.9/10 of RFC6458.
>>
>> With this option, you can provide more than one destination addrs
>> to sendmsg when creating asoc, like sctp_connectx.
>>
>> It's also a necessary send info for sctp_sendv.
>>
>> Signed-off-by: Xin Long <lucien.xin@gmail.com>
>> ---
>> include/net/sctp/structs.h | 1 +
>> include/uapi/linux/sctp.h | 6 ++++
>> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 84 insertions(+)
>>
>> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
>> index d40a2a3..ec6e46b 100644
>> --- a/include/net/sctp/structs.h
>> +++ b/include/net/sctp/structs.h
>> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
>> struct sctp_sndrcvinfo *srinfo;
>> struct sctp_sndinfo *sinfo;
>> struct sctp_prinfo *prinfo;
>> + struct msghdr *addrs_msg;
>> };
>>
>> /* Structure for tracking memory objects */
>> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
>> index 0dd1f82..a1bc350 100644
>> --- a/include/uapi/linux/sctp.h
>> +++ b/include/uapi/linux/sctp.h
>> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
>> #define SCTP_NXTINFO SCTP_NXTINFO
>> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
>> #define SCTP_PRINFO SCTP_PRINFO
>> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
>> +#define SCTP_AUTHINFO SCTP_AUTHINFO
>> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
>> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
>> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
>> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
>> } sctp_cmsg_t;
>>
>> /*
>> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
>> index fdde697..067b57a 100644
>> --- a/net/sctp/socket.c
>> +++ b/net/sctp/socket.c
>> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
>> struct net *net = sock_net(sk);
>> struct sctp_association *asoc;
>> enum sctp_scope scope;
>> + struct cmsghdr *cmsg;
>> int err = -EINVAL;
>>
>> *tp = NULL;
>> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
>> goto free;
>> }
>>
>> + if (!cmsgs->addrs_msg)
>> + return 0;
>> +
>> + /* sendv addr list parse */
>> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
>> + struct sctp_transport *transport;
>> + struct sctp_association *old;
>> + union sctp_addr _daddr;
>> + int dlen;
>> +
>> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
>> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
>> + cmsg->cmsg_type != SCTP_DSTADDRV6))
>> + continue;
>> +
>> + daddr = &_daddr;
>> + memset(daddr, 0, sizeof(*daddr));
>> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
>> + if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
>> + if (dlen < sizeof(struct in_addr))
>> + goto free;
>> +
>> + dlen = sizeof(struct in_addr);
>> + daddr->v4.sin_family = AF_INET;
>> + daddr->v4.sin_port = htons(asoc->peer.port);
>> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
>> + } else {
>> + if (dlen < sizeof(struct in6_addr))
>> + goto free;
>> +
>> + dlen = sizeof(struct in6_addr);
>> + daddr->v6.sin6_family = AF_INET6;
>> + daddr->v6.sin6_port = htons(asoc->peer.port);
>> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
>> + }
>> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
>> + if (err)
>> + goto free;
>> +
>> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
>> + if (old && old != asoc) {
>> + if (old->state >= SCTP_STATE_ESTABLISHED)
>> + err = -EISCONN;
>> + else
>> + err = -EALREADY;
>> + goto free;
>> + }
>> +
>> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
>> + err = -EADDRNOTAVAIL;
>> + goto free;
>> + }
>> +
>> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
>> + SCTP_UNKNOWN);
>> + if (!transport) {
>> + err = -ENOMEM;
>> + goto free;
>> + }
>> + }
>> +
>> return 0;
>>
>> free:
>> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
>> if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
>> cmsgs->prinfo->pr_value = 0;
>> break;
>> + case SCTP_DSTADDRV4:
>> + case SCTP_DSTADDRV6:
>> + /* SCTP Socket API Extension
>> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
>> + *
>> + * This cmsghdr structure specifies SCTP options for sendmsg().
>> + *
>> + * cmsg_level cmsg_type cmsg_data[]
>> + * ------------ ------------ ---------------------
>> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
>> + * ------------ ------------ ---------------------
>> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
>> + */
>> + cmsgs->addrs_msg = my_msg;
>
> I think this is being handled differently from what the RFC specifies.
> AFAIU the rfc defines these two options being each one an array of a
> specific element type, in_addr and in6_addr.
Hi, Marcelo.
>From section 5.3.9 of RFC6458:
This ancillary data can be used to provide more than one destination
address to sendmsg(). It can be used to implement sctp_sendv() using
sendmsg().
It doesn't say to put "more than one destination address" into an array of
one option, or put "more than one destination address" into many options.
I was also confused, then I checked sctp_process_cmsgs_for_init() in
freebsd, I think it's in MANY options.
>
> The patch is saving both options into a single pointer, which later is
> processed as a list of (in_addr or in6_addr) elements.
It's not, 'my_msg' is the whole msghdr, not only in_addr or in6_addr.
later in sctp_sendmsg_new_asoc, it will parse this msghdr again but
this time only to pick up SCTP_DSTADDRV4/6 options.
(by this way I don't need to alloc list or array to save them)
Note that: one option is just one address, NOT a list of addresses.
like, it can even be:
SCTP_DSTADDRV4 (one option)
SCTP_DSTADDRV6 (one option)
SCTP_DSTADDRV4 (one option)
SCTP_DSTADDRV4 (one option)
SCTP_DSTADDRV6 (one option)
Maybe the name of cmsgs->addrs_msg is confusing here, but I
actually think it as a flag to see if there is addrs info in the msghdr,
and also as a parameter to pass the msghdr into sctp_sendmsg_new_asoc.
>
> If an application specifies both options, each with a list of its own
> addresses, it will ignore one of the options.
If an application specifies many options, some are SCTP_DSTADDRV4
and some are SCTP_DSTADDRV6, none of them will be ignored in
sctp_sendmsg_new_asoc().
>
>> + break;
>> default:
>> return -EINVAL;
>> }
>> --
>> 2.1.0
>>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
@ 2018-03-06 7:03 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-03-06 7:03 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: network dev, linux-sctp, Neil Horman, davem
On Tue, Mar 6, 2018 at 7:39 AM, Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
> On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
>> This patch is to add support for Destination IPv4/6 Address options
>> for sendmsg, as described in section 5.3.9/10 of RFC6458.
>>
>> With this option, you can provide more than one destination addrs
>> to sendmsg when creating asoc, like sctp_connectx.
>>
>> It's also a necessary send info for sctp_sendv.
>>
>> Signed-off-by: Xin Long <lucien.xin@gmail.com>
>> ---
>> include/net/sctp/structs.h | 1 +
>> include/uapi/linux/sctp.h | 6 ++++
>> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 84 insertions(+)
>>
>> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
>> index d40a2a3..ec6e46b 100644
>> --- a/include/net/sctp/structs.h
>> +++ b/include/net/sctp/structs.h
>> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
>> struct sctp_sndrcvinfo *srinfo;
>> struct sctp_sndinfo *sinfo;
>> struct sctp_prinfo *prinfo;
>> + struct msghdr *addrs_msg;
>> };
>>
>> /* Structure for tracking memory objects */
>> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
>> index 0dd1f82..a1bc350 100644
>> --- a/include/uapi/linux/sctp.h
>> +++ b/include/uapi/linux/sctp.h
>> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
>> #define SCTP_NXTINFO SCTP_NXTINFO
>> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
>> #define SCTP_PRINFO SCTP_PRINFO
>> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
>> +#define SCTP_AUTHINFO SCTP_AUTHINFO
>> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
>> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
>> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
>> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
>> } sctp_cmsg_t;
>>
>> /*
>> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
>> index fdde697..067b57a 100644
>> --- a/net/sctp/socket.c
>> +++ b/net/sctp/socket.c
>> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
>> struct net *net = sock_net(sk);
>> struct sctp_association *asoc;
>> enum sctp_scope scope;
>> + struct cmsghdr *cmsg;
>> int err = -EINVAL;
>>
>> *tp = NULL;
>> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
>> goto free;
>> }
>>
>> + if (!cmsgs->addrs_msg)
>> + return 0;
>> +
>> + /* sendv addr list parse */
>> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
>> + struct sctp_transport *transport;
>> + struct sctp_association *old;
>> + union sctp_addr _daddr;
>> + int dlen;
>> +
>> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
>> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
>> + cmsg->cmsg_type != SCTP_DSTADDRV6))
>> + continue;
>> +
>> + daddr = &_daddr;
>> + memset(daddr, 0, sizeof(*daddr));
>> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
>> + if (cmsg->cmsg_type = SCTP_DSTADDRV4) {
>> + if (dlen < sizeof(struct in_addr))
>> + goto free;
>> +
>> + dlen = sizeof(struct in_addr);
>> + daddr->v4.sin_family = AF_INET;
>> + daddr->v4.sin_port = htons(asoc->peer.port);
>> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
>> + } else {
>> + if (dlen < sizeof(struct in6_addr))
>> + goto free;
>> +
>> + dlen = sizeof(struct in6_addr);
>> + daddr->v6.sin6_family = AF_INET6;
>> + daddr->v6.sin6_port = htons(asoc->peer.port);
>> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
>> + }
>> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
>> + if (err)
>> + goto free;
>> +
>> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
>> + if (old && old != asoc) {
>> + if (old->state >= SCTP_STATE_ESTABLISHED)
>> + err = -EISCONN;
>> + else
>> + err = -EALREADY;
>> + goto free;
>> + }
>> +
>> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
>> + err = -EADDRNOTAVAIL;
>> + goto free;
>> + }
>> +
>> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
>> + SCTP_UNKNOWN);
>> + if (!transport) {
>> + err = -ENOMEM;
>> + goto free;
>> + }
>> + }
>> +
>> return 0;
>>
>> free:
>> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
>> if (cmsgs->prinfo->pr_policy = SCTP_PR_SCTP_NONE)
>> cmsgs->prinfo->pr_value = 0;
>> break;
>> + case SCTP_DSTADDRV4:
>> + case SCTP_DSTADDRV6:
>> + /* SCTP Socket API Extension
>> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
>> + *
>> + * This cmsghdr structure specifies SCTP options for sendmsg().
>> + *
>> + * cmsg_level cmsg_type cmsg_data[]
>> + * ------------ ------------ ---------------------
>> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
>> + * ------------ ------------ ---------------------
>> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
>> + */
>> + cmsgs->addrs_msg = my_msg;
>
> I think this is being handled differently from what the RFC specifies.
> AFAIU the rfc defines these two options being each one an array of a
> specific element type, in_addr and in6_addr.
Hi, Marcelo.
From section 5.3.9 of RFC6458:
This ancillary data can be used to provide more than one destination
address to sendmsg(). It can be used to implement sctp_sendv() using
sendmsg().
It doesn't say to put "more than one destination address" into an array of
one option, or put "more than one destination address" into many options.
I was also confused, then I checked sctp_process_cmsgs_for_init() in
freebsd, I think it's in MANY options.
>
> The patch is saving both options into a single pointer, which later is
> processed as a list of (in_addr or in6_addr) elements.
It's not, 'my_msg' is the whole msghdr, not only in_addr or in6_addr.
later in sctp_sendmsg_new_asoc, it will parse this msghdr again but
this time only to pick up SCTP_DSTADDRV4/6 options.
(by this way I don't need to alloc list or array to save them)
Note that: one option is just one address, NOT a list of addresses.
like, it can even be:
SCTP_DSTADDRV4 (one option)
SCTP_DSTADDRV6 (one option)
SCTP_DSTADDRV4 (one option)
SCTP_DSTADDRV4 (one option)
SCTP_DSTADDRV6 (one option)
Maybe the name of cmsgs->addrs_msg is confusing here, but I
actually think it as a flag to see if there is addrs info in the msghdr,
and also as a parameter to pass the msghdr into sctp_sendmsg_new_asoc.
>
> If an application specifies both options, each with a list of its own
> addresses, it will ignore one of the options.
If an application specifies many options, some are SCTP_DSTADDRV4
and some are SCTP_DSTADDRV6, none of them will be ignored in
sctp_sendmsg_new_asoc().
>
>> + break;
>> default:
>> return -EINVAL;
>> }
>> --
>> 2.1.0
>>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
2018-03-06 7:03 ` Xin Long
@ 2018-03-06 12:21 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:21 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Tue, Mar 06, 2018 at 03:03:13PM +0800, Xin Long wrote:
> On Tue, Mar 6, 2018 at 7:39 AM, Marcelo Ricardo Leitner
> <marcelo.leitner@gmail.com> wrote:
> > On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
> >> This patch is to add support for Destination IPv4/6 Address options
> >> for sendmsg, as described in section 5.3.9/10 of RFC6458.
> >>
> >> With this option, you can provide more than one destination addrs
> >> to sendmsg when creating asoc, like sctp_connectx.
> >>
> >> It's also a necessary send info for sctp_sendv.
> >>
> >> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> >> ---
> >> include/net/sctp/structs.h | 1 +
> >> include/uapi/linux/sctp.h | 6 ++++
> >> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
> >> 3 files changed, 84 insertions(+)
> >>
> >> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> >> index d40a2a3..ec6e46b 100644
> >> --- a/include/net/sctp/structs.h
> >> +++ b/include/net/sctp/structs.h
> >> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
> >> struct sctp_sndrcvinfo *srinfo;
> >> struct sctp_sndinfo *sinfo;
> >> struct sctp_prinfo *prinfo;
> >> + struct msghdr *addrs_msg;
> >> };
> >>
> >> /* Structure for tracking memory objects */
> >> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> >> index 0dd1f82..a1bc350 100644
> >> --- a/include/uapi/linux/sctp.h
> >> +++ b/include/uapi/linux/sctp.h
> >> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
> >> #define SCTP_NXTINFO SCTP_NXTINFO
> >> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> >> #define SCTP_PRINFO SCTP_PRINFO
> >> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
> >> +#define SCTP_AUTHINFO SCTP_AUTHINFO
> >> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
> >> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
> >> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
> >> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
> >> } sctp_cmsg_t;
> >>
> >> /*
> >> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> >> index fdde697..067b57a 100644
> >> --- a/net/sctp/socket.c
> >> +++ b/net/sctp/socket.c
> >> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> >> struct net *net = sock_net(sk);
> >> struct sctp_association *asoc;
> >> enum sctp_scope scope;
> >> + struct cmsghdr *cmsg;
> >> int err = -EINVAL;
> >>
> >> *tp = NULL;
> >> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> >> goto free;
> >> }
> >>
> >> + if (!cmsgs->addrs_msg)
> >> + return 0;
> >> +
> >> + /* sendv addr list parse */
> >> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
> >> + struct sctp_transport *transport;
> >> + struct sctp_association *old;
> >> + union sctp_addr _daddr;
> >> + int dlen;
> >> +
> >> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
> >> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
> >> + cmsg->cmsg_type != SCTP_DSTADDRV6))
> >> + continue;
> >> +
> >> + daddr = &_daddr;
> >> + memset(daddr, 0, sizeof(*daddr));
> >> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
> >> + if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
> >> + if (dlen < sizeof(struct in_addr))
> >> + goto free;
> >> +
> >> + dlen = sizeof(struct in_addr);
> >> + daddr->v4.sin_family = AF_INET;
> >> + daddr->v4.sin_port = htons(asoc->peer.port);
> >> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
> >> + } else {
> >> + if (dlen < sizeof(struct in6_addr))
> >> + goto free;
> >> +
> >> + dlen = sizeof(struct in6_addr);
> >> + daddr->v6.sin6_family = AF_INET6;
> >> + daddr->v6.sin6_port = htons(asoc->peer.port);
> >> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
> >> + }
> >> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
> >> + if (err)
> >> + goto free;
> >> +
> >> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> >> + if (old && old != asoc) {
> >> + if (old->state >= SCTP_STATE_ESTABLISHED)
> >> + err = -EISCONN;
> >> + else
> >> + err = -EALREADY;
> >> + goto free;
> >> + }
> >> +
> >> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
> >> + err = -EADDRNOTAVAIL;
> >> + goto free;
> >> + }
> >> +
> >> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
> >> + SCTP_UNKNOWN);
> >> + if (!transport) {
> >> + err = -ENOMEM;
> >> + goto free;
> >> + }
> >> + }
> >> +
> >> return 0;
> >>
> >> free:
> >> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> >> if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
> >> cmsgs->prinfo->pr_value = 0;
> >> break;
> >> + case SCTP_DSTADDRV4:
> >> + case SCTP_DSTADDRV6:
> >> + /* SCTP Socket API Extension
> >> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
> >> + *
> >> + * This cmsghdr structure specifies SCTP options for sendmsg().
> >> + *
> >> + * cmsg_level cmsg_type cmsg_data[]
> >> + * ------------ ------------ ---------------------
> >> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
> >> + * ------------ ------------ ---------------------
> >> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
> >> + */
> >> + cmsgs->addrs_msg = my_msg;
> >
> > I think this is being handled differently from what the RFC specifies.
> > AFAIU the rfc defines these two options being each one an array of a
> > specific element type, in_addr and in6_addr.
> Hi, Marcelo.
>
> From section 5.3.9 of RFC6458:
>
> This ancillary data can be used to provide more than one destination
> address to sendmsg(). It can be used to implement sctp_sendv() using
> sendmsg().
>
> It doesn't say to put "more than one destination address" into an array of
> one option, or put "more than one destination address" into many options.
Spot on. And I went with the first interpretation, thus why the
difference.
>
> I was also confused, then I checked sctp_process_cmsgs_for_init() in
> freebsd, I think it's in MANY options.
Nice, ok
>
>
> >
> > The patch is saving both options into a single pointer, which later is
> > processed as a list of (in_addr or in6_addr) elements.
> It's not, 'my_msg' is the whole msghdr, not only in_addr or in6_addr.
> later in sctp_sendmsg_new_asoc, it will parse this msghdr again but
> this time only to pick up SCTP_DSTADDRV4/6 options.
> (by this way I don't need to alloc list or array to save them)
Which is nice, btw.
>
> Note that: one option is just one address, NOT a list of addresses.
> like, it can even be:
> SCTP_DSTADDRV4 (one option)
> SCTP_DSTADDRV6 (one option)
> SCTP_DSTADDRV4 (one option)
> SCTP_DSTADDRV4 (one option)
> SCTP_DSTADDRV6 (one option)
>
> Maybe the name of cmsgs->addrs_msg is confusing here, but I
> actually think it as a flag to see if there is addrs info in the msghdr,
> and also as a parameter to pass the msghdr into sctp_sendmsg_new_asoc.
What was more confusing to me is that it seems to overwrite the
pointer at every other addr option, but I should have noticed that it
is saving the entire cmsg.
>
> >
> > If an application specifies both options, each with a list of its own
> > addresses, it will ignore one of the options.
> If an application specifies many options, some are SCTP_DSTADDRV4
> and some are SCTP_DSTADDRV6, none of them will be ignored in
> sctp_sendmsg_new_asoc().
Yep. Thanks.
>
> >
> >> + break;
> >> default:
> >> return -EINVAL;
> >> }
> >> --
> >> 2.1.0
> >>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
@ 2018-03-06 12:21 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:21 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Tue, Mar 06, 2018 at 03:03:13PM +0800, Xin Long wrote:
> On Tue, Mar 6, 2018 at 7:39 AM, Marcelo Ricardo Leitner
> <marcelo.leitner@gmail.com> wrote:
> > On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
> >> This patch is to add support for Destination IPv4/6 Address options
> >> for sendmsg, as described in section 5.3.9/10 of RFC6458.
> >>
> >> With this option, you can provide more than one destination addrs
> >> to sendmsg when creating asoc, like sctp_connectx.
> >>
> >> It's also a necessary send info for sctp_sendv.
> >>
> >> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> >> ---
> >> include/net/sctp/structs.h | 1 +
> >> include/uapi/linux/sctp.h | 6 ++++
> >> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
> >> 3 files changed, 84 insertions(+)
> >>
> >> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> >> index d40a2a3..ec6e46b 100644
> >> --- a/include/net/sctp/structs.h
> >> +++ b/include/net/sctp/structs.h
> >> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
> >> struct sctp_sndrcvinfo *srinfo;
> >> struct sctp_sndinfo *sinfo;
> >> struct sctp_prinfo *prinfo;
> >> + struct msghdr *addrs_msg;
> >> };
> >>
> >> /* Structure for tracking memory objects */
> >> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> >> index 0dd1f82..a1bc350 100644
> >> --- a/include/uapi/linux/sctp.h
> >> +++ b/include/uapi/linux/sctp.h
> >> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
> >> #define SCTP_NXTINFO SCTP_NXTINFO
> >> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> >> #define SCTP_PRINFO SCTP_PRINFO
> >> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
> >> +#define SCTP_AUTHINFO SCTP_AUTHINFO
> >> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
> >> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
> >> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
> >> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
> >> } sctp_cmsg_t;
> >>
> >> /*
> >> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> >> index fdde697..067b57a 100644
> >> --- a/net/sctp/socket.c
> >> +++ b/net/sctp/socket.c
> >> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> >> struct net *net = sock_net(sk);
> >> struct sctp_association *asoc;
> >> enum sctp_scope scope;
> >> + struct cmsghdr *cmsg;
> >> int err = -EINVAL;
> >>
> >> *tp = NULL;
> >> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> >> goto free;
> >> }
> >>
> >> + if (!cmsgs->addrs_msg)
> >> + return 0;
> >> +
> >> + /* sendv addr list parse */
> >> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
> >> + struct sctp_transport *transport;
> >> + struct sctp_association *old;
> >> + union sctp_addr _daddr;
> >> + int dlen;
> >> +
> >> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
> >> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
> >> + cmsg->cmsg_type != SCTP_DSTADDRV6))
> >> + continue;
> >> +
> >> + daddr = &_daddr;
> >> + memset(daddr, 0, sizeof(*daddr));
> >> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
> >> + if (cmsg->cmsg_type = SCTP_DSTADDRV4) {
> >> + if (dlen < sizeof(struct in_addr))
> >> + goto free;
> >> +
> >> + dlen = sizeof(struct in_addr);
> >> + daddr->v4.sin_family = AF_INET;
> >> + daddr->v4.sin_port = htons(asoc->peer.port);
> >> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
> >> + } else {
> >> + if (dlen < sizeof(struct in6_addr))
> >> + goto free;
> >> +
> >> + dlen = sizeof(struct in6_addr);
> >> + daddr->v6.sin6_family = AF_INET6;
> >> + daddr->v6.sin6_port = htons(asoc->peer.port);
> >> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
> >> + }
> >> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
> >> + if (err)
> >> + goto free;
> >> +
> >> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> >> + if (old && old != asoc) {
> >> + if (old->state >= SCTP_STATE_ESTABLISHED)
> >> + err = -EISCONN;
> >> + else
> >> + err = -EALREADY;
> >> + goto free;
> >> + }
> >> +
> >> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
> >> + err = -EADDRNOTAVAIL;
> >> + goto free;
> >> + }
> >> +
> >> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
> >> + SCTP_UNKNOWN);
> >> + if (!transport) {
> >> + err = -ENOMEM;
> >> + goto free;
> >> + }
> >> + }
> >> +
> >> return 0;
> >>
> >> free:
> >> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> >> if (cmsgs->prinfo->pr_policy = SCTP_PR_SCTP_NONE)
> >> cmsgs->prinfo->pr_value = 0;
> >> break;
> >> + case SCTP_DSTADDRV4:
> >> + case SCTP_DSTADDRV6:
> >> + /* SCTP Socket API Extension
> >> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
> >> + *
> >> + * This cmsghdr structure specifies SCTP options for sendmsg().
> >> + *
> >> + * cmsg_level cmsg_type cmsg_data[]
> >> + * ------------ ------------ ---------------------
> >> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
> >> + * ------------ ------------ ---------------------
> >> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
> >> + */
> >> + cmsgs->addrs_msg = my_msg;
> >
> > I think this is being handled differently from what the RFC specifies.
> > AFAIU the rfc defines these two options being each one an array of a
> > specific element type, in_addr and in6_addr.
> Hi, Marcelo.
>
> From section 5.3.9 of RFC6458:
>
> This ancillary data can be used to provide more than one destination
> address to sendmsg(). It can be used to implement sctp_sendv() using
> sendmsg().
>
> It doesn't say to put "more than one destination address" into an array of
> one option, or put "more than one destination address" into many options.
Spot on. And I went with the first interpretation, thus why the
difference.
>
> I was also confused, then I checked sctp_process_cmsgs_for_init() in
> freebsd, I think it's in MANY options.
Nice, ok
>
>
> >
> > The patch is saving both options into a single pointer, which later is
> > processed as a list of (in_addr or in6_addr) elements.
> It's not, 'my_msg' is the whole msghdr, not only in_addr or in6_addr.
> later in sctp_sendmsg_new_asoc, it will parse this msghdr again but
> this time only to pick up SCTP_DSTADDRV4/6 options.
> (by this way I don't need to alloc list or array to save them)
Which is nice, btw.
>
> Note that: one option is just one address, NOT a list of addresses.
> like, it can even be:
> SCTP_DSTADDRV4 (one option)
> SCTP_DSTADDRV6 (one option)
> SCTP_DSTADDRV4 (one option)
> SCTP_DSTADDRV4 (one option)
> SCTP_DSTADDRV6 (one option)
>
> Maybe the name of cmsgs->addrs_msg is confusing here, but I
> actually think it as a flag to see if there is addrs info in the msghdr,
> and also as a parameter to pass the msghdr into sctp_sendmsg_new_asoc.
What was more confusing to me is that it seems to overwrite the
pointer at every other addr option, but I should have noticed that it
is saving the entire cmsg.
>
> >
> > If an application specifies both options, each with a list of its own
> > addresses, it will ignore one of the options.
> If an application specifies many options, some are SCTP_DSTADDRV4
> and some are SCTP_DSTADDRV6, none of them will be ignored in
> sctp_sendmsg_new_asoc().
Yep. Thanks.
>
> >
> >> + break;
> >> default:
> >> return -EINVAL;
> >> }
> >> --
> >> 2.1.0
> >>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 1/3] sctp: add support for PR-SCTP Information for sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-06 12:22 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:22 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:18PM +0800, Xin Long wrote:
> 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>
> ---
> include/net/sctp/structs.h | 1 +
> include/uapi/linux/sctp.h | 15 +++++++++++++++
> net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++-
> 3 files changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index 03e92dd..d40a2a3 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -2112,6 +2112,7 @@ struct sctp_cmsgs {
> struct sctp_initmsg *init;
> struct sctp_sndrcvinfo *srinfo;
> struct sctp_sndinfo *sinfo;
> + struct sctp_prinfo *prinfo;
> };
>
> /* Structure for tracking memory objects */
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index 4c4db14..0dd1f82 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -260,6 +260,19 @@ struct sctp_nxtinfo {
> 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)
> *
> @@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type {
> #define SCTP_RCVINFO SCTP_RCVINFO
> SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
> #define SCTP_NXTINFO SCTP_NXTINFO
> + SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> +#define SCTP_PRINFO SCTP_PRINFO
> } sctp_cmsg_t;
>
> /*
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 7fa7603..fdde697 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -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;
> }
>
> + 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;
> if (!sflags && msg_len)
> return 0;
> @@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
> sinfo->sinfo_ppid = asoc->default_ppid;
> sinfo->sinfo_context = asoc->default_context;
> 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;
> }
>
> @@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> SCTP_ABORT | SCTP_EOF))
> return -EINVAL;
> 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:
> return -EINVAL;
> }
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 1/3] sctp: add support for PR-SCTP Information for sendmsg
@ 2018-03-06 12:22 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:22 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:18PM +0800, Xin Long wrote:
> 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>
> ---
> include/net/sctp/structs.h | 1 +
> include/uapi/linux/sctp.h | 15 +++++++++++++++
> net/sctp/socket.c | 31 ++++++++++++++++++++++++++++++-
> 3 files changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index 03e92dd..d40a2a3 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -2112,6 +2112,7 @@ struct sctp_cmsgs {
> struct sctp_initmsg *init;
> struct sctp_sndrcvinfo *srinfo;
> struct sctp_sndinfo *sinfo;
> + struct sctp_prinfo *prinfo;
> };
>
> /* Structure for tracking memory objects */
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index 4c4db14..0dd1f82 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -260,6 +260,19 @@ struct sctp_nxtinfo {
> 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)
> *
> @@ -293,6 +306,8 @@ typedef enum sctp_cmsg_type {
> #define SCTP_RCVINFO SCTP_RCVINFO
> SCTP_NXTINFO, /* 5.3.6 SCTP Next Receive Information Structure */
> #define SCTP_NXTINFO SCTP_NXTINFO
> + SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> +#define SCTP_PRINFO SCTP_PRINFO
> } sctp_cmsg_t;
>
> /*
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 7fa7603..fdde697 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -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;
> }
>
> + 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;
> if (!sflags && msg_len)
> return 0;
> @@ -1901,9 +1907,12 @@ static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
> sinfo->sinfo_ppid = asoc->default_ppid;
> sinfo->sinfo_context = asoc->default_context;
> 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;
> }
>
> @@ -7749,6 +7758,26 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> SCTP_ABORT | SCTP_EOF))
> return -EINVAL;
> 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:
> return -EINVAL;
> }
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-06 12:22 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:22 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
> This patch is to add support for Destination IPv4/6 Address options
> for sendmsg, as described in section 5.3.9/10 of RFC6458.
>
> With this option, you can provide more than one destination addrs
> to sendmsg when creating asoc, like sctp_connectx.
>
> 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>
> ---
> include/net/sctp/structs.h | 1 +
> include/uapi/linux/sctp.h | 6 ++++
> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 84 insertions(+)
>
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index d40a2a3..ec6e46b 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
> struct sctp_sndrcvinfo *srinfo;
> struct sctp_sndinfo *sinfo;
> struct sctp_prinfo *prinfo;
> + struct msghdr *addrs_msg;
> };
>
> /* Structure for tracking memory objects */
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index 0dd1f82..a1bc350 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
> #define SCTP_NXTINFO SCTP_NXTINFO
> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> #define SCTP_PRINFO SCTP_PRINFO
> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
> +#define SCTP_AUTHINFO SCTP_AUTHINFO
> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
> } sctp_cmsg_t;
>
> /*
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index fdde697..067b57a 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> struct net *net = sock_net(sk);
> struct sctp_association *asoc;
> enum sctp_scope scope;
> + struct cmsghdr *cmsg;
> int err = -EINVAL;
>
> *tp = NULL;
> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> goto free;
> }
>
> + if (!cmsgs->addrs_msg)
> + return 0;
> +
> + /* sendv addr list parse */
> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
> + struct sctp_transport *transport;
> + struct sctp_association *old;
> + union sctp_addr _daddr;
> + int dlen;
> +
> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
> + cmsg->cmsg_type != SCTP_DSTADDRV6))
> + continue;
> +
> + daddr = &_daddr;
> + memset(daddr, 0, sizeof(*daddr));
> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
> + if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
> + if (dlen < sizeof(struct in_addr))
> + goto free;
> +
> + dlen = sizeof(struct in_addr);
> + daddr->v4.sin_family = AF_INET;
> + daddr->v4.sin_port = htons(asoc->peer.port);
> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
> + } else {
> + if (dlen < sizeof(struct in6_addr))
> + goto free;
> +
> + dlen = sizeof(struct in6_addr);
> + daddr->v6.sin6_family = AF_INET6;
> + daddr->v6.sin6_port = htons(asoc->peer.port);
> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
> + }
> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
> + if (err)
> + goto free;
> +
> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> + if (old && old != asoc) {
> + if (old->state >= SCTP_STATE_ESTABLISHED)
> + err = -EISCONN;
> + else
> + err = -EALREADY;
> + goto free;
> + }
> +
> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
> + err = -EADDRNOTAVAIL;
> + goto free;
> + }
> +
> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
> + SCTP_UNKNOWN);
> + if (!transport) {
> + err = -ENOMEM;
> + goto free;
> + }
> + }
> +
> return 0;
>
> free:
> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
> cmsgs->prinfo->pr_value = 0;
> break;
> + case SCTP_DSTADDRV4:
> + case SCTP_DSTADDRV6:
> + /* SCTP Socket API Extension
> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
> + *
> + * This cmsghdr structure specifies SCTP options for sendmsg().
> + *
> + * cmsg_level cmsg_type cmsg_data[]
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
> + */
> + cmsgs->addrs_msg = my_msg;
> + break;
> default:
> return -EINVAL;
> }
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg
@ 2018-03-06 12:22 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:22 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:19PM +0800, Xin Long wrote:
> This patch is to add support for Destination IPv4/6 Address options
> for sendmsg, as described in section 5.3.9/10 of RFC6458.
>
> With this option, you can provide more than one destination addrs
> to sendmsg when creating asoc, like sctp_connectx.
>
> 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>
> ---
> include/net/sctp/structs.h | 1 +
> include/uapi/linux/sctp.h | 6 ++++
> net/sctp/socket.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 84 insertions(+)
>
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index d40a2a3..ec6e46b 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -2113,6 +2113,7 @@ struct sctp_cmsgs {
> struct sctp_sndrcvinfo *srinfo;
> struct sctp_sndinfo *sinfo;
> struct sctp_prinfo *prinfo;
> + struct msghdr *addrs_msg;
> };
>
> /* Structure for tracking memory objects */
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index 0dd1f82..a1bc350 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -308,6 +308,12 @@ typedef enum sctp_cmsg_type {
> #define SCTP_NXTINFO SCTP_NXTINFO
> SCTP_PRINFO, /* 5.3.7 SCTP PR-SCTP Information Structure */
> #define SCTP_PRINFO SCTP_PRINFO
> + SCTP_AUTHINFO, /* 5.3.8 SCTP AUTH Information Structure (RESERVED) */
> +#define SCTP_AUTHINFO SCTP_AUTHINFO
> + SCTP_DSTADDRV4, /* 5.3.9 SCTP Destination IPv4 Address Structure */
> +#define SCTP_DSTADDRV4 SCTP_DSTADDRV4
> + SCTP_DSTADDRV6, /* 5.3.10 SCTP Destination IPv6 Address Structure */
> +#define SCTP_DSTADDRV6 SCTP_DSTADDRV6
> } sctp_cmsg_t;
>
> /*
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index fdde697..067b57a 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1676,6 +1676,7 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> struct net *net = sock_net(sk);
> struct sctp_association *asoc;
> enum sctp_scope scope;
> + struct cmsghdr *cmsg;
> int err = -EINVAL;
>
> *tp = NULL;
> @@ -1741,6 +1742,67 @@ static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
> goto free;
> }
>
> + if (!cmsgs->addrs_msg)
> + return 0;
> +
> + /* sendv addr list parse */
> + for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
> + struct sctp_transport *transport;
> + struct sctp_association *old;
> + union sctp_addr _daddr;
> + int dlen;
> +
> + if (cmsg->cmsg_level != IPPROTO_SCTP ||
> + (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
> + cmsg->cmsg_type != SCTP_DSTADDRV6))
> + continue;
> +
> + daddr = &_daddr;
> + memset(daddr, 0, sizeof(*daddr));
> + dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
> + if (cmsg->cmsg_type = SCTP_DSTADDRV4) {
> + if (dlen < sizeof(struct in_addr))
> + goto free;
> +
> + dlen = sizeof(struct in_addr);
> + daddr->v4.sin_family = AF_INET;
> + daddr->v4.sin_port = htons(asoc->peer.port);
> + memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
> + } else {
> + if (dlen < sizeof(struct in6_addr))
> + goto free;
> +
> + dlen = sizeof(struct in6_addr);
> + daddr->v6.sin6_family = AF_INET6;
> + daddr->v6.sin6_port = htons(asoc->peer.port);
> + memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
> + }
> + err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
> + if (err)
> + goto free;
> +
> + old = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> + if (old && old != asoc) {
> + if (old->state >= SCTP_STATE_ESTABLISHED)
> + err = -EISCONN;
> + else
> + err = -EALREADY;
> + goto free;
> + }
> +
> + if (sctp_endpoint_is_peeled_off(ep, daddr)) {
> + err = -EADDRNOTAVAIL;
> + goto free;
> + }
> +
> + transport = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL,
> + SCTP_UNKNOWN);
> + if (!transport) {
> + err = -ENOMEM;
> + goto free;
> + }
> + }
> +
> return 0;
>
> free:
> @@ -7778,6 +7840,21 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
> if (cmsgs->prinfo->pr_policy = SCTP_PR_SCTP_NONE)
> cmsgs->prinfo->pr_value = 0;
> break;
> + case SCTP_DSTADDRV4:
> + case SCTP_DSTADDRV6:
> + /* SCTP Socket API Extension
> + * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
> + *
> + * This cmsghdr structure specifies SCTP options for sendmsg().
> + *
> + * cmsg_level cmsg_type cmsg_data[]
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
> + * ------------ ------------ ---------------------
> + * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
> + */
> + cmsgs->addrs_msg = my_msg;
> + break;
> default:
> return -EINVAL;
> }
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 3/3] sctp: add support for snd flag SCTP_SENDALL process in sendmsg
2018-03-05 12:44 ` Xin Long
@ 2018-03-06 12:22 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:22 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:20PM +0800, Xin Long wrote:
> This patch is to add support for snd flag SCTP_SENDALL process
> in sendmsg, as described in section 5.3.4 of RFC6458.
>
> With this flag, you can send the same data to all the asocs of
> this sk once.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> ---
> include/uapi/linux/sctp.h | 2 ++
> net/sctp/socket.c | 35 +++++++++++++++++++++++++++++++----
> 2 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index a1bc350..e94b6d2 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -284,6 +284,8 @@ enum sctp_sinfo_flags {
> SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */
> SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */
> SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */
> + /* 2 bits here have been used by SCTP_PR_SCTP_MASK */
> + SCTP_SENDALL = (1 << 6),
> SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */
> SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */
> };
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 067b57a..7d3476a 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1820,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
> if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
> return -EPIPE;
>
> + if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
> + !sctp_state(asoc, ESTABLISHED))
> + return 0;
> +
> if (sflags & SCTP_EOF) {
> pr_debug("%s: shutting down association:%p\n", __func__, asoc);
> sctp_primitive_SHUTDOWN(net, asoc, NULL);
> @@ -2007,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
>
> lock_sock(sk);
>
> + /* SCTP_SENDALL process */
> + if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
> + list_for_each_entry(asoc, &ep->asocs, asocs) {
> + err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
> + msg_len);
> + if (err == 0)
> + continue;
> + if (err < 0)
> + goto out_unlock;
> +
> + sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
> +
> + err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
> + NULL, sinfo);
> + if (err < 0)
> + goto out_unlock;
> +
> + iov_iter_revert(&msg->msg_iter, err);
> + }
> +
> + goto out_unlock;
> + }
> +
> /* Get and check or create asoc */
> if (daddr) {
> asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> @@ -7792,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
>
> if (cmsgs->srinfo->sinfo_flags &
> ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
> - SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
> - SCTP_ABORT | SCTP_EOF))
> + SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
> + SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
> return -EINVAL;
> break;
>
> @@ -7816,8 +7843,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
>
> if (cmsgs->sinfo->snd_flags &
> ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
> - SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
> - SCTP_ABORT | SCTP_EOF))
> + SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
> + SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
> return -EINVAL;
> break;
> case SCTP_PRINFO:
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 3/3] sctp: add support for snd flag SCTP_SENDALL process in sendmsg
@ 2018-03-06 12:22 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-03-06 12:22 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Mar 05, 2018 at 08:44:20PM +0800, Xin Long wrote:
> This patch is to add support for snd flag SCTP_SENDALL process
> in sendmsg, as described in section 5.3.4 of RFC6458.
>
> With this flag, you can send the same data to all the asocs of
> this sk once.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> ---
> include/uapi/linux/sctp.h | 2 ++
> net/sctp/socket.c | 35 +++++++++++++++++++++++++++++++----
> 2 files changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
> index a1bc350..e94b6d2 100644
> --- a/include/uapi/linux/sctp.h
> +++ b/include/uapi/linux/sctp.h
> @@ -284,6 +284,8 @@ enum sctp_sinfo_flags {
> SCTP_ADDR_OVER = (1 << 1), /* Override the primary destination. */
> SCTP_ABORT = (1 << 2), /* Send an ABORT message to the peer. */
> SCTP_SACK_IMMEDIATELY = (1 << 3), /* SACK should be sent without delay. */
> + /* 2 bits here have been used by SCTP_PR_SCTP_MASK */
> + SCTP_SENDALL = (1 << 6),
> SCTP_NOTIFICATION = MSG_NOTIFICATION, /* Next message is not user msg but notification. */
> SCTP_EOF = MSG_FIN, /* Initiate graceful shutdown process. */
> };
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 067b57a..7d3476a 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1820,6 +1820,10 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
> if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
> return -EPIPE;
>
> + if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
> + !sctp_state(asoc, ESTABLISHED))
> + return 0;
> +
> if (sflags & SCTP_EOF) {
> pr_debug("%s: shutting down association:%p\n", __func__, asoc);
> sctp_primitive_SHUTDOWN(net, asoc, NULL);
> @@ -2007,6 +2011,29 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
>
> lock_sock(sk);
>
> + /* SCTP_SENDALL process */
> + if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
> + list_for_each_entry(asoc, &ep->asocs, asocs) {
> + err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
> + msg_len);
> + if (err = 0)
> + continue;
> + if (err < 0)
> + goto out_unlock;
> +
> + sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
> +
> + err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
> + NULL, sinfo);
> + if (err < 0)
> + goto out_unlock;
> +
> + iov_iter_revert(&msg->msg_iter, err);
> + }
> +
> + goto out_unlock;
> + }
> +
> /* Get and check or create asoc */
> if (daddr) {
> asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
> @@ -7792,8 +7819,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
>
> if (cmsgs->srinfo->sinfo_flags &
> ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
> - SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
> - SCTP_ABORT | SCTP_EOF))
> + SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
> + SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
> return -EINVAL;
> break;
>
> @@ -7816,8 +7843,8 @@ static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
>
> if (cmsgs->sinfo->snd_flags &
> ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
> - SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK |
> - SCTP_ABORT | SCTP_EOF))
> + SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
> + SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
> return -EINVAL;
> break;
> case SCTP_PRINFO:
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458
2018-03-05 12:44 ` Xin Long
@ 2018-03-07 15:56 ` David Miller
-1 siblings, 0 replies; 46+ messages in thread
From: David Miller @ 2018-03-07 15:56 UTC (permalink / raw)
To: lucien.xin; +Cc: netdev, linux-sctp, marcelo.leitner, nhorman
From: Xin Long <lucien.xin@gmail.com>
Date: Mon, 5 Mar 2018 20:44:17 +0800
> This patchset is to add support for 3 msg_control options described
> in RFC6458:
>
> 5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
> 5.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
> 5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
>
> one send flag described in RFC6458:
>
> SCTP_SENDALL: This flag, if set, will cause a one-to-many
> style socket to send the message to all associations that
> are currently established on this socket. For the one-to-
> one style socket, this flag has no effect.
>
> Note there is another msg_control option:
>
> 5.3.8. SCTP AUTH Information Structure (SCTP_AUTHINFO)
>
> It's a little complicated, I will post it in another patchset after
> this.
Series applied, thanks Xin.
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458
@ 2018-03-07 15:56 ` David Miller
0 siblings, 0 replies; 46+ messages in thread
From: David Miller @ 2018-03-07 15:56 UTC (permalink / raw)
To: lucien.xin; +Cc: netdev, linux-sctp, marcelo.leitner, nhorman
From: Xin Long <lucien.xin@gmail.com>
Date: Mon, 5 Mar 2018 20:44:17 +0800
> This patchset is to add support for 3 msg_control options described
> in RFC6458:
>
> 5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
> 5.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
> 5.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
>
> one send flag described in RFC6458:
>
> SCTP_SENDALL: This flag, if set, will cause a one-to-many
> style socket to send the message to all associations that
> are currently established on this socket. For the one-to-
> one style socket, this flag has no effect.
>
> Note there is another msg_control option:
>
> 5.3.8. SCTP AUTH Information Structure (SCTP_AUTHINFO)
>
> It's a little complicated, I will post it in another patchset after
> this.
Series applied, thanks Xin.
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH net-next 0/3] sctp: add support for sk_reuseport
2018-03-05 12:44 ` Xin Long
@ 2018-10-21 4:43 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
sctp sk_reuseport allows multiple socks to listen on the same port and
addresses, as long as these socks have the same uid. This works pretty
much as TCP/UDP does, the only difference is that sctp is multi-homing
and all the bind_addrs in these socks will have to completely matched,
otherwise listen() will return err.
The below is when 5 sockets are listening on 172.16.254.254:6400 on a
server, 26 sockets on a client connect to 172.16.254.254:6400 and each
may be processed by a different socket on the server which is selected
by hash(lport, pport, paddr) in reuseport_select_sock():
# ss --sctp -nn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.3:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.4:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.253.253:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.5:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.1:1234
Xin Long (3):
sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
sctp: process sk_reuseport in sctp_get_port_local
include/net/sctp/sctp.h | 2 +-
include/net/sctp/structs.h | 6 ++-
net/core/sock_reuseport.c | 1 +
net/sctp/bind_addr.c | 28 ++++++++++
net/sctp/input.c | 129 ++++++++++++++++++++++++++++++++-------------
net/sctp/socket.c | 49 +++++++++++------
6 files changed, 162 insertions(+), 53 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH net-next 0/3] sctp: add support for sk_reuseport
@ 2018-10-21 4:43 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
sctp sk_reuseport allows multiple socks to listen on the same port and
addresses, as long as these socks have the same uid. This works pretty
much as TCP/UDP does, the only difference is that sctp is multi-homing
and all the bind_addrs in these socks will have to completely matched,
otherwise listen() will return err.
The below is when 5 sockets are listening on 172.16.254.254:6400 on a
server, 26 sockets on a client connect to 172.16.254.254:6400 and each
may be processed by a different socket on the server which is selected
by hash(lport, pport, paddr) in reuseport_select_sock():
# ss --sctp -nn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.3:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.4:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.253.253:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.2:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.3:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.4:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.5:1234
LISTEN 0 10 172.16.254.254:6400 *:*
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.5:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.1:1234
`- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.1:1234
Xin Long (3):
sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
sctp: process sk_reuseport in sctp_get_port_local
include/net/sctp/sctp.h | 2 +-
include/net/sctp/structs.h | 6 ++-
net/core/sock_reuseport.c | 1 +
net/sctp/bind_addr.c | 28 ++++++++++
net/sctp/input.c | 129 ++++++++++++++++++++++++++++++++-------------
net/sctp/socket.c | 49 +++++++++++------
6 files changed, 162 insertions(+), 53 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
2018-10-21 4:43 ` Xin Long
@ 2018-10-21 4:43 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This is a part of sk_reuseport support for sctp, and it selects a
sock by the hashkey of lport, paddr and dport by default. It will
work until sk_reuseport support is added in sctp_get_port_local()
in the next patch.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/sctp/input.c | 69 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 41 insertions(+), 28 deletions(-)
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 5c36a99..60ede89 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -57,6 +57,7 @@
#include <net/sctp/checksum.h>
#include <net/net_namespace.h>
#include <linux/rhashtable.h>
+#include <net/sock_reuseport.h>
/* Forward declarations for internal helpers. */
static int sctp_rcv_ootb(struct sk_buff *);
@@ -65,8 +66,10 @@ static struct sctp_association *__sctp_rcv_lookup(struct net *net,
const union sctp_addr *paddr,
const union sctp_addr *laddr,
struct sctp_transport **transportp);
-static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
- const union sctp_addr *laddr);
+static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
+ struct net *net, struct sk_buff *skb,
+ const union sctp_addr *laddr,
+ const union sctp_addr *daddr);
static struct sctp_association *__sctp_lookup_association(
struct net *net,
const union sctp_addr *local,
@@ -171,7 +174,7 @@ int sctp_rcv(struct sk_buff *skb)
asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
if (!asoc)
- ep = __sctp_rcv_lookup_endpoint(net, &dest);
+ ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
/* Retrieve the common input handling substructure. */
rcvr = asoc ? &asoc->base : &ep->base;
@@ -770,16 +773,35 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
local_bh_enable();
}
+static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
+ const union sctp_addr *paddr, __u32 seed)
+{
+ __u32 addr;
+
+ if (paddr->sa.sa_family == AF_INET6)
+ addr = jhash(&paddr->v6.sin6_addr, 16, seed);
+ else
+ addr = (__force __u32)paddr->v4.sin_addr.s_addr;
+
+ return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
+ (__force __u32)lport, net_hash_mix(net), seed);
+}
+
/* Look up an endpoint. */
-static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
- const union sctp_addr *laddr)
+static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
+ struct net *net, struct sk_buff *skb,
+ const union sctp_addr *laddr,
+ const union sctp_addr *paddr)
{
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_endpoint *ep;
+ struct sock *sk;
+ __be32 lport;
int hash;
- hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
+ lport = laddr->v4.sin_port;
+ hash = sctp_ep_hashfn(net, ntohs(lport));
head = &sctp_ep_hashtable[hash];
read_lock(&head->lock);
sctp_for_each_hentry(epb, &head->chain) {
@@ -791,6 +813,15 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
ep = sctp_sk(net->sctp.ctl_sock)->ep;
hit:
+ sk = ep->base.sk;
+ if (sk->sk_reuseport) {
+ __u32 phash = sctp_hashfn(net, lport, paddr, 0);
+
+ sk = reuseport_select_sock(sk, phash, skb,
+ sizeof(struct sctphdr));
+ if (sk)
+ ep = sctp_sk(sk)->ep;
+ }
sctp_endpoint_hold(ep);
read_unlock(&head->lock);
return ep;
@@ -829,35 +860,17 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
{
const struct sctp_transport *t = data;
- const union sctp_addr *paddr = &t->ipaddr;
- const struct net *net = sock_net(t->asoc->base.sk);
- __be16 lport = htons(t->asoc->base.bind_addr.port);
- __u32 addr;
-
- if (paddr->sa.sa_family == AF_INET6)
- addr = jhash(&paddr->v6.sin6_addr, 16, seed);
- else
- addr = (__force __u32)paddr->v4.sin_addr.s_addr;
- return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
- (__force __u32)lport, net_hash_mix(net), seed);
+ return sctp_hashfn(sock_net(t->asoc->base.sk),
+ htons(t->asoc->base.bind_addr.port),
+ &t->ipaddr, seed);
}
static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
{
const struct sctp_hash_cmp_arg *x = data;
- const union sctp_addr *paddr = x->paddr;
- const struct net *net = x->net;
- __be16 lport = x->lport;
- __u32 addr;
-
- if (paddr->sa.sa_family == AF_INET6)
- addr = jhash(&paddr->v6.sin6_addr, 16, seed);
- else
- addr = (__force __u32)paddr->v4.sin_addr.s_addr;
- return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
- (__force __u32)lport, net_hash_mix(net), seed);
+ return sctp_hashfn(x->net, x->lport, x->paddr, seed);
}
static const struct rhashtable_params sctp_hash_params = {
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
@ 2018-10-21 4:43 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This is a part of sk_reuseport support for sctp, and it selects a
sock by the hashkey of lport, paddr and dport by default. It will
work until sk_reuseport support is added in sctp_get_port_local()
in the next patch.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/sctp/input.c | 69 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 41 insertions(+), 28 deletions(-)
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 5c36a99..60ede89 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -57,6 +57,7 @@
#include <net/sctp/checksum.h>
#include <net/net_namespace.h>
#include <linux/rhashtable.h>
+#include <net/sock_reuseport.h>
/* Forward declarations for internal helpers. */
static int sctp_rcv_ootb(struct sk_buff *);
@@ -65,8 +66,10 @@ static struct sctp_association *__sctp_rcv_lookup(struct net *net,
const union sctp_addr *paddr,
const union sctp_addr *laddr,
struct sctp_transport **transportp);
-static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
- const union sctp_addr *laddr);
+static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
+ struct net *net, struct sk_buff *skb,
+ const union sctp_addr *laddr,
+ const union sctp_addr *daddr);
static struct sctp_association *__sctp_lookup_association(
struct net *net,
const union sctp_addr *local,
@@ -171,7 +174,7 @@ int sctp_rcv(struct sk_buff *skb)
asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
if (!asoc)
- ep = __sctp_rcv_lookup_endpoint(net, &dest);
+ ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
/* Retrieve the common input handling substructure. */
rcvr = asoc ? &asoc->base : &ep->base;
@@ -770,16 +773,35 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
local_bh_enable();
}
+static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
+ const union sctp_addr *paddr, __u32 seed)
+{
+ __u32 addr;
+
+ if (paddr->sa.sa_family = AF_INET6)
+ addr = jhash(&paddr->v6.sin6_addr, 16, seed);
+ else
+ addr = (__force __u32)paddr->v4.sin_addr.s_addr;
+
+ return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
+ (__force __u32)lport, net_hash_mix(net), seed);
+}
+
/* Look up an endpoint. */
-static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
- const union sctp_addr *laddr)
+static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
+ struct net *net, struct sk_buff *skb,
+ const union sctp_addr *laddr,
+ const union sctp_addr *paddr)
{
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_endpoint *ep;
+ struct sock *sk;
+ __be32 lport;
int hash;
- hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
+ lport = laddr->v4.sin_port;
+ hash = sctp_ep_hashfn(net, ntohs(lport));
head = &sctp_ep_hashtable[hash];
read_lock(&head->lock);
sctp_for_each_hentry(epb, &head->chain) {
@@ -791,6 +813,15 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
ep = sctp_sk(net->sctp.ctl_sock)->ep;
hit:
+ sk = ep->base.sk;
+ if (sk->sk_reuseport) {
+ __u32 phash = sctp_hashfn(net, lport, paddr, 0);
+
+ sk = reuseport_select_sock(sk, phash, skb,
+ sizeof(struct sctphdr));
+ if (sk)
+ ep = sctp_sk(sk)->ep;
+ }
sctp_endpoint_hold(ep);
read_unlock(&head->lock);
return ep;
@@ -829,35 +860,17 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
{
const struct sctp_transport *t = data;
- const union sctp_addr *paddr = &t->ipaddr;
- const struct net *net = sock_net(t->asoc->base.sk);
- __be16 lport = htons(t->asoc->base.bind_addr.port);
- __u32 addr;
-
- if (paddr->sa.sa_family = AF_INET6)
- addr = jhash(&paddr->v6.sin6_addr, 16, seed);
- else
- addr = (__force __u32)paddr->v4.sin_addr.s_addr;
- return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
- (__force __u32)lport, net_hash_mix(net), seed);
+ return sctp_hashfn(sock_net(t->asoc->base.sk),
+ htons(t->asoc->base.bind_addr.port),
+ &t->ipaddr, seed);
}
static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
{
const struct sctp_hash_cmp_arg *x = data;
- const union sctp_addr *paddr = x->paddr;
- const struct net *net = x->net;
- __be16 lport = x->lport;
- __u32 addr;
-
- if (paddr->sa.sa_family = AF_INET6)
- addr = jhash(&paddr->v6.sin6_addr, 16, seed);
- else
- addr = (__force __u32)paddr->v4.sin_addr.s_addr;
- return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
- (__force __u32)lport, net_hash_mix(net), seed);
+ return sctp_hashfn(x->net, x->lport, x->paddr, seed);
}
static const struct rhashtable_params sctp_hash_params = {
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
2018-10-21 4:43 ` Xin Long
@ 2018-10-21 4:43 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This is a part of sk_reuseport support for sctp. It defines a helper
sctp_bind_addrs_check() to check if the bind_addrs in two socks are
matched. It will add sock_reuseport if they are completely matched,
and return err if they are partly matched, and alloc sock_reuseport
if all socks are not matched at all.
It will work until sk_reuseport support is added in
sctp_get_port_local() in the next patch.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/sctp.h | 2 +-
include/net/sctp/structs.h | 2 ++
net/core/sock_reuseport.c | 1 +
net/sctp/bind_addr.c | 28 ++++++++++++++++++++++
net/sctp/input.c | 60 +++++++++++++++++++++++++++++++++++++++-------
net/sctp/socket.c | 3 +--
6 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 8c2caa3..b8cd58d 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -152,7 +152,7 @@ int sctp_primitive_RECONF(struct net *net, struct sctp_association *asoc,
*/
int sctp_rcv(struct sk_buff *skb);
void sctp_v4_err(struct sk_buff *skb, u32 info);
-void sctp_hash_endpoint(struct sctp_endpoint *);
+int sctp_hash_endpoint(struct sctp_endpoint *ep);
void sctp_unhash_endpoint(struct sctp_endpoint *);
struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
struct sctphdr *, struct sctp_association **,
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index a11f937..15d017f 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1190,6 +1190,8 @@ int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
struct sctp_sock *, struct sctp_sock *);
int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
const union sctp_addr *addr);
+int sctp_bind_addrs_check(struct sctp_sock *sp,
+ struct sctp_sock *sp2, int cnt2);
union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
const union sctp_addr *addrs,
int addrcnt,
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index ba5cba5..d8fe3e5 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -187,6 +187,7 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
call_rcu(&old_reuse->rcu, reuseport_free_rcu);
return 0;
}
+EXPORT_SYMBOL(reuseport_add_sock);
void reuseport_detach_sock(struct sock *sk)
{
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index 7df3704..78d0d93 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -337,6 +337,34 @@ int sctp_bind_addr_match(struct sctp_bind_addr *bp,
return match;
}
+int sctp_bind_addrs_check(struct sctp_sock *sp,
+ struct sctp_sock *sp2, int cnt2)
+{
+ struct sctp_bind_addr *bp2 = &sp2->ep->base.bind_addr;
+ struct sctp_bind_addr *bp = &sp->ep->base.bind_addr;
+ struct sctp_sockaddr_entry *laddr, *laddr2;
+ bool exist = false;
+ int cnt = 0;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(laddr, &bp->address_list, list) {
+ list_for_each_entry_rcu(laddr2, &bp2->address_list, list) {
+ if (sp->pf->af->cmp_addr(&laddr->a, &laddr2->a) &&
+ laddr->valid == laddr2->valid) {
+ exist = true;
+ goto next;
+ }
+ }
+ cnt = 0;
+ break;
+next:
+ cnt++;
+ }
+ rcu_read_unlock();
+
+ return (cnt == cnt2) ? 0 : (exist ? -EEXIST : 1);
+}
+
/* Does the address 'addr' conflict with any addresses in
* the bp.
*/
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 60ede89..6bfeb10 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -723,43 +723,87 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
}
/* Insert endpoint into the hash table. */
-static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
+static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
{
- struct net *net = sock_net(ep->base.sk);
- struct sctp_ep_common *epb;
+ struct sock *sk = ep->base.sk;
+ struct net *net = sock_net(sk);
struct sctp_hashbucket *head;
+ struct sctp_ep_common *epb;
epb = &ep->base;
-
epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
head = &sctp_ep_hashtable[epb->hashent];
+ if (sk->sk_reuseport) {
+ bool any = sctp_is_ep_boundall(sk);
+ struct sctp_ep_common *epb2;
+ struct list_head *list;
+ int cnt = 0, err = 1;
+
+ list_for_each(list, &ep->base.bind_addr.address_list)
+ cnt++;
+
+ sctp_for_each_hentry(epb2, &head->chain) {
+ struct sock *sk2 = epb2->sk;
+
+ if (!net_eq(sock_net(sk2), net) || sk2 == sk ||
+ !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
+ !sk2->sk_reuseport)
+ continue;
+
+ err = sctp_bind_addrs_check(sctp_sk(sk2),
+ sctp_sk(sk), cnt);
+ if (!err) {
+ err = reuseport_add_sock(sk, sk2, any);
+ if (err)
+ return err;
+ break;
+ } else if (err < 0) {
+ return err;
+ }
+ }
+
+ if (err) {
+ err = reuseport_alloc(sk, any);
+ if (err)
+ return err;
+ }
+ }
+
write_lock(&head->lock);
hlist_add_head(&epb->node, &head->chain);
write_unlock(&head->lock);
+ return 0;
}
/* Add an endpoint to the hash. Local BH-safe. */
-void sctp_hash_endpoint(struct sctp_endpoint *ep)
+int sctp_hash_endpoint(struct sctp_endpoint *ep)
{
+ int err;
+
local_bh_disable();
- __sctp_hash_endpoint(ep);
+ err = __sctp_hash_endpoint(ep);
local_bh_enable();
+
+ return err;
}
/* Remove endpoint from the hash table. */
static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
{
- struct net *net = sock_net(ep->base.sk);
+ struct sock *sk = ep->base.sk;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
epb = &ep->base;
- epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
+ epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
head = &sctp_ep_hashtable[epb->hashent];
+ if (rcu_access_pointer(sk->sk_reuseport_cb))
+ reuseport_detach_sock(sk);
+
write_lock(&head->lock);
hlist_del_init(&epb->node);
write_unlock(&head->lock);
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index fc0386e..44e7d8c 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -7850,8 +7850,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
}
sk->sk_max_ack_backlog = backlog;
- sctp_hash_endpoint(ep);
- return 0;
+ return sctp_hash_endpoint(ep);
}
/*
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
@ 2018-10-21 4:43 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
This is a part of sk_reuseport support for sctp. It defines a helper
sctp_bind_addrs_check() to check if the bind_addrs in two socks are
matched. It will add sock_reuseport if they are completely matched,
and return err if they are partly matched, and alloc sock_reuseport
if all socks are not matched at all.
It will work until sk_reuseport support is added in
sctp_get_port_local() in the next patch.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/sctp.h | 2 +-
include/net/sctp/structs.h | 2 ++
net/core/sock_reuseport.c | 1 +
net/sctp/bind_addr.c | 28 ++++++++++++++++++++++
net/sctp/input.c | 60 +++++++++++++++++++++++++++++++++++++++-------
net/sctp/socket.c | 3 +--
6 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 8c2caa3..b8cd58d 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -152,7 +152,7 @@ int sctp_primitive_RECONF(struct net *net, struct sctp_association *asoc,
*/
int sctp_rcv(struct sk_buff *skb);
void sctp_v4_err(struct sk_buff *skb, u32 info);
-void sctp_hash_endpoint(struct sctp_endpoint *);
+int sctp_hash_endpoint(struct sctp_endpoint *ep);
void sctp_unhash_endpoint(struct sctp_endpoint *);
struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
struct sctphdr *, struct sctp_association **,
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index a11f937..15d017f 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1190,6 +1190,8 @@ int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
struct sctp_sock *, struct sctp_sock *);
int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
const union sctp_addr *addr);
+int sctp_bind_addrs_check(struct sctp_sock *sp,
+ struct sctp_sock *sp2, int cnt2);
union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
const union sctp_addr *addrs,
int addrcnt,
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index ba5cba5..d8fe3e5 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -187,6 +187,7 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
call_rcu(&old_reuse->rcu, reuseport_free_rcu);
return 0;
}
+EXPORT_SYMBOL(reuseport_add_sock);
void reuseport_detach_sock(struct sock *sk)
{
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index 7df3704..78d0d93 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -337,6 +337,34 @@ int sctp_bind_addr_match(struct sctp_bind_addr *bp,
return match;
}
+int sctp_bind_addrs_check(struct sctp_sock *sp,
+ struct sctp_sock *sp2, int cnt2)
+{
+ struct sctp_bind_addr *bp2 = &sp2->ep->base.bind_addr;
+ struct sctp_bind_addr *bp = &sp->ep->base.bind_addr;
+ struct sctp_sockaddr_entry *laddr, *laddr2;
+ bool exist = false;
+ int cnt = 0;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(laddr, &bp->address_list, list) {
+ list_for_each_entry_rcu(laddr2, &bp2->address_list, list) {
+ if (sp->pf->af->cmp_addr(&laddr->a, &laddr2->a) &&
+ laddr->valid = laddr2->valid) {
+ exist = true;
+ goto next;
+ }
+ }
+ cnt = 0;
+ break;
+next:
+ cnt++;
+ }
+ rcu_read_unlock();
+
+ return (cnt = cnt2) ? 0 : (exist ? -EEXIST : 1);
+}
+
/* Does the address 'addr' conflict with any addresses in
* the bp.
*/
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 60ede89..6bfeb10 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -723,43 +723,87 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
}
/* Insert endpoint into the hash table. */
-static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
+static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
{
- struct net *net = sock_net(ep->base.sk);
- struct sctp_ep_common *epb;
+ struct sock *sk = ep->base.sk;
+ struct net *net = sock_net(sk);
struct sctp_hashbucket *head;
+ struct sctp_ep_common *epb;
epb = &ep->base;
-
epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
head = &sctp_ep_hashtable[epb->hashent];
+ if (sk->sk_reuseport) {
+ bool any = sctp_is_ep_boundall(sk);
+ struct sctp_ep_common *epb2;
+ struct list_head *list;
+ int cnt = 0, err = 1;
+
+ list_for_each(list, &ep->base.bind_addr.address_list)
+ cnt++;
+
+ sctp_for_each_hentry(epb2, &head->chain) {
+ struct sock *sk2 = epb2->sk;
+
+ if (!net_eq(sock_net(sk2), net) || sk2 = sk ||
+ !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
+ !sk2->sk_reuseport)
+ continue;
+
+ err = sctp_bind_addrs_check(sctp_sk(sk2),
+ sctp_sk(sk), cnt);
+ if (!err) {
+ err = reuseport_add_sock(sk, sk2, any);
+ if (err)
+ return err;
+ break;
+ } else if (err < 0) {
+ return err;
+ }
+ }
+
+ if (err) {
+ err = reuseport_alloc(sk, any);
+ if (err)
+ return err;
+ }
+ }
+
write_lock(&head->lock);
hlist_add_head(&epb->node, &head->chain);
write_unlock(&head->lock);
+ return 0;
}
/* Add an endpoint to the hash. Local BH-safe. */
-void sctp_hash_endpoint(struct sctp_endpoint *ep)
+int sctp_hash_endpoint(struct sctp_endpoint *ep)
{
+ int err;
+
local_bh_disable();
- __sctp_hash_endpoint(ep);
+ err = __sctp_hash_endpoint(ep);
local_bh_enable();
+
+ return err;
}
/* Remove endpoint from the hash table. */
static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
{
- struct net *net = sock_net(ep->base.sk);
+ struct sock *sk = ep->base.sk;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
epb = &ep->base;
- epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
+ epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
head = &sctp_ep_hashtable[epb->hashent];
+ if (rcu_access_pointer(sk->sk_reuseport_cb))
+ reuseport_detach_sock(sk);
+
write_lock(&head->lock);
hlist_del_init(&epb->node);
write_unlock(&head->lock);
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index fc0386e..44e7d8c 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -7850,8 +7850,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
}
sk->sk_max_ack_backlog = backlog;
- sctp_hash_endpoint(ep);
- return 0;
+ return sctp_hash_endpoint(ep);
}
/*
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 3/3] sctp: process sk_reuseport in sctp_get_port_local
2018-10-21 4:43 ` Xin Long
@ 2018-10-21 4:43 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
When socks' sk_reuseport is set, the same port and address are allowed
to be bound into these socks who have the same uid.
Note that the difference from sk_reuse is that it allows multiple socks
to listen on the same port and address.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/structs.h | 4 +++-
net/sctp/socket.c | 46 +++++++++++++++++++++++++++++++++-------------
2 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 15d017f..af9d494 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -96,7 +96,9 @@ struct sctp_stream;
struct sctp_bind_bucket {
unsigned short port;
- unsigned short fastreuse;
+ signed char fastreuse;
+ signed char fastreuseport;
+ kuid_t fastuid;
struct hlist_node node;
struct hlist_head owner;
struct net *net;
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 44e7d8c..8605705 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -7642,8 +7642,10 @@ static struct sctp_bind_bucket *sctp_bucket_create(
static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
{
- bool reuse = (sk->sk_reuse || sctp_sk(sk)->reuse);
+ struct sctp_sock *sp = sctp_sk(sk);
+ bool reuse = (sk->sk_reuse || sp->reuse);
struct sctp_bind_hashbucket *head; /* hash list */
+ kuid_t uid = sock_i_uid(sk);
struct sctp_bind_bucket *pp;
unsigned short snum;
int ret;
@@ -7719,7 +7721,10 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
pr_debug("%s: found a possible match\n", __func__);
- if (pp->fastreuse && reuse && sk->sk_state != SCTP_SS_LISTENING)
+ if ((pp->fastreuse && reuse &&
+ sk->sk_state != SCTP_SS_LISTENING) ||
+ (pp->fastreuseport && sk->sk_reuseport &&
+ uid_eq(pp->fastuid, uid)))
goto success;
/* Run through the list of sockets bound to the port
@@ -7733,16 +7738,18 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
* in an endpoint.
*/
sk_for_each_bound(sk2, &pp->owner) {
- struct sctp_endpoint *ep2;
- ep2 = sctp_sk(sk2)->ep;
+ struct sctp_sock *sp2 = sctp_sk(sk2);
+ struct sctp_endpoint *ep2 = sp2->ep;
if (sk == sk2 ||
- (reuse && (sk2->sk_reuse || sctp_sk(sk2)->reuse) &&
- sk2->sk_state != SCTP_SS_LISTENING))
+ (reuse && (sk2->sk_reuse || sp2->reuse) &&
+ sk2->sk_state != SCTP_SS_LISTENING) ||
+ (sk->sk_reuseport && sk2->sk_reuseport &&
+ uid_eq(uid, sock_i_uid(sk2))))
continue;
- if (sctp_bind_addr_conflict(&ep2->base.bind_addr, addr,
- sctp_sk(sk2), sctp_sk(sk))) {
+ if (sctp_bind_addr_conflict(&ep2->base.bind_addr,
+ addr, sp2, sp)) {
ret = (long)sk2;
goto fail_unlock;
}
@@ -7765,19 +7772,32 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
pp->fastreuse = 1;
else
pp->fastreuse = 0;
- } else if (pp->fastreuse &&
- (!reuse || sk->sk_state == SCTP_SS_LISTENING))
- pp->fastreuse = 0;
+
+ if (sk->sk_reuseport) {
+ pp->fastreuseport = 1;
+ pp->fastuid = uid;
+ } else {
+ pp->fastreuseport = 0;
+ }
+ } else {
+ if (pp->fastreuse &&
+ (!reuse || sk->sk_state == SCTP_SS_LISTENING))
+ pp->fastreuse = 0;
+
+ if (pp->fastreuseport &&
+ (!sk->sk_reuseport || !uid_eq(pp->fastuid, uid)))
+ pp->fastreuseport = 0;
+ }
/* We are set, so fill up all the data in the hash table
* entry, tie the socket list information with the rest of the
* sockets FIXME: Blurry, NPI (ipg).
*/
success:
- if (!sctp_sk(sk)->bind_hash) {
+ if (!sp->bind_hash) {
inet_sk(sk)->inet_num = snum;
sk_add_bind_node(sk, &pp->owner);
- sctp_sk(sk)->bind_hash = pp;
+ sp->bind_hash = pp;
}
ret = 0;
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH net-next 3/3] sctp: process sk_reuseport in sctp_get_port_local
@ 2018-10-21 4:43 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 4:43 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
When socks' sk_reuseport is set, the same port and address are allowed
to be bound into these socks who have the same uid.
Note that the difference from sk_reuse is that it allows multiple socks
to listen on the same port and address.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/structs.h | 4 +++-
net/sctp/socket.c | 46 +++++++++++++++++++++++++++++++++-------------
2 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 15d017f..af9d494 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -96,7 +96,9 @@ struct sctp_stream;
struct sctp_bind_bucket {
unsigned short port;
- unsigned short fastreuse;
+ signed char fastreuse;
+ signed char fastreuseport;
+ kuid_t fastuid;
struct hlist_node node;
struct hlist_head owner;
struct net *net;
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 44e7d8c..8605705 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -7642,8 +7642,10 @@ static struct sctp_bind_bucket *sctp_bucket_create(
static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
{
- bool reuse = (sk->sk_reuse || sctp_sk(sk)->reuse);
+ struct sctp_sock *sp = sctp_sk(sk);
+ bool reuse = (sk->sk_reuse || sp->reuse);
struct sctp_bind_hashbucket *head; /* hash list */
+ kuid_t uid = sock_i_uid(sk);
struct sctp_bind_bucket *pp;
unsigned short snum;
int ret;
@@ -7719,7 +7721,10 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
pr_debug("%s: found a possible match\n", __func__);
- if (pp->fastreuse && reuse && sk->sk_state != SCTP_SS_LISTENING)
+ if ((pp->fastreuse && reuse &&
+ sk->sk_state != SCTP_SS_LISTENING) ||
+ (pp->fastreuseport && sk->sk_reuseport &&
+ uid_eq(pp->fastuid, uid)))
goto success;
/* Run through the list of sockets bound to the port
@@ -7733,16 +7738,18 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
* in an endpoint.
*/
sk_for_each_bound(sk2, &pp->owner) {
- struct sctp_endpoint *ep2;
- ep2 = sctp_sk(sk2)->ep;
+ struct sctp_sock *sp2 = sctp_sk(sk2);
+ struct sctp_endpoint *ep2 = sp2->ep;
if (sk = sk2 ||
- (reuse && (sk2->sk_reuse || sctp_sk(sk2)->reuse) &&
- sk2->sk_state != SCTP_SS_LISTENING))
+ (reuse && (sk2->sk_reuse || sp2->reuse) &&
+ sk2->sk_state != SCTP_SS_LISTENING) ||
+ (sk->sk_reuseport && sk2->sk_reuseport &&
+ uid_eq(uid, sock_i_uid(sk2))))
continue;
- if (sctp_bind_addr_conflict(&ep2->base.bind_addr, addr,
- sctp_sk(sk2), sctp_sk(sk))) {
+ if (sctp_bind_addr_conflict(&ep2->base.bind_addr,
+ addr, sp2, sp)) {
ret = (long)sk2;
goto fail_unlock;
}
@@ -7765,19 +7772,32 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
pp->fastreuse = 1;
else
pp->fastreuse = 0;
- } else if (pp->fastreuse &&
- (!reuse || sk->sk_state = SCTP_SS_LISTENING))
- pp->fastreuse = 0;
+
+ if (sk->sk_reuseport) {
+ pp->fastreuseport = 1;
+ pp->fastuid = uid;
+ } else {
+ pp->fastreuseport = 0;
+ }
+ } else {
+ if (pp->fastreuse &&
+ (!reuse || sk->sk_state = SCTP_SS_LISTENING))
+ pp->fastreuse = 0;
+
+ if (pp->fastreuseport &&
+ (!sk->sk_reuseport || !uid_eq(pp->fastuid, uid)))
+ pp->fastreuseport = 0;
+ }
/* We are set, so fill up all the data in the hash table
* entry, tie the socket list information with the rest of the
* sockets FIXME: Blurry, NPI (ipg).
*/
success:
- if (!sctp_sk(sk)->bind_hash) {
+ if (!sp->bind_hash) {
inet_sk(sk)->inet_num = snum;
sk_add_bind_node(sk, &pp->owner);
- sctp_sk(sk)->bind_hash = pp;
+ sp->bind_hash = pp;
}
ret = 0;
--
2.1.0
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for sk_reuseport
2018-10-21 4:43 ` Xin Long
@ 2018-10-21 6:58 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 6:58 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
[-- Attachment #1: Type: text/plain, Size: 3812 bytes --]
On Sun, Oct 21, 2018 at 1:43 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> sctp sk_reuseport allows multiple socks to listen on the same port and
> addresses, as long as these socks have the same uid. This works pretty
> much as TCP/UDP does, the only difference is that sctp is multi-homing
> and all the bind_addrs in these socks will have to completely matched,
> otherwise listen() will return err.
>
> The below is when 5 sockets are listening on 172.16.254.254:6400 on a
> server, 26 sockets on a client connect to 172.16.254.254:6400 and each
> may be processed by a different socket on the server which is selected
> by hash(lport, pport, paddr) in reuseport_select_sock():
>
> # ss --sctp -nn
> State Recv-Q Send-Q Local Address:Port Peer Address:Port
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.3:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.4:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.253.253:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.5:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.1:1234
Attached is the testcase based on sctp-tests.git.
>
> Xin Long (3):
> sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
> sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
> sctp: process sk_reuseport in sctp_get_port_local
>
> include/net/sctp/sctp.h | 2 +-
> include/net/sctp/structs.h | 6 ++-
> net/core/sock_reuseport.c | 1 +
> net/sctp/bind_addr.c | 28 ++++++++++
> net/sctp/input.c | 129 ++++++++++++++++++++++++++++++++-------------
> net/sctp/socket.c | 49 +++++++++++------
> 6 files changed, 162 insertions(+), 53 deletions(-)
>
> --
> 2.1.0
>
[-- Attachment #2: reuseport.tar.gz --]
[-- Type: application/x-gzip, Size: 2501 bytes --]
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for sk_reuseport
@ 2018-10-21 6:58 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-10-21 6:58 UTC (permalink / raw)
To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem
[-- Attachment #1: Type: text/plain, Size: 3812 bytes --]
On Sun, Oct 21, 2018 at 1:43 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> sctp sk_reuseport allows multiple socks to listen on the same port and
> addresses, as long as these socks have the same uid. This works pretty
> much as TCP/UDP does, the only difference is that sctp is multi-homing
> and all the bind_addrs in these socks will have to completely matched,
> otherwise listen() will return err.
>
> The below is when 5 sockets are listening on 172.16.254.254:6400 on a
> server, 26 sockets on a client connect to 172.16.254.254:6400 and each
> may be processed by a different socket on the server which is selected
> by hash(lport, pport, paddr) in reuseport_select_sock():
>
> # ss --sctp -nn
> State Recv-Q Send-Q Local Address:Port Peer Address:Port
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.3:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.4:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.253.253:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.5:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.1:1234
Attached is the testcase based on sctp-tests.git.
>
> Xin Long (3):
> sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
> sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
> sctp: process sk_reuseport in sctp_get_port_local
>
> include/net/sctp/sctp.h | 2 +-
> include/net/sctp/structs.h | 6 ++-
> net/core/sock_reuseport.c | 1 +
> net/sctp/bind_addr.c | 28 ++++++++++
> net/sctp/input.c | 129 ++++++++++++++++++++++++++++++++-------------
> net/sctp/socket.c | 49 +++++++++++------
> 6 files changed, 162 insertions(+), 53 deletions(-)
>
> --
> 2.1.0
>
[-- Attachment #2: reuseport.tar.gz --]
[-- Type: application/x-gzip, Size: 2501 bytes --]
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for sk_reuseport
2018-10-21 4:43 ` Xin Long
@ 2018-10-22 11:40 ` Neil Horman
-1 siblings, 0 replies; 46+ messages in thread
From: Neil Horman @ 2018-10-22 11:40 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, davem
On Sun, Oct 21, 2018 at 12:43:35PM +0800, Xin Long wrote:
> sctp sk_reuseport allows multiple socks to listen on the same port and
> addresses, as long as these socks have the same uid. This works pretty
> much as TCP/UDP does, the only difference is that sctp is multi-homing
> and all the bind_addrs in these socks will have to completely matched,
> otherwise listen() will return err.
>
> The below is when 5 sockets are listening on 172.16.254.254:6400 on a
> server, 26 sockets on a client connect to 172.16.254.254:6400 and each
> may be processed by a different socket on the server which is selected
> by hash(lport, pport, paddr) in reuseport_select_sock():
>
> # ss --sctp -nn
> State Recv-Q Send-Q Local Address:Port Peer Address:Port
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.3:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.4:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.253.253:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.5:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.1:1234
>
> Xin Long (3):
> sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
> sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
> sctp: process sk_reuseport in sctp_get_port_local
>
> include/net/sctp/sctp.h | 2 +-
> include/net/sctp/structs.h | 6 ++-
> net/core/sock_reuseport.c | 1 +
> net/sctp/bind_addr.c | 28 ++++++++++
> net/sctp/input.c | 129 ++++++++++++++++++++++++++++++++-------------
> net/sctp/socket.c | 49 +++++++++++------
> 6 files changed, 162 insertions(+), 53 deletions(-)
>
> --
> 2.1.0
>
>
Series
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for sk_reuseport
@ 2018-10-22 11:40 ` Neil Horman
0 siblings, 0 replies; 46+ messages in thread
From: Neil Horman @ 2018-10-22 11:40 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, davem
On Sun, Oct 21, 2018 at 12:43:35PM +0800, Xin Long wrote:
> sctp sk_reuseport allows multiple socks to listen on the same port and
> addresses, as long as these socks have the same uid. This works pretty
> much as TCP/UDP does, the only difference is that sctp is multi-homing
> and all the bind_addrs in these socks will have to completely matched,
> otherwise listen() will return err.
>
> The below is when 5 sockets are listening on 172.16.254.254:6400 on a
> server, 26 sockets on a client connect to 172.16.254.254:6400 and each
> may be processed by a different socket on the server which is selected
> by hash(lport, pport, paddr) in reuseport_select_sock():
>
> # ss --sctp -nn
> State Recv-Q Send-Q Local Address:Port Peer Address:Port
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.3:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.4:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.4.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.253.253:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.2:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.3:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.4:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.5:1234
> LISTEN 0 10 172.16.254.254:6400 *:*
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.1.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.2.5:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.3.1:1234
> `- ESTAB 0 0 172.16.254.254%eth1:6400 172.16.5.1:1234
>
> Xin Long (3):
> sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
> sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
> sctp: process sk_reuseport in sctp_get_port_local
>
> include/net/sctp/sctp.h | 2 +-
> include/net/sctp/structs.h | 6 ++-
> net/core/sock_reuseport.c | 1 +
> net/sctp/bind_addr.c | 28 ++++++++++
> net/sctp/input.c | 129 ++++++++++++++++++++++++++++++++-------------
> net/sctp/socket.c | 49 +++++++++++------
> 6 files changed, 162 insertions(+), 53 deletions(-)
>
> --
> 2.1.0
>
>
Series
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
2018-10-21 4:43 ` Xin Long
@ 2018-10-22 14:15 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-10-22 14:15 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Sun, Oct 21, 2018 at 12:43:37PM +0800, Xin Long wrote:
> This is a part of sk_reuseport support for sctp. It defines a helper
> sctp_bind_addrs_check() to check if the bind_addrs in two socks are
> matched. It will add sock_reuseport if they are completely matched,
> and return err if they are partly matched, and alloc sock_reuseport
> if all socks are not matched at all.
>
> It will work until sk_reuseport support is added in
> sctp_get_port_local() in the next patch.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
> include/net/sctp/sctp.h | 2 +-
> include/net/sctp/structs.h | 2 ++
> net/core/sock_reuseport.c | 1 +
> net/sctp/bind_addr.c | 28 ++++++++++++++++++++++
> net/sctp/input.c | 60 +++++++++++++++++++++++++++++++++++++++-------
> net/sctp/socket.c | 3 +--
> 6 files changed, 85 insertions(+), 11 deletions(-)
>
> diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
> index 8c2caa3..b8cd58d 100644
> --- a/include/net/sctp/sctp.h
> +++ b/include/net/sctp/sctp.h
> @@ -152,7 +152,7 @@ int sctp_primitive_RECONF(struct net *net, struct sctp_association *asoc,
> */
> int sctp_rcv(struct sk_buff *skb);
> void sctp_v4_err(struct sk_buff *skb, u32 info);
> -void sctp_hash_endpoint(struct sctp_endpoint *);
> +int sctp_hash_endpoint(struct sctp_endpoint *ep);
> void sctp_unhash_endpoint(struct sctp_endpoint *);
> struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
> struct sctphdr *, struct sctp_association **,
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index a11f937..15d017f 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -1190,6 +1190,8 @@ int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
> struct sctp_sock *, struct sctp_sock *);
> int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
> const union sctp_addr *addr);
> +int sctp_bind_addrs_check(struct sctp_sock *sp,
> + struct sctp_sock *sp2, int cnt2);
> union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
> const union sctp_addr *addrs,
> int addrcnt,
> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> index ba5cba5..d8fe3e5 100644
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -187,6 +187,7 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
> call_rcu(&old_reuse->rcu, reuseport_free_rcu);
> return 0;
> }
> +EXPORT_SYMBOL(reuseport_add_sock);
>
> void reuseport_detach_sock(struct sock *sk)
> {
> diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
> index 7df3704..78d0d93 100644
> --- a/net/sctp/bind_addr.c
> +++ b/net/sctp/bind_addr.c
> @@ -337,6 +337,34 @@ int sctp_bind_addr_match(struct sctp_bind_addr *bp,
> return match;
> }
>
> +int sctp_bind_addrs_check(struct sctp_sock *sp,
> + struct sctp_sock *sp2, int cnt2)
> +{
> + struct sctp_bind_addr *bp2 = &sp2->ep->base.bind_addr;
> + struct sctp_bind_addr *bp = &sp->ep->base.bind_addr;
> + struct sctp_sockaddr_entry *laddr, *laddr2;
> + bool exist = false;
> + int cnt = 0;
> +
> + rcu_read_lock();
> + list_for_each_entry_rcu(laddr, &bp->address_list, list) {
> + list_for_each_entry_rcu(laddr2, &bp2->address_list, list) {
> + if (sp->pf->af->cmp_addr(&laddr->a, &laddr2->a) &&
> + laddr->valid == laddr2->valid) {
I think by here in the normal run laddr2->valid will always be true,
but as is it gives the impression that it accepts 0 == 0 too, which
would be bad. May be on a fast BINDX_REM/BINDX_ADD it could trigger
laddr2->valid = 0 in there, not sure.
Anyway, may be '... laddr->valid && laddr2->valid' instead or you
really want to allow the 0 == 0 case?
> + exist = true;
> + goto next;
> + }
> + }
> + cnt = 0;
> + break;
> +next:
> + cnt++;
> + }
> + rcu_read_unlock();
> +
> + return (cnt == cnt2) ? 0 : (exist ? -EEXIST : 1);
> +}
> +
> /* Does the address 'addr' conflict with any addresses in
> * the bp.
> */
> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 60ede89..6bfeb10 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -723,43 +723,87 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
> }
>
> /* Insert endpoint into the hash table. */
> -static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
> +static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
> {
> - struct net *net = sock_net(ep->base.sk);
> - struct sctp_ep_common *epb;
> + struct sock *sk = ep->base.sk;
> + struct net *net = sock_net(sk);
> struct sctp_hashbucket *head;
> + struct sctp_ep_common *epb;
>
> epb = &ep->base;
> -
> epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> head = &sctp_ep_hashtable[epb->hashent];
>
> + if (sk->sk_reuseport) {
> + bool any = sctp_is_ep_boundall(sk);
> + struct sctp_ep_common *epb2;
> + struct list_head *list;
> + int cnt = 0, err = 1;
> +
> + list_for_each(list, &ep->base.bind_addr.address_list)
> + cnt++;
> +
> + sctp_for_each_hentry(epb2, &head->chain) {
> + struct sock *sk2 = epb2->sk;
> +
> + if (!net_eq(sock_net(sk2), net) || sk2 == sk ||
> + !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
> + !sk2->sk_reuseport)
> + continue;
> +
> + err = sctp_bind_addrs_check(sctp_sk(sk2),
> + sctp_sk(sk), cnt);
> + if (!err) {
> + err = reuseport_add_sock(sk, sk2, any);
> + if (err)
> + return err;
> + break;
> + } else if (err < 0) {
> + return err;
> + }
> + }
> +
> + if (err) {
> + err = reuseport_alloc(sk, any);
> + if (err)
> + return err;
> + }
> + }
> +
> write_lock(&head->lock);
> hlist_add_head(&epb->node, &head->chain);
> write_unlock(&head->lock);
> + return 0;
> }
>
> /* Add an endpoint to the hash. Local BH-safe. */
> -void sctp_hash_endpoint(struct sctp_endpoint *ep)
> +int sctp_hash_endpoint(struct sctp_endpoint *ep)
> {
> + int err;
> +
> local_bh_disable();
> - __sctp_hash_endpoint(ep);
> + err = __sctp_hash_endpoint(ep);
> local_bh_enable();
> +
> + return err;
> }
>
> /* Remove endpoint from the hash table. */
> static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
> {
> - struct net *net = sock_net(ep->base.sk);
> + struct sock *sk = ep->base.sk;
> struct sctp_hashbucket *head;
> struct sctp_ep_common *epb;
>
> epb = &ep->base;
>
> - epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> + epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
>
> head = &sctp_ep_hashtable[epb->hashent];
>
> + if (rcu_access_pointer(sk->sk_reuseport_cb))
> + reuseport_detach_sock(sk);
> +
> write_lock(&head->lock);
> hlist_del_init(&epb->node);
> write_unlock(&head->lock);
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index fc0386e..44e7d8c 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -7850,8 +7850,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
> }
>
> sk->sk_max_ack_backlog = backlog;
> - sctp_hash_endpoint(ep);
> - return 0;
> + return sctp_hash_endpoint(ep);
> }
>
> /*
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
@ 2018-10-22 14:15 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-10-22 14:15 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Sun, Oct 21, 2018 at 12:43:37PM +0800, Xin Long wrote:
> This is a part of sk_reuseport support for sctp. It defines a helper
> sctp_bind_addrs_check() to check if the bind_addrs in two socks are
> matched. It will add sock_reuseport if they are completely matched,
> and return err if they are partly matched, and alloc sock_reuseport
> if all socks are not matched at all.
>
> It will work until sk_reuseport support is added in
> sctp_get_port_local() in the next patch.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
> include/net/sctp/sctp.h | 2 +-
> include/net/sctp/structs.h | 2 ++
> net/core/sock_reuseport.c | 1 +
> net/sctp/bind_addr.c | 28 ++++++++++++++++++++++
> net/sctp/input.c | 60 +++++++++++++++++++++++++++++++++++++++-------
> net/sctp/socket.c | 3 +--
> 6 files changed, 85 insertions(+), 11 deletions(-)
>
> diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
> index 8c2caa3..b8cd58d 100644
> --- a/include/net/sctp/sctp.h
> +++ b/include/net/sctp/sctp.h
> @@ -152,7 +152,7 @@ int sctp_primitive_RECONF(struct net *net, struct sctp_association *asoc,
> */
> int sctp_rcv(struct sk_buff *skb);
> void sctp_v4_err(struct sk_buff *skb, u32 info);
> -void sctp_hash_endpoint(struct sctp_endpoint *);
> +int sctp_hash_endpoint(struct sctp_endpoint *ep);
> void sctp_unhash_endpoint(struct sctp_endpoint *);
> struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
> struct sctphdr *, struct sctp_association **,
> diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> index a11f937..15d017f 100644
> --- a/include/net/sctp/structs.h
> +++ b/include/net/sctp/structs.h
> @@ -1190,6 +1190,8 @@ int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
> struct sctp_sock *, struct sctp_sock *);
> int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
> const union sctp_addr *addr);
> +int sctp_bind_addrs_check(struct sctp_sock *sp,
> + struct sctp_sock *sp2, int cnt2);
> union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
> const union sctp_addr *addrs,
> int addrcnt,
> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> index ba5cba5..d8fe3e5 100644
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -187,6 +187,7 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
> call_rcu(&old_reuse->rcu, reuseport_free_rcu);
> return 0;
> }
> +EXPORT_SYMBOL(reuseport_add_sock);
>
> void reuseport_detach_sock(struct sock *sk)
> {
> diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
> index 7df3704..78d0d93 100644
> --- a/net/sctp/bind_addr.c
> +++ b/net/sctp/bind_addr.c
> @@ -337,6 +337,34 @@ int sctp_bind_addr_match(struct sctp_bind_addr *bp,
> return match;
> }
>
> +int sctp_bind_addrs_check(struct sctp_sock *sp,
> + struct sctp_sock *sp2, int cnt2)
> +{
> + struct sctp_bind_addr *bp2 = &sp2->ep->base.bind_addr;
> + struct sctp_bind_addr *bp = &sp->ep->base.bind_addr;
> + struct sctp_sockaddr_entry *laddr, *laddr2;
> + bool exist = false;
> + int cnt = 0;
> +
> + rcu_read_lock();
> + list_for_each_entry_rcu(laddr, &bp->address_list, list) {
> + list_for_each_entry_rcu(laddr2, &bp2->address_list, list) {
> + if (sp->pf->af->cmp_addr(&laddr->a, &laddr2->a) &&
> + laddr->valid = laddr2->valid) {
I think by here in the normal run laddr2->valid will always be true,
but as is it gives the impression that it accepts 0 = 0 too, which
would be bad. May be on a fast BINDX_REM/BINDX_ADD it could trigger
laddr2->valid = 0 in there, not sure.
Anyway, may be '... laddr->valid && laddr2->valid' instead or you
really want to allow the 0 = 0 case?
> + exist = true;
> + goto next;
> + }
> + }
> + cnt = 0;
> + break;
> +next:
> + cnt++;
> + }
> + rcu_read_unlock();
> +
> + return (cnt = cnt2) ? 0 : (exist ? -EEXIST : 1);
> +}
> +
> /* Does the address 'addr' conflict with any addresses in
> * the bp.
> */
> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 60ede89..6bfeb10 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -723,43 +723,87 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
> }
>
> /* Insert endpoint into the hash table. */
> -static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
> +static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
> {
> - struct net *net = sock_net(ep->base.sk);
> - struct sctp_ep_common *epb;
> + struct sock *sk = ep->base.sk;
> + struct net *net = sock_net(sk);
> struct sctp_hashbucket *head;
> + struct sctp_ep_common *epb;
>
> epb = &ep->base;
> -
> epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> head = &sctp_ep_hashtable[epb->hashent];
>
> + if (sk->sk_reuseport) {
> + bool any = sctp_is_ep_boundall(sk);
> + struct sctp_ep_common *epb2;
> + struct list_head *list;
> + int cnt = 0, err = 1;
> +
> + list_for_each(list, &ep->base.bind_addr.address_list)
> + cnt++;
> +
> + sctp_for_each_hentry(epb2, &head->chain) {
> + struct sock *sk2 = epb2->sk;
> +
> + if (!net_eq(sock_net(sk2), net) || sk2 = sk ||
> + !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
> + !sk2->sk_reuseport)
> + continue;
> +
> + err = sctp_bind_addrs_check(sctp_sk(sk2),
> + sctp_sk(sk), cnt);
> + if (!err) {
> + err = reuseport_add_sock(sk, sk2, any);
> + if (err)
> + return err;
> + break;
> + } else if (err < 0) {
> + return err;
> + }
> + }
> +
> + if (err) {
> + err = reuseport_alloc(sk, any);
> + if (err)
> + return err;
> + }
> + }
> +
> write_lock(&head->lock);
> hlist_add_head(&epb->node, &head->chain);
> write_unlock(&head->lock);
> + return 0;
> }
>
> /* Add an endpoint to the hash. Local BH-safe. */
> -void sctp_hash_endpoint(struct sctp_endpoint *ep)
> +int sctp_hash_endpoint(struct sctp_endpoint *ep)
> {
> + int err;
> +
> local_bh_disable();
> - __sctp_hash_endpoint(ep);
> + err = __sctp_hash_endpoint(ep);
> local_bh_enable();
> +
> + return err;
> }
>
> /* Remove endpoint from the hash table. */
> static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
> {
> - struct net *net = sock_net(ep->base.sk);
> + struct sock *sk = ep->base.sk;
> struct sctp_hashbucket *head;
> struct sctp_ep_common *epb;
>
> epb = &ep->base;
>
> - epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> + epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
>
> head = &sctp_ep_hashtable[epb->hashent];
>
> + if (rcu_access_pointer(sk->sk_reuseport_cb))
> + reuseport_detach_sock(sk);
> +
> write_lock(&head->lock);
> hlist_del_init(&epb->node);
> write_unlock(&head->lock);
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index fc0386e..44e7d8c 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -7850,8 +7850,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
> }
>
> sk->sk_max_ack_backlog = backlog;
> - sctp_hash_endpoint(ep);
> - return 0;
> + return sctp_hash_endpoint(ep);
> }
>
> /*
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
2018-10-21 4:43 ` Xin Long
@ 2018-10-22 14:17 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-10-22 14:17 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Sun, Oct 21, 2018 at 12:43:36PM +0800, Xin Long wrote:
> This is a part of sk_reuseport support for sctp, and it selects a
> sock by the hashkey of lport, paddr and dport by default. It will
> work until sk_reuseport support is added in sctp_get_port_local()
> in the next patch.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
> net/sctp/input.c | 69 +++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 41 insertions(+), 28 deletions(-)
>
> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 5c36a99..60ede89 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -57,6 +57,7 @@
> #include <net/sctp/checksum.h>
> #include <net/net_namespace.h>
> #include <linux/rhashtable.h>
> +#include <net/sock_reuseport.h>
>
> /* Forward declarations for internal helpers. */
> static int sctp_rcv_ootb(struct sk_buff *);
> @@ -65,8 +66,10 @@ static struct sctp_association *__sctp_rcv_lookup(struct net *net,
> const union sctp_addr *paddr,
> const union sctp_addr *laddr,
> struct sctp_transport **transportp);
> -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> - const union sctp_addr *laddr);
> +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> + struct net *net, struct sk_buff *skb,
> + const union sctp_addr *laddr,
> + const union sctp_addr *daddr);
> static struct sctp_association *__sctp_lookup_association(
> struct net *net,
> const union sctp_addr *local,
> @@ -171,7 +174,7 @@ int sctp_rcv(struct sk_buff *skb)
> asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
>
> if (!asoc)
> - ep = __sctp_rcv_lookup_endpoint(net, &dest);
> + ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
>
> /* Retrieve the common input handling substructure. */
> rcvr = asoc ? &asoc->base : &ep->base;
> @@ -770,16 +773,35 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
> local_bh_enable();
> }
>
> +static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
> + const union sctp_addr *paddr, __u32 seed)
> +{
> + __u32 addr;
> +
> + if (paddr->sa.sa_family == AF_INET6)
> + addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> + else
> + addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> +
> + return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> + (__force __u32)lport, net_hash_mix(net), seed);
> +}
> +
> /* Look up an endpoint. */
> -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> - const union sctp_addr *laddr)
> +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> + struct net *net, struct sk_buff *skb,
> + const union sctp_addr *laddr,
> + const union sctp_addr *paddr)
> {
> struct sctp_hashbucket *head;
> struct sctp_ep_common *epb;
> struct sctp_endpoint *ep;
> + struct sock *sk;
> + __be32 lport;
This could be a __be16 one.
> int hash;
>
> - hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
> + lport = laddr->v4.sin_port;
> + hash = sctp_ep_hashfn(net, ntohs(lport));
> head = &sctp_ep_hashtable[hash];
> read_lock(&head->lock);
> sctp_for_each_hentry(epb, &head->chain) {
> @@ -791,6 +813,15 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> ep = sctp_sk(net->sctp.ctl_sock)->ep;
>
> hit:
> + sk = ep->base.sk;
> + if (sk->sk_reuseport) {
> + __u32 phash = sctp_hashfn(net, lport, paddr, 0);
> +
> + sk = reuseport_select_sock(sk, phash, skb,
> + sizeof(struct sctphdr));
> + if (sk)
> + ep = sctp_sk(sk)->ep;
> + }
> sctp_endpoint_hold(ep);
> read_unlock(&head->lock);
> return ep;
> @@ -829,35 +860,17 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
> static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
> {
> const struct sctp_transport *t = data;
> - const union sctp_addr *paddr = &t->ipaddr;
> - const struct net *net = sock_net(t->asoc->base.sk);
> - __be16 lport = htons(t->asoc->base.bind_addr.port);
> - __u32 addr;
> -
> - if (paddr->sa.sa_family == AF_INET6)
> - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> - else
> - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
>
> - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> - (__force __u32)lport, net_hash_mix(net), seed);
> + return sctp_hashfn(sock_net(t->asoc->base.sk),
> + htons(t->asoc->base.bind_addr.port),
> + &t->ipaddr, seed);
> }
>
> static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
> {
> const struct sctp_hash_cmp_arg *x = data;
> - const union sctp_addr *paddr = x->paddr;
> - const struct net *net = x->net;
> - __be16 lport = x->lport;
> - __u32 addr;
> -
> - if (paddr->sa.sa_family == AF_INET6)
> - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> - else
> - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
>
> - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> - (__force __u32)lport, net_hash_mix(net), seed);
> + return sctp_hashfn(x->net, x->lport, x->paddr, seed);
> }
>
> static const struct rhashtable_params sctp_hash_params = {
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
@ 2018-10-22 14:17 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-10-22 14:17 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Sun, Oct 21, 2018 at 12:43:36PM +0800, Xin Long wrote:
> This is a part of sk_reuseport support for sctp, and it selects a
> sock by the hashkey of lport, paddr and dport by default. It will
> work until sk_reuseport support is added in sctp_get_port_local()
> in the next patch.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
> net/sctp/input.c | 69 +++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 41 insertions(+), 28 deletions(-)
>
> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 5c36a99..60ede89 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -57,6 +57,7 @@
> #include <net/sctp/checksum.h>
> #include <net/net_namespace.h>
> #include <linux/rhashtable.h>
> +#include <net/sock_reuseport.h>
>
> /* Forward declarations for internal helpers. */
> static int sctp_rcv_ootb(struct sk_buff *);
> @@ -65,8 +66,10 @@ static struct sctp_association *__sctp_rcv_lookup(struct net *net,
> const union sctp_addr *paddr,
> const union sctp_addr *laddr,
> struct sctp_transport **transportp);
> -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> - const union sctp_addr *laddr);
> +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> + struct net *net, struct sk_buff *skb,
> + const union sctp_addr *laddr,
> + const union sctp_addr *daddr);
> static struct sctp_association *__sctp_lookup_association(
> struct net *net,
> const union sctp_addr *local,
> @@ -171,7 +174,7 @@ int sctp_rcv(struct sk_buff *skb)
> asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
>
> if (!asoc)
> - ep = __sctp_rcv_lookup_endpoint(net, &dest);
> + ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
>
> /* Retrieve the common input handling substructure. */
> rcvr = asoc ? &asoc->base : &ep->base;
> @@ -770,16 +773,35 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
> local_bh_enable();
> }
>
> +static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
> + const union sctp_addr *paddr, __u32 seed)
> +{
> + __u32 addr;
> +
> + if (paddr->sa.sa_family = AF_INET6)
> + addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> + else
> + addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> +
> + return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> + (__force __u32)lport, net_hash_mix(net), seed);
> +}
> +
> /* Look up an endpoint. */
> -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> - const union sctp_addr *laddr)
> +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> + struct net *net, struct sk_buff *skb,
> + const union sctp_addr *laddr,
> + const union sctp_addr *paddr)
> {
> struct sctp_hashbucket *head;
> struct sctp_ep_common *epb;
> struct sctp_endpoint *ep;
> + struct sock *sk;
> + __be32 lport;
This could be a __be16 one.
> int hash;
>
> - hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
> + lport = laddr->v4.sin_port;
> + hash = sctp_ep_hashfn(net, ntohs(lport));
> head = &sctp_ep_hashtable[hash];
> read_lock(&head->lock);
> sctp_for_each_hentry(epb, &head->chain) {
> @@ -791,6 +813,15 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> ep = sctp_sk(net->sctp.ctl_sock)->ep;
>
> hit:
> + sk = ep->base.sk;
> + if (sk->sk_reuseport) {
> + __u32 phash = sctp_hashfn(net, lport, paddr, 0);
> +
> + sk = reuseport_select_sock(sk, phash, skb,
> + sizeof(struct sctphdr));
> + if (sk)
> + ep = sctp_sk(sk)->ep;
> + }
> sctp_endpoint_hold(ep);
> read_unlock(&head->lock);
> return ep;
> @@ -829,35 +860,17 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
> static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
> {
> const struct sctp_transport *t = data;
> - const union sctp_addr *paddr = &t->ipaddr;
> - const struct net *net = sock_net(t->asoc->base.sk);
> - __be16 lport = htons(t->asoc->base.bind_addr.port);
> - __u32 addr;
> -
> - if (paddr->sa.sa_family = AF_INET6)
> - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> - else
> - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
>
> - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> - (__force __u32)lport, net_hash_mix(net), seed);
> + return sctp_hashfn(sock_net(t->asoc->base.sk),
> + htons(t->asoc->base.bind_addr.port),
> + &t->ipaddr, seed);
> }
>
> static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
> {
> const struct sctp_hash_cmp_arg *x = data;
> - const union sctp_addr *paddr = x->paddr;
> - const struct net *net = x->net;
> - __be16 lport = x->lport;
> - __u32 addr;
> -
> - if (paddr->sa.sa_family = AF_INET6)
> - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> - else
> - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
>
> - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> - (__force __u32)lport, net_hash_mix(net), seed);
> + return sctp_hashfn(x->net, x->lport, x->paddr, seed);
> }
>
> static const struct rhashtable_params sctp_hash_params = {
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for sk_reuseport
2018-10-21 4:43 ` Xin Long
@ 2018-10-22 14:20 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-10-22 14:20 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Sun, Oct 21, 2018 at 12:43:35PM +0800, Xin Long wrote:
> sctp sk_reuseport allows multiple socks to listen on the same port and
> addresses, as long as these socks have the same uid. This works pretty
> much as TCP/UDP does, the only difference is that sctp is multi-homing
> and all the bind_addrs in these socks will have to completely matched,
> otherwise listen() will return err.
>
FWIW, I won't be able to review this patchset thoroughly. The 2 small
comments that I sent are all I have.
Thanks,
Marcelo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 0/3] sctp: add support for sk_reuseport
@ 2018-10-22 14:20 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 46+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-10-22 14:20 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, Neil Horman, davem
On Sun, Oct 21, 2018 at 12:43:35PM +0800, Xin Long wrote:
> sctp sk_reuseport allows multiple socks to listen on the same port and
> addresses, as long as these socks have the same uid. This works pretty
> much as TCP/UDP does, the only difference is that sctp is multi-homing
> and all the bind_addrs in these socks will have to completely matched,
> otherwise listen() will return err.
>
FWIW, I won't be able to review this patchset thoroughly. The 2 small
comments that I sent are all I have.
Thanks,
Marcelo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
2018-10-22 14:17 ` Marcelo Ricardo Leitner
@ 2018-11-12 9:56 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-11-12 9:56 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Oct 22, 2018 at 11:18 PM Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
>
> On Sun, Oct 21, 2018 at 12:43:36PM +0800, Xin Long wrote:
> > This is a part of sk_reuseport support for sctp, and it selects a
> > sock by the hashkey of lport, paddr and dport by default. It will
> > work until sk_reuseport support is added in sctp_get_port_local()
> > in the next patch.
> >
> > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > ---
> > net/sctp/input.c | 69 +++++++++++++++++++++++++++++++++-----------------------
> > 1 file changed, 41 insertions(+), 28 deletions(-)
> >
> > diff --git a/net/sctp/input.c b/net/sctp/input.c
> > index 5c36a99..60ede89 100644
> > --- a/net/sctp/input.c
> > +++ b/net/sctp/input.c
> > @@ -57,6 +57,7 @@
> > #include <net/sctp/checksum.h>
> > #include <net/net_namespace.h>
> > #include <linux/rhashtable.h>
> > +#include <net/sock_reuseport.h>
> >
> > /* Forward declarations for internal helpers. */
> > static int sctp_rcv_ootb(struct sk_buff *);
> > @@ -65,8 +66,10 @@ static struct sctp_association *__sctp_rcv_lookup(struct net *net,
> > const union sctp_addr *paddr,
> > const union sctp_addr *laddr,
> > struct sctp_transport **transportp);
> > -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> > - const union sctp_addr *laddr);
> > +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> > + struct net *net, struct sk_buff *skb,
> > + const union sctp_addr *laddr,
> > + const union sctp_addr *daddr);
> > static struct sctp_association *__sctp_lookup_association(
> > struct net *net,
> > const union sctp_addr *local,
> > @@ -171,7 +174,7 @@ int sctp_rcv(struct sk_buff *skb)
> > asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
> >
> > if (!asoc)
> > - ep = __sctp_rcv_lookup_endpoint(net, &dest);
> > + ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
> >
> > /* Retrieve the common input handling substructure. */
> > rcvr = asoc ? &asoc->base : &ep->base;
> > @@ -770,16 +773,35 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
> > local_bh_enable();
> > }
> >
> > +static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
> > + const union sctp_addr *paddr, __u32 seed)
> > +{
> > + __u32 addr;
> > +
> > + if (paddr->sa.sa_family == AF_INET6)
> > + addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > + else
> > + addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> > +
> > + return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> > + (__force __u32)lport, net_hash_mix(net), seed);
> > +}
> > +
> > /* Look up an endpoint. */
> > -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> > - const union sctp_addr *laddr)
> > +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> > + struct net *net, struct sk_buff *skb,
> > + const union sctp_addr *laddr,
> > + const union sctp_addr *paddr)
> > {
> > struct sctp_hashbucket *head;
> > struct sctp_ep_common *epb;
> > struct sctp_endpoint *ep;
> > + struct sock *sk;
> > + __be32 lport;
>
> This could be a __be16 one.
right, will correct it in v2.
>
> > int hash;
> >
> > - hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
> > + lport = laddr->v4.sin_port;
> > + hash = sctp_ep_hashfn(net, ntohs(lport));
> > head = &sctp_ep_hashtable[hash];
> > read_lock(&head->lock);
> > sctp_for_each_hentry(epb, &head->chain) {
> > @@ -791,6 +813,15 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> > ep = sctp_sk(net->sctp.ctl_sock)->ep;
> >
> > hit:
> > + sk = ep->base.sk;
> > + if (sk->sk_reuseport) {
> > + __u32 phash = sctp_hashfn(net, lport, paddr, 0);
> > +
> > + sk = reuseport_select_sock(sk, phash, skb,
> > + sizeof(struct sctphdr));
> > + if (sk)
> > + ep = sctp_sk(sk)->ep;
> > + }
> > sctp_endpoint_hold(ep);
> > read_unlock(&head->lock);
> > return ep;
> > @@ -829,35 +860,17 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
> > static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
> > {
> > const struct sctp_transport *t = data;
> > - const union sctp_addr *paddr = &t->ipaddr;
> > - const struct net *net = sock_net(t->asoc->base.sk);
> > - __be16 lport = htons(t->asoc->base.bind_addr.port);
> > - __u32 addr;
> > -
> > - if (paddr->sa.sa_family == AF_INET6)
> > - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > - else
> > - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> >
> > - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> > - (__force __u32)lport, net_hash_mix(net), seed);
> > + return sctp_hashfn(sock_net(t->asoc->base.sk),
> > + htons(t->asoc->base.bind_addr.port),
> > + &t->ipaddr, seed);
> > }
> >
> > static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
> > {
> > const struct sctp_hash_cmp_arg *x = data;
> > - const union sctp_addr *paddr = x->paddr;
> > - const struct net *net = x->net;
> > - __be16 lport = x->lport;
> > - __u32 addr;
> > -
> > - if (paddr->sa.sa_family == AF_INET6)
> > - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > - else
> > - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> >
> > - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> > - (__force __u32)lport, net_hash_mix(net), seed);
> > + return sctp_hashfn(x->net, x->lport, x->paddr, seed);
> > }
> >
> > static const struct rhashtable_params sctp_hash_params = {
> > --
> > 2.1.0
> >
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint
@ 2018-11-12 9:56 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-11-12 9:56 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Oct 22, 2018 at 11:18 PM Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
>
> On Sun, Oct 21, 2018 at 12:43:36PM +0800, Xin Long wrote:
> > This is a part of sk_reuseport support for sctp, and it selects a
> > sock by the hashkey of lport, paddr and dport by default. It will
> > work until sk_reuseport support is added in sctp_get_port_local()
> > in the next patch.
> >
> > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > ---
> > net/sctp/input.c | 69 +++++++++++++++++++++++++++++++++-----------------------
> > 1 file changed, 41 insertions(+), 28 deletions(-)
> >
> > diff --git a/net/sctp/input.c b/net/sctp/input.c
> > index 5c36a99..60ede89 100644
> > --- a/net/sctp/input.c
> > +++ b/net/sctp/input.c
> > @@ -57,6 +57,7 @@
> > #include <net/sctp/checksum.h>
> > #include <net/net_namespace.h>
> > #include <linux/rhashtable.h>
> > +#include <net/sock_reuseport.h>
> >
> > /* Forward declarations for internal helpers. */
> > static int sctp_rcv_ootb(struct sk_buff *);
> > @@ -65,8 +66,10 @@ static struct sctp_association *__sctp_rcv_lookup(struct net *net,
> > const union sctp_addr *paddr,
> > const union sctp_addr *laddr,
> > struct sctp_transport **transportp);
> > -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> > - const union sctp_addr *laddr);
> > +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> > + struct net *net, struct sk_buff *skb,
> > + const union sctp_addr *laddr,
> > + const union sctp_addr *daddr);
> > static struct sctp_association *__sctp_lookup_association(
> > struct net *net,
> > const union sctp_addr *local,
> > @@ -171,7 +174,7 @@ int sctp_rcv(struct sk_buff *skb)
> > asoc = __sctp_rcv_lookup(net, skb, &src, &dest, &transport);
> >
> > if (!asoc)
> > - ep = __sctp_rcv_lookup_endpoint(net, &dest);
> > + ep = __sctp_rcv_lookup_endpoint(net, skb, &dest, &src);
> >
> > /* Retrieve the common input handling substructure. */
> > rcvr = asoc ? &asoc->base : &ep->base;
> > @@ -770,16 +773,35 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
> > local_bh_enable();
> > }
> >
> > +static inline __u32 sctp_hashfn(const struct net *net, __be16 lport,
> > + const union sctp_addr *paddr, __u32 seed)
> > +{
> > + __u32 addr;
> > +
> > + if (paddr->sa.sa_family = AF_INET6)
> > + addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > + else
> > + addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> > +
> > + return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> > + (__force __u32)lport, net_hash_mix(net), seed);
> > +}
> > +
> > /* Look up an endpoint. */
> > -static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> > - const union sctp_addr *laddr)
> > +static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(
> > + struct net *net, struct sk_buff *skb,
> > + const union sctp_addr *laddr,
> > + const union sctp_addr *paddr)
> > {
> > struct sctp_hashbucket *head;
> > struct sctp_ep_common *epb;
> > struct sctp_endpoint *ep;
> > + struct sock *sk;
> > + __be32 lport;
>
> This could be a __be16 one.
right, will correct it in v2.
>
> > int hash;
> >
> > - hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
> > + lport = laddr->v4.sin_port;
> > + hash = sctp_ep_hashfn(net, ntohs(lport));
> > head = &sctp_ep_hashtable[hash];
> > read_lock(&head->lock);
> > sctp_for_each_hentry(epb, &head->chain) {
> > @@ -791,6 +813,15 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
> > ep = sctp_sk(net->sctp.ctl_sock)->ep;
> >
> > hit:
> > + sk = ep->base.sk;
> > + if (sk->sk_reuseport) {
> > + __u32 phash = sctp_hashfn(net, lport, paddr, 0);
> > +
> > + sk = reuseport_select_sock(sk, phash, skb,
> > + sizeof(struct sctphdr));
> > + if (sk)
> > + ep = sctp_sk(sk)->ep;
> > + }
> > sctp_endpoint_hold(ep);
> > read_unlock(&head->lock);
> > return ep;
> > @@ -829,35 +860,17 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
> > static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
> > {
> > const struct sctp_transport *t = data;
> > - const union sctp_addr *paddr = &t->ipaddr;
> > - const struct net *net = sock_net(t->asoc->base.sk);
> > - __be16 lport = htons(t->asoc->base.bind_addr.port);
> > - __u32 addr;
> > -
> > - if (paddr->sa.sa_family = AF_INET6)
> > - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > - else
> > - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> >
> > - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> > - (__force __u32)lport, net_hash_mix(net), seed);
> > + return sctp_hashfn(sock_net(t->asoc->base.sk),
> > + htons(t->asoc->base.bind_addr.port),
> > + &t->ipaddr, seed);
> > }
> >
> > static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
> > {
> > const struct sctp_hash_cmp_arg *x = data;
> > - const union sctp_addr *paddr = x->paddr;
> > - const struct net *net = x->net;
> > - __be16 lport = x->lport;
> > - __u32 addr;
> > -
> > - if (paddr->sa.sa_family = AF_INET6)
> > - addr = jhash(&paddr->v6.sin6_addr, 16, seed);
> > - else
> > - addr = (__force __u32)paddr->v4.sin_addr.s_addr;
> >
> > - return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
> > - (__force __u32)lport, net_hash_mix(net), seed);
> > + return sctp_hashfn(x->net, x->lport, x->paddr, seed);
> > }
> >
> > static const struct rhashtable_params sctp_hash_params = {
> > --
> > 2.1.0
> >
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
2018-10-22 14:15 ` Marcelo Ricardo Leitner
@ 2018-11-12 9:58 ` Xin Long
-1 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-11-12 9:58 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Oct 22, 2018 at 11:15 PM Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
>
> On Sun, Oct 21, 2018 at 12:43:37PM +0800, Xin Long wrote:
> > This is a part of sk_reuseport support for sctp. It defines a helper
> > sctp_bind_addrs_check() to check if the bind_addrs in two socks are
> > matched. It will add sock_reuseport if they are completely matched,
> > and return err if they are partly matched, and alloc sock_reuseport
> > if all socks are not matched at all.
> >
> > It will work until sk_reuseport support is added in
> > sctp_get_port_local() in the next patch.
> >
> > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > ---
> > include/net/sctp/sctp.h | 2 +-
> > include/net/sctp/structs.h | 2 ++
> > net/core/sock_reuseport.c | 1 +
> > net/sctp/bind_addr.c | 28 ++++++++++++++++++++++
> > net/sctp/input.c | 60 +++++++++++++++++++++++++++++++++++++++-------
> > net/sctp/socket.c | 3 +--
> > 6 files changed, 85 insertions(+), 11 deletions(-)
> >
> > diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
> > index 8c2caa3..b8cd58d 100644
> > --- a/include/net/sctp/sctp.h
> > +++ b/include/net/sctp/sctp.h
> > @@ -152,7 +152,7 @@ int sctp_primitive_RECONF(struct net *net, struct sctp_association *asoc,
> > */
> > int sctp_rcv(struct sk_buff *skb);
> > void sctp_v4_err(struct sk_buff *skb, u32 info);
> > -void sctp_hash_endpoint(struct sctp_endpoint *);
> > +int sctp_hash_endpoint(struct sctp_endpoint *ep);
> > void sctp_unhash_endpoint(struct sctp_endpoint *);
> > struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
> > struct sctphdr *, struct sctp_association **,
> > diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> > index a11f937..15d017f 100644
> > --- a/include/net/sctp/structs.h
> > +++ b/include/net/sctp/structs.h
> > @@ -1190,6 +1190,8 @@ int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
> > struct sctp_sock *, struct sctp_sock *);
> > int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
> > const union sctp_addr *addr);
> > +int sctp_bind_addrs_check(struct sctp_sock *sp,
> > + struct sctp_sock *sp2, int cnt2);
> > union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
> > const union sctp_addr *addrs,
> > int addrcnt,
> > diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> > index ba5cba5..d8fe3e5 100644
> > --- a/net/core/sock_reuseport.c
> > +++ b/net/core/sock_reuseport.c
> > @@ -187,6 +187,7 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
> > call_rcu(&old_reuse->rcu, reuseport_free_rcu);
> > return 0;
> > }
> > +EXPORT_SYMBOL(reuseport_add_sock);
> >
> > void reuseport_detach_sock(struct sock *sk)
> > {
> > diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
> > index 7df3704..78d0d93 100644
> > --- a/net/sctp/bind_addr.c
> > +++ b/net/sctp/bind_addr.c
> > @@ -337,6 +337,34 @@ int sctp_bind_addr_match(struct sctp_bind_addr *bp,
> > return match;
> > }
> >
> > +int sctp_bind_addrs_check(struct sctp_sock *sp,
> > + struct sctp_sock *sp2, int cnt2)
> > +{
> > + struct sctp_bind_addr *bp2 = &sp2->ep->base.bind_addr;
> > + struct sctp_bind_addr *bp = &sp->ep->base.bind_addr;
> > + struct sctp_sockaddr_entry *laddr, *laddr2;
> > + bool exist = false;
> > + int cnt = 0;
> > +
> > + rcu_read_lock();
> > + list_for_each_entry_rcu(laddr, &bp->address_list, list) {
> > + list_for_each_entry_rcu(laddr2, &bp2->address_list, list) {
> > + if (sp->pf->af->cmp_addr(&laddr->a, &laddr2->a) &&
> > + laddr->valid == laddr2->valid) {
>
> I think by here in the normal run laddr2->valid will always be true,
> but as is it gives the impression that it accepts 0 == 0 too, which
> would be bad. May be on a fast BINDX_REM/BINDX_ADD it could trigger
> laddr2->valid = 0 in there, not sure.
>
> Anyway, may be '... laddr->valid && laddr2->valid' instead or you
> really want to allow the 0 == 0 case?
>
will improve it in v2. thanks.
> > + exist = true;
> > + goto next;
> > + }
> > + }
> > + cnt = 0;
> > + break;
> > +next:
> > + cnt++;
> > + }
> > + rcu_read_unlock();
> > +
> > + return (cnt == cnt2) ? 0 : (exist ? -EEXIST : 1);
> > +}
> > +
> > /* Does the address 'addr' conflict with any addresses in
> > * the bp.
> > */
> > diff --git a/net/sctp/input.c b/net/sctp/input.c
> > index 60ede89..6bfeb10 100644
> > --- a/net/sctp/input.c
> > +++ b/net/sctp/input.c
> > @@ -723,43 +723,87 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
> > }
> >
> > /* Insert endpoint into the hash table. */
> > -static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
> > +static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
> > {
> > - struct net *net = sock_net(ep->base.sk);
> > - struct sctp_ep_common *epb;
> > + struct sock *sk = ep->base.sk;
> > + struct net *net = sock_net(sk);
> > struct sctp_hashbucket *head;
> > + struct sctp_ep_common *epb;
> >
> > epb = &ep->base;
> > -
> > epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> > head = &sctp_ep_hashtable[epb->hashent];
> >
> > + if (sk->sk_reuseport) {
> > + bool any = sctp_is_ep_boundall(sk);
> > + struct sctp_ep_common *epb2;
> > + struct list_head *list;
> > + int cnt = 0, err = 1;
> > +
> > + list_for_each(list, &ep->base.bind_addr.address_list)
> > + cnt++;
> > +
> > + sctp_for_each_hentry(epb2, &head->chain) {
> > + struct sock *sk2 = epb2->sk;
> > +
> > + if (!net_eq(sock_net(sk2), net) || sk2 == sk ||
> > + !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
> > + !sk2->sk_reuseport)
> > + continue;
> > +
> > + err = sctp_bind_addrs_check(sctp_sk(sk2),
> > + sctp_sk(sk), cnt);
> > + if (!err) {
> > + err = reuseport_add_sock(sk, sk2, any);
> > + if (err)
> > + return err;
> > + break;
> > + } else if (err < 0) {
> > + return err;
> > + }
> > + }
> > +
> > + if (err) {
> > + err = reuseport_alloc(sk, any);
> > + if (err)
> > + return err;
> > + }
> > + }
> > +
> > write_lock(&head->lock);
> > hlist_add_head(&epb->node, &head->chain);
> > write_unlock(&head->lock);
> > + return 0;
> > }
> >
> > /* Add an endpoint to the hash. Local BH-safe. */
> > -void sctp_hash_endpoint(struct sctp_endpoint *ep)
> > +int sctp_hash_endpoint(struct sctp_endpoint *ep)
> > {
> > + int err;
> > +
> > local_bh_disable();
> > - __sctp_hash_endpoint(ep);
> > + err = __sctp_hash_endpoint(ep);
> > local_bh_enable();
> > +
> > + return err;
> > }
> >
> > /* Remove endpoint from the hash table. */
> > static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
> > {
> > - struct net *net = sock_net(ep->base.sk);
> > + struct sock *sk = ep->base.sk;
> > struct sctp_hashbucket *head;
> > struct sctp_ep_common *epb;
> >
> > epb = &ep->base;
> >
> > - epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> > + epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
> >
> > head = &sctp_ep_hashtable[epb->hashent];
> >
> > + if (rcu_access_pointer(sk->sk_reuseport_cb))
> > + reuseport_detach_sock(sk);
> > +
> > write_lock(&head->lock);
> > hlist_del_init(&epb->node);
> > write_unlock(&head->lock);
> > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > index fc0386e..44e7d8c 100644
> > --- a/net/sctp/socket.c
> > +++ b/net/sctp/socket.c
> > @@ -7850,8 +7850,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
> > }
> >
> > sk->sk_max_ack_backlog = backlog;
> > - sctp_hash_endpoint(ep);
> > - return 0;
> > + return sctp_hash_endpoint(ep);
> > }
> >
> > /*
> > --
> > 2.1.0
> >
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint
@ 2018-11-12 9:58 ` Xin Long
0 siblings, 0 replies; 46+ messages in thread
From: Xin Long @ 2018-11-12 9:58 UTC (permalink / raw)
To: Marcelo Ricardo Leitner; +Cc: network dev, linux-sctp, Neil Horman, davem
On Mon, Oct 22, 2018 at 11:15 PM Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
>
> On Sun, Oct 21, 2018 at 12:43:37PM +0800, Xin Long wrote:
> > This is a part of sk_reuseport support for sctp. It defines a helper
> > sctp_bind_addrs_check() to check if the bind_addrs in two socks are
> > matched. It will add sock_reuseport if they are completely matched,
> > and return err if they are partly matched, and alloc sock_reuseport
> > if all socks are not matched at all.
> >
> > It will work until sk_reuseport support is added in
> > sctp_get_port_local() in the next patch.
> >
> > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > ---
> > include/net/sctp/sctp.h | 2 +-
> > include/net/sctp/structs.h | 2 ++
> > net/core/sock_reuseport.c | 1 +
> > net/sctp/bind_addr.c | 28 ++++++++++++++++++++++
> > net/sctp/input.c | 60 +++++++++++++++++++++++++++++++++++++++-------
> > net/sctp/socket.c | 3 +--
> > 6 files changed, 85 insertions(+), 11 deletions(-)
> >
> > diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
> > index 8c2caa3..b8cd58d 100644
> > --- a/include/net/sctp/sctp.h
> > +++ b/include/net/sctp/sctp.h
> > @@ -152,7 +152,7 @@ int sctp_primitive_RECONF(struct net *net, struct sctp_association *asoc,
> > */
> > int sctp_rcv(struct sk_buff *skb);
> > void sctp_v4_err(struct sk_buff *skb, u32 info);
> > -void sctp_hash_endpoint(struct sctp_endpoint *);
> > +int sctp_hash_endpoint(struct sctp_endpoint *ep);
> > void sctp_unhash_endpoint(struct sctp_endpoint *);
> > struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
> > struct sctphdr *, struct sctp_association **,
> > diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
> > index a11f937..15d017f 100644
> > --- a/include/net/sctp/structs.h
> > +++ b/include/net/sctp/structs.h
> > @@ -1190,6 +1190,8 @@ int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
> > struct sctp_sock *, struct sctp_sock *);
> > int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
> > const union sctp_addr *addr);
> > +int sctp_bind_addrs_check(struct sctp_sock *sp,
> > + struct sctp_sock *sp2, int cnt2);
> > union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
> > const union sctp_addr *addrs,
> > int addrcnt,
> > diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> > index ba5cba5..d8fe3e5 100644
> > --- a/net/core/sock_reuseport.c
> > +++ b/net/core/sock_reuseport.c
> > @@ -187,6 +187,7 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
> > call_rcu(&old_reuse->rcu, reuseport_free_rcu);
> > return 0;
> > }
> > +EXPORT_SYMBOL(reuseport_add_sock);
> >
> > void reuseport_detach_sock(struct sock *sk)
> > {
> > diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
> > index 7df3704..78d0d93 100644
> > --- a/net/sctp/bind_addr.c
> > +++ b/net/sctp/bind_addr.c
> > @@ -337,6 +337,34 @@ int sctp_bind_addr_match(struct sctp_bind_addr *bp,
> > return match;
> > }
> >
> > +int sctp_bind_addrs_check(struct sctp_sock *sp,
> > + struct sctp_sock *sp2, int cnt2)
> > +{
> > + struct sctp_bind_addr *bp2 = &sp2->ep->base.bind_addr;
> > + struct sctp_bind_addr *bp = &sp->ep->base.bind_addr;
> > + struct sctp_sockaddr_entry *laddr, *laddr2;
> > + bool exist = false;
> > + int cnt = 0;
> > +
> > + rcu_read_lock();
> > + list_for_each_entry_rcu(laddr, &bp->address_list, list) {
> > + list_for_each_entry_rcu(laddr2, &bp2->address_list, list) {
> > + if (sp->pf->af->cmp_addr(&laddr->a, &laddr2->a) &&
> > + laddr->valid = laddr2->valid) {
>
> I think by here in the normal run laddr2->valid will always be true,
> but as is it gives the impression that it accepts 0 = 0 too, which
> would be bad. May be on a fast BINDX_REM/BINDX_ADD it could trigger
> laddr2->valid = 0 in there, not sure.
>
> Anyway, may be '... laddr->valid && laddr2->valid' instead or you
> really want to allow the 0 = 0 case?
>
will improve it in v2. thanks.
> > + exist = true;
> > + goto next;
> > + }
> > + }
> > + cnt = 0;
> > + break;
> > +next:
> > + cnt++;
> > + }
> > + rcu_read_unlock();
> > +
> > + return (cnt = cnt2) ? 0 : (exist ? -EEXIST : 1);
> > +}
> > +
> > /* Does the address 'addr' conflict with any addresses in
> > * the bp.
> > */
> > diff --git a/net/sctp/input.c b/net/sctp/input.c
> > index 60ede89..6bfeb10 100644
> > --- a/net/sctp/input.c
> > +++ b/net/sctp/input.c
> > @@ -723,43 +723,87 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
> > }
> >
> > /* Insert endpoint into the hash table. */
> > -static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
> > +static int __sctp_hash_endpoint(struct sctp_endpoint *ep)
> > {
> > - struct net *net = sock_net(ep->base.sk);
> > - struct sctp_ep_common *epb;
> > + struct sock *sk = ep->base.sk;
> > + struct net *net = sock_net(sk);
> > struct sctp_hashbucket *head;
> > + struct sctp_ep_common *epb;
> >
> > epb = &ep->base;
> > -
> > epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> > head = &sctp_ep_hashtable[epb->hashent];
> >
> > + if (sk->sk_reuseport) {
> > + bool any = sctp_is_ep_boundall(sk);
> > + struct sctp_ep_common *epb2;
> > + struct list_head *list;
> > + int cnt = 0, err = 1;
> > +
> > + list_for_each(list, &ep->base.bind_addr.address_list)
> > + cnt++;
> > +
> > + sctp_for_each_hentry(epb2, &head->chain) {
> > + struct sock *sk2 = epb2->sk;
> > +
> > + if (!net_eq(sock_net(sk2), net) || sk2 = sk ||
> > + !uid_eq(sock_i_uid(sk2), sock_i_uid(sk)) ||
> > + !sk2->sk_reuseport)
> > + continue;
> > +
> > + err = sctp_bind_addrs_check(sctp_sk(sk2),
> > + sctp_sk(sk), cnt);
> > + if (!err) {
> > + err = reuseport_add_sock(sk, sk2, any);
> > + if (err)
> > + return err;
> > + break;
> > + } else if (err < 0) {
> > + return err;
> > + }
> > + }
> > +
> > + if (err) {
> > + err = reuseport_alloc(sk, any);
> > + if (err)
> > + return err;
> > + }
> > + }
> > +
> > write_lock(&head->lock);
> > hlist_add_head(&epb->node, &head->chain);
> > write_unlock(&head->lock);
> > + return 0;
> > }
> >
> > /* Add an endpoint to the hash. Local BH-safe. */
> > -void sctp_hash_endpoint(struct sctp_endpoint *ep)
> > +int sctp_hash_endpoint(struct sctp_endpoint *ep)
> > {
> > + int err;
> > +
> > local_bh_disable();
> > - __sctp_hash_endpoint(ep);
> > + err = __sctp_hash_endpoint(ep);
> > local_bh_enable();
> > +
> > + return err;
> > }
> >
> > /* Remove endpoint from the hash table. */
> > static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
> > {
> > - struct net *net = sock_net(ep->base.sk);
> > + struct sock *sk = ep->base.sk;
> > struct sctp_hashbucket *head;
> > struct sctp_ep_common *epb;
> >
> > epb = &ep->base;
> >
> > - epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
> > + epb->hashent = sctp_ep_hashfn(sock_net(sk), epb->bind_addr.port);
> >
> > head = &sctp_ep_hashtable[epb->hashent];
> >
> > + if (rcu_access_pointer(sk->sk_reuseport_cb))
> > + reuseport_detach_sock(sk);
> > +
> > write_lock(&head->lock);
> > hlist_del_init(&epb->node);
> > write_unlock(&head->lock);
> > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > index fc0386e..44e7d8c 100644
> > --- a/net/sctp/socket.c
> > +++ b/net/sctp/socket.c
> > @@ -7850,8 +7850,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
> > }
> >
> > sk->sk_max_ack_backlog = backlog;
> > - sctp_hash_endpoint(ep);
> > - return 0;
> > + return sctp_hash_endpoint(ep);
> > }
> >
> > /*
> > --
> > 2.1.0
> >
^ permalink raw reply [flat|nested] 46+ messages in thread
end of thread, other threads:[~2018-11-12 19:51 UTC | newest]
Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-21 4:43 [PATCH net-next 0/3] sctp: add support for sk_reuseport Xin Long
2018-10-21 4:43 ` Xin Long
2018-10-21 4:43 ` [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint Xin Long
2018-10-21 4:43 ` Xin Long
2018-10-21 4:43 ` [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint Xin Long
2018-10-21 4:43 ` Xin Long
2018-10-21 4:43 ` [PATCH net-next 3/3] sctp: process sk_reuseport in sctp_get_port_local Xin Long
2018-10-21 4:43 ` Xin Long
2018-10-22 14:15 ` [PATCH net-next 2/3] sctp: add sock_reuseport for the sock in __sctp_hash_endpoint Marcelo Ricardo Leitner
2018-10-22 14:15 ` Marcelo Ricardo Leitner
2018-11-12 9:58 ` Xin Long
2018-11-12 9:58 ` Xin Long
2018-10-22 14:17 ` [PATCH net-next 1/3] sctp: do reuseport_select_sock in __sctp_rcv_lookup_endpoint Marcelo Ricardo Leitner
2018-10-22 14:17 ` Marcelo Ricardo Leitner
2018-11-12 9:56 ` Xin Long
2018-11-12 9:56 ` Xin Long
2018-10-21 6:58 ` [PATCH net-next 0/3] sctp: add support for sk_reuseport Xin Long
2018-10-21 6:58 ` Xin Long
2018-10-22 11:40 ` Neil Horman
2018-10-22 11:40 ` Neil Horman
2018-10-22 14:20 ` Marcelo Ricardo Leitner
2018-10-22 14:20 ` Marcelo Ricardo Leitner
-- strict thread matches above, loose matches on Subject: below --
2018-03-05 12:44 [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458 Xin Long
2018-03-05 12:44 ` Xin Long
2018-03-05 12:44 ` [PATCH net-next 1/3] sctp: add support for PR-SCTP Information for sendmsg Xin Long
2018-03-05 12:44 ` Xin Long
2018-03-05 12:44 ` [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 " Xin Long
2018-03-05 12:44 ` Xin Long
2018-03-05 12:44 ` [PATCH net-next 3/3] sctp: add support for snd flag SCTP_SENDALL process in sendmsg Xin Long
2018-03-05 12:44 ` Xin Long
2018-03-06 12:22 ` Marcelo Ricardo Leitner
2018-03-06 12:22 ` Marcelo Ricardo Leitner
2018-03-05 23:39 ` [PATCH net-next 2/3] sctp: add support for SCTP_DSTADDRV4/6 Information for sendmsg Marcelo Ricardo Leitner
2018-03-05 23:39 ` Marcelo Ricardo Leitner
2018-03-06 7:03 ` Xin Long
2018-03-06 7:03 ` Xin Long
2018-03-06 12:21 ` Marcelo Ricardo Leitner
2018-03-06 12:21 ` Marcelo Ricardo Leitner
2018-03-06 12:22 ` Marcelo Ricardo Leitner
2018-03-06 12:22 ` Marcelo Ricardo Leitner
2018-03-06 12:22 ` [PATCH net-next 1/3] sctp: add support for PR-SCTP " Marcelo Ricardo Leitner
2018-03-06 12:22 ` Marcelo Ricardo Leitner
2018-03-05 23:52 ` [PATCH net-next 0/3] sctp: add support for some msg_control options from RFC6458 Marcelo Ricardo Leitner
2018-03-05 23:52 ` Marcelo Ricardo Leitner
2018-03-07 15:56 ` David Miller
2018-03-07 15:56 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.