~ubuntu-branches/ubuntu/saucy/openvpn/saucy

« back to all changes in this revision

Viewing changes to mbuf.h

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Gonzalez Iniesta
  • Date: 2005-01-05 19:03:11 UTC
  • mto: (1.4.1) (10.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050105190311-d0uioiqtor5xbzre
Tags: upstream-1.99+2.rc6
ImportĀ upstreamĀ versionĀ 1.99+2.rc6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2004 James Yonan <jim@yonan.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 as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program (see the file COPYING included with this
 
22
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 
23
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
 
 
26
#ifndef MBUF_H
 
27
#define MBUF_H
 
28
 
 
29
/*
 
30
 * Handle both multicast and broadcast functions.
 
31
 */
 
32
 
 
33
#if P2MP
 
34
 
 
35
/* define this to enable special test mode */
 
36
/*#define MBUF_TEST*/
 
37
 
 
38
#include "basic.h"
 
39
#include "buffer.h"
 
40
 
 
41
struct multi_instance;
 
42
 
 
43
#define MBUF_INDEX(head, offset, size) (((head) + (offset)) & ((size)-1))
 
44
 
 
45
struct mbuf_buffer
 
46
{
 
47
  struct buffer buf;
 
48
  int refcount;
 
49
 
 
50
# define MF_UNICAST (1<<0)
 
51
  unsigned int flags;
 
52
};
 
53
 
 
54
struct mbuf_item
 
55
{
 
56
  struct mbuf_buffer *buffer;
 
57
  struct multi_instance *instance;
 
58
};
 
59
 
 
60
struct mbuf_set
 
61
{
 
62
  MUTEX_DEFINE (mutex);
 
63
  unsigned int head;
 
64
  unsigned int len;
 
65
  unsigned int capacity;
 
66
  unsigned int max_queued;
 
67
  struct mbuf_item *array;
 
68
};
 
69
 
 
70
struct mbuf_set *mbuf_init (unsigned int size);
 
71
void mbuf_free (struct mbuf_set *ms);
 
72
 
 
73
struct mbuf_buffer *mbuf_alloc_buf (const struct buffer *buf);
 
74
void mbuf_free_buf (struct mbuf_buffer *mb);
 
75
 
 
76
void mbuf_add_item (struct mbuf_set *ms, const struct mbuf_item *item);
 
77
 
 
78
bool mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item, const bool lock);
 
79
 
 
80
void mbuf_dereference_instance (struct mbuf_set *ms, struct multi_instance *mi);
 
81
 
 
82
static inline bool
 
83
mbuf_defined (const struct mbuf_set *ms)
 
84
{
 
85
  return ms && ms->len;
 
86
}
 
87
 
 
88
static inline bool
 
89
mbuf_len (const struct mbuf_set *ms)
 
90
{
 
91
  return ms->len;
 
92
}
 
93
 
 
94
static inline int
 
95
mbuf_maximum_queued (const struct mbuf_set *ms)
 
96
{
 
97
  return (int) ms->max_queued;
 
98
}
 
99
 
 
100
static inline struct multi_instance *
 
101
mbuf_peek (struct mbuf_set *ms)
 
102
{
 
103
  struct multi_instance *mbuf_peek_dowork (struct mbuf_set *ms);
 
104
  if (mbuf_defined (ms))
 
105
    return mbuf_peek_dowork (ms);
 
106
  else
 
107
    return NULL;
 
108
}
 
109
 
 
110
#endif
 
111
#endif