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 /* 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)
58 #define __iucv_sock_wait(sk, condition, timeo, ret) \
60 DEFINE_WAIT(__wait); \
61 long __timeo = timeo; \
63 prepare_to_wait(sk_sleep(sk), &__wait, TASK_INTERRUPTIBLE); \
64 while (!(condition)) { \
69 if (signal_pending(current)) { \
70 ret = sock_intr_errno(__timeo); \
74 __timeo = schedule_timeout(__timeo); \
76 ret = sock_error(sk); \
80 finish_wait(sk_sleep(sk), &__wait); \
83 #define iucv_sock_wait(sk, condition, timeo) \
87 __iucv_sock_wait(sk, condition, timeo, __ret); \
91 static void iucv_sock_kill(struct sock
*sk
);
92 static void iucv_sock_close(struct sock
*sk
);
93 static void iucv_sever_path(struct sock
*, int);
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
);
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]);
105 static int iucv_callback_connreq(struct iucv_path
*, u8 ipvmid
[8],
107 static void iucv_callback_connrej(struct iucv_path
*, u8 ipuser
[16]);
108 static void iucv_callback_shutdown(struct iucv_path
*, u8 ipuser
[16]);
110 static struct iucv_sock_list iucv_sk_list
= {
111 .lock
= __RW_LOCK_UNLOCKED(iucv_sk_list
.lock
),
112 .autobind_name
= ATOMIC_INIT(0)
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
,
120 .message_complete
= iucv_callback_txdone
,
121 .path_quiesced
= iucv_callback_shutdown
,
124 static inline void high_nmcpy(unsigned char *dst
, char *src
)
129 static inline void low_nmcpy(unsigned char *dst
, char *src
)
131 memcpy(&dst
[8], src
, 8);
134 static int afiucv_pm_prepare(struct device
*dev
)
136 #ifdef CONFIG_PM_DEBUG
137 printk(KERN_WARNING
"afiucv_pm_prepare\n");
142 static void afiucv_pm_complete(struct device
*dev
)
144 #ifdef CONFIG_PM_DEBUG
145 printk(KERN_WARNING
"afiucv_pm_complete\n");
150 * afiucv_pm_freeze() - Freeze PM callback
151 * @dev: AFIUCV dummy device
153 * Sever all established IUCV communication pathes
155 static int afiucv_pm_freeze(struct device
*dev
)
157 struct iucv_sock
*iucv
;
159 struct hlist_node
*node
;
162 #ifdef CONFIG_PM_DEBUG
163 printk(KERN_WARNING
"afiucv_pm_freeze\n");
165 read_lock(&iucv_sk_list
.lock
);
166 sk_for_each(sk
, node
, &iucv_sk_list
.head
) {
168 switch (sk
->sk_state
) {
172 iucv_sever_path(sk
, 0);
181 skb_queue_purge(&iucv
->send_skb_q
);
182 skb_queue_purge(&iucv
->backlog_skb_q
);
184 read_unlock(&iucv_sk_list
.lock
);
189 * afiucv_pm_restore_thaw() - Thaw and restore PM callback
190 * @dev: AFIUCV dummy device
192 * socket clean up after freeze
194 static int afiucv_pm_restore_thaw(struct device
*dev
)
197 struct hlist_node
*node
;
199 #ifdef CONFIG_PM_DEBUG
200 printk(KERN_WARNING
"afiucv_pm_restore_thaw\n");
202 read_lock(&iucv_sk_list
.lock
);
203 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
);
219 read_unlock(&iucv_sk_list
.lock
);
223 static const struct dev_pm_ops afiucv_pm_ops
= {
224 .prepare
= afiucv_pm_prepare
,
225 .complete
= afiucv_pm_complete
,
226 .freeze
= afiucv_pm_freeze
,
227 .thaw
= afiucv_pm_restore_thaw
,
228 .restore
= afiucv_pm_restore_thaw
,
231 static struct device_driver af_iucv_driver
= {
232 .owner
= THIS_MODULE
,
235 .pm
= &afiucv_pm_ops
,
238 /* dummy device used as trigger for PM functions */
239 static struct device
*af_iucv_dev
;
242 * iucv_msg_length() - Returns the length of an iucv message.
243 * @msg: Pointer to struct iucv_message, MUST NOT be NULL
245 * The function returns the length of the specified iucv message @msg of data
246 * stored in a buffer and of data stored in the parameter list (PRMDATA).
248 * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket
250 * PRMDATA[0..6] socket data (max 7 bytes);
251 * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7])
253 * The socket data length is computed by subtracting the socket data length
255 * If the socket data len is greater 7, then PRMDATA can be used for special
256 * notifications (see iucv_sock_shutdown); and further,
257 * if the socket data len is > 7, the function returns 8.
259 * Use this function to allocate socket buffers to store iucv message data.
261 static inline size_t iucv_msg_length(struct iucv_message
*msg
)
265 if (msg
->flags
& IUCV_IPRMDATA
) {
266 datalen
= 0xff - msg
->rmmsg
[7];
267 return (datalen
< 8) ? datalen
: 8;
273 * iucv_sock_in_state() - check for specific states
274 * @sk: sock structure
275 * @state: first iucv sk state
276 * @state: second iucv sk state
278 * Returns true if the socket in either in the first or second state.
280 static int iucv_sock_in_state(struct sock
*sk
, int state
, int state2
)
282 return (sk
->sk_state
== state
|| sk
->sk_state
== state2
);
286 * iucv_below_msglim() - function to check if messages can be sent
287 * @sk: sock structure
289 * Returns true if the send queue length is lower than the message limit.
290 * Always returns true if the socket is not connected (no iucv path for
291 * checking the message limit).
293 static inline int iucv_below_msglim(struct sock
*sk
)
295 struct iucv_sock
*iucv
= iucv_sk(sk
);
297 if (sk
->sk_state
!= IUCV_CONNECTED
)
299 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
)
300 return (skb_queue_len(&iucv
->send_skb_q
) < iucv
->path
->msglim
);
302 return ((atomic_read(&iucv
->msg_sent
) < iucv
->msglimit_peer
) &&
303 (atomic_read(&iucv
->pendings
) <= 0));
307 * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit
309 static void iucv_sock_wake_msglim(struct sock
*sk
)
311 struct socket_wq
*wq
;
314 wq
= rcu_dereference(sk
->sk_wq
);
315 if (wq_has_sleeper(wq
))
316 wake_up_interruptible_all(&wq
->wait
);
317 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
322 * afiucv_hs_send() - send a message through HiperSockets transport
324 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
325 struct sk_buff
*skb
, u8 flags
)
327 struct iucv_sock
*iucv
= iucv_sk(sock
);
328 struct af_iucv_trans_hdr
*phs_hdr
;
329 struct sk_buff
*nskb
;
330 int err
, confirm_recv
= 0;
332 memset(skb
->head
, 0, ETH_HLEN
);
333 phs_hdr
= (struct af_iucv_trans_hdr
*)skb_push(skb
,
334 sizeof(struct af_iucv_trans_hdr
));
335 skb_reset_mac_header(skb
);
336 skb_reset_network_header(skb
);
337 skb_push(skb
, ETH_HLEN
);
338 skb_reset_mac_header(skb
);
339 memset(phs_hdr
, 0, sizeof(struct af_iucv_trans_hdr
));
341 phs_hdr
->magic
= ETH_P_AF_IUCV
;
342 phs_hdr
->version
= 1;
343 phs_hdr
->flags
= flags
;
344 if (flags
== AF_IUCV_FLAG_SYN
)
345 phs_hdr
->window
= iucv
->msglimit
;
346 else if ((flags
== AF_IUCV_FLAG_WIN
) || !flags
) {
347 confirm_recv
= atomic_read(&iucv
->msg_recv
);
348 phs_hdr
->window
= confirm_recv
;
350 phs_hdr
->flags
= phs_hdr
->flags
| AF_IUCV_FLAG_WIN
;
352 memcpy(phs_hdr
->destUserID
, iucv
->dst_user_id
, 8);
353 memcpy(phs_hdr
->destAppName
, iucv
->dst_name
, 8);
354 memcpy(phs_hdr
->srcUserID
, iucv
->src_user_id
, 8);
355 memcpy(phs_hdr
->srcAppName
, iucv
->src_name
, 8);
356 ASCEBC(phs_hdr
->destUserID
, sizeof(phs_hdr
->destUserID
));
357 ASCEBC(phs_hdr
->destAppName
, sizeof(phs_hdr
->destAppName
));
358 ASCEBC(phs_hdr
->srcUserID
, sizeof(phs_hdr
->srcUserID
));
359 ASCEBC(phs_hdr
->srcAppName
, sizeof(phs_hdr
->srcAppName
));
361 memcpy(&phs_hdr
->iucv_hdr
, imsg
, sizeof(struct iucv_message
));
363 skb
->dev
= iucv
->hs_dev
;
366 if (!(skb
->dev
->flags
& IFF_UP
) || !netif_carrier_ok(skb
->dev
))
368 if (skb
->len
> skb
->dev
->mtu
) {
369 if (sock
->sk_type
== SOCK_SEQPACKET
)
372 skb_trim(skb
, skb
->dev
->mtu
);
374 skb
->protocol
= ETH_P_AF_IUCV
;
375 skb_shinfo(skb
)->tx_flags
|= SKBTX_DRV_NEEDS_SK_REF
;
376 nskb
= skb_clone(skb
, GFP_ATOMIC
);
379 skb_queue_tail(&iucv
->send_skb_q
, nskb
);
380 err
= dev_queue_xmit(skb
);
381 if (net_xmit_eval(err
)) {
382 skb_unlink(nskb
, &iucv
->send_skb_q
);
385 atomic_sub(confirm_recv
, &iucv
->msg_recv
);
386 WARN_ON(atomic_read(&iucv
->msg_recv
) < 0);
388 return net_xmit_eval(err
);
391 static struct sock
*__iucv_get_sock_by_name(char *nm
)
394 struct hlist_node
*node
;
396 sk_for_each(sk
, node
, &iucv_sk_list
.head
)
397 if (!memcmp(&iucv_sk(sk
)->src_name
, nm
, 8))
403 static void iucv_sock_destruct(struct sock
*sk
)
405 skb_queue_purge(&sk
->sk_receive_queue
);
406 skb_queue_purge(&sk
->sk_error_queue
);
410 if (!sock_flag(sk
, SOCK_DEAD
)) {
411 pr_err("Attempt to release alive iucv socket %p\n", sk
);
415 WARN_ON(atomic_read(&sk
->sk_rmem_alloc
));
416 WARN_ON(atomic_read(&sk
->sk_wmem_alloc
));
417 WARN_ON(sk
->sk_wmem_queued
);
418 WARN_ON(sk
->sk_forward_alloc
);
422 static void iucv_sock_cleanup_listen(struct sock
*parent
)
426 /* Close non-accepted connections */
427 while ((sk
= iucv_accept_dequeue(parent
, NULL
))) {
432 parent
->sk_state
= IUCV_CLOSED
;
435 /* Kill socket (only if zapped and orphaned) */
436 static void iucv_sock_kill(struct sock
*sk
)
438 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
441 iucv_sock_unlink(&iucv_sk_list
, sk
);
442 sock_set_flag(sk
, SOCK_DEAD
);
446 /* Terminate an IUCV path */
447 static void iucv_sever_path(struct sock
*sk
, int with_user_data
)
449 unsigned char user_data
[16];
450 struct iucv_sock
*iucv
= iucv_sk(sk
);
451 struct iucv_path
*path
= iucv
->path
;
455 if (with_user_data
) {
456 low_nmcpy(user_data
, iucv
->src_name
);
457 high_nmcpy(user_data
, iucv
->dst_name
);
458 ASCEBC(user_data
, sizeof(user_data
));
459 pr_iucv
->path_sever(path
, user_data
);
461 pr_iucv
->path_sever(path
, NULL
);
462 iucv_path_free(path
);
466 /* Send FIN through an IUCV socket for HIPER transport */
467 static int iucv_send_ctrl(struct sock
*sk
, u8 flags
)
473 blen
= sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
;
474 skb
= sock_alloc_send_skb(sk
, blen
, 1, &err
);
476 skb_reserve(skb
, blen
);
477 err
= afiucv_hs_send(NULL
, sk
, skb
, flags
);
482 /* Close an IUCV socket */
483 static void iucv_sock_close(struct sock
*sk
)
485 struct iucv_sock
*iucv
= iucv_sk(sk
);
491 switch (sk
->sk_state
) {
493 iucv_sock_cleanup_listen(sk
);
497 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
498 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
499 sk
->sk_state
= IUCV_DISCONN
;
500 sk
->sk_state_change(sk
);
502 case IUCV_DISCONN
: /* fall through */
503 sk
->sk_state
= IUCV_CLOSING
;
504 sk
->sk_state_change(sk
);
506 if (!err
&& !skb_queue_empty(&iucv
->send_skb_q
)) {
507 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
508 timeo
= sk
->sk_lingertime
;
510 timeo
= IUCV_DISCONN_TIMEOUT
;
512 iucv_sock_in_state(sk
, IUCV_CLOSED
, 0),
516 case IUCV_CLOSING
: /* fall through */
517 sk
->sk_state
= IUCV_CLOSED
;
518 sk
->sk_state_change(sk
);
520 sk
->sk_err
= ECONNRESET
;
521 sk
->sk_state_change(sk
);
523 skb_queue_purge(&iucv
->send_skb_q
);
524 skb_queue_purge(&iucv
->backlog_skb_q
);
526 default: /* fall through */
527 iucv_sever_path(sk
, 1);
531 dev_put(iucv
->hs_dev
);
533 sk
->sk_bound_dev_if
= 0;
536 /* mark socket for deletion by iucv_sock_kill() */
537 sock_set_flag(sk
, SOCK_ZAPPED
);
542 static void iucv_sock_init(struct sock
*sk
, struct sock
*parent
)
545 sk
->sk_type
= parent
->sk_type
;
548 static struct sock
*iucv_sock_alloc(struct socket
*sock
, int proto
, gfp_t prio
)
551 struct iucv_sock
*iucv
;
553 sk
= sk_alloc(&init_net
, PF_IUCV
, prio
, &iucv_proto
);
558 sock_init_data(sock
, sk
);
559 INIT_LIST_HEAD(&iucv
->accept_q
);
560 spin_lock_init(&iucv
->accept_q_lock
);
561 skb_queue_head_init(&iucv
->send_skb_q
);
562 INIT_LIST_HEAD(&iucv
->message_q
.list
);
563 spin_lock_init(&iucv
->message_q
.lock
);
564 skb_queue_head_init(&iucv
->backlog_skb_q
);
566 atomic_set(&iucv
->pendings
, 0);
569 atomic_set(&iucv
->msg_sent
, 0);
570 atomic_set(&iucv
->msg_recv
, 0);
572 iucv
->sk_txnotify
= afiucv_hs_callback_txnotify
;
573 memset(&iucv
->src_user_id
, 0, 32);
575 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
577 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
579 sk
->sk_destruct
= iucv_sock_destruct
;
580 sk
->sk_sndtimeo
= IUCV_CONN_TIMEOUT
;
581 sk
->sk_allocation
= GFP_DMA
;
583 sock_reset_flag(sk
, SOCK_ZAPPED
);
585 sk
->sk_protocol
= proto
;
586 sk
->sk_state
= IUCV_OPEN
;
588 iucv_sock_link(&iucv_sk_list
, sk
);
592 /* Create an IUCV socket */
593 static int iucv_sock_create(struct net
*net
, struct socket
*sock
, int protocol
,
598 if (protocol
&& protocol
!= PF_IUCV
)
599 return -EPROTONOSUPPORT
;
601 sock
->state
= SS_UNCONNECTED
;
603 switch (sock
->type
) {
605 sock
->ops
= &iucv_sock_ops
;
608 /* currently, proto ops can handle both sk types */
609 sock
->ops
= &iucv_sock_ops
;
612 return -ESOCKTNOSUPPORT
;
615 sk
= iucv_sock_alloc(sock
, protocol
, GFP_KERNEL
);
619 iucv_sock_init(sk
, NULL
);
624 void iucv_sock_link(struct iucv_sock_list
*l
, struct sock
*sk
)
626 write_lock_bh(&l
->lock
);
627 sk_add_node(sk
, &l
->head
);
628 write_unlock_bh(&l
->lock
);
631 void iucv_sock_unlink(struct iucv_sock_list
*l
, struct sock
*sk
)
633 write_lock_bh(&l
->lock
);
634 sk_del_node_init(sk
);
635 write_unlock_bh(&l
->lock
);
638 void iucv_accept_enqueue(struct sock
*parent
, struct sock
*sk
)
641 struct iucv_sock
*par
= iucv_sk(parent
);
644 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
645 list_add_tail(&iucv_sk(sk
)->accept_q
, &par
->accept_q
);
646 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
647 iucv_sk(sk
)->parent
= parent
;
648 sk_acceptq_added(parent
);
651 void iucv_accept_unlink(struct sock
*sk
)
654 struct iucv_sock
*par
= iucv_sk(iucv_sk(sk
)->parent
);
656 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
657 list_del_init(&iucv_sk(sk
)->accept_q
);
658 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
659 sk_acceptq_removed(iucv_sk(sk
)->parent
);
660 iucv_sk(sk
)->parent
= NULL
;
664 struct sock
*iucv_accept_dequeue(struct sock
*parent
, struct socket
*newsock
)
666 struct iucv_sock
*isk
, *n
;
669 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
670 sk
= (struct sock
*) isk
;
673 if (sk
->sk_state
== IUCV_CLOSED
) {
674 iucv_accept_unlink(sk
);
679 if (sk
->sk_state
== IUCV_CONNECTED
||
680 sk
->sk_state
== IUCV_DISCONN
||
682 iucv_accept_unlink(sk
);
684 sock_graft(sk
, newsock
);
695 /* Bind an unbound socket */
696 static int iucv_sock_bind(struct socket
*sock
, struct sockaddr
*addr
,
699 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
700 struct sock
*sk
= sock
->sk
;
701 struct iucv_sock
*iucv
;
703 struct net_device
*dev
;
706 /* Verify the input sockaddr */
707 if (!addr
|| addr
->sa_family
!= AF_IUCV
)
711 if (sk
->sk_state
!= IUCV_OPEN
) {
716 write_lock_bh(&iucv_sk_list
.lock
);
719 if (__iucv_get_sock_by_name(sa
->siucv_name
)) {
726 /* Bind the socket */
728 if (!memcmp(sa
->siucv_user_id
, iucv_userid
, 8))
729 goto vm_bind
; /* VM IUCV transport */
731 /* try hiper transport */
732 memcpy(uid
, sa
->siucv_user_id
, sizeof(uid
));
735 for_each_netdev_rcu(&init_net
, dev
) {
736 if (!memcmp(dev
->perm_addr
, uid
, 8)) {
737 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
738 memcpy(iucv
->src_user_id
, sa
->siucv_user_id
, 8);
739 sk
->sk_bound_dev_if
= dev
->ifindex
;
742 sk
->sk_state
= IUCV_BOUND
;
743 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
745 iucv
->msglimit
= IUCV_HIPER_MSGLIM_DEFAULT
;
753 /* use local userid for backward compat */
754 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
755 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
756 sk
->sk_state
= IUCV_BOUND
;
757 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
759 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
762 /* found no dev to bind */
765 /* Release the socket list lock */
766 write_unlock_bh(&iucv_sk_list
.lock
);
772 /* Automatically bind an unbound socket */
773 static int iucv_sock_autobind(struct sock
*sk
)
775 struct iucv_sock
*iucv
= iucv_sk(sk
);
779 if (unlikely(!pr_iucv
))
782 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
784 write_lock_bh(&iucv_sk_list
.lock
);
786 sprintf(name
, "%08x", atomic_inc_return(&iucv_sk_list
.autobind_name
));
787 while (__iucv_get_sock_by_name(name
)) {
788 sprintf(name
, "%08x",
789 atomic_inc_return(&iucv_sk_list
.autobind_name
));
792 write_unlock_bh(&iucv_sk_list
.lock
);
794 memcpy(&iucv
->src_name
, name
, 8);
797 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
802 static int afiucv_path_connect(struct socket
*sock
, struct sockaddr
*addr
)
804 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
805 struct sock
*sk
= sock
->sk
;
806 struct iucv_sock
*iucv
= iucv_sk(sk
);
807 unsigned char user_data
[16];
810 high_nmcpy(user_data
, sa
->siucv_name
);
811 low_nmcpy(user_data
, iucv
->src_name
);
812 ASCEBC(user_data
, sizeof(user_data
));
815 iucv
->path
= iucv_path_alloc(iucv
->msglimit
,
816 IUCV_IPRMDATA
, GFP_KERNEL
);
821 err
= pr_iucv
->path_connect(iucv
->path
, &af_iucv_handler
,
822 sa
->siucv_user_id
, NULL
, user_data
,
825 iucv_path_free(iucv
->path
);
828 case 0x0b: /* Target communicator is not logged on */
831 case 0x0d: /* Max connections for this guest exceeded */
832 case 0x0e: /* Max connections for target guest exceeded */
835 case 0x0f: /* Missing IUCV authorization */
847 /* Connect an unconnected socket */
848 static int iucv_sock_connect(struct socket
*sock
, struct sockaddr
*addr
,
851 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
852 struct sock
*sk
= sock
->sk
;
853 struct iucv_sock
*iucv
= iucv_sk(sk
);
856 if (addr
->sa_family
!= AF_IUCV
|| alen
< sizeof(struct sockaddr_iucv
))
859 if (sk
->sk_state
!= IUCV_OPEN
&& sk
->sk_state
!= IUCV_BOUND
)
862 if (sk
->sk_state
== IUCV_OPEN
&&
863 iucv
->transport
== AF_IUCV_TRANS_HIPER
)
864 return -EBADFD
; /* explicit bind required */
866 if (sk
->sk_type
!= SOCK_STREAM
&& sk
->sk_type
!= SOCK_SEQPACKET
)
869 if (sk
->sk_state
== IUCV_OPEN
) {
870 err
= iucv_sock_autobind(sk
);
877 /* Set the destination information */
878 memcpy(iucv
->dst_user_id
, sa
->siucv_user_id
, 8);
879 memcpy(iucv
->dst_name
, sa
->siucv_name
, 8);
881 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
882 err
= iucv_send_ctrl(sock
->sk
, AF_IUCV_FLAG_SYN
);
884 err
= afiucv_path_connect(sock
, addr
);
888 if (sk
->sk_state
!= IUCV_CONNECTED
)
889 err
= iucv_sock_wait(sk
, iucv_sock_in_state(sk
, IUCV_CONNECTED
,
891 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
893 if (sk
->sk_state
== IUCV_DISCONN
|| sk
->sk_state
== IUCV_CLOSED
)
896 if (err
&& iucv
->transport
== AF_IUCV_TRANS_IUCV
)
897 iucv_sever_path(sk
, 0);
904 /* Move a socket into listening state. */
905 static int iucv_sock_listen(struct socket
*sock
, int backlog
)
907 struct sock
*sk
= sock
->sk
;
913 if (sk
->sk_state
!= IUCV_BOUND
)
916 if (sock
->type
!= SOCK_STREAM
&& sock
->type
!= SOCK_SEQPACKET
)
919 sk
->sk_max_ack_backlog
= backlog
;
920 sk
->sk_ack_backlog
= 0;
921 sk
->sk_state
= IUCV_LISTEN
;
929 /* Accept a pending connection */
930 static int iucv_sock_accept(struct socket
*sock
, struct socket
*newsock
,
933 DECLARE_WAITQUEUE(wait
, current
);
934 struct sock
*sk
= sock
->sk
, *nsk
;
938 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
940 if (sk
->sk_state
!= IUCV_LISTEN
) {
945 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
947 /* Wait for an incoming connection */
948 add_wait_queue_exclusive(sk_sleep(sk
), &wait
);
949 while (!(nsk
= iucv_accept_dequeue(sk
, newsock
))) {
950 set_current_state(TASK_INTERRUPTIBLE
);
957 timeo
= schedule_timeout(timeo
);
958 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
960 if (sk
->sk_state
!= IUCV_LISTEN
) {
965 if (signal_pending(current
)) {
966 err
= sock_intr_errno(timeo
);
971 set_current_state(TASK_RUNNING
);
972 remove_wait_queue(sk_sleep(sk
), &wait
);
977 newsock
->state
= SS_CONNECTED
;
984 static int iucv_sock_getname(struct socket
*sock
, struct sockaddr
*addr
,
987 struct sockaddr_iucv
*siucv
= (struct sockaddr_iucv
*) addr
;
988 struct sock
*sk
= sock
->sk
;
989 struct iucv_sock
*iucv
= iucv_sk(sk
);
991 addr
->sa_family
= AF_IUCV
;
992 *len
= sizeof(struct sockaddr_iucv
);
995 memcpy(siucv
->siucv_user_id
, iucv
->dst_user_id
, 8);
996 memcpy(siucv
->siucv_name
, iucv
->dst_name
, 8);
998 memcpy(siucv
->siucv_user_id
, iucv
->src_user_id
, 8);
999 memcpy(siucv
->siucv_name
, iucv
->src_name
, 8);
1001 memset(&siucv
->siucv_port
, 0, sizeof(siucv
->siucv_port
));
1002 memset(&siucv
->siucv_addr
, 0, sizeof(siucv
->siucv_addr
));
1003 memset(&siucv
->siucv_nodeid
, 0, sizeof(siucv
->siucv_nodeid
));
1009 * iucv_send_iprm() - Send socket data in parameter list of an iucv message.
1011 * @msg: Pointer to a struct iucv_message
1012 * @skb: The socket data to send, skb->len MUST BE <= 7
1014 * Send the socket data in the parameter list in the iucv message
1015 * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter
1016 * list and the socket data len at index 7 (last byte).
1017 * See also iucv_msg_length().
1019 * Returns the error code from the iucv_message_send() call.
1021 static int iucv_send_iprm(struct iucv_path
*path
, struct iucv_message
*msg
,
1022 struct sk_buff
*skb
)
1026 memcpy(prmdata
, (void *) skb
->data
, skb
->len
);
1027 prmdata
[7] = 0xff - (u8
) skb
->len
;
1028 return pr_iucv
->message_send(path
, msg
, IUCV_IPRMDATA
, 0,
1029 (void *) prmdata
, 8);
1032 static int iucv_sock_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
1033 struct msghdr
*msg
, size_t len
)
1035 struct sock
*sk
= sock
->sk
;
1036 struct iucv_sock
*iucv
= iucv_sk(sk
);
1037 struct sk_buff
*skb
;
1038 struct iucv_message txmsg
;
1039 struct cmsghdr
*cmsg
;
1045 int noblock
= msg
->msg_flags
& MSG_DONTWAIT
;
1047 err
= sock_error(sk
);
1051 if (msg
->msg_flags
& MSG_OOB
)
1054 /* SOCK_SEQPACKET: we do not support segmented records */
1055 if (sk
->sk_type
== SOCK_SEQPACKET
&& !(msg
->msg_flags
& MSG_EOR
))
1060 if (sk
->sk_shutdown
& SEND_SHUTDOWN
) {
1065 /* Return if the socket is not in connected state */
1066 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1071 /* initialize defaults */
1072 cmsg_done
= 0; /* check for duplicate headers */
1075 /* iterate over control messages */
1076 for (cmsg
= CMSG_FIRSTHDR(msg
); cmsg
;
1077 cmsg
= CMSG_NXTHDR(msg
, cmsg
)) {
1079 if (!CMSG_OK(msg
, cmsg
)) {
1084 if (cmsg
->cmsg_level
!= SOL_IUCV
)
1087 if (cmsg
->cmsg_type
& cmsg_done
) {
1091 cmsg_done
|= cmsg
->cmsg_type
;
1093 switch (cmsg
->cmsg_type
) {
1094 case SCM_IUCV_TRGCLS
:
1095 if (cmsg
->cmsg_len
!= CMSG_LEN(TRGCLS_SIZE
)) {
1100 /* set iucv message target class */
1101 memcpy(&txmsg
.class,
1102 (void *) CMSG_DATA(cmsg
), TRGCLS_SIZE
);
1113 /* allocate one skb for each iucv message:
1114 * this is fine for SOCK_SEQPACKET (unless we want to support
1115 * segmented records using the MSG_EOR flag), but
1116 * for SOCK_STREAM we might want to improve it in future */
1117 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
1118 skb
= sock_alloc_send_skb(sk
,
1119 len
+ sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
,
1122 skb
= sock_alloc_send_skb(sk
, len
, noblock
, &err
);
1127 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
1128 skb_reserve(skb
, sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
);
1129 if (memcpy_fromiovec(skb_put(skb
, len
), msg
->msg_iov
, len
)) {
1134 /* wait if outstanding messages for iucv path has reached */
1135 timeo
= sock_sndtimeo(sk
, noblock
);
1136 err
= iucv_sock_wait(sk
, iucv_below_msglim(sk
), timeo
);
1140 /* return -ECONNRESET if the socket is no longer connected */
1141 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1146 /* increment and save iucv message tag for msg_completion cbk */
1147 txmsg
.tag
= iucv
->send_tag
++;
1148 memcpy(CB_TAG(skb
), &txmsg
.tag
, CB_TAG_LEN
);
1150 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1151 atomic_inc(&iucv
->msg_sent
);
1152 err
= afiucv_hs_send(&txmsg
, sk
, skb
, 0);
1154 atomic_dec(&iucv
->msg_sent
);
1159 skb_queue_tail(&iucv
->send_skb_q
, skb
);
1161 if (((iucv
->path
->flags
& IUCV_IPRMDATA
) & iucv
->flags
)
1163 err
= iucv_send_iprm(iucv
->path
, &txmsg
, skb
);
1165 /* on success: there is no message_complete callback
1166 * for an IPRMDATA msg; remove skb from send queue */
1168 skb_unlink(skb
, &iucv
->send_skb_q
);
1172 /* this error should never happen since the
1173 * IUCV_IPRMDATA path flag is set... sever path */
1175 pr_iucv
->path_sever(iucv
->path
, NULL
);
1176 skb_unlink(skb
, &iucv
->send_skb_q
);
1181 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
, 0, 0,
1182 (void *) skb
->data
, skb
->len
);
1186 memcpy(user_id
, iucv
->dst_user_id
, 8);
1188 memcpy(appl_id
, iucv
->dst_name
, 8);
1189 pr_err("Application %s on z/VM guest %s"
1190 " exceeds message limit\n",
1195 skb_unlink(skb
, &iucv
->send_skb_q
);
1210 /* iucv_fragment_skb() - Fragment a single IUCV message into multiple skb's
1212 * Locking: must be called with message_q.lock held
1214 static int iucv_fragment_skb(struct sock
*sk
, struct sk_buff
*skb
, int len
)
1216 int dataleft
, size
, copied
= 0;
1217 struct sk_buff
*nskb
;
1221 if (dataleft
>= sk
->sk_rcvbuf
/ 4)
1222 size
= sk
->sk_rcvbuf
/ 4;
1226 nskb
= alloc_skb(size
, GFP_ATOMIC
| GFP_DMA
);
1230 /* copy target class to control buffer of new skb */
1231 memcpy(CB_TRGCLS(nskb
), CB_TRGCLS(skb
), CB_TRGCLS_LEN
);
1233 /* copy data fragment */
1234 memcpy(nskb
->data
, skb
->data
+ copied
, size
);
1238 skb_reset_transport_header(nskb
);
1239 skb_reset_network_header(nskb
);
1242 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, nskb
);
1248 /* iucv_process_message() - Receive a single outstanding IUCV message
1250 * Locking: must be called with message_q.lock held
1252 static void iucv_process_message(struct sock
*sk
, struct sk_buff
*skb
,
1253 struct iucv_path
*path
,
1254 struct iucv_message
*msg
)
1259 len
= iucv_msg_length(msg
);
1261 /* store msg target class in the second 4 bytes of skb ctrl buffer */
1262 /* Note: the first 4 bytes are reserved for msg tag */
1263 memcpy(CB_TRGCLS(skb
), &msg
->class, CB_TRGCLS_LEN
);
1265 /* check for special IPRM messages (e.g. iucv_sock_shutdown) */
1266 if ((msg
->flags
& IUCV_IPRMDATA
) && len
> 7) {
1267 if (memcmp(msg
->rmmsg
, iprm_shutdown
, 8) == 0) {
1272 rc
= pr_iucv
->message_receive(path
, msg
,
1273 msg
->flags
& IUCV_IPRMDATA
,
1274 skb
->data
, len
, NULL
);
1279 /* we need to fragment iucv messages for SOCK_STREAM only;
1280 * for SOCK_SEQPACKET, it is only relevant if we support
1281 * record segmentation using MSG_EOR (see also recvmsg()) */
1282 if (sk
->sk_type
== SOCK_STREAM
&&
1283 skb
->truesize
>= sk
->sk_rcvbuf
/ 4) {
1284 rc
= iucv_fragment_skb(sk
, skb
, len
);
1288 pr_iucv
->path_sever(path
, NULL
);
1291 skb
= skb_dequeue(&iucv_sk(sk
)->backlog_skb_q
);
1293 skb_reset_transport_header(skb
);
1294 skb_reset_network_header(skb
);
1299 if (sock_queue_rcv_skb(sk
, skb
))
1300 skb_queue_head(&iucv_sk(sk
)->backlog_skb_q
, skb
);
1303 /* iucv_process_message_q() - Process outstanding IUCV messages
1305 * Locking: must be called with message_q.lock held
1307 static void iucv_process_message_q(struct sock
*sk
)
1309 struct iucv_sock
*iucv
= iucv_sk(sk
);
1310 struct sk_buff
*skb
;
1311 struct sock_msg_q
*p
, *n
;
1313 list_for_each_entry_safe(p
, n
, &iucv
->message_q
.list
, list
) {
1314 skb
= alloc_skb(iucv_msg_length(&p
->msg
), GFP_ATOMIC
| GFP_DMA
);
1317 iucv_process_message(sk
, skb
, p
->path
, &p
->msg
);
1320 if (!skb_queue_empty(&iucv
->backlog_skb_q
))
1325 static int iucv_sock_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
1326 struct msghdr
*msg
, size_t len
, int flags
)
1328 int noblock
= flags
& MSG_DONTWAIT
;
1329 struct sock
*sk
= sock
->sk
;
1330 struct iucv_sock
*iucv
= iucv_sk(sk
);
1331 unsigned int copied
, rlen
;
1332 struct sk_buff
*skb
, *rskb
, *cskb
;
1335 if ((sk
->sk_state
== IUCV_DISCONN
) &&
1336 skb_queue_empty(&iucv
->backlog_skb_q
) &&
1337 skb_queue_empty(&sk
->sk_receive_queue
) &&
1338 list_empty(&iucv
->message_q
.list
))
1341 if (flags
& (MSG_OOB
))
1344 /* receive/dequeue next skb:
1345 * the function understands MSG_PEEK and, thus, does not dequeue skb */
1346 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
1348 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1353 rlen
= skb
->len
; /* real length of skb */
1354 copied
= min_t(unsigned int, rlen
, len
);
1356 sk
->sk_shutdown
= sk
->sk_shutdown
| RCV_SHUTDOWN
;
1359 if (skb_copy_datagram_iovec(cskb
, 0, msg
->msg_iov
, copied
)) {
1360 if (!(flags
& MSG_PEEK
))
1361 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1365 /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */
1366 if (sk
->sk_type
== SOCK_SEQPACKET
) {
1368 msg
->msg_flags
|= MSG_TRUNC
;
1369 /* each iucv message contains a complete record */
1370 msg
->msg_flags
|= MSG_EOR
;
1373 /* create control message to store iucv msg target class:
1374 * get the trgcls from the control buffer of the skb due to
1375 * fragmentation of original iucv message. */
1376 err
= put_cmsg(msg
, SOL_IUCV
, SCM_IUCV_TRGCLS
,
1377 CB_TRGCLS_LEN
, CB_TRGCLS(skb
));
1379 if (!(flags
& MSG_PEEK
))
1380 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1384 /* Mark read part of skb as used */
1385 if (!(flags
& MSG_PEEK
)) {
1387 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
1388 if (sk
->sk_type
== SOCK_STREAM
) {
1389 skb_pull(skb
, copied
);
1391 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1397 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1398 atomic_inc(&iucv
->msg_recv
);
1399 if (atomic_read(&iucv
->msg_recv
) > iucv
->msglimit
) {
1401 iucv_sock_close(sk
);
1406 /* Queue backlog skbs */
1407 spin_lock_bh(&iucv
->message_q
.lock
);
1408 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1410 if (sock_queue_rcv_skb(sk
, rskb
)) {
1411 skb_queue_head(&iucv
->backlog_skb_q
,
1415 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1418 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
1419 if (!list_empty(&iucv
->message_q
.list
))
1420 iucv_process_message_q(sk
);
1421 if (atomic_read(&iucv
->msg_recv
) >=
1422 iucv
->msglimit
/ 2) {
1423 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_WIN
);
1425 sk
->sk_state
= IUCV_DISCONN
;
1426 sk
->sk_state_change(sk
);
1430 spin_unlock_bh(&iucv
->message_q
.lock
);
1434 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
1435 if (sk
->sk_type
== SOCK_SEQPACKET
&& (flags
& MSG_TRUNC
))
1441 static inline unsigned int iucv_accept_poll(struct sock
*parent
)
1443 struct iucv_sock
*isk
, *n
;
1446 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
1447 sk
= (struct sock
*) isk
;
1449 if (sk
->sk_state
== IUCV_CONNECTED
)
1450 return POLLIN
| POLLRDNORM
;
1456 unsigned int iucv_sock_poll(struct file
*file
, struct socket
*sock
,
1459 struct sock
*sk
= sock
->sk
;
1460 unsigned int mask
= 0;
1462 sock_poll_wait(file
, sk_sleep(sk
), wait
);
1464 if (sk
->sk_state
== IUCV_LISTEN
)
1465 return iucv_accept_poll(sk
);
1467 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
))
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
) {
1544 err
= pr_iucv
->path_quiesce(iucv
->path
, NULL
);
1547 /* skb_queue_purge(&sk->sk_receive_queue); */
1549 skb_queue_purge(&sk
->sk_receive_queue
);
1552 /* Wake up anyone sleeping in poll */
1553 sk
->sk_state_change(sk
);
1560 static int iucv_sock_release(struct socket
*sock
)
1562 struct sock
*sk
= sock
->sk
;
1568 iucv_sock_close(sk
);
1575 /* getsockopt and setsockopt */
1576 static int iucv_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
1577 char __user
*optval
, unsigned int optlen
)
1579 struct sock
*sk
= sock
->sk
;
1580 struct iucv_sock
*iucv
= iucv_sk(sk
);
1584 if (level
!= SOL_IUCV
)
1585 return -ENOPROTOOPT
;
1587 if (optlen
< sizeof(int))
1590 if (get_user(val
, (int __user
*) optval
))
1597 case SO_IPRMDATA_MSG
:
1599 iucv
->flags
|= IUCV_IPRMDATA
;
1601 iucv
->flags
&= ~IUCV_IPRMDATA
;
1604 switch (sk
->sk_state
) {
1607 if (val
< 1 || val
> (u16
)(~0))
1610 iucv
->msglimit
= val
;
1626 static int iucv_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
1627 char __user
*optval
, int __user
*optlen
)
1629 struct sock
*sk
= sock
->sk
;
1630 struct iucv_sock
*iucv
= iucv_sk(sk
);
1634 if (level
!= SOL_IUCV
)
1635 return -ENOPROTOOPT
;
1637 if (get_user(len
, optlen
))
1643 len
= min_t(unsigned int, len
, sizeof(int));
1646 case SO_IPRMDATA_MSG
:
1647 val
= (iucv
->flags
& IUCV_IPRMDATA
) ? 1 : 0;
1651 val
= (iucv
->path
!= NULL
) ? iucv
->path
->msglim
/* connected */
1652 : iucv
->msglimit
; /* default */
1656 if (sk
->sk_state
== IUCV_OPEN
)
1658 val
= (iucv
->hs_dev
) ? iucv
->hs_dev
->mtu
-
1659 sizeof(struct af_iucv_trans_hdr
) - ETH_HLEN
:
1663 return -ENOPROTOOPT
;
1666 if (put_user(len
, optlen
))
1668 if (copy_to_user(optval
, &val
, len
))
1675 /* Callback wrappers - called from iucv base support */
1676 static int iucv_callback_connreq(struct iucv_path
*path
,
1677 u8 ipvmid
[8], u8 ipuser
[16])
1679 unsigned char user_data
[16];
1680 unsigned char nuser_data
[16];
1681 unsigned char src_name
[8];
1682 struct hlist_node
*node
;
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
, node
, &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
, 1);
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 (!memcmp(&msg
->tag
, CB_TAG(list_skb
), CB_TAG_LEN
)) {
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 */
1946 afiucv_swap_src_dest(skb
);
1947 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
1948 err
= dev_queue_xmit(skb
);
1953 niucv
= iucv_sk(nsk
);
1954 iucv_sock_init(nsk
, sk
);
1955 niucv
->transport
= AF_IUCV_TRANS_HIPER
;
1956 niucv
->msglimit
= iucv
->msglimit
;
1957 if (!trans_hdr
->window
)
1958 niucv
->msglimit_peer
= IUCV_HIPER_MSGLIM_DEFAULT
;
1960 niucv
->msglimit_peer
= trans_hdr
->window
;
1961 memcpy(niucv
->dst_name
, trans_hdr
->srcAppName
, 8);
1962 memcpy(niucv
->dst_user_id
, trans_hdr
->srcUserID
, 8);
1963 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1964 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1965 nsk
->sk_bound_dev_if
= sk
->sk_bound_dev_if
;
1966 niucv
->hs_dev
= iucv
->hs_dev
;
1967 dev_hold(niucv
->hs_dev
);
1968 afiucv_swap_src_dest(skb
);
1969 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
;
1970 trans_hdr
->window
= niucv
->msglimit
;
1971 /* if receiver acks the xmit connection is established */
1972 err
= dev_queue_xmit(skb
);
1974 iucv_accept_enqueue(sk
, nsk
);
1975 nsk
->sk_state
= IUCV_CONNECTED
;
1976 sk
->sk_data_ready(sk
, 1);
1978 iucv_sock_kill(nsk
);
1982 return NET_RX_SUCCESS
;
1986 * afiucv_hs_callback_synack() - react on received SYN-ACK
1988 static int afiucv_hs_callback_synack(struct sock
*sk
, struct sk_buff
*skb
)
1990 struct iucv_sock
*iucv
= iucv_sk(sk
);
1991 struct af_iucv_trans_hdr
*trans_hdr
=
1992 (struct af_iucv_trans_hdr
*)skb
->data
;
1996 if (sk
->sk_state
!= IUCV_BOUND
)
1999 iucv
->msglimit_peer
= trans_hdr
->window
;
2000 sk
->sk_state
= IUCV_CONNECTED
;
2001 sk
->sk_state_change(sk
);
2005 return NET_RX_SUCCESS
;
2009 * afiucv_hs_callback_synfin() - react on received SYN_FIN
2011 static int afiucv_hs_callback_synfin(struct sock
*sk
, struct sk_buff
*skb
)
2013 struct iucv_sock
*iucv
= iucv_sk(sk
);
2017 if (sk
->sk_state
!= IUCV_BOUND
)
2020 sk
->sk_state
= IUCV_DISCONN
;
2021 sk
->sk_state_change(sk
);
2025 return NET_RX_SUCCESS
;
2029 * afiucv_hs_callback_fin() - react on received FIN
2031 static int afiucv_hs_callback_fin(struct sock
*sk
, struct sk_buff
*skb
)
2033 struct iucv_sock
*iucv
= iucv_sk(sk
);
2035 /* other end of connection closed */
2039 if (sk
->sk_state
== IUCV_CONNECTED
) {
2040 sk
->sk_state
= IUCV_DISCONN
;
2041 sk
->sk_state_change(sk
);
2046 return NET_RX_SUCCESS
;
2050 * afiucv_hs_callback_win() - react on received WIN
2052 static int afiucv_hs_callback_win(struct sock
*sk
, struct sk_buff
*skb
)
2054 struct iucv_sock
*iucv
= iucv_sk(sk
);
2055 struct af_iucv_trans_hdr
*trans_hdr
=
2056 (struct af_iucv_trans_hdr
*)skb
->data
;
2059 return NET_RX_SUCCESS
;
2061 if (sk
->sk_state
!= IUCV_CONNECTED
)
2062 return NET_RX_SUCCESS
;
2064 atomic_sub(trans_hdr
->window
, &iucv
->msg_sent
);
2065 iucv_sock_wake_msglim(sk
);
2066 return NET_RX_SUCCESS
;
2070 * afiucv_hs_callback_rx() - react on received data
2072 static int afiucv_hs_callback_rx(struct sock
*sk
, struct sk_buff
*skb
)
2074 struct iucv_sock
*iucv
= iucv_sk(sk
);
2078 return NET_RX_SUCCESS
;
2081 if (sk
->sk_state
!= IUCV_CONNECTED
) {
2083 return NET_RX_SUCCESS
;
2086 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
2088 return NET_RX_SUCCESS
;
2091 /* write stuff from iucv_msg to skb cb */
2092 if (skb
->len
< sizeof(struct af_iucv_trans_hdr
)) {
2094 return NET_RX_SUCCESS
;
2096 skb_pull(skb
, sizeof(struct af_iucv_trans_hdr
));
2097 skb_reset_transport_header(skb
);
2098 skb_reset_network_header(skb
);
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
)
2119 struct hlist_node
*node
;
2121 struct iucv_sock
*iucv
;
2122 struct af_iucv_trans_hdr
*trans_hdr
;
2126 skb_pull(skb
, ETH_HLEN
);
2127 trans_hdr
= (struct af_iucv_trans_hdr
*)skb
->data
;
2128 EBCASC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
2129 EBCASC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
2130 EBCASC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
2131 EBCASC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
2132 memset(nullstring
, 0, sizeof(nullstring
));
2135 read_lock(&iucv_sk_list
.lock
);
2136 sk_for_each(sk
, node
, &iucv_sk_list
.head
) {
2137 if (trans_hdr
->flags
== AF_IUCV_FLAG_SYN
) {
2138 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2139 trans_hdr
->destAppName
, 8)) &&
2140 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2141 trans_hdr
->destUserID
, 8)) &&
2142 (!memcmp(&iucv_sk(sk
)->dst_name
, nullstring
, 8)) &&
2143 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2149 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2150 trans_hdr
->destAppName
, 8)) &&
2151 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2152 trans_hdr
->destUserID
, 8)) &&
2153 (!memcmp(&iucv_sk(sk
)->dst_name
,
2154 trans_hdr
->srcAppName
, 8)) &&
2155 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2156 trans_hdr
->srcUserID
, 8))) {
2162 read_unlock(&iucv_sk_list
.lock
);
2167 how should we send with no sock
2168 1) send without sock no send rc checking?
2169 2) introduce default sock to handle this cases
2171 SYN -> send SYN|ACK in good case, send SYN|FIN in bad case
2173 SYN|ACK, SYN|FIN, FIN -> no action? */
2175 switch (trans_hdr
->flags
) {
2176 case AF_IUCV_FLAG_SYN
:
2177 /* connect request */
2178 err
= afiucv_hs_callback_syn(sk
, skb
);
2180 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
):
2181 /* connect request confirmed */
2182 err
= afiucv_hs_callback_synack(sk
, skb
);
2184 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
):
2185 /* connect request refused */
2186 err
= afiucv_hs_callback_synfin(sk
, skb
);
2188 case (AF_IUCV_FLAG_FIN
):
2190 err
= afiucv_hs_callback_fin(sk
, skb
);
2192 case (AF_IUCV_FLAG_WIN
):
2193 err
= afiucv_hs_callback_win(sk
, skb
);
2194 if (skb
->len
== sizeof(struct af_iucv_trans_hdr
)) {
2198 /* fall through and receive non-zero length data */
2199 case (AF_IUCV_FLAG_SHT
):
2200 /* shutdown request */
2201 /* fall through and receive zero length data */
2203 /* plain data frame */
2204 memcpy(CB_TRGCLS(skb
), &trans_hdr
->iucv_hdr
.class,
2206 err
= afiucv_hs_callback_rx(sk
, skb
);
2216 * afiucv_hs_callback_txnotify() - handle send notifcations from HiperSockets
2219 static void afiucv_hs_callback_txnotify(struct sk_buff
*skb
,
2220 enum iucv_tx_notify n
)
2222 struct sock
*isk
= skb
->sk
;
2223 struct sock
*sk
= NULL
;
2224 struct iucv_sock
*iucv
= NULL
;
2225 struct sk_buff_head
*list
;
2226 struct sk_buff
*list_skb
;
2227 struct sk_buff
*nskb
;
2228 unsigned long flags
;
2229 struct hlist_node
*node
;
2231 read_lock_irqsave(&iucv_sk_list
.lock
, flags
);
2232 sk_for_each(sk
, node
, &iucv_sk_list
.head
)
2237 read_unlock_irqrestore(&iucv_sk_list
.lock
, flags
);
2239 if (!iucv
|| sock_flag(sk
, SOCK_ZAPPED
))
2242 list
= &iucv
->send_skb_q
;
2243 spin_lock_irqsave(&list
->lock
, flags
);
2244 if (skb_queue_empty(list
))
2246 list_skb
= list
->next
;
2247 nskb
= list_skb
->next
;
2248 while (list_skb
!= (struct sk_buff
*)list
) {
2249 if (skb_shinfo(list_skb
) == skb_shinfo(skb
)) {
2252 __skb_unlink(list_skb
, list
);
2253 kfree_skb(list_skb
);
2254 iucv_sock_wake_msglim(sk
);
2256 case TX_NOTIFY_PENDING
:
2257 atomic_inc(&iucv
->pendings
);
2259 case TX_NOTIFY_DELAYED_OK
:
2260 __skb_unlink(list_skb
, list
);
2261 atomic_dec(&iucv
->pendings
);
2262 if (atomic_read(&iucv
->pendings
) <= 0)
2263 iucv_sock_wake_msglim(sk
);
2264 kfree_skb(list_skb
);
2266 case TX_NOTIFY_UNREACHABLE
:
2267 case TX_NOTIFY_DELAYED_UNREACHABLE
:
2268 case TX_NOTIFY_TPQFULL
: /* not yet used */
2269 case TX_NOTIFY_GENERALERROR
:
2270 case TX_NOTIFY_DELAYED_GENERALERROR
:
2271 __skb_unlink(list_skb
, list
);
2272 kfree_skb(list_skb
);
2273 if (sk
->sk_state
== IUCV_CONNECTED
) {
2274 sk
->sk_state
= IUCV_DISCONN
;
2275 sk
->sk_state_change(sk
);
2285 spin_unlock_irqrestore(&list
->lock
, flags
);
2287 if (sk
->sk_state
== IUCV_CLOSING
) {
2288 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
2289 sk
->sk_state
= IUCV_CLOSED
;
2290 sk
->sk_state_change(sk
);
2297 * afiucv_netdev_event: handle netdev notifier chain events
2299 static int afiucv_netdev_event(struct notifier_block
*this,
2300 unsigned long event
, void *ptr
)
2302 struct net_device
*event_dev
= (struct net_device
*)ptr
;
2303 struct hlist_node
*node
;
2305 struct iucv_sock
*iucv
;
2309 case NETDEV_GOING_DOWN
:
2310 sk_for_each(sk
, node
, &iucv_sk_list
.head
) {
2312 if ((iucv
->hs_dev
== event_dev
) &&
2313 (sk
->sk_state
== IUCV_CONNECTED
)) {
2314 if (event
== NETDEV_GOING_DOWN
)
2315 iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
2316 sk
->sk_state
= IUCV_DISCONN
;
2317 sk
->sk_state_change(sk
);
2322 case NETDEV_UNREGISTER
:
2329 static struct notifier_block afiucv_netdev_notifier
= {
2330 .notifier_call
= afiucv_netdev_event
,
2333 static const struct proto_ops iucv_sock_ops
= {
2335 .owner
= THIS_MODULE
,
2336 .release
= iucv_sock_release
,
2337 .bind
= iucv_sock_bind
,
2338 .connect
= iucv_sock_connect
,
2339 .listen
= iucv_sock_listen
,
2340 .accept
= iucv_sock_accept
,
2341 .getname
= iucv_sock_getname
,
2342 .sendmsg
= iucv_sock_sendmsg
,
2343 .recvmsg
= iucv_sock_recvmsg
,
2344 .poll
= iucv_sock_poll
,
2345 .ioctl
= sock_no_ioctl
,
2346 .mmap
= sock_no_mmap
,
2347 .socketpair
= sock_no_socketpair
,
2348 .shutdown
= iucv_sock_shutdown
,
2349 .setsockopt
= iucv_sock_setsockopt
,
2350 .getsockopt
= iucv_sock_getsockopt
,
2353 static const struct net_proto_family iucv_sock_family_ops
= {
2355 .owner
= THIS_MODULE
,
2356 .create
= iucv_sock_create
,
2359 static struct packet_type iucv_packet_type
= {
2360 .type
= cpu_to_be16(ETH_P_AF_IUCV
),
2361 .func
= afiucv_hs_rcv
,
2364 static int afiucv_iucv_init(void)
2368 err
= pr_iucv
->iucv_register(&af_iucv_handler
, 0);
2371 /* establish dummy device */
2372 af_iucv_driver
.bus
= pr_iucv
->bus
;
2373 err
= driver_register(&af_iucv_driver
);
2376 af_iucv_dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
2381 dev_set_name(af_iucv_dev
, "af_iucv");
2382 af_iucv_dev
->bus
= pr_iucv
->bus
;
2383 af_iucv_dev
->parent
= pr_iucv
->root
;
2384 af_iucv_dev
->release
= (void (*)(struct device
*))kfree
;
2385 af_iucv_dev
->driver
= &af_iucv_driver
;
2386 err
= device_register(af_iucv_dev
);
2392 driver_unregister(&af_iucv_driver
);
2394 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2399 static int __init
afiucv_init(void)
2403 if (MACHINE_IS_VM
) {
2404 cpcmd("QUERY USERID", iucv_userid
, sizeof(iucv_userid
), &err
);
2405 if (unlikely(err
)) {
2407 err
= -EPROTONOSUPPORT
;
2411 pr_iucv
= try_then_request_module(symbol_get(iucv_if
), "iucv");
2413 printk(KERN_WARNING
"iucv_if lookup failed\n");
2414 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2417 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2421 err
= proto_register(&iucv_proto
, 0);
2424 err
= sock_register(&iucv_sock_family_ops
);
2429 err
= afiucv_iucv_init();
2433 register_netdevice_notifier(&afiucv_netdev_notifier
);
2434 dev_add_pack(&iucv_packet_type
);
2438 sock_unregister(PF_IUCV
);
2440 proto_unregister(&iucv_proto
);
2443 symbol_put(iucv_if
);
2447 static void __exit
afiucv_exit(void)
2450 device_unregister(af_iucv_dev
);
2451 driver_unregister(&af_iucv_driver
);
2452 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2453 symbol_put(iucv_if
);
2455 unregister_netdevice_notifier(&afiucv_netdev_notifier
);
2456 dev_remove_pack(&iucv_packet_type
);
2457 sock_unregister(PF_IUCV
);
2458 proto_unregister(&iucv_proto
);
2461 module_init(afiucv_init
);
2462 module_exit(afiucv_exit
);
2464 MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>");
2465 MODULE_DESCRIPTION("IUCV Sockets ver " VERSION
);
2466 MODULE_VERSION(VERSION
);
2467 MODULE_LICENSE("GPL");
2468 MODULE_ALIAS_NETPROTO(PF_IUCV
);