]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[master]
authorShawn Routhier <sar@isc.org>
Thu, 31 Oct 2013 21:09:24 +0000 (14:09 -0700)
committerShawn Routhier <sar@isc.org>
Thu, 31 Oct 2013 21:09:24 +0000 (14:09 -0700)
Add log messages for when the addresses we assign.

RELNOTES
server/dhcpv6.c

index 6c1ec67907e08b77acecf37fb6bab195f219c021..358464dee3d208319cb618e5b1e01411029dda16 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -132,6 +132,10 @@ work on other platforms. Please report any problems and suggested fixes to
 - Added support for gentle shutdown after signal is received.
   [ISC-BUGS #32692]
 
+- Enhance the DHCPv6 server logging to include the addresses that are assigned
+  to the clients.
+  [ISC-Bugs #26377]
+
                        Changes since 4.2.4
 
 - Correct code to calculate timing values in client to compare
index 4f150511ea074a950f13f4aa4f4453a4ed51fb11..6daba5e4b77365ff2f81f832c4dd882f334831b7 100644 (file)
@@ -61,6 +61,7 @@ struct reply_state {
        struct ia_xx *old_ia;
        struct option_state *reply_ia;
        struct data_string fixed;
+       struct iaddrcidrnet fixed_pref; /* static prefix for logging */
 
        /* IAADDR/PREFIX level persistent state */
        struct iasubopt *lease;
@@ -1895,6 +1896,62 @@ reply_process_ia_na(struct reply_state *reply, struct option_cache *ia) {
        }
        putULong(reply->buf.data + ia_cursor + 12, reply->rebind);
 
+       /*
+        * yes, goto's aren't the best but we also want to avoid extra
+        * indents
+        */
+       if (status == ISC_R_CANCELED)
+               goto cleanup;
+
+       /*
+        * Handle static leases, we always log stuff and if it's
+        * a hard binding we run any commit statements that we have
+        */
+       if (reply->static_lease) {
+               char tmp_addr[INET6_ADDRSTRLEN];
+               log_info("%s NA: address %s to client with duid %s iaid = %d "
+                        "static",
+                        dhcpv6_type_names[reply->buf.reply.msg_type],
+                        inet_ntop(AF_INET6, reply->fixed.data, tmp_addr,
+                                  sizeof(tmp_addr)),
+                        print_hex_1(reply->client_id.len,
+                                    reply->client_id.data, 60),
+                        iaid);
+
+               if ((reply->buf.reply.msg_type == DHCPV6_REPLY) &&
+                   (reply->on_star.on_commit != NULL)) {
+                       execute_statements(NULL, reply->packet, NULL, NULL, 
+                                          reply->packet->options,
+                                          reply->opt_state, NULL,
+                                          reply->on_star.on_commit, NULL);
+                       executable_statement_dereference
+                               (&reply->on_star.on_commit, MDL);
+               }
+               goto cleanup;
+       }
+
+       /*
+        * If we have any addresses log what we are doing.
+        */
+       if (reply->ia->num_iasubopt != 0) {
+               struct iasubopt *tmp;
+               int i;
+               char tmp_addr[INET6_ADDRSTRLEN];
+
+               for (i = 0 ; i < reply->ia->num_iasubopt ; i++) {
+                       tmp = reply->ia->iasubopt[i];
+
+                       log_info("%s NA: address %s to client with duid %s "
+                                "iaid = %d valid for %d seconds",
+                                dhcpv6_type_names[reply->buf.reply.msg_type],
+                                inet_ntop(AF_INET6, &tmp->addr,
+                                          tmp_addr, sizeof(tmp_addr)),
+                                print_hex_1(reply->client_id.len,
+                                            reply->client_id.data, 60),
+                                iaid, tmp->valid);
+               }
+       }
+
        /*
         * If this is not a 'soft' binding, consume the new changes into
         * the database (if any have been attached to the ia_na).
@@ -1903,9 +1960,9 @@ reply_process_ia_na(struct reply_state *reply, struct option_cache *ia) {
         * leases onto this IA_NA rather than any old ones, and updating
         * pool timers for each (if any).
         */
-       if ((status != ISC_R_CANCELED) && !reply->static_lease &&
-           (reply->buf.reply.msg_type == DHCPV6_REPLY) &&
-           (reply->ia->num_iasubopt != 0)) {
+
+       if ((reply->ia->num_iasubopt != 0) &&
+           (reply->buf.reply.msg_type == DHCPV6_REPLY)) {
                struct iasubopt *tmp;
                struct data_string *ia_id;
                int i;
@@ -1971,20 +2028,6 @@ reply_process_ia_na(struct reply_state *reply, struct option_cache *ia) {
                write_ia(reply->ia);
        }
 
-       /*
-        * If this would be a hard binding for a static lease
-        * run any commit statements that we have
-        */
-       if ((status != ISC_R_CANCELED) && reply->static_lease &&
-           (reply->buf.reply.msg_type == DHCPV6_REPLY) &&
-           (reply->on_star.on_commit != NULL)) {
-               execute_statements(NULL, reply->packet, NULL, NULL, 
-                                  reply->packet->options, reply->opt_state,
-                                  NULL, reply->on_star.on_commit, NULL);
-               executable_statement_dereference
-                       (&reply->on_star.on_commit, MDL);
-       }
-
       cleanup:
        if (packet_ia != NULL)
                option_state_dereference(&packet_ia, MDL);
@@ -2597,16 +2640,45 @@ reply_process_ia_ta(struct reply_state *reply, struct option_cache *ia) {
                  reply->cursor - (ia_cursor + 4));
 
        /*
-        * Consume the new changes into the database (if any have been
-        * attached to the ia_ta).
+        * yes, goto's aren't the best but we also want to avoid extra
+        * indents
+        */
+       if (status == ISC_R_CANCELED)
+               goto cleanup;
+
+       /*
+        * If we have any addresses log what we are doing.
+        */
+       if (reply->ia->num_iasubopt != 0) {
+               struct iasubopt *tmp;
+               int i;
+               char tmp_addr[INET6_ADDRSTRLEN];
+
+               for (i = 0 ; i < reply->ia->num_iasubopt ; i++) {
+                       tmp = reply->ia->iasubopt[i];
+
+                       log_info("%s TA: address %s to client with duid %s "
+                                "iaid = %d valid for %d seconds",
+                                dhcpv6_type_names[reply->buf.reply.msg_type],
+                                inet_ntop(AF_INET6, &tmp->addr,
+                                          tmp_addr, sizeof(tmp_addr)),
+                                print_hex_1(reply->client_id.len,
+                                            reply->client_id.data, 60),
+                                iaid,
+                                tmp->valid);
+               }
+       }
+
+       /*
+        * For hard bindings we consume the new changes into
+        * the database (if any have been attached to the ia_ta).
         *
         * Loop through the assigned dynamic addresses, referencing the
         * leases onto this IA_TA rather than any old ones, and updating
         * pool timers for each (if any).
         */
-       if ((status != ISC_R_CANCELED) &&
-           (reply->buf.reply.msg_type == DHCPV6_REPLY) &&
-           (reply->ia->num_iasubopt != 0)) {
+       if ((reply->ia->num_iasubopt != 0) &&
+           (reply->buf.reply.msg_type == DHCPV6_REPLY)) {
                struct iasubopt *tmp;
                struct data_string *ia_id;
                int i;
@@ -3615,6 +3687,64 @@ reply_process_ia_pd(struct reply_state *reply, struct option_cache *ia) {
        }
        putULong(reply->buf.data + ia_cursor + 12, reply->rebind);
 
+       /*
+        * yes, goto's aren't the best but we also want to avoid extra
+        * indents
+        */
+       if (status == ISC_R_CANCELED)
+               goto cleanup;
+
+       /*
+        * Handle static prefixes, we always log stuff and if it's
+        * a hard binding we run any commit statements that we have
+        */
+       if (reply->static_prefixes != 0) {
+               char tmp_addr[INET6_ADDRSTRLEN];
+               log_info("%s PD: address %s/%d to client with duid %s "
+                        "iaid = %d static",
+                        dhcpv6_type_names[reply->buf.reply.msg_type],
+                        inet_ntop(AF_INET6, reply->fixed_pref.lo_addr.iabuf,
+                                  tmp_addr, sizeof(tmp_addr)),
+                        reply->fixed_pref.bits,
+                        print_hex_1(reply->client_id.len,
+                                    reply->client_id.data, 60),
+                        iaid);
+               if ((reply->buf.reply.msg_type == DHCPV6_REPLY) &&
+                   (reply->on_star.on_commit != NULL)) {
+                       execute_statements(NULL, reply->packet, NULL, NULL,
+                                          reply->packet->options,
+                                          reply->opt_state,
+                                          NULL, reply->on_star.on_commit,
+                                          NULL);
+                       executable_statement_dereference
+                               (&reply->on_star.on_commit, MDL);
+               }
+               goto cleanup;
+       }
+
+       /*
+        * If we have any addresses log what we are doing.
+        */
+       if (reply->ia->num_iasubopt != 0) {
+               struct iasubopt *tmp;
+               int i;
+               char tmp_addr[INET6_ADDRSTRLEN];
+
+               for (i = 0 ; i < reply->ia->num_iasubopt ; i++) {
+                       tmp = reply->ia->iasubopt[i];
+
+                       log_info("%s PD: address %s/%d to client with duid %s"
+                                " iaid = %d valid for %d seconds",
+                                dhcpv6_type_names[reply->buf.reply.msg_type],
+                                inet_ntop(AF_INET6, &tmp->addr,
+                                          tmp_addr, sizeof(tmp_addr)),
+                                (int)tmp->plen,
+                                print_hex_1(reply->client_id.len,
+                                            reply->client_id.data, 60),
+                                iaid, tmp->valid);
+               }
+       }
+
        /*
         * If this is not a 'soft' binding, consume the new changes into
         * the database (if any have been attached to the ia_pd).
@@ -3623,8 +3753,7 @@ reply_process_ia_pd(struct reply_state *reply, struct option_cache *ia) {
         * prefixes onto this IA_PD rather than any old ones, and updating
         * prefix pool timers for each (if any).
         */
-       if ((status != ISC_R_CANCELED) && (reply->static_prefixes == 0) &&
-           (reply->buf.reply.msg_type == DHCPV6_REPLY) &&
+       if ((reply->buf.reply.msg_type == DHCPV6_REPLY) &&
            (reply->ia->num_iasubopt != 0)) {
                struct iasubopt *tmp;
                struct data_string *ia_id;
@@ -3673,20 +3802,6 @@ reply_process_ia_pd(struct reply_state *reply, struct option_cache *ia) {
                write_ia(reply->ia);
        }
 
-       /*
-        * If this would be a hard binding for a static lease
-        * run any commit statements that we have
-        */
-       if ((status != ISC_R_CANCELED) && reply->static_prefixes != 0 &&
-           (reply->buf.reply.msg_type == DHCPV6_REPLY) &&
-           (reply->on_star.on_commit != NULL)) {
-               execute_statements(NULL, reply->packet, NULL, NULL, 
-                                  reply->packet->options, reply->opt_state,
-                                  NULL, reply->on_star.on_commit, NULL);
-               executable_statement_dereference
-                       (&reply->on_star.on_commit, MDL);
-       }
-
       cleanup:
        if (packet_ia != NULL)
                option_state_dereference(&packet_ia, MDL);
@@ -3880,6 +3995,9 @@ reply_process_prefix(struct reply_state *reply, struct option_cache *pref) {
                        log_fatal("Impossible condition at %s:%d.", MDL);
                group = reply->subnet->group;
                subnet_dereference(&reply->subnet, MDL);
+
+               /* Copy the static prefix for logging purposes */
+               memcpy(&reply->fixed_pref, &tmp_pref, sizeof(tmp_pref));
        } else {
                if (reply->lease == NULL)
                        log_fatal("Impossible condition at %s:%d.", MDL);
@@ -4127,6 +4245,9 @@ find_client_prefix(struct reply_state *reply) {
                group = reply->subnet->group;
                subnet_dereference(&reply->subnet, MDL);
 
+               /* Copy the prefix for logging purposes */
+               memcpy(&reply->fixed_pref, &l->cidrnet, sizeof(send_pref));
+
                goto send_pref;
        }