Rev 4344 | Rev 4366 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4344 | Rev 4347 | ||
---|---|---|---|
Line 81... | Line 81... | ||
81 | proc TCP_process_input |
81 | proc TCP_process_input |
Line 82... | Line 82... | ||
82 | 82 | ||
83 | locals |
83 | locals |
84 | dataoffset dd ? |
84 | dataoffset dd ? |
- | 85 | timestamp dd ? |
|
85 | timestamp dd ? |
86 | temp_bits db ? |
Line 86... | Line 87... | ||
86 | endl |
87 | endl |
87 | 88 | ||
88 | xor esi, esi |
89 | xor esi, esi |
Line 216... | Line 217... | ||
216 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: socket locked\n" |
217 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: socket locked\n" |
Line 217... | Line 218... | ||
217 | 218 | ||
218 | ;--------------------------- |
219 | ;--------------------------- |
Line 219... | Line 220... | ||
219 | ; disable all temporary bits |
220 | ; disable all temporary bits |
Line 220... | Line 221... | ||
220 | 221 | ||
221 | mov [ebx + TCP_SOCKET.temp_bits], 0 |
222 | mov [temp_bits], 0 |
Line 222... | Line 223... | ||
222 | 223 | ||
Line 250... | Line 251... | ||
250 | test eax, eax |
251 | test eax, eax |
251 | jz .drop_no_socket |
252 | jz .drop_no_socket |
Line 252... | Line 253... | ||
252 | 253 | ||
Line 253... | Line 254... | ||
253 | mov ebx, eax |
254 | mov ebx, eax |
Line 254... | Line 255... | ||
254 | 255 | ||
255 | mov [ebx + TCP_SOCKET.temp_bits], TCP_BIT_DROPSOCKET ;;; FIXME: should we take over bits from previous socket? |
256 | mov [temp_bits], TCP_BIT_DROPSOCKET |
Line 256... | Line 257... | ||
256 | 257 | ||
Line 376... | Line 377... | ||
376 | lodsd |
377 | lodsd |
377 | bswap eax |
378 | bswap eax |
378 | mov [ebx + TCP_SOCKET.ts_val], eax |
379 | mov [ebx + TCP_SOCKET.ts_val], eax |
379 | lodsd ; timestamp echo reply |
380 | lodsd ; timestamp echo reply |
380 | mov [ebx + TCP_SOCKET.ts_ecr], eax |
381 | mov [ebx + TCP_SOCKET.ts_ecr], eax |
381 | or [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP |
382 | or [temp_bits], TCP_BIT_TIMESTAMP |
Line 382... | Line 383... | ||
382 | 383 | ||
Line 383... | Line 384... | ||
383 | ; Since we have a timestamp, lets do the paws test right away! |
384 | ; Since we have a timestamp, lets do the paws test right away! |
384 | 385 | ||
Line 481... | Line 482... | ||
481 | call SOCKET_ring_free |
482 | call SOCKET_ring_free |
482 | popa |
483 | popa |
Line 483... | Line 484... | ||
483 | 484 | ||
Line 484... | Line 485... | ||
484 | ; Update RTT estimators |
485 | ; Update RTT estimators |
485 | 486 | ||
486 | test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP |
487 | test [temp_bits], TCP_BIT_TIMESTAMP |
487 | jz .no_timestamp_rtt |
488 | jz .no_timestamp_rtt |
488 | mov eax, [timestamp] |
489 | mov eax, [timestamp] |
489 | sub eax, [ebx + TCP_SOCKET.ts_ecr] |
490 | sub eax, [ebx + TCP_SOCKET.ts_ecr] |
Line 711... | Line 712... | ||
711 | 712 | ||
712 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
713 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
713 | ;;; TODO: update stats |
714 | ;;; TODO: update stats |
714 | .dont_drop_all: |
715 | .dont_drop_all: |
715 | ;;; TODO: update stats |
716 | ;;; TODO: update stats |
716 | DEBUGF 1, "Trimming %u bytes from the right of the window\n" |
717 | DEBUGF DEBUG_NETWORK_VERBOSE, "Trimming %u bytes from the right of the window\n" |
717 | sub ecx, eax ; remove data from the right side of window (decrease data length) |
718 | sub ecx, eax ; remove data from the right side of window (decrease data length) |
718 | and [ebx + TCP_SOCKET.t_flags], not (TH_PUSH or TH_FIN) |
719 | and [edx + TCP_header.Flags], not (TH_PUSH or TH_FIN) |
Line 719... | Line 720... | ||
719 | .no_excess_data: |
720 | .no_excess_data: |
720 | 721 | ||
Line 721... | Line 722... | ||
721 | ;----------------- |
722 | ;----------------- |
722 | ; Record timestamp |
723 | ; Record timestamp |
723 | 724 | ||
724 | ; If last ACK falls within this segments sequence numbers, record its timestamp |
725 | ; If last ACK falls within this segments sequence numbers, record its timestamp |
725 | test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP |
726 | test [temp_bits], TCP_BIT_TIMESTAMP |
726 | jz .no_timestamp |
727 | jz .no_timestamp |
727 | mov eax, [ebx + TCP_SOCKET.last_ack_sent] |
728 | mov eax, [ebx + TCP_SOCKET.last_ack_sent] |
Line 1002... | Line 1003... | ||
1002 | ;;; TODO: update stats |
1003 | ;;; TODO: update stats |
Line 1003... | Line 1004... | ||
1003 | 1004 | ||
Line 1004... | Line 1005... | ||
1004 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: acceptable ACK for %u bytes\n", edi |
1005 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: acceptable ACK for %u bytes\n", edi |
1005 | 1006 | ||
Line 1006... | Line 1007... | ||
1006 | ;------------------------------------------ |
1007 | ;------------------------------------------ |
Line 1007... | Line 1008... | ||
1007 | ; RTT measurements and retransmission timer (912-926) |
1008 | ; RTT measurements and retransmission timer |
1008 | 1009 | ||
1009 | ; If we have a timestamp, update smoothed RTT |
1010 | ; If we have a timestamp, update smoothed RTT |
1010 | 1011 | ||
1011 | test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP |
1012 | test [temp_bits], TCP_BIT_TIMESTAMP |
1012 | jz .timestamp_not_present |
1013 | jz .timestamp_not_present |
Line 1037... | Line 1038... | ||
1037 | 1038 | ||
1038 | mov eax, [ebx + TCP_SOCKET.SND_MAX] |
1039 | mov eax, [ebx + TCP_SOCKET.SND_MAX] |
1039 | cmp eax, [edx + TCP_header.AckNumber] |
1040 | cmp eax, [edx + TCP_header.AckNumber] |
1040 | jne .more_data |
1041 | jne .more_data |
1041 | and [ebx + TCP_SOCKET.timer_flags], not timer_flag_retransmission |
1042 | and [ebx + TCP_SOCKET.timer_flags], not timer_flag_retransmission |
1042 | or [ebx + TCP_SOCKET.temp_bits], TCP_BIT_NEEDOUTPUT |
1043 | or [temp_bits], TCP_BIT_NEEDOUTPUT |
1043 | jmp .no_restart |
1044 | jmp .no_restart |
1044 | .more_data: |
1045 | .more_data: |
1045 | test [ebx + TCP_SOCKET.timer_flags], timer_flag_persist |
1046 | test [ebx + TCP_SOCKET.timer_flags], timer_flag_persist |
Line 1239... | Line 1240... | ||
1239 | 1240 | ||
1240 | TCP_sendseqinit ebx |
1241 | TCP_sendseqinit ebx |
Line 1241... | Line 1242... | ||
1241 | TCP_rcvseqinit ebx |
1242 | TCP_rcvseqinit ebx |
1242 | 1243 | ||
1243 | mov [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED |
1244 | mov [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED |
1244 | mov [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
1245 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
Line 1245... | Line 1246... | ||
1245 | mov [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval ;;;; macro |
1246 | mov [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval ;;;; macro |
1246 | or [ebx + TCP_SOCKET.timer_flags], timer_flag_keepalive |
1247 | or [ebx + TCP_SOCKET.timer_flags], timer_flag_keepalive |
Line 1247... | Line 1248... | ||
1247 | 1248 | ||
1248 | lea eax, [ebx + STREAM_SOCKET.snd] |
1249 | lea eax, [ebx + STREAM_SOCKET.snd] |
Line 1249... | Line 1250... | ||
1249 | call SOCKET_ring_create |
1250 | call SOCKET_ring_create |
Line 1250... | Line 1251... | ||
1250 | 1251 | ||
1251 | lea eax, [ebx + STREAM_SOCKET.rcv] |
1252 | lea eax, [ebx + STREAM_SOCKET.rcv] |
1252 | call SOCKET_ring_create |
1253 | call SOCKET_ring_create |
1253 | 1254 | ||
Line 1429... | Line 1430... | ||
1429 | pop [ebx + TCP_SOCKET.SND_WL1] |
1430 | pop [ebx + TCP_SOCKET.SND_WL1] |
Line 1430... | Line 1431... | ||
1430 | 1431 | ||
1431 | push [edx + TCP_header.AckNumber] |
1432 | push [edx + TCP_header.AckNumber] |
Line 1432... | Line 1433... | ||
1432 | pop [ebx + TCP_SOCKET.SND_WL2] |
1433 | pop [ebx + TCP_SOCKET.SND_WL2] |
Line 1433... | Line 1434... | ||
1433 | 1434 | ||
Line 1434... | Line 1435... | ||
1434 | or [ebx + TCP_SOCKET.temp_bits], TCP_BIT_NEEDOUTPUT |
1435 | or [temp_bits], TCP_BIT_NEEDOUTPUT |
1435 | 1436 | ||
Line 1519... | Line 1520... | ||
1519 | call TCP_reassemble |
1520 | call TCP_reassemble |
Line 1520... | Line 1521... | ||
1520 | 1521 | ||
1521 | ; Generate ACK immediately, to let the other end know that a segment was received out of order, |
1522 | ; Generate ACK immediately, to let the other end know that a segment was received out of order, |
1522 | ; and to tell it what sequence number is expected. This aids the fast-retransmit algorithm. |
1523 | ; and to tell it what sequence number is expected. This aids the fast-retransmit algorithm. |
1523 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
- | |
1524 | 1524 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
|
Line 1525... | Line 1525... | ||
1525 | .data_done: |
1525 | .data_done: |
1526 | 1526 | ||
Line 1538... | Line 1538... | ||
1538 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: First FIN for this connection\n" |
1538 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: First FIN for this connection\n" |
Line 1539... | Line 1539... | ||
1539 | 1539 | ||
1540 | mov eax, ebx |
1540 | mov eax, ebx |
Line 1541... | Line 1541... | ||
1541 | call SOCKET_cant_recv_more |
1541 | call SOCKET_cant_recv_more |
1542 | 1542 | ||
Line 1543... | Line 1543... | ||
1543 | mov [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
1543 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
1544 | inc [ebx + TCP_SOCKET.RCV_NXT] |
1544 | inc [ebx + TCP_SOCKET.RCV_NXT] |
1545 | 1545 | ||
Line 1560... | Line 1560... | ||
1560 | dd .final_processing ; TCPS_LAST_ACK |
1560 | dd .final_processing ; TCPS_LAST_ACK |
1561 | dd .fin_wait2 ; TCPS_FIN_WAIT_2 |
1561 | dd .fin_wait2 ; TCPS_FIN_WAIT_2 |
1562 | dd .fin_timed ; TCPS_TIMED_WAIT |
1562 | dd .fin_timed ; TCPS_TIMED_WAIT |
Line 1563... | Line 1563... | ||
1563 | 1563 | ||
1564 | .fin_syn_est: |
- | |
1565 | 1564 | .fin_syn_est: |
|
1566 | mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSE_WAIT |
1565 | mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSE_WAIT |
Line 1567... | Line 1566... | ||
1567 | jmp .final_processing |
1566 | jmp .final_processing |
1568 | - | ||
1569 | .fin_wait1: |
1567 | |
1570 | 1568 | .fin_wait1: |
|
Line 1571... | Line 1569... | ||
1571 | mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSING |
1569 | mov [ebx + TCP_SOCKET.t_state], TCPS_CLOSING |
1572 | jmp .final_processing |
- | |
1573 | 1570 | jmp .final_processing |
|
1574 | .fin_wait2: |
1571 | |
1575 | 1572 | .fin_wait2: |
|
1576 | mov [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT |
- | |
1577 | mov eax, ebx |
- | |
1578 | call TCP_cancel_timers |
1573 | mov [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT |
1579 | mov [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL |
- | |
Line 1580... | Line 1574... | ||
1580 | or [ebx + TCP_SOCKET.timer_flags], timer_flag_wait |
1574 | mov eax, ebx |
1581 | call SOCKET_is_disconnected |
1575 | call TCP_cancel_timers |
1582 | jmp .final_processing |
1576 | call SOCKET_is_disconnected |
- | 1577 | ||
- | 1578 | .fin_timed: |
|
- | 1579 | mov [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL |
|
- | 1580 | or [ebx + TCP_SOCKET.timer_flags], timer_flag_wait |
|
- | 1581 | ||
- | 1582 | ;----------------- |
|
- | 1583 | ; Final processing |
|
- | 1584 | ||
- | 1585 | .final_processing: |
|
- | 1586 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Final processing\n" |
|
- | 1587 | ||
- | 1588 | push ebx |
|
- | 1589 | lea ecx, [ebx + SOCKET.mutex] |
|
- | 1590 | call mutex_unlock |
|
- | 1591 | pop eax |
|
- | 1592 | ||
- | 1593 | test [temp_bits], TCP_BIT_NEEDOUTPUT |
|
- | 1594 | jnz .need_output |
|
- | 1595 | ||
- | 1596 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW |
|
- | 1597 | jz .dumpit |
|
- | 1598 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n" |
|
- | 1599 | ||
- | 1600 | .need_output: |
|
- | 1601 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n" |
|
- | 1602 | call TCP_output |
|
- | 1603 | ||
1583 | 1604 | .dumpit: |
|
- | 1605 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n" |
|
- | 1606 | ||
- | 1607 | call NET_packet_free |
|
- | 1608 | jmp .loop |
|
Line 1584... | Line 1609... | ||
1584 | .fin_timed: |
1609 | |
1585 | mov [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL |
1610 | |
Line 1619... | Line 1644... | ||
1619 | 1644 | ||
1620 | test [edx + TCP_header.Flags], TH_SYN |
1645 | test [edx + TCP_header.Flags], TH_SYN |
1621 | jnz .respond_syn |
1646 | jnz .respond_syn |
Line 1622... | Line -... | ||
1622 | jmp .dumpit |
- | |
1623 | - | ||
1624 | ;----------------- |
- | |
1625 | ; Final processing |
- | |
1626 | - | ||
1627 | .final_processing: |
- | |
1628 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Final processing\n" |
- | |
1629 | - | ||
1630 | push ebx |
- | |
1631 | lea ecx, [ebx + SOCKET.mutex] |
- | |
1632 | call mutex_unlock |
- | |
1633 | pop eax |
- | |
1634 | - | ||
1635 | test [eax + TCP_SOCKET.temp_bits], TCP_BIT_NEEDOUTPUT |
- | |
1636 | jnz .need_output |
- | |
1637 | - | ||
1638 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW |
- | |
1639 | jz .dumpit |
- | |
1640 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n" |
- | |
1641 | - | ||
1642 | .need_output: |
- | |
1643 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n" |
- | |
1644 | call TCP_output |
- | |
1645 | - | ||
1646 | .dumpit: |
- | |
1647 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n" |
- | |
1648 | - | ||
1649 | call NET_packet_free |
- | |
1650 | jmp .loop |
1647 | jmp .dumpit |
1651 | 1648 | ||
Line 1652... | Line 1649... | ||
1652 | ;--------- |
1649 | ;--------- |
1653 | ; Respond |
1650 | ; Respond |
Line 1707... | Line 1704... | ||
1707 | lea ecx, [ebx + SOCKET.mutex] |
1704 | lea ecx, [ebx + SOCKET.mutex] |
1708 | call mutex_unlock |
1705 | call mutex_unlock |
1709 | popa |
1706 | popa |
Line 1710... | Line 1707... | ||
1710 | 1707 | ||
1711 | .destroy_new_socket: |
1708 | .destroy_new_socket: |
1712 | test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_DROPSOCKET |
1709 | test [temp_bits], TCP_BIT_DROPSOCKET |
Line 1713... | Line 1710... | ||
1713 | jz .drop_no_socket |
1710 | jz .drop_no_socket |
1714 | 1711 |