]> git.saurik.com Git - apple/network_cmds.git/commitdiff
network_cmds-511.50.3.tar.gz macos-10124 macos-10125 macos-10126 v511.50.3
authorApple <opensource@apple.com>
Thu, 1 Dec 2016 22:33:08 +0000 (22:33 +0000)
committerApple <opensource@apple.com>
Thu, 1 Dec 2016 22:33:08 +0000 (22:33 +0000)
.gitignore [new file with mode: 0644]
cfilutil/cfilutil.c
ecnprobe/capture.c
ecnprobe/ecn.c
ecnprobe/ecn.h
ecnprobe/ecn_probe.c
ecnprobe/inet.c
ecnprobe/session.c
ecnprobe/session.h
ecnprobe/support.c
network_cmds.xcodeproj/project.pbxproj

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..009fb98
--- /dev/null
@@ -0,0 +1,8 @@
+.DS_Store
+*.xcodeproj/project.xcworkspace
+*.xcodeproj/xcuserdata
+.svn
+build
+*~.m
+*~.c
+*~.h
index 546604ca87b08f885d124d8109316bffb8608ce1..4aaa7193a5bd109fd1d200252bdadd18c195617f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014 Apple Inc. All rights reserved.
+ * Copyright (c) 2013-2016 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -476,14 +476,19 @@ doit()
        kv.filter = EVFILT_READ;
        kv.flags = EV_ADD;
        if (kevent(kq, &kv, 1, NULL, 0, NULL) == -1)
-               err(1, "kevent(sf)");
-       
-       bzero(&kv, sizeof(struct kevent));
-       kv.ident = fdin;
-       kv.filter = EVFILT_READ;
-       kv.flags = EV_ADD;
-       if (kevent(kq, &kv, 1, NULL, 0, NULL) == -1)
-               err(1, "kevent(sf)");
+               err(1, "kevent(sf %d)", sf);
+       
+       /*
+        * We can only read from an interactive terminal
+        */
+       if (isatty(fdin)) {
+               bzero(&kv, sizeof(struct kevent));
+               kv.ident = fdin;
+               kv.filter = EVFILT_READ;
+               kv.flags = EV_ADD;
+               if (kevent(kq, &kv, 1, NULL, 0, NULL) == -1)
+                       err(1, "kevent(fdin %d)", fdin);
+       }
        
        buffer = malloc(MAX_BUFFER);
        if (buffer == NULL)
index 34ed9ece68e414a58cd2b9e41e0aebdfe072ceb1..ff6b6d58584f978f95bfbbe97171b1c1ed3bd968 100644 (file)
@@ -56,7 +56,7 @@
 
 pcap_t *pc;            /* pcap device */
 int datalinkOffset;    /* offset of ip packet from datalink packet */
