Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/arp.c File Reference


Detailed Description

Author:
Version:
1.0
Date:
10.7.2002
Bug:
Warning:
Todo:
OpenTCP ARP protocol implementation. Function declarations can be found in inet/arp.h.

Definition in file arp.c.

Go to the source code of this file.

Functions

UINT8 process_arp (struct ethernet_frame *frame)
 Process and analyze the received ARP packet.

void arp_send_response (void)
 Send response to an ARP request.

void arp_get_response (void)
 Extract data from the received ARP packet.

void arp_send_req (UINT8 entry)
 Send ARP request based on information in an ARP cache table.

INT8 arp_alloc (UINT8 type)
 Allocate ARP entry in ARP cache table.

INT8 arp_add (UINT32 pra, UINT8 *hwadr, UINT8 type)
 Add given IP address and MAC address to ARP cache.

arp_entryarp_find (LWORD pra, struct netif *machine, UINT8 type)
 Find an ARP entry given a protocol address.

void arp_manage (void)
 Manage ARP cache periodically.

void arp_init (void)
 Initialize data structures for ARP processing.

BYTE is_subnet (LWORD ipadr, struct netif *machine)
 Checks if a given IP address belongs to the subnet of a given machine.


Variables

arp_entry arp_table [ARP_TSIZE]
 ARP cache table holding ARP_TSIZE cache values.

UINT8 arp_timer
 ARP timer handle used for measuring timeouts, doing retransmissions,..


Function Documentation

UINT8 process_arp struct ethernet_frame   frame
 

Author:
Date:
10.07.2002
Parameters:
frame  Pointer to ethernet_frame structure containing information about the received frame
Returns:
Return TRUE if Ethernet frame processed held ARP packet, otherwise FALSE.
Invoke process_arp function whenever ARP packet is received (see main_demo.c for an example loop). This function will process the received packet, analyze it'c content briefly and perform on of the two possible actions:
  • If the received packet is ARP request it will invoke arp_send_reply in order to send ARP reply back
  • If the received packet is ARP response it will iterate through the cache table and try to find ARP entry that is beeing resolved or refreshed
Examples:
main_demo.c.

Definition at line 116 of file arp.c.

References arp_get_response(), arp_send_response(), ethernet_frame::buf_index, ethernet_frame::frame_size, MAXHWALEN, MAXPRALEN, NETWORK_RECEIVE_INITIALIZE, ethernet_frame::protocol, and RECEIVE_NETWORK_B.

void arp_send_response void   
 

Author:
Date:
10.07.2002
Warning:
  • This function starts reading data from Ethernet controller without initializing it for reading it first, so NIC must already be initialized for reading from correct address (it expects ar$sha field from ARP packet immediately)
This function is invoked from process_arp() function in order to send a reply to an ARP request. First, incoming packet is checked to see if it is intended for us or not. If not, function does not do anything. Otherwise, ARP reply packet is formed and sent.

Definition at line 188 of file arp.c.

References arp_add(), ARP_BUFFER, ARP_TEMP_IP, MAXHWALEN, MAXPRALEN, NETWORK_ADD_DATALINK, NETWORK_COMPLETE_SEND, NETWORK_SEND_INITIALIZE, PROTOCOL_ARP, RECEIVE_NETWORK_B, and SEND_NETWORK_B.

Referenced by process_arp().

void arp_get_response void   
 

Author:
Date:
10.07.2002
Warning:
  • This function starts reading data from Ethernet controller without initializing it for reading it first, so NIC must already be initialized for reading from correct address (it expects ar$sha field from ARP packet immediately)
This function is invoked from process_arp() function when ARP reply packet is detected. Basic checking is performed to see if the packet is intended for us, and if it is, ARP cache table is checked and corresponding entry is refreshed (resolved).

Definition at line 307 of file arp.c.

References ARP_FREE, ARP_MAXRETRY, ARP_RESERVED, ARP_RESOLVED, ARP_TIMEOUT, arp_entry::hwadr, MAXHWALEN, MAXPRALEN, arp_entry::pradr, RECEIVE_NETWORK_B, arp_entry::retries, arp_entry::state, and arp_entry::ttl.

Referenced by process_arp().

void arp_send_req UINT8    entry
 

