summaryrefslogtreecommitdiff
path: root/server/dhcp.c
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2014-10-27 14:51:20 -0400
committerThomas Markwalder <tmark@isc.org>2014-10-27 14:51:20 -0400
commit0a7e1a8ab06b462095f1aff14d07f83b5ff2e101 (patch)
tree0aeebd289ee185dd7d0f37dcd68b035140b63c02 /server/dhcp.c
parente046c826214dbf49bf8a507e4fbdc64f3394edd0 (diff)
downloadisc-dhcp-0a7e1a8ab06b462095f1aff14d07f83b5ff2e101.tar.gz
[master] Add use-host-decl-names support to BOOTP
Merges in rt36233.
Diffstat (limited to 'server/dhcp.c')
-rw-r--r--server/dhcp.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/server/dhcp.c b/server/dhcp.c
index 492487a1..f055c473 100644
--- a/server/dhcp.c
+++ b/server/dhcp.c
@@ -3216,33 +3216,10 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
}
}
- /* Use the hostname from the host declaration if there is one
+ /* Use the name of the host declaration if there is one
and no hostname has otherwise been provided, and if the
use-host-decl-name flag is set. */
- i = DHO_HOST_NAME;
- j = SV_USE_HOST_DECL_NAMES;
- if (!lookup_option (&dhcp_universe, state -> options, i) &&
- lease -> host && lease -> host -> name &&
- (evaluate_boolean_option_cache
- (&ignorep, packet, lease, (struct client_state *)0,
- packet -> options, state -> options, &lease -> scope,
- lookup_option (&server_universe, state -> options, j), MDL))) {
- oc = (struct option_cache *)0;
- if (option_cache_allocate (&oc, MDL)) {
- if (make_const_data (&oc -> expression,
- ((unsigned char *)
- lease -> host -> name),
- strlen (lease -> host -> name),
- 1, 0, MDL)) {
- option_code_hash_lookup(&oc->option,
- dhcp_universe.code_hash,
- &i, 0, MDL);
- save_option (&dhcp_universe,
- state -> options, oc);
- }
- option_cache_dereference (&oc, MDL);
- }
- }
+ use_host_decl_name(packet, lease, state->options);
/* Send client_id back if we received it and echo-client-id is on. */
echo_client_id(packet, lease, state->options, state->options);
@@ -5144,3 +5121,44 @@ maybe_return_agent_options(struct packet *packet, struct option_state *options)
options->universe_count = agent_universe.index + 1;
}
}
+
+/*!
+ * \brief Adds hostname option when use-host-decl-names is enabled.
+ *
+ * Constructs a hostname option from the name of the host declaration if
+ * there is one and no hostname has otherwise been provided and the
+ * use-host-decl-names flag is set, then adds the new option to the given
+ * option_state. This funciton is used for both bootp and dhcp.
+ *
+ * \param packet inbound packet received from the client
+ * \param lease lease associated with the client
+ * \param options option state to search and update
+ */
+void use_host_decl_name(struct packet* packet,
+ struct lease *lease,
+ struct option_state *options) {
+ unsigned int ocode = SV_USE_HOST_DECL_NAMES;
+ if ((lease->host && lease->host->name) &&
+ !lookup_option(&dhcp_universe, options, DHO_HOST_NAME) &&
+ (evaluate_boolean_option_cache(NULL, packet, lease, NULL,
+ packet->options, options,
+ &lease->scope,
+ lookup_option(&server_universe,
+ options, ocode),
+ MDL))) {
+ struct option_cache *oc = NULL;
+ if (option_cache_allocate (&oc, MDL)) {
+ if (make_const_data(&oc -> expression,
+ ((unsigned char*)lease->host->name),
+ strlen(lease->host->name),
+ 1, 0, MDL)) {
+ ocode = DHO_HOST_NAME;
+ option_code_hash_lookup(&oc->option,
+ dhcp_universe.code_hash,
+ &ocode, 0, MDL);
+ save_option(&dhcp_universe, options, oc);
+ }
+ option_cache_dereference(&oc, MDL);
+ }
+ }
+}