All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Typedefs | Functions | Variables
radsniff.c File Reference

Capture, filter, and generate statistics for RADIUS traffic. More...

#include <time.h>
#include <math.h>
#include <freeradius-devel/libradius.h>
#include <freeradius-devel/event.h>
#include <freeradius-devel/radpaths.h>
#include <freeradius-devel/conf.h>
#include <freeradius-devel/pcap.h>
#include <freeradius-devel/radsniff.h>
+ Include dependency graph for radsniff.c:

Go to the source code of this file.

Macros

#define _LIBRADIUS   1
 
#define RS_ASSERT(_x)   if (!(_x) && !fr_assert(_x)) exit(1)
 
#define RS_CLEANUP_NOW(_x, _s)
 
#define USEC   1000000
 

Typedefs

typedef int(* rbcmp )(void const *, void const *)
 

Functions

static int _request_free (rs_request_t *request)
 
static void _rs_event (void *ctx, UNUSED struct timeval *now)
 
static void _rs_event_status (struct timeval *wake)
 
static void _unmark_link (void *request)
 Callback for when the request is removed from the link tree. More...
 
static void _unmark_request (void *request)
 Callback for when the request is removed from the request tree. More...
 
int main (int argc, char *argv[])
 
static int rs_build_dict_list (fr_dict_attr_t const **out, size_t len, char *list)
 
static int rs_build_event_flags (int *flags, FR_NAME_NUMBER const *map, char *list)
 
static int rs_build_filter (VALUE_PAIR **out, char const *filter)
 
static int rs_check_pcap_drop (fr_pcap_t *in)
 Query libpcap to see if it dropped any packets. More...
 
static void rs_daemonize (char const *pidfile)
 Fork and kill the parent process, writing out our PID. More...
 
static int rs_get_pairs (TALLOC_CTX *ctx, VALUE_PAIR **out, VALUE_PAIR *vps, fr_dict_attr_t const *da[], int num)
 Copy a subset of attributes from one list into the other. More...
 
static void rs_got_packet (fr_event_list_t *el, int fd, void *ctx)
 
static int rs_install_stats_processor (rs_stats_t *stats, fr_event_list_t *el, fr_pcap_t *in, struct timeval *now, bool live)
 
static void rs_packet_cleanup (rs_request_t *request)
 
static int rs_packet_cmp (rs_request_t const *a, rs_request_t const *b)
 Wrapper around fr_packet_cmp to strip off the outer request struct. More...
 
static void rs_packet_print (rs_request_t *request, uint64_t count, rs_status_t status, fr_pcap_t *handle, RADIUS_PACKET *packet, struct timeval *elapsed, struct timeval *latency, bool response, bool body)
 
static void rs_packet_print_csv (uint64_t count, rs_status_t status, fr_pcap_t *handle, RADIUS_PACKET *packet, UNUSED struct timeval *elapsed, struct timeval *latency, UNUSED bool response, bool body)
 
static void rs_packet_print_csv_header (void)
 
static void rs_packet_print_fancy (uint64_t count, rs_status_t status, fr_pcap_t *handle, RADIUS_PACKET *packet, struct timeval *elapsed, struct timeval *latency, bool response, bool body)
 
static void rs_packet_process (uint64_t count, rs_event_t *event, struct pcap_pkthdr const *header, uint8_t const *data)
 
static int rs_request_to_pcap (rs_event_t *event, rs_request_t *request, struct pcap_pkthdr const *header, uint8_t const *data)
 
static int rs_response_to_pcap (rs_event_t *event, rs_request_t *request, struct pcap_pkthdr const *header, uint8_t const *data)
 
static int rs_rtx_cmp (rs_request_t const *a, rs_request_t const *b)
 Compare requests using packet info and lists of attributes. More...
 
static void rs_signal_action (UNUSED fr_event_list_t *list, int fd, UNUSED void *ctx)
 Read the last signal from the signal pipe. More...
 
static void rs_signal_self (int sig)
 Write the last signal to the signal pipe. More...
 
