Deleted Added
full compact
iptests.c (31183) iptests.c (34739)
1/*
2 * Copyright (C) 1993-1997 by Darren Reed.
3 *
4 * Redistribution and use in source and binary forms are permitted
5 * provided that this notice is preserved and due credit is given
6 * to the original author and the contributors.
7 */
8#if !defined(lint)
9static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
1/*
2 * Copyright (C) 1993-1997 by Darren Reed.
3 *
4 * Redistribution and use in source and binary forms are permitted
5 * provided that this notice is preserved and due credit is given
6 * to the original author and the contributors.
7 */
8#if !defined(lint)
9static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
10static const char rcsid[] = "@(#)$Id: iptests.c,v 2.0.2.13 1997/10/23 11:42:45 darrenr Exp $";
10static const char rcsid[] = "@(#)$Id: iptests.c,v 2.0.2.13.2.1 1997/11/28 03:37:10 darrenr Exp $";
11#endif
12#include <stdio.h>
13#include <unistd.h>
14#include <stdlib.h>
15#include <string.h>
16#include <sys/types.h>
17#include <sys/time.h>
18#include <sys/param.h>

--- 868 unchanged lines hidden (view full) ---

887 t->th_off = 0;
888 t->th_sport = 1;
889 t->th_dport = 1;
890 t->th_win = 4096;
891 t->th_urp = 0;
892 t->th_sum = 0;
893 t->th_seq = 1;
894 t->th_ack = 0;
11#endif
12#include <stdio.h>
13#include <unistd.h>
14#include <stdlib.h>
15#include <string.h>
16#include <sys/types.h>
17#include <sys/time.h>
18#include <sys/param.h>

--- 868 unchanged lines hidden (view full) ---

