VirtualBox

Changeset 50046 in vbox for trunk


Ignore:
Timestamp:
Jan 10, 2014 2:06:06 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
91535
Message:

NAT/DrvNAT.cpp: introduces drvNATHostNetworkConfigurationChangeEventStrategySelector selecting strategy how to deal with Host Network change event and Host Resume. Function acting in following manner:

  • if Slirp configured as exposing host network configuration to guest, we proceed with "re-activating cable connection".
  • if Slirp configured as dns proxy, we reconfigure internal DNS state.
  • if Slirp configured to use host resolver, we should just ignore event.

currently this function called from couple places: drvNATResume and Host Network change event "listener" (darwin only). This will be changed in the future, when notification of host network change will be finished in Main, and we can drop OS dependent part in DrvNat, processing these events in the same way as port-forwarding done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r48947 r50046  
    2424#define __STDC_CONSTANT_MACROS
    2525#include "slirp/libslirp.h"
     26extern "C" {
     27#include "slirp/slirp_dns.h"
     28};
    2629#include "slirp/ctl.h"
    2730
     
    218221*******************************************************************************/
    219222static void drvNATNotifyNATThread(PDRVNAT pThis, const char *pszWho);
     223DECLINLINE(void) drvNATHostNetworkConfigurationChangeEventStrategySelector(
     224  PDRVNAT pThis,
     225  bool fHostNetworkConfigurationEventListener);
     226static DECLCALLBACK(int) drvNATReinitializeHostNameResolving(PDRVNAT pThis);
    220227
    221228
     
    972979        CFArrayRef hArrAddresses = (CFArrayRef)CFDictionaryGetValue(hDnsDict, kSCPropNetDNSServerAddresses);
    973980        if (hArrAddresses)
    974             pThis->pIAboveConfig->pfnSetLinkState(pThis->pIAboveConfig, PDMNETWORKLINKSTATE_DOWN_RESUME);
     981            drvNATHostNetworkConfigurationChangeEventStrategySelector(pThis, /* RT_OS_DARWIN */ true);
    975982
    976983        CFRelease(hDnsDict);
     
    10451052    {
    10461053        case VMRESUMEREASON_HOST_RESUME:
     1054            drvNATHostNetworkConfigurationChangeEventStrategySelector(pThis, !RT_OS_DARWIN);
     1055            return;
     1056        default: /* Ignore every other resume reason. */
     1057            /* do nothing */
     1058            return;
     1059    }
     1060}
     1061
     1062
     1063static DECLCALLBACK(int) drvNATReinitializeHostNameResolving(PDRVNAT pThis)
     1064{
     1065    slirpReleaseDnsSettings(pThis->pNATState);
     1066    slirpInitializeDnsSettings(pThis->pNATState);
     1067    return VINF_SUCCESS;
     1068}
     1069
     1070/**
     1071 * This function at this stage could be called from two places, but both from non-NAT thread,
     1072 * - drvNATResume (EMT?)
     1073 * - drvNatDnsChanged (darwin, GUI or main) "listener"
     1074 * When Main's interface IHost will support host network configuration change event on every host,
     1075 * we won't call it from drvNATResume, but from listener of Main event in the similar way it done
     1076 * for port-forwarding, and it wan't be on GUI/main thread, but on EMT thread only.
     1077 *
     1078 * Thread here is important, because we need to change DNS server list and domain name (+ perhaps,
     1079 * search string) at runtime (VBOX_NAT_ENFORCE_INTERNAL_DNS_UPDATE), we can do it safely on NAT thread,
     1080 * so with changing other variables (place where we handle update) the main mechanism of update
     1081 * _won't_ be changed, the only thing will change is drop of fHostNetworkConfigurationEventListener parameter.
     1082 */
     1083DECLINLINE(void) drvNATHostNetworkConfigurationChangeEventStrategySelector(PDRVNAT pThis,
     1084                                                                        bool fHostNetworkConfigurationEventListener)
     1085{
     1086    int strategy = slirp_host_network_configuration_change_strategy_selector(pThis->pNATState);
     1087    switch (strategy)
     1088    {
     1089                 
     1090        case VBOX_NAT_HNCE_DNSPROXY:
     1091            {
     1092                /**
     1093                 * It's unsafe to to do it directly on non-NAT thread
     1094                 * so we schedule the worker and kick the NAT thread.
     1095                 */
     1096                RTREQQUEUE hQueue = pThis->hSlirpReqQueue;
     1097               
     1098                int rc = RTReqQueueCallEx(hQueue, NULL /*ppReq*/, 0 /*cMillies*/,
     1099                                          RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     1100                                          (PFNRT)drvNATReinitializeHostNameResolving, 1, pThis);
     1101                if (RT_SUCCESS(rc))
     1102                    drvNATNotifyNATThread(pThis, "drvNATNetworkUp_SendBuf");
     1103
     1104
     1105                return;
     1106
     1107            }
     1108        case VBOX_NAT_HNCE_EXSPOSED_NAME_RESOLUTION_INFO:
    10471109            /*
    10481110             * Host resumed from a suspend and the network might have changed.
    10491111             * Disconnect the guest from the network temporarily to let it pick up the changes.
    10501112             */
    1051 #ifndef RT_OS_DARWIN
    1052             pThis->pIAboveConfig->pfnSetLinkState(pThis->pIAboveConfig,
    1053                                                   PDMNETWORKLINKSTATE_DOWN_RESUME);
    1054 #endif
     1113
     1114            if (fHostNetworkConfigurationEventListener)
     1115                pThis->pIAboveConfig->pfnSetLinkState(pThis->pIAboveConfig,
     1116                                                      PDMNETWORKLINKSTATE_DOWN_RESUME);
    10551117            return;
    1056         default: /* Ignore every other resume reason. */
    1057             /* do nothing */
     1118        case VBOX_NAT_HNCE_HOSTRESOLVER:
     1119        default:
    10581120            return;
    10591121    }
Note: See TracChangeset for help on using the changeset viewer.

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