For higher-level use. Connects b/w struct file
and struct sk
:
typedef enum {
SS_FREE = 0, /* not allocated */
SS_UNCONNECTED, /* unconnected to any socket */
SS_CONNECTING, /* in process of connecting */
use std::{fs, str::FromStr}; | |
#[derive(Debug, PartialEq, Eq, Copy, Clone)] | |
struct Range { | |
start: i64, | |
end: i64, | |
} | |
impl PartialOrd for Range { | |
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
A local process attempts to send packet to WireGuard IP address (e.g., 192.168.4.3). The packet is delivered to wg interface (for user-space implementation, this is a TUN interface). Boringtun reads packets from the tun interface, find a matching peer, encapsulate packet and emit packet via the Udp socket. Recall that unlike TCP (connection, STREAM, ...), a UDP socket can be reused to send packets to different destinations (See sendto() and recvfrom() usages).
TL;DR. You first create a network namesmace (netns
), and a veth
device
(you also create a peer). Then you assign one end to another netns.
You can talk to another netns via the veth.
TODO: How to use a different device instead of veth for communication across netns?
qemu-system-x86_64 -enable-kvm -m 2G -smp 4 --machine q35 -nographic -drive if=pflash,format=raw,file=OVMF_CODE.fd,readonly=on -drive if=pflash,format=raw,file=OVMF_VARS.fd,readonly=on -drive if=none,file=fat:rw:esp,id=esp0,format=raw -device virtio-blk-pci,drive=esp0,num-queues=4 | |
SecCoreStartupWithStack(0xFFFCC000, 0x820000) | |
Register PPI Notify: DCD0BE23-9586-40F4-B643-06522CED4EDE | |
Install PPI: 8C8CE578-8A3D-4F1C-9935-896185C32DD3 | |
Install PPI: 5473C07A-3DCB-4DCA-BD6F-1E9689E7349A | |
The 0th FV start address is 0x00000820000, size is 0x000E0000, handle is 0x820000 | |
Register PPI Notify: 49EDB1C1-BF21-4761-BB12-EB0031AABB39 | |
Register PPI Notify: EA7CA24B-DED5-4DAD-A389-BF827E8F9B38 | |
Install PPI: B9E0ABFE-5979-4914-977F-6DEE78C278A6 | |
Install PPI: DBE23AA9-A345-4B97-85B6-B226F1617389 |
On Ubuntu, you can use lsinitramfs
or unmkinitramfs
tools to play with initrd.
#!/usr/bin/env bash | |
KERNEL=$1 | |
DISKIMG=$2 | |
# NOTE: You can omit `virtio_mmio.device=4K@0xd0000000:5` | |
qemu-system-x86_64 -machine microvm \ | |
-drive file=$DISKIMG,format=raw,id=id0 \ | |
-device virtio-blk-device,drive=id0 \ | |
-m 4G -smp 8 \ |