From: Alan T. DeKok Date: Mon, 23 Apr 2018 18:44:04 +0000 (-0400) Subject: add packet comparison function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c997cde030efbfd5199bd217bcc4741a7eca70f;p=thirdparty%2Ffreeradius-server.git add packet comparison function for doing dedup --- diff --git a/src/lib/io/application.h b/src/lib/io/application.h index 1d5b6c8afb6..7c7e4fd1949 100644 --- a/src/lib/io/application.h +++ b/src/lib/io/application.h @@ -111,5 +111,6 @@ typedef struct fr_app_io_t { fr_io_signal_t error; //!< There was an error on the socket. fr_io_open_t close; //!< Close the transport. fr_io_nak_t nak; //!< Function to send a NAK. + fr_io_data_cmp_t compare; //!< compare two packets void *private; //!< any private APIs it needs to export. } fr_app_io_t; diff --git a/src/lib/io/io.h b/src/lib/io/io.h index 2e48f506e91..797dc315f91 100644 --- a/src/lib/io/io.h +++ b/src/lib/io/io.h @@ -255,6 +255,32 @@ typedef int (*fr_io_data_inject_t)(void *instance,uint8_t *buffer, size_t buffer */ typedef void (*fr_io_data_vnode_t)(void *instance, uint32_t fflags); +/** Compare two packets for storing in a duplicate detection tree. + * + * We presume that the packets are well formed. + * + * The comparison should be stable. i.e. compare the packets a field + * at a time. If the field is different, return the result from that + * field. + * + * The comparison order of the fields should be "very different" to + * "much the same". The packets are put into an rbtree, so having a + * large fanout at the top is useful. + * + * Note that this function should not check if the packets are + * completely identical. Instead, if checks whether or not the + * packets take the same place in any dedup tree. + * + * @param[in] instance the context for this function + * @param[in] packet1 one packet + * @param[in] packet2 a second packet + * @return + * - <0 on packet one "smaller" than packet two + * - >0 on packet two "larger" than packet one + * - =0 on the two packets being identical + */ +typedef int (*fr_io_data_cmp_t)(void const *instance, void const *packet1, void const *packet2); + /** Handle a close or error on the socket. * * In general, the only thing to do on errors is to close the