From Markus Friedl:
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 Mar 2003 16:52:46 +0000 (16:52 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 Mar 2003 16:52:46 +0000 (16:52 +0000)
  Add support for the OpenBSD enc(4) encapsulating interface.  Add
  support for Ethernet over IP (RFC 3378).

Fold Markus' .h files into their respective .c files, add a define to
ipproto.h and use it.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@7310 f5534014-38df-0310-8fa8-9805f1628bb7

AUTHORS
Makefile.am
doc/ethereal.pod.template
ipproto.h
packet-enc.c [new file with mode: 0644]
packet-etherip.c [new file with mode: 0644]
wiretap/libpcap.c
wiretap/wtap.h

diff --git a/AUTHORS b/AUTHORS
index a8f6bfeb28ee2fd4882a2e92938bb0c629111d40..40c2be5bf7c275283921e478e599c2703358ac7f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1640,6 +1640,11 @@ Miha Jemec <m.jemec [AT] iskratel.si> {
        Support for G.711 codec
 }
 
+Markus Friedl <markus [AT] openbsd.org> {
+       Support for OpenBSD Encapsulating Device
+       Support for Ethernet-within-IP encapsulation
+}
+
 And assorted fixes and enhancements by the people listed above and by:
 
        Pavel Roskin <proski [AT] gnu.org>
index 6d8f36dad31219f8875890dfde0a683f0f4b616d..73bb5534b6aa4a2694c273b3da20c0c3d4b316ed 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for Ethereal
 #
-# $Id: Makefile.am,v 1.566 2003/03/06 20:35:09 sahlberg Exp $
+# $Id: Makefile.am,v 1.567 2003/03/07 16:52:41 gerald Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@ethereal.com>
@@ -179,8 +179,10 @@ DISSECTOR_SRC = \
        packet-eap.c \
        packet-eapol.c \
        packet-eigrp.c \
+       packet-enc.c    \
        packet-esis.c  \
        packet-eth.c   \
+       packet-etherip.c        \
        packet-ethertype.c   \
        packet-fc.c \
        packet-fcct.c \
index 9935fd9f3518724e0d484868a7c0aaadd298c322..ba17946947440ceeb998034afc312006c9f6d5c3 100644 (file)
@@ -1731,6 +1731,7 @@ B<http://www.ethereal.com>.
   Pavel Roskin             <proski [AT] gnu.org>
   Georgi Guninski          <guninski [AT] guninski.com>
   Jason Copenhaver         <jcopenha [AT] typedef.org>
+  Markus Friedl            <markus [AT] openbsd.org>
 
 Alain Magloire <alainm[AT]rcsm.ece.mcgill.ca> was kind enough to give his
 permission to use his version of snprintf.c.
index ebd2757d9da8f846e29be62aee0c8bc604ec8838..442779d240a6bf06b3e7b83cd03483d9ca71d9f0 100644 (file)
--- a/ipproto.h
+++ b/ipproto.h
@@ -2,7 +2,7 @@
  * Declarations of IP protocol numbers, and of routines for converting
  * IP protocol numbers into strings.
  *
- * $Id: ipproto.h,v 1.7 2003/02/04 20:16:57 guy Exp $
+ * $Id: ipproto.h,v 1.8 2003/03/07 16:52:41 gerald Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #define IP_PROTO_ICMPV6                58              /* ICMP6 */
 #define IP_PROTO_NONE          59              /* IP6 no next header */
 #define IP_PROTO_DSTOPTS       60              /* IP6 destination options */
-#define IP_PROTO_MIPV6      62              /* Mobile IPv6 */
+#define IP_PROTO_MIPV6         62              /* Mobile IPv6 */
 #define IP_PROTO_EON           80              /* ISO cnlp */
 #define IP_PROTO_VINES         83              /* Vines over raw IP */
 #define IP_PROTO_EIGRP         88
 #define IP_PROTO_OSPF          89
+#define IP_PROTO_ETHERIP       97              /* Ethernet-within-IP (RFC 3378) */
 #define IP_PROTO_ENCAP         98              /* encapsulation header */
 #define IP_PROTO_PIM           103             /* Protocol Independent Mcast */
 #define IP_PROTO_IPCOMP                108             /* IP payload compression */
diff --git a/packet-enc.c b/packet-enc.c
new file mode 100644 (file)
index 0000000..0b1a93e
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2003 Markus Friedl.  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.
+ *
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <glib.h>
+#include <epan/packet.h>
+#include "etypes.h"
+#include <epan/resolv.h>
+#include "packet-ip.h"
+#include "packet-ipv6.h"
+
+#ifndef offsetof
+/* Can't trust stddef.h to be there for us */
+# define offsetof(type, member) ((size_t)(&((type *)0)->member))
+#endif
+
+/* The header in OpenBSD Encapsulating Interface files. */
+
+struct enchdr {
+  guint32 af;
+  guint32 spi;
+  guint32 flags;
+};
+#define ENC_HDRLEN    sizeof(struct enchdr)
+
+# define BSD_ENC_INET    2
+# define BSD_ENC_INET6   24
+
+# define BSD_ENC_M_CONF          0x0400  /* payload encrypted */
+# define BSD_ENC_M_AUTH          0x0800  /* payload authenticated */
+# define BSD_ENC_M_COMP          0x1000  /* payload compressed */
+# define BSD_ENC_M_AUTH_AH       0x2000  /* header authenticated */
+
+
+static dissector_handle_t  data_handle, ip_handle, ipv6_handle;
+
+/* header fields */
+static unsigned int proto_enc = -1;
+static unsigned int hf_enc_af = -1;
+static unsigned int hf_enc_spi = -1;
+static unsigned int hf_enc_flags = -1;
+
+static gint ett_enc = -1;
+
+void
+capture_enc(const guchar *pd, int offset, int len, packet_counts *ld)
+{
+  struct enchdr ench;
+
+  if (!BYTES_ARE_IN_FRAME(offset, len, (int)ENC_HDRLEN)) {
+    ld->other++;
+    return;
+  }
+
+  offset += ENC_HDRLEN;
+
+  /* Copy out the enc header to insure alignment */
+  memcpy(&ench, pd, sizeof(ench));
+  ench.af = g_ntohl(ench.af);
+
+  switch (ench.af) {
+
+  case BSD_ENC_INET:
+    capture_ip(pd, offset, len, ld);
+    break;
+
+#ifdef notyet
+  case BSD_ENC_INET6:
+    capture_ipv6(pd, offset, len, ld);
+    break;
+#endif
+
+  default:
+    ld->other++;
+    break;
+  }
+}
+
+static const value_string af_vals[] = {
+  { BSD_ENC_INET,  "IPv4" },
+  { BSD_ENC_INET6, "IPv6" },
+  { 0,            NULL }
+};
+
+static void
+dissect_enc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+  struct enchdr ench;
+  tvbuff_t *next_tvb;
+  proto_tree *enc_tree;
+  proto_item *ti;
+
+  if (check_col(pinfo->cinfo, COL_PROTOCOL))
+    col_set_str(pinfo->cinfo, COL_PROTOCOL, "ENC");
+
+  /* Copy out the enc header to insure alignment */
+  tvb_memcpy(tvb, (guint8 *)&ench, 0, sizeof(ench));
+
+  /* Byteswap the header now */
+  ench.spi = g_ntohl(ench.spi);
+  /* ench.af = g_ntohl(ench.af); */
+  /* ench.flags = g_ntohl(ench.flags); */
+
+  if (tree) {
+    ti = proto_tree_add_protocol_format(tree, proto_enc, tvb, 0,
+             ENC_HDRLEN,
+             "Enc %s, SPI 0x%8.8x, %s%s%s%s",
+             val_to_str(ench.af, af_vals, "unknown (%u)"),
+             ench.spi,
+             ench.flags ? "" : "unprotected",
+             ench.flags & BSD_ENC_M_AUTH ? "authentic" : "",
+             (ench.flags & (BSD_ENC_M_AUTH|BSD_ENC_M_CONF)) ==
+               (BSD_ENC_M_AUTH|BSD_ENC_M_CONF) ? ", " : "",
+             ench.flags & BSD_ENC_M_CONF ? "confidential" : ""
+            );
+    enc_tree = proto_item_add_subtree(ti, ett_enc);
+
+    proto_tree_add_uint(enc_tree, hf_enc_af, tvb,
+             offsetof(struct enchdr, af), sizeof(ench.af),
+             ench.af);
+    proto_tree_add_uint(enc_tree, hf_enc_spi, tvb,
+             offsetof(struct enchdr, spi), sizeof(ench.spi),
+             ench.spi);
+    proto_tree_add_uint(enc_tree, hf_enc_flags, tvb,
+             offsetof(struct enchdr, flags), sizeof(ench.flags),
+             ench.flags);
+  }
+
+  /* Set the tvbuff for the payload after the header */
+  next_tvb = tvb_new_subset(tvb, ENC_HDRLEN, -1, -1);
+
+  switch (ench.af) {
+
+  case BSD_ENC_INET:
+    call_dissector(ip_handle, next_tvb, pinfo, tree);
+    break;
+
+  case BSD_ENC_INET6:
+    call_dissector(ipv6_handle, next_tvb, pinfo, tree);
+    break;
+
+  default:
+    call_dissector(data_handle, next_tvb, pinfo, tree);
+    break;
+  }
+}
+
+void
+proto_register_enc(void)
+{
+  static hf_register_info hf[] = {
+    { &hf_enc_af,
+      { "Address Family", "enc.af", FT_UINT32, BASE_DEC, VALS(af_vals), 0x0,
+        "Protocol (IPv4 vs IPv6)", HFILL }},
+    { &hf_enc_spi,
+      { "SPI", "enc.spi", FT_UINT32, BASE_HEX, NULL, 0x0,
+        "Security Parameter Index", HFILL }},
+    { &hf_enc_flags,
+      { "Flags", "enc.flags", FT_UINT32, BASE_HEX, NULL, 0x0,
+        "ENC flags", HFILL }},
+  };
+  static gint *ett[] = { &ett_enc };
+
+  proto_enc = proto_register_protocol("OpenBSD Encapsulating device",
+                                     "ENC", "enc");
+  proto_register_field_array(proto_enc, hf, array_length(hf));
+  proto_register_subtree_array(ett, array_length(ett));
+}
+
+void
+proto_reg_handoff_enc(void)
+{
+  dissector_handle_t enc_handle;
+
+  ip_handle = find_dissector("ip");
+  ipv6_handle = find_dissector("ipv6");
+  data_handle = find_dissector("data");
+
+  enc_handle = create_dissector_handle(dissect_enc, proto_enc);
+  dissector_add("wtap_encap", WTAP_ENCAP_ENC0, enc_handle);
+}
diff --git a/packet-etherip.c b/packet-etherip.c
new file mode 100644 (file)
index 0000000..be958ce
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2003 Markus Friedl.  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.
+ *
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <glib.h>
+#include <epan/packet.h>
+#include "ipproto.h"
+
+static int proto_etherip = -1;
+static int hf_etherip_ver = -1;
+
+static gint ett_etherip = -1;
+
+static dissector_handle_t eth_handle;
+
+#ifndef offsetof
+#define        offsetof(type, member)  ((size_t)(&((type *)0)->member))
+#endif
+
+
+/*
+ * RFC 3378: EtherIP: Tunneling Ethernet Frames in IP Datagrams
+ *
+ *     Bits 0-3:  Protocol version
+ *     Bits 4-15: Reserved for future use
+ */
+
+struct etheriphdr {
+       guint8 ver;                /* version/reserved */
+       guint8 pad;                /* required padding byte */
+};
+
+#define ETHERIP_VERS_MASK 0x0f
+
+
+static void
+dissect_etherip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+  struct etheriphdr etheriph;
+  tvbuff_t *next_tvb;
+  proto_tree *etherip_tree;
+  proto_item *ti;
+
+  if (check_col(pinfo->cinfo, COL_PROTOCOL))
+    col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETHERIP");
+
+  /* Copy out the etherip header to insure alignment */
+  tvb_memcpy(tvb, (guint8 *)&etheriph, 0, sizeof(etheriph));
+
+  /* mask out reserved bits */
+  etheriph.ver &= ETHERIP_VERS_MASK;
+
+  if (tree) {
+    ti = proto_tree_add_protocol_format(tree, proto_etherip, tvb, 0,
+             sizeof(etheriph),
+             "EtherIP, Version %d",
+            etheriph.ver
+            );
+    etherip_tree = proto_item_add_subtree(ti, ett_etherip);
+
+    proto_tree_add_uint(etherip_tree, hf_etherip_ver, tvb,
+             offsetof(struct etheriphdr, ver), sizeof(etheriph.ver),
+             etheriph.ver);
+  }
+
+  /* Set the tvbuff for the payload after the header */
+  next_tvb = tvb_new_subset(tvb, sizeof(etheriph), -1, -1);
+
+  call_dissector(eth_handle, next_tvb, pinfo, tree);
+}
+
+void
+proto_register_etherip(void)
+{
+  static hf_register_info hf_etherip[] = {
+    { &hf_etherip_ver,
+      { "Version",     "etherip.ver",  FT_UINT8,       BASE_HEX, NULL, 0x0,
+       "", HFILL }},
+  };
+  static gint *ett[] = {
+    &ett_etherip,
+  };
+
+  proto_etherip = proto_register_protocol("Ethernet over IP",
+                                         "ETHERIP", "etherip");
+  proto_register_field_array(proto_etherip, hf_etherip, array_length(hf_etherip));
+  proto_register_subtree_array(ett, array_length(ett));
+
+  register_dissector("etherip", dissect_etherip, proto_etherip);
+}
+
+void
+proto_reg_handoff_etherip(void)
+{
+  dissector_handle_t etherip_handle;
+
+  eth_handle = find_dissector("eth");
+  etherip_handle = find_dissector("etherip");
+  dissector_add("ip.proto", IP_PROTO_ETHERIP, etherip_handle);
+}
index b7d633817a54d71dbb2934aadec93331f2043177..aae2e6f428ec47975c414a8f638f401bc78c9780 100644 (file)
@@ -1,6 +1,6 @@
 /* libpcap.c
  *
- * $Id: libpcap.c,v 1.92 2003/01/31 01:02:07 guy Exp $
+ * $Id: libpcap.c,v 1.93 2003/03/07 16:52:46 gerald Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -324,7 +324,7 @@ static const struct {
 #if defined(DLT_ATM_RFC1483) && (DLT_ATM_RFC1483 == 13)
        { 13,           WTAP_ENCAP_ATM_RFC1483 },
 #elif defined(DLT_ENC) && (DLT_ENC == 13)
-       /* Put entry for DLT_ENC here */
+       { 13,           WTAP_ENCAP_ENC0 },
 #endif
 
        /*
index 0c3b1c1075dcb1f4e1ce2085ca2dc29fbceab88e..09f153e32fb309674ffe5ddefcc7b5d4b6076c5a 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.h
  *
- * $Id: wtap.h,v 1.134 2003/01/31 01:02:14 guy Exp $
+ * $Id: wtap.h,v 1.135 2003/03/07 16:52:46 gerald Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
 #define WTAP_ENCAP_WFLEET_HDLC                 34
 #define WTAP_ENCAP_SDLC                                35
 #define WTAP_ENCAP_TZSP                                36
+#define WTAP_ENCAP_ENC0                                37
 
 /* last WTAP_ENCAP_ value + 1 */
-#define WTAP_NUM_ENCAP_TYPES                   37
+#define WTAP_NUM_ENCAP_TYPES                   38
 
 /* File types that can be read by wiretap.
    We support writing some many of these file types, too, so we