tg.patch 10 KB
Newer Older
1
2
diff -ru dist-tg2.0/src/tg/config.h tg2.0/src/tg/config.h
--- dist-tg2.0/src/tg/config.h	Thu Jan 24 16:30:09 2002
Mike Hibler's avatar
Mike Hibler committed
3
+++ tg2.0/src/tg/config.h	Mon Jul  8 14:46:06 2002
4
5
6
7
8
9
10
11
12
@@ -14,7 +14,7 @@
 
 /* Maximum packet buffer size.						*/
 
-#define MAX_PKT_SIZE		8192 /* 3072	/* Sized for Ethernet.	*/
+#define MAX_PKT_SIZE		65536 /* 3072	/* Sized for Ethernet.	*/
 
 /* Maximum value from random-number generator.				*/
 
13
14
diff -ru dist-tg2.0/src/tg/log.c tg2.0/src/tg/log.c
--- dist-tg2.0/src/tg/log.c	Thu Jan 24 16:30:09 2002
Mike Hibler's avatar
Mike Hibler committed
15
+++ tg2.0/src/tg/log.c	Mon Jul  8 14:46:06 2002
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
@@ -268,6 +268,11 @@
 	char		*cp = buf;
 	char		ctl;
 
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
+
 	/* Encode record type.						*/
 
 	*cp++ = LOGTYPE_ACCEPT;
@@ -326,6 +331,11 @@
 	char		*cp = buf;
 	char		ctl;
 
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
+
 	/* Encode record type.						*/
 
 	*cp++ = LOGTYPE_ERROR;
@@ -391,6 +401,11 @@
 	char		*cp = buf;
 	char		ctl;
 
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
+
 	/* Encode record type.						*/
 
 	*cp++ = LOGTYPE_RX;
@@ -459,6 +474,11 @@
 	char		*cp = buf;
 	char		ctl;
 
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
+
 	/* Encode record type.						*/
 
 	*cp++ = LOGTYPE_SETUP;
@@ -510,6 +530,11 @@
 	char		*cp = buf;
 	char		ctl;
 
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
+
 	/* Encode record type.						*/
 
 	*cp++ = LOGTYPE_TEARDOWN;
76
@@ -568,6 +593,11 @@
77
78
 	char		*cp = buf;
 	char		ctl;
79
 
80
81
82
83
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
84
+
85
86
 	/* Encode record type.						*/
 
87
88
89
90
91
92
93
94
95
96
97
98
 	*cp++ = LOGTYPE_TX;
@@ -717,6 +747,10 @@
 
 	extern FILE	*log_fp;
 	
+#ifdef USEEVENTS
+	if (log_fp == NULL)
+		return;
+#endif
 	if (log_fp != stdout &&  log_fp != stderr) 
 	  (void) fclose (log_fp);
 
99
100
diff -ru dist-tg2.0/src/tg/prot_dgram.c tg2.0/src/tg/prot_dgram.c
--- dist-tg2.0/src/tg/prot_dgram.c	Thu Jan 24 16:30:10 2002
Mike Hibler's avatar
Mike Hibler committed
101
+++ tg2.0/src/tg/prot_dgram.c	Mon Jul  8 14:56:37 2002
102
@@ -198,6 +198,22 @@
103
104
105
106
107
108
109
110
111
112
113
114
 	for (;;)
 		{
 
+#ifdef USEEVENTS
+		extern int gotevent;
+		tgevent_poll();
+		if (gotevent)
+			{
+			rcving = 0;
+			errno = ETIME;
+			return (0);
+			}
115
116
+		if (tv.tv_sec > 0 || tv.tv_usec > 100000)
+			{
117
118
+			tv.tv_sec = 0;
+			tv.tv_usec = 100000;
119
+			}
120
121
122
123
124
+#endif
+
 		/* Set up for select:  get fd bitmaps.			*/
 
 		rfds = fds;
Mike Hibler's avatar
Mike Hibler committed
125
126
127
128
129
130
131
132
133
@@ -396,6 +412,7 @@
 
 	if (fd == -1)
 		{
+		(*(prtab->buffer_free))(buf);
 		errno = EINVAL;
 		return (-1);
 		}
@@ -427,6 +444,7 @@
Mike Hibler's avatar
Mike Hibler committed
134
135
136
137
138
139
140
 
 			if (fromlen == 0)
 				{
+				(*(prtab->buffer_free))(buf);
 				errno = EBADF;
 				return (-1);
 				}
Mike Hibler's avatar
Mike Hibler committed
141
@@ -489,6 +507,7 @@
Mike Hibler's avatar
Mike Hibler committed
142
143
144
145
146
147
148
 
 	if (!dgram_get_packets(fd, endtout))
 		{
+		(*(prtab->buffer_free))(buf);
 		return (-1);
 		}
 	else
Mike Hibler's avatar
Mike Hibler committed
149
150
151
152
153
154
155
156
157
@@ -508,6 +527,7 @@
 
 			if (fromlen == 0)
 				{
+				(*(prtab->buffer_free))(buf);
 				errno = EBADF;
 				return (-1);
 				}
@@ -609,6 +629,11 @@
158
159
160
 	justrcvd = 0;
 	sta = close(fd);    
 	log_teardown(NULL, sta == 0 ? -1 : sta);
161
162
+	if (fd == sfd)
+		sfd = -1;
163
164
165
166
167
168
+#ifdef USEEVENTS
+	firsttime = 1;
+#endif
 	return (sta);
 	}
 
