[PATCH] ipw2100: Fix a gcc compile warning
[linux-2.6/verdex.git] / net / rxrpc / transport.c
blobdbe6105e83a54e1f9ce66b4466a2863e0d7f155f
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 = kmalloc(sizeof(struct rxrpc_transport), GFP_KERNEL);
72 if (!trans)
73 return -ENOMEM;
75 memset(trans, 0, sizeof(struct rxrpc_transport));
76 atomic_set(&trans->usage, 1);
77 INIT_LIST_HEAD(&trans->services);
78 INIT_LIST_HEAD(&trans->link);
79 INIT_LIST_HEAD(&trans->krxiodq_link);
80 spin_lock_init(&trans->lock);
81 INIT_LIST_HEAD(&trans->peer_active);
82 INIT_LIST_HEAD(&trans->peer_graveyard);
83 spin_lock_init(&trans->peer_gylock);
84 init_waitqueue_head(&trans->peer_gy_waitq);
85 rwlock_init(&trans->peer_lock);
86 atomic_set(&trans->peer_count, 0);
87 trans->port = port;
89 /* create a UDP socket to be my actual transport endpoint */
90 ret = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &trans->socket);
91 if (ret < 0)
92 goto error;
94 /* use the specified port */
95 if (port) {
96 memset(&sin, 0, sizeof(sin));
97 sin.sin_family = AF_INET;
98 sin.sin_port = htons(port);
99 ret = trans->socket->ops->bind(trans->socket,
100 (struct sockaddr *) &sin,
101 sizeof(sin));
102 if (ret < 0)
103 goto error;
106 opt = 1;
107 oldfs = get_fs();
108 set_fs(KERNEL_DS);
109 ret = trans->socket->ops->setsockopt(trans->socket, SOL_IP, IP_RECVERR,
110 (char *) &opt, sizeof(opt));
111 set_fs(oldfs);
113 spin_lock(&rxrpc_transports_lock);
114 list_add(&trans->link, &rxrpc_transports);
115 spin_unlock(&rxrpc_transports_lock);
117 /* set the socket up */
118 sock = trans->socket->sk;
119 sock->sk_user_data = trans;
120 sock->sk_data_ready = rxrpc_data_ready;
121 sock->sk_error_report = rxrpc_error_report;
123 down_write(&rxrpc_proc_transports_sem);
124 list_add_tail(&trans->proc_link, &rxrpc_proc_transports);
125 up_write(&rxrpc_proc_transports_sem);
127 __RXACCT(atomic_inc(&rxrpc_transport_count));
129 *_trans = trans;
130 _leave(" = 0 (%p)", trans);
131 return 0;
133 error:
134 /* finish cleaning up the transport (not really needed here, but...) */
135 if (trans->socket)
136 trans->socket->ops->shutdown(trans->socket, 2);
138 /* close the socket */
139 if (trans->socket) {
140 trans->socket->sk->sk_user_data = NULL;
141 sock_release(trans->socket);
142 trans->socket = NULL;
145 kfree(trans);
148 _leave(" = %d", ret);
149 return ret;
150 } /* end rxrpc_create_transport() */
152 /*****************************************************************************/
154 * destroy a transport endpoint
156 void rxrpc_put_transport(struct rxrpc_transport *trans)
158 _enter("%p{u=%d p=%hu}",
159 trans, atomic_read(&trans->usage), trans->port);
161 BUG_ON(atomic_read(&trans->usage) <= 0);
163 /* to prevent a race, the decrement and the dequeue must be
164 * effectively atomic */
165 spin_lock(&rxrpc_transports_lock);
166 if (likely(!atomic_dec_and_test(&trans->usage))) {
167 spin_unlock(&rxrpc_transports_lock);
168 _leave("");
169 return;
172 list_del(&trans->link);
173 spin_unlock(&rxrpc_transports_lock);
175 /* finish cleaning up the transport */
176 if (trans->socket)
177 trans->socket->ops->shutdown(trans->socket, 2);
179 rxrpc_krxsecd_clear_transport(trans);
180 rxrpc_krxiod_dequeue_transport(trans);
182 /* discard all peer information */
183 rxrpc_peer_clearall(trans);
185 down_write(&rxrpc_proc_transports_sem);
186 list_del(&trans->proc_link);
187 up_write(&rxrpc_proc_transports_sem);
188 __RXACCT(atomic_dec(&rxrpc_transport_count));
190 /* close the socket */
191 if (trans->socket) {
192 trans->socket->sk->sk_user_data = NULL;
193 sock_release(trans->socket);
194 trans->socket = NULL;
197 kfree(trans);
199 _leave("");
200 } /* end rxrpc_put_transport() */
202 /*****************************************************************************/
204 * add a service to a transport to be listened upon
206 int rxrpc_add_service(struct rxrpc_transport *trans,
207 struct rxrpc_service *newsrv)
209 struct rxrpc_service *srv;
210 struct list_head *_p;
211 int ret = -EEXIST;
213 _enter("%p{%hu},%p{%hu}",
214 trans, trans->port, newsrv, newsrv->service_id);
216 /* verify that the service ID is not already present */
217 spin_lock(&trans->lock);
219 list_for_each(_p, &trans->services) {
220 srv = list_entry(_p, struct rxrpc_service, link);
221 if (srv->service_id == newsrv->service_id)
222 goto out;
225 /* okay - add the transport to the list */
226 list_add_tail(&newsrv->link, &trans->services);
227 rxrpc_get_transport(trans);
228 ret = 0;
230 out:
231 spin_unlock(&trans->lock);
233 _leave("= %d", ret);
234 return ret;
235 } /* end rxrpc_add_service() */
237 /*****************************************************************************/
239 * remove a service from a transport
241 void rxrpc_del_service(struct rxrpc_transport *trans, struct rxrpc_service *srv)
243 _enter("%p{%hu},%p{%hu}", trans, trans->port, srv, srv->service_id);
245 spin_lock(&trans->lock);
246 list_del(&srv->link);
247 spin_unlock(&trans->lock);
249 rxrpc_put_transport(trans);
251 _leave("");
252 } /* end rxrpc_del_service() */
254 /*****************************************************************************/
256 * INET callback when data has been received on the socket.
258 static void rxrpc_data_ready(struct sock *sk, int count)
260 struct rxrpc_transport *trans;
262 _enter("%p{t=%p},%d", sk, sk->sk_user_data, count);
264 /* queue the transport for attention by krxiod */
265 trans = (struct rxrpc_transport *) sk->sk_user_data;
266 if (trans)
267 rxrpc_krxiod_queue_transport(trans);
269 /* wake up anyone waiting on the socket */
270 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
271 wake_up_interruptible(sk->sk_sleep);
273 _leave("");
274 } /* end rxrpc_data_ready() */
276 /*****************************************************************************/
278 * INET callback when an ICMP error packet is received
279 * - sk->err is error (EHOSTUNREACH, EPROTO or EMSGSIZE)
281 static void rxrpc_error_report(struct sock *sk)
283 struct rxrpc_transport *trans;
285 _enter("%p{t=%p}", sk, sk->sk_user_data);
287 /* queue the transport for attention by krxiod */
288 trans = (struct rxrpc_transport *) sk->sk_user_data;
289 if (trans) {
290 trans->error_rcvd = 1;
291 rxrpc_krxiod_queue_transport(trans);
294 /* wake up anyone waiting on the socket */
295 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
296 wake_up_interruptible(sk->sk_sleep);
298 _leave("");
299 } /* end rxrpc_error_report() */
301 /*****************************************************************************/
303 * split a message up, allocating message records and filling them in
304 * from the contents of a socket buffer
306 static int rxrpc_incoming_msg(struct rxrpc_transport *trans,
307 struct sk_buff *pkt,
308 struct list_head *msgq)
310 struct rxrpc_message *msg;
311 int ret;
313 _enter("");
315 msg = kmalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
316 if (!msg) {
317 _leave(" = -ENOMEM");
318 return -ENOMEM;
321 memset(msg, 0, sizeof(*msg));
322 atomic_set(&msg->usage, 1);
323 list_add_tail(&msg->link,msgq);
325 /* dig out the Rx routing parameters */
326 if (skb_copy_bits(pkt, sizeof(struct udphdr),
327 &msg->hdr, sizeof(msg->hdr)) < 0) {
328 ret = -EBADMSG;
329 goto error;
332 msg->trans = trans;
333 msg->state = RXRPC_MSG_RECEIVED;
334 skb_get_timestamp(pkt, &msg->stamp);
335 if (msg->stamp.tv_sec == 0) {
336 do_gettimeofday(&msg->stamp);
337 if (pkt->sk)
338 sock_enable_timestamp(pkt->sk);
340 msg->seq = ntohl(msg->hdr.seq);
342 /* attach the packet */
343 skb_get(pkt);
344 msg->pkt = pkt;
346 msg->offset = sizeof(struct udphdr) + sizeof(struct rxrpc_header);
347 msg->dsize = msg->pkt->len - msg->offset;
349 _net("Rx Received packet from %s (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
350 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
351 ntohl(msg->hdr.epoch),
352 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
353 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
354 ntohl(msg->hdr.callNumber),
355 rxrpc_pkts[msg->hdr.type],
356 msg->hdr.flags,
357 ntohs(msg->hdr.serviceId),
358 msg->hdr.securityIndex);
360 __RXACCT(atomic_inc(&rxrpc_message_count));
362 /* split off jumbo packets */
363 while (msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
364 msg->hdr.flags & RXRPC_JUMBO_PACKET
366 struct rxrpc_jumbo_header jumbo;
367 struct rxrpc_message *jumbomsg = msg;
369 _debug("split jumbo packet");
371 /* quick sanity check */
372 ret = -EBADMSG;
373 if (msg->dsize <
374 RXRPC_JUMBO_DATALEN + sizeof(struct rxrpc_jumbo_header))
375 goto error;
376 if (msg->hdr.flags & RXRPC_LAST_PACKET)
377 goto error;
379 /* dig out the secondary header */
380 if (skb_copy_bits(pkt, msg->offset + RXRPC_JUMBO_DATALEN,
381 &jumbo, sizeof(jumbo)) < 0)
382 goto error;
384 /* allocate a new message record */
385 ret = -ENOMEM;
386 msg = kmalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
387 if (!msg)
388 goto error;
390 memcpy(msg, jumbomsg, sizeof(*msg));
391 list_add_tail(&msg->link, msgq);
393 /* adjust the jumbo packet */
394 jumbomsg->dsize = RXRPC_JUMBO_DATALEN;
396 /* attach the packet here too */
397 skb_get(pkt);
399 /* adjust the parameters */
400 msg->seq++;
401 msg->hdr.seq = htonl(msg->seq);
402 msg->hdr.serial = htonl(ntohl(msg->hdr.serial) + 1);
403 msg->offset += RXRPC_JUMBO_DATALEN +
404 sizeof(struct rxrpc_jumbo_header);
405 msg->dsize -= RXRPC_JUMBO_DATALEN +
406 sizeof(struct rxrpc_jumbo_header);
407 msg->hdr.flags = jumbo.flags;
408 msg->hdr._rsvd = jumbo._rsvd;
410 _net("Rx Split jumbo packet from %s"
411 " (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
412 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
413 ntohl(msg->hdr.epoch),
414 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
415 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
416 ntohl(msg->hdr.callNumber),
417 rxrpc_pkts[msg->hdr.type],
418 msg->hdr.flags,
419 ntohs(msg->hdr.serviceId),
420 msg->hdr.securityIndex);
422 __RXACCT(atomic_inc(&rxrpc_message_count));
425 _leave(" = 0 #%d", atomic_read(&rxrpc_message_count));
426 return 0;
428 error:
429 while (!list_empty(msgq)) {
430 msg = list_entry(msgq->next, struct rxrpc_message, link);
431 list_del_init(&msg->link);
433 rxrpc_put_message(msg);
436 _leave(" = %d", ret);
437 return ret;
438 } /* end rxrpc_incoming_msg() */
440 /*****************************************************************************/
442 * accept a new call
443 * - called from krxiod in process context
445 void rxrpc_trans_receive_packet(struct rxrpc_transport *trans)
447 struct rxrpc_message *msg;
448 struct rxrpc_peer *peer;
449 struct sk_buff *pkt;
450 int ret;
451 __be32 addr;
452 __be16 port;
454 LIST_HEAD(msgq);
456 _enter("%p{%d}", trans, trans->port);
458 for (;;) {
459 /* deal with outstanting errors first */
460 if (trans->error_rcvd)
461 rxrpc_trans_receive_error_report(trans);
463 /* attempt to receive a packet */
464 pkt = skb_recv_datagram(trans->socket->sk, 0, 1, &ret);
465 if (!pkt) {
466 if (ret == -EAGAIN) {
467 _leave(" EAGAIN");
468 return;
471 /* an icmp error may have occurred */
472 rxrpc_krxiod_queue_transport(trans);
473 _leave(" error %d\n", ret);
474 return;
477 /* we'll probably need to checksum it (didn't call
478 * sock_recvmsg) */
479 if (skb_checksum_complete(pkt)) {
480 kfree_skb(pkt);
481 rxrpc_krxiod_queue_transport(trans);
482 _leave(" CSUM failed");
483 return;
486 addr = pkt->nh.iph->saddr;
487 port = pkt->h.uh->source;
489 _net("Rx Received UDP packet from %08x:%04hu",
490 ntohl(addr), ntohs(port));
492 /* unmarshall the Rx parameters and split jumbo packets */
493 ret = rxrpc_incoming_msg(trans, pkt, &msgq);
494 if (ret < 0) {
495 kfree_skb(pkt);
496 rxrpc_krxiod_queue_transport(trans);
497 _leave(" bad packet");
498 return;
501 BUG_ON(list_empty(&msgq));
503 msg = list_entry(msgq.next, struct rxrpc_message, link);
505 /* locate the record for the peer from which it
506 * originated */
507 ret = rxrpc_peer_lookup(trans, addr, &peer);
508 if (ret < 0) {
509 kdebug("Rx No connections from that peer");
510 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
511 goto finished_msg;
514 /* try and find a matching connection */
515 ret = rxrpc_connection_lookup(peer, msg, &msg->conn);
516 if (ret < 0) {
517 kdebug("Rx Unknown Connection");
518 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
519 rxrpc_put_peer(peer);
520 goto finished_msg;
522 rxrpc_put_peer(peer);
524 /* deal with the first packet of a new call */
525 if (msg->hdr.flags & RXRPC_CLIENT_INITIATED &&
526 msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
527 ntohl(msg->hdr.seq) == 1
529 _debug("Rx New server call");
530 rxrpc_trans_receive_new_call(trans, &msgq);
531 goto finished_msg;
534 /* deal with subsequent packet(s) of call */
535 _debug("Rx Call packet");
536 while (!list_empty(&msgq)) {
537 msg = list_entry(msgq.next, struct rxrpc_message, link);
538 list_del_init(&msg->link);
540 ret = rxrpc_conn_receive_call_packet(msg->conn, NULL, msg);
541 if (ret < 0) {
542 rxrpc_trans_immediate_abort(trans, msg, ret);
543 rxrpc_put_message(msg);
544 goto finished_msg;
547 rxrpc_put_message(msg);
550 goto finished_msg;
552 /* dispose of the packets */
553 finished_msg:
554 while (!list_empty(&msgq)) {
555 msg = list_entry(msgq.next, struct rxrpc_message, link);
556 list_del_init(&msg->link);
558 rxrpc_put_message(msg);
560 kfree_skb(pkt);
563 _leave("");
565 } /* end rxrpc_trans_receive_packet() */
567 /*****************************************************************************/
569 * accept a new call from a client trying to connect to one of my services
570 * - called in process context
572 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
573 struct list_head *msgq)
575 struct rxrpc_message *msg;
577 _enter("");
579 /* only bother with the first packet */
580 msg = list_entry(msgq->next, struct rxrpc_message, link);
581 list_del_init(&msg->link);
582 rxrpc_krxsecd_queue_incoming_call(msg);
583 rxrpc_put_message(msg);
585 _leave(" = 0");
587 return 0;
588 } /* end rxrpc_trans_receive_new_call() */
590 /*****************************************************************************/
592 * perform an immediate abort without connection or call structures
594 int rxrpc_trans_immediate_abort(struct rxrpc_transport *trans,
595 struct rxrpc_message *msg,
596 int error)
598 struct rxrpc_header ahdr;
599 struct sockaddr_in sin;
600 struct msghdr msghdr;
601 struct kvec iov[2];
602 __be32 _error;
603 int len, ret;
605 _enter("%p,%p,%d", trans, msg, error);
607 /* don't abort an abort packet */
608 if (msg->hdr.type == RXRPC_PACKET_TYPE_ABORT) {
609 _leave(" = 0");
610 return 0;
613 _error = htonl(-error);
615 /* set up the message to be transmitted */
616 memcpy(&ahdr, &msg->hdr, sizeof(ahdr));
617 ahdr.epoch = msg->hdr.epoch;
618 ahdr.serial = htonl(1);
619 ahdr.seq = 0;
620 ahdr.type = RXRPC_PACKET_TYPE_ABORT;
621 ahdr.flags = RXRPC_LAST_PACKET;
622 ahdr.flags |= ~msg->hdr.flags & RXRPC_CLIENT_INITIATED;
624 iov[0].iov_len = sizeof(ahdr);
625 iov[0].iov_base = &ahdr;
626 iov[1].iov_len = sizeof(_error);
627 iov[1].iov_base = &_error;
629 len = sizeof(ahdr) + sizeof(_error);
631 memset(&sin,0,sizeof(sin));
632 sin.sin_family = AF_INET;
633 sin.sin_port = msg->pkt->h.uh->source;
634 sin.sin_addr.s_addr = msg->pkt->nh.iph->saddr;
636 msghdr.msg_name = &sin;
637 msghdr.msg_namelen = sizeof(sin);
638 msghdr.msg_control = NULL;
639 msghdr.msg_controllen = 0;
640 msghdr.msg_flags = MSG_DONTWAIT;
642 _net("Sending message type %d of %d bytes to %08x:%d",
643 ahdr.type,
644 len,
645 ntohl(sin.sin_addr.s_addr),
646 ntohs(sin.sin_port));
648 /* send the message */
649 ret = kernel_sendmsg(trans->socket, &msghdr, iov, 2, len);
651 _leave(" = %d", ret);
652 return ret;
653 } /* end rxrpc_trans_immediate_abort() */
655 /*****************************************************************************/
657 * receive an ICMP error report and percolate it to all connections
658 * heading to the affected host or port
660 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans)
662 struct rxrpc_connection *conn;
663 struct sockaddr_in sin;
664 struct rxrpc_peer *peer;
665 struct list_head connq, *_p;
666 struct errormsg emsg;
667 struct msghdr msg;
668 __be16 port;
669 int local, err;
671 _enter("%p", trans);
673 for (;;) {
674 trans->error_rcvd = 0;
676 /* try and receive an error message */
677 msg.msg_name = &sin;
678 msg.msg_namelen = sizeof(sin);
679 msg.msg_control = &emsg;
680 msg.msg_controllen = sizeof(emsg);
681 msg.msg_flags = 0;
683 err = kernel_recvmsg(trans->socket, &msg, NULL, 0, 0,
684 MSG_ERRQUEUE | MSG_DONTWAIT | MSG_TRUNC);
686 if (err == -EAGAIN) {
687 _leave("");
688 return;
691 if (err < 0) {
692 printk("%s: unable to recv an error report: %d\n",
693 __FUNCTION__, err);
694 _leave("");
695 return;
698 msg.msg_controllen = (char *) msg.msg_control - (char *) &emsg;
700 if (msg.msg_controllen < sizeof(emsg.cmsg) ||
701 msg.msg_namelen < sizeof(sin)) {
702 printk("%s: short control message"
703 " (nlen=%u clen=%Zu fl=%x)\n",
704 __FUNCTION__,
705 msg.msg_namelen,
706 msg.msg_controllen,
707 msg.msg_flags);
708 continue;
711 _net("Rx Received control message"
712 " { len=%Zu level=%u type=%u }",
713 emsg.cmsg.cmsg_len,
714 emsg.cmsg.cmsg_level,
715 emsg.cmsg.cmsg_type);
717 if (sin.sin_family != AF_INET) {
718 printk("Rx Ignoring error report with non-INET address"
719 " (fam=%u)",
720 sin.sin_family);
721 continue;
724 _net("Rx Received message pertaining to host addr=%x port=%hu",
725 ntohl(sin.sin_addr.s_addr), ntohs(sin.sin_port));
727 if (emsg.cmsg.cmsg_level != SOL_IP ||
728 emsg.cmsg.cmsg_type != IP_RECVERR) {
729 printk("Rx Ignoring unknown error report"
730 " { level=%u type=%u }",
731 emsg.cmsg.cmsg_level,
732 emsg.cmsg.cmsg_type);
733 continue;
736 if (msg.msg_controllen < sizeof(emsg.cmsg) + sizeof(emsg.ee)) {
737 printk("%s: short error message (%Zu)\n",
738 __FUNCTION__, msg.msg_controllen);
739 _leave("");
740 return;
743 port = sin.sin_port;
745 switch (emsg.ee.ee_origin) {
746 case SO_EE_ORIGIN_ICMP:
747 local = 0;
748 switch (emsg.ee.ee_type) {
749 case ICMP_DEST_UNREACH:
750 switch (emsg.ee.ee_code) {
751 case ICMP_NET_UNREACH:
752 _net("Rx Received ICMP Network Unreachable");
753 port = 0;
754 err = -ENETUNREACH;
755 break;
756 case ICMP_HOST_UNREACH:
757 _net("Rx Received ICMP Host Unreachable");
758 port = 0;
759 err = -EHOSTUNREACH;
760 break;
761 case ICMP_PORT_UNREACH:
762 _net("Rx Received ICMP Port Unreachable");
763 err = -ECONNREFUSED;
764 break;
765 case ICMP_NET_UNKNOWN:
766 _net("Rx Received ICMP Unknown Network");
767 port = 0;
768 err = -ENETUNREACH;
769 break;
770 case ICMP_HOST_UNKNOWN:
771 _net("Rx Received ICMP Unknown Host");
772 port = 0;
773 err = -EHOSTUNREACH;
774 break;
775 default:
776 _net("Rx Received ICMP DestUnreach { code=%u }",
777 emsg.ee.ee_code);
778 err = emsg.ee.ee_errno;
779 break;
781 break;
783 case ICMP_TIME_EXCEEDED:
784 _net("Rx Received ICMP TTL Exceeded");
785 err = emsg.ee.ee_errno;
786 break;
788 default:
789 _proto("Rx Received ICMP error { type=%u code=%u }",
790 emsg.ee.ee_type, emsg.ee.ee_code);
791 err = emsg.ee.ee_errno;
792 break;
794 break;
796 case SO_EE_ORIGIN_LOCAL:
797 _proto("Rx Received local error { error=%d }",
798 emsg.ee.ee_errno);
799 local = 1;
800 err = emsg.ee.ee_errno;
801 break;
803 case SO_EE_ORIGIN_NONE:
804 case SO_EE_ORIGIN_ICMP6:
805 default:
806 _proto("Rx Received error report { orig=%u }",
807 emsg.ee.ee_origin);
808 local = 0;
809 err = emsg.ee.ee_errno;
810 break;
813 /* find all the connections between this transport and the
814 * affected destination */
815 INIT_LIST_HEAD(&connq);
817 if (rxrpc_peer_lookup(trans, sin.sin_addr.s_addr,
818 &peer) == 0) {
819 read_lock(&peer->conn_lock);
820 list_for_each(_p, &peer->conn_active) {
821 conn = list_entry(_p, struct rxrpc_connection,
822 link);
823 if (port && conn->addr.sin_port != port)
824 continue;
825 if (!list_empty(&conn->err_link))
826 continue;
828 rxrpc_get_connection(conn);
829 list_add_tail(&conn->err_link, &connq);
831 read_unlock(&peer->conn_lock);
833 /* service all those connections */
834 while (!list_empty(&connq)) {
835 conn = list_entry(connq.next,
836 struct rxrpc_connection,
837 err_link);
838 list_del(&conn->err_link);
840 rxrpc_conn_handle_error(conn, local, err);
842 rxrpc_put_connection(conn);
845 rxrpc_put_peer(peer);
849 _leave("");
850 return;
851 } /* end rxrpc_trans_receive_error_report() */