Skip to content

Commit c7cbdbf

Browse files
arndbdavem330
authored andcommitted
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>
1 parent 1ab8392 commit c7cbdbf

33 files changed

Lines changed: 75 additions & 232 deletions

File tree

‎include/linux/net.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ struct proto_ops {
161161
int (*compat_ioctl) (struct socket *sock, unsigned int cmd,
162162
unsigned long arg);
163163
#endif
164+
int (*gettstamp) (struct socket *sock, void __user *userstamp,
165+
bool timeval, bool time32);
164166
int (*listen) (struct socket *sock, int len);
165167
int (*shutdown) (struct socket *sock, int flags);
166168
int (*setsockopt)(struct socket *sock, int level,

‎include/net/compat.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ struct compat_cmsghdr {
3030
compat_int_t cmsg_type;
3131
};
3232

33-
int compat_sock_get_timestamp(struct sock *, struct timeval __user *);
34-
int compat_sock_get_timestampns(struct sock *, struct timespec __user *);
35-
3633
#else /* defined(CONFIG_COMPAT) */
3734
/*
3835
* To avoid compiler warnings:

‎include/net/sock.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,8 @@ int sock_setsockopt(struct socket *sock, int level, int op,
16141614

16151615
int sock_getsockopt(struct socket *sock, int level, int op,
16161616
char __user *optval, int __user *optlen);
1617+
int sock_gettstamp(struct socket *sock, void __user *userstamp,
1618+
bool timeval, bool time32);
16171619
struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size,
16181620
int noblock, int *errcode);
16191621
struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
@@ -2503,8 +2505,6 @@ static inline bool sk_listener(const struct sock *sk)
25032505
}
25042506

25052507
void sock_enable_timestamp(struct sock *sk, int flag);
2506-
int sock_get_timestamp(struct sock *, struct timeval __user *);
2507-
int sock_get_timestampns(struct sock *, struct timespec __user *);
25082508
int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, int level,
25092509
int type);
25102510

‎net/appletalk/ddp.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,12 +1806,6 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
18061806
rc = put_user(amount, (int __user *)argp);
18071807
break;
18081808
}
1809-
case SIOCGSTAMP:
1810-
rc = sock_get_timestamp(sk, argp);
1811-
break;
1812-
case SIOCGSTAMPNS:
1813-
rc = sock_get_timestampns(sk, argp);
1814-
break;
18151809
/* Routing */
18161810
case SIOCADDRT:
18171811
case SIOCDELRT:
@@ -1871,6 +1865,7 @@ static const struct proto_ops atalk_dgram_ops = {
18711865
.getname = atalk_getname,
18721866
.poll = datagram_poll,
18731867
.ioctl = atalk_ioctl,
1868+
.gettstamp = sock_gettstamp,
18741869
#ifdef CONFIG_COMPAT
18751870
.compat_ioctl = atalk_compat_ioctl,
18761871
#endif

‎net/atm/ioctl.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,6 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
8181
(int __user *)argp) ? -EFAULT : 0;
8282
goto done;
8383
}
84-
case SIOCGSTAMP: /* borrowed from IP */
85-
#ifdef CONFIG_COMPAT
86-
if (compat)
87-
error = compat_sock_get_timestamp(sk, argp);
88-
else
89-
#endif
90-
error = sock_get_timestamp(sk, argp);
91-
goto done;
92-
case SIOCGSTAMPNS: /* borrowed from IP */
93-
#ifdef CONFIG_COMPAT
94-
if (compat)
95-
error = compat_sock_get_timestampns(sk, argp);
96-
else
97-
#endif
98-
error = sock_get_timestampns(sk, argp);
99-
goto done;
10084
case ATM_SETSC:
10185
net_warn_ratelimited("ATM_SETSC is obsolete; used by %s:%d\n",
10286
current->comm, task_pid_nr(current));

‎net/atm/pvc.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static const struct proto_ops pvc_proto_ops = {
118118
#ifdef CONFIG_COMPAT
119119
.compat_ioctl = vcc_compat_ioctl,
120120
#endif
121+
.gettstamp = sock_gettstamp,
121122
.listen = sock_no_listen,
122123
.shutdown = pvc_shutdown,
123124
.setsockopt = pvc_setsockopt,

‎net/atm/svc.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static const struct proto_ops svc_proto_ops = {
641641
#ifdef CONFIG_COMPAT
642642
.compat_ioctl = svc_compat_ioctl,
643643
#endif
644+
.gettstamp = sock_gettstamp,
644645
.listen = svc_listen,
645646
.shutdown = svc_shutdown,
646647
.setsockopt = svc_setsockopt,

‎net/ax25/af_ax25.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,14 +1714,6 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
17141714
break;
17151715
}
17161716

1717-
case SIOCGSTAMP:
1718-
res = sock_get_timestamp(sk, argp);
1719-
break;
1720-
1721-
case SIOCGSTAMPNS:
1722-
res = sock_get_timestampns(sk, argp);
1723-
break;
1724-
17251717
case SIOCAX25ADDUID: /* Add a uid to the uid/call map table */
17261718
case SIOCAX25DELUID: /* Delete a uid from the uid/call map table */
17271719
case SIOCAX25GETUID: {
@@ -1950,6 +1942,7 @@ static const struct proto_ops ax25_proto_ops = {
19501942
.getname = ax25_getname,
19511943
.poll = datagram_poll,
19521944
.ioctl = ax25_ioctl,
1945+
.gettstamp = sock_gettstamp,
19531946
.listen = ax25_listen,
19541947
.shutdown = ax25_shutdown,
19551948
.setsockopt = ax25_setsockopt,

‎net/bluetooth/af_bluetooth.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,6 @@ int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
521521
err = put_user(amount, (int __user *) arg);
522522
break;
523523

524-
case SIOCGSTAMP:
525-
err = sock_get_timestamp(sk, (struct timeval __user *) arg);
526-
break;
527-
528-
case SIOCGSTAMPNS:
529-
err = sock_get_timestampns(sk, (struct timespec __user *) arg);
530-
break;
531-
532524
default:
533525
err = -ENOIOCTLCMD;
534526
break;

‎net/bluetooth/l2cap_sock.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ static const struct proto_ops l2cap_sock_ops = {
16551655
.recvmsg = l2cap_sock_recvmsg,
16561656
.poll = bt_sock_poll,
16571657
.ioctl = bt_sock_ioctl,
1658+
.gettstamp = sock_gettstamp,
16581659
.mmap = sock_no_mmap,
16591660
.socketpair = sock_no_socketpair,
16601661
.shutdown = l2cap_sock_shutdown,

0 commit comments

Comments
 (0)