The Pedigree Project
0.1
src
modules
system
network-stack
NetworkStack.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 MACHINE_NETWORK_STACK_H
21
#define MACHINE_NETWORK_STACK_H
22
#include "pedigree/kernel/compiler.h"
23
#include "pedigree/kernel/machine/Network.h"
24
#include "pedigree/kernel/process/Mutex.h"
25
#include "pedigree/kernel/process/OperationBarrier.h"
26
#include "pedigree/kernel/processor/types.h"
27
#include "pedigree/kernel/utilities/MemoryPool.h"
28
#include "pedigree/kernel/utilities/String.h"
29
#include "pedigree/kernel/utilities/Tree.h"
30
#include "pedigree/kernel/utilities/Vector.h"
31
32
#include <config.h>
33
34
// lwIP network interface type
35
struct
netif
;
36
42
class
EXPORTED_PUBLIC
NetworkStack
{
43
public
:
51
class
EXPORTED_PUBLIC
DeviceLease
{
52
public
:
53
DeviceLease
();
54
DeviceLease
(
DeviceLease
&& other);
55
~DeviceLease
();
56
57
DeviceLease
& operator=(
DeviceLease
&& other);
58
59
Network
* device()
const
{
60
return
m_Device;
61
}
62
63
struct
netif
* interface()
const
{
64
return
m_Interface;
65
}
66
67
explicit
operator
bool()
const
{
68
return
m_Device !=
nullptr
;
69
}
70
71
private
:
72
friend
class
NetworkStack
;
73
74
DeviceLease
(
Network
* device,
struct
netif
* interface,
OperationBarrier::Lease
&& lease);
75
76
DeviceLease
(
const
DeviceLease
&) =
delete
;
77
DeviceLease
& operator=(
const
DeviceLease
&) =
delete
;
78
79
Network
* m_Device;
80
struct
netif
* m_Interface;
81
OperationBarrier::Lease
m_Lease;
82
};
83
84
NetworkStack
();
85
virtual
~NetworkStack
();
86
88
static
NetworkStack
&
instance
() {
89
return
*__atomic_load_n(&stack, __ATOMIC_ACQUIRE);
90
}
91
92
static
NetworkStack
* instanceIfAvailable() {
93
return
__atomic_load_n(&stack, __ATOMIC_ACQUIRE);
94
}
95
97
void
receive(
size_t
nBytes, uintptr_t packet,
Network
* pCard, uint32_t offset);
98
100
void
receive(
size_t
nBytes, uintptr_t packet,
const
DeviceLease& device, uint32_t offset);
101
103
void
registerDevice(
Network
* pDevice);
104
106
MUST_USE_RESULT
bool
acquireDevice(
size_t
n, DeviceLease& lease);
107
109
MUST_USE_RESULT
bool
acquireDevice(
Network
* pDevice, DeviceLease& lease);
110
112
void
deRegisterDevice(
Network
* pDevice);
113
115
inline
MemoryPool
&
getMemPool
() {
116
return
m_MemPool;
117
}
118
119
private
:
120
struct
DeviceRegistration;
121
122
static
NetworkStack
* stack;
123
125
Vector<Network*>
m_Children
;
126
128
MemoryPool
m_MemPool
;
129
130
#if THREADS || UTILITY_LINUX
131
Mutex
m_Lock;
132
#endif
133
135
size_t
m_NextInterfaceNumber
;
136
138
Tree<Network*, DeviceRegistration*>
m_Registrations
;
139
};
140
141
#endif
MemoryPool
Definition
MemoryPool.h:60
Mutex
Definition
Mutex.h:56
NetworkStack::DeviceLease
Definition
NetworkStack.h:51
NetworkStack
Definition
NetworkStack.h:42
NetworkStack::getMemPool
MemoryPool & getMemPool()
Definition
NetworkStack.h:115
NetworkStack::m_NextInterfaceNumber
size_t m_NextInterfaceNumber
Definition
NetworkStack.h:135
NetworkStack::m_MemPool
MemoryPool m_MemPool
Definition
NetworkStack.h:128
NetworkStack::m_Registrations
Tree< Network *, DeviceRegistration * > m_Registrations
Definition
NetworkStack.h:138
NetworkStack::instance
static NetworkStack & instance()
Definition
NetworkStack.h:88
NetworkStack::m_Children
Vector< Network * > m_Children
Definition
NetworkStack.h:125
Network
Definition
Network.h:65
OperationBarrier::Lease
Definition
OperationBarrier.h:26
Tree
A key/value dictionary.
Definition
Tree.h:33
Vector
A vector / dynamic array.
Definition
Vector.h:33
MUST_USE_RESULT
#define MUST_USE_RESULT
Definition
system/include/pedigree/kernel/compiler.h:70
netif
Definition
netif.h:244
Generated on Sat Oct 3 2026 06:38:07 for The Pedigree Project by
1.9.8