Config.h revision 4385e174d1b0fa3a119b083b2234fd018a345dc6
/* $Id$ */
/** @file
* Config.h
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* 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.
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <iprt/asm-math.h>
{
return (b < a);
}
{
{
}
};
/*
* it's a basic representation of
* of out undestanding what client is
* XXX: Client might sends Option 61 (RFC2132 9.14 "Client-identifier") signalling
* that we may identify it in special way
*
* XXX: Client might send Option 60 (RFC2132 9.13 "Vendor class undentifier")
* in response it's expected server sends Option 43 (RFC2132 8.4. "Vendor Specific Information")
*/
{
Client();
const RTMAC& getMacAddress() const;
/** Dumps client query */
void dump();
static const Client NullClient;
Client(ClientData *);
SharedPtr<ClientData> m;
};
}
{
//friend int ConfigurationManager::loadFromFile(const std::string&);
Lease();
bool isExpired() const;
void expire();
/* Depending on phase *Expiration and phaseStart initialize different values. */
void bindingPhase(bool);
bool isInBindingPhase() const;
/* returns 0 if in binding state */
void setExpiration(uint32_t);
uint32_t getExpiration() const;
RTNETADDRIPV4 getAddress() const;
void setAddress(RTNETADDRIPV4);
const NetworkConfigEntity *getConfig() const;
void setConfig(NetworkConfigEntity *);
const MapOptionId2RawOption& options() const;
Lease(ClientData *);
SharedPtr<ClientData> m;
};
/**
*
*/
{
};
{
{
}
{
}
};
{
{
}
{
}
};
{
{
return true;
}
};
{
};
#if 0
/* XXX: Later */
{
{
}
};
#endif
/* Option 60 */
/* Option 61 */
{
int matchingLevel = 0)
: m_criteria(criteria),
virtual ~BaseConfigEntity(){};
/* XXX */
{
return 0;
}
/* Should return how strong matching */
const ClientMatchCriteria *m_criteria;
int m_MatchLevel;
};
{
NullConfigEntity(){}
virtual ~NullConfigEntity(){}
int add(BaseConfigEntity *) const { return 0;}
};
{
/* range */
/* match conditions */
const BaseConfigEntity *cfg,
const ClientMatchCriteria *criteria,
int matchingLevel = 0):
{
}
{
if (!m_u32ExpirationPeriod)
return m_parentCfg->expirationPeriod();
else
return m_u32ExpirationPeriod;
}
/* XXX: private:*/
const BaseConfigEntity *m_parentCfg;
};
/**
* Network specific entries
*/
{
/* Address Pool matching with network declaration */
const BaseConfigEntity *cfg,
const ClientMatchCriteria *criteria,
int matchlvl,
const RTNETADDRIPV4& networkID,
const RTNETADDRIPV4& networkMask,
const RTNETADDRIPV4& lowerIP,
const RTNETADDRIPV4& upperIP):
{
};
const BaseConfigEntity *cfg,
const ClientMatchCriteria *criteria,
const RTNETADDRIPV4& networkID,
const RTNETADDRIPV4& networkMask):
{
m_LowerIP.u = m_NetworkID.u;
};
};
/**
* Host specific entry
* Address pool is contains one element
*/
{
const NetworkConfigEntity *cfg,
const ClientMatchCriteria *criteria):
{
/* upper addr == lower addr */
}
};
{
virtual ~RootConfigEntity(){};
};
#if 0
/**
* Shared regions e.g. some of configured networks declarations
* are cover each other.
* XXX: Shared Network is join on Network config entities with possible
* overlaps in address pools. for a moment we won't configure and use them them
*/
{
{
}
};
#endif
{
static ConfigurationManager* getConfigurationManager();
int saveToFile();
/**
*
*/
/**
* XXX: it's could be done on DHCPOFFER or on DHCPACK (rfc2131 gives freedom here
* 3.1.2, what is strict that allocation should do address check before real
* allocation)...
*/
/**
* We call this before DHCPACK sent and after DHCPREQUEST received ...
* when requested configuration is acceptable.
*/
/**
* Expires client lease.
*/
const RTNETADDRIPV4& networkId,
const RTNETADDRIPV4& netmask,
ConfigurationManager():m(NULL){}
void init();
/* nulls */
const Ipv4AddressContainer m_empty;
struct Data;
Data *m;
};
{
static NetworkManager *getNetworkManager();
const RTNETADDRIPV4& getOurAddress() const;
const RTNETADDRIPV4& getOurNetmask() const;
void setService(const VBoxNetHlpUDPService *);
~NetworkManager();
int processParameterReqList(const Client& client, const uint8_t *pu8ReqList, int cReqList, std::vector<RawOption>& extra);
struct Data;
Data *m;
};
extern const ClientMatchCriteria *g_AnyClient;
extern RootConfigEntity *g_RootConfig;
extern const NullConfigEntity *g_NullConfig;
/**
* Helper class for stuffing DHCP options into a reply packet.
*/
{
bool m_fOverflowed; /**< Set if we've overflowed, otherwise false. */
/** Instantiate an option cursor for the specified DHCP message. */
m_fUsed(0),
m_fOverflowed(false)
{
}
/** Destructor. */
{
}
/**
* Try use the bp_file field.
* @returns true if not overloaded, false otherwise.
*/
bool useBpFile(void)
{
if ( m_pfOverload
&& (*m_pfOverload & 1))
return false;
return true;
}
/**
* Try overload more BOOTP fields
*/
bool overloadMore(void)
{
/* switch option area. */
if (!(m_fUsed & 1))
{
fField = 1;
}
else if (!(m_fUsed & 2))
{
fField = 2;
}
else
return false;
if (!m_pfOverload)
{
/* Add an overload option. */
}
else
*m_pfOverload |= fField;
/* pad current option field */
/* switch */
return true;
}
/**
* Begin an option.
*
* @returns true on success, false if we're out of space.
*
* @param uOption The option number.
* @param cb The amount of data.
*/
{
/* Check that the data of the previous option has all been written. */
/* Check if we need to overload more stuff. */
{
if (!overloadMore())
{
m_fOverflowed = true;
}
{
m_fOverflowed = true;
}
}
/* Emit the option header. */
m_pbCur += 2;
return true;
}
/**
* Puts option data.
*
* @param pvData The data.
* @param cb The amount to put.
*/
{
{
}
}
/**
* Puts an IPv4 Address.
*
* @param IPv4Addr The address.
*/
{
}
/**
* Adds an IPv4 address option.
*
*
* @param uOption The option number.
* @param IPv4Addr The address.
*/
{
return false;
return true;
}
/**
* Adds an option taking 1 or more IPv4 address.
*
* If the vector contains no addresses, the option will not be added.
*
*
* @param uOption The option number.
* @param rIPv4Addrs Reference to the address vector.
*/
{
if (!c)
return true;
return false;
for (size_t i = 0; i < c; i++)
putIPv4Addr(rIPv4Addrs[i]);
return true;
}
/**
* Puts an 8-bit integer.
*
* @param u8 The integer.
*/
{
}
/**
* Adds an 8-bit integer option.
*
*
* @param uOption The option number.
* @param u8 The integer
*/
{
return false;
return true;
}
/**
* Puts an 32-bit integer (network endian).
*
* @param u32Network The integer.
*/
{
}
/**
* Adds an 32-bit integer (network endian) option.
*
*
* @param uOption The option number.
* @param u32Network The integer.
*/
{
return false;
return true;
}
/**
* Puts a std::string.
*
* @param rStr Reference to the string.
*/
{
}
/**
* Adds an std::string option if the string isn't empty.
*
*
* @param uOption The option number.
* @param rStr Reference to the string.
*/
{
if (!cch)
return true;
return false;
return true;
}
/**
* Whether we've overflowed.
*
* @returns true on overflow, false otherwise.
*/
bool hasOverflowed(void) const
{
return m_fOverflowed;
}
/**
* Adds the terminating END option.
*
* The END will always be added as we're reserving room for it, however, we
* might have dropped previous options due to overflows and that is what the
* return status indicates.
*
* @returns true on success, false on a (previous) overflow.
*/
bool optEnd(void)
{
*m_pbCur++ = RTNET_DHCP_OPT_END;
return !hasOverflowed();
}
};
#endif