2 * IUCV protocol stack for Linux on zSeries
4 * Copyright IBM Corp. 2006, 2009
6 * Author(s): Jennifer Hunt <jenhunt@us.ibm.com>
7 * Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
9 * Ursula Braun <ursula.braun@de.ibm.com>
12 #define KMSG_COMPONENT "af_iucv"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
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>
26 #include <asm/ebcdic.h>
27 #include <asm/cpcmd.h>
28 #include <linux/kmod.h>
30 #include <net/iucv/af_iucv.h>
34 static char iucv_userid
[80];
36 static const struct proto_ops iucv_sock_ops
;
38 static struct proto iucv_proto
= {
41 .obj_size
= sizeof(struct iucv_sock
),
44 static struct iucv_interface
*pr_iucv
;
46 /* special AF_IUCV IPRM messages */
47 static const u8 iprm_shutdown
[8] =
48 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
50 #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
52 #define __iucv_sock_wait(sk, condition, timeo, ret) \
54 DEFINE_WAIT(__wait); \
55 long __timeo = timeo; \
57 prepare_to_wait(sk_sleep(sk), &__wait, TASK_INTERRUPTIBLE); \
58 while (!(condition)) { \
63 if (signal_pending(current)) { \
64 ret = sock_intr_errno(__timeo); \
68 __timeo = schedule_timeout(__timeo); \
70 ret = sock_error(sk); \
74 finish_wait(sk_sleep(sk), &__wait); \
77 #define iucv_sock_wait(sk, condition, timeo) \
81 __iucv_sock_wait(sk, condition, timeo, __ret); \
85 static void iucv_sock_kill(struct sock
*sk
);
86 static void iucv_sock_close(struct sock
*sk
);
87 static void iucv_sever_path(struct sock
*, int);
89 static int afiucv_hs_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
90 struct packet_type
*pt
, struct net_device
*orig_dev
);
91 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
92 struct sk_buff
*skb
, u8 flags
);
93 static void afiucv_hs_callback_txnotify(struct sk_buff
*, enum iucv_tx_notify
);
95 /* Call Back functions */
96 static void iucv_callback_rx(struct iucv_path
*, struct iucv_message
*);
97 static void iucv_callback_txdone(struct iucv_path
*, struct iucv_message
*);
98 static void iucv_callback_connack(struct iucv_path
*, u8 ipuser
[16]);
99 static int iucv_callback_connreq(struct iucv_path
*, u8 ipvmid
[8],
101 static void iucv_callback_connrej(struct iucv_path
*, u8 ipuser
[16]);
102 static void iucv_callback_shutdown(struct iucv_path
*, u8 ipuser
[16]);
104 static struct iucv_sock_list iucv_sk_list
= {
105 .lock
= __RW_LOCK_UNLOCKED(iucv_sk_list
.lock
),
106 .autobind_name
= ATOMIC_INIT(0)
109 static struct iucv_handler af_iucv_handler
= {
110 .path_pending
= iucv_callback_connreq
,
111 .path_complete
= iucv_callback_connack
,
112 .path_severed
= iucv_callback_connrej
,
113 .message_pending
= iucv_callback_rx
,
114 .message_complete
= iucv_callback_txdone
,
115 .path_quiesced
= iucv_callback_shutdown
,
118 static inline void high_nmcpy(unsigned char *dst
, char *src
)
123 static inline void low_nmcpy(unsigned char *dst
, char *src
)
125 memcpy(&dst
[8], src
, 8);
128 static int afiucv_pm_prepare(struct device
*dev
)
130 #ifdef CONFIG_PM_DEBUG
131 printk(KERN_WARNING
"afiucv_pm_prepare\n");
136 static void afiucv_pm_complete(struct device
*dev
)
138 #ifdef CONFIG_PM_DEBUG
139 printk(KERN_WARNING
"afiucv_pm_complete\n");
144 * afiucv_pm_freeze() - Freeze PM callback
145 * @dev: AFIUCV dummy device
147 * Sever all established IUCV communication pathes
149 static int afiucv_pm_freeze(struct device
*dev
)
151 struct iucv_sock
*iucv
;
155 #ifdef CONFIG_PM_DEBUG
156 printk(KERN_WARNING
"afiucv_pm_freeze\n");
158 read_lock(&iucv_sk_list
.lock
);
159 sk_for_each(sk
, &iucv_sk_list
.head
) {
161 switch (sk
->sk_state
) {
165 iucv_sever_path(sk
, 0);
174 skb_queue_purge(&iucv
->send_skb_q
);
175 skb_queue_purge(&iucv
->backlog_skb_q
);
177 read_unlock(&iucv_sk_list
.lock
);
182 * afiucv_pm_restore_thaw() - Thaw and restore PM callback
183 * @dev: AFIUCV dummy device
185 * socket clean up after freeze
187 static int afiucv_pm_restore_thaw(struct device
*dev
)
191 #ifdef CONFIG_PM_DEBUG
192 printk(KERN_WARNING
"afiucv_pm_restore_thaw\n");
194 read_lock(&iucv_sk_list
.lock
);
195 sk_for_each(sk
, &iucv_sk_list
.head
) {
196 switch (sk
->sk_state
) {
199 sk
->sk_state
= IUCV_DISCONN
;
200 sk
->sk_state_change(sk
);
211 read_unlock(&iucv_sk_list
.lock
);
215 static const struct dev_pm_ops afiucv_pm_ops
= {
216 .prepare
= afiucv_pm_prepare
,
217 .complete
= afiucv_pm_complete
,
218 .freeze
= afiucv_pm_freeze
,
219 .thaw
= afiucv_pm_restore_thaw
,
220 .restore
= afiucv_pm_restore_thaw
,
223 static struct device_driver af_iucv_driver
= {
224 .owner
= THIS_MODULE
,
227 .pm
= &afiucv_pm_ops
,
230 /* dummy device used as trigger for PM functions */
231 static struct device
*af_iucv_dev
;
234 * iucv_msg_length() - Returns the length of an iucv message.
235 * @msg: Pointer to struct iucv_message, MUST NOT be NULL
237 * The function returns the length of the specified iucv message @msg of data
238 * stored in a buffer and of data stored in the parameter list (PRMDATA).
240 * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket
242 * PRMDATA[0..6] socket data (max 7 bytes);
243 * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7])
245 * The socket data length is computed by subtracting the socket data length
247 * If the socket data len is greater 7, then PRMDATA can be used for special
248 * notifications (see iucv_sock_shutdown); and further,
249 * if the socket data len is > 7, the function returns 8.
251 * Use this function to allocate socket buffers to store iucv message data.
253 static inline size_t iucv_msg_length(struct iucv_message
*msg
)
257 if (msg
->flags
& IUCV_IPRMDATA
) {
258 datalen
= 0xff - msg
->rmmsg
[7];
259 return (datalen
< 8) ? datalen
: 8;
265 * iucv_sock_in_state() - check for specific states
266 * @sk: sock structure
267 * @state: first iucv sk state
268 * @state: second iucv sk state
270 * Returns true if the socket in either in the first or second state.
272 static int iucv_sock_in_state(struct sock
*sk
, int state
, int state2
)
274 return (sk
->sk_state
== state
|| sk
->sk_state
== state2
);
278 * iucv_below_msglim() - function to check if messages can be sent
279 * @sk: sock structure
281 * Returns true if the send queue length is lower than the message limit.
282 * Always returns true if the socket is not connected (no iucv path for
283 * checking the message limit).
285 static inline int iucv_below_msglim(struct sock
*sk
)
287 struct iucv_sock
*iucv
= iucv_sk(sk
);
289 if (sk
->sk_state
!= IUCV_CONNECTED
)
291 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
)
292 return (skb_queue_len(&iucv
->send_skb_q
) < iucv
->path
->msglim
);
294 return ((atomic_read(&iucv
->msg_sent
) < iucv
->msglimit_peer
) &&
295 (atomic_read(&iucv
->pendings
) <= 0));
299 * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit
301 static void iucv_sock_wake_msglim(struct sock
*sk
)
303 struct socket_wq
*wq
;
306 wq
= rcu_dereference(sk
->sk_wq
);
307 if (wq_has_sleeper(wq
))
308 wake_up_interruptible_all(&wq
->wait
);
309 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
314 * afiucv_hs_send() - send a message through HiperSockets transport
316 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
317 struct sk_buff
*skb
, u8 flags
)
319 struct iucv_sock
*iucv
= iucv_sk(sock
);
320 struct af_iucv_trans_hdr
*phs_hdr
;
321 struct sk_buff
*nskb
;
322 int err
, confirm_recv
= 0;
324 memset(skb
->head
, 0, ETH_HLEN
);
325 phs_hdr
= (struct af_iucv_trans_hdr
*)skb_push(skb
,
326 sizeof(struct af_iucv_trans_hdr
));
327 skb_reset_mac_header(skb
);
328 skb_reset_network_header(skb
);
329 skb_push(skb
, ETH_HLEN
);
330 skb_reset_mac_header(skb
);
331 memset(phs_hdr
, 0, sizeof(struct af_iucv_trans_hdr
));
333 phs_hdr
->magic
= ETH_P_AF_IUCV
;
334 phs_hdr
->version
= 1;
335 phs_hdr
->flags
= flags
;
336 if (flags
== AF_IUCV_FLAG_SYN
)
337 phs_hdr
->window
= iucv
->msglimit
;
338 else if ((flags
== AF_IUCV_FLAG_WIN
) || !flags
) {
339 confirm_recv
= atomic_read(&iucv
->msg_recv
);
340 phs_hdr
->window
= confirm_recv
;
342 phs_hdr
->flags
= phs_hdr
->flags
| AF_IUCV_FLAG_WIN
;
344 memcpy(phs_hdr
->destUserID
, iucv
->dst_user_id
, 8);
345 memcpy(phs_hdr
->destAppName
, iucv
->dst_name
, 8);
346 memcpy(phs_hdr
->srcUserID
, iucv
->src_user_id
, 8);
347 memcpy(phs_hdr
->srcAppName
, iucv
->src_name
, 8);
348 ASCEBC(phs_hdr
->destUserID
, sizeof(phs_hdr
->destUserID
));
349 ASCEBC(phs_hdr
->destAppName
, sizeof(phs_hdr
->destAppName
));
350 ASCEBC(phs_hdr
->srcUserID
, sizeof(phs_hdr
->srcUserID
));
351 ASCEBC(phs_hdr
->srcAppName
, sizeof(phs_hdr
->srcAppName
));
353 memcpy(&phs_hdr
->iucv_hdr
, imsg
, sizeof(struct iucv_message
));
355 skb
->dev
= iucv
->hs_dev
;
358 if (!(skb
->dev
->flags
& IFF_UP
) || !netif_carrier_ok(skb
->dev
))
360 if (skb
->len
> skb
->dev
->mtu
) {
361 if (sock
->sk_type
== SOCK_SEQPACKET
)
364 skb_trim(skb
, skb
->dev
->mtu
);
366 skb
->protocol
= ETH_P_AF_IUCV
;
367 nskb
= skb_clone(skb
, GFP_ATOMIC
);
370 skb_queue_tail(&iucv
->send_skb_q
, nskb
);
371 err
= dev_queue_xmit(skb
);
372 if (net_xmit_eval(err
)) {
373 skb_unlink(nskb
, &iucv
->send_skb_q
);
376 atomic_sub(confirm_recv
, &iucv
->msg_recv
);
377 WARN_ON(atomic_read(&iucv
->msg_recv
) < 0);
379 return net_xmit_eval(err
);
382 static struct sock
*__iucv_get_sock_by_name(char *nm
)
386 sk_for_each(sk
, &iucv_sk_list
.head
)
387 if (!memcmp(&iucv_sk(sk
)->src_name
, nm
, 8))
393 static void iucv_sock_destruct(struct sock
*sk
)
395 skb_queue_purge(&sk
->sk_receive_queue
);
396 skb_queue_purge(&sk
->sk_error_queue
);
400 if (!sock_flag(sk
, SOCK_DEAD
)) {
401 pr_err("Attempt to release alive iucv socket %p\n", sk
);
405 WARN_ON(atomic_read(&sk
->sk_rmem_alloc
));
406 WARN_ON(atomic_read(&sk
->sk_wmem_alloc
));
407 WARN_ON(sk
->sk_wmem_queued
);
408 WARN_ON(sk
->sk_forward_alloc
);
412 static void iucv_sock_cleanup_listen(struct sock
*parent
)
416 /* Close non-accepted connections */
417 while ((sk
= iucv_accept_dequeue(parent
, NULL
))) {
422 parent
->sk_state
= IUCV_CLOSED
;
425 /* Kill socket (only if zapped and orphaned) */
426 static void iucv_sock_kill(struct sock
*sk
)
428 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
431 iucv_sock_unlink(&iucv_sk_list
, sk
);
432 sock_set_flag(sk
, SOCK_DEAD
);
436 /* Terminate an IUCV path */
437 static void iucv_sever_path(struct sock
*sk
, int with_user_data
)
439 unsigned char user_data
[16];
440 struct iucv_sock
*iucv
= iucv_sk(sk
);
441 struct iucv_path
*path
= iucv
->path
;
445 if (with_user_data
) {
446 low_nmcpy(user_data
, iucv
->src_name
);
447 high_nmcpy(user_data
, iucv
->dst_name
);
448 ASCEBC(user_data
, sizeof(user_data
));
449 pr_iucv
->path_sever(path
, user_data
);
451 pr_iucv
->path_sever(path
, NULL
);
452 iucv_path_free(path
);
456 /* Send FIN through an IUCV socket for HIPER transport */
457 static int iucv_send_ctrl(struct sock
*sk
, u8 flags
)
463 blen
= sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
;
464 skb
= sock_alloc_send_skb(sk
, blen
, 1, &err
);
466 skb_reserve(skb
, blen
);
467 err
= afiucv_hs_send(NULL
, sk
, skb
, flags
);
472 /* Close an IUCV socket */
473 static void iucv_sock_close(struct sock
*sk
)
475 struct iucv_sock
*iucv
= iucv_sk(sk
);
481 switch (sk
->sk_state
) {
483 iucv_sock_cleanup_listen(sk
);
487 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
488 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
489 sk
->sk_state
= IUCV_DISCONN
;
490 sk
->sk_state_change(sk
);
492 case IUCV_DISCONN
: /* fall through */
493 sk
->sk_state
= IUCV_CLOSING
;
494 sk
->sk_state_change(sk
);
496 if (!err
&& !skb_queue_empty(&iucv
->send_skb_q
)) {
497 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
498 timeo
= sk
->sk_lingertime
;
500 timeo
= IUCV_DISCONN_TIMEOUT
;
502 iucv_sock_in_state(sk
, IUCV_CLOSED
, 0),
506 case IUCV_CLOSING
: /* fall through */
507 sk
->sk_state
= IUCV_CLOSED
;
508 sk
->sk_state_change(sk
);
510 sk
->sk_err
= ECONNRESET
;
511 sk
->sk_state_change(sk
);
513 skb_queue_purge(&iucv
->send_skb_q
);
514 skb_queue_purge(&iucv
->backlog_skb_q
);
516 default: /* fall through */
517 iucv_sever_path(sk
, 1);
521 dev_put(iucv
->hs_dev
);
523 sk
->sk_bound_dev_if
= 0;
526 /* mark socket for deletion by iucv_sock_kill() */
527 sock_set_flag(sk
, SOCK_ZAPPED
);
532 static void iucv_sock_init(struct sock
*sk
, struct sock
*parent
)
535 sk
->sk_type
= parent
->sk_type
;
538 static struct sock
*iucv_sock_alloc(struct socket
*sock
, int proto
, gfp_t prio
)
541 struct iucv_sock
*iucv
;
543 sk
= sk_alloc(&init_net
, PF_IUCV
, prio
, &iucv_proto
);
548 sock_init_data(sock
, sk
);
549 INIT_LIST_HEAD(&iucv
->accept_q
);
550 spin_lock_init(&iucv
->accept_q_lock
);
551 skb_queue_head_init(&iucv
->send_skb_q
);
552 INIT_LIST_HEAD(&iucv
->message_q
.list
);
553 spin_lock_init(&iucv
->message_q
.lock
);
554 skb_queue_head_init(&iucv
->backlog_skb_q
);
556 atomic_set(&iucv
->pendings
, 0);
559 atomic_set(&iucv
->msg_sent
, 0);
560 atomic_set(&iucv
->msg_recv
, 0);
562 iucv
->sk_txnotify
= afiucv_hs_callback_txnotify
;
563 memset(&iucv
->src_user_id
, 0, 32);
565 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
567 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
569 sk
->sk_destruct
= iucv_sock_destruct
;
570 sk
->sk_sndtimeo
= IUCV_CONN_TIMEOUT
;
571 sk
->sk_allocation
= GFP_DMA
;
573 sock_reset_flag(sk
, SOCK_ZAPPED
);
575 sk
->sk_protocol
= proto
;
576 sk
->sk_state
= IUCV_OPEN
;
578 iucv_sock_link(&iucv_sk_list
, sk
);
582 /* Create an IUCV socket */
583 static int iucv_sock_create(struct net
*net
, struct socket
*sock
, int protocol
,
588 if (protocol
&& protocol
!= PF_IUCV
)
589 return -EPROTONOSUPPORT
;
591 sock
->state
= SS_UNCONNECTED
;
593 switch (sock
->type
) {
595 sock
->ops
= &iucv_sock_ops
;
598 /* currently, proto ops can handle both sk types */
599 sock
->ops
= &iucv_sock_ops
;
602 return -ESOCKTNOSUPPORT
;
605 sk
= iucv_sock_alloc(sock
, protocol
, GFP_KERNEL
);
609 iucv_sock_init(sk
, NULL
);
614 void iucv_sock_link(struct iucv_sock_list
*l
, struct sock
*sk
)
616 write_lock_bh(&l
->lock
);
617 sk_add_node(sk
, &l
->head
);
618 write_unlock_bh(&l
->lock
);
621 void iucv_sock_unlink(struct iucv_sock_list
*l
, struct sock
*sk
)
623 write_lock_bh(&l
->lock
);
624 sk_del_node_init(sk
);
625 write_unlock_bh(&l
->lock
);
628 void iucv_accept_enqueue(struct sock
*parent
, struct sock
*sk
)
631 struct iucv_sock
*par
= iucv_sk(parent
);
634 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
635 list_add_tail(&iucv_sk(sk
)->accept_q
, &par
->accept_q
);
636 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
637 iucv_sk(sk
)->parent
= parent
;
638 sk_acceptq_added(parent
);
641 void iucv_accept_unlink(struct sock
*sk
)
644 struct iucv_sock
*par
= iucv_sk(iucv_sk(sk
)->parent
);
646 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
647 list_del_init(&iucv_sk(sk
)->accept_q
);
648 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
649 sk_acceptq_removed(iucv_sk(sk
)->parent
);
650 iucv_sk(sk
)->parent
= NULL
;
654 struct sock
*iucv_accept_dequeue(struct sock
*parent
, struct socket
*newsock
)
656 struct iucv_sock
*isk
, *n
;
659 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
660 sk
= (struct sock
*) isk
;
663 if (sk
->sk_state
== IUCV_CLOSED
) {
664 iucv_accept_unlink(sk
);
669 if (sk
->sk_state
== IUCV_CONNECTED
||
670 sk
->sk_state
== IUCV_DISCONN
||
672 iucv_accept_unlink(sk
);
674 sock_graft(sk
, newsock
);
685 static void __iucv_auto_name(struct iucv_sock
*iucv
)
689 sprintf(name
, "%08x", atomic_inc_return(&iucv_sk_list
.autobind_name
));
690 while (__iucv_get_sock_by_name(name
)) {
691 sprintf(name
, "%08x",
692 atomic_inc_return(&iucv_sk_list
.autobind_name
));
694 memcpy(iucv
->src_name
, name
, 8);
697 /* Bind an unbound socket */
698 static int iucv_sock_bind(struct socket
*sock
, struct sockaddr
*addr
,
701 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
702 struct sock
*sk
= sock
->sk
;
703 struct iucv_sock
*iucv
;
705 struct net_device
*dev
;
708 /* Verify the input sockaddr */
709 if (!addr
|| addr
->sa_family
!= AF_IUCV
)
713 if (sk
->sk_state
!= IUCV_OPEN
) {
718 write_lock_bh(&iucv_sk_list
.lock
);
721 if (__iucv_get_sock_by_name(sa
->siucv_name
)) {
728 /* Bind the socket */
730 if (!memcmp(sa
->siucv_user_id
, iucv_userid
, 8))
731 goto vm_bind
; /* VM IUCV transport */
733 /* try hiper transport */
734 memcpy(uid
, sa
->siucv_user_id
, sizeof(uid
));
737 for_each_netdev_rcu(&init_net
, dev
) {
738 if (!memcmp(dev
->perm_addr
, uid
, 8)) {
739 memcpy(iucv
->src_user_id
, sa
->siucv_user_id
, 8);
740 /* Check for unitialized siucv_name */
741 if (strncmp(sa
->siucv_name
, " ", 8) == 0)
742 __iucv_auto_name(iucv
);
744 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
745 sk
->sk_bound_dev_if
= dev
->ifindex
;
748 sk
->sk_state
= IUCV_BOUND
;
749 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
751 iucv
->msglimit
= IUCV_HIPER_MSGLIM_DEFAULT
;
759 /* use local userid for backward compat */
760 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
761 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
762 sk
->sk_state
= IUCV_BOUND
;
763 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
765 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
768 /* found no dev to bind */
771 /* Release the socket list lock */
772 write_unlock_bh(&iucv_sk_list
.lock
);
778 /* Automatically bind an unbound socket */
779 static int iucv_sock_autobind(struct sock
*sk
)
781 struct iucv_sock
*iucv
= iucv_sk(sk
);
784 if (unlikely(!pr_iucv
))
787 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
789 write_lock_bh(&iucv_sk_list
.lock
);
790 __iucv_auto_name(iucv
);
791 write_unlock_bh(&iucv_sk_list
.lock
);
794 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
799 static int afiucv_path_connect(struct socket
*sock
, struct sockaddr
*addr
)
801 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
802 struct sock
*sk
= sock
->sk
;
803 struct iucv_sock
*iucv
= iucv_sk(sk
);
804 unsigned char user_data
[16];
807 high_nmcpy(user_data
, sa
->siucv_name
);
808 low_nmcpy(user_data
, iucv
->src_name
);
809 ASCEBC(user_data
, sizeof(user_data
));
812 iucv
->path
= iucv_path_alloc(iucv
->msglimit
,
813 IUCV_IPRMDATA
, GFP_KERNEL
);
818 err
= pr_iucv
->path_connect(iucv
->path
, &af_iucv_handler
,
819 sa
->siucv_user_id
, NULL
, user_data
,
822 iucv_path_free(iucv
->path
);
825 case 0x0b: /* Target communicator is not logged on */
828 case 0x0d: /* Max connections for this guest exceeded */
829 case 0x0e: /* Max connections for target guest exceeded */
832 case 0x0f: /* Missing IUCV authorization */
844 /* Connect an unconnected socket */
845 static int iucv_sock_connect(struct socket
*sock
, struct sockaddr
*addr
,
848 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
849 struct sock
*sk
= sock
->sk
;
850 struct iucv_sock
*iucv
= iucv_sk(sk
);
853 if (addr
->sa_family
!= AF_IUCV
|| alen
< sizeof(struct sockaddr_iucv
))
856 if (sk
->sk_state
!= IUCV_OPEN
&& sk
->sk_state
!= IUCV_BOUND
)
859 if (sk
->sk_state
== IUCV_OPEN
&&
860 iucv
->transport
== AF_IUCV_TRANS_HIPER
)
861 return -EBADFD
; /* explicit bind required */
863 if (sk
->sk_type
!= SOCK_STREAM
&& sk
->sk_type
!= SOCK_SEQPACKET
)
866 if (sk
->sk_state
== IUCV_OPEN
) {
867 err
= iucv_sock_autobind(sk
);
874 /* Set the destination information */
875 memcpy(iucv
->dst_user_id
, sa
->siucv_user_id
, 8);
876 memcpy(iucv
->dst_name
, sa
->siucv_name
, 8);
878 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
879 err
= iucv_send_ctrl(sock
->sk
, AF_IUCV_FLAG_SYN
);
881 err
= afiucv_path_connect(sock
, addr
);
885 if (sk
->sk_state
!= IUCV_CONNECTED
)
886 err
= iucv_sock_wait(sk
, iucv_sock_in_state(sk
, IUCV_CONNECTED
,
888 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
890 if (sk
->sk_state
== IUCV_DISCONN
|| sk
->sk_state
== IUCV_CLOSED
)
893 if (err
&& iucv
->transport
== AF_IUCV_TRANS_IUCV
)
894 iucv_sever_path(sk
, 0);
901 /* Move a socket into listening state. */
902 static int iucv_sock_listen(struct socket
*sock
, int backlog
)
904 struct sock
*sk
= sock
->sk
;
910 if (sk
->sk_state
!= IUCV_BOUND
)
913 if (sock
->type
!= SOCK_STREAM
&& sock
->type
!= SOCK_SEQPACKET
)
916 sk
->sk_max_ack_backlog
= backlog
;
917 sk
->sk_ack_backlog
= 0;
918 sk
->sk_state
= IUCV_LISTEN
;
926 /* Accept a pending connection */
927 static int iucv_sock_accept(struct socket
*sock
, struct socket
*newsock
,
930 DECLARE_WAITQUEUE(wait
, current
);
931 struct sock
*sk
= sock
->sk
, *nsk
;
935 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
937 if (sk
->sk_state
!= IUCV_LISTEN
) {
942 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
944 /* Wait for an incoming connection */
945 add_wait_queue_exclusive(sk_sleep(sk
), &wait
);
946 while (!(nsk
= iucv_accept_dequeue(sk
, newsock
))) {
947 set_current_state(TASK_INTERRUPTIBLE
);
954 timeo
= schedule_timeout(timeo
);
955 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
957 if (sk
->sk_state
!= IUCV_LISTEN
) {
962 if (signal_pending(current
)) {
963 err
= sock_intr_errno(timeo
);
968 set_current_state(TASK_RUNNING
);
969 remove_wait_queue(sk_sleep(sk
), &wait
);
974 newsock
->state
= SS_CONNECTED
;
981 static int iucv_sock_getname(struct socket
*sock
, struct sockaddr
*addr
,
984 struct sockaddr_iucv
*siucv
= (struct sockaddr_iucv
*) addr
;
985 struct sock
*sk
= sock
->sk
;
986 struct iucv_sock
*iucv
= iucv_sk(sk
);
988 addr
->sa_family
= AF_IUCV
;
989 *len
= sizeof(struct sockaddr_iucv
);
992 memcpy(siucv
->siucv_user_id
, iucv
->dst_user_id
, 8);
993 memcpy(siucv
->siucv_name
, iucv
->dst_name
, 8);
995 memcpy(siucv
->siucv_user_id
, iucv
->src_user_id
, 8);
996 memcpy(siucv
->siucv_name
, iucv
->src_name
, 8);
998 memset(&siucv
->siucv_port
, 0, sizeof(siucv
->siucv_port
));
999 memset(&siucv
->siucv_addr
, 0, sizeof(siucv
->siucv_addr
));
1000 memset(&siucv
->siucv_nodeid
, 0, sizeof(siucv
->siucv_nodeid
));
1006 * iucv_send_iprm() - Send socket data in parameter list of an iucv message.
1008 * @msg: Pointer to a struct iucv_message
1009 * @skb: The socket data to send, skb->len MUST BE <= 7
1011 * Send the socket data in the parameter list in the iucv message
1012 * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter
1013 * list and the socket data len at index 7 (last byte).
1014 * See also iucv_msg_length().
1016 * Returns the error code from the iucv_message_send() call.
1018 static int iucv_send_iprm(struct iucv_path
*path
, struct iucv_message
*msg
,
1019 struct sk_buff
*skb
)
1023 memcpy(prmdata
, (void *) skb
->data
, skb
->len
);
1024 prmdata
[7] = 0xff - (u8
) skb
->len
;
1025 return pr_iucv
->message_send(path
, msg
, IUCV_IPRMDATA
, 0,
1026 (void *) prmdata
, 8);
1029 static int iucv_sock_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
1030 struct msghdr
*msg
, size_t len
)
1032 struct sock
*sk
= sock
->sk
;
1033 struct iucv_sock
*iucv
= iucv_sk(sk
);
1034 struct sk_buff
*skb
;
1035 struct iucv_message txmsg
;
1036 struct cmsghdr
*cmsg
;
1042 int noblock
= msg
->msg_flags
& MSG_DONTWAIT
;
1044 err
= sock_error(sk
);
1048 if (msg
->msg_flags
& MSG_OOB
)
1051 /* SOCK_SEQPACKET: we do not support segmented records */
1052 if (sk
->sk_type
== SOCK_SEQPACKET
&& !(msg
->msg_flags
& MSG_EOR
))
1057 if (sk
->sk_shutdown
& SEND_SHUTDOWN
) {
1062 /* Return if the socket is not in connected state */
1063 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1068 /* initialize defaults */
1069 cmsg_done
= 0; /* check for duplicate headers */
1072 /* iterate over control messages */
1073 for_each_cmsghdr(cmsg
, msg
) {
1074 if (!CMSG_OK(msg
, cmsg
)) {
1079 if (cmsg
->cmsg_level
!= SOL_IUCV
)
1082 if (cmsg
->cmsg_type
& cmsg_done
) {
1086 cmsg_done
|= cmsg
->cmsg_type
;
1088 switch (cmsg
->cmsg_type
) {
1089 case SCM_IUCV_TRGCLS
:
1090 if (cmsg
->cmsg_len
!= CMSG_LEN(TRGCLS_SIZE
)) {
1095 /* set iucv message target class */
1096 memcpy(&txmsg
.class,
1097 (void *) CMSG_DATA(cmsg
), TRGCLS_SIZE
);
1107 /* allocate one skb for each iucv message:
1108 * this is fine for SOCK_SEQPACKET (unless we want to support
1109 * segmented records using the MSG_EOR flag), but
1110 * for SOCK_STREAM we might want to improve it in future */
1111 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
1112 skb
= sock_alloc_send_skb(sk
,
1113 len
+ sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
,
1116 skb
= sock_alloc_send_skb(sk
, len
, noblock
, &err
);
1121 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
1122 skb_reserve(skb
, sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
);
1123 if (memcpy_from_msg(skb_put(skb
, len
), msg
, len
)) {
1128 /* wait if outstanding messages for iucv path has reached */
1129 timeo
= sock_sndtimeo(sk
, noblock
);
1130 err
= iucv_sock_wait(sk
, iucv_below_msglim(sk
), timeo
);
1134 /* return -ECONNRESET if the socket is no longer connected */
1135 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1140 /* increment and save iucv message tag for msg_completion cbk */
1141 txmsg
.tag
= iucv
->send_tag
++;
1142 IUCV_SKB_CB(skb
)->tag
= txmsg
.tag
;
1144 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1145 atomic_inc(&iucv
->msg_sent
);
1146 err
= afiucv_hs_send(&txmsg
, sk
, skb
, 0);
1148 atomic_dec(&iucv
->msg_sent
);
1153 skb_queue_tail(&iucv
->send_skb_q
, skb
);
1155 if (((iucv
->path
->flags
& IUCV_IPRMDATA
) & iucv
->flags
)
1157 err
= iucv_send_iprm(iucv
->path
, &txmsg
, skb
);
1159 /* on success: there is no message_complete callback
1160 * for an IPRMDATA msg; remove skb from send queue */
1162 skb_unlink(skb
, &iucv
->send_skb_q
);
1166 /* this error should never happen since the
1167 * IUCV_IPRMDATA path flag is set... sever path */
1169 pr_iucv
->path_sever(iucv
->path
, NULL
);
1170 skb_unlink(skb
, &iucv
->send_skb_q
);
1175 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
, 0, 0,
1176 (void *) skb
->data
, skb
->len
);
1180 memcpy(user_id
, iucv
->dst_user_id
, 8);
1182 memcpy(appl_id
, iucv
->dst_name
, 8);
1183 pr_err("Application %s on z/VM guest %s"
1184 " exceeds message limit\n",
1189 skb_unlink(skb
, &iucv
->send_skb_q
);
1204 /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's
1206 * Locking: must be called with message_q.lock held
1208 static int iucv_fragment_skb(struct sock
*sk
, struct sk_buff
*skb
, int len
)
1210 int dataleft
, size
, copied
= 0;
1211 struct sk_buff
*nskb
;
1215 if (dataleft
>= sk
->sk_rcvbuf
/ 4)
1216 size
= sk
->sk_rcvbuf
/ 4;
1220 nskb
= alloc_skb(size
, GFP_ATOMIC
| GFP_DMA
);
1224 /* copy target class to control buffer of new skb */
1225 IUCV_SKB_CB(nskb
)->class = IUCV_SKB_CB(skb
)->class;
1227 /* copy data fragment */
1228 memcpy(nskb
->data
, skb
->data
+ copied
, size
);
1232 skb_reset_transport_header(nskb
);
1233 skb_reset_network_header(nskb
);
1236 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, nskb
);
1242 /* iucv_process_message() - Receive a single outstanding IUCV message
1244 * Locking: must be called with message_q.lock held
1246 static void iucv_process_message(struct sock
*sk
, struct sk_buff
*skb
,
1247 struct iucv_path
*path
,
1248 struct iucv_message
*msg
)
1253 len
= iucv_msg_length(msg
);
1255 /* store msg target class in the second 4 bytes of skb ctrl buffer */
1256 /* Note: the first 4 bytes are reserved for msg tag */
1257 IUCV_SKB_CB(skb
)->class = msg
->class;
1259 /* check for special IPRM messages (e.g. iucv_sock_shutdown) */
1260 if ((msg
->flags
& IUCV_IPRMDATA
) && len
> 7) {
1261 if (memcmp(msg
->rmmsg
, iprm_shutdown
, 8) == 0) {
1266 rc
= pr_iucv
->message_receive(path
, msg
,
1267 msg
->flags
& IUCV_IPRMDATA
,
1268 skb
->data
, len
, NULL
);
1273 /* we need to fragment iucv messages for SOCK_STREAM only;
1274 * for SOCK_SEQPACKET, it is only relevant if we support
1275 * record segmentation using MSG_EOR (see also recvmsg()) */
1276 if (sk
->sk_type
== SOCK_STREAM
&&
1277 skb
->truesize
>= sk
->sk_rcvbuf
/ 4) {
1278 rc
= iucv_fragment_skb(sk
, skb
, len
);
1282 pr_iucv
->path_sever(path
, NULL
);
1285 skb
= skb_dequeue(&iucv_sk(sk
)->backlog_skb_q
);
1287 skb_reset_transport_header(skb
);
1288 skb_reset_network_header(skb
);
1293 IUCV_SKB_CB(skb
)->offset
= 0;
1294 if (sock_queue_rcv_skb(sk
, skb
))
1295 skb_queue_head(&iucv_sk(sk
)->backlog_skb_q
, skb
);
1298 /* iucv_process_message_q() - Process outstanding IUCV messages
1300 * Locking: must be called with message_q.lock held
1302 static void iucv_process_message_q(struct sock
*sk
)
1304 struct iucv_sock
*iucv
= iucv_sk(sk
);
1305 struct sk_buff
*skb
;
1306 struct sock_msg_q
*p
, *n
;
1308 list_for_each_entry_safe(p
, n
, &iucv
->message_q
.list
, list
) {
1309 skb
= alloc_skb(iucv_msg_length(&p
->msg
), GFP_ATOMIC
| GFP_DMA
);
1312 iucv_process_message(sk
, skb
, p
->path
, &p
->msg
);
1315 if (!skb_queue_empty(&iucv
->backlog_skb_q
))
1320 static int iucv_sock_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
1321 struct msghdr
*msg
, size_t len
, int flags
)
1323 int noblock
= flags
& MSG_DONTWAIT
;
1324 struct sock
*sk
= sock
->sk
;
1325 struct iucv_sock
*iucv
= iucv_sk(sk
);
1326 unsigned int copied
, rlen
;
1327 struct sk_buff
*skb
, *rskb
, *cskb
;
1331 if ((sk
->sk_state
== IUCV_DISCONN
) &&
1332 skb_queue_empty(&iucv
->backlog_skb_q
) &&
1333 skb_queue_empty(&sk
->sk_receive_queue
) &&
1334 list_empty(&iucv
->message_q
.list
))
1337 if (flags
& (MSG_OOB
))
1340 /* receive/dequeue next skb:
1341 * the function understands MSG_PEEK and, thus, does not dequeue skb */
1342 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
1344 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1349 offset
= IUCV_SKB_CB(skb
)->offset
;
1350 rlen
= skb
->len
- offset
; /* real length of skb */
1351 copied
= min_t(unsigned int, rlen
, len
);
1353 sk
->sk_shutdown
= sk
->sk_shutdown
| RCV_SHUTDOWN
;
1356 if (skb_copy_datagram_msg(cskb
, offset
, msg
, copied
)) {
1357 if (!(flags
& MSG_PEEK
))
1358 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1362 /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */
1363 if (sk
->sk_type
== SOCK_SEQPACKET
) {
1365 msg
->msg_flags
|= MSG_TRUNC
;
1366 /* each iucv message contains a complete record */
1367 msg
->msg_flags
|= MSG_EOR
;
1370 /* create control message to store iucv msg target class:
1371 * get the trgcls from the control buffer of the skb due to
1372 * fragmentation of original iucv message. */
1373 err
= put_cmsg(msg
, SOL_IUCV
, SCM_IUCV_TRGCLS
,
1374 sizeof(IUCV_SKB_CB(skb
)->class),
1375 (void *)&IUCV_SKB_CB(skb
)->class);
1377 if (!(flags
& MSG_PEEK
))
1378 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1382 /* Mark read part of skb as used */
1383 if (!(flags
& MSG_PEEK
)) {
1385 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
1386 if (sk
->sk_type
== SOCK_STREAM
) {
1387 if (copied
< rlen
) {
1388 IUCV_SKB_CB(skb
)->offset
= offset
+ copied
;
1389 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1395 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1396 atomic_inc(&iucv
->msg_recv
);
1397 if (atomic_read(&iucv
->msg_recv
) > iucv
->msglimit
) {
1399 iucv_sock_close(sk
);
1404 /* Queue backlog skbs */
1405 spin_lock_bh(&iucv
->message_q
.lock
);
1406 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1408 IUCV_SKB_CB(rskb
)->offset
= 0;
1409 if (sock_queue_rcv_skb(sk
, rskb
)) {
1410 skb_queue_head(&iucv
->backlog_skb_q
,
1414 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1417 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
1418 if (!list_empty(&iucv
->message_q
.list
))
1419 iucv_process_message_q(sk
);
1420 if (atomic_read(&iucv
->msg_recv
) >=
1421 iucv
->msglimit
/ 2) {
1422 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_WIN
);
1424 sk
->sk_state
= IUCV_DISCONN
;
1425 sk
->sk_state_change(sk
);
1429 spin_unlock_bh(&iucv
->message_q
.lock
);
1433 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
1434 if (sk
->sk_type
== SOCK_SEQPACKET
&& (flags
& MSG_TRUNC
))
1440 static inline unsigned int iucv_accept_poll(struct sock
*parent
)
1442 struct iucv_sock
*isk
, *n
;
1445 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
1446 sk
= (struct sock
*) isk
;
1448 if (sk
->sk_state
== IUCV_CONNECTED
)
1449 return POLLIN
| POLLRDNORM
;
1455 unsigned int iucv_sock_poll(struct file
*file
, struct socket
*sock
,
1458 struct sock
*sk
= sock
->sk
;
1459 unsigned int mask
= 0;
1461 sock_poll_wait(file
, sk_sleep(sk
), wait
);
1463 if (sk
->sk_state
== IUCV_LISTEN
)
1464 return iucv_accept_poll(sk
);
1466 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
))
1468 (sock_flag(sk
, SOCK_SELECT_ERR_QUEUE
) ? POLLPRI
: 0);
1470 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1473 if (sk
->sk_shutdown
== SHUTDOWN_MASK
)
1476 if (!skb_queue_empty(&sk
->sk_receive_queue
) ||
1477 (sk
->sk_shutdown
& RCV_SHUTDOWN
))
1478 mask
|= POLLIN
| POLLRDNORM
;
1480 if (sk
->sk_state
== IUCV_CLOSED
)
1483 if (sk
->sk_state
== IUCV_DISCONN
)
1486 if (sock_writeable(sk
) && iucv_below_msglim(sk
))
1487 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
1489 set_bit(SOCK_ASYNC_NOSPACE
, &sk
->sk_socket
->flags
);
1494 static int iucv_sock_shutdown(struct socket
*sock
, int how
)
1496 struct sock
*sk
= sock
->sk
;
1497 struct iucv_sock
*iucv
= iucv_sk(sk
);
1498 struct iucv_message txmsg
;
1503 if ((how
& ~SHUTDOWN_MASK
) || !how
)
1507 switch (sk
->sk_state
) {
1518 if (how
== SEND_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1519 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
) {
1522 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1523 IUCV_IPRMDATA
, 0, (void *) iprm_shutdown
, 8);
1538 iucv_send_ctrl(sk
, AF_IUCV_FLAG_SHT
);
1541 sk
->sk_shutdown
|= how
;
1542 if (how
== RCV_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1543 if ((iucv
->transport
== AF_IUCV_TRANS_IUCV
) &&
1545 err
= pr_iucv
->path_quiesce(iucv
->path
, NULL
);
1548 /* skb_queue_purge(&sk->sk_receive_queue); */
1550 skb_queue_purge(&sk
->sk_receive_queue
);
1553 /* Wake up anyone sleeping in poll */
1554 sk
->sk_state_change(sk
);
1561 static int iucv_sock_release(struct socket
*sock
)
1563 struct sock
*sk
= sock
->sk
;
1569 iucv_sock_close(sk
);
1576 /* getsockopt and setsockopt */
1577 static int iucv_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
1578 char __user
*optval
, unsigned int optlen
)
1580 struct sock
*sk
= sock
->sk
;
1581 struct iucv_sock
*iucv
= iucv_sk(sk
);
1585 if (level
!= SOL_IUCV
)
1586 return -ENOPROTOOPT
;
1588 if (optlen
< sizeof(int))
1591 if (get_user(val
, (int __user
*) optval
))
1598 case SO_IPRMDATA_MSG
:
1600 iucv
->flags
|= IUCV_IPRMDATA
;
1602 iucv
->flags
&= ~IUCV_IPRMDATA
;
1605 switch (sk
->sk_state
) {
1608 if (val
< 1 || val
> (u16
)(~0))
1611 iucv
->msglimit
= val
;
1627 static int iucv_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
1628 char __user
*optval
, int __user
*optlen
)
1630 struct sock
*sk
= sock
->sk
;
1631 struct iucv_sock
*iucv
= iucv_sk(sk
);
1635 if (level
!= SOL_IUCV
)
1636 return -ENOPROTOOPT
;
1638 if (get_user(len
, optlen
))
1644 len
= min_t(unsigned int, len
, sizeof(int));
1647 case SO_IPRMDATA_MSG
:
1648 val
= (iucv
->flags
& IUCV_IPRMDATA
) ? 1 : 0;
1652 val
= (iucv
->path
!= NULL
) ? iucv
->path
->msglim
/* connected */
1653 : iucv
->msglimit
; /* default */
1657 if (sk
->sk_state
== IUCV_OPEN
)
1659 val
= (iucv
->hs_dev
) ? iucv
->hs_dev
->mtu
-
1660 sizeof(struct af_iucv_trans_hdr
) - ETH_HLEN
:
1664 return -ENOPROTOOPT
;
1667 if (put_user(len
, optlen
))
1669 if (copy_to_user(optval
, &val
, len
))
1676 /* Callback wrappers - called from iucv base support */
1677 static int iucv_callback_connreq(struct iucv_path
*path
,
1678 u8 ipvmid
[8], u8 ipuser
[16])
1680 unsigned char user_data
[16];
1681 unsigned char nuser_data
[16];
1682 unsigned char src_name
[8];
1683 struct sock
*sk
, *nsk
;
1684 struct iucv_sock
*iucv
, *niucv
;
1687 memcpy(src_name
, ipuser
, 8);
1688 EBCASC(src_name
, 8);
1689 /* Find out if this path belongs to af_iucv. */
1690 read_lock(&iucv_sk_list
.lock
);
1693 sk_for_each(sk
, &iucv_sk_list
.head
)
1694 if (sk
->sk_state
== IUCV_LISTEN
&&
1695 !memcmp(&iucv_sk(sk
)->src_name
, src_name
, 8)) {
1697 * Found a listening socket with
1698 * src_name == ipuser[0-7].
1703 read_unlock(&iucv_sk_list
.lock
);
1705 /* No socket found, not one of our paths. */
1710 /* Check if parent socket is listening */
1711 low_nmcpy(user_data
, iucv
->src_name
);
1712 high_nmcpy(user_data
, iucv
->dst_name
);
1713 ASCEBC(user_data
, sizeof(user_data
));
1714 if (sk
->sk_state
!= IUCV_LISTEN
) {
1715 err
= pr_iucv
->path_sever(path
, user_data
);
1716 iucv_path_free(path
);
1720 /* Check for backlog size */
1721 if (sk_acceptq_is_full(sk
)) {
1722 err
= pr_iucv
->path_sever(path
, user_data
);
1723 iucv_path_free(path
);
1727 /* Create the new socket */
1728 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
);
1730 err
= pr_iucv
->path_sever(path
, user_data
);
1731 iucv_path_free(path
);
1735 niucv
= iucv_sk(nsk
);
1736 iucv_sock_init(nsk
, sk
);
1738 /* Set the new iucv_sock */
1739 memcpy(niucv
->dst_name
, ipuser
+ 8, 8);
1740 EBCASC(niucv
->dst_name
, 8);
1741 memcpy(niucv
->dst_user_id
, ipvmid
, 8);
1742 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1743 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1746 /* Call iucv_accept */
1747 high_nmcpy(nuser_data
, ipuser
+ 8);
1748 memcpy(nuser_data
+ 8, niucv
->src_name
, 8);
1749 ASCEBC(nuser_data
+ 8, 8);
1751 /* set message limit for path based on msglimit of accepting socket */
1752 niucv
->msglimit
= iucv
->msglimit
;
1753 path
->msglim
= iucv
->msglimit
;
1754 err
= pr_iucv
->path_accept(path
, &af_iucv_handler
, nuser_data
, nsk
);
1756 iucv_sever_path(nsk
, 1);
1757 iucv_sock_kill(nsk
);
1761 iucv_accept_enqueue(sk
, nsk
);
1763 /* Wake up accept */
1764 nsk
->sk_state
= IUCV_CONNECTED
;
1765 sk
->sk_data_ready(sk
);
1772 static void iucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
1774 struct sock
*sk
= path
->private;
1776 sk
->sk_state
= IUCV_CONNECTED
;
1777 sk
->sk_state_change(sk
);
1780 static void iucv_callback_rx(struct iucv_path
*path
, struct iucv_message
*msg
)
1782 struct sock
*sk
= path
->private;
1783 struct iucv_sock
*iucv
= iucv_sk(sk
);
1784 struct sk_buff
*skb
;
1785 struct sock_msg_q
*save_msg
;
1788 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
1789 pr_iucv
->message_reject(path
, msg
);
1793 spin_lock(&iucv
->message_q
.lock
);
1795 if (!list_empty(&iucv
->message_q
.list
) ||
1796 !skb_queue_empty(&iucv
->backlog_skb_q
))
1799 len
= atomic_read(&sk
->sk_rmem_alloc
);
1800 len
+= SKB_TRUESIZE(iucv_msg_length(msg
));
1801 if (len
> sk
->sk_rcvbuf
)
1804 skb
= alloc_skb(iucv_msg_length(msg
), GFP_ATOMIC
| GFP_DMA
);
1808 iucv_process_message(sk
, skb
, path
, msg
);
1812 save_msg
= kzalloc(sizeof(struct sock_msg_q
), GFP_ATOMIC
| GFP_DMA
);
1815 save_msg
->path
= path
;
1816 save_msg
->msg
= *msg
;
1818 list_add_tail(&save_msg
->list
, &iucv
->message_q
.list
);
1821 spin_unlock(&iucv
->message_q
.lock
);
1824 static void iucv_callback_txdone(struct iucv_path
*path
,
1825 struct iucv_message
*msg
)
1827 struct sock
*sk
= path
->private;
1828 struct sk_buff
*this = NULL
;
1829 struct sk_buff_head
*list
= &iucv_sk(sk
)->send_skb_q
;
1830 struct sk_buff
*list_skb
= list
->next
;
1831 unsigned long flags
;
1834 if (!skb_queue_empty(list
)) {
1835 spin_lock_irqsave(&list
->lock
, flags
);
1837 while (list_skb
!= (struct sk_buff
*)list
) {
1838 if (msg
->tag
== IUCV_SKB_CB(list_skb
)->tag
) {
1842 list_skb
= list_skb
->next
;
1845 __skb_unlink(this, list
);
1847 spin_unlock_irqrestore(&list
->lock
, flags
);
1851 /* wake up any process waiting for sending */
1852 iucv_sock_wake_msglim(sk
);
1856 if (sk
->sk_state
== IUCV_CLOSING
) {
1857 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
1858 sk
->sk_state
= IUCV_CLOSED
;
1859 sk
->sk_state_change(sk
);
1866 static void iucv_callback_connrej(struct iucv_path
*path
, u8 ipuser
[16])
1868 struct sock
*sk
= path
->private;
1870 if (sk
->sk_state
== IUCV_CLOSED
)
1874 iucv_sever_path(sk
, 1);
1875 sk
->sk_state
= IUCV_DISCONN
;
1877 sk
->sk_state_change(sk
);
1881 /* called if the other communication side shuts down its RECV direction;
1882 * in turn, the callback sets SEND_SHUTDOWN to disable sending of data.
1884 static void iucv_callback_shutdown(struct iucv_path
*path
, u8 ipuser
[16])
1886 struct sock
*sk
= path
->private;
1889 if (sk
->sk_state
!= IUCV_CLOSED
) {
1890 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
1891 sk
->sk_state_change(sk
);
1896 /***************** HiperSockets transport callbacks ********************/
1897 static void afiucv_swap_src_dest(struct sk_buff
*skb
)
1899 struct af_iucv_trans_hdr
*trans_hdr
=
1900 (struct af_iucv_trans_hdr
*)skb
->data
;
1904 ASCEBC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
1905 ASCEBC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
1906 ASCEBC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
1907 ASCEBC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
1908 memcpy(tmpID
, trans_hdr
->srcUserID
, 8);
1909 memcpy(tmpName
, trans_hdr
->srcAppName
, 8);
1910 memcpy(trans_hdr
->srcUserID
, trans_hdr
->destUserID
, 8);
1911 memcpy(trans_hdr
->srcAppName
, trans_hdr
->destAppName
, 8);
1912 memcpy(trans_hdr
->destUserID
, tmpID
, 8);
1913 memcpy(trans_hdr
->destAppName
, tmpName
, 8);
1914 skb_push(skb
, ETH_HLEN
);
1915 memset(skb
->data
, 0, ETH_HLEN
);
1919 * afiucv_hs_callback_syn - react on received SYN
1921 static int afiucv_hs_callback_syn(struct sock
*sk
, struct sk_buff
*skb
)
1924 struct iucv_sock
*iucv
, *niucv
;
1925 struct af_iucv_trans_hdr
*trans_hdr
;
1929 trans_hdr
= (struct af_iucv_trans_hdr
*)skb
->data
;
1931 /* no sock - connection refused */
1932 afiucv_swap_src_dest(skb
);
1933 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
1934 err
= dev_queue_xmit(skb
);
1938 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
);
1940 if ((sk
->sk_state
!= IUCV_LISTEN
) ||
1941 sk_acceptq_is_full(sk
) ||
1943 /* error on server socket - connection refused */
1944 afiucv_swap_src_dest(skb
);
1945 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
1946 err
= dev_queue_xmit(skb
);
1947 iucv_sock_kill(nsk
);
1952 niucv
= iucv_sk(nsk
);
1953 iucv_sock_init(nsk
, sk
);
1954 niucv
->transport
= AF_IUCV_TRANS_HIPER
;
1955 niucv
->msglimit
= iucv
->msglimit
;
1956 if (!trans_hdr
->window
)
1957 niucv
->msglimit_peer
= IUCV_HIPER_MSGLIM_DEFAULT
;
1959 niucv
->msglimit_peer
= trans_hdr
->window
;
1960 memcpy(niucv
->dst_name
, trans_hdr
->srcAppName
, 8);
1961 memcpy(niucv
->dst_user_id
, trans_hdr
->srcUserID
, 8);
1962 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1963 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1964 nsk
->sk_bound_dev_if
= sk
->sk_bound_dev_if
;
1965 niucv
->hs_dev
= iucv
->hs_dev
;
1966 dev_hold(niucv
->hs_dev
);
1967 afiucv_swap_src_dest(skb
);
1968 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
;
1969 trans_hdr
->window
= niucv
->msglimit
;
1970 /* if receiver acks the xmit connection is established */
1971 err
= dev_queue_xmit(skb
);
1973 iucv_accept_enqueue(sk
, nsk
);
1974 nsk
->sk_state
= IUCV_CONNECTED
;
1975 sk
->sk_data_ready(sk
);
1977 iucv_sock_kill(nsk
);
1981 return NET_RX_SUCCESS
;
1985 * afiucv_hs_callback_synack() - react on received SYN-ACK
1987 static int afiucv_hs_callback_synack(struct sock
*sk
, struct sk_buff
*skb
)
1989 struct iucv_sock
*iucv
= iucv_sk(sk
);
1990 struct af_iucv_trans_hdr
*trans_hdr
=
1991 (struct af_iucv_trans_hdr
*)skb
->data
;
1995 if (sk
->sk_state
!= IUCV_BOUND
)
1998 iucv
->msglimit_peer
= trans_hdr
->window
;
1999 sk
->sk_state
= IUCV_CONNECTED
;
2000 sk
->sk_state_change(sk
);
2004 return NET_RX_SUCCESS
;
2008 * afiucv_hs_callback_synfin() - react on received SYN_FIN
2010 static int afiucv_hs_callback_synfin(struct sock
*sk
, struct sk_buff
*skb
)
2012 struct iucv_sock
*iucv
= iucv_sk(sk
);
2016 if (sk
->sk_state
!= IUCV_BOUND
)
2019 sk
->sk_state
= IUCV_DISCONN
;
2020 sk
->sk_state_change(sk
);
2024 return NET_RX_SUCCESS
;
2028 * afiucv_hs_callback_fin() - react on received FIN
2030 static int afiucv_hs_callback_fin(struct sock
*sk
, struct sk_buff
*skb
)
2032 struct iucv_sock
*iucv
= iucv_sk(sk
);
2034 /* other end of connection closed */
2038 if (sk
->sk_state
== IUCV_CONNECTED
) {
2039 sk
->sk_state
= IUCV_DISCONN
;
2040 sk
->sk_state_change(sk
);
2045 return NET_RX_SUCCESS
;
2049 * afiucv_hs_callback_win() - react on received WIN
2051 static int afiucv_hs_callback_win(struct sock
*sk
, struct sk_buff
*skb
)
2053 struct iucv_sock
*iucv
= iucv_sk(sk
);
2054 struct af_iucv_trans_hdr
*trans_hdr
=
2055 (struct af_iucv_trans_hdr
*)skb
->data
;
2058 return NET_RX_SUCCESS
;
2060 if (sk
->sk_state
!= IUCV_CONNECTED
)
2061 return NET_RX_SUCCESS
;
2063 atomic_sub(trans_hdr
->window
, &iucv
->msg_sent
);
2064 iucv_sock_wake_msglim(sk
);
2065 return NET_RX_SUCCESS
;
2069 * afiucv_hs_callback_rx() - react on received data
2071 static int afiucv_hs_callback_rx(struct sock
*sk
, struct sk_buff
*skb
)
2073 struct iucv_sock
*iucv
= iucv_sk(sk
);
2077 return NET_RX_SUCCESS
;
2080 if (sk
->sk_state
!= IUCV_CONNECTED
) {
2082 return NET_RX_SUCCESS
;
2085 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
2087 return NET_RX_SUCCESS
;
2090 /* write stuff from iucv_msg to skb cb */
2091 if (skb
->len
< sizeof(struct af_iucv_trans_hdr
)) {
2093 return NET_RX_SUCCESS
;
2095 skb_pull(skb
, sizeof(struct af_iucv_trans_hdr
));
2096 skb_reset_transport_header(skb
);
2097 skb_reset_network_header(skb
);
2098 IUCV_SKB_CB(skb
)->offset
= 0;
2099 spin_lock(&iucv
->message_q
.lock
);
2100 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
2101 if (sock_queue_rcv_skb(sk
, skb
)) {
2102 /* handle rcv queue full */
2103 skb_queue_tail(&iucv
->backlog_skb_q
, skb
);
2106 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, skb
);
2107 spin_unlock(&iucv
->message_q
.lock
);
2108 return NET_RX_SUCCESS
;
2112 * afiucv_hs_rcv() - base function for arriving data through HiperSockets
2114 * called from netif RX softirq
2116 static int afiucv_hs_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
2117 struct packet_type
*pt
, struct net_device
*orig_dev
)
2120 struct iucv_sock
*iucv
;
2121 struct af_iucv_trans_hdr
*trans_hdr
;
2125 skb_pull(skb
, ETH_HLEN
);
2126 trans_hdr
= (struct af_iucv_trans_hdr
*)skb
->data
;
2127 EBCASC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
2128 EBCASC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
2129 EBCASC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
2130 EBCASC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
2131 memset(nullstring
, 0, sizeof(nullstring
));
2134 read_lock(&iucv_sk_list
.lock
);
2135 sk_for_each(sk
, &iucv_sk_list
.head
) {
2136 if (trans_hdr
->flags
== AF_IUCV_FLAG_SYN
) {
2137 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2138 trans_hdr
->destAppName
, 8)) &&
2139 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2140 trans_hdr
->destUserID
, 8)) &&
2141 (!memcmp(&iucv_sk(sk
)->dst_name
, nullstring
, 8)) &&
2142 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2148 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2149 trans_hdr
->destAppName
, 8)) &&
2150 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2151 trans_hdr
->destUserID
, 8)) &&
2152 (!memcmp(&iucv_sk(sk
)->dst_name
,
2153 trans_hdr
->srcAppName
, 8)) &&
2154 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2155 trans_hdr
->srcUserID
, 8))) {
2161 read_unlock(&iucv_sk_list
.lock
);
2166 how should we send with no sock
2167 1) send without sock no send rc checking?
2168 2) introduce default sock to handle this cases
2170 SYN -> send SYN|ACK in good case, send SYN|FIN in bad case
2172 SYN|ACK, SYN|FIN, FIN -> no action? */
2174 switch (trans_hdr
->flags
) {
2175 case AF_IUCV_FLAG_SYN
:
2176 /* connect request */
2177 err
= afiucv_hs_callback_syn(sk
, skb
);
2179 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
):
2180 /* connect request confirmed */
2181 err
= afiucv_hs_callback_synack(sk
, skb
);
2183 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
):
2184 /* connect request refused */
2185 err
= afiucv_hs_callback_synfin(sk
, skb
);
2187 case (AF_IUCV_FLAG_FIN
):
2189 err
= afiucv_hs_callback_fin(sk
, skb
);
2191 case (AF_IUCV_FLAG_WIN
):
2192 err
= afiucv_hs_callback_win(sk
, skb
);
2193 if (skb
->len
== sizeof(struct af_iucv_trans_hdr
)) {
2197 /* fall through and receive non-zero length data */
2198 case (AF_IUCV_FLAG_SHT
):
2199 /* shutdown request */
2200 /* fall through and receive zero length data */
2202 /* plain data frame */
2203 IUCV_SKB_CB(skb
)->class = trans_hdr
->iucv_hdr
.class;
2204 err
= afiucv_hs_callback_rx(sk
, skb
);
2214 * afiucv_hs_callback_txnotify() - handle send notifcations from HiperSockets
2217 static void afiucv_hs_callback_txnotify(struct sk_buff
*skb
,
2218 enum iucv_tx_notify n
)
2220 struct sock
*isk
= skb
->sk
;
2221 struct sock
*sk
= NULL
;
2222 struct iucv_sock
*iucv
= NULL
;
2223 struct sk_buff_head
*list
;
2224 struct sk_buff
*list_skb
;
2225 struct sk_buff
*nskb
;
2226 unsigned long flags
;
2228 read_lock_irqsave(&iucv_sk_list
.lock
, flags
);
2229 sk_for_each(sk
, &iucv_sk_list
.head
)
2234 read_unlock_irqrestore(&iucv_sk_list
.lock
, flags
);
2236 if (!iucv
|| sock_flag(sk
, SOCK_ZAPPED
))
2239 list
= &iucv
->send_skb_q
;
2240 spin_lock_irqsave(&list
->lock
, flags
);
2241 if (skb_queue_empty(list
))
2243 list_skb
= list
->next
;
2244 nskb
= list_skb
->next
;
2245 while (list_skb
!= (struct sk_buff
*)list
) {
2246 if (skb_shinfo(list_skb
) == skb_shinfo(skb
)) {
2249 __skb_unlink(list_skb
, list
);
2250 kfree_skb(list_skb
);
2251 iucv_sock_wake_msglim(sk
);
2253 case TX_NOTIFY_PENDING
:
2254 atomic_inc(&iucv
->pendings
);
2256 case TX_NOTIFY_DELAYED_OK
:
2257 __skb_unlink(list_skb
, list
);
2258 atomic_dec(&iucv
->pendings
);
2259 if (atomic_read(&iucv
->pendings
) <= 0)
2260 iucv_sock_wake_msglim(sk
);
2261 kfree_skb(list_skb
);
2263 case TX_NOTIFY_UNREACHABLE
:
2264 case TX_NOTIFY_DELAYED_UNREACHABLE
:
2265 case TX_NOTIFY_TPQFULL
: /* not yet used */
2266 case TX_NOTIFY_GENERALERROR
:
2267 case TX_NOTIFY_DELAYED_GENERALERROR
:
2268 __skb_unlink(list_skb
, list
);
2269 kfree_skb(list_skb
);
2270 if (sk
->sk_state
== IUCV_CONNECTED
) {
2271 sk
->sk_state
= IUCV_DISCONN
;
2272 sk
->sk_state_change(sk
);
2282 spin_unlock_irqrestore(&list
->lock
, flags
);
2284 if (sk
->sk_state
== IUCV_CLOSING
) {
2285 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
2286 sk
->sk_state
= IUCV_CLOSED
;
2287 sk
->sk_state_change(sk
);
2294 * afiucv_netdev_event: handle netdev notifier chain events
2296 static int afiucv_netdev_event(struct notifier_block
*this,
2297 unsigned long event
, void *ptr
)
2299 struct net_device
*event_dev
= netdev_notifier_info_to_dev(ptr
);
2301 struct iucv_sock
*iucv
;
2305 case NETDEV_GOING_DOWN
:
2306 sk_for_each(sk
, &iucv_sk_list
.head
) {
2308 if ((iucv
->hs_dev
== event_dev
) &&
2309 (sk
->sk_state
== IUCV_CONNECTED
)) {
2310 if (event
== NETDEV_GOING_DOWN
)
2311 iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
2312 sk
->sk_state
= IUCV_DISCONN
;
2313 sk
->sk_state_change(sk
);
2318 case NETDEV_UNREGISTER
:
2325 static struct notifier_block afiucv_netdev_notifier
= {
2326 .notifier_call
= afiucv_netdev_event
,
2329 static const struct proto_ops iucv_sock_ops
= {
2331 .owner
= THIS_MODULE
,
2332 .release
= iucv_sock_release
,
2333 .bind
= iucv_sock_bind
,
2334 .connect
= iucv_sock_connect
,
2335 .listen
= iucv_sock_listen
,
2336 .accept
= iucv_sock_accept
,
2337 .getname
= iucv_sock_getname
,
2338 .sendmsg
= iucv_sock_sendmsg
,
2339 .recvmsg
= iucv_sock_recvmsg
,
2340 .poll
= iucv_sock_poll
,
2341 .ioctl
= sock_no_ioctl
,
2342 .mmap
= sock_no_mmap
,
2343 .socketpair
= sock_no_socketpair
,
2344 .shutdown
= iucv_sock_shutdown
,
2345 .setsockopt
= iucv_sock_setsockopt
,
2346 .getsockopt
= iucv_sock_getsockopt
,
2349 static const struct net_proto_family iucv_sock_family_ops
= {
2351 .owner
= THIS_MODULE
,
2352 .create
= iucv_sock_create
,
2355 static struct packet_type iucv_packet_type
= {
2356 .type
= cpu_to_be16(ETH_P_AF_IUCV
),
2357 .func
= afiucv_hs_rcv
,
2360 static int afiucv_iucv_init(void)
2364 err
= pr_iucv
->iucv_register(&af_iucv_handler
, 0);
2367 /* establish dummy device */
2368 af_iucv_driver
.bus
= pr_iucv
->bus
;
2369 err
= driver_register(&af_iucv_driver
);
2372 af_iucv_dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
2377 dev_set_name(af_iucv_dev
, "af_iucv");
2378 af_iucv_dev
->bus
= pr_iucv
->bus
;
2379 af_iucv_dev
->parent
= pr_iucv
->root
;
2380 af_iucv_dev
->release
= (void (*)(struct device
*))kfree
;
2381 af_iucv_dev
->driver
= &af_iucv_driver
;
2382 err
= device_register(af_iucv_dev
);
2388 driver_unregister(&af_iucv_driver
);
2390 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2395 static int __init
afiucv_init(void)
2399 if (MACHINE_IS_VM
) {
2400 cpcmd("QUERY USERID", iucv_userid
, sizeof(iucv_userid
), &err
);
2401 if (unlikely(err
)) {
2403 err
= -EPROTONOSUPPORT
;
2407 pr_iucv
= try_then_request_module(symbol_get(iucv_if
), "iucv");
2409 printk(KERN_WARNING
"iucv_if lookup failed\n");
2410 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2413 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2417 err
= proto_register(&iucv_proto
, 0);
2420 err
= sock_register(&iucv_sock_family_ops
);
2425 err
= afiucv_iucv_init();
2429 register_netdevice_notifier(&afiucv_netdev_notifier
);
2430 dev_add_pack(&iucv_packet_type
);
2434 sock_unregister(PF_IUCV
);
2436 proto_unregister(&iucv_proto
);
2439 symbol_put(iucv_if
);
2443 static void __exit
afiucv_exit(void)
2446 device_unregister(af_iucv_dev
);
2447 driver_unregister(&af_iucv_driver
);
2448 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2449 symbol_put(iucv_if
);
2451 unregister_netdevice_notifier(&afiucv_netdev_notifier
);
2452 dev_remove_pack(&iucv_packet_type
);
2453 sock_unregister(PF_IUCV
);
2454 proto_unregister(&iucv_proto
);
2457 module_init(afiucv_init
);
2458 module_exit(afiucv_exit
);
2460 MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>");
2461 MODULE_DESCRIPTION("IUCV Sockets ver " VERSION
);
2462 MODULE_VERSION(VERSION
);
2463 MODULE_LICENSE("GPL");
2464 MODULE_ALIAS_NETPROTO(PF_IUCV
);