Commit 76ee0785 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

net: add sock_set_sndtimeo

Add a helper to directly set the SO_SNDTIMEO_NEW sockopt from kernel
space without going through a fake uaccess.  The interface is
simplified to only pass the seconds value, as that is the only
thing needed at the moment.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6e434967
...@@ -918,7 +918,6 @@ static void sctp_connect_to_sock(struct connection *con) ...@@ -918,7 +918,6 @@ static void sctp_connect_to_sock(struct connection *con)
int result; int result;
int addr_len; int addr_len;
struct socket *sock; struct socket *sock;
struct __kernel_sock_timeval tv = { .tv_sec = 5, .tv_usec = 0 };
if (con->nodeid == 0) { if (con->nodeid == 0) {
log_print("attempt to connect sock 0 foiled"); log_print("attempt to connect sock 0 foiled");
...@@ -970,13 +969,10 @@ static void sctp_connect_to_sock(struct connection *con) ...@@ -970,13 +969,10 @@ static void sctp_connect_to_sock(struct connection *con)
* since O_NONBLOCK argument in connect() function does not work here, * since O_NONBLOCK argument in connect() function does not work here,
* then, we should restore the default value of this attribute. * then, we should restore the default value of this attribute.
*/ */
kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO_NEW, (char *)&tv, sock_set_sndtimeo(sock->sk, 5);
sizeof(tv));
result = sock->ops->connect(sock, (struct sockaddr *)&daddr, addr_len, result = sock->ops->connect(sock, (struct sockaddr *)&daddr, addr_len,
0); 0);
memset(&tv, 0, sizeof(tv)); sock_set_sndtimeo(sock->sk, 0);
kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO_NEW, (char *)&tv,
sizeof(tv));
if (result == -EINPROGRESS) if (result == -EINPROGRESS)
result = 0; result = 0;
......
...@@ -2691,5 +2691,6 @@ void sock_def_readable(struct sock *sk); ...@@ -2691,5 +2691,6 @@ void sock_def_readable(struct sock *sk);
void sock_no_linger(struct sock *sk); void sock_no_linger(struct sock *sk);
void sock_set_priority(struct sock *sk, u32 priority); void sock_set_priority(struct sock *sk, u32 priority);
void sock_set_reuseaddr(struct sock *sk); void sock_set_reuseaddr(struct sock *sk);
void sock_set_sndtimeo(struct sock *sk, s64 secs);
#endif /* _SOCK_H */ #endif /* _SOCK_H */
...@@ -737,6 +737,17 @@ void sock_set_priority(struct sock *sk, u32 priority) ...@@ -737,6 +737,17 @@ void sock_set_priority(struct sock *sk, u32 priority)
} }
EXPORT_SYMBOL(sock_set_priority); EXPORT_SYMBOL(sock_set_priority);
void sock_set_sndtimeo(struct sock *sk, s64 secs)
{
lock_sock(sk);
if (secs && secs < MAX_SCHEDULE_TIMEOUT / HZ - 1)
sk->sk_sndtimeo = secs * HZ;
else
sk->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT;
release_sock(sk);
}
EXPORT_SYMBOL(sock_set_sndtimeo);
/* /*
* This is meant for all protocols to use and covers goings on * This is meant for all protocols to use and covers goings on
* at the socket level. Everything here is generic. * at the socket level. Everything here is generic.
......
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