VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/DHCP/NetworkManagerDhcp.cpp@ 49582

Last change on this file since 49582 was 49566, checked in by vboxsync, 11 years ago

DHCP: G/c lines.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: NetworkManagerDhcp.cpp 49566 2013-11-20 08:49:10Z vboxsync $ */
2/** @file
3 * NetworkManagerDhcp - Network Manager part handling Dhcp.
4 */
5
6/*
7 * Copyright (C) 2013 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/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <iprt/asm.h>
22#include <iprt/cdefs.h>
23#include <iprt/net.h>
24#include <iprt/param.h>
25#include <iprt/path.h>
26#include <iprt/stream.h>
27#include <iprt/time.h>
28#include <iprt/string.h>
29
30#include "../NetLib/shared_ptr.h"
31
32#include <vector>
33#include <list>
34#include <string>
35#include <map>
36
37#include <VBox/sup.h>
38#include <VBox/intnet.h>
39
40#include "Config.h"
41#include "ClientDataInt.h"
42
43/**
44 * The client is requesting an offer.
45 *
46 * @returns true.
47 *
48 * @param pDhcpMsg The message.
49 * @param cb The message size.
50 */
51bool NetworkManager::handleDhcpReqDiscover(PCRTNETBOOTP pDhcpMsg, size_t cb)
52{
53 RawOption opt;
54 memset(&opt, 0, sizeof(RawOption));
55 /* 1. Find client */
56 ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
57 Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb);
58
59 /* 2. Find/Bind lease for client */
60 Lease lease = confManager->allocateLease4Client(client, pDhcpMsg, cb);
61 AssertReturn(lease != Lease::NullLease, VINF_SUCCESS);
62
63 int rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt);
64
65 /* 3. Send of offer */
66
67 lease.bindingPhase(true);
68 lease.phaseStart(RTTimeMilliTS());
69 lease.setExpiration(300); /* 3 min. */
70 offer4Client(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
71
72 return VINF_SUCCESS;
73}
74
75
76/**
77 * The client is requesting an offer.
78 *
79 * @returns true.
80 *
81 * @param pDhcpMsg The message.
82 * @param cb The message size.
83 */
84bool NetworkManager::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb)
85{
86 ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
87
88 /* 1. find client */
89 Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb);
90
91 /* 2. find bound lease */
92 Lease l = client.lease();
93 if (l != Lease::NullLease)
94 {
95
96 if (l.isExpired())
97 {
98 /* send client to INIT state */
99 Client c(client);
100 nak(client, pDhcpMsg->bp_xid);
101 confManager->expireLease4Client(c);
102 return true;
103 }
104 else {
105 /* XXX: Validate request */
106 RawOption opt;
107 RT_ZERO(opt);
108
109 Client c(client);
110 int rc = confManager->commitLease4Client(c);
111 AssertRCReturn(rc, false);
112
113 rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt);
114 AssertRCReturn(rc, false);
115
116 ack(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
117 }
118 }
119 else
120 {
121 nak(client, pDhcpMsg->bp_xid);
122 }
123 return true;
124}
125
126
127/**
128 * The client is declining an offer we've made.
129 *
130 * @returns true.
131 *
132 * @param pDhcpMsg The message.
133 * @param cb The message size.
134 */
135bool NetworkManager::handleDhcpReqDecline(PCRTNETBOOTP, size_t)
136{
137 /** @todo Probably need to match the server IP here to work correctly with
138 * other servers. */
139
140 /*
141 * The client is supposed to pass us option 50, requested address,
142 * from the offer. We also match the lease state. Apparently the
143 * MAC address is not supposed to be checked here.
144 */
145
146 /** @todo this is not required in the initial implementation, do it later. */
147 return true;
148}
149
150
151/**
152 * The client is releasing its lease - good boy.
153 *
154 * @returns true.
155 *
156 * @param pDhcpMsg The message.
157 * @param cb The message size.
158 */
159bool NetworkManager::handleDhcpReqRelease(PCRTNETBOOTP, size_t)
160{
161 /** @todo Probably need to match the server IP here to work correctly with
162 * other servers. */
163
164 /*
165 * The client may pass us option 61, client identifier, which we should
166 * use to find the lease by.
167 *
168 * We're matching MAC address and lease state as well.
169 */
170
171 /*
172 * If no client identifier or if we couldn't find a lease by using it,
173 * we will try look it up by the client IP address.
174 */
175
176
177 /*
178 * If found, release it.
179 */
180
181
182 /** @todo this is not required in the initial implementation, do it later. */
183 return true;
184}
185
Note: See TracBrowser for help on using the repository browser.

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