FreeNOS
ARP.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBNET_ARP_H
19 #define __LIB_LIBNET_ARP_H
20 
21 #include <Types.h>
22 #include <HashTable.h>
23 #include <Timer.h>
24 #include <KernelTimer.h>
25 #include "Ethernet.h"
26 #include "IPV4.h"
27 #include "NetworkProtocol.h"
28 
29 class ARPSocket;
30 
42 class ARP : public NetworkProtocol
43 {
44  private:
45 
47  static const Size MaxRetries = 3;
48 
52  typedef struct ARPCache
53  {
57  bool valid;
58  }
59  ARPCache;
60 
61  public:
62 
67  {
69  };
70 
75  {
76  IPV4 = 0x0800
77  };
78 
82  enum Operation
83  {
84  Request = 1,
85  Reply = 2
86  };
87 
94  typedef struct Header
95  {
101 
104 
107  }
108  PACKED Header;
109 
110  public:
111 
119  ARP(NetworkServer &server,
120  NetworkDevice &device,
121  NetworkProtocol &parent);
122 
126  virtual ~ARP();
127 
133  virtual FileSystem::Result initialize();
134 
140  void setIP(::IPV4 *ip);
141 
151  Ethernet::Address *ethAddr);
152 
161 
171  const IPV4::Address ipAddr);
172 
182  const Size offset);
183 
184  private:
185 
193  ARPCache * insertCacheEntry(const IPV4::Address ipAddr);
194 
202  ARPCache * getCacheEntry(const IPV4::Address ipAddr);
203 
210  void updateCacheEntry(const IPV4::Address ipAddr,
211  const Ethernet::Address *ethAddr);
212 
213  private:
214 
217 
220 
223 
226 };
227 
233 #endif /* __LIB_LIBNET_ARP_H */
ARP::Header::etherTarget
Ethernet::Address etherTarget
Definition: ARP.h:105
NetworkProtocol
Network protocol abstraction class.
Definition: NetworkProtocol.h:39
HashTable
Efficient key -> value lookups.
Definition: HashTable.h:44
ARP::lookupAddress
FileSystem::Result lookupAddress(const IPV4::Address *ipAddr, Ethernet::Address *ethAddr)
Lookup Ethernet address for an IP.
Definition: ARP.cpp:86
ARP::m_sock
ARPSocket * m_sock
The single ARP socket.
Definition: ARP.h:216
ARP::Header
ARP network packet header.
Definition: ARP.h:94
ARP::ARPCache
ARP table cache entry.
Definition: ARP.h:52
Types.h
ARP::Header::hardwareType
u16 hardwareType
Definition: ARP.h:96
ARP::Header::hardwareLength
u8 hardwareLength
Definition: ARP.h:98
ARP::Header::ipTarget
IPV4::Address ipTarget
Definition: ARP.h:106
ARP::process
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition: ARP.cpp:246
ARP::sendReply
FileSystem::Result sendReply(const Ethernet::Address *ethaddr, const IPV4::Address ipAddr)
Send ARP reply.
Definition: ARP.cpp:197
HashTable.h
Ethernet.h
NetworkDevice
Network Device abstract class.
Definition: NetworkDevice.h:41
ARP::Request
@ Request
Definition: ARP.h:84
ARP::m_cache
HashTable< IPV4::Address, ARPCache * > m_cache
Contains a cached mapping from IP to Ethernet addresses.
Definition: ARP.h:222
ARP::setIP
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition: ARP.cpp:50
ARPSocket
Address Resolution Protocol (ARP) socket.
Definition: ARPSocket.h:40
KernelTimer
Provides the timer of the kernel.
Definition: KernelTimer.h:36
ARP::ARPCache::valid
bool valid
Definition: ARP.h:57
ARP::Header
struct ARP::Header Header
ARP network packet header.
ARP::Header::operation
u16 operation
Definition: ARP.h:100
Timer::Info
Timer information structure.
Definition: Timer.h:42
ARP::Header::protocolType
u16 protocolType
Definition: ARP.h:97
Ethernet
Ethernet networking protocol.
Definition: Ethernet.h:42
NetworkProtocol.h
ARP::Operation
Operation
ARP message types (operation codes)
Definition: ARP.h:82
ARP::m_kernelTimer
KernelTimer m_kernelTimer
Provides access to the kernel timer.
Definition: ARP.h:225
ARP::getCacheEntry
ARPCache * getCacheEntry(const IPV4::Address ipAddr)
Retrieve cache entry by IP.
Definition: ARP.cpp:55
PACKED
#define PACKED
Ensures strict minimum memory requirements.
Definition: Macros.h:159
Ethernet::Address
Ethernet network address.
Definition: Ethernet.h:52
Timer.h
NetworkServer
Networking server.
Definition: NetworkServer.h:40
ARP::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: ARP.cpp:41
ARP::ProtocolType
ProtocolType
ARP inter-network protocol types.
Definition: ARP.h:74
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
ARP::m_ip
::IPV4 * m_ip
IPV4 instance object.
Definition: ARP.h:219
ARP::ARPCache::time
Timer::Info time
Definition: ARP.h:55
ARP::Header::etherSender
Ethernet::Address etherSender
Definition: ARP.h:102
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
IPV4::Address
u32 Address
IP-address.
Definition: IPV4.h:47
IPV4.h
IPV4
Internet Protocol Version 4.
Definition: IPV4.h:40
KernelTimer.h
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
ARP::Header::protocolLength
u8 protocolLength
Definition: ARP.h:99
NetworkProtocol::ARP
@ ARP
Definition: NetworkProtocol.h:50
ARP::MaxRetries
static const Size MaxRetries
Maximum number of retries for ARP lookup.
Definition: ARP.h:47
ARP::ARPCache::ethAddr
Ethernet::Address ethAddr
Definition: ARP.h:54
ARP::Reply
@ Reply
Definition: ARP.h:85
ARP::ARPCache::retryCount
Size retryCount
Definition: ARP.h:56
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
ARP::updateCacheEntry
void updateCacheEntry(const IPV4::Address ipAddr, const Ethernet::Address *ethAddr)
Update cache entry.
Definition: ARP.cpp:75
ARP
Address Resolution Protocol.
Definition: ARP.h:42
ARP::HardwareType
HardwareType
ARP hardware types.
Definition: ARP.h:66
ARP::Header::ipSender
IPV4::Address ipSender
Definition: ARP.h:103
ARP::~ARP
virtual ~ARP()
Destructor.
Definition: ARP.cpp:33
ARP::sendRequest
FileSystem::Result sendRequest(const IPV4::Address address)
Send ARP request.
Definition: ARP.cpp:133
ARP::ARPCache
struct ARP::ARPCache ARPCache
ARP table cache entry.
ARP::insertCacheEntry
ARPCache * insertCacheEntry(const IPV4::Address ipAddr)
Insert a new entry to the ARP cache.
Definition: ARP.cpp:64