16 #ifndef _FR_RADSNIFF_H
17 #define _FR_RADSNIFF_H
28 RCSIDH(radsniff_h,
"$Id: 686605e0800f88bd8bbdf20014ae866b05f58dc6 $")
30 #include <sys/types.h>
32 #include <freeradius-devel/libradius.h>
33 #include <freeradius-devel/pcap.h>
34 #include <freeradius-devel/event.h>
36 #ifdef HAVE_COLLECTDC_H
37 # include <collectd/client.h>
40 #define RS_DEFAULT_PREFIX "radsniff"
41 #define RS_DEFAULT_SECRET "testing123"
42 #define RS_DEFAULT_TIMEOUT 5200
43 #define RS_FORCE_YIELD 1000
44 #define RS_RETRANSMIT_MAX 5
45 #define RS_MAX_ATTRS 50
46 #define RS_SOCKET_REOPEN_DELAY 5000
52 #define DEBUG2(fmt, ...) if (fr_debug_lvl > 2) fprintf(fr_log_fp , fmt "\n", ## __VA_ARGS__)
54 #define DEBUG(fmt, ...) if (fr_debug_lvl > 1) fprintf(fr_log_fp , fmt "\n", ## __VA_ARGS__)
56 #define INFO(fmt, ...) if (fr_debug_lvl > 0) fprintf(fr_log_fp , fmt "\n", ## __VA_ARGS__)
58 #define ERROR(fmt, ...) fr_perror("radsniff: " fmt, ## __VA_ARGS__)
60 #define RIDEBUG_ENABLED() (conf->print_packet && (fr_debug_lvl > 0))
61 #define RDEBUG_ENABLED() (conf->print_packet && (fr_debug_lvl > 1))
62 #define RDEBUG_ENABLED2() (conf->print_packet && (fr_debug_lvl > 2))
64 #define REDEBUG(fmt, ...) if (conf->print_packet) fr_perror("%s (%" PRIu64 ") " fmt , timestr, count, ## __VA_ARGS__)
65 #define RIDEBUG(fmt, ...) if (conf->print_packet && (fr_debug_lvl > 0)) fprintf(fr_log_fp , "%s (%" PRIu64 ") " fmt "\n", timestr, count, ## __VA_ARGS__)
66 #define RDEBUG(fmt, ...) if (conf->print_packet && (fr_debug_lvl > 1)) fprintf(fr_log_fp , "%s (%" PRIu64 ") " fmt "\n", timestr, count, ## __VA_ARGS__)
67 #define RDEBUG2(fmt, ...) if (conf->print_packet && (fr_debug_lvl > 2)) fprintf(fr_log_fp , "%s (%" PRIu64 ") " fmt "\n", timestr, count, ## __VA_ARGS__)
79 struct timeval *elapsed,
struct timeval *latency,
bool response,
bool body);
81 #ifdef HAVE_COLLECTDC_H
82 RS_STATS_OUT_COLLECTD = 1,
90 #ifdef HAVE_COLLECTDC_H
91 typedef struct rs_stats_tmpl rs_stats_tmpl_t;
92 typedef struct rs_stats_value_tmpl rs_stats_value_tmpl_t;
110 uint64_t received_total;
111 uint64_t linked_total;
112 uint64_t unlinked_total;
113 uint64_t reused_total;
127 long double latency_total;
129 double latency_average;
295 #ifdef HAVE_COLLECTDC_H
296 char const *collectd;
298 lcc_connection_t *handle;
299 rs_stats_tmpl_t *tmpl;
304 #ifdef HAVE_COLLECTDC_H
309 typedef void (*rs_stats_cb_t)(
rs_t *
conf, rs_stats_value_tmpl_t *tmpl);
311 struct rs_stats_value_tmpl {
326 rs_stats_value_tmpl_t *value_tmpl;
328 lcc_value_list_t *value;
330 rs_stats_tmpl_t *next;
336 rs_stats_tmpl_t *rs_stats_collectd_init_latency(TALLOC_CTX *ctx, rs_stats_tmpl_t **out,
rs_t *conf,
338 void rs_stats_collectd_do_stats(
rs_t *conf, rs_stats_tmpl_t *tmpls,
struct timeval *now);
339 int rs_stats_collectd_open(
rs_t *conf);
340 int rs_stats_collectd_close(
rs_t *conf);
bool logged
Whether any messages regarding this request were logged.
rs_stats_t * stats
Stats to process.
struct rs_capture rs_capture_t
rs_stats_t * stats
Where to write stats.
bool decode_attrs
Whether we should decode attributes in the request and response.
fr_dict_attr_t const * link_da[RS_MAX_ATTRS]
fr_dict_attr_ts to link on.
bool to_stdout
Were writing pcap data to stdout.
int link_da_num
Number of rtx fr_dict_attr_ts.
fr_pcap_t * in
Linked list of PCAP handles to check for drops.
bool daemonize
Daemonize and write PID out to file.
bool done_header
Have we printed the stats header?
VALUE_PAIR * link_vps
VALUE_PAIRs used to link retransmissions.
char const * radius_secret
Secret to decode encrypted attributes.
rs_latency_t * stats_req
Latency entry for the request type.
uint64_t invalid_attribute
bool verify_udp_checksum
Check UDP checksum in packets.
char * pcap_filter
PCAP filter string applied to live capture devices.
uint64_t too_many_attributes
fr_event_t * event
Event created when we received the original request.
char const * pidfile
File to write PID to.
Wrapper for RADIUS_PACKET.
fr_pcap_t * in
PCAP handle the original request was received on.
rs_capture_t * capture_p
Next packet slot.
uint64_t min_length_mimatch
char * link_attributes
Names of fr_dict_attr_ts to use for rtx.
bool from_stdin
Were reading pcap data from stdin.
bool promiscuous
Capture in promiscuous mode.
struct rs_counters rs_counters_t
struct rs_latency::@8 interval
rs_latency_t exchange[PW_CODE_MAX]
We end up allocating ~16K, but memory is cheap so what the hell.
bool from_dev
Were reading pcap data from devices.
struct rs_latency rs_latency_t
Stats for a single interval.
uint64_t attribute_overflow
RADIUS_PACKET * packet
The original packet.
RADIUS_PACKET * linked
The subsequent response or forwarded request the packet was linked against.
uint64_t latency_smoothed_count
Number of CMA datapoints processed.
uint8_t * data
PCAP packet data.
struct rs_request rs_request_t
Wrapper for RADIUS_PACKET.
uint64_t id
Monotonically increasing packet counter.
int intervals
Number of stats intervals.
fr_pcap_t * in
PCAP handle event occurred on.
PW_CODE filter_request_code
Filter request packets by code.
rs_stats_print_header_cb_t head
Print header.
rs_latency_t * stats_rsp
Latency entry for the request type.
bool in_link_tree
Whether the request is currently in the linked tree.
int buffer_pkts
Size of the ring buffer to setup for live capture.
uint64_t attribute_underflow
fr_dict_attr_t const * list_da[RS_MAX_ATTRS]
Output CSV with these attribute values.
uint64_t ma_invalid_length
void(* rs_packet_logger_t)(uint64_t count, rs_status_t status, fr_pcap_t *handle, RADIUS_PACKET *packet, struct timeval *elapsed, struct timeval *latency, bool response, bool body)
FD data which gets passed to callbacks.
Stores an attribute, a value and various bits of other data.
bool silent_cleanup
Cleanup was forced before normal expiry period, ignore stats about packet loss.
char const * filter_response
Raw response filter string.
uint64_t min_length_field
uint64_t type[PW_CODE_MAX]
struct pcap_pkthdr * header
PCAP packet header.
rs_stats_print_cb_t body
Print body.
PW_CODE filter_response_code
Filter response packets by code.
rs_status_t event_flags
Events we log and capture on.
uint64_t rt_rsp
Number of times we saw a retransmitted response packet.
uint64_t min_length_packet
static char const * prefix
bool to_file
Were writing pcap data to files.
VALUE_PAIR * filter_response_vps
Sorted filter vps.
#define RS_RETRANSMIT_MAX
Maximum number of times we expect to see a packet retransmitted.
char * list_attributes
Raw attribute filter string.
RADIUS_PACKET * expect
Request/response.
struct timeval quiet
We may need to 'mute' the stats if libpcap starts dropping packets, or we run out of memory...
rs_capture_t capture[RS_RETRANSMIT_MAX]
Buffered request packets (if a response filter has been applied).
bool print_packet
Print packet info, disabled with -W.
VALUE_PAIR * filter_request_vps
Sorted filter vps.
struct rs_event rs_event_t
Statistic write/print event.
rs_packet_logger_t logger
Packet logger.
struct timeval when
Time when the packet was received, or next time an event is scheduled.
uint64_t limit
Maximum number of packets to capture.
void(* rs_stats_print_cb_t)(rs_update_t *this, rs_stats_t *stats, struct timeval *now)
Callback for printing stats values.
fr_pcap_t * out
Where to write output.
char const * filter_request
Raw request filter string.
fr_event_list_t * list
List to insert new event into.
double latency_smoothed
Smoothed moving average.
PW_CODE
RADIUS packet codes.
int intervals
Number of stats intervals.
Statistic write/print event.
struct rs_malformed rs_malformed_t
bool from_auto
From list was auto-generated.
bool in_request_tree
Whether the request is currently in the request tree.
uint64_t rt_req
Number of times we saw the same request packet.
Stats for a single interval.
#define RS_MAX_ATTRS
Maximum number of attributes we can filter on.
bool from_file
Were reading pcap data from files.
uint64_t attribute_too_short
fr_event_list_t * list
The event list.
void(* rs_stats_print_header_cb_t)(rs_update_t *this)
Callback for printing stats header.
struct rs_stats rs_stats_t
One set of statistics.