[kea-dev] Accessing DHCP options within hooks libs

Francis Dupont fdupont at isc.org
Tue Jun 21 19:49:07 UTC 2016


Francis Dupont writes:
> We are using smart pointers, not raw pointers, so perhaps it is
> possible to implement a kind of copy on write?
> 
> PS: usually COW in C++ is done playing on const/not const.

=> revisiting the #4497 ticket and its associated discussio I add
a point: there is a trivial way to deep copy a packet (or an option):
just pack it and unpack the result, i.e., the opposite of the repack
method of pkt.h:

    /// @brief Copies content of input buffer to output buffer.
    ///
    /// This is mostly a diagnostic function. It is being used for sending
    /// received packet. Received packet is stored in data_, but
    /// transmitted data is stored in buffer_out_. If we want to send packet
    /// that we just received, a copy between those two buffers is necessary.
    void repack();
			    
BTW even it is a reunpack() IMHO something like deepcopy() is a better
(and less misleading) name.

Regards

Francis Dupont <fdupont at isc.org>

PS: sample code (with X = 4 or 6) for a packet:

void deepCopy(PktXPtr& pkt) {
    pkt->pack();
    OutputBuffer& buf(pkt->getBuffer());
    pkt.reset(new PktX(&buf[0], buf.size(),
                       pkt->getLocalAddr(),
                       pkt->getRemoteAddr(),
                       pkt->getLocalPort(),
                       pkt->getRemotePort()));
}


More information about the kea-dev mailing list