summaryrefslogtreecommitdiff
path: root/staging/cli_igmp.c
blob: cdd1df1d1c40b4cadb4a4937d1c62e4afa59b8f4 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 * Mausezahn - A fast versatile traffic generator
 * Copyright (C) 2008-2010 Herbert Haas
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the 
 * Free Software Foundation.
 * 
 * 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, see http://www.gnu.org/licenses/gpl-2.0.html
 * 
*/



#include "mz.h"
#include "cli.h"
#include "mops.h"


int cmd_igmpv2_genquery (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	int mrt, sum;
	
	if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) ) {
		cli_print(cli, "Configure a IGMPv2 general query.\n");
		cli_print(cli, "ARGUMENTS: [<MRT> [<checksum>]]\n");
		cli_print(cli, "<MRT>        ... maximum response time in 100 msec units (default: 10 s)\r");
		cli_print(cli, "<checksum>   ... user-defined checksum (usually wrong by intention) in \r");
		cli_print(cli, "                 hexadecimal notation (e. g. 'c7b3').\n");
		return CLI_OK;
	}
   
	if (argc>=1) {
		if (mz_strisnum(argv[0])==0) {
			cli_print(cli, "Maximum response time must only contain numbers!\n");
			return CLI_OK;
		}
		mrt = (int) str2int(argv[0]);
	} else mrt = 100; // default: 10 s
	
	if (argc==2) {
		if (mz_strishex(argv[1])==0) {
			cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
			return CLI_OK;
		}
		sum = (int) xstr2int(argv[1]);
		if (sum>0xffff) {
			cli_print(cli, "Checksum must be a 2-byte value!\n");
			return CLI_OK;
		}

	} else sum = -1;

	clipkt->ip_dst = str2ip32("224.0.0.1");
	clipkt->ip_ttl = 1;
	clipkt->ndelay.tv_sec = 125;
	clipkt->ndelay.tv_nsec = 0;
	if (mops_create_igmpv2 (clipkt, 0, IGMP_GENERAL_QUERY, mrt, sum, 0)) 
		cli_print(cli, "Invalid parameters!\n");

	return CLI_OK;
}


int cmd_igmpv2_specquery (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	int mrt=100, sum=-1;
	u_int8_t IP[4];
	u_int32_t mip=0;
	
	if ( (strcmp(argv[argc-1],"?")==0) || (argc>3) ) {
		cli_print(cli, "Configure a IGMPv2 group-specific query.\n");
		cli_print(cli, "ARGUMENTS: <IP-address> [<MRT> [<checksum>]]\n");
		cli_print(cli, "<IP-Address>  ... multicast group to be queried (can be ANY IP address!)\r");
		cli_print(cli, "<MRT>         ... maximum response time in 100 msec units (default: 10 s)\r");
		cli_print(cli, "<checksum>    ... user-defined checksum (usually wrong by intention) in \r");
		cli_print(cli, "                  hexadecimal notation (e. g. 'c7b3').\n");
		return CLI_OK;
	}
   

	if (argc==0) {
		cli_print(cli, "You must at least specify the group address\n");
		return CLI_OK;
	}
	
	if (argc>=1) {
		if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
		        mip = str2ip32(argv[0]);
		else {
			cli_print(cli, "Invalid IP address\n");
			return CLI_OK;
		}		
	}
	
	if (argc>=2) {
		if (mz_strisnum(argv[1])==0) {
			cli_print(cli, "Maximum response time must only contain numbers!\n");
			return CLI_OK;
		}
		mrt = (int) str2int(argv[1]);
	}
	
	if (argc==3) {
		if (mz_strishex(argv[2])==0) {
			cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
			return CLI_OK;
		}
		sum = (int) xstr2int(argv[2]);
		if (sum>0xffff) {
			cli_print(cli, "Checksum must be a 2-byte value!\n");
			return CLI_OK;
		}
	} 

	clipkt->ip_dst = mip;
	clipkt->ip_ttl = 1;
	clipkt->ndelay.tv_sec = 125;
	clipkt->ndelay.tv_nsec = 0;
	if (mops_create_igmpv2 (clipkt, 0, IGMP_GSPEC_QUERY, mrt, sum, mip))
		cli_print(cli, "Invalid parameters!\n");

	return CLI_OK;
}





int cmd_igmpv2_report (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	int sum;
	u_int8_t IP[4];
	u_int32_t mip=0;
	
	if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) || (argc==0)) {
		cli_print(cli, "Configure a IGMPv2 membership report.\n");
		cli_print(cli, "ARGUMENTS: <IP-Address> [<checksum>]\n");
		cli_print(cli, "<IP-Address>   ... multicast group address to be reported (but ANY IP\r");
		cli_print(cli, "                   address allowed, Mausezahn is really generous...)\r");
		cli_print(cli, "<checksum>     ... user-defined checksum (usually wrong by intention) in \r");
		cli_print(cli, "                   hexadecimal notation (e. g. 'c7b3').\n");
		return CLI_OK;
	}
   
	
	if (argc>=1) {
		if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
		        mip = str2ip32(argv[0]);
		else {
			cli_print(cli, "Invalid IP address\n");
			return CLI_OK;
		}
	}
       
	if (argc==2) {
		if (mz_strishex(argv[1])==0) {
			cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
			return CLI_OK;
		}
		sum = (int) xstr2int(argv[1]);
		if (sum>0xffff) {
			cli_print(cli, "Checksum must be a 2-byte value!\n");
			return CLI_OK;
		}
	} else sum = -1;

	clipkt->ip_dst = mip;
	clipkt->ip_ttl = 1;
	clipkt->ndelay.tv_sec = 1;
	clipkt->ndelay.tv_nsec = 0;

	if (mops_create_igmpv2 (clipkt, 0, IGMP_V2_REPORT, 0, sum, mip))
		cli_print(cli, "Invalid parameters!\n");

	return CLI_OK;
}


int cmd_igmpv2_leave (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	int sum;
	u_int8_t IP[4];
	u_int32_t mip=0;
	
	if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) || (argc==0)) {
		cli_print(cli, "Configure a IGMPv2 leave group message.\n");
		cli_print(cli, "ARGUMENTS: <IP-Address> [<checksum>]\n");
		cli_print(cli, "<IP-Address>   ... multicast group address that should be left; use\r");
        	cli_print(cli, "                   the special address 0.0.0.0 for a 'general leave'\r");
		cli_print(cli, "<checksum>     ... user-defined checksum (usually wrong by intention) in \r");
		cli_print(cli, "                   hexadecimal notation (e. g. 'c7b3').\n");
		return CLI_OK;
	}
   
	
	if (argc>=1) {
		if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
		        mip = str2ip32(argv[0]);
		else {
			cli_print(cli, "Invalid IP address\n");
			return CLI_OK;
		}
	}
       
	if (argc==2) {
		if (mz_strishex(argv[1])==0) {
			cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
			return CLI_OK;
		}
		sum = (int) xstr2int(argv[1]);
		if (sum>0xffff) {
			cli_print(cli, "Checksum must be a 2-byte value!\n");
			return CLI_OK;
		}
	} else sum = -1;

	clipkt->ip_dst = str2ip32("224.0.0.2");
	clipkt->ip_ttl = 1;
	clipkt->ndelay.tv_sec = 1;
	clipkt->ndelay.tv_nsec = 0;

	if (mops_create_igmpv2 (clipkt, 0, IGMP_LEAVE, 0, sum, mip))
		cli_print(cli, "Invalid parameters!\n");

	return CLI_OK;
}





int cmd_igmpv1_query (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	int sum;
	
	if ( (strcmp(argv[argc-1],"?")==0) || (argc>1) ) {
		cli_print(cli, "Configure a IGMPv1 query.\n");
		cli_print(cli, "OPTIONAL ARGUMENT: [<checksum>]\n");
		cli_print(cli, "<checksum>   ... user-defined checksum (usually wrong by intention) in \r");
		cli_print(cli, "                 hexadecimal notation (e. g. 'c7b3').\n");
		return CLI_OK;
	}
   
	if (argc==1) {
		if (mz_strishex(argv[0])==0) {
			cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
			return CLI_OK;
		}
		sum = (int) xstr2int(argv[0]);
		if (sum>0xffff) {
			cli_print(cli, "Checksum must be a 2-byte value!\n");
			return CLI_OK;
		}
	} else sum = -1;

	clipkt->ip_dst = str2ip32("224.0.0.1");
	clipkt->ip_ttl = 1;
	clipkt->ndelay.tv_sec = 125;
	clipkt->ndelay.tv_nsec = 0;
	if (mops_create_igmpv2 (clipkt, 0, IGMP_GENERAL_QUERY, 0, sum, 0))
		cli_print(cli, "Invalid parameters!\n");

	return CLI_OK;
}


int cmd_igmpv1_report (struct cli_def *cli, const char *command, char *argv[], int argc)
{
	int sum;
	u_int8_t IP[4];
	u_int32_t mip=0;
	
	if ( (strcmp(argv[argc-1],"?")==0) || (argc>2) || (argc==0)) {
		cli_print(cli, "Configure a IGMPv1 membership report.\n");
		cli_print(cli, "ARGUMENTS: <IP-Address> [<checksum>]\n");
		cli_print(cli, "<IP-Address>   ... multicast group address to be reported (but ANY IP\r");
		cli_print(cli, "                   address allowed, Mausezahn is really generous...)\r");
		cli_print(cli, "<checksum>     ... user-defined checksum (usually wrong by intention) in \r");
		cli_print(cli, "                   hexadecimal notation (e. g. 'c7b3').\n");
		return CLI_OK;
	}
   
	
	if (argc>=1) {
		if (mops_pdesc_ip (IP, argv[0])==0) // check if format is really an IP address
		        mip = str2ip32(argv[0]);
		else {
			cli_print(cli, "Invalid IP address\n");
			return CLI_OK;
		}
	} 
       
	if (argc==2) {
		if (mz_strishex(argv[1])==0) {
			cli_print(cli, "Checksum must only contain hexadecimal numbers!\n");
			return CLI_OK;
		}
		sum = (int) xstr2int(argv[1]);
		if (sum>0xffff) {
			cli_print(cli, "Checksum must be a 2-byte value!\n");
			return CLI_OK;
		}
	} else sum = -1;

	clipkt->ip_dst = mip;
	clipkt->ip_ttl = 1;
	clipkt->ndelay.tv_sec = 1;
	clipkt->ndelay.tv_nsec = 0;

	if (mops_create_igmpv2 (clipkt, 0, IGMP_V1_REPORT, 0, sum, mip))
		cli_print(cli, "Invalid parameters!\n");

	return CLI_OK;
}