Reference counting (devel. question) (fwd)

David W. Hankins David_Hankins at isc.org
Fri May 27 19:07:26 UTC 2005


On Fri, May 27, 2005 at 10:49:31AM +0200, Erik Alap?? wrote:
> I am using the ISC DHCP code (3.0.2) as a starting poing for
> developing a DHCP relay that, in addition to providing normal relay
> function, also will "sniff" the DHCP packets and send some information
> to a proprietary system. My question concerns reference counting. I am
> using the dhcrelay code, but am trying to reuse some of the
> packet-decoding functions that are used by dhclient and dhcpd. The
> problem is that it seems that this code (function do_packet() in
> common/options.c and the functions it calls) are decrementing a
> reference count to the decoded packet. Therefore, later code in the
> relay does not get to handle the packet appropriately.

Your dhcp() or bootp() function should packet_reference() the pointer
that is passed to it onto some structure, if it needs to retain the
reference to the decoded packet after it exits.

When an object is created, it starts with a reference count of 1.
When you attach an object to another, you want to blah_reference()
it, to increment that counter...when you're done with it,
blah_dereference() will both decrement the counter and null out your
pointer...if the reference count reaches zero, it is freed.


Does that help?

-- 
David W. Hankins		"If you don't do it right the first time,
Software Engineer			you'll just have to do it again."
Internet Systems Consortium, Inc.		-- Jack T. Hankins


More information about the dhcp-hackers mailing list