Config.cpp revision e5d2729873049f9be403f69089c6f2af5e9e14ec
/* $Id$ */
/**
* XXX: license.
*/
#include <VBox/intnetinline.h>
#include "../NetLib/VBoxNetLib.h"
#include <list>
#include <vector>
#include <map>
#include <string>
#include "Config.h"
static ConfigurationManager *g_ConfigurationManager = ConfigurationManager::getConfigurationManager();
{
if (m_children.empty())
{
if (iMatch > 0)
{
*cfg = this;
return iMatch;
}
}
else
{
*cfg = this;
/* XXX: hack */
BaseConfigEntity *matching = this;
int matchingLevel = m_MatchLevel;
++it)
{
if (iMatch > matchingLevel)
{
}
}
return matchingLevel;
}
return iMatch;
}
/* Client */
{
}
/* Configs
NetworkConfigEntity(std::string name,
ConfigEntity* pCfg,
ClientMatchCriteria* criteria,
RTNETADDRIPV4& networkID,
RTNETADDRIPV4& networkMask)
*/
static const RTNETADDRIPV4 g_AnyIpv4 = {0};
{
m_MatchLevel = 2;
}
/* Configuration Manager */
{
if (!g_ConfigurationManager)
return g_ConfigurationManager;
}
int ConfigurationManager::extractRequestList(PCRTNETBOOTP pDhcpMsg, size_t cbDhcpMsg, RawOption& rawOpt)
{
return ConfigurationManager::findOption(RTNET_DHCP_OPT_PARAM_REQ_LIST, pDhcpMsg, cbDhcpMsg, rawOpt);
}
{
bool fDhcpValid = false;
/* 1st. client IDs */
++it)
{
{
/* check timestamp that request wasn't expired. */
return (*it);
}
}
{
/* We hasn't got any session for this client */
}
return NULL;
}
/**
* Finds an option.
*
* @returns On success, a pointer to the first byte in the option data (no none
* then it'll be the byte following the 0 size field) and *pcbOpt set
* to the option length.
* On failure, NULL is returned and *pcbOpt unchanged.
*
* @param uOption The option to search for.
* @param pDhcpMsg The DHCP message.
* that this is adjusted if the option length is larger
* than the message buffer.
*/
int
ConfigurationManager::findOption(uint8_t uOption, PCRTNETBOOTP pDhcpMsg, size_t cbDhcpMsg, RawOption& opt)
{
/*
* Validate the DHCP bits and figure the max size of the options in the vendor field.
*/
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
if (cbLeft > RTNET_DHCP_OPT_SIZE)
/*
* Search the vendor field.
*/
bool fExtended = false;
{
if (uCur == RTNET_DHCP_OPT_PAD)
{
cbLeft--;
pb++;
}
else if (cbLeft <= 1)
break;
else
{
{
return VINF_SUCCESS;
}
}
}
/** @todo search extended dhcp option field(s) when present */
return VERR_NOT_FOUND;
}
/**
* We bind lease for client till it continue with it on DHCPREQUEST.
*/
Lease *ConfigurationManager::allocateLease4Client(Client *client, PCRTNETBOOTP pDhcpMsg, size_t cbDhcpMsg)
{
/**
* Well, session hasn't get the config.
*/
/**
* This mean that client has already bound or commited lease.
* If we've it happens it means that we received DHCPDISCOVER twice.
*/
{
else
{
}
}
/* DHCPDISCOVER MAY contain request address */
hintAddress.u = 0;
if (RT_SUCCESS(rc))
{
hintAddress.u = 0; /* clear hint */
}
if ( hintAddress.u
{
return please;
}
++u32)
{
{
return please;
}
}
return NULL;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
++it)
{
{
if (ppLease)
return true;
}
}
return false;
}
const RTNETADDRIPV4& networkId,
const RTNETADDRIPV4& netmask,
{
static int id;
char name[64];
id++;
if (!LowerAddress.u)
if (!UpperAddress.u)
return new NetworkConfigEntity(strname,
5,
}
const RTNETADDRIPV4& address,
{
static int id;
char name[64];
id++;
}
{
switch(u8OptId)
{
case RTNET_DHCP_OPT_DNS:
break;
case RTNET_DHCP_OPT_ROUTERS:
break;
default:
}
return VINF_SUCCESS;
}
{
switch(u8OptId)
{
case RTNET_DHCP_OPT_DNS:
break;
case RTNET_DHCP_OPT_ROUTERS:
break;
default:
}
return VINF_SUCCESS;
}
{
switch(u8OptId)
{
case RTNET_DHCP_OPT_DNS:
return m_nameservers;
case RTNET_DHCP_OPT_ROUTERS:
return m_routers;
}
/* XXX: Grrr !!! */
return m_empty;
}
{
switch (u8OptId)
{
m_domainName = str;
break;
default:
break;
}
return VINF_SUCCESS;
}
{
switch (u8OptId)
{
if (m_domainName.length())
return m_domainName;
else
return m_noString;
default:
break;
}
return m_noString;
}
/**
* Network manager
*/
{
if (!g_NetworkManager)
g_NetworkManager = new NetworkManager();
return g_NetworkManager;
}
/**
* Network manager creates DHCPOFFER datagramm
*/
{
/* Ubuntu ???*/
/* options:
* - IP lease time
* - message type
* - server identifier
*/
/* XXX: can't store options per session */
}
/**
* Network manager creates DHCPACK
*/
{
/* rfc2131 4.3.1 is about DHCPDISCOVER and this value is equal to ciaddr from
* DHCPREQUEST or 0 ...
* XXX: Using addressHint is not correct way to initialize [cy]iaddress...
*/
/* options:
* - IP address lease time (if DHCPREQUEST)
* - message type
* - server identifier
*/
/*
* XXX: lease time should be conditional. If on dhcprequest then tim should be provided,
* else on dhcpinform it mustn't.
*/
}
/**
* Network manager creates DHCPNAK
*/
{
/* this field filed in prepareReplyPacket4Session, and
* RFC 2131 require to have it zero fo NAK.
*/
/* options:
* - message type (if DHCPREQUEST)
* - server identifier
*/
}
/**
*
*/
{
/* XXX: bp_flags should be processed specially */
'\0',
return VINF_SUCCESS;
}
{
int rc;
/*
Options....
*/
/* The basics */
{
break;
}
{
Log(("Wasn't able to put all options\n"));
/* force clean up */
}
/*
*/
#if 0
if (!(pDhcpMsg->bp_flags & RTNET_DHCP_FLAGS_NO_BROADCAST)) /** @todo need to see someone set this flag to check that it's correct. */
{
&m_OurMac,
RTNETIPV4_PORT_BOOTPS, /* sender */
RTNETIPV4_PORT_BOOTPC, /* receiver */
}
else
#endif
&m_OurMac,
RTNETIPV4_PORT_BOOTPS, /* sender */
return VINF_SUCCESS;
}
{
/* request parameter list */
int idxParam = 0;
{
{
break;
case RTNET_DHCP_OPT_ROUTERS:
case RTNET_DHCP_OPT_DNS:
{
const Ipv4AddressContainer lst =
++it)
{
*pAddresses = (*it);
pAddresses++;
}
}
break;
{
break;
}
break;
default:
break;
}
}
return VINF_SUCCESS;
}