Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
netbuff.c
Go to the documentation of this file.
1#include "netbuff.h"
2#include "init/init.h"
3#include "ioforge/ioforge.h"
4#include "memory/slab.h"
5#include <str.h>
6
7#define NETBUFF_MAX_TEMP 32
8
9static struct slab_cache* netbuff_cache = 0;
10
12static size_t netbuff_temp_count = 0;
13
14INIT(Netbuff) {
15 vxCreateSlabCache(&netbuff_cache, "netbuff", sizeof(struct netbuff), 0,
16 0);
17}
18
20 struct netbuff* netbuff = 0;
21 if (!netbuff_temp_count) {
24 &netbuff->paddr);
25 memset((void*) rawbuffer, 0, NETBUFF_DATA_SIZE);
26 netbuff->head = rawbuffer;
27 netbuff->end = rawbuffer + NETBUFF_DATA_SIZE;
28 } else {
32 }
33
36 netbuff->length = 0;
37
38 return netbuff;
39}
40
41// Dipakai oleh Aplikasi/Layer atas untuk menambahkan payload ke belakang
42void* netbuff_put(struct netbuff* nb, size_t len) {
43 void* current_tail = (void*) nb->tail;
44 nb->tail += len;
45 nb->length += len;
46 return current_tail;
47}
48
49// Dipakai oleh Layer Network (TCP/IP/Eth) untuk menyisipkan header ke depan
50void* netbuff_push(struct netbuff* nb, size_t len) {
51 nb->data -= len; // Mundurkan pointer data ke area headroom
52 nb->length += len;
53 return (void*) nb->data;
54}
55
66
67// void netbuff_insert(struct netbuff* netbuff,)
#define INIT(fn)
Definition init.h:26
void ioforge_dma_free(void *paddr, void *vaddr, size_t size)
void * ioforge_dma_alloc(size_t size, uintptr_t *paddr)
void free_netbuff(struct netbuff *netbuff)
Definition netbuff.c:56
void * netbuff_put(struct netbuff *nb, size_t len)
Definition netbuff.c:42
void * netbuff_push(struct netbuff *nb, size_t len)
Definition netbuff.c:50
struct netbuff * create_netbuff()
Definition netbuff.c:19
static size_t netbuff_temp_count
Definition netbuff.c:12
static struct slab_cache * netbuff_cache
Definition netbuff.c:9
#define NETBUFF_MAX_TEMP
Definition netbuff.c:7
static struct netbuff * netbuff_temp[32]
Definition netbuff.c:11
#define NETBUFF_DATA_SIZE
Definition netbuff.h:6
#define NETBUFF_MAX_HEADROOM
Definition netbuff.h:7
size_t len
Definition oct2bin.h:7
void * vxSlabAlloc(struct slab_cache *cache)
Definition slab.c:93
void slab_free(struct slab_cache *cache, void *obj)
Definition slab.c:235
void vxCreateSlabCache(struct slab_cache **cache, const char *name, const size_t obj_size, size_t alignment, const uintptr_t virt_addr)
Definition slab.c:44
void memset(void *ptr, int value, size_t num)
uint8_t * data
Definition netbuff.h:15
uint8_t * end
Definition netbuff.h:13
uintptr_t paddr
Definition netbuff.h:10
uint8_t * tail
Definition netbuff.h:16
uint16_t length
Definition netbuff.h:18
uint8_t * head
Definition netbuff.h:12
unsigned char uint8_t
Definition type.h:7