Exemplo n.º 1
0
/*
 * opens proper (multicast or unicast) socket on interface
 */
bool TRelTransMgr::openSocket(SPtr<TRelCfgIface> cfgIface) {

    SPtr<TIfaceIface> iface = RelIfaceMgr().getIfaceByID(cfgIface->getID());
    if (!iface) {
        Log(Crit) << "Unable to find " << cfgIface->getName() << "/" << cfgIface->getID()
                  << " interface in the IfaceMgr." << LogEnd;
        return false;
    }

    SPtr<TIPv6Addr> srvUnicast = cfgIface->getServerUnicast();
    SPtr<TIPv6Addr> clntUnicast = cfgIface->getClientUnicast();
    SPtr<TIPv6Addr> addr;

    if (cfgIface->getServerMulticast() || srvUnicast) {

        iface->firstGlobalAddr();
        addr = iface->getGlobalAddr();
        if (!addr) {
            Log(Warning) << "No global address defined on the " << iface->getFullName() << " interface."
                         << " Trying to bind link local address, but expect troubles with relaying." << LogEnd;
            iface->firstLLAddress();
            addr = new TIPv6Addr(iface->getLLAddress());
        }
        Log(Notice) << "Creating srv unicast (" << addr->getPlain() << ") socket on the "
                    << iface->getName() << "/" << iface->getID() << " interface." << LogEnd;
        if (!iface->addSocket(addr, DHCPSERVER_PORT, true, false)) {
            Log(Crit) << "Proper socket creation failed." << LogEnd;
            return false;
        }
    }

    if (cfgIface->getClientMulticast()) {
        addr = new TIPv6Addr(ALL_DHCP_RELAY_AGENTS_AND_SERVERS, true);
        Log(Notice) << "Creating clnt multicast (" << addr->getPlain() << ") socket on the "
                    << iface->getName() << "/" << iface->getID() << " interface." << LogEnd;
        if (!iface->addSocket(addr, DHCPSERVER_PORT, true, false)) {
            Log(Crit) << "Proper socket creation failed." << LogEnd;
            return false;
        }
    }

    if (clntUnicast) {
        addr = new TIPv6Addr(ALL_DHCP_RELAY_AGENTS_AND_SERVERS, true);
        Log(Notice) << "Creating clnt unicast (" << clntUnicast->getPlain() << ") socket on the "
                    << iface->getName() << "/" << iface->getID() << " interface." << LogEnd;
        if (!iface->addSocket(clntUnicast, DHCPSERVER_PORT, true, false)) {
            Log(Crit) << "Proper socket creation failed." << LogEnd;
            return false;
        }
    }

    return true;
}
Exemplo n.º 2
0
bool TClntTransMgr::openLoopbackSocket() {
    SPtr<TIfaceIface> ptrIface;

    // if BindReuse is set, return true from here and dont create new loopback socket to allow multiple instances 
    if (this->BindReuse)
        return true;

#ifndef WIN32
    SPtr<TIfaceIface> loopback;
    ClntIfaceMgr().firstIface();
    while (ptrIface=ClntIfaceMgr().getIface()) {
        if (!ptrIface->flagLoopback()) {
            continue;
            }
            loopback = ptrIface;
            break;
    }
    if (!loopback) {
           Log(Crit) << "Loopback interface not found!" << LogEnd;
           return false;
    }

    SPtr<TIPv6Addr> loopAddr = new TIPv6Addr("::", true);
    Log(Notice) << "Creating control (" << *loopAddr << ") socket on the " << loopback->getName() 
                << "/" << loopback->getID() << " interface." << LogEnd;

    if (!loopback->addSocket(loopAddr,DHCPCLIENT_PORT, false, true)) {
        Log(Crit) << "Proper socket creation failed." << LogEnd;
        return false;
    }
#endif
    return true;
}
Exemplo n.º 3
0
/*
 * opens proper (multicast or unicast) socket on interface
 */
