Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r826 committed - Merge Trunk changes r817-825...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r826 committed - Merge Trunk changes r817-825...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r826 committed - Merge Trunk changes r817-825...
  • Date: Tue, 04 Jun 2013 04:19:22 +0000
  • Authentication-results: sfpop-ironport01.merit.edu; dkim=neutral (message not signed) header.i=none

Revision: 826
Author:

Date: Mon Jun 3 21:18:52 2013
Log: Merge Trunk changes r817-825
Reverts network.c fix from r816 in favour of the trunk fix.
http://code.google.com/p/ndt/source/detail?r=826

Added:
/branches/ndt-web10g/contrib/apache-ndt.conf
Modified:
/branches/ndt-web10g
/branches/ndt-web10g/Applet/Tcpbw100.java
/branches/ndt-web10g/src/logging.c
/branches/ndt-web10g/src/network.c
/branches/ndt-web10g/src/network.h
/branches/ndt-web10g/src/test_s2c_clt.c
/branches/ndt-web10g/src/viewtrace.c
/branches/ndt-web10g/src/web100-pcap.c
/branches/ndt-web10g/src/web100srv.c
/branches/ndt-web10g/src/web100srv.h

=======================================
--- /dev/null
+++ /branches/ndt-web10g/contrib/apache-ndt.conf Mon Jun 3 21:18:52
2013
@@ -0,0 +1,18 @@
+Listen 7123
+NameVirtualHost *:7123
+<VirtualHost *:7123>
+ DocumentRoot /usr/ndt
+ <Directory /usr/ndt>
+ DirectoryIndex tcpbw100.html
+ AllowOverride None
+ </Directory>
+
+ ErrorLog /var/log/ndt/httpd_error.log
+
+ # Possible values include: debug, info, notice, warn, error, crit,
+ # alert, emerg.
+ LogLevel warn
+
+ CustomLog /var/log/ndt/httpd_access.log combined
+ ServerSignature On
+</VirtualHost>
=======================================
--- /branches/ndt-web10g/Applet/Tcpbw100.java Thu Apr 11 07:56:39 2013
+++ /branches/ndt-web10g/Applet/Tcpbw100.java Mon Jun 3 21:18:52 2013
@@ -1293,7 +1293,7 @@

// Time out the socket after 6.5 seconds
midSrvrSockObj.setSoTimeout(6500);
- int bytes = 0;
+ long bytes = 0;
int inlth;
_dTime = System.currentTimeMillis();
pub_TimeStamp = new Date();
=======================================
--- /branches/ndt-web10g/src/logging.c Thu Apr 11 07:52:06 2013
+++ /branches/ndt-web10g/src/logging.c Mon Jun 3 21:18:52 2013
@@ -948,10 +948,10 @@

// get socketaddr size based on whether IPv6/IPV4 address was used
#ifdef AF_INET6
- if (meta.family == AF_INET6)
+ if (meta.c_addr.ss_family == AF_INET6)
len = sizeof(struct sockaddr_in6);
#endif
- if (meta.family == AF_INET)
+ if (meta.c_addr.ss_family == AF_INET)
len = sizeof(struct sockaddr_in);

// Look up the host name and service name information for given struct
=======================================
--- /branches/ndt-web10g/src/network.c Sat Apr 13 19:56:13 2013
+++ /branches/ndt-web10g/src/network.c Mon Jun 3 21:18:52 2013
@@ -18,6 +18,7 @@
* Create and bind socket.
* @param addr I2Addr structure, where the new socket will be stored
* @param serv the port number
+ * @param family the ip family to try binding to
* @param options the binding socket options
* @returns The socket descriptor or error code (<0).
* Error codes:
@@ -26,78 +27,21 @@
* -2 : Unable to set socket options
*/

-#ifndef AF_INET6
-#error This file assumes AF_INET6 is defined.
-#endif
-
-struct ai_node {
- struct addrinfo* ai;
- struct ai_node* next;
-};
-
-static int OpenSocket(I2Addr addr, char* serv, int options) {
+static int OpenSocket(I2Addr addr, char* serv, int family, int options) {
int fd = -1;
int return_code = 0;

- // Keep a list of all ipv4 and ipv6 addresses we come across
- // So we can search for ipv6 first
- struct ai_node ipv4_list[5] = {{NULL}};
- struct ai_node ipv6_list[5] = {{NULL}};
struct addrinfo *fai = NULL;
- struct ai_node *fain = NULL;
-
if (!(fai = I2AddrAddrInfo(addr, NULL, serv))) {
return -2;
}
-
- struct ai_node* ain_ipv6 = &ipv6_list[0];
- struct ai_node* ain_ipv4 = &ipv4_list[0];
-
- // Get lists of all IPv6 and IPv4 addresses.
- for (struct addrinfo* ai = fai; ai != NULL; ai = ai->ai_next) {
- if (ai->ai_family == AF_INET6 && ain_ipv6 <= &ipv6_list[4]){
- if(ain_ipv6->ai != NULL){
- ain_ipv6 += 1;
- ain_ipv6->next = ain_ipv6 + 1;
- }
- ain_ipv6->ai = ai;
- }
- else if (ai->ai_family == AF_INET && ain_ipv4 <= &ipv4_list[4]){
- if(ain_ipv4->ai != NULL){
- ain_ipv4 += 1;
- ain_ipv4->next = ain_ipv4 + 1;
- }
- ain_ipv4->ai = ai;
- }
- }
-
-
- // Determine which family the user would prefer, based on command line.
- int family = AF_UNSPEC;
- // options provided by user indicate V6 or V4 only
- if ((options & OPT_IPV6_ONLY) != 0)
- family = AF_INET6;
- else if ((options & OPT_IPV4_ONLY) != 0)
- family = AF_INET;
-
- // Prefer IPv6.
- if ( (family == AF_UNSPEC || family == AF_INET6)
- && ipv6_list[0].ai != NULL) {
- fain = &ipv6_list[0];
- // Link IPv4 onto the end as a fallback
- if(ipv4_list[0].ai != NULL){
- ain_ipv6->next = &ipv4_list[0];
- }
- } else {
- if(ipv4_list[0].ai != NULL)
- fain = &ipv4_list[0];
- else
- fain = NULL;
- }

// Attempt to connect to one of the chosen addresses.
struct addrinfo* ai = NULL;
- for (ai = fain->ai; fain != NULL; fain = fain->next, ai = fain->ai) {
+ for (ai = fai; ai; ai = ai->ai_next) {
+ if(ai->ai_family != family)
+ continue;
+
// create socket with obtained address domain, socket type and protocol
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);

@@ -114,28 +58,18 @@
}
// end trying to set socket option to reuse local address

- if (family == AF_INET6) {
- // If we're binding to an IPv6 address and the user hasn't specified IPv6
- // only, bind to any address to allow IPv4 clients.
- if ((options & OPT_IPV6_ONLY) == 0) {
- struct sockaddr_in6* addr_in = (struct sockaddr_in6*) ai;
- addr_in->sin6_addr = in6addr_any;
- }
-
-#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
+#ifdef AF_INET6
+#ifdef IPV6_V6ONLY
+ if (family == AF_INET6 && (options & OPT_IPV6_ONLY)) {
+ on = 1;
// the IPv6 version socket option setup
- else if (
- setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) != 0) {
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) != 0) {
return_code = -2;
goto failsock;
}
+ }
+#endif
#endif
- // If the user has not specified only V4 and we're listening as V4, allow V6
- // clients to connect.
- } else if ((options & OPT_IPV4_ONLY) == 0) {
- struct sockaddr_in* addr_in = (struct sockaddr_in*) ai;
- addr_in->sin_addr.s_addr = INADDR_ANY;
- }

// try to bind to address
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == 0) { // successful
@@ -190,9 +124,6 @@
goto failsock;
}

- // set meta test's address domain family to the one used to create socket
- if (fd != -1 && meta.family == 0)
- meta.family = ai->ai_family;
return fd;

// If opening socket failed, print error, and try to close socket
@@ -234,8 +165,15 @@
goto error;
}

- // create and bind socket using arguments
- fd = OpenSocket(addr, serv, options);
+ // create and bind socket using arguments, prefering v6 (since v6 addresses
+ // can be both v4 and v6).
+#ifdef AF_INET6
+ if ((options & OPT_IPV4_ONLY) == 0)
+ fd = OpenSocket(addr, serv, AF_INET6, options);
+#endif
+ if (fd < 0)
+ if ((options & OPT_IPV6_ONLY) == 0)
+ fd = OpenSocket(addr, serv, AF_INET, options);

if (fd < 0) {
log_println(1, "Unable to open socket.");
@@ -325,9 +263,11 @@
}

