From: Christoph Hellwig <hch@lst.de>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>,
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
Jon Maloy <jmaloy@redhat.com>, Ying Xue <ying.xue@windriver.com>,
drbd-dev@lists.linbit.com, linux-kernel@vger.kernel.org,
linux-rdma@vger.kernel.org, linux-nvme@lists.infradead.org,
target-devel@vger.kernel.org, linux-afs@lists.infradead.org,
linux-cifs@vger.kernel.org, cluster-devel@redhat.com,
ocfs2-devel@oss.oracle.com, netdev@vger.kernel.org,
ceph-devel@vger.kernel.org, rds-devel@oss.oracle.com,
linux-nfs@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
David Howells <dhowells@redhat.com>
Subject: [PATCH 21/28] ipv4: add ip_sock_set_mtu_discover
Date: Thu, 28 May 2020 07:12:29 +0200 [thread overview]
Message-ID: <20200528051236.620353-22-hch@lst.de> (raw)
In-Reply-To: <20200528051236.620353-1-hch@lst.de>
Add a helper to directly set the IP_MTU_DISCOVER sockopt from kernel
space without going through a fake uaccess.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Howells <dhowells@redhat.com> [rxrpc bits]
---
include/net/ip.h | 1 +
net/ipv4/ip_sockglue.c | 11 +++++++++++
net/rxrpc/local_object.c | 8 +-------
net/rxrpc/output.c | 14 +++++---------
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/include/net/ip.h b/include/net/ip.h
index f063a491b9063..d3649c49dd333 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -766,6 +766,7 @@ static inline bool inetdev_valid_mtu(unsigned int mtu)
}
void ip_sock_set_freebind(struct sock *sk);
+int ip_sock_set_mtu_discover(struct sock *sk, int val);
void ip_sock_set_recverr(struct sock *sk);
void ip_sock_set_tos(struct sock *sk, int val);
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index aca6b81da9bae..aa115be11dcfb 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -597,6 +597,17 @@ void ip_sock_set_recverr(struct sock *sk)
}
EXPORT_SYMBOL(ip_sock_set_recverr);
+int ip_sock_set_mtu_discover(struct sock *sk, int val)
+{
+ if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT)
+ return -EINVAL;
+ lock_sock(sk);
+ inet_sk(sk)->pmtudisc = val;
+ release_sock(sk);
+ return 0;
+}
+EXPORT_SYMBOL(ip_sock_set_mtu_discover);
+
/*
* Socket option code for IP. This is the end of the line after any
* TCP,UDP etc options on an IP socket.
diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
index 4c0e8fe5ec1fb..6f4e6b4817cf2 100644
--- a/net/rxrpc/local_object.c
+++ b/net/rxrpc/local_object.c
@@ -174,13 +174,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
ip_sock_set_recverr(local->socket->sk);
/* we want to set the don't fragment bit */
- opt = IP_PMTUDISC_DO;
- ret = kernel_setsockopt(local->socket, SOL_IP, IP_MTU_DISCOVER,
- (char *) &opt, sizeof(opt));
- if (ret < 0) {
- _debug("setsockopt failed");
- goto error;
- }
+ ip_sock_set_mtu_discover(local->socket->sk, IP_PMTUDISC_DO);
/* We want receive timestamps. */
sock_enable_timestamps(local->socket->sk);
diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c
index f8b632a5c6197..1ba43c3df4adb 100644
--- a/net/rxrpc/output.c
+++ b/net/rxrpc/output.c
@@ -321,7 +321,7 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
struct kvec iov[2];
rxrpc_serial_t serial;
size_t len;
- int ret, opt;
+ int ret;
_enter(",{%d}", skb->len);
@@ -473,18 +473,14 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
switch (conn->params.local->srx.transport.family) {
case AF_INET6:
case AF_INET:
- opt = IP_PMTUDISC_DONT;
- kernel_setsockopt(conn->params.local->socket,
- SOL_IP, IP_MTU_DISCOVER,
- (char *)&opt, sizeof(opt));
+ ip_sock_set_mtu_discover(conn->params.local->socket->sk,
+ IP_PMTUDISC_DONT);
ret = kernel_sendmsg(conn->params.local->socket, &msg,
iov, 2, len);
conn->params.peer->last_tx_at = ktime_get_seconds();
- opt = IP_PMTUDISC_DO;
- kernel_setsockopt(conn->params.local->socket,
- SOL_IP, IP_MTU_DISCOVER,
- (char *)&opt, sizeof(opt));
+ ip_sock_set_mtu_discover(conn->params.local->socket->sk,
+ IP_PMTUDISC_DO);
break;
default:
--
2.26.2
next prev parent reply other threads:[~2020-05-28 5:15 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-28 5:12 remove most callers of kernel_setsockopt v3 Christoph Hellwig
2020-05-28 5:12 ` [PATCH 01/28] net: add sock_set_reuseaddr Christoph Hellwig
2020-05-28 5:12 ` [PATCH 02/28] net: add sock_no_linger Christoph Hellwig
2020-05-28 5:12 ` [PATCH 03/28] net: add sock_set_priority Christoph Hellwig
2020-05-28 5:12 ` [PATCH 04/28] net: add sock_set_sndtimeo Christoph Hellwig
2020-05-28 5:12 ` [PATCH 05/28] net: add sock_bindtoindex Christoph Hellwig
2020-05-28 5:12 ` [PATCH 06/28] net: add sock_enable_timestamps Christoph Hellwig
2020-05-28 5:12 ` [PATCH 07/28] net: add sock_set_keepalive Christoph Hellwig
2020-05-28 5:12 ` [PATCH 08/28] net: add sock_set_rcvbuf Christoph Hellwig
2020-05-28 5:12 ` [PATCH 09/28] net: add sock_set_reuseport Christoph Hellwig
2020-05-28 5:12 ` [PATCH 10/28] tcp: add tcp_sock_set_cork Christoph Hellwig
2020-05-28 5:12 ` [PATCH 11/28] tcp: add tcp_sock_set_nodelay Christoph Hellwig
2020-05-28 5:12 ` [PATCH 12/28] tcp: add tcp_sock_set_quickack Christoph Hellwig
2020-05-28 5:12 ` [PATCH 13/28] tcp: add tcp_sock_set_syncnt Christoph Hellwig
2020-05-28 5:12 ` [PATCH 14/28] tcp: add tcp_sock_set_user_timeout Christoph Hellwig
2020-05-28 5:12 ` [PATCH 15/28] tcp: add tcp_sock_set_keepidle Christoph Hellwig
2020-05-28 5:12 ` [PATCH 16/28] tcp: add tcp_sock_set_keepintvl Christoph Hellwig
2020-05-28 5:12 ` [PATCH 17/28] tcp: add tcp_sock_set_keepcnt Christoph Hellwig
2020-05-28 5:12 ` [PATCH 18/28] ipv4: add ip_sock_set_tos Christoph Hellwig
2020-05-28 5:12 ` [PATCH 19/28] ipv4: add ip_sock_set_freebind Christoph Hellwig
2020-05-28 5:12 ` [PATCH 20/28] ipv4: add ip_sock_set_recverr Christoph Hellwig
2020-05-28 5:12 ` Christoph Hellwig [this message]
2020-05-28 5:12 ` [PATCH 22/28] ipv4: add ip_sock_set_pktinfo Christoph Hellwig
2020-05-28 5:12 ` [PATCH 23/28] ipv6: add ip6_sock_set_v6only Christoph Hellwig
2020-05-28 5:12 ` [PATCH 24/28] ipv6: add ip6_sock_set_recverr Christoph Hellwig
2020-05-28 5:12 ` [PATCH 25/28] ipv6: add ip6_sock_set_addr_preferences Christoph Hellwig
2020-05-28 5:12 ` [PATCH 26/28] ipv6: add ip6_sock_set_recvpktinfo Christoph Hellwig
2020-05-28 5:12 ` [PATCH 27/28] rxrpc: add rxrpc_sock_set_min_security_level Christoph Hellwig
2020-05-28 5:12 ` [PATCH 28/28] tipc: call tsk_set_importance from tipc_topsrv_create_listener Christoph Hellwig
2020-05-28 18:12 ` remove most callers of kernel_setsockopt v3 David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200528051236.620353-22-hch@lst.de \
--to=hch@lst.de \
--cc=ceph-devel@vger.kernel.org \
--cc=cluster-devel@redhat.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=drbd-dev@lists.linbit.com \
--cc=edumazet@google.com \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-afs@lists.infradead.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ocfs2-devel@oss.oracle.com \
--cc=rds-devel@oss.oracle.com \
--cc=target-devel@vger.kernel.org \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=ying.xue@windriver.com \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).