Skip to content

Commit

Permalink
Pull request: home: rollback serveraddresses in mobileconfig
Browse files Browse the repository at this point in the history
Updates AdguardTeam#3607.

Squashed commit of the following:

commit 1f0a970
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Sep 30 13:26:49 2021 +0300

    home: rollback serveraddresses in mobileconfig
  • Loading branch information
ainar-g authored and heyxkhoa committed Mar 17, 2023
1 parent e3924bd commit 0c1e0cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ and this project adheres to

### Added

- DNS server IP addresses to the `mobileconfig` API responses ([#3568],
[#3607]).
- Setting the timeout for IP address pinging in the "Fastest IP address" mode
through the new `fastest_timeout` field in the configuration file ([#1992]).
- Static IP address detection on FreeBSD ([#3289]).
Expand Down Expand Up @@ -116,7 +114,8 @@ In this release, the schema version has changed from 10 to 12.

### Fixed

- Adding an IP into only one of the matching ipsets on Linux ([#3638]).
- Addition of IPs into only one as opposed to all matching ipsets on Linux
([#3638]).
- Removal of temporary filter files ([#3567]).
- Panic when an upstream server responds with an empty question section
([#3551]).
Expand Down
40 changes: 6 additions & 34 deletions internal/home/mobileconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type dnsSettings struct {
ServerName string `plist:",omitempty"`

// ServerAddresses is a list IP addresses of the server.
//
// TODO(a.garipov): Allow users to set this.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/3607.
ServerAddresses []net.IP `plist:",omitempty"`
}

Expand Down Expand Up @@ -157,19 +161,9 @@ func handleMobileConfig(w http.ResponseWriter, r *http.Request, dnsp string) {
}
}

dnsIPs, err := collectDNSIPs()
if err != nil {
// Don't add a lot of formatting, since the error is already
// wrapped by collectDNSIPs.
respondJSONError(w, http.StatusInternalServerError, err.Error())

return
}

d := &dnsSettings{
DNSProtocol: dnsp,
ServerName: host,
ServerAddresses: dnsIPs,
DNSProtocol: dnsp,
ServerName: host,
}

mobileconfig, err := encodeMobileConfig(d, clientID)
Expand Down Expand Up @@ -203,25 +197,3 @@ func handleMobileConfigDoH(w http.ResponseWriter, r *http.Request) {
func handleMobileConfigDoT(w http.ResponseWriter, r *http.Request) {
handleMobileConfig(w, r, dnsProtoTLS)
}

// collectDNSIPs returns a slice of IP addresses the server is listening
// on, including the addresses on all interfaces in cases of unspecified IPs but
// excluding loopback addresses.
func collectDNSIPs() (ips []net.IP, err error) {
// TODO(a.garipov): This really shouldn't be a function that parses
// a list of strings. Instead, we need a function that returns this
// data as []net.IP or []*netutil.IPPort. Maybe someday.
addrs, err := collectDNSAddresses()
if err != nil {
return nil, err
}

for _, addr := range addrs {
ip := net.ParseIP(addr)
if ip != nil && !ip.IsLoopback() {
ips = append(ips, ip)
}
}

return ips, nil
}
4 changes: 0 additions & 4 deletions internal/home/mobileconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestHandleMobileConfigDoH(t *testing.T) {
s := mc.PayloadContent[0].DNSSettings
require.NotNil(t, s)

assert.NotEmpty(t, s.ServerAddresses)
assert.Empty(t, s.ServerName)
assert.Equal(t, "https://example.org/dns-query", s.ServerURL)
})
Expand Down Expand Up @@ -104,7 +103,6 @@ func TestHandleMobileConfigDoH(t *testing.T) {
s := mc.PayloadContent[0].DNSSettings
require.NotNil(t, s)

assert.NotEmpty(t, s.ServerAddresses)
assert.Empty(t, s.ServerName)
assert.Equal(t, "https://example.org/dns-query/cli42", s.ServerURL)
})
Expand Down Expand Up @@ -132,7 +130,6 @@ func TestHandleMobileConfigDoT(t *testing.T) {
s := mc.PayloadContent[0].DNSSettings
require.NotNil(t, s)

assert.NotEmpty(t, s.ServerAddresses)
assert.Equal(t, "example.org", s.ServerName)
assert.Empty(t, s.ServerURL)
})
Expand Down Expand Up @@ -179,7 +176,6 @@ func TestHandleMobileConfigDoT(t *testing.T) {
s := mc.PayloadContent[0].DNSSettings
require.NotNil(t, s)

assert.NotEmpty(t, s.ServerAddresses)
assert.Equal(t, "cli42.example.org", s.ServerName)
assert.Empty(t, s.ServerURL)
})
Expand Down

0 comments on commit 0c1e0cc

Please sign in to comment.