int family = AF_UNSPEC;
+#ifdef AF_INET6
// options provided by user indicate V6 or V4 only
if ((options & OPT_IPV6_ONLY) != 0)
family = AF_INET6;
+#endif
else if ((options & OPT_IPV4_ONLY) != 0)
family = AF_INET;

@@ -341,8 +281,7 @@
*sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (*sockfd < 0) {
// socket create failed. Abandon further activities using this socket
- log_println(1, "Failed to create %d %d %d",
- ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+ log_println(1, "Failed to create %d %d %d", ai->ai_family, ai->ai_socktype, ai->ai_protocol);
continue;
}

@@ -417,7 +356,7 @@
return 1;
} else {
log_println(0, "Failed to connect: %s", strerror(errno));
- // goto error;
+ //goto error;
}
}

@@ -441,7 +380,7 @@
*
*/

-int send_msg(int ctlSocket, int type, const void* msg, int len) {
+int send_msg(int ctlSocket, int type, void* msg, int len) {
unsigned char buff[3];
int rc, i;

@@ -550,9 +489,9 @@
* @return The amount of bytes written to the file descriptor
*/

-int writen(int fd, const void* buf, int amount) {
+int writen(int fd, void* buf, int amount) {
int sent, n;
- const char* ptr = buf;
+ char* ptr = buf;
sent = 0;
assert(amount >= 0);
while (sent < amount) {
=======================================
--- /branches/ndt-web10g/src/network.h Thu Apr 11 07:52:06 2013
+++ /branches/ndt-web10g/src/network.h Mon Jun 3 21:18:52 2013
@@ -20,9 +20,9 @@
I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size);
int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr,
int option, int buf_sizes);
-int send_msg(int ctlSocket, int type, const void* msg, int len);
+int send_msg(int ctlSocket, int type, void* msg, int len);
int recv_msg(int ctlSocket, int* type, void* msg, int* len);
-int writen(int fd, const void* buf, int amount);
+int writen(int fd, void* buf, int amount);
int readn(int fd, void* buf, int amount);

/* web100-util.c routine used in network. */
=======================================
--- /branches/ndt-web10g/src/test_s2c_clt.c Thu Nov 15 13:34:19 2012
+++ /branches/ndt-web10g/src/test_s2c_clt.c Mon Jun 3 21:18:52 2013
@@ -48,7 +48,7 @@
int inlth, retcode, one = 1, set_size;
int inSocket;
socklen_t optlen;
- uint32_t bytes;
+ uint64_t bytes;
double t;
struct timeval sel_tv;
fd_set rfd;
=======================================
--- /branches/ndt-web10g/src/viewtrace.c Thu Nov 15 13:34:19 2012
+++ /branches/ndt-web10g/src/viewtrace.c Mon Jun 3 21:18:52 2013
@@ -96,13 +96,8 @@
void init_vars(struct spdpair *cur) {
int i;

-#if defined(AF_INET6)
memset(cur->saddr, 0, 4);
memset(cur->daddr, 0, 4);
-#else
- cur->saddr = 0;
- cur->daddr = 0;
-#endif
cur->sport = 0;
cur->dport = 0;
cur->seq = 0;
@@ -159,11 +154,11 @@
fprintf(
stderr,
"%u.%u.%u.%u:%d --> ",
- (cur->saddr & 0xFF), ((cur->saddr >> 8) & 0xff),
- ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);
- fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF),
- ((cur->daddr >> 8) & 0xff), ((cur->daddr >> 16) & 0xff),
- (cur->daddr >> 24), cur->dport);
+ (cur->saddr[0] & 0xFF), ((cur->saddr[0] >> 8) & 0xff),
+ ((cur->saddr[0] >> 16) & 0xff), (cur->saddr[0] >> 24), cur->sport);
+ fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->daddr[0] & 0xFF),
+ ((cur->daddr[0] >> 8) & 0xff), ((cur->daddr[0] >> 16) & 0xff),
+ (cur->daddr[0] >> 24), cur->dport);
#endif
} else {
#if defined(AF_INET6)
@@ -175,12 +170,12 @@
inet_ntop(AF_INET6, (void *) cur->saddr, str, sizeof(str));
fprintf(stderr, "%s.%d ", str, cur->sport);
#else
- fprintf(stderr, "%u.%u.%u.%u:%d --> ", (cur->daddr & 0xFF),
- ((cur->daddr >> 8) & 0xff), ((cur->daddr >> 16) & 0xff),
- (cur->daddr >> 24), cur->dport);
- fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->saddr & 0xFF),
- ((cur->saddr >> 8) & 0xff), ((cur->saddr >> 16) & 0xff),
- (cur->saddr >> 24), cur->sport);
+ fprintf(stderr, "%u.%u.%u.%u:%d --> ", (cur->daddr[0] & 0xFF),
+ ((cur->daddr[0] >> 8) & 0xff), ((cur->daddr[0] >> 16) & 0xff),
+ (cur->daddr[0] >> 24), cur->dport);
+ fprintf(stderr, "%u.%u.%u.%u:%d ", (cur->saddr[0] & 0xFF),
+ ((cur->saddr[0] >> 8) & 0xff), ((cur->saddr[0] >> 16) & 0xff),
+ (cur->saddr[0] >> 24), cur->sport);
#endif
}
if (max == 0)
@@ -333,18 +328,11 @@
p += sizeof(struct ether_header); // move packet pointer past ethernet fields

ip = (const struct ip *)p;
-#if defined(AF_INET6)
if (ip->ip_v == 4) {
-#endif
p += (ip->ip_hl) * 4;
tcp = (const struct tcphdr *)p;
-#if defined(AF_INET6)
current.saddr[0] = ip->ip_src.s_addr;
current.daddr[0] = ip->ip_dst.s_addr;
-#else
- current.saddr = ip->ip_src.s_addr;
- current.daddr = ip->ip_dst.s_addr;
-#endif
current.sport = ntohs(tcp->source);
current.dport = ntohs(tcp->dest);
current.seq = ntohl(tcp->seq);
@@ -357,60 +345,39 @@
vt_print_bins(&rev);
return;
}
-#if defined(AF_INET6)
if (fwd.saddr[0] == 0) {
fprintf(stderr, "Started data collection for sockets %d:%d\n",
current.dport, current.sport);
fwd.saddr[0] = current.saddr[0];
fwd.daddr[0] = current.daddr[0];
-#else
- if (fwd.saddr == 0) {
- fprintf(stderr, "Started data collection for sockets %d:%d\n",
- current.dport, current.sport);
- fwd.saddr = current.saddr;
- fwd.daddr = current.daddr;
-#endif
- fwd.sport = current.sport;
- fwd.dport = current.dport;
- fwd.st_sec = current.sec;
- fwd.st_usec = current.usec;
-#if defined(AF_INET6)
- rev.saddr[0] = current.daddr[0];
- rev.daddr[0] = current.saddr[0];
-#else
- rev.saddr = current.daddr;
- rev.daddr = current.saddr;
-#endif
- rev.sport = current.dport;
- rev.dport = current.sport;
- rev.st_sec = current.sec;
- rev.st_usec = current.usec;
- log_println(1, "Completed data collection for port %d", current.dport);
- return;
- }
+ fwd.sport = current.sport;
+ fwd.dport = current.dport;
+ fwd.st_sec = current.sec;
+ fwd.st_usec = current.usec;
+ rev.saddr[0] = current.daddr[0];
+ rev.daddr[0] = current.saddr[0];
+ rev.sport = current.dport;
+ rev.dport = current.sport;
+ rev.st_sec = current.sec;
+ rev.st_usec = current.usec;
+ log_println(1, "Completed data collection for port %d", current.dport);
+ return;
+ }

+ if (fwd.saddr[0] == current.saddr[0]) {
+ if (current.dport == c2sport)
+ vt_calculate_spd(&current, &fwd);
+ else if (current.sport == s2cport)
+ vt_calculate_spd(&current, &fwd);
+ }
+ if (rev.saddr[0] == current.saddr[0]) {
+ if (current.sport == c2sport)
+ vt_calculate_spd(&current, &rev);
+ else if (current.dport == s2cport)
+ vt_calculate_spd(&current, &rev);
+ }
+ } else {
#if defined(AF_INET6)
- if (fwd.saddr[0] == current.saddr[0]) {
-#else
- if (fwd.saddr == current.saddr) {
-#endif
- if (current.dport == c2sport)
- vt_calculate_spd(&current, &fwd);
- else if (current.sport == s2cport)
- vt_calculate_spd(&current, &fwd);
- }
-#if defined(AF_INET6)
- if (rev.saddr[0] == current.saddr[0]) {
-#else
- if (rev.saddr == current.saddr) {
-#endif
- if (current.sport == c2sport)
- vt_calculate_spd(&current, &rev);
- else if (current.dport == s2cport)
- vt_calculate_spd(&current, &rev);
- }
-#if defined(AF_INET6)
- } else {
ip6 = (const struct ip6_hdr *)p;

p += 40;
@@ -477,144 +444,144 @@
else if (current.dport == s2cport)
vt_calculate_spd(&current, &rev);
}
- }
#endif
- }
+ }
+}
#endif

