2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
26 // NOTE: The port numbers are maintained for both TCP and UDP.
30 int cmd_tcp_seqnr (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
33 unsigned long long int tmp
;
35 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>3) ) {
36 cli_print(cli
, "Specify the TCP sequence number (0-4294967295)\n");
37 cli_print(cli
, "You may specify up to three parameters:\n");
38 cli_print(cli
, " <sqnr>\r");
39 cli_print(cli
, " <sqnr_start> <sqnr_stop>\r");
40 cli_print(cli
, " <sqnr_start> <sqnr_stop> <sqnr_delta>\n");
41 cli_print(cli
, "If a range is specified without step size 'sqnr_delta' (2nd case)\r");
42 cli_print(cli
, "then sqnr_delta is per default set to one.\r");
47 tmp
= str2lint(argv
[0]);
49 clipkt
->tcp_seq
= (u_int32_t
) tmp
;
51 cli_print(cli
, "Argument 1 must not exceed 4294967295\n");
54 clipkt
->tcp_seq_delta
= 0;
57 tmp
= str2lint(argv
[1]);
58 if (tmp
<=0xffffffff) {
59 clipkt
->tcp_seq_start
= clipkt
->tcp_seq
;
60 clipkt
->tcp_seq_stop
= (u_int32_t
) tmp
;
62 cli_print(cli
, "Argument 2 must not exceed 4294967295\n");
65 clipkt
->tcp_seq_delta
= 1;
69 tmp
= str2lint(argv
[2]);
70 if (tmp
<=0xffffffff) {
71 clipkt
->tcp_seq_delta
= (u_int32_t
) tmp
;
73 cli_print(cli
, "Argument 3 must not exceed 4294967295\n");
78 cli_print(cli
, "Note that a zero step size disables the range feature\n");
83 txs
= mops_tcp_complexity_sqnr (clipkt
);
84 cli_print(cli
, "FYI: Packet runs through %lu sequence numbers\n", (long unsigned int) txs
);
93 int cmd_tcp_acknr (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
96 unsigned long long int tmp
;
98 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>3) ) {
99 cli_print(cli
, "Specify the TCP acknowledgement number (0-4294967295)\n");
100 cli_print(cli
, "You may specify up to three parameters:\n");
101 cli_print(cli
, " <acknr>\r");
102 cli_print(cli
, " <acknr_start> <acknr_stop>\r");
103 cli_print(cli
, " <acknr_start> <acknr_stop> <acknr_delta>\n");
104 cli_print(cli
, "If a range is specified without step size 'acknr_delta' (2nd case)\r");
105 cli_print(cli
, "then acknr_delta is per default set to one.\r");
106 cli_print(cli
, "\n");
110 tmp
= str2lint(argv
[0]);
112 clipkt
->tcp_ack
= (u_int32_t
) tmp
;
114 cli_print(cli
, "Argument 1 must not exceed 4294967295\n");
117 clipkt
->tcp_ack_delta
= 0;
120 tmp
= str2lint(argv
[1]);
121 if (tmp
<=0xffffffff) {
122 clipkt
->tcp_ack_start
= clipkt
->tcp_ack
;
123 clipkt
->tcp_ack_stop
= (u_int32_t
) tmp
;
125 cli_print(cli
, "Argument 2 must not exceed 4294967295\n");
128 clipkt
->tcp_ack_delta
= 1;
132 tmp
= str2lint(argv
[2]);
133 if (tmp
<=0xffffffff) {
134 clipkt
->tcp_ack_delta
= (u_int32_t
) tmp
;
136 cli_print(cli
, "Argument 3 must not exceed 4294967295\n");
141 cli_print(cli
, "Note that a zero step size disables the range feature\n");
146 txs
= mops_tcp_complexity_acknr (clipkt
);
147 cli_print(cli
, "FYI: Packet runs through %lu acknowledge numbers\n", (long unsigned int) txs
);
158 int cmd_tcp_offset (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
162 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) )
164 cli_print(cli
, "Specify the TCP offset (=header length, 0..15) \r");
165 cli_print(cli
, "\n");
169 tmp
= (unsigned int) str2int(argv
[0]);
171 clipkt
->tcp_offset
= (u_int8_t
) tmp
;
174 cli_print(cli
, "The TCP offset must not exceed 15\n");
183 int cmd_tcp_res (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
187 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) )
189 cli_print(cli
, "Specify the TCP reserved field in binary format (4 bits)\n");
190 cli_print(cli
, "\n");
194 tmp
= str2bin8 (argv
[0]);
195 if ((tmp
==-1)||(tmp
>15))
197 cli_print(cli
, "Invalid binary value! Allowed range: 0000 - 1111\n");
200 clipkt
->tcp_res
= (u_int8_t
) tmp
;
206 int cmd_tcp_flags (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
211 if (strcmp(argv
[argc
-1],"?")==0)
213 cli_print(cli
, "Configure a combination of TCP flags at once. All mentioned \r");
214 cli_print(cli
, "flags are set, while not mentioned flags remain unset.\r");
215 cli_print(cli
, "Flag keywords: cwr, ece, urg, ack, psh, rst, syn, fin.\r");
216 cli_print(cli
, "NOTE: The flags command alone resets all flags to zero!\n");
217 cli_print(cli
, "Example:\n");
218 cli_print(cli
, " mz(config-pkt-1-tcp)# flags syn fin ack \n");
219 cli_print(cli
, "\n");
220 mops_tcp_flags2str (clipkt
, str
);
221 cli_print(cli
,"Current setting is: %s\n",str
);
227 cli_print(cli
, "Up to 8 arguments are allowed using the keywords:\r");
228 cli_print(cli
, "cwr, ece, urg, ack, psh, rst, syn, fin.\n");
232 clipkt
->tcp_ctrl_CWR
= 0;
233 clipkt
->tcp_ctrl_ECE
= 0;
234 clipkt
->tcp_ctrl_URG
= 0;
235 clipkt
->tcp_ctrl_ACK
= 0;
236 clipkt
->tcp_ctrl_PSH
= 0;
237 clipkt
->tcp_ctrl_RST
= 0;
238 clipkt
->tcp_ctrl_SYN
= 0;
239 clipkt
->tcp_ctrl_FIN
= 0;
243 for (i
=0; i
<argc
; i
++) {
244 if (mz_strcmp(argv
[i
], "cwr", 1)==0) {
245 clipkt
->tcp_ctrl_CWR
= 1;
249 if (mz_strcmp(argv
[i
], "ece", 1)==0) {
250 clipkt
->tcp_ctrl_ECE
= 1;
254 if (mz_strcmp(argv
[i
], "urg", 1)==0) {
255 clipkt
->tcp_ctrl_URG
= 1;
259 if (mz_strcmp(argv
[i
], "ack", 1)==0) {
260 clipkt
->tcp_ctrl_ACK
= 1;
264 if (mz_strcmp(argv
[i
], "psh", 1)==0) {
265 clipkt
->tcp_ctrl_PSH
= 1;
269 if (mz_strcmp(argv
[i
], "rst", 1)==0) {
270 clipkt
->tcp_ctrl_RST
= 1;
274 if (mz_strcmp(argv
[i
], "syn", 1)==0) {
275 clipkt
->tcp_ctrl_SYN
= 1;
279 if (mz_strcmp(argv
[i
], "fin", 1)==0) {
280 clipkt
->tcp_ctrl_FIN
= 1;
285 cli_print(cli
, "Unknown keyword at position %i\n", i
+1);
288 else { // flag matched, continue
293 mops_tcp_flags2str (clipkt
, str
);
294 cli_print(cli
,"Current setting is: %s\n",str
);
301 int cmd_tcp_cwr (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
305 if (strcmp(argv
[argc
-1],"?")==0)
307 cli_print(cli
, "Set or unset the TCP Congestion Window Reduced flag (CWR)\r");
308 mops_tcp_flags2str (clipkt
, str
);
309 cli_print(cli
,"Current setting is: %s\n",str
);
315 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
320 if (mz_strcmp(argv
[0], "set", 1)==0)
321 clipkt
->tcp_ctrl_CWR
= 1;
322 else if (mz_strcmp(argv
[0], "unset", 1)==0)
323 clipkt
->tcp_ctrl_CWR
= 0;
325 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
327 mops_tcp_flags2str (clipkt
, str
);
328 cli_print(cli
,"Current setting is: %s\n",str
);
335 int cmd_tcp_ece (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
339 if (strcmp(argv
[argc
-1],"?")==0) {
340 cli_print(cli
, "Set or unset the TCP ECN-Echo flag (ECE)\r");
341 mops_tcp_flags2str (clipkt
, str
);
342 cli_print(cli
,"Current setting is: %s\n",str
);
347 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
351 if (mz_strcmp(argv
[0], "set", 1)==0)
352 clipkt
->tcp_ctrl_ECE
= 1;
353 else if (mz_strcmp(argv
[0], "unset", 1)==0)
354 clipkt
->tcp_ctrl_ECE
= 0;
356 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
358 mops_tcp_flags2str (clipkt
, str
);
359 cli_print(cli
,"Current setting is: %s\n",str
);
366 int cmd_tcp_urg (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
370 if (strcmp(argv
[argc
-1],"?")==0) {
371 cli_print(cli
, "Set or unset the TCP urgent flag (URG)\r");
372 mops_tcp_flags2str (clipkt
, str
);
373 cli_print(cli
,"Current setting is: %s\n",str
);
378 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
382 if (mz_strcmp(argv
[0], "set", 1)==0)
383 clipkt
->tcp_ctrl_URG
= 1;
384 else if (mz_strcmp(argv
[0], "unset", 1)==0)
385 clipkt
->tcp_ctrl_URG
= 0;
387 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
389 mops_tcp_flags2str (clipkt
, str
);
390 cli_print(cli
,"Current setting is: %s\n",str
);
398 int cmd_tcp_ack (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
402 if (strcmp(argv
[argc
-1],"?")==0) {
403 cli_print(cli
, "Set or unset the TCP acknowledgement flag (ACK)\r");
404 mops_tcp_flags2str (clipkt
, str
);
405 cli_print(cli
,"Current setting is: %s\n",str
);
410 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
415 if (mz_strcmp(argv
[0], "set", 1)==0)
416 clipkt
->tcp_ctrl_ACK
= 1;
417 else if (mz_strcmp(argv
[0], "unset", 1)==0)
418 clipkt
->tcp_ctrl_ACK
= 0;
420 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
422 mops_tcp_flags2str (clipkt
, str
);
423 cli_print(cli
,"Current setting is: %s\n",str
);
430 int cmd_tcp_psh (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
434 if (strcmp(argv
[argc
-1],"?")==0) {
435 cli_print(cli
, "Set or unset the TCP push flag (PSH)\r");
436 mops_tcp_flags2str (clipkt
, str
);
437 cli_print(cli
,"Current setting is: %s\n",str
);
442 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
446 if (mz_strcmp(argv
[0], "set", 1)==0)
447 clipkt
->tcp_ctrl_PSH
= 1;
448 else if (mz_strcmp(argv
[0], "unset", 1)==0)
449 clipkt
->tcp_ctrl_PSH
= 0;
451 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
453 mops_tcp_flags2str (clipkt
, str
);
454 cli_print(cli
,"Current setting is: %s\n",str
);
461 int cmd_tcp_rst (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
465 if (strcmp(argv
[argc
-1],"?")==0) {
466 cli_print(cli
, "Set or unset the TCP reset flag (RST)\r");
467 mops_tcp_flags2str (clipkt
, str
);
468 cli_print(cli
,"Current setting is: %s\n",str
);
473 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
477 if (mz_strcmp(argv
[0], "set", 1)==0)
478 clipkt
->tcp_ctrl_RST
= 1;
479 else if (mz_strcmp(argv
[0], "unset", 1)==0)
480 clipkt
->tcp_ctrl_RST
= 0;
482 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
484 mops_tcp_flags2str (clipkt
, str
);
485 cli_print(cli
,"Current setting is: %s\n",str
);
492 int cmd_tcp_syn (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
496 if (strcmp(argv
[argc
-1],"?")==0) {
497 cli_print(cli
, "Set or unset the TCP synchronisation flag (SYN)\r");
498 mops_tcp_flags2str (clipkt
, str
);
499 cli_print(cli
,"Current setting is: %s\n",str
);
504 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
508 if (mz_strcmp(argv
[0], "set", 1)==0)
509 clipkt
->tcp_ctrl_SYN
= 1;
510 else if (mz_strcmp(argv
[0], "unset", 1)==0)
511 clipkt
->tcp_ctrl_SYN
= 0;
513 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
515 mops_tcp_flags2str (clipkt
, str
);
516 cli_print(cli
,"Current setting is: %s\n",str
);
523 int cmd_tcp_fin (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
527 if (strcmp(argv
[argc
-1],"?")==0) {
528 cli_print(cli
, "Set or unset the TCP finalisation flag (FIN)\r");
529 mops_tcp_flags2str (clipkt
, str
);
530 cli_print(cli
,"Current setting is: %s\n",str
);
535 cli_print(cli
, "Use the 'set' or 'unset' keywords.\n");
539 if (mz_strcmp(argv
[0], "set", 1)==0)
540 clipkt
->tcp_ctrl_FIN
= 1;
541 else if (mz_strcmp(argv
[0], "unset", 1)==0)
542 clipkt
->tcp_ctrl_FIN
= 0;
544 cli_print(cli
, "Unknown keyword. Use the 'set' or 'unset' keywords.\n");
546 mops_tcp_flags2str (clipkt
, str
);
547 cli_print(cli
,"Current setting is: %s\n",str
);
554 int cmd_tcp_window (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
556 unsigned long int tmp
;
558 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) )
560 cli_print(cli
, "Specify the TCP window size (0..65535)\r");
561 cli_print(cli
, "\n");
565 tmp
= (unsigned long int) str2int (argv
[0]);
568 clipkt
->tcp_win
= (u_int16_t
) tmp
;
572 cli_print(cli
, "The TCP window size must not exceed 65535\n");
580 int cmd_tcp_sum (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
584 if (strncmp(argv
[argc
-1], "?", 2)==0)
586 cli_print(cli
, "Specify the TCP checksum in hexadecimal or use the keyword 'auto'.\r");
587 cli_print(cli
, "By default, the checksum is computed automatically.\n");
591 if (mz_strcmp(argv
[0], "auto", 2)==0)
593 clipkt
->tcp_sum_false
=0;
597 sum
= (int) xstr2int(argv
[0]);
601 cli_print(cli
, "The checksum must be within range 0..ffff\n");
605 clipkt
->tcp_sum
= (u_int16_t
) sum
;
606 clipkt
->tcp_sum_false
=1;
613 int cmd_tcp_urgptr(struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
616 unsigned long int tmp
;
618 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) )
620 cli_print(cli
, "Specify the TCP urgent pointer (0..65535)\r");
621 cli_print(cli
, "\n");
625 tmp
= (unsigned long int) str2int (argv
[0]);
628 clipkt
->tcp_urg
= (u_int16_t
) tmp
;
632 cli_print(cli
, "The TCP urgent pointer must not exceed 65535\n");
640 int cmd_tcp_options (struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
642 int mss
=0, sack
=0, scale
=0;
643 u_int32_t tsval
=0, tsecr
=0;
645 if ( (strcmp(argv
[argc
-1],"?")==0) || (argc
>1) ) {
646 cli_print(cli
, "Specify TCP options\n");
647 cli_print(cli
, "Option parameters:\n");
648 cli_print(cli
, "[ mss <0..65535> ] [sack] [tsval <0..4294967295> [tsecr <0..4294967295>]] [nop] [scale <0..14>]\n");
649 cli_print(cli
, "NOTE: Only a set of default options are supported in this version\r");
650 cli_print(cli
, "(20 bytes, consisting of MSS=1452 bytes, SACK permitted, a Timestamp,\r");
651 cli_print(cli
, "NOP, and Window Scale 5)\r");
652 cli_print(cli
, "\n");
656 if (clipkt
->tcp_option_used
) {
658 clipkt
->tcp_option_used
= 0;
661 mops_tcp_add_option (clipkt
, mss
, sack
, scale
, tsval
, tsecr
);
663 cli_print(cli
, "NOTE: Only a set of default options are supported in this version\r");
664 cli_print(cli
, "(20 bytes, consisting of MSS=1452 bytes, SACK permitted, a Timestamp,\r");
665 cli_print(cli
, "NOP, and Window Scale 5)\n");
673 int cmd_tcp_end(struct cli_def
*cli
, const char *command
, char *argv
[], int argc
)
676 sprintf(prompt
, "pkt-%i",clipkt
->id
);
677 cli_set_configmode(cli
, MZ_MODE_PACKET
, prompt
);