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-2024 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, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef MBUF_H
25 #define MBUF_H
26 
27 /*
28  * Handle both multicast and broadcast functions.
29  */
30 
31 /* define this to enable special test mode */
32 /*#define MBUF_TEST*/
33 
34 #include "basic.h"
35 #include "buffer.h"
36 
37 struct multi_instance;
38 
39 #define MBUF_INDEX(head, offset, size) (((head) + (offset)) & ((size)-1))
40 
42 {
43  struct buffer buf;
44  int refcount;
45 
46 #define MF_UNICAST (1<<0)
47  unsigned int flags;
48 };
49 
50 struct mbuf_item
51 {
54 };
55 
56 struct mbuf_set
57 {
58  unsigned int head;
59  unsigned int len;
60  unsigned int capacity;
61  unsigned int max_queued;
62  struct mbuf_item *array;
63 };
64 
65 struct mbuf_set *mbuf_init(unsigned int size);
66 
67 void mbuf_free(struct mbuf_set *ms);
68 
69 struct mbuf_buffer *mbuf_alloc_buf(const struct buffer *buf);
70 
71 void mbuf_free_buf(struct mbuf_buffer *mb);
72 
73 void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item);
74 
75 bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item);
76 
77 void mbuf_dereference_instance(struct mbuf_set *ms, struct multi_instance *mi);
78 
79 static inline bool
80 mbuf_defined(const struct mbuf_set *ms)
81 {
82  return ms && ms->len;
83 }
84 
85 static inline unsigned int
86 mbuf_len(const struct mbuf_set *ms)
87 {
88  return ms->len;
89 }
90 
91 static inline int
92 mbuf_maximum_queued(const struct mbuf_set *ms)
93 {
94  return (int) ms->max_queued;
95 }
96 
97 struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms);
98 
99 static inline struct multi_instance *
100 mbuf_peek(struct mbuf_set *ms)
101 {
102  if (mbuf_defined(ms))
103  {
104  return mbuf_peek_dowork(ms);
105  }
106  else
107  {
108  return NULL;
109  }
110 }
111 
112 #endif /* ifndef MBUF_H */
multi_instance
Server-mode state structure for one single VPN tunnel.
Definition: multi.h:101
mbuf_defined
static bool mbuf_defined(const struct mbuf_set *ms)
Definition: mbuf.h:80
mbuf_dereference_instance
void mbuf_dereference_instance(struct mbuf_set *ms, struct multi_instance *mi)
Definition: mbuf.c:152
mbuf_init
struct mbuf_set * mbuf_init(unsigned int size)
Definition: mbuf.c:39
mbuf_set
Definition: mbuf.h:56
mbuf_free_buf
void mbuf_free_buf(struct mbuf_buffer *mb)
Definition: mbuf.c:76
mbuf_peek
static struct multi_instance * mbuf_peek(struct mbuf_set *ms)
Definition: mbuf.h:100
mbuf_buffer::refcount
int refcount
Definition: mbuf.h:44
mbuf_free
void mbuf_free(struct mbuf_set *ms)
Definition: mbuf.c:49
mbuf_alloc_buf
struct mbuf_buffer * mbuf_alloc_buf(const struct buffer *buf)
Definition: mbuf.c:65
mbuf_extract_item
bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item)
Definition: mbuf.c:111
mbuf_set::len
unsigned int len
Definition: mbuf.h:59
mbuf_set::max_queued
unsigned int max_queued
Definition: mbuf.h:61
mbuf_item::instance
struct multi_instance * instance
Definition: mbuf.h:53
mbuf_buffer::buf
struct buffer buf
Definition: mbuf.h:43
buffer
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
mbuf_item
Definition: mbuf.h:50
buffer.h
mbuf_set::head
unsigned int head
Definition: mbuf.h:58
mbuf_maximum_queued
static int mbuf_maximum_queued(const struct mbuf_set *ms)
Definition: mbuf.h:92
mbuf_buffer
Definition: mbuf.h:41
mbuf_buffer::flags
unsigned int flags
Definition: mbuf.h:47
basic.h
mbuf_peek_dowork
struct multi_instance * mbuf_peek_dowork(struct mbuf_set *ms)
Definition: mbuf.c:132
mbuf_set::capacity
unsigned int capacity
Definition: mbuf.h:60
mbuf_len
static unsigned int mbuf_len(const struct mbuf_set *ms)
Definition: mbuf.h:86
mbuf_item::buffer
struct mbuf_buffer * buffer
Definition: mbuf.h:52
mbuf_set::array
struct mbuf_item * array
Definition: mbuf.h:62
mbuf_add_item
void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item)
Definition: mbuf.c:89