void TSrvMsgLeaseQueryReply::appendClientData(SPtr<TAddrClient> cli) { Log(Debug) << "LQ: Appending data for client " << cli->getDUID()->getPlain() << LogEnd; SPtr<TSrvOptLQClientData> cliData = new TSrvOptLQClientData(this); SPtr<TAddrIA> ia; SPtr<TAddrAddr> addr; SPtr<TAddrPrefix> prefix; unsigned long nowTs = now(); unsigned long cliTs = cli->getLastTimestamp(); unsigned long diff = nowTs - cliTs; Log(Debug) << "LQ: modifying the lifetimes (client last seen " << diff << "secs ago)." << LogEnd; // add all assigned addresses cli->firstIA(); while ( ia = cli->getIA() ) { ia->firstAddr(); while ( addr=ia->getAddr() ) { unsigned long a = addr->getPref() - diff; unsigned long b = addr->getValid() - diff; cliData->addOption( new TSrvOptIAAddress(addr->get(), a, b, this) ); } } // add all assigned prefixes cli->firstPD(); while ( ia = cli->getPD() ) { ia->firstPrefix(); while (prefix = ia->getPrefix()) { cliData->addOption( new TSrvOptIAPrefix( prefix->getPrefix(), prefix->getLength(), prefix->getPref(), prefix->getValid(), this)); } } cliData->addOption(new TOptDUID(OPTION_CLIENTID, cli->getDUID(), this)); // TODO: add all temporary addresses // add CLT_TIME Log(Debug) << "LQ: Adding CLT_TIME option: " << diff << " second(s)." << LogEnd; cliData->addOption( new TSrvOptLQClientTime(diff, this)); Options.push_back((Ptr*)cliData); }
/* CHANGED in this function: According to RFC3315,'status==STATE_NOTCONFIGURED' is not a must. * this method adds requested (which have status==STATE_NOTCONFIGURED) options */ void TClntMsg::appendRequestedOptions() { // find configuration specified in config file SPtr<TClntCfgIface> iface = ClntCfgMgr().getIface(this->Iface); if (!iface) { Log(Error) << "Unable to find interface with ifindex=" << this->Iface << LogEnd; return; } if ( (MsgType==SOLICIT_MSG || MsgType==REQUEST_MSG) && ClntCfgMgr().getReconfigure()) { SPtr<TOptEmpty> optReconfigure = new TOptEmpty(OPTION_RECONF_ACCEPT, this); Options.push_back( (Ptr*) optReconfigure); } SPtr<TClntOptOptionRequest> optORO = new TClntOptOptionRequest(iface, this); if (iface->getUnicast()) { optORO->addOption(OPTION_UNICAST); Log(Debug) << "Adding UNICAST to ORO." << LogEnd; } if (ClntCfgMgr().addInfRefreshTime()) { optORO->addOption(OPTION_INFORMATION_REFRESH_TIME); Log(Debug) << "Adding INFORMATION REFRESH TIME to ORO." << LogEnd; } // --- option: DNS-SERVERS --- if ( iface->isReqDNSServer() ) { optORO->addOption(OPTION_DNS_SERVERS); List(TIPv6Addr) * dnsLst = iface->getProposedDNSServerLst(); if (dnsLst->count()) { // if there are any hints specified in config file, include them Options.push_back( new TOptAddrLst(OPTION_DNS_SERVERS, *dnsLst, this) ); } iface->setDNSServerState(STATE_INPROCESS); } // --- option: DOMAINS -- if ( iface->isReqDomain() ) { optORO->addOption(OPTION_DOMAIN_LIST); List(string) * domainsLst = iface->getProposedDomainLst(); if ( domainsLst->count() ) { // if there are any hints specified in config file, include them Options.push_back( new TOptDomainLst(OPTION_DOMAIN_LIST, *domainsLst, this)); } iface->setDomainState(STATE_INPROCESS); } // --- option: NTP SERVER --- if ( iface->isReqNTPServer() ) { optORO->addOption(OPTION_SNTP_SERVERS); List(TIPv6Addr) * ntpLst = iface->getProposedNTPServerLst(); if (ntpLst->count()) { // if there are any hints specified in config file, include them Options.push_back( new TOptAddrLst(OPTION_SNTP_SERVERS, *ntpLst, this) ); } iface->setNTPServerState(STATE_INPROCESS); } // --- option: TIMEZONE --- if ( iface->isReqTimezone() ) { optORO->addOption(OPTION_NEW_TZDB_TIMEZONE); string timezone = iface->getProposedTimezone(); if (timezone.length()) { // if there are any hints specified in config file, include them SPtr<TClntOptTimeZone> opt = new TClntOptTimeZone(timezone,this); Options.push_back( (Ptr*)opt ); } iface->setTimezoneState(STATE_INPROCESS); } // --- option: SIP-SERVERS --- if ( iface->isReqSIPServer() ) { optORO->addOption(OPTION_SIP_SERVER_A); List(TIPv6Addr) * lst = iface->getProposedSIPServerLst(); if ( lst->count()) { // if there are any hints specified in config file, include them Options.push_back( new TOptAddrLst(OPTION_SIP_SERVER_A, *lst, this ) ); } iface->setSIPServerState(STATE_INPROCESS); } // --- option: SIP-DOMAINS --- if ( iface->isReqSIPDomain() ) { optORO->addOption(OPTION_SIP_SERVER_D); List(string) * domainsLst = iface->getProposedSIPDomainLst(); if ( domainsLst->count() ) { // if there are any hints specified in config file, include them Options.push_back( new TOptDomainLst(OPTION_SIP_SERVER_D, *domainsLst, this )); } iface->setSIPDomainState(STATE_INPROCESS); } // --- option: FQDN --- if ( iface->isReqFQDN() ) { optORO->addOption(OPTION_FQDN); string fqdn = iface->getProposedFQDN(); { SPtr<TClntOptFQDN> opt = new TClntOptFQDN( fqdn,this ); opt->setSFlag(ClntCfgMgr().getFQDNFlagS()); Options.push_back( (Ptr*)opt ); } iface->setFQDNState(STATE_INPROCESS); } // --- option: NIS-SERVERS --- if ( iface->isReqNISServer() ) { optORO->addOption(OPTION_NIS_SERVERS); List(TIPv6Addr) * lst = iface->getProposedNISServerLst(); if ( lst->count() ) { // if there are any hints specified in config file, include them Options.push_back( new TOptAddrLst(OPTION_NIS_SERVERS, *lst, this )); } iface->setNISServerState(STATE_INPROCESS); } // --- option: NIS-DOMAIN --- if ( iface->isReqNISDomain() ) { optORO->addOption(OPTION_NIS_DOMAIN_NAME); string domain = iface->getProposedNISDomain(); if (domain.length()) { Options.push_back( new TOptDomainLst(OPTION_NIS_DOMAIN_NAME, domain, this) ); } iface->setNISDomainState(STATE_INPROCESS); } // --- option: NIS+-SERVERS --- if ( iface->isReqNISPServer() ) { optORO->addOption(OPTION_NISP_SERVERS); List(TIPv6Addr) * lst = iface->getProposedNISPServerLst(); if ( lst->count() ) { // if there are any hints specified in config file, include them Options.push_back( new TOptAddrLst(OPTION_NISP_SERVERS, *lst, this) ); } iface->setNISPServerState(STATE_INPROCESS); } // --- option: NIS+-DOMAIN --- if ( iface->isReqNISPDomain() ) { optORO->addOption(OPTION_NISP_DOMAIN_NAME); string domain = iface->getProposedNISPDomain(); if (domain.length()) { Options.push_back( new TOptDomainLst(OPTION_NISP_DOMAIN_NAME, domain, this) ); } iface->setNISPDomainState(STATE_INPROCESS); } // --- option: Prefix Delegation --- // prefix delegation is supported in a similar way to IA and TA // see ClntTransMgr::checkSolicit() for details // --- option: LIFETIME --- if ( iface->isReqLifetime() && (this->MsgType == INFORMATION_REQUEST_MSG) && optORO->count() ) optORO->addOption(OPTION_INFORMATION_REFRESH_TIME); // --- option: VENDOR-SPEC --- if ( iface->isReqVendorSpec() ) { optORO->addOption(OPTION_VENDOR_OPTS); iface->setVendorSpecState(STATE_INPROCESS); SPtr<TOptVendorSpecInfo> optVendor; iface->firstVendorSpec(); while (optVendor = iface->getVendorSpec()) { Options.push_back( (Ptr*) optVendor); } } // --- option: Routing --- if ( (this->MsgType == SOLICIT_MSG || this->MsgType == REQUEST_MSG || this->MsgType == RENEW_MSG || this->MsgType == REBIND_MSG || this->MsgType == INFORMATION_REQUEST_MSG) && iface->isRoutingEnabled() ) { optORO->addOption(OPTION_NEXT_HOP); optORO->addOption(OPTION_RTPREFIX); // only for debugging Log(Debug) << "Adding NEXT_HOP and RTPREFIX to ORO." << LogEnd; } // --- option: ADDRPARAMS --- SPtr<TClntCfgIA> ia; iface->firstIA(); bool addrParams = false; while (ia = iface->getIA()) { if (ia->getAddrParams()) addrParams = true; } if (addrParams) optORO->addOption(OPTION_ADDRPARAMS); appendElapsedOption(); // --- generic options --- TClntCfgIface::TOptionStatusLst& genericOpts = iface->getExtraOptions(); for (TClntCfgIface::TOptionStatusLst::iterator gen = genericOpts.begin(); gen!=genericOpts.end(); ++gen) { if ( (*gen)->State == STATE_NOTCONFIGURED || (*gen)->State == STATE_INPROCESS || (*gen)->State == STATE_CONFIRMME) { optORO->addOption( (*gen)->OptionType); if ( (*gen)->Option && (*gen)->Always) Options.push_back( (*gen)->Option ); } } #ifdef MOD_REMOTE_AUTOCONF if (ClntCfgMgr().getRemoteAutoconf()) optORO->addOption(OPTION_NEIGHBORS); #endif // final setup: Did we add any options at all? if ( optORO->count() ) Options.push_back( (Ptr*) optORO ); }
/** * @brief appends authentication option. * */ void TClntMsg::appendAuthenticationOption() { #ifndef MOD_DISABLE_AUTH uint8_t algorithm = 0; // algorithm is protocol specific DigestType_ = DIGEST_NONE; // ClntAddrMgr().firstClient(); // SPtr<TAddrClient> client = ClntAddrMgr().getClient(); string realm; switch (ClntCfgMgr().getAuthProtocol()) { case AUTH_PROTO_NONE: { algorithm = 0; // Do not sent AUTH with proto=0. return; } case AUTH_PROTO_DELAYED: { algorithm = 1; realm = ClntCfgMgr().getAuthRealm(); break; } case AUTH_PROTO_RECONFIGURE_KEY: { // RFC 3315, section 21.5.1 // When reconfigure-key is enabled, client does not send anything return; } case AUTH_PROTO_DIBBLER: { // Mechanism proposed by Kowalczuk DigestType_ = ClntCfgMgr().getDigest(); algorithm = static_cast<uint8_t>(DigestType_); setSPI(ClntCfgMgr().getSPI()); SPtr<TClntOptOptionRequest> optORO = (Ptr*) getOption(OPTION_ORO); if (optORO) { // request Authentication optORO->addOption(OPTION_AUTH); } break; } default: { Log(Error) << "Auth: Invalid protocol specified. Can't sent AUTH option." << LogEnd; return; } } SPtr<TOptAuthentication> auth = new TOptAuthentication(ClntCfgMgr().getAuthProtocol(), algorithm, ClntCfgMgr().getAuthReplay(), this); // Realm is used by delayed-auth only. Even fro delayed-auth, it is set // only for non-SOLICIT messages if (MsgType != SOLICIT_MSG && !realm.empty()) { auth->setRealm(realm); } // replay detection if (ClntCfgMgr().getAuthReplay() == AUTH_REPLAY_MONOTONIC) { auth->setReplayDetection(ClntAddrMgr().getNextReplayDetectionValue()); } addOption((Ptr*)auth); // otherwise replay value is zero #endif }