This repository was archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmod_tcplib.c
3905 lines (3113 loc) · 103 KB
/
mod_tcplib.c
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
* 2002, 2003, 2004
* Ohio University.
*
* ---
*
* Starting with the release of tcptrace version 6 in 2001, tcptrace
* is licensed under the GNU General Public License (GPL). We believe
* that, among the available licenses, the GPL will do the best job of
* allowing tcptrace to continue to be a valuable, freely-available
* and well-maintained tool for the networking community.
*
* Previous versions of tcptrace were released under a license that
* was much less restrictive with respect to how tcptrace could be
* used in commercial products. Because of this, I am willing to
* consider alternate license arrangements as allowed in Section 10 of
* the GNU GPL. Before I would consider licensing tcptrace under an
* alternate agreement with a particular individual or company,
* however, I would have to be convinced that such an alternative
* would be to the greater benefit of the networking community.
*
* ---
*
* This file is part of Tcptrace.
*
* Tcptrace was originally written and continues to be maintained by
* Shawn Ostermann with the help of a group of devoted students and
* users (see the file 'THANKS'). The work on tcptrace has been made
* possible over the years through the generous support of NASA GRC,
* the National Science Foundation, and Sun Microsystems.
*
* Tcptrace is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Tcptrace 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 Tcptrace (in the file 'COPYING'); if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Original Author: Eric Helvey
* School of Electrical Engineering and Computer Science
* Ohio University
* Athens, OH
* http://www.tcptrace.org/
* Extensively Modified: Shawn Ostermann
*/
#include "tcptrace.h"
static char const GCC_UNUSED rcsid[] =
"$Header$";
#ifdef LOAD_MODULE_TCPLIB
/****************************************************************************
*
* Module Title: Mod_TCPLib
*
* Author: Eric Helvey
*
* Purpose: To generate data files needed by TCPLib and TrafGen.
*
****************************************************************************/
#include "mod_tcplib.h"
#include "dyncounter.h"
/* reading old files is problematic and I never use it anyway!!!
it probably doesn't work anymore.
sdo - Thu Aug 5, 1999 */
#undef READ_OLD_FILES
/* we're no longer interested in the old phone/conv columns */
#undef INCLUDE_PHONE_CONV
/* Local global variables */
/* different types of "directions" */
#define NUM_DIRECTION_TYPES 4
enum t_dtype {LOCAL = 0, INCOMING = 1, OUTGOING = 2, REMOTE = 3};
static char *dtype_names[NUM_DIRECTION_TYPES] = {"local","incoming","outgoing", "remote"};
/* structure to keep track of "inside" */
struct insidenode {
ipaddr min;
ipaddr max;
struct insidenode *next;
} *inside_head = NULL;
#define LOCAL_ONLY (inside_head == NULL)
/* for the parallelism hack */
#define BURST_KEY_MAGIC 0x49524720 /* 'I' 'R' 'G' '<space>' */
struct burstkey {
unsigned long magic; /* MUST be BURST_KEY_MAGIC */
unsigned long nbytes; /* bytes in burst (INCLUDING this struct) */
unsigned char key; /* one character key to return */
unsigned char unused[3]; /* (explicit padding) */
unsigned long groupnum; /* for keeping track of parallel HTTP */
};
#ifdef BROKEN
char *BREAKDOWN_APPS_NAMES[] = {
"app 1",
"app 2",
"app 3",
"app 4",
"app 5",
"app 6",
"app 7",
"app 8"
};
#endif /* BROKEN */
/* for VM efficiency, we pull the info that we want out of the tcptrace
structures into THIS structure (or large files thrash) */
typedef struct module_conninfo_tcb {
/* cached connection type (incoming, remote, etc) */
enum t_dtype dtype;
/* cached data bytes */
u_llong data_bytes;
/*
* FTP: number of data connections against this control conn
* HTTP:
* NNTP: number of bursts
* HTTP: number of bursts
*/
u_long numitems;
/* burst info */
u_long burst_bytes; /* size of the current burst */
struct burstdata *pburst;
/* was the last segment PUSHed? */
Bool last_seg_pushed; /* Thu Aug 26, 1999 - not used */
/* last time new data was sent */
timeval last_data_time;
/* link back to REAL information */
tcb *ptcb;
/* previous connection of same type */
struct module_conninfo *prev_dtype_all;/* for ALL app types */
struct module_conninfo *prev_dtype_byapp; /* just for THIS app type */
} module_conninfo_tcb;
/* structure that this module keeps for each connection */
#define TCB_CACHE_A2B 0
#define TCB_CACHE_B2A 1
#define LOOP_OVER_BOTH_TCBS(var) var=TCB_CACHE_A2B; var<=TCB_CACHE_B2A; ++var
typedef struct module_conninfo {
/* cached info */
struct module_conninfo_tcb tcb_cache[2];
/* this connection should be ignored for breakdown/convarrival */
Bool ignore_conn;
/* breakdown type */
short btype;
/* cached copy of address pair */
tcp_pair_addrblock addr_pair;
/* link back to the tcb's */
tcp_pair *ptp;
/* time of connection start */
timeval first_time;
timeval last_time;
/* previous connection in linked list of all connections */
struct module_conninfo *prev;
/* for parallel http sessions */
struct parallelism *pparallelism;
/* unidirectional conns ignored totally */
Bool unidirectional_http;
/* for determining bursts */
tcb *tcb_lastdata;
/* to determine parallelism in conns, trafgen encodes a group
number in the data */
u_long http_groupnum;
/* next connection in linked list by endpoint pairs */
struct module_conninfo *next_pair;
} module_conninfo;
module_conninfo *module_conninfo_tail = NULL;
/* data structure to store endpoint pairs */
typedef struct endpoint_pair {
/* endpoint identification */
tcp_pair_addrblock addr_pair;
/* linked list of connections using that pair */
module_conninfo *pmchead;
/* next address pair */
struct endpoint_pair *pepnext;
} endpoint_pair;
#define ENDPOINT_PAIR_HASHSIZE 1023
/* for tracking burst data */
struct burstdata {
dyn_counter nitems; /* total items (bursts) in connection */
dyn_counter size; /* size of the items */
dyn_counter idletime; /* idle time between bursts */
};
/* for tracking number of connections */
struct parallelism {
Bool counted[NUM_DIRECTION_TYPES];
/* have we already accumulated this? */
/* (in each of the 4 directions) */
Bool persistant[2]; /* is this persistant (for each TCB) */
u_short maxparallel; /* maximum degree of parallelism */
u_long ttlitems[2]; /* across entire group (each dir) */
};
static struct tcplibstats {
/* telnet packet sizes */
dyn_counter telnet_pktsize;
/* telnet interarrival times */
dyn_counter telnet_interarrival;
/* conversation interarrival times */
dyn_counter conv_interarrival_all;
/* protocol-specific interarrival times */
dyn_counter conv_interarrival_byapp[NUM_APPS];
/* conversation duration */
dyn_counter conv_duration;
/* for the interval breakdowns */
int interval_count;
timeval last_interval;
int tcplib_breakdown_interval[NUM_APPS];
/* histogram files */
MFILE *hist_file;
/* for NNTP, we track: */
/* # items per connection */
/* idletime between items */
/* burst size */
struct burstdata nntp_bursts;
/* for HTTP1.0, we track: */
/* # items per connection */
/* # connections */
/* idletime between items */
/* burst size */
struct burstdata http_P_bursts;
dyn_counter http_P_maxconns; /* max degree of concurrency */
dyn_counter http_P_ttlitems; /* ttl items across whole parallel group */
dyn_counter http_P_persistant; /* which parallel groups are persistant */
/* for HTTP1.1, we track: */
/* # items per connection */
/* idletime between items */
/* burst size */
struct burstdata http_S_bursts;
/* telnet packet sizes */
dyn_counter throughput;
int throughput_bytes;
} *global_pstats[NUM_DIRECTION_TYPES] = {NULL};
/* local debugging flag */
static int ldebug = 0;
/* parallelism for our TRAFGEN files */
static Bool trafgen_generated = FALSE;
/* offset for all ports */
static int ipport_offset = 0;
/* the name of the directory (prefix) for the output */
static char *output_dir = DEFAULT_TCPLIB_DATADIR;
/* the name of the current tcptrace input file */
static char *current_file = NULL;
/* characters to print in interval breakdown file */
static const char breakdown_hash_char[] = { 'S', 'N', 'T', 'F', 'H', 'f'};
/* FTP endpoints hash table */
endpoint_pair *ftp_endpoints[ENDPOINT_PAIR_HASHSIZE];
/* HTTP endpoints hash table */
endpoint_pair *http_endpoints[ENDPOINT_PAIR_HASHSIZE];
/* internal types */
typedef Bool (*f_testinside) (module_conninfo *pmc,
module_conninfo_tcb *ptcbc);
/* various statistics and counters */
static u_long debug_newconn_counter; /* total conns */
static u_long debug_newconn_badport; /* a port we don't want */
static u_long debug_newconn_goodport; /* we want the port */
static u_long debug_newconn_ftp_data_heuristic; /* merely ASSUMED to be ftp data */
static u_llong debug_total_bytes; /* total "bytes" accepted */
/* parallel http counters */
static u_long debug_http_total; /* all HTTP conns */
static u_long debug_http_parallel; /* parallel HTTP, not counted in breakdown/conv */
static u_long debug_http_single;
static u_long debug_http_groups;
static u_long debug_http_slaves;
static u_long debug_http_uni_conns; /* data in at most one direction, ignored */
static u_llong debug_http_uni_bytes; /* data in at most one direction, ignored */
static u_long debug_http_persistant;
static u_long debug_http_nonpersistant;
/* conns by type */
static u_long conntype_counter[NUM_DIRECTION_TYPES];
/* both flows have data */
static u_long conntype_duplex_counter[NUM_DIRECTION_TYPES];
/* this flow has data, twin is empty */
static u_long conntype_uni_counter[NUM_DIRECTION_TYPES];
/* this flow has NO data, twin is NOT empty */
static u_long conntype_nodata_counter[NUM_DIRECTION_TYPES];
/* neither this flow OR its twin has data */
static u_long conntype_noplex_counter[NUM_DIRECTION_TYPES];
/* Function Prototypes */
static void ParseArgs(char *argstring);
static int breakdown_type(tcp_pair *ptp);
static void do_final_breakdown(char* filename, f_testinside p_tester,
struct tcplibstats *pstats);
static void do_all_final_breakdowns(void);
static void do_all_conv_arrivals(void);
static void do_tcplib_final_converse(char *filename,
char *protocol, dyn_counter psizes);
static void do_tcplib_next_converse(module_conninfo_tcb *ptcbc,
module_conninfo *pmc);
static void do_tcplib_conv_duration(char *filename,
dyn_counter psizes);
static void do_tcplib_next_duration(module_conninfo_tcb *ptcbc,
module_conninfo *pmc);
static void tcplib_cleanup_bursts(void);
static void tcplib_save_bursts(void);
static Bool is_parallel_http(module_conninfo *pmc_new);
static void tcplib_filter_http_uni(void);
/* prototypes for connection-type determination */
static Bool is_ftp_ctrl_port(portnum port);
static Bool is_ftp_data_port(portnum port);
static Bool is_http_port(portnum port);
static Bool is_nntp_port(portnum port);
static Bool is_smtp_port(portnum port);
static Bool is_telnet_port(portnum port);
/* shorthand */
#define is_ftp_ctrl_conn(pmc) (pmc->btype == TCPLIBPORT_FTPCTRL)
#define is_ftp_data_conn(pmc) (pmc->btype == TCPLIBPORT_FTPDATA)
#define is_http_conn(pmc) (pmc->btype == TCPLIBPORT_HTTP)
#define is_nntp_conn(pmc) (pmc->btype == TCPLIBPORT_NNTP)
#define is_smtp_conn(pmc) (pmc->btype == TCPLIBPORT_SMTP)
#define is_telnet_conn(pmc) (pmc->btype == TCPLIBPORT_TELNET)
static char* namedfile(char *localsuffix, char * file);
static void setup_breakdown(void);
static void tcplib_add_telnet_interarrival(tcp_pair *ptp,
module_conninfo *pmc,
dyn_counter *psizes);
static void tcplib_add_telnet_packetsize(struct tcplibstats *pstats,
int length);
static void tcplib_do_ftp_control_size(char *filename, f_testinside p_tester);
static void tcplib_do_ftp_itemsize(char *filename, f_testinside p_tester);
static void tcplib_do_ftp_numitems(char *filename, f_testinside p_tester);
static void tcplib_do_smtp_itemsize(char *filename, f_testinside p_tester);
static void tcplib_do_telnet_duration(char *filename, f_testinside p_tester);
static void tcplib_do_telnet_interarrival(char *filename,
f_testinside p_tester);
static void tcplib_do_telnet_packetsize(char *filename,
f_testinside p_tester);
static void tcplib_init_setup(void);
static void update_breakdown(tcp_pair *ptp, struct tcplibstats *pstats);
module_conninfo *FindPrevConnection(module_conninfo *pmc,
enum t_dtype dtype, int app_type);
static char *FormatBrief(tcp_pair *ptp,tcb *ptcb);
static char *FormatAddrBrief(tcp_pair_addrblock *addr_pair);
static void ModuleConnFillcache(void);
/* prototypes for determining "insideness" */
static void DefineInside(char *iplist);
static Bool IsInside(ipaddr *pipaddr);
static Bool TestOutgoing(module_conninfo*, module_conninfo_tcb *ptcbc);
static Bool TestIncoming(module_conninfo*, module_conninfo_tcb *ptcbc);
static Bool TestLocal(module_conninfo*, module_conninfo_tcb *ptcbc);
static Bool TestRemote(module_conninfo*, module_conninfo_tcb *ptcbc);
static int InsideBytes(module_conninfo*, f_testinside);
static enum t_dtype traffic_type(module_conninfo *pmc,
module_conninfo_tcb *ptcbc);
/* prototypes for endpoint pairs */
static void TrackEndpoints(module_conninfo *pmc);
static hash EndpointHash(tcp_pair_addrblock *addr_pair);
static hash IPHash(ipaddr *paddr);
static Bool SameEndpoints(tcp_pair_addrblock *paddr_pair1,
tcp_pair_addrblock *paddr_pair2);
static struct module_conninfo_tcb *MostRecentFtpControl(endpoint_pair *pep);
static Bool CouldBeFtpData(tcp_pair *ptp);
static void AddEndpointPair(endpoint_pair *hashtable[],
module_conninfo *pmc);
static endpoint_pair *FindEndpointPair(endpoint_pair *hashtable[],
tcp_pair_addrblock *paddr_pair);
static Bool IsNewBurst(module_conninfo *pmc, tcb *ptcb,
module_conninfo_tcb *ptcbc,
struct tcphdr *tcp);
/* various helper routines used by many others -- sdo */
static Bool ActiveConn(module_conninfo *pmc);
static Bool RecentlyActiveConn(module_conninfo *pmc);
static void tcplib_do_GENERIC_itemsize(
char *filename, int btype,
f_testinside p_tester, int bucketsize);
static void tcplib_do_GENERIC_burstsize(
char *filename, dyn_counter counter);
static void tcplib_do_GENERIC_P_maxconns(
char *filename, dyn_counter counter);
static void tcplib_do_GENERIC_nitems(
char *filename, dyn_counter counter);
static void tcplib_do_GENERIC_idletime(
char *filename, dyn_counter counter);
static void StoreCounters(char *filename, char *header1, char *header2,
int bucketsize, dyn_counter psizes);
#ifdef READ_OLD_FILES
static dyn_counter ReadOldFile(char *filename, int bucketsize,
int maxlegal, dyn_counter psizes);
#endif /* READ_OLD_FILES */
/* First section is comprised of functions that TCPTrace will call
* for all modules.
*/
/***************************************************************************
*
* Function Name: tcplib_init
*
* Returns: TRUE/FALSE whether or not the tcplib module for tcptrace
* has been requested on the command line.
*
* Purpose: To parse the command line arguments for the tcplib module's
* command line flags, return whether or not to run the module,
* and to set up the local global variables needed to generate
* the tcplib data files.
*
* Called by: LoadModules() in tcptrace.c
*
*
****************************************************************************/
int tcplib_init(
int argc, /* Number of command line arguments */
char *argv[] /* Command line arguments */
)
{
int i; /* Runner for command line arguments */
int enable = 0; /* Do we turn on this module, or not? */
char *args = NULL;
for(i = 0; i < argc; i++) {
if (!argv[i])
continue;
/* See if they want to use us */
if ((argv[i] != NULL) && (strncmp(argv[i], "-xtcplib", 8) == 0)) {
/* Calling the Tcplib part */
enable = 1;
args = argv[i]+(sizeof("-xtcplib")-1);
printf("Capturing TCPLib traffic\n");
/* We free this argument so that no other modules
* or the main program mis-interprets this flag.
*/
argv[i] = NULL;
continue;
}
}
/* If enable is not true, then all tcplib functions will
* be ignored during this run of the program.
*/
if (!enable)
return(0); /* don't call me again */
/* parse the encoded args */
ParseArgs(args);
/* init internal data */
tcplib_init_setup();
/* don't care for detailed output! */
printsuppress = TRUE;
return TRUE;
}
/* wants strings of the form IP1-IP2 */
static struct insidenode *
DefineInsideRange(
char *ip_pair)
{
char *pdash;
struct insidenode *pnode;
ipaddr *paddr;
char *paddr1;
char *paddr2;
if (ldebug>2)
printf("DefineInsideRange('%s') called\n", ip_pair);
pdash = strchr(ip_pair,'-');
if (pdash == NULL) {
/* just one address, treat it as a range */
paddr1 = ip_pair;
paddr2 = ip_pair;
} else {
/* a pair */
*pdash = '\00';
paddr1 = ip_pair;
paddr2 = pdash+1;
}
pnode = MallocZ(sizeof(struct insidenode));
paddr = str2ipaddr(paddr1);
if (paddr == NULL) {
fprintf(stderr,"invalid IP address: '%s'\n", paddr1);
exit(-1);
}
pnode->min = *paddr;
paddr = str2ipaddr(paddr2);
if (paddr == NULL) {
fprintf(stderr,"invalid IP address: '%s'\n", paddr2);
exit(-1);
}
pnode->max = *paddr;
return(pnode);
}
static struct insidenode *
DefineInsideRecurse(
char *iplist)
{
char *pcomma;
struct insidenode *left;
/* find commas and recurse */
pcomma = strchr(iplist,',');
if (pcomma) {
*pcomma = '\00';
left = DefineInsideRecurse(iplist);
left->next = DefineInsideRecurse(pcomma+1);
return(left);
} else {
/* just one term left */
return(DefineInsideRange(iplist));
}
}
static void
DefineInside(
char *iplist)
{
if (ldebug>2)
printf("DefineInside(%s) called\n", iplist);
inside_head = DefineInsideRecurse(iplist);
if (ldebug) {
struct insidenode *phead;
printf("DefineInside: result:\n ");
for (phead=inside_head; phead; phead=phead->next) {
printf("(%s <= addr", HostAddr(phead->min));
printf(" <= %s)", HostAddr(phead->max));
if (phead->next)
printf(" OR ");
}
printf("\n");
}
}
static Bool
IsInside(
ipaddr *paddr)
{
struct insidenode *phead;
/* if use didn't specify "inside", then EVERYTHING is "inside" */
if (LOCAL_ONLY)
return(TRUE);
for (phead = inside_head; phead; phead=phead->next) {
int cmp1 = IPcmp(&phead->min, paddr);
int cmp2 = IPcmp(&phead->max, paddr);
if ((cmp1 == -2) || (cmp2 == -2)) {
/* not all the same address type, fail */
return(FALSE);
}
if ((cmp1 <= 0) && /* min <= addr */
(cmp2 >= 0)) /* max >= addr */
return(TRUE);
}
return(FALSE);
}
static Bool
TestOutgoing(
module_conninfo *pmc,
module_conninfo_tcb *ptcbc)
{
if (ptcbc == &pmc->tcb_cache[TCB_CACHE_A2B])
return( IsInside(&pmc->addr_pair.a_address) &&
!IsInside(&pmc->addr_pair.b_address));
else
return( IsInside(&pmc->addr_pair.b_address) &&
!IsInside(&pmc->addr_pair.a_address));
}
static Bool
TestIncoming(
module_conninfo *pmc,
module_conninfo_tcb *ptcbc)
{
if (ptcbc == &pmc->tcb_cache[TCB_CACHE_A2B])
return(!IsInside(&pmc->addr_pair.a_address) &&
IsInside(&pmc->addr_pair.b_address));
else
return(!IsInside(&pmc->addr_pair.b_address) &&
IsInside(&pmc->addr_pair.a_address));
}
static Bool
TestLocal(
module_conninfo *pmc,
module_conninfo_tcb *ptcbc)
{
return(IsInside(&pmc->addr_pair.a_address) &&
IsInside(&pmc->addr_pair.b_address));
}
static Bool
TestRemote(
module_conninfo *pmc,
module_conninfo_tcb *ptcbc)
{
return(!IsInside(&pmc->addr_pair.a_address) &&
!IsInside(&pmc->addr_pair.b_address));
}
static int InsideBytes(
module_conninfo *pmc,
f_testinside p_tester) /* function to test "insideness" */
{
int temp = 0;
int dir;
for (LOOP_OVER_BOTH_TCBS(dir)) {
/* if "p_tester" likes this side of the connection, count the bytes */
if ((*p_tester)(pmc, &pmc->tcb_cache[dir]))
temp += pmc->tcb_cache[dir].data_bytes;
}
return(temp);
}
static void
ParseArgs(char *argstring)
{
int argc;
char **argv;
int i;
/* make sure there ARE arguments */
if (!(argstring && *argstring))
return;
/* break the string into normal arguments */
StringToArgv(argstring,&argc,&argv);
/* check the module args */
for (i=1; i < argc; ++i) {
/* The "-o####" flag sets the offset that we're going
* to consider for tcplib data files. The reason is that
* for verification purposes, when trafgen creates traffic
* it sends it to non-standard ports. So, in order to get
* a data set from generated traffic, we'd have to remove
* the offset. The -o allows us to do that.
*/
if (argv[i] && !strncmp(argv[i], "-o", 2)) {
ipport_offset = atoi(argv[i]+2);
if (!ipport_offset) {
fprintf(stderr, "\
Invalid argument to flag \"-o\".\n\
Must be integer value greater than 0.\n");
exit(1);
}
printf("TCPLib port offset - %d\n", ipport_offset);
}
/* The "-iIPs" gives the definition of "inside". When it's used,
* we divide the the data into four sets:
* data.incoming:
* for all data flowing from "inside" to "outside"
* data.outgoing:
* for all data flowing from "outside" to "inside"
* data.local:
* for all data flowing from "inside" to "inside"
* data.remote:
* for all data flowing from "outside" to "outside"
* (probably an error)
*/
else
if (argv[i] && !strncmp(argv[i], "-i", 2)) {
if (!isdigit((int)*(argv[i]+2))) {
fprintf(stderr,"-i requires IP address list\n");
tcplib_usage();
exit(-1);
}
DefineInside(argv[i]+2);
}
/* parallelism hack */
else
if (argv[i] && !strncmp(argv[i], "-H", 2)) {
trafgen_generated = TRUE;
}
/* local debugging flag */
else
if (argv[i] && !strncmp(argv[i], "-d", 2)) {
++ldebug;
}
/* We will probably need to add another flag here to
* specify the directory in which to place the data
* files. And here it is.
*/
else if (argv[i] && !strncmp(argv[i], "-D", 2)) {
char *pdir = argv[i]+2;
if (!pdir) {
fprintf(stderr,"argument -DDIR requires directory name\n");
exit(-1);
}
output_dir = strdup(pdir);
printf("TCPLib output directory - %sdata\n", output_dir);
}
/* ... else invalid */
else {
fprintf(stderr,"tcplib module: bad argument '%s'\n",
argv[i]);
exit(-1);
}
}
}
static void
tcplib_save_bursts()
{
int dtype;
module_conninfo *pmc;
int non_parallel = 0;
char *filename;
tcplib_cleanup_bursts();
/* accumulate parallelism stats */
for (dtype=0; dtype < NUM_DIRECTION_TYPES; ++dtype) {
non_parallel = 0;
for (pmc = module_conninfo_tail; pmc; pmc = pmc->prev) {
struct parallelism *pp = pmc->pparallelism;
int dir;
/* make sure it's http */
if (!is_http_conn(pmc))
continue;
/* ignore unidirectional */
if (pmc->unidirectional_http)
continue;
/* check each TCB */
for (LOOP_OVER_BOTH_TCBS(dir)) {
module_conninfo_tcb *ptcbc = &pmc->tcb_cache[dir];
/* make sure it's
-- the right direction
-- and parallel
-- not already counted */
if (ptcbc->dtype != dtype)
continue;
if (pp == NULL) {
++non_parallel;
continue;
}
if (pp->counted[dtype])
continue;
/* count the max connections */
AddToCounter(&global_pstats[dtype]->http_P_maxconns,
pp->maxparallel, 1, 1);
/* count the ttl items in the parallel group */
AddToCounter(&global_pstats[dtype]->http_P_ttlitems,
pp->ttlitems[dir],
1, GRAN_NUMITEMS);
/* binary counter, one sample of either: */
/* 1: NOT persistant */
/* 2: persistant */
AddToCounter(&global_pstats[dtype]->http_P_persistant,
pp->persistant[dir]?2:1,
1, 1);
/* debugging */
if (pp->persistant[dir])
++debug_http_persistant;
else
++debug_http_nonpersistant;
/* don't count it again! */
pmc->pparallelism->counted[dtype] = TRUE;
}
}
/* add the NON-parallel HTTP to the counter */
AddToCounter(&global_pstats[dtype]->http_P_maxconns, 1,
non_parallel, 1);
}
/* write all the counters */
for (dtype=0; dtype < NUM_DIRECTION_TYPES; ++dtype) {
if (ldebug>1)
printf("tcplib: running burstsizes (%s)\n", dtype_names[dtype]);
/* ---------------------*/
/* Burstsize */
/* ---------------------*/
/* HTTP 1.0 */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_P_BURSTSIZE_FILE);
tcplib_do_GENERIC_burstsize(filename,
global_pstats[dtype]->http_P_bursts.size);
/* HTTP 1.1 */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_S_BURSTSIZE_FILE);
tcplib_do_GENERIC_burstsize(filename,
global_pstats[dtype]->http_S_bursts.size);
/* NNTP */
filename = namedfile(dtype_names[dtype],TCPLIB_NNTP_BURSTSIZE_FILE);
tcplib_do_GENERIC_burstsize(filename,
global_pstats[dtype]->nntp_bursts.size);
/* ---------------------*/
/* Total parallel items */
/* ---------------------*/
/* HTTP 1.0 */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_P_TTLITEMS_FILE);
tcplib_do_GENERIC_nitems(filename,
global_pstats[dtype]->http_P_ttlitems);
/* ---------------------*/
/* Num Items in Burst */
/* ---------------------*/
/* HTTP 1.1 */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_S_NITEMS_FILE);
tcplib_do_GENERIC_nitems(filename,
global_pstats[dtype]->http_S_bursts.nitems);
/* NNTP */
filename = namedfile(dtype_names[dtype],TCPLIB_NNTP_NITEMS_FILE);
tcplib_do_GENERIC_nitems(filename,
global_pstats[dtype]->nntp_bursts.nitems);
/* ---------------------*/
/* Idletime */
/* ---------------------*/
/* HTTP 1.0 */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_P_IDLETIME_FILE);
tcplib_do_GENERIC_idletime(filename,
global_pstats[dtype]->http_P_bursts.idletime);
/* HTTP 1.1 */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_S_IDLETIME_FILE);
tcplib_do_GENERIC_idletime(filename,
global_pstats[dtype]->http_S_bursts.idletime);
/* NNTP */
filename = namedfile(dtype_names[dtype],TCPLIB_NNTP_IDLETIME_FILE);
tcplib_do_GENERIC_idletime(filename,
global_pstats[dtype]->nntp_bursts.idletime);
/* store the counters */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_P_MAXCONNS_FILE);
tcplib_do_GENERIC_P_maxconns(filename,
global_pstats[dtype]->http_P_maxconns);
/* store the persistance */
filename = namedfile(dtype_names[dtype],TCPLIB_HTTP_P_PERSIST_FILE);
tcplib_do_GENERIC_nitems(filename,
global_pstats[dtype]->http_P_persistant);
if (LOCAL_ONLY)
break;
}
}
/***************************************************************************
*
* Function Name: tcplib_done
*
* Returns: Nothing
*
* Purpose: This function runs after all the packets have been read in
* and filed. The functions that tcplib_done calls are the ones
* that generate the data files.
*
* Called by: FinishModules() in tcptrace.c
*
*
****************************************************************************/
static void