bool TSrvTransMgr::openSocket(SPtr<TSrvCfgIface> confIface, int port) {

    int ifindex = -1;
    if (confIface->isRelay()) {
      ifindex = confIface->getRelayID();
    } else {
      ifindex = confIface->getID();
    }
    SPtr<TIfaceIface> iface = SrvIfaceMgr().getIfaceByID(ifindex);
    SPtr<TIPv6Addr> unicast = confIface->getUnicast();
    if (!iface) {
        Log(Crit) << "Unable to find interface with ifindex=" << ifindex << LogEnd;
        return false;
    }

    if (confIface->isRelay()) {
        Log(Info) << "Relay init: Creating socket on the underlaying interface: "
		  << iface->getFullName() << "." << LogEnd;
    }

    if (unicast) {
        /* unicast */
        Log(Notice) << "Creating unicast (" << *unicast << ") socket on "
		    << confIface->getFullName() << " interface." << LogEnd;
        if (!iface->addSocket(unicast, port, true, false)) {
            Log(Crit) << "Proper socket creation failed." << LogEnd;
            return false;
        }
    }

    char srvAddr[16];
    if (!confIface->isRelay()) {
        inet_pton6(ALL_DHCP_RELAY_AGENTS_AND_SERVERS,srvAddr);
    } else {
        inet_pton6(ALL_DHCP_SERVERS,srvAddr);
    }

    SPtr<TIPv6Addr> ipAddr(new TIPv6Addr(srvAddr));
    Log(Notice) << "Creating multicast (" << ipAddr->getPlain() << ") socket on "
                << confIface->getFullName() << " (" << iface->getFullName()
                << ") interface." << LogEnd;
    if (iface->getSocketByAddr(ipAddr)) {
        Log(Notice) << "Address " << ipAddr->getPlain() << " is already bound on the "
                    << iface->getName() << "." << LogEnd;
        return true;
    }

    if (!iface->addSocket(ipAddr, port, true, false)) {
        Log(Crit) << "Proper socket creation failed." << LogEnd;
        return false;
    }

#if 1
    if (!iface->countLLAddress()) {
        Log(Crit) << "There is no link-local address on " << iface->getFullName() << " defined." << LogEnd;
        return false;
    }
    memcpy(srvAddr, iface->firstLLAddress(), 16);
    SPtr<TIPv6Addr> llAddr = new TIPv6Addr(iface->firstLLAddress());
    if (iface->getSocketByAddr(llAddr)) {
        Log(Notice) << "Address " << llAddr->getPlain() << " is already bound on the "
            << iface->getName() << "." << LogEnd;
        return true;
    } else {
        Log(Notice) << "Creating link-local (" << llAddr->getPlain() << ") socket on " << iface->getFullName()
                    << " interface." << LogEnd;
        if (!iface->addSocket(llAddr, port, true, false)) {
            Log(Crit) << "Failed to create link-local socket on " << iface->getFullName() << " interface." << LogEnd;
            return false;
        }
    }
#endif

    return true;
}
Exemplo n.º 4
0
bool TClntTransMgr::openSockets(SPtr<TClntCfgIface> iface) {

    if (iface->noConfig())       
        return true;
    
    // open socket
    SPtr<TIfaceIface> realIface = ClntIfaceMgr().getIfaceByID(iface->getID());
    if (!realIface) {
            Log(Error) << "Interface " << iface->getFullName()
                           << " not present in system." << LogEnd;
        return false;
    }
    if (!realIface->flagUp()) {
        Log(Error) << "Interface " << realIface->getFullName()
                   << " is down. Unable to open socket." << LogEnd;
        return false;
    }
    if (!realIface->flagRunning()) {
        Log(Error) << "Interface " << realIface->getFullName()
                   << " is not running." << LogEnd;
        return false;
    }
    
    // get link-local address
    char* llAddr;
    realIface->firstLLAddress();
    llAddr=realIface->getLLAddress();
    if (!llAddr) {
        Log(Error) << "Interface " << realIface->getFullName()
                   << " does not have link-layer address. Weird." << LogEnd;
        return false;
    }

    // By default, we use the first link-local address on the interface
    SPtr<TIPv6Addr> addr = new TIPv6Addr(llAddr);

    // However, if the user specified bind-to address, we'll use that instead.
    if (iface->getBindToAddr()) {
        addr = iface->getBindToAddr();
        Log(Debug) << "Using bind-to address " << addr->getPlain() << " on interface "
                   << iface->getFullName() << LogEnd;
    }

    // it's very important to open unicast socket first as it will be used for
    // unicast communication
    if (iface->getUnicast()) {
        Log(Notice) << "Creating socket for unicast communication on " << iface->getFullName()
                    << LogEnd;
        SPtr<TIPv6Addr> anyaddr = new TIPv6Addr("::", true); // don't bind to a specific address
        if (!realIface->addSocket(anyaddr, DHCPCLIENT_PORT, false, this->BindReuse)) {
            Log(Crit) << "Unicast socket creation (addr=" << anyaddr->getPlain() << ") on " 
                      << iface->getFullName() << " interface failed." << LogEnd;
            return false;
        }

    }

    Log(Notice) << "Creating socket (addr=" << *addr << ") on " 
                << iface->getFullName() << " interface." << LogEnd;
    if (!realIface->addSocket(addr,DHCPCLIENT_PORT,true, this->BindReuse)) {
        Log(Crit) << "Socket creation (addr=" << *addr << ") on " 
                  << iface->getFullName() << " interface failed." << LogEnd;
        return false;
    }

    if (llAddr) {
        char buf[48];
        inet_ntop6(llAddr,buf);
        CtrlIface_ = realIface->getID();
        strncpy(CtrlAddr_, buf, 48);
    } 

    return true;
}
Exemplo n.º 5
0
/*
 * opens proper (multicast or unicast) socket on interface
 */
