- Timestamp:
- Aug 9, 2011 8:37:03 AM (13 years ago)
- Location:
- trunk/src/VBox/HostDrivers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c
r36951 r38370 1197 1197 for (i = 0; i < RT_ELEMENTS(g_aAdapters); i++) 1198 1198 { 1199 g_aAdapters[i].uMagic = VBOXNETADP_MAGIC; 1199 1200 g_aAdapters[i].enmState = kVBoxNetAdpState_Invalid; 1200 1201 g_aAdapters[i].iUnit = -1; -
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h
r35824 r38370 30 30 typedef struct VBOXNETADPGLOBALS *PVBOXNETADPGLOBALS; 31 31 32 /* WARNING! There a copy of VBOXNETADP_MAGIC in VBoxNetFlt/VBoxNetFltInternal.h! */ 33 /* v b n a */ 34 #define VBOXNETADP_MAGIC 0x56424e41 32 35 #define VBOXNETADP_MAX_INSTANCES 8 33 36 #define VBOXNETADP_MAX_UNITS 128 … … 83 86 struct VBoxNetAdapter 84 87 { 88 /** Magic id to tell vboxnetX interfaces apart. */ 89 uint32_t uMagic; 85 90 /** Denotes availability of this slot in adapter array. */ 86 91 VBOXNETADPSTATE enmState; … … 104 109 /** Protocol families attached to this adapter. */ 105 110 protocol_family_t aAttachedFamilies[VBOXNETADP_MAX_FAMILIES]; 111 /** Packet sniffer mode. */ 112 bpf_tap_mode nTapMode; 106 113 /** @} */ 107 114 # elif defined(RT_OS_LINUX) -
trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp
r37423 r38370 55 55 #include <sys/conf.h> 56 56 #include <miscfs/devfs/devfs.h> 57 extern "C" { 58 #include <net/bpf.h> 59 } 57 60 58 61 #define VBOXNETADP_OS_SPECFIC 1 … … 142 145 static errno_t vboxNetAdpDarwinOutput(ifnet_t pIface, mbuf_t pMBuf) 143 146 { 147 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 148 Assert(pThis); 149 if (pThis->u.s.nTapMode & BPF_MODE_OUTPUT) 150 { 151 Log2(("vboxnetadp: out len=%d\n%.*Rhxd\n", mbuf_len(pMBuf), 14, mbuf_data(pMBuf))); 152 bpf_tap_out(pIface, DLT_EN10MB, pMBuf, NULL, 0); 153 } 144 154 mbuf_freem_list(pMBuf); 145 155 return 0; … … 192 202 } 193 203 194 204 static errno_t vboxNetAdpDarwinDemux(ifnet_t pIface, mbuf_t pMBuf, 205 char *pFrameHeader, 206 protocol_family_t *pProtocolFamily) 207 { 208 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 209 Assert(pThis); 210 Log2(("vboxNetAdpDarwinDemux: mode=%d\n", nMode)); 211 if (pThis->u.s.nTapMode & BPF_MODE_INPUT) 212 { 213 Log2(("vboxnetadp: in len=%d\n%.*Rhxd\n", mbuf_len(pMBuf), 14, pFrameHeader)); 214 bpf_tap_in(pIface, DLT_EN10MB, pMBuf, pFrameHeader, ETHER_HDR_LEN); 215 } 216 return ether_demux(pIface, pMBuf, pFrameHeader, pProtocolFamily); 217 } 218 219 static errno_t vboxNetAdpDarwinBpfTap(ifnet_t pIface, u_int32_t uLinkType, bpf_tap_mode nMode) 220 { 221 PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface); 222 Assert(pThis); 223 Log2(("vboxNetAdpDarwinBpfTap: mode=%d\n", nMode)); 224 pThis->u.s.nTapMode = nMode; 225 return 0; 226 } 227 228 static errno_t vboxNetAdpDarwinBpfSend(ifnet_t pIface, u_int32_t uLinkType, mbuf_t pMBuf) 229 { 230 LogRel(("vboxnetadp: BPF send function is not implemented (dlt=%d)\n", uLinkType)); 231 mbuf_freem_list(pMBuf); 232 return 0; 233 } 195 234 196 235 int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMACAddress) … … 208 247 return rc; 209 248 } 249 250 pThis->u.s.nTapMode = BPF_MODE_DISABLED; 210 251 211 252 mac.sdl_len = sizeof(mac); … … 225 266 Params.type = IFT_ETHER; 226 267 Params.output = vboxNetAdpDarwinOutput; 227 Params.demux = ether_demux;268 Params.demux = vboxNetAdpDarwinDemux; 228 269 Params.add_proto = vboxNetAdpDarwinAddProto; 229 270 Params.del_proto = vboxNetAdpDarwinDelProto; … … 244 285 if (!err) 245 286 { 287 err = bpf_attach(pThis->u.s.pIface, DLT_EN10MB, ETHER_HDR_LEN, 288 vboxNetAdpDarwinBpfSend, vboxNetAdpDarwinBpfTap); 289 if (err) 290 { 291 LogRel(("vboxnetadp: bpf_attach failed with %d\n", err)); 292 } 246 293 err = ifnet_set_flags(pThis->u.s.pIface, IFF_RUNNING | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST, 0xFFFF); 247 294 if (!err) 248 295 { 249 296 ifnet_set_mtu(pThis->u.s.pIface, VBOXNETADP_MTU); 297 Log2(("vboxnetadp: created interface %s (%p), pThis=%p, pMagic=%p, *pMagic=%x(%x)\n", 298 pThis->szName, pThis->u.s.pIface, pThis, ifnet_softc(pThis->u.s.pIface), *(uint32_t*)ifnet_softc(pThis->u.s.pIface), pThis->uMagic)); 250 299 return VINF_SUCCESS; 251 300 } -
trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
r38140 r38370 24 24 #include <iprt/assert.h> 25 25 26 /* Copied from VBoxNetAdp/VBoxNetAdpInternal.h */ 27 #define VBOXNETADP_MAGIC 0x56424e41 26 28 27 29 RT_C_DECLS_BEGIN -
trunk/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp
r33676 r38370 787 787 * @param fSrc Where the packet (allegedly) comes from, one INTNETTRUNKDIR_* value. 788 788 * @param eProtocol The protocol. 789 * @param pIfNet The network interface. 789 790 */ 790 791 static errno_t vboxNetFltDarwinIffInputOutputWorker(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame, 791 uint32_t fSrc, protocol_family_t eProtocol) 792 uint32_t fSrc, protocol_family_t eProtocol, 793 ifnet_t pIfNet) 792 794 { 793 795 /* … … 838 840 fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, fSrc); 839 841 if (fDropIt) 840 mbuf_freem(pMBuf); 842 { 843 /* 844 * Check is this interface belongs to vboxnetadp. We should not drop 845 * any packets before they get to vboxnetadp as it passes them to tap 846 * callbacks in order for BPF to work properly. 847 */ 848 uint32_t *pMagic = (uint32_t *)ifnet_softc(pIfNet); 849 Log2(("vboxnetflt: pMagic=%p *pMagic=%x\n", pMagic, pMagic ? *pMagic : -1)); 850 if (pMagic && *pMagic == VBOXNETADP_MAGIC) 851 fDropIt = false; 852 else 853 mbuf_freem(pMBuf); 854 } 841 855 } 842 856 … … 857 871 858 872 NOREF(eProtocol); 859 NOREF(pIfNet); 860 return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, NULL, INTNETTRUNKDIR_HOST, eProtocol); 873 return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, NULL, INTNETTRUNKDIR_HOST, eProtocol, pIfNet); 861 874 } 862 875 … … 870 883 { 871 884 NOREF(eProtocol); 872 NOREF(pIfNet); 873 return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, *ppchFrame, INTNETTRUNKDIR_WIRE, eProtocol); 885 return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, *ppchFrame, INTNETTRUNKDIR_WIRE, eProtocol, pIfNet); 874 886 } 875 887
Note:
See TracChangeset
for help on using the changeset viewer.