docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
type updateJSON struct {
<mask> _ = writeAllConfigsAndReloadDNS() <mask> returnOK(w) <mask> } <mask> <mask> type clientUpdateJSON struct { <mask> Name string `json:"name"` <mask> Data clientJSON `json:"data"` <mask> } <mask> <mask> // Update client's properties </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if !clientDel(cj.Name) { </s> add if !config.clients.Del(cj.Name) { </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove _, _ = clientAddHost(ip, host, ClientSourceRDNS) </s> add _, _ = config.clients.AddHost(ip, host, ClientSourceRDNS) </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove func clientUpdate(name string, c Client) error { err := clientCheck(&c) </s> add func (clients *clientsContainer) Update(name string, c Client) error { err := c.check()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients.go
var dj updateJSON
<mask> httpError(w, http.StatusBadRequest, "failed to read request body: %s", err) <mask> return <mask> } <mask> <mask> var dj clientUpdateJSON <mask> err = json.Unmarshal(body, &dj) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "JSON parse: %s", err) <mask> return <mask> } </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if !clientDel(cj.Name) { </s> add if !config.clients.Del(cj.Name) { </s> remove err = clientUpdate(dj.Name, *c) </s> add err = config.clients.Update(dj.Name, *c) </s> remove ok, err := clientAdd(*c) </s> add ok, err := config.clients.Add(*c) </s> remove _, err = clientAdd(cli) </s> add _, err = config.clients.Add(cli) </s> remove func clientUpdate(name string, c Client) error { err := clientCheck(&c) </s> add func (clients *clientsContainer) Update(name string, c Client) error { err := c.check()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients.go
err = config.clients.Update(dj.Name, *c)
<mask> httpError(w, http.StatusBadRequest, "%s", err) <mask> return <mask> } <mask> <mask> err = clientUpdate(dj.Name, *c) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "%s", err) <mask> return <mask> } <mask> </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove ok, err := clientAdd(*c) </s> add ok, err := config.clients.Add(*c) </s> remove var dj clientUpdateJSON </s> add var dj updateJSON </s> remove if !clientDel(cj.Name) { </s> add if !config.clients.Del(cj.Name) { </s> remove _, err = clientAdd(cli) </s> add _, err = config.clients.Add(cli) </s> remove func clientUpdate(name string, c Client) error { err := clientCheck(&c) </s> add func (clients *clientsContainer) Update(name string, c Client) error { err := c.check()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients.go
clients := clientsContainer{}
<mask> var e error <mask> var b bool <mask> <mask> clients.Init() <mask> <mask> // add <mask> c = Client{ <mask> IP: "1.1.1.1", </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove clientsInit() </s> add clients.Init() </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1") </s> remove t.Fatalf("clientFind #2") </s> add t.Fatalf("Find #2") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c)
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
clients.Init()
<mask> var c Client <mask> var e error <mask> var b bool <mask> <mask> clientsInit() <mask> <mask> // add <mask> c = Client{ <mask> IP: "1.1.1.1", <mask> Name: "client1", </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1") </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.Add(c)
<mask> c = Client{ <mask> IP: "1.1.1.1", <mask> Name: "client1", <mask> } <mask> b, e = clientAdd(c) <mask> if !b || e != nil { <mask> t.Fatalf("clientAdd #1") <mask> } <mask> <mask> // add #2 </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
t.Fatalf("Add #1")
<mask> Name: "client1", <mask> } <mask> b, e = clientAdd(c) <mask> if !b || e != nil { <mask> t.Fatalf("clientAdd #1") <mask> } <mask> <mask> // add #2 <mask> c = Client{ <mask> IP: "2.2.2.2", </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.Add(c)
<mask> c = Client{ <mask> IP: "2.2.2.2", <mask> Name: "client2", <mask> } <mask> b, e = clientAdd(c) <mask> if !b || e != nil { <mask> t.Fatalf("clientAdd #2") <mask> } <mask> <mask> c, b = clientFind("1.1.1.1") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove t.Fatalf("clientAdd #2") </s> add t.Fatalf("Add #2") </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove c, b = clientFind("1.1.1.1") </s> add c, b = clients.Find("1.1.1.1")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
t.Fatalf("Add #2")
<mask> Name: "client2", <mask> } <mask> b, e = clientAdd(c) <mask> if !b || e != nil { <mask> t.Fatalf("clientAdd #2") <mask> } <mask> <mask> c, b = clientFind("1.1.1.1") <mask> if !b || c.Name != "client1" { <mask> t.Fatalf("clientFind #1") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove c, b = clientFind("1.1.1.1") </s> add c, b = clients.Find("1.1.1.1") </s> remove t.Fatalf("clientFind #1") </s> add t.Fatalf("Find #1") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove c, b = clientFind("2.2.2.2") </s> add c, b = clients.Find("2.2.2.2") </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
c, b = clients.Find("1.1.1.1")
<mask> if !b || e != nil { <mask> t.Fatalf("clientAdd #2") <mask> } <mask> <mask> c, b = clientFind("1.1.1.1") <mask> if !b || c.Name != "client1" { <mask> t.Fatalf("clientFind #1") <mask> } <mask> <mask> c, b = clientFind("2.2.2.2") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove t.Fatalf("clientFind #1") </s> add t.Fatalf("Find #1") </s> remove t.Fatalf("clientAdd #2") </s> add t.Fatalf("Add #2") </s> remove c, b = clientFind("2.2.2.2") </s> add c, b = clients.Find("2.2.2.2") </s> remove t.Fatalf("clientFind #2") </s> add t.Fatalf("Find #2") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
t.Fatalf("Find #1")
<mask> } <mask> <mask> c, b = clientFind("1.1.1.1") <mask> if !b || c.Name != "client1" { <mask> t.Fatalf("clientFind #1") <mask> } <mask> <mask> c, b = clientFind("2.2.2.2") <mask> if !b || c.Name != "client2" { <mask> t.Fatalf("clientFind #2") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove c, b = clientFind("1.1.1.1") </s> add c, b = clients.Find("1.1.1.1") </s> remove c, b = clientFind("2.2.2.2") </s> add c, b = clients.Find("2.2.2.2") </s> remove t.Fatalf("clientAdd #2") </s> add t.Fatalf("Add #2") </s> remove t.Fatalf("clientFind #2") </s> add t.Fatalf("Find #2") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
c, b = clients.Find("2.2.2.2")
<mask> if !b || c.Name != "client1" { <mask> t.Fatalf("clientFind #1") <mask> } <mask> <mask> c, b = clientFind("2.2.2.2") <mask> if !b || c.Name != "client2" { <mask> t.Fatalf("clientFind #2") <mask> } <mask> <mask> // failed add - name in use </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove t.Fatalf("clientFind #1") </s> add t.Fatalf("Find #1") </s> remove t.Fatalf("clientFind #2") </s> add t.Fatalf("Find #2") </s> remove c, b = clientFind("1.1.1.1") </s> add c, b = clients.Find("1.1.1.1") </s> remove t.Fatalf("clientAdd #2") </s> add t.Fatalf("Add #2") </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - name in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
t.Fatalf("Find #2")
<mask> } <mask> <mask> c, b = clientFind("2.2.2.2") <mask> if !b || c.Name != "client2" { <mask> t.Fatalf("clientFind #2") <mask> } <mask> <mask> // failed add - name in use <mask> c = Client{ <mask> IP: "1.2.3.5", </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove c, b = clientFind("2.2.2.2") </s> add c, b = clients.Find("2.2.2.2") </s> remove t.Fatalf("clientFind #1") </s> add t.Fatalf("Find #1") </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove c, b = clientFind("1.1.1.1") </s> add c, b = clients.Find("1.1.1.1")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, _ = clients.Add(c)
<mask> c = Client{ <mask> IP: "1.2.3.5", <mask> Name: "client1", <mask> } <mask> b, _ = clientAdd(c) <mask> if b { <mask> t.Fatalf("clientAdd - name in use") <mask> } <mask> <mask> // failed add - ip in use </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove t.Fatalf("clientFind #2") </s> add t.Fatalf("Find #2") </s> remove t.Fatalf("clientAdd - ip in use") </s> add t.Fatalf("Add - ip in use") </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - name in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
t.Fatalf("Add - name in use")
<mask> Name: "client1", <mask> } <mask> b, _ = clientAdd(c) <mask> if b { <mask> t.Fatalf("clientAdd - name in use") <mask> } <mask> <mask> // failed add - ip in use <mask> c = Client{ <mask> IP: "2.2.2.2", </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove t.Fatalf("clientAdd - ip in use") </s> add t.Fatalf("Add - ip in use") </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1") </s> remove t.Fatalf("clientFind #2") </s> add t.Fatalf("Find #2")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.Add(c)
<mask> c = Client{ <mask> IP: "2.2.2.2", <mask> Name: "client3", <mask> } <mask> b, e = clientAdd(c) <mask> if b || e == nil { <mask> t.Fatalf("clientAdd - ip in use") <mask> } <mask> <mask> // get </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove t.Fatalf("clientAdd - ip in use") </s> add t.Fatalf("Add - ip in use") </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
t.Fatalf("Add - ip in use")
<mask> Name: "client3", <mask> } <mask> b, e = clientAdd(c) <mask> if b || e == nil { <mask> t.Fatalf("clientAdd - ip in use") <mask> } <mask> <mask> // get <mask> if clientExists("1.2.3.4") { <mask> t.Fatalf("clientExists") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove if clientExists("1.2.3.4") { t.Fatalf("clientExists") </s> add if clients.Exists("1.2.3.4") { t.Fatalf("Exists") </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove b, _ = clientAdd(c) </s> add b, _ = clients.Add(c) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Exists("1.2.3.4") { t.Fatalf("Exists")
<mask> t.Fatalf("clientAdd - ip in use") <mask> } <mask> <mask> // get <mask> if clientExists("1.2.3.4") { <mask> t.Fatalf("clientExists") <mask> } <mask> if !clientExists("1.1.1.1") { <mask> t.Fatalf("clientExists #1") <mask> } <mask> if !clientExists("2.2.2.2") { </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if !clientExists("1.1.1.1") { t.Fatalf("clientExists #1") </s> add if !clients.Exists("1.1.1.1") { t.Fatalf("Exists #1") </s> remove t.Fatalf("clientAdd - ip in use") </s> add t.Fatalf("Add - ip in use") </s> remove if !clientExists("2.2.2.2") { t.Fatalf("clientExists #2") </s> add if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2") </s> remove if !clientExists("1.1.1.1") { </s> add if !clients.Exists("1.1.1.1") { </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if !clients.Exists("1.1.1.1") { t.Fatalf("Exists #1")
<mask> // get <mask> if clientExists("1.2.3.4") { <mask> t.Fatalf("clientExists") <mask> } <mask> if !clientExists("1.1.1.1") { <mask> t.Fatalf("clientExists #1") <mask> } <mask> if !clientExists("2.2.2.2") { <mask> t.Fatalf("clientExists #2") <mask> } <mask> </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientExists("1.2.3.4") { t.Fatalf("clientExists") </s> add if clients.Exists("1.2.3.4") { t.Fatalf("Exists") </s> remove if !clientExists("2.2.2.2") { t.Fatalf("clientExists #2") </s> add if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2") </s> remove t.Fatalf("clientAdd - ip in use") </s> add t.Fatalf("Add - ip in use") </s> remove if !clientExists("1.1.1.1") { </s> add if !clients.Exists("1.1.1.1") { </s> remove if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { t.Fatalf("clientExists - get after update") </s> add if clients.Exists("1.1.1.1") || !clients.Exists("1.1.1.2") { t.Fatalf("Exists - get after update")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2")
<mask> } <mask> if !clientExists("1.1.1.1") { <mask> t.Fatalf("clientExists #1") <mask> } <mask> if !clientExists("2.2.2.2") { <mask> t.Fatalf("clientExists #2") <mask> } <mask> <mask> // failed update - no such name <mask> c.IP = "1.2.3.0" <mask> c.Name = "client3" </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientUpdate("client3", c) == nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client3", c) == nil { t.Fatalf("Update") </s> remove if !clientExists("1.1.1.1") { t.Fatalf("clientExists #1") </s> add if !clients.Exists("1.1.1.1") { t.Fatalf("Exists #1") </s> remove if clientDel("client3") { t.Fatalf("clientDel - no such name") </s> add if clients.Del("client3") { t.Fatalf("Del - no such name") </s> remove if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { t.Fatalf("clientExists - get after update") </s> add if clients.Exists("1.1.1.1") || !clients.Exists("1.1.1.2") { t.Fatalf("Exists - get after update") </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - name in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Update("client3", c) == nil { t.Fatalf("Update")
<mask> <mask> // failed update - no such name <mask> c.IP = "1.2.3.0" <mask> c.Name = "client3" <mask> if clientUpdate("client3", c) == nil { <mask> t.Fatalf("clientUpdate") <mask> } <mask> <mask> // failed update - name in use <mask> c.IP = "1.2.3.0" <mask> c.Name = "client2" </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - name in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use") </s> remove if !clientExists("2.2.2.2") { t.Fatalf("clientExists #2") </s> add if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2") </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - ip in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - ip in use") </s> remove if clientUpdate("client1", c) != nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client1", c) != nil { t.Fatalf("Update") </s> remove c, b = clientFind("2.2.2.2") </s> add c, b = clients.Find("2.2.2.2")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use")
<mask> <mask> // failed update - name in use <mask> c.IP = "1.2.3.0" <mask> c.Name = "client2" <mask> if clientUpdate("client1", c) == nil { <mask> t.Fatalf("clientUpdate - name in use") <mask> } <mask> <mask> // failed update - ip in use <mask> c.IP = "2.2.2.2" <mask> c.Name = "client1" </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - ip in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - ip in use") </s> remove if clientUpdate("client3", c) == nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client3", c) == nil { t.Fatalf("Update") </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use") </s> remove c, b = clientFind("2.2.2.2") </s> add c, b = clients.Find("2.2.2.2") </s> remove if clientUpdate("client1", c) != nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client1", c) != nil { t.Fatalf("Update")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Update("client1", c) == nil { t.Fatalf("Update - ip in use")
<mask> <mask> // failed update - ip in use <mask> c.IP = "2.2.2.2" <mask> c.Name = "client1" <mask> if clientUpdate("client1", c) == nil { <mask> t.Fatalf("clientUpdate - ip in use") <mask> } <mask> <mask> // update <mask> c.IP = "1.1.1.2" <mask> c.Name = "client1" </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - name in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use") </s> remove if clientUpdate("client3", c) == nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client3", c) == nil { t.Fatalf("Update") </s> remove if clientUpdate("client1", c) != nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client1", c) != nil { t.Fatalf("Update") </s> remove if !clientExists("2.2.2.2") { t.Fatalf("clientExists #2") </s> add if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2") </s> remove t.Fatalf("clientAdd - name in use") </s> add t.Fatalf("Add - name in use")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Update("client1", c) != nil { t.Fatalf("Update")
<mask> <mask> // update <mask> c.IP = "1.1.1.2" <mask> c.Name = "client1" <mask> if clientUpdate("client1", c) != nil { <mask> t.Fatalf("clientUpdate") <mask> } <mask> <mask> // get after update <mask> if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { <mask> t.Fatalf("clientExists - get after update") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { t.Fatalf("clientExists - get after update") </s> add if clients.Exists("1.1.1.1") || !clients.Exists("1.1.1.2") { t.Fatalf("Exists - get after update") </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - ip in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - ip in use") </s> remove if clientUpdate("client1", c) == nil { t.Fatalf("clientUpdate - name in use") </s> add if clients.Update("client1", c) == nil { t.Fatalf("Update - name in use") </s> remove if clientUpdate("client3", c) == nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client3", c) == nil { t.Fatalf("Update") </s> remove if clientDel("client3") { t.Fatalf("clientDel - no such name") </s> add if clients.Del("client3") { t.Fatalf("Del - no such name")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Exists("1.1.1.1") || !clients.Exists("1.1.1.2") { t.Fatalf("Exists - get after update")
<mask> t.Fatalf("clientUpdate") <mask> } <mask> <mask> // get after update <mask> if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { <mask> t.Fatalf("clientExists - get after update") <mask> } <mask> <mask> // failed remove - no such name <mask> if clientDel("client3") { <mask> t.Fatalf("clientDel - no such name") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientDel("client3") { t.Fatalf("clientDel - no such name") </s> add if clients.Del("client3") { t.Fatalf("Del - no such name") </s> remove if clientUpdate("client1", c) != nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client1", c) != nil { t.Fatalf("Update") </s> remove if !clientExists("2.2.2.2") { t.Fatalf("clientExists #2") </s> add if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2") </s> remove if !clientDel("client1") || clientExists("1.1.1.2") { t.Fatalf("clientDel") </s> add if !clients.Del("client1") || clients.Exists("1.1.1.2") { t.Fatalf("Del") </s> remove if clientUpdate("client3", c) == nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client3", c) == nil { t.Fatalf("Update")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if clients.Del("client3") { t.Fatalf("Del - no such name")
<mask> t.Fatalf("clientExists - get after update") <mask> } <mask> <mask> // failed remove - no such name <mask> if clientDel("client3") { <mask> t.Fatalf("clientDel - no such name") <mask> } <mask> <mask> // remove <mask> if !clientDel("client1") || clientExists("1.1.1.2") { <mask> t.Fatalf("clientDel") </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { t.Fatalf("clientExists - get after update") </s> add if clients.Exists("1.1.1.1") || !clients.Exists("1.1.1.2") { t.Fatalf("Exists - get after update") </s> remove if !clientDel("client1") || clientExists("1.1.1.2") { t.Fatalf("clientDel") </s> add if !clients.Del("client1") || clients.Exists("1.1.1.2") { t.Fatalf("Del") </s> remove if !clientExists("2.2.2.2") { t.Fatalf("clientExists #2") </s> add if !clients.Exists("2.2.2.2") { t.Fatalf("Exists #2") </s> remove if clientUpdate("client3", c) == nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client3", c) == nil { t.Fatalf("Update") </s> remove if clientUpdate("client1", c) != nil { t.Fatalf("clientUpdate") </s> add if clients.Update("client1", c) != nil { t.Fatalf("Update")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if !clients.Del("client1") || clients.Exists("1.1.1.2") { t.Fatalf("Del")
<mask> t.Fatalf("clientDel - no such name") <mask> } <mask> <mask> // remove <mask> if !clientDel("client1") || clientExists("1.1.1.2") { <mask> t.Fatalf("clientDel") <mask> } <mask> <mask> // add host client <mask> b, e = clientAddHost("1.1.1.1", "host", ClientSourceARP) <mask> if !b || e != nil { </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if clientDel("client3") { t.Fatalf("clientDel - no such name") </s> add if clients.Del("client3") { t.Fatalf("Del - no such name") </s> remove b, e = clientAddHost("1.1.1.1", "host", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host", ClientSourceARP) </s> remove if clientExists("1.1.1.1") || !clientExists("1.1.1.2") { t.Fatalf("clientExists - get after update") </s> add if clients.Exists("1.1.1.1") || !clients.Exists("1.1.1.2") { t.Fatalf("Exists - get after update") </s> remove b, e = clientAddHost("1.1.1.1", "host2", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host2", ClientSourceARP) </s> remove b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> add b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.AddHost("1.1.1.1", "host", ClientSourceARP)
<mask> t.Fatalf("clientDel") <mask> } <mask> <mask> // add host client <mask> b, e = clientAddHost("1.1.1.1", "host", ClientSourceARP) <mask> if !b || e != nil { <mask> t.Fatalf("clientAddHost") <mask> } <mask> <mask> // failed add - ip exists </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove if !clientDel("client1") || clientExists("1.1.1.2") { t.Fatalf("clientDel") </s> add if !clients.Del("client1") || clients.Exists("1.1.1.2") { t.Fatalf("Del") </s> remove b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> add b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> remove b, e = clientAddHost("1.1.1.1", "host2", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host2", ClientSourceARP) </s> remove b, e = clientAdd(c) </s> add b, e = clients.Add(c) </s> remove t.Fatalf("clientAdd #1") </s> add t.Fatalf("Add #1")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS)
<mask> t.Fatalf("clientAddHost") <mask> } <mask> <mask> // failed add - ip exists <mask> b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) <mask> if b || e != nil { <mask> t.Fatalf("clientAddHost - ip exists") <mask> } <mask> <mask> // overwrite with new data </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAddHost("1.1.1.1", "host2", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host2", ClientSourceARP) </s> remove b, e = clientAddHost("1.1.1.1", "host3", ClientSourceHostsFile) </s> add b, e = clients.AddHost("1.1.1.1", "host3", ClientSourceHostsFile) </s> remove b, e = clientAddHost("1.1.1.1", "host", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host", ClientSourceARP) </s> remove if !clientExists("1.1.1.1") { </s> add if !clients.Exists("1.1.1.1") { </s> remove t.Fatalf("clientAdd - ip in use") </s> add t.Fatalf("Add - ip in use")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.AddHost("1.1.1.1", "host2", ClientSourceARP)
<mask> t.Fatalf("clientAddHost - ip exists") <mask> } <mask> <mask> // overwrite with new data <mask> b, e = clientAddHost("1.1.1.1", "host2", ClientSourceARP) <mask> if !b || e != nil { <mask> t.Fatalf("clientAddHost - overwrite with new data") <mask> } <mask> <mask> // overwrite with new data (higher priority) </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAddHost("1.1.1.1", "host3", ClientSourceHostsFile) </s> add b, e = clients.AddHost("1.1.1.1", "host3", ClientSourceHostsFile) </s> remove b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> add b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> remove if !clientExists("1.1.1.1") { </s> add if !clients.Exists("1.1.1.1") { </s> remove b, e = clientAddHost("1.1.1.1", "host", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host", ClientSourceARP) </s> remove // Add new IP -> Host pair </s> add // AddHost adds new IP -> Host pair
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
b, e = clients.AddHost("1.1.1.1", "host3", ClientSourceHostsFile)
<mask> t.Fatalf("clientAddHost - overwrite with new data") <mask> } <mask> <mask> // overwrite with new data (higher priority) <mask> b, e = clientAddHost("1.1.1.1", "host3", ClientSourceHostsFile) <mask> if !b || e != nil { <mask> t.Fatalf("clientAddHost - overwrite with new data (higher priority)") <mask> } <mask> <mask> // get </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAddHost("1.1.1.1", "host2", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host2", ClientSourceARP) </s> remove if !clientExists("1.1.1.1") { </s> add if !clients.Exists("1.1.1.1") { </s> remove b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> add b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> remove // Add new IP -> Host pair </s> add // AddHost adds new IP -> Host pair </s> remove b, e = clientAddHost("1.1.1.1", "host", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host", ClientSourceARP)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
if !clients.Exists("1.1.1.1") {
<mask> t.Fatalf("clientAddHost - overwrite with new data (higher priority)") <mask> } <mask> <mask> // get <mask> if !clientExists("1.1.1.1") { <mask> t.Fatalf("clientAddHost") <mask> } <mask> } </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove b, e = clientAddHost("1.1.1.1", "host3", ClientSourceHostsFile) </s> add b, e = clients.AddHost("1.1.1.1", "host3", ClientSourceHostsFile) </s> remove b, e = clientAddHost("1.1.1.1", "host2", ClientSourceARP) </s> add b, e = clients.AddHost("1.1.1.1", "host2", ClientSourceARP) </s> remove b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> add b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> remove if clientExists("1.2.3.4") { t.Fatalf("clientExists") </s> add if clients.Exists("1.2.3.4") { t.Fatalf("Exists") </s> remove if !clientExists("1.1.1.1") { t.Fatalf("clientExists #1") </s> add if !clients.Exists("1.1.1.1") { t.Fatalf("Exists #1")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/clients_test.go
clients clientsContainer
<mask> runningAsService bool <mask> disableUpdate bool // If set, don't check for updates <mask> appSignalChannel chan os.Signal <mask> <mask> BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to <mask> BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server <mask> AuthName string `yaml:"auth_name"` // AuthName is the basic auth username <mask> AuthPass string `yaml:"auth_pass"` // AuthPass is the basic auth password </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove func clientsGetList() map[string]*Client { </s> add // GetList returns the pointer to clients list func (clients *clientsContainer) GetList() map[string]*Client { </s> remove func clientAddHost(ip, host string, source clientSource) (bool, error) { </s> add func (clients *clientsContainer) AddHost(ip, host string, source clientSource) (bool, error) { </s> remove // Add new IP -> Host pair </s> add // AddHost adds new IP -> Host pair </s> remove clientsInit() </s> add config.clients.Init() </s> remove func clientsAddFromSystemARP() { </s> add func (clients *clientsContainer) addFromSystemARP() {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/config.go
_, err = config.clients.Add(cli)
<mask> ParentalEnabled: cy.ParentalEnabled, <mask> SafeSearchEnabled: cy.SafeSearchEnabled, <mask> SafeBrowsingEnabled: cy.SafeBrowsingEnabled, <mask> } <mask> _, err = clientAdd(cli) <mask> if err != nil { <mask> log.Tracef("clientAdd: %s", err) <mask> } <mask> } <mask> config.Clients = nil </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove var dj clientUpdateJSON </s> add var dj updateJSON </s> remove err = clientUpdate(dj.Name, *c) </s> add err = config.clients.Update(dj.Name, *c) </s> remove ok, err := clientAdd(*c) </s> add ok, err := config.clients.Add(*c) </s> remove func clientUpdate(name string, c Client) error { err := clientCheck(&c) </s> add func (clients *clientsContainer) Update(name string, c Client) error { err := c.check() </s> remove if !clientDel(cj.Name) { </s> add if !config.clients.Del(cj.Name) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/config.go
clientsList := config.clients.GetList()
<mask> func (c *configuration) write() error { <mask> c.Lock() <mask> defer c.Unlock() <mask> <mask> clientsList := clientsGetList() <mask> for _, cli := range clientsList { <mask> ip := cli.IP <mask> if len(cli.MAC) != 0 { <mask> ip = "" <mask> } </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove clients.lock.Lock() for _, c := range clients.list { </s> add config.clients.lock.Lock() for _, c := range config.clients.list { </s> remove func clientCheck(c *Client) error { </s> add func (c *Client) check() error { </s> remove for ip, ch := range clients.ipHost { </s> add for ip, ch := range config.clients.ipHost { </s> remove func clientExists(ip string) bool { </s> add // Exists checks if client with this IP already exists func (clients *clientsContainer) Exists(ip string) bool { </s> remove // Search for a client by IP func clientFind(ip string) (Client, bool) { </s> add // Find searches for a client by IP func (clients *clientsContainer) Find(ip string) (Client, bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/config.go
if config.clients.Exists(ip) {
<mask> return dnsServer != nil && dnsServer.IsRunning() <mask> } <mask> <mask> func beginAsyncRDNS(ip string) { <mask> if clientExists(ip) { <mask> return <mask> } <mask> <mask> // add IP to rdnsIP, if not exists <mask> dnsctx.rdnsLock.Lock() </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove func clientExists(ip string) bool { </s> add // Exists checks if client with this IP already exists func (clients *clientsContainer) Exists(ip string) bool { </s> remove func clientsGetList() map[string]*Client { </s> add // GetList returns the pointer to clients list func (clients *clientsContainer) GetList() map[string]*Client { </s> remove func clientCheck(c *Client) error { </s> add func (c *Client) check() error { </s> remove if !clientDel(cj.Name) { </s> add if !config.clients.Del(cj.Name) { </s> remove // Search for a client by IP func clientFind(ip string) (Client, bool) { </s> add // Find searches for a client by IP func (clients *clientsContainer) Find(ip string) (Client, bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/dns.go
_, _ = config.clients.AddHost(ip, host, ClientSourceRDNS)
<mask> dnsctx.rdnsLock.Lock() <mask> delete(dnsctx.rdnsIP, ip) <mask> dnsctx.rdnsLock.Unlock() <mask> <mask> _, _ = clientAddHost(ip, host, ClientSourceRDNS) <mask> } <mask> } <mask> <mask> func onDNSRequest(d *proxy.DNSContext) { <mask> qType := d.Req.Question[0].Qtype </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove ok, e := clientAddHost(ip, host, ClientSourceARP) </s> add ok, e := clients.AddHost(ip, host, ClientSourceARP) </s> remove b, e = clientAddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> add b, e = clients.AddHost("1.1.1.1", "host1", ClientSourceRDNS) </s> remove _, err = clientAdd(cli) </s> add _, err = config.clients.Add(cli) </s> remove clientsList := clientsGetList() </s> add clientsList := config.clients.GetList() </s> remove if clientExists(ip) { </s> add if config.clients.Exists(ip) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/dns.go
c, ok := config.clients.Find(clientAddr)
<mask> } <mask> <mask> // If a client has his own settings, apply them <mask> func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSettings) { <mask> c, ok := clientFind(clientAddr) <mask> if !ok || !c.UseOwnSettings { <mask> return <mask> } <mask> <mask> log.Debug("Using settings for client with IP %s", clientAddr) </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove // Search for a client by IP func clientFind(ip string) (Client, bool) { </s> add // Find searches for a client by IP func (clients *clientsContainer) Find(ip string) (Client, bool) { </s> remove // Remove a client func clientDel(name string) bool { </s> add // Del removes a client func (clients *clientsContainer) Del(name string) bool { </s> remove func clientUpdate(name string, c Client) error { err := clientCheck(&c) </s> add func (clients *clientsContainer) Update(name string, c Client) error { err := c.check() </s> remove func clientExists(ip string) bool { </s> add // Exists checks if client with this IP already exists func (clients *clientsContainer) Exists(ip string) bool { </s> remove func clientAdd(c Client) (bool, error) { e := clientCheck(&c) </s> add func (clients *clientsContainer) Add(c Client) (bool, error) { e := c.check()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/dns.go
config.clients.Init()
<mask> cleanupAlways() <mask> os.Exit(0) <mask> }() <mask> <mask> clientsInit() <mask> <mask> if !config.firstRun { <mask> // Do the upgrade if necessary <mask> err := upgradeConfig() <mask> if err != nil { </s> * clients: move container object to "config" Now the functions use parameter, not a global object. </s> remove ok, err := clientAdd(*c) </s> add ok, err := config.clients.Add(*c) </s> remove func clientUpdate(name string, c Client) error { err := clientCheck(&c) </s> add func (clients *clientsContainer) Update(name string, c Client) error { err := c.check() </s> remove err = clientUpdate(dj.Name, *c) </s> add err = config.clients.Update(dj.Name, *c) </s> remove _, err = clientAdd(cli) </s> add _, err = config.clients.Add(cli) </s> remove var dj clientUpdateJSON </s> add var dj updateJSON
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d51f43e27a5b664be5da299ea6f8c73872ef1a9e
home/home.go
return s.queryLog.flushLogBuffer(true)
<mask> s.dnsFilter = nil <mask> } <mask> <mask> // flush remainder to file <mask> return s.queryLog.flushLogBuffer() <mask> } <mask> <mask> // IsRunning returns true if the DNS server is running <mask> func (s *Server) IsRunning() bool { <mask> s.RLock() </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock() </s> remove go func() { err := l.flushToFile(flushBuffer) if err != nil { log.Printf("Failed to flush the query log: %s", err) } }() </s> add go l.flushLogBuffer(false) </s> remove if len(flushBuffer) > 0 { </s> add if needFlush {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/dnsforward.go
fileFlushLock sync.Mutex // synchronize a file-flushing goroutine and main thread flushPending bool // don't start another goroutine while the previous one is still running
<mask> logBufferLock sync.RWMutex <mask> logBuffer []*logEntry <mask> <mask> queryLogCache []*logEntry <mask> queryLogLock sync.RWMutex <mask> } <mask> </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove var flushBuffer []*logEntry </s> add </s> remove if len(l.logBuffer) >= logBufferCap { flushBuffer = l.logBuffer l.logBuffer = nil </s> add needFlush := false if !l.flushPending { needFlush = len(l.logBuffer) >= logBufferCap if needFlush { l.flushPending = true } </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true) </s> remove go func() { err := l.flushToFile(flushBuffer) if err != nil { log.Printf("Failed to flush the query log: %s", err) } }() </s> add go l.flushLogBuffer(false)
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog.go
<mask> Elapsed: elapsed, <mask> IP: ip, <mask> Upstream: upstream, <mask> } <mask> var flushBuffer []*logEntry <mask> <mask> l.logBufferLock.Lock() <mask> l.logBuffer = append(l.logBuffer, &entry) <mask> if len(l.logBuffer) >= logBufferCap { <mask> flushBuffer = l.logBuffer </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove if len(l.logBuffer) >= logBufferCap { flushBuffer = l.logBuffer l.logBuffer = nil </s> add needFlush := false if !l.flushPending { needFlush = len(l.logBuffer) >= logBufferCap if needFlush { l.flushPending = true } </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock() </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog.go
needFlush := false if !l.flushPending { needFlush = len(l.logBuffer) >= logBufferCap if needFlush { l.flushPending = true }
<mask> var flushBuffer []*logEntry <mask> <mask> l.logBufferLock.Lock() <mask> l.logBuffer = append(l.logBuffer, &entry) <mask> if len(l.logBuffer) >= logBufferCap { <mask> flushBuffer = l.logBuffer <mask> l.logBuffer = nil <mask> } <mask> l.logBufferLock.Unlock() <mask> l.queryLogLock.Lock() <mask> l.queryLogCache = append(l.queryLogCache, &entry) <mask> if len(l.queryLogCache) > queryLogSize { </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove var flushBuffer []*logEntry </s> add </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock() </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog.go
if needFlush {
<mask> // don't do failure, just log <mask> } <mask> <mask> // if buffer needs to be flushed to disk, do it now <mask> if len(flushBuffer) > 0 { <mask> // write to file <mask> // do it in separate goroutine -- we are stalling DNS response this whole time <mask> go func() { <mask> err := l.flushToFile(flushBuffer) <mask> if err != nil { </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove go func() { err := l.flushToFile(flushBuffer) if err != nil { log.Printf("Failed to flush the query log: %s", err) } }() </s> add go l.flushLogBuffer(false) </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true) </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog.go
go l.flushLogBuffer(false)
<mask> // if buffer needs to be flushed to disk, do it now <mask> if len(flushBuffer) > 0 { <mask> // write to file <mask> // do it in separate goroutine -- we are stalling DNS response this whole time <mask> go func() { <mask> err := l.flushToFile(flushBuffer) <mask> if err != nil { <mask> log.Printf("Failed to flush the query log: %s", err) <mask> } <mask> }() <mask> } <mask> <mask> return &entry <mask> } <mask> </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove if len(flushBuffer) > 0 { </s> add if needFlush { </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true) </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog.go
func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock()
<mask> <mask> const enableGzip = false <mask> <mask> // flushLogBuffer flushes the current buffer to file and resets the current buffer <mask> func (l *queryLog) flushLogBuffer() error { <mask> // flush remainder to file <mask> l.logBufferLock.Lock() <mask> flushBuffer := l.logBuffer <mask> l.logBuffer = nil <mask> l.logBufferLock.Unlock() </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true) </s> remove go func() { err := l.flushToFile(flushBuffer) if err != nil { log.Printf("Failed to flush the query log: %s", err) } }() </s> add go l.flushLogBuffer(false) </s> remove if len(flushBuffer) > 0 { </s> add if needFlush {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog_file.go
needFlush := len(l.logBuffer) >= logBufferCap if !needFlush && !fullFlush { l.logBufferLock.Unlock() return nil }
<mask> defer l.fileFlushLock.Unlock() <mask> <mask> // flush remainder to file <mask> l.logBufferLock.Lock() <mask> flushBuffer := l.logBuffer <mask> l.logBuffer = nil <mask> l.flushPending = false <mask> l.logBufferLock.Unlock() <mask> err := l.flushToFile(flushBuffer) <mask> if err != nil { </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock() </s> remove if len(l.logBuffer) >= logBufferCap { flushBuffer = l.logBuffer l.logBuffer = nil </s> add needFlush := false if !l.flushPending { needFlush = len(l.logBuffer) >= logBufferCap if needFlush { l.flushPending = true } </s> remove if len(flushBuffer) > 0 { </s> add if needFlush { </s> remove return s.queryLog.flushLogBuffer() </s> add return s.queryLog.flushLogBuffer(true)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog_file.go
l.flushPending = false
<mask> return nil <mask> } <mask> flushBuffer := l.logBuffer <mask> l.logBuffer = nil <mask> l.logBufferLock.Unlock() <mask> err := l.flushToFile(flushBuffer) <mask> if err != nil { <mask> log.Error("Saving querylog to file failed: %s", err) <mask> return err </s> - dns query log: robust file flushing mechanism Before this patch we could exit the process without waiting for file writing task to complete. As a result a file could become corrupted or a large chunk of data could be missing. Now the main thread either waits until file writing task completes or it writes log buffer to file itself. </s> remove go func() { err := l.flushToFile(flushBuffer) if err != nil { log.Printf("Failed to flush the query log: %s", err) } }() </s> add go l.flushLogBuffer(false) </s> remove if len(l.logBuffer) >= logBufferCap { flushBuffer = l.logBuffer l.logBuffer = nil </s> add needFlush := false if !l.flushPending { needFlush = len(l.logBuffer) >= logBufferCap if needFlush { l.flushPending = true } </s> remove if len(flushBuffer) > 0 { </s> add if needFlush { </s> remove func (l *queryLog) flushLogBuffer() error { </s> add func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock() defer l.fileFlushLock.Unlock()
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d5f6dd1a46446ebb440811691a6ee8ce2443320d
dnsforward/querylog_file.go
// handleDHCPInterfaces is the handler for the GET /control/dhcp/interfaces HTTP // API.
<mask> Addrs6 []netip.Addr `json:"ipv6_addresses"` <mask> } <mask> <mask> func (s *server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) { <mask> resp := map[string]netInterfaceJSON{} <mask> <mask> ifaces, err := net.Interfaces() <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove response := map[string]netInterfaceJSON{} </s> add resp := map[string]netInterfaceJSON{} </s> remove err := json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { </s> add // handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) { </s> remove err = json.NewEncoder(w).Encode(response) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with available interfaces: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove response[iface.Name] = jsonIface </s> add resp[iface.Name] = jsonIface
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/dhcpd/http_unix.go
resp := map[string]netInterfaceJSON{}
<mask> Addrs6 []netip.Addr `json:"ipv6_addresses"` <mask> } <mask> <mask> func (s *server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) { <mask> response := map[string]netInterfaceJSON{} <mask> <mask> ifaces, err := net.Interfaces() <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) <mask> </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove err := json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { </s> add // handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) { </s> remove err = json.NewEncoder(w).Encode(response) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with available interfaces: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove response[iface.Name] = jsonIface </s> add resp[iface.Name] = jsonIface
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/dhcpd/http_unix.go
resp[iface.Name] = jsonIface
<mask> } <mask> } <mask> if len(jsonIface.Addrs4)+len(jsonIface.Addrs6) != 0 { <mask> jsonIface.GatewayIP = aghnet.GatewayIP(iface.Name) <mask> response[iface.Name] = jsonIface <mask> } <mask> } <mask> <mask> err = json.NewEncoder(w).Encode(response) <mask> if err != nil { </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove err = json.NewEncoder(w).Encode(response) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with available interfaces: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove err := json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { </s> add // handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) { </s> remove response := map[string]netInterfaceJSON{} </s> add resp := map[string]netInterfaceJSON{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/dhcpd/http_unix.go
_ = aghhttp.WriteJSONResponse(w, r, resp)
<mask> response[iface.Name] = jsonIface <mask> } <mask> } <mask> <mask> err = json.NewEncoder(w).Encode(response) <mask> if err != nil { <mask> aghhttp.Error( <mask> r, <mask> w, <mask> http.StatusInternalServerError, <mask> "Failed to marshal json with available interfaces: %s", <mask> err, <mask> ) <mask> } <mask> } <mask> <mask> // dhcpSearchOtherResult contains information about other DHCP server for <mask> // specific network interface. <mask> type dhcpSearchOtherResult struct { </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove response[iface.Name] = jsonIface </s> add resp[iface.Name] = jsonIface </s> remove err := json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { </s> add // handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) { </s> remove response := map[string]netInterfaceJSON{} </s> add resp := map[string]netInterfaceJSON{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/dhcpd/http_unix.go
Context.mux.HandleFunc("/control/version.json", postInstall(optionalAuth(handleVersionJSON)))
<mask> func registerControlHandlers() { <mask> httpRegister(http.MethodGet, "/control/status", handleStatus) <mask> httpRegister(http.MethodPost, "/control/i18n/change_language", handleI18nChangeLanguage) <mask> httpRegister(http.MethodGet, "/control/i18n/current_language", handleI18nCurrentLanguage) <mask> Context.mux.HandleFunc("/control/version.json", postInstall(optionalAuth(handleGetVersionJSON))) <mask> httpRegister(http.MethodPost, "/control/update", handleUpdate) <mask> httpRegister(http.MethodGet, "/control/profile", handleGetProfile) <mask> httpRegister(http.MethodPut, "/control/profile/update", handlePutProfile) <mask> <mask> // No auth is necessary for DoH/DoT configurations </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { </s> add // handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) { </s> remove err = json.NewEncoder(w).Encode(response) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with available interfaces: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove err := json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove response := map[string]netInterfaceJSON{} </s> add resp := map[string]netInterfaceJSON{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/home/control.go
// handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) {
<mask> error <mask> Temporary() (ok bool) <mask> } <mask> <mask> // Get the latest available version from the Internet <mask> func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { <mask> resp := &versionResponse{} <mask> if Context.disableUpdate { <mask> resp.Disabled = true <mask> err := json.NewEncoder(w).Encode(resp) <mask> if err != nil { </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove err := json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove response := map[string]netInterfaceJSON{} </s> add resp := map[string]netInterfaceJSON{} </s> remove response[iface.Name] = jsonIface </s> add resp[iface.Name] = jsonIface </s> remove err = json.NewEncoder(w).Encode(response) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with available interfaces: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/home/controlupdate.go
_ = aghhttp.WriteJSONResponse(w, r, resp)
<mask> func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { <mask> resp := &versionResponse{} <mask> if Context.disableUpdate { <mask> resp.Disabled = true <mask> err := json.NewEncoder(w).Encode(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) <mask> } <mask> <mask> return <mask> } <mask> <mask> req := &struct { </s> Pull request 1838: 5716-content-type Updates #5716. Squashed commit of the following: commit 584e6771c82b92857e3c13232e942cad5c183682 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 14:54:43 2023 +0300 all: fix content types </s> remove // Get the latest available version from the Internet func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { </s> add // handleVersionJSON is the handler for the POST /control/version.json HTTP API. // // TODO(a.garipov): Find out if this API used with a GET method by anyone. func handleVersionJSON(w http.ResponseWriter, r *http.Request) { </s> remove response := map[string]netInterfaceJSON{} </s> add resp := map[string]netInterfaceJSON{} </s> remove response[iface.Name] = jsonIface </s> add resp[iface.Name] = jsonIface </s> remove err = json.NewEncoder(w).Encode(response) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with available interfaces: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6043e2352ba17ebe6eb57e045ce3fcbecc796c9
internal/home/controlupdate.go
<mask> defer s.RUnlock() <mask> return s.isRunning <mask> } <mask> <mask> // Restart - restart server <mask> func (s *Server) Restart() error { <mask> s.Lock() <mask> defer s.Unlock() <mask> log.Print("Start reconfiguring the server") <mask> err := s.stopInternal() <mask> if err != nil { <mask> return errorx.Decorate(err, "could not reconfigure the server") <mask> } <mask> err = s.startInternal() <mask> if err != nil { <mask> return errorx.Decorate(err, "could not reconfigure the server") <mask> } <mask> <mask> return nil <mask> } <mask> <mask> // Reconfigure applies the new configuration to the DNS server <mask> func (s *Server) Reconfigure(config *ServerConfig) error { <mask> s.Lock() <mask> defer s.Unlock() <mask> </s> - DNS: configuration settings were not applied until full restart </s> remove err = s.Restart() </s> add err = s.Reconfigure(nil) </s> remove err = s.Restart() </s> add err = s.Reconfigure(nil)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d65cdd4544efdecb9bbe36e411c0bbcb6475ba94
dnsforward/dnsforward.go
err = s.Reconfigure(nil)
<mask> s.Unlock() <mask> s.conf.ConfigModified() <mask> <mask> if restart { <mask> err = s.Restart() <mask> if err != nil { <mask> httpError(r, w, http.StatusInternalServerError, "%s", err) <mask> return <mask> } <mask> } </s> - DNS: configuration settings were not applied until full restart </s> remove // Restart - restart server func (s *Server) Restart() error { s.Lock() defer s.Unlock() log.Print("Start reconfiguring the server") err := s.stopInternal() if err != nil { return errorx.Decorate(err, "could not reconfigure the server") } err = s.startInternal() if err != nil { return errorx.Decorate(err, "could not reconfigure the server") } return nil } </s> add </s> remove err = s.Restart() </s> add err = s.Reconfigure(nil)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d65cdd4544efdecb9bbe36e411c0bbcb6475ba94
dnsforward/dnsforward_http.go
err = s.Reconfigure(nil)
<mask> s.conf.AllServers = newconf.AllServers <mask> s.Unlock() <mask> s.conf.ConfigModified() <mask> <mask> err = s.Restart() <mask> if err != nil { <mask> httpError(r, w, http.StatusInternalServerError, "%s", err) <mask> return <mask> } <mask> } </s> - DNS: configuration settings were not applied until full restart </s> remove // Restart - restart server func (s *Server) Restart() error { s.Lock() defer s.Unlock() log.Print("Start reconfiguring the server") err := s.stopInternal() if err != nil { return errorx.Decorate(err, "could not reconfigure the server") } err = s.startInternal() if err != nil { return errorx.Decorate(err, "could not reconfigure the server") } return nil } </s> add </s> remove err = s.Restart() </s> add err = s.Reconfigure(nil)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d65cdd4544efdecb9bbe36e411c0bbcb6475ba94
dnsforward/dnsforward_http.go
ok, err := f.update()
<mask> f.ID = assignUniqueFilterID() <mask> f.Enabled = true <mask> <mask> // Download the filter contents <mask> ok, err := f.update(true) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "Couldn't fetch filter from url %s: %s", f.URL, err) <mask> return <mask> } <mask> if f.RulesCount == 0 { </s> - filter: update 'LastUpdated' field and 'last-modified' file time even when filter's content is up to date * filters: refactor: don't check 'LastUpdated' inside update() </s> remove updated, err := filter.update(force) </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { continue } updated, err := filter.update() </s> remove // Checks for filters updates // If "force" is true -- does not check the filter's LastUpdated field // Call "save" to persist the filter contents func (filter *filter) update(force bool) (bool, error) { if !force && time.Since(filter.LastUpdated) <= updatePeriod { return false, nil } </s> add // Perform upgrade on a filter func (filter *filter) update() (bool, error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d664a9de1d27a375cb7ae42dad0a5db88b4d18bc
control.go
if !force && time.Since(filter.LastUpdated) <= updatePeriod { continue } updated, err := filter.update()
<mask> if !filter.Enabled { <mask> continue <mask> } <mask> <mask> updated, err := filter.update(force) <mask> if err != nil { <mask> log.Printf("Failed to update filter %s: %s\n", filter.URL, err) <mask> continue <mask> } <mask> if updated { </s> - filter: update 'LastUpdated' field and 'last-modified' file time even when filter's content is up to date * filters: refactor: don't check 'LastUpdated' inside update() </s> remove ok, err := f.update(true) </s> add ok, err := f.update() </s> remove // Checks for filters updates // If "force" is true -- does not check the filter's LastUpdated field // Call "save" to persist the filter contents func (filter *filter) update(force bool) (bool, error) { if !force && time.Since(filter.LastUpdated) <= updatePeriod { return false, nil } </s> add // Perform upgrade on a filter func (filter *filter) update() (bool, error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d664a9de1d27a375cb7ae42dad0a5db88b4d18bc
filter.go
} else { mtime := time.Now() os.Chtimes(filter.Path(), mtime, mtime) filter.LastUpdated = mtime
<mask> <mask> updateCount++ <mask> } <mask> } <mask> config.Unlock() <mask> <mask> if updateCount > 0 && isRunning() { <mask> err := reconfigureDNSServer() </s> - filter: update 'LastUpdated' field and 'last-modified' file time even when filter's content is up to date * filters: refactor: don't check 'LastUpdated' inside update() </s> remove updated, err := filter.update(force) </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { continue } updated, err := filter.update() </s> remove ok, err := f.update(true) </s> add ok, err := f.update() </s> remove // Checks for filters updates // If "force" is true -- does not check the filter's LastUpdated field // Call "save" to persist the filter contents func (filter *filter) update(force bool) (bool, error) { if !force && time.Since(filter.LastUpdated) <= updatePeriod { return false, nil } </s> add // Perform upgrade on a filter func (filter *filter) update() (bool, error) {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d664a9de1d27a375cb7ae42dad0a5db88b4d18bc
filter.go
// Perform upgrade on a filter func (filter *filter) update() (bool, error) {
<mask> <mask> return rulesCount, name, lines <mask> } <mask> <mask> // Checks for filters updates <mask> // If "force" is true -- does not check the filter's LastUpdated field <mask> // Call "save" to persist the filter contents <mask> func (filter *filter) update(force bool) (bool, error) { <mask> if !force && time.Since(filter.LastUpdated) <= updatePeriod { <mask> return false, nil <mask> } <mask> <mask> log.Tracef("Downloading update for filter %d from %s", filter.ID, filter.URL) <mask> <mask> resp, err := client.Get(filter.URL) <mask> if resp != nil && resp.Body != nil { <mask> defer resp.Body.Close() </s> - filter: update 'LastUpdated' field and 'last-modified' file time even when filter's content is up to date * filters: refactor: don't check 'LastUpdated' inside update() </s> remove updated, err := filter.update(force) </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { continue } updated, err := filter.update() </s> remove ok, err := f.update(true) </s> add ok, err := f.update()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d664a9de1d27a375cb7ae42dad0a5db88b4d18bc
filter.go
hostname := p.ParseOptions()[dhcp4.OptionHostName] lease := &Lease{HWAddr: hwaddr, Hostname: string(hostname)}
<mask> hwaddrCOW := p.CHAddr() <mask> hwaddr := make(net.HardwareAddr, len(hwaddrCOW)) <mask> copy(hwaddr, hwaddrCOW) <mask> // not assigned a lease, create new one, find IP from LRU <mask> log.Tracef("Lease not found for %s: creating new one", hwaddr) <mask> ip, err := s.findFreeIP(hwaddr) <mask> if err != nil { <mask> i := s.findExpiredLease() <mask> if i < 0 { <mask> return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) </s> + dhcp: handle lease expiration </s> remove return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) </s> add i := s.findExpiredLease() if i < 0 { return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) } log.Tracef("Assigning IP address %s to %s (lease for %s expired at %s)", s.leases[i].IP, hwaddr, s.leases[i].HWAddr, s.leases[i].Expiry) lease.IP = s.leases[i].IP s.Lock() s.leases[i] = lease s.Unlock() s.reserveIP(lease.IP, hwaddr) return lease, nil </s> remove hostname := p.ParseOptions()[dhcp4.OptionHostName] lease := &Lease{HWAddr: hwaddr, IP: ip, Hostname: string(hostname)} </s> add lease.IP = ip
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d68600c5d03b73d94f380f5442c22ddc8f755d9a
dhcpd/dhcpd.go
i := s.findExpiredLease() if i < 0 { return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) } log.Tracef("Assigning IP address %s to %s (lease for %s expired at %s)", s.leases[i].IP, hwaddr, s.leases[i].HWAddr, s.leases[i].Expiry) lease.IP = s.leases[i].IP s.Lock() s.leases[i] = lease s.Unlock() s.reserveIP(lease.IP, hwaddr) return lease, nil
<mask> // not assigned a lease, create new one, find IP from LRU <mask> log.Tracef("Lease not found for %s: creating new one", hwaddr) <mask> ip, err := s.findFreeIP(hwaddr) <mask> if err != nil { <mask> return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) <mask> } <mask> log.Tracef("Assigning to %s IP address %s", hwaddr, ip.String()) <mask> hostname := p.ParseOptions()[dhcp4.OptionHostName] <mask> lease := &Lease{HWAddr: hwaddr, IP: ip, Hostname: string(hostname)} <mask> s.Lock() </s> + dhcp: handle lease expiration </s> remove hostname := p.ParseOptions()[dhcp4.OptionHostName] lease := &Lease{HWAddr: hwaddr, IP: ip, Hostname: string(hostname)} </s> add lease.IP = ip
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d68600c5d03b73d94f380f5442c22ddc8f755d9a
dhcpd/dhcpd.go
lease.IP = ip
<mask> if err != nil { <mask> return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) <mask> } <mask> log.Tracef("Assigning to %s IP address %s", hwaddr, ip.String()) <mask> hostname := p.ParseOptions()[dhcp4.OptionHostName] <mask> lease := &Lease{HWAddr: hwaddr, IP: ip, Hostname: string(hostname)} <mask> s.Lock() <mask> s.leases = append(s.leases, lease) <mask> s.Unlock() <mask> return lease, nil <mask> } </s> + dhcp: handle lease expiration </s> remove return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) </s> add i := s.findExpiredLease() if i < 0 { return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) } log.Tracef("Assigning IP address %s to %s (lease for %s expired at %s)", s.leases[i].IP, hwaddr, s.leases[i].HWAddr, s.leases[i].Expiry) lease.IP = s.leases[i].IP s.Lock() s.leases[i] = lease s.Unlock() s.reserveIP(lease.IP, hwaddr) return lease, nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d68600c5d03b73d94f380f5442c22ddc8f755d9a
dhcpd/dhcpd.go
// Find an expired lease and return its index or -1 func (s *Server) findExpiredLease() int { now := time.Now().Unix() for i, lease := range s.leases { if lease.Expiry.Unix() <= now { return i } } return -1 }
<mask> } <mask> <mask> func (s *Server) findFreeIP(hwaddr net.HardwareAddr) (net.IP, error) { <mask> // if IP pool is nil, lazy initialize it <mask> if s.IPpool == nil { <mask> s.IPpool = make(map[[4]byte]net.HardwareAddr) <mask> } </s> + dhcp: handle lease expiration </s> remove hostname := p.ParseOptions()[dhcp4.OptionHostName] lease := &Lease{HWAddr: hwaddr, IP: ip, Hostname: string(hostname)} </s> add lease.IP = ip </s> remove return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) </s> add i := s.findExpiredLease() if i < 0 { return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) } log.Tracef("Assigning IP address %s to %s (lease for %s expired at %s)", s.leases[i].IP, hwaddr, s.leases[i].HWAddr, s.leases[i].Expiry) lease.IP = s.leases[i].IP s.Lock() s.leases[i] = lease s.Unlock() s.reserveIP(lease.IP, hwaddr) return lease, nil
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d68600c5d03b73d94f380f5442c22ddc8f755d9a
dhcpd/dhcpd.go
github.com/AdguardTeam/dnsproxy v0.50.0
<mask> <mask> go 1.19 <mask> <mask> require ( <mask> github.com/AdguardTeam/dnsproxy v0.49.2 <mask> github.com/AdguardTeam/golibs v0.13.2 <mask> github.com/AdguardTeam/urlfilter v0.16.1 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/ameshkov/dnscrypt/v2 v2.2.7 <mask> github.com/digineo/go-ipset/v2 v2.2.1 </s> Pull request 1862: upd-proxy Merge in DNS/adguard-home from upd-proxy to master Squashed commit of the following: commit b258697cdac6a6ac83c94814dbe8551c5685fa3b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jun 6 13:22:17 2023 +0300 all: upd proxy </s> remove github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= </s> add github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo= github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g= </s> remove github.com/AdguardTeam/dnsproxy v0.49.2 h1:DAFhLpz8KOvw9r6F3H1jK/JFYKzXY2RkqWSjkfwZMqU= github.com/AdguardTeam/dnsproxy v0.49.2/go.mod h1:Y7g7jRTd/u7+KJ/QvnGI2PCE8vnisp6EsW47/Sz0DZw= </s> add github.com/AdguardTeam/dnsproxy v0.50.0 h1:gqImxUMBVS8VQmGdXw0U7MjJNVzXkYaZ9NM5TKl3JBU= github.com/AdguardTeam/dnsproxy v0.50.0/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8= </s> remove github.com/quic-go/quic-go v0.33.0 </s> add github.com/quic-go/quic-go v0.35.1
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6fe0bd740f5e75b9b2757c1d322fdb3f73ae1d5
go.mod
github.com/quic-go/quic-go v0.35.1
<mask> // TODO(a.garipov): This package is deprecated; find a new one or use our <mask> // own code for that. Perhaps, use gopacket. <mask> github.com/mdlayher/raw v0.1.0 <mask> github.com/miekg/dns v1.1.53 <mask> github.com/quic-go/quic-go v0.33.0 <mask> github.com/stretchr/testify v1.8.2 <mask> github.com/ti-mo/netfilter v0.5.0 <mask> go.etcd.io/bbolt v1.3.7 <mask> golang.org/x/crypto v0.8.0 <mask> golang.org/x/exp v0.0.0-20230321023759-10a507213a29 </s> Pull request 1862: upd-proxy Merge in DNS/adguard-home from upd-proxy to master Squashed commit of the following: commit b258697cdac6a6ac83c94814dbe8551c5685fa3b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jun 6 13:22:17 2023 +0300 all: upd proxy </s> remove github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= </s> add github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo= github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g= </s> remove github.com/AdguardTeam/dnsproxy v0.49.2 h1:DAFhLpz8KOvw9r6F3H1jK/JFYKzXY2RkqWSjkfwZMqU= github.com/AdguardTeam/dnsproxy v0.49.2/go.mod h1:Y7g7jRTd/u7+KJ/QvnGI2PCE8vnisp6EsW47/Sz0DZw= </s> add github.com/AdguardTeam/dnsproxy v0.50.0 h1:gqImxUMBVS8VQmGdXw0U7MjJNVzXkYaZ9NM5TKl3JBU= github.com/AdguardTeam/dnsproxy v0.50.0/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8= </s> remove github.com/AdguardTeam/dnsproxy v0.49.2 </s> add github.com/AdguardTeam/dnsproxy v0.50.0
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6fe0bd740f5e75b9b2757c1d322fdb3f73ae1d5
go.mod
github.com/AdguardTeam/dnsproxy v0.50.0 h1:gqImxUMBVS8VQmGdXw0U7MjJNVzXkYaZ9NM5TKl3JBU= github.com/AdguardTeam/dnsproxy v0.50.0/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8=
<mask> github.com/AdguardTeam/dnsproxy v0.49.2 h1:DAFhLpz8KOvw9r6F3H1jK/JFYKzXY2RkqWSjkfwZMqU= <mask> github.com/AdguardTeam/dnsproxy v0.49.2/go.mod h1:Y7g7jRTd/u7+KJ/QvnGI2PCE8vnisp6EsW47/Sz0DZw= <mask> github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= <mask> github.com/AdguardTeam/golibs v0.13.2 h1:BPASsyQKmb+b8VnvsNOHp7bKfcZl9Z+Z2UhPjOiupSc= <mask> github.com/AdguardTeam/golibs v0.13.2/go.mod h1:7ylQLv2Lqsc3UW3jHoITynYk6Y1tYtgEMkR09ppfsN8= <mask> github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= </s> Pull request 1862: upd-proxy Merge in DNS/adguard-home from upd-proxy to master Squashed commit of the following: commit b258697cdac6a6ac83c94814dbe8551c5685fa3b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jun 6 13:22:17 2023 +0300 all: upd proxy </s> remove github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= </s> add github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo= github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g= </s> remove github.com/quic-go/quic-go v0.33.0 </s> add github.com/quic-go/quic-go v0.35.1 </s> remove github.com/AdguardTeam/dnsproxy v0.49.2 </s> add github.com/AdguardTeam/dnsproxy v0.50.0
[ "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6fe0bd740f5e75b9b2757c1d322fdb3f73ae1d5
go.sum
github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62poo= github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g=
<mask> github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= <mask> github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= <mask> github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= <mask> github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= <mask> github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= <mask> github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= <mask> github.com/shirou/gopsutil/v3 v3.21.8 h1:nKct+uP0TV8DjjNiHanKf8SAuub+GNsbrOtM9Nl9biA= <mask> github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ= <mask> github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= <mask> github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= <mask> github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= </s> Pull request 1862: upd-proxy Merge in DNS/adguard-home from upd-proxy to master Squashed commit of the following: commit b258697cdac6a6ac83c94814dbe8551c5685fa3b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jun 6 13:22:17 2023 +0300 all: upd proxy </s> remove github.com/AdguardTeam/dnsproxy v0.49.2 h1:DAFhLpz8KOvw9r6F3H1jK/JFYKzXY2RkqWSjkfwZMqU= github.com/AdguardTeam/dnsproxy v0.49.2/go.mod h1:Y7g7jRTd/u7+KJ/QvnGI2PCE8vnisp6EsW47/Sz0DZw= </s> add github.com/AdguardTeam/dnsproxy v0.50.0 h1:gqImxUMBVS8VQmGdXw0U7MjJNVzXkYaZ9NM5TKl3JBU= github.com/AdguardTeam/dnsproxy v0.50.0/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8= </s> remove github.com/quic-go/quic-go v0.33.0 </s> add github.com/quic-go/quic-go v0.35.1 </s> remove github.com/AdguardTeam/dnsproxy v0.49.2 </s> add github.com/AdguardTeam/dnsproxy v0.50.0
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d6fe0bd740f5e75b9b2757c1d322fdb3f73ae1d5
go.sum
// IsValidHostOuterRune returns true if r is a valid initial or final rune for // a hostname label. func IsValidHostOuterRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || IsValidHostOuterRune(r) }
<mask> "golang.org/x/net/idna" <mask> ) <mask> <mask> // ValidateHardwareAddress returns an error if hwa is not a valid EUI-48, <mask> // EUI-64, or 20-octet InfiniBand link-layer address. <mask> func ValidateHardwareAddress(hwa net.HardwareAddr) (err error) { <mask> defer agherr.Annotate("validating hardware address %q: %w", &err, hwa) </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen { </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove } else if len(label) == 0 { </s> add } else if l == 0 {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
<mask> const maxDomainNameLen = 253 <mask> <mask> const invalidCharMsg = "invalid char %q at index %d in %q" <mask> <mask> // isValidHostFirstRune returns true if r is a valid first rune for a hostname <mask> // label. <mask> func isValidHostFirstRune(r rune) (ok bool) { <mask> return (r >= 'a' && r <= 'z') || <mask> (r >= 'A' && r <= 'Z') || <mask> (r >= '0' && r <= '9') <mask> } <mask> <mask> // isValidHostRune returns true if r is a valid rune for a hostname label. <mask> func isValidHostRune(r rune) (ok bool) { <mask> return r == '-' || isValidHostFirstRune(r) <mask> } <mask> <mask> // ValidateDomainNameLabel returns an error if label is not a valid label of <mask> // a domain name. <mask> func ValidateDomainNameLabel(label string) (err error) { <mask> if len(label) > maxDomainLabelLen { <mask> return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen { </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove // Return TRUE if host names doesn't contain disallowed characters func isHostnameOK(hostname string) bool { for _, c := range hostname { if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-') { log.Debug("dns: skipping invalid hostname %s from DHCP", hostname) return false } } return true } </s> add </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
l := len(label) if l > maxDomainLabelLen {
<mask> <mask> // ValidateDomainNameLabel returns an error if label is not a valid label of <mask> // a domain name. <mask> func ValidateDomainNameLabel(label string) (err error) { <mask> if len(label) > maxDomainLabelLen { <mask> return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) <mask> } else if len(label) == 0 { <mask> return agherr.Error("label is empty") <mask> } <mask> </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove if l == 0 || l > maxDomainNameLen { </s> add if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen { </s> remove if r := label[0]; !isValidHostFirstRune(rune(r)) { </s> add if r := label[0]; !IsValidHostOuterRune(rune(r)) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
} else if l == 0 {
<mask> // a domain name. <mask> func ValidateDomainNameLabel(label string) (err error) { <mask> if len(label) > maxDomainLabelLen { <mask> return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) <mask> } else if len(label) == 0 { <mask> return agherr.Error("label is empty") <mask> } <mask> <mask> if r := label[0]; !isValidHostFirstRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, 0, label) </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen { </s> remove if r := label[0]; !isValidHostFirstRune(rune(r)) { </s> add if r := label[0]; !IsValidHostOuterRune(rune(r)) { </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove if l == 0 || l > maxDomainNameLen { </s> add if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen { </s> remove for i, r := range label[1:] { </s> add for i, r := range label[1 : l-1] {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
if r := label[0]; !IsValidHostOuterRune(rune(r)) {
<mask> } else if len(label) == 0 { <mask> return agherr.Error("label is empty") <mask> } <mask> <mask> if r := label[0]; !isValidHostFirstRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, 0, label) <mask> } <mask> <mask> for i, r := range label[1:] { <mask> if !isValidHostRune(r) { </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove for i, r := range label[1:] { </s> add for i, r := range label[1 : l-1] { </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen { </s> remove if l == 0 || l > maxDomainNameLen { </s> add if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
} else if l == 1 { return nil
<mask> <mask> if r := label[0]; !IsValidHostOuterRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, 0, label) <mask> } <mask> <mask> for i, r := range label[1 : l-1] { <mask> if !isValidHostRune(r) { </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove for i, r := range label[1:] { </s> add for i, r := range label[1 : l-1] { </s> remove if r := label[0]; !isValidHostFirstRune(rune(r)) { </s> add if r := label[0]; !IsValidHostOuterRune(rune(r)) { </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove if l == 0 || l > maxDomainNameLen { </s> add if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
for i, r := range label[1 : l-1] {
<mask> if r := label[0]; !isValidHostFirstRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, 0, label) <mask> } <mask> <mask> for i, r := range label[1:] { <mask> if !isValidHostRune(r) { <mask> return fmt.Errorf(invalidCharMsg, r, i+1, label) <mask> } <mask> } <mask> </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove if r := label[0]; !isValidHostFirstRune(rune(r)) { </s> add if r := label[0]; !IsValidHostOuterRune(rune(r)) { </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove if l == 0 || l > maxDomainNameLen { </s> add if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
if r := label[l-1]; !IsValidHostOuterRune(rune(r)) { return fmt.Errorf(invalidCharMsg, r, l-1, label) }
<mask> } <mask> <mask> return nil <mask> } <mask> <mask> // ValidateDomainName validates the domain name in accordance to RFC 952, RFC <mask> // 1035, and with RFC-1123's inclusion of digits at the start of the host. It </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove // normalizeHostname normalizes and validates a hostname sent by the client. // // TODO(a.garipov): Add client hostname uniqueness validations and rename the // method to validateHostname. func (s *v4Server) normalizeHostname(name string) (norm string, err error) { </s> add // normalizeHostname normalizes a hostname sent by the client. func normalizeHostname(name string) (norm string, err error) { </s> remove // GenerateHostName generates the hostname from ip. In case of using IPv4 the </s> add // GenerateHostname generates the hostname from ip. In case of using IPv4 the </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove func GenerateHostName(ip net.IP) (hostname string) { </s> add func GenerateHostname(ip net.IP) (hostname string) {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen {
<mask> return err <mask> } <mask> <mask> l := len(name) <mask> if l == 0 || l > maxDomainNameLen { <mask> return fmt.Errorf("%q is too long, max: %d", name, maxDomainNameLen) <mask> } <mask> <mask> labels := strings.Split(name, ".") <mask> for i, l := range labels { </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen { </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove if len(l.Hostname) == 0 || !isHostnameOK(l.Hostname) { continue </s> add // TODO(a.garipov): Remove this after we're finished // with the client hostname validations in the DHCP // server code. err = aghnet.ValidateDomainName(l.Hostname) if err != nil { log.Debug( "dns: skipping invalid hostname %q from dhcp: %s", l.Hostname, err, )
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
// GenerateHostname generates the hostname from ip. In case of using IPv4 the
<mask> <mask> return string(hnData) <mask> } <mask> <mask> // GenerateHostName generates the hostname from ip. In case of using IPv4 the <mask> // result should be like: <mask> // <mask> // 192-168-10-1 <mask> // <mask> // In case of using IPv6, the result is like: </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove func GenerateHostName(ip net.IP) (hostname string) { </s> add func GenerateHostname(ip net.IP) (hostname string) { </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove // normalizeHostname normalizes and validates a hostname sent by the client. // // TODO(a.garipov): Add client hostname uniqueness validations and rename the // method to validateHostname. func (s *v4Server) normalizeHostname(name string) (norm string, err error) { </s> add // normalizeHostname normalizes a hostname sent by the client. func normalizeHostname(name string) (norm string, err error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
func GenerateHostname(ip net.IP) (hostname string) {
<mask> // In case of using IPv6, the result is like: <mask> // <mask> // ff80-f076-0000-0000-0000-0000-0000-0010 <mask> // <mask> func GenerateHostName(ip net.IP) (hostname string) { <mask> if ipv4 := ip.To4(); ipv4 != nil { <mask> return generateIPv4Hostname(ipv4) <mask> } else if ipv6 := ip.To16(); ipv6 != nil { <mask> return generateIPv6Hostname(ipv6) <mask> } </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove // GenerateHostName generates the hostname from ip. In case of using IPv4 the </s> add // GenerateHostname generates the hostname from ip. In case of using IPv4 the </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen { </s> remove } else if len(label) == 0 { </s> add } else if l == 0 { </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr.go
}, { name: "bad_label_last_symbol", in: "example-.aa.com", wantErrMsg: `invalid domain name label at index 0:` + ` invalid char '-' at index 7 in "example-"`,
<mask> wantErrMsg: `invalid domain name label at index 1:` + <mask> ` invalid char '-' at index 0 in "-aa"`, <mask> }, { <mask> name: "bad_label_symbol", <mask> in: "example.a!!!.com", <mask> wantErrMsg: `invalid domain name label at index 1:` + <mask> ` invalid char '!' at index 1 in "a!!!"`, </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove name: "error", hostname: "!!!", wantErrMsg: `validating non-normalized hostname: ` + `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, want: "", </s> add name: "success_underscores", hostname: "my_device_01", wantErrMsg: "", want: "my-device-01", </s> remove name: "error_spaces", hostname: "! ! !", wantErrMsg: `validating normalized hostname: ` + `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!-!-!"`, want: "", </s> add name: "error_part", hostname: "device !!!", wantErrMsg: "", want: "device", }, { name: "error_part_spaces", hostname: "device ! ! !", wantErrMsg: "", want: "device", }, { name: "error", hostname: "!!!", wantErrMsg: `normalizing hostname "!!!": no valid parts`, want: "", }, { name: "error_spaces", hostname: "! ! !", wantErrMsg: `normalizing hostname "! ! !": no valid parts`, want: "", </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove if len(label) > maxDomainLabelLen { </s> add l := len(label) if l > maxDomainLabelLen {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr_test.go
hostname := GenerateHostname(tc.ip)
<mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> hostname := GenerateHostName(tc.ip) <mask> assert.Equal(t, tc.want, hostname) <mask> }) <mask> } <mask> } </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove got, err := (&v4Server{}).normalizeHostname(tc.hostname) </s> add got, err := normalizeHostname(tc.hostname) </s> remove func TestV4Server_normalizeHostname(t *testing.T) { </s> add func TestNormalizeHostname(t *testing.T) { </s> remove name: "error_spaces", hostname: "! ! !", wantErrMsg: `validating normalized hostname: ` + `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!-!-!"`, want: "", </s> add name: "error_part", hostname: "device !!!", wantErrMsg: "", want: "device", }, { name: "error_part_spaces", hostname: "device ! ! !", wantErrMsg: "", want: "device", }, { name: "error", hostname: "!!!", wantErrMsg: `normalizing hostname "!!!": no valid parts`, want: "", }, { name: "error_spaces", hostname: "! ! !", wantErrMsg: `normalizing hostname "! ! !": no valid parts`, want: "", </s> remove // Return TRUE if host names doesn't contain disallowed characters func isHostnameOK(hostname string) bool { for _, c := range hostname { if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-') { log.Debug("dns: skipping invalid hostname %s from DHCP", hostname) return false } } return true } </s> add </s> remove if len(l.Hostname) == 0 || !isHostnameOK(l.Hostname) { continue </s> add // TODO(a.garipov): Remove this after we're finished // with the client hostname validations in the DHCP // server code. err = aghnet.ValidateDomainName(l.Hostname) if err != nil { log.Debug( "dns: skipping invalid hostname %q from dhcp: %s", l.Hostname, err, )
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/aghnet/addr_test.go
// normalizeHostname normalizes a hostname sent by the client. func normalizeHostname(name string) (norm string, err error) {
<mask> copy(b[i:], []byte(o.name)) <mask> return b <mask> } <mask> <mask> // normalizeHostname normalizes and validates a hostname sent by the client. <mask> // <mask> // TODO(a.garipov): Add client hostname uniqueness validations and rename the <mask> // method to validateHostname. <mask> func (s *v4Server) normalizeHostname(name string) (norm string, err error) { <mask> if name == "" { <mask> return "", nil <mask> } <mask> <mask> // Some devices send hostnames with spaces, but we still want to accept </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove if len(l.Hostname) == 0 || !isHostnameOK(l.Hostname) { continue </s> add // TODO(a.garipov): Remove this after we're finished // with the client hostname validations in the DHCP // server code. err = aghnet.ValidateDomainName(l.Hostname) if err != nil { log.Debug( "dns: skipping invalid hostname %q from dhcp: %s", l.Hostname, err, )
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil
<mask> if name == "" { <mask> return "", nil <mask> } <mask> <mask> // Some devices send hostnames with spaces, but we still want to accept <mask> // them, so replace them with dashes and issue a warning. <mask> // <mask> // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. <mask> norm = strings.ReplaceAll(name, " ", "-") <mask> state := "non-normalized" <mask> if name != norm { <mask> log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) <mask> state = "normalized" <mask> } <mask> <mask> err = aghnet.ValidateDomainName(norm) <mask> if err != nil { <mask> return "", fmt.Errorf("validating %s hostname: %w", state, err) </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name) </s> remove // normalizeHostname normalizes and validates a hostname sent by the client. // // TODO(a.garipov): Add client hostname uniqueness validations and rename the // method to validateHostname. func (s *v4Server) normalizeHostname(name string) (norm string, err error) { </s> add // normalizeHostname normalizes a hostname sent by the client. func normalizeHostname(name string) (norm string, err error) { </s> remove return "", fmt.Errorf("validating %s hostname: %w", state, err) </s> add return fmt.Errorf("validating hostname: %w", err) </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
err = aghnet.ValidateDomainName(name)
<mask> log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) <mask> state = "normalized" <mask> } <mask> <mask> err = aghnet.ValidateDomainName(norm) <mask> if err != nil { <mask> return "", fmt.Errorf("validating %s hostname: %w", state, err) <mask> } <mask> <mask> return norm, nil </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove return "", fmt.Errorf("validating %s hostname: %w", state, err) </s> add return fmt.Errorf("validating hostname: %w", err) </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil </s> remove hostname, err = s.normalizeHostname(req.HostName()) </s> add hostname, err = normalizeHostname(cliHostname)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
return fmt.Errorf("validating hostname: %w", err)
<mask> } <mask> <mask> err = aghnet.ValidateDomainName(norm) <mask> if err != nil { <mask> return "", fmt.Errorf("validating %s hostname: %w", state, err) <mask> } <mask> <mask> return norm, nil <mask> } <mask> </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name) </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove return norm, nil </s> add // TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil </s> remove hostname, err = s.normalizeHostname(req.HostName()) </s> add hostname, err = normalizeHostname(cliHostname) </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
// TODO(a.garipov): Add client hostname uniqueness validation either // here or into method processRequest. This is not as easy as it might // look like, because the process of adding and releasing a lease is // currently non-straightforward. return nil
<mask> if err != nil { <mask> return "", fmt.Errorf("validating %s hostname: %w", state, err) <mask> } <mask> <mask> return norm, nil <mask> } <mask> <mask> // Process Request request and return lease <mask> // Return false if we don't need to reply <mask> func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove return "", fmt.Errorf("validating %s hostname: %w", state, err) </s> add return fmt.Errorf("validating hostname: %w", err) </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name) </s> remove // normalizeHostname normalizes and validates a hostname sent by the client. // // TODO(a.garipov): Add client hostname uniqueness validations and rename the // method to validateHostname. func (s *v4Server) normalizeHostname(name string) (norm string, err error) { </s> add // normalizeHostname normalizes a hostname sent by the client. func normalizeHostname(name string) (norm string, err error) { </s> remove // Return TRUE if host names doesn't contain disallowed characters func isHostnameOK(hostname string) bool { for _, c := range hostname { if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-') { log.Debug("dns: skipping invalid hostname %s from DHCP", hostname) return false } } return true } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
cliHostname := req.HostName()
<mask> return nil, true <mask> } <mask> <mask> if !lease.IsStatic() { <mask> var hostname string <mask> hostname, err = normalizeHostname(cliHostname) <mask> if err != nil { <mask> log.Error("dhcpv4: cannot normalize hostname for %s: %s", mac, err) </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove hostname, err = s.normalizeHostname(req.HostName()) </s> add hostname, err = normalizeHostname(cliHostname) </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove hostname = aghnet.GenerateHostName(reqIP) </s> add hostname = aghnet.GenerateHostname(reqIP) </s> remove func TestV4Server_normalizeHostname(t *testing.T) { </s> add func TestNormalizeHostname(t *testing.T) { </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
hostname, err = normalizeHostname(cliHostname)
<mask> } <mask> <mask> if !lease.IsStatic() { <mask> var hostname string <mask> hostname, err = s.normalizeHostname(req.HostName()) <mask> if err != nil { <mask> log.Error("dhcpv4: cannot normalize hostname for %s: %s", mac, err) <mask> <mask> return nil, false <mask> } </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove hostname = aghnet.GenerateHostName(reqIP) </s> add hostname = aghnet.GenerateHostname(reqIP) </s> remove func TestV4Server_normalizeHostname(t *testing.T) { </s> add func TestNormalizeHostname(t *testing.T) { </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
// Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP.
<mask> hostname, err = s.normalizeHostname(req.HostName()) <mask> if err != nil { <mask> log.Error("dhcpv4: cannot normalize hostname for %s: %s", mac, err) <mask> <mask> return nil, false <mask> } <mask> <mask> if hostname == "" { <mask> hostname = aghnet.GenerateHostName(reqIP) <mask> } </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove hostname, err = s.normalizeHostname(req.HostName()) </s> add hostname, err = normalizeHostname(cliHostname) </s> remove hostname = aghnet.GenerateHostName(reqIP) </s> add hostname = aghnet.GenerateHostname(reqIP) </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
hostname = aghnet.GenerateHostname(reqIP)
<mask> return nil, false <mask> } <mask> <mask> if hostname == "" { <mask> hostname = aghnet.GenerateHostName(reqIP) <mask> } <mask> <mask> lease.Hostname = hostname <mask> s.commitLease(lease) <mask> } else if len(lease.Hostname) != 0 { </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP. </s> remove hostname, err = s.normalizeHostname(req.HostName()) </s> add hostname, err = normalizeHostname(cliHostname) </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4.go
func TestNormalizeHostname(t *testing.T) {
<mask> assert.Equal(t, mac, ls[0].HWAddr) <mask> }) <mask> } <mask> <mask> func TestV4Server_normalizeHostname(t *testing.T) { <mask> testCases := []struct { <mask> name string <mask> hostname string <mask> wantErrMsg string <mask> want string </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove hostname, err = s.normalizeHostname(req.HostName()) </s> add hostname, err = normalizeHostname(cliHostname) </s> remove hostname := GenerateHostName(tc.ip) </s> add hostname := GenerateHostname(tc.ip) </s> remove got, err := (&v4Server{}).normalizeHostname(tc.hostname) </s> add got, err := normalizeHostname(tc.hostname) </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4_test.go
name: "success_underscores", hostname: "my_device_01", wantErrMsg: "", want: "my-device-01",
<mask> hostname: "my device 01", <mask> wantErrMsg: "", <mask> want: "my-device-01", <mask> }, { <mask> name: "error", <mask> hostname: "!!!", <mask> wantErrMsg: `validating non-normalized hostname: ` + <mask> `invalid domain name label at index 0: ` + <mask> `invalid char '!' at index 0 in "!!!"`, <mask> want: "", <mask> }, { <mask> name: "error_spaces", <mask> hostname: "! ! !", <mask> wantErrMsg: `validating normalized hostname: ` + <mask> `invalid domain name label at index 0: ` + </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove name: "error_spaces", hostname: "! ! !", wantErrMsg: `validating normalized hostname: ` + `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!-!-!"`, want: "", </s> add name: "error_part", hostname: "device !!!", wantErrMsg: "", want: "device", }, { name: "error_part_spaces", hostname: "device ! ! !", wantErrMsg: "", want: "device", }, { name: "error", hostname: "!!!", wantErrMsg: `normalizing hostname "!!!": no valid parts`, want: "", }, { name: "error_spaces", hostname: "! ! !", wantErrMsg: `normalizing hostname "! ! !": no valid parts`, want: "", </s> remove return "", fmt.Errorf("validating %s hostname: %w", state, err) </s> add return fmt.Errorf("validating hostname: %w", err) </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove err = aghnet.ValidateDomainName(norm) </s> add err = aghnet.ValidateDomainName(name)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4_test.go
name: "error_part", hostname: "device !!!", wantErrMsg: "", want: "device", }, { name: "error_part_spaces", hostname: "device ! ! !", wantErrMsg: "", want: "device", }, { name: "error", hostname: "!!!", wantErrMsg: `normalizing hostname "!!!": no valid parts`, want: "", }, { name: "error_spaces", hostname: "! ! !", wantErrMsg: `normalizing hostname "! ! !": no valid parts`, want: "",
<mask> `invalid domain name label at index 0: ` + <mask> `invalid char '!' at index 0 in "!!!"`, <mask> want: "", <mask> }, { <mask> name: "error_spaces", <mask> hostname: "! ! !", <mask> wantErrMsg: `validating normalized hostname: ` + <mask> `invalid domain name label at index 0: ` + <mask> `invalid char '!' at index 0 in "!-!-!"`, <mask> want: "", <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> got, err := (&v4Server{}).normalizeHostname(tc.hostname) </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove name: "error", hostname: "!!!", wantErrMsg: `validating non-normalized hostname: ` + `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, want: "", </s> add name: "success_underscores", hostname: "my_device_01", wantErrMsg: "", want: "my-device-01", </s> remove got, err := (&v4Server{}).normalizeHostname(tc.hostname) </s> add got, err := normalizeHostname(tc.hostname) </s> remove hostname := GenerateHostName(tc.ip) </s> add hostname := GenerateHostname(tc.ip) </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4_test.go
got, err := normalizeHostname(tc.hostname)
<mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> got, err := (&v4Server{}).normalizeHostname(tc.hostname) <mask> if tc.wantErrMsg == "" { <mask> assert.NoError(t, err) <mask> } else { <mask> require.Error(t, err) <mask> </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove hostname := GenerateHostName(tc.ip) </s> add hostname := GenerateHostname(tc.ip) </s> remove name: "error_spaces", hostname: "! ! !", wantErrMsg: `validating normalized hostname: ` + `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!-!-!"`, want: "", </s> add name: "error_part", hostname: "device !!!", wantErrMsg: "", want: "device", }, { name: "error_part_spaces", hostname: "device ! ! !", wantErrMsg: "", want: "device", }, { name: "error", hostname: "!!!", wantErrMsg: `normalizing hostname "!!!": no valid parts`, want: "", }, { name: "error_spaces", hostname: "! ! !", wantErrMsg: `normalizing hostname "! ! !": no valid parts`, want: "", </s> remove func TestV4Server_normalizeHostname(t *testing.T) { </s> add func TestNormalizeHostname(t *testing.T) { </s> remove if r := label[0]; !isValidHostFirstRune(rune(r)) { </s> add if r := label[0]; !IsValidHostOuterRune(rune(r)) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dhcpd/v4_test.go
<mask> <mask> return resultCodeSuccess <mask> } <mask> <mask> // Return TRUE if host names doesn't contain disallowed characters <mask> func isHostnameOK(hostname string) bool { <mask> for _, c := range hostname { <mask> if !((c >= 'a' && c <= 'z') || <mask> (c >= 'A' && c <= 'Z') || <mask> (c >= '0' && c <= '9') || <mask> c == '.' || c == '-') { <mask> log.Debug("dns: skipping invalid hostname %s from DHCP", hostname) <mask> return false <mask> } <mask> } <mask> return true <mask> } <mask> <mask> func (s *Server) setTableHostToIP(t hostToIPTable) { <mask> s.tableHostToIPLock.Lock() <mask> defer s.tableHostToIPLock.Unlock() <mask> <mask> s.tableHostToIP = t </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove // isValidHostFirstRune returns true if r is a valid first rune for a hostname // label. func isValidHostFirstRune(r rune) (ok bool) { return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') } // isValidHostRune returns true if r is a valid rune for a hostname label. func isValidHostRune(r rune) (ok bool) { return r == '-' || isValidHostFirstRune(r) } </s> add </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil </s> remove if len(l.Hostname) == 0 || !isHostnameOK(l.Hostname) { continue </s> add // TODO(a.garipov): Remove this after we're finished // with the client hostname validations in the DHCP // server code. err = aghnet.ValidateDomainName(l.Hostname) if err != nil { log.Debug( "dns: skipping invalid hostname %q from dhcp: %s", l.Hostname, err, ) </s> remove return nil, false </s> add // Go on and assign a hostname made from the IP. } if hostname != "" && cliHostname != hostname { log.Debug("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } err = s.validateHostname(hostname) if err != nil { log.Error("dhcpv4: validating hostname for %s: %s", mac, err) // Go on and assign a hostname made from the IP.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dnsforward/dns.go
var err error
<mask> } <mask> <mask> func (s *Server) onDHCPLeaseChanged(flags int) { <mask> add := true <mask> switch flags { <mask> case dhcpd.LeaseChangedAdded, <mask> dhcpd.LeaseChangedAddedStatic, </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove // Return TRUE if host names doesn't contain disallowed characters func isHostnameOK(hostname string) bool { for _, c := range hostname { if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-') { log.Debug("dns: skipping invalid hostname %s from DHCP", hostname) return false } } return true } </s> add </s> remove func GenerateHostName(ip net.IP) (hostname string) { </s> add func GenerateHostname(ip net.IP) (hostname string) { </s> remove func TestV4Server_normalizeHostname(t *testing.T) { </s> add func TestNormalizeHostname(t *testing.T) { </s> remove // Some devices send hostnames with spaces, but we still want to accept // them, so replace them with dashes and issue a warning. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2946. norm = strings.ReplaceAll(name, " ", "-") state := "non-normalized" if name != norm { log.Debug("dhcpv4: normalized hostname %q into %q", name, norm) state = "normalized" </s> add parts := strings.FieldsFunc(name, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { if name == "" { return nil
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dnsforward/dns.go
// TODO(a.garipov): Remove this after we're finished // with the client hostname validations in the DHCP // server code. err = aghnet.ValidateDomainName(l.Hostname) if err != nil { log.Debug( "dns: skipping invalid hostname %q from dhcp: %s", l.Hostname, err, )
<mask> <mask> ll := s.dhcpServer.Leases(dhcpd.LeasesAll) <mask> <mask> for _, l := range ll { <mask> if len(l.Hostname) == 0 || !isHostnameOK(l.Hostname) { <mask> continue <mask> } <mask> <mask> lowhost := strings.ToLower(l.Hostname) <mask> <mask> ipToHost[l.IP.String()] = lowhost </s> Pull request: all: imp dhcp client hostname normalization Updates #2952. Updates #2978. Squashed commit of the following: commit 20e379b94ccf8140fd9056429315945c17f711a5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:58:37 2021 +0300 all: imp naming commit ed300e0563fa37e161406a97991b26a89e23903a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 19 15:43:09 2021 +0300 all: imp dhcp client hostname normalization </s> remove if l == 0 || l > maxDomainNameLen { </s> add if l == 0 { return agherr.Error("domain name is empty") } else if l > maxDomainNameLen { </s> remove got, err := (&v4Server{}).normalizeHostname(tc.hostname) </s> add got, err := normalizeHostname(tc.hostname) </s> remove // Return TRUE if host names doesn't contain disallowed characters func isHostnameOK(hostname string) bool { for _, c := range hostname { if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-') { log.Debug("dns: skipping invalid hostname %s from DHCP", hostname) return false } } return true } </s> add </s> remove hostname := GenerateHostName(tc.ip) </s> add hostname := GenerateHostname(tc.ip)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d707f8b1d1be0ef201209ecfa30b4d43eabea937
internal/dnsforward/dns.go
github.com/AdguardTeam/dnsproxy v0.46.5
<mask> <mask> go 1.18 <mask> <mask> require ( <mask> github.com/AdguardTeam/dnsproxy v0.46.4 <mask> github.com/AdguardTeam/golibs v0.11.3 <mask> github.com/AdguardTeam/urlfilter v0.16.0 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/ameshkov/dnscrypt/v2 v2.2.5 <mask> github.com/digineo/go-ipset/v2 v2.2.1 </s> Pull request: 5251-close-ups Merge in DNS/adguard-home from 5251-close-ups to master Updates #5251. Squashed commit of the following: commit 98a4a9a45ae702df3cf26cab0b28bd83a6556085 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 14 18:31:17 2022 +0300 all: log changes better commit af25803925c15ba2d9b07865c3deb58033006c52 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 14 18:24:42 2022 +0300 all: log changes commit 65bb12d8b6d6bd2e37ee83bc4aca63aa573da63a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 14 18:15:41 2022 +0300 all: upd dnsproxy commit 24039cd7f9c64ee5d9806e1146dbd1e76c298a20 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 14 17:19:15 2022 +0300 dnsforward: imp code, docs commit a40bbd55267c9904c14b89568408f86ccb3ef6c9 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 14 16:43:10 2022 +0300 dnsforward: log errs instead of return </s> remove github.com/AdguardTeam/dnsproxy v0.46.4 h1:/+wnTG0q2TkGQyA1PeSsjv4/f5ZprGduKPSoOcG+rOU= github.com/AdguardTeam/dnsproxy v0.46.4/go.mod h1:yYDMAH6ay2PxLcLtfVM3FUiyv/U9B/zYO+cIIssuJNU= </s> add github.com/AdguardTeam/dnsproxy v0.46.5 h1:TiJZhwaIDDaKkqEfJ9AD9aroFjcHN8oEbKB8WfTjSIs= github.com/AdguardTeam/dnsproxy v0.46.5/go.mod h1:yKBVgFlE6CqTQtye++3e7SATaMPc4Ixij+KkHsM6HhM= </s> remove if len(errs) > 0 { return errors.List("stopping dns server", errs...) } else { s.isRunning = false } </s> add s.isRunning = false </s> remove if errors.Is(err, net.ErrClosed) { log.Debug("dnsforward: %s: %s", action, err) } else { errs = append(errs, fmt.Errorf("%s: %w", action, err)) } </s> add log.Error("dnsforward: closing local resolvers: %s", err) </s> remove const action = "closing local resolvers" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/d77b743c7bd371a207d0c103a3a8821dd95841ba
go.mod