diff --git a/CHANGELOG b/CHANGELOG index 7d0f5ce..795cbd2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -60,7 +60,7 @@ version 2.81 Fix bug which caused very rarely caused zero-length DHCPv6 packets. Thanks to Dereck Higgins for spotting this. - + version 2.80 Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method for the initial patch and motivation. diff --git a/src/rfc2131.c b/src/rfc2131.c index 0058747..033c5db 100644 --- a/src/rfc2131.c +++ b/src/rfc2131.c @@ -725,9 +725,37 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, client_hostname = daemon->dhcp_buff; } - if (client_hostname && option_bool(OPT_LOG_OPTS)) - my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), ntohl(mess->xid), client_hostname); - + if (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)) { @@ -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) { diff --git a/src/rfc3315.c b/src/rfc3315.c index 7a00c51..2ef9073 100644 --- a/src/rfc3315.c +++ b/src/rfc3315.c @@ -501,9 +501,37 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_ if (legal_hostname(daemon->dhcp_buff)) { + struct dhcp_match_name *m; + size_t nl = strlen(daemon->dhcp_buff); + state->client_hostname = daemon->dhcp_buff; + 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) { state->domain = strip_hostname(state->client_hostname); - + if (strlen(state->client_hostname) != 0) { 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) { struct dhcp_netid_list *list;