2 * Copyright 2006 Alejandro Vaquero <alejandrovaquero@yahoo.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 #include "epan/packet_info.h"
38 #include <epan/stat_cmd_args.h>
39 #include "epan/value_string.h"
41 #include <epan/dissectors/packet-radius.h>
42 #include "timestats.h"
44 #define NUM_TIMESTATS 8
46 /* used to keep track of the statistics for an entire program interface */
47 typedef struct _radiusstat_t {
49 timestat_t rtd[NUM_TIMESTATS];
56 static const value_string radius_message_code[] = {
60 { 3, "Access Passw "},
61 { 4, "Ascend Acce Ev"},
63 { 6, "Change Filter "},
69 radiusstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pri)
71 radiusstat_t *rs=(radiusstat_t *)prs;
72 const radius_info_t *ri=pri;
78 case RADIUS_ACCESS_REQUEST:
79 case RADIUS_ACCOUNTING_REQUEST:
80 case RADIUS_ACCESS_PASSWORD_REQUEST:
81 case RADIUS_ASCEND_ACCESS_EVENT_REQUEST:
82 case RADIUS_DISCONNECT_REQUEST:
83 case RADIUS_CHANGE_FILTER_REQUEST:
85 /* Duplicate is ignored */
93 case RADIUS_ACCESS_ACCEPT:
94 case RADIUS_ACCESS_REJECT:
95 case RADIUS_ACCOUNTING_RESPONSE:
96 case RADIUS_ACCESS_PASSWORD_ACK:
97 case RADIUS_ACCESS_PASSWORD_REJECT:
98 case RADIUS_ASCEND_ACCESS_EVENT_RESPONSE:
99 case RADIUS_DISCONNECT_REQUEST_ACK:
100 case RADIUS_DISCONNECT_REQUEST_NAK:
101 case RADIUS_CHANGE_FILTER_REQUEST_ACK:
102 case RADIUS_CHANGE_FILTER_REQUEST_NAK:
103 if(ri->is_duplicate){
104 /* Duplicate is ignored */
107 else if (!ri->request_available) {
108 /* no request was seen */
113 /* calculate time delta between request and response */
114 nstime_delta(&delta, &pinfo->fd->abs_ts, &ri->req_time);
116 time_stat_update(&(rs->rtd[0]),&delta, pinfo);
117 if (ri->code == RADIUS_ACCESS_ACCEPT || ri->code == RADIUS_ACCESS_REJECT) {
118 time_stat_update(&(rs->rtd[1]),&delta, pinfo);
120 else if (ri->code == RADIUS_ACCOUNTING_RESPONSE) {
121 time_stat_update(&(rs->rtd[2]),&delta, pinfo);
124 time_stat_update(&(rs->rtd[7]),&delta, pinfo);
139 radiusstat_draw(void *prs)
141 radiusstat_t *rs=(radiusstat_t *)prs;
144 /* printing results */
146 printf("===========================================================================================================\n");
147 printf("RADIUS Response Time Delay (RTD) Statistics:\n");
148 printf("Filter for statistics: %s\n",rs->filter?rs->filter:"");
149 printf("Duplicate requests: %u\n",rs->req_dup_num);
150 printf("Duplicate responses: %u\n",rs->rsp_dup_num);
151 printf("Open requests: %u\n",rs->open_req_num);
152 printf("Discarded responses: %u\n",rs->disc_rsp_num);
153 printf("Type | Messages | Min RTD | Max RTD | Avg RTD | Min in Frame | Max in Frame |\n");
154 for(i=0;i<NUM_TIMESTATS;i++) {
156 printf("%s | %7u | %8.2f msec | %8.2f msec | %8.2f msec | %10u | %10u |\n",
157 val_to_str(i,radius_message_code,"Other "),rs->rtd[i].num,
158 nstime_to_msec(&(rs->rtd[i].min)), nstime_to_msec(&(rs->rtd[i].max)),
159 get_average(&(rs->rtd[i].tot), rs->rtd[i].num),
160 rs->rtd[i].min_num, rs->rtd[i].max_num
164 printf("===========================================================================================================\n");
169 radiusstat_init(const char *optarg, void* userdata _U_)
173 const char *filter=NULL;
174 GString *error_string;
176 if(!strncmp(optarg,"radius,rtd,",11)){
182 rs=g_malloc(sizeof(radiusstat_t));
183 rs->filter=g_strdup(filter);
185 for(i=0;i<NUM_TIMESTATS;i++) {
187 rs->rtd[i].min_num=0;
188 rs->rtd[i].max_num=0;
189 rs->rtd[i].min.secs=0;
190 rs->rtd[i].min.nsecs=0;
191 rs->rtd[i].max.secs=0;
192 rs->rtd[i].max.nsecs=0;
193 rs->rtd[i].tot.secs=0;
194 rs->rtd[i].tot.nsecs=0;
202 error_string=register_tap_listener("radius", rs, filter, NULL, radiusstat_packet, radiusstat_draw);
204 /* error, we failed to attach to the tap. clean up */
208 fprintf(stderr, "tshark: Couldn't register radius,rtd tap: %s\n",
210 g_string_free(error_string, TRUE);
217 register_tap_listener_radiusstat(void)
219 register_stat_cmd_arg("radius,rtd", radiusstat_init, NULL);