-int captureDebug = 0;
+int captureDebug = 1;
 unsigned int thisTimeZone;
 
 void CaptureInit(u_int32_t sourceIP, u_int16_t sourcePort,
index f09282d7e3faeededd48a22ccaacd6fcfb0f2cbf..b7dabdf1a34442868813c24e9f12807be742dcb9 100644 (file)
@@ -947,3 +947,173 @@ void ECNPathCheckTest(u_int32_t sourceAddress, u_int16_t sourcePort,
   DataPktPathCheck(session.filename, 3, 0);
   return;
 }
+
+
+void
+SynTest(u_int32_t sourceAddress, u_int16_t sourcePort,
+    u_int32_t targetAddress, u_int16_t targetPort, int mss, int syn_reply)
+{
+       int rawSocket, flag;
+       struct IPPacket *synPacket = NULL, *ackPacket = NULL;
+       char *read_packet;
+       struct pcap_pkthdr pi;
+       int synAckReceived = 0;
+       int numRetransmits = 0;
+       double timeoutTime;
+       int tcpoptlen = 4; /* For negotiating MSS */
+       u_int8_t *opt = NULL;
+       struct IPPacket *p = NULL;
+
+       arc4random_stir();
+
+       session.src = sourceAddress;
+       session.sport = sourcePort;
+       session.dst = targetAddress;
+       session.dport = targetPort;
+       session.rcv_wnd = 5*mss;
+       session.snd_nxt = arc4random();
+       session.iss = session.snd_nxt;
+       session.rcv_nxt = 0;
+       session.irs = 0;
+       session.mss = mss;
+       session.maxseqseen = 0;
+       session.epochTime = GetTime();
+       session.maxpkts = 1000;
+
+       if ((session.dataRcvd = (u_int8_t *)calloc(sizeof(u_int8_t),
+                                                  mss * session.maxpkts)) == NULL) {
+               printf("no memory to store data, error: %d \n", ERR_MEM_ALLOC);
+               Quit(ERR_MEM_ALLOC);
+       }
+
+       if ((rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
+               perror("ERROR: couldn't open socket:");
+               Quit(ERR_SOCKET_OPEN);
+       }
+
+       flag = 1;
+       if (setsockopt(rawSocket, IPPROTO_IP, IP_HDRINCL,
+                      (char *)&flag, sizeof(flag)) < 0) {
+               perror("ERROR: couldn't set raw socket options:");
+               Quit(ERR_SOCKOPT);
+       }
+
+       session.socket = rawSocket;
+
+
+       /* allocate the syn packet -- Changed for new IPPacket structure */
+       synPacket = AllocateIPPacket(0, tcpoptlen, 0, "ECN (SYN)");
+       opt = (((u_int8_t *)synPacket->tcp) + sizeof(struct TcpHeader));
+       opt[0] = (u_int8_t)TCPOPT_MAXSEG;
+       opt[1] = (u_int8_t)TCPOLEN_MAXSEG;
+       *((u_int16_t *)((u_int8_t *)opt + 2)) = htons(session.mss);
+
+       SendSessionPacket(synPacket,
+                         sizeof(struct IpHeader) + sizeof(struct TcpHeader) + tcpoptlen,
+                         TCPFLAGS_SYN , 0, tcpoptlen, 0);
+       timeoutTime = GetTime() + 1;
+
+       /*
+        * Wait for SYN/ACK and retransmit SYN if appropriate
+        * not great, but it gets the job done
+        */
+
+       while(!synAckReceived && numRetransmits < 3) {
+               while(GetTime() < timeoutTime) {
+                       /* Have we captured any packets? */
+                       if ((read_packet = (char *)CaptureGetPacket(&pi)) != NULL) {
+                               p = (struct IPPacket *)FindHeaderBoundaries(read_packet);
+                               /* Received a packet from us to them */
+                               if (INSESSION(p, session.src, session.sport,
+                                             session.dst, session.dport)) {
+                                       /* Is it a SYN/ACK? */
+                                       if (p->tcp->tcp_flags & TCPFLAGS_SYN) {
+                                               if (session.debug >= SESSION_DEBUG_LOW) {
+                                                       PrintTcpPacket(p);
+                                               }
+                                               StorePacket(p);
+                                               session.totSeenSent++ ;
+                                       } else {
+                                               processBadPacket(p);
+                                       }
+                                       continue;
+                               }
+
+                               /* Received a packet from them to us */
+                               if (INSESSION(p, session.dst, session.dport, session.src,
+                                             session.sport)) {
+                                       /* Is it a SYN/ACK? */
+                                       if ((p->tcp->tcp_flags & TCPFLAGS_SYN) &&
+                                           (p->tcp->tcp_flags & TCPFLAGS_ACK)) {
+                                               timeoutTime = GetTime(); /* force exit */
+                                               synAckReceived++;
+                                               if (session.debug >= SESSION_DEBUG_LOW) {
+                                                       PrintTcpPacket(p);
+                                               }
+                                               StorePacket(p);
+
+                                               /*
+                                                * Save ttl for,admittedly poor,indications of reverse
+                                                * route change
+                                                */
+                                               session.ttl = p->ip->ip_ttl;
+                                               session.snd_wnd = ntohl(p->tcp->tcp_win);
+                                               session.totRcvd ++;
+                                               break;
+                                       } else {
+                                               if ((p->tcp->tcp_flags)& (TCPFLAGS_RST)) {
+                                                       printf ("ERROR: EARLY_RST\n");
+                                                       goto done;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               if (!synAckReceived) {
+                       if (session.debug >= SESSION_DEBUG_LOW) {
+                               printf("SYN timeout. Retransmitting\n");
+                       }
+                       SendSessionPacket(synPacket,
+                                         sizeof(struct IpHeader) + sizeof(struct TcpHeader) + tcpoptlen,
+                                         TCPFLAGS_SYN , 0, tcpoptlen, 0);
+                       timeoutTime = GetTime() + 1;
+                       numRetransmits++;
+               }
+       }
+
+       if (numRetransmits >= 3) {
+               printf("ERROR: No connection after 3 retries...\nRETURN CODE: %d\n",
+                      NO_CONNECTION);
+               goto done;
+       }
+       if (session.debug >= SESSION_DEBUG_LOW)
+               printf("Received SYN-ACK\n");
+       if (syn_reply != 0) {
+               /* Update session variables */
+               session.irs = ntohl(p->tcp->tcp_seq);
+               session.dataRcvd[0] = 1 ;
+               session.rcv_nxt = session.irs + 1;      /* SYN/ACK takes up a byte of seq space */
+               session.snd_nxt = session.iss + 1;      /* SYN takes up a byte of seq space */
+               session.snd_una = session.iss + 1;
+               session.maxseqseen = ntohl(p->tcp->tcp_seq);
+               session.initSession = 1;
+               if (session.debug >= SESSION_DEBUG_LOW) {
+                       printf("try to send the %s\n", syn_reply == TCPFLAGS_ACK ? "third Ack" : "RST");
+                       printf("src = %s:%d (%u)\n", InetAddress(session.src),
+                              session.sport, session.iss);
+                       printf("dst = %s:%d (%u)\n",InetAddress(session.dst),
+                              session.dport, session.irs);
+               }
+
+               /* allocate the syn packet -- Changed for new IPPacket structure */
+               ackPacket = AllocateIPPacket(0, 0, 0, "SYN reply");
+               /* send an ACK */
+               SendSessionPacket(ackPacket,
+                                 sizeof(struct IpHeader) + sizeof(struct TcpHeader),
+                                 syn_reply, 0, 0, 0);
+               FreeIPPacket(&ackPacket);
+       }
+done:
+       FreeIPPacket(&synPacket);
+}
index adf826004b9ca376966a3b9c2fb07c5a4422bb45..5ac582c389bbddf3e84f718649979b98bb5b5f4b 100644 (file)
@@ -46,3 +46,4 @@ void DataPkt (char *filename, u_int8_t iptos, u_int8_t tcp_flags);
 void checkECN ();
 void ECNPathCheckTest(u_int32_t sourceIpAddress, u_int16_t surcePort,
   u_int32_t targetIpAddress, u_int16_t targetPort, int mss);
+void SynTest(u_int32_t sourceIpAddress, u_int16_t surcePort, u_int32_t targetIpAddress, u_int16_t targetPort, int mss, int syn_reply);
index 9ff6193b1b3f6c1de988c7aea7062ebd884ec3db..ae00f4ad3a032eaaf652e6db4ee3c7d813a6f625 100644 (file)
@@ -79,6 +79,8 @@ void usage(char *name)
        printf("\t-f <file-name to get>\n");
        printf("\t-d <interface name>\n");
        printf("\t-C for CE path check\n");
+       printf("\t-S [A|R|X] SYN followed by ACK or RST or nothing\n");
+       printf("\t-F [set|clear|skip] how to handle firewall rules\n");
        return;
 }
 
@@ -86,17 +88,17 @@ void SetupFirewall(u_int32_t targetIP, u_int16_t port, char *dev)
 {
        char pfcmd[512];
        char *pf_file_name = "/tmp/pf.conf";
-    int pf_fd = 0, rc;
+       int pf_fd = 0, rc;
        ssize_t bytes;
-    char *args[4];
+       char *args[4];
 
        bzero(pfcmd, sizeof(pfcmd));
 
-    bzero(args, sizeof(args));
+       bzero(args, sizeof(args));
        sprintf(pfcmd, "block in quick on %s inet proto tcp from %s port %u\n",
-           dev, InetAddress(targetIP), port);
+               dev, InetAddress(targetIP), port);
        if (session.debug >= SESSION_DEBUG_LOW)
-           printf("PF rule: %s\n", pfcmd);
+               printf("PF rule: %s\n", pfcmd);
 
        pf_fd = open(pf_file_name, O_RDWR|O_TRUNC|O_CREAT);
        if (pf_fd < 0) {
@@ -105,52 +107,59 @@ void SetupFirewall(u_int32_t targetIP, u_int16_t port, char *dev)
        }
        bytes = write(pf_fd, pfcmd, strlen(pfcmd) + 1);
        close(pf_fd);
-    args[0] = "pfctl";
-    args[1] = "-d";
-    args[2] = NULL;
-    rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
-    if (rc != 0) {
-        printf("Failed to exec: pfctl -d: %d\n", rc);
-        Quit(FAIL);
-    }
-    
-    args[1] = "-f";
-    args[2] = pf_file_name;
-    args[3] = NULL;
-    rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
-    if (rc != 0) {
-        printf("Failed to exec: pfctl -f /tmp/pf.conf: %d\n", rc);
-        Quit(FAIL);
-    }
-
-    args[1] = "-e";
-    args[2] = NULL;
-    rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
-    if (rc != 0) {
-        printf("Failed to exec: pfctl -e: %d\n", rc);
-        Quit(FAIL);
-    }
+       args[0] = "pfctl";
+       args[1] = "-d";
+       args[2] = NULL;
+       rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
+       if (rc != 0) {
+               printf("Failed to exec: pfctl -d: %d\n", rc);
+               Quit(FAIL);
+       }
+
+       args[1] = "-f";
+       args[2] = pf_file_name;
+       args[3] = NULL;
+       rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
+       if (rc != 0) {
+               printf("Failed to exec: pfctl -f /tmp/pf.conf: %d\n", rc);
+               Quit(FAIL);
+       }
+
+       args[1] = "-e";
+       args[2] = NULL;
+       rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
+       if (rc != 0) {
+               printf("Failed to exec: pfctl -e: %d\n", rc);
+               Quit(FAIL);
+       }
+}
+
+void CleanupFirewall()
+{
+       char * args[3];
+       int rc;
+
+       args[0] = "pfctl";
+       args[1] = "-d";
+       args[2] = NULL;
+       rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
+       if (rc != 0) {
+               printf("Failed to exec: pfctl -d: %d\n", rc);
+               Quit(FAIL);
+       }
 }
 
 void Cleanup()
 {
-    char * args[3];
-    int rc;
        if (session.initSession > 0) {
                shutdown(session.socket, 2);
        }
-
        if (session.initCapture > 0) {
                CaptureEnd();
        }
-    args[0] = "pfctl";
-    args[1] = "-d";
-    args[2] = NULL;
-    rc = posix_spawn(NULL, "/sbin/pfctl", NULL, NULL, args, NULL);
-    if (rc != 0) {
-        printf("Failed to exec: pfctl -d: %d\n", rc);
-        Quit(FAIL);
-    }
+       if (session.initFirewall > 0) {
+               CleanupFirewall();
+       }
 }
 
 void Quit(int how)
@@ -227,21 +236,34 @@ int BindTcpPort(int sockfd)
                ++port;
                sockName.sin_addr.s_addr = INADDR_ANY;
                sockName.sin_family = AF_INET;
-               sockName.sin_port = htons(port);
+               sockName.sin_port = 0; //htons(port);
                result = bind(sockfd, (struct sockaddr *)&sockName,
                            sizeof(sockName));
        } while ((result < 0) && (port < END_PORT));
 
+
        if (result < 0) {
                /* No free ports */
                perror("bind"); 
                port = 0;
-       }    
+       } else {
+               socklen_t len = sizeof(sockName);
+               result = getsockname(sockfd, (struct sockaddr *)&sockName, &len);
+               if (result < 0) {
+                       perror("getsockname");
+                       port = 0;
+               } else {
+                       port = ntohs(sockName.sin_port);
+               }
+       }
        return port;
 
 }
 
-
+#define        FIREWALL_DEFAULT 0
+#define        FIREWALL_SET_ONLY 1
+#define        FIREWALL_CLEAR_ONLY 2
+#define FIREWALL_SKIP 3
 
 int main(int argc, char **argv)
 {
@@ -252,83 +274,111 @@ int main(int argc, char **argv)
        int mss = DEFAULT_MSS;
        int mtu = DEFAULT_MTU;
        int fd, opt, usedev = 0, rc = 0, path_check = 0;
+       int syn_test = 0, syn_reply = 0;
        struct sockaddr_in saddr;
        char dev[11];  /* device name for pcap init */
        struct ifaddrs *ifap, *tmp;
+       int firewall_mode = FIREWALL_DEFAULT;
 
        bzero(&session, sizeof(session));
-       while ((opt = getopt(argc, argv, "n:p:w:m:M:s:d:f:-C")) != -1) {
+       while ((opt = getopt(argc, argv, "n:p:w:m:M:s:d:f:-CS:vF:")) != -1) {
                switch (opt) {
-               case 'n':
-                       if (strlen(optarg) > (MAXHOSTNAMELEN - 1)) {
-                               printf("Target host name too long, max %u chars\n", MAXHOSTNAMELEN);
-                               Quit(FAIL);
-                       }
-                       strncpy(session.targetHostName, optarg,
-                           MAXHOSTNAMELEN);
-                       strncpy(session.targetName, session.targetHostName,
-                           MAXHOSTNAMELEN);
-                       break;
-               case 'p':
-                       targetPort = atoi(optarg);
-                       break;
-               case 'm':
-                       mss = atoi(optarg);
-                       break;
-               case 'M':
-                       mtu = atoi(optarg);
-                       break;
-               case 'w':
-                       sourcePort = atoi(optarg);
-                       break;
-               case 's':
-                       if (strlen(optarg) > (MAXHOSTNAMELEN - 1)) {
-                               printf("Source host name too long, max %u chars\n", MAXHOSTNAMELEN);
-                               Quit(FAIL);
-                       }
-                       strncpy(session.sourceHostName, optarg,
-                           MAXHOSTNAMELEN);
-                       break;
-               case 'd':
-                       if (strlen(optarg) > (sizeof(dev) - 1)) {
-                               printf("Interface nae is too large, max %lu chars\n", (sizeof(dev) - 1));
-                               Quit(FAIL);
-                       }
-                       bzero(dev, sizeof(dev));
-                       strncpy(dev, optarg, (sizeof(dev) - 1));
-                       usedev = 1;
-                       break;
-               case 'f':
-                       if (strlen(optarg) > 0) {
-                               session.filename = strndup(optarg, strlen(optarg) + 1);
-                       } else {
-                               printf("Invalid file name \n");
-                       }
-                       break;
-               case 'C':
-                       path_check = 1;
-                       break;
-               default:
-                       usage(argv[0]);
-                       exit(1);
+                       case 'n':
+                               if (strlen(optarg) > (MAXHOSTNAMELEN - 1)) {
+                                       printf("Target host name too long, max %u chars\n", MAXHOSTNAMELEN);
+                                       Quit(FAIL);
+                               }
+                               strncpy(session.targetHostName, optarg,
+                                       MAXHOSTNAMELEN);
+                               strncpy(session.targetName, session.targetHostName,
+                                       MAXHOSTNAMELEN);
+                               break;
+                       case 'p':
+                               targetPort = atoi(optarg);
+                               break;
+                       case 'm':
+                               mss = atoi(optarg);
+                               break;
+                       case 'M':
+                               mtu = atoi(optarg);
+                               break;
+                       case 'w':
+                               sourcePort = atoi(optarg);
+                               break;
+                       case 's':
+                               if (strlen(optarg) > (MAXHOSTNAMELEN - 1)) {
+                                       printf("Source host name too long, max %u chars\n", MAXHOSTNAMELEN);
+                                       Quit(FAIL);
+                               }
+                               strncpy(session.sourceHostName, optarg,
+                                       MAXHOSTNAMELEN);
+                               break;
+                       case 'd':
+                               if (strlen(optarg) > (sizeof(dev) - 1)) {
+                                       printf("Interface nae is too large, max %lu chars\n", (sizeof(dev) - 1));
+                                       Quit(FAIL);
+                               }
+                               bzero(dev, sizeof(dev));
+                               strncpy(dev, optarg, (sizeof(dev) - 1));
+                               usedev = 1;
+                               break;
+                       case 'f':
+                               if (strlen(optarg) > 0) {
+                                       session.filename = strndup(optarg, strlen(optarg) + 1);
+                               } else {
+                                       printf("Invalid file name \n");
+                               }
+                               break;
+                       case 'F':
+                               if (strcasecmp(optarg, "default") == 0)
+                                       firewall_mode = FIREWALL_DEFAULT;
+                               else if (strcasecmp(optarg, "set") == 0)
+                                       firewall_mode = FIREWALL_SET_ONLY;
+                               else if (strcasecmp(optarg, "clear") == 0)
+                                       firewall_mode = FIREWALL_CLEAR_ONLY;
+                               else if (strcasecmp(optarg, "skip") == 0)
+                                       firewall_mode = FIREWALL_SKIP;
+                               else
+                                       printf("firewall mode\n");
+                               break;
+                       case 'C':
+                               path_check = 1;
+                               break;
+                       case 'S':
+                               syn_test = 1;
+                               if (strcasecmp(optarg, "A") == 0)
+                                       syn_reply = TCPFLAGS_ACK;
+                               else if (strcasecmp(optarg, "R") == 0)
+                                       syn_reply = TCPFLAGS_RST;
+                               else if (strcasecmp(optarg, "X") == 0)
+                                       syn_reply = 0;
+                               else
+                                       printf("Invalid SYN reply \n");
+                               break;
+                       case 'v':
+                               session.debug++;
+                               break;
+                       default:
+                               usage(argv[0]);
+                               exit(1);
                }
        }
        signal(SIGTERM, SigHandle);
        signal(SIGINT, SigHandle);
        signal(SIGHUP, SigHandle);
-       
+
        if (GetCannonicalInfo(session.targetHostName, &targetIpAddress) < 0)
        {
                printf("Failed to convert targetIP address\n");
                Quit(NO_TARGET_CANON_INFO);
-       } 
-/*
-       if (GetCannonicalInfo(session.sourceHostName, &sourceIpAddress) < 0)
-       {
+       }
+       /*
+        if (GetCannonicalInfo(session.sourceHostName, &sourceIpAddress) < 0)
+        {
                printf("Failed to convert source IP address\n");
                Quit(NO_TARGET_CANON_INFO);
-       }
-*/
+        }
+        */
        rc = getifaddrs(&ifap);
        if (rc != 0 || ifap == NULL) {
                printf("Failed to get source addresswith getifaddrs: %d\n", rc);
@@ -349,8 +399,8 @@ int main(int argc, char **argv)
                                sin = (struct sockaddr_in *)tmp->ifa_addr;
                                sourceIpAddress = sin->sin_addr.s_addr;
                                strncpy(session.sourceHostName,
-                                   inet_ntoa(sin->sin_addr),
-                                   MAXHOSTNAMELEN);
+                                       inet_ntoa(sin->sin_addr),
+                                       MAXHOSTNAMELEN);
                        } else {
                                continue;
                        }
@@ -360,9 +410,9 @@ int main(int argc, char **argv)
                        sin = (struct sockaddr_in *)tmp->ifa_addr;
                        sourceIpAddress = sin->sin_addr.s_addr;
                        strncpy(session.sourceHostName,
-                           inet_ntoa(sin->sin_addr),
-                           MAXHOSTNAMELEN);
-                       strncpy(dev, tmp->ifa_name, sizeof(dev)); 
+                               inet_ntoa(sin->sin_addr),
+                               MAXHOSTNAMELEN);
+                       strncpy(dev, tmp->ifa_name, sizeof(dev));
                }
        }
        freeifaddrs(ifap);
@@ -383,23 +433,42 @@ int main(int argc, char **argv)
                        return (-1);
                }
        }
-       CaptureInit(sourceIpAddress, sourcePort, targetIpAddress,
-           targetPort, dev);
-       session.initCapture = 1;
-
        printf("Source: %s:%d\n", session.sourceHostName, sourcePort);
        printf("Destination: %s:%d\n", session.targetHostName, targetPort);
 
-       SetupFirewall(targetIpAddress, targetPort, dev);
+       switch (firewall_mode) {
+               case FIREWALL_DEFAULT:
+                       SetupFirewall(targetIpAddress, targetPort, dev);
+                       session.initFirewall = 1;
+                       break;
+               case FIREWALL_SET_ONLY:
+                       SetupFirewall(targetIpAddress, targetPort, dev);
+                       goto done;
+               case FIREWALL_CLEAR_ONLY:
+                       session.initFirewall = 1;
+                       goto done;
+               case FIREWALL_SKIP:
+                       break;
+       }
+
+       CaptureInit(sourceIpAddress, sourcePort, targetIpAddress,
+                   targetPort, dev);
+       session.initCapture = 1;
+
 
        printf("Starting ECN test\n");
-       if (path_check) {
-         ECNPathCheckTest(sourceIpAddress, sourcePort, targetIpAddress,
-            targetPort, mss);
+       if (syn_test) {
+               session.dont_send_reset = 1;
+               SynTest(sourceIpAddress, sourcePort, targetIpAddress,
+                       targetPort, mss, syn_reply);
+       } else if (path_check) {
+               ECNPathCheckTest(sourceIpAddress, sourcePort, targetIpAddress,
+                                targetPort, mss);
        } else {
-         ECNTest(sourceIpAddress, sourcePort, targetIpAddress,
-            targetPort, mss);
+               ECNTest(sourceIpAddress, sourcePort, targetIpAddress,
+                       targetPort, mss);
        }
+done:
        Quit(SUCCESS);
        close(session.socket);
        return (0);
index 723101a9e0e4c5650943ed184d6b8fd626e99177..b145412d165d4f585571ba2750ea046fc25bc136 100644 (file)
@@ -85,7 +85,7 @@ uint16 InetChecksum(uint16 *ip, uint16 *tcp, uint16 ip_len, uint16 tcp_len) {
   uint16 *ip_addr = ip;
   uint16 *tcp_addr = tcp;
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In InetChecksum...\n");
     printf("iplen: %d, tcplen: %d\n", ip_len, tcp_len);
   }
@@ -115,7 +115,7 @@ uint16 InetChecksum(uint16 *ip, uint16 *tcp, uint16 ip_len, uint16 tcp_len) {
     sum = (sum & 0xffff) + (sum >> 16);
   }
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out InetChecksum...\n");
   }
 
