]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[v4_2]
authorShawn Routhier <sar@isc.org>
Wed, 19 Sep 2012 21:38:53 +0000 (14:38 -0700)
committerShawn Routhier <sar@isc.org>
Wed, 19 Sep 2012 21:38:53 +0000 (14:38 -0700)
Update the memory leakage debug code to work with v6.

RELNOTES
common/options.c
doc/devel/debug.dox
omapip/alloc.c
server/salloc.c

index ebbcbdc011112b518d9ad03338fe44f15937be9b..14912a058963c11369bda5ce5c7ece75e5520528 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -98,6 +98,9 @@ work on other platforms. Please report any problems and suggested fixes to
   [ISC-Bugs #30281]
   CVE: CVE-2012-3955
 
+- Update the memory leakage debug code to work with v6.
+  [ISC-Bugs #30297]
+
                        Changes since 4.2.4rc2
 
 - None
index eccaa244a6a896784da1691ffc432b0f24934af3..51940f16dbb2a72efb19c9e9c2e05084b77aae06 100644 (file)
@@ -3749,55 +3749,51 @@ void do_packet (interface, packet, len, from_port, from, hfrom)
 #endif
 
 #if defined (TRACING)
-       trace_inpacket_stash (interface, packet, len, from_port, from, hfrom);
+       trace_inpacket_stash(interface, packet, len, from_port, from, hfrom);
 #endif
 
-       decoded_packet = (struct packet *)0;
-       if (!packet_allocate (&decoded_packet, MDL)) {
-               log_error ("do_packet: no memory for incoming packet!");
+       decoded_packet = NULL;
+       if (!packet_allocate(&decoded_packet, MDL)) {
+               log_error("do_packet: no memory for incoming packet!");
                return;
        }
-       decoded_packet -> raw = packet;
-       decoded_packet -> packet_length = len;
-       decoded_packet -> client_port = from_port;
-       decoded_packet -> client_addr = from;
-       interface_reference (&decoded_packet -> interface, interface, MDL);
-       decoded_packet -> haddr = hfrom;
-
-       if (packet -> hlen > sizeof packet -> chaddr) {
-               packet_dereference (&decoded_packet, MDL);
-               log_info ("Discarding packet with bogus hlen.");
+       decoded_packet->raw = packet;
+       decoded_packet->packet_length = len;
+       decoded_packet->client_port = from_port;
+       decoded_packet->client_addr = from;
+       interface_reference(&decoded_packet->interface, interface, MDL);
+       decoded_packet->haddr = hfrom;
+
+       if (packet->hlen > sizeof packet->chaddr) {
+               packet_dereference(&decoded_packet, MDL);
+               log_info("Discarding packet with bogus hlen.");
                return;
        }
 
        /* If there's an option buffer, try to parse it. */
-       if (decoded_packet -> packet_length >= DHCP_FIXED_NON_UDP + 4) {
-               if (!parse_options (decoded_packet)) {
-                       if (decoded_packet -> options)
+       if (decoded_packet->packet_length >= DHCP_FIXED_NON_UDP + 4) {
+               if (!parse_options(decoded_packet)) {
+                       if (decoded_packet->options)
                                option_state_dereference
-                                       (&decoded_packet -> options, MDL);
+                                       (&decoded_packet->options, MDL);
                        packet_dereference (&decoded_packet, MDL);
                        return;
                }
 
-               if (decoded_packet -> options_valid &&
-                   (op = lookup_option (&dhcp_universe,
-                                        decoded_packet -> options, 
-                                        DHO_DHCP_MESSAGE_TYPE))) {
+               if (decoded_packet->options_valid &&
+                   (op = lookup_option(&dhcp_universe,
+                                       decoded_packet->options, 
+                                       DHO_DHCP_MESSAGE_TYPE))) {
                        struct data_string dp;
-                       memset (&dp, 0, sizeof dp);
-                       evaluate_option_cache (&dp, decoded_packet,
-                                              (struct lease *)0,
-                                              (struct client_state *)0,
-                                              decoded_packet -> options,
-                                              (struct option_state *)0,
-                                              (struct binding_scope **)0,
-                                              op, MDL);
+                       memset(&dp, 0, sizeof dp);
+                       evaluate_option_cache(&dp, decoded_packet, NULL, NULL,
+                                             decoded_packet->options, NULL,
+                                             NULL, op, MDL);
                        if (dp.len > 0)
-                               decoded_packet -> packet_type = dp.data [0];
+                               decoded_packet->packet_type = dp.data[0];
                        else
-                               decoded_packet -> packet_type = 0;
-                       data_string_forget (&dp, MDL);
+                               decoded_packet->packet_type = 0;
+                       data_string_forget(&dp, MDL);
                }
        }
 
@@ -3809,19 +3805,17 @@ void do_packet (interface, packet, len, from_port, from, hfrom)
        }
 
        /* If the caller kept the packet, they'll have upped the refcnt. */
-       packet_dereference (&decoded_packet, MDL);
+       packet_dereference(&decoded_packet, MDL);
 
 #if defined (DEBUG_MEMORY_LEAKAGE)
-       log_info ("generation %ld: %ld new, %ld outstanding, %ld long-term",
-                 dmalloc_generation,
-                 dmalloc_outstanding - previous_outstanding,
-                 dmalloc_outstanding, dmalloc_longterm);
-#endif
-#if defined (DEBUG_MEMORY_LEAKAGE)
-       dmalloc_dump_outstanding ();
+       log_info("generation %ld: %ld new, %ld outstanding, %ld long-term",
+                dmalloc_generation,
+                dmalloc_outstanding - previous_outstanding,
+                dmalloc_outstanding, dmalloc_longterm);
+       dmalloc_dump_outstanding();
 #endif
 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY)
-       dump_rc_history (0);
+       dump_rc_history(0);
 #endif
 }
 
@@ -3855,6 +3849,9 @@ do_packet6(struct interface_info *interface, const char *packet,
        const struct dhcpv6_packet *msg;
        const struct dhcpv6_relay_packet *relay; 
        struct packet *decoded_packet;
+#if defined (DEBUG_MEMORY_LEAKAGE)
+       unsigned long previous_outstanding = dmalloc_outstanding;
+#endif
 
        if (!packet6_len_okay(packet, len)) {
                log_info("do_packet6: "
@@ -3882,8 +3879,8 @@ do_packet6(struct interface_info *interface, const char *packet,
        /* decoded_packet->circuit_id_len = 0; */
        /* decoded_packet->remote_id = NULL; */
        /* decoded_packet->remote_id_len = 0; */
-       decoded_packet->raw = (struct dhcp_packet *) packet;
-       decoded_packet->packet_length = (unsigned) len;
+       decoded_packet->raw = (struct dhcp_packet *)packet;
+       decoded_packet->packet_length = (unsigned)len;
        decoded_packet->client_port = from_port;
        decoded_packet->client_addr = *from;
        interface_reference(&decoded_packet->interface, interface, MDL);
@@ -3935,6 +3932,17 @@ do_packet6(struct interface_info *interface, const char *packet,
        dhcpv6(decoded_packet);
 
        packet_dereference(&decoded_packet, MDL);
+
+#if defined (DEBUG_MEMORY_LEAKAGE)
+       log_info("generation %ld: %ld new, %ld outstanding, %ld long-term",
+                dmalloc_generation,
+                dmalloc_outstanding - previous_outstanding,
+                dmalloc_outstanding, dmalloc_longterm);
+       dmalloc_dump_outstanding();
+#endif
+#if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY)
+       dump_rc_history(0);
+#endif
 }
 #endif /* DHCPv6 */
 
index 5feac16dc3fd364b225f888055028adb395a9489..f9f4696ae100d0d2bd293149563395dabb2033bf 100644 (file)
@@ -18,4 +18,16 @@ file dhcpd
 b lease_reference
 @endverbatim
 
+DEBUG_MEMORY_LEAKAGE may be defined in includes/site.h to enable some debugging
+code to help with debugging memory issues.  This code keeps a running total
+of the outstanding memory that has been allocated and a list of the outstanding
+allocations.  Both are updated whent he memory is freed.  Status information is
+printed when do_packet() and do_packet6() complete processing.  The outstanding
+value is expected to grow when new structures are used - for example when a new
+IPv6 lease is created.  It is not expected to grow when a structure is reused
+for example when an IPv6 lease is renewed.
+
+DEBUG_RC_HISTORY and DEBUG_RC_HISTORY_EXHAUSTIVELY can also be defined to provide
+more verbose information about reference counts on objects.
+
 */
index 69172a5bcc18c904bd13488cfb4abc17ac49495e..df695fb89997569a5395a84dd7570d81ef0e8ba8 100644 (file)
@@ -4,6 +4,7 @@
    protocol... */
 
 /*
+ * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1999-2003 by Internet Software Consortium
@@ -311,7 +312,7 @@ void dmalloc_dump_outstanding ()
                                inhistory = 1;
                                if (!noted) {
                                    log_info ("  %s(%d): %ld", dp -> file,
-                                             dp -> line, dp -> size);
+                                             dp -> line, (long) dp -> size);
                                    noted = 1;
                                }
                                print_rc_hist_entry (i);
@@ -324,7 +325,8 @@ void dmalloc_dump_outstanding ()
                        if (!inhistory)
 #endif
                                log_info ("  %s(%d): %ld",
-                                         dp -> file, dp -> line, dp -> size);
+                                         dp -> file, dp -> line, 
+                                         (long) dp -> size);
                }
 #endif
        }
index 17a23b50e630ddd4559f95256de81e55baa17368..da6e0798a85920b858861a5f2e317cfb826cc4ee 100644 (file)
@@ -3,7 +3,8 @@
    Memory allocation for the DHCP server... */
 
 /*
- * Copyright (c) 2004-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2009,2012 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1996-2003 by Internet Software Consortium
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -61,7 +62,9 @@ void relinquish_lease_hunks ()
                if (!c) {
                    log_info ("lease %s refcnt %d",
                              piaddr (n [i].ip_addr), n [i].refcnt);
+#if defined (DEBUG_RC_HISTORY)
                    dump_rc_history (&n [i]);
+#endif
                }
            }
        }