VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NetLib/VBoxNetIntIf.cpp@ 28714

Last change on this file since 28714 was 28714, checked in by vboxsync, 15 years ago

intnetinline.h: Changed the prefix to IntNet.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: VBoxNetIntIf.cpp 28714 2010-04-25 20:04:02Z vboxsync $ */
2/** @file
3 * VBoxNetIntIf - IntNet Interface Client Routines.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#define LOG_GROUP LOG_GROUP_DEFAULT
26#include "VBoxNetLib.h"
27#include <VBox/intnet.h>
28#include <VBox/intnetinline.h>
29#include <VBox/sup.h>
30#include <VBox/vmm.h>
31#include <VBox/err.h>
32#include <VBox/log.h>
33
34#include <iprt/string.h>
35
36
37
38/**
39 * Flushes the send buffer.
40 *
41 * @returns VBox status code.
42 * @param pSession The support driver session.
43 * @param hIf The interface handle to flush.
44 */
45int VBoxNetIntIfFlush(PSUPDRVSESSION pSession, INTNETIFHANDLE hIf)
46{
47 INTNETIFSENDREQ SendReq;
48 SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
49 SendReq.Hdr.cbReq = sizeof(SendReq);
50 SendReq.pSession = pSession;
51 SendReq.hIf = hIf;
52 return SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, VMMR0_DO_INTNET_IF_SEND, 0, &SendReq.Hdr);
53}
54
55
56/**
57 * Copys the SG segments into the specified fram.
58 *
59 * @param pvFrame The frame buffer.
60 * @param cSegs The number of segments.
61 * @param paSegs The segments.
62 */
63static void vboxnetIntIfCopySG(void *pvFrame, size_t cSegs, PCINTNETSEG paSegs)
64{
65 uint8_t *pbDst = (uint8_t *)pvFrame;
66 for (size_t iSeg = 0; iSeg < cSegs; iSeg++)
67 {
68 memcpy(pbDst, paSegs[iSeg].pv, paSegs[iSeg].cb);
69 pbDst += paSegs[iSeg].cb;
70 }
71}
72
73
74/**
75 * Writes a frame packet to the buffer.
76 *
77 * @returns VBox status code.
78 * @param pBuf The buffer.
79 * @param pRingBuf The ring buffer to read from.
80 * @param cSegs The number of segments.
81 * @param paSegs The segments.
82 */
83int VBoxNetIntIfRingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, size_t cSegs, PCINTNETSEG paSegs)
84{
85 /*
86 * Validate input.
87 */
88 AssertPtr(pBuf);
89 AssertPtr(pRingBuf);
90 AssertPtr(paSegs);
91 Assert(cSegs > 0);
92
93 /*
94 * Calc frame size.
95 */
96 uint32_t cbFrame = 0;
97 for (size_t iSeg = 0; iSeg < cSegs; iSeg++)
98 cbFrame += paSegs[iSeg].cb;
99 Assert(cbFrame >= sizeof(RTMAC) * 2);
100
101 /*
102 * Allocate a frame, copy the data and commit it.
103 */
104 PINTNETHDR pHdr;
105 void *pvFrame;
106 int rc = IntNetRingAllocateFrame(pRingBuf, cbFrame, &pHdr, &pvFrame);
107 if (RT_SUCCESS(rc))
108 {
109 vboxnetIntIfCopySG(pvFrame, cSegs, paSegs);
110 IntNetRingCommitFrame(pRingBuf, pHdr);
111 return VINF_SUCCESS;
112 }
113
114 return rc;
115}
116
117
118/**
119 * Sends a frame
120 *
121 * @returns VBox status code.
122 * @param pSession The support driver session.
123 * @param hIf The interface handle.
124 * @param pBuf The interface buffer.
125 * @param cSegs The number of segments.
126 * @param paSegs The segments.
127 * @param fFlush Whether to flush the write.
128 */
129int VBoxNetIntIfSend(PSUPDRVSESSION pSession, INTNETIFHANDLE hIf, PINTNETBUF pBuf,
130 size_t cSegs, PCINTNETSEG paSegs, bool fFlush)
131{
132 int rc = VBoxNetIntIfRingWriteFrame(pBuf, &pBuf->Send, cSegs, paSegs);
133 if (rc == VERR_BUFFER_OVERFLOW)
134 {
135 VBoxNetIntIfFlush(pSession, hIf);
136 rc = VBoxNetIntIfRingWriteFrame(pBuf, &pBuf->Send, cSegs, paSegs);
137 }
138 if (RT_SUCCESS(rc) && fFlush)
139 rc = VBoxNetIntIfFlush(pSession, hIf);
140 return rc;
141}
Note: See TracBrowser for help on using the repository browser.

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