@@ -144,7 +144,7 @@ void WriteIPPacket(struct IPPacket *p,
   struct IpHeader *ip = p->ip;
   struct TcpHeader *tcp = p->tcp;
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In WriteIPPacket...\n");
   }
 
@@ -191,7 +191,12 @@ void WriteIPPacket(struct IPPacket *p,
   ip->ip_off = IP_DF;
   ip->ip_len = (uint16)(sizeof(struct IpHeader) + ip_optlen + sizeof(struct TcpHeader) + optlen + datalen);
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  ip->ip_xsum = 0;
+  ip->ip_xsum = InetChecksum((uint16 *)ip, NULL,
+                              (uint16)sizeof(struct IpHeader) + ip_optlen, /* IP Options should aren't included */
+                              0);
+
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out WriteIPPacket...\n");
   }
 
@@ -445,7 +450,7 @@ AllocateIPPacket(int ip_optlen, int tcp_optlen, int datalen, char *str)
 {
        struct IPPacket *p;
 
-       if (session.debug == SESSION_DEBUG_HIGH) {
+       if (session.debug >= SESSION_DEBUG_HIGH) {
                printf("In AllocateIPPacket: %s...\n", str);
        }
 
@@ -470,7 +475,7 @@ AllocateIPPacket(int ip_optlen, int tcp_optlen, int datalen, char *str)
                Quit(ERR_MEM_ALLOC);
        }
 
-       if (session.debug == SESSION_DEBUG_HIGH) {
+       if (session.debug >= SESSION_DEBUG_HIGH) {
                printf("Out of AllocateIPPacket: %s...\n", str);
        }
        return(p);
index 0247dea7f4ddcfa6da917f23f5f4322d90d2d73c..5ca97d85b58cf174f4aeaf096575a73a27ae3903 100644 (file)
@@ -84,7 +84,7 @@ int EstablishSession(uint32 sourceAddress,
   double ts1 = 0, ts2;
   int flag = 1;
        
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In EstablishSession...\n");
   }
 
@@ -295,7 +295,7 @@ int EstablishSession(uint32 sourceAddress,
   free(synPacket->tcp);
   free(synPacket); 
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out of EstablishSession...\n");
   }
 
@@ -320,7 +320,7 @@ int PrepareRequest(char *data, char *filename)
   char deffile[] = DEFAULT_FILENAME;
   
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In PrepareRequest...\n");
   }
 
@@ -353,7 +353,7 @@ int PrepareRequest(char *data, char *filename)
            h4);
   }
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out PrepareRequest...\n");
   }
 
