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];
43 int sysctl_llc2_ack_timeout = LLC2_ACK_TIME * HZ;
44 int sysctl_llc2_p_timeout = LLC2_P_TIME * HZ;
45 int sysctl_llc2_rej_timeout = LLC2_REJ_TIME * HZ;
46 int sysctl_llc2_busy_timeout = LLC2_BUSY_TIME * HZ;
49 * llc_conn_state_process - sends event to connection state machine
51 * @skb: occurred event
53 * Sends an event to connection state machine. After processing event
54 * (executing it's actions and changing state), upper layer will be
55 * indicated or confirmed, if needed. Returns 0 for success, 1 for
56 * failure. The socket lock has to be held before calling this function.
58 int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
61 struct llc_sock *llc = llc_sk(sk);
62 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
65 * We have to hold the skb, because llc_conn_service will kfree it in
66 * the sending path and we need to look at the skb->cb, where we encode
70 ev->ind_prim = ev->cfm_prim = 0;
71 rc = llc_conn_service(sk, skb); /* sending event to state machine */
72 if (unlikely(rc != 0)) {
73 printk(KERN_ERR "%s: llc_conn_service failed\n", __FUNCTION__);
77 if (unlikely(!ev->ind_prim && !ev->cfm_prim)) {
78 /* indicate or confirm not required */
79 /* XXX this is not very pretty, perhaps we should store
80 * XXX indicate/confirm-needed state in the llc_conn_state_ev
81 * XXX control block of the SKB instead? -DaveM
88 if (unlikely(ev->ind_prim && ev->cfm_prim)) /* Paranoia */
91 switch (ev->ind_prim) {
93 llc_save_primitive(sk, skb, LLC_DATA_PRIM);
94 if (unlikely(sock_queue_rcv_skb(sk, skb))) {
98 printk(KERN_ERR "%s: sock_queue_rcv_skb failed!\n",
103 case LLC_CONN_PRIM: {
104 struct sock *parent = skb->sk;
108 * Set the skb->sk to the new struct sock, so that at accept
109 * type the upper layer can get the newly created struct sock.
112 skb_queue_tail(&parent->sk_receive_queue, skb);
113 sk->sk_state_change(parent);
118 if (sk->sk_type == SOCK_STREAM &&
119 sk->sk_state == TCP_ESTABLISHED) {
120 sk->sk_shutdown = SHUTDOWN_MASK;
121 sk->sk_socket->state = SS_UNCONNECTED;
122 sk->sk_state = TCP_CLOSE;
123 if (!sock_flag(sk, SOCK_DEAD)) {
124 sk->sk_state_change(sk);
125 sock_set_flag(sk, SOCK_DEAD);
134 * RESET is not being notified to upper layers for now
136 printk(KERN_INFO "%s: received a reset ind!\n", __FUNCTION__);
141 printk(KERN_INFO "%s: received unknown %d prim!\n",
142 __FUNCTION__, ev->ind_prim);
149 switch (ev->cfm_prim) {
151 if (!llc_data_accept_state(llc->state))
152 sk->sk_write_space(sk);
154 rc = llc->failed_data_req = 1;
157 if (sk->sk_type == SOCK_STREAM &&
158 sk->sk_state == TCP_SYN_SENT) {
160 sk->sk_socket->state = SS_UNCONNECTED;
161 sk->sk_state = TCP_CLOSE;
163 sk->sk_socket->state = SS_CONNECTED;
164 sk->sk_state = TCP_ESTABLISHED;
166 sk->sk_state_change(sk);
171 if (sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_CLOSING) {
172 sk->sk_socket->state = SS_UNCONNECTED;
173 sk->sk_state = TCP_CLOSE;
174 sk->sk_state_change(sk);
181 * RESET is not being notified to upper layers for now
183 printk(KERN_INFO "%s: received a reset conf!\n", __FUNCTION__);
187 printk(KERN_INFO "%s: received unknown %d prim!\n",
188 __FUNCTION__, ev->cfm_prim);
191 goto out_skb_put; /* No confirmation */
200 void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
202 /* queue PDU to send to MAC layer */
203 skb_queue_tail(&sk->sk_write_queue, skb);
204 llc_conn_send_pdus(sk);
208 * llc_conn_rtn_pdu - sends received data pdu to upper layer
209 * @sk: Active connection
210 * @skb: Received data frame
212 * Sends received data pdu to upper layer (by using indicate function).
213 * Prepares service parameters (prim and prim_data). calling indication
214 * function will be done in llc_conn_state_process.
216 void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb)
218 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
220 ev->ind_prim = LLC_DATA_PRIM;
224 * llc_conn_resend_i_pdu_as_cmd - resend all all unacknowledged I PDUs
225 * @sk: active connection
227 * @first_p_bit: p_bit value of first pdu
229 * Resend all unacknowledged I PDUs, starting with the NR; send first as
230 * command PDU with P bit equal first_p_bit; if more than one send
231 * subsequent as command PDUs with P bit equal zero (0).
233 void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit)
236 struct llc_pdu_sn *pdu;
238 struct llc_sock *llc;
239 u8 howmany_resend = 0;
241 llc_conn_remove_acked_pdus(sk, nr, &nbr_unack_pdus);
245 * Process unack PDUs only if unack queue is not empty; remove
246 * appropriate PDUs, fix them up, and put them on mac_pdu_q.
250 while ((skb = skb_dequeue(&llc->pdu_unack_q)) != NULL) {
251 pdu = llc_pdu_sn_hdr(skb);
252 llc_pdu_set_cmd_rsp(skb, LLC_PDU_CMD);
253 llc_pdu_set_pf_bit(skb, first_p_bit);
254 skb_queue_tail(&sk->sk_write_queue, skb);
256 llc->vS = LLC_I_GET_NS(pdu);
259 if (howmany_resend > 0)
260 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
261 /* any PDUs to re-send are queued up; start sending to MAC */
262 llc_conn_send_pdus(sk);
267 * llc_conn_resend_i_pdu_as_rsp - Resend all unacknowledged I PDUs
268 * @sk: active connection.
270 * @first_f_bit: f_bit value of first pdu.
272 * Resend all unacknowledged I PDUs, starting with the NR; send first as
273 * response PDU with F bit equal first_f_bit; if more than one send
274 * subsequent as response PDUs with F bit equal zero (0).
276 void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit)
280 struct llc_sock *llc = llc_sk(sk);
281 u8 howmany_resend = 0;
283 llc_conn_remove_acked_pdus(sk, nr, &nbr_unack_pdus);
287 * Process unack PDUs only if unack queue is not empty; remove
288 * appropriate PDUs, fix them up, and put them on mac_pdu_q
290 while ((skb = skb_dequeue(&llc->pdu_unack_q)) != NULL) {
291 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
293 llc_pdu_set_cmd_rsp(skb, LLC_PDU_RSP);
294 llc_pdu_set_pf_bit(skb, first_f_bit);
295 skb_queue_tail(&sk->sk_write_queue, skb);
297 llc->vS = LLC_I_GET_NS(pdu);
300 if (howmany_resend > 0)
301 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
302 /* any PDUs to re-send are queued up; start sending to MAC */
303 llc_conn_send_pdus(sk);
308 * llc_conn_remove_acked_pdus - Removes acknowledged pdus from tx queue
309 * @sk: active connection
311 * how_many_unacked: size of pdu_unack_q after removing acked pdus
313 * Removes acknowledged pdus from transmit queue (pdu_unack_q). Returns
314 * the number of pdus that removed from queue.
316 int llc_conn_remove_acked_pdus(struct sock *sk, u8 nr, u16 *how_many_unacked)
320 struct llc_pdu_sn *pdu;
322 struct llc_sock *llc = llc_sk(sk);
323 int q_len = skb_queue_len(&llc->pdu_unack_q);
327 skb = skb_peek(&llc->pdu_unack_q);
328 pdu = llc_pdu_sn_hdr(skb);
330 /* finding position of last acked pdu in queue */
331 pdu_pos = ((int)LLC_2_SEQ_NBR_MODULO + (int)nr -
332 (int)LLC_I_GET_NS(pdu)) % LLC_2_SEQ_NBR_MODULO;
334 for (i = 0; i < pdu_pos && i < q_len; i++) {
335 skb = skb_dequeue(&llc->pdu_unack_q);
341 *how_many_unacked = skb_queue_len(&llc->pdu_unack_q);
346 * llc_conn_send_pdus - Sends queued PDUs
347 * @sk: active connection
349 * Sends queued pdus to MAC layer for transmission.
351 static void llc_conn_send_pdus(struct sock *sk)
355 while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) {
356 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
358 if (LLC_PDU_TYPE_IS_I(pdu) &&
359 !(skb->dev->flags & IFF_LOOPBACK)) {
360 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
362 skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb);
372 * llc_conn_service - finds transition and changes state of connection
374 * @skb: happened event
376 * This function finds transition that matches with happened event, then
377 * executes related actions and finally changes state of connection.
378 * Returns 0 for success, 1 for failure.
380 static int llc_conn_service(struct sock *sk, struct sk_buff *skb)
383 struct llc_sock *llc = llc_sk(sk);
384 struct llc_conn_state_trans *trans;
386 if (llc->state > NBR_CONN_STATES)
389 trans = llc_qualify_conn_ev(sk, skb);
391 rc = llc_exec_conn_trans_actions(sk, trans, skb);
392 if (!rc && trans->next_state != NO_STATE_CHANGE) {
393 llc->state = trans->next_state;
394 if (!llc_data_accept_state(llc->state))
395 sk->sk_state_change(sk);
403 * llc_qualify_conn_ev - finds transition for event
405 * @skb: happened event
407 * This function finds transition that matches with happened event.
408 * Returns pointer to found transition on success, %NULL otherwise.
410 static struct llc_conn_state_trans *llc_qualify_conn_ev(struct sock *sk,
413 struct llc_conn_state_trans **next_trans;
414 llc_conn_ev_qfyr_t *next_qualifier;
415 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
416 struct llc_sock *llc = llc_sk(sk);
417 struct llc_conn_state *curr_state =
418 &llc_conn_state_table[llc->state - 1];
420 /* search thru events for this state until
421 * list exhausted or until no more
423 for (next_trans = curr_state->transitions +
424 llc_find_offset(llc->state - 1, ev->type);
425 (*next_trans)->ev; next_trans++) {
426 if (!((*next_trans)->ev)(sk, skb)) {
427 /* got POSSIBLE event match; the event may require
428 * qualification based on the values of a number of
429 * state flags; if all qualifications are met (i.e.,
430 * if all qualifying functions return success, or 0,
431 * then this is THE event we're looking for
433 for (next_qualifier = (*next_trans)->ev_qualifiers;
434 next_qualifier && *next_qualifier &&
435 !(*next_qualifier)(sk, skb); next_qualifier++)
437 if (!next_qualifier || !*next_qualifier)
438 /* all qualifiers executed successfully; this is
439 * our transition; return it so we can perform
440 * the associated actions & change the state
449 * llc_exec_conn_trans_actions - executes related actions
451 * @trans: transition that it's actions must be performed
454 * Executes actions that is related to happened event. Returns 0 for
455 * success, 1 to indicate failure of at least one action.
457 static int llc_exec_conn_trans_actions(struct sock *sk,
458 struct llc_conn_state_trans *trans,
462 llc_conn_action_t *next_action;
464 for (next_action = trans->ev_actions;
465 next_action && *next_action; next_action++) {
466 int rc2 = (*next_action)(sk, skb);
478 * llc_lookup_established - Finds connection for the remote/local sap/mac
480 * @daddr: address of remote LLC (MAC + SAP)
481 * @laddr: address of local LLC (MAC + SAP)
483 * Search connection list of the SAP and finds connection using the remote
484 * mac, remote sap, local mac, and local sap. Returns pointer for
485 * connection found, %NULL otherwise.
487 struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr,
488 struct llc_addr *laddr)
491 struct hlist_node *node;
493 read_lock_bh(&sap->sk_list.lock);
494 sk_for_each(rc, node, &sap->sk_list.list) {
495 struct llc_sock *llc = llc_sk(rc);
497 if (llc->laddr.lsap == laddr->lsap &&
498 llc->daddr.lsap == daddr->lsap &&
499 llc_mac_match(llc->laddr.mac, laddr->mac) &&
500 llc_mac_match(llc->daddr.mac, daddr->mac)) {
507 read_unlock_bh(&sap->sk_list.lock);
512 * llc_lookup_listener - Finds listener for local MAC + SAP
514 * @laddr: address of local LLC (MAC + SAP)
516 * Search connection list of the SAP and finds connection listening on
517 * local mac, and local sap. Returns pointer for parent socket found,
520 static struct sock *llc_lookup_listener(struct llc_sap *sap,
521 struct llc_addr *laddr)
524 struct hlist_node *node;
526 read_lock_bh(&sap->sk_list.lock);
527 sk_for_each(rc, node, &sap->sk_list.list) {
528 struct llc_sock *llc = llc_sk(rc);
530 if (rc->sk_type == SOCK_STREAM && rc->sk_state == TCP_LISTEN &&
531 llc->laddr.lsap == laddr->lsap &&
532 (llc_mac_match(llc->laddr.mac, laddr->mac) ||
533 llc_mac_null(llc->laddr.mac))) {
540 read_unlock_bh(&sap->sk_list.lock);
545 * llc_data_accept_state - designates if in this state data can be sent.
546 * @state: state of connection.
548 * Returns 0 if data can be sent, 1 otherwise.
550 u8 llc_data_accept_state(u8 state)
552 return state != LLC_CONN_STATE_NORMAL && state != LLC_CONN_STATE_BUSY &&
553 state != LLC_CONN_STATE_REJ;
557 * llc_find_next_offset - finds offset for next category of transitions
558 * @state: state table.
559 * @offset: start offset.
561 * Finds offset of next category of transitions in transition table.
562 * Returns the start index of next category.
564 static u16 __init llc_find_next_offset(struct llc_conn_state *state, u16 offset)
567 struct llc_conn_state_trans **next_trans;
569 for (next_trans = state->transitions + offset;
570 (*next_trans)->ev; next_trans++)
576 * llc_build_offset_table - builds offset table of connection
578 * Fills offset table of connection state transition table
579 * (llc_offset_table).
581 void __init llc_build_offset_table(void)
583 struct llc_conn_state *curr_state;
584 int state, ev_type, next_offset;
586 for (state = 0; state < NBR_CONN_STATES; state++) {
587 curr_state = &llc_conn_state_table[state];
589 for (ev_type = 0; ev_type < NBR_CONN_EV; ev_type++) {
590 llc_offset_table[state][ev_type] = next_offset;
591 next_offset += llc_find_next_offset(curr_state,
598 * llc_find_offset - finds start offset of category of transitions
599 * @state: state of connection
600 * @ev_type: type of happened event
602 * Finds start offset of desired category of transitions. Returns the
603 * desired start offset.
605 static int llc_find_offset(int state, int ev_type)
608 /* at this stage, llc_offset_table[..][2] is not important. it is for
609 * init_pf_cycle and I don't know what is it.
612 case LLC_CONN_EV_TYPE_PRIM:
613 rc = llc_offset_table[state][0]; break;
614 case LLC_CONN_EV_TYPE_PDU:
615 rc = llc_offset_table[state][4]; break;
616 case LLC_CONN_EV_TYPE_SIMPLE:
617 rc = llc_offset_table[state][1]; break;
618 case LLC_CONN_EV_TYPE_P_TMR:
619 case LLC_CONN_EV_TYPE_ACK_TMR:
620 case LLC_CONN_EV_TYPE_REJ_TMR:
621 case LLC_CONN_EV_TYPE_BUSY_TMR:
622 rc = llc_offset_table[state][3]; break;
628 * llc_sap_add_socket - adds a socket to a SAP
632 * This function adds a socket to sk_list of a SAP.
634 void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
637 write_lock_bh(&sap->sk_list.lock);
638 llc_sk(sk)->sap = sap;
639 sk_add_node(sk, &sap->sk_list.list);
640 write_unlock_bh(&sap->sk_list.lock);
644 * llc_sap_remove_socket - removes a socket from SAP
648 * This function removes a connection from sk_list.list of a SAP if
649 * the connection was in this list.
651 void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk)
653 write_lock_bh(&sap->sk_list.lock);
654 sk_del_node_init(sk);
655 write_unlock_bh(&sap->sk_list.lock);
660 * llc_conn_rcv - sends received pdus to the connection state machine
661 * @sk: current connection structure.
662 * @skb: received frame.
664 * Sends received pdus to the connection state machine.
666 static int llc_conn_rcv(struct sock* sk, struct sk_buff *skb)
668 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
669 struct llc_sock *llc = llc_sk(sk);
673 ev->type = LLC_CONN_EV_TYPE_PDU;
675 return llc_conn_state_process(sk, skb);
678 void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
680 struct llc_addr saddr, daddr;
683 llc_pdu_decode_sa(skb, saddr.mac);
684 llc_pdu_decode_ssap(skb, &saddr.lsap);
685 llc_pdu_decode_da(skb, daddr.mac);
686 llc_pdu_decode_dsap(skb, &daddr.lsap);
688 sk = llc_lookup_established(sap, &saddr, &daddr);
691 * Didn't find an active connection; verify if there
692 * is a listening socket for this llc addr
694 struct llc_sock *llc;
695 struct sock *parent = llc_lookup_listener(sap, &daddr);
698 dprintk("llc_lookup_listener failed!\n");
702 sk = llc_sk_alloc(parent->sk_family, GFP_ATOMIC, parent->sk_prot);
708 memcpy(&llc->laddr, &daddr, sizeof(llc->laddr));
709 memcpy(&llc->daddr, &saddr, sizeof(llc->daddr));
710 llc_sap_add_socket(sap, sk);
712 skb_set_owner_r(skb, parent);
716 if (!sock_owned_by_user(sk))
717 llc_conn_rcv(sk, skb);
719 dprintk("%s: adding to backlog...\n", __FUNCTION__);
720 llc_set_backlog_type(skb, LLC_PACKET);
721 sk_add_backlog(sk, skb);
730 #undef LLC_REFCNT_DEBUG
731 #ifdef LLC_REFCNT_DEBUG
732 static atomic_t llc_sock_nr;
736 * llc_backlog_rcv - Processes rx frames and expired timers.
737 * @sk: LLC sock (p8022 connection)
738 * @skb: queued rx frame or event
740 * This function processes frames that has received and timers that has
741 * expired during sending an I pdu (refer to data_req_handler). frames
742 * queue by llc_rcv function (llc_mac.c) and timers queue by timer
743 * callback functions(llc_c_ac.c).
745 static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
748 struct llc_sock *llc = llc_sk(sk);
750 if (likely(llc_backlog_type(skb) == LLC_PACKET)) {
751 if (likely(llc->state > 1)) /* not closed */
752 rc = llc_conn_rcv(sk, skb);
755 } else if (llc_backlog_type(skb) == LLC_EVENT) {
756 /* timer expiration event */
757 if (likely(llc->state > 1)) /* not closed */
758 rc = llc_conn_state_process(sk, skb);
762 printk(KERN_ERR "%s: invalid skb in backlog\n", __FUNCTION__);
773 * llc_sk_init - Initializes a socket with default llc values.
774 * @sk: socket to initialize.
776 * Initializes a socket with default llc values.
778 static void llc_sk_init(struct sock* sk)
780 struct llc_sock *llc = llc_sk(sk);
782 llc->state = LLC_CONN_STATE_ADM;
783 llc->inc_cntr = llc->dec_cntr = 2;
784 llc->dec_step = llc->connect_step = 1;
786 init_timer(&llc->ack_timer.timer);
787 llc->ack_timer.expire = sysctl_llc2_ack_timeout;
788 llc->ack_timer.timer.data = (unsigned long)sk;
789 llc->ack_timer.timer.function = llc_conn_ack_tmr_cb;
791 init_timer(&llc->pf_cycle_timer.timer);
792 llc->pf_cycle_timer.expire = sysctl_llc2_p_timeout;
793 llc->pf_cycle_timer.timer.data = (unsigned long)sk;
794 llc->pf_cycle_timer.timer.function = llc_conn_pf_cycle_tmr_cb;
796 init_timer(&llc->rej_sent_timer.timer);
797 llc->rej_sent_timer.expire = sysctl_llc2_rej_timeout;
798 llc->rej_sent_timer.timer.data = (unsigned long)sk;
799 llc->rej_sent_timer.timer.function = llc_conn_rej_tmr_cb;
801 init_timer(&llc->busy_state_timer.timer);
802 llc->busy_state_timer.expire = sysctl_llc2_busy_timeout;
803 llc->busy_state_timer.timer.data = (unsigned long)sk;
804 llc->busy_state_timer.timer.function = llc_conn_busy_tmr_cb;
806 llc->n2 = 2; /* max retransmit */
807 llc->k = 2; /* tx win size, will adjust dynam */
808 llc->rw = 128; /* rx win size (opt and equal to
809 * tx_win of remote LLC) */
810 skb_queue_head_init(&llc->pdu_unack_q);
811 sk->sk_backlog_rcv = llc_backlog_rcv;
815 * llc_sk_alloc - Allocates LLC sock
816 * @family: upper layer protocol family
817 * @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
819 * Allocates a LLC sock and initializes it. Returns the new LLC sock
820 * or %NULL if there's no memory available for one
822 struct sock *llc_sk_alloc(int family, int priority, struct proto *prot)
824 struct sock *sk = sk_alloc(family, priority, prot, 1);
829 sock_init_data(NULL, sk);
830 #ifdef LLC_REFCNT_DEBUG
831 atomic_inc(&llc_sock_nr);
832 printk(KERN_DEBUG "LLC socket %p created in %s, now we have %d alive\n", sk,
833 __FUNCTION__, atomic_read(&llc_sock_nr));
840 * llc_sk_free - Frees a LLC socket
841 * @sk - socket to free
845 void llc_sk_free(struct sock *sk)
847 struct llc_sock *llc = llc_sk(sk);
849 llc->state = LLC_CONN_OUT_OF_SVC;
850 /* Stop all (possibly) running timers */
851 llc_conn_ac_stop_all_timers(sk, NULL);
852 #ifdef DEBUG_LLC_CONN_ALLOC
853 printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __FUNCTION__,
854 skb_queue_len(&llc->pdu_unack_q),
855 skb_queue_len(&sk->sk_write_queue));
857 skb_queue_purge(&sk->sk_receive_queue);
858 skb_queue_purge(&sk->sk_write_queue);
859 skb_queue_purge(&llc->pdu_unack_q);
860 #ifdef LLC_REFCNT_DEBUG
861 if (atomic_read(&sk->sk_refcnt) != 1) {
862 printk(KERN_DEBUG "Destruction of LLC sock %p delayed in %s, cnt=%d\n",
863 sk, __FUNCTION__, atomic_read(&sk->sk_refcnt));
864 printk(KERN_DEBUG "%d LLC sockets are still alive\n",
865 atomic_read(&llc_sock_nr));
867 atomic_dec(&llc_sock_nr);
868 printk(KERN_DEBUG "LLC socket %p released in %s, %d are still alive\n", sk,
869 __FUNCTION__, atomic_read(&llc_sock_nr));
876 * llc_sk_reset - resets a connection
877 * @sk: LLC socket to reset
879 * Resets a connection to the out of service state. Stops its timers
880 * and frees any frames in the queues of the connection.
882 void llc_sk_reset(struct sock *sk)
884 struct llc_sock *llc = llc_sk(sk);
886 llc_conn_ac_stop_all_timers(sk, NULL);
887 skb_queue_purge(&sk->sk_write_queue);
888 skb_queue_purge(&llc->pdu_unack_q);
889 llc->remote_busy_flag = 0;
891 llc->retry_count = 0;
892 llc_conn_set_p_flag(sk, 0);
896 llc->first_pdu_Ns = 0;
897 llc->ack_must_be_send = 0;
902 llc->failed_data_req = 0 ;