mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 06:34:12 +08:00
[NET]: Introduce SIOCGSTAMPNS ioctl to get timestamps with nanosec resolution
Now network timestamps use ktime_t infrastructure, we can add a new ioctl() SIOCGSTAMPNS command to get timestamps in 'struct timespec'. User programs can thus access to nanosecond resolution. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> CC: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
cb69cc5236
commit
ae40eb1ef3
@ -266,6 +266,23 @@ static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
|
||||
return err;
|
||||
}
|
||||
|
||||
static int do_siocgstampns(unsigned int fd, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
struct compat_timespec __user *up = compat_ptr(arg);
|
||||
struct timespec kts;
|
||||
mm_segment_t old_fs = get_fs();
|
||||
int err;
|
||||
|
||||
set_fs(KERNEL_DS);
|
||||
err = sys_ioctl(fd, cmd, (unsigned long)&kts);
|
||||
set_fs(old_fs);
|
||||
if (!err) {
|
||||
err = put_user(kts.tv_sec, &up->tv_sec);
|
||||
err |= __put_user(kts.tv_nsec, &up->tv_nsec);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
struct ifmap32 {
|
||||
compat_ulong_t mem_start;
|
||||
compat_ulong_t mem_end;
|
||||
@ -2437,6 +2454,7 @@ HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
|
||||
/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
|
||||
HANDLE_IOCTL(SIOCRTMSG, ret_einval)
|
||||
HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
|
||||
HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
|
||||
#endif
|
||||
#ifdef CONFIG_BLOCK
|
||||
HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
|
||||
|
@ -10,6 +10,7 @@
|
||||
#define SIOCSPGRP _IOW('s', 8, pid_t)
|
||||
#define SIOCGPGRP _IOR('s', 9, pid_t)
|
||||
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp - linux-specific */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _ASM_ALPHA_SOCKIOS_H */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* __ASM_AVR32_SOCKIOS_H */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -7,7 +7,8 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _ASM_SOCKIOS__ */
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* __ARCH_H8300_SOCKIOS__ */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _ASM_IA64_SOCKIOS_H */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _ASM_M32R_SOCKIOS_H */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* __ARCH_M68K_SOCKIOS__ */
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define SIOCSPGRP _IOW('s', 8, pid_t)
|
||||
#define SIOCGPGRP _IOR('s', 9, pid_t)
|
||||
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp - linux-specific */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _ASM_SOCKIOS_H */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _ASM_POWERPC_SOCKIOS_H */
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -9,5 +9,6 @@
|
||||
#define SIOCSPGRP _IOW('s', 8, pid_t)
|
||||
#define SIOCGPGRP _IOR('s', 9, pid_t)
|
||||
|
||||
#define SIOCGSTAMP _IOR('s', 100, struct timeval) /* Get stamp - linux-specific */
|
||||
#define SIOCGSTAMP _IOR('s', 100, struct timeval) /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS _IOR('s', 101, struct timespec) /* Get stamp (timespec) */
|
||||
#endif /* __ASM_SH_SOCKIOS_H */
|
||||
|
@ -20,5 +20,6 @@
|
||||
#define SIOCSPGRP _IOW('s', 8, pid_t)
|
||||
#define SIOCGPGRP _IOR('s', 9, pid_t)
|
||||
|
||||
#define SIOCGSTAMP _IOR('s', 100, struct timeval) /* Get stamp - linux-specific */
|
||||
#define SIOCGSTAMP _IOR('s', 100, struct timeval) /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS _IOR('s', 101, struct timespec) /* Get stamp (timespec) */
|
||||
#endif /* __ASM_SH64_SOCKIOS_H */
|
||||
|
@ -7,7 +7,8 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* !(_ASM_SPARC_SOCKIOS_H) */
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* !(_ASM_SPARC64_SOCKIOS_H) */
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* __V850_SOCKIOS_H__ */
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define SIOCSPGRP _IOW('s', 8, pid_t)
|
||||
#define SIOCGPGRP _IOR('s', 9, pid_t)
|
||||
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp - linux-specific */
|
||||
#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */
|
||||
#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
|
||||
|
||||
#endif /* _XTENSA_SOCKIOS_H */
|
||||
|
@ -25,6 +25,7 @@ struct compat_cmsghdr {
|
||||
};
|
||||
|
||||
extern int compat_sock_get_timestamp(struct sock *, struct timeval __user *);
|
||||
extern int compat_sock_get_timestampns(struct sock *, struct timespec __user *);
|
||||
|
||||
#else /* defined(CONFIG_COMPAT) */
|
||||
#define compat_msghdr msghdr /* to avoid compiler warnings */
|
||||
|
@ -1329,6 +1329,7 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_e
|
||||
|
||||
extern void sock_enable_timestamp(struct sock *sk);
|
||||
extern int sock_get_timestamp(struct sock *, struct timeval __user *);
|
||||
extern int sock_get_timestampns(struct sock *, struct timespec __user *);
|
||||
|
||||
/*
|
||||
* Enable debug/info messages
|
||||
|
@ -1771,6 +1771,9 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
case SIOCGSTAMP:
|
||||
rc = sock_get_timestamp(sk, argp);
|
||||
break;
|
||||
case SIOCGSTAMPNS:
|
||||
rc = sock_get_timestampns(sk, argp);
|
||||
break;
|
||||
/* Routing */
|
||||
case SIOCADDRT:
|
||||
case SIOCDELRT:
|
||||
|
@ -82,6 +82,9 @@ int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
case SIOCGSTAMP: /* borrowed from IP */
|
||||
error = sock_get_timestamp(sk, argp);
|
||||
goto done;
|
||||
case SIOCGSTAMPNS: /* borrowed from IP */
|
||||
error = sock_get_timestampns(sk, argp);
|
||||
goto done;
|
||||
case ATM_SETSC:
|
||||
printk(KERN_WARNING "ATM_SETSC is obsolete\n");
|
||||
error = 0;
|
||||
|
@ -1711,6 +1711,10 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
res = sock_get_timestamp(sk, argp);
|
||||
break;
|
||||
|
||||
case SIOCGSTAMPNS:
|
||||
res = sock_get_timestampns(sk, argp);
|
||||
break;
|
||||
|
||||
case SIOCAX25ADDUID: /* Add a uid to the uid/call map table */
|
||||
case SIOCAX25DELUID: /* Delete a uid from the uid/call map table */
|
||||
case SIOCAX25GETUID: {
|
||||
|
24
net/compat.c
24
net/compat.c
@ -564,6 +564,30 @@ int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
|
||||
}
|
||||
EXPORT_SYMBOL(compat_sock_get_timestamp);
|
||||
|
||||
int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
|
||||
{
|
||||
struct compat_timespec __user *ctv =
|
||||
(struct compat_timespec __user*) userstamp;
|
||||
int err = -ENOENT;
|
||||
struct timespec ts;
|
||||
|
||||
if (!sock_flag(sk, SOCK_TIMESTAMP))
|
||||
sock_enable_timestamp(sk);
|
||||
ts = ktime_to_timespec(sk->sk_stamp);
|
||||
if (ts.tv_sec == -1)
|
||||
return err;
|
||||
if (ts.tv_sec == 0) {
|
||||
sk->sk_stamp = ktime_get_real();
|
||||
ts = ktime_to_timespec(sk->sk_stamp);
|
||||
}
|
||||
err = 0;
|
||||
if (put_user(ts.tv_sec, &ctv->tv_sec) ||
|
||||
put_user(ts.tv_nsec, &ctv->tv_nsec))
|
||||
err = -EFAULT;
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(compat_sock_get_timestampns);
|
||||
|
||||
asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
|
||||
char __user *optval, int __user *optlen)
|
||||
{
|
||||
|
@ -1567,6 +1567,22 @@ int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
|
||||
}
|
||||
EXPORT_SYMBOL(sock_get_timestamp);
|
||||
|
||||
int sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (!sock_flag(sk, SOCK_TIMESTAMP))
|
||||
sock_enable_timestamp(sk);
|
||||
ts = ktime_to_timespec(sk->sk_stamp);
|
||||
if (ts.tv_sec == -1)
|
||||
return -ENOENT;
|
||||
if (ts.tv_sec == 0) {
|
||||
sk->sk_stamp = ktime_get_real();
|
||||
ts = ktime_to_timespec(sk->sk_stamp);
|
||||
}
|
||||
return copy_to_user(userstamp, &ts, sizeof(ts)) ? -EFAULT : 0;
|
||||
}
|
||||
EXPORT_SYMBOL(sock_get_timestampns);
|
||||
|
||||
void sock_enable_timestamp(struct sock *sk)
|
||||
{
|
||||
if (!sock_flag(sk, SOCK_TIMESTAMP)) {
|
||||
|
@ -727,6 +727,9 @@ static int econet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg
|
||||
case SIOCGSTAMP:
|
||||
return sock_get_timestamp(sk, argp);
|
||||
|
||||
case SIOCGSTAMPNS:
|
||||
return sock_get_timestampns(sk, argp);
|
||||
|
||||
case SIOCSIFADDR:
|
||||
case SIOCGIFADDR:
|
||||
return ec_dev_ioctl(sock, cmd, argp);
|
||||
|
@ -755,6 +755,9 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
case SIOCGSTAMP:
|
||||
err = sock_get_timestamp(sk, (struct timeval __user *)arg);
|
||||
break;
|
||||
case SIOCGSTAMPNS:
|
||||
err = sock_get_timestampns(sk, (struct timespec __user *)arg);
|
||||
break;
|
||||
case SIOCADDRT:
|
||||
case SIOCDELRT:
|
||||
case SIOCRTMSG:
|
||||
|
@ -443,6 +443,9 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
case SIOCGSTAMP:
|
||||
return sock_get_timestamp(sk, (struct timeval __user *)arg);
|
||||
|
||||
case SIOCGSTAMPNS:
|
||||
return sock_get_timestampns(sk, (struct timespec __user *)arg);
|
||||
|
||||
case SIOCADDRT:
|
||||
case SIOCDELRT:
|
||||
|
||||
|
@ -1209,6 +1209,12 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
release_sock(sk);
|
||||
return ret;
|
||||
|
||||
case SIOCGSTAMPNS:
|
||||
lock_sock(sk);
|
||||
ret = sock_get_timestampns(sk, argp);
|
||||
release_sock(sk);
|
||||
return ret;
|
||||
|
||||
case SIOCGIFADDR:
|
||||
case SIOCSIFADDR:
|
||||
case SIOCGIFDSTADDR:
|
||||
|
@ -1545,6 +1545,8 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
|
||||
}
|
||||
case SIOCGSTAMP:
|
||||
return sock_get_timestamp(sk, (struct timeval __user *)arg);
|
||||
case SIOCGSTAMPNS:
|
||||
return sock_get_timestampns(sk, (struct timespec __user *)arg);
|
||||
|
||||
#ifdef CONFIG_INET
|
||||
case SIOCADDRT:
|
||||
|
@ -1296,6 +1296,9 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
case SIOCGSTAMP:
|
||||
return sock_get_timestamp(sk, (struct timeval __user *) argp);
|
||||
|
||||
case SIOCGSTAMPNS:
|
||||
return sock_get_timestampns(sk, (struct timespec __user *) argp);
|
||||
|
||||
case SIOCGIFADDR:
|
||||
case SIOCSIFADDR:
|
||||
case SIOCGIFDSTADDR:
|
||||
|
@ -1280,6 +1280,12 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
||||
rc = sock_get_timestamp(sk,
|
||||
(struct timeval __user *)argp);
|
||||
break;
|
||||
case SIOCGSTAMPNS:
|
||||
rc = -EINVAL;
|
||||
if (sk)
|
||||
rc = sock_get_timestampns(sk,
|
||||
(struct timespec __user *)argp);
|
||||
break;
|
||||
case SIOCGIFADDR:
|
||||
case SIOCSIFADDR:
|
||||
case SIOCGIFDSTADDR:
|
||||
@ -1521,6 +1527,12 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
|
||||
rc = compat_sock_get_timestamp(sk,
|
||||
(struct timeval __user*)argp);
|
||||
break;
|
||||
case SIOCGSTAMPNS:
|
||||
rc = -EINVAL;
|
||||
if (sk)
|
||||
rc = compat_sock_get_timestampns(sk,
|
||||
(struct timespec __user*)argp);
|
||||
break;
|
||||
case SIOCGIFADDR:
|
||||
case SIOCSIFADDR:
|
||||
case SIOCGIFDSTADDR:
|
||||
|
Loading…
Reference in New Issue
Block a user