- int main(int argc, char **argv) {
- char *read_file, *cmdbuf, *device;
+int main(int argc, char **argv) {
+ char *read_file, *cmdbuf, *device;
#ifdef HAVE_LIBPCAP
- pcap_handler printer;
- u_char * pcap_userdata = NULL;
- struct bpf_program fcode;
- char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_handler printer;
+ u_char * pcap_userdata = NULL;
+ struct bpf_program fcode;
+ char errbuf[PCAP_ERRBUF_SIZE];
#endif
- int cnt, pflag = 0, debug = 0, c;
- struct sigaction new;
+ int cnt, pflag = 0, debug = 0, c;
+ struct sigaction new;

- read_file = NULL;
- device = NULL;
- cnt = -1; /* read forever, or until end of file */
- while ((c = getopt_long(argc, argv, "c:df:hi:l:v",
- long_options, 0)) != -1) {
- switch (c) {
- case 'c':
- cnt = atoi(optarg);
- break;
- case 'd':
- debug++;
- break;
- case 'f':
- read_file = optarg;
- break;
- case 'i':
- device = optarg;
- break;
- case 'h':
+ read_file = NULL;
+ device = NULL;
+ cnt = -1; /* read forever, or until end of file */
+ while ((c = getopt_long(argc, argv, "c:df:hi:l:v",
+ long_options, 0)) != -1) {
+ switch (c) {
+ case 'c':
+ cnt = atoi(optarg);
+ break;
+ case 'd':
+ debug++;
+ break;
+ case 'f':
+ read_file = optarg;
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ case 'h':
#ifdef HAVE_LIBPCAP
- vt_long_usage("ANL/Internet2 NDT version " VERSION
- " (viewtrace)");
+ vt_long_usage("ANL/Internet2 NDT version " VERSION
+ " (viewtrace)");
#else
- vt_long_usage("ANL/Internet2 NDT version " VERSION
- " (viewtrace) [missing pcap library]");
+ vt_long_usage("ANL/Internet2 NDT version " VERSION
+ " (viewtrace) [missing pcap library]");
#endif
- break;
- case 'v':
+ break;
+ case 'v':
#ifdef HAVE_LIBPCAP
- printf("ANL/Internet2 NDT version " VERSION " (viewtrace)\n");
+ printf("ANL/Internet2 NDT version " VERSION " (viewtrace)\n");
#else
- printf("ANL/Internet2 NDT version " VERSION " (viewtrace) "
- "[missing pcap library]\n");
+ printf("ANL/Internet2 NDT version " VERSION " (viewtrace) "
+ "[missing pcap library]\n");
#endif
- exit(0);
- break;
- case 303:
- if (check_int(optarg, &c2sport)) {
- char tmpText[200];
- snprintf(tmpText, sizeof(tmpText),
- "Invalid C2S throughput test port number: %s", optarg);
- short_usage(argv[0], tmpText);
- }
- break;
- case 304:
- if (check_int(optarg, &s2cport)) {
- char tmpText[200];
- snprintf(tmpText, sizeof(tmpText),
- "Invalid S2C throughput test port number: %s", optarg);
- short_usage(argv[0], tmpText);
- }
- break;
- case '?':
- short_usage(argv[0], "");
- break;
- }
+ exit(0);
+ break;
+ case 303:
+ if (check_int(optarg, &c2sport)) {
+ char tmpText[200];
+ snprintf(tmpText, sizeof(tmpText),
+ "Invalid C2S throughput test port number: %s", optarg);
+ short_usage(argv[0], tmpText);
}
-
- if (optind < argc) {
- short_usage(argv[0], "Unrecognized non-option elements");
+ break;
+ case 304:
+ if (check_int(optarg, &s2cport)) {
+ char tmpText[200];
+ snprintf(tmpText, sizeof(tmpText),
+ "Invalid S2C throughput test port number: %s", optarg);
+ short_usage(argv[0], tmpText);
}
+ break;
+ case '?':
+ short_usage(argv[0], "");
+ break;
+ }
+ }

- log_init(argv[0], debug);
+ if (optind < argc) {
+ short_usage(argv[0], "Unrecognized non-option elements");
+ }
+
+ log_init(argv[0], debug);

#ifdef HAVE_LIBPCAP
- init_vars(&fwd);
- init_vars(&rev);
+ init_vars(&fwd);
+ init_vars(&rev);

- if (read_file == NULL) {
- if (device == NULL) {
- device = pcap_lookupdev(errbuf);
- if (device == NULL) {
- fprintf(stderr, "pcap_lookupdev failed: %s\n", errbuf);
- exit(-1);
- }
- }
- if ((pd = pcap_open_live(device, 68, !pflag, 1000, errbuf)) == NULL) {
- fprintf(stderr, "pcap_open_live failed: %s\n", errbuf);
- exit(-9);
- }
- memset(&new, 0, sizeof(new));
- new.sa_handler = cleanup;
- sigaction(SIGTERM, &new, NULL);
- sigaction(SIGINT, &new, NULL);
- sigaction(SIGALRM, &new, NULL);
- } else {
- if ((pd = pcap_open_offline(read_file, errbuf)) == NULL) {
- fprintf(stderr, "pcap_open_offline failed: %s\n", errbuf);
- exit(-2);
- }
- }
+ if (read_file == NULL) {
+ if (device == NULL) {
+ device = pcap_lookupdev(errbuf);
+ if (device == NULL) {
+ fprintf(stderr, "pcap_lookupdev failed: %s\n", errbuf);
+ exit(-1);
+ }
+ }
+ if ((pd = pcap_open_live(device, 68, !pflag, 1000, errbuf)) == NULL) {
+ fprintf(stderr, "pcap_open_live failed: %s\n", errbuf);
+ exit(-9);
+ }
+ memset(&new, 0, sizeof(new));
+ new.sa_handler = cleanup;
+ sigaction(SIGTERM, &new, NULL);
+ sigaction(SIGINT, &new, NULL);
+ sigaction(SIGALRM, &new, NULL);
+ } else {
+ if ((pd = pcap_open_offline(read_file, errbuf)) == NULL) {
+ fprintf(stderr, "pcap_open_offline failed: %s\n", errbuf);
+ exit(-2);
+ }
+ }

- cmdbuf = copy_argv(&argv[optind]);
+ cmdbuf = copy_argv(&argv[optind]);

- if (pcap_compile(pd, &fcode, cmdbuf, 0, 0xFFFFFF00) < 0) {
- fprintf(stderr, "pcap_compile failed %s\n", pcap_geterr(pd));
- exit(-2);
- }
+ if (pcap_compile(pd, &fcode, cmdbuf, 0, 0xFFFFFF00) < 0) {
+ fprintf(stderr, "pcap_compile failed %s\n", pcap_geterr(pd));
+ exit(-2);
+ }

- if (pcap_setfilter(pd, &fcode) < 0) {
- fprintf(stderr, "pcap_setfiler failed %s\n", pcap_geterr(pd));
- exit(-2);
- }
+ if (pcap_setfilter(pd, &fcode) < 0) {
+ fprintf(stderr, "pcap_setfiler failed %s\n", pcap_geterr(pd));
+ exit(-2);
+ }

- printer = (pcap_handler) print_speed;
- if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) {
- fprintf(stderr, "pcap_loop failed %s\n", pcap_geterr(pd));
- exit(-2);
- }
- if (fwd.sport == s2cport) {
- vt_print_bins(&rev);
- vt_print_bins(&fwd);
- } else {
- vt_print_bins(&fwd);
- vt_print_bins(&rev);
- }
- pcap_close(pd);
+ printer = (pcap_handler) print_speed;
+ if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) {
+ fprintf(stderr, "pcap_loop failed %s\n", pcap_geterr(pd));
+ exit(-2);
+ }
+ if (fwd.sport == s2cport) {
+ vt_print_bins(&rev);
+ vt_print_bins(&fwd);
+ } else {
+ vt_print_bins(&fwd);
+ vt_print_bins(&rev);
+ }
+ pcap_close(pd);
#else
- log_println(
- 0,
- "\n!!! In order to use viewtrace utility you have to compile it "
- "with the pcap library !!!\n");
+ log_println(
+ 0,
+ "\n!!! In order to use viewtrace utility you have to compile it "
+ "with the pcap library !!!\n");
#endif
- return 0;
- }
+ return 0;
+}
=======================================
--- /branches/ndt-web10g/src/web100-pcap.c Thu Apr 11 07:52:06 2013
+++ /branches/ndt-web10g/src/web100-pcap.c Mon Jun 3 21:18:52 2013
@@ -22,13 +22,20 @@
#include "strlutils.h"
#include "utils.h"

-int dumptrace;
-pcap_t *pd;
-pcap_dumper_t *pdump;
-int mon_pipe1[2], mon_pipe2[2];
+static struct iflists {
+ char name[8][32];
+ u_int16_t speed[32];
+} iflist;
+
+static int dumptrace;
+static pcap_t *pd;
+static pcap_dumper_t *pdump;
+static int mon_pipe1[2], mon_pipe2[2];
/* int sig1, sig2; */
-int sigj = 0, sigk = 0;
-int ifspeed;
+static int sigj = 0, sigk = 0;
+static int ifspeed;
+
+static struct spdpair fwd, rev;

/** Scan through interface device list and get names/speeds of each interface.
*
@@ -37,7 +44,7 @@
* the bottleneck link detection algorithm RAC 7/14/09
*
*/
-void get_iflist(void) {
+void init_iflist(void) {
/* pcap_addr_t *ifaceAddr; */
pcap_if_t *alldevs, *dp;
struct ethtool_cmd ecmd;
@@ -88,6 +95,10 @@
// free list allocated by pcap_findalldevs call
if (alldevs != NULL)
pcap_freealldevs(alldevs);
+
+ for (i = 0; iflist.speed[i] > 0; i++)
+ log_println(4, "Generated iflist with device=%s and if_speed=%d",
+ iflist.name[i], iflist.speed[i]);
}

/**
@@ -97,7 +108,7 @@
*
* This calls pcap_breakloop with the correct capture.
*/
-void force_breakloop() {
+void force_breakloop(){
if (pd != NULL) {
pcap_breakloop(pd);
}
@@ -121,15 +132,9 @@
"Sending pkt-pair data back to parent on pipe %d, %d",
mon_pipe1[0], mon_pipe1[1]);
if (get_debuglvl() > 3) {
-#ifdef AF_INET6
if (fwd.family == 4) {
fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
-#else
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr, fwd.sport, rev.saddr, rev.sport);
-#endif
-#ifdef AF_INET6
} else if (fwd.family == 6) {
char str[136];
memset(str, 0, 136);
@@ -142,7 +147,6 @@
fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n",
fwd.family);
}
-#endif
}
print_bins(&fwd, mon_pipe1);
usleep(30000); /* wait here 30 msec, for parent to read this data */
@@ -158,15 +162,9 @@
"Sending pkt-pair data back to parent on pipe %d, %d",
mon_pipe2[0], mon_pipe2[1]);
if (get_debuglvl() > 3) {
-#ifdef AF_INET6
if (fwd.family == 4) {
fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
fwd.saddr[0], fwd.sport, rev.saddr[0], rev.sport);
-#else
- fprintf(stderr, "fwd.saddr = %x:%d, rev.saddr = %x:%d\n",
- fwd.saddr, fwd.sport, rev.saddr, rev.sport);
-#endif
-#ifdef AF_INET6
} else if (fwd.family == 6) {
char str[136];
memset(str, 0, 136);
@@ -179,7 +177,6 @@
fprintf(stderr, "check_signal_flags: Unknown IP family (%d)\n",
fwd.family);
}
-#endif
}
print_bins(&fwd, mon_pipe2);
usleep(30000); /* wait here 30 msec, for parent to read this data */
@@ -205,13 +202,8 @@

assert(cur);

