VirtualBox

Changeset 28830 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Apr 27, 2010 2:05:25 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60746
Message:

IntNet,VBoxNetFlt: Cleaned up the locking protocol between IntNet and NetFlt. Eleminated the out-bound trunk lock that IntNet always took when calling NetFlt.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/intnet.h

    r28800 r28830  
    402402     *                      set!
    403403     *
    404      * @remarks Will only grab the switch table spinlock (interrupt safe).
     404     * @remarks Will only grab the switch table spinlock (interrupt safe).  May
     405     *          signal an event semaphore iff we're racing network cleanup.  The
     406     *          caller must be busy when calling.
    405407     */
    406408    DECLR0CALLBACKMEMBER(INTNETSWDECISION, pfnPreRecv,(PINTNETTRUNKSWPORT pSwitchPort,
     
    411413     *
    412414     * The frame may be modified when the trunk port on the switch is set to share
    413      * the mac address of the host when hitting the wire. Currently rames containing
    414      * ARP packets are subject to this, later other protocols like NDP/ICMPv6 may
    415      * need editing as well when operating in this mode.
     415     * the mac address of the host when hitting the wire.  Currently frames
     416     * containing ARP packets are subject to this, later other protocols like
     417     * NDP/ICMPv6 may need editing as well when operating in this mode.  The edited
     418     * packet should be forwarded to the host/wire when @c false is returned.
    416419     *
    417420     * @returns true if we've handled it and it should be dropped.
     
    419422     *
    420423     * @param   pSwitchPort Pointer to this structure.
    421      * @param   pSG         The (scatter /) gather structure for the frame.
    422      *                      This will only be use during the call, so a temporary one can
    423      *                      be used. The Phys member will not be used.
    424      * @param   fSrc        Where this frame comes from. Only one bit should be set!
    425      *
    426      * @remarks Will grab the network semaphore.
     424     * @param   pSG         The (scatter /) gather structure for the frame.  This
     425     *                      will only be use during the call, so a temporary one can
     426     *                      be used.  The Phys member will not be used.
     427     * @param   fSrc        Where this frame comes from.  Exactly one bit shall be
     428     *                      set!
     429     *
     430     * @remarks Will only grab the switch table spinlock (interrupt safe).  Will
     431     *          signal event semaphores.  The caller must be busy when calling.
    427432     *
    428433     * @remarks NAT and TAP will use this interface.
    429434     *
    430      * @todo    Do any of the host require notification before frame modifications? If so,
    431      *          we'll add a callback to INTNETTRUNKIFPORT for this (pfnSGModifying) and
    432      *          a SG flag.
     435     * @todo    Do any of the host require notification before frame modifications?
     436     *          If so, we'll add a callback to INTNETTRUNKIFPORT for this
     437     *          (pfnSGModifying) and a SG flag.
    433438     */
    434439    DECLR0CALLBACKMEMBER(bool, pfnRecv,(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG, uint32_t fSrc));
     
    440445     * @param   pSG         Pointer to the (scatter /) gather structure.
    441446     *
    442      * @remarks Will not grab any locks.
     447     * @remarks Will not grab any locks.  The caller must be busy when calling.
    443448     */
    444449    DECLR0CALLBACKMEMBER(void, pfnSGRetain,(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG));
     
    447452     * Release a SG.
    448453     *
    449      * This is called by the pfnXmit code when done with a SG. This may safe
     454     * This is called by the pfnXmit code when done with a SG.  This may safe
    450455     * be done in an asynchronous manner.
    451456     *
     
    453458     * @param   pSG         Pointer to the (scatter /) gather structure.
    454459     *
    455      * @remarks Will grab the network semaphore.
     460     * @remarks May signal an event semaphore later on, currently code won't though.
     461     *          The caller is busy when making this call.
    456462     */
    457463    DECLR0CALLBACKMEMBER(void, pfnSGRelease,(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG));
     
    462468     * By enabling physical addresses in the scatter / gather segments it should
    463469     * be possible to save some unnecessary address translation and memory locking
    464      * in the network stack. (Internal networking knows the physical address for
    465      * all the INTNETBUF data and that it's locked memory.) There is a negative
     470     * in the network stack.  (Internal networking knows the physical address for
     471     * all the INTNETBUF data and that it's locked memory.)  There is a negative
    466472     * side effects though, frames that crosses page boundraries will require
    467473     * multiple scather / gather segments.
     
    472478     * @param   fEnable     Whether to enable or disable it.
    473479     *
    474      * @remarks Will grab the network semaphore.
     480     * @remarks Will not grab any locks.  The caller must be busy when calling.
    475481     */
    476482    DECLR0CALLBACKMEMBER(bool, pfnSetSGPhys,(PINTNETTRUNKSWPORT pSwitchPort, bool fEnable));
     
    485491     * @param   pMacAddr            The MAC address.
    486492     *
    487      * @remarks May take a spinlock or two.
     493     * @remarks May take a spinlock or two.  The caller must be busy when calling.
    488494     */
    489495    DECLR0CALLBACKMEMBER(void, pfnReportMacAddress,(PINTNETTRUNKSWPORT pSwitchPort, PCRTMAC pMacAddr));
     
    499505     *                              promiscuous mode, false if not.
    500506     *
    501      * @remarks May take a spinlock or two.
     507     * @remarks May take a spinlock or two.  The caller must be busy when calling.
    502508     */
    503509    DECLR0CALLBACKMEMBER(void, pfnReportPromiscuousMode,(PINTNETTRUNKSWPORT pSwitchPort, bool fPromiscuous));
     
    515521     * @param   fDst                The destination mask (INTNETTRUNKDIR_XXX).
    516522     *
    517      * @remarks Does not take any locks.
     523     * @remarks Does not take any locks.  The caller must be busy when calling.
    518524     */
    519525    DECLR0CALLBACKMEMBER(void, pfnReportGsoCapabilities,(PINTNETTRUNKSWPORT pSwitchPort, uint32_t fGsoCapabilities, uint32_t fDst));
     
    531537     * @param   fDst                The destination mask (INTNETTRUNKDIR_XXX).
    532538     *
    533      * @remarks Does not take any locks.
     539     * @remarks Does not take any locks.  The caller must be busy when calling.
    534540     */
    535541    DECLR0CALLBACKMEMBER(void, pfnReportNoPreemptDsts,(PINTNETTRUNKSWPORT pSwitchPort, uint32_t fNoPreemptDsts));
     
    543549
    544550
     551/**
     552 * The trunk interface state used set by INTNETTRUNKIFPORT::pfnSetState.
     553 */
     554typedef enum INTNETTRUNKIFSTATE
     555{
     556    /** The invalid zero entry. */
     557    INTNETTRUNKIFSTATE_INVALID = 0,
     558    /** The trunk is inactive.  No calls to INTNETTRUNKSWPORT::pfnRecv or
     559     *  INTNETTRUNKSWPORT::pfnPreRecv.  Calling other methods is OK. */
     560    INTNETTRUNKIFSTATE_INACTIVE,
     561    /** The trunk is active, no restrictions on methods or anything. */
     562    INTNETTRUNKIFSTATE_ACTIVE,
     563    /** The trunk is about to be disconnected from the internal network.  No
     564     *  calls to any INTNETRUNKSWPORT methods. */
     565    INTNETTRUNKIFSTATE_DISCONNECTING,
     566    /** The end of the valid states. */
     567    INTNETTRUNKIFSTATE_END,
     568    /** The usual 32-bit type blow up hack. */
     569    INTNETTRUNKIFSTATE_32BIT_HACK = 0x7fffffff
     570} INTNETTRUNKIFSTATE;
     571
    545572/** Pointer to the interface side of a trunk port. */
    546573typedef struct INTNETTRUNKIFPORT *PINTNETTRUNKIFPORT;
    547574/**
    548  * This is the port on the trunk interface, i.e. the driver
    549  * side which the internal network is connected to.
     575 * This is the port on the trunk interface, i.e. the driver side which the
     576 * internal network is connected to.
    550577 *
    551578 * This is only used for the in-kernel trunk connections.
    552  *
    553  * @remarks The internal network side is responsible for serializing all calls
    554  *          to this interface. This is (assumed) to be implemented using a lock
    555  *          that is only ever taken before a call to this interface. The lock
    556  *          is referred to as the out-bound trunk port lock.
    557579 */
    558580typedef struct INTNETTRUNKIFPORT
     
    568590     * @param   pIfPort     Pointer to this structure.
    569591     *
    570      * @remarks The caller may own any locks or none at all, we don't care.
     592     * @remarks May own the big mutex, no spinlocks.
    571593     */
    572594    DECLR0CALLBACKMEMBER(void, pfnRetain,(PINTNETTRUNKIFPORT pIfPort));
     
    580602     * @param   pIfPort     Pointer to this structure.
    581603     *
    582      * @remarks Only the out-bound trunk port lock, unless the caller is certain the
    583      *          call is not going to cause destruction (wont happen).
     604     * @remarks May own the big mutex, no spinlocks.
    584605     */
    585606    DECLR0CALLBACKMEMBER(void, pfnRelease,(PINTNETTRUNKIFPORT pIfPort));
     
    593614     * @param   pIfPort     Pointer to this structure.
    594615     *
    595      * @remarks Called holding the out-bound trunk port lock.
     616     * @remarks Owns the big mutex.
    596617     */
    597618    DECLR0CALLBACKMEMBER(void, pfnDisconnectAndRelease,(PINTNETTRUNKIFPORT pIfPort));
    598619
    599620    /**
    600      * Changes the active state of the interface.
    601      *
    602      * The interface is created in the suspended (non-active) state and then activated
    603      * when the VM/network is started. It may be suspended and re-activated later
    604      * for various reasons. It will finally be suspended again before disconnecting
    605      * the interface from the internal network, however, this might be done immediately
    606      * before disconnecting and may leave an incoming frame waiting on the internal network
    607      * semaphore. So, after the final suspend a pfnWaitForIdle is always called to make sure
    608      * the interface is idle before pfnDisconnectAndRelease is called.
     621     * Changes the state of the trunk interface.
     622     *
     623     * The interface is created in the inactive state (INTNETTRUNKIFSTATE_INACTIVE).
     624     * When the first connect VM or service is activated, the internal network
     625     * activates the trunk (INTNETTRUNKIFSTATE_ACTIVE).  The state may then be set
     626     * back and forth between INACTIVE and ACTIVE as VMs are paused, added and
     627     * removed.
     628     *
     629     * Eventually though, the network is destroyed as a result of there being no
     630     * more VMs left in it and the state is changed to disconnecting
     631     * (INTNETTRUNKIFSTATE_DISCONNECTING) and pfnWaitForIdle is called to make sure
     632     * there are no active calls in either direction when pfnDisconnectAndRelease is
     633     * called.
    609634     *
    610635     * A typical operation to performed by this method is to enable/disable promiscuous
    611      * mode on the host network interface. (This is the reason we cannot call this when
    612      * owning any semaphores.)
     636     * mode on the host network interface when entering/leaving the active state.
    613637     *
    614638     * @returns The previous state.
    615639     *
    616640     * @param   pIfPort     Pointer to this structure.
    617      * @param   fActive     True if the new state is 'active', false if the new state is 'suspended'.
    618      *
    619      * @remarks Called holding the out-bound trunk port lock.
    620      */
    621     DECLR0CALLBACKMEMBER(bool, pfnSetActive,(PINTNETTRUNKIFPORT pIfPort, bool fActive));
     641     * @param   enmState    The new state.
     642     *
     643     * @remarks Owns the big mutex.  No racing pfnSetState, pfnWaitForIdle,
     644     *          pfnDisconnectAndRelease or INTNETTRUNKFACTORY::pfnCreateAndConnect
     645     *          calls.
     646     */
     647    DECLR0CALLBACKMEMBER(INTNETTRUNKIFSTATE, pfnSetState,(PINTNETTRUNKIFPORT pIfPort, INTNETTRUNKIFSTATE enmState));
    622648
    623649    /**
    624650     * Waits for the interface to become idle.
    625651     *
    626      * This method must be called before disconnecting and releasing the
    627      * object in order to prevent racing incoming/outgoing frames and device
     652     * This method must be called before disconnecting and releasing the object in
     653     * order to prevent racing incoming/outgoing frames and device
    628654     * enabling/disabling.
    629655     *
     
    634660     *                      an indefinite wait.
    635661     *
    636      * @remarks Called holding the out-bound trunk port lock.
     662     * @remarks Owns the big mutex.  No racing pfnDisconnectAndRelease.
    637663     */
    638664    DECLR0CALLBACKMEMBER(int, pfnWaitForIdle,(PINTNETTRUNKIFPORT pIfPort, uint32_t cMillies));
    639 
    640     /**
    641      * Gets the MAC address of the host network interface that we're attached to.
    642      *
    643      * @param   pIfPort     Pointer to this structure.
    644      * @param   pMac        Where to store the host MAC address.
    645      *
    646      * @remarks Called while owning the network and the out-bound trunk port semaphores.
    647      */
    648     DECLR0CALLBACKMEMBER(void, pfnGetMacAddress,(PINTNETTRUNKIFPORT pIfPort, PRTMAC pMac));
    649 
    650     /**
    651      * Tests whether the host is operating the interface is promiscuous mode.
    652      *
    653      * The default behavior of the internal networking 'switch' is to 'autodetect'
    654      * promiscuous mode on the trunk port, which is when this method is used.
    655      * For security reasons this default may of course be overridden so that the
    656      * host cannot sniff at what's going on.
    657      *
    658      * Note that this differs from operating the trunk port on the switch in
    659      * 'promiscuous' mode, because that relates to the bits going to the wire.
    660      *
    661      * @returns true / false.
    662      *
    663      * @param   pIfPort     Pointer to this structure.
    664      *
    665      * @remarks Usuaully called while owning the network and the out-bound trunk
    666      *          port semaphores.
    667      */
    668     DECLR0CALLBACKMEMBER(bool, pfnIsPromiscuous,(PINTNETTRUNKIFPORT pIfPort));
    669665
    670666    /**
     
    679675     * @param   fDst        The destination mask. At least one bit will be set.
    680676     *
    681      * @remarks Called holding the out-bound trunk port lock.
    682      *
    683      * @remarks TAP and NAT will use this interface for all their traffic, see pfnIsHostMac.
    684      *
    685      * @todo
     677     * @remarks No locks.  May be called concurrently on several threads.
    686678     */
    687679    DECLR0CALLBACKMEMBER(int, pfnXmit,(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG, uint32_t fDst));
     
    743735
    744736/** The UUID for the (current) trunk factory. (case sensitive) */
    745 #define INTNETTRUNKFACTORY_UUID_STR     "5d347cb7-98e3-411f-916a-67c4becae09b"
     737#define INTNETTRUNKFACTORY_UUID_STR     "1849823d-33ed-4f23-a32f-ef7203ee2b9f"
    746738
    747739/** @name INTNETTRUNKFACTORY::pfnCreateAndConnect flags.
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