Fix dhcp-name-match to always match client-supplied name.

This modifies commit 6ebdc95754.
This commit is contained in:
Simon Kelley
2019-12-05 23:44:29 +00:00
parent 0c211c4ec5
commit 34d41475e7
3 changed files with 63 additions and 67 deletions

View File

@@ -60,7 +60,7 @@ version 2.81
Fix bug which caused very rarely caused zero-length DHCPv6 packets. Fix bug which caused very rarely caused zero-length DHCPv6 packets.
Thanks to Dereck Higgins for spotting this. Thanks to Dereck Higgins for spotting this.
version 2.80 version 2.80
Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method
for the initial patch and motivation. for the initial patch and motivation.

View File

@@ -725,9 +725,37 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
client_hostname = daemon->dhcp_buff; client_hostname = daemon->dhcp_buff;
} }
if (client_hostname && option_bool(OPT_LOG_OPTS)) if (client_hostname)
my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), ntohl(mess->xid), client_hostname); {
struct dhcp_match_name *m;
size_t nl = strlen(client_hostname);
if (option_bool(OPT_LOG_OPTS))
my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), ntohl(mess->xid), client_hostname);
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 = client_hostname[ml];
client_hostname[ml] = 0;
}
if (hostname_isequal(client_hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = netid;
netid = m->netid;
}
if (save != 0)
client_hostname[ml] = save;
}
}
if (have_config(config, CONFIG_NAME)) if (have_config(config, CONFIG_NAME))
{ {
@@ -765,36 +793,6 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
} }
} }
} }
if (hostname)
{
struct dhcp_match_name *m;
size_t nl = strlen(hostname);
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 = hostname[ml];
hostname[ml] = 0;
}
if (hostname_isequal(hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = netid;
netid = m->netid;
}
if (save != 0)
hostname[ml] = save;
}
}
if (config) if (config)
{ {

View File

@@ -501,9 +501,37 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
if (legal_hostname(daemon->dhcp_buff)) if (legal_hostname(daemon->dhcp_buff))
{ {
struct dhcp_match_name *m;
size_t nl = strlen(daemon->dhcp_buff);
state->client_hostname = daemon->dhcp_buff; state->client_hostname = daemon->dhcp_buff;
if (option_bool(OPT_LOG_OPTS)) if (option_bool(OPT_LOG_OPTS))
my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), state->xid, state->client_hostname); my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), state->xid, state->client_hostname);
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;
}
} }
} }
} }
@@ -519,7 +547,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
else if (state->client_hostname) else if (state->client_hostname)
{ {
state->domain = strip_hostname(state->client_hostname); state->domain = strip_hostname(state->client_hostname);
if (strlen(state->client_hostname) != 0) if (strlen(state->client_hostname) != 0)
{ {
state->hostname = state->client_hostname; state->hostname = state->client_hostname;
@@ -535,37 +563,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
} }
} }
} }
if (state->hostname)
{
struct dhcp_match_name *m;
size_t nl = strlen(state->hostname);
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->hostname[ml];
state->hostname[ml] = 0;
}
if (hostname_isequal(state->hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = state->tags;
state->tags = m->netid;
}
if (save != 0)
state->hostname[ml] = save;
}
}
if (config) if (config)
{ {
struct dhcp_netid_list *list; struct dhcp_netid_list *list;