Commit 49f5eba7575e6dfb146c5e24623d50200ce23ff1
Committed by
David S. Miller
1 parent
7194660da7
Exists in
master
and in
39 other branches
af_iucv: use sk functions to modify sk->sk_ack_backlog
Instead of modifying sk->sk_ack_backlog directly, use respective socket functions. Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com> Signed-off-by: Ursula Braun <ursula.braun@de.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 2 additions and 2 deletions Inline Diff
net/iucv/af_iucv.c
1 | /* | 1 | /* |
2 | * IUCV protocol stack for Linux on zSeries | 2 | * IUCV protocol stack for Linux on zSeries |
3 | * | 3 | * |
4 | * Copyright IBM Corp. 2006, 2009 | 4 | * Copyright IBM Corp. 2006, 2009 |
5 | * | 5 | * |
6 | * Author(s): Jennifer Hunt <jenhunt@us.ibm.com> | 6 | * Author(s): Jennifer Hunt <jenhunt@us.ibm.com> |
7 | * Hendrik Brueckner <brueckner@linux.vnet.ibm.com> | 7 | * Hendrik Brueckner <brueckner@linux.vnet.ibm.com> |
8 | * PM functions: | 8 | * PM functions: |
9 | * Ursula Braun <ursula.braun@de.ibm.com> | 9 | * Ursula Braun <ursula.braun@de.ibm.com> |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #define KMSG_COMPONENT "af_iucv" | 12 | #define KMSG_COMPONENT "af_iucv" |
13 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | 13 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/skbuff.h> | 22 | #include <linux/skbuff.h> |
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/poll.h> | 24 | #include <linux/poll.h> |
25 | #include <net/sock.h> | 25 | #include <net/sock.h> |
26 | #include <asm/ebcdic.h> | 26 | #include <asm/ebcdic.h> |
27 | #include <asm/cpcmd.h> | 27 | #include <asm/cpcmd.h> |
28 | #include <linux/kmod.h> | 28 | #include <linux/kmod.h> |
29 | 29 | ||
30 | #include <net/iucv/iucv.h> | 30 | #include <net/iucv/iucv.h> |
31 | #include <net/iucv/af_iucv.h> | 31 | #include <net/iucv/af_iucv.h> |
32 | 32 | ||
33 | #define VERSION "1.1" | 33 | #define VERSION "1.1" |
34 | 34 | ||
35 | static char iucv_userid[80]; | 35 | static char iucv_userid[80]; |
36 | 36 | ||
37 | static const struct proto_ops iucv_sock_ops; | 37 | static const struct proto_ops iucv_sock_ops; |
38 | 38 | ||
39 | static struct proto iucv_proto = { | 39 | static struct proto iucv_proto = { |
40 | .name = "AF_IUCV", | 40 | .name = "AF_IUCV", |
41 | .owner = THIS_MODULE, | 41 | .owner = THIS_MODULE, |
42 | .obj_size = sizeof(struct iucv_sock), | 42 | .obj_size = sizeof(struct iucv_sock), |
43 | }; | 43 | }; |
44 | 44 | ||
45 | /* special AF_IUCV IPRM messages */ | 45 | /* special AF_IUCV IPRM messages */ |
46 | static const u8 iprm_shutdown[8] = | 46 | static const u8 iprm_shutdown[8] = |
47 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; | 47 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
48 | 48 | ||
49 | #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class)) | 49 | #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class)) |
50 | 50 | ||
51 | /* macros to set/get socket control buffer at correct offset */ | 51 | /* macros to set/get socket control buffer at correct offset */ |
52 | #define CB_TAG(skb) ((skb)->cb) /* iucv message tag */ | 52 | #define CB_TAG(skb) ((skb)->cb) /* iucv message tag */ |
53 | #define CB_TAG_LEN (sizeof(((struct iucv_message *) 0)->tag)) | 53 | #define CB_TAG_LEN (sizeof(((struct iucv_message *) 0)->tag)) |
54 | #define CB_TRGCLS(skb) ((skb)->cb + CB_TAG_LEN) /* iucv msg target class */ | 54 | #define CB_TRGCLS(skb) ((skb)->cb + CB_TAG_LEN) /* iucv msg target class */ |
55 | #define CB_TRGCLS_LEN (TRGCLS_SIZE) | 55 | #define CB_TRGCLS_LEN (TRGCLS_SIZE) |
56 | 56 | ||
57 | #define __iucv_sock_wait(sk, condition, timeo, ret) \ | 57 | #define __iucv_sock_wait(sk, condition, timeo, ret) \ |
58 | do { \ | 58 | do { \ |
59 | DEFINE_WAIT(__wait); \ | 59 | DEFINE_WAIT(__wait); \ |
60 | long __timeo = timeo; \ | 60 | long __timeo = timeo; \ |
61 | ret = 0; \ | 61 | ret = 0; \ |
62 | prepare_to_wait(sk->sk_sleep, &__wait, TASK_INTERRUPTIBLE); \ | 62 | prepare_to_wait(sk->sk_sleep, &__wait, TASK_INTERRUPTIBLE); \ |
63 | while (!(condition)) { \ | 63 | while (!(condition)) { \ |
64 | if (!__timeo) { \ | 64 | if (!__timeo) { \ |
65 | ret = -EAGAIN; \ | 65 | ret = -EAGAIN; \ |
66 | break; \ | 66 | break; \ |
67 | } \ | 67 | } \ |
68 | if (signal_pending(current)) { \ | 68 | if (signal_pending(current)) { \ |
69 | ret = sock_intr_errno(__timeo); \ | 69 | ret = sock_intr_errno(__timeo); \ |
70 | break; \ | 70 | break; \ |
71 | } \ | 71 | } \ |
72 | release_sock(sk); \ | 72 | release_sock(sk); \ |
73 | __timeo = schedule_timeout(__timeo); \ | 73 | __timeo = schedule_timeout(__timeo); \ |
74 | lock_sock(sk); \ | 74 | lock_sock(sk); \ |
75 | ret = sock_error(sk); \ | 75 | ret = sock_error(sk); \ |
76 | if (ret) \ | 76 | if (ret) \ |
77 | break; \ | 77 | break; \ |
78 | } \ | 78 | } \ |
79 | finish_wait(sk->sk_sleep, &__wait); \ | 79 | finish_wait(sk->sk_sleep, &__wait); \ |
80 | } while (0) | 80 | } while (0) |
81 | 81 | ||
82 | #define iucv_sock_wait(sk, condition, timeo) \ | 82 | #define iucv_sock_wait(sk, condition, timeo) \ |
83 | ({ \ | 83 | ({ \ |
84 | int __ret = 0; \ | 84 | int __ret = 0; \ |
85 | if (!(condition)) \ | 85 | if (!(condition)) \ |
86 | __iucv_sock_wait(sk, condition, timeo, __ret); \ | 86 | __iucv_sock_wait(sk, condition, timeo, __ret); \ |
87 | __ret; \ | 87 | __ret; \ |
88 | }) | 88 | }) |
89 | 89 | ||
90 | static void iucv_sock_kill(struct sock *sk); | 90 | static void iucv_sock_kill(struct sock *sk); |
91 | static void iucv_sock_close(struct sock *sk); | 91 | static void iucv_sock_close(struct sock *sk); |
92 | 92 | ||
93 | /* Call Back functions */ | 93 | /* Call Back functions */ |
94 | static void iucv_callback_rx(struct iucv_path *, struct iucv_message *); | 94 | static void iucv_callback_rx(struct iucv_path *, struct iucv_message *); |
95 | static void iucv_callback_txdone(struct iucv_path *, struct iucv_message *); | 95 | static void iucv_callback_txdone(struct iucv_path *, struct iucv_message *); |
96 | static void iucv_callback_connack(struct iucv_path *, u8 ipuser[16]); | 96 | static void iucv_callback_connack(struct iucv_path *, u8 ipuser[16]); |
97 | static int iucv_callback_connreq(struct iucv_path *, u8 ipvmid[8], | 97 | static int iucv_callback_connreq(struct iucv_path *, u8 ipvmid[8], |
98 | u8 ipuser[16]); | 98 | u8 ipuser[16]); |
99 | static void iucv_callback_connrej(struct iucv_path *, u8 ipuser[16]); | 99 | static void iucv_callback_connrej(struct iucv_path *, u8 ipuser[16]); |
100 | static void iucv_callback_shutdown(struct iucv_path *, u8 ipuser[16]); | 100 | static void iucv_callback_shutdown(struct iucv_path *, u8 ipuser[16]); |
101 | 101 | ||
102 | static struct iucv_sock_list iucv_sk_list = { | 102 | static struct iucv_sock_list iucv_sk_list = { |
103 | .lock = __RW_LOCK_UNLOCKED(iucv_sk_list.lock), | 103 | .lock = __RW_LOCK_UNLOCKED(iucv_sk_list.lock), |
104 | .autobind_name = ATOMIC_INIT(0) | 104 | .autobind_name = ATOMIC_INIT(0) |
105 | }; | 105 | }; |
106 | 106 | ||
107 | static struct iucv_handler af_iucv_handler = { | 107 | static struct iucv_handler af_iucv_handler = { |
108 | .path_pending = iucv_callback_connreq, | 108 | .path_pending = iucv_callback_connreq, |
109 | .path_complete = iucv_callback_connack, | 109 | .path_complete = iucv_callback_connack, |
110 | .path_severed = iucv_callback_connrej, | 110 | .path_severed = iucv_callback_connrej, |
111 | .message_pending = iucv_callback_rx, | 111 | .message_pending = iucv_callback_rx, |
112 | .message_complete = iucv_callback_txdone, | 112 | .message_complete = iucv_callback_txdone, |
113 | .path_quiesced = iucv_callback_shutdown, | 113 | .path_quiesced = iucv_callback_shutdown, |
114 | }; | 114 | }; |
115 | 115 | ||
116 | static inline void high_nmcpy(unsigned char *dst, char *src) | 116 | static inline void high_nmcpy(unsigned char *dst, char *src) |
117 | { | 117 | { |
118 | memcpy(dst, src, 8); | 118 | memcpy(dst, src, 8); |
119 | } | 119 | } |
120 | 120 | ||
121 | static inline void low_nmcpy(unsigned char *dst, char *src) | 121 | static inline void low_nmcpy(unsigned char *dst, char *src) |
122 | { | 122 | { |
123 | memcpy(&dst[8], src, 8); | 123 | memcpy(&dst[8], src, 8); |
124 | } | 124 | } |
125 | 125 | ||
126 | static int afiucv_pm_prepare(struct device *dev) | 126 | static int afiucv_pm_prepare(struct device *dev) |
127 | { | 127 | { |
128 | #ifdef CONFIG_PM_DEBUG | 128 | #ifdef CONFIG_PM_DEBUG |
129 | printk(KERN_WARNING "afiucv_pm_prepare\n"); | 129 | printk(KERN_WARNING "afiucv_pm_prepare\n"); |
130 | #endif | 130 | #endif |
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
133 | 133 | ||
134 | static void afiucv_pm_complete(struct device *dev) | 134 | static void afiucv_pm_complete(struct device *dev) |
135 | { | 135 | { |
136 | #ifdef CONFIG_PM_DEBUG | 136 | #ifdef CONFIG_PM_DEBUG |
137 | printk(KERN_WARNING "afiucv_pm_complete\n"); | 137 | printk(KERN_WARNING "afiucv_pm_complete\n"); |
138 | #endif | 138 | #endif |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * afiucv_pm_freeze() - Freeze PM callback | 143 | * afiucv_pm_freeze() - Freeze PM callback |
144 | * @dev: AFIUCV dummy device | 144 | * @dev: AFIUCV dummy device |
145 | * | 145 | * |
146 | * Sever all established IUCV communication pathes | 146 | * Sever all established IUCV communication pathes |
147 | */ | 147 | */ |
148 | static int afiucv_pm_freeze(struct device *dev) | 148 | static int afiucv_pm_freeze(struct device *dev) |
149 | { | 149 | { |
150 | struct iucv_sock *iucv; | 150 | struct iucv_sock *iucv; |
151 | struct sock *sk; | 151 | struct sock *sk; |
152 | struct hlist_node *node; | 152 | struct hlist_node *node; |
153 | int err = 0; | 153 | int err = 0; |
154 | 154 | ||
155 | #ifdef CONFIG_PM_DEBUG | 155 | #ifdef CONFIG_PM_DEBUG |
156 | printk(KERN_WARNING "afiucv_pm_freeze\n"); | 156 | printk(KERN_WARNING "afiucv_pm_freeze\n"); |
157 | #endif | 157 | #endif |
158 | read_lock(&iucv_sk_list.lock); | 158 | read_lock(&iucv_sk_list.lock); |
159 | sk_for_each(sk, node, &iucv_sk_list.head) { | 159 | sk_for_each(sk, node, &iucv_sk_list.head) { |
160 | iucv = iucv_sk(sk); | 160 | iucv = iucv_sk(sk); |
161 | skb_queue_purge(&iucv->send_skb_q); | 161 | skb_queue_purge(&iucv->send_skb_q); |
162 | skb_queue_purge(&iucv->backlog_skb_q); | 162 | skb_queue_purge(&iucv->backlog_skb_q); |
163 | switch (sk->sk_state) { | 163 | switch (sk->sk_state) { |
164 | case IUCV_SEVERED: | 164 | case IUCV_SEVERED: |
165 | case IUCV_DISCONN: | 165 | case IUCV_DISCONN: |
166 | case IUCV_CLOSING: | 166 | case IUCV_CLOSING: |
167 | case IUCV_CONNECTED: | 167 | case IUCV_CONNECTED: |
168 | if (iucv->path) { | 168 | if (iucv->path) { |
169 | err = iucv_path_sever(iucv->path, NULL); | 169 | err = iucv_path_sever(iucv->path, NULL); |
170 | iucv_path_free(iucv->path); | 170 | iucv_path_free(iucv->path); |
171 | iucv->path = NULL; | 171 | iucv->path = NULL; |
172 | } | 172 | } |
173 | break; | 173 | break; |
174 | case IUCV_OPEN: | 174 | case IUCV_OPEN: |
175 | case IUCV_BOUND: | 175 | case IUCV_BOUND: |
176 | case IUCV_LISTEN: | 176 | case IUCV_LISTEN: |
177 | case IUCV_CLOSED: | 177 | case IUCV_CLOSED: |
178 | default: | 178 | default: |
179 | break; | 179 | break; |
180 | } | 180 | } |
181 | } | 181 | } |
182 | read_unlock(&iucv_sk_list.lock); | 182 | read_unlock(&iucv_sk_list.lock); |
183 | return err; | 183 | return err; |
184 | } | 184 | } |
185 | 185 | ||
186 | /** | 186 | /** |
187 | * afiucv_pm_restore_thaw() - Thaw and restore PM callback | 187 | * afiucv_pm_restore_thaw() - Thaw and restore PM callback |
188 | * @dev: AFIUCV dummy device | 188 | * @dev: AFIUCV dummy device |
189 | * | 189 | * |
190 | * socket clean up after freeze | 190 | * socket clean up after freeze |
191 | */ | 191 | */ |
192 | static int afiucv_pm_restore_thaw(struct device *dev) | 192 | static int afiucv_pm_restore_thaw(struct device *dev) |
193 | { | 193 | { |
194 | struct iucv_sock *iucv; | 194 | struct iucv_sock *iucv; |
195 | struct sock *sk; | 195 | struct sock *sk; |
196 | struct hlist_node *node; | 196 | struct hlist_node *node; |
197 | 197 | ||
198 | #ifdef CONFIG_PM_DEBUG | 198 | #ifdef CONFIG_PM_DEBUG |
199 | printk(KERN_WARNING "afiucv_pm_restore_thaw\n"); | 199 | printk(KERN_WARNING "afiucv_pm_restore_thaw\n"); |
200 | #endif | 200 | #endif |
201 | read_lock(&iucv_sk_list.lock); | 201 | read_lock(&iucv_sk_list.lock); |
202 | sk_for_each(sk, node, &iucv_sk_list.head) { | 202 | sk_for_each(sk, node, &iucv_sk_list.head) { |
203 | iucv = iucv_sk(sk); | 203 | iucv = iucv_sk(sk); |
204 | switch (sk->sk_state) { | 204 | switch (sk->sk_state) { |
205 | case IUCV_CONNECTED: | 205 | case IUCV_CONNECTED: |
206 | sk->sk_err = EPIPE; | 206 | sk->sk_err = EPIPE; |
207 | sk->sk_state = IUCV_DISCONN; | 207 | sk->sk_state = IUCV_DISCONN; |
208 | sk->sk_state_change(sk); | 208 | sk->sk_state_change(sk); |
209 | break; | 209 | break; |
210 | case IUCV_DISCONN: | 210 | case IUCV_DISCONN: |
211 | case IUCV_SEVERED: | 211 | case IUCV_SEVERED: |
212 | case IUCV_CLOSING: | 212 | case IUCV_CLOSING: |
213 | case IUCV_LISTEN: | 213 | case IUCV_LISTEN: |
214 | case IUCV_BOUND: | 214 | case IUCV_BOUND: |
215 | case IUCV_OPEN: | 215 | case IUCV_OPEN: |
216 | default: | 216 | default: |
217 | break; | 217 | break; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | read_unlock(&iucv_sk_list.lock); | 220 | read_unlock(&iucv_sk_list.lock); |
221 | return 0; | 221 | return 0; |
222 | } | 222 | } |
223 | 223 | ||
224 | static struct dev_pm_ops afiucv_pm_ops = { | 224 | static struct dev_pm_ops afiucv_pm_ops = { |
225 | .prepare = afiucv_pm_prepare, | 225 | .prepare = afiucv_pm_prepare, |
226 | .complete = afiucv_pm_complete, | 226 | .complete = afiucv_pm_complete, |
227 | .freeze = afiucv_pm_freeze, | 227 | .freeze = afiucv_pm_freeze, |
228 | .thaw = afiucv_pm_restore_thaw, | 228 | .thaw = afiucv_pm_restore_thaw, |
229 | .restore = afiucv_pm_restore_thaw, | 229 | .restore = afiucv_pm_restore_thaw, |
230 | }; | 230 | }; |
231 | 231 | ||
232 | static struct device_driver af_iucv_driver = { | 232 | static struct device_driver af_iucv_driver = { |
233 | .owner = THIS_MODULE, | 233 | .owner = THIS_MODULE, |
234 | .name = "afiucv", | 234 | .name = "afiucv", |
235 | .bus = &iucv_bus, | 235 | .bus = &iucv_bus, |
236 | .pm = &afiucv_pm_ops, | 236 | .pm = &afiucv_pm_ops, |
237 | }; | 237 | }; |
238 | 238 | ||
239 | /* dummy device used as trigger for PM functions */ | 239 | /* dummy device used as trigger for PM functions */ |
240 | static struct device *af_iucv_dev; | 240 | static struct device *af_iucv_dev; |
241 | 241 | ||
242 | /** | 242 | /** |
243 | * iucv_msg_length() - Returns the length of an iucv message. | 243 | * iucv_msg_length() - Returns the length of an iucv message. |
244 | * @msg: Pointer to struct iucv_message, MUST NOT be NULL | 244 | * @msg: Pointer to struct iucv_message, MUST NOT be NULL |
245 | * | 245 | * |
246 | * The function returns the length of the specified iucv message @msg of data | 246 | * The function returns the length of the specified iucv message @msg of data |
247 | * stored in a buffer and of data stored in the parameter list (PRMDATA). | 247 | * stored in a buffer and of data stored in the parameter list (PRMDATA). |
248 | * | 248 | * |
249 | * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket | 249 | * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket |
250 | * data: | 250 | * data: |
251 | * PRMDATA[0..6] socket data (max 7 bytes); | 251 | * PRMDATA[0..6] socket data (max 7 bytes); |
252 | * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7]) | 252 | * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7]) |
253 | * | 253 | * |
254 | * The socket data length is computed by substracting the socket data length | 254 | * The socket data length is computed by substracting the socket data length |
255 | * value from 0xFF. | 255 | * value from 0xFF. |
256 | * If the socket data len is greater 7, then PRMDATA can be used for special | 256 | * If the socket data len is greater 7, then PRMDATA can be used for special |
257 | * notifications (see iucv_sock_shutdown); and further, | 257 | * notifications (see iucv_sock_shutdown); and further, |
258 | * if the socket data len is > 7, the function returns 8. | 258 | * if the socket data len is > 7, the function returns 8. |
259 | * | 259 | * |
260 | * Use this function to allocate socket buffers to store iucv message data. | 260 | * Use this function to allocate socket buffers to store iucv message data. |
261 | */ | 261 | */ |
262 | static inline size_t iucv_msg_length(struct iucv_message *msg) | 262 | static inline size_t iucv_msg_length(struct iucv_message *msg) |
263 | { | 263 | { |
264 | size_t datalen; | 264 | size_t datalen; |
265 | 265 | ||
266 | if (msg->flags & IUCV_IPRMDATA) { | 266 | if (msg->flags & IUCV_IPRMDATA) { |
267 | datalen = 0xff - msg->rmmsg[7]; | 267 | datalen = 0xff - msg->rmmsg[7]; |
268 | return (datalen < 8) ? datalen : 8; | 268 | return (datalen < 8) ? datalen : 8; |
269 | } | 269 | } |
270 | return msg->length; | 270 | return msg->length; |
271 | } | 271 | } |
272 | 272 | ||
273 | /** | 273 | /** |
274 | * iucv_sock_in_state() - check for specific states | 274 | * iucv_sock_in_state() - check for specific states |
275 | * @sk: sock structure | 275 | * @sk: sock structure |
276 | * @state: first iucv sk state | 276 | * @state: first iucv sk state |
277 | * @state: second iucv sk state | 277 | * @state: second iucv sk state |
278 | * | 278 | * |
279 | * Returns true if the socket in either in the first or second state. | 279 | * Returns true if the socket in either in the first or second state. |
280 | */ | 280 | */ |
281 | static int iucv_sock_in_state(struct sock *sk, int state, int state2) | 281 | static int iucv_sock_in_state(struct sock *sk, int state, int state2) |
282 | { | 282 | { |
283 | return (sk->sk_state == state || sk->sk_state == state2); | 283 | return (sk->sk_state == state || sk->sk_state == state2); |
284 | } | 284 | } |
285 | 285 | ||
286 | /** | 286 | /** |
287 | * iucv_below_msglim() - function to check if messages can be sent | 287 | * iucv_below_msglim() - function to check if messages can be sent |
288 | * @sk: sock structure | 288 | * @sk: sock structure |
289 | * | 289 | * |
290 | * Returns true if the send queue length is lower than the message limit. | 290 | * Returns true if the send queue length is lower than the message limit. |
291 | * Always returns true if the socket is not connected (no iucv path for | 291 | * Always returns true if the socket is not connected (no iucv path for |
292 | * checking the message limit). | 292 | * checking the message limit). |
293 | */ | 293 | */ |
294 | static inline int iucv_below_msglim(struct sock *sk) | 294 | static inline int iucv_below_msglim(struct sock *sk) |
295 | { | 295 | { |
296 | struct iucv_sock *iucv = iucv_sk(sk); | 296 | struct iucv_sock *iucv = iucv_sk(sk); |
297 | 297 | ||
298 | if (sk->sk_state != IUCV_CONNECTED) | 298 | if (sk->sk_state != IUCV_CONNECTED) |
299 | return 1; | 299 | return 1; |
300 | return (skb_queue_len(&iucv->send_skb_q) < iucv->path->msglim); | 300 | return (skb_queue_len(&iucv->send_skb_q) < iucv->path->msglim); |
301 | } | 301 | } |
302 | 302 | ||
303 | /** | 303 | /** |
304 | * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit | 304 | * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit |
305 | */ | 305 | */ |
306 | static void iucv_sock_wake_msglim(struct sock *sk) | 306 | static void iucv_sock_wake_msglim(struct sock *sk) |
307 | { | 307 | { |
308 | read_lock(&sk->sk_callback_lock); | 308 | read_lock(&sk->sk_callback_lock); |
309 | if (sk_has_sleeper(sk)) | 309 | if (sk_has_sleeper(sk)) |
310 | wake_up_interruptible_all(sk->sk_sleep); | 310 | wake_up_interruptible_all(sk->sk_sleep); |
311 | sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); | 311 | sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); |
312 | read_unlock(&sk->sk_callback_lock); | 312 | read_unlock(&sk->sk_callback_lock); |
313 | } | 313 | } |
314 | 314 | ||
315 | /* Timers */ | 315 | /* Timers */ |
316 | static void iucv_sock_timeout(unsigned long arg) | 316 | static void iucv_sock_timeout(unsigned long arg) |
317 | { | 317 | { |
318 | struct sock *sk = (struct sock *)arg; | 318 | struct sock *sk = (struct sock *)arg; |
319 | 319 | ||
320 | bh_lock_sock(sk); | 320 | bh_lock_sock(sk); |
321 | sk->sk_err = ETIMEDOUT; | 321 | sk->sk_err = ETIMEDOUT; |
322 | sk->sk_state_change(sk); | 322 | sk->sk_state_change(sk); |
323 | bh_unlock_sock(sk); | 323 | bh_unlock_sock(sk); |
324 | 324 | ||
325 | iucv_sock_kill(sk); | 325 | iucv_sock_kill(sk); |
326 | sock_put(sk); | 326 | sock_put(sk); |
327 | } | 327 | } |
328 | 328 | ||
329 | static void iucv_sock_clear_timer(struct sock *sk) | 329 | static void iucv_sock_clear_timer(struct sock *sk) |
330 | { | 330 | { |
331 | sk_stop_timer(sk, &sk->sk_timer); | 331 | sk_stop_timer(sk, &sk->sk_timer); |
332 | } | 332 | } |
333 | 333 | ||
334 | static struct sock *__iucv_get_sock_by_name(char *nm) | 334 | static struct sock *__iucv_get_sock_by_name(char *nm) |
335 | { | 335 | { |
336 | struct sock *sk; | 336 | struct sock *sk; |
337 | struct hlist_node *node; | 337 | struct hlist_node *node; |
338 | 338 | ||
339 | sk_for_each(sk, node, &iucv_sk_list.head) | 339 | sk_for_each(sk, node, &iucv_sk_list.head) |
340 | if (!memcmp(&iucv_sk(sk)->src_name, nm, 8)) | 340 | if (!memcmp(&iucv_sk(sk)->src_name, nm, 8)) |
341 | return sk; | 341 | return sk; |
342 | 342 | ||
343 | return NULL; | 343 | return NULL; |
344 | } | 344 | } |
345 | 345 | ||
346 | static void iucv_sock_destruct(struct sock *sk) | 346 | static void iucv_sock_destruct(struct sock *sk) |
347 | { | 347 | { |
348 | skb_queue_purge(&sk->sk_receive_queue); | 348 | skb_queue_purge(&sk->sk_receive_queue); |
349 | skb_queue_purge(&sk->sk_write_queue); | 349 | skb_queue_purge(&sk->sk_write_queue); |
350 | } | 350 | } |
351 | 351 | ||
352 | /* Cleanup Listen */ | 352 | /* Cleanup Listen */ |
353 | static void iucv_sock_cleanup_listen(struct sock *parent) | 353 | static void iucv_sock_cleanup_listen(struct sock *parent) |
354 | { | 354 | { |
355 | struct sock *sk; | 355 | struct sock *sk; |
356 | 356 | ||
357 | /* Close non-accepted connections */ | 357 | /* Close non-accepted connections */ |
358 | while ((sk = iucv_accept_dequeue(parent, NULL))) { | 358 | while ((sk = iucv_accept_dequeue(parent, NULL))) { |
359 | iucv_sock_close(sk); | 359 | iucv_sock_close(sk); |
360 | iucv_sock_kill(sk); | 360 | iucv_sock_kill(sk); |
361 | } | 361 | } |
362 | 362 | ||
363 | parent->sk_state = IUCV_CLOSED; | 363 | parent->sk_state = IUCV_CLOSED; |
364 | } | 364 | } |
365 | 365 | ||
366 | /* Kill socket (only if zapped and orphaned) */ | 366 | /* Kill socket (only if zapped and orphaned) */ |
367 | static void iucv_sock_kill(struct sock *sk) | 367 | static void iucv_sock_kill(struct sock *sk) |
368 | { | 368 | { |
369 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) | 369 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
370 | return; | 370 | return; |
371 | 371 | ||
372 | iucv_sock_unlink(&iucv_sk_list, sk); | 372 | iucv_sock_unlink(&iucv_sk_list, sk); |
373 | sock_set_flag(sk, SOCK_DEAD); | 373 | sock_set_flag(sk, SOCK_DEAD); |
374 | sock_put(sk); | 374 | sock_put(sk); |
375 | } | 375 | } |
376 | 376 | ||
377 | /* Close an IUCV socket */ | 377 | /* Close an IUCV socket */ |
378 | static void iucv_sock_close(struct sock *sk) | 378 | static void iucv_sock_close(struct sock *sk) |
379 | { | 379 | { |
380 | unsigned char user_data[16]; | 380 | unsigned char user_data[16]; |
381 | struct iucv_sock *iucv = iucv_sk(sk); | 381 | struct iucv_sock *iucv = iucv_sk(sk); |
382 | int err; | 382 | int err; |
383 | unsigned long timeo; | 383 | unsigned long timeo; |
384 | 384 | ||
385 | iucv_sock_clear_timer(sk); | 385 | iucv_sock_clear_timer(sk); |
386 | lock_sock(sk); | 386 | lock_sock(sk); |
387 | 387 | ||
388 | switch (sk->sk_state) { | 388 | switch (sk->sk_state) { |
389 | case IUCV_LISTEN: | 389 | case IUCV_LISTEN: |
390 | iucv_sock_cleanup_listen(sk); | 390 | iucv_sock_cleanup_listen(sk); |
391 | break; | 391 | break; |
392 | 392 | ||
393 | case IUCV_CONNECTED: | 393 | case IUCV_CONNECTED: |
394 | case IUCV_DISCONN: | 394 | case IUCV_DISCONN: |
395 | err = 0; | 395 | err = 0; |
396 | 396 | ||
397 | sk->sk_state = IUCV_CLOSING; | 397 | sk->sk_state = IUCV_CLOSING; |
398 | sk->sk_state_change(sk); | 398 | sk->sk_state_change(sk); |
399 | 399 | ||
400 | if (!skb_queue_empty(&iucv->send_skb_q)) { | 400 | if (!skb_queue_empty(&iucv->send_skb_q)) { |
401 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) | 401 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) |
402 | timeo = sk->sk_lingertime; | 402 | timeo = sk->sk_lingertime; |
403 | else | 403 | else |
404 | timeo = IUCV_DISCONN_TIMEOUT; | 404 | timeo = IUCV_DISCONN_TIMEOUT; |
405 | err = iucv_sock_wait(sk, | 405 | err = iucv_sock_wait(sk, |
406 | iucv_sock_in_state(sk, IUCV_CLOSED, 0), | 406 | iucv_sock_in_state(sk, IUCV_CLOSED, 0), |
407 | timeo); | 407 | timeo); |
408 | } | 408 | } |
409 | 409 | ||
410 | case IUCV_CLOSING: /* fall through */ | 410 | case IUCV_CLOSING: /* fall through */ |
411 | sk->sk_state = IUCV_CLOSED; | 411 | sk->sk_state = IUCV_CLOSED; |
412 | sk->sk_state_change(sk); | 412 | sk->sk_state_change(sk); |
413 | 413 | ||
414 | if (iucv->path) { | 414 | if (iucv->path) { |
415 | low_nmcpy(user_data, iucv->src_name); | 415 | low_nmcpy(user_data, iucv->src_name); |
416 | high_nmcpy(user_data, iucv->dst_name); | 416 | high_nmcpy(user_data, iucv->dst_name); |
417 | ASCEBC(user_data, sizeof(user_data)); | 417 | ASCEBC(user_data, sizeof(user_data)); |
418 | err = iucv_path_sever(iucv->path, user_data); | 418 | err = iucv_path_sever(iucv->path, user_data); |
419 | iucv_path_free(iucv->path); | 419 | iucv_path_free(iucv->path); |
420 | iucv->path = NULL; | 420 | iucv->path = NULL; |
421 | } | 421 | } |
422 | 422 | ||
423 | sk->sk_err = ECONNRESET; | 423 | sk->sk_err = ECONNRESET; |
424 | sk->sk_state_change(sk); | 424 | sk->sk_state_change(sk); |
425 | 425 | ||
426 | skb_queue_purge(&iucv->send_skb_q); | 426 | skb_queue_purge(&iucv->send_skb_q); |
427 | skb_queue_purge(&iucv->backlog_skb_q); | 427 | skb_queue_purge(&iucv->backlog_skb_q); |
428 | break; | 428 | break; |
429 | 429 | ||
430 | default: | 430 | default: |
431 | sock_set_flag(sk, SOCK_ZAPPED); | 431 | sock_set_flag(sk, SOCK_ZAPPED); |
432 | /* nothing to do here */ | 432 | /* nothing to do here */ |
433 | break; | 433 | break; |
434 | } | 434 | } |
435 | 435 | ||
436 | /* mark socket for deletion by iucv_sock_kill() */ | 436 | /* mark socket for deletion by iucv_sock_kill() */ |
437 | sock_set_flag(sk, SOCK_ZAPPED); | 437 | sock_set_flag(sk, SOCK_ZAPPED); |
438 | 438 | ||
439 | release_sock(sk); | 439 | release_sock(sk); |
440 | } | 440 | } |
441 | 441 | ||
442 | static void iucv_sock_init(struct sock *sk, struct sock *parent) | 442 | static void iucv_sock_init(struct sock *sk, struct sock *parent) |
443 | { | 443 | { |
444 | if (parent) | 444 | if (parent) |
445 | sk->sk_type = parent->sk_type; | 445 | sk->sk_type = parent->sk_type; |
446 | } | 446 | } |
447 | 447 | ||
448 | static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio) | 448 | static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio) |
449 | { | 449 | { |
450 | struct sock *sk; | 450 | struct sock *sk; |
451 | 451 | ||
452 | sk = sk_alloc(&init_net, PF_IUCV, prio, &iucv_proto); | 452 | sk = sk_alloc(&init_net, PF_IUCV, prio, &iucv_proto); |
453 | if (!sk) | 453 | if (!sk) |
454 | return NULL; | 454 | return NULL; |
455 | 455 | ||
456 | sock_init_data(sock, sk); | 456 | sock_init_data(sock, sk); |
457 | INIT_LIST_HEAD(&iucv_sk(sk)->accept_q); | 457 | INIT_LIST_HEAD(&iucv_sk(sk)->accept_q); |
458 | spin_lock_init(&iucv_sk(sk)->accept_q_lock); | 458 | spin_lock_init(&iucv_sk(sk)->accept_q_lock); |
459 | skb_queue_head_init(&iucv_sk(sk)->send_skb_q); | 459 | skb_queue_head_init(&iucv_sk(sk)->send_skb_q); |
460 | INIT_LIST_HEAD(&iucv_sk(sk)->message_q.list); | 460 | INIT_LIST_HEAD(&iucv_sk(sk)->message_q.list); |
461 | spin_lock_init(&iucv_sk(sk)->message_q.lock); | 461 | spin_lock_init(&iucv_sk(sk)->message_q.lock); |
462 | skb_queue_head_init(&iucv_sk(sk)->backlog_skb_q); | 462 | skb_queue_head_init(&iucv_sk(sk)->backlog_skb_q); |
463 | iucv_sk(sk)->send_tag = 0; | 463 | iucv_sk(sk)->send_tag = 0; |
464 | iucv_sk(sk)->flags = 0; | 464 | iucv_sk(sk)->flags = 0; |
465 | iucv_sk(sk)->msglimit = IUCV_QUEUELEN_DEFAULT; | 465 | iucv_sk(sk)->msglimit = IUCV_QUEUELEN_DEFAULT; |
466 | iucv_sk(sk)->path = NULL; | 466 | iucv_sk(sk)->path = NULL; |
467 | memset(&iucv_sk(sk)->src_user_id , 0, 32); | 467 | memset(&iucv_sk(sk)->src_user_id , 0, 32); |
468 | 468 | ||
469 | sk->sk_destruct = iucv_sock_destruct; | 469 | sk->sk_destruct = iucv_sock_destruct; |
470 | sk->sk_sndtimeo = IUCV_CONN_TIMEOUT; | 470 | sk->sk_sndtimeo = IUCV_CONN_TIMEOUT; |
471 | sk->sk_allocation = GFP_DMA; | 471 | sk->sk_allocation = GFP_DMA; |
472 | 472 | ||
473 | sock_reset_flag(sk, SOCK_ZAPPED); | 473 | sock_reset_flag(sk, SOCK_ZAPPED); |
474 | 474 | ||
475 | sk->sk_protocol = proto; | 475 | sk->sk_protocol = proto; |
476 | sk->sk_state = IUCV_OPEN; | 476 | sk->sk_state = IUCV_OPEN; |
477 | 477 | ||
478 | setup_timer(&sk->sk_timer, iucv_sock_timeout, (unsigned long)sk); | 478 | setup_timer(&sk->sk_timer, iucv_sock_timeout, (unsigned long)sk); |
479 | 479 | ||
480 | iucv_sock_link(&iucv_sk_list, sk); | 480 | iucv_sock_link(&iucv_sk_list, sk); |
481 | return sk; | 481 | return sk; |
482 | } | 482 | } |
483 | 483 | ||
484 | /* Create an IUCV socket */ | 484 | /* Create an IUCV socket */ |
485 | static int iucv_sock_create(struct net *net, struct socket *sock, int protocol) | 485 | static int iucv_sock_create(struct net *net, struct socket *sock, int protocol) |
486 | { | 486 | { |
487 | struct sock *sk; | 487 | struct sock *sk; |
488 | 488 | ||
489 | if (protocol && protocol != PF_IUCV) | 489 | if (protocol && protocol != PF_IUCV) |
490 | return -EPROTONOSUPPORT; | 490 | return -EPROTONOSUPPORT; |
491 | 491 | ||
492 | sock->state = SS_UNCONNECTED; | 492 | sock->state = SS_UNCONNECTED; |
493 | 493 | ||
494 | switch (sock->type) { | 494 | switch (sock->type) { |
495 | case SOCK_STREAM: | 495 | case SOCK_STREAM: |
496 | sock->ops = &iucv_sock_ops; | 496 | sock->ops = &iucv_sock_ops; |
497 | break; | 497 | break; |
498 | case SOCK_SEQPACKET: | 498 | case SOCK_SEQPACKET: |
499 | /* currently, proto ops can handle both sk types */ | 499 | /* currently, proto ops can handle both sk types */ |
500 | sock->ops = &iucv_sock_ops; | 500 | sock->ops = &iucv_sock_ops; |
501 | break; | 501 | break; |
502 | default: | 502 | default: |
503 | return -ESOCKTNOSUPPORT; | 503 | return -ESOCKTNOSUPPORT; |
504 | } | 504 | } |
505 | 505 | ||
506 | sk = iucv_sock_alloc(sock, protocol, GFP_KERNEL); | 506 | sk = iucv_sock_alloc(sock, protocol, GFP_KERNEL); |
507 | if (!sk) | 507 | if (!sk) |
508 | return -ENOMEM; | 508 | return -ENOMEM; |
509 | 509 | ||
510 | iucv_sock_init(sk, NULL); | 510 | iucv_sock_init(sk, NULL); |
511 | 511 | ||
512 | return 0; | 512 | return 0; |
513 | } | 513 | } |
514 | 514 | ||
515 | void iucv_sock_link(struct iucv_sock_list *l, struct sock *sk) | 515 | void iucv_sock_link(struct iucv_sock_list *l, struct sock *sk) |
516 | { | 516 | { |
517 | write_lock_bh(&l->lock); | 517 | write_lock_bh(&l->lock); |
518 | sk_add_node(sk, &l->head); | 518 | sk_add_node(sk, &l->head); |
519 | write_unlock_bh(&l->lock); | 519 | write_unlock_bh(&l->lock); |
520 | } | 520 | } |
521 | 521 | ||
522 | void iucv_sock_unlink(struct iucv_sock_list *l, struct sock *sk) | 522 | void iucv_sock_unlink(struct iucv_sock_list *l, struct sock *sk) |
523 | { | 523 | { |
524 | write_lock_bh(&l->lock); | 524 | write_lock_bh(&l->lock); |
525 | sk_del_node_init(sk); | 525 | sk_del_node_init(sk); |
526 | write_unlock_bh(&l->lock); | 526 | write_unlock_bh(&l->lock); |
527 | } | 527 | } |
528 | 528 | ||
529 | void iucv_accept_enqueue(struct sock *parent, struct sock *sk) | 529 | void iucv_accept_enqueue(struct sock *parent, struct sock *sk) |
530 | { | 530 | { |
531 | unsigned long flags; | 531 | unsigned long flags; |
532 | struct iucv_sock *par = iucv_sk(parent); | 532 | struct iucv_sock *par = iucv_sk(parent); |
533 | 533 | ||
534 | sock_hold(sk); | 534 | sock_hold(sk); |
535 | spin_lock_irqsave(&par->accept_q_lock, flags); | 535 | spin_lock_irqsave(&par->accept_q_lock, flags); |
536 | list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q); | 536 | list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q); |
537 | spin_unlock_irqrestore(&par->accept_q_lock, flags); | 537 | spin_unlock_irqrestore(&par->accept_q_lock, flags); |
538 | iucv_sk(sk)->parent = parent; | 538 | iucv_sk(sk)->parent = parent; |
539 | parent->sk_ack_backlog++; | 539 | sk_acceptq_added(parent); |
540 | } | 540 | } |
541 | 541 | ||
542 | void iucv_accept_unlink(struct sock *sk) | 542 | void iucv_accept_unlink(struct sock *sk) |
543 | { | 543 | { |
544 | unsigned long flags; | 544 | unsigned long flags; |
545 | struct iucv_sock *par = iucv_sk(iucv_sk(sk)->parent); | 545 | struct iucv_sock *par = iucv_sk(iucv_sk(sk)->parent); |
546 | 546 | ||
547 | spin_lock_irqsave(&par->accept_q_lock, flags); | 547 | spin_lock_irqsave(&par->accept_q_lock, flags); |
548 | list_del_init(&iucv_sk(sk)->accept_q); | 548 | list_del_init(&iucv_sk(sk)->accept_q); |
549 | spin_unlock_irqrestore(&par->accept_q_lock, flags); | 549 | spin_unlock_irqrestore(&par->accept_q_lock, flags); |
550 | iucv_sk(sk)->parent->sk_ack_backlog--; | 550 | sk_acceptq_removed(iucv_sk(sk)->parent); |
551 | iucv_sk(sk)->parent = NULL; | 551 | iucv_sk(sk)->parent = NULL; |
552 | sock_put(sk); | 552 | sock_put(sk); |
553 | } | 553 | } |
554 | 554 | ||
555 | struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock) | 555 | struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock) |
556 | { | 556 | { |
557 | struct iucv_sock *isk, *n; | 557 | struct iucv_sock *isk, *n; |
558 | struct sock *sk; | 558 | struct sock *sk; |
559 | 559 | ||
560 | list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) { | 560 | list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) { |
561 | sk = (struct sock *) isk; | 561 | sk = (struct sock *) isk; |
562 | lock_sock(sk); | 562 | lock_sock(sk); |
563 | 563 | ||
564 | if (sk->sk_state == IUCV_CLOSED) { | 564 | if (sk->sk_state == IUCV_CLOSED) { |
565 | iucv_accept_unlink(sk); | 565 | iucv_accept_unlink(sk); |
566 | release_sock(sk); | 566 | release_sock(sk); |
567 | continue; | 567 | continue; |
568 | } | 568 | } |
569 | 569 | ||
570 | if (sk->sk_state == IUCV_CONNECTED || | 570 | if (sk->sk_state == IUCV_CONNECTED || |
571 | sk->sk_state == IUCV_SEVERED || | 571 | sk->sk_state == IUCV_SEVERED || |
572 | sk->sk_state == IUCV_DISCONN || /* due to PM restore */ | 572 | sk->sk_state == IUCV_DISCONN || /* due to PM restore */ |
573 | !newsock) { | 573 | !newsock) { |
574 | iucv_accept_unlink(sk); | 574 | iucv_accept_unlink(sk); |
575 | if (newsock) | 575 | if (newsock) |
576 | sock_graft(sk, newsock); | 576 | sock_graft(sk, newsock); |
577 | 577 | ||
578 | if (sk->sk_state == IUCV_SEVERED) | 578 | if (sk->sk_state == IUCV_SEVERED) |
579 | sk->sk_state = IUCV_DISCONN; | 579 | sk->sk_state = IUCV_DISCONN; |
580 | 580 | ||
581 | release_sock(sk); | 581 | release_sock(sk); |
582 | return sk; | 582 | return sk; |
583 | } | 583 | } |
584 | 584 | ||
585 | release_sock(sk); | 585 | release_sock(sk); |
586 | } | 586 | } |
587 | return NULL; | 587 | return NULL; |
588 | } | 588 | } |
589 | 589 | ||
590 | /* Bind an unbound socket */ | 590 | /* Bind an unbound socket */ |
591 | static int iucv_sock_bind(struct socket *sock, struct sockaddr *addr, | 591 | static int iucv_sock_bind(struct socket *sock, struct sockaddr *addr, |
592 | int addr_len) | 592 | int addr_len) |
593 | { | 593 | { |
594 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; | 594 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; |
595 | struct sock *sk = sock->sk; | 595 | struct sock *sk = sock->sk; |
596 | struct iucv_sock *iucv; | 596 | struct iucv_sock *iucv; |
597 | int err; | 597 | int err; |
598 | 598 | ||
599 | /* Verify the input sockaddr */ | 599 | /* Verify the input sockaddr */ |
600 | if (!addr || addr->sa_family != AF_IUCV) | 600 | if (!addr || addr->sa_family != AF_IUCV) |
601 | return -EINVAL; | 601 | return -EINVAL; |
602 | 602 | ||
603 | lock_sock(sk); | 603 | lock_sock(sk); |
604 | if (sk->sk_state != IUCV_OPEN) { | 604 | if (sk->sk_state != IUCV_OPEN) { |
605 | err = -EBADFD; | 605 | err = -EBADFD; |
606 | goto done; | 606 | goto done; |
607 | } | 607 | } |
608 | 608 | ||
609 | write_lock_bh(&iucv_sk_list.lock); | 609 | write_lock_bh(&iucv_sk_list.lock); |
610 | 610 | ||
611 | iucv = iucv_sk(sk); | 611 | iucv = iucv_sk(sk); |
612 | if (__iucv_get_sock_by_name(sa->siucv_name)) { | 612 | if (__iucv_get_sock_by_name(sa->siucv_name)) { |
613 | err = -EADDRINUSE; | 613 | err = -EADDRINUSE; |
614 | goto done_unlock; | 614 | goto done_unlock; |
615 | } | 615 | } |
616 | if (iucv->path) { | 616 | if (iucv->path) { |
617 | err = 0; | 617 | err = 0; |
618 | goto done_unlock; | 618 | goto done_unlock; |
619 | } | 619 | } |
620 | 620 | ||
621 | /* Bind the socket */ | 621 | /* Bind the socket */ |
622 | memcpy(iucv->src_name, sa->siucv_name, 8); | 622 | memcpy(iucv->src_name, sa->siucv_name, 8); |
623 | 623 | ||
624 | /* Copy the user id */ | 624 | /* Copy the user id */ |
625 | memcpy(iucv->src_user_id, iucv_userid, 8); | 625 | memcpy(iucv->src_user_id, iucv_userid, 8); |
626 | sk->sk_state = IUCV_BOUND; | 626 | sk->sk_state = IUCV_BOUND; |
627 | err = 0; | 627 | err = 0; |
628 | 628 | ||
629 | done_unlock: | 629 | done_unlock: |
630 | /* Release the socket list lock */ | 630 | /* Release the socket list lock */ |
631 | write_unlock_bh(&iucv_sk_list.lock); | 631 | write_unlock_bh(&iucv_sk_list.lock); |
632 | done: | 632 | done: |
633 | release_sock(sk); | 633 | release_sock(sk); |
634 | return err; | 634 | return err; |
635 | } | 635 | } |
636 | 636 | ||
637 | /* Automatically bind an unbound socket */ | 637 | /* Automatically bind an unbound socket */ |
638 | static int iucv_sock_autobind(struct sock *sk) | 638 | static int iucv_sock_autobind(struct sock *sk) |
639 | { | 639 | { |
640 | struct iucv_sock *iucv = iucv_sk(sk); | 640 | struct iucv_sock *iucv = iucv_sk(sk); |
641 | char query_buffer[80]; | 641 | char query_buffer[80]; |
642 | char name[12]; | 642 | char name[12]; |
643 | int err = 0; | 643 | int err = 0; |
644 | 644 | ||
645 | /* Set the userid and name */ | 645 | /* Set the userid and name */ |
646 | cpcmd("QUERY USERID", query_buffer, sizeof(query_buffer), &err); | 646 | cpcmd("QUERY USERID", query_buffer, sizeof(query_buffer), &err); |
647 | if (unlikely(err)) | 647 | if (unlikely(err)) |
648 | return -EPROTO; | 648 | return -EPROTO; |
649 | 649 | ||
650 | memcpy(iucv->src_user_id, query_buffer, 8); | 650 | memcpy(iucv->src_user_id, query_buffer, 8); |
651 | 651 | ||
652 | write_lock_bh(&iucv_sk_list.lock); | 652 | write_lock_bh(&iucv_sk_list.lock); |
653 | 653 | ||
654 | sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name)); | 654 | sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name)); |
655 | while (__iucv_get_sock_by_name(name)) { | 655 | while (__iucv_get_sock_by_name(name)) { |
656 | sprintf(name, "%08x", | 656 | sprintf(name, "%08x", |
657 | atomic_inc_return(&iucv_sk_list.autobind_name)); | 657 | atomic_inc_return(&iucv_sk_list.autobind_name)); |
658 | } | 658 | } |
659 | 659 | ||
660 | write_unlock_bh(&iucv_sk_list.lock); | 660 | write_unlock_bh(&iucv_sk_list.lock); |
661 | 661 | ||
662 | memcpy(&iucv->src_name, name, 8); | 662 | memcpy(&iucv->src_name, name, 8); |
663 | 663 | ||
664 | return err; | 664 | return err; |
665 | } | 665 | } |
666 | 666 | ||
667 | /* Connect an unconnected socket */ | 667 | /* Connect an unconnected socket */ |
668 | static int iucv_sock_connect(struct socket *sock, struct sockaddr *addr, | 668 | static int iucv_sock_connect(struct socket *sock, struct sockaddr *addr, |
669 | int alen, int flags) | 669 | int alen, int flags) |
670 | { | 670 | { |
671 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; | 671 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; |
672 | struct sock *sk = sock->sk; | 672 | struct sock *sk = sock->sk; |
673 | struct iucv_sock *iucv; | 673 | struct iucv_sock *iucv; |
674 | unsigned char user_data[16]; | 674 | unsigned char user_data[16]; |
675 | int err; | 675 | int err; |
676 | 676 | ||
677 | if (addr->sa_family != AF_IUCV || alen < sizeof(struct sockaddr_iucv)) | 677 | if (addr->sa_family != AF_IUCV || alen < sizeof(struct sockaddr_iucv)) |
678 | return -EINVAL; | 678 | return -EINVAL; |
679 | 679 | ||
680 | if (sk->sk_state != IUCV_OPEN && sk->sk_state != IUCV_BOUND) | 680 | if (sk->sk_state != IUCV_OPEN && sk->sk_state != IUCV_BOUND) |
681 | return -EBADFD; | 681 | return -EBADFD; |
682 | 682 | ||
683 | if (sk->sk_type != SOCK_STREAM && sk->sk_type != SOCK_SEQPACKET) | 683 | if (sk->sk_type != SOCK_STREAM && sk->sk_type != SOCK_SEQPACKET) |
684 | return -EINVAL; | 684 | return -EINVAL; |
685 | 685 | ||
686 | if (sk->sk_state == IUCV_OPEN) { | 686 | if (sk->sk_state == IUCV_OPEN) { |
687 | err = iucv_sock_autobind(sk); | 687 | err = iucv_sock_autobind(sk); |
688 | if (unlikely(err)) | 688 | if (unlikely(err)) |
689 | return err; | 689 | return err; |
690 | } | 690 | } |
691 | 691 | ||
692 | lock_sock(sk); | 692 | lock_sock(sk); |
693 | 693 | ||
694 | /* Set the destination information */ | 694 | /* Set the destination information */ |
695 | memcpy(iucv_sk(sk)->dst_user_id, sa->siucv_user_id, 8); | 695 | memcpy(iucv_sk(sk)->dst_user_id, sa->siucv_user_id, 8); |
696 | memcpy(iucv_sk(sk)->dst_name, sa->siucv_name, 8); | 696 | memcpy(iucv_sk(sk)->dst_name, sa->siucv_name, 8); |
697 | 697 | ||
698 | high_nmcpy(user_data, sa->siucv_name); | 698 | high_nmcpy(user_data, sa->siucv_name); |
699 | low_nmcpy(user_data, iucv_sk(sk)->src_name); | 699 | low_nmcpy(user_data, iucv_sk(sk)->src_name); |
700 | ASCEBC(user_data, sizeof(user_data)); | 700 | ASCEBC(user_data, sizeof(user_data)); |
701 | 701 | ||
702 | iucv = iucv_sk(sk); | 702 | iucv = iucv_sk(sk); |
703 | /* Create path. */ | 703 | /* Create path. */ |
704 | iucv->path = iucv_path_alloc(iucv->msglimit, | 704 | iucv->path = iucv_path_alloc(iucv->msglimit, |
705 | IUCV_IPRMDATA, GFP_KERNEL); | 705 | IUCV_IPRMDATA, GFP_KERNEL); |
706 | if (!iucv->path) { | 706 | if (!iucv->path) { |
707 | err = -ENOMEM; | 707 | err = -ENOMEM; |
708 | goto done; | 708 | goto done; |
709 | } | 709 | } |
710 | err = iucv_path_connect(iucv->path, &af_iucv_handler, | 710 | err = iucv_path_connect(iucv->path, &af_iucv_handler, |
711 | sa->siucv_user_id, NULL, user_data, sk); | 711 | sa->siucv_user_id, NULL, user_data, sk); |
712 | if (err) { | 712 | if (err) { |
713 | iucv_path_free(iucv->path); | 713 | iucv_path_free(iucv->path); |
714 | iucv->path = NULL; | 714 | iucv->path = NULL; |
715 | switch (err) { | 715 | switch (err) { |
716 | case 0x0b: /* Target communicator is not logged on */ | 716 | case 0x0b: /* Target communicator is not logged on */ |
717 | err = -ENETUNREACH; | 717 | err = -ENETUNREACH; |
718 | break; | 718 | break; |
719 | case 0x0d: /* Max connections for this guest exceeded */ | 719 | case 0x0d: /* Max connections for this guest exceeded */ |
720 | case 0x0e: /* Max connections for target guest exceeded */ | 720 | case 0x0e: /* Max connections for target guest exceeded */ |
721 | err = -EAGAIN; | 721 | err = -EAGAIN; |
722 | break; | 722 | break; |
723 | case 0x0f: /* Missing IUCV authorization */ | 723 | case 0x0f: /* Missing IUCV authorization */ |
724 | err = -EACCES; | 724 | err = -EACCES; |
725 | break; | 725 | break; |
726 | default: | 726 | default: |
727 | err = -ECONNREFUSED; | 727 | err = -ECONNREFUSED; |
728 | break; | 728 | break; |
729 | } | 729 | } |
730 | goto done; | 730 | goto done; |
731 | } | 731 | } |
732 | 732 | ||
733 | if (sk->sk_state != IUCV_CONNECTED) { | 733 | if (sk->sk_state != IUCV_CONNECTED) { |
734 | err = iucv_sock_wait(sk, iucv_sock_in_state(sk, IUCV_CONNECTED, | 734 | err = iucv_sock_wait(sk, iucv_sock_in_state(sk, IUCV_CONNECTED, |
735 | IUCV_DISCONN), | 735 | IUCV_DISCONN), |
736 | sock_sndtimeo(sk, flags & O_NONBLOCK)); | 736 | sock_sndtimeo(sk, flags & O_NONBLOCK)); |
737 | } | 737 | } |
738 | 738 | ||
739 | if (sk->sk_state == IUCV_DISCONN) { | 739 | if (sk->sk_state == IUCV_DISCONN) { |
740 | err = -ECONNREFUSED; | 740 | err = -ECONNREFUSED; |
741 | } | 741 | } |
742 | 742 | ||
743 | if (err) { | 743 | if (err) { |
744 | iucv_path_sever(iucv->path, NULL); | 744 | iucv_path_sever(iucv->path, NULL); |
745 | iucv_path_free(iucv->path); | 745 | iucv_path_free(iucv->path); |
746 | iucv->path = NULL; | 746 | iucv->path = NULL; |
747 | } | 747 | } |
748 | 748 | ||
749 | done: | 749 | done: |
750 | release_sock(sk); | 750 | release_sock(sk); |
751 | return err; | 751 | return err; |
752 | } | 752 | } |
753 | 753 | ||
754 | /* Move a socket into listening state. */ | 754 | /* Move a socket into listening state. */ |
755 | static int iucv_sock_listen(struct socket *sock, int backlog) | 755 | static int iucv_sock_listen(struct socket *sock, int backlog) |
756 | { | 756 | { |
757 | struct sock *sk = sock->sk; | 757 | struct sock *sk = sock->sk; |
758 | int err; | 758 | int err; |
759 | 759 | ||
760 | lock_sock(sk); | 760 | lock_sock(sk); |
761 | 761 | ||
762 | err = -EINVAL; | 762 | err = -EINVAL; |
763 | if (sk->sk_state != IUCV_BOUND) | 763 | if (sk->sk_state != IUCV_BOUND) |
764 | goto done; | 764 | goto done; |
765 | 765 | ||
766 | if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET) | 766 | if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET) |
767 | goto done; | 767 | goto done; |
768 | 768 | ||
769 | sk->sk_max_ack_backlog = backlog; | 769 | sk->sk_max_ack_backlog = backlog; |
770 | sk->sk_ack_backlog = 0; | 770 | sk->sk_ack_backlog = 0; |
771 | sk->sk_state = IUCV_LISTEN; | 771 | sk->sk_state = IUCV_LISTEN; |
772 | err = 0; | 772 | err = 0; |
773 | 773 | ||
774 | done: | 774 | done: |
775 | release_sock(sk); | 775 | release_sock(sk); |
776 | return err; | 776 | return err; |
777 | } | 777 | } |
778 | 778 | ||
779 | /* Accept a pending connection */ | 779 | /* Accept a pending connection */ |
780 | static int iucv_sock_accept(struct socket *sock, struct socket *newsock, | 780 | static int iucv_sock_accept(struct socket *sock, struct socket *newsock, |
781 | int flags) | 781 | int flags) |
782 | { | 782 | { |
783 | DECLARE_WAITQUEUE(wait, current); | 783 | DECLARE_WAITQUEUE(wait, current); |
784 | struct sock *sk = sock->sk, *nsk; | 784 | struct sock *sk = sock->sk, *nsk; |
785 | long timeo; | 785 | long timeo; |
786 | int err = 0; | 786 | int err = 0; |
787 | 787 | ||
788 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); | 788 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
789 | 789 | ||
790 | if (sk->sk_state != IUCV_LISTEN) { | 790 | if (sk->sk_state != IUCV_LISTEN) { |
791 | err = -EBADFD; | 791 | err = -EBADFD; |
792 | goto done; | 792 | goto done; |
793 | } | 793 | } |
794 | 794 | ||
795 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); | 795 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
796 | 796 | ||
797 | /* Wait for an incoming connection */ | 797 | /* Wait for an incoming connection */ |
798 | add_wait_queue_exclusive(sk->sk_sleep, &wait); | 798 | add_wait_queue_exclusive(sk->sk_sleep, &wait); |
799 | while (!(nsk = iucv_accept_dequeue(sk, newsock))) { | 799 | while (!(nsk = iucv_accept_dequeue(sk, newsock))) { |
800 | set_current_state(TASK_INTERRUPTIBLE); | 800 | set_current_state(TASK_INTERRUPTIBLE); |
801 | if (!timeo) { | 801 | if (!timeo) { |
802 | err = -EAGAIN; | 802 | err = -EAGAIN; |
803 | break; | 803 | break; |
804 | } | 804 | } |
805 | 805 | ||
806 | release_sock(sk); | 806 | release_sock(sk); |
807 | timeo = schedule_timeout(timeo); | 807 | timeo = schedule_timeout(timeo); |
808 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); | 808 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
809 | 809 | ||
810 | if (sk->sk_state != IUCV_LISTEN) { | 810 | if (sk->sk_state != IUCV_LISTEN) { |
811 | err = -EBADFD; | 811 | err = -EBADFD; |
812 | break; | 812 | break; |
813 | } | 813 | } |
814 | 814 | ||
815 | if (signal_pending(current)) { | 815 | if (signal_pending(current)) { |
816 | err = sock_intr_errno(timeo); | 816 | err = sock_intr_errno(timeo); |
817 | break; | 817 | break; |
818 | } | 818 | } |
819 | } | 819 | } |
820 | 820 | ||
821 | set_current_state(TASK_RUNNING); | 821 | set_current_state(TASK_RUNNING); |
822 | remove_wait_queue(sk->sk_sleep, &wait); | 822 | remove_wait_queue(sk->sk_sleep, &wait); |
823 | 823 | ||
824 | if (err) | 824 | if (err) |
825 | goto done; | 825 | goto done; |
826 | 826 | ||
827 | newsock->state = SS_CONNECTED; | 827 | newsock->state = SS_CONNECTED; |
828 | 828 | ||
829 | done: | 829 | done: |
830 | release_sock(sk); | 830 | release_sock(sk); |
831 | return err; | 831 | return err; |
832 | } | 832 | } |
833 | 833 | ||
834 | static int iucv_sock_getname(struct socket *sock, struct sockaddr *addr, | 834 | static int iucv_sock_getname(struct socket *sock, struct sockaddr *addr, |
835 | int *len, int peer) | 835 | int *len, int peer) |
836 | { | 836 | { |
837 | struct sockaddr_iucv *siucv = (struct sockaddr_iucv *) addr; | 837 | struct sockaddr_iucv *siucv = (struct sockaddr_iucv *) addr; |
838 | struct sock *sk = sock->sk; | 838 | struct sock *sk = sock->sk; |
839 | 839 | ||
840 | addr->sa_family = AF_IUCV; | 840 | addr->sa_family = AF_IUCV; |
841 | *len = sizeof(struct sockaddr_iucv); | 841 | *len = sizeof(struct sockaddr_iucv); |
842 | 842 | ||
843 | if (peer) { | 843 | if (peer) { |
844 | memcpy(siucv->siucv_user_id, iucv_sk(sk)->dst_user_id, 8); | 844 | memcpy(siucv->siucv_user_id, iucv_sk(sk)->dst_user_id, 8); |
845 | memcpy(siucv->siucv_name, &iucv_sk(sk)->dst_name, 8); | 845 | memcpy(siucv->siucv_name, &iucv_sk(sk)->dst_name, 8); |
846 | } else { | 846 | } else { |
847 | memcpy(siucv->siucv_user_id, iucv_sk(sk)->src_user_id, 8); | 847 | memcpy(siucv->siucv_user_id, iucv_sk(sk)->src_user_id, 8); |
848 | memcpy(siucv->siucv_name, iucv_sk(sk)->src_name, 8); | 848 | memcpy(siucv->siucv_name, iucv_sk(sk)->src_name, 8); |
849 | } | 849 | } |
850 | memset(&siucv->siucv_port, 0, sizeof(siucv->siucv_port)); | 850 | memset(&siucv->siucv_port, 0, sizeof(siucv->siucv_port)); |
851 | memset(&siucv->siucv_addr, 0, sizeof(siucv->siucv_addr)); | 851 | memset(&siucv->siucv_addr, 0, sizeof(siucv->siucv_addr)); |
852 | memset(siucv->siucv_nodeid, 0, sizeof(siucv->siucv_nodeid)); | 852 | memset(siucv->siucv_nodeid, 0, sizeof(siucv->siucv_nodeid)); |
853 | 853 | ||
854 | return 0; | 854 | return 0; |
855 | } | 855 | } |
856 | 856 | ||
857 | /** | 857 | /** |
858 | * iucv_send_iprm() - Send socket data in parameter list of an iucv message. | 858 | * iucv_send_iprm() - Send socket data in parameter list of an iucv message. |
859 | * @path: IUCV path | 859 | * @path: IUCV path |
860 | * @msg: Pointer to a struct iucv_message | 860 | * @msg: Pointer to a struct iucv_message |
861 | * @skb: The socket data to send, skb->len MUST BE <= 7 | 861 | * @skb: The socket data to send, skb->len MUST BE <= 7 |
862 | * | 862 | * |
863 | * Send the socket data in the parameter list in the iucv message | 863 | * Send the socket data in the parameter list in the iucv message |
864 | * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter | 864 | * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter |
865 | * list and the socket data len at index 7 (last byte). | 865 | * list and the socket data len at index 7 (last byte). |
866 | * See also iucv_msg_length(). | 866 | * See also iucv_msg_length(). |
867 | * | 867 | * |
868 | * Returns the error code from the iucv_message_send() call. | 868 | * Returns the error code from the iucv_message_send() call. |
869 | */ | 869 | */ |
870 | static int iucv_send_iprm(struct iucv_path *path, struct iucv_message *msg, | 870 | static int iucv_send_iprm(struct iucv_path *path, struct iucv_message *msg, |
871 | struct sk_buff *skb) | 871 | struct sk_buff *skb) |
872 | { | 872 | { |
873 | u8 prmdata[8]; | 873 | u8 prmdata[8]; |
874 | 874 | ||
875 | memcpy(prmdata, (void *) skb->data, skb->len); | 875 | memcpy(prmdata, (void *) skb->data, skb->len); |
876 | prmdata[7] = 0xff - (u8) skb->len; | 876 | prmdata[7] = 0xff - (u8) skb->len; |
877 | return iucv_message_send(path, msg, IUCV_IPRMDATA, 0, | 877 | return iucv_message_send(path, msg, IUCV_IPRMDATA, 0, |
878 | (void *) prmdata, 8); | 878 | (void *) prmdata, 8); |
879 | } | 879 | } |
880 | 880 | ||
881 | static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock, | 881 | static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock, |
882 | struct msghdr *msg, size_t len) | 882 | struct msghdr *msg, size_t len) |
883 | { | 883 | { |
884 | struct sock *sk = sock->sk; | 884 | struct sock *sk = sock->sk; |
885 | struct iucv_sock *iucv = iucv_sk(sk); | 885 | struct iucv_sock *iucv = iucv_sk(sk); |
886 | struct sk_buff *skb; | 886 | struct sk_buff *skb; |
887 | struct iucv_message txmsg; | 887 | struct iucv_message txmsg; |
888 | struct cmsghdr *cmsg; | 888 | struct cmsghdr *cmsg; |
889 | int cmsg_done; | 889 | int cmsg_done; |
890 | long timeo; | 890 | long timeo; |
891 | char user_id[9]; | 891 | char user_id[9]; |
892 | char appl_id[9]; | 892 | char appl_id[9]; |
893 | int err; | 893 | int err; |
894 | int noblock = msg->msg_flags & MSG_DONTWAIT; | 894 | int noblock = msg->msg_flags & MSG_DONTWAIT; |
895 | 895 | ||
896 | err = sock_error(sk); | 896 | err = sock_error(sk); |
897 | if (err) | 897 | if (err) |
898 | return err; | 898 | return err; |
899 | 899 | ||
900 | if (msg->msg_flags & MSG_OOB) | 900 | if (msg->msg_flags & MSG_OOB) |
901 | return -EOPNOTSUPP; | 901 | return -EOPNOTSUPP; |
902 | 902 | ||
903 | /* SOCK_SEQPACKET: we do not support segmented records */ | 903 | /* SOCK_SEQPACKET: we do not support segmented records */ |
904 | if (sk->sk_type == SOCK_SEQPACKET && !(msg->msg_flags & MSG_EOR)) | 904 | if (sk->sk_type == SOCK_SEQPACKET && !(msg->msg_flags & MSG_EOR)) |
905 | return -EOPNOTSUPP; | 905 | return -EOPNOTSUPP; |
906 | 906 | ||
907 | lock_sock(sk); | 907 | lock_sock(sk); |
908 | 908 | ||
909 | if (sk->sk_shutdown & SEND_SHUTDOWN) { | 909 | if (sk->sk_shutdown & SEND_SHUTDOWN) { |
910 | err = -EPIPE; | 910 | err = -EPIPE; |
911 | goto out; | 911 | goto out; |
912 | } | 912 | } |
913 | 913 | ||
914 | /* Return if the socket is not in connected state */ | 914 | /* Return if the socket is not in connected state */ |
915 | if (sk->sk_state != IUCV_CONNECTED) { | 915 | if (sk->sk_state != IUCV_CONNECTED) { |
916 | err = -ENOTCONN; | 916 | err = -ENOTCONN; |
917 | goto out; | 917 | goto out; |
918 | } | 918 | } |
919 | 919 | ||
920 | /* initialize defaults */ | 920 | /* initialize defaults */ |
921 | cmsg_done = 0; /* check for duplicate headers */ | 921 | cmsg_done = 0; /* check for duplicate headers */ |
922 | txmsg.class = 0; | 922 | txmsg.class = 0; |
923 | 923 | ||
924 | /* iterate over control messages */ | 924 | /* iterate over control messages */ |
925 | for (cmsg = CMSG_FIRSTHDR(msg); cmsg; | 925 | for (cmsg = CMSG_FIRSTHDR(msg); cmsg; |
926 | cmsg = CMSG_NXTHDR(msg, cmsg)) { | 926 | cmsg = CMSG_NXTHDR(msg, cmsg)) { |
927 | 927 | ||
928 | if (!CMSG_OK(msg, cmsg)) { | 928 | if (!CMSG_OK(msg, cmsg)) { |
929 | err = -EINVAL; | 929 | err = -EINVAL; |
930 | goto out; | 930 | goto out; |
931 | } | 931 | } |
932 | 932 | ||
933 | if (cmsg->cmsg_level != SOL_IUCV) | 933 | if (cmsg->cmsg_level != SOL_IUCV) |
934 | continue; | 934 | continue; |
935 | 935 | ||
936 | if (cmsg->cmsg_type & cmsg_done) { | 936 | if (cmsg->cmsg_type & cmsg_done) { |
937 | err = -EINVAL; | 937 | err = -EINVAL; |
938 | goto out; | 938 | goto out; |
939 | } | 939 | } |
940 | cmsg_done |= cmsg->cmsg_type; | 940 | cmsg_done |= cmsg->cmsg_type; |
941 | 941 | ||
942 | switch (cmsg->cmsg_type) { | 942 | switch (cmsg->cmsg_type) { |
943 | case SCM_IUCV_TRGCLS: | 943 | case SCM_IUCV_TRGCLS: |
944 | if (cmsg->cmsg_len != CMSG_LEN(TRGCLS_SIZE)) { | 944 | if (cmsg->cmsg_len != CMSG_LEN(TRGCLS_SIZE)) { |
945 | err = -EINVAL; | 945 | err = -EINVAL; |
946 | goto out; | 946 | goto out; |
947 | } | 947 | } |
948 | 948 | ||
949 | /* set iucv message target class */ | 949 | /* set iucv message target class */ |
950 | memcpy(&txmsg.class, | 950 | memcpy(&txmsg.class, |
951 | (void *) CMSG_DATA(cmsg), TRGCLS_SIZE); | 951 | (void *) CMSG_DATA(cmsg), TRGCLS_SIZE); |
952 | 952 | ||
953 | break; | 953 | break; |
954 | 954 | ||
955 | default: | 955 | default: |
956 | err = -EINVAL; | 956 | err = -EINVAL; |
957 | goto out; | 957 | goto out; |
958 | break; | 958 | break; |
959 | } | 959 | } |
960 | } | 960 | } |
961 | 961 | ||
962 | /* allocate one skb for each iucv message: | 962 | /* allocate one skb for each iucv message: |
963 | * this is fine for SOCK_SEQPACKET (unless we want to support | 963 | * this is fine for SOCK_SEQPACKET (unless we want to support |
964 | * segmented records using the MSG_EOR flag), but | 964 | * segmented records using the MSG_EOR flag), but |
965 | * for SOCK_STREAM we might want to improve it in future */ | 965 | * for SOCK_STREAM we might want to improve it in future */ |
966 | skb = sock_alloc_send_skb(sk, len, noblock, &err); | 966 | skb = sock_alloc_send_skb(sk, len, noblock, &err); |
967 | if (!skb) | 967 | if (!skb) |
968 | goto out; | 968 | goto out; |
969 | if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) { | 969 | if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) { |
970 | err = -EFAULT; | 970 | err = -EFAULT; |
971 | goto fail; | 971 | goto fail; |
972 | } | 972 | } |
973 | 973 | ||
974 | /* wait if outstanding messages for iucv path has reached */ | 974 | /* wait if outstanding messages for iucv path has reached */ |
975 | timeo = sock_sndtimeo(sk, noblock); | 975 | timeo = sock_sndtimeo(sk, noblock); |
976 | err = iucv_sock_wait(sk, iucv_below_msglim(sk), timeo); | 976 | err = iucv_sock_wait(sk, iucv_below_msglim(sk), timeo); |
977 | if (err) | 977 | if (err) |
978 | goto fail; | 978 | goto fail; |
979 | 979 | ||
980 | /* return -ECONNRESET if the socket is no longer connected */ | 980 | /* return -ECONNRESET if the socket is no longer connected */ |
981 | if (sk->sk_state != IUCV_CONNECTED) { | 981 | if (sk->sk_state != IUCV_CONNECTED) { |
982 | err = -ECONNRESET; | 982 | err = -ECONNRESET; |
983 | goto fail; | 983 | goto fail; |
984 | } | 984 | } |
985 | 985 | ||
986 | /* increment and save iucv message tag for msg_completion cbk */ | 986 | /* increment and save iucv message tag for msg_completion cbk */ |
987 | txmsg.tag = iucv->send_tag++; | 987 | txmsg.tag = iucv->send_tag++; |
988 | memcpy(CB_TAG(skb), &txmsg.tag, CB_TAG_LEN); | 988 | memcpy(CB_TAG(skb), &txmsg.tag, CB_TAG_LEN); |
989 | skb_queue_tail(&iucv->send_skb_q, skb); | 989 | skb_queue_tail(&iucv->send_skb_q, skb); |
990 | 990 | ||
991 | if (((iucv->path->flags & IUCV_IPRMDATA) & iucv->flags) | 991 | if (((iucv->path->flags & IUCV_IPRMDATA) & iucv->flags) |
992 | && skb->len <= 7) { | 992 | && skb->len <= 7) { |
993 | err = iucv_send_iprm(iucv->path, &txmsg, skb); | 993 | err = iucv_send_iprm(iucv->path, &txmsg, skb); |
994 | 994 | ||
995 | /* on success: there is no message_complete callback | 995 | /* on success: there is no message_complete callback |
996 | * for an IPRMDATA msg; remove skb from send queue */ | 996 | * for an IPRMDATA msg; remove skb from send queue */ |
997 | if (err == 0) { | 997 | if (err == 0) { |
998 | skb_unlink(skb, &iucv->send_skb_q); | 998 | skb_unlink(skb, &iucv->send_skb_q); |
999 | kfree_skb(skb); | 999 | kfree_skb(skb); |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | /* this error should never happen since the | 1002 | /* this error should never happen since the |
1003 | * IUCV_IPRMDATA path flag is set... sever path */ | 1003 | * IUCV_IPRMDATA path flag is set... sever path */ |
1004 | if (err == 0x15) { | 1004 | if (err == 0x15) { |
1005 | iucv_path_sever(iucv->path, NULL); | 1005 | iucv_path_sever(iucv->path, NULL); |
1006 | skb_unlink(skb, &iucv->send_skb_q); | 1006 | skb_unlink(skb, &iucv->send_skb_q); |
1007 | err = -EPIPE; | 1007 | err = -EPIPE; |
1008 | goto fail; | 1008 | goto fail; |
1009 | } | 1009 | } |
1010 | } else | 1010 | } else |
1011 | err = iucv_message_send(iucv->path, &txmsg, 0, 0, | 1011 | err = iucv_message_send(iucv->path, &txmsg, 0, 0, |
1012 | (void *) skb->data, skb->len); | 1012 | (void *) skb->data, skb->len); |
1013 | if (err) { | 1013 | if (err) { |
1014 | if (err == 3) { | 1014 | if (err == 3) { |
1015 | user_id[8] = 0; | 1015 | user_id[8] = 0; |
1016 | memcpy(user_id, iucv->dst_user_id, 8); | 1016 | memcpy(user_id, iucv->dst_user_id, 8); |
1017 | appl_id[8] = 0; | 1017 | appl_id[8] = 0; |
1018 | memcpy(appl_id, iucv->dst_name, 8); | 1018 | memcpy(appl_id, iucv->dst_name, 8); |
1019 | pr_err("Application %s on z/VM guest %s" | 1019 | pr_err("Application %s on z/VM guest %s" |
1020 | " exceeds message limit\n", | 1020 | " exceeds message limit\n", |
1021 | appl_id, user_id); | 1021 | appl_id, user_id); |
1022 | err = -EAGAIN; | 1022 | err = -EAGAIN; |
1023 | } else | 1023 | } else |
1024 | err = -EPIPE; | 1024 | err = -EPIPE; |
1025 | skb_unlink(skb, &iucv->send_skb_q); | 1025 | skb_unlink(skb, &iucv->send_skb_q); |
1026 | goto fail; | 1026 | goto fail; |
1027 | } | 1027 | } |
1028 | 1028 | ||
1029 | release_sock(sk); | 1029 | release_sock(sk); |
1030 | return len; | 1030 | return len; |
1031 | 1031 | ||
1032 | fail: | 1032 | fail: |
1033 | kfree_skb(skb); | 1033 | kfree_skb(skb); |
1034 | out: | 1034 | out: |
1035 | release_sock(sk); | 1035 | release_sock(sk); |
1036 | return err; | 1036 | return err; |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's | 1039 | /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's |
1040 | * | 1040 | * |
1041 | * Locking: must be called with message_q.lock held | 1041 | * Locking: must be called with message_q.lock held |
1042 | */ | 1042 | */ |
1043 | static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len) | 1043 | static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len) |
1044 | { | 1044 | { |
1045 | int dataleft, size, copied = 0; | 1045 | int dataleft, size, copied = 0; |
1046 | struct sk_buff *nskb; | 1046 | struct sk_buff *nskb; |
1047 | 1047 | ||
1048 | dataleft = len; | 1048 | dataleft = len; |
1049 | while (dataleft) { | 1049 | while (dataleft) { |
1050 | if (dataleft >= sk->sk_rcvbuf / 4) | 1050 | if (dataleft >= sk->sk_rcvbuf / 4) |
1051 | size = sk->sk_rcvbuf / 4; | 1051 | size = sk->sk_rcvbuf / 4; |
1052 | else | 1052 | else |
1053 | size = dataleft; | 1053 | size = dataleft; |
1054 | 1054 | ||
1055 | nskb = alloc_skb(size, GFP_ATOMIC | GFP_DMA); | 1055 | nskb = alloc_skb(size, GFP_ATOMIC | GFP_DMA); |
1056 | if (!nskb) | 1056 | if (!nskb) |
1057 | return -ENOMEM; | 1057 | return -ENOMEM; |
1058 | 1058 | ||
1059 | /* copy target class to control buffer of new skb */ | 1059 | /* copy target class to control buffer of new skb */ |
1060 | memcpy(CB_TRGCLS(nskb), CB_TRGCLS(skb), CB_TRGCLS_LEN); | 1060 | memcpy(CB_TRGCLS(nskb), CB_TRGCLS(skb), CB_TRGCLS_LEN); |
1061 | 1061 | ||
1062 | /* copy data fragment */ | 1062 | /* copy data fragment */ |
1063 | memcpy(nskb->data, skb->data + copied, size); | 1063 | memcpy(nskb->data, skb->data + copied, size); |
1064 | copied += size; | 1064 | copied += size; |
1065 | dataleft -= size; | 1065 | dataleft -= size; |
1066 | 1066 | ||
1067 | skb_reset_transport_header(nskb); | 1067 | skb_reset_transport_header(nskb); |
1068 | skb_reset_network_header(nskb); | 1068 | skb_reset_network_header(nskb); |
1069 | nskb->len = size; | 1069 | nskb->len = size; |
1070 | 1070 | ||
1071 | skb_queue_tail(&iucv_sk(sk)->backlog_skb_q, nskb); | 1071 | skb_queue_tail(&iucv_sk(sk)->backlog_skb_q, nskb); |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | return 0; | 1074 | return 0; |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | /* iucv_process_message() - Receive a single outstanding IUCV message | 1077 | /* iucv_process_message() - Receive a single outstanding IUCV message |
1078 | * | 1078 | * |
1079 | * Locking: must be called with message_q.lock held | 1079 | * Locking: must be called with message_q.lock held |
1080 | */ | 1080 | */ |
1081 | static void iucv_process_message(struct sock *sk, struct sk_buff *skb, | 1081 | static void iucv_process_message(struct sock *sk, struct sk_buff *skb, |
1082 | struct iucv_path *path, | 1082 | struct iucv_path *path, |
1083 | struct iucv_message *msg) | 1083 | struct iucv_message *msg) |
1084 | { | 1084 | { |
1085 | int rc; | 1085 | int rc; |
1086 | unsigned int len; | 1086 | unsigned int len; |
1087 | 1087 | ||
1088 | len = iucv_msg_length(msg); | 1088 | len = iucv_msg_length(msg); |
1089 | 1089 | ||
1090 | /* store msg target class in the second 4 bytes of skb ctrl buffer */ | 1090 | /* store msg target class in the second 4 bytes of skb ctrl buffer */ |
1091 | /* Note: the first 4 bytes are reserved for msg tag */ | 1091 | /* Note: the first 4 bytes are reserved for msg tag */ |
1092 | memcpy(CB_TRGCLS(skb), &msg->class, CB_TRGCLS_LEN); | 1092 | memcpy(CB_TRGCLS(skb), &msg->class, CB_TRGCLS_LEN); |
1093 | 1093 | ||
1094 | /* check for special IPRM messages (e.g. iucv_sock_shutdown) */ | 1094 | /* check for special IPRM messages (e.g. iucv_sock_shutdown) */ |
1095 | if ((msg->flags & IUCV_IPRMDATA) && len > 7) { | 1095 | if ((msg->flags & IUCV_IPRMDATA) && len > 7) { |
1096 | if (memcmp(msg->rmmsg, iprm_shutdown, 8) == 0) { | 1096 | if (memcmp(msg->rmmsg, iprm_shutdown, 8) == 0) { |
1097 | skb->data = NULL; | 1097 | skb->data = NULL; |
1098 | skb->len = 0; | 1098 | skb->len = 0; |
1099 | } | 1099 | } |
1100 | } else { | 1100 | } else { |
1101 | rc = iucv_message_receive(path, msg, msg->flags & IUCV_IPRMDATA, | 1101 | rc = iucv_message_receive(path, msg, msg->flags & IUCV_IPRMDATA, |
1102 | skb->data, len, NULL); | 1102 | skb->data, len, NULL); |
1103 | if (rc) { | 1103 | if (rc) { |
1104 | kfree_skb(skb); | 1104 | kfree_skb(skb); |
1105 | return; | 1105 | return; |
1106 | } | 1106 | } |
1107 | /* we need to fragment iucv messages for SOCK_STREAM only; | 1107 | /* we need to fragment iucv messages for SOCK_STREAM only; |
1108 | * for SOCK_SEQPACKET, it is only relevant if we support | 1108 | * for SOCK_SEQPACKET, it is only relevant if we support |
1109 | * record segmentation using MSG_EOR (see also recvmsg()) */ | 1109 | * record segmentation using MSG_EOR (see also recvmsg()) */ |
1110 | if (sk->sk_type == SOCK_STREAM && | 1110 | if (sk->sk_type == SOCK_STREAM && |
1111 | skb->truesize >= sk->sk_rcvbuf / 4) { | 1111 | skb->truesize >= sk->sk_rcvbuf / 4) { |
1112 | rc = iucv_fragment_skb(sk, skb, len); | 1112 | rc = iucv_fragment_skb(sk, skb, len); |
1113 | kfree_skb(skb); | 1113 | kfree_skb(skb); |
1114 | skb = NULL; | 1114 | skb = NULL; |
1115 | if (rc) { | 1115 | if (rc) { |
1116 | iucv_path_sever(path, NULL); | 1116 | iucv_path_sever(path, NULL); |
1117 | return; | 1117 | return; |
1118 | } | 1118 | } |
1119 | skb = skb_dequeue(&iucv_sk(sk)->backlog_skb_q); | 1119 | skb = skb_dequeue(&iucv_sk(sk)->backlog_skb_q); |
1120 | } else { | 1120 | } else { |
1121 | skb_reset_transport_header(skb); | 1121 | skb_reset_transport_header(skb); |
1122 | skb_reset_network_header(skb); | 1122 | skb_reset_network_header(skb); |
1123 | skb->len = len; | 1123 | skb->len = len; |
1124 | } | 1124 | } |
1125 | } | 1125 | } |
1126 | 1126 | ||
1127 | if (sock_queue_rcv_skb(sk, skb)) | 1127 | if (sock_queue_rcv_skb(sk, skb)) |
1128 | skb_queue_head(&iucv_sk(sk)->backlog_skb_q, skb); | 1128 | skb_queue_head(&iucv_sk(sk)->backlog_skb_q, skb); |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | /* iucv_process_message_q() - Process outstanding IUCV messages | 1131 | /* iucv_process_message_q() - Process outstanding IUCV messages |
1132 | * | 1132 | * |
1133 | * Locking: must be called with message_q.lock held | 1133 | * Locking: must be called with message_q.lock held |
1134 | */ | 1134 | */ |
1135 | static void iucv_process_message_q(struct sock *sk) | 1135 | static void iucv_process_message_q(struct sock *sk) |
1136 | { | 1136 | { |
1137 | struct iucv_sock *iucv = iucv_sk(sk); | 1137 | struct iucv_sock *iucv = iucv_sk(sk); |
1138 | struct sk_buff *skb; | 1138 | struct sk_buff *skb; |
1139 | struct sock_msg_q *p, *n; | 1139 | struct sock_msg_q *p, *n; |
1140 | 1140 | ||
1141 | list_for_each_entry_safe(p, n, &iucv->message_q.list, list) { | 1141 | list_for_each_entry_safe(p, n, &iucv->message_q.list, list) { |
1142 | skb = alloc_skb(iucv_msg_length(&p->msg), GFP_ATOMIC | GFP_DMA); | 1142 | skb = alloc_skb(iucv_msg_length(&p->msg), GFP_ATOMIC | GFP_DMA); |
1143 | if (!skb) | 1143 | if (!skb) |
1144 | break; | 1144 | break; |
1145 | iucv_process_message(sk, skb, p->path, &p->msg); | 1145 | iucv_process_message(sk, skb, p->path, &p->msg); |
1146 | list_del(&p->list); | 1146 | list_del(&p->list); |
1147 | kfree(p); | 1147 | kfree(p); |
1148 | if (!skb_queue_empty(&iucv->backlog_skb_q)) | 1148 | if (!skb_queue_empty(&iucv->backlog_skb_q)) |
1149 | break; | 1149 | break; |
1150 | } | 1150 | } |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock, | 1153 | static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock, |
1154 | struct msghdr *msg, size_t len, int flags) | 1154 | struct msghdr *msg, size_t len, int flags) |
1155 | { | 1155 | { |
1156 | int noblock = flags & MSG_DONTWAIT; | 1156 | int noblock = flags & MSG_DONTWAIT; |
1157 | struct sock *sk = sock->sk; | 1157 | struct sock *sk = sock->sk; |
1158 | struct iucv_sock *iucv = iucv_sk(sk); | 1158 | struct iucv_sock *iucv = iucv_sk(sk); |
1159 | unsigned int copied, rlen; | 1159 | unsigned int copied, rlen; |
1160 | struct sk_buff *skb, *rskb, *cskb; | 1160 | struct sk_buff *skb, *rskb, *cskb; |
1161 | int err = 0; | 1161 | int err = 0; |
1162 | 1162 | ||
1163 | if ((sk->sk_state == IUCV_DISCONN || sk->sk_state == IUCV_SEVERED) && | 1163 | if ((sk->sk_state == IUCV_DISCONN || sk->sk_state == IUCV_SEVERED) && |
1164 | skb_queue_empty(&iucv->backlog_skb_q) && | 1164 | skb_queue_empty(&iucv->backlog_skb_q) && |
1165 | skb_queue_empty(&sk->sk_receive_queue) && | 1165 | skb_queue_empty(&sk->sk_receive_queue) && |
1166 | list_empty(&iucv->message_q.list)) | 1166 | list_empty(&iucv->message_q.list)) |
1167 | return 0; | 1167 | return 0; |
1168 | 1168 | ||
1169 | if (flags & (MSG_OOB)) | 1169 | if (flags & (MSG_OOB)) |
1170 | return -EOPNOTSUPP; | 1170 | return -EOPNOTSUPP; |
1171 | 1171 | ||
1172 | /* receive/dequeue next skb: | 1172 | /* receive/dequeue next skb: |
1173 | * the function understands MSG_PEEK and, thus, does not dequeue skb */ | 1173 | * the function understands MSG_PEEK and, thus, does not dequeue skb */ |
1174 | skb = skb_recv_datagram(sk, flags, noblock, &err); | 1174 | skb = skb_recv_datagram(sk, flags, noblock, &err); |
1175 | if (!skb) { | 1175 | if (!skb) { |
1176 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 1176 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
1177 | return 0; | 1177 | return 0; |
1178 | return err; | 1178 | return err; |
1179 | } | 1179 | } |
1180 | 1180 | ||
1181 | rlen = skb->len; /* real length of skb */ | 1181 | rlen = skb->len; /* real length of skb */ |
1182 | copied = min_t(unsigned int, rlen, len); | 1182 | copied = min_t(unsigned int, rlen, len); |
1183 | 1183 | ||
1184 | cskb = skb; | 1184 | cskb = skb; |
1185 | if (memcpy_toiovec(msg->msg_iov, cskb->data, copied)) { | 1185 | if (memcpy_toiovec(msg->msg_iov, cskb->data, copied)) { |
1186 | if (!(flags & MSG_PEEK)) | 1186 | if (!(flags & MSG_PEEK)) |
1187 | skb_queue_head(&sk->sk_receive_queue, skb); | 1187 | skb_queue_head(&sk->sk_receive_queue, skb); |
1188 | return -EFAULT; | 1188 | return -EFAULT; |
1189 | } | 1189 | } |
1190 | 1190 | ||
1191 | /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */ | 1191 | /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */ |
1192 | if (sk->sk_type == SOCK_SEQPACKET) { | 1192 | if (sk->sk_type == SOCK_SEQPACKET) { |
1193 | if (copied < rlen) | 1193 | if (copied < rlen) |
1194 | msg->msg_flags |= MSG_TRUNC; | 1194 | msg->msg_flags |= MSG_TRUNC; |
1195 | /* each iucv message contains a complete record */ | 1195 | /* each iucv message contains a complete record */ |
1196 | msg->msg_flags |= MSG_EOR; | 1196 | msg->msg_flags |= MSG_EOR; |
1197 | } | 1197 | } |
1198 | 1198 | ||
1199 | /* create control message to store iucv msg target class: | 1199 | /* create control message to store iucv msg target class: |
1200 | * get the trgcls from the control buffer of the skb due to | 1200 | * get the trgcls from the control buffer of the skb due to |
1201 | * fragmentation of original iucv message. */ | 1201 | * fragmentation of original iucv message. */ |
1202 | err = put_cmsg(msg, SOL_IUCV, SCM_IUCV_TRGCLS, | 1202 | err = put_cmsg(msg, SOL_IUCV, SCM_IUCV_TRGCLS, |
1203 | CB_TRGCLS_LEN, CB_TRGCLS(skb)); | 1203 | CB_TRGCLS_LEN, CB_TRGCLS(skb)); |
1204 | if (err) { | 1204 | if (err) { |
1205 | if (!(flags & MSG_PEEK)) | 1205 | if (!(flags & MSG_PEEK)) |
1206 | skb_queue_head(&sk->sk_receive_queue, skb); | 1206 | skb_queue_head(&sk->sk_receive_queue, skb); |
1207 | return err; | 1207 | return err; |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | /* Mark read part of skb as used */ | 1210 | /* Mark read part of skb as used */ |
1211 | if (!(flags & MSG_PEEK)) { | 1211 | if (!(flags & MSG_PEEK)) { |
1212 | 1212 | ||
1213 | /* SOCK_STREAM: re-queue skb if it contains unreceived data */ | 1213 | /* SOCK_STREAM: re-queue skb if it contains unreceived data */ |
1214 | if (sk->sk_type == SOCK_STREAM) { | 1214 | if (sk->sk_type == SOCK_STREAM) { |
1215 | skb_pull(skb, copied); | 1215 | skb_pull(skb, copied); |
1216 | if (skb->len) { | 1216 | if (skb->len) { |
1217 | skb_queue_head(&sk->sk_receive_queue, skb); | 1217 | skb_queue_head(&sk->sk_receive_queue, skb); |
1218 | goto done; | 1218 | goto done; |
1219 | } | 1219 | } |
1220 | } | 1220 | } |
1221 | 1221 | ||
1222 | kfree_skb(skb); | 1222 | kfree_skb(skb); |
1223 | 1223 | ||
1224 | /* Queue backlog skbs */ | 1224 | /* Queue backlog skbs */ |
1225 | spin_lock_bh(&iucv->message_q.lock); | 1225 | spin_lock_bh(&iucv->message_q.lock); |
1226 | rskb = skb_dequeue(&iucv->backlog_skb_q); | 1226 | rskb = skb_dequeue(&iucv->backlog_skb_q); |
1227 | while (rskb) { | 1227 | while (rskb) { |
1228 | if (sock_queue_rcv_skb(sk, rskb)) { | 1228 | if (sock_queue_rcv_skb(sk, rskb)) { |
1229 | skb_queue_head(&iucv->backlog_skb_q, | 1229 | skb_queue_head(&iucv->backlog_skb_q, |
1230 | rskb); | 1230 | rskb); |
1231 | break; | 1231 | break; |
1232 | } else { | 1232 | } else { |
1233 | rskb = skb_dequeue(&iucv->backlog_skb_q); | 1233 | rskb = skb_dequeue(&iucv->backlog_skb_q); |
1234 | } | 1234 | } |
1235 | } | 1235 | } |
1236 | if (skb_queue_empty(&iucv->backlog_skb_q)) { | 1236 | if (skb_queue_empty(&iucv->backlog_skb_q)) { |
1237 | if (!list_empty(&iucv->message_q.list)) | 1237 | if (!list_empty(&iucv->message_q.list)) |
1238 | iucv_process_message_q(sk); | 1238 | iucv_process_message_q(sk); |
1239 | } | 1239 | } |
1240 | spin_unlock_bh(&iucv->message_q.lock); | 1240 | spin_unlock_bh(&iucv->message_q.lock); |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | done: | 1243 | done: |
1244 | /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */ | 1244 | /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */ |
1245 | if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC)) | 1245 | if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC)) |
1246 | copied = rlen; | 1246 | copied = rlen; |
1247 | 1247 | ||
1248 | return copied; | 1248 | return copied; |
1249 | } | 1249 | } |
1250 | 1250 | ||
1251 | static inline unsigned int iucv_accept_poll(struct sock *parent) | 1251 | static inline unsigned int iucv_accept_poll(struct sock *parent) |
1252 | { | 1252 | { |
1253 | struct iucv_sock *isk, *n; | 1253 | struct iucv_sock *isk, *n; |
1254 | struct sock *sk; | 1254 | struct sock *sk; |
1255 | 1255 | ||
1256 | list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) { | 1256 | list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) { |
1257 | sk = (struct sock *) isk; | 1257 | sk = (struct sock *) isk; |
1258 | 1258 | ||
1259 | if (sk->sk_state == IUCV_CONNECTED) | 1259 | if (sk->sk_state == IUCV_CONNECTED) |
1260 | return POLLIN | POLLRDNORM; | 1260 | return POLLIN | POLLRDNORM; |
1261 | } | 1261 | } |
1262 | 1262 | ||
1263 | return 0; | 1263 | return 0; |
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | unsigned int iucv_sock_poll(struct file *file, struct socket *sock, | 1266 | unsigned int iucv_sock_poll(struct file *file, struct socket *sock, |
1267 | poll_table *wait) | 1267 | poll_table *wait) |
1268 | { | 1268 | { |
1269 | struct sock *sk = sock->sk; | 1269 | struct sock *sk = sock->sk; |
1270 | unsigned int mask = 0; | 1270 | unsigned int mask = 0; |
1271 | 1271 | ||
1272 | sock_poll_wait(file, sk->sk_sleep, wait); | 1272 | sock_poll_wait(file, sk->sk_sleep, wait); |
1273 | 1273 | ||
1274 | if (sk->sk_state == IUCV_LISTEN) | 1274 | if (sk->sk_state == IUCV_LISTEN) |
1275 | return iucv_accept_poll(sk); | 1275 | return iucv_accept_poll(sk); |
1276 | 1276 | ||
1277 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) | 1277 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) |
1278 | mask |= POLLERR; | 1278 | mask |= POLLERR; |
1279 | 1279 | ||
1280 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 1280 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
1281 | mask |= POLLRDHUP; | 1281 | mask |= POLLRDHUP; |
1282 | 1282 | ||
1283 | if (sk->sk_shutdown == SHUTDOWN_MASK) | 1283 | if (sk->sk_shutdown == SHUTDOWN_MASK) |
1284 | mask |= POLLHUP; | 1284 | mask |= POLLHUP; |
1285 | 1285 | ||
1286 | if (!skb_queue_empty(&sk->sk_receive_queue) || | 1286 | if (!skb_queue_empty(&sk->sk_receive_queue) || |
1287 | (sk->sk_shutdown & RCV_SHUTDOWN)) | 1287 | (sk->sk_shutdown & RCV_SHUTDOWN)) |
1288 | mask |= POLLIN | POLLRDNORM; | 1288 | mask |= POLLIN | POLLRDNORM; |
1289 | 1289 | ||
1290 | if (sk->sk_state == IUCV_CLOSED) | 1290 | if (sk->sk_state == IUCV_CLOSED) |
1291 | mask |= POLLHUP; | 1291 | mask |= POLLHUP; |
1292 | 1292 | ||
1293 | if (sk->sk_state == IUCV_DISCONN || sk->sk_state == IUCV_SEVERED) | 1293 | if (sk->sk_state == IUCV_DISCONN || sk->sk_state == IUCV_SEVERED) |
1294 | mask |= POLLIN; | 1294 | mask |= POLLIN; |
1295 | 1295 | ||
1296 | if (sock_writeable(sk)) | 1296 | if (sock_writeable(sk)) |
1297 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; | 1297 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; |
1298 | else | 1298 | else |
1299 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | 1299 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); |
1300 | 1300 | ||
1301 | return mask; | 1301 | return mask; |
1302 | } | 1302 | } |
1303 | 1303 | ||
1304 | static int iucv_sock_shutdown(struct socket *sock, int how) | 1304 | static int iucv_sock_shutdown(struct socket *sock, int how) |
1305 | { | 1305 | { |
1306 | struct sock *sk = sock->sk; | 1306 | struct sock *sk = sock->sk; |
1307 | struct iucv_sock *iucv = iucv_sk(sk); | 1307 | struct iucv_sock *iucv = iucv_sk(sk); |
1308 | struct iucv_message txmsg; | 1308 | struct iucv_message txmsg; |
1309 | int err = 0; | 1309 | int err = 0; |
1310 | 1310 | ||
1311 | how++; | 1311 | how++; |
1312 | 1312 | ||
1313 | if ((how & ~SHUTDOWN_MASK) || !how) | 1313 | if ((how & ~SHUTDOWN_MASK) || !how) |
1314 | return -EINVAL; | 1314 | return -EINVAL; |
1315 | 1315 | ||
1316 | lock_sock(sk); | 1316 | lock_sock(sk); |
1317 | switch (sk->sk_state) { | 1317 | switch (sk->sk_state) { |
1318 | case IUCV_DISCONN: | 1318 | case IUCV_DISCONN: |
1319 | case IUCV_CLOSING: | 1319 | case IUCV_CLOSING: |
1320 | case IUCV_SEVERED: | 1320 | case IUCV_SEVERED: |
1321 | case IUCV_CLOSED: | 1321 | case IUCV_CLOSED: |
1322 | err = -ENOTCONN; | 1322 | err = -ENOTCONN; |
1323 | goto fail; | 1323 | goto fail; |
1324 | 1324 | ||
1325 | default: | 1325 | default: |
1326 | sk->sk_shutdown |= how; | 1326 | sk->sk_shutdown |= how; |
1327 | break; | 1327 | break; |
1328 | } | 1328 | } |
1329 | 1329 | ||
1330 | if (how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) { | 1330 | if (how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) { |
1331 | txmsg.class = 0; | 1331 | txmsg.class = 0; |
1332 | txmsg.tag = 0; | 1332 | txmsg.tag = 0; |
1333 | err = iucv_message_send(iucv->path, &txmsg, IUCV_IPRMDATA, 0, | 1333 | err = iucv_message_send(iucv->path, &txmsg, IUCV_IPRMDATA, 0, |
1334 | (void *) iprm_shutdown, 8); | 1334 | (void *) iprm_shutdown, 8); |
1335 | if (err) { | 1335 | if (err) { |
1336 | switch (err) { | 1336 | switch (err) { |
1337 | case 1: | 1337 | case 1: |
1338 | err = -ENOTCONN; | 1338 | err = -ENOTCONN; |
1339 | break; | 1339 | break; |
1340 | case 2: | 1340 | case 2: |
1341 | err = -ECONNRESET; | 1341 | err = -ECONNRESET; |
1342 | break; | 1342 | break; |
1343 | default: | 1343 | default: |
1344 | err = -ENOTCONN; | 1344 | err = -ENOTCONN; |
1345 | break; | 1345 | break; |
1346 | } | 1346 | } |
1347 | } | 1347 | } |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK) { | 1350 | if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK) { |
1351 | err = iucv_path_quiesce(iucv_sk(sk)->path, NULL); | 1351 | err = iucv_path_quiesce(iucv_sk(sk)->path, NULL); |
1352 | if (err) | 1352 | if (err) |
1353 | err = -ENOTCONN; | 1353 | err = -ENOTCONN; |
1354 | 1354 | ||
1355 | skb_queue_purge(&sk->sk_receive_queue); | 1355 | skb_queue_purge(&sk->sk_receive_queue); |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | /* Wake up anyone sleeping in poll */ | 1358 | /* Wake up anyone sleeping in poll */ |
1359 | sk->sk_state_change(sk); | 1359 | sk->sk_state_change(sk); |
1360 | 1360 | ||
1361 | fail: | 1361 | fail: |
1362 | release_sock(sk); | 1362 | release_sock(sk); |
1363 | return err; | 1363 | return err; |
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | static int iucv_sock_release(struct socket *sock) | 1366 | static int iucv_sock_release(struct socket *sock) |
1367 | { | 1367 | { |
1368 | struct sock *sk = sock->sk; | 1368 | struct sock *sk = sock->sk; |
1369 | int err = 0; | 1369 | int err = 0; |
1370 | 1370 | ||
1371 | if (!sk) | 1371 | if (!sk) |
1372 | return 0; | 1372 | return 0; |
1373 | 1373 | ||
1374 | iucv_sock_close(sk); | 1374 | iucv_sock_close(sk); |
1375 | 1375 | ||
1376 | /* Unregister with IUCV base support */ | 1376 | /* Unregister with IUCV base support */ |
1377 | if (iucv_sk(sk)->path) { | 1377 | if (iucv_sk(sk)->path) { |
1378 | iucv_path_sever(iucv_sk(sk)->path, NULL); | 1378 | iucv_path_sever(iucv_sk(sk)->path, NULL); |
1379 | iucv_path_free(iucv_sk(sk)->path); | 1379 | iucv_path_free(iucv_sk(sk)->path); |
1380 | iucv_sk(sk)->path = NULL; | 1380 | iucv_sk(sk)->path = NULL; |
1381 | } | 1381 | } |
1382 | 1382 | ||
1383 | sock_orphan(sk); | 1383 | sock_orphan(sk); |
1384 | iucv_sock_kill(sk); | 1384 | iucv_sock_kill(sk); |
1385 | return err; | 1385 | return err; |
1386 | } | 1386 | } |
1387 | 1387 | ||
1388 | /* getsockopt and setsockopt */ | 1388 | /* getsockopt and setsockopt */ |
1389 | static int iucv_sock_setsockopt(struct socket *sock, int level, int optname, | 1389 | static int iucv_sock_setsockopt(struct socket *sock, int level, int optname, |
1390 | char __user *optval, unsigned int optlen) | 1390 | char __user *optval, unsigned int optlen) |
1391 | { | 1391 | { |
1392 | struct sock *sk = sock->sk; | 1392 | struct sock *sk = sock->sk; |
1393 | struct iucv_sock *iucv = iucv_sk(sk); | 1393 | struct iucv_sock *iucv = iucv_sk(sk); |
1394 | int val; | 1394 | int val; |
1395 | int rc; | 1395 | int rc; |
1396 | 1396 | ||
1397 | if (level != SOL_IUCV) | 1397 | if (level != SOL_IUCV) |
1398 | return -ENOPROTOOPT; | 1398 | return -ENOPROTOOPT; |
1399 | 1399 | ||
1400 | if (optlen < sizeof(int)) | 1400 | if (optlen < sizeof(int)) |
1401 | return -EINVAL; | 1401 | return -EINVAL; |
1402 | 1402 | ||
1403 | if (get_user(val, (int __user *) optval)) | 1403 | if (get_user(val, (int __user *) optval)) |
1404 | return -EFAULT; | 1404 | return -EFAULT; |
1405 | 1405 | ||
1406 | rc = 0; | 1406 | rc = 0; |
1407 | 1407 | ||
1408 | lock_sock(sk); | 1408 | lock_sock(sk); |
1409 | switch (optname) { | 1409 | switch (optname) { |
1410 | case SO_IPRMDATA_MSG: | 1410 | case SO_IPRMDATA_MSG: |
1411 | if (val) | 1411 | if (val) |
1412 | iucv->flags |= IUCV_IPRMDATA; | 1412 | iucv->flags |= IUCV_IPRMDATA; |
1413 | else | 1413 | else |
1414 | iucv->flags &= ~IUCV_IPRMDATA; | 1414 | iucv->flags &= ~IUCV_IPRMDATA; |
1415 | break; | 1415 | break; |
1416 | case SO_MSGLIMIT: | 1416 | case SO_MSGLIMIT: |
1417 | switch (sk->sk_state) { | 1417 | switch (sk->sk_state) { |
1418 | case IUCV_OPEN: | 1418 | case IUCV_OPEN: |
1419 | case IUCV_BOUND: | 1419 | case IUCV_BOUND: |
1420 | if (val < 1 || val > (u16)(~0)) | 1420 | if (val < 1 || val > (u16)(~0)) |
1421 | rc = -EINVAL; | 1421 | rc = -EINVAL; |
1422 | else | 1422 | else |
1423 | iucv->msglimit = val; | 1423 | iucv->msglimit = val; |
1424 | break; | 1424 | break; |
1425 | default: | 1425 | default: |
1426 | rc = -EINVAL; | 1426 | rc = -EINVAL; |
1427 | break; | 1427 | break; |
1428 | } | 1428 | } |
1429 | break; | 1429 | break; |
1430 | default: | 1430 | default: |
1431 | rc = -ENOPROTOOPT; | 1431 | rc = -ENOPROTOOPT; |
1432 | break; | 1432 | break; |
1433 | } | 1433 | } |
1434 | release_sock(sk); | 1434 | release_sock(sk); |
1435 | 1435 | ||
1436 | return rc; | 1436 | return rc; |
1437 | } | 1437 | } |
1438 | 1438 | ||
1439 | static int iucv_sock_getsockopt(struct socket *sock, int level, int optname, | 1439 | static int iucv_sock_getsockopt(struct socket *sock, int level, int optname, |
1440 | char __user *optval, int __user *optlen) | 1440 | char __user *optval, int __user *optlen) |
1441 | { | 1441 | { |
1442 | struct sock *sk = sock->sk; | 1442 | struct sock *sk = sock->sk; |
1443 | struct iucv_sock *iucv = iucv_sk(sk); | 1443 | struct iucv_sock *iucv = iucv_sk(sk); |
1444 | int val, len; | 1444 | int val, len; |
1445 | 1445 | ||
1446 | if (level != SOL_IUCV) | 1446 | if (level != SOL_IUCV) |
1447 | return -ENOPROTOOPT; | 1447 | return -ENOPROTOOPT; |
1448 | 1448 | ||
1449 | if (get_user(len, optlen)) | 1449 | if (get_user(len, optlen)) |
1450 | return -EFAULT; | 1450 | return -EFAULT; |
1451 | 1451 | ||
1452 | if (len < 0) | 1452 | if (len < 0) |
1453 | return -EINVAL; | 1453 | return -EINVAL; |
1454 | 1454 | ||
1455 | len = min_t(unsigned int, len, sizeof(int)); | 1455 | len = min_t(unsigned int, len, sizeof(int)); |
1456 | 1456 | ||
1457 | switch (optname) { | 1457 | switch (optname) { |
1458 | case SO_IPRMDATA_MSG: | 1458 | case SO_IPRMDATA_MSG: |
1459 | val = (iucv->flags & IUCV_IPRMDATA) ? 1 : 0; | 1459 | val = (iucv->flags & IUCV_IPRMDATA) ? 1 : 0; |
1460 | break; | 1460 | break; |
1461 | case SO_MSGLIMIT: | 1461 | case SO_MSGLIMIT: |
1462 | lock_sock(sk); | 1462 | lock_sock(sk); |
1463 | val = (iucv->path != NULL) ? iucv->path->msglim /* connected */ | 1463 | val = (iucv->path != NULL) ? iucv->path->msglim /* connected */ |
1464 | : iucv->msglimit; /* default */ | 1464 | : iucv->msglimit; /* default */ |
1465 | release_sock(sk); | 1465 | release_sock(sk); |
1466 | break; | 1466 | break; |
1467 | default: | 1467 | default: |
1468 | return -ENOPROTOOPT; | 1468 | return -ENOPROTOOPT; |
1469 | } | 1469 | } |
1470 | 1470 | ||
1471 | if (put_user(len, optlen)) | 1471 | if (put_user(len, optlen)) |
1472 | return -EFAULT; | 1472 | return -EFAULT; |
1473 | if (copy_to_user(optval, &val, len)) | 1473 | if (copy_to_user(optval, &val, len)) |
1474 | return -EFAULT; | 1474 | return -EFAULT; |
1475 | 1475 | ||
1476 | return 0; | 1476 | return 0; |
1477 | } | 1477 | } |
1478 | 1478 | ||
1479 | 1479 | ||
1480 | /* Callback wrappers - called from iucv base support */ | 1480 | /* Callback wrappers - called from iucv base support */ |
1481 | static int iucv_callback_connreq(struct iucv_path *path, | 1481 | static int iucv_callback_connreq(struct iucv_path *path, |
1482 | u8 ipvmid[8], u8 ipuser[16]) | 1482 | u8 ipvmid[8], u8 ipuser[16]) |
1483 | { | 1483 | { |
1484 | unsigned char user_data[16]; | 1484 | unsigned char user_data[16]; |
1485 | unsigned char nuser_data[16]; | 1485 | unsigned char nuser_data[16]; |
1486 | unsigned char src_name[8]; | 1486 | unsigned char src_name[8]; |
1487 | struct hlist_node *node; | 1487 | struct hlist_node *node; |
1488 | struct sock *sk, *nsk; | 1488 | struct sock *sk, *nsk; |
1489 | struct iucv_sock *iucv, *niucv; | 1489 | struct iucv_sock *iucv, *niucv; |
1490 | int err; | 1490 | int err; |
1491 | 1491 | ||
1492 | memcpy(src_name, ipuser, 8); | 1492 | memcpy(src_name, ipuser, 8); |
1493 | EBCASC(src_name, 8); | 1493 | EBCASC(src_name, 8); |
1494 | /* Find out if this path belongs to af_iucv. */ | 1494 | /* Find out if this path belongs to af_iucv. */ |
1495 | read_lock(&iucv_sk_list.lock); | 1495 | read_lock(&iucv_sk_list.lock); |
1496 | iucv = NULL; | 1496 | iucv = NULL; |
1497 | sk = NULL; | 1497 | sk = NULL; |
1498 | sk_for_each(sk, node, &iucv_sk_list.head) | 1498 | sk_for_each(sk, node, &iucv_sk_list.head) |
1499 | if (sk->sk_state == IUCV_LISTEN && | 1499 | if (sk->sk_state == IUCV_LISTEN && |
1500 | !memcmp(&iucv_sk(sk)->src_name, src_name, 8)) { | 1500 | !memcmp(&iucv_sk(sk)->src_name, src_name, 8)) { |
1501 | /* | 1501 | /* |
1502 | * Found a listening socket with | 1502 | * Found a listening socket with |
1503 | * src_name == ipuser[0-7]. | 1503 | * src_name == ipuser[0-7]. |
1504 | */ | 1504 | */ |
1505 | iucv = iucv_sk(sk); | 1505 | iucv = iucv_sk(sk); |
1506 | break; | 1506 | break; |
1507 | } | 1507 | } |
1508 | read_unlock(&iucv_sk_list.lock); | 1508 | read_unlock(&iucv_sk_list.lock); |
1509 | if (!iucv) | 1509 | if (!iucv) |
1510 | /* No socket found, not one of our paths. */ | 1510 | /* No socket found, not one of our paths. */ |
1511 | return -EINVAL; | 1511 | return -EINVAL; |
1512 | 1512 | ||
1513 | bh_lock_sock(sk); | 1513 | bh_lock_sock(sk); |
1514 | 1514 | ||
1515 | /* Check if parent socket is listening */ | 1515 | /* Check if parent socket is listening */ |
1516 | low_nmcpy(user_data, iucv->src_name); | 1516 | low_nmcpy(user_data, iucv->src_name); |
1517 | high_nmcpy(user_data, iucv->dst_name); | 1517 | high_nmcpy(user_data, iucv->dst_name); |
1518 | ASCEBC(user_data, sizeof(user_data)); | 1518 | ASCEBC(user_data, sizeof(user_data)); |
1519 | if (sk->sk_state != IUCV_LISTEN) { | 1519 | if (sk->sk_state != IUCV_LISTEN) { |
1520 | err = iucv_path_sever(path, user_data); | 1520 | err = iucv_path_sever(path, user_data); |
1521 | iucv_path_free(path); | 1521 | iucv_path_free(path); |
1522 | goto fail; | 1522 | goto fail; |
1523 | } | 1523 | } |
1524 | 1524 | ||
1525 | /* Check for backlog size */ | 1525 | /* Check for backlog size */ |
1526 | if (sk_acceptq_is_full(sk)) { | 1526 | if (sk_acceptq_is_full(sk)) { |
1527 | err = iucv_path_sever(path, user_data); | 1527 | err = iucv_path_sever(path, user_data); |
1528 | iucv_path_free(path); | 1528 | iucv_path_free(path); |
1529 | goto fail; | 1529 | goto fail; |
1530 | } | 1530 | } |
1531 | 1531 | ||
1532 | /* Create the new socket */ | 1532 | /* Create the new socket */ |
1533 | nsk = iucv_sock_alloc(NULL, sk->sk_type, GFP_ATOMIC); | 1533 | nsk = iucv_sock_alloc(NULL, sk->sk_type, GFP_ATOMIC); |
1534 | if (!nsk) { | 1534 | if (!nsk) { |
1535 | err = iucv_path_sever(path, user_data); | 1535 | err = iucv_path_sever(path, user_data); |
1536 | iucv_path_free(path); | 1536 | iucv_path_free(path); |
1537 | goto fail; | 1537 | goto fail; |
1538 | } | 1538 | } |
1539 | 1539 | ||
1540 | niucv = iucv_sk(nsk); | 1540 | niucv = iucv_sk(nsk); |
1541 | iucv_sock_init(nsk, sk); | 1541 | iucv_sock_init(nsk, sk); |
1542 | 1542 | ||
1543 | /* Set the new iucv_sock */ | 1543 | /* Set the new iucv_sock */ |
1544 | memcpy(niucv->dst_name, ipuser + 8, 8); | 1544 | memcpy(niucv->dst_name, ipuser + 8, 8); |
1545 | EBCASC(niucv->dst_name, 8); | 1545 | EBCASC(niucv->dst_name, 8); |
1546 | memcpy(niucv->dst_user_id, ipvmid, 8); | 1546 | memcpy(niucv->dst_user_id, ipvmid, 8); |
1547 | memcpy(niucv->src_name, iucv->src_name, 8); | 1547 | memcpy(niucv->src_name, iucv->src_name, 8); |
1548 | memcpy(niucv->src_user_id, iucv->src_user_id, 8); | 1548 | memcpy(niucv->src_user_id, iucv->src_user_id, 8); |
1549 | niucv->path = path; | 1549 | niucv->path = path; |
1550 | 1550 | ||
1551 | /* Call iucv_accept */ | 1551 | /* Call iucv_accept */ |
1552 | high_nmcpy(nuser_data, ipuser + 8); | 1552 | high_nmcpy(nuser_data, ipuser + 8); |
1553 | memcpy(nuser_data + 8, niucv->src_name, 8); | 1553 | memcpy(nuser_data + 8, niucv->src_name, 8); |
1554 | ASCEBC(nuser_data + 8, 8); | 1554 | ASCEBC(nuser_data + 8, 8); |
1555 | 1555 | ||
1556 | /* set message limit for path based on msglimit of accepting socket */ | 1556 | /* set message limit for path based on msglimit of accepting socket */ |
1557 | niucv->msglimit = iucv->msglimit; | 1557 | niucv->msglimit = iucv->msglimit; |
1558 | path->msglim = iucv->msglimit; | 1558 | path->msglim = iucv->msglimit; |
1559 | err = iucv_path_accept(path, &af_iucv_handler, nuser_data, nsk); | 1559 | err = iucv_path_accept(path, &af_iucv_handler, nuser_data, nsk); |
1560 | if (err) { | 1560 | if (err) { |
1561 | err = iucv_path_sever(path, user_data); | 1561 | err = iucv_path_sever(path, user_data); |
1562 | iucv_path_free(path); | 1562 | iucv_path_free(path); |
1563 | iucv_sock_kill(nsk); | 1563 | iucv_sock_kill(nsk); |
1564 | goto fail; | 1564 | goto fail; |
1565 | } | 1565 | } |
1566 | 1566 | ||
1567 | iucv_accept_enqueue(sk, nsk); | 1567 | iucv_accept_enqueue(sk, nsk); |
1568 | 1568 | ||
1569 | /* Wake up accept */ | 1569 | /* Wake up accept */ |
1570 | nsk->sk_state = IUCV_CONNECTED; | 1570 | nsk->sk_state = IUCV_CONNECTED; |
1571 | sk->sk_data_ready(sk, 1); | 1571 | sk->sk_data_ready(sk, 1); |
1572 | err = 0; | 1572 | err = 0; |
1573 | fail: | 1573 | fail: |
1574 | bh_unlock_sock(sk); | 1574 | bh_unlock_sock(sk); |
1575 | return 0; | 1575 | return 0; |
1576 | } | 1576 | } |
1577 | 1577 | ||
1578 | static void iucv_callback_connack(struct iucv_path *path, u8 ipuser[16]) | 1578 | static void iucv_callback_connack(struct iucv_path *path, u8 ipuser[16]) |
1579 | { | 1579 | { |
1580 | struct sock *sk = path->private; | 1580 | struct sock *sk = path->private; |
1581 | 1581 | ||
1582 | sk->sk_state = IUCV_CONNECTED; | 1582 | sk->sk_state = IUCV_CONNECTED; |
1583 | sk->sk_state_change(sk); | 1583 | sk->sk_state_change(sk); |
1584 | } | 1584 | } |
1585 | 1585 | ||
1586 | static void iucv_callback_rx(struct iucv_path *path, struct iucv_message *msg) | 1586 | static void iucv_callback_rx(struct iucv_path *path, struct iucv_message *msg) |
1587 | { | 1587 | { |
1588 | struct sock *sk = path->private; | 1588 | struct sock *sk = path->private; |
1589 | struct iucv_sock *iucv = iucv_sk(sk); | 1589 | struct iucv_sock *iucv = iucv_sk(sk); |
1590 | struct sk_buff *skb; | 1590 | struct sk_buff *skb; |
1591 | struct sock_msg_q *save_msg; | 1591 | struct sock_msg_q *save_msg; |
1592 | int len; | 1592 | int len; |
1593 | 1593 | ||
1594 | if (sk->sk_shutdown & RCV_SHUTDOWN) { | 1594 | if (sk->sk_shutdown & RCV_SHUTDOWN) { |
1595 | iucv_message_reject(path, msg); | 1595 | iucv_message_reject(path, msg); |
1596 | return; | 1596 | return; |
1597 | } | 1597 | } |
1598 | 1598 | ||
1599 | spin_lock(&iucv->message_q.lock); | 1599 | spin_lock(&iucv->message_q.lock); |
1600 | 1600 | ||
1601 | if (!list_empty(&iucv->message_q.list) || | 1601 | if (!list_empty(&iucv->message_q.list) || |
1602 | !skb_queue_empty(&iucv->backlog_skb_q)) | 1602 | !skb_queue_empty(&iucv->backlog_skb_q)) |
1603 | goto save_message; | 1603 | goto save_message; |
1604 | 1604 | ||
1605 | len = atomic_read(&sk->sk_rmem_alloc); | 1605 | len = atomic_read(&sk->sk_rmem_alloc); |
1606 | len += iucv_msg_length(msg) + sizeof(struct sk_buff); | 1606 | len += iucv_msg_length(msg) + sizeof(struct sk_buff); |
1607 | if (len > sk->sk_rcvbuf) | 1607 | if (len > sk->sk_rcvbuf) |
1608 | goto save_message; | 1608 | goto save_message; |
1609 | 1609 | ||
1610 | skb = alloc_skb(iucv_msg_length(msg), GFP_ATOMIC | GFP_DMA); | 1610 | skb = alloc_skb(iucv_msg_length(msg), GFP_ATOMIC | GFP_DMA); |
1611 | if (!skb) | 1611 | if (!skb) |
1612 | goto save_message; | 1612 | goto save_message; |
1613 | 1613 | ||
1614 | iucv_process_message(sk, skb, path, msg); | 1614 | iucv_process_message(sk, skb, path, msg); |
1615 | goto out_unlock; | 1615 | goto out_unlock; |
1616 | 1616 | ||
1617 | save_message: | 1617 | save_message: |
1618 | save_msg = kzalloc(sizeof(struct sock_msg_q), GFP_ATOMIC | GFP_DMA); | 1618 | save_msg = kzalloc(sizeof(struct sock_msg_q), GFP_ATOMIC | GFP_DMA); |
1619 | if (!save_msg) | 1619 | if (!save_msg) |
1620 | return; | 1620 | return; |
1621 | save_msg->path = path; | 1621 | save_msg->path = path; |
1622 | save_msg->msg = *msg; | 1622 | save_msg->msg = *msg; |
1623 | 1623 | ||
1624 | list_add_tail(&save_msg->list, &iucv->message_q.list); | 1624 | list_add_tail(&save_msg->list, &iucv->message_q.list); |
1625 | 1625 | ||
1626 | out_unlock: | 1626 | out_unlock: |
1627 | spin_unlock(&iucv->message_q.lock); | 1627 | spin_unlock(&iucv->message_q.lock); |
1628 | } | 1628 | } |
1629 | 1629 | ||
1630 | static void iucv_callback_txdone(struct iucv_path *path, | 1630 | static void iucv_callback_txdone(struct iucv_path *path, |
1631 | struct iucv_message *msg) | 1631 | struct iucv_message *msg) |
1632 | { | 1632 | { |
1633 | struct sock *sk = path->private; | 1633 | struct sock *sk = path->private; |
1634 | struct sk_buff *this = NULL; | 1634 | struct sk_buff *this = NULL; |
1635 | struct sk_buff_head *list = &iucv_sk(sk)->send_skb_q; | 1635 | struct sk_buff_head *list = &iucv_sk(sk)->send_skb_q; |
1636 | struct sk_buff *list_skb = list->next; | 1636 | struct sk_buff *list_skb = list->next; |
1637 | unsigned long flags; | 1637 | unsigned long flags; |
1638 | 1638 | ||
1639 | if (!skb_queue_empty(list)) { | 1639 | if (!skb_queue_empty(list)) { |
1640 | spin_lock_irqsave(&list->lock, flags); | 1640 | spin_lock_irqsave(&list->lock, flags); |
1641 | 1641 | ||
1642 | while (list_skb != (struct sk_buff *)list) { | 1642 | while (list_skb != (struct sk_buff *)list) { |
1643 | if (!memcmp(&msg->tag, CB_TAG(list_skb), CB_TAG_LEN)) { | 1643 | if (!memcmp(&msg->tag, CB_TAG(list_skb), CB_TAG_LEN)) { |
1644 | this = list_skb; | 1644 | this = list_skb; |
1645 | break; | 1645 | break; |
1646 | } | 1646 | } |
1647 | list_skb = list_skb->next; | 1647 | list_skb = list_skb->next; |
1648 | } | 1648 | } |
1649 | if (this) | 1649 | if (this) |
1650 | __skb_unlink(this, list); | 1650 | __skb_unlink(this, list); |
1651 | 1651 | ||
1652 | spin_unlock_irqrestore(&list->lock, flags); | 1652 | spin_unlock_irqrestore(&list->lock, flags); |
1653 | 1653 | ||
1654 | if (this) { | 1654 | if (this) { |
1655 | kfree_skb(this); | 1655 | kfree_skb(this); |
1656 | /* wake up any process waiting for sending */ | 1656 | /* wake up any process waiting for sending */ |
1657 | iucv_sock_wake_msglim(sk); | 1657 | iucv_sock_wake_msglim(sk); |
1658 | } | 1658 | } |
1659 | } | 1659 | } |
1660 | BUG_ON(!this); | 1660 | BUG_ON(!this); |
1661 | 1661 | ||
1662 | if (sk->sk_state == IUCV_CLOSING) { | 1662 | if (sk->sk_state == IUCV_CLOSING) { |
1663 | if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) { | 1663 | if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) { |
1664 | sk->sk_state = IUCV_CLOSED; | 1664 | sk->sk_state = IUCV_CLOSED; |
1665 | sk->sk_state_change(sk); | 1665 | sk->sk_state_change(sk); |
1666 | } | 1666 | } |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | static void iucv_callback_connrej(struct iucv_path *path, u8 ipuser[16]) | 1671 | static void iucv_callback_connrej(struct iucv_path *path, u8 ipuser[16]) |
1672 | { | 1672 | { |
1673 | struct sock *sk = path->private; | 1673 | struct sock *sk = path->private; |
1674 | 1674 | ||
1675 | if (!list_empty(&iucv_sk(sk)->accept_q)) | 1675 | if (!list_empty(&iucv_sk(sk)->accept_q)) |
1676 | sk->sk_state = IUCV_SEVERED; | 1676 | sk->sk_state = IUCV_SEVERED; |
1677 | else | 1677 | else |
1678 | sk->sk_state = IUCV_DISCONN; | 1678 | sk->sk_state = IUCV_DISCONN; |
1679 | 1679 | ||
1680 | sk->sk_state_change(sk); | 1680 | sk->sk_state_change(sk); |
1681 | } | 1681 | } |
1682 | 1682 | ||
1683 | /* called if the other communication side shuts down its RECV direction; | 1683 | /* called if the other communication side shuts down its RECV direction; |
1684 | * in turn, the callback sets SEND_SHUTDOWN to disable sending of data. | 1684 | * in turn, the callback sets SEND_SHUTDOWN to disable sending of data. |
1685 | */ | 1685 | */ |
1686 | static void iucv_callback_shutdown(struct iucv_path *path, u8 ipuser[16]) | 1686 | static void iucv_callback_shutdown(struct iucv_path *path, u8 ipuser[16]) |
1687 | { | 1687 | { |
1688 | struct sock *sk = path->private; | 1688 | struct sock *sk = path->private; |
1689 | 1689 | ||
1690 | bh_lock_sock(sk); | 1690 | bh_lock_sock(sk); |
1691 | if (sk->sk_state != IUCV_CLOSED) { | 1691 | if (sk->sk_state != IUCV_CLOSED) { |
1692 | sk->sk_shutdown |= SEND_SHUTDOWN; | 1692 | sk->sk_shutdown |= SEND_SHUTDOWN; |
1693 | sk->sk_state_change(sk); | 1693 | sk->sk_state_change(sk); |
1694 | } | 1694 | } |
1695 | bh_unlock_sock(sk); | 1695 | bh_unlock_sock(sk); |
1696 | } | 1696 | } |
1697 | 1697 | ||
1698 | static const struct proto_ops iucv_sock_ops = { | 1698 | static const struct proto_ops iucv_sock_ops = { |
1699 | .family = PF_IUCV, | 1699 | .family = PF_IUCV, |
1700 | .owner = THIS_MODULE, | 1700 | .owner = THIS_MODULE, |
1701 | .release = iucv_sock_release, | 1701 | .release = iucv_sock_release, |
1702 | .bind = iucv_sock_bind, | 1702 | .bind = iucv_sock_bind, |
1703 | .connect = iucv_sock_connect, | 1703 | .connect = iucv_sock_connect, |
1704 | .listen = iucv_sock_listen, | 1704 | .listen = iucv_sock_listen, |
1705 | .accept = iucv_sock_accept, | 1705 | .accept = iucv_sock_accept, |
1706 | .getname = iucv_sock_getname, | 1706 | .getname = iucv_sock_getname, |
1707 | .sendmsg = iucv_sock_sendmsg, | 1707 | .sendmsg = iucv_sock_sendmsg, |
1708 | .recvmsg = iucv_sock_recvmsg, | 1708 | .recvmsg = iucv_sock_recvmsg, |
1709 | .poll = iucv_sock_poll, | 1709 | .poll = iucv_sock_poll, |
1710 | .ioctl = sock_no_ioctl, | 1710 | .ioctl = sock_no_ioctl, |
1711 | .mmap = sock_no_mmap, | 1711 | .mmap = sock_no_mmap, |
1712 | .socketpair = sock_no_socketpair, | 1712 | .socketpair = sock_no_socketpair, |
1713 | .shutdown = iucv_sock_shutdown, | 1713 | .shutdown = iucv_sock_shutdown, |
1714 | .setsockopt = iucv_sock_setsockopt, | 1714 | .setsockopt = iucv_sock_setsockopt, |
1715 | .getsockopt = iucv_sock_getsockopt, | 1715 | .getsockopt = iucv_sock_getsockopt, |
1716 | }; | 1716 | }; |
1717 | 1717 | ||
1718 | static const struct net_proto_family iucv_sock_family_ops = { | 1718 | static const struct net_proto_family iucv_sock_family_ops = { |
1719 | .family = AF_IUCV, | 1719 | .family = AF_IUCV, |
1720 | .owner = THIS_MODULE, | 1720 | .owner = THIS_MODULE, |
1721 | .create = iucv_sock_create, | 1721 | .create = iucv_sock_create, |
1722 | }; | 1722 | }; |
1723 | 1723 | ||
1724 | static int __init afiucv_init(void) | 1724 | static int __init afiucv_init(void) |
1725 | { | 1725 | { |
1726 | int err; | 1726 | int err; |
1727 | 1727 | ||
1728 | if (!MACHINE_IS_VM) { | 1728 | if (!MACHINE_IS_VM) { |
1729 | pr_err("The af_iucv module cannot be loaded" | 1729 | pr_err("The af_iucv module cannot be loaded" |
1730 | " without z/VM\n"); | 1730 | " without z/VM\n"); |
1731 | err = -EPROTONOSUPPORT; | 1731 | err = -EPROTONOSUPPORT; |
1732 | goto out; | 1732 | goto out; |
1733 | } | 1733 | } |
1734 | cpcmd("QUERY USERID", iucv_userid, sizeof(iucv_userid), &err); | 1734 | cpcmd("QUERY USERID", iucv_userid, sizeof(iucv_userid), &err); |
1735 | if (unlikely(err)) { | 1735 | if (unlikely(err)) { |
1736 | WARN_ON(err); | 1736 | WARN_ON(err); |
1737 | err = -EPROTONOSUPPORT; | 1737 | err = -EPROTONOSUPPORT; |
1738 | goto out; | 1738 | goto out; |
1739 | } | 1739 | } |
1740 | 1740 | ||
1741 | err = iucv_register(&af_iucv_handler, 0); | 1741 | err = iucv_register(&af_iucv_handler, 0); |
1742 | if (err) | 1742 | if (err) |
1743 | goto out; | 1743 | goto out; |
1744 | err = proto_register(&iucv_proto, 0); | 1744 | err = proto_register(&iucv_proto, 0); |
1745 | if (err) | 1745 | if (err) |
1746 | goto out_iucv; | 1746 | goto out_iucv; |
1747 | err = sock_register(&iucv_sock_family_ops); | 1747 | err = sock_register(&iucv_sock_family_ops); |
1748 | if (err) | 1748 | if (err) |
1749 | goto out_proto; | 1749 | goto out_proto; |
1750 | /* establish dummy device */ | 1750 | /* establish dummy device */ |
1751 | err = driver_register(&af_iucv_driver); | 1751 | err = driver_register(&af_iucv_driver); |
1752 | if (err) | 1752 | if (err) |
1753 | goto out_sock; | 1753 | goto out_sock; |
1754 | af_iucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); | 1754 | af_iucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
1755 | if (!af_iucv_dev) { | 1755 | if (!af_iucv_dev) { |
1756 | err = -ENOMEM; | 1756 | err = -ENOMEM; |
1757 | goto out_driver; | 1757 | goto out_driver; |
1758 | } | 1758 | } |
1759 | dev_set_name(af_iucv_dev, "af_iucv"); | 1759 | dev_set_name(af_iucv_dev, "af_iucv"); |
1760 | af_iucv_dev->bus = &iucv_bus; | 1760 | af_iucv_dev->bus = &iucv_bus; |
1761 | af_iucv_dev->parent = iucv_root; | 1761 | af_iucv_dev->parent = iucv_root; |
1762 | af_iucv_dev->release = (void (*)(struct device *))kfree; | 1762 | af_iucv_dev->release = (void (*)(struct device *))kfree; |
1763 | af_iucv_dev->driver = &af_iucv_driver; | 1763 | af_iucv_dev->driver = &af_iucv_driver; |
1764 | err = device_register(af_iucv_dev); | 1764 | err = device_register(af_iucv_dev); |
1765 | if (err) | 1765 | if (err) |
1766 | goto out_driver; | 1766 | goto out_driver; |
1767 | 1767 | ||
1768 | return 0; | 1768 | return 0; |
1769 | 1769 | ||
1770 | out_driver: | 1770 | out_driver: |
1771 | driver_unregister(&af_iucv_driver); | 1771 | driver_unregister(&af_iucv_driver); |
1772 | out_sock: | 1772 | out_sock: |
1773 | sock_unregister(PF_IUCV); | 1773 | sock_unregister(PF_IUCV); |
1774 | out_proto: | 1774 | out_proto: |
1775 | proto_unregister(&iucv_proto); | 1775 | proto_unregister(&iucv_proto); |
1776 | out_iucv: | 1776 | out_iucv: |
1777 | iucv_unregister(&af_iucv_handler, 0); | 1777 | iucv_unregister(&af_iucv_handler, 0); |
1778 | out: | 1778 | out: |
1779 | return err; | 1779 | return err; |
1780 | } | 1780 | } |
1781 | 1781 | ||
1782 | static void __exit afiucv_exit(void) | 1782 | static void __exit afiucv_exit(void) |
1783 | { | 1783 | { |
1784 | device_unregister(af_iucv_dev); | 1784 | device_unregister(af_iucv_dev); |
1785 | driver_unregister(&af_iucv_driver); | 1785 | driver_unregister(&af_iucv_driver); |
1786 | sock_unregister(PF_IUCV); | 1786 | sock_unregister(PF_IUCV); |
1787 | proto_unregister(&iucv_proto); | 1787 | proto_unregister(&iucv_proto); |
1788 | iucv_unregister(&af_iucv_handler, 0); | 1788 | iucv_unregister(&af_iucv_handler, 0); |
1789 | } | 1789 | } |
1790 | 1790 | ||
1791 | module_init(afiucv_init); | 1791 | module_init(afiucv_init); |
1792 | module_exit(afiucv_exit); | 1792 | module_exit(afiucv_exit); |
1793 | 1793 | ||
1794 | MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>"); | 1794 | MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>"); |
1795 | MODULE_DESCRIPTION("IUCV Sockets ver " VERSION); | 1795 | MODULE_DESCRIPTION("IUCV Sockets ver " VERSION); |
1796 | MODULE_VERSION(VERSION); | 1796 | MODULE_VERSION(VERSION); |
1797 | MODULE_LICENSE("GPL"); | 1797 | MODULE_LICENSE("GPL"); |
1798 | MODULE_ALIAS_NETPROTO(PF_IUCV); | 1798 | MODULE_ALIAS_NETPROTO(PF_IUCV); |
1799 | 1799 |