当前位置: 首页>>代码示例>>C++>>正文


C++ SPtr::checkReservedPrefix方法代码示例

本文整理汇总了C++中SPtr::checkReservedPrefix方法的典型用法代码示例。如果您正苦于以下问题:C++ SPtr::checkReservedPrefix方法的具体用法?C++ SPtr::checkReservedPrefix怎么用?C++ SPtr::checkReservedPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SPtr的用法示例。


在下文中一共展示了SPtr::checkReservedPrefix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: List

/**
 * @brief returns list of free prefixes for this client
 *
 * return free prefixes for a client. There are several ways that method may work:
 * 1 - client didn't provide any hints:
 *     => one prefix from each pool will be granted
 * 2 - client has provided hint and that is valid (supported and unused):
 *     => requested prefix will be granted
 * 3 - client has provided hint, which belongs to supported pool, but this prefix is used:
 *     => other prefix from that pool will be asigned
 * 4 - client has provided hint, but it is invalid (not beloninging to a supported pool,
 *     multicast or link-local):
 *     => see 1
 *
 * @param clientMsg message received from a client
 * @param cli_hint hint provided by client (or ::)
 *
 * @return - list of prefixes
 */
List(TIPv6Addr) TSrvOptIA_PD::getFreePrefixes(SPtr<TSrvMsg> clientMsg, SPtr<TIPv6Addr> cli_hint) {

    SPtr<TSrvCfgIface> ptrIface;
    SPtr<TIPv6Addr>    prefix;
    SPtr<TSrvCfgPD>    ptrPD;
    bool validHint = true;
    List(TIPv6Addr) lst;

    lst.clear();
    ptrIface = SrvCfgMgr().getIfaceByID(this->Iface);
    if (!ptrIface) {
      Log(Error) << "PD: Trying to find free prefix on non-existent interface (ifindex="
                 << this->Iface << ")." << LogEnd;
      return lst; // empty list
    }

    if (!ptrIface->supportPrefixDelegation()) {
      // this method should not be called anyway
      Log(Error) << "PD: Prefix delegation is not supported on the " << ptrIface->getFullName()
                 << "." << LogEnd;
      return lst; // empty list
    }

    ptrIface->firstPD();
    ptrPD = ptrIface->getPD();
    // should be ==, asigned>total should never happen
    if (ptrPD->getAssignedCount() >= ptrPD->getTotalCount()) {
      Log(Error) << "PD: Unable to grant any prefixes: Already asigned " << ptrPD->getAssignedCount()
                 << " out of " << ptrPD->getTotalCount() << "." << LogEnd;
      return lst; // empty list
    }

    // check if this prefix is ok

    // is it anyaddress (::)?
    SPtr<TIPv6Addr> anyaddr = new TIPv6Addr();
    if (*anyaddr==*cli_hint) {
        Log(Debug) << "PD: Client requested unspecified (" << *cli_hint
                   << ") prefix. Hint ignored." << LogEnd;
        validHint = false;
    }

    // is it multicast address (ff...)?
    if ((*(cli_hint->getAddr()))==0xff) {
        Log(Debug) << "PD: Client requested multicast (" << *cli_hint
                   << ") prefix. Hint ignored." << LogEnd;
        validHint = false;
    }

    // is it link-local address (fe80::...)?
    char linklocal[]={0xfe, 0x80};
    if (!memcmp(cli_hint->getAddr(),linklocal,2)) {
        Log(Debug) << "PD: Client requested link-local (" << *cli_hint
                   << ") prefix. Hint ignored." << LogEnd;
        validHint = false;
    }

    SPtr<TOptVendorData> remoteID;
    TSrvMsg * par = (TSrvMsg*)(Parent);
    if (par) {
        remoteID = par->getRemoteID();
    }

    if ( validHint ) {
        // hint is valid, try to use it
        ptrPD = SrvCfgMgr().getClassByPrefix(this->Iface, cli_hint);

        // if the PD allow the hint, based on DUID, Addr, and Msg from client
        if (ptrPD && ptrPD->clntSupported(ClntDuid, ClntAddr, clientMsg)) {

            // Let's make a copy of the hint (we may need to tweak the hint in a second)
            SPtr<TIPv6Addr> hint(new TIPv6Addr(cli_hint->getAddr()));

            // Now zero the remaining part
            hint->truncate(0, ptrPD->getPD_Length());
            
            // Is this hint reserved for someone else?
            if (!ptrIface->checkReservedPrefix(hint, ClntDuid, remoteID, ClntAddr))
            {
                // Nope, not reserved.

//.........这里部分代码省略.........
开发者ID:justincormack,项目名称:dibbler,代码行数:101,代码来源:SrvOptIA_PD.cpp


注:本文中的SPtr::checkReservedPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。