1 /* Error message handling (ICMP)
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/net.h>
14 #include <linux/skbuff.h>
15 #include <linux/errqueue.h>
16 #include <linux/udp.h>
18 #include <linux/in6.h>
19 #include <linux/icmp.h>
21 #include <net/af_rxrpc.h>
23 #include "ar-internal.h"
26 * handle an error received on the local endpoint
28 void rxrpc_UDP_error_report(struct sock *sk)
30 struct sock_exterr_skb *serr;
31 struct rxrpc_transport *trans;
32 struct rxrpc_local *local = sk->sk_user_data;
33 struct rxrpc_peer *peer;
38 _enter("%p{%d}", sk, local->debug_id);
40 skb = skb_dequeue(&sk->sk_error_queue);
42 _leave("UDP socket errqueue empty");
48 serr = SKB_EXT_ERR(skb);
49 addr = *(__be32 *)(skb_network_header(skb) + serr->addr_offset);
52 _net("Rx UDP Error from "NIPQUAD_FMT":%hu",
53 NIPQUAD(addr), ntohs(port));
54 _debug("Msg l:%d d:%d", skb->len, skb->data_len);
56 peer = rxrpc_find_peer(local, addr, port);
63 trans = rxrpc_find_transport(local, peer);
67 _leave(" [no trans]");
71 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP &&
72 serr->ee.ee_type == ICMP_DEST_UNREACH &&
73 serr->ee.ee_code == ICMP_FRAG_NEEDED
75 u32 mtu = serr->ee.ee_info;
77 _net("Rx Received ICMP Fragmentation Needed (%d)", mtu);
79 /* wind down the local interface MTU */
80 if (mtu > 0 && peer->if_mtu == 65535 && mtu < peer->if_mtu) {
82 _net("I/F MTU %u", mtu);
85 /* ip_rt_frag_needed() may have eaten the info */
87 mtu = ntohs(icmp_hdr(skb)->un.frag.mtu);
90 /* they didn't give us a size, estimate one */
97 if (mtu < peer->hdrsize)
98 mtu = peer->hdrsize + 4;
102 if (mtu < peer->mtu) {
103 spin_lock_bh(&peer->lock);
105 peer->maxdata = peer->mtu - peer->hdrsize;
106 spin_unlock_bh(&peer->lock);
107 _net("Net MTU %u (maxdata %u)",
108 peer->mtu, peer->maxdata);
112 rxrpc_put_peer(peer);
114 /* pass the transport ref to error_handler to release */
115 skb_queue_tail(&trans->error_queue, skb);
116 rxrpc_queue_work(&trans->error_handler);
118 /* reset and regenerate socket error */
119 spin_lock_bh(&sk->sk_error_queue.lock);
121 skb = skb_peek(&sk->sk_error_queue);
123 sk->sk_err = SKB_EXT_ERR(skb)->ee.ee_errno;
124 spin_unlock_bh(&sk->sk_error_queue.lock);
125 sk->sk_error_report(sk);
127 spin_unlock_bh(&sk->sk_error_queue.lock);
134 * deal with UDP error messages
136 void rxrpc_UDP_error_handler(struct work_struct *work)
138 struct sock_extended_err *ee;
139 struct sock_exterr_skb *serr;
140 struct rxrpc_transport *trans =
141 container_of(work, struct rxrpc_transport, error_handler);
147 skb = skb_dequeue(&trans->error_queue);
151 serr = SKB_EXT_ERR(skb);
154 _net("Rx Error o=%d t=%d c=%d e=%d",
155 ee->ee_origin, ee->ee_type, ee->ee_code, ee->ee_errno);
159 switch (ee->ee_origin) {
160 case SO_EE_ORIGIN_ICMP:
162 switch (ee->ee_type) {
163 case ICMP_DEST_UNREACH:
164 switch (ee->ee_code) {
165 case ICMP_NET_UNREACH:
166 _net("Rx Received ICMP Network Unreachable");
169 case ICMP_HOST_UNREACH:
170 _net("Rx Received ICMP Host Unreachable");
173 case ICMP_PORT_UNREACH:
174 _net("Rx Received ICMP Port Unreachable");
177 case ICMP_FRAG_NEEDED:
178 _net("Rx Received ICMP Fragmentation Needed (%d)",
180 err = 0; /* dealt with elsewhere */
182 case ICMP_NET_UNKNOWN:
183 _net("Rx Received ICMP Unknown Network");
186 case ICMP_HOST_UNKNOWN:
187 _net("Rx Received ICMP Unknown Host");
191 _net("Rx Received ICMP DestUnreach code=%u",
197 case ICMP_TIME_EXCEEDED:
198 _net("Rx Received ICMP TTL Exceeded");
202 _proto("Rx Received ICMP error { type=%u code=%u }",
203 ee->ee_type, ee->ee_code);
208 case SO_EE_ORIGIN_LOCAL:
209 _proto("Rx Received local error { error=%d }",
214 case SO_EE_ORIGIN_NONE:
215 case SO_EE_ORIGIN_ICMP6:
217 _proto("Rx Received error report { orig=%u }",
223 /* terminate all the affected calls if there's an unrecoverable
226 struct rxrpc_call *call, *_n;
228 _debug("ISSUE ERROR %d", err);
230 spin_lock_bh(&trans->peer->lock);
231 trans->peer->net_error = err;
233 list_for_each_entry_safe(call, _n, &trans->peer->error_targets,
235 write_lock(&call->state_lock);
236 if (call->state != RXRPC_CALL_COMPLETE &&
237 call->state < RXRPC_CALL_NETWORK_ERROR) {
238 call->state = RXRPC_CALL_NETWORK_ERROR;
239 set_bit(RXRPC_CALL_RCVD_ERROR, &call->events);
240 rxrpc_queue_call(call);
242 write_unlock(&call->state_lock);
243 list_del_init(&call->error_link);
246 spin_unlock_bh(&trans->peer->lock);
249 if (!skb_queue_empty(&trans->error_queue))
250 rxrpc_queue_work(&trans->error_handler);
253 rxrpc_put_transport(trans);