VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/darwin/VBoxNetSend.h@ 83298

Last change on this file since 83298 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: VBoxNetSend.h 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * A place to share code and definitions between VBoxNetAdp and VBoxNetFlt host drivers.
4 */
5
6/*
7 * Copyright (C) 2014-2020 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/** @todo move this to src/VBox/HostDrivers/darwin as a .cpp file. */
28
29#ifndef VBOX_INCLUDED_SRC_darwin_VBoxNetSend_h
30#define VBOX_INCLUDED_SRC_darwin_VBoxNetSend_h
31#ifndef RT_WITHOUT_PRAGMA_ONCE
32# pragma once
33#endif
34
35#if defined(RT_OS_DARWIN)
36
37# include <iprt/err.h>
38# include <iprt/assert.h>
39# include <iprt/string.h>
40
41# include <sys/socket.h>
42# include <net/kpi_interface.h>
43RT_C_DECLS_BEGIN /* Buggy 10.4 headers, fixed in 10.5. */
44# include <sys/kpi_mbuf.h>
45RT_C_DECLS_END
46# include <net/if.h>
47
48RT_C_DECLS_BEGIN
49
50# if defined(IN_RING0)
51
52/**
53 * Constructs and submits a dummy packet to ifnet_input().
54 *
55 * This is a workaround for "stuck dock icon" issue. When the first packet goes
56 * through the interface DLIL grabs a reference to the thread that submits the
57 * packet and holds it until the interface is destroyed. By submitting this
58 * dummy we make DLIL grab the thread of a non-GUI process.
59 *
60 * Most of this function was copied from vboxNetFltDarwinMBufFromSG().
61 *
62 * @returns VBox status code.
63 * @param pIfNet The interface that will hold the reference to the calling
64 * thread. We submit dummy as if it was coming from this interface.
65 */
66DECLINLINE(int) VBoxNetSendDummy(ifnet_t pIfNet)
67{
68 int rc = VINF_SUCCESS;
69
70 size_t cbTotal = 50; /* No Ethernet header */
71 mbuf_how_t How = MBUF_WAITOK;
72 mbuf_t pPkt = NULL;
73 errno_t err = mbuf_allocpacket(How, cbTotal, NULL, &pPkt);
74 if (!err)
75 {
76 /* Skip zero sized memory buffers (paranoia). */
77 mbuf_t pCur = pPkt;
78 while (pCur && !mbuf_maxlen(pCur))
79 pCur = mbuf_next(pCur);
80 Assert(pCur);
81
82 /* Set the required packet header attributes. */
83 mbuf_pkthdr_setlen(pPkt, cbTotal);
84 mbuf_pkthdr_setheader(pPkt, mbuf_data(pCur));
85
86 mbuf_setlen(pCur, cbTotal);
87 memset(mbuf_data(pCur), 0, cbTotal);
88
89 mbuf_pkthdr_setrcvif(pPkt, pIfNet); /* will crash without this. */
90
91 err = ifnet_input(pIfNet, pPkt, NULL);
92 if (err)
93 {
94 rc = RTErrConvertFromErrno(err);
95 mbuf_freem(pPkt);
96 }
97 }
98 else
99 rc = RTErrConvertFromErrno(err);
100
101 return rc;
102}
103
104# endif /* IN_RING0 */
105
106RT_C_DECLS_END
107
108#endif /* RT_OS_DARWIN */
109
110#endif /* !VBOX_INCLUDED_SRC_darwin_VBoxNetSend_h */
111
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette