From 755a8d69d575c678ea4570e9f9ef0d076b0f1557 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 1 Dec 2016 22:33:08 +0000 Subject: [PATCH] network_cmds-511.50.3.tar.gz --- .gitignore | 8 + cfilutil/cfilutil.c | 23 +- ecnprobe/capture.c | 2 +- ecnprobe/ecn.c | 170 ++++++++++++++ ecnprobe/ecn.h | 1 + ecnprobe/ecn_probe.c | 307 +++++++++++++++---------- ecnprobe/inet.c | 17 +- ecnprobe/session.c | 26 +-- ecnprobe/session.h | 1 + ecnprobe/support.c | 3 + network_cmds.xcodeproj/project.pbxproj | 6 +- 11 files changed, 413 insertions(+), 151 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..009fb98 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +*.xcodeproj/project.xcworkspace +*.xcodeproj/xcuserdata +.svn +build +*~.m +*~.c +*~.h diff --git a/cfilutil/cfilutil.c b/cfilutil/cfilutil.c index 546604c..4aaa719 100644 --- a/cfilutil/cfilutil.c +++ b/cfilutil/cfilutil.c @@ -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) diff --git a/ecnprobe/capture.c b/ecnprobe/capture.c index 34ed9ec..ff6b6d5 100644 --- a/ecnprobe/capture.c +++ b/ecnprobe/capture.c @@ -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, diff --git a/ecnprobe/ecn.c b/ecnprobe/ecn.c index f09282d..b7dabdf 100644 --- a/ecnprobe/ecn.c +++ b/ecnprobe/ecn.c @@ -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); +} diff --git a/ecnprobe/ecn.h b/ecnprobe/ecn.h index adf8260..5ac582c 100644 --- a/ecnprobe/ecn.h +++ b/ecnprobe/ecn.h @@ -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); diff --git a/ecnprobe/ecn_probe.c b/ecnprobe/ecn_probe.c index 9ff6193..ae00f4a 100644 --- a/ecnprobe/ecn_probe.c +++ b/ecnprobe/ecn_probe.c @@ -79,6 +79,8 @@ void usage(char *name) printf("\t-f \n"); printf("\t-d \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); diff --git a/ecnprobe/inet.c b/ecnprobe/inet.c index 723101a..b145412 100644 --- a/ecnprobe/inet.c +++ b/ecnprobe/inet.c @@ -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); diff --git a/ecnprobe/session.c b/ecnprobe/session.c index 0247dea..5ca97d8 100644 --- a/ecnprobe/session.c +++ b/ecnprobe/session.c @@ -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"); } diff --git a/ecnprobe/session.h b/ecnprobe/session.h index 4153bab..bff3296 100644 --- a/ecnprobe/session.h +++ b/ecnprobe/session.h @@ -143,6 +143,7 @@ struct TcpSession { /* For MidBoxTTL test */ int curr_ttl; + int dont_send_reset; }; //void SendSessionPacket(struct IPPacket *packet, diff --git a/ecnprobe/support.c b/ecnprobe/support.c index 2ba19e5..2cdb405 100644 --- a/ecnprobe/support.c +++ b/ecnprobe/support.c @@ -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) ; diff --git a/network_cmds.xcodeproj/project.pbxproj b/network_cmds.xcodeproj/project.pbxproj index 511810c..1de7d67 100755 --- a/network_cmds.xcodeproj/project.pbxproj +++ b/network_cmds.xcodeproj/project.pbxproj @@ -4077,6 +4077,7 @@ WARNING_CFLAGS = ( "$(inherited)", "-Wno-deprecated-declarations", + "-Wno-address-of-packed-member", ); }; name = "Ignore Me"; @@ -4697,6 +4698,7 @@ WARNING_CFLAGS = ( "$(inherited)", "-Wno-deprecated-declarations", + "-Wno-address-of-packed-member", ); }; name = Debug; @@ -4720,6 +4722,7 @@ WARNING_CFLAGS = ( "$(inherited)", "-Wno-deprecated-declarations", + "-Wno-address-of-packed-member", ); }; name = Release; @@ -5305,7 +5308,6 @@ 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; @@ -5344,7 +5346,6 @@ 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; @@ -5379,7 +5380,6 @@ 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; -- 2.45.2