OpenVPN
mbuf.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef MBUF_H
24#define MBUF_H
25
26/*
27 * Handle both multicast and broadcast functions.
28 */
29
30/* define this to enable special test mode */
31/*#define MBUF_TEST*/
32
33#include "basic.h"
34#include "buffer.h"
35
36struct multi_instance;
37
38#define MBUF_INDEX(head, offset, size) (((head) + (offset)) & ((size) - 1))
39/* limited by adjust_power_of_2 and array_mult_safe */
40#define MBUF_SIZE_MAX (ALLOC_SIZE_MAX / sizeof(struct mbuf_item))
41
43{
44 struct buffer buf;
46
47#define MF_UNICAST (1 << 0)
48 unsigned int flags;
49};
50
52{
55};
56
58{
59 unsigned int head;
60 unsigned int len;
61 unsigned int capacity;
62 unsigned int max_queued;
64};
65
66struct mbuf_set *mbuf_init(unsigned int size);
67
68void mbuf_free(struct mbuf_set *ms);
69
70struct mbuf_buffer *mbuf_alloc_buf(const struct buffer *buf);
71
72void mbuf_free_buf(struct mbuf_buffer *mb);
73
74void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item);
75
76bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item);
77
78void mbuf_dereference_instance(struct mbuf_set *ms, struct multi_instance *mi);
79
80static inline bool
81mbuf_defined(const struct mbuf_set *ms)
82{
83 return ms && ms->len;
84}
85
86static inline unsigned int
87mbuf_len(const struct mbuf_set *ms)
88{
89 return ms->len;
90}
91
92static inline int
94{
95 return (int)ms->max_queued;
96}
97
98struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
99
100static inline struct multi_instance *
102{
103 if (mbuf_defined(ms))
104 {
105 return mbuf_peek_dowork(ms);
106 }
107 else
108 {
109 return NULL;
110 }
111}
112
113#endif /* ifndef MBUF_H */
static struct multi_instance * mbuf_peek(struct mbuf_set *ms)
Definition mbuf.h:101
void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item)
Definition mbuf.c:99
struct mbuf_buffer * mbuf_alloc_buf(const struct buffer *buf)
Definition mbuf.c:75
static bool mbuf_defined(const struct mbuf_set *ms)
Definition mbuf.h:81
void mbuf_free_buf(struct mbuf_buffer *mb)
Definition mbuf.c:86
void mbuf_dereference_instance(struct mbuf_set *ms, struct multi_instance *mi)
Definition mbuf.c:163
static unsigned int mbuf_len(const struct mbuf_set *ms)
Definition mbuf.h:87
bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item)
Definition mbuf.c:121
void mbuf_free(struct mbuf_set *ms)
Definition mbuf.c:59
struct multi_instance * mbuf_peek_dowork(struct mbuf_set *ms)
Definition mbuf.c:143
struct mbuf_set * mbuf_init(unsigned int size)
Definition mbuf.c:43
static int mbuf_maximum_queued(const struct mbuf_set *ms)
Definition mbuf.h:93
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
unsigned int flags
Definition mbuf.h:48
struct buffer buf
Definition mbuf.h:44
int refcount
Definition mbuf.h:45
struct mbuf_buffer * buffer
Definition mbuf.h:53
struct multi_instance * instance
Definition mbuf.h:54
struct mbuf_item * array
Definition mbuf.h:63
unsigned int max_queued
Definition mbuf.h:62
unsigned int head
Definition mbuf.h:59
unsigned int len
Definition mbuf.h:60
unsigned int capacity
Definition mbuf.h:61
Server-mode state structure for one single VPN tunnel.
Definition multi.h:102