1 | /* $Id: DHCPD.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DHCP server - protocol logic
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_Dhcpd_DHCPD_h
|
---|
29 | #define VBOX_INCLUDED_SRC_Dhcpd_DHCPD_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "DhcpdInternal.h"
|
---|
35 | #include <iprt/cpp/ministring.h>
|
---|
36 | #include "Config.h"
|
---|
37 | #include "DhcpMessage.h"
|
---|
38 | #include "Db.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * The core of the DHCP server.
|
---|
43 | *
|
---|
44 | * This class is feed DhcpClientMessages that VBoxNetDhcpd has picked up from
|
---|
45 | * the network. After processing a message it returns the appropriate response
|
---|
46 | * (if any) which VBoxNetDhcpd sends out.
|
---|
47 | */
|
---|
48 | class DHCPD
|
---|
49 | {
|
---|
50 | /** The DHCP configuration. */
|
---|
51 | const Config *m_pConfig;
|
---|
52 | /** The lease database. */
|
---|
53 | Db m_db;
|
---|
54 |
|
---|
55 | public:
|
---|
56 | DHCPD();
|
---|
57 |
|
---|
58 | int init(const Config *) RT_NOEXCEPT;
|
---|
59 |
|
---|
60 | DhcpServerMessage *process(const std::unique_ptr<DhcpClientMessage> &req) RT_NOEXCEPT
|
---|
61 | {
|
---|
62 | if (req.get() != NULL)
|
---|
63 | return process(*req.get());
|
---|
64 | return NULL;
|
---|
65 | }
|
---|
66 |
|
---|
67 | DhcpServerMessage *process(DhcpClientMessage &req) RT_NOEXCEPT;
|
---|
68 |
|
---|
69 | private:
|
---|
70 | /** @name DHCP message processing methods
|
---|
71 | * @{ */
|
---|
72 | DhcpServerMessage *i_doDiscover(const DhcpClientMessage &req);
|
---|
73 | DhcpServerMessage *i_doRequest(const DhcpClientMessage &req);
|
---|
74 | DhcpServerMessage *i_doInform(const DhcpClientMessage &req);
|
---|
75 | DhcpServerMessage *i_doDecline(const DhcpClientMessage &req) RT_NOEXCEPT;
|
---|
76 | DhcpServerMessage *i_doRelease(const DhcpClientMessage &req) RT_NOEXCEPT;
|
---|
77 |
|
---|
78 | DhcpServerMessage *i_createMessage(int type, const DhcpClientMessage &req);
|
---|
79 | /** @} */
|
---|
80 |
|
---|
81 | /** @name Lease database handling
|
---|
82 | * @{ */
|
---|
83 | int i_loadLeases() RT_NOEXCEPT;
|
---|
84 | void i_saveLeases() RT_NOEXCEPT;
|
---|
85 | /** @} */
|
---|
86 | };
|
---|
87 |
|
---|
88 | #endif /* !VBOX_INCLUDED_SRC_Dhcpd_DHCPD_h */
|
---|