mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-09-22 18:43:17 +00:00
.github
.vscode
arch
core
exec
files
include
boot
cpu
filesystem
memory
net
arp.hpp
dhcp.hpp
dns.hpp
eth.hpp
icmpv4.hpp
icmpv6.hpp
ipv4.hpp
ipv6.hpp
nc.hpp
net.hpp
ntp.hpp
tcp.hpp
udp.hpp
stb
syscall
abi.h
acpi.hpp
bitmap.hpp
cargs.h
convert.h
cpu.hpp
crc32.h
cwalk.h
debug.h
disk.hpp
display.hpp
driver.hpp
dumper.hpp
elf.h
exec.hpp
filesystem.hpp
hashmap.hpp
ini.h
intrin.hpp
ints.hpp
io.h
kconfig.hpp
kshell.hpp
lock.hpp
md5.h
memory.hpp
msexec.h
pci.hpp
power.hpp
printf.h
rand.hpp
scheduler.hpp
signal.hpp
smart_ptr.hpp
smp.hpp
symbols.hpp
syscalls.hpp
targp.h
task.hpp
time.hpp
types.h
uart.hpp
vm.hpp
include_std
kshell
library
network
profiling
storage
syscalls
tasking
tests
virtualization
.gdbinit
.gitignore
CREDITS.md
Doxyfile
ISSUES.md
LICENSE.md
LICENSES.md
Makefile
README.md
TODO.md
driver.h
dump.sh
kernel.cpp
kernel.h
kernel_config.cpp
kernel_thread.cpp
kernel_vfs.cpp
syscalls.h
138 lines
3.3 KiB
C++
138 lines
3.3 KiB
C++
/*
|
|
This file is part of Fennix Kernel.
|
|
|
|
Fennix Kernel is free software: you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation, either version 3 of
|
|
the License, or (at your option) any later version.
|
|
|
|
Fennix Kernel is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef __FENNIX_KERNEL_IPv4_H__
|
|
#define __FENNIX_KERNEL_IPv4_H__
|
|
|
|
#include <net/ipv4.hpp>
|
|
#include <net/arp.hpp>
|
|
#include <net/nc.hpp>
|
|
#include <types.h>
|
|
|
|
namespace NetworkIPv4
|
|
{
|
|
struct IPv4Header
|
|
{
|
|
uint8_t IHL : 4;
|
|
uint8_t Version : 4;
|
|
uint8_t TypeOfService;
|
|
uint16_t TotalLength;
|
|
uint16_t Identification;
|
|
uint8_t Flags;
|
|
uint8_t FragmentOffset;
|
|
uint8_t TimeToLive;
|
|
uint8_t Protocol;
|
|
uint16_t HeaderChecksum;
|
|
uint32_t SourceIP;
|
|
uint32_t DestinationIP;
|
|
|
|
/* On wikipedia page we have this: https://en.wikipedia.org/wiki/File:IPv4_Packet-en.svg
|
|
but only the code above works... */
|
|
// uint8_t Version : 4;
|
|
// uint8_t IHL : 4;
|
|
// uint16_t TypeOfService : 8;
|
|
// uint16_t TotalLength : 12;
|
|
// uint16_t Identification : 16;
|
|
// uint16_t Flags : 3;
|
|
// uint16_t FragmentOffset : 13;
|
|
// uint8_t TimeToLive : 8;
|
|
// uint8_t Protocol : 8;
|
|
// uint16_t HeaderChecksum;
|
|
// uint32_t SourceIP;
|
|
// uint32_t DestinationIP;
|
|
};
|
|
|
|
struct IPv4Packet
|
|
{
|
|
IPv4Header Header;
|
|
uint8_t Data[];
|
|
};
|
|
|
|
enum IPv4Protocols
|
|
{
|
|
PROTOCOL_ICMP = 1,
|
|
PROTOCOL_IGMP = 2,
|
|
PROTOCOL_TCP = 6,
|
|
PROTOCOL_UDP = 17,
|
|
PROTOCOL_IPV6 = 41,
|
|
PROTOCOL_ROUTING = 43,
|
|
PROTOCOL_FRAGMENT = 44,
|
|
PROTOCOL_ESP = 50,
|
|
PROTOCOL_AH = 51,
|
|
PROTOCOL_ICMPV6 = 58,
|
|
PROTOCOL_NONE = 59,
|
|
PROTOCOL_DSTOPTS = 60,
|
|
PROTOCOL_ND = 77,
|
|
PROTOCOL_ICLFXBM = 78,
|
|
PROTOCOL_PIM = 103,
|
|
PROTOCOL_COMP = 108,
|
|
PROTOCOL_SCTP = 132,
|
|
PROTOCOL_UDPLITE = 136,
|
|
PROTOCOL_RAW = 255
|
|
};
|
|
|
|
class IPv4 : public NetworkEthernet::EthernetEvents
|
|
{
|
|
private:
|
|
NetworkARP::ARP *ARP;
|
|
NetworkEthernet::Ethernet *Ethernet;
|
|
|
|
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
|
|
|
public:
|
|
InternetProtocol GatewayIP;
|
|
InternetProtocol SubNetworkMaskIP;
|
|
IPv4(NetworkARP::ARP *ARP, NetworkEthernet::Ethernet *Ethernet);
|
|
~IPv4();
|
|
|
|
/**
|
|
* @brief Send an IPv4 packet.
|
|
*
|
|
* @param Data The data to send.
|
|
* @param Length The length of the data.
|
|
* @param Protocol The protocol of the packet.
|
|
* @param DestinationIP The IP address of the destination. (Big-endian)
|
|
*/
|
|
void Send(uint8_t *Data, size_t Length, uint8_t Protocol, InternetProtocol DestinationIP);
|
|
};
|
|
|
|
class IPv4Events
|
|
{
|
|
private:
|
|
uint8_t Protocol;
|
|
|
|
protected:
|
|
IPv4Events(IPv4Protocols Protocol);
|
|
~IPv4Events();
|
|
|
|
public:
|
|
uint8_t GetProtocol() { return Protocol; }
|
|
|
|
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length)
|
|
{
|
|
UNUSED(SourceIP);
|
|
UNUSED(DestinationIP);
|
|
UNUSED(Data);
|
|
UNUSED(Length);
|
|
warn("Not implemented.");
|
|
return false;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // !__FENNIX_KERNEL_IPv4_H__
|