1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/* $Id: NetworkManagerDhcp.cpp $ */
/** @file
* NetworkManagerDhcp - Network Manager part handling Dhcp.
*/
/*
* Copyright (C) 2013-2019 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#include <iprt/asm.h>
#include <iprt/cdefs.h>
#include <iprt/getopt.h>
#include <iprt/net.h>
#include <iprt/param.h>
#include <iprt/path.h>
#include <iprt/stream.h>
#include <iprt/time.h>
#include <iprt/string.h>
#include "../NetLib/shared_ptr.h"
#include <vector>
#include <list>
#include <string>
#include <map>
#include <VBox/sup.h>
#include <VBox/intnet.h>
#define BASE_SERVICES_ONLY
#include "../NetLib/VBoxNetBaseService.h"
#include "Config.h"
#include "ClientDataInt.h"
/**
* The client is requesting an offer.
*
* @returns true.
*
* @param pDhcpMsg The message.
* @param cb The message size.
*/
bool NetworkManager::handleDhcpReqDiscover(PCRTNETBOOTP pDhcpMsg, size_t cb)
{
RawOption opt;
RT_ZERO(opt);
/* 1. Find client */
ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb);
/* 2. Find/Bind lease for client */
Lease lease = confManager->allocateLease4Client(client, pDhcpMsg, cb);
AssertReturn(lease != Lease::NullLease, VINF_SUCCESS);
int rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt);
NOREF(rc); /** @todo check */
/* 3. Send of offer */
lease.bindingPhase(true);
lease.phaseStart(RTTimeMilliTS());
lease.setExpiration(300); /* 3 min. */
offer4Client(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
return true;
}
/**
* The client is requesting an offer.
*
* @returns true.
*
* @param pDhcpMsg The message.
* @param cb The message size.
*/
bool NetworkManager::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb)
{
ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
/* 1. find client */
Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb);
/* 2. find bound lease */
Lease l = client.lease();
if (l != Lease::NullLease)
{
if (l.isExpired())
{
/* send client to INIT state */
Client c(client);
nak(client, pDhcpMsg->bp_xid);
confManager->expireLease4Client(c);
return true;
}
/* XXX: Validate request */
RawOption opt;
RT_ZERO(opt);
Client c(client);
int rc = confManager->commitLease4Client(c);
AssertRCReturn(rc, false);
rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt);
AssertRCReturn(rc, false);
ack(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
}
else
{
nak(client, pDhcpMsg->bp_xid);
}
return true;
}
/**
* The client is declining an offer we've made.
*
* @returns true.
*
* @param pDhcpMsg The message.
* @param cb The message size.
*/
bool NetworkManager::handleDhcpReqDecline(PCRTNETBOOTP, size_t)
{
/** @todo Probably need to match the server IP here to work correctly with
* other servers. */
/*
* The client is supposed to pass us option 50, requested address,
* from the offer. We also match the lease state. Apparently the
* MAC address is not supposed to be checked here.
*/
/** @todo this is not required in the initial implementation, do it later. */
return true;
}
/**
* The client is releasing its lease - good boy.
*
* @returns true.
*
* @param pDhcpMsg The message.
* @param cb The message size.
*/
bool NetworkManager::handleDhcpReqRelease(PCRTNETBOOTP, size_t)
{
/** @todo Probably need to match the server IP here to work correctly with
* other servers. */
/*
* The client may pass us option 61, client identifier, which we should
* use to find the lease by.
*
* We're matching MAC address and lease state as well.
*/
/*
* If no client identifier or if we couldn't find a lease by using it,
* we will try look it up by the client IP address.
*/
/*
* If found, release it.
*/
/** @todo this is not required in the initial implementation, do it later. */
return true;
}
|