Skip to content

Commit ff1d0aa

Browse files
committed
tstest/natlab/vnet: start adding tests
And refactor some of vnet.go for testability. The only behavioral change (with a new test) is that ethernet broadcasts no longer get sent back to the sender. Updates tailscale#13038 Change-Id: Ic2e7e7d6d8805b7b7f2b5c52c2c5ba97101cef14 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 31cdbd6 commit ff1d0aa

File tree

3 files changed

+402
-99
lines changed

3 files changed

+402
-99
lines changed

tstest/natlab/vnet/conf.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package vnet
66
import (
77
"cmp"
88
"fmt"
9-
"log"
109
"net/netip"
1110
"os"
1211
"slices"
@@ -61,6 +60,11 @@ func (c *Config) FirstNetwork() *Network {
6160
return c.networks[0]
6261
}
6362

63+
func nodeMac(n int) MAC {
64+
// 52=TS then 0xcc for cccclient
65+
return MAC{0x52, 0xcc, 0xcc, 0xcc, 0xcc, byte(n)}
66+
}
67+
6468
// AddNode creates a new node in the world.
6569
//
6670
// The opts may be of the following types:
@@ -70,10 +74,10 @@ func (c *Config) FirstNetwork() *Network {
7074
// On an error or unknown opt type, AddNode returns a
7175
// node with a carried error that gets returned later.
7276
func (c *Config) AddNode(opts ...any) *Node {
73-
num := len(c.nodes)
77+
num := len(c.nodes) + 1
7478
n := &Node{
75-
num: num + 1,
76-
mac: MAC{0x52, 0xcc, 0xcc, 0xcc, 0xcc, byte(num) + 1}, // 52=TS then 0xcc for ccclient
79+
num: num,
80+
mac: nodeMac(num),
7781
}
7882
c.nodes = append(c.nodes, n)
7983
for _, o := range opts {
@@ -130,10 +134,10 @@ type TailscaledEnv struct {
130134
// On an error or unknown opt type, AddNetwork returns a
131135
// network with a carried error that gets returned later.
132136
func (c *Config) AddNetwork(opts ...any) *Network {
133-
num := len(c.networks)
137+
num := len(c.networks) + 1
134138
n := &Network{
135-
num: num + 1,
136-
mac: MAC{0x52, 0xee, 0xee, 0xee, 0xee, byte(num) + 1}, // 52=TS then 0xee for 'etwork
139+
num: num,
140+
mac: MAC{0x52, 0xee, 0xee, 0xee, 0xee, byte(num)}, // 52=TS then 0xee for 'etwork
137141
}
138142
c.networks = append(c.networks, n)
139143
for _, o := range opts {
@@ -330,7 +334,7 @@ func (s *Server) initFromConfig(c *Config) error {
330334
lanIP4: conf.lanIP4,
331335
nodesByIP4: map[netip.Addr]*node{},
332336
nodesByMAC: map[MAC]*node{},
333-
logf: logger.WithPrefix(log.Printf, fmt.Sprintf("[net-%v] ", conf.mac)),
337+
logf: logger.WithPrefix(s.logf, fmt.Sprintf("[net-%v] ", conf.mac)),
334338
}
335339
netOfConf[conf] = n
336340
s.networks.Add(n)

0 commit comments

Comments
 (0)