VirtualBox

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

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

DHCP: first-level DHCP request packet processing moved to NetworkManager class.
warning [-Wdelete-incomplete].

  • 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 49563 2013-11-20 07:13:46Z 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#include "Config.h"
40#include "ClientDataInt.h"
41
42/**
43 * The client is requesting an offer.
44 *
45 * @returns true.
46 *
47 * @param pDhcpMsg The message.
48 * @param cb The message size.
49 */
50bool NetworkManager::handleDhcpReqDiscover(PCRTNETBOOTP pDhcpMsg, size_t cb)
51{
52 RawOption opt;
53 memset(&opt, 0, sizeof(RawOption));
54 /* 1. Find client */
55 ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
56 Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb);
57
58 /* 2. Find/Bind lease for client */
59 Lease lease = confManager->allocateLease4Client(client, pDhcpMsg, cb);
60 AssertReturn(lease != Lease::NullLease, VINF_SUCCESS);
61
62 int rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt);
63
64 /* 3. Send of offer */
65
66 lease.bindingPhase(true);
67 lease.phaseStart(RTTimeMilliTS());
68 lease.setExpiration(300); /* 3 min. */
69 offer4Client(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
70
71 return VINF_SUCCESS;
72}
73
74
75/**
76 * The client is requesting an offer.
77 *
78 * @returns true.
79 *
80 * @param pDhcpMsg The message.
81 * @param cb The message size.
82 */
83bool NetworkManager::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb)
84{
85 ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
86
87 /* 1. find client */
88 Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb);
89
90 /* 2. find bound lease */
91 Lease l = client.lease();
92 if (l != Lease::NullLease)
93 {
94
95 if (l.isExpired())
96 {
97 /* send client to INIT state */
98 Client c(client);
99 nak(client, pDhcpMsg->bp_xid);
100 confManager->expireLease4Client(c);
101 return true;
102 }
103 else {
104 /* XXX: Validate request */
105 RawOption opt;
106 RT_ZERO(opt);
107
108 Client c(client);
109 int rc = confManager->commitLease4Client(c);
110 AssertRCReturn(rc, false);
111
112 rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt);
113 AssertRCReturn(rc, false);
114
115 ack(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
116 }
117 }
118 else
119 {
120 nak(client, pDhcpMsg->bp_xid);
121 }
122 return true;
123}
124
125
126/**
127 * The client is declining an offer we've made.
128 *
129 * @returns true.
130 *
131 * @param pDhcpMsg The message.
132 * @param cb The message size.
133 */
134bool NetworkManager::handleDhcpReqDecline(PCRTNETBOOTP, size_t)
135{
136 /** @todo Probably need to match the server IP here to work correctly with
137 * other servers. */
138
139 /*
140 * The client is supposed to pass us option 50, requested address,
141 * from the offer. We also match the lease state. Apparently the
142 * MAC address is not supposed to be checked here.
143 */
144
145 /** @todo this is not required in the initial implementation, do it later. */
146 return true;
147}
148
149
150/**
151 * The client is releasing its lease - good boy.
152 *
153 * @returns true.
154 *
155 * @param pDhcpMsg The message.
156 * @param cb The message size.
157 */
158bool NetworkManager::handleDhcpReqRelease(PCRTNETBOOTP, size_t)
159{
160 /** @todo Probably need to match the server IP here to work correctly with
161 * other servers. */
162
163 /*
164 * The client may pass us option 61, client identifier, which we should
165 * use to find the lease by.
166 *
167 * We're matching MAC address and lease state as well.
168 */
169
170 /*
171 * If no client identifier or if we couldn't find a lease by using it,
172 * we will try look it up by the client IP address.
173 */
174
175
176 /*
177 * If found, release it.
178 */
179
180
181 /** @todo this is not required in the initial implementation, do it later. */
182 return true;
183}
184
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