pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/emulators/tme Add tap(4) support for *BSD, written by ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/80181d19f0ed
branches:  trunk
changeset: 412269:80181d19f0ed
user:      rin <rin%pkgsrc.org@localhost>
date:      Wed Mar 04 07:52:11 2020 +0000

description:
Add tap(4) support for *BSD, written by kiyohara@.

The patch was proposed on some mailing lists back in 2013, but
unfortunately, left uncommitted until today:

    https://mail-index.netbsd.org/port-sparc64/2013/01/29/msg001951.html

It works perfectly for me on NetBSD/amd64 for sun[23].

Bump revision.

diffstat:

 emulators/tme/Makefile                                 |    7 +-
 emulators/tme/distinfo                                 |   12 +-
 emulators/tme/files/bsd-tap.c                          |  744 +++++++++++++++++
 emulators/tme/patches/patch-host_bsd_Makefile.am       |   19 +
 emulators/tme/patches/patch-host_bsd_Makefile.in       |   33 +
 emulators/tme/patches/patch-machine_sun2_SUN2-MULTIBUS |   19 +-
 emulators/tme/patches/patch-machine_sun3_SUN3-CARRERA  |   19 +-
 emulators/tme/patches/patch-machine_sun4_SUN4-75       |   17 +-
 emulators/tme/patches/patch-machine_sun4u_SUN-ULTRA-1  |   17 +-
 9 files changed, 866 insertions(+), 21 deletions(-)

diffs (truncated from 989 to 300 lines):

diff -r b2e57ad0907a -r 80181d19f0ed emulators/tme/Makefile
--- a/emulators/tme/Makefile    Wed Mar 04 06:28:32 2020 +0000
+++ b/emulators/tme/Makefile    Wed Mar 04 07:52:11 2020 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.72 2019/12/06 05:38:02 mrg Exp $
+# $NetBSD: Makefile,v 1.73 2020/03/04 07:52:11 rin Exp $
 #
 
 DISTNAME=              tme-0.8
-PKGREVISION=           39
+PKGREVISION=           40
 CATEGORIES=            emulators
 MASTER_SITES=          http://csail.mit.edu/~fredette/tme/
 
@@ -40,6 +40,9 @@
 PLIST.bsd=     yes
 .endif
 
+post-extract:
+       ${CP} ${FILESDIR}/bsd-tap.c ${WRKSRC}/host/bsd
+
 .include "../../devel/libltdl/buildlink3.mk"
 .include "../../x11/gtk2/buildlink3.mk"
 .include "../../x11/libSM/buildlink3.mk"
diff -r b2e57ad0907a -r 80181d19f0ed emulators/tme/distinfo
--- a/emulators/tme/distinfo    Wed Mar 04 06:28:32 2020 +0000
+++ b/emulators/tme/distinfo    Wed Mar 04 07:52:11 2020 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.23 2015/11/04 03:33:39 dholland Exp $
+$NetBSD: distinfo,v 1.24 2020/03/04 07:52:11 rin Exp $
 
 SHA1 (tme-0.8.tar.gz) = dd4f3421c20ceed548c5328a21dbb26e80f46b9c
 RMD160 (tme-0.8.tar.gz) = 6bd505c5fa7810d37f436883383c4ba655df2ded
@@ -10,6 +10,8 @@
 SHA1 (patch-ad) = e90986262fe9d883ae64fe01dfb4ae07bde6a916
 SHA1 (patch-ae) = cfcea636744991c6eef84ea34ca78d40eb01c086
 SHA1 (patch-af) = cd3ffe52d4d75d05394ca74c3f69052bfdc41989
+SHA1 (patch-host_bsd_Makefile.am) = db0add22732e95b18886877a92e57e1a19d3099f
+SHA1 (patch-host_bsd_Makefile.in) = 0c361aca770ec7e323cef150e0e1b29d6a442306
 SHA1 (patch-host_bsd_bsd-bpf.c) = 02a94a141da7d1790969deb8624d3a219d3e64ed
 SHA1 (patch-host_posix_posix-serial.c) = b1e009d6432c49672ca07a16ced939c8a46ef6e2
 SHA1 (patch-ic_ieee754_ieee754-misc-auto.sh) = afeb7452ef64bcae71e4dbae21881cff12cb9d4f
@@ -18,14 +20,14 @@
 SHA1 (patch-ic_m68k_m68k-m68k-insns.c) = 1a9d8e3d4e11c5710d1f67b65954d6e3de68d99f
 SHA1 (patch-ic_m68k_m68k-misc.c) = 7aeef098631196fe60b9940600cf90c86d1be375
 SHA1 (patch-libtme_memory-auto.sh) = f7d989831b2468d1288faabc10b6fc53ce5bd0f4
-SHA1 (patch-machine_sun2_SUN2-MULTIBUS) = dc44d9c842277a2f4ff55b0200edbc990ee86669
+SHA1 (patch-machine_sun2_SUN2-MULTIBUS) = cf9f55fcc15e2d977823dd54b9a10c42b11a6666
 SHA1 (patch-machine_sun2_sun2-mainbus.c) = 91b901d37d5f9a72064831d440c4371b81857640
