/** * The client is requesting an offer. * * @returns true. * * @param pDhcpMsg The message. * @param cb The message size. */ bool NetworkManager::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb) { ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager(); /* 1. find client */ Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb); /* 2. find bound lease */ Lease l = client.lease(); if (l != Lease::NullLease) { if (l.isExpired()) { /* send client to INIT state */ Client c(client); nak(client, pDhcpMsg->bp_xid); confManager->expireLease4Client(c); return true; } else { /* XXX: Validate request */ RawOption opt; RT_ZERO(opt); Client c(client); int rc = confManager->commitLease4Client(c); AssertRCReturn(rc, false); rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt); AssertRCReturn(rc, false); ack(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt); } } else { nak(client, pDhcpMsg->bp_xid); } return true; }
/** * The client is requesting an offer. * * @returns true. * * @param pDhcpMsg The message. * @param cb The message size. */ bool NetworkManager::handleDhcpReqDiscover(PCRTNETBOOTP pDhcpMsg, size_t cb) { RawOption opt; RT_ZERO(opt); /* 1. Find client */ ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager(); Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb); /* 2. Find/Bind lease for client */ Lease lease = confManager->allocateLease4Client(client, pDhcpMsg, cb); AssertReturn(lease != Lease::NullLease, VINF_SUCCESS); int rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt); /* 3. Send of offer */ lease.bindingPhase(true); lease.phaseStart(RTTimeMilliTS()); lease.setExpiration(300); /* 3 min. */ offer4Client(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt); return VINF_SUCCESS; }