Rev 1185 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1185 | Rev 1187 | ||
---|---|---|---|
Line 109... | Line 109... | ||
109 | ; EAX = Returned value depends on opcodes, more detailed see below |
109 | ; EAX = Returned value depends on opcodes, more detailed see below |
110 | ; |
110 | ; |
111 | ;*************************************************************************** |
111 | ;*************************************************************************** |
112 | ;Opcode's constants |
112 | ;Opcode's constants |
113 | ARP_TABLE_ADD equ 1 |
113 | ARP_TABLE_ADD equ 1 |
114 | ARP_TABLE_DEL equ 2 |
- | |
115 | ARP_TABLE_GET equ 3 |
- | |
116 | ARP_TABLE_GET_ENTRIES_NUMBER equ 4 |
- | |
117 | ARP_TABLE_IP_TO_MAC equ 5 |
114 | ARP_TABLE_IP_TO_MAC equ 5 |
118 | ARP_TABLE_TIMER equ 6 |
- | |
Line 119... | Line 115... | ||
119 | 115 | ||
120 | ;Index's constants |
116 | ;Index's constants |
121 | EXTRA_IS_ARP_PACKET_PTR equ 0 ;if Extra contain pointer to ARP_Packet |
117 | EXTRA_IS_ARP_PACKET_PTR equ 0 ;if Extra contain pointer to ARP_Packet |
Line 127... | Line 123... | ||
127 | mov ebx, ARPTable ;ARPTable base |
123 | mov ebx, ARPTable ;ARPTable base |
128 | mov ecx, dword[NumARP] ;ARP-entries counter |
124 | mov ecx, dword[NumARP] ;ARP-entries counter |
Line 129... | Line 125... | ||
129 | 125 | ||
Line 130... | Line -... | ||
130 | mov eax, dword[Opcode] |
- | |
131 | - | ||
Line 132... | Line 126... | ||
132 | cmp eax, ARP_TABLE_TIMER |
126 | mov eax, dword[Opcode] |
Line 133... | Line 127... | ||
133 | je .timer |
127 | |
134 | 128 | ||
135 | DEBUGF 1,"ARP table manager opcode:%u numARP:%u\n",eax,ecx |
- | |
136 | - | ||
137 | cmp eax, ARP_TABLE_ADD |
- | |
138 | je .add |
129 | DEBUGF 1,"ARP table manager opcode:%u numARP:%u\n",eax,ecx |
139 | cmp eax, ARP_TABLE_DEL |
130 | |
140 | je .del |
131 | cmp eax, ARP_TABLE_ADD |
141 | cmp eax, ARP_TABLE_GET |
- | |
142 | je .get |
- | |
143 | cmp eax, ARP_TABLE_IP_TO_MAC |
- | |
144 | je .ip_to_mac |
- | |
145 | cmp eax, ARP_TABLE_GET_ENTRIES_NUMBER |
- | |
146 | je .get_entries_number |
- | |
147 | jmp .exit ;if unknown opcode |
- | |
148 | - | ||
149 | - | ||
150 | ;;BEGIN TIMER |
- | |
151 | ;;Description: it must be callback every second. It is responsible for removing expired routes. |
- | |
152 | ;;IN: Operation: ARP_TABLE_TIMER |
- | |
153 | ;; Index: must be zero |
- | |
154 | ;; Extra: must be zero |
- | |
155 | ;;OUT: |
- | |
156 | ;; EAX=not defined |
- | |
157 | ;; |
- | |
158 | .timer: |
- | |
159 | test ecx, ecx |
- | |
160 | jz .exit ;if NumARP=0 nothing to do |
- | |
161 | ; sub ecx, ARP_TABLE_ENTRIES ;ecx=dynamic entries number |
- | |
162 | ; jz .exit ;if NumARP=number of static entries then exit |
- | |
163 | - | ||
164 | ; add ebx, ARP_TABLE_ENTRIES*ARP_ENTRY_SIZE ;ebx=dynamic entries base |
- | |
165 | - | ||
166 | .timer_loop: |
- | |
167 | movsx esi, word [ebx + ARP_ENTRY.TTL] |
- | |
168 | cmp esi, 0xFFFFFFFF |
- | |
169 | je .timer_loop_end ;if TTL==0xFFFF then it's static entry |
- | |
170 | - | ||
171 | test esi, esi |
- | |
172 | jnz .timer_loop_end_with_dec ;if TTL!=0 |
- | |
173 | - | ||
174 | ; Ok, TTL is 0 |
- | |
175 | ;if Status==AWAITING_RESPONSE and TTL==0 |
- | |
176 | ;then we have to change it to ARP_RESPONSE_TIMEOUT |
- | |
177 | cmp word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
- | |
178 | jne @f |
- | |
179 | - | ||
180 | mov word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT |
- | |
181 | mov word [ebx + ARP_ENTRY.TTL], word 0x000A ;10 sec |
- | |
182 | jmp .timer_loop_end |
- | |
183 | - | ||
184 | @@: |
- | |
185 | ;if TTL==0 and Status==VALID_MAPPING, we have to delete it |
- | |
186 | ;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too |
- | |
187 | mov esi, dword[NumARP] |
- | |
Line 188... | Line -... | ||
188 | sub esi, ecx ;esi=index of entry, will be deleted |
- | |
189 | stdcall arp_table_manager,ARP_TABLE_DEL,esi,0 ;opcode,index,extra |
- | |
190 | jmp .timer_loop_end |
- | |
191 | 132 | je .add |
|
192 | - | ||
Line 193... | Line -... | ||
193 | .timer_loop_end_with_dec: |
- | |
194 | dec word [ebx + ARP_ENTRY.TTL] ;decrease TTL |
- | |
Line 195... | Line 133... | ||
195 | .timer_loop_end: |
133 | |
196 | add ebx, ARP_ENTRY.size |
134 | cmp eax, ARP_TABLE_IP_TO_MAC |
197 | loop .timer_loop |
135 | je .ip_to_mac |
198 | 136 | ||
Line 292... | Line 230... | ||
292 | 230 | ||
293 | add esp, ARP_ENTRY.size ;free stack |
231 | add esp, ARP_ENTRY.size ;free stack |
294 | jmp .exit |
232 | jmp .exit |
Line 295... | Line -... | ||
295 | ;;END ADD |
- | |
296 | - | ||
297 | ;;BEGIN DEL |
- | |
298 | ;;Description: it deletes an entry in the table. |
- | |
299 | ;;IN: Operation: ARP_TABLE_DEL |
- | |
300 | ;; Index: index of entry, that should be deleted |
- | |
301 | ;; Extra: must be zero |
- | |
302 | ;;OUT: |
- | |
303 | ;; EAX=not defined |
- | |
304 | ;; |
- | |
305 | .del: |
- | |
306 | mov esi, [Index] |
- | |
307 | imul esi, ARP_ENTRY.size |
- | |
308 | - | ||
Line 309... | Line -... | ||
309 | mov ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY.size |
- | |
310 | sub ecx, esi |
- | |
311 | - | ||
312 | lea edi, [ebx + esi] ;edi=ptr to entry that should be deleted |
- | |
313 | lea esi, [edi + ARP_ENTRY.size] ;esi=ptr to next entry |
- | |
314 | - | ||
315 | shr ecx,1 ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER! |
- | |
316 | cld |
- | |
317 | rep movsw |
- | |
318 | - | ||
319 | dec dword[NumARP] ;decrease arp-entries counter |
- | |
320 | jmp .exit |
- | |
321 | ;;END DEL |
- | |
322 | - | ||
323 | ;;BEGIN GET |
- | |
324 | ;;Description: it reads an entry of table into buffer. |
- | |
325 | ;;IN: Operation: ARP_TABLE_GET |
- | |
326 | ;; Index: index of entry, that should be read |
- | |
327 | ;; Extra: pointer to buffer for reading(size must be equal to ARP_ENTRY_SIZE) |
- | |
328 | ;;OUT: |
- | |
329 | ;; EAX=not defined |
- | |
330 | ;; |
- | |
331 | .get: |
- | |
332 | mov esi, [Index] |
- | |
333 | imul esi, ARP_ENTRY.size ;esi=ptr to required ARP_ENTRY |
- | |
334 | mov edi, [Extra] ;edi=buffer for reading |
- | |
335 | mov ecx, ARP_ENTRY.size/2 ; must be even number!!! |
- | |
336 | cld |
- | |
Line 337... | Line 233... | ||
337 | rep movsw |
233 | ;;END ADD |
338 | jmp .exit |
234 | |
339 | ;;END GET |
235 | |
340 | 236 | ||
Line 427... | Line 323... | ||
427 | mov eax, ARP_NO_ENTRY |
323 | mov eax, ARP_NO_ENTRY |
428 | jmp .exit |
324 | jmp .exit |
Line 429... | Line 325... | ||
429 | 325 | ||
Line 430... | Line -... | ||
430 | ;;END IP_TO_MAC |
- | |
431 | - | ||
432 | ;;BEGIN GET_ENTRIES_NUMBER |
- | |
433 | ;;Description: returns an ARP-entries number in the ARPTable |
- | |
434 | ;;IN: Operation: ARP_TABLE_GET_ENTRIES_NUMBER |
- | |
435 | ;; Index: must be zero |
- | |
436 | ;; Extra: must be zero |
- | |
437 | ;;OUT: |
- | |
438 | ;; EAX=ARP-entries number in the ARPTable |
- | |
439 | .get_entries_number: |
- | |
440 | mov eax, dword[NumARP] |
- | |
441 | jmp .exit |
- | |
442 | ;;END GET_ENTRIES_NUMBER |
326 | ;;END IP_TO_MAC |
443 | 327 | ||
444 | .exit: |
328 | .exit: |