- Timestamp:
- Sep 17, 2008 9:24:05 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c
r12326 r12531 28 28 #include <iprt/mem.h> 29 29 #include <iprt/thread.h> 30 #include <iprt/spinlock.h> 30 31 31 32 #include <inet/ip.h> … … 760 761 static int VBoxNetFltSolarisModReadPut(queue_t *pQueue, mblk_t *pMsg) 761 762 { 763 if (!pMsg) 764 return 0; 765 762 766 LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModReadPut pQueue=%p pMsg=%p\n")); 763 767 764 768 bool fSendUpstream = true; 769 bool fActive = false; 765 770 vboxnetflt_stream_t *pStream = pQueue->q_ptr; 771 PVBOXNETFLTINS pThis = NULL; 766 772 767 773 /* … … 773 779 && pMsg) 774 780 { 775 PVBOXNETFLTINSpThis = vboxNetFltSolarisFindInstance(pStream);781 pThis = vboxNetFltSolarisFindInstance(pStream); 776 782 if (RT_LIKELY(pThis)) 777 783 { 784 /* 785 * Retain the instance if we're actively filtering. 786 */ 787 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 788 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 789 fActive = ASMAtomicUoReadBool(&pThis->fActive); 790 if (fActive) 791 vboxNetFltRetain(pThis, true); 792 RTSpinlockRelease(pThis->hSpinlock, &Tmp); 793 778 794 switch (DB_TYPE(pMsg)) 779 795 { … … 782 798 LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModReadPut M_DATA\n")); 783 799 784 vboxNetFltSolarisRecv(pThis, pStream, pQueue, pMsg); 785 fSendUpstream = false; /* vboxNetFltSolarisRecv would send it if required, do nothing more here. */ 800 if (fActive) 801 { 802 vboxNetFltSolarisRecv(pThis, pStream, pQueue, pMsg); 803 fSendUpstream = false; 804 } 786 805 break; 787 806 } … … 804 823 LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModReadPut: DL_UNITDATA_IND\n")); 805 824 806 vboxNetFltSolarisRecv(pThis, pStream, pQueue, pMsg); 807 fSendUpstream = false; /* vboxNetFltSolarisRecv would send it if required, do nothing more here. */ 825 if (fActive) 826 { 827 vboxNetFltSolarisRecv(pThis, pStream, pQueue, pMsg); 828 fSendUpstream = false; 829 } 808 830 break; 809 831 } … … 860 882 if (pIOC->ioc_id == pStream->ModeReqId) 861 883 { 862 pStream->fRawMode = !pStream->fRawMode;884 pStream->fRawMode = true; 863 885 LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModReadPut: Mode acknowledgement. RawMode is %s\n", 864 886 pStream->fRawMode ? "ON" : "OFF")); … … 902 924 } 903 925 926 if (fActive) 927 vboxNetFltRelease(pThis, true); 928 904 929 return 0; 905 930 } … … 922 947 */ 923 948 bool fSendDownstream = true; 949 bool fActive = false; 924 950 vboxnetflt_stream_t *pStream = pQueue->q_ptr; 951 PVBOXNETFLTINS pThis = NULL; 925 952 926 953 /* … … 932 959 && pMsg) 933 960 { 934 PVBOXNETFLTINSpThis = vboxNetFltSolarisFindInstance(pStream);961 pThis = vboxNetFltSolarisFindInstance(pStream); 935 962 if (RT_LIKELY(pThis)) 936 963 { 964 /* 965 * Retain the instance if we're actively filtering. 966 */ 967 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 968 RTSpinlockAcquire(pThis->hSpinlock, &Tmp); 969 fActive = ASMAtomicUoReadBool(&pThis->fActive); 970 if (fActive) 971 vboxNetFltRetain(pThis, true); 972 RTSpinlockRelease(pThis->hSpinlock, &Tmp); 973 937 974 switch (DB_TYPE(pMsg)) 938 975 { … … 991 1028 if (pIOC->ioc_cmd == DL_IOC_HDR_INFO) 992 1029 { 993 if (pThis->fActive) 1030 fSendDownstream = false; 1031 1032 /* 1033 * Some sanity checks. 1034 */ 1035 if ( !pMsg->b_cont 1036 || (MBLKL(pMsg->b_cont) < sizeof(dl_unitdata_req_t) + VBOXNETFLT_DLADDRL) 1037 || (*((uint32_t *)pMsg->b_cont->b_rptr) != DL_UNITDATA_REQ)) 994 1038 { 995 fSendDownstream = false; 996 997 /* 998 * Some sanity checks. 999 */ 1000 if ( !pMsg->b_cont 1001 || (MBLKL(pMsg->b_cont) < sizeof(dl_unitdata_req_t) + VBOXNETFLT_DLADDRL) 1002 || (*((uint32_t *)pMsg->b_cont->b_rptr) != DL_UNITDATA_REQ)) 1003 { 1004 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Invalid fast path request!\n")); 1005 miocnak(pQueue, pMsg, 0, EPROTO); 1006 break; 1007 } 1008 1009 dl_unitdata_req_t *pDlReq = (dl_unitdata_req_t *)pMsg->b_cont->b_rptr; 1010 size_t cbOffset = pDlReq->dl_dest_addr_offset; 1011 size_t cbAddr = pDlReq->dl_dest_addr_length; 1012 if ( !MBLKIN(pMsg->b_cont, cbOffset, cbAddr) 1013 || cbAddr != VBOXNETFLT_DLADDRL) 1014 { 1015 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Invalid header in fast path request!\n")); 1016 miocnak(pQueue, pMsg, 0, EPROTO); 1017 break; 1018 } 1019 1020 vboxnetflt_dladdr_t *pDLSapAddr = (vboxnetflt_dladdr_t *)(pMsg->b_cont->b_rptr + cbOffset); 1021 mblk_t *pReplyMsg = allocb(sizeof(RTNETETHERHDR), BPRI_MED); 1022 if (RT_UNLIKELY(!pReplyMsg)) 1023 { 1024 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Invalid header in fast path request!\n")); 1025 miocnak(pQueue, pMsg, 0, ENOMEM); 1026 break; 1027 } 1028 1029 PRTNETETHERHDR pEthHdr = (PRTNETETHERHDR)pMsg->b_rptr; 1030 bcopy(&pDLSapAddr->Mac, &pEthHdr->DstMac, sizeof(RTMAC)); 1031 bcopy(&pThis->u.s.Mac, &pEthHdr->SrcMac, sizeof(RTMAC)); 1032 pEthHdr->EtherType = RT_H2BE_U16(pDLSapAddr->SAP); 1033 1034 linkb(pMsg, pReplyMsg); 1035 1036 /* 1037 * Somebody is wanting fast path when we need raw mode. 1038 * Since we are evil, let's acknowledge the request ourselves! 1039 */ 1040 miocack(pQueue, pMsg, msgsize(pMsg->b_cont), EINVAL); 1041 LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Fast path request acknowledged.\n")); 1039 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Invalid fast path request!\n")); 1040 miocnak(pQueue, pMsg, 0, EPROTO); 1041 break; 1042 1042 } 1043 1044 dl_unitdata_req_t *pDlReq = (dl_unitdata_req_t *)pMsg->b_cont->b_rptr; 1045 size_t cbOffset = pDlReq->dl_dest_addr_offset; 1046 size_t cbAddr = pDlReq->dl_dest_addr_length; 1047 if ( !MBLKIN(pMsg->b_cont, cbOffset, cbAddr) 1048 || cbAddr != VBOXNETFLT_DLADDRL) 1049 { 1050 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Invalid header in fast path request!\n")); 1051 miocnak(pQueue, pMsg, 0, EPROTO); 1052 break; 1053 } 1054 1055 vboxnetflt_dladdr_t *pDLSapAddr = (vboxnetflt_dladdr_t *)(pMsg->b_cont->b_rptr + cbOffset); 1056 mblk_t *pReplyMsg = allocb(sizeof(RTNETETHERHDR), BPRI_MED); 1057 if (RT_UNLIKELY(!pReplyMsg)) 1058 { 1059 LogRel((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Invalid header in fast path request!\n")); 1060 miocnak(pQueue, pMsg, 0, ENOMEM); 1061 break; 1062 } 1063 1064 PRTNETETHERHDR pEthHdr = (PRTNETETHERHDR)pMsg->b_rptr; 1065 bcopy(&pDLSapAddr->Mac, &pEthHdr->DstMac, sizeof(RTMAC)); 1066 bcopy(&pThis->u.s.Mac, &pEthHdr->SrcMac, sizeof(RTMAC)); 1067 pEthHdr->EtherType = RT_H2BE_U16(pDLSapAddr->SAP); 1068 1069 linkb(pMsg, pReplyMsg); 1070 1071 /* 1072 * Somebody is wanting fast path when we need raw mode. 1073 * Since we are evil, let's acknowledge the request ourselves! 1074 */ 1075 miocack(pQueue, pMsg, msgsize(pMsg->b_cont), EINVAL); 1076 LogFlow((DEVICE_NAME ":VBoxNetFltSolarisModWritePut: Fast path request acknowledged.\n")); 1043 1077 } 1044 1078 break; … … 1094 1128 putq(pQueue, pMsg); 1095 1129 } 1130 1131 if (fActive) 1132 vboxNetFltRelease(pThis, true); 1096 1133 1097 1134 return 0; … … 2160 2197 PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs])); 2161 2198 int rc = vboxNetFltSolarisMBlkToSG(pThis, pMsg, pSG, cSegs, fSrc); 2162 if ( VBOX_FAILURE(rc))2199 if (RT_FAILURE(rc)) 2163 2200 { 2164 2201 LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG failed. rc=%d\n", rc)); … … 2377 2414 2378 2415 PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pMsg->b_rptr; 2416 uint8_t *pb = pMsg->b_rptr; 2379 2417 if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV4)) 2380 2418 { … … 2383 2421 if (RTNetIPv4IsHdrValid(pIpHdr, cbLen, cbLen)) 2384 2422 { 2385 uint8_t *pb = pMsg->b_rptr;2386 2423 if (pIpHdr->ip_p == RTNETIPV4_PROT_ICMP) 2387 2424 LogFlow((DEVICE_NAME ":ICMP D=%.6Rhxs S=%.6Rhxs T=%04x\n", pb, pb + 6, RT_BE2H_U16(*(uint16_t *)(pb + 12)))); … … 2391 2428 LogFlow((DEVICE_NAME ":UDP D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6)); 2392 2429 } 2430 else if (!pMsg->b_cont) 2431 { 2432 LogFlow((DEVICE_NAME ":Invalid IP header.\n")); 2433 } 2393 2434 else 2394 2435 { 2395 LogFlow((DEVICE_NAME ":Invalid IP header.\n")); 2396 return; 2436 LogFlow((DEVICE_NAME ":Chained IP packet. Skipped validity check.\n")); 2397 2437 } 2398 2438 } … … 2402 2442 LogFlow((DEVICE_NAME ":ARP Op=%d\n", pArpHdr->ar_oper)); 2403 2443 } 2444 else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV6)) 2445 { 2446 LogFlow((DEVICE_NAME ":IPv6 D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6)); 2447 } 2448 else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_1) 2449 || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_2) 2450 || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_3)) 2451 { 2452 LogFlow((DEVICE_NAME ":IPX packet.\n")); 2453 } 2404 2454 else 2405 2455 { … … 2415 2465 { 2416 2466 vboxnetflt_stream_t *pStream = pThis->u.s.pvStream; 2417 return pStream->fPromisc; 2467 if (pStream) 2468 return pStream->fPromisc; 2469 2470 LogRel((DEVICE_NAME ":vboxNetFltPortOsIsPromiscuous stream not found!!\n")); 2471 return false; 2418 2472 } 2419 2473 … … 2456 2510 */ 2457 2511 vboxnetflt_stream_t *pStream = pThis->u.s.pvStream; 2458 Assert(pStream->Type == kIpStream); 2459 int rc = vboxNetFltSolarisPromiscReq(pStream->pReadQueue, fActive); 2460 if (VBOX_FAILURE(rc)) 2461 LogRel((DEVICE_NAME ":vboxNetFltPortOsSetActive failed to request promiscuous mode! rc=%d\n", rc)); 2512 if (pStream) 2513 { 2514 int rc = vboxNetFltSolarisPromiscReq(pStream->pReadQueue, fActive); 2515 if (RT_FAILURE(rc)) 2516 LogRel((DEVICE_NAME ":vboxNetFltPortOsSetActive failed to request promiscuous mode! rc=%d\n", rc)); 2517 } 2518 else 2519 LogRel((DEVICE_NAME ":vboxNetFltPortOsSetActive stream not found!\n")); 2462 2520 } 2463 2521 … … 2557 2615 mblk_t *pDlpiMsg; 2558 2616 int rc = vboxNetFltSolarisRawToUnitData(pMsg, &pDlpiMsg); 2559 if ( VBOX_FAILURE(rc))2617 if (RT_FAILURE(rc)) 2560 2618 { 2561 2619 LogRel((DEVICE_NAME ":vboxNetFltSolarisRawToUnitData failed! rc=%d\n", rc));
Note:
See TracChangeset
for help on using the changeset viewer.