]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add packet comparison function
authorAlan T. DeKok <aland@freeradius.org>
Mon, 23 Apr 2018 18:44:04 +0000 (14:44 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 25 Apr 2018 16:53:44 +0000 (12:53 -0400)
for doing dedup

src/lib/io/application.h
src/lib/io/io.h

index 1d5b6c8afb6ad2ca35f7227466e25f3734fa7783..7c7e4fd1949e5897afd6dad7a63826c2cf34276e 100644 (file)
@@ -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;
index 2e48f506e916945a6c5cd5e57d552d1a1be43433..797dc315f91b4f3ced2465920aad1a6814416448 100644 (file)
@@ -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