VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.h@ 79763

最後變更 在這個檔案從79763是 79568,由 vboxsync 提交於 6 年 前

Dhcpd: Went over the DhcpMessage a little as well as revisiting the lease reading code in the database. Logging is LogRel() or similar, no cout, RTPrintf or similar. The debug & release loggers can both output to stderr/out/whatever as needed. bugref:9288

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.4 KB
 
1/* $Id: DhcpMessage.h 79568 2019-07-06 23:42:51Z vboxsync $ */
2/** @file
3 * DHCP Message and its de/serialization.
4 */
5
6/*
7 * Copyright (C) 2017-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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_DhcpMessage_h
19#define VBOX_INCLUDED_SRC_Dhcpd_DhcpMessage_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "DhcpdInternal.h"
25#include <iprt/net.h>
26#include <iprt/cpp/ministring.h>
27#include "ClientId.h"
28#include "DhcpOptions.h"
29
30
31/**
32 * Base class for internal DHCP client and server message representations.
33 */
34class DhcpMessage
35{
36protected:
37 uint32_t m_xid;
38 uint16_t m_flags;
39
40 RTMAC m_mac;
41
42 RTNETADDRIPV4 m_ciaddr;
43 RTNETADDRIPV4 m_yiaddr;
44 RTNETADDRIPV4 m_siaddr;
45 RTNETADDRIPV4 m_giaddr;
46
47#if 0 /* not currently unused, so avoid wasting time on them for now. */
48 RTCString m_sname; /**< @note Not necessarily UTF-8 clean. */
49 RTCString m_file; /**< @note Not necessarily UTF-8 clean. */
50#endif
51
52 OptMessageType m_optMessageType;
53
54protected:
55 DhcpMessage();
56
57public:
58 /** @name Accessors
59 * @{ */
60 uint32_t xid() const RT_NOEXCEPT { return m_xid; }
61
62 uint16_t flags() const RT_NOEXCEPT { return m_flags; }
63 bool broadcast() const RT_NOEXCEPT { return (m_flags & RTNET_DHCP_FLAG_BROADCAST) != 0; }
64
65 const RTMAC &mac() const RT_NOEXCEPT { return m_mac; }
66
67 RTNETADDRIPV4 ciaddr() const RT_NOEXCEPT { return m_ciaddr; }
68 RTNETADDRIPV4 yiaddr() const RT_NOEXCEPT { return m_yiaddr; }
69 RTNETADDRIPV4 siaddr() const RT_NOEXCEPT { return m_siaddr; }
70 RTNETADDRIPV4 giaddr() const RT_NOEXCEPT { return m_giaddr; }
71
72 void setCiaddr(RTNETADDRIPV4 addr) RT_NOEXCEPT { m_ciaddr = addr; }
73 void setYiaddr(RTNETADDRIPV4 addr) RT_NOEXCEPT { m_yiaddr = addr; }
74 void setSiaddr(RTNETADDRIPV4 addr) RT_NOEXCEPT { m_siaddr = addr; }
75 void setGiaddr(RTNETADDRIPV4 addr) RT_NOEXCEPT { m_giaddr = addr; }
76
77 uint8_t messageType() const RT_NOEXCEPT
78 {
79 Assert(m_optMessageType.present());
80 return m_optMessageType.value();
81 }
82 /** @} */
83};
84
85
86/**
87 * Decoded DHCP client message.
88 *
89 * This is the internal decoded representation of a DHCP message picked up from
90 * the wire.
91 */
92class DhcpClientMessage
93 : public DhcpMessage
94{
95protected:
96 rawopts_t m_rawopts;
97 ClientId m_id;
98 bool m_broadcasted;
99
100public:
101 static DhcpClientMessage *parse(bool broadcasted, const void *buf, size_t buflen);
102
103 /** @name Getters
104 * @{ */
105 bool broadcasted() const RT_NOEXCEPT { return m_broadcasted; }
106 const rawopts_t &rawopts() const RT_NOEXCEPT { return m_rawopts; }
107 const ClientId &clientId() const RT_NOEXCEPT { return m_id; }
108 /** @} */
109
110 void dump() const RT_NOEXCEPT;
111
112protected:
113 int i_parseOptions(const uint8_t *pbBuf, size_t cbBuf) RT_NOEXCEPT;
114};
115
116
117
118/**
119 * DHCP server message for encoding.
120 */
121class DhcpServerMessage
122 : public DhcpMessage
123{
124protected:
125 RTNETADDRIPV4 m_dst;
126 OptServerId m_optServerId;
127 optmap_t m_optmap;
128
129public:
130 DhcpServerMessage(const DhcpClientMessage &req, uint8_t messageType, RTNETADDRIPV4 serverAddr);
131
132 /** @name Accessors
133 * @{ */
134 RTNETADDRIPV4 dst() const RT_NOEXCEPT { return m_dst; }
135 void setDst(RTNETADDRIPV4 aDst) RT_NOEXCEPT { m_dst = aDst; }
136
137 void maybeUnicast(const DhcpClientMessage &req) RT_NOEXCEPT;
138
139 void addOption(DhcpOption *opt);
140 void addOption(const DhcpOption &opt) { addOption(opt.clone()); }
141
142 void addOptions(const optmap_t &optmap);
143 /** @} */
144
145 int encode(octets_t &data);
146};
147
148#endif /* !VBOX_INCLUDED_SRC_Dhcpd_DhcpMessage_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette