initial commit with v2.6.9
[linux-2.6.9-moxart.git] / net / rxrpc / transport.c
blob7e015ceecee5fa8a6e254b4531f96a0ea0b2725b
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 <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 <asm/checksum.h>
34 #include "internal.h"
36 struct errormsg {
37 struct cmsghdr cmsg; /* control message header */
38 struct sock_extended_err ee; /* extended error information */
39 struct sockaddr_in icmp_src; /* ICMP packet source address */
42 static spinlock_t rxrpc_transports_lock = SPIN_LOCK_UNLOCKED;
43 static struct list_head rxrpc_transports = LIST_HEAD_INIT(rxrpc_transports);
45 __RXACCT_DECL(atomic_t rxrpc_transport_count);
46 LIST_HEAD(rxrpc_proc_transports);
47 DECLARE_RWSEM(rxrpc_proc_transports_sem);
49 static void rxrpc_data_ready(struct sock *sk, int count);
50 static void rxrpc_error_report(struct sock *sk);
51 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
52 struct list_head *msgq);
53 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans);
55 /*****************************************************************************/
57 * create a new transport endpoint using the specified UDP port
59 int rxrpc_create_transport(unsigned short port,
60 struct rxrpc_transport **_trans)
62 struct rxrpc_transport *trans;
63 struct sockaddr_in sin;
64 mm_segment_t oldfs;
65 struct sock *sock;
66 int ret, opt;
68 _enter("%hu", port);
70 trans = kmalloc(sizeof(struct rxrpc_transport), GFP_KERNEL);
71 if (!trans)
72 return -ENOMEM;
74 memset(trans, 0, sizeof(struct rxrpc_transport));
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 * clear the connections on a transport endpoint
155 void rxrpc_clear_transport(struct rxrpc_transport *trans)
157 //struct rxrpc_connection *conn;
159 } /* end rxrpc_clear_transport() */
161 /*****************************************************************************/
163 * destroy a transport endpoint
165 void rxrpc_put_transport(struct rxrpc_transport *trans)
167 _enter("%p{u=%d p=%hu}",
168 trans, atomic_read(&trans->usage), trans->port);
170 BUG_ON(atomic_read(&trans->usage) <= 0);
172 /* to prevent a race, the decrement and the dequeue must be
173 * effectively atomic */
174 spin_lock(&rxrpc_transports_lock);
175 if (likely(!atomic_dec_and_test(&trans->usage))) {
176 spin_unlock(&rxrpc_transports_lock);
177 _leave("");
178 return;
181 list_del(&trans->link);
182 spin_unlock(&rxrpc_transports_lock);
184 /* finish cleaning up the transport */
185 if (trans->socket)
186 trans->socket->ops->shutdown(trans->socket, 2);
188 rxrpc_krxsecd_clear_transport(trans);
189 rxrpc_krxiod_dequeue_transport(trans);
191 /* discard all peer information */
192 rxrpc_peer_clearall(trans);
194 down_write(&rxrpc_proc_transports_sem);
195 list_del(&trans->proc_link);
196 up_write(&rxrpc_proc_transports_sem);
197 __RXACCT(atomic_dec(&rxrpc_transport_count));
199 /* close the socket */
200 if (trans->socket) {
201 trans->socket->sk->sk_user_data = NULL;
202 sock_release(trans->socket);
203 trans->socket = NULL;
206 kfree(trans);
208 _leave("");
209 } /* end rxrpc_put_transport() */
211 /*****************************************************************************/
213 * add a service to a transport to be listened upon
215 int rxrpc_add_service(struct rxrpc_transport *trans,
216 struct rxrpc_service *newsrv)
218 struct rxrpc_service *srv;
219 struct list_head *_p;
220 int ret = -EEXIST;
222 _enter("%p{%hu},%p{%hu}",
223 trans, trans->port, newsrv, newsrv->service_id);
225 /* verify that the service ID is not already present */
226 spin_lock(&trans->lock);
228 list_for_each(_p, &trans->services) {
229 srv = list_entry(_p, struct rxrpc_service, link);
230 if (srv->service_id == newsrv->service_id)
231 goto out;
234 /* okay - add the transport to the list */
235 list_add_tail(&newsrv->link, &trans->services);
236 rxrpc_get_transport(trans);
237 ret = 0;
239 out:
240 spin_unlock(&trans->lock);
242 _leave("= %d", ret);
243 return ret;
244 } /* end rxrpc_add_service() */
246 /*****************************************************************************/
248 * remove a service from a transport
250 void rxrpc_del_service(struct rxrpc_transport *trans, struct rxrpc_service *srv)
252 _enter("%p{%hu},%p{%hu}", trans, trans->port, srv, srv->service_id);
254 spin_lock(&trans->lock);
255 list_del(&srv->link);
256 spin_unlock(&trans->lock);
258 rxrpc_put_transport(trans);
260 _leave("");
261 } /* end rxrpc_del_service() */
263 /*****************************************************************************/
265 * INET callback when data has been received on the socket.
267 static void rxrpc_data_ready(struct sock *sk, int count)
269 struct rxrpc_transport *trans;
271 _enter("%p{t=%p},%d", sk, sk->sk_user_data, count);
273 /* queue the transport for attention by krxiod */
274 trans = (struct rxrpc_transport *) sk->sk_user_data;
275 if (trans)
276 rxrpc_krxiod_queue_transport(trans);
278 /* wake up anyone waiting on the socket */
279 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
280 wake_up_interruptible(sk->sk_sleep);
282 _leave("");
283 } /* end rxrpc_data_ready() */
285 /*****************************************************************************/
287 * INET callback when an ICMP error packet is received
288 * - sk->err is error (EHOSTUNREACH, EPROTO or EMSGSIZE)
290 static void rxrpc_error_report(struct sock *sk)
292 struct rxrpc_transport *trans;
294 _enter("%p{t=%p}", sk, sk->sk_user_data);
296 /* queue the transport for attention by krxiod */
297 trans = (struct rxrpc_transport *) sk->sk_user_data;
298 if (trans) {
299 trans->error_rcvd = 1;
300 rxrpc_krxiod_queue_transport(trans);
303 /* wake up anyone waiting on the socket */
304 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
305 wake_up_interruptible(sk->sk_sleep);
307 _leave("");
308 } /* end rxrpc_error_report() */
310 /*****************************************************************************/
312 * split a message up, allocating message records and filling them in
313 * from the contents of a socket buffer
315 static int rxrpc_incoming_msg(struct rxrpc_transport *trans,
316 struct sk_buff *pkt,
317 struct list_head *msgq)
319 struct rxrpc_message *msg;
320 int ret;
322 _enter("");
324 msg = kmalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
325 if (!msg) {
326 _leave(" = -ENOMEM");
327 return -ENOMEM;
330 memset(msg, 0, sizeof(*msg));
331 atomic_set(&msg->usage, 1);
332 list_add_tail(&msg->link,msgq);
334 /* dig out the Rx routing parameters */
335 if (skb_copy_bits(pkt, sizeof(struct udphdr),
336 &msg->hdr, sizeof(msg->hdr)) < 0) {
337 ret = -EBADMSG;
338 goto error;
341 msg->trans = trans;
342 msg->state = RXRPC_MSG_RECEIVED;
343 msg->stamp = pkt->stamp;
344 if (msg->stamp.tv_sec == 0) {
345 do_gettimeofday(&msg->stamp);
346 if (pkt->sk)
347 sock_enable_timestamp(pkt->sk);
349 msg->seq = ntohl(msg->hdr.seq);
351 /* attach the packet */
352 skb_get(pkt);
353 msg->pkt = pkt;
355 msg->offset = sizeof(struct udphdr) + sizeof(struct rxrpc_header);
356 msg->dsize = msg->pkt->len - msg->offset;
358 _net("Rx Received packet from %s (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
359 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
360 ntohl(msg->hdr.epoch),
361 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
362 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
363 ntohl(msg->hdr.callNumber),
364 rxrpc_pkts[msg->hdr.type],
365 msg->hdr.flags,
366 ntohs(msg->hdr.serviceId),
367 msg->hdr.securityIndex);
369 __RXACCT(atomic_inc(&rxrpc_message_count));
371 /* split off jumbo packets */
372 while (msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
373 msg->hdr.flags & RXRPC_JUMBO_PACKET
375 struct rxrpc_jumbo_header jumbo;
376 struct rxrpc_message *jumbomsg = msg;
378 _debug("split jumbo packet");
380 /* quick sanity check */
381 ret = -EBADMSG;
382 if (msg->dsize <
383 RXRPC_JUMBO_DATALEN + sizeof(struct rxrpc_jumbo_header))
384 goto error;
385 if (msg->hdr.flags & RXRPC_LAST_PACKET)
386 goto error;
388 /* dig out the secondary header */
389 if (skb_copy_bits(pkt, msg->offset + RXRPC_JUMBO_DATALEN,
390 &jumbo, sizeof(jumbo)) < 0)
391 goto error;
393 /* allocate a new message record */
394 ret = -ENOMEM;
395 msg = kmalloc(sizeof(struct rxrpc_message), GFP_KERNEL);
396 if (!msg)
397 goto error;
399 memcpy(msg, jumbomsg, sizeof(*msg));
400 list_add_tail(&msg->link, msgq);
402 /* adjust the jumbo packet */
403 jumbomsg->dsize = RXRPC_JUMBO_DATALEN;
405 /* attach the packet here too */
406 skb_get(pkt);
408 /* adjust the parameters */
409 msg->seq++;
410 msg->hdr.seq = htonl(msg->seq);
411 msg->hdr.serial = htonl(ntohl(msg->hdr.serial) + 1);
412 msg->offset += RXRPC_JUMBO_DATALEN +
413 sizeof(struct rxrpc_jumbo_header);
414 msg->dsize -= RXRPC_JUMBO_DATALEN +
415 sizeof(struct rxrpc_jumbo_header);
416 msg->hdr.flags = jumbo.flags;
417 msg->hdr._rsvd = jumbo._rsvd;
419 _net("Rx Split jumbo packet from %s"
420 " (%08x;%08x,%1x,%d,%s,%02x,%d,%d)",
421 msg->hdr.flags & RXRPC_CLIENT_INITIATED ? "client" : "server",
422 ntohl(msg->hdr.epoch),
423 (ntohl(msg->hdr.cid) & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT,
424 ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK,
425 ntohl(msg->hdr.callNumber),
426 rxrpc_pkts[msg->hdr.type],
427 msg->hdr.flags,
428 ntohs(msg->hdr.serviceId),
429 msg->hdr.securityIndex);
431 __RXACCT(atomic_inc(&rxrpc_message_count));
434 _leave(" = 0 #%d", atomic_read(&rxrpc_message_count));
435 return 0;
437 error:
438 while (!list_empty(msgq)) {
439 msg = list_entry(msgq->next, struct rxrpc_message, link);
440 list_del_init(&msg->link);
442 rxrpc_put_message(msg);
445 _leave(" = %d", ret);
446 return ret;
447 } /* end rxrpc_incoming_msg() */
449 /*****************************************************************************/
451 * accept a new call
452 * - called from krxiod in process context
454 void rxrpc_trans_receive_packet(struct rxrpc_transport *trans)
456 struct rxrpc_message *msg;
457 struct rxrpc_peer *peer;
458 struct sk_buff *pkt;
459 int ret;
460 __be32 addr;
461 __be16 port;
463 LIST_HEAD(msgq);
465 _enter("%p{%d}", trans, trans->port);
467 for (;;) {
468 /* deal with outstanting errors first */
469 if (trans->error_rcvd)
470 rxrpc_trans_receive_error_report(trans);
472 /* attempt to receive a packet */
473 pkt = skb_recv_datagram(trans->socket->sk, 0, 1, &ret);
474 if (!pkt) {
475 if (ret == -EAGAIN) {
476 _leave(" EAGAIN");
477 return;
480 /* an icmp error may have occurred */
481 rxrpc_krxiod_queue_transport(trans);
482 _leave(" error %d\n", ret);
483 return;
486 /* we'll probably need to checksum it (didn't call
487 * sock_recvmsg) */
488 if (pkt->ip_summed != CHECKSUM_UNNECESSARY) {
489 if ((unsigned short)
490 csum_fold(skb_checksum(pkt, 0, pkt->len,
491 pkt->csum))) {
492 kfree_skb(pkt);
493 rxrpc_krxiod_queue_transport(trans);
494 _leave(" CSUM failed");
495 return;
499 addr = pkt->nh.iph->saddr;
500 port = pkt->h.uh->source;
502 _net("Rx Received UDP packet from %08x:%04hu",
503 ntohl(addr), ntohs(port));
505 /* unmarshall the Rx parameters and split jumbo packets */
506 ret = rxrpc_incoming_msg(trans, pkt, &msgq);
507 if (ret < 0) {
508 kfree_skb(pkt);
509 rxrpc_krxiod_queue_transport(trans);
510 _leave(" bad packet");
511 return;
514 BUG_ON(list_empty(&msgq));
516 msg = list_entry(msgq.next, struct rxrpc_message, link);
518 /* locate the record for the peer from which it
519 * originated */
520 ret = rxrpc_peer_lookup(trans, addr, &peer);
521 if (ret < 0) {
522 kdebug("Rx No connections from that peer");
523 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
524 goto finished_msg;
527 /* try and find a matching connection */
528 ret = rxrpc_connection_lookup(peer, msg, &msg->conn);
529 if (ret < 0) {
530 kdebug("Rx Unknown Connection");
531 rxrpc_trans_immediate_abort(trans, msg, -EINVAL);
532 rxrpc_put_peer(peer);
533 goto finished_msg;
535 rxrpc_put_peer(peer);
537 /* deal with the first packet of a new call */
538 if (msg->hdr.flags & RXRPC_CLIENT_INITIATED &&
539 msg->hdr.type == RXRPC_PACKET_TYPE_DATA &&
540 ntohl(msg->hdr.seq) == 1
542 _debug("Rx New server call");
543 rxrpc_trans_receive_new_call(trans, &msgq);
544 goto finished_msg;
547 /* deal with subsequent packet(s) of call */
548 _debug("Rx Call packet");
549 while (!list_empty(&msgq)) {
550 msg = list_entry(msgq.next, struct rxrpc_message, link);
551 list_del_init(&msg->link);
553 ret = rxrpc_conn_receive_call_packet(msg->conn, NULL, msg);
554 if (ret < 0) {
555 rxrpc_trans_immediate_abort(trans, msg, ret);
556 rxrpc_put_message(msg);
557 goto finished_msg;
560 rxrpc_put_message(msg);
563 goto finished_msg;
565 /* dispose of the packets */
566 finished_msg:
567 while (!list_empty(&msgq)) {
568 msg = list_entry(msgq.next, struct rxrpc_message, link);
569 list_del_init(&msg->link);
571 rxrpc_put_message(msg);
573 kfree_skb(pkt);
576 _leave("");
578 } /* end rxrpc_trans_receive_packet() */
580 /*****************************************************************************/
582 * accept a new call from a client trying to connect to one of my services
583 * - called in process context
585 static int rxrpc_trans_receive_new_call(struct rxrpc_transport *trans,
586 struct list_head *msgq)
588 struct rxrpc_message *msg;
590 _enter("");
592 /* only bother with the first packet */
593 msg = list_entry(msgq->next, struct rxrpc_message, link);
594 list_del_init(&msg->link);
595 rxrpc_krxsecd_queue_incoming_call(msg);
596 rxrpc_put_message(msg);
598 _leave(" = 0");
600 return 0;
601 } /* end rxrpc_trans_receive_new_call() */
603 /*****************************************************************************/
605 * perform an immediate abort without connection or call structures
607 int rxrpc_trans_immediate_abort(struct rxrpc_transport *trans,
608 struct rxrpc_message *msg,
609 int error)
611 struct rxrpc_header ahdr;
612 struct sockaddr_in sin;
613 struct msghdr msghdr;
614 struct kvec iov[2];
615 __be32 _error;
616 int len, ret;
618 _enter("%p,%p,%d", trans, msg, error);
620 /* don't abort an abort packet */
621 if (msg->hdr.type == RXRPC_PACKET_TYPE_ABORT) {
622 _leave(" = 0");
623 return 0;
626 _error = htonl(-error);
628 /* set up the message to be transmitted */
629 memcpy(&ahdr, &msg->hdr, sizeof(ahdr));
630 ahdr.epoch = msg->hdr.epoch;
631 ahdr.serial = htonl(1);
632 ahdr.seq = 0;
633 ahdr.type = RXRPC_PACKET_TYPE_ABORT;
634 ahdr.flags = RXRPC_LAST_PACKET;
635 ahdr.flags |= ~msg->hdr.flags & RXRPC_CLIENT_INITIATED;
637 iov[0].iov_len = sizeof(ahdr);
638 iov[0].iov_base = &ahdr;
639 iov[1].iov_len = sizeof(_error);
640 iov[1].iov_base = &_error;
642 len = sizeof(ahdr) + sizeof(_error);
644 memset(&sin,0,sizeof(sin));
645 sin.sin_family = AF_INET;
646 sin.sin_port = msg->pkt->h.uh->source;
647 sin.sin_addr.s_addr = msg->pkt->nh.iph->saddr;
649 msghdr.msg_name = &sin;
650 msghdr.msg_namelen = sizeof(sin);
651 msghdr.msg_control = NULL;
652 msghdr.msg_controllen = 0;
653 msghdr.msg_flags = MSG_DONTWAIT;
655 _net("Sending message type %d of %d bytes to %08x:%d",
656 ahdr.type,
657 len,
658 ntohl(sin.sin_addr.s_addr),
659 ntohs(sin.sin_port));
661 /* send the message */
662 ret = kernel_sendmsg(trans->socket, &msghdr, iov, 2, len);
664 _leave(" = %d", ret);
665 return ret;
666 } /* end rxrpc_trans_immediate_abort() */
668 /*****************************************************************************/
670 * receive an ICMP error report and percolate it to all connections
671 * heading to the affected host or port
673 static void rxrpc_trans_receive_error_report(struct rxrpc_transport *trans)
675 struct rxrpc_connection *conn;
676 struct sockaddr_in sin;
677 struct rxrpc_peer *peer;
678 struct list_head connq, *_p;
679 struct errormsg emsg;
680 struct msghdr msg;
681 __be16 port;
682 int local, err;
684 _enter("%p", trans);
686 for (;;) {
687 trans->error_rcvd = 0;
689 /* try and receive an error message */
690 msg.msg_name = &sin;
691 msg.msg_namelen = sizeof(sin);
692 msg.msg_control = &emsg;
693 msg.msg_controllen = sizeof(emsg);
694 msg.msg_flags = 0;
696 err = kernel_recvmsg(trans->socket, &msg, NULL, 0, 0,
697 MSG_ERRQUEUE | MSG_DONTWAIT | MSG_TRUNC);
699 if (err == -EAGAIN) {
700 _leave("");
701 return;
704 if (err < 0) {
705 printk("%s: unable to recv an error report: %d\n",
706 __FUNCTION__, err);
707 _leave("");
708 return;
711 msg.msg_controllen = (char *) msg.msg_control - (char *) &emsg;
713 if (msg.msg_controllen < sizeof(emsg.cmsg) ||
714 msg.msg_namelen < sizeof(sin)) {
715 printk("%s: short control message"
716 " (nlen=%u clen=%Zu fl=%x)\n",
717 __FUNCTION__,
718 msg.msg_namelen,
719 msg.msg_controllen,
720 msg.msg_flags);
721 continue;
724 _net("Rx Received control message"
725 " { len=%Zu level=%u type=%u }",
726 emsg.cmsg.cmsg_len,
727 emsg.cmsg.cmsg_level,
728 emsg.cmsg.cmsg_type);
730 if (sin.sin_family != AF_INET) {
731 printk("Rx Ignoring error report with non-INET address"
732 " (fam=%u)",
733 sin.sin_family);
734 continue;
737 _net("Rx Received message pertaining to host addr=%x port=%hu",
738 ntohl(sin.sin_addr.s_addr), ntohs(sin.sin_port));
740 if (emsg.cmsg.cmsg_level != SOL_IP ||
741 emsg.cmsg.cmsg_type != IP_RECVERR) {
742 printk("Rx Ignoring unknown error report"
743 " { level=%u type=%u }",
744 emsg.cmsg.cmsg_level,
745 emsg.cmsg.cmsg_type);
746 continue;
749 if (msg.msg_controllen < sizeof(emsg.cmsg) + sizeof(emsg.ee)) {
750 printk("%s: short error message (%Zu)\n",
751 __FUNCTION__, msg.msg_controllen);
752 _leave("");
753 return;
756 port = sin.sin_port;
758 switch (emsg.ee.ee_origin) {
759 case SO_EE_ORIGIN_ICMP:
760 local = 0;
761 switch (emsg.ee.ee_type) {
762 case ICMP_DEST_UNREACH:
763 switch (emsg.ee.ee_code) {
764 case ICMP_NET_UNREACH:
765 _net("Rx Received ICMP Network Unreachable");
766 port = 0;
767 err = -ENETUNREACH;
768 break;
769 case ICMP_HOST_UNREACH:
770 _net("Rx Received ICMP Host Unreachable");
771 port = 0;
772 err = -EHOSTUNREACH;
773 break;
774 case ICMP_PORT_UNREACH:
775 _net("Rx Received ICMP Port Unreachable");
776 err = -ECONNREFUSED;
777 break;
778 case ICMP_NET_UNKNOWN:
779 _net("Rx Received ICMP Unknown Network");
780 port = 0;
781 err = -ENETUNREACH;
782 break;
783 case ICMP_HOST_UNKNOWN:
784 _net("Rx Received ICMP Unknown Host");
785 port = 0;
786 err = -EHOSTUNREACH;
787 break;
788 default:
789 _net("Rx Received ICMP DestUnreach { code=%u }",
790 emsg.ee.ee_code);
791 err = emsg.ee.ee_errno;
792 break;
794 break;
796 case ICMP_TIME_EXCEEDED:
797 _net("Rx Received ICMP TTL Exceeded");
798 err = emsg.ee.ee_errno;
799 break;
801 default:
802 _proto("Rx Received ICMP error { type=%u code=%u }",
803 emsg.ee.ee_type, emsg.ee.ee_code);
804 err = emsg.ee.ee_errno;
805 break;
807 break;
809 case SO_EE_ORIGIN_LOCAL:
810 _proto("Rx Received local error { error=%d }",
811 emsg.ee.ee_errno);
812 local = 1;
813 err = emsg.ee.ee_errno;
814 break;
816 case SO_EE_ORIGIN_NONE:
817 case SO_EE_ORIGIN_ICMP6:
818 default:
819 _proto("Rx Received error report { orig=%u }",
820 emsg.ee.ee_origin);
821 local = 0;
822 err = emsg.ee.ee_errno;
823 break;
826 /* find all the connections between this transport and the
827 * affected destination */
828 INIT_LIST_HEAD(&connq);
830 if (rxrpc_peer_lookup(trans, sin.sin_addr.s_addr,
831 &peer) == 0) {
832 read_lock(&peer->conn_lock);
833 list_for_each(_p, &peer->conn_active) {
834 conn = list_entry(_p, struct rxrpc_connection,
835 link);
836 if (port && conn->addr.sin_port != port)
837 continue;
838 if (!list_empty(&conn->err_link))
839 continue;
841 rxrpc_get_connection(conn);
842 list_add_tail(&conn->err_link, &connq);
844 read_unlock(&peer->conn_lock);
846 /* service all those connections */
847 while (!list_empty(&connq)) {
848 conn = list_entry(connq.next,
849 struct rxrpc_connection,
850 err_link);
851 list_del(&conn->err_link);
853 rxrpc_conn_handle_error(conn, local, err);
855 rxrpc_put_connection(conn);
858 rxrpc_put_peer(peer);
862 _leave("");
863 return;
864 } /* end rxrpc_trans_receive_error_report() */