Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / net / rxrpc / ar-error.c
blobdb57458c824c87b463ceff200be22c07df936b73
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>
17 #include <linux/in.h>
18 #include <linux/in6.h>
19 #include <linux/icmp.h>
20 #include <net/sock.h>
21 #include <net/af_rxrpc.h>
22 #include <net/ip.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;
34 struct sk_buff *skb;
35 __be32 addr;
36 __be16 port;
38 _enter("%p{%d}", sk, local->debug_id);
40 skb = skb_dequeue(&sk->sk_error_queue);
41 if (!skb) {
42 _leave("UDP socket errqueue empty");
43 return;
46 rxrpc_new_skb(skb);
48 serr = SKB_EXT_ERR(skb);
49 addr = *(__be32 *)(skb_network_header(skb) + serr->addr_offset);
50 port = serr->port;
52 _net("Rx UDP Error from %pI4:%hu", &addr, ntohs(port));
53 _debug("Msg l:%d d:%d", skb->len, skb->data_len);
55 peer = rxrpc_find_peer(local, addr, port);
56 if (IS_ERR(peer)) {
57 rxrpc_free_skb(skb);
58 _leave(" [no peer]");
59 return;
62 trans = rxrpc_find_transport(local, peer);
63 if (!trans) {
64 rxrpc_put_peer(peer);
65 rxrpc_free_skb(skb);
66 _leave(" [no trans]");
67 return;
70 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP &&
71 serr->ee.ee_type == ICMP_DEST_UNREACH &&
72 serr->ee.ee_code == ICMP_FRAG_NEEDED
73 ) {
74 u32 mtu = serr->ee.ee_info;
76 _net("Rx Received ICMP Fragmentation Needed (%d)", mtu);
78 /* wind down the local interface MTU */
79 if (mtu > 0 && peer->if_mtu == 65535 && mtu < peer->if_mtu) {
80 peer->if_mtu = mtu;
81 _net("I/F MTU %u", mtu);
84 if (mtu == 0) {
85 /* they didn't give us a size, estimate one */
86 mtu = peer->if_mtu;
87 if (mtu > 1500) {
88 mtu >>= 1;
89 if (mtu < 1500)
90 mtu = 1500;
91 } else {
92 mtu -= 100;
93 if (mtu < peer->hdrsize)
94 mtu = peer->hdrsize + 4;
98 if (mtu < peer->mtu) {
99 spin_lock_bh(&peer->lock);
100 peer->mtu = mtu;
101 peer->maxdata = peer->mtu - peer->hdrsize;
102 spin_unlock_bh(&peer->lock);
103 _net("Net MTU %u (maxdata %u)",
104 peer->mtu, peer->maxdata);
108 rxrpc_put_peer(peer);
110 /* pass the transport ref to error_handler to release */
111 skb_queue_tail(&trans->error_queue, skb);
112 rxrpc_queue_work(&trans->error_handler);
114 /* reset and regenerate socket error */
115 spin_lock_bh(&sk->sk_error_queue.lock);
116 sk->sk_err = 0;
117 skb = skb_peek(&sk->sk_error_queue);
118 if (skb) {
119 sk->sk_err = SKB_EXT_ERR(skb)->ee.ee_errno;
120 spin_unlock_bh(&sk->sk_error_queue.lock);
121 sk->sk_error_report(sk);
122 } else {
123 spin_unlock_bh(&sk->sk_error_queue.lock);
126 _leave("");
130 * deal with UDP error messages
132 void rxrpc_UDP_error_handler(struct work_struct *work)
134 struct sock_extended_err *ee;
135 struct sock_exterr_skb *serr;
136 struct rxrpc_transport *trans =
137 container_of(work, struct rxrpc_transport, error_handler);
138 struct sk_buff *skb;
139 int err;
141 _enter("");
143 skb = skb_dequeue(&trans->error_queue);
144 if (!skb)
145 return;
147 serr = SKB_EXT_ERR(skb);
148 ee = &serr->ee;
150 _net("Rx Error o=%d t=%d c=%d e=%d",
151 ee->ee_origin, ee->ee_type, ee->ee_code, ee->ee_errno);
153 err = ee->ee_errno;
155 switch (ee->ee_origin) {
156 case SO_EE_ORIGIN_ICMP:
157 switch (ee->ee_type) {
158 case ICMP_DEST_UNREACH:
159 switch (ee->ee_code) {
160 case ICMP_NET_UNREACH:
161 _net("Rx Received ICMP Network Unreachable");
162 err = ENETUNREACH;
163 break;
164 case ICMP_HOST_UNREACH:
165 _net("Rx Received ICMP Host Unreachable");
166 err = EHOSTUNREACH;
167 break;
168 case ICMP_PORT_UNREACH:
169 _net("Rx Received ICMP Port Unreachable");
170 err = ECONNREFUSED;
171 break;
172 case ICMP_FRAG_NEEDED:
173 _net("Rx Received ICMP Fragmentation Needed (%d)",
174 ee->ee_info);
175 err = 0; /* dealt with elsewhere */
176 break;
177 case ICMP_NET_UNKNOWN:
178 _net("Rx Received ICMP Unknown Network");
179 err = ENETUNREACH;
180 break;
181 case ICMP_HOST_UNKNOWN:
182 _net("Rx Received ICMP Unknown Host");
183 err = EHOSTUNREACH;
184 break;
185 default:
186 _net("Rx Received ICMP DestUnreach code=%u",
187 ee->ee_code);
188 break;
190 break;
192 case ICMP_TIME_EXCEEDED:
193 _net("Rx Received ICMP TTL Exceeded");
194 break;
196 default:
197 _proto("Rx Received ICMP error { type=%u code=%u }",
198 ee->ee_type, ee->ee_code);
199 break;
201 break;
203 case SO_EE_ORIGIN_LOCAL:
204 _proto("Rx Received local error { error=%d }",
205 ee->ee_errno);
206 break;
208 case SO_EE_ORIGIN_NONE:
209 case SO_EE_ORIGIN_ICMP6:
210 default:
211 _proto("Rx Received error report { orig=%u }",
212 ee->ee_origin);
213 break;
216 /* terminate all the affected calls if there's an unrecoverable
217 * error */
218 if (err) {
219 struct rxrpc_call *call, *_n;
221 _debug("ISSUE ERROR %d", err);
223 spin_lock_bh(&trans->peer->lock);
224 trans->peer->net_error = err;
226 list_for_each_entry_safe(call, _n, &trans->peer->error_targets,
227 error_link) {
228 write_lock(&call->state_lock);
229 if (call->state != RXRPC_CALL_COMPLETE &&
230 call->state < RXRPC_CALL_NETWORK_ERROR) {
231 call->state = RXRPC_CALL_NETWORK_ERROR;
232 set_bit(RXRPC_CALL_RCVD_ERROR, &call->events);
233 rxrpc_queue_call(call);
235 write_unlock(&call->state_lock);
236 list_del_init(&call->error_link);
239 spin_unlock_bh(&trans->peer->lock);
242 if (!skb_queue_empty(&trans->error_queue))
243 rxrpc_queue_work(&trans->error_handler);
245 rxrpc_free_skb(skb);
246 rxrpc_put_transport(trans);
247 _leave("");