|
@@ -219,7 +219,6 @@ static int rarp(void);
|
219
|
219
|
#else
|
220
|
220
|
static int bootp(void);
|
221
|
221
|
#endif
|
222
|
|
-static unsigned short tcpudpchksum(struct iphdr *ip);
|
223
|
222
|
|
224
|
223
|
|
225
|
224
|
/*
|
|
@@ -320,9 +319,6 @@ static int nic_load ( struct type_dev *type_dev,
|
320
|
319
|
char *kernel;
|
321
|
320
|
|
322
|
321
|
/* Now use TFTP to load file */
|
323
|
|
-#ifdef DOWNLOAD_PROTO_NFS
|
324
|
|
- rpc_init();
|
325
|
|
-#endif
|
326
|
322
|
kernel = KERNEL_BUF[0] == '\0' ?
|
327
|
323
|
#ifdef DEFAULT_BOOTFILE
|
328
|
324
|
DEFAULT_BOOTFILE
|
|
@@ -529,29 +525,6 @@ void build_udp_hdr(unsigned long destip,
|
529
|
525
|
udp->chksum = 0xffff;
|
530
|
526
|
}
|
531
|
527
|
|
532
|
|
-#ifdef DOWNLOAD_PROTO_HTTP
|
533
|
|
-void build_tcp_hdr(unsigned long destip, unsigned int srcsock,
|
534
|
|
- unsigned int destsock, long send_seq, long recv_seq,
|
535
|
|
- int window, int flags, int ttl, int len, const void *buf)
|
536
|
|
-{
|
537
|
|
- struct iphdr *ip;
|
538
|
|
- struct tcphdr *tcp;
|
539
|
|
- ip = (struct iphdr *)buf;
|
540
|
|
- build_ip_hdr(destip, ttl, IP_TCP, 0, len, buf);
|
541
|
|
- tcp = (struct tcphdr *)(ip + 1);
|
542
|
|
- tcp->src = htons(srcsock);
|
543
|
|
- tcp->dst = htons(destsock);
|
544
|
|
- tcp->seq = htonl(send_seq);
|
545
|
|
- tcp->ack = htonl(recv_seq);
|
546
|
|
- tcp->ctrl = htons(flags + (5 << 12)); /* No TCP options */
|
547
|
|
- tcp->window = htons(window);
|
548
|
|
- tcp->chksum = 0;
|
549
|
|
- if ((tcp->chksum = tcpudpchksum(ip)) == 0)
|
550
|
|
- tcp->chksum = 0xffff;
|
551
|
|
-}
|
552
|
|
-#endif
|
553
|
|
-
|
554
|
|
-
|
555
|
528
|
/**************************************************************************
|
556
|
529
|
UDP_TRANSMIT - Send an UDP datagram
|
557
|
530
|
**************************************************************************/
|
|
@@ -562,37 +535,6 @@ int udp_transmit(unsigned long destip, unsigned int srcsock,
|
562
|
535
|
return ip_transmit(len, buf);
|
563
|
536
|
}
|
564
|
537
|
|
565
|
|
-/**************************************************************************
|
566
|
|
-TCP_TRANSMIT - Send a TCP packet
|
567
|
|
-**************************************************************************/
|
568
|
|
-#ifdef DOWNLOAD_PROTO_HTTP
|
569
|
|
-int tcp_transmit(unsigned long destip, unsigned int srcsock,
|
570
|
|
- unsigned int destsock, long send_seq, long recv_seq,
|
571
|
|
- int window, int flags, int len, const void *buf)
|
572
|
|
-{
|
573
|
|
- build_tcp_hdr(destip, srcsock, destsock, send_seq, recv_seq,
|
574
|
|
- window, flags, 60, len, buf);
|
575
|
|
- return ip_transmit(len, buf);
|
576
|
|
-}
|
577
|
|
-
|
578
|
|
-int tcp_reset(struct iphdr *ip) {
|
579
|
|
- struct tcphdr *tcp = (struct tcphdr *)(ip + 1);
|
580
|
|
- char buf[sizeof(struct iphdr) + sizeof(struct tcphdr)];
|
581
|
|
-
|
582
|
|
- if (!(tcp->ctrl & htons(RST))) {
|
583
|
|
- long seq = ntohl(tcp->seq) + ntohs(ip->len) -
|
584
|
|
- sizeof(struct iphdr) -
|
585
|
|
- ((ntohs(tcp->ctrl) >> 10) & 0x3C);
|
586
|
|
- if (tcp->ctrl & htons(SYN|FIN))
|
587
|
|
- seq++;
|
588
|
|
- return tcp_transmit(ntohl(ip->src.s_addr),
|
589
|
|
- ntohs(tcp->dst), ntohs(tcp->src),
|
590
|
|
- tcp->ctrl&htons(ACK) ? ntohl(tcp->ack) : 0,
|
591
|
|
- seq, TCP_MAX_WINDOW, RST, sizeof(buf), buf);
|
592
|
|
- }
|
593
|
|
- return (1);
|
594
|
|
-}
|
595
|
|
-#endif
|
596
|
538
|
|
597
|
539
|
/**************************************************************************
|
598
|
540
|
QDRAIN - clear the nic's receive queue
|
|
@@ -616,9 +558,6 @@ void rx_qdrain(void)
|
616
|
558
|
await_reply(await_qdrain, 0, NULL, 0);
|
617
|
559
|
}
|
618
|
560
|
|
619
|
|
-#ifdef DOWNLOAD_PROTO_TFTP
|
620
|
|
-#endif /* DOWNLOAD_PROTO_TFTP */
|
621
|
|
-
|
622
|
561
|
#ifdef RARP_NOT_BOOTP
|
623
|
562
|
/**************************************************************************
|
624
|
563
|
RARP - Get my IP address and load information
|
|
@@ -876,7 +815,7 @@ static int bootp(void)
|
876
|
815
|
}
|
877
|
816
|
#endif /* RARP_NOT_BOOTP */
|
878
|
817
|
|
879
|
|
-static uint16_t tcpudpchksum(struct iphdr *ip)
|
|
818
|
+uint16_t tcpudpchksum(struct iphdr *ip)
|
880
|
819
|
{
|
881
|
820
|
struct udp_pseudo_hdr pseudo;
|
882
|
821
|
uint16_t checksum;
|
|
@@ -1034,239 +973,6 @@ void join_group(int slot, unsigned long group)
|
1034
|
973
|
|
1035
|
974
|
#include "proto_eth_slow.c"
|
1036
|
975
|
|
1037
|
|
-/**************************************************************************
|
1038
|
|
-TCP - Simple-minded TCP stack. Can only send data once and then
|
1039
|
|
- receive the response. The algorithm for computing window
|
1040
|
|
- sizes and delaying ack's is currently broken, and thus
|
1041
|
|
- disabled. Performance would probably improve a little, if
|
1042
|
|
- this gets fixed. FIXME
|
1043
|
|
-**************************************************************************/
|
1044
|
|
-#ifdef DOWNLOAD_PROTO_HTTP
|
1045
|
|
-static int await_tcp(int ival, void *ptr, unsigned short ptype __unused,
|
1046
|
|
- struct iphdr *ip, struct udphdr *udp __unused,
|
1047
|
|
- struct tcphdr *tcp)
|
1048
|
|
-{
|
1049
|
|
- if (!tcp) {
|
1050
|
|
- return 0;
|
1051
|
|
- }
|
1052
|
|
- if (arptable[ARP_CLIENT].ipaddr.s_addr != ip->dest.s_addr)
|
1053
|
|
- return 0;
|
1054
|
|
- if (ntohs(tcp->dst) != ival) {
|
1055
|
|
- tcp_reset(ip);
|
1056
|
|
- return 0;
|
1057
|
|
- }
|
1058
|
|
- *(void **)ptr = tcp;
|
1059
|
|
- return 1;
|
1060
|
|
-}
|
1061
|
|
-
|
1062
|
|
-int tcp_transaction(unsigned long destip, unsigned int destsock, void *ptr,
|
1063
|
|
- int (*send)(int len, void *buf, void *ptr),
|
1064
|
|
- int (*recv)(int len, const void *buf, void *ptr)) {
|
1065
|
|
- static uint16_t srcsock = 0;
|
1066
|
|
- int rc = 1;
|
1067
|
|
- long send_seq = currticks();
|
1068
|
|
- long recv_seq = 0;
|
1069
|
|
- int can_send = 0;
|
1070
|
|
- int sent_all = 0;
|
1071
|
|
- struct iphdr *ip;
|
1072
|
|
- struct tcphdr *tcp;
|
1073
|
|
- int ctrl = SYN;
|
1074
|
|
- char buf[128]; /* Small outgoing buffer */
|
1075
|
|
- long payload;
|
1076
|
|
- int header_size;
|
1077
|
|
- int window = 3*TCP_MIN_WINDOW;
|
1078
|
|
- long last_ack = 0;
|
1079
|
|
- long last_sent = 0;
|
1080
|
|
- long rtt = 0;
|
1081
|
|
- long srtt = 0;
|
1082
|
|
- long rto = TCP_INITIAL_TIMEOUT;
|
1083
|
|
- int retry = TCP_MAX_TIMEOUT/TCP_INITIAL_TIMEOUT;
|
1084
|
|
- enum { CLOSED, SYN_RCVD, ESTABLISHED,
|
1085
|
|
- FIN_WAIT_1, FIN_WAIT_2 } state = CLOSED;
|
1086
|
|
-
|
1087
|
|
- if (!srcsock) {
|
1088
|
|
- srcsock = currticks();
|
1089
|
|
- }
|
1090
|
|
- if (++srcsock < 1024)
|
1091
|
|
- srcsock += 1024;
|
1092
|
|
-
|
1093
|
|
- await_reply(await_qdrain, 0, NULL, 0);
|
1094
|
|
-
|
1095
|
|
- send_data:
|
1096
|
|
- if (ctrl & ACK)
|
1097
|
|
- last_ack = recv_seq;
|
1098
|
|
- if (!tcp_transmit(destip, srcsock, destsock, send_seq,
|
1099
|
|
- recv_seq, window, ctrl,
|
1100
|
|
- sizeof(struct iphdr) + sizeof(struct tcphdr)+
|
1101
|
|
- can_send, buf)) {
|
1102
|
|
- return (0);
|
1103
|
|
- }
|
1104
|
|
- last_sent = currticks();
|
1105
|
|
-
|
1106
|
|
- recv_data:
|
1107
|
|
- if (!await_reply(await_tcp, srcsock, &tcp,
|
1108
|
|
- (state == ESTABLISHED && !can_send)
|
1109
|
|
- ? TCP_MAX_TIMEOUT : rto)) {
|
1110
|
|
- if (state == ESTABLISHED) {
|
1111
|
|
- close:
|
1112
|
|
- ctrl = FIN|ACK;
|
1113
|
|
- state = FIN_WAIT_1;
|
1114
|
|
- rc = 0;
|
1115
|
|
- goto send_data;
|
1116
|
|
- }
|
1117
|
|
-
|
1118
|
|
- if (state == FIN_WAIT_1 || state == FIN_WAIT_2)
|
1119
|
|
- return (rc);
|
1120
|
|
-
|
1121
|
|
- if (--retry <= 0) {
|
1122
|
|
- /* time out */
|
1123
|
|
- if (state == SYN_RCVD) {
|
1124
|
|
- tcp_transmit(destip, srcsock, destsock,
|
1125
|
|
- send_seq, 0, window, RST,
|
1126
|
|
- sizeof(struct iphdr) +
|
1127
|
|
- sizeof(struct tcphdr), buf);
|
1128
|
|
- }
|
1129
|
|
- return (0);
|
1130
|
|
- }
|
1131
|
|
- /* retransmit */
|
1132
|
|
- goto send_data;
|
1133
|
|
- }
|
1134
|
|
- got_data:
|
1135
|
|
- retry = TCP_MAX_RETRY;
|
1136
|
|
-
|
1137
|
|
- if (tcp->ctrl & htons(ACK) ) {
|
1138
|
|
- char *data;
|
1139
|
|
- int syn_ack, consumed;
|
1140
|
|
-
|
1141
|
|
- if (state == FIN_WAIT_1 || state == FIN_WAIT_2) {
|
1142
|
|
- state = FIN_WAIT_2;
|
1143
|
|
- ctrl = ACK;
|
1144
|
|
- goto consume_data;
|
1145
|
|
- }
|
1146
|
|
- syn_ack = state == CLOSED || state == SYN_RCVD;
|
1147
|
|
- consumed = ntohl(tcp->ack) - send_seq - syn_ack;
|
1148
|
|
- if (consumed < 0 || consumed > can_send) {
|
1149
|
|
- tcp_reset((struct iphdr *)&nic.packet[ETH_HLEN]);
|
1150
|
|
- goto recv_data;
|
1151
|
|
- }
|
1152
|
|
-
|
1153
|
|
- rtt = currticks() - last_sent;
|
1154
|
|
- srtt = !srtt ? rtt : (srtt*4 + rtt)/5;
|
1155
|
|
- rto = srtt + srtt/2;
|
1156
|
|
- if (rto < TCP_MIN_TIMEOUT)
|
1157
|
|
- rto = TCP_MIN_TIMEOUT;
|
1158
|
|
- else if (rto > TCP_MAX_TIMEOUT)
|
1159
|
|
- rto = TCP_MAX_TIMEOUT;
|
1160
|
|
-
|
1161
|
|
- can_send -= consumed;
|
1162
|
|
- send_seq += consumed + syn_ack;
|
1163
|
|
- data = buf + sizeof(struct iphdr) + sizeof(struct tcphdr);
|
1164
|
|
- if (can_send) {
|
1165
|
|
- memmove(data, data + consumed, can_send);
|
1166
|
|
- }
|
1167
|
|
- if (!sent_all) {
|
1168
|
|
- int more_data;
|
1169
|
|
- data += can_send;
|
1170
|
|
- more_data = buf + sizeof(buf) - data;
|
1171
|
|
- if (more_data > 0) {
|
1172
|
|
- more_data = send(more_data, data, ptr);
|
1173
|
|
- can_send += more_data;
|
1174
|
|
- }
|
1175
|
|
- sent_all = !more_data;
|
1176
|
|
- }
|
1177
|
|
- if (state == SYN_RCVD) {
|
1178
|
|
- state = ESTABLISHED;
|
1179
|
|
- ctrl = PSH|ACK;
|
1180
|
|
- goto consume_data;
|
1181
|
|
- }
|
1182
|
|
- if (tcp->ctrl & htons(RST))
|
1183
|
|
- return (0);
|
1184
|
|
- } else if (tcp->ctrl & htons(RST)) {
|
1185
|
|
- if (state == CLOSED)
|
1186
|
|
- goto recv_data;
|
1187
|
|
- return (0);
|
1188
|
|
- }
|
1189
|
|
-
|
1190
|
|
- consume_data:
|
1191
|
|
- ip = (struct iphdr *)&nic.packet[ETH_HLEN];
|
1192
|
|
- header_size = sizeof(struct iphdr) + ((ntohs(tcp->ctrl)>>10)&0x3C);
|
1193
|
|
- payload = ntohs(ip->len) - header_size;
|
1194
|
|
- if (payload > 0 && state == ESTABLISHED) {
|
1195
|
|
- int old_bytes = recv_seq - (long)ntohl(tcp->seq);
|
1196
|
|
- if (old_bytes >= 0 && payload - old_bytes > 0) {
|
1197
|
|
- recv_seq += payload - old_bytes;
|
1198
|
|
- if (state != FIN_WAIT_1 && state != FIN_WAIT_2 &&
|
1199
|
|
- !recv(payload - old_bytes,
|
1200
|
|
- &nic.packet[ETH_HLEN+header_size+old_bytes],
|
1201
|
|
- ptr)) {
|
1202
|
|
- goto close;
|
1203
|
|
- }
|
1204
|
|
- if ((state == ESTABLISHED || state == SYN_RCVD) &&
|
1205
|
|
- !(tcp->ctrl & htons(FIN))) {
|
1206
|
|
- int in_window = window - 2*TCP_MIN_WINDOW >
|
1207
|
|
- recv_seq - last_ack;
|
1208
|
|
- ctrl = can_send ? PSH|ACK : ACK;
|
1209
|
|
- if (!can_send && in_window) {
|
1210
|
|
-/* Window scaling is broken right now, just fall back to acknowledging every */
|
1211
|
|
-/* packet immediately and unconditionally. FIXME */ /***/
|
1212
|
|
-/* if (await_reply(await_tcp, srcsock,
|
1213
|
|
- &tcp, rto))
|
1214
|
|
- goto got_data;
|
1215
|
|
- else */
|
1216
|
|
- goto send_data;
|
1217
|
|
- }
|
1218
|
|
- if (!in_window) {
|
1219
|
|
- window += TCP_MIN_WINDOW;
|
1220
|
|
- if (window > TCP_MAX_WINDOW)
|
1221
|
|
- window = TCP_MAX_WINDOW;
|
1222
|
|
- }
|
1223
|
|
- goto send_data;
|
1224
|
|
- }
|
1225
|
|
- } else {
|
1226
|
|
- /* saw old data again, must have lost packets */
|
1227
|
|
- window /= 2;
|
1228
|
|
- if (window < 2*TCP_MIN_WINDOW)
|
1229
|
|
- window = 2*TCP_MIN_WINDOW;
|
1230
|
|
- }
|
1231
|
|
- }
|
1232
|
|
-
|
1233
|
|
- if (tcp->ctrl & htons(FIN)) {
|
1234
|
|
- if (state == ESTABLISHED) {
|
1235
|
|
- ctrl = FIN|ACK;
|
1236
|
|
- } else if (state == FIN_WAIT_1 || state == FIN_WAIT_2) {
|
1237
|
|
- ctrl = ACK;
|
1238
|
|
- } else {
|
1239
|
|
- ctrl = RST;
|
1240
|
|
- }
|
1241
|
|
- return (tcp_transmit(destip, srcsock, destsock,
|
1242
|
|
- send_seq, recv_seq + 1, window, ctrl,
|
1243
|
|
- sizeof(struct iphdr) +
|
1244
|
|
- sizeof(struct tcphdr), buf) &&
|
1245
|
|
- (state == ESTABLISHED ||
|
1246
|
|
- state == FIN_WAIT_1 || state == FIN_WAIT_2) &&
|
1247
|
|
- !can_send);
|
1248
|
|
- }
|
1249
|
|
-
|
1250
|
|
- if (state == CLOSED) {
|
1251
|
|
- if (tcp->ctrl & htons(SYN)) {
|
1252
|
|
- recv_seq = ntohl(tcp->seq) + 1;
|
1253
|
|
- if (!(tcp->ctrl & htons(ACK))) {
|
1254
|
|
- state = SYN_RCVD;
|
1255
|
|
- ctrl = SYN|ACK|PSH;
|
1256
|
|
- goto send_data;
|
1257
|
|
- } else {
|
1258
|
|
- state = ESTABLISHED;
|
1259
|
|
- ctrl = PSH|ACK;
|
1260
|
|
- }
|
1261
|
|
- }
|
1262
|
|
- }
|
1263
|
|
-
|
1264
|
|
- if (can_send || payload) {
|
1265
|
|
- goto send_data;
|
1266
|
|
- }
|
1267
|
|
- goto recv_data;
|
1268
|
|
-}
|
1269
|
|
-#endif
|
1270
|
976
|
|
1271
|
977
|
/**************************************************************************
|
1272
|
978
|
AWAIT_REPLY - Wait until we get a response for our request
|
|
@@ -1361,7 +1067,6 @@ int await_reply(reply_t reply, int ival, void *ptr, long timeout)
|
1361
|
1067
|
}
|
1362
|
1068
|
}
|
1363
|
1069
|
tcp = 0;
|
1364
|
|
-#ifdef DOWNLOAD_PROTO_HTTP
|
1365
|
1070
|
if (ip && (ip->protocol == IP_TCP) &&
|
1366
|
1071
|
(nic.packetlen >=
|
1367
|
1072
|
ETH_HLEN + sizeof(struct iphdr) + sizeof(struct tcphdr))){
|
|
@@ -1377,7 +1082,6 @@ int await_reply(reply_t reply, int ival, void *ptr, long timeout)
|
1377
|
1082
|
}
|
1378
|
1083
|
|
1379
|
1084
|
}
|
1380
|
|
-#endif
|
1381
|
1085
|
result = reply(ival, ptr, ptype, ip, udp, tcp);
|
1382
|
1086
|
if (result > 0) {
|
1383
|
1087
|
return result;
|