Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / rxrpc / transport.c
blob8e57be2df93625867d470eb5185fe22114ec513d
1 /* transport.c: Rx Transport routines
3 * Copyright (C) 2002 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/slab.h>
13 #include <linux/module.h>
14 #include <rxrpc/transport.h>
15 #include <rxrpc/peer.h>
16 #include <rxrpc/connection.h>
17 #include <rxrpc/call.h>
18 #include <rxrpc/message.h>
19 #include <rxrpc/krxiod.h>
20 #include <rxrpc/krxsecd.h>
21 #include <linux/udp.h>
22 #include <linux/in.h>
23 #include <linux/in6.h>
24 #include <linux/icmp.h>
25 #include <linux/skbuff.h>
26 #include <net/sock.h>
27 #include <net/ip.h>
28 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
29 #include <linux/ipv6.h> /* this should _really_ be in errqueue.h.. */
30 #endif
31 #include <linux/errqueue.h>
32 #include <asm/uaccess.h>
33 #include "internal.h"
35 struct errormsg {
36 struct cmsghdr cmsg; /* control message header */
37 struct sock_extended_err ee; /* extended error information */
38 struct sockaddr_in icmp_src; /* ICMP packet source address */
41 static DEFINE_SPINLOCK(rxrpc_transports_lock);
42 static struct list_head rxrpc_transports = LIST_HEAD_INIT(rxrpc_transports);
44 __RXACCT_DECL(atomic_t rxrpc_transport_count);
45 LIST_HEAD(rxrpc_proc_transports);
46 DECLARE_RWSEM(rxrpc_proc_transports_sem);
48 static void rxrpc_data_ready(struct sock *sk, int count);
49 static void rxrpc_error_report(struct sock *sk);
50 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
51 struct list_head *msgq);
52 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans);
54 /*****************************************************************************/
56 * create a new transport endpoint using the specified UDP port
58 int rxrpc_create_transport(unsigned short port,
59 struct rxrpc_transport **_trans)
61 struct rxrpc_transport *trans;
62 struct sockaddr_in sin;
63 mm_segment_t oldfs;
64 struct sock *sock;
65 int ret, opt;
67 _enter("%hu", port);
69 trans = kzalloc(sizeof(struct rxrpc_transport), GFP_KERNEL);
70 if (!trans)
71 return -ENOMEM;
73 atomic_set(&trans->usage, 1);
74 INIT_LIST_HEAD(&trans->services);
75 INIT_LIST_HEAD(&trans->link);
76 INIT_LIST_HEAD(&trans->krxiodq_link);
77 spin_lock_init(&trans->lock);
78 INIT_LIST_HEAD(&trans->peer_active);
79 INIT_LIST_HEAD(&trans->peer_graveyard);
80 spin_lock_init(&trans->peer_gylock);
81 init_waitqueue_head(&trans->peer_gy_waitq);
82 rwlock_init(&trans->peer_lock);
83 atomic_set(&trans->peer_count, 0);
84 trans->port = port;
86 /* create a UDP socket to be my actual transport endpoint */
87 ret = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &trans->socket);
88 if (ret < 0)
89 goto error;
91 /* use the specified port */
92 if (port) {
93 memset(&sin, 0, sizeof(sin));
94 sin.sin_family = AF_INET;
95 sin.sin_port = htons(port);
96 ret = trans->socket->ops->bind(trans->socket,
97 (struct sockaddr *) &sin,
98 sizeof(sin));
99 if (ret < 0)
100 goto error;
103 opt = 1;
104 oldfs = get_fs();
105 set_fs(KERNEL_DS);
106 ret = trans->socket->ops->setsockopt(trans->socket, SOL_IP, IP_RECVERR,
107 (char *) &opt, sizeof(opt));
108 set_fs(oldfs);
110 spin_lock(&rxrpc_transports_lock);
111 list_add(&trans->link, &rxrpc_transports);
112 spin_unlock(&rxrpc_transports_lock);
114 /* set the socket up */
115 sock = trans->socket->sk;
116 sock->sk_user_data = trans;
117 sock->sk_data_ready = rxrpc_data_ready;
118 sock->sk_error_report = rxrpc_error_report;
120 down_write(&rxrpc_proc_transports_sem);
121 list_add_tail(&trans->proc_link, &rxrpc_proc_transports);
122 up_write(&rxrpc_proc_transports_sem);
124 __RXACCT(atomic_inc(&rxrpc_transport_count));
126 *_trans = trans;
127 _leave(" = 0 (%p)", trans);
128 return 0;
130 error:
131 /* finish cleaning up the transport (not really needed here, but...) */
132 if (trans->socket)
133 trans->socket->ops->shutdown(trans->socket, 2);
135 /* close the socket */
136 if (trans->socket) {
137 trans->socket->sk->sk_user_data = NULL;
138 sock_release(trans->socket);
139 trans->socket = NULL;
142 kfree(trans);
145 _leave(" = %d", ret);
146 return ret;
147 } /* end rxrpc_create_transport() */
149 /*****************************************************************************/
151 * destroy a transport endpoint
153 void rxrpc_put_transport(struct rxrpc_transport *trans)
155 _enter("%p{u=%d p=%hu}",
156 trans, atomic_read(&trans->usage), trans->port);
158 BUG_ON(atomic_read(&trans->usage) <= 0);
160 /* to prevent a race, the decrement and the dequeue must be
161 * effectively atomic */
162 spin_lock(&rxrpc_transports_lock);
163 if (likely(!atomic_dec_and_test(&trans->usage))) {
164 spin_unlock(&rxrpc_transports_lock);
165 _leave("");
166 return;
169 list_del(&trans->link);
170 spin_unlock(&rxrpc_transports_lock);
172 /* finish cleaning up the transport */
173 if (trans->socket)
174 trans->socket->ops->shutdown(trans->socket, 2);
176 rxrpc_krxsecd_clear_transport(trans);
177 rxrpc_krxiod_dequeue_transport(trans);
179 /* discard all peer information */
180 rxrpc_peer_clearall(trans);
182 down_write(&rxrpc_proc_transports_sem);
183 list_del(&trans->proc_link);
184 up_write(&rxrpc_proc_transports_sem);
185 __RXACCT(atomic_dec(&rxrpc_transport_count));
187 /* close the socket */
188 if (trans->socket) {
189 trans->socket->sk->sk_user_data = NULL;
190 sock_release(trans->socket);
191 trans->socket = NULL;
194 kfree(trans);
196 _leave("");
197 } /* end rxrpc_put_transport() */
199 /*****************************************************************************/
201 * add a service to a transport to be listened upon
203 int rxrpc_add_service(struct rxrpc_transport *trans,
204 struct rxrpc_service *newsrv)
206 struct rxrpc_service *srv;
207 struct list_head *_p;
208 int ret = -EEXIST;
210 _enter("%p{%hu},%p{%hu}",
211 trans, trans->port, newsrv, newsrv->service_id);
213 /* verify that the service ID is not already present */
214 spin_lock(&trans->lock);
216 list_for_each(_p, &trans->services) {
217 srv = list_entry(_p, struct rxrpc_service, link);
218 if (srv->service_id == newsrv->service_id)
219 goto out;
222 /* okay - add the transport to the list */
223 list_add_tail(&newsrv->link, &trans->services);
224 rxrpc_get_transport(trans);
225 ret = 0;
227 out:
228 spin_unlock(&trans->lock);
230 _leave("= %d", ret);
231 return ret;
232 } /* end rxrpc_add_service() */
234 /*****************************************************************************/
236 * remove a service from a transport
238 void rxrpc_del_service(struct rxrpc_transport *trans, struct rxrpc_service *srv)
240 _enter("%p{%hu},%p{%hu}", trans, trans->port, srv, srv->service_id);
242 spin_lock(&trans->lock);
243 list_del(&srv->link);
244 spin_unlock(&trans->lock);
246 rxrpc_put_transport(trans);
248 _leave("");
249 } /* end rxrpc_del_service() */
251 /*****************************************************************************/
253 * INET callback when data has been received on the socket.
255 static void rxrpc_data_ready(struct sock *sk, int count)
257 struct rxrpc_transport *trans;
259 _enter("%p{t=%p},%d", sk, sk->sk_user_data, count);
261 /* queue the transport for attention by krxiod */
262 trans = (struct rxrpc_transport *) sk->sk_user_data;
263 if (trans)
264 rxrpc_krxiod_queue_transport(trans);
266 /* wake up anyone waiting on the socket */
267 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
268 wake_up_interruptible(sk->sk_sleep);
270 _leave("");
271 } /* end rxrpc_data_ready() */
273 /*****************************************************************************/
275 * INET callback when an ICMP error packet is received
276 * - sk->err is error (EHOSTUNREACH, EPROTO or EMSGSIZE)
278 static void rxrpc_error_report(struct sock *sk)
280 struct rxrpc_transport *trans;
282 _enter("%p{t=%p}", sk, sk->sk_user_data);
284 /* queue the transport for attention by krxiod */
285 trans = (struct rxrpc_transport *) sk->sk_user_data;
286 if (trans) {
287 trans->error_rcvd = 1;
288 rxrpc_krxiod_queue_transport(trans);
291 /* wake up anyone waiting on the socket */
292 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
293 wake_up_interruptible(sk->sk_sleep);
295 _leave("");
296 } /* end rxrpc_error_report() */
298 /*****************************************************************************/
300 * split a message up, allocating message records and filling them in
301 * from the contents of a socket buffer
303 static int rxrpc_incoming_msg(struct rxrpc_transport *trans,
304 struct sk_buff *pkt,
305 struct list_head *msgq)
307 struct rxrpc_message *msg;
308 int ret;
310 _enter("");
312 msg = kzalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
313 if (!msg) {
314 _leave(" = -ENOMEM");
315 return -ENOMEM;
318 atomic_set(&msg->usage, 1);
319 list_add_tail(&msg->link,msgq);
321 /* dig out the Rx routing parameters */
322 if (skb_copy_bits(pkt, sizeof(struct udphdr),
323 &msg->hdr, sizeof(msg->hdr)) < 0) {
324 ret = -EBADMSG;
325 goto error;
328 msg->trans = trans;
329 msg->state = RXRPC_MSG_RECEIVED;
330 skb_get_timestamp(pkt, &msg->stamp);
331 if (msg->stamp.tv_sec == 0) {
332 do_gettimeofday(&msg->stamp);
333 if (pkt->sk)
334 sock_enable_timestamp(pkt->sk);
336 msg->seq = ntohl(msg->hdr.seq);
338 /* attach the packet */
339 skb_get(pkt);
340 msg->pkt = pkt;
342 msg->offset = sizeof(struct udphdr) + sizeof(struct rxrpc_header);
343 msg->dsize = msg->pkt->len - msg->offset;
345 _net("Rx Received packet from %s (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
346 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
347 ntohl(msg->hdr.epoch),
348 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
349 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
350 ntohl(msg->hdr.callNumber),
351 rxrpc_pkts[msg->hdr.type],
352 msg->hdr.flags,
353 ntohs(msg->hdr.serviceId),
354 msg->hdr.securityIndex);
356 __RXACCT(atomic_inc(&rxrpc_message_count));
358 /* split off jumbo packets */
359 while (msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
360 msg->hdr.flags & RXRPC_JUMBO_PACKET
362 struct rxrpc_jumbo_header jumbo;
363 struct rxrpc_message *jumbomsg = msg;
365 _debug("split jumbo packet");
367 /* quick sanity check */
368 ret = -EBADMSG;
369 if (msg->dsize <
370 RXRPC_JUMBO_DATALEN + sizeof(struct rxrpc_jumbo_header))
371 goto error;
372 if (msg->hdr.flags & RXRPC_LAST_PACKET)
373 goto error;
375 /* dig out the secondary header */
376 if (skb_copy_bits(pkt, msg->offset + RXRPC_JUMBO_DATALEN,
377 &jumbo, sizeof(jumbo)) < 0)
378 goto error;
380 /* allocate a new message record */
381 ret = -ENOMEM;
382 msg = kmemdup(jumbomsg, sizeof(struct rxrpc_message), GFP_KERNEL);
383 if (!msg)
384 goto error;
386 list_add_tail(&msg->link, msgq);
388 /* adjust the jumbo packet */
389 jumbomsg->dsize = RXRPC_JUMBO_DATALEN;
391 /* attach the packet here too */
392 skb_get(pkt);
394 /* adjust the parameters */
395 msg->seq++;
396 msg->hdr.seq = htonl(msg->seq);
397 msg->hdr.serial = htonl(ntohl(msg->hdr.serial) + 1);
398 msg->offset += RXRPC_JUMBO_DATALEN +
399 sizeof(struct rxrpc_jumbo_header);
400 msg->dsize -= RXRPC_JUMBO_DATALEN +
401 sizeof(struct rxrpc_jumbo_header);
402 msg->hdr.flags = jumbo.flags;
403 msg->hdr._rsvd = jumbo._rsvd;
405 _net("Rx Split jumbo packet from %s"
406 " (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
407 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
408 ntohl(msg->hdr.epoch),
409 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
410 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
411 ntohl(msg->hdr.callNumber),
412 rxrpc_pkts[msg->hdr.type],
413 msg->hdr.flags,
414 ntohs(msg->hdr.serviceId),
415 msg->hdr.securityIndex);
417 __RXACCT(atomic_inc(&rxrpc_message_count));
420 _leave(" = 0 #%d", atomic_read(&rxrpc_message_count));
421 return 0;
423 error:
424 while (!list_empty(msgq)) {
425 msg = list_entry(msgq->next, struct rxrpc_message, link);
426 list_del_init(&msg->link);
428 rxrpc_put_message(msg);
431 _leave(" = %d", ret);
432 return ret;
433 } /* end rxrpc_incoming_msg() */
435 /*****************************************************************************/
437 * accept a new call
438 * - called from krxiod in process context
440 void rxrpc_trans_receive_packet(struct rxrpc_transport *trans)
442 struct rxrpc_message *msg;
443 struct rxrpc_peer *peer;
444 struct sk_buff *pkt;
445 int ret;
446 __be32 addr;
447 __be16 port;
449 LIST_HEAD(msgq);
451 _enter("%p{%d}", trans, trans->port);
453 for (;;) {
454 /* deal with outstanting errors first */
455 if (trans->error_rcvd)
456 rxrpc_trans_receive_error_report(trans);
458 /* attempt to receive a packet */
459 pkt = skb_recv_datagram(trans->socket->sk, 0, 1, &ret);
460 if (!pkt) {
461 if (ret == -EAGAIN) {
462 _leave(" EAGAIN");
463 return;
466 /* an icmp error may have occurred */
467 rxrpc_krxiod_queue_transport(trans);
468 _leave(" error %d\n", ret);
469 return;
472 /* we'll probably need to checksum it (didn't call
473 * sock_recvmsg) */
474 if (skb_checksum_complete(pkt)) {
475 kfree_skb(pkt);
476 rxrpc_krxiod_queue_transport(trans);
477 _leave(" CSUM failed");
478 return;
481 addr = pkt->nh.iph->saddr;
482 port = pkt->h.uh->source;
484 _net("Rx Received UDP packet from %08x:%04hu",
485 ntohl(addr), ntohs(port));
487 /* unmarshall the Rx parameters and split jumbo packets */
488 ret = rxrpc_incoming_msg(trans, pkt, &msgq);
489 if (ret < 0) {
490 kfree_skb(pkt);
491 rxrpc_krxiod_queue_transport(trans);
492 _leave(" bad packet");
493 return;
496 BUG_ON(list_empty(&msgq));
498 msg = list_entry(msgq.next, struct rxrpc_message, link);
500 /* locate the record for the peer from which it
501 * originated */
502 ret = rxrpc_peer_lookup(trans, addr, &peer);
503 if (ret < 0) {
504 kdebug("Rx No connections from that peer");
505 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
506 goto finished_msg;
509 /* try and find a matching connection */
510 ret = rxrpc_connection_lookup(peer, msg, &msg->conn);
511 if (ret < 0) {
512 kdebug("Rx Unknown Connection");
513 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
514 rxrpc_put_peer(peer);
515 goto finished_msg;
517 rxrpc_put_peer(peer);
519 /* deal with the first packet of a new call */
520 if (msg->hdr.flags & RXRPC_CLIENT_INITIATED &&
521 msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
522 ntohl(msg->hdr.seq) == 1
524 _debug("Rx New server call");
525 rxrpc_trans_receive_new_call(trans, &msgq);
526 goto finished_msg;
529 /* deal with subsequent packet(s) of call */
530 _debug("Rx Call packet");
531 while (!list_empty(&msgq)) {
532 msg = list_entry(msgq.next, struct rxrpc_message, link);
533 list_del_init(&msg->link);
535 ret = rxrpc_conn_receive_call_packet(msg->conn, NULL, msg);
536 if (ret < 0) {
537 rxrpc_trans_immediate_abort(trans, msg, ret);
538 rxrpc_put_message(msg);
539 goto finished_msg;
542 rxrpc_put_message(msg);
545 goto finished_msg;
547 /* dispose of the packets */
548 finished_msg:
549 while (!list_empty(&msgq)) {
550 msg = list_entry(msgq.next, struct rxrpc_message, link);
551 list_del_init(&msg->link);
553 rxrpc_put_message(msg);
555 kfree_skb(pkt);
558 _leave("");
560 } /* end rxrpc_trans_receive_packet() */
562 /*****************************************************************************/
564 * accept a new call from a client trying to connect to one of my services
565 * - called in process context
567 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
568 struct list_head *msgq)
570 struct rxrpc_message *msg;
572 _enter("");
574 /* only bother with the first packet */
575 msg = list_entry(msgq->next, struct rxrpc_message, link);
576 list_del_init(&msg->link);
577 rxrpc_krxsecd_queue_incoming_call(msg);
578 rxrpc_put_message(msg);
580 _leave(" = 0");
582 return 0;
583 } /* end rxrpc_trans_receive_new_call() */
585 /*****************************************************************************/
587 * perform an immediate abort without connection or call structures
589 int rxrpc_trans_immediate_abort(struct rxrpc_transport *trans,
590 struct rxrpc_message *msg,
591 int error)
593 struct rxrpc_header ahdr;
594 struct sockaddr_in sin;
595 struct msghdr msghdr;
596 struct kvec iov[2];
597 __be32 _error;
598 int len, ret;
600 _enter("%p,%p,%d", trans, msg, error);
602 /* don't abort an abort packet */
603 if (msg->hdr.type == RXRPC_PACKET_TYPE_ABORT) {
604 _leave(" = 0");
605 return 0;
608 _error = htonl(-error);
610 /* set up the message to be transmitted */
611 memcpy(&ahdr, &msg->hdr, sizeof(ahdr));
612 ahdr.epoch = msg->hdr.epoch;
613 ahdr.serial = htonl(1);
614 ahdr.seq = 0;
615 ahdr.type = RXRPC_PACKET_TYPE_ABORT;
616 ahdr.flags = RXRPC_LAST_PACKET;
617 ahdr.flags |= ~msg->hdr.flags & RXRPC_CLIENT_INITIATED;
619 iov[0].iov_len = sizeof(ahdr);
620 iov[0].iov_base = &ahdr;
621 iov[1].iov_len = sizeof(_error);
622 iov[1].iov_base = &_error;
624 len = sizeof(ahdr) + sizeof(_error);
626 memset(&sin,0,sizeof(sin));
627 sin.sin_family = AF_INET;
628 sin.sin_port = msg->pkt->h.uh->source;
629 sin.sin_addr.s_addr = msg->pkt->nh.iph->saddr;
631 msghdr.msg_name = &sin;
632 msghdr.msg_namelen = sizeof(sin);
633 msghdr.msg_control = NULL;
634 msghdr.msg_controllen = 0;
635 msghdr.msg_flags = MSG_DONTWAIT;
637 _net("Sending message type %d of %d bytes to %08x:%d",
638 ahdr.type,
639 len,
640 ntohl(sin.sin_addr.s_addr),
641 ntohs(sin.sin_port));
643 /* send the message */
644 ret = kernel_sendmsg(trans->socket, &msghdr, iov, 2, len);
646 _leave(" = %d", ret);
647 return ret;
648 } /* end rxrpc_trans_immediate_abort() */
650 /*****************************************************************************/
652 * receive an ICMP error report and percolate it to all connections
653 * heading to the affected host or port
655 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans)
657 struct rxrpc_connection *conn;
658 struct sockaddr_in sin;
659 struct rxrpc_peer *peer;
660 struct list_head connq, *_p;
661 struct errormsg emsg;
662 struct msghdr msg;
663 __be16 port;
664 int local, err;
666 _enter("%p", trans);
668 for (;;) {
669 trans->error_rcvd = 0;
671 /* try and receive an error message */
672 msg.msg_name = &sin;
673 msg.msg_namelen = sizeof(sin);
674 msg.msg_control = &emsg;
675 msg.msg_controllen = sizeof(emsg);
676 msg.msg_flags = 0;
678 err = kernel_recvmsg(trans->socket, &msg, NULL, 0, 0,
679 MSG_ERRQUEUE | MSG_DONTWAIT | MSG_TRUNC);
681 if (err == -EAGAIN) {
682 _leave("");
683 return;
686 if (err < 0) {
687 printk("%s: unable to recv an error report: %d\n",
688 __FUNCTION__, err);
689 _leave("");
690 return;
693 msg.msg_controllen = (char *) msg.msg_control - (char *) &emsg;
695 if (msg.msg_controllen < sizeof(emsg.cmsg) ||
696 msg.msg_namelen < sizeof(sin)) {
697 printk("%s: short control message"
698 " (nlen=%u clen=%Zu fl=%x)\n",
699 __FUNCTION__,
700 msg.msg_namelen,
701 msg.msg_controllen,
702 msg.msg_flags);
703 continue;
706 _net("Rx Received control message"
707 " { len=%Zu level=%u type=%u }",
708 emsg.cmsg.cmsg_len,
709 emsg.cmsg.cmsg_level,
710 emsg.cmsg.cmsg_type);
712 if (sin.sin_family != AF_INET) {
713 printk("Rx Ignoring error report with non-INET address"
714 " (fam=%u)",
715 sin.sin_family);
716 continue;
719 _net("Rx Received message pertaining to host addr=%x port=%hu",
720 ntohl(sin.sin_addr.s_addr), ntohs(sin.sin_port));
722 if (emsg.cmsg.cmsg_level != SOL_IP ||
723 emsg.cmsg.cmsg_type != IP_RECVERR) {
724 printk("Rx Ignoring unknown error report"
725 " { level=%u type=%u }",
726 emsg.cmsg.cmsg_level,
727 emsg.cmsg.cmsg_type);
728 continue;
731 if (msg.msg_controllen < sizeof(emsg.cmsg) + sizeof(emsg.ee)) {
732 printk("%s: short error message (%Zu)\n",
733 __FUNCTION__, msg.msg_controllen);
734 _leave("");
735 return;
738 port = sin.sin_port;
740 switch (emsg.ee.ee_origin) {
741 case SO_EE_ORIGIN_ICMP:
742 local = 0;
743 switch (emsg.ee.ee_type) {
744 case ICMP_DEST_UNREACH:
745 switch (emsg.ee.ee_code) {
746 case ICMP_NET_UNREACH:
747 _net("Rx Received ICMP Network Unreachable");
748 port = 0;
749 err = -ENETUNREACH;
750 break;
751 case ICMP_HOST_UNREACH:
752 _net("Rx Received ICMP Host Unreachable");
753 port = 0;
754 err = -EHOSTUNREACH;
755 break;
756 case ICMP_PORT_UNREACH:
757 _net("Rx Received ICMP Port Unreachable");
758 err = -ECONNREFUSED;
759 break;
760 case ICMP_NET_UNKNOWN:
761 _net("Rx Received ICMP Unknown Network");
762 port = 0;
763 err = -ENETUNREACH;
764 break;
765 case ICMP_HOST_UNKNOWN:
766 _net("Rx Received ICMP Unknown Host");
767 port = 0;
768 err = -EHOSTUNREACH;
769 break;
770 default:
771 _net("Rx Received ICMP DestUnreach { code=%u }",
772 emsg.ee.ee_code);
773 err = emsg.ee.ee_errno;
774 break;
776 break;
778 case ICMP_TIME_EXCEEDED:
779 _net("Rx Received ICMP TTL Exceeded");
780 err = emsg.ee.ee_errno;
781 break;
783 default:
784 _proto("Rx Received ICMP error { type=%u code=%u }",
785 emsg.ee.ee_type, emsg.ee.ee_code);
786 err = emsg.ee.ee_errno;
787 break;
789 break;
791 case SO_EE_ORIGIN_LOCAL:
792 _proto("Rx Received local error { error=%d }",
793 emsg.ee.ee_errno);
794 local = 1;
795 err = emsg.ee.ee_errno;
796 break;
798 case SO_EE_ORIGIN_NONE:
799 case SO_EE_ORIGIN_ICMP6:
800 default:
801 _proto("Rx Received error report { orig=%u }",
802 emsg.ee.ee_origin);
803 local = 0;
804 err = emsg.ee.ee_errno;
805 break;
808 /* find all the connections between this transport and the
809 * affected destination */
810 INIT_LIST_HEAD(&connq);
812 if (rxrpc_peer_lookup(trans, sin.sin_addr.s_addr,
813 &peer) == 0) {
814 read_lock(&peer->conn_lock);
815 list_for_each(_p, &peer->conn_active) {
816 conn = list_entry(_p, struct rxrpc_connection,
817 link);
818 if (port && conn->addr.sin_port != port)
819 continue;
820 if (!list_empty(&conn->err_link))
821 continue;
823 rxrpc_get_connection(conn);
824 list_add_tail(&conn->err_link, &connq);
826 read_unlock(&peer->conn_lock);
828 /* service all those connections */
829 while (!list_empty(&connq)) {
830 conn = list_entry(connq.next,
831 struct rxrpc_connection,
832 err_link);
833 list_del(&conn->err_link);
835 rxrpc_conn_handle_error(conn, local, err);
837 rxrpc_put_connection(conn);
840 rxrpc_put_peer(peer);
844 _leave("");
845 return;
846 } /* end rxrpc_trans_receive_error_report() */