Subversion Repositories Kolibri OS

Rev

Rev 3908 | Rev 5565 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
  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                             ;;
  15. ;;             Version 2, June- 1991                               ;;
  16. ;;                                                                 ;;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18.  
  19. $Revision: 3386 $
  20.  
  21. ARP_NO_ENTRY            = 0
  22. ARP_VALID_MAPPING       = 1
  23. ARP_AWAITING_RESPONSE   = 2
  24. ARP_RESPONSE_TIMEOUT    = 3
  25.  
  26. ARP_REQUEST_TTL         = 31          ; 20 s
  27. ARP_ENTRY_TTL           = 937         ; 600 s
  28. ARP_STATIC_ENTRY        = -1
  29.  
  30. ARP_REQ_OPCODE          = 0x0100      ; request
  31. ARP_REP_OPCODE          = 0x0200      ; reply
  32.  
  33. ARP_TABLE_SIZE          = 20          ; Size of table
  34.  
  35. struct  ARP_entry
  36.  
  37.         IP              dd ?
  38.         MAC             dp ?
  39.         Status          dw ?
  40.         TTL             dw ?
  41.  
  42. ends
  43.  
  44. struct  ARP_header
  45.  
  46.         HardwareType    dw ?
  47.         ProtocolType    dw ?
  48.         HardwareSize    db ?
  49.         ProtocolSize    db ?
  50.         Opcode          dw ?
  51.         SenderMAC       dp ?
  52.         SenderIP        dd ?
  53.         TargetMAC       dp ?
  54.         TargetIP        dd ?
  55.  
  56. ends
  57.  
  58. uglobal
  59. align 4
  60.  
  61.         ARP_table       rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry)
  62.  
  63.         ARP_entries_num rd NET_DEVICES_MAX
  64.         ARP_PACKETS_TX  rd NET_DEVICES_MAX
  65.         ARP_PACKETS_RX  rd NET_DEVICES_MAX
  66.         ARP_CONFLICTS   rd NET_DEVICES_MAX
  67.  
  68.  
  69. endg
  70.  
  71.  
  72.  
  73. ;-----------------------------------------------------------------
  74. ;
  75. ; ARP_init
  76. ;
  77. ;  This function resets all ARP variables
  78. ;
  79. ;-----------------------------------------------------------------
  80. macro ARP_init {
  81.  
  82.         xor     eax, eax
  83.         mov     edi, ARP_entries_num
  84.         mov     ecx, 4*NET_DEVICES_MAX
  85.         rep stosd
  86.  
  87. }
  88.  
  89. ;---------------------------------------------------------------------------
  90. ;
  91. ; ARP_decrease_entry_ttls
  92. ;
  93. ;---------------------------------------------------------------------------
  94.  
  95. macro ARP_decrease_entry_ttls {
  96.  
  97. local   .loop
  98. local   .exit
  99.  
  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
  110.  
  111.         xor     edi, edi
  112.   .loop_outer:
  113.         mov     ecx, [ARP_entries_num + 4*edi]
  114.         test    ecx, ecx
  115.         jz      .exit
  116.  
  117.         mov     esi, (ARP_TABLE_SIZE * sizeof.ARP_entry)
  118.         imul    esi, edi
  119.         add     esi, ARP_table
  120.   .loop:
  121.         cmp     [esi + ARP_entry.TTL], ARP_STATIC_ENTRY
  122.         je      .next
  123.  
  124.         dec     [esi + ARP_entry.TTL]
  125.         jz      .time_out
  126.  
  127.   .next:
  128.         add     esi, sizeof.ARP_entry
  129.         dec     ecx
  130.         jnz     .loop
  131.         jmp     .exit
  132.  
  133.   .time_out:
  134.         cmp     [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE
  135.         je      .response_timeout
  136.  
  137.         push    esi edi ecx
  138.         call    ARP_del_entry
  139.         pop     ecx edi esi
  140.  
  141.         jmp     .next
  142.  
  143.   .response_timeout:
  144.         mov     [esi + ARP_entry.Status], ARP_RESPONSE_TIMEOUT
  145.         mov     [esi + ARP_entry.TTL], 10
  146.  
  147.         jmp     .next
  148.  
  149.   .exit:
  150.         inc     edi
  151.         cmp     edi, NET_DEVICES_MAX
  152.         jb      .loop_outer
  153.  
  154. }
  155.  
  156.  
  157. ;-----------------------------------------------------------------
  158. ;
  159. ; ARP_input
  160. ;
  161. ;  IN:  Pointer to buffer in [esp]
  162. ;       size of buffer in [esp+4]
  163. ;       packet size (without ethernet header) in ecx
  164. ;       packet ptr in edx
  165. ;       device ptr in ebx
  166. ;  OUT: /
  167. ;
  168. ;-----------------------------------------------------------------
  169. align 4
  170. ARP_input:
  171.  
  172. ;-----------------------------------------
  173. ; Check validity and print some debug info
  174.  
  175.         cmp     ecx, sizeof.ARP_header
  176.         jb      .exit
  177.  
  178.         call    NET_ptr_to_num4
  179.         cmp     edi, -1
  180.         jz      .exit
  181.  
  182.         inc     [ARP_PACKETS_RX + edi]          ; update stats
  183.  
  184.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: got packet from %u.%u.%u.%u (device*4=%u)\n",\
  185.         [edx + ARP_header.SenderIP]:1, [edx + ARP_header.SenderIP + 1]:1,\
  186.         [edx + ARP_header.SenderIP + 2]:1, [edx + ARP_header.SenderIP + 3]:1, edi
  187.  
  188. ;------------------------------
  189. ; First, check for IP collision
  190.  
  191.         mov     eax, [edx + ARP_header.SenderIP]
  192.         cmp     eax, [IP_LIST + edi]
  193.         je      .collision
  194.  
  195. ;---------------------
  196. ; Handle reply packets
  197.  
  198.         cmp     [edx + ARP_header.Opcode], ARP_REP_OPCODE
  199.         jne     .maybe_request
  200.  
  201.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: It's a reply\n"
  202.  
  203.         mov     ecx, [ARP_entries_num + edi]
  204.         test    ecx, ecx
  205.         jz      .exit
  206.  
  207.         mov     esi, edi
  208.         imul    esi, (ARP_TABLE_SIZE * sizeof.ARP_entry)/4
  209.         add     esi, ARP_table
  210.   .loop:
  211.         cmp     [esi + ARP_entry.IP], eax
  212.         je      .gotit
  213.         add     esi, sizeof.ARP_entry
  214.         dec     ecx
  215.         jnz     .loop
  216.  
  217.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: no matching entry found\n"
  218.         jmp     .exit
  219.  
  220.   .gotit:
  221.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: found matching entry\n"
  222.  
  223.         cmp     [esi + ARP_entry.TTL], ARP_STATIC_ENTRY         ; if it is a static entry, dont touch it
  224.         je      .exit
  225.  
  226.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: updating entry\n"
  227.  
  228.         mov     [esi + ARP_entry.Status], ARP_VALID_MAPPING
  229.         mov     [esi + ARP_entry.TTL], ARP_ENTRY_TTL
  230.  
  231.         mov     eax, dword [edx + ARP_header.SenderMAC]
  232.         mov     dword [esi + ARP_entry.MAC], eax
  233.         mov     cx, word [edx + ARP_header.SenderMAC + 4]
  234.         mov     word [esi + ARP_entry.MAC + 4], cx
  235.  
  236.         jmp     .exit
  237.  
  238. ;-----------------------
  239. ; Handle request packets
  240.  
  241.   .maybe_request:
  242.         cmp     [edx + ARP_header.Opcode], ARP_REQ_OPCODE
  243.         jne     .exit
  244.  
  245.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: its a request\n"
  246.  
  247.         mov     eax, [IP_LIST + edi]
  248.         cmp     eax, [edx + ARP_header.TargetIP]                ; Is it looking for my IP address?
  249.         jne     .exit
  250.  
  251.         push    eax
  252.         push    edi
  253.  
  254. ; OK, it is a request for one of our MAC addresses.
  255. ; Build the frame and send it. We can reuse the buffer.  (faster then using ARP_create_packet)
  256.  
  257.         lea     esi, [edx + ARP_header.SenderMAC]
  258.         lea     edi, [edx + ARP_header.TargetMAC]
  259.         movsd                                                   ; Move Sender Mac to Dest MAC
  260.         movsw                                                   ;
  261.         movsd                                                   ; Move sender IP to Dest IP
  262.  
  263.         pop     esi
  264.         mov     esi, [NET_DRV_LIST + esi]
  265.         lea     esi, [esi + ETH_DEVICE.mac]
  266.         lea     edi, [edx + ARP_header.SenderMAC]
  267.         movsd                                                   ; Copy MAC address from in MAC_LIST
  268.         movsw                                                   ;
  269.         pop     eax
  270.         stosd                                                   ; Write our IP
  271.  
  272.         mov     [edx + ARP_header.Opcode], ARP_REP_OPCODE
  273.  
  274. ; Now, Fill in ETHERNET header
  275.  
  276.         mov     edi, [esp]
  277.         lea     esi, [edx + ARP_header.TargetMAC]
  278.         movsd
  279.         movsw
  280.         lea     esi, [edx + ARP_header.SenderMAC]
  281.         movsd
  282.         movsw
  283. ;        mov     ax , ETHER_ARP                                 ; It's already there, I'm sure of it!
  284. ;        stosw
  285.  
  286.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: Sending reply\n"
  287.  
  288.         call    [ebx + NET_DEVICE.transmit]
  289.         ret
  290.  
  291.   .collision:
  292.         inc     [ARP_CONFLICTS + edi]
  293.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n"
  294.  
  295.   .exit:
  296.         call    NET_packet_free
  297.         add     esp, 4                                          ; pop (balance stack)
  298.  
  299.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_input: exiting\n"
  300.         ret
  301.  
  302.  
  303. ;---------------------------------------------------------------------------
  304. ;
  305. ; ARP_output_request
  306. ;
  307. ; IN:   ebx = device ptr
  308. ;       eax = IP
  309. ; OUT: /
  310. ;       scratched: probably everything
  311. ;
  312. ;---------------------------------------------------------------------------
  313. align 4
  314. ARP_output_request:
  315.  
  316.         push    eax
  317.  
  318.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\
  319.         [esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx
  320.  
  321.         mov     ax, ETHER_PROTO_ARP
  322.         mov     ecx, sizeof.ARP_header
  323.         mov     edx, ETH_BROADCAST              ; broadcast mac
  324.         call    ETH_output
  325.         jz      .exit
  326.  
  327.         mov     [edi + ARP_header.HardwareType], 0x0100         ; Ethernet
  328.         mov     [edi + ARP_header.ProtocolType], 0x0008         ; IP
  329.         mov     [edi + ARP_header.HardwareSize], 6              ; MAC-addr length
  330.         mov     [edi + ARP_header.ProtocolSize], 4              ; IP-addr length
  331.         mov     [edi + ARP_header.Opcode], ARP_REQ_OPCODE       ; Request
  332.  
  333.         add     edi, ARP_header.SenderMAC
  334.         lea     esi, [ebx + ETH_DEVICE.mac]     ; SenderMac
  335.         movsw                                   ;
  336.         movsd                                   ;
  337.  
  338.         push    edi
  339.         call    NET_ptr_to_num4
  340.         inc     [ARP_PACKETS_TX + edi]          ; assume we will succeed
  341.         lea     esi, [IP_LIST + edi]            ; SenderIP
  342.         pop     edi
  343.         movsd
  344.  
  345.         mov     esi, ETH_BROADCAST              ; DestMac
  346.         movsw                                   ;
  347.         movsd                                   ;
  348.         popd    [edi]                           ; DestIP
  349.  
  350.         push    edx eax
  351.         call    [ebx + NET_DEVICE.transmit]
  352.         ret
  353.  
  354.   .exit:
  355.         add     esp, 4
  356.         DEBUGF  DEBUG_NETWORK_ERROR, "ARP_output_request: send failed\n"
  357.         ret
  358.  
  359.  
  360. ;-----------------------------------------------------------------
  361. ;
  362. ; ARP_add_entry (or update)
  363. ;
  364. ; IN:  esi = ptr to entry (can easily be made on the stack)
  365. ;      edi = device num*4
  366. ; OUT: eax = entry #, -1 on error
  367. ;      esi = ptr to newly created entry
  368. ;
  369. ;-----------------------------------------------------------------      ; TODO: use a mutex
  370. align 4
  371. ARP_add_entry:
  372.  
  373.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_add_entry: device=%u\n", edi
  374.  
  375.         mov     ecx, [ARP_entries_num + edi]
  376.         cmp     ecx, ARP_TABLE_SIZE                                     ; list full ?
  377.         jae     .full
  378.  
  379. ; From this point on, we can only fail if IP has a static entry, or if table is corrupt.
  380.  
  381.         inc     [ARP_entries_num + edi]                                 ; assume we will succeed
  382.  
  383.         push    edi
  384.         xor     ecx, ecx
  385.         imul    edi, ARP_TABLE_SIZE*sizeof.ARP_entry/4
  386.         add     edi, ARP_table
  387.         mov     eax, [esi + ARP_entry.IP]
  388.   .loop:
  389.         cmp     [edi + ARP_entry.Status], ARP_NO_ENTRY                  ; is this slot empty?
  390.         je      .add
  391.  
  392.         cmp     [edi + ARP_entry.IP], eax                               ; if not, check if it doesnt collide
  393.         jne     .maybe_next
  394.  
  395.         cmp     [edi + ARP_entry.TTL], ARP_STATIC_ENTRY                 ; ok, its the same IP, update it if not static
  396.         jne     .add
  397.  
  398.         DEBUGF  DEBUG_NETWORK_ERROR, "ARP_add_entry: failed, IP already has a static entry\n"
  399.         jmp     .error
  400.  
  401.   .maybe_next:                                                          ; try the next slot
  402.         add     edi, sizeof.ARP_entry
  403.         inc     ecx
  404.         cmp     ecx, ARP_TABLE_SIZE
  405.         jb      .loop
  406.  
  407.   .add:
  408.         push    ecx
  409.         mov     ecx, sizeof.ARP_entry/2
  410.         rep movsw
  411.         pop     ecx
  412.         lea     esi, [edi - sizeof.ARP_entry]
  413.         pop     edi
  414.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_add_entry: entry=%u\n", ecx
  415.  
  416.         ret
  417.  
  418.   .error:
  419.         pop     edi
  420.         dec     [ARP_entries_num + edi]
  421.         DEBUGF  DEBUG_NETWORK_ERROR, "ARP_add_entry_failed\n"
  422.   .full:
  423.         mov     eax, -1
  424.         ret
  425.  
  426.  
  427. ;-----------------------------------------------------------------
  428. ;
  429. ; ARP_del_entry
  430. ;
  431. ; IN:   esi = ptr to arp entry
  432. ;       edi = device number
  433. ; OUT:  /
  434. ;
  435. ;-----------------------------------------------------------------
  436. align 4
  437. ARP_del_entry:
  438.  
  439.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_del_entry: entry=%x entrys=%u\n", esi, [ARP_entries_num + 4*edi]
  440.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_del_entry: IP=%u.%u.%u.%u\n", \
  441.         [esi + ARP_entry.IP]:1, [esi + ARP_entry.IP + 1]:1, [esi + ARP_entry.IP + 2]:1, [esi + ARP_entry.IP + 3]:1
  442.  
  443.         push    edi
  444.         imul    edi, (ARP_TABLE_SIZE) * sizeof.ARP_entry
  445.         lea     ecx, [ARP_table + (ARP_TABLE_SIZE - 1) * sizeof.ARP_entry + edi]
  446.         sub     ecx, esi
  447.         shr     ecx, 1
  448.  
  449. ; move all trailing entries, sizeof.ARP_entry bytes to left.
  450.         mov     edi, esi
  451.         add     esi, sizeof.ARP_entry
  452.         rep movsw
  453.  
  454. ; now add an empty entry to the end (erasing previous one)
  455.         xor     eax, eax
  456.         mov     ecx, sizeof.ARP_entry/2
  457.         rep stosw
  458.  
  459.         pop     edi
  460.         dec     [ARP_entries_num + 4*edi]
  461.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_del_entry: success\n"
  462.  
  463.         ret
  464.  
  465.  
  466.  
  467.  
  468.  
  469. ;-----------------------------------------------------------------
  470. ;
  471. ; ARP_IP_to_MAC
  472. ;
  473. ;  This function translates an IP address to a MAC address
  474. ;
  475. ;  IN:  eax = IPv4 address
  476. ;       edi = device number * 4
  477. ;  OUT: eax = -1 on error, -2 means request send
  478. ;      else, ax = first two bytes of mac (high 16 bits of eax will be 0)
  479. ;       ebx = last four bytes of mac
  480. ;       edi = unchanged
  481. ;
  482. ;-----------------------------------------------------------------
  483. align 4
  484. ARP_IP_to_MAC:
  485.  
  486.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: %u.%u", al, ah
  487.         rol     eax, 16
  488.         DEBUGF  DEBUG_NETWORK_VERBOSE, ".%u.%u device*4: %u\n", al, ah, edi
  489.         rol     eax, 16
  490.  
  491.         cmp     eax, 0xffffffff
  492.         je      .broadcast
  493.  
  494. ;--------------------------------
  495. ; Try to find the IP in ARP_table
  496.  
  497.         mov     ecx, [ARP_entries_num + edi]
  498.         test    ecx, ecx
  499.         jz      .not_in_list
  500.         mov     esi, edi
  501.         imul    esi, (sizeof.ARP_entry * ARP_TABLE_SIZE)/4
  502.         add     esi, ARP_table + ARP_entry.IP
  503.   .scan_loop:
  504.         cmp     [esi], eax
  505.         je      .found_it
  506.         add     esi, sizeof.ARP_entry
  507.         dec     ecx
  508.         jnz     .scan_loop
  509.  
  510.   .not_in_list:
  511.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: preparing for ARP request\n"
  512.  
  513.         push    eax edi                 ; save IP for ARP_output_request
  514. ; Now craft the ARP entry on the stack
  515.         pushw   ARP_REQUEST_TTL         ; TTL
  516.         pushw   ARP_AWAITING_RESPONSE   ; status
  517.         pushd   0                       ; mac
  518.         pushw   0
  519.         pushd   eax                     ; ip
  520.         mov     esi, esp
  521.  
  522. ; Add it to the list
  523.         call    ARP_add_entry
  524.  
  525. ; Delete the temporary entry
  526.         add     esp, sizeof.ARP_entry   ; clear the entry from stack
  527.  
  528. ; If we could not add it to the list, give up
  529.         cmp     eax, -1                 ; did ARP_add_entry fail?
  530.         je      .full
  531.  
  532. ;-----------------------------------------------
  533. ; At this point, we got an ARP entry in the list
  534.  
  535. ; Now send a request packet on the network
  536.         pop     edi eax                 ; IP in eax, device number in ebx, for ARP_output_request
  537.  
  538.         push    esi edi
  539.         mov     ebx, [NET_DRV_LIST + edi]
  540.         call    ARP_output_request
  541.         pop     edi esi
  542.   .found_it:
  543.         cmp     [esi + ARP_entry.Status], ARP_VALID_MAPPING             ; Does it have a MAC assigned?
  544.         je      .valid
  545.  
  546. if ARP_BLOCK
  547.  
  548.         cmp     [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE         ; Are we waiting for reply from remote end?
  549.         jne     .give_up
  550.         push    esi
  551.         mov     esi, 10                 ; wait 10 ms
  552.         call    delay_ms
  553.         pop     esi
  554.         jmp     .found_it               ; now check again
  555.  
  556. else
  557.  
  558.         jmp     .give_up
  559.  
  560. end if
  561.  
  562.   .valid:
  563.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: found MAC\n"
  564.         movzx   eax, word[esi + ARP_entry.MAC]
  565.         mov     ebx, dword[esi + ARP_entry.MAC + 2]
  566.         ret
  567.  
  568.   .full:
  569.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: table is full!\n"
  570.         add     esp, 8
  571.   .give_up:
  572.         DEBUGF  DEBUG_NETWORK_VERBOSE, "ARP_IP_to_MAC: entry has no valid mapping!\n"
  573.         mov     eax, -1
  574.         ret
  575.  
  576.   .broadcast:
  577.         mov     eax, 0x0000ffff
  578.         mov     ebx, 0xffffffff
  579.         ret
  580.  
  581.  
  582. ;-----------------------------------------------------------------
  583. ;
  584. ; ARP_API
  585. ;
  586. ; This function is called by system function 76
  587. ;
  588. ; IN:  subfunction number in bl
  589. ;      device number in bh
  590. ;      ecx, edx, .. depends on subfunction
  591. ;
  592. ; OUT:  ?
  593. ;
  594. ;-----------------------------------------------------------------
  595. align 4
  596. ARP_api:
  597.  
  598.         movzx   eax, bh
  599.         shl     eax, 2
  600.  
  601.         and     ebx, 0xff
  602.         cmp     ebx, .number
  603.         ja      .error
  604.         jmp     dword [.table + 4*ebx]
  605.  
  606.   .table:
  607.         dd      .packets_tx     ; 0
  608.         dd      .packets_rx     ; 1
  609.         dd      .entries        ; 2
  610.         dd      .read           ; 3
  611.         dd      .write          ; 4
  612.         dd      .remove         ; 5
  613.         dd      .send_announce  ; 6
  614.         dd      .conflicts      ; 7
  615.   .number = ($ - .table) / 4 - 1
  616.  
  617.   .error:
  618.         mov     eax, -1
  619.         ret
  620.  
  621.   .packets_tx:
  622.         mov     eax, [ARP_PACKETS_TX + eax]
  623.         ret
  624.  
  625.   .packets_rx:
  626.         mov     eax, [ARP_PACKETS_RX + eax]
  627.         ret
  628.  
  629.   .conflicts:
  630.         mov     eax, [ARP_CONFLICTS + eax]
  631.         ret
  632.  
  633.   .entries:
  634.         mov     eax, [ARP_entries_num + eax]
  635.         ret
  636.  
  637.   .read:
  638.         cmp     ecx, [ARP_entries_num + eax]
  639.         jae     .error
  640.         shr     eax, 2
  641.         imul    eax, sizeof.ARP_entry*ARP_TABLE_SIZE
  642.         add     eax, ARP_table
  643.         ; edi = pointer to buffer
  644.         ; ecx = # entry
  645.         imul    ecx, sizeof.ARP_entry
  646.         lea     esi, [eax + ecx]
  647.         mov     ecx, sizeof.ARP_entry/2
  648.         rep movsw
  649.  
  650.         xor     eax, eax
  651.         ret
  652.  
  653.   .write:
  654.         ; esi = pointer to buffer
  655.         mov     edi, eax
  656.         call    ARP_add_entry           ; out: eax = entry number, -1 on error
  657.         ret
  658.  
  659.   .remove:
  660.         ; ecx = # entry
  661.         cmp     ecx, [ARP_entries_num + eax]
  662.         jae     .error
  663.         imul    ecx, sizeof.ARP_entry
  664.         lea     esi, [ARP_table + ecx]
  665.         mov     edi, eax
  666.         shr     edi, 2
  667.         call    ARP_del_entry
  668.         ret
  669.  
  670.   .send_announce:
  671.         mov     ebx, [NET_DRV_LIST + eax]
  672.         mov     eax, [IP_LIST + eax]
  673.         call    ARP_output_request      ; now send a gratuitous ARP
  674.         ret
  675.  
  676.