#include <net/sock.h>
#include <linux/tcp.h>
#include <net/llc_main.h>
-#include <net/llc_mac.h>
#include <net/llc_pdu.h>
#include <linux/if_tr.h>
-static int llc_sap_next_state(struct llc_sap *sap, struct sk_buff *skb);
-static int llc_exec_sap_trans_actions(struct llc_sap *sap,
- struct llc_sap_state_trans *trans,
- struct sk_buff *skb);
-static struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap,
- struct sk_buff *skb);
-
/**
* llc_sap_assign_sock - adds a connection to a SAP
* @sap: pointer to SAP.
write_unlock_bh(&sap->sk_list.lock);
}
-/**
- * llc_sap_state_process - sends event to SAP state machine
- * @sap: sap to use
- * @skb: pointer to occurred event
- *
- * After executing actions of the event, upper layer will be indicated
- * if needed(on receiving an UI frame). sk can be null for the
- * datalink_proto case.
- */
-void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
-{
- struct llc_sap_state_ev *ev = llc_sap_ev(skb);
-
- /*
- * We have to hold the skb, because llc_sap_next_state
- * will kfree it in the sending path and we need to
- * look at the skb->cb, where we encode llc_sap_state_ev.
- */
- skb_get(skb);
- ev->ind_cfm_flag = 0;
- llc_sap_next_state(sap, skb);
- if (ev->ind_cfm_flag == LLC_IND) {
- if (skb->sk->state == TCP_LISTEN)
- kfree_skb(skb);
- else {
- llc_save_primitive(skb, ev->prim);
-
- /* queue skb to the user. */
- if (sock_queue_rcv_skb(skb->sk, skb))
- kfree_skb(skb);
- }
- }
- kfree_skb(skb);
-}
-
/**
* llc_sap_rtn_pdu - Informs upper layer on rx of an UI, XID or TEST pdu.
* @sap: pointer to SAP
*/
void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb)
{
- struct llc_pdu_un *pdu;
struct llc_sap_state_ev *ev = llc_sap_ev(skb);
+ struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
- pdu = llc_pdu_un_hdr(skb);
switch (LLC_U_PDU_RSP(pdu)) {
case LLC_1_PDU_CMD_TEST:
ev->prim = LLC_TEST_PRIM; break;
ev->ind_cfm_flag = LLC_IND;
}
-/**
- * llc_sap_next_state - finds transition, execs actions & change SAP state
- * @sap: pointer to SAP
- * @skb: happened event
- *
- * This function finds transition that matches with happened event, then
- * executes related actions and finally changes state of SAP. It returns
- * 0 on success and 1 for failure.
- */
-static int llc_sap_next_state(struct llc_sap *sap, struct sk_buff *skb)
-{
- int rc = 1;
- struct llc_sap_state_trans *trans;
-
- if (sap->state <= LLC_NR_SAP_STATES) {
- trans = llc_find_sap_trans(sap, skb);
- if (trans) {
- /* got the state to which we next transition; perform
- * the actions associated with this transition before
- * actually transitioning to the next state
- */
- rc = llc_exec_sap_trans_actions(sap, trans, skb);
- if (!rc)
- /* transition SAP to next state if all actions
- * execute successfully
- */
- sap->state = trans->next_state;
- }
- }
- return rc;
-}
-
/**
* llc_find_sap_trans - finds transition for event
* @sap: pointer to SAP
struct llc_sap_state_trans *rc = NULL;
struct llc_sap_state_trans **next_trans;
struct llc_sap_state *curr_state = &llc_sap_state_table[sap->state - 1];
- /* search thru events for this state until list exhausted or until
+ /*
+ * Search thru events for this state until list exhausted or until
* its obvious the event is not valid for the current state
*/
for (next_trans = curr_state->transitions; next_trans[i]->ev; i++)
if (!next_trans[i]->ev(sap, skb)) {
- /* got event match; return it */
- rc = next_trans[i];
+ rc = next_trans[i]; /* got event match; return it */
break;
}
return rc;
rc = 1;
return rc;
}
+
+/**
+ * llc_sap_next_state - finds transition, execs actions & change SAP state
+ * @sap: pointer to SAP
+ * @skb: happened event
+ *
+ * This function finds transition that matches with happened event, then
+ * executes related actions and finally changes state of SAP. It returns
+ * 0 on success and 1 for failure.
+ */
+static int llc_sap_next_state(struct llc_sap *sap, struct sk_buff *skb)
+{
+ int rc = 1;
+ struct llc_sap_state_trans *trans;
+
+ if (sap->state > LLC_NR_SAP_STATES)
+ goto out;
+ trans = llc_find_sap_trans(sap, skb);
+ if (!trans)
+ goto out;
+ /*
+ * Got the state to which we next transition; perform the actions
+ * associated with this transition before actually transitioning to the
+ * next state
+ */
+ rc = llc_exec_sap_trans_actions(sap, trans, skb);
+ if (rc)
+ goto out;
+ /*
+ * Transition SAP to next state if all actions execute successfully
+ */
+ sap->state = trans->next_state;
+out:
+ return rc;
+}
+
+/**
+ * llc_sap_state_process - sends event to SAP state machine
+ * @sap: sap to use
+ * @skb: pointer to occurred event
+ *
+ * After executing actions of the event, upper layer will be indicated
+ * if needed(on receiving an UI frame). sk can be null for the
+ * datalink_proto case.
+ */
+void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
+{
+ struct llc_sap_state_ev *ev = llc_sap_ev(skb);
+
+ /*
+ * We have to hold the skb, because llc_sap_next_state
+ * will kfree it in the sending path and we need to
+ * look at the skb->cb, where we encode llc_sap_state_ev.
+ */
+ skb_get(skb);
+ ev->ind_cfm_flag = 0;
+ llc_sap_next_state(sap, skb);
+ if (ev->ind_cfm_flag == LLC_IND) {
+ if (skb->sk->state == TCP_LISTEN)
+ kfree_skb(skb);
+ else {
+ llc_save_primitive(skb, ev->prim);
+
+ /* queue skb to the user. */
+ if (sock_queue_rcv_skb(skb->sk, skb))
+ kfree_skb(skb);
+ }
+ }
+ kfree_skb(skb);
+}