aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2007-03-26 01:14:49 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:24:21 -0400
commit92f37fd2ee805aa77925c1e64fd56088b46094fc (patch)
tree8251c38b83ab362116dac89d94412ce229b42831
parentc7a3c5da35055e2fa97ed4f0da3eec4bd0ef4c38 (diff)
[NET]: Adding SO_TIMESTAMPNS / SCM_TIMESTAMPNS support
Now that network timestamps use ktime_t infrastructure, we can add a new SOL_SOCKET sockopt SO_TIMESTAMPNS. This command is similar to SO_TIMESTAMP, but permits transmission of a 'timespec struct' instead of a 'timeval struct' control message. (nanosecond resolution instead of microsecond) Control message is labelled SCM_TIMESTAMPNS instead of SCM_TIMESTAMP A socket cannot mix SO_TIMESTAMP and SO_TIMESTAMPNS : the two modes are mutually exclusive. sock_recv_timestamp() became too big to be fully inlined so I added a __sock_recv_timestamp() helper function. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> CC: linux-arch@vger.kernel.org Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/asm-alpha/socket.h2
-rw-r--r--include/asm-arm/socket.h2
-rw-r--r--include/asm-arm26/socket.h2
-rw-r--r--include/asm-avr32/socket.h2
-rw-r--r--include/asm-cris/socket.h2
-rw-r--r--include/asm-frv/socket.h2
-rw-r--r--include/asm-h8300/socket.h2
-rw-r--r--include/asm-i386/socket.h2
-rw-r--r--include/asm-ia64/socket.h2
-rw-r--r--include/asm-m32r/socket.h2
-rw-r--r--include/asm-m68k/socket.h2
-rw-r--r--include/asm-mips/socket.h2
-rw-r--r--include/asm-parisc/socket.h2
-rw-r--r--include/asm-powerpc/socket.h2
-rw-r--r--include/asm-s390/socket.h2
-rw-r--r--include/asm-sh/socket.h2
-rw-r--r--include/asm-sparc/socket.h2
-rw-r--r--include/asm-sparc64/socket.h2
-rw-r--r--include/asm-v850/socket.h2
-rw-r--r--include/asm-x86_64/socket.h2
-rw-r--r--include/asm-xtensa/socket.h2
-rw-r--r--include/net/sock.h17
-rw-r--r--net/compat.c10
-rw-r--r--net/core/sock.c16
-rw-r--r--net/socket.c29
25 files changed, 101 insertions, 13 deletions
diff --git a/include/asm-alpha/socket.h b/include/asm-alpha/socket.h
index d22ab97ea72e..1fede7f92860 100644
--- a/include/asm-alpha/socket.h
+++ b/include/asm-alpha/socket.h
@@ -52,6 +52,8 @@
52 52
53#define SO_PEERSEC 30 53#define SO_PEERSEC 30
54#define SO_PASSSEC 34 54#define SO_PASSSEC 34
55#define SO_TIMESTAMPNS 35
56#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
55 57
56/* Security levels - as per NRL IPv6 - don't actually do anything */ 58/* Security levels - as per NRL IPv6 - don't actually do anything */
57#define SO_SECURITY_AUTHENTICATION 19 59#define SO_SECURITY_AUTHENTICATION 19
diff --git a/include/asm-arm/socket.h b/include/asm-arm/socket.h
index 19f7df702b06..65a1a64bf934 100644
--- a/include/asm-arm/socket.h
+++ b/include/asm-arm/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-arm26/socket.h b/include/asm-arm26/socket.h
index 19f7df702b06..65a1a64bf934 100644
--- a/include/asm-arm26/socket.h
+++ b/include/asm-arm26/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-avr32/socket.h b/include/asm-avr32/socket.h
index 543229de8173..a0d0507a5034 100644
--- a/include/asm-avr32/socket.h
+++ b/include/asm-avr32/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* __ASM_AVR32_SOCKET_H */ 55#endif /* __ASM_AVR32_SOCKET_H */
diff --git a/include/asm-cris/socket.h b/include/asm-cris/socket.h
index 01cfdf1d6d33..5b18dfdf1748 100644
--- a/include/asm-cris/socket.h
+++ b/include/asm-cris/socket.h
@@ -51,6 +51,8 @@
51 51
52#define SO_PEERSEC 31 52#define SO_PEERSEC 31
53#define SO_PASSSEC 34 53#define SO_PASSSEC 34
54#define SO_TIMESTAMPNS 35
55#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
54 56
55#endif /* _ASM_SOCKET_H */ 57#endif /* _ASM_SOCKET_H */
56 58
diff --git a/include/asm-frv/socket.h b/include/asm-frv/socket.h
index 31db18fc871f..a823befd11dd 100644
--- a/include/asm-frv/socket.h
+++ b/include/asm-frv/socket.h
@@ -49,6 +49,8 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
54 56
diff --git a/include/asm-h8300/socket.h b/include/asm-h8300/socket.h
index ebc830fee0d0..39911d8c9684 100644
--- a/include/asm-h8300/socket.h
+++ b/include/asm-h8300/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-i386/socket.h b/include/asm-i386/socket.h
index 5755d57c4e95..99ca648b94c5 100644
--- a/include/asm-i386/socket.h
+++ b/include/asm-i386/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-ia64/socket.h b/include/asm-ia64/socket.h
index d638ef3d50c3..9e42ce43cfbe 100644
--- a/include/asm-ia64/socket.h
+++ b/include/asm-ia64/socket.h
@@ -58,5 +58,7 @@
58 58
59#define SO_PEERSEC 31 59#define SO_PEERSEC 31
60#define SO_PASSSEC 34 60#define SO_PASSSEC 34
61#define SO_TIMESTAMPNS 35
62#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
61 63
62#endif /* _ASM_IA64_SOCKET_H */ 64#endif /* _ASM_IA64_SOCKET_H */
diff --git a/include/asm-m32r/socket.h b/include/asm-m32r/socket.h
index acdf748fcdc8..793d5d30c850 100644
--- a/include/asm-m32r/socket.h
+++ b/include/asm-m32r/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_M32R_SOCKET_H */ 55#endif /* _ASM_M32R_SOCKET_H */
diff --git a/include/asm-m68k/socket.h b/include/asm-m68k/socket.h
index a5966ec005ae..6d21b90863ad 100644
--- a/include/asm-m68k/socket.h
+++ b/include/asm-m68k/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-mips/socket.h b/include/asm-mips/socket.h
index 36ebe4e186a7..95945689b1c6 100644
--- a/include/asm-mips/socket.h
+++ b/include/asm-mips/socket.h
@@ -70,6 +70,8 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */
70#define SO_SNDBUFFORCE 31 70#define SO_SNDBUFFORCE 31
71#define SO_RCVBUFFORCE 33 71#define SO_RCVBUFFORCE 33
72#define SO_PASSSEC 34 72#define SO_PASSSEC 34
73#define SO_TIMESTAMPNS 35
74#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
73 75
74#ifdef __KERNEL__ 76#ifdef __KERNEL__
75 77
diff --git a/include/asm-parisc/socket.h b/include/asm-parisc/socket.h
index ce2eae1708b5..99e868f6a8f5 100644
--- a/include/asm-parisc/socket.h
+++ b/include/asm-parisc/socket.h
@@ -33,6 +33,8 @@
33#define SO_PEERCRED 0x4011 33#define SO_PEERCRED 0x4011
34#define SO_TIMESTAMP 0x4012 34#define SO_TIMESTAMP 0x4012
35#define SCM_TIMESTAMP SO_TIMESTAMP 35#define SCM_TIMESTAMP SO_TIMESTAMP
36#define SO_TIMESTAMPNS 0x4013
37#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
36 38
37/* Security levels - as per NRL IPv6 - don't actually do anything */ 39/* Security levels - as per NRL IPv6 - don't actually do anything */
38#define SO_SECURITY_AUTHENTICATION 0x4016 40#define SO_SECURITY_AUTHENTICATION 0x4016
diff --git a/include/asm-powerpc/socket.h b/include/asm-powerpc/socket.h
index c8b1da50e72d..403e9fde2eb5 100644
--- a/include/asm-powerpc/socket.h
+++ b/include/asm-powerpc/socket.h
@@ -56,5 +56,7 @@
56 56
57#define SO_PEERSEC 31 57#define SO_PEERSEC 31
58#define SO_PASSSEC 34 58#define SO_PASSSEC 34
59#define SO_TIMESTAMPNS 35
60#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
59 61
60#endif /* _ASM_POWERPC_SOCKET_H */ 62#endif /* _ASM_POWERPC_SOCKET_H */
diff --git a/include/asm-s390/socket.h b/include/asm-s390/socket.h
index 1778a49a74c5..1161ebe3dec9 100644
--- a/include/asm-s390/socket.h
+++ b/include/asm-s390/socket.h
@@ -57,5 +57,7 @@
57 57
58#define SO_PEERSEC 31 58#define SO_PEERSEC 31
59#define SO_PASSSEC 34 59#define SO_PASSSEC 34
60#define SO_TIMESTAMPNS 35
61#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
60 62
61#endif /* _ASM_SOCKET_H */ 63#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-sh/socket.h b/include/asm-sh/socket.h
index ca70362eb563..c48d6fc9da38 100644
--- a/include/asm-sh/socket.h
+++ b/include/asm-sh/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* __ASM_SH_SOCKET_H */ 55#endif /* __ASM_SH_SOCKET_H */
diff --git a/include/asm-sparc/socket.h b/include/asm-sparc/socket.h
index f6c4e5baf3f7..7c1423997cf0 100644
--- a/include/asm-sparc/socket.h
+++ b/include/asm-sparc/socket.h
@@ -49,6 +49,8 @@
49 49
50#define SO_PEERSEC 0x001e 50#define SO_PEERSEC 0x001e
51#define SO_PASSSEC 0x001f 51#define SO_PASSSEC 0x001f
52#define SO_TIMESTAMPNS 0x0021
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53/* Security levels - as per NRL IPv6 - don't actually do anything */ 55/* Security levels - as per NRL IPv6 - don't actually do anything */
54#define SO_SECURITY_AUTHENTICATION 0x5001 56#define SO_SECURITY_AUTHENTICATION 0x5001
diff --git a/include/asm-sparc64/socket.h b/include/asm-sparc64/socket.h
index 754d46a50af3..986441dcb8f0 100644
--- a/include/asm-sparc64/socket.h
+++ b/include/asm-sparc64/socket.h
@@ -49,6 +49,8 @@
49 49
50#define SO_PEERSEC 0x001e 50#define SO_PEERSEC 0x001e
51#define SO_PASSSEC 0x001f 51#define SO_PASSSEC 0x001f
52#define SO_TIMESTAMPNS 0x0021
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53/* Security levels - as per NRL IPv6 - don't actually do anything */ 55/* Security levels - as per NRL IPv6 - don't actually do anything */
54#define SO_SECURITY_AUTHENTICATION 0x5001 56#define SO_SECURITY_AUTHENTICATION 0x5001
diff --git a/include/asm-v850/socket.h b/include/asm-v850/socket.h
index 0dfe55ac2ef2..a4c2493b025f 100644
--- a/include/asm-v850/socket.h
+++ b/include/asm-v850/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* __V850_SOCKET_H__ */ 55#endif /* __V850_SOCKET_H__ */
diff --git a/include/asm-x86_64/socket.h b/include/asm-x86_64/socket.h
index b46702607933..90af60cf3c0e 100644
--- a/include/asm-x86_64/socket.h
+++ b/include/asm-x86_64/socket.h
@@ -49,5 +49,7 @@
49 49
50#define SO_PEERSEC 31 50#define SO_PEERSEC 31
51#define SO_PASSSEC 34 51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
52 54
53#endif /* _ASM_SOCKET_H */ 55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-xtensa/socket.h b/include/asm-xtensa/socket.h
index 971d231be60e..1f5aeacb9da2 100644
--- a/include/asm-xtensa/socket.h
+++ b/include/asm-xtensa/socket.h
@@ -60,5 +60,7 @@
60#define SO_ACCEPTCONN 30 60#define SO_ACCEPTCONN 30
61#define SO_PEERSEC 31 61#define SO_PEERSEC 31
62#define SO_PASSSEC 34 62#define SO_PASSSEC 34
63#define SO_TIMESTAMPNS 35
64#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
63 65
64#endif /* _XTENSA_SOCKET_H */ 66#endif /* _XTENSA_SOCKET_H */
diff --git a/include/net/sock.h b/include/net/sock.h
index 51246579592e..390c04700590 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -390,6 +390,7 @@ enum sock_flags {
390 SOCK_USE_WRITE_QUEUE, /* whether to call sk->sk_write_space in sock_wfree */ 390 SOCK_USE_WRITE_QUEUE, /* whether to call sk->sk_write_space in sock_wfree */
391 SOCK_DBG, /* %SO_DEBUG setting */ 391 SOCK_DBG, /* %SO_DEBUG setting */
392 SOCK_RCVTSTAMP, /* %SO_TIMESTAMP setting */ 392 SOCK_RCVTSTAMP, /* %SO_TIMESTAMP setting */
393 SOCK_RCVTSTAMPNS, /* %SO_TIMESTAMPNS setting */
393 SOCK_LOCALROUTE, /* route locally only, %SO_DONTROUTE setting */ 394 SOCK_LOCALROUTE, /* route locally only, %SO_DONTROUTE setting */
394 SOCK_QUEUE_SHRUNK, /* write queue has been shrunk recently */ 395 SOCK_QUEUE_SHRUNK, /* write queue has been shrunk recently */
395}; 396};
@@ -1283,21 +1284,17 @@ static inline int sock_intr_errno(long timeo)
1283 return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; 1284 return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR;
1284} 1285}
1285 1286
1287extern void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
1288 struct sk_buff *skb);
1289
1286static __inline__ void 1290static __inline__ void
1287sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) 1291sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
1288{ 1292{
1289 ktime_t kt = skb->tstamp; 1293 ktime_t kt = skb->tstamp;
1290 1294
1291 if (sock_flag(sk, SOCK_RCVTSTAMP)) { 1295 if (sock_flag(sk, SOCK_RCVTSTAMP))
1292 struct timeval tv; 1296 __sock_recv_timestamp(msg, sk, skb);
1293 /* Race occurred between timestamp enabling and packet 1297 else
1294 receiving. Fill in the current time for now. */
1295 if (kt.tv64 == 0)
1296 kt = ktime_get_real();
1297 skb->tstamp = kt;
1298 tv = ktime_to_timeval(kt);
1299 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP, sizeof(tv), &tv);
1300 } else
1301 sk->sk_stamp = kt; 1298 sk->sk_stamp = kt;
1302} 1299}
1303 1300
diff --git a/net/compat.c b/net/compat.c
index 0e407563ae85..9a0f5f2b90c8 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -215,6 +215,7 @@ Efault:
215int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data) 215int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
216{ 216{
217 struct compat_timeval ctv; 217 struct compat_timeval ctv;
218 struct compat_timespec cts;
218 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control; 219 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
219 struct compat_cmsghdr cmhdr; 220 struct compat_cmsghdr cmhdr;
220 int cmlen; 221 int cmlen;
@@ -229,7 +230,14 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
229 ctv.tv_sec = tv->tv_sec; 230 ctv.tv_sec = tv->tv_sec;
230 ctv.tv_usec = tv->tv_usec; 231 ctv.tv_usec = tv->tv_usec;
231 data = &ctv; 232 data = &ctv;
232 len = sizeof(struct compat_timeval); 233 len = sizeof(ctv);
234 }
235 if (level == SOL_SOCKET && type == SO_TIMESTAMPNS) {
236 struct timespec *ts = (struct timespec *)data;
237 cts.tv_sec = ts->tv_sec;
238 cts.tv_nsec = ts->tv_nsec;
239 data = &cts;
240 len = sizeof(cts);
233 } 241 }
234 242
235 cmlen = CMSG_COMPAT_LEN(len); 243 cmlen = CMSG_COMPAT_LEN(len);
diff --git a/net/core/sock.c b/net/core/sock.c
index 792ae39804a2..f9e6991d3729 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -521,11 +521,18 @@ set_rcvbuf:
521 break; 521 break;
522 522
523 case SO_TIMESTAMP: 523 case SO_TIMESTAMP:
524 case SO_TIMESTAMPNS:
524 if (valbool) { 525 if (valbool) {
526 if (optname == SO_TIMESTAMP)
527 sock_reset_flag(sk, SOCK_RCVTSTAMPNS);
528 else
529 sock_set_flag(sk, SOCK_RCVTSTAMPNS);
525 sock_set_flag(sk, SOCK_RCVTSTAMP); 530 sock_set_flag(sk, SOCK_RCVTSTAMP);
526 sock_enable_timestamp(sk); 531 sock_enable_timestamp(sk);
527 } else 532 } else {
528 sock_reset_flag(sk, SOCK_RCVTSTAMP); 533 sock_reset_flag(sk, SOCK_RCVTSTAMP);
534 sock_reset_flag(sk, SOCK_RCVTSTAMPNS);
535 }
529 break; 536 break;
530 537
531 case SO_RCVLOWAT: 538 case SO_RCVLOWAT:
@@ -715,7 +722,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
715 break; 722 break;
716 723
717 case SO_TIMESTAMP: 724 case SO_TIMESTAMP:
718 v.val = sock_flag(sk, SOCK_RCVTSTAMP); 725 v.val = sock_flag(sk, SOCK_RCVTSTAMP) &&
726 !sock_flag(sk, SOCK_RCVTSTAMPNS);
727 break;
728
729 case SO_TIMESTAMPNS:
730 v.val = sock_flag(sk, SOCK_RCVTSTAMPNS);
719 break; 731 break;
720 732
721 case SO_RCVTIMEO: 733 case SO_RCVTIMEO:
diff --git a/net/socket.c b/net/socket.c
index cf18c5eb592e..a7bd0df115b2 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -585,6 +585,35 @@ int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
585 return result; 585 return result;
586} 586}
587 587
588/*
589 * called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP)
590 */
591void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
592 struct sk_buff *skb)
593{
594 ktime_t kt = skb->tstamp;
595
596 if (!sock_flag(sk, SOCK_RCVTSTAMPNS)) {
597 struct timeval tv;
598 /* Race occurred between timestamp enabling and packet
599 receiving. Fill in the current time for now. */
600 if (kt.tv64 == 0)
601 kt = ktime_get_real();
602 skb->tstamp = kt;
603 tv = ktime_to_timeval(kt);
604 put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP, sizeof(tv), &tv);
605 } else {
606 struct timespec ts;
607 /* Race occurred between timestamp enabling and packet
608 receiving. Fill in the current time for now. */
609 if (kt.tv64 == 0)
610 kt = ktime_get_real();
611 skb->tstamp = kt;
612 ts = ktime_to_timespec(kt);
613 put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPNS, sizeof(ts), &ts);
614 }
615}
616
588static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock, 617static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
589 struct msghdr *msg, size_t size, int flags) 618 struct msghdr *msg, size_t size, int flags)
590{ 619{