From 9f7cbf6cf14c4a3642c3ffae5e89d605f301734b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 22 Jan 2021 14:26:39 -0800 Subject: [PATCH] wgengine/filter: add a Clone method. Signed-off-by: David Anderson --- wgengine/filter/match.go | 2 ++ wgengine/filter/match_clone.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 wgengine/filter/match_clone.go diff --git a/wgengine/filter/match.go b/wgengine/filter/match.go index 6dbe6b5bd..c30c37552 100644 --- a/wgengine/filter/match.go +++ b/wgengine/filter/match.go @@ -12,6 +12,8 @@ import ( "tailscale.com/net/packet" ) +//go:generate go run tailscale.com/cmd/cloner --type=Match --output=match_clone.go + // PortRange is a range of TCP and UDP ports. type PortRange struct { First, Last uint16 // inclusive diff --git a/wgengine/filter/match_clone.go b/wgengine/filter/match_clone.go new file mode 100644 index 000000000..571664bd5 --- /dev/null +++ b/wgengine/filter/match_clone.go @@ -0,0 +1,31 @@ +// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Code generated by tailscale.com/cmd/cloner -type Match; DO NOT EDIT. + +package filter + +import ( + "inet.af/netaddr" +) + +// Clone makes a deep copy of Match. +// The result aliases no memory with the original. +func (src *Match) Clone() *Match { + if src == nil { + return nil + } + dst := new(Match) + *dst = *src + dst.Dsts = append(src.Dsts[:0:0], src.Dsts...) + dst.Srcs = append(src.Srcs[:0:0], src.Srcs...) + return dst +} + +// A compilation failure here means this code must be regenerated, with command: +// tailscale.com/cmd/cloner -type Match +var _MatchNeedsRegeneration = Match(struct { + Dsts []NetPortRange + Srcs []netaddr.IPPrefix +}{})