ipv4: add ip_sock_set_recverr
authorChristoph Hellwig <hch@lst.de>
Thu, 28 May 2020 05:12:28 +0000 (07:12 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 28 May 2020 18:11:45 +0000 (11:11 -0700)
Add a helper to directly set the IP_RECVERR 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>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
net/ipv4/ip_sockglue.c
net/rxrpc/local_object.c

index 5f5d822..f063a49 100644 (file)
@@ -766,6 +766,7 @@ static inline bool inetdev_valid_mtu(unsigned int mtu)
 }
 
 void ip_sock_set_freebind(struct sock *sk);
+void ip_sock_set_recverr(struct sock *sk);
 void ip_sock_set_tos(struct sock *sk, int val);
 
 #endif /* _IP_H */
index 767838d..aca6b81 100644 (file)
@@ -589,6 +589,14 @@ void ip_sock_set_freebind(struct sock *sk)
 }
 EXPORT_SYMBOL(ip_sock_set_freebind);
 
+void ip_sock_set_recverr(struct sock *sk)
+{
+       lock_sock(sk);
+       inet_sk(sk)->recverr = true;
+       release_sock(sk);
+}
+EXPORT_SYMBOL(ip_sock_set_recverr);
+
 /*
  *     Socket option code for IP. This is the end of the line after any
  *     TCP,UDP etc options on an IP socket.
index 5ea2bd0..4c0e8fe 100644 (file)
@@ -171,13 +171,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
                /* Fall through */
        case AF_INET:
                /* we want to receive ICMP errors */
-               opt = 1;
-               ret = kernel_setsockopt(local->socket, SOL_IP, IP_RECVERR,
-                                       (char *) &opt, sizeof(opt));
-               if (ret < 0) {
-                       _debug("setsockopt failed");
-                       goto error;
-               }
+               ip_sock_set_recverr(local->socket->sk);
 
                /* we want to set the don't fragment bit */
                opt = IP_PMTUDISC_DO;