* [PATCH net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket
@ 2021-02-07 8:23 Xin Long
2021-02-07 14:23 ` Vadim Fedorenko
2021-02-08 23:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Xin Long @ 2021-02-07 8:23 UTC (permalink / raw)
To: network dev; +Cc: davem, Jakub Kicinski, David Howells
In rxrpc_open_socket(), now it's using sock_create_kern() and
kernel_bind() to create a udp tunnel socket, and other kernel
APIs to set up it. These code can be replaced with udp tunnel
APIs udp_sock_create() and setup_udp_tunnel_sock(), and it'll
simplify rxrpc_open_socket().
Note that with this patch, the udp tunnel socket will always
bind to a random port if transport is not provided by users,
which is suggested by David Howells, thanks!
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/rxrpc/local_object.c | 69 +++++++++++++++++-------------------------------
1 file changed, 24 insertions(+), 45 deletions(-)
diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
index 33b4936..546fd23 100644
--- a/net/rxrpc/local_object.c
+++ b/net/rxrpc/local_object.c
@@ -107,54 +107,42 @@ static struct rxrpc_local *rxrpc_alloc_local(struct rxrpc_net *rxnet,
*/
static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
{
+ struct udp_tunnel_sock_cfg tuncfg = {NULL};
+ struct sockaddr_rxrpc *srx = &local->srx;
+ struct udp_port_cfg udp_conf = {0};
struct sock *usk;
int ret;
_enter("%p{%d,%d}",
- local, local->srx.transport_type, local->srx.transport.family);
-
- /* create a socket to represent the local endpoint */
- ret = sock_create_kern(net, local->srx.transport.family,
- local->srx.transport_type, 0, &local->socket);
+ local, srx->transport_type, srx->transport.family);
+
+ udp_conf.family = srx->transport.family;
+ if (udp_conf.family == AF_INET) {
+ udp_conf.local_ip = srx->transport.sin.sin_addr;
+ udp_conf.local_udp_port = srx->transport.sin.sin_port;
+ } else {
+ udp_conf.local_ip6 = srx->transport.sin6.sin6_addr;
+ udp_conf.local_udp_port = srx->transport.sin6.sin6_port;
+ }
+ ret = udp_sock_create(net, &udp_conf, &local->socket);
if (ret < 0) {
_leave(" = %d [socket]", ret);
return ret;
}
+ tuncfg.encap_type = UDP_ENCAP_RXRPC;
+ tuncfg.encap_rcv = rxrpc_input_packet;
+ tuncfg.sk_user_data = local;
+ setup_udp_tunnel_sock(net, local->socket, &tuncfg);
+
/* set the socket up */
usk = local->socket->sk;
- inet_sk(usk)->mc_loop = 0;
-
- /* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
- inet_inc_convert_csum(usk);
-
- rcu_assign_sk_user_data(usk, local);
-
- udp_sk(usk)->encap_type = UDP_ENCAP_RXRPC;
- udp_sk(usk)->encap_rcv = rxrpc_input_packet;
- udp_sk(usk)->encap_destroy = NULL;
- udp_sk(usk)->gro_receive = NULL;
- udp_sk(usk)->gro_complete = NULL;
-
- udp_tunnel_encap_enable(local->socket);
usk->sk_error_report = rxrpc_error_report;
- /* if a local address was supplied then bind it */
- if (local->srx.transport_len > sizeof(sa_family_t)) {
- _debug("bind");
- ret = kernel_bind(local->socket,
- (struct sockaddr *)&local->srx.transport,
- local->srx.transport_len);
- if (ret < 0) {
- _debug("bind failed %d", ret);
- goto error;
- }
- }
-
- switch (local->srx.transport.family) {
+ switch (srx->transport.family) {
case AF_INET6:
/* we want to receive ICMPv6 errors */
- ip6_sock_set_recverr(local->socket->sk);
+ ip6_sock_set_recverr(usk);
/* Fall through and set IPv4 options too otherwise we don't get
* errors from IPv4 packets sent through the IPv6 socket.
@@ -162,13 +150,13 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
fallthrough;
case AF_INET:
/* we want to receive ICMP errors */
- ip_sock_set_recverr(local->socket->sk);
+ ip_sock_set_recverr(usk);
/* we want to set the don't fragment bit */
- ip_sock_set_mtu_discover(local->socket->sk, IP_PMTUDISC_DO);
+ ip_sock_set_mtu_discover(usk, IP_PMTUDISC_DO);
/* We want receive timestamps. */
- sock_enable_timestamps(local->socket->sk);
+ sock_enable_timestamps(usk);
break;
default:
@@ -177,15 +165,6 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
_leave(" = 0");
return 0;
-
-error:
- kernel_sock_shutdown(local->socket, SHUT_RDWR);
- local->socket->sk->sk_user_data = NULL;
- sock_release(local->socket);
- local->socket = NULL;
-
- _leave(" = %d", ret);
- return ret;
}
/*
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket
2021-02-07 8:23 [PATCH net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket Xin Long
@ 2021-02-07 14:23 ` Vadim Fedorenko
2021-02-08 23:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Vadim Fedorenko @ 2021-02-07 14:23 UTC (permalink / raw)
To: Xin Long, network dev
Cc: Jakub Kicinski, David Howells, Jakub Kicinski, David Howells
On 07.02.2021 08:23, Xin Long wrote:
> In rxrpc_open_socket(), now it's using sock_create_kern() and
> kernel_bind() to create a udp tunnel socket, and other kernel
> APIs to set up it. These code can be replaced with udp tunnel
> APIs udp_sock_create() and setup_udp_tunnel_sock(), and it'll
> simplify rxrpc_open_socket().
>
> Note that with this patch, the udp tunnel socket will always
> bind to a random port if transport is not provided by users,
> which is suggested by David Howells, thanks!
>
> Acked-by: David Howells <dhowells@redhat.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
Looks good to me.
Reviewed-by: Vadim Fedorenko <vfedorenko@novek.ru>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket
2021-02-07 8:23 [PATCH net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket Xin Long
2021-02-07 14:23 ` Vadim Fedorenko
@ 2021-02-08 23:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-08 23:20 UTC (permalink / raw)
To: Xin Long; +Cc: netdev, davem, kuba, dhowells
Hello:
This patch was applied to netdev/net-next.git (refs/heads/master):
On Sun, 7 Feb 2021 16:23:14 +0800 you wrote:
> In rxrpc_open_socket(), now it's using sock_create_kern() and
> kernel_bind() to create a udp tunnel socket, and other kernel
> APIs to set up it. These code can be replaced with udp tunnel
> APIs udp_sock_create() and setup_udp_tunnel_sock(), and it'll
> simplify rxrpc_open_socket().
>
> Note that with this patch, the udp tunnel socket will always
> bind to a random port if transport is not provided by users,
> which is suggested by David Howells, thanks!
>
> [...]
Here is the summary with links:
- [net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket
https://git.kernel.org/netdev/net-next/c/1a9b86c9fd95
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-08 23:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-07 8:23 [PATCH net-next] rxrpc: use udp tunnel APIs instead of open code in rxrpc_open_socket Xin Long
2021-02-07 14:23 ` Vadim Fedorenko
2021-02-08 23:20 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.