-SHA1 (patch-machine_sun3_SUN3-CARRERA) = 73b8f3a5a7c587aa726db4fa53844f2a0dc82a24
+SHA1 (patch-machine_sun3_SUN3-CARRERA) = f07eabcab452686277f4f22849474bbc196e7ba7
 SHA1 (patch-machine_sun3_sun3-mainbus.c) = bfe56fdee109824ccf8a81760406b6c5d1ab7157
-SHA1 (patch-machine_sun4_SUN4-75) = 02218192d50e7679358e822515210711602c3271
+SHA1 (patch-machine_sun4_SUN4-75) = bd5412f970de3a1883b1d27cf3e8f9c2ac70d569
 SHA1 (patch-machine_sun4_sun4-mainbus.c) = 9dda3c5365e608cce2faa180d6a58351c8e58095
 SHA1 (patch-machine_sun4_sun4-timer.c) = 979e62cd68d1e8f9b15ba9511d798cbb4c0e2105
-SHA1 (patch-machine_sun4u_SUN-ULTRA-1) = e2bd0b991acf47ff01658f2f692913c24d7478b5
+SHA1 (patch-machine_sun4u_SUN-ULTRA-1) = 1aa0dcefafaa70cdaaaac0161b7adda2b2b00ed8
 SHA1 (patch-tme_common.h) = 1c07068397022ff349c283cbbfaa804deeb2aabf
 SHA1 (patch-tme_generic_float.h) = 4f48ebdd713367d47784caa990d46990e4f8108f
 SHA1 (patch-tmesh_Makefile.in) = 850adc8390ea3031ee3d55396373be8507a43c32
