Changeset 12783 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt
- Timestamp:
- Sep 29, 2008 9:31:21 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 37128
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c
r12770 r12783 320 320 } vboxnetflt_promisc_stream_t; 321 321 322 /**323 * vboxnetflt_state_t: per-driver data324 */325 typedef struct vboxnetflt_state_t326 {327 /** The list of all opened streams. */328 vboxnetflt_stream_t *pOpenedStreams;329 /**330 * pCurInstance is the currently VBox instance to be associated with the stream being created331 * in ModOpen. This is just shared global data between the dynamic attach and the ModOpen procedure.332 */333 PVBOXNETFLTINS pCurInstance;334 /** Goes along with pCurInstance to determine type of stream being opened/created. */335 VBOXNETFLTSTREAMTYPE CurType;336 } vboxnetflt_state_t;337 338 322 339 323 /******************************************************************************* … … 366 350 * Global Variables * 367 351 *******************************************************************************/ 352 /** Global device info handle. */ 353 static dev_info_t *g_pVBoxNetFltSolarisDip = NULL; 354 368 355 /** The (common) global data. */ 369 356 static VBOXNETFLTGLOBALS g_VBoxNetFltSolarisGlobals; 370 /** Global state. */ 371 static vboxnetflt_state_t g_VBoxNetFltSolarisState; 357 372 358 /** Mutex protecting dynamic binding of the filter. */ 373 359 RTSEMFASTMUTEX g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX; 374 /** Global device info handle. */ 375 static dev_info_t *g_pVBoxNetFltSolarisDip = NULL; 376 360 361 /** The list of all opened streams. */ 362 vboxnetflt_stream_t *g_VBoxNetFltSolarisStreams; 363 364 /** 365 * g_VBoxNetFltInstance is the current PVBOXNETFLTINS to be associated with the stream being created 366 * in ModOpen. This is just shared global data between the dynamic attach and the ModOpen procedure. 367 */ 368 PVBOXNETFLTINS volatile g_VBoxNetFltSolarisInstance; 369 370 /** Goes along with the instance to determine type of stream being opened/created. */ 371 VBOXNETFLTSTREAMTYPE volatile g_VBoxNetFltSolarisStreamType; 377 372 378 373 /** GCC C++ hack. */ … … 405 400 * Initialize Solaris specific globals here. 406 401 */ 407 g_VBoxNetFltSolarisSt ate.pOpenedStreams = NULL;408 g_VBoxNetFltSolaris State.pCurInstance = NULL;402 g_VBoxNetFltSolarisStreams = NULL; 403 g_VBoxNetFltSolarisInstance = NULL; 409 404 rc = RTSemFastMutexCreate(&g_VBoxNetFltSolarisMtx); 410 405 if (RT_SUCCESS(rc)) … … 619 614 * Check for the VirtualBox instance. 620 615 */ 621 vboxnetflt_state_t *pState = &g_VBoxNetFltSolarisState; 622 if (RT_UNLIKELY(!pState->pCurInstance)) 616 if (RT_UNLIKELY(!g_VBoxNetFltSolarisInstance)) 623 617 { 624 618 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed to get VirtualBox instance.\n")); … … 627 621 628 622 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 629 PVBOXNETFLTINS pThis = pState->pCurInstance;623 PVBOXNETFLTINS pThis = g_VBoxNetFltSolarisInstance; 630 624 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 631 625 … … 633 627 * Check VirtualBox stream type. 634 628 */ 635 if ( pState->CurType == kUndefined)629 if (g_VBoxNetFltSolarisStreamType == kUndefined) 636 630 { 637 631 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode.\n")); … … 646 640 minor_t DevMinor = 0; 647 641 vboxnetflt_stream_t *pStream = NULL; 648 vboxnetflt_stream_t **ppPrevStream = & pState->pOpenedStreams;642 vboxnetflt_stream_t **ppPrevStream = &g_VBoxNetFltSolarisStreams; 649 643 if (fStreamMode == CLONEOPEN) 650 644 { … … 660 654 DevMinor = getminor(*pDev); 661 655 662 if ( pState->CurType == kPromiscStream)656 if (g_VBoxNetFltSolarisStreamType == kPromiscStream) 663 657 { 664 658 vboxnetflt_promisc_stream_t *pPromiscStream = RTMemAlloc(sizeof(vboxnetflt_promisc_stream_t)); … … 701 695 */ 702 696 ASMAtomicUoWritePtr((void * volatile *)&pStream->pThis, pThis); 703 pStream->Type = pState->CurType;697 pStream->Type = g_VBoxNetFltSolarisStreamType; 704 698 switch (pStream->Type) 705 699 { … … 811 805 * Unlink it from the list of streams. 812 806 */ 813 for (ppPrevStream = &g_VBoxNetFltSolarisSt ate.pOpenedStreams; (pStream = *ppPrevStream) != NULL; ppPrevStream = &pStream->pNext)807 for (ppPrevStream = &g_VBoxNetFltSolarisStreams; (pStream = *ppPrevStream) != NULL; ppPrevStream = &pStream->pNext) 814 808 if (pStream == (vboxnetflt_stream_t *)pQueue->q_ptr) 815 809 break; … … 1687 1681 * the I_PUSH phase. 1688 1682 * 1683 * @param pThis The instance. 1689 1684 */ 1690 1685 static int vboxNetFltSolarisOpenStream(PVBOXNETFLTINS pThis) … … 1710 1705 if (!ret) 1711 1706 { 1712 g_VBoxNetFltSolaris State.pCurInstance = pThis;1713 g_VBoxNetFltSolarisSt ate.CurType = kPromiscStream;1707 g_VBoxNetFltSolarisInstance = pThis; 1708 g_VBoxNetFltSolarisStreamType = kPromiscStream; 1714 1709 1715 1710 rc = ldi_ioctl(pThis->u.s.hIface, I_PUSH, (intptr_t)DEVICE_NAME, FKIOCTL, kcred, &ret); 1716 1711 1717 g_VBoxNetFltSolaris State.pCurInstance = NULL;1718 g_VBoxNetFltSolarisSt ate.CurType = kUndefined;1712 g_VBoxNetFltSolarisInstance = NULL; 1713 g_VBoxNetFltSolarisStreamType = kUndefined; 1719 1714 1720 1715 if (!rc) … … 1782 1777 * Statuatory Warning: Hackish code ahead. 1783 1778 */ 1784 if (strlen(pThis->szName) > VBOXNETFLT_IFNAME_LEN - 1)1785 {1786 LogRel((DEVICE_NAME ":vboxNetFltSolarisModSetup: interface name too long %s\n", pThis->szName));1787 return VERR_INTNET_FLT_IF_NOT_FOUND;1788 }1789 1790 1779 char *pszModName = DEVICE_NAME; 1791 1780 … … 1900 1889 * of the inability to pass user data while inserting. 1901 1890 */ 1902 g_VBoxNetFltSolaris State.pCurInstance = pThis;1903 g_VBoxNetFltSolarisSt ate.CurType = kIpStream;1891 g_VBoxNetFltSolarisInstance = pThis; 1892 g_VBoxNetFltSolarisStreamType = kIpStream; 1904 1893 1905 1894 /* … … 1913 1902 * Inject/Eject from the host ARP stack. 1914 1903 */ 1915 g_VBoxNetFltSolarisSt ate.CurType = kArpStream;1904 g_VBoxNetFltSolarisStreamType = kArpStream; 1916 1905 rc = strioctl(pVNodeArp, fAttach ? _I_INSERT : _I_REMOVE, (intptr_t)&ArpStrMod, 0, K_TO_K, 1917 1906 kcred, &ret); 1918 1907 if (!rc) 1919 1908 { 1920 g_VBoxNetFltSolaris State.pCurInstance = NULL;1921 g_VBoxNetFltSolarisSt ate.CurType = kUndefined;1909 g_VBoxNetFltSolarisInstance = NULL; 1910 g_VBoxNetFltSolarisStreamType = kUndefined; 1922 1911 1923 1912 /* … … 1990 1979 } 1991 1980 else 1992 LogRel((DEVICE_NAME ":vboxNetFltSolarisModSetup: invalid interface '%s'.\n", pThis->szName)); 1981 { 1982 /* 1983 * This would happen for interfaces that are not plumbed. 1984 */ 1985 LogRel((DEVICE_NAME ":vboxNetFltSolarisModSetup: Warning: seems '%s' is unplumbed.\n", pThis->szName)); 1986 rc = VINF_SUCCESS; 1987 } 1993 1988 1994 1989 ldi_close(ARPDevHandle, FREAD | FWRITE, kcred); 1995 1990 ldi_close(IPDevHandle, FREAD | FWRITE, kcred); 1991 1992 if (RT_SUCCESS(rc)) 1993 return rc; 1996 1994 1997 1995 return VERR_INTNET_FLT_IF_FAILED; … … 2018 2016 if (RT_SUCCESS(rc)) 2019 2017 ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, false); 2018 else 2019 vboxNetFltSolarisCloseStream(pThis); 2020 2020 } 2021 2021 else … … 2573 2573 * Don't loopback packets we transmit to the wire. 2574 2574 */ 2575 /** @todo maybe we need not check for loopback for INTNETTRUNKDIR_HOST case? */ 2575 2576 if (vboxNetFltSolarisIsOurMBlk(pThis, pPromiscStream, pMsg)) 2576 2577 { … … 2580 2581 } 2581 2582 2582 #if 02583 /*2584 * Yeah, I wish.2585 */2586 if (pMsg->b_flag & MSGNOLOOP)2587 {2588 freemsg(pMsg);2589 return VINF_SUCCESS;2590 }2591 #endif2592 2593 2583 /* 2594 2584 * Figure out the source of the packet based on the source Mac address. 2595 2585 */ 2596 /** @todo Is there a more fool-proof way to determine if the packet was indeed sent from the host?? */2597 2586 uint32_t fSrc = INTNETTRUNKDIR_WIRE; 2598 2587 PRTNETETHERHDR pEthHdr = (PRTNETETHERHDR)pMsg->b_rptr; … … 2642 2631 return NULL; 2643 2632 2644 vboxnetflt_stream_t *pCur = g_VBoxNetFltSolarisSt ate.pOpenedStreams;2633 vboxnetflt_stream_t *pCur = g_VBoxNetFltSolarisStreams; 2645 2634 for (; pCur; pCur = pCur->pNext) 2646 2635 if (pCur == pStream) … … 2860 2849 { 2861 2850 LogFlow((DEVICE_NAME ":vboxNetFltPortOsGetMacAddress pThis=%p\n", pThis)); 2862 2863 RTMAC EmptyMac;2864 bzero(&EmptyMac, sizeof(EmptyMac));2865 if (!bcmp(&pThis->u.s.Mac, &EmptyMac, sizeof(EmptyMac))) /* This should never happen... */2866 {2867 /* Bummer, Mac address is not copied yet. */2868 LogRel((DEVICE_NAME ":vboxNetFltPortOsGetMacAddress: Mac address not cached yet!\n"));2869 return;2870 }2871 2872 2851 *pMac = pThis->u.s.Mac; 2873 2852 } … … 2995 2974 2996 2975 vboxNetFltSolarisQueueLoopback(pThis, pPromiscStream, pMsg); 2997 2998 #if 02999 /*3000 * Too bad we can't keep this, though it "works"....3001 */3002 pMsg->b_flag |= MSGNOLOOP;3003 #endif3004 2976 putnext(WR(pPromiscStream->Stream.pReadQueue), pMsg); 3005 2977 } … … 3035 3007 3036 3008 vboxnetflt_stream_t *pArpStream = ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pvArpStream); 3037 if ( RT_LIKELY(pArpStream))3009 if (pArpStream) 3038 3010 { 3039 3011 queue_t *pArpReadQueue = pArpStream->pReadQueue; … … 3041 3013 } 3042 3014 else 3043 rc = VERR_INVALID_POINTER; 3015 { 3016 /* 3017 * For unplumbed interfaces we may not be bound to ARP. 3018 */ 3019 freemsg(pMsg); 3020 } 3044 3021 } 3045 3022 else … … 3057 3034 LogFlow((DEVICE_NAME ":vboxNetFltPortOsXmit INTNETTRUNKDIR_HOST\n")); 3058 3035 3059 pMsg->b_rptr += sizeof(RTNETETHERHDR);3060 3061 3036 vboxnetflt_stream_t *pIpStream = ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pvIpStream); 3062 if ( RT_LIKELY(pIpStream))3037 if (pIpStream) 3063 3038 { 3039 pMsg->b_rptr += sizeof(RTNETETHERHDR); 3064 3040 queue_t *pIpReadQueue = pIpStream->pReadQueue; 3065 3041 putnext(pIpReadQueue, pMsg); 3066 3042 } 3067 3043 else 3068 rc = VERR_INVALID_POINTER; 3044 { 3045 /* 3046 * For unplumbed interfaces we may not be bound to IP. 3047 */ 3048 freemsg(pMsg); 3049 } 3069 3050 } 3070 3051 }
Note:
See TracChangeset
for help on using the changeset viewer.