diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-30 06:33:17 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-30 06:33:17 +0100 |
commit | 20e9e0920d400575478820978b71dd766af725e4 (patch) | |
tree | ad8e18faa6e03e7db306c817210c7fab1602b888 /src/fastd.h | |
parent | f4b53bd0634bc7a54aa5da72d9e7a079f120d821 (diff) | |
download | fastd-20e9e0920d400575478820978b71dd766af725e4.tar fastd-20e9e0920d400575478820978b71dd766af725e4.zip |
Move buffer-related functions to a new header and add some more utility functions
Diffstat (limited to 'src/fastd.h')
-rw-r--r-- | src/fastd.h | 45 |
1 files changed, 1 insertions, 44 deletions
diff --git a/src/fastd.h b/src/fastd.h index 3df0ad1..76a71da 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -30,6 +30,7 @@ #include "compat.h" #include "types.h" #include "dlist.h" +#include "buffer.h" #include "log.h" #include <errno.h> @@ -43,14 +44,6 @@ #include <sys/uio.h> -struct fastd_buffer { - void *base; - size_t base_len; - - void *data; - size_t len; -}; - struct __attribute__((__packed__)) fastd_eth_addr { uint8_t data[ETH_ALEN]; }; @@ -346,42 +339,6 @@ static inline size_t alignto(size_t l, size_t a) { } -static inline fastd_buffer_t fastd_buffer_alloc(const fastd_context_t *ctx, size_t len, size_t head_space, size_t tail_space) { - size_t base_len = head_space+len+tail_space; - void *ptr; - int err = posix_memalign(&ptr, 16, base_len); - if (err) - exit_error(ctx, "posix_memalign: %s", strerror(err)); - - return (fastd_buffer_t){ .base = ptr, .base_len = base_len, .data = ptr+head_space, .len = len }; -} - -static inline fastd_buffer_t fastd_buffer_dup(const fastd_context_t *ctx, fastd_buffer_t buffer, size_t head_space, size_t tail_space) { - fastd_buffer_t new_buffer = fastd_buffer_alloc(ctx, buffer.len, head_space, tail_space); - memcpy(new_buffer.data, buffer.data, buffer.len); - return new_buffer; -} - -static inline void fastd_buffer_free(fastd_buffer_t buffer) { - free(buffer.base); -} - -static inline void fastd_buffer_pull_head(const fastd_context_t *ctx, fastd_buffer_t *buffer, size_t len) { - buffer->data -= len; - buffer->len += len; - - if (buffer->data < buffer->base) - exit_bug(ctx, "tried to pull buffer across head"); -} - -static inline void fastd_buffer_push_head(const fastd_context_t *ctx, fastd_buffer_t *buffer, size_t len) { - if (buffer->len < len) - exit_bug(ctx, "tried to push buffer across tail"); - - buffer->data += len; - buffer->len -= len; -} - static inline size_t fastd_max_inner_packet(const fastd_context_t *ctx) { switch (ctx->conf->mode) { case MODE_TAP: |