-#if defined(AF_INET6)
memset(cur->saddr, 0, 4);
memset(cur->daddr, 0, 4);
-#else
- cur->saddr = 0;
- cur->daddr = 0;
-#endif
cur->sport = 0;
cur->dport = 0;
cur->seq = 0;
@@ -257,7 +249,6 @@
}
}
if (get_debuglvl() > 2) {
-#ifdef AF_INET6
if (cur->family == 4) {
if (fp) {
fprintf(fp, "%u.%u.%u.%u:%d --> ", (cur->saddr[0] & 0xFF),
@@ -274,25 +265,6 @@
((cur->daddr[0] >> 8) & 0xff), ((cur->daddr[0] >> 16) & 0xff),
(cur->daddr[0] >> 24), cur->dport);
}
-#else
- if (fp) {
- fprintf(
- fp,
- "%u.%u.%u.%u:%d --> ",
- (cur->saddr & 0xFF), ((cur->saddr >> 8) & 0xff),
- ((cur->saddr >> 16) & 0xff), (cur->saddr >> 24), cur->sport);
- fprintf(fp, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF),
- ((cur->daddr >> 8) & 0xff), ((cur->daddr >> 16) & 0xff),
- (cur->daddr >> 24), cur->dport);
- }
- log_print(3, "%u.%u.%u.%u:%d --> ", (cur->saddr & 0xFF),
- ((cur->saddr >> 8) & 0xff), ((cur->saddr >> 16) & 0xff),
- (cur->saddr >> 24), cur->sport);
- log_print(3, "%u.%u.%u.%u:%d ", (cur->daddr & 0xFF),
- ((cur->daddr >> 8) & 0xff), ((cur->daddr >> 16) & 0xff),
- (cur->daddr >> 24), cur->dport);
-#endif
-#ifdef AF_INET6
else {
char name[200];
socklen_t len;
@@ -311,7 +283,6 @@
}
log_print(3, "%s:%d ", name, cur->dport);
}
-#endif
}
// If max speed is 0, then indicate that no data has been collected
if (max == 0) {
@@ -574,22 +545,14 @@
p += sizeof(struct ether_header); // move packet pointer past ethernet fields

ip = (const struct ip *) p;
-#if defined(AF_INET6)
if (ip->ip_v == 4) {
-#endif
-
/* This section grabs the IP & TCP header values from an IPv4 packet and loads the various
* variables with the packet's values.
*/
p += (ip->ip_hl) * 4;
tcp = (const struct tcphdr *) p;
-#if defined(AF_INET6)
current.saddr[0] = ip->ip_src.s_addr;
current.daddr[0] = ip->ip_dst.s_addr;
-#else
- current.saddr = ip->ip_src.s_addr;
- current.daddr = ip->ip_dst.s_addr;
-#endif

current.sport = ntohs(tcp->source);
current.dport = ntohs(tcp->dest);
@@ -630,465 +593,457 @@
* capacity based on the times between this packet and the previous one.
*/

-#if defined(AF_INET6)
if (fwd.saddr[0] == current.saddr[0]) {
-#else
- if (fwd.saddr == current.saddr) {
-#endif
- if (current.dport == port2) {
- calculate_spd(&current, &fwd, port2, port4);
- return;
- }
- if (current.sport == port4) {
- calculate_spd(&current, &fwd, port2, port4);
- return;
- }
+ if (current.dport == port2) {
+ calculate_spd(&current, &fwd, port2, port4);
+ return;
}
+ if (current.sport == port4) {
+ calculate_spd(&current, &fwd, port2, port4);
+ return;
+ }
+ }
+ if (rev.saddr[0] == current.saddr[0]) {
+ if (current.sport == port2) {
+ calculate_spd(&current, &rev, port2, port4);
+ return;
+ }
+ if (current.dport == port4) {
+ calculate_spd(&current, &rev, port2, port4);
+ return;
+ }
+ }
+ } else { /* IP header value is not = 4, so must be IPv6 */
#if defined(AF_INET6)
- if (rev.saddr[0] == current.saddr[0]) {
-#else
- if (rev.saddr == current.saddr) {
-#endif
- if (current.sport == port2) {
- calculate_spd(&current, &rev, port2, port4);
- return;
- }
- if (current.dport == port4) {
- calculate_spd(&current, &rev, port2, port4);
- return;
- }
- }
-#if defined(AF_INET6)
- } else { /* IP header value is not = 4, so must be IPv6 */
- // This is an IPv6 packet, grab the IP & TCP header values for further
- // use.
+ // This is an IPv6 packet, grab the IP & TCP header values for further
+ // use.

- ip6 = (const struct ip6_hdr *)p;
+ ip6 = (const struct ip6_hdr *)p;

- p += 40;
- tcp = (const struct tcphdr *)p;
- memcpy(current.saddr, (void *) &ip6->ip6_src, 16);
- memcpy(current.daddr, (void *) &ip6->ip6_dst, 16);
+ p += 40;
+ tcp = (const struct tcphdr *)p;
+ memcpy(current.saddr, (void *) &ip6->ip6_src, 16);
+ memcpy(current.daddr, (void *) &ip6->ip6_dst, 16);

- current.sport = ntohs(tcp->source);
- current.dport = ntohs(tcp->dest);
- current.seq = ntohl(tcp->seq);
- current.ack = ntohl(tcp->ack_seq);
- current.win = ntohs(tcp->window);
+ current.sport = ntohs(tcp->source);
+ current.dport = ntohs(tcp->dest);
+ current.seq = ntohl(tcp->seq);
+ current.ack = ntohl(tcp->ack_seq);
+ current.win = ntohs(tcp->window);

- // The 1st packet has been received, finish the initialization process
- // and return.
+ // The 1st packet has been received, finish the initialization process
+ // and return.

- // if ((fwd.saddr[0] == 0) && (fwd.saddr[1] == 0) &&
- // (fwd.saddr[2] == 0) && (fwd.saddr[3] == 0)) {
- if (fwd.seq == 0) {
- log_println(1, "New IPv6 packet trace started -- "
- "initializing counters");
- fwd.seq = current.seq;
- fwd.st_sec = current.sec;
- fwd.st_usec = current.usec;
- rev.st_sec = current.sec;
- rev.st_usec = current.usec;
- fwd.dec_cnt = 0;
- fwd.inc_cnt = 0;
- fwd.same_cnt = 0;
- fwd.timeout = 0;
- fwd.dupack = 0;
- rev.dec_cnt = 0;
- rev.inc_cnt = 0;
- rev.same_cnt = 0;
- rev.timeout = 0;
- rev.dupack = 0;
- fwd.family = 6;
- rev.family = 6;
- return;
- }
+ if (fwd.seq == 0) {
+ log_println(1, "New IPv6 packet trace started -- "
+ "initializing counters");
+ fwd.seq = current.seq;
+ fwd.st_sec = current.sec;
+ fwd.st_usec = current.usec;
+ rev.st_sec = current.sec;
+ rev.st_usec = current.usec;
+ fwd.dec_cnt = 0;
+ fwd.inc_cnt = 0;
+ fwd.same_cnt = 0;
+ fwd.timeout = 0;
+ fwd.dupack = 0;
+ rev.dec_cnt = 0;
+ rev.inc_cnt = 0;
+ rev.same_cnt = 0;
+ rev.timeout = 0;
+ rev.dupack = 0;
+ fwd.family = 6;
+ rev.family = 6;
+ return;
+ }

- /* A new packet has been recieved, and it's not the 1st. Use it to calculate the
- * bottleneck link capacity for this flow.
- */
+ /* A new packet has been recieved, and it's not the 1st. Use it to calculate the
+ * bottleneck link capacity for this flow.
+ */

- if ((fwd.saddr[0] == current.saddr[0]) &&
- (fwd.saddr[1] == current.saddr[1]) &&
- (fwd.saddr[2] == current.saddr[2]) &&
- (fwd.saddr[3] == current.saddr[3])) {
- if (current.dport == port2) {
- calculate_spd(&current, &fwd, port2, port4);
- return;
- }
- if (current.sport == port4) {
- calculate_spd(&current, &fwd, port2, port4);
- return;
- }
- }
- if ((rev.saddr[0] == current.saddr[0]) &&
- (rev.saddr[1] == current.saddr[1]) &&
- (rev.saddr[2] == current.saddr[2]) &&
- (rev.saddr[3] == current.saddr[3])) {
- if (current.sport == port2) {
- calculate_spd(&current, &rev, port2, port4);
- return;
- }
- if (current.dport == port4) {
- calculate_spd(&current, &rev, port2, port4);
- return;
- }
- }
+ if ((fwd.saddr[0] == current.saddr[0]) &&
+ (fwd.saddr[1] == current.saddr[1]) &&
+ (fwd.saddr[2] == current.saddr[2]) &&
+ (fwd.saddr[3] == current.saddr[3])) {
+ if (current.dport == port2) {
+ calculate_spd(&current, &fwd, port2, port4);
+ return;
}
-#endif
-
- /* a packet has been received, so it matched the filter, but the src/dst ports are backward for some reason.
- * Need to fix this by reversing the values.
- */
-
- if (sigk == 0) {
- sigk++;
- log_println(6,
- "Fault: unknown packet received with src/dst port = %d/%d",
- current.sport, current.dport);
+ if (current.sport == port4) {
+ calculate_spd(&current, &fwd, port2, port4);
+ return;
}
- if (sigj == 0) {
- log_println(6, "Ports need to be reversed now port1/port2 = %d/%d",
- pair->port1, pair->port2);
- int tport = pair->port1;
- pair->port1 = pair->port2;
- pair->port2 = tport;
- fwd.st_sec = current.sec;
- fwd.st_usec = current.usec;
- rev.st_sec = current.sec;
- rev.st_usec = current.usec;
- fwd.dec_cnt = 0;
- fwd.inc_cnt = 0;
- fwd.same_cnt = 0;
- fwd.timeout = 0;
- fwd.dupack = 0;
- rev.dec_cnt = 0;
- rev.inc_cnt = 0;
- rev.same_cnt = 0;
- rev.timeout = 0;
- rev.dupack = 0;
- log_println(6,
- "Ports should have been reversed now port1/port2 = %d/%d",
- pair->port1, pair->port2);
- sigj = 1;
+ }
+ if ((rev.saddr[0] == current.saddr[0]) &&
+ (rev.saddr[1] == current.saddr[1]) &&
+ (rev.saddr[2] == current.saddr[2]) &&
+ (rev.saddr[3] == current.saddr[3])) {
+ if (current.sport == port2) {
+ calculate_spd(&current, &rev, port2, port4);
+ return;
}
+ if (current.dport == port4) {
+ calculate_spd(&current, &rev, port2, port4);
+ return;
}
+ }
+#endif
+ }

- /**
- * Perform opening and initialization functions needed
- * by the libpcap routines. The print_speed function above, is passed
- * to the pcap_open_live() function as the pcap_handler.
- * @param srcAddr Source address
- * @param sock_addr socket address used to determine client address
- * @param saddrlen socket address length
- * @param monitor_pipe socket file descriptors used to read/write data (for interprocess communication)
- * @param device devive detail string
- * @param pair PortPair strcuture
- * @param direction string indicating C2S/S2c test
- * @param compress Option indicating whether log files (here, ndttrace) needs to be compressed. Unused here.
- */
+ /* a packet has been received, so it matched the filter, but the src/dst ports are backward for some reason.
+ * Need to fix this by reversing the values.
+ */

- void init_pkttrace(I2Addr srcAddr, struct sockaddr *sock_addr,
- socklen_t saddrlen, int monitor_pipe[2], char *device,
- PortPair* pair, const char *direction, int compress) {
- char cmdbuf[256], dir[256];
- pcap_handler printer;
- u_char * pcap_userdata = (u_char*) pair;
- struct bpf_program fcode;
- char errbuf[PCAP_ERRBUF_SIZE];
- int cnt, pflag = 0, i;
- char c;
- char namebuf[200], isoTime[64];
- size_t nameBufLen = 199;
- I2Addr sockAddr = NULL;
- struct sockaddr *src_addr;
- pcap_if_t *alldevs, *dp;
- pcap_addr_t *curAddr;
- int rc;
+ if (sigk == 0) {
+ sigk++;
+ log_println(6,
+ "Fault: unknown packet received with src/dst port = %d/%d",
+ current.sport, current.dport);
+ }
+ if (sigj == 0) {
+ log_println(6, "Ports need to be reversed now port1/port2 = %d/%d",
+ pair->port1, pair->port2);
+ int tport = pair->port1;
+ pair->port1 = pair->port2;
+ pair->port2 = tport;
+ fwd.st_sec = current.sec;
+ fwd.st_usec = current.usec;
+ rev.st_sec = current.sec;
+ rev.st_usec = current.usec;
+ fwd.dec_cnt = 0;
+ fwd.inc_cnt = 0;
+ fwd.same_cnt = 0;
+ fwd.timeout = 0;
+ fwd.dupack = 0;
+ rev.dec_cnt = 0;
+ rev.inc_cnt = 0;
+ rev.same_cnt = 0;
+ rev.timeout = 0;
+ rev.dupack = 0;
+ log_println(6,
+ "Ports should have been reversed now port1/port2 = %d/%d",
+ pair->port1, pair->port2);
+ sigj = 1;
+ }
+}

- char logdir[256];
+/**
+ * Perform opening and initialization functions needed
+ * by the libpcap routines. The print_speed function above, is passed
+ * to the pcap_open_live() function as the pcap_handler.
+ * @param srcAddr Source address
+ * @param sock_addr socket address used to determine client address
+ * @param saddrlen socket address length
+ * @param monitor_pipe socket file descriptors used to read/write data (for interprocess communication)
+ * @param device devive detail string
+ * @param pair PortPair strcuture
+ * @param direction string indicating C2S/S2c test
+ * @param compress Option indicating whether log files (here, ndttrace) needs to be compressed. Unused here.
+ */

- cnt = -1; /* read forever, or until end of file */
- sig1 = 0;
- sig2 = 0;
+void init_pkttrace(I2Addr srcAddr, struct sockaddr *sock_addr,
+ socklen_t saddrlen, int monitor_pipe[2], char *device,
+ PortPair* pair, char *direction, int compress) {
+ char cmdbuf[256], dir[256];
+ pcap_handler printer;
+ u_char * pcap_userdata = (u_char*) pair;
+ struct bpf_program fcode;
+ char errbuf[PCAP_ERRBUF_SIZE];
+ int cnt, pflag = 0, i;
+ char c;
+ char namebuf[200], isoTime[64];
+ size_t nameBufLen = 199;
+ I2Addr sockAddr = NULL;
+ struct sockaddr *src_addr;
+ pcap_if_t *alldevs, *dp;
+ pcap_addr_t *curAddr;
+ int rc;

- init_vars(&fwd);
- init_vars(&rev);
+ char logdir[256];

- sockAddr = I2AddrBySAddr(get_errhandle(), sock_addr, saddrlen, 0, 0);
- sock_addr = I2AddrSAddr(sockAddr, 0);
- src_addr = I2AddrSAddr(srcAddr, 0);
+ cnt = -1; /* read forever, or until end of file */
+ sig1 = 0;
+ sig2 = 0;

- /* special check for localhost, set device accordingly */
- if (I2SockAddrIsLoopback(sock_addr, saddrlen) > 0)
- // hardcoding device address to 100, as initialised in main()
- strlcpy(device, "lo", 100);
- if (device == NULL) {
- if (pcap_findalldevs(&alldevs, errbuf) == 0) {
- for (dp = alldevs; dp != NULL; dp = dp->next) {
- for (curAddr = dp->addresses; curAddr != NULL;
- curAddr = curAddr->next) {
- switch (curAddr->addr->sa_family) {
- case AF_INET:
- memset(namebuf, 0, 200);
- inet_ntop(
- AF_INET,
- &((struct sockaddr_in *) curAddr->addr)->sin_addr,
- namebuf, INET_ADDRSTRLEN);
- log_println(3, "IPv4 interface found address=%s",
- namebuf);
- if (((struct sockaddr_in *) curAddr->addr)->sin_addr.s_addr
- == ((struct sockaddr_in *) src_addr)->sin_addr.s_addr) {
- log_println(
- 4,
- "IPv4 address match, setting device to '%s'",
- dp->name);
- device = dp->name;
- ifspeed = -1;
- for (i = 0; iflist.name[0][i] != '0'; i++) {
- if (strncmp((char *) iflist.name[i], device, 4)
- == 0) {
- ifspeed = iflist.speed[i];
- break;
- }
- }
+ init_vars(&fwd);
+ init_vars(&rev);

- if (direction[0] == 's') {
-#if defined(AF_INET6)
- fwd.saddr[0] =
- ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
- fwd.daddr[0] =
- ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
- rev.saddr[0] =
- ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
- rev.daddr[0] =
- ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
-#else
- fwd.saddr =
- ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
- fwd.daddr =
- ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
- rev.saddr =
- ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
- rev.daddr =
- ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
-#endif
- fwd.sport =
- ntohs(
- ((struct sockaddr_in *) src_addr)->sin_port);
- fwd.dport =
- ntohs(
- ((struct sockaddr_in *) sock_addr)->sin_port);
- rev.sport =
- ntohs(
- ((struct sockaddr_in *) sock_addr)->sin_port);
- rev.dport =
- ntohs(
- ((struct sockaddr_in *) src_addr)->sin_port);
- } else {
-#if defined(AF_INET6)
- rev.saddr[0] =
- ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
- rev.daddr[0] =
- ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
- fwd.saddr[0] =
- ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
- fwd.daddr[0] =
- ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
-#else
- rev.saddr =
- ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
- rev.daddr =
- ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
- fwd.saddr =
- ((struct sockaddr_in *) sock_addr)->sin_addr.s_addr;
- fwd.daddr =
- ((struct sockaddr_in *) src_addr)->sin_addr.s_addr;
-#endif
- rev.sport =
- ntohs(
- ((struct sockaddr_in *) src_addr)->sin_port);
- rev.dport =
- ntohs(
- ((struct sockaddr_in *) sock_addr)->sin_port);
- fwd.sport =
- ntohs(
- ((struct sockaddr_in *) sock_addr)->sin_port);
- fwd.dport =
- ntohs(
- ((struct sockaddr_in *) src_addr)->sin_port);
- }
- goto endLoop;
- }
+ // scan through the interface device list and get the names/speeds of each
+ // if. The speed data can be used to cap the search for the bottleneck link
+ // capacity. The intent is to reduce the impact of interrupt coalescing on
+ // the bottleneck link detection algorithm
+ // RAC 7/14/09
+ init_iflist();
+
+ sockAddr = I2AddrBySAddr(get_errhandle(), sock_addr, saddrlen, 0, 0);
+ sock_addr = I2AddrSAddr(sockAddr, 0);
+ src_addr = I2AddrSAddr(srcAddr, 0);
+
+ /* special check for localhost, set device accordingly */
+ if (I2SockAddrIsLoopback(sock_addr, saddrlen) > 0)
+ // hardcoding device address to 100, as initialised in main()
+ strlcpy(device, "lo", 100);
+ if (device == NULL) {
+ if (pcap_findalldevs(&alldevs, errbuf) == 0) {
+ for (dp = alldevs; dp != NULL; dp = dp->next) {
+ for (curAddr = dp->addresses; curAddr != NULL;
+ curAddr = curAddr->next) {
+ switch (curAddr->addr->sa_family) {
+ case AF_INET:
+ memset(namebuf, 0, 200);
+ inet_ntop(
+ AF_INET,
+ &((struct sockaddr_in *) curAddr->addr)->sin_addr,
+ namebuf, INET_ADDRSTRLEN);
+ log_println(3, "IPv4 interface found address=%s",
+ namebuf);
+ if (((struct sockaddr_in *) curAddr->addr)->sin_addr.s_addr
+ == ((struct sockaddr_in *) src_addr)->sin_addr.s_addr) {
+ log_println(
+ 4,
+ "IPv4 address match, setting device to '%s'",
+ dp->name);
+ device = dp->name;
+ ifspeed = -1;
+ for (i = 0; iflist.name[0][i] != '0'; i++) {
+ if (strncmp((char *) iflist.name[i], device, 4)
+ == 0) {
+ ifspeed = iflist.speed[i];
break;
+ }
+ }
+
+ if (direction[0] == 's') {
+ fwd.saddr[0] =
+ ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+ fwd.daddr[0] =
+ ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+ rev.saddr[0] =
+ ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+ rev.daddr[0] =
+ ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+
+ fwd.sport =
+ ntohs(
+ ((struct sockaddr_in *) src_addr)->sin_port);
+ fwd.dport =
+ ntohs(
+ ((struct sockaddr_in *) sock_addr)->sin_port);
+ rev.sport =
+ ntohs(
+ ((struct sockaddr_in *) sock_addr)->sin_port);
+ rev.dport =
+ ntohs(
+ ((struct sockaddr_in *) src_addr)->sin_port);
+ } else {
+ rev.saddr[0] =
+ ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+ rev.daddr[0] =
+ ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+ fwd.saddr[0] =
+ ((struct sockaddr_in *)sock_addr)->sin_addr.s_addr;
+ fwd.daddr[0] =
+ ((struct sockaddr_in *)src_addr)->sin_addr.s_addr;
+
+ rev.sport =
+ ntohs(
+ ((struct sockaddr_in *) src_addr)->sin_port);
+ rev.dport =
+ ntohs(
+ ((struct sockaddr_in *) sock_addr)->sin_port);
+ fwd.sport =
+ ntohs(
+ ((struct sockaddr_in *) sock_addr)->sin_port);
+ fwd.dport =
+ ntohs(
+ ((struct sockaddr_in *) src_addr)->sin_port);
+ }
+ goto endLoop;
+ }
+ break;
#if defined(AF_INET6)
- case AF_INET6:
- memset(namebuf, 0, 200);
- inet_ntop(AF_INET6,
- &((struct sockaddr_in6*)(curAddr->addr))->sin6_addr,
- namebuf, INET6_ADDRSTRLEN);
- /* I2AddrNodeName(srcAddr, namebuf, &nameBufLen); */
- log_println(3, "IPv6 interface found address=%s", namebuf);
- if (memcmp(((struct sockaddr_in6 *)curAddr->addr)->
- sin6_addr.s6_addr,
- ((struct sockaddr_in6 *)src_addr)->
- sin6_addr.s6_addr,
- 16) == 0) {
- log_println(4, "IPv6 address match, setting device to "
- "'%s'", dp->name);
- device = dp->name;
+ case AF_INET6:
+ memset(namebuf, 0, 200);
+ inet_ntop(AF_INET6,
+ &((struct sockaddr_in6*)(curAddr->addr))->sin6_addr,
+ namebuf, INET6_ADDRSTRLEN);
+ /* I2AddrNodeName(srcAddr, namebuf, &nameBufLen); */
+ log_println(3, "IPv6 interface found address=%s", namebuf);
+ if (memcmp(((struct sockaddr_in6 *)curAddr->addr)->
+ sin6_addr.s6_addr,
+ ((struct sockaddr_in6 *)src_addr)->
+ sin6_addr.s6_addr,
+ 16) == 0) {
+ log_println(4, "IPv6 address match, setting device to "
+ "'%s'", dp->name);
+ device = dp->name;

- struct sockaddr_in6* src_addr6 =
- (struct sockaddr_in6*)src_addr;
- struct sockaddr_in6* sock_addr6 =
- (struct sockaddr_in6*)sock_addr;
+ struct sockaddr_in6* src_addr6 =
+ (struct sockaddr_in6*)src_addr;
+ struct sockaddr_in6* sock_addr6 =
+ (struct sockaddr_in6*)sock_addr;

- if (direction[0] == 's') {
- memcpy(fwd.saddr, src_addr6->sin6_addr.s6_addr, 16);
- memcpy(fwd.daddr, sock_addr6->sin6_addr.s6_addr, 16);
- memcpy(rev.saddr, sock_addr6->sin6_addr.s6_addr, 16);
- memcpy(rev.daddr, src_addr6->sin6_addr.s6_addr, 16);
- fwd.sport = ntohs(src_addr6->sin6_port);
- fwd.dport = ntohs(sock_addr6->sin6_port);
- rev.sport = ntohs(sock_addr6->sin6_port);
- rev.dport = ntohs(src_addr6->sin6_port);
- } else {
- memcpy(rev.saddr, src_addr6->sin6_addr.s6_addr, 16);
- memcpy(rev.daddr, sock_addr6->sin6_addr.s6_addr, 16);
- memcpy(fwd.saddr, sock_addr6->sin6_addr.s6_addr, 16);
- memcpy(fwd.daddr, src_addr6->sin6_addr.s6_addr, 16);
- rev.sport = ntohs(src_addr6->sin6_port);
- rev.dport = ntohs(sock_addr6->sin6_port);
- fwd.sport = ntohs(sock_addr6->sin6_port);
- fwd.dport = ntohs(src_addr6->sin6_port);
- }
- goto endLoop;
- }
- break;
-#endif
- default:
- log_println(4, "Unknown address family=%d found",
- curAddr->addr->sa_family);
+ if (direction[0] == 's') {
+ memcpy(fwd.saddr, src_addr6->sin6_addr.s6_addr, 16);
+ memcpy(fwd.daddr, sock_addr6->sin6_addr.s6_addr, 16);
+ memcpy(rev.saddr, sock_addr6->sin6_addr.s6_addr, 16);
+ memcpy(rev.daddr, src_addr6->sin6_addr.s6_addr, 16);
+ fwd.sport = ntohs(src_addr6->sin6_port);
+ fwd.dport = ntohs(sock_addr6->sin6_port);
+ rev.sport = ntohs(sock_addr6->sin6_port);
+ rev.dport = ntohs(src_addr6->sin6_port);
+ } else {
+ memcpy(rev.saddr, src_addr6->sin6_addr.s6_addr, 16);
+ memcpy(rev.daddr, sock_addr6->sin6_addr.s6_addr, 16);
+ memcpy(fwd.saddr, sock_addr6->sin6_addr.s6_addr, 16);
+ memcpy(fwd.daddr, src_addr6->sin6_addr.s6_addr, 16);
+ rev.sport = ntohs(src_addr6->sin6_port);
+ rev.dport = ntohs(sock_addr6->sin6_port);
+ fwd.sport = ntohs(sock_addr6->sin6_port);
+ fwd.dport = ntohs(src_addr6->sin6_port);
}
+ goto endLoop;
}
- }
+ break;
+#endif
+ default:
+ log_println(4, "Unknown address family=%d found",
+ curAddr->addr->sa_family);
}
}
+ }
+ }
+ }
endLoop:

- /* device = pcap_lookupdev(errbuf); */
- if (device == NULL) {
- fprintf(stderr, "pcap_lookupdev failed: %s\n", errbuf);
- }
+ /* device = pcap_lookupdev(errbuf); */
+ if (device == NULL) {
+ fprintf(stderr, "pcap_lookupdev failed: %s\n", errbuf);
+ }

- log_println(1, "Opening network interface '%s' for packet-pair timing",
- device);
+ log_println(1, "Opening network interface '%s' for packet-pair timing",
+ device);

- if ((pd = pcap_open_live(device, 68, !pflag, 1000, errbuf)) == NULL) {
- fprintf(stderr, "pcap_open_live failed: %s\n", errbuf);
- }
+ if ((pd = pcap_open_live(device, 68, !pflag, 1000, errbuf)) == NULL) {
+ fprintf(stderr, "pcap_open_live failed: %s\n", errbuf);
+ }

- log_println(2, "pcap_open_live() returned pointer %p", pd);
+ log_println(2, "pcap_open_live() returned pointer %p", pd);

- memset(namebuf, 0, 200);
- I2AddrNodeName(sockAddr, namebuf, &nameBufLen);
- memset(cmdbuf, 0, sizeof(cmdbuf));
- snprintf(cmdbuf, sizeof(cmdbuf), "host %s and port %d", namebuf,
- I2AddrPort(sockAddr));
+ switch(sock_addr->sa_family) {
+ case AF_INET:
+ inet_ntop(AF_INET, &(((struct sockaddr_in *)sock_addr)->sin_addr),
+ namebuf, nameBufLen);
+ break;

- log_println(1, "installing pkt filter for '%s'", cmdbuf);
- log_println(1, "Initial pkt src data = %p", fwd.saddr);
+#ifdef AF_INET6
+ case AF_INET6:
+ inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sock_addr)->sin6_addr),
+ namebuf, nameBufLen);
+ break;
+#endif

- if (pcap_compile(pd, &fcode, cmdbuf, 0, 0xFFFFFF00) < 0) {
- fprintf(stderr, "pcap_compile failed %s\n", pcap_geterr(pd));
- return;
- }
+ default:
+ I2AddrNodeName(sockAddr, namebuf, &nameBufLen);
+ }

- if (pcap_setfilter(pd, &fcode) < 0) {
- fprintf(stderr, "pcap_setfiler failed %s\n", pcap_geterr(pd));
- return;
- }
+ memset(cmdbuf, 0, sizeof(cmdbuf));
+ snprintf(cmdbuf, sizeof(cmdbuf), "host %s and port %d", namebuf,
+ I2AddrPort(sockAddr));

- if (dumptrace == 1) {
- // Create log file
- snprintf(dir, sizeof(dir), "%s_%s:%d.%s_ndttrace",
- get_ISOtime(isoTime, sizeof(isoTime)), namebuf,
- I2AddrPort(sockAddr), direction);
- create_named_logdir(logdir, sizeof(logdir), dir, 0);
- pdump = pcap_dump_open(pd, logdir);
- fprintf(stderr, "Opening '%s' log fine\n", logdir);
- if (pdump == NULL) {
- fprintf(stderr, "Unable to create trace file '%s'\n", logdir);
- dumptrace = 0;
- }
- }
+ log_println(1, "installing pkt filter for '%s'", cmdbuf);
+ log_println(1, "Initial pkt src data = %p", fwd.saddr);

- printer = (pcap_handler) print_speed;
- if (dumptrace == 0) {
- for (i = 0; i < 5; i++) {
- rc = write(monitor_pipe[1], "Ready", 6);
- if (rc == 6)
- break;
- if ((rc == -1) && (errno == EINTR))
- continue;
- }
- } else {
- for (i = 0; i < 5; i++) {
- rc = write(monitor_pipe[1], dir, strlen(dir));
- if (rc == strlen(dir))
- break;
- if ((rc == -1) && (errno == EINTR))
- continue;
- }
- }
+ if (pcap_compile(pd, &fcode, cmdbuf, 0, 0xFFFFFF00) < 0) {
+ fprintf(stderr, "pcap_compile failed %s\n", pcap_geterr(pd));
+ return;
+ }

- /* kill process off if parent doesn't send a signal. */
- alarm(60);
+ if (pcap_setfilter(pd, &fcode) < 0) {
+ fprintf(stderr, "pcap_setfiler failed %s\n", pcap_geterr(pd));
+ return;
+ }

- if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) {
- log_println(5, "pcap_loop exited %s", pcap_geterr(pd));
- }
+ if (dumptrace == 1) {
+ // Create log file
+ snprintf(dir, sizeof(dir), "%s_%s:%d.%s_ndttrace",
+ get_ISOtime(isoTime, sizeof(isoTime)), namebuf,
+ I2AddrPort(sockAddr), direction);
+ create_named_logdir(logdir, sizeof(logdir), dir, 0);
+ pdump = pcap_dump_open(pd, logdir);
+ fprintf(stderr, "Opening '%s' log fine\n", logdir);
+ if (pdump == NULL) {
+ fprintf(stderr, "Unable to create trace file '%s'\n", logdir);
+ dumptrace = 0;
+ }
+ }

- /* Send back results to our parent */
- if (check_signal_flags() == 0) {
- log_println(5, "We should have a sig flag set");
- }
+ printer = (pcap_handler) print_speed;
+ if (dumptrace == 0) {
+ for (i = 0; i < 5; i++) {
+ rc = write(monitor_pipe[1], "Ready", 6);
+ if (rc == 6)
+ break;
+ if ((rc == -1) && (errno == EINTR))
+ continue;
+ }
+ } else {
+ for (i = 0; i < 5; i++) {
+ rc = write(monitor_pipe[1], dir, strlen(dir));
+ if (rc == strlen(dir))
+ break;
+ if ((rc == -1) && (errno == EINTR))
+ continue;
+ }
+ }

- pcap_close(pd);
+ /* kill process off if parent doesn't send a signal. */
+ alarm(60);

- log_println(
- 5,
- "Pkt-Pair data collection ended, waiting for signal to terminate "
- "process");
- /* Temporarily remove these free statements, The memory should be free'd when
- * the child process terminates, so we don't have a leak. There might be a bug in
- * the pcap lib (on-line reference found from 2003) and on 10/14/09 I was seeing
- * child crashes with a traceback pointing to the freecode() routine inside the pcap-lib
- * as the culprit. RAC 10/15/09
- *
- * if (alldevs != NULL)
- * pcap_freealldevs(alldevs);
- * if (&fcode != NULL)
- * pcap_freecode(&fcode);
- */
- free(sockAddr);
+ if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) {
+ log_println(5, "pcap_loop exited %s", pcap_geterr(pd));
+ }

- if (sig1 == 2) {
- while ((read(mon_pipe1[0], &c, 1)) < 0) { }
- close(mon_pipe1[0]);
- close(mon_pipe1[1]);
- sig1 = 0;
***The diff for this file has been truncated for email.***
=======================================
--- /branches/ndt-web10g/src/web100srv.c Thu Apr 11 07:52:06 2013
+++ /branches/ndt-web10g/src/web100srv.c Mon Jun 3 21:18:52 2013
@@ -99,60 +99,52 @@
static char dbPWDbuf[256]; // DB Password

// list of global variables used throughout this program.
-int window = 64000; // TCP buffer size
-int randomize = 0;
-int count_vars = 0;
-int dumptrace = 0;
-int usesyslog = 0;
-int multiple = 0;
-int compress = 1;
-int max_clients = 50;
-int set_buff = 0;
-int admin_view = 0;
-int queue = 1;
-int view_flag = 0;
-int record_reverse = 0;
-int testing; // a test is currently being performed.
-int waiting; // # of many tests pending
-int mclients; // multiple client mode client count
-int refresh = 30;
-int old_mismatch = 0; /* use the old duplex mismatch detection heuristic */
+static int window = 64000; // TCP buffer size
+static int count_vars = 0;
+static int dumptrace = 0;
+static int usesyslog = 0;
+static int multiple = 0;
+static int compress = 1;
+static int max_clients = 50;
+static int set_buff = 0;
+static int admin_view = 0;
+static int queue = 1;
+static int record_reverse = 0;
+static int testing; // a test is currently being performed.
+static int waiting; // # of many tests pending
+static int mclients; // multiple client mode client count
+static int refresh = 30;
+static int old_mismatch = 0; /* use the old duplex mismatch detection heuristic */
/* int sig1, sig2, sig17; */

-Options options;
-CwndPeaks peaks;
-int cputime = 0;
-char cputimelog[256];
-pthread_t workerThreadId, zombieThreadId;
-int cputimeworkerLoop = 1, zombie_check = 0;
+static Options options;
+static CwndPeaks peaks;
+static int cputime = 0;
+static char cputimelog[256];
+static pthread_t workerThreadId, zombieThreadId;
+static int cputimeworkerLoop = 1, zombie_check = 0;

-int useDB = 0;
-char* dbDSN = NULL;
-char* dbUID = NULL;
-char* dbPWD = NULL;
+static int useDB = 0;
+static char* dbDSN = NULL;
+static char* dbUID = NULL;
+static char* dbPWD = NULL;

-char *VarFileName = NULL;
-char *AdminFileName = NULL;
-char *SysLogFacility = NULL;
-int syslogfacility = LOG_FACILITY;
-char *ProcessName = { "web100srv" };
-char *ConfigFileName = NULL;
-char buff[BUFFSIZE + 1];
-char*rmt_host;
-char spds[4][256], buff2[32];
-char *device = NULL;
-char* port = PORT;
-TestOptions testopt;
+static char *VarFileName = NULL;
+static char *AdminFileName = NULL;
+static char *SysLogFacility = NULL;
+static int syslogfacility = LOG_FACILITY;
+static char *ConfigFileName = NULL;
+static char buff[BUFFSIZE + 1];
+static char*rmt_host;
+static char *device = NULL;
+static char* port = PORT;
+static TestOptions testopt;

-pcap_t *pd;
-pcap_dumper_t *pdump;
-float run_ave[4];
-
-int conn_options = 0;
-struct ndtchild *head_ptr;
-int ndtpid;
-int testPort;
-char testName[256];
+static int conn_options = 0;
+static struct ndtchild *head_ptr;
+static int ndtpid;
+static int testPort;
+static char testName[256];

/* create semaphore to allow only 1 process to modify the wait queue */
#include <semaphore.h>
@@ -1890,18 +1882,6 @@
protolog_printgeneric(srvstatusdesc, startsrvmsg);
*/

- // scan through the interface device list and get the names/speeds of each
- // if. The speed data can be used to cap the search for the bottleneck link
- // capacity. The intent is to reduce the impact of interrupt coalescing on
- // the bottleneck link detection algorithm
- // RAC 7/14/09
-
- get_iflist();
-
- for (i = 0; iflist.speed[i] > 0; i++)
- log_println(4, "Generated iflist with device=%s and if_speed=%d",
- iflist.name[i], iflist.speed[i]);
-
// Wait at accept() for a new connection from a client process.

// These 2 flags keep track of running processes. The 'testing' flag
=======================================
--- /branches/ndt-web10g/src/web100srv.h Sat Apr 13 19:56:13 2013
+++ /branches/ndt-web10g/src/web100srv.h Mon Jun 3 21:18:52 2013
@@ -145,13 +145,9 @@
/* structure used to collect speed data in bins */
struct spdpair {
int family; // Address family
-#if defined(AF_INET6)
u_int32_t saddr[4]; // source address
u_int32_t daddr[4]; // dest address
-#else
- u_int32_t saddr; // source address
- u_int32_t daddr; // dest address
-#endif
+
u_int16_t sport; // source port
u_int16_t dport; // destination port
u_int32_t seq; // seq number
@@ -174,8 +170,6 @@
u_int32_t totalcount; // total number of valid speed data bins
};

-struct spdpair fwd, rev;
-
struct web100_variables {
char name[256]; // key
char value[256]; // value
@@ -216,11 +210,6 @@
u_int32_t reserved[4];
};

-struct iflists {
- char name[8][32];
- u_int16_t speed[32];
-} iflist;
-
typedef int tcp_stat_var;

struct tcp_vars {
@@ -276,7 +265,7 @@
int port3);
void init_pkttrace(I2Addr srcAddr, struct sockaddr *sock_addr,
socklen_t saddrlen, int monitor_pipe[2], char *device,
- PortPair* pair, const char* direction, int compress);
+ PortPair* pair, char* direction, int compress);
void force_breakloop();
#endif



  • [ndt-dev] [ndt] r826 committed - Merge Trunk changes r817-825..., ndt, 06/04/2013

Archive powered by MHonArc 2.6.16.

Top of Page