Compare commits

...

7 Commits

Author SHA1 Message Date
Dominik 8d6bff9cf2
Merge 231a9853bd into e10bb5c605 2024-05-05 05:10:00 +00:00
Dominik e10bb5c605
Merge pull request #1944 from pi-hole/fix/clients_docs
Improve API /clients documentation
2024-05-05 07:09:42 +02:00
Dominik 240a2fe7a1
Merge pull request #1945 from pi-hole/tweak/tcp_conn_err
Improve error logging when TCP connections are prematurely closed by remote server
2024-05-05 07:08:07 +02:00
DL6ER 1611da221c
Improve error logging when TCP connections are prematurely closed by remote server
Signed-off-by: DL6ER <dl6er@dl6er.de>
2024-05-04 10:09:03 +02:00
DL6ER 01697669ac
API /clients: Add note that {client} needs to be URI-encoded (if specified) and add documentation of read-only optional {name0} field
Signed-off-by: DL6ER <dl6er@dl6er.de>
2024-05-03 20:05:00 +02:00
DL6ER 231a9853bd
If dns.domainNeeded is set, refuse to send plain domain queries (like laptop) upstream at all.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2024-03-07 16:58:52 +01:00
DL6ER ad46a1018a
We should only set local=/<domain>/ if there is no conditional forwarding setting (v6 supports multiple reverse lookup servers), otherwise, this creates a harmless but nonetheless needlessly confusing configuration.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2024-03-07 16:55:11 +01:00
3 changed files with 50 additions and 15 deletions

View File

@ -11,7 +11,7 @@ components:
- "Client management"
operationId: "get_clients"
description: |
`{client}` is optional. Specifying it will result in only the requested client being returned.
`{client}` is optional. If it is specified, it will result in only the requested client being returned. This parameter needs to be URI-encoded.
Valid combinations are:
- `/api/clients` (all clients)
@ -42,7 +42,7 @@ components:
- "Client management"
operationId: "replace_client"
description: |
Items may be updated by replacing them. `{client}` is required.
Items may be updated by replacing them. `{client}` is required and needs to be URI-encoded.
Ensure to send all the required parameters (such as `comment` or `groups`) to ensure these properties are retained.
The read-only fields `id` and `date_added` are preserved, `date_modified` is automatically updated on success.
@ -91,7 +91,7 @@ components:
- "Client management"
operationId: "delete_client"
description: |
*Note:* There will be no content on success.
*Note:* There will be no content on success. `{client}` is required and needs to be URI-encoded.
responses:
'204':
description: Item deleted
@ -383,6 +383,12 @@ components:
type: integer
readOnly: true
example: 1611239099
name:
description: hostname (only if available)
type: string
readOnly: true
nullable: true
example: localhost
lists_processed:
type: object
properties:

View File

@ -449,6 +449,8 @@ bool __attribute__((const)) write_dnsmasq_config(struct config *conf, bool test_
}
fputs("\n", pihole_conf);
// Add upstream DNS servers for reverse lookups
bool domain_revServer = false;
const unsigned int revServers = cJSON_GetArraySize(conf->dns.revServers.v.json);
for(unsigned int i = 0; i < revServers; i++)
{
@ -485,8 +487,15 @@ bool __attribute__((const)) write_dnsmasq_config(struct config *conf, bool test_
// If we have a reverse domain, we forward all queries to this domain to
// the same destination
if(strlen(domain) > 0)
{
fprintf(pihole_conf, "server=/%s/%s\n", domain, target);
// Check if the configured domain is the same as the main domain
if(strlen(config.dns.domain.v.s) > 0 &&
strcasecmp(domain, config.dns.domain.v.s) == 0)
domain_revServer = true;
}
// Forward unqualified names to the target only when the "never forward
// non-FQDN" option is NOT ticked
if(!conf->dns.domainNeeded.v.b)
@ -497,19 +506,14 @@ bool __attribute__((const)) write_dnsmasq_config(struct config *conf, bool test_
free(copy);
}
// When there is a Pi-hole domain set and "Never forward non-FQDNs" is
// ticked, we add `local=/domain/` to signal that this domain is purely
// local and FTL may answer queries from /etc/hosts or DHCP but should
// never forward queries on that domain to any upstream servers
// When "Never forward non-FQDNs" is ticked, we add `local=//` to signal
// that non-FQDNs queries should never be sent to any upstream servers
if(conf->dns.domainNeeded.v.b)
{
fputs("# Never forward A or AAAA queries for plain names, without\n",pihole_conf);
fputs("# dots or domain parts, to upstream nameservers. If the name\n", pihole_conf);
fputs("# is not known from /etc/hosts or DHCP a NXDOMAIN is returned\n", pihole_conf);
if(strlen(conf->dns.domain.v.s))
fprintf(pihole_conf, "local=/%s/\n\n", conf->dns.domain.v.s);
else
fputs("\n", pihole_conf);
fputs("# is not known from /etc/hosts or DHCP, NXDOMAIN is returned\n", pihole_conf);
fputs("local=//\n\n", pihole_conf);
}
// Add domain to DNS server. It will also be used for DHCP if the DHCP
@ -517,7 +521,20 @@ bool __attribute__((const)) write_dnsmasq_config(struct config *conf, bool test_
if(strlen(conf->dns.domain.v.s) > 0)
{
fputs("# DNS domain for both the DNS and DHCP server\n", pihole_conf);
fprintf(pihole_conf, "domain=%s\n\n", conf->dns.domain.v.s);
if(!domain_revServer)
{
fputs("# This DNS domain in purely local. FTL may answer queries from\n", pihole_conf);
fputs("# /etc/hosts or DHCP but should never forward queries on that\n", pihole_conf);
fputs("# domain to any upstream servers\n", pihole_conf);
fprintf(pihole_conf, "domain=%s\n", conf->dns.domain.v.s);
fprintf(pihole_conf, "local=/%s/\n\n", conf->dns.domain.v.s);
}
else
{
fputs("# This DNS domain is also used for reverse lookups\n", pihole_conf);
fputs("# (see server=/<domain>/target above)\n", pihole_conf);
fprintf(pihole_conf, "domain=%s\n\n", conf->dns.domain.v.s);
}
}
if(conf->dhcp.active.v.b)

View File

@ -3512,7 +3512,19 @@ void get_dnsmasq_metrics_obj(cJSON *json)
void FTL_connection_error(const char *reason, const union mysockaddr *addr)
{
// Make a private copy of the error
const char *error = strerror(errno);
const int errnum = errno;
const char *error = strerror(errnum);
// Set log priority
int priority = LOG_ERR;
// If this is a TCP connection error and errno == 0, this isn't a
// connection error but the remote side closed the connection
if(errnum == 0 && strstr(reason, "TCP(read_write)") != NULL)
{
error = "Connection prematurely closed by remote server";
priority = LOG_INFO;
}
// Format the address into a string (if available)
in_port_t port = 0;
@ -3525,7 +3537,7 @@ void FTL_connection_error(const char *reason, const union mysockaddr *addr)
log_debug(DEBUG_QUERIES, "Connection error (%s#%u, ID %d): %s (%s)", ip, port, id, reason, error);
// Log to pihole.log
my_syslog(LOG_ERR, "%s: %s", reason, error);
my_syslog(priority, "%s: %s", reason, error);
// Add to Pi-hole diagnostics but do not add messages more often than
// once every five seconds to avoid hammering the database with errors