[NET_SCHED]: Remove old estimator implementation
[hh.org.git] / net / rxrpc / transport.c
blob94b2e2fe6fdb97ec548956f1d247d5da8ad4c70b
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/sched.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <rxrpc/transport.h>
16 #include <rxrpc/peer.h>
17 #include <rxrpc/connection.h>
18 #include <rxrpc/call.h>
19 #include <rxrpc/message.h>
20 #include <rxrpc/krxiod.h>
21 #include <rxrpc/krxsecd.h>
22 #include <linux/udp.h>
23 #include <linux/in.h>
24 #include <linux/in6.h>
25 #include <linux/icmp.h>
26 #include <linux/skbuff.h>
27 #include <net/sock.h>
28 #include <net/ip.h>
29 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
30 #include <linux/ipv6.h> /* this should _really_ be in errqueue.h.. */
31 #endif
32 #include <linux/errqueue.h>
33 #include <asm/uaccess.h>
34 #include <asm/checksum.h>
35 #include "internal.h"
37 struct errormsg {
38 struct cmsghdr cmsg; /* control message header */
39 struct sock_extended_err ee; /* extended error information */
40 struct sockaddr_in icmp_src; /* ICMP packet source address */
43 static DEFINE_SPINLOCK(rxrpc_transports_lock);
44 static struct list_head rxrpc_transports = LIST_HEAD_INIT(rxrpc_transports);
46 __RXACCT_DECL(atomic_t rxrpc_transport_count);
47 LIST_HEAD(rxrpc_proc_transports);
48 DECLARE_RWSEM(rxrpc_proc_transports_sem);
50 static void rxrpc_data_ready(struct sock *sk, int count);
51 static void rxrpc_error_report(struct sock *sk);
52 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
53 struct list_head *msgq);
54 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans);
56 /*****************************************************************************/
58 * create a new transport endpoint using the specified UDP port
60 int rxrpc_create_transport(unsigned short port,
61 struct rxrpc_transport **_trans)
63 struct rxrpc_transport *trans;
64 struct sockaddr_in sin;
65 mm_segment_t oldfs;
66 struct sock *sock;
67 int ret, opt;
69 _enter("%hu", port);
71 trans = kzalloc(sizeof(struct rxrpc_transport), GFP_KERNEL);
72 if (!trans)
73 return -ENOMEM;
75 atomic_set(&trans->usage, 1);
76 INIT_LIST_HEAD(&trans->services);
77 INIT_LIST_HEAD(&trans->link);
78 INIT_LIST_HEAD(&trans->krxiodq_link);
79 spin_lock_init(&trans->lock);
80 INIT_LIST_HEAD(&trans->peer_active);
81 INIT_LIST_HEAD(&trans->peer_graveyard);
82 spin_lock_init(&trans->peer_gylock);
83 init_waitqueue_head(&trans->peer_gy_waitq);
84 rwlock_init(&trans->peer_lock);
85 atomic_set(&trans->peer_count, 0);
86 trans->port = port;
88 /* create a UDP socket to be my actual transport endpoint */
89 ret = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &trans->socket);
90 if (ret < 0)
91 goto error;
93 /* use the specified port */
94 if (port) {
95 memset(&sin, 0, sizeof(sin));
96 sin.sin_family = AF_INET;
97 sin.sin_port = htons(port);
98 ret = trans->socket->ops->bind(trans->socket,
99 (struct sockaddr *) &sin,
100 sizeof(sin));
101 if (ret < 0)
102 goto error;
105 opt = 1;
106 oldfs = get_fs();
107 set_fs(KERNEL_DS);
108 ret = trans->socket->ops->setsockopt(trans->socket, SOL_IP, IP_RECVERR,
109 (char *) &opt, sizeof(opt));
110 set_fs(oldfs);
112 spin_lock(&rxrpc_transports_lock);
113 list_add(&trans->link, &rxrpc_transports);
114 spin_unlock(&rxrpc_transports_lock);
116 /* set the socket up */
117 sock = trans->socket->sk;
118 sock->sk_user_data = trans;
119 sock->sk_data_ready = rxrpc_data_ready;
120 sock->sk_error_report = rxrpc_error_report;
122 down_write(&rxrpc_proc_transports_sem);
123 list_add_tail(&trans->proc_link, &rxrpc_proc_transports);
124 up_write(&rxrpc_proc_transports_sem);
126 __RXACCT(atomic_inc(&rxrpc_transport_count));
128 *_trans = trans;
129 _leave(" = 0 (%p)", trans);
130 return 0;
132 error:
133 /* finish cleaning up the transport (not really needed here, but...) */
134 if (trans->socket)
135 trans->socket->ops->shutdown(trans->socket, 2);
137 /* close the socket */
138 if (trans->socket) {
139 trans->socket->sk->sk_user_data = NULL;
140 sock_release(trans->socket);
141 trans->socket = NULL;
144 kfree(trans);
147 _leave(" = %d", ret);
148 return ret;
149 } /* end rxrpc_create_transport() */
151 /*****************************************************************************/
153 * destroy a transport endpoint
155 void rxrpc_put_transport(struct rxrpc_transport *trans)
157 _enter("%p{u=%d p=%hu}",
158 trans, atomic_read(&trans->usage), trans->port);
160 BUG_ON(atomic_read(&trans->usage) <= 0);
162 /* to prevent a race, the decrement and the dequeue must be
163 * effectively atomic */
164 spin_lock(&rxrpc_transports_lock);
165 if (likely(!atomic_dec_and_test(&trans->usage))) {
166 spin_unlock(&rxrpc_transports_lock);
167 _leave("");
168 return;
171 list_del(&trans->link);
172 spin_unlock(&rxrpc_transports_lock);
174 /* finish cleaning up the transport */
175 if (trans->socket)
176 trans->socket->ops->shutdown(trans->socket, 2);
178 rxrpc_krxsecd_clear_transport(trans);
179 rxrpc_krxiod_dequeue_transport(trans);
181 /* discard all peer information */
182 rxrpc_peer_clearall(trans);
184 down_write(&rxrpc_proc_transports_sem);
185 list_del(&trans->proc_link);
186 up_write(&rxrpc_proc_transports_sem);
187 __RXACCT(atomic_dec(&rxrpc_transport_count));
189 /* close the socket */
190 if (trans->socket) {
191 trans->socket->sk->sk_user_data = NULL;
192 sock_release(trans->socket);
193 trans->socket = NULL;
196 kfree(trans);
198 _leave("");
199 } /* end rxrpc_put_transport() */
201 /*****************************************************************************/
203 * add a service to a transport to be listened upon
205 int rxrpc_add_service(struct rxrpc_transport *trans,
206 struct rxrpc_service *newsrv)
208 struct rxrpc_service *srv;
209 struct list_head *_p;
210 int ret = -EEXIST;
212 _enter("%p{%hu},%p{%hu}",
213 trans, trans->port, newsrv, newsrv->service_id);
215 /* verify that the service ID is not already present */
216 spin_lock(&trans->lock);
218 list_for_each(_p, &trans->services) {
219 srv = list_entry(_p, struct rxrpc_service, link);
220 if (srv->service_id == newsrv->service_id)
221 goto out;
224 /* okay - add the transport to the list */
225 list_add_tail(&newsrv->link, &trans->services);
226 rxrpc_get_transport(trans);
227 ret = 0;
229 out:
230 spin_unlock(&trans->lock);
232 _leave("= %d", ret);
233 return ret;
234 } /* end rxrpc_add_service() */
236 /*****************************************************************************/
238 * remove a service from a transport
240 void rxrpc_del_service(struct rxrpc_transport *trans, struct rxrpc_service *srv)
242 _enter("%p{%hu},%p{%hu}", trans, trans->port, srv, srv->service_id);
244 spin_lock(&trans->lock);
245 list_del(&srv->link);
246 spin_unlock(&trans->lock);
248 rxrpc_put_transport(trans);
250 _leave("");
251 } /* end rxrpc_del_service() */
253 /*****************************************************************************/
255 * INET callback when data has been received on the socket.
257 static void rxrpc_data_ready(struct sock *sk, int count)
259 struct rxrpc_transport *trans;
261 _enter("%p{t=%p},%d", sk, sk->sk_user_data, count);
263 /* queue the transport for attention by krxiod */
264 trans = (struct rxrpc_transport *) sk->sk_user_data;
265 if (trans)
266 rxrpc_krxiod_queue_transport(trans);
268 /* wake up anyone waiting on the socket */
269 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
270 wake_up_interruptible(sk->sk_sleep);
272 _leave("");
273 } /* end rxrpc_data_ready() */
275 /*****************************************************************************/
277 * INET callback when an ICMP error packet is received
278 * - sk->err is error (EHOSTUNREACH, EPROTO or EMSGSIZE)
280 static void rxrpc_error_report(struct sock *sk)
282 struct rxrpc_transport *trans;
284 _enter("%p{t=%p}", sk, sk->sk_user_data);
286 /* queue the transport for attention by krxiod */
287 trans = (struct rxrpc_transport *) sk->sk_user_data;
288 if (trans) {
289 trans->error_rcvd = 1;
290 rxrpc_krxiod_queue_transport(trans);
293 /* wake up anyone waiting on the socket */
294 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
295 wake_up_interruptible(sk->sk_sleep);
297 _leave("");
298 } /* end rxrpc_error_report() */
300 /*****************************************************************************/
302 * split a message up, allocating message records and filling them in
303 * from the contents of a socket buffer
305 static int rxrpc_incoming_msg(struct rxrpc_transport *trans,
306 struct sk_buff *pkt,
307 struct list_head *msgq)
309 struct rxrpc_message *msg;
310 int ret;
312 _enter("");
314 msg = kzalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
315 if (!msg) {
316 _leave(" = -ENOMEM");
317 return -ENOMEM;
320 atomic_set(&msg->usage, 1);
321 list_add_tail(&msg->link,msgq);
323 /* dig out the Rx routing parameters */
324 if (skb_copy_bits(pkt, sizeof(struct udphdr),
325 &msg->hdr, sizeof(msg->hdr)) < 0) {
326 ret = -EBADMSG;
327 goto error;
330 msg->trans = trans;
331 msg->state = RXRPC_MSG_RECEIVED;
332 skb_get_timestamp(pkt, &msg->stamp);
333 if (msg->stamp.tv_sec == 0) {
334 do_gettimeofday(&msg->stamp);
335 if (pkt->sk)
336 sock_enable_timestamp(pkt->sk);
338 msg->seq = ntohl(msg->hdr.seq);
340 /* attach the packet */
341 skb_get(pkt);
342 msg->pkt = pkt;
344 msg->offset = sizeof(struct udphdr) + sizeof(struct rxrpc_header);
345 msg->dsize = msg->pkt->len - msg->offset;
347 _net("Rx Received packet from %s (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
348 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
349 ntohl(msg->hdr.epoch),
350 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
351 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
352 ntohl(msg->hdr.callNumber),
353 rxrpc_pkts[msg->hdr.type],
354 msg->hdr.flags,
355 ntohs(msg->hdr.serviceId),
356 msg->hdr.securityIndex);
358 __RXACCT(atomic_inc(&rxrpc_message_count));
360 /* split off jumbo packets */
361 while (msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
362 msg->hdr.flags & RXRPC_JUMBO_PACKET
364 struct rxrpc_jumbo_header jumbo;
365 struct rxrpc_message *jumbomsg = msg;
367 _debug("split jumbo packet");
369 /* quick sanity check */
370 ret = -EBADMSG;
371 if (msg->dsize <
372 RXRPC_JUMBO_DATALEN + sizeof(struct rxrpc_jumbo_header))
373 goto error;
374 if (msg->hdr.flags & RXRPC_LAST_PACKET)
375 goto error;
377 /* dig out the secondary header */
378 if (skb_copy_bits(pkt, msg->offset + RXRPC_JUMBO_DATALEN,
379 &jumbo, sizeof(jumbo)) < 0)
380 goto error;
382 /* allocate a new message record */
383 ret = -ENOMEM;
384 msg = kmemdup(jumbomsg, sizeof(struct rxrpc_message), GFP_KERNEL);
385 if (!msg)
386 goto error;
388 list_add_tail(&msg->link, msgq);
390 /* adjust the jumbo packet */
391 jumbomsg->dsize = RXRPC_JUMBO_DATALEN;
393 /* attach the packet here too */
394 skb_get(pkt);
396 /* adjust the parameters */
397 msg->seq++;
398 msg->hdr.seq = htonl(msg->seq);
399 msg->hdr.serial = htonl(ntohl(msg->hdr.serial) + 1);
400 msg->offset += RXRPC_JUMBO_DATALEN +
401 sizeof(struct rxrpc_jumbo_header);
402 msg->dsize -= RXRPC_JUMBO_DATALEN +
403 sizeof(struct rxrpc_jumbo_header);
404 msg->hdr.flags = jumbo.flags;
405 msg->hdr._rsvd = jumbo._rsvd;
407 _net("Rx Split jumbo packet from %s"
408 " (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
409 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
410 ntohl(msg->hdr.epoch),
411 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
412 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
413 ntohl(msg->hdr.callNumber),
414 rxrpc_pkts[msg->hdr.type],
415 msg->hdr.flags,
416 ntohs(msg->hdr.serviceId),
417 msg->hdr.securityIndex);
419 __RXACCT(atomic_inc(&rxrpc_message_count));
422 _leave(" = 0 #%d", atomic_read(&rxrpc_message_count));
423 return 0;
425 error:
426 while (!list_empty(msgq)) {
427 msg = list_entry(msgq->next, struct rxrpc_message, link);
428 list_del_init(&msg->link);
430 rxrpc_put_message(msg);
433 _leave(" = %d", ret);
434 return ret;
435 } /* end rxrpc_incoming_msg() */
437 /*****************************************************************************/
439 * accept a new call
440 * - called from krxiod in process context
442 void rxrpc_trans_receive_packet(struct rxrpc_transport *trans)
444 struct rxrpc_message *msg;
445 struct rxrpc_peer *peer;
446 struct sk_buff *pkt;
447 int ret;
448 __be32 addr;
449 __be16 port;
451 LIST_HEAD(msgq);
453 _enter("%p{%d}", trans, trans->port);
455 for (;;) {
456 /* deal with outstanting errors first */
457 if (trans->error_rcvd)
458 rxrpc_trans_receive_error_report(trans);
460 /* attempt to receive a packet */
461 pkt = skb_recv_datagram(trans->socket->sk, 0, 1, &ret);
462 if (!pkt) {
463 if (ret == -EAGAIN) {
464 _leave(" EAGAIN");
465 return;
468 /* an icmp error may have occurred */
469 rxrpc_krxiod_queue_transport(trans);
470 _leave(" error %d\n", ret);
471 return;
474 /* we'll probably need to checksum it (didn't call
475 * sock_recvmsg) */
476 if (skb_checksum_complete(pkt)) {
477 kfree_skb(pkt);
478 rxrpc_krxiod_queue_transport(trans);
479 _leave(" CSUM failed");
480 return;
483 addr = pkt->nh.iph->saddr;
484 port = pkt->h.uh->source;
486 _net("Rx Received UDP packet from %08x:%04hu",
487 ntohl(addr), ntohs(port));
489 /* unmarshall the Rx parameters and split jumbo packets */
490 ret = rxrpc_incoming_msg(trans, pkt, &msgq);
491 if (ret < 0) {
492 kfree_skb(pkt);
493 rxrpc_krxiod_queue_transport(trans);
494 _leave(" bad packet");
495 return;
498 BUG_ON(list_empty(&msgq));
500 msg = list_entry(msgq.next, struct rxrpc_message, link);
502 /* locate the record for the peer from which it
503 * originated */
504 ret = rxrpc_peer_lookup(trans, addr, &peer);
505 if (ret < 0) {
506 kdebug("Rx No connections from that peer");
507 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
508 goto finished_msg;
511 /* try and find a matching connection */
512 ret = rxrpc_connection_lookup(peer, msg, &msg->conn);
513 if (ret < 0) {
514 kdebug("Rx Unknown Connection");
515 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
516 rxrpc_put_peer(peer);
517 goto finished_msg;
519 rxrpc_put_peer(peer);
521 /* deal with the first packet of a new call */
522 if (msg->hdr.flags & RXRPC_CLIENT_INITIATED &&
523 msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
524 ntohl(msg->hdr.seq) == 1
526 _debug("Rx New server call");
527 rxrpc_trans_receive_new_call(trans, &msgq);
528 goto finished_msg;
531 /* deal with subsequent packet(s) of call */
532 _debug("Rx Call packet");
533 while (!list_empty(&msgq)) {
534 msg = list_entry(msgq.next, struct rxrpc_message, link);
535 list_del_init(&msg->link);
537 ret = rxrpc_conn_receive_call_packet(msg->conn, NULL, msg);
538 if (ret < 0) {
539 rxrpc_trans_immediate_abort(trans, msg, ret);
540 rxrpc_put_message(msg);
541 goto finished_msg;
544 rxrpc_put_message(msg);
547 goto finished_msg;
549 /* dispose of the packets */
550 finished_msg:
551 while (!list_empty(&msgq)) {
552 msg = list_entry(msgq.next, struct rxrpc_message, link);
553 list_del_init(&msg->link);
555 rxrpc_put_message(msg);
557 kfree_skb(pkt);
560 _leave("");
562 } /* end rxrpc_trans_receive_packet() */
564 /*****************************************************************************/
566 * accept a new call from a client trying to connect to one of my services
567 * - called in process context
569 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
570 struct list_head *msgq)
572 struct rxrpc_message *msg;
574 _enter("");
576 /* only bother with the first packet */
577 msg = list_entry(msgq->next, struct rxrpc_message, link);
578 list_del_init(&msg->link);
579 rxrpc_krxsecd_queue_incoming_call(msg);
580 rxrpc_put_message(msg);
582 _leave(" = 0");
584 return 0;
585 } /* end rxrpc_trans_receive_new_call() */
587 /*****************************************************************************/
589 * perform an immediate abort without connection or call structures
591 int rxrpc_trans_immediate_abort(struct rxrpc_transport *trans,
592 struct rxrpc_message *msg,
593 int error)
595 struct rxrpc_header ahdr;
596 struct sockaddr_in sin;
597 struct msghdr msghdr;
598 struct kvec iov[2];
599 __be32 _error;
600 int len, ret;
602 _enter("%p,%p,%d", trans, msg, error);
604 /* don't abort an abort packet */
605 if (msg->hdr.type == RXRPC_PACKET_TYPE_ABORT) {
606 _leave(" = 0");
607 return 0;
610 _error = htonl(-error);
612 /* set up the message to be transmitted */
613 memcpy(&ahdr, &msg->hdr, sizeof(ahdr));
614 ahdr.epoch = msg->hdr.epoch;
615 ahdr.serial = htonl(1);
616 ahdr.seq = 0;
617 ahdr.type = RXRPC_PACKET_TYPE_ABORT;
618 ahdr.flags = RXRPC_LAST_PACKET;
619 ahdr.flags |= ~msg->hdr.flags & RXRPC_CLIENT_INITIATED;
621 iov[0].iov_len = sizeof(ahdr);
622 iov[0].iov_base = &ahdr;
623 iov[1].iov_len = sizeof(_error);
624 iov[1].iov_base = &_error;
626 len = sizeof(ahdr) + sizeof(_error);
628 memset(&sin,0,sizeof(sin));
629 sin.sin_family = AF_INET;
630 sin.sin_port = msg->pkt->h.uh->source;
631 sin.sin_addr.s_addr = msg->pkt->nh.iph->saddr;
633 msghdr.msg_name = &sin;
634 msghdr.msg_namelen = sizeof(sin);
635 msghdr.msg_control = NULL;
636 msghdr.msg_controllen = 0;
637 msghdr.msg_flags = MSG_DONTWAIT;
639 _net("Sending message type %d of %d bytes to %08x:%d",
640 ahdr.type,
641 len,
642 ntohl(sin.sin_addr.s_addr),
643 ntohs(sin.sin_port));
645 /* send the message */
646 ret = kernel_sendmsg(trans->socket, &msghdr, iov, 2, len);
648 _leave(" = %d", ret);
649 return ret;
650 } /* end rxrpc_trans_immediate_abort() */
652 /*****************************************************************************/
654 * receive an ICMP error report and percolate it to all connections
655 * heading to the affected host or port
657 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans)
659 struct rxrpc_connection *conn;
660 struct sockaddr_in sin;
661 struct rxrpc_peer *peer;
662 struct list_head connq, *_p;
663 struct errormsg emsg;
664 struct msghdr msg;
665 __be16 port;
666 int local, err;
668 _enter("%p", trans);
670 for (;;) {
671 trans->error_rcvd = 0;
673 /* try and receive an error message */
674 msg.msg_name = &sin;
675 msg.msg_namelen = sizeof(sin);
676 msg.msg_control = &emsg;
677 msg.msg_controllen = sizeof(emsg);
678 msg.msg_flags = 0;
680 err = kernel_recvmsg(trans->socket, &msg, NULL, 0, 0,
681 MSG_ERRQUEUE | MSG_DONTWAIT | MSG_TRUNC);
683 if (err == -EAGAIN) {
684 _leave("");
685 return;
688 if (err < 0) {
689 printk("%s: unable to recv an error report: %d\n",
690 __FUNCTION__, err);
691 _leave("");
692 return;
695 msg.msg_controllen = (char *) msg.msg_control - (char *) &emsg;
697 if (msg.msg_controllen < sizeof(emsg.cmsg) ||
698 msg.msg_namelen < sizeof(sin)) {
699 printk("%s: short control message"
700 " (nlen=%u clen=%Zu fl=%x)\n",
701 __FUNCTION__,
702 msg.msg_namelen,
703 msg.msg_controllen,
704 msg.msg_flags);
705 continue;
708 _net("Rx Received control message"
709 " { len=%Zu level=%u type=%u }",
710 emsg.cmsg.cmsg_len,
711 emsg.cmsg.cmsg_level,
712 emsg.cmsg.cmsg_type);
714 if (sin.sin_family != AF_INET) {
715 printk("Rx Ignoring error report with non-INET address"
716 " (fam=%u)",
717 sin.sin_family);
718 continue;
721 _net("Rx Received message pertaining to host addr=%x port=%hu",
722 ntohl(sin.sin_addr.s_addr), ntohs(sin.sin_port));
724 if (emsg.cmsg.cmsg_level != SOL_IP ||
725 emsg.cmsg.cmsg_type != IP_RECVERR) {
726 printk("Rx Ignoring unknown error report"
727 " { level=%u type=%u }",
728 emsg.cmsg.cmsg_level,
729 emsg.cmsg.cmsg_type);
730 continue;
733 if (msg.msg_controllen < sizeof(emsg.cmsg) + sizeof(emsg.ee)) {
734 printk("%s: short error message (%Zu)\n",
735 __FUNCTION__, msg.msg_controllen);
736 _leave("");
737 return;
740 port = sin.sin_port;
742 switch (emsg.ee.ee_origin) {
743 case SO_EE_ORIGIN_ICMP:
744 local = 0;
745 switch (emsg.ee.ee_type) {
746 case ICMP_DEST_UNREACH:
747 switch (emsg.ee.ee_code) {
748 case ICMP_NET_UNREACH:
749 _net("Rx Received ICMP Network Unreachable");
750 port = 0;
751 err = -ENETUNREACH;
752 break;
753 case ICMP_HOST_UNREACH:
754 _net("Rx Received ICMP Host Unreachable");
755 port = 0;
756 err = -EHOSTUNREACH;
757 break;
758 case ICMP_PORT_UNREACH:
759 _net("Rx Received ICMP Port Unreachable");
760 err = -ECONNREFUSED;
761 break;
762 case ICMP_NET_UNKNOWN:
763 _net("Rx Received ICMP Unknown Network");
764 port = 0;
765 err = -ENETUNREACH;
766 break;
767 case ICMP_HOST_UNKNOWN:
768 _net("Rx Received ICMP Unknown Host");
769 port = 0;
770 err = -EHOSTUNREACH;
771 break;
772 default:
773 _net("Rx Received ICMP DestUnreach { code=%u }",
774 emsg.ee.ee_code);
775 err = emsg.ee.ee_errno;
776 break;
778 break;
780 case ICMP_TIME_EXCEEDED:
781 _net("Rx Received ICMP TTL Exceeded");
782 err = emsg.ee.ee_errno;
783 break;
785 default:
786 _proto("Rx Received ICMP error { type=%u code=%u }",
787 emsg.ee.ee_type, emsg.ee.ee_code);
788 err = emsg.ee.ee_errno;
789 break;
791 break;
793 case SO_EE_ORIGIN_LOCAL:
794 _proto("Rx Received local error { error=%d }",
795 emsg.ee.ee_errno);
796 local = 1;
797 err = emsg.ee.ee_errno;
798 break;
800 case SO_EE_ORIGIN_NONE:
801 case SO_EE_ORIGIN_ICMP6:
802 default:
803 _proto("Rx Received error report { orig=%u }",
804 emsg.ee.ee_origin);
805 local = 0;
806 err = emsg.ee.ee_errno;
807 break;
810 /* find all the connections between this transport and the
811 * affected destination */
812 INIT_LIST_HEAD(&connq);
814 if (rxrpc_peer_lookup(trans, sin.sin_addr.s_addr,
815 &peer) == 0) {
816 read_lock(&peer->conn_lock);
817 list_for_each(_p, &peer->conn_active) {
818 conn = list_entry(_p, struct rxrpc_connection,
819 link);
820 if (port && conn->addr.sin_port != port)
821 continue;
822 if (!list_empty(&conn->err_link))
823 continue;
825 rxrpc_get_connection(conn);
826 list_add_tail(&conn->err_link, &connq);
828 read_unlock(&peer->conn_lock);
830 /* service all those connections */
831 while (!list_empty(&connq)) {
832 conn = list_entry(connq.next,
833 struct rxrpc_connection,
834 err_link);
835 list_del(&conn->err_link);
837 rxrpc_conn_handle_error(conn, local, err);
839 rxrpc_put_connection(conn);
842 rxrpc_put_peer(peer);
846 _leave("");
847 return;
848 } /* end rxrpc_trans_receive_error_report() */