887 t->th_off = 0;
888 t->th_sport = 1;
889 t->th_dport = 1;
890 t->th_win = 4096;
891 t->th_urp = 0;
892 t->th_sum = 0;
893 t->th_seq = 1;
894 t->th_ack = 0;
895 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
895 nfd = initdevice(dev, t->th_sport, 1);
896
897 if (!ptest || (ptest == 1)) {
898 /*
899 * Test 1: flags variations, 0 - 3f
900 */
901 t->th_off = sizeof(*t) >> 2;
902 printf("5.1 Test TCP flag combinations\n");

--- 113 unchanged lines hidden (view full) ---

1016
1017 printf("5.4.3 TCP win = 65535\n");
1018 t->th_win = 0xffff;
1019 (void) send_tcp(nfd, mtu, ip, gwip);
1020 fflush(stdout);
1021 PAUSE();
1022 }
1023
896 nfd = initdevice(dev, t->th_sport, 1);
897
898 if (!ptest || (ptest == 1)) {
899 /*
900 * Test 1: flags variations, 0 - 3f
901 */
902 t->th_off = sizeof(*t) >> 2;
903 printf("5.1 Test TCP flag combinations\n");

--- 113 unchanged lines hidden (view full) ---

1017
1018 printf("5.4.3 TCP win = 65535\n");
1019 t->th_win = 0xffff;
1020 (void) send_tcp(nfd, mtu, ip, gwip);
1021 fflush(stdout);
1022 PAUSE();
1023 }
1024
1024#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && !defined(__sgi)
1025#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && \
1026 !defined(__sgi)
1025 {
1027 {
1026 struct tcpcb *t, tcb;
1028 struct tcpcb *tcbp, tcb;
1027 struct tcpiphdr ti;
1028 struct sockaddr_in sin;
1029 int fd, slen;
1030
1031 bzero((char *)&sin, sizeof(sin));
1032
1033 for (i = 1; i < 63; i++) {
1034 fd = socket(AF_INET, SOCK_STREAM, 0);
1029 struct tcpiphdr ti;
1030 struct sockaddr_in sin;
1031 int fd, slen;
1032
1033 bzero((char *)&sin, sizeof(sin));
1034
1035 for (i = 1; i < 63; i++) {
1036 fd = socket(AF_INET, SOCK_STREAM, 0);
1037 bzero((char *)&sin, sizeof(sin));
1035 sin.sin_addr.s_addr = ip->ip_dst.s_addr;
1036 sin.sin_port = htons(i);
1038 sin.sin_addr.s_addr = ip->ip_dst.s_addr;
1039 sin.sin_port = htons(i);
1040 sin.sin_family = AF_INET;
1037 if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin)))
1038 break;
1041 if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin)))
1042 break;
1043 close(fd);
1039 }
1040
1041 if (i == 63) {
1042 printf("Couldn't open a TCP socket between ports 1 and 63\n");
1043 printf("to host %s for test 5 and 6 - skipping.\n",
1044 inet_ntoa(ip->ip_dst));
1045 goto skip_five_and_six;
1046 }
1047
1048 bcopy((char *)ip, (char *)&ti, sizeof(*ip));
1044 }
1045
1046 if (i == 63) {
1047 printf("Couldn't open a TCP socket between ports 1 and 63\n");
1048 printf("to host %s for test 5 and 6 - skipping.\n",
1049 inet_ntoa(ip->ip_dst));
1050 goto skip_five_and_six;
1051 }
1052
1053 bcopy((char *)ip, (char *)&ti, sizeof(*ip));
1049 ti.ti_dport = i;
1054 t->th_dport = htons(i);
1050 slen = sizeof(sin);
1051 if (!getsockname(fd, (struct sockaddr *)&sin, &slen))
1055 slen = sizeof(sin);
1056 if (!getsockname(fd, (struct sockaddr *)&sin, &slen))
1052 ti.ti_sport = sin.sin_port;
1053 if (!(t = find_tcp(fd, &ti))) {
1057 t->th_sport = sin.sin_port;
1058 if (!(tcbp = find_tcp(fd, &ti))) {
1054 printf("Can't find PCB\n");
1055 goto skip_five_and_six;
1056 }
1059 printf("Can't find PCB\n");
1060 goto skip_five_and_six;
1061 }
1057 KMCPY(&tcb, t, sizeof(tcb));
1062 KMCPY(&tcb, tcbp, sizeof(tcb));
1058 ti.ti_win = tcb.rcv_adv;
1059 ti.ti_seq = tcb.snd_nxt - 1;
1060 ti.ti_ack = tcb.rcv_nxt;
1061
1062 if (!ptest || (ptest == 5)) {
1063 /*
1064 * Test 5: urp
1065 */
1063 ti.ti_win = tcb.rcv_adv;
1064 ti.ti_seq = tcb.snd_nxt - 1;
1065 ti.ti_ack = tcb.rcv_nxt;
1066
1067 if (!ptest || (ptest == 5)) {
1068 /*
1069 * Test 5: urp
1070 */
1066 printf("5.1 TCP Urgent pointer\n");
1067 ti.ti_urp = 1;
1071 t->th_flags = TH_ACK|TH_URG;
1072 printf("5.5.1 TCP Urgent pointer, sport %hu dport %hu\n",
1073 ntohs(t->th_sport), ntohs(t->th_dport));
1074 t->th_urp = htons(1);
1068 (void) send_tcp(nfd, mtu, ip, gwip);
1069 PAUSE();
1075 (void) send_tcp(nfd, mtu, ip, gwip);
1076 PAUSE();
1070 ti.ti_urp = 0x7fff;
1077
1078 t->th_seq = tcb.snd_nxt;
1079 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1;
1080 t->th_urp = htons(0x7fff);
1071 (void) send_tcp(nfd, mtu, ip, gwip);
1072 PAUSE();
1081 (void) send_tcp(nfd, mtu, ip, gwip);
1082 PAUSE();
1073 ti.ti_urp = 0x8000;
1083 t->th_urp = htons(0x8000);
1074 (void) send_tcp(nfd, mtu, ip, gwip);
1075 PAUSE();
1084 (void) send_tcp(nfd, mtu, ip, gwip);
1085 PAUSE();
1076 ti.ti_urp = 0xffff;
1086 t->th_urp = htons(0xffff);
1077 (void) send_tcp(nfd, mtu, ip, gwip);
1078 PAUSE();
1087 (void) send_tcp(nfd, mtu, ip, gwip);
1088 PAUSE();
1089 t->th_urp = htons(0);
1090 t->th_flags &= ~TH_URG;
1091 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
1079 }
1080
1081 if (!ptest || (ptest == 6)) {
1082 /*
1083 * Test 6: data offset, off = 0, off is inside, off is outside
1084 */
1092 }
1093
1094 if (!ptest || (ptest == 6)) {
1095 /*
1096 * Test 6: data offset, off = 0, off is inside, off is outside
1097 */
1085 printf("6.1 TCP off = 0-15, len = 40\n");
1086 for (i = 0; i < 16; i++) {
1098 t->th_flags = TH_ACK;
1099 printf("5.6.1 TCP off = 1-15, len = 40\n");
1100 for (i = 1; i < 16; i++) {
1087 ti.ti_off = ntohs(i);
1088 (void) send_tcp(nfd, mtu, ip, gwip);
1089 printf("%d\r", i);
1090 fflush(stdout);
1091 PAUSE();
1092 }
1093 putchar('\n');
1101 ti.ti_off = ntohs(i);
1102 (void) send_tcp(nfd, mtu, ip, gwip);
1103 printf("%d\r", i);
1104 fflush(stdout);
1105 PAUSE();
1106 }
1107 putchar('\n');
1108 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
1094 }
1095
1096 (void) close(fd);
1097 }
1098skip_five_and_six:
1099#endif
1100 t->th_seq = 1;
1101 t->th_ack = 1;
1109 }
1110
1111 (void) close(fd);
1112 }
1113skip_five_and_six:
1114#endif
1115 t->th_seq = 1;
1116 t->th_ack = 1;
1117 t->th_off = 0;
1102
1103 if (!ptest || (ptest == 7)) {
1118
1119 if (!ptest || (ptest == 7)) {
1104 t->th_off = 0;
1105 t->th_flags = TH_SYN;
1106 /*
1107 * Test 7: sport = 0, sport = 1, sport = 32767
1108 * sport = 32768, sport = 65535
1109 */
1110 printf("5.7.1 TCP sport = 0\n");
1111 t->th_sport = 0;
1112 (void) send_tcp(nfd, mtu, ip, gwip);

--- 22 unchanged lines hidden (view full) ---

1135 t->th_sport = 65535;
1136 (void) send_tcp(nfd, mtu, ip, gwip);
1137 fflush(stdout);
1138 PAUSE();
1139 }
1140
1141 if (!ptest || (ptest == 8)) {
1142 t->th_sport = 1;
1120 t->th_flags = TH_SYN;
1121 /*
1122 * Test 7: sport = 0, sport = 1, sport = 32767
1123 * sport = 32768, sport = 65535
1124 */
1125 printf("5.7.1 TCP sport = 0\n");
1126 t->th_sport = 0;
1127 (void) send_tcp(nfd, mtu, ip, gwip);

--- 22 unchanged lines hidden (view full) ---

1150 t->th_sport = 65535;
1151 (void) send_tcp(nfd, mtu, ip, gwip);
1152 fflush(stdout);
1153 PAUSE();
1154 }
1155
1156 if (!ptest || (ptest == 8)) {
1157 t->th_sport = 1;
1158 t->th_flags = TH_SYN;
1143 /*
1144 * Test 8: dport = 0, dport = 1, dport = 32767
1145 * dport = 32768, dport = 65535
1146 */
1147 printf("5.8.1 TCP dport = 0\n");
1148 t->th_dport = 0;
1149 (void) send_tcp(nfd, mtu, ip, gwip);
1150 fflush(stdout);

--- 18 unchanged lines hidden (view full) ---

1169 PAUSE();
1170
1171 printf("5.8.5 TCP dport = 65535\n");
1172 t->th_dport = 65535;
1173 (void) send_tcp(nfd, mtu, ip, gwip);
1174 fflush(stdout);
1175 PAUSE();
1176 }
1159 /*
1160 * Test 8: dport = 0, dport = 1, dport = 32767
1161 * dport = 32768, dport = 65535
1162 */
1163 printf("5.8.1 TCP dport = 0\n");
1164 t->th_dport = 0;
1165 (void) send_tcp(nfd, mtu, ip, gwip);
1166 fflush(stdout);

--- 18 unchanged lines hidden (view full) ---

1185 PAUSE();
1186
1187 printf("5.8.5 TCP dport = 65535\n");
1188 t->th_dport = 65535;
1189 (void) send_tcp(nfd, mtu, ip, gwip);
1190 fflush(stdout);
1191 PAUSE();
1192 }
1193
1194 /* LAND attack - self connect, so make src & dst ip/port the same */
1195 if (!ptest || (ptest == 9)) {
1196 printf("5.9 TCP LAND attack. sport = 25, dport = 25\n");
1197 /* chose SMTP port 25 */
1198 t->th_sport = htons(25);
1199 t->th_dport = htons(25);
1200 t->th_flags = TH_SYN;
1201 ip->ip_src = ip->ip_dst;
1202 (void) send_tcp(nfd, mtu, ip, gwip);
1203 fflush(stdout);
1204 PAUSE();
1205 }
1206
1177 /* TCP options header checking */
1178 /* 0 length options, etc */
1179}
1180
1181
1182/* Perform test 6 (exhaust mbuf test) */
1183
1184void ip_test6(dev, mtu, ip, gwip, ptest)