169
170
diff -ru dist-tg2.0/src/tg/prot_stream.c tg2.0/src/tg/prot_stream.c
--- dist-tg2.0/src/tg/prot_stream.c	Thu Jan 24 16:30:10 2002
Mike Hibler's avatar
Mike Hibler committed
171
+++ tg2.0/src/tg/prot_stream.c	Mon Jul  8 14:59:52 2002
172
@@ -147,6 +147,22 @@
173
174
175
176
177
178
179
180
181
182
183
184
 	for (;;)
 		{
 
+#ifdef USEEVENTS
+		extern int gotevent;
+		tgevent_poll();
+		if (gotevent)
+			{
+			rcving = 0;
+			errno = ETIME;
+			return (0);
+			}
185
186
187
188
189
+		if (tv.tv_sec > 0 || tv.tv_usec > 100000)
+			{
+			tv.tv_sec = 0;
+			tv.tv_usec = 100000;
+			}
190
191
192
193
194
+#endif
+
 		/* Set up for select:  get fd bitmaps.			*/
 
 		rfds = fds;
Mike Hibler's avatar
Mike Hibler committed
195
196
197
198
199
200
201
202
203
@@ -384,6 +400,7 @@
 	/* Make sure that fd wasn't closed out from under the sender.	*/
 
 	if (fd < 0) {
+		buffer_generic_free(buf);
 		errno = EINVAL;
 		return (-1);
 	}
@@ -440,6 +457,7 @@
Mike Hibler's avatar
Mike Hibler committed
204
205
206
207
208
209
210
 	    /* new connections while we are waiting to write.		*/
 
             if (!stream_get_packets(fd, endtout)) {
+		buffer_generic_free(buf);
 		return (-1);
             } else {
 
Mike Hibler's avatar
Mike Hibler committed
211
@@ -597,6 +615,22 @@
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
 		return (-1);
 		}
 
+#ifdef USEEVENTS
+	/*
+	 * XXX force the connection to disappear quickly in case we are
+	 * doing a restart.
+	 *
+	 * This is not considered a legit thing to do in general as it
+	 * potentially leaves TCP segments floating around that might be
+	 * improperly delivered to a new connection on the same IP/port.
+	 */
+	{
+		struct linger linger;
+		linger.l_onoff = 1;
+		linger.l_linger = 0;
+		setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
+	}
+#endif
 	result = close(fd);
 	log_teardown(NULL, result == 0 ? -1 : errno);
 
Mike Hibler's avatar
Mike Hibler committed
234
@@ -626,5 +660,8 @@
235
236
237
238
239
240
241
242
 		errno = tmperrno;
 		}
 
+#ifdef USEEVENTS
+	firsttime = 1;
+#endif
 	return (result);
 	}
243
244
diff -ru dist-tg2.0/src/tg/prot_tcp.c tg2.0/src/tg/prot_tcp.c
--- dist-tg2.0/src/tg/prot_tcp.c	Thu Jan 24 16:30:10 2002
Mike Hibler's avatar
Mike Hibler committed
245
+++ tg2.0/src/tg/prot_tcp.c	Mon Jul  8 14:46:06 2002
246
@@ -184,7 +184,24 @@
247
248
249
250
 			return (-1);
 		}	
 