@@ -376,7 +376,7 @@ void SendRequest(char *filename, void (*ackData)(struct IPPacket *p))
   int datalen;
   int ipsz; 
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In SendRequest...\n");
   }
 
@@ -497,7 +497,7 @@ void SendRequest(char *filename, void (*ackData)(struct IPPacket *p))
   free(datapkt->tcp);
   free(datapkt);
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out of SendRequest...\n");
   }
 }
@@ -506,7 +506,7 @@ void SendSessionPacket(struct IPPacket *p,
     uint16 ip_len, uint8  tcp_flags, uint16 ip_optlen, uint16 optlen,
     uint8  iptos)
 {
-       if (session.debug == SESSION_DEBUG_HIGH) {
+       if (session.debug >= SESSION_DEBUG_HIGH) {
            printf("In SendSessionPacket...\n");
        }
        WriteIPPacket(p,
@@ -527,7 +527,7 @@ void SendSessionPacket(struct IPPacket *p,
          ip_optlen, /* ip options len */
          optlen);   /* tcp options len */
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out of SendSessionPacket...\n");
   }
 
@@ -543,7 +543,7 @@ void SendICMPReply(struct IPPacket *p)
   struct IpHeader *ip = p->ip;
   struct TcpHeader *tcp = p->tcp;
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In SendICMPReply...\n");
   }
 
@@ -613,7 +613,7 @@ void SendICMPReply(struct IPPacket *p)
 
   SendICMPPkt(icmp_pkt, sizeof(struct ICMPUnreachableErrorPacket));
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out of SendICMPReply...\n");
   }
 
