Changeset 49494 in vbox
- Timestamp:
- Nov 15, 2013 10:32:10 AM (11 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/DHCPServerImpl.h
r48955 r49494 43 43 DHCPServerRunner():NetworkServiceRunner(DHCP_EXECUTABLE_NAME){} 44 44 virtual ~DHCPServerRunner(){}; 45 46 static const std::string kDsrKeyGateway; 47 static const std::string kDsrKeyLowerIp; 48 static const std::string kDsrKeyUpperIp; 45 49 }; 46 50 -
trunk/src/VBox/Main/include/NATNetworkImpl.h
r49129 r49494 49 49 public: 50 50 NATNetworkServiceRunner(): NetworkServiceRunner(NATSR_EXECUTABLE_NAME){} 51 virtual~NATNetworkServiceRunner(){}51 ~NATNetworkServiceRunner(){} 52 52 }; 53 53 -
trunk/src/VBox/Main/include/NetworkServiceRunner.h
r48107 r49494 22 22 #include <VBox/com/string.h> 23 23 24 typedef enum25 {26 NETCFG_NAME = 1,27 NETCFG_NETNAME,28 NETCFG_TRUNKTYPE,29 NETCFG_TRUNKNAME,30 NETCFG_MACADDRESS,31 NETCFG_IPADDRESS,32 NETCFG_NETMASK,33 NETCFG_VERBOSE,34 NETCFG_NOTOPT_MAXVAL35 } NETCFG;36 37 24 #define TRUNKTYPE_WHATEVER "whatever" 38 25 #define TRUNKTYPE_NETFLT "netflt" … … 43 30 { 44 31 public: 45 NetworkServiceRunner(const char *aProcName) 46 : mProcName(aProcName) 47 , mProcess(NIL_RTPROCESS) 48 { 49 RT_ZERO(mOptionEnabled); 50 }; 51 ~NetworkServiceRunner() 52 { 53 stop(); /* don't leave abandoned servers */ 54 } 32 NetworkServiceRunner(const char *aProcName); 33 virtual ~NetworkServiceRunner(); 55 34 56 int setOption(NETCFG opt, const char *val, bool enabled) 57 { 58 if (opt == 0 || opt >= NETCFG_NOTOPT_MAXVAL) 59 return VERR_INVALID_PARAMETER; 60 if (isRunning()) 61 return VERR_INVALID_STATE; 62 63 mOptions[opt] = val; 64 mOptionEnabled[opt] = enabled; 65 return VINF_SUCCESS; 66 } 67 68 int setOption(NETCFG opt, const com::Utf8Str &val, bool enabled) 69 { 70 return setOption(opt, val.c_str(), enabled); 71 } 35 int setOption(const std::string& key, const std::string& val); 72 36 73 37 int start(); … … 76 40 77 41 void detachFromServer(); 42 43 static const std::string kNsrKeyName; 44 static const std::string kNsrKeyNetwork; 45 static const std::string kNsrKeyTrunkType; 46 static const std::string kNsrTrunkName; 47 static const std::string kNsrMacAddress; 48 static const std::string kNsrIpAddress; 49 static const std::string kNsrIpNetmask; 50 78 51 private: 79 com::Utf8Str mOptions[NETCFG_NOTOPT_MAXVAL]; 80 bool mOptionEnabled[NETCFG_NOTOPT_MAXVAL]; 81 const char *mProcName; 82 RTPROCESS mProcess; 52 struct Data; 53 Data *m; 83 54 }; 84 -
trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
r47112 r49494 18 18 */ 19 19 20 #include <string> 20 21 #include "NetworkServiceRunner.h" 21 22 #include "DHCPServerImpl.h" … … 32 33 // constructor / destructor 33 34 ///////////////////////////////////////////////////////////////////////////// 35 const std::string DHCPServerRunner::kDsrKeyGateway = "--gateway"; 36 const std::string DHCPServerRunner::kDsrKeyLowerIp = "--lower-ip"; 37 const std::string DHCPServerRunner::kDsrKeyUpperIp = "--upper-ip"; 38 34 39 35 40 DHCPServer::DHCPServer() … … 471 476 472 477 /* Commmon Network Settings */ 473 m.dhcp.setOption(N ETCFG_NETNAME, Utf8Str(aNetworkName), true);478 m.dhcp.setOption(NetworkServiceRunner::kNsrKeyNetwork, Utf8Str(aNetworkName).c_str()); 474 479 475 480 Bstr tmp(aTrunkName); 476 481 477 482 if (!tmp.isEmpty()) 478 m.dhcp.setOption(N ETCFG_TRUNKNAME, Utf8Str(tmp), true);479 m.dhcp.setOption(N ETCFG_TRUNKTYPE, Utf8Str(aTrunkType), true);483 m.dhcp.setOption(NetworkServiceRunner::kNsrTrunkName, Utf8Str(tmp).c_str()); 484 m.dhcp.setOption(NetworkServiceRunner::kNsrKeyTrunkType, Utf8Str(aTrunkType).c_str()); 480 485 481 486 /* XXX: should this MAC default initialization moved to NetworkServiceRunner? */ … … 487 492 guid.raw()->au8[1], 488 493 guid.raw()->au8[2]); 489 m.dhcp.setOption(NETCFG_MACADDRESS, strMAC, true); 490 m.dhcp.setOption(NETCFG_IPADDRESS, Utf8Str(m.IPAddress), true); 491 m.dhcp.setOption(NETCFG_NETMASK, Utf8Str(m.GlobalDhcpOptions[DhcpOpt_SubnetMask]), true); 494 m.dhcp.setOption(NetworkServiceRunner::kNsrMacAddress, strMAC); 495 m.dhcp.setOption(NetworkServiceRunner::kNsrIpAddress, Utf8Str(m.IPAddress).c_str()); 496 m.dhcp.setOption(NetworkServiceRunner::kNsrIpNetmask, Utf8Str(m.GlobalDhcpOptions[DhcpOpt_SubnetMask]).c_str()); 497 m.dhcp.setOption(DHCPServerRunner::kDsrKeyLowerIp, Utf8Str(m.lowerIP).c_str()); 498 m.dhcp.setOption(DHCPServerRunner::kDsrKeyUpperIp, Utf8Str(m.upperIP).c_str()); 492 499 493 500 /* XXX: This parameters Dhcp Server will fetch via API */ -
trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp
r49408 r49494 16 16 */ 17 17 18 #include <string> 18 19 #include "NetworkServiceRunner.h" 19 20 #include "DHCPServerImpl.h" … … 870 871 if (!m->fEnabled) return S_OK; 871 872 872 m->NATRunner.setOption(N ETCFG_NETNAME, mName, true);873 m->NATRunner.setOption(N ETCFG_TRUNKTYPE, Utf8Str(aTrunkType), true);874 m->NATRunner.setOption(N ETCFG_IPADDRESS, m->IPv4Gateway, true);875 m->NATRunner.setOption(N ETCFG_NETMASK, m->IPv4NetworkMask, true);873 m->NATRunner.setOption(NetworkServiceRunner::kNsrKeyNetwork, Utf8Str(mName).c_str()); 874 m->NATRunner.setOption(NetworkServiceRunner::kNsrKeyTrunkType, Utf8Str(aTrunkType).c_str()); 875 m->NATRunner.setOption(NetworkServiceRunner::kNsrIpAddress, Utf8Str(m->IPv4Gateway).c_str()); 876 m->NATRunner.setOption(NetworkServiceRunner::kNsrIpNetmask, Utf8Str(m->IPv4NetworkMask).c_str()); 876 877 877 878 /* No portforwarding rules from command-line, all will be fetched via API */ -
trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp
r47447 r49494 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 #include <map> 19 #include <string> 17 20 #include "NetworkServiceRunner.h" 18 21 #include <iprt/process.h> … … 20 23 #include <iprt/env.h> 21 24 22 struct ARGDEF 25 26 const std::string NetworkServiceRunner::kNsrKeyName = "--name"; 27 const std::string NetworkServiceRunner::kNsrKeyNetwork = "--network"; 28 const std::string NetworkServiceRunner::kNsrKeyTrunkType = "--trunk-type"; 29 const std::string NetworkServiceRunner::kNsrTrunkName = "--trunk-name"; 30 const std::string NetworkServiceRunner::kNsrMacAddress = "--mac-address"; 31 const std::string NetworkServiceRunner::kNsrIpAddress = "--ip-address"; 32 const std::string NetworkServiceRunner::kNsrIpNetmask = "--netmask"; 33 34 struct NetworkServiceRunner::Data 23 35 { 24 NETCFG Type; 25 const char * Name; 36 Data(const char* aProcName):mProcName(aProcName), mProcess(NIL_RTPROCESS){} 37 const char *mProcName; 38 RTPROCESS mProcess; 39 std::map<std::string, std::string> mOptions; 26 40 }; 27 41 28 static const ARGDEF g_aArgDefs[] = 42 NetworkServiceRunner::NetworkServiceRunner(const char *aProcName) 29 43 { 30 {NETCFG_NAME, "--name"}, 31 {NETCFG_NETNAME, "--network"}, 32 {NETCFG_TRUNKTYPE, "--trunk-type"}, 33 {NETCFG_TRUNKNAME, "--trunk-name"}, 34 {NETCFG_MACADDRESS, "--mac-address"}, 35 {NETCFG_IPADDRESS, "--ip-address"}, 36 {NETCFG_VERBOSE, "--verbose"}, 37 {NETCFG_NETMASK, "--netmask"}, 38 }; 44 m = new NetworkServiceRunner::Data(aProcName); 45 46 } 39 47 40 static const ARGDEF * getArgDef(NETCFG type) 48 49 NetworkServiceRunner::~NetworkServiceRunner() 41 50 { 42 for (unsigned i = 0; i < RT_ELEMENTS(g_aArgDefs); i++) 43 if (g_aArgDefs[i].Type == type) 44 return &g_aArgDefs[i]; 51 stop(); 52 delete m; 53 m = NULL; 54 } 45 55 46 return NULL; 56 57 int NetworkServiceRunner::setOption(const std::string& key, const std::string& val) 58 { 59 m->mOptions.insert(std::map<std::string, std::string>::value_type(key, val)); 60 return VINF_SUCCESS; 47 61 } 62 48 63 49 64 void NetworkServiceRunner::detachFromServer() 50 65 { 51 m Process = NIL_RTPROCESS;66 m->mProcess = NIL_RTPROCESS; 52 67 } 68 53 69 54 70 int NetworkServiceRunner::start() … … 57 73 return VINF_ALREADY_INITIALIZED; 58 74 59 const char * args[NETCFG_NOTOPT_MAXVAL * 2]; 75 const char * args[10*2]; 76 77 AssertReturn(m->mOptions.size() < 10, VERR_INTERNAL_ERROR); 60 78 61 79 /* get the path to the executable */ … … 69 87 { 70 88 suffix++; 71 strcpy(suffix, m ProcName);89 strcpy(suffix, m->mProcName); 72 90 } 73 91 … … 76 94 args[index++] = exePath; 77 95 78 for (unsigned i = 0; i < NETCFG_NOTOPT_MAXVAL; i++) 96 std::map<std::string, std::string>::const_iterator it; 97 for(it = m->mOptions.begin(); it != m->mOptions.end(); ++it) 79 98 { 80 if (mOptionEnabled[i]) 81 { 82 const ARGDEF *pArgDef = getArgDef((NETCFG)i); 83 if (!pArgDef) 84 continue; 85 args[index++] = pArgDef->Name; 86 87 if (mOptions[i].length()) 88 args[index++] = mOptions[i].c_str(); // value 89 } 99 args[index++] = it->first.c_str(); 100 args[index++] = it->second.c_str(); 90 101 } 91 102 92 103 args[index++] = NULL; 93 104 94 int rc = RTProcCreate(suffix ? exePath : m ProcName, args, RTENV_DEFAULT, 0, &mProcess);105 int rc = RTProcCreate(suffix ? exePath : m->mProcName, args, RTENV_DEFAULT, 0, &m->mProcess); 95 106 if (RT_FAILURE(rc)) 96 m Process = NIL_RTPROCESS;107 m->mProcess = NIL_RTPROCESS; 97 108 98 109 return rc; 99 110 } 111 100 112 101 113 int NetworkServiceRunner::stop() … … 104 116 return VINF_OBJECT_DESTROYED; 105 117 106 int rc = RTProcTerminate(m Process);107 RTProcWait(m Process, RTPROCWAIT_FLAGS_BLOCK, NULL);108 m Process = NIL_RTPROCESS;118 int rc = RTProcTerminate(m->mProcess); 119 RTProcWait(m->mProcess, RTPROCWAIT_FLAGS_BLOCK, NULL); 120 m->mProcess = NIL_RTPROCESS; 109 121 return rc; 110 122 } … … 112 124 bool NetworkServiceRunner::isRunning() 113 125 { 114 if (m Process == NIL_RTPROCESS)126 if (m->mProcess == NIL_RTPROCESS) 115 127 return false; 116 128 117 129 RTPROCSTATUS status; 118 int rc = RTProcWait(m Process, RTPROCWAIT_FLAGS_NOBLOCK, &status);130 int rc = RTProcWait(m->mProcess, RTPROCWAIT_FLAGS_NOBLOCK, &status); 119 131 120 132 if (rc == VERR_PROCESS_RUNNING) 121 133 return true; 122 134 123 m Process = NIL_RTPROCESS;135 m->mProcess = NIL_RTPROCESS; 124 136 return false; 125 137 }
Note:
See TracChangeset
for help on using the changeset viewer.