This is inspired by @Kasoo's work in PR #234, but slightly different.
The "ip" option now takes "ignore" as a value , but it'll only disable
DHCPv4 for a matching client.
Similarly, the "hostid" option now also understands "ignore", which will
disable DHCPv6 for a matching client.
Of course, this is all based on client-reported MAC
addresses/DUIDs/client IDs/etc, so it's not actually a security feature.
Closes: https://github.com/openwrt/odhcpd/pull/234
Closes: https://github.com/openwrt/odhcpd/issues/198
Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/303
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
### Sections of type host (static leases)
| Option | Type |Default| Description |
| :-------------------- | :---- | :---- | :---------- |
-| ip |string |(none) | IPv4 host address |
+| ip |string |(none) | IPv4 host address or `ignore` to ignore any DHCPv4 request from this host |
| mac |list\|string|(none) | HexadecimalMACaddress(es) |
| duid |list\|string|(none) | Hexadecimal DUID(s), or DUID%IAID(s) |
-| hostid |string |(none) | IPv6hostidentifier |
+| hostid |string |(none) | IPv6 tokenised IID or `ignore` to ignore any DHCPv6 request from this host |
| name |string |(none) | Hostname |
| leasetime |string |(none) | DHCPv4/v6leasetime |
goto err;
}
- if ((c = tb[LEASE_CFG_ATTR_IP]))
- if (inet_pton(AF_INET, blobmsg_get_string(c), &lease_cfg->ipaddr) < 0)
+ if ((c = tb[LEASE_CFG_ATTR_IP])) {
+ const char *ip = blobmsg_get_string(c);
+
+ if (!strcmp(ip, "ignore"))
+ lease_cfg->ignore4 = true;
+ else if (inet_pton(AF_INET, blobmsg_get_string(c), &lease_cfg->ipaddr) < 0)
goto err;
+ }
if ((c = tb[LEASE_CFG_ATTR_HOSTID])) {
- errno = 0;
- lease_cfg->hostid = strtoull(blobmsg_get_string(c), NULL, 16);
- if (errno)
- goto err;
+ const char *iid = blobmsg_get_string(c);
+
+ if (!strcmp(iid, "ignore")) {
+ lease_cfg->ignore6 = true;
+ } else {
+ errno = 0;
+ lease_cfg->hostid = strtoull(blobmsg_get_string(c), NULL, 16);
+ if (errno)
+ goto err;
+ }
} else {
uint32_t i4a = ntohl(lease_cfg->ipaddr) & 0xff;
lease_cfg->hostid = ((i4a / 100) << 8) | (((i4a % 100) / 10) << 4) | (i4a % 10);
if (!lease_cfg)
lease_cfg = config_find_lease_cfg_by_mac(req_mac);
+ if (lease_cfg && lease_cfg->ignore4)
+ return NULL;
+
/*
* If we found a static lease cfg, but no old assignment for this
* hwaddr, we need to clear out any old assignments given to other
if (!lease_cfg)
lease_cfg = config_find_lease_cfg_by_mac(mac);
+ if (lease_cfg && lease_cfg->ignore6)
+ return -1;
+
/* Parse request hint for IA-PD */
if (is_pd) {
uint8_t *sdata;
struct duid *duids;
uint32_t leasetime; // duration of granted leases, UINT32_MAX = inf
char *hostname;
+ bool ignore4;
+ bool ignore6;
};
// DNR - RFC9463