bool TSrvTransMgr::openSocket(SPtr<TSrvCfgIface> confIface) {

    SPtr<TSrvIfaceIface> iface = (Ptr*)SrvIfaceMgr().getIfaceByID(confIface->getID());
    SPtr<TIPv6Addr> unicast = confIface->getUnicast();

    if (confIface->isRelay()) {
        while (iface->getUnderlaying()) {
            iface = iface->getUnderlaying();
        }
        if (!iface->countSocket())
            Log(Notice) << "Relay init: Creating socket on the underlaying interface: " << iface->getName()
                        << "/" << iface->getID() << "." << LogEnd;
    }

    if (unicast) {
        /* unicast */
        Log(Notice) << "Creating unicast (" << *unicast << ") socket on " << confIface->getName()
                    << "/" << confIface->getID() << " interface." << LogEnd;
        if (!iface->addSocket( unicast, DHCPSERVER_PORT, true, false)) {
            Log(Crit) << "Proper socket creation failed." << LogEnd;
            return false;
        }
    }

    // Creating TCP socket
    if (SrvCfgMgr().isBulkSupported()) {
        Log(Notice) << "Bulk-leasequery accepted. Creating TCP socket on" << confIface->getName()
                       <<"/" << confIface->getID() << " interface." << LogEnd;
        if (!iface->addTcpSocket(unicast,DHCPSERVER_PORT,0)) {
            Log(Crit) << "Proper TCP socket creation failed." << LogEnd;
        }
    }

    char srvAddr[16];
    if (!confIface->isRelay()) {
        inet_pton6(ALL_DHCP_RELAY_AGENTS_AND_SERVERS,srvAddr);
    } else {
        inet_pton6(ALL_DHCP_SERVERS,srvAddr);
    }

    SPtr<TIPv6Addr> ipAddr(new TIPv6Addr(srvAddr));
    Log(Notice) << "Creating multicast (" << ipAddr->getPlain() << ") socket on " << confIface->getName()
                << "/" << confIface->getID() << " (" << iface->getName() << "/"
                << iface->getID() << ") interface." << LogEnd;
    if (iface->getSocketByAddr(ipAddr)) {
        Log(Notice) << "Address " << ipAddr->getPlain() << " is already bound on the "
                    << iface->getName() << "." << LogEnd;
        return true;
    }

    if (!iface->addSocket(ipAddr, DHCPSERVER_PORT, true, false)) {
        Log(Crit) << "Proper socket creation failed." << LogEnd;
        return false;
    }

#if 1
    if (!iface->countLLAddress()) {
        Log(Crit) << "There is no link-local address on " << iface->getFullName() << " defined." << LogEnd;
        return false;
    }
    memcpy(srvAddr, iface->firstLLAddress(), 16);
    SPtr<TIPv6Addr> llAddr = new TIPv6Addr(iface->firstLLAddress());
    if (iface->getSocketByAddr(llAddr)) {
        Log(Notice) << "Address " << llAddr->getPlain() << " is already bound on the "
            << iface->getName() << "." << LogEnd;
        return true;
    } else {
        Log(Notice) << "Creating link-local (" << llAddr->getPlain() << ") socket on " << iface->getFullName()
                    << " interface." << LogEnd;
        if (!iface->addSocket(llAddr, DHCPSERVER_PORT, true, false)) {
            Log(Crit) << "Failed to create link-local socket on " << iface->getFullName() << " interface." << LogEnd;
            return false;
        }
    }
#endif

    return true;
}