1 // SPDX-License-Identifier: GPL-2.0-only
3 * IUCV protocol stack for Linux on zSeries
5 * Copyright IBM Corp. 2006, 2009
7 * Author(s): Jennifer Hunt <jenhunt@us.ibm.com>
8 * Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
10 * Ursula Braun <ursula.braun@de.ibm.com>
13 #define KMSG_COMPONENT "af_iucv"
14 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
16 #include <linux/module.h>
17 #include <linux/netdevice.h>
18 #include <linux/types.h>
19 #include <linux/list.h>
20 #include <linux/errno.h>
21 #include <linux/kernel.h>
22 #include <linux/sched/signal.h>
23 #include <linux/slab.h>
24 #include <linux/skbuff.h>
25 #include <linux/init.h>
26 #include <linux/poll.h>
27 #include <linux/security.h>
29 #include <asm/ebcdic.h>
30 #include <asm/cpcmd.h>
31 #include <linux/kmod.h>
33 #include <net/iucv/af_iucv.h>
37 static char iucv_userid
[80];
39 static const struct proto_ops iucv_sock_ops
;
41 static struct proto iucv_proto
= {
44 .obj_size
= sizeof(struct iucv_sock
),
47 static struct iucv_interface
*pr_iucv
;
49 /* special AF_IUCV IPRM messages */
50 static const u8 iprm_shutdown
[8] =
51 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
53 #define TRGCLS_SIZE sizeof_field(struct iucv_message, class)
55 #define __iucv_sock_wait(sk, condition, timeo, ret) \
57 DEFINE_WAIT(__wait); \
58 long __timeo = timeo; \
60 prepare_to_wait(sk_sleep(sk), &__wait, TASK_INTERRUPTIBLE); \
61 while (!(condition)) { \
66 if (signal_pending(current)) { \
67 ret = sock_intr_errno(__timeo); \
71 __timeo = schedule_timeout(__timeo); \
73 ret = sock_error(sk); \
77 finish_wait(sk_sleep(sk), &__wait); \
80 #define iucv_sock_wait(sk, condition, timeo) \
84 __iucv_sock_wait(sk, condition, timeo, __ret); \
88 static void iucv_sock_kill(struct sock
*sk
);
89 static void iucv_sock_close(struct sock
*sk
);
90 static void iucv_sever_path(struct sock
*, int);
92 static int afiucv_hs_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
93 struct packet_type
*pt
, struct net_device
*orig_dev
);
94 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
95 struct sk_buff
*skb
, u8 flags
);
96 static void afiucv_hs_callback_txnotify(struct sk_buff
*, enum iucv_tx_notify
);
98 /* Call Back functions */
99 static void iucv_callback_rx(struct iucv_path
*, struct iucv_message
*);
100 static void iucv_callback_txdone(struct iucv_path
*, struct iucv_message
*);
101 static void iucv_callback_connack(struct iucv_path
*, u8
*);
102 static int iucv_callback_connreq(struct iucv_path
*, u8
*, u8
*);
103 static void iucv_callback_connrej(struct iucv_path
*, u8
*);
104 static void iucv_callback_shutdown(struct iucv_path
*, u8
*);
106 static struct iucv_sock_list iucv_sk_list
= {
107 .lock
= __RW_LOCK_UNLOCKED(iucv_sk_list
.lock
),
108 .autobind_name
= ATOMIC_INIT(0)
111 static struct iucv_handler af_iucv_handler
= {
112 .path_pending
= iucv_callback_connreq
,
113 .path_complete
= iucv_callback_connack
,
114 .path_severed
= iucv_callback_connrej
,
115 .message_pending
= iucv_callback_rx
,
116 .message_complete
= iucv_callback_txdone
,
117 .path_quiesced
= iucv_callback_shutdown
,
120 static inline void high_nmcpy(unsigned char *dst
, char *src
)
125 static inline void low_nmcpy(unsigned char *dst
, char *src
)
127 memcpy(&dst
[8], src
, 8);
130 static int afiucv_pm_prepare(struct device
*dev
)
132 #ifdef CONFIG_PM_DEBUG
133 printk(KERN_WARNING
"afiucv_pm_prepare\n");
138 static void afiucv_pm_complete(struct device
*dev
)
140 #ifdef CONFIG_PM_DEBUG
141 printk(KERN_WARNING
"afiucv_pm_complete\n");
146 * afiucv_pm_freeze() - Freeze PM callback
147 * @dev: AFIUCV dummy device
149 * Sever all established IUCV communication pathes
151 static int afiucv_pm_freeze(struct device
*dev
)
153 struct iucv_sock
*iucv
;
156 #ifdef CONFIG_PM_DEBUG
157 printk(KERN_WARNING
"afiucv_pm_freeze\n");
159 read_lock(&iucv_sk_list
.lock
);
160 sk_for_each(sk
, &iucv_sk_list
.head
) {
162 switch (sk
->sk_state
) {
166 iucv_sever_path(sk
, 0);
175 skb_queue_purge(&iucv
->send_skb_q
);
176 skb_queue_purge(&iucv
->backlog_skb_q
);
178 read_unlock(&iucv_sk_list
.lock
);
183 * afiucv_pm_restore_thaw() - Thaw and restore PM callback
184 * @dev: AFIUCV dummy device
186 * socket clean up after freeze
188 static int afiucv_pm_restore_thaw(struct device
*dev
)
192 #ifdef CONFIG_PM_DEBUG
193 printk(KERN_WARNING
"afiucv_pm_restore_thaw\n");
195 read_lock(&iucv_sk_list
.lock
);
196 sk_for_each(sk
, &iucv_sk_list
.head
) {
197 switch (sk
->sk_state
) {
200 sk
->sk_state
= IUCV_DISCONN
;
201 sk
->sk_state_change(sk
);
212 read_unlock(&iucv_sk_list
.lock
);
216 static const struct dev_pm_ops afiucv_pm_ops
= {
217 .prepare
= afiucv_pm_prepare
,
218 .complete
= afiucv_pm_complete
,
219 .freeze
= afiucv_pm_freeze
,
220 .thaw
= afiucv_pm_restore_thaw
,
221 .restore
= afiucv_pm_restore_thaw
,
224 static struct device_driver af_iucv_driver
= {
225 .owner
= THIS_MODULE
,
228 .pm
= &afiucv_pm_ops
,
231 /* dummy device used as trigger for PM functions */
232 static struct device
*af_iucv_dev
;
235 * iucv_msg_length() - Returns the length of an iucv message.
236 * @msg: Pointer to struct iucv_message, MUST NOT be NULL
238 * The function returns the length of the specified iucv message @msg of data
239 * stored in a buffer and of data stored in the parameter list (PRMDATA).
241 * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket
243 * PRMDATA[0..6] socket data (max 7 bytes);
244 * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7])
246 * The socket data length is computed by subtracting the socket data length
248 * If the socket data len is greater 7, then PRMDATA can be used for special
249 * notifications (see iucv_sock_shutdown); and further,
250 * if the socket data len is > 7, the function returns 8.
252 * Use this function to allocate socket buffers to store iucv message data.
254 static inline size_t iucv_msg_length(struct iucv_message
*msg
)
258 if (msg
->flags
& IUCV_IPRMDATA
) {
259 datalen
= 0xff - msg
->rmmsg
[7];
260 return (datalen
< 8) ? datalen
: 8;
266 * iucv_sock_in_state() - check for specific states
267 * @sk: sock structure
268 * @state: first iucv sk state
269 * @state: second iucv sk state
271 * Returns true if the socket in either in the first or second state.
273 static int iucv_sock_in_state(struct sock
*sk
, int state
, int state2
)
275 return (sk
->sk_state
== state
|| sk
->sk_state
== state2
);
279 * iucv_below_msglim() - function to check if messages can be sent
280 * @sk: sock structure
282 * Returns true if the send queue length is lower than the message limit.
283 * Always returns true if the socket is not connected (no iucv path for
284 * checking the message limit).
286 static inline int iucv_below_msglim(struct sock
*sk
)
288 struct iucv_sock
*iucv
= iucv_sk(sk
);
290 if (sk
->sk_state
!= IUCV_CONNECTED
)
292 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
)
293 return (skb_queue_len(&iucv
->send_skb_q
) < iucv
->path
->msglim
);
295 return ((atomic_read(&iucv
->msg_sent
) < iucv
->msglimit_peer
) &&
296 (atomic_read(&iucv
->pendings
) <= 0));
300 * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit
302 static void iucv_sock_wake_msglim(struct sock
*sk
)
304 struct socket_wq
*wq
;
307 wq
= rcu_dereference(sk
->sk_wq
);
308 if (skwq_has_sleeper(wq
))
309 wake_up_interruptible_all(&wq
->wait
);
310 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
315 * afiucv_hs_send() - send a message through HiperSockets transport
317 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
318 struct sk_buff
*skb
, u8 flags
)
320 struct iucv_sock
*iucv
= iucv_sk(sock
);
321 struct af_iucv_trans_hdr
*phs_hdr
;
322 struct sk_buff
*nskb
;
323 int err
, confirm_recv
= 0;
325 phs_hdr
= skb_push(skb
, sizeof(*phs_hdr
));
326 memset(phs_hdr
, 0, sizeof(*phs_hdr
));
327 skb_reset_network_header(skb
);
329 phs_hdr
->magic
= ETH_P_AF_IUCV
;
330 phs_hdr
->version
= 1;
331 phs_hdr
->flags
= flags
;
332 if (flags
== AF_IUCV_FLAG_SYN
)
333 phs_hdr
->window
= iucv
->msglimit
;
334 else if ((flags
== AF_IUCV_FLAG_WIN
) || !flags
) {
335 confirm_recv
= atomic_read(&iucv
->msg_recv
);
336 phs_hdr
->window
= confirm_recv
;
338 phs_hdr
->flags
= phs_hdr
->flags
| AF_IUCV_FLAG_WIN
;
340 memcpy(phs_hdr
->destUserID
, iucv
->dst_user_id
, 8);
341 memcpy(phs_hdr
->destAppName
, iucv
->dst_name
, 8);
342 memcpy(phs_hdr
->srcUserID
, iucv
->src_user_id
, 8);
343 memcpy(phs_hdr
->srcAppName
, iucv
->src_name
, 8);
344 ASCEBC(phs_hdr
->destUserID
, sizeof(phs_hdr
->destUserID
));
345 ASCEBC(phs_hdr
->destAppName
, sizeof(phs_hdr
->destAppName
));
346 ASCEBC(phs_hdr
->srcUserID
, sizeof(phs_hdr
->srcUserID
));
347 ASCEBC(phs_hdr
->srcAppName
, sizeof(phs_hdr
->srcAppName
));
349 memcpy(&phs_hdr
->iucv_hdr
, imsg
, sizeof(struct iucv_message
));
351 skb
->dev
= iucv
->hs_dev
;
357 dev_hard_header(skb
, skb
->dev
, ETH_P_AF_IUCV
, NULL
, NULL
, skb
->len
);
359 if (!(skb
->dev
->flags
& IFF_UP
) || !netif_carrier_ok(skb
->dev
)) {
363 if (skb
->len
> skb
->dev
->mtu
) {
364 if (sock
->sk_type
== SOCK_SEQPACKET
) {
368 skb_trim(skb
, skb
->dev
->mtu
);
370 skb
->protocol
= cpu_to_be16(ETH_P_AF_IUCV
);
372 __skb_header_release(skb
);
373 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
);
395 static struct sock
*__iucv_get_sock_by_name(char *nm
)
399 sk_for_each(sk
, &iucv_sk_list
.head
)
400 if (!memcmp(&iucv_sk(sk
)->src_name
, nm
, 8))
406 static void iucv_sock_destruct(struct sock
*sk
)
408 skb_queue_purge(&sk
->sk_receive_queue
);
409 skb_queue_purge(&sk
->sk_error_queue
);
413 if (!sock_flag(sk
, SOCK_DEAD
)) {
414 pr_err("Attempt to release alive iucv socket %p\n", sk
);
418 WARN_ON(atomic_read(&sk
->sk_rmem_alloc
));
419 WARN_ON(refcount_read(&sk
->sk_wmem_alloc
));
420 WARN_ON(sk
->sk_wmem_queued
);
421 WARN_ON(sk
->sk_forward_alloc
);
425 static void iucv_sock_cleanup_listen(struct sock
*parent
)
429 /* Close non-accepted connections */
430 while ((sk
= iucv_accept_dequeue(parent
, NULL
))) {
435 parent
->sk_state
= IUCV_CLOSED
;
438 /* Kill socket (only if zapped and orphaned) */
439 static void iucv_sock_kill(struct sock
*sk
)
441 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
444 iucv_sock_unlink(&iucv_sk_list
, sk
);
445 sock_set_flag(sk
, SOCK_DEAD
);
449 /* Terminate an IUCV path */
450 static void iucv_sever_path(struct sock
*sk
, int with_user_data
)
452 unsigned char user_data
[16];
453 struct iucv_sock
*iucv
= iucv_sk(sk
);
454 struct iucv_path
*path
= iucv
->path
;
458 if (with_user_data
) {
459 low_nmcpy(user_data
, iucv
->src_name
);
460 high_nmcpy(user_data
, iucv
->dst_name
);
461 ASCEBC(user_data
, sizeof(user_data
));
462 pr_iucv
->path_sever(path
, user_data
);
464 pr_iucv
->path_sever(path
, NULL
);
465 iucv_path_free(path
);
469 /* Send controlling flags through an IUCV socket for HIPER transport */
470 static int iucv_send_ctrl(struct sock
*sk
, u8 flags
)
472 struct iucv_sock
*iucv
= iucv_sk(sk
);
478 blen
= sizeof(struct af_iucv_trans_hdr
) +
479 LL_RESERVED_SPACE(iucv
->hs_dev
);
480 if (sk
->sk_shutdown
& SEND_SHUTDOWN
) {
481 /* controlling flags should be sent anyway */
482 shutdown
= sk
->sk_shutdown
;
483 sk
->sk_shutdown
&= RCV_SHUTDOWN
;
485 skb
= sock_alloc_send_skb(sk
, blen
, 1, &err
);
487 skb_reserve(skb
, blen
);
488 err
= afiucv_hs_send(NULL
, sk
, skb
, flags
);
491 sk
->sk_shutdown
= shutdown
;
495 /* Close an IUCV socket */
496 static void iucv_sock_close(struct sock
*sk
)
498 struct iucv_sock
*iucv
= iucv_sk(sk
);
504 switch (sk
->sk_state
) {
506 iucv_sock_cleanup_listen(sk
);
510 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
511 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
512 sk
->sk_state
= IUCV_DISCONN
;
513 sk
->sk_state_change(sk
);
518 sk
->sk_state
= IUCV_CLOSING
;
519 sk
->sk_state_change(sk
);
521 if (!err
&& !skb_queue_empty(&iucv
->send_skb_q
)) {
522 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
523 timeo
= sk
->sk_lingertime
;
525 timeo
= IUCV_DISCONN_TIMEOUT
;
527 iucv_sock_in_state(sk
, IUCV_CLOSED
, 0),
533 sk
->sk_state
= IUCV_CLOSED
;
534 sk
->sk_state_change(sk
);
536 sk
->sk_err
= ECONNRESET
;
537 sk
->sk_state_change(sk
);
539 skb_queue_purge(&iucv
->send_skb_q
);
540 skb_queue_purge(&iucv
->backlog_skb_q
);
544 iucv_sever_path(sk
, 1);
548 dev_put(iucv
->hs_dev
);
550 sk
->sk_bound_dev_if
= 0;
553 /* mark socket for deletion by iucv_sock_kill() */
554 sock_set_flag(sk
, SOCK_ZAPPED
);
559 static void iucv_sock_init(struct sock
*sk
, struct sock
*parent
)
562 sk
->sk_type
= parent
->sk_type
;
563 security_sk_clone(parent
, sk
);
567 static struct sock
*iucv_sock_alloc(struct socket
*sock
, int proto
, gfp_t prio
, int kern
)
570 struct iucv_sock
*iucv
;
572 sk
= sk_alloc(&init_net
, PF_IUCV
, prio
, &iucv_proto
, kern
);
577 sock_init_data(sock
, sk
);
578 INIT_LIST_HEAD(&iucv
->accept_q
);
579 spin_lock_init(&iucv
->accept_q_lock
);
580 skb_queue_head_init(&iucv
->send_skb_q
);
581 INIT_LIST_HEAD(&iucv
->message_q
.list
);
582 spin_lock_init(&iucv
->message_q
.lock
);
583 skb_queue_head_init(&iucv
->backlog_skb_q
);
585 atomic_set(&iucv
->pendings
, 0);
588 atomic_set(&iucv
->msg_sent
, 0);
589 atomic_set(&iucv
->msg_recv
, 0);
591 iucv
->sk_txnotify
= afiucv_hs_callback_txnotify
;
592 memset(&iucv
->src_user_id
, 0, 32);
594 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
596 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
598 sk
->sk_destruct
= iucv_sock_destruct
;
599 sk
->sk_sndtimeo
= IUCV_CONN_TIMEOUT
;
601 sock_reset_flag(sk
, SOCK_ZAPPED
);
603 sk
->sk_protocol
= proto
;
604 sk
->sk_state
= IUCV_OPEN
;
606 iucv_sock_link(&iucv_sk_list
, sk
);
610 /* Create an IUCV socket */
611 static int iucv_sock_create(struct net
*net
, struct socket
*sock
, int protocol
,
616 if (protocol
&& protocol
!= PF_IUCV
)
617 return -EPROTONOSUPPORT
;
619 sock
->state
= SS_UNCONNECTED
;
621 switch (sock
->type
) {
623 sock
->ops
= &iucv_sock_ops
;
626 /* currently, proto ops can handle both sk types */
627 sock
->ops
= &iucv_sock_ops
;
630 return -ESOCKTNOSUPPORT
;
633 sk
= iucv_sock_alloc(sock
, protocol
, GFP_KERNEL
, kern
);
637 iucv_sock_init(sk
, NULL
);
642 void iucv_sock_link(struct iucv_sock_list
*l
, struct sock
*sk
)
644 write_lock_bh(&l
->lock
);
645 sk_add_node(sk
, &l
->head
);
646 write_unlock_bh(&l
->lock
);
649 void iucv_sock_unlink(struct iucv_sock_list
*l
, struct sock
*sk
)
651 write_lock_bh(&l
->lock
);
652 sk_del_node_init(sk
);
653 write_unlock_bh(&l
->lock
);
656 void iucv_accept_enqueue(struct sock
*parent
, struct sock
*sk
)
659 struct iucv_sock
*par
= iucv_sk(parent
);
662 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
663 list_add_tail(&iucv_sk(sk
)->accept_q
, &par
->accept_q
);
664 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
665 iucv_sk(sk
)->parent
= parent
;
666 sk_acceptq_added(parent
);
669 void iucv_accept_unlink(struct sock
*sk
)
672 struct iucv_sock
*par
= iucv_sk(iucv_sk(sk
)->parent
);
674 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
675 list_del_init(&iucv_sk(sk
)->accept_q
);
676 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
677 sk_acceptq_removed(iucv_sk(sk
)->parent
);
678 iucv_sk(sk
)->parent
= NULL
;
682 struct sock
*iucv_accept_dequeue(struct sock
*parent
, struct socket
*newsock
)
684 struct iucv_sock
*isk
, *n
;
687 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
688 sk
= (struct sock
*) isk
;
691 if (sk
->sk_state
== IUCV_CLOSED
) {
692 iucv_accept_unlink(sk
);
697 if (sk
->sk_state
== IUCV_CONNECTED
||
698 sk
->sk_state
== IUCV_DISCONN
||
700 iucv_accept_unlink(sk
);
702 sock_graft(sk
, newsock
);
713 static void __iucv_auto_name(struct iucv_sock
*iucv
)
717 sprintf(name
, "%08x", atomic_inc_return(&iucv_sk_list
.autobind_name
));
718 while (__iucv_get_sock_by_name(name
)) {
719 sprintf(name
, "%08x",
720 atomic_inc_return(&iucv_sk_list
.autobind_name
));
722 memcpy(iucv
->src_name
, name
, 8);
725 /* Bind an unbound socket */
726 static int iucv_sock_bind(struct socket
*sock
, struct sockaddr
*addr
,
729 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
730 struct sock
*sk
= sock
->sk
;
731 struct iucv_sock
*iucv
;
733 struct net_device
*dev
;
736 /* Verify the input sockaddr */
737 if (addr_len
< sizeof(struct sockaddr_iucv
) ||
738 addr
->sa_family
!= AF_IUCV
)
742 if (sk
->sk_state
!= IUCV_OPEN
) {
747 write_lock_bh(&iucv_sk_list
.lock
);
750 if (__iucv_get_sock_by_name(sa
->siucv_name
)) {
757 /* Bind the socket */
759 if (!memcmp(sa
->siucv_user_id
, iucv_userid
, 8))
760 goto vm_bind
; /* VM IUCV transport */
762 /* try hiper transport */
763 memcpy(uid
, sa
->siucv_user_id
, sizeof(uid
));
766 for_each_netdev_rcu(&init_net
, dev
) {
767 if (!memcmp(dev
->perm_addr
, uid
, 8)) {
768 memcpy(iucv
->src_user_id
, sa
->siucv_user_id
, 8);
769 /* Check for unitialized siucv_name */
770 if (strncmp(sa
->siucv_name
, " ", 8) == 0)
771 __iucv_auto_name(iucv
);
773 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
774 sk
->sk_bound_dev_if
= dev
->ifindex
;
777 sk
->sk_state
= IUCV_BOUND
;
778 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
780 iucv
->msglimit
= IUCV_HIPER_MSGLIM_DEFAULT
;
788 /* use local userid for backward compat */
789 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
790 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
791 sk
->sk_state
= IUCV_BOUND
;
792 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
793 sk
->sk_allocation
|= GFP_DMA
;
795 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
798 /* found no dev to bind */
801 /* Release the socket list lock */
802 write_unlock_bh(&iucv_sk_list
.lock
);
808 /* Automatically bind an unbound socket */
809 static int iucv_sock_autobind(struct sock
*sk
)
811 struct iucv_sock
*iucv
= iucv_sk(sk
);
814 if (unlikely(!pr_iucv
))
817 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
818 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
819 sk
->sk_allocation
|= GFP_DMA
;
821 write_lock_bh(&iucv_sk_list
.lock
);
822 __iucv_auto_name(iucv
);
823 write_unlock_bh(&iucv_sk_list
.lock
);
826 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
831 static int afiucv_path_connect(struct socket
*sock
, struct sockaddr
*addr
)
833 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
834 struct sock
*sk
= sock
->sk
;
835 struct iucv_sock
*iucv
= iucv_sk(sk
);
836 unsigned char user_data
[16];
839 high_nmcpy(user_data
, sa
->siucv_name
);
840 low_nmcpy(user_data
, iucv
->src_name
);
841 ASCEBC(user_data
, sizeof(user_data
));
844 iucv
->path
= iucv_path_alloc(iucv
->msglimit
,
845 IUCV_IPRMDATA
, GFP_KERNEL
);
850 err
= pr_iucv
->path_connect(iucv
->path
, &af_iucv_handler
,
851 sa
->siucv_user_id
, NULL
, user_data
,
854 iucv_path_free(iucv
->path
);
857 case 0x0b: /* Target communicator is not logged on */
860 case 0x0d: /* Max connections for this guest exceeded */
861 case 0x0e: /* Max connections for target guest exceeded */
864 case 0x0f: /* Missing IUCV authorization */
876 /* Connect an unconnected socket */
877 static int iucv_sock_connect(struct socket
*sock
, struct sockaddr
*addr
,
880 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
881 struct sock
*sk
= sock
->sk
;
882 struct iucv_sock
*iucv
= iucv_sk(sk
);
885 if (alen
< sizeof(struct sockaddr_iucv
) || addr
->sa_family
!= AF_IUCV
)
888 if (sk
->sk_state
!= IUCV_OPEN
&& sk
->sk_state
!= IUCV_BOUND
)
891 if (sk
->sk_state
== IUCV_OPEN
&&
892 iucv
->transport
== AF_IUCV_TRANS_HIPER
)
893 return -EBADFD
; /* explicit bind required */
895 if (sk
->sk_type
!= SOCK_STREAM
&& sk
->sk_type
!= SOCK_SEQPACKET
)
898 if (sk
->sk_state
== IUCV_OPEN
) {
899 err
= iucv_sock_autobind(sk
);
906 /* Set the destination information */
907 memcpy(iucv
->dst_user_id
, sa
->siucv_user_id
, 8);
908 memcpy(iucv
->dst_name
, sa
->siucv_name
, 8);
910 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
911 err
= iucv_send_ctrl(sock
->sk
, AF_IUCV_FLAG_SYN
);
913 err
= afiucv_path_connect(sock
, addr
);
917 if (sk
->sk_state
!= IUCV_CONNECTED
)
918 err
= iucv_sock_wait(sk
, iucv_sock_in_state(sk
, IUCV_CONNECTED
,
920 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
922 if (sk
->sk_state
== IUCV_DISCONN
|| sk
->sk_state
== IUCV_CLOSED
)
925 if (err
&& iucv
->transport
== AF_IUCV_TRANS_IUCV
)
926 iucv_sever_path(sk
, 0);
933 /* Move a socket into listening state. */
934 static int iucv_sock_listen(struct socket
*sock
, int backlog
)
936 struct sock
*sk
= sock
->sk
;
942 if (sk
->sk_state
!= IUCV_BOUND
)
945 if (sock
->type
!= SOCK_STREAM
&& sock
->type
!= SOCK_SEQPACKET
)
948 sk
->sk_max_ack_backlog
= backlog
;
949 sk
->sk_ack_backlog
= 0;
950 sk
->sk_state
= IUCV_LISTEN
;
958 /* Accept a pending connection */
959 static int iucv_sock_accept(struct socket
*sock
, struct socket
*newsock
,
960 int flags
, bool kern
)
962 DECLARE_WAITQUEUE(wait
, current
);
963 struct sock
*sk
= sock
->sk
, *nsk
;
967 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
969 if (sk
->sk_state
!= IUCV_LISTEN
) {
974 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
976 /* Wait for an incoming connection */
977 add_wait_queue_exclusive(sk_sleep(sk
), &wait
);
978 while (!(nsk
= iucv_accept_dequeue(sk
, newsock
))) {
979 set_current_state(TASK_INTERRUPTIBLE
);
986 timeo
= schedule_timeout(timeo
);
987 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
989 if (sk
->sk_state
!= IUCV_LISTEN
) {
994 if (signal_pending(current
)) {
995 err
= sock_intr_errno(timeo
);
1000 set_current_state(TASK_RUNNING
);
1001 remove_wait_queue(sk_sleep(sk
), &wait
);
1006 newsock
->state
= SS_CONNECTED
;
1013 static int iucv_sock_getname(struct socket
*sock
, struct sockaddr
*addr
,
1016 struct sockaddr_iucv
*siucv
= (struct sockaddr_iucv
*) addr
;
1017 struct sock
*sk
= sock
->sk
;
1018 struct iucv_sock
*iucv
= iucv_sk(sk
);
1020 addr
->sa_family
= AF_IUCV
;
1023 memcpy(siucv
->siucv_user_id
, iucv
->dst_user_id
, 8);
1024 memcpy(siucv
->siucv_name
, iucv
->dst_name
, 8);
1026 memcpy(siucv
->siucv_user_id
, iucv
->src_user_id
, 8);
1027 memcpy(siucv
->siucv_name
, iucv
->src_name
, 8);
1029 memset(&siucv
->siucv_port
, 0, sizeof(siucv
->siucv_port
));
1030 memset(&siucv
->siucv_addr
, 0, sizeof(siucv
->siucv_addr
));
1031 memset(&siucv
->siucv_nodeid
, 0, sizeof(siucv
->siucv_nodeid
));
1033 return sizeof(struct sockaddr_iucv
);
1037 * iucv_send_iprm() - Send socket data in parameter list of an iucv message.
1039 * @msg: Pointer to a struct iucv_message
1040 * @skb: The socket data to send, skb->len MUST BE <= 7
1042 * Send the socket data in the parameter list in the iucv message
1043 * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter
1044 * list and the socket data len at index 7 (last byte).
1045 * See also iucv_msg_length().
1047 * Returns the error code from the iucv_message_send() call.
1049 static int iucv_send_iprm(struct iucv_path
*path
, struct iucv_message
*msg
,
1050 struct sk_buff
*skb
)
1054 memcpy(prmdata
, (void *) skb
->data
, skb
->len
);
1055 prmdata
[7] = 0xff - (u8
) skb
->len
;
1056 return pr_iucv
->message_send(path
, msg
, IUCV_IPRMDATA
, 0,
1057 (void *) prmdata
, 8);
1060 static int iucv_sock_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
1063 struct sock
*sk
= sock
->sk
;
1064 struct iucv_sock
*iucv
= iucv_sk(sk
);
1065 size_t headroom
= 0;
1067 struct sk_buff
*skb
;
1068 struct iucv_message txmsg
= {0};
1069 struct cmsghdr
*cmsg
;
1075 int noblock
= msg
->msg_flags
& MSG_DONTWAIT
;
1077 err
= sock_error(sk
);
1081 if (msg
->msg_flags
& MSG_OOB
)
1084 /* SOCK_SEQPACKET: we do not support segmented records */
1085 if (sk
->sk_type
== SOCK_SEQPACKET
&& !(msg
->msg_flags
& MSG_EOR
))
1090 if (sk
->sk_shutdown
& SEND_SHUTDOWN
) {
1095 /* Return if the socket is not in connected state */
1096 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1101 /* initialize defaults */
1102 cmsg_done
= 0; /* check for duplicate headers */
1105 /* iterate over control messages */
1106 for_each_cmsghdr(cmsg
, msg
) {
1107 if (!CMSG_OK(msg
, cmsg
)) {
1112 if (cmsg
->cmsg_level
!= SOL_IUCV
)
1115 if (cmsg
->cmsg_type
& cmsg_done
) {
1119 cmsg_done
|= cmsg
->cmsg_type
;
1121 switch (cmsg
->cmsg_type
) {
1122 case SCM_IUCV_TRGCLS
:
1123 if (cmsg
->cmsg_len
!= CMSG_LEN(TRGCLS_SIZE
)) {
1128 /* set iucv message target class */
1129 memcpy(&txmsg
.class,
1130 (void *) CMSG_DATA(cmsg
), TRGCLS_SIZE
);
1140 /* allocate one skb for each iucv message:
1141 * this is fine for SOCK_SEQPACKET (unless we want to support
1142 * segmented records using the MSG_EOR flag), but
1143 * for SOCK_STREAM we might want to improve it in future */
1144 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1145 headroom
= sizeof(struct af_iucv_trans_hdr
) +
1146 LL_RESERVED_SPACE(iucv
->hs_dev
);
1149 if (len
< PAGE_SIZE
) {
1152 /* In nonlinear "classic" iucv skb,
1153 * reserve space for iucv_array
1155 headroom
= sizeof(struct iucv_array
) *
1156 (MAX_SKB_FRAGS
+ 1);
1157 linear
= PAGE_SIZE
- headroom
;
1160 skb
= sock_alloc_send_pskb(sk
, headroom
+ linear
, len
- linear
,
1165 skb_reserve(skb
, headroom
);
1166 skb_put(skb
, linear
);
1168 skb
->data_len
= len
- linear
;
1169 err
= skb_copy_datagram_from_iter(skb
, 0, &msg
->msg_iter
, len
);
1173 /* wait if outstanding messages for iucv path has reached */
1174 timeo
= sock_sndtimeo(sk
, noblock
);
1175 err
= iucv_sock_wait(sk
, iucv_below_msglim(sk
), timeo
);
1179 /* return -ECONNRESET if the socket is no longer connected */
1180 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1185 /* increment and save iucv message tag for msg_completion cbk */
1186 txmsg
.tag
= iucv
->send_tag
++;
1187 IUCV_SKB_CB(skb
)->tag
= txmsg
.tag
;
1189 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1190 atomic_inc(&iucv
->msg_sent
);
1191 err
= afiucv_hs_send(&txmsg
, sk
, skb
, 0);
1193 atomic_dec(&iucv
->msg_sent
);
1196 } else { /* Classic VM IUCV transport */
1197 skb_queue_tail(&iucv
->send_skb_q
, skb
);
1199 if (((iucv
->path
->flags
& IUCV_IPRMDATA
) & iucv
->flags
) &&
1201 err
= iucv_send_iprm(iucv
->path
, &txmsg
, skb
);
1203 /* on success: there is no message_complete callback */
1204 /* for an IPRMDATA msg; remove skb from send queue */
1206 skb_unlink(skb
, &iucv
->send_skb_q
);
1210 /* this error should never happen since the */
1211 /* IUCV_IPRMDATA path flag is set... sever path */
1213 pr_iucv
->path_sever(iucv
->path
, NULL
);
1214 skb_unlink(skb
, &iucv
->send_skb_q
);
1218 } else if (skb_is_nonlinear(skb
)) {
1219 struct iucv_array
*iba
= (struct iucv_array
*)skb
->head
;
1222 /* skip iucv_array lying in the headroom */
1223 iba
[0].address
= (u32
)(addr_t
)skb
->data
;
1224 iba
[0].length
= (u32
)skb_headlen(skb
);
1225 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1226 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1228 iba
[i
+ 1].address
=
1229 (u32
)(addr_t
)skb_frag_address(frag
);
1230 iba
[i
+ 1].length
= (u32
)skb_frag_size(frag
);
1232 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1234 (void *)iba
, skb
->len
);
1235 } else { /* non-IPRM Linear skb */
1236 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1237 0, 0, (void *)skb
->data
, skb
->len
);
1242 memcpy(user_id
, iucv
->dst_user_id
, 8);
1244 memcpy(appl_id
, iucv
->dst_name
, 8);
1246 "Application %s on z/VM guest %s exceeds message limit\n",
1252 skb_unlink(skb
, &iucv
->send_skb_q
);
1267 static struct sk_buff
*alloc_iucv_recv_skb(unsigned long len
)
1269 size_t headroom
, linear
;
1270 struct sk_buff
*skb
;
1273 if (len
< PAGE_SIZE
) {
1277 headroom
= sizeof(struct iucv_array
) * (MAX_SKB_FRAGS
+ 1);
1278 linear
= PAGE_SIZE
- headroom
;
1280 skb
= alloc_skb_with_frags(headroom
+ linear
, len
- linear
,
1281 0, &err
, GFP_ATOMIC
| GFP_DMA
);
1283 "alloc of recv iucv skb len=%lu failed with errcode=%d\n",
1287 skb_reserve(skb
, headroom
);
1288 skb_put(skb
, linear
);
1290 skb
->data_len
= len
- linear
;
1295 /* iucv_process_message() - Receive a single outstanding IUCV message
1297 * Locking: must be called with message_q.lock held
1299 static void iucv_process_message(struct sock
*sk
, struct sk_buff
*skb
,
1300 struct iucv_path
*path
,
1301 struct iucv_message
*msg
)
1306 len
= iucv_msg_length(msg
);
1308 /* store msg target class in the second 4 bytes of skb ctrl buffer */
1309 /* Note: the first 4 bytes are reserved for msg tag */
1310 IUCV_SKB_CB(skb
)->class = msg
->class;
1312 /* check for special IPRM messages (e.g. iucv_sock_shutdown) */
1313 if ((msg
->flags
& IUCV_IPRMDATA
) && len
> 7) {
1314 if (memcmp(msg
->rmmsg
, iprm_shutdown
, 8) == 0) {
1319 if (skb_is_nonlinear(skb
)) {
1320 struct iucv_array
*iba
= (struct iucv_array
*)skb
->head
;
1323 iba
[0].address
= (u32
)(addr_t
)skb
->data
;
1324 iba
[0].length
= (u32
)skb_headlen(skb
);
1325 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1326 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1328 iba
[i
+ 1].address
=
1329 (u32
)(addr_t
)skb_frag_address(frag
);
1330 iba
[i
+ 1].length
= (u32
)skb_frag_size(frag
);
1332 rc
= pr_iucv
->message_receive(path
, msg
,
1334 (void *)iba
, len
, NULL
);
1336 rc
= pr_iucv
->message_receive(path
, msg
,
1337 msg
->flags
& IUCV_IPRMDATA
,
1338 skb
->data
, len
, NULL
);
1344 WARN_ON_ONCE(skb
->len
!= len
);
1347 IUCV_SKB_CB(skb
)->offset
= 0;
1348 if (sk_filter(sk
, skb
)) {
1349 atomic_inc(&sk
->sk_drops
); /* skb rejected by filter */
1353 if (__sock_queue_rcv_skb(sk
, skb
)) /* handle rcv queue full */
1354 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, skb
);
1357 /* iucv_process_message_q() - Process outstanding IUCV messages
1359 * Locking: must be called with message_q.lock held
1361 static void iucv_process_message_q(struct sock
*sk
)
1363 struct iucv_sock
*iucv
= iucv_sk(sk
);
1364 struct sk_buff
*skb
;
1365 struct sock_msg_q
*p
, *n
;
1367 list_for_each_entry_safe(p
, n
, &iucv
->message_q
.list
, list
) {
1368 skb
= alloc_iucv_recv_skb(iucv_msg_length(&p
->msg
));
1371 iucv_process_message(sk
, skb
, p
->path
, &p
->msg
);
1374 if (!skb_queue_empty(&iucv
->backlog_skb_q
))
1379 static int iucv_sock_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
1380 size_t len
, int flags
)
1382 int noblock
= flags
& MSG_DONTWAIT
;
1383 struct sock
*sk
= sock
->sk
;
1384 struct iucv_sock
*iucv
= iucv_sk(sk
);
1385 unsigned int copied
, rlen
;
1386 struct sk_buff
*skb
, *rskb
, *cskb
;
1390 if ((sk
->sk_state
== IUCV_DISCONN
) &&
1391 skb_queue_empty(&iucv
->backlog_skb_q
) &&
1392 skb_queue_empty(&sk
->sk_receive_queue
) &&
1393 list_empty(&iucv
->message_q
.list
))
1396 if (flags
& (MSG_OOB
))
1399 /* receive/dequeue next skb:
1400 * the function understands MSG_PEEK and, thus, does not dequeue skb */
1401 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
1403 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1408 offset
= IUCV_SKB_CB(skb
)->offset
;
1409 rlen
= skb
->len
- offset
; /* real length of skb */
1410 copied
= min_t(unsigned int, rlen
, len
);
1412 sk
->sk_shutdown
= sk
->sk_shutdown
| RCV_SHUTDOWN
;
1415 if (skb_copy_datagram_msg(cskb
, offset
, msg
, copied
)) {
1416 if (!(flags
& MSG_PEEK
))
1417 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1421 /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */
1422 if (sk
->sk_type
== SOCK_SEQPACKET
) {
1424 msg
->msg_flags
|= MSG_TRUNC
;
1425 /* each iucv message contains a complete record */
1426 msg
->msg_flags
|= MSG_EOR
;
1429 /* create control message to store iucv msg target class:
1430 * get the trgcls from the control buffer of the skb due to
1431 * fragmentation of original iucv message. */
1432 err
= put_cmsg(msg
, SOL_IUCV
, SCM_IUCV_TRGCLS
,
1433 sizeof(IUCV_SKB_CB(skb
)->class),
1434 (void *)&IUCV_SKB_CB(skb
)->class);
1436 if (!(flags
& MSG_PEEK
))
1437 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1441 /* Mark read part of skb as used */
1442 if (!(flags
& MSG_PEEK
)) {
1444 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
1445 if (sk
->sk_type
== SOCK_STREAM
) {
1446 if (copied
< rlen
) {
1447 IUCV_SKB_CB(skb
)->offset
= offset
+ copied
;
1448 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1454 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1455 atomic_inc(&iucv
->msg_recv
);
1456 if (atomic_read(&iucv
->msg_recv
) > iucv
->msglimit
) {
1458 iucv_sock_close(sk
);
1463 /* Queue backlog skbs */
1464 spin_lock_bh(&iucv
->message_q
.lock
);
1465 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1467 IUCV_SKB_CB(rskb
)->offset
= 0;
1468 if (__sock_queue_rcv_skb(sk
, rskb
)) {
1469 /* handle rcv queue full */
1470 skb_queue_head(&iucv
->backlog_skb_q
,
1474 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1476 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
1477 if (!list_empty(&iucv
->message_q
.list
))
1478 iucv_process_message_q(sk
);
1479 if (atomic_read(&iucv
->msg_recv
) >=
1480 iucv
->msglimit
/ 2) {
1481 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_WIN
);
1483 sk
->sk_state
= IUCV_DISCONN
;
1484 sk
->sk_state_change(sk
);
1488 spin_unlock_bh(&iucv
->message_q
.lock
);
1492 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
1493 if (sk
->sk_type
== SOCK_SEQPACKET
&& (flags
& MSG_TRUNC
))
1499 static inline __poll_t
iucv_accept_poll(struct sock
*parent
)
1501 struct iucv_sock
*isk
, *n
;
1504 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
1505 sk
= (struct sock
*) isk
;
1507 if (sk
->sk_state
== IUCV_CONNECTED
)
1508 return EPOLLIN
| EPOLLRDNORM
;
1514 __poll_t
iucv_sock_poll(struct file
*file
, struct socket
*sock
,
1517 struct sock
*sk
= sock
->sk
;
1520 sock_poll_wait(file
, sock
, wait
);
1522 if (sk
->sk_state
== IUCV_LISTEN
)
1523 return iucv_accept_poll(sk
);
1525 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
))
1527 (sock_flag(sk
, SOCK_SELECT_ERR_QUEUE
) ? EPOLLPRI
: 0);
1529 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1532 if (sk
->sk_shutdown
== SHUTDOWN_MASK
)
1535 if (!skb_queue_empty(&sk
->sk_receive_queue
) ||
1536 (sk
->sk_shutdown
& RCV_SHUTDOWN
))
1537 mask
|= EPOLLIN
| EPOLLRDNORM
;
1539 if (sk
->sk_state
== IUCV_CLOSED
)
1542 if (sk
->sk_state
== IUCV_DISCONN
)
1545 if (sock_writeable(sk
) && iucv_below_msglim(sk
))
1546 mask
|= EPOLLOUT
| EPOLLWRNORM
| EPOLLWRBAND
;
1548 sk_set_bit(SOCKWQ_ASYNC_NOSPACE
, sk
);
1553 static int iucv_sock_shutdown(struct socket
*sock
, int how
)
1555 struct sock
*sk
= sock
->sk
;
1556 struct iucv_sock
*iucv
= iucv_sk(sk
);
1557 struct iucv_message txmsg
;
1562 if ((how
& ~SHUTDOWN_MASK
) || !how
)
1566 switch (sk
->sk_state
) {
1577 if (how
== SEND_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1578 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
) {
1581 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1582 IUCV_IPRMDATA
, 0, (void *) iprm_shutdown
, 8);
1597 iucv_send_ctrl(sk
, AF_IUCV_FLAG_SHT
);
1600 sk
->sk_shutdown
|= how
;
1601 if (how
== RCV_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1602 if ((iucv
->transport
== AF_IUCV_TRANS_IUCV
) &&
1604 err
= pr_iucv
->path_quiesce(iucv
->path
, NULL
);
1607 /* skb_queue_purge(&sk->sk_receive_queue); */
1609 skb_queue_purge(&sk
->sk_receive_queue
);
1612 /* Wake up anyone sleeping in poll */
1613 sk
->sk_state_change(sk
);
1620 static int iucv_sock_release(struct socket
*sock
)
1622 struct sock
*sk
= sock
->sk
;
1628 iucv_sock_close(sk
);
1635 /* getsockopt and setsockopt */
1636 static int iucv_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
1637 char __user
*optval
, unsigned int optlen
)
1639 struct sock
*sk
= sock
->sk
;
1640 struct iucv_sock
*iucv
= iucv_sk(sk
);
1644 if (level
!= SOL_IUCV
)
1645 return -ENOPROTOOPT
;
1647 if (optlen
< sizeof(int))
1650 if (get_user(val
, (int __user
*) optval
))
1657 case SO_IPRMDATA_MSG
:
1659 iucv
->flags
|= IUCV_IPRMDATA
;
1661 iucv
->flags
&= ~IUCV_IPRMDATA
;
1664 switch (sk
->sk_state
) {
1667 if (val
< 1 || val
> (u16
)(~0))
1670 iucv
->msglimit
= val
;
1686 static int iucv_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
1687 char __user
*optval
, int __user
*optlen
)
1689 struct sock
*sk
= sock
->sk
;
1690 struct iucv_sock
*iucv
= iucv_sk(sk
);
1694 if (level
!= SOL_IUCV
)
1695 return -ENOPROTOOPT
;
1697 if (get_user(len
, optlen
))
1703 len
= min_t(unsigned int, len
, sizeof(int));
1706 case SO_IPRMDATA_MSG
:
1707 val
= (iucv
->flags
& IUCV_IPRMDATA
) ? 1 : 0;
1711 val
= (iucv
->path
!= NULL
) ? iucv
->path
->msglim
/* connected */
1712 : iucv
->msglimit
; /* default */
1716 if (sk
->sk_state
== IUCV_OPEN
)
1718 val
= (iucv
->hs_dev
) ? iucv
->hs_dev
->mtu
-
1719 sizeof(struct af_iucv_trans_hdr
) - ETH_HLEN
:
1723 return -ENOPROTOOPT
;
1726 if (put_user(len
, optlen
))
1728 if (copy_to_user(optval
, &val
, len
))
1735 /* Callback wrappers - called from iucv base support */
1736 static int iucv_callback_connreq(struct iucv_path
*path
,
1737 u8 ipvmid
[8], u8 ipuser
[16])
1739 unsigned char user_data
[16];
1740 unsigned char nuser_data
[16];
1741 unsigned char src_name
[8];
1742 struct sock
*sk
, *nsk
;
1743 struct iucv_sock
*iucv
, *niucv
;
1746 memcpy(src_name
, ipuser
, 8);
1747 EBCASC(src_name
, 8);
1748 /* Find out if this path belongs to af_iucv. */
1749 read_lock(&iucv_sk_list
.lock
);
1752 sk_for_each(sk
, &iucv_sk_list
.head
)
1753 if (sk
->sk_state
== IUCV_LISTEN
&&
1754 !memcmp(&iucv_sk(sk
)->src_name
, src_name
, 8)) {
1756 * Found a listening socket with
1757 * src_name == ipuser[0-7].
1762 read_unlock(&iucv_sk_list
.lock
);
1764 /* No socket found, not one of our paths. */
1769 /* Check if parent socket is listening */
1770 low_nmcpy(user_data
, iucv
->src_name
);
1771 high_nmcpy(user_data
, iucv
->dst_name
);
1772 ASCEBC(user_data
, sizeof(user_data
));
1773 if (sk
->sk_state
!= IUCV_LISTEN
) {
1774 err
= pr_iucv
->path_sever(path
, user_data
);
1775 iucv_path_free(path
);
1779 /* Check for backlog size */
1780 if (sk_acceptq_is_full(sk
)) {
1781 err
= pr_iucv
->path_sever(path
, user_data
);
1782 iucv_path_free(path
);
1786 /* Create the new socket */
1787 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
, 0);
1789 err
= pr_iucv
->path_sever(path
, user_data
);
1790 iucv_path_free(path
);
1794 niucv
= iucv_sk(nsk
);
1795 iucv_sock_init(nsk
, sk
);
1796 niucv
->transport
= AF_IUCV_TRANS_IUCV
;
1797 nsk
->sk_allocation
|= GFP_DMA
;
1799 /* Set the new iucv_sock */
1800 memcpy(niucv
->dst_name
, ipuser
+ 8, 8);
1801 EBCASC(niucv
->dst_name
, 8);
1802 memcpy(niucv
->dst_user_id
, ipvmid
, 8);
1803 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1804 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1807 /* Call iucv_accept */
1808 high_nmcpy(nuser_data
, ipuser
+ 8);
1809 memcpy(nuser_data
+ 8, niucv
->src_name
, 8);
1810 ASCEBC(nuser_data
+ 8, 8);
1812 /* set message limit for path based on msglimit of accepting socket */
1813 niucv
->msglimit
= iucv
->msglimit
;
1814 path
->msglim
= iucv
->msglimit
;
1815 err
= pr_iucv
->path_accept(path
, &af_iucv_handler
, nuser_data
, nsk
);
1817 iucv_sever_path(nsk
, 1);
1818 iucv_sock_kill(nsk
);
1822 iucv_accept_enqueue(sk
, nsk
);
1824 /* Wake up accept */
1825 nsk
->sk_state
= IUCV_CONNECTED
;
1826 sk
->sk_data_ready(sk
);
1833 static void iucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
1835 struct sock
*sk
= path
->private;
1837 sk
->sk_state
= IUCV_CONNECTED
;
1838 sk
->sk_state_change(sk
);
1841 static void iucv_callback_rx(struct iucv_path
*path
, struct iucv_message
*msg
)
1843 struct sock
*sk
= path
->private;
1844 struct iucv_sock
*iucv
= iucv_sk(sk
);
1845 struct sk_buff
*skb
;
1846 struct sock_msg_q
*save_msg
;
1849 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
1850 pr_iucv
->message_reject(path
, msg
);
1854 spin_lock(&iucv
->message_q
.lock
);
1856 if (!list_empty(&iucv
->message_q
.list
) ||
1857 !skb_queue_empty(&iucv
->backlog_skb_q
))
1860 len
= atomic_read(&sk
->sk_rmem_alloc
);
1861 len
+= SKB_TRUESIZE(iucv_msg_length(msg
));
1862 if (len
> sk
->sk_rcvbuf
)
1865 skb
= alloc_iucv_recv_skb(iucv_msg_length(msg
));
1869 iucv_process_message(sk
, skb
, path
, msg
);
1873 save_msg
= kzalloc(sizeof(struct sock_msg_q
), GFP_ATOMIC
| GFP_DMA
);
1876 save_msg
->path
= path
;
1877 save_msg
->msg
= *msg
;
1879 list_add_tail(&save_msg
->list
, &iucv
->message_q
.list
);
1882 spin_unlock(&iucv
->message_q
.lock
);
1885 static void iucv_callback_txdone(struct iucv_path
*path
,
1886 struct iucv_message
*msg
)
1888 struct sock
*sk
= path
->private;
1889 struct sk_buff
*this = NULL
;
1890 struct sk_buff_head
*list
= &iucv_sk(sk
)->send_skb_q
;
1891 struct sk_buff
*list_skb
;
1892 unsigned long flags
;
1896 spin_lock_irqsave(&list
->lock
, flags
);
1897 skb_queue_walk(list
, list_skb
) {
1898 if (msg
->tag
== IUCV_SKB_CB(list_skb
)->tag
) {
1904 __skb_unlink(this, list
);
1905 spin_unlock_irqrestore(&list
->lock
, flags
);
1909 /* wake up any process waiting for sending */
1910 iucv_sock_wake_msglim(sk
);
1913 if (sk
->sk_state
== IUCV_CLOSING
) {
1914 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
1915 sk
->sk_state
= IUCV_CLOSED
;
1916 sk
->sk_state_change(sk
);
1923 static void iucv_callback_connrej(struct iucv_path
*path
, u8 ipuser
[16])
1925 struct sock
*sk
= path
->private;
1927 if (sk
->sk_state
== IUCV_CLOSED
)
1931 iucv_sever_path(sk
, 1);
1932 sk
->sk_state
= IUCV_DISCONN
;
1934 sk
->sk_state_change(sk
);
1938 /* called if the other communication side shuts down its RECV direction;
1939 * in turn, the callback sets SEND_SHUTDOWN to disable sending of data.
1941 static void iucv_callback_shutdown(struct iucv_path
*path
, u8 ipuser
[16])
1943 struct sock
*sk
= path
->private;
1946 if (sk
->sk_state
!= IUCV_CLOSED
) {
1947 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
1948 sk
->sk_state_change(sk
);
1953 /***************** HiperSockets transport callbacks ********************/
1954 static void afiucv_swap_src_dest(struct sk_buff
*skb
)
1956 struct af_iucv_trans_hdr
*trans_hdr
= iucv_trans_hdr(skb
);
1960 ASCEBC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
1961 ASCEBC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
1962 ASCEBC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
1963 ASCEBC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
1964 memcpy(tmpID
, trans_hdr
->srcUserID
, 8);
1965 memcpy(tmpName
, trans_hdr
->srcAppName
, 8);
1966 memcpy(trans_hdr
->srcUserID
, trans_hdr
->destUserID
, 8);
1967 memcpy(trans_hdr
->srcAppName
, trans_hdr
->destAppName
, 8);
1968 memcpy(trans_hdr
->destUserID
, tmpID
, 8);
1969 memcpy(trans_hdr
->destAppName
, tmpName
, 8);
1970 skb_push(skb
, ETH_HLEN
);
1971 memset(skb
->data
, 0, ETH_HLEN
);
1975 * afiucv_hs_callback_syn - react on received SYN
1977 static int afiucv_hs_callback_syn(struct sock
*sk
, struct sk_buff
*skb
)
1979 struct af_iucv_trans_hdr
*trans_hdr
= iucv_trans_hdr(skb
);
1981 struct iucv_sock
*iucv
, *niucv
;
1986 /* no sock - connection refused */
1987 afiucv_swap_src_dest(skb
);
1988 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
1989 err
= dev_queue_xmit(skb
);
1993 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
, 0);
1995 if ((sk
->sk_state
!= IUCV_LISTEN
) ||
1996 sk_acceptq_is_full(sk
) ||
1998 /* error on server socket - connection refused */
1999 afiucv_swap_src_dest(skb
);
2000 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
2001 err
= dev_queue_xmit(skb
);
2002 iucv_sock_kill(nsk
);
2007 niucv
= iucv_sk(nsk
);
2008 iucv_sock_init(nsk
, sk
);
2009 niucv
->transport
= AF_IUCV_TRANS_HIPER
;
2010 niucv
->msglimit
= iucv
->msglimit
;
2011 if (!trans_hdr
->window
)
2012 niucv
->msglimit_peer
= IUCV_HIPER_MSGLIM_DEFAULT
;
2014 niucv
->msglimit_peer
= trans_hdr
->window
;
2015 memcpy(niucv
->dst_name
, trans_hdr
->srcAppName
, 8);
2016 memcpy(niucv
->dst_user_id
, trans_hdr
->srcUserID
, 8);
2017 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
2018 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
2019 nsk
->sk_bound_dev_if
= sk
->sk_bound_dev_if
;
2020 niucv
->hs_dev
= iucv
->hs_dev
;
2021 dev_hold(niucv
->hs_dev
);
2022 afiucv_swap_src_dest(skb
);
2023 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
;
2024 trans_hdr
->window
= niucv
->msglimit
;
2025 /* if receiver acks the xmit connection is established */
2026 err
= dev_queue_xmit(skb
);
2028 iucv_accept_enqueue(sk
, nsk
);
2029 nsk
->sk_state
= IUCV_CONNECTED
;
2030 sk
->sk_data_ready(sk
);
2032 iucv_sock_kill(nsk
);
2036 return NET_RX_SUCCESS
;
2040 * afiucv_hs_callback_synack() - react on received SYN-ACK
2042 static int afiucv_hs_callback_synack(struct sock
*sk
, struct sk_buff
*skb
)
2044 struct iucv_sock
*iucv
= iucv_sk(sk
);
2048 if (sk
->sk_state
!= IUCV_BOUND
)
2051 iucv
->msglimit_peer
= iucv_trans_hdr(skb
)->window
;
2052 sk
->sk_state
= IUCV_CONNECTED
;
2053 sk
->sk_state_change(sk
);
2057 return NET_RX_SUCCESS
;
2061 * afiucv_hs_callback_synfin() - react on received SYN_FIN
2063 static int afiucv_hs_callback_synfin(struct sock
*sk
, struct sk_buff
*skb
)
2065 struct iucv_sock
*iucv
= iucv_sk(sk
);
2069 if (sk
->sk_state
!= IUCV_BOUND
)
2072 sk
->sk_state
= IUCV_DISCONN
;
2073 sk
->sk_state_change(sk
);
2077 return NET_RX_SUCCESS
;
2081 * afiucv_hs_callback_fin() - react on received FIN
2083 static int afiucv_hs_callback_fin(struct sock
*sk
, struct sk_buff
*skb
)
2085 struct iucv_sock
*iucv
= iucv_sk(sk
);
2087 /* other end of connection closed */
2091 if (sk
->sk_state
== IUCV_CONNECTED
) {
2092 sk
->sk_state
= IUCV_DISCONN
;
2093 sk
->sk_state_change(sk
);
2098 return NET_RX_SUCCESS
;
2102 * afiucv_hs_callback_win() - react on received WIN
2104 static int afiucv_hs_callback_win(struct sock
*sk
, struct sk_buff
*skb
)
2106 struct iucv_sock
*iucv
= iucv_sk(sk
);
2109 return NET_RX_SUCCESS
;
2111 if (sk
->sk_state
!= IUCV_CONNECTED
)
2112 return NET_RX_SUCCESS
;
2114 atomic_sub(iucv_trans_hdr(skb
)->window
, &iucv
->msg_sent
);
2115 iucv_sock_wake_msglim(sk
);
2116 return NET_RX_SUCCESS
;
2120 * afiucv_hs_callback_rx() - react on received data
2122 static int afiucv_hs_callback_rx(struct sock
*sk
, struct sk_buff
*skb
)
2124 struct iucv_sock
*iucv
= iucv_sk(sk
);
2128 return NET_RX_SUCCESS
;
2131 if (sk
->sk_state
!= IUCV_CONNECTED
) {
2133 return NET_RX_SUCCESS
;
2136 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
2138 return NET_RX_SUCCESS
;
2141 /* write stuff from iucv_msg to skb cb */
2142 skb_pull(skb
, sizeof(struct af_iucv_trans_hdr
));
2143 skb_reset_transport_header(skb
);
2144 skb_reset_network_header(skb
);
2145 IUCV_SKB_CB(skb
)->offset
= 0;
2146 if (sk_filter(sk
, skb
)) {
2147 atomic_inc(&sk
->sk_drops
); /* skb rejected by filter */
2149 return NET_RX_SUCCESS
;
2152 spin_lock(&iucv
->message_q
.lock
);
2153 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
2154 if (__sock_queue_rcv_skb(sk
, skb
))
2155 /* handle rcv queue full */
2156 skb_queue_tail(&iucv
->backlog_skb_q
, skb
);
2158 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, skb
);
2159 spin_unlock(&iucv
->message_q
.lock
);
2160 return NET_RX_SUCCESS
;
2164 * afiucv_hs_rcv() - base function for arriving data through HiperSockets
2166 * called from netif RX softirq
2168 static int afiucv_hs_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
2169 struct packet_type
*pt
, struct net_device
*orig_dev
)
2172 struct iucv_sock
*iucv
;
2173 struct af_iucv_trans_hdr
*trans_hdr
;
2174 int err
= NET_RX_SUCCESS
;
2177 if (!pskb_may_pull(skb
, sizeof(*trans_hdr
))) {
2178 WARN_ONCE(1, "AF_IUCV failed to receive skb, len=%u", skb
->len
);
2180 return NET_RX_SUCCESS
;
2183 trans_hdr
= iucv_trans_hdr(skb
);
2184 EBCASC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
2185 EBCASC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
2186 EBCASC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
2187 EBCASC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
2188 memset(nullstring
, 0, sizeof(nullstring
));
2191 read_lock(&iucv_sk_list
.lock
);
2192 sk_for_each(sk
, &iucv_sk_list
.head
) {
2193 if (trans_hdr
->flags
== AF_IUCV_FLAG_SYN
) {
2194 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2195 trans_hdr
->destAppName
, 8)) &&
2196 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2197 trans_hdr
->destUserID
, 8)) &&
2198 (!memcmp(&iucv_sk(sk
)->dst_name
, nullstring
, 8)) &&
2199 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2205 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2206 trans_hdr
->destAppName
, 8)) &&
2207 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2208 trans_hdr
->destUserID
, 8)) &&
2209 (!memcmp(&iucv_sk(sk
)->dst_name
,
2210 trans_hdr
->srcAppName
, 8)) &&
2211 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2212 trans_hdr
->srcUserID
, 8))) {
2218 read_unlock(&iucv_sk_list
.lock
);
2223 how should we send with no sock
2224 1) send without sock no send rc checking?
2225 2) introduce default sock to handle this cases
2227 SYN -> send SYN|ACK in good case, send SYN|FIN in bad case
2229 SYN|ACK, SYN|FIN, FIN -> no action? */
2231 switch (trans_hdr
->flags
) {
2232 case AF_IUCV_FLAG_SYN
:
2233 /* connect request */
2234 err
= afiucv_hs_callback_syn(sk
, skb
);
2236 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
):
2237 /* connect request confirmed */
2238 err
= afiucv_hs_callback_synack(sk
, skb
);
2240 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
):
2241 /* connect request refused */
2242 err
= afiucv_hs_callback_synfin(sk
, skb
);
2244 case (AF_IUCV_FLAG_FIN
):
2246 err
= afiucv_hs_callback_fin(sk
, skb
);
2248 case (AF_IUCV_FLAG_WIN
):
2249 err
= afiucv_hs_callback_win(sk
, skb
);
2250 if (skb
->len
== sizeof(struct af_iucv_trans_hdr
)) {
2254 /* fall through - and receive non-zero length data */
2255 case (AF_IUCV_FLAG_SHT
):
2256 /* shutdown request */
2257 /* fall through - and receive zero length data */
2259 /* plain data frame */
2260 IUCV_SKB_CB(skb
)->class = trans_hdr
->iucv_hdr
.class;
2261 err
= afiucv_hs_callback_rx(sk
, skb
);
2271 * afiucv_hs_callback_txnotify() - handle send notifcations from HiperSockets
2274 static void afiucv_hs_callback_txnotify(struct sk_buff
*skb
,
2275 enum iucv_tx_notify n
)
2277 struct sock
*isk
= skb
->sk
;
2278 struct sock
*sk
= NULL
;
2279 struct iucv_sock
*iucv
= NULL
;
2280 struct sk_buff_head
*list
;
2281 struct sk_buff
*list_skb
;
2282 struct sk_buff
*nskb
;
2283 unsigned long flags
;
2285 read_lock_irqsave(&iucv_sk_list
.lock
, flags
);
2286 sk_for_each(sk
, &iucv_sk_list
.head
)
2291 read_unlock_irqrestore(&iucv_sk_list
.lock
, flags
);
2293 if (!iucv
|| sock_flag(sk
, SOCK_ZAPPED
))
2296 list
= &iucv
->send_skb_q
;
2297 spin_lock_irqsave(&list
->lock
, flags
);
2298 skb_queue_walk_safe(list
, list_skb
, nskb
) {
2299 if (skb_shinfo(list_skb
) == skb_shinfo(skb
)) {
2302 __skb_unlink(list_skb
, list
);
2303 kfree_skb(list_skb
);
2304 iucv_sock_wake_msglim(sk
);
2306 case TX_NOTIFY_PENDING
:
2307 atomic_inc(&iucv
->pendings
);
2309 case TX_NOTIFY_DELAYED_OK
:
2310 __skb_unlink(list_skb
, list
);
2311 atomic_dec(&iucv
->pendings
);
2312 if (atomic_read(&iucv
->pendings
) <= 0)
2313 iucv_sock_wake_msglim(sk
);
2314 kfree_skb(list_skb
);
2316 case TX_NOTIFY_UNREACHABLE
:
2317 case TX_NOTIFY_DELAYED_UNREACHABLE
:
2318 case TX_NOTIFY_TPQFULL
: /* not yet used */
2319 case TX_NOTIFY_GENERALERROR
:
2320 case TX_NOTIFY_DELAYED_GENERALERROR
:
2321 __skb_unlink(list_skb
, list
);
2322 kfree_skb(list_skb
);
2323 if (sk
->sk_state
== IUCV_CONNECTED
) {
2324 sk
->sk_state
= IUCV_DISCONN
;
2325 sk
->sk_state_change(sk
);
2332 spin_unlock_irqrestore(&list
->lock
, flags
);
2334 if (sk
->sk_state
== IUCV_CLOSING
) {
2335 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
2336 sk
->sk_state
= IUCV_CLOSED
;
2337 sk
->sk_state_change(sk
);
2344 * afiucv_netdev_event: handle netdev notifier chain events
2346 static int afiucv_netdev_event(struct notifier_block
*this,
2347 unsigned long event
, void *ptr
)
2349 struct net_device
*event_dev
= netdev_notifier_info_to_dev(ptr
);
2351 struct iucv_sock
*iucv
;
2355 case NETDEV_GOING_DOWN
:
2356 sk_for_each(sk
, &iucv_sk_list
.head
) {
2358 if ((iucv
->hs_dev
== event_dev
) &&
2359 (sk
->sk_state
== IUCV_CONNECTED
)) {
2360 if (event
== NETDEV_GOING_DOWN
)
2361 iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
2362 sk
->sk_state
= IUCV_DISCONN
;
2363 sk
->sk_state_change(sk
);
2368 case NETDEV_UNREGISTER
:
2375 static struct notifier_block afiucv_netdev_notifier
= {
2376 .notifier_call
= afiucv_netdev_event
,
2379 static const struct proto_ops iucv_sock_ops
= {
2381 .owner
= THIS_MODULE
,
2382 .release
= iucv_sock_release
,
2383 .bind
= iucv_sock_bind
,
2384 .connect
= iucv_sock_connect
,
2385 .listen
= iucv_sock_listen
,
2386 .accept
= iucv_sock_accept
,
2387 .getname
= iucv_sock_getname
,
2388 .sendmsg
= iucv_sock_sendmsg
,
2389 .recvmsg
= iucv_sock_recvmsg
,
2390 .poll
= iucv_sock_poll
,
2391 .ioctl
= sock_no_ioctl
,
2392 .mmap
= sock_no_mmap
,
2393 .socketpair
= sock_no_socketpair
,
2394 .shutdown
= iucv_sock_shutdown
,
2395 .setsockopt
= iucv_sock_setsockopt
,
2396 .getsockopt
= iucv_sock_getsockopt
,
2399 static const struct net_proto_family iucv_sock_family_ops
= {
2401 .owner
= THIS_MODULE
,
2402 .create
= iucv_sock_create
,
2405 static struct packet_type iucv_packet_type
= {
2406 .type
= cpu_to_be16(ETH_P_AF_IUCV
),
2407 .func
= afiucv_hs_rcv
,
2410 static int afiucv_iucv_init(void)
2414 err
= pr_iucv
->iucv_register(&af_iucv_handler
, 0);
2417 /* establish dummy device */
2418 af_iucv_driver
.bus
= pr_iucv
->bus
;
2419 err
= driver_register(&af_iucv_driver
);
2422 af_iucv_dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
2427 dev_set_name(af_iucv_dev
, "af_iucv");
2428 af_iucv_dev
->bus
= pr_iucv
->bus
;
2429 af_iucv_dev
->parent
= pr_iucv
->root
;
2430 af_iucv_dev
->release
= (void (*)(struct device
*))kfree
;
2431 af_iucv_dev
->driver
= &af_iucv_driver
;
2432 err
= device_register(af_iucv_dev
);
2438 put_device(af_iucv_dev
);
2440 driver_unregister(&af_iucv_driver
);
2442 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2447 static void afiucv_iucv_exit(void)
2449 device_unregister(af_iucv_dev
);
2450 driver_unregister(&af_iucv_driver
);
2451 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2454 static int __init
afiucv_init(void)
2458 if (MACHINE_IS_VM
) {
2459 cpcmd("QUERY USERID", iucv_userid
, sizeof(iucv_userid
), &err
);
2460 if (unlikely(err
)) {
2462 err
= -EPROTONOSUPPORT
;
2466 pr_iucv
= try_then_request_module(symbol_get(iucv_if
), "iucv");
2468 printk(KERN_WARNING
"iucv_if lookup failed\n");
2469 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2472 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2476 err
= proto_register(&iucv_proto
, 0);
2479 err
= sock_register(&iucv_sock_family_ops
);
2484 err
= afiucv_iucv_init();
2489 err
= register_netdevice_notifier(&afiucv_netdev_notifier
);
2493 dev_add_pack(&iucv_packet_type
);
2500 sock_unregister(PF_IUCV
);
2502 proto_unregister(&iucv_proto
);
2505 symbol_put(iucv_if
);
2509 static void __exit
afiucv_exit(void)
2513 symbol_put(iucv_if
);
2516 unregister_netdevice_notifier(&afiucv_netdev_notifier
);
2517 dev_remove_pack(&iucv_packet_type
);
2518 sock_unregister(PF_IUCV
);
2519 proto_unregister(&iucv_proto
);
2522 module_init(afiucv_init
);
2523 module_exit(afiucv_exit
);
2525 MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>");
2526 MODULE_DESCRIPTION("IUCV Sockets ver " VERSION
);
2527 MODULE_VERSION(VERSION
);
2528 MODULE_LICENSE("GPL");
2529 MODULE_ALIAS_NETPROTO(PF_IUCV
);