-		if ((connect(sfd, &(prot->dst), sizeof(prot->dst)) < 0) &
251
252
253
+		/* Bind to a local address if desired.			*/
+		if (prot->qos & QOS_SRC)
+			{
254
255
256
257
258
259
260
+#ifdef USEEVENTS
+			flags = 1;
+			if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(int)) < 0)
+				{
+				perror("tcp_setup: can't set REUSEADDR");
+				}
+#endif
261
262
263
264
265
266
267
+			if (bind(sfd, &(prot->src), sizeof(prot->src)) < 0)
+				{
+				(void)close(sfd);
+				return (-1);
+				}
+			}
+
268
269
270
271
+		if ((connect(sfd, &(prot->dst), sizeof(prot->dst)) < 0) &&
 		    (errno != EINPROGRESS))
 			{
 			(void)close(sfd);
272
273
274
275
276
277
278
279
280
281
282
283
284
285
@@ -217,6 +234,13 @@
 			return (-1);
 		}	
 
+#ifdef USEEVENTS
+		flags = 1;
+		if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(int)) < 0)
+			{
+			perror("tcp_setup: can't set REUSEADDR");
+			}
+#endif
 		if (bind(sfd, &(prot->src), sizeof(prot->src)) < 0)
 			{
 			(void)close(sfd);
Mike Hibler's avatar
Mike Hibler committed
286
287
diff -ru dist-tg2.0/src/tg/prot_test.c tg2.0/src/tg/prot_test.c
--- dist-tg2.0/src/tg/prot_test.c	Thu Jan 24 16:30:10 2002
Mike Hibler's avatar
Mike Hibler committed
288
+++ tg2.0/src/tg/prot_test.c	Mon Jul  8 14:46:06 2002
Mike Hibler's avatar
Mike Hibler committed
289
290
291
292
293
294
295
296
@@ -447,6 +447,7 @@
 
 	if (!test_get_packets(prtab, fd, endtout))
 		{
+		buffer_generic_free(buf);
 		return (-1);
 		}
 	else
297
298
diff -ru dist-tg2.0/src/tg/prot_udp.c tg2.0/src/tg/prot_udp.c
--- dist-tg2.0/src/tg/prot_udp.c	Thu Jan 24 16:30:10 2002
Mike Hibler's avatar
Mike Hibler committed
299
+++ tg2.0/src/tg/prot_udp.c	Mon Jul  8 14:46:06 2002
300
301
302
303
304
305
306
307
308
309
310
311
312
313
@@ -199,13 +199,20 @@
 
 		if (prot->qos & QOS_SRC)
 			{
+#ifdef USEEVENTS
+			flags = 1;
+			if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(int)) < 0)
+			{
+				perror("udp_setup: can't set REUSEADDR");
+			}
+#endif
 			if (bind(sfd, &(prot->src), sizeof(prot->src)) < 0)
 				{
 				(void)close(sfd);
314
315
316
317
318
319
320
321
 				return (-1);
 				}
 			}
