mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
tstest/natlab: use common helper for conn registration.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
80a14c49c6
commit
d7bc4ec029
@ -371,14 +371,7 @@ func (m *Machine) registerConn4(c *conn) error {
|
||||
if c.ipp.IP.Is6() && c.ipp.IP != v6unspec {
|
||||
return fmt.Errorf("registerConn4 got IPv6 %s", c.ipp)
|
||||
}
|
||||
if _, ok := m.conns4[c.ipp]; ok {
|
||||
return fmt.Errorf("duplicate conn listening on %v", c.ipp)
|
||||
}
|
||||
if m.conns4 == nil {
|
||||
m.conns4 = map[netaddr.IPPort]*conn{}
|
||||
}
|
||||
m.conns4[c.ipp] = c
|
||||
return nil
|
||||
return registerConn(&m.conns4, c)
|
||||
}
|
||||
|
||||
func (m *Machine) unregisterConn4(c *conn) {
|
||||
@ -393,14 +386,7 @@ func (m *Machine) registerConn6(c *conn) error {
|
||||
if c.ipp.IP.Is4() {
|
||||
return fmt.Errorf("registerConn6 got IPv4 %s", c.ipp)
|
||||
}
|
||||
if _, ok := m.conns6[c.ipp]; ok {
|
||||
return fmt.Errorf("duplicate conn listening on %v", c.ipp)
|
||||
}
|
||||
if m.conns6 == nil {
|
||||
m.conns6 = map[netaddr.IPPort]*conn{}
|
||||
}
|
||||
m.conns6[c.ipp] = c
|
||||
return nil
|
||||
return registerConn(&m.conns6, c)
|
||||
}
|
||||
|
||||
func (m *Machine) unregisterConn6(c *conn) {
|
||||
@ -409,6 +395,17 @@ func (m *Machine) unregisterConn6(c *conn) {
|
||||
delete(m.conns6, c.ipp)
|
||||
}
|
||||
|
||||
func registerConn(conns *map[netaddr.IPPort]*conn, c *conn) error {
|
||||
if _, ok := (*conns)[c.ipp]; ok {
|
||||
return fmt.Errorf("duplicate conn listening on %v", c.ipp)
|
||||
}
|
||||
if *conns == nil {
|
||||
*conns = map[netaddr.IPPort]*conn{}
|
||||
}
|
||||
(*conns)[c.ipp] = c
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Machine) AddNetwork(n *Network) {}
|
||||
|
||||
func (m *Machine) ListenPacket(network, address string) (net.PacketConn, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user