--- 18 unchanged lines hidden (view full) ---

1203 u->uh_dport = 9;
1204 u->uh_sum = 0;
1205
1206 nfd = initdevice(dev, u->uh_sport, 1);
1207 u->uh_sport = htons(u->uh_sport);
1208 u->uh_dport = htons(u->uh_dport);
1209 u->uh_ulen = 7168;
1210
1207 /* TCP options header checking */
1208 /* 0 length options, etc */
1209}
1210
1211
1212/* Perform test 6 (exhaust mbuf test) */
1213
1214void ip_test6(dev, mtu, ip, gwip, ptest)

--- 18 unchanged lines hidden (view full) ---

1233 u->uh_dport = 9;
1234 u->uh_sum = 0;
1235
1236 nfd = initdevice(dev, u->uh_sport, 1);
1237 u->uh_sport = htons(u->uh_sport);
1238 u->uh_dport = htons(u->uh_dport);
1239 u->uh_ulen = 7168;
1240
1241 printf("6. Exhaustive mbuf test.\n");
1242 printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n");
1243 printf(" Total of around 8,900 packets\n");
1211 for (i = 0; i < 128; i++) {
1212 /*
1213 * First send the entire packet in 768 byte chunks.
1214 */
1215 ip->ip_len = sizeof(*ip) + 768 + sizeof(*u);
1216 ip->ip_hl = sizeof(*ip) >> 2;
1217 ip->ip_off = IP_MF;
1218 (void) send_ip(nfd, 1500, ip, gwip, 1);

--- 89 unchanged lines hidden ---
1244 for (i = 0; i < 128; i++) {
1245 /*
1246 * First send the entire packet in 768 byte chunks.
1247 */
1248 ip->ip_len = sizeof(*ip) + 768 + sizeof(*u);
1249 ip->ip_hl = sizeof(*ip) >> 2;
1250 ip->ip_off = IP_MF;
1251 (void) send_ip(nfd, 1500, ip, gwip, 1);

--- 89 unchanged lines hidden ---