Rev 3389 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3389 | Rev 3406 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 16... | Line 16... | ||
16 | 16 | ||
Line 17... | Line 17... | ||
17 | $Revision: 3389 $ |
17 | $Revision: 3406 $ |
18 | 18 | ||
19 | ;----------------------------------------------------------------- |
19 | ;----------------------------------------------------------------- |
20 | ; |
20 | ; |
Line 71... | Line 71... | ||
71 | 71 | ||
Line -... | Line 72... | ||
- | 72 | ret |
|
72 | ret |
73 | |
73 | 74 | ||
Line 74... | Line 75... | ||
74 | 75 | ||
75 | 76 | ||
76 | align 4 |
77 | align 4 |
77 | TCP_process_input: |
78 | TCP_process_input: |
Line 78... | Line 79... | ||
78 | 79 | ||
79 | xor esi, esi |
80 | xor esi, esi |
80 | mov ecx, MANUAL_DESTROY |
81 | mov ecx, MANUAL_DESTROY |
Line -... | Line 82... | ||
- | 82 | call create_event |
|
81 | call create_event |
83 | mov [TCP_input_event], eax |
Line 82... | Line -... | ||
82 | mov [TCP_input_event], eax |
- | |
83 | 84 | ||
84 | .loop: |
85 | .wait: |
Line 85... | Line 86... | ||
85 | mov eax, [TCP_input_event] |
86 | mov eax, [TCP_input_event] |
86 | call wait_event |
87 | call wait_event |
87 | 88 | ||
88 | get_from_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .loop |
89 | .loop: |
Line 89... | Line -... | ||
89 | - | ||
90 | push .loop |
- | |
91 | push [esi + TCP_queue_entry.buffer_size] |
- | |
92 | push [esi + TCP_queue_entry.buffer_ptr] |
- | |
93 | - | ||
94 | mov ebx, [esi + TCP_queue_entry.device_ptr] |
- | |
95 | mov ecx, [esi + TCP_queue_entry.segment_size] |
- | |
96 | mov edi, [esi + TCP_queue_entry.ip_ptr] |
- | |
97 | mov esi, [esi + TCP_queue_entry.segment_ptr] ; change esi last |
- | |
98 | - | ||
99 | ;----------------------------------------------------------------- |
- | |
100 | ; |
- | |
101 | ; IN: [esp] = ptr to buffer |
- | |
102 | ; [esp+4] = timestamp when segment was received |
90 | get_from_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .wait |
Line -... | Line 91... | ||
- | 91 | ||
- | 92 | push [esi + TCP_queue_entry.timestamp] |
|
- | 93 | push [esi + TCP_queue_entry.buffer_ptr] |
|
- | 94 | ||
- | 95 | mov ebx, [esi + TCP_queue_entry.device_ptr] |
|
103 | ; ebx = ptr to device struct |
96 | mov ecx, [esi + TCP_queue_entry.segment_size] |
104 | ; ecx = segment size |
97 | mov edi, [esi + TCP_queue_entry.ip_ptr] ; ptr to ipv4 source address, followed by ipv4 destination address |
105 | ; esi = ptr to TCP segment |
98 | mov esi, [esi + TCP_queue_entry.segment_ptr] ; change esi last |
Line 106... | Line 99... | ||
106 | ; edi = ptr to ipv4 source address, followed by ipv4 dest address |
99 | |
Line 169... | Line 162... | ||
169 | 162 | ||
170 | cmp [ebx + TCP_SOCKET.LocalPort], si |
163 | cmp [ebx + TCP_SOCKET.LocalPort], si |
Line 171... | Line 164... | ||
171 | jne .socket_loop |
164 | jne .socket_loop |
172 | 165 | ||
173 | mov eax, [ebx + IP_SOCKET.RemoteIP] |
166 | mov eax, [ebx + IP_SOCKET.RemoteIP] |
174 | cmp eax, [edi] ; Ipv4 source addres |
167 | cmp eax, [edi] ; Ipv4 source address |
175 | je @f |
168 | je @f |
176 | test eax, eax |
169 | test eax, eax |
Line 578... | Line 571... | ||
578 | je .SYN_SENT |
571 | je .SYN_SENT |
Line 579... | Line 572... | ||
579 | 572 | ||
580 | ;---------------------------- |
573 | ;---------------------------- |
Line 581... | Line 574... | ||
581 | ; trim any data not in window |
574 | ; trim any data not in window |
Line 582... | Line 575... | ||
582 | 575 | ||
583 | ; check for duplicate data at beginning of segment |
576 | ; check for duplicate data at beginning of segment (635) |
584 | 577 | ||
Line 604... | Line 597... | ||
604 | and [edx + TCP_header.Flags], not (TH_URG) |
597 | and [edx + TCP_header.Flags], not (TH_URG) |
605 | .dup_syn: |
598 | .dup_syn: |
606 | dec eax |
599 | dec eax |
607 | .no_dup_syn: |
600 | .no_dup_syn: |
Line 608... | Line 601... | ||
608 | 601 | ||
609 | ; Check for entire duplicate segment |
602 | ; Check for entire duplicate segment (646) |
610 | cmp eax, ecx ; eax holds number of bytes to drop, ecx is data size |
603 | cmp eax, ecx ; eax holds number of bytes to drop, ecx is data size |
611 | jb .duplicate |
604 | jb .duplicate |
612 | jnz @f |
605 | jnz @f |
613 | test [edx + TCP_header.Flags], TH_FIN |
606 | test [edx + TCP_header.Flags], TH_FIN |
Line 618... | Line 611... | ||
618 | ; At this point the FIN must be out of sequence or a duplicate, drop it |
611 | ; At this point the FIN must be out of sequence or a duplicate, drop it |
619 | and [edx + TCP_header.Flags], not TH_FIN |
612 | and [edx + TCP_header.Flags], not TH_FIN |
Line 620... | Line 613... | ||
620 | 613 | ||
621 | ; send an ACK and resynchronize and drop any data. |
614 | ; send an ACK and resynchronize and drop any data. |
- | 615 | ; But keep on processing for RST or ACK |
|
622 | ; But keep on processing for RST or ACK |
616 | DEBUGF 1, "616\n" |
623 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
617 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
624 | mov eax, ecx |
618 | mov eax, ecx |
Line 625... | Line 619... | ||
625 | ;TODO: update stats |
619 | ;TODO: update stats |
Line 637... | Line 631... | ||
637 | and [edx + TCP_header.Flags], not (TH_URG) |
631 | and [edx + TCP_header.Flags], not (TH_URG) |
638 | mov [edx + TCP_header.UrgentPointer], 0 |
632 | mov [edx + TCP_header.UrgentPointer], 0 |
639 | @@: |
633 | @@: |
Line 640... | Line 634... | ||
640 | 634 | ||
641 | ;-------------------------------------------------- |
635 | ;-------------------------------------------------- |
Line 642... | Line 636... | ||
642 | ; Handle data that arrives after process terminates |
636 | ; Handle data that arrives after process terminates (687) |
643 | 637 | ||
644 | .no_duplicate: |
638 | .no_duplicate: |
645 | cmp [ebx + SOCKET.PID], 0 |
639 | cmp [ebx + SOCKET.PID], 0 |
Line 691... | Line 685... | ||
691 | jne .drop_after_ack |
685 | jne .drop_after_ack |
692 | mov eax, [edx + TCP_header.SequenceNumber] |
686 | mov eax, [edx + TCP_header.SequenceNumber] |
693 | cmp eax, [ebx + TCP_SOCKET.RCV_NXT] |
687 | cmp eax, [ebx + TCP_SOCKET.RCV_NXT] |
694 | jne .drop_after_ack |
688 | jne .drop_after_ack |
Line -... | Line 689... | ||
- | 689 | ||
695 | 690 | DEBUGF 1, "690\n" |
|
696 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
691 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
697 | ;;; TODO: update stats |
692 | ;;; TODO: update stats |
698 | jmp .no_excess_data |
693 | jmp .no_excess_data |
699 | .dont_drop_all: |
694 | .dont_drop_all: |
Line 702... | Line 697... | ||
702 | 697 | ||
703 | sub ecx, eax |
698 | sub ecx, eax |
704 | and [ebx + TCP_SOCKET.t_flags], not (TH_PUSH or TH_FIN) |
699 | and [ebx + TCP_SOCKET.t_flags], not (TH_PUSH or TH_FIN) |
Line 705... | Line -... | ||
705 | .no_excess_data: |
- | |
706 | - | ||
707 | ;--------------------- FIXME ------------------- |
- | |
708 | - | ||
709 | pusha |
- | |
710 | movzx esi, [edx + TCP_header.DataOffset] |
- | |
711 | add esi, edx |
- | |
712 | lea eax, [ebx + STREAM_SOCKET.rcv] |
- | |
713 | call SOCKET_ring_write ; Add the data to the socket buffer |
- | |
714 | add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied |
- | |
715 | popa |
- | |
716 | - | ||
717 | ;--------------------- FIXME -------------------- |
700 | .no_excess_data: |
718 | 701 | ||
Line 719... | Line 702... | ||
719 | ;----------------- |
702 | ;----------------- |
720 | ; Record timestamp (737-746) |
703 | ; Record timestamp (737-746) |
Line 1445... | Line 1428... | ||
1445 | 1428 | ||
1446 | test ecx, ecx |
1429 | test ecx, ecx |
1447 | jnz .final_processing |
1430 | jnz .final_processing |
Line -... | Line 1431... | ||
- | 1431 | @@: |
|
- | 1432 | ||
- | 1433 | ||
- | 1434 | ; The segment is in order? |
|
- | 1435 | mov eax, [edx + TCP_header.SequenceNumber] |
|
- | 1436 | cmp eax, [ebx + TCP_SOCKET.RCV_NXT] |
|
- | 1437 | jne .out_of_order |
|
- | 1438 | ||
- | 1439 | ; The reassembly queue is empty? |
|
- | 1440 | cmp [ebx + TCP_SOCKET.seg_next], 0 |
|
- | 1441 | jne .out_of_order |
|
- | 1442 | ||
- | 1443 | ; The connection is established? |
|
- | 1444 | cmp [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED |
|
- | 1445 | jne .out_of_order |
|
- | 1446 | ||
- | 1447 | ; Ok, lets do this.. Set delayed ACK flag and copy data into socket buffer |
|
- | 1448 | or [ebx + TCP_SOCKET.t_flags], TF_DELACK |
|
- | 1449 | ||
- | 1450 | pusha |
|
- | 1451 | movzx esi, [edx + TCP_header.DataOffset] |
|
- | 1452 | add esi, edx |
|
- | 1453 | lea eax, [ebx + STREAM_SOCKET.rcv] |
|
- | 1454 | call SOCKET_ring_write ; Add the data to the socket buffer |
|
- | 1455 | add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied |
|
- | 1456 | popa |
|
- | 1457 | ||
- | 1458 | ; Wake up the sleeping process |
|
- | 1459 | mov eax, ebx |
|
- | 1460 | call SOCKET_notify |
|
- | 1461 | ||
- | 1462 | jmp .data_done |
|
- | 1463 | ||
- | 1464 | .out_of_order: |
|
- | 1465 | ||
1448 | @@: |
1466 | ; Uh-oh, some data is out of order, lets call TCP reassemble for help |
- | 1467 | ||
- | 1468 | call TCP_reassemble |
|
- | 1469 | ||
- | 1470 | DEBUGF 1, "1470\n" |
|
- | 1471 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
|
Line 1449... | Line 1472... | ||
1449 | 1472 | ||
1450 | ; call TCP_reassemble ;;; TODO |
1473 | .data_done: |
Line 1451... | Line 1474... | ||
1451 | 1474 | ||
Line 1569... | Line 1592... | ||
1569 | .dumpit: |
1592 | .dumpit: |
1570 | DEBUGF 1,"TCP_input: dumping\n" |
1593 | DEBUGF 1,"TCP_input: dumping\n" |
Line 1571... | Line 1594... | ||
1571 | 1594 | ||
1572 | call kernel_free |
1595 | call kernel_free |
1573 | add esp, 4 |
1596 | add esp, 4 |
Line 1574... | Line 1597... | ||
1574 | ret |
1597 | jmp .loop |
1575 | 1598 | ||
Line 1576... | Line 1599... | ||
1576 | ;--------- |
1599 | ;--------- |
Line 1635... | Line 1658... | ||
1635 | .drop_no_socket: |
1658 | .drop_no_socket: |
1636 | DEBUGF 1,"TCP_input: Drop (no socket)\n" |
1659 | DEBUGF 1,"TCP_input: Drop (no socket)\n" |
Line 1637... | Line 1660... | ||
1637 | 1660 | ||
1638 | call kernel_free |
1661 | call kernel_free |
1639 | add esp, 4 |
1662 | add esp, 4 |