[PATCH] scx200_acb: Fix the state machine
[linux-3.10.git] / net / rxrpc / connection.c
1 /* connection.c: Rx connection routines
2  *
3  * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
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.
10  */
11
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <rxrpc/rxrpc.h>
16 #include <rxrpc/transport.h>
17 #include <rxrpc/peer.h>
18 #include <rxrpc/connection.h>
19 #include <rxrpc/call.h>
20 #include <rxrpc/message.h>
21 #include <linux/udp.h>
22 #include <linux/ip.h>
23 #include <net/sock.h>
24 #include <asm/uaccess.h>
25 #include "internal.h"
26
27 __RXACCT_DECL(atomic_t rxrpc_connection_count);
28
29 LIST_HEAD(rxrpc_conns);
30 DECLARE_RWSEM(rxrpc_conns_sem);
31 unsigned long rxrpc_conn_timeout = 60 * 60;
32
33 static void rxrpc_conn_do_timeout(struct rxrpc_connection *conn);
34
35 static void __rxrpc_conn_timeout(rxrpc_timer_t *timer)
36 {
37         struct rxrpc_connection *conn =
38                 list_entry(timer, struct rxrpc_connection, timeout);
39
40         _debug("Rx CONN TIMEOUT [%p{u=%d}]", conn, atomic_read(&conn->usage));
41
42         rxrpc_conn_do_timeout(conn);
43 }
44
45 static const struct rxrpc_timer_ops rxrpc_conn_timer_ops = {
46         .timed_out      = __rxrpc_conn_timeout,
47 };
48
49 /*****************************************************************************/
50 /*
51  * create a new connection record
52  */
53 static inline int __rxrpc_create_connection(struct rxrpc_peer *peer,
54                                             struct rxrpc_connection **_conn)
55 {
56         struct rxrpc_connection *conn;
57
58         _enter("%p",peer);
59
60         /* allocate and initialise a connection record */
61         conn = kmalloc(sizeof(struct rxrpc_connection), GFP_KERNEL);
62         if (!conn) {
63                 _leave(" = -ENOMEM");
64                 return -ENOMEM;
65         }
66
67         memset(conn, 0, sizeof(struct rxrpc_connection));
68         atomic_set(&conn->usage, 1);
69
70         INIT_LIST_HEAD(&conn->link);
71         INIT_LIST_HEAD(&conn->id_link);
72         init_waitqueue_head(&conn->chanwait);
73         spin_lock_init(&conn->lock);
74         rxrpc_timer_init(&conn->timeout, &rxrpc_conn_timer_ops);
75
76         do_gettimeofday(&conn->atime);
77         conn->mtu_size = 1024;
78         conn->peer = peer;
79         conn->trans = peer->trans;
80
81         __RXACCT(atomic_inc(&rxrpc_connection_count));
82         *_conn = conn;
83         _leave(" = 0 (%p)", conn);
84
85         return 0;
86 } /* end __rxrpc_create_connection() */
87
88 /*****************************************************************************/
89 /*
90  * create a new connection record for outgoing connections
91  */
92 int rxrpc_create_connection(struct rxrpc_transport *trans,
93                             __be16 port,
94                             __be32 addr,
95                             uint16_t service_id,
96                             void *security,
97                             struct rxrpc_connection **_conn)
98 {
99         struct rxrpc_connection *candidate, *conn;
100         struct rxrpc_peer *peer;
101         struct list_head *_p;
102         __be32 connid;
103         int ret;
104
105         _enter("%p{%hu},%u,%hu", trans, trans->port, ntohs(port), service_id);
106
107         /* get a peer record */
108         ret = rxrpc_peer_lookup(trans, addr, &peer);
109         if (ret < 0) {
110                 _leave(" = %d", ret);
111                 return ret;
112         }
113
114         /* allocate and initialise a connection record */
115         ret = __rxrpc_create_connection(peer, &candidate);
116         if (ret < 0) {
117                 rxrpc_put_peer(peer);
118                 _leave(" = %d", ret);
119                 return ret;
120         }
121
122         /* fill in the specific bits */
123         candidate->addr.sin_family      = AF_INET;
124         candidate->addr.sin_port        = port;
125         candidate->addr.sin_addr.s_addr = addr;
126
127         candidate->in_epoch             = rxrpc_epoch;
128         candidate->out_epoch            = rxrpc_epoch;
129         candidate->in_clientflag        = 0;
130         candidate->out_clientflag       = RXRPC_CLIENT_INITIATED;
131         candidate->service_id           = htons(service_id);
132
133         /* invent a unique connection ID */
134         write_lock(&peer->conn_idlock);
135
136  try_next_id:
137         connid = htonl(peer->conn_idcounter & RXRPC_CIDMASK);
138         peer->conn_idcounter += RXRPC_MAXCALLS;
139
140         list_for_each(_p, &peer->conn_idlist) {
141                 conn = list_entry(_p, struct rxrpc_connection, id_link);
142                 if (connid == conn->conn_id)
143                         goto try_next_id;
144                 if (connid > conn->conn_id)
145                         break;
146         }
147
148         _debug("selected candidate conn ID %x.%u",
149                ntohl(peer->addr.s_addr), ntohl(connid));
150
151         candidate->conn_id = connid;
152         list_add_tail(&candidate->id_link, _p);
153
154         write_unlock(&peer->conn_idlock);
155
156         /* attach to peer */
157         candidate->peer = peer;
158
159         write_lock(&peer->conn_lock);
160
161         /* search the peer's transport graveyard list */
162         spin_lock(&peer->conn_gylock);
163         list_for_each(_p, &peer->conn_graveyard) {
164                 conn = list_entry(_p, struct rxrpc_connection, link);
165                 if (conn->addr.sin_port == candidate->addr.sin_port     &&
166                     conn->security_ix   == candidate->security_ix       &&
167                     conn->service_id    == candidate->service_id        && 
168                     conn->in_clientflag == 0)
169                         goto found_in_graveyard;
170         }
171         spin_unlock(&peer->conn_gylock);
172
173         /* pick the new candidate */
174         _debug("created connection: {%08x} [out]", ntohl(candidate->conn_id));
175         atomic_inc(&peer->conn_count);
176         conn = candidate;
177         candidate = NULL;
178
179  make_active:
180         list_add_tail(&conn->link, &peer->conn_active);
181         write_unlock(&peer->conn_lock);
182
183         if (candidate) {
184                 write_lock(&peer->conn_idlock);
185                 list_del(&candidate->id_link);
186                 write_unlock(&peer->conn_idlock);
187
188                 __RXACCT(atomic_dec(&rxrpc_connection_count));
189                 kfree(candidate);
190         }
191         else {
192                 down_write(&rxrpc_conns_sem);
193                 list_add_tail(&conn->proc_link, &rxrpc_conns);
194                 up_write(&rxrpc_conns_sem);
195         }
196
197         *_conn = conn;
198         _leave(" = 0 (%p)", conn);
199
200         return 0;
201
202         /* handle resurrecting a connection from the graveyard */
203  found_in_graveyard:
204         _debug("resurrecting connection: {%08x} [out]", ntohl(conn->conn_id));
205         rxrpc_get_connection(conn);
206         rxrpc_krxtimod_del_timer(&conn->timeout);
207         list_del_init(&conn->link);
208         spin_unlock(&peer->conn_gylock);
209         goto make_active;
210 } /* end rxrpc_create_connection() */
211
212 /*****************************************************************************/
213 /*
214  * lookup the connection for an incoming packet
215  * - create a new connection record for unrecorded incoming connections
216  */
217 int rxrpc_connection_lookup(struct rxrpc_peer *peer,
218                             struct rxrpc_message *msg,
219                             struct rxrpc_connection **_conn)
220 {
221         struct rxrpc_connection *conn, *candidate = NULL;
222         struct list_head *_p;
223         struct sk_buff *pkt = msg->pkt;
224         int ret, fresh = 0;
225         __be32 x_epoch, x_connid;
226         __be16 x_port, x_servid;
227         __u32 x_secix;
228         u8 x_clflag;
229
230         _enter("%p{{%hu}},%u,%hu",
231                peer,
232                peer->trans->port,
233                ntohs(pkt->h.uh->source),
234                ntohs(msg->hdr.serviceId));
235
236         x_port          = pkt->h.uh->source;
237         x_epoch         = msg->hdr.epoch;
238         x_clflag        = msg->hdr.flags & RXRPC_CLIENT_INITIATED;
239         x_connid        = htonl(ntohl(msg->hdr.cid) & RXRPC_CIDMASK);
240         x_servid        = msg->hdr.serviceId;
241         x_secix         = msg->hdr.securityIndex;
242
243         /* [common case] search the transport's active list first */
244         read_lock(&peer->conn_lock);
245         list_for_each(_p, &peer->conn_active) {
246                 conn = list_entry(_p, struct rxrpc_connection, link);
247                 if (conn->addr.sin_port         == x_port       &&
248                     conn->in_epoch              == x_epoch      &&
249                     conn->conn_id               == x_connid     &&
250                     conn->security_ix           == x_secix      &&
251                     conn->service_id            == x_servid     && 
252                     conn->in_clientflag         == x_clflag)
253                         goto found_active;
254         }
255         read_unlock(&peer->conn_lock);
256
257         /* [uncommon case] not active 
258          * - create a candidate for a new record if an inbound connection
259          * - only examine the graveyard for an outbound connection
260          */
261         if (x_clflag) {
262                 ret = __rxrpc_create_connection(peer, &candidate);
263                 if (ret < 0) {
264                         _leave(" = %d", ret);
265                         return ret;
266                 }
267
268                 /* fill in the specifics */
269                 candidate->addr.sin_family      = AF_INET;
270                 candidate->addr.sin_port        = x_port;
271                 candidate->addr.sin_addr.s_addr = pkt->nh.iph->saddr;
272                 candidate->in_epoch             = x_epoch;
273                 candidate->out_epoch            = x_epoch;
274                 candidate->in_clientflag        = RXRPC_CLIENT_INITIATED;
275                 candidate->out_clientflag       = 0;
276                 candidate->conn_id              = x_connid;
277                 candidate->service_id           = x_servid;
278                 candidate->security_ix          = x_secix;
279         }
280
281         /* search the active list again, just in case it appeared whilst we
282          * were busy */
283         write_lock(&peer->conn_lock);
284         list_for_each(_p, &peer->conn_active) {
285                 conn = list_entry(_p, struct rxrpc_connection, link);
286                 if (conn->addr.sin_port         == x_port       &&
287                     conn->in_epoch              == x_epoch      &&
288                     conn->conn_id               == x_connid     &&
289                     conn->security_ix           == x_secix      &&
290                     conn->service_id            == x_servid     && 
291                     conn->in_clientflag         == x_clflag)
292                         goto found_active_second_chance;
293         }
294
295         /* search the transport's graveyard list */
296         spin_lock(&peer->conn_gylock);
297         list_for_each(_p, &peer->conn_graveyard) {
298                 conn = list_entry(_p, struct rxrpc_connection, link);
299                 if (conn->addr.sin_port         == x_port       &&
300                     conn->in_epoch              == x_epoch      &&
301                     conn->conn_id               == x_connid     &&
302                     conn->security_ix           == x_secix      &&
303                     conn->service_id            == x_servid     && 
304                     conn->in_clientflag         == x_clflag)
305                         goto found_in_graveyard;
306         }
307         spin_unlock(&peer->conn_gylock);
308
309         /* outbound connections aren't created here */
310         if (!x_clflag) {
311                 write_unlock(&peer->conn_lock);
312                 _leave(" = -ENOENT");
313                 return -ENOENT;
314         }
315
316         /* we can now add the new candidate to the list */
317         _debug("created connection: {%08x} [in]", ntohl(candidate->conn_id));
318         rxrpc_get_peer(peer);
319         conn = candidate;
320         candidate = NULL;
321         atomic_inc(&peer->conn_count);
322         fresh = 1;
323
324  make_active:
325         list_add_tail(&conn->link, &peer->conn_active);
326
327  success_uwfree:
328         write_unlock(&peer->conn_lock);
329
330         if (candidate) {
331                 write_lock(&peer->conn_idlock);
332                 list_del(&candidate->id_link);
333                 write_unlock(&peer->conn_idlock);
334
335                 __RXACCT(atomic_dec(&rxrpc_connection_count));
336                 kfree(candidate);
337         }
338
339         if (fresh) {
340                 down_write(&rxrpc_conns_sem);
341                 list_add_tail(&conn->proc_link, &rxrpc_conns);
342                 up_write(&rxrpc_conns_sem);
343         }
344
345  success:
346         *_conn = conn;
347         _leave(" = 0 (%p)", conn);
348         return 0;
349
350         /* handle the connection being found in the active list straight off */
351  found_active:
352         rxrpc_get_connection(conn);
353         read_unlock(&peer->conn_lock);
354         goto success;
355
356         /* handle resurrecting a connection from the graveyard */
357  found_in_graveyard:
358         _debug("resurrecting connection: {%08x} [in]", ntohl(conn->conn_id));
359         rxrpc_get_peer(peer);
360         rxrpc_get_connection(conn);
361         rxrpc_krxtimod_del_timer(&conn->timeout);
362         list_del_init(&conn->link);
363         spin_unlock(&peer->conn_gylock);
364         goto make_active;
365
366         /* handle finding the connection on the second time through the active
367          * list */
368  found_active_second_chance:
369         rxrpc_get_connection(conn);
370         goto success_uwfree;
371
372 } /* end rxrpc_connection_lookup() */
373
374 /*****************************************************************************/
375 /*
376  * finish using a connection record
377  * - it will be transferred to the peer's connection graveyard when refcount
378  *   reaches 0
379  */
380 void rxrpc_put_connection(struct rxrpc_connection *conn)
381 {
382         struct rxrpc_peer *peer;
383
384         if (!conn)
385                 return;
386
387         _enter("%p{u=%d p=%hu}",
388                conn, atomic_read(&conn->usage), ntohs(conn->addr.sin_port));
389
390         peer = conn->peer;
391         spin_lock(&peer->conn_gylock);
392
393         /* sanity check */
394         if (atomic_read(&conn->usage) <= 0)
395                 BUG();
396
397         if (likely(!atomic_dec_and_test(&conn->usage))) {
398                 spin_unlock(&peer->conn_gylock);
399                 _leave("");
400                 return;
401         }
402
403         /* move to graveyard queue */
404         _debug("burying connection: {%08x}", ntohl(conn->conn_id));
405         list_move_tail(&conn->link, &peer->conn_graveyard);
406
407         rxrpc_krxtimod_add_timer(&conn->timeout, rxrpc_conn_timeout * HZ);
408
409         spin_unlock(&peer->conn_gylock);
410
411         rxrpc_put_peer(conn->peer);
412
413         _leave(" [killed]");
414 } /* end rxrpc_put_connection() */
415
416 /*****************************************************************************/
417 /*
418  * free a connection record
419  */
420 static void rxrpc_conn_do_timeout(struct rxrpc_connection *conn)
421 {
422         struct rxrpc_peer *peer;
423
424         _enter("%p{u=%d p=%hu}",
425                conn, atomic_read(&conn->usage), ntohs(conn->addr.sin_port));
426
427         peer = conn->peer;
428
429         if (atomic_read(&conn->usage) < 0)
430                 BUG();
431
432         /* remove from graveyard if still dead */
433         spin_lock(&peer->conn_gylock);
434         if (atomic_read(&conn->usage) == 0) {
435                 list_del_init(&conn->link);
436         }
437         else {
438                 conn = NULL;
439         }
440         spin_unlock(&peer->conn_gylock);
441
442         if (!conn) {
443                 _leave("");
444                 return; /* resurrected */
445         }
446
447         _debug("--- Destroying Connection %p{%08x} ---",
448                conn, ntohl(conn->conn_id));
449
450         down_write(&rxrpc_conns_sem);
451         list_del(&conn->proc_link);
452         up_write(&rxrpc_conns_sem);
453
454         write_lock(&peer->conn_idlock);
455         list_del(&conn->id_link);
456         write_unlock(&peer->conn_idlock);
457
458         __RXACCT(atomic_dec(&rxrpc_connection_count));
459         kfree(conn);
460
461         /* if the graveyard is now empty, wake up anyone waiting for that */
462         if (atomic_dec_and_test(&peer->conn_count))
463                 wake_up(&peer->conn_gy_waitq);
464
465         _leave(" [destroyed]");
466 } /* end rxrpc_conn_do_timeout() */
467
468 /*****************************************************************************/
469 /*
470  * clear all connection records from a peer endpoint
471  */
472 void rxrpc_conn_clearall(struct rxrpc_peer *peer)
473 {
474         DECLARE_WAITQUEUE(myself, current);
475
476         struct rxrpc_connection *conn;
477         int err;
478
479         _enter("%p", peer);
480
481         /* there shouldn't be any active conns remaining */
482         if (!list_empty(&peer->conn_active))
483                 BUG();
484
485         /* manually timeout all conns in the graveyard */
486         spin_lock(&peer->conn_gylock);
487         while (!list_empty(&peer->conn_graveyard)) {
488                 conn = list_entry(peer->conn_graveyard.next,
489                                   struct rxrpc_connection, link);
490                 err = rxrpc_krxtimod_del_timer(&conn->timeout);
491                 spin_unlock(&peer->conn_gylock);
492
493                 if (err == 0)
494                         rxrpc_conn_do_timeout(conn);
495
496                 spin_lock(&peer->conn_gylock);
497         }
498         spin_unlock(&peer->conn_gylock);
499
500         /* wait for the the conn graveyard to be completely cleared */
501         set_current_state(TASK_UNINTERRUPTIBLE);
502         add_wait_queue(&peer->conn_gy_waitq, &myself);
503
504         while (atomic_read(&peer->conn_count) != 0) {
505                 schedule();
506                 set_current_state(TASK_UNINTERRUPTIBLE);
507         }
508
509         remove_wait_queue(&peer->conn_gy_waitq, &myself);
510         set_current_state(TASK_RUNNING);
511
512         _leave("");
513 } /* end rxrpc_conn_clearall() */
514
515 /*****************************************************************************/
516 /*
517  * allocate and prepare a message for sending out through the transport
518  * endpoint
519  */
520 int rxrpc_conn_newmsg(struct rxrpc_connection *conn,
521                       struct rxrpc_call *call,
522                       uint8_t type,
523                       int dcount,
524                       struct kvec diov[],
525                       gfp_t alloc_flags,
526                       struct rxrpc_message **_msg)
527 {
528         struct rxrpc_message *msg;
529         int loop;
530
531         _enter("%p{%d},%p,%u", conn, ntohs(conn->addr.sin_port), call, type);
532
533         if (dcount > 3) {
534                 _leave(" = -EINVAL");
535                 return -EINVAL;
536         }
537
538         msg = kmalloc(sizeof(struct rxrpc_message), alloc_flags);
539         if (!msg) {
540                 _leave(" = -ENOMEM");
541                 return -ENOMEM;
542         }
543
544         memset(msg, 0, sizeof(*msg));
545         atomic_set(&msg->usage, 1);
546
547         INIT_LIST_HEAD(&msg->link);
548
549         msg->state = RXRPC_MSG_PREPARED;
550
551         msg->hdr.epoch          = conn->out_epoch;
552         msg->hdr.cid            = conn->conn_id | (call ? call->chan_ix : 0);
553         msg->hdr.callNumber     = call ? call->call_id : 0;
554         msg->hdr.type           = type;
555         msg->hdr.flags          = conn->out_clientflag;
556         msg->hdr.securityIndex  = conn->security_ix;
557         msg->hdr.serviceId      = conn->service_id;
558
559         /* generate sequence numbers for data packets */
560         if (call) {
561                 switch (type) {
562                 case RXRPC_PACKET_TYPE_DATA:
563                         msg->seq = ++call->snd_seq_count;
564                         msg->hdr.seq = htonl(msg->seq);
565                         break;
566                 case RXRPC_PACKET_TYPE_ACK:
567                         /* ACK sequence numbers are complicated. The following
568                          * may be wrong:
569                          * - jumbo packet ACKs should have a seq number
570                          * - normal ACKs should not
571                          */
572                 default:
573                         break;
574                 }
575         }
576
577         msg->dcount = dcount + 1;
578         msg->dsize = sizeof(msg->hdr);
579         msg->data[0].iov_len = sizeof(msg->hdr);
580         msg->data[0].iov_base = &msg->hdr;
581
582         for (loop=0; loop < dcount; loop++) {
583                 msg->dsize += diov[loop].iov_len;
584                 msg->data[loop+1].iov_len  = diov[loop].iov_len;
585                 msg->data[loop+1].iov_base = diov[loop].iov_base;
586         }
587
588         __RXACCT(atomic_inc(&rxrpc_message_count));
589         *_msg = msg;
590         _leave(" = 0 (%p) #%d", msg, atomic_read(&rxrpc_message_count));
591         return 0;
592 } /* end rxrpc_conn_newmsg() */
593
594 /*****************************************************************************/
595 /*
596  * free a message
597  */
598 void __rxrpc_put_message(struct rxrpc_message *msg)
599 {
600         int loop;
601
602         _enter("%p #%d", msg, atomic_read(&rxrpc_message_count));
603
604         if (msg->pkt)
605                 kfree_skb(msg->pkt);
606         rxrpc_put_connection(msg->conn);
607
608         for (loop = 0; loop < 8; loop++)
609                 if (test_bit(loop, &msg->dfree))
610                         kfree(msg->data[loop].iov_base);
611
612         __RXACCT(atomic_dec(&rxrpc_message_count));
613         kfree(msg);
614
615         _leave("");
616 } /* end __rxrpc_put_message() */
617
618 /*****************************************************************************/
619 /*
620  * send a message out through the transport endpoint
621  */
622 int rxrpc_conn_sendmsg(struct rxrpc_connection *conn,
623                        struct rxrpc_message *msg)
624 {
625         struct msghdr msghdr;
626         int ret;
627
628         _enter("%p{%d}", conn, ntohs(conn->addr.sin_port));
629
630         /* fill in some fields in the header */
631         spin_lock(&conn->lock);
632         msg->hdr.serial = htonl(++conn->serial_counter);
633         msg->rttdone = 0;
634         spin_unlock(&conn->lock);
635
636         /* set up the message to be transmitted */
637         msghdr.msg_name         = &conn->addr;
638         msghdr.msg_namelen      = sizeof(conn->addr);
639         msghdr.msg_control      = NULL;
640         msghdr.msg_controllen   = 0;
641         msghdr.msg_flags        = MSG_CONFIRM | MSG_DONTWAIT;
642
643         _net("Sending message type %d of %Zd bytes to %08x:%d",
644              msg->hdr.type,
645              msg->dsize,
646              ntohl(conn->addr.sin_addr.s_addr),
647              ntohs(conn->addr.sin_port));
648
649         /* send the message */
650         ret = kernel_sendmsg(conn->trans->socket, &msghdr,
651                              msg->data, msg->dcount, msg->dsize);
652         if (ret < 0) {
653                 msg->state = RXRPC_MSG_ERROR;
654         } else {
655                 msg->state = RXRPC_MSG_SENT;
656                 ret = 0;
657
658                 spin_lock(&conn->lock);
659                 do_gettimeofday(&conn->atime);
660                 msg->stamp = conn->atime;
661                 spin_unlock(&conn->lock);
662         }
663
664         _leave(" = %d", ret);
665
666         return ret;
667 } /* end rxrpc_conn_sendmsg() */
668
669 /*****************************************************************************/
670 /*
671  * deal with a subsequent call packet
672  */
673 int rxrpc_conn_receive_call_packet(struct rxrpc_connection *conn,
674                                    struct rxrpc_call *call,
675                                    struct rxrpc_message *msg)
676 {
677         struct rxrpc_message *pmsg;
678         struct dst_entry *dst;
679         struct list_head *_p;
680         unsigned cix, seq;
681         int ret = 0;
682
683         _enter("%p,%p,%p", conn, call, msg);
684
685         if (!call) {
686                 cix = ntohl(msg->hdr.cid) & RXRPC_CHANNELMASK;
687
688                 spin_lock(&conn->lock);
689                 call = conn->channels[cix];
690
691                 if (!call || call->call_id != msg->hdr.callNumber) {
692                         spin_unlock(&conn->lock);
693                         rxrpc_trans_immediate_abort(conn->trans, msg, -ENOENT);
694                         goto out;
695                 }
696                 else {
697                         rxrpc_get_call(call);
698                         spin_unlock(&conn->lock);
699                 }
700         }
701         else {
702                 rxrpc_get_call(call);
703         }
704
705         _proto("Received packet %%%u [%u] on call %hu:%u:%u",
706                ntohl(msg->hdr.serial),
707                ntohl(msg->hdr.seq),
708                ntohs(msg->hdr.serviceId),
709                ntohl(conn->conn_id),
710                ntohl(call->call_id));
711
712         call->pkt_rcv_count++;
713
714         dst = msg->pkt->dst;
715         if (dst && dst->dev)
716                 conn->peer->if_mtu =
717                         dst->dev->mtu - dst->dev->hard_header_len;
718
719         /* queue on the call in seq order */
720         rxrpc_get_message(msg);
721         seq = msg->seq;
722
723         spin_lock(&call->lock);
724         list_for_each(_p, &call->rcv_receiveq) {
725                 pmsg = list_entry(_p, struct rxrpc_message, link);
726                 if (pmsg->seq > seq)
727                         break;
728         }
729         list_add_tail(&msg->link, _p);
730
731         /* reset the activity timeout */
732         call->flags |= RXRPC_CALL_RCV_PKT;
733         mod_timer(&call->rcv_timeout,jiffies + rxrpc_call_rcv_timeout * HZ);
734
735         spin_unlock(&call->lock);
736
737         rxrpc_krxiod_queue_call(call);
738
739         rxrpc_put_call(call);
740  out:
741         _leave(" = %d", ret);
742         return ret;
743 } /* end rxrpc_conn_receive_call_packet() */
744
745 /*****************************************************************************/
746 /*
747  * handle an ICMP error being applied to a connection
748  */
749 void rxrpc_conn_handle_error(struct rxrpc_connection *conn,
750                              int local, int errno)
751 {
752         struct rxrpc_call *calls[4];
753         int loop;
754
755         _enter("%p{%d},%d", conn, ntohs(conn->addr.sin_port), errno);
756
757         /* get a ref to all my calls in one go */
758         memset(calls, 0, sizeof(calls));
759         spin_lock(&conn->lock);
760
761         for (loop = 3; loop >= 0; loop--) {
762                 if (conn->channels[loop]) {
763                         calls[loop] = conn->channels[loop];
764                         rxrpc_get_call(calls[loop]);
765                 }
766         }
767
768         spin_unlock(&conn->lock);
769
770         /* now kick them all */
771         for (loop = 3; loop >= 0; loop--) {
772                 if (calls[loop]) {
773                         rxrpc_call_handle_error(calls[loop], local, errno);
774                         rxrpc_put_call(calls[loop]);
775                 }
776         }
777
778         _leave("");
779 } /* end rxrpc_conn_handle_error() */