-		if ((connect(sfd, &(prot->dst), sizeof(prot->dst)) < 0) &
+		if ((connect(sfd, &(prot->dst), sizeof(prot->dst)) < 0) &&
 		    (errno != EINPROGRESS))
 			{
 			(void)close(sfd);
322
@@ -232,7 +239,7 @@
323
324
325
326
327
328
329
330
 
 
 
-		    /* don't think this is correect */
+		    /* don't think this is correct */
 		addr = (struct sockaddr_in *)&(prot->src);
 		if ( IN_MULTICAST(ntohl(addr->sin_addr.s_addr)))		
 	        {
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@@ -270,6 +277,13 @@
 		 }   
 		 else
 		 {    
+#ifdef USEEVENTS
+			flags = 1;
+			if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(int)) < 0)
+			{
+				perror("udp_setup: can't set REUSEADDR");
+			}
+#endif
 		        if (bind(sfd, &(prot->src), sizeof(prot->src)) < 0)
 			{
 			    (void)close(sfd);
345
346
diff -ru dist-tg2.0/src/tg/tg.y tg2.0/src/tg/tg.y
--- dist-tg2.0/src/tg/tg.y	Thu Jan 24 16:30:10 2002
Mike Hibler's avatar
Mike Hibler committed
347
+++ tg2.0/src/tg/tg.y	Mon Jul  8 14:46:06 2002
348
@@ -133,7 +133,11 @@
349
350
351
352
353
 char                    *version = "2.0";	/* TG program version.	*/
 char			*ofile = NULL;
 char			*ifile = NULL;
- int			FlushOutput = 0;      /* whether to flush after each*/
+int			FlushOutput = 0;      /* whether to flush after each*/
354
+int			active_tx_asn = -1;
355
356
357
358
359
360
+#ifdef USEEVENTS
+int			gotevent;
+#endif
 
 
 /* Variables local to this file.					*/
361
@@ -856,6 +860,14 @@
362
363
364
365
366
 	void		sigint();
 	FILE		*fp;
 
+#ifdef USEEVENTS
+	tgevent_init(argc, argv);
367
368
369
370
+
+	(void) signal(SIGINT, sigint);
+	(void) signal(SIGTERM, sigint);
+
371
372
373
374
375
+	tgevent_loop();
+#else
 	/* Set debugging if it is desired.				*/
 
 #	if YYDEBUG
376
@@ -917,6 +929,7 @@
377
378
379
380
381
382
383
 	/* Generate traffic.						*/
 
 	do_actions();
+#endif
 	return (0);
 	}
 
384
385
386
387
388
389
390
391
392
393
@@ -1005,7 +1018,7 @@
 	/* If there is no explicit setup clause, do an immediate setup.	*/
 
 	if (got_setup_implicit &&
-	    ((tx_asn = (*(prot.prot->setup))(&prot)) == -1))
+	    ((active_tx_asn = tx_asn = (*(prot.prot->setup))(&prot)) == -1))
 		{
 
 		/* log the setup error. */
@@ -1017,6 +1030,10 @@
394
395
396
397
398
399
400
401
402
403
 	/* Each pass through the following loop processes one tg_action	*/
 	/* element from the list.					*/
 
+#ifdef USEEVENTS
+ restart:
+	gotevent = 0;
+#endif
 	for (cur_tg = tg_first; cur_tg != NULL; cur_tg = cur_tg->next)
 		{
 
404
405
406
407
408
409
410
411
412
413
@@ -1070,7 +1087,7 @@
 
 			/* Perform setup phase.				*/
 
-			if ((tx_asn = (*(prot.prot->setup))(&prot)) == -1)
+			if ((active_tx_asn = tx_asn = (*(prot.prot->setup))(&prot)) == -1)
 				{
 
 				/* log the setup error. */
@@ -1116,7 +1133,7 @@
414
415
416
417
418
419
420
421
 
 			(*(prot.prot->sleep_till))(&(cur_tg->stop_before));
 			}
-	else if ((cur_tg->tg_flags & TG_LOG) != 0)
+		else if ((cur_tg->tg_flags & TG_LOG) != 0)
 			{
 			/* (Re-)Start logging to a new file */
 			time_t now;
422
@@ -1144,6 +1161,10 @@
423
424
425
426
427
428
429
430
431
432
 
 			generate(tx_asn, cur_tg, lasttime);
 			}
+#ifdef USEEVENTS
+		if (gotevent)
+			goto restart;
+#endif
 		}
 
 	/* Finished, tear down connection.				*/
433
@@ -1154,8 +1175,11 @@
434
 		/* log the teardown error. */
435
 
436
 		perror("do_actions: protocol teardown");
437
+#ifndef USEEVENTS
438
 		exit(-1);
439
+#endif
440
441
442
443
444
 		}
+	active_tx_asn = -1;
 
 	return;
 	}
445
@@ -1341,6 +1365,12 @@
446
447
448
449
450
451
452
453
454
455
456
457
 
 		if (arrival != 0)
 			(*(prot.prot->sleep_till))(&nextpkt_tv);
+#ifdef USEEVENTS
+		else
+			tgevent_poll();
+		if (gotevent)
+			break;
+#endif
 		lasttime = nextpkt_tv;
 
 		/* Did we exceed the limit on the number of packets to send? */
458
@@ -1382,6 +1412,10 @@
459
460
461
462
463
464
465
466
467
468
 						   pktlen,
 						   &(cur_tg->stop_before),
 						   &pktid);
+#ifdef USEEVENTS
+			if (gotevent)
+				break;
+#endif
 			}
 		}
 	}
469
@@ -2096,5 +2130,16 @@
470
 	char		*addr;
471
472
 {
 
473
+	if ((*(prot.prot->teardown))(active_tx_asn) == -1)
474
475
476
477
478
479
+		{
+
+		/* log the teardown error. */
+
+		perror("sigint: protocol teardown");
+		}
480
481
482
483
484
485
 	log_close();
+#ifdef USEEVENTS
+	tgevent_shutdown();
+#endif
+	exit(1);
 }