Changeset 28295 in vbox for trunk/src/VBox
- Timestamp:
- Apr 14, 2010 11:51:07 AM (15 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/NetworkAdapterImpl.cpp
r28290 r28295 1161 1161 break; 1162 1162 } 1163 if (data.fHasDisabledNAT) 1164 mNATEngine->loadSettings(data.nat); 1163 1165 1164 1166 // after loading settings, we are no longer different from the XML on disk … … 1205 1207 1206 1208 case NetworkAttachmentType_NAT: 1209 data.fHasDisabledNAT = 0; 1207 1210 mNATEngine->commit(); 1208 1211 mNATEngine->saveSettings(data.nat); … … 1220 1223 data.strName = mData->mHostInterface; 1221 1224 break; 1225 } 1226 1227 if (data.mode != NetworkAttachmentType_NAT) 1228 { 1229 data.fHasDisabledNAT = 1; /* ??? */ 1230 mNATEngine->commit(); 1231 mNATEngine->saveSettings(data.nat); 1222 1232 } 1223 1233 -
trunk/src/VBox/Main/xml/Settings.cpp
r28290 r28295 1828 1828 pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority); 1829 1829 1830 const xml::ElementNode *pelmAdapterChild; 1831 if ((pelmAdapterChild = pelmAdapter->findChildElement("NAT"))) 1830 xml::ElementNodesList llNetworkModes; 1831 pelmAdapter->getChildElements(llNetworkModes); 1832 xml::ElementNodesList::iterator it; 1833 /* We should have only active mode descriptor and disabled modes set */ 1834 if (llNetworkModes.size() > 2) 1835 { 1836 throw ConfigFileError(this, pelmAdapter, N_("Invalid number of modes '%d' attached to Adapter attribute"), llNetworkModes.size()); 1837 } 1838 for (it = llNetworkModes.begin(); it != llNetworkModes.end(); ++it) 1839 { 1840 const xml::ElementNode *pelmNode = *it; 1841 if (pelmNode->nameEquals("DisabledModes")) 1842 { 1843 xml::ElementNodesList llDisabledNetworkModes; 1844 xml::ElementNodesList::iterator itDisabled; 1845 pelmNode->getChildElements(llDisabledNetworkModes); 1846 /* run over disabled list and load settings */ 1847 for(itDisabled = llDisabledNetworkModes.begin(); itDisabled != llDisabledNetworkModes.end(); ++itDisabled) 1848 { 1849 const xml::ElementNode *pelmDisabledNode = *itDisabled; 1850 readAttachedNetworkMode(*pelmDisabledNode, false, nic); 1851 } 1852 } 1853 else 1854 readAttachedNetworkMode(*pelmNode, true, nic); 1855 } 1856 // else: default is NetworkAttachmentType_Null 1857 1858 ll.push_back(nic); 1859 } 1860 } 1861 1862 void MachineConfigFile::readAttachedNetworkMode(const xml::ElementNode &elmMode, bool fEnabled, NetworkAdapter &nic) 1863 { 1864 if (elmMode.nameEquals("NAT")) 1865 { 1866 if (fEnabled) 1832 1867 { 1833 1868 nic.mode = NetworkAttachmentType_NAT; 1834 pelmAdapterChild->getAttributeValue("network", nic.nat.strNetwork); // optional network name 1835 pelmAdapterChild->getAttributeValue("hostip", nic.nat.strBindIP); 1836 pelmAdapterChild->getAttributeValue("mtu", nic.nat.u32Mtu); 1837 pelmAdapterChild->getAttributeValue("sockrcv", nic.nat.u32SockRcv); 1838 pelmAdapterChild->getAttributeValue("socksnd", nic.nat.u32SockSnd); 1839 pelmAdapterChild->getAttributeValue("tcprcv", nic.nat.u32TcpRcv); 1840 pelmAdapterChild->getAttributeValue("tcpsnd", nic.nat.u32TcpSnd); 1841 const xml::ElementNode *pelmDNS; 1842 if ((pelmDNS = pelmAdapterChild->findChildElement("DNS"))) 1843 { 1844 pelmDNS->getAttributeValue("pass-domain", nic.nat.fDnsPassDomain); 1845 pelmDNS->getAttributeValue("use-proxy", nic.nat.fDnsProxy); 1846 pelmDNS->getAttributeValue("use-host-resolver", nic.nat.fDnsUseHostResolver); 1847 } 1848 const xml::ElementNode *pelmTFTP; 1849 if ((pelmTFTP = pelmAdapterChild->findChildElement("TFTP"))) 1850 { 1851 pelmTFTP->getAttributeValue("prefix", nic.nat.strTftpPrefix); 1852 pelmTFTP->getAttributeValue("boot-file", nic.nat.strTftpBootFile); 1853 pelmTFTP->getAttributeValue("next-server", nic.nat.strTftpNextServer); 1854 } 1855 xml::ElementNodesList plstNatPF; 1856 pelmAdapterChild->getChildElements(plstNatPF, "Forwarding"); 1857 for(xml::ElementNodesList::iterator pf = plstNatPF.begin(); pf != plstNatPF.end(); ++pf) 1858 { 1859 NATRule rule; 1860 uint32_t port = 0; 1861 (*pf)->getAttributeValue("name", rule.strName); 1862 (*pf)->getAttributeValue("proto", rule.u32Proto); 1863 (*pf)->getAttributeValue("hostip", rule.strHostIP); 1864 (*pf)->getAttributeValue("hostport", port); 1865 rule.u16HostPort = port; 1866 (*pf)->getAttributeValue("guestip", rule.strGuestIP); 1867 (*pf)->getAttributeValue("guestport", port); 1868 rule.u16GuestPort = port; 1869 nic.nat.llRules.push_back(rule); 1870 } 1871 } 1872 else if ( ((pelmAdapterChild = pelmAdapter->findChildElement("HostInterface"))) 1873 || ((pelmAdapterChild = pelmAdapter->findChildElement("BridgedInterface"))) 1874 ) 1875 { 1876 nic.mode = NetworkAttachmentType_Bridged; 1877 pelmAdapterChild->getAttributeValue("name", nic.strName); // optional host interface name 1878 } 1879 else if ((pelmAdapterChild = pelmAdapter->findChildElement("InternalNetwork"))) 1880 { 1881 nic.mode = NetworkAttachmentType_Internal; 1882 if (!pelmAdapterChild->getAttributeValue("name", nic.strName)) // required network name 1883 throw ConfigFileError(this, pelmAdapterChild, N_("Required InternalNetwork/@name element is missing")); 1884 } 1885 else if ((pelmAdapterChild = pelmAdapter->findChildElement("HostOnlyInterface"))) 1886 { 1887 nic.mode = NetworkAttachmentType_HostOnly; 1888 if (!pelmAdapterChild->getAttributeValue("name", nic.strName)) // required network name 1889 throw ConfigFileError(this, pelmAdapterChild, N_("Required HostOnlyInterface/@name element is missing")); 1890 } 1891 // else: default is NetworkAttachmentType_Null 1892 1893 ll.push_back(nic); 1869 } 1870 nic.fHasDisabledNAT = (nic.mode != NetworkAttachmentType_NAT) && !fEnabled; 1871 elmMode.getAttributeValue("network", nic.nat.strNetwork); // optional network name 1872 elmMode.getAttributeValue("hostip", nic.nat.strBindIP); 1873 elmMode.getAttributeValue("mtu", nic.nat.u32Mtu); 1874 elmMode.getAttributeValue("sockrcv", nic.nat.u32SockRcv); 1875 elmMode.getAttributeValue("socksnd", nic.nat.u32SockSnd); 1876 elmMode.getAttributeValue("tcprcv", nic.nat.u32TcpRcv); 1877 elmMode.getAttributeValue("tcpsnd", nic.nat.u32TcpSnd); 1878 const xml::ElementNode *pelmDNS; 1879 if ((pelmDNS = elmMode.findChildElement("DNS"))) 1880 { 1881 pelmDNS->getAttributeValue("pass-domain", nic.nat.fDnsPassDomain); 1882 pelmDNS->getAttributeValue("use-proxy", nic.nat.fDnsProxy); 1883 pelmDNS->getAttributeValue("use-host-resolver", nic.nat.fDnsUseHostResolver); 1884 } 1885 const xml::ElementNode *pelmTFTP; 1886 if ((pelmTFTP = elmMode.findChildElement("TFTP"))) 1887 { 1888 pelmTFTP->getAttributeValue("prefix", nic.nat.strTftpPrefix); 1889 pelmTFTP->getAttributeValue("boot-file", nic.nat.strTftpBootFile); 1890 pelmTFTP->getAttributeValue("next-server", nic.nat.strTftpNextServer); 1891 } 1892 xml::ElementNodesList plstNatPF; 1893 elmMode.getChildElements(plstNatPF, "Forwarding"); 1894 for(xml::ElementNodesList::iterator pf = plstNatPF.begin(); pf != plstNatPF.end(); ++pf) 1895 { 1896 NATRule rule; 1897 uint32_t port = 0; 1898 (*pf)->getAttributeValue("name", rule.strName); 1899 (*pf)->getAttributeValue("proto", rule.u32Proto); 1900 (*pf)->getAttributeValue("hostip", rule.strHostIP); 1901 (*pf)->getAttributeValue("hostport", port); 1902 rule.u16HostPort = port; 1903 (*pf)->getAttributeValue("guestip", rule.strGuestIP); 1904 (*pf)->getAttributeValue("guestport", port); 1905 rule.u16GuestPort = port; 1906 nic.nat.llRules.push_back(rule); 1907 } 1908 } 1909 else if ( fEnabled 1910 && ( (elmMode.nameEquals("HostInterface")) 1911 || (elmMode.nameEquals("BridgedInterface"))) 1912 ) 1913 { 1914 nic.mode = NetworkAttachmentType_Bridged; 1915 elmMode.getAttributeValue("name", nic.strName); // optional host interface name 1916 } 1917 else if ( fEnabled 1918 && elmMode.findChildElement("InternalNetwork")) 1919 { 1920 nic.mode = NetworkAttachmentType_Internal; 1921 if (!elmMode.getAttributeValue("name", nic.strName)) // required network name 1922 throw ConfigFileError(this, &elmMode, N_("Required InternalNetwork/@name element is missing")); 1923 } 1924 else if ( fEnabled 1925 && elmMode.nameEquals("HostOnlyInterface")) 1926 { 1927 nic.mode = NetworkAttachmentType_HostOnly; 1928 if (!elmMode.getAttributeValue("name", nic.strName)) // required network name 1929 throw ConfigFileError(this, &elmMode, N_("Required HostOnlyInterface/@name element is missing")); 1894 1930 } 1895 1931 } … … 3318 3354 3319 3355 xml::ElementNode *pelmNAT; 3320 switch (nic.mode) 3321 { 3322 case NetworkAttachmentType_NAT: 3323 pelmNAT = pelmAdapter->createChild("NAT"); 3324 if (nic.nat.strNetwork.length()) 3325 pelmNAT->setAttribute("network", nic.nat.strNetwork); 3326 if (m->sv >= SettingsVersion_v1_10) 3327 { 3328 if (nic.nat.strBindIP.length()) 3329 pelmNAT->setAttribute("hostip", nic.nat.strBindIP); 3330 if (nic.nat.u32Mtu) 3331 pelmNAT->setAttribute("mtu", nic.nat.u32Mtu); 3332 if (nic.nat.u32SockRcv) 3333 pelmNAT->setAttribute("sockrcv", nic.nat.u32SockRcv); 3334 if (nic.nat.u32SockSnd) 3335 pelmNAT->setAttribute("socksnd", nic.nat.u32SockSnd); 3336 if (nic.nat.u32TcpRcv) 3337 pelmNAT->setAttribute("tcprcv", nic.nat.u32TcpRcv); 3338 if (nic.nat.u32TcpSnd) 3339 pelmNAT->setAttribute("tcpsnd", nic.nat.u32TcpSnd); 3340 xml::ElementNode *pelmDNS; 3341 pelmDNS = pelmNAT->createChild("DNS"); 3342 pelmDNS->setAttribute("pass-domain", nic.nat.fDnsPassDomain); 3343 pelmDNS->setAttribute("use-proxy", nic.nat.fDnsProxy); 3344 pelmDNS->setAttribute("use-host-resolver", nic.nat.fDnsUseHostResolver); 3345 if ( nic.nat.strTftpPrefix.length() 3346 || nic.nat.strTftpBootFile.length() 3347 || nic.nat.strTftpNextServer.length()) 3348 { 3349 xml::ElementNode *pelmTFTP; 3350 pelmTFTP = pelmNAT->createChild("TFTP"); 3351 if (nic.nat.strTftpPrefix.length()) 3352 pelmTFTP->setAttribute("prefix", nic.nat.strTftpPrefix); 3353 if (nic.nat.strTftpBootFile.length()) 3354 pelmTFTP->setAttribute("boot-file", nic.nat.strTftpBootFile); 3355 if (nic.nat.strTftpNextServer.length()) 3356 pelmTFTP->setAttribute("next-server", nic.nat.strTftpNextServer); 3357 } 3358 for(NATRuleList::const_iterator rule = nic.nat.llRules.begin(); 3359 rule != nic.nat.llRules.end(); ++rule) 3360 { 3361 xml::ElementNode *pelmPF; 3362 pelmPF = pelmNAT->createChild("Forwarding"); 3363 if ((*rule).strName.length()) 3364 pelmPF->setAttribute("name", (*rule).strName); 3365 pelmPF->setAttribute("proto", (*rule).u32Proto); 3366 if ((*rule).strHostIP.length()) 3367 pelmPF->setAttribute("hostip", (*rule).strHostIP); 3368 if ((*rule).u16HostPort) 3369 pelmPF->setAttribute("hostport", (*rule).u16HostPort); 3370 if ((*rule).strGuestIP.length()) 3371 pelmPF->setAttribute("guestip", (*rule).strGuestIP); 3372 if ((*rule).u16GuestPort) 3373 pelmPF->setAttribute("guestport", (*rule).u16GuestPort); 3374 } 3375 } 3376 break; 3377 3378 case NetworkAttachmentType_Bridged: 3379 pelmAdapter->createChild("BridgedInterface")->setAttribute("name", nic.strName); 3380 break; 3381 3382 case NetworkAttachmentType_Internal: 3383 pelmAdapter->createChild("InternalNetwork")->setAttribute("name", nic.strName); 3384 break; 3385 3386 case NetworkAttachmentType_HostOnly: 3387 pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strName); 3388 break; 3389 3390 default: /*case NetworkAttachmentType_Null:*/ 3391 break; 3356 if (m->sv < SettingsVersion_v1_10) 3357 { 3358 switch (nic.mode) 3359 { 3360 case NetworkAttachmentType_NAT: 3361 pelmNAT = pelmAdapter->createChild("NAT"); 3362 if (nic.nat.strNetwork.length()) 3363 pelmNAT->setAttribute("network", nic.nat.strNetwork); 3364 break; 3365 3366 case NetworkAttachmentType_Bridged: 3367 pelmAdapter->createChild("BridgedInterface")->setAttribute("name", nic.strName); 3368 break; 3369 3370 case NetworkAttachmentType_Internal: 3371 pelmAdapter->createChild("InternalNetwork")->setAttribute("name", nic.strName); 3372 break; 3373 3374 case NetworkAttachmentType_HostOnly: 3375 pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strName); 3376 break; 3377 3378 default: /*case NetworkAttachmentType_Null:*/ 3379 break; 3380 } 3381 } 3382 else 3383 { 3384 /* m->sv >= SettingsVersion_v1_10 */ 3385 xml::ElementNode *pelmDisabledNode; 3386 if (nic.fHasDisabledNAT) 3387 pelmDisabledNode = pelmAdapter->createChild("DisabledModes"); 3388 if (nic.fHasDisabledNAT) 3389 buildNetworkXML(NetworkAttachmentType_NAT, *pelmDisabledNode, nic); 3390 buildNetworkXML(nic.mode, *pelmAdapter, nic); 3392 3391 } 3393 3392 } … … 3545 3544 if (hw.strNotificationPatterns.length()) 3546 3545 pelmGuestProps->setAttribute("notificationPatterns", hw.strNotificationPatterns); 3546 } 3547 3548 void MachineConfigFile::buildNetworkXML(NetworkAttachmentType_T mode, xml::ElementNode &elmParent, const NetworkAdapter &nic) 3549 { 3550 switch (mode) 3551 { 3552 case NetworkAttachmentType_NAT: 3553 xml::ElementNode *pelmNAT; 3554 pelmNAT = elmParent.createChild("NAT"); 3555 3556 if (nic.nat.strBindIP.length()) 3557 pelmNAT->setAttribute("hostip", nic.nat.strBindIP); 3558 if (nic.nat.u32Mtu) 3559 pelmNAT->setAttribute("mtu", nic.nat.u32Mtu); 3560 if (nic.nat.u32SockRcv) 3561 pelmNAT->setAttribute("sockrcv", nic.nat.u32SockRcv); 3562 if (nic.nat.u32SockSnd) 3563 pelmNAT->setAttribute("socksnd", nic.nat.u32SockSnd); 3564 if (nic.nat.u32TcpRcv) 3565 pelmNAT->setAttribute("tcprcv", nic.nat.u32TcpRcv); 3566 if (nic.nat.u32TcpSnd) 3567 pelmNAT->setAttribute("tcpsnd", nic.nat.u32TcpSnd); 3568 xml::ElementNode *pelmDNS; 3569 pelmDNS = pelmNAT->createChild("DNS"); 3570 pelmDNS->setAttribute("pass-domain", nic.nat.fDnsPassDomain); 3571 pelmDNS->setAttribute("use-proxy", nic.nat.fDnsProxy); 3572 pelmDNS->setAttribute("use-host-resolver", nic.nat.fDnsUseHostResolver); 3573 if ( nic.nat.strTftpPrefix.length() 3574 || nic.nat.strTftpBootFile.length() 3575 || nic.nat.strTftpNextServer.length()) 3576 { 3577 xml::ElementNode *pelmTFTP; 3578 pelmTFTP = pelmNAT->createChild("TFTP"); 3579 if (nic.nat.strTftpPrefix.length()) 3580 pelmTFTP->setAttribute("prefix", nic.nat.strTftpPrefix); 3581 if (nic.nat.strTftpBootFile.length()) 3582 pelmTFTP->setAttribute("boot-file", nic.nat.strTftpBootFile); 3583 if (nic.nat.strTftpNextServer.length()) 3584 pelmTFTP->setAttribute("next-server", nic.nat.strTftpNextServer); 3585 } 3586 for(NATRuleList::const_iterator rule = nic.nat.llRules.begin(); 3587 rule != nic.nat.llRules.end(); ++rule) 3588 { 3589 xml::ElementNode *pelmPF; 3590 pelmPF = pelmNAT->createChild("Forwarding"); 3591 if ((*rule).strName.length()) 3592 pelmPF->setAttribute("name", (*rule).strName); 3593 pelmPF->setAttribute("proto", (*rule).u32Proto); 3594 if ((*rule).strHostIP.length()) 3595 pelmPF->setAttribute("hostip", (*rule).strHostIP); 3596 if ((*rule).u16HostPort) 3597 pelmPF->setAttribute("hostport", (*rule).u16HostPort); 3598 if ((*rule).strGuestIP.length()) 3599 pelmPF->setAttribute("guestip", (*rule).strGuestIP); 3600 if ((*rule).u16GuestPort) 3601 pelmPF->setAttribute("guestport", (*rule).u16GuestPort); 3602 } 3603 break; 3604 3605 case NetworkAttachmentType_Bridged: 3606 elmParent.createChild("BridgedInterface")->setAttribute("name", nic.strName); 3607 break; 3608 3609 case NetworkAttachmentType_Internal: 3610 elmParent.createChild("InternalNetwork")->setAttribute("name", nic.strName); 3611 break; 3612 3613 case NetworkAttachmentType_HostOnly: 3614 elmParent.createChild("HostOnlyInterface")->setAttribute("name", nic.strName); 3615 break; 3616 3617 default: /*case NetworkAttachmentType_Null:*/ 3618 break; 3619 } 3547 3620 } 3548 3621
Note:
See TracChangeset
for help on using the changeset viewer.