Changeset 17678 in vbox
- Timestamp:
- Mar 11, 2009 11:19:47 AM (16 years ago)
- 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$ 2 2 ## @file 3 3 # Sub-Makefile for VBoxNetDHCP. -
trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp
r17663 r17678 47 47 #include <vector> 48 48 #include <string> 49 50 /** @Todo move these: */ 51 52 /** The requested address. */ 53 #define RTNET_DHCP_OPT_REQUESTED_ADDRESS 50 49 54 50 55 … … 182 187 { 183 188 public: 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 184 205 /** The client MAC address. */ 185 206 RTMAC m_MacAddress; 207 /** The IPv4 address. */ 208 RTNETADDRIPV4 m_IPv4Address; 209 210 /** The current lease state. */ 211 State m_enmState; 186 212 /** The lease expiration time. */ 187 213 RTTIMESPEC m_ExpireTime; 214 /** Transaction ID. */ 215 uint32_t m_xid; 216 /** The configuration for this lease. */ 217 VBoxNetDhcpCfg *m_pCfg; 188 218 }; 189 219 … … 208 238 bool handleDhcpReqDecline(PCRTNETBOOTP pDhcpMsg, size_t cb); 209 239 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); 211 249 212 250 inline void debugPrint( int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const; … … 272 310 m_IpAddress.u = RT_H2N_U32_C(RT_BSWAP_U32_C(RT_MAKE_U32_FROM_U8( 10, 0, 2, 5))); 273 311 274 m_pSession = N ULL;312 m_pSession = NIL_RTR0PTR; 275 313 m_cbSendBuf = 8192; 276 314 m_cbRecvBuf = 51200; /** @todo tune to 64 KB with help from SrvIntR0 */ … … 324 362 { 325 363 SUPTerm(false /* not forced */); 326 m_pSession = N ULL;364 m_pSession = NIL_RTR0PTR; 327 365 } 328 366 } … … 496 534 if (RT_FAILURE(rc)) 497 535 { 498 m_pSession = N ULL;536 m_pSession = NIL_RTR0PTR; 499 537 RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: SUPR3Init -> %Rrc", rc); 500 538 return 1; … … 709 747 * If none was found, create a new lease for it and then construct a reply. 710 748 */ 711 VBoxNetDhcpLease *pLease = findLeaseByMacAddress( pDhcpMsg->bp_chaddr.Mac,749 VBoxNetDhcpLease *pLease = findLeaseByMacAddress(&pDhcpMsg->bp_chaddr.Mac, 712 750 true /* fEnsureUpToDateConfig */); 713 751 if (!pLease) … … 715 753 if (!pLease) 716 754 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); 720 758 return true; 721 759 } 722 760 723 724 /** The requested address. */725 #define RTNET_DHCP_OPT_REQUESTED_ADDRESS 50726 761 727 762 /** … … 735 770 bool VBoxNetDhcp::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb) 736 771 { 772 /** @todo Probably need to match the server IP here to work correctly with 773 * other servers. */ 774 737 775 /* 738 776 * Windows will reissue these requests when rejoining a network if it thinks it … … 740 778 * make a new one and return NAC. 741 779 */ 742 uint8_t uReplyType = RTNET_DHCP_MT_NAC;743 VBoxNetDhcpLease *pLease = NULL;744 780 RTNETADDRIPV4 IPv4Addr; 745 if (findOptionIPv4Addr(RTNET_DHCP_OPT_REQUESTED_ADDRESS, pDhcpMsg, cb, &I pv4Addr))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); 748 784 if (pLease) 749 785 { 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) 754 792 { 793 debugPrint(1, true, "bp_xid %#x != lease %#x", pDhcpMsg->bp_xid, pLease->m_xid); 794 return true; 755 795 } 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); 757 804 } 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 766 833 return true; 767 834 } … … 778 845 bool VBoxNetDhcp::handleDhcpReqDecline(PCRTNETBOOTP pDhcpMsg, size_t cb) 779 846 { 847 /** @todo Probably need to match the server IP here to work correctly with 848 * other servers. */ 849 780 850 /* 781 851 * The client is supposed to pass us option 50, requested address, … … 799 869 bool VBoxNetDhcp::handleDhcpReqRelease(PCRTNETBOOTP pDhcpMsg, size_t cb) 800 870 { 871 /** @todo Probably need to match the server IP here to work correctly with 872 * other servers. */ 873 801 874 /* 802 875 * The client may pass us option 61, client identifier, which we should … … 832 905 * @param cb The size of the client message. 833 906 */ 834 void VBoxNetDhcp:: handleDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb)907 void VBoxNetDhcp::makeDhcpReply(uint8_t uMsgType, VBoxNetDhcpLease *pLease, PCRTNETBOOTP pDhcpMsg, size_t cb) 835 908 { 836 909 /** @todo this is required. :-) */ 837 910 } 838 911 912 913 914 VBoxNetDhcpLease *VBoxNetDhcp::findLeaseByMacAddress(PCRTMAC pMacAddress, bool fEnsureUpToDateConfig) 915 { 916 return NULL; 917 } 918 919 920 VBoxNetDhcpLease *VBoxNetDhcp::findLeaseByIpv4AndMacAddresses(RTNETADDRIPV4 IPv4Addr, PCRTMAC pMacAddress) 921 { 922 return NULL; 923 924 } 925 926 VBoxNetDhcpLease *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 * 947 VBoxNetDhcp::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 964 VBoxNetDhcp::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 } 839 974 840 975
Note:
See TracChangeset
for help on using the changeset viewer.