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>
25 #include <linux/security.h>
27 #include <asm/ebcdic.h>
28 #include <asm/cpcmd.h>
29 #include <linux/kmod.h>
31 #include <net/iucv/af_iucv.h>
35 static char iucv_userid
[80];
37 static const struct proto_ops iucv_sock_ops
;
39 static struct proto iucv_proto
= {
42 .obj_size
= sizeof(struct iucv_sock
),
45 static struct iucv_interface
*pr_iucv
;
47 /* special AF_IUCV IPRM messages */
48 static const u8 iprm_shutdown
[8] =
49 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
51 #define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
53 #define __iucv_sock_wait(sk, condition, timeo, ret) \
55 DEFINE_WAIT(__wait); \
56 long __timeo = timeo; \
58 prepare_to_wait(sk_sleep(sk), &__wait, TASK_INTERRUPTIBLE); \
59 while (!(condition)) { \
64 if (signal_pending(current)) { \
65 ret = sock_intr_errno(__timeo); \
69 __timeo = schedule_timeout(__timeo); \
71 ret = sock_error(sk); \
75 finish_wait(sk_sleep(sk), &__wait); \
78 #define iucv_sock_wait(sk, condition, timeo) \
82 __iucv_sock_wait(sk, condition, timeo, __ret); \
86 static void iucv_sock_kill(struct sock
*sk
);
87 static void iucv_sock_close(struct sock
*sk
);
88 static void iucv_sever_path(struct sock
*, int);
90 static int afiucv_hs_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
91 struct packet_type
*pt
, struct net_device
*orig_dev
);
92 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
93 struct sk_buff
*skb
, u8 flags
);
94 static void afiucv_hs_callback_txnotify(struct sk_buff
*, enum iucv_tx_notify
);
96 /* Call Back functions */
97 static void iucv_callback_rx(struct iucv_path
*, struct iucv_message
*);
98 static void iucv_callback_txdone(struct iucv_path
*, struct iucv_message
*);
99 static void iucv_callback_connack(struct iucv_path
*, u8
*);
100 static int iucv_callback_connreq(struct iucv_path
*, u8
*, u8
*);
101 static void iucv_callback_connrej(struct iucv_path
*, u8
*);
102 static void iucv_callback_shutdown(struct iucv_path
*, u8
*);
104 static struct iucv_sock_list iucv_sk_list
= {
105 .lock
= __RW_LOCK_UNLOCKED(iucv_sk_list
.lock
),
106 .autobind_name
= ATOMIC_INIT(0)
109 static struct iucv_handler af_iucv_handler
= {
110 .path_pending
= iucv_callback_connreq
,
111 .path_complete
= iucv_callback_connack
,
112 .path_severed
= iucv_callback_connrej
,
113 .message_pending
= iucv_callback_rx
,
114 .message_complete
= iucv_callback_txdone
,
115 .path_quiesced
= iucv_callback_shutdown
,
118 static inline void high_nmcpy(unsigned char *dst
, char *src
)
123 static inline void low_nmcpy(unsigned char *dst
, char *src
)
125 memcpy(&dst
[8], src
, 8);
128 static int afiucv_pm_prepare(struct device
*dev
)
130 #ifdef CONFIG_PM_DEBUG
131 printk(KERN_WARNING
"afiucv_pm_prepare\n");
136 static void afiucv_pm_complete(struct device
*dev
)
138 #ifdef CONFIG_PM_DEBUG
139 printk(KERN_WARNING
"afiucv_pm_complete\n");
144 * afiucv_pm_freeze() - Freeze PM callback
145 * @dev: AFIUCV dummy device
147 * Sever all established IUCV communication pathes
149 static int afiucv_pm_freeze(struct device
*dev
)
151 struct iucv_sock
*iucv
;
155 #ifdef CONFIG_PM_DEBUG
156 printk(KERN_WARNING
"afiucv_pm_freeze\n");
158 read_lock(&iucv_sk_list
.lock
);
159 sk_for_each(sk
, &iucv_sk_list
.head
) {
161 switch (sk
->sk_state
) {
165 iucv_sever_path(sk
, 0);
174 skb_queue_purge(&iucv
->send_skb_q
);
175 skb_queue_purge(&iucv
->backlog_skb_q
);
177 read_unlock(&iucv_sk_list
.lock
);
182 * afiucv_pm_restore_thaw() - Thaw and restore PM callback
183 * @dev: AFIUCV dummy device
185 * socket clean up after freeze
187 static int afiucv_pm_restore_thaw(struct device
*dev
)
191 #ifdef CONFIG_PM_DEBUG
192 printk(KERN_WARNING
"afiucv_pm_restore_thaw\n");
194 read_lock(&iucv_sk_list
.lock
);
195 sk_for_each(sk
, &iucv_sk_list
.head
) {
196 switch (sk
->sk_state
) {
199 sk
->sk_state
= IUCV_DISCONN
;
200 sk
->sk_state_change(sk
);
211 read_unlock(&iucv_sk_list
.lock
);
215 static const struct dev_pm_ops afiucv_pm_ops
= {
216 .prepare
= afiucv_pm_prepare
,
217 .complete
= afiucv_pm_complete
,
218 .freeze
= afiucv_pm_freeze
,
219 .thaw
= afiucv_pm_restore_thaw
,
220 .restore
= afiucv_pm_restore_thaw
,
223 static struct device_driver af_iucv_driver
= {
224 .owner
= THIS_MODULE
,
227 .pm
= &afiucv_pm_ops
,
230 /* dummy device used as trigger for PM functions */
231 static struct device
*af_iucv_dev
;
234 * iucv_msg_length() - Returns the length of an iucv message.
235 * @msg: Pointer to struct iucv_message, MUST NOT be NULL
237 * The function returns the length of the specified iucv message @msg of data
238 * stored in a buffer and of data stored in the parameter list (PRMDATA).
240 * For IUCV_IPRMDATA, AF_IUCV uses the following convention to transport socket
242 * PRMDATA[0..6] socket data (max 7 bytes);
243 * PRMDATA[7] socket data length value (len is 0xff - PRMDATA[7])
245 * The socket data length is computed by subtracting the socket data length
247 * If the socket data len is greater 7, then PRMDATA can be used for special
248 * notifications (see iucv_sock_shutdown); and further,
249 * if the socket data len is > 7, the function returns 8.
251 * Use this function to allocate socket buffers to store iucv message data.
253 static inline size_t iucv_msg_length(struct iucv_message
*msg
)
257 if (msg
->flags
& IUCV_IPRMDATA
) {
258 datalen
= 0xff - msg
->rmmsg
[7];
259 return (datalen
< 8) ? datalen
: 8;
265 * iucv_sock_in_state() - check for specific states
266 * @sk: sock structure
267 * @state: first iucv sk state
268 * @state: second iucv sk state
270 * Returns true if the socket in either in the first or second state.
272 static int iucv_sock_in_state(struct sock
*sk
, int state
, int state2
)
274 return (sk
->sk_state
== state
|| sk
->sk_state
== state2
);
278 * iucv_below_msglim() - function to check if messages can be sent
279 * @sk: sock structure
281 * Returns true if the send queue length is lower than the message limit.
282 * Always returns true if the socket is not connected (no iucv path for
283 * checking the message limit).
285 static inline int iucv_below_msglim(struct sock
*sk
)
287 struct iucv_sock
*iucv
= iucv_sk(sk
);
289 if (sk
->sk_state
!= IUCV_CONNECTED
)
291 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
)
292 return (skb_queue_len(&iucv
->send_skb_q
) < iucv
->path
->msglim
);
294 return ((atomic_read(&iucv
->msg_sent
) < iucv
->msglimit_peer
) &&
295 (atomic_read(&iucv
->pendings
) <= 0));
299 * iucv_sock_wake_msglim() - Wake up thread waiting on msg limit
301 static void iucv_sock_wake_msglim(struct sock
*sk
)
303 struct socket_wq
*wq
;
306 wq
= rcu_dereference(sk
->sk_wq
);
307 if (skwq_has_sleeper(wq
))
308 wake_up_interruptible_all(&wq
->wait
);
309 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
314 * afiucv_hs_send() - send a message through HiperSockets transport
316 static int afiucv_hs_send(struct iucv_message
*imsg
, struct sock
*sock
,
317 struct sk_buff
*skb
, u8 flags
)
319 struct iucv_sock
*iucv
= iucv_sk(sock
);
320 struct af_iucv_trans_hdr
*phs_hdr
;
321 struct sk_buff
*nskb
;
322 int err
, confirm_recv
= 0;
324 memset(skb
->head
, 0, ETH_HLEN
);
325 phs_hdr
= (struct af_iucv_trans_hdr
*)skb_push(skb
,
326 sizeof(struct af_iucv_trans_hdr
));
327 skb_reset_mac_header(skb
);
328 skb_reset_network_header(skb
);
329 skb_push(skb
, ETH_HLEN
);
330 skb_reset_mac_header(skb
);
331 memset(phs_hdr
, 0, sizeof(struct af_iucv_trans_hdr
));
333 phs_hdr
->magic
= ETH_P_AF_IUCV
;
334 phs_hdr
->version
= 1;
335 phs_hdr
->flags
= flags
;
336 if (flags
== AF_IUCV_FLAG_SYN
)
337 phs_hdr
->window
= iucv
->msglimit
;
338 else if ((flags
== AF_IUCV_FLAG_WIN
) || !flags
) {
339 confirm_recv
= atomic_read(&iucv
->msg_recv
);
340 phs_hdr
->window
= confirm_recv
;
342 phs_hdr
->flags
= phs_hdr
->flags
| AF_IUCV_FLAG_WIN
;
344 memcpy(phs_hdr
->destUserID
, iucv
->dst_user_id
, 8);
345 memcpy(phs_hdr
->destAppName
, iucv
->dst_name
, 8);
346 memcpy(phs_hdr
->srcUserID
, iucv
->src_user_id
, 8);
347 memcpy(phs_hdr
->srcAppName
, iucv
->src_name
, 8);
348 ASCEBC(phs_hdr
->destUserID
, sizeof(phs_hdr
->destUserID
));
349 ASCEBC(phs_hdr
->destAppName
, sizeof(phs_hdr
->destAppName
));
350 ASCEBC(phs_hdr
->srcUserID
, sizeof(phs_hdr
->srcUserID
));
351 ASCEBC(phs_hdr
->srcAppName
, sizeof(phs_hdr
->srcAppName
));
353 memcpy(&phs_hdr
->iucv_hdr
, imsg
, sizeof(struct iucv_message
));
355 skb
->dev
= iucv
->hs_dev
;
358 if (!(skb
->dev
->flags
& IFF_UP
) || !netif_carrier_ok(skb
->dev
))
360 if (skb
->len
> skb
->dev
->mtu
) {
361 if (sock
->sk_type
== SOCK_SEQPACKET
)
364 skb_trim(skb
, skb
->dev
->mtu
);
366 skb
->protocol
= ETH_P_AF_IUCV
;
367 nskb
= skb_clone(skb
, GFP_ATOMIC
);
370 skb_queue_tail(&iucv
->send_skb_q
, nskb
);
371 err
= dev_queue_xmit(skb
);
372 if (net_xmit_eval(err
)) {
373 skb_unlink(nskb
, &iucv
->send_skb_q
);
376 atomic_sub(confirm_recv
, &iucv
->msg_recv
);
377 WARN_ON(atomic_read(&iucv
->msg_recv
) < 0);
379 return net_xmit_eval(err
);
382 static struct sock
*__iucv_get_sock_by_name(char *nm
)
386 sk_for_each(sk
, &iucv_sk_list
.head
)
387 if (!memcmp(&iucv_sk(sk
)->src_name
, nm
, 8))
393 static void iucv_sock_destruct(struct sock
*sk
)
395 skb_queue_purge(&sk
->sk_receive_queue
);
396 skb_queue_purge(&sk
->sk_error_queue
);
400 if (!sock_flag(sk
, SOCK_DEAD
)) {
401 pr_err("Attempt to release alive iucv socket %p\n", sk
);
405 WARN_ON(atomic_read(&sk
->sk_rmem_alloc
));
406 WARN_ON(atomic_read(&sk
->sk_wmem_alloc
));
407 WARN_ON(sk
->sk_wmem_queued
);
408 WARN_ON(sk
->sk_forward_alloc
);
412 static void iucv_sock_cleanup_listen(struct sock
*parent
)
416 /* Close non-accepted connections */
417 while ((sk
= iucv_accept_dequeue(parent
, NULL
))) {
422 parent
->sk_state
= IUCV_CLOSED
;
425 /* Kill socket (only if zapped and orphaned) */
426 static void iucv_sock_kill(struct sock
*sk
)
428 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
431 iucv_sock_unlink(&iucv_sk_list
, sk
);
432 sock_set_flag(sk
, SOCK_DEAD
);
436 /* Terminate an IUCV path */
437 static void iucv_sever_path(struct sock
*sk
, int with_user_data
)
439 unsigned char user_data
[16];
440 struct iucv_sock
*iucv
= iucv_sk(sk
);
441 struct iucv_path
*path
= iucv
->path
;
445 if (with_user_data
) {
446 low_nmcpy(user_data
, iucv
->src_name
);
447 high_nmcpy(user_data
, iucv
->dst_name
);
448 ASCEBC(user_data
, sizeof(user_data
));
449 pr_iucv
->path_sever(path
, user_data
);
451 pr_iucv
->path_sever(path
, NULL
);
452 iucv_path_free(path
);
456 /* Send FIN through an IUCV socket for HIPER transport */
457 static int iucv_send_ctrl(struct sock
*sk
, u8 flags
)
463 blen
= sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
;
464 skb
= sock_alloc_send_skb(sk
, blen
, 1, &err
);
466 skb_reserve(skb
, blen
);
467 err
= afiucv_hs_send(NULL
, sk
, skb
, flags
);
472 /* Close an IUCV socket */
473 static void iucv_sock_close(struct sock
*sk
)
475 struct iucv_sock
*iucv
= iucv_sk(sk
);
481 switch (sk
->sk_state
) {
483 iucv_sock_cleanup_listen(sk
);
487 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
488 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
489 sk
->sk_state
= IUCV_DISCONN
;
490 sk
->sk_state_change(sk
);
492 case IUCV_DISCONN
: /* fall through */
493 sk
->sk_state
= IUCV_CLOSING
;
494 sk
->sk_state_change(sk
);
496 if (!err
&& !skb_queue_empty(&iucv
->send_skb_q
)) {
497 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
498 timeo
= sk
->sk_lingertime
;
500 timeo
= IUCV_DISCONN_TIMEOUT
;
502 iucv_sock_in_state(sk
, IUCV_CLOSED
, 0),
506 case IUCV_CLOSING
: /* fall through */
507 sk
->sk_state
= IUCV_CLOSED
;
508 sk
->sk_state_change(sk
);
510 sk
->sk_err
= ECONNRESET
;
511 sk
->sk_state_change(sk
);
513 skb_queue_purge(&iucv
->send_skb_q
);
514 skb_queue_purge(&iucv
->backlog_skb_q
);
516 default: /* fall through */
517 iucv_sever_path(sk
, 1);
521 dev_put(iucv
->hs_dev
);
523 sk
->sk_bound_dev_if
= 0;
526 /* mark socket for deletion by iucv_sock_kill() */
527 sock_set_flag(sk
, SOCK_ZAPPED
);
532 static void iucv_sock_init(struct sock
*sk
, struct sock
*parent
)
535 sk
->sk_type
= parent
->sk_type
;
536 security_sk_clone(parent
, sk
);
540 static struct sock
*iucv_sock_alloc(struct socket
*sock
, int proto
, gfp_t prio
, int kern
)
543 struct iucv_sock
*iucv
;
545 sk
= sk_alloc(&init_net
, PF_IUCV
, prio
, &iucv_proto
, kern
);
550 sock_init_data(sock
, sk
);
551 INIT_LIST_HEAD(&iucv
->accept_q
);
552 spin_lock_init(&iucv
->accept_q_lock
);
553 skb_queue_head_init(&iucv
->send_skb_q
);
554 INIT_LIST_HEAD(&iucv
->message_q
.list
);
555 spin_lock_init(&iucv
->message_q
.lock
);
556 skb_queue_head_init(&iucv
->backlog_skb_q
);
558 atomic_set(&iucv
->pendings
, 0);
561 atomic_set(&iucv
->msg_sent
, 0);
562 atomic_set(&iucv
->msg_recv
, 0);
564 iucv
->sk_txnotify
= afiucv_hs_callback_txnotify
;
565 memset(&iucv
->src_user_id
, 0, 32);
567 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
569 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
571 sk
->sk_destruct
= iucv_sock_destruct
;
572 sk
->sk_sndtimeo
= IUCV_CONN_TIMEOUT
;
573 sk
->sk_allocation
= GFP_DMA
;
575 sock_reset_flag(sk
, SOCK_ZAPPED
);
577 sk
->sk_protocol
= proto
;
578 sk
->sk_state
= IUCV_OPEN
;
580 iucv_sock_link(&iucv_sk_list
, sk
);
584 /* Create an IUCV socket */
585 static int iucv_sock_create(struct net
*net
, struct socket
*sock
, int protocol
,
590 if (protocol
&& protocol
!= PF_IUCV
)
591 return -EPROTONOSUPPORT
;
593 sock
->state
= SS_UNCONNECTED
;
595 switch (sock
->type
) {
597 sock
->ops
= &iucv_sock_ops
;
600 /* currently, proto ops can handle both sk types */
601 sock
->ops
= &iucv_sock_ops
;
604 return -ESOCKTNOSUPPORT
;
607 sk
= iucv_sock_alloc(sock
, protocol
, GFP_KERNEL
, kern
);
611 iucv_sock_init(sk
, NULL
);
616 void iucv_sock_link(struct iucv_sock_list
*l
, struct sock
*sk
)
618 write_lock_bh(&l
->lock
);
619 sk_add_node(sk
, &l
->head
);
620 write_unlock_bh(&l
->lock
);
623 void iucv_sock_unlink(struct iucv_sock_list
*l
, struct sock
*sk
)
625 write_lock_bh(&l
->lock
);
626 sk_del_node_init(sk
);
627 write_unlock_bh(&l
->lock
);
630 void iucv_accept_enqueue(struct sock
*parent
, struct sock
*sk
)
633 struct iucv_sock
*par
= iucv_sk(parent
);
636 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
637 list_add_tail(&iucv_sk(sk
)->accept_q
, &par
->accept_q
);
638 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
639 iucv_sk(sk
)->parent
= parent
;
640 sk_acceptq_added(parent
);
643 void iucv_accept_unlink(struct sock
*sk
)
646 struct iucv_sock
*par
= iucv_sk(iucv_sk(sk
)->parent
);
648 spin_lock_irqsave(&par
->accept_q_lock
, flags
);
649 list_del_init(&iucv_sk(sk
)->accept_q
);
650 spin_unlock_irqrestore(&par
->accept_q_lock
, flags
);
651 sk_acceptq_removed(iucv_sk(sk
)->parent
);
652 iucv_sk(sk
)->parent
= NULL
;
656 struct sock
*iucv_accept_dequeue(struct sock
*parent
, struct socket
*newsock
)
658 struct iucv_sock
*isk
, *n
;
661 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
662 sk
= (struct sock
*) isk
;
665 if (sk
->sk_state
== IUCV_CLOSED
) {
666 iucv_accept_unlink(sk
);
671 if (sk
->sk_state
== IUCV_CONNECTED
||
672 sk
->sk_state
== IUCV_DISCONN
||
674 iucv_accept_unlink(sk
);
676 sock_graft(sk
, newsock
);
687 static void __iucv_auto_name(struct iucv_sock
*iucv
)
691 sprintf(name
, "%08x", atomic_inc_return(&iucv_sk_list
.autobind_name
));
692 while (__iucv_get_sock_by_name(name
)) {
693 sprintf(name
, "%08x",
694 atomic_inc_return(&iucv_sk_list
.autobind_name
));
696 memcpy(iucv
->src_name
, name
, 8);
699 /* Bind an unbound socket */
700 static int iucv_sock_bind(struct socket
*sock
, struct sockaddr
*addr
,
703 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
704 struct sock
*sk
= sock
->sk
;
705 struct iucv_sock
*iucv
;
707 struct net_device
*dev
;
710 /* Verify the input sockaddr */
711 if (!addr
|| addr
->sa_family
!= AF_IUCV
)
714 if (addr_len
< sizeof(struct sockaddr_iucv
))
718 if (sk
->sk_state
!= IUCV_OPEN
) {
723 write_lock_bh(&iucv_sk_list
.lock
);
726 if (__iucv_get_sock_by_name(sa
->siucv_name
)) {
733 /* Bind the socket */
735 if (!memcmp(sa
->siucv_user_id
, iucv_userid
, 8))
736 goto vm_bind
; /* VM IUCV transport */
738 /* try hiper transport */
739 memcpy(uid
, sa
->siucv_user_id
, sizeof(uid
));
742 for_each_netdev_rcu(&init_net
, dev
) {
743 if (!memcmp(dev
->perm_addr
, uid
, 8)) {
744 memcpy(iucv
->src_user_id
, sa
->siucv_user_id
, 8);
745 /* Check for unitialized siucv_name */
746 if (strncmp(sa
->siucv_name
, " ", 8) == 0)
747 __iucv_auto_name(iucv
);
749 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
750 sk
->sk_bound_dev_if
= dev
->ifindex
;
753 sk
->sk_state
= IUCV_BOUND
;
754 iucv
->transport
= AF_IUCV_TRANS_HIPER
;
756 iucv
->msglimit
= IUCV_HIPER_MSGLIM_DEFAULT
;
764 /* use local userid for backward compat */
765 memcpy(iucv
->src_name
, sa
->siucv_name
, 8);
766 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
767 sk
->sk_state
= IUCV_BOUND
;
768 iucv
->transport
= AF_IUCV_TRANS_IUCV
;
770 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
773 /* found no dev to bind */
776 /* Release the socket list lock */
777 write_unlock_bh(&iucv_sk_list
.lock
);
783 /* Automatically bind an unbound socket */
784 static int iucv_sock_autobind(struct sock
*sk
)
786 struct iucv_sock
*iucv
= iucv_sk(sk
);
789 if (unlikely(!pr_iucv
))
792 memcpy(iucv
->src_user_id
, iucv_userid
, 8);
794 write_lock_bh(&iucv_sk_list
.lock
);
795 __iucv_auto_name(iucv
);
796 write_unlock_bh(&iucv_sk_list
.lock
);
799 iucv
->msglimit
= IUCV_QUEUELEN_DEFAULT
;
804 static int afiucv_path_connect(struct socket
*sock
, struct sockaddr
*addr
)
806 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
807 struct sock
*sk
= sock
->sk
;
808 struct iucv_sock
*iucv
= iucv_sk(sk
);
809 unsigned char user_data
[16];
812 high_nmcpy(user_data
, sa
->siucv_name
);
813 low_nmcpy(user_data
, iucv
->src_name
);
814 ASCEBC(user_data
, sizeof(user_data
));
817 iucv
->path
= iucv_path_alloc(iucv
->msglimit
,
818 IUCV_IPRMDATA
, GFP_KERNEL
);
823 err
= pr_iucv
->path_connect(iucv
->path
, &af_iucv_handler
,
824 sa
->siucv_user_id
, NULL
, user_data
,
827 iucv_path_free(iucv
->path
);
830 case 0x0b: /* Target communicator is not logged on */
833 case 0x0d: /* Max connections for this guest exceeded */
834 case 0x0e: /* Max connections for target guest exceeded */
837 case 0x0f: /* Missing IUCV authorization */
849 /* Connect an unconnected socket */
850 static int iucv_sock_connect(struct socket
*sock
, struct sockaddr
*addr
,
853 struct sockaddr_iucv
*sa
= (struct sockaddr_iucv
*) addr
;
854 struct sock
*sk
= sock
->sk
;
855 struct iucv_sock
*iucv
= iucv_sk(sk
);
858 if (addr
->sa_family
!= AF_IUCV
|| alen
< sizeof(struct sockaddr_iucv
))
861 if (sk
->sk_state
!= IUCV_OPEN
&& sk
->sk_state
!= IUCV_BOUND
)
864 if (sk
->sk_state
== IUCV_OPEN
&&
865 iucv
->transport
== AF_IUCV_TRANS_HIPER
)
866 return -EBADFD
; /* explicit bind required */
868 if (sk
->sk_type
!= SOCK_STREAM
&& sk
->sk_type
!= SOCK_SEQPACKET
)
871 if (sk
->sk_state
== IUCV_OPEN
) {
872 err
= iucv_sock_autobind(sk
);
879 /* Set the destination information */
880 memcpy(iucv
->dst_user_id
, sa
->siucv_user_id
, 8);
881 memcpy(iucv
->dst_name
, sa
->siucv_name
, 8);
883 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
884 err
= iucv_send_ctrl(sock
->sk
, AF_IUCV_FLAG_SYN
);
886 err
= afiucv_path_connect(sock
, addr
);
890 if (sk
->sk_state
!= IUCV_CONNECTED
)
891 err
= iucv_sock_wait(sk
, iucv_sock_in_state(sk
, IUCV_CONNECTED
,
893 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
895 if (sk
->sk_state
== IUCV_DISCONN
|| sk
->sk_state
== IUCV_CLOSED
)
898 if (err
&& iucv
->transport
== AF_IUCV_TRANS_IUCV
)
899 iucv_sever_path(sk
, 0);
906 /* Move a socket into listening state. */
907 static int iucv_sock_listen(struct socket
*sock
, int backlog
)
909 struct sock
*sk
= sock
->sk
;
915 if (sk
->sk_state
!= IUCV_BOUND
)
918 if (sock
->type
!= SOCK_STREAM
&& sock
->type
!= SOCK_SEQPACKET
)
921 sk
->sk_max_ack_backlog
= backlog
;
922 sk
->sk_ack_backlog
= 0;
923 sk
->sk_state
= IUCV_LISTEN
;
931 /* Accept a pending connection */
932 static int iucv_sock_accept(struct socket
*sock
, struct socket
*newsock
,
935 DECLARE_WAITQUEUE(wait
, current
);
936 struct sock
*sk
= sock
->sk
, *nsk
;
940 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
942 if (sk
->sk_state
!= IUCV_LISTEN
) {
947 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
949 /* Wait for an incoming connection */
950 add_wait_queue_exclusive(sk_sleep(sk
), &wait
);
951 while (!(nsk
= iucv_accept_dequeue(sk
, newsock
))) {
952 set_current_state(TASK_INTERRUPTIBLE
);
959 timeo
= schedule_timeout(timeo
);
960 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
962 if (sk
->sk_state
!= IUCV_LISTEN
) {
967 if (signal_pending(current
)) {
968 err
= sock_intr_errno(timeo
);
973 set_current_state(TASK_RUNNING
);
974 remove_wait_queue(sk_sleep(sk
), &wait
);
979 newsock
->state
= SS_CONNECTED
;
986 static int iucv_sock_getname(struct socket
*sock
, struct sockaddr
*addr
,
989 struct sockaddr_iucv
*siucv
= (struct sockaddr_iucv
*) addr
;
990 struct sock
*sk
= sock
->sk
;
991 struct iucv_sock
*iucv
= iucv_sk(sk
);
993 addr
->sa_family
= AF_IUCV
;
994 *len
= sizeof(struct sockaddr_iucv
);
997 memcpy(siucv
->siucv_user_id
, iucv
->dst_user_id
, 8);
998 memcpy(siucv
->siucv_name
, iucv
->dst_name
, 8);
1000 memcpy(siucv
->siucv_user_id
, iucv
->src_user_id
, 8);
1001 memcpy(siucv
->siucv_name
, iucv
->src_name
, 8);
1003 memset(&siucv
->siucv_port
, 0, sizeof(siucv
->siucv_port
));
1004 memset(&siucv
->siucv_addr
, 0, sizeof(siucv
->siucv_addr
));
1005 memset(&siucv
->siucv_nodeid
, 0, sizeof(siucv
->siucv_nodeid
));
1011 * iucv_send_iprm() - Send socket data in parameter list of an iucv message.
1013 * @msg: Pointer to a struct iucv_message
1014 * @skb: The socket data to send, skb->len MUST BE <= 7
1016 * Send the socket data in the parameter list in the iucv message
1017 * (IUCV_IPRMDATA). The socket data is stored at index 0 to 6 in the parameter
1018 * list and the socket data len at index 7 (last byte).
1019 * See also iucv_msg_length().
1021 * Returns the error code from the iucv_message_send() call.
1023 static int iucv_send_iprm(struct iucv_path
*path
, struct iucv_message
*msg
,
1024 struct sk_buff
*skb
)
1028 memcpy(prmdata
, (void *) skb
->data
, skb
->len
);
1029 prmdata
[7] = 0xff - (u8
) skb
->len
;
1030 return pr_iucv
->message_send(path
, msg
, IUCV_IPRMDATA
, 0,
1031 (void *) prmdata
, 8);
1034 static int iucv_sock_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
1037 struct sock
*sk
= sock
->sk
;
1038 struct iucv_sock
*iucv
= iucv_sk(sk
);
1039 size_t headroom
, linear
;
1040 struct sk_buff
*skb
;
1041 struct iucv_message txmsg
= {0};
1042 struct cmsghdr
*cmsg
;
1048 int noblock
= msg
->msg_flags
& MSG_DONTWAIT
;
1050 err
= sock_error(sk
);
1054 if (msg
->msg_flags
& MSG_OOB
)
1057 /* SOCK_SEQPACKET: we do not support segmented records */
1058 if (sk
->sk_type
== SOCK_SEQPACKET
&& !(msg
->msg_flags
& MSG_EOR
))
1063 if (sk
->sk_shutdown
& SEND_SHUTDOWN
) {
1068 /* Return if the socket is not in connected state */
1069 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1074 /* initialize defaults */
1075 cmsg_done
= 0; /* check for duplicate headers */
1078 /* iterate over control messages */
1079 for_each_cmsghdr(cmsg
, msg
) {
1080 if (!CMSG_OK(msg
, cmsg
)) {
1085 if (cmsg
->cmsg_level
!= SOL_IUCV
)
1088 if (cmsg
->cmsg_type
& cmsg_done
) {
1092 cmsg_done
|= cmsg
->cmsg_type
;
1094 switch (cmsg
->cmsg_type
) {
1095 case SCM_IUCV_TRGCLS
:
1096 if (cmsg
->cmsg_len
!= CMSG_LEN(TRGCLS_SIZE
)) {
1101 /* set iucv message target class */
1102 memcpy(&txmsg
.class,
1103 (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 headroom
= (iucv
->transport
== AF_IUCV_TRANS_HIPER
)
1118 ? sizeof(struct af_iucv_trans_hdr
) + ETH_HLEN
: 0;
1119 if (headroom
+ len
< PAGE_SIZE
) {
1122 /* In nonlinear "classic" iucv skb,
1123 * reserve space for iucv_array
1125 if (iucv
->transport
!= AF_IUCV_TRANS_HIPER
)
1126 headroom
+= sizeof(struct iucv_array
) *
1127 (MAX_SKB_FRAGS
+ 1);
1128 linear
= PAGE_SIZE
- headroom
;
1130 skb
= sock_alloc_send_pskb(sk
, headroom
+ linear
, len
- linear
,
1135 skb_reserve(skb
, headroom
);
1136 skb_put(skb
, linear
);
1138 skb
->data_len
= len
- linear
;
1139 err
= skb_copy_datagram_from_iter(skb
, 0, &msg
->msg_iter
, len
);
1143 /* wait if outstanding messages for iucv path has reached */
1144 timeo
= sock_sndtimeo(sk
, noblock
);
1145 err
= iucv_sock_wait(sk
, iucv_below_msglim(sk
), timeo
);
1149 /* return -ECONNRESET if the socket is no longer connected */
1150 if (sk
->sk_state
!= IUCV_CONNECTED
) {
1155 /* increment and save iucv message tag for msg_completion cbk */
1156 txmsg
.tag
= iucv
->send_tag
++;
1157 IUCV_SKB_CB(skb
)->tag
= txmsg
.tag
;
1159 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1160 atomic_inc(&iucv
->msg_sent
);
1161 err
= afiucv_hs_send(&txmsg
, sk
, skb
, 0);
1163 atomic_dec(&iucv
->msg_sent
);
1166 } else { /* Classic VM IUCV transport */
1167 skb_queue_tail(&iucv
->send_skb_q
, skb
);
1169 if (((iucv
->path
->flags
& IUCV_IPRMDATA
) & iucv
->flags
) &&
1171 err
= iucv_send_iprm(iucv
->path
, &txmsg
, skb
);
1173 /* on success: there is no message_complete callback */
1174 /* for an IPRMDATA msg; remove skb from send queue */
1176 skb_unlink(skb
, &iucv
->send_skb_q
);
1180 /* this error should never happen since the */
1181 /* IUCV_IPRMDATA path flag is set... sever path */
1183 pr_iucv
->path_sever(iucv
->path
, NULL
);
1184 skb_unlink(skb
, &iucv
->send_skb_q
);
1188 } else if (skb_is_nonlinear(skb
)) {
1189 struct iucv_array
*iba
= (struct iucv_array
*)skb
->head
;
1192 /* skip iucv_array lying in the headroom */
1193 iba
[0].address
= (u32
)(addr_t
)skb
->data
;
1194 iba
[0].length
= (u32
)skb_headlen(skb
);
1195 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1196 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1198 iba
[i
+ 1].address
=
1199 (u32
)(addr_t
)skb_frag_address(frag
);
1200 iba
[i
+ 1].length
= (u32
)skb_frag_size(frag
);
1202 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1204 (void *)iba
, skb
->len
);
1205 } else { /* non-IPRM Linear skb */
1206 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1207 0, 0, (void *)skb
->data
, skb
->len
);
1212 memcpy(user_id
, iucv
->dst_user_id
, 8);
1214 memcpy(appl_id
, iucv
->dst_name
, 8);
1216 "Application %s on z/VM guest %s exceeds message limit\n",
1222 skb_unlink(skb
, &iucv
->send_skb_q
);
1237 static struct sk_buff
*alloc_iucv_recv_skb(unsigned long len
)
1239 size_t headroom
, linear
;
1240 struct sk_buff
*skb
;
1243 if (len
< PAGE_SIZE
) {
1247 headroom
= sizeof(struct iucv_array
) * (MAX_SKB_FRAGS
+ 1);
1248 linear
= PAGE_SIZE
- headroom
;
1250 skb
= alloc_skb_with_frags(headroom
+ linear
, len
- linear
,
1251 0, &err
, GFP_ATOMIC
| GFP_DMA
);
1253 "alloc of recv iucv skb len=%lu failed with errcode=%d\n",
1257 skb_reserve(skb
, headroom
);
1258 skb_put(skb
, linear
);
1260 skb
->data_len
= len
- linear
;
1265 /* iucv_process_message() - Receive a single outstanding IUCV message
1267 * Locking: must be called with message_q.lock held
1269 static void iucv_process_message(struct sock
*sk
, struct sk_buff
*skb
,
1270 struct iucv_path
*path
,
1271 struct iucv_message
*msg
)
1276 len
= iucv_msg_length(msg
);
1278 /* store msg target class in the second 4 bytes of skb ctrl buffer */
1279 /* Note: the first 4 bytes are reserved for msg tag */
1280 IUCV_SKB_CB(skb
)->class = msg
->class;
1282 /* check for special IPRM messages (e.g. iucv_sock_shutdown) */
1283 if ((msg
->flags
& IUCV_IPRMDATA
) && len
> 7) {
1284 if (memcmp(msg
->rmmsg
, iprm_shutdown
, 8) == 0) {
1289 if (skb_is_nonlinear(skb
)) {
1290 struct iucv_array
*iba
= (struct iucv_array
*)skb
->head
;
1293 iba
[0].address
= (u32
)(addr_t
)skb
->data
;
1294 iba
[0].length
= (u32
)skb_headlen(skb
);
1295 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1296 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1298 iba
[i
+ 1].address
=
1299 (u32
)(addr_t
)skb_frag_address(frag
);
1300 iba
[i
+ 1].length
= (u32
)skb_frag_size(frag
);
1302 rc
= pr_iucv
->message_receive(path
, msg
,
1304 (void *)iba
, len
, NULL
);
1306 rc
= pr_iucv
->message_receive(path
, msg
,
1307 msg
->flags
& IUCV_IPRMDATA
,
1308 skb
->data
, len
, NULL
);
1314 WARN_ON_ONCE(skb
->len
!= len
);
1317 IUCV_SKB_CB(skb
)->offset
= 0;
1318 if (sock_queue_rcv_skb(sk
, skb
))
1319 skb_queue_head(&iucv_sk(sk
)->backlog_skb_q
, skb
);
1322 /* iucv_process_message_q() - Process outstanding IUCV messages
1324 * Locking: must be called with message_q.lock held
1326 static void iucv_process_message_q(struct sock
*sk
)
1328 struct iucv_sock
*iucv
= iucv_sk(sk
);
1329 struct sk_buff
*skb
;
1330 struct sock_msg_q
*p
, *n
;
1332 list_for_each_entry_safe(p
, n
, &iucv
->message_q
.list
, list
) {
1333 skb
= alloc_iucv_recv_skb(iucv_msg_length(&p
->msg
));
1336 iucv_process_message(sk
, skb
, p
->path
, &p
->msg
);
1339 if (!skb_queue_empty(&iucv
->backlog_skb_q
))
1344 static int iucv_sock_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
1345 size_t len
, int flags
)
1347 int noblock
= flags
& MSG_DONTWAIT
;
1348 struct sock
*sk
= sock
->sk
;
1349 struct iucv_sock
*iucv
= iucv_sk(sk
);
1350 unsigned int copied
, rlen
;
1351 struct sk_buff
*skb
, *rskb
, *cskb
;
1355 if ((sk
->sk_state
== IUCV_DISCONN
) &&
1356 skb_queue_empty(&iucv
->backlog_skb_q
) &&
1357 skb_queue_empty(&sk
->sk_receive_queue
) &&
1358 list_empty(&iucv
->message_q
.list
))
1361 if (flags
& (MSG_OOB
))
1364 /* receive/dequeue next skb:
1365 * the function understands MSG_PEEK and, thus, does not dequeue skb */
1366 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
1368 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1373 offset
= IUCV_SKB_CB(skb
)->offset
;
1374 rlen
= skb
->len
- offset
; /* real length of skb */
1375 copied
= min_t(unsigned int, rlen
, len
);
1377 sk
->sk_shutdown
= sk
->sk_shutdown
| RCV_SHUTDOWN
;
1380 if (skb_copy_datagram_msg(cskb
, offset
, msg
, copied
)) {
1381 if (!(flags
& MSG_PEEK
))
1382 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1386 /* SOCK_SEQPACKET: set MSG_TRUNC if recv buf size is too small */
1387 if (sk
->sk_type
== SOCK_SEQPACKET
) {
1389 msg
->msg_flags
|= MSG_TRUNC
;
1390 /* each iucv message contains a complete record */
1391 msg
->msg_flags
|= MSG_EOR
;
1394 /* create control message to store iucv msg target class:
1395 * get the trgcls from the control buffer of the skb due to
1396 * fragmentation of original iucv message. */
1397 err
= put_cmsg(msg
, SOL_IUCV
, SCM_IUCV_TRGCLS
,
1398 sizeof(IUCV_SKB_CB(skb
)->class),
1399 (void *)&IUCV_SKB_CB(skb
)->class);
1401 if (!(flags
& MSG_PEEK
))
1402 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1406 /* Mark read part of skb as used */
1407 if (!(flags
& MSG_PEEK
)) {
1409 /* SOCK_STREAM: re-queue skb if it contains unreceived data */
1410 if (sk
->sk_type
== SOCK_STREAM
) {
1411 if (copied
< rlen
) {
1412 IUCV_SKB_CB(skb
)->offset
= offset
+ copied
;
1413 skb_queue_head(&sk
->sk_receive_queue
, skb
);
1419 if (iucv
->transport
== AF_IUCV_TRANS_HIPER
) {
1420 atomic_inc(&iucv
->msg_recv
);
1421 if (atomic_read(&iucv
->msg_recv
) > iucv
->msglimit
) {
1423 iucv_sock_close(sk
);
1428 /* Queue backlog skbs */
1429 spin_lock_bh(&iucv
->message_q
.lock
);
1430 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1432 IUCV_SKB_CB(rskb
)->offset
= 0;
1433 if (sock_queue_rcv_skb(sk
, rskb
)) {
1434 skb_queue_head(&iucv
->backlog_skb_q
,
1438 rskb
= skb_dequeue(&iucv
->backlog_skb_q
);
1441 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
1442 if (!list_empty(&iucv
->message_q
.list
))
1443 iucv_process_message_q(sk
);
1444 if (atomic_read(&iucv
->msg_recv
) >=
1445 iucv
->msglimit
/ 2) {
1446 err
= iucv_send_ctrl(sk
, AF_IUCV_FLAG_WIN
);
1448 sk
->sk_state
= IUCV_DISCONN
;
1449 sk
->sk_state_change(sk
);
1453 spin_unlock_bh(&iucv
->message_q
.lock
);
1457 /* SOCK_SEQPACKET: return real length if MSG_TRUNC is set */
1458 if (sk
->sk_type
== SOCK_SEQPACKET
&& (flags
& MSG_TRUNC
))
1464 static inline unsigned int iucv_accept_poll(struct sock
*parent
)
1466 struct iucv_sock
*isk
, *n
;
1469 list_for_each_entry_safe(isk
, n
, &iucv_sk(parent
)->accept_q
, accept_q
) {
1470 sk
= (struct sock
*) isk
;
1472 if (sk
->sk_state
== IUCV_CONNECTED
)
1473 return POLLIN
| POLLRDNORM
;
1479 unsigned int iucv_sock_poll(struct file
*file
, struct socket
*sock
,
1482 struct sock
*sk
= sock
->sk
;
1483 unsigned int mask
= 0;
1485 sock_poll_wait(file
, sk_sleep(sk
), wait
);
1487 if (sk
->sk_state
== IUCV_LISTEN
)
1488 return iucv_accept_poll(sk
);
1490 if (sk
->sk_err
|| !skb_queue_empty(&sk
->sk_error_queue
))
1492 (sock_flag(sk
, SOCK_SELECT_ERR_QUEUE
) ? POLLPRI
: 0);
1494 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
1497 if (sk
->sk_shutdown
== SHUTDOWN_MASK
)
1500 if (!skb_queue_empty(&sk
->sk_receive_queue
) ||
1501 (sk
->sk_shutdown
& RCV_SHUTDOWN
))
1502 mask
|= POLLIN
| POLLRDNORM
;
1504 if (sk
->sk_state
== IUCV_CLOSED
)
1507 if (sk
->sk_state
== IUCV_DISCONN
)
1510 if (sock_writeable(sk
) && iucv_below_msglim(sk
))
1511 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
1513 sk_set_bit(SOCKWQ_ASYNC_NOSPACE
, sk
);
1518 static int iucv_sock_shutdown(struct socket
*sock
, int how
)
1520 struct sock
*sk
= sock
->sk
;
1521 struct iucv_sock
*iucv
= iucv_sk(sk
);
1522 struct iucv_message txmsg
;
1527 if ((how
& ~SHUTDOWN_MASK
) || !how
)
1531 switch (sk
->sk_state
) {
1542 if (how
== SEND_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1543 if (iucv
->transport
== AF_IUCV_TRANS_IUCV
) {
1546 err
= pr_iucv
->message_send(iucv
->path
, &txmsg
,
1547 IUCV_IPRMDATA
, 0, (void *) iprm_shutdown
, 8);
1562 iucv_send_ctrl(sk
, AF_IUCV_FLAG_SHT
);
1565 sk
->sk_shutdown
|= how
;
1566 if (how
== RCV_SHUTDOWN
|| how
== SHUTDOWN_MASK
) {
1567 if ((iucv
->transport
== AF_IUCV_TRANS_IUCV
) &&
1569 err
= pr_iucv
->path_quiesce(iucv
->path
, NULL
);
1572 /* skb_queue_purge(&sk->sk_receive_queue); */
1574 skb_queue_purge(&sk
->sk_receive_queue
);
1577 /* Wake up anyone sleeping in poll */
1578 sk
->sk_state_change(sk
);
1585 static int iucv_sock_release(struct socket
*sock
)
1587 struct sock
*sk
= sock
->sk
;
1593 iucv_sock_close(sk
);
1600 /* getsockopt and setsockopt */
1601 static int iucv_sock_setsockopt(struct socket
*sock
, int level
, int optname
,
1602 char __user
*optval
, unsigned int optlen
)
1604 struct sock
*sk
= sock
->sk
;
1605 struct iucv_sock
*iucv
= iucv_sk(sk
);
1609 if (level
!= SOL_IUCV
)
1610 return -ENOPROTOOPT
;
1612 if (optlen
< sizeof(int))
1615 if (get_user(val
, (int __user
*) optval
))
1622 case SO_IPRMDATA_MSG
:
1624 iucv
->flags
|= IUCV_IPRMDATA
;
1626 iucv
->flags
&= ~IUCV_IPRMDATA
;
1629 switch (sk
->sk_state
) {
1632 if (val
< 1 || val
> (u16
)(~0))
1635 iucv
->msglimit
= val
;
1651 static int iucv_sock_getsockopt(struct socket
*sock
, int level
, int optname
,
1652 char __user
*optval
, int __user
*optlen
)
1654 struct sock
*sk
= sock
->sk
;
1655 struct iucv_sock
*iucv
= iucv_sk(sk
);
1659 if (level
!= SOL_IUCV
)
1660 return -ENOPROTOOPT
;
1662 if (get_user(len
, optlen
))
1668 len
= min_t(unsigned int, len
, sizeof(int));
1671 case SO_IPRMDATA_MSG
:
1672 val
= (iucv
->flags
& IUCV_IPRMDATA
) ? 1 : 0;
1676 val
= (iucv
->path
!= NULL
) ? iucv
->path
->msglim
/* connected */
1677 : iucv
->msglimit
; /* default */
1681 if (sk
->sk_state
== IUCV_OPEN
)
1683 val
= (iucv
->hs_dev
) ? iucv
->hs_dev
->mtu
-
1684 sizeof(struct af_iucv_trans_hdr
) - ETH_HLEN
:
1688 return -ENOPROTOOPT
;
1691 if (put_user(len
, optlen
))
1693 if (copy_to_user(optval
, &val
, len
))
1700 /* Callback wrappers - called from iucv base support */
1701 static int iucv_callback_connreq(struct iucv_path
*path
,
1702 u8 ipvmid
[8], u8 ipuser
[16])
1704 unsigned char user_data
[16];
1705 unsigned char nuser_data
[16];
1706 unsigned char src_name
[8];
1707 struct sock
*sk
, *nsk
;
1708 struct iucv_sock
*iucv
, *niucv
;
1711 memcpy(src_name
, ipuser
, 8);
1712 EBCASC(src_name
, 8);
1713 /* Find out if this path belongs to af_iucv. */
1714 read_lock(&iucv_sk_list
.lock
);
1717 sk_for_each(sk
, &iucv_sk_list
.head
)
1718 if (sk
->sk_state
== IUCV_LISTEN
&&
1719 !memcmp(&iucv_sk(sk
)->src_name
, src_name
, 8)) {
1721 * Found a listening socket with
1722 * src_name == ipuser[0-7].
1727 read_unlock(&iucv_sk_list
.lock
);
1729 /* No socket found, not one of our paths. */
1734 /* Check if parent socket is listening */
1735 low_nmcpy(user_data
, iucv
->src_name
);
1736 high_nmcpy(user_data
, iucv
->dst_name
);
1737 ASCEBC(user_data
, sizeof(user_data
));
1738 if (sk
->sk_state
!= IUCV_LISTEN
) {
1739 err
= pr_iucv
->path_sever(path
, user_data
);
1740 iucv_path_free(path
);
1744 /* Check for backlog size */
1745 if (sk_acceptq_is_full(sk
)) {
1746 err
= pr_iucv
->path_sever(path
, user_data
);
1747 iucv_path_free(path
);
1751 /* Create the new socket */
1752 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
, 0);
1754 err
= pr_iucv
->path_sever(path
, user_data
);
1755 iucv_path_free(path
);
1759 niucv
= iucv_sk(nsk
);
1760 iucv_sock_init(nsk
, sk
);
1762 /* Set the new iucv_sock */
1763 memcpy(niucv
->dst_name
, ipuser
+ 8, 8);
1764 EBCASC(niucv
->dst_name
, 8);
1765 memcpy(niucv
->dst_user_id
, ipvmid
, 8);
1766 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1767 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1770 /* Call iucv_accept */
1771 high_nmcpy(nuser_data
, ipuser
+ 8);
1772 memcpy(nuser_data
+ 8, niucv
->src_name
, 8);
1773 ASCEBC(nuser_data
+ 8, 8);
1775 /* set message limit for path based on msglimit of accepting socket */
1776 niucv
->msglimit
= iucv
->msglimit
;
1777 path
->msglim
= iucv
->msglimit
;
1778 err
= pr_iucv
->path_accept(path
, &af_iucv_handler
, nuser_data
, nsk
);
1780 iucv_sever_path(nsk
, 1);
1781 iucv_sock_kill(nsk
);
1785 iucv_accept_enqueue(sk
, nsk
);
1787 /* Wake up accept */
1788 nsk
->sk_state
= IUCV_CONNECTED
;
1789 sk
->sk_data_ready(sk
);
1796 static void iucv_callback_connack(struct iucv_path
*path
, u8 ipuser
[16])
1798 struct sock
*sk
= path
->private;
1800 sk
->sk_state
= IUCV_CONNECTED
;
1801 sk
->sk_state_change(sk
);
1804 static void iucv_callback_rx(struct iucv_path
*path
, struct iucv_message
*msg
)
1806 struct sock
*sk
= path
->private;
1807 struct iucv_sock
*iucv
= iucv_sk(sk
);
1808 struct sk_buff
*skb
;
1809 struct sock_msg_q
*save_msg
;
1812 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
1813 pr_iucv
->message_reject(path
, msg
);
1817 spin_lock(&iucv
->message_q
.lock
);
1819 if (!list_empty(&iucv
->message_q
.list
) ||
1820 !skb_queue_empty(&iucv
->backlog_skb_q
))
1823 len
= atomic_read(&sk
->sk_rmem_alloc
);
1824 len
+= SKB_TRUESIZE(iucv_msg_length(msg
));
1825 if (len
> sk
->sk_rcvbuf
)
1828 skb
= alloc_iucv_recv_skb(iucv_msg_length(msg
));
1832 iucv_process_message(sk
, skb
, path
, msg
);
1836 save_msg
= kzalloc(sizeof(struct sock_msg_q
), GFP_ATOMIC
| GFP_DMA
);
1839 save_msg
->path
= path
;
1840 save_msg
->msg
= *msg
;
1842 list_add_tail(&save_msg
->list
, &iucv
->message_q
.list
);
1845 spin_unlock(&iucv
->message_q
.lock
);
1848 static void iucv_callback_txdone(struct iucv_path
*path
,
1849 struct iucv_message
*msg
)
1851 struct sock
*sk
= path
->private;
1852 struct sk_buff
*this = NULL
;
1853 struct sk_buff_head
*list
= &iucv_sk(sk
)->send_skb_q
;
1854 struct sk_buff
*list_skb
= list
->next
;
1855 unsigned long flags
;
1858 if (!skb_queue_empty(list
)) {
1859 spin_lock_irqsave(&list
->lock
, flags
);
1861 while (list_skb
!= (struct sk_buff
*)list
) {
1862 if (msg
->tag
== IUCV_SKB_CB(list_skb
)->tag
) {
1866 list_skb
= list_skb
->next
;
1869 __skb_unlink(this, list
);
1871 spin_unlock_irqrestore(&list
->lock
, flags
);
1875 /* wake up any process waiting for sending */
1876 iucv_sock_wake_msglim(sk
);
1880 if (sk
->sk_state
== IUCV_CLOSING
) {
1881 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
1882 sk
->sk_state
= IUCV_CLOSED
;
1883 sk
->sk_state_change(sk
);
1890 static void iucv_callback_connrej(struct iucv_path
*path
, u8 ipuser
[16])
1892 struct sock
*sk
= path
->private;
1894 if (sk
->sk_state
== IUCV_CLOSED
)
1898 iucv_sever_path(sk
, 1);
1899 sk
->sk_state
= IUCV_DISCONN
;
1901 sk
->sk_state_change(sk
);
1905 /* called if the other communication side shuts down its RECV direction;
1906 * in turn, the callback sets SEND_SHUTDOWN to disable sending of data.
1908 static void iucv_callback_shutdown(struct iucv_path
*path
, u8 ipuser
[16])
1910 struct sock
*sk
= path
->private;
1913 if (sk
->sk_state
!= IUCV_CLOSED
) {
1914 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
1915 sk
->sk_state_change(sk
);
1920 /***************** HiperSockets transport callbacks ********************/
1921 static void afiucv_swap_src_dest(struct sk_buff
*skb
)
1923 struct af_iucv_trans_hdr
*trans_hdr
=
1924 (struct af_iucv_trans_hdr
*)skb
->data
;
1928 ASCEBC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
1929 ASCEBC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
1930 ASCEBC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
1931 ASCEBC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
1932 memcpy(tmpID
, trans_hdr
->srcUserID
, 8);
1933 memcpy(tmpName
, trans_hdr
->srcAppName
, 8);
1934 memcpy(trans_hdr
->srcUserID
, trans_hdr
->destUserID
, 8);
1935 memcpy(trans_hdr
->srcAppName
, trans_hdr
->destAppName
, 8);
1936 memcpy(trans_hdr
->destUserID
, tmpID
, 8);
1937 memcpy(trans_hdr
->destAppName
, tmpName
, 8);
1938 skb_push(skb
, ETH_HLEN
);
1939 memset(skb
->data
, 0, ETH_HLEN
);
1943 * afiucv_hs_callback_syn - react on received SYN
1945 static int afiucv_hs_callback_syn(struct sock
*sk
, struct sk_buff
*skb
)
1948 struct iucv_sock
*iucv
, *niucv
;
1949 struct af_iucv_trans_hdr
*trans_hdr
;
1953 trans_hdr
= (struct af_iucv_trans_hdr
*)skb
->data
;
1955 /* no sock - connection refused */
1956 afiucv_swap_src_dest(skb
);
1957 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
1958 err
= dev_queue_xmit(skb
);
1962 nsk
= iucv_sock_alloc(NULL
, sk
->sk_type
, GFP_ATOMIC
, 0);
1964 if ((sk
->sk_state
!= IUCV_LISTEN
) ||
1965 sk_acceptq_is_full(sk
) ||
1967 /* error on server socket - connection refused */
1968 afiucv_swap_src_dest(skb
);
1969 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
;
1970 err
= dev_queue_xmit(skb
);
1971 iucv_sock_kill(nsk
);
1976 niucv
= iucv_sk(nsk
);
1977 iucv_sock_init(nsk
, sk
);
1978 niucv
->transport
= AF_IUCV_TRANS_HIPER
;
1979 niucv
->msglimit
= iucv
->msglimit
;
1980 if (!trans_hdr
->window
)
1981 niucv
->msglimit_peer
= IUCV_HIPER_MSGLIM_DEFAULT
;
1983 niucv
->msglimit_peer
= trans_hdr
->window
;
1984 memcpy(niucv
->dst_name
, trans_hdr
->srcAppName
, 8);
1985 memcpy(niucv
->dst_user_id
, trans_hdr
->srcUserID
, 8);
1986 memcpy(niucv
->src_name
, iucv
->src_name
, 8);
1987 memcpy(niucv
->src_user_id
, iucv
->src_user_id
, 8);
1988 nsk
->sk_bound_dev_if
= sk
->sk_bound_dev_if
;
1989 niucv
->hs_dev
= iucv
->hs_dev
;
1990 dev_hold(niucv
->hs_dev
);
1991 afiucv_swap_src_dest(skb
);
1992 trans_hdr
->flags
= AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
;
1993 trans_hdr
->window
= niucv
->msglimit
;
1994 /* if receiver acks the xmit connection is established */
1995 err
= dev_queue_xmit(skb
);
1997 iucv_accept_enqueue(sk
, nsk
);
1998 nsk
->sk_state
= IUCV_CONNECTED
;
1999 sk
->sk_data_ready(sk
);
2001 iucv_sock_kill(nsk
);
2005 return NET_RX_SUCCESS
;
2009 * afiucv_hs_callback_synack() - react on received SYN-ACK
2011 static int afiucv_hs_callback_synack(struct sock
*sk
, struct sk_buff
*skb
)
2013 struct iucv_sock
*iucv
= iucv_sk(sk
);
2014 struct af_iucv_trans_hdr
*trans_hdr
=
2015 (struct af_iucv_trans_hdr
*)skb
->data
;
2019 if (sk
->sk_state
!= IUCV_BOUND
)
2022 iucv
->msglimit_peer
= trans_hdr
->window
;
2023 sk
->sk_state
= IUCV_CONNECTED
;
2024 sk
->sk_state_change(sk
);
2028 return NET_RX_SUCCESS
;
2032 * afiucv_hs_callback_synfin() - react on received SYN_FIN
2034 static int afiucv_hs_callback_synfin(struct sock
*sk
, struct sk_buff
*skb
)
2036 struct iucv_sock
*iucv
= iucv_sk(sk
);
2040 if (sk
->sk_state
!= IUCV_BOUND
)
2043 sk
->sk_state
= IUCV_DISCONN
;
2044 sk
->sk_state_change(sk
);
2048 return NET_RX_SUCCESS
;
2052 * afiucv_hs_callback_fin() - react on received FIN
2054 static int afiucv_hs_callback_fin(struct sock
*sk
, struct sk_buff
*skb
)
2056 struct iucv_sock
*iucv
= iucv_sk(sk
);
2058 /* other end of connection closed */
2062 if (sk
->sk_state
== IUCV_CONNECTED
) {
2063 sk
->sk_state
= IUCV_DISCONN
;
2064 sk
->sk_state_change(sk
);
2069 return NET_RX_SUCCESS
;
2073 * afiucv_hs_callback_win() - react on received WIN
2075 static int afiucv_hs_callback_win(struct sock
*sk
, struct sk_buff
*skb
)
2077 struct iucv_sock
*iucv
= iucv_sk(sk
);
2078 struct af_iucv_trans_hdr
*trans_hdr
=
2079 (struct af_iucv_trans_hdr
*)skb
->data
;
2082 return NET_RX_SUCCESS
;
2084 if (sk
->sk_state
!= IUCV_CONNECTED
)
2085 return NET_RX_SUCCESS
;
2087 atomic_sub(trans_hdr
->window
, &iucv
->msg_sent
);
2088 iucv_sock_wake_msglim(sk
);
2089 return NET_RX_SUCCESS
;
2093 * afiucv_hs_callback_rx() - react on received data
2095 static int afiucv_hs_callback_rx(struct sock
*sk
, struct sk_buff
*skb
)
2097 struct iucv_sock
*iucv
= iucv_sk(sk
);
2101 return NET_RX_SUCCESS
;
2104 if (sk
->sk_state
!= IUCV_CONNECTED
) {
2106 return NET_RX_SUCCESS
;
2109 if (sk
->sk_shutdown
& RCV_SHUTDOWN
) {
2111 return NET_RX_SUCCESS
;
2114 /* write stuff from iucv_msg to skb cb */
2115 skb_pull(skb
, sizeof(struct af_iucv_trans_hdr
));
2116 skb_reset_transport_header(skb
);
2117 skb_reset_network_header(skb
);
2118 IUCV_SKB_CB(skb
)->offset
= 0;
2119 spin_lock(&iucv
->message_q
.lock
);
2120 if (skb_queue_empty(&iucv
->backlog_skb_q
)) {
2121 if (sock_queue_rcv_skb(sk
, skb
)) {
2122 /* handle rcv queue full */
2123 skb_queue_tail(&iucv
->backlog_skb_q
, skb
);
2126 skb_queue_tail(&iucv_sk(sk
)->backlog_skb_q
, skb
);
2127 spin_unlock(&iucv
->message_q
.lock
);
2128 return NET_RX_SUCCESS
;
2132 * afiucv_hs_rcv() - base function for arriving data through HiperSockets
2134 * called from netif RX softirq
2136 static int afiucv_hs_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
2137 struct packet_type
*pt
, struct net_device
*orig_dev
)
2140 struct iucv_sock
*iucv
;
2141 struct af_iucv_trans_hdr
*trans_hdr
;
2145 if (skb
->len
< (ETH_HLEN
+ sizeof(struct af_iucv_trans_hdr
))) {
2146 WARN_ONCE(1, "AF_IUCV too short skb, len=%d, min=%d",
2148 (int)(ETH_HLEN
+ sizeof(struct af_iucv_trans_hdr
)));
2150 return NET_RX_SUCCESS
;
2152 if (skb_headlen(skb
) < (ETH_HLEN
+ sizeof(struct af_iucv_trans_hdr
)))
2153 if (skb_linearize(skb
)) {
2154 WARN_ONCE(1, "AF_IUCV skb_linearize failed, len=%d",
2157 return NET_RX_SUCCESS
;
2159 skb_pull(skb
, ETH_HLEN
);
2160 trans_hdr
= (struct af_iucv_trans_hdr
*)skb
->data
;
2161 EBCASC(trans_hdr
->destAppName
, sizeof(trans_hdr
->destAppName
));
2162 EBCASC(trans_hdr
->destUserID
, sizeof(trans_hdr
->destUserID
));
2163 EBCASC(trans_hdr
->srcAppName
, sizeof(trans_hdr
->srcAppName
));
2164 EBCASC(trans_hdr
->srcUserID
, sizeof(trans_hdr
->srcUserID
));
2165 memset(nullstring
, 0, sizeof(nullstring
));
2168 read_lock(&iucv_sk_list
.lock
);
2169 sk_for_each(sk
, &iucv_sk_list
.head
) {
2170 if (trans_hdr
->flags
== AF_IUCV_FLAG_SYN
) {
2171 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2172 trans_hdr
->destAppName
, 8)) &&
2173 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2174 trans_hdr
->destUserID
, 8)) &&
2175 (!memcmp(&iucv_sk(sk
)->dst_name
, nullstring
, 8)) &&
2176 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2182 if ((!memcmp(&iucv_sk(sk
)->src_name
,
2183 trans_hdr
->destAppName
, 8)) &&
2184 (!memcmp(&iucv_sk(sk
)->src_user_id
,
2185 trans_hdr
->destUserID
, 8)) &&
2186 (!memcmp(&iucv_sk(sk
)->dst_name
,
2187 trans_hdr
->srcAppName
, 8)) &&
2188 (!memcmp(&iucv_sk(sk
)->dst_user_id
,
2189 trans_hdr
->srcUserID
, 8))) {
2195 read_unlock(&iucv_sk_list
.lock
);
2200 how should we send with no sock
2201 1) send without sock no send rc checking?
2202 2) introduce default sock to handle this cases
2204 SYN -> send SYN|ACK in good case, send SYN|FIN in bad case
2206 SYN|ACK, SYN|FIN, FIN -> no action? */
2208 switch (trans_hdr
->flags
) {
2209 case AF_IUCV_FLAG_SYN
:
2210 /* connect request */
2211 err
= afiucv_hs_callback_syn(sk
, skb
);
2213 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_ACK
):
2214 /* connect request confirmed */
2215 err
= afiucv_hs_callback_synack(sk
, skb
);
2217 case (AF_IUCV_FLAG_SYN
| AF_IUCV_FLAG_FIN
):
2218 /* connect request refused */
2219 err
= afiucv_hs_callback_synfin(sk
, skb
);
2221 case (AF_IUCV_FLAG_FIN
):
2223 err
= afiucv_hs_callback_fin(sk
, skb
);
2225 case (AF_IUCV_FLAG_WIN
):
2226 err
= afiucv_hs_callback_win(sk
, skb
);
2227 if (skb
->len
== sizeof(struct af_iucv_trans_hdr
)) {
2231 /* fall through and receive non-zero length data */
2232 case (AF_IUCV_FLAG_SHT
):
2233 /* shutdown request */
2234 /* fall through and receive zero length data */
2236 /* plain data frame */
2237 IUCV_SKB_CB(skb
)->class = trans_hdr
->iucv_hdr
.class;
2238 err
= afiucv_hs_callback_rx(sk
, skb
);
2248 * afiucv_hs_callback_txnotify() - handle send notifcations from HiperSockets
2251 static void afiucv_hs_callback_txnotify(struct sk_buff
*skb
,
2252 enum iucv_tx_notify n
)
2254 struct sock
*isk
= skb
->sk
;
2255 struct sock
*sk
= NULL
;
2256 struct iucv_sock
*iucv
= NULL
;
2257 struct sk_buff_head
*list
;
2258 struct sk_buff
*list_skb
;
2259 struct sk_buff
*nskb
;
2260 unsigned long flags
;
2262 read_lock_irqsave(&iucv_sk_list
.lock
, flags
);
2263 sk_for_each(sk
, &iucv_sk_list
.head
)
2268 read_unlock_irqrestore(&iucv_sk_list
.lock
, flags
);
2270 if (!iucv
|| sock_flag(sk
, SOCK_ZAPPED
))
2273 list
= &iucv
->send_skb_q
;
2274 spin_lock_irqsave(&list
->lock
, flags
);
2275 if (skb_queue_empty(list
))
2277 list_skb
= list
->next
;
2278 nskb
= list_skb
->next
;
2279 while (list_skb
!= (struct sk_buff
*)list
) {
2280 if (skb_shinfo(list_skb
) == skb_shinfo(skb
)) {
2283 __skb_unlink(list_skb
, list
);
2284 kfree_skb(list_skb
);
2285 iucv_sock_wake_msglim(sk
);
2287 case TX_NOTIFY_PENDING
:
2288 atomic_inc(&iucv
->pendings
);
2290 case TX_NOTIFY_DELAYED_OK
:
2291 __skb_unlink(list_skb
, list
);
2292 atomic_dec(&iucv
->pendings
);
2293 if (atomic_read(&iucv
->pendings
) <= 0)
2294 iucv_sock_wake_msglim(sk
);
2295 kfree_skb(list_skb
);
2297 case TX_NOTIFY_UNREACHABLE
:
2298 case TX_NOTIFY_DELAYED_UNREACHABLE
:
2299 case TX_NOTIFY_TPQFULL
: /* not yet used */
2300 case TX_NOTIFY_GENERALERROR
:
2301 case TX_NOTIFY_DELAYED_GENERALERROR
:
2302 __skb_unlink(list_skb
, list
);
2303 kfree_skb(list_skb
);
2304 if (sk
->sk_state
== IUCV_CONNECTED
) {
2305 sk
->sk_state
= IUCV_DISCONN
;
2306 sk
->sk_state_change(sk
);
2316 spin_unlock_irqrestore(&list
->lock
, flags
);
2318 if (sk
->sk_state
== IUCV_CLOSING
) {
2319 if (skb_queue_empty(&iucv_sk(sk
)->send_skb_q
)) {
2320 sk
->sk_state
= IUCV_CLOSED
;
2321 sk
->sk_state_change(sk
);
2328 * afiucv_netdev_event: handle netdev notifier chain events
2330 static int afiucv_netdev_event(struct notifier_block
*this,
2331 unsigned long event
, void *ptr
)
2333 struct net_device
*event_dev
= netdev_notifier_info_to_dev(ptr
);
2335 struct iucv_sock
*iucv
;
2339 case NETDEV_GOING_DOWN
:
2340 sk_for_each(sk
, &iucv_sk_list
.head
) {
2342 if ((iucv
->hs_dev
== event_dev
) &&
2343 (sk
->sk_state
== IUCV_CONNECTED
)) {
2344 if (event
== NETDEV_GOING_DOWN
)
2345 iucv_send_ctrl(sk
, AF_IUCV_FLAG_FIN
);
2346 sk
->sk_state
= IUCV_DISCONN
;
2347 sk
->sk_state_change(sk
);
2352 case NETDEV_UNREGISTER
:
2359 static struct notifier_block afiucv_netdev_notifier
= {
2360 .notifier_call
= afiucv_netdev_event
,
2363 static const struct proto_ops iucv_sock_ops
= {
2365 .owner
= THIS_MODULE
,
2366 .release
= iucv_sock_release
,
2367 .bind
= iucv_sock_bind
,
2368 .connect
= iucv_sock_connect
,
2369 .listen
= iucv_sock_listen
,
2370 .accept
= iucv_sock_accept
,
2371 .getname
= iucv_sock_getname
,
2372 .sendmsg
= iucv_sock_sendmsg
,
2373 .recvmsg
= iucv_sock_recvmsg
,
2374 .poll
= iucv_sock_poll
,
2375 .ioctl
= sock_no_ioctl
,
2376 .mmap
= sock_no_mmap
,
2377 .socketpair
= sock_no_socketpair
,
2378 .shutdown
= iucv_sock_shutdown
,
2379 .setsockopt
= iucv_sock_setsockopt
,
2380 .getsockopt
= iucv_sock_getsockopt
,
2383 static const struct net_proto_family iucv_sock_family_ops
= {
2385 .owner
= THIS_MODULE
,
2386 .create
= iucv_sock_create
,
2389 static struct packet_type iucv_packet_type
= {
2390 .type
= cpu_to_be16(ETH_P_AF_IUCV
),
2391 .func
= afiucv_hs_rcv
,
2394 static int afiucv_iucv_init(void)
2398 err
= pr_iucv
->iucv_register(&af_iucv_handler
, 0);
2401 /* establish dummy device */
2402 af_iucv_driver
.bus
= pr_iucv
->bus
;
2403 err
= driver_register(&af_iucv_driver
);
2406 af_iucv_dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
2411 dev_set_name(af_iucv_dev
, "af_iucv");
2412 af_iucv_dev
->bus
= pr_iucv
->bus
;
2413 af_iucv_dev
->parent
= pr_iucv
->root
;
2414 af_iucv_dev
->release
= (void (*)(struct device
*))kfree
;
2415 af_iucv_dev
->driver
= &af_iucv_driver
;
2416 err
= device_register(af_iucv_dev
);
2422 driver_unregister(&af_iucv_driver
);
2424 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2429 static int __init
afiucv_init(void)
2433 if (MACHINE_IS_VM
) {
2434 cpcmd("QUERY USERID", iucv_userid
, sizeof(iucv_userid
), &err
);
2435 if (unlikely(err
)) {
2437 err
= -EPROTONOSUPPORT
;
2441 pr_iucv
= try_then_request_module(symbol_get(iucv_if
), "iucv");
2443 printk(KERN_WARNING
"iucv_if lookup failed\n");
2444 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2447 memset(&iucv_userid
, 0, sizeof(iucv_userid
));
2451 err
= proto_register(&iucv_proto
, 0);
2454 err
= sock_register(&iucv_sock_family_ops
);
2459 err
= afiucv_iucv_init();
2463 register_netdevice_notifier(&afiucv_netdev_notifier
);
2464 dev_add_pack(&iucv_packet_type
);
2468 sock_unregister(PF_IUCV
);
2470 proto_unregister(&iucv_proto
);
2473 symbol_put(iucv_if
);
2477 static void __exit
afiucv_exit(void)
2480 device_unregister(af_iucv_dev
);
2481 driver_unregister(&af_iucv_driver
);
2482 pr_iucv
->iucv_unregister(&af_iucv_handler
, 0);
2483 symbol_put(iucv_if
);
2485 unregister_netdevice_notifier(&afiucv_netdev_notifier
);
2486 dev_remove_pack(&iucv_packet_type
);
2487 sock_unregister(PF_IUCV
);
2488 proto_unregister(&iucv_proto
);
2491 module_init(afiucv_init
);
2492 module_exit(afiucv_exit
);
2494 MODULE_AUTHOR("Jennifer Hunt <jenhunt@us.ibm.com>");
2495 MODULE_DESCRIPTION("IUCV Sockets ver " VERSION
);
2496 MODULE_VERSION(VERSION
);
2497 MODULE_LICENSE("GPL");
2498 MODULE_ALIAS_NETPROTO(PF_IUCV
);