Fix dhcp-match-name to match hostname, not complete FQDN.

Also do name matching for DHCPv6.
This commit is contained in:
Simon Kelley
2018-10-05 23:35:54 +01:00
parent ee1df06aab
commit 0fdf3c1f61
2 changed files with 60 additions and 33 deletions

View File

@@ -496,11 +496,16 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
}
else if (state->client_hostname)
{
struct dhcp_match_name *m;
size_t nl;
state->domain = strip_hostname(state->client_hostname);
nl = strlen(state->client_hostname);
if (strlen(state->client_hostname) != 0)
{
state->hostname = state->client_hostname;
if (!config)
{
/* Search again now we have a hostname.
@@ -510,6 +515,30 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
if (new && !have_config(new, CONFIG_CLID) && !new->hwaddr)
config = new;
}
for (m = daemon->dhcp_name_match; m; m = m->next)
{
size_t ml = strlen(m->name);
char save = 0;
if (nl < ml)
continue;
if (nl > ml)
{
save = state->client_hostname[ml];
state->client_hostname[ml] = 0;
}
if (hostname_isequal(state->client_hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = state->tags;
state->tags = m->netid;
}
if (save != 0)
state->client_hostname[ml] = save;
}
}
}
}