2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * @brief Structures and prototypes for the radius library.
24 * @copyright 1999-2008 The FreeRADIUS server project
26 RCSIDH(libradius_h, "$Id$")
28 #include <freeradius-devel/missing.h>
33 * Let any external program building against the library know what
34 * features the library was built with.
36 #include <freeradius-devel/features.h>
43 #include <freeradius-devel/radius.h>
44 #include <freeradius-devel/token.h>
45 #include <freeradius-devel/hash.h>
47 #ifdef SIZEOF_UNSIGNED_INT
48 #if SIZEOF_UNSIGNED_INT != 4
49 #error FATAL: sizeof(unsigned int) != 4
54 * Include for modules.
56 #include <freeradius-devel/sha1.h>
57 #include <freeradius-devel/md4.h>
63 #if defined(WITH_VERIFY_PTR)
65 * Requires typeof(), which is in most modern C compilers.
69 #define VERIFY_VP(_x) do { (void) talloc_get_type_abort(_x, VALUE_PAIR); \
71 (void) talloc_get_type_abort(_x->da, DICT_ATTR); \
75 #define FREE_MAGIC (0xF4EEF4EE)
77 #define VERIFY_VP(_x) (void) talloc_get_type_abort(_x, VALUE_PAIR)
78 #define VERIFY_PACKET(_x) (void) talloc_get_type_abort(_x, RADIUS_PACKET)
81 #define VERIFY_PACKET(_x)
84 #define AUTH_VECTOR_LEN 16
85 #define CHAP_VALUE_LENGTH 16
86 #define MAX_STRING_LEN 254 /* RFC2138: string 0-253 octets */
87 #define FR_MAX_VENDOR (1 << 24) /* RFC limitations */
90 # define AUTH_HDR_LEN 20
91 # define VENDORPEC_USR 429
92 #define VENDORPEC_LUCENT 4846
93 #define VENDORPEC_STARENT 8164
94 # define DEBUG if (fr_debug_flag && fr_log_fp) fr_printf_log
95 # define debug_pair(vp) do { if (fr_debug_flag && fr_log_fp) { \
96 vp_print(fr_log_fp, vp); \
101 #define TAG_VALID(x) ((x) > 0 && (x) < 0x20)
102 #define TAG_VALID_ZERO(x) ((x) < 0x20)
103 #define TAG_ANY -128 /* minimum signed char */
106 #if defined(__GNUC__)
107 # define PRINTF_LIKE(n) __attribute__ ((format(printf, n, n+1)))
108 # define NEVER_RETURNS __attribute__ ((noreturn))
109 # define UNUSED __attribute__ ((unused))
110 # define BLANK_FORMAT " " /* GCC_LINT whines about empty formats */
112 # define PRINTF_LIKE(n) /* ignore */
113 # define NEVER_RETURNS /* ignore */
114 # define UNUSED /* ignore */
115 # define BLANK_FORMAT ""
118 typedef struct attr_flags {
119 unsigned int is_unknown : 1; //!< Attribute number or vendor is unknown.
120 unsigned int is_tlv : 1; //!< Is a sub attribute.
121 unsigned int vp_free : 1; //!< Should be freed when VALUE_PAIR is freed.
123 unsigned int has_tag : 1; //!< Tagged attribute.
124 unsigned int array : 1; //!< Pack multiples into 1 attr.
125 unsigned int has_value : 1; //!< Has a value.
126 unsigned int has_value_alias : 1; //!< Has a value alias.
127 unsigned int has_tlv : 1; //!< Has sub attributes.
129 unsigned int extended : 1; //!< Extended attribute.
130 unsigned int long_extended : 1; //!< Long format.
131 unsigned int evs : 1; //!< Extended VSA.
132 unsigned int wimax: 1; //!< WiMAX format=1,1,c.
134 unsigned int concat : 1; //!< concatenate multiple instances
135 unsigned int is_pointer : 1; //!< data is a pointer
137 uint8_t encrypt; //!< Ecryption method.
142 * Values of the encryption flags.
144 #define FLAG_ENCRYPT_NONE (0)
145 #define FLAG_ENCRYPT_USER_PASSWORD (1)
146 #define FLAG_ENCRYPT_TUNNEL_PASSWORD (2)
147 #define FLAG_ENCRYPT_ASCEND_SECRET (3)
149 extern const FR_NAME_NUMBER dict_attr_types[];
150 extern const size_t dict_attr_sizes[PW_TYPE_MAX][2];
152 /** dictionary attribute
155 typedef struct dict_attr {
163 /** value of an enumerated attribute
166 typedef struct dict_value {
173 /** dictionary vendor
176 typedef struct dict_vendor {
177 unsigned int vendorpec;
178 size_t type; //!< Length of type data
179 size_t length; //!< Length of length data
184 /** Union containing all data types supported by the server
186 * This union contains all data types that can be represented with VALUE_PAIRs. It may also be used in other parts
187 * of the server where values of different types need to be stored.
189 * PW_TYPE should be an enumeration of the values in this union.
191 typedef union value_data {
192 char const *strvalue; //!< Pointer to UTF-8 string.
193 uint8_t const *octets; //!< Pointer to binary string.
194 struct in_addr ipaddr; //!< IPv4 Address.
195 struct in6_addr ipv6addr; //!< IPv6 Address.
196 uint32_t date; //!< Date (32bit Unix timestamp).
197 uint32_t integer; //!< 32bit unsigned integer.
198 int32_t sinteger; //!< 32bit signed integer.
199 uint64_t integer64; //!< 64bit unsigned integer.
200 size_t filter[32/sizeof(size_t)]; //!< 64bit signed integer.
201 uint8_t ifid[8]; /* struct? */ //!< IPv6 interface ID.
202 uint8_t ipv6prefix[18]; /* struct? */ //!< IPv6 prefix.
203 uint8_t ipv4prefix[6]; /* struct? */ //!< IPv4 prefix.
204 uint8_t ether[6]; //!< Ethernet (MAC) address.
205 uint8_t *tlv; //!< Nested TLV (should go away).
206 void const *ptr; //!< generic pointer.
209 /** The type of value a VALUE_PAIR contains
211 * This is used to add structure to nested VALUE_PAIRs and specifies what type of node it is (set, list, data).
213 * xlat is another type of data node which must first be expanded before use.
215 typedef enum value_type {
216 VT_NONE = 0, //!< VALUE_PAIR has no value.
217 VT_SET, //!< VALUE_PAIR has children.
218 VT_LIST, //!< VALUE_PAIR has multiple values.
219 VT_DATA, //!< VALUE_PAIR has a single value.
220 VT_XLAT //!< valuepair value must be xlat expanded when it's
221 //!< added to VALUE_PAIR tree.
224 /** Stores an attribute, a value and various bits of other data
226 * VALUE_PAIRs are the main data structure used in the server, they specify an attribute, it's children and
229 * They also specify what behaviour should be used when the attribute is merged into a new list/tree.
231 typedef struct value_pair {
232 DICT_ATTR const *da; //!< Dictionary attribute defines the attribute
233 //!< number, vendor and type of the attribute.
235 struct value_pair *next;
237 FR_TOKEN op; //!< Operator to use when moving or inserting
238 //!< valuepair into a list.
240 int8_t tag; //!< Tag value used to group valuepairs.
243 // VALUE_SET *set; //!< Set of child attributes.
244 // VALUE_LIST *list; //!< List of values for
245 //!< multivalued attribute.
246 // value_data_t *data; //!< Value data for this attribute.
248 char const *xlat; //!< Source string for xlat expansion.
251 value_type_t type; //!< Type of pointer in value union.
253 size_t length; //!< of Data field.
257 /** Abstraction to allow iterating over different configurations of VALUE_PAIRs
259 * This allows functions which do not care about the structure of collections of VALUE_PAIRs
260 * to iterate over all members in a collection.
262 * Field within a vp_cursor should not be accessed directly, and vp_cursors should only be
263 * manipulated with the pair* functions.
265 typedef struct vp_cursor {
267 VALUE_PAIR *found; //!< pairfind marker.
268 VALUE_PAIR *last; //!< Temporary only used for pairinsert
269 VALUE_PAIR *current; //!< The current attribute.
270 VALUE_PAIR *next; //!< Next attribute to process.
273 /** A VALUE_PAIR in string format.
275 * Used to represent pairs in the legacy 'users' file format.
277 typedef struct value_pair_raw {
278 char l_opand[64]; //!< Left hand side of the pair.
279 char r_opand[1024]; //!< Right hand side of the pair.
281 FR_TOKEN quote; //!< Type of quoting around the r_opand.
283 FR_TOKEN op; //!< Operator.
286 #define vp_strvalue data.strvalue
287 #define vp_octets data.octets
288 #define vp_ipv6addr data.ipv6addr
289 #define vp_ifid data.ifid
290 #define vp_ipv6prefix data.ipv6prefix
291 #define vp_ipv4prefix data.ipv4prefix
292 #define vp_filter data.filter
293 #define vp_ether data.ether
294 #define vp_signed data.sinteger
295 #define vp_tlv data.tlv
296 #define vp_integer64 data.integer64
297 #define vp_ipaddr data.ipaddr.s_addr
298 #define vp_date data.date
299 #define vp_integer data.integer
301 typedef struct fr_ipaddr_t {
302 int af; /* address family */
304 struct in_addr ip4addr;
305 struct in6_addr ip6addr; /* maybe defined in missing.h */
307 uint32_t scope; /* for IPv6 */
311 * vector: Request authenticator from access-request packet
312 * Put in there by rad_decode, and must be put in the
313 * response RADIUS_PACKET as well before calling rad_send
315 * verified: Filled in by rad_decode for accounting-request packets
317 * data,data_len: Used between rad_recv and rad_decode.
319 typedef struct radius_packet {
321 fr_ipaddr_t src_ipaddr;
322 fr_ipaddr_t dst_ipaddr;
327 uint8_t vector[AUTH_VECTOR_LEN];
328 struct timeval timestamp;
339 * Printing functions.
341 int fr_utf8_char(uint8_t const *str);
342 size_t fr_print_string(char const *in, size_t inlen,
343 char *out, size_t outlen);
344 size_t vp_prints_value(char *out, size_t outlen, VALUE_PAIR const *vp, int8_t quote);
345 char *vp_aprinttype(TALLOC_CTX *ctx, PW_TYPE type);
346 char *vp_aprint(TALLOC_CTX *ctx, VALUE_PAIR const *vp);
347 size_t vp_prints_value_json(char *out, size_t outlen, VALUE_PAIR const *vp);
348 size_t vp_print_name(char *out, size_t outlen, unsigned int attr, unsigned int vendor);
349 size_t vp_prints(char *out, size_t outlen, VALUE_PAIR const *vp);
350 void vp_print(FILE *, VALUE_PAIR const *);
351 void vp_printlist(FILE *, VALUE_PAIR const *);
352 #define fprint_attr_val vp_print
355 * Dictionary functions.
357 extern const int dict_attr_allowed_chars[256];
358 int str2argv(char *str, char **argv, int max_argc);
359 int dict_str2oid(char const *ptr, unsigned int *pattr,
360 unsigned int *pvendor, int tlv_depth);
361 int dict_addvendor(char const *name, unsigned int value);
362 int dict_addattr(char const *name, int attr, unsigned int vendor, int type, ATTR_FLAGS flags);
363 int dict_addvalue(char const *namestr, char const *attrstr, int value);
364 int dict_init(char const *dir, char const *fn);
365 void dict_free(void);
366 int dict_read(char const *dir, char const *filename);
367 void dict_attr_free(DICT_ATTR const **da);
368 DICT_ATTR const *dict_attr_copy(DICT_ATTR const *da, int vp_free);
369 DICT_ATTR const *dict_attrunknown(unsigned int attr, unsigned int vendor, int vp_free);
370 DICT_ATTR const *dict_attrunknownbyname(char const *attribute, int vp_free);
371 DICT_ATTR const *dict_attrbyvalue(unsigned int attr, unsigned int vendor);
372 DICT_ATTR const *dict_attrbyname(char const *attr);
373 DICT_ATTR const *dict_attrbytype(unsigned int attr, unsigned int vendor,
375 DICT_ATTR const *dict_attrbyparent(DICT_ATTR const *parent, unsigned int attr,
376 unsigned int vendor);
377 int dict_attr_child(DICT_ATTR const *parent,
378 unsigned int *pattr, unsigned int *pvendor);
379 DICT_VALUE *dict_valbyattr(unsigned int attr, unsigned int vendor, int val);
380 DICT_VALUE *dict_valbyname(unsigned int attr, unsigned int vendor, char const *val);
381 char const *dict_valnamebyattr(unsigned int attr, unsigned int vendor, int value);
382 int dict_vendorbyname(char const *name);
383 DICT_VENDOR *dict_vendorbyvalue(int vendor);
385 #if 1 /* FIXME: compat */
386 #define dict_attrget dict_attrbyvalue
387 #define dict_attrfind dict_attrbyname
388 #define dict_valfind dict_valbyname
389 /*#define dict_valget dict_valbyattr almost but not quite*/
394 void fr_md5_calc(uint8_t *, uint8_t const *, unsigned int);
398 void fr_hmac_md5(uint8_t const *text, size_t text_len, uint8_t const *key, size_t key_len, unsigned char *digest);
402 void fr_hmac_sha1(uint8_t const *text, size_t text_len, uint8_t const *key, size_t key_len, uint8_t *digest);
405 int rad_send(RADIUS_PACKET *, RADIUS_PACKET const *, char const *secret);
406 int rad_packet_ok(RADIUS_PACKET *packet, int flags);
407 RADIUS_PACKET *rad_recv(int fd, int flags);
408 ssize_t rad_recv_header(int sockfd, fr_ipaddr_t *src_ipaddr, int *src_port,
410 void rad_recv_discard(int sockfd);
411 int rad_verify(RADIUS_PACKET *packet, RADIUS_PACKET *original,
413 int rad_decode(RADIUS_PACKET *packet, RADIUS_PACKET *original, char const *secret);
414 int rad_encode(RADIUS_PACKET *packet, RADIUS_PACKET const *original,
416 int rad_sign(RADIUS_PACKET *packet, RADIUS_PACKET const *original,
419 int rad_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length);
420 RADIUS_PACKET *rad_alloc(TALLOC_CTX *ctx, int newvector);
421 RADIUS_PACKET *rad_alloc_reply(TALLOC_CTX *ctx, RADIUS_PACKET *);
422 void rad_free(RADIUS_PACKET **);
423 int rad_pwencode(char *encpw, size_t *len, char const *secret,
424 uint8_t const *vector);
425 int rad_pwdecode(char *encpw, size_t len, char const *secret,
426 uint8_t const *vector);
427 int rad_tunnel_pwencode(char *encpw, size_t *len, char const *secret,
428 uint8_t const *vector);
429 int rad_tunnel_pwdecode(uint8_t *encpw, size_t *len,
430 char const *secret, uint8_t const *vector);
431 int rad_chap_encode(RADIUS_PACKET *packet, uint8_t *output,
432 int id, VALUE_PAIR *password);
434 int rad_attr_ok(RADIUS_PACKET const *packet, RADIUS_PACKET const *original,
436 uint8_t const *data, size_t length);
437 int rad_tlv_ok(uint8_t const *data, size_t length,
438 size_t dv_type, size_t dv_length);
440 ssize_t rad_attr2vp(RADIUS_PACKET *packet, RADIUS_PACKET const *original,
442 uint8_t const *data, size_t length,
445 ssize_t rad_data2vp(unsigned int attribute, unsigned int vendor,
446 uint8_t const *data, size_t length,
449 ssize_t rad_vp2data(VALUE_PAIR const *vp, uint8_t *out, size_t outlen);
451 int rad_vp2extended(RADIUS_PACKET const *packet,
452 RADIUS_PACKET const *original,
453 char const *secret, VALUE_PAIR const **pvp,
454 uint8_t *ptr, size_t room);
455 int rad_vp2wimax(RADIUS_PACKET const *packet,
456 RADIUS_PACKET const *original,
457 char const *secret, VALUE_PAIR const **pvp,
458 uint8_t *ptr, size_t room);
459 int rad_vp2vsa(RADIUS_PACKET const *packet, RADIUS_PACKET const *original,
460 char const *secret, VALUE_PAIR const **pvp, uint8_t *start,
462 int rad_vp2rfc(RADIUS_PACKET const *packet,
463 RADIUS_PACKET const *original,
464 char const *secret, VALUE_PAIR const **pvp,
465 uint8_t *ptr, size_t room);
467 int rad_vp2attr(RADIUS_PACKET const *packet,
468 RADIUS_PACKET const *original, char const *secret,
469 VALUE_PAIR const **pvp, uint8_t *ptr, size_t room);
472 VALUE_PAIR *pairalloc(TALLOC_CTX *ctx, DICT_ATTR const *da);
473 VALUE_PAIR *paircreate(TALLOC_CTX *ctx, unsigned int attr, unsigned int vendor);
474 int pair2unknown(VALUE_PAIR *vp);
475 void pairfree(VALUE_PAIR **);
476 VALUE_PAIR *pairfind(VALUE_PAIR *, unsigned int attr, unsigned int vendor, int8_t tag);
478 #define paircursor(_x, _y) paircursorc(_x,(VALUE_PAIR const * const *) _y)
479 VALUE_PAIR *paircursorc(vp_cursor_t *cursor, VALUE_PAIR const * const *node);
480 VALUE_PAIR *pairfirst(vp_cursor_t *cursor);
481 VALUE_PAIR *pairfindnext(vp_cursor_t *cursor, unsigned int attr, unsigned int vendor, int8_t tag);
482 VALUE_PAIR *pairnext(vp_cursor_t *cursor);
483 VALUE_PAIR *pairlast(vp_cursor_t *cursor);
484 VALUE_PAIR *paircurrent(vp_cursor_t *cursor);
485 void pairinsert(vp_cursor_t *cursor, VALUE_PAIR *vp);
486 VALUE_PAIR *pairremove(vp_cursor_t *cursor);
487 void pairdelete(VALUE_PAIR **, unsigned int attr, unsigned int vendor, int8_t tag);
488 void pairadd(VALUE_PAIR **, VALUE_PAIR *);
489 void pairreplace(VALUE_PAIR **first, VALUE_PAIR *add);
490 int paircmp(VALUE_PAIR *check, VALUE_PAIR *data);
491 int paircmp_op(VALUE_PAIR const *one, FR_TOKEN op, VALUE_PAIR const *two);
492 void pairsort(VALUE_PAIR **vps, bool with_tag);
493 bool pairvalidate(VALUE_PAIR *filter, VALUE_PAIR *list);
494 VALUE_PAIR *paircopyvp(TALLOC_CTX *ctx, VALUE_PAIR const *vp);
495 VALUE_PAIR *paircopyvpdata(TALLOC_CTX *ctx, DICT_ATTR const *da, VALUE_PAIR const *vp);
496 VALUE_PAIR *paircopy(TALLOC_CTX *ctx, VALUE_PAIR *from);
497 VALUE_PAIR *paircopy2(TALLOC_CTX *ctx, VALUE_PAIR *from, unsigned int attr, unsigned int vendor, int8_t tag);
498 void pairmemcpy(VALUE_PAIR *vp, uint8_t const * src, size_t len);
499 void pairstrsteal(VALUE_PAIR *vp, char * src);
500 void pairstrcpy(VALUE_PAIR *vp, char const * src);
501 void pairsprintf(VALUE_PAIR *vp, char const * fmt, ...)
503 __attribute__ ((format (printf, 2, 3)))
506 void pairmove(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from);
507 void pairfilter(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from,
508 unsigned int attr, unsigned int vendor, int8_t tag);
509 bool pairparsevalue(VALUE_PAIR *vp, char const *value);
510 VALUE_PAIR *pairmake(TALLOC_CTX *ctx, VALUE_PAIR **vps, char const *attribute, char const *value, FR_TOKEN op);
511 int pairmark_xlat(VALUE_PAIR *vp, char const *value);
512 FR_TOKEN pairread(char const **ptr, VALUE_PAIR_RAW *raw);
513 FR_TOKEN userparse(TALLOC_CTX *ctx, char const *buffer, VALUE_PAIR **head);
514 VALUE_PAIR *readvp2(TALLOC_CTX *ctx, FILE *fp, int *pfiledone, char const *errprefix);
520 void fr_strerror_printf(char const *, ...)
522 __attribute__ ((format (printf, 1, 2)))
526 void fr_perror(char const *, ...)
528 __attribute__ ((format (printf, 1, 2)))
531 extern bool fr_assert_cond(char const *file, int line, char const *expr, bool cond);
532 #define fr_assert(_x) fr_assert_cond(__FILE__, __LINE__, #_x, (_x))
534 extern void _fr_exit(char const *file, int line, int status);
535 #define fr_exit(_x) _fr_exit(__FILE__, __LINE__, (_x))
537 extern void _fr_exit_now(char const *file, int line, int status);
538 #define fr_exit_now(_x) _fr_exit_now(__FILE__, __LINE__, (_x))
540 extern char const *fr_strerror(void);
541 extern int fr_dns_lookups; /* 0 = no dns lookups */
542 extern int fr_debug_flag; /* 0 = no debugging information */
543 extern int fr_max_attributes; /* per incoming packet */
544 #define FR_MAX_PACKET_CODE (52)
545 extern char const *fr_packet_codes[FR_MAX_PACKET_CODE];
546 extern FILE *fr_log_fp;
547 extern void rad_print_hex(RADIUS_PACKET *packet);
548 void fr_printf_log(char const *, ...)
550 __attribute__ ((format (printf, 1, 2)))
555 * Several handy miscellaneous functions.
557 void fr_debug_break(void);
558 char const *ip_ntoa(char *, uint32_t);
559 char *ifid_ntoa(char *buffer, size_t size, uint8_t const *ifid);
560 uint8_t *ifid_aton(char const *ifid_str, uint8_t *ifid);
561 int rad_lockfd(int fd, int lock_len);
562 int rad_lockfd_nonblock(int fd, int lock_len);
563 int rad_unlockfd(int fd, int lock_len);
564 size_t fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen);
565 size_t fr_hex2bin(uint8_t *bin, char const *hex, size_t outlen);
566 int fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b);
568 int ip_hton(char const *src, int af, fr_ipaddr_t *dst);
569 char const *ip_ntoh(fr_ipaddr_t const *src, char *dst, size_t cnt);
570 int fr_ipaddr2sockaddr(fr_ipaddr_t const *ipaddr, int port,
571 struct sockaddr_storage *sa, socklen_t *salen);
572 int fr_sockaddr2ipaddr(struct sockaddr_storage const *sa, socklen_t salen,
573 fr_ipaddr_t *ipaddr, int * port);
576 #ifdef WITH_ASCEND_BINARY
578 int ascend_parse_filter(VALUE_PAIR *pair);
579 void print_abinary(VALUE_PAIR const *vp, char *buffer, size_t len, int8_t quote);
580 #endif /*WITH_ASCEND_BINARY*/
582 /* random numbers in isaac.c */
583 /* context of random number generator */
584 typedef struct fr_randctx {
586 uint32_t randrsl[256];
587 uint32_t randmem[256];
593 void fr_isaac(fr_randctx *ctx);
594 void fr_randinit(fr_randctx *ctx, int flag);
595 uint32_t fr_rand(void); /* like rand(), but better. */
596 void fr_rand_seed(void const *, size_t ); /* seed the random pool */
599 /* crypt wrapper from crypt.c */
600 int fr_crypt_check(char const *key, char const *salt);
603 typedef struct rbtree_t rbtree_t;
604 typedef struct rbnode_t rbnode_t;
606 #define RBTREE_FLAG_NONE (0)
607 #define RBTREE_FLAG_REPLACE (1 << 0)
608 #define RBTREE_FLAG_LOCK (1 << 1)
609 rbtree_t *rbtree_create(int (*Compare)(void const *, void const *),
610 void (*freeNode)(void *),
612 void rbtree_free(rbtree_t *tree);
613 bool rbtree_insert(rbtree_t *tree, void *Data);
614 rbnode_t *rbtree_insertnode(rbtree_t *tree, void *Data);
615 void rbtree_delete(rbtree_t *tree, rbnode_t *Z);
616 bool rbtree_deletebydata(rbtree_t *tree, void const *data);
617 rbnode_t *rbtree_find(rbtree_t *tree, void const *Data);
618 void *rbtree_finddata(rbtree_t *tree, void const *Data);
619 int rbtree_num_elements(rbtree_t *tree);
620 void *rbtree_min(rbtree_t *tree);
621 void *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
623 /* callback order for walking */
624 typedef enum { PreOrder, InOrder, PostOrder, DeleteOrder } RBTREE_ORDER;
627 * The callback should be declared as:
628 * int callback(void *context, void *data)
630 * The "context" is some user-defined context.
631 * The "data" is the pointer to the user data in the node,
632 * NOT the node itself.
634 * It should return 0 if all is OK, and !0 for any error.
635 * The walking will stop on any error.
637 * Except with DeleteOrder, where the callback should return <0 for
638 * errors, and may return 1 to delete the current node and halt,
639 * or 2 to delete the current node and continue. This may be
640 * used to batch-delete select nodes from a locked rbtree.
642 int rbtree_walk(rbtree_t *tree, RBTREE_ORDER order, int (*callback)(void *, void *), void *context);
645 * Find a matching data item in an rbtree and, if one is found,
646 * perform a callback on it.
648 * The callback is similar to rbtree_walk above, except that a
649 * positive return code from the callback will cause the found node
650 * to be deleted from the tree. If the tree was created with
651 * RBTREE_FLAG_LOCK, then the entire find/callback/delete/rebalance
652 * sequence happens while the lock is held.
654 * Note that the callback MUST NOT alter any of the data which
655 * is used as the rbtree key, nor attempt to alter the rest of
656 * the rbtree in any way.
658 * Returns a pointer to the user data in the found node, or NULL if the
659 * item was not found, or NULL if the item was deleted and the tree was
660 * created with a freeNode garbage collection routine.
662 void *rbtree_callbydata(rbtree_t *tree, void const *Data, int (*callback)(void *, void *), void *context);
667 typedef struct fr_fifo_t fr_fifo_t;
668 typedef void (*fr_fifo_free_t)(void *);
669 fr_fifo_t *fr_fifo_create(int max_entries, fr_fifo_free_t freeNode);
670 void fr_fifo_free(fr_fifo_t *fi);
671 int fr_fifo_push(fr_fifo_t *fi, void *data);
672 void *fr_fifo_pop(fr_fifo_t *fi);
673 void *fr_fifo_peek(fr_fifo_t *fi);
674 int fr_fifo_num_elements(fr_fifo_t *fi);
680 #include <freeradius-devel/packet.h>
683 #include <freeradius-devel/tcp.h>
686 #endif /*LIBRADIUS_H*/