The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ipv4.c File Reference

IPv4 (see ipv4.h). More...

#include "ipv4.h"
#include "arp.h"
#include "byteorder.h"
#include "checksum.h"
#include "common/memory.h"
#include "ethernet.h"
#include "icmp.h"
#include "tcp.h"
#include "udp.h"
#include "kernel/memory/heap.h"

Macros

#define VERSION_IHL   0x45
#define DEFAULT_TTL   64
#define FLAG_DF   0x4000
#define FLAG_MF   0x2000
#define OFFSET_MASK   0x1FFF
#define LOOPBACK_NET   0x7F

Functions

void ipv4_receive (netif_t *netif, const uint8_t *packet, uint32_t length)
 a packet from an interface (net_lock held).
netif_t * ipv4_route (uint32_t dst, uint32_t *next_hop)
 the interface a packet to dst goes out on, and the host it goes to first (dst, or a gateway).
uint32_t ipv4_pseudo_sum (uint32_t source, uint32_t dst, uint8_t protocol, uint32_t length)
 the sum of the pseudo-header of UDP and TCP (the addresses, the protocol, the length), to start their checksum with.
uint32_t ipv4_source_for (uint32_t dst)
 the source address a packet to dst gets (net_lock held), 0 if there is no route.
bool ipv4_init (void)
 get the send buffer (from net_init).
bool ipv4_send (uint32_t source, uint32_t dst, uint8_t protocol, const void *payload, uint32_t length)
 send a payload to dst (net_lock held).

Variables

ipv4_stats_t ipv4_stats

Detailed Description

IPv4 (see ipv4.h).

Macro Definition Documentation

◆ VERSION_IHL

#define VERSION_IHL   0x45

◆ DEFAULT_TTL

#define DEFAULT_TTL   64

◆ FLAG_DF

#define FLAG_DF   0x4000

◆ FLAG_MF

#define FLAG_MF   0x2000

◆ OFFSET_MASK

#define OFFSET_MASK   0x1FFF

◆ LOOPBACK_NET

#define LOOPBACK_NET   0x7F

Function Documentation

◆ ipv4_receive()

void ipv4_receive ( netif_t * netif,
const uint8_t * packet,
uint32_t length )

a packet from an interface (net_lock held).

◆ ipv4_route()

netif_t * ipv4_route ( uint32_t dst,
uint32_t * next_hop )

the interface a packet to dst goes out on, and the host it goes to first (dst, or a gateway).

net_lock held.

Returns
NULL if there is no route.

◆ ipv4_pseudo_sum()

uint32_t ipv4_pseudo_sum ( uint32_t source,
uint32_t dst,
uint8_t protocol,
uint32_t length )

the sum of the pseudo-header of UDP and TCP (the addresses, the protocol, the length), to start their checksum with.

◆ ipv4_source_for()

uint32_t ipv4_source_for ( uint32_t dst)

the source address a packet to dst gets (net_lock held), 0 if there is no route.

◆ ipv4_init()

bool ipv4_init ( void )

get the send buffer (from net_init).

Returns
false if there is no memory.

◆ ipv4_send()

bool ipv4_send ( uint32_t source,
uint32_t dst,
uint8_t protocol,
const void * payload,
uint32_t length )

send a payload to dst (net_lock held).

Parameters
sourcethe source address, or 0 for the address of the interface the packet goes out on.
Returns
false if there is no route or the device has no room.

Variable Documentation

◆ ipv4_stats

ipv4_stats_t ipv4_stats