mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
tcp: bugfixes
This commit is contained in:
+18
-8
@@ -816,12 +816,19 @@ static uint32_t getsendmss(tcpheader_t *tcpheader, tcb_t *tcb) {
|
|||||||
break;
|
break;
|
||||||
} else if (*options == 1) { // nop
|
} else if (*options == 1) { // nop
|
||||||
++options;
|
++options;
|
||||||
|
--optionslength;
|
||||||
continue;
|
continue;
|
||||||
} else if (*options == OPTIONS_MSS_KIND) {
|
} else if (*options == OPTIONS_MSS_KIND) {
|
||||||
options += 2;
|
if (optionslength < OPTIONS_MSS_LEN || options[1] != OPTIONS_MSS_LEN)
|
||||||
newsendmss = be_to_cpu_w(*(uint16_t *)options);
|
break;
|
||||||
|
|
||||||
|
newsendmss = be_to_cpu_w(*(uint16_t *)(options + 2));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
if (optionslength < 2 || options[1] < 2 || options[1] > optionslength)
|
||||||
|
break;
|
||||||
|
|
||||||
|
optionslength -= options[1];
|
||||||
options += options[1];
|
options += options[1];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -970,11 +977,11 @@ __attribute__((noreturn)) static void tcp_worker() {
|
|||||||
newtcb->sndmss = mtu;
|
newtcb->sndmss = mtu;
|
||||||
newtcb->sndmss = getsendmss(tcpheader, newtcb);
|
newtcb->sndmss = getsendmss(tcpheader, newtcb);
|
||||||
newtcb->iss = getrand32();
|
newtcb->iss = getrand32();
|
||||||
newtcb->rcvwindow = 0;
|
|
||||||
newtcb->sndnext = newtcb->iss;
|
newtcb->sndnext = newtcb->iss;
|
||||||
|
newtcb->sndwindow = tcpheader->window;
|
||||||
newtcb->rcvmss = MSS_LIMIT(mtu);
|
newtcb->rcvmss = MSS_LIMIT(mtu);
|
||||||
newtcb->rcvnext = tcpheader->seq + 1;
|
newtcb->rcvnext = tcpheader->seq + 1;
|
||||||
newtcb->rcvwindow = tcpheader->window;
|
newtcb->rcvwindow = TCB_RINGBUFFER_SIZE;
|
||||||
newtcb->rcvurgent = 0;
|
newtcb->rcvurgent = 0;
|
||||||
newtcb->irs = tcpheader->seq;
|
newtcb->irs = tcpheader->seq;
|
||||||
|
|
||||||
@@ -1001,8 +1008,8 @@ __attribute__((noreturn)) static void tcp_worker() {
|
|||||||
.mss = newtcb->rcvmss
|
.mss = newtcb->rcvmss
|
||||||
};
|
};
|
||||||
|
|
||||||
tcb->retransmitpacketlen = sizeof(tcpheader_t) + sizeof(synoptions_t);
|
newtcb->retransmitpacketlen = sizeof(tcpheader_t) + sizeof(synoptions_t);
|
||||||
tcp_createheader(newtcb->retransmitbuffer, newtcb, tcb->retransmitpacketlen, &synoptions, sizeof(synoptions_t), CONTROL_SYN | CONTROL_ACK, 0);
|
tcp_createheader(newtcb->retransmitbuffer, newtcb, newtcb->retransmitpacketlen, &synoptions, sizeof(synoptions_t), CONTROL_SYN | CONTROL_ACK, 0);
|
||||||
|
|
||||||
// ugly hack but whatever, we only add options here and in connect.
|
// ugly hack but whatever, we only add options here and in connect.
|
||||||
synoptions_t *fixptr = (synoptions_t *)((uintptr_t)newtcb->retransmitbuffer + sizeof(tcpheader_t));
|
synoptions_t *fixptr = (synoptions_t *)((uintptr_t)newtcb->retransmitbuffer + sizeof(tcpheader_t));
|
||||||
@@ -1010,9 +1017,10 @@ __attribute__((noreturn)) static void tcp_worker() {
|
|||||||
|
|
||||||
newtcb->sndunack = newtcb->sndnext;
|
newtcb->sndunack = newtcb->sndnext;
|
||||||
newtcb->sndnext += 1;
|
newtcb->sndnext += 1;
|
||||||
if (tcp_sendpacket(newtcb->retransmitbuffer, tcb->retransmitpacketlen, key.peer, self)) {
|
if (tcp_sendpacket(newtcb->retransmitbuffer, newtcb->retransmitpacketlen, key.peer, self)) {
|
||||||
// unset the tcb and wait for a SYN retransmission
|
// unset the tcb and wait for a SYN retransmission
|
||||||
tcp_reset(tcb);
|
newtcb->state = TCB_STATE_ABORT;
|
||||||
|
tcbset(newtcb, &key, true);
|
||||||
TCB_RELEASE(newtcb);
|
TCB_RELEASE(newtcb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1628,6 +1636,8 @@ static int tcp_listen(socket_t *socket, int backlog) {
|
|||||||
TCB_HOLD(tcb); // for the release later
|
TCB_HOLD(tcb); // for the release later
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MUTEX_ACQUIRE(&tcb->mutex);
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
if (tcb->state != TCB_STATE_CLOSED) {
|
if (tcb->state != TCB_STATE_CLOSED) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
|
|||||||
Reference in New Issue
Block a user