static size_t rs_snprint_csv (char *out, size_t outlen, char const *in, size_t inlen)
 
static ssize_t rs_stats_print_code_csv (char *out, size_t outlen, rs_latency_t *stats)
 
static void rs_stats_print_code_fancy (rs_latency_t *stats, PW_CODE code)
 
static void rs_stats_print_csv (rs_update_t *this, rs_stats_t *stats, UNUSED struct timeval *now)
 
static void rs_stats_print_csv_header (rs_update_t *this)
 
static void rs_stats_print_fancy (rs_update_t *this, rs_stats_t *stats, struct timeval *now)
 
static void rs_stats_process (void *ctx, struct timeval *now)
 Process stats for a single interval. More...
 
static void rs_stats_process_counters (rs_latency_t *stats)
 
static void rs_stats_process_latency (rs_latency_t *stats)
 Update smoothed average. More...
 
static void rs_stats_update_latency (rs_latency_t *stats, struct timeval *latency)
 Update latency statistics for request/response and forwarded packets. More...
 
static void rs_time_print (char *out, size_t len, struct timeval const *t)
 
static void rs_tv_add_ms (struct timeval const *start, unsigned long interval, struct timeval *result)
 
static void rs_tv_sub (struct timeval const *end, struct timeval const *start, struct timeval *elapsed)
 
static void NEVER_RETURNS usage (int status)
 

Variables

static bool cleanup
 
static rs_tconf
 
static fr_event_list_tevents
 
static rbtree_tlink_tree = NULL
 
static char const * radsniff_version
 
static rbtree_trequest_tree = NULL
 
static const FR_NAME_NUMBER rs_events []
 
static int rs_useful_codes []
 
static int self_pipe [2] = {-1, -1}
 Signals from sig handlers. More...
 
static struct timeval start_pcap = {0, 0}
 
static char timestr [50]
 

Detailed Description

Capture, filter, and generate statistics for RADIUS traffic.

Id:
118c1a00ea31b674d6228b3aef49a9308da7b115

Definition in file radsniff.c.

Macro Definition Documentation

#define _LIBRADIUS   1

Definition at line 29 of file radsniff.c.

#define RS_ASSERT (   _x)    if (!(_x) && !fr_assert(_x)) exit(1)

Definition at line 44 of file radsniff.c.

#define RS_CLEANUP_NOW (   _x,
  _s 
)
Value:
{\
_x->silent_cleanup = _s;\
_x->when = header->ts;\
_x = NULL;\
} while (0)
static void rs_packet_cleanup(rs_request_t *request)
Definition: radsniff.c:1020

Definition at line 1190 of file radsniff.c.

#define USEC   1000000

Definition at line 164 of file radsniff.c.

Typedef Documentation

typedef int(* rbcmp)(void const *, void const *)

Definition at line 57 of file radsniff.c.

Function Documentation

static int _request_free ( rs_request_t request)
static

Definition at line 990 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void _rs_event ( void *  ctx,
UNUSED struct timeval *  now 
)
static

Definition at line 1087 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void _rs_event_status ( struct timeval *  wake)
static

Definition at line 1851 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void _unmark_link ( void *  request)
static

Callback for when the request is removed from the link tree.

Parameters
requestbeing removed.

Definition at line 1999 of file radsniff.c.

+ Here is the caller graph for this function:

static void _unmark_request ( void *  request)
static

Callback for when the request is removed from the request tree.

Parameters
requestbeing removed.

Definition at line 1989 of file radsniff.c.

+ Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 2139 of file radsniff.c.

+ Here is the call graph for this function:

static int rs_build_dict_list ( fr_dict_attr_t const **  out,
size_t  len,
char *  list 
)
static

Definition at line 1887 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_build_event_flags ( int *  flags,
FR_NAME_NUMBER const *  map,
char *  list 
)
static

Definition at line 1960 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_build_filter ( VALUE_PAIR **  out,
char const *  filter 
)
static

Definition at line 1922 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_check_pcap_drop ( fr_pcap_t *  in)
static

