Commit c2e856db authored by Mike Hibler's avatar Mike Hibler
Browse files

Changes to trafgen to force binding to local addr/port.

Rob noticed, that in an experiment with gated running, the trafgen
would startup before gated got its routes.  The result was that trafgen
traffic would use the default route sending data out the control net IF.
When the real route came online, traffic would start going out the
proper interface but the source addr would still be the control net addr
so TCP ACKs would still come back via the control net.

By binding the local address for trafgen to 192.168.X.X we force the
source addr to be correct always.
parent 949b502b
......@@ -43,8 +43,8 @@ usage()
{
fprintf(stderr,
"Usage: %s [-s serverip] [-p serverport] [-l logfile] "
"[ -N name ] [ -T targetip.targetport ] [-P proto] [-R role] "
"[ -E pid/eid ]\n",
"[ -N name ] [ -S srcip.srcport ] [ -T targetip.targetport ] "
"[-P proto] [-R role] [ -E pid/eid ]\n",
progname);
exit(-1);
}
......@@ -75,13 +75,14 @@ tgevent_init(int argc, char *argv[])
char *ipaddr = NULL;
char *myname = NULL;
char buf[BUFSIZ], ipbuf[BUFSIZ];
struct sockaddr tmp;
int c;
struct sockaddr saddr, taddr;
int c, gotsaddr = 0;
progname = argv[0];
memset(&tmp, 0, sizeof(tmp));
memset(&saddr, 0, sizeof(saddr));
memset(&taddr, 0, sizeof(taddr));
while ((c = getopt(argc, argv, "s:p:T:P:R:N:l:E:")) != -1) {
while ((c = getopt(argc, argv, "s:p:S:T:P:R:N:l:E:")) != -1) {
switch (c) {
case 's':
server = optarg;
......@@ -89,8 +90,13 @@ tgevent_init(int argc, char *argv[])
case 'p':
port = optarg;
break;
case 'S':
if (!ipport_atoaddr(optarg, &saddr))
badaddr();
gotsaddr = 1;
break;
case 'T':
if (!ipport_atoaddr(optarg, &tmp))
if (!ipport_atoaddr(optarg, &taddr))
badaddr();
break;
case 'P':
......@@ -120,11 +126,19 @@ tgevent_init(int argc, char *argv[])
badprot();
if (prot.qos & QOS_SERVER) {
prot.src = tmp;
prot.src = taddr;
prot.qos |= QOS_SRC;
} else {
prot.dst = tmp;
prot.dst = taddr;
prot.qos |= QOS_DST;
/*
* Can specify source address to bind local interface
* of sender.
*/
if (gotsaddr) {
prot.src = saddr;
prot.qos |= QOS_SRC;
}
}
argc -= optind;
......
......@@ -152,12 +152,22 @@ diff -ru dist-tg2.0/src/tg/prot_stream.c tg2.0/src/tg/prot_stream.c
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
+++ tg2.0/src/tg/prot_tcp.c Wed Mar 13 09:16:49 2002
@@ -184,7 +184,7 @@
+++ tg2.0/src/tg/prot_tcp.c Tue Apr 2 23:20:41 2002
@@ -184,7 +184,17 @@
return (-1);
}
- if ((connect(sfd, &(prot->dst), sizeof(prot->dst)) < 0) &
+ /* Bind to a local address if desired. */
+ if (prot->qos & QOS_SRC)
+ {
+ if (bind(sfd, &(prot->src), sizeof(prot->src)) < 0)
+ {
+ (void)close(sfd);
+ return (-1);
+ }
+ }
+
+ if ((connect(sfd, &(prot->dst), sizeof(prot->dst)) < 0) &&
(errno != EINPROGRESS))
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment