- Timestamp:
- Jun 29, 2009 4:11:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r21004 r21009 58 58 #define VBOX_NAT_DELAY_HACK 59 59 60 61 #define GET_EXTRADATA(node, drv_inst, name, rc, type, type_name, var) \ 62 do { \ 63 (rc) = CFGMR3Query ## type((node), name, &(var)); \ 64 if (RT_FAILURE((rc)) && (rc) != VERR_CFGM_VALUE_NOT_FOUND) \ 65 return PDMDrvHlpVMSetError(pThis->pDrvIns, (rc), RT_SRC_POS, N_("NAT#%d: configuration" \ 66 " query for \""name"\" " #type_name " failed"), (drv_inst)); \ 67 }while(0) 68 69 #define GET_EXTRADATA_N(node, drv_inst, name, rc, type, type_name, var, var_size) \ 70 do { \ 71 (rc) = CFGMR3Query ## type((node), name, &(var), var_size); \ 72 if (RT_FAILURE((rc)) && (rc) != VERR_CFGM_VALUE_NOT_FOUND) \ 73 return PDMDrvHlpVMSetError(pThis->pDrvIns, (rc), RT_SRC_POS, N_("NAT#%d: configuration" \ 74 " query for \""name"\" " #type_name " failed"), (drv_inst)); \ 75 }while(0) 76 77 #define GET_BOOL(rc, node, drv_inst, name, var) \ 78 GET_EXTRADATA(node, drv_inst, name, (rc), Bool, bolean, (var)) 79 #define GET_STRING(rc, node, drv_inst, name, var, var_size) \ 80 GET_EXTRADATA_N(node, drv_inst, name, (rc), String, string, (var), (var_size)) 81 #define GET_STRING_ALLOC(rc, node, drv_inst, name, var) \ 82 GET_EXTRADATA(node, drv_inst, name, (rc), StringAlloc, string, (var)) 60 83 61 84 /******************************************************************************* … … 648 671 bool fUDP; 649 672 char szProtocol[32]; 650 int rc = CFGMR3QueryString(pNode, "Protocol", &szProtocol[0], sizeof(szProtocol)); 673 int rc; 674 GET_STRING(rc, pNode, iInstance, "Protocol", szProtocol[0], sizeof(szProtocol)); 651 675 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 652 676 { 653 rc = CFGMR3QueryBool(pNode, "UDP", &fUDP); 654 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 655 fUDP = false; 656 else if (RT_FAILURE(rc)) 657 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"UDP\" boolean failed"), iInstance); 677 fUDP = false; 678 GET_BOOL(rc, pNode, iInstance, "UDP", fUDP); 658 679 } 659 680 else if (RT_SUCCESS(rc)) … … 664 685 fUDP = true; 665 686 else 666 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS, N_("NAT#%d: Invalid configuration value for \"Protocol\": \"%s\""), iInstance, szProtocol); 687 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS, 688 N_("NAT#%d: Invalid configuration value for \"Protocol\": \"%s\""), 689 iInstance, szProtocol); 667 690 } 668 else 669 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Protocol\" string failed"), iInstance); 670 671 #define DOGETIP(rc, status, x) \ 672 do { \ 673 char sz##x[32]; \ 674 rc = CFGMR3QueryString(pNode, #x, &sz ## x[0], sizeof(sz ## x)); \ 675 if (rc == VERR_CFGM_VALUE_NOT_FOUND) \ 676 RTStrPrintf(sz ## x, sizeof(sz ## x), "%d.%d.%d.%d", \ 677 (Network & 0xFF000000) >> 24, (Network & 0xFF0000) >> 16, (Network & 0xFF00) >> 8, (Network & 0xE0) | 15); \ 678 else if (RT_FAILURE(rc)) \ 679 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"" #x "\" string failed"), iInstance); \ 680 status = inet_aton(sz ## x, &x); \ 691 692 #define DOGETIP(rc, status, x) \ 693 do { \ 694 char sz##x[32]; \ 695 GET_STRING(rc, pNode, iInstance, #x, sz ## x[0], sizeof(sz ## x)); \ 696 if (rc == VERR_CFGM_VALUE_NOT_FOUND) \ 697 RTStrPrintf(sz ## x, sizeof(sz ## x), "%d.%d.%d.%d", \ 698 (Network & 0xFF000000) >> 24, (Network & 0xFF0000) >> 16, \ 699 (Network & 0xFF00) >> 8, (Network & 0xE0) | 15); \ 700 status = inet_aton(sz ## x, &x); \ 681 701 }while(0) 682 702 683 #define GETIP(x) \ 684 do \ 685 { \ 686 int status = 0; \ 687 DOGETIP(rc, status, x); \ 688 if (status == 0) \ 689 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, \ 690 N_("NAT#%d: configuration error: invalid \"" #x "\" inet_aton failed"), iInstance); \ 703 #define GETIP(x) \ 704 do \ 705 { \ 706 int status = 0; \ 707 DOGETIP(rc, status, x); \ 708 if (status == 0) \ 709 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, \ 710 N_("NAT#%d: configuration error: invalid \"" #x \ 711 "\" inet_aton failed"), iInstance); \ 691 712 }while(0) 692 713 693 #define GETIP_DEF(x, def) 694 do 695 { 696 int status = 0; 697 DOGETIP(rc, status, x); 698 if (status == 0 || rc == VERR_CFGM_VALUE_NOT_FOUND) 699 x.s_addr = def; 714 #define GETIP_DEF(x, def) \ 715 do \ 716 { \ 717 int status = 0; \ 718 DOGETIP(rc, status, x); \ 719 if (status == 0 || rc == VERR_CFGM_VALUE_NOT_FOUND) \ 720 x.s_addr = def; \ 700 721 }while(0) 701 722 /* host port */ … … 798 819 * Get the configuration settings. 799 820 */ 821 int rc; 800 822 bool fPassDomain = true; 801 int rc = CFGMR3QueryBool(pCfgHandle, "PassDomain", &fPassDomain); 802 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 803 fPassDomain = true; 804 else if (RT_FAILURE(rc)) 805 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"PassDomain\" boolean failed"), pDrvIns->iInstance); 806 807 rc = CFGMR3QueryStringAlloc(pCfgHandle, "TFTPPrefix", &pThis->pszTFTPPrefix); 808 if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND) 809 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"TFTPPrefix\" string failed"), pDrvIns->iInstance); 810 rc = CFGMR3QueryStringAlloc(pCfgHandle, "BootFile", &pThis->pszBootFile); 811 if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND) 812 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"BootFile\" string failed"), pDrvIns->iInstance); 813 rc = CFGMR3QueryStringAlloc(pCfgHandle, "NextServer", &pThis->pszNextServer); 814 if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND) 815 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"NextServer\" string failed"), pDrvIns->iInstance); 823 GET_BOOL(rc, pCfgHandle, pDrvIns->iInstance, "PassDomain", fPassDomain); 824 825 GET_STRING_ALLOC(rc, pCfgHandle, pDrvIns->iInstance, "TFTPPrefix", pThis->pszTFTPPrefix); 826 GET_STRING_ALLOC(rc, pCfgHandle, pDrvIns->iInstance, "BootFile", pThis->pszBootFile); 827 GET_STRING_ALLOC(rc, pCfgHandle, pDrvIns->iInstance, "NextServer", pThis->pszNextServer); 828 816 829 int fDNSProxy; 817 830 rc = CFGMR3QueryS32(pCfgHandle, "DNSProxy", &fDNSProxy); … … 822 835 * Query the network port interface. 823 836 */ 824 pThis->pPort = (PPDMINETWORKPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_NETWORK_PORT); 837 pThis->pPort = 838 (PPDMINETWORKPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, 839 PDMINTERFACE_NETWORK_PORT); 825 840 if (!pThis->pPort) 826 841 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, 827 N_("Configuration error: the above device/driver didn't export the network port interface")); 828 pThis->pConfig = (PPDMINETWORKCONFIG)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_NETWORK_CONFIG); 842 N_("Configuration error: the above device/driver didn't " 843 "export the network port interface")); 844 pThis->pConfig = 845 (PPDMINETWORKCONFIG)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, 846 PDMINTERFACE_NETWORK_CONFIG); 829 847 if (!pThis->pConfig) 830 848 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, 831 N_("Configuration error: the above device/driver didn't export the network config interface")); 849 N_("Configuration error: the above device/driver didn't " 850 "export the network config interface")); 832 851 833 852 /* Generate a network address for this network card. */ 834 rc = CFGMR3QueryString(pCfgHandle, "Network", szNetwork, sizeof(szNetwork));853 GET_STRING(rc, pCfgHandle, pDrvIns->iInstance, "Network", szNetwork[0], sizeof(szNetwork)); 835 854 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 836 855 RTStrPrintf(szNetwork, sizeof(szNetwork), "10.0.%d.0/24", pDrvIns->iInstance + 2); 837 else if (RT_FAILURE(rc))838 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Network\" string failed"), pDrvIns->iInstance);839 856 840 857 RTIPV4ADDR Network; … … 858 875 slirp_set_dhcp_dns_proxy(pThis->pNATState, !!fDNSProxy); 859 876 char *pszBindIP = NULL; 860 rc = CFGMR3QueryStringAlloc(pCfgHandle, "BindIP", &pszBindIP); 861 if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND) 862 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"BindIP\" string failed"), pDrvIns->iInstance); 877 GET_STRING_ALLOC(rc, pCfgHandle, pDrvIns->iInstance, "BindIP", pszBindIP); 863 878 rc = slirp_set_binding_address(pThis->pNATState, pszBindIP); 864 879 if (rc != 0)
Note:
See TracChangeset
for help on using the changeset viewer.