1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,33 @@ |
1 |
+# |
|
2 |
+# configuration for TurboSIP testing |
|
3 |
+# |
|
4 |
+# $ID: $ |
|
5 |
+# |
|
6 |
+ |
|
7 |
+ |
|
8 |
+debug=3 # debug level (cmd line: -dddddddddd) |
|
9 |
+#fork=yes # (cmd. line: -D) |
|
10 |
+fork=yes |
|
11 |
+fork=no |
|
12 |
+log_stderror=yes # (cmd line: -E) |
|
13 |
+#log_stderror=no # (cmd line: -E) |
|
14 |
+ |
|
15 |
+ |
|
16 |
+children=4 |
|
17 |
+check_via=no # (cmd. line: -v) |
|
18 |
+dns=off # (cmd. line: -r) |
|
19 |
+rev_dns=off # (cmd. line: -R) |
|
20 |
+#port=5070 |
|
21 |
+listen=10.0.0.179 |
|
22 |
+#listen=127.0.0.1 |
|
23 |
+#listen=192.168.57.33 |
|
24 |
+loop_checks=0 |
|
25 |
+# for more info: sip_router -h |
|
26 |
+ |
|
27 |
+#modules |
|
28 |
+ |
|
29 |
+ |
|
30 |
+route{ |
|
31 |
+ #forward(uri:host, uri:port); |
|
32 |
+ forward(127.0.0.1, 5090); |
|
33 |
+} |
0 | 34 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,40 @@ |
1 |
+ |
|
2 |
+ |
|
3 |
+ nolock flock sysv posix pmutex fastl |
|
4 |
+ |
|
5 |
+Linux 2* Athlon 1200, 2.4.16: |
|
6 |
+real 0.044/ 14.713 9.330 2.670 1.730 0.400 |
|
7 |
+user 0.040 2.610 2.950 2.670 1.720 0.400 |
|
8 |
+sys 0.000 12.110 6.370 0.000 0.010 0.000 |
|
9 |
+* 1 334.386 212.045 60.681 39.318 9.090 |
|
10 |
+ |
|
11 |
+Linux 2*PIII, 2.4.17: |
|
12 |
+real 0.056 17.771 14.476 3.099 1.902 0.603 |
|
13 |
+user 0.050 4.130 5.120 3.100 1.900 0.600 |
|
14 |
+sys 0.000 13.650 9.350 0.000 0.000 0.000 |
|
15 |
+* 1 317.339 258.500 55.339 33.964 10.767 |
|
16 |
+ |
|
17 |
+Solaris 8: |
|
18 |
+real 0.105 n/a 48.490 27.492 3.602 1.284 |
|
19 |
+user 0.090 n/a 29.330 27.410 3.590 1.270 |
|
20 |
+sys 0.010 n/a 19.110 0.010 0.010 0.020 |
|
21 |
+* 1 n/a 461.809 257.142 34.304 12.228 |
|
22 |
+ |
|
23 |
+FreeBSD, PII 333: |
|
24 |
+real: 0.147 43.952 54.428 37.385 15.706 1.863 |
|
25 |
+user: 0.121 12.761 13.131 31.958 13.402 1.606 |
|
26 |
+sys: 0.001 25.149 33.732 0.017 0.017 0.001 |
|
27 |
+* 1 299.061 370.258 254.319 106.843 12.673 |
|
28 |
+ |
|
29 |
+ |
|
30 |
+nolock= no locking, just a loop |
|
31 |
+flock= using flock |
|
32 |
+sysv = using SYSV semaphores |
|
33 |
+posix = using POSIX1003.1b semaphores (sem_wait, sem_post) |
|
34 |
+pmutex = using pthread_mutex* |
|
35 |
+fastl = using fastlock.h from ser (hand made assembler locks) |
|
36 |
+ |
|
37 |
+Test: time ./locking_test* -c 10000000 |
|
38 |
+(sip_router/test/locking/*) |
|
39 |
+ |
|
40 |
+ |
15 | 15 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,56 @@ |
1 |
+#include <stdlib.h> |
|
2 |
+#include <stdio.h> |
|
3 |
+#include <string.h> |
|
4 |
+#include <sys/types.h> |
|
5 |
+#include <sys/socket.h> |
|
6 |
+#include <netinet/in.h> |
|
7 |
+#include <errno.h> |
|
8 |
+#include <arpa/inet.h> |
|
9 |
+ |
|
10 |
+ |
|
11 |
+#define LOOP_COUNT 100 |
|
12 |
+#define PORT 5060 |
|
13 |
+#define SEND_PORT 5090 |
|
14 |
+#define SEND_ADDR 0x0a000022 /*10.0.0.34*/ /* 0x7f000001 127.0.0.1*/ |
|
15 |
+#define BUF_SIZE 65535 |
|
16 |
+static char buf[BUF_SIZE]; |
|
17 |
+ |
|
18 |
+int main(char** argv, int argn) |
|
19 |
+{ |
|
20 |
+ int sock; |
|
21 |
+ struct sockaddr_in addr; |
|
22 |
+ struct sockaddr_in to; |
|
23 |
+ int r, len; |
|
24 |
+ |
|
25 |
+ printf("starting\n"); |
|
26 |
+ |
|
27 |
+ addr.sin_family=AF_INET; |
|
28 |
+ addr.sin_port=htons(PORT); |
|
29 |
+ addr.sin_addr.s_addr=INADDR_ANY; |
|
30 |
+ to.sin_family=AF_INET; |
|
31 |
+ to.sin_port=htons(SEND_PORT); |
|
32 |
+ to.sin_addr.s_addr=htonl(SEND_ADDR); |
|
33 |
+ |
|
34 |
+ |
|
35 |
+ sock=socket(PF_INET, SOCK_DGRAM,0); |
|
36 |
+ if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){ |
|
37 |
+ fprintf(stderr, "ERROR: udp_init: bind: %s\n", strerror(errno)); |
|
38 |
+ exit(1); |
|
39 |
+ } |
|
40 |
+ |
|
41 |
+ //if (fork()) |
|
42 |
+ if (fork()){ |
|
43 |
+ close(sock); |
|
44 |
+ for(;;) sleep(100); |
|
45 |
+ exit(1); |
|
46 |
+ } |
|
47 |
+ /*children*/ |
|
48 |
+ printf("child\n"); |
|
49 |
+ for(;;){ |
|
50 |
+ len=read(sock, buf, BUF_SIZE); |
|
51 |
+ /*for (r=0;r < LOOP_COUNT; r++);*/ |
|
52 |
+ /* send it back*/ |
|
53 |
+ sendto(sock, buf, len, 0, (struct sockaddr*) &to, |
|
54 |
+ sizeof(struct sockaddr_in)); |
|
55 |
+ } |
|
56 |
+} |
0 | 57 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,205 @@ |
1 |
+/* $Id */ |
|
2 |
+ |
|
3 |
+#include <stdlib.h> |
|
4 |
+#include <stdio.h> |
|
5 |
+#include <errno.h> |
|
6 |
+#include <string.h> |
|
7 |
+#include <ctype.h> |
|
8 |
+#include <netdb.h> |
|
9 |
+#include <unistd.h> |
|
10 |
+#include <sys/types.h> |
|
11 |
+#include <sys/socket.h> |
|
12 |
+#include <netinet/in.h> |
|
13 |
+#include <arpa/inet.h> |
|
14 |
+ |
|
15 |
+ |
|
16 |
+ |
|
17 |
+static char *id="$Id$"; |
|
18 |
+static char *version="udp_test_proxy 0.1"; |
|
19 |
+static char* help_msg="\ |
|
20 |
+Usage: udp_test_proxy -l address -s port -d address -p port [-n no] [-v]\n\ |
|
21 |
+Options:\n\ |
|
22 |
+ -l address listen address\n\ |
|
23 |
+ -s port listen(source) port\n\ |
|
24 |
+ -d address destination address\n\ |
|
25 |
+ -p port destination port\n\ |
|
26 |
+ -n no number of processes\n\ |
|
27 |
+ -v increase verbosity level\n\ |
|
28 |
+ -V version number\n\ |
|
29 |
+ -h this help message\n\ |
|
30 |
+"; |
|
31 |
+#define BUF_SIZE 65535 |
|
32 |
+static char buf[BUF_SIZE]; |
|
33 |
+ |
|
34 |
+int main(int argc, char** argv) |
|
35 |
+{ |
|
36 |
+ int sock; |
|
37 |
+ pid_t pid; |
|
38 |
+ struct sockaddr_in addr; |
|
39 |
+ struct sockaddr_in to; |
|
40 |
+ int r, n, len; |
|
41 |
+ char c; |
|
42 |
+ struct hostent* he; |
|
43 |
+ int verbose; |
|
44 |
+ int sport, dport; |
|
45 |
+ char *dst; |
|
46 |
+ char *src; |
|
47 |
+ char* tmp; |
|
48 |
+ |
|
49 |
+ |
|
50 |
+ /* init */ |
|
51 |
+ verbose=0; |
|
52 |
+ dst=0; |
|
53 |
+ sport=dport=0; |
|
54 |
+ src=dst=0; |
|
55 |
+ n=0; |
|
56 |
+ |
|
57 |
+ opterr=0; |
|
58 |
+ while ((c=getopt(argc,argv, "l:p:d:s:n:vhV"))!=-1){ |
|
59 |
+ switch(c){ |
|
60 |
+ case 'v': |
|
61 |
+ verbose++; |
|
62 |
+ break; |
|
63 |
+ case 'd': |
|
64 |
+ dst=optarg; |
|
65 |
+ break; |
|
66 |
+ case 'l': |
|
67 |
+ src=optarg; |
|
68 |
+ break; |
|
69 |
+ case 'p': |
|
70 |
+ dport=strtol(optarg, &tmp, 10); |
|
71 |
+ if ((tmp==0)||(*tmp)){ |
|
72 |
+ fprintf(stderr, "bad port number: -p %s\n", optarg); |
|
73 |
+ goto error; |
|
74 |
+ } |
|
75 |
+ break; |
|
76 |
+ case 's': |
|
77 |
+ sport=strtol(optarg, &tmp, 10); |
|
78 |
+ if ((tmp==0)||(*tmp)){ |
|
79 |
+ fprintf(stderr, "bad port number: -s %s\n", optarg); |
|
80 |
+ goto error; |
|
81 |
+ } |
|
82 |
+ break; |
|
83 |
+ case 'n': |
|
84 |
+ n=strtol(optarg, &tmp, 10); |
|
85 |
+ if ((tmp==0)||(*tmp)){ |
|
86 |
+ fprintf(stderr, "bad process number: -n %s\n", optarg); |
|
87 |
+ goto error; |
|
88 |
+ } |
|
89 |
+ break; |
|
90 |
+ case 'V': |
|
91 |
+ printf("version: %s\n", version); |
|
92 |
+ printf("%s\n",id); |
|
93 |
+ exit(0); |
|
94 |
+ break; |
|
95 |
+ case 'h': |
|
96 |
+ printf("version: %s\n", version); |
|
97 |
+ printf("%s", help_msg); |
|
98 |
+ exit(0); |
|
99 |
+ break; |
|
100 |
+ case '?': |
|
101 |
+ if (isprint(optopt)) |
|
102 |
+ fprintf(stderr, "Unknown option `-%c�\n", optopt); |
|
103 |
+ else |
|
104 |
+ fprintf(stderr, "Unknown character `\\x%x�\n", optopt); |
|
105 |
+ goto error; |
|
106 |
+ case ':': |
|
107 |
+ fprintf(stderr, "Option `-%c� requires an argument.\n", |
|
108 |
+ optopt); |
|
109 |
+ goto error; |
|
110 |
+ break; |
|
111 |
+ default: |
|
112 |
+ abort(); |
|
113 |
+ } |
|
114 |
+ } |
|
115 |
+ |
|
116 |
+ /* check if all the required params are present */ |
|
117 |
+ if (dst==0){ |
|
118 |
+ fprintf(stderr, "Missing destination (-d ...)\n"); |
|
119 |
+ exit(-1); |
|
120 |
+ } |
|
121 |
+ if (src==0){ |
|
122 |
+ fprintf(stderr, "Missing listen address (-l ...)\n"); |
|
123 |
+ exit(-1); |
|
124 |
+ } |
|
125 |
+ if(sport==0){ |
|
126 |
+ fprintf(stderr, "Missing source port number (-s port)\n"); |
|
127 |
+ exit(-1); |
|
128 |
+ }else if(sport<0){ |
|
129 |
+ fprintf(stderr, "Invalid source port number (-s %d)\n", sport); |
|
130 |
+ exit(-1); |
|
131 |
+ } |
|
132 |
+ if(dport==0){ |
|
133 |
+ fprintf(stderr, "Missing destination port number (-p port)\n"); |
|
134 |
+ exit(-1); |
|
135 |
+ }else if(dport<0){ |
|
136 |
+ fprintf(stderr, "Invalid destination port number (-p %d)\n", dport); |
|
137 |
+ exit(-1); |
|
138 |
+ } |
|
139 |
+ if(n<0){ |
|
140 |
+ fprintf(stderr, "Invalid process no (-n %d)\n", n); |
|
141 |
+ exit(-1); |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ |
|
145 |
+ /* resolve destination */ |
|
146 |
+ he=gethostbyname(dst); |
|
147 |
+ if (he==0){ |
|
148 |
+ fprintf(stderr, "ERROR: could not resolve %s\n", dst); |
|
149 |
+ goto error; |
|
150 |
+ } |
|
151 |
+ |
|
152 |
+ /* set to*/ |
|
153 |
+ to.sin_family=he->h_addrtype; |
|
154 |
+ to.sin_port=htons(dport); |
|
155 |
+ memcpy(&to.sin_addr.s_addr, he->h_addr_list[0], he->h_length); |
|
156 |
+ |
|
157 |
+ /* resolve source/listen */ |
|
158 |
+ he=gethostbyname(src); |
|
159 |
+ if (he==0){ |
|
160 |
+ fprintf(stderr, "ERROR: could not resolve %s\n", dst); |
|
161 |
+ goto error; |
|
162 |
+ } |
|
163 |
+ /* open socket*/ |
|
164 |
+ addr.sin_family=he->h_addrtype; |
|
165 |
+ addr.sin_port=htons(sport); |
|
166 |
+ memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); |
|
167 |
+ |
|
168 |
+ sock = socket(he->h_addrtype, SOCK_DGRAM, 0); |
|
169 |
+ if (sock==-1){ |
|
170 |
+ fprintf(stderr, "ERROR: socket: %s\n", strerror(errno)); |
|
171 |
+ goto error; |
|
172 |
+ } |
|
173 |
+ if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){ |
|
174 |
+ fprintf(stderr, "ERROR: bind: %s\n", strerror(errno)); |
|
175 |
+ goto error; |
|
176 |
+ } |
|
177 |
+ |
|
178 |
+ for(r=1; r<n; r++){ |
|
179 |
+ if ((pid=fork())==-1){ |
|
180 |
+ fprintf(stderr, "ERROR: fork: %s\n", strerror(errno)); |
|
181 |
+ goto error; |
|
182 |
+ } |
|
183 |
+ if (pid==0) break; /* child, skip */ |
|
184 |
+ } |
|
185 |
+ |
|
186 |
+ if (verbose>3) printf("process starting\n"); |
|
187 |
+ for(;;){ |
|
188 |
+ len=read(sock, buf, BUF_SIZE); |
|
189 |
+ if (len==-1){ |
|
190 |
+ fprintf(stderr, "ERROR: read: %s\n", strerror(errno)); |
|
191 |
+ continue; |
|
192 |
+ } |
|
193 |
+ if (verbose>2) putchar('r'); |
|
194 |
+ /* send it back*/ |
|
195 |
+ len=sendto(sock, buf, len, 0, (struct sockaddr*) &to, |
|
196 |
+ sizeof(struct sockaddr_in)); |
|
197 |
+ if (len==-1){ |
|
198 |
+ fprintf(stderr, "ERROR: sendto: %s\n", strerror(errno)); |
|
199 |
+ continue; |
|
200 |
+ } |
|
201 |
+ if (verbose>1) putchar('.'); |
|
202 |
+ } |
|
203 |
+error: |
|
204 |
+ exit(-1); |
|
205 |
+} |
... | ... |
@@ -123,7 +123,7 @@ int udp_init(unsigned long ip, unsigned short port) |
123 | 123 |
} |
124 | 124 |
/* set sock opts? */ |
125 | 125 |
optval=1; |
126 |
- if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR, |
|
126 |
+ if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR , |
|
127 | 127 |
(void*)&optval, sizeof(optval)) ==-1) |
128 | 128 |
{ |
129 | 129 |
LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno)); |