1 | /* $Id: tstIntNet-1.cpp 10681 2008-07-15 20:00:27Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox - Testcase for internal networking, simple NetFlt trunk creation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 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 | #include <VBox/intnet.h>
|
---|
26 | #include <VBox/sup.h>
|
---|
27 | #include <VBox/vmm.h>
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <iprt/initterm.h>
|
---|
30 | #include <iprt/alloc.h>
|
---|
31 | #include <iprt/path.h>
|
---|
32 | #include <iprt/stream.h>
|
---|
33 | #include <iprt/string.h>
|
---|
34 | #include <iprt/thread.h>
|
---|
35 | #include <iprt/param.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /*******************************************************************************
|
---|
39 | * Global Variables *
|
---|
40 | *******************************************************************************/
|
---|
41 | static int g_cErrors = 0;
|
---|
42 |
|
---|
43 |
|
---|
44 | int main(int argc, char **argv)
|
---|
45 | {
|
---|
46 | /*
|
---|
47 | * Init the runtime, open the support driver and load VMMR0.r0.
|
---|
48 | */
|
---|
49 | RTR3Init(false, 0);
|
---|
50 | RTPrintf("tstIntNet-1: TESTING...\n");
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * Open the session, load ring-0 and issue the request.
|
---|
54 | */
|
---|
55 | PSUPDRVSESSION pSession;
|
---|
56 | int rc = SUPInit(&pSession, 0);
|
---|
57 | if (RT_FAILURE(rc))
|
---|
58 | {
|
---|
59 | RTPrintf("tstIntNet-1: SUPInit -> %Rrc\n", rc);
|
---|
60 | return 1;
|
---|
61 | }
|
---|
62 |
|
---|
63 | char szPath[RTPATH_MAX];
|
---|
64 | rc = RTPathProgram(szPath, sizeof(szPath) - sizeof("/../VMMR0.r0"));
|
---|
65 | if (RT_FAILURE(rc))
|
---|
66 | {
|
---|
67 | RTPrintf("tstIntNet-1: RTPathProgram -> %Rrc\n", rc);
|
---|
68 | return 1;
|
---|
69 | }
|
---|
70 |
|
---|
71 | rc = SUPLoadVMM(strcat(szPath, "/../VMMR0.r0"));
|
---|
72 | if (RT_FAILURE(rc))
|
---|
73 | {
|
---|
74 | RTPrintf("tstIntNet-1: SUPLoadVMM(\"%s\") -> %Rrc\n", szPath, rc);
|
---|
75 | return 1;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Create the request, picking the network and trunk names from argv[2]
|
---|
80 | * and argv[1] if present.
|
---|
81 | */
|
---|
82 | INTNETOPENREQ OpenReq;
|
---|
83 | OpenReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
84 | OpenReq.Hdr.cbReq = sizeof(OpenReq);
|
---|
85 | OpenReq.pSession = pSession; /* later */
|
---|
86 | if (argc >= 2)
|
---|
87 | strncpy(OpenReq.szNetwork, argv[2], sizeof(OpenReq.szNetwork));
|
---|
88 | else
|
---|
89 | strncpy(OpenReq.szNetwork, "tstIntNet-1", sizeof(OpenReq.szNetwork));
|
---|
90 | if (argc >= 2)
|
---|
91 | strncpy(OpenReq.szNetwork, argv[2], sizeof(OpenReq.szNetwork));
|
---|
92 | else
|
---|
93 | #ifdef RT_OS_DARWIN
|
---|
94 | strncpy(OpenReq.szTrunk, "en0", sizeof(OpenReq.szTrunk));
|
---|
95 | #elif defined(RT_OS_LINUX)
|
---|
96 | strncpy(OpenReq.szTrunk, "eth0", sizeof(OpenReq.szTrunk));
|
---|
97 | #else
|
---|
98 | strncpy(OpenReq.szTrunk, "em0", sizeof(OpenReq.szTrunk));
|
---|
99 | #endif
|
---|
100 | OpenReq.enmTrunkType = kIntNetTrunkType_NetFlt;
|
---|
101 | OpenReq.fFlags = 0;
|
---|
102 | OpenReq.cbSend = 0;
|
---|
103 | OpenReq.cbRecv = 0;
|
---|
104 | OpenReq.hIf = INTNET_HANDLE_INVALID;
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * Issue the request.
|
---|
108 | */
|
---|
109 | RTPrintf("tstIntNet-1: attempting to open/create network \"%s\" with NetFlt trunk \"%s\"...\n",
|
---|
110 | OpenReq.szNetwork, OpenReq.szTrunk);
|
---|
111 | RTThreadSleep(250);
|
---|
112 | rc = SUPCallVMMR0Ex(NIL_RTR0PTR, VMMR0_DO_INTNET_OPEN, 0, &OpenReq.Hdr);
|
---|
113 | if (RT_SUCCESS(rc))
|
---|
114 | {
|
---|
115 | RTPrintf("tstIntNet-1: successfully opened/created \"%s\" with NetFlt trunk \"%s\" - hIf=%#x",
|
---|
116 | OpenReq.szNetwork, OpenReq.szTrunk, OpenReq.hIf);
|
---|
117 |
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | RTPrintf("stdIntNet-1: SUPCallVMMR0Ex(,VMMR0_DO_INTNET_OPEN,) failed, rc=%Rrc\n", rc);
|
---|
122 | g_cErrors++;
|
---|
123 | }
|
---|
124 |
|
---|
125 | RTThreadSleep(1000);
|
---|
126 | SUPTerm(false /* not forced */);
|
---|
127 |
|
---|
128 | /*
|
---|
129 | * Summary.
|
---|
130 | */
|
---|
131 | if (!g_cErrors)
|
---|
132 | RTPrintf("tstIntNet-1: SUCCESS\n");
|
---|
133 | else
|
---|
134 | RTPrintf("tstIntNet-1: FAILURE - %d errors\n", g_cErrors);
|
---|
135 |
|
---|
136 | return !!g_cErrors;
|
---|
137 | }
|
---|
138 |
|
---|