1 | /* $Id: VBoxNetFlt-darwin.cpp 62466 2016-07-22 18:00:27Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxNetFlt - Network Filter Driver (Host), Darwin Specific Code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_NET_FLT_DRV
|
---|
23 | #include "../../../Runtime/r0drv/darwin/the-darwin-kernel.h"
|
---|
24 |
|
---|
25 | #include <VBox/log.h>
|
---|
26 | #include <VBox/err.h>
|
---|
27 | #include <VBox/intnetinline.h>
|
---|
28 | #include <VBox/version.h>
|
---|
29 | #include <iprt/initterm.h>
|
---|
30 | #include <iprt/assert.h>
|
---|
31 | #include <iprt/spinlock.h>
|
---|
32 | #include <iprt/semaphore.h>
|
---|
33 | #include <iprt/process.h>
|
---|
34 | #include <iprt/alloc.h>
|
---|
35 | #include <iprt/alloca.h>
|
---|
36 | #include <iprt/time.h>
|
---|
37 | #include <iprt/net.h>
|
---|
38 | #include <iprt/thread.h>
|
---|
39 |
|
---|
40 | #include "../../darwin/VBoxNetSend.h"
|
---|
41 |
|
---|
42 | #include <mach/kmod.h>
|
---|
43 | #include <sys/conf.h>
|
---|
44 | #include <sys/errno.h>
|
---|
45 | #include <sys/ioccom.h>
|
---|
46 | #include <sys/filio.h>
|
---|
47 | #include <sys/malloc.h>
|
---|
48 | #include <sys/proc.h>
|
---|
49 | #include <sys/socket.h>
|
---|
50 | #include <sys/sockio.h>
|
---|
51 | #include <sys/kern_event.h>
|
---|
52 | #include <net/kpi_interface.h>
|
---|
53 | RT_C_DECLS_BEGIN /* Buggy 10.4 headers, fixed in 10.5. */
|
---|
54 | #include <sys/kpi_mbuf.h>
|
---|
55 | #include <net/kpi_interfacefilter.h>
|
---|
56 | RT_C_DECLS_END
|
---|
57 |
|
---|
58 | #include <sys/kpi_socket.h>
|
---|
59 | #include <net/if.h>
|
---|
60 | #include <net/if_var.h>
|
---|
61 | RT_C_DECLS_BEGIN
|
---|
62 | #include <net/bpf.h>
|
---|
63 | RT_C_DECLS_END
|
---|
64 | #include <netinet/in.h>
|
---|
65 | #include <netinet/in_var.h>
|
---|
66 | #include <netinet6/in6_var.h>
|
---|
67 |
|
---|
68 | #define VBOXNETFLT_OS_SPECFIC 1
|
---|
69 | #include "../VBoxNetFltInternal.h"
|
---|
70 |
|
---|
71 |
|
---|
72 | /*********************************************************************************************************************************
|
---|
73 | * Defined Constants And Macros *
|
---|
74 | *********************************************************************************************************************************/
|
---|
75 | /** The maximum number of SG segments.
|
---|
76 | * Used to prevent stack overflow and similar bad stuff. */
|
---|
77 | #define VBOXNETFLT_DARWIN_MAX_SEGS 32
|
---|
78 |
|
---|
79 | #if 0
|
---|
80 | /** For testing extremely segmented frames. */
|
---|
81 | #define VBOXNETFLT_DARWIN_TEST_SEG_SIZE 14
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | /* XXX: hidden undef #ifdef __APPLE__ */
|
---|
85 | #define VBOX_IN_LOOPBACK(addr) (((addr) & IN_CLASSA_NET) == 0x7f000000)
|
---|
86 | #define VBOX_IN_LINKLOCAL(addr) (((addr) & IN_CLASSB_NET) == 0xa9fe0000)
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | /*********************************************************************************************************************************
|
---|
91 | * Internal Functions *
|
---|
92 | *********************************************************************************************************************************/
|
---|
93 | RT_C_DECLS_BEGIN
|
---|
94 | static kern_return_t VBoxNetFltDarwinStart(struct kmod_info *pKModInfo, void *pvData);
|
---|
95 | static kern_return_t VBoxNetFltDarwinStop(struct kmod_info *pKModInfo, void *pvData);
|
---|
96 |
|
---|
97 | static void vboxNetFltDarwinSysSockUpcall(socket_t pSysSock, void *pvData, int fWait);
|
---|
98 | RT_C_DECLS_END
|
---|
99 |
|
---|
100 |
|
---|
101 | /*********************************************************************************************************************************
|
---|
102 | * Structures and Typedefs *
|
---|
103 | *********************************************************************************************************************************/
|
---|
104 | /**
|
---|
105 | * The mbuf tag data.
|
---|
106 | *
|
---|
107 | * We have to associate the ethernet header with each packet we're sending
|
---|
108 | * because things like icmp will inherit the tag it self so the tag along
|
---|
109 | * isn't sufficient to identify our mbufs. For the icmp scenario the ethernet
|
---|
110 | * header naturally changes before the packet is send pack, so let check it.
|
---|
111 | */
|
---|
112 | typedef struct VBOXNETFLTTAG
|
---|
113 | {
|
---|
114 | /** The ethernet header of the outgoing frame. */
|
---|
115 | RTNETETHERHDR EthHdr;
|
---|
116 | } VBOXNETFLTTAG;
|
---|
117 | /** Pointer to a VBoxNetFlt mbuf tag. */
|
---|
118 | typedef VBOXNETFLTTAG *PVBOXNETFLTTAG;
|
---|
119 | /** Pointer to a const VBoxNetFlt mbuf tag. */
|
---|
120 | typedef VBOXNETFLTTAG const *PCVBOXNETFLTTAG;
|
---|
121 |
|
---|
122 |
|
---|
123 | /*********************************************************************************************************************************
|
---|
124 | * Global Variables *
|
---|
125 | *********************************************************************************************************************************/
|
---|
126 | /**
|
---|
127 | * Declare the module stuff.
|
---|
128 | */
|
---|
129 | RT_C_DECLS_BEGIN
|
---|
130 | extern kern_return_t _start(struct kmod_info *pKModInfo, void *pvData);
|
---|
131 | extern kern_return_t _stop(struct kmod_info *pKModInfo, void *pvData);
|
---|
132 |
|
---|
133 | KMOD_EXPLICIT_DECL(VBoxNetFlt, VBOX_VERSION_STRING, _start, _stop)
|
---|
134 | DECLHIDDEN(kmod_start_func_t *) _realmain = VBoxNetFltDarwinStart;
|
---|
135 | DECLHIDDEN(kmod_stop_func_t *) _antimain = VBoxNetFltDarwinStop;
|
---|
136 | DECLHIDDEN(int) _kext_apple_cc = __APPLE_CC__;
|
---|
137 | RT_C_DECLS_END
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * The (common) global data.
|
---|
142 | */
|
---|
143 | static VBOXNETFLTGLOBALS g_VBoxNetFltGlobals;
|
---|
144 |
|
---|
145 | /** The unique tag id for this module.
|
---|
146 | * This is basically a unique string hash that lives on until reboot.
|
---|
147 | * It is used for tagging mbufs. */
|
---|
148 | static mbuf_tag_id_t g_idTag;
|
---|
149 |
|
---|
150 | /** The offset of the struct ifnet::if_pcount variable.
|
---|
151 | * @remarks Initial value is valid for Lion and earlier. We adjust it on attach
|
---|
152 | * for later releases. */
|
---|
153 | static unsigned g_offIfNetPCount = sizeof(void *) * (1 /*if_softc*/ + 1 /*if_name*/ + 2 /*if_link*/ + 2 /*if_addrhead*/ + 1 /*if_check_multi*/)
|
---|
154 | + sizeof(u_long) /*if_refcnt*/;
|
---|
155 | /** Macro for accessing ifnet::if_pcount. */
|
---|
156 | #define VBOX_GET_PCOUNT(pIfNet) ( *(int *)((uintptr_t)pIfNet + g_offIfNetPCount) )
|
---|
157 | /** The size of area of ifnet structure we try to locate if_pcount in. */
|
---|
158 | #define VBOXNETFLT_DARWIN_IFNET_SIZE 256
|
---|
159 | /** Indicates whether g_offIfNetPCount has been adjusted already (no point in
|
---|
160 | * doing it more than once). */
|
---|
161 | static bool g_fNetPCountFound = false;
|
---|
162 |
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Change the promiscuous setting and try spot the changed in @a pIfNet.
|
---|
166 | *
|
---|
167 | * @returns Offset of potential p_count field.
|
---|
168 | * @param pIfNet The interface we're attaching to.
|
---|
169 | * @param iPromisc Whether to enable (1) or disable (0) promiscuous mode.
|
---|
170 | *
|
---|
171 | * @note This implementation relies on if_pcount to be aligned on sizeof(int).
|
---|
172 | */
|
---|
173 | static unsigned vboxNetFltDarwinSetAndDiff(ifnet_t pIfNet, int iPromisc)
|
---|
174 | {
|
---|
175 | int aiSavedState[VBOXNETFLT_DARWIN_IFNET_SIZE / sizeof(int)];
|
---|
176 | memcpy(aiSavedState, pIfNet, sizeof(aiSavedState));
|
---|
177 |
|
---|
178 | ifnet_set_promiscuous(pIfNet, iPromisc);
|
---|
179 |
|
---|
180 | int const iDiff = iPromisc ? 1 : -1;
|
---|
181 |
|
---|
182 | /*
|
---|
183 | * We assume that ifnet structure will never have less members in front of if_pcount
|
---|
184 | * than it used to have in Lion. If this turns out to be false assumption we will
|
---|
185 | * have to start from zero offset.
|
---|
186 | */
|
---|
187 | for (unsigned i = g_offIfNetPCount / sizeof(int); i < RT_ELEMENTS(aiSavedState); i++)
|
---|
188 | if (((int*)pIfNet)[i] - aiSavedState[i] == iDiff)
|
---|
189 | return i * sizeof(int);
|
---|
190 |
|
---|
191 | return 0;
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Detect and adjust the offset of ifnet::if_pcount.
|
---|
197 | *
|
---|
198 | * @param pIfNet The interface we're attaching to.
|
---|
199 | */
|
---|
200 | static void vboxNetFltDarwinDetectPCountOffset(ifnet_t pIfNet)
|
---|
201 | {
|
---|
202 | if (g_fNetPCountFound)
|
---|
203 | return;
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * It would be nice to use locking at this point, but it is not available via KPI.
|
---|
207 | * This is why we try several times. At each attempt we modify if_pcount four times
|
---|
208 | * to rule out false detections.
|
---|
209 | */
|
---|
210 | unsigned offTry1, offTry2, offTry3, offTry4;
|
---|
211 | for (int iAttempt = 0; iAttempt < 3; iAttempt++)
|
---|
212 | {
|
---|
213 | offTry1 = vboxNetFltDarwinSetAndDiff(pIfNet, 1);
|
---|
214 | offTry2 = vboxNetFltDarwinSetAndDiff(pIfNet, 1);
|
---|
215 | offTry3 = vboxNetFltDarwinSetAndDiff(pIfNet, 0);
|
---|
216 | offTry4 = vboxNetFltDarwinSetAndDiff(pIfNet, 0);
|
---|
217 | if (offTry1 == offTry2 && offTry2 == offTry3 && offTry3 == offTry4)
|
---|
218 | {
|
---|
219 | if (g_offIfNetPCount != offTry1)
|
---|
220 | {
|
---|
221 | Log(("VBoxNetFltDarwinDetectPCountOffset: Adjusted if_pcount offset to %x from %x.\n", offTry1, g_offIfNetPCount));
|
---|
222 | g_offIfNetPCount = offTry1;
|
---|
223 | g_fNetPCountFound = true;
|
---|
224 | }
|
---|
225 | break;
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | if (g_offIfNetPCount != offTry1)
|
---|
230 | LogRel(("VBoxNetFlt: Failed to detect promiscuous count, all traffic may reach wire (%x != %x).\n", g_offIfNetPCount, offTry1));
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Start the kernel module.
|
---|
236 | */
|
---|
237 | static kern_return_t VBoxNetFltDarwinStart(struct kmod_info *pKModInfo, void *pvData)
|
---|
238 | {
|
---|
239 | int rc;
|
---|
240 |
|
---|
241 | /*
|
---|
242 | * Initialize IPRT and find our module tag id.
|
---|
243 | * (IPRT is shared with VBoxDrv, it creates the loggers.)
|
---|
244 | */
|
---|
245 | rc = RTR0Init(0);
|
---|
246 | if (RT_SUCCESS(rc))
|
---|
247 | {
|
---|
248 | Log(("VBoxNetFltDarwinStart\n"));
|
---|
249 | errno_t err = mbuf_tag_id_find("org.VirtualBox.kext.VBoxFltDrv", &g_idTag);
|
---|
250 | if (!err)
|
---|
251 | {
|
---|
252 | /*
|
---|
253 | * Initialize the globals and connect to the support driver.
|
---|
254 | *
|
---|
255 | * This will call back vboxNetFltOsOpenSupDrv (and maybe vboxNetFltOsCloseSupDrv)
|
---|
256 | * for establishing the connect to the support driver.
|
---|
257 | */
|
---|
258 | memset(&g_VBoxNetFltGlobals, 0, sizeof(g_VBoxNetFltGlobals));
|
---|
259 | rc = vboxNetFltInitGlobalsAndIdc(&g_VBoxNetFltGlobals);
|
---|
260 | if (RT_SUCCESS(rc))
|
---|
261 | {
|
---|
262 | LogRel(("VBoxFltDrv: version " VBOX_VERSION_STRING " r%d\n", VBOX_SVN_REV));
|
---|
263 | return KMOD_RETURN_SUCCESS;
|
---|
264 | }
|
---|
265 |
|
---|
266 | LogRel(("VBoxFltDrv: failed to initialize device extension (rc=%d)\n", rc));
|
---|
267 | }
|
---|
268 | else
|
---|
269 | LogRel(("VBoxFltDrv: mbuf_tag_id_find failed, err=%d\n", err));
|
---|
270 | RTR0Term();
|
---|
271 | }
|
---|
272 | else
|
---|
273 | printf("VBoxFltDrv: failed to initialize IPRT (rc=%d)\n", rc);
|
---|
274 |
|
---|
275 | memset(&g_VBoxNetFltGlobals, 0, sizeof(g_VBoxNetFltGlobals));
|
---|
276 | return KMOD_RETURN_FAILURE;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Stop the kernel module.
|
---|
282 | */
|
---|
283 | static kern_return_t VBoxNetFltDarwinStop(struct kmod_info *pKModInfo, void *pvData)
|
---|
284 | {
|
---|
285 | Log(("VBoxNetFltDarwinStop\n"));
|
---|
286 |
|
---|
287 | /*
|
---|
288 | * Refuse to unload if anyone is currently using the filter driver.
|
---|
289 | * This is important as I/O kit / xnu will to be able to do usage
|
---|
290 | * tracking for us!
|
---|
291 | */
|
---|
292 | int rc = vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltGlobals);
|
---|
293 | if (RT_FAILURE(rc))
|
---|
294 | {
|
---|
295 | Log(("VBoxNetFltDarwinStop - failed, busy.\n"));
|
---|
296 | return KMOD_RETURN_FAILURE;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /*
|
---|
300 | * Undo the work done during start (in reverse order).
|
---|
301 | */
|
---|
302 | memset(&g_VBoxNetFltGlobals, 0, sizeof(g_VBoxNetFltGlobals));
|
---|
303 |
|
---|
304 | RTR0Term();
|
---|
305 |
|
---|
306 | return KMOD_RETURN_SUCCESS;
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 | /**
|
---|
311 | * Reads and retains the host interface handle.
|
---|
312 | *
|
---|
313 | * @returns The handle, NULL if detached.
|
---|
314 | * @param pThis
|
---|
315 | */
|
---|
316 | DECLINLINE(ifnet_t) vboxNetFltDarwinRetainIfNet(PVBOXNETFLTINS pThis)
|
---|
317 | {
|
---|
318 | ifnet_t pIfNet = NULL;
|
---|
319 |
|
---|
320 | /*
|
---|
321 | * Be careful here to avoid problems racing the detached callback.
|
---|
322 | */
|
---|
323 | RTSpinlockAcquire(pThis->hSpinlock);
|
---|
324 | if (!ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost))
|
---|
325 | {
|
---|
326 | pIfNet = ASMAtomicUoReadPtrT(&pThis->u.s.pIfNet, ifnet_t);
|
---|
327 | if (pIfNet)
|
---|
328 | ifnet_reference(pIfNet);
|
---|
329 | }
|
---|
330 | RTSpinlockRelease(pThis->hSpinlock);
|
---|
331 |
|
---|
332 | return pIfNet;
|
---|
333 | }
|
---|
334 |
|
---|
335 |
|
---|
336 | /**
|
---|
337 | * Release the host interface handle previously retained
|
---|
338 | * by vboxNetFltDarwinRetainIfNet.
|
---|
339 | *
|
---|
340 | * @param pThis The instance.
|
---|
341 | * @param pIfNet The vboxNetFltDarwinRetainIfNet return value, NULL is fine.
|
---|
342 | */
|
---|
343 | DECLINLINE(void) vboxNetFltDarwinReleaseIfNet(PVBOXNETFLTINS pThis, ifnet_t pIfNet)
|
---|
344 | {
|
---|
345 | NOREF(pThis);
|
---|
346 | if (pIfNet)
|
---|
347 | ifnet_release(pIfNet);
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * Checks whether this is an mbuf created by vboxNetFltDarwinMBufFromSG,
|
---|
353 | * i.e. a buffer which we're pushing and should be ignored by the filter callbacks.
|
---|
354 | *
|
---|
355 | * @returns true / false accordingly.
|
---|
356 | * @param pThis The instance.
|
---|
357 | * @param pMBuf The mbuf.
|
---|
358 | * @param pvFrame The frame pointer, optional.
|
---|
359 | */
|
---|
360 | DECLINLINE(bool) vboxNetFltDarwinMBufIsOur(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame)
|
---|
361 | {
|
---|
362 | NOREF(pThis);
|
---|
363 |
|
---|
364 | /*
|
---|
365 | * Lookup the tag set by vboxNetFltDarwinMBufFromSG.
|
---|
366 | */
|
---|
367 | PCVBOXNETFLTTAG pTagData;
|
---|
368 | size_t cbTagData;
|
---|
369 | errno_t err = mbuf_tag_find(pMBuf, g_idTag, 0 /* type */, &cbTagData, (void **)&pTagData);
|
---|
370 | if (err)
|
---|
371 | return false;
|
---|
372 | AssertReturn(cbTagData == sizeof(*pTagData), false);
|
---|
373 |
|
---|
374 | /*
|
---|
375 | * Dig out the ethernet header from the mbuf.
|
---|
376 | */
|
---|
377 | PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pvFrame;
|
---|
378 | if (!pEthHdr)
|
---|
379 | pEthHdr = (PCRTNETETHERHDR)mbuf_pkthdr_header(pMBuf);
|
---|
380 | if (!pEthHdr)
|
---|
381 | pEthHdr = (PCRTNETETHERHDR)mbuf_data(pMBuf);
|
---|
382 | /* ASSUMING that there is enough data to work on! */
|
---|
383 | if ( pEthHdr->DstMac.au8[0] != pTagData->EthHdr.DstMac.au8[0]
|
---|
384 | || pEthHdr->DstMac.au8[1] != pTagData->EthHdr.DstMac.au8[1]
|
---|
385 | || pEthHdr->DstMac.au8[2] != pTagData->EthHdr.DstMac.au8[2]
|
---|
386 | || pEthHdr->DstMac.au8[3] != pTagData->EthHdr.DstMac.au8[3]
|
---|
387 | || pEthHdr->DstMac.au8[4] != pTagData->EthHdr.DstMac.au8[4]
|
---|
388 | || pEthHdr->DstMac.au8[5] != pTagData->EthHdr.DstMac.au8[5]
|
---|
389 | || pEthHdr->SrcMac.au8[0] != pTagData->EthHdr.SrcMac.au8[0]
|
---|
390 | || pEthHdr->SrcMac.au8[1] != pTagData->EthHdr.SrcMac.au8[1]
|
---|
391 | || pEthHdr->SrcMac.au8[2] != pTagData->EthHdr.SrcMac.au8[2]
|
---|
392 | || pEthHdr->SrcMac.au8[3] != pTagData->EthHdr.SrcMac.au8[3]
|
---|
393 | || pEthHdr->SrcMac.au8[4] != pTagData->EthHdr.SrcMac.au8[4]
|
---|
394 | || pEthHdr->SrcMac.au8[5] != pTagData->EthHdr.SrcMac.au8[5]
|
---|
395 | || pEthHdr->EtherType != pTagData->EthHdr.EtherType)
|
---|
396 | {
|
---|
397 | Log3(("tagged, but the ethernet header has changed\n"));
|
---|
398 | return false;
|
---|
399 | }
|
---|
400 |
|
---|
401 | return true;
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Internal worker that create a darwin mbuf for a (scatter/)gather list.
|
---|
407 | *
|
---|
408 | * @returns Pointer to the mbuf.
|
---|
409 | * @param pThis The instance.
|
---|
410 | * @param pSG The (scatter/)gather list.
|
---|
411 | */
|
---|
412 | static mbuf_t vboxNetFltDarwinMBufFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG)
|
---|
413 | {
|
---|
414 | /// @todo future? mbuf_how_t How = preemption enabled ? MBUF_DONTWAIT : MBUF_WAITOK;
|
---|
415 | mbuf_how_t How = MBUF_WAITOK;
|
---|
416 |
|
---|
417 | /*
|
---|
418 | * We need some way of getting back to our instance data when
|
---|
419 | * the mbuf is freed, so use pvUserData for this.
|
---|
420 | * -- this is not relevant anylonger! --
|
---|
421 | */
|
---|
422 | Assert(!pSG->pvUserData || pSG->pvUserData == pThis);
|
---|
423 | Assert(!pSG->pvUserData2);
|
---|
424 | pSG->pvUserData = pThis;
|
---|
425 |
|
---|
426 | /*
|
---|
427 | * Allocate a packet and copy over the data.
|
---|
428 | *
|
---|
429 | * Using mbuf_attachcluster() here would've been nice but there are two
|
---|
430 | * issues with it: (1) it's 10.5.x only, and (2) the documentation indicates
|
---|
431 | * that it's not supposed to be used for really external buffers. The 2nd
|
---|
432 | * point might be argued against considering that the only m_clattach user
|
---|
433 | * is mallocs memory for the ext mbuf and not doing what's stated in the docs.
|
---|
434 | * However, it's hard to tell if these m_clattach buffers actually makes it
|
---|
435 | * to the NICs or not, and even if they did, the NIC would need the physical
|
---|
436 | * addresses for the pages they contain and might end up copying the data
|
---|
437 | * to a new mbuf anyway.
|
---|
438 | *
|
---|
439 | * So, in the end it's better to just do it the simple way that will work
|
---|
440 | * 100%, even if it involves some extra work (alloc + copy) we really wished
|
---|
441 | * to avoid.
|
---|
442 | *
|
---|
443 | * Note. We can't make use of the physical addresses on darwin because the
|
---|
444 | * way the mbuf / cluster stuff works (see mbuf_data_to_physical and
|
---|
445 | * mcl_to_paddr).
|
---|
446 | */
|
---|
447 | mbuf_t pPkt = NULL;
|
---|
448 | errno_t err = mbuf_allocpacket(How, pSG->cbTotal, NULL, &pPkt);
|
---|
449 | if (!err)
|
---|
450 | {
|
---|
451 | /* Skip zero sized memory buffers (paranoia). */
|
---|
452 | mbuf_t pCur = pPkt;
|
---|
453 | while (pCur && !mbuf_maxlen(pCur))
|
---|
454 | pCur = mbuf_next(pCur);
|
---|
455 | Assert(pCur);
|
---|
456 |
|
---|
457 | /* Set the required packet header attributes. */
|
---|
458 | mbuf_pkthdr_setlen(pPkt, pSG->cbTotal);
|
---|
459 | mbuf_pkthdr_setheader(pPkt, mbuf_data(pCur));
|
---|
460 |
|
---|
461 | /* Special case the single buffer copy. */
|
---|
462 | if ( mbuf_next(pCur)
|
---|
463 | && mbuf_maxlen(pCur) >= pSG->cbTotal)
|
---|
464 | {
|
---|
465 | mbuf_setlen(pCur, pSG->cbTotal);
|
---|
466 | IntNetSgRead(pSG, mbuf_data(pCur));
|
---|
467 | }
|
---|
468 | else
|
---|
469 | {
|
---|
470 | /* Multi buffer copying. */
|
---|
471 | size_t cbLeft = pSG->cbTotal;
|
---|
472 | size_t offSrc = 0;
|
---|
473 | while (cbLeft > 0 && pCur)
|
---|
474 | {
|
---|
475 | size_t cb = mbuf_maxlen(pCur);
|
---|
476 | if (cb > cbLeft)
|
---|
477 | cb = cbLeft;
|
---|
478 | mbuf_setlen(pCur, cb);
|
---|
479 | IntNetSgReadEx(pSG, offSrc, cb, mbuf_data(pCur));
|
---|
480 |
|
---|
481 | /* advance */
|
---|
482 | offSrc += cb;
|
---|
483 | cbLeft -= cb;
|
---|
484 | pCur = mbuf_next(pCur);
|
---|
485 | }
|
---|
486 | Assert(cbLeft == 0);
|
---|
487 | }
|
---|
488 | if (!err)
|
---|
489 | {
|
---|
490 | /*
|
---|
491 | * Tag the packet and return successfully.
|
---|
492 | */
|
---|
493 | PVBOXNETFLTTAG pTagData;
|
---|
494 | err = mbuf_tag_allocate(pPkt, g_idTag, 0 /* type */, sizeof(VBOXNETFLTTAG) /* tag len */, How, (void **)&pTagData);
|
---|
495 | if (!err)
|
---|
496 | {
|
---|
497 | Assert(pSG->aSegs[0].cb >= sizeof(pTagData->EthHdr));
|
---|
498 | memcpy(&pTagData->EthHdr, pSG->aSegs[0].pv, sizeof(pTagData->EthHdr));
|
---|
499 | return pPkt;
|
---|
500 | }
|
---|
501 |
|
---|
502 | /* bailout: */
|
---|
503 | AssertMsg(err == ENOMEM || err == EWOULDBLOCK, ("err=%d\n", err));
|
---|
504 | }
|
---|
505 |
|
---|
506 | mbuf_freem(pPkt);
|
---|
507 | }
|
---|
508 | else
|
---|
509 | AssertMsg(err == ENOMEM || err == EWOULDBLOCK, ("err=%d\n", err));
|
---|
510 | pSG->pvUserData = NULL;
|
---|
511 |
|
---|
512 | return NULL;
|
---|
513 | }
|
---|
514 |
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Calculates the number of segments required to represent the mbuf.
|
---|
518 | *
|
---|
519 | * @returns Number of segments.
|
---|
520 | * @param pThis The instance.
|
---|
521 | * @param pMBuf The mbuf.
|
---|
522 | * @param pvFrame The frame pointer, optional.
|
---|
523 | */
|
---|
524 | DECLINLINE(unsigned) vboxNetFltDarwinMBufCalcSGSegs(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame)
|
---|
525 | {
|
---|
526 | NOREF(pThis);
|
---|
527 |
|
---|
528 | /*
|
---|
529 | * Count the buffers in the chain.
|
---|
530 | */
|
---|
531 | unsigned cSegs = 0;
|
---|
532 | for (mbuf_t pCur = pMBuf; pCur; pCur = mbuf_next(pCur))
|
---|
533 | if (mbuf_len(pCur))
|
---|
534 | cSegs++;
|
---|
535 | else if ( !cSegs
|
---|
536 | && pvFrame
|
---|
537 | && (uintptr_t)pvFrame - (uintptr_t)mbuf_datastart(pMBuf) < mbuf_maxlen(pMBuf))
|
---|
538 | cSegs++;
|
---|
539 |
|
---|
540 | #ifdef PADD_RUNT_FRAMES_FROM_HOST
|
---|
541 | /*
|
---|
542 | * Add one buffer if the total is less than the ethernet minimum 60 bytes.
|
---|
543 | * This may allocate a segment too much if the ethernet header is separated,
|
---|
544 | * but that shouldn't harm us much.
|
---|
545 | */
|
---|
546 | if (mbuf_pkthdr_len(pMBuf) < 60)
|
---|
547 | cSegs++;
|
---|
548 | #endif
|
---|
549 |
|
---|
550 | #ifdef VBOXNETFLT_DARWIN_TEST_SEG_SIZE
|
---|
551 | /* maximize the number of segments. */
|
---|
552 | cSegs = RT_MAX(VBOXNETFLT_DARWIN_MAX_SEGS - 1, cSegs);
|
---|
553 | #endif
|
---|
554 |
|
---|
555 | return cSegs ? cSegs : 1;
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 | /**
|
---|
560 | * Initializes a SG list from an mbuf.
|
---|
561 | *
|
---|
562 | * @returns Number of segments.
|
---|
563 | * @param pThis The instance.
|
---|
564 | * @param pMBuf The mbuf.
|
---|
565 | * @param pSG The SG.
|
---|
566 | * @param pvFrame The frame pointer, optional.
|
---|
567 | * @param cSegs The number of segments allocated for the SG.
|
---|
568 | * This should match the number in the mbuf exactly!
|
---|
569 | * @param fSrc The source of the frame.
|
---|
570 | */
|
---|
571 | DECLINLINE(void) vboxNetFltDarwinMBufToSG(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc)
|
---|
572 | {
|
---|
573 | NOREF(pThis);
|
---|
574 |
|
---|
575 | /*
|
---|
576 | * Walk the chain and convert the buffers to segments. Works INTNETSG::cbTotal.
|
---|
577 | */
|
---|
578 | unsigned iSeg = 0;
|
---|
579 | IntNetSgInitTempSegs(pSG, 0 /*cbTotal*/, cSegs, 0 /*cSegsUsed*/);
|
---|
580 | for (mbuf_t pCur = pMBuf; pCur; pCur = mbuf_next(pCur))
|
---|
581 | {
|
---|
582 | size_t cbSeg = mbuf_len(pCur);
|
---|
583 | if (cbSeg)
|
---|
584 | {
|
---|
585 | void *pvSeg = mbuf_data(pCur);
|
---|
586 |
|
---|
587 | /* deal with pvFrame */
|
---|
588 | if (!iSeg && pvFrame && pvFrame != pvSeg)
|
---|
589 | {
|
---|
590 | void *pvStart = mbuf_datastart(pMBuf);
|
---|
591 | uintptr_t offSeg = (uintptr_t)pvSeg - (uintptr_t)pvStart;
|
---|
592 | uintptr_t offSegEnd = offSeg + cbSeg;
|
---|
593 | Assert(pvStart && pvSeg && offSeg < mbuf_maxlen(pMBuf) && offSegEnd <= mbuf_maxlen(pMBuf)); NOREF(offSegEnd);
|
---|
594 | uintptr_t offFrame = (uintptr_t)pvFrame - (uintptr_t)pvStart;
|
---|
595 | if (RT_LIKELY(offFrame < offSeg))
|
---|
596 | {
|
---|
597 | pvSeg = pvFrame;
|
---|
598 | cbSeg += offSeg - offFrame;
|
---|
599 | }
|
---|
600 | else
|
---|
601 | AssertMsgFailed(("pvFrame=%p pvStart=%p pvSeg=%p offSeg=%p cbSeg=%#zx offSegEnd=%p offFrame=%p maxlen=%#zx\n",
|
---|
602 | pvFrame, pvStart, pvSeg, offSeg, cbSeg, offSegEnd, offFrame, mbuf_maxlen(pMBuf)));
|
---|
603 | pvFrame = NULL;
|
---|
604 | }
|
---|
605 |
|
---|
606 | AssertBreak(iSeg < cSegs);
|
---|
607 | pSG->cbTotal += cbSeg;
|
---|
608 | pSG->aSegs[iSeg].cb = cbSeg;
|
---|
609 | pSG->aSegs[iSeg].pv = pvSeg;
|
---|
610 | pSG->aSegs[iSeg].Phys = NIL_RTHCPHYS;
|
---|
611 | iSeg++;
|
---|
612 | }
|
---|
613 | /* The pvFrame might be in a now empty buffer. */
|
---|
614 | else if ( !iSeg
|
---|
615 | && pvFrame
|
---|
616 | && (uintptr_t)pvFrame - (uintptr_t)mbuf_datastart(pMBuf) < mbuf_maxlen(pMBuf))
|
---|
617 | {
|
---|
618 | cbSeg = (uintptr_t)mbuf_datastart(pMBuf) + mbuf_maxlen(pMBuf) - (uintptr_t)pvFrame;
|
---|
619 | pSG->cbTotal += cbSeg;
|
---|
620 | pSG->aSegs[iSeg].cb = cbSeg;
|
---|
621 | pSG->aSegs[iSeg].pv = pvFrame;
|
---|
622 | pSG->aSegs[iSeg].Phys = NIL_RTHCPHYS;
|
---|
623 | iSeg++;
|
---|
624 | pvFrame = NULL;
|
---|
625 | }
|
---|
626 | }
|
---|
627 |
|
---|
628 | Assert(iSeg && iSeg <= cSegs);
|
---|
629 | pSG->cSegsUsed = iSeg;
|
---|
630 |
|
---|
631 | #ifdef PADD_RUNT_FRAMES_FROM_HOST
|
---|
632 | /*
|
---|
633 | * Add a trailer if the frame is too small.
|
---|
634 | *
|
---|
635 | * Since we're getting to the packet before it is framed, it has not
|
---|
636 | * yet been padded. The current solution is to add a segment pointing
|
---|
637 | * to a buffer containing all zeros and pray that works for all frames...
|
---|
638 | */
|
---|
639 | if (pSG->cbTotal < 60 && (fSrc == INTNETTRUNKDIR_HOST))
|
---|
640 | {
|
---|
641 | AssertReturnVoid(iSeg < cSegs);
|
---|
642 |
|
---|
643 | static uint8_t const s_abZero[128] = {0};
|
---|
644 | pSG->aSegs[iSeg].Phys = NIL_RTHCPHYS;
|
---|
645 | pSG->aSegs[iSeg].pv = (void *)&s_abZero[0];
|
---|
646 | pSG->aSegs[iSeg].cb = 60 - pSG->cbTotal;
|
---|
647 | pSG->cbTotal = 60;
|
---|
648 | pSG->cSegsUsed++;
|
---|
649 | }
|
---|
650 | #endif
|
---|
651 |
|
---|
652 | #ifdef VBOXNETFLT_DARWIN_TEST_SEG_SIZE
|
---|
653 | /*
|
---|
654 | * Redistribute the segments.
|
---|
655 | */
|
---|
656 | if (pSG->cSegsUsed < pSG->cSegsAlloc)
|
---|
657 | {
|
---|
658 | /* copy the segments to the end. */
|
---|
659 | int iSrc = pSG->cSegsUsed;
|
---|
660 | int iDst = pSG->cSegsAlloc;
|
---|
661 | while (iSrc > 0)
|
---|
662 | {
|
---|
663 | iDst--;
|
---|
664 | iSrc--;
|
---|
665 | pSG->aSegs[iDst] = pSG->aSegs[iSrc];
|
---|
666 | }
|
---|
667 |
|
---|
668 | /* create small segments from the start. */
|
---|
669 | pSG->cSegsUsed = pSG->cSegsAlloc;
|
---|
670 | iSrc = iDst;
|
---|
671 | iDst = 0;
|
---|
672 | while ( iDst < iSrc
|
---|
673 | && iDst < pSG->cSegsAlloc)
|
---|
674 | {
|
---|
675 | pSG->aSegs[iDst].Phys = NIL_RTHCPHYS;
|
---|
676 | pSG->aSegs[iDst].pv = pSG->aSegs[iSrc].pv;
|
---|
677 | pSG->aSegs[iDst].cb = RT_MIN(pSG->aSegs[iSrc].cb, VBOXNETFLT_DARWIN_TEST_SEG_SIZE);
|
---|
678 | if (pSG->aSegs[iDst].cb != pSG->aSegs[iSrc].cb)
|
---|
679 | {
|
---|
680 | pSG->aSegs[iSrc].cb -= pSG->aSegs[iDst].cb;
|
---|
681 | pSG->aSegs[iSrc].pv = (uint8_t *)pSG->aSegs[iSrc].pv + pSG->aSegs[iDst].cb;
|
---|
682 | }
|
---|
683 | else if (++iSrc >= pSG->cSegsAlloc)
|
---|
684 | {
|
---|
685 | pSG->cSegsUsed = iDst + 1;
|
---|
686 | break;
|
---|
687 | }
|
---|
688 | iDst++;
|
---|
689 | }
|
---|
690 | }
|
---|
691 | #endif
|
---|
692 |
|
---|
693 | AssertMsg(!pvFrame, ("pvFrame=%p pMBuf=%p iSeg=%d\n", pvFrame, pMBuf, iSeg));
|
---|
694 | }
|
---|
695 |
|
---|
696 |
|
---|
697 | /**
|
---|
698 | * Helper for determining whether the host wants the interface to be
|
---|
699 | * promiscuous.
|
---|
700 | */
|
---|
701 | static bool vboxNetFltDarwinIsPromiscuous(PVBOXNETFLTINS pThis)
|
---|
702 | {
|
---|
703 | bool fRc = false;
|
---|
704 | ifnet_t pIfNet = vboxNetFltDarwinRetainIfNet(pThis);
|
---|
705 | if (pIfNet)
|
---|
706 | {
|
---|
707 | /* gather the data */
|
---|
708 | uint16_t fIf = ifnet_flags(pIfNet);
|
---|
709 | unsigned cPromisc = VBOX_GET_PCOUNT(pIfNet);
|
---|
710 | bool fSetPromiscuous = ASMAtomicUoReadBool(&pThis->u.s.fSetPromiscuous);
|
---|
711 | vboxNetFltDarwinReleaseIfNet(pThis, pIfNet);
|
---|
712 |
|
---|
713 | /* calc the return. */
|
---|
714 | fRc = (fIf & IFF_PROMISC)
|
---|
715 | && cPromisc > fSetPromiscuous;
|
---|
716 | }
|
---|
717 | return fRc;
|
---|
718 | }
|
---|
719 |
|
---|
720 |
|
---|
721 |
|
---|
722 | /**
|
---|
723 | *
|
---|
724 | * @see iff_detached_func in the darwin kpi.
|
---|
725 | */
|
---|
726 | static void vboxNetFltDarwinIffDetached(void *pvThis, ifnet_t pIfNet)
|
---|
727 | {
|
---|
728 | PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvThis;
|
---|
729 | uint64_t NanoTS = RTTimeSystemNanoTS();
|
---|
730 | LogFlow(("vboxNetFltDarwinIffDetached: pThis=%p NanoTS=%RU64 (%d)\n",
|
---|
731 | pThis, NanoTS, VALID_PTR(pIfNet) ? VBOX_GET_PCOUNT(pIfNet) : -1));
|
---|
732 |
|
---|
733 | Assert(!pThis->fDisconnectedFromHost);
|
---|
734 | Assert(!pThis->fRediscoveryPending);
|
---|
735 |
|
---|
736 | /*
|
---|
737 | * If we've put it into promiscuous mode, undo that now. If we don't
|
---|
738 | * the if_pcount will go all wrong when it's replugged.
|
---|
739 | */
|
---|
740 | if (ASMAtomicXchgBool(&pThis->u.s.fSetPromiscuous, false))
|
---|
741 | ifnet_set_promiscuous(pIfNet, 0);
|
---|
742 |
|
---|
743 | /*
|
---|
744 | * We carefully take the spinlock and increase the interface reference
|
---|
745 | * behind it in order to avoid problematic races with the detached callback.
|
---|
746 | */
|
---|
747 | RTSpinlockAcquire(pThis->hSpinlock);
|
---|
748 |
|
---|
749 | pIfNet = ASMAtomicUoReadPtrT(&pThis->u.s.pIfNet, ifnet_t);
|
---|
750 | int cPromisc = VALID_PTR(pIfNet) ? VBOX_GET_PCOUNT(pIfNet) : - 1;
|
---|
751 |
|
---|
752 | ASMAtomicUoWriteNullPtr(&pThis->u.s.pIfNet);
|
---|
753 | ASMAtomicUoWriteNullPtr(&pThis->u.s.pIfFilter);
|
---|
754 | ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false);
|
---|
755 | pThis->u.s.fSetPromiscuous = false;
|
---|
756 | ASMAtomicUoWriteU64(&pThis->NanoTSLastRediscovery, NanoTS);
|
---|
757 | ASMAtomicUoWriteBool(&pThis->fRediscoveryPending, false);
|
---|
758 | ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, true);
|
---|
759 |
|
---|
760 | RTSpinlockRelease(pThis->hSpinlock);
|
---|
761 |
|
---|
762 | if (pIfNet)
|
---|
763 | ifnet_release(pIfNet);
|
---|
764 | LogRel(("VBoxNetFlt: was detached from '%s' (%d)\n", pThis->szName, cPromisc));
|
---|
765 | }
|
---|
766 |
|
---|
767 |
|
---|
768 | /**
|
---|
769 | *
|
---|
770 | * @see iff_ioctl_func in the darwin kpi.
|
---|
771 | */
|
---|
772 | static errno_t vboxNetFltDarwinIffIoCtl(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, u_long uCmd, void *pvArg)
|
---|
773 | {
|
---|
774 | PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvThis;
|
---|
775 | LogFlow(("vboxNetFltDarwinIffIoCtl: pThis=%p uCmd=%lx\n", pThis, uCmd));
|
---|
776 |
|
---|
777 | /*
|
---|
778 | * Update fOtherPromiscuous.
|
---|
779 | */
|
---|
780 | /** @todo we'll have to find the offset of if_pcount to get this right! */
|
---|
781 | //if (uCmd == SIOCSIFFLAGS)
|
---|
782 | //{
|
---|
783 | //
|
---|
784 | //}
|
---|
785 |
|
---|
786 | /*
|
---|
787 | * We didn't handle it, continue processing.
|
---|
788 | */
|
---|
789 | NOREF(pThis);
|
---|
790 | NOREF(eProtocol);
|
---|
791 | NOREF(uCmd);
|
---|
792 | NOREF(pvArg);
|
---|
793 | return EOPNOTSUPP;
|
---|
794 | }
|
---|
795 |
|
---|
796 |
|
---|
797 | /**
|
---|
798 | *
|
---|
799 | * @see iff_event_func in the darwin kpi.
|
---|
800 | */
|
---|
801 | static void vboxNetFltDarwinIffEvent(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, const struct kev_msg *pEvMsg)
|
---|
802 | {
|
---|
803 | PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvThis;
|
---|
804 | LogFlow(("vboxNetFltDarwinIffEvent: pThis=%p\n", pThis));
|
---|
805 |
|
---|
806 | NOREF(pThis);
|
---|
807 | NOREF(pIfNet);
|
---|
808 | NOREF(eProtocol);
|
---|
809 | NOREF(pEvMsg);
|
---|
810 |
|
---|
811 | /*
|
---|
812 | * Watch out for the interface going online / offline.
|
---|
813 | */
|
---|
814 | if ( VALID_PTR(pThis)
|
---|
815 | && VALID_PTR(pEvMsg)
|
---|
816 | && pEvMsg->vendor_code == KEV_VENDOR_APPLE
|
---|
817 | && pEvMsg->kev_class == KEV_NETWORK_CLASS
|
---|
818 | && pEvMsg->kev_subclass == KEV_DL_SUBCLASS)
|
---|
819 | {
|
---|
820 | if (pThis->u.s.pIfNet == pIfNet)
|
---|
821 | {
|
---|
822 | if (pEvMsg->event_code == KEV_DL_LINK_ON)
|
---|
823 | {
|
---|
824 | if (ASMAtomicUoReadBool(&pThis->u.s.fNeedSetPromiscuous))
|
---|
825 | {
|
---|
826 | /* failed to bring it online. */
|
---|
827 | errno_t err = ifnet_set_promiscuous(pIfNet, 1);
|
---|
828 | if (!err)
|
---|
829 | {
|
---|
830 | ASMAtomicWriteBool(&pThis->u.s.fSetPromiscuous, true);
|
---|
831 | ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false);
|
---|
832 | Log(("vboxNetFltDarwinIffEvent: enabled promiscuous mode on %s (%d)\n", pThis->szName, VBOX_GET_PCOUNT(pIfNet)));
|
---|
833 | }
|
---|
834 | else
|
---|
835 | Log(("vboxNetFltDarwinIffEvent: ifnet_set_promiscuous failed on %s, err=%d (%d)\n", pThis->szName, err, VBOX_GET_PCOUNT(pIfNet)));
|
---|
836 | }
|
---|
837 | else if ( ASMAtomicUoReadBool(&pThis->u.s.fSetPromiscuous)
|
---|
838 | && !(ifnet_flags(pIfNet) & IFF_PROMISC))
|
---|
839 | {
|
---|
840 | /* Try fix the inconsistency. */
|
---|
841 | errno_t err = ifnet_set_flags(pIfNet, IFF_PROMISC, IFF_PROMISC);
|
---|
842 | if (!err)
|
---|
843 | err = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL);
|
---|
844 | if (!err && (ifnet_flags(pIfNet) & IFF_PROMISC))
|
---|
845 | Log(("vboxNetFltDarwinIffEvent: fixed IFF_PROMISC on %s (%d)\n", pThis->szName, VBOX_GET_PCOUNT(pIfNet)));
|
---|
846 | else
|
---|
847 | Log(("vboxNetFltDarwinIffEvent: failed to fix IFF_PROMISC on %s, err=%d flags=%#x (%d)\n",
|
---|
848 | pThis->szName, err, ifnet_flags(pIfNet), VBOX_GET_PCOUNT(pIfNet)));
|
---|
849 | }
|
---|
850 | else
|
---|
851 | Log(("vboxNetFltDarwinIffEvent: online, '%s'. flags=%#x (%d)\n", pThis->szName, ifnet_flags(pIfNet), VBOX_GET_PCOUNT(pIfNet)));
|
---|
852 | }
|
---|
853 | else if (pEvMsg->event_code == KEV_DL_LINK_OFF)
|
---|
854 | Log(("vboxNetFltDarwinIffEvent: %s goes down (%d)\n", pThis->szName, VBOX_GET_PCOUNT(pIfNet)));
|
---|
855 | /** @todo KEV_DL_LINK_ADDRESS_CHANGED -> pfnReportMacAddress */
|
---|
856 | /** @todo KEV_DL_SIFFLAGS -> pfnReportPromiscuousMode */
|
---|
857 | }
|
---|
858 | else
|
---|
859 | Log(("vboxNetFltDarwinIffEvent: pThis->u.s.pIfNet=%p pIfNet=%p (%d)\n", pThis->u.s.pIfNet, pIfNet, VALID_PTR(pIfNet) ? VBOX_GET_PCOUNT(pIfNet) : -1));
|
---|
860 | }
|
---|
861 | else if (VALID_PTR(pEvMsg))
|
---|
862 | Log(("vboxNetFltDarwinIffEvent: vendor_code=%#x kev_class=%#x kev_subclass=%#x event_code=%#x\n",
|
---|
863 | pEvMsg->vendor_code, pEvMsg->kev_class, pEvMsg->kev_subclass, pEvMsg->event_code));
|
---|
864 | }
|
---|
865 |
|
---|
866 |
|
---|
867 | /**
|
---|
868 | * Internal worker for vboxNetFltDarwinIffInput and vboxNetFltDarwinIffOutput,
|
---|
869 | *
|
---|
870 | * @returns 0 or EJUSTRETURN.
|
---|
871 | * @param pThis The instance.
|
---|
872 | * @param pMBuf The mbuf.
|
---|
873 | * @param pvFrame The start of the frame, optional.
|
---|
874 | * @param fSrc Where the packet (allegedly) comes from, one INTNETTRUNKDIR_* value.
|
---|
875 | * @param eProtocol The protocol.
|
---|
876 | */
|
---|
877 | static errno_t vboxNetFltDarwinIffInputOutputWorker(PVBOXNETFLTINS pThis, mbuf_t pMBuf, void *pvFrame,
|
---|
878 | uint32_t fSrc, protocol_family_t eProtocol)
|
---|
879 | {
|
---|
880 | /*
|
---|
881 | * Drop it immediately?
|
---|
882 | */
|
---|
883 | Log2(("vboxNetFltDarwinIffInputOutputWorker: pThis=%p pMBuf=%p pvFrame=%p fSrc=%#x cbPkt=%x\n",
|
---|
884 | pThis, pMBuf, pvFrame, fSrc, pMBuf ? mbuf_pkthdr_len(pMBuf) : -1));
|
---|
885 | if (!pMBuf)
|
---|
886 | return 0;
|
---|
887 | #if 0 /* debugging lost icmp packets */
|
---|
888 | if (mbuf_pkthdr_len(pMBuf) > 0x300)
|
---|
889 | {
|
---|
890 | uint8_t *pb = (uint8_t *)(pvFrame ? pvFrame : mbuf_data(pMBuf));
|
---|
891 | Log3(("D=%.6Rhxs S=%.6Rhxs T=%04x IFF\n", pb, pb + 6, RT_BE2H_U16(*(uint16_t *)(pb + 12))));
|
---|
892 | }
|
---|
893 | #endif
|
---|
894 | if (vboxNetFltDarwinMBufIsOur(pThis, pMBuf, pvFrame))
|
---|
895 | return 0;
|
---|
896 |
|
---|
897 | /*
|
---|
898 | * Active? Retain the instance and increment the busy counter.
|
---|
899 | */
|
---|
900 | if (!vboxNetFltTryRetainBusyActive(pThis))
|
---|
901 | return 0;
|
---|
902 |
|
---|
903 | /*
|
---|
904 | * Finalize out-bound packets since the stack puts off finalizing
|
---|
905 | * TCP/IP checksums as long as possible.
|
---|
906 | * ASSUMES this only applies to outbound IP packets.
|
---|
907 | */
|
---|
908 | if ( (fSrc == INTNETTRUNKDIR_HOST)
|
---|
909 | && eProtocol == PF_INET)
|
---|
910 | {
|
---|
911 | Assert(!pvFrame);
|
---|
912 | mbuf_outbound_finalize(pMBuf, eProtocol, sizeof(RTNETETHERHDR));
|
---|
913 | }
|
---|
914 |
|
---|
915 | /*
|
---|
916 | * Create a (scatter/)gather list for the mbuf and feed it to the internal network.
|
---|
917 | */
|
---|
918 | bool fDropIt = false;
|
---|
919 | unsigned cSegs = vboxNetFltDarwinMBufCalcSGSegs(pThis, pMBuf, pvFrame);
|
---|
920 | if (cSegs < VBOXNETFLT_DARWIN_MAX_SEGS)
|
---|
921 | {
|
---|
922 | PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
|
---|
923 | vboxNetFltDarwinMBufToSG(pThis, pMBuf, pvFrame, pSG, cSegs, fSrc);
|
---|
924 |
|
---|
925 | fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, fSrc);
|
---|
926 | if (fDropIt)
|
---|
927 | {
|
---|
928 | /*
|
---|
929 | * If the interface is in promiscuous mode we should let
|
---|
930 | * all inbound packets (this one was for a bridged guest)
|
---|
931 | * reach the driver as it passes them to tap callbacks in
|
---|
932 | * order for BPF to work properly.
|
---|
933 | */
|
---|
934 | if ( fSrc == INTNETTRUNKDIR_WIRE
|
---|
935 | && vboxNetFltDarwinIsPromiscuous(pThis))
|
---|
936 | {
|
---|
937 | fDropIt = false;
|
---|
938 | }
|
---|
939 |
|
---|
940 | /*
|
---|
941 | * A packet from the host to a guest. As we won't pass it
|
---|
942 | * to the drvier/wire we need to feed it to bpf ourselves.
|
---|
943 | *
|
---|
944 | * XXX: TODO: bpf should be done before; use pfnPreRecv?
|
---|
945 | */
|
---|
946 | if (fSrc == INTNETTRUNKDIR_HOST)
|
---|
947 | {
|
---|
948 | bpf_tap_out(pThis->u.s.pIfNet, DLT_EN10MB, pMBuf, NULL, 0);
|
---|
949 | ifnet_stat_increment_out(pThis->u.s.pIfNet, 1, mbuf_len(pMBuf), 0);
|
---|
950 | }
|
---|
951 | }
|
---|
952 | }
|
---|
953 |
|
---|
954 | vboxNetFltRelease(pThis, true /* fBusy */);
|
---|
955 |
|
---|
956 | if (fDropIt)
|
---|
957 | {
|
---|
958 | mbuf_freem(pMBuf);
|
---|
959 | return EJUSTRETURN;
|
---|
960 | }
|
---|
961 | return 0;
|
---|
962 | }
|
---|
963 |
|
---|
964 |
|
---|
965 | /**
|
---|
966 | * From the host.
|
---|
967 | *
|
---|
968 | * @see iff_output_func in the darwin kpi.
|
---|
969 | */
|
---|
970 | static errno_t vboxNetFltDarwinIffOutput(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, mbuf_t *ppMBuf)
|
---|
971 | {
|
---|
972 | /** @todo there was some note about the ethernet header here or something like that... */
|
---|
973 |
|
---|
974 | NOREF(eProtocol);
|
---|
975 | NOREF(pIfNet);
|
---|
976 | return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, NULL, INTNETTRUNKDIR_HOST, eProtocol);
|
---|
977 | }
|
---|
978 |
|
---|
979 |
|
---|
980 | /**
|
---|
981 | * From the wire.
|
---|
982 | *
|
---|
983 | * @see iff_input_func in the darwin kpi.
|
---|
984 | */
|
---|
985 | static errno_t vboxNetFltDarwinIffInput(void *pvThis, ifnet_t pIfNet, protocol_family_t eProtocol, mbuf_t *ppMBuf, char **ppchFrame)
|
---|
986 | {
|
---|
987 | NOREF(eProtocol);
|
---|
988 | NOREF(pIfNet);
|
---|
989 | return vboxNetFltDarwinIffInputOutputWorker((PVBOXNETFLTINS)pvThis, *ppMBuf, *ppchFrame, INTNETTRUNKDIR_WIRE, eProtocol);
|
---|
990 | }
|
---|
991 |
|
---|
992 |
|
---|
993 | /** A worker thread for vboxNetFltSendDummy(). */
|
---|
994 | static DECLCALLBACK(int) vboxNetFltSendDummyWorker(RTTHREAD hThreadSelf, void *pvUser)
|
---|
995 | {
|
---|
996 | Assert(pvUser);
|
---|
997 | ifnet_t pIfNet = (ifnet_t)pvUser;
|
---|
998 | return VBoxNetSendDummy(pIfNet);
|
---|
999 | }
|
---|
1000 |
|
---|
1001 |
|
---|
1002 | /**
|
---|
1003 | * Prevent GUI icon freeze issue when VirtualBoxVM process terminates.
|
---|
1004 | *
|
---|
1005 | * This function is a workaround for stuck-in-dock issue. The idea here is to
|
---|
1006 | * send a dummy packet to an interface from the context of a kernel thread.
|
---|
1007 | * Therefore, an XNU's receive thread (which is created as a result if we are
|
---|
1008 | * the first who is communicating with the interface) will be associated with
|
---|
1009 | * the kernel thread instead of VirtualBoxVM process.
|
---|
1010 | *
|
---|
1011 | * @param pIfNet Interface to be used to send data.
|
---|
1012 | */
|
---|
1013 | static void vboxNetFltSendDummy(ifnet_t pIfNet)
|
---|
1014 | {
|
---|
1015 | RTTHREAD hThread;
|
---|
1016 | int rc = RTThreadCreate(&hThread, vboxNetFltSendDummyWorker, (void *)pIfNet, 0,
|
---|
1017 | RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "DummyThread");
|
---|
1018 | if (RT_SUCCESS(rc))
|
---|
1019 | {
|
---|
1020 | RTThreadWait(hThread, RT_INDEFINITE_WAIT, NULL);
|
---|
1021 | LogFlow(("vboxNetFltSendDummy: a dummy packet has been successfully sent in order to prevent stuck-in-dock issue\n"));
|
---|
1022 | }
|
---|
1023 | else
|
---|
1024 | LogFlow(("vboxNetFltSendDummy: unable to send dummy packet in order to prevent stuck-in-dock issue\n"));
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 |
|
---|
1028 | /**
|
---|
1029 | * Internal worker for vboxNetFltOsInitInstance and vboxNetFltOsMaybeRediscovered.
|
---|
1030 | *
|
---|
1031 | * @returns VBox status code.
|
---|
1032 | * @param pThis The instance.
|
---|
1033 | * @param fRediscovery If set we're doing a rediscovery attempt, so, don't
|
---|
1034 | * flood the release log.
|
---|
1035 | */
|
---|
1036 | static int vboxNetFltDarwinAttachToInterface(PVBOXNETFLTINS pThis, bool fRediscovery)
|
---|
1037 | {
|
---|
1038 | LogFlow(("vboxNetFltDarwinAttachToInterface: pThis=%p (%s)\n", pThis, pThis->szName));
|
---|
1039 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
1040 |
|
---|
1041 | /*
|
---|
1042 | * Locate the interface first.
|
---|
1043 | *
|
---|
1044 | * The pIfNet member is updated before iflt_attach is called and used
|
---|
1045 | * to deal with the hypothetical case where someone rips out the
|
---|
1046 | * interface immediately after our iflt_attach call.
|
---|
1047 | */
|
---|
1048 | ifnet_t pIfNet = NULL;
|
---|
1049 | errno_t err = ifnet_find_by_name(pThis->szName, &pIfNet);
|
---|
1050 | if (err)
|
---|
1051 | {
|
---|
1052 | Assert(err == ENXIO);
|
---|
1053 | if (!fRediscovery)
|
---|
1054 | LogRel(("VBoxFltDrv: failed to find ifnet '%s' (err=%d)\n", pThis->szName, err));
|
---|
1055 | else
|
---|
1056 | Log(("VBoxFltDrv: failed to find ifnet '%s' (err=%d)\n", pThis->szName, err));
|
---|
1057 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1058 | return VERR_INTNET_FLT_IF_NOT_FOUND;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | RTSpinlockAcquire(pThis->hSpinlock);
|
---|
1062 | ASMAtomicUoWritePtr(&pThis->u.s.pIfNet, pIfNet);
|
---|
1063 | RTSpinlockRelease(pThis->hSpinlock);
|
---|
1064 |
|
---|
1065 | /* Adjust g_offIfNetPCount as it varies for different versions of xnu. */
|
---|
1066 | vboxNetFltDarwinDetectPCountOffset(pIfNet);
|
---|
1067 |
|
---|
1068 | /* Prevent stuck-in-dock issue by associating interface receive thread with kernel thread. */
|
---|
1069 | vboxNetFltSendDummy(pIfNet);
|
---|
1070 |
|
---|
1071 | /*
|
---|
1072 | * Get the mac address while we still have a valid ifnet reference.
|
---|
1073 | */
|
---|
1074 | err = ifnet_lladdr_copy_bytes(pIfNet, &pThis->u.s.MacAddr, sizeof(pThis->u.s.MacAddr));
|
---|
1075 | if (!err)
|
---|
1076 | {
|
---|
1077 | /*
|
---|
1078 | * Try attach the filter.
|
---|
1079 | */
|
---|
1080 | struct iff_filter RegRec;
|
---|
1081 | RegRec.iff_cookie = pThis;
|
---|
1082 | RegRec.iff_name = "VBoxNetFlt";
|
---|
1083 | RegRec.iff_protocol = 0;
|
---|
1084 | RegRec.iff_input = vboxNetFltDarwinIffInput;
|
---|
1085 | RegRec.iff_output = vboxNetFltDarwinIffOutput;
|
---|
1086 | RegRec.iff_event = vboxNetFltDarwinIffEvent;
|
---|
1087 | RegRec.iff_ioctl = vboxNetFltDarwinIffIoCtl;
|
---|
1088 | RegRec.iff_detached = vboxNetFltDarwinIffDetached;
|
---|
1089 | interface_filter_t pIfFilter = NULL;
|
---|
1090 | err = iflt_attach(pIfNet, &RegRec, &pIfFilter);
|
---|
1091 | Assert(err || pIfFilter);
|
---|
1092 |
|
---|
1093 | RTSpinlockAcquire(pThis->hSpinlock);
|
---|
1094 | pIfNet = ASMAtomicUoReadPtrT(&pThis->u.s.pIfNet, ifnet_t);
|
---|
1095 | if (pIfNet && !err)
|
---|
1096 | {
|
---|
1097 | ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, false);
|
---|
1098 | ASMAtomicUoWritePtr(&pThis->u.s.pIfFilter, pIfFilter);
|
---|
1099 | pIfNet = NULL; /* don't dereference it */
|
---|
1100 | }
|
---|
1101 | RTSpinlockRelease(pThis->hSpinlock);
|
---|
1102 |
|
---|
1103 | /* Report capabilities. */
|
---|
1104 | if ( !pIfNet
|
---|
1105 | && vboxNetFltTryRetainBusyNotDisconnected(pThis))
|
---|
1106 | {
|
---|
1107 | Assert(pThis->pSwitchPort);
|
---|
1108 | pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr);
|
---|
1109 | #if 0
|
---|
1110 | /*
|
---|
1111 | * XXX: Don't tell SrvIntNetR0 if the interface is
|
---|
1112 | * promiscuous, because there's no code yet to update that
|
---|
1113 | * information and we don't want it stuck, spamming all
|
---|
1114 | * traffic to the host.
|
---|
1115 | */
|
---|
1116 | pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, vboxNetFltDarwinIsPromiscuous(pThis));
|
---|
1117 | #endif
|
---|
1118 | pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
|
---|
1119 | pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */);
|
---|
1120 | vboxNetFltRelease(pThis, true /*fBusy*/);
|
---|
1121 | }
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | /* Release the interface on failure. */
|
---|
1125 | if (pIfNet)
|
---|
1126 | ifnet_release(pIfNet);
|
---|
1127 |
|
---|
1128 | int rc = RTErrConvertFromErrno(err);
|
---|
1129 | if (RT_SUCCESS(rc))
|
---|
1130 | LogRel(("VBoxFltDrv: attached to '%s' / %RTmac\n", pThis->szName, &pThis->u.s.MacAddr));
|
---|
1131 | else
|
---|
1132 | LogRel(("VBoxFltDrv: failed to attach to ifnet '%s' (err=%d)\n", pThis->szName, err));
|
---|
1133 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1134 | return rc;
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 |
|
---|
1138 | bool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis)
|
---|
1139 | {
|
---|
1140 | vboxNetFltDarwinAttachToInterface(pThis, true /* fRediscovery */);
|
---|
1141 | return !ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost);
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 |
|
---|
1145 | int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
|
---|
1146 | {
|
---|
1147 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
1148 | NOREF(pvIfData);
|
---|
1149 |
|
---|
1150 | int rc = VINF_SUCCESS;
|
---|
1151 | ifnet_t pIfNet = vboxNetFltDarwinRetainIfNet(pThis);
|
---|
1152 | if (pIfNet)
|
---|
1153 | {
|
---|
1154 | /*
|
---|
1155 | * Create a mbuf for the gather list and push it onto the wire.
|
---|
1156 | * BPF tap and stats will be taken care of by the driver.
|
---|
1157 | */
|
---|
1158 | if (fDst & INTNETTRUNKDIR_WIRE)
|
---|
1159 | {
|
---|
1160 | mbuf_t pMBuf = vboxNetFltDarwinMBufFromSG(pThis, pSG);
|
---|
1161 | if (pMBuf)
|
---|
1162 | {
|
---|
1163 | errno_t err = ifnet_output_raw(pIfNet, PF_LINK, pMBuf);
|
---|
1164 | if (err)
|
---|
1165 | rc = RTErrConvertFromErrno(err);
|
---|
1166 | }
|
---|
1167 | else
|
---|
1168 | rc = VERR_NO_MEMORY;
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | /*
|
---|
1172 | * Create a mbuf for the gather list and push it onto the host stack.
|
---|
1173 | * BPF tap and stats are on us.
|
---|
1174 | */
|
---|
1175 | if (fDst & INTNETTRUNKDIR_HOST)
|
---|
1176 | {
|
---|
1177 | mbuf_t pMBuf = vboxNetFltDarwinMBufFromSG(pThis, pSG);
|
---|
1178 | if (pMBuf)
|
---|
1179 | {
|
---|
1180 | void *pvEthHdr = mbuf_data(pMBuf);
|
---|
1181 | unsigned const cbEthHdr = 14;
|
---|
1182 | struct ifnet_stat_increment_param stats;
|
---|
1183 |
|
---|
1184 | RT_ZERO(stats);
|
---|
1185 | stats.packets_in = 1;
|
---|
1186 | stats.bytes_in = mbuf_len(pMBuf); /* full ethernet frame */
|
---|
1187 |
|
---|
1188 | mbuf_pkthdr_setrcvif(pMBuf, pIfNet);
|
---|
1189 | mbuf_pkthdr_setheader(pMBuf, pvEthHdr); /* link-layer header */
|
---|
1190 | mbuf_adj(pMBuf, cbEthHdr); /* move to payload */
|
---|
1191 |
|
---|
1192 | #if 0 /* XXX: disabled since we don't request promiscuous from intnet */
|
---|
1193 | /*
|
---|
1194 | * TODO: Since intnet knows whether it forwarded us
|
---|
1195 | * this packet because it's for us or because we are
|
---|
1196 | * promiscuous, it can perhaps set a flag for us in
|
---|
1197 | * INTNETSG::fFlags so that we don't have to re-check
|
---|
1198 | * it here.
|
---|
1199 | */
|
---|
1200 | PCRTNETETHERHDR pcEthHdr = (PCRTNETETHERHDR)pvEthHdr;
|
---|
1201 | if ( (pcEthHdr->DstMac.au8[0] & 1) == 0 /* unicast? */
|
---|
1202 | && memcmp(&pcEthHdr->DstMac, &pThis->u.s.MacAddr, sizeof(RTMAC)) != 0)
|
---|
1203 | {
|
---|
1204 | mbuf_setflags_mask(pMBuf, MBUF_PROMISC, MBUF_PROMISC);
|
---|
1205 | }
|
---|
1206 | #endif
|
---|
1207 |
|
---|
1208 | bpf_tap_in(pIfNet, DLT_EN10MB, pMBuf, pvEthHdr, cbEthHdr);
|
---|
1209 | errno_t err = ifnet_input(pIfNet, pMBuf, &stats);
|
---|
1210 | if (err)
|
---|
1211 | rc = RTErrConvertFromErrno(err);
|
---|
1212 | }
|
---|
1213 | else
|
---|
1214 | rc = VERR_NO_MEMORY;
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | vboxNetFltDarwinReleaseIfNet(pThis, pIfNet);
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1221 | return rc;
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 |
|
---|
1225 | void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive)
|
---|
1226 | {
|
---|
1227 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
1228 | ifnet_t pIfNet = vboxNetFltDarwinRetainIfNet(pThis);
|
---|
1229 | if (pIfNet)
|
---|
1230 | {
|
---|
1231 | if (pThis->fDisablePromiscuous)
|
---|
1232 | {
|
---|
1233 | /*
|
---|
1234 | * Promiscuous mode should not be used (wireless), we just need to
|
---|
1235 | * make sure the interface is up.
|
---|
1236 | */
|
---|
1237 | if (fActive)
|
---|
1238 | {
|
---|
1239 | u_int16_t fIf = ifnet_flags(pIfNet);
|
---|
1240 | if ((fIf & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING))
|
---|
1241 | {
|
---|
1242 | ifnet_set_flags(pIfNet, IFF_UP, IFF_UP);
|
---|
1243 | ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL);
|
---|
1244 | }
|
---|
1245 | }
|
---|
1246 | }
|
---|
1247 | else
|
---|
1248 | {
|
---|
1249 | /*
|
---|
1250 | * This api is a bit weird, the best reference is the code.
|
---|
1251 | *
|
---|
1252 | * Also, we have a bit or race conditions wrt the maintenance of
|
---|
1253 | * host the interface promiscuity for vboxNetFltPortOsIsPromiscuous.
|
---|
1254 | */
|
---|
1255 | unsigned const cPromiscBefore = VBOX_GET_PCOUNT(pIfNet);
|
---|
1256 | u_int16_t fIf;
|
---|
1257 | if (fActive)
|
---|
1258 | {
|
---|
1259 | Assert(!pThis->u.s.fSetPromiscuous);
|
---|
1260 | errno_t err = ENETDOWN;
|
---|
1261 | ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, true);
|
---|
1262 |
|
---|
1263 | /*
|
---|
1264 | * Try bring the interface up and running if it's down.
|
---|
1265 | */
|
---|
1266 | fIf = ifnet_flags(pIfNet);
|
---|
1267 | if ((fIf & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING))
|
---|
1268 | {
|
---|
1269 | err = ifnet_set_flags(pIfNet, IFF_UP, IFF_UP);
|
---|
1270 | errno_t err2 = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL);
|
---|
1271 | if (!err)
|
---|
1272 | err = err2;
|
---|
1273 | fIf = ifnet_flags(pIfNet);
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | /*
|
---|
1277 | * Is it already up? If it isn't, leave it to the link event or
|
---|
1278 | * we'll upset if_pcount (as stated above, ifnet_set_promiscuous is weird).
|
---|
1279 | */
|
---|
1280 | if ((fIf & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING))
|
---|
1281 | {
|
---|
1282 | err = ifnet_set_promiscuous(pIfNet, 1);
|
---|
1283 | pThis->u.s.fSetPromiscuous = err == 0;
|
---|
1284 | if (!err)
|
---|
1285 | {
|
---|
1286 | ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false);
|
---|
1287 |
|
---|
1288 | /* check if it actually worked, this stuff is not always behaving well. */
|
---|
1289 | if (!(ifnet_flags(pIfNet) & IFF_PROMISC))
|
---|
1290 | {
|
---|
1291 | err = ifnet_set_flags(pIfNet, IFF_PROMISC, IFF_PROMISC);
|
---|
1292 | if (!err)
|
---|
1293 | err = ifnet_ioctl(pIfNet, 0, SIOCSIFFLAGS, NULL);
|
---|
1294 | if (!err)
|
---|
1295 | Log(("vboxNetFlt: fixed IFF_PROMISC on %s (%d->%d)\n", pThis->szName, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
|
---|
1296 | else
|
---|
1297 | Log(("VBoxNetFlt: failed to fix IFF_PROMISC on %s, err=%d (%d->%d)\n",
|
---|
1298 | pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
|
---|
1299 | }
|
---|
1300 | }
|
---|
1301 | else
|
---|
1302 | Log(("VBoxNetFlt: ifnet_set_promiscuous -> err=%d grr! (%d->%d)\n", err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
|
---|
1303 | }
|
---|
1304 | else if (!err)
|
---|
1305 | Log(("VBoxNetFlt: Waiting for the link to come up... (%d->%d)\n", cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
|
---|
1306 | if (err)
|
---|
1307 | LogRel(("VBoxNetFlt: Failed to put '%s' into promiscuous mode, err=%d (%d->%d)\n", pThis->szName, err, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
|
---|
1308 | }
|
---|
1309 | else
|
---|
1310 | {
|
---|
1311 | ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false);
|
---|
1312 | if (pThis->u.s.fSetPromiscuous)
|
---|
1313 | {
|
---|
1314 | errno_t err = ifnet_set_promiscuous(pIfNet, 0);
|
---|
1315 | AssertMsg(!err, ("%d\n", err)); NOREF(err);
|
---|
1316 | }
|
---|
1317 | pThis->u.s.fSetPromiscuous = false;
|
---|
1318 |
|
---|
1319 | fIf = ifnet_flags(pIfNet);
|
---|
1320 | Log(("VBoxNetFlt: fIf=%#x; %d->%d\n", fIf, cPromiscBefore, VBOX_GET_PCOUNT(pIfNet)));
|
---|
1321 | }
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | vboxNetFltDarwinReleaseIfNet(pThis, pIfNet);
|
---|
1325 | }
|
---|
1326 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 |
|
---|
1330 | int vboxNetFltOsDisconnectIt(PVBOXNETFLTINS pThis)
|
---|
1331 | {
|
---|
1332 | /* Nothing to do here. */
|
---|
1333 | return VINF_SUCCESS;
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 |
|
---|
1337 | int vboxNetFltOsConnectIt(PVBOXNETFLTINS pThis)
|
---|
1338 | {
|
---|
1339 | /* Nothing to do here. */
|
---|
1340 | return VINF_SUCCESS;
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 |
|
---|
1344 | void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
|
---|
1345 | {
|
---|
1346 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
1347 |
|
---|
1348 | /*
|
---|
1349 | * Carefully obtain the interface filter reference and detach it.
|
---|
1350 | */
|
---|
1351 | RTSpinlockAcquire(pThis->hSpinlock);
|
---|
1352 | interface_filter_t pIfFilter = ASMAtomicUoReadPtrT(&pThis->u.s.pIfFilter, interface_filter_t);
|
---|
1353 | if (pIfFilter)
|
---|
1354 | ASMAtomicUoWriteNullPtr(&pThis->u.s.pIfFilter);
|
---|
1355 | RTSpinlockRelease(pThis->hSpinlock);
|
---|
1356 |
|
---|
1357 | if (pIfFilter)
|
---|
1358 | iflt_detach(pIfFilter);
|
---|
1359 |
|
---|
1360 | if (pThis->u.s.pSysSock != NULL)
|
---|
1361 | {
|
---|
1362 | sock_close(pThis->u.s.pSysSock);
|
---|
1363 | pThis->u.s.pSysSock = NULL;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 |
|
---|
1370 | int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, void *pvContext)
|
---|
1371 | {
|
---|
1372 | NOREF(pvContext);
|
---|
1373 |
|
---|
1374 | int rc = vboxNetFltDarwinAttachToInterface(pThis, false /* fRediscovery */);
|
---|
1375 | if (RT_FAILURE(rc))
|
---|
1376 | return rc;
|
---|
1377 |
|
---|
1378 | if (pThis->pSwitchPort->pfnNotifyHostAddress == NULL)
|
---|
1379 | return rc;
|
---|
1380 |
|
---|
1381 | /*
|
---|
1382 | * XXX: uwe
|
---|
1383 | *
|
---|
1384 | * Learn host's IP addresses and set up notifications for changes.
|
---|
1385 | * To avoid racing, set up notifications first.
|
---|
1386 | *
|
---|
1387 | * XXX: This should probably be global, since the only thing
|
---|
1388 | * specific to ifnet here is its IPv6 link-local address.
|
---|
1389 | */
|
---|
1390 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
1391 | errno_t error;
|
---|
1392 |
|
---|
1393 | /** @todo reorg code to not have numerous returns with duplicate code... */
|
---|
1394 | error = sock_socket(PF_SYSTEM, SOCK_RAW, SYSPROTO_EVENT,
|
---|
1395 | vboxNetFltDarwinSysSockUpcall, pThis,
|
---|
1396 | &pThis->u.s.pSysSock);
|
---|
1397 | if (error != 0)
|
---|
1398 | {
|
---|
1399 | LogRel(("sock_socket(SYSPROTO_EVENT): error %d\n", error));
|
---|
1400 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1401 | return rc;
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | int nbio = 1;
|
---|
1405 | error = sock_ioctl(pThis->u.s.pSysSock, FIONBIO, &nbio);
|
---|
1406 | if (error != 0)
|
---|
1407 | {
|
---|
1408 | LogRel(("FIONBIO: error %d\n", error));
|
---|
1409 | sock_close(pThis->u.s.pSysSock);
|
---|
1410 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1411 | return rc;
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | if (!sock_isnonblocking(pThis->u.s.pSysSock))
|
---|
1415 | {
|
---|
1416 | LogRel(("FIONBIO ok, but socket is blocking?!\n"));
|
---|
1417 | sock_close(pThis->u.s.pSysSock);
|
---|
1418 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1419 | return rc;
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | struct kev_request req;
|
---|
1423 | req.vendor_code = KEV_VENDOR_APPLE;
|
---|
1424 | req.kev_class = KEV_NETWORK_CLASS;
|
---|
1425 | req.kev_subclass = KEV_ANY_SUBCLASS; /* need both INET and INET6, so have to request all */
|
---|
1426 |
|
---|
1427 | error = sock_ioctl(pThis->u.s.pSysSock, SIOCSKEVFILT, &req);
|
---|
1428 | if (error != 0)
|
---|
1429 | {
|
---|
1430 | LogRel(("SIOCSKEVFILT: error %d\n", error));
|
---|
1431 | sock_close(pThis->u.s.pSysSock);
|
---|
1432 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1433 | return rc;
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | ifnet_t pIfNet = pThis->u.s.pIfNet; /* already retained */
|
---|
1437 |
|
---|
1438 | ifaddr_t *pIfAddrList;
|
---|
1439 | error = ifnet_get_address_list(/* all interfaces*/ NULL, &pIfAddrList);
|
---|
1440 | if (error != 0)
|
---|
1441 | {
|
---|
1442 | LogRel(("ifnet_get_address_list: error %d\n", error));
|
---|
1443 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1444 | return rc;
|
---|
1445 | }
|
---|
1446 |
|
---|
1447 | for (ifaddr_t *pIfAddr = pIfAddrList; *pIfAddr != NULL; ++pIfAddr)
|
---|
1448 | {
|
---|
1449 | ifaddr_t ifa = *pIfAddr;
|
---|
1450 | sa_family_t family = ifaddr_address_family(ifa);
|
---|
1451 | struct sockaddr_storage ss;
|
---|
1452 |
|
---|
1453 | error = ifaddr_address(ifa, (struct sockaddr *)&ss, sizeof(ss));
|
---|
1454 | if (error != 0)
|
---|
1455 | {
|
---|
1456 | LogRel(("getting address family %d: error %d\n", family, error));
|
---|
1457 | continue;
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | if (family == AF_INET)
|
---|
1461 | {
|
---|
1462 | struct sockaddr_in *sin = (struct sockaddr_in *)&ss;
|
---|
1463 | u_int32_t u32Addr = ntohl(sin->sin_addr.s_addr);
|
---|
1464 |
|
---|
1465 | if (VBOX_IN_LOOPBACK(u32Addr))
|
---|
1466 | continue;
|
---|
1467 |
|
---|
1468 | if (ifaddr_ifnet(ifa) != pIfNet && VBOX_IN_LINKLOCAL(u32Addr))
|
---|
1469 | continue;
|
---|
1470 |
|
---|
1471 | Log(("> inet %RTnaipv4\n", sin->sin_addr.s_addr));
|
---|
1472 | pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort,
|
---|
1473 | /* :fAdded */ true, kIntNetAddrType_IPv4, &sin->sin_addr);
|
---|
1474 | }
|
---|
1475 | else if (family == AF_INET6)
|
---|
1476 | {
|
---|
1477 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ss;
|
---|
1478 |
|
---|
1479 | if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
|
---|
1480 | continue;
|
---|
1481 |
|
---|
1482 | /* link-local from other interfaces are out of scope */
|
---|
1483 | if (ifaddr_ifnet(ifa) != pIfNet && IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
|
---|
1484 | continue;
|
---|
1485 |
|
---|
1486 | Log(("> inet6 %RTnaipv6\n", &sin6->sin6_addr));
|
---|
1487 | pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort,
|
---|
1488 | /* :fAdded */ true, kIntNetAddrType_IPv6, &sin6->sin6_addr);
|
---|
1489 | }
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | ifnet_free_address_list(pIfAddrList);
|
---|
1493 |
|
---|
1494 | /*
|
---|
1495 | * Now that we've got current addresses, check for events that
|
---|
1496 | * might have happened while we were working.
|
---|
1497 | */
|
---|
1498 | vboxNetFltDarwinSysSockUpcall(pThis->u.s.pSysSock, pThis, MBUF_DONTWAIT);
|
---|
1499 |
|
---|
1500 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
1501 | return rc;
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 |
|
---|
1505 | static void vboxNetFltDarwinSysSockUpcall(socket_t pSysSock, void *pvData, int fWait)
|
---|
1506 | {
|
---|
1507 | PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvData;
|
---|
1508 | errno_t error;
|
---|
1509 |
|
---|
1510 | NOREF(fWait);
|
---|
1511 |
|
---|
1512 | if (RT_UNLIKELY(pSysSock != pThis->u.s.pSysSock))
|
---|
1513 | {
|
---|
1514 | Log(("vboxNetFltDarwinSysSockUpcall: %p != %p?\n",
|
---|
1515 | pSysSock, pThis->u.s.pSysSock));
|
---|
1516 | return;
|
---|
1517 | }
|
---|
1518 |
|
---|
1519 | struct net_event_data my_link;
|
---|
1520 | ifnet_t pIfNet = pThis->u.s.pIfNet; /* XXX: retain? */
|
---|
1521 | ifnet_family_t if_family = ifnet_family(pIfNet);
|
---|
1522 | u_int32_t if_unit = ifnet_unit(pIfNet);
|
---|
1523 |
|
---|
1524 | for (;;)
|
---|
1525 | {
|
---|
1526 | mbuf_t m;
|
---|
1527 | size_t len = sizeof(struct kern_event_msg) - sizeof(u_int32_t) + sizeof(struct kev_in6_data);
|
---|
1528 |
|
---|
1529 | error = sock_receivembuf(pSysSock, NULL, &m, 0, &len);
|
---|
1530 | if (error != 0)
|
---|
1531 | {
|
---|
1532 | if (error == EWOULDBLOCK)
|
---|
1533 | {
|
---|
1534 | Log(("vboxNetFltDarwinSysSockUpcall: EWOULDBLOCK - we are done\n"));
|
---|
1535 | error = 0;
|
---|
1536 | }
|
---|
1537 | else
|
---|
1538 | Log(("sock_receivembuf: error %d\n", error));
|
---|
1539 | break;
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | if (len < sizeof(struct kern_event_msg) - sizeof(u_int32_t))
|
---|
1543 | {
|
---|
1544 | Log(("vboxNetFltDarwinSysSockUpcall: %u bytes is too short\n", (unsigned int)len));
|
---|
1545 | mbuf_freem(m);
|
---|
1546 | return;
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | struct kern_event_msg *msg = (struct kern_event_msg *)mbuf_data(m);
|
---|
1550 | if (msg->kev_subclass == KEV_INET_SUBCLASS)
|
---|
1551 | {
|
---|
1552 | if (len - (sizeof(struct kern_event_msg) - sizeof(u_int32_t)) < sizeof(struct kev_in_data))
|
---|
1553 | {
|
---|
1554 | Log(("vboxNetFltDarwinSysSockUpcall: %u bytes is too short for KEV_INET_SUBCLASS\n",
|
---|
1555 | (unsigned int)len));
|
---|
1556 | mbuf_freem(m);
|
---|
1557 | return;
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | struct kev_in_data *iev = (struct kev_in_data *)msg->event_data;
|
---|
1561 | struct net_event_data *link = &iev->link_data;
|
---|
1562 | PCRTNETADDRU pAddr = (PCRTNETADDRU)&iev->ia_addr;
|
---|
1563 | u_int32_t u32Addr = ntohl(pAddr->IPv4.u);
|
---|
1564 |
|
---|
1565 | if (VBOX_IN_LOOPBACK(u32Addr))
|
---|
1566 | {
|
---|
1567 | mbuf_freem(m);
|
---|
1568 | continue;
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | if ( (link->if_family != if_family || link->if_unit != if_unit)
|
---|
1572 | && VBOX_IN_LINKLOCAL(u32Addr))
|
---|
1573 | {
|
---|
1574 | mbuf_freem(m);
|
---|
1575 | continue;
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | switch (msg->event_code)
|
---|
1579 | {
|
---|
1580 | case KEV_INET_NEW_ADDR:
|
---|
1581 | Log(("KEV_INET_NEW_ADDR %.*s%d: %RTnaipv4\n", IFNAMSIZ, link->if_name, link->if_unit, pAddr->IPv4.u));
|
---|
1582 | pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, true /*fAdded*/, kIntNetAddrType_IPv4, pAddr);
|
---|
1583 | break;
|
---|
1584 |
|
---|
1585 | case KEV_INET_ADDR_DELETED:
|
---|
1586 | Log(("KEV_INET_ADDR_DELETED %.*s%d: %RTnaipv4\n", IFNAMSIZ, link->if_name, link->if_unit, pAddr->IPv4.u));
|
---|
1587 | pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, false /*fAdded*/, kIntNetAddrType_IPv4, pAddr);
|
---|
1588 | break;
|
---|
1589 |
|
---|
1590 | default:
|
---|
1591 | Log(("KEV INET event %u %.*s%d: addr %RTnaipv4\n",
|
---|
1592 | msg->event_code, IFNAMSIZ, link->if_name, link->if_unit, pAddr->IPv4.u));
|
---|
1593 | break;
|
---|
1594 | }
|
---|
1595 | }
|
---|
1596 | else if (msg->kev_subclass == KEV_INET6_SUBCLASS)
|
---|
1597 | {
|
---|
1598 | if (len - (sizeof(struct kern_event_msg) - sizeof(u_int32_t)) < sizeof(struct kev_in6_data))
|
---|
1599 | {
|
---|
1600 | Log(("vboxNetFltDarwinSysSockUpcall: %u bytes is too short for KEV_INET6_SUBCLASS\n",
|
---|
1601 | (unsigned int)len));
|
---|
1602 | mbuf_freem(m);
|
---|
1603 | return;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | struct kev_in6_data *iev6 = (struct kev_in6_data *)msg->event_data;
|
---|
1607 | struct net_event_data *link = &iev6->link_data;
|
---|
1608 | PCRTNETADDRU pAddr = (PCRTNETADDRU)&iev6->ia_addr.sin6_addr;
|
---|
1609 |
|
---|
1610 | if (IN6_IS_ADDR_LOOPBACK(&iev6->ia_addr.sin6_addr))
|
---|
1611 | {
|
---|
1612 | mbuf_freem(m);
|
---|
1613 | continue;
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | if ( (link->if_family != if_family || link->if_unit != if_unit)
|
---|
1617 | && IN6_IS_ADDR_LINKLOCAL(&iev6->ia_addr.sin6_addr))
|
---|
1618 | {
|
---|
1619 | mbuf_freem(m);
|
---|
1620 | continue;
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 | switch (msg->event_code)
|
---|
1624 | {
|
---|
1625 | case KEV_INET6_NEW_USER_ADDR:
|
---|
1626 | Log(("KEV_INET6_NEW_USER_ADDR %.*s%d: %RTnaipv6\n",
|
---|
1627 | IFNAMSIZ, link->if_name, link->if_unit, pAddr));
|
---|
1628 | goto kev_inet6_new;
|
---|
1629 |
|
---|
1630 | case KEV_INET6_NEW_LL_ADDR:
|
---|
1631 | Log(("KEV_INET6_NEW_LL_ADDR %.*s%d: %RTnaipv6\n",
|
---|
1632 | IFNAMSIZ, link->if_name, link->if_unit, pAddr));
|
---|
1633 | goto kev_inet6_new;
|
---|
1634 |
|
---|
1635 | case KEV_INET6_NEW_RTADV_ADDR:
|
---|
1636 | Log(("KEV_INET6_NEW_RTADV_ADDR %.*s%d: %RTnaipv6\n",
|
---|
1637 | IFNAMSIZ, link->if_name, link->if_unit, pAddr));
|
---|
1638 | goto kev_inet6_new;
|
---|
1639 |
|
---|
1640 | kev_inet6_new:
|
---|
1641 | pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort,
|
---|
1642 | /* :fAdded */ true, kIntNetAddrType_IPv6, pAddr);
|
---|
1643 | break;
|
---|
1644 |
|
---|
1645 | case KEV_INET6_ADDR_DELETED:
|
---|
1646 | Log(("KEV_INET6_ADDR_DELETED %.*s%d: %RTnaipv6\n",
|
---|
1647 | IFNAMSIZ, link->if_name, link->if_unit, pAddr));
|
---|
1648 |
|
---|
1649 | pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort,
|
---|
1650 | /* :fAdded */ false, kIntNetAddrType_IPv6, pAddr);
|
---|
1651 | break;
|
---|
1652 |
|
---|
1653 | default:
|
---|
1654 | Log(("KEV INET6 event %u %.*s%d: addr %RTnaipv6\n",
|
---|
1655 | msg->event_code, IFNAMSIZ, link->if_name, link->if_unit, pAddr));
|
---|
1656 | break;
|
---|
1657 | }
|
---|
1658 | }
|
---|
1659 | else
|
---|
1660 | Log(("vboxNetFltDarwinSysSockUpcall: subclass %u ignored\n", (unsigned)msg->kev_subclass));
|
---|
1661 |
|
---|
1662 | mbuf_freem(m);
|
---|
1663 | }
|
---|
1664 | }
|
---|
1665 |
|
---|
1666 |
|
---|
1667 | int vboxNetFltOsPreInitInstance(PVBOXNETFLTINS pThis)
|
---|
1668 | {
|
---|
1669 | /*
|
---|
1670 | * Init the darwin specific members.
|
---|
1671 | */
|
---|
1672 | pThis->u.s.pIfNet = NULL;
|
---|
1673 | pThis->u.s.pIfFilter = NULL;
|
---|
1674 | pThis->u.s.fSetPromiscuous = false;
|
---|
1675 | pThis->u.s.fNeedSetPromiscuous = false;
|
---|
1676 | //pThis->u.s.MacAddr = {0};
|
---|
1677 | pThis->u.s.pSysSock = NULL;
|
---|
1678 |
|
---|
1679 | return VINF_SUCCESS;
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 |
|
---|
1683 | void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRTMAC pMac)
|
---|
1684 | {
|
---|
1685 | NOREF(pThis); NOREF(pvIfData); NOREF(pMac);
|
---|
1686 | }
|
---|
1687 |
|
---|
1688 |
|
---|
1689 | int vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **ppvIfData)
|
---|
1690 | {
|
---|
1691 | /* Nothing to do */
|
---|
1692 | NOREF(pThis); NOREF(pvIf); NOREF(ppvIfData);
|
---|
1693 | return VINF_SUCCESS;
|
---|
1694 | }
|
---|
1695 |
|
---|
1696 |
|
---|
1697 | int vboxNetFltPortOsDisconnectInterface(PVBOXNETFLTINS pThis, void *pvIfData)
|
---|
1698 | {
|
---|
1699 | /* Nothing to do */
|
---|
1700 | NOREF(pThis); NOREF(pvIfData);
|
---|
1701 | return VINF_SUCCESS;
|
---|
1702 | }
|
---|
1703 |
|
---|