72 lines
1.6 KiB
C
72 lines
1.6 KiB
C
#ifndef ETHERLIB_TEST_ARP_CACHE_H
|
|
#define ETHERLIB_TEST_ARP_CACHE_H
|
|
|
|
#include "prefab/packet_parsers/ethernet_frame.h"
|
|
#include "prefab/packet_parsers/ipv4_types.h"
|
|
#include "connection_block.h"
|
|
|
|
#define ETH_ARP_PACKET_CLASS (0x0806)
|
|
|
|
struct EthInterface_;
|
|
|
|
|
|
/**
|
|
* ARP cache entry record.
|
|
*/
|
|
typedef struct {
|
|
EthernetAddress eth; ///< Ethernet address
|
|
ip4_addr ip; ///< IPv4 address
|
|
} ArpEntry;
|
|
|
|
/**
|
|
* ARP cache class.
|
|
*/
|
|
typedef struct {
|
|
uint16_t size; ///< Number of cache entries
|
|
uint16_t fill; ///< Fill level
|
|
ConnBlock cb; ///< Connection block for sending and receiving ARP requests
|
|
ArpEntry entries[]; ///< Cache entries
|
|
} ArpCache;
|
|
|
|
/**
|
|
* Create new ARP cache table.
|
|
* @param intf Related Ethernet interface
|
|
* @param size Number of available entries
|
|
* @return Pointer to newly allocated ARP cache
|
|
*/
|
|
ArpCache * arpc_new(struct EthInterface_ * intf, uint16_t size);
|
|
|
|
/**
|
|
* Learn new assignment.
|
|
* @param arpc Pointer to ARP cache
|
|
* @param newEntry Pointer to map newEntry
|
|
*/
|
|
void arpc_learn(ArpCache * arpc, const ArpEntry * newEntry);
|
|
|
|
/**
|
|
* Get entry by IP-address.
|
|
* @param ip IP address
|
|
* @return Pointer to matching entry OR NULL if not found
|
|
*/
|
|
const ArpEntry *arpc_get(ArpCache *arpc, ip4_addr ip);
|
|
|
|
/**
|
|
* Free ARP cache.
|
|
* @param aprc Pointer to existing ARP cache.
|
|
*/
|
|
void arpc_free(ArpCache * aprc);
|
|
|
|
void arpc_ask(ArpCache *arpc, ip4_addr addr);
|
|
|
|
void arpc_respond(ArpCache *arpc, const EthernetAddress hwAddr, ip4_addr ipAddr);
|
|
|
|
const ArpEntry *arpc_get_ask(ArpCache *arpc, ip4_addr ip);
|
|
|
|
/**
|
|
* Dump ARP cache contents.
|
|
* @param arpc
|
|
*/
|
|
void arpc_dump(ArpCache * arpc);
|
|
|
|
#endif //ETHERLIB_TEST_ARP_CACHE_H
|