Lines Matching +full:packet +full:- +full:oriented

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2007-2013 VMware, Inc. All rights reserved.
10 * - There are two kinds of sockets: those created by user action (such as
13 * - There are two "global" tables, one for bound sockets (sockets that have
17 * within them. - Note, though, that the bound table contains an extra entry
26 * - Sockets created by user action will either be "client" sockets that
30 * - "Server" sockets are referred to as listener sockets throughout this
36 * bound to, we check if the source of the packet is from one that has an
37 * existing pending connection. If it does, we process the packet for the
46 * - It is possible that these pending sockets will never reach the connected
47 * state; in fact, we may never receive another packet after the connection
52 * up (sock_put() -> sk_free() -> our sk_destruct implementation). Note this
56 * - Lock ordering for pending or accept queue sockets is:
64 * - Sockets created by user action will be cleaned up when the user process
70 * - A socket's reference count is what ensures that the structure won't be
78 * - sk->sk_state uses the TCP state constants because they are widely used by
81 * TCP_CLOSE - unconnected
82 * TCP_SYN_SENT - connecting
83 * TCP_ESTABLISHED - connected
84 * TCP_CLOSING - disconnecting
85 * TCP_LISTEN - listening
137 /* Transport used for host->guest communication */
139 /* Transport used for guest->host communication */
159 * vsock_bind_table[VSOCK_HASH_SIZE - 1] are for bound sockets and
165 #define VSOCK_HASH(addr) ((addr)->svm_port % VSOCK_HASH_SIZE)
171 (((src)->svm_cid ^ (dst)->svm_port) % VSOCK_HASH_SIZE)
175 vsock_connected_sockets(&(vsk)->remote_addr, &(vsk)->local_addr)
190 if (vsock_addr_bound(&vsk->local_addr)) in vsock_auto_bind()
210 sock_hold(&vsk->sk); in __vsock_insert_bound()
211 list_add(&vsk->bound_table, list); in __vsock_insert_bound()
217 sock_hold(&vsk->sk); in __vsock_insert_connected()
218 list_add(&vsk->connected_table, list); in __vsock_insert_connected()
223 list_del_init(&vsk->bound_table); in __vsock_remove_bound()
224 sock_put(&vsk->sk); in __vsock_remove_bound()
229 list_del_init(&vsk->connected_table); in __vsock_remove_connected()
230 sock_put(&vsk->sk); in __vsock_remove_connected()
238 if (vsock_addr_equals_addr(addr, &vsk->local_addr)) in __vsock_find_bound_socket()
241 if (addr->svm_port == vsk->local_addr.svm_port && in __vsock_find_bound_socket()
242 (vsk->local_addr.svm_cid == VMADDR_CID_ANY || in __vsock_find_bound_socket()
243 addr->svm_cid == VMADDR_CID_ANY)) in __vsock_find_bound_socket()
257 if (vsock_addr_equals_addr(src, &vsk->remote_addr) && in __vsock_find_connected_socket()
258 dst->svm_port == vsk->local_addr.svm_port) { in __vsock_find_connected_socket()
276 &vsk->remote_addr, &vsk->local_addr); in vsock_insert_connected()
351 if (vsk->transport != transport) in vsock_for_each_connected_socket()
372 list_add_tail(&vpending->pending_links, &vlistener->pending_links); in vsock_add_pending()
380 list_del_init(&vpending->pending_links); in vsock_remove_pending()
396 list_add_tail(&vconnected->accept_queue, &vlistener->accept_queue); in vsock_enqueue_accept()
409 return remote_cid == transport_g2h->get_local_cid(); in vsock_use_local_transport()
417 if (!vsk->transport) in vsock_deassign_transport()
420 vsk->transport->destruct(vsk); in vsock_deassign_transport()
421 module_put(vsk->transport->module); in vsock_deassign_transport()
422 vsk->transport = NULL; in vsock_deassign_transport()
427 * Note: for connection oriented socket this must be called when vsk->remote_addr
430 * The vsk->remote_addr is used to decide which transport to use:
431 * - remote CID == VMADDR_CID_LOCAL or g2h->local_cid or VMADDR_CID_HOST if
433 * - remote CID <= VMADDR_CID_HOST or h2g is not loaded or remote flags field
434 * includes VMADDR_FLAG_TO_HOST flag value, will use guest->host transport;
435 * - remote CID > VMADDR_CID_HOST will use host->guest transport;
441 unsigned int remote_cid = vsk->remote_addr.svm_cid; in vsock_assign_transport()
445 /* If the packet is coming with the source and destination CIDs higher in vsock_assign_transport()
453 if (psk && vsk->local_addr.svm_cid > VMADDR_CID_HOST && in vsock_assign_transport()
454 vsk->remote_addr.svm_cid > VMADDR_CID_HOST) in vsock_assign_transport()
455 vsk->remote_addr.svm_flags |= VMADDR_FLAG_TO_HOST; in vsock_assign_transport()
457 remote_flags = vsk->remote_addr.svm_flags; in vsock_assign_transport()
459 switch (sk->sk_type) { in vsock_assign_transport()
474 return -ESOCKTNOSUPPORT; in vsock_assign_transport()
477 if (vsk->transport) { in vsock_assign_transport()
478 if (vsk->transport == new_transport) in vsock_assign_transport()
481 /* transport->release() must be called with sock lock acquired. in vsock_assign_transport()
487 vsk->transport->release(vsk); in vsock_assign_transport()
494 if (!new_transport || !try_module_get(new_transport->module)) in vsock_assign_transport()
495 return -ENODEV; in vsock_assign_transport()
497 if (sk->sk_type == SOCK_SEQPACKET) { in vsock_assign_transport()
498 if (!new_transport->seqpacket_allow || in vsock_assign_transport()
499 !new_transport->seqpacket_allow(remote_cid)) { in vsock_assign_transport()
500 module_put(new_transport->module); in vsock_assign_transport()
501 return -ESOCKTNOSUPPORT; in vsock_assign_transport()
505 ret = new_transport->init(vsk, psk); in vsock_assign_transport()
507 module_put(new_transport->module); in vsock_assign_transport()
511 vsk->transport = new_transport; in vsock_assign_transport()
519 if (transport_g2h && cid == transport_g2h->get_local_cid()) in vsock_find_cid()
539 if (list_empty(&vlistener->accept_queue)) in vsock_dequeue_accept()
542 vconnected = list_entry(vlistener->accept_queue.next, in vsock_dequeue_accept()
545 list_del_init(&vconnected->accept_queue); in vsock_dequeue_accept()
557 return list_empty(&vsk->accept_queue); in vsock_is_accept_queue_empty()
563 return !list_empty(&vsk->pending_links); in vsock_is_pending()
570 if (!vsk->transport) in vsock_send_shutdown()
571 return -ENODEV; in vsock_send_shutdown()
573 return vsk->transport->shutdown(vsk, mode); in vsock_send_shutdown()
585 listener = vsk->listener; in vsock_pending_work()
595 } else if (!vsk->rejected) { in vsock_pending_work()
611 sk->sk_state = TCP_CLOSE; in vsock_pending_work()
634 vsock_addr_init(&new_addr, addr->svm_cid, addr->svm_port); in __vsock_bind_connectible()
636 if (addr->svm_port == VMADDR_PORT_ANY) { in __vsock_bind_connectible()
653 return -EADDRNOTAVAIL; in __vsock_bind_connectible()
658 if (addr->svm_port <= LAST_RESERVED_PORT && in __vsock_bind_connectible()
660 return -EACCES; in __vsock_bind_connectible()
664 return -EADDRINUSE; in __vsock_bind_connectible()
667 vsock_addr_init(&vsk->local_addr, new_addr.svm_cid, new_addr.svm_port); in __vsock_bind_connectible()
669 /* Remove connection oriented sockets from the unbound list and add them in __vsock_bind_connectible()
675 __vsock_insert_bound(vsock_bound_sockets(&vsk->local_addr), vsk); in __vsock_bind_connectible()
683 return vsk->transport->dgram_bind(vsk, addr); in __vsock_bind_dgram()
692 if (vsock_addr_bound(&vsk->local_addr)) in __vsock_bind()
693 return -EINVAL; in __vsock_bind()
697 * like AF_INET prevents binding to a non-local IP address (in most in __vsock_bind()
700 if (addr->svm_cid != VMADDR_CID_ANY && !vsock_find_cid(addr->svm_cid)) in __vsock_bind()
701 return -EADDRNOTAVAIL; in __vsock_bind()
703 switch (sk->sk_socket->type) { in __vsock_bind()
716 retval = -EINVAL; in __vsock_bind()
742 /* sk->sk_type is normally set in sock_init_data, but only if sock is in __vsock_create()
743 * non-NULL. We make sure that our sockets always have a type by in __vsock_create()
747 sk->sk_type = type; in __vsock_create()
750 vsock_addr_init(&vsk->local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY); in __vsock_create()
751 vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY); in __vsock_create()
753 sk->sk_destruct = vsock_sk_destruct; in __vsock_create()
754 sk->sk_backlog_rcv = vsock_queue_rcv_skb; in __vsock_create()
757 INIT_LIST_HEAD(&vsk->bound_table); in __vsock_create()
758 INIT_LIST_HEAD(&vsk->connected_table); in __vsock_create()
759 vsk->listener = NULL; in __vsock_create()
760 INIT_LIST_HEAD(&vsk->pending_links); in __vsock_create()
761 INIT_LIST_HEAD(&vsk->accept_queue); in __vsock_create()
762 vsk->rejected = false; in __vsock_create()
763 vsk->sent_request = false; in __vsock_create()
764 vsk->ignore_connecting_rst = false; in __vsock_create()
765 vsk->peer_shutdown = 0; in __vsock_create()
766 INIT_DELAYED_WORK(&vsk->connect_work, vsock_connect_timeout); in __vsock_create()
767 INIT_DELAYED_WORK(&vsk->pending_work, vsock_pending_work); in __vsock_create()
771 vsk->trusted = psk->trusted; in __vsock_create()
772 vsk->owner = get_cred(psk->owner); in __vsock_create()
773 vsk->connect_timeout = psk->connect_timeout; in __vsock_create()
774 vsk->buffer_size = psk->buffer_size; in __vsock_create()
775 vsk->buffer_min_size = psk->buffer_min_size; in __vsock_create()
776 vsk->buffer_max_size = psk->buffer_max_size; in __vsock_create()
779 vsk->trusted = ns_capable_noaudit(&init_user_ns, CAP_NET_ADMIN); in __vsock_create()
780 vsk->owner = get_current_cred(); in __vsock_create()
781 vsk->connect_timeout = VSOCK_DEFAULT_CONNECT_TIMEOUT; in __vsock_create()
782 vsk->buffer_size = VSOCK_DEFAULT_BUFFER_SIZE; in __vsock_create()
783 vsk->buffer_min_size = VSOCK_DEFAULT_BUFFER_MIN_SIZE; in __vsock_create()
784 vsk->buffer_max_size = VSOCK_DEFAULT_BUFFER_MAX_SIZE; in __vsock_create()
811 if (vsk->transport) in __vsock_release()
812 vsk->transport->release(vsk); in __vsock_release()
813 else if (sock_type_connectible(sk->sk_type)) in __vsock_release()
817 sk->sk_shutdown = SHUTDOWN_MASK; in __vsock_release()
819 skb_queue_purge(&sk->sk_receive_queue); in __vsock_release()
841 vsock_addr_init(&vsk->local_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY); in vsock_sk_destruct()
842 vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, VMADDR_PORT_ANY); in vsock_sk_destruct()
844 put_cred(vsk->owner); in vsock_sk_destruct()
861 parent->sk_type, 0); in vsock_create_connected()
867 return vsk->transport->stream_has_data(vsk); in vsock_stream_has_data()
875 if (sk->sk_type == SOCK_SEQPACKET) in vsock_connectible_has_data()
876 return vsk->transport->seqpacket_has_data(vsk); in vsock_connectible_has_data()
884 return vsk->transport->stream_has_space(vsk); in vsock_stream_has_space()
892 if (vsock_stream_has_data(vsk) >= sk->sk_rcvlowat || in vsock_data_ready()
894 sk->sk_data_ready(sk); in vsock_data_ready()
900 __vsock_release(sock->sk, 0); in vsock_release()
901 sock->sk = NULL; in vsock_release()
902 sock->state = SS_FREE; in vsock_release()
914 sk = sock->sk; in vsock_bind()
917 return -EINVAL; in vsock_bind()
934 sk = sock->sk; in vsock_getname()
941 if (sock->state != SS_CONNECTED) { in vsock_getname()
942 err = -ENOTCONN; in vsock_getname()
945 vm_addr = &vsk->remote_addr; in vsock_getname()
947 vm_addr = &vsk->local_addr; in vsock_getname()
951 err = -EINVAL; in vsock_getname()
956 * MAX_SOCK_ADDR-sized buffer and don't set addr_len. Unfortunately in vsock_getname()
983 return -EINVAL; in vsock_shutdown()
985 /* If this is a connection oriented socket and it is not connected then in vsock_shutdown()
991 sk = sock->sk; in vsock_shutdown()
994 if (sock->state == SS_UNCONNECTED) { in vsock_shutdown()
995 err = -ENOTCONN; in vsock_shutdown()
996 if (sock_type_connectible(sk->sk_type)) in vsock_shutdown()
999 sock->state = SS_DISCONNECTING; in vsock_shutdown()
1006 sk->sk_shutdown |= mode; in vsock_shutdown()
1007 sk->sk_state_change(sk); in vsock_shutdown()
1009 if (sock_type_connectible(sk->sk_type)) { in vsock_shutdown()
1027 sk = sock->sk; in vsock_poll()
1033 if (sk->sk_err) in vsock_poll()
1040 if ((sk->sk_shutdown == SHUTDOWN_MASK) || in vsock_poll()
1041 ((sk->sk_shutdown & SEND_SHUTDOWN) && in vsock_poll()
1042 (vsk->peer_shutdown & SEND_SHUTDOWN))) { in vsock_poll()
1046 if (sk->sk_shutdown & RCV_SHUTDOWN || in vsock_poll()
1047 vsk->peer_shutdown & SEND_SHUTDOWN) { in vsock_poll()
1051 if (sock->type == SOCK_DGRAM) { in vsock_poll()
1056 if (!skb_queue_empty_lockless(&sk->sk_receive_queue) || in vsock_poll()
1057 (sk->sk_shutdown & RCV_SHUTDOWN)) { in vsock_poll()
1061 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) in vsock_poll()
1064 } else if (sock_type_connectible(sk->sk_type)) { in vsock_poll()
1069 transport = vsk->transport; in vsock_poll()
1074 if (sk->sk_state == TCP_LISTEN in vsock_poll()
1079 if (transport && transport->stream_is_active(vsk) && in vsock_poll()
1080 !(sk->sk_shutdown & RCV_SHUTDOWN)) { in vsock_poll()
1083 int ret = transport->notify_poll_in( in vsock_poll()
1098 if (sk->sk_shutdown & RCV_SHUTDOWN || in vsock_poll()
1099 vsk->peer_shutdown & SEND_SHUTDOWN) { in vsock_poll()
1104 if (transport && sk->sk_state == TCP_ESTABLISHED) { in vsock_poll()
1105 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { in vsock_poll()
1107 int ret = transport->notify_poll_out( in vsock_poll()
1126 if (sk->sk_state == TCP_CLOSE || sk->sk_state == TCP_CLOSING) { in vsock_poll()
1127 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) in vsock_poll()
1142 return vsk->transport->read_skb(vsk, read_actor); in vsock_read_skb()
1154 if (msg->msg_flags & MSG_OOB) in vsock_dgram_sendmsg()
1155 return -EOPNOTSUPP; in vsock_dgram_sendmsg()
1159 sk = sock->sk; in vsock_dgram_sendmsg()
1164 transport = vsk->transport; in vsock_dgram_sendmsg()
1174 if (msg->msg_name && in vsock_dgram_sendmsg()
1175 vsock_addr_cast(msg->msg_name, msg->msg_namelen, in vsock_dgram_sendmsg()
1181 if (remote_addr->svm_cid == VMADDR_CID_ANY) in vsock_dgram_sendmsg()
1182 remote_addr->svm_cid = transport->get_local_cid(); in vsock_dgram_sendmsg()
1185 err = -EINVAL; in vsock_dgram_sendmsg()
1188 } else if (sock->state == SS_CONNECTED) { in vsock_dgram_sendmsg()
1189 remote_addr = &vsk->remote_addr; in vsock_dgram_sendmsg()
1191 if (remote_addr->svm_cid == VMADDR_CID_ANY) in vsock_dgram_sendmsg()
1192 remote_addr->svm_cid = transport->get_local_cid(); in vsock_dgram_sendmsg()
1197 if (!vsock_addr_bound(&vsk->remote_addr)) { in vsock_dgram_sendmsg()
1198 err = -EINVAL; in vsock_dgram_sendmsg()
1202 err = -EINVAL; in vsock_dgram_sendmsg()
1206 if (!transport->dgram_allow(remote_addr->svm_cid, in vsock_dgram_sendmsg()
1207 remote_addr->svm_port)) { in vsock_dgram_sendmsg()
1208 err = -EINVAL; in vsock_dgram_sendmsg()
1212 err = transport->dgram_enqueue(vsk, remote_addr, msg, len); in vsock_dgram_sendmsg()
1227 sk = sock->sk; in vsock_dgram_connect()
1231 if (err == -EAFNOSUPPORT && remote_addr->svm_family == AF_UNSPEC) { in vsock_dgram_connect()
1233 vsock_addr_init(&vsk->remote_addr, VMADDR_CID_ANY, in vsock_dgram_connect()
1235 sock->state = SS_UNCONNECTED; in vsock_dgram_connect()
1239 return -EINVAL; in vsock_dgram_connect()
1247 if (!vsk->transport->dgram_allow(remote_addr->svm_cid, in vsock_dgram_connect()
1248 remote_addr->svm_port)) { in vsock_dgram_connect()
1249 err = -EINVAL; in vsock_dgram_connect()
1253 memcpy(&vsk->remote_addr, remote_addr, sizeof(vsk->remote_addr)); in vsock_dgram_connect()
1254 sock->state = SS_CONNECTED; in vsock_dgram_connect()
1256 /* sock map disallows redirection of non-TCP sockets with sk_state != in vsock_dgram_connect()
1264 sk->sk_state = TCP_ESTABLISHED; in vsock_dgram_connect()
1280 sk = sock->sk; in vsock_dgram_recvmsg()
1284 prot = READ_ONCE(sk->sk_prot); in vsock_dgram_recvmsg()
1286 return prot->recvmsg(sk, msg, len, flags, NULL); in vsock_dgram_recvmsg()
1289 return vsk->transport->dgram_dequeue(vsk, msg, len, flags); in vsock_dgram_recvmsg()
1314 const struct vsock_transport *transport = vsk->transport; in vsock_transport_cancel_pkt()
1316 if (!transport || !transport->cancel_pkt) in vsock_transport_cancel_pkt()
1317 return -EOPNOTSUPP; in vsock_transport_cancel_pkt()
1319 return transport->cancel_pkt(vsk); in vsock_transport_cancel_pkt()
1331 if (sk->sk_state == TCP_SYN_SENT && in vsock_connect_timeout()
1332 (sk->sk_shutdown != SHUTDOWN_MASK)) { in vsock_connect_timeout()
1333 sk->sk_state = TCP_CLOSE; in vsock_connect_timeout()
1334 sk->sk_socket->state = SS_UNCONNECTED; in vsock_connect_timeout()
1335 sk->sk_err = ETIMEDOUT; in vsock_connect_timeout()
1356 sk = sock->sk; in vsock_connect()
1362 switch (sock->state) { in vsock_connect()
1364 err = -EISCONN; in vsock_connect()
1367 err = -EINVAL; in vsock_connect()
1373 * for the connection or return -EALREADY should this be a in vsock_connect()
1374 * non-blocking call. in vsock_connect()
1376 err = -EALREADY; in vsock_connect()
1381 if ((sk->sk_state == TCP_LISTEN) || in vsock_connect()
1383 err = -EINVAL; in vsock_connect()
1388 memcpy(&vsk->remote_addr, remote_addr, in vsock_connect()
1389 sizeof(vsk->remote_addr)); in vsock_connect()
1395 transport = vsk->transport; in vsock_connect()
1397 /* The hypervisor and well-known contexts do not have socket in vsock_connect()
1401 !transport->stream_allow(remote_addr->svm_cid, in vsock_connect()
1402 remote_addr->svm_port)) { in vsock_connect()
1403 err = -ENETUNREACH; in vsock_connect()
1411 sk->sk_state = TCP_SYN_SENT; in vsock_connect()
1413 err = transport->connect(vsk); in vsock_connect()
1418 * progress in case this is a non-blocking connect. in vsock_connect()
1420 sock->state = SS_CONNECTING; in vsock_connect()
1421 err = -EINPROGRESS; in vsock_connect()
1428 timeout = vsk->connect_timeout; in vsock_connect()
1431 while (sk->sk_state != TCP_ESTABLISHED && sk->sk_err == 0) { in vsock_connect()
1445 if (mod_delayed_work(system_wq, &vsk->connect_work, in vsock_connect()
1459 sk->sk_state = sk->sk_state == TCP_ESTABLISHED ? TCP_CLOSING : TCP_CLOSE; in vsock_connect()
1460 sock->state = SS_UNCONNECTED; in vsock_connect()
1464 } else if ((sk->sk_state != TCP_ESTABLISHED) && (timeout == 0)) { in vsock_connect()
1465 err = -ETIMEDOUT; in vsock_connect()
1466 sk->sk_state = TCP_CLOSE; in vsock_connect()
1467 sock->state = SS_UNCONNECTED; in vsock_connect()
1475 if (sk->sk_err) { in vsock_connect()
1476 err = -sk->sk_err; in vsock_connect()
1477 sk->sk_state = TCP_CLOSE; in vsock_connect()
1478 sock->state = SS_UNCONNECTED; in vsock_connect()
1501 listener = sock->sk; in vsock_accept()
1505 if (!sock_type_connectible(sock->type)) { in vsock_accept()
1506 err = -EOPNOTSUPP; in vsock_accept()
1510 if (listener->sk_state != TCP_LISTEN) { in vsock_accept()
1511 err = -EINVAL; in vsock_accept()
1522 listener->sk_err == 0) { in vsock_accept()
1532 err = -EAGAIN; in vsock_accept()
1540 if (listener->sk_err) in vsock_accept()
1541 err = -listener->sk_err; in vsock_accept()
1557 vconnected->rejected = true; in vsock_accept()
1559 newsock->state = SS_CONNECTED; in vsock_accept()
1578 sk = sock->sk; in vsock_listen()
1582 if (!sock_type_connectible(sk->sk_type)) { in vsock_listen()
1583 err = -EOPNOTSUPP; in vsock_listen()
1587 if (sock->state != SS_UNCONNECTED) { in vsock_listen()
1588 err = -EINVAL; in vsock_listen()
1594 if (!vsock_addr_bound(&vsk->local_addr)) { in vsock_listen()
1595 err = -EINVAL; in vsock_listen()
1599 sk->sk_max_ack_backlog = backlog; in vsock_listen()
1600 sk->sk_state = TCP_LISTEN; in vsock_listen()
1613 if (val > vsk->buffer_max_size) in vsock_update_buffer_size()
1614 val = vsk->buffer_max_size; in vsock_update_buffer_size()
1616 if (val < vsk->buffer_min_size) in vsock_update_buffer_size()
1617 val = vsk->buffer_min_size; in vsock_update_buffer_size()
1619 if (val != vsk->buffer_size && in vsock_update_buffer_size()
1620 transport && transport->notify_buffer_size) in vsock_update_buffer_size()
1621 transport->notify_buffer_size(vsk, &val); in vsock_update_buffer_size()
1623 vsk->buffer_size = val; in vsock_update_buffer_size()
1639 return -ENOPROTOOPT; in vsock_connectible_setsockopt()
1644 err = -EINVAL; \ in vsock_connectible_setsockopt()
1648 err = -EFAULT; \ in vsock_connectible_setsockopt()
1654 sk = sock->sk; in vsock_connectible_setsockopt()
1659 transport = vsk->transport; in vsock_connectible_setsockopt()
1669 vsk->buffer_max_size = val; in vsock_connectible_setsockopt()
1670 vsock_update_buffer_size(vsk, transport, vsk->buffer_size); in vsock_connectible_setsockopt()
1675 vsk->buffer_min_size = val; in vsock_connectible_setsockopt()
1676 vsock_update_buffer_size(vsk, transport, vsk->buffer_size); in vsock_connectible_setsockopt()
1688 tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) { in vsock_connectible_setsockopt()
1689 vsk->connect_timeout = tv.tv_sec * HZ + in vsock_connectible_setsockopt()
1691 if (vsk->connect_timeout == 0) in vsock_connectible_setsockopt()
1692 vsk->connect_timeout = in vsock_connectible_setsockopt()
1696 err = -ERANGE; in vsock_connectible_setsockopt()
1702 err = -ENOPROTOOPT; in vsock_connectible_setsockopt()
1718 struct sock *sk = sock->sk; in vsock_connectible_getsockopt()
1732 return -ENOPROTOOPT; in vsock_connectible_getsockopt()
1735 return -EFAULT; in vsock_connectible_getsockopt()
1741 v.val64 = vsk->buffer_size; in vsock_connectible_getsockopt()
1745 v.val64 = vsk->buffer_max_size; in vsock_connectible_getsockopt()
1749 v.val64 = vsk->buffer_min_size; in vsock_connectible_getsockopt()
1754 lv = sock_get_timeout(vsk->connect_timeout, &v, in vsock_connectible_getsockopt()
1759 return -ENOPROTOOPT; in vsock_connectible_getsockopt()
1763 return -EINVAL; in vsock_connectible_getsockopt()
1767 return -EFAULT; in vsock_connectible_getsockopt()
1770 return -EFAULT; in vsock_connectible_getsockopt()
1787 sk = sock->sk; in vsock_connectible_sendmsg()
1792 if (msg->msg_flags & MSG_OOB) in vsock_connectible_sendmsg()
1793 return -EOPNOTSUPP; in vsock_connectible_sendmsg()
1797 transport = vsk->transport; in vsock_connectible_sendmsg()
1799 /* Callers should not provide a destination with connection oriented in vsock_connectible_sendmsg()
1802 if (msg->msg_namelen) { in vsock_connectible_sendmsg()
1803 err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP; in vsock_connectible_sendmsg()
1808 if (sk->sk_shutdown & SEND_SHUTDOWN || in vsock_connectible_sendmsg()
1809 vsk->peer_shutdown & RCV_SHUTDOWN) { in vsock_connectible_sendmsg()
1810 err = -EPIPE; in vsock_connectible_sendmsg()
1814 if (!transport || sk->sk_state != TCP_ESTABLISHED || in vsock_connectible_sendmsg()
1815 !vsock_addr_bound(&vsk->local_addr)) { in vsock_connectible_sendmsg()
1816 err = -ENOTCONN; in vsock_connectible_sendmsg()
1820 if (!vsock_addr_bound(&vsk->remote_addr)) { in vsock_connectible_sendmsg()
1821 err = -EDESTADDRREQ; in vsock_connectible_sendmsg()
1826 timeout = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); in vsock_connectible_sendmsg()
1828 err = transport->notify_send_init(vsk, &send_data); in vsock_connectible_sendmsg()
1837 sk->sk_err == 0 && in vsock_connectible_sendmsg()
1838 !(sk->sk_shutdown & SEND_SHUTDOWN) && in vsock_connectible_sendmsg()
1839 !(vsk->peer_shutdown & RCV_SHUTDOWN)) { in vsock_connectible_sendmsg()
1841 /* Don't wait for non-blocking sockets. */ in vsock_connectible_sendmsg()
1843 err = -EAGAIN; in vsock_connectible_sendmsg()
1848 err = transport->notify_send_pre_block(vsk, &send_data); in vsock_connectible_sendmsg()
1862 err = -EAGAIN; in vsock_connectible_sendmsg()
1873 if (sk->sk_err) { in vsock_connectible_sendmsg()
1874 err = -sk->sk_err; in vsock_connectible_sendmsg()
1876 } else if ((sk->sk_shutdown & SEND_SHUTDOWN) || in vsock_connectible_sendmsg()
1877 (vsk->peer_shutdown & RCV_SHUTDOWN)) { in vsock_connectible_sendmsg()
1878 err = -EPIPE; in vsock_connectible_sendmsg()
1882 err = transport->notify_send_pre_enqueue(vsk, &send_data); in vsock_connectible_sendmsg()
1892 if (sk->sk_type == SOCK_SEQPACKET) { in vsock_connectible_sendmsg()
1893 written = transport->seqpacket_enqueue(vsk, in vsock_connectible_sendmsg()
1894 msg, len - total_written); in vsock_connectible_sendmsg()
1896 written = transport->stream_enqueue(vsk, in vsock_connectible_sendmsg()
1897 msg, len - total_written); in vsock_connectible_sendmsg()
1907 err = transport->notify_send_post_enqueue( in vsock_connectible_sendmsg()
1920 if (sk->sk_type == SOCK_STREAM || total_written == len) in vsock_connectible_sendmsg()
1941 transport = vsk->transport; in vsock_connectible_wait_data()
1949 if (sk->sk_err != 0 || in vsock_connectible_wait_data()
1950 (sk->sk_shutdown & RCV_SHUTDOWN) || in vsock_connectible_wait_data()
1951 (vsk->peer_shutdown & SEND_SHUTDOWN)) { in vsock_connectible_wait_data()
1955 /* Don't wait for non-blocking sockets. */ in vsock_connectible_wait_data()
1957 err = -EAGAIN; in vsock_connectible_wait_data()
1962 err = transport->notify_recv_pre_block(vsk, target, recv_data); in vsock_connectible_wait_data()
1975 err = -EAGAIN; in vsock_connectible_wait_data()
1990 return -ENOMEM; in vsock_connectible_wait_data()
2009 transport = vsk->transport; in __vsock_stream_recvmsg()
2018 if (target >= transport->stream_rcvhiwat(vsk)) { in __vsock_stream_recvmsg()
2019 err = -ENOMEM; in __vsock_stream_recvmsg()
2025 err = transport->notify_recv_init(vsk, target, &recv_data); in __vsock_stream_recvmsg()
2038 err = transport->notify_recv_pre_dequeue(vsk, target, in __vsock_stream_recvmsg()
2043 read = transport->stream_dequeue(vsk, msg, len - copied, flags); in __vsock_stream_recvmsg()
2051 err = transport->notify_recv_post_dequeue(vsk, target, read, in __vsock_stream_recvmsg()
2059 target -= read; in __vsock_stream_recvmsg()
2062 if (sk->sk_err) in __vsock_stream_recvmsg()
2063 err = -sk->sk_err; in __vsock_stream_recvmsg()
2064 else if (sk->sk_shutdown & RCV_SHUTDOWN) in __vsock_stream_recvmsg()
2085 transport = vsk->transport; in __vsock_seqpacket_recvmsg()
2093 msg_len = transport->seqpacket_dequeue(vsk, msg, flags); in __vsock_seqpacket_recvmsg()
2100 if (sk->sk_err) { in __vsock_seqpacket_recvmsg()
2101 err = -sk->sk_err; in __vsock_seqpacket_recvmsg()
2102 } else if (sk->sk_shutdown & RCV_SHUTDOWN) { in __vsock_seqpacket_recvmsg()
2106 * packet. in __vsock_seqpacket_recvmsg()
2111 err = len - msg_data_left(msg); in __vsock_seqpacket_recvmsg()
2113 /* Always set MSG_TRUNC if real length of packet is in __vsock_seqpacket_recvmsg()
2117 msg->msg_flags |= MSG_TRUNC; in __vsock_seqpacket_recvmsg()
2136 sk = sock->sk; in vsock_connectible_recvmsg()
2142 transport = vsk->transport; in vsock_connectible_recvmsg()
2144 if (!transport || sk->sk_state != TCP_ESTABLISHED) { in vsock_connectible_recvmsg()
2153 err = -ENOTCONN; in vsock_connectible_recvmsg()
2159 err = -EOPNOTSUPP; in vsock_connectible_recvmsg()
2167 if (sk->sk_shutdown & RCV_SHUTDOWN) { in vsock_connectible_recvmsg()
2172 /* It is valid on Linux to pass in a zero-length receive buffer. This in vsock_connectible_recvmsg()
2181 prot = READ_ONCE(sk->sk_prot); in vsock_connectible_recvmsg()
2184 return prot->recvmsg(sk, msg, len, flags, NULL); in vsock_connectible_recvmsg()
2188 if (sk->sk_type == SOCK_STREAM) in vsock_connectible_recvmsg()
2206 if (val > vsk->buffer_size) in vsock_set_rcvlowat()
2207 return -EINVAL; in vsock_set_rcvlowat()
2209 transport = vsk->transport; in vsock_set_rcvlowat()
2211 if (transport && transport->set_rcvlowat) in vsock_set_rcvlowat()
2212 return transport->set_rcvlowat(vsk, val); in vsock_set_rcvlowat()
2214 WRITE_ONCE(sk->sk_rcvlowat, val ? : 1); in vsock_set_rcvlowat()
2269 return -EINVAL; in vsock_create()
2272 return -EPROTONOSUPPORT; in vsock_create()
2274 switch (sock->type) { in vsock_create()
2276 sock->ops = &vsock_dgram_ops; in vsock_create()
2279 sock->ops = &vsock_stream_ops; in vsock_create()
2282 sock->ops = &vsock_seqpacket_ops; in vsock_create()
2285 return -ESOCKTNOSUPPORT; in vsock_create()
2288 sock->state = SS_UNCONNECTED; in vsock_create()
2292 return -ENOMEM; in vsock_create()
2296 if (sock->type == SOCK_DGRAM) { in vsock_create()
2325 * guest CID instead of well-know host CID (VMADDR_CID_HOST). in vsock_dev_do_ioctl()
2328 cid = transport_g2h->get_local_cid(); in vsock_dev_do_ioctl()
2330 cid = transport_h2g->get_local_cid(); in vsock_dev_do_ioctl()
2333 retval = -EFAULT; in vsock_dev_do_ioctl()
2337 retval = -ENOIOCTLCMD; in vsock_dev_do_ioctl()
2419 return vsk->transport; in vsock_core_get_transport()
2438 err = -EBUSY; in vsock_core_register()
2446 err = -EBUSY; in vsock_core_register()
2454 err = -EBUSY; in vsock_core_register()
2462 err = -EBUSY; in vsock_core_register()
2504 MODULE_VERSION("1.0.2.0-k");