Alloc connections pools in the NULL ctx
[freeradius.git] / src / include / libradius.h
index 22d67f2..25a24c3 100644 (file)
 RCSIDH(libradius_h, "$Id$")
 
 /*
- *  Preprocessor hacks.
+ *  Compiler hinting macros.  Included here for 3rd party consumers
+ *  of libradius.h.
  */
-#ifndef STRINGIFY
-#  define XSTRINGIFY(x) #x
-#  define STRINGIFY(x) XSTRINGIFY(x)
-#endif
-
-#ifndef HEXIFY
-#  define XHEXIFY4(b1,b2,b3,b4)        (0x ## b1 ## b2 ## b3 ## b4)
-#  define HEXIFY4(b1,b2,b3,b4) XHEXIFY4(b1, b2, b3, b4)
-
-#  define XHEXIFY3(b1,b2,b3)   (0x ## b1 ## b2 ## b3)
-#  define HEXIFY3(b1,b2,b3)    XHEXIFY3(b1, b2, b3)
-
-#  define XHEXIFY2(b1,b2)      (0x ## b1 ## b2)
-#  define HEXIFY2(b1,b2)       XHEXIFY2(b1, b2)
-
-#  define XHEXIFY(b1)          (0x ## b1)
-#  define HEXIFY(b1)           XHEXIFY(b1)
-#endif
+#include <freeradius-devel/build.h>
 
 /*
  *  Let any external program building against the library know what
@@ -89,6 +73,10 @@ RCSIDH(libradius_h, "$Id$")
 #include <stdbool.h>
 #include <signal.h>
 
+#ifdef HAVE_LIMITS_H
+#  include <limits.h>
+#endif
+
 #include <freeradius-devel/threads.h>
 #include <freeradius-devel/radius.h>
 #include <freeradius-devel/token.h>
@@ -111,39 +99,25 @@ extern "C" {
 #endif
 
 #if defined(WITH_VERIFY_PTR)
-/*
- *     Requires typeof(), which is in most modern C compilers.
- */
-
-/*
-#define VERIFY_VP(_x) do { (void) talloc_get_type_abort(_x, VALUE_PAIR); \
-                       if (_x->da) { \
-                               (void) talloc_get_type_abort(_x->da, DICT_ATTR); \
-                       } \
-                     } while (0)
-*/
 #  define FREE_MAGIC (0xF4EEF4EE)
 
-#  define VERIFY_VP(_x) \
-do {\
-       (void) talloc_get_type_abort(_x, VALUE_PAIR);\
-       if (_x->data.ptr) switch (_x->da->type) {\
-       case PW_TYPE_OCTETS:\
-       case PW_TYPE_TLV:\
-               (void) talloc_get_type_abort(_x->data.ptr, uint8_t);\
-               break;\
-       case PW_TYPE_STRING:\
-               (void) talloc_get_type_abort(_x->data.ptr, char);\
-               break;\
-       default:\
-               break;\
-       }\
-} while (0)\
-
-#  define VERIFY_PACKET(_x) (void) talloc_get_type_abort(_x, RADIUS_PACKET)
+/*
+ * @FIXME
+ *  Add if (_x->da) (void) talloc_get_type_abort(_x->da, DICT_ATTR);
+ *  to the macro below when dictionaries are talloced.
+ */
+#  define VERIFY_VP(_x)                fr_verify_vp(__FILE__,  __LINE__, _x)
+#  define VERIFY_LIST(_x)      fr_verify_list(__FILE__,  __LINE__, NULL, _x)
+#  define VERIFY_PACKET(_x)    (void) talloc_get_type_abort(_x, RADIUS_PACKET)
 #else
