mirror of
https://github.com/cirruslabs/softnet.git
synced 2026-10-18 22:50:16 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a92c290be | ||
|
|
f5a1b1cdbd | ||
|
|
817dbb6e32 | ||
|
|
5f3b371e93 |
+7
-5
@@ -4,17 +4,18 @@ env:
|
|||||||
task:
|
task:
|
||||||
name: Build
|
name: Build
|
||||||
macos_instance:
|
macos_instance:
|
||||||
image: ghcr.io/cirruslabs/macos-monterey-xcode:14
|
image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest
|
||||||
install_rust_script:
|
install_rust_script:
|
||||||
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||||
|
- rustup target add x86_64-apple-darwin
|
||||||
build_script:
|
build_script:
|
||||||
- cargo build
|
- cargo build --target aarch64-apple-darwin --target x86_64-apple-darwin
|
||||||
|
|
||||||
task:
|
task:
|
||||||
name: Release
|
name: Release
|
||||||
only_if: $CIRRUS_TAG != ''
|
only_if: $CIRRUS_TAG != ''
|
||||||
macos_instance:
|
macos_instance:
|
||||||
image: ghcr.io/cirruslabs/macos-monterey-xcode:14
|
image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ENCRYPTED[!98ace8259c6024da912c14d5a3c5c6aac186890a8d4819fad78f3e0c41a4e0cd3a2537dd6e91493952fb056fa434be7c!]
|
GITHUB_TOKEN: ENCRYPTED[!98ace8259c6024da912c14d5a3c5c6aac186890a8d4819fad78f3e0c41a4e0cd3a2537dd6e91493952fb056fa434be7c!]
|
||||||
GORELEASER_KEY: ENCRYPTED[!9b80b6ef684ceaf40edd4c7af93014ee156c8aba7e6e5795f41c482729887b5c31f36b651491d790f1f668670888d9fd!]
|
GORELEASER_KEY: ENCRYPTED[!9b80b6ef684ceaf40edd4c7af93014ee156c8aba7e6e5795f41c482729887b5c31f36b651491d790f1f668670888d9fd!]
|
||||||
@@ -23,13 +24,14 @@ task:
|
|||||||
SENTRY_AUTH_TOKEN: ENCRYPTED[!c16a5cf7da5f856b4bc2f21fe8cb7aa2a6c981f851c094ed4d3025fd02ea59a58a86cee8b193a69a1fc20fa217e56ac3!]
|
SENTRY_AUTH_TOKEN: ENCRYPTED[!c16a5cf7da5f856b4bc2f21fe8cb7aa2a6c981f851c094ed4d3025fd02ea59a58a86cee8b193a69a1fc20fa217e56ac3!]
|
||||||
install_rust_script:
|
install_rust_script:
|
||||||
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||||
|
- rustup target add x86_64-apple-darwin
|
||||||
install_script:
|
install_script:
|
||||||
- brew install go goreleaser/tap/goreleaser-pro getsentry/tools/sentry-cli
|
- brew install go goreleaser/tap/goreleaser-pro getsentry/tools/sentry-cli
|
||||||
build_script:
|
build_script:
|
||||||
- cargo build --profile release-with-debug
|
- cargo build --target aarch64-apple-darwin --target x86_64-apple-darwin --profile release-with-debug
|
||||||
release_script: goreleaser
|
release_script: goreleaser
|
||||||
upload_sentry_debug_files_script:
|
upload_sentry_debug_files_script:
|
||||||
- cd target/release-with-debug/
|
- cd target/aarch64-apple-darwin/release-with-debug/
|
||||||
# Generate and upload symbols
|
# Generate and upload symbols
|
||||||
- dsymutil softnet
|
- dsymutil softnet
|
||||||
- sentry-cli debug-files upload -o $SENTRY_ORG -p $SENTRY_PROJECT softnet.dSYM/
|
- sentry-cli debug-files upload -o $SENTRY_ORG -p $SENTRY_PROJECT softnet.dSYM/
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
/.idea
|
||||||
|
/dist
|
||||||
/target
|
/target
|
||||||
|
|||||||
+7
-9
@@ -1,29 +1,27 @@
|
|||||||
project_name: softnet
|
project_name: softnet
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
- builder: prebuilt
|
- id: softnet
|
||||||
|
builder: prebuilt
|
||||||
|
goamd64: [v1]
|
||||||
goos:
|
goos:
|
||||||
- darwin
|
- darwin
|
||||||
goarch:
|
goarch:
|
||||||
- arm64
|
- arm64
|
||||||
|
- amd64
|
||||||
prebuilt:
|
prebuilt:
|
||||||
path: "target/release-with-debug/softnet"
|
path: 'target/{{- if eq .Arch "arm64" }}aarch64{{- else }}x86_64{{ end }}-apple-darwin/release-with-debug/softnet'
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- id: binary
|
|
||||||
format: binary
|
|
||||||
name_template: "{{ .ProjectName }}"
|
|
||||||
- id: regular
|
- id: regular
|
||||||
name_template: "{{ .ProjectName }}"
|
name_template: "{{ .ProjectName }}-{{ .Arch }}"
|
||||||
|
|
||||||
release:
|
release:
|
||||||
prerelease: auto
|
prerelease: auto
|
||||||
|
|
||||||
brews:
|
brews:
|
||||||
- name: softnet
|
- name: softnet
|
||||||
ids:
|
repository:
|
||||||
- regular
|
|
||||||
tap:
|
|
||||||
owner: cirruslabs
|
owner: cirruslabs
|
||||||
name: homebrew-cli
|
name: homebrew-cli
|
||||||
caveats: See the Github repository for more information
|
caveats: See the Github repository for more information
|
||||||
|
|||||||
+19
-3
@@ -1,3 +1,4 @@
|
|||||||
|
use clap::ArgEnum;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
@@ -8,6 +9,18 @@ use vmnet::mode::Mode;
|
|||||||
use vmnet::parameters::{Parameter, ParameterKind};
|
use vmnet::parameters::{Parameter, ParameterKind};
|
||||||
use vmnet::{Events, Options};
|
use vmnet::{Events, Options};
|
||||||
|
|
||||||
|
#[derive(ArgEnum, Clone, Debug)]
|
||||||
|
pub enum NetType {
|
||||||
|
/// Shared network
|
||||||
|
///
|
||||||
|
/// Uses NAT-translation to give guests access to the global network
|
||||||
|
Nat,
|
||||||
|
/// Host network
|
||||||
|
///
|
||||||
|
/// Guests will be able to talk only to the host without access to global network
|
||||||
|
Host,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Host {
|
pub struct Host {
|
||||||
interface: vmnet::Interface,
|
interface: vmnet::Interface,
|
||||||
new_packets_rx: UnixDatagram,
|
new_packets_rx: UnixDatagram,
|
||||||
@@ -18,10 +31,13 @@ pub struct Host {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Host {
|
impl Host {
|
||||||
pub fn new() -> Result<Host> {
|
pub fn new(vm_net_type: NetType) -> Result<Host> {
|
||||||
// Initialize a vmnet.framework NAT interface with isolation enabled
|
// Initialize a vmnet.framework NAT or Host interface with isolation enabled
|
||||||
let mut interface = vmnet::Interface::new(
|
let mut interface = vmnet::Interface::new(
|
||||||
Mode::Shared(Default::default()),
|
match vm_net_type {
|
||||||
|
NetType::Nat => Mode::Shared(Default::default()),
|
||||||
|
NetType::Host => Mode::Host(Default::default()),
|
||||||
|
},
|
||||||
Options {
|
Options {
|
||||||
enable_isolation: Some(true),
|
enable_isolation: Some(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
mod dhcp_snooper;
|
mod dhcp_snooper;
|
||||||
mod host;
|
mod host;
|
||||||
|
pub use host::NetType;
|
||||||
mod poller;
|
mod poller;
|
||||||
pub mod proxy;
|
pub mod proxy;
|
||||||
mod vm;
|
mod vm;
|
||||||
|
|||||||
+3
-2
@@ -4,6 +4,7 @@ mod vm;
|
|||||||
|
|
||||||
use crate::dhcp_snooper::DhcpSnooper;
|
use crate::dhcp_snooper::DhcpSnooper;
|
||||||
use crate::host::Host;
|
use crate::host::Host;
|
||||||
|
use crate::host::NetType;
|
||||||
use crate::poller::Poller;
|
use crate::poller::Poller;
|
||||||
use crate::vm::VM;
|
use crate::vm::VM;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@@ -22,9 +23,9 @@ pub struct Proxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Proxy {
|
impl Proxy {
|
||||||
pub fn new(vm_fd: RawFd, vm_mac_address: MacAddress) -> Result<Proxy> {
|
pub fn new(vm_fd: RawFd, vm_mac_address: MacAddress, vm_net_type: NetType) -> Result<Proxy> {
|
||||||
let vm = VM::new(vm_fd)?;
|
let vm = VM::new(vm_fd)?;
|
||||||
let host = Host::new()?;
|
let host = Host::new(vm_net_type)?;
|
||||||
let poller = Poller::new(vm.as_raw_fd(), host.as_raw_fd())?;
|
let poller = Poller::new(vm.as_raw_fd(), host.as_raw_fd())?;
|
||||||
|
|
||||||
Ok(Proxy {
|
Ok(Proxy {
|
||||||
|
|||||||
+5
-1
@@ -2,6 +2,7 @@ use anyhow::{anyhow, Context};
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use nix::sys::signal::{signal, SigHandler, Signal};
|
use nix::sys::signal::{signal, SigHandler, Signal};
|
||||||
use privdrop::PrivDrop;
|
use privdrop::PrivDrop;
|
||||||
|
use softnet::NetType;
|
||||||
use softnet::proxy::Proxy;
|
use softnet::proxy::Proxy;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -28,6 +29,9 @@ struct Args {
|
|||||||
#[clap(long, help = "MAC address to enforce for the VM")]
|
#[clap(long, help = "MAC address to enforce for the VM")]
|
||||||
vm_mac_address: mac_address::MacAddress,
|
vm_mac_address: mac_address::MacAddress,
|
||||||
|
|
||||||
|
#[clap(long, arg_enum, help = "type of network to use for the VM", default_value_t=NetType::Nat)]
|
||||||
|
vm_net_type: NetType,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
help = "set bootpd(8) lease time to this value (in seconds) before starting the VM",
|
help = "set bootpd(8) lease time to this value (in seconds) before starting the VM",
|
||||||
@@ -140,7 +144,7 @@ fn try_main() -> anyhow::Result<()> {
|
|||||||
set_bootpd_lease_time(args.bootpd_lease_time);
|
set_bootpd_lease_time(args.bootpd_lease_time);
|
||||||
|
|
||||||
// Initialize the proxy while still having the root privileges
|
// Initialize the proxy while still having the root privileges
|
||||||
let mut proxy = Proxy::new(args.vm_fd as RawFd, args.vm_mac_address)
|
let mut proxy = Proxy::new(args.vm_fd as RawFd, args.vm_mac_address, args.vm_net_type)
|
||||||
.context("failed to initialize proxy")?;
|
.context("failed to initialize proxy")?;
|
||||||
|
|
||||||
// Drop effective privileges to the user
|
// Drop effective privileges to the user
|
||||||
|
|||||||
Reference in New Issue
Block a user