Commit a9beb86a authored by Deepa Dinamani's avatar Deepa Dinamani Committed by David S. Miller

sock: Add SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW

Add new socket timeout options that are y2038 safe.
Signed-off-by: default avatarDeepa Dinamani <deepa.kernel@gmail.com>
Acked-by: default avatarWillem de Bruijn <willemb@google.com>
Cc: ccaulfie@redhat.com
Cc: davem@davemloft.net
Cc: deller@gmx.de
Cc: paulus@samba.org
Cc: ralf@linux-mips.org
Cc: rth@twiddle.net
Cc: cluster-devel@redhat.com
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-alpha@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: sparclinux@vger.kernel.org
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 45bdc661
...@@ -119,19 +119,25 @@ ...@@ -119,19 +119,25 @@
#define SO_TIMESTAMPNS_NEW 64 #define SO_TIMESTAMPNS_NEW 64
#define SO_TIMESTAMPING_NEW 65 #define SO_TIMESTAMPING_NEW 65
#if !defined(__KERNEL__) #define SO_RCVTIMEO_NEW 66
#define SO_SNDTIMEO_NEW 67
#define SO_RCVTIMEO SO_RCVTIMEO_OLD #if !defined(__KERNEL__)
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64
#define SO_TIMESTAMP SO_TIMESTAMP_OLD #define SO_TIMESTAMP SO_TIMESTAMP_OLD
#define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD #define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD
#define SO_TIMESTAMPING SO_TIMESTAMPING_OLD #define SO_TIMESTAMPING SO_TIMESTAMPING_OLD
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#else #else
#define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW) #define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW)
#define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW) #define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW)
#define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW) #define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW)
#define SO_RCVTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_RCVTIMEO_OLD : SO_RCVTIMEO_NEW)
#define SO_SNDTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_SNDTIMEO_OLD : SO_SNDTIMEO_NEW)
#endif #endif
#define SCM_TIMESTAMP SO_TIMESTAMP #define SCM_TIMESTAMP SO_TIMESTAMP
......
...@@ -130,18 +130,25 @@ ...@@ -130,18 +130,25 @@
#define SO_TIMESTAMPNS_NEW 64 #define SO_TIMESTAMPNS_NEW 64
#define SO_TIMESTAMPING_NEW 65 #define SO_TIMESTAMPING_NEW 65
#define SO_RCVTIMEO_NEW 66
#define SO_SNDTIMEO_NEW 67
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64
#define SO_TIMESTAMP SO_TIMESTAMP_OLD #define SO_TIMESTAMP SO_TIMESTAMP_OLD
#define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD #define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD
#define SO_TIMESTAMPING SO_TIMESTAMPING_OLD #define SO_TIMESTAMPING SO_TIMESTAMPING_OLD
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#else #else
#define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW) #define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW)
#define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW) #define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW)
#define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW) #define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW)
#define SO_RCVTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_RCVTIMEO_OLD : SO_RCVTIMEO_NEW)
#define SO_SNDTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_SNDTIMEO_OLD : SO_SNDTIMEO_NEW)
#endif #endif
#define SCM_TIMESTAMP SO_TIMESTAMP #define SCM_TIMESTAMP SO_TIMESTAMP
......
...@@ -111,18 +111,24 @@ ...@@ -111,18 +111,24 @@
#define SO_TIMESTAMPNS_NEW 0x4039 #define SO_TIMESTAMPNS_NEW 0x4039
#define SO_TIMESTAMPING_NEW 0x403A #define SO_TIMESTAMPING_NEW 0x403A
#define SO_RCVTIMEO_NEW 0x4040
#define SO_SNDTIMEO_NEW 0x4041
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64
#define SO_TIMESTAMP SO_TIMESTAMP_OLD #define SO_TIMESTAMP SO_TIMESTAMP_OLD
#define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD #define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD
#define SO_TIMESTAMPING SO_TIMESTAMPING_OLD #define SO_TIMESTAMPING SO_TIMESTAMPING_OLD
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#else #else
#define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW) #define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW)
#define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW) #define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW)
#define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW) #define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW)
#define SO_RCVTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_RCVTIMEO_OLD : SO_RCVTIMEO_NEW)
#define SO_SNDTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_SNDTIMEO_OLD : SO_SNDTIMEO_NEW)
#endif #endif
#define SCM_TIMESTAMP SO_TIMESTAMP #define SCM_TIMESTAMP SO_TIMESTAMP
......
...@@ -112,19 +112,26 @@ ...@@ -112,19 +112,26 @@
#define SO_TIMESTAMPNS_NEW 0x0042 #define SO_TIMESTAMPNS_NEW 0x0042
#define SO_TIMESTAMPING_NEW 0x0043 #define SO_TIMESTAMPING_NEW 0x0043
#define SO_RCVTIMEO_NEW 0x0044
#define SO_SNDTIMEO_NEW 0x0045
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#if __BITS_PER_LONG == 64 #if __BITS_PER_LONG == 64
#define SO_TIMESTAMP SO_TIMESTAMP_OLD #define SO_TIMESTAMP SO_TIMESTAMP_OLD
#define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD #define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD
#define SO_TIMESTAMPING SO_TIMESTAMPING_OLD #define SO_TIMESTAMPING SO_TIMESTAMPING_OLD
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#else #else
#define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW) #define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW)
#define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW) #define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW)
#define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW) #define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW)
#define SO_RCVTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_RCVTIMEO_OLD : SO_RCVTIMEO_NEW)
#define SO_SNDTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_SNDTIMEO_OLD : SO_SNDTIMEO_NEW)
#endif #endif
#define SCM_TIMESTAMP SO_TIMESTAMP #define SCM_TIMESTAMP SO_TIMESTAMP
......
...@@ -114,19 +114,26 @@ ...@@ -114,19 +114,26 @@
#define SO_TIMESTAMPNS_NEW 64 #define SO_TIMESTAMPNS_NEW 64
#define SO_TIMESTAMPING_NEW 65 #define SO_TIMESTAMPING_NEW 65
#define SO_RCVTIMEO_NEW 66
#define SO_SNDTIMEO_NEW 67
#if !defined(__KERNEL__) #if !defined(__KERNEL__)
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__)) #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
/* on 64-bit and x32, avoid the ?: operator */ /* on 64-bit and x32, avoid the ?: operator */
#define SO_TIMESTAMP SO_TIMESTAMP_OLD #define SO_TIMESTAMP SO_TIMESTAMP_OLD
#define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD #define SO_TIMESTAMPNS SO_TIMESTAMPNS_OLD
#define SO_TIMESTAMPING SO_TIMESTAMPING_OLD #define SO_TIMESTAMPING SO_TIMESTAMPING_OLD
#define SO_RCVTIMEO SO_RCVTIMEO_OLD
#define SO_SNDTIMEO SO_SNDTIMEO_OLD
#else #else
#define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW) #define SO_TIMESTAMP (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMP_OLD : SO_TIMESTAMP_NEW)
#define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW) #define SO_TIMESTAMPNS (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPNS_OLD : SO_TIMESTAMPNS_NEW)
#define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW) #define SO_TIMESTAMPING (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_TIMESTAMPING_OLD : SO_TIMESTAMPING_NEW)
#define SO_RCVTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_RCVTIMEO_OLD : SO_RCVTIMEO_NEW)
#define SO_SNDTIMEO (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_SNDTIMEO_OLD : SO_SNDTIMEO_NEW)
#endif #endif
#define SCM_TIMESTAMP SO_TIMESTAMP #define SCM_TIMESTAMP SO_TIMESTAMP
......
...@@ -335,9 +335,10 @@ int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -335,9 +335,10 @@ int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
} }
EXPORT_SYMBOL(__sk_backlog_rcv); EXPORT_SYMBOL(__sk_backlog_rcv);
static int sock_get_timeout(long timeo, void *optval) static int sock_get_timeout(long timeo, void *optval, bool old_timeval)
{ {
struct __kernel_old_timeval tv; struct __kernel_sock_timeval tv;
int size;
if (timeo == MAX_SCHEDULE_TIMEOUT) { if (timeo == MAX_SCHEDULE_TIMEOUT) {
tv.tv_sec = 0; tv.tv_sec = 0;
...@@ -353,13 +354,23 @@ static int sock_get_timeout(long timeo, void *optval) ...@@ -353,13 +354,23 @@ static int sock_get_timeout(long timeo, void *optval)
return sizeof(tv32); return sizeof(tv32);
} }
*(struct __kernel_old_timeval *)optval = tv; if (old_timeval) {
return sizeof(tv); struct __kernel_old_timeval old_tv;
old_tv.tv_sec = tv.tv_sec;
old_tv.tv_usec = tv.tv_usec;
*(struct __kernel_old_timeval *)optval = old_tv;
size = sizeof(old_tv);
} else {
*(struct __kernel_sock_timeval *)optval = tv;
size = sizeof(tv);
}
return size;
} }
static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen) static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen, bool old_timeval)
{ {
struct __kernel_old_timeval tv; struct __kernel_sock_timeval tv;
if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) { if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
struct old_timeval32 tv32; struct old_timeval32 tv32;
...@@ -371,6 +382,15 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen) ...@@ -371,6 +382,15 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
return -EFAULT; return -EFAULT;
tv.tv_sec = tv32.tv_sec; tv.tv_sec = tv32.tv_sec;
tv.tv_usec = tv32.tv_usec; tv.tv_usec = tv32.tv_usec;
} else if (old_timeval) {
struct __kernel_old_timeval old_tv;
if (optlen < sizeof(old_tv))
return -EINVAL;
if (copy_from_user(&old_tv, optval, sizeof(old_tv)))
return -EFAULT;
tv.tv_sec = old_tv.tv_sec;
tv.tv_usec = old_tv.tv_usec;
} else { } else {
if (optlen < sizeof(tv)) if (optlen < sizeof(tv))
return -EINVAL; return -EINVAL;
...@@ -394,8 +414,8 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen) ...@@ -394,8 +414,8 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
*timeo_p = MAX_SCHEDULE_TIMEOUT; *timeo_p = MAX_SCHEDULE_TIMEOUT;
if (tv.tv_sec == 0 && tv.tv_usec == 0) if (tv.tv_sec == 0 && tv.tv_usec == 0)
return 0; return 0;
if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1)) if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1))
*timeo_p = tv.tv_sec * HZ + DIV_ROUND_UP(tv.tv_usec, USEC_PER_SEC / HZ); *timeo_p = tv.tv_sec * HZ + DIV_ROUND_UP((unsigned long)tv.tv_usec, USEC_PER_SEC / HZ);
return 0; return 0;
} }
...@@ -942,11 +962,13 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -942,11 +962,13 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
break; break;
case SO_RCVTIMEO_OLD: case SO_RCVTIMEO_OLD:
ret = sock_set_timeout(&sk->sk_rcvtimeo, optval, optlen); case SO_RCVTIMEO_NEW:
ret = sock_set_timeout(&sk->sk_rcvtimeo, optval, optlen, optname == SO_RCVTIMEO_OLD);
break; break;
case SO_SNDTIMEO_OLD: case SO_SNDTIMEO_OLD:
ret = sock_set_timeout(&sk->sk_sndtimeo, optval, optlen); case SO_SNDTIMEO_NEW:
ret = sock_set_timeout(&sk->sk_sndtimeo, optval, optlen, optname == SO_SNDTIMEO_OLD);
break; break;
case SO_ATTACH_FILTER: case SO_ATTACH_FILTER:
...@@ -1171,6 +1193,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, ...@@ -1171,6 +1193,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
struct linger ling; struct linger ling;
struct old_timeval32 tm32; struct old_timeval32 tm32;
struct __kernel_old_timeval tm; struct __kernel_old_timeval tm;
struct __kernel_sock_timeval stm;
struct sock_txtime txtime; struct sock_txtime txtime;
} v; } v;
...@@ -1279,12 +1302,14 @@ int sock_getsockopt(struct socket *sock, int level, int optname, ...@@ -1279,12 +1302,14 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val = sk->sk_tsflags; v.val = sk->sk_tsflags;
break; break;
case SO_RCVTIMEO: case SO_RCVTIMEO_OLD:
lv = sock_get_timeout(sk->sk_rcvtimeo, &v); case SO_RCVTIMEO_NEW:
lv = sock_get_timeout(sk->sk_rcvtimeo, &v, SO_RCVTIMEO_OLD == optname);
break; break;
case SO_SNDTIMEO: case SO_SNDTIMEO_OLD:
lv = sock_get_timeout(sk->sk_sndtimeo, &v); case SO_SNDTIMEO_NEW:
lv = sock_get_timeout(sk->sk_sndtimeo, &v, SO_SNDTIMEO_OLD == optname);
break; break;
case SO_RCVLOWAT: case SO_RCVLOWAT:
......
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