From 1a5e7f6bf81e72edb44b7ed0cd66aafe8be67c12 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 30 May 2024 12:26:40 +0200 Subject: [PATCH] Add new dhcp.ignoreUnknownClients option Signed-off-by: DL6ER --- src/api/docs/content/specs/config.yaml | 3 +++ src/config/config.c | 7 +++++++ src/config/config.h | 1 + src/config/dnsmasq_config.c | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/src/api/docs/content/specs/config.yaml b/src/api/docs/content/specs/config.yaml index 0b785754..08d5dd1b 100644 --- a/src/api/docs/content/specs/config.yaml +++ b/src/api/docs/content/specs/config.yaml @@ -320,6 +320,8 @@ components: type: boolean logging: type: boolean + ignoreUnknownClients: + type: boolean hosts: type: array items: @@ -653,6 +655,7 @@ components: rapidCommit: false multiDNS: false logging: false + ignoreUnknownClients: false hosts: - "11:22:33:44:55:66,192.168.1.123" - "11:22:33:44:55:67,192.168.1.124,hostname" diff --git a/src/config/config.c b/src/config/config.c index f5bb3fa1..b81cf769 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -785,6 +785,13 @@ void initConfig(struct config *conf) conf->dhcp.logging.d.b = false; conf->dhcp.logging.c = validate_stub; // Only type-based checking + conf->dhcp.ignoreUnknownClients.k = "dhcp.ignoreUnknownClients"; + conf->dhcp.ignoreUnknownClients.h = "Ignore unknown DHCP clients.\n If this option is set, Pi-hole ignores all clients which are not explicitly configured through dhcp.hosts. This can be useful to prevent unauthorized clients from getting an IP address from the DHCP server.\n It should be noted that this option is not a security feature, as clients can still assign themselves an IP address and use the network. It is merely a convenience feature to prevent unknown clients from getting a valid IP configuration assigned automatically.\n Note that you will need to configure new clients manually in dhcp.hosts before they can use the network when this feature is enabled."; + conf->dhcp.ignoreUnknownClients.t = CONF_BOOL; + conf->dhcp.ignoreUnknownClients.f = FLAG_RESTART_FTL; + conf->dhcp.ignoreUnknownClients.d.b = false; + conf->dhcp.ignoreUnknownClients.c = validate_stub; // Only type-based checking + conf->dhcp.hosts.k = "dhcp.hosts"; conf->dhcp.hosts.h = "Per host parameters for the DHCP server. This allows a machine with a particular hardware address to be always allocated the same hostname, IP address and lease time or to specify static DHCP leases"; conf->dhcp.hosts.a = cJSON_CreateStringReference("Array of static leases each on in one of the following forms: \"[][,id:|*][,set:][,tag:][,][,][,][,ignore]\""); diff --git a/src/config/config.h b/src/config/config.h index 013414ed..884f1faa 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -187,6 +187,7 @@ struct config { struct conf_item rapidCommit; struct conf_item multiDNS; struct conf_item logging; + struct conf_item ignoreUnknownClients; struct conf_item hosts; } dhcp; diff --git a/src/config/dnsmasq_config.c b/src/config/dnsmasq_config.c index 5dda68b0..516b924c 100644 --- a/src/config/dnsmasq_config.c +++ b/src/config/dnsmasq_config.c @@ -582,6 +582,13 @@ bool __attribute__((const)) write_dnsmasq_config(struct config *conf, bool test_ fputs("log-dhcp\n\n", pihole_conf); } + // Add option to ignore unknown clients if enabled + if(conf->dhcp.ignoreUnknownClients.v.b) + { + fputs("# Ignore clients not configured below\n", pihole_conf); + fputs("dhcp-ignore=tag:!known\n", pihole_conf); + } + // Add per-host parameters if(cJSON_GetArraySize(conf->dhcp.hosts.v.json) > 0) {