aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2012-09-15 13:11:47 -0400
committerDavid S. Miller <davem@davemloft.net>2012-09-17 13:04:19 -0400
commit12ebc8b9af7e29ff4dc77ee0e73a6b1de513d659 (patch)
tree2ed4e36db09f02bdc7b4a4ba637543005ec0a61e /net
parentda3188801898f2fb8859c232554b100f2a0250f8 (diff)
llc2: Collapse remainder of state machine into simple if-else if-statement
Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/llc/llc_station.c91
1 files changed, 4 insertions, 87 deletions
diff --git a/net/llc/llc_station.c b/net/llc/llc_station.c
index fe43158e06de..204a8351efff 100644
--- a/net/llc/llc_station.c
+++ b/net/llc/llc_station.c
@@ -25,16 +25,6 @@
25#include <net/llc_s_st.h> 25#include <net/llc_s_st.h>
26#include <net/llc_pdu.h> 26#include <net/llc_pdu.h>
27 27
28typedef int (*llc_station_ev_t)(struct sk_buff *skb);
29
30typedef int (*llc_station_action_t)(struct sk_buff *skb);
31
32/* Station component state table structure */
33struct llc_station_state_trans {
34 llc_station_ev_t ev;
35 llc_station_action_t *ev_actions;
36};
37
38static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb) 28static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb)
39{ 29{
40 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 30 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
@@ -109,78 +99,6 @@ free:
109 goto out; 99 goto out;
110} 100}
111 101
112/* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */
113static llc_station_action_t llc_stat_up_state_actions_2[] = {
114 llc_station_ac_send_xid_r,
115 NULL,
116};
117
118static struct llc_station_state_trans llc_stat_up_state_trans_2 = {
119 .ev = llc_stat_ev_rx_null_dsap_xid_c,
120 .ev_actions = llc_stat_up_state_actions_2,
121};
122
123/* state transition for LLC_STATION_EV_RX_NULL_DSAP_TEST_C event */
124static llc_station_action_t llc_stat_up_state_actions_3[] = {
125 llc_station_ac_send_test_r,
126 NULL,
127};
128
129static struct llc_station_state_trans llc_stat_up_state_trans_3 = {
130 .ev = llc_stat_ev_rx_null_dsap_test_c,
131 .ev_actions = llc_stat_up_state_actions_3,
132};
133
134/* array of pointers; one to each transition */
135static struct llc_station_state_trans *llc_stat_up_state_trans [] = {
136 &llc_stat_up_state_trans_2,
137 &llc_stat_up_state_trans_3,
138 NULL,
139};
140
141/**
142 * llc_exec_station_trans_actions - executes actions for transition
143 * @trans: Address of the transition
144 * @skb: Address of the event that caused the transition
145 *
146 * Executes actions of a transition of the station state machine. Returns
147 * 0 if all actions complete successfully, nonzero otherwise.
148 */
149static u16 llc_exec_station_trans_actions(struct llc_station_state_trans *trans,
150 struct sk_buff *skb)
151{
152 u16 rc = 0;
153 llc_station_action_t *next_action = trans->ev_actions;
154
155 for (; next_action && *next_action; next_action++)
156 if ((*next_action)(skb))
157 rc = 1;
158 return rc;
159}
160
161/**
162 * llc_find_station_trans - finds transition for this event
163 * @skb: Address of the event
164 *
165 * Search thru events of the current state of the station until list
166 * exhausted or it's obvious that the event is not valid for the current
167 * state. Returns the address of the transition if cound, %NULL otherwise.
168 */
169static struct llc_station_state_trans *
170 llc_find_station_trans(struct sk_buff *skb)
171{
172 int i = 0;
173 struct llc_station_state_trans *rc = NULL;
174 struct llc_station_state_trans **next_trans;
175
176 for (next_trans = llc_stat_up_state_trans; next_trans[i]; i++)
177 if (!next_trans[i]->ev(skb)) {
178 rc = next_trans[i];
179 break;
180 }
181 return rc;
182}
183
184/** 102/**
185 * llc_station_rcv - send received pdu to the station state machine 103 * llc_station_rcv - send received pdu to the station state machine
186 * @skb: received frame. 104 * @skb: received frame.
@@ -189,11 +107,10 @@ static struct llc_station_state_trans *
189 */ 107 */
190static void llc_station_rcv(struct sk_buff *skb) 108static void llc_station_rcv(struct sk_buff *skb)
191{ 109{
192 struct llc_station_state_trans *trans; 110 if (llc_stat_ev_rx_null_dsap_xid_c(skb))
193 111 llc_station_ac_send_xid_r(skb);
194 trans = llc_find_station_trans(skb); 112 else if (llc_stat_ev_rx_null_dsap_test_c(skb))
195 if (trans) 113 llc_station_ac_send_test_r(skb);
196 llc_exec_station_trans_actions(trans, skb);
197 kfree_skb(skb); 114 kfree_skb(skb);
198} 115}
199 116