VirtualBox

Changeset 17678 in vbox


Ignore:
Timestamp:
Mar 11, 2009 11:19:47 AM (16 years ago)
Author:
vboxsync
Message:

More code.

Location:
trunk/src/VBox/NetworkServices/DHCP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/DHCP/Makefile.kmk

    r17320 r17678  
    1 # $Id$
     1 # $Id$
    22## @file
    33# Sub-Makefile for VBoxNetDHCP.
  • trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp

    r17663 r17678  
    4747#include <vector>
    4848#include <string>
     49
     50/** @Todo move these:  */
     51
     52/** The requested address. */
     53#define RTNET_DHCP_OPT_REQUESTED_ADDRESS    50
    4954
    5055
     
    182187{
    183188public:
     189    typedef enum State
     190    {
     191        /** The lease is free / released. */
     192        kState_Free = 0,
     193        /** An offer has been made.
     194         * Expire time indicates when the offer expires. */
     195        kState_Offer,
     196        /** The lease is active.
     197         * Expire time indicates when the lease expires. */
     198        kState_Active
     199    } State;
     200
     201    void            offer(uint32_t xid);
     202    void            activate(void);
     203    void            release(void);
     204
    184205    /** The client MAC address. */
    185206    RTMAC           m_MacAddress;
     207    /** The IPv4 address. */
     208    RTNETADDRIPV4   m_IPv4Address;
     209
     210    /** The current lease state. */
     211    State           m_enmState;
    186212    /** The lease expiration time. */
    187213    RTTIMESPEC      m_ExpireTime;
     214    /** Transaction ID. */
     215    uint32_t        m_xid;
     216    /** The configuration for this lease. */
     217    VBoxNetDhcpCfg *m_pCfg;
    188218};
    189219
     
    208238    bool                handleDhcpReqDecline(PCRTNETBOOTP pDhcpMsg, size_t cb);
    209239    bool                handleDhcpReqRelease(PCRTNETBOOTP pDhcpMsg, size_t cb);
    210     void                handleDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb);
     240    void                makeDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb);
     241
     242    VBoxNetDhcpLease   *findLeaseByMacAddress(PCRTMAC pMacAddress, bool fEnsureUpToDateConfig);
     243    VBoxNetDhcpLease   *findLeaseByIpv4AndMacAddresses(RTNETADDRIPV4 IPv4Addr, PCRTMAC pMacAddress);
     244    VBoxNetDhcpLease   *newLease(PCRTNETBOOTP pDhcpMsg, size_t cb);
     245    void                updateLeaseConfig(VBoxNetDhcpLease *pLease);
     246
     247    static uint8_t     *findOption(uint8_t uOption, PCRTNETBOOTP pDhcpMsg, size_t cb, size_t *pcbMaxOpt);
     248    static bool         findOptionIPv4Addr(uint8_t uOption, PCRTNETBOOTP pDhcpMsg, size_t cb, PRTNETADDRIPV4 pIPv4Addr);
    211249
    212250    inline void         debugPrint( int32_t iMinLevel, bool fMsg,  const char *pszFmt, ...) const;
     
    272310    m_IpAddress.u           = RT_H2N_U32_C(RT_BSWAP_U32_C(RT_MAKE_U32_FROM_U8( 10,  0,  2,  5)));
    273311
    274     m_pSession              = NULL;
     312    m_pSession              = NIL_RTR0PTR;
    275313    m_cbSendBuf             =  8192;
    276314    m_cbRecvBuf             = 51200; /** @todo tune to 64 KB with help from SrvIntR0 */
     
    324362    {
    325363        SUPTerm(false /* not forced */);
    326         m_pSession = NULL;
     364        m_pSession = NIL_RTR0PTR;
    327365    }
    328366}
     
    496534    if (RT_FAILURE(rc))
    497535    {
    498         m_pSession = NULL;
     536        m_pSession = NIL_RTR0PTR;
    499537        RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPR3Init -> %Rrc", rc);
    500538        return 1;
     
    709747     * If none was found, create a new lease for it and then construct a reply.
    710748     */
    711     VBoxNetDhcpLease *pLease = findLeaseByMacAddress(pDhcpMsg->bp_chaddr.Mac,
     749    VBoxNetDhcpLease *pLease = findLeaseByMacAddress(&pDhcpMsg->bp_chaddr.Mac,
    712750                                                     true /* fEnsureUpToDateConfig */);
    713751    if (!pLease)
     
    715753    if (!pLease)
    716754        return false;
    717     pLease->setState(pLease::kState_Discover);
    718 
    719     handleDhcpReply(RTNET_DHCP_MT_OFFER, pLease, pDhcpMsg, cb);
     755    pLease->offer(pDhcpMsg->bp_xid);
     756
     757    makeDhcpReply(RTNET_DHCP_MT_OFFER, pLease, pDhcpMsg, cb);
    720758    return true;
    721759}
    722760
    723 
    724 /** The requested address. */
    725 #define RTNET_DHCP_OPT_REQUESTED_ADDRESS    50
    726761
    727762/**
     
    735770bool VBoxNetDhcp::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb)
    736771{
     772    /** @todo Probably need to match the server IP here to work correctly with
     773     *        other servers. */
     774
    737775    /*
    738776     * Windows will reissue these requests when rejoining a network if it thinks it
     
    740778     * make a new one and return NAC.
    741779     */
    742     uint8_t             uReplyType  = RTNET_DHCP_MT_NAC;
    743     VBoxNetDhcpLease   *pLease      = NULL;
    744780    RTNETADDRIPV4       IPv4Addr;
    745     if (findOptionIPv4Addr(RTNET_DHCP_OPT_REQUESTED_ADDRESS, pDhcpMsg, cb, &Ipv4Addr))
    746     {
    747         pLease = findLeaseByIpv4AndMacAddresses(Ipv4Addr, pDhcpMsg->bp_chaddr);
     781    if (findOptionIPv4Addr(RTNET_DHCP_OPT_REQUESTED_ADDRESS, pDhcpMsg, cb, &IPv4Addr))
     782    {
     783        VBoxNetDhcpLease *pLease = findLeaseByIpv4AndMacAddresses(IPv4Addr, &pDhcpMsg->bp_chaddr.Mac);
    748784        if (pLease)
    749785        {
    750             /** @todo check how windows treats bp_xid here, it should match I think. If
    751              *        it doesn't we've no way of filtering out broadcast replies to other
    752              *        DHCP servers. */
    753             if (pDhcpMsg->bp_xid == )
     786            /* Check if the xid matches, if it doesn't it's not our call. */
     787#if 0      /** @todo check how windows treats bp_xid here, it should match I think. If
     788            *        it doesn't we've no way of filtering out broadcast replies to other
     789            *        DHCP servers. Fix this later.
     790            */
     791            if (pDhcpMsg->bp_xid != pLease->m_xid)
    754792            {
     793                debugPrint(1, true, "bp_xid %#x != lease %#x", pDhcpMsg->bp_xid, pLease->m_xid);
     794                return true;
    755795            }
    756 
     796#endif
     797            /* Check if the config has changed since the offer was given? NAK it then? */
     798
     799            /*
     800             * Ack it.
     801             */
     802            pLease->activate();
     803            makeDhcpReply(RTNET_DHCP_MT_ACK, pLease, pDhcpMsg, cb);
    757804        }
    758     }
    759 
    760     if (pLease)
    761     {
    762     }
    763 
    764 
    765     /** @todo this code IS required. */
     805        else
     806        {
     807            /*
     808             * Try make a new offer and see if we get the requested IP and config, that
     809             * will make the (windows) client happy apparently...
     810             */
     811            pLease = newLease(pDhcpMsg, cb);
     812            if (    pLease
     813                &&  pLease->m_IPv4Address.u == IPv4Addr.u
     814                /** @todo match requested config later */)
     815            {
     816                /* ACK it. */
     817                pLease->activate();
     818                makeDhcpReply(RTNET_DHCP_MT_ACK, pLease, pDhcpMsg, cb);
     819            }
     820            else
     821            {
     822                /* NAK it */
     823                if (pLease)
     824                    pLease->release();
     825                pLease->activate();
     826                makeDhcpReply(RTNET_DHCP_MT_NAC, NULL, pDhcpMsg, cb);
     827            }
     828        }
     829    }
     830    else
     831        debugPrint(1, true, "No requested address option");
     832
    766833    return true;
    767834}
     
    778845bool VBoxNetDhcp::handleDhcpReqDecline(PCRTNETBOOTP pDhcpMsg, size_t cb)
    779846{
     847    /** @todo Probably need to match the server IP here to work correctly with
     848     *        other servers. */
     849
    780850    /*
    781851     * The client is supposed to pass us option 50, requested address,
     
    799869bool VBoxNetDhcp::handleDhcpReqRelease(PCRTNETBOOTP pDhcpMsg, size_t cb)
    800870{
     871    /** @todo Probably need to match the server IP here to work correctly with
     872     *        other servers. */
     873
    801874    /*
    802875     * The client may pass us option 61, client identifier, which we should
     
    832905 * @param   cb              The size of the client message.
    833906 */
    834 void VBoxNetDhcp::handleDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb)
     907void VBoxNetDhcp::makeDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb)
    835908{
    836909    /** @todo this is required. :-) */
    837910}
    838911
     912
     913
     914VBoxNetDhcpLease *VBoxNetDhcp::findLeaseByMacAddress(PCRTMAC pMacAddress, bool fEnsureUpToDateConfig)
     915{
     916    return NULL;
     917}
     918
     919
     920VBoxNetDhcpLease *VBoxNetDhcp::findLeaseByIpv4AndMacAddresses(RTNETADDRIPV4 IPv4Addr, PCRTMAC pMacAddress)
     921{
     922    return NULL;
     923
     924}
     925
     926VBoxNetDhcpLease *VBoxNetDhcp::newLease(PCRTNETBOOTP pDhcpMsg, size_t cb)
     927{
     928
     929    return NULL;
     930}
     931
     932
     933/**
     934 * Finds an option.
     935 *
     936 * @returns On success, a pointer to the option number within the DHCP message
     937 *          and *pcbMaxOpt set to the maximum number of bytes the option may
     938 *          contain.
     939 *          If not found NULL is returned and *pcbMaxOpt is not changed.
     940 *
     941 * @param   uOption         The option to search for.
     942 * @param   pDhcpMsg        The DHCP message.
     943 * @param   cb              The size of the message.
     944 * @param   pcbMaxOpt       Where to store the max option size. Optional.
     945 */
     946/* static */ uint8_t *
     947VBoxNetDhcp::findOption(uint8_t uOption, PCRTNETBOOTP pDhcpMsg, size_t cb, size_t *pcbMaxOpt)
     948{
     949    return NULL;
     950}
     951
     952
     953/**
     954 * Locates an option with an IPv4 address in the DHCP message.
     955 *
     956 * @returns true and *pIpv4Addr if found, false if not.
     957 *
     958 * @param   uOption         The option to find.
     959 * @param   pDhcpMsg        The DHCP message.
     960 * @param   cb              The size of the message.
     961 * @param   pIPv4Addr       Where to put the address.
     962 */
     963/* static */ bool
     964VBoxNetDhcp::findOptionIPv4Addr(uint8_t uOption, PCRTNETBOOTP pDhcpMsg, size_t cb, PRTNETADDRIPV4 pIPv4Addr)
     965{
     966    size_t   cbMaxOpt;
     967    uint8_t *pbOpt = findOption(uOption, pDhcpMsg, cb, &cbMaxOpt);
     968    if (pbOpt)
     969    {
     970
     971    }
     972    return false;
     973}
    839974
    840975
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette