Changeset 18098 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Mar 19, 2009 4:59:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp
r17186 r18098 1050 1050 if (pIfNet) 1051 1051 { 1052 /*1053 * If there is no need to set promiscuous mode the only thing1054 * we have to do in order to preserve the backward compatibility1055 * is to try bringing the interface up if it gets activated.1056 */1057 1052 if (pThis->fDisablePromiscuous) 1058 1053 { 1059 Log(("vboxNetFltPortOsSetActive: promisc disabled, do nothing.\n")); 1054 /* 1055 * Promiscuous mode should not be used (wireless), we just need to 1056 * make sure the interface is up. 1057 */ 1060 1058 if (fActive) 1061 1059 { 1062 /*1063 * Try bring the interface up and running if it's down.1064 */1065 1060 u_int16_t fIf = ifnet_flags(pIfNet); 1066 1061 if ((fIf & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) … … 1070 1065 } 1071 1066 } 1072 vboxNetFltDarwinReleaseIfNet(pThis, pIfNet); 1073 return; 1074 } 1075 /* 1076 * This api is a bit weird, the best reference is the code. 1077 * 1078 * Also, we have a bit or race conditions wrt the maintance of 1079 * host the interface promiscuity for vboxNetFltPortOsIsPromiscuous. 1080 */ 1081 unsigned const cPromiscBefore = VBOX_GET_PCOUNT(pIfNet); 1082 u_int16_t fIf; 1083 if (fActive) 1084 { 1085 Assert(!pThis->u.s.fSetPromiscuous); 1086 errno_t err = ENETDOWN; 1087 ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, true); 1088 1067 } 1068 else 1069 { 1089 1070 /* 1090 * Try bring the interface up and running if it's down. 1071 * This api is a bit weird, the best reference is the code. 1072 * 1073 * Also, we have a bit or race conditions wrt the maintance of 1074 * host the interface promiscuity for vboxNetFltPortOsIsPromiscuous. 1091 1075 */ 1092 fIf = ifnet_flags(pIfNet); 1093 if ((fIf & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) 1076 unsigned const cPromiscBefore = VBOX_GET_PCOUNT(pIfNet); 1077 u_int16_t fIf; 1078 if (fActive) 1094 1079 { 1095 err = ifnet_set_flags(pIfNet, IFF_UP, IFF_UP); 1096 errno_t err2 = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL); 1097 if (!err) 1098 err = err2; 1080 Assert(!pThis->u.s.fSetPromiscuous); 1081 errno_t err = ENETDOWN; 1082 ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, true); 1083 1084 /* 1085 * Try bring the interface up and running if it's down. 1086 */ 1099 1087 fIf = ifnet_flags(pIfNet); 1088 if ((fIf & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) 1089 { 1090 err = ifnet_set_flags(pIfNet, IFF_UP, IFF_UP); 1091 errno_t err2 = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL); 1092 if (!err) 1093 err = err2; 1094 fIf = ifnet_flags(pIfNet); 1095 } 1096 1097 /* 1098 * Is it already up? If it isn't, leave it to the link event or 1099 * we'll upset if_pcount (as stated above, ifnet_set_promiscuous is weird). 1100 */ 1101 if ((fIf & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) 1102 { 1103 err = ifnet_set_promiscuous(pIfNet, 1); 1104 pThis->u.s.fSetPromiscuous = err == 0; 1105 if (!err) 1106 { 1107 ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false); 1108 1109 /* check if it actually worked, this stuff is not always behaving well. */ 1110 if (!(ifnet_flags(pIfNet) & IFF_PROMISC)) 1111 { 1112 err = ifnet_set_flags(pIfNet, IFF_PROMISC, IFF_PROMISC); 1113 if (!err) 1114 err = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL); 1115 if (!err) 1116 Log(("vboxNetFlt: fixed IFF_PROMISC on %s (%d->%d)\n", pThis->szName, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1117 else 1118 Log(("VBoxNetFlt: failed to fix IFF_PROMISC on %s, err=%d (%d->%d)\n", 1119 pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1120 } 1121 } 1122 else 1123 Log(("VBoxNetFlt: ifnet_set_promiscuous -> err=%d grr! (%d->%d)\n", err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1124 } 1125 else if (!err) 1126 Log(("VBoxNetFlt: Waiting for the link to come up... (%d->%d)\n", cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1127 if (err) 1128 LogRel(("VBoxNetFlt: Failed to put '%s' into promiscuous mode, err=%d (%d->%d)\n", pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1100 1129 } 1101 1102 /* 1103 * Is it already up? If it isn't, leave it to the link event or 1104 * we'll upset if_pcount (as stated above, ifnet_set_promiscuous is weird). 1105 */ 1106 if ((fIf & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING)) 1130 else 1107 1131 { 1108 err = ifnet_set_promiscuous(pIfNet, 1); 1109 pThis->u.s.fSetPromiscuous = err == 0; 1110 if (!err) 1132 ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false); 1133 if (pThis->u.s.fSetPromiscuous) 1111 1134 { 1112 ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false); 1113 1114 /* check if it actually worked, this stuff is not always behaving well. */ 1115 if (!(ifnet_flags(pIfNet) & IFF_PROMISC)) 1116 { 1117 err = ifnet_set_flags(pIfNet, IFF_PROMISC, IFF_PROMISC); 1118 if (!err) 1119 err = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL); 1120 if (!err) 1121 Log(("vboxNetFlt: fixed IFF_PROMISC on %s (%d->%d)\n", pThis->szName, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1122 else 1123 Log(("VBoxNetFlt: failed to fix IFF_PROMISC on %s, err=%d (%d->%d)\n", 1124 pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1125 } 1135 errno_t err = ifnet_set_promiscuous(pIfNet, 0); 1136 AssertMsg(!err, ("%d\n", err)); NOREF(err); 1126 1137 } 1127 else 1128 Log(("VBoxNetFlt: ifnet_set_promiscuous -> err=%d grr! (%d->%d)\n", err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1138 pThis->u.s.fSetPromiscuous = false; 1139 1140 fIf = ifnet_flags(pIfNet); 1141 Log(("VBoxNetFlt: fIf=%#x; %d->%d\n", fIf, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet))); 1129 1142 } 1130 else if (!err)1131 Log(("VBoxNetFlt: Waiting for the link to come up... (%d->%d)\n", cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));1132 if (err)1133 LogRel(("VBoxNetFlt: Failed to put '%s' into promiscuous mode, err=%d (%d->%d)\n", pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));1134 }1135 else1136 {1137 ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false);1138 if (pThis->u.s.fSetPromiscuous)1139 {1140 errno_t err = ifnet_set_promiscuous(pIfNet, 0);1141 AssertMsg(!err, ("%d\n", err)); NOREF(err);1142 }1143 pThis->u.s.fSetPromiscuous = false;1144 1145 fIf = ifnet_flags(pIfNet);1146 Log(("VBoxNetFlt: fIf=%#x; %d->%d\n", fIf, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));1147 1143 } 1148 1144
Note:
See TracChangeset
for help on using the changeset viewer.