mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Add tag filtering of dhcp-host directives.
This commit is contained in:
@@ -304,11 +304,12 @@ static int is_config_in_context(struct dhcp_context *context, struct dhcp_config
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
struct dhcp_context *context,
|
||||
unsigned char *clid, int clid_len,
|
||||
unsigned char *hwaddr, int hw_len,
|
||||
int hw_type, char *hostname)
|
||||
static struct dhcp_config *find_config_match(struct dhcp_config *configs,
|
||||
struct dhcp_context *context,
|
||||
unsigned char *clid, int clid_len,
|
||||
unsigned char *hwaddr, int hw_len,
|
||||
int hw_type, char *hostname,
|
||||
struct dhcp_netid *tags, int tag_not_needed)
|
||||
{
|
||||
int count, new;
|
||||
struct dhcp_config *config, *candidate;
|
||||
@@ -320,7 +321,9 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
{
|
||||
if (config->clid_len == clid_len &&
|
||||
memcmp(config->clid, clid, clid_len) == 0 &&
|
||||
is_config_in_context(context, config))
|
||||
is_config_in_context(context, config) &&
|
||||
match_netid(config->filter, tags, tag_not_needed))
|
||||
|
||||
return config;
|
||||
|
||||
/* dhcpcd prefixes ASCII client IDs by zero which is wrong, but we try and
|
||||
@@ -328,7 +331,8 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
see lease_update_from_configs() */
|
||||
if ((!context || !(context->flags & CONTEXT_V6)) && *clid == 0 && config->clid_len == clid_len-1 &&
|
||||
memcmp(config->clid, clid+1, clid_len-1) == 0 &&
|
||||
is_config_in_context(context, config))
|
||||
is_config_in_context(context, config) &&
|
||||
match_netid(config->filter, tags, tag_not_needed))
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -336,14 +340,16 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
if (hwaddr)
|
||||
for (config = configs; config; config = config->next)
|
||||
if (config_has_mac(config, hwaddr, hw_len, hw_type) &&
|
||||
is_config_in_context(context, config))
|
||||
is_config_in_context(context, config) &&
|
||||
match_netid(config->filter, tags, tag_not_needed))
|
||||
return config;
|
||||
|
||||
if (hostname && context)
|
||||
for (config = configs; config; config = config->next)
|
||||
if ((config->flags & CONFIG_NAME) &&
|
||||
hostname_isequal(config->hostname, hostname) &&
|
||||
is_config_in_context(context, config))
|
||||
is_config_in_context(context, config) &&
|
||||
match_netid(config->filter, tags, tag_not_needed))
|
||||
return config;
|
||||
|
||||
|
||||
@@ -352,7 +358,8 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
|
||||
/* use match with fewest wildcard octets */
|
||||
for (candidate = NULL, count = 0, config = configs; config; config = config->next)
|
||||
if (is_config_in_context(context, config))
|
||||
if (is_config_in_context(context, config) &&
|
||||
match_netid(config->filter, tags, tag_not_needed))
|
||||
for (conf_addr = config->hwaddr; conf_addr; conf_addr = conf_addr->next)
|
||||
if (conf_addr->wildcard_mask != 0 &&
|
||||
conf_addr->hwaddr_len == hw_len &&
|
||||
@@ -366,6 +373,21 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
return candidate;
|
||||
}
|
||||
|
||||
/* Find tagged configs first. */
|
||||
struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||
struct dhcp_context *context,
|
||||
unsigned char *clid, int clid_len,
|
||||
unsigned char *hwaddr, int hw_len,
|
||||
int hw_type, char *hostname, struct dhcp_netid *tags)
|
||||
{
|
||||
struct dhcp_config *ret = find_config_match(configs, context, clid, clid_len, hwaddr, hw_len, hw_type, hostname, tags, 0);
|
||||
|
||||
if (!ret)
|
||||
ret = find_config_match(configs, context, clid, clid_len, hwaddr, hw_len, hw_type, hostname, tags, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dhcp_update_configs(struct dhcp_config *configs)
|
||||
{
|
||||
/* Some people like to keep all static IP addresses in /etc/hosts.
|
||||
|
||||
Reference in New Issue
Block a user