Message ID | 20200513062649.2100053-21-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/33] net: add sock_set_reuseaddr | expand |
Christoph Hellwig <hch@lst.de> wrote: > Add a helper to directly set the IP_RECVERR sockopt from kernel space > without going through a fake uaccess. It looks like if this is an AF_INET6 socket, it will just pass the message straight through to AF_INET4, so: Reviewed-by: David Howells <dhowells@redhat.com>
On Wed, 2020-05-13 at 08:26 +0200, Christoph Hellwig wrote: > Add a helper to directly set the IP_RECVERR sockopt from kernel space > without going through a fake uaccess. This seems used only with true as the second arg. Is there reason to have that argument at all? > diff --git a/include/net/ip.h b/include/net/ip.h [] > @@ -767,5 +767,6 @@ static inline bool inetdev_valid_mtu(unsigned int mtu) > > void ip_sock_set_tos(struct sock *sk, int val); > void ip_sock_set_freebind(struct sock *sk, bool val); > +void ip_sock_set_recverr(struct sock *sk, bool val); > > #endif /* _IP_H */ > diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c > index 0c40887a817f8..9abecc3195520 100644 > --- a/net/ipv4/ip_sockglue.c > +++ b/net/ipv4/ip_sockglue.c > @@ -589,6 +589,16 @@ void ip_sock_set_freebind(struct sock *sk, bool val) > } > EXPORT_SYMBOL(ip_sock_set_freebind); > > +void ip_sock_set_recverr(struct sock *sk, bool val) > +{ > + lock_sock(sk); > + inet_sk(sk)->recverr = val; > + if (!val) > + skb_queue_purge(&sk->sk_error_queue); > + 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. > diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c > index 562ea36c96b0f..1b87b8a9ff725 100644 > --- a/net/rxrpc/local_object.c > +++ b/net/rxrpc/local_object.c > @@ -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, true); > > /* we want to set the don't fragment bit */ > opt = IP_PMTUDISC_DO;
On Wed, May 13, 2020 at 02:00:43PM -0700, Joe Perches wrote: > On Wed, 2020-05-13 at 08:26 +0200, Christoph Hellwig wrote: > > Add a helper to directly set the IP_RECVERR sockopt from kernel space > > without going through a fake uaccess. > > This seems used only with true as the second arg. > Is there reason to have that argument at all? Mostly to keep it symmetric with the sockopt. I could probably remove a few arguments in the series if we want to be strict.
On Thu, 2020-05-14 at 12:30 +0200, Christoph Hellwig wrote: > On Wed, May 13, 2020 at 02:00:43PM -0700, Joe Perches wrote: > > On Wed, 2020-05-13 at 08:26 +0200, Christoph Hellwig wrote: > > > Add a helper to directly set the IP_RECVERR sockopt from kernel space > > > without going through a fake uaccess. > > > > This seems used only with true as the second arg. > > Is there reason to have that argument at all? > > Mostly to keep it symmetric with the sockopt. I could probably remove > a few arguments in the series if we want to be strict. My preference would use strict and add arguments only when necessary.
On Thu, May 14, 2020 at 04:51:26AM -0700, Joe Perches wrote: > > Mostly to keep it symmetric with the sockopt. I could probably remove > > a few arguments in the series if we want to be strict. > > My preference would use strict and add > arguments only when necessary. In a few cases that would create confusion as the arguments are rather overloaded. But for a lot of the cases where it doesn't and there isn't really much use for other arguments I've done that now.
diff --git a/include/net/ip.h b/include/net/ip.h index 1e2feca8630d0..7ab8140b54429 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -767,5 +767,6 @@ static inline bool inetdev_valid_mtu(unsigned int mtu) void ip_sock_set_tos(struct sock *sk, int val); void ip_sock_set_freebind(struct sock *sk, bool val); +void ip_sock_set_recverr(struct sock *sk, bool val); #endif /* _IP_H */ diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 0c40887a817f8..9abecc3195520 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -589,6 +589,16 @@ void ip_sock_set_freebind(struct sock *sk, bool val) } EXPORT_SYMBOL(ip_sock_set_freebind); +void ip_sock_set_recverr(struct sock *sk, bool val) +{ + lock_sock(sk); + inet_sk(sk)->recverr = val; + if (!val) + skb_queue_purge(&sk->sk_error_queue); + 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. diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c index 562ea36c96b0f..1b87b8a9ff725 100644 --- a/net/rxrpc/local_object.c +++ b/net/rxrpc/local_object.c @@ -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, true); /* we want to set the don't fragment bit */ opt = IP_PMTUDISC_DO;
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> --- include/net/ip.h | 1 + net/ipv4/ip_sockglue.c | 10 ++++++++++ net/rxrpc/local_object.c | 8 +------- 3 files changed, 12 insertions(+), 7 deletions(-)