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
29class ARPSocket;
30
42class ARP : public NetworkProtocol
43{
44 private:
45
47 static const Size MaxRetries = 3;
48
60
61 public:
62
67 {
68 Ethernet = 1
69 };
70
75 {
76 IPV4 = 0x0800
77 };
78
83 {
85 Reply = 2
86 };
87
109
110 public:
111
119 ARP(NetworkServer &server,
120 NetworkDevice &device,
121 NetworkProtocol &parent);
122
126 virtual ~ARP();
127
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
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 */
Address Resolution Protocol (ARP) socket.
Definition ARPSocket.h:41
Address Resolution Protocol.
Definition ARP.h:43
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition ARP.cpp:246
ProtocolType
ARP inter-network protocol types.
Definition ARP.h:75
KernelTimer m_kernelTimer
Provides access to the kernel timer.
Definition ARP.h:225
void updateCacheEntry(const IPV4::Address ipAddr, const Ethernet::Address *ethAddr)
Update cache entry.
Definition ARP.cpp:75
HardwareType
ARP hardware types.
Definition ARP.h:67
::IPV4 * m_ip
IPV4 instance object.
Definition ARP.h:219
virtual FileSystem::Result initialize()
Perform initialization.
Definition ARP.cpp:41
HashTable< IPV4::Address, ARPCache * > m_cache
Contains a cached mapping from IP to Ethernet addresses.
Definition ARP.h:222
FileSystem::Result sendReply(const Ethernet::Address *ethaddr, const IPV4::Address ipAddr)
Send ARP reply.
Definition ARP.cpp:197
struct ARP::ARPCache ARPCache
ARP table cache entry.
struct ARP::Header Header
ARP network packet header.
FileSystem::Result sendRequest(const IPV4::Address address)
Send ARP request.
Definition ARP.cpp:133
Operation
ARP message types (operation codes)
Definition ARP.h:83
@ Request
Definition ARP.h:84
@ Reply
Definition ARP.h:85
ARPCache * getCacheEntry(const IPV4::Address ipAddr)
Retrieve cache entry by IP.
Definition ARP.cpp:55
static const Size MaxRetries
Maximum number of retries for ARP lookup.
Definition ARP.h:47
virtual ~ARP()
Destructor.
Definition ARP.cpp:33
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition ARP.cpp:50
FileSystem::Result lookupAddress(const IPV4::Address *ipAddr, Ethernet::Address *ethAddr)
Lookup Ethernet address for an IP.
Definition ARP.cpp:86
ARPCache * insertCacheEntry(const IPV4::Address ipAddr)
Insert a new entry to the ARP cache.
Definition ARP.cpp:64
ARPSocket * m_sock
The single ARP socket.
Definition ARP.h:216
Ethernet networking protocol.
Definition Ethernet.h:43
Efficient key -> value lookups.
Definition HashTable.h:45
Internet Protocol Version 4.
Definition IPV4.h:41
u32 Address
IP-address.
Definition IPV4.h:47
Provides the timer of the kernel.
Definition KernelTimer.h:37
Network Device abstract class.
Network protocol abstraction class.
Networking server.
#define PACKED
Ensures strict minimum memory requirements.
Definition Macros.h:159
unsigned short u16
Unsigned 16-bit number.
Definition Types.h:56
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
ARP table cache entry.
Definition ARP.h:53
bool valid
Definition ARP.h:57
Ethernet::Address ethAddr
Definition ARP.h:54
Timer::Info time
Definition ARP.h:55
Size retryCount
Definition ARP.h:56
ARP network packet header.
Definition ARP.h:95
u16 operation
Definition ARP.h:100
Ethernet::Address etherTarget
Definition ARP.h:105
u8 protocolLength
Definition ARP.h:99
IPV4::Address ipSender
Definition ARP.h:103
IPV4::Address ipTarget
Definition ARP.h:106
u16 protocolType
Definition ARP.h:97
Ethernet::Address etherSender
Definition ARP.h:102
u16 hardwareType
Definition ARP.h:96
u8 hardwareLength
Definition ARP.h:98
Ethernet network address.
Definition Ethernet.h:53
Represents a network packet.
Timer information structure.
Definition Timer.h:43