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"
40 #include <epan/dissectors/packet-radius.h>
41 #include "timestats.h"
43 #define NUM_TIMESTATS 8
45 /* used to keep track of the statistics for an entire program interface */
46 typedef struct _radiusstat_t {
48 timestat_t rtd[NUM_TIMESTATS];
55 static const value_string radius_message_code[] = {
59 { 3, "Access Passw "},
60 { 4, "Ascend Acce Ev"},
62 { 6, "Change Filter "},
68 radiusstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pri)
70 radiusstat_t *rs=(radiusstat_t *)prs;
71 const radius_info_t *ri=pri;
77 case RADIUS_ACCESS_REQUEST:
78 case RADIUS_ACCOUNTING_REQUEST:
79 case RADIUS_ACCESS_PASSWORD_REQUEST:
80 case RADIUS_ASCEND_ACCESS_EVENT_REQUEST:
81 case RADIUS_DISCONNECT_REQUEST:
82 case RADIUS_CHANGE_FILTER_REQUEST:
84 /* Duplicate is ignored */
92 case RADIUS_ACCESS_ACCEPT:
93 case RADIUS_ACCESS_REJECT:
94 case RADIUS_ACCOUNTING_RESPONSE:
95 case RADIUS_ACCESS_PASSWORD_ACK:
96 case RADIUS_ACCESS_PASSWORD_REJECT:
97 case RADIUS_ASCEND_ACCESS_EVENT_RESPONSE:
98 case RADIUS_DISCONNECT_REQUEST_ACK:
99 case RADIUS_DISCONNECT_REQUEST_NAK:
100 case RADIUS_CHANGE_FILTER_REQUEST_ACK:
101 case RADIUS_CHANGE_FILTER_REQUEST_NAK:
102 if(ri->is_duplicate){
103 /* Duplicate is ignored */
106 else if (!ri->request_available) {
107 /* no request was seen */
112 /* calculate time delta between request and response */
113 nstime_delta(&delta, &pinfo->fd->abs_ts, &ri->req_time);
115 time_stat_update(&(rs->rtd[0]),&delta, pinfo);
116 if (ri->code == RADIUS_ACCESS_ACCEPT || ri->code == RADIUS_ACCESS_REJECT) {
117 time_stat_update(&(rs->rtd[1]),&delta, pinfo);
119 else if (ri->code == RADIUS_ACCOUNTING_RESPONSE) {
120 time_stat_update(&(rs->rtd[2]),&delta, pinfo);
123 time_stat_update(&(rs->rtd[7]),&delta, pinfo);
138 radiusstat_draw(void *prs)
140 radiusstat_t *rs=(radiusstat_t *)prs;
143 /* printing results */
145 printf("===========================================================================================================\n");
146 printf("RADIUS Response Time Delay (RTD) Statistics:\n");
147 printf("Filter for statistics: %s\n",rs->filter?rs->filter:"");
148 printf("Duplicate requests: %u\n",rs->req_dup_num);
149 printf("Duplicate responses: %u\n",rs->rsp_dup_num);
150 printf("Open requests: %u\n",rs->open_req_num);
151 printf("Discarded responses: %u\n",rs->disc_rsp_num);
152 printf("Type | Messages | Min RTD | Max RTD | Avg RTD | Min in Frame | Max in Frame |\n");
153 for(i=0;i<NUM_TIMESTATS;i++) {
155 printf("%s | %7u | %8.2f msec | %8.2f msec | %8.2f msec | %10u | %10u |\n",
156 val_to_str(i,radius_message_code,"Other "),rs->rtd[i].num,
157 nstime_to_msec(&(rs->rtd[i].min)), nstime_to_msec(&(rs->rtd[i].max)),
158 get_average(&(rs->rtd[i].tot), rs->rtd[i].num),
159 rs->rtd[i].min_num, rs->rtd[i].max_num
163 printf("===========================================================================================================\n");
168 radiusstat_init(const char *optarg, void* userdata _U_)
172 GString *error_string;
174 rs=g_malloc(sizeof(radiusstat_t));
175 if(!strncmp(optarg,"radius,rtd,",11)){
176 rs->filter=g_strdup(optarg+11);
181 for(i=0;i<NUM_TIMESTATS;i++) {
183 rs->rtd[i].min_num=0;
184 rs->rtd[i].max_num=0;
185 rs->rtd[i].min.secs=0;
186 rs->rtd[i].min.nsecs=0;
187 rs->rtd[i].max.secs=0;
188 rs->rtd[i].max.nsecs=0;
189 rs->rtd[i].tot.secs=0;
190 rs->rtd[i].tot.nsecs=0;
198 error_string=register_tap_listener("radius", rs, rs->filter, 0, NULL, radiusstat_packet, radiusstat_draw);
200 /* error, we failed to attach to the tap. clean up */
204 fprintf(stderr, "tshark: Couldn't register radius,rtd tap: %s\n",
206 g_string_free(error_string, TRUE);
213 register_tap_listener_radiusstat(void)
215 register_stat_cmd_arg("radius,rtd", radiusstat_init, NULL);