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/iucv.h>
31 #include <net/iucv/af_iucv.h>
35 static char iucv_userid
[80];
37 static const struct proto_ops iucv_sock_ops
;
39 static struct proto iucv_proto
= {
42 .obj_size
= sizeof(struct iucv_sock
),
45 /* special AF_IUCV IPRM messages */
46 static const u8 iprm_shutdown
[8] =
47 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
49 #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
51 /* macros to set/get socket control buffer at correct offset */
52 #define CB_TAG(skb) ((skb)->cb) /* iucv message tag */
53 #define CB_TAG_LEN (sizeof(((struct iucv_message *) 0)->tag))
54 #define CB_TRGCLS(skb) ((skb)->cb + CB_TAG_LEN) /* iucv msg target class */
55 #define CB_TRGCLS_LEN (TRGCLS_SIZE)
57 #define __iucv_sock_wait(sk, condition, timeo, ret) \
59 DEFINE_WAIT(__wait); \
60 long __timeo = timeo; \
62 prepare_to_wait(sk->sk_sleep, &__wait, TASK_INTERRUPTIBLE); \
63 while (!(condition)) { \
68 if (signal_pending(current)) { \
69 ret = sock_intr_errno(__timeo); \
73 __timeo = schedule_timeout(__timeo); \
75 ret = sock_error(sk); \
79 finish_wait(sk->sk_sleep, &__wait); \
82 #define iucv_sock_wait(sk, condition, timeo) \
86 __iucv_sock_wait(sk, condition, timeo, __ret); \
90 static void iucv_sock_kill(struct sock
*sk
);
91 static void iucv_sock_close(struct sock
*sk
);
93 /* Call Back functions */
94 static void iucv_callback_rx(struct iucv_path
*, struct iucv_message
*);
95 static void iucv_callback_txdone(struct iucv_path
*, struct iucv_message
*);
96 static void iucv_callback_connack(struct iucv_path
*, u8 ipuser
[16]);
97 static int iucv_callback_connreq(struct iucv_path
*, u8 ipvmid
[8],
99 static void iucv_callback_connrej(struct iucv_path
*, u8 ipuser
[16]);
100 static void iucv_callback_shutdown(struct iucv_path
*, u8 ipuser
[16]);
102 static struct iucv_sock_list iucv_sk_list
= {
103 .lock
= __RW_LOCK_UNLOCKED(iucv_sk_list
.lock
),
104 .autobind_name
= ATOMIC_INIT(0)
107 static struct iucv_handler af_iucv_handler
= {
108 .path_pending
= iucv_callback_connreq
,
109 .path_complete
= iucv_callback_connack
,
110 .path_severed
= iucv_callback_connrej
,
111 .message_pending
= iucv_callback_rx
,
112 .message_complete
= iucv_callback_txdone
,
113 .path_quiesced
= iucv_callback_shutdown
,
116 static inline void high_nmcpy(unsigned char *dst
, char *src
)
121 static inline void low_nmcpy(unsigned char *dst
, char *src
)
123 memcpy(&dst
[8], src
, 8);
126 static int afiucv_pm_prepare(struct device
*dev
)
128 #ifdef CONFIG_PM_DEBUG
129 printk(KERN_WARNING
"afiucv_pm_prepare\n");
134 static void afiucv_pm_complete(struct device
*dev
)
136 #ifdef CONFIG_PM_DEBUG
137 printk(KERN_WARNING
"afiucv_pm_complete\n");
143 * afiucv_pm_freeze() - Freeze PM callback
144 * @dev: AFIUCV dummy device
146 * Sever all established IUCV communication pathes
148 static int afiucv_pm_freeze(struct device
*dev
)
150 struct iucv_sock
*iucv
;
152 struct hlist_node
*node
;
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
, node
, &iucv_sk_list
.head
) {
161 skb_queue_purge(&iucv
->send_skb_q
);
162 skb_queue_purge(&iucv
->backlog_skb_q
);
163 switch (sk
->sk_state
) {
169 err
= iucv_path_sever(iucv
->path
, NULL
);
170 iucv_path_free(iucv
->path
);
182 read_unlock(&iucv_sk_list
.lock
);
187 * afiucv_pm_restore_thaw() - Thaw and restore PM callback
188 * @dev: AFIUCV dummy device
190 * socket clean up after freeze
192 static int afiucv_pm_restore_thaw(struct device
*dev
)
194 struct iucv_sock
*iucv
;
196 struct hlist_node
*node
;
198 #ifdef CONFIG_PM_DEBUG
199 printk(KERN_WARNING
"afiucv_pm_restore_thaw\n");
201 read_lock(&iucv_sk_list
.lock
);
202 sk_for_each(sk
, node
, &iucv_sk_list
.head
) {
204 switch (sk
->sk_state
) {
207 sk
->sk_state
= IUCV_DISCONN
;
208 sk
->sk_state_change(sk
);
220 read_unlock(&iucv_sk_list
.lock
);
224 static struct dev_pm_ops afiucv_pm_ops
= {
225 .prepare
= afiucv_pm_prepare
,
226 .complete
= afiucv_pm_complete
,
227 .freeze
= afiucv_pm_freeze
,
228 .thaw
= afiucv_pm_restore_thaw
,
229 .restore
= afiucv_pm_restore_thaw
,
232 static struct device_driver af_iucv_driver
= {
233 .owner
= THIS_MODULE
,
236 .pm
= &afiucv_pm_ops
,
239 /* dummy device used as trigger for PM functions */
240 static struct device
*af_iucv_dev
;
243 * iucv_msg_length() - Returns the length of an iucv message.
244 * @msg: Pointer to struct iucv_message, MUST NOT be NULL
246 * The function returns the length of the specified iucv message @msg of data
247 * stored in a buffer and of data stored in the parameter list (PRMDATA).
249 * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket
251 * PRMDATA[0..6] socket data (max 7 bytes);
252 * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7])
254 * The socket data length is computed by substracting the socket data length
256 * If the socket data len is greater 7, then PRMDATA can be used for special
257 * notifications (see iucv_sock_shutdown); and further,
258 * if the socket data len is > 7, the function returns 8.
260 * Use this function to allocate socket buffers to store iucv message data.
262 static inline size_t iucv_msg_length(struct iucv_message
*msg
)
266 if (msg
->flags
& IUCV_IPRMDATA
) {
267 datalen
= 0xff - msg
->rmmsg
[7];
268 return (datalen
< 8) ? datalen
: 8;
274 * iucv_sock_in_state() - check for specific states
275 * @sk: sock structure
276 * @state: first iucv sk state
277 * @state: second iucv sk state
279 * Returns true if the socket in either in the first or second state.
281 static int iucv_sock_in_state(struct sock
*sk
, int state
, int state2
)
283 return (sk
->sk_state
== state
|| sk
->sk_state
== state2
);
287 * iucv_below_msglim() - function to check if messages can be sent
288 * @sk: sock structure
290 * Returns true if the send queue length is lower than the message limit.
291 * Always returns true if the socket is not connected (no iucv path for
292 * checking the message limit).
294 static inline int iucv_below_msglim(struct sock
*sk
)
296 struct iucv_sock
*iucv
= iucv_sk(sk
);
298 if (sk
->sk_state
!= IUCV_CONNECTED
)
300 return (skb_queue_len(&iucv
->send_skb_q
) < iucv
->path
->msglim
);
304 * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit
306 static void iucv_sock_wake_msglim(struct sock
*sk
)
308 read_lock(&sk
->sk_callback_lock
);
309 if (sk_has_sleeper(sk
))
310 wake_up_interruptible_all(sk
->sk_sleep
);
311 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
312 read_unlock(&sk
->sk_callback_lock
);
316 static void iucv_sock_timeout(unsigned long arg
)
318 struct sock
*sk
= (struct sock
*)arg
;
321 sk
->sk_err
= ETIMEDOUT
;
322 sk
->sk_state_change(sk
);
329 static void iucv_sock_clear_timer(struct sock
*sk
)
331 sk_stop_timer(sk
, &sk
->sk_timer
);
334 static struct sock
*__iucv_get_sock_by_name(char *nm
)
337 struct hlist_node
*node
;
339 sk_for_each(sk
, node
, &iucv_sk_list
.head
)
340 if (!memcmp(&iucv_sk(sk
)->src_name
, nm
, 8))
346 static void iucv_sock_destruct(struct sock
*sk
)
348 skb_queue_purge(&sk
->sk_receive_queue
);
349 skb_queue_purge(&sk
->sk_write_queue
);
353 static void iucv_sock_cleanup_listen(struct sock
*parent
)
357 /* Close non-accepted connections */
358 while ((sk
= iucv_accept_dequeue(parent
, NULL
))) {
363 parent
->sk_state
= IUCV_CLOSED
;
366 /* Kill socket (only if zapped and orphaned) */
367 static void iucv_sock_kill(struct sock
*sk
)
369 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
372 iucv_sock_unlink(&iucv_sk_list
, sk
);
373 sock_set_flag(sk
, SOCK_DEAD
);
377 /* Close an IUCV socket */
378 static void iucv_sock_close(struct sock
*sk
)
380 unsigned char user_data
[16];
381 struct iucv_sock
*iucv
= iucv_sk(sk
);
385 iucv_sock_clear_timer(sk
);
388 switch (sk
->sk_state
) {
390 iucv_sock_cleanup_listen(sk
);
397 sk
->sk_state
= IUCV_CLOSING
;
398 sk
->sk_state_change(sk
);
400 if (!skb_queue_empty(&iucv
->send_skb_q
)) {
401 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
402 timeo
= sk
->sk_lingertime
;
404 timeo
= IUCV_DISCONN_TIMEOUT
;
405 err
= iucv_sock_wait(sk
,
406 iucv_sock_in_state(sk
, IUCV_CLOSED
, 0),
410 case IUCV_CLOSING
: /* fall through */
411 sk
->sk_state
= IUCV_CLOSED
;
412 sk
->sk_state_change(sk
);
415 low_nmcpy(user_data
, iucv
->src_name
);
416 high_nmcpy(user_data
, iucv
->dst_name
);
417 ASCEBC(user_data
, sizeof(user_data
));
418 err
= iucv_path_sever(iucv
->path
, user_data
);
419 iucv_path_free(iucv
->path
);
423 sk
->sk_err
= ECONNRESET
;
424 sk
->sk_state_change(sk
);
426 skb_queue_purge(&iucv
->send_skb_q
);
427 skb_queue_purge(&iucv
->backlog_skb_q
);
431 /* nothing to do here */
435 /* mark socket for deletion by iucv_sock_kill() */
436 sock_set_flag(sk
, SOCK_ZAPPED
);
441 static void iucv_sock_init(struct sock
*sk
, struct sock
*parent
)
444 sk
->sk_type
= parent
->sk_type
;
447 static struct sock
*iucv_sock_alloc(struct socket
*sock
, int proto
, gfp_t prio
)
451 sk
= sk_alloc(&init_net
, PF_IUCV
, prio
, &iucv_proto
);
455 sock_init_data(sock
, sk
);
456 INIT_LIST_HEAD(&iucv_sk(sk
)->accept_q
);
457 spin_lock_init(&iucv_sk(sk
)->accept_q_lock
);
458 skb_queue_head_init(&iucv_sk(sk
)->send_skb_q
);
459 INIT_LIST_HEAD(&iucv_sk(sk
)->message_q
.list
);
460 spin_lock_init(&iucv_sk(sk
)->message_q
.lock
);
461 skb_queue_head_init(&iucv_sk(sk
)->backlog_skb_q
);
462 iucv_sk(sk
)->send_tag
= 0;
463 iucv_sk(sk
)->flags
= 0;
464 iucv_sk(sk
)->msglimit
= IUCV_QUEUELEN_DEFAULT
;
465 iucv_sk(sk
)->path
= NULL
;
466 memset(&iucv_sk(sk
)->src_user_id
, 0, 32);
468 sk
->sk_destruct
= iucv_sock_destruct
;
469 sk
->sk_sndtimeo
= IUCV_CONN_TIMEOUT
;
470 sk
->sk_allocation
= GFP_DMA
;
472 sock_reset_flag(sk
, SOCK_ZAPPED
);
474 sk
->sk_protocol
= proto
;
475 sk
->sk_state
= IUCV_OPEN
;
477 setup_timer(&sk
->sk_timer
, iucv_sock_timeout
, (unsigned long)sk
);
479 iucv_sock_link(&iucv_sk_list
, sk
);
483 /* Create an IUCV socket */
484 static int iucv_sock_create(struct net
*net
, struct socket
*sock
, int protocol
)
488 if (protocol
&& protocol
!= PF_IUCV
)
489 return -EPROTONOSUPPORT
;
491 sock
->state
= SS_UNCONNECTED
;
493 switch (sock
->type
) {
495 sock
->ops
= &iucv_sock_ops
;
498 /* currently, proto ops can handle both sk types */
499 sock
->ops
= &iucv_sock_ops
;
502 return -ESOCKTNOSUPPORT
;
505 sk
= iucv_sock_alloc(sock
, protocol
, GFP_KERNEL
);
509 iucv_sock_init(sk
, NULL
);
514 void iucv_sock_link(struct iucv_sock_list
*l
, struct sock
*sk
)
516 write_lock_bh(&l
->lock
);
517 sk_add_node(sk
, &l
->head
);
518 write_unlock_bh(&l
->lock
);
521 void iucv_sock_unlink(struct iucv_sock_list
*l
, struct sock
*sk
)
523 write_lock_bh(&l
->lock
);
524 sk_del_node_init(sk
);
525 write_unlock_bh(&l
->lock
);
528 void iucv_accept_enqueue(struct sock
*parent
, struct sock
*sk
)
531 struct iucv_sock
*par
= iucv_sk(parent
);
534 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
535 list_add_tail(&iucv_sk(sk
)->accept_q
, &par
->accept_q
);
536 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
537 iucv_sk(sk
)->parent
= parent
;
538 sk_acceptq_added(parent
);
541 void iucv_accept_unlink(struct sock
*sk
)
544 struct iucv_sock
*par
= iucv_sk(iucv_sk(sk
)->parent
);
546 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
547 list_del_init(&iucv_sk(sk
)->accept_q
);
548 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
549 sk_acceptq_removed(iucv_sk(sk
)->parent
);
550 iucv_sk(sk
)->parent
= NULL
;
554 struct sock
*iucv_accept_dequeue(struct sock
*parent
, struct socket
*newsock
)
556 struct iucv_sock
*isk
, *n
;
559 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
560 sk
= (struct sock
*) isk
;
563 if (sk
->sk_state
== IUCV_CLOSED
) {
564 iucv_accept_unlink(sk
);
569 if (sk
->sk_state
== IUCV_CONNECTED
||
570 sk
->sk_state
== IUCV_SEVERED
||
571 sk
->sk_state
== IUCV_DISCONN
|| /* due to PM restore */
573 iucv_accept_unlink(sk
);
575 sock_graft(sk
, newsock
);
577 if (sk
->sk_state
== IUCV_SEVERED
)
578 sk
->sk_state
= IUCV_DISCONN
;
589 /* Bind an unbound socket */
590 static int iucv_sock_bind(struct socket
*sock
, struct sockaddr
*addr
,
593 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
594 struct sock
*sk
= sock
->sk
;
595 struct iucv_sock
*iucv
;
598 /* Verify the input sockaddr */
599 if (!addr
|| addr
->sa_family
!= AF_IUCV
)
603 if (sk
->sk_state
!= IUCV_OPEN
) {
608 write_lock_bh(&iucv_sk_list
.lock
);
611 if (__iucv_get_sock_by_name(sa
->siucv_name
)) {
620 /* Bind the socket */
621 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
623 /* Copy the user id */
624 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
625 sk
->sk_state
= IUCV_BOUND
;
629 /* Release the socket list lock */
630 write_unlock_bh(&iucv_sk_list
.lock
);
636 /* Automatically bind an unbound socket */
637 static int iucv_sock_autobind(struct sock
*sk
)
639 struct iucv_sock
*iucv
= iucv_sk(sk
);
640 char query_buffer
[80];
644 /* Set the userid and name */
645 cpcmd("QUERY USERID", query_buffer
, sizeof(query_buffer
), &err
);
649 memcpy(iucv
->src_user_id
, query_buffer
, 8);
651 write_lock_bh(&iucv_sk_list
.lock
);
653 sprintf(name
, "%08x", atomic_inc_return(&iucv_sk_list
.autobind_name
));
654 while (__iucv_get_sock_by_name(name
)) {
655 sprintf(name
, "%08x",
656 atomic_inc_return(&iucv_sk_list
.autobind_name
));
659 write_unlock_bh(&iucv_sk_list
.lock
);
661 memcpy(&iucv
->src_name
, name
, 8);
666 /* Connect an unconnected socket */
667 static int iucv_sock_connect(struct socket
*sock
, struct sockaddr
*addr
,
670 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
671 struct sock
*sk
= sock
->sk
;
672 struct iucv_sock
*iucv
;
673 unsigned char user_data
[16];
676 if (addr
->sa_family
!= AF_IUCV
|| alen
< sizeof(struct sockaddr_iucv
))
679 if (sk
->sk_state
!= IUCV_OPEN
&& sk
->sk_state
!= IUCV_BOUND
)
682 if (sk
->sk_type
!= SOCK_STREAM
&& sk
->sk_type
!= SOCK_SEQPACKET
)
685 if (sk
->sk_state
== IUCV_OPEN
) {
686 err
= iucv_sock_autobind(sk
);
693 /* Set the destination information */
694 memcpy(iucv_sk(sk
)->dst_user_id
, sa
->siucv_user_id
, 8);
695 memcpy(iucv_sk(sk
)->dst_name
, sa
->siucv_name
, 8);
697 high_nmcpy(user_data
, sa
->siucv_name
);
698 low_nmcpy(user_data
, iucv_sk(sk
)->src_name
);
699 ASCEBC(user_data
, sizeof(user_data
));
703 iucv
->path
= iucv_path_alloc(iucv
->msglimit
,
704 IUCV_IPRMDATA
, GFP_KERNEL
);
709 err
= iucv_path_connect(iucv
->path
, &af_iucv_handler
,
710 sa
->siucv_user_id
, NULL
, user_data
, sk
);
712 iucv_path_free(iucv
->path
);
715 case 0x0b: /* Target communicator is not logged on */
718 case 0x0d: /* Max connections for this guest exceeded */
719 case 0x0e: /* Max connections for target guest exceeded */
722 case 0x0f: /* Missing IUCV authorization */
732 if (sk
->sk_state
!= IUCV_CONNECTED
) {
733 err
= iucv_sock_wait(sk
, iucv_sock_in_state(sk
, IUCV_CONNECTED
,
735 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
738 if (sk
->sk_state
== IUCV_DISCONN
) {
743 iucv_path_sever(iucv
->path
, NULL
);
744 iucv_path_free(iucv
->path
);
753 /* Move a socket into listening state. */
754 static int iucv_sock_listen(struct socket
*sock
, int backlog
)
756 struct sock
*sk
= sock
->sk
;
762 if (sk
->sk_state
!= IUCV_BOUND
)
765 if (sock
->type
!= SOCK_STREAM
&& sock
->type
!= SOCK_SEQPACKET
)
768 sk
->sk_max_ack_backlog
= backlog
;
769 sk
->sk_ack_backlog
= 0;
770 sk
->sk_state
= IUCV_LISTEN
;
778 /* Accept a pending connection */
779 static int iucv_sock_accept(struct socket
*sock
, struct socket
*newsock
,
782 DECLARE_WAITQUEUE(wait
, current
);
783 struct sock
*sk
= sock
->sk
, *nsk
;
787 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
789 if (sk
->sk_state
!= IUCV_LISTEN
) {
794 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
796 /* Wait for an incoming connection */
797 add_wait_queue_exclusive(sk
->sk_sleep
, &wait
);
798 while (!(nsk
= iucv_accept_dequeue(sk
, newsock
))) {
799 set_current_state(TASK_INTERRUPTIBLE
);
806 timeo
= schedule_timeout(timeo
);
807 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
809 if (sk
->sk_state
!= IUCV_LISTEN
) {
814 if (signal_pending(current
)) {
815 err
= sock_intr_errno(timeo
);
820 set_current_state(TASK_RUNNING
);
821 remove_wait_queue(sk
->sk_sleep
, &wait
);
826 newsock
->state
= SS_CONNECTED
;
833 static int iucv_sock_getname(struct socket
*sock
, struct sockaddr
*addr
,
836 struct sockaddr_iucv
*siucv
= (struct sockaddr_iucv
*) addr
;
837 struct sock
*sk
= sock
->sk
;
839 addr
->sa_family
= AF_IUCV
;
840 *len
= sizeof(struct sockaddr_iucv
);
843 memcpy(siucv
->siucv_user_id
, iucv_sk(sk
)->dst_user_id
, 8);
844 memcpy(siucv
->siucv_name
, &iucv_sk(sk
)->dst_name
, 8);
846 memcpy(siucv
->siucv_user_id
, iucv_sk(sk
)->src_user_id
, 8);
847 memcpy(siucv
->siucv_name
, iucv_sk(sk
)->src_name
, 8);
849 memset(&siucv
->siucv_port
, 0, sizeof(siucv
->siucv_port
));
850 memset(&siucv
->siucv_addr
, 0, sizeof(siucv
->siucv_addr
));
851 memset(siucv
->siucv_nodeid
, 0, sizeof(siucv
->siucv_nodeid
));
857 * iucv_send_iprm() - Send socket data in parameter list of an iucv message.
859 * @msg: Pointer to a struct iucv_message
860 * @skb: The socket data to send, skb->len MUST BE <= 7
862 * Send the socket data in the parameter list in the iucv message
863 * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter
864 * list and the socket data len at index 7 (last byte).
865 * See also iucv_msg_length().
867 * Returns the error code from the iucv_message_send() call.
869 static int iucv_send_iprm(struct iucv_path
*path
, struct iucv_message
*msg
,
874 memcpy(prmdata
, (void *) skb
->data
, skb
->len
);
875 prmdata
[7] = 0xff - (u8
) skb
->len
;
876 return iucv_message_send(path
, msg
, IUCV_IPRMDATA
, 0,
877 (void *) prmdata
, 8);
880 static int iucv_sock_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
881 struct msghdr
*msg
, size_t len
)
883 struct sock
*sk
= sock
->sk
;
884 struct iucv_sock
*iucv
= iucv_sk(sk
);
886 struct iucv_message txmsg
;
887 struct cmsghdr
*cmsg
;
893 int noblock
= msg
->msg_flags
& MSG_DONTWAIT
;
895 err
= sock_error(sk
);
899 if (msg
->msg_flags
& MSG_OOB
)
902 /* SOCK_SEQPACKET: we do not support segmented records */
903 if (sk
->sk_type
== SOCK_SEQPACKET
&& !(msg
->msg_flags
& MSG_EOR
))
908 if (sk
->sk_shutdown
& SEND_SHUTDOWN
) {
913 /* Return if the socket is not in connected state */
914 if (sk
->sk_state
!= IUCV_CONNECTED
) {
919 /* initialize defaults */
920 cmsg_done
= 0; /* check for duplicate headers */
923 /* iterate over control messages */
924 for (cmsg
= CMSG_FIRSTHDR(msg
); cmsg
;
925 cmsg
= CMSG_NXTHDR(msg
, cmsg
)) {
927 if (!CMSG_OK(msg
, cmsg
)) {
932 if (cmsg
->cmsg_level
!= SOL_IUCV
)
935 if (cmsg
->cmsg_type
& cmsg_done
) {
939 cmsg_done
|= cmsg
->cmsg_type
;
941 switch (cmsg
->cmsg_type
) {
942 case SCM_IUCV_TRGCLS
:
943 if (cmsg
->cmsg_len
!= CMSG_LEN(TRGCLS_SIZE
)) {
948 /* set iucv message target class */
950 (void *) CMSG_DATA(cmsg
), TRGCLS_SIZE
);
961 /* allocate one skb for each iucv message:
962 * this is fine for SOCK_SEQPACKET (unless we want to support
963 * segmented records using the MSG_EOR flag), but
964 * for SOCK_STREAM we might want to improve it in future */
965 skb
= sock_alloc_send_skb(sk
, len
, noblock
, &err
);
968 if (memcpy_fromiovec(skb_put(skb
, len
), msg
->msg_iov
, len
)) {
973 /* wait if outstanding messages for iucv path has reached */
974 timeo
= sock_sndtimeo(sk
, noblock
);
975 err
= iucv_sock_wait(sk
, iucv_below_msglim(sk
), timeo
);
979 /* return -ECONNRESET if the socket is no longer connected */
980 if (sk
->sk_state
!= IUCV_CONNECTED
) {
985 /* increment and save iucv message tag for msg_completion cbk */
986 txmsg
.tag
= iucv
->send_tag
++;
987 memcpy(CB_TAG(skb
), &txmsg
.tag
, CB_TAG_LEN
);
988 skb_queue_tail(&iucv
->send_skb_q
, skb
);
990 if (((iucv
->path
->flags
& IUCV_IPRMDATA
) & iucv
->flags
)
992 err
= iucv_send_iprm(iucv
->path
, &txmsg
, skb
);
994 /* on success: there is no message_complete callback
995 * for an IPRMDATA msg; remove skb from send queue */
997 skb_unlink(skb
, &iucv
->send_skb_q
);
1001 /* this error should never happen since the
1002 * IUCV_IPRMDATA path flag is set... sever path */
1004 iucv_path_sever(iucv
->path
, NULL
);
1005 skb_unlink(skb
, &iucv
->send_skb_q
);
1010 err
= iucv_message_send(iucv
->path
, &txmsg
, 0, 0,
1011 (void *) skb
->data
, skb
->len
);
1015 memcpy(user_id
, iucv
->dst_user_id
, 8);
1017 memcpy(appl_id
, iucv
->dst_name
, 8);
1018 pr_err("Application %s on z/VM guest %s"
1019 " exceeds message limit\n",
1024 skb_unlink(skb
, &iucv
->send_skb_q
);
1038 /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's
1040 * Locking: must be called with message_q.lock held
1042 static int iucv_fragment_skb(struct sock
*sk
, struct sk_buff
*skb
, int len
)
1044 int dataleft
, size
, copied
= 0;
1045 struct sk_buff
*nskb
;
1049 if (dataleft
>= sk
->sk_rcvbuf
/ 4)
1050 size
= sk
->sk_rcvbuf
/ 4;
1054 nskb
= alloc_skb(size
, GFP_ATOMIC
| GFP_DMA
);
1058 /* copy target class to control buffer of new skb */
1059 memcpy(CB_TRGCLS(nskb
), CB_TRGCLS(skb
), CB_TRGCLS_LEN
);
1061 /* copy data fragment */
1062 memcpy(nskb
->data
, skb
->data
+ copied
, size
);
1066 skb_reset_transport_header(nskb
);
1067 skb_reset_network_header(nskb
);
1070 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, nskb
);
1076 /* iucv_process_message() - Receive a single outstanding IUCV message
1078 * Locking: must be called with message_q.lock held
1080 static void iucv_process_message(struct sock
*sk
, struct sk_buff
*skb
,
1081 struct iucv_path
*path
,
1082 struct iucv_message
*msg
)
1087 len
= iucv_msg_length(msg
);
1089 /* store msg target class in the second 4 bytes of skb ctrl buffer */
1090 /* Note: the first 4 bytes are reserved for msg tag */
1091 memcpy(CB_TRGCLS(skb
), &msg
->class, CB_TRGCLS_LEN
);
1093 /* check for special IPRM messages (e.g. iucv_sock_shutdown) */
1094 if ((msg
->flags
& IUCV_IPRMDATA
) && len
> 7) {
1095 if (memcmp(msg
->rmmsg
, iprm_shutdown
, 8) == 0) {
1100 rc
= iucv_message_receive(path
, msg
, msg
->flags
& IUCV_IPRMDATA
,
1101 skb
->data
, len
, NULL
);
1106 /* we need to fragment iucv messages for SOCK_STREAM only;
1107 * for SOCK_SEQPACKET, it is only relevant if we support
1108 * record segmentation using MSG_EOR (see also recvmsg()) */
1109 if (sk
->sk_type
== SOCK_STREAM
&&
1110 skb
->truesize
>= sk
->sk_rcvbuf
/ 4) {
1111 rc
= iucv_fragment_skb(sk
, skb
, len
);
1115 iucv_path_sever(path
, NULL
);
1118 skb
= skb_dequeue(&iucv_sk(sk
)->backlog_skb_q
);
1120 skb_reset_transport_header(skb
);
1121 skb_reset_network_header(skb
);
1126 if (sock_queue_rcv_skb(sk
, skb
))
1127 skb_queue_head(&iucv_sk(sk
)->backlog_skb_q
, skb
);
1130 /* iucv_process_message_q() - Process outstanding IUCV messages
1132 * Locking: must be called with message_q.lock held
1134 static void iucv_process_message_q(struct sock
*sk
)
1136 struct iucv_sock
*iucv
= iucv_sk(sk
);
1137 struct sk_buff
*skb
;
1138 struct sock_msg_q
*p
, *n
;
1140 list_for_each_entry_safe(p
, n
, &iucv
->message_q
.list
, list
) {
1141 skb
= alloc_skb(iucv_msg_length(&p
->msg
), GFP_ATOMIC
| GFP_DMA
);
1144 iucv_process_message(sk
, skb
, p
->path
, &p
->msg
);
1147 if (!skb_queue_empty(&iucv
->backlog_skb_q
))
1152 static int iucv_sock_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
1153 struct msghdr
*msg
, size_t len
, int flags
)
1155 int noblock
= flags
& MSG_DONTWAIT
;
1156 struct sock
*sk
= sock
->sk
;
1157 struct iucv_sock
*iucv
= iucv_sk(sk
);
1158 unsigned int copied
, rlen
;
1159 struct sk_buff
*skb
, *rskb
, *cskb
;
1162 if ((sk
->sk_state
== IUCV_DISCONN
|| sk
->sk_state
== IUCV_SEVERED
) &&
1163 skb_queue_empty(&iucv
->backlog_skb_q
) &&
1164 skb_queue_empty(&sk
->sk_receive_queue
) &&
1165 list_empty(&iucv
->message_q
.list
))
1168 if (flags
& (MSG_OOB
))
1171 /* receive/dequeue next skb:
1172 * the function understands MSG_PEEK and, thus, does not dequeue skb */
1173 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
1175 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1180 rlen
= skb
->len
; /* real length of skb */
1181 copied
= min_t(unsigned int, rlen
, len
);
1184 if (memcpy_toiovec(msg
->msg_iov
, cskb
->data
, copied
)) {
1185 if (!(flags
& MSG_PEEK
))
1186 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1190 /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */
1191 if (sk
->sk_type
== SOCK_SEQPACKET
) {
1193 msg
->msg_flags
|= MSG_TRUNC
;
1194 /* each iucv message contains a complete record */
1195 msg
->msg_flags
|= MSG_EOR
;
1198 /* create control message to store iucv msg target class:
1199 * get the trgcls from the control buffer of the skb due to
1200 * fragmentation of original iucv message. */
1201 err
= put_cmsg(msg
, SOL_IUCV
, SCM_IUCV_TRGCLS
,
1202 CB_TRGCLS_LEN
, CB_TRGCLS(skb
));
1204 if (!(flags
& MSG_PEEK
))
1205 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1209 /* Mark read part of skb as used */
1210 if (!(flags
& MSG_PEEK
)) {
1212 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
1213 if (sk
->sk_type
== SOCK_STREAM
) {
1214 skb_pull(skb
, copied
);
1216 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1223 /* Queue backlog skbs */
1224 spin_lock_bh(&iucv
->message_q
.lock
);
1225 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1227 if (sock_queue_rcv_skb(sk
, rskb
)) {
1228 skb_queue_head(&iucv
->backlog_skb_q
,
1232 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1235 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
1236 if (!list_empty(&iucv
->message_q
.list
))
1237 iucv_process_message_q(sk
);
1239 spin_unlock_bh(&iucv
->message_q
.lock
);
1243 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
1244 if (sk
->sk_type
== SOCK_SEQPACKET
&& (flags
& MSG_TRUNC
))
1250 static inline unsigned int iucv_accept_poll(struct sock
*parent
)
1252 struct iucv_sock
*isk
, *n
;
1255 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
1256 sk
= (struct sock
*) isk
;
1258 if (sk
->sk_state
== IUCV_CONNECTED
)
1259 return POLLIN
| POLLRDNORM
;
1265 unsigned int iucv_sock_poll(struct file
*file
, struct socket
*sock
,
1268 struct sock
*sk
= sock
->sk
;
1269 unsigned int mask
= 0;
1271 sock_poll_wait(file
, sk
->sk_sleep
, wait
);
1273 if (sk
->sk_state
== IUCV_LISTEN
)
1274 return iucv_accept_poll(sk
);
1276 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
))
1279 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1282 if (sk
->sk_shutdown
== SHUTDOWN_MASK
)
1285 if (!skb_queue_empty(&sk
->sk_receive_queue
) ||
1286 (sk
->sk_shutdown
& RCV_SHUTDOWN
))
1287 mask
|= POLLIN
| POLLRDNORM
;
1289 if (sk
->sk_state
== IUCV_CLOSED
)
1292 if (sk
->sk_state
== IUCV_DISCONN
|| sk
->sk_state
== IUCV_SEVERED
)
1295 if (sock_writeable(sk
))
1296 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
1298 set_bit(SOCK_ASYNC_NOSPACE
, &sk
->sk_socket
->flags
);
1303 static int iucv_sock_shutdown(struct socket
*sock
, int how
)
1305 struct sock
*sk
= sock
->sk
;
1306 struct iucv_sock
*iucv
= iucv_sk(sk
);
1307 struct iucv_message txmsg
;
1312 if ((how
& ~SHUTDOWN_MASK
) || !how
)
1316 switch (sk
->sk_state
) {
1325 sk
->sk_shutdown
|= how
;
1329 if (how
== SEND_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1332 err
= iucv_message_send(iucv
->path
, &txmsg
, IUCV_IPRMDATA
, 0,
1333 (void *) iprm_shutdown
, 8);
1349 if (how
== RCV_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1350 err
= iucv_path_quiesce(iucv_sk(sk
)->path
, NULL
);
1354 skb_queue_purge(&sk
->sk_receive_queue
);
1357 /* Wake up anyone sleeping in poll */
1358 sk
->sk_state_change(sk
);
1365 static int iucv_sock_release(struct socket
*sock
)
1367 struct sock
*sk
= sock
->sk
;
1373 iucv_sock_close(sk
);
1375 /* Unregister with IUCV base support */
1376 if (iucv_sk(sk
)->path
) {
1377 iucv_path_sever(iucv_sk(sk
)->path
, NULL
);
1378 iucv_path_free(iucv_sk(sk
)->path
);
1379 iucv_sk(sk
)->path
= NULL
;
1387 /* getsockopt and setsockopt */
1388 static int iucv_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
1389 char __user
*optval
, unsigned int optlen
)
1391 struct sock
*sk
= sock
->sk
;
1392 struct iucv_sock
*iucv
= iucv_sk(sk
);
1396 if (level
!= SOL_IUCV
)
1397 return -ENOPROTOOPT
;
1399 if (optlen
< sizeof(int))
1402 if (get_user(val
, (int __user
*) optval
))
1409 case SO_IPRMDATA_MSG
:
1411 iucv
->flags
|= IUCV_IPRMDATA
;
1413 iucv
->flags
&= ~IUCV_IPRMDATA
;
1416 switch (sk
->sk_state
) {
1419 if (val
< 1 || val
> (u16
)(~0))
1422 iucv
->msglimit
= val
;
1438 static int iucv_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
1439 char __user
*optval
, int __user
*optlen
)
1441 struct sock
*sk
= sock
->sk
;
1442 struct iucv_sock
*iucv
= iucv_sk(sk
);
1445 if (level
!= SOL_IUCV
)
1446 return -ENOPROTOOPT
;
1448 if (get_user(len
, optlen
))
1454 len
= min_t(unsigned int, len
, sizeof(int));
1457 case SO_IPRMDATA_MSG
:
1458 val
= (iucv
->flags
& IUCV_IPRMDATA
) ? 1 : 0;
1462 val
= (iucv
->path
!= NULL
) ? iucv
->path
->msglim
/* connected */
1463 : iucv
->msglimit
; /* default */
1467 return -ENOPROTOOPT
;
1470 if (put_user(len
, optlen
))
1472 if (copy_to_user(optval
, &val
, len
))
1479 /* Callback wrappers - called from iucv base support */
1480 static int iucv_callback_connreq(struct iucv_path
*path
,
1481 u8 ipvmid
[8], u8 ipuser
[16])
1483 unsigned char user_data
[16];
1484 unsigned char nuser_data
[16];
1485 unsigned char src_name
[8];
1486 struct hlist_node
*node
;
1487 struct sock
*sk
, *nsk
;
1488 struct iucv_sock
*iucv
, *niucv
;
1491 memcpy(src_name
, ipuser
, 8);
1492 EBCASC(src_name
, 8);
1493 /* Find out if this path belongs to af_iucv. */
1494 read_lock(&iucv_sk_list
.lock
);
1497 sk_for_each(sk
, node
, &iucv_sk_list
.head
)
1498 if (sk
->sk_state
== IUCV_LISTEN
&&
1499 !memcmp(&iucv_sk(sk
)->src_name
, src_name
, 8)) {
1501 * Found a listening socket with
1502 * src_name == ipuser[0-7].
1507 read_unlock(&iucv_sk_list
.lock
);
1509 /* No socket found, not one of our paths. */
1514 /* Check if parent socket is listening */
1515 low_nmcpy(user_data
, iucv
->src_name
);
1516 high_nmcpy(user_data
, iucv
->dst_name
);
1517 ASCEBC(user_data
, sizeof(user_data
));
1518 if (sk
->sk_state
!= IUCV_LISTEN
) {
1519 err
= iucv_path_sever(path
, user_data
);
1520 iucv_path_free(path
);
1524 /* Check for backlog size */
1525 if (sk_acceptq_is_full(sk
)) {
1526 err
= iucv_path_sever(path
, user_data
);
1527 iucv_path_free(path
);
1531 /* Create the new socket */
1532 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
);
1534 err
= iucv_path_sever(path
, user_data
);
1535 iucv_path_free(path
);
1539 niucv
= iucv_sk(nsk
);
1540 iucv_sock_init(nsk
, sk
);
1542 /* Set the new iucv_sock */
1543 memcpy(niucv
->dst_name
, ipuser
+ 8, 8);
1544 EBCASC(niucv
->dst_name
, 8);
1545 memcpy(niucv
->dst_user_id
, ipvmid
, 8);
1546 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1547 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1550 /* Call iucv_accept */
1551 high_nmcpy(nuser_data
, ipuser
+ 8);
1552 memcpy(nuser_data
+ 8, niucv
->src_name
, 8);
1553 ASCEBC(nuser_data
+ 8, 8);
1555 /* set message limit for path based on msglimit of accepting socket */
1556 niucv
->msglimit
= iucv
->msglimit
;
1557 path
->msglim
= iucv
->msglimit
;
1558 err
= iucv_path_accept(path
, &af_iucv_handler
, nuser_data
, nsk
);
1560 err
= iucv_path_sever(path
, user_data
);
1561 iucv_path_free(path
);
1562 iucv_sock_kill(nsk
);
1566 iucv_accept_enqueue(sk
, nsk
);
1568 /* Wake up accept */
1569 nsk
->sk_state
= IUCV_CONNECTED
;
1570 sk
->sk_data_ready(sk
, 1);
1577 static void iucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
1579 struct sock
*sk
= path
->private;
1581 sk
->sk_state
= IUCV_CONNECTED
;
1582 sk
->sk_state_change(sk
);
1585 static void iucv_callback_rx(struct iucv_path
*path
, struct iucv_message
*msg
)
1587 struct sock
*sk
= path
->private;
1588 struct iucv_sock
*iucv
= iucv_sk(sk
);
1589 struct sk_buff
*skb
;
1590 struct sock_msg_q
*save_msg
;
1593 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
1594 iucv_message_reject(path
, msg
);
1598 spin_lock(&iucv
->message_q
.lock
);
1600 if (!list_empty(&iucv
->message_q
.list
) ||
1601 !skb_queue_empty(&iucv
->backlog_skb_q
))
1604 len
= atomic_read(&sk
->sk_rmem_alloc
);
1605 len
+= iucv_msg_length(msg
) + sizeof(struct sk_buff
);
1606 if (len
> sk
->sk_rcvbuf
)
1609 skb
= alloc_skb(iucv_msg_length(msg
), GFP_ATOMIC
| GFP_DMA
);
1613 iucv_process_message(sk
, skb
, path
, msg
);
1617 save_msg
= kzalloc(sizeof(struct sock_msg_q
), GFP_ATOMIC
| GFP_DMA
);
1620 save_msg
->path
= path
;
1621 save_msg
->msg
= *msg
;
1623 list_add_tail(&save_msg
->list
, &iucv
->message_q
.list
);
1626 spin_unlock(&iucv
->message_q
.lock
);
1629 static void iucv_callback_txdone(struct iucv_path
*path
,
1630 struct iucv_message
*msg
)
1632 struct sock
*sk
= path
->private;
1633 struct sk_buff
*this = NULL
;
1634 struct sk_buff_head
*list
= &iucv_sk(sk
)->send_skb_q
;
1635 struct sk_buff
*list_skb
= list
->next
;
1636 unsigned long flags
;
1638 if (!skb_queue_empty(list
)) {
1639 spin_lock_irqsave(&list
->lock
, flags
);
1641 while (list_skb
!= (struct sk_buff
*)list
) {
1642 if (!memcmp(&msg
->tag
, CB_TAG(list_skb
), CB_TAG_LEN
)) {
1646 list_skb
= list_skb
->next
;
1649 __skb_unlink(this, list
);
1651 spin_unlock_irqrestore(&list
->lock
, flags
);
1655 /* wake up any process waiting for sending */
1656 iucv_sock_wake_msglim(sk
);
1661 if (sk
->sk_state
== IUCV_CLOSING
) {
1662 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
1663 sk
->sk_state
= IUCV_CLOSED
;
1664 sk
->sk_state_change(sk
);
1670 static void iucv_callback_connrej(struct iucv_path
*path
, u8 ipuser
[16])
1672 struct sock
*sk
= path
->private;
1674 if (!list_empty(&iucv_sk(sk
)->accept_q
))
1675 sk
->sk_state
= IUCV_SEVERED
;
1677 sk
->sk_state
= IUCV_DISCONN
;
1679 sk
->sk_state_change(sk
);
1682 /* called if the other communication side shuts down its RECV direction;
1683 * in turn, the callback sets SEND_SHUTDOWN to disable sending of data.
1685 static void iucv_callback_shutdown(struct iucv_path
*path
, u8 ipuser
[16])
1687 struct sock
*sk
= path
->private;
1690 if (sk
->sk_state
!= IUCV_CLOSED
) {
1691 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
1692 sk
->sk_state_change(sk
);
1697 static const struct proto_ops iucv_sock_ops
= {
1699 .owner
= THIS_MODULE
,
1700 .release
= iucv_sock_release
,
1701 .bind
= iucv_sock_bind
,
1702 .connect
= iucv_sock_connect
,
1703 .listen
= iucv_sock_listen
,
1704 .accept
= iucv_sock_accept
,
1705 .getname
= iucv_sock_getname
,
1706 .sendmsg
= iucv_sock_sendmsg
,
1707 .recvmsg
= iucv_sock_recvmsg
,
1708 .poll
= iucv_sock_poll
,
1709 .ioctl
= sock_no_ioctl
,
1710 .mmap
= sock_no_mmap
,
1711 .socketpair
= sock_no_socketpair
,
1712 .shutdown
= iucv_sock_shutdown
,
1713 .setsockopt
= iucv_sock_setsockopt
,
1714 .getsockopt
= iucv_sock_getsockopt
,
1717 static const struct net_proto_family iucv_sock_family_ops
= {
1719 .owner
= THIS_MODULE
,
1720 .create
= iucv_sock_create
,
1723 static int __init
afiucv_init(void)
1727 if (!MACHINE_IS_VM
) {
1728 pr_err("The af_iucv module cannot be loaded"
1730 err
= -EPROTONOSUPPORT
;
1733 cpcmd("QUERY USERID", iucv_userid
, sizeof(iucv_userid
), &err
);
1734 if (unlikely(err
)) {
1736 err
= -EPROTONOSUPPORT
;
1740 err
= iucv_register(&af_iucv_handler
, 0);
1743 err
= proto_register(&iucv_proto
, 0);
1746 err
= sock_register(&iucv_sock_family_ops
);
1749 /* establish dummy device */
1750 err
= driver_register(&af_iucv_driver
);
1753 af_iucv_dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1758 dev_set_name(af_iucv_dev
, "af_iucv");
1759 af_iucv_dev
->bus
= &iucv_bus
;
1760 af_iucv_dev
->parent
= iucv_root
;
1761 af_iucv_dev
->release
= (void (*)(struct device
*))kfree
;
1762 af_iucv_dev
->driver
= &af_iucv_driver
;
1763 err
= device_register(af_iucv_dev
);
1770 driver_unregister(&af_iucv_driver
);
1772 sock_unregister(PF_IUCV
);
1774 proto_unregister(&iucv_proto
);
1776 iucv_unregister(&af_iucv_handler
, 0);
1781 static void __exit
afiucv_exit(void)
1783 device_unregister(af_iucv_dev
);
1784 driver_unregister(&af_iucv_driver
);
1785 sock_unregister(PF_IUCV
);
1786 proto_unregister(&iucv_proto
);
1787 iucv_unregister(&af_iucv_handler
, 0);
1790 module_init(afiucv_init
);
1791 module_exit(afiucv_exit
);
1793 MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>");
1794 MODULE_DESCRIPTION("IUCV Sockets ver " VERSION
);
1795 MODULE_VERSION(VERSION
);
1796 MODULE_LICENSE("GPL");
1797 MODULE_ALIAS_NETPROTO(PF_IUCV
);