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