Subversion Repositories Kolibri OS

Rev

Rev 3626 | Rev 3908 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3626 Rev 3725
Line 14... Line 14...
14
;;          GNU GENERAL PUBLIC LICENSE                             ;;
14
;;          GNU GENERAL PUBLIC LICENSE                             ;;
15
;;             Version 2, June 1991                                ;;
15
;;             Version 2, June 1991                                ;;
16
;;                                                                 ;;
16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 18... Line 18...
18
 
18
 
Line 19... Line 19...
19
$Revision: 3626 $
19
$Revision: 3725 $
Line 20... Line 20...
20
 
20
 
Line 95... Line 95...
95
        SequenceNumber          dw ?
95
        SequenceNumber          dw ?
Line 96... Line 96...
96
 
96
 
Line 97... Line -...
97
ends
-
 
98
 
97
ends
-
 
98
 
-
 
99
 
99
 
100
uglobal
100
align 4
101
align 4
-
 
102
 
101
uglobal
103
        ICMP_PACKETS_TX         rd NET_DEVICES_MAX
Line 102... Line 104...
102
        ICMP_PACKETS_TX         rd NET_DEVICES_MAX
104
        ICMP_PACKETS_RX         rd NET_DEVICES_MAX
Line 154... Line 156...
154
        pop     si
156
        pop     si
155
        cmp     dx, si
157
        cmp     dx, si
156
        pop     ecx edx
158
        pop     ecx edx
157
        jne     .checksum_mismatch
159
        jne     .checksum_mismatch
Line -... Line 160...
-
 
160
 
-
 
161
; Check packet type
158
 
162
 
159
        cmp     [edx + ICMP_header.Type], ICMP_ECHO             ; Is this an echo request?
163
        cmp     [edx + ICMP_header.Type], ICMP_ECHO             ; Is this an echo request?
Line -... Line 164...
-
 
164
        jne     .check_sockets
-
 
165
 
-
 
166
; Update stats (and validate device ptr)
-
 
167
        call    NET_ptr_to_num4
-
 
168
        cmp     edi, -1
-
 
169
        je      .dump
160
        jne     .check_sockets
170
        inc     [ICMP_PACKETS_RX + edi]
161
 
171
 
Line 162... Line 172...
162
; We well re-use the packet so we can create the response as fast as possible
172
; We well re-use the packet so we can create the response as fast as possible
163
; Notice: this only works on pure ethernet
173
; Notice: this only works on pure ethernet
Line 164... Line 174...
164
 
174
 
165
        DEBUGF  DEBUG_NETWORK_VERBOSE, "got echo request\n"
-
 
166
        mov     [edx + ICMP_header.Type], ICMP_ECHOREPLY        ; Change Packet type to reply
-
 
167
 
-
 
168
        mov     esi, [esp]                                      ; Start of buffer
-
 
169
 
-
 
170
; Update stats (and validate device ptr)
-
 
171
        call    NET_ptr_to_num
-
 
172
        cmp     edi, -1
-
 
173
        je      .dump
175
        DEBUGF  DEBUG_NETWORK_VERBOSE, "got echo request\n"
174
        inc     [ICMP_PACKETS_RX + 4*edi]
176
        mov     [edx + ICMP_header.Type], ICMP_ECHOREPLY        ; Change Packet type to reply
Line 175... Line 177...
175
        inc     [ICMP_PACKETS_TX + 4*edi]
177
 
Line 223... Line 225...
223
        call    checksum_2                                      ;
225
        call    checksum_2                                      ;
224
        mov     [eax + ICMP_header.Checksum], dx                ;
226
        mov     [eax + ICMP_header.Checksum], dx                ;
Line 225... Line 227...
225
 
227
 
226
; Transmit the packet (notice that packet ptr and packet size have been on stack since start of the procedure!)
228
; Transmit the packet (notice that packet ptr and packet size have been on stack since start of the procedure!)
-
 
229
        call    [ebx + NET_DEVICE.transmit]
-
 
230
        test    eax, eax
-
 
231
        jnz     @f
-
 
232
        call    NET_ptr_to_num4
-
 
233
        inc     [UDP_PACKETS_TX + edi]
227
        call    [ebx + NET_DEVICE.transmit]
234
       @@:
Line 228... Line 235...
228
        ret
235
        ret
229
 
236
 
Line -... Line 237...
-
 
237
 
-
 
238
 
-
 
239
 
-
 
240
       .check_sockets:
-
 
241
        ; Look for an open ICMP socket
230
 
242
 
231
 
243
        pusha
232
 
244
        mov     ecx, socket_mutex
233
       .check_sockets:
245
        call    mutex_lock
234
        ; Look for an open ICMP socket
246
        popa
235
 
247
 
236
        mov     esi, [edi]              ; ipv4 source address
248
        mov     esi, [edi]              ; ipv4 source address
237
        mov     eax, net_sockets
249
        mov     eax, net_sockets
Line 238... Line 250...
238
  .try_more:
250
  .try_more:
239
;        mov      , [edx + ICMP_header.Identifier]
251
;        mov      , [edx + ICMP_header.Identifier]
Line 240... Line 252...
240
  .next_socket:
252
  .next_socket:
Line 252... Line 264...
252
        jne     .next_socket
264
        jne     .next_socket
Line 253... Line 265...
253
 
265
 
254
;        cmp     [eax + ICMP_SOCKET.Identifier],
266
;        cmp     [eax + ICMP_SOCKET.Identifier],
Line -... Line 267...
-
 
267
;        jne     .next_socket
255
;        jne     .next_socket
268
 
256
 
269
; Update stats (and validate device ptr)
257
;        call    IPv4_dest_to_dev
270
        call    NET_ptr_to_num4
258
;        cmp     edi,-1
271
        cmp     edi, -1
-
 
272
        je      .dump_
-
 
273
        inc     [ICMP_PACKETS_RX + edi]
-
 
274
 
-
 
275
        pusha
-
 
276
        mov     ecx, socket_mutex
Line 259... Line 277...
259
;        je      .dump
277
        call    mutex_unlock
Line 260... Line 278...
260
;        inc     [ICMP_PACKETS_RX+edi]
278
        popa
261
 
279
 
Line 267... Line 285...
267
        popa
285
        popa
Line 268... Line 286...
268
 
286
 
269
        mov     esi, edx
287
        mov     esi, edx
Line -... Line 288...
-
 
288
        jmp     SOCKET_input
-
 
289
 
-
 
290
  .dump_:
-
 
291
 
-
 
292
        pusha
-
 
293
        mov     ecx, socket_mutex
-
 
294
        call    mutex_unlock
-
 
295
        popa
-
 
296
 
-
 
297
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ICMP_input: no socket found\n"
Line 270... Line 298...
270
        jmp     SOCKET_input
298
        jmp     .dump
271
 
299
 
Line 272... Line 300...
272
 
300
 
Line 334... Line 362...
334
 
362
 
335
        sub     edi, edx                                ;;; TODO: find a better way to remember start of packet
363
        sub     edi, edx                                ;;; TODO: find a better way to remember start of packet
336
        push    edx edi
364
        push    edx edi
337
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Sending ICMP Packet\n"
365
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Sending ICMP Packet\n"
-
 
366
        call    [ebx + NET_DEVICE.transmit]
-
 
367
        test    eax, eax
-
 
368
        jnz     @f
-
 
369
        call    NET_ptr_to_num4
-
 
370
        inc     [ICMP_PACKETS_TX + edi]
338
        call    [ebx + NET_DEVICE.transmit]
371
       @@:
339
        ret
372
        ret
340
  .exit:
373
  .exit:
341
        DEBUGF  DEBUG_NETWORK_ERROR, "Creating ICMP Packet failed\n"
374
        DEBUGF  DEBUG_NETWORK_ERROR, "Creating ICMP Packet failed\n"
342
        add     esp, 2*4 + 2
375
        add     esp, 2*4 + 2
Line 384... Line 417...
384
        call    checksum_2
417
        call    checksum_2
385
        mov     [edi + ICMP_header.Checksum], dx
418
        mov     [edi + ICMP_header.Checksum], dx
Line 386... Line 419...
386
 
419
 
387
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Sending ICMP Packet\n"
420
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Sending ICMP Packet\n"
-
 
421
        call    [ebx + NET_DEVICE.transmit]
-
 
422
        test    eax, eax
-
 
423
        jnz     @f
-
 
424
        call    NET_ptr_to_num4
-
 
425
        inc     [ICMP_PACKETS_TX + edi]
388
        call    [ebx + NET_DEVICE.transmit]
426
       @@:
389
        ret
427
        ret
390
  .exit:
428
  .exit:
391
        DEBUGF  DEBUG_NETWORK_ERROR, "Creating ICMP Packet failed\n"
429
        DEBUGF  DEBUG_NETWORK_ERROR, "Creating ICMP Packet failed\n"
392
        add     esp, 4
430
        add     esp, 4