diff -r b2e57ad0907a -r 80181d19f0ed emulators/tme/files/bsd-tap.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/emulators/tme/files/bsd-tap.c     Wed Mar 04 07:52:11 2020 +0000
@@ -0,0 +1,744 @@
+/* $NetBSD: bsd-tap.c,v 1.1 2020/03/04 07:52:11 rin Exp $ */
+/* Id: bsd-bpf.c,v 1.9 2007/02/21 01:24:50 fredette Exp  */
+
+/* host/bsd/bsd-tap.c - BSD TAP Ethernet support: */
+
+/*
+ * Copyright (c) 2001, 2003 Matt Fredette
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Matt Fredette.
+ * 4. 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 ``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 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.
+ */
+
+#include <tme/common.h>
+_TME_RCSID("Id: bsd-bpf.c,v 1.9 2007/02/21 01:24:50 fredette Exp ");
+
+/* includes: */
+#include "bsd-impl.h"
+#include <tme/generic/ethernet.h>
+#include <tme/threads.h>
+#include <tme/misc.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <net/if.h>
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#if defined(HAVE_SYS_SOCKIO_H)
+#include <sys/sockio.h>
+#elif defined(HAVE_SYS_SOCKETIO_H)
+#include <sys/socketio.h> 
+#endif /* HAVE_SYS_SOCKETIO_H */
+#include <sys/ioctl.h>
+#ifdef HAVE_IOCTLS_H
+#include <ioctls.h>
+#endif /* HAVE_IOCTLS_H */
+#ifdef HAVE_NET_IF_ETHER_H
+#include <net/if_ether.h>
+#endif /* HAVE_NET_IF_ETHER_H */
+#ifdef HAVE_NET_ETHERNET_H
+#include <net/ethernet.h>
+#endif /* HAVE_NET_ETHERNET_H */
+#include <netinet/ip.h>
+#ifdef HAVE_NET_IF_DL_H
+#include <net/if_dl.h>
+#endif /* HAVE_NET_IF_DL_H */
+#include <arpa/inet.h>
+
+/* macros: */
+
+/* ARP and RARP opcodes: */
+#define TME_NET_ARP_OPCODE_REQUEST     (0x0001)
+#define TME_NET_ARP_OPCODE_REPLY       (0x0002)
+#define TME_NET_ARP_OPCODE_REV_REQUEST (0x0003)
+#define TME_NET_ARP_OPCODE_REV_REPLY   (0x0004)
+
+/* the callout flags: */
+#define TME_BSD_TAP_CALLOUT_CHECK      (0)
+#define TME_BSD_TAP_CALLOUT_RUNNING    TME_BIT(0)
+#define TME_BSD_TAP_CALLOUTS_MASK      (-2)
+#define  TME_BSD_TAP_CALLOUT_CTRL      TME_BIT(1)
+#define  TME_BSD_TAP_CALLOUT_READ      TME_BIT(2)
+
+/* structures: */
+
+/* our internal data structure: */
+struct tme_bsd_tap {
+
+  /* backpointer to our element: */
+  struct tme_element *tme_bsd_tap_element;
+
+  /* our mutex: */
+  tme_mutex_t tme_bsd_tap_mutex;
+
+  /* our reader condition: */
+  tme_cond_t tme_bsd_tap_cond_reader;
+
+  /* the callout flags: */
+  unsigned int tme_bsd_tap_callout_flags;
+
+  /* our Ethernet connection: */
+  struct tme_ethernet_connection *tme_bsd_tap_eth_connection;
+
+  /* the TAP file descriptor: */
+  int tme_bsd_tap_fd;
+
+  /* the packet buffer for the interface: */
+  tme_uint8_t *tme_bsd_tap_buffer;
+
+  int tme_bsd_tap_buffer_in_bytes;
+
+  /* when nonzero, the packet delay sleep time, in microseconds: */
+  unsigned long tme_bsd_tap_delay_sleep;
+
+  /* when nonzero, the packet delay is sleeping: */
+  int tme_bsd_tap_delay_sleeping;
+};
+
+/* a crude ARP header: */
+struct tme_net_arp_header {
+  tme_uint8_t tme_net_arp_header_hardware[2];
+  tme_uint8_t tme_net_arp_header_protocol[2];
+  tme_uint8_t tme_net_arp_header_hardware_length;
+  tme_uint8_t tme_net_arp_header_protocol_length;
+  tme_uint8_t tme_net_arp_header_opcode[2];
+};
+
+/* a crude partial IPv4 header: */
+struct tme_net_ipv4_header {
+  tme_uint8_t tme_net_ipv4_header_v_hl;
+  tme_uint8_t tme_net_ipv4_header_tos;
+  tme_uint8_t tme_net_ipv4_header_length[2];
+};
+
+/* the tap callout function.  it must be called with the mutex locked: */
+static void
+_tme_bsd_tap_callout(struct tme_bsd_tap *tap, int new_callouts)
+{
+  struct tme_ethernet_connection *conn_eth;
+  int callouts, later_callouts;
+  unsigned int ctrl;
+  int rc;
+  int status;
+  tme_ethernet_fid_t frame_id;
+  struct tme_ethernet_frame_chunk frame_chunk_buffer;
+  tme_uint8_t frame[TME_ETHERNET_FRAME_MAX];
+  
+  /* add in any new callouts: */
+  tap->tme_bsd_tap_callout_flags |= new_callouts;
+
+  /* if this function is already running in another thread, simply
+     return now.  the other thread will do our work: */
+  if (tap->tme_bsd_tap_callout_flags & TME_BSD_TAP_CALLOUT_RUNNING) {
+    return;
+  }
+
+  /* callouts are now running: */
+  tap->tme_bsd_tap_callout_flags |= TME_BSD_TAP_CALLOUT_RUNNING;
+
+  /* assume that we won't need any later callouts: */
+  later_callouts = 0;
+
+  /* loop while callouts are needed: */
+  for (; (callouts = tap->tme_bsd_tap_callout_flags) & TME_BSD_TAP_CALLOUTS_MASK; ) {
+
+    /* clear the needed callouts: */
+    tap->tme_bsd_tap_callout_flags = callouts & ~TME_BSD_TAP_CALLOUTS_MASK;
+    callouts &= TME_BSD_TAP_CALLOUTS_MASK;
+
+    /* get our Ethernet connection: */
+    conn_eth = tap->tme_bsd_tap_eth_connection;
+
+    /* if we need to call out new control information: */
+    if (callouts & TME_BSD_TAP_CALLOUT_CTRL) {
+
+      /* form the new ctrl: */
+      ctrl = 0;
+      if (tap->tme_bsd_tap_buffer_in_bytes > 0) {
+       ctrl |= TME_ETHERNET_CTRL_OK_READ;
+      }
+
+      /* unlock the mutex: */
+      tme_mutex_unlock(&tap->tme_bsd_tap_mutex);
+      
+      /* do the callout: */
+      rc = (conn_eth != NULL
+           ? ((*conn_eth->tme_ethernet_connection_ctrl)
+              (conn_eth,
+               ctrl))
+           : TME_OK);
+       
+      /* lock the mutex: */
+      tme_mutex_lock(&tap->tme_bsd_tap_mutex);
+      
+      /* if the callout was unsuccessful, remember that at some later
+        time this callout should be attempted again: */
+      if (rc != TME_OK) {
+       later_callouts |= TME_BSD_TAP_CALLOUT_CTRL;
+      }
+    }
+      
+    /* if the Ethernet is readable: */
+    if (callouts & TME_BSD_TAP_CALLOUT_READ) {
+
+      /* unlock the mutex: */
+      tme_mutex_unlock(&tap->tme_bsd_tap_mutex);
+      
+      /* make a frame chunk to receive this frame: */
+      frame_chunk_buffer.tme_ethernet_frame_chunk_next = NULL;
+      frame_chunk_buffer.tme_ethernet_frame_chunk_bytes = frame;
+      frame_chunk_buffer.tme_ethernet_frame_chunk_bytes_count
+       = sizeof(frame);
+
+      /* do the callout: */
+      rc = (conn_eth == NULL
+           ? TME_OK
+           : ((*conn_eth->tme_ethernet_connection_read)
+              (conn_eth,
+               &frame_id,
+               &frame_chunk_buffer,
+               TME_ETHERNET_READ_NEXT)));
+      
+      /* lock the mutex: */
+      tme_mutex_lock(&tap->tme_bsd_tap_mutex);
+      
+      /* if the read was successful: */
+      if (rc > 0) {



Home | Main Index | Thread Index | Old Index