Browse code

- added test udp flood program & config - prototype plugin interface

Andrei Pelinescu-Onciul authored on 21/10/2001 18:33:24
Showing 4 changed files
... ...
@@ -310,7 +310,7 @@ int main(int argc, char** argv)
310 310
 					break;
311 311
 			case '?':
312 312
 					if (isprint(optopt))
313
-						fprintf(stderr, "Unknown option `-%c'.\n", optopt);
313
+						fprintf(stderr, "Unknown option `-%c�.\n", optopt);
314 314
 					else
315 315
 						fprintf(stderr, 
316 316
 								"Unknown option character `\\x%x�.\n",
317 317
new file mode 100644
... ...
@@ -0,0 +1,50 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * interface for modules
5
+ */
6
+
7
+#ifndef mod_iface_h
8
+#define mod_iface_h
9
+
10
+
11
+struct hdr_lst{
12
+	int type; /* VIA, OTHER, UNSPEC(=0), ... */
13
+	int op;   /* DEL, ADD, NOP, UNSPEC(=0) */
14
+	
15
+	union{
16
+		int offset; /* used for DEL, MODIFY */
17
+		char * value; /* used for ADD */
18
+	}u;
19
+	int len; /* length of this header field */
20
+	
21
+	
22
+	struct hdr_lst* before; /* list of headers to be inserted in front of the
23
+								current one */
24
+	struct hdr_lst* after; /* list of headers to be inserted immediately after
25
+							  the current one */
26
+	
27
+	struct hdr_lst* next;
28
+};
29
+
30
+/*
31
+ * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC)
32
+ * and/or their position (ADD). E.g.:
33
+ *  - to delete header Z insert it in to the list according to its offset 
34
+ *   and with op=DELETE
35
+ * - if you want to add a new header X after a  header Y, insert Y in the list
36
+ *   with op NOP and after it X (op ADD).
37
+ * - if you want X before Y, insert X in Y's before list.
38
+ * - if you want X to be the first header just put it first in hdr_lst.
39
+ *  -if you want to replace Y with X, insert Y with op=DELETE and then X with
40
+ *  op=ADD.
41
+ * before and after must contain only ADD ops!
42
+ * 
43
+ * Difference between "after" & "next" when ADDing:
44
+ * "after" forces the new header immediately after the current one while
45
+ * "next" means another header can be inserted between them.
46
+ * 
47
+ */
48
+
49
+
50
+#endif
0 51
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+debug=1			# for speed
2
+check_via=0
3
+dns=off
4
+rev_dns=off
5
+fork=yes
6
+log_stderror=no
7
+children=64
8
+
9
+route{
10
+
11
+	if ( method=~'^INV' && uri=~'iptel\.org' ){
12
+		forward(127.0.0.1, 5060);
13
+		drop;
14
+	};
15
+	log("no rule for this packet => dropping\n");
16
+}
17
+
0 18
new file mode 100644
... ...
@@ -0,0 +1,186 @@
1
+/* $Id$ */
2
+
3
+
4
+#include <stdio.h>
5
+#include <stdlib.h>
6
+#include <errno.h>
7
+#include <string.h>
8
+#include <ctype.h>
9
+#include <netdb.h>
10
+#include <unistd.h>
11
+#include <sys/types.h>
12
+#include <fcntl.h>
13
+#include <sys/socket.h>
14
+#include <netinet/in.h>
15
+#include <arpa/inet.h>
16
+
17
+
18
+static char *id="$Id$";
19
+static char *version="udp_flood 0.1";
20
+static char* help_msg="\
21
+Usage: udp_flood -f file -d address -p port -c count [-v]\n\
22
+Options:\n\
23
+    -f file       file with the content of the udp packet (max 65k)\n\
24
+    -d address    destination address\n\
25
+    -p port       destination port\n\
26
+    -c count      number of packets to be sent\n\
27
+    -v            increase verbosity level\n\
28
+    -V            version number\n\
29
+    -h            this help message\n\
30
+";
31
+
32
+#define BUF_SIZE 65535
33
+
34
+
35
+int main (int argc, char** argv)
36
+{
37
+	int fd;
38
+	int sock;
39
+	char c;
40
+	int n,r;
41
+	char* tmp;
42
+	char* buf[BUF_SIZE];
43
+	struct hostent* he;
44
+	struct sockaddr_in addr;
45
+	
46
+	int count;
47
+	int verbose;
48
+	char *fname;
49
+	char *dst;
50
+	int port;
51
+	
52
+	/* init */
53
+	count=0;
54
+	verbose=0;
55
+	fname=0;
56
+	dst=0;
57
+	port=0;
58
+
59
+	opterr=0;
60
+	while ((c=getopt(argc,argv, "f:c:d:p:vhV"))!=-1){
61
+		switch(c){
62
+			case 'f':
63
+				fname=optarg;
64
+				break;
65
+			case 'v':
66
+				verbose++;
67
+				break;
68
+			case 'd':
69
+				dst=optarg;
70
+				break;
71
+			case 'p':
72
+				port=strtol(optarg, &tmp, 10);
73
+				if ((tmp==0)||(*tmp)){
74
+					fprintf(stderr, "bad port number: -p %s\n", optarg);
75
+					goto error;
76
+				}
77
+				break;
78
+			case 'c':
79
+				count=strtol(optarg, &tmp, 10);
80
+				if ((tmp==0)||(*tmp)){
81
+					fprintf(stderr, "bad count: -c %s\n", optarg);
82
+					goto error;
83
+				}
84
+				break;
85
+			case 'V':
86
+				printf("version: %s\n", version);
87
+				printf("%s\n",id);
88
+				exit(0);
89
+				break;
90
+			case 'h':
91
+				printf("version: %s\n", version);
92
+				printf("%s", help_msg);
93
+				exit(0);
94
+				break;
95
+			case '?':
96
+				if (isprint(optopt))
97
+					fprintf(stderr, "Unknown option `-%c�\n", optopt);
98
+				else
99
+					fprintf(stderr, "Unknown character `\\x%x�\n", optopt);
100
+				goto error;
101
+			case ':':
102
+				fprintf(stderr, "Option `-%c� requires an argument.\n",
103
+						optopt);
104
+				goto error;
105
+				break;
106
+			default:
107
+					abort();
108
+		}
109
+	}
110
+	
111
+	/* check if all the required params are present */
112
+	if (fname==0){
113
+		fprintf(stderr, "Missing -f file\n");
114
+		exit(-1);
115
+	}
116
+	if (dst==0){
117
+		fprintf(stderr, "Missing destination (-d ...)\n");
118
+		exit(-1);
119
+	}
120
+	if(port==0){
121
+		fprintf(stderr, "Missing port number (-p port)\n");
122
+		exit(-1);
123
+	}else if(port<0){
124
+		fprintf(stderr, "Invalid port number (-p %d)\n", port);
125
+		exit(-1);
126
+	}
127
+	if(count==0){
128
+		fprintf(stderr, "Missing packet count (-c number)\n");
129
+		exit(-1);
130
+	}else if(count<0){
131
+		fprintf(stderr, "Invalid packet count (-c %d)\n", count);
132
+		exit(-1);
133
+	}
134
+	
135
+	/* open packet file */
136
+	fd=open(fname, O_RDONLY);
137
+	if (fd<0){
138
+		fprintf(stderr, "ERROR: loading packet-file(%s): %s\n", fname,
139
+				strerror(errno));
140
+		goto error;
141
+	}
142
+	n=read(fd, buf, BUF_SIZE);
143
+	if (n<0){
144
+		fprintf(stderr, "ERROR: reading file(%s): %s\n", fname,
145
+				strerror(errno));
146
+		goto error;
147
+	}
148
+	if (verbose) printf("read %d bytes from file %s\n", n, fname);
149
+	close(fd);
150
+
151
+	/* resolve destination */
152
+	he=gethostbyname(dst);
153
+	if (he==0){
154
+		fprintf(stderr, "ERROR: could not resolve %s\n", dst);
155
+		goto error;
156
+	}
157
+	/* open socket*/
158
+	addr.sin_family=he->h_addrtype;
159
+	addr.sin_port=htons(port);
160
+	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
161
+	
162
+	sock = socket(he->h_addrtype, SOCK_DGRAM, 0);
163
+	if (sock==-1){
164
+		fprintf(stderr, "ERROR: socket: %s\n", strerror(errno));
165
+		goto error;
166
+	}
167
+	if (connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))!=0){
168
+		fprintf(stderr, "ERROR: connect: %s\n", strerror(errno));
169
+		goto error;
170
+	}
171
+
172
+
173
+	/* flood loop */
174
+	for (r=0; r<count; r++){
175
+		if ((verbose>1)&&(r%1000))  putchar('.');
176
+		send(sock, buf, n, 0);
177
+	}
178
+	printf("\n%d packets sent, %d bytes each => total %d bytes\n",
179
+			count, n, n*count);
180
+
181
+	close(sock);
182
+	exit(0);
183
+
184
+error:
185
+	exit(-1);
186
+}