Skip to content

Commit

Permalink
Client managers are now singletons. Warning: code change in progress.…
Browse files Browse the repository at this point in the history
… Stability problems expected.
  • Loading branch information
tomaszmrugalski committed Apr 28, 2010
1 parent b7d2330 commit aca45cd
Show file tree
Hide file tree
Showing 93 changed files with 1,131 additions and 1,809 deletions.
18 changes: 9 additions & 9 deletions AddrMgr/AddrMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TAddrMgr::TAddrMgr(string xmlFile, bool loadfile)
if (loadfile) {
dbLoad(xmlFile.c_str());
} else {
Log(Debug) << "Skipping database loading." << LogEnd;
Log(Debug) << "Skipping database loading." << LogEnd;
}
DeleteEmptyClient = true;
}
Expand Down Expand Up @@ -63,8 +63,8 @@ void TAddrMgr::dbLoad(const char * xmlFile)
xmlDocPtr root;
root = xmlLoad(xmlFile);
if (!root) {
Log(Error) << "File loading has failed." << LogEnd;
return;
Log(Error) << "File loading has failed." << LogEnd;
return;
}
this->parseAddrMgr(root,0);
xmlFreeDoc(root);
Expand Down Expand Up @@ -162,12 +162,12 @@ SPtr<TAddrClient> TAddrMgr::getClient(SPtr<TIPv6Addr> leasedAddr)
ClntsLst.first();
while (cli = ClntsLst.get() )
{
SPtr<TAddrIA> ia;
cli->firstIA();
while (ia = cli->getIA()) {
if ( ia->getAddr(leasedAddr) )
return cli;
}
SPtr<TAddrIA> ia;
cli->firstIA();
while (ia = cli->getIA()) {
if ( ia->getAddr(leasedAddr) )
return cli;
}
}
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- It is now possible to configure IAID
- Support for Mac OS X added (experimental, of course)

----
- OptPreference class removed
- tunnel endpoint removed

0.7.3 [2009-03-09]
- Linux: Fix for compilation with libc6, version 2.8
- New timezone option support added (by Petr Pisar) (bug #185)
Expand Down
44 changes: 22 additions & 22 deletions CfgMgr/CfgMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
#include "Logger.h"
#include "Portable.h"
#include "Logger.h"
#include "Iface.h"

TCfgMgr::TCfgMgr(SPtr<TIfaceMgr> IfaceMgr) {
this->IfaceMgr = IfaceMgr;
this->DUIDType = DUID_TYPE_LLT; /* default DUID type: LLT */
TCfgMgr::TCfgMgr()
:IsDone(false),
DUIDType(DUID_TYPE_LLT) /* default DUID type: LLT */
{

}

TCfgMgr::~TCfgMgr() {
this->IfaceMgr = 0;
}

// method compares both files and if differs
Expand Down Expand Up @@ -142,49 +142,49 @@ bool TCfgMgr::loadDUID(const string duidFile)
return true;
}

bool TCfgMgr::setDUID(const string filename) {
bool TCfgMgr::setDUID(const string filename, TIfaceMgr & ifaceMgr) {

// --- load DUID ---
if (this->loadDUID(filename)) {
Log(Info) << "My DUID is " << this->DUID->getPlain() << "." << LogEnd;
return true;
Log(Info) << "My DUID is " << this->DUID->getPlain() << "." << LogEnd;
return true;
}

SPtr<TIfaceIface> realIface;

bool found=false;


IfaceMgr->firstIface();
ifaceMgr.firstIface();
if (this->DUIDType == DUID_TYPE_EN) {
realIface = IfaceMgr->getIface(); // use the first interface. It will be ignored anyway
found = true;
realIface = ifaceMgr.getIface(); // use the first interface. It will be ignored anyway
found = true;

if (!realIface) {
Log(Error) << "Unable to find any interfaces. Can't generate DUID" << LogEnd;
return false;
}
if (!realIface) {
Log(Error) << "Unable to find any interfaces. Can't generate DUID" << LogEnd;
return false;
}
}
while( (!found) && (realIface=IfaceMgr->getIface()) )
while( (!found) && (realIface=ifaceMgr.getIface()) )
{
realIface->firstLLAddress();
char buf[64];
memset(buf,0,64);

if (!realIface->getMac()) {
Log(Debug) << "DUID creation: Interface " << realIface->getName() << "/" << realIface->getID()
Log(Debug) << "DUID creation: Interface " << realIface->getFullName()
<< " skipped: no link addresses." << LogEnd;
continue;
}
if ( realIface->getMacLen()<6 ) {
Log(Debug) << "DUID creation: Interface " << realIface->getName() << "/" << realIface->getID()
<< " skipped: MAC length is " << realIface->getMacLen() << ", but at least 6 is required." << LogEnd;
Log(Debug) << "DUID creation: Interface " << realIface->getFullName()
<< " skipped: MAC length is " << realIface->getMacLen()
<< ", but at least 6 is required." << LogEnd;
continue;
}
if ( realIface->flagLoopback() ) {
Log(Debug) << "DUID creation: Interface " << realIface->getName() << "/" << realIface->getID()
Log(Debug) << "DUID creation: Interface " << realIface->getFullName()
<< " skipped: Interface is loopback." << LogEnd;
continue;
continue;
}
if ( !memcmp(realIface->getMac(),buf,realIface->getMacLen()) ) {
Log(Debug) << "DUID creation: Interface " << realIface->getName() << "/" << realIface->getID()
Expand Down
11 changes: 4 additions & 7 deletions CfgMgr/CfgMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
*/

class TCfgMgr;
#ifndef CFGMGR_H
#define CFGMGR_H
#include <string>
Expand All @@ -22,7 +21,6 @@ class TCfgMgr;
#define RELAY_MIN_IFINDEX 1024

/* Defined DUID types */
using namespace std;

enum EDUIDType{
DUID_TYPE_NOT_DEFINED = 0,
Expand All @@ -34,7 +32,7 @@ enum EDUIDType{
class TCfgMgr
{
public:
TCfgMgr(SPtr<TIfaceMgr> IfaceMgr);
TCfgMgr();
virtual ~TCfgMgr();

bool compareConfigs(const string cfgFile, const string oldCfgFile);
Expand All @@ -47,14 +45,13 @@ class TCfgMgr

protected:
SPtr<TDUID> DUID;
bool setDUID(const string duidFile);
bool loadDUID(const string filename);
bool generateDUID(const string duidFile,char * mac,int macLen, int macType);
bool setDUID(const std::string duidFile, TIfaceMgr &ifaceMgr);
bool loadDUID(const std::string filename);
bool generateDUID(const std::string duidFile,char * mac,int macLen, int macType);
string Workdir;
string LogName;
int LogLevel;
bool IsDone;
SPtr<TIfaceMgr> IfaceMgr;
EDUIDType DUIDType;
int DUIDEnterpriseNumber;
SPtr<TDUID> DUIDEnterpriseID;
Expand Down
55 changes: 36 additions & 19 deletions ClntAddrMgr/ClntAddrMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
#include "AddrClient.h"
#include "Logger.h"

TClntAddrMgr * TClntAddrMgr::Instance = 0;

void TClntAddrMgr::instanceCreate(SPtr<TDUID> clientDUID, bool useConfirm, string xmlFile, bool loadDB)
{
if (Instance) {
Log(Crit) << "Attempt to create another instance of TClntAddrMgr!" << LogEnd;
return;
}
Instance = new TClntAddrMgr(clientDUID, useConfirm, xmlFile, loadDB);
}

TClntAddrMgr& TClntAddrMgr::instance()
{
return *Instance;
}

/**
* @brief Client Address Manager constructor
Expand Down Expand Up @@ -157,6 +172,8 @@ SPtr<TAddrIA> TClntAddrMgr::getIA(unsigned long IAID)

/**
* sets specified interface to CONFIRMME state
* when network switch off signal received, the funtion will be invoked to
* set valid IA to CONFIRMME state.
*
* @param changedLinks structure containing interface indexes to be confirmed
*/
Expand All @@ -174,8 +191,8 @@ void TClntAddrMgr::setIA2Confirm(volatile link_state_notify_t * changedLinks)
if (changedLinks->ifindex[i]==ifindex)
found = true;

if (!found)
continue;
if (!found)
continue;

if( (ptrIA->getState() == STATE_CONFIGURED || ptrIA->getState() == STATE_INPROCESS) )
{
Expand Down Expand Up @@ -262,23 +279,23 @@ void TClntAddrMgr::print(ostream &x) {

}

/**
* @brief Adds a prefix.
*
* @param srvDuid Server DUID
* @param srvAddr Server address.
* @param iface interface index
* @param IAID IAID
* @param T1 T1 timer
* @param T2 T2 timer
* @param prefix prefix
* @param pref prefered lifetime
* @param valid valid lifetime
* @param length prefix length
* @param quiet quiet mode (true=be quiet)
*
* @return true if successful, false otherwise
*/
/**
* @brief Adds a prefix.
*
* @param srvDuid Server DUID
* @param srvAddr Server address.
* @param iface interface index
* @param IAID IAID
* @param T1 T1 timer
* @param T2 T2 timer
* @param prefix prefix
* @param pref prefered lifetime
* @param valid valid lifetime
* @param length prefix length
* @param quiet quiet mode (true=be quiet)
*
* @return true if successful, false otherwise
*/
bool TClntAddrMgr::addPrefix(SPtr<TDUID> srvDuid , SPtr<TIPv6Addr> srvAddr,
int iface, unsigned long IAID, unsigned long T1, unsigned long T2,
SPtr<TIPv6Addr> prefix, unsigned long pref, unsigned long valid,
Expand Down
10 changes: 8 additions & 2 deletions ClntAddrMgr/ClntAddrMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
#include "AddrMgr.h"
#include "Portable.h"

#define ClntAddrMgr() (TClntAddrMgr::instance())

class TClntAddrMgr : public TAddrMgr
{
public:
private:
TClntAddrMgr(SPtr<TDUID> clientDuid, bool useConfirm, string xmlFile, bool loadDB);

public:
static TClntAddrMgr& instance();
static void instanceCreate(SPtr<TDUID> clientDUID, bool useConfirm, string xmlFile, bool loadDB);

unsigned long getT1Timeout();
unsigned long getT2Timeout();
unsigned long getPrefTimeout();
Expand All @@ -39,7 +45,6 @@ class TClntAddrMgr : public TAddrMgr
void addIA(SPtr<TAddrIA> ptr);
bool delIA(long IAID);
int countIA();
// CHANGED here: when network switch off signal received, the funtion will be invoked to set valid IA to CONFIRMME state.
void setIA2Confirm(volatile link_state_notify_t * changedLinks);

// --- PD ---
Expand Down Expand Up @@ -76,6 +81,7 @@ class TClntAddrMgr : public TAddrMgr
void print(ostream &x);
private:
SPtr<TAddrClient> Client;
static TClntAddrMgr * Instance;
};

#endif
41 changes: 25 additions & 16 deletions ClntCfgMgr/ClntCfgIface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Michal Kowalczuk <michal@kowalczuk.eu>
*
* released under GNU GPL v2 only licence
*
* $Id: ClntCfgIface.cpp,v 1.29 2009-03-24 22:46:17 thomson Exp $
*
*/

Expand All @@ -21,29 +19,21 @@
using namespace std;

TClntCfgIface::TClntCfgIface(string ifaceName) {
setDefaults();

NoConfig=false;
IfaceName=ifaceName;
ID=-1;
this->DNSServerState = STATE_DISABLED;
this->DomainState = STATE_DISABLED;
this->NTPServerState = STATE_DISABLED;
this->TimezoneState = STATE_DISABLED;
this->SIPServerState = STATE_DISABLED;
this->SIPDomainState = STATE_DISABLED;
this->FQDNState = STATE_DISABLED;
this->NISServerState = STATE_DISABLED;
this->NISPServerState = STATE_DISABLED;
this->NISDomainState = STATE_DISABLED;
this->NISPDomainState = STATE_DISABLED;
this->LifetimeState = STATE_DISABLED;
this->PrefixDelegationState = STATE_DISABLED;
this->VendorSpecState = STATE_DISABLED;
}

TClntCfgIface::TClntCfgIface(int ifaceNr) {
setDefaults();
NoConfig=false;
ID=ifaceNr;
IfaceName="[unknown]";
}

void TClntCfgIface::setDefaults() {
this->DNSServerState = STATE_DISABLED;
this->DomainState = STATE_DISABLED;
this->NTPServerState = STATE_DISABLED;
Expand All @@ -58,6 +48,8 @@ TClntCfgIface::TClntCfgIface(int ifaceNr) {
this->LifetimeState = STATE_DISABLED;
this->PrefixDelegationState = STATE_DISABLED;
this->VendorSpecState = STATE_DISABLED;
// this->DsLiteTunnelName = STATE_DISABLED;
// this->DsLiteTunnelAddr = STATE_DISABLED;
}

void TClntCfgIface::setOptions(SPtr<TClntParsGlobalOpt> opt) {
Expand Down Expand Up @@ -108,6 +100,23 @@ void TClntCfgIface::setOptions(SPtr<TClntParsGlobalOpt> opt) {
if (ReqNISPDomain) this->setNISPDomainState(STATE_NOTCONFIGURED);
if (ReqLifetime) this->setLifetimeState(STATE_NOTCONFIGURED);
if (ReqVendorSpec) this->setVendorSpecState(STATE_NOTCONFIGURED);

switch (opt->getDsLiteTunnelMode())
{
case TUNNEL_ADDR:
DsLiteTunnelAddr = opt->getDsLiteTunnelAddr();
break;
case TUNNEL_NAME:
DsLiteTunnelName = opt->getDsLiteTunnelName();
break;
case TUNNEL_BOTH:
DsLiteTunnelAddr = opt->getDsLiteTunnelAddr();
DsLiteTunnelName = opt->getDsLiteTunnelName();
break;
case TUNNEL_NONE:
break;
}

// copy preferred-server list
SPtr<TStationID> station;
opt->firstPrefSrv();
Expand Down
4 changes: 4 additions & 0 deletions ClntCfgMgr/ClntCfgIface.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class TClntCfgIface
void setAuthenticationState(EState state);

private:
void setDefaults();
string IfaceName;
int ID;
bool NoConfig;
Expand Down Expand Up @@ -240,6 +241,9 @@ class TClntCfgIface
bool ReqLifetime;
bool ReqPrefixDelegation;
bool ReqVendorSpec;

SPtr<TIPv6Addr> DsLiteTunnelAddr;
SPtr<TOpt> DsLiteTunnelName;
};

#endif
Loading

0 comments on commit aca45cd

Please sign in to comment.