summaryrefslogtreecommitdiff
path: root/server
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
parente046c826214dbf49bf8a507e4fbdc64f3394edd0 (diff)
downloadisc-dhcp-0a7e1a8ab06b462095f1aff14d07f83b5ff2e101.tar.gz
[master] Add use-host-decl-names support to BOOTP
Merges in rt36233.
Diffstat (limited to 'server')
-rw-r--r--server/bootp.c57
-rw-r--r--server/dhcp.c68
2 files changed, 77 insertions, 48 deletions
diff --git a/server/bootp.c b/server/bootp.c
index 41528204..ca54be64 100644
--- a/server/bootp.c
+++ b/server/bootp.c
@@ -170,29 +170,29 @@ void bootp (packet)
/* Execute the host statements. */
if (hp != NULL) {
- execute_statements_in_scope (NULL, packet, lease, NULL,
- packet->options, options,
- &lease->scope, hp->group,
- lease->subnet->group, NULL);
+ execute_statements_in_scope(NULL, packet, lease, NULL,
+ packet->options, options,
+ &lease->scope, hp->group,
+ lease->subnet->group, NULL);
}
/* Drop the request if it's not allowed for this client. */
if ((oc = lookup_option (&server_universe, options, SV_ALLOW_BOOTP)) &&
- !evaluate_boolean_option_cache (&ignorep, packet, lease,
- (struct client_state *)0,
- packet -> options, options,
- &lease -> scope, oc, MDL)) {
+ !evaluate_boolean_option_cache(&ignorep, packet, lease,
+ NULL,
+ packet->options, options,
+ &lease->scope, oc, MDL)) {
if (!ignorep)
log_info ("%s: bootp disallowed", msgbuf);
goto out;
}
- if ((oc = lookup_option (&server_universe,
+ if ((oc = lookup_option(&server_universe,
options, SV_ALLOW_BOOTING)) &&
- !evaluate_boolean_option_cache (&ignorep, packet, lease,
- (struct client_state *)0,
- packet -> options, options,
- &lease -> scope, oc, MDL)) {
+ !evaluate_boolean_option_cache(&ignorep, packet, lease,
+ NULL,
+ packet->options, options,
+ &lease->scope, oc, MDL)) {
if (!ignorep)
log_info ("%s: booting disallowed", msgbuf);
goto out;
@@ -205,20 +205,26 @@ void bootp (packet)
/* If we didn't get a known vendor magic number on the way in,
just copy the input options to the output. */
- if (!packet -> options_valid &&
- !(evaluate_boolean_option_cache
- (&ignorep, packet, lease, (struct client_state *)0,
- packet -> options, options, &lease -> scope,
- lookup_option (&server_universe, options,
- SV_ALWAYS_REPLY_RFC1048), MDL))) {
- memcpy (outgoing.raw -> options,
- packet -> raw -> options, DHCP_MAX_OPTION_LEN);
- outgoing.packet_length = BOOTP_MIN_LEN;
+ i = SV_ALWAYS_REPLY_RFC1048;
+ if (!packet->options_valid &&
+ !(evaluate_boolean_option_cache(&ignorep, packet, lease, NULL,
+ packet->options, options,
+ &lease->scope,
+ lookup_option (&server_universe,
+ options, i), MDL))) {
+ if (packet->packet_length > DHCP_FIXED_NON_UDP) {
+ memcpy(outgoing.raw->options, packet->raw->options,
+ packet->packet_length - DHCP_FIXED_NON_UDP);
+ }
+
+ outgoing.packet_length =
+ (packet->packet_length < BOOTP_MIN_LEN)
+ ? BOOTP_MIN_LEN
+ : packet->packet_length;
} else {
/* Use the subnet mask from the subnet declaration if no other
mask has been provided. */
-
oc = (struct option_cache *)0;
i = DHO_SUBNET_MASK;
if (!lookup_option (&dhcp_universe, options, i)) {
@@ -238,6 +244,11 @@ void bootp (packet)
}
}
+ /* If use-host-decl-names is enabled and there is a hostname
+ * defined in the host delcartion, send it back in hostname
+ * option */
+ use_host_decl_name(packet, lease, options);
+
/* Pack the options into the buffer. Unlike DHCP, we
can't pack options into the filename and server
name buffers. */
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);
+ }
+ }
+}