Pull request: 2508 ip conversion vol.2
Merge in DNS/adguard-home from 2508-ip-conversion-vol2 to master Closes #2508. Squashed commit of the following: commit 5b9d33f9cd352756831f63e34c4aea48674628c1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:15:17 2021 +0300 util: replace net.IPNet with pointer commit 680126de7d59464077f9edf1bbaa925dd3fcee19 Merge: d3ba6a6c5a50efadAuthor: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:02:41 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit d3ba6a6cdd01c0aa736418fdb86ed40120169fe9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 18:29:54 2021 +0300 all: remove last conversion commit 88b63f11a6c3f8705d7fa0c448c50dd646cc9214 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 14:12:45 2021 +0300 all: improve code quality commit 71af60c70a0dbaf55e2221023d6d2e4993c9e9a7 Merge: 98af37849f75725dAuthor: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 17:13:27 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit 98af3784ce44d0993d171653c13d6e83bb8d1e6a Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:32:53 2021 +0300 all: log changes commit e99595a172bae1e844019d344544be84ddd65e4e Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:06:49 2021 +0300 all: fix or remove remaining net.IP <-> string conversions commit 7fd0634ce945f7e4c9b856684c5199f8a84a543e Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jan 15 15:36:17 2021 +0300 all: remove redundant net.IP <-> string converions commit 5df8af030421237d41b67ed659f83526cc258199 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:35:25 2021 +0300 stats: remove redundant net.IP <-> string conversion commit fbe4e3fc015e6898063543a90c04401d76dbb18f Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:20:35 2021 +0300 querylog: remove redundant net.IP <-> string conversion
This commit is contained in:
@@ -31,7 +31,7 @@ type netInterfaceJSON struct {
|
||||
Name string `json:"name"`
|
||||
MTU int `json:"mtu"`
|
||||
HardwareAddr string `json:"hardware_address"`
|
||||
Addresses []string `json:"ip_addresses"`
|
||||
Addresses []net.IP `json:"ip_addresses"`
|
||||
Flags string `json:"flags"`
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (web *Web) handleInstallGetAddresses(w http.ResponseWriter, r *http.Request
|
||||
|
||||
type checkConfigReqEnt struct {
|
||||
Port int `json:"port"`
|
||||
IP string `json:"ip"`
|
||||
IP net.IP `json:"ip"`
|
||||
Autofix bool `json:"autofix"`
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func (web *Web) handleInstallCheckConfig(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
if err != nil {
|
||||
respData.DNS.Status = err.Error()
|
||||
} else if reqData.DNS.IP != "0.0.0.0" {
|
||||
} else if !reqData.DNS.IP.IsUnspecified() {
|
||||
respData.StaticIP = handleStaticIP(reqData.DNS.IP, reqData.SetStaticIP)
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func (web *Web) handleInstallCheckConfig(w http.ResponseWriter, r *http.Request)
|
||||
// handleStaticIP - handles static IP request
|
||||
// It either checks if we have a static IP
|
||||
// Or if set=true, it tries to set it
|
||||
func handleStaticIP(ip string, set bool) staticIPJSON {
|
||||
func handleStaticIP(ip net.IP, set bool) staticIPJSON {
|
||||
resp := staticIPJSON{}
|
||||
|
||||
interfaceName := util.GetInterfaceByIP(ip)
|
||||
@@ -186,7 +186,7 @@ func handleStaticIP(ip string, set bool) staticIPJSON {
|
||||
if isStaticIP {
|
||||
resp.Static = "yes"
|
||||
}
|
||||
resp.IP = util.GetSubnet(interfaceName)
|
||||
resp.IP = util.GetSubnet(interfaceName).String()
|
||||
}
|
||||
return resp
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func disableDNSStubListener() error {
|
||||
}
|
||||
|
||||
type applyConfigReqEnt struct {
|
||||
IP string `json:"ip"`
|
||||
IP net.IP `json:"ip"`
|
||||
Port int `json:"port"`
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ func (web *Web) handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
restartHTTP := true
|
||||
if config.BindHost == newSettings.Web.IP && config.BindPort == newSettings.Web.Port {
|
||||
if config.BindHost.Equal(newSettings.Web.IP) && config.BindPort == newSettings.Web.Port {
|
||||
// no need to rebind
|
||||
restartHTTP = false
|
||||
}
|
||||
@@ -307,7 +307,7 @@ func (web *Web) handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
err = util.CheckPortAvailable(newSettings.Web.IP, newSettings.Web.Port)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s due to %s",
|
||||
net.JoinHostPort(newSettings.Web.IP, strconv.Itoa(newSettings.Web.Port)), err)
|
||||
net.JoinHostPort(newSettings.Web.IP.String(), strconv.Itoa(newSettings.Web.Port)), err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -388,18 +388,18 @@ func (web *Web) registerInstallHandlers() {
|
||||
// checkConfigReqEntBeta is a struct representing new client's config check
|
||||
// request entry. It supports multiple IP values unlike the checkConfigReqEnt.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default checkConfigReqEnt.
|
||||
type checkConfigReqEntBeta struct {
|
||||
Port int `json:"port"`
|
||||
IP []string `json:"ip"`
|
||||
IP []net.IP `json:"ip"`
|
||||
Autofix bool `json:"autofix"`
|
||||
}
|
||||
|
||||
// checkConfigReqBeta is a struct representing new client's config check request
|
||||
// body. It uses checkConfigReqEntBeta instead of checkConfigReqEnt.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default checkConfigReq.
|
||||
type checkConfigReqBeta struct {
|
||||
Web checkConfigReqEntBeta `json:"web"`
|
||||
@@ -410,7 +410,7 @@ type checkConfigReqBeta struct {
|
||||
// handleInstallCheckConfigBeta is a substitution of /install/check_config
|
||||
// handler for new client.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default handleInstallCheckConfig.
|
||||
func (web *Web) handleInstallCheckConfigBeta(w http.ResponseWriter, r *http.Request) {
|
||||
reqData := checkConfigReqBeta{}
|
||||
@@ -456,17 +456,17 @@ func (web *Web) handleInstallCheckConfigBeta(w http.ResponseWriter, r *http.Requ
|
||||
// applyConfigReqEntBeta is a struct representing new client's config setting
|
||||
// request entry. It supports multiple IP values unlike the applyConfigReqEnt.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default applyConfigReqEnt.
|
||||
type applyConfigReqEntBeta struct {
|
||||
IP []string `json:"ip"`
|
||||
IP []net.IP `json:"ip"`
|
||||
Port int `json:"port"`
|
||||
}
|
||||
|
||||
// applyConfigReqBeta is a struct representing new client's config setting
|
||||
// request body. It uses applyConfigReqEntBeta instead of applyConfigReqEnt.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default applyConfigReq.
|
||||
type applyConfigReqBeta struct {
|
||||
Web applyConfigReqEntBeta `json:"web"`
|
||||
@@ -478,7 +478,7 @@ type applyConfigReqBeta struct {
|
||||
// handleInstallConfigureBeta is a substitution of /install/configure handler
|
||||
// for new client.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default handleInstallConfigure.
|
||||
func (web *Web) handleInstallConfigureBeta(w http.ResponseWriter, r *http.Request) {
|
||||
reqData := applyConfigReqBeta{}
|
||||
@@ -523,7 +523,7 @@ func (web *Web) handleInstallConfigureBeta(w http.ResponseWriter, r *http.Reques
|
||||
// firstRunDataBeta is a struct representing new client's getting addresses
|
||||
// request body. It uses array of structs instead of map.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default firstRunData.
|
||||
type firstRunDataBeta struct {
|
||||
WebPort int `json:"web_port"`
|
||||
@@ -534,7 +534,7 @@ type firstRunDataBeta struct {
|
||||
// handleInstallConfigureBeta is a substitution of /install/get_addresses
|
||||
// handler for new client.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default handleInstallGetAddresses.
|
||||
func (web *Web) handleInstallGetAddressesBeta(w http.ResponseWriter, r *http.Request) {
|
||||
data := firstRunDataBeta{}
|
||||
@@ -570,7 +570,7 @@ func (web *Web) handleInstallGetAddressesBeta(w http.ResponseWriter, r *http.Req
|
||||
// registerBetaInstallHandlers registers the install handlers for new client
|
||||
// with the structures it supports.
|
||||
//
|
||||
// TODO(e.burkov): this should removed with the API v1 when the appropriate
|
||||
// TODO(e.burkov): This should removed with the API v1 when the appropriate
|
||||
// functionality will appear in default handlers.
|
||||
func (web *Web) registerBetaInstallHandlers() {
|
||||
Context.mux.HandleFunc("/control/install/get_addresses_beta", preInstall(ensureGET(web.handleInstallGetAddressesBeta)))
|
||||
|
||||
Reference in New Issue
Block a user