VirtualBox

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

Last change on this file since 76690 was 76576, checked in by vboxsync, 6 years ago

NetworkServices: scm header guard alignment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: DhcpMessage.h 76576 2019-01-01 06:05:25Z 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.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_DhcpMessage_h
19#define VBOX_INCLUDED_SRC_Dhcpd_DhcpMessage_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "Defs.h"
25#include <iprt/net.h>
26#include <string>
27#include "ClientId.h"
28#include "DhcpOptions.h"
29
30
31/* move to <iptr/net.h>? */
32#define DHCP_OPTION_OVERLOAD_MASK 0x3
33#define DHCP_OPTION_OVERLOAD_FILE 0x1
34#define DHCP_OPTION_OVERLOAD_SNAME 0x2
35
36
37class DhcpMessage
38{
39protected:
40 uint32_t m_xid;
41 uint16_t m_flags;
42
43 RTMAC m_mac;
44
45 RTNETADDRIPV4 m_ciaddr;
46 RTNETADDRIPV4 m_yiaddr;
47 RTNETADDRIPV4 m_siaddr;
48 RTNETADDRIPV4 m_giaddr;
49
50 std::string m_sname;
51 std::string m_file;
52
53 OptMessageType m_optMessageType;
54
55public:
56 DhcpMessage();
57
58
59 uint32_t xid() const { return m_xid; }
60
61 uint16_t flags() const { return m_flags; }
62 bool broadcast() const { return (m_flags & RTNET_DHCP_FLAG_BROADCAST) != 0; }
63
64 const RTMAC &mac() const { return m_mac; }
65
66 RTNETADDRIPV4 ciaddr() const { return m_ciaddr; }
67 RTNETADDRIPV4 yiaddr() const { return m_yiaddr; }
68 RTNETADDRIPV4 siaddr() const { return m_siaddr; }
69 RTNETADDRIPV4 giaddr() const { return m_giaddr; }
70
71 void setCiaddr(RTNETADDRIPV4 addr) { m_ciaddr = addr; }
72 void setYiaddr(RTNETADDRIPV4 addr) { m_yiaddr = addr; }
73 void setSiaddr(RTNETADDRIPV4 addr) { m_siaddr = addr; }
74 void setGiaddr(RTNETADDRIPV4 addr) { m_giaddr = addr; }
75
76 uint8_t messageType() const
77 {
78 Assert(m_optMessageType.present());
79 return m_optMessageType.value();
80 }
81};
82
83
84class DhcpClientMessage
85 : public DhcpMessage
86{
87protected:
88 rawopts_t m_rawopts;
89 ClientId m_id;
90 bool m_broadcasted;
91
92public:
93 static DhcpClientMessage *parse(bool broadcasted, const void *buf, size_t buflen);
94
95 bool broadcasted() const { return m_broadcasted; }
96
97 const rawopts_t &rawopts() const { return m_rawopts; }
98 const ClientId &clientId() const { return m_id; }
99
100 void dump() const;
101
102protected:
103 int parseOptions(const void *buf, size_t buflen);
104};
105
106
107
108class DhcpServerMessage
109 : public DhcpMessage
110{
111protected:
112 RTNETADDRIPV4 m_dst;
113
114 OptServerId m_optServerId;
115
116 optmap_t m_optmap;
117
118public:
119 DhcpServerMessage(const DhcpClientMessage &req,
120 uint8_t messageType, RTNETADDRIPV4 serverAddr);
121
122 RTNETADDRIPV4 dst() const { return m_dst; }
123 void setDst(RTNETADDRIPV4 aDst) { m_dst = aDst; }
124
125 void maybeUnicast(const DhcpClientMessage &req);
126
127 void addOption(DhcpOption *opt);
128 void addOption(const DhcpOption &opt)
129 {
130 addOption(opt.clone());
131 }
132
133 void addOptions(const optmap_t &optmap);
134
135 int encode(octets_t &data);
136};
137
138#endif /* !VBOX_INCLUDED_SRC_Dhcpd_DhcpMessage_h */
Note: See TracBrowser for help on using the repository browser.

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