blob: 7f7cf25c2023809c5404a4358f755964d59087a5 [file] [log] [blame]
Alice Wangd158e392023-08-30 12:51:12 +00001// Copyright 2023, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Vsock setup shared between the host and the service VM.
16
Alice Wang1d9a5872023-09-06 14:32:36 +000017const PROTECTED_VM_PORT: u32 = 5679;
18const NON_PROTECTED_VM_PORT: u32 = 5680;
Alice Wangd158e392023-08-30 12:51:12 +000019
Alice Wang1d9a5872023-09-06 14:32:36 +000020/// VM Type.
Alice Wangd3a96402023-11-24 15:37:39 +000021#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Alice Wang1d9a5872023-09-06 14:32:36 +000022pub enum VmType {
23 /// Protected VM.
24 ProtectedVm,
25
26 /// NonProtectev VM.
27 NonProtectedVm,
28}
29
30impl VmType {
31 /// Returns the port number used for the vsock communication between
32 /// the host and the service VM.
33 pub fn port(&self) -> u32 {
34 match self {
35 Self::ProtectedVm => PROTECTED_VM_PORT,
36 Self::NonProtectedVm => NON_PROTECTED_VM_PORT,
37 }
38 }
39
40 /// Returns whether it is a protected VM.
41 pub fn is_protected(&self) -> bool {
42 match self {
43 Self::ProtectedVm => true,
44 Self::NonProtectedVm => false,
45 }
Alice Wangd158e392023-08-30 12:51:12 +000046 }
47}