-#  define VERIFY_VP(_x)
-#  define VERIFY_PACKET(_x)
+/*
+ *  Even if were building without WITH_VERIFY_PTR
+ *  the pointer must not be NULL when these various macros are used
+ *  so we can add some sneaky soft asserts.
+ */
+#  define VERIFY_VP(_x)                fr_assert(_x)
+#  define VERIFY_LIST(_x)      fr_assert(_x)
+#  define VERIFY_PACKET(_x)    fr_assert(_x)
 #endif
 
 #define AUTH_VECTOR_LEN                16
@@ -165,22 +139,26 @@ do {\
 
 #define TAG_VALID(x)           ((x) > 0 && (x) < 0x20)
 #define TAG_VALID_ZERO(x)      ((x) < 0x20)
-#define TAG_ANY                        -128    /* minimum signed char */
-#define TAG_UNUSED             0
+#define TAG_ANY                        INT8_MIN
+#define TAG_NONE               0
+/** Check if tags are equal
+ *
+ * @param _x tag were matching on.
+ * @param _y tag belonging to the attribute were checking.
+ */
+#define TAG_EQ(_x, _y) ((_x == _y) || (_x == TAG_ANY) || ((_x == TAG_NONE) && (_y == TAG_ANY)))
+#define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da) && (!_x->da->flags.has_tag || TAG_EQ(_x->tag, _y->tag)))
+
+#define NUM_ANY                        INT_MIN
+#define NUM_JOIN               (INT_MIN + 1)
+#define NUM_COUNT              (INT_MIN + 2)
 
 #define PAD(_x, _y)            (_y - ((_x) % _y))
 
-#if defined(__GNUC__)
-#  define PRINTF_LIKE(n) __attribute__ ((format(printf, n, n+1)))
-#  define NEVER_RETURNS __attribute__ ((noreturn))
-#  define UNUSED __attribute__ ((unused))
-#  define BLANK_FORMAT " "     /* GCC_LINT whines about empty formats */
-#else
-#  define PRINTF_LIKE(n)       /* ignore */
-#  define NEVER_RETURNS /* ignore */
-#  define UNUSED /* ignore */
-#  define BLANK_FORMAT ""
-#endif
+#define PRINTF_LIKE(n)         CC_HINT(format(printf, n, n+1))
+#define NEVER_RETURNS          CC_HINT(noreturn)
+#define UNUSED                 CC_HINT(unused)
+#define BLANK_FORMAT           " "     /* GCC_LINT whines about empty formats */
 
 typedef struct attr_flags {
        unsigned int    is_unknown : 1;                         //!< Attribute number or vendor is unknown.
@@ -250,7 +228,7 @@ typedef struct dict_vendor {
 
 /** Union containing all data types supported by the server
  *
- * This union contains all data types that can be represented with VALUE_PAIRs. It may also be used in other parts
+ * This union contains all data types that can be represented by VALUE_PAIRs. It may also be used in other parts
  * of the server where values of different types need to be stored.
  *
  * PW_TYPE should be an enumeration of the values in this union.
@@ -264,9 +242,9 @@ typedef union value_data {
        size_t                  filter[32/sizeof(size_t)];      //!< Ascend binary format a packed data
                                                                //!< structure.
 
-       uint8_t                 ifid[8]; /* struct? */          //!< IPv6 interface ID.
+       uint8_t                 ifid[8];                        //!< IPv6 interface ID (should be struct?).
        struct in6_addr         ipv6addr;                       //!< IPv6 Address.
-       uint8_t                 ipv6prefix[18]; /* struct? */   //!< IPv6 prefix.
+       uint8_t                 ipv6prefix[18];                 //!< IPv6 prefix (should be struct?).
 
        uint8_t                 byte;                           //!< 8bit unsigned integer.
        uint16_t                ushort;                         //!< 16bit unsigned integer.
@@ -276,7 +254,7 @@ typedef union value_data {
        int32_t                 sinteger;                       //!< 32bit signed integer.
        uint64_t                integer64;                      //!< 64bit unsigned integer.
 
-       uint8_t                 ipv4prefix[6]; /* struct? */    //!< IPv4 prefix.
+       uint8_t                 ipv4prefix[6];                  //!< IPv4 prefix (should be struct?).
 
        uint8_t                 *tlv;                           //!< Nested TLV (should go away).
        void const              *ptr;                           //!< generic pointer.
@@ -299,8 +277,7 @@ typedef enum value_type {
 
 /** Stores an attribute, a value and various bits of other data
  *
- * VALUE_PAIRs are the main data structure used in the server, they specify an attribute, it's children and
- * it's siblings.
+ * VALUE_PAIRs are the main data structure used in the server
  *
  * They also specify what behaviour should be used when the attribute is merged into a new list/tree.
  */
@@ -382,6 +359,7 @@ typedef struct fr_ipaddr_t {
                struct in_addr  ip4addr;
                struct in6_addr ip6addr; /* maybe defined in missing.h */
        } ipaddr;
+       uint8_t         prefix;
        uint32_t        scope;  /* for IPv6 */
 } fr_ipaddr_t;
 
@@ -446,14 +424,16 @@ size_t            fr_print_string_len(char const *in, size_t inlen);
 
 #define                is_truncated(_ret, _max) ((_ret) >= (_max))
 #define                truncate_len(_ret, _max) (((_ret) >= (_max)) ? ((_max) - 1) : _ret)
+size_t         vp_data_prints_value(char *out, size_t outlen,
+                                    DICT_ATTR const *da, value_data_t const *data, size_t data_len, int8_t quote);
 size_t         vp_prints_value(char *out, size_t outlen, VALUE_PAIR const *vp, int8_t quote);
-char           *vp_aprinttype(TALLOC_CTX *ctx, PW_TYPE type);
-char           *vp_aprint(TALLOC_CTX *ctx, VALUE_PAIR const *vp);
 size_t         vp_prints_value_json(char *out, size_t outlen, VALUE_PAIR const *vp);
-size_t         vp_print_name(char *out, size_t outlen, unsigned int attr, unsigned int vendor);
 size_t         vp_prints(char *out, size_t outlen, VALUE_PAIR const *vp);
 void           vp_print(FILE *, VALUE_PAIR const *);
 void           vp_printlist(FILE *, VALUE_PAIR const *);
+char           *vp_aprint_type(TALLOC_CTX *ctx, PW_TYPE type);
+char           *vp_aprint_value(TALLOC_CTX *ctx, VALUE_PAIR const *vp);
+char           *vp_aprint(TALLOC_CTX *ctx, VALUE_PAIR const *vp);
 #define                fprint_attr_val vp_print
 
 /*
@@ -475,6 +455,7 @@ DICT_ATTR const     *dict_attrunknown(unsigned int attr, unsigned int vendor, int vp
 DICT_ATTR const        *dict_attrunknownbyname(char const *attribute, int vp_free);
 DICT_ATTR const        *dict_attrbyvalue(unsigned int attr, unsigned int vendor);
 DICT_ATTR const        *dict_attrbyname(char const *attr);
+DICT_ATTR const *dict_attrbytagged_name(char const *name);
 DICT_ATTR const        *dict_attrbytype(unsigned int attr, unsigned int vendor,
                                 PW_TYPE type);
 DICT_ATTR const        *dict_attrbyparent(DICT_ATTR const *parent, unsigned int attr,
@@ -498,20 +479,11 @@ DICT_VENDOR       *dict_vendorbyvalue(int vendor);
 
 void           fr_md5_calc(uint8_t *, uint8_t const *, unsigned int);
 
-/* hmac.c */
-
-void fr_hmac_md5(uint8_t const *text, size_t text_len, uint8_t const *key, size_t key_len, unsigned char *digest);
-
-/* hmacsha1.c */
-
-void fr_hmac_sha1(uint8_t const *text, size_t text_len, uint8_t const *key, size_t key_len, uint8_t *digest);
-
 /* radius.c */
 int            rad_send(RADIUS_PACKET *, RADIUS_PACKET const *, char const *secret);
-int            rad_packet_ok(RADIUS_PACKET *packet, int flags);
+bool           rad_packet_ok(RADIUS_PACKET *packet, int flags, decode_fail_t *reason);
 RADIUS_PACKET  *rad_recv(int fd, int flags);
-ssize_t rad_recv_header(int sockfd, fr_ipaddr_t *src_ipaddr, int *src_port,
-                       int *code);
+ssize_t rad_recv_header(int sockfd, fr_ipaddr_t *src_ipaddr, uint16_t *src_port, int *code);
 void           rad_recv_discard(int sockfd);
 int            rad_verify(RADIUS_PACKET *packet, RADIUS_PACKET *original,
                           char const *secret);
@@ -524,6 +496,8 @@ int         rad_sign(RADIUS_PACKET *packet, RADIUS_PACKET const *original,
 int rad_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length);
 RADIUS_PACKET  *rad_alloc(TALLOC_CTX *ctx, int newvector);
 RADIUS_PACKET  *rad_alloc_reply(TALLOC_CTX *ctx, RADIUS_PACKET *);
+RADIUS_PACKET *rad_copy_packet(TALLOC_CTX *ctx, RADIUS_PACKET const *in);
+
 void           rad_free(RADIUS_PACKET **);
 int            rad_pwencode(char *encpw, size_t *len, char const *secret,
                             uint8_t const *vector);
@@ -543,12 +517,16 @@ int               rad_attr_ok(RADIUS_PACKET const *packet, RADIUS_PACKET const *original,
 int            rad_tlv_ok(uint8_t const *data, size_t length,
                           size_t dv_type, size_t dv_length);
 
-ssize_t                rad_attr2vp(RADIUS_PACKET *packet, RADIUS_PACKET const *original,
-                           char const *secret,
-                           uint8_t const *data, size_t length,
-                           VALUE_PAIR **pvp);
+ssize_t                data2vp(TALLOC_CTX *ctx,
+                       RADIUS_PACKET *packet, RADIUS_PACKET const *original,
+                       char const *secret,
+                       DICT_ATTR const *da, uint8_t const *start,
+                       size_t const attrlen, size_t const packetlen,
+                       VALUE_PAIR **pvp);
 
-ssize_t                rad_data2vp(unsigned int attribute, unsigned int vendor,
+ssize_t                rad_attr2vp(TALLOC_CTX *ctx,
+                           RADIUS_PACKET *packet, RADIUS_PACKET const *original,
+                           char const *secret,
                            uint8_t const *data, size_t length,
                            VALUE_PAIR **pvp);
 
@@ -588,8 +566,12 @@ VALUE_PAIR *pairfind_da(VALUE_PAIR *, DICT_ATTR const *da, int8_t tag);
 VALUE_PAIR     *_fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR const * const *node);
 void           fr_cursor_copy(vp_cursor_t *out, vp_cursor_t *in);
 VALUE_PAIR     *fr_cursor_first(vp_cursor_t *cursor);
+VALUE_PAIR     *fr_cursor_last(vp_cursor_t *cursor);
 VALUE_PAIR     *fr_cursor_next_by_num(vp_cursor_t *cursor, unsigned int attr, unsigned int vendor, int8_t tag);
-VALUE_PAIR     *fr_cursor_next_by_da(vp_cursor_t *cursor, DICT_ATTR const *da, int8_t tag);
+
+VALUE_PAIR     *fr_cursor_next_by_da(vp_cursor_t *cursor, DICT_ATTR const *da, int8_t tag)
+               CC_HINT(nonnull);
+
 VALUE_PAIR     *fr_cursor_next(vp_cursor_t *cursor);
 VALUE_PAIR     *fr_cursor_current(vp_cursor_t *cursor);
 void           fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *vp);
@@ -603,52 +585,41 @@ int8_t            paircmp_op(VALUE_PAIR const *a, FR_TOKEN op, VALUE_PAIR const *b);
 int8_t         paircmp(VALUE_PAIR *a, VALUE_PAIR *b);
 int8_t         pairlistcmp(VALUE_PAIR *a, VALUE_PAIR *b);
 
-typedef int8_t (*fr_pair_cmp_t)(VALUE_PAIR const *a, VALUE_PAIR const *b);
-int8_t         attrcmp(VALUE_PAIR const *a, VALUE_PAIR const *b);
-int8_t         attrtagcmp(VALUE_PAIR const *a, VALUE_PAIR const *b);
-void           pairsort(VALUE_PAIR **vps, fr_pair_cmp_t cmp);
-bool           pairvalidate(VALUE_PAIR *filter, VALUE_PAIR *list);
-bool           pairvalidate_relaxed(VALUE_PAIR *filter, VALUE_PAIR *list);
+typedef int8_t (*fr_cmp_t)(void const *a, void const *b);
+int8_t         attrcmp(void const *a, void const *b);
+int8_t         attrtagcmp(void const *a, void const *b);
+void           pairsort(VALUE_PAIR **vps, fr_cmp_t cmp);
+void           pairvalidate_debug(TALLOC_CTX *ctx, VALUE_PAIR const *failed[2]);
+bool           pairvalidate(VALUE_PAIR const *failed[2], VALUE_PAIR *filter, VALUE_PAIR *list);
+bool           pairvalidate_relaxed(VALUE_PAIR const *failed[2], VALUE_PAIR *filter, VALUE_PAIR *list);
 VALUE_PAIR     *paircopyvp(TALLOC_CTX *ctx, VALUE_PAIR const *vp);
-VALUE_PAIR     *paircopyvpdata(TALLOC_CTX *ctx, DICT_ATTR const *da, VALUE_PAIR const *vp);
 VALUE_PAIR     *paircopy(TALLOC_CTX *ctx, VALUE_PAIR *from);
 VALUE_PAIR     *paircopy2(TALLOC_CTX *ctx, VALUE_PAIR *from, unsigned int attr, unsigned int vendor, int8_t tag);
 VALUE_PAIR     *pairsteal(TALLOC_CTX *ctx, VALUE_PAIR *from);
-void           pairtypeset(VALUE_PAIR *vp);
 void           pairmemcpy(VALUE_PAIR *vp, uint8_t const * src, size_t len);
 void           pairmemsteal(VALUE_PAIR *vp, uint8_t const *src);
 void           pairstrsteal(VALUE_PAIR *vp, char const *src);
 void           pairstrcpy(VALUE_PAIR *vp, char const * src);
-void           pairsprintf(VALUE_PAIR *vp, char const * fmt, ...)
-#ifdef __GNUC__
-               __attribute__ ((format (printf, 2, 3)))
-#endif
-;
+void           pairstrncpy(VALUE_PAIR *vp, char const * src, size_t len);
+int            pairdatacpy(VALUE_PAIR *vp, DICT_ATTR const *da, value_data_t const *data, size_t len);
+void           pairsprintf(VALUE_PAIR *vp, char const * fmt, ...) CC_HINT(format (printf, 2, 3));
 void           pairmove(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from);
 void           pairfilter(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from,
                           unsigned int attr, unsigned int vendor, int8_t tag);
 VALUE_PAIR     *pairmake_ip(TALLOC_CTX *ctx, char const *value,
                             DICT_ATTR *ipv4, DICT_ATTR *ipv6, DICT_ATTR *ipv4_prefix, DICT_ATTR *ipv6_prefix);
-bool           pairparsevalue(VALUE_PAIR *vp, char const *value);
+int            pairparsevalue(VALUE_PAIR *vp, char const *value, size_t len);
 VALUE_PAIR     *pairmake(TALLOC_CTX *ctx, VALUE_PAIR **vps, char const *attribute, char const *value, FR_TOKEN op);
 int            pairmark_xlat(VALUE_PAIR *vp, char const *value);
 FR_TOKEN       pairread(char const **ptr, VALUE_PAIR_RAW *raw);
 FR_TOKEN       userparse(TALLOC_CTX *ctx, char const *buffer, VALUE_PAIR **head);
-VALUE_PAIR     *readvp2(TALLOC_CTX *ctx, FILE *fp, bool *pfiledone, char const *errprefix);
+int            readvp2(VALUE_PAIR **out, TALLOC_CTX *ctx, FILE *fp, bool *pfiledone);
 
 /*
  *     Error functions.
  */
-void           fr_strerror_printf(char const *, ...)
-#ifdef __GNUC__
-               __attribute__ ((format (printf, 1, 2)))
-#endif
-;
-void           fr_perror(char const *, ...)
-#ifdef __GNUC__
-               __attribute__ ((format (printf, 1, 2)))
-#endif
-;
+void           fr_strerror_printf(char const *, ...) CC_HINT(format (printf, 1, 2));
+void           fr_perror(char const *, ...) CC_HINT(format (printf, 1, 2));
 
 extern bool fr_assert_cond(char const *file, int line, char const *expr, bool cond);
 #define fr_assert(_x) fr_assert_cond(__FILE__,  __LINE__, #_x, (_x))
@@ -664,52 +635,55 @@ extern char const *fr_syserror(int num);
 extern bool    fr_dns_lookups; /* do IP -> hostname lookups? */
 extern bool    fr_hostname_lookups; /* do hostname -> IP lookups? */
 extern int     fr_debug_flag;  /* 0 = no debugging information */
-extern int     fr_max_attributes; /* per incoming packet */
+extern uint32_t        fr_max_attributes; /* per incoming packet */
 #define        FR_MAX_PACKET_CODE (52)
 extern char const *fr_packet_codes[FR_MAX_PACKET_CODE];
 #define is_radius_code(_x) ((_x > 0) && (_x < FR_MAX_PACKET_CODE))
 extern FILE    *fr_log_fp;
 extern void rad_print_hex(RADIUS_PACKET *packet);
-void           fr_printf_log(char const *, ...)
-#ifdef __GNUC__
-               __attribute__ ((format (printf, 1, 2)))
-#endif
-;
+void           fr_printf_log(char const *, ...) CC_HINT(format (printf, 1, 2));
 
 /*
  *     Several handy miscellaneous functions.
  */
 int            fr_set_signal(int sig, sig_t func);
-TALLOC_CTX     *fr_autofree_ctx(void);
+int            fr_link_talloc_ctx_free(TALLOC_CTX *parent, TALLOC_CTX *child);
 char const     *fr_inet_ntop(int af, void const *src);
 char const     *ip_ntoa(char *, uint32_t);
+int            fr_pton4(fr_ipaddr_t *out, char const *value, size_t inlen, bool resolve, bool fallback);
+int            fr_pton6(fr_ipaddr_t *out, char const *value, size_t inlen, bool resolve, bool fallback);
+int            fr_pton(fr_ipaddr_t *out, char const *value, size_t inlen, bool resolve);
+bool           is_wildcard(fr_ipaddr_t *addr);
+int            fr_ntop(char *out, size_t outlen, fr_ipaddr_t *addr);
 char           *ifid_ntoa(char *buffer, size_t size, uint8_t const *ifid);
 uint8_t                *ifid_aton(char const *ifid_str, uint8_t *ifid);
 int            rad_lockfd(int fd, int lock_len);
 int            rad_lockfd_nonblock(int fd, int lock_len);
 int            rad_unlockfd(int fd, int lock_len);
 size_t         fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen);
-size_t         fr_hex2bin(uint8_t *bin, char const *hex, size_t outlen);
+size_t         fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen);
 uint32_t       fr_strtoul(char const *value, char **end);
-bool           fr_whitespace_check(char const *value);
-bool           fr_integer_check(char const *value);
+bool           is_whitespace(char const *value);
+bool           is_integer(char const *value);
+bool           is_zero(char const *value);
 
 int            fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b);
 
-int            ip_ptonx(char const *src, fr_ipaddr_t *dst);
-int            ip_hton(char const *src, int af, fr_ipaddr_t *dst);
+int            ip_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback);
 char const     *ip_ntoh(fr_ipaddr_t const *src, char *dst, size_t cnt);
