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

/opentcp/include/inet/arp.h File Reference


Detailed Description

Author:
Version:
1.0
Date:
10.7.2002
OpenTCP ARP protocol function declarations, constants, etc.

Definition in file arp.h.

Go to the source code of this file.

Data Structures

struct  arp_entry
 ARP packet header fields. More...


Defines

#define MAXHWALEN   6
#define MAXPRALEN   4
#define ARP_TSIZE   10
 ARP cache size (number of entries).

#define ARP_TIMEOUT   60
 ARP cache entry refresh period (in seconds).

#define ARP_RESEND   2
 ARP Request resend period (in seconds).

#define ARP_MAXRETRY   5
 Number of IP address resolving retires.

#define ARP_FREE   0
#define ARP_RESERVED   1
#define ARP_PENDING   2
#define ARP_RESOLVED   3
#define ARP_REFRESHING   4
#define ARP_FIXED_IP   0
#define ARP_TEMP_IP   1

Functions

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

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

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

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

void arp_manage (void)
 Manage ARP cache periodically.

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

BYTE process_arp (struct ethernet_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.

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


Define Documentation

#define MAXHWALEN   6
 

Maximum HW address Length (6=Eth)

Definition at line 74 of file arp.h.

Referenced by arp_add(), arp_get_response(), arp_init(), arp_send_req(), arp_send_response(), process_arp(), and process_ip_out().

#define MAXPRALEN   4
 

Maximum Protocol adr.len (4=IPv4)

Definition at line 75 of file arp.h.

Referenced by arp_get_response(), arp_send_req(), arp_send_response(), and process_arp().

#define ARP_FREE   0
 

Entry is Unused (initial value)

Definition at line 185 of file arp.h.

Referenced by arp_add(), arp_alloc(), arp_find(), arp_get_response(), arp_init(), and arp_manage().

#define ARP_RESERVED   1
 

Entry is reserved (allocated)

Definition at line 186 of file arp.h.

Referenced by arp_alloc(), and arp_get_response().

#define ARP_PENDING   2
 

Entry is used but incomplete

Definition at line 187 of file arp.h.

Referenced by arp_find(), and arp_manage().

#define ARP_RESOLVED   3
 

Entry has been resolved

Definition at line 188 of file arp.h.

Referenced by arp_add(), arp_find(), arp_get_response(), arp_init(), and arp_manage().

#define ARP_REFRESHING   4
 

Entry is being refreshed

Definition at line 189 of file arp.h.

Referenced by arp_manage().

#define ARP_FIXED_IP   0
 

For Fixed addresses like GW. Entry is refreshed after ttl

Definition at line 195 of file arp.h.

Referenced by arp_add(), arp_find(), arp_init(), and arp_manage().

#define ARP_TEMP_IP   1
 

For Temporary addresses. Entry is removed after ttl

Definition at line 196 of file arp.h.

Referenced by arp_alloc(), arp_init(), arp_manage(), arp_send_response(), process_ip_in(), and process_ip_out().


Function Documentation

void arp_init void   
 

Author:
Date:
01.11.2001
Warning:
  • Invoke this function at start-up to properly initialize ARP cache subsystem.
Call this function to properly initialize ARP cache table and so that ARP allocates and initializes a timer for it's use.

Definition at line 910 of file arp.c.

References ARP_FIXED_IP, ARP_FREE, ARP_MAXRETRY, ARP_RESOLVED, ARP_TEMP_IP, ARP_TIMEOUT, arp_timer, get_timer(), arp_entry::hwadr, init_timer(), MAXHWALEN, arp_entry::pradr, arp_entry::retries, arp_entry::state, TIMERTIC, arp_entry::ttl, and arp_entry::type.

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().

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().

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().

void arp_manage void   
 

Author:
Date:
04.11.2001
Warning:
  • Invoke this function periodically to ensure proper ARP cache behaviour
Iterate through ARP cache aging entries. If timed-out entry is found, remove it (dynamic address) or update it (static address). This function must be called periodically by the system.

Definition at line 785 of file arp.c.

References ARP_FIXED_IP, ARP_FREE, ARP_PENDING, ARP_REFRESHING, ARP_RESEND, ARP_RESOLVED, arp_send_req(), ARP_TEMP_IP, ARP_TIMEOUT, arp_timer, check_timer(), init_timer(), arp_entry::pradr, arp_entry::retries, arp_entry::state, TIMERTIC, arp_entry::ttl, and arp_entry::type.

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().

BYTE 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

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().

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().


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