Skip to content

Commit ac56a0b

Browse files
committed
rxrpc: Fix ICMP/ICMP6 error handling
Because rxrpc pretends to be a tunnel on top of a UDP/UDP6 socket, allowing it to siphon off UDP packets early in the handling of received UDP packets thereby avoiding the packet going through the UDP receive queue, it doesn't get ICMP packets through the UDP ->sk_error_report() callback. In fact, it doesn't appear that there's any usable option for getting hold of ICMP packets. Fix this by adding a new UDP encap hook to distribute error messages for UDP tunnels. If the hook is set, then the tunnel driver will be able to see ICMP packets. The hook provides the offset into the packet of the UDP header of the original packet that caused the notification. An alternative would be to call the ->error_handler() hook - but that requires that the skbuff be cloned (as ip_icmp_error() or ipv6_cmp_error() do, though isn't really necessary or desirable in rxrpc's case is we want to parse them there and then, not queue them). Changes ======= ver #3) - Fixed an uninitialised variable. ver #2) - Fixed some missing CONFIG_AF_RXRPC_IPV6 conditionals. Fixes: 5271953 ("rxrpc: Use the UDP encap_rcv hook") Signed-off-by: David Howells <dhowells@redhat.com>
1 parent f612466 commit ac56a0b

File tree

8 files changed

+270
-38
lines changed

8 files changed

+270
-38
lines changed

include/linux/udp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct udp_sock {
7070
* For encapsulation sockets.
7171
*/
7272
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
73+
void (*encap_err_rcv)(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset);
7374
int (*encap_err_lookup)(struct sock *sk, struct sk_buff *skb);
7475
void (*encap_destroy)(struct sock *sk);
7576

include/net/udp_tunnel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ static inline int udp_sock_create(struct net *net,
6767
typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
6868
typedef int (*udp_tunnel_encap_err_lookup_t)(struct sock *sk,
6969
struct sk_buff *skb);
70+
typedef void (*udp_tunnel_encap_err_rcv_t)(struct sock *sk,
71+
struct sk_buff *skb,
72+
unsigned int udp_offset);
7073
typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
7174
typedef struct sk_buff *(*udp_tunnel_gro_receive_t)(struct sock *sk,
7275
struct list_head *head,
@@ -80,6 +83,7 @@ struct udp_tunnel_sock_cfg {
8083
__u8 encap_type;
8184
udp_tunnel_encap_rcv_t encap_rcv;
8285
udp_tunnel_encap_err_lookup_t encap_err_lookup;
86+
udp_tunnel_encap_err_rcv_t encap_err_rcv;
8387
udp_tunnel_encap_destroy_t encap_destroy;
8488
udp_tunnel_gro_receive_t gro_receive;
8589
udp_tunnel_gro_complete_t gro_complete;

net/ipv4/udp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
783783
*/
784784
if (tunnel) {
785785
/* ...not for tunnels though: we don't have a sending socket */
786+
if (udp_sk(sk)->encap_err_rcv)
787+
udp_sk(sk)->encap_err_rcv(sk, skb, iph->ihl << 2);
786788
goto out;
787789
}
788790
if (!inet->recverr) {

net/ipv4/udp_tunnel_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
7272

7373
udp_sk(sk)->encap_type = cfg->encap_type;
7474
udp_sk(sk)->encap_rcv = cfg->encap_rcv;
75+
udp_sk(sk)->encap_err_rcv = cfg->encap_err_rcv;
7576
udp_sk(sk)->encap_err_lookup = cfg->encap_err_lookup;
7677
udp_sk(sk)->encap_destroy = cfg->encap_destroy;
7778
udp_sk(sk)->gro_receive = cfg->gro_receive;

net/ipv6/udp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,11 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
616616
}
617617

618618
/* Tunnels don't have an application socket: don't pass errors back */
619-
if (tunnel)
619+
if (tunnel) {
620+
if (udp_sk(sk)->encap_err_rcv)
621+
udp_sk(sk)->encap_err_rcv(sk, skb, offset);
620622
goto out;
623+
}
621624

622625
if (!np->recverr) {
623626
if (!harderr || sk->sk_state != TCP_ESTABLISHED)

net/rxrpc/ar-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ void rxrpc_send_keepalive(struct rxrpc_peer *);
982982
/*
983983
* peer_event.c
984984
*/
985+
void rxrpc_encap_err_rcv(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset);
985986
void rxrpc_error_report(struct sock *);
986987
void rxrpc_peer_keepalive_worker(struct work_struct *);
987988

net/rxrpc/local_object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
137137

138138
tuncfg.encap_type = UDP_ENCAP_RXRPC;
139139
tuncfg.encap_rcv = rxrpc_input_packet;
140+
tuncfg.encap_err_rcv = rxrpc_encap_err_rcv;
140141
tuncfg.sk_user_data = local;
141142
setup_udp_tunnel_sock(net, local->socket, &tuncfg);
142143

0 commit comments

Comments
 (0)