int VBoxNetDhcp::processUDP(void *pv, size_t cbPv) { PCRTNETBOOTP pDhcpMsg = (PCRTNETBOOTP)pv; m_pCurMsg = pDhcpMsg; m_cbCurMsg = cbPv; uint8_t uMsgType; if (RTNetIPv4IsDHCPValid(NULL /* why is this here? */, pDhcpMsg, cbPv, &uMsgType)) { m_uCurMsgType = uMsgType; { /* To avoid fight with event processing thread */ VBoxNetALock(this); handleDhcpMsg(uMsgType, pDhcpMsg, cbPv); } m_uCurMsgType = UINT8_MAX; } else debugPrint(1, true, "VBoxNetDHCP: Skipping invalid DHCP packet.\n"); /** @todo handle pure bootp clients too? */ m_pCurMsg = NULL; m_cbCurMsg = 0; return VINF_SUCCESS; }
Client ConfigurationManager::getClientByDhcpPacket(const RTNETBOOTP *pDhcpMsg, size_t cbDhcpMsg) { VecClientIterator it; bool fDhcpValid = false; uint8_t uMsgType = 0; fDhcpValid = RTNetIPv4IsDHCPValid(NULL, pDhcpMsg, cbDhcpMsg, &uMsgType); AssertReturn(fDhcpValid, Client::NullClient); LogFlowFunc(("dhcp:mac:%RTmac\n", &pDhcpMsg->bp_chaddr.Mac)); /* 1st. client IDs */ for ( it = m->m_clients.begin(); it != m->m_clients.end(); ++it) { if ((*it) == pDhcpMsg->bp_chaddr.Mac) { LogFlowFunc(("client:mac:%RTmac\n", it->getMacAddress())); /* check timestamp that request wasn't expired. */ return (*it); } } if (it == m->m_clients.end()) { /* We hasn't got any session for this client */ Client c; c.initWithMac(pDhcpMsg->bp_chaddr.Mac); m->m_clients.push_back(c); return m->m_clients.back(); } return Client::NullClient; }