Query libpcap to see if it dropped any packets.

We need to check to see if libpcap dropped any packets and if it did, we need to stop stats output for long enough for inaccurate statistics to be cleared out.

Parameters
inpcap handle to check.
Returns
  • 0 No drops.
  • -1 We couldn't check.
  • -2 Dropped because of buffer exhaustion.
  • -3 Dropped because of NIC.

Definition at line 519 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_daemonize ( char const *  pidfile)
static

Fork and kill the parent process, writing out our PID.

Parameters
pidfilethe PID file to write our PID to

Definition at line 98 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_get_pairs ( TALLOC_CTX *  ctx,
VALUE_PAIR **  out,
VALUE_PAIR vps,
fr_dict_attr_t const *  da[],
int  num 
)
static

Copy a subset of attributes from one list into the other.

Should be O(n) if all the attributes exist. List must be pre-sorted.

Definition at line 956 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_got_packet ( fr_event_list_t el,
int  fd,
void *  ctx 
)
static

Definition at line 1771 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_install_stats_processor ( rs_stats_t stats,
fr_event_list_t el,
fr_pcap_t *  in,
struct timeval *  now,
bool  live 
)
static

Definition at line 902 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_packet_cleanup ( rs_request_t request)
static

Definition at line 1020 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_packet_cmp ( rs_request_t const *  a,
rs_request_t const *  b 
)
static

Wrapper around fr_packet_cmp to strip off the outer request struct.

Definition at line 1097 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_packet_print ( rs_request_t request,
uint64_t  count,
rs_status_t  status,
fr_pcap_t *  handle,
RADIUS_PACKET packet,
struct timeval *  elapsed,
struct timeval *  latency,
bool  response,
bool  body 
)
inlinestatic

Definition at line 497 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_packet_print_csv ( uint64_t  count,
rs_status_t  status,
fr_pcap_t *  handle,
RADIUS_PACKET packet,
UNUSED struct timeval *  elapsed,
struct timeval *  latency,
UNUSED bool  response,
bool  body 
)
static

Definition at line 308 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_packet_print_csv_header ( void  )
static

Definition at line 267 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_packet_print_fancy ( uint64_t  count,
rs_status_t  status,
fr_pcap_t *  handle,
RADIUS_PACKET packet,
struct timeval *  elapsed,
struct timeval *  latency,
bool  response,
bool  body 
)
static

Definition at line 403 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_packet_process ( uint64_t  count,
rs_event_t event,
struct pcap_pkthdr const *  header,
uint8_t const *  data 
)
static

Definition at line 1198 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int rs_request_to_pcap ( rs_event_t event,
rs_request_t request,
struct pcap_pkthdr const *  header,
uint8_t const *  data 
)
inlinestatic

Definition at line 1152 of file radsniff.c.

+ Here is the caller graph for this function:

static int rs_response_to_pcap ( rs_event_t event,
rs_request_t request,
struct pcap_pkthdr const *  header,
uint8_t const *  data 
)
inlinestatic

Definition at line 1102 of file radsniff.c.

+ Here is the caller graph for this function:

static int rs_rtx_cmp ( rs_request_t const *  a,
rs_request_t const *  b 
)
static

Compare requests using packet info and lists of attributes.

Definition at line 1865 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_signal_action ( UNUSED fr_event_list_t list,
int  fd,
UNUSED void *  ctx 
)
static

Read the last signal from the signal pipe.

Definition at line 2045 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_signal_self ( int  sig)
static

Write the last signal to the signal pipe.

Parameters
sigraised

Definition at line 2034 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static size_t rs_snprint_csv ( char *  out,
size_t  outlen,
char const *  in,
size_t  inlen 
)
static

Definition at line 219 of file radsniff.c.

+ Here is the caller graph for this function:

static ssize_t rs_stats_print_code_csv ( char *  out,
size_t  outlen,
rs_latency_t stats 
)
static

Definition at line 741 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_stats_print_code_fancy ( rs_latency_t stats,
PW_CODE  code 
)
static

Definition at line 602 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_stats_print_csv ( rs_update_t this,
rs_stats_t stats,
UNUSED struct timeval *  now 
)
static

Definition at line 766 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_stats_print_csv_header ( rs_update_t this)
static

Definition at line 693 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_stats_print_fancy ( rs_update_t this,
rs_stats_t stats,
struct timeval *  now 
)
static

Definition at line 646 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_stats_process ( void *  ctx,
struct timeval *  now 
)
static

Process stats for a single interval.

Definition at line 811 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_stats_process_counters ( rs_latency_t stats)
static

Definition at line 587 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_stats_process_latency ( rs_latency_t stats)
static

Update smoothed average.

Definition at line 547 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_stats_update_latency ( rs_latency_t stats,
struct timeval *  latency 
)
static

Update latency statistics for request/response and forwarded packets.

Definition at line 885 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_time_print ( char *  out,
size_t  len,
struct timeval const *  t 
)
static

Definition at line 193 of file radsniff.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rs_tv_add_ms ( struct timeval const *  start,
unsigned long  interval,
struct timeval *  result 
)
static

Definition at line 183 of file radsniff.c.

+ Here is the caller graph for this function:

static void rs_tv_sub ( struct timeval const *  end,
struct timeval const *  start,
struct timeval *  elapsed 
)
static

Definition at line 165 of file radsniff.c.

+ Here is the caller graph for this function:

static void NEVER_RETURNS usage ( int  status)
static

Definition at line 2091 of file radsniff.c.

+ Here is the caller graph for this function:

Variable Documentation

bool cleanup
static

Definition at line 53 of file radsniff.c.

rs_t* conf
static

Definition at line 46 of file radsniff.c.

fr_event_list_t* events
static

Definition at line 52 of file radsniff.c.

rbtree_t* link_tree = NULL
static

Definition at line 51 of file radsniff.c.

char const* radsniff_version
static
Initial value:
= "radsniff version " RADIUSD_VERSION_STRING
", built on " __DATE__ " at " __TIME__

Definition at line 59 of file radsniff.c.

rbtree_t* request_tree = NULL
static

Definition at line 50 of file radsniff.c.

const FR_NAME_NUMBER rs_events[]
static
Initial value:
= {
{ "received", RS_NORMAL },
{ "norsp", RS_LOST },
{ "rtx", RS_RTX },
{ "noreq", RS_UNLINKED },
{ "reused", RS_REUSED },
{ "error", RS_ERROR },
{ NULL , -1 }
}

Definition at line 82 of file radsniff.c.

int rs_useful_codes[]
static
Initial value:
= {
}
RFC2865 - Access-Challenge.
Definition: radius.h:102
RFC3575/RFC5176 - Disconnect-Ack (positive)
Definition: radius.h:106
RFC2866 - Accounting-Response.
Definition: radius.h:96
RFC2865 - Access-Reject.
Definition: radius.h:94
RFC3575/RFC5176 - CoA-Ack (positive)
Definition: radius.h:109
RFC2865 - Access-Request.
Definition: radius.h:92
RFC2866 - Accounting-Request.
Definition: radius.h:95
RFC3575/RFC5176 - CoA-Nak (not willing to perform)
Definition: radius.h:110
RFC2865 - Access-Accept.
Definition: radius.h:93
RFC3575/RFC5176 - CoA-Request.
Definition: radius.h:108
RFC2865/RFC5997 - Status Server (response)
Definition: radius.h:104
RFC2865/RFC5997 - Status Server (request)
Definition: radius.h:103
RFC3575/RFC5176 - Disconnect-Nak (not willing to perform)
Definition: radius.h:107
RFC3575/RFC5176 - Disconnect-Request.
Definition: radius.h:105

Definition at line 65 of file radsniff.c.

int self_pipe[2] = {-1, -1}
static

Signals from sig handlers.

Definition at line 55 of file radsniff.c.

struct timeval start_pcap = {0, 0}
static

Definition at line 47 of file radsniff.c.

char timestr[50]
static

Definition at line 48 of file radsniff.c.