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