14#ifndef KERNEL_NET_IPV4_H
15#define KERNEL_NET_IPV4_H
18#include <kernel/net.h>
19#include <kernel/types.h>
21#include <utils/compiler.h>
31#define IPV4_MIN_LENGTH 20
33#define IPV4_DEFAULT_TTL 64
38struct PACKED ALIGNED(sizeof(uint16_t)) ipv4_header {
39#if defined(ARCH_LITTLE_ENDIAN)
47 __be uint16_t tot_len;
49 __be uint16_t frag_off;
59#define IPV4_FRAG_MASK 0x1FFF
60#define IPV4_RESERVED (0x4 << 13)
61#define IPV4_NOFRAG (0x2 << 13)
62#define IPV4_MORE_FRAG (0x1 << 13)
67 return ntohs(iphdr->frag_off) & IPV4_FRAG_MASK;
73 return ntohs(iphdr->frag_off) & IPV4_MORE_FRAG;
79 return ntohs(iphdr->frag_off) & (IPV4_MORE_FRAG | IPV4_FRAG_MASK);
83static inline bool ipv4_is_multicast(__be ipv4_t addr)
85 return (ntohl(addr) >> 28) == 0xE;
89static inline bool ipv4_is_broadcast(__be ipv4_t addr)
91 return addr == 0XFFFFFFFF;
104static inline __be ipv4_t
IPV4(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
106 return htonl(a << 24 | b << 16 | c << 8 | d);
109#define FMT_IP "%u.%u.%u.%u"
111 ((uint8_t *)&ip)[0], ((uint8_t *)&ip)[1], ((uint8_t *)&ip)[2], \
#define IPV4_MIN_LENGTH
Minimum size of an IP header.
Definition: ipv4.h:31
error_t ipv4_receive_packet(struct packet *packet)
Process a newly received IP packet.
Definition: ipv4.c:63
static uint16_t ipv4_fragment_offset(const struct ipv4_header *iphdr)
Definition: ipv4.h:65
static __be ipv4_t IPV4(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Helper to quickly generate an IPv4 address.
Definition: ipv4.h:104
static bool ipv4_is_fragmented(const struct ipv4_header *iphdr)
Definition: ipv4.h:77
struct packet * ipv4_build_packet(const struct net_route *, u8 protocol, const void *payload, size_t)
Build an IP packet The L2/L3 headers are filled using the routing information.
Definition: ipv4.c:147
static bool ipv4_more_framents(const struct ipv4_header *iphdr)
Definition: ipv4.h:71
Structure of the page fault's error code https://wiki.osdev.org/Exceptions#Page_Fault.
Definition: mmu.c:587
Routing structure.
Definition: route.h:14
A network packet.
Definition: packet.h:51
void * payload
Start of the packet's content (L4 and beyond)
Definition: packet.h:73