The Pedigree Project 0.1
network-namespace.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef POSIX_NETWORK_NAMESPACE_H
3#define POSIX_NETWORK_NAMESPACE_H
4
5#include "pedigree/kernel/process/Mutex.h"
6#include "pedigree/kernel/utilities/Tree.h"
7
8#include "user-namespace.h"
9
10class NetworkSyscalls;
13
14EXPORTED_PUBLIC NetworkNamespaceRef posix_sandbox_network(Thread& task);
15EXPORTED_PUBLIC bool posix_sandbox_set_network(Thread& task, const NetworkNamespaceRef& space);
16
17class EXPORTED_PUBLIC PosixNetworkNamespace {
18 public:
19 explicit PosixNetworkNamespace(const UserNamespaceRef& owner);
20 const UserNamespaceRef& owner() const {
21 return m_Owner;
22 }
23 uint64_t identity() const {
24 return m_Identity;
25 }
26 bool usable() const;
27 int configureAddress(uint32_t address, unsigned prefix, bool exclusive);
28 int configureLink(uint32_t flags, uint32_t changed);
29 uint32_t flags() const;
30 uint32_t address() const;
31 uint64_t reserve(int type, uint32_t address, uint16_t& port);
32 void release(uint64_t token);
33 uint32_t reserveRoutePort(uint32_t preferred, bool fixed);
34 void releaseRoutePort(uint32_t port);
35 bool find(int type, uint32_t address, uint16_t port, uint32_t& boundAddress, uint64_t& token);
36
37 private:
38 const UserNamespaceRef m_Owner;
39 const uint64_t m_Identity;
40 mutable Mutex m_Lock;
41 bool m_Up = false;
42 uint32_t m_Address = 0;
43 uint16_t m_NextPort = 32768;
44 uint64_t m_NextToken = 0;
45 Tree<uint64_t, uint64_t> m_Bindings;
46 Tree<uint32_t, bool> m_RoutePorts;
47 uint32_t m_NextRoutePort = 0x80000000;
48};
49
50EXPORTED_PUBLIC bool posix_network_namespace_prepare(const UserNamespaceRef& owner,
51 NetworkNamespaceRef& result);
52EXPORTED_PUBLIC NetworkSyscalls* posix_network_socket(int domain, int type, int protocol,
53 const NetworkNamespaceRef& space);
54NetworkSyscalls* posix_route_netlink_socket(int type, int protocol,
55 const NetworkNamespaceRef& space);
56EXPORTED_PUBLIC int posix_network_ioctl(NetworkSyscalls& socket, unsigned long request,
57 uintptr_t argument);
58
59#endif
Definition Mutex.h:56
A key/value dictionary.
Definition Tree.h:33