]> git.ipfire.org Git - thirdparty/dhcp.git/blobdiff - server/dhcpleasequery.c
Update RELNOTES
[thirdparty/dhcp.git] / server / dhcpleasequery.c
index 9daff89493fa81d3b9ce262e71b6b91c93ed1cc6..0f1d4f77cd4b1510d5eb92de73d0857e59f4572e 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * Copyright (C) 2006-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2006-2017 by Internet Systems Consortium, Inc. ("ISC")
  *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -152,6 +152,9 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
        u_int32_t time_rebinding;
        u_int32_t time_expiry;
        u_int32_t client_last_transaction_time;
+#if defined(RELAY_PORT)
+       u_int16_t relay_port = 0;
+#endif
        struct sockaddr_in to;
        struct in_addr siaddr;
        struct data_string prl;
@@ -171,6 +174,11 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
        /* 
         * We can't reply if there is no giaddr field.
         */
+       /*
+        * Note: this makes DHCPv4-over-DHCPv6 always fail but it should not
+        * really be a problem because it is not a specified use case
+        * (or even one that makes sense).
+        */
        if (!packet->raw->giaddr.s_addr) {
                log_info("%s: missing giaddr, ciaddr is %s, no reply sent", 
                         msgbuf, inet_ntoa(packet->raw->ciaddr));
@@ -203,26 +211,16 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
                return;
        }
 
-       execute_statements_in_scope(NULL,
-                                   packet,
-                                   NULL,
-                                   NULL,
-                                   packet->options,
-                                   options,
-                                   &global_scope,
-                                   relay_group,
-                                   NULL);
+       execute_statements_in_scope(NULL, packet, NULL, NULL, packet->options,
+                                   options, &global_scope, relay_group,
+                                   NULL, NULL);
 
        for (i=packet->class_count-1; i>=0; i--) {
-               execute_statements_in_scope(NULL,
-                                           packet,
-                                           NULL,
-                                           NULL,
-                                           packet->options,
-                                           options,
+               execute_statements_in_scope(NULL, packet, NULL, NULL,
+                                           packet->options, options,
                                            &global_scope,
                                            packet->classes[i]->group,
-                                           relay_group);
+                                           relay_group, NULL);
        }
 
        /* 
@@ -454,10 +452,7 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
                        (lease_duration / 8);
 
                if (time_renewal > cur_time) {
-                       if (time_renewal < cur_time)
-                               time_renewal = 0;
-                       else
-                               time_renewal = htonl(time_renewal - cur_time);
+                       time_renewal = htonl(time_renewal - cur_time);
 
                        if (!add_option(options, 
                                        DHO_DHCP_RENEWAL_TIME,
@@ -487,15 +482,8 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
                }
 
                if (lease->ends > cur_time) {
-                       if (time_expiry < cur_time) {
-                               log_error("Impossible condition at %s:%d.",
-                                         MDL);
-
-                               option_state_dereference(&options, MDL);
-                               lease_dereference(&lease, MDL);
-                               return;
-                       }
                        time_expiry = htonl(lease->ends - cur_time);
+
                        if (!add_option(options, 
                                        DHO_DHCP_LEASE_TIME,
                                        &time_expiry, 
@@ -625,7 +613,7 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
        /*
         * Figure out which address to use to send from.
         */
-       get_server_source_address(&siaddr, options, packet);
+       get_server_source_address(&siaddr, options, options, packet);
 
        /* 
         * Set up the option buffer.
@@ -675,12 +663,20 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
 #endif
        memset(to.sin_zero, 0, sizeof(to.sin_zero));
 
+#if defined(RELAY_PORT)
+       relay_port = dhcp_check_relayport(packet);
+#endif
+
        /* 
         * Leasequery packets are be sent to the gateway address.
         */
        to.sin_addr = packet->raw->giaddr;
        if (packet->raw->giaddr.s_addr != htonl(INADDR_LOOPBACK)) {
+#if defined(RELAY_PORT)
+               to.sin_port = relay_port ? relay_port : local_port;
+#else
                to.sin_port = local_port;
+#endif
        } else {
                to.sin_port = remote_port; /* XXXSK: For debugging. */
        }
@@ -877,15 +873,9 @@ valid_query_msg(struct lq6_state *lq) {
 
 exit:
        if (!ret_val) {
-               if (lq->client_id.len > 0) {
-                       data_string_forget(&lq->client_id, MDL);
-               }
-               if (lq->server_id.len > 0) {
-                       data_string_forget(&lq->server_id, MDL);
-               }
-               if (lq->lq_query.len > 0) {
-                       data_string_forget(&lq->lq_query, MDL);
-               }
+               data_string_forget(&lq->client_id, MDL);
+               data_string_forget(&lq->server_id, MDL);
+               data_string_forget(&lq->lq_query, MDL);
        }
        return ret_val;
 }
@@ -1102,7 +1092,7 @@ dhcpv6_leasequery(struct data_string *reply_ret, struct packet *packet) {
        }
        execute_statements_in_scope(NULL, lq.packet, NULL, NULL,
                                    lq.packet->options, lq.reply_opts,
-                                   &global_scope, root_group, NULL);
+                                   &global_scope, root_group, NULL, NULL);
 
        lq.buf.reply.msg_type = DHCPV6_LEASEQUERY_REPLY;