VBoxNetDHCP.cpp revision 7bfbf0ce3fc47308e5088f7b34b185af5b314fc9
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * VBoxNetDHCP - DHCP Service for connecting to IntNet.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * available from http://www.virtualbox.org. This file is free software;
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * General Public License (GPL) as published by the Free Software
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * additional information or have any questions.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync/** @page pg_net_dhcp VBoxNetDHCP
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Write a few words...
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync/*******************************************************************************
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync* Header Files *
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync*******************************************************************************/
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync/*******************************************************************************
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync* Structures and Typedefs *
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync*******************************************************************************/
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * DHCP configuration item.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * This is all public data because I'm too lazy to do it propertly right now.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** The etheret addresses this matches config applies to.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * An empty vector means 'ANY'. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** The upper address in the range. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** The lower address in the range. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 1: The net mask. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 2: The time offset. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 3: Routers for the subnet. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 4: Time server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 5: Name server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 6: Domain Name Server (DNS) */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 7: Log server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 8: Cookie server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 9: LPR server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 10: Impress server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 11: Resource location server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 12: Host name. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync //std::string<char> m_HostName;
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 13: Boot file size option. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 14: Merit dump file. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 15: Domain name. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 16: Swap server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 17: Root path. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 18: Extension path. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 19: IP forwarding enable/disable. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 20: Non-local routing enable/disable. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 21: Policy filter. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 22: Maximum datagram reassembly size (MRS). */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 23: Default IP time-to-live. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 24: Path MTU aging timeout. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 25: Path MTU plateau table. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 26: Interface MTU. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 27: All subnets are local. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 28: Broadcast address. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 29: Perform maximum discovery. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 30: Mask supplier. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 31: Perform route discovery. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 32: Router solicitation address. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 33: Static route. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 34: Trailer encapsulation. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 35: ARP cache timeout. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 36: Ethernet encapsulation. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 37: TCP Default TTL. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 38: TCP Keepalive Interval. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 39: TCP Keepalive Garbage. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 40: Network Information Service (NIS) Domain. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 41: Network Information Servers. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 42: Network Time Protocol Servers. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 43: Vendor Specific Information. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 44: NetBIOS over TCP/IP Name Server (NBNS). */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 45: NetBIOS over TCP/IP Datagram distribution Server (NBDD). */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 46: NetBIOS over TCP/IP Node Type. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 47: NetBIOS over TCP/IP Scope. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 48: X Window System Font Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 49: X Window System Display Manager. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 51: IP Address Lease Time. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 64: Network Information Service+ Domain. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 65: Network Information Service+ Servers. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 66: TFTP server name. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Option 67: Bootfile name. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 68: Mobile IP Home Agent. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 69: Simple Mail Transport Protocol (SMPT) Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 70: Post Office Protocol (POP3) Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 71: Network News Transport Protocol (NNTP) Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 72: Default World Wide Web (WWW) Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 73: Default Finger Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 74: Default Internet Relay Chat (IRC) Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 75: StreetTalk Server. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /* * Option 119: Domain Search. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** Validates the configuration.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * @returns 0 on success, exit code + error message to stderr on failure. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: Config is missing:");
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * DHCP lease.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** The client MAC address. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** The lease expiration time. */
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * DHCP server instance.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync bool handleDhcpMsg(uint8_t uMsgType, PCRTNETBOOTP pDhcpMsg, size_t cb);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync bool handleDhcpReqDiscover(PCRTNETBOOTP pDhcpMsg, size_t cb);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync bool handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync bool handleDhcpReqDecline(PCRTNETBOOTP pDhcpMsg, size_t cb);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync bool handleDhcpReqRelease(PCRTNETBOOTP pDhcpMsg, size_t cb);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync void handleDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync inline void debugPrint( int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const;
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const;
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync static const char *debugDhcpName(uint8_t uMsgType);
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync /** @name The server configuration data members.
m_cVerbosity = 0;
m_cbCurMsg = 0;
if (m_pSession)
int rc = 0;
if (pCfg)
if (!rc)
delete pCfg;
return rc;
if (!rc)
switch (rc)
m_cVerbosity++;
if (rc)
if (!pCurCfg)
if (!pCurCfg)
switch (rc)
rc = 0;
return rc;
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPCallVMMR0Ex(,VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE,) failed, rc=%Rrc\n", rc);
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPCallVMMR0Ex(,VMMR0_DO_INTNET_IF_GET_RING3_BUFFER,) failed, rc=%Rrc\n", rc);
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPCallVMMR0Ex(,VMMR0_DO_INTNET_OPEN,) failed, rc=%Rrc\n", rc);
WaitReq.cMillies = 2000; /* 2 secs - the sleep is for some reason uninterruptible... */ /** @todo fix interruptability in SrvIntNet! */
debugPrint(1, true, "VBoxNetDHCP: Skipping invalid DHCP packet.\n"); /** @todo handle pure bootp clients too? */
m_cbCurMsg = 0;
switch (uMsgType)
case RTNET_DHCP_MT_DISCOVER:
case RTNET_DHCP_MT_REQUEST:
case RTNET_DHCP_MT_DECLINE:
case RTNET_DHCP_MT_RELEASE:
case RTNET_DHCP_MT_INFORM:
if (!pLease)
if (!pLease)
if (pLease)
if (pLease)
void VBoxNetDhcp::handleDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb)
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: %s: %N\n", iMinLevel >= 2 ? "debug" : "info", pszFmt, &vaCopy);
if ( fMsg
&& m_pCurMsg)
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: debug: %8s chaddr=%.6Rhxs ciaddr=%d.%d.%d.%d yiaddr=%d.%d.%d.%d siaddr=%d.%d.%d.%d\n",
m_pCurMsg->bp_ciaddr.au8[0], m_pCurMsg->bp_ciaddr.au8[1], m_pCurMsg->bp_ciaddr.au8[2], m_pCurMsg->bp_ciaddr.au8[3],
m_pCurMsg->bp_yiaddr.au8[0], m_pCurMsg->bp_yiaddr.au8[1], m_pCurMsg->bp_yiaddr.au8[2], m_pCurMsg->bp_yiaddr.au8[3],
m_pCurMsg->bp_siaddr.au8[0], m_pCurMsg->bp_siaddr.au8[1], m_pCurMsg->bp_siaddr.au8[2], m_pCurMsg->bp_siaddr.au8[3]);
switch (uMsgType)
if (!pDhcp)
if (rc)
return rc;
if (rc)
delete pDhcp;
return rc;
delete pDhcp;
return rc;
#ifndef VBOX_WITH_HARDENING