From 3b70968c256979a1f08ff02f716c058729ad69c2 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 23 Aug 2024 11:37:19 -0700 Subject: [PATCH] cmd/vnet: add --blend and --pcap flags Updates #13038 Change-Id: Id16ea9eb94447a3d9651215f04b2525daf10b3eb Signed-off-by: Brad Fitzpatrick --- cmd/vnet/vnet-main.go | 14 +++++++++----- tstest/natlab/vnet/conf.go | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/vnet/vnet-main.go b/cmd/vnet/vnet-main.go index 99eb022a8..c26014116 100644 --- a/cmd/vnet/vnet-main.go +++ b/cmd/vnet/vnet-main.go @@ -22,11 +22,13 @@ ) var ( - listen = flag.String("listen", "/tmp/qemu.sock", "path to listen on") - nat = flag.String("nat", "easy", "type of NAT to use") - nat2 = flag.String("nat2", "hard", "type of NAT to use for second network") - portmap = flag.Bool("portmap", false, "enable portmapping") - dgram = flag.Bool("dgram", false, "enable datagram mode; for use with macOS Hypervisor.Framework and VZFileHandleNetworkDeviceAttachment") + listen = flag.String("listen", "/tmp/qemu.sock", "path to listen on") + nat = flag.String("nat", "easy", "type of NAT to use") + nat2 = flag.String("nat2", "hard", "type of NAT to use for second network") + portmap = flag.Bool("portmap", false, "enable portmapping") + dgram = flag.Bool("dgram", false, "enable datagram mode; for use with macOS Hypervisor.Framework and VZFileHandleNetworkDeviceAttachment") + blend = flag.Bool("blend", true, "blend reality (controlplane.tailscale.com and DERPs) into the virtual network") + pcapFile = flag.String("pcap", "", "if non-empty, filename to write pcap") ) func main() { @@ -57,6 +59,8 @@ func main() { } var c vnet.Config + c.SetPCAPFile(*pcapFile) + c.SetBlendReality(*blend) node1 := c.AddNode(c.AddNetwork("2.1.1.1", "192.168.1.1/24", vnet.NAT(*nat))) c.AddNode(c.AddNetwork("2.2.2.2", "10.2.0.1/16", vnet.NAT(*nat2))) if *portmap { diff --git a/tstest/natlab/vnet/conf.go b/tstest/natlab/vnet/conf.go index 1703e0c12..7e4a1207e 100644 --- a/tstest/natlab/vnet/conf.go +++ b/tstest/natlab/vnet/conf.go @@ -29,19 +29,31 @@ // values to modify the config before calling NewServer. // Once the NewServer is called, Config is no longer used. type Config struct { - nodes []*Node - networks []*Network - pcapFile string + nodes []*Node + networks []*Network + pcapFile string + blendReality bool } +// SetPCAPFile sets the filename to write a pcap file to, +// or empty to disable pcap file writing. func (c *Config) SetPCAPFile(file string) { c.pcapFile = file } +// NumNodes returns the number of nodes in the configuration. func (c *Config) NumNodes() int { return len(c.nodes) } +// SetBlendReality sets whether to blend the real controlplane.tailscale.com and +// DERP servers into the virtual network. This is mostly useful for interactive +// testing when working on natlab. +func (c *Config) SetBlendReality(v bool) { + c.blendReality = v +} + +// FirstNetwork returns the first network in the config, or nil if none. func (c *Config) FirstNetwork() *Network { if len(c.networks) == 0 { return nil