AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
netbuf.c File Reference

Packet buffers (see net/netbuf.h). More...

#include <core/system.h>
#include <core/arch.h>
#include <mm/mm.h>
#include <net/netbuf.h>

Go to the source code of this file.

Macros

#define NETBUF_KEEP   64
#define NETBUF_PER_PAGE   (PAGE_SIZE / NETBUF_SIZE)

Functions

static void free_push (struct netbuf *nb)
 Puts a netbuf on the free list.
static void free_remove (struct netbuf *nb)
 Takes a netbuf off the free list.
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.

Variables

static struct netbuf * free_netbufs
static size_t free_count

Detailed Description

Packet buffers (see net/netbuf.h).

A netbuf holds one packet: NETBUF_SIZE bytes, two to a page of memory. Freed netbufs are kept on a free list, ready for the next packets, and a page goes back to the page allocator only when all its netbufs are free and the list has enough without them.

Definition in file netbuf.c.

Macro Definition Documentation

◆ NETBUF_KEEP

#define NETBUF_KEEP   64

Definition at line 19 of file netbuf.c.

Referenced by netbuf_free().

◆ NETBUF_PER_PAGE

#define NETBUF_PER_PAGE   (PAGE_SIZE / NETBUF_SIZE)

Definition at line 20 of file netbuf.c.

Referenced by netbuf_free().

Function Documentation

◆ free_push()

void free_push ( struct netbuf * nb)
static

Puts a netbuf on the free list.

Definition at line 26 of file netbuf.c.

References free_count, free_netbufs, netbuf::free_prev, free_push(), netbuf::next, and NULL.

Referenced by free_push(), netbuf_alloc(), and netbuf_free().

◆ free_remove()

void free_remove ( struct netbuf * nb)
static

Takes a netbuf off the free list.

Definition at line 39 of file netbuf.c.

References free_count, free_netbufs, netbuf::free_prev, free_remove(), and netbuf::next.

Referenced by free_remove(), netbuf_alloc(), and netbuf_free().

◆ 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()

Variable Documentation

◆ free_count

size_t free_count
static

Definition at line 23 of file netbuf.c.

Referenced by free_push(), free_remove(), and netbuf_free().

◆ free_netbufs

struct netbuf* free_netbufs
static

Definition at line 22 of file netbuf.c.

Referenced by free_push(), free_remove(), and netbuf_alloc().