28 RCSIDH(radsniff_h,
"$Id: 10c2de3c134cbcb676f0c24bcb98032b29ee09e7 $")
30 #include <sys/types.h>
32 #include <freeradius-devel/util/pcap.h>
33 #include <freeradius-devel/util/event.h>
34 #include <freeradius-devel/radius/radius.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__)
80 struct timeval *elapsed,
struct timeval *latency,
bool response,
bool body);
82 #ifdef HAVE_COLLECTDC_H
83 RS_STATS_OUT_COLLECTD = 1,
91 #ifdef HAVE_COLLECTDC_H
92 typedef struct rs_stats_tmpl rs_stats_tmpl_t;
93 typedef struct rs_stats_value_tmpl rs_stats_value_tmpl_t;
100 typedef struct CC_HINT(__packed__) {
119 uint64_t received_total;
120 uint64_t linked_total;
121 uint64_t unlinked_total;
122 uint64_t reused_total;
136 long double latency_total;
138 double latency_average;
170 struct timeval
quiet;
313 #ifdef HAVE_COLLECTDC_H
314 char const *collectd;
316 lcc_connection_t *handle;
317 rs_stats_tmpl_t *tmpl;
322 #ifdef HAVE_COLLECTDC_H
327 typedef void (*rs_stats_cb_t)(
rs_t *
conf, rs_stats_value_tmpl_t *tmpl);
329 struct rs_stats_value_tmpl {
344 rs_stats_value_tmpl_t *value_tmpl;
346 lcc_value_list_t *
value;
348 rs_stats_tmpl_t *
next;
354 rs_stats_tmpl_t *rs_stats_collectd_init_latency(TALLOC_CTX *ctx, rs_stats_tmpl_t **
out,
rs_t *
conf,
356 void rs_stats_collectd_do_stats(
rs_t *
conf, rs_stats_tmpl_t *tmpls,
struct timeval *now);
357 int rs_stats_collectd_open(
rs_t *
conf);
358 int rs_stats_collectd_close(
rs_t *
conf);
fr_radius_packet_code_t
RADIUS packet codes.
@ FR_RADIUS_CODE_MAX
Maximum possible protocol code.
static fr_time_delta_t timeout
Stores all information relating to an event list.
#define RADIUS_AUTH_VECTOR_LENGTH
rs_stats_t * stats
Where to write stats.
fr_radius_packet_code_t filter_response_code
Filter response packets by code.
fr_pcap_t * in
PCAP handle event occurred on.
fr_packet_t * expect
Request/response.
bool to_output_dir
Were writing attributes into directory.
fr_event_timer_t const * event
Event created when we received the original request.
uint64_t attribute_underflow
rs_stats_print_cb_t body
Print body.
bool print_packet
Print packet info, disabled with -W.
uint64_t min_length_field
uint8_t * data
PCAP packet data.
char const * output_dir
Where we should save the files $PATH/requests.txt and $PATH/reply.txt.
@ RS_STATS_OUT_STDIO_FANCY
bool in_request_tree
Whether the request is currently in the request tree.
rs_status_t event_flags
Events we log and capture on.
uint64_t latency_smoothed_count
Number of CMA datapoints processed.
int link_da_num
Number of rtx fr_dict_attr_ts.
fr_radius_packet_code_t filter_request_code
Filter request packets by code.
rs_stats_t * stats
Stats to process.
int buffer_pkts
Size of the ring buffer to setup for live capture.
char const * filter_response
Raw response filter string.
fr_event_list_t * list
List to insert new event into.
bool from_dev
Were reading pcap data from devices.
uint64_t min_length_packet
rs_packet_logger_t logger
Packet logger.
char * pcap_filter_vlan
Variant of the normal filter to apply to devices which support VLAN tags.
char * pcap_filter
PCAP filter string applied to live capture devices.
int intervals
Number of stats intervals.
#define RS_MAX_ATTRS
Maximum number of attributes we can filter on.
bool from_auto
From list was auto-generated.
rs_latency_t * stats_req
Latency entry for the request type.
bool done_header
Have we printed the stats header?
uint64_t attribute_too_short
bool decode_attrs
Whether we should decode attributes in the request and response.
uint64_t id
Monotonically increasing packet counter.
void(* rs_stats_print_header_cb_t)(rs_update_t *this)
Callback for printing stats header.
rs_latency_t * stats_rsp
Latency entry for the request type.
bool to_file
Were writing pcap data to files.
uint64_t ma_invalid_length
fr_pair_list_t link_vps
fr_pair_ts used to link retransmissions.
fr_rb_node_t request_node
fr_packet_t * packet
The original packet.
#define RS_RETRANSMIT_MAX
Maximum number of times we expect to see a packet retransmitted.
rs_stats_print_header_cb_t head
Print header.
char * list_attributes
Raw attribute filter string.
char * radius_secret
Secret to decode encrypted attributes.
bool from_file
Were reading pcap data from files.
fr_pcap_t * out
Where to write output.
uint64_t attribute_overflow
fr_pcap_t * in
PCAP handle the original request was received on.
uint64_t invalid_attribute
fr_pcap_t * in
Linked list of PCAP handles to check for drops.
rs_capture_t * capture_p
Next packet slot.
void(* rs_stats_print_cb_t)(rs_update_t *this, rs_stats_t *stats, struct timeval *now)
Callback for printing stats values.
bool in_link_tree
Whether the request is currently in the linked tree.
int intervals
Number of stats intervals.
fr_event_list_t * list
The event list.
fr_packet_t * linked
The subsequent response or forwarded request the packet.
bool verify_radius_authenticator
Check RADIUS authenticator in packets.
uint64_t limit
Maximum number of packets to capture.
char const * pidfile
File to write PID to.
uint64_t min_length_mimatch
uint64_t rt_rsp
Number of times we saw a retransmitted response packet.
bool from_stdin
Were reading pcap data from stdin.
bool daemonize
Daemonize and write PID out to file.
double latency_smoothed
Smoothed moving average.
uint64_t rt_req
Number of times we saw the same request packet.
fr_pair_list_t filter_response_vps
Sorted filter vps.
bool promiscuous
Capture in promiscuous mode.
fr_pair_list_t expect_vps
fr_pair_list_t packet_vps
bool logged
Whether any messages regarding this request were logged.
char * link_attributes
Names of fr_dict_attr_ts to use for rtx.
bool silent_cleanup
Cleanup was forced before normal expiry period, ignore stats about packet loss.
char const * filter_request
Raw request filter string.
void(* rs_packet_logger_t)(uint64_t count, rs_status_t status, fr_pcap_t *handle, fr_packet_t *packet, fr_pair_list_t *list, struct timeval *elapsed, struct timeval *latency, bool response, bool body)
struct pcap_pkthdr * header
PCAP packet header.
uint64_t too_many_attributes
bool verify_udp_checksum
Check UDP checksum in packets.
bool to_stdout
Were writing pcap data to stdout.
fr_pair_list_t filter_request_vps
Sorted filter vps.
Statistic write/print event.
Stats for a single interval.
FD data which gets passed to callbacks.
fr_aka_sim_id_type_t type
static size_t char ** out