AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
netbuf.h
Go to the documentation of this file.
1
#ifndef _NET_NETBUF_H
2
#define _NET_NETBUF_H
3
4
#include <
core/system.h
>
5
#include <
core/panic.h
>
6
7
struct
netif
;
8
16
struct
netbuf
{
17
struct
netbuf
*
next
;
/* the next one in a queue, or on the free list */
18
struct
netif
*
netif
;
/* the interface it came in on */
19
uint8_t
*
data
;
20
size_t
len
;
21
22
int
loopback
;
/* whether it's an IPv4 packet sent to ourselves */
23
24
/* where a datagram came from (in a socket's queue) */
25
uint32_t
src_ip
;
26
uint16_t
src_port
;
27
28
/* for a TCP segment that came before its turn: where its data goes,
29
* and whether a FIN follows it */
30
uint32_t
seq
;
31
int
fin
;
32
33
/* its page of memory, and the netbuf before it on the free list */
34
paddr_t
page
;
35
struct
netbuf
*
free_prev
;
36
};
37
38
/* A netbuf's size, and the room kept before the data for the headers
39
* that the layers below add. */
40
#define NETBUF_SIZE 2048
41
#define NETBUF_HEADROOM 128
42
43
/* The end of a netbuf's room. */
44
#define NETBUF_END(nb) ((uint8_t *) (nb) + NETBUF_SIZE)
45
46
/* Allocates a netbuf, or frees one. */
47
struct
netbuf
*
netbuf_alloc
(
void
);
48
void
netbuf_free
(
struct
netbuf
*nb);
49
52
static
inline
void
*
netbuf_push
(
struct
netbuf
*nb,
size_t
size)
53
{
54
if
(nb->
data
- size < (
uint8_t
*) (nb + 1))
55
panic
(
"netbuf: no room for a header"
);
56
57
nb->
data
-= size;
58
nb->
len
+= size;
59
return
nb->
data
;
60
}
61
64
static
inline
void
*
netbuf_pull
(
struct
netbuf
*nb,
size_t
size)
65
{
66
if
(nb->
len
< size)
67
return
NULL
;
68
69
void
*header = nb->
data
;
70
nb->
data
+= size;
71
nb->
len
-= size;
72
return
header;
73
}
74
77
static
inline
void
*
netbuf_put
(
struct
netbuf
*nb,
size_t
size)
78
{
79
if
(nb->
data
+ nb->
len
+ size >
NETBUF_END
(nb))
80
return
NULL
;
81
82
void
*tail = nb->
data
+ nb->
len
;
83
nb->
len
+= size;
84
return
tail;
85
}
86
87
#endif
/* ! _NET_NETBUF_H */
paddr_t
uint64_t paddr_t
Definition
mm.h:39
panic
#define panic(s)
Definition
panic.h:15
panic.h
system.h
netbuf_push
static void * netbuf_push(struct netbuf *nb, size_t size)
Makes room for a header of size bytes before the data, and returns it.
Definition
netbuf.h:52
netbuf_put
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.
Definition
netbuf.h:77
netbuf_pull
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 ...
Definition
netbuf.h:64
netbuf_free
void netbuf_free(struct netbuf *nb)
Frees a netbuf.
Definition
netbuf.c:99
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.
Definition
netbuf.c:58
NETBUF_END
#define NETBUF_END(nb)
Definition
netbuf.h:44
NULL
#define NULL
Definition
stddef.h:27
uint32_t
unsigned int uint32_t
Definition
stddef.h:22
uint8_t
unsigned char uint8_t
Definition
stddef.h:20
uint16_t
unsigned short int uint16_t
Definition
stddef.h:21
netbuf
A packet (net/netbuf.c).
Definition
netbuf.h:16
netbuf::loopback
int loopback
Definition
netbuf.h:22
netbuf::fin
int fin
Definition
netbuf.h:31
netbuf::src_ip
uint32_t src_ip
Definition
netbuf.h:25
netbuf::seq
uint32_t seq
Definition
netbuf.h:30
netbuf::netif
struct netif * netif
Definition
netbuf.h:18
netbuf::next
struct netbuf * next
Definition
netbuf.h:17
netbuf::data
uint8_t * data
Definition
netbuf.h:19
netbuf::src_port
uint16_t src_port
Definition
netbuf.h:26
netbuf::page
paddr_t page
Definition
netbuf.h:34
netbuf::free_prev
struct netbuf * free_prev
Definition
netbuf.h:35
netbuf::len
size_t len
Definition
netbuf.h:20
netif
A network interface (net/netif.c): a device that sends and receives Ethernet frames,...
Definition
netif.h:16
kernel
include
net
netbuf.h
Generated by
1.18.0