diff options
author | Arnd Bergmann <arnd@arndb.de> | 2019-04-17 16:51:48 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-04-19 17:07:40 -0400 |
commit | c7cbdbf29f488a19982cd9f4a109887f18028bbb (patch) | |
tree | 74b39321c14b93411eda0939683dc9b8b713717b /net/socket.c | |
parent | 1ab839281cf72476988901a2606378d76530f99c (diff) |
net: rework SIOCGSTAMP ioctl handling
The SIOCGSTAMP/SIOCGSTAMPNS ioctl commands are implemented by many
socket protocol handlers, and all of those end up calling the same
sock_get_timestamp()/sock_get_timestampns() helper functions, which
results in a lot of duplicate code.
With the introduction of 64-bit time_t on 32-bit architectures, this
gets worse, as we then need four different ioctl commands in each
socket protocol implementation.
To simplify that, let's add a new .gettstamp() operation in
struct proto_ops, and move ioctl implementation into the common
sock_ioctl()/compat_sock_ioctl_trans() functions that these all go
through.
We can reuse the sock_get_timestamp() implementation, but generalize
it so it can deal with both native and compat mode, as well as
timeval and timespec structures.
Acked-by: Stefan Schmidt <stefan@datenfreihafen.org>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/lkml/CAK8P3a038aDQQotzua_QtKGhq8O9n+rdiz2=WDCp82ys8eUT+A@mail.gmail.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/net/socket.c b/net/socket.c index 8255f5bda0aa..ab624d42ead5 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -1164,6 +1164,15 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |||
1164 | 1164 | ||
1165 | err = open_related_ns(&net->ns, get_net_ns); | 1165 | err = open_related_ns(&net->ns, get_net_ns); |
1166 | break; | 1166 | break; |
1167 | case SIOCGSTAMP: | ||
1168 | case SIOCGSTAMPNS: | ||
1169 | if (!sock->ops->gettstamp) { | ||
1170 | err = -ENOIOCTLCMD; | ||
1171 | break; | ||
1172 | } | ||
1173 | err = sock->ops->gettstamp(sock, argp, | ||
1174 | cmd == SIOCGSTAMP, false); | ||
1175 | break; | ||
1167 | default: | 1176 | default: |
1168 | err = sock_do_ioctl(net, sock, cmd, arg); | 1177 | err = sock_do_ioctl(net, sock, cmd, arg); |
1169 | break; | 1178 | break; |
@@ -2916,38 +2925,6 @@ void socket_seq_show(struct seq_file *seq) | |||
2916 | #endif /* CONFIG_PROC_FS */ | 2925 | #endif /* CONFIG_PROC_FS */ |
2917 | 2926 | ||
2918 | #ifdef CONFIG_COMPAT | 2927 | #ifdef CONFIG_COMPAT |
2919 | static int do_siocgstamp(struct net *net, struct socket *sock, | ||
2920 | unsigned int cmd, void __user *up) | ||
2921 | { | ||
2922 | mm_segment_t old_fs = get_fs(); | ||
2923 | struct timeval ktv; | ||
2924 | int err; | ||
2925 | |||
2926 | set_fs(KERNEL_DS); | ||
2927 | err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv); | ||
2928 | set_fs(old_fs); | ||
2929 | if (!err) | ||
2930 | err = compat_put_timeval(&ktv, up); | ||
2931 | |||
2932 | return err; | ||
2933 | } | ||
2934 | |||
2935 | static int do_siocgstampns(struct net *net, struct socket *sock, | ||
2936 | unsigned int cmd, void __user *up) | ||
2937 | { | ||
2938 | mm_segment_t old_fs = get_fs(); | ||
2939 | struct timespec kts; | ||
2940 | int err; | ||
2941 | |||
2942 | set_fs(KERNEL_DS); | ||
2943 | err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts); | ||
2944 | set_fs(old_fs); | ||
2945 | if (!err) | ||
2946 | err = compat_put_timespec(&kts, up); | ||
2947 | |||
2948 | return err; | ||
2949 | } | ||
2950 | |||
2951 | static int compat_dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) | 2928 | static int compat_dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) |
2952 | { | 2929 | { |
2953 | struct compat_ifconf ifc32; | 2930 | struct compat_ifconf ifc32; |
@@ -3348,9 +3325,12 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock, | |||
3348 | case SIOCDELRT: | 3325 | case SIOCDELRT: |
3349 | return routing_ioctl(net, sock, cmd, argp); | 3326 | return routing_ioctl(net, sock, cmd, argp); |
3350 | case SIOCGSTAMP: | 3327 | case SIOCGSTAMP: |
3351 | return do_siocgstamp(net, sock, cmd, argp); | ||
3352 | case SIOCGSTAMPNS: | 3328 | case SIOCGSTAMPNS: |
3353 | return do_siocgstampns(net, sock, cmd, argp); | 3329 | if (!sock->ops->gettstamp) |
3330 | return -ENOIOCTLCMD; | ||
3331 | return sock->ops->gettstamp(sock, argp, cmd == SIOCGSTAMP, | ||
3332 | !COMPAT_USE_64BIT_TIME); | ||
3333 | |||
3354 | case SIOCBONDSLAVEINFOQUERY: | 3334 | case SIOCBONDSLAVEINFOQUERY: |
3355 | case SIOCBONDINFOQUERY: | 3335 | case SIOCBONDINFOQUERY: |
3356 | case SIOCSHWTSTAMP: | 3336 | case SIOCSHWTSTAMP: |