Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1 | /* |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2 | * IUCV protocol stack for Linux on zSeries |
| 3 | * |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2006, 2009 |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 5 | * |
| 6 | * Author(s): Jennifer Hunt <jenhunt@us.ibm.com> |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 7 | * Hendrik Brueckner <brueckner@linux.vnet.ibm.com> |
| 8 | * PM functions: |
| 9 | * Ursula Braun <ursula.braun@de.ibm.com> |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 12 | #define KMSG_COMPONENT "af_iucv" |
| 13 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 14 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/poll.h> |
| 25 | #include <net/sock.h> |
| 26 | #include <asm/ebcdic.h> |
| 27 | #include <asm/cpcmd.h> |
| 28 | #include <linux/kmod.h> |
| 29 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 30 | #include <net/iucv/af_iucv.h> |
| 31 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 32 | #define VERSION "1.2" |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 33 | |
| 34 | static char iucv_userid[80]; |
| 35 | |
Alexey Dobriyan | 5708e86 | 2009-09-14 12:23:23 +0000 | [diff] [blame] | 36 | static const struct proto_ops iucv_sock_ops; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 37 | |
| 38 | static struct proto iucv_proto = { |
| 39 | .name = "AF_IUCV", |
| 40 | .owner = THIS_MODULE, |
| 41 | .obj_size = sizeof(struct iucv_sock), |
| 42 | }; |
| 43 | |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 44 | static struct iucv_interface *pr_iucv; |
| 45 | |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 46 | /* special AF_IUCV IPRM messages */ |
| 47 | static const u8 iprm_shutdown[8] = |
| 48 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
| 49 | |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 50 | #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class)) |
| 51 | |
| 52 | /* macros to set/get socket control buffer at correct offset */ |
| 53 | #define CB_TAG(skb) ((skb)->cb) /* iucv message tag */ |
| 54 | #define CB_TAG_LEN (sizeof(((struct iucv_message *) 0)->tag)) |
| 55 | #define CB_TRGCLS(skb) ((skb)->cb + CB_TAG_LEN) /* iucv msg target class */ |
| 56 | #define CB_TRGCLS_LEN (TRGCLS_SIZE) |
| 57 | |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 58 | #define __iucv_sock_wait(sk, condition, timeo, ret) \ |
| 59 | do { \ |
| 60 | DEFINE_WAIT(__wait); \ |
| 61 | long __timeo = timeo; \ |
| 62 | ret = 0; \ |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 63 | prepare_to_wait(sk_sleep(sk), &__wait, TASK_INTERRUPTIBLE); \ |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 64 | while (!(condition)) { \ |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 65 | if (!__timeo) { \ |
| 66 | ret = -EAGAIN; \ |
| 67 | break; \ |
| 68 | } \ |
| 69 | if (signal_pending(current)) { \ |
| 70 | ret = sock_intr_errno(__timeo); \ |
| 71 | break; \ |
| 72 | } \ |
| 73 | release_sock(sk); \ |
| 74 | __timeo = schedule_timeout(__timeo); \ |
| 75 | lock_sock(sk); \ |
| 76 | ret = sock_error(sk); \ |
| 77 | if (ret) \ |
| 78 | break; \ |
| 79 | } \ |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 80 | finish_wait(sk_sleep(sk), &__wait); \ |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 81 | } while (0) |
| 82 | |
| 83 | #define iucv_sock_wait(sk, condition, timeo) \ |
| 84 | ({ \ |
| 85 | int __ret = 0; \ |
| 86 | if (!(condition)) \ |
| 87 | __iucv_sock_wait(sk, condition, timeo, __ret); \ |
| 88 | __ret; \ |
| 89 | }) |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 90 | |
Heiko Carstens | 57f2044 | 2007-10-08 02:02:52 -0700 | [diff] [blame] | 91 | static void iucv_sock_kill(struct sock *sk); |
| 92 | static void iucv_sock_close(struct sock *sk); |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 93 | static void iucv_sever_path(struct sock *, int); |
Heiko Carstens | 57f2044 | 2007-10-08 02:02:52 -0700 | [diff] [blame] | 94 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 95 | static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev, |
| 96 | struct packet_type *pt, struct net_device *orig_dev); |
| 97 | static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock, |
| 98 | struct sk_buff *skb, u8 flags); |
| 99 | static void afiucv_hs_callback_txnotify(struct sk_buff *, enum iucv_tx_notify); |
| 100 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 101 | /* Call Back functions */ |
| 102 | static void iucv_callback_rx(struct iucv_path *, struct iucv_message *); |
| 103 | static void iucv_callback_txdone(struct iucv_path *, struct iucv_message *); |
| 104 | static void iucv_callback_connack(struct iucv_path *, u8 ipuser[16]); |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 105 | static int iucv_callback_connreq(struct iucv_path *, u8 ipvmid[8], |
| 106 | u8 ipuser[16]); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 107 | static void iucv_callback_connrej(struct iucv_path *, u8 ipuser[16]); |
Hendrik Brueckner | af88b52 | 2009-04-21 23:26:21 +0000 | [diff] [blame] | 108 | static void iucv_callback_shutdown(struct iucv_path *, u8 ipuser[16]); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 109 | |
| 110 | static struct iucv_sock_list iucv_sk_list = { |
Robert P. J. Day | 3db8ce3 | 2008-04-10 02:11:24 -0700 | [diff] [blame] | 111 | .lock = __RW_LOCK_UNLOCKED(iucv_sk_list.lock), |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 112 | .autobind_name = ATOMIC_INIT(0) |
| 113 | }; |
| 114 | |
| 115 | static struct iucv_handler af_iucv_handler = { |
| 116 | .path_pending = iucv_callback_connreq, |
| 117 | .path_complete = iucv_callback_connack, |
| 118 | .path_severed = iucv_callback_connrej, |
| 119 | .message_pending = iucv_callback_rx, |
Hendrik Brueckner | af88b52 | 2009-04-21 23:26:21 +0000 | [diff] [blame] | 120 | .message_complete = iucv_callback_txdone, |
| 121 | .path_quiesced = iucv_callback_shutdown, |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | static inline void high_nmcpy(unsigned char *dst, char *src) |
| 125 | { |
| 126 | memcpy(dst, src, 8); |
| 127 | } |
| 128 | |
| 129 | static inline void low_nmcpy(unsigned char *dst, char *src) |
| 130 | { |
| 131 | memcpy(&dst[8], src, 8); |
| 132 | } |
| 133 | |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 134 | static int afiucv_pm_prepare(struct device *dev) |
| 135 | { |
| 136 | #ifdef CONFIG_PM_DEBUG |
| 137 | printk(KERN_WARNING "afiucv_pm_prepare\n"); |
| 138 | #endif |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static void afiucv_pm_complete(struct device *dev) |
| 143 | { |
| 144 | #ifdef CONFIG_PM_DEBUG |
| 145 | printk(KERN_WARNING "afiucv_pm_complete\n"); |
| 146 | #endif |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * afiucv_pm_freeze() - Freeze PM callback |
| 151 | * @dev: AFIUCV dummy device |
| 152 | * |
| 153 | * Sever all established IUCV communication pathes |
| 154 | */ |
| 155 | static int afiucv_pm_freeze(struct device *dev) |
| 156 | { |
| 157 | struct iucv_sock *iucv; |
| 158 | struct sock *sk; |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 159 | int err = 0; |
| 160 | |
| 161 | #ifdef CONFIG_PM_DEBUG |
| 162 | printk(KERN_WARNING "afiucv_pm_freeze\n"); |
| 163 | #endif |
| 164 | read_lock(&iucv_sk_list.lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 165 | sk_for_each(sk, &iucv_sk_list.head) { |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 166 | iucv = iucv_sk(sk); |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 167 | switch (sk->sk_state) { |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 168 | case IUCV_DISCONN: |
| 169 | case IUCV_CLOSING: |
| 170 | case IUCV_CONNECTED: |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 171 | iucv_sever_path(sk, 0); |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 172 | break; |
| 173 | case IUCV_OPEN: |
| 174 | case IUCV_BOUND: |
| 175 | case IUCV_LISTEN: |
| 176 | case IUCV_CLOSED: |
| 177 | default: |
| 178 | break; |
| 179 | } |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 180 | skb_queue_purge(&iucv->send_skb_q); |
| 181 | skb_queue_purge(&iucv->backlog_skb_q); |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 182 | } |
| 183 | read_unlock(&iucv_sk_list.lock); |
| 184 | return err; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * afiucv_pm_restore_thaw() - Thaw and restore PM callback |
| 189 | * @dev: AFIUCV dummy device |
| 190 | * |
| 191 | * socket clean up after freeze |
| 192 | */ |
| 193 | static int afiucv_pm_restore_thaw(struct device *dev) |
| 194 | { |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 195 | struct sock *sk; |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 196 | |
| 197 | #ifdef CONFIG_PM_DEBUG |
| 198 | printk(KERN_WARNING "afiucv_pm_restore_thaw\n"); |
| 199 | #endif |
| 200 | read_lock(&iucv_sk_list.lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 201 | sk_for_each(sk, &iucv_sk_list.head) { |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 202 | switch (sk->sk_state) { |
| 203 | case IUCV_CONNECTED: |
| 204 | sk->sk_err = EPIPE; |
| 205 | sk->sk_state = IUCV_DISCONN; |
| 206 | sk->sk_state_change(sk); |
| 207 | break; |
| 208 | case IUCV_DISCONN: |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 209 | case IUCV_CLOSING: |
| 210 | case IUCV_LISTEN: |
| 211 | case IUCV_BOUND: |
| 212 | case IUCV_OPEN: |
| 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | read_unlock(&iucv_sk_list.lock); |
| 218 | return 0; |
| 219 | } |
| 220 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 221 | static const struct dev_pm_ops afiucv_pm_ops = { |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 222 | .prepare = afiucv_pm_prepare, |
| 223 | .complete = afiucv_pm_complete, |
| 224 | .freeze = afiucv_pm_freeze, |
| 225 | .thaw = afiucv_pm_restore_thaw, |
| 226 | .restore = afiucv_pm_restore_thaw, |
| 227 | }; |
| 228 | |
| 229 | static struct device_driver af_iucv_driver = { |
| 230 | .owner = THIS_MODULE, |
| 231 | .name = "afiucv", |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 232 | .bus = NULL, |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 233 | .pm = &afiucv_pm_ops, |
| 234 | }; |
| 235 | |
| 236 | /* dummy device used as trigger for PM functions */ |
| 237 | static struct device *af_iucv_dev; |
| 238 | |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 239 | /** |
| 240 | * iucv_msg_length() - Returns the length of an iucv message. |
| 241 | * @msg: Pointer to struct iucv_message, MUST NOT be NULL |
| 242 | * |
| 243 | * The function returns the length of the specified iucv message @msg of data |
| 244 | * stored in a buffer and of data stored in the parameter list (PRMDATA). |
| 245 | * |
| 246 | * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket |
| 247 | * data: |
| 248 | * PRMDATA[0..6] socket data (max 7 bytes); |
| 249 | * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7]) |
| 250 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 251 | * The socket data length is computed by subtracting the socket data length |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 252 | * value from 0xFF. |
| 253 | * If the socket data len is greater 7, then PRMDATA can be used for special |
| 254 | * notifications (see iucv_sock_shutdown); and further, |
| 255 | * if the socket data len is > 7, the function returns 8. |
| 256 | * |
| 257 | * Use this function to allocate socket buffers to store iucv message data. |
| 258 | */ |
| 259 | static inline size_t iucv_msg_length(struct iucv_message *msg) |
| 260 | { |
| 261 | size_t datalen; |
| 262 | |
| 263 | if (msg->flags & IUCV_IPRMDATA) { |
| 264 | datalen = 0xff - msg->rmmsg[7]; |
| 265 | return (datalen < 8) ? datalen : 8; |
| 266 | } |
| 267 | return msg->length; |
| 268 | } |
| 269 | |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 270 | /** |
| 271 | * iucv_sock_in_state() - check for specific states |
| 272 | * @sk: sock structure |
| 273 | * @state: first iucv sk state |
| 274 | * @state: second iucv sk state |
| 275 | * |
| 276 | * Returns true if the socket in either in the first or second state. |
| 277 | */ |
| 278 | static int iucv_sock_in_state(struct sock *sk, int state, int state2) |
| 279 | { |
| 280 | return (sk->sk_state == state || sk->sk_state == state2); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * iucv_below_msglim() - function to check if messages can be sent |
| 285 | * @sk: sock structure |
| 286 | * |
| 287 | * Returns true if the send queue length is lower than the message limit. |
| 288 | * Always returns true if the socket is not connected (no iucv path for |
| 289 | * checking the message limit). |
| 290 | */ |
| 291 | static inline int iucv_below_msglim(struct sock *sk) |
| 292 | { |
| 293 | struct iucv_sock *iucv = iucv_sk(sk); |
| 294 | |
| 295 | if (sk->sk_state != IUCV_CONNECTED) |
| 296 | return 1; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 297 | if (iucv->transport == AF_IUCV_TRANS_IUCV) |
| 298 | return (skb_queue_len(&iucv->send_skb_q) < iucv->path->msglim); |
| 299 | else |
| 300 | return ((atomic_read(&iucv->msg_sent) < iucv->msglimit_peer) && |
| 301 | (atomic_read(&iucv->pendings) <= 0)); |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
| 305 | * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit |
| 306 | */ |
| 307 | static void iucv_sock_wake_msglim(struct sock *sk) |
| 308 | { |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 309 | struct socket_wq *wq; |
| 310 | |
| 311 | rcu_read_lock(); |
| 312 | wq = rcu_dereference(sk->sk_wq); |
| 313 | if (wq_has_sleeper(wq)) |
| 314 | wake_up_interruptible_all(&wq->wait); |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 315 | sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 316 | rcu_read_unlock(); |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 319 | /** |
| 320 | * afiucv_hs_send() - send a message through HiperSockets transport |
| 321 | */ |
| 322 | static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock, |
| 323 | struct sk_buff *skb, u8 flags) |
| 324 | { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 325 | struct iucv_sock *iucv = iucv_sk(sock); |
| 326 | struct af_iucv_trans_hdr *phs_hdr; |
| 327 | struct sk_buff *nskb; |
| 328 | int err, confirm_recv = 0; |
| 329 | |
| 330 | memset(skb->head, 0, ETH_HLEN); |
| 331 | phs_hdr = (struct af_iucv_trans_hdr *)skb_push(skb, |
| 332 | sizeof(struct af_iucv_trans_hdr)); |
| 333 | skb_reset_mac_header(skb); |
| 334 | skb_reset_network_header(skb); |
| 335 | skb_push(skb, ETH_HLEN); |
| 336 | skb_reset_mac_header(skb); |
| 337 | memset(phs_hdr, 0, sizeof(struct af_iucv_trans_hdr)); |
| 338 | |
| 339 | phs_hdr->magic = ETH_P_AF_IUCV; |
| 340 | phs_hdr->version = 1; |
| 341 | phs_hdr->flags = flags; |
| 342 | if (flags == AF_IUCV_FLAG_SYN) |
| 343 | phs_hdr->window = iucv->msglimit; |
| 344 | else if ((flags == AF_IUCV_FLAG_WIN) || !flags) { |
| 345 | confirm_recv = atomic_read(&iucv->msg_recv); |
| 346 | phs_hdr->window = confirm_recv; |
| 347 | if (confirm_recv) |
| 348 | phs_hdr->flags = phs_hdr->flags | AF_IUCV_FLAG_WIN; |
| 349 | } |
| 350 | memcpy(phs_hdr->destUserID, iucv->dst_user_id, 8); |
| 351 | memcpy(phs_hdr->destAppName, iucv->dst_name, 8); |
| 352 | memcpy(phs_hdr->srcUserID, iucv->src_user_id, 8); |
| 353 | memcpy(phs_hdr->srcAppName, iucv->src_name, 8); |
| 354 | ASCEBC(phs_hdr->destUserID, sizeof(phs_hdr->destUserID)); |
| 355 | ASCEBC(phs_hdr->destAppName, sizeof(phs_hdr->destAppName)); |
| 356 | ASCEBC(phs_hdr->srcUserID, sizeof(phs_hdr->srcUserID)); |
| 357 | ASCEBC(phs_hdr->srcAppName, sizeof(phs_hdr->srcAppName)); |
| 358 | if (imsg) |
| 359 | memcpy(&phs_hdr->iucv_hdr, imsg, sizeof(struct iucv_message)); |
| 360 | |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 361 | skb->dev = iucv->hs_dev; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 362 | if (!skb->dev) |
| 363 | return -ENODEV; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 364 | if (!(skb->dev->flags & IFF_UP) || !netif_carrier_ok(skb->dev)) |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 365 | return -ENETDOWN; |
| 366 | if (skb->len > skb->dev->mtu) { |
| 367 | if (sock->sk_type == SOCK_SEQPACKET) |
| 368 | return -EMSGSIZE; |
| 369 | else |
| 370 | skb_trim(skb, skb->dev->mtu); |
| 371 | } |
| 372 | skb->protocol = ETH_P_AF_IUCV; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 373 | nskb = skb_clone(skb, GFP_ATOMIC); |
| 374 | if (!nskb) |
| 375 | return -ENOMEM; |
| 376 | skb_queue_tail(&iucv->send_skb_q, nskb); |
| 377 | err = dev_queue_xmit(skb); |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 378 | if (net_xmit_eval(err)) { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 379 | skb_unlink(nskb, &iucv->send_skb_q); |
| 380 | kfree_skb(nskb); |
| 381 | } else { |
| 382 | atomic_sub(confirm_recv, &iucv->msg_recv); |
| 383 | WARN_ON(atomic_read(&iucv->msg_recv) < 0); |
| 384 | } |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 385 | return net_xmit_eval(err); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 388 | static struct sock *__iucv_get_sock_by_name(char *nm) |
| 389 | { |
| 390 | struct sock *sk; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 391 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 392 | sk_for_each(sk, &iucv_sk_list.head) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 393 | if (!memcmp(&iucv_sk(sk)->src_name, nm, 8)) |
| 394 | return sk; |
| 395 | |
| 396 | return NULL; |
| 397 | } |
| 398 | |
| 399 | static void iucv_sock_destruct(struct sock *sk) |
| 400 | { |
| 401 | skb_queue_purge(&sk->sk_receive_queue); |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 402 | skb_queue_purge(&sk->sk_error_queue); |
| 403 | |
| 404 | sk_mem_reclaim(sk); |
| 405 | |
| 406 | if (!sock_flag(sk, SOCK_DEAD)) { |
| 407 | pr_err("Attempt to release alive iucv socket %p\n", sk); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | WARN_ON(atomic_read(&sk->sk_rmem_alloc)); |
| 412 | WARN_ON(atomic_read(&sk->sk_wmem_alloc)); |
| 413 | WARN_ON(sk->sk_wmem_queued); |
| 414 | WARN_ON(sk->sk_forward_alloc); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* Cleanup Listen */ |
| 418 | static void iucv_sock_cleanup_listen(struct sock *parent) |
| 419 | { |
| 420 | struct sock *sk; |
| 421 | |
| 422 | /* Close non-accepted connections */ |
| 423 | while ((sk = iucv_accept_dequeue(parent, NULL))) { |
| 424 | iucv_sock_close(sk); |
| 425 | iucv_sock_kill(sk); |
| 426 | } |
| 427 | |
| 428 | parent->sk_state = IUCV_CLOSED; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Hendrik Brueckner | 7514bab | 2009-09-16 04:37:27 +0000 | [diff] [blame] | 431 | /* Kill socket (only if zapped and orphaned) */ |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 432 | static void iucv_sock_kill(struct sock *sk) |
| 433 | { |
| 434 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
| 435 | return; |
| 436 | |
| 437 | iucv_sock_unlink(&iucv_sk_list, sk); |
| 438 | sock_set_flag(sk, SOCK_DEAD); |
| 439 | sock_put(sk); |
| 440 | } |
| 441 | |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 442 | /* Terminate an IUCV path */ |
| 443 | static void iucv_sever_path(struct sock *sk, int with_user_data) |
| 444 | { |
| 445 | unsigned char user_data[16]; |
| 446 | struct iucv_sock *iucv = iucv_sk(sk); |
| 447 | struct iucv_path *path = iucv->path; |
| 448 | |
| 449 | if (iucv->path) { |
| 450 | iucv->path = NULL; |
| 451 | if (with_user_data) { |
| 452 | low_nmcpy(user_data, iucv->src_name); |
| 453 | high_nmcpy(user_data, iucv->dst_name); |
| 454 | ASCEBC(user_data, sizeof(user_data)); |
| 455 | pr_iucv->path_sever(path, user_data); |
| 456 | } else |
| 457 | pr_iucv->path_sever(path, NULL); |
| 458 | iucv_path_free(path); |
| 459 | } |
| 460 | } |
| 461 | |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 462 | /* Send FIN through an IUCV socket for HIPER transport */ |
| 463 | static int iucv_send_ctrl(struct sock *sk, u8 flags) |
| 464 | { |
| 465 | int err = 0; |
| 466 | int blen; |
| 467 | struct sk_buff *skb; |
| 468 | |
| 469 | blen = sizeof(struct af_iucv_trans_hdr) + ETH_HLEN; |
| 470 | skb = sock_alloc_send_skb(sk, blen, 1, &err); |
| 471 | if (skb) { |
| 472 | skb_reserve(skb, blen); |
| 473 | err = afiucv_hs_send(NULL, sk, skb, flags); |
| 474 | } |
| 475 | return err; |
| 476 | } |
| 477 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 478 | /* Close an IUCV socket */ |
| 479 | static void iucv_sock_close(struct sock *sk) |
| 480 | { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 481 | struct iucv_sock *iucv = iucv_sk(sk); |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 482 | unsigned long timeo; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 483 | int err = 0; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 484 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 485 | lock_sock(sk); |
| 486 | |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 487 | switch (sk->sk_state) { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 488 | case IUCV_LISTEN: |
| 489 | iucv_sock_cleanup_listen(sk); |
| 490 | break; |
| 491 | |
| 492 | case IUCV_CONNECTED: |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 493 | if (iucv->transport == AF_IUCV_TRANS_HIPER) { |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 494 | err = iucv_send_ctrl(sk, AF_IUCV_FLAG_FIN); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 495 | sk->sk_state = IUCV_DISCONN; |
| 496 | sk->sk_state_change(sk); |
| 497 | } |
Ursula Braun | 816abba | 2011-12-19 22:56:29 +0000 | [diff] [blame] | 498 | case IUCV_DISCONN: /* fall through */ |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 499 | sk->sk_state = IUCV_CLOSING; |
| 500 | sk->sk_state_change(sk); |
| 501 | |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 502 | if (!err && !skb_queue_empty(&iucv->send_skb_q)) { |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 503 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) |
| 504 | timeo = sk->sk_lingertime; |
| 505 | else |
| 506 | timeo = IUCV_DISCONN_TIMEOUT; |
Ursula Braun | 9f6298a | 2011-05-12 18:45:08 +0000 | [diff] [blame] | 507 | iucv_sock_wait(sk, |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 508 | iucv_sock_in_state(sk, IUCV_CLOSED, 0), |
| 509 | timeo); |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Ursula Braun | bbe188c | 2009-04-21 06:04:20 +0000 | [diff] [blame] | 512 | case IUCV_CLOSING: /* fall through */ |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 513 | sk->sk_state = IUCV_CLOSED; |
| 514 | sk->sk_state_change(sk); |
| 515 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 516 | sk->sk_err = ECONNRESET; |
| 517 | sk->sk_state_change(sk); |
| 518 | |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 519 | skb_queue_purge(&iucv->send_skb_q); |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 520 | skb_queue_purge(&iucv->backlog_skb_q); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 521 | |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 522 | default: /* fall through */ |
| 523 | iucv_sever_path(sk, 1); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 524 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 525 | |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 526 | if (iucv->hs_dev) { |
| 527 | dev_put(iucv->hs_dev); |
| 528 | iucv->hs_dev = NULL; |
| 529 | sk->sk_bound_dev_if = 0; |
| 530 | } |
| 531 | |
Hendrik Brueckner | 7514bab | 2009-09-16 04:37:27 +0000 | [diff] [blame] | 532 | /* mark socket for deletion by iucv_sock_kill() */ |
| 533 | sock_set_flag(sk, SOCK_ZAPPED); |
| 534 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 535 | release_sock(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void iucv_sock_init(struct sock *sk, struct sock *parent) |
| 539 | { |
| 540 | if (parent) |
| 541 | sk->sk_type = parent->sk_type; |
| 542 | } |
| 543 | |
| 544 | static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio) |
| 545 | { |
| 546 | struct sock *sk; |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 547 | struct iucv_sock *iucv; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 548 | |
Pavel Emelyanov | 6257ff2 | 2007-11-01 00:39:31 -0700 | [diff] [blame] | 549 | sk = sk_alloc(&init_net, PF_IUCV, prio, &iucv_proto); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 550 | if (!sk) |
| 551 | return NULL; |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 552 | iucv = iucv_sk(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 553 | |
| 554 | sock_init_data(sock, sk); |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 555 | INIT_LIST_HEAD(&iucv->accept_q); |
| 556 | spin_lock_init(&iucv->accept_q_lock); |
| 557 | skb_queue_head_init(&iucv->send_skb_q); |
| 558 | INIT_LIST_HEAD(&iucv->message_q.list); |
| 559 | spin_lock_init(&iucv->message_q.lock); |
| 560 | skb_queue_head_init(&iucv->backlog_skb_q); |
| 561 | iucv->send_tag = 0; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 562 | atomic_set(&iucv->pendings, 0); |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 563 | iucv->flags = 0; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 564 | iucv->msglimit = 0; |
| 565 | atomic_set(&iucv->msg_sent, 0); |
| 566 | atomic_set(&iucv->msg_recv, 0); |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 567 | iucv->path = NULL; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 568 | iucv->sk_txnotify = afiucv_hs_callback_txnotify; |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 569 | memset(&iucv->src_user_id , 0, 32); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 570 | if (pr_iucv) |
| 571 | iucv->transport = AF_IUCV_TRANS_IUCV; |
| 572 | else |
| 573 | iucv->transport = AF_IUCV_TRANS_HIPER; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 574 | |
| 575 | sk->sk_destruct = iucv_sock_destruct; |
| 576 | sk->sk_sndtimeo = IUCV_CONN_TIMEOUT; |
| 577 | sk->sk_allocation = GFP_DMA; |
| 578 | |
| 579 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 580 | |
| 581 | sk->sk_protocol = proto; |
| 582 | sk->sk_state = IUCV_OPEN; |
| 583 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 584 | iucv_sock_link(&iucv_sk_list, sk); |
| 585 | return sk; |
| 586 | } |
| 587 | |
| 588 | /* Create an IUCV socket */ |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 589 | static int iucv_sock_create(struct net *net, struct socket *sock, int protocol, |
| 590 | int kern) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 591 | { |
| 592 | struct sock *sk; |
| 593 | |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 594 | if (protocol && protocol != PF_IUCV) |
| 595 | return -EPROTONOSUPPORT; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 596 | |
| 597 | sock->state = SS_UNCONNECTED; |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 598 | |
| 599 | switch (sock->type) { |
| 600 | case SOCK_STREAM: |
| 601 | sock->ops = &iucv_sock_ops; |
| 602 | break; |
| 603 | case SOCK_SEQPACKET: |
| 604 | /* currently, proto ops can handle both sk types */ |
| 605 | sock->ops = &iucv_sock_ops; |
| 606 | break; |
| 607 | default: |
| 608 | return -ESOCKTNOSUPPORT; |
| 609 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 610 | |
| 611 | sk = iucv_sock_alloc(sock, protocol, GFP_KERNEL); |
| 612 | if (!sk) |
| 613 | return -ENOMEM; |
| 614 | |
| 615 | iucv_sock_init(sk, NULL); |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | void iucv_sock_link(struct iucv_sock_list *l, struct sock *sk) |
| 621 | { |
| 622 | write_lock_bh(&l->lock); |
| 623 | sk_add_node(sk, &l->head); |
| 624 | write_unlock_bh(&l->lock); |
| 625 | } |
| 626 | |
| 627 | void iucv_sock_unlink(struct iucv_sock_list *l, struct sock *sk) |
| 628 | { |
| 629 | write_lock_bh(&l->lock); |
| 630 | sk_del_node_init(sk); |
| 631 | write_unlock_bh(&l->lock); |
| 632 | } |
| 633 | |
| 634 | void iucv_accept_enqueue(struct sock *parent, struct sock *sk) |
| 635 | { |
Ursula Braun | febca28 | 2007-07-14 19:04:25 -0700 | [diff] [blame] | 636 | unsigned long flags; |
| 637 | struct iucv_sock *par = iucv_sk(parent); |
| 638 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 639 | sock_hold(sk); |
Ursula Braun | febca28 | 2007-07-14 19:04:25 -0700 | [diff] [blame] | 640 | spin_lock_irqsave(&par->accept_q_lock, flags); |
| 641 | list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q); |
| 642 | spin_unlock_irqrestore(&par->accept_q_lock, flags); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 643 | iucv_sk(sk)->parent = parent; |
Hendrik Brueckner | 49f5eba | 2009-10-14 22:54:55 +0000 | [diff] [blame] | 644 | sk_acceptq_added(parent); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void iucv_accept_unlink(struct sock *sk) |
| 648 | { |
Ursula Braun | febca28 | 2007-07-14 19:04:25 -0700 | [diff] [blame] | 649 | unsigned long flags; |
| 650 | struct iucv_sock *par = iucv_sk(iucv_sk(sk)->parent); |
| 651 | |
| 652 | spin_lock_irqsave(&par->accept_q_lock, flags); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 653 | list_del_init(&iucv_sk(sk)->accept_q); |
Ursula Braun | febca28 | 2007-07-14 19:04:25 -0700 | [diff] [blame] | 654 | spin_unlock_irqrestore(&par->accept_q_lock, flags); |
Hendrik Brueckner | 49f5eba | 2009-10-14 22:54:55 +0000 | [diff] [blame] | 655 | sk_acceptq_removed(iucv_sk(sk)->parent); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 656 | iucv_sk(sk)->parent = NULL; |
| 657 | sock_put(sk); |
| 658 | } |
| 659 | |
| 660 | struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock) |
| 661 | { |
| 662 | struct iucv_sock *isk, *n; |
| 663 | struct sock *sk; |
| 664 | |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 665 | list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 666 | sk = (struct sock *) isk; |
| 667 | lock_sock(sk); |
| 668 | |
| 669 | if (sk->sk_state == IUCV_CLOSED) { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 670 | iucv_accept_unlink(sk); |
Ursula Braun | febca28 | 2007-07-14 19:04:25 -0700 | [diff] [blame] | 671 | release_sock(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 672 | continue; |
| 673 | } |
| 674 | |
| 675 | if (sk->sk_state == IUCV_CONNECTED || |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 676 | sk->sk_state == IUCV_DISCONN || |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 677 | !newsock) { |
| 678 | iucv_accept_unlink(sk); |
| 679 | if (newsock) |
| 680 | sock_graft(sk, newsock); |
| 681 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 682 | release_sock(sk); |
| 683 | return sk; |
| 684 | } |
| 685 | |
| 686 | release_sock(sk); |
| 687 | } |
| 688 | return NULL; |
| 689 | } |
| 690 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 691 | /* Bind an unbound socket */ |
| 692 | static int iucv_sock_bind(struct socket *sock, struct sockaddr *addr, |
| 693 | int addr_len) |
| 694 | { |
| 695 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; |
| 696 | struct sock *sk = sock->sk; |
| 697 | struct iucv_sock *iucv; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 698 | int err = 0; |
| 699 | struct net_device *dev; |
| 700 | char uid[9]; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 701 | |
| 702 | /* Verify the input sockaddr */ |
| 703 | if (!addr || addr->sa_family != AF_IUCV) |
| 704 | return -EINVAL; |
| 705 | |
| 706 | lock_sock(sk); |
| 707 | if (sk->sk_state != IUCV_OPEN) { |
| 708 | err = -EBADFD; |
| 709 | goto done; |
| 710 | } |
| 711 | |
| 712 | write_lock_bh(&iucv_sk_list.lock); |
| 713 | |
| 714 | iucv = iucv_sk(sk); |
| 715 | if (__iucv_get_sock_by_name(sa->siucv_name)) { |
| 716 | err = -EADDRINUSE; |
| 717 | goto done_unlock; |
| 718 | } |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 719 | if (iucv->path) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 720 | goto done_unlock; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 721 | |
| 722 | /* Bind the socket */ |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 723 | if (pr_iucv) |
| 724 | if (!memcmp(sa->siucv_user_id, iucv_userid, 8)) |
| 725 | goto vm_bind; /* VM IUCV transport */ |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 726 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 727 | /* try hiper transport */ |
| 728 | memcpy(uid, sa->siucv_user_id, sizeof(uid)); |
| 729 | ASCEBC(uid, 8); |
| 730 | rcu_read_lock(); |
| 731 | for_each_netdev_rcu(&init_net, dev) { |
| 732 | if (!memcmp(dev->perm_addr, uid, 8)) { |
| 733 | memcpy(iucv->src_name, sa->siucv_name, 8); |
| 734 | memcpy(iucv->src_user_id, sa->siucv_user_id, 8); |
Ursula Braun | 816abba | 2011-12-19 22:56:29 +0000 | [diff] [blame] | 735 | sk->sk_bound_dev_if = dev->ifindex; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 736 | iucv->hs_dev = dev; |
| 737 | dev_hold(dev); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 738 | sk->sk_state = IUCV_BOUND; |
| 739 | iucv->transport = AF_IUCV_TRANS_HIPER; |
| 740 | if (!iucv->msglimit) |
| 741 | iucv->msglimit = IUCV_HIPER_MSGLIM_DEFAULT; |
| 742 | rcu_read_unlock(); |
| 743 | goto done_unlock; |
| 744 | } |
| 745 | } |
| 746 | rcu_read_unlock(); |
| 747 | vm_bind: |
| 748 | if (pr_iucv) { |
| 749 | /* use local userid for backward compat */ |
| 750 | memcpy(iucv->src_name, sa->siucv_name, 8); |
| 751 | memcpy(iucv->src_user_id, iucv_userid, 8); |
| 752 | sk->sk_state = IUCV_BOUND; |
| 753 | iucv->transport = AF_IUCV_TRANS_IUCV; |
| 754 | if (!iucv->msglimit) |
| 755 | iucv->msglimit = IUCV_QUEUELEN_DEFAULT; |
| 756 | goto done_unlock; |
| 757 | } |
| 758 | /* found no dev to bind */ |
| 759 | err = -ENODEV; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 760 | done_unlock: |
| 761 | /* Release the socket list lock */ |
| 762 | write_unlock_bh(&iucv_sk_list.lock); |
| 763 | done: |
| 764 | release_sock(sk); |
| 765 | return err; |
| 766 | } |
| 767 | |
| 768 | /* Automatically bind an unbound socket */ |
| 769 | static int iucv_sock_autobind(struct sock *sk) |
| 770 | { |
| 771 | struct iucv_sock *iucv = iucv_sk(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 772 | char name[12]; |
| 773 | int err = 0; |
| 774 | |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 775 | if (unlikely(!pr_iucv)) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 776 | return -EPROTO; |
| 777 | |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 778 | memcpy(iucv->src_user_id, iucv_userid, 8); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 779 | |
| 780 | write_lock_bh(&iucv_sk_list.lock); |
| 781 | |
| 782 | sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name)); |
| 783 | while (__iucv_get_sock_by_name(name)) { |
| 784 | sprintf(name, "%08x", |
| 785 | atomic_inc_return(&iucv_sk_list.autobind_name)); |
| 786 | } |
| 787 | |
| 788 | write_unlock_bh(&iucv_sk_list.lock); |
| 789 | |
| 790 | memcpy(&iucv->src_name, name, 8); |
| 791 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 792 | if (!iucv->msglimit) |
| 793 | iucv->msglimit = IUCV_QUEUELEN_DEFAULT; |
| 794 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 795 | return err; |
| 796 | } |
| 797 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 798 | static int afiucv_path_connect(struct socket *sock, struct sockaddr *addr) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 799 | { |
| 800 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; |
| 801 | struct sock *sk = sock->sk; |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 802 | struct iucv_sock *iucv = iucv_sk(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 803 | unsigned char user_data[16]; |
| 804 | int err; |
| 805 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 806 | high_nmcpy(user_data, sa->siucv_name); |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 807 | low_nmcpy(user_data, iucv->src_name); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 808 | ASCEBC(user_data, sizeof(user_data)); |
| 809 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 810 | /* Create path. */ |
Hendrik Brueckner | 09488e2 | 2009-04-21 23:26:27 +0000 | [diff] [blame] | 811 | iucv->path = iucv_path_alloc(iucv->msglimit, |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 812 | IUCV_IPRMDATA, GFP_KERNEL); |
Ursula Braun | d444472 | 2008-02-07 18:07:19 -0800 | [diff] [blame] | 813 | if (!iucv->path) { |
| 814 | err = -ENOMEM; |
| 815 | goto done; |
| 816 | } |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 817 | err = pr_iucv->path_connect(iucv->path, &af_iucv_handler, |
| 818 | sa->siucv_user_id, NULL, user_data, |
| 819 | sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 820 | if (err) { |
| 821 | iucv_path_free(iucv->path); |
| 822 | iucv->path = NULL; |
Hendrik Brueckner | 55cdea9 | 2009-01-05 18:07:07 -0800 | [diff] [blame] | 823 | switch (err) { |
| 824 | case 0x0b: /* Target communicator is not logged on */ |
| 825 | err = -ENETUNREACH; |
| 826 | break; |
| 827 | case 0x0d: /* Max connections for this guest exceeded */ |
| 828 | case 0x0e: /* Max connections for target guest exceeded */ |
| 829 | err = -EAGAIN; |
| 830 | break; |
| 831 | case 0x0f: /* Missing IUCV authorization */ |
| 832 | err = -EACCES; |
| 833 | break; |
| 834 | default: |
| 835 | err = -ECONNREFUSED; |
| 836 | break; |
| 837 | } |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 838 | } |
| 839 | done: |
| 840 | return err; |
| 841 | } |
| 842 | |
| 843 | /* Connect an unconnected socket */ |
| 844 | static int iucv_sock_connect(struct socket *sock, struct sockaddr *addr, |
| 845 | int alen, int flags) |
| 846 | { |
| 847 | struct sockaddr_iucv *sa = (struct sockaddr_iucv *) addr; |
| 848 | struct sock *sk = sock->sk; |
| 849 | struct iucv_sock *iucv = iucv_sk(sk); |
| 850 | int err; |
| 851 | |
| 852 | if (addr->sa_family != AF_IUCV || alen < sizeof(struct sockaddr_iucv)) |
| 853 | return -EINVAL; |
| 854 | |
| 855 | if (sk->sk_state != IUCV_OPEN && sk->sk_state != IUCV_BOUND) |
| 856 | return -EBADFD; |
| 857 | |
| 858 | if (sk->sk_state == IUCV_OPEN && |
| 859 | iucv->transport == AF_IUCV_TRANS_HIPER) |
| 860 | return -EBADFD; /* explicit bind required */ |
| 861 | |
| 862 | if (sk->sk_type != SOCK_STREAM && sk->sk_type != SOCK_SEQPACKET) |
| 863 | return -EINVAL; |
| 864 | |
| 865 | if (sk->sk_state == IUCV_OPEN) { |
| 866 | err = iucv_sock_autobind(sk); |
| 867 | if (unlikely(err)) |
| 868 | return err; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 871 | lock_sock(sk); |
| 872 | |
| 873 | /* Set the destination information */ |
| 874 | memcpy(iucv->dst_user_id, sa->siucv_user_id, 8); |
| 875 | memcpy(iucv->dst_name, sa->siucv_name, 8); |
| 876 | |
| 877 | if (iucv->transport == AF_IUCV_TRANS_HIPER) |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 878 | err = iucv_send_ctrl(sock->sk, AF_IUCV_FLAG_SYN); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 879 | else |
| 880 | err = afiucv_path_connect(sock, addr); |
| 881 | if (err) |
| 882 | goto done; |
| 883 | |
| 884 | if (sk->sk_state != IUCV_CONNECTED) |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 885 | err = iucv_sock_wait(sk, iucv_sock_in_state(sk, IUCV_CONNECTED, |
| 886 | IUCV_DISCONN), |
| 887 | sock_sndtimeo(sk, flags & O_NONBLOCK)); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 888 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 889 | if (sk->sk_state == IUCV_DISCONN || sk->sk_state == IUCV_CLOSED) |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 890 | err = -ECONNREFUSED; |
Ursula Braun | 18becbc | 2009-01-05 18:07:46 -0800 | [diff] [blame] | 891 | |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 892 | if (err && iucv->transport == AF_IUCV_TRANS_IUCV) |
| 893 | iucv_sever_path(sk, 0); |
Ursula Braun | 18becbc | 2009-01-05 18:07:46 -0800 | [diff] [blame] | 894 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 895 | done: |
| 896 | release_sock(sk); |
| 897 | return err; |
| 898 | } |
| 899 | |
| 900 | /* Move a socket into listening state. */ |
| 901 | static int iucv_sock_listen(struct socket *sock, int backlog) |
| 902 | { |
| 903 | struct sock *sk = sock->sk; |
| 904 | int err; |
| 905 | |
| 906 | lock_sock(sk); |
| 907 | |
| 908 | err = -EINVAL; |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 909 | if (sk->sk_state != IUCV_BOUND) |
| 910 | goto done; |
| 911 | |
| 912 | if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 913 | goto done; |
| 914 | |
| 915 | sk->sk_max_ack_backlog = backlog; |
| 916 | sk->sk_ack_backlog = 0; |
| 917 | sk->sk_state = IUCV_LISTEN; |
| 918 | err = 0; |
| 919 | |
| 920 | done: |
| 921 | release_sock(sk); |
| 922 | return err; |
| 923 | } |
| 924 | |
| 925 | /* Accept a pending connection */ |
| 926 | static int iucv_sock_accept(struct socket *sock, struct socket *newsock, |
| 927 | int flags) |
| 928 | { |
| 929 | DECLARE_WAITQUEUE(wait, current); |
| 930 | struct sock *sk = sock->sk, *nsk; |
| 931 | long timeo; |
| 932 | int err = 0; |
| 933 | |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 934 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 935 | |
| 936 | if (sk->sk_state != IUCV_LISTEN) { |
| 937 | err = -EBADFD; |
| 938 | goto done; |
| 939 | } |
| 940 | |
| 941 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 942 | |
| 943 | /* Wait for an incoming connection */ |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 944 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 945 | while (!(nsk = iucv_accept_dequeue(sk, newsock))) { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 946 | set_current_state(TASK_INTERRUPTIBLE); |
| 947 | if (!timeo) { |
| 948 | err = -EAGAIN; |
| 949 | break; |
| 950 | } |
| 951 | |
| 952 | release_sock(sk); |
| 953 | timeo = schedule_timeout(timeo); |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 954 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 955 | |
| 956 | if (sk->sk_state != IUCV_LISTEN) { |
| 957 | err = -EBADFD; |
| 958 | break; |
| 959 | } |
| 960 | |
| 961 | if (signal_pending(current)) { |
| 962 | err = sock_intr_errno(timeo); |
| 963 | break; |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | set_current_state(TASK_RUNNING); |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 968 | remove_wait_queue(sk_sleep(sk), &wait); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 969 | |
| 970 | if (err) |
| 971 | goto done; |
| 972 | |
| 973 | newsock->state = SS_CONNECTED; |
| 974 | |
| 975 | done: |
| 976 | release_sock(sk); |
| 977 | return err; |
| 978 | } |
| 979 | |
| 980 | static int iucv_sock_getname(struct socket *sock, struct sockaddr *addr, |
| 981 | int *len, int peer) |
| 982 | { |
| 983 | struct sockaddr_iucv *siucv = (struct sockaddr_iucv *) addr; |
| 984 | struct sock *sk = sock->sk; |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 985 | struct iucv_sock *iucv = iucv_sk(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 986 | |
| 987 | addr->sa_family = AF_IUCV; |
| 988 | *len = sizeof(struct sockaddr_iucv); |
| 989 | |
| 990 | if (peer) { |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 991 | memcpy(siucv->siucv_user_id, iucv->dst_user_id, 8); |
| 992 | memcpy(siucv->siucv_name, iucv->dst_name, 8); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 993 | } else { |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 994 | memcpy(siucv->siucv_user_id, iucv->src_user_id, 8); |
| 995 | memcpy(siucv->siucv_name, iucv->src_name, 8); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 996 | } |
| 997 | memset(&siucv->siucv_port, 0, sizeof(siucv->siucv_port)); |
| 998 | memset(&siucv->siucv_addr, 0, sizeof(siucv->siucv_addr)); |
Ursula Braun | 493d397 | 2011-08-08 01:33:52 +0000 | [diff] [blame] | 999 | memset(&siucv->siucv_nodeid, 0, sizeof(siucv->siucv_nodeid)); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1004 | /** |
| 1005 | * iucv_send_iprm() - Send socket data in parameter list of an iucv message. |
| 1006 | * @path: IUCV path |
| 1007 | * @msg: Pointer to a struct iucv_message |
| 1008 | * @skb: The socket data to send, skb->len MUST BE <= 7 |
| 1009 | * |
| 1010 | * Send the socket data in the parameter list in the iucv message |
| 1011 | * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter |
| 1012 | * list and the socket data len at index 7 (last byte). |
| 1013 | * See also iucv_msg_length(). |
| 1014 | * |
| 1015 | * Returns the error code from the iucv_message_send() call. |
| 1016 | */ |
| 1017 | static int iucv_send_iprm(struct iucv_path *path, struct iucv_message *msg, |
| 1018 | struct sk_buff *skb) |
| 1019 | { |
| 1020 | u8 prmdata[8]; |
| 1021 | |
| 1022 | memcpy(prmdata, (void *) skb->data, skb->len); |
| 1023 | prmdata[7] = 0xff - (u8) skb->len; |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1024 | return pr_iucv->message_send(path, msg, IUCV_IPRMDATA, 0, |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1025 | (void *) prmdata, 8); |
| 1026 | } |
| 1027 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1028 | static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock, |
| 1029 | struct msghdr *msg, size_t len) |
| 1030 | { |
| 1031 | struct sock *sk = sock->sk; |
| 1032 | struct iucv_sock *iucv = iucv_sk(sk); |
| 1033 | struct sk_buff *skb; |
| 1034 | struct iucv_message txmsg; |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1035 | struct cmsghdr *cmsg; |
| 1036 | int cmsg_done; |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 1037 | long timeo; |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 1038 | char user_id[9]; |
| 1039 | char appl_id[9]; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1040 | int err; |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 1041 | int noblock = msg->msg_flags & MSG_DONTWAIT; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1042 | |
| 1043 | err = sock_error(sk); |
| 1044 | if (err) |
| 1045 | return err; |
| 1046 | |
| 1047 | if (msg->msg_flags & MSG_OOB) |
| 1048 | return -EOPNOTSUPP; |
| 1049 | |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1050 | /* SOCK_SEQPACKET: we do not support segmented records */ |
| 1051 | if (sk->sk_type == SOCK_SEQPACKET && !(msg->msg_flags & MSG_EOR)) |
| 1052 | return -EOPNOTSUPP; |
| 1053 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1054 | lock_sock(sk); |
| 1055 | |
| 1056 | if (sk->sk_shutdown & SEND_SHUTDOWN) { |
| 1057 | err = -EPIPE; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1061 | /* Return if the socket is not in connected state */ |
| 1062 | if (sk->sk_state != IUCV_CONNECTED) { |
| 1063 | err = -ENOTCONN; |
| 1064 | goto out; |
| 1065 | } |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1066 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1067 | /* initialize defaults */ |
| 1068 | cmsg_done = 0; /* check for duplicate headers */ |
| 1069 | txmsg.class = 0; |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1070 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1071 | /* iterate over control messages */ |
| 1072 | for (cmsg = CMSG_FIRSTHDR(msg); cmsg; |
| 1073 | cmsg = CMSG_NXTHDR(msg, cmsg)) { |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1074 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1075 | if (!CMSG_OK(msg, cmsg)) { |
| 1076 | err = -EINVAL; |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1077 | goto out; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1080 | if (cmsg->cmsg_level != SOL_IUCV) |
| 1081 | continue; |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1082 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1083 | if (cmsg->cmsg_type & cmsg_done) { |
| 1084 | err = -EINVAL; |
| 1085 | goto out; |
| 1086 | } |
| 1087 | cmsg_done |= cmsg->cmsg_type; |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1088 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1089 | switch (cmsg->cmsg_type) { |
| 1090 | case SCM_IUCV_TRGCLS: |
| 1091 | if (cmsg->cmsg_len != CMSG_LEN(TRGCLS_SIZE)) { |
| 1092 | err = -EINVAL; |
| 1093 | goto out; |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1096 | /* set iucv message target class */ |
| 1097 | memcpy(&txmsg.class, |
| 1098 | (void *) CMSG_DATA(cmsg), TRGCLS_SIZE); |
| 1099 | |
| 1100 | break; |
| 1101 | |
| 1102 | default: |
| 1103 | err = -EINVAL; |
| 1104 | goto out; |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | /* allocate one skb for each iucv message: |
| 1110 | * this is fine for SOCK_SEQPACKET (unless we want to support |
| 1111 | * segmented records using the MSG_EOR flag), but |
| 1112 | * for SOCK_STREAM we might want to improve it in future */ |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1113 | if (iucv->transport == AF_IUCV_TRANS_HIPER) |
| 1114 | skb = sock_alloc_send_skb(sk, |
| 1115 | len + sizeof(struct af_iucv_trans_hdr) + ETH_HLEN, |
| 1116 | noblock, &err); |
| 1117 | else |
| 1118 | skb = sock_alloc_send_skb(sk, len, noblock, &err); |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 1119 | if (!skb) { |
| 1120 | err = -ENOMEM; |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1121 | goto out; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 1122 | } |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1123 | if (iucv->transport == AF_IUCV_TRANS_HIPER) |
| 1124 | skb_reserve(skb, sizeof(struct af_iucv_trans_hdr) + ETH_HLEN); |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1125 | if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) { |
| 1126 | err = -EFAULT; |
| 1127 | goto fail; |
| 1128 | } |
| 1129 | |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 1130 | /* wait if outstanding messages for iucv path has reached */ |
| 1131 | timeo = sock_sndtimeo(sk, noblock); |
| 1132 | err = iucv_sock_wait(sk, iucv_below_msglim(sk), timeo); |
| 1133 | if (err) |
| 1134 | goto fail; |
| 1135 | |
| 1136 | /* return -ECONNRESET if the socket is no longer connected */ |
| 1137 | if (sk->sk_state != IUCV_CONNECTED) { |
| 1138 | err = -ECONNRESET; |
| 1139 | goto fail; |
| 1140 | } |
| 1141 | |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1142 | /* increment and save iucv message tag for msg_completion cbk */ |
| 1143 | txmsg.tag = iucv->send_tag++; |
| 1144 | memcpy(CB_TAG(skb), &txmsg.tag, CB_TAG_LEN); |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 1145 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1146 | if (iucv->transport == AF_IUCV_TRANS_HIPER) { |
| 1147 | atomic_inc(&iucv->msg_sent); |
| 1148 | err = afiucv_hs_send(&txmsg, sk, skb, 0); |
| 1149 | if (err) { |
| 1150 | atomic_dec(&iucv->msg_sent); |
| 1151 | goto fail; |
| 1152 | } |
| 1153 | goto release; |
| 1154 | } |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1155 | skb_queue_tail(&iucv->send_skb_q, skb); |
| 1156 | |
| 1157 | if (((iucv->path->flags & IUCV_IPRMDATA) & iucv->flags) |
| 1158 | && skb->len <= 7) { |
| 1159 | err = iucv_send_iprm(iucv->path, &txmsg, skb); |
| 1160 | |
| 1161 | /* on success: there is no message_complete callback |
| 1162 | * for an IPRMDATA msg; remove skb from send queue */ |
| 1163 | if (err == 0) { |
| 1164 | skb_unlink(skb, &iucv->send_skb_q); |
| 1165 | kfree_skb(skb); |
| 1166 | } |
| 1167 | |
| 1168 | /* this error should never happen since the |
| 1169 | * IUCV_IPRMDATA path flag is set... sever path */ |
| 1170 | if (err == 0x15) { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1171 | pr_iucv->path_sever(iucv->path, NULL); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1172 | skb_unlink(skb, &iucv->send_skb_q); |
| 1173 | err = -EPIPE; |
| 1174 | goto fail; |
| 1175 | } |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1176 | } else |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1177 | err = pr_iucv->message_send(iucv->path, &txmsg, 0, 0, |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1178 | (void *) skb->data, skb->len); |
| 1179 | if (err) { |
| 1180 | if (err == 3) { |
| 1181 | user_id[8] = 0; |
| 1182 | memcpy(user_id, iucv->dst_user_id, 8); |
| 1183 | appl_id[8] = 0; |
| 1184 | memcpy(appl_id, iucv->dst_name, 8); |
| 1185 | pr_err("Application %s on z/VM guest %s" |
| 1186 | " exceeds message limit\n", |
| 1187 | appl_id, user_id); |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 1188 | err = -EAGAIN; |
| 1189 | } else |
| 1190 | err = -EPIPE; |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1191 | skb_unlink(skb, &iucv->send_skb_q); |
Hendrik Brueckner | bb664f4 | 2009-06-17 21:54:47 +0000 | [diff] [blame] | 1192 | goto fail; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1195 | release: |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1196 | release_sock(sk); |
| 1197 | return len; |
| 1198 | |
| 1199 | fail: |
| 1200 | kfree_skb(skb); |
| 1201 | out: |
| 1202 | release_sock(sk); |
| 1203 | return err; |
| 1204 | } |
| 1205 | |
Hendrik Brueckner | bf95d20 | 2009-09-16 04:37:28 +0000 | [diff] [blame] | 1206 | /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's |
| 1207 | * |
| 1208 | * Locking: must be called with message_q.lock held |
| 1209 | */ |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1210 | static int iucv_fragment_skb(struct sock *sk, struct sk_buff *skb, int len) |
| 1211 | { |
| 1212 | int dataleft, size, copied = 0; |
| 1213 | struct sk_buff *nskb; |
| 1214 | |
| 1215 | dataleft = len; |
| 1216 | while (dataleft) { |
| 1217 | if (dataleft >= sk->sk_rcvbuf / 4) |
| 1218 | size = sk->sk_rcvbuf / 4; |
| 1219 | else |
| 1220 | size = dataleft; |
| 1221 | |
| 1222 | nskb = alloc_skb(size, GFP_ATOMIC | GFP_DMA); |
| 1223 | if (!nskb) |
| 1224 | return -ENOMEM; |
| 1225 | |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1226 | /* copy target class to control buffer of new skb */ |
| 1227 | memcpy(CB_TRGCLS(nskb), CB_TRGCLS(skb), CB_TRGCLS_LEN); |
| 1228 | |
| 1229 | /* copy data fragment */ |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1230 | memcpy(nskb->data, skb->data + copied, size); |
| 1231 | copied += size; |
| 1232 | dataleft -= size; |
| 1233 | |
| 1234 | skb_reset_transport_header(nskb); |
| 1235 | skb_reset_network_header(nskb); |
| 1236 | nskb->len = size; |
| 1237 | |
| 1238 | skb_queue_tail(&iucv_sk(sk)->backlog_skb_q, nskb); |
| 1239 | } |
| 1240 | |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
Hendrik Brueckner | bf95d20 | 2009-09-16 04:37:28 +0000 | [diff] [blame] | 1244 | /* iucv_process_message() - Receive a single outstanding IUCV message |
| 1245 | * |
| 1246 | * Locking: must be called with message_q.lock held |
| 1247 | */ |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1248 | static void iucv_process_message(struct sock *sk, struct sk_buff *skb, |
| 1249 | struct iucv_path *path, |
| 1250 | struct iucv_message *msg) |
| 1251 | { |
| 1252 | int rc; |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1253 | unsigned int len; |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1254 | |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1255 | len = iucv_msg_length(msg); |
| 1256 | |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1257 | /* store msg target class in the second 4 bytes of skb ctrl buffer */ |
| 1258 | /* Note: the first 4 bytes are reserved for msg tag */ |
| 1259 | memcpy(CB_TRGCLS(skb), &msg->class, CB_TRGCLS_LEN); |
| 1260 | |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1261 | /* check for special IPRM messages (e.g. iucv_sock_shutdown) */ |
| 1262 | if ((msg->flags & IUCV_IPRMDATA) && len > 7) { |
| 1263 | if (memcmp(msg->rmmsg, iprm_shutdown, 8) == 0) { |
| 1264 | skb->data = NULL; |
| 1265 | skb->len = 0; |
| 1266 | } |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1267 | } else { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1268 | rc = pr_iucv->message_receive(path, msg, |
| 1269 | msg->flags & IUCV_IPRMDATA, |
| 1270 | skb->data, len, NULL); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1271 | if (rc) { |
| 1272 | kfree_skb(skb); |
| 1273 | return; |
| 1274 | } |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1275 | /* we need to fragment iucv messages for SOCK_STREAM only; |
| 1276 | * for SOCK_SEQPACKET, it is only relevant if we support |
| 1277 | * record segmentation using MSG_EOR (see also recvmsg()) */ |
| 1278 | if (sk->sk_type == SOCK_STREAM && |
| 1279 | skb->truesize >= sk->sk_rcvbuf / 4) { |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1280 | rc = iucv_fragment_skb(sk, skb, len); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1281 | kfree_skb(skb); |
| 1282 | skb = NULL; |
| 1283 | if (rc) { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1284 | pr_iucv->path_sever(path, NULL); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1285 | return; |
| 1286 | } |
| 1287 | skb = skb_dequeue(&iucv_sk(sk)->backlog_skb_q); |
| 1288 | } else { |
| 1289 | skb_reset_transport_header(skb); |
| 1290 | skb_reset_network_header(skb); |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1291 | skb->len = len; |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | if (sock_queue_rcv_skb(sk, skb)) |
| 1296 | skb_queue_head(&iucv_sk(sk)->backlog_skb_q, skb); |
| 1297 | } |
| 1298 | |
Hendrik Brueckner | bf95d20 | 2009-09-16 04:37:28 +0000 | [diff] [blame] | 1299 | /* iucv_process_message_q() - Process outstanding IUCV messages |
| 1300 | * |
| 1301 | * Locking: must be called with message_q.lock held |
| 1302 | */ |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1303 | static void iucv_process_message_q(struct sock *sk) |
| 1304 | { |
| 1305 | struct iucv_sock *iucv = iucv_sk(sk); |
| 1306 | struct sk_buff *skb; |
| 1307 | struct sock_msg_q *p, *n; |
| 1308 | |
| 1309 | list_for_each_entry_safe(p, n, &iucv->message_q.list, list) { |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1310 | skb = alloc_skb(iucv_msg_length(&p->msg), GFP_ATOMIC | GFP_DMA); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1311 | if (!skb) |
| 1312 | break; |
| 1313 | iucv_process_message(sk, skb, p->path, &p->msg); |
| 1314 | list_del(&p->list); |
| 1315 | kfree(p); |
| 1316 | if (!skb_queue_empty(&iucv->backlog_skb_q)) |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1321 | static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock, |
| 1322 | struct msghdr *msg, size_t len, int flags) |
| 1323 | { |
| 1324 | int noblock = flags & MSG_DONTWAIT; |
| 1325 | struct sock *sk = sock->sk; |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1326 | struct iucv_sock *iucv = iucv_sk(sk); |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1327 | unsigned int copied, rlen; |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 1328 | struct sk_buff *skb, *rskb, *cskb; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1329 | int err = 0; |
| 1330 | |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 1331 | if ((sk->sk_state == IUCV_DISCONN) && |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1332 | skb_queue_empty(&iucv->backlog_skb_q) && |
| 1333 | skb_queue_empty(&sk->sk_receive_queue) && |
| 1334 | list_empty(&iucv->message_q.list)) |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1335 | return 0; |
| 1336 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1337 | if (flags & (MSG_OOB)) |
| 1338 | return -EOPNOTSUPP; |
| 1339 | |
Hendrik Brueckner | 60d3705 | 2009-04-21 06:04:21 +0000 | [diff] [blame] | 1340 | /* receive/dequeue next skb: |
| 1341 | * the function understands MSG_PEEK and, thus, does not dequeue skb */ |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1342 | skb = skb_recv_datagram(sk, flags, noblock, &err); |
| 1343 | if (!skb) { |
| 1344 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 1345 | return 0; |
| 1346 | return err; |
| 1347 | } |
| 1348 | |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1349 | rlen = skb->len; /* real length of skb */ |
| 1350 | copied = min_t(unsigned int, rlen, len); |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 1351 | if (!rlen) |
| 1352 | sk->sk_shutdown = sk->sk_shutdown | RCV_SHUTDOWN; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1353 | |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1354 | cskb = skb; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1355 | if (skb_copy_datagram_iovec(cskb, 0, msg->msg_iov, copied)) { |
Hendrik Brueckner | 802788b | 2009-04-21 23:26:26 +0000 | [diff] [blame] | 1356 | if (!(flags & MSG_PEEK)) |
| 1357 | skb_queue_head(&sk->sk_receive_queue, skb); |
| 1358 | return -EFAULT; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1361 | /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */ |
| 1362 | if (sk->sk_type == SOCK_SEQPACKET) { |
| 1363 | if (copied < rlen) |
| 1364 | msg->msg_flags |= MSG_TRUNC; |
| 1365 | /* each iucv message contains a complete record */ |
| 1366 | msg->msg_flags |= MSG_EOR; |
| 1367 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1368 | |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1369 | /* create control message to store iucv msg target class: |
| 1370 | * get the trgcls from the control buffer of the skb due to |
| 1371 | * fragmentation of original iucv message. */ |
| 1372 | err = put_cmsg(msg, SOL_IUCV, SCM_IUCV_TRGCLS, |
| 1373 | CB_TRGCLS_LEN, CB_TRGCLS(skb)); |
| 1374 | if (err) { |
| 1375 | if (!(flags & MSG_PEEK)) |
| 1376 | skb_queue_head(&sk->sk_receive_queue, skb); |
| 1377 | return err; |
| 1378 | } |
| 1379 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1380 | /* Mark read part of skb as used */ |
| 1381 | if (!(flags & MSG_PEEK)) { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1382 | |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1383 | /* SOCK_STREAM: re-queue skb if it contains unreceived data */ |
| 1384 | if (sk->sk_type == SOCK_STREAM) { |
| 1385 | skb_pull(skb, copied); |
| 1386 | if (skb->len) { |
| 1387 | skb_queue_head(&sk->sk_receive_queue, skb); |
| 1388 | goto done; |
| 1389 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | kfree_skb(skb); |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 1393 | if (iucv->transport == AF_IUCV_TRANS_HIPER) { |
| 1394 | atomic_inc(&iucv->msg_recv); |
| 1395 | if (atomic_read(&iucv->msg_recv) > iucv->msglimit) { |
| 1396 | WARN_ON(1); |
| 1397 | iucv_sock_close(sk); |
| 1398 | return -EFAULT; |
| 1399 | } |
| 1400 | } |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1401 | |
| 1402 | /* Queue backlog skbs */ |
Hendrik Brueckner | bf95d20 | 2009-09-16 04:37:28 +0000 | [diff] [blame] | 1403 | spin_lock_bh(&iucv->message_q.lock); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1404 | rskb = skb_dequeue(&iucv->backlog_skb_q); |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1405 | while (rskb) { |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1406 | if (sock_queue_rcv_skb(sk, rskb)) { |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1407 | skb_queue_head(&iucv->backlog_skb_q, |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1408 | rskb); |
| 1409 | break; |
| 1410 | } else { |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1411 | rskb = skb_dequeue(&iucv->backlog_skb_q); |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1412 | } |
| 1413 | } |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1414 | if (skb_queue_empty(&iucv->backlog_skb_q)) { |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1415 | if (!list_empty(&iucv->message_q.list)) |
| 1416 | iucv_process_message_q(sk); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1417 | if (atomic_read(&iucv->msg_recv) >= |
| 1418 | iucv->msglimit / 2) { |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 1419 | err = iucv_send_ctrl(sk, AF_IUCV_FLAG_WIN); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1420 | if (err) { |
| 1421 | sk->sk_state = IUCV_DISCONN; |
| 1422 | sk->sk_state_change(sk); |
| 1423 | } |
| 1424 | } |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1425 | } |
Hendrik Brueckner | bf95d20 | 2009-09-16 04:37:28 +0000 | [diff] [blame] | 1426 | spin_unlock_bh(&iucv->message_q.lock); |
Hendrik Brueckner | 60d3705 | 2009-04-21 06:04:21 +0000 | [diff] [blame] | 1427 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1428 | |
| 1429 | done: |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1430 | /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */ |
| 1431 | if (sk->sk_type == SOCK_SEQPACKET && (flags & MSG_TRUNC)) |
| 1432 | copied = rlen; |
| 1433 | |
| 1434 | return copied; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static inline unsigned int iucv_accept_poll(struct sock *parent) |
| 1438 | { |
| 1439 | struct iucv_sock *isk, *n; |
| 1440 | struct sock *sk; |
| 1441 | |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1442 | list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1443 | sk = (struct sock *) isk; |
| 1444 | |
| 1445 | if (sk->sk_state == IUCV_CONNECTED) |
| 1446 | return POLLIN | POLLRDNORM; |
| 1447 | } |
| 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | unsigned int iucv_sock_poll(struct file *file, struct socket *sock, |
| 1453 | poll_table *wait) |
| 1454 | { |
| 1455 | struct sock *sk = sock->sk; |
| 1456 | unsigned int mask = 0; |
| 1457 | |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 1458 | sock_poll_wait(file, sk_sleep(sk), wait); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1459 | |
| 1460 | if (sk->sk_state == IUCV_LISTEN) |
| 1461 | return iucv_accept_poll(sk); |
| 1462 | |
| 1463 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) |
Keller, Jacob E | 7d4c04f | 2013-03-28 11:19:25 +0000 | [diff] [blame^] | 1464 | mask |= POLLERR | |
| 1465 | sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? POLLPRI : 0; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1466 | |
| 1467 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 1468 | mask |= POLLRDHUP; |
| 1469 | |
| 1470 | if (sk->sk_shutdown == SHUTDOWN_MASK) |
| 1471 | mask |= POLLHUP; |
| 1472 | |
| 1473 | if (!skb_queue_empty(&sk->sk_receive_queue) || |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1474 | (sk->sk_shutdown & RCV_SHUTDOWN)) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1475 | mask |= POLLIN | POLLRDNORM; |
| 1476 | |
| 1477 | if (sk->sk_state == IUCV_CLOSED) |
| 1478 | mask |= POLLHUP; |
| 1479 | |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 1480 | if (sk->sk_state == IUCV_DISCONN) |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1481 | mask |= POLLIN; |
| 1482 | |
Ursula Braun | 7f1b0ea | 2012-02-08 00:19:46 +0000 | [diff] [blame] | 1483 | if (sock_writeable(sk) && iucv_below_msglim(sk)) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1484 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; |
| 1485 | else |
| 1486 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); |
| 1487 | |
| 1488 | return mask; |
| 1489 | } |
| 1490 | |
| 1491 | static int iucv_sock_shutdown(struct socket *sock, int how) |
| 1492 | { |
| 1493 | struct sock *sk = sock->sk; |
| 1494 | struct iucv_sock *iucv = iucv_sk(sk); |
| 1495 | struct iucv_message txmsg; |
| 1496 | int err = 0; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1497 | |
| 1498 | how++; |
| 1499 | |
| 1500 | if ((how & ~SHUTDOWN_MASK) || !how) |
| 1501 | return -EINVAL; |
| 1502 | |
| 1503 | lock_sock(sk); |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1504 | switch (sk->sk_state) { |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 1505 | case IUCV_LISTEN: |
Hendrik Brueckner | e14ad5f | 2009-04-21 06:04:23 +0000 | [diff] [blame] | 1506 | case IUCV_DISCONN: |
| 1507 | case IUCV_CLOSING: |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1508 | case IUCV_CLOSED: |
| 1509 | err = -ENOTCONN; |
| 1510 | goto fail; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1511 | default: |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1512 | break; |
| 1513 | } |
| 1514 | |
| 1515 | if (how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) { |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 1516 | if (iucv->transport == AF_IUCV_TRANS_IUCV) { |
| 1517 | txmsg.class = 0; |
| 1518 | txmsg.tag = 0; |
| 1519 | err = pr_iucv->message_send(iucv->path, &txmsg, |
| 1520 | IUCV_IPRMDATA, 0, (void *) iprm_shutdown, 8); |
| 1521 | if (err) { |
| 1522 | switch (err) { |
| 1523 | case 1: |
| 1524 | err = -ENOTCONN; |
| 1525 | break; |
| 1526 | case 2: |
| 1527 | err = -ECONNRESET; |
| 1528 | break; |
| 1529 | default: |
| 1530 | err = -ENOTCONN; |
| 1531 | break; |
| 1532 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1533 | } |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 1534 | } else |
| 1535 | iucv_send_ctrl(sk, AF_IUCV_FLAG_SHT); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1536 | } |
| 1537 | |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 1538 | sk->sk_shutdown |= how; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1539 | if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK) { |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 1540 | if (iucv->transport == AF_IUCV_TRANS_IUCV) { |
| 1541 | err = pr_iucv->path_quiesce(iucv->path, NULL); |
| 1542 | if (err) |
| 1543 | err = -ENOTCONN; |
| 1544 | /* skb_queue_purge(&sk->sk_receive_queue); */ |
| 1545 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1546 | skb_queue_purge(&sk->sk_receive_queue); |
| 1547 | } |
| 1548 | |
| 1549 | /* Wake up anyone sleeping in poll */ |
| 1550 | sk->sk_state_change(sk); |
| 1551 | |
| 1552 | fail: |
| 1553 | release_sock(sk); |
| 1554 | return err; |
| 1555 | } |
| 1556 | |
| 1557 | static int iucv_sock_release(struct socket *sock) |
| 1558 | { |
| 1559 | struct sock *sk = sock->sk; |
| 1560 | int err = 0; |
| 1561 | |
| 1562 | if (!sk) |
| 1563 | return 0; |
| 1564 | |
| 1565 | iucv_sock_close(sk); |
| 1566 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1567 | sock_orphan(sk); |
| 1568 | iucv_sock_kill(sk); |
| 1569 | return err; |
| 1570 | } |
| 1571 | |
Hendrik Brueckner | 9d5c5d8 | 2009-04-21 23:26:22 +0000 | [diff] [blame] | 1572 | /* getsockopt and setsockopt */ |
| 1573 | static int iucv_sock_setsockopt(struct socket *sock, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 1574 | char __user *optval, unsigned int optlen) |
Hendrik Brueckner | 9d5c5d8 | 2009-04-21 23:26:22 +0000 | [diff] [blame] | 1575 | { |
| 1576 | struct sock *sk = sock->sk; |
| 1577 | struct iucv_sock *iucv = iucv_sk(sk); |
| 1578 | int val; |
| 1579 | int rc; |
| 1580 | |
| 1581 | if (level != SOL_IUCV) |
| 1582 | return -ENOPROTOOPT; |
| 1583 | |
| 1584 | if (optlen < sizeof(int)) |
| 1585 | return -EINVAL; |
| 1586 | |
| 1587 | if (get_user(val, (int __user *) optval)) |
| 1588 | return -EFAULT; |
| 1589 | |
| 1590 | rc = 0; |
| 1591 | |
| 1592 | lock_sock(sk); |
| 1593 | switch (optname) { |
| 1594 | case SO_IPRMDATA_MSG: |
| 1595 | if (val) |
| 1596 | iucv->flags |= IUCV_IPRMDATA; |
| 1597 | else |
| 1598 | iucv->flags &= ~IUCV_IPRMDATA; |
| 1599 | break; |
Hendrik Brueckner | 09488e2 | 2009-04-21 23:26:27 +0000 | [diff] [blame] | 1600 | case SO_MSGLIMIT: |
| 1601 | switch (sk->sk_state) { |
| 1602 | case IUCV_OPEN: |
| 1603 | case IUCV_BOUND: |
| 1604 | if (val < 1 || val > (u16)(~0)) |
| 1605 | rc = -EINVAL; |
| 1606 | else |
| 1607 | iucv->msglimit = val; |
| 1608 | break; |
| 1609 | default: |
| 1610 | rc = -EINVAL; |
| 1611 | break; |
| 1612 | } |
| 1613 | break; |
Hendrik Brueckner | 9d5c5d8 | 2009-04-21 23:26:22 +0000 | [diff] [blame] | 1614 | default: |
| 1615 | rc = -ENOPROTOOPT; |
| 1616 | break; |
| 1617 | } |
| 1618 | release_sock(sk); |
| 1619 | |
| 1620 | return rc; |
| 1621 | } |
| 1622 | |
| 1623 | static int iucv_sock_getsockopt(struct socket *sock, int level, int optname, |
| 1624 | char __user *optval, int __user *optlen) |
| 1625 | { |
| 1626 | struct sock *sk = sock->sk; |
| 1627 | struct iucv_sock *iucv = iucv_sk(sk); |
Ursula Braun | 51363b8 | 2012-02-08 00:19:48 +0000 | [diff] [blame] | 1628 | unsigned int val; |
| 1629 | int len; |
Hendrik Brueckner | 9d5c5d8 | 2009-04-21 23:26:22 +0000 | [diff] [blame] | 1630 | |
| 1631 | if (level != SOL_IUCV) |
| 1632 | return -ENOPROTOOPT; |
| 1633 | |
| 1634 | if (get_user(len, optlen)) |
| 1635 | return -EFAULT; |
| 1636 | |
| 1637 | if (len < 0) |
| 1638 | return -EINVAL; |
| 1639 | |
| 1640 | len = min_t(unsigned int, len, sizeof(int)); |
| 1641 | |
| 1642 | switch (optname) { |
| 1643 | case SO_IPRMDATA_MSG: |
| 1644 | val = (iucv->flags & IUCV_IPRMDATA) ? 1 : 0; |
| 1645 | break; |
Hendrik Brueckner | 09488e2 | 2009-04-21 23:26:27 +0000 | [diff] [blame] | 1646 | case SO_MSGLIMIT: |
| 1647 | lock_sock(sk); |
| 1648 | val = (iucv->path != NULL) ? iucv->path->msglim /* connected */ |
| 1649 | : iucv->msglimit; /* default */ |
| 1650 | release_sock(sk); |
| 1651 | break; |
Ursula Braun | 51363b8 | 2012-02-08 00:19:48 +0000 | [diff] [blame] | 1652 | case SO_MSGSIZE: |
| 1653 | if (sk->sk_state == IUCV_OPEN) |
| 1654 | return -EBADFD; |
| 1655 | val = (iucv->hs_dev) ? iucv->hs_dev->mtu - |
| 1656 | sizeof(struct af_iucv_trans_hdr) - ETH_HLEN : |
| 1657 | 0x7fffffff; |
| 1658 | break; |
Hendrik Brueckner | 9d5c5d8 | 2009-04-21 23:26:22 +0000 | [diff] [blame] | 1659 | default: |
| 1660 | return -ENOPROTOOPT; |
| 1661 | } |
| 1662 | |
| 1663 | if (put_user(len, optlen)) |
| 1664 | return -EFAULT; |
| 1665 | if (copy_to_user(optval, &val, len)) |
| 1666 | return -EFAULT; |
| 1667 | |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1672 | /* Callback wrappers - called from iucv base support */ |
| 1673 | static int iucv_callback_connreq(struct iucv_path *path, |
| 1674 | u8 ipvmid[8], u8 ipuser[16]) |
| 1675 | { |
| 1676 | unsigned char user_data[16]; |
| 1677 | unsigned char nuser_data[16]; |
| 1678 | unsigned char src_name[8]; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1679 | struct sock *sk, *nsk; |
| 1680 | struct iucv_sock *iucv, *niucv; |
| 1681 | int err; |
| 1682 | |
| 1683 | memcpy(src_name, ipuser, 8); |
| 1684 | EBCASC(src_name, 8); |
| 1685 | /* Find out if this path belongs to af_iucv. */ |
| 1686 | read_lock(&iucv_sk_list.lock); |
| 1687 | iucv = NULL; |
Ursula Braun | febca28 | 2007-07-14 19:04:25 -0700 | [diff] [blame] | 1688 | sk = NULL; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1689 | sk_for_each(sk, &iucv_sk_list.head) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1690 | if (sk->sk_state == IUCV_LISTEN && |
| 1691 | !memcmp(&iucv_sk(sk)->src_name, src_name, 8)) { |
| 1692 | /* |
| 1693 | * Found a listening socket with |
| 1694 | * src_name == ipuser[0-7]. |
| 1695 | */ |
| 1696 | iucv = iucv_sk(sk); |
| 1697 | break; |
| 1698 | } |
| 1699 | read_unlock(&iucv_sk_list.lock); |
| 1700 | if (!iucv) |
| 1701 | /* No socket found, not one of our paths. */ |
| 1702 | return -EINVAL; |
| 1703 | |
| 1704 | bh_lock_sock(sk); |
| 1705 | |
| 1706 | /* Check if parent socket is listening */ |
| 1707 | low_nmcpy(user_data, iucv->src_name); |
| 1708 | high_nmcpy(user_data, iucv->dst_name); |
| 1709 | ASCEBC(user_data, sizeof(user_data)); |
| 1710 | if (sk->sk_state != IUCV_LISTEN) { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1711 | err = pr_iucv->path_sever(path, user_data); |
Hendrik Brueckner | 65dbd7c | 2009-01-05 18:08:23 -0800 | [diff] [blame] | 1712 | iucv_path_free(path); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1713 | goto fail; |
| 1714 | } |
| 1715 | |
| 1716 | /* Check for backlog size */ |
| 1717 | if (sk_acceptq_is_full(sk)) { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1718 | err = pr_iucv->path_sever(path, user_data); |
Hendrik Brueckner | 65dbd7c | 2009-01-05 18:08:23 -0800 | [diff] [blame] | 1719 | iucv_path_free(path); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1720 | goto fail; |
| 1721 | } |
| 1722 | |
| 1723 | /* Create the new socket */ |
Hendrik Brueckner | aa8e71f | 2009-04-21 23:26:25 +0000 | [diff] [blame] | 1724 | nsk = iucv_sock_alloc(NULL, sk->sk_type, GFP_ATOMIC); |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1725 | if (!nsk) { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1726 | err = pr_iucv->path_sever(path, user_data); |
Hendrik Brueckner | 65dbd7c | 2009-01-05 18:08:23 -0800 | [diff] [blame] | 1727 | iucv_path_free(path); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1728 | goto fail; |
| 1729 | } |
| 1730 | |
| 1731 | niucv = iucv_sk(nsk); |
| 1732 | iucv_sock_init(nsk, sk); |
| 1733 | |
| 1734 | /* Set the new iucv_sock */ |
| 1735 | memcpy(niucv->dst_name, ipuser + 8, 8); |
| 1736 | EBCASC(niucv->dst_name, 8); |
| 1737 | memcpy(niucv->dst_user_id, ipvmid, 8); |
| 1738 | memcpy(niucv->src_name, iucv->src_name, 8); |
| 1739 | memcpy(niucv->src_user_id, iucv->src_user_id, 8); |
| 1740 | niucv->path = path; |
| 1741 | |
| 1742 | /* Call iucv_accept */ |
| 1743 | high_nmcpy(nuser_data, ipuser + 8); |
| 1744 | memcpy(nuser_data + 8, niucv->src_name, 8); |
| 1745 | ASCEBC(nuser_data + 8, 8); |
| 1746 | |
Hendrik Brueckner | 09488e2 | 2009-04-21 23:26:27 +0000 | [diff] [blame] | 1747 | /* set message limit for path based on msglimit of accepting socket */ |
| 1748 | niucv->msglimit = iucv->msglimit; |
| 1749 | path->msglim = iucv->msglimit; |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1750 | err = pr_iucv->path_accept(path, &af_iucv_handler, nuser_data, nsk); |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1751 | if (err) { |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 1752 | iucv_sever_path(nsk, 1); |
Hendrik Brueckner | 65dbd7c | 2009-01-05 18:08:23 -0800 | [diff] [blame] | 1753 | iucv_sock_kill(nsk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1754 | goto fail; |
| 1755 | } |
| 1756 | |
| 1757 | iucv_accept_enqueue(sk, nsk); |
| 1758 | |
| 1759 | /* Wake up accept */ |
| 1760 | nsk->sk_state = IUCV_CONNECTED; |
| 1761 | sk->sk_data_ready(sk, 1); |
| 1762 | err = 0; |
| 1763 | fail: |
| 1764 | bh_unlock_sock(sk); |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | static void iucv_callback_connack(struct iucv_path *path, u8 ipuser[16]) |
| 1769 | { |
| 1770 | struct sock *sk = path->private; |
| 1771 | |
| 1772 | sk->sk_state = IUCV_CONNECTED; |
| 1773 | sk->sk_state_change(sk); |
| 1774 | } |
| 1775 | |
| 1776 | static void iucv_callback_rx(struct iucv_path *path, struct iucv_message *msg) |
| 1777 | { |
| 1778 | struct sock *sk = path->private; |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1779 | struct iucv_sock *iucv = iucv_sk(sk); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1780 | struct sk_buff *skb; |
| 1781 | struct sock_msg_q *save_msg; |
| 1782 | int len; |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1783 | |
Hendrik Brueckner | fe86e54 | 2009-04-21 06:04:22 +0000 | [diff] [blame] | 1784 | if (sk->sk_shutdown & RCV_SHUTDOWN) { |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 1785 | pr_iucv->message_reject(path, msg); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1786 | return; |
Hendrik Brueckner | fe86e54 | 2009-04-21 06:04:22 +0000 | [diff] [blame] | 1787 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1788 | |
Hendrik Brueckner | 3fa6b5a | 2009-04-21 06:04:24 +0000 | [diff] [blame] | 1789 | spin_lock(&iucv->message_q.lock); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1790 | |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1791 | if (!list_empty(&iucv->message_q.list) || |
| 1792 | !skb_queue_empty(&iucv->backlog_skb_q)) |
| 1793 | goto save_message; |
| 1794 | |
| 1795 | len = atomic_read(&sk->sk_rmem_alloc); |
Eric Dumazet | 87fb4b7 | 2011-10-13 07:28:54 +0000 | [diff] [blame] | 1796 | len += SKB_TRUESIZE(iucv_msg_length(msg)); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1797 | if (len > sk->sk_rcvbuf) |
| 1798 | goto save_message; |
| 1799 | |
Hendrik Brueckner | b8942e3 | 2009-04-21 23:26:23 +0000 | [diff] [blame] | 1800 | skb = alloc_skb(iucv_msg_length(msg), GFP_ATOMIC | GFP_DMA); |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1801 | if (!skb) |
| 1802 | goto save_message; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1803 | |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1804 | iucv_process_message(sk, skb, path, msg); |
Hendrik Brueckner | 3fa6b5a | 2009-04-21 06:04:24 +0000 | [diff] [blame] | 1805 | goto out_unlock; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1806 | |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1807 | save_message: |
| 1808 | save_msg = kzalloc(sizeof(struct sock_msg_q), GFP_ATOMIC | GFP_DMA); |
Ursula Braun | d444472 | 2008-02-07 18:07:19 -0800 | [diff] [blame] | 1809 | if (!save_msg) |
Julia Lawall | a56635a | 2010-05-26 05:56:48 +0000 | [diff] [blame] | 1810 | goto out_unlock; |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1811 | save_msg->path = path; |
| 1812 | save_msg->msg = *msg; |
| 1813 | |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1814 | list_add_tail(&save_msg->list, &iucv->message_q.list); |
Hendrik Brueckner | 3fa6b5a | 2009-04-21 06:04:24 +0000 | [diff] [blame] | 1815 | |
| 1816 | out_unlock: |
Ursula Braun | f0703c8 | 2007-10-08 02:03:31 -0700 | [diff] [blame] | 1817 | spin_unlock(&iucv->message_q.lock); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | static void iucv_callback_txdone(struct iucv_path *path, |
| 1821 | struct iucv_message *msg) |
| 1822 | { |
| 1823 | struct sock *sk = path->private; |
Ursula Braun | f2a7799 | 2008-02-07 18:07:44 -0800 | [diff] [blame] | 1824 | struct sk_buff *this = NULL; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1825 | struct sk_buff_head *list = &iucv_sk(sk)->send_skb_q; |
| 1826 | struct sk_buff *list_skb = list->next; |
| 1827 | unsigned long flags; |
| 1828 | |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 1829 | bh_lock_sock(sk); |
Ursula Braun | f2a7799 | 2008-02-07 18:07:44 -0800 | [diff] [blame] | 1830 | if (!skb_queue_empty(list)) { |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1831 | spin_lock_irqsave(&list->lock, flags); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1832 | |
Ursula Braun | f2a7799 | 2008-02-07 18:07:44 -0800 | [diff] [blame] | 1833 | while (list_skb != (struct sk_buff *)list) { |
Hendrik Brueckner | 44b1e6b | 2009-04-21 23:26:24 +0000 | [diff] [blame] | 1834 | if (!memcmp(&msg->tag, CB_TAG(list_skb), CB_TAG_LEN)) { |
Ursula Braun | f2a7799 | 2008-02-07 18:07:44 -0800 | [diff] [blame] | 1835 | this = list_skb; |
| 1836 | break; |
| 1837 | } |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1838 | list_skb = list_skb->next; |
Ursula Braun | f2a7799 | 2008-02-07 18:07:44 -0800 | [diff] [blame] | 1839 | } |
| 1840 | if (this) |
| 1841 | __skb_unlink(this, list); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1842 | |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1843 | spin_unlock_irqrestore(&list->lock, flags); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1844 | |
Hendrik Brueckner | 0ea920d | 2009-06-17 21:54:48 +0000 | [diff] [blame] | 1845 | if (this) { |
| 1846 | kfree_skb(this); |
| 1847 | /* wake up any process waiting for sending */ |
| 1848 | iucv_sock_wake_msglim(sk); |
| 1849 | } |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 1852 | if (sk->sk_state == IUCV_CLOSING) { |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1853 | if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) { |
| 1854 | sk->sk_state = IUCV_CLOSED; |
| 1855 | sk->sk_state_change(sk); |
| 1856 | } |
| 1857 | } |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 1858 | bh_unlock_sock(sk); |
Jennifer Hunt | 561e036 | 2007-05-04 12:22:07 -0700 | [diff] [blame] | 1859 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | static void iucv_callback_connrej(struct iucv_path *path, u8 ipuser[16]) |
| 1863 | { |
| 1864 | struct sock *sk = path->private; |
| 1865 | |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 1866 | if (sk->sk_state == IUCV_CLOSED) |
| 1867 | return; |
| 1868 | |
| 1869 | bh_lock_sock(sk); |
| 1870 | iucv_sever_path(sk, 1); |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 1871 | sk->sk_state = IUCV_DISCONN; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1872 | |
| 1873 | sk->sk_state_change(sk); |
Ursula Braun | 7d316b9 | 2012-02-08 00:19:45 +0000 | [diff] [blame] | 1874 | bh_unlock_sock(sk); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 1875 | } |
| 1876 | |
Hendrik Brueckner | af88b52 | 2009-04-21 23:26:21 +0000 | [diff] [blame] | 1877 | /* called if the other communication side shuts down its RECV direction; |
| 1878 | * in turn, the callback sets SEND_SHUTDOWN to disable sending of data. |
| 1879 | */ |
| 1880 | static void iucv_callback_shutdown(struct iucv_path *path, u8 ipuser[16]) |
| 1881 | { |
| 1882 | struct sock *sk = path->private; |
| 1883 | |
| 1884 | bh_lock_sock(sk); |
| 1885 | if (sk->sk_state != IUCV_CLOSED) { |
| 1886 | sk->sk_shutdown |= SEND_SHUTDOWN; |
| 1887 | sk->sk_state_change(sk); |
| 1888 | } |
| 1889 | bh_unlock_sock(sk); |
| 1890 | } |
| 1891 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1892 | /***************** HiperSockets transport callbacks ********************/ |
| 1893 | static void afiucv_swap_src_dest(struct sk_buff *skb) |
| 1894 | { |
| 1895 | struct af_iucv_trans_hdr *trans_hdr = |
| 1896 | (struct af_iucv_trans_hdr *)skb->data; |
| 1897 | char tmpID[8]; |
| 1898 | char tmpName[8]; |
| 1899 | |
| 1900 | ASCEBC(trans_hdr->destUserID, sizeof(trans_hdr->destUserID)); |
| 1901 | ASCEBC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName)); |
| 1902 | ASCEBC(trans_hdr->srcUserID, sizeof(trans_hdr->srcUserID)); |
| 1903 | ASCEBC(trans_hdr->srcAppName, sizeof(trans_hdr->srcAppName)); |
| 1904 | memcpy(tmpID, trans_hdr->srcUserID, 8); |
| 1905 | memcpy(tmpName, trans_hdr->srcAppName, 8); |
| 1906 | memcpy(trans_hdr->srcUserID, trans_hdr->destUserID, 8); |
| 1907 | memcpy(trans_hdr->srcAppName, trans_hdr->destAppName, 8); |
| 1908 | memcpy(trans_hdr->destUserID, tmpID, 8); |
| 1909 | memcpy(trans_hdr->destAppName, tmpName, 8); |
| 1910 | skb_push(skb, ETH_HLEN); |
| 1911 | memset(skb->data, 0, ETH_HLEN); |
| 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * afiucv_hs_callback_syn - react on received SYN |
| 1916 | **/ |
| 1917 | static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb) |
| 1918 | { |
| 1919 | struct sock *nsk; |
| 1920 | struct iucv_sock *iucv, *niucv; |
| 1921 | struct af_iucv_trans_hdr *trans_hdr; |
| 1922 | int err; |
| 1923 | |
| 1924 | iucv = iucv_sk(sk); |
| 1925 | trans_hdr = (struct af_iucv_trans_hdr *)skb->data; |
| 1926 | if (!iucv) { |
| 1927 | /* no sock - connection refused */ |
| 1928 | afiucv_swap_src_dest(skb); |
| 1929 | trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN; |
| 1930 | err = dev_queue_xmit(skb); |
| 1931 | goto out; |
| 1932 | } |
| 1933 | |
| 1934 | nsk = iucv_sock_alloc(NULL, sk->sk_type, GFP_ATOMIC); |
| 1935 | bh_lock_sock(sk); |
| 1936 | if ((sk->sk_state != IUCV_LISTEN) || |
| 1937 | sk_acceptq_is_full(sk) || |
| 1938 | !nsk) { |
| 1939 | /* error on server socket - connection refused */ |
| 1940 | if (nsk) |
| 1941 | sk_free(nsk); |
| 1942 | afiucv_swap_src_dest(skb); |
| 1943 | trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN; |
| 1944 | err = dev_queue_xmit(skb); |
| 1945 | bh_unlock_sock(sk); |
| 1946 | goto out; |
| 1947 | } |
| 1948 | |
| 1949 | niucv = iucv_sk(nsk); |
| 1950 | iucv_sock_init(nsk, sk); |
| 1951 | niucv->transport = AF_IUCV_TRANS_HIPER; |
| 1952 | niucv->msglimit = iucv->msglimit; |
| 1953 | if (!trans_hdr->window) |
| 1954 | niucv->msglimit_peer = IUCV_HIPER_MSGLIM_DEFAULT; |
| 1955 | else |
| 1956 | niucv->msglimit_peer = trans_hdr->window; |
| 1957 | memcpy(niucv->dst_name, trans_hdr->srcAppName, 8); |
| 1958 | memcpy(niucv->dst_user_id, trans_hdr->srcUserID, 8); |
| 1959 | memcpy(niucv->src_name, iucv->src_name, 8); |
| 1960 | memcpy(niucv->src_user_id, iucv->src_user_id, 8); |
| 1961 | nsk->sk_bound_dev_if = sk->sk_bound_dev_if; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 1962 | niucv->hs_dev = iucv->hs_dev; |
| 1963 | dev_hold(niucv->hs_dev); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 1964 | afiucv_swap_src_dest(skb); |
| 1965 | trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_ACK; |
| 1966 | trans_hdr->window = niucv->msglimit; |
| 1967 | /* if receiver acks the xmit connection is established */ |
| 1968 | err = dev_queue_xmit(skb); |
| 1969 | if (!err) { |
| 1970 | iucv_accept_enqueue(sk, nsk); |
| 1971 | nsk->sk_state = IUCV_CONNECTED; |
| 1972 | sk->sk_data_ready(sk, 1); |
| 1973 | } else |
| 1974 | iucv_sock_kill(nsk); |
| 1975 | bh_unlock_sock(sk); |
| 1976 | |
| 1977 | out: |
| 1978 | return NET_RX_SUCCESS; |
| 1979 | } |
| 1980 | |
| 1981 | /** |
| 1982 | * afiucv_hs_callback_synack() - react on received SYN-ACK |
| 1983 | **/ |
| 1984 | static int afiucv_hs_callback_synack(struct sock *sk, struct sk_buff *skb) |
| 1985 | { |
| 1986 | struct iucv_sock *iucv = iucv_sk(sk); |
| 1987 | struct af_iucv_trans_hdr *trans_hdr = |
| 1988 | (struct af_iucv_trans_hdr *)skb->data; |
| 1989 | |
| 1990 | if (!iucv) |
| 1991 | goto out; |
| 1992 | if (sk->sk_state != IUCV_BOUND) |
| 1993 | goto out; |
| 1994 | bh_lock_sock(sk); |
| 1995 | iucv->msglimit_peer = trans_hdr->window; |
| 1996 | sk->sk_state = IUCV_CONNECTED; |
| 1997 | sk->sk_state_change(sk); |
| 1998 | bh_unlock_sock(sk); |
| 1999 | out: |
| 2000 | kfree_skb(skb); |
| 2001 | return NET_RX_SUCCESS; |
| 2002 | } |
| 2003 | |
| 2004 | /** |
| 2005 | * afiucv_hs_callback_synfin() - react on received SYN_FIN |
| 2006 | **/ |
| 2007 | static int afiucv_hs_callback_synfin(struct sock *sk, struct sk_buff *skb) |
| 2008 | { |
| 2009 | struct iucv_sock *iucv = iucv_sk(sk); |
| 2010 | |
| 2011 | if (!iucv) |
| 2012 | goto out; |
| 2013 | if (sk->sk_state != IUCV_BOUND) |
| 2014 | goto out; |
| 2015 | bh_lock_sock(sk); |
| 2016 | sk->sk_state = IUCV_DISCONN; |
| 2017 | sk->sk_state_change(sk); |
| 2018 | bh_unlock_sock(sk); |
| 2019 | out: |
| 2020 | kfree_skb(skb); |
| 2021 | return NET_RX_SUCCESS; |
| 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * afiucv_hs_callback_fin() - react on received FIN |
| 2026 | **/ |
| 2027 | static int afiucv_hs_callback_fin(struct sock *sk, struct sk_buff *skb) |
| 2028 | { |
| 2029 | struct iucv_sock *iucv = iucv_sk(sk); |
| 2030 | |
| 2031 | /* other end of connection closed */ |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2032 | if (!iucv) |
| 2033 | goto out; |
| 2034 | bh_lock_sock(sk); |
| 2035 | if (sk->sk_state == IUCV_CONNECTED) { |
Ursula Braun | aac6399 | 2011-12-19 22:56:31 +0000 | [diff] [blame] | 2036 | sk->sk_state = IUCV_DISCONN; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2037 | sk->sk_state_change(sk); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2038 | } |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2039 | bh_unlock_sock(sk); |
| 2040 | out: |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2041 | kfree_skb(skb); |
| 2042 | return NET_RX_SUCCESS; |
| 2043 | } |
| 2044 | |
| 2045 | /** |
| 2046 | * afiucv_hs_callback_win() - react on received WIN |
| 2047 | **/ |
| 2048 | static int afiucv_hs_callback_win(struct sock *sk, struct sk_buff *skb) |
| 2049 | { |
| 2050 | struct iucv_sock *iucv = iucv_sk(sk); |
| 2051 | struct af_iucv_trans_hdr *trans_hdr = |
| 2052 | (struct af_iucv_trans_hdr *)skb->data; |
| 2053 | |
| 2054 | if (!iucv) |
| 2055 | return NET_RX_SUCCESS; |
| 2056 | |
| 2057 | if (sk->sk_state != IUCV_CONNECTED) |
| 2058 | return NET_RX_SUCCESS; |
| 2059 | |
| 2060 | atomic_sub(trans_hdr->window, &iucv->msg_sent); |
| 2061 | iucv_sock_wake_msglim(sk); |
| 2062 | return NET_RX_SUCCESS; |
| 2063 | } |
| 2064 | |
| 2065 | /** |
| 2066 | * afiucv_hs_callback_rx() - react on received data |
| 2067 | **/ |
| 2068 | static int afiucv_hs_callback_rx(struct sock *sk, struct sk_buff *skb) |
| 2069 | { |
| 2070 | struct iucv_sock *iucv = iucv_sk(sk); |
| 2071 | |
| 2072 | if (!iucv) { |
| 2073 | kfree_skb(skb); |
| 2074 | return NET_RX_SUCCESS; |
| 2075 | } |
| 2076 | |
| 2077 | if (sk->sk_state != IUCV_CONNECTED) { |
| 2078 | kfree_skb(skb); |
| 2079 | return NET_RX_SUCCESS; |
| 2080 | } |
| 2081 | |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 2082 | if (sk->sk_shutdown & RCV_SHUTDOWN) { |
| 2083 | kfree_skb(skb); |
| 2084 | return NET_RX_SUCCESS; |
| 2085 | } |
| 2086 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2087 | /* write stuff from iucv_msg to skb cb */ |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 2088 | if (skb->len < sizeof(struct af_iucv_trans_hdr)) { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2089 | kfree_skb(skb); |
| 2090 | return NET_RX_SUCCESS; |
| 2091 | } |
| 2092 | skb_pull(skb, sizeof(struct af_iucv_trans_hdr)); |
| 2093 | skb_reset_transport_header(skb); |
| 2094 | skb_reset_network_header(skb); |
| 2095 | spin_lock(&iucv->message_q.lock); |
| 2096 | if (skb_queue_empty(&iucv->backlog_skb_q)) { |
| 2097 | if (sock_queue_rcv_skb(sk, skb)) { |
| 2098 | /* handle rcv queue full */ |
| 2099 | skb_queue_tail(&iucv->backlog_skb_q, skb); |
| 2100 | } |
| 2101 | } else |
| 2102 | skb_queue_tail(&iucv_sk(sk)->backlog_skb_q, skb); |
| 2103 | spin_unlock(&iucv->message_q.lock); |
| 2104 | return NET_RX_SUCCESS; |
| 2105 | } |
| 2106 | |
| 2107 | /** |
| 2108 | * afiucv_hs_rcv() - base function for arriving data through HiperSockets |
| 2109 | * transport |
| 2110 | * called from netif RX softirq |
| 2111 | **/ |
| 2112 | static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev, |
| 2113 | struct packet_type *pt, struct net_device *orig_dev) |
| 2114 | { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2115 | struct sock *sk; |
| 2116 | struct iucv_sock *iucv; |
| 2117 | struct af_iucv_trans_hdr *trans_hdr; |
| 2118 | char nullstring[8]; |
| 2119 | int err = 0; |
| 2120 | |
| 2121 | skb_pull(skb, ETH_HLEN); |
| 2122 | trans_hdr = (struct af_iucv_trans_hdr *)skb->data; |
| 2123 | EBCASC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName)); |
| 2124 | EBCASC(trans_hdr->destUserID, sizeof(trans_hdr->destUserID)); |
| 2125 | EBCASC(trans_hdr->srcAppName, sizeof(trans_hdr->srcAppName)); |
| 2126 | EBCASC(trans_hdr->srcUserID, sizeof(trans_hdr->srcUserID)); |
| 2127 | memset(nullstring, 0, sizeof(nullstring)); |
| 2128 | iucv = NULL; |
| 2129 | sk = NULL; |
| 2130 | read_lock(&iucv_sk_list.lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2131 | sk_for_each(sk, &iucv_sk_list.head) { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2132 | if (trans_hdr->flags == AF_IUCV_FLAG_SYN) { |
| 2133 | if ((!memcmp(&iucv_sk(sk)->src_name, |
| 2134 | trans_hdr->destAppName, 8)) && |
| 2135 | (!memcmp(&iucv_sk(sk)->src_user_id, |
| 2136 | trans_hdr->destUserID, 8)) && |
| 2137 | (!memcmp(&iucv_sk(sk)->dst_name, nullstring, 8)) && |
| 2138 | (!memcmp(&iucv_sk(sk)->dst_user_id, |
| 2139 | nullstring, 8))) { |
| 2140 | iucv = iucv_sk(sk); |
| 2141 | break; |
| 2142 | } |
| 2143 | } else { |
| 2144 | if ((!memcmp(&iucv_sk(sk)->src_name, |
| 2145 | trans_hdr->destAppName, 8)) && |
| 2146 | (!memcmp(&iucv_sk(sk)->src_user_id, |
| 2147 | trans_hdr->destUserID, 8)) && |
| 2148 | (!memcmp(&iucv_sk(sk)->dst_name, |
| 2149 | trans_hdr->srcAppName, 8)) && |
| 2150 | (!memcmp(&iucv_sk(sk)->dst_user_id, |
| 2151 | trans_hdr->srcUserID, 8))) { |
| 2152 | iucv = iucv_sk(sk); |
| 2153 | break; |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | read_unlock(&iucv_sk_list.lock); |
| 2158 | if (!iucv) |
| 2159 | sk = NULL; |
| 2160 | |
| 2161 | /* no sock |
| 2162 | how should we send with no sock |
| 2163 | 1) send without sock no send rc checking? |
| 2164 | 2) introduce default sock to handle this cases |
| 2165 | |
| 2166 | SYN -> send SYN|ACK in good case, send SYN|FIN in bad case |
| 2167 | data -> send FIN |
| 2168 | SYN|ACK, SYN|FIN, FIN -> no action? */ |
| 2169 | |
| 2170 | switch (trans_hdr->flags) { |
| 2171 | case AF_IUCV_FLAG_SYN: |
| 2172 | /* connect request */ |
| 2173 | err = afiucv_hs_callback_syn(sk, skb); |
| 2174 | break; |
| 2175 | case (AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_ACK): |
| 2176 | /* connect request confirmed */ |
| 2177 | err = afiucv_hs_callback_synack(sk, skb); |
| 2178 | break; |
| 2179 | case (AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN): |
| 2180 | /* connect request refused */ |
| 2181 | err = afiucv_hs_callback_synfin(sk, skb); |
| 2182 | break; |
| 2183 | case (AF_IUCV_FLAG_FIN): |
| 2184 | /* close request */ |
| 2185 | err = afiucv_hs_callback_fin(sk, skb); |
| 2186 | break; |
| 2187 | case (AF_IUCV_FLAG_WIN): |
| 2188 | err = afiucv_hs_callback_win(sk, skb); |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2189 | if (skb->len == sizeof(struct af_iucv_trans_hdr)) { |
| 2190 | kfree_skb(skb); |
| 2191 | break; |
| 2192 | } |
Ursula Braun | 82492a3 | 2012-03-07 02:06:24 +0000 | [diff] [blame] | 2193 | /* fall through and receive non-zero length data */ |
| 2194 | case (AF_IUCV_FLAG_SHT): |
| 2195 | /* shutdown request */ |
| 2196 | /* fall through and receive zero length data */ |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2197 | case 0: |
| 2198 | /* plain data frame */ |
Ursula Braun | c64d3f8 | 2011-12-19 22:56:27 +0000 | [diff] [blame] | 2199 | memcpy(CB_TRGCLS(skb), &trans_hdr->iucv_hdr.class, |
| 2200 | CB_TRGCLS_LEN); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2201 | err = afiucv_hs_callback_rx(sk, skb); |
| 2202 | break; |
| 2203 | default: |
| 2204 | ; |
| 2205 | } |
| 2206 | |
| 2207 | return err; |
| 2208 | } |
| 2209 | |
| 2210 | /** |
| 2211 | * afiucv_hs_callback_txnotify() - handle send notifcations from HiperSockets |
| 2212 | * transport |
| 2213 | **/ |
| 2214 | static void afiucv_hs_callback_txnotify(struct sk_buff *skb, |
| 2215 | enum iucv_tx_notify n) |
| 2216 | { |
| 2217 | struct sock *isk = skb->sk; |
| 2218 | struct sock *sk = NULL; |
| 2219 | struct iucv_sock *iucv = NULL; |
| 2220 | struct sk_buff_head *list; |
| 2221 | struct sk_buff *list_skb; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2222 | struct sk_buff *nskb; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2223 | unsigned long flags; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2224 | |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2225 | read_lock_irqsave(&iucv_sk_list.lock, flags); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2226 | sk_for_each(sk, &iucv_sk_list.head) |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2227 | if (sk == isk) { |
| 2228 | iucv = iucv_sk(sk); |
| 2229 | break; |
| 2230 | } |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2231 | read_unlock_irqrestore(&iucv_sk_list.lock, flags); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2232 | |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2233 | if (!iucv || sock_flag(sk, SOCK_ZAPPED)) |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2234 | return; |
| 2235 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2236 | list = &iucv->send_skb_q; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2237 | spin_lock_irqsave(&list->lock, flags); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2238 | if (skb_queue_empty(list)) |
| 2239 | goto out_unlock; |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2240 | list_skb = list->next; |
| 2241 | nskb = list_skb->next; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2242 | while (list_skb != (struct sk_buff *)list) { |
| 2243 | if (skb_shinfo(list_skb) == skb_shinfo(skb)) { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2244 | switch (n) { |
| 2245 | case TX_NOTIFY_OK: |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2246 | __skb_unlink(list_skb, list); |
| 2247 | kfree_skb(list_skb); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2248 | iucv_sock_wake_msglim(sk); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2249 | break; |
| 2250 | case TX_NOTIFY_PENDING: |
| 2251 | atomic_inc(&iucv->pendings); |
| 2252 | break; |
| 2253 | case TX_NOTIFY_DELAYED_OK: |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2254 | __skb_unlink(list_skb, list); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2255 | atomic_dec(&iucv->pendings); |
| 2256 | if (atomic_read(&iucv->pendings) <= 0) |
| 2257 | iucv_sock_wake_msglim(sk); |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2258 | kfree_skb(list_skb); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2259 | break; |
| 2260 | case TX_NOTIFY_UNREACHABLE: |
| 2261 | case TX_NOTIFY_DELAYED_UNREACHABLE: |
| 2262 | case TX_NOTIFY_TPQFULL: /* not yet used */ |
| 2263 | case TX_NOTIFY_GENERALERROR: |
| 2264 | case TX_NOTIFY_DELAYED_GENERALERROR: |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2265 | __skb_unlink(list_skb, list); |
| 2266 | kfree_skb(list_skb); |
| 2267 | if (sk->sk_state == IUCV_CONNECTED) { |
| 2268 | sk->sk_state = IUCV_DISCONN; |
| 2269 | sk->sk_state_change(sk); |
| 2270 | } |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2271 | break; |
| 2272 | } |
| 2273 | break; |
| 2274 | } |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2275 | list_skb = nskb; |
| 2276 | nskb = nskb->next; |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2277 | } |
Ursula Braun | 800c5eb | 2012-02-08 00:19:47 +0000 | [diff] [blame] | 2278 | out_unlock: |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2279 | spin_unlock_irqrestore(&list->lock, flags); |
| 2280 | |
Ursula Braun | 42bd48e | 2011-12-19 22:56:28 +0000 | [diff] [blame] | 2281 | if (sk->sk_state == IUCV_CLOSING) { |
| 2282 | if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) { |
| 2283 | sk->sk_state = IUCV_CLOSED; |
| 2284 | sk->sk_state_change(sk); |
| 2285 | } |
| 2286 | } |
| 2287 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2288 | } |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 2289 | |
| 2290 | /* |
| 2291 | * afiucv_netdev_event: handle netdev notifier chain events |
| 2292 | */ |
| 2293 | static int afiucv_netdev_event(struct notifier_block *this, |
| 2294 | unsigned long event, void *ptr) |
| 2295 | { |
| 2296 | struct net_device *event_dev = (struct net_device *)ptr; |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 2297 | struct sock *sk; |
| 2298 | struct iucv_sock *iucv; |
| 2299 | |
| 2300 | switch (event) { |
| 2301 | case NETDEV_REBOOT: |
| 2302 | case NETDEV_GOING_DOWN: |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2303 | sk_for_each(sk, &iucv_sk_list.head) { |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 2304 | iucv = iucv_sk(sk); |
| 2305 | if ((iucv->hs_dev == event_dev) && |
| 2306 | (sk->sk_state == IUCV_CONNECTED)) { |
| 2307 | if (event == NETDEV_GOING_DOWN) |
| 2308 | iucv_send_ctrl(sk, AF_IUCV_FLAG_FIN); |
| 2309 | sk->sk_state = IUCV_DISCONN; |
| 2310 | sk->sk_state_change(sk); |
| 2311 | } |
| 2312 | } |
| 2313 | break; |
| 2314 | case NETDEV_DOWN: |
| 2315 | case NETDEV_UNREGISTER: |
| 2316 | default: |
| 2317 | break; |
| 2318 | } |
| 2319 | return NOTIFY_DONE; |
| 2320 | } |
| 2321 | |
| 2322 | static struct notifier_block afiucv_netdev_notifier = { |
| 2323 | .notifier_call = afiucv_netdev_event, |
| 2324 | }; |
| 2325 | |
Alexey Dobriyan | 5708e86 | 2009-09-14 12:23:23 +0000 | [diff] [blame] | 2326 | static const struct proto_ops iucv_sock_ops = { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2327 | .family = PF_IUCV, |
| 2328 | .owner = THIS_MODULE, |
| 2329 | .release = iucv_sock_release, |
| 2330 | .bind = iucv_sock_bind, |
| 2331 | .connect = iucv_sock_connect, |
| 2332 | .listen = iucv_sock_listen, |
| 2333 | .accept = iucv_sock_accept, |
| 2334 | .getname = iucv_sock_getname, |
| 2335 | .sendmsg = iucv_sock_sendmsg, |
| 2336 | .recvmsg = iucv_sock_recvmsg, |
| 2337 | .poll = iucv_sock_poll, |
| 2338 | .ioctl = sock_no_ioctl, |
| 2339 | .mmap = sock_no_mmap, |
| 2340 | .socketpair = sock_no_socketpair, |
| 2341 | .shutdown = iucv_sock_shutdown, |
Hendrik Brueckner | 9d5c5d8 | 2009-04-21 23:26:22 +0000 | [diff] [blame] | 2342 | .setsockopt = iucv_sock_setsockopt, |
| 2343 | .getsockopt = iucv_sock_getsockopt, |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2344 | }; |
| 2345 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 2346 | static const struct net_proto_family iucv_sock_family_ops = { |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2347 | .family = AF_IUCV, |
| 2348 | .owner = THIS_MODULE, |
| 2349 | .create = iucv_sock_create, |
| 2350 | }; |
| 2351 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2352 | static struct packet_type iucv_packet_type = { |
| 2353 | .type = cpu_to_be16(ETH_P_AF_IUCV), |
| 2354 | .func = afiucv_hs_rcv, |
| 2355 | }; |
| 2356 | |
| 2357 | static int afiucv_iucv_init(void) |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 2358 | { |
| 2359 | int err; |
| 2360 | |
| 2361 | err = pr_iucv->iucv_register(&af_iucv_handler, 0); |
| 2362 | if (err) |
| 2363 | goto out; |
| 2364 | /* establish dummy device */ |
| 2365 | af_iucv_driver.bus = pr_iucv->bus; |
| 2366 | err = driver_register(&af_iucv_driver); |
| 2367 | if (err) |
| 2368 | goto out_iucv; |
| 2369 | af_iucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 2370 | if (!af_iucv_dev) { |
| 2371 | err = -ENOMEM; |
| 2372 | goto out_driver; |
| 2373 | } |
| 2374 | dev_set_name(af_iucv_dev, "af_iucv"); |
| 2375 | af_iucv_dev->bus = pr_iucv->bus; |
| 2376 | af_iucv_dev->parent = pr_iucv->root; |
| 2377 | af_iucv_dev->release = (void (*)(struct device *))kfree; |
| 2378 | af_iucv_dev->driver = &af_iucv_driver; |
| 2379 | err = device_register(af_iucv_dev); |
| 2380 | if (err) |
| 2381 | goto out_driver; |
| 2382 | return 0; |
| 2383 | |
| 2384 | out_driver: |
| 2385 | driver_unregister(&af_iucv_driver); |
| 2386 | out_iucv: |
| 2387 | pr_iucv->iucv_unregister(&af_iucv_handler, 0); |
| 2388 | out: |
| 2389 | return err; |
| 2390 | } |
| 2391 | |
Heiko Carstens | da99f05 | 2007-05-04 12:23:27 -0700 | [diff] [blame] | 2392 | static int __init afiucv_init(void) |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2393 | { |
| 2394 | int err; |
| 2395 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2396 | if (MACHINE_IS_VM) { |
| 2397 | cpcmd("QUERY USERID", iucv_userid, sizeof(iucv_userid), &err); |
| 2398 | if (unlikely(err)) { |
| 2399 | WARN_ON(err); |
| 2400 | err = -EPROTONOSUPPORT; |
| 2401 | goto out; |
| 2402 | } |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2403 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2404 | pr_iucv = try_then_request_module(symbol_get(iucv_if), "iucv"); |
| 2405 | if (!pr_iucv) { |
| 2406 | printk(KERN_WARNING "iucv_if lookup failed\n"); |
| 2407 | memset(&iucv_userid, 0, sizeof(iucv_userid)); |
| 2408 | } |
| 2409 | } else { |
| 2410 | memset(&iucv_userid, 0, sizeof(iucv_userid)); |
| 2411 | pr_iucv = NULL; |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2414 | err = proto_register(&iucv_proto, 0); |
| 2415 | if (err) |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 2416 | goto out; |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2417 | err = sock_register(&iucv_sock_family_ops); |
| 2418 | if (err) |
| 2419 | goto out_proto; |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 2420 | |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2421 | if (pr_iucv) { |
| 2422 | err = afiucv_iucv_init(); |
| 2423 | if (err) |
| 2424 | goto out_sock; |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 2425 | } else |
| 2426 | register_netdevice_notifier(&afiucv_netdev_notifier); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2427 | dev_add_pack(&iucv_packet_type); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2428 | return 0; |
| 2429 | |
Ursula Braun | c23cad9 | 2009-06-16 10:30:44 +0200 | [diff] [blame] | 2430 | out_sock: |
| 2431 | sock_unregister(PF_IUCV); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2432 | out_proto: |
| 2433 | proto_unregister(&iucv_proto); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2434 | out: |
Frank Blaschka | 6fcd61f | 2011-08-08 01:33:51 +0000 | [diff] [blame] | 2435 | if (pr_iucv) |
| 2436 | symbol_put(iucv_if); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2437 | return err; |
| 2438 | } |
| 2439 | |
| 2440 | static void __exit afiucv_exit(void) |
| 2441 | { |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2442 | if (pr_iucv) { |
| 2443 | device_unregister(af_iucv_dev); |
| 2444 | driver_unregister(&af_iucv_driver); |
| 2445 | pr_iucv->iucv_unregister(&af_iucv_handler, 0); |
| 2446 | symbol_put(iucv_if); |
Ursula Braun | 9fbd87d | 2012-03-07 02:06:23 +0000 | [diff] [blame] | 2447 | } else |
| 2448 | unregister_netdevice_notifier(&afiucv_netdev_notifier); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2449 | dev_remove_pack(&iucv_packet_type); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2450 | sock_unregister(PF_IUCV); |
| 2451 | proto_unregister(&iucv_proto); |
Jennifer Hunt | eac3731 | 2007-02-08 13:51:54 -0800 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | module_init(afiucv_init); |
| 2455 | module_exit(afiucv_exit); |
| 2456 | |
| 2457 | MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>"); |
| 2458 | MODULE_DESCRIPTION("IUCV Sockets ver " VERSION); |
| 2459 | MODULE_VERSION(VERSION); |
| 2460 | MODULE_LICENSE("GPL"); |
| 2461 | MODULE_ALIAS_NETPROTO(PF_IUCV); |
Ursula Braun | 3881ac4 | 2011-08-08 01:33:54 +0000 | [diff] [blame] | 2462 | |