Subversion Repositories Kolibri OS

Rev

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

Rev 7535 Rev 7678
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2019. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  ARP.INC                                                        ;;
6
;;  ARP.INC                                                        ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
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: 7535 $
19
$Revision: 7678 $
20
 
20
 
21
ARP_NO_ENTRY            = 0
21
ARP_NO_ENTRY            = 0
22
ARP_VALID_MAPPING       = 1
22
ARP_VALID_MAPPING       = 1
Line 58... Line 58...
58
uglobal
58
uglobal
59
align 4
59
align 4
Line 60... Line 60...
60
 
60
 
Line 61... Line 61...
61
        ARP_table       rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry)
61
        ARP_table       rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry)
62
 
62
 
63
        ARP_entries_num rd NET_DEVICES_MAX
63
        ARP_entries     rd NET_DEVICES_MAX
64
        ARP_PACKETS_TX  rd NET_DEVICES_MAX
64
        ARP_packets_tx  rd NET_DEVICES_MAX
Line 65... Line 65...
65
        ARP_PACKETS_RX  rd NET_DEVICES_MAX
65
        ARP_packets_rx  rd NET_DEVICES_MAX
Line 76... Line 76...
76
;                                                                 ;
76
;                                                                 ;
77
;-----------------------------------------------------------------;
77
;-----------------------------------------------------------------;
78
macro arp_init {
78
macro arp_init {
Line 79... Line 79...
79
 
79
 
80
        xor     eax, eax
80
        xor     eax, eax
81
        mov     edi, ARP_entries_num
81
        mov     edi, ARP_entries
82
        mov     ecx, 4*NET_DEVICES_MAX
82
        mov     ecx, 4*NET_DEVICES_MAX
Line 83... Line 83...
83
        rep stosd
83
        rep stosd
Line 105... Line 105...
105
; The last status value is provided to allow the network layer to delete
105
; The last status value is provided to allow the network layer to delete
106
; a packet that is queued awaiting an ARP response
106
; a packet that is queued awaiting an ARP response
Line 107... Line 107...
107
 
107
 
108
        xor     edi, edi
108
        xor     edi, edi
109
  .loop_outer:
109
  .loop_outer:
110
        mov     ecx, [ARP_entries_num + 4*edi]
110
        mov     ecx, [ARP_entries + 4*edi]
111
        test    ecx, ecx
111
        test    ecx, ecx
Line 112... Line 112...
112
        jz      .exit
112
        jz      .exit
113
 
113
 
Line 175... Line 175...
175
 
175
 
176
        call    net_ptr_to_num4
176
        call    net_ptr_to_num4
177
        cmp     edi, -1
177
        cmp     edi, -1
Line 178... Line 178...
178
        jz      .exit
178
        jz      .exit
Line 179... Line 179...
179
 
179
 
180
        inc     [ARP_PACKETS_RX + edi]          ; update stats
180
        inc     [ARP_packets_rx + edi]          ; update stats
181
 
181
 
Line 182... Line 182...
182
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: got packet from %u.%u.%u.%u (device*4=%u)\n",\
182
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: got packet from %u.%u.%u.%u (device*4=%u)\n",\
183
        [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
183
        [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
Line 184... Line 184...
184
        [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1, edi
184
        [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1, edi
185
 
185
 
186
;------------------------------
186
;------------------------------
Line 187... Line 187...
187
; First, check for IP collision
187
; First, check for IP collision
188
 
188
 
Line 189... Line 189...
189
        mov     eax, [edx + ARP_header.SenderIP]
189
        mov     eax, [edx + ARP_header.SenderIP]
190
        cmp     eax, [IP_LIST + edi]
190
        cmp     eax, [IPv4_address + edi]
Line 191... Line 191...
191
        je      .collision
191
        je      .collision
Line 192... Line 192...
192
 
192
 
193
;---------------------
193
;---------------------
194
; Handle reply packets
194
; Handle reply packets
Line 195... Line 195...
195
 
195
 
196
        cmp     [edx + ARP_header.Opcode], ARP_REP_OPCODE
196
        cmp     [edx + ARP_header.Opcode], ARP_REP_OPCODE
Line 240... Line 240...
240
        cmp     [edx + ARP_header.Opcode], ARP_REQ_OPCODE
240
        cmp     [edx + ARP_header.Opcode], ARP_REQ_OPCODE
241
        jne     .exit
241
        jne     .exit
Line 242... Line 242...
242
 
242
 
Line 243... Line 243...
243
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: its a request\n"
243
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: its a request\n"
244
 
244
 
245
        mov     eax, [IP_LIST + edi]
245
        mov     eax, [IPv4_address + edi]
Line 246... Line 246...
246
        cmp     eax, [edx + ARP_header.TargetIP]                ; Is it looking for my IP address?
246
        cmp     eax, [edx + ARP_header.TargetIP]                ; Is it looking for my IP address?
247
        jne     .exit
247
        jne     .exit
Line 257... Line 257...
257
        movsd                                                   ; Move Sender Mac to Dest MAC
257
        movsd                                                   ; Move Sender Mac to Dest MAC
258
        movsw                                                   ;
258
        movsw                                                   ;
259
        movsd                                                   ; Move sender IP to Dest IP
259
        movsd                                                   ; Move sender IP to Dest IP
Line 260... Line 260...
260
 
260
 
261
        pop     esi
261
        pop     esi
262
        mov     esi, [NET_DRV_LIST + esi]
262
        mov     esi, [net_drv_list + esi]
263
        lea     esi, [esi + ETH_DEVICE.mac]
263
        lea     esi, [esi + ETH_DEVICE.mac]
264
        lea     edi, [edx + ARP_header.SenderMAC]
264
        lea     edi, [edx + ARP_header.SenderMAC]
265
        movsd                                                   ; Copy MAC address from in MAC_LIST
265
        movsd                                                   ; Copy MAC address from in MAC_LIST
266
        movsw                                                   ;
266
        movsw                                                   ;
Line 286... Line 286...
286
 
286
 
287
        call    [ebx + NET_DEVICE.transmit]
287
        call    [ebx + NET_DEVICE.transmit]
Line 288... Line 288...
288
        ret
288
        ret
289
 
289
 
290
  .collision:
290
  .collision:
Line 291... Line 291...
291
        inc     [ARP_CONFLICTS + edi]
291
        inc     [ARP_conflicts + edi]
292
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n"
292
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n"
293
 
293
 
Line 331... Line 331...
331
        movsw                                   ;
331
        movsw                                   ;
332
        movsd                                   ;
332
        movsd                                   ;
Line 333... Line 333...
333
 
333
 
334
        push    edi
334
        push    edi
335
        call    net_ptr_to_num4
335
        call    net_ptr_to_num4
336
        inc     [ARP_PACKETS_TX + edi]          ; assume we will succeed
336
        inc     [ARP_packets_tx + edi]          ; assume we will succeed
337
        lea     esi, [IP_LIST + edi]            ; SenderIP
337
        lea     esi, [IPv4_address + edi]            ; SenderIP
338
        pop     edi
338
        pop     edi
Line 339... Line 339...
339
        movsd
339
        movsd
340
 
340
 
Line 370... Line 370...
370
 
370
 
Line 371... Line 371...
371
; TODO: use a mutex to lock ARP table
371
; TODO: use a mutex to lock ARP table
Line 372... Line 372...
372
 
372
 
373
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_add_entry: device=%u\n", edi
373
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_add_entry: device=%u\n", edi
374
 
374
 
Line 375... Line 375...
375
        mov     ecx, [ARP_entries_num + edi]
375
        mov     ecx, [ARP_entries + edi]
Line 376... Line 376...
376
        cmp     ecx, ARP_TABLE_SIZE                                     ; list full ?
376
        cmp     ecx, ARP_TABLE_SIZE                                     ; list full ?
Line 377... Line 377...
377
        jae     .full
377
        jae     .full
378
 
378
 
379
; From this point on, we can only fail if IP has a static entry, or if table is corrupt.
379
; From this point on, we can only fail if IP has a static entry, or if table is corrupt.
380
 
380
 
Line 415... Line 415...
415
 
415
 
Line 416... Line 416...
416
        ret
416
        ret
417
 
417
 
418
  .error:
418
  .error:
419
        pop     edi
419
        pop     edi
420
        dec     [ARP_entries_num + edi]
420
        dec     [ARP_entries + edi]
421
        DEBUGF  DEBUG_NETWORK_ERROR, "ARP_add_entry_failed\n"
421
        DEBUGF  DEBUG_NETWORK_ERROR, "ARP_add_entry_failed\n"
422
  .full:
422
  .full:
Line 458... Line 458...
458
        xor     eax, eax
458
        xor     eax, eax
459
        mov     ecx, sizeof.ARP_entry/2
459
        mov     ecx, sizeof.ARP_entry/2
460
        rep stosw
460
        rep stosw
Line 461... Line 461...
461
 
461
 
462
        pop     edi
462
        pop     edi
463
        dec     [ARP_entries_num + 4*edi]
463
        dec     [ARP_entries + 4*edi]
Line 464... Line 464...
464
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_del_entry: success\n"
464
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_del_entry: success\n"
Line 495... Line 495...
495
        je      .broadcast
495
        je      .broadcast
Line 496... Line 496...
496
 
496
 
497
;--------------------------------
497
;--------------------------------
Line 498... Line 498...
498
; Try to find the IP in ARP_table
498
; Try to find the IP in ARP_table
499
 
499
 
500
        mov     ecx, [ARP_entries_num + edi]
500
        mov     ecx, [ARP_entries + edi]
501
        test    ecx, ecx
501
        test    ecx, ecx
502
        jz      .not_in_list
502
        jz      .not_in_list
503
        mov     esi, edi
503
        mov     esi, edi
Line 537... Line 537...
537
 
537
 
538
; Now send a request packet on the network
538
; Now send a request packet on the network
Line 539... Line 539...
539
        pop     edi eax                 ; IP in eax, device number in ebx, for ARP_output_request
539
        pop     edi eax                 ; IP in eax, device number in ebx, for ARP_output_request
540
 
540
 
541
        push    esi edi
541
        push    esi edi
542
        mov     ebx, [NET_DRV_LIST + edi]
542
        mov     ebx, [net_drv_list + edi]
543
        call    arp_output_request
543
        call    arp_output_request
544
        pop     edi esi
544
        pop     edi esi
545
  .found_it:
545
  .found_it:
Line 618... Line 618...
618
  .error:
618
  .error:
619
        mov     eax, -1
619
        mov     eax, -1
620
        ret
620
        ret
Line 621... Line 621...
621
 
621
 
622
  .packets_tx:
622
  .packets_tx:
623
        mov     eax, [ARP_PACKETS_TX + eax]
623
        mov     eax, [ARP_packets_tx + eax]
Line 624... Line 624...
624
        ret
624
        ret
625
 
625
 
626
  .packets_rx:
626
  .packets_rx:
Line 627... Line 627...
627
        mov     eax, [ARP_PACKETS_RX + eax]
627
        mov     eax, [ARP_packets_rx + eax]
628
        ret
628
        ret
629
 
629
 
Line 630... Line 630...
630
  .conflicts:
630
  .conflicts:
631
        mov     eax, [ARP_CONFLICTS + eax]
631
        mov     eax, [ARP_conflicts + eax]
632
        ret
632
        ret
Line 633... Line 633...
633
 
633
 
634
  .entries:
634
  .entries:
635
        mov     eax, [ARP_entries_num + eax]
635
        mov     eax, [ARP_entries + eax]
636
        ret
636
        ret
637
 
637
 
638
  .read:
638
  .read:
639
        cmp     ecx, [ARP_entries_num + eax]
639
        cmp     ecx, [ARP_entries + eax]
Line 657... Line 657...
657
        call    arp_add_entry           ; out: eax = entry number, -1 on error
657
        call    arp_add_entry           ; out: eax = entry number, -1 on error
658
        ret
658
        ret
Line 659... Line 659...
659
 
659
 
660
  .remove:
660
  .remove:
661
        ; ecx = # entry
661
        ; ecx = # entry
662
        cmp     ecx, [ARP_entries_num + eax]
662
        cmp     ecx, [ARP_entries + eax]
663
        jae     .error
663
        jae     .error
664
        imul    ecx, sizeof.ARP_entry
664
        imul    ecx, sizeof.ARP_entry
665
        lea     esi, [ARP_table + ecx]
665
        lea     esi, [ARP_table + ecx]
666
        mov     edi, eax
666
        mov     edi, eax
667
        shr     edi, 2
667
        shr     edi, 2
668
        call    arp_del_entry
668
        call    arp_del_entry
Line 669... Line 669...
669
        ret
669
        ret
670
 
670
 
671
  .send_announce:
671
  .send_announce:
672
        mov     ebx, [NET_DRV_LIST + eax]
672
        mov     ebx, [net_drv_list + eax]
673
        mov     eax, [IP_LIST + eax]
673
        mov     eax, [IPv4_address + eax]