Subversion Repositories Kolibri OS

Rev

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

Rev 2877 Rev 2891
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: 2877 $
19
$Revision: 2891 $
20
 
20
 
21
MAX_FRAGMENTS                   = 64
21
MAX_FRAGMENTS                   = 64
Line 217... Line 217...
217
; re-calculate the checksum
217
; re-calculate the checksum
Line 218... Line 218...
218
 
218
 
219
        IPv4_checksum edx
219
        IPv4_checksum edx
Line 220... Line 220...
220
        jnz     .dump                                           ; if checksum isn't valid then dump packet
220
        jnz     .dump                                           ; if checksum isn't valid then dump packet
Line 221... Line 221...
221
 
221
 
222
        DEBUGF  1,"IPv4 Checksum is correct\n"
222
        DEBUGF  1,"IPv4_input: Checksum ok\n"
Line 223... Line 223...
223
 
223
 
Line 255... Line 255...
255
        cmp     eax, 127
255
        cmp     eax, 127
256
        je      .ip_ok
256
        je      .ip_ok
Line 257... Line 257...
257
 
257
 
Line 258... Line 258...
258
        ; or it's just not meant for us.. :(
258
        ; or it's just not meant for us.. :(
259
 
259
 
Line 260... Line 260...
260
        DEBUGF  2,"IPv4_input - Destination address does not match!\n"
260
        DEBUGF  2,"IPv4_input: Destination address does not match!\n"
261
        jmp     .dump
261
        jmp     .dump
Line 299... Line 299...
299
        je      UDP_input
299
        je      UDP_input
Line 300... Line 300...
300
 
300
 
301
        cmp     al, IP_PROTO_ICMP
301
        cmp     al, IP_PROTO_ICMP
Line 302... Line 302...
302
        je      ICMP_input
302
        je      ICMP_input
Line 303... Line 303...
303
 
303
 
304
        DEBUGF  2,"IPv4_input - unknown protocol: %u\n", al
304
        DEBUGF  2,"IPv4_input: unknown protocol %u\n", al
305
 
305
 
306
  .dump:
306
  .dump:
307
        DEBUGF  2,"IPv4_input - dumping\n"
307
        DEBUGF  2,"IPv4_input: dumping\n"
308
;        inc     [dumped_rx_count]
308
;        inc     [dumped_rx_count]                              ;;; TODO
Line 318... Line 318...
318
  .has_fragments:
318
  .has_fragments:
319
        movzx   eax, [edx + IPv4_header.FlagsAndFragmentOffset]
319
        movzx   eax, [edx + IPv4_header.FlagsAndFragmentOffset]
320
        xchg    al , ah
320
        xchg    al , ah
321
        shl     ax , 3
321
        shl     ax , 3
Line 322... Line 322...
322
 
322
 
Line 323... Line 323...
323
        DEBUGF  1,"Fragmented packet, offset:%u, id:%x\n", ax, [edx + IPv4_header.Identification]:4
323
        DEBUGF  1,"IPv4_input: fragmented packet offset=%u id=%x\n", ax, [edx + IPv4_header.Identification]:4
324
 
324
 
Line 325... Line 325...
325
        test    ax , ax                                         ; Is this the first packet of the fragment?
325
        test    ax , ax                                         ; Is this the first packet of the fragment?
326
        jz      .is_first_fragment
326
        jz      .is_first_fragment
Line 327... Line 327...
327
 
327
 
Line 328... Line 328...
328
 
328
 
329
;-------------------------------------------------------
329
;-------------------------------------------------------
330
; We have a fragmented IP packet, but it's not the first
330
; We have a fragmented IP packet, but it's not the first
Line 360... Line 360...
360
 
360
 
361
;------------------------------------
361
;------------------------------------
Line 362... Line 362...
362
; We have received the first fragment
362
; We have received the first fragment
363
 
363
 
364
  .is_first_fragment:
364
  .is_first_fragment:
365
        DEBUGF  1,"First fragmented packet received!\n"
365
        DEBUGF  1,"IPv4_input: First fragment packet received!\n"
366
                                                                ; try to locate a free slot..
366
                                                                ; try to locate a free slot..
367
        mov     ecx, MAX_FRAGMENTS
367
        mov     ecx, MAX_FRAGMENTS
368
        mov     esi, FRAGMENT_LIST
368
        mov     esi, FRAGMENT_LIST
Line 394... Line 394...
394
 
394
 
395
;-----------------------------------
395
;-----------------------------------
Line 396... Line 396...
396
; We have received the last fragment
396
; We have received the last fragment
397
 
397
 
Line 398... Line 398...
398
  .is_last_fragment:
398
  .is_last_fragment:
399
        DEBUGF  1,"Last fragmented packet received!\n"
399
        DEBUGF  1,"IPv4_input: Last fragment packet received!\n"
400
 
400
 
Line 410... Line 410...
410
  .count_bytes:
410
  .count_bytes:
411
        cmp     [esi + FRAGMENT_entry.PrevPtr], edi
411
        cmp     [esi + FRAGMENT_entry.PrevPtr], edi
412
        jne     .destroy_slot_pop                                               ; Damn, something screwed up, remove the whole slot (and free buffers too if possible!)
412
        jne     .destroy_slot_pop                                               ; Damn, something screwed up, remove the whole slot (and free buffers too if possible!)
413
        mov     cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength]       ; Add total length
413
        mov     cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength]       ; Add total length
414
        xchg    cl, ch
414
        xchg    cl, ch
415
        DEBUGF  1,"Packet size: %u\n", cx
415
        DEBUGF  1,"IPv4_input: Packet size=%u\n", cx
416
        add     ax, cx
416
        add     ax, cx
417
        movzx   cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL]     ; Sub Header length
417
        movzx   cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL]     ; Sub Header length
418
        and     cx, 0x000F
418
        and     cx, 0x000F
419
        shl     cx, 2
419
        shl     cx, 2
420
        DEBUGF  1,"Header size: %u\n", cx
420
        DEBUGF  1,"IPv4_input: Header size=%u\n", cx
421
        sub     ax, cx
421
        sub     ax, cx
422
        mov     edi, esi
422
        mov     edi, esi
423
        mov     esi, [esi + FRAGMENT_entry.NextPtr]
423
        mov     esi, [esi + FRAGMENT_entry.NextPtr]
424
        cmp     esi, -1
424
        cmp     esi, -1
425
        jne     .count_bytes
425
        jne     .count_bytes
Line 430... Line 430...
430
        mov     [esi + FRAGMENT_entry.PrevPtr], edi
430
        mov     [esi + FRAGMENT_entry.PrevPtr], edi
431
        mov     [esi + FRAGMENT_entry.Owner], ebx
431
        mov     [esi + FRAGMENT_entry.Owner], ebx
Line 432... Line 432...
432
 
432
 
433
        mov     cx, [edx + IPv4_header.TotalLength]                            ; Note: This time we dont substract Header length
433
        mov     cx, [edx + IPv4_header.TotalLength]                            ; Note: This time we dont substract Header length
434
        xchg    cl , ch
434
        xchg    cl , ch
435
        DEBUGF  1,"Packet size: %u\n", cx
435
        DEBUGF  1,"IPv4_input: Packet size=%u\n", cx
436
        add     ax , cx
436
        add     ax , cx
Line 437... Line 437...
437
        DEBUGF  1,"Total Received data size: %u\n", eax
437
        DEBUGF  1,"IPv4_input: Total Received data size=%u\n", eax
438
 
438
 
439
        push    eax
439
        push    eax
440
        mov     ax , [edx + IPv4_header.FlagsAndFragmentOffset]
440
        mov     ax , [edx + IPv4_header.FlagsAndFragmentOffset]
441
        xchg    al , ah
441
        xchg    al , ah
442
        shl     ax , 3
442
        shl     ax , 3
443
        add     cx , ax
443
        add     cx , ax
Line 444... Line 444...
444
        pop     eax
444
        pop     eax
445
        DEBUGF  1,"Total Fragment size: %u\n", ecx
445
        DEBUGF  1,"IPv4_input: Total Fragment size=%u\n", ecx
Line 446... Line 446...
446
 
446
 
Line 456... Line 456...
456
 
456
 
457
  .rebuild_packet_loop:
457
  .rebuild_packet_loop:
458
        movzx   ecx, [edx + sizeof.FRAGMENT_entry + IPv4_header.FlagsAndFragmentOffset]   ; Calculate the fragment offset
458
        movzx   ecx, [edx + sizeof.FRAGMENT_entry + IPv4_header.FlagsAndFragmentOffset]   ; Calculate the fragment offset
459
        xchg    cl , ch                                                                 ;  intel byte order
459
        xchg    cl , ch                                                                 ;  intel byte order
460
        shl     cx , 3                                                                  ;   multiply by 8 and clear first 3 bits
460
        shl     cx , 3                                                                  ;   multiply by 8 and clear first 3 bits
Line 461... Line 461...
461
        DEBUGF  1,"Fragment offset: %u\n", cx
461
        DEBUGF  1,"IPv4_input: Fragment offset=%u\n", cx
462
 
462
 
463
        lea     edi, [eax + ecx]                                                        ; Notice that edi will be equal to eax for first fragment
463
        lea     edi, [eax + ecx]                                                        ; Notice that edi will be equal to eax for first fragment
464
        movzx   ebx, [edx + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL]            ; Find header size (in ebx) of fragment
464
        movzx   ebx, [edx + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL]            ; Find header size (in ebx) of fragment
Line 503... Line 503...
503
        jmp     .handle_it          ; edx = buf ptr, ecx = size, [esp] buf ptr, [esp+4], total size, ebx=device ptr
503
        jmp     .handle_it          ; edx = buf ptr, ecx = size, [esp] buf ptr, [esp+4], total size, ebx=device ptr
Line 504... Line 504...
504
 
504
 
505
  .destroy_slot_pop:
505
  .destroy_slot_pop:
506
        add     esp, 4
506
        add     esp, 4
507
  .destroy_slot:
507
  .destroy_slot:
508
        DEBUGF  1,"Destroy fragment slot!\n"
508
        DEBUGF  1,"IPv4_input: Destroy fragment slot!\n"
509
        ; TODO!
509
        ; TODO!
Line 611... Line 611...
611
 
611
 
Line 612... Line 612...
612
        pop     ecx
612
        pop     ecx
613
 
613
 
614
        IPv4_checksum edi
614
        IPv4_checksum edi
615
        add     edi, sizeof.IPv4_header
615
        add     edi, sizeof.IPv4_header
Line 616... Line 616...
616
        DEBUGF  1,"IPv4 Packet for device %x created successfully\n", ebx
616
        DEBUGF  1,"IPv4_output: success!\n"
617
        ret
617
        ret
618
 
618
 
619
  .eth_error:
619
  .eth_error:
620
        DEBUGF  1,"IPv4_output: ethernet error\n"
620
        DEBUGF  1,"IPv4_output: ethernet error\n"
Line 621... Line 621...
621
        add     esp, 3*4+2+6
621
        add     esp, 3*4+2+6
622
        xor     edi, edi
622
        xor     edi, edi
623
        ret
623
        ret
624
 
624
 
625
  .arp_error:
625
  .arp_error:
Line 626... Line 626...
626
        DEBUGF  1,"IPv4_output: ARP error (0x%x)\n", eax
626
        DEBUGF  1,"IPv4_output: ARP error=%x\n", eax
627
        add     esp, 3*4+2
627
        add     esp, 3*4+2
628
        xor     edi, edi
628
        xor     edi, edi
629
        ret
629
        ret
Line 704... Line 704...
704
;        [edi + IPv4_header.SourceAddress]
704
;        [edi + IPv4_header.SourceAddress]
705
;        [edi + IPv4_header.DestinationAddress]
705
;        [edi + IPv4_header.DestinationAddress]
Line 706... Line 706...
706
 
706
 
707
        IPv4_checksum edi                       ;;;; todo: checksum for IP packet with options!
707
        IPv4_checksum edi                       ;;;; todo: checksum for IP packet with options!
708
        add     edi, sizeof.IPv4_header
708
        add     edi, sizeof.IPv4_header
709
        DEBUGF  1,"IPv4 Packet for device %x created successfully\n", ebx
709
        DEBUGF  1,"IPv4_output_raw: device=%x\n", ebx
710
        call    [ebx + NET_DEVICE.transmit]
710
        call    [ebx + NET_DEVICE.transmit]
Line 711... Line 711...
711
        ret
711
        ret
712
 
712
 
Line 761... Line 761...
761
        sub     ecx, sizeof.IPv4_header         ; substract header size
761
        sub     ecx, sizeof.IPv4_header         ; substract header size
762
        push    ecx                             ; max data size
762
        push    ecx                             ; max data size
763
        push    dword 0                         ; offset
763
        push    dword 0                         ; offset
Line 764... Line 764...
764
 
764
 
765
  .new_fragment:
765
  .new_fragment:
Line 766... Line 766...
766
        DEBUGF 1,"Ipv4_fragment - new_fragmentn"
766
        DEBUGF 1,"Ipv4_fragment: new fragment"
767
 
767
 
768
 
768
 
Line 783... Line 783...
783
        mov     esi, [esp + 2*4]
783
        mov     esi, [esp + 2*4]
784
        add     esi, sizeof.IPv4_header
784
        add     esi, sizeof.IPv4_header
785
        add     esi, [esp]      ; offset
785
        add     esi, [esp]      ; offset
Line 786... Line 786...
786
 
786
 
787
        mov     ecx, [esp + 1*4]
787
        mov     ecx, [esp + 1*4]
788
        DEBUGF 1,"IPv4_fragment - copying data (%u bytes)\n", ecx
788
        DEBUGF 1,"IPv4_fragment: copying %u bytes\n", ecx
Line 789... Line 789...
789
        rep     movsb
789
        rep     movsb
790
 
790
 
791
; now, correct header
791
; now, correct header
Line 820... Line 820...
820
        mov     ecx, [esp+3*4+6+4]      ; ptr to begin of buff
820
        mov     ecx, [esp+3*4+6+4]      ; ptr to begin of buff
821
        add     ecx, [esp+3*4+6+4+4]    ; buff size
821
        add     ecx, [esp+3*4+6+4+4]    ; buff size
822
        sub     ecx, [esp+2*4]          ; ptr to ip header
822
        sub     ecx, [esp+2*4]          ; ptr to ip header
823
        add     ecx, [esp]              ; offset
823
        add     ecx, [esp]              ; offset
Line 824... Line 824...
824
 
824
 
Line 825... Line 825...
825
        DEBUGF 1,"Ipv4_fragment - bytes remaining: %u\n", ecx
825
        DEBUGF 1,"Ipv4_fragment: %u bytes remaining\n", ecx
826
 
826
 
Line 827... Line 827...
827
        cmp     ecx, [esp+1*4]
827
        cmp     ecx, [esp+1*4]
828
        jae     .new_fragment
828
        jae     .new_fragment
Line 829... Line 829...
829
 
829
 
830
        mov     [esp+4], ecx            ; set fragment size to remaining packet size
830
        mov     [esp+4], ecx            ; set fragment size to remaining packet size
831
        jmp     .new_fragment
831
        jmp     .new_fragment
832
 
832
 
833
      .err:
833
      .err:
834
        DEBUGF 1,"Ipv4_fragment - failed\n"
834
        DEBUGF 1,"Ipv4_fragment: failed\n"
835
      .done:
835
      .done:
836
        add     esp, 12 + 4 + 6
836
        add     esp, 12 + 4 + 6
Line 837... Line 837...
837
      .err2:
837
      .err2: