VirtualBox

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

Last change on this file since 56292 was 55365, checked in by vboxsync, 10 years ago

NetworkServices: When handling COM/XPCOM events, always check if the event is for our network, otherwise ignore the event. Renamed {get/set}Network to {get/set}NetworkName(). Renamed {get/set}Name to {get/set}ServiceName(). Use RT_ZERO instead of memset if possible. Coding style.

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