aboutsummaryrefslogtreecommitdiffstats
path: root/ui/cli/tap-ldapstat.c
blob: e0021059fc7156a8f17e74f6f745353dfcc57966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* tap-ldapstat.c
 *
 * Based on afpstat
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <epan/packet_info.h>
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <ui/cli/cli_service_response_time_table.h>
#include <epan/value_string.h>
#include <epan/dissectors/packet-ldap.h>
#include "epan/timestats.h"

void register_tap_listener_ldapstat(void);

#define LDAP_NUM_PROCEDURES     24

/* used to keep track of the statistics for an entire program interface */
typedef struct _ldapstat_t {
	srt_stat_table ldap_srt_table;
} ldapstat_t;

static int
ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
{
	const ldap_call_response_t *ldap=(const ldap_call_response_t *)psi;
	ldapstat_t *fs=(ldapstat_t *)pldap;

	/* we are only interested in reply packets */
	if(ldap->is_request){
		return 0;
	}
	/* if we havnt seen the request, just ignore it */
	if(!ldap->req_frame){
		return 0;
	}

	/* only use the commands we know how to handle */
	switch(ldap->protocolOpTag){
	case LDAP_REQ_BIND:
	case LDAP_REQ_SEARCH:
	case LDAP_REQ_MODIFY:
	case LDAP_REQ_ADD:
	case LDAP_REQ_DELETE:
	case LDAP_REQ_MODRDN:
	case LDAP_REQ_COMPARE:
	case LDAP_REQ_EXTENDED:
		break;
	default:
		return 0;
	}

	add_srt_table_data(&fs->ldap_srt_table, ldap->protocolOpTag, &ldap->req_time, pinfo);
	return 1;
}

static void
ldapstat_draw(void *pss)
{
	ldapstat_t *ss = (ldapstat_t *)pss;

	draw_srt_table_data(&ss->ldap_srt_table, TRUE, TRUE);
}


static void
ldapstat_init(const char *opt_arg, void *userdata _U_)
{
	ldapstat_t *ldap;
	const char *filter = NULL;
	GString *error_string;
	int i;

	if (!strncmp(opt_arg, "ldap,srt,", 9)) {
		filter = opt_arg+8;
	}

	ldap = g_new(ldapstat_t,1);

	init_srt_table("LDAP", &ldap->ldap_srt_table, LDAP_NUM_PROCEDURES, NULL, filter ? g_strdup(filter) : NULL);
	for (i = 0; i < LDAP_NUM_PROCEDURES; i++)
	{
		init_srt_table_row(&ldap->ldap_srt_table, i, val_to_str_const(i, ldap_procedure_names, "<unknown>"));
	}

	error_string = register_tap_listener("ldap", ldap, filter, 0, NULL, ldapstat_packet, ldapstat_draw);
	if (error_string) {
		/* error, we failed to attach to the tap. clean up */
		free_srt_table_data(&ldap->ldap_srt_table);
		g_free(ldap);

		fprintf(stderr, "tshark: Couldn't register ldap,srt tap: %s\n",
		    error_string->str);
		g_string_free(error_string, TRUE);
		exit(1);
	}
}

static stat_tap_ui ldapstat_ui = {
	REGISTER_STAT_GROUP_GENERIC,
	NULL,
	"ldap,srt",
	ldapstat_init,
	0,
	NULL
};

void
register_tap_listener_ldapstat(void)
{
	register_stat_tap_ui(&ldapstat_ui, NULL);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */