diff mbox series

[v3,mptcp-next,1/7] sock: expose so_timestamp options for mptcp

Message ID 20210514094857.10663-2-fw@strlen.de (mailing list archive)
State Accepted, archived
Commit 480085ab2b4f44609014bf815a7f1201e0c58b71
Delegated to: Matthieu Baerts
Headers show
Series add cmsg support to receive path | expand

Commit Message

Florian Westphal May 14, 2021, 9:48 a.m. UTC
This exports SO_TIMESTAMP_* function for re-use by MPTCP.

Without this there is too much copy & paste needed to support
this from mptcp setsockopt path.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 include/net/sock.h |  1 +
 net/core/sock.c    | 26 +++++++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)

Comments

Mat Martineau May 14, 2021, 7:05 p.m. UTC | #1
On Fri, 14 May 2021, Florian Westphal wrote:

> This exports SO_TIMESTAMP_* function for re-use by MPTCP.
>
> Without this there is too much copy & paste needed to support
> this from mptcp setsockopt path.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> include/net/sock.h |  1 +
> net/core/sock.c    | 26 +++++++++++++++++++-------
> 2 files changed, 20 insertions(+), 7 deletions(-)
>

Acked-by: Mat Martineau <mathew.j.martineau@linux.intel.com>

--
Mat Martineau
Intel
diff mbox series

Patch

diff --git a/include/net/sock.h b/include/net/sock.h
index 42bc5e1a627f..7ee2347846b6 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2741,6 +2741,7 @@  static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
 void sock_def_readable(struct sock *sk);
 
 int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk);
+void sock_set_timestamp(struct sock *sk, int optname, bool valbool);
 void sock_enable_timestamps(struct sock *sk);
 void sock_no_linger(struct sock *sk);
 void sock_set_keepalive(struct sock *sk);
diff --git a/net/core/sock.c b/net/core/sock.c
index c761c4a0b66b..294b5a9bf520 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -776,6 +776,24 @@  void sock_enable_timestamps(struct sock *sk)
 }
 EXPORT_SYMBOL(sock_enable_timestamps);
 
+void sock_set_timestamp(struct sock *sk, int optname, bool valbool)
+{
+	switch (optname) {
+	case SO_TIMESTAMP_OLD:
+		__sock_set_timestamps(sk, valbool, false, false);
+		break;
+	case SO_TIMESTAMP_NEW:
+		__sock_set_timestamps(sk, valbool, true, false);
+		break;
+	case SO_TIMESTAMPNS_OLD:
+		__sock_set_timestamps(sk, valbool, false, true);
+		break;
+	case SO_TIMESTAMPNS_NEW:
+		__sock_set_timestamps(sk, valbool, true, true);
+		break;
+	}
+}
+
 void sock_set_keepalive(struct sock *sk)
 {
 	lock_sock(sk);
@@ -989,16 +1007,10 @@  int sock_setsockopt(struct socket *sock, int level, int optname,
 		break;
 
 	case SO_TIMESTAMP_OLD:
-		__sock_set_timestamps(sk, valbool, false, false);
-		break;
 	case SO_TIMESTAMP_NEW:
-		__sock_set_timestamps(sk, valbool, true, false);
-		break;
 	case SO_TIMESTAMPNS_OLD:
-		__sock_set_timestamps(sk, valbool, false, true);
-		break;
 	case SO_TIMESTAMPNS_NEW:
-		__sock_set_timestamps(sk, valbool, true, true);
+		sock_set_timestamp(sk, valbool, optname);
 		break;
 	case SO_TIMESTAMPING_NEW:
 	case SO_TIMESTAMPING_OLD: