File: networking.html

package info (click to toggle)
gxemul 0.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,152 kB
  • sloc: ansic: 111,065; sh: 972; exp: 354; makefile: 118
file content (354 lines) | stat: -rw-r--r-- 12,705 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>GXemul: Networking</title>
  <meta name="robots" content="noarchive,nofollow,noindex">
</head>
<body style="font-family : sans-serif;">

<!-- 10 lines header.  -->

<h1>GXemul: Networking</h1>
<p>

<a href="./">Back to the index.</a>

<!--

Copyright (C) 2003-2021  Anders Gavare.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

-->

<p><br>
<ul>
  <li><a href="#intro">Introduction</a>
  <li><a href="#tap">Virtual Ethernet switch using a tap device</a>
  <li><a href="#multihost">Network across multiple hosts</a>
  <li><a href="#direct_example_1">UDP "Direct-access" example: udp_snoop</a>
</ul>







<p><br>
<a name="intro"></a>
<h3>Introduction:</h3>

<p>GXemul's current networking layer supports three modes:

<p><ol>
  <li>A virtual Ethernet switch built on top of a <i>tap</i> device.
  <p>
  <li>A NAT-like emulation layer, which allows guest OSes to access the outside
	internet world (IPv4 only, so far). When only one machine is being 
	emulated, the following default values apply to the guest OS:<pre>
	IPv4 address:			10.0.0.1
	Netmask:			255.0.0.0
	Gateway / default route:	10.0.0.254
	Nameserver:			10.0.0.254
</pre>To the outside world, it will seem as if the host is doing all the
	networking, since the emulator is just a normal user process
	on the host.
  <p>
  <li>A UDP mode, allowing external tools to read/write raw
	ethernet packages from/to the emulator via UDP.
</ol>

<p><i>NOTES:</i>

<p>The tap device support was contributed by Jason Thorpe.

<p>The NAT-like layer is very 
"hackish" and was only meant as a proof-of-concept, to see if networking 
like this would work with e.g. NetBSD as a guest OS. (If you are 
interested in the technical details, and the reasons why NAT networking is 
implemented this way, you might want to read the <a 
href="technical.html#net"> networking section in the technical 
documentation</a>.)

<p>The UDP mode is used to connect multiple instances of GXemul in
an easy way, but it provides no security of any kind.

<p><font color="#ff0000">Use the networking features at your own risk. 
</font>


<p>The emulated machine must have a NIC (network interface card). Not all
machines have this. At the moment, the following NICs are more or less
working:

<ul>
  <li><tt><b>dec21143</b></tt>, Digital's 21143 PCI NIC (known as <tt>dc</tt>
	in OpenBSD, or <tt>tlp</tt> in NetBSD)
  <li><tt><b>ether</b></tt>, the "fake" experimental ethernet device
	(documented <a href="experiments.html#expdevices_ether">here</a>)
  <li><tt><b>le</b></tt>, Lance Ethernet, as used in <a href="machine_decstation.html">DECstation 5000/200</a> ("3max") and the <a href="machine_luna88k.html">LUNA88K</a> machines
  <li><tt><b>mec</b></tt>, the <a href="machine_sgi_o2.html">SGI O2</a>'s ethernet controller
</ul>

<p>It is not possible to simply attach any of the supported NICs into any
of the supported emulated machines. Some machines, for example, have a 
specific NIC in them, others may have a PCI bus where a PCI NIC can be 
used. This is very much machine-dependent, and implemented on a case-by-case basis.

<p>If you are impatient, and simply want to try out networking in GXemul,
I would recommend trying out an ftp install of <a
href="machine_decstation.html#netbsdpmaxinstall">NetBSD/pmax</a>.






<p><br>
<a name="tap"></a>
<h3>Virtual Ethernet switch using a <i>tap</i> device:</h3>

<p>The simplest way to emulate a real Ethernet network is using a <i>tap</i>
device.  In this mode, the emulator disables the simulated NAT and
direct-access machinery and internally treats all emulated NICs as if
they are on a single Ethernet switch.  In this mode, packets destined for
the guest's specific MAC address as well as Ethernet multicast and broadcast
packets are send to the individual guest instances.  Individual NIC
emulations may also apply their own multicast filtering; multicast filtering
is implemented for the DEC 21143 and Lance NICs.

<p>The <i>tap</i> interface on the host can be thought of as an upstream
link on the virtual Ethernet switch.  In addition to providing a "port"
for the host, the <i>tap</i> interface can be bridged to a physical Ethernet
port on the host, allowing the guests to access the host's connected LAN.

<p>Networking services such as DHCP and DNS must be provided either by
the host or by the host's connected LAN.

<p>Support for the <i>tap</i> device was developed on NetBSD, but should
also work on FreeBSD, OpenBSD, and Linux hosts.

<p>The easiest way to enable tap device networking is to use the <tt>-L</tt>
command line option, e.g.:

<p><pre>gxemul -e 3max <b>-L /dev/tap0</b> -d nbsd_pmax.img
</pre>

<p>Here is a simple example of how to enable it when using configuration
files:

<p><pre>
<font color="#2020cf">!  Configuration file for
!  virtual Ethernet switch networking
!  using a tap device.</font>

<b>net(</b>
	<b>tapdev(</b><font color="#ff003f">"/dev/tap0"</font><b>)</b>
<b>)</b>
<b>machine(</b>
	<b>name(<font color="#ff003f">"guest machine"</font>)</b>

	<b>type(<font color="#ff003f">"dec"</font>)</b>
	<b>subtype(<font color="#ff003f">"5000/200"</font>)</b>

	<font color="#2020cf">!  Add a disk, etc.</font>
<b>)</b>
</pre>

<p>Before starting the emulator, you will need to create the <i>tap</i>
interface on the host.  Here is an example for NetBSD:

<p><pre>
<b># ifconfig tap0 create up</b>
</pre>

<p>If you wish to simply network the host and the guests together, then
simply assign an IP address to the <i>tap</i> interface on the host:

<p><pre>
<b># ifconfig tap0 10.0.0.254</b>
</pre>

<p>You can now run a DHCP server on the host for the guests, or you can
configure the guests manually.

<p>If instead you would like to bridge to the host's connected LAN,
Here is an example for NetBSD:

<p><pre>
<b># ifconfig bridge0 create up</b>
<b># brconfig add tap0 add wm0</b>
</pre>

<p>Although it <i>is</i> possible to have more than one machine per 
configuration file, I strongly recommend against it. Please use one 
configuration file for one emulated machine.  Each configuration file
must have a unique <i>tap</i> instance, and machines in separate
configuration files must use bridged <i>tap</i> devices if they wish
to communicate with each other as if on the same LAN.

<p><small>(The section above is written by Jason Thorpe.)</small>



<p><br>
<a name="multihost"></a>
<h3>Network across multiple hosts:</h3>

<p>The way to emulate a network of multiple emulated machines, whether 
they are actually running on the same physical host, or on multiple hosts, 
is to use <a href="configfiles.html">configuration files</a>, and the
"direct-access" method of networking.

<p>Although it <i>is</i> possible to have more than one machine per 
configuration file, I strongly recommend against it. Please use one 
configuration file for one emulated machine.

<p>Here is a simple example:

<p><table border="0" width="100%"><tr><td width="40">&nbsp;</td>
<td><pre>
<font color="#2020cf">!  Configuration file for a
!  "client" machine, netbooting
!  of another machine.</font>

<b>net(</b>
	<b>local_port(15000)</b>
	<b>add_remote(<font color="#ff003f">"localhost:15001"</font>)</b>
<b>)</b>
<b>machine(</b>
	<b>name(<font color="#ff003f">"client machine"</font>)</b>
	<b>serial_nr(1)</b>	<font color="#2020cf">!  10.0.0.1</font>

	<b>type(<font color="#ff003f">"sgi"</font>)</b>
	<b>subtype(<font color="#ff003f">"o2"</font>)</b>
        <b>load(<font color="#ff003f">"netbsd-GENERIC32_IP3x.gz"</font>)</b>
<b>)</b>
</pre></td><td width="20">&nbsp;</td><td><pre>
<font color="#2020cf">!  Configuration file for the
!  "server" machine.</font>

<b>net(</b>
	<b>local_port(15001)</b>
	<b>add_remote(<font color="#ff003f">"localhost:15000"</font>)</b>
<b>)</b>
<b>machine(</b>
	<b>name(<font color="#ff003f">"nfs server"</font>)</b>
	<b>serial_nr(2)</b>	<font color="#2020cf">!  10.0.0.2</font>

        <b>type(<font color="#ff003f">"dec"</font>)</b>
        <b>subtype(<font color="#ff003f">"3max"</font>)</b>
        <b>disk(<font color="#ff003f">"nbsd_pmax.img"</font>)</b>
<b>)</b>
</pre></td><td width="20">&nbsp;</td></tr></table>

<p>This example creates a network using the default settings (10.0.0.0/8), 
but it also uses the direct-access networking mode to allow the network 
to be connected to other emulator instances. <tt>local_port(15000)</tt> 
means that anything coming in to UDP port 15000 on the host is added to 
the network. All ethernet packets on the network are also sent out to all 
other connected machines (those added with <tt>add_remote()</tt>).

<p>As you can see in the example, this is a configuration file for
netbooting a NetBSD/sgimips diskless machine, with a NetBSD/pmax machine
acting as the nfs server. Note that the nfs server has ports 15000 and 
15001 reversed, compared to the client!

<p>"<tt>localhost</tt>" can be changed to the Internet hostname of a 
remote machine, to run the simulation across a physical network.

<p><font color="#ff0000"><b>NOTE:</b> There is no error checking or
security checking of any kind. All UDP packets arriving at the input port
are added to the emulated ethernet. This is not very good of course; use 
this feature at your own risk.</font>





<p><br>
<a name="direct_example_1"></a>
<h3>UDP "Direct-access" example: udp_snoop:</h3>

<p>The most basic example of how the simple direct-access system works is a small 
program in the <tt>experiments/</tt> directory, <tt>udp_snoop</tt>, which simply 
dumps incoming UDP packets to the terminal, in hex and ASCII.

<p>The easiest way to test the example is to download a <a href="ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-3.1/pmax/binary/kernel/netbsd-INSTALL.gz">
NetBSD/pmax INSTALL kernel</a>, and start the emulator with a configuration file 
looking something like this:

<pre>
	net(
	    add_remote("localhost:12300")
	)

	machine(
	    subtype(3max)
	    load("netbsd-INSTALL.gz")
	)
</pre>

<p>In addition to the machine section, you can see that there is also a 
<tt>net()</tt> section. It defaults to emulating a 10.0.0.0/8 IPv4 NATed
network, but there is also an additional "raw output", to UDP port 12300.

<p>Now, do the following:
<ul>
  <li>Start the emulator with the configuration file, i.e.
	<tt><b>gxemul @testconfig</b></tt>.
  <li>Start <tt><b>udp_snoop 12300</b></tt> in another terminal.
  <li>Inside emulated NetBSD/pmax, type <tt><b>ifconfig le0 10.0.0.1</b></tt>.
</ul>

<p>This should be enough to see broadcast messages from the guest OS which 
are not directed to the gateway. It might look like this:

<pre>
	$ ./udp_snoop 12300
	 ff ff ff ff ff ff 10 20 30 00 00 10 08 06 00 01  ....... 0.......
	 08 00 06 04 00 01 10 20 30 00 00 10 0a 00 00 02  ....... 0.......
	 00 00 00 00 00 00 0a 00 00 02 00 00 00 00 00 00  ................
	 00 00 00 00 00 00 00 00 00 00 00 00              ............

	 33 33 ff 00 00 10 10 20 30 00 00 10 86 dd 60 00  33..... 0.....`.
	 00 00 00 20 00 01 00 00 00 00 00 00 00 00 00 00  ... ............
	 00 00 00 00 00 00 ff 02 00 00 00 00 00 00 00 00  ................
	 00 01 ff 00 00 10 3a 00 01 00 05 02 00 00 83 00  ......:.........
	 80 83 00 00 00 00 ff 02 00 00 00 00 00 00 00 00  ................
	 00 01 ff 00 00 10                                ......
	...
</pre>




</p>

</body>
</html>