1 | /* $Id: DHCPD.h 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DHCP server - protocol logic
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_Dhcpd_DHCPD_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Dhcpd_DHCPD_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include "DhcpdInternal.h"
|
---|
25 | #include <iprt/cpp/ministring.h>
|
---|
26 | #include "Config.h"
|
---|
27 | #include "DhcpMessage.h"
|
---|
28 | #include "Db.h"
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * The core of the DHCP server.
|
---|
33 | *
|
---|
34 | * This class is feed DhcpClientMessages that VBoxNetDhcpd has picked up from
|
---|
35 | * the network. After processing a message it returns the appropriate response
|
---|
36 | * (if any) which VBoxNetDhcpd sends out.
|
---|
37 | */
|
---|
38 | class DHCPD
|
---|
39 | {
|
---|
40 | /** The DHCP configuration. */
|
---|
41 | const Config *m_pConfig;
|
---|
42 | /** The lease database. */
|
---|
43 | Db m_db;
|
---|
44 |
|
---|
45 | public:
|
---|
46 | DHCPD();
|
---|
47 |
|
---|
48 | int init(const Config *) RT_NOEXCEPT;
|
---|
49 |
|
---|
50 | DhcpServerMessage *process(const std::unique_ptr<DhcpClientMessage> &req) RT_NOEXCEPT
|
---|
51 | {
|
---|
52 | if (req.get() != NULL)
|
---|
53 | return process(*req.get());
|
---|
54 | return NULL;
|
---|
55 | }
|
---|
56 |
|
---|
57 | DhcpServerMessage *process(DhcpClientMessage &req) RT_NOEXCEPT;
|
---|
58 |
|
---|
59 | private:
|
---|
60 | /** @name DHCP message processing methods
|
---|
61 | * @{ */
|
---|
62 | DhcpServerMessage *i_doDiscover(const DhcpClientMessage &req);
|
---|
63 | DhcpServerMessage *i_doRequest(const DhcpClientMessage &req);
|
---|
64 | DhcpServerMessage *i_doInform(const DhcpClientMessage &req);
|
---|
65 | DhcpServerMessage *i_doDecline(const DhcpClientMessage &req) RT_NOEXCEPT;
|
---|
66 | DhcpServerMessage *i_doRelease(const DhcpClientMessage &req) RT_NOEXCEPT;
|
---|
67 |
|
---|
68 | DhcpServerMessage *i_createMessage(int type, const DhcpClientMessage &req);
|
---|
69 | /** @} */
|
---|
70 |
|
---|
71 | /** @name Lease database handling
|
---|
72 | * @{ */
|
---|
73 | int i_loadLeases() RT_NOEXCEPT;
|
---|
74 | void i_saveLeases() RT_NOEXCEPT;
|
---|
75 | /** @} */
|
---|
76 | };
|
---|
77 |
|
---|
78 | #endif /* !VBOX_INCLUDED_SRC_Dhcpd_DHCPD_h */
|
---|