Commit c223c7f2 authored by David S. Miller's avatar David S. Miller

Merge branch 'remove-kernel_setsockopt-v4'

Christoph Hellwig says:

====================
remove kernel_setsockopt v4

now that only the dlm calls to sctp are left for kernel_setsockopt,
while we haven't really made much progress with the sctp setsockopt
refactoring, how about this small series that splits out a
sctp_setsockopt_bindx_kernel that takes a kernel space address array
to share more code as requested by Marcelo.  This should fit in with
whatever variant of the refator of sctp setsockopt we go with, but
just solved the immediate problem for now.

Changes since v3:
 - dropped all the merged patches, just sctp setsockopt left now
 - factor out a new sctp_setsockopt_bindx_kernel helper instead of
   duplicating a small amount of logic

Changes since v2:
 - drop the separately merged kernel_getopt_removal
 - drop the sctp patches, as there is conflicting cleanup going on
 - add an additional ACK for the rxrpc changes

Changes since v1:
 - use ->getname for sctp sockets in dlm
 - add a new ->bind_add struct proto method for dlm/sctp
 - switch the ipv6 and remaining sctp helpers to inline function so that
   the ipv6 and sctp modules are not pulled in by any module that could
   potentially use ipv6 or sctp connections
 - remove arguments to various sock_* helpers that are always used with
   the same constant arguments
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f26e9b2c 5a892ff2
...@@ -882,6 +882,7 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed) ...@@ -882,6 +882,7 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)
static int sctp_bind_addrs(struct connection *con, uint16_t port) static int sctp_bind_addrs(struct connection *con, uint16_t port)
{ {
struct sockaddr_storage localaddr; struct sockaddr_storage localaddr;
struct sockaddr *addr = (struct sockaddr *)&localaddr;
int i, addr_len, result = 0; int i, addr_len, result = 0;
for (i = 0; i < dlm_local_count; i++) { for (i = 0; i < dlm_local_count; i++) {
...@@ -889,13 +890,9 @@ static int sctp_bind_addrs(struct connection *con, uint16_t port) ...@@ -889,13 +890,9 @@ static int sctp_bind_addrs(struct connection *con, uint16_t port)
make_sockaddr(&localaddr, port, &addr_len); make_sockaddr(&localaddr, port, &addr_len);
if (!i) if (!i)
result = kernel_bind(con->sock, result = kernel_bind(con->sock, addr, addr_len);
(struct sockaddr *)&localaddr,
addr_len);
else else
result = kernel_setsockopt(con->sock, SOL_SCTP, result = sock_bind_add(con->sock->sk, addr, addr_len);
SCTP_SOCKOPT_BINDX_ADD,
(char *)&localaddr, addr_len);
if (result < 0) { if (result < 0) {
log_print("Can't bind to %d addr number %d, %d.\n", log_print("Can't bind to %d addr number %d, %d.\n",
...@@ -914,7 +911,6 @@ static int sctp_bind_addrs(struct connection *con, uint16_t port) ...@@ -914,7 +911,6 @@ static int sctp_bind_addrs(struct connection *con, uint16_t port)
static void sctp_connect_to_sock(struct connection *con) static void sctp_connect_to_sock(struct connection *con)
{ {
struct sockaddr_storage daddr; struct sockaddr_storage daddr;
int one = 1;
int result; int result;
int addr_len; int addr_len;
struct socket *sock; struct socket *sock;
...@@ -961,8 +957,7 @@ static void sctp_connect_to_sock(struct connection *con) ...@@ -961,8 +957,7 @@ static void sctp_connect_to_sock(struct connection *con)
log_print("connecting to %d", con->nodeid); log_print("connecting to %d", con->nodeid);
/* Turn off Nagle's algorithm */ /* Turn off Nagle's algorithm */
kernel_setsockopt(sock, SOL_SCTP, SCTP_NODELAY, (char *)&one, sctp_sock_set_nodelay(sock->sk);
sizeof(one));
/* /*
* Make sock->ops->connect() function return in specified time, * Make sock->ops->connect() function return in specified time,
...@@ -1176,7 +1171,6 @@ static int sctp_listen_for_all(void) ...@@ -1176,7 +1171,6 @@ static int sctp_listen_for_all(void)
struct socket *sock = NULL; struct socket *sock = NULL;
int result = -EINVAL; int result = -EINVAL;
struct connection *con = nodeid2con(0, GFP_NOFS); struct connection *con = nodeid2con(0, GFP_NOFS);
int one = 1;
if (!con) if (!con)
return -ENOMEM; return -ENOMEM;
...@@ -1191,10 +1185,7 @@ static int sctp_listen_for_all(void) ...@@ -1191,10 +1185,7 @@ static int sctp_listen_for_all(void)
} }
sock_set_rcvbuf(sock->sk, NEEDED_RMEM); sock_set_rcvbuf(sock->sk, NEEDED_RMEM);
result = kernel_setsockopt(sock, SOL_SCTP, SCTP_NODELAY, (char *)&one, sctp_sock_set_nodelay(sock->sk);
sizeof(one));
if (result < 0)
log_print("Could not set SCTP NODELAY error %d\n", result);
write_lock_bh(&sock->sk->sk_callback_lock); write_lock_bh(&sock->sk->sk_callback_lock);
/* Init con struct */ /* Init con struct */
......
...@@ -303,8 +303,6 @@ int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, ...@@ -303,8 +303,6 @@ int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen,
int flags); int flags);
int kernel_getsockname(struct socket *sock, struct sockaddr *addr); int kernel_getsockname(struct socket *sock, struct sockaddr *addr);
int kernel_getpeername(struct socket *sock, struct sockaddr *addr); int kernel_getpeername(struct socket *sock, struct sockaddr *addr);
int kernel_setsockopt(struct socket *sock, int level, int optname, char *optval,
unsigned int optlen);
int kernel_sendpage(struct socket *sock, struct page *page, int offset, int kernel_sendpage(struct socket *sock, struct page *page, int offset,
size_t size, int flags); size_t size, int flags);
int kernel_sendpage_locked(struct sock *sk, struct page *page, int offset, int kernel_sendpage_locked(struct sock *sk, struct page *page, int offset,
......
...@@ -615,4 +615,11 @@ static inline bool sctp_newsk_ready(const struct sock *sk) ...@@ -615,4 +615,11 @@ static inline bool sctp_newsk_ready(const struct sock *sk)
return sock_flag(sk, SOCK_DEAD) || sk->sk_socket; return sock_flag(sk, SOCK_DEAD) || sk->sk_socket;
} }
static inline void sctp_sock_set_nodelay(struct sock *sk)
{
lock_sock(sk);
sctp_sk(sk)->nodelay = true;
release_sock(sk);
}
#endif /* __net_sctp_h__ */ #endif /* __net_sctp_h__ */
...@@ -1156,7 +1156,9 @@ struct proto { ...@@ -1156,7 +1156,9 @@ struct proto {
int (*sendpage)(struct sock *sk, struct page *page, int (*sendpage)(struct sock *sk, struct page *page,
int offset, size_t size, int flags); int offset, size_t size, int flags);
int (*bind)(struct sock *sk, int (*bind)(struct sock *sk,
struct sockaddr *uaddr, int addr_len); struct sockaddr *addr, int addr_len);
int (*bind_add)(struct sock *sk,
struct sockaddr *addr, int addr_len);
int (*backlog_rcv) (struct sock *sk, int (*backlog_rcv) (struct sock *sk,
struct sk_buff *skb); struct sk_buff *skb);
...@@ -2698,4 +2700,6 @@ void sock_set_reuseaddr(struct sock *sk); ...@@ -2698,4 +2700,6 @@ void sock_set_reuseaddr(struct sock *sk);
void sock_set_reuseport(struct sock *sk); void sock_set_reuseport(struct sock *sk);
void sock_set_sndtimeo(struct sock *sk, s64 secs); void sock_set_sndtimeo(struct sock *sk, s64 secs);
int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len);
#endif /* _SOCK_H */ #endif /* _SOCK_H */
...@@ -3712,3 +3712,11 @@ bool sk_busy_loop_end(void *p, unsigned long start_time) ...@@ -3712,3 +3712,11 @@ bool sk_busy_loop_end(void *p, unsigned long start_time)
} }
EXPORT_SYMBOL(sk_busy_loop_end); EXPORT_SYMBOL(sk_busy_loop_end);
#endif /* CONFIG_NET_RX_BUSY_POLL */ #endif /* CONFIG_NET_RX_BUSY_POLL */
int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len)
{
if (!sk->sk_prot->bind_add)
return -EOPNOTSUPP;
return sk->sk_prot->bind_add(sk, addr, addr_len);
}
EXPORT_SYMBOL(sock_bind_add);
...@@ -972,23 +972,22 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw) ...@@ -972,23 +972,22 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw)
* it. * it.
* *
* sk The sk of the socket * sk The sk of the socket
* addrs The pointer to the addresses in user land * addrs The pointer to the addresses
* addrssize Size of the addrs buffer * addrssize Size of the addrs buffer
* op Operation to perform (add or remove, see the flags of * op Operation to perform (add or remove, see the flags of
* sctp_bindx) * sctp_bindx)
* *
* Returns 0 if ok, <0 errno code on error. * Returns 0 if ok, <0 errno code on error.
*/ */
static int sctp_setsockopt_bindx(struct sock *sk, static int sctp_setsockopt_bindx_kernel(struct sock *sk,
struct sockaddr __user *addrs, struct sockaddr *addrs, int addrs_size,
int addrs_size, int op) int op)
{ {
struct sockaddr *kaddrs;
int err; int err;
int addrcnt = 0; int addrcnt = 0;
int walk_size = 0; int walk_size = 0;
struct sockaddr *sa_addr; struct sockaddr *sa_addr;
void *addr_buf; void *addr_buf = addrs;
struct sctp_af *af; struct sctp_af *af;
pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n", pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",
...@@ -997,17 +996,10 @@ static int sctp_setsockopt_bindx(struct sock *sk, ...@@ -997,17 +996,10 @@ static int sctp_setsockopt_bindx(struct sock *sk,
if (unlikely(addrs_size <= 0)) if (unlikely(addrs_size <= 0))
return -EINVAL; return -EINVAL;
kaddrs = memdup_user(addrs, addrs_size);
if (IS_ERR(kaddrs))
return PTR_ERR(kaddrs);
/* Walk through the addrs buffer and count the number of addresses. */ /* Walk through the addrs buffer and count the number of addresses. */
addr_buf = kaddrs;
while (walk_size < addrs_size) { while (walk_size < addrs_size) {
if (walk_size + sizeof(sa_family_t) > addrs_size) { if (walk_size + sizeof(sa_family_t) > addrs_size)
kfree(kaddrs);
return -EINVAL; return -EINVAL;
}
sa_addr = addr_buf; sa_addr = addr_buf;
af = sctp_get_af_specific(sa_addr->sa_family); af = sctp_get_af_specific(sa_addr->sa_family);
...@@ -1015,10 +1007,8 @@ static int sctp_setsockopt_bindx(struct sock *sk, ...@@ -1015,10 +1007,8 @@ static int sctp_setsockopt_bindx(struct sock *sk,
/* If the address family is not supported or if this address /* If the address family is not supported or if this address
* causes the address buffer to overflow return EINVAL. * causes the address buffer to overflow return EINVAL.
*/ */
if (!af || (walk_size + af->sockaddr_len) > addrs_size) { if (!af || (walk_size + af->sockaddr_len) > addrs_size)
kfree(kaddrs);
return -EINVAL; return -EINVAL;
}
addrcnt++; addrcnt++;
addr_buf += af->sockaddr_len; addr_buf += af->sockaddr_len;
walk_size += af->sockaddr_len; walk_size += af->sockaddr_len;
...@@ -1029,31 +1019,48 @@ static int sctp_setsockopt_bindx(struct sock *sk, ...@@ -1029,31 +1019,48 @@ static int sctp_setsockopt_bindx(struct sock *sk,
case SCTP_BINDX_ADD_ADDR: case SCTP_BINDX_ADD_ADDR:
/* Allow security module to validate bindx addresses. */ /* Allow security module to validate bindx addresses. */
err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD, err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD,
(struct sockaddr *)kaddrs, addrs, addrs_size);
addrs_size);
if (err) if (err)
goto out; return err;
err = sctp_bindx_add(sk, kaddrs, addrcnt); err = sctp_bindx_add(sk, addrs, addrcnt);
if (err) if (err)
goto out; return err;
err = sctp_send_asconf_add_ip(sk, kaddrs, addrcnt); return sctp_send_asconf_add_ip(sk, addrs, addrcnt);
break;
case SCTP_BINDX_REM_ADDR: case SCTP_BINDX_REM_ADDR:
err = sctp_bindx_rem(sk, kaddrs, addrcnt); err = sctp_bindx_rem(sk, addrs, addrcnt);
if (err) if (err)
goto out; return err;
err = sctp_send_asconf_del_ip(sk, kaddrs, addrcnt); return sctp_send_asconf_del_ip(sk, addrs, addrcnt);
break;
default: default:
err = -EINVAL; return -EINVAL;
break;
} }
}
out: static int sctp_setsockopt_bindx(struct sock *sk,
struct sockaddr __user *addrs,
int addrs_size, int op)
{
struct sockaddr *kaddrs;
int err;
kaddrs = memdup_user(addrs, addrs_size);
if (IS_ERR(kaddrs))
return PTR_ERR(kaddrs);
err = sctp_setsockopt_bindx_kernel(sk, kaddrs, addrs_size, op);
kfree(kaddrs); kfree(kaddrs);
return err;
}
static int sctp_bind_add(struct sock *sk, struct sockaddr *addrs,
int addrlen)
{
int err;
lock_sock(sk);
err = sctp_setsockopt_bindx_kernel(sk, addrs, addrlen,
SCTP_BINDX_ADD_ADDR);
release_sock(sk);
return err; return err;
} }
...@@ -9625,6 +9632,7 @@ struct proto sctp_prot = { ...@@ -9625,6 +9632,7 @@ struct proto sctp_prot = {
.sendmsg = sctp_sendmsg, .sendmsg = sctp_sendmsg,
.recvmsg = sctp_recvmsg, .recvmsg = sctp_recvmsg,
.bind = sctp_bind, .bind = sctp_bind,
.bind_add = sctp_bind_add,
.backlog_rcv = sctp_backlog_rcv, .backlog_rcv = sctp_backlog_rcv,
.hash = sctp_hash, .hash = sctp_hash,
.unhash = sctp_unhash, .unhash = sctp_unhash,
...@@ -9667,6 +9675,7 @@ struct proto sctpv6_prot = { ...@@ -9667,6 +9675,7 @@ struct proto sctpv6_prot = {
.sendmsg = sctp_sendmsg, .sendmsg = sctp_sendmsg,
.recvmsg = sctp_recvmsg, .recvmsg = sctp_recvmsg,
.bind = sctp_bind, .bind = sctp_bind,
.bind_add = sctp_bind_add,
.backlog_rcv = sctp_backlog_rcv, .backlog_rcv = sctp_backlog_rcv,
.hash = sctp_hash, .hash = sctp_hash,
.unhash = sctp_unhash, .unhash = sctp_unhash,
......
...@@ -3624,37 +3624,6 @@ int kernel_getpeername(struct socket *sock, struct sockaddr *addr) ...@@ -3624,37 +3624,6 @@ int kernel_getpeername(struct socket *sock, struct sockaddr *addr)
} }
EXPORT_SYMBOL(kernel_getpeername); EXPORT_SYMBOL(kernel_getpeername);
/**
* kernel_setsockopt - set a socket option (kernel space)
* @sock: socket
* @level: API level (SOL_SOCKET, ...)
* @optname: option tag
* @optval: option value
* @optlen: option length
*
* Returns 0 or an error.
*/
int kernel_setsockopt(struct socket *sock, int level, int optname,
char *optval, unsigned int optlen)
{
mm_segment_t oldfs = get_fs();
char __user *uoptval;
int err;
uoptval = (char __user __force *) optval;
set_fs(KERNEL_DS);
if (level == SOL_SOCKET)
err = sock_setsockopt(sock, level, optname, uoptval, optlen);
else
err = sock->ops->setsockopt(sock, level, optname, uoptval,
optlen);
set_fs(oldfs);
return err;
}
EXPORT_SYMBOL(kernel_setsockopt);
/** /**
* kernel_sendpage - send a &page through a socket (kernel space) * kernel_sendpage - send a &page through a socket (kernel space)
* @sock: socket * @sock: socket
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment