1 // Copyright 2022 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use data_model::Le16; 6 use data_model::Le32; 7 use data_model::Le64; 8 use zerocopy::AsBytes; 9 use zerocopy::FromBytes; 10 use zerocopy::FromZeroes; 11 12 pub const TYPE_STREAM_SOCKET: u16 = 1; 13 14 /// virtio_vsock_config is the vsock device configuration space defined by the virtio spec. 15 #[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)] 16 #[repr(C)] 17 pub struct virtio_vsock_config { 18 pub guest_cid: Le64, 19 } 20 21 /// The message header for data packets sent on the tx/rx queues 22 #[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)] 23 #[repr(C, packed)] 24 #[allow(non_camel_case_types)] 25 pub struct virtio_vsock_hdr { 26 pub src_cid: Le64, 27 pub dst_cid: Le64, 28 pub src_port: Le32, 29 pub dst_port: Le32, 30 pub len: Le32, 31 pub r#type: Le16, 32 pub op: Le16, 33 pub flags: Le32, 34 pub buf_alloc: Le32, 35 pub fwd_cnt: Le32, 36 } 37 38 /// An event sent to the event queue 39 #[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)] 40 #[repr(C)] 41 pub struct virtio_vsock_event { 42 // ID from the virtio_vsock_event_id struct in the virtio spec 43 pub id: Le32, 44 } 45 46 pub mod vsock_op { 47 pub const VIRTIO_VSOCK_OP_INVALID: u16 = 0; 48 49 /* Connect operations */ 50 pub const VIRTIO_VSOCK_OP_REQUEST: u16 = 1; 51 pub const VIRTIO_VSOCK_OP_RESPONSE: u16 = 2; 52 pub const VIRTIO_VSOCK_OP_RST: u16 = 3; 53 pub const VIRTIO_VSOCK_OP_SHUTDOWN: u16 = 4; 54 55 /* To send payload */ 56 pub const VIRTIO_VSOCK_OP_RW: u16 = 5; 57 58 /* Tell the peer our credit info */ 59 pub const VIRTIO_VSOCK_OP_CREDIT_UPDATE: u16 = 6; 60 /* Request the peer to send the credit info to us */ 61 pub const VIRTIO_VSOCK_OP_CREDIT_REQUEST: u16 = 7; 62 } 63