@@ -625,7 +625,7 @@ void SendPkt(struct IPPacket *p, uint16 ip_len, int ip_optlen,
        struct sockaddr_in sockAddr;
        char *assembled_pkt;
 
-       if (session.debug == SESSION_DEBUG_HIGH) {
+       if (session.debug >= SESSION_DEBUG_HIGH) {
                printf("In SendPkt...\n");
        }
        /*  Assemble contiguos packet to be sent */
@@ -669,7 +669,7 @@ void SendPkt(struct IPPacket *p, uint16 ip_len, int ip_optlen,
 
   free(assembled_pkt);
 
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("Out SendPkt...\n");
   }
 
@@ -707,7 +707,7 @@ void rcvData (void (*ackData)(struct IPPacket *p))
   char *read_packet;
   double startTime = GetTime () ;
   
-  if (session.debug == SESSION_DEBUG_HIGH) {
+  if (session.debug >= SESSION_DEBUG_HIGH) {
     printf("In rcvData...\n");
   }
 
index 4153babbbfd16fcfd622c60040b2ac71d1979a62..bff32967fe4f46716584994d62ecf1aebf60312c 100644 (file)
@@ -143,6 +143,7 @@ struct TcpSession {
   /* For MidBoxTTL test */
   int curr_ttl;
 
+  int dont_send_reset;
 };
 
 //void SendSessionPacket(struct IPPacket *packet, 
index 2ba19e5b7d2aa3b7ebcceb77b6f446e55b8d2e81..2cdb4057c623387304a212295b4d69ec7ca8d33f 100644 (file)
@@ -59,6 +59,9 @@ void SendReset()
   struct IPPacket *p;
   int i;
 
+  if (session.dont_send_reset)
+         return;
+
   if ((p = (struct IPPacket *)calloc(1, sizeof(struct IPPacket))) == NULL) {
     perror("ERROR: Could not allocate RST packet:") ;
     Quit(ERR_MEM_ALLOC) ; 
index 511810c66a3585140f8b3eb0c63ce89f7bb2359a..1de7d6724d918536a536c39d7c462eb6a7bb1ae8 100755 (executable)
                                WARNING_CFLAGS = (
                                        "$(inherited)",
                                        "-Wno-deprecated-declarations",
+                                       "-Wno-address-of-packed-member",
                                );
                        };
                        name = "Ignore Me";
                                WARNING_CFLAGS = (
                                        "$(inherited)",
                                        "-Wno-deprecated-declarations",
+                                       "-Wno-address-of-packed-member",
                                );
                        };
                        name = Debug;
                                WARNING_CFLAGS = (
                                        "$(inherited)",
                                        "-Wno-deprecated-declarations",
+                                       "-Wno-address-of-packed-member",
                                );
                        };
                        name = Release;
                        buildSettings = {
                                CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
                                CLANG_CXX_LIBRARY = "libc++";
-                               CLANG_ENABLE_MODULES = YES;
                                CLANG_ENABLE_OBJC_ARC = YES;
                                CLANG_WARN_BOOL_CONVERSION = YES;
                                CLANG_WARN_CONSTANT_CONVERSION = YES;
                        buildSettings = {
                                CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
                                CLANG_CXX_LIBRARY = "libc++";
-                               CLANG_ENABLE_MODULES = YES;
                                CLANG_ENABLE_OBJC_ARC = YES;
                                CLANG_WARN_BOOL_CONVERSION = YES;
                                CLANG_WARN_CONSTANT_CONVERSION = YES;
                        buildSettings = {
                                CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
                                CLANG_CXX_LIBRARY = "libc++";
-                               CLANG_ENABLE_MODULES = YES;
                                CLANG_ENABLE_OBJC_ARC = YES;
                                CLANG_WARN_BOOL_CONVERSION = YES;
                                CLANG_WARN_CONSTANT_CONVERSION = YES;