Ejemplo n.º 1
0
void TClntOptIA_NA::releaseAddr(long IAID, SPtr<TIPv6Addr> addr )
{
    SPtr<TAddrIA> ptrIA = ClntAddrMgr().getIA(IAID);
    if (ptrIA)
        ptrIA->delAddr(addr);
    else
        Log(Warning) << "Unable to release addr: IA ("
                     << IAID << ") not present in addrDB." << LogEnd;
}
Ejemplo n.º 2
0
void TClntOptIA_PD::setState(EState state)
{
    SPtr<TClntCfgIface> cfgIface = ClntCfgMgr().getIface(this->Iface);

    SPtr<TClntCfgPD> cfgPD = cfgIface->getPD(getIAID());
    if (!cfgPD) {
	Log(Error) << "Unable to find PD with iaid=" << getIAID() << " on the "
		   << cfgIface->getFullName() << " interface (CfgMgr)." << LogEnd;
	return;
    }
    cfgPD->setState(state);

    SPtr<TAddrIA> addrPD = ClntAddrMgr().getPD(getIAID());
    if (!addrPD) {
	/* Log(Error) << "Unable to find PD with iaid=" << getIAID() << " on the "
	   << cfgIface->getFullName() << " interface (AddrMgr)." << LogEnd; */
	/* Don't complain about it. It is normal that IA is being deleted when there
	   are no more prefixes in it */
	return;
    }
    addrPD->setState(state);
}
Ejemplo n.º 3
0
  :TClntMsg(iface, addr, RELEASE_MSG)
{
    SPtr<TDUID> srvDUID;
    
    IRT=REL_TIMEOUT;
    MRT=0;
    MRC=REL_MAX_RC;
    MRD=0;
    RT=0;

    // obtain IA, TA or PD, so server DUID can be obtained
    SPtr<TAddrIA> x = 0;
    if (iaLst.count()) {
        iaLst.first();
        x=iaLst.get();
    }
    if (!x)
        x = ta;
    if (!x) {
        pdLst.first();
        x = pdLst.get();
    }
    if (!x) {
        Log(Error) << "Unable to send RELEASE. No IA, TA or PD provided." << LogEnd;
        this->IsDone = true;
        return;
    }
    if (!x->getDUID()) {
        Log(Error) << "Unable to send RELEASE. Unable to find DUID. " << LogEnd;
        this->IsDone = true;
        return;
    }
    srvDUID = x->getDUID();

    Options.push_back(new TOptDUID(OPTION_SERVERID, srvDUID,this));
    Options.push_back(new TOptDUID(OPTION_CLIENTID, ClntCfgMgr().getDUID(),this));

#if 0
    if (ClntCfgMgr().getNotifyScripts()) {
	// release workaround (add removed IAs)
        /// @todo: WTF? Why are those IAs removed?
        iaLst.first();
        SPtr<TAddrIA> ia;
	while (ia = iaLst.get()) 
	{
	    ClntAddrMgr().addIA(ia);
	}
	
	
	iaLst.first();
	while (ia = iaLst.get())
	{
	    ClntAddrMgr().delIA(ia->getIAID());
	}
    }
#endif

    // --- RELEASE IA ---
    iaLst.first();
    while(x=iaLst.get()) {
        Options.push_back(new TClntOptIA_NA(x,this));
        SPtr<TAddrAddr> ptrAddr;
        SPtr<TClntIfaceIface> ptrIface;
        ptrIface = (Ptr*)ClntIfaceMgr().getIfaceByID(x->getIface());
        x->firstAddr();
        while (ptrAddr = x->getAddr()) {
            ptrIface->delAddr(ptrAddr->get(), ptrAddr->getPrefix());
        }

	// --- DNS Update ---
	SPtr<TIPv6Addr> dns = x->getFQDNDnsServer();
	if (dns) {
	    string fqdn = ptrIface->getFQDN();
	    ClntIfaceMgr().fqdnDel(ptrIface, x, fqdn);
	}
	// --- DNS Update ---
    }
    
    // --- RELEASE TA ---
    if (ta)
	Options.push_back(new TClntOptTA(ta, this));

    // --- RELEASE PD ---

    SPtr<TAddrIA> pd = 0;
    
    pdLst.first();
    while(pd=pdLst.get()) {
        SPtr<TClntOptIA_PD> pdOpt = new TClntOptIA_PD(pd,this);
        Options.push_back( (Ptr*)pdOpt );
        pdOpt->setContext(srvDUID, addr, this);
        pdOpt->delPrefixes();

        ClntAddrMgr().delPD(pd->getIAID() );
    }

    appendElapsedOption();
    appendAuthenticationOption();

    IsDone = false;
    send();
}
Ejemplo n.º 4
0
bool TClntOptIA_PD::modifyPrefixes(TClntIfaceMgr::PrefixModifyMode mode)
{
    bool status = false;
    EState state = STATE_NOTCONFIGURED;
    SPtr<TClntOptIAPrefix> prefix;
    string action;
    switch(mode) {
      case TClntIfaceMgr::PREFIX_MODIFY_ADD:
        action = "addition";
        state = STATE_CONFIGURED;
        break;
      case TClntIfaceMgr::PREFIX_MODIFY_UPDATE:
        action = "update";
        state = STATE_CONFIGURED;
        break;
      case TClntIfaceMgr::PREFIX_MODIFY_DEL:
        action = "delete";
        state = STATE_NOTCONFIGURED;
        break;
    }
    
    if ( (mode==TClntIfaceMgr::PREFIX_MODIFY_ADD) || (mode==TClntIfaceMgr::PREFIX_MODIFY_UPDATE) ) {
      if ( (T1==0) && (T2==0) ) {
        firstPrefix();
        if (prefix = getPrefix()) {
          T1 = prefix->getPref()/2;
          T2 = (int)((prefix->getPref())*0.7);
          Log(Notice) << "Server set T1 and T2 to 0. Choosing default (50%, 70% * prefered-lifetime): T1=" << T1 
                      << ", T2=" << T2 << LogEnd;
        }
      }
    }

    this->firstPrefix();
    while (prefix = this->getPrefix() ) {
	switch (mode) {
    case TClntIfaceMgr::PREFIX_MODIFY_ADD:
	    ClntAddrMgr().addPrefix(this->DUID, this->Prefix, this->Iface, this->IAID, this->T1, this->T2,
                           prefix->getPrefix(), prefix->getPref(), prefix->getValid(), prefix->getPrefixLength(), false);
	    status = ClntIfaceMgr().addPrefix(this->Iface, prefix->getPrefix(), prefix->getPrefixLength(),
                                     prefix->getPref(), prefix->getValid());
        Log(Debug) << "RENEW will be sent (T1) after " << T1 << ", REBIND (T2) after " << T2 << " seconds." << LogEnd;
	    action = "addition";
	    break;
	case TClntIfaceMgr::PREFIX_MODIFY_UPDATE:
	    ClntAddrMgr().updatePrefix(this->DUID, this->Prefix, this->Iface, this->IAID, this->T1, this->T2,
				  prefix->getPrefix(), prefix->getPref(), prefix->getValid(), prefix->getPrefixLength(), false);
	    status = ClntIfaceMgr().updatePrefix(this->Iface, prefix->getPrefix(), prefix->getPrefixLength(),
					    prefix->getPref(), prefix->getValid());
        Log(Debug) << "RENEW will be sent (T1) after " << T1 << ", REBIND (T2) after " << T2 << " seconds." << LogEnd;
	    action = "update";
	    break;
	case TClntIfaceMgr::PREFIX_MODIFY_DEL:
	    ClntAddrMgr().delPrefix(ClntCfgMgr().getDUID(), this->IAID, prefix->getPrefix(), false);
	    status = ClntIfaceMgr().delPrefix(this->Iface, prefix->getPrefix(), prefix->getPrefixLength() );
	    action = "delete";
	    break;
	}
	
	if (!status) {
	    string tmp = error_message();
	    Log(Error) << "Prefix error encountered during prefix " << action << " operation: " << tmp << LogEnd;
            // Let's pretend it was configured and renew it
	    // setState(STATE_FAILED);
	    //return true;
	}
    }

    setState(state);
    return true;
}
Ejemplo n.º 5
0
    :TClntMsg(iface, addr, SOLICIT_MSG)
{
    IRT=SOL_TIMEOUT;
    MRT=SOL_MAX_RT;
    MRC=0; //these both below mean there is no ending condition and transactions
    MRD=0; //lasts till receiving answer
    RT=0;
	
    // ClientIdentifier option
    appendClientID();

    SPtr<TAddrIA> addrIA;
    
    // all IAs are provided by ::checkSolicit()
    SPtr<TClntCfgIA> ia;
    iaLst.first();
    while (ia = iaLst.get()) {
        SPtr<TClntOptIA_NA> iaOpt;
        iaOpt = new TClntOptIA_NA(ia, this);
        Options.push_back( (Ptr*)iaOpt );
        if (!remoteAutoconf)
            ia->setState(STATE_INPROCESS);
        addrIA = ClntAddrMgr().getIA(ia->getIAID());
        if (addrIA)
            addrIA->setState(STATE_INPROCESS);
        else
            Log(Error) << "AddrMgr does not have IA with IAID=" << ia->getIAID() << LogEnd;
    }

    // TA is provided by ::checkSolicit()
    if (ta) {
	SPtr<TClntOptTA> taOpt = new TClntOptTA(ta->getIAID(), this);
	Options.push_back( (Ptr*) taOpt);
	if (!remoteAutoconf)
	    ta->setState(STATE_INPROCESS);
        addrIA = ClntAddrMgr().getTA(ta->getIAID());
        if (addrIA)
            addrIA->setState(STATE_INPROCESS);
        else
            Log(Error) << "AddrMgr does not have TA with IAID=" << ia->getIAID() << LogEnd;
    }

    // all PDs are provided by ::checkSolicit()
    SPtr<TClntCfgPD> pd;
    pdLst.first();
    while ( pd = pdLst.get() ) {
        SPtr<TClntOptIA_PD> pdOpt = new TClntOptIA_PD(pd, this);
        Options.push_back( (Ptr*)pdOpt );
        if (!remoteAutoconf)
            pd->setState(STATE_INPROCESS);
        addrIA = ClntAddrMgr().getPD(pd->getIAID());
        if (addrIA)
            addrIA->setState(STATE_INPROCESS);
        else
            Log(Error) << "AddrMgr does not have PD with IAID=" << pd->getIAID() << LogEnd;
    }
    
    if (rapid)
        Options.push_back(new TOptEmpty(OPTION_RAPID_COMMIT, this));

    // RECONF-ACCEPT is added in TClntMsg::appendRequestedOptions()

    // append and switch to INPROCESS state
    if (!remoteAutoconf)
	appendTAOptions(true); 

    // append options specified in the config file
    if (!remoteAutoconf)
	appendRequestedOptions();

    appendAuthenticationOption();
    
    IsDone = false;
    send();
}
Ejemplo n.º 6
0
bool TClntOptIA_NA::doDuties() {

    // find this IA in addrMgr...
    SPtr<TAddrIA> ptrIA=ClntAddrMgr().getIA(this->getIAID());
    if (!ptrIA) {
        // unknown IAID, ignore it
        Log(Warning) << "Received message contains unknown IA (IAID="
                     << this->getIAID() << "). We didn't order it. Weird... ignoring it." << LogEnd;
        return true;
    }

    // IAID found, set up new received options.
    SPtr<TAddrAddr> ptrAddrAddr;
    SPtr<TOptIAAddress> ptrOptAddr;

    SPtr<TIfaceIface> ptrIface;
    ptrIface = ClntIfaceMgr().getIfaceByID(Iface_);
    if (!ptrIface)
    {
        Log(Error) << "Interface with ifindex=" << Iface_ << " not found." << LogEnd;
        return true;
    }

    // for each address in IA option...
    this->firstAddr();
    while (ptrOptAddr = this->getAddr() ) {
        ptrAddrAddr = ptrIA->getAddr( ptrOptAddr->getAddr() );

        // no such address in DB ??
        if (!ptrAddrAddr) {
            if (ptrOptAddr->getValid()) {

                int prefixLen = ptrIface->getPrefixLength();
                if (ptrOptAddr->getOption(OPTION_ADDRPARAMS)) {
                    Log(Debug) << "Experimental addr-params found." << LogEnd;
                    SPtr<TOptAddrParams> optAddrParams =
                        SPtr_cast<TOptAddrParams>(ptrOptAddr->getOption(OPTION_ADDRPARAMS));
                    prefixLen = optAddrParams->getPrefix();
                }

                // add this address in addrDB...
                ptrIA->addAddr(ptrOptAddr->getAddr(), ptrOptAddr->getPref(),
                               ptrOptAddr->getValid(), prefixLen);
                ptrIA->setDUID(this->DUID);

                // ... and in IfaceMgr -
                ptrIface->addAddr(ptrOptAddr->getAddr(), ptrOptAddr->getPref(),
                                  ptrOptAddr->getValid(), prefixLen);
            }
            else {
                Log(Warning) << "Server send new addr with valid lifetime 0." << LogEnd;
            }
        } else {
            // we have this addr in DB
            if ( ptrOptAddr->getValid() == 0 ) {
                // valid=0, release this address
                // delete address from addrDB
                ptrIA->delAddr(ptrOptAddr->getAddr());
                // delete address from IfaceMgr
                ptrIface->delAddr(ptrOptAddr->getAddr(), ptrIface->getPrefixLength());
                break; // analyze next option OPTION_IA_NA
            }

            // set up new options in IfaceMgr
            SPtr<TIfaceIface> ptrIface = ClntIfaceMgr().getIfaceByID(Iface_);
            if (ptrIface)
                ptrIface->updateAddr(ptrOptAddr->getAddr(),
                        ptrOptAddr->getPref(),
                        ptrOptAddr->getValid());
            // set up new options in addrDB
            ptrAddrAddr->setPref(ptrOptAddr->getPref());
            ptrAddrAddr->setValid(ptrOptAddr->getValid());
            ptrAddrAddr->setTimestamp();
        }
    }
    SPtr<TClntCfgIA> ptrCfgIA;
    ptrCfgIA=ClntCfgMgr().getIA(ptrIA->getIAID());

    if (getT1() && getT2()) {
        ptrIA->setT1( this->getT1() );
        ptrIA->setT2( this->getT2() );
        Log(Debug) << "RENEW(IA_NA) will be sent (T1) after " << ptrIA->getT1()
                   << ", REBIND (T2) after " << ptrIA->getT2() << " seconds." << LogEnd;
    } else {
        this->firstAddr();
        ptrOptAddr = this->getAddr();
        if (ptrOptAddr) {
            ptrIA->setT1( ptrOptAddr->getPref()/2);
            ptrIA->setT2( (int)((ptrOptAddr->getPref())*0.7) );
            Log(Notice) << "Server set T1 and T2 to 0. Choosing default (50%, "
                        << "70% * prefered-lifetime): T1=" << ptrIA->getT1()
                        << ", T2=" << ptrIA->getT2() << LogEnd;
        }
    }

    ptrIA->setTimestamp();
    ptrIA->setState(STATE_CONFIGURED);
    ptrCfgIA->setState(STATE_CONFIGURED);
    return true;
}
Ejemplo n.º 7
0
 */bool TClntOptTA::doDuties()
{
    // find this TA in addrMgr...
    SPtr<TAddrIA> ta = ClntAddrMgr().getTA(this->getIAID());

    if (!ta) {
	Log(Debug) << "Creating TA (iaid=" << this->getIAID() << ") in the addrDB." << LogEnd;
        ta = new TAddrIA(this->Iface, TAddrIA::TYPE_TA, 0 /*if unicast, then this->Addr*/, 
		         this->DUID, DHCPV6_INFINITY, 
		         DHCPV6_INFINITY, this->getIAID());
        ClntAddrMgr().addTA(ta);
    }

    // IAID found, set up new received options.
    SPtr<TAddrAddr> addr;
    SPtr<TClntOptIAAddress> optAddr;

    SPtr<TIfaceIface> ptrIface;
    ptrIface = ClntIfaceMgr().getIfaceByID(this->Iface);
    if (!ptrIface) 
    {
	Log(Error) << "Interface " << this->Iface << " not found." << LogEnd;
	return true;
    }

    // for each address in IA option...
    this->firstAddr();
    while (optAddr = this->getAddr() ) {
        addr = ta->getAddr( optAddr->getAddr() );
        
        if (!addr) { // - no such address in DB -
            if (!optAddr->getValid()) {
                Log(Warning) << "Server send new addr with valid=0." << LogEnd;
		continue;
	    }
	    // add this address in addrDB...
	    ta->addAddr(optAddr->getAddr(), optAddr->getPref(), optAddr->getValid());
	    ta->setDUID(this->DUID);
	    // ... and in IfaceMgr - 
	    ptrIface->addAddr(optAddr->getAddr(), optAddr->getPref(), optAddr->getValid(), ptrIface->getPrefixLength());
	    Log(Notice) << "Temp. address " << *optAddr->getAddr() << " has been added to "
			<< ptrIface->getName() << "/" << ptrIface->getID() 
			<< " interface." << LogEnd;

        } else { // - we have this addr in DB -

            if ( optAddr->getValid() == 0 ) {
                // valid=0, release this address and delete address from addrDB
                ta->delAddr(optAddr->getAddr());
                // delete address from IfaceMgr
                ptrIface->delAddr(optAddr->getAddr(), ptrIface->getPrefixLength());
                continue; // analyze next option OPTION_IA
            }

            // set up new options in IfaceMgr
	    ptrIface->updateAddr(optAddr->getAddr(), optAddr->getPref(), optAddr->getValid());
            // set up new options in addrDB
            addr->setPref(optAddr->getPref());
            addr->setValid(optAddr->getValid());
            addr->setTimestamp();
        }
    }

    // mark this TA as configured
    SPtr<TClntCfgTA> cfgTA;
    SPtr<TClntCfgIface> cfgIface;
    if (! (cfgIface = ClntCfgMgr().getIface(this->Iface)) ) {
        Log(Error) << "Unable to find TA class in the CfgMgr, on the " << this->Iface << " interface." << LogEnd;
        return true;
    }
    cfgIface->firstTA();
    cfgTA = cfgIface->getTA();
    cfgTA->setState(STATE_CONFIGURED);

    ta->setState(STATE_CONFIGURED);
    return true;
}