Rev 2300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1196 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
1514 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; |
1196 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; ARP.INC ;; |
||
7 | ;; ;; |
||
8 | ;; Part of the tcp/ip network stack for KolibriOS ;; |
||
9 | ;; ;; |
||
10 | ;; Based on the work of [Johnny_B] and [smb] ;; |
||
11 | ;; ;; |
||
12 | ;; Written by hidnplayr@kolibrios.org ;; |
||
13 | ;; ;; |
||
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
1529 | hidnplayr | 15 | ;; Version 2, June- 1991 ;; |
1196 | hidnplayr | 16 | ;; ;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1159 | hidnplayr | 18 | |
1206 | hidnplayr | 19 | $Revision: 2301 $ |
1159 | hidnplayr | 20 | |
1529 | hidnplayr | 21 | ARP_NO_ENTRY equ 0 |
22 | ARP_VALID_MAPPING equ 1 |
||
23 | ARP_AWAITING_RESPONSE equ 2 |
||
24 | ARP_RESPONSE_TIMEOUT equ 3 |
||
1159 | hidnplayr | 25 | |
1529 | hidnplayr | 26 | ARP_REQUEST_TTL equ 31 ; 20 s |
27 | ARP_ENTRY_TTL equ 937 ; 600 s |
||
1159 | hidnplayr | 28 | |
1529 | hidnplayr | 29 | ARP_REQ_OPCODE equ 0x0100 ; request |
30 | ARP_REP_OPCODE equ 0x0200 ; reply |
||
1196 | hidnplayr | 31 | |
1529 | hidnplayr | 32 | ARP_TABLE_SIZE equ 20 ; Size of table |
1159 | hidnplayr | 33 | |
34 | struct ARP_ENTRY |
||
35 | .IP dd ? |
||
36 | .MAC dp ? |
||
37 | .Status dw ? |
||
1529 | hidnplayr | 38 | .TTL dw ? |
1159 | hidnplayr | 39 | .size: |
40 | ends |
||
41 | |||
42 | struct ARP_Packet |
||
43 | .HardwareType dw ? |
||
44 | .ProtocolType dw ? |
||
45 | .HardwareSize db ? |
||
46 | .ProtocolSize db ? |
||
47 | .Opcode dw ? |
||
48 | .SenderMAC dp ? |
||
49 | .SenderIP dd ? |
||
50 | .TargetMAC dp ? |
||
51 | .TargetIP dd ? |
||
1529 | hidnplayr | 52 | .size: |
1159 | hidnplayr | 53 | ends |
54 | |||
55 | |||
56 | align 4 |
||
57 | uglobal |
||
58 | |||
59 | NumARP dd ? |
||
1258 | hidnplayr | 60 | |
1529 | hidnplayr | 61 | ARP_table rb ARP_ENTRY.size * ARP_TABLE_SIZE |
1159 | hidnplayr | 62 | |
1529 | hidnplayr | 63 | ARP_PACKETS_TX rd MAX_NET_DEVICES |
64 | ARP_PACKETS_RX rd MAX_NET_DEVICES |
||
1159 | hidnplayr | 65 | |
66 | |||
67 | endg |
||
68 | |||
69 | |||
70 | |||
1196 | hidnplayr | 71 | ;----------------------------------------------------------------- |
72 | ; |
||
73 | ; ARP_init |
||
74 | ; |
||
75 | ; This function resets all ARP variables |
||
76 | ; |
||
77 | ;----------------------------------------------------------------- |
||
1529 | hidnplayr | 78 | macro ARP_init { |
1159 | hidnplayr | 79 | |
80 | xor eax, eax |
||
81 | mov [NumARP], eax |
||
82 | |||
83 | mov edi, ARP_PACKETS_TX |
||
84 | mov ecx, 2*MAX_NET_DEVICES |
||
85 | rep stosd |
||
86 | |||
1529 | hidnplayr | 87 | } |
1159 | hidnplayr | 88 | |
1529 | hidnplayr | 89 | ;--------------------------------------------------------------------------- |
1159 | hidnplayr | 90 | ; |
1529 | hidnplayr | 91 | ; ARP_decrease_entry_ttls |
1159 | hidnplayr | 92 | ; |
1529 | hidnplayr | 93 | ;--------------------------------------------------------------------------- |
1159 | hidnplayr | 94 | |
1529 | hidnplayr | 95 | macro ARP_decrease_entry_ttls { |
1159 | hidnplayr | 96 | |
1529 | hidnplayr | 97 | local .loop |
98 | local .exit |
||
1159 | hidnplayr | 99 | |
1529 | hidnplayr | 100 | ; The TTL field is decremented every second, and is deleted when it reaches 0. |
101 | ; It is refreshed every time a packet is received. |
||
102 | ; If the TTL field is 0xFFFF it is a static entry and is never deleted. |
||
103 | ; The status field can be the following values: |
||
104 | ; 0x0000 entry not used |
||
105 | ; 0x0001 entry holds a valid mapping |
||
106 | ; 0x0002 entry contains an IP address, awaiting ARP response |
||
107 | ; 0x0003 No response received to ARP request. |
||
108 | ; The last status value is provided to allow the network layer to delete |
||
109 | ; a packet that is queued awaiting an ARP response |
||
1159 | hidnplayr | 110 | |
1529 | hidnplayr | 111 | mov ecx, [NumARP] |
112 | test ecx, ecx |
||
113 | jz .exit |
||
1206 | hidnplayr | 114 | |
1529 | hidnplayr | 115 | mov esi, ARP_table |
116 | .loop: |
||
117 | cmp [esi + ARP_ENTRY.TTL], 0xffff ; 0xffff = static entry |
||
118 | je .next |
||
1206 | hidnplayr | 119 | |
1529 | hidnplayr | 120 | dec [esi + ARP_ENTRY.TTL] |
121 | jz .time_out |
||
1159 | hidnplayr | 122 | |
1529 | hidnplayr | 123 | .next: |
1206 | hidnplayr | 124 | add esi, ARP_ENTRY.size |
2300 | hidnplayr | 125 | dec ecx |
126 | jnz .loop |
||
1529 | hidnplayr | 127 | jmp .exit |
1159 | hidnplayr | 128 | |
1529 | hidnplayr | 129 | .time_out: |
130 | cmp [esi + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
||
131 | jz .response_timeout |
||
1159 | hidnplayr | 132 | |
1529 | hidnplayr | 133 | push esi ecx |
134 | call ARP_del_entry |
||
135 | pop ecx esi |
||
1159 | hidnplayr | 136 | |
1529 | hidnplayr | 137 | jmp .next |
1159 | hidnplayr | 138 | |
1529 | hidnplayr | 139 | .response_timeout: |
140 | mov [esi + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT |
||
141 | mov [esi + ARP_ENTRY.TTL], 10 |
||
1159 | hidnplayr | 142 | |
1529 | hidnplayr | 143 | jmp .next |
1258 | hidnplayr | 144 | |
1529 | hidnplayr | 145 | .exit: |
1258 | hidnplayr | 146 | |
1529 | hidnplayr | 147 | } |
1159 | hidnplayr | 148 | |
1258 | hidnplayr | 149 | |
1529 | hidnplayr | 150 | ;----------------------------------------------------------------- |
151 | ; |
||
152 | ; ARP_input |
||
153 | ; |
||
154 | ; IN: Pointer to buffer in [esp] |
||
155 | ; size of buffer in [esp+4] |
||
156 | ; packet size (without ethernet header) in ecx |
||
157 | ; OUT: / |
||
158 | ; |
||
159 | ;----------------------------------------------------------------- |
||
160 | align 4 |
||
161 | ARP_input: |
||
1258 | hidnplayr | 162 | |
1529 | hidnplayr | 163 | DEBUGF 1,"ARP_Handler - start\n" |
2301 | hidnplayr | 164 | cmp ecx, ARP_Packet.size |
2300 | hidnplayr | 165 | jb .exit |
1258 | hidnplayr | 166 | |
1529 | hidnplayr | 167 | ;--------------------- |
168 | ; Handle Reply packets |
||
1258 | hidnplayr | 169 | |
1529 | hidnplayr | 170 | cmp word [edx + ARP_Packet.Opcode], ARP_REP_OPCODE |
171 | jne .maybe_request |
||
1159 | hidnplayr | 172 | |
1529 | hidnplayr | 173 | DEBUGF 1,"ARP_Handler - it's a reply packet from %u.%u.%u.%u\n",\ |
174 | [edx + ARP_Packet.SenderIP]:1,[edx + ARP_Packet.SenderIP+1]:1,[edx + ARP_Packet.SenderIP+2]:1,[edx + ARP_Packet.SenderIP+3]:1, |
||
1159 | hidnplayr | 175 | |
1529 | hidnplayr | 176 | mov ecx, [NumARP] |
177 | test ecx, ecx |
||
178 | jz .exit |
||
1159 | hidnplayr | 179 | |
1529 | hidnplayr | 180 | mov eax, [edx + ARP_Packet.SenderIP] |
181 | mov esi, ARP_table |
||
1196 | hidnplayr | 182 | |
1529 | hidnplayr | 183 | .loop: |
184 | cmp [esi + ARP_ENTRY.IP], eax |
||
185 | je .gotit |
||
186 | add esi, ARP_ENTRY.size |
||
2300 | hidnplayr | 187 | dec ecx |
188 | jnz .loop |
||
1258 | hidnplayr | 189 | |
1529 | hidnplayr | 190 | jmp .exit |
1159 | hidnplayr | 191 | |
1529 | hidnplayr | 192 | .gotit: |
193 | DEBUGF 1,"ARP_Handler - found matching entry\n" |
||
1159 | hidnplayr | 194 | |
1529 | hidnplayr | 195 | cmp [esi+ARP_ENTRY.TTL], 0xffff ; if it is a static entry, dont touch it |