1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/gfp.h>
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/netdevice.h>
18#include <linux/errno.h>
19#include <net/llc_if.h>
20#include <net/llc_sap.h>
21#include <net/llc_s_ev.h>
22#include <net/llc_conn.h>
23#include <net/sock.h>
24#include <net/llc_c_ev.h>
25#include <net/llc_c_ac.h>
26#include <net/llc_c_st.h>
27#include <net/tcp_states.h>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb)
43{
44 struct llc_conn_state_ev *ev;
45 int rc = -ECONNABORTED;
46 struct llc_sock *llc = llc_sk(sk);
47
48 if (unlikely(llc->state == LLC_CONN_STATE_ADM))
49 goto out;
50 rc = -EBUSY;
51 if (unlikely(llc_data_accept_state(llc->state) ||
52 llc->p_flag)) {
53 llc->failed_data_req = 1;
54 goto out;
55 }
56 ev = llc_conn_ev(skb);
57 ev->type = LLC_CONN_EV_TYPE_PRIM;
58 ev->prim = LLC_DATA_PRIM;
59 ev->prim_type = LLC_PRIM_TYPE_REQ;
60 skb->dev = llc->dev;
61 rc = llc_conn_state_process(sk, skb);
62out:
63 return rc;
64}
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79int llc_establish_connection(struct sock *sk, u8 *lmac, u8 *dmac, u8 dsap)
80{
81 int rc = -EISCONN;
82 struct llc_addr laddr, daddr;
83 struct sk_buff *skb;
84 struct llc_sock *llc = llc_sk(sk);
85 struct sock *existing;
86
87 laddr.lsap = llc->sap->laddr.lsap;
88 daddr.lsap = dsap;
89 memcpy(daddr.mac, dmac, sizeof(daddr.mac));
90 memcpy(laddr.mac, lmac, sizeof(laddr.mac));
91 existing = llc_lookup_established(llc->sap, &daddr, &laddr);
92 if (existing) {
93 if (existing->sk_state == TCP_ESTABLISHED) {
94 sk = existing;
95 goto out_put;
96 } else
97 sock_put(existing);
98 }
99 sock_hold(sk);
100 rc = -ENOMEM;
101 skb = alloc_skb(0, GFP_ATOMIC);
102 if (skb) {
103 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
104
105 ev->type = LLC_CONN_EV_TYPE_PRIM;
106 ev->prim = LLC_CONN_PRIM;
107 ev->prim_type = LLC_PRIM_TYPE_REQ;
108 skb_set_owner_w(skb, sk);
109 rc = llc_conn_state_process(sk, skb);
110 }
111out_put:
112 sock_put(sk);
113 return rc;
114}
115
116
117
118
119
120
121
122
123
124
125int llc_send_disc(struct sock *sk)
126{
127 u16 rc = 1;
128 struct llc_conn_state_ev *ev;
129 struct sk_buff *skb;
130
131 sock_hold(sk);
132 if (sk->sk_type != SOCK_STREAM || sk->sk_state != TCP_ESTABLISHED ||
133 llc_sk(sk)->state == LLC_CONN_STATE_ADM ||
134 llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC)
135 goto out;
136
137
138
139
140 skb = alloc_skb(0, GFP_ATOMIC);
141 if (!skb)
142 goto out;
143 skb_set_owner_w(skb, sk);
144 sk->sk_state = TCP_CLOSING;
145 ev = llc_conn_ev(skb);
146 ev->type = LLC_CONN_EV_TYPE_PRIM;
147 ev->prim = LLC_DISC_PRIM;
148 ev->prim_type = LLC_PRIM_TYPE_REQ;
149 rc = llc_conn_state_process(sk, skb);
150out:
151 sock_put(sk);
152 return rc;
153}
154