VirtualBox

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

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: VBoxNetSend.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * A place to share code and definitions between VBoxNetAdp and VBoxNetFlt host drivers.
4 */
5
6/*
7 * Copyright (C) 2014-2022 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# if MAC_OS_X_VERSION_MIN_REQUIRED >= 101500 /* The 10.15 SDK has a slightly butchered API deprecation attempt. */
43# pragma clang diagnostic push
44# pragma clang diagnostic ignored "-Wmacro-redefined" /* Each header redefines __NKE_API_DEPRECATED. */
45# pragma clang diagnostic ignored "-Wmissing-declarations" /* Misplaced __NKE_API_DEPRECATED; in kpi_mbuf.h. */
46# include <net/kpi_interface.h>
47# include <sys/kpi_mbuf.h>
48# include <net/if.h>
49# pragma clang diagnostic pop
50# else /* < 10.15 */
51# include <net/kpi_interface.h>
52RT_C_DECLS_BEGIN /* Buggy 10.4 headers, fixed in 10.5. */
53# include <sys/kpi_mbuf.h>
54RT_C_DECLS_END
55# include <net/if.h>
56# endif /* < 10.15 */
57
58
59RT_C_DECLS_BEGIN
60
61# if defined(IN_RING0)
62
63/**
64 * Constructs and submits a dummy packet to ifnet_input().
65 *
66 * This is a workaround for "stuck dock icon" issue. When the first packet goes
67 * through the interface DLIL grabs a reference to the thread that submits the
68 * packet and holds it until the interface is destroyed. By submitting this
69 * dummy we make DLIL grab the thread of a non-GUI process.
70 *
71 * Most of this function was copied from vboxNetFltDarwinMBufFromSG().
72 *
73 * @returns VBox status code.
74 * @param pIfNet The interface that will hold the reference to the calling
75 * thread. We submit dummy as if it was coming from this interface.
76 */
77DECLINLINE(int) VBoxNetSendDummy(ifnet_t pIfNet)
78{
79 int rc = VINF_SUCCESS;
80
81 size_t cbTotal = 50; /* No Ethernet header */
82 mbuf_how_t How = MBUF_WAITOK;
83 mbuf_t pPkt = NULL;
84 errno_t err = mbuf_allocpacket(How, cbTotal, NULL, &pPkt);
85 if (!err)
86 {
87 /* Skip zero sized memory buffers (paranoia). */
88 mbuf_t pCur = pPkt;
89 while (pCur && !mbuf_maxlen(pCur))
90 pCur = mbuf_next(pCur);
91 Assert(pCur);
92
93 /* Set the required packet header attributes. */
94 mbuf_pkthdr_setlen(pPkt, cbTotal);
95 mbuf_pkthdr_setheader(pPkt, mbuf_data(pCur));
96
97 mbuf_setlen(pCur, cbTotal);
98 memset(mbuf_data(pCur), 0, cbTotal);
99
100 mbuf_pkthdr_setrcvif(pPkt, pIfNet); /* will crash without this. */
101
102 err = ifnet_input(pIfNet, pPkt, NULL);
103 if (err)
104 {
105 rc = RTErrConvertFromErrno(err);
106 mbuf_freem(pPkt);
107 }
108 }
109 else
110 rc = RTErrConvertFromErrno(err);
111
112 return rc;
113}
114
115# endif /* IN_RING0 */
116
117RT_C_DECLS_END
118
119#endif /* RT_OS_DARWIN */
120
121#endif /* !VBOX_INCLUDED_SRC_darwin_VBoxNetSend_h */
122
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