pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/emulators/gxemul - Add tap(4) networking support to gx...
details: https://anonhg.NetBSD.org/pkgsrc/rev/03628b0b4f92
branches: trunk
changeset: 440357:03628b0b4f92
user: thorpej <thorpej%pkgsrc.org@localhost>
date: Wed Oct 07 00:43:04 2020 +0000
description:
- Add tap(4) networking support to gxemul. See the networking documentation
for it's theory of operation in gxemul and how to configure it.
- Add address filtering to the LANCE and Tulip emulation.
These changes have already been upstreamed in the main gxemul repository.
Bump package version to gxemul-0.6.2nb1.
diffstat:
emulators/gxemul/Makefile | 3 +-
emulators/gxemul/distinfo | 17 +-
emulators/gxemul/patches/patch-doc_networking.html | 120 +
emulators/gxemul/patches/patch-src_devices_dev_dec21143.cc | 890 +++++++++++++
emulators/gxemul/patches/patch-src_devices_dev_ether.cc | 74 +
emulators/gxemul/patches/patch-src_devices_dev_le.cc | 232 +++
emulators/gxemul/patches/patch-src_devices_dev_rtl8139c.cc | 51 +
emulators/gxemul/patches/patch-src_devices_dev_sgi_mec.cc | 69 +
emulators/gxemul/patches/patch-src_devices_dev_sn.cc | 40 +
emulators/gxemul/patches/patch-src_include_net.h | 107 +
emulators/gxemul/patches/patch-src_net_Makefile.skel | 15 +
emulators/gxemul/patches/patch-src_net_net.cc | 318 ++++
emulators/gxemul/patches/patch-src_net_net_ether.cc | 150 ++
emulators/gxemul/patches/patch-src_net_net_ip.cc | 238 +++
emulators/gxemul/patches/patch-src_net_net_tap.cc | 192 ++
emulators/gxemul/patches/patch-src_old_main_emul.cc | 14 +
emulators/gxemul/patches/patch-src_old_main_emul_parse.cc | 38 +
17 files changed, 2566 insertions(+), 2 deletions(-)
diffs (truncated from 2646 to 300 lines):
diff -r a750eb4a6ef0 -r 03628b0b4f92 emulators/gxemul/Makefile
--- a/emulators/gxemul/Makefile Wed Oct 07 00:04:40 2020 +0000
+++ b/emulators/gxemul/Makefile Wed Oct 07 00:43:04 2020 +0000
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.67 2019/08/23 13:13:49 ryoon Exp $
+# $NetBSD: Makefile,v 1.68 2020/10/07 00:43:04 thorpej Exp $
DISTNAME= gxemul-0.6.2
+PKGREVISION= 1
CATEGORIES= emulators
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=gxemul/}
diff -r a750eb4a6ef0 -r 03628b0b4f92 emulators/gxemul/distinfo
--- a/emulators/gxemul/distinfo Wed Oct 07 00:04:40 2020 +0000
+++ b/emulators/gxemul/distinfo Wed Oct 07 00:43:04 2020 +0000
@@ -1,6 +1,21 @@
-$NetBSD: distinfo,v 1.60 2019/08/23 13:13:49 ryoon Exp $
+$NetBSD: distinfo,v 1.61 2020/10/07 00:43:04 thorpej Exp $
SHA1 (gxemul-0.6.2.tar.gz) = aabaeba783e70be952ab0056bf84d0f2b70c2155
RMD160 (gxemul-0.6.2.tar.gz) = ccac73d82446f89792b1fc803bee623813f3aab2
SHA512 (gxemul-0.6.2.tar.gz) = 4f389c509f9ecf39603ceed50e899e2bee285d3fefac9b3214076115ee71b5a7a68d1d92690b6debc8de5cf5f0303da83b3cc921a5c0b5eb4c7ad89baa730b59
Size (gxemul-0.6.2.tar.gz) = 5897883 bytes
+SHA1 (patch-doc_networking.html) = dd7a1519a678196fd5a835317a32ba483630ece8
+SHA1 (patch-src_devices_dev_dec21143.cc) = 52f36741038c76a2dbafc7da6737e816aed5c9f9
+SHA1 (patch-src_devices_dev_ether.cc) = 00221e09530743e81faedcc75ee951fa853d0e2c
+SHA1 (patch-src_devices_dev_le.cc) = a728e8008a7a9f33aaf95811a33ebac2cb86e80e
+SHA1 (patch-src_devices_dev_rtl8139c.cc) = ee6dbba7c7c9c62c50493c476297ee5ac89d2b83
+SHA1 (patch-src_devices_dev_sgi_mec.cc) = 24b1259350faf60265df7958f0f680302f475e8e
+SHA1 (patch-src_devices_dev_sn.cc) = e939521be1630f51e7ddc67abe90980de38e8837
+SHA1 (patch-src_include_net.h) = 4d31fcefe384fcc9d68255825240c89b45acc92e
+SHA1 (patch-src_net_Makefile.skel) = 4738229a928b9cb5a2531dfc357297f91e9fdc09
+SHA1 (patch-src_net_net.cc) = 57397c9a8197ee25e7faa8c0733273014e3e0670
+SHA1 (patch-src_net_net_ether.cc) = ef7464dbb0812a9cb8d5be806db07cc19853fc1e
+SHA1 (patch-src_net_net_ip.cc) = f5615f3b347e9bdcd256fa4b5b1594473fd2e5e4
+SHA1 (patch-src_net_net_tap.cc) = f913b3efb51bc4a8080420988d5fc845e8a38f73
+SHA1 (patch-src_old_main_emul.cc) = 0b1106745e7c5d320e93f9f7775d8ced6109c089
+SHA1 (patch-src_old_main_emul_parse.cc) = 23048bc3a0a83fd189b3bbd4656ef0e1a2c23b99
diff -r a750eb4a6ef0 -r 03628b0b4f92 emulators/gxemul/patches/patch-doc_networking.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emulators/gxemul/patches/patch-doc_networking.html Wed Oct 07 00:43:04 2020 +0000
@@ -0,0 +1,120 @@
+$NetBSD: patch-doc_networking.html,v 1.1 2020/10/07 00:43:05 thorpej Exp $
+
+Document tap(4)-based networking.
+
+--- doc/networking.html.orig 2020-10-05 22:53:41.969487340 +0000
++++ doc/networking.html 2020-10-05 22:54:17.309695478 +0000
+@@ -46,6 +46,7 @@ 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">Direct-access example 1: udp_snoop</a>
+ </ul>
+@@ -60,9 +61,11 @@ SUCH DAMAGE.
+ <a name="intro"></a>
+ <h3>Introduction:</h3>
+
+-<p>GXemul's current networking layer supports two modes:
++<p>GXemul's current networking layer supports three modes:
+
+ <p><ol>
++ <li>A vitual Ethernet switch built on top of a <i>tap</i> device.
++ <p>
+ <li>A NAT-like 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>
+@@ -78,7 +81,7 @@ SUCH DAMAGE.
+ ethernet packages from/to the emulator.
+ </ol>
+
+-<p><i>NOTE:</i> Both these modes have problems. The NAT-like layer is very
++<p><i>NOTE:</i> The latter two modes have problems. 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
+@@ -120,6 +123,83 @@ href="machine_decstation.html#netbsdpmax
+
+
+
++<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; multcast 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>Here is a simple example:
++
++<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><br>
+ <a name="multihost"></a>
diff -r a750eb4a6ef0 -r 03628b0b4f92 emulators/gxemul/patches/patch-src_devices_dev_dec21143.cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emulators/gxemul/patches/patch-src_devices_dev_dec21143.cc Wed Oct 07 00:43:04 2020 +0000
@@ -0,0 +1,890 @@
+$NetBSD: patch-src_devices_dev_dec21143.cc,v 1.1 2020/10/07 00:43:05 thorpej Exp $
+
+- Add support for tap(4)-based networking.
+- Process the setup packet, and implement all of the Tulip receive
+ filtering modes.
+- Add ugly hack to deal with PCI vs. CPU views of main memory differences
+ between systems.
+
+--- src/devices/dev_dec21143.cc.orig 2020-10-05 22:54:55.903897678 +0000
++++ src/devices/dev_dec21143.cc 2020-10-05 22:55:15.711704852 +0000
+@@ -45,8 +45,6 @@
+ * o) Handle _writes_ to MII registers.
+ * o) Make it work with modern Linux kernels (as a guest OS).
+ * o) Endianness for descriptors? If necessary.
+- * o) Actually handle the "Setup" packet.
+- * o) MAC filtering on incoming packets.
+ * o) Don't hardcode as many values.
+ */
+
+@@ -76,16 +74,15 @@
+ #define ROM_WIDTH 6
+
+ struct dec21143_data {
++ /* NIC common data */
++ struct nic_data nic;
++
+ struct interrupt irq;
+ int irq_was_asserted;
+
+ /* PCI: */
+ int pci_little_endian;
+
+- /* Ethernet address, and a network which we are connected to: */
+- uint8_t mac[6];
+- struct net *net;
+-
+ /* SROM emulation: */
+ uint8_t srom[1 << (ROM_WIDTH + 1)];
+ int srom_curbit;
+@@ -105,19 +102,66 @@ struct dec21143_data {
+ uint32_t reg[N_REGS];
+
+ /* Internal TX state: */
+- uint64_t cur_tx_addr;
++ uint32_t cur_tx_addr;
+ unsigned char *cur_tx_buf;
+ int cur_tx_buf_len;
+ int tx_idling;
+ int tx_idling_threshold;
+
+ /* Internal RX state: */
+- uint64_t cur_rx_addr;
++ uint32_t cur_rx_addr;
+ unsigned char *cur_rx_buf;
+ int cur_rx_buf_len;
+ int cur_rx_offset;
++
++ /*
++ * Receive filter information. We keep our own copy of
++ * the promiscuous flag because to implement some of the
++ * filtering modes, we need to tell the network layer that
++ * we want all packets.
++ */
++ int (*drop_packet)(struct net *, struct dec21143_data *);
++ int allmulti;
++ int promiscuous;
++ int filter_needs_promiscuous;
++ uint8_t perfect_filter[6 * TULIP_MAXADDRS];
++
++ /* Only 16 bits are used per filter word. */
++#define MCHASH_NWORDS (TULIP_MCHASHSIZE / 16)
++ uint32_t hash_filter[MCHASH_NWORDS];
++ int hash_filter_saturated;
++
++ /*
++ * XXX XXX XXX
++ * XXX UGLY HACK. Need a proper way to deal with
++ * XXX different PCI vs. CPU views of RAM.
++ * XXX XXX XXX
++ */
++ uint32_t xxx_dma_to_phys_mask;
+ };
+
++/* XXX This is an UGLY hack. */
++static uint64_t dma_to_phys(const struct dec21143_data *d, uint32_t dma_addr)
++{
++ return dma_addr & d->xxx_dma_to_phys_mask;
++}
++
++
++static inline uint32_t load_le32(const uint8_t *buf)
++{
++ return buf[0] | ((uint32_t)buf[1] << 8) |
++ ((uint32_t)buf[2] << 16) | ((uint32_t)buf[3] << 24);
++}
++
++
++static inline void store_le32(uint8_t *buf, uint32_t val)
++{
++ buf[0] = (uint8_t)val;
++ buf[1] = (uint8_t)(val >> 8);
++ buf[2] = (uint8_t)(val >> 16);
++ buf[3] = (uint8_t)(val >> 24);
++}
++
+
+ /* Internal states during MII data stream decode: */
+ #define MII_STATE_RESET 0
+@@ -130,6 +174,171 @@ struct dec21143_data {
+
+
+ /*
++ * The 21143 has multiple address matching modes:
++ *
++ * - Perfect Filtering: The chip interprets the descriptor buffer
++ * as a table of 16 MAC addresses that it should match. The
++ * station address and broadcast must be included in the list.
++ *
++ * - Hash Perfect Filtering: The chip interprets the descriptor buffer
++ * as a 512-bit hash table plus one perfect filter match. Multicast
++ * addresses only are matched against the hash table.
++ *
++ * - Inverse Filtering: Like Perfect Filtering, but the table is
++ * addresses NOT to match.
++ *
++ * - Hash-only Filtering: Like Hash Perfect, except without the Perfect.
++ * All addresses are matched against the hash table.
++ *
++ * The mode seleted by the TDCTL descriptor field is reflected in 3
++ * read-only bits in the OPMODE register.
++ *
++ * We implement all 4 (NetBSD, at least, is known to use Perfect and
++ * Hash Perfect on the 21143; it also uses Hash-only on the 21140).
++ */
Home |
Main Index |
Thread Index |
Old Index