The Pedigree Project
0.1
src
modules
system
network-stack
Filter.h
1
/*
2
* Copyright (c) 2008-2014, Pedigree Developers
3
*
4
* Please see the CONTRIB file in the root of the source tree for a full
5
* list of contributors.
6
*
7
* Permission to use, copy, modify, and distribute this software for any
8
* purpose with or without fee is hereby granted, provided that the above
9
* copyright notice and this permission notice appear in all copies.
10
*
11
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
*/
19
20
#ifndef NETWORK_STACK_FILTER_H
21
#define NETWORK_STACK_FILTER_H
22
#include "pedigree/kernel/Spinlock.h"
23
#include "pedigree/kernel/compiler.h"
24
#include "pedigree/kernel/process/WaitQueue.h"
25
#include "pedigree/kernel/processor/types.h"
26
#include "pedigree/kernel/utilities/List.h"
27
28
#include <config.h>
29
30
class
Thread
;
31
34
class
EXPORTED_PUBLIC
NetworkFilter
{
35
public
:
37
NetworkFilter
();
38
40
virtual
~NetworkFilter
();
41
43
static
NetworkFilter
&
instance
() {
44
return
m_Instance;
45
}
46
62
bool
filter(
size_t
level, uintptr_t packet,
size_t
sz);
63
68
size_t
installCallback(
size_t
level,
bool
(*callback)(uintptr_t,
size_t
));
69
79
bool
removeCallback(
size_t
level,
size_t
id
);
80
81
#if (HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS) || PEDIGREE_CONCURRENCY_SMOKE_TESTS
82
using
CallbackPinHook = void (*)(bool (*)(uintptr_t, size_t),
size_t
);
83
static
void
setCallbackPinHook(CallbackPinHook hook);
84
#endif
85
86
private
:
87
struct
CallbackItem
{
88
size_t
id;
89
bool (*callback)(uintptr_t, size_t);
90
size_t
inFlight;
91
size_t
removers;
92
bool
enabled;
93
bool
draining;
94
WaitQueue
drainWaiters;
95
};
96
97
struct
ActiveInvocation
{
98
CallbackItem
* item;
99
Thread
* thread;
100
ActiveInvocation
* next;
101
};
102
103
void
drainCallback(
size_t
level,
CallbackItem
* item);
104
bool
isCallbackInvocation(
Thread
* thread)
const
;
105
106
static
NetworkFilter
m_Instance;
107
108
List<CallbackItem*>
m_Callbacks[4];
109
Spinlock
m_Lock;
110
size_t
m_NextCallbackId;
111
ActiveInvocation
* m_pActiveInvocations;
112
113
#if (HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS) || PEDIGREE_CONCURRENCY_SMOKE_TESTS
114
static
CallbackPinHook m_CallbackPinHook;
115
#endif
116
};
117
118
#endif
// NETWORK_STACK_FILTER_H
List
Definition
List.h:61
NetworkFilter
Definition
Filter.h:34
NetworkFilter::instance
static NetworkFilter & instance()
Definition
Filter.h:43
Spinlock
Definition
Spinlock.h:27
Thread
Definition
Thread.h:77
WaitQueue
Definition
WaitQueue.h:28
NetworkFilter::ActiveInvocation
Definition
Filter.h:97
NetworkFilter::CallbackItem
Definition
Filter.h:87
Generated on Sat Oct 3 2026 06:38:07 for The Pedigree Project by
1.9.8