forked from luck/tmp_suning_uos_patched
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: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
c223c7f22c
|
@ -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)
|
||||
{
|
||||
struct sockaddr_storage localaddr;
|
||||
struct sockaddr *addr = (struct sockaddr *)&localaddr;
|
||||
int i, addr_len, result = 0;
|
||||
|
||||
for (i = 0; i < dlm_local_count; i++) {
|
||||
|
@ -889,13 +890,9 @@ static int sctp_bind_addrs(struct connection *con, uint16_t port)
|
|||
make_sockaddr(&localaddr, port, &addr_len);
|
||||
|
||||
if (!i)
|
||||
result = kernel_bind(con->sock,
|
||||
(struct sockaddr *)&localaddr,
|
||||
addr_len);
|
||||
result = kernel_bind(con->sock, addr, addr_len);
|
||||
else
|
||||
result = kernel_setsockopt(con->sock, SOL_SCTP,
|
||||
SCTP_SOCKOPT_BINDX_ADD,
|
||||
(char *)&localaddr, addr_len);
|
||||
result = sock_bind_add(con->sock->sk, addr, addr_len);
|
||||
|
||||
if (result < 0) {
|
||||
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)
|
|||
static void sctp_connect_to_sock(struct connection *con)
|
||||
{
|
||||
struct sockaddr_storage daddr;
|
||||
int one = 1;
|
||||
int result;
|
||||
int addr_len;
|
||||
struct socket *sock;
|
||||
|
@ -961,8 +957,7 @@ static void sctp_connect_to_sock(struct connection *con)
|
|||
log_print("connecting to %d", con->nodeid);
|
||||
|
||||
/* Turn off Nagle's algorithm */
|
||||
kernel_setsockopt(sock, SOL_SCTP, SCTP_NODELAY, (char *)&one,
|
||||
sizeof(one));
|
||||
sctp_sock_set_nodelay(sock->sk);
|
||||
|
||||
/*
|
||||
* Make sock->ops->connect() function return in specified time,
|
||||
|
@ -1176,7 +1171,6 @@ static int sctp_listen_for_all(void)
|
|||
struct socket *sock = NULL;
|
||||
int result = -EINVAL;
|
||||
struct connection *con = nodeid2con(0, GFP_NOFS);
|
||||
int one = 1;
|
||||
|
||||
if (!con)
|
||||
return -ENOMEM;
|
||||
|
@ -1191,10 +1185,7 @@ static int sctp_listen_for_all(void)
|
|||
}
|
||||
|
||||
sock_set_rcvbuf(sock->sk, NEEDED_RMEM);
|
||||
result = kernel_setsockopt(sock, SOL_SCTP, SCTP_NODELAY, (char *)&one,
|
||||
sizeof(one));
|
||||
if (result < 0)
|
||||
log_print("Could not set SCTP NODELAY error %d\n", result);
|
||||
sctp_sock_set_nodelay(sock->sk);
|
||||
|
||||
write_lock_bh(&sock->sk->sk_callback_lock);
|
||||
/* Init con struct */
|
||||
|
|
|
@ -303,8 +303,6 @@ int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen,
|
|||
int flags);
|
||||
int kernel_getsockname(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,
|
||||
size_t size, int flags);
|
||||
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)
|
|||
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__ */
|
||||
|
|
|
@ -1156,7 +1156,9 @@ struct proto {
|
|||
int (*sendpage)(struct sock *sk, struct page *page,
|
||||
int offset, size_t size, int flags);
|
||||
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,
|
||||
struct sk_buff *skb);
|
||||
|
@ -2698,4 +2700,6 @@ void sock_set_reuseaddr(struct sock *sk);
|
|||
void sock_set_reuseport(struct sock *sk);
|
||||
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 */
|
||||
|
|
|
@ -3712,3 +3712,11 @@ bool sk_busy_loop_end(void *p, unsigned long start_time)
|
|||
}
|
||||
EXPORT_SYMBOL(sk_busy_loop_end);
|
||||
#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)
|
|||
* it.
|
||||
*
|
||||
* 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
|
||||
* op Operation to perform (add or remove, see the flags of
|
||||
* sctp_bindx)
|
||||
*
|
||||
* Returns 0 if ok, <0 errno code on error.
|
||||
*/
|
||||
static int sctp_setsockopt_bindx(struct sock *sk,
|
||||
struct sockaddr __user *addrs,
|
||||
int addrs_size, int op)
|
||||
static int sctp_setsockopt_bindx_kernel(struct sock *sk,
|
||||
struct sockaddr *addrs, int addrs_size,
|
||||
int op)
|
||||
{
|
||||
struct sockaddr *kaddrs;
|
||||
int err;
|
||||
int addrcnt = 0;
|
||||
int walk_size = 0;
|
||||
struct sockaddr *sa_addr;
|
||||
void *addr_buf;
|
||||
void *addr_buf = addrs;
|
||||
struct sctp_af *af;
|
||||
|
||||
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,
|
|||
if (unlikely(addrs_size <= 0))
|
||||
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. */
|
||||
addr_buf = kaddrs;
|
||||
while (walk_size < addrs_size) {
|
||||
if (walk_size + sizeof(sa_family_t) > addrs_size) {
|
||||
kfree(kaddrs);
|
||||
if (walk_size + sizeof(sa_family_t) > addrs_size)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
sa_addr = addr_buf;
|
||||
af = sctp_get_af_specific(sa_addr->sa_family);
|
||||
|
@ -1015,10 +1007,8 @@ static int sctp_setsockopt_bindx(struct sock *sk,
|
|||
/* If the address family is not supported or if this address
|
||||
* causes the address buffer to overflow return EINVAL.
|
||||
*/
|
||||
if (!af || (walk_size + af->sockaddr_len) > addrs_size) {
|
||||
kfree(kaddrs);
|
||||
if (!af || (walk_size + af->sockaddr_len) > addrs_size)
|
||||
return -EINVAL;
|
||||
}
|
||||
addrcnt++;
|
||||
addr_buf += af->sockaddr_len;
|
||||
walk_size += af->sockaddr_len;
|
||||
|
@ -1029,31 +1019,48 @@ static int sctp_setsockopt_bindx(struct sock *sk,
|
|||
case SCTP_BINDX_ADD_ADDR:
|
||||
/* Allow security module to validate bindx addresses. */
|
||||
err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD,
|
||||
(struct sockaddr *)kaddrs,
|
||||
addrs_size);
|
||||
addrs, addrs_size);
|
||||
if (err)
|
||||
goto out;
|
||||
err = sctp_bindx_add(sk, kaddrs, addrcnt);
|
||||
return err;
|
||||
err = sctp_bindx_add(sk, addrs, addrcnt);
|
||||
if (err)
|
||||
goto out;
|
||||
err = sctp_send_asconf_add_ip(sk, kaddrs, addrcnt);
|
||||
break;
|
||||
|
||||
return err;
|
||||
return sctp_send_asconf_add_ip(sk, addrs, addrcnt);
|
||||
case SCTP_BINDX_REM_ADDR:
|
||||
err = sctp_bindx_rem(sk, kaddrs, addrcnt);
|
||||
err = sctp_bindx_rem(sk, addrs, addrcnt);
|
||||
if (err)
|
||||
goto out;
|
||||
err = sctp_send_asconf_del_ip(sk, kaddrs, addrcnt);
|
||||
break;
|
||||
return err;
|
||||
return sctp_send_asconf_del_ip(sk, addrs, addrcnt);
|
||||
|
||||
default:
|
||||
err = -EINVAL;
|
||||
break;
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -9625,6 +9632,7 @@ struct proto sctp_prot = {
|
|||
.sendmsg = sctp_sendmsg,
|
||||
.recvmsg = sctp_recvmsg,
|
||||
.bind = sctp_bind,
|
||||
.bind_add = sctp_bind_add,
|
||||
.backlog_rcv = sctp_backlog_rcv,
|
||||
.hash = sctp_hash,
|
||||
.unhash = sctp_unhash,
|
||||
|
@ -9667,6 +9675,7 @@ struct proto sctpv6_prot = {
|
|||
.sendmsg = sctp_sendmsg,
|
||||
.recvmsg = sctp_recvmsg,
|
||||
.bind = sctp_bind,
|
||||
.bind_add = sctp_bind_add,
|
||||
.backlog_rcv = sctp_backlog_rcv,
|
||||
.hash = sctp_hash,
|
||||
.unhash = sctp_unhash,
|
||||
|
|
31
net/socket.c
31
net/socket.c
|
@ -3624,37 +3624,6 @@ int kernel_getpeername(struct socket *sock, struct sockaddr *addr)
|
|||
}
|
||||
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)
|
||||
* @sock: socket
|
||||
|
|
Loading…
Reference in New Issue
Block a user