AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
netbuf.h File Reference
#include <core/system.h>
#include <core/panic.h>

Go to the source code of this file.

Data Structures

struct  netbuf
 A packet (net/netbuf.c). More...

Macros

#define NETBUF_SIZE   2048
#define NETBUF_HEADROOM   128
#define NETBUF_END(nb)

Functions

struct netbuf * netbuf_alloc (void)
 Allocates a netbuf, empty, with room for the headers that will be put in front of its data.
void netbuf_free (struct netbuf *nb)
 Frees a netbuf.
static void * netbuf_push (struct netbuf *nb, size_t size)
 Makes room for a header of size bytes before the data, and returns it.
static void * netbuf_pull (struct netbuf *nb, size_t size)
 Takes the header of size bytes off the front of the packet, and returns it, or NULL if the packet is shorter.
static void * netbuf_put (struct netbuf *nb, size_t size)
 Adds size bytes at the end of the packet, and returns them, or NULL if there's no room.

Macro Definition Documentation

◆ NETBUF_END

#define NETBUF_END ( nb)
Value:
((uint8_t *) (nb) + NETBUF_SIZE)
#define NETBUF_SIZE
Definition netbuf.h:40
unsigned char uint8_t
Definition stddef.h:20

Definition at line 44 of file netbuf.h.

Referenced by netbuf_put().

◆ NETBUF_HEADROOM

#define NETBUF_HEADROOM   128

Definition at line 41 of file netbuf.h.

Referenced by netbuf_alloc().

◆ NETBUF_SIZE

#define NETBUF_SIZE   2048

Definition at line 40 of file netbuf.h.

Referenced by inet_sock_deliver(), netbuf_alloc(), netbuf_free(), rx_poll(), and socket_inet_recv().

Function Documentation

◆ netbuf_alloc()

struct netbuf * netbuf_alloc ( void )

Allocates a netbuf, empty, with room for the headers that will be put in front of its data.

Returns
the netbuf, or NULL if there was no memory for it

Definition at line 58 of file netbuf.c.

References arch_phys_map(), netbuf::data, free_netbufs, free_push(), free_remove(), netbuf::len, mm_page_alloc(), mm_page_dealloc(), mm_page_incref(), netbuf_alloc(), NETBUF_HEADROOM, NETBUF_SIZE, netbuf::netif, netbuf::next, NULL, vm_page::off, vm_page::paddr, netbuf::page, and PAGE_SIZE.

Referenced by arp_request(), icmp_unreachable(), loopback_transmit(), netbuf_alloc(), rx_poll(), segment(), socket_inet_send(), and tcp_reply_rst().

◆ netbuf_free()

◆ netbuf_pull()

void * netbuf_pull ( struct netbuf * nb,
size_t size )
inlinestatic

Takes the header of size bytes off the front of the packet, and returns it, or NULL if the packet is shorter.

Definition at line 64 of file netbuf.h.

References netbuf::data, netbuf::len, netbuf_pull(), and NULL.

Referenced by ether_input(), ipv4_input(), netbuf_pull(), and udp_input().

◆ netbuf_push()

void * netbuf_push ( struct netbuf * nb,
size_t size )
inlinestatic

Makes room for a header of size bytes before the data, and returns it.

Panics if there's no room: the headroom is always enough.

Definition at line 52 of file netbuf.h.

References netbuf::data, netbuf::len, netbuf_push(), and panic.

Referenced by ether_output(), ipv4_output(), netbuf_push(), segment(), socket_inet_send(), and tcp_reply_rst().

◆ netbuf_put()

void * netbuf_put ( struct netbuf * nb,
size_t size )
inlinestatic

Adds size bytes at the end of the packet, and returns them, or NULL if there's no room.

Definition at line 77 of file netbuf.h.

References netbuf::data, netbuf::len, NETBUF_END, and NULL.