-struct in_addr fr_ipaddr_mask(struct in_addr const *ipaddr, uint8_t prefix);
-struct in6_addr        fr_ipaddr_mask6(struct in6_addr const *ipaddr, uint8_t prefix);
-int            fr_ipaddr2sockaddr(fr_ipaddr_t const *ipaddr, int port,
+struct in_addr fr_inaddr_mask(struct in_addr const *ipaddr, uint8_t prefix);
+struct in6_addr        fr_in6addr_mask(struct in6_addr const *ipaddr, uint8_t prefix);
+void           fr_ipaddr_mask(fr_ipaddr_t *addr, uint8_t prefix);
+int            fr_ipaddr2sockaddr(fr_ipaddr_t const *ipaddr, uint16_t port,
                                   struct sockaddr_storage *sa, socklen_t *salen);
 int            fr_sockaddr2ipaddr(struct sockaddr_storage const *sa, socklen_t salen,
-                                  fr_ipaddr_t *ipaddr, int * port);
+                                  fr_ipaddr_t *ipaddr, uint16_t *port);
 ssize_t                fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen);
 size_t         fr_prints_uint128(char *out, size_t outlen, uint128_t const num);
 int64_t                fr_pow(int32_t base, uint8_t exp);
 int            fr_get_time(char const *date_str, time_t *date);