Author:
Date:
1.11.2001
Parameters:
entry  Index of ARP cache entry that is beeing resolved
Invoked from arp_find() and arp_manage() functions, arp_send_request creates ARP request packet based on data stored in the ARP cache entry who's index is given as a parameter.

Definition at line 390 of file arp.c.

References ARP_BUFFER, MAXHWALEN, MAXPRALEN, NETWORK_ADD_DATALINK, NETWORK_COMPLETE_SEND, NETWORK_SEND_INITIALIZE, arp_entry::pradr, PROTOCOL_ARP, and SEND_NETWORK_B.

Referenced by arp_find(), and arp_manage().

INT8 arp_alloc UINT8    type
 

Author:
Date:
1.11.2001
Parameters:
type  Type of ARP cache entry beeing allocated. Can be one of the following:
Returns:
>=0 - pointer to allocated ARP entry (actaully index in the ARP cache table)
Allocate arp entry for given type. Chooses the unused entry if one exists. Otherwice deletes entries in round-robin fashion.

Definition at line 466 of file arp.c.

References ARP_FREE, ARP_RESERVED, ARP_TEMP_IP, arp_entry::state, and arp_entry::type.

Referenced by arp_add(), and arp_find().

INT8 arp_add UINT32    pra,
UINT8 *    hwadr,
UINT8    type
 

Author:
Date:
10.07.2002
Parameters:
pra  - protocol address (assumed IPv4)
hwadr  - pointer to Ethernet MAC address (6 bytes)
type  - type of address allocated if not found. Can be one of the following:
Returns:
  • 0 - Address already in cache. Refreshed.
  • 1 - New entry in ARP cache created
New IP address is added to ARP cache based on the information supplied to function as parameters.

Definition at line 552 of file arp.c.

References arp_alloc(), ARP_FIXED_IP, ARP_FREE, ARP_MAXRETRY, ARP_RESOLVED, ARP_TIMEOUT, FALSE, arp_entry::hwadr, is_subnet(), MAXHWALEN, arp_entry::pradr, arp_entry::retries, arp_entry::state, and arp_entry::ttl.

Referenced by arp_send_response(), and process_ip_in().

struct arp_entry* arp_find LWORD    pra,
struct netif   machine,
UINT8    type
 

Author:
Date:
01.11.2001
Parameters:
pra  - Protocol address (IPv4)
machine  - Pointer to configuration of network interface used
type  - Type of address allocated if not found. Can be one of the following:
Returns:
  • 0 - ARP entry not found or not ready yet (waiting for ARP response)
  • struct arp_entry* - pointer to solved entry of ARP cache table
This function tries to resolve IPv4 address by checking the ARP cache table and sending ARP requested if needed.

Definition at line 639 of file arp.c.

References arp_alloc(), ARP_FIXED_IP, ARP_FREE, ARP_MAXRETRY, ARP_PENDING, ARP_RESEND, ARP_RESOLVED, arp_send_req(), arp_entry::hwadr, is_subnet(), arp_entry::pradr, arp_entry::retries, arp_entry::state, and arp_entry::ttl.

Referenced by process_ip_out().

BYTE is_subnet LWORD    ipadr,
struct netif   machine
 

Author:
Date:
05.11.2001
Parameters:
ipadr  - IP address under check
machine  - pointer to configuration of network parameters used
Returns:
  • TRUE - ipadr belongs to subnet of given machine
  • FALSE - ipadr is NOT a part of subnet of given machine
Based on information supplied in ipadr and machine parameters this function performs basic check if IP address is on the same subnet as the one defined for the machine.

Definition at line 960 of file arp.c.

References netif::localip, and netif::netmask.

Referenced by arp_add(), and arp_find().


Variable Documentation

struct arp_entry arp_table[ARP_TSIZE]
 

ARP cache table is an array of arp_entry structures holding all of the necessary information about the state, timeouts and hardware/IP addresses of individual entries. By modifying the ARP_TSIZE, cache size can be changed and thus RAM memory occupied by the ARP cache significantly reduced or increased. See arp_entry definition for more information about struct fields.

Definition at line 86 of file arp.c.

UINT8 arp_timer
 

ARP module uses this timer handle to detect that a certain period of time has expired (defined by the value of ARP_MANG_TOUT) and that cache entries should be examined to see what to do with them.

Definition at line 94 of file arp.c.

Referenced by arp_init(), and arp_manage().


Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by doxygen1.2.18