From a5b84fa9213f71e1ffcf5b352486261c325cc0e3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 17 Feb 2020 13:48:04 -0800 Subject: [PATCH] ipn: add AdvertiseRoutes to Prefs. This is a prelude to supporting relaynode's --routes in tailscaled. The daemon needs to remembers routes to advertise, and the CLI needs to be able to change the set of advertised routes. Prefs is the thing used for both of these. Signed-off-by: David Anderson --- ipn/prefs.go | 8 +++++--- ipn/prefs_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ipn/prefs.go b/ipn/prefs.go index 12babdd69..6da71bfaa 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -10,6 +10,7 @@ import ( "fmt" "io/ioutil" "log" + "net" "os" "path/filepath" @@ -24,6 +25,7 @@ type Prefs struct { WantRunning bool NotepadURLs bool UsePacketFilter bool + AdvertiseRoutes []*net.IPNet // The Persist field is named 'Config' in the file for backward // compatibility with earlier versions. @@ -34,7 +36,7 @@ type Prefs struct { } // IsEmpty reports whether p is nil or pointing to a Prefs zero value. -func (uc *Prefs) IsEmpty() bool { return uc == nil || *uc == Prefs{} } +func (uc *Prefs) IsEmpty() bool { return uc == nil || uc.Equals(&Prefs{}) } func (uc *Prefs) Pretty() string { var ucp string @@ -43,9 +45,9 @@ func (uc *Prefs) Pretty() string { } else { ucp = "Persist=nil" } - return fmt.Sprintf("Prefs{ra=%v mesh=%v dns=%v want=%v notepad=%v pf=%v %v}", + return fmt.Sprintf("Prefs{ra=%v mesh=%v dns=%v want=%v notepad=%v pf=%v routes=%v %v}", uc.RouteAll, uc.AllowSingleHosts, uc.CorpDNS, uc.WantRunning, - uc.NotepadURLs, uc.UsePacketFilter, ucp) + uc.NotepadURLs, uc.UsePacketFilter, uc.AdvertiseRoutes, ucp) } func (uc *Prefs) ToBytes() []byte { diff --git a/ipn/prefs_test.go b/ipn/prefs_test.go index 467ba0960..95e5cca6c 100644 --- a/ipn/prefs_test.go +++ b/ipn/prefs_test.go @@ -29,7 +29,7 @@ func checkPrefs(t *testing.T, p Prefs) { } p2 = p p2.RouteAll = true - if p == p2 { + if p.Equals(&p2) { t.Fatalf("p == p2\n") } p2b, err = PrefsFromBytes(p2.ToBytes(), false)