2 * llc_conn.c - Driver routines for connection component.
4 * Copyright (c) 1997 by Procom Technology, Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 * This program can be redistributed or modified under the terms of the
8 * GNU General Public License as published by the Free Software Foundation.
9 * This program is distributed without any warranty or implied warranty
10 * of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
15 #include <linux/init.h>
16 #include <net/llc_sap.h>
17 #include <net/llc_conn.h>
19 #include <net/tcp_states.h>
20 #include <net/llc_c_ev.h>
21 #include <net/llc_c_ac.h>
22 #include <net/llc_c_st.h>
23 #include <net/llc_pdu.h>
26 #define dprintk(args...) printk(KERN_DEBUG args)
28 #define dprintk(args...)
31 static int llc_find_offset(int state, int ev_type);
32 static void llc_conn_send_pdus(struct sock *sk);
33 static int llc_conn_service(struct sock *sk, struct sk_buff *skb);
34 static int llc_exec_conn_trans_actions(struct sock *sk,
35 struct llc_conn_state_trans *trans,
37 static struct llc_conn_state_trans *llc_qualify_conn_ev(struct sock *sk,
40 /* Offset table on connection states transition diagram */
41 static int llc_offset_table[NBR_CONN_STATES][NBR_CONN_EV];
44 * llc_conn_state_process - sends event to connection state machine
46 * @skb: occurred event
48 * Sends an event to connection state machine. After processing event
49 * (executing it's actions and changing state), upper layer will be
50 * indicated or confirmed, if needed. Returns 0 for success, 1 for
51 * failure. The socket lock has to be held before calling this function.
53 int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
56 struct llc_sock *llc = llc_sk(sk);
57 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
60 * We have to hold the skb, because llc_conn_service will kfree it in
61 * the sending path and we need to look at the skb->cb, where we encode
65 ev->ind_prim = ev->cfm_prim = 0;
66 rc = llc_conn_service(sk, skb); /* sending event to state machine */
68 printk(KERN_ERR "%s: llc_conn_service failed\n", __FUNCTION__);
72 if (!ev->ind_prim && !ev->cfm_prim) {
73 /* indicate or confirm not required */
74 /* XXX this is not very pretty, perhaps we should store
75 * XXX indicate/confirm-needed state in the llc_conn_state_ev
76 * XXX control block of the SKB instead? -DaveM
83 if (ev->ind_prim && ev->cfm_prim) /* Paranoia */
86 switch (ev->ind_prim) {
88 llc_save_primitive(skb, LLC_DATA_PRIM);
89 if (sock_queue_rcv_skb(sk, skb)) {
93 printk(KERN_ERR "%s: sock_queue_rcv_skb failed!\n",
99 struct sock *parent = skb->sk;
102 skb_queue_tail(&parent->sk_receive_queue, skb);
103 sk->sk_state_change(parent);
108 if (sk->sk_type == SOCK_STREAM &&
109 sk->sk_state == TCP_ESTABLISHED) {
110 sk->sk_shutdown = SHUTDOWN_MASK;
111 sk->sk_socket->state = SS_UNCONNECTED;
112 sk->sk_state = TCP_CLOSE;
113 if (!sock_flag(sk, SOCK_DEAD)) {
114 sk->sk_state_change(sk);
115 sock_set_flag(sk, SOCK_DEAD);
124 * RESET is not being notified to upper layers for now
126 printk(KERN_INFO "%s: received a reset ind!\n", __FUNCTION__);
131 printk(KERN_INFO "%s: received unknown %d prim!\n",
132 __FUNCTION__, ev->ind_prim);
139 switch (ev->cfm_prim) {
141 if (!llc_data_accept_state(llc->state))
142 sk->sk_write_space(sk);
144 rc = llc->failed_data_req = 1;
147 if (sk->sk_type == SOCK_STREAM &&
148 sk->sk_state == TCP_SYN_SENT) {
150 sk->sk_socket->state = SS_UNCONNECTED;
151 sk->sk_state = TCP_CLOSE;
153 sk->sk_socket->state = SS_CONNECTED;
154 sk->sk_state = TCP_ESTABLISHED;
156 sk->sk_state_change(sk);
161 if (sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_CLOSING) {
162 sk->sk_socket->state = SS_UNCONNECTED;
163 sk->sk_state = TCP_CLOSE;
164 sk->sk_state_change(sk);
171 * RESET is not being notified to upper layers for now
173 printk(KERN_INFO "%s: received a reset conf!\n", __FUNCTION__);
177 printk(KERN_INFO "%s: received unknown %d prim!\n",
178 __FUNCTION__, ev->cfm_prim);
181 goto out_skb_put; /* No confirmation */
190 void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
192 /* queue PDU to send to MAC layer */
193 skb_queue_tail(&sk->sk_write_queue, skb);
194 llc_conn_send_pdus(sk);
198 * llc_conn_rtn_pdu - sends received data pdu to upper layer
199 * @sk: Active connection
200 * @skb: Received data frame
202 * Sends received data pdu to upper layer (by using indicate function).
203 * Prepares service parameters (prim and prim_data). calling indication
204 * function will be done in llc_conn_state_process.
206 void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb)
208 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
210 ev->ind_prim = LLC_DATA_PRIM;
214 * llc_conn_resend_i_pdu_as_cmd - resend all all unacknowledged I PDUs
215 * @sk: active connection
217 * @first_p_bit: p_bit value of first pdu
219 * Resend all unacknowledged I PDUs, starting with the NR; send first as
220 * command PDU with P bit equal first_p_bit; if more than one send
221 * subsequent as command PDUs with P bit equal zero (0).
223 void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit)
226 struct llc_pdu_sn *pdu;
228 struct llc_sock *llc;
229 u8 howmany_resend = 0;
231 llc_conn_remove_acked_pdus(sk, nr, &nbr_unack_pdus);
235 * Process unack PDUs only if unack queue is not empty; remove
236 * appropriate PDUs, fix them up, and put them on mac_pdu_q.
240 while ((skb = skb_dequeue(&llc->pdu_unack_q)) != NULL) {
241 pdu = llc_pdu_sn_hdr(skb);
242 llc_pdu_set_cmd_rsp(skb, LLC_PDU_CMD);
243 llc_pdu_set_pf_bit(skb, first_p_bit);
244 skb_queue_tail(&sk->sk_write_queue, skb);
246 llc->vS = LLC_I_GET_NS(pdu);
249 if (howmany_resend > 0)
250 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
251 /* any PDUs to re-send are queued up; start sending to MAC */
252 llc_conn_send_pdus(sk);
257 * llc_conn_resend_i_pdu_as_rsp - Resend all unacknowledged I PDUs
258 * @sk: active connection.
260 * @first_f_bit: f_bit value of first pdu.
262 * Resend all unacknowledged I PDUs, starting with the NR; send first as
263 * response PDU with F bit equal first_f_bit; if more than one send
264 * subsequent as response PDUs with F bit equal zero (0).
266 void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit)
270 struct llc_sock *llc = llc_sk(sk);
271 u8 howmany_resend = 0;
273 llc_conn_remove_acked_pdus(sk, nr, &nbr_unack_pdus);
277 * Process unack PDUs only if unack queue is not empty; remove
278 * appropriate PDUs, fix them up, and put them on mac_pdu_q
280 while ((skb = skb_dequeue(&llc->pdu_unack_q)) != NULL) {
281 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
283 llc_pdu_set_cmd_rsp(skb, LLC_PDU_RSP);
284 llc_pdu_set_pf_bit(skb, first_f_bit);
285 skb_queue_tail(&sk->sk_write_queue, skb);
287 llc->vS = LLC_I_GET_NS(pdu);
290 if (howmany_resend > 0)
291 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
292 /* any PDUs to re-send are queued up; start sending to MAC */
293 llc_conn_send_pdus(sk);
298 * llc_conn_remove_acked_pdus - Removes acknowledged pdus from tx queue
299 * @sk: active connection
301 * how_many_unacked: size of pdu_unack_q after removing acked pdus
303 * Removes acknowledged pdus from transmit queue (pdu_unack_q). Returns
304 * the number of pdus that removed from queue.
306 int llc_conn_remove_acked_pdus(struct sock *sk, u8 nr, u16 *how_many_unacked)
310 struct llc_pdu_sn *pdu;
312 struct llc_sock *llc = llc_sk(sk);
313 int q_len = skb_queue_len(&llc->pdu_unack_q);
317 skb = skb_peek(&llc->pdu_unack_q);
318 pdu = llc_pdu_sn_hdr(skb);
320 /* finding position of last acked pdu in queue */
321 pdu_pos = ((int)LLC_2_SEQ_NBR_MODULO + (int)nr -
322 (int)LLC_I_GET_NS(pdu)) % LLC_2_SEQ_NBR_MODULO;
324 for (i = 0; i < pdu_pos && i < q_len; i++) {
325 skb = skb_dequeue(&llc->pdu_unack_q);
331 *how_many_unacked = skb_queue_len(&llc->pdu_unack_q);
336 * llc_conn_send_pdus - Sends queued PDUs
337 * @sk: active connection
339 * Sends queued pdus to MAC layer for transmission.
341 static void llc_conn_send_pdus(struct sock *sk)
345 while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) {
346 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
348 if (LLC_PDU_TYPE_IS_I(pdu) &&
349 !(skb->dev->flags & IFF_LOOPBACK)) {
350 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
352 skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb);
362 * llc_conn_service - finds transition and changes state of connection
364 * @skb: happened event
366 * This function finds transition that matches with happened event, then
367 * executes related actions and finally changes state of connection.
368 * Returns 0 for success, 1 for failure.
370 static int llc_conn_service(struct sock *sk, struct sk_buff *skb)
373 struct llc_sock *llc = llc_sk(sk);
374 struct llc_conn_state_trans *trans;
376 if (llc->state > NBR_CONN_STATES)
379 trans = llc_qualify_conn_ev(sk, skb);
381 rc = llc_exec_conn_trans_actions(sk, trans, skb);
382 if (!rc && trans->next_state != NO_STATE_CHANGE) {
383 llc->state = trans->next_state;
384 if (!llc_data_accept_state(llc->state))
385 sk->sk_state_change(sk);
393 * llc_qualify_conn_ev - finds transition for event
395 * @skb: happened event
397 * This function finds transition that matches with happened event.
398 * Returns pointer to found transition on success, %NULL otherwise.
400 static struct llc_conn_state_trans *llc_qualify_conn_ev(struct sock *sk,
403 struct llc_conn_state_trans **next_trans;
404 llc_conn_ev_qfyr_t *next_qualifier;
405 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
406 struct llc_sock *llc = llc_sk(sk);
407 struct llc_conn_state *curr_state =
408 &llc_conn_state_table[llc->state - 1];
410 /* search thru events for this state until
411 * list exhausted or until no more
413 for (next_trans = curr_state->transitions +
414 llc_find_offset(llc->state - 1, ev->type);
415 (*next_trans)->ev; next_trans++) {
416 if (!((*next_trans)->ev)(sk, skb)) {
417 /* got POSSIBLE event match; the event may require
418 * qualification based on the values of a number of
419 * state flags; if all qualifications are met (i.e.,
420 * if all qualifying functions return success, or 0,
421 * then this is THE event we're looking for
423 for (next_qualifier = (*next_trans)->ev_qualifiers;
424 next_qualifier && *next_qualifier &&
425 !(*next_qualifier)(sk, skb); next_qualifier++)
427 if (!next_qualifier || !*next_qualifier)
428 /* all qualifiers executed successfully; this is
429 * our transition; return it so we can perform
430 * the associated actions & change the state
439 * llc_exec_conn_trans_actions - executes related actions
441 * @trans: transition that it's actions must be performed
444 * Executes actions that is related to happened event. Returns 0 for
445 * success, 1 to indicate failure of at least one action.
447 static int llc_exec_conn_trans_actions(struct sock *sk,
448 struct llc_conn_state_trans *trans,
452 llc_conn_action_t *next_action;
454 for (next_action = trans->ev_actions;
455 next_action && *next_action; next_action++) {
456 int rc2 = (*next_action)(sk, skb);
468 * llc_lookup_established - Finds connection for the remote/local sap/mac
470 * @daddr: address of remote LLC (MAC + SAP)
471 * @laddr: address of local LLC (MAC + SAP)
473 * Search connection list of the SAP and finds connection using the remote
474 * mac, remote sap, local mac, and local sap. Returns pointer for
475 * connection found, %NULL otherwise.
477 struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr,
478 struct llc_addr *laddr)
481 struct hlist_node *node;
483 read_lock_bh(&sap->sk_list.lock);
484 sk_for_each(rc, node, &sap->sk_list.list) {
485 struct llc_sock *llc = llc_sk(rc);
487 if (llc->laddr.lsap == laddr->lsap &&
488 llc->daddr.lsap == daddr->lsap &&
489 llc_mac_match(llc->laddr.mac, laddr->mac) &&
490 llc_mac_match(llc->daddr.mac, daddr->mac)) {
497 read_unlock_bh(&sap->sk_list.lock);
502 * llc_lookup_listener - Finds listener for local MAC + SAP
504 * @laddr: address of local LLC (MAC + SAP)
506 * Search connection list of the SAP and finds connection listening on
507 * local mac, and local sap. Returns pointer for parent socket found,
510 static struct sock *llc_lookup_listener(struct llc_sap *sap,
511 struct llc_addr *laddr)
514 struct hlist_node *node;
516 read_lock_bh(&sap->sk_list.lock);
517 sk_for_each(rc, node, &sap->sk_list.list) {
518 struct llc_sock *llc = llc_sk(rc);
520 if (rc->sk_type == SOCK_STREAM && rc->sk_state == TCP_LISTEN &&
521 llc->laddr.lsap == laddr->lsap &&
522 (llc_mac_match(llc->laddr.mac, laddr->mac) ||
523 llc_mac_null(llc->laddr.mac))) {
530 read_unlock_bh(&sap->sk_list.lock);
535 * llc_data_accept_state - designates if in this state data can be sent.
536 * @state: state of connection.
538 * Returns 0 if data can be sent, 1 otherwise.
540 u8 llc_data_accept_state(u8 state)
542 return state != LLC_CONN_STATE_NORMAL && state != LLC_CONN_STATE_BUSY &&
543 state != LLC_CONN_STATE_REJ;
547 * find_next_offset - finds offset for next category of transitions
548 * @state: state table.
549 * @offset: start offset.
551 * Finds offset of next category of transitions in transition table.
552 * Returns the start index of next category.
554 static u16 find_next_offset(struct llc_conn_state *state, u16 offset)
557 struct llc_conn_state_trans **next_trans;
559 for (next_trans = state->transitions + offset;
560 (*next_trans)->ev; next_trans++)
566 * llc_build_offset_table - builds offset table of connection
568 * Fills offset table of connection state transition table
569 * (llc_offset_table).
571 void __init llc_build_offset_table(void)
573 struct llc_conn_state *curr_state;
574 int state, ev_type, next_offset;
576 for (state = 0; state < NBR_CONN_STATES; state++) {
577 curr_state = &llc_conn_state_table[state];
579 for (ev_type = 0; ev_type < NBR_CONN_EV; ev_type++) {
580 llc_offset_table[state][ev_type] = next_offset;
581 next_offset += find_next_offset(curr_state,
588 * llc_find_offset - finds start offset of category of transitions
589 * @state: state of connection
590 * @ev_type: type of happened event
592 * Finds start offset of desired category of transitions. Returns the
593 * desired start offset.
595 static int llc_find_offset(int state, int ev_type)
598 /* at this stage, llc_offset_table[..][2] is not important. it is for
599 * init_pf_cycle and I don't know what is it.
602 case LLC_CONN_EV_TYPE_PRIM:
603 rc = llc_offset_table[state][0]; break;
604 case LLC_CONN_EV_TYPE_PDU:
605 rc = llc_offset_table[state][4]; break;
606 case LLC_CONN_EV_TYPE_SIMPLE:
607 rc = llc_offset_table[state][1]; break;
608 case LLC_CONN_EV_TYPE_P_TMR:
609 case LLC_CONN_EV_TYPE_ACK_TMR:
610 case LLC_CONN_EV_TYPE_REJ_TMR:
611 case LLC_CONN_EV_TYPE_BUSY_TMR:
612 rc = llc_offset_table[state][3]; break;
618 * llc_sap_add_socket - adds a socket to a SAP
622 * This function adds a socket to sk_list of a SAP.
624 void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
626 write_lock_bh(&sap->sk_list.lock);
627 llc_sk(sk)->sap = sap;
628 sk_add_node(sk, &sap->sk_list.list);
629 write_unlock_bh(&sap->sk_list.lock);
633 * llc_sap_remove_socket - removes a socket from SAP
637 * This function removes a connection from sk_list.list of a SAP if
638 * the connection was in this list.
640 void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk)
642 write_lock_bh(&sap->sk_list.lock);
643 sk_del_node_init(sk);
644 write_unlock_bh(&sap->sk_list.lock);
648 * llc_conn_rcv - sends received pdus to the connection state machine
649 * @sk: current connection structure.
650 * @skb: received frame.
652 * Sends received pdus to the connection state machine.
654 static int llc_conn_rcv(struct sock* sk, struct sk_buff *skb)
656 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
657 struct llc_sock *llc = llc_sk(sk);
661 ev->type = LLC_CONN_EV_TYPE_PDU;
663 return llc_conn_state_process(sk, skb);
666 void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
668 struct llc_addr saddr, daddr;
671 llc_pdu_decode_sa(skb, saddr.mac);
672 llc_pdu_decode_ssap(skb, &saddr.lsap);
673 llc_pdu_decode_da(skb, daddr.mac);
674 llc_pdu_decode_dsap(skb, &daddr.lsap);
676 sk = llc_lookup_established(sap, &saddr, &daddr);
679 * Didn't find an active connection; verify if there
680 * is a listening socket for this llc addr
682 struct llc_sock *llc;
683 struct sock *parent = llc_lookup_listener(sap, &daddr);
686 dprintk("llc_lookup_listener failed!\n");
690 sk = llc_sk_alloc(parent->sk_family, GFP_ATOMIC, parent->sk_prot);
696 memcpy(&llc->laddr, &daddr, sizeof(llc->laddr));
697 memcpy(&llc->daddr, &saddr, sizeof(llc->daddr));
698 llc_sap_add_socket(sap, sk);
705 if (!sock_owned_by_user(sk))
706 llc_conn_rcv(sk, skb);
708 dprintk("%s: adding to backlog...\n", __FUNCTION__);
709 llc_set_backlog_type(skb, LLC_PACKET);
710 sk_add_backlog(sk, skb);
719 #undef LLC_REFCNT_DEBUG
720 #ifdef LLC_REFCNT_DEBUG
721 static atomic_t llc_sock_nr;
725 * llc_release_sockets - releases all sockets in a sap
726 * @sap: sap to release its sockets
728 * Releases all connections of a sap. Returns 0 if all actions complete
729 * successfully, nonzero otherwise
731 int llc_release_sockets(struct llc_sap *sap)
735 struct hlist_node *node;
737 write_lock_bh(&sap->sk_list.lock);
739 sk_for_each(sk, node, &sap->sk_list.list) {
740 llc_sk(sk)->state = LLC_CONN_STATE_TEMP;
742 if (llc_send_disc(sk))
746 write_unlock_bh(&sap->sk_list.lock);
751 * llc_backlog_rcv - Processes rx frames and expired timers.
752 * @sk: LLC sock (p8022 connection)
753 * @skb: queued rx frame or event
755 * This function processes frames that has received and timers that has
756 * expired during sending an I pdu (refer to data_req_handler). frames
757 * queue by llc_rcv function (llc_mac.c) and timers queue by timer
758 * callback functions(llc_c_ac.c).
760 static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
763 struct llc_sock *llc = llc_sk(sk);
765 if (llc_backlog_type(skb) == LLC_PACKET) {
766 if (llc->state > 1) /* not closed */
767 rc = llc_conn_rcv(sk, skb);
770 } else if (llc_backlog_type(skb) == LLC_EVENT) {
771 /* timer expiration event */
772 if (llc->state > 1) /* not closed */
773 rc = llc_conn_state_process(sk, skb);
777 printk(KERN_ERR "%s: invalid skb in backlog\n", __FUNCTION__);
788 * llc_sk_init - Initializes a socket with default llc values.
789 * @sk: socket to initialize.
791 * Initializes a socket with default llc values.
793 static void llc_sk_init(struct sock* sk)
795 struct llc_sock *llc = llc_sk(sk);
797 llc->state = LLC_CONN_STATE_ADM;
798 llc->inc_cntr = llc->dec_cntr = 2;
799 llc->dec_step = llc->connect_step = 1;
801 init_timer(&llc->ack_timer.timer);
802 llc->ack_timer.expire = LLC_ACK_TIME;
803 llc->ack_timer.timer.data = (unsigned long)sk;
804 llc->ack_timer.timer.function = llc_conn_ack_tmr_cb;
806 init_timer(&llc->pf_cycle_timer.timer);
807 llc->pf_cycle_timer.expire = LLC_P_TIME;
808 llc->pf_cycle_timer.timer.data = (unsigned long)sk;
809 llc->pf_cycle_timer.timer.function = llc_conn_pf_cycle_tmr_cb;
811 init_timer(&llc->rej_sent_timer.timer);
812 llc->rej_sent_timer.expire = LLC_REJ_TIME;
813 llc->rej_sent_timer.timer.data = (unsigned long)sk;
814 llc->rej_sent_timer.timer.function = llc_conn_rej_tmr_cb;
816 init_timer(&llc->busy_state_timer.timer);
817 llc->busy_state_timer.expire = LLC_BUSY_TIME;
818 llc->busy_state_timer.timer.data = (unsigned long)sk;
819 llc->busy_state_timer.timer.function = llc_conn_busy_tmr_cb;
821 llc->n2 = 2; /* max retransmit */
822 llc->k = 2; /* tx win size, will adjust dynam */
823 llc->rw = 128; /* rx win size (opt and equal to
824 * tx_win of remote LLC) */
825 skb_queue_head_init(&llc->pdu_unack_q);
826 sk->sk_backlog_rcv = llc_backlog_rcv;
830 * llc_sk_alloc - Allocates LLC sock
831 * @family: upper layer protocol family
832 * @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
834 * Allocates a LLC sock and initializes it. Returns the new LLC sock
835 * or %NULL if there's no memory available for one
837 struct sock *llc_sk_alloc(int family, int priority, struct proto *prot)
839 struct sock *sk = sk_alloc(family, priority, prot, 1);
844 sock_init_data(NULL, sk);
845 #ifdef LLC_REFCNT_DEBUG
846 atomic_inc(&llc_sock_nr);
847 printk(KERN_DEBUG "LLC socket %p created in %s, now we have %d alive\n", sk,
848 __FUNCTION__, atomic_read(&llc_sock_nr));
855 * llc_sk_free - Frees a LLC socket
856 * @sk - socket to free
860 void llc_sk_free(struct sock *sk)
862 struct llc_sock *llc = llc_sk(sk);
864 llc->state = LLC_CONN_OUT_OF_SVC;
865 /* Stop all (possibly) running timers */
866 llc_conn_ac_stop_all_timers(sk, NULL);
867 #ifdef DEBUG_LLC_CONN_ALLOC
868 printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __FUNCTION__,
869 skb_queue_len(&llc->pdu_unack_q),
870 skb_queue_len(&sk->sk_write_queue));
872 skb_queue_purge(&sk->sk_receive_queue);
873 skb_queue_purge(&sk->sk_write_queue);
874 skb_queue_purge(&llc->pdu_unack_q);
875 #ifdef LLC_REFCNT_DEBUG
876 if (atomic_read(&sk->sk_refcnt) != 1) {
877 printk(KERN_DEBUG "Destruction of LLC sock %p delayed in %s, cnt=%d\n",
878 sk, __FUNCTION__, atomic_read(&sk->sk_refcnt));
879 printk(KERN_DEBUG "%d LLC sockets are still alive\n",
880 atomic_read(&llc_sock_nr));
882 atomic_dec(&llc_sock_nr);
883 printk(KERN_DEBUG "LLC socket %p released in %s, %d are still alive\n", sk,
884 __FUNCTION__, atomic_read(&llc_sock_nr));
891 * llc_sk_reset - resets a connection
892 * @sk: LLC socket to reset
894 * Resets a connection to the out of service state. Stops its timers
895 * and frees any frames in the queues of the connection.
897 void llc_sk_reset(struct sock *sk)
899 struct llc_sock *llc = llc_sk(sk);
901 llc_conn_ac_stop_all_timers(sk, NULL);
902 skb_queue_purge(&sk->sk_write_queue);
903 skb_queue_purge(&llc->pdu_unack_q);
904 llc->remote_busy_flag = 0;
906 llc->retry_count = 0;
907 llc_conn_set_p_flag(sk, 0);
911 llc->first_pdu_Ns = 0;
912 llc->ack_must_be_send = 0;
917 llc->failed_data_req = 0 ;