-
+int8_t         fr_pointer_cmp(void const *a, void const *b);
+void           fr_quick_sort(void const *to_sort[], int min_idx, int max_idx, fr_cmp_t cmp);
 /*
  *     Define TALLOC_DEBUG to check overflows with talloc.
  *     we can't use valgrind, because the memory used by
@@ -726,8 +700,8 @@ void                fr_talloc_verify_cb(const void *ptr, int depth,
 
 #ifdef WITH_ASCEND_BINARY
 /* filters.c */
-int            ascend_parse_filter(VALUE_PAIR *vp, char const *value);
-void           print_abinary(VALUE_PAIR const *vp, char *buffer, size_t len, int8_t quote);
+int            ascend_parse_filter(VALUE_PAIR *vp, char const *value, size_t len);
+void           print_abinary(char *out, size_t outlen, uint8_t const *data, size_t len, int8_t quote);
 #endif /*WITH_ASCEND_BINARY*/
 
 /* random numbers in isaac.c */
@@ -735,7 +709,7 @@ void                print_abinary(VALUE_PAIR const *vp, char *buffer, size_t len, int8_t quote
 typedef struct fr_randctx {
        uint32_t randcnt;
        uint32_t randrsl[256];
-       uint32_t randmem[256];
+       uint32_t randmem[256];
        uint32_t randa;
        uint32_t randb;
        uint32_t randc;
@@ -758,13 +732,39 @@ void              fr_cbuff_rp_insert(fr_cbuff_t *cbuff, void *obj);
 void           *fr_cbuff_rp_next(fr_cbuff_t *cbuff, TALLOC_CTX *ctx);
 
 /* debug.c */
+
+/** Optional callback passed to fr_fault_setup
+ *
+ * Allows optional logic to be run before calling the main fault handler.
+ *
+ * If the callback returns < 0, the main fault handler will not be called.
+ *
+ * @param signum signal raised.
+ * @return 0 on success < 0 on failure.
+ */
+typedef int (*fr_fault_cb_t)(int signum);
 typedef struct fr_bt_marker fr_bt_marker_t;
 
 void           fr_debug_break(void);
 void           backtrace_print(fr_cbuff_t *cbuff, void *obj);
 fr_bt_marker_t *fr_backtrace_attach(fr_cbuff_t **cbuff, TALLOC_CTX *obj);
-void NEVER_RETURNS fr_fault(int sig);
+
+typedef void (*fr_fault_log_t)(char const *msg, ...) CC_HINT(format (printf, 1, 2));
+
+void           fr_panic_on_free(TALLOC_CTX *ctx);
+int            fr_set_dumpable_init(void);
+int            fr_set_dumpable(bool allow_core_dumps);
+int            fr_log_talloc_report(TALLOC_CTX *ctx);
+void           fr_fault(int sig);
 int            fr_fault_setup(char const *cmd, char const *program);
+void           fr_fault_set_cb(fr_fault_cb_t func);
+void           fr_fault_set_log_fn(fr_fault_log_t func);
+void           fr_fault_set_log_fd(int fd);
+
+#ifdef WITH_VERIFY_PTR
+void           fr_verify_vp(char const *file, int line, VALUE_PAIR const *vp);
+void           fr_verify_list(char const *file, int line, TALLOC_CTX *expected, VALUE_PAIR *vps);
+#endif
 
 /* rbtree.c */
 typedef struct rbtree_t rbtree_t;
@@ -786,7 +786,7 @@ typedef int (*rb_comparator_t)(void const *ctx, void const *data);
 typedef int (*rb_walker_t)(void *ctx, void *data);
 typedef void (*rb_free_t)(void *data);
 
-rbtree_t       *rbtree_create(rb_comparator_t compare, rb_free_t node_free, int flags);
+rbtree_t       *rbtree_create(TALLOC_CTX *ctx, rb_comparator_t compare, rb_free_t node_free, int flags);
 void           rbtree_free(rbtree_t *tree);
 bool           rbtree_insert(rbtree_t *tree, void *data);
 rbnode_t       *rbtree_insert_node(rbtree_t *tree, void *data);
@@ -794,8 +794,7 @@ void                rbtree_delete(rbtree_t *tree, rbnode_t *z);
 bool           rbtree_deletebydata(rbtree_t *tree, void const *data);
 rbnode_t       *rbtree_find(rbtree_t *tree, void const *data);
 void           *rbtree_finddata(rbtree_t *tree, void const *data);
-int            rbtree_num_elements(rbtree_t *tree);
-void           *rbtree_min(rbtree_t *tree);
+uint32_t       rbtree_num_elements(rbtree_t *tree);
 void           *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
 
 /*
@@ -804,7 +803,7 @@ void                *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
  *
  *     The "context" is some user-defined context.
  *     The "data" is the pointer to the user data in the node,
- *       NOT the node itself.
+ *     NOT the node itself.
  *
  *     It should return 0 if all is OK, and !0 for any error.
  *     The walking will stop on any error.
@@ -817,26 +816,6 @@ void               *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
 int            rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *context);
 
 /*
- *     Find a matching data item in an rbtree and, if one is found,
- *     perform a callback on it.
- *
- *     The callback is similar to rbtree_walk above, except that a
- *     positive return code from the callback will cause the found node
- *     to be deleted from the tree.  If the tree was created with
- *     RBTREE_FLAG_LOCK, then the entire find/callback/delete/rebalance
- *     sequence happens while the lock is held.
- *
- *     Note that the callback MUST NOT alter any of the data which
- *     is used as the rbtree key, nor attempt to alter the rest of
- *     the rbtree in any way.
- *
- *     Returns a pointer to the user data in the found node, or NULL if the
- *     item was not found, or NULL if the item was deleted and the tree was
- *     created with a freeNode garbage collection routine.
- */
-void           *rbtree_callbydata(rbtree_t *tree, void const *data, rb_comparator_t compare, void *context);
-
-/*
  *     FIFOs
  */
 typedef